Skip to contentSkip to conversation

dump.f2fs: show extra attr only when feature is enabled

PATCH New Chao Yu 1 participant 4 messages Nov 16, 2017

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/4 dump.f2fs: show extra attr only when feature is enabled

If we don't turn on the feature, don't show related info in dumped data.

---
 fsck/mount.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
fsck/mount.c +9 -4
index 653dcf391da7..c094f940ee1b 100644
@@ -222,10 +222,15 @@ void print_inode_info(struct f2fs_sb_info *sbi,
 			le32_to_cpu(inode->i_ext.blk_addr),
 			le32_to_cpu(inode->i_ext.len));
 
-	DISP_u16(inode, i_extra_isize);
-	DISP_u16(inode, i_inline_xattr_size);
-	DISP_u32(inode, i_projid);
-	DISP_u32(inode, i_inode_checksum);
+	if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
+		DISP_u16(inode, i_extra_isize);
+		if (c.feature & cpu_to_le32(F2FS_FEATURE_FLEXIBLE_INLINE_XATTR))
+			DISP_u16(inode, i_inline_xattr_size);
+		if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
+			DISP_u32(inode, i_projid);
+		if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
+			DISP_u32(inode, i_inode_checksum);
+	}
 
 	DISP_u32(inode, i_addr[ofs]);		/* Pointers to data blocks */
 	DISP_u32(inode, i_addr[ofs + 1]);	/* Pointers to data blocks */
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
author
#1 lore raw

PATCH 2/4 fsck.f2fs: fix potential stack overflow issue

In fsck_chk_inode_blk, we will allocate 256 bytes memory in stack before traversing sub-directory recursively, it's not safe, in order to avoid potential stack overflow, use malloc instead.

---
 fsck/fsck.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fsck/fsck.c +7 -1
index ec8871278464..11b8b0b8303d 100644
@@ -633,7 +633,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 	u64 i_size = le64_to_cpu(node_blk->i.i_size);
 	u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
 	int ofs = get_extra_isize(node_blk);
-	unsigned char en[F2FS_NAME_LEN + 1];
+	unsigned char *en;
 	int namelen;
 	unsigned int idx = 0;
 	int need_fix = 0;
@@ -838,6 +838,9 @@ check:
 		}
 	}
 skip_blkcnt_fix:
+	en = malloc(F2FS_NAME_LEN + 1);
+	ASSERT(en);
+
 	namelen = convert_encrypted_name(node_blk->i.i_name,
 					le32_to_cpu(node_blk->i.i_namelen),
 					en, file_enc_name(&node_blk->i));
@@ -879,6 +882,9 @@ skip_blkcnt_fix:
 			}
 		}
 	}
+
+	free(en);
+
 	if (ftype == F2FS_FT_SYMLINK && i_blocks && i_size == 0) {
 		DBG(1, "ino: 0x%x i_blocks: %lu with zero i_size",
 						nid, (unsigned long)i_blocks);
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
author
#2 lore raw

PATCH 3/4 f2fs: avoid memory leak in f2fs_write_root_inode

In reply to Chao Yu

Before exiting f2fs_write_root_inode, we should free in-there allocated memory.

---
 mkfs/f2fs_format.c | 3 +++
 1 file changed, 3 insertions(+)
mkfs/f2fs_format.c +3 -0
index d5f39ca3dac4..9fc0398fab65 100644
@@ -1042,6 +1042,7 @@ static int f2fs_write_root_inode(void)
 			c.blks_per_seg, main_area_node_seg_blk_offset);
 	if (dev_write_block(raw_node, main_area_node_seg_blk_offset)) {
 		MSG(1, "\tError: While writing the raw_node to disk!!!\n");
+		free(raw_node);
 		return -1;
 	}
 
@@ -1052,9 +1053,11 @@ static int f2fs_write_root_inode(void)
 
 #ifndef WITH_ANDROID
 	if (discard_obsolete_dnode(raw_node, main_area_node_seg_blk_offset)) {
+		free(raw_node);
 		return -1;
 	}
 #endif
+	free(raw_node);
 	return 0;
 }
 
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
author
#3 lore raw

PATCH 4/4 f2fs-tools: adjust feature name

In reply to Chao Yu

This patch slightly changes showed feature name.

Before:
Info: superblock features = f9 : encrypt extra attribute project quota inode checksum flexible inline xattr quota ino

After:
Info: superblock features = f9 : encrypt extra_attr project_quota inode_checksum flexible_inline_xattr quota_ino

---
 fsck/mount.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fsck/mount.c +6 -6
index c094f940ee1b..4ad22a136ca9 100644
@@ -429,22 +429,22 @@ void print_sb_state(struct f2fs_super_block *sb)
 		MSG(0, "%s", " encrypt");
 	}
 	if (f & cpu_to_le32(F2FS_FEATURE_BLKZONED)) {
-		MSG(0, "%s", " zoned block device");
+		MSG(0, "%s", " blkzoned");
 	}
 	if (f & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
-		MSG(0, "%s", " extra attribute");
+		MSG(0, "%s", " extra_attr");
 	}
 	if (f & cpu_to_le32(F2FS_FEATURE_PRJQUOTA)) {
-		MSG(0, "%s", " project quota");
+		MSG(0, "%s", " project_quota");
 	}
 	if (f & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM)) {
-		MSG(0, "%s", " inode checksum");
+		MSG(0, "%s", " inode_checksum");
 	}
 	if (f & cpu_to_le32(F2FS_FEATURE_FLEXIBLE_INLINE_XATTR)) {
-		MSG(0, "%s", " flexible inline xattr");
+		MSG(0, "%s", " flexible_inline_xattr");
 	}
 	if (f & cpu_to_le32(F2FS_FEATURE_QUOTA_INO)) {
-		MSG(0, "%s", " quota ino");
+		MSG(0, "%s", " quota_ino");
 	}
 	MSG(0, "\n");
 	MSG(0, "Info: superblock encrypt level = %d, salt = ",
Signature · 6 lines
2.15.0.55.gc2ece9dc4de6


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot