Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow setting read/write, UUID and volume name options for EXT4 file systems #2199

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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