erofs-utils: adjust volume label maximum length to the kernel implementation
authorNaoto Yamaguchi <wata2ki@gmail.com>
Fri, 16 Aug 2024 03:13:36 +0000 (12:13 +0900)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 16 Aug 2024 06:27:50 +0000 (14:27 +0800)
The erofs implementation of kernel has limitation of the volume label length.
The volume label data size of super block is 16 bytes.
The kernel implementation requires to null terminate inside a that 16 bytes.

Logs:
  $ ./mkfs/mkfs.erofs test16.erofs -L 0123456789abcdef test/
  $ mount -o loop ./test16.erofs ./mnt/
  $ dmesg
  [26477.019283] erofs: (device loop0): erofs_read_superblock: bad volume name without NIL terminator

  $ ./mkfs/mkfs.erofs test15.erofs -L 0123456789abcde test/
  $ mount -o loop ./test15.erofs ./mnt/
  $ dmesg
  [26500.516871] erofs: (device loop0): mounted with root inode @ nid 36.

This patch adjusts volume label maximum length to the kernel implementation.

Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Link: https://lore.kernel.org/r/20240816031601.45848-1-naoto.yamaguchi@aisin.co.jp
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
mkfs/main.c

index b7129eb7c6e05489af9f950b3ee590dc920bc352..5cc2778aa368a4acbabe315adec564c0f5ea8671 100644 (file)
@@ -151,7 +151,7 @@ static void usage(int argc, char **argv)
        printf(
                " -C#                   specify the size of compress physical cluster in bytes\n"
                " -EX[,...]             X=extended options\n"
-               " -L volume-label       set the volume label (maximum 16)\n"
+               " -L volume-label       set the volume label (maximum 15 bytes)\n"
                " -T#                   specify a fixed UNIX timestamp # as build time\n"
                "    --all-time         the timestamp is also applied to all files (default)\n"
                "    --mkfs-time        the timestamp is applied as build time only\n"
@@ -598,7 +598,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 
                case 'L':
                        if (optarg == NULL ||
-                           strlen(optarg) > sizeof(g_sbi.volume_name)) {
+                           strlen(optarg) > (sizeof(g_sbi.volume_name) - 1u)) {
                                erofs_err("invalid volume label");
                                return -EINVAL;
                        }