Skip to content

Commit

Permalink
writable ext4
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Deitcher <avi@deitcher.net>
  • Loading branch information
deitch committed Jul 29, 2024
1 parent 11ccf43 commit f46e730
Show file tree
Hide file tree
Showing 17 changed files with 1,775 additions and 203 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ cat $PWD/foo.img | docker run -i --rm $INT_IMAGE mdir -i /file.img /abc
Future plans are to add the following:

* embed boot code in `mbr` e.g. `altmbr.bin` (no need for `gpt` since an ESP with `/EFI/BOOT/BOOT<arch>.EFI` will boot)
* `ext4` filesystem writing (read-only already works)
* `Joliet` extensions to `iso9660`
* `Rock Ridge` sparse file support - supports the flag, but not yet reading or writing
* `squashfs` sparse file support - currently treats sparse files as regular files
Expand Down
104 changes: 0 additions & 104 deletions filesystem/ext4/bitmaps.go

This file was deleted.

14 changes: 8 additions & 6 deletions filesystem/ext4/blockgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package ext4

import (
"fmt"

"github.com/diskfs/go-diskfs/util"
)

// blockGroup is a structure holding the data about a single block group
//
//nolint:unused // will be used in the future, not yet
type blockGroup struct {
inodeBitmap *bitmap
blockBitmap *bitmap
inodeBitmap *util.Bitmap
blockBitmap *util.Bitmap
blockSize int
number int
inodeTableSize int
Expand All @@ -26,8 +28,8 @@ func blockGroupFromBytes(b []byte, blockSize, groupNumber int) (*blockGroup, err
if actualSize != expectedSize {
return nil, fmt.Errorf("expected to be passed %d bytes for 2 blocks of size %d, instead received %d", expectedSize, blockSize, actualSize)
}
inodeBitmap := bitmapFromBytes(b[0:blockSize])
blockBitmap := bitmapFromBytes(b[blockSize : 2*blockSize])
inodeBitmap := util.BitmapFromBytes(b[0:blockSize])
blockBitmap := util.BitmapFromBytes(b[blockSize : 2*blockSize])

bg := blockGroup{
inodeBitmap: inodeBitmap,
Expand All @@ -43,8 +45,8 @@ func blockGroupFromBytes(b []byte, blockSize, groupNumber int) (*blockGroup, err
//nolint:unused // will be used in the future, not yet
func (bg *blockGroup) toBytes() ([]byte, error) {
b := make([]byte, 2*bg.blockSize)
inodeBitmapBytes := bg.inodeBitmap.toBytes()
blockBitmapBytes := bg.blockBitmap.toBytes()
inodeBitmapBytes := bg.inodeBitmap.ToBytes()
blockBitmapBytes := bg.blockBitmap.ToBytes()

b = append(b, inodeBitmapBytes...)
b = append(b, blockBitmapBytes...)
Expand Down
2 changes: 2 additions & 0 deletions filesystem/ext4/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func directoryChecksummer(seed, inodeNumber, inodeGeneration uint32) checksummer
// directoryChecksumAppender returns a function that implements checksumAppender for a directory entries block
// original calculations can be seen for e2fsprogs https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/tree/lib/ext2fs/csum.c#n301
// and in the linux tree https://github.com/torvalds/linux/blob/master/fs/ext4/namei.c#L376-L384
//
//nolint:unparam // inodeGeneration is always 0
func directoryChecksumAppender(seed, inodeNumber, inodeGeneration uint32) checksumAppender {
fn := directoryChecksummer(seed, inodeNumber, inodeGeneration)
return func(b []byte) []byte {
Expand Down
5 changes: 5 additions & 0 deletions filesystem/ext4/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ext4

const (
maxUint16 uint64 = 1<<16 - 1
)
2 changes: 1 addition & 1 deletion filesystem/ext4/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (d *Directory) toBytes(bytesPerBlock uint32, checksumFunc checksumAppender)
switch {
case len(block)+len(b2) > int(bytesPerBlock)-minDirEntryLength:
// if adding this one will go past the end of the block, pad out the previous
block = b[:len(block)-previousLength]
block = block[:len(block)-previousLength]
previousB := previousEntry.toBytes(uint16(int(bytesPerBlock) - len(block) - minDirEntryLength))
block = append(block, previousB...)
// add the checksum
Expand Down
Loading

0 comments on commit f46e730

Please sign in to comment.