mt_utils_windows.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // +build windows
  2. /*
  3. Copyright 2019 The Kubernetes Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package mounttest
  15. import (
  16. "bytes"
  17. "fmt"
  18. "os"
  19. "os/exec"
  20. "strconv"
  21. "strings"
  22. )
  23. func umask(mask int) int {
  24. // noop for Windows.
  25. return 0
  26. }
  27. func fileOwner(path string) error {
  28. // Windows does not have owner UID / GID. However, it has owner SID.
  29. // not currently implemented in Kubernetes, so noop.
  30. return nil
  31. }
  32. func fileMode(path string) error {
  33. if path == "" {
  34. return nil
  35. }
  36. permissions, err := getFilePerm(path)
  37. if err != nil {
  38. return err
  39. }
  40. fmt.Printf("mode of Windows file %q: %v\n", path, permissions)
  41. return nil
  42. }
  43. func filePerm(path string) error {
  44. if path == "" {
  45. return nil
  46. }
  47. permissions, err := getFilePerm(path)
  48. if err != nil {
  49. return err
  50. }
  51. fmt.Printf("perms of Windows file %q: %v\n", path, permissions)
  52. return nil
  53. }
  54. func getFilePerm(path string) (os.FileMode, error) {
  55. var (
  56. out bytes.Buffer
  57. errOut bytes.Buffer
  58. )
  59. cmd := exec.Command("powershell.exe", "-NonInteractive", "./filePermissions.ps1",
  60. "-FileName", path)
  61. cmd.Stdout = &out
  62. cmd.Stderr = &errOut
  63. err := cmd.Run()
  64. if err != nil {
  65. fmt.Printf("error from PowerShell Script: %v, %v\n", err, errOut.String())
  66. return 0, err
  67. }
  68. output := strings.TrimSpace(out.String())
  69. val, err := strconv.ParseInt(output, 8, 32)
  70. if err != nil {
  71. fmt.Printf("error parsing string '%s' as int: %v\n", output, err)
  72. return 0, err
  73. }
  74. return os.FileMode(val), nil
  75. }
  76. func fsType(path string) error {
  77. // only NTFS is supported at the moment.
  78. return nil
  79. }