gopkg.in/dotcloud/docker.v1@v1.13.1/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  		"overlay2",
    60  		"overlay",
    61  		"devicemapper",
    62  		"vfs",
    63  	}
    64  
    65  	// FsNames maps filesystem id to name of the filesystem.
    66  	FsNames = map[FsMagic]string{
    67  		FsMagicAufs:        "aufs",
    68  		FsMagicBtrfs:       "btrfs",
    69  		FsMagicCramfs:      "cramfs",
    70  		FsMagicExtfs:       "extfs",
    71  		FsMagicF2fs:        "f2fs",
    72  		FsMagicGPFS:        "gpfs",
    73  		FsMagicJffs2Fs:     "jffs2",
    74  		FsMagicJfs:         "jfs",
    75  		FsMagicNfsFs:       "nfs",
    76  		FsMagicOverlay:     "overlayfs",
    77  		FsMagicRAMFs:       "ramfs",
    78  		FsMagicReiserFs:    "reiserfs",
    79  		FsMagicSmbFs:       "smb",
    80  		FsMagicSquashFs:    "squashfs",
    81  		FsMagicTmpFs:       "tmpfs",
    82  		FsMagicUnsupported: "unsupported",
    83  		FsMagicVxFS:        "vxfs",
    84  		FsMagicXfs:         "xfs",
    85  		FsMagicZfs:         "zfs",
    86  	}
    87  )
    88  
    89  // GetFSMagic returns the filesystem id given the path.
    90  func GetFSMagic(rootpath string) (FsMagic, error) {
    91  	var buf syscall.Statfs_t
    92  	if err := syscall.Statfs(filepath.Dir(rootpath), &buf); err != nil {
    93  		return 0, err
    94  	}
    95  	return FsMagic(buf.Type), nil
    96  }
    97  
    98  // NewFsChecker returns a checker configured for the provied FsMagic
    99  func NewFsChecker(t FsMagic) Checker {
   100  	return &fsChecker{
   101  		t: t,
   102  	}
   103  }
   104  
   105  type fsChecker struct {
   106  	t FsMagic
   107  }
   108  
   109  func (c *fsChecker) IsMounted(path string) bool {
   110  	m, _ := Mounted(c.t, path)
   111  	return m
   112  }
   113  
   114  // NewDefaultChecker returns a check that parses /proc/mountinfo to check
   115  // if the specified path is mounted.
   116  func NewDefaultChecker() Checker {
   117  	return &defaultChecker{}
   118  }
   119  
   120  type defaultChecker struct {
   121  }
   122  
   123  func (c *defaultChecker) IsMounted(path string) bool {
   124  	m, _ := mount.Mounted(path)
   125  	return m
   126  }
   127  
   128  // Mounted checks if the given path is mounted as the fs type
   129  func Mounted(fsType FsMagic, mountPath string) (bool, error) {
   130  	var buf syscall.Statfs_t
   131  	if err := syscall.Statfs(mountPath, &buf); err != nil {
   132  		return false, err
   133  	}
   134  	return FsMagic(buf.Type) == fsType, nil
   135  }