[PATCH] erofs-utils: mkfs: Add volume-name setting support

Naoto Yamaguchi wata2ki at gmail.com
Wed Oct 5 03:02:37 AEDT 2022


The erofs_super_block has volume_name field.  On the other hand,
mkfs.erofs is not supporting to set volume name.
This patch add volume-name setting support to mkfs.erofs.
Option keyword is similar to mkfs.vfat.

usage:
  mkfs.erofs -n volume-name image-fn dir

Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi at aisin.co.jp>
---
 include/erofs/internal.h |  1 +
 man/mkfs.erofs.1         |  4 ++++
 mkfs/main.c              | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 2e0aae8..7dc42eb 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -92,6 +92,7 @@ struct erofs_sb_info {
 	u64 inos;
 
 	u8 uuid[16];
+	char volume_name[16];
 
 	u16 available_compr_algs;
 	u16 lz4_max_distance;
diff --git a/man/mkfs.erofs.1 b/man/mkfs.erofs.1
index 11e8323..fb98505 100644
--- a/man/mkfs.erofs.1
+++ b/man/mkfs.erofs.1
@@ -32,6 +32,10 @@ big pcluster feature if needed (Linux v5.13+).
 Specify the level of debugging messages. The default is 2, which shows basic
 warning messages.
 .TP
+.BI "\-n " volume-name
+Set the volume name for the filesystem to volume-name.  The maximum length of
+the volume name is 16 bytes.
+.TP
 .BI "\-x " #
 Specify the upper limit of an xattr which is still inlined. The default is 2.
 Disable storing xattrs if < 0.
diff --git a/mkfs/main.c b/mkfs/main.c
index 594ecf9..613ee46 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -80,6 +80,7 @@ static void usage(void)
 	fputs("usage: [options] FILE DIRECTORY\n\n"
 	      "Generate erofs image from DIRECTORY to FILE, and [options] are:\n"
 	      " -d#                   set output message level to # (maximum 9)\n"
+	      " -n volume-name        set the volume name (max 16 bytes).\n"
 	      " -x#                   set xattr tolerance to # (< 0, disable xattrs; default 2)\n"
 	      " -zX[,Y]               X=compressor (Y=compression level, optional)\n"
 	      " -C#                   specify the size of compress physical cluster in bytes\n"
@@ -212,7 +213,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:T:U:d:n:x:z:",
 				  long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'z':
@@ -241,6 +242,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			cfg.c_dbg_lvl = i;
 			break;
 
+		case 'n':
+			if (optarg == NULL || strlen(optarg) > 16) {
+				erofs_err("invalid volume name");
+				return -EINVAL;
+			}
+			strncpy(sbi.volume_name, optarg, 16);
+			break;
+
 		case 'x':
 			i = strtol(optarg, &endptr, 0);
 			if (*endptr != '\0') {
@@ -255,6 +264,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			if (opt)
 				return opt;
 			break;
+
 		case 'T':
 			cfg.c_unix_timestamp = strtoull(optarg, &endptr, 0);
 			if (cfg.c_unix_timestamp == -1 || *endptr != '\0') {
@@ -483,6 +493,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 	sb.blocks       = cpu_to_le32(*blocks);
 	sb.root_nid     = cpu_to_le16(root_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;
-- 
2.25.1



More information about the Linux-erofs mailing list