-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
actions/image-partition: truncate filesystem label to maximum supported length #271
Open
vigneshraman
wants to merge
1
commit into
go-debos:main
Choose a base branch
from
vigneshraman:vigneshraman/debos/issues/251-v1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ Yaml syntax for partitions: | |
- name: partition name | ||
partlabel: partition label | ||
fs: filesystem | ||
fslabel: filesystem label | ||
start: offset | ||
end: offset | ||
features: list of filesystem features | ||
|
@@ -72,6 +73,12 @@ Optional properties: | |
- partlabel -- label for the partition in the GPT partition table. Defaults | ||
to the `name` property of the partition. May only be used for GPT partitions. | ||
|
||
- fslabel -- (optional) Sets the volume name (label) of the filesystem. Defaults | ||
to the `name` property of the partition. The filesystem label can be up to 11 | ||
characters long for vfat, 16 characters long for ext2/3/4, 255 characters long | ||
for btrfs, 512 characters long for hfs/hfsplus and 12 characters long for xfs. | ||
Any longer labels will be automatically truncated. | ||
|
||
- parttype -- set the partition type in the partition table. The string should | ||
be in a hexadecimal format (2-characters) for msdos partition tables and GUID format | ||
(36-characters) for GPT partition tables. For instance, "82" for msdos sets the | ||
|
@@ -168,6 +175,7 @@ type Partition struct { | |
number int | ||
Name string | ||
PartLabel string | ||
FSLabel string | ||
PartType string | ||
Start string | ||
End string | ||
|
@@ -305,37 +313,37 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC | |
cmdline := []string{} | ||
switch p.FS { | ||
case "vfat": | ||
cmdline = append(cmdline, "mkfs.vfat", "-F32", "-n", p.Name) | ||
cmdline = append(cmdline, "mkfs.vfat", "-F32", "-n", p.FSLabel) | ||
case "btrfs": | ||
// Force formatting to prevent failure in case if partition was formatted already | ||
cmdline = append(cmdline, "mkfs.btrfs", "-L", p.Name, "-f") | ||
cmdline = append(cmdline, "mkfs.btrfs", "-L", p.FSLabel, "-f") | ||
if len(p.Features) > 0 { | ||
cmdline = append(cmdline, "-O", strings.Join(p.Features, ",")) | ||
} | ||
if len(p.FSUUID) > 0 { | ||
cmdline = append(cmdline, "-U", p.FSUUID) | ||
} | ||
case "f2fs": | ||
cmdline = append(cmdline, "mkfs.f2fs", "-l", p.Name) | ||
cmdline = append(cmdline, "mkfs.f2fs", "-l", p.FSLabel) | ||
if len(p.Features) > 0 { | ||
cmdline = append(cmdline, "-O", strings.Join(p.Features, ",")) | ||
} | ||
case "hfs": | ||
cmdline = append(cmdline, "mkfs.hfs", "-h", "-v", p.Name) | ||
cmdline = append(cmdline, "mkfs.hfs", "-h", "-v", p.FSLabel) | ||
case "hfsplus": | ||
cmdline = append(cmdline, "mkfs.hfsplus", "-v", p.Name) | ||
cmdline = append(cmdline, "mkfs.hfsplus", "-v", p.FSLabel) | ||
case "hfsx": | ||
cmdline = append(cmdline, "mkfs.hfsplus", "-s", "-v", p.Name) | ||
cmdline = append(cmdline, "mkfs.hfsplus", "-s", "-v", p.FSLabel) | ||
// hfsx is case-insensitive hfs+, should be treated as "normal" hfs+ from now on | ||
p.FS = "hfsplus" | ||
case "xfs": | ||
cmdline = append(cmdline, "mkfs.xfs", "-L", p.Name) | ||
cmdline = append(cmdline, "mkfs.xfs", "-L", p.FSLabel) | ||
if len(p.FSUUID) > 0 { | ||
cmdline = append(cmdline, "-m", "uuid="+p.FSUUID) | ||
} | ||
case "none": | ||
default: | ||
cmdline = append(cmdline, fmt.Sprintf("mkfs.%s", p.FS), "-L", p.Name) | ||
cmdline = append(cmdline, fmt.Sprintf("mkfs.%s", p.FS), "-L", p.FSLabel) | ||
if len(p.Features) > 0 { | ||
cmdline = append(cmdline, "-O", strings.Join(p.Features, ",")) | ||
} | ||
|
@@ -599,6 +607,7 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error { | |
|
||
num := 1 | ||
for idx, _ := range i.Partitions { | ||
var maxLength int = 0 | ||
p := &i.Partitions[idx] | ||
p.number = num | ||
num++ | ||
|
@@ -654,6 +663,31 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error { | |
case "": | ||
return fmt.Errorf("Partition %s missing fs type", p.Name) | ||
} | ||
|
||
if p.FSLabel == "" { | ||
p.FSLabel = p.Name | ||
} | ||
|
||
switch p.FS { | ||
case "vfat": | ||
maxLength = 11 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also warn if someone tries to set an fslabel for an unsupported fs (but ignore |
||
case "ext2", "ext3", "ext4": | ||
maxLength = 16 | ||
case "btrfs": | ||
maxLength = 255 | ||
case "f2fs": | ||
maxLength = 512 | ||
case "hfs", "hfsplus": | ||
maxLength = 255 | ||
case "xfs": | ||
maxLength = 12 | ||
} | ||
|
||
if maxLength > 0 && len(p.FSLabel) > maxLength { | ||
truncated := p.FSLabel[0:maxLength] | ||
log.Printf("Warning: fs label for %s '%s' is too long; truncated to '%s'", p.Name, p.FSLabel, truncated) | ||
p.FSLabel = truncated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why truncate rather then erroring out? |
||
} | ||
} | ||
|
||
for idx, _ := range i.Mountpoints { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.