mt_utils.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. "fmt"
  17. "os"
  18. "syscall"
  19. )
  20. func umask(mask int) int {
  21. return syscall.Umask(mask)
  22. }
  23. // Defined by Linux (sys/statfs.h) - the type number for tmpfs mounts.
  24. const linuxTmpfsMagic = 0x01021994
  25. func fsType(path string) error {
  26. if path == "" {
  27. return nil
  28. }
  29. buf := syscall.Statfs_t{}
  30. if err := syscall.Statfs(path, &buf); err != nil {
  31. fmt.Printf("error from statfs(%q): %v\n", path, err)
  32. return err
  33. }
  34. if buf.Type == linuxTmpfsMagic {
  35. fmt.Printf("mount type of %q: tmpfs\n", path)
  36. } else {
  37. fmt.Printf("mount type of %q: %v\n", path, buf.Type)
  38. }
  39. return nil
  40. }
  41. func fileMode(path string) error {
  42. if path == "" {
  43. return nil
  44. }
  45. fileinfo, err := os.Stat(path)
  46. if err != nil {
  47. fmt.Printf("error from Stat(%q): %v\n", path, err)
  48. return err
  49. }
  50. fmt.Printf("mode of file %q: %v\n", path, fileinfo.Mode())
  51. return nil
  52. }
  53. func filePerm(path string) error {
  54. if path == "" {
  55. return nil
  56. }
  57. fileinfo, err := os.Stat(path)
  58. if err != nil {
  59. fmt.Printf("error from Stat(%q): %v\n", path, err)
  60. return err
  61. }
  62. fmt.Printf("perms of file %q: %v\n", path, fileinfo.Mode().Perm())
  63. return nil
  64. }
  65. func fileOwner(path string) error {
  66. if path == "" {
  67. return nil
  68. }
  69. buf := syscall.Stat_t{}
  70. if err := syscall.Stat(path, &buf); err != nil {
  71. fmt.Printf("error from stat(%q): %v\n", path, err)
  72. return err
  73. }
  74. fmt.Printf("owner UID of %q: %v\n", path, buf.Uid)
  75. fmt.Printf("owner GID of %q: %v\n", path, buf.Gid)
  76. return nil
  77. }