fix index key to new uint8 size

This commit is contained in:
Ben McClelland
2024-06-25 15:13:45 -07:00
parent 1253270250
commit 76a7e1175a
3 changed files with 20 additions and 14 deletions

View File

@@ -13,7 +13,7 @@ func main() {
// flags mount path name // flags mount path name
mountPath := flag.String("mount", "", "mount path name") mountPath := flag.String("mount", "", "mount path name")
// flags index type uint64 // flags index type uint64
indexType := flag.Uint64("type", 0, "index type") indexType := flag.Uint("type", 0, "index type")
// flags index start uint64 // flags index start uint64
indexStart := flag.Uint64("start", 0, "index start") indexStart := flag.Uint64("start", 0, "index start")
// flags index end uint64 // flags index end uint64
@@ -29,7 +29,12 @@ func main() {
} }
defer f.Close() defer f.Close()
idx := scoutfs.NewIndexSearch(f, *indexType, *indexStart, *indexEnd) if *indexType > 255 {
log.Fatal("index type out of bounds")
}
itype := uint8(*indexType)
idx := scoutfs.NewIndexSearch(f, itype, *indexStart, *indexEnd)
for { for {
ents, err := idx.Next() ents, err := idx.Next()
if err != nil { if err != nil {

View File

@@ -1707,17 +1707,17 @@ const (
indexXattrBatch = 1024 indexXattrBatch = 1024
) )
func NewIndexSearch(f *os.File, key, start, end uint64, opts ...IOption) *IndexSearch { func NewIndexSearch(f *os.File, key uint8, start, end uint64, opts ...IOption) *IndexSearch {
i := &IndexSearch{ i := &IndexSearch{
f: f, f: f,
pos: indexEntry{ pos: indexEntry{
A: key, Major: key,
B: start, Minor: start,
}, },
end: indexEntry{ end: indexEntry{
A: key, Major: key,
B: end, Minor: end,
Ino: math.MaxUint64, Ino: math.MaxUint64,
}, },
batch: indexXattrBatch, batch: indexXattrBatch,
} }
@@ -1789,7 +1789,7 @@ func (i *IndexSearch) Next() ([]IndexEnt, error) {
} }
inodes[i].Inode = e.Ino inodes[i].Inode = e.Ino
inodes[i].Value = e.B inodes[i].Value = e.Minor
} }
i.pos = e.increment() i.pos = e.increment()
@@ -1800,9 +1800,9 @@ func (i *IndexSearch) Next() ([]IndexEnt, error) {
func (i indexEntry) increment() indexEntry { func (i indexEntry) increment() indexEntry {
i.Ino++ i.Ino++
if i.Ino == 0 { if i.Ino == 0 {
i.B++ i.Minor++
if i.B == 0 { if i.Minor == 0 {
i.A++ i.Major++
} }
} }
return i return i

View File

@@ -213,9 +213,10 @@ type getQuotaRules struct {
Nr uint64 Nr uint64
} }
type indexEntry struct { type indexEntry struct {
A uint64 Minor uint64
B uint64
Ino uint64 Ino uint64
Major uint8
X_pad [7]uint8
} }
type readXattrIndex struct { type readXattrIndex struct {
Flags uint64 Flags uint64