Skip to contentSkip to conversation

f2fs-tools: fix missing function declaration

PATCH New Changman Lee 1 participant 4 messages Jul 30, 2013 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 f2fs-tools: fix missing function declaration

Explicitly declare function name.

---
 fsck/fsck.h |    1 +
 1 file changed, 1 insertion(+)
fsck/fsck.h +1 -0
index a8f440c..94808b8 100644
@@ -160,5 +160,6 @@ struct dump_option {
 extern void sit_dump(struct f2fs_sb_info *sbi, int start_sit, int end_sit);
 extern void ssa_dump(struct f2fs_sb_info *sbi, int start_ssa, int end_ssa);
 extern int dump_node(struct f2fs_sb_info *sbi, nid_t nid);
+extern int dump_inode_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr);
 
 #endif /* _FSCK_H_ */
Signature · 9 lines
1.7.10.4


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
#1 lore raw

PATCH 2/4 f2fs-tools: cleanup debug statement

The debug message is too verbose therefore decrease message.

---
 fsck/dump.c      |    2 +-
 fsck/mount.c     |   12 ++++++++++--
 3 files changed, 12 insertions(+), 4 deletions(-)
fsck/dump.c +1 -1
index 4c113dd..1b19bbc 100644
@@ -170,7 +170,7 @@ read_node_blk:
 	ino = le32_to_cpu(node_blk->footer.ino);
 	nid = le32_to_cpu(node_blk->footer.nid);
 	if (ino == nid) {
-		print_inode_info(&node_blk->i);
+		print_node_info(node_blk);
 	} else {
 		ret = get_node_info(sbi, ino, &ni);
 		goto read_node_blk;
fsck/mount.c +10 -2
index 13a3ef1..d936600 100644
@@ -88,6 +88,10 @@ void print_node_info(struct f2fs_node *node_block)
 void print_raw_sb_info(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
+
+	if (!config.dbg_lv)
+		return;
+
 	printf("\n");
 	printf("+--------------------------------------------------------+\n");
 	printf("| Super block                                            |\n");
@@ -132,6 +136,9 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
 
+	if (!config.dbg_lv)
+		return;
+
 	printf("\n");
 	printf("+--------------------------------------------------------+\n");
 	printf("| Checkpoint                                             |\n");
@@ -938,7 +945,8 @@ int build_sit_area_bitmap(struct f2fs_sb_info *sbi)
 	fsck->chk.sit_valid_blocks = sum_vblocks;
 	fsck->chk.sit_free_segs = free_segs;
 
-	DBG(0, "Blocks [0x%x] Free Segs [0x%x]\n\n", sum_vblocks, free_segs);
+	DBG(1, "Blocks [0x%x : %d] Free Segs [0x%x : %d]\n\n", sum_vblocks, sum_vblocks,
+			free_segs, free_segs);
 	return 0;
 }
 
@@ -1031,7 +1039,7 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
 	}
 	free(nat_block);
 
-	DBG(0, "valid nat entries (block_addr != 0x0) [0x%8x : %u]\n",
+	DBG(1, "valid nat entries (block_addr != 0x0) [0x%8x : %u]\n",
 			fsck->chk.valid_nat_entry_cnt, fsck->chk.valid_nat_entry_cnt);
 
 }
Signature · 9 lines
1.7.10.4


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
#2 lore raw

PATCH 3/4 f2fs-tools: use either hex or decimal options

In reply to Changman Lee

This patch supports both hex and decimal when using nid as option.

---
 fsck/main.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fsck/main.c +8 -2
index d72533d..60bebc2 100644
@@ -76,7 +76,10 @@ void f2fs_parse_options(int argc, char *argv[])
 					MSG(0, "Info: Debug level = %d\n", config.dbg_lv);
 					break;
 				case 'i':
-					sscanf(optarg, "%x", &dump_opt.nid);
+					if (strncmp(optarg, "0x", 2))
+						sscanf(optarg, "%d", &dump_opt.nid);
+					else
+						sscanf(optarg, "%x", &dump_opt.nid);
 					break;
 				case 's':
 					sscanf(optarg, "%d~%d", &dump_opt.start_sit, &dump_opt.end_sit);
@@ -85,7 +88,10 @@ void f2fs_parse_options(int argc, char *argv[])
 					sscanf(optarg, "%d~%d", &dump_opt.start_ssa, &dump_opt.end_ssa);
 					break;
 				case 'b':
-					sscanf(optarg, "%d", &dump_opt.blk_addr);
+					if (strncmp(optarg, "0x", 2))
+						sscanf(optarg, "%d", &dump_opt.blk_addr);
+					else
+						sscanf(optarg, "%x", &dump_opt.blk_addr);
 					break;
 				default:
 					MSG(0, "\tError: Unknown option %c\n", option);
Signature · 9 lines
1.7.10.4


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
#3 lore raw

PATCH 4/4 f2fs-tools: add option to display directory tree

In reply to Changman Lee

This option shows directory tree of f2fs.

Usage: fsck.f2fs -t /dev/sdx

`-- p0
|-- f4
`-- d6

        |-- f5e
        |-- cb6
        |-- fdb
        |-- fe8
        `-- l9a
---
 fsck/fsck.c       |   53 +++++++++++++++++++++++++++++++++++++---
 fsck/main.c       |    5 +++-
 include/f2fs_fs.h |    3 ++-
 lib/libf2fs.c     |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+), 5 deletions(-)
fsck/fsck.c +50 -3
index b5619ba..2a4d064 100644
@@ -10,6 +10,9 @@
  */
 #include "fsck.h"
 
+char *tree_mark;
+int tree_mark_size = 256;
+
 static int add_into_hard_link_list(struct f2fs_sb_info *sbi, u32 nid, u32 link_cnt)
 {
 	struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
@@ -267,7 +270,7 @@ int fsck_chk_inode_blk(struct f2fs_sb_info *sbi,
 	u32 child_cnt = 0, child_files = 0;
 	enum NODE_TYPE ntype;
 	u32 i_links = le32_to_cpu(node_blk->i.i_links);
-	u64 i_blocks = le32_to_cpu(node_blk->i.i_blocks);
+	u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
 	int idx = 0;
 	int ret = 0;
 
@@ -409,7 +412,7 @@ int fsck_chk_dnode_blk(struct f2fs_sb_info *sbi,
 				le32_to_cpu(node_blk->dn.addr[idx]),
 				&child_cnt,
 				&child_files,
-				le32_to_cpu(inode->i_blocks == *blk_cnt),
+				le64_to_cpu(inode->i_blocks) == *blk_cnt,
 				ftype,
 				nid,
 				idx,
@@ -467,6 +470,45 @@ int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi,
 	return 0;
 }
 
+static void print_dentry(__u32 depth, __u8 *name,
+		struct f2fs_dentry_block *de_blk, int idx, int last_blk)
+{
+	int last_de = 0;
+	int next_idx = 0;
+	int name_len;
+	int i;
+	int bit_offset;
+
+	if (config.dbg_lv != -1)
+		return;
+
+	name_len = le16_to_cpu(de_blk->dentry[idx].name_len);
+	next_idx = idx + (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN;
+
+	bit_offset = find_next_bit((unsigned long *)de_blk->dentry_bitmap,
+			NR_DENTRY_IN_BLOCK, next_idx);
+	if (bit_offset >= NR_DENTRY_IN_BLOCK && last_blk)
+		last_de = 1;
+
+	if (tree_mark_size <= depth) {
+		tree_mark_size *= 2;
+		tree_mark = realloc(tree_mark, tree_mark_size);
+	}
+
+	if (last_de)
+		tree_mark[depth] = '`';
+	else
+		tree_mark[depth] = '|';
+
+	if (tree_mark[depth - 1] == '`')
+		tree_mark[depth - 1] = ' ';
+
+
+	for (i = 1; i < depth; i++)
+		printf("%c   ", tree_mark[i]);
+	printf("%c-- %s\n", last_de ? '`' : '|', name);
+}
+
 int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi,
 		struct f2fs_inode *inode,
 		u32 blk_addr,
@@ -484,7 +526,6 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi,
 	u16 name_len;;
 
 	enum FILE_TYPE ftype;
-
 	struct f2fs_dentry_block *de_blk;
 
 	de_blk = (struct f2fs_dentry_block *)calloc(BLOCK_SZ, 1);
@@ -527,6 +568,8 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi,
 				le32_to_cpu(de_blk->dentry[i].ino),
 				de_blk->dentry[i].file_type);
 
+		print_dentry(fsck->dentry_depth, name, de_blk, i, last_blk);
+
 		blk_cnt = 1;
 		ret = fsck_chk_node_blk(sbi,
 				NULL,
@@ -702,6 +745,7 @@ int fsck_init(struct f2fs_sb_info *sbi)
 
 	build_sit_area_bitmap(sbi);
 
+	tree_mark = calloc(tree_mark_size, 1);
 	return 0;
 }
 
@@ -801,4 +845,7 @@ void fsck_free(struct f2fs_sb_info *sbi)
 
 	if (fsck->sit_area_bitmap)
 		free(fsck->sit_area_bitmap);
+
+	if (tree_mark)
+		free(tree_mark);
 }
fsck/main.c +4 -1
index 60bebc2..80db15d 100644
@@ -42,7 +42,7 @@ void f2fs_parse_options(int argc, char *argv[])
 	char *prog = basename(argv[0]);
 
 	if (!strcmp("fsck.f2fs", prog)) {
-		const char *option_string = "d:";
+		const char *option_string = "d:t";
 
 		config.func = FSCK;
 		while ((option = getopt(argc, argv, option_string)) != EOF) {
@@ -51,6 +51,9 @@ void f2fs_parse_options(int argc, char *argv[])
 					config.dbg_lv = atoi(optarg);
 					MSG(0, "Info: Debug level = %d\n", config.dbg_lv);
 					break;
+				case 't':
+					config.dbg_lv = -1;
+					break;
 				default:
 					MSG(0, "\tError: Unknown option %c\n",option);
 					fsck_usage();
include/f2fs_fs.h +2 -1
index 2fdd283..d0fc79e 100644
@@ -185,7 +185,7 @@ struct f2fs_configuration {
 	void *private;
 } __attribute__((packed));
 
-#ifdef CONFIG_64BIT
+#ifndef CONFIG_64BIT
 #define BITS_PER_LONG	64
 #else
 #define BITS_PER_LONG	32
@@ -635,6 +635,7 @@ extern int test_bit(unsigned int nr, const void * addr);
 extern int f2fs_test_bit(unsigned int, const char *);
 extern int f2fs_set_bit(unsigned int, char *);
 extern int f2fs_clear_bit(unsigned int, char *);
+extern unsigned long find_next_bit(const unsigned long *, unsigned long, unsigned long);
 
 extern u_int32_t f2fs_cal_crc32(u_int32_t, void *, int);
 extern int f2fs_crc_valid(u_int32_t blk_crc, void *buf, int len);
lib/libf2fs.c +70 -0

76 lines not on this page · raw message

Signature · 9 lines
1.7.10.4


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk