On 6/13/25 15:55, Chao Yu wrote:
On 2025/6/10 20:37, Sheng Yong wrote:
From: Sheng Yong <shengyo...@xiaomi.com>
This patch adds a new member `filename' in inject_dentry to inject
dentry filename. The dentry is specified by nid option.
Note that '.' and '..' dentries are special, because they are not in the
parent directory of nid. So this patch also adds a new option `--dots'
to inject these two dentries.
Signed-off-by: Sheng Yong <shengyo...@xiaomi.com>
---
fsck/inject.c | 94 ++++++++++++++++++++++++++++++++++++++++-------
fsck/inject.h | 1 +
man/inject.f2fs.8 | 12 +++++-
3 files changed, 92 insertions(+), 15 deletions(-)
diff --git a/fsck/inject.c b/fsck/inject.c
index 8c2f8c5dc332..5eb913fefad7 100644
--- a/fsck/inject.c
+++ b/fsck/inject.c
[...]
@@ -1265,6 +1301,36 @@ static int inject_dentry(struct f2fs_sb_info *sbi,
struct inject_option *opt)
"%d -> %d\n", opt->nid, dent->file_type,
(u8)opt->val);
dent->file_type = (u8)opt->val;
+ } else if (!strcmp(opt->mb, "filename")) {
+ if (!opt->str) {
+ ERR_MSG("option str is needed\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ namecap = ALIGN_UP(le16_to_cpu(dent->name_len), F2FS_SLOT_LEN);
+ namelen = strlen(opt->str);
+ if (namelen > namecap || namelen > F2FS_NAME_LEN) {
+ ERR_MSG("option str too long\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ name = (char *)d.filename[slot];
+ MSG(0, "Info: inject dentry filename of nid %u: "
+ "%.*s -> %s\n", opt->nid, le16_to_cpu(dent->name_len),
+ name, opt->str);
+ memcpy(name, opt->str, namelen);
+ MSG(0, "Info: inject dentry namelen of nid %u: "
+ "%d -> %d\n", opt->nid, le16_to_cpu(dent->name_len),
+ namelen);
+ dent->name_len = cpu_to_le16(namelen);
+ dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
+ IS_CASEFOLDED(inode),
+ (unsigned char *)name,
+ namelen);
+ MSG(0, "Info: inject dentry d_hash of nid %u: "
+ "0x%x -> 0x%x\n", opt->nid, le32_to_cpu(dent->hash_code),
+ dentry_hash);
+ dent->hash_code = cpu_to_le32(dentry_hash);
Yong,
Out of curiosity, if we inject filename in target dirent, according new
filename's hash, it may be located in dentry block which belongs to another
bucket, can fsck repair it?
Hi, Chao,
Yes, I think fsck can repair it, but it removes the entry directly instead of
"reordering" it (`f2fs_check_dirent_position`). I can add a test for this case.
Thanks,
shengyong
Thanks,
} else {
ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb);
ret = -EINVAL;
diff --git a/fsck/inject.h b/fsck/inject.h
index 43c21b56a7eb..706a211bc645 100644
--- a/fsck/inject.h
+++ b/fsck/inject.h
@@ -30,6 +30,7 @@ struct inject_option {
int cp; /* which cp */
int nat; /* which nat pack */
int sit; /* which sit pack */
+ int dots; /* . or .. dentry */
bool ssa;
bool node;
bool dent;
diff --git a/man/inject.f2fs.8 b/man/inject.f2fs.8
index 72d1c90f7ce4..27b66f59b77d 100644
--- a/man/inject.f2fs.8
+++ b/man/inject.f2fs.8
@@ -214,7 +214,14 @@ inode i_nid array specified by \fIidx\fP.
.RE
.TP
.BI \-\-dent
-Inject dentry block or dir entry specified \fInid\fP.
+Inject dentry block or dir entry specified by \fInid\fP.
+.RS 1.2i
+.TP
+.BI \-\-dots " 1 or 2"
+The option means the "." or ".." directory entry of \fInid\fP is going to be
injected.
+.RE
+.TP
+.BI ""
The available \fImb\fP of \fIdent\fP are:
.RS 1.2i
.TP
@@ -229,6 +236,9 @@ dentry ino.
.TP
.BI d_ftype
dentry ftype.
+.TP
+.BI filename
+dentry filename, and corresponding d_hash and namelen are updated implicitly.
.RE
.TP
.BI \-\-dry\-run
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel