Documentation ¶
Overview ¶
Package mount implements mounting, moving, and unmounting file systems.
Index ¶
- Constants
- Variables
- func FSFromBlock(n string) (fs string, flags uintptr, err error)
- func FindFileSystem(fstype string) error
- func FindMagics(blk []byte) []magic
- func GetBlockFilesystems() (fstypes []string, err error)
- func IsTmpRamfs(path string) (bool, error)
- func MoveMount(oldPath string, newPath string) error
- func SameFilesystem(path1, path2 string) (bool, error)
- func SwitchRoot(newRootDir string, init string) error
- func Unmount(path string, force, lazy bool) error
- type MountPoint
- type Mounter
- type Pool
Constants ¶
const ( MS_RDONLY = unix.MS_RDONLY MS_BIND = unix.MS_BIND MS_LAZYTIME = unix.MS_LAZYTIME MS_NOEXEC = unix.MS_NOEXEC MS_NOSUID = unix.MS_NOSUID MS_NOUSER = unix.MS_NOUSER MS_RELATIME = unix.MS_RELATIME MS_SYNC = unix.MS_SYNC MS_NOATIME = unix.MS_NOATIME ReadOnly = unix.MS_RDONLY | unix.MS_NOATIME )
Most commonly used mount flags.
const ( MNT_FORCE = unix.MNT_FORCE MNT_DETACH = unix.MNT_DETACH )
Unmount flags.
Variables ¶
var ( EXT2 = []byte{0x53, 0xef} EXT3 = []byte{0x53, 0xef} EXT4 = []byte{0x53, 0xef} ISOFS = []byte{1, 'C', 'D', '0', '0', '1'} SQUASHFS = []byte{'h', 's', 'q', 's'} XFS = []byte{'X', 'F', 'S', 'B'} // There's no fixed magic number for the different FAT varieties // Usually they start with 0xEB but it's not mandatory. // Therefore we just list a few examples that we have seen in the wild. MSDOS = []byte{0xeb, 0x3c} VFAT = []byte{0xeb, 0x58} // QEMU virtual VFAT VVFAT = []byte{0xeb, 0x3e} AAFS = []byte{0x5a, 0x3c, 0x69, 0xf0} ADFS = []byte{0xad, 0xf5} AFFS = []byte{0xad, 0xff} AFS = []byte{0x53, 0x46, 0x41, 0x4F} BDEVFS = []byte{0x62, 0x64, 0x65, 0x76} BINDERFS = []byte{0x6c, 0x6f, 0x6f, 0x70} BINFMTFS = []byte{0x42, 0x49, 0x4e, 0x4d} BPF = []byte{0xca, 0xfe, 0x4a, 0x11} BTRFS = []byte{0x91, 0x23, 0x68, 0x3E} CGROUP = []byte{0x27, 0xe0, 0xeb} CGROUP2 = []byte{0x63, 0x67, 0x72, 0x70} CODA = []byte{0x73, 0x75, 0x72, 0x45} CRAMFS = []byte{0x28, 0xcd, 0x3d, 0x45} CRAMFSOther = []byte{0x45, 0x3d, 0xcd, 0x28} DAXFS = []byte{0x64, 0x64, 0x61, 0x78} DEBUGFS = []byte{0x64, 0x62, 0x67, 0x20} DEVPTS = []byte{0x1c, 0xd1} ECRYPTFS = []byte{0xf1, 0x5f} EFIVARFS = []byte{0xde, 0x5e, 0x81, 0xe4} EFS = []byte{0x41, 0x4A, 0x53} // EXFAT seems to be a samsung file system. //EXFAT = []byte{0x53, 0xef} F2FS = []byte{0xF2, 0xF5, 0x20, 0x10} FUSE = []byte{0x65, 0x73, 0x55, 0x46} FUTEXFS = []byte{0xBA, 0xD1, 0xDE, 0xA} HOSTFS = []byte{0x00, 0xc0, 0xff, 0xee} HPFS = []byte{0xf9, 0x95, 0xe8, 0x49} HUGETLBFS = []byte{0x95, 0x84, 0x58, 0xf6} JFFS2 = []byte{0x72, 0xb6} JFS = []byte{0x31, 0x53, 0x46, 0x4a} MTD = []byte{0x11, 0x30, 0x78, 0x54} NFS = []byte{0x69, 0x69} NILFS = []byte{0x34, 0x34} NSFS = []byte{0x6e, 0x73, 0x66, 0x73} // From docs, not tested. NTFS = []byte{0xeb, 0x52, 0x90, 'N', 'T', 'F', 'S', ' ', ' ', ' ', ' '} OCFS2 = []byte{0x74, 0x61, 0x63, 0x6f} OPENPROM = []byte{0x9f, 0xa1} OVERLAYFS = []byte{0x79, 0x4c, 0x76, 0x30} PIPEFS = []byte{0x50, 0x49, 0x50, 0x45} PROC = []byte{0x9f, 0xa0} PSTOREFS = []byte{0x61, 0x65, 0x67, 0x6C} QNX4 = []byte{0x00, 0x2f} QNX6 = []byte{0x68, 0x19, 0x11, 0x22} RAMFS = []byte{0x85, 0x84, 0x58, 0xf6} RDTGROUP = []byte{0x76, 0x55, 0x82, 1} ROMFS = []byte{0x72, 0x75} SECURITYFS = []byte{0x73, 0x63, 0x66, 0x73} SELINUX = []byte{0xf9, 0x7c, 0xff, 0x8c} SMACK = []byte{0x43, 0x41, 0x5d, 0x53} SMB = []byte{0x51, 0x7B} SOCKFS = []byte{0x53, 0x4F, 0x43, 0x4B} SYSFS = []byte{0x62, 0x65, 0x65, 0x72} TMPFS = []byte{0x01, 0x02, 0x19, 0x94} TRACEFS = []byte{0x74, 0x72, 0x61, 0x63} UBIFS = []byte{0x24, 0x05, 0x19, 0x05} UDF = []byte{0x15, 0x01, 0x33, 0x46} USBDEVICE = []byte{0x9f, 0xa2} V9FS = []byte{0x01, 0x02, 0x19, 0x97} XENFS = []byte{0xab, 0xba, 0x19, 0x74} ZONEFS = []byte{0x5a, 0x4f, 0x46, 0x53} ZSMALLOC = []byte{0x58, 0x29, 0x58, 0x29} )
These are inferred magic numbers from documents and partitions. Ones known to work are first, followed by a gap, followed by not tested ones. Please preserve this pattern.
Functions ¶
func FSFromBlock ¶
FSFromBlock determines the file system type of a block device. It returns a string and an error. The error can be for an IO operation, an unknown magic number, or a magic with an unsupported file system. There is still a question here about whether this ought to act like a map and return a bool, not an error, since there are so many bogus block devices and we don't care about most of them.
func FindFileSystem ¶
FindFileSystem returns nil if a file system is available for use.
It rereads /proc/filesystems each time as the supported file systems can change as modules are added and removed.
func FindMagics ¶
func FindMagics(blk []byte) []magic
FindMagics finds all the magics matching a magic number.
func GetBlockFilesystems ¶
GetBlockFilesystems returns the supported file systems for block devices.
func IsTmpRamfs ¶
IsTmpRamfs tells if the file path given is under a tmpfs or ramfs.
func MoveMount ¶
MoveMount moves a mount from oldPath to newPath.
This function is just a wrapper around the MOUNT syscall with the MOVE flag supplied.
func SameFilesystem ¶
SameFilesystem returns true if both paths reside in the same filesystem. This is achieved by comparing Stat_t.Dev, which contains the fs device's major/minor numbers.
func SwitchRoot ¶
SwitchRoot makes newRootDir the new root directory of the system.
To be exact, it makes newRootDir the new root directory of the calling process's mount namespace.
It moves special mounts (dev, proc, sys, run) to the new directory, then does a chroot, moves the root mount to the new directory and finally DELETES EVERYTHING in the old root and execs the given init.
func Unmount ¶
Unmount detaches any file system mounted at path.
force forces an unmount regardless of currently open or otherwise used files within the file system to be unmounted.
lazy disallows future uses of any files below path -- i.e. it hides the file system mounted at path, but the file system itself is still active and any currently open files can continue to be used. When all references to files from this file system are gone, the file system will actually be unmounted.
Types ¶
type MountPoint ¶
MountPoint represents a mounted file system.
func Mount ¶
func Mount(dev, path, fsType, data string, flags uintptr) (*MountPoint, error)
Mount attaches the fsType file system at path.
dev is the device to mount (this is often the path of a block device, name of a file, or a placeholder string). data usually contains arguments for the specific file system.
func TryMount ¶
func TryMount(device, path, data string, flags uintptr) (*MountPoint, error)
TryMount tries to mount a device on the given mountpoint, trying in order the supported block device file systems on the system.
func (*MountPoint) Unmount ¶
func (mp *MountPoint) Unmount(flags uintptr) error
Unmount unmounts a file system that was previously mounted.
type Mounter ¶
type Mounter interface { // DevName returns the name of the device. DevName() string // Mount attaches the device at path. Mount(path string, flags uintptr) (*MountPoint, error) }
Mounter is a device that can be attached at a file system path.
type Pool ¶
type Pool struct { // List of items mounted by this pool. MountPoints []*MountPoint // contains filtered or unexported fields }
Pool keeps track of multiple MountPoint.
func (*Pool) Mount ¶
func (p *Pool) Mount(mounter Mounter, flags uintptr) (*MountPoint, error)
Mount mounts a file system using Mounter and returns the MountPoint. If the device has already been mounted, it is not mounted again.
Note the pool is keyed on Mounter.DevName() alone meaning DevName is used to determine whether it has already been mounted.
func (*Pool) UnmountAll ¶
UnmountAll umounts all the mountpoints from the pool. This makes a best-effort attempt to unmount everything and cleanup temporary directories. If this function fails, it can be re-tried.
Directories ¶
Path | Synopsis |
---|---|
Package block finds, mounts, and modifies block devices on Linux systems.
|
Package block finds, mounts, and modifies block devices on Linux systems. |
Package gpt implements reading and writing of GUID Partition tables.
|
Package gpt implements reading and writing of GUID Partition tables. |
Package loop provides an interface to interacting with Linux loop devices.
|
Package loop provides an interface to interacting with Linux loop devices. |
Chips are made by vendors, and an individual vendor is defined by a 1 to 8 byte vendor id stored in the chip.
|
Chips are made by vendors, and an individual vendor is defined by a 1 to 8 byte vendor id stored in the chip. |
Package scuzz supports direct access to SCSI or SATA devices.
|
Package scuzz supports direct access to SCSI or SATA devices. |