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