* [PATCH mtd-utils 0/2] mtd-utils: fsck.ubifs: fixes several undefined behaviors
@ 2025-11-13 8:29 Yuta Hayama
2025-11-13 8:31 ` [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables Yuta Hayama
2025-11-13 8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama
0 siblings, 2 replies; 7+ messages in thread
From: Yuta Hayama @ 2025-11-13 8:29 UTC (permalink / raw)
To: linux-mtd; +Cc: Yuta Hayama
The first patch fixes the use of pointers to out-of-scope local variables.
The second patch fixes an issue where printf reads variables from the wrong
address due to an incorrect printf format length specifier. Note that the
former issue was detected by the cppcheck tool.
$ cppcheck fsck.ubifs/
Checking fsck.ubifs/check_files.c ...
fsck.ubifs/check_files.c:104:48: error: Using pointer to local variable 'ino_node' that is out of scope. [invalidLifetime]
inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
^
fsck.ubifs/check_files.c:71:31: note: Address of variable taken here.
sn = (struct scanned_node *)&ino_node;
^
fsck.ubifs/check_files.c:64:27: note: Variable created here.
struct scanned_ino_node ino_node;
^
fsck.ubifs/check_files.c:104:48: note: Using pointer to local variable 'ino_node' that is out of scope.
inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
^
fsck.ubifs/check_files.c:104:48: error: Using pointer to local variable 'dent_node' that is out of scope. [invalidLifetime]
inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
^
fsck.ubifs/check_files.c:84:31: note: Address of variable taken here.
sn = (struct scanned_node *)&dent_node;
^
fsck.ubifs/check_files.c:77:28: note: Variable created here.
struct scanned_dent_node dent_node;
^
fsck.ubifs/check_files.c:104:48: note: Using pointer to local variable 'dent_node' that is out of scope.
inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
^
fsck.ubifs/check_files.c:104:48: error: Using pointer to local variable 'data_node' that is out of scope. [invalidLifetime]
inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
^
fsck.ubifs/check_files.c:96:31: note: Address of variable taken here.
sn = (struct scanned_node *)&data_node;
^
fsck.ubifs/check_files.c:89:28: note: Variable created here.
struct scanned_data_node data_node;
^
fsck.ubifs/check_files.c:104:48: note: Using pointer to local variable 'data_node' that is out of scope.
inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs,
^
fsck.ubifs/check_files.c:106:40: error: Using pointer to local variable 'ino_node' that is out of scope. [invalidLifetime]
return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
^
fsck.ubifs/check_files.c:71:31: note: Address of variable taken here.
sn = (struct scanned_node *)&ino_node;
^
fsck.ubifs/check_files.c:64:27: note: Variable created here.
struct scanned_ino_node ino_node;
^
fsck.ubifs/check_files.c:106:40: note: Using pointer to local variable 'ino_node' that is out of scope.
return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
^
fsck.ubifs/check_files.c:106:40: error: Using pointer to local variable 'dent_node' that is out of scope. [invalidLifetime]
return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
^
fsck.ubifs/check_files.c:84:31: note: Address of variable taken here.
sn = (struct scanned_node *)&dent_node;
^
fsck.ubifs/check_files.c:77:28: note: Variable created here.
struct scanned_dent_node dent_node;
^
fsck.ubifs/check_files.c:106:40: note: Using pointer to local variable 'dent_node' that is out of scope.
return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
^
fsck.ubifs/check_files.c:106:40: error: Using pointer to local variable 'data_node' that is out of scope. [invalidLifetime]
return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
^
fsck.ubifs/check_files.c:96:31: note: Address of variable taken here.
sn = (struct scanned_node *)&data_node;
^
fsck.ubifs/check_files.c:89:28: note: Variable created here.
struct scanned_data_node data_node;
^
fsck.ubifs/check_files.c:106:40: note: Using pointer to local variable 'data_node' that is out of scope.
return insert_or_update_file(c, tree, sn, key_type(c, key), inum);
^
Yuta Hayama (2):
fsck.ubifs: don't use pointers that reference out-of-scope variables
fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t
ubifs-utils/fsck.ubifs/check_files.c | 20 +--
ubifs-utils/fsck.ubifs/extract_files.c | 179 ++++++++++---------
ubifs-utils/fsck.ubifs/handle_disconnected.c | 10 +-
ubifs-utils/fsck.ubifs/problem.c | 36 ++--
ubifs-utils/fsck.ubifs/rebuild_fs.c | 8 +-
ubifs-utils/libubifs/dir.c | 8 +-
6 files changed, 130 insertions(+), 131 deletions(-)
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables 2025-11-13 8:29 [PATCH mtd-utils 0/2] mtd-utils: fsck.ubifs: fixes several undefined behaviors Yuta Hayama @ 2025-11-13 8:31 ` Yuta Hayama 2025-11-14 3:15 ` Zhihao Cheng 2025-11-13 8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama 1 sibling, 1 reply; 7+ messages in thread From: Yuta Hayama @ 2025-11-13 8:31 UTC (permalink / raw) To: linux-mtd; +Cc: Yuta Hayama sn is a reference to either an ino_node, dent_node, or data_node. When sn is actually used in calls to dbg_fsck() or insert_or_update_file(), these variables must not be out of scope. Signed-off-by: Yuta Hayama <hayama@lineo.co.jp> --- ubifs-utils/fsck.ubifs/check_files.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ubifs-utils/fsck.ubifs/check_files.c b/ubifs-utils/fsck.ubifs/check_files.c index 1e1a77b..54300a3 100644 --- a/ubifs-utils/fsck.ubifs/check_files.c +++ b/ubifs-utils/fsck.ubifs/check_files.c @@ -57,12 +57,13 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, struct rb_root *tree = &FSCK(c)->scanned_files; struct scanned_node *sn = NULL; struct ubifs_ch *ch = (struct ubifs_ch *)node; + struct scanned_ino_node ino_node; + struct scanned_dent_node dent_node; + struct scanned_data_node data_node; switch (ch->node_type) { case UBIFS_INO_NODE: { - struct scanned_ino_node ino_node; - if (!parse_ino_node(c, lnum, offs, node, key, &ino_node)) { if (fix_problem(c, INVALID_INO_NODE, NULL)) return add_invalid_node(c, key, lnum, offs, iter); @@ -74,8 +75,6 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, case UBIFS_DENT_NODE: case UBIFS_XENT_NODE: { - struct scanned_dent_node dent_node; - if (!parse_dent_node(c, lnum, offs, node, key, &dent_node)) { if (fix_problem(c, INVALID_DENT_NODE, NULL)) return add_invalid_node(c, key, lnum, offs, iter); @@ -86,8 +85,6 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, } case UBIFS_DATA_NODE: { - struct scanned_data_node data_node; - if (!parse_data_node(c, lnum, offs, node, key, &data_node)) { if (fix_problem(c, INVALID_DATA_NODE, NULL)) return add_invalid_node(c, key, lnum, offs, iter); -- 2.43.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables 2025-11-13 8:31 ` [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables Yuta Hayama @ 2025-11-14 3:15 ` Zhihao Cheng 0 siblings, 0 replies; 7+ messages in thread From: Zhihao Cheng @ 2025-11-14 3:15 UTC (permalink / raw) To: Yuta Hayama, linux-mtd 在 2025/11/13 16:31, Yuta Hayama 写道: > sn is a reference to either an ino_node, dent_node, or data_node. When sn > is actually used in calls to dbg_fsck() or insert_or_update_file(), these > variables must not be out of scope. > > Signed-off-by: Yuta Hayama <hayama@lineo.co.jp> > --- > ubifs-utils/fsck.ubifs/check_files.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > Thanks for fixing it. Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> > diff --git a/ubifs-utils/fsck.ubifs/check_files.c b/ubifs-utils/fsck.ubifs/check_files.c > index 1e1a77b..54300a3 100644 > --- a/ubifs-utils/fsck.ubifs/check_files.c > +++ b/ubifs-utils/fsck.ubifs/check_files.c > @@ -57,12 +57,13 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, > struct rb_root *tree = &FSCK(c)->scanned_files; > struct scanned_node *sn = NULL; > struct ubifs_ch *ch = (struct ubifs_ch *)node; > + struct scanned_ino_node ino_node; > + struct scanned_dent_node dent_node; > + struct scanned_data_node data_node; > > switch (ch->node_type) { > case UBIFS_INO_NODE: > { > - struct scanned_ino_node ino_node; > - > if (!parse_ino_node(c, lnum, offs, node, key, &ino_node)) { > if (fix_problem(c, INVALID_INO_NODE, NULL)) > return add_invalid_node(c, key, lnum, offs, iter); > @@ -74,8 +75,6 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, > case UBIFS_DENT_NODE: > case UBIFS_XENT_NODE: > { > - struct scanned_dent_node dent_node; > - > if (!parse_dent_node(c, lnum, offs, node, key, &dent_node)) { > if (fix_problem(c, INVALID_DENT_NODE, NULL)) > return add_invalid_node(c, key, lnum, offs, iter); > @@ -86,8 +85,6 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, > } > case UBIFS_DATA_NODE: > { > - struct scanned_data_node data_node; > - > if (!parse_data_node(c, lnum, offs, node, key, &data_node)) { > if (fix_problem(c, INVALID_DATA_NODE, NULL)) > return add_invalid_node(c, key, lnum, offs, iter); > ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t 2025-11-13 8:29 [PATCH mtd-utils 0/2] mtd-utils: fsck.ubifs: fixes several undefined behaviors Yuta Hayama 2025-11-13 8:31 ` [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables Yuta Hayama @ 2025-11-13 8:32 ` Yuta Hayama 2025-11-14 8:54 ` Zhihao Cheng 2026-02-13 13:55 ` [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting Tomas Alvarez Vanoli 1 sibling, 2 replies; 7+ messages in thread From: Yuta Hayama @ 2025-11-13 8:32 UTC (permalink / raw) To: linux-mtd; +Cc: Yuta Hayama On architectures such as armv7-a, ino_t is unsigned long long rather than unsigned long. In such cases, the printf format specifier "%lu" is not appropriate and causes an incorrect address offset. mtd-utils/ubifs-utils/fsck.ubifs/problem.c:224 log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", problem->desc, ifp->file->inum, c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, ubifs_get_type_name(dent_node->type), key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); fsck.ubifs[484] (/dev/ubi0_0,danger mode): problem: Dentry is unreachable, ino 917, unreachable dentry (null), type checksum_typefile Furthermore, running fsck.ubifs with the --debug=4 option will almost certainly cause a SEGV at the following point. mtd-utils/ubifs-utils/fsck.ubifs/check_files.c:103 dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, c->dev_name); To ensure functionality regardless of environment, cast ino_t to unsigned long long and output using "%lld". Apply the same fix for loff_t. Signed-off-by: Yuta Hayama <hayama@lineo.co.jp> --- ubifs-utils/fsck.ubifs/check_files.c | 11 +- ubifs-utils/fsck.ubifs/extract_files.c | 179 ++++++++++--------- ubifs-utils/fsck.ubifs/handle_disconnected.c | 10 +- ubifs-utils/fsck.ubifs/problem.c | 36 ++-- ubifs-utils/fsck.ubifs/rebuild_fs.c | 8 +- ubifs-utils/libubifs/dir.c | 8 +- 6 files changed, 127 insertions(+), 125 deletions(-) diff --git a/ubifs-utils/fsck.ubifs/check_files.c b/ubifs-utils/fsck.ubifs/check_files.c index 54300a3..53f3860 100644 --- a/ubifs-utils/fsck.ubifs/check_files.c +++ b/ubifs-utils/fsck.ubifs/check_files.c @@ -97,9 +97,9 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, ubifs_assert(c, 0); } - dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", - inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, - c->dev_name); + dbg_fsck("construct file(%llu) for %s node, TNC location %d:%d, in %s", + (unsigned long long)inum, ubifs_get_key_name(key_type(c, key)), + sn->lnum, sn->offs, c->dev_name); return insert_or_update_file(c, tree, sn, key_type(c, key), inum); } @@ -340,8 +340,9 @@ void update_files_size(struct ubifs_info *c) file = lookup_file(&FSCK(c)->scanned_files, e->inum); if (file && file->ino.header.exist && file->ino.size < e->d_size) { - dbg_fsck("update file(%lu) size %llu->%llu, in %s", - e->inum, file->ino.size, + dbg_fsck("update file(%llu) size %llu->%llu, in %s", + (unsigned long long)e->inum, + file->ino.size, (unsigned long long)e->d_size, c->dev_name); file->ino.size = e->d_size; diff --git a/ubifs-utils/fsck.ubifs/extract_files.c b/ubifs-utils/fsck.ubifs/extract_files.c index 000ef5d..2bbcc86 100644 --- a/ubifs-utils/fsck.ubifs/extract_files.c +++ b/ubifs-utils/fsck.ubifs/extract_files.c @@ -77,22 +77,22 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!inum || inum > INUM_WATERMARK) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node(bad inum %lu) at %d:%d, in %s", - inum, lnum, offs, c->dev_name); + dbg_fsck("bad inode node(bad inum %llu) at %d:%d, in %s", + (unsigned long long)inum, lnum, offs, c->dev_name); else - log_out(c, "bad inode node(bad inum %lu) at %d:%d", - inum, lnum, offs); + log_out(c, "bad inode node(bad inum %llu) at %d:%d", + (unsigned long long)inum, lnum, offs); goto out; } if (ch->node_type != key_type(c, key)) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(inconsistent node type %d vs key_type %d) at %d:%d, in %s", - inum, ch->node_type, key_type(c, key), + dbg_fsck("bad inode node %llu(inconsistent node type %d vs key_type %d) at %d:%d, in %s", + (unsigned long long)inum, ch->node_type, key_type(c, key), lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(inconsistent node type %d vs key_type %d) at %d:%d", - inum, ch->node_type, key_type(c, key), + log_out(c, "bad inode node %llu(inconsistent node type %d vs key_type %d) at %d:%d", + (unsigned long long)inum, ch->node_type, key_type(c, key), lnum, offs); goto out; } @@ -113,99 +113,99 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (inum == UBIFS_ROOT_INO && !S_ISDIR(ino_node->mode)) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(root inode is not dir, tyoe %u) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, lnum, offs, + dbg_fsck("bad inode node %llu(root inode is not dir, tyoe %u) at %d:%d, in %s", + (unsigned long long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(root inode is not dir, tyoe %u) at %d:%d", - inum, ino_node->mode & S_IFMT, lnum, offs); + log_out(c, "bad inode node %llu(root inode is not dir, tyoe %u) at %d:%d", + (unsigned long long)inum, ino_node->mode & S_IFMT, lnum, offs); goto out; } if (ino_node->size > c->max_inode_sz) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(size %llu is too large) at %d:%d, in %s", - inum, ino_node->size, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(size %llu is too large) at %d:%d, in %s", + (unsigned long long)inum, ino_node->size, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(size %llu is too large) at %d:%d", - inum, ino_node->size, lnum, offs); + log_out(c, "bad inode node %llu(size %llu is too large) at %d:%d", + (unsigned long long)inum, ino_node->size, lnum, offs); goto out; } if (le16_to_cpu(ino->compr_type) >= UBIFS_COMPR_TYPES_CNT) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(unknown compression type %d) at %d:%d, in %s", - inum, le16_to_cpu(ino->compr_type), lnum, offs, + dbg_fsck("bad inode node %llu(unknown compression type %d) at %d:%d, in %s", + (unsigned long long)inum, le16_to_cpu(ino->compr_type), lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(unknown compression type %d) at %d:%d", - inum, le16_to_cpu(ino->compr_type), lnum, offs); + log_out(c, "bad inode node %llu(unknown compression type %d) at %d:%d", + (unsigned long long)inum, le16_to_cpu(ino->compr_type), lnum, offs); goto out; } if (ino_node->xnms + ino_node->xcnt > XATTR_LIST_MAX) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(too big xnames %u xcount %u) at %d:%d, in %s", - inum, ino_node->xnms, ino_node->xcnt, + dbg_fsck("bad inode node %llu(too big xnames %u xcount %u) at %d:%d, in %s", + (unsigned long long)inum, ino_node->xnms, ino_node->xcnt, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(too big xnames %u xcount %u) at %d:%d", - inum, ino_node->xnms, ino_node->xcnt, + log_out(c, "bad inode node %llu(too big xnames %u xcount %u) at %d:%d", + (unsigned long long)inum, ino_node->xnms, ino_node->xcnt, lnum, offs); goto out; } if (data_len < 0 || data_len > UBIFS_MAX_INO_DATA) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(invalid data len %d) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(invalid data len %d) at %d:%d, in %s", + (unsigned long long)inum, data_len, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(invalid data len %d) at %d:%d", - inum, data_len, lnum, offs); + log_out(c, "bad inode node %llu(invalid data len %d) at %d:%d", + (unsigned long long)inum, data_len, lnum, offs); goto out; } if (UBIFS_INO_NODE_SZ + data_len != node_len) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(inconsistent data len %d vs node len %d) at %d:%d, in %s", - inum, data_len, node_len, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(inconsistent data len %d vs node len %d) at %d:%d, in %s", + (unsigned long long)inum, data_len, node_len, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(inconsistent data len %d vs node len %d) at %d:%d", - inum, data_len, node_len, lnum, offs); + log_out(c, "bad inode node %llu(inconsistent data len %d vs node len %d) at %d:%d", + (unsigned long long)inum, data_len, node_len, lnum, offs); goto out; } if (ino_node->is_xattr) { if (!S_ISREG(ino_node->mode)) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(bad type %u for xattr) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, + dbg_fsck("bad inode node %llu(bad type %u for xattr) at %d:%d, in %s", + (unsigned long long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(bad type %u for xattr) at %d:%d", - inum, ino_node->mode & S_IFMT, + log_out(c, "bad inode node %llu(bad type %u for xattr) at %d:%d", + (unsigned long long)inum, ino_node->mode & S_IFMT, lnum, offs); goto out; } if (data_len != ino_node->size) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(inconsistent data_len %d vs size %llu for xattr) at %d:%d, in %s", - inum, data_len, ino_node->size, + dbg_fsck("bad inode node %llu(inconsistent data_len %d vs size %llu for xattr) at %d:%d, in %s", + (unsigned long long)inum, data_len, ino_node->size, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(inconsistent data_len %d vs size %llu for xattr) at %d:%d", - inum, data_len, ino_node->size, + log_out(c, "bad inode node %llu(inconsistent data_len %d vs size %llu for xattr) at %d:%d", + (unsigned long long)inum, data_len, ino_node->size, lnum, offs); goto out; } if (ino_node->xcnt || ino_node->xsz || ino_node->xnms) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d, in %s", - inum, ino_node->xcnt, ino_node->xsz, + dbg_fsck("bad inode node %llu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d, in %s", + (unsigned long long)inum, ino_node->xcnt, ino_node->xsz, ino_node->xnms, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d", - inum, ino_node->xcnt, ino_node->xsz, + log_out(c, "bad inode node %llu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d", + (unsigned long long)inum, ino_node->xcnt, ino_node->xsz, ino_node->xnms, lnum, offs); goto out; } @@ -215,22 +215,22 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, case S_IFREG: if (!ino_node->is_xattr && data_len != 0) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(bad data len %d for reg file) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(bad data len %d for reg file) at %d:%d, in %s", + (unsigned long long)inum, data_len, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(bad data len %d for reg file) at %d:%d", - inum, data_len, lnum, offs); + log_out(c, "bad inode node %llu(bad data len %d for reg file) at %d:%d", + (unsigned long long)inum, data_len, lnum, offs); goto out; } break; case S_IFDIR: if (data_len != 0) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(bad data len %d for dir file) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(bad data len %d for dir file) at %d:%d, in %s", + (unsigned long long)inum, data_len, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(bad data len %d for dir file) at %d:%d", - inum, data_len, lnum, offs); + log_out(c, "bad inode node %llu(bad data len %d for dir file) at %d:%d", + (unsigned long long)inum, data_len, lnum, offs); goto out; } break; @@ -248,11 +248,11 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, * exceptions are found. */ if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad symlink inode node %lu(bad data len %d) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + dbg_fsck("bad symlink inode node %llu(bad data len %d) at %d:%d, in %s", + (unsigned long long)inum, data_len, lnum, offs, c->dev_name); else - log_out(c, "bad symlink inode node %lu(bad data len %d) at %d:%d", - inum, data_len, lnum, offs); + log_out(c, "bad symlink inode node %llu(bad data len %d) at %d:%d", + (unsigned long long)inum, data_len, lnum, offs); goto out; } break; @@ -265,12 +265,12 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (data_len != sz_new && data_len != sz_huge) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(bad data len %d for char/block file, expect %d or %d) at %d:%d, in %s", - inum, data_len, sz_new, sz_huge, lnum, + dbg_fsck("bad inode node %llu(bad data len %d for char/block file, expect %d or %d) at %d:%d, in %s", + (unsigned long long)inum, data_len, sz_new, sz_huge, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(bad data len %d for char/block file, expect %d or %d) at %d:%d", - inum, data_len, sz_new, sz_huge, lnum, + log_out(c, "bad inode node %llu(bad data len %d for char/block file, expect %d or %d) at %d:%d", + (unsigned long long)inum, data_len, sz_new, sz_huge, lnum, offs); goto out; } @@ -281,33 +281,33 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, case S_IFIFO: if (data_len != 0) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(bad data len %d for fifo/sock file) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(bad data len %d for fifo/sock file) at %d:%d, in %s", + (unsigned long long)inum, data_len, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(bad data len %d for fifo/sock file) at %d:%d", - inum, data_len, lnum, offs); + log_out(c, "bad inode node %llu(bad data len %d for fifo/sock file) at %d:%d", + (unsigned long long)inum, data_len, lnum, offs); goto out; } break; default: /* invalid file type. */ if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(unknown type %u) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); + dbg_fsck("bad inode node %llu(unknown type %u) at %d:%d, in %s", + (unsigned long long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(unknown type %u) at %d:%d", - inum, ino_node->mode & S_IFMT, lnum, offs); + log_out(c, "bad inode node %llu(unknown type %u) at %d:%d", + (unsigned long long)inum, ino_node->mode & S_IFMT, lnum, offs); goto out; } if (ino_node->is_encrypted && !inode_can_be_encrypted(c, ino_node)) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad inode node %lu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, ino_node->is_xattr, + dbg_fsck("bad inode node %llu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d, in %s", + (unsigned long long)inum, ino_node->mode & S_IFMT, ino_node->is_xattr, c->encrypted, lnum, offs, c->dev_name); else - log_out(c, "bad inode node %lu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d", - inum, ino_node->mode & S_IFMT, ino_node->is_xattr, + log_out(c, "bad inode node %llu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d", + (unsigned long long)inum, ino_node->mode & S_IFMT, ino_node->is_xattr, c->encrypted, lnum, offs); goto out; } @@ -355,14 +355,14 @@ bool parse_dent_node(struct ubifs_info *c, int lnum, int offs, void *node, strnlen((const char *)dent->name, nlen) != nlen) || inum > INUM_WATERMARK || key_type != ch->node_type) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad %s node(len %d nlen %d type %d inum %lu key_type %d node_type %d) at %d:%d, in %s", + dbg_fsck("bad %s node(len %d nlen %d type %d inum %llu key_type %d node_type %d) at %d:%d, in %s", ch->node_type == UBIFS_XENT_NODE ? "xattr entry" : "directory entry", - node_len, nlen, dent->type, inum, key_type, + node_len, nlen, dent->type, (unsigned long long)inum, key_type, ch->node_type, lnum, offs, c->dev_name); else - log_out(c, "bad %s node(len %d nlen %d type %d inum %lu key_type %d node_type %d) at %d:%d", + log_out(c, "bad %s node(len %d nlen %d type %d inum %llu key_type %d node_type %d) at %d:%d", ch->node_type == UBIFS_XENT_NODE ? "xattr entry" : "directory entry", - node_len, nlen, dent->type, inum, key_type, + node_len, nlen, dent->type, (unsigned long long)inum, key_type, ch->node_type, lnum, offs); goto out; } @@ -418,11 +418,11 @@ bool parse_data_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!inum || inum > INUM_WATERMARK) { if (FSCK(c)->mode == REBUILD_MODE) - dbg_fsck("bad data node(bad inum %lu) at %d:%d, in %s", - inum, lnum, offs, c->dev_name); + dbg_fsck("bad data node(bad inum %llu) at %d:%d, in %s", + (unsigned long long)inum, lnum, offs, c->dev_name); else - log_out(c, "bad data node(bad inum %lu) at %d:%d", - inum, lnum, offs); + log_out(c, "bad data node(bad inum %llu) at %d:%d", + (unsigned long long)inum, lnum, offs); goto out; } @@ -484,8 +484,8 @@ bool parse_trun_node(struct ubifs_info *c, int lnum, int offs, void *node, ino_t inum = le32_to_cpu(trun->inum); if (!inum || inum > INUM_WATERMARK) { - dbg_fsck("bad truncation node(bad inum %lu) at %d:%d, in %s", - inum, lnum, offs, c->dev_name); + dbg_fsck("bad truncation node(bad inum %llu) at %d:%d, in %s", + (unsigned long long)inum, lnum, offs, c->dev_name); goto out; } @@ -496,8 +496,9 @@ bool parse_trun_node(struct ubifs_info *c, int lnum, int offs, void *node, if (old_size < 0 || old_size > c->max_inode_sz || new_size < 0 || new_size > c->max_inode_sz || old_size <= new_size) { - dbg_fsck("bad truncation node(new size %ld old size %ld inum %lu) at %d:%d, in %s", - new_size, old_size, inum, lnum, offs, c->dev_name); + dbg_fsck("bad truncation node(new size %lld old size %lld inum %llu) at %d:%d, in %s", + (long long)new_size, (long long)old_size, + (unsigned long long)inum, lnum, offs, c->dev_name); goto out; } @@ -1007,7 +1008,7 @@ int file_is_valid(struct ubifs_info *c, struct scanned_file *file, struct scanned_data_node *data_node; LIST_HEAD(drop_list); - dbg_fsck("check validation of file %lu, in %s", file->inum, c->dev_name); + dbg_fsck("check validation of file %llu, in %s", (unsigned long long)file->inum, c->dev_name); if (!file->ino.header.exist) { handle_invalid_file(c, FILE_HAS_NO_INODE, file, NULL); @@ -1275,12 +1276,12 @@ retry: handle_invalid_file(c, FILE_IS_DISCONNECTED, file, NULL); else handle_invalid_file(c, FILE_HAS_NO_DENT, file, NULL); - dbg_fsck("file %lu is unreachable, in %s", file->inum, c->dev_name); + dbg_fsck("file %llu is unreachable, in %s", (unsigned long long)file->inum, c->dev_name); return false; } reachable: - dbg_fsck("file %lu is reachable, in %s", file->inum, c->dev_name); + dbg_fsck("file %llu is reachable, in %s", (unsigned long long)file->inum, c->dev_name); return true; } @@ -1497,8 +1498,8 @@ static int correct_file_info(struct ubifs_info *c, struct scanned_file *file) handle_invalid_file(c, FILE_IS_INCONSISTENT, file, NULL); lnum = file->ino.header.lnum; - dbg_fsck("correct file(inum:%lu type:%s), nlink %u->%u, xattr cnt %u->%u, xattr size %u->%u, xattr names %u->%u, size %llu->%llu, at %d:%d, in %s", - file->inum, file->ino.is_xattr ? "xattr" : + dbg_fsck("correct file(inum:%llu type:%s), nlink %u->%u, xattr cnt %u->%u, xattr size %u->%u, xattr names %u->%u, size %llu->%llu, at %d:%d, in %s", + (unsigned long long)file->inum, file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), file->ino.nlink, file->calc_nlink, file->ino.xcnt, file->calc_xcnt, diff --git a/ubifs-utils/fsck.ubifs/handle_disconnected.c b/ubifs-utils/fsck.ubifs/handle_disconnected.c index be62522..15fd14e 100644 --- a/ubifs-utils/fsck.ubifs/handle_disconnected.c +++ b/ubifs-utils/fsck.ubifs/handle_disconnected.c @@ -117,7 +117,7 @@ static int handle_disonnected_file(struct ubifs_info *c, struct ubifs_inode *target_ui; err = snprintf(file_name, sizeof(file_name), - "INO_%lu_%u", file->inum, index); + "INO_%llu_%u", (unsigned long long)file->inum, index); if (err < 0) goto free_ui; fname_name(&nm) = file_name; @@ -137,8 +137,8 @@ static int handle_disonnected_file(struct ubifs_info *c, err = 0; kfree(ui); kfree(lost_found_ui); - log_out(c, "Too many duplicated names(%u) in lost+found for inum %lu", - index, file->inum); + log_out(c, "Too many duplicated names(%u) in lost+found for inum %llu", + index, (unsigned long long)file->inum); goto delete_file; } @@ -149,8 +149,8 @@ static int handle_disonnected_file(struct ubifs_info *c, log_out(c, "No free space to recover disconnected file"); goto delete_file; } - dbg_fsck("recover disconnected file %lu, in %s", - file->inum, c->dev_name); + dbg_fsck("recover disconnected file %llu, in %s", + (unsigned long long)file->inum, c->dev_name); free_ui: kfree(ui); diff --git a/ubifs-utils/fsck.ubifs/problem.c b/ubifs-utils/fsck.ubifs/problem.c index 916c976..bb2fa72 100644 --- a/ubifs-utils/fsck.ubifs/problem.c +++ b/ubifs-utils/fsck.ubifs/problem.c @@ -147,7 +147,7 @@ static void print_problem(const struct ubifs_info *c, { const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; - log_out(c, "problem: %s, ino %lu", problem->desc, ifp->file->inum); + log_out(c, "problem: %s, ino %llu", problem->desc, (unsigned long long)ifp->file->inum); break; } case FILE_HAS_INCONSIST_TYPE: @@ -155,8 +155,8 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; - log_out(c, "problem: %s, ino %lu, inode type %s%s, dentry %s has type %s%s", - problem->desc, ifp->file->inum, + log_out(c, "problem: %s, ino %llu, inode type %s%s, dentry %s has type %s%s", + problem->desc, (unsigned long long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : "", c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, @@ -170,8 +170,8 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; - log_out(c, "problem: %s, ino %lu, type %s%s, dentry %s", - problem->desc, ifp->file->inum, + log_out(c, "problem: %s, ino %llu, type %s%s, dentry %s", + problem->desc, (unsigned long long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : "", c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name); @@ -182,8 +182,8 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; const struct scanned_data_node *data_node = (const struct scanned_data_node *)ifp->priv; - log_out(c, "problem: %s, ino %lu, type %s%s, data block %u", - problem->desc, ifp->file->inum, + log_out(c, "problem: %s, ino %llu, type %s%s, data block %u", + problem->desc, (unsigned long long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : "", key_block(c, &data_node->key)); @@ -197,8 +197,8 @@ static void print_problem(const struct ubifs_info *c, { const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; - log_out(c, "problem: %s, ino %lu type %s%s", problem->desc, - ifp->file->inum, + log_out(c, "problem: %s, ino %llu type %s%s", problem->desc, + (unsigned long long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : ""); break; @@ -208,10 +208,10 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; const struct scanned_file *host = (const struct scanned_file *)ifp->priv; - log_out(c, "problem: %s, ino %lu type %s%s, host ino %lu type %s%s", - problem->desc, ifp->file->inum, + log_out(c, "problem: %s, ino %llu type %s%s, host ino %llu type %s%s", + problem->desc, (unsigned long long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), - ifp->file->ino.is_xattr ? "(xattr)" : "", host->inum, + ifp->file->ino.is_xattr ? "(xattr)" : "", (unsigned long long)host->inum, ubifs_get_type_name(ubifs_get_dent_type(host->ino.mode)), host->ino.is_xattr ? "(xattr)" : ""); break; @@ -221,8 +221,8 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; - log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", - problem->desc, ifp->file->inum, + log_out(c, "problem: %s, ino %llu, unreachable dentry %s, type %s%s", + problem->desc, (unsigned long long)ifp->file->inum, c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, ubifs_get_type_name(dent_node->type), key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); @@ -233,9 +233,9 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; const struct scanned_file *file = ifp->file; - log_out(c, "problem: %s, ino %lu type %s, nlink %u xcnt %u xsz %u xnms %u size %llu, " + log_out(c, "problem: %s, ino %llu type %s, nlink %u xcnt %u xsz %u xnms %u size %llu, " "should be nlink %u xcnt %u xsz %u xnms %u size %llu", - problem->desc, file->inum, + problem->desc, (unsigned long long)file->inum, file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), file->ino.nlink, file->ino.xcnt, file->ino.xsz, file->ino.xnms, file->ino.size, @@ -298,8 +298,8 @@ static void print_problem(const struct ubifs_info *c, { const struct scanned_file *file = (const struct scanned_file *)priv; - log_out(c, "problem: %s, ino %lu, size %llu", problem->desc, - file->inum, file->ino.size); + log_out(c, "problem: %s, ino %llu, size %llu", problem->desc, + (unsigned long long)file->inum, file->ino.size); break; } default: diff --git a/ubifs-utils/fsck.ubifs/rebuild_fs.c b/ubifs-utils/fsck.ubifs/rebuild_fs.c index b82d728..076cbe5 100644 --- a/ubifs-utils/fsck.ubifs/rebuild_fs.c +++ b/ubifs-utils/fsck.ubifs/rebuild_fs.c @@ -696,8 +696,8 @@ static void extract_dentry_tree(struct ubifs_info *c) while (!list_empty(&unreachable)) { file = list_entry(unreachable.next, struct scanned_file, list); - dbg_fsck("remove unreachable file %lu, in %s", - file->inum, c->dev_name); + dbg_fsck("remove unreachable file %llu, in %s", + (unsigned long long)file->inum, c->dev_name); list_del(&file->list); destroy_file_content(c, file); rb_erase(&file->rb, tree); @@ -1096,8 +1096,8 @@ static int record_file_used_lebs(struct ubifs_info *c, struct scanned_dent_node *dent_node; struct scanned_data_node *data_node; - dbg_fsck("recovered file(inum:%lu name:%s type:%s), in %s", - file->inum, get_file_name(c, file), + dbg_fsck("recovered file(inum:%llu name:%s type:%s), in %s", + (unsigned long long)file->inum, get_file_name(c, file), file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), c->dev_name); diff --git a/ubifs-utils/libubifs/dir.c b/ubifs-utils/libubifs/dir.c index 89f77eb..50cb818 100644 --- a/ubifs-utils/libubifs/dir.c +++ b/ubifs-utils/libubifs/dir.c @@ -248,8 +248,8 @@ int ubifs_mkdir(struct ubifs_info *c, struct ubifs_inode *dir_ui, * Budget request settings: new inode, new direntry and changing parent * directory inode. */ - dbg_gen("dent '%s', mode %#hx in dir ino %lu", - fname_name(nm), mode, dir->inum); + dbg_gen("dent '%s', mode %#hx in dir ino %llu", + fname_name(nm), mode, (unsigned long long)dir->inum); /* New dir is not allowed to be created under an encrypted directory. */ ubifs_assert(c, !(dir_ui->flags & UBIFS_CRYPT_FL)); @@ -314,8 +314,8 @@ int ubifs_link_recovery(struct ubifs_info *c, struct ubifs_inode *dir_ui, * Budget request settings: new direntry, changing the target inode, * changing the parent inode. */ - dbg_gen("dent '%s' to ino %lu (nlink %d) in dir ino %lu", - fname_name(nm), inode->inum, inode->nlink, dir->inum); + dbg_gen("dent '%s' to ino %llu (nlink %d) in dir ino %llu", + fname_name(nm), (unsigned long long)inode->inum, inode->nlink, (unsigned long long)dir->inum); /* New dir is not allowed to be created under an encrypted directory. */ ubifs_assert(c, !(dir_ui->flags & UBIFS_CRYPT_FL)); -- 2.43.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t 2025-11-13 8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama @ 2025-11-14 8:54 ` Zhihao Cheng 2026-02-13 13:55 ` [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting Tomas Alvarez Vanoli 1 sibling, 0 replies; 7+ messages in thread From: Zhihao Cheng @ 2025-11-14 8:54 UTC (permalink / raw) To: linux-mtd 在 2025/11/13 16:32, Yuta Hayama 写道: > On architectures such as armv7-a, ino_t is unsigned long long rather than > unsigned long. In such cases, the printf format specifier "%lu" is not > appropriate and causes an incorrect address offset. > > mtd-utils/ubifs-utils/fsck.ubifs/problem.c:224 > log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", > problem->desc, ifp->file->inum, > c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, > ubifs_get_type_name(dent_node->type), > key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); > > fsck.ubifs[484] (/dev/ubi0_0,danger mode): problem: Dentry is unreachable, ino 917, unreachable dentry (null), type checksum_typefile The ubifs inode number won't exceed 4 bytes, and the bytewidth of 'ino_t' varies on different machines. How about changing debug message like '%lu, (unsigned long)inum'? > > Furthermore, running fsck.ubifs with the --debug=4 option will almost > certainly cause a SEGV at the following point. > > mtd-utils/ubifs-utils/fsck.ubifs/check_files.c:103 > dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", > inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, > c->dev_name); > > To ensure functionality regardless of environment, cast ino_t to unsigned > long long and output using "%lld". Apply the same fix for loff_t. > ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting 2025-11-13 8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama 2025-11-14 8:54 ` Zhihao Cheng @ 2026-02-13 13:55 ` Tomas Alvarez Vanoli 2026-02-14 1:33 ` Zhihao Cheng 1 sibling, 1 reply; 7+ messages in thread From: Tomas Alvarez Vanoli @ 2026-02-13 13:55 UTC (permalink / raw) To: linux-mtd; +Cc: chengzhihao1, Yuta Hayama, Tomas Alvarez Vanoli From: Yuta Hayama <hayama@lineo.co.jp> On architectures such as armv7-a, ino_t and loff_t are unsigned long long rather than unsigned long. In such cases, the printf format specifier "%lu" is not appropriate and causes an incorrect address offset. mtd-utils/ubifs-utils/fsck.ubifs/problem.c:224 log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", problem->desc, ifp->file->inum, c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, ubifs_get_type_name(dent_node->type), key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); fsck.ubifs[484] (/dev/ubi0_0,danger mode): problem: Dentry is unreachable, ino 917, unreachable dentry (null), type checksum_typefile Furthermore, running fsck.ubifs with the --debug=4 option will almost certainly cause a SEGV at the following point. mtd-utils/ubifs-utils/fsck.ubifs/check_files.c:103 dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, c->dev_name); To ensure functionality regardless of environment, cast ino_t to unsigned long, since it will never be more than 4 bytes. For loff_t, use %lld and cast accordingly. Signed-off-by: Yuta Hayama <hayama@lineo.co.jp> Signed-off-by: Tomas Alvarez Vanoli <tomas.alvarez-vanoli@hitachienergy.com> --- ubifs-utils/fsck.ubifs/check_files.c | 7 +- ubifs-utils/fsck.ubifs/extract_files.c | 95 ++++++++++---------- ubifs-utils/fsck.ubifs/handle_disconnected.c | 6 +- ubifs-utils/fsck.ubifs/problem.c | 20 ++--- ubifs-utils/fsck.ubifs/rebuild_fs.c | 4 +- ubifs-utils/libubifs/dir.c | 4 +- 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/ubifs-utils/fsck.ubifs/check_files.c b/ubifs-utils/fsck.ubifs/check_files.c index 1e1a77b..4e5ff58 100644 --- a/ubifs-utils/fsck.ubifs/check_files.c +++ b/ubifs-utils/fsck.ubifs/check_files.c @@ -101,8 +101,8 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, } dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", - inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, - c->dev_name); + (unsigned long)inum, ubifs_get_key_name(key_type(c, key)), + sn->lnum, sn->offs, c->dev_name); return insert_or_update_file(c, tree, sn, key_type(c, key), inum); } @@ -344,7 +344,8 @@ void update_files_size(struct ubifs_info *c) if (file && file->ino.header.exist && file->ino.size < e->d_size) { dbg_fsck("update file(%lu) size %llu->%llu, in %s", - e->inum, file->ino.size, + (unsigned long)e->inum, + file->ino.size, (unsigned long long)e->d_size, c->dev_name); file->ino.size = e->d_size; diff --git a/ubifs-utils/fsck.ubifs/extract_files.c b/ubifs-utils/fsck.ubifs/extract_files.c index 000ef5d..2e47b42 100644 --- a/ubifs-utils/fsck.ubifs/extract_files.c +++ b/ubifs-utils/fsck.ubifs/extract_files.c @@ -78,21 +78,21 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!inum || inum > INUM_WATERMARK) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node(bad inum %lu) at %d:%d, in %s", - inum, lnum, offs, c->dev_name); + (unsigned long)inum, lnum, offs, c->dev_name); else log_out(c, "bad inode node(bad inum %lu) at %d:%d", - inum, lnum, offs); + (unsigned long)inum, lnum, offs); goto out; } if (ch->node_type != key_type(c, key)) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(inconsistent node type %d vs key_type %d) at %d:%d, in %s", - inum, ch->node_type, key_type(c, key), + (unsigned long)inum, ch->node_type, key_type(c, key), lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(inconsistent node type %d vs key_type %d) at %d:%d", - inum, ch->node_type, key_type(c, key), + (unsigned long)inum, ch->node_type, key_type(c, key), lnum, offs); goto out; } @@ -114,43 +114,43 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (inum == UBIFS_ROOT_INO && !S_ISDIR(ino_node->mode)) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(root inode is not dir, tyoe %u) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, lnum, offs, + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(root inode is not dir, tyoe %u) at %d:%d", - inum, ino_node->mode & S_IFMT, lnum, offs); + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs); goto out; } if (ino_node->size > c->max_inode_sz) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(size %llu is too large) at %d:%d, in %s", - inum, ino_node->size, lnum, offs, c->dev_name); + (unsigned long)inum, ino_node->size, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(size %llu is too large) at %d:%d", - inum, ino_node->size, lnum, offs); + (unsigned long)inum, ino_node->size, lnum, offs); goto out; } if (le16_to_cpu(ino->compr_type) >= UBIFS_COMPR_TYPES_CNT) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(unknown compression type %d) at %d:%d, in %s", - inum, le16_to_cpu(ino->compr_type), lnum, offs, + (unsigned long)inum, le16_to_cpu(ino->compr_type), lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(unknown compression type %d) at %d:%d", - inum, le16_to_cpu(ino->compr_type), lnum, offs); + (unsigned long)inum, le16_to_cpu(ino->compr_type), lnum, offs); goto out; } if (ino_node->xnms + ino_node->xcnt > XATTR_LIST_MAX) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(too big xnames %u xcount %u) at %d:%d, in %s", - inum, ino_node->xnms, ino_node->xcnt, + (unsigned long)inum, ino_node->xnms, ino_node->xcnt, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(too big xnames %u xcount %u) at %d:%d", - inum, ino_node->xnms, ino_node->xcnt, + (unsigned long)inum, ino_node->xnms, ino_node->xcnt, lnum, offs); goto out; } @@ -158,20 +158,20 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (data_len < 0 || data_len > UBIFS_MAX_INO_DATA) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(invalid data len %d) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + (unsigned long)inum, data_len, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(invalid data len %d) at %d:%d", - inum, data_len, lnum, offs); + (unsigned long)inum, data_len, lnum, offs); goto out; } if (UBIFS_INO_NODE_SZ + data_len != node_len) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(inconsistent data len %d vs node len %d) at %d:%d, in %s", - inum, data_len, node_len, lnum, offs, c->dev_name); + (unsigned long)inum, data_len, node_len, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(inconsistent data len %d vs node len %d) at %d:%d", - inum, data_len, node_len, lnum, offs); + (unsigned long)inum, data_len, node_len, lnum, offs); goto out; } @@ -179,33 +179,33 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!S_ISREG(ino_node->mode)) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(bad type %u for xattr) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(bad type %u for xattr) at %d:%d", - inum, ino_node->mode & S_IFMT, + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs); goto out; } if (data_len != ino_node->size) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(inconsistent data_len %d vs size %llu for xattr) at %d:%d, in %s", - inum, data_len, ino_node->size, + (unsigned long)inum, data_len, ino_node->size, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(inconsistent data_len %d vs size %llu for xattr) at %d:%d", - inum, data_len, ino_node->size, + (unsigned long)inum, data_len, ino_node->size, lnum, offs); goto out; } if (ino_node->xcnt || ino_node->xsz || ino_node->xnms) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d, in %s", - inum, ino_node->xcnt, ino_node->xsz, + (unsigned long)inum, ino_node->xcnt, ino_node->xsz, ino_node->xnms, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d", - inum, ino_node->xcnt, ino_node->xsz, + (unsigned long)inum, ino_node->xcnt, ino_node->xsz, ino_node->xnms, lnum, offs); goto out; } @@ -216,10 +216,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!ino_node->is_xattr && data_len != 0) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(bad data len %d for reg file) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + (unsigned long)inum, data_len, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(bad data len %d for reg file) at %d:%d", - inum, data_len, lnum, offs); + (unsigned long)inum, data_len, lnum, offs); goto out; } break; @@ -227,10 +227,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (data_len != 0) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(bad data len %d for dir file) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + (unsigned long)inum, data_len, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(bad data len %d for dir file) at %d:%d", - inum, data_len, lnum, offs); + (unsigned long)inum, data_len, lnum, offs); goto out; } break; @@ -249,10 +249,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, */ if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad symlink inode node %lu(bad data len %d) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + (unsigned long)inum, data_len, lnum, offs, c->dev_name); else log_out(c, "bad symlink inode node %lu(bad data len %d) at %d:%d", - inum, data_len, lnum, offs); + (unsigned long)inum, data_len, lnum, offs); goto out; } break; @@ -266,11 +266,11 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (data_len != sz_new && data_len != sz_huge) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(bad data len %d for char/block file, expect %d or %d) at %d:%d, in %s", - inum, data_len, sz_new, sz_huge, lnum, + (unsigned long)inum, data_len, sz_new, sz_huge, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(bad data len %d for char/block file, expect %d or %d) at %d:%d", - inum, data_len, sz_new, sz_huge, lnum, + (unsigned long)inum, data_len, sz_new, sz_huge, lnum, offs); goto out; } @@ -282,10 +282,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, if (data_len != 0) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(bad data len %d for fifo/sock file) at %d:%d, in %s", - inum, data_len, lnum, offs, c->dev_name); + (unsigned long)inum, data_len, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(bad data len %d for fifo/sock file) at %d:%d", - inum, data_len, lnum, offs); + (unsigned long)inum, data_len, lnum, offs); goto out; } break; @@ -293,21 +293,21 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, /* invalid file type. */ if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(unknown type %u) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(unknown type %u) at %d:%d", - inum, ino_node->mode & S_IFMT, lnum, offs); + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs); goto out; } if (ino_node->is_encrypted && !inode_can_be_encrypted(c, ino_node)) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad inode node %lu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d, in %s", - inum, ino_node->mode & S_IFMT, ino_node->is_xattr, + (unsigned long)inum, ino_node->mode & S_IFMT, ino_node->is_xattr, c->encrypted, lnum, offs, c->dev_name); else log_out(c, "bad inode node %lu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d", - inum, ino_node->mode & S_IFMT, ino_node->is_xattr, + (unsigned long)inum, ino_node->mode & S_IFMT, ino_node->is_xattr, c->encrypted, lnum, offs); goto out; } @@ -357,12 +357,12 @@ bool parse_dent_node(struct ubifs_info *c, int lnum, int offs, void *node, if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad %s node(len %d nlen %d type %d inum %lu key_type %d node_type %d) at %d:%d, in %s", ch->node_type == UBIFS_XENT_NODE ? "xattr entry" : "directory entry", - node_len, nlen, dent->type, inum, key_type, + node_len, nlen, dent->type, (unsigned long)inum, key_type, ch->node_type, lnum, offs, c->dev_name); else log_out(c, "bad %s node(len %d nlen %d type %d inum %lu key_type %d node_type %d) at %d:%d", ch->node_type == UBIFS_XENT_NODE ? "xattr entry" : "directory entry", - node_len, nlen, dent->type, inum, key_type, + node_len, nlen, dent->type, (unsigned long)inum, key_type, ch->node_type, lnum, offs); goto out; } @@ -419,10 +419,10 @@ bool parse_data_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!inum || inum > INUM_WATERMARK) { if (FSCK(c)->mode == REBUILD_MODE) dbg_fsck("bad data node(bad inum %lu) at %d:%d, in %s", - inum, lnum, offs, c->dev_name); + (unsigned long)inum, lnum, offs, c->dev_name); else log_out(c, "bad data node(bad inum %lu) at %d:%d", - inum, lnum, offs); + (unsigned long)inum, lnum, offs); goto out; } @@ -485,7 +485,7 @@ bool parse_trun_node(struct ubifs_info *c, int lnum, int offs, void *node, if (!inum || inum > INUM_WATERMARK) { dbg_fsck("bad truncation node(bad inum %lu) at %d:%d, in %s", - inum, lnum, offs, c->dev_name); + (unsigned long)inum, lnum, offs, c->dev_name); goto out; } @@ -496,8 +496,9 @@ bool parse_trun_node(struct ubifs_info *c, int lnum, int offs, void *node, if (old_size < 0 || old_size > c->max_inode_sz || new_size < 0 || new_size > c->max_inode_sz || old_size <= new_size) { - dbg_fsck("bad truncation node(new size %ld old size %ld inum %lu) at %d:%d, in %s", - new_size, old_size, inum, lnum, offs, c->dev_name); + dbg_fsck("bad truncation node(new size %lld old size %lld inum %lu) at %d:%d, in %s", + (long long)new_size, (long long)old_size, + (unsigned long)inum, lnum, offs, c->dev_name); goto out; } @@ -1007,7 +1008,7 @@ int file_is_valid(struct ubifs_info *c, struct scanned_file *file, struct scanned_data_node *data_node; LIST_HEAD(drop_list); - dbg_fsck("check validation of file %lu, in %s", file->inum, c->dev_name); + dbg_fsck("check validation of file %lu, in %s", (unsigned long)file->inum, c->dev_name); if (!file->ino.header.exist) { handle_invalid_file(c, FILE_HAS_NO_INODE, file, NULL); @@ -1275,12 +1276,12 @@ retry: handle_invalid_file(c, FILE_IS_DISCONNECTED, file, NULL); else handle_invalid_file(c, FILE_HAS_NO_DENT, file, NULL); - dbg_fsck("file %lu is unreachable, in %s", file->inum, c->dev_name); + dbg_fsck("file %lu is unreachable, in %s", (unsigned long)file->inum, c->dev_name); return false; } reachable: - dbg_fsck("file %lu is reachable, in %s", file->inum, c->dev_name); + dbg_fsck("file %lu is reachable, in %s", (unsigned long)file->inum, c->dev_name); return true; } @@ -1498,7 +1499,7 @@ static int correct_file_info(struct ubifs_info *c, struct scanned_file *file) handle_invalid_file(c, FILE_IS_INCONSISTENT, file, NULL); lnum = file->ino.header.lnum; dbg_fsck("correct file(inum:%lu type:%s), nlink %u->%u, xattr cnt %u->%u, xattr size %u->%u, xattr names %u->%u, size %llu->%llu, at %d:%d, in %s", - file->inum, file->ino.is_xattr ? "xattr" : + (unsigned long)file->inum, file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), file->ino.nlink, file->calc_nlink, file->ino.xcnt, file->calc_xcnt, diff --git a/ubifs-utils/fsck.ubifs/handle_disconnected.c b/ubifs-utils/fsck.ubifs/handle_disconnected.c index be62522..9e5d925 100644 --- a/ubifs-utils/fsck.ubifs/handle_disconnected.c +++ b/ubifs-utils/fsck.ubifs/handle_disconnected.c @@ -117,7 +117,7 @@ static int handle_disonnected_file(struct ubifs_info *c, struct ubifs_inode *target_ui; err = snprintf(file_name, sizeof(file_name), - "INO_%lu_%u", file->inum, index); + "INO_%lu_%u", (unsigned long)file->inum, index); if (err < 0) goto free_ui; fname_name(&nm) = file_name; @@ -138,7 +138,7 @@ static int handle_disonnected_file(struct ubifs_info *c, kfree(ui); kfree(lost_found_ui); log_out(c, "Too many duplicated names(%u) in lost+found for inum %lu", - index, file->inum); + index, (unsigned long)file->inum); goto delete_file; } @@ -150,7 +150,7 @@ static int handle_disonnected_file(struct ubifs_info *c, goto delete_file; } dbg_fsck("recover disconnected file %lu, in %s", - file->inum, c->dev_name); + (unsigned long)file->inum, c->dev_name); free_ui: kfree(ui); diff --git a/ubifs-utils/fsck.ubifs/problem.c b/ubifs-utils/fsck.ubifs/problem.c index 916c976..edb5f57 100644 --- a/ubifs-utils/fsck.ubifs/problem.c +++ b/ubifs-utils/fsck.ubifs/problem.c @@ -147,7 +147,7 @@ static void print_problem(const struct ubifs_info *c, { const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; - log_out(c, "problem: %s, ino %lu", problem->desc, ifp->file->inum); + log_out(c, "problem: %s, ino %lu", problem->desc, (unsigned long)ifp->file->inum); break; } case FILE_HAS_INCONSIST_TYPE: @@ -156,7 +156,7 @@ static void print_problem(const struct ubifs_info *c, const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; log_out(c, "problem: %s, ino %lu, inode type %s%s, dentry %s has type %s%s", - problem->desc, ifp->file->inum, + problem->desc, (unsigned long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : "", c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, @@ -171,7 +171,7 @@ static void print_problem(const struct ubifs_info *c, const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; log_out(c, "problem: %s, ino %lu, type %s%s, dentry %s", - problem->desc, ifp->file->inum, + problem->desc, (unsigned long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : "", c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name); @@ -183,7 +183,7 @@ static void print_problem(const struct ubifs_info *c, const struct scanned_data_node *data_node = (const struct scanned_data_node *)ifp->priv; log_out(c, "problem: %s, ino %lu, type %s%s, data block %u", - problem->desc, ifp->file->inum, + problem->desc, (unsigned long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : "", key_block(c, &data_node->key)); @@ -198,7 +198,7 @@ static void print_problem(const struct ubifs_info *c, const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; log_out(c, "problem: %s, ino %lu type %s%s", problem->desc, - ifp->file->inum, + (unsigned long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), ifp->file->ino.is_xattr ? "(xattr)" : ""); break; @@ -209,9 +209,9 @@ static void print_problem(const struct ubifs_info *c, const struct scanned_file *host = (const struct scanned_file *)ifp->priv; log_out(c, "problem: %s, ino %lu type %s%s, host ino %lu type %s%s", - problem->desc, ifp->file->inum, + problem->desc, (unsigned long)ifp->file->inum, ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), - ifp->file->ino.is_xattr ? "(xattr)" : "", host->inum, + ifp->file->ino.is_xattr ? "(xattr)" : "", (unsigned long)host->inum, ubifs_get_type_name(ubifs_get_dent_type(host->ino.mode)), host->ino.is_xattr ? "(xattr)" : ""); break; @@ -222,7 +222,7 @@ static void print_problem(const struct ubifs_info *c, const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", - problem->desc, ifp->file->inum, + problem->desc, (unsigned long)ifp->file->inum, c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, ubifs_get_type_name(dent_node->type), key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); @@ -235,7 +235,7 @@ static void print_problem(const struct ubifs_info *c, log_out(c, "problem: %s, ino %lu type %s, nlink %u xcnt %u xsz %u xnms %u size %llu, " "should be nlink %u xcnt %u xsz %u xnms %u size %llu", - problem->desc, file->inum, + problem->desc, (unsigned long)file->inum, file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), file->ino.nlink, file->ino.xcnt, file->ino.xsz, file->ino.xnms, file->ino.size, @@ -299,7 +299,7 @@ static void print_problem(const struct ubifs_info *c, const struct scanned_file *file = (const struct scanned_file *)priv; log_out(c, "problem: %s, ino %lu, size %llu", problem->desc, - file->inum, file->ino.size); + (unsigned long)file->inum, file->ino.size); break; } default: diff --git a/ubifs-utils/fsck.ubifs/rebuild_fs.c b/ubifs-utils/fsck.ubifs/rebuild_fs.c index b82d728..b399b3e 100644 --- a/ubifs-utils/fsck.ubifs/rebuild_fs.c +++ b/ubifs-utils/fsck.ubifs/rebuild_fs.c @@ -697,7 +697,7 @@ static void extract_dentry_tree(struct ubifs_info *c) file = list_entry(unreachable.next, struct scanned_file, list); dbg_fsck("remove unreachable file %lu, in %s", - file->inum, c->dev_name); + (unsigned long)file->inum, c->dev_name); list_del(&file->list); destroy_file_content(c, file); rb_erase(&file->rb, tree); @@ -1097,7 +1097,7 @@ static int record_file_used_lebs(struct ubifs_info *c, struct scanned_data_node *data_node; dbg_fsck("recovered file(inum:%lu name:%s type:%s), in %s", - file->inum, get_file_name(c, file), + (unsigned long)file->inum, get_file_name(c, file), file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), c->dev_name); diff --git a/ubifs-utils/libubifs/dir.c b/ubifs-utils/libubifs/dir.c index 89f77eb..2eb4e75 100644 --- a/ubifs-utils/libubifs/dir.c +++ b/ubifs-utils/libubifs/dir.c @@ -249,7 +249,7 @@ int ubifs_mkdir(struct ubifs_info *c, struct ubifs_inode *dir_ui, * directory inode. */ dbg_gen("dent '%s', mode %#hx in dir ino %lu", - fname_name(nm), mode, dir->inum); + fname_name(nm), mode, (unsigned long)dir->inum); /* New dir is not allowed to be created under an encrypted directory. */ ubifs_assert(c, !(dir_ui->flags & UBIFS_CRYPT_FL)); @@ -315,7 +315,7 @@ int ubifs_link_recovery(struct ubifs_info *c, struct ubifs_inode *dir_ui, * changing the parent inode. */ dbg_gen("dent '%s' to ino %lu (nlink %d) in dir ino %lu", - fname_name(nm), inode->inum, inode->nlink, dir->inum); + fname_name(nm), (unsigned long)inode->inum, inode->nlink, (unsigned long)dir->inum); /* New dir is not allowed to be created under an encrypted directory. */ ubifs_assert(c, !(dir_ui->flags & UBIFS_CRYPT_FL)); -- 2.43.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting 2026-02-13 13:55 ` [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting Tomas Alvarez Vanoli @ 2026-02-14 1:33 ` Zhihao Cheng 0 siblings, 0 replies; 7+ messages in thread From: Zhihao Cheng @ 2026-02-14 1:33 UTC (permalink / raw) To: Tomas Alvarez Vanoli, linux-mtd; +Cc: Yuta Hayama 在 2026/2/13 21:55, Tomas Alvarez Vanoli 写道: > From: Yuta Hayama <hayama@lineo.co.jp> > > On architectures such as armv7-a, ino_t and loff_t are unsigned long long rather than > unsigned long. In such cases, the printf format specifier "%lu" is not > appropriate and causes an incorrect address offset. > > mtd-utils/ubifs-utils/fsck.ubifs/problem.c:224 > log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", > problem->desc, ifp->file->inum, > c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, > ubifs_get_type_name(dent_node->type), > key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); > > fsck.ubifs[484] (/dev/ubi0_0,danger mode): problem: Dentry is unreachable, ino 917, unreachable dentry (null), type checksum_typefile > > Furthermore, running fsck.ubifs with the --debug=4 option will almost > certainly cause a SEGV at the following point. > > mtd-utils/ubifs-utils/fsck.ubifs/check_files.c:103 > dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", > inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, > c->dev_name); > > To ensure functionality regardless of environment, cast ino_t to unsigned > long, since it will never be more than 4 bytes. > > For loff_t, use %lld and cast accordingly. > > Signed-off-by: Yuta Hayama <hayama@lineo.co.jp> > Signed-off-by: Tomas Alvarez Vanoli <tomas.alvarez-vanoli@hitachienergy.com> > --- > ubifs-utils/fsck.ubifs/check_files.c | 7 +- > ubifs-utils/fsck.ubifs/extract_files.c | 95 ++++++++++---------- > ubifs-utils/fsck.ubifs/handle_disconnected.c | 6 +- > ubifs-utils/fsck.ubifs/problem.c | 20 ++--- > ubifs-utils/fsck.ubifs/rebuild_fs.c | 4 +- > ubifs-utils/libubifs/dir.c | 4 +- > 6 files changed, 69 insertions(+), 67 deletions(-) Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> > > diff --git a/ubifs-utils/fsck.ubifs/check_files.c b/ubifs-utils/fsck.ubifs/check_files.c > index 1e1a77b..4e5ff58 100644 > --- a/ubifs-utils/fsck.ubifs/check_files.c > +++ b/ubifs-utils/fsck.ubifs/check_files.c > @@ -101,8 +101,8 @@ static int construct_file(struct ubifs_info *c, union ubifs_key *key, > } > > dbg_fsck("construct file(%lu) for %s node, TNC location %d:%d, in %s", > - inum, ubifs_get_key_name(key_type(c, key)), sn->lnum, sn->offs, > - c->dev_name); > + (unsigned long)inum, ubifs_get_key_name(key_type(c, key)), > + sn->lnum, sn->offs, c->dev_name); > return insert_or_update_file(c, tree, sn, key_type(c, key), inum); > } > > @@ -344,7 +344,8 @@ void update_files_size(struct ubifs_info *c) > if (file && file->ino.header.exist && > file->ino.size < e->d_size) { > dbg_fsck("update file(%lu) size %llu->%llu, in %s", > - e->inum, file->ino.size, > + (unsigned long)e->inum, > + file->ino.size, > (unsigned long long)e->d_size, > c->dev_name); > file->ino.size = e->d_size; > diff --git a/ubifs-utils/fsck.ubifs/extract_files.c b/ubifs-utils/fsck.ubifs/extract_files.c > index 000ef5d..2e47b42 100644 > --- a/ubifs-utils/fsck.ubifs/extract_files.c > +++ b/ubifs-utils/fsck.ubifs/extract_files.c > @@ -78,21 +78,21 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (!inum || inum > INUM_WATERMARK) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node(bad inum %lu) at %d:%d, in %s", > - inum, lnum, offs, c->dev_name); > + (unsigned long)inum, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node(bad inum %lu) at %d:%d", > - inum, lnum, offs); > + (unsigned long)inum, lnum, offs); > goto out; > } > > if (ch->node_type != key_type(c, key)) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(inconsistent node type %d vs key_type %d) at %d:%d, in %s", > - inum, ch->node_type, key_type(c, key), > + (unsigned long)inum, ch->node_type, key_type(c, key), > lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(inconsistent node type %d vs key_type %d) at %d:%d", > - inum, ch->node_type, key_type(c, key), > + (unsigned long)inum, ch->node_type, key_type(c, key), > lnum, offs); > goto out; > } > @@ -114,43 +114,43 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (inum == UBIFS_ROOT_INO && !S_ISDIR(ino_node->mode)) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(root inode is not dir, tyoe %u) at %d:%d, in %s", > - inum, ino_node->mode & S_IFMT, lnum, offs, > + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs, > c->dev_name); > else > log_out(c, "bad inode node %lu(root inode is not dir, tyoe %u) at %d:%d", > - inum, ino_node->mode & S_IFMT, lnum, offs); > + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs); > goto out; > } > > if (ino_node->size > c->max_inode_sz) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(size %llu is too large) at %d:%d, in %s", > - inum, ino_node->size, lnum, offs, c->dev_name); > + (unsigned long)inum, ino_node->size, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(size %llu is too large) at %d:%d", > - inum, ino_node->size, lnum, offs); > + (unsigned long)inum, ino_node->size, lnum, offs); > goto out; > } > > if (le16_to_cpu(ino->compr_type) >= UBIFS_COMPR_TYPES_CNT) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(unknown compression type %d) at %d:%d, in %s", > - inum, le16_to_cpu(ino->compr_type), lnum, offs, > + (unsigned long)inum, le16_to_cpu(ino->compr_type), lnum, offs, > c->dev_name); > else > log_out(c, "bad inode node %lu(unknown compression type %d) at %d:%d", > - inum, le16_to_cpu(ino->compr_type), lnum, offs); > + (unsigned long)inum, le16_to_cpu(ino->compr_type), lnum, offs); > goto out; > } > > if (ino_node->xnms + ino_node->xcnt > XATTR_LIST_MAX) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(too big xnames %u xcount %u) at %d:%d, in %s", > - inum, ino_node->xnms, ino_node->xcnt, > + (unsigned long)inum, ino_node->xnms, ino_node->xcnt, > lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(too big xnames %u xcount %u) at %d:%d", > - inum, ino_node->xnms, ino_node->xcnt, > + (unsigned long)inum, ino_node->xnms, ino_node->xcnt, > lnum, offs); > goto out; > } > @@ -158,20 +158,20 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (data_len < 0 || data_len > UBIFS_MAX_INO_DATA) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(invalid data len %d) at %d:%d, in %s", > - inum, data_len, lnum, offs, c->dev_name); > + (unsigned long)inum, data_len, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(invalid data len %d) at %d:%d", > - inum, data_len, lnum, offs); > + (unsigned long)inum, data_len, lnum, offs); > goto out; > } > > if (UBIFS_INO_NODE_SZ + data_len != node_len) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(inconsistent data len %d vs node len %d) at %d:%d, in %s", > - inum, data_len, node_len, lnum, offs, c->dev_name); > + (unsigned long)inum, data_len, node_len, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(inconsistent data len %d vs node len %d) at %d:%d", > - inum, data_len, node_len, lnum, offs); > + (unsigned long)inum, data_len, node_len, lnum, offs); > goto out; > } > > @@ -179,33 +179,33 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (!S_ISREG(ino_node->mode)) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(bad type %u for xattr) at %d:%d, in %s", > - inum, ino_node->mode & S_IFMT, > + (unsigned long)inum, ino_node->mode & S_IFMT, > lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(bad type %u for xattr) at %d:%d", > - inum, ino_node->mode & S_IFMT, > + (unsigned long)inum, ino_node->mode & S_IFMT, > lnum, offs); > goto out; > } > if (data_len != ino_node->size) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(inconsistent data_len %d vs size %llu for xattr) at %d:%d, in %s", > - inum, data_len, ino_node->size, > + (unsigned long)inum, data_len, ino_node->size, > lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(inconsistent data_len %d vs size %llu for xattr) at %d:%d", > - inum, data_len, ino_node->size, > + (unsigned long)inum, data_len, ino_node->size, > lnum, offs); > goto out; > } > if (ino_node->xcnt || ino_node->xsz || ino_node->xnms) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d, in %s", > - inum, ino_node->xcnt, ino_node->xsz, > + (unsigned long)inum, ino_node->xcnt, ino_node->xsz, > ino_node->xnms, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(non zero xattr count %u xattr size %u xattr names %u for xattr) at %d:%d", > - inum, ino_node->xcnt, ino_node->xsz, > + (unsigned long)inum, ino_node->xcnt, ino_node->xsz, > ino_node->xnms, lnum, offs); > goto out; > } > @@ -216,10 +216,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (!ino_node->is_xattr && data_len != 0) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(bad data len %d for reg file) at %d:%d, in %s", > - inum, data_len, lnum, offs, c->dev_name); > + (unsigned long)inum, data_len, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(bad data len %d for reg file) at %d:%d", > - inum, data_len, lnum, offs); > + (unsigned long)inum, data_len, lnum, offs); > goto out; > } > break; > @@ -227,10 +227,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (data_len != 0) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(bad data len %d for dir file) at %d:%d, in %s", > - inum, data_len, lnum, offs, c->dev_name); > + (unsigned long)inum, data_len, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(bad data len %d for dir file) at %d:%d", > - inum, data_len, lnum, offs); > + (unsigned long)inum, data_len, lnum, offs); > goto out; > } > break; > @@ -249,10 +249,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > */ > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad symlink inode node %lu(bad data len %d) at %d:%d, in %s", > - inum, data_len, lnum, offs, c->dev_name); > + (unsigned long)inum, data_len, lnum, offs, c->dev_name); > else > log_out(c, "bad symlink inode node %lu(bad data len %d) at %d:%d", > - inum, data_len, lnum, offs); > + (unsigned long)inum, data_len, lnum, offs); > goto out; > } > break; > @@ -266,11 +266,11 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (data_len != sz_new && data_len != sz_huge) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(bad data len %d for char/block file, expect %d or %d) at %d:%d, in %s", > - inum, data_len, sz_new, sz_huge, lnum, > + (unsigned long)inum, data_len, sz_new, sz_huge, lnum, > offs, c->dev_name); > else > log_out(c, "bad inode node %lu(bad data len %d for char/block file, expect %d or %d) at %d:%d", > - inum, data_len, sz_new, sz_huge, lnum, > + (unsigned long)inum, data_len, sz_new, sz_huge, lnum, > offs); > goto out; > } > @@ -282,10 +282,10 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (data_len != 0) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(bad data len %d for fifo/sock file) at %d:%d, in %s", > - inum, data_len, lnum, offs, c->dev_name); > + (unsigned long)inum, data_len, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(bad data len %d for fifo/sock file) at %d:%d", > - inum, data_len, lnum, offs); > + (unsigned long)inum, data_len, lnum, offs); > goto out; > } > break; > @@ -293,21 +293,21 @@ bool parse_ino_node(struct ubifs_info *c, int lnum, int offs, void *node, > /* invalid file type. */ > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(unknown type %u) at %d:%d, in %s", > - inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); > + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(unknown type %u) at %d:%d", > - inum, ino_node->mode & S_IFMT, lnum, offs); > + (unsigned long)inum, ino_node->mode & S_IFMT, lnum, offs); > goto out; > } > > if (ino_node->is_encrypted && !inode_can_be_encrypted(c, ino_node)) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad inode node %lu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d, in %s", > - inum, ino_node->mode & S_IFMT, ino_node->is_xattr, > + (unsigned long)inum, ino_node->mode & S_IFMT, ino_node->is_xattr, > c->encrypted, lnum, offs, c->dev_name); > else > log_out(c, "bad inode node %lu(encrypted but cannot be encrypted, type %u, is_xattr %d, fs_encrypted %d) at %d:%d", > - inum, ino_node->mode & S_IFMT, ino_node->is_xattr, > + (unsigned long)inum, ino_node->mode & S_IFMT, ino_node->is_xattr, > c->encrypted, lnum, offs); > goto out; > } > @@ -357,12 +357,12 @@ bool parse_dent_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad %s node(len %d nlen %d type %d inum %lu key_type %d node_type %d) at %d:%d, in %s", > ch->node_type == UBIFS_XENT_NODE ? "xattr entry" : "directory entry", > - node_len, nlen, dent->type, inum, key_type, > + node_len, nlen, dent->type, (unsigned long)inum, key_type, > ch->node_type, lnum, offs, c->dev_name); > else > log_out(c, "bad %s node(len %d nlen %d type %d inum %lu key_type %d node_type %d) at %d:%d", > ch->node_type == UBIFS_XENT_NODE ? "xattr entry" : "directory entry", > - node_len, nlen, dent->type, inum, key_type, > + node_len, nlen, dent->type, (unsigned long)inum, key_type, > ch->node_type, lnum, offs); > goto out; > } > @@ -419,10 +419,10 @@ bool parse_data_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (!inum || inum > INUM_WATERMARK) { > if (FSCK(c)->mode == REBUILD_MODE) > dbg_fsck("bad data node(bad inum %lu) at %d:%d, in %s", > - inum, lnum, offs, c->dev_name); > + (unsigned long)inum, lnum, offs, c->dev_name); > else > log_out(c, "bad data node(bad inum %lu) at %d:%d", > - inum, lnum, offs); > + (unsigned long)inum, lnum, offs); > goto out; > } > > @@ -485,7 +485,7 @@ bool parse_trun_node(struct ubifs_info *c, int lnum, int offs, void *node, > > if (!inum || inum > INUM_WATERMARK) { > dbg_fsck("bad truncation node(bad inum %lu) at %d:%d, in %s", > - inum, lnum, offs, c->dev_name); > + (unsigned long)inum, lnum, offs, c->dev_name); > goto out; > } > > @@ -496,8 +496,9 @@ bool parse_trun_node(struct ubifs_info *c, int lnum, int offs, void *node, > if (old_size < 0 || old_size > c->max_inode_sz || > new_size < 0 || new_size > c->max_inode_sz || > old_size <= new_size) { > - dbg_fsck("bad truncation node(new size %ld old size %ld inum %lu) at %d:%d, in %s", > - new_size, old_size, inum, lnum, offs, c->dev_name); > + dbg_fsck("bad truncation node(new size %lld old size %lld inum %lu) at %d:%d, in %s", > + (long long)new_size, (long long)old_size, > + (unsigned long)inum, lnum, offs, c->dev_name); > goto out; > } > > @@ -1007,7 +1008,7 @@ int file_is_valid(struct ubifs_info *c, struct scanned_file *file, > struct scanned_data_node *data_node; > LIST_HEAD(drop_list); > > - dbg_fsck("check validation of file %lu, in %s", file->inum, c->dev_name); > + dbg_fsck("check validation of file %lu, in %s", (unsigned long)file->inum, c->dev_name); > > if (!file->ino.header.exist) { > handle_invalid_file(c, FILE_HAS_NO_INODE, file, NULL); > @@ -1275,12 +1276,12 @@ retry: > handle_invalid_file(c, FILE_IS_DISCONNECTED, file, NULL); > else > handle_invalid_file(c, FILE_HAS_NO_DENT, file, NULL); > - dbg_fsck("file %lu is unreachable, in %s", file->inum, c->dev_name); > + dbg_fsck("file %lu is unreachable, in %s", (unsigned long)file->inum, c->dev_name); > return false; > } > > reachable: > - dbg_fsck("file %lu is reachable, in %s", file->inum, c->dev_name); > + dbg_fsck("file %lu is reachable, in %s", (unsigned long)file->inum, c->dev_name); > return true; > } > > @@ -1498,7 +1499,7 @@ static int correct_file_info(struct ubifs_info *c, struct scanned_file *file) > handle_invalid_file(c, FILE_IS_INCONSISTENT, file, NULL); > lnum = file->ino.header.lnum; > dbg_fsck("correct file(inum:%lu type:%s), nlink %u->%u, xattr cnt %u->%u, xattr size %u->%u, xattr names %u->%u, size %llu->%llu, at %d:%d, in %s", > - file->inum, file->ino.is_xattr ? "xattr" : > + (unsigned long)file->inum, file->ino.is_xattr ? "xattr" : > ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), > file->ino.nlink, file->calc_nlink, > file->ino.xcnt, file->calc_xcnt, > diff --git a/ubifs-utils/fsck.ubifs/handle_disconnected.c b/ubifs-utils/fsck.ubifs/handle_disconnected.c > index be62522..9e5d925 100644 > --- a/ubifs-utils/fsck.ubifs/handle_disconnected.c > +++ b/ubifs-utils/fsck.ubifs/handle_disconnected.c > @@ -117,7 +117,7 @@ static int handle_disonnected_file(struct ubifs_info *c, > struct ubifs_inode *target_ui; > > err = snprintf(file_name, sizeof(file_name), > - "INO_%lu_%u", file->inum, index); > + "INO_%lu_%u", (unsigned long)file->inum, index); > if (err < 0) > goto free_ui; > fname_name(&nm) = file_name; > @@ -138,7 +138,7 @@ static int handle_disonnected_file(struct ubifs_info *c, > kfree(ui); > kfree(lost_found_ui); > log_out(c, "Too many duplicated names(%u) in lost+found for inum %lu", > - index, file->inum); > + index, (unsigned long)file->inum); > goto delete_file; > } > > @@ -150,7 +150,7 @@ static int handle_disonnected_file(struct ubifs_info *c, > goto delete_file; > } > dbg_fsck("recover disconnected file %lu, in %s", > - file->inum, c->dev_name); > + (unsigned long)file->inum, c->dev_name); > > free_ui: > kfree(ui); > diff --git a/ubifs-utils/fsck.ubifs/problem.c b/ubifs-utils/fsck.ubifs/problem.c > index 916c976..edb5f57 100644 > --- a/ubifs-utils/fsck.ubifs/problem.c > +++ b/ubifs-utils/fsck.ubifs/problem.c > @@ -147,7 +147,7 @@ static void print_problem(const struct ubifs_info *c, > { > const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; > > - log_out(c, "problem: %s, ino %lu", problem->desc, ifp->file->inum); > + log_out(c, "problem: %s, ino %lu", problem->desc, (unsigned long)ifp->file->inum); > break; > } > case FILE_HAS_INCONSIST_TYPE: > @@ -156,7 +156,7 @@ static void print_problem(const struct ubifs_info *c, > const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; > > log_out(c, "problem: %s, ino %lu, inode type %s%s, dentry %s has type %s%s", > - problem->desc, ifp->file->inum, > + problem->desc, (unsigned long)ifp->file->inum, > ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), > ifp->file->ino.is_xattr ? "(xattr)" : "", > c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, > @@ -171,7 +171,7 @@ static void print_problem(const struct ubifs_info *c, > const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; > > log_out(c, "problem: %s, ino %lu, type %s%s, dentry %s", > - problem->desc, ifp->file->inum, > + problem->desc, (unsigned long)ifp->file->inum, > ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), > ifp->file->ino.is_xattr ? "(xattr)" : "", > c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name); > @@ -183,7 +183,7 @@ static void print_problem(const struct ubifs_info *c, > const struct scanned_data_node *data_node = (const struct scanned_data_node *)ifp->priv; > > log_out(c, "problem: %s, ino %lu, type %s%s, data block %u", > - problem->desc, ifp->file->inum, > + problem->desc, (unsigned long)ifp->file->inum, > ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), > ifp->file->ino.is_xattr ? "(xattr)" : "", > key_block(c, &data_node->key)); > @@ -198,7 +198,7 @@ static void print_problem(const struct ubifs_info *c, > const struct invalid_file_problem *ifp = (const struct invalid_file_problem *)priv; > > log_out(c, "problem: %s, ino %lu type %s%s", problem->desc, > - ifp->file->inum, > + (unsigned long)ifp->file->inum, > ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), > ifp->file->ino.is_xattr ? "(xattr)" : ""); > break; > @@ -209,9 +209,9 @@ static void print_problem(const struct ubifs_info *c, > const struct scanned_file *host = (const struct scanned_file *)ifp->priv; > > log_out(c, "problem: %s, ino %lu type %s%s, host ino %lu type %s%s", > - problem->desc, ifp->file->inum, > + problem->desc, (unsigned long)ifp->file->inum, > ubifs_get_type_name(ubifs_get_dent_type(ifp->file->ino.mode)), > - ifp->file->ino.is_xattr ? "(xattr)" : "", host->inum, > + ifp->file->ino.is_xattr ? "(xattr)" : "", (unsigned long)host->inum, > ubifs_get_type_name(ubifs_get_dent_type(host->ino.mode)), > host->ino.is_xattr ? "(xattr)" : ""); > break; > @@ -222,7 +222,7 @@ static void print_problem(const struct ubifs_info *c, > const struct scanned_dent_node *dent_node = (const struct scanned_dent_node *)ifp->priv; > > log_out(c, "problem: %s, ino %lu, unreachable dentry %s, type %s%s", > - problem->desc, ifp->file->inum, > + problem->desc, (unsigned long)ifp->file->inum, > c->encrypted && !ifp->file->ino.is_xattr ? "<encrypted>" : dent_node->name, > ubifs_get_type_name(dent_node->type), > key_type(c, &dent_node->key) == UBIFS_XENT_KEY ? "(xattr)" : ""); > @@ -235,7 +235,7 @@ static void print_problem(const struct ubifs_info *c, > > log_out(c, "problem: %s, ino %lu type %s, nlink %u xcnt %u xsz %u xnms %u size %llu, " > "should be nlink %u xcnt %u xsz %u xnms %u size %llu", > - problem->desc, file->inum, > + problem->desc, (unsigned long)file->inum, > file->ino.is_xattr ? "xattr" : ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), > file->ino.nlink, file->ino.xcnt, file->ino.xsz, > file->ino.xnms, file->ino.size, > @@ -299,7 +299,7 @@ static void print_problem(const struct ubifs_info *c, > const struct scanned_file *file = (const struct scanned_file *)priv; > > log_out(c, "problem: %s, ino %lu, size %llu", problem->desc, > - file->inum, file->ino.size); > + (unsigned long)file->inum, file->ino.size); > break; > } > default: > diff --git a/ubifs-utils/fsck.ubifs/rebuild_fs.c b/ubifs-utils/fsck.ubifs/rebuild_fs.c > index b82d728..b399b3e 100644 > --- a/ubifs-utils/fsck.ubifs/rebuild_fs.c > +++ b/ubifs-utils/fsck.ubifs/rebuild_fs.c > @@ -697,7 +697,7 @@ static void extract_dentry_tree(struct ubifs_info *c) > file = list_entry(unreachable.next, struct scanned_file, list); > > dbg_fsck("remove unreachable file %lu, in %s", > - file->inum, c->dev_name); > + (unsigned long)file->inum, c->dev_name); > list_del(&file->list); > destroy_file_content(c, file); > rb_erase(&file->rb, tree); > @@ -1097,7 +1097,7 @@ static int record_file_used_lebs(struct ubifs_info *c, > struct scanned_data_node *data_node; > > dbg_fsck("recovered file(inum:%lu name:%s type:%s), in %s", > - file->inum, get_file_name(c, file), > + (unsigned long)file->inum, get_file_name(c, file), > file->ino.is_xattr ? "xattr" : > ubifs_get_type_name(ubifs_get_dent_type(file->ino.mode)), > c->dev_name); > diff --git a/ubifs-utils/libubifs/dir.c b/ubifs-utils/libubifs/dir.c > index 89f77eb..2eb4e75 100644 > --- a/ubifs-utils/libubifs/dir.c > +++ b/ubifs-utils/libubifs/dir.c > @@ -249,7 +249,7 @@ int ubifs_mkdir(struct ubifs_info *c, struct ubifs_inode *dir_ui, > * directory inode. > */ > dbg_gen("dent '%s', mode %#hx in dir ino %lu", > - fname_name(nm), mode, dir->inum); > + fname_name(nm), mode, (unsigned long)dir->inum); > > /* New dir is not allowed to be created under an encrypted directory. */ > ubifs_assert(c, !(dir_ui->flags & UBIFS_CRYPT_FL)); > @@ -315,7 +315,7 @@ int ubifs_link_recovery(struct ubifs_info *c, struct ubifs_inode *dir_ui, > * changing the parent inode. > */ > dbg_gen("dent '%s' to ino %lu (nlink %d) in dir ino %lu", > - fname_name(nm), inode->inum, inode->nlink, dir->inum); > + fname_name(nm), (unsigned long)inode->inum, inode->nlink, (unsigned long)dir->inum); > > /* New dir is not allowed to be created under an encrypted directory. */ > ubifs_assert(c, !(dir_ui->flags & UBIFS_CRYPT_FL)); > ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-14 1:33 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-13 8:29 [PATCH mtd-utils 0/2] mtd-utils: fsck.ubifs: fixes several undefined behaviors Yuta Hayama 2025-11-13 8:31 ` [PATCH mtd-utils 1/2] fsck.ubifs: don't use pointers that reference out-of-scope variables Yuta Hayama 2025-11-14 3:15 ` Zhihao Cheng 2025-11-13 8:32 ` [PATCH mtd-utils 2/2] fsck.ubifs: use the appropriate format specifiers for ino_t and loff_t Yuta Hayama 2025-11-14 8:54 ` Zhihao Cheng 2026-02-13 13:55 ` [mtd-utils,v2,2/2] fsck.ubifs: fix platform dependant ino_t and loff_t formatting Tomas Alvarez Vanoli 2026-02-14 1:33 ` Zhihao Cheng
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox