2020-04-16 05:23:37 -04:00
|
|
|
package mountinfo
|
|
|
|
|
2020-11-10 08:26:15 -05:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
2020-04-16 05:23:37 -04:00
|
|
|
|
|
|
|
// GetMounts retrieves a list of mounts for the current running process,
|
|
|
|
// with an optional filter applied (use nil for no filter).
|
|
|
|
func GetMounts(f FilterFunc) ([]*Info, error) {
|
|
|
|
return parseMountTable(f)
|
|
|
|
}
|
|
|
|
|
2020-11-10 08:26:15 -05:00
|
|
|
// Mounted determines if a specified path is a mount point.
|
|
|
|
//
|
|
|
|
// The argument must be an absolute path, with all symlinks resolved, and clean.
|
|
|
|
// One way to ensure it is to process the path using filepath.Abs followed by
|
|
|
|
// filepath.EvalSymlinks before calling this function.
|
|
|
|
func Mounted(path string) (bool, error) {
|
|
|
|
// root is always mounted
|
|
|
|
if path == string(os.PathSeparator) {
|
|
|
|
return true, nil
|
2020-04-16 05:23:37 -04:00
|
|
|
}
|
2020-11-10 08:26:15 -05:00
|
|
|
return mounted(path)
|
2020-04-16 05:23:37 -04:00
|
|
|
}
|
2017-05-10 17:13:36 -04:00
|
|
|
|
|
|
|
// Info reveals information about a particular mounted filesystem. This
|
|
|
|
// struct is populated from the content in the /proc/<pid>/mountinfo file.
|
|
|
|
type Info struct {
|
|
|
|
// ID is a unique identifier of the mount (may be reused after umount).
|
|
|
|
ID int
|
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Parent is the ID of the parent mount (or of self for the root
|
|
|
|
// of this mount namespace's mount tree).
|
2017-05-10 17:13:36 -04:00
|
|
|
Parent int
|
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Major and Minor are the major and the minor components of the Dev
|
|
|
|
// field of unix.Stat_t structure returned by unix.*Stat calls for
|
|
|
|
// files on this filesystem.
|
|
|
|
Major, Minor int
|
2017-05-10 17:13:36 -04:00
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Root is the pathname of the directory in the filesystem which forms
|
|
|
|
// the root of this mount.
|
2017-05-10 17:13:36 -04:00
|
|
|
Root string
|
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Mountpoint is the pathname of the mount point relative to the
|
|
|
|
// process's root directory.
|
2017-05-10 17:13:36 -04:00
|
|
|
Mountpoint string
|
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Options is a comma-separated list of mount options.
|
2020-11-10 08:26:15 -05:00
|
|
|
Options string
|
2017-05-10 17:13:36 -04:00
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Optional are zero or more fields of the form "tag[:value]",
|
|
|
|
// separated by a space. Currently, the possible optional fields are
|
|
|
|
// "shared", "master", "propagate_from", and "unbindable". For more
|
|
|
|
// information, see mount_namespaces(7) Linux man page.
|
2017-05-10 17:13:36 -04:00
|
|
|
Optional string
|
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// FSType is the filesystem type in the form "type[.subtype]".
|
2020-11-10 08:26:15 -05:00
|
|
|
FSType string
|
2017-05-10 17:13:36 -04:00
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// Source is filesystem-specific information, or "none".
|
2017-05-10 17:13:36 -04:00
|
|
|
Source string
|
|
|
|
|
2021-06-21 06:29:20 -04:00
|
|
|
// VFSOptions is a comma-separated list of superblock options.
|
2020-11-10 08:26:15 -05:00
|
|
|
VFSOptions string
|
2017-05-10 17:13:36 -04:00
|
|
|
}
|