erofs-utils: mkfs: Add volume-label setting support
authorNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Tue, 4 Oct 2022 17:01:15 +0000 (02:01 +0900)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 7 Oct 2022 17:01:48 +0000 (01:01 +0800)
The on-disk erofs_super_block has the volume_name field.  On the other
hand, mkfs.erofs doesn't support setting volume label.

This patch adds volume-label setting support to mkfs.erofs.
Option keyword is similar to mke2fs.

Usage:
  mkfs.erofs -L volume-label image-fn dir

Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/YzxzRTg5oUeOCMr+@debian
include/erofs/internal.h
man/mkfs.erofs.1
mkfs/main.c

index db7ac2d87b388f1042958b648dad6a3f086f2fb8..13c691b655e2d52911ea8c48c1b37c6b353ce88f 100644 (file)
@@ -94,6 +94,7 @@ struct erofs_sb_info {
        u64 inos;
 
        u8 uuid[16];
+       char volume_name[16];
 
        u16 available_compr_algs;
        u16 lz4_max_distance;
index 11e832346d64b08f63fbd7a4d5b3089861511762..b65d01bf9ff2b27853ca9bd9fccf9665ee020d6b 100644 (file)
@@ -66,6 +66,11 @@ Pack the tail part (pcluster) of compressed files into its metadata to save
 more space and the tail part I/O. (Linux v5.17+)
 .RE
 .TP
+.BI "\-L " volume-label
+Set the volume label for the filesystem to
+.IR volume-label .
+The maximum length of the volume label is 16 bytes.
+.TP
 .BI "\-T " #
 Set all files to the given UNIX timestamp. Reproducible builds requires setting
 all to a specific one.
index 8b97796ee191ea0e55dd61063b63d3ad2aca22ad..00a2deb3b55c20a792de53e68ad8c61cfbddb88c 100644 (file)
@@ -86,6 +86,7 @@ static void usage(void)
              " -zX[,Y]               X=compressor (Y=compression level, optional)\n"
              " -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"
              " -T#                   set a fixed UNIX timestamp # to all files\n"
 #ifdef HAVE_LIBUUID
              " -UX                   use a given filesystem UUID\n"
@@ -237,7 +238,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
        int opt, i;
        bool quiet = false;
 
-       while ((opt = getopt_long(argc, argv, "C:E:T:U:d:x:z:",
+       while ((opt = getopt_long(argc, argv, "C:E:L:T:U:d:x:z:",
                                  long_options, NULL)) != -1) {
                switch (opt) {
                case 'z':
@@ -280,6 +281,17 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                        if (opt)
                                return opt;
                        break;
+
+               case 'L':
+                       if (optarg == NULL ||
+                           strlen(optarg) > sizeof(sbi.volume_name)) {
+                               erofs_err("invalid volume label");
+                               return -EINVAL;
+                       }
+                       strncpy(sbi.volume_name, optarg,
+                               sizeof(sbi.volume_name));
+                       break;
+
                case 'T':
                        cfg.c_unix_timestamp = strtoull(optarg, &endptr, 0);
                        if (cfg.c_unix_timestamp == -1 || *endptr != '\0') {
@@ -510,6 +522,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
        sb.root_nid     = cpu_to_le16(root_nid);
        sb.packed_nid    = cpu_to_le64(packed_nid);
        memcpy(sb.uuid, sbi.uuid, sizeof(sb.uuid));
+       memcpy(sb.volume_name, sbi.volume_name, sizeof(sb.volume_name));
 
        if (erofs_sb_has_compr_cfgs())
                sb.u1.available_compr_algs = sbi.available_compr_algs;