github.com/mforkel/docker-ce-i386@v17.12.1-ce-rc2+incompatible/components/engine/daemon/graphdriver/driver_linux.go (about)

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