Skip to content

Commit

Permalink
actions/image-partition: check filesystem label length in verify stage
Browse files Browse the repository at this point in the history
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.

Fixes: go-debos#251

Suggested-by: Christopher Obbard <[email protected]>
Signed-off-by: Vignesh Raman <[email protected]>
  • Loading branch information
vigneshraman committed Jul 27, 2021
1 parent 0bf4676 commit 6917710
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ to the `name` property of the partition. May only be used for GPT partitions.
- fslabel -- 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.
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
Expand Down Expand Up @@ -621,9 +622,31 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error {
}

if i.PartitionType == "gpt" {
var maxLength int = 0
if p.FSLabel == "" {
p.FSLabel = p.Name
}

switch p.FS {
case "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
}

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
}
}

if len(p.FSUUID) > 0 {
Expand Down

0 comments on commit 6917710

Please sign in to comment.