Skip to content

Commit

Permalink
writable ext4
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Deitcher <[email protected]>
  • Loading branch information
deitch committed Jul 29, 2024
1 parent 11ccf43 commit 41a6fd1
Show file tree
Hide file tree
Showing 14 changed files with 1,672 additions and 172 deletions.
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
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 41a6fd1

Please sign in to comment.