-
Notifications
You must be signed in to change notification settings - Fork 138
Fix ext4 offset #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ext4 offset #313
Conversation
|
I was wondering why our tests didn't get this, and I realize that our tests all use an image where the filesystem starts at byte 0. So nice catch. I have a few comments on this. Most importantly, can we add a test where we have an image that is offset by even something small, say 1MB? Or even update the current tests to use an image where the ext4 filesystem is offset by 1MB? It does not need to be partitioned properly (shouldn't, as we want to exercise just ext4 in the tests), as long as the tests tell it what byte offset to start it. Second, I count 7 places in ext4 where we do All of which makes me question if this is the right approach. Maybe have The signature for creating the func Read(b backend.Storage, size, start, sectorsize int64) (*FileSystem, error) {
...
n, err := b.ReadAt(bs, start)
...
n, err = b.ReadAt(superblockBytes, start+int64(BootSectorSize))
...
n, err = b.ReadAt(gdtBytes, start+int64(gdtBlock)*int64(sb.blockSize))
...
return &FileSystem{
bootSector: bs,
superblock: sb,
groupDescriptors: gdt,
blockGroups: int64(sb.blockGroupCount()),
size: size,
start: start,
backend: b,
}, nilMaybe we should do something like this: func Read(b backend.Storage, size, start, sectorsize int64) (*FileSystem, error) {
// creates a new backend that wraps the original, but only includes
// from start to start+size, and so you can do all ReadAt() and WriteTo without considering original offset
fsBackend := backend.Sub(b, start, size)
...
n, err := fsBackend.ReadAt(bs, 0)
...
n, err = fsBackend.ReadAt(superblockBytes, int64(BootSectorSize))
...
n, err = fsBackend.ReadAt(gdtBytes, int64(gdtBlock)*int64(sb.blockSize))
...
return &FileSystem{
bootSector: bs,
superblock: sb,
groupDescriptors: gdt,
blockGroups: int64(sb.blockGroupCount()),
size: size,
start: start,
backend: fsBackend,
}, nilThen we not only do not need the changes here, but we can remove any other place we added it (the 3 correct Thoughts? |
This reverts commit b8fa375.
…t any point within an img file
|
It took a while for me to understand why your suggestion was easier, but it did seem to make sense in the end. I think I implemented what you were talking about. I modified the generation of the test img build script to create a second img with an offset, and also added the tests. I'm unsure if you want to keep the tests separate, one for offset and one for not, or if it would be safe to combine into a single test. I feel like it would be fine to use just the offset test, as if it works at 1024 bytes, I think it should work just fine at 0 as well as any other number. Thanks for the direction and suggestions, let me know if this is what you had in mind. |
deitch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this!
I instinctively feel the same way, but having had enough experience where things that should collapse down to zero and behave the same way somehow just do not, that if you have the tests, I would leave them. |
|
Lint has a few complaints about extra spaces, and about duplicate code twice; I think it wants you to put it in a shared function. |
|
Oh you. I should check existing PRs first. My bad #314 😄 Do you have any ETA for this? |
|
@deitch I think all the lint complaints are fixed as well as updating all ext4 tests to try both with and without offset. |
|
All good. Thank you for this! |
|
Thank you both. |
Fixes an offset issue that is possibly related to #310. Was failing to read from a ext4 partition.
Read works on:
Used update repro for Raspberry Pi Images.
Output:
go run ./tools/ext4-rpi.go ./tools/2025-10-01-raspios-trixie-arm64-lite.img Partition 1: success, fs.Type=0 Partition 1: ReadDir(/) entries: 46 - overlays (dir, 0 bytes) - bcm2710-rpi-2-b.dtb (file, 32503 bytes) - LICENCE.broadcom (file, 1594 bytes) - issue.txt (file, 145 bytes) - bcm2710-rpi-3-b-plus.dtb (file, 35330 bytes) - bcm2710-rpi-3-b.dtb (file, 34695 bytes) - bcm2710-rpi-cm0.dtb (file, 33684 bytes) - bcm2710-rpi-cm3.dtb (file, 32266 bytes) - bcm2710-rpi-zero-2-w.dtb (file, 33672 bytes) - bcm2710-rpi-zero-2.dtb (file, 33672 bytes) Partition 2: success, fs.Type=3 Partition 2: ReadDir(/) entries: 21 - . (dir, 4096 bytes) - .. (dir, 4096 bytes) - lost+found (dir, 16384 bytes) - boot (dir, 4096 bytes) - bin (file, 7 bytes) - lib (file, 7 bytes) - sbin (file, 8 bytes) - dev (dir, 4096 bytes) - etc (dir, 4096 bytes) - home (dir, 4096 bytes) Partition 3: error: unknown filesystem on partition 3 Partition 4: error: unknown filesystem on partition 4Used
filesystem/ext4/testdata/buildimg.shto build test image and used new ext4-test.go on that image.Output: