Skip to contentSkip to conversation

erofs-utils: lib: migrate `c_force_inodeversion`

PATCH New Gao Xiang 1 participant 2 messages Sep 9, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: lib: migrate `c_force_inodeversion`

---
 include/erofs/config.h   |  7 -------
 include/erofs/importer.h |  6 ++++++
 lib/config.c             |  1 -
 lib/inode.c              | 20 +++++++++++---------
 mkfs/main.c              |  9 +++++----
 5 files changed, 22 insertions(+), 21 deletions(-)
include/erofs/config.h +0 -7
index 0312909..6554ad2 100644
@@ -15,12 +15,6 @@ extern "C"
 #include "defs.h"
 #include "err.h"
 
-
-enum {
-	FORCE_INODE_COMPACT = 1,
-	FORCE_INODE_EXTENDED,
-};
-
 enum {
 	FORCE_INODE_BLOCK_MAP = 1,
 	FORCE_INODE_CHUNK_INDEXES,
@@ -73,7 +67,6 @@ struct erofs_configure {
 	char *c_blobdev_path;
 	char *c_compress_hints_file;
 	struct erofs_compr_opts c_compr_opts[EROFS_MAX_COMPR_CFGS];
-	char c_force_inodeversion;
 	char c_force_chunkformat;
 	u8 c_mkfs_metabox_algid;
 	/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
include/erofs/importer.h +6 -0
index 28d29bd..85e3a50 100644
@@ -12,6 +12,11 @@ extern "C"
 
 #include "internal.h"
 
+enum {
+	EROFS_FORCE_INODE_COMPACT = 1,
+	EROFS_FORCE_INODE_EXTENDED,
+};
+
 struct erofs_importer_params {
 	char *source;
 	u32 mt_async_queue_limit;
@@ -20,6 +25,7 @@ struct erofs_importer_params {
 	u32 uid_offset;
 	u32 gid_offset;
 	u32 fsalignblks;
+	char force_inodeversion;
 	bool no_datainline;
 	bool hard_dereference;
 	bool ovlfs_strip;
lib/config.c +0 -1
index c5e6757..28bfc2f 100644
@@ -30,7 +30,6 @@ void erofs_init_configure(void)
 	cfg.c_version  = PACKAGE_VERSION;
 	cfg.c_dry_run  = false;
 	cfg.c_ignore_mtime = false;
-	cfg.c_force_inodeversion = 0;
 	cfg.c_inline_xattr_tolerance = 2;
 	cfg.c_unix_timestamp = -1;
 	cfg.c_max_decompressed_extent_bytes = -1;
lib/inode.c +11 -9
index 7ee6b3d..0bb82f8 100644
@@ -1073,10 +1073,10 @@ out:
 	return 0;
 }
 
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
-					    const char *path)
+static bool erofs_should_use_inode_extended(struct erofs_importer *im,
+				struct erofs_inode *inode, const char *path)
 {
-	if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
+	if (im->params->force_inodeversion == EROFS_FORCE_INODE_EXTENDED)
 		return true;
 	if (inode->i_size > UINT_MAX)
 		return true;
@@ -1206,8 +1206,10 @@ int __erofs_fill_inode(struct erofs_importer *im, struct erofs_inode *inode,
 static int erofs_fill_inode(struct erofs_importer *im, struct erofs_inode *inode,
 			    struct stat *st, const char *path)
 {
-	int err = __erofs_fill_inode(im, inode, st, path);
+	const struct erofs_importer_params *params = im->params;
+	int err;
 
+	err =  __erofs_fill_inode(im, inode, st, path);
 	if (err)
 		return err;
 
@@ -1239,8 +1241,8 @@ static int erofs_fill_inode(struct erofs_importer *im, struct erofs_inode *inode
 			return -ENOMEM;
 	}
 
-	if (erofs_should_use_inode_extended(inode, path)) {
-		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
+	if (erofs_should_use_inode_extended(im, inode, path)) {
+		if (params->force_inodeversion == EROFS_FORCE_INODE_COMPACT) {
 			erofs_err("file %s cannot be in compact form",
 				  inode->i_srcpath);
 			return -EINVAL;
@@ -1813,7 +1815,7 @@ static int erofs_mkfs_handle_inode(struct erofs_importer *im,
 static int erofs_rebuild_handle_inode(struct erofs_importer *im,
 				    struct erofs_inode *inode, bool incremental)
 {
-	struct erofs_importer_params *params = im->params;
+	const struct erofs_importer_params *params = im->params;
 	char *trimmed;
 	int ret;
 
@@ -1822,8 +1824,8 @@ static int erofs_rebuild_handle_inode(struct erofs_importer *im,
 	erofs_update_progressinfo("Processing %s ...", trimmed);
 	free(trimmed);
 
-	if (erofs_should_use_inode_extended(inode, inode->i_srcpath)) {
-		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
+	if (erofs_should_use_inode_extended(im, inode, inode->i_srcpath)) {
+		if (params->force_inodeversion == EROFS_FORCE_INODE_COMPACT) {
 			erofs_err("file %s cannot be in compact form",
 				  inode->i_srcpath);
 			return -EINVAL;
mkfs/main.c +5 -4
index 28588db..4f52656 100644
@@ -416,7 +416,8 @@ static struct {
 
 static bool mkfs_no_datainline;
 
-static int parse_extended_opts(const char *opts)
+static int parse_extended_opts(struct erofs_importer_params *params,
+			       const char *opts)
 {
 #define MATCH_EXTENTED_OPT(opt, token, keylen) \
 	(keylen == strlen(opt) && !memcmp(token, opt, keylen))
@@ -461,12 +462,12 @@ static int parse_extended_opts(const char *opts)
 		if (MATCH_EXTENTED_OPT("force-inode-compact", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
-			cfg.c_force_inodeversion = FORCE_INODE_COMPACT;
+			params->force_inodeversion = EROFS_FORCE_INODE_COMPACT;
 			cfg.c_ignore_mtime = true;
 		} else if (MATCH_EXTENTED_OPT("force-inode-extended", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
-			cfg.c_force_inodeversion = FORCE_INODE_EXTENDED;
+			params->force_inodeversion = EROFS_FORCE_INODE_EXTENDED;
 		} else if (MATCH_EXTENTED_OPT("nosbcrc", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
@@ -1011,7 +1012,7 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 			break;
 
 		case 'E':
-			opt = parse_extended_opts(optarg);
+			opt = parse_extended_opts(params, optarg);
 			if (opt)
 				return opt;
 			break;
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/2 erofs-utils: lib: migrate `c_ignore_mtime`

---
 include/erofs/config.h   |  1 -
 include/erofs/importer.h |  1 +
 lib/config.c             |  1 -
 lib/inode.c              | 18 +++++++++++-------
 mkfs/main.c              |  6 +++---
 5 files changed, 15 insertions(+), 12 deletions(-)
include/erofs/config.h +0 -1
index 6554ad2..67f5aa3 100644
@@ -53,7 +53,6 @@ struct erofs_configure {
 	bool c_all_fragments;
 	bool c_dedupe;
 	char c_fragdedupe;
-	bool c_ignore_mtime;
 	bool c_showprogress;
 	bool c_extra_ea_name_prefixes;
 	bool c_xattr_name_filter;
include/erofs/importer.h +1 -0
index 85e3a50..a5a4c8c 100644
@@ -26,6 +26,7 @@ struct erofs_importer_params {
 	u32 gid_offset;
 	u32 fsalignblks;
 	char force_inodeversion;
+	bool ignore_mtime;
 	bool no_datainline;
 	bool hard_dereference;
 	bool ovlfs_strip;
lib/config.c +0 -1
index 28bfc2f..b1d076d 100644
@@ -29,7 +29,6 @@ void erofs_init_configure(void)
 	cfg.c_dbg_lvl  = EROFS_WARN;
 	cfg.c_version  = PACKAGE_VERSION;
 	cfg.c_dry_run  = false;
-	cfg.c_ignore_mtime = false;
 	cfg.c_inline_xattr_tolerance = 2;
 	cfg.c_unix_timestamp = -1;
 	cfg.c_max_decompressed_extent_bytes = -1;
lib/inode.c +11 -7
index 0bb82f8..75a0b4d 100644
@@ -717,7 +717,7 @@ int erofs_iflush(struct erofs_inode *inode)
 	    inode->u.i_blocks > UINT32_MAX) {
 		nb.blocks_hi = cpu_to_le16(inode->u.i_blocks >> 32);
 	} else if (inode->datalayout != EROFS_INODE_CHUNK_BASED &&
-		 inode->u.i_blkaddr > UINT32_MAX) {
+		   inode->u.i_blkaddr > UINT32_MAX) {
 		nb.startblk_hi = cpu_to_le16(inode->u.i_blkaddr >> 32);
 		if (inode->u.i_blkaddr == EROFS_NULL_ADDR) {
 			nlink_1 = false;
@@ -744,8 +744,7 @@ int erofs_iflush(struct erofs_inode *inode)
 
 		u.dic.i_uid = cpu_to_le16((u16)inode->i_uid);
 		u.dic.i_gid = cpu_to_le16((u16)inode->i_gid);
-		if (!cfg.c_ignore_mtime)
-			u.dic.i_mtime = cpu_to_le64(inode->i_mtime - sbi->epoch);
+		u.dic.i_mtime = cpu_to_le64(inode->i_mtime - sbi->epoch);
 		u.dic.i_u = u1;
 
 		if (nlink_1) {
@@ -1076,7 +1075,9 @@ out:
 static bool erofs_should_use_inode_extended(struct erofs_importer *im,
 				struct erofs_inode *inode, const char *path)
 {
-	if (im->params->force_inodeversion == EROFS_FORCE_INODE_EXTENDED)
+	const struct erofs_importer_params *params = im->params;
+
+	if (params->force_inodeversion == EROFS_FORCE_INODE_EXTENDED)
 		return true;
 	if (inode->i_size > UINT_MAX)
 		return true;
@@ -1088,10 +1089,13 @@ static bool erofs_should_use_inode_extended(struct erofs_importer *im,
 		return true;
 	if (inode->i_nlink > USHRT_MAX)
 		return true;
-	if (!erofs_is_special_identifier(path) && !cfg.c_ignore_mtime &&
+	if (!erofs_is_special_identifier(path) &&
 	    !erofs_sb_has_48bit(inode->sbi) &&
-	    inode->i_mtime != inode->sbi->epoch)
-		return true;
+	    inode->i_mtime != inode->sbi->epoch) {
+		if (!params->ignore_mtime)
+			return true;
+		inode->i_mtime = inode->sbi->epoch;
+	}
 	return false;
 }
 
mkfs/main.c +3 -3
index 4f52656..1b5cb2b 100644
@@ -463,7 +463,7 @@ static int parse_extended_opts(struct erofs_importer_params *params,
 			if (vallen)
 				return -EINVAL;
 			params->force_inodeversion = EROFS_FORCE_INODE_COMPACT;
-			cfg.c_ignore_mtime = true;
+			params->ignore_mtime = true;
 		} else if (MATCH_EXTENTED_OPT("force-inode-extended", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
@@ -1170,10 +1170,10 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 			cfg.c_blobdev_path = optarg;
 			break;
 		case 14:
-			cfg.c_ignore_mtime = true;
+			params->ignore_mtime = true;
 			break;
 		case 15:
-			cfg.c_ignore_mtime = false;
+			params->ignore_mtime = false;
 			break;
 		case 16:
 			errno = 0;
Signature · 1 line
2.43.5