2018-02-05 16:05:59 -05:00
|
|
|
package graphdriver // import "github.com/docker/docker/daemon/graphdriver"
|
2015-01-15 16:40:39 -05:00
|
|
|
|
|
|
|
import (
|
2016-05-06 15:04:26 -04:00
|
|
|
"github.com/docker/docker/pkg/mount"
|
2017-05-23 10:22:32 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2015-01-15 16:40:39 -05:00
|
|
|
)
|
|
|
|
|
2015-04-24 15:35:51 -04:00
|
|
|
const (
|
2015-07-21 18:21:05 -04:00
|
|
|
// FsMagicAufs filesystem id for Aufs
|
|
|
|
FsMagicAufs = FsMagic(0x61756673)
|
|
|
|
// FsMagicBtrfs filesystem id for Btrfs
|
|
|
|
FsMagicBtrfs = FsMagic(0x9123683E)
|
|
|
|
// FsMagicCramfs filesystem id for Cramfs
|
|
|
|
FsMagicCramfs = FsMagic(0x28cd3d45)
|
2016-05-31 05:36:55 -04:00
|
|
|
// FsMagicEcryptfs filesystem id for eCryptfs
|
|
|
|
FsMagicEcryptfs = FsMagic(0xf15f)
|
2015-07-21 18:21:05 -04:00
|
|
|
// FsMagicExtfs filesystem id for Extfs
|
|
|
|
FsMagicExtfs = FsMagic(0x0000EF53)
|
|
|
|
// FsMagicF2fs filesystem id for F2fs
|
|
|
|
FsMagicF2fs = FsMagic(0xF2F52010)
|
2016-01-10 06:31:43 -05:00
|
|
|
// FsMagicGPFS filesystem id for GPFS
|
|
|
|
FsMagicGPFS = FsMagic(0x47504653)
|
2015-07-21 18:21:05 -04:00
|
|
|
// FsMagicJffs2Fs filesystem if for Jffs2Fs
|
|
|
|
FsMagicJffs2Fs = FsMagic(0x000072b6)
|
|
|
|
// FsMagicJfs filesystem id for Jfs
|
|
|
|
FsMagicJfs = FsMagic(0x3153464a)
|
|
|
|
// FsMagicNfsFs filesystem id for NfsFs
|
|
|
|
FsMagicNfsFs = FsMagic(0x00006969)
|
|
|
|
// FsMagicRAMFs filesystem id for RamFs
|
|
|
|
FsMagicRAMFs = FsMagic(0x858458f6)
|
|
|
|
// FsMagicReiserFs filesystem id for ReiserFs
|
2015-04-24 15:35:51 -04:00
|
|
|
FsMagicReiserFs = FsMagic(0x52654973)
|
2015-07-21 18:21:05 -04:00
|
|
|
// FsMagicSmbFs filesystem id for SmbFs
|
|
|
|
FsMagicSmbFs = FsMagic(0x0000517B)
|
|
|
|
// FsMagicSquashFs filesystem id for SquashFs
|
2015-04-24 15:35:51 -04:00
|
|
|
FsMagicSquashFs = FsMagic(0x73717368)
|
2015-07-21 18:21:05 -04:00
|
|
|
// FsMagicTmpFs filesystem id for TmpFs
|
|
|
|
FsMagicTmpFs = FsMagic(0x01021994)
|
|
|
|
// FsMagicVxFS filesystem id for VxFs
|
|
|
|
FsMagicVxFS = FsMagic(0xa501fcf5)
|
|
|
|
// FsMagicXfs filesystem id for Xfs
|
|
|
|
FsMagicXfs = FsMagic(0x58465342)
|
|
|
|
// FsMagicZfs filesystem id for Zfs
|
|
|
|
FsMagicZfs = FsMagic(0x2fc12fc1)
|
2016-03-09 16:23:04 -05:00
|
|
|
// FsMagicOverlay filesystem id for overlay
|
|
|
|
FsMagicOverlay = FsMagic(0x794C7630)
|
2020-02-09 11:42:08 -05:00
|
|
|
// FsMagicFUSE filesystem id for FUSE
|
|
|
|
FsMagicFUSE = FsMagic(0x65735546)
|
2015-04-24 15:35:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-11-15 16:54:56 -05:00
|
|
|
// List of drivers that should be used in an order
|
2020-02-09 11:42:08 -05:00
|
|
|
priority = "btrfs,zfs,overlay2,fuse-overlayfs,aufs,overlay,devicemapper,vfs"
|
2015-04-24 15:35:51 -04:00
|
|
|
|
2015-07-21 18:21:05 -04:00
|
|
|
// FsNames maps filesystem id to name of the filesystem.
|
2015-04-24 15:35:51 -04:00
|
|
|
FsNames = map[FsMagic]string{
|
|
|
|
FsMagicAufs: "aufs",
|
|
|
|
FsMagicBtrfs: "btrfs",
|
|
|
|
FsMagicCramfs: "cramfs",
|
2017-09-04 10:46:05 -04:00
|
|
|
FsMagicEcryptfs: "ecryptfs",
|
2015-04-24 15:35:51 -04:00
|
|
|
FsMagicExtfs: "extfs",
|
|
|
|
FsMagicF2fs: "f2fs",
|
2020-02-09 11:42:08 -05:00
|
|
|
FsMagicFUSE: "fuse",
|
2016-01-10 06:31:43 -05:00
|
|
|
FsMagicGPFS: "gpfs",
|
2015-04-24 15:35:51 -04:00
|
|
|
FsMagicJffs2Fs: "jffs2",
|
|
|
|
FsMagicJfs: "jfs",
|
|
|
|
FsMagicNfsFs: "nfs",
|
2016-09-22 08:26:41 -04:00
|
|
|
FsMagicOverlay: "overlayfs",
|
2015-07-21 18:21:05 -04:00
|
|
|
FsMagicRAMFs: "ramfs",
|
2015-04-24 15:35:51 -04:00
|
|
|
FsMagicReiserFs: "reiserfs",
|
|
|
|
FsMagicSmbFs: "smb",
|
|
|
|
FsMagicSquashFs: "squashfs",
|
|
|
|
FsMagicTmpFs: "tmpfs",
|
|
|
|
FsMagicUnsupported: "unsupported",
|
2015-07-24 04:37:56 -04:00
|
|
|
FsMagicVxFS: "vxfs",
|
2015-04-24 15:35:51 -04:00
|
|
|
FsMagicXfs: "xfs",
|
|
|
|
FsMagicZfs: "zfs",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-07-21 18:21:05 -04:00
|
|
|
// GetFSMagic returns the filesystem id given the path.
|
2015-01-15 16:40:39 -05:00
|
|
|
func GetFSMagic(rootpath string) (FsMagic, error) {
|
2017-05-23 10:22:32 -04:00
|
|
|
var buf unix.Statfs_t
|
2017-12-04 17:45:26 -05:00
|
|
|
if err := unix.Statfs(rootpath, &buf); err != nil {
|
2015-01-15 16:40:39 -05:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return FsMagic(buf.Type), nil
|
|
|
|
}
|
2016-03-09 16:23:04 -05:00
|
|
|
|
2017-05-21 19:24:07 -04:00
|
|
|
// NewFsChecker returns a checker configured for the provided FsMagic
|
2016-05-06 15:04:26 -04:00
|
|
|
func NewFsChecker(t FsMagic) Checker {
|
|
|
|
return &fsChecker{
|
|
|
|
t: t,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type fsChecker struct {
|
|
|
|
t FsMagic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *fsChecker) IsMounted(path string) bool {
|
|
|
|
m, _ := Mounted(c.t, path)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2016-05-06 16:09:45 -04:00
|
|
|
// NewDefaultChecker returns a check that parses /proc/mountinfo to check
|
|
|
|
// if the specified path is mounted.
|
|
|
|
func NewDefaultChecker() Checker {
|
|
|
|
return &defaultChecker{}
|
|
|
|
}
|
|
|
|
|
2016-05-06 15:04:26 -04:00
|
|
|
type defaultChecker struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *defaultChecker) IsMounted(path string) bool {
|
|
|
|
m, _ := mount.Mounted(path)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2016-03-09 16:23:04 -05:00
|
|
|
// Mounted checks if the given path is mounted as the fs type
|
|
|
|
func Mounted(fsType FsMagic, mountPath string) (bool, error) {
|
2017-05-23 10:22:32 -04:00
|
|
|
var buf unix.Statfs_t
|
|
|
|
if err := unix.Statfs(mountPath, &buf); err != nil {
|
2019-05-24 15:54:07 -04:00
|
|
|
if err == unix.ENOENT { // not exist, thus not mounted
|
|
|
|
err = nil
|
|
|
|
}
|
2016-03-09 16:23:04 -05:00
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return FsMagic(buf.Type) == fsType, nil
|
|
|
|
}
|