Skip to contentSkip to conversation

f2fs-tools: improve filename printing

PATCH In review Eric Biggers 3 participants 4 messages Apr 24, 2019 – May 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs-tools: improve filename printing

From: Eric Biggers <[email protected]>

- Make buffers for pretty-printed filenames 341 bytes long, long enough for 255 (NAME_MAX) base64-encoded bytes. Then print encrypted filenames in full, base64-encoded. This will be useful for tests I'm writing which verify the correct ciphertext is stored on-disk.

- Rename convert_encrypted_name() to pretty_print_filename(), to make it clear that it handles unencrypted names too. Also make the output 'char' rather than 'unsigned char', as it's for printing; and remove the unnecessary return value.

---
 fsck/dump.c       | 12 ++++------
 fsck/fsck.c       | 58 ++++++++++++++++++++---------------------------
 fsck/fsck.h       |  3 ++-
 fsck/mount.c      | 10 ++++----
 include/f2fs_fs.h |  4 ++++
 5 files changed, 40 insertions(+), 47 deletions(-)
fsck/dump.c +5 -7
index 07dc2fc..390361d 100644
@@ -627,8 +627,8 @@ static void dump_dirent(u32 blk_addr, int is_inline, int enc_name)
 
 	while (i < d.max) {
 		struct f2fs_dir_entry *de;
-		unsigned char en[F2FS_NAME_LEN + 1];
-		u16 en_len, name_len;
+		char en[F2FS_PRINT_NAMELEN];
+		u16 name_len;
 		int enc;
 
 		if (!test_bit_le(i, d.bitmap)) {
@@ -654,18 +654,16 @@ static void dump_dirent(u32 blk_addr, int is_inline, int enc_name)
 			}
 		}
 
-		en_len = convert_encrypted_name(d.filename[i],
-				le16_to_cpu(de->name_len), en, enc);
-		en[en_len] = '\0';
+		pretty_print_filename(d.filename[i], name_len, en, enc);
 
 		DBG(1, "bitmap pos[0x%x] name[%s] len[0x%x] hash[0x%x] ino[0x%x] type[0x%x]\n",
 				i, en,
-				le16_to_cpu(de->name_len),
+				name_len,
 				le32_to_cpu(de->hash_code),
 				le32_to_cpu(de->ino),
 				de->file_type);
 
-		i += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
+		i += GET_DENTRY_SLOTS(name_len);
 	}
 
 	free(blk);
fsck/fsck.c +25 -33

133 lines not on this page · raw message

fsck/fsck.h +2 -1
index c8802b0..4991a63 100644
@@ -157,7 +157,8 @@ int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
 void fsck_chk_checkpoint(struct f2fs_sb_info *sbi);
 int fsck_chk_meta(struct f2fs_sb_info *sbi);
 int fsck_chk_curseg_info(struct f2fs_sb_info *);
-int convert_encrypted_name(unsigned char *, u32, unsigned char *, int);
+void pretty_print_filename(const u8 *raw_name, u32 len,
+			   char out[F2FS_PRINT_NAMELEN], int enc_name);
 
 extern void update_free_segments(struct f2fs_sb_info *);
 void print_cp_state(u32);
fsck/mount.c +4 -6
index c69226d..4800d26 100644
@@ -165,16 +165,14 @@ void print_inode_info(struct f2fs_sb_info *sbi,
 	struct f2fs_inode *inode = &node->i;
 	void *xattr_addr;
 	struct f2fs_xattr_entry *ent;
-	unsigned char en[F2FS_NAME_LEN + 1];
+	char en[F2FS_PRINT_NAMELEN];
 	unsigned int i = 0;
 	u32 namelen = le32_to_cpu(inode->i_namelen);
 	int enc_name = file_enc_name(inode);
 	int ofs = __get_extra_isize(inode);
 
-	namelen = convert_encrypted_name(inode->i_name, namelen, en, enc_name);
-	en[namelen] = '\0';
-	if (name && namelen) {
-		inode->i_name[namelen] = '\0';
+	pretty_print_filename(inode->i_name, namelen, en, enc_name);
+	if (name && en[0]) {
 		MSG(0, " - File name         : %s%s\n", en,
 				enc_name ? " <encrypted>" : "");
 		setlocale(LC_ALL, "");
@@ -206,7 +204,7 @@ void print_inode_info(struct f2fs_sb_info *sbi,
 	DISP_u32(inode, i_pino);
 	DISP_u32(inode, i_dir_level);
 
-	if (namelen) {
+	if (en[0]) {
 		DISP_u32(inode, i_namelen);
 		printf("%-30s\t\t[%s]\n", "i_name", en);
 	}
include/f2fs_fs.h +4 -0
index 9f76795..f0a558e 100644
@@ -726,6 +726,10 @@ struct f2fs_extent {
 } __attribute__((packed));
 
 #define F2FS_NAME_LEN		255
+
+/* max output length of pretty_print_filename() including null terminator */
+#define F2FS_PRINT_NAMELEN	(4 * ((F2FS_NAME_LEN + 2) / 3) + 1)
+
 /* 200 bytes for inline xattrs by default */
 #define DEFAULT_INLINE_XATTR_ADDRS	50
 #define DEF_ADDRS_PER_INODE	923	/* Address Pointers in an Inode */
Signature · 1 line
2.21.0.593.g511ec345e18-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

- Make buffers for pretty-printed filenames 341 bytes long, long enough for 255 (NAME_MAX) base64-encoded bytes. Then print encrypted filenames in full, base64-encoded. This will be useful for tests I'm writing which verify the correct ciphertext is stored on-disk.

Quoted 6 lines

- Rename convert_encrypted_name() to pretty_print_filename(), to make it clear that it handles unencrypted names too. Also make the output 'char' rather than 'unsigned char', as it's for printing; and remove the unnecessary return value.

Thanks,

#2 lore raw
Quoted 13 lines · Chao Yu
Quoted 12 lines · Eric Biggers

From: Eric Biggers <[email protected]>

- Make buffers for pretty-printed filenames 341 bytes long, long enough for 255 (NAME_MAX) base64-encoded bytes. Then print encrypted filenames in full, base64-encoded. This will be useful for tests I'm writing which verify the correct ciphertext is stored on-disk.

- Rename convert_encrypted_name() to pretty_print_filename(), to make it clear that it handles unencrypted names too. Also make the output 'char' rather than 'unsigned char', as it's for printing; and remove the unnecessary return value.

Quoted 6 lines
Quoted 1 line

Thanks,

Hi Jaegeuk, are you planning to apply this patch?

Thanks,

- Eric

#3 lore raw
Quoted 14 lines · Eric Biggers
Quoted 13 lines · Chao Yu
Quoted 12 lines · Eric Biggers

From: Eric Biggers <[email protected]>

- Make buffers for pretty-printed filenames 341 bytes long, long enough for 255 (NAME_MAX) base64-encoded bytes. Then print encrypted filenames in full, base64-encoded. This will be useful for tests I'm writing which verify the correct ciphertext is stored on-disk.

- Rename convert_encrypted_name() to pretty_print_filename(), to make it clear that it handles unencrypted names too. Also make the output 'char' rather than 'unsigned char', as it's for printing; and remove the unnecessary return value.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks,

Hi Jaegeuk, are you planning to apply this patch?

ditto.

Quoted 4 lines

Thanks,

- Eric