mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Define sizes for extent headers and entries separately to improve clarity.
PiperOrigin-RevId: 288799694
This commit is contained in:
@@ -29,8 +29,12 @@ package disklayout
|
||||
// byte (i * sb.BlockSize()) to ((i+1) * sb.BlockSize()).
|
||||
|
||||
const (
|
||||
// ExtentStructsSize is the size of all the three extent on-disk structs.
|
||||
ExtentStructsSize = 12
|
||||
// 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
|
||||
@@ -57,7 +61,7 @@ type ExtentNode struct {
|
||||
Entries []ExtentEntryPair
|
||||
}
|
||||
|
||||
// ExtentEntry reprsents an extent tree node entry. The entry can either be
|
||||
// ExtentEntry represents an extent tree node entry. The entry can either be
|
||||
// an ExtentIdx or Extent itself. This exists to simplify navigation logic.
|
||||
type ExtentEntry interface {
|
||||
// FileBlock returns the first file block number covered by this entry.
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// TestExtentSize tests that the extent structs are of the correct
|
||||
// size.
|
||||
func TestExtentSize(t *testing.T) {
|
||||
assertSize(t, ExtentHeader{}, ExtentStructsSize)
|
||||
assertSize(t, ExtentIdx{}, ExtentStructsSize)
|
||||
assertSize(t, Extent{}, ExtentStructsSize)
|
||||
assertSize(t, ExtentHeader{}, ExtentHeaderSize)
|
||||
assertSize(t, ExtentIdx{}, ExtentEntrySize)
|
||||
assertSize(t, Extent{}, ExtentEntrySize)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func newExtentFile(regFile regularFile) (*extentFile, error) {
|
||||
func (f *extentFile) buildExtTree() error {
|
||||
rootNodeData := f.regFile.inode.diskInode.Data()
|
||||
|
||||
binary.Unmarshal(rootNodeData[:disklayout.ExtentStructsSize], binary.LittleEndian, &f.root.Header)
|
||||
binary.Unmarshal(rootNodeData[:disklayout.ExtentHeaderSize], binary.LittleEndian, &f.root.Header)
|
||||
|
||||
// Root node can not have more than 4 entries: 60 bytes = 1 header + 4 entries.
|
||||
if f.root.Header.NumEntries > 4 {
|
||||
@@ -67,7 +67,7 @@ func (f *extentFile) buildExtTree() error {
|
||||
}
|
||||
|
||||
f.root.Entries = make([]disklayout.ExtentEntryPair, f.root.Header.NumEntries)
|
||||
for i, off := uint16(0), disklayout.ExtentStructsSize; i < f.root.Header.NumEntries; i, off = i+1, off+disklayout.ExtentStructsSize {
|
||||
for i, off := uint16(0), disklayout.ExtentEntrySize; i < f.root.Header.NumEntries; i, off = i+1, off+disklayout.ExtentEntrySize {
|
||||
var curEntry disklayout.ExtentEntry
|
||||
if f.root.Header.Height == 0 {
|
||||
// Leaf node.
|
||||
@@ -76,7 +76,7 @@ func (f *extentFile) buildExtTree() error {
|
||||
// Internal node.
|
||||
curEntry = &disklayout.ExtentIdx{}
|
||||
}
|
||||
binary.Unmarshal(rootNodeData[off:off+disklayout.ExtentStructsSize], binary.LittleEndian, curEntry)
|
||||
binary.Unmarshal(rootNodeData[off:off+disklayout.ExtentEntrySize], binary.LittleEndian, curEntry)
|
||||
f.root.Entries[i].Entry = curEntry
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func (f *extentFile) buildExtTreeFromDisk(entry disklayout.ExtentEntry) (*diskla
|
||||
}
|
||||
|
||||
entries := make([]disklayout.ExtentEntryPair, header.NumEntries)
|
||||
for i, off := uint16(0), off+disklayout.ExtentStructsSize; i < header.NumEntries; i, off = i+1, off+disklayout.ExtentStructsSize {
|
||||
for i, off := uint16(0), off+disklayout.ExtentEntrySize; i < header.NumEntries; i, off = i+1, off+disklayout.ExtentEntrySize {
|
||||
var curEntry disklayout.ExtentEntry
|
||||
if header.Height == 0 {
|
||||
// Leaf node.
|
||||
|
||||
Reference in New Issue
Block a user