If fscrypt is enabled, we need to convert the encrypted file name before
printing it. So let's export convert_encrypted_name for other functions,
and make it returns the length of converted string.
This patch also changes the parameter of file_is_encrypt to f2fs_inode.
Signed-off-by: Sheng Yong
---
fsck/dump.c | 6 --
fsck/fsck.c | 46 --
fsck/fsck.h | 1 +
fsck/mount.c | 10 +++---
include/f2fs_fs.h | 2 +-
5 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/fsck/dump.c b/fsck/dump.c
index befffd7..8e7c85c 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -353,9 +353,10 @@ static void dump_file(struct f2fs_sb_info *sbi, struct
node_info *ni,
struct f2fs_inode *inode = &node_blk->i;
u32 imode = le32_to_cpu(inode->i_mode);
u32 namelen = le32_to_cpu(inode->i_namelen);
- char name[255] = {0};
+ unsigned char name[F2FS_NAME_LEN + 1] = {0};
char path[1024] = {0};
char ans[255] = {0};
+ int is_encrypt = file_is_encrypt(inode);
int ret;
if (!S_ISREG(imode) || namelen == 0 || namelen > F2FS_NAME_LEN) {
@@ -375,7 +376,8 @@ dump:
ASSERT(ret >= 0);
/* make a file */
- strncpy(name, (const char *)inode->i_name, namelen);
+ namelen = convert_encrypted_name(inode->i_name, namelen,
+ name, is_encrypt);
name[namelen] = 0;
sprintf(path, "./lost_found/%s", name);
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 7dd311f..d0392c3 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -426,8 +426,19 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32
nid,
if (ntype == TYPE_INODE && ftype == F2FS_FT_DIR) {
u32 len = le32_to_cpu(node_blk->i.i_namelen);
if (name && memcmp(name, node_blk->i.i_name, len)) {
- ASSERT_MSG("mismatch name [0x%x] [%s vs. %s]",
- nid, name, node_blk->i.i_name);
+ int is_encrypt = file_is_encrypt(&node_blk->i);
+ unsigned char en1[F2FS_NAME_LEN + 1];
+ unsigned char en2[F2FS_NAME_LEN + 1];
+ /* if file is encrypted, its parent must be encrypted */
+ int len1 = convert_encrypted_name(name, len, en1,
+ is_encrypt);
+ int len2 = convert_encrypted_name(node_blk->i.i_name,
+ len, en2, is_encrypt);
+ en1[len1] = '\0';
+ en2[len2] = '\0';
+ ASSERT_MSG("mismatch name [0x%x] [%s vs. %s]%s",
+ nid, en1, en2,
+ is_encrypt ? " " : "");
return -EINVAL;
}
}
@@ -607,6 +618,8 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
u32 i_links = le32_to_cpu(node_blk->i.i_links);
u64 i_size = le64_to_cpu(node_blk->i.i_size);
u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
+ unsigned char en[F2FS_NAME_LEN + 1];
+ int namelen;
unsigned int idx = 0;
int need_fix = 0;
int ret;
@@ -727,7 +740,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
blkaddr,
&child, (i_blocks == *blk_cnt),
ftype, nid, idx, ni->version,
- file_is_encrypt(node_blk->i.i_advise));
+ file_is_encrypt(&node_blk->i));
if (!ret) {
*blk_cnt = *blk_cnt + 1;
} else if (c.fix_on) {
@@ -798,16 +811,18 @@ check:
}
}
skip_blkcnt_fix:
+ namelen = convert_encrypted_name(node_blk->i.i_name,
+ le32_to_cpu(node_blk->i.i_namelen),
+ en, file_is_encrypt(&node_blk->i));
+ en[namelen] = '\0';
if (ftype == F2FS_FT_ORPHAN)
DBG(1, "Orphan Inode: 0x%x [%s] i_blocks: %u\n\n",
le32_to_cpu(node_blk->footer.ino),
- node_blk->i.i_name,
- (u32)i_blocks);
+ en, (u32)i_blocks);
if (ftype == F2FS_FT_DIR) {
DBG(1, "Directory Inode: 0x%x [%s] depth: %d has %d files\n\n",
- le32_to_cpu(node_blk->footer.ino),
- node_blk->i.i_name,
+ le32_to_cpu(node_blk->footer.ino), en,
le32_to_cpu(node_blk->i.i_current_depth),