summaryrefslogtreecommitdiff
path: root/pkg/btrfs/btrfsitem
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/btrfs/btrfsitem')
-rw-r--r--pkg/btrfs/btrfsitem/item_dir.go21
-rw-r--r--pkg/btrfs/btrfsitem/items.txt6
-rw-r--r--pkg/btrfs/btrfsitem/items_gen.go8
3 files changed, 20 insertions, 15 deletions
diff --git a/pkg/btrfs/btrfsitem/item_dir.go b/pkg/btrfs/btrfsitem/item_dir.go
index 253d257..14541bd 100644
--- a/pkg/btrfs/btrfsitem/item_dir.go
+++ b/pkg/btrfs/btrfsitem/item_dir.go
@@ -2,6 +2,7 @@ package btrfsitem
import (
"fmt"
+ "hash/crc32"
"lukeshu.com/btrfs-tools/pkg/binstruct"
"lukeshu.com/btrfs-tools/pkg/btrfs/internal"
@@ -9,15 +10,19 @@ import (
// key.objectid = inode of directory containing this entry
// key.offset =
-// for DIR_ITEM and XATTR_ITEM = crc32c(name)
+// for DIR_ITEM and XATTR_ITEM = NameHash(name)
// for DIR_INDEX = index id in the directory (starting at 2, because "." and "..")
-type DirList []Dir // DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24
+type DirEntries []DirEntry // DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24
-func (o *DirList) UnmarshalBinary(dat []byte) (int, error) {
+func NameHash(dat []byte) uint64 {
+ return uint64(^crc32.Update(1, crc32.MakeTable(crc32.Castagnoli), dat))
+}
+
+func (o *DirEntries) UnmarshalBinary(dat []byte) (int, error) {
*o = nil
n := 0
for n < len(dat) {
- var ref Dir
+ var ref DirEntry
_n, err := binstruct.Unmarshal(dat, &ref)
n += _n
if err != nil {
@@ -28,7 +33,7 @@ func (o *DirList) UnmarshalBinary(dat []byte) (int, error) {
return n, nil
}
-func (o DirList) MarshalBinary() ([]byte, error) {
+func (o DirEntries) MarshalBinary() ([]byte, error) {
var ret []byte
for _, ref := range o {
bs, err := binstruct.Marshal(ref)
@@ -40,7 +45,7 @@ func (o DirList) MarshalBinary() ([]byte, error) {
return ret, nil
}
-type Dir struct {
+type DirEntry struct {
Location internal.Key `bin:"off=0x0, siz=0x11"`
TransID int64 `bin:"off=0x11, siz=8"`
DataLen uint16 `bin:"off=0x19, siz=2"` // [ignored-when-writing]
@@ -51,7 +56,7 @@ type Dir struct {
Name []byte `bin:"-"`
}
-func (o *Dir) UnmarshalBinary(dat []byte) (int, error) {
+func (o *DirEntry) UnmarshalBinary(dat []byte) (int, error) {
n, err := binstruct.UnmarshalWithoutInterface(dat, o)
if err != nil {
return n, err
@@ -63,7 +68,7 @@ func (o *Dir) UnmarshalBinary(dat []byte) (int, error) {
return n, nil
}
-func (o Dir) MarshalBinary() ([]byte, error) {
+func (o DirEntry) MarshalBinary() ([]byte, error) {
o.DataLen = uint16(len(o.Data))
o.NameLen = uint16(len(o.Name))
dat, err := binstruct.MarshalWithoutInterface(o)
diff --git a/pkg/btrfs/btrfsitem/items.txt b/pkg/btrfs/btrfsitem/items.txt
index dbcd260..a5f247f 100644
--- a/pkg/btrfs/btrfsitem/items.txt
+++ b/pkg/btrfs/btrfsitem/items.txt
@@ -2,8 +2,8 @@ BLOCK_GROUP_ITEM=192 BlockGroup
CHUNK_ITEM=228 Chunk
DEV_EXTENT=204 DevExtent
DEV_ITEM=216 Dev
-DIR_INDEX=96 DirList
-DIR_ITEM=84 DirList
+DIR_INDEX=96 DirEntries
+DIR_ITEM=84 DirEntries
EXTENT_CSUM=128 ExtentCSum
EXTENT_DATA=108 FileExtent
EXTENT_DATA_REF=178 ExtentDataRef
@@ -24,4 +24,4 @@ TREE_BLOCK_REF=176 Empty
UNTYPED=0:FREE_SPACE_OBJECTID FreeSpaceHeader
UUID_RECEIVED_SUBVOL=252 UUIDMap
UUID_SUBVOL=251 UUIDMap
-XATTR_ITEM=24 DirList
+XATTR_ITEM=24 DirEntries
diff --git a/pkg/btrfs/btrfsitem/items_gen.go b/pkg/btrfs/btrfsitem/items_gen.go
index f0a4274..92e2523 100644
--- a/pkg/btrfs/btrfsitem/items_gen.go
+++ b/pkg/btrfs/btrfsitem/items_gen.go
@@ -43,8 +43,8 @@ var keytype2gotype = map[Type]reflect.Type{
CHUNK_ITEM_KEY: reflect.TypeOf(Chunk{}),
DEV_EXTENT_KEY: reflect.TypeOf(DevExtent{}),
DEV_ITEM_KEY: reflect.TypeOf(Dev{}),
- DIR_INDEX_KEY: reflect.TypeOf(DirList{}),
- DIR_ITEM_KEY: reflect.TypeOf(DirList{}),
+ DIR_INDEX_KEY: reflect.TypeOf(DirEntries{}),
+ DIR_ITEM_KEY: reflect.TypeOf(DirEntries{}),
EXTENT_CSUM_KEY: reflect.TypeOf(ExtentCSum{}),
EXTENT_DATA_KEY: reflect.TypeOf(FileExtent{}),
EXTENT_DATA_REF_KEY: reflect.TypeOf(ExtentDataRef{}),
@@ -64,7 +64,7 @@ var keytype2gotype = map[Type]reflect.Type{
TREE_BLOCK_REF_KEY: reflect.TypeOf(Empty{}),
UUID_RECEIVED_SUBVOL_KEY: reflect.TypeOf(UUIDMap{}),
UUID_SUBVOL_KEY: reflect.TypeOf(UUIDMap{}),
- XATTR_ITEM_KEY: reflect.TypeOf(DirList{}),
+ XATTR_ITEM_KEY: reflect.TypeOf(DirEntries{}),
}
var untypedObjID2gotype = map[internal.ObjID]reflect.Type{
internal.FREE_SPACE_OBJECTID: reflect.TypeOf(FreeSpaceHeader{}),
@@ -75,7 +75,7 @@ func (Chunk) isItem() {}
func (Dev) isItem() {}
func (DevExtent) isItem() {}
func (DevStats) isItem() {}
-func (DirList) isItem() {}
+func (DirEntries) isItem() {}
func (Empty) isItem() {}
func (Extent) isItem() {}
func (ExtentCSum) isItem() {}