Skip to content
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 #531

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
51 changes: 43 additions & 8 deletions actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ a 32 bits hexadecimal number (e.g. '1234ABCD' without any dash separator).
- name: partition name
partlabel: partition label
fs: filesystem
fslabel: filesystem label
start: offset
end: offset
features: list of filesystem features
Expand Down Expand Up @@ -81,6 +82,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 -- label for the filesystem. Defaults
to the `name` property of the partition. The filesystem label can be up to 11
characters long for {v}fat{12|16|32}, 16 characters long for ext2/3/4, 255
characters long for btrfs, 512 characters long for hfs/hfsplus and 12 characters
long for xfs.

- 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
Expand Down Expand Up @@ -186,6 +193,7 @@ type Partition struct {
number int
Name string
PartLabel string
FSLabel string
PartType string
PartUUID string
Start string
Expand Down Expand Up @@ -352,7 +360,7 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC
cmdline := []string{}
switch p.FS {
case "fat", "fat12", "fat16", "fat32", "msdos", "vfat":
cmdline = append(cmdline, "mkfs.vfat", "-n", p.Name)
cmdline = append(cmdline, "mkfs.vfat", "-n", p.FSLabel)

switch p.FS {
case "fat12":
Expand All @@ -371,34 +379,34 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC
}
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, ","))
}
Expand Down Expand Up @@ -775,6 +783,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++
Expand Down Expand Up @@ -845,6 +854,32 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
if p.FS == "" {
return fmt.Errorf("Partition %s missing fs type", p.Name)
}

if p.FSLabel == "" {
p.FSLabel = p.Name
}

switch p.FS {
case "fat", "fat12", "fat16", "fat32", "msdos", "vfat":
maxLength = 11
case "ext2", "ext3", "ext4":
maxLength = 16
case "btrfs":
maxLength = 255
case "f2fs":
maxLength = 512
case "hfs", "hfsplus":
maxLength = 255
case "xfs":
maxLength = 12
case "none":
default:
log.Printf("Warning: setting a fs label for %s is unsupported", p.FS)
}

if maxLength > 0 && len(p.FSLabel) > maxLength {
return fmt.Errorf("fs label for %s '%s' is too long", p.Name, p.FSLabel)
}
}

for idx, _ := range i.Mountpoints {
Expand Down
Loading