diff --git a/low/reader.go b/low/reader.go index ea71895..4883d94 100644 --- a/low/reader.go +++ b/low/reader.go @@ -3,6 +3,7 @@ package squashfslow import ( "encoding/binary" "errors" + "fmt" "io" "math" @@ -88,7 +89,7 @@ func (r *Reader) Id(i uint16) (uint32, error) { // Populate the id table as needed var blockNum uint32 if i != 0 { // If i == 0, we go negatives causing issues with uint32s - blockNum = uint32(math.Ceil(float64(i)/2048)) - 1 + blockNum = uint32(math.Ceil(float64(i+1)/2048)) - 1 } else { blockNum = 0 } @@ -131,10 +132,11 @@ func (r *Reader) fragEntry(i uint32) (fragEntry, error) { // Populate the fragment table as needed var blockNum uint32 if i != 0 { // If i == 0, we go negatives causing issues with uint32s - blockNum = uint32(math.Ceil(float64(i)/512)) - 1 + blockNum = uint32(math.Ceil(float64(i+1)/512)) - 1 } else { blockNum = 0 } + fmt.Println(blockNum) blocksRead := len(r.fragTable) / 512 blocksToRead := int(blockNum) - blocksRead + 1 @@ -177,7 +179,7 @@ func (r *Reader) inodeRef(i uint32) (uint64, error) { // Populate the export table as needed var blockNum uint32 if i != 0 { // If i == 0, we go negatives causing issues with uint32s - blockNum = uint32(math.Ceil(float64(i)/1024)) - 1 + blockNum = uint32(math.Ceil(float64(i+1)/1024)) - 1 } else { blockNum = 0 } diff --git a/low/reader_test.go b/low/reader_test.go index 6a4a4d0..6a01c09 100644 --- a/low/reader_test.go +++ b/low/reader_test.go @@ -1,4 +1,4 @@ -package squashfslow_test +package squashfslow import ( "fmt" @@ -8,13 +8,11 @@ import ( "os/exec" "path/filepath" "testing" - - squashfslow "github.com/CalebQ42/squashfs/low" ) const ( squashfsURL = "https://darkstorm.tech/files/LinuxPATest.sfs" - squashfsName = "LinuxPATest.sfs" + squashfsName = "airootfs.sfs" ) func preTest(dir string) (fil *os.File, err error) { @@ -50,6 +48,21 @@ func preTest(dir string) (fil *os.File, err error) { return } +func TestMisc(t *testing.T) { + tmpDir := "../testing" + fil, err := preTest(tmpDir) + if err != nil { + t.Fatal(err) + } + defer fil.Close() + rdr, err := NewReader(fil) + if err != nil { + t.Fatal(err) + } + t.Log(rdr.Superblock.FragCount) + t.Fatal(rdr.fragEntry(1233)) +} + func TestReader(t *testing.T) { tmpDir := "../testing" fil, err := preTest(tmpDir) @@ -57,7 +70,7 @@ func TestReader(t *testing.T) { t.Fatal(err) } defer fil.Close() - rdr, err := squashfslow.NewReader(fil) + rdr, err := NewReader(fil) if err != nil { t.Fatal(err) } @@ -77,7 +90,7 @@ func TestSingleFile(t *testing.T) { t.Fatal(err) } defer fil.Close() - rdr, err := squashfslow.NewReader(fil) + rdr, err := NewReader(fil) if err != nil { t.Fatal(err) } @@ -92,7 +105,7 @@ func TestSingleFile(t *testing.T) { t.Fatal(err) } -func extractToDir(rdr *squashfslow.Reader, b *squashfslow.FileBase, folder string) error { +func extractToDir(rdr *Reader, b *FileBase, folder string) error { path := filepath.Join(folder, b.Name) if b.IsDir() { d, err := b.ToDir(rdr) @@ -103,7 +116,7 @@ func extractToDir(rdr *squashfslow.Reader, b *squashfslow.FileBase, folder strin if err != nil { return err } - var nestBast squashfslow.FileBase + var nestBast FileBase for _, e := range d.Entries { nestBast, err = rdr.BaseFromEntry(e) if err != nil {