summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/btrfs-ls-files/main.go30
-rw-r--r--pkg/btrfs/io3_btree.go13
2 files changed, 27 insertions, 16 deletions
diff --git a/cmd/btrfs-ls-files/main.go b/cmd/btrfs-ls-files/main.go
index d6b8c97..042dc14 100644
--- a/cmd/btrfs-ls-files/main.go
+++ b/cmd/btrfs-ls-files/main.go
@@ -116,7 +116,7 @@ func printDir(fs *btrfs.FS, fsTree btrfsvol.LogicalAddr, prefix0, prefix1, dirNa
}
membersByIndex[index] = entry
}
- case btrfsitem.XATTR_ITEM_KEY:
+ //case btrfsitem.XATTR_ITEM_KEY:
default:
panic(fmt.Errorf("TODO: handle item type %v", item.Head.Key.ItemType))
}
@@ -142,27 +142,37 @@ func printDir(fs *btrfs.FS, fsTree btrfsvol.LogicalAddr, prefix0, prefix1, dirNa
errs = append(errs, fmt.Errorf("read dir: no DIR_ITEM crc32c(%q)=%#x for DIR_INDEX index=%d",
entry.Name, namehash, index))
}
- prefix := tT
+ p0, p1 := tT, tl
if (i == len(membersByIndex)-1) && (len(membersByNameHash) == 0) && (len(errs) == 0) {
- prefix = tL
+ p0, p1 = tL, tS
}
- printItem(fs, fsTree, prefix1+prefix, prefix1+tS, string(entry.Name), entry.Location)
+ printDirEntry(fs, fsTree, prefix1+p0, prefix1+p1, entry)
}
for _, namehash := range util.SortedMapKeys(membersByNameHash) {
entry := membersByNameHash[namehash]
errs = append(errs, fmt.Errorf("read dir: no DIR_INDEX for DIR_ITEM crc32c(%q)=%#x",
entry.Name, namehash))
- printItem(fs, fsTree, prefix1+tT, prefix1+tS, string(entry.Name), entry.Location)
+ printDirEntry(fs, fsTree, prefix1+tT, prefix1+tl, entry)
}
for i, err := range errs {
- prefix := tT
+ p0, p1 := tT, tl
if i == len(errs)-1 {
- prefix = tL
+ p0, p1 = tL, tS
}
- fmt.Printf("%s%s%s\n", prefix1, prefix, strings.ReplaceAll(err.Error(), "\n", prefix1+tS+"\n"))
+ fmt.Printf("%s%s%s\n", prefix1+p0, prefix1+p1, strings.ReplaceAll(err.Error(), "\n", prefix1+tS+"\n"))
}
}
-func printItem(fs *btrfs.FS, fsTree btrfsvol.LogicalAddr, prefix0, prefix1, name string, location btrfs.Key) {
- fmt.Printf("%s%q\t[location=%v]\n", prefix0, name, location)
+func printDirEntry(fs *btrfs.FS, fsTree btrfsvol.LogicalAddr, prefix0, prefix1 string, entry btrfsitem.DirEntry) {
+ if len(entry.Data) != 0 {
+ fmt.Printf("%s%q: error: TODO: I don't know how to handle dirent.data\n",
+ prefix0, entry.Name)
+ return
+ }
+ switch entry.Type {
+ case btrfsitem.FT_DIR:
+ printDir(fs, fsTree, prefix0, prefix1, string(entry.Name), entry.Location.ObjectID)
+ default:
+ fmt.Printf("%s%q\t[location=%v type=%v]\n", prefix0, entry.Name, entry.Location, entry.Type)
+ }
}
diff --git a/pkg/btrfs/io3_btree.go b/pkg/btrfs/io3_btree.go
index b4eb4cb..b5414ab 100644
--- a/pkg/btrfs/io3_btree.go
+++ b/pkg/btrfs/io3_btree.go
@@ -237,15 +237,16 @@ func (fs *FS) treeSearch(treeRoot btrfsvol.LogicalAddr, fn func(Key) int) (TreeP
// is returned.
//
// Implement this search as a binary search.
- items := node.Data.BodyLeaf
- for len(items) > 0 {
- midpoint := len(items) / 2
- direction := fn(items[midpoint].Head.Key)
+ beg := 0
+ end := len(node.Data.BodyLeaf) - 1
+ for beg < end {
+ midpoint := (beg + end) / 2
+ direction := fn(node.Data.BodyLeaf[midpoint].Head.Key)
switch {
case direction < 0:
- items = items[:midpoint]
+ end = midpoint
case direction > 0:
- items = items[midpoint+1:]
+ beg = midpoint + 1
case direction == 0:
path = append(path, TreePathElem{
ItemIdx: midpoint,