mountinfo.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package mountinfo
  2. import (
  3. "os"
  4. )
  5. // GetMounts retrieves a list of mounts for the current running process,
  6. // with an optional filter applied (use nil for no filter).
  7. func GetMounts(f FilterFunc) ([]*Info, error) {
  8. return parseMountTable(f)
  9. }
  10. // Mounted determines if a specified path is a mount point. In case of any
  11. // error, false (and an error) is returned.
  12. //
  13. // If a non-existent path is specified, an appropriate error is returned.
  14. // In case the caller is not interested in this particular error, it should
  15. // be handled separately using e.g. errors.Is(err, fs.ErrNotExist).
  16. func Mounted(path string) (bool, error) {
  17. // root is always mounted
  18. if path == string(os.PathSeparator) {
  19. return true, nil
  20. }
  21. return mounted(path)
  22. }
  23. // Info reveals information about a particular mounted filesystem. This
  24. // struct is populated from the content in the /proc/<pid>/mountinfo file.
  25. type Info struct {
  26. // ID is a unique identifier of the mount (may be reused after umount).
  27. ID int
  28. // Parent is the ID of the parent mount (or of self for the root
  29. // of this mount namespace's mount tree).
  30. Parent int
  31. // Major and Minor are the major and the minor components of the Dev
  32. // field of unix.Stat_t structure returned by unix.*Stat calls for
  33. // files on this filesystem.
  34. Major, Minor int
  35. // Root is the pathname of the directory in the filesystem which forms
  36. // the root of this mount.
  37. Root string
  38. // Mountpoint is the pathname of the mount point relative to the
  39. // process's root directory.
  40. Mountpoint string
  41. // Options is a comma-separated list of mount options.
  42. Options string
  43. // Optional are zero or more fields of the form "tag[:value]",
  44. // separated by a space. Currently, the possible optional fields are
  45. // "shared", "master", "propagate_from", and "unbindable". For more
  46. // information, see mount_namespaces(7) Linux man page.
  47. Optional string
  48. // FSType is the filesystem type in the form "type[.subtype]".
  49. FSType string
  50. // Source is filesystem-specific information, or "none".
  51. Source string
  52. // VFSOptions is a comma-separated list of superblock options.
  53. VFSOptions string
  54. }