Documentation ¶
Index ¶
- Constants
- Variables
- func IsAnonymous(s StableAttr) bool
- func IsCharDevice(s StableAttr) bool
- func IsDir(s StableAttr) bool
- func IsFile(s StableAttr) bool
- func IsPipe(s StableAttr) bool
- func IsRegular(s StableAttr) bool
- func IsSocket(s StableAttr) bool
- func IsSymlink(s StableAttr) bool
- func ToDirentType(nodeType InodeType) uint8
- type AttrMask
- type BGFlags
- type BlockGroup
- type BlockGroup32Bit
- func (bg *BlockGroup32Bit) BlockBitmap() uint64
- func (bg *BlockGroup32Bit) BlockBitmapChecksum() uint32
- func (bg *BlockGroup32Bit) Checksum() uint16
- func (bg *BlockGroup32Bit) DirectoryCount() uint32
- func (bg *BlockGroup32Bit) ExclusionBitmap() uint64
- func (bg *BlockGroup32Bit) Flags() BGFlags
- func (bg *BlockGroup32Bit) FreeBlocksCount() uint32
- func (bg *BlockGroup32Bit) FreeInodesCount() uint32
- func (bg *BlockGroup32Bit) InodeBitmap() uint64
- func (bg *BlockGroup32Bit) InodeBitmapChecksum() uint32
- func (bg *BlockGroup32Bit) InodeTable() uint64
- func (bg *BlockGroup32Bit) SizeBytes() int
- func (bg *BlockGroup32Bit) UnmarshalBytes(src []byte) error
- func (bg *BlockGroup32Bit) UnusedInodeCount() uint32
- type BlockGroup64Bit
- func (bg *BlockGroup64Bit) BlockBitmap() uint64
- func (bg *BlockGroup64Bit) BlockBitmapChecksum() uint32
- func (bg *BlockGroup64Bit) DirectoryCount() uint32
- func (bg *BlockGroup64Bit) ExclusionBitmap() uint64
- func (bg *BlockGroup64Bit) FreeBlocksCount() uint32
- func (bg *BlockGroup64Bit) FreeInodesCount() uint32
- func (bg *BlockGroup64Bit) InodeBitmap() uint64
- func (bg *BlockGroup64Bit) InodeBitmapChecksum() uint32
- func (bg *BlockGroup64Bit) InodeTable() uint64
- func (bg *BlockGroup64Bit) SizeBytes() int
- func (bg *BlockGroup64Bit) UnmarshalBytes(src []byte) error
- func (bg *BlockGroup64Bit) UnusedInodeCount() uint32
- type CompatFeatures
- type Dirent
- type DirentNew
- type DirentOld
- type ExtType
- type Extent
- type ExtentEntry
- type ExtentEntryPair
- type ExtentHeader
- type ExtentIdx
- type ExtentNode
- type FileMode
- type FileOwner
- type FilePermissions
- func (f FilePermissions) AnyExecute() bool
- func (f FilePermissions) AnyRead() bool
- func (f FilePermissions) AnyWrite() bool
- func (f *FilePermissions) DropSetUIDAndMaybeGID()
- func (f FilePermissions) HasSetUIDOrGID() bool
- func (f FilePermissions) LinuxMode() FileMode
- func (f FilePermissions) OSMode() os.FileMode
- type FlagSet
- type IncompatFeatures
- type Inode
- type InodeFlags
- type InodeNew
- type InodeOld
- func (in *InodeOld) AccessTime() time.Time
- func (in *InodeOld) ChangeTime() time.Time
- func (in *InodeOld) Data() []byte
- func (in *InodeOld) DeletionTime() time.Time
- func (in *InodeOld) Flags() InodeFlags
- func (in *InodeOld) GID() uint32
- func (in *InodeOld) InodeSize() uint16
- func (in *InodeOld) LinksCount() uint16
- func (in *InodeOld) Mode() linux.FileMode
- func (in *InodeOld) ModificationTime() time.Time
- func (in *InodeOld) Size() uint64
- func (in *InodeOld) SizeBytes() int
- func (in *InodeOld) UID() uint32
- func (in *InodeOld) UnmarshalBytes(src []byte) error
- type InodeType
- type PermMask
- type RoCompatFeatures
- type SbRevision
- type StableAttr
- type Statx
- type SuperBlock
- type SuperBlock32Bit
- func (sb *SuperBlock32Bit) CompatibleFeatures() CompatFeatures
- func (sb *SuperBlock32Bit) ExtType() ExtType
- func (sb *SuperBlock32Bit) IncompatibleFeatures() IncompatFeatures
- func (sb *SuperBlock32Bit) InodeSize() uint16
- func (sb *SuperBlock32Bit) ReadOnlyCompatibleFeatures() RoCompatFeatures
- func (sb *SuperBlock32Bit) SizeBytes() int
- func (sb *SuperBlock32Bit) UnmarshalBytes(src []byte) error
- type SuperBlock64Bit
- type SuperBlockOld
- func (sb *SuperBlockOld) BgDescSize() uint16
- func (sb *SuperBlockOld) BlockSize() uint64
- func (sb *SuperBlockOld) BlocksCount() uint64
- func (sb *SuperBlockOld) BlocksPerGroup() uint32
- func (sb *SuperBlockOld) ClusterSize() uint64
- func (sb *SuperBlockOld) ClustersPerGroup() uint32
- func (sb *SuperBlockOld) CompatibleFeatures() CompatFeatures
- func (sb *SuperBlockOld) ExtType() ExtType
- func (sb *SuperBlockOld) FirstDataBlock() uint32
- func (sb *SuperBlockOld) FreeBlocksCount() uint64
- func (sb *SuperBlockOld) FreeInodesCount() uint32
- func (sb *SuperBlockOld) IncompatibleFeatures() IncompatFeatures
- func (sb *SuperBlockOld) InodeSize() uint16
- func (sb *SuperBlockOld) InodesCount() uint32
- func (sb *SuperBlockOld) InodesPerGroup() uint32
- func (sb *SuperBlockOld) Magic() uint16
- func (sb *SuperBlockOld) MaxMountCount() uint16
- func (sb *SuperBlockOld) MountCount() uint16
- func (sb *SuperBlockOld) ReadOnlyCompatibleFeatures() RoCompatFeatures
- func (sb *SuperBlockOld) Revision() SbRevision
- func (sb *SuperBlockOld) SizeBytes() int
- func (sb *SuperBlockOld) UnmarshalBytes(src []byte) error
- type UnstableAttr
- type ValueSet
Constants ¶
const ( S_IROTH = 0x4 S_IWOTH = 0x2 S_IXOTH = 0x1 )
const ( // BgInodeUninit indicates that inode table and bitmap are not initialized. BgInodeUninit uint16 = 0x1 // BgBlockUninit indicates that block bitmap is not initialized. BgBlockUninit uint16 = 0x2 // BgInodeZeroed indicates that inode table is zeroed. BgInodeZeroed uint16 = 0x4 )
These are the different block group flags.
const ( // MaxFileName is the maximum length of an ext fs file's name. MaxFileName = 255 // DirentSize is the size of ext dirent structures. DirentSize = 263 )
const ( // ExtentHeaderSize is the size of the header of an extent tree node. ExtentHeaderSize = 12 // ExtentEntrySize is the size of an entry in an extent tree node. // This size is the same for both leaf and internal nodes. ExtentEntrySize = 12 // ExtentMagic is the magic number which must be present in the header. ExtentMagic = 0xf30a )
const ( O_ACCMODE = 000000003 O_RDONLY = 000000000 O_WRONLY = 000000001 O_RDWR = 000000002 O_CREAT = 000000100 O_EXCL = 000000200 O_NOCTTY = 000000400 O_TRUNC = 000001000 O_APPEND = 000002000 O_NONBLOCK = 000004000 O_DSYNC = 000010000 O_ASYNC = 000020000 O_NOATIME = 001000000 O_CLOEXEC = 002000000 O_SYNC = 004000000 // __O_SYNC in Linux O_PATH = 010000000 O_TMPFILE = 020000000 // __O_TMPFILE in Linux )
Constants for open(2).
const ( MS_RDONLY = 0x1 MS_NOSUID = 0x2 MS_NODEV = 0x4 MS_NOEXEC = 0x8 MS_SYNCHRONOUS = 0x10 MS_REMOUNT = 0x20 MS_MANDLOCK = 0x40 MS_DIRSYNC = 0x80 MS_NOATIME = 0x400 MS_NODIRATIME = 0x800 MS_BIND = 0x1000 MS_MOVE = 0x2000 MS_REC = 0x4000 MS_POSIXACL = 0x10000 MS_UNBINDABLE = 0x20000 MS_PRIVATE = 0x40000 MS_SLAVE = 0x80000 MS_SHARED = 0x100000 MS_RELATIME = 0x200000 MS_KERNMOUNT = 0x400000 MS_I_VERSION = 0x800000 MS_STRICTATIME = 0x1000000 MS_MGC_VAL = 0xC0ED0000 MS_MGC_MSK = 0xffff0000 )
Constants for mount(2).
const ( MNT_FORCE = 0x1 MNT_DETACH = 0x2 MNT_EXPIRE = 0x4 UMOUNT_NOFOLLOW = 0x8 )
Constants for umount2(2).
const ( AT_SYMLINK_FOLLOW = 0x400 AT_EMPTY_PATH = 0x1000 )
Constants for linkat(2) and fchownat(2).
const ( UTIME_NOW = ((1 << 30) - 1) UTIME_OMIT = ((1 << 30) - 2) )
Special values for the ns field in utimensat(2).
const ( LOCK_SH = 1 // shared lock LOCK_EX = 2 // exclusive lock LOCK_NB = 4 // or'd with one of the above to prevent blocking LOCK_UN = 8 // remove lock )
Constants for flock(2).
const ( S_IFMT = 0170000 S_IFSOCK = 0140000 S_IFLNK = 0120000 S_IFREG = 0100000 S_IFBLK = 060000 S_IFDIR = 040000 S_IFCHR = 020000 S_IFIFO = 010000 FileTypeMask = S_IFMT ModeSocket = S_IFSOCK ModeSymlink = S_IFLNK ModeRegular = S_IFREG ModeBlockDevice = S_IFBLK ModeDirectory = S_IFDIR ModeCharacterDevice = S_IFCHR ModeNamedPipe = S_IFIFO S_ISUID = 04000 S_ISGID = 02000 S_ISVTX = 01000 ModeSetUID = S_ISUID ModeSetGID = S_ISGID ModeSticky = S_ISVTX ModeUserAll = 0700 ModeUserRead = 0400 ModeUserWrite = 0200 ModeUserExec = 0100 ModeGroupAll = 0070 ModeGroupRead = 0040 ModeGroupWrite = 0020 ModeGroupExec = 0010 ModeOtherAll = 0007 ModeOtherRead = 0004 ModeOtherWrite = 0002 ModeOtherExec = 0001 PermissionsMask = 0777 )
Values for mode_t.
const ( DT_UNKNOWN = 0 DT_FIFO = 1 DT_CHR = 2 DT_DIR = 4 DT_BLK = 6 DT_REG = 8 DT_LNK = 10 DT_SOCK = 12 DT_WHT = 14 )
Values for linux_dirent64.d_type.
const ( // NOTE(b/120162627): not implemented the RWF_HIPRI feature, but // the flag is accepted as a valid flag argument for preadv2/pwritev2 and // silently ignored. RWF_HIPRI = 0x00000001 RWF_DSYNC = 0x00000002 RWF_SYNC = 0x00000004 RWF_VALID = RWF_HIPRI | RWF_DSYNC | RWF_SYNC )
Values for preadv2/pwritev2.
const ( AT_STATX_SYNC_TYPE = 0x6000 AT_STATX_SYNC_AS_STAT = 0x0000 AT_STATX_FORCE_SYNC = 0x2000 AT_STATX_DONT_SYNC = 0x4000 )
Flags for statx.
const ( STATX_TYPE = 0x00000001 STATX_MODE = 0x00000002 STATX_NLINK = 0x00000004 STATX_UID = 0x00000008 STATX_GID = 0x00000010 STATX_ATIME = 0x00000020 STATX_MTIME = 0x00000040 STATX_CTIME = 0x00000080 STATX_INO = 0x00000100 STATX_SIZE = 0x00000200 STATX_BLOCKS = 0x00000400 STATX_BASIC_STATS = 0x000007ff STATX_BTIME = 0x00000800 STATX_ALL = 0x00000fff STATX__RESERVED = 0x80000000 )
Mask values for statx.
const ( STATX_ATTR_COMPRESSED = 0x00000004 STATX_ATTR_IMMUTABLE = 0x00000010 STATX_ATTR_APPEND = 0x00000020 STATX_ATTR_NODUMP = 0x00000040 STATX_ATTR_ENCRYPTED = 0x00000800 STATX_ATTR_AUTOMOUNT = 0x00001000 )
Bitmasks for Statx.Attributes and Statx.AttributesMask, from include/uapi/linux/stat.h.
const ( MFD_CLOEXEC = 0x0001 MFD_ALLOW_SEALING = 0x0002 )
Constants for memfd_create(2). Source: include/uapi/linux/memfd.h
const ( F_LINUX_SPECIFIC_BASE = 1024 F_ADD_SEALS = F_LINUX_SPECIFIC_BASE + 9 F_GET_SEALS = F_LINUX_SPECIFIC_BASE + 10 F_SEAL_SEAL = 0x0001 // Prevent further seals from being set. F_SEAL_SHRINK = 0x0002 // Prevent file from shrinking. F_SEAL_GROW = 0x0004 // Prevent file from growing. F_SEAL_WRITE = 0x0008 // Prevent writes. )
Constants related to file seals. Source: include/uapi/{asm-generic,linux}/fcntl.h
const ( FALLOC_FL_KEEP_SIZE = 0x01 FALLOC_FL_PUNCH_HOLE = 0x02 FALLOC_FL_NO_HIDE_STALE = 0x04 FALLOC_FL_COLLAPSE_RANGE = 0x08 FALLOC_FL_ZERO_RANGE = 0x10 FALLOC_FL_INSERT_RANGE = 0x20 FALLOC_FL_UNSHARE_RANGE = 0x40 )
Constants related to fallocate(2). Source: include/uapi/linux/falloc.h
const ( // InSync indicates that all writes to the file must be synchronous. InSync = 0x8 // InImmutable indicates that this file is immutable. InImmutable = 0x10 // InAppend indicates that this file can only be appended to. InAppend = 0x20 // InNoDump indicates that teh dump(1) utility should not dump this file. InNoDump = 0x40 // InNoAccessTime indicates that the access time of this inode must not be // updated. InNoAccessTime = 0x80 // InIndex indicates that this directory has hashed indexes. InIndex = 0x1000 // InJournalData indicates that file data must always be written through a // journal device. InJournalData = 0x4000 // InDirSync indicates that all the directory entiry data must be written // synchronously. InDirSync = 0x10000 // InTopDir indicates that this inode is at the top of the directory hierarchy. InTopDir = 0x20000 // InHugeFile indicates that this is a huge file. InHugeFile = 0x40000 // InExtents indicates that this inode uses extents. InExtents = 0x80000 // InExtendedAttr indicates that this inode stores a large extended attribute // value in its data blocks. InExtendedAttr = 0x200000 // InInline indicates that this inode has inline data. InInline = 0x10000000 // InReserved indicates that this inode is reserved for the ext4 library. InReserved = 0x80000000 )
Inode flags. This is not comprehensive and flags which were not used in the Linux kernel have been excluded.
const ( InUserReadFlagMask = 0x4BDFFF InUserWriteFlagMask = 0x4B80FF )
These masks define how users can view/modify inode flags. The rest of the flags are for internal kernel usage only.
const ( // SbDirPrealloc indicates directory preallocation. SbDirPrealloc = 0x1 // SbHasJournal indicates the presence of a journal. jbd2 should only work // with this being set. SbHasJournal = 0x4 // SbExtAttr indicates extended attributes support. SbExtAttr = 0x8 // SbResizeInode indicates that the fs has reserved GDT blocks (right after // group descriptors) for fs expansion. SbResizeInode = 0x10 // SbDirIndex indicates that the fs has directory indices. SbDirIndex = 0x20 // SbSparseV2 stands for Sparse superblock version 2. SbSparseV2 = 0x200 )
Superblock compatible features. This is not exhaustive, unused features are not listed.
const ( // SbDirentFileType indicates that directory entries record the file type. // We should use struct DirentNew for dirents then. SbDirentFileType = 0x2 // SbRecovery indicates that the filesystem needs recovery. SbRecovery = 0x4 // SbJournalDev indicates that the filesystem has a separate journal device. SbJournalDev = 0x8 // SbMetaBG indicates that the filesystem is using Meta block groups. Moves // the group descriptors from the congested first block group into the first // group of each metablock group to increase the maximum block groups limit // and hence support much larger filesystems. // // See https://www.kernel.org/doc/html/latest/filesystems/ext4/overview.html#meta-block-groups. SbMetaBG = 0x10 // SbExtents indicates that the filesystem uses extents. Must be set in ext4 // filesystems. SbExtents = 0x40 // SbIs64Bit indicates that this filesystem addresses blocks with 64-bits. // Hence can support 2^64 data blocks. SbIs64Bit = 0x80 // SbMMP indicates that this filesystem has multiple mount protection. // // See https://www.kernel.org/doc/html/latest/filesystems/ext4/globals.html#multiple-mount-protection. SbMMP = 0x100 // SbFlexBg indicates that this filesystem has flexible block groups. Several // block groups are tied into one logical block group so that all the metadata // for the block groups (bitmaps and inode tables) are close together for // faster loading. Consequently, large files will be continuous on disk. // However, this does not affect the placement of redundant superblocks and // group descriptors. // // See https://www.kernel.org/doc/html/latest/filesystems/ext4/overview.html#flexible-block-groups. SbFlexBg = 0x200 // SbLargeDir shows that large directory enabled. Directory htree can be 3 // levels deep. Directory htrees are allowed to be 2 levels deep otherwise. SbLargeDir = 0x4000 // SbInlineData allows inline data in inodes for really small files. SbInlineData = 0x8000 // SbEncrypted indicates that this fs contains encrypted inodes. SbEncrypted = 0x10000 Ext2FeatureIncompatSupp uint32 = SbDirentFileType | SbMetaBG Ext2FeatureIncompatUnsupported uint32 = ^Ext2FeatureIncompatSupp Ext3FeatureIncompatSupp uint32 = SbDirentFileType | SbRecovery | SbMetaBG Ext3FeatureIncompatUnsupported uint32 = ^Ext3FeatureIncompatSupp )
Superblock incompatible features. This is not exhaustive, unused features are not listed.
const ( // SbSparse indicates sparse superblocks. Only groups with number either 0 or // a power of 3, 5, or 7 will have redundant copies of the superblock and // block descriptors. SbSparse = 0x1 // SbLargeFile indicates that this fs has been used to store a file >= 2GiB. SbLargeFile = 0x2 // SbBtreeDir SbBtreeDir = 0x4 // SbHugeFile indicates that this fs contains files whose sizes are // represented in units of logicals blocks, not 512-byte sectors. SbHugeFile = 0x8 // SbGdtCsum indicates that group descriptors have checksums. SbGdtCsum = 0x10 // SbDirNlink indicates that the new subdirectory limit is 64,999. Ext3 has a // 32,000 subdirectory limit. SbDirNlink = 0x20 // SbExtraIsize indicates that large inodes exist on this filesystem. SbExtraIsize = 0x40 // SbHasSnapshot indicates the existence of a snapshot. SbHasSnapshot = 0x80 // SbQuota enables usage tracking for all quota types. SbQuota = 0x100 // SbBigalloc maps to the bigalloc feature. When set, the minimum allocation // unit becomes a cluster rather than a data block. Then block bitmaps track // clusters, not data blocks. // // See https://www.kernel.org/doc/html/latest/filesystems/ext4/overview.html#bigalloc. SbBigalloc = 0x200 // SbMetadataCsum indicates that the fs supports metadata checksumming. SbMetadataCsum = 0x400 // SbReadOnly marks this filesystem as readonly. Should refuse to mount in // read/write mode. SbReadOnly = 0x1000 Ext2FeatureRoCompatSupp uint32 = SbSparse | SbLargeFile | SbBtreeDir Ext2FeatureRoCompatUnsupported uint32 = ^Ext2FeatureRoCompatSupp Ext3FeatureRoCompatSupp uint32 = SbSparse | SbLargeFile | SbBtreeDir Ext3FeatureRoCompatUnsupported uint32 = ^Ext3FeatureRoCompatSupp )
Superblock readonly compatible features. This is not exhaustive, unused features are not listed.
const ( Ext2 = iota Ext3 Ext4 )
const (
AT_FDCWD = -100
)
Constants for all file-related ...at(2) syscalls.
const (
AT_REMOVEDIR = 0x200
)
Constants for unlinkat(2).
const (
AT_SYMLINK_NOFOLLOW = 0x100
)
Constants for fstatat(2).
const MaxSymlinkTraversals = 40
MaxSymlinkTraversals is the maximum number of links that will be followed by the kernel to resolve a symlink.
const (
// OldInodeSize is the inode size in ext2/ext3.
OldInodeSize = 128
)
const (
// RootDirInode is the inode number of the root directory inode.
RootDirInode = 2
)
Special inodes. See https://www.kernel.org/doc/html/latest/filesystems/ext4/overview.html#special-inodes.
const (
// SbOffset is the absolute offset at which the superblock is placed.
SbOffset = 1024
)
Variables ¶
var DirentType = ValueSet{ DT_UNKNOWN: "DT_UNKNOWN", DT_FIFO: "DT_FIFO", DT_CHR: "DT_CHR", DT_DIR: "DT_DIR", DT_BLK: "DT_BLK", DT_REG: "DT_REG", DT_LNK: "DT_LNK", DT_SOCK: "DT_SOCK", DT_WHT: "DT_WHT", }
DirentType are the friendly strings for linux_dirent64.d_type.
var RootOwner = FileOwner{
UID: 0,
GID: 0,
}
RootOwner corresponds to KUID/KGID 0/0.
Functions ¶
func IsAnonymous ¶
func IsAnonymous(s StableAttr) bool
IsAnonymous returns true if StableAttr.Type matches any type of anonymous.
func IsCharDevice ¶
func IsCharDevice(s StableAttr) bool
IsCharDevice returns true if StableAttr.Type matches a character device.
func IsDir ¶
func IsDir(s StableAttr) bool
IsDir returns true if StableAttr.Type matches any type of directory.
func IsFile ¶
func IsFile(s StableAttr) bool
IsFile returns true if StableAttr.Type matches any type of file.
func IsPipe ¶
func IsPipe(s StableAttr) bool
IsPipe returns true if StableAttr.Type matches any type of pipe.
func IsRegular ¶
func IsRegular(s StableAttr) bool
IsRegular returns true if StableAttr.Type matches a regular file.
func IsSocket ¶
func IsSocket(s StableAttr) bool
IsSocket returns true if StableAttr.Type matches any type of socket.
func IsSymlink ¶
func IsSymlink(s StableAttr) bool
IsSymlink returns true if StableAttr.Type matches a symlink.
func ToDirentType ¶
ToDirentType converts an InodeType to a linux dirent type field.
Types ¶
type AttrMask ¶
type AttrMask struct { Type bool DeviceID bool InodeID bool BlockSize bool Size bool Usage bool Perms bool UID bool GID bool AccessTime bool ModificationTime bool StatusChangeTime bool Links bool }
AttrMask contains fields to mask StableAttr and UnstableAttr.
+stateify savable
type BGFlags ¶
BGFlags represents all the different combinations of block group flags.
func BGFlagsFromInt ¶
BGFlagsFromInt converts the 16-bit flag representation to a BGFlags struct.
type BlockGroup ¶
type BlockGroup interface { common.Unmarshal // InodeTable returns the absolute block number of the block containing the // inode table. This points to an array of Inode structs. Inode tables are // statically allocated at mkfs time. The superblock records the number of // inodes per group (length of this table) and the size of each inode struct. InodeTable() uint64 // BlockBitmap returns the absolute block number of the block containing the // block bitmap. This bitmap tracks the usage of data blocks within this block // group and has its own checksum. BlockBitmap() uint64 // InodeBitmap returns the absolute block number of the block containing the // inode bitmap. This bitmap tracks the usage of this group's inode table // entries and has its own checksum. InodeBitmap() uint64 // ExclusionBitmap returns the absolute block number of the snapshot exclusion // bitmap. ExclusionBitmap() uint64 // FreeBlocksCount returns the number of free blocks in the group. FreeBlocksCount() uint32 // FreeInodesCount returns the number of free inodes in the group. FreeInodesCount() uint32 // DirectoryCount returns the number of inodes that represent directories // under this block group. DirectoryCount() uint32 // UnusedInodeCount returns the number of unused inodes beyond the last used // inode in this group's inode table. As a result, we needn’t scan past the // (InodesPerGroup - UnusedInodeCount())th entry in the inode table. UnusedInodeCount() uint32 // BlockBitmapChecksum returns the block bitmap checksum. This is calculated // using crc32c(FS UUID + group number + entire bitmap). BlockBitmapChecksum() uint32 // InodeBitmapChecksum returns the inode bitmap checksum. This is calculated // using crc32c(FS UUID + group number + entire bitmap). InodeBitmapChecksum() uint32 // Checksum returns this block group's checksum. // // If SbMetadataCsum feature is set: // - checksum is crc32c(FS UUID + group number + group descriptor // structure) & 0xFFFF. // // If SbGdtCsum feature is set: // - checksum is crc16(FS UUID + group number + group descriptor // structure). // // SbMetadataCsum and SbGdtCsum should not be both set. // If they are, Linux warns and asks to run fsck. Checksum() uint16 // Flags returns BGFlags which represents the block group flags. Flags() BGFlags }
BlockGroup represents a Linux ext block group descriptor. An ext file system is split into a series of block groups. This provides an access layer to information needed to access and use a block group.
Location:
- The block group descriptor table is always placed in the blocks immediately after the block containing the superblock.
- The 1st block group descriptor in the original table is in the (sb.FirstDataBlock() + 1)th block.
- See SuperBlock docs to see where the block group descriptor table is replicated.
- sb.BgDescSize() must be used as the block group descriptor entry size while reading the table from disk.
See https://www.kernel.org/doc/html/latest/filesystems/ext4/globals.html#block-group-descriptors.
type BlockGroup32Bit ¶
type BlockGroup32Bit struct { BlockBitmapLo uint32 `struc:"uint32,little"` InodeBitmapLo uint32 `struc:"uint32,little"` InodeTableLo uint32 `struc:"uint32,little"` FreeBlocksCountLo uint16 `struc:"uint16,little"` FreeInodesCountLo uint16 `struc:"uint16,little"` UsedDirsCountLo uint16 `struc:"uint16,little"` FlagsRaw uint16 `struc:"uint16,little"` ExcludeBitmapLo uint32 `struc:"uint32,little"` BlockBitmapChecksumLo uint16 `struc:"uint16,little"` InodeBitmapChecksumLo uint16 `struc:"uint16,little"` ItableUnusedLo uint16 `struc:"uint16,little"` ChecksumRaw uint16 `struc:"uint16,little"` }
BlockGroup32Bit emulates the first half of struct ext4_group_desc in fs/ext4/ext4.h. It is the block group descriptor struct for ext2, ext3 and 32-bit ext4 filesystems. It implements BlockGroup interface.
+marshal
func (*BlockGroup32Bit) BlockBitmap ¶
func (bg *BlockGroup32Bit) BlockBitmap() uint64
BlockBitmap implements BlockGroup.BlockBitmap.
func (*BlockGroup32Bit) BlockBitmapChecksum ¶
func (bg *BlockGroup32Bit) BlockBitmapChecksum() uint32
BlockBitmapChecksum implements BlockGroup.BlockBitmapChecksum.
func (*BlockGroup32Bit) Checksum ¶
func (bg *BlockGroup32Bit) Checksum() uint16
Checksum implements BlockGroup.Checksum.
func (*BlockGroup32Bit) DirectoryCount ¶
func (bg *BlockGroup32Bit) DirectoryCount() uint32
DirectoryCount implements BlockGroup.DirectoryCount.
func (*BlockGroup32Bit) ExclusionBitmap ¶
func (bg *BlockGroup32Bit) ExclusionBitmap() uint64
ExclusionBitmap implements BlockGroup.ExclusionBitmap.
func (*BlockGroup32Bit) Flags ¶
func (bg *BlockGroup32Bit) Flags() BGFlags
Flags implements BlockGroup.Flags.
func (*BlockGroup32Bit) FreeBlocksCount ¶
func (bg *BlockGroup32Bit) FreeBlocksCount() uint32
FreeBlocksCount implements BlockGroup.FreeBlocksCount.
func (*BlockGroup32Bit) FreeInodesCount ¶
func (bg *BlockGroup32Bit) FreeInodesCount() uint32
FreeInodesCount implements BlockGroup.FreeInodesCount.
func (*BlockGroup32Bit) InodeBitmap ¶
func (bg *BlockGroup32Bit) InodeBitmap() uint64
InodeBitmap implements BlockGroup.InodeBitmap.
func (*BlockGroup32Bit) InodeBitmapChecksum ¶
func (bg *BlockGroup32Bit) InodeBitmapChecksum() uint32
InodeBitmapChecksum implements BlockGroup.InodeBitmapChecksum.
func (*BlockGroup32Bit) InodeTable ¶
func (bg *BlockGroup32Bit) InodeTable() uint64
InodeTable implements BlockGroup.InodeTable.
func (*BlockGroup32Bit) SizeBytes ¶
func (bg *BlockGroup32Bit) SizeBytes() int
func (*BlockGroup32Bit) UnmarshalBytes ¶
func (bg *BlockGroup32Bit) UnmarshalBytes(src []byte) error
func (*BlockGroup32Bit) UnusedInodeCount ¶
func (bg *BlockGroup32Bit) UnusedInodeCount() uint32
UnusedInodeCount implements BlockGroup.UnusedInodeCount.
type BlockGroup64Bit ¶
type BlockGroup64Bit struct { // We embed the 32-bit struct here because 64-bit version is just an extension // of the 32-bit version. BlockGroup32Bit // 64-bit specific fields. BlockBitmapHi uint32 `struc:"uint32,little"` InodeBitmapHi uint32 `struc:"uint32,little"` InodeTableHi uint32 `struc:"uint32,little"` FreeBlocksCountHi uint16 `struc:"uint16,little"` FreeInodesCountHi uint16 `struc:"uint16,little"` UsedDirsCountHi uint16 `struc:"uint16,little"` ItableUnusedHi uint16 `struc:"uint16,little"` ExcludeBitmapHi uint32 `struc:"uint32,little"` BlockBitmapChecksumHi uint16 `struc:"uint16,little"` InodeBitmapChecksumHi uint16 `struc:"uint16,little"` Reserved uint32 `struc:"uint32,little"` }
BlockGroup64Bit emulates struct ext4_group_desc in fs/ext4/ext4.h. It is the block group descriptor struct for 64-bit ext4 filesystems. It implements BlockGroup interface. It is an extension of the 32-bit version of BlockGroup.
+marshal
func (*BlockGroup64Bit) BlockBitmap ¶
func (bg *BlockGroup64Bit) BlockBitmap() uint64
BlockBitmap implements BlockGroup.BlockBitmap.
func (*BlockGroup64Bit) BlockBitmapChecksum ¶
func (bg *BlockGroup64Bit) BlockBitmapChecksum() uint32
BlockBitmapChecksum implements BlockGroup.BlockBitmapChecksum.
func (*BlockGroup64Bit) DirectoryCount ¶
func (bg *BlockGroup64Bit) DirectoryCount() uint32
DirectoryCount implements BlockGroup.DirectoryCount.
func (*BlockGroup64Bit) ExclusionBitmap ¶
func (bg *BlockGroup64Bit) ExclusionBitmap() uint64
ExclusionBitmap implements BlockGroup.ExclusionBitmap.
func (*BlockGroup64Bit) FreeBlocksCount ¶
func (bg *BlockGroup64Bit) FreeBlocksCount() uint32
FreeBlocksCount implements BlockGroup.FreeBlocksCount.
func (*BlockGroup64Bit) FreeInodesCount ¶
func (bg *BlockGroup64Bit) FreeInodesCount() uint32
FreeInodesCount implements BlockGroup.FreeInodesCount.
func (*BlockGroup64Bit) InodeBitmap ¶
func (bg *BlockGroup64Bit) InodeBitmap() uint64
InodeBitmap implements BlockGroup.InodeBitmap.
func (*BlockGroup64Bit) InodeBitmapChecksum ¶
func (bg *BlockGroup64Bit) InodeBitmapChecksum() uint32
InodeBitmapChecksum implements BlockGroup.InodeBitmapChecksum.
func (*BlockGroup64Bit) InodeTable ¶
func (bg *BlockGroup64Bit) InodeTable() uint64
InodeTable implements BlockGroup.InodeTable.
func (*BlockGroup64Bit) SizeBytes ¶
func (bg *BlockGroup64Bit) SizeBytes() int
func (*BlockGroup64Bit) UnmarshalBytes ¶
func (bg *BlockGroup64Bit) UnmarshalBytes(src []byte) error
func (*BlockGroup64Bit) UnusedInodeCount ¶
func (bg *BlockGroup64Bit) UnusedInodeCount() uint32
UnusedInodeCount implements BlockGroup.UnusedInodeCount.
type CompatFeatures ¶
type CompatFeatures struct { DirPrealloc bool HasJournal bool ExtAttr bool ResizeInode bool DirIndex bool SparseV2 bool }
CompatFeatures represents a superblock's compatible feature set. If the kernel does not understand any of these feature, it can still read/write to this fs.
func CompatFeaturesFromInt ¶
func CompatFeaturesFromInt(f uint32) CompatFeatures
CompatFeaturesFromInt converts the integer representation of superblock compatible features to CompatFeatures struct.
func (CompatFeatures) ToInt ¶
func (f CompatFeatures) ToInt() uint32
ToInt converts superblock compatible features back to its 32-bit rep.
type Dirent ¶
type Dirent interface { common.Unmarshal // Inode returns the absolute inode number of the underlying inode. // Inode number 0 signifies an unused dirent. Inode() uint32 // RecordSize returns the record length of this dirent on disk. The next // dirent in the dirent list should be read after these many bytes from // the current dirent. Must be a multiple of 4. RecordSize() uint16 // FileName returns the name of the file. Can be at most 255 is length. Name() string // FileType returns the inode type of the underlying inode. This is a // performance hack so that we do not have to read the underlying inode struct // to know the type of inode. This will only work when the SbDirentFileType // feature is set. If not, the second returned value will be false indicating // that user code has to use the inode mode to extract the file type. FileType() (InodeType, bool) }
The Dirent interface should be implemented by structs representing ext directory entries. These are for the linear classical directories which just store a list of dirent structs. A directory is a series of data blocks where is each data block contains a linear array of dirents. The last entry of the block has a record size that takes it to the end of the block. The end of the directory is when you read dirInode.Size() bytes from the blocks.
See https://www.kernel.org/doc/html/latest/filesystems/ext4/dynamic.html#linear-classic-directories.
type DirentNew ¶
type DirentNew struct { InodeNumber uint32 `struc:"uint32,little"` RecordLength uint16 `struc:"uint16,little"` NameLength uint8 `struc:"uint8,sizeof=FileNameRaw"` FileTypeRaw uint8 `struc:"uint8"` FileNameRaw [MaxFileName]byte `struc:"[]byte"` }
DirentNew represents the ext4 directory entry struct. This emulates Linux's ext4_dir_entry_2 struct. The FileName can not be more than 255 bytes so we only need 8 bits to store the NameLength. As a result, NameLength has been shortened and the other 8 bits are used to encode the file type. Use the FileTypeRaw field only if the SbDirentFileType feature is set.
Note: This struct can be of variable size on disk. The one described below is of maximum size and the FileName beyond NameLength bytes might contain garbage.
+marshal
func (*DirentNew) RecordSize ¶
RecordSize implements Dirent.RecordSize.
func (*DirentNew) UnmarshalBytes ¶
type DirentOld ¶
type DirentOld struct { InodeNumber uint32 `struc:"uint32,little"` RecordLength uint16 `struc:"uint16,little"` NameLength uint16 `struc:"uint16,little"` FileNameRaw [MaxFileName]byte `struc:"[]byte"` }
DirentOld represents the old directory entry struct which does not contain the file type. This emulates Linux's ext4_dir_entry struct.
Note: This struct can be of variable size on disk. The one described below is of maximum size and the FileName beyond NameLength bytes might contain garbage.
+marshal
func (*DirentOld) RecordSize ¶
RecordSize implements Dirent.RecordSize.
func (*DirentOld) UnmarshalBytes ¶
type Extent ¶
type Extent struct { FirstFileBlock uint32 `struc:"uint32,little"` Length uint16 `struc:"uint16,little"` StartBlockHi uint16 `struc:"uint16,little"` StartBlockLo uint32 `struc:"uint32,little"` }
Extent represents the ext4_extent struct in ext4. Only present in leaf nodes. Sorted in ascending order based on FirstFileBlock since Linux does a binary search on this. This points to an array of data blocks containing the file data. It covers `Length` data blocks starting from `StartBlock`.
+marshal
func (*Extent) PhysicalBlock ¶
PhysicalBlock implements ExtentEntry.PhysicalBlock. It returns the physical block number of the first data block this extent covers.
func (*Extent) UnmarshalBytes ¶
type ExtentEntry ¶
type ExtentEntry interface { common.Unmarshal // FileBlock returns the first file block number covered by this entry. FileBlock() uint32 // PhysicalBlock returns the child physical block that this entry points to. PhysicalBlock() uint64 }
ExtentEntry represents an extent tree node entry. The entry can either be an ExtentIdx or Extent itself. This exists to simplify navigation logic.
type ExtentEntryPair ¶
type ExtentEntryPair struct { // Entry points to the child node on disk. Entry ExtentEntry // Node points to child node in memory. Is nil if the current node is a leaf. Node *ExtentNode }
ExtentEntryPair couples an in-memory ExtendNode with the ExtentEntry that points to it. We want to cache these structs in memory to avoid repeated disk reads.
Note: This struct itself does not represent an on-disk struct.
type ExtentHeader ¶
type ExtentHeader struct { // Magic in the extent magic number, must be 0xf30a. Magic uint16 `struc:"uint16,little"` // NumEntries indicates the number of valid entries following the header. NumEntries uint16 `struc:"uint16,little"` // MaxEntries that could follow the header. Used while adding entries. MaxEntries uint16 `struc:"uint16,little"` // Height represents the distance of this node from the farthest leaf. Please // note that Linux incorrectly calls this `Depth` (which means the distance // of the node from the root). Height uint16 `struc:"uint16,little"` Generation uint32 `struc:"uint32,little"` }
ExtentHeader emulates the ext4_extent_header struct in ext4. Each extent tree node begins with this and is followed by `NumEntries` number of:
- Extent if `Depth` == 0
- ExtentIdx otherwise
+marshal
func (*ExtentHeader) SizeBytes ¶
func (ex *ExtentHeader) SizeBytes() int
func (*ExtentHeader) UnmarshalBytes ¶
func (ex *ExtentHeader) UnmarshalBytes(src []byte) error
type ExtentIdx ¶
type ExtentIdx struct { FirstFileBlock uint32 `struc:"uint32,little"` ChildBlockLo uint32 `struc:"uint32,little"` ChildBlockHi uint16 `struc:"uint16,little"` Reserved uint16 `struc:"uint16,little"` }
ExtentIdx emulates the ext4_extent_idx struct in ext4. Only present in internal nodes. Sorted in ascending order based on FirstFileBlock since Linux does a binary search on this. This points to a block containing the child node.
+marshal
func (*ExtentIdx) PhysicalBlock ¶
PhysicalBlock implements ExtentEntry.PhysicalBlock. It returns the physical block number of the child block.
func (*ExtentIdx) UnmarshalBytes ¶
type ExtentNode ¶
type ExtentNode struct { Header ExtentHeader Entries []ExtentEntryPair }
ExtentNode represents an extent tree node. For internal nodes, all Entries will be ExtendIdxs. For leaf nodes, they will all be Extents.
Note: This struct itself does not represent an on-disk struct.
type FileMode ¶
type FileMode uint16
FileMode represents a mode_t.
func (FileMode) DirentType ¶
DirentType maps file types to dirent types appropriate for (struct dirent)::d_type.
func (FileMode) Permissions ¶
Permissions returns just the permission bits.
type FilePermissions ¶
type FilePermissions struct { User PermMask Group PermMask Other PermMask // Sticky, if set on directories, restricts renaming and deletion of // files in those directories to the directory owner, file owner, or // CAP_FOWNER. The sticky bit is ignored when set on other files. Sticky bool // SetUID executables can call UID-setting syscalls without CAP_SETUID. SetUID bool // SetGID executables can call GID-setting syscalls without CAP_SETGID. SetGID bool }
FilePermissions represents the permissions of a file, with Read/Write/Execute bits for user, group, and other.
+stateify savable
func FilePermsFromMode ¶
func FilePermsFromMode(mode FileMode) (fp FilePermissions)
FilePermsFromMode converts a system file mode to a FilePermissions struct.
func (FilePermissions) AnyExecute ¶
func (f FilePermissions) AnyExecute() bool
AnyExecute returns true if any of U/G/O have the execute bit set.
func (FilePermissions) AnyRead ¶
func (f FilePermissions) AnyRead() bool
AnyRead returns true if any of U/G/O have the read bit set.
func (FilePermissions) AnyWrite ¶
func (f FilePermissions) AnyWrite() bool
AnyWrite returns true if any of U/G/O have the write bit set.
func (*FilePermissions) DropSetUIDAndMaybeGID ¶
func (f *FilePermissions) DropSetUIDAndMaybeGID()
DropSetUIDAndMaybeGID turns off setuid, and turns off setgid if f allows group execution.
func (FilePermissions) HasSetUIDOrGID ¶
func (f FilePermissions) HasSetUIDOrGID() bool
HasSetUIDOrGID returns true if either the setuid or setgid bit is set.
func (FilePermissions) LinuxMode ¶
func (f FilePermissions) LinuxMode() FileMode
LinuxMode returns the linux mode_t representation of these permissions.
func (FilePermissions) OSMode ¶
func (f FilePermissions) OSMode() os.FileMode
OSMode returns the Go runtime's OS independent os.FileMode representation of these permissions.
type IncompatFeatures ¶
type IncompatFeatures struct { DirentFileType bool Recovery bool JournalDev bool MetaBG bool Extents bool Is64Bit bool MMP bool FlexBg bool LargeDir bool InlineData bool Encrypted bool }
IncompatFeatures represents a superblock's incompatible feature set. If the kernel does not understand any of these feature, it should refuse to mount.
func IncompatFeaturesFromInt ¶
func IncompatFeaturesFromInt(f uint32) IncompatFeatures
IncompatFeaturesFromInt converts the integer representation of superblock incompatible features to IncompatFeatures struct.
func (IncompatFeatures) ToInt ¶
func (f IncompatFeatures) ToInt() uint32
ToInt converts superblock incompatible features back to its 32-bit rep.
type Inode ¶
type Inode interface { common.Unmarshal // Mode returns the linux file mode which is majorly used to extract // information like: // - File permissions (read/write/execute by user/group/others). // - Sticky, set UID and GID bits. // - File type. // // Masks to extract this information are provided in pkg/abi/linux/file.go. Mode() linux.FileMode // UID returns the owner UID. UID() uint32 // GID returns the owner GID. GID() uint32 // Size returns the size of the file in bytes. Size() uint64 // InodeSize returns the size of this inode struct in bytes. // In ext2 and ext3, the inode struct and inode disk record size was fixed at // 128 bytes. Ext4 makes it possible for the inode struct to be bigger. // However, accessing any field beyond the 128 bytes marker must be verified // using this method. InodeSize() uint16 // AccessTime returns the last access time. Shows when the file was last read. // // If InExtendedAttr is set, then this should NOT be used because the // underlying field is used to store the extended attribute value checksum. AccessTime() time.Time // ChangeTime returns the last change time. Shows when the file meta data // (like permissions) was last changed. // // If InExtendedAttr is set, then this should NOT be used because the // underlying field is used to store the lower 32 bits of the attribute // value’s reference count. ChangeTime() time.Time // ModificationTime returns the last modification time. Shows when the file // content was last modified. // // If InExtendedAttr is set, then this should NOT be used because // the underlying field contains the number of the inode that owns the // extended attribute. ModificationTime() time.Time // DeletionTime returns the deletion time. Inodes are marked as deleted by // writing to the underlying field. FS tools can restore files until they are // actually overwritten. DeletionTime() time.Time // LinksCount returns the number of hard links to this inode. // // Normally there is an upper limit on the number of hard links: // - ext2/ext3 = 32,000 // - ext4 = 65,000 // // This implies that an ext4 directory cannot have more than 64,998 // subdirectories because each subdirectory will have a hard link to the // directory via the `..` entry. The directory has hard link via the `.` entry // of its own. And finally the inode is initiated with 1 hard link (itself). // // The underlying value is reset to 1 if all the following hold: // - Inode is a directory. // - SbDirNlink is enabled. // - Number of hard links is incremented past 64,999. // Hard link value of 1 for a directory would indicate that the number of hard // links is unknown because a directory can have minimum 2 hard links (itself // and `.` entry). LinksCount() uint16 // Flags returns InodeFlags which represents the inode flags. Flags() InodeFlags // Data returns the underlying inode.i_block array as a slice so it's // modifiable. This field is special and is used to store various kinds of // things depending on the filesystem version and inode type. The underlying // field name in Linux is a little misleading. // - In ext2/ext3, it contains the block map. // - In ext4, it contains the extent tree root node. // - For inline files, it contains the file contents. // - For symlinks, it contains the link path (if it fits here). // // See https://www.kernel.org/doc/html/latest/filesystems/ext4/dynamic.html#the-contents-of-inode-i-block. Data() []byte }
The Inode interface must be implemented by structs representing ext inodes. The inode stores all the metadata pertaining to the file (except for the file name which is held by the directory entry). It does NOT expose all fields and should be extended if need be.
Some file systems (e.g. FAT) use the directory entry to store all this information. Ext file systems do not so that they can support hard links. However, ext4 cheats a little bit and duplicates the file type in the directory entry for performance gains.
See https://www.kernel.org/doc/html/latest/filesystems/ext4/dynamic.html#index-nodes.
type InodeFlags ¶
type InodeFlags struct { Sync bool Immutable bool Append bool NoDump bool NoAccessTime bool Index bool JournalData bool DirSync bool TopDir bool HugeFile bool Extents bool ExtendedAttr bool Inline bool Reserved bool }
InodeFlags represents all possible combinations of inode flags. It aims to cover the bit masks and provide a more user-friendly interface.
func InodeFlagsFromInt ¶
func InodeFlagsFromInt(f uint32) InodeFlags
InodeFlagsFromInt converts the integer representation of inode flags to a InodeFlags struct.
func (InodeFlags) ToInt ¶
func (f InodeFlags) ToInt() uint32
ToInt converts inode flags back to its 32-bit rep.
type InodeNew ¶
type InodeNew struct { InodeOld ExtraInodeSize uint16 `struc:"uint16,little"` ChecksumHi uint16 `struc:"uint16,little"` ChangeTimeExtra uint32 `struc:"uint32,little"` ModificationTimeExtra uint32 `struc:"uint32,little"` AccessTimeExtra uint32 `struc:"uint32,little"` CreationTime uint32 `struc:"uint32,little"` CreationTimeExtra uint32 `struc:"uint32,little"` VersionHi uint32 `struc:"uint32,little"` ProjectID uint32 `struc:"uint32,little"` }
InodeNew represents ext4 inode structure which can be bigger than OldInodeSize. The actual size of this struct should be determined using inode.ExtraInodeSize. Accessing any field here should be verified with the actual size. The extra space between the end of the inode struct and end of the inode record can be used to store extended attr.
If the TimeExtra fields are in scope, the lower 2 bits of those are used to extend their counter part to be 34 bits wide; the rest (upper) 30 bits are used to provide nanoscond precision. Hence, these timestamps will now overflow in May 2446. See https://www.kernel.org/doc/html/latest/filesystems/ext4/dynamic.html#inode-timestamps.
+marshal
func (*InodeNew) AccessTime ¶
AccessTime implements Inode.AccessTime.
func (*InodeNew) ChangeTime ¶
ChangeTime implements Inode.ChangeTime.
func (*InodeNew) ModificationTime ¶
ModificationTime implements Inode.ModificationTime.
func (*InodeNew) UnmarshalBytes ¶
type InodeOld ¶
type InodeOld struct { ModeRaw uint16 `struc:"uint16,little"` UIDLo uint16 `struc:"uint16,little"` SizeLo uint32 `struc:"uint32,little"` // The time fields are signed integers because they could be negative to // represent time before the epoch. AccessTimeRaw int32 `struc:"uint32,little"` ChangeTimeRaw int32 `struc:"uint32,little"` ModificationTimeRaw int32 `struc:"uint32,little"` DeletionTimeRaw int32 `struc:"uint32,little"` GIDLo uint16 `struc:"uint16,little"` LinksCountRaw uint16 `struc:"uint16,little"` BlocksCountLo uint32 `struc:"uint32,little"` FlagsRaw uint32 `struc:"uint32,little"` VersionLo uint32 `struc:"uint32,little"` // This is OS dependent. DataRaw [60]byte `struc:"[60]byte,little"` Generation uint32 `struc:"uint32,little"` FileACLLo uint32 `struc:"uint32,little"` SizeHi uint32 `struc:"uint32,little"` ObsoFaddr uint32 `struc:"uint32,little"` // OS dependent fields have been inlined here. BlocksCountHi uint16 `struc:"uint16,little"` FileACLHi uint16 `struc:"uint16,little"` UIDHi uint16 `struc:"uint16,little"` GIDHi uint16 `struc:"uint16,little"` ChecksumLo uint16 `struc:"uint16,little"` Unused uint16 `struc:"uint16,little"` }
InodeOld implements Inode interface. It emulates ext2/ext3 inode struct. Inode struct size and record size are both 128 bytes for this.
All fields representing time are in seconds since the epoch. Which means that they will overflow in January 2038.
+marshal
func (*InodeOld) AccessTime ¶
AccessTime implements Inode.AccessTime.
func (*InodeOld) ChangeTime ¶
ChangeTime implements Inode.ChangeTime.
func (*InodeOld) DeletionTime ¶
DeletionTime implements Inode.DeletionTime.
func (*InodeOld) LinksCount ¶
LinksCount implements Inode.LinksCount.
func (*InodeOld) ModificationTime ¶
ModificationTime implements Inode.ModificationTime.
func (*InodeOld) UnmarshalBytes ¶
type InodeType ¶
type InodeType int
InodeType enumerates types of Inodes.
const ( // RegularFile is a regular file. RegularFile InodeType = iota // SpecialFile is a file that doesn't support SeekEnd. It is used for // things like proc files. SpecialFile // Directory is a directory. Directory // SpecialDirectory is a directory that *does* support SeekEnd. It's // the opposite of the SpecialFile scenario above. It similarly // supports proc files. SpecialDirectory // Symlink is a symbolic link. Symlink // Pipe is a pipe (named or regular). Pipe // Socket is a socket. Socket // CharacterDevice is a character device. CharacterDevice // BlockDevice is a block device. BlockDevice // Anonymous is an anonymous type when none of the above apply. // Epoll fds and event-driven fds fit this category. Anonymous )
func ToInodeType ¶
ToInodeType coverts a linux file type to InodeType.
type PermMask ¶
type PermMask struct { // Read indicates reading is permitted. Read bool // Write indicates writing is permitted. Write bool // Execute indicates execution is permitted. Execute bool }
PermMask are file access permissions.
+stateify savable
func PermsFromMode ¶
PermsFromMode takes the Other permissions (last 3 bits) of a FileMode and returns a set of PermMask.
func (PermMask) Mode ¶
Mode returns the system mode (unix.S_IXOTH, etc.) for these permissions in the "other" bits.
func (PermMask) SupersetOf ¶
SupersetOf returns true iff the permissions in p are a superset of the permissions in other.
type RoCompatFeatures ¶
type RoCompatFeatures struct { Sparse bool LargeFile bool HugeFile bool GdtCsum bool DirNlink bool ExtraIsize bool HasSnapshot bool Quota bool Bigalloc bool MetadataCsum bool ReadOnly bool }
RoCompatFeatures represents a superblock's readonly compatible feature set. If the kernel does not understand any of these feature, it can still mount readonly. But if the user wants to mount read/write, the kernel should refuse to mount.
func RoCompatFeaturesFromInt ¶
func RoCompatFeaturesFromInt(f uint32) RoCompatFeatures
RoCompatFeaturesFromInt converts the integer representation of superblock readonly compatible features to RoCompatFeatures struct.
func (RoCompatFeatures) ToInt ¶
func (f RoCompatFeatures) ToInt() uint32
ToInt converts superblock readonly compatible features to its 32-bit rep.
type SbRevision ¶
type SbRevision uint32
SbRevision is the type for superblock revisions.
const ( // OldRev is the good old (original) format. OldRev SbRevision = 0 // DynamicRev is v2 format w/ dynamic inode sizes. DynamicRev SbRevision = 1 )
Super block revisions.
type StableAttr ¶
type StableAttr struct { // Type is the InodeType of a InodeOperations. Type InodeType // DeviceID is the device on which a InodeOperations resides. DeviceID uint64 // InodeID uniquely identifies InodeOperations on its device. InodeID uint64 // BlockSize is the block size of data backing this InodeOperations. BlockSize int64 // DeviceFileMajor is the major device number of this Node, if it is a // device file. DeviceFileMajor uint16 // DeviceFileMinor is the minor device number of this Node, if it is a // device file. DeviceFileMinor uint32 }
StableAttr contains Inode attributes that will be stable throughout the lifetime of the Inode.
+stateify savable
type Statx ¶
type Statx struct { Mask uint32 Blksize uint32 Attributes uint64 Nlink uint32 UID uint32 GID uint32 Mode uint16 Ino uint64 Size uint64 Blocks uint64 AttributesMask uint64 Atime uint32 Btime uint32 Ctime uint32 Mtime uint32 RdevMajor uint32 RdevMinor uint32 DevMajor uint32 DevMinor uint32 // contains filtered or unexported fields }
Statx represents struct statx.
+marshal
type SuperBlock ¶
type SuperBlock interface { common.Unmarshal // InodesCount returns the total number of inodes in this filesystem. InodesCount() uint32 // BlocksCount returns the total number of data blocks in this filesystem. BlocksCount() uint64 // FreeBlocksCount returns the number of free blocks in this filesystem. FreeBlocksCount() uint64 // FreeInodesCount returns the number of free inodes in this filesystem. FreeInodesCount() uint32 // MountCount returns the number of mounts since the last fsck. MountCount() uint16 // MaxMountCount returns the number of mounts allowed beyond which a fsck is // needed. MaxMountCount() uint16 // FirstDataBlock returns the absolute block number of the first data block, // which contains the super block itself. // // If the filesystem has 1kb data blocks then this should return 1. For all // other configurations, this typically returns 0. FirstDataBlock() uint32 // BlockSize returns the size of one data block in this filesystem. // This can be calculated by 2^(10 + sb.s_log_block_size). This ensures that // the smallest block size is 1kb. BlockSize() uint64 // BlocksPerGroup returns the number of data blocks in a block group. BlocksPerGroup() uint32 // ClusterSize returns block cluster size (set during mkfs time by admin). // This can be calculated by 2^(10 + sb.s_log_cluster_size). This ensures that // the smallest cluster size is 1kb. // // sb.s_log_cluster_size must equal sb.s_log_block_size if bigalloc feature // is NOT set and consequently BlockSize() = ClusterSize() in that case. ClusterSize() uint64 // ClustersPerGroup returns: // - number of clusters per group if bigalloc is enabled. // - BlocksPerGroup() otherwise. ClustersPerGroup() uint32 // InodeSize returns the size of the inode disk record size in bytes. Use this // to iterate over inode arrays on disk. // // In ext2 and ext3: // - Each inode had a disk record of 128 bytes. // - The inode struct size was fixed at 128 bytes. // // In ext4 its possible to allocate larger on-disk inodes: // - Inode disk record size = sb.s_inode_size (function return value). // = 256 (default) // - Inode struct size = 128 + inode.i_extra_isize. // = 128 + 32 = 160 (default) InodeSize() uint16 // InodesPerGroup returns the number of inodes in a block group. InodesPerGroup() uint32 // BgDescSize returns the size of the block group descriptor struct. // // In ext2, ext3, ext4 (without 64-bit feature), the block group descriptor // is only 32 bytes long. // In ext4 with 64-bit feature, the block group descriptor expands to AT LEAST // 64 bytes. It might be bigger than that. BgDescSize() uint16 // CompatibleFeatures returns the CompatFeatures struct which holds all the // compatible features this fs supports. CompatibleFeatures() CompatFeatures // IncompatibleFeatures returns the CompatFeatures struct which holds all the // incompatible features this fs supports. IncompatibleFeatures() IncompatFeatures // ReadOnlyCompatibleFeatures returns the CompatFeatures struct which holds all the // readonly compatible features this fs supports. ReadOnlyCompatibleFeatures() RoCompatFeatures // Magic() returns the magic signature which must be 0xef53. Magic() uint16 // Revision returns the superblock revision. Superblock struct fields from // offset 0x54 till 0x150 should only be used if superblock has DynamicRev. Revision() SbRevision // ExtType returns ext type ExtType() ExtType }
SuperBlock should be implemented by structs representing the ext superblock. The superblock holds a lot of information about the enclosing filesystem. This interface aims to provide access methods to important information held by the superblock. It does NOT expose all fields of the superblock, only the ones necessary. This can be expanded when need be.
Location and replication:
- The superblock is located at offset 1024 in block group 0.
- Redundant copies of the superblock and group descriptors are kept in all groups if SbSparse feature flag is NOT set. If it is set, the replicas only exist in groups whose group number is either 0 or a power of 3, 5, or 7.
- There is also a sparse superblock feature v2 in which there are just two replicas saved in the block groups pointed by sb.s_backup_bgs.
Replicas should eventually be updated if the superblock is updated.
See https://www.kernel.org/doc/html/latest/filesystems/ext4/globals.html#super-block.
type SuperBlock32Bit ¶
type SuperBlock32Bit struct { // We embed the old superblock struct here because the 32-bit version is just // an extension of the old version. SuperBlockOld FirstInode uint32 `struc:"uint32,little"` InodeSizeRaw uint16 `struc:"uint16,little"` BlockGroupNumber uint16 `struc:"uint16,little"` FeatureCompat uint32 `struc:"uint32,little"` FeatureIncompat uint32 `struc:"uint32,little"` FeatureRoCompat uint32 `struc:"uint32,little"` UUID [16]byte `struc:"[16]byte"` VolumeName [16]byte `struc:"[16]byte"` LastMounted [64]byte `struc:"[64]byte"` AlgoUsageBitmap uint32 `struc:"uint32,little"` PreallocBlocks byte `struc:"byte,little"` PreallocDirBlocks byte `struc:"byte,little"` ReservedGdtBlocks uint16 `struc:"uint16,little"` JournalUUID [16]byte `struc:"[16]byte"` JournalInum uint32 `struc:"uint32,little"` JournalDev uint32 `struc:"uint32,little"` LastOrphan uint32 `struc:"uint32,little"` HashSeed [4]uint32 `struc:"[4]uint32,little"` DefaultHashVersion byte `struc:"byte"` JnlBackupType byte `struc:"byte"` BgDescSizeRaw uint16 `struc:"uint16,little"` DefaultMountOpts uint32 `struc:"uint32,little"` FirstMetaBg uint32 `struc:"uint32,little"` MkfsTime uint32 `struc:"uint32,little"` JnlBlocks [17]uint32 `struc:"[17]uint32,little"` }
SuperBlock32Bit implements SuperBlock and represents the 32-bit version of the ext4_super_block struct in fs/ext4/ext4.h. Should be used only if RevLevel = DynamicRev and 64-bit feature is disabled.
+marshal
func (*SuperBlock32Bit) CompatibleFeatures ¶
func (sb *SuperBlock32Bit) CompatibleFeatures() CompatFeatures
CompatibleFeatures implements SuperBlock.CompatibleFeatures.
func (*SuperBlock32Bit) ExtType ¶
func (sb *SuperBlock32Bit) ExtType() ExtType
ExtType implements SuperBlock.ExtType
func (*SuperBlock32Bit) IncompatibleFeatures ¶
func (sb *SuperBlock32Bit) IncompatibleFeatures() IncompatFeatures
IncompatibleFeatures implements SuperBlock.IncompatibleFeatures.
func (*SuperBlock32Bit) InodeSize ¶
func (sb *SuperBlock32Bit) InodeSize() uint16
InodeSize implements SuperBlock.InodeSize.
func (*SuperBlock32Bit) ReadOnlyCompatibleFeatures ¶
func (sb *SuperBlock32Bit) ReadOnlyCompatibleFeatures() RoCompatFeatures
ReadOnlyCompatibleFeatures implements SuperBlock.ReadOnlyCompatibleFeatures.
func (*SuperBlock32Bit) SizeBytes ¶
func (sb *SuperBlock32Bit) SizeBytes() int
func (*SuperBlock32Bit) UnmarshalBytes ¶
func (sb *SuperBlock32Bit) UnmarshalBytes(src []byte) error
type SuperBlock64Bit ¶
type SuperBlock64Bit struct { // We embed the 32-bit struct here because 64-bit version is just an extension // of the 32-bit version. SuperBlock32Bit BlocksCountHi uint32 `struc:"uint32,little"` ReservedBlocksCountHi uint32 `struc:"uint32,little"` FreeBlocksCountHi uint32 `struc:"uint32,little"` MinInodeSize uint16 `struc:"uint16,little"` WantInodeSize uint16 `struc:"uint16,little"` Flags uint32 `struc:"uint32,little"` RaidStride uint16 `struc:"uint16,little"` MmpInterval uint16 `struc:"uint16,little"` MmpBlock uint64 `struc:"uint64,little"` RaidStripeWidth uint32 `struc:"uint32,little"` LogGroupsPerFlex byte `struc:"byte"` ChecksumType byte `struc:"byte"` EncryptionLevel byte `struc:"byte"` ReservedPad byte `struc:"byte"` KbytesWritten uint64 `struc:"uint64,little"` SnapshotInum uint32 `struc:"uint32,little"` SnapshotID uint32 `struc:"uint32,little"` SnapshotRsrvBlocksCount uint64 `struc:"uint64,little"` SnapshotList uint32 `struc:"uint32,little"` ErrorCount uint32 `struc:"uint32,little"` FirstErrorTime uint32 `struc:"uint32,little"` FirstErrorInode uint32 `struc:"uint32,little"` FirstErrorBlock uint64 `struc:"uint64,little"` FirstErrorFunction [32]byte `struc:"[32]pad"` FirstErrorLine uint32 `struc:"uint32,little"` LastErrorTime uint32 `struc:"uint32,little"` LastErrorInode uint32 `struc:"uint32,little"` LastErrorLine uint32 `struc:"uint32,little"` LastErrorBlock uint64 `struc:"uint64,little"` LastErrorFunction [32]byte `struc:"[32]pad"` MountOpts [64]byte `struc:"[64]pad"` UserQuotaInum uint32 `struc:"uint32,little"` GroupQuotaInum uint32 `struc:"uint32,little"` OverheadBlocks uint32 `struc:"uint32,little"` BackupBgs [2]uint32 `struc:"[2]uint32,little"` EncryptAlgos [4]byte `struc:"[4]pad"` EncryptPwSalt [16]byte `struc:"[16]pad"` LostFoundInode uint32 `struc:"uint32,little"` ProjectQuotaInode uint32 `struc:"uint32,little"` ChecksumSeed uint32 `struc:"uint32,little"` WtimeHi byte `struc:"byte"` MtimeHi byte `struc:"byte"` MkfsTimeHi byte `struc:"byte"` LastCheckHi byte `struc:"byte"` FirstErrorTimeHi byte `struc:"byte"` LastErrorTimeHi byte `struc:"byte"` Reserved1 [2]byte `struc:"[2]pad"` Encoding uint16 `struc:"uint16,little"` EncodingFlags uint16 `struc:"uint16,little"` Reserved2 [95]uint32 `struc:"[95]uint32,little"` Checksum uint32 `struc:"uint32,little"` }
SuperBlock64Bit implements SuperBlock and represents the 64-bit version of the ext4_super_block struct in fs/ext4/ext4.h. This sums up to be exactly 1024 bytes (smallest possible block size) and hence the superblock always fits in no more than one data block. Should only be used when the 64-bit feature is set.
+marshal
func (*SuperBlock64Bit) BgDescSize ¶
func (sb *SuperBlock64Bit) BgDescSize() uint16
BgDescSize implements SuperBlock.BgDescSize.
func (*SuperBlock64Bit) BlocksCount ¶
func (sb *SuperBlock64Bit) BlocksCount() uint64
BlocksCount implements SuperBlock.BlocksCount.
func (*SuperBlock64Bit) ExtType ¶
func (sb *SuperBlock64Bit) ExtType() ExtType
ExtType implements SuperBlock.ExtType
func (*SuperBlock64Bit) FreeBlocksCount ¶
func (sb *SuperBlock64Bit) FreeBlocksCount() uint64
FreeBlocksCount implements SuperBlock.FreeBlocksCount.
func (*SuperBlock64Bit) SizeBytes ¶
func (sb *SuperBlock64Bit) SizeBytes() int
func (*SuperBlock64Bit) UnmarshalBytes ¶
func (sb *SuperBlock64Bit) UnmarshalBytes(src []byte) error
type SuperBlockOld ¶
type SuperBlockOld struct { InodesCountRaw uint32 `struc:"uint32,little"` BlocksCountLo uint32 `struc:"uint32,little"` ReservedBlocksCount uint32 `struc:"uint32,little"` FreeBlocksCountLo uint32 `struc:"uint32,little"` FreeInodesCountRaw uint32 `struc:"uint32,little"` FirstDataBlockRaw uint32 `struc:"uint32,little"` LogBlockSize uint32 `struc:"uint32,little"` LogClusterSize uint32 `struc:"uint32,little"` BlocksPerGroupRaw uint32 `struc:"uint32,little"` ClustersPerGroupRaw uint32 `struc:"uint32,little"` InodesPerGroupRaw uint32 `struc:"uint32,little"` Mtime uint32 `struc:"uint32,little"` Wtime uint32 `struc:"uint32,little"` MountCountRaw uint16 `struc:"uint16,little"` MaxMountCountRaw uint16 `struc:"uint16,little"` MagicRaw uint16 `struc:"uint16,little"` State uint16 `struc:"uint16,little"` Errors uint16 `struc:"uint16,little"` MinorRevLevel uint16 `struc:"uint16,little"` LastCheck uint32 `struc:"uint32,little"` CheckInterval uint32 `struc:"uint32,little"` CreatorOS uint32 `struc:"uint32,little"` RevLevel uint32 `struc:"uint32,little"` DefResUID uint16 `struc:"uint16,little"` DefResGID uint16 `struc:"uint16,little"` }
SuperBlockOld implements SuperBlock and represents the old version of the superblock struct. Should be used only if RevLevel = OldRev.
+marshal
func (*SuperBlockOld) BgDescSize ¶
func (sb *SuperBlockOld) BgDescSize() uint16
BgDescSize implements SuperBlock.BgDescSize.
func (*SuperBlockOld) BlockSize ¶
func (sb *SuperBlockOld) BlockSize() uint64
BlockSize implements SuperBlock.BlockSize.
func (*SuperBlockOld) BlocksCount ¶
func (sb *SuperBlockOld) BlocksCount() uint64
BlocksCount implements SuperBlock.BlocksCount.
func (*SuperBlockOld) BlocksPerGroup ¶
func (sb *SuperBlockOld) BlocksPerGroup() uint32
BlocksPerGroup implements SuperBlock.BlocksPerGroup.
func (*SuperBlockOld) ClusterSize ¶
func (sb *SuperBlockOld) ClusterSize() uint64
ClusterSize implements SuperBlock.ClusterSize.
func (*SuperBlockOld) ClustersPerGroup ¶
func (sb *SuperBlockOld) ClustersPerGroup() uint32
ClustersPerGroup implements SuperBlock.ClustersPerGroup.
func (*SuperBlockOld) CompatibleFeatures ¶
func (sb *SuperBlockOld) CompatibleFeatures() CompatFeatures
CompatibleFeatures implements SuperBlock.CompatibleFeatures.
func (*SuperBlockOld) ExtType ¶
func (sb *SuperBlockOld) ExtType() ExtType
ExtType implements SuperBlock.ExtType
func (*SuperBlockOld) FirstDataBlock ¶
func (sb *SuperBlockOld) FirstDataBlock() uint32
FirstDataBlock implements SuperBlock.FirstDataBlock.
func (*SuperBlockOld) FreeBlocksCount ¶
func (sb *SuperBlockOld) FreeBlocksCount() uint64
FreeBlocksCount implements SuperBlock.FreeBlocksCount.
func (*SuperBlockOld) FreeInodesCount ¶
func (sb *SuperBlockOld) FreeInodesCount() uint32
FreeInodesCount implements SuperBlock.FreeInodesCount.
func (*SuperBlockOld) IncompatibleFeatures ¶
func (sb *SuperBlockOld) IncompatibleFeatures() IncompatFeatures
IncompatibleFeatures implements SuperBlock.IncompatibleFeatures.
func (*SuperBlockOld) InodeSize ¶
func (sb *SuperBlockOld) InodeSize() uint16
InodeSize implements SuperBlock.InodeSize.
func (*SuperBlockOld) InodesCount ¶
func (sb *SuperBlockOld) InodesCount() uint32
InodesCount implements SuperBlock.InodesCount.
func (*SuperBlockOld) InodesPerGroup ¶
func (sb *SuperBlockOld) InodesPerGroup() uint32
InodesPerGroup implements SuperBlock.InodesPerGroup.
func (*SuperBlockOld) Magic ¶
func (sb *SuperBlockOld) Magic() uint16
Magic implements SuperBlock.Magic.
func (*SuperBlockOld) MaxMountCount ¶
func (sb *SuperBlockOld) MaxMountCount() uint16
MaxMountCount implements SuperBlock.MaxMountCount.
func (*SuperBlockOld) MountCount ¶
func (sb *SuperBlockOld) MountCount() uint16
MountCount implements SuperBlock.MountCount.
func (*SuperBlockOld) ReadOnlyCompatibleFeatures ¶
func (sb *SuperBlockOld) ReadOnlyCompatibleFeatures() RoCompatFeatures
ReadOnlyCompatibleFeatures implements SuperBlock.ReadOnlyCompatibleFeatures.
func (*SuperBlockOld) Revision ¶
func (sb *SuperBlockOld) Revision() SbRevision
Revision implements SuperBlock.Revision.
func (*SuperBlockOld) SizeBytes ¶
func (sb *SuperBlockOld) SizeBytes() int
func (*SuperBlockOld) UnmarshalBytes ¶
func (sb *SuperBlockOld) UnmarshalBytes(src []byte) error
type UnstableAttr ¶
type UnstableAttr struct { // Size is the file size in bytes. Size int64 // Usage is the actual data usage in bytes. Usage int64 // Perms is the protection (read/write/execute for user/group/other). Perms FilePermissions // Owner describes the ownership of this file. Owner FileOwner // AccessTime is the time of last access AccessTime uint32 // ModificationTime is the time of last modification. ModificationTime uint32 // StatusChangeTime is the time of last attribute modification. StatusChangeTime uint32 // Links is the number of hard links. Links uint64 }
UnstableAttr contains Inode attributes that may change over the lifetime of the Inode.
+stateify savable
type ValueSet ¶
ValueSet is a map of syscall values to their name. Parse will use the name or the value if unknown.
func (ValueSet) Parse ¶
Parse returns the name of the value associated with `val`. Unknown values are converted to hex.
func (ValueSet) ParseDecimal ¶
ParseDecimal returns the name of the value associated with `val`. Unknown values are converted to decimal.