Skip to content

Commit f92199d

Browse files
authored
Merge pull request #243 from diskfs/ext4-write
writable ext4
2 parents 11ccf43 + f46e730 commit f92199d

File tree

17 files changed

+1775
-203
lines changed

17 files changed

+1775
-203
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ cat $PWD/foo.img | docker run -i --rm $INT_IMAGE mdir -i /file.img /abc
109109
Future plans are to add the following:
110110

111111
* embed boot code in `mbr` e.g. `altmbr.bin` (no need for `gpt` since an ESP with `/EFI/BOOT/BOOT<arch>.EFI` will boot)
112-
* `ext4` filesystem writing (read-only already works)
113112
* `Joliet` extensions to `iso9660`
114113
* `Rock Ridge` sparse file support - supports the flag, but not yet reading or writing
115114
* `squashfs` sparse file support - currently treats sparse files as regular files

filesystem/ext4/bitmaps.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

filesystem/ext4/blockgroup.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package ext4
22

33
import (
44
"fmt"
5+
6+
"github.com/diskfs/go-diskfs/util"
57
)
68

79
// blockGroup is a structure holding the data about a single block group
810
//
911
//nolint:unused // will be used in the future, not yet
1012
type blockGroup struct {
11-
inodeBitmap *bitmap
12-
blockBitmap *bitmap
13+
inodeBitmap *util.Bitmap
14+
blockBitmap *util.Bitmap
1315
blockSize int
1416
number int
1517
inodeTableSize int
@@ -26,8 +28,8 @@ func blockGroupFromBytes(b []byte, blockSize, groupNumber int) (*blockGroup, err
2628
if actualSize != expectedSize {
2729
return nil, fmt.Errorf("expected to be passed %d bytes for 2 blocks of size %d, instead received %d", expectedSize, blockSize, actualSize)
2830
}
29-
inodeBitmap := bitmapFromBytes(b[0:blockSize])
30-
blockBitmap := bitmapFromBytes(b[blockSize : 2*blockSize])
31+
inodeBitmap := util.BitmapFromBytes(b[0:blockSize])
32+
blockBitmap := util.BitmapFromBytes(b[blockSize : 2*blockSize])
3133

3234
bg := blockGroup{
3335
inodeBitmap: inodeBitmap,
@@ -43,8 +45,8 @@ func blockGroupFromBytes(b []byte, blockSize, groupNumber int) (*blockGroup, err
4345
//nolint:unused // will be used in the future, not yet
4446
func (bg *blockGroup) toBytes() ([]byte, error) {
4547
b := make([]byte, 2*bg.blockSize)
46-
inodeBitmapBytes := bg.inodeBitmap.toBytes()
47-
blockBitmapBytes := bg.blockBitmap.toBytes()
48+
inodeBitmapBytes := bg.inodeBitmap.ToBytes()
49+
blockBitmapBytes := bg.blockBitmap.ToBytes()
4850

4951
b = append(b, inodeBitmapBytes...)
5052
b = append(b, blockBitmapBytes...)

filesystem/ext4/checksum.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func directoryChecksummer(seed, inodeNumber, inodeGeneration uint32) checksummer
2929
// directoryChecksumAppender returns a function that implements checksumAppender for a directory entries block
3030
// original calculations can be seen for e2fsprogs https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/tree/lib/ext2fs/csum.c#n301
3131
// and in the linux tree https://github.com/torvalds/linux/blob/master/fs/ext4/namei.c#L376-L384
32+
//
33+
//nolint:unparam // inodeGeneration is always 0
3234
func directoryChecksumAppender(seed, inodeNumber, inodeGeneration uint32) checksumAppender {
3335
fn := directoryChecksummer(seed, inodeNumber, inodeGeneration)
3436
return func(b []byte) []byte {

filesystem/ext4/consts.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ext4
2+
3+
const (
4+
maxUint16 uint64 = 1<<16 - 1
5+
)

filesystem/ext4/directory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (d *Directory) toBytes(bytesPerBlock uint32, checksumFunc checksumAppender)
3636
switch {
3737
case len(block)+len(b2) > int(bytesPerBlock)-minDirEntryLength:
3838
// if adding this one will go past the end of the block, pad out the previous
39-
block = b[:len(block)-previousLength]
39+
block = block[:len(block)-previousLength]
4040
previousB := previousEntry.toBytes(uint16(int(bytesPerBlock) - len(block) - minDirEntryLength))
4141
block = append(block, previousB...)
4242
// add the checksum

0 commit comments

Comments
 (0)