Skip to content

Commit

Permalink
feature: Allow setting read/write, UUID and volume name option for EX…
Browse files Browse the repository at this point in the history
…T4 file system writer

Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
  • Loading branch information
pojntfx committed Jul 10, 2024
1 parent 7af6804 commit 2f57b0f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ext4/internal/compactext4/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Writer struct {
initialized bool
supportInlineData bool
maxDiskSize int64
readWrite bool
uuid [16]byte
volumeName [16]byte
gdBlocks uint32
}

Expand Down Expand Up @@ -1141,6 +1144,25 @@ func MaximumDiskSize(size int64) Option {
}
}

// ReadWrite instructs the writer to not mark the file system as write-protected.
func ReadWrite(w *Writer) {
w.readWrite = true
}

// UUID instructs the writer to set the UUID.
func UUID(uuid [16]byte) Option {
return func(w *Writer) {
w.uuid = uuid
}
}

// VolumeName instructs the writer to set the volume name.
func VolumeName(volumeName [16]byte) Option {
return func(w *Writer) {
w.volumeName = volumeName
}
}

func (w *Writer) init() error {
// Skip the defective block inode.
w.inodes = make([]*inode, 1, 32)
Expand Down Expand Up @@ -1311,6 +1333,10 @@ func (w *Writer) Close() error {
// Write the super block
var blk [BlockSize]byte
b := bytes.NewBuffer(blk[:1024])
featureRoCompat := format.RoCompatLargeFile | format.RoCompatHugeFile | format.RoCompatExtraIsize
if !w.readWrite {
featureRoCompat |= format.RoCompatReadonly
}
sb := &format.SuperBlock{
InodesCount: inodesPerGroup * groups,
BlocksCountLow: diskSize,
Expand All @@ -1332,10 +1358,12 @@ func (w *Writer) Close() error {
InodeSize: inodeSize,
FeatureCompat: format.CompatSparseSuper2 | format.CompatExtAttr,
FeatureIncompat: format.IncompatFiletype | format.IncompatExtents | format.IncompatFlexBg,
FeatureRoCompat: format.RoCompatLargeFile | format.RoCompatHugeFile | format.RoCompatExtraIsize | format.RoCompatReadonly,
FeatureRoCompat: featureRoCompat,
MinExtraIsize: extraIsize,
WantExtraIsize: extraIsize,
LogGroupsPerFlex: 31,
UUID: w.uuid,
VolumeName: w.volumeName,
}
if w.supportInlineData {
sb.FeatureIncompat |= format.IncompatInlineData
Expand Down
21 changes: 21 additions & 0 deletions ext4/tar2ext4/tar2ext4.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ func MaximumDiskSize(size int64) Option {
}
}

// ReadWrite instructs the writer to not mark the file system as write-protected.
func ReadWrite() Option {
return func(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.ReadWrite)
}
}

// UUID instructs the writer to set the UUID.
func UUID(uuid [16]byte) Option {
return func(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.UUID(uuid))
}
}

// VolumeName instructs the writer to set the volume name.
func VolumeName(volumeName [16]byte) Option {
return func(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.VolumeName(volumeName))
}
}

const (
whiteoutPrefix = ".wh."
opaqueWhiteout = ".wh..wh..opq"
Expand Down

0 comments on commit 2f57b0f

Please # to comment.