mount

package
v0.0.0-...-c70285d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RDONLY will mount the file system read-only.
	RDONLY = unix.MS_RDONLY

	// NOSUID will not allow set-user-identifier or set-group-identifier bits to
	// take effect.
	NOSUID = unix.MS_NOSUID

	// NODEV will not interpret character or block special devices on the file
	// system.
	NODEV = unix.MS_NODEV

	// NOEXEC will not allow execution of any binaries on the mounted file system.
	NOEXEC = unix.MS_NOEXEC

	// SYNCHRONOUS will allow I/O to the file system to be done synchronously.
	SYNCHRONOUS = unix.MS_SYNCHRONOUS

	// DIRSYNC will force all directory updates within the file system to be done
	// synchronously. This affects the following system calls: create, link,
	// unlink, symlink, mkdir, rmdir, mknod and rename.
	DIRSYNC = unix.MS_DIRSYNC

	// REMOUNT will attempt to remount an already-mounted file system. This is
	// commonly used to change the mount flags for a file system, especially to
	// make a readonly file system writeable. It does not change device or mount
	// point.
	REMOUNT = unix.MS_REMOUNT

	// MANDLOCK will force mandatory locks on a filesystem.
	MANDLOCK = unix.MS_MANDLOCK

	// NOATIME will not update the file access time when reading from a file.
	NOATIME = unix.MS_NOATIME

	// NODIRATIME will not update the directory access time.
	NODIRATIME = unix.MS_NODIRATIME

	// BIND remounts a subtree somewhere else.
	BIND = unix.MS_BIND

	// RBIND remounts a subtree and all possible submounts somewhere else.
	RBIND = unix.MS_BIND | unix.MS_REC

	// UNBINDABLE creates a mount which cannot be cloned through a bind operation.
	UNBINDABLE = unix.MS_UNBINDABLE

	// RUNBINDABLE marks the entire mount tree as UNBINDABLE.
	RUNBINDABLE = unix.MS_UNBINDABLE | unix.MS_REC

	// PRIVATE creates a mount which carries no propagation abilities.
	PRIVATE = unix.MS_PRIVATE

	// RPRIVATE marks the entire mount tree as PRIVATE.
	RPRIVATE = unix.MS_PRIVATE | unix.MS_REC

	// SLAVE creates a mount which receives propagation from its master, but not
	// vice versa.
	SLAVE = unix.MS_SLAVE

	// RSLAVE marks the entire mount tree as SLAVE.
	RSLAVE = unix.MS_SLAVE | unix.MS_REC

	// SHARED creates a mount which provides the ability to create mirrors of
	// that mount such that mounts and unmounts within any of the mirrors
	// propagate to the other mirrors.
	SHARED = unix.MS_SHARED

	// RSHARED marks the entire mount tree as SHARED.
	RSHARED = unix.MS_SHARED | unix.MS_REC

	// RELATIME updates inode access times relative to modify or change time.
	RELATIME = unix.MS_RELATIME

	// STRICTATIME allows to explicitly request full atime updates.  This makes
	// it possible for the kernel to default to relatime or noatime but still
	// allow userspace to override it.
	STRICTATIME = unix.MS_STRICTATIME
)

Variables

This section is empty.

Functions

func ForceMount

func ForceMount(device, target, mType, options string) error

ForceMount will mount a filesystem according to the specified configuration, *regardless* if the target path is not already mounted. Options must be specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See flags.go for supported option flags.

func MakeMount

func MakeMount(mnt string) error

MakeMount ensures that the file or directory given is a mount point, bind mounting it to itself it case it is not.

func MakePrivate

func MakePrivate(mountPoint string) error

MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled. See the supported options in flags.go for further reference.

func MakeRPrivate

func MakeRPrivate(mountPoint string) error

MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option enabled. See the supported options in flags.go for further reference.

func MakeRShared

func MakeRShared(mountPoint string) error

MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled. See the supported options in flags.go for further reference.

func MakeRSlave

func MakeRSlave(mountPoint string) error

MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled. See the supported options in flags.go for further reference.

func MakeRUnbindable

func MakeRUnbindable(mountPoint string) error

MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount option enabled. See the supported options in flags.go for further reference.

func MakeShared

func MakeShared(mountPoint string) error

MakeShared ensures a mounted filesystem has the SHARED mount option enabled. See the supported options in flags.go for further reference.

func MakeSlave

func MakeSlave(mountPoint string) error

MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled. See the supported options in flags.go for further reference.

func MakeUnbindable

func MakeUnbindable(mountPoint string) error

MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option enabled. See the supported options in flags.go for further reference.

func MergeTmpfsOptions

func MergeTmpfsOptions(options []string) ([]string, error)

MergeTmpfsOptions merge mount options to make sure there is no duplicate.

func Mount

func Mount(device, target, mType, options string) error

Mount will mount filesystem according to the specified configuration, on the condition that the target path is *not* already mounted. Options must be specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See flags.go for supported option flags.

func Mounted

func Mounted(mountpoint string) (bool, error)

Mounted determines if a specified mountpoint has been mounted. On Linux it looks at /proc/self/mountinfo.

func RecursiveUnmount

func RecursiveUnmount(target string) error

RecursiveUnmount unmounts the target and all mounts underneath, starting with the deepsest mount first.

func Unmount

func Unmount(target string) error

Unmount lazily unmounts a filesystem on supported platforms, otherwise does a normal unmount.

Types

type FilterFunc

type FilterFunc func(*Info) (skip, stop bool)

FilterFunc is a type defining a callback function to filter out unwanted entries. It takes a pointer to an Info struct (not fully populated, currently only Mountpoint is filled in), and returns two booleans:

  • skip: true if the entry should be skipped
  • stop: true if parsing should be stopped after the entry

func ParentsFilter

func ParentsFilter(path string) FilterFunc

ParentsFilter returns all entries whose mount points can be parents of a path specified, discarding others. For example, given `/var/lib/docker/something`, entries like `/var/lib/docker`, `/var` and `/` are returned.

func PrefixFilter

func PrefixFilter(prefix string) FilterFunc

PrefixFilter discards all entries whose mount points do not start with a prefix specified

func SingleEntryFilter

func SingleEntryFilter(mp string) FilterFunc

SingleEntryFilter looks for a specific entry

type Info

type Info struct {
	// ID is a unique identifier of the mount (may be reused after umount).
	ID int

	// Parent indicates the ID of the mount parent (or of self for the top of the
	// mount tree).
	Parent int

	// Major indicates one half of the device ID which identifies the device class.
	Major int

	// Minor indicates one half of the device ID which identifies a specific
	// instance of device.
	Minor int

	// Root of the mount within the filesystem.
	Root string

	// Mountpoint indicates the mount point relative to the process's root.
	Mountpoint string

	// Opts represents mount-specific options.
	Opts string

	// Optional represents optional fields.
	Optional string

	// Fstype indicates the type of filesystem, such as EXT3.
	Fstype string

	// Source indicates filesystem specific information or "none".
	Source string

	// VfsOpts represents per super block options.
	VfsOpts string
}

Info reveals information about a particular mounted filesystem. This struct is populated from the content in the /proc/<pid>/mountinfo file.

func GetMounts

func GetMounts(f FilterFunc) ([]*Info, error)

GetMounts retrieves a list of mounts for the current running process, with an optional filter applied (use nil for no filter).

func PidMountInfo

func PidMountInfo(pid int) ([]*Info, error)

PidMountInfo collects the mounts for a specific process ID. If the process ID is unknown, it is better to use `GetMounts` which will inspect "/proc/self/mountinfo" instead.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL