Documentation ¶
Index ¶
- Constants
- func CheckDeviceSize(rs io.ReadSeeker, blockSize uint64) (uint64, error)
- func KeyCompare(a, b Key) int
- func KeyTypeString(t uint8) string
- func ObjectIDString(id uint64) string
- func SliceTimeLE(b []byte) time.Time
- func SliceUUID(b []byte) uuid.UUID
- func SliceUint16LE(b []byte) uint16
- func SliceUint32LE(b []byte) uint32
- func SliceUint64LE(b []byte) uint64
- type BlockGroupItem
- type CSum
- type CSumItem
- type Chunk
- func (c Chunk) IOAlign() uint32
- func (c Chunk) IOWidth() uint32
- func (c Chunk) Length() uint64
- func (c Chunk) NumStripes() uint16
- func (c Chunk) Owner() uint64
- func (c Chunk) SectorSize() uint32
- func (c Chunk) Stripe(i uint16) Stripe
- func (c Chunk) StripeLen() uint64
- func (c Chunk) SubStripes() uint16
- func (c Chunk) Type() uint64
- type DevExtent
- type DevItem
- func (i DevItem) Bandwidth() uint8
- func (i DevItem) BytesUsed() uint64
- func (i DevItem) DevGroup() uint32
- func (i DevItem) DevID() uint64
- func (i DevItem) FSID() uuid.UUID
- func (i DevItem) Generation() uint64
- func (i DevItem) IOAlign() uint32
- func (i DevItem) IOWidth() uint32
- func (i DevItem) SectorSize() uint32
- func (i DevItem) SeekSpeed() uint8
- func (i DevItem) StartOffset() uint64
- func (i DevItem) TotalBytes() uint64
- func (i DevItem) Type() uint64
- func (i DevItem) UUID() uuid.UUID
- type DirItem
- type ExtentItem
- type FileExtentItem
- func (i FileExtentItem) Compression() uint8
- func (i FileExtentItem) Data() string
- func (i FileExtentItem) DiskByteNr() uint64
- func (i FileExtentItem) DiskNumBytes() uint64
- func (i FileExtentItem) Encryption() uint8
- func (i FileExtentItem) Generation() uint64
- func (i FileExtentItem) IsInline() bool
- func (i FileExtentItem) NumBytes() uint64
- func (i FileExtentItem) Offset() uint64
- func (i FileExtentItem) OtherEncoding() uint16
- func (i FileExtentItem) RAMBytes() uint64
- func (i FileExtentItem) Type() uint8
- type Header
- func (h Header) ByteNr() uint64
- func (h Header) CSum() CSum
- func (h Header) ChunkTreeUUID() uuid.UUID
- func (h Header) FSID() uuid.UUID
- func (h Header) Flags() uint64
- func (h Header) Generation() uint64
- func (h Header) IsLeaf() bool
- func (h Header) Level() uint8
- func (h Header) NrItems() uint32
- func (h Header) Owner() uint64
- type InodeItem
- func (i InodeItem) Atime() time.Time
- func (i InodeItem) BlockGroup() uint64
- func (i InodeItem) Ctime() time.Time
- func (i InodeItem) Flags() uint64
- func (i InodeItem) GID() uint32
- func (i InodeItem) Generation() uint64
- func (i InodeItem) Mode() uint32
- func (i InodeItem) Mtime() time.Time
- func (i InodeItem) Nlink() uint32
- func (i InodeItem) Rdev() uint64
- func (i InodeItem) Reserved() [4]uint64
- func (i InodeItem) Rtime() time.Time
- func (i InodeItem) Sequence() uint64
- func (i InodeItem) Size() uint64
- func (i InodeItem) TransID() uint64
- func (i InodeItem) UID() uint32
- type InodeRefItem
- type Item
- type Key
- type Leaf
- type ParseBuffer
- func (b *ParseBuffer) Cap() int
- func (b *ParseBuffer) Len() int
- func (b *ParseBuffer) Next(n int) []byte
- func (b *ParseBuffer) NextTime() time.Time
- func (b *ParseBuffer) NextUint16() uint16
- func (b *ParseBuffer) NextUint32() uint32
- func (b *ParseBuffer) NextUint64() uint64
- func (b *ParseBuffer) NextUint8() uint8
- func (b *ParseBuffer) Offset() int
- func (b *ParseBuffer) Rewind()
- func (b *ParseBuffer) SetOffset(offset int)
- func (b *ParseBuffer) Unread() int
- type RootItem
- func (i RootItem) ByteLimit() uint64
- func (i RootItem) ByteNr() uint64
- func (i RootItem) BytesUsed() uint64
- func (i RootItem) CTransID() uint64
- func (i RootItem) Ctime() time.Time
- func (i RootItem) DropLevel() uint8
- func (i RootItem) DropProgress() Key
- func (i RootItem) Flags() uint64
- func (i RootItem) Generation() uint64
- func (i RootItem) GenerationV2() uint64
- func (i RootItem) Inode() InodeItem
- func (i RootItem) IsGenerationV2() bool
- func (i RootItem) LastSnapshot() uint64
- func (i RootItem) Level() uint8
- func (i RootItem) OTransID() uint64
- func (i RootItem) Otime() time.Time
- func (i RootItem) ParentUUID() uuid.UUID
- func (i RootItem) RTransID() uint64
- func (i RootItem) ReceivedUUID() uuid.UUID
- func (i RootItem) Refs() uint32
- func (i RootItem) Reserved() [8]uint64
- func (i RootItem) RootDirID() uint64
- func (i RootItem) Rtime() time.Time
- func (i RootItem) STransID() uint64
- func (i RootItem) Stime() time.Time
- func (i RootItem) UUID() uuid.UUID
- type RootRef
- type Stripe
Constants ¶
const ( // Magic spells "_BHRfS_M" in little-endian Magic = 0x4d5f53665248425f // X86RegularPageSize is the size of a regular memory page on X86. X86RegularPageSize = 1 << 12 // DefaultBlockSize is the default block size for BTRFS. It is the size // of four pages on x86 (16384 bytes). DefaultBlockSize = 4 * X86RegularPageSize )
const ( SuperInfoOffset = 0x10000 // 64 KiB SuperInfoOffset2 = 0x4000000 // 64 MiB SuperInfoOffset3 = 0x4000000000 // 256 GiB SuperInfoOffset4 = 0x4000000000000 // 1 PiB )
Offsets of all superblock copies
const ( // Holds pointers to all of the tree roots RootTreeObjectID = 1 // Stores information about which extents are in use, and reference // counts ExtentTreeObjectID = 2 // The chunk tree stores translations from logical -> physical block // numbering the super block points to the chunk tree ChunkTreeObjectID = 3 // Stores information about which areas of a given device are in use. One // per device. The tree of tree roots points to the device tree. DevTreeObjectID = 4 // One per subvolume, storing files and directories FSTreeObjectID = 5 // Directory objectid inside the root tree RootTreeDirObjectID = 6 // Holds checksums of all the data extents CSumTreeObjectID = 7 // Holds quota configuration and tracking QuotaTreeObjectID = 8 // For storing items that use the BTRFS_UUID_KEY* types UuidTreeObjectID = 9 // Tracks free space in block groups FreeSpaceTreeObjectID = 10 // Device stats in the device tree DevStatsObjectID = 0 // For storing balance parameters in the root tree BalanceObjectID = ^uint64(4) + 1 // Orphan objectid for tracking unlinked/truncated files OrphanObjectID = ^uint64(5) + 1 // Does write ahead logging to speed up fsyncs TreeLogObjectID = ^uint64(6) + 1 TreeLogFixupObjectID = ^uint64(7) + 1 // For space balancing TreeRelocObjectID = ^uint64(8) + 1 DataRelocTreeObjectID = ^uint64(9) + 1 // Extent checksums all have this objectid. This allows them to share the // logging tree for fsyncs. ExtentCSumObjectID = ^uint64(10) + 1 // For storing free space cache FreeSpaceObjectID = ^uint64(11) + 1 // The inode number assigned to the special inode for storing free inode // cache FreeInoObjectID = ^uint64(12) + 1 // Dummy objectid represents multiple objectids MultipleObjectIDs = ^uint64(255) + 1 // All files have objectids in this range FirstFreeObjectID = 256 LastFreeObjectID = ^uint64(256) + 1 FirstChunkTreeObjectID = 256 // The device items go into the chunk tree. The key is in the form // [ 1 DevItemKey device_id ] DevItemsObjectID = 1 BtreeInodeObjectID = 1 EmptySubvolDirObjectID = 2 // Maximum value of an objectid LastObjectID = ^uint64(0) )
Object ids
const ( CSumSize = 32 LabelSize = 256 SystemChunkArraySize = 2048 )
Entity sizes
const ( // Inode items have the data typically returned from stat and store other // info about object characteristics. There is one for every file and dir // in the FS. InodeItemKey = 1 InodeRefKey = 12 InodeExtrefKey = 13 XAttrItemKey = 24 OrphanItemKey = 48 // dir items are the name -> inode pointers in a directory. There is one // for every name in a directory. DirLogItemKey = 60 DirLogIndexKey = 72 DirItemKey = 84 DirIndexKey = 96 // Extent data is for file data. ExtentDataKey = 108 // Extent csums are stored in a separate tree and hold csums for // an entire extent on disk. ExtentCSumKey = 128 // Root items point to tree roots. They are typically in the root // tree used by the super block to find all the other trees. RootItemKey = 132 // Root backrefs tie subvols and snapshots to the directory entries that // reference them. RootBackRefKey = 144 // Root refs make a fast index for listing all of the snapshots and // subvolumes referenced by a given root. They point directly to the // directory item in the root that references the subvol. RootRefKey = 156 // Extent items are in the extent map tree. These record which blocks // are used, and how many references there are to each block. ExtentItemKey = 168 // The same as the ExtentItemKey, except it's metadata we already know // the length, so we save the level in key->offset instead of the // length. MetadataItemKey = 169 // These are contained within an extent item. // TODO(cblichmann): Parse these TreeBlockRefKey = 176 ExtentDataRefKey = 178 ExtentRefV0Key = 180 // Block groups give us hints into the extent allocation trees. Which // blocks are free etc. BlockGroupItemKey = 192 // Every block group is represented in the free space tree by a free space // info item, which stores some accounting information. It is keyed on // (block_group_start, FREE_SPACE_INFO, block_group_length). FreeSpaceInfoKey = 198 // A free space extent tracks an extent of space that is free in a block // group. It is keyed on (start, FREE_SPACE_EXTENT, length). FreeSpaceExtentKey = 199 // When a block group becomes very fragmented, we convert it to use bitmaps // instead of extents. A free space bitmap is keyed on // (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap // with (length / sectorsize) bits. FreeSpaceBitmapKey = 200 DevExtentKey = 204 DevItemKey = 216 ChunkItemKey = 228 // Records the overall state of the qgroups. // There's only one instance of this key present, // (0, BTRFS_QGROUP_STATUS_KEY, 0) QgroupStatusKey = 240 // Records the currently used space of the qgroup. // One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). QgroupInfoKey = 242 // Contains the user configured limits for the qgroup. // One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). QgroupLimitKey = 244 // Records the child-parent relationship of qgroups. For each relation, 2 // keys are present: // (childid, BTRFS_QGROUP_RELATION_KEY, parentid) // (parentid, BTRFS_QGROUP_RELATION_KEY, childid) QgroupRelationKey = 246 // Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY BalanceItemKey = TemporaryItemKey // The key type for tree items that are stored persistently, but do not need // to exist for extended period of time. The items can exist in any tree. // // [subtype, BTRFS_TEMPORARY_ITEM_KEY, data] // // Existing items: // // - balance status item // (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0) TemporaryItemKey = 248 // Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY DevStatsKey = PersistentItemKey // The key type for tree items that are stored persistently and usually // exist for a long period, eg. filesystem lifetime. The item kinds can be // status information, stats or preference values. The item can exist in // any tree. // // [subtype, BTRFS_PERSISTENT_ITEM_KEY, data] // // Existing items: // // - device statistics, store IO stats in the device tree, one key for all // stats // (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0) PersistentItemKey = 249 // Persistantly stores the device replace state in the device tree. // The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0). DevReplaceKey = 250 // Stores items that allow to quickly map UUIDs to something else. // These items are part of the filesystem UUID tree. // The key is built like this: // (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits). // // For UUIDs assigned to subvols UUIDKeySubvol = 251 // For UUIDs assigned to received subvols UUIDKeyReceivedSubvol = 252 // String items are for debugging. They just store a short string of data // in the FS. StringItemKey = 253 )
Key types
const ( FtUnknown = iota FtRegFile FtDir FtChrdev FtBlkdev FtFifo FtSock FtSymlink FtXattr FtMax )
Directory item type
const ( BlockGroupData = 1 << iota BlockGroupSystem BlockGroupMetadata BlockGroupRaid0 BlockGroupRaid1 BlockGroupDup BlockGroupRaid10 BlockGroupRaid5 BlockGroupRaid6 )
const ( FileExtentInline = iota FileExtentReg FileExtentPreAlloc )
File extent type
const ( ExtentFlagData = 1 << iota ExtentFlagTreeBlock ExtentFlagFullBackref = 0x80 )
Extent item flags
const (
DevExtentLen = devExtentChunkTreeUUID + uuid.UUIDSize
)
Dev extent offsets for parsing from byte slice
const (
DevItemLen = devItemFSID + uuid.UUIDSize
)
const (
FileExtentItemEnd = fileExtentItemNumBytes + 8
)
FileExtentItem offsets for parsing from byte slice
const (
HeaderLen = headerLevel + 1
)
Header offsets for parsing from byte slice
const (
InodeItemLen = inodeItemOtime + 12
)
InodeItem offsets for parsing from byte slice
const (
ItemLen = itemSize + 4
)
const KeyLen = 8 + 1 + 8
const (
RootItemLen = rootItemReserved + 8*8
)
RootItem offsets for parsing from byte slice
Variables ¶
This section is empty.
Functions ¶
func CheckDeviceSize ¶
func CheckDeviceSize(rs io.ReadSeeker, blockSize uint64) (uint64, error)
func KeyCompare ¶
KeyCompare compares two BTRFS keys lexicographically. It returns 0 if a==b, -1 if a < b and +1 if a > b.
func KeyTypeString ¶
func ObjectIDString ¶
func SliceTimeLE ¶
func SliceUint16LE ¶
func SliceUint32LE ¶
func SliceUint64LE ¶
Types ¶
type BlockGroupItem ¶
type BlockGroupItem []byte
func (BlockGroupItem) ChunkObjectID ¶
func (i BlockGroupItem) ChunkObjectID() uint64
func (BlockGroupItem) Flags ¶
func (i BlockGroupItem) Flags() uint64
func (BlockGroupItem) Used ¶
func (i BlockGroupItem) Used() uint64
type Chunk ¶
type Chunk []byte
func (Chunk) NumStripes ¶
NumStripes returns the number of stripes in this chunk. 2^16 stripes is quite a lot, a second limit is the size of a single item in the btree
func (Chunk) SectorSize ¶
SectorSize returns the minimal IO size for this chunk
type DevExtent ¶
type DevExtent []byte
Dev extents record free space on individual devices. The owner field points back to the chunk allocation mapping tree that allocated the extent. The chunk tree uuid field is a way to double check the owner.
func (DevExtent) ChunkObjectID ¶
func (DevExtent) ChunkOffset ¶
func (DevExtent) ChunkTreeUUID ¶
type DevItem ¶
type DevItem []byte
func (DevItem) Bandwidth ¶
Bandwidth returns the device bandwidth in range 0-100 where 100 is fastest
func (DevItem) Generation ¶
Generation returns the expected generation for this device
func (DevItem) SectorSize ¶
SectorSize returns the minimal I/O size for this device
func (DevItem) SeekSpeed ¶
SeekSpeed returns the device seek speed in range 0-100 where 100 is fastest
func (DevItem) StartOffset ¶
StartOffset returns the starting byte of this partition on the device. This allows for stripe alignment in the future.
func (DevItem) TotalBytes ¶
TotalBytes returns the size of the device
type ExtentItem ¶
type ExtentItem []byte
Items in the extent btree are used to record the objectid of the owner of the block and the number of references.
func (ExtentItem) Flags ¶
func (i ExtentItem) Flags() uint64
func (ExtentItem) Generation ¶
func (i ExtentItem) Generation() uint64
func (ExtentItem) IsCompatV0 ¶
func (i ExtentItem) IsCompatV0() bool
func (ExtentItem) Refs ¶
func (i ExtentItem) Refs() uint64
type FileExtentItem ¶
type FileExtentItem []byte
func (FileExtentItem) Compression ¶
func (i FileExtentItem) Compression() uint8
32 bits for the various ways we might encode the data, including compression and encryption. If any of these are set to something a given disk format doesn't understand it is treated like an incompat flag for reading and writing, but not for stat.
func (FileExtentItem) Data ¶
func (i FileExtentItem) Data() string
The data returned is only valid if Type == FileExtentInline:
func (FileExtentItem) DiskByteNr ¶
func (i FileExtentItem) DiskByteNr() uint64
func (FileExtentItem) DiskNumBytes ¶
func (i FileExtentItem) DiskNumBytes() uint64
func (FileExtentItem) Encryption ¶
func (i FileExtentItem) Encryption() uint8
func (FileExtentItem) Generation ¶
func (i FileExtentItem) Generation() uint64
Transaction id that created this extent
func (FileExtentItem) IsInline ¶
func (i FileExtentItem) IsInline() bool
func (FileExtentItem) NumBytes ¶
func (i FileExtentItem) NumBytes() uint64
The logical number of file blocks (no csums included). This always reflects the size uncompressed and without encoding.
func (FileExtentItem) Offset ¶
func (i FileExtentItem) Offset() uint64
The logical offset in file blocks (no csums) this extent record is for. This allows a file extent to point into the middle of an existing extent on disk, sharing it between two snapshots (useful if some bytes in the middle of the extent have changed.
func (FileExtentItem) RAMBytes ¶
func (i FileExtentItem) RAMBytes() uint64
Max number of bytes to hold this extent in ram when we split a compressed extent we can't know how big each of the resulting pieces will be. So, this is an upper limit on the size of the extent in ram instead of an exact limit.
func (FileExtentItem) Type ¶
func (i FileExtentItem) Type() uint8
Are we inline data or a real extent?
type Header ¶
type Header []byte
func (Header) ByteNr ¶
ByteNr returns the start of this block relative to the begining of the backing device
func (Header) ChunkTreeUUID ¶
func (Header) Generation ¶
type InodeRefItem ¶
type InodeRefItem []byte
func (InodeRefItem) Index ¶
func (i InodeRefItem) Index() uint64
func (InodeRefItem) Name ¶
func (i InodeRefItem) Name() string
func (InodeRefItem) NameLen ¶
func (i InodeRefItem) NameLen() uint16
type ParseBuffer ¶
ParseBuffer is similar to bytes.Buffer, except that it is read-only and can be restarted.
func NewParseBuffer ¶
func NewParseBuffer(buf []byte) *ParseBuffer
func (*ParseBuffer) Cap ¶
func (b *ParseBuffer) Cap() int
func (*ParseBuffer) Len ¶
func (b *ParseBuffer) Len() int
func (*ParseBuffer) Next ¶
func (b *ParseBuffer) Next(n int) []byte
Next returns a slice containing the next n bytes from the buffer and advancing it. Panics if there are fewer than n bytes in the buffer. The slice is only valid until the next call to one of the next methods.
func (*ParseBuffer) NextTime ¶
func (b *ParseBuffer) NextTime() time.Time
func (*ParseBuffer) NextUint16 ¶
func (b *ParseBuffer) NextUint16() uint16
func (*ParseBuffer) NextUint32 ¶
func (b *ParseBuffer) NextUint32() uint32
func (*ParseBuffer) NextUint64 ¶
func (b *ParseBuffer) NextUint64() uint64
func (*ParseBuffer) NextUint8 ¶
func (b *ParseBuffer) NextUint8() uint8
func (*ParseBuffer) Offset ¶
func (b *ParseBuffer) Offset() int
func (*ParseBuffer) Rewind ¶
func (b *ParseBuffer) Rewind()
func (*ParseBuffer) SetOffset ¶
func (b *ParseBuffer) SetOffset(offset int)
func (*ParseBuffer) Unread ¶
func (b *ParseBuffer) Unread() int
type RootItem ¶
type RootItem []byte
func (RootItem) DropProgress ¶
func (RootItem) Generation ¶
func (RootItem) GenerationV2 ¶
This generation number is used to test if the new fields are valid and up to date while reading the root item. Everytime the root item is written out, the "generation" field is copied into this field. If anyone ever mounted the fs with an older kernel, we will have mismatching generation values here and thus must invalidate the new fields.