xfs

package
v0.0.0-...-1b22259 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Index

Constants

View Source
const (
	BMBT_EXNTFLAG_BITLEN = 1
	INODEV3_SIZE         = 176
	INODE_SIZE           = 96
	LEAF_ENTRY_SIZE      = 8

	XFS_DIR2_DATA_FD_COUNT  = 3
	XFS_DIR2_DATA_FREE_TAG  = 0xffff
	XFS_DIR2_DATA_ALIGN_LOG = 3

	XFS_SB_MAGIC         = 0x58465342
	XFS_AGF_MAGIC        = 0x58414746
	XFS_AGI_MAGIC        = 0x58414749
	XFS_AGFL_MAGIC       = 0x5841464c
	XFS_DINODE_MAGIC     = 0x494e
	XFS_DQUOT_MAGIC      = 0x4451
	XFS_SYMLINK_MAGIC    = 0x58534c4d
	XFS_ABTB_MAGIC       = 0x41425442
	XFS_ABTB_CRC_MAGIC   = 0x41423342
	XFS_ABTC_MAGIC       = 0x41425443
	XFS_ABTC_CRC_MAGIC   = 0x41423343
	XFS_IBT_MAGIC        = 0x49414254
	XFS_IBT_CRC_MAGIC    = 0x49414233
	XFS_FIBT_MAGIC       = 0x46494254
	XFS_FIBT_CRC_MAGIC   = 0x46494233
	XFS_BMAP_MAGICa      = 0x424d4150
	XFS_BMAP_CRC_MAGIC   = 0x424d4133
	XFS_DA_NODE_MAGIC    = 0xfebe
	XFS_DA3_NODE_MAGIC   = 0x3ebe
	XFS_DIR2_BLOCK_MAGIC = 0x58443242
	XFS_DIR3_BLOCK_MAGIC = 0x58444233 // XDB3 Block Directory Magic number
	XFS_DIR2_DATA_MAGIC  = 0x58443244
	XFS_DIR3_DATA_MAGIC  = 0x58444433 // XDD3 Leaf Directory Magic number
	XFS_DIR2_LEAF1_MAGIC = 0xd2f1
	XFS_DIR3_LEAF1_MAGIC = 0x3df1
	XFS_DIR2_LEAFN_MAGIC = 0xd2ff
	XFS_DIR3_LEAFN_MAGIC = 0x3dff
	XFS_DIR2_FREE_MAGIC  = 0x58443246
	XFS_DIR3_FREE_MAGIC  = 0x58444633
	XFS_ATTR_LEAF_MAGIC  = 0xfbee
	XFS_ATTR3_LEAF_MAGIC = 0x3bee
	XFS_ATTR3_RMT_MAGIC  = 0x5841524d
	XFS_RMAP_CRC_MAGIC   = 0x524d4233
	XFS_RTRMAP_CRC_MAGIC = 0x4d415052
	XFS_REFC_CRC_MAGIC   = 0x52334643
	XFS_MD_MAGIC         = 0x5846534d
)
View Source
const (
	XFS_SB_VERSION2_RESERVED1BIT   = 0x00000001
	XFS_SB_VERSION2_LAZYSBCOUNTBIT = 0x00000002 /* Superblk counters */
	XFS_SB_VERSION2_RESERVED4BIT   = 0x00000004
	XFS_SB_VERSION2_ATTR2BIT       = 0x00000008 /* Inline attr rework */
	XFS_SB_VERSION2_PARENTBIT      = 0x00000010 /* parent pointers */
	XFS_SB_VERSION2_PROJID32BIT    = 0x00000080 /* 32 bit project id */
	XFS_SB_VERSION2_CRCBIT         = 0x00000100 /* metadata CRCs */
	XFS_SB_VERSION2_FTYPE          = 0x00000200 /* inode type in dir */
)
View Source
const (
	XFS_DIR2_DATA_SPACE int64 = iota
	XFS_DIR2_LEAF_SPACE
	XFS_DIR2_FREE_SPACE
)
View Source
const (
	// typedef enum xfs_dinode_fmt
	XFS_DINODE_FMT_DEV = iota
	XFS_DINODE_FMT_LOCAL
	XFS_DINODE_FMT_EXTENTS
	XFS_DINODE_FMT_BTREE
	XFS_DINODE_FMT_UUID
	XFS_DINODE_FMT_RMAP
)

Variables

View Source
var (
	InodeSupportVersion = 3

	XFS_DIR2_SPACE_SIZE  = int64(1) << (32 + XFS_DIR2_DATA_ALIGN_LOG)
	XFS_DIR2_DATA_OFFSET = XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE
	XFS_DIR2_LEAF_OFFSET = XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE
	XFS_DIR2_FREE_OFFSET = XFS_DIR2_FREE_SPACE * XFS_DIR2_SPACE_SIZE
)
View Source
var (
	ErrReadSizeFormat   = "failed to read size error: actual(%d), expected(%d)"
	ErrSeekOffsetFormat = "failed to seek offset error: actual(%d), expected(%d)"
)
View Source
var (
	ErrOpenSymlink = xerrors.New("symlink open not support")
)

Functions

func Check

func Check(r io.Reader) bool

func Mask64Lo

func Mask64Lo(n int64) uint64

Types

type AB3B

type AB3B struct {
	BtreeShortBlock
}

type AB3C

type AB3C struct {
	BtreeShortBlock
}

type AG

type AG struct {
	SuperBlock SuperBlock
	Agi        AGI
	Agf        AGF
	Agfl       AGFL

	Ab3b AB3B
	Ab3c AB3C
	Iab3 IAB3
	Fib3 FIB3
}

func ParseAG

func ParseAG(reader io.Reader) (*AG, error)

type AGF

type AGF struct {
	Magicnum   uint32
	Versionnum uint32
	Seqno      uint32
	Length     uint32

	Roots  [3]uint32
	Levels [3]uint32

	Flfirst   uint32
	Fllast    uint32
	Flcount   uint32
	Freeblks  uint32
	Longest   uint32
	Btreeblks uint32
	UUID      [16]byte

	RmapBlocks     uint32
	RefcountBlocks uint32
	RefcountRoot   uint32
	RefcountLevel  uint32
	Spare64        [112]byte
	Lsn            uint64
	CRC            uint32
	Spare2         uint32
}

type AGFL

type AGFL struct {
	Magicnum uint32
	Seqno    uint32
	UUID     [16]byte
	Lsn      uint64
	CRC      uint32
	Bno      [118]uint32
}

type AGI

type AGI struct {
	Magicnum   uint32
	Versionnum uint32
	Seqno      uint32
	Length     uint32
	Count      uint32
	Root       uint32
	Level      uint32
	Freecount  uint32
	Newino     uint32
	Dirino     uint32
	Unlinked   [256]byte
	UUID       [16]byte
	CRC        uint32
	Pad32      uint32
	Lsn        uint64
	FreeRoot   uint32
	FreeLevel  uint32
	Iblocks    uint32
	Fblocks    uint32
}

type BmbrBlock

type BmbrBlock struct {
	Level   uint16
	Numrecs uint16
	// contains filtered or unexported fields
}

https://github.com/torvalds/linux/blob/d2b6f8a179194de0ffc4886ffc2c4358d86047b8/fs/xfs/libxfs/xfs_format.h#L1761

type BmbtPtr

type BmbtPtr uint64

type Btree

type Btree struct {
	// contains filtered or unexported fields
}

type BtreeBlock

type BtreeBlock struct {
	Magic      uint32
	Level      uint16 // tree level, 0 is leaf block.
	Numrecs    uint16
	BbLeftsib  int64
	BbRightsib int64

	// Long version header
	// https://github.com/torvalds/linux/blob/d2b6f8a179194de0ffc4886ffc2c4358d86047b8/fs/xfs/libxfs/xfs_format.h#L1855
	BbBlockNo uint64
	BbLsn     uint64
	UUID      [16]byte
	BbOwner   uint64
	CRC       uint32
	Padding   int32
}

BtreeBlock is almost BmbtBlock https://github.com/torvalds/linux/blob/d2b6f8a179194de0ffc4886ffc2c4358d86047b8/fs/xfs/libxfs/xfs_format.h#L1868

type BtreeShortBlock

type BtreeShortBlock struct {
	Magicnum uint32
	Level    uint16
	Numrecs  uint16
	Leftsib  uint32
	Rightsib uint32
	Blkno    uint64
	Lsn      uint64
	UUID     [16]byte
	Owner    uint32
	CRC      uint32
}

type Cache

type Cache[K comparable, V any] interface {
	// Add cache data
	Add(key K, value V) bool

	// Get returns key's value from the cache
	Get(key K) (value V, ok bool)
}

type Device

type Device struct{}

type Dir2Block

type Dir2Block struct {
	Header  Dir3DataHdr
	Entries []Dir2DataEntry

	UnusedEntries []Dir2DataUnused
	Leafs         []Dir2LeafEntry
	Tail          Dir2BlockTail
}

type Dir2BlockTail

type Dir2BlockTail struct {
	Count uint32
	Stale uint32
}

type Dir2DataEntry

type Dir2DataEntry struct {
	Inumber   uint64
	Namelen   uint8
	EntryName string
	Filetype  uint8
	Tag       uint16
}

https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/fs/xfs/libxfs/xfs_da_format.h#L339-L345

func (Dir2DataEntry) FileType

func (e Dir2DataEntry) FileType() uint8

func (Dir2DataEntry) InodeNumber

func (e Dir2DataEntry) InodeNumber() uint64

func (Dir2DataEntry) Name

func (e Dir2DataEntry) Name() string

type Dir2DataFree

type Dir2DataFree struct {
	Offset uint16
	Length uint16
}

type Dir2LeafEntry

type Dir2LeafEntry struct {
	Hashval uint32
	Address uint32
}

type Dir2SfEntry

type Dir2SfEntry struct {
	Namelen   uint8
	Offset    [2]uint8
	EntryName string
	Filetype  uint8
	Inumber   uint64
	Inumber32 uint32
}

https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/fs/xfs/libxfs/xfs_da_format.h#L209-L220

func (Dir2SfEntry) FileType

func (e Dir2SfEntry) FileType() uint8

func (Dir2SfEntry) InodeNumber

func (e Dir2SfEntry) InodeNumber() uint64

func (Dir2SfEntry) Name

func (e Dir2SfEntry) Name() string

type DirectoryExtents

type DirectoryExtents struct {
	// contains filtered or unexported fields
}

type DirectoryLocal

type DirectoryLocal struct {
	// contains filtered or unexported fields
}

type Entry

type Entry interface {
	Name() string
	FileType() uint8
	InodeNumber() uint64
}

type FIB3

type FIB3 struct {
	BtreeShortBlock
}

type File

type File struct {
	FileInfo
	// contains filtered or unexported fields
}

File is implemented io/fs File interface

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(buf []byte) (int, error)

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

type FileInfo

type FileInfo struct {
	// contains filtered or unexported fields
}

FileInfo is implemented io/fs FileInfo interface

func (FileInfo) IsDir

func (i FileInfo) IsDir() bool

func (FileInfo) ModTime

func (i FileInfo) ModTime() time.Time

func (FileInfo) Mode

func (i FileInfo) Mode() fs.FileMode

func (FileInfo) Name

func (i FileInfo) Name() string

func (FileInfo) Size

func (i FileInfo) Size() int64

func (FileInfo) Sys

func (i FileInfo) Sys() interface{}

type FileSystem

type FileSystem struct {
	PrimaryAG AG
	AGs       []AG
	// contains filtered or unexported fields
}

FileSystem is implemented io/fs FS interface

func NewFS

func NewFS(r io.SectionReader, cache Cache[string, any]) (*FileSystem, error)

func (*FileSystem) Close

func (xfs *FileSystem) Close() error

func (*FileSystem) Glob

func (xfs *FileSystem) Glob(pattern string) ([]string, error)

TODO: support GlobFS Interface

func (*FileSystem) Open

func (xfs *FileSystem) Open(name string) (fs.File, error)

func (*FileSystem) ParseInode

func (xfs *FileSystem) ParseInode(ino uint64) (*Inode, error)

func (*FileSystem) ReadDir

func (xfs *FileSystem) ReadDir(name string) ([]fs.DirEntry, error)

func (*FileSystem) ReadDirInfo

func (xfs *FileSystem) ReadDirInfo(name string) (fs.FileInfo, error)

func (*FileSystem) ReadFile

func (xfs *FileSystem) ReadFile(name string) ([]byte, error)

TODO: support ReadFile Interface

func (*FileSystem) Stat

func (xfs *FileSystem) Stat(name string) (fs.FileInfo, error)

type IAB3

type IAB3 struct {
	Header BtreeShortBlock
	Inodes []InobtRec
}

type InobtRec

type InobtRec struct {
	Startino  uint32
	Freecount uint32
	Free      uint64
}

type Inode

type Inode struct {
	// contains filtered or unexported fields
}

func (*Inode) AttributeOffset

func (i *Inode) AttributeOffset() uint32

type InodeCore

type InodeCore struct {
	Magic        uint16
	Mode         uint16
	Version      uint8
	Format       uint8
	OnLink       uint16
	UID          uint32
	GID          uint32
	NLink        uint32
	ProjId       uint16
	Padding      [8]byte
	Flushiter    uint16
	Atime        uint64
	Mtime        uint64
	Ctime        uint64
	Size         uint64
	Nblocks      uint64
	Extsize      uint32
	Nextents     uint32
	Anextents    uint16
	Forkoff      uint8
	Aformat      uint8
	Dmevmask     uint32
	Dmstate      uint16
	Flags        uint16
	Gen          uint32
	NextUnlinked uint32

	CRC         uint32
	Changecount uint64
	Lsn         uint64
	Flags2      uint64
	Cowextsize  uint32
	Padding2    [12]byte
	Crtime      uint64
	Ino         uint64
	MetaUUID    [16]byte
}

func (InodeCore) IsDir

func (ic InodeCore) IsDir() bool

func (InodeCore) IsRegular

func (ic InodeCore) IsRegular() bool

func (InodeCore) IsSocket

func (ic InodeCore) IsSocket() bool
func (ic InodeCore) IsSymlink() bool

type RegularExtent

type RegularExtent struct {
	// contains filtered or unexported fields
}

type SuperBlock

type SuperBlock struct {
	Magicnum   uint32
	BlockSize  uint32
	Dblocks    uint64
	Rblocks    uint64
	Rextens    uint64
	UUID       [16]byte
	Logstart   uint64
	Rootino    uint64
	Rbmino     uint64
	Rsmino     uint64
	Rextsize   uint32
	Agblocks   uint32
	Agcount    uint32
	Rbblocks   uint32
	Logblocks  uint32
	Versionnum uint16
	Sectsize   uint16
	Inodesize  uint16
	Inopblock  uint16
	Fname      [12]byte
	Blocklog   uint8
	Sectlog    uint8
	Inodelog   uint8
	Inopblog   uint8
	Agblklog   uint8
	Rextslog   uint8
	Inprogress uint8
	ImaxPct    uint8

	Icount    uint64
	Ifree     uint64
	Fdblocks  uint64
	Frextents uint64

	Uqunotino   uint64
	Gquotino    uint64
	Qflags      uint16
	Flags       uint8
	SharedVn    uint8
	Inoalignmt  uint32
	Unit        uint32
	Width       uint32
	Dirblklog   uint8
	Logsectlog  uint8
	Logsectsize uint16
	Logsunit    uint32
	Features2   uint32

	BadFeatures2        uint32
	FeaturesCompat      uint32
	FeaturesRoCompat    uint32
	FeaturesIncompat    uint32
	FeaturesLogIncompat uint32
	CRC                 uint32
	SpinoAlign          uint32
	Pquotino            uint64
	Lsn                 int64
	MetaUUID            [16]byte
}

func (SuperBlock) BlockToAgBlockNumber

func (sb SuperBlock) BlockToAgBlockNumber(n uint64) uint64

func (SuperBlock) BlockToAgNumber

func (sb SuperBlock) BlockToAgNumber(n uint64) uint64

func (SuperBlock) BlockToPhysicalOffset

func (sb SuperBlock) BlockToPhysicalOffset(n uint64) int64

func (SuperBlock) InodeAbsOffset

func (sb SuperBlock) InodeAbsOffset(inodeNumber uint64) uint64

return Offset

func (SuperBlock) InodeOffset

func (sb SuperBlock) InodeOffset(inodeNumber uint64) (int, uint64, uint64)

return (AG number), (Inode Block), (Inode Offset)

type SymlinkString

type SymlinkString struct {
	Name string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL