magic_linux.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright The containerd Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. Copyright 2013-2018 Docker, Inc.
  15. Licensed under the Apache License, Version 2.0 (the "License");
  16. you may not use this file except in compliance with the License.
  17. You may obtain a copy of the License at
  18. https://www.apache.org/licenses/LICENSE-2.0
  19. Unless required by applicable law or agreed to in writing, software
  20. distributed under the License is distributed on an "AS IS" BASIS,
  21. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. See the License for the specific language governing permissions and
  23. limitations under the License.
  24. */
  25. // Original source: https://github.com/moby/moby/blob/v26.0.0/daemon/graphdriver/driver_linux.go
  26. package fs
  27. import (
  28. "path/filepath"
  29. "syscall"
  30. )
  31. // Magic unsigned id of the filesystem in use.
  32. type Magic uint32
  33. const (
  34. // MagicUnsupported is a predefined constant value other than a valid filesystem id.
  35. MagicUnsupported = Magic(0x00000000)
  36. )
  37. const (
  38. // MagicAufs filesystem id for Aufs
  39. MagicAufs = Magic(0x61756673)
  40. // MagicBtrfs filesystem id for Btrfs
  41. MagicBtrfs = Magic(0x9123683E)
  42. // MagicCramfs filesystem id for Cramfs
  43. MagicCramfs = Magic(0x28cd3d45)
  44. // MagicEcryptfs filesystem id for eCryptfs
  45. MagicEcryptfs = Magic(0xf15f)
  46. // MagicExtfs filesystem id for Extfs
  47. MagicExtfs = Magic(0x0000EF53)
  48. // MagicF2fs filesystem id for F2fs
  49. MagicF2fs = Magic(0xF2F52010)
  50. // MagicGPFS filesystem id for GPFS
  51. MagicGPFS = Magic(0x47504653)
  52. // MagicJffs2Fs filesystem if for Jffs2Fs
  53. MagicJffs2Fs = Magic(0x000072b6)
  54. // MagicJfs filesystem id for Jfs
  55. MagicJfs = Magic(0x3153464a)
  56. // MagicNfsFs filesystem id for NfsFs
  57. MagicNfsFs = Magic(0x00006969)
  58. // MagicRAMFs filesystem id for RamFs
  59. MagicRAMFs = Magic(0x858458f6)
  60. // MagicReiserFs filesystem id for ReiserFs
  61. MagicReiserFs = Magic(0x52654973)
  62. // MagicSmbFs filesystem id for SmbFs
  63. MagicSmbFs = Magic(0x0000517B)
  64. // MagicSquashFs filesystem id for SquashFs
  65. MagicSquashFs = Magic(0x73717368)
  66. // MagicTmpFs filesystem id for TmpFs
  67. MagicTmpFs = Magic(0x01021994)
  68. // MagicVxFS filesystem id for VxFs
  69. MagicVxFS = Magic(0xa501fcf5)
  70. // MagicXfs filesystem id for Xfs
  71. MagicXfs = Magic(0x58465342)
  72. // MagicZfs filesystem id for Zfs
  73. MagicZfs = Magic(0x2fc12fc1)
  74. // MagicOverlay filesystem id for overlay
  75. MagicOverlay = Magic(0x794C7630)
  76. )
  77. var (
  78. // FsNames maps filesystem id to name of the filesystem.
  79. FsNames = map[Magic]string{
  80. MagicAufs: "aufs",
  81. MagicBtrfs: "btrfs",
  82. MagicCramfs: "cramfs",
  83. MagicExtfs: "extfs",
  84. MagicF2fs: "f2fs",
  85. MagicGPFS: "gpfs",
  86. MagicJffs2Fs: "jffs2",
  87. MagicJfs: "jfs",
  88. MagicNfsFs: "nfs",
  89. MagicOverlay: "overlayfs",
  90. MagicRAMFs: "ramfs",
  91. MagicReiserFs: "reiserfs",
  92. MagicSmbFs: "smb",
  93. MagicSquashFs: "squashfs",
  94. MagicTmpFs: "tmpfs",
  95. MagicUnsupported: "unsupported",
  96. MagicVxFS: "vxfs",
  97. MagicXfs: "xfs",
  98. MagicZfs: "zfs",
  99. }
  100. )
  101. // GetMagic returns the filesystem id given the path.
  102. func GetMagic(rootpath string) (Magic, error) {
  103. var buf syscall.Statfs_t
  104. if err := syscall.Statfs(filepath.Dir(rootpath), &buf); err != nil {
  105. return 0, err
  106. }
  107. return Magic(buf.Type), nil
  108. }