Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f3c9fd6
filesystem: add EROFS type
carbonin Oct 20, 2026
296146d
erofs: parse and validate superblocks
carbonin Oct 20, 2026
ee3101c
erofs: add core uncompressed reader
carbonin Oct 20, 2026
2e04f25
erofs: support compressed LZMA files
carbonin Oct 21, 2026
89e7151
erofs: accept padded final directory names
carbonin Oct 21, 2026
d5de6fd
erofs: separate superblock checksum verification
carbonin Oct 22, 2026
5427e35
erofs: split reads across inline tail boundary
carbonin Oct 22, 2026
ab8ef2d
erofs: add reproducible compatibility fixtures
carbonin Oct 22, 2026
6036dba
erofs: test full and malformed compressed indexes
carbonin Oct 22, 2026
df26a55
erofs: fix opened-directory io/fs behavior
carbonin Oct 22, 2026
d575193
disk: detect EROFS filesystems
carbonin Oct 22, 2026
e5df9d3
erofs: test unsupported feature rejection
carbonin Oct 22, 2026
6b5f69e
docs: document EROFS reader support
carbonin Oct 22, 2026
f893c71
erofs: fix compact directory external data
carbonin Oct 26, 2026
bb24855
erofs: reject unknown compression algorithms
carbonin Oct 26, 2026
fea401a
erofs: reject directory name ranges outside blocks
carbonin Oct 26, 2026
c462d63
erofs: count reads across inline boundaries
carbonin Oct 26, 2026
4b50fdd
erofs: preserve high fragment offset bits
carbonin Oct 26, 2026
e6d61e9
erofs: match complete inode file types
carbonin Oct 26, 2026
76fb58a
erofs: reject directory names with slashes
carbonin Oct 26, 2026
062a6db
erofs: validate inode numbers before address math
carbonin Oct 26, 2026
2ae9c03
erofs: reject unsupported filesystem creation
carbonin Oct 26, 2026
82bc426
erofs: preserve special permission bits
carbonin Oct 26, 2026
cbf124b
erofs: enforce filesystem bounds on all reads
carbonin Oct 29, 2026
2d4ad4c
erofs: wrap public path errors with operation context
carbonin Oct 29, 2026
e2c003e
erofs: clamp directory counts before advancing the cursor
carbonin Oct 29, 2026
6be5e99
erofs: preserve the complete encoded device number
carbonin Oct 29, 2026
b5a4420
erofs: return EOF for reads beyond the end of a file
carbonin Oct 29, 2026
2b28495
erofs: retain a bounded decoded extent across file reads
carbonin Oct 29, 2026
00d1945
erofs: simplify compressed extent boundary mapping
carbonin Oct 29, 2026
302a6f2
erofs: discard unused inode and compression state
carbonin Oct 29, 2026
a426c65
erofs: explain compression formats and offset units
carbonin Oct 29, 2026
ba0b519
erofs: document unsupported reader formats
carbonin Oct 29, 2026
0eadf4a
erofs: document symlink inspection semantics
carbonin Oct 29, 2026
bc616e1
erofs: document backend ownership and close behavior
carbonin Oct 29, 2026
4b128fb
erofs: return consistent read-only errors for mutations
carbonin Oct 29, 2026
d6f7b2e
docs: Read only erofs clarification
carbonin Oct 30, 2026
306cfd9
erofs: fix golangci-lint findings
carbonin Oct 30, 2026
45b7126
erofs: script reproducible test fixture generation
carbonin Nov 2, 2026
02f072b
erofs: link format specifications in package documentation
carbonin Nov 2, 2026
608d220
erofs: use committed fixtures for compatibility tests
carbonin Nov 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ Once you have a valid disk, and optionally partition, you can access filesystems
* `CreateFilesystem()` - create a filesystem in an individual partition or the entire disk
* `GetFilesystem()` - access an existing filesystem in a partition or the entire disk

As of this writing, supported filesystems include `FAT32` and `ISO9660` (a.k.a. `.iso`).
As of this writing, supported filesystems include `FAT32`, `ISO9660` (a.k.a. `.iso`), `SquashFS`, `ext4`, and read-only `EROFS`.

EROFS support targets a read-only subset of the EROFS on-disk format: basic and
LZMA-compressed files, compact and full compression indexes, fragment tails,
and large logical clusters. Extended attributes are not exposed. See the
[filesystem/erofs](./filesystem/erofs) package documentation for details,
including how to read an image nested inside another backend.

With a filesystem in hand, you can create, access and modify directories and files.

Expand All @@ -84,7 +90,7 @@ With a `File` in hand, you then can:
* `Seek(offset int64, whence int)` to set the next read or write to an offset in the file

### Read-Only Filesystems
Some filesystem types are intended to be created once, after which they are read-only, for example `ISO9660`/`.iso` and `squashfs`.
Some filesystem types are intended to be created once, after which they are read-only, for example `ISO9660`/`.iso` and `squashfs`. EROFS is currently read-only with no creation support.

`godiskfs` recognizes read-only filesystems and limits working with them to the following:

Expand Down
9 changes: 9 additions & 0 deletions disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/diskfs/go-diskfs/backend"
"github.com/diskfs/go-diskfs/filesystem"
"github.com/diskfs/go-diskfs/filesystem/erofs"
"github.com/diskfs/go-diskfs/filesystem/ext4"
"github.com/diskfs/go-diskfs/filesystem/fat12"
"github.com/diskfs/go-diskfs/filesystem/fat16"
Expand Down Expand Up @@ -178,6 +179,8 @@ func (d *Disk) CreateFilesystem(spec FilesystemSpec) (filesystem.FileSystem, err
return ext4.Create(d.Backend, size, start, d.LogicalBlocksize, &ext4.Params{VolumeName: spec.VolumeLabel})
case filesystem.TypeSquashfs:
return squashfs.Create(d.Backend, size, start, d.LogicalBlocksize)
case filesystem.TypeErofs:
return nil, filesystem.ErrNotImplemented
default:
return nil, errors.New("unknown filesystem type requested")
}
Expand Down Expand Up @@ -246,6 +249,12 @@ func (d *Disk) GetFilesystem(partIndex int) (filesystem.FileSystem, error) {
if err == nil {
return squashFS, nil
}
log.Debug("trying erofs")
erofsFS, err := erofs.Read(d.Backend, size, start, 0)
if err == nil {
return erofsFS, nil
}
log.Debugf("erofs failed: %v", err)
log.Debug("trying ext4")
ext4FS, err := ext4.Read(d.Backend, size, start, d.LogicalBlocksize)
if err == nil {
Expand Down
49 changes: 49 additions & 0 deletions disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,53 @@ func TestGetFilesystem(t *testing.T) {
t.Errorf("returned filesystem was unexpectedly nil")
}
})
t.Run("erofs partition", func(t *testing.T) {
image, err := os.ReadFile("../filesystem/erofs/testdata/compressed.erofs")
if err != nil {
t.Fatalf("error reading EROFS fixture: %v", err)
}
f, err := os.CreateTemp("", "erofs_disk_test")
if err != nil {
t.Fatalf("error creating temporary disk: %v", err)
}
defer f.Close()
if _, err := f.Write(make([]byte, 4096)); err != nil {
t.Fatalf("error writing partition prefix: %v", err)
}
if _, err := f.Write(image); err != nil {
t.Fatalf("error writing EROFS image: %v", err)
}
fileInfo, err := f.Stat()
if err != nil {
t.Fatalf("error reading temporary disk info: %v", err)
}

table := &mbr.Table{
Partitions: []*mbr.Partition{
{Index: 1, Start: 8, Size: uint32(len(image) / 512)},
},
LogicalSectorSize: 512,
}
d := &disk.Disk{
Backend: file.New(f, true),
LogicalBlocksize: 512,
PhysicalBlocksize: 512,
Size: fileInfo.Size(),
Table: table,
}
fs, err := d.GetFilesystem(1)
if err != nil {
t.Fatalf("GetFilesystem() error = %v", err)
}
if fs.Type() != filesystem.TypeErofs {
t.Fatalf("filesystem type = %v, want %v", fs.Type(), filesystem.TypeErofs)
}
data, err := fs.ReadFile("sub/data.bin")
if err != nil {
t.Fatalf("ReadFile() error = %v", err)
}
if len(data) != 96*1024 {
t.Fatalf("ReadFile() length = %d, want %d", len(data), 96*1024)
}
})
}
43 changes: 43 additions & 0 deletions filesystem/erofs/cache_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package erofs

import (
"bytes"
"io"
"os"
"sync"
"testing"
)

func TestConcurrentCompressedReadAt(t *testing.T) {
filesystem := readTestImage(t, fullFixture)
opened, err := filesystem.OpenFile("data.bin", os.O_RDONLY)
if err != nil {
t.Fatal(err)
}
defer opened.Close()
reader, ok := opened.(io.ReaderAt)
if !ok {
t.Fatalf("OpenFile() returned %T, want io.ReaderAt", opened)
}
payload := fullFixturePayload()
var workers sync.WaitGroup
for worker := 0; worker < 8; worker++ {
workers.Go(func() {
buffer := make([]byte, 1024)
for i := 0; i < 32; i++ {
offset := (worker*7919 + i*4093) % (len(payload) - len(buffer))
n, err := reader.ReadAt(buffer, int64(offset))
if err != nil || n != len(buffer) || !bytes.Equal(buffer, payload[offset:offset+n]) {
t.Errorf("ReadAt(%d) = %d, %v or incorrect data", offset, n, err)
return
}
}
})
}
workers.Wait()
// ReaderAt must not change the sequential cursor.
buffer := make([]byte, 32)
if _, err := io.ReadFull(opened, buffer); err != nil || !bytes.Equal(buffer, payload[:len(buffer)]) {
t.Fatalf("Read after ReadAt = %x, %v", buffer, err)
}
}
Loading
Loading