github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/daemon/graphdriver/driver_linux.go (about) 1 // +build linux 2 3 package graphdriver 4 5 import ( 6 "path/filepath" 7 "syscall" 8 9 "github.com/docker/docker/pkg/mount" 10 ) 11 12 const ( 13 // FsMagicAufs filesystem id for Aufs 14 FsMagicAufs = FsMagic(0x61756673) 15 // FsMagicBtrfs filesystem id for Btrfs 16 FsMagicBtrfs = FsMagic(0x9123683E) 17 // FsMagicCramfs filesystem id for Cramfs 18 FsMagicCramfs = FsMagic(0x28cd3d45) 19 // FsMagicEcryptfs filesystem id for eCryptfs 20 FsMagicEcryptfs = FsMagic(0xf15f) 21 // FsMagicExtfs filesystem id for Extfs 22 FsMagicExtfs = FsMagic(0x0000EF53) 23 // FsMagicF2fs filesystem id for F2fs 24 FsMagicF2fs = FsMagic(0xF2F52010) 25 // FsMagicGPFS filesystem id for GPFS 26 FsMagicGPFS = FsMagic(0x47504653) 27 // FsMagicJffs2Fs filesystem if for Jffs2Fs 28 FsMagicJffs2Fs = FsMagic(0x000072b6) 29 // FsMagicJfs filesystem id for Jfs 30 FsMagicJfs = FsMagic(0x3153464a) 31 // FsMagicNfsFs filesystem id for NfsFs 32 FsMagicNfsFs = FsMagic(0x00006969) 33 // FsMagicRAMFs filesystem id for RamFs 34 FsMagicRAMFs = FsMagic(0x858458f6) 35 // FsMagicReiserFs filesystem id for ReiserFs 36 FsMagicReiserFs = FsMagic(0x52654973) 37 // FsMagicSmbFs filesystem id for SmbFs 38 FsMagicSmbFs = FsMagic(0x0000517B) 39 // FsMagicSquashFs filesystem id for SquashFs 40 FsMagicSquashFs = FsMagic(0x73717368) 41 // FsMagicTmpFs filesystem id for TmpFs 42 FsMagicTmpFs = FsMagic(0x01021994) 43 // FsMagicVxFS filesystem id for VxFs 44 FsMagicVxFS = FsMagic(0xa501fcf5) 45 // FsMagicXfs filesystem id for Xfs 46 FsMagicXfs = FsMagic(0x58465342) 47 // FsMagicZfs filesystem id for Zfs 48 FsMagicZfs = FsMagic(0x2fc12fc1) 49 // FsMagicOverlay filesystem id for overlay 50 FsMagicOverlay = FsMagic(0x794C7630) 51 ) 52 53 var ( 54 // Slice of drivers that should be used in an order 55 priority = []string{ 56 "aufs", 57 "btrfs", 58 "zfs", 59 "devicemapper", 60 "overlay", 61 "vfs", 62 } 63 64 // FsNames maps filesystem id to name of the filesystem. 65 FsNames = map[FsMagic]string{ 66 FsMagicAufs: "aufs", 67 FsMagicBtrfs: "btrfs", 68 FsMagicCramfs: "cramfs", 69 FsMagicExtfs: "extfs", 70 FsMagicF2fs: "f2fs", 71 FsMagicGPFS: "gpfs", 72 FsMagicJffs2Fs: "jffs2", 73 FsMagicJfs: "jfs", 74 FsMagicNfsFs: "nfs", 75 FsMagicOverlay: "overlayfs", 76 FsMagicRAMFs: "ramfs", 77 FsMagicReiserFs: "reiserfs", 78 FsMagicSmbFs: "smb", 79 FsMagicSquashFs: "squashfs", 80 FsMagicTmpFs: "tmpfs", 81 FsMagicUnsupported: "unsupported", 82 FsMagicVxFS: "vxfs", 83 FsMagicXfs: "xfs", 84 FsMagicZfs: "zfs", 85 } 86 ) 87 88 // GetFSMagic returns the filesystem id given the path. 89 func GetFSMagic(rootpath string) (FsMagic, error) { 90 var buf syscall.Statfs_t 91 if err := syscall.Statfs(filepath.Dir(rootpath), &buf); err != nil { 92 return 0, err 93 } 94 return FsMagic(buf.Type), nil 95 } 96 97 // NewFsChecker returns a checker configured for the provied FsMagic 98 func NewFsChecker(t FsMagic) Checker { 99 return &fsChecker{ 100 t: t, 101 } 102 } 103 104 type fsChecker struct { 105 t FsMagic 106 } 107 108 func (c *fsChecker) IsMounted(path string) bool { 109 m, _ := Mounted(c.t, path) 110 return m 111 } 112 113 // NewDefaultChecker returns a check that parses /proc/mountinfo to check 114 // if the specified path is mounted. 115 func NewDefaultChecker() Checker { 116 return &defaultChecker{} 117 } 118 119 type defaultChecker struct { 120 } 121 122 func (c *defaultChecker) IsMounted(path string) bool { 123 m, _ := mount.Mounted(path) 124 return m 125 } 126 127 // Mounted checks if the given path is mounted as the fs type 128 func Mounted(fsType FsMagic, mountPath string) (bool, error) { 129 var buf syscall.Statfs_t 130 if err := syscall.Statfs(mountPath, &buf); err != nil { 131 return false, err 132 } 133 return FsMagic(buf.Type) == fsType, nil 134 }