Skip to contentSkip to conversation

mkfs.f2fs: avoid build warning

PATCH New Jaegeuk Kim 1 participant 4 messages Oct 16, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 mkfs.f2fs: avoid build warning

Avoid build warning for printf.

---
 mkfs/f2fs_format_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mkfs/f2fs_format_main.c +2 -1
index 19c52e4..e1f7c69 100644
@@ -103,7 +103,8 @@ static void f2fs_parse_options(int argc, char *argv[])
 	if ((optind + 1) < argc) {
 		/* We have a sector count. */
 		config.total_sectors = atoll(argv[optind+1]);
-		MSG(0, "\ttotal_sectors=%lu (%s bytes)\n", config.total_sectors, argv[optind+1]);
+		MSG(0, "\ttotal_sectors=%08"PRIx64" (%s bytes)\n",
+				config.total_sectors, argv[optind+1]);
 	}
 
 	config.reserved_segments  =
Signature · 9 lines
2.1.1


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
#1 lore raw

PATCH 2/4 fsck.f2fs: fix superblock offset

The second offset should be F2FS_BLKSIZE + F2FS_SUPER_OFFSET.

---
 fsck/mount.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fsck/mount.c +6 -1
index 415f977..8b39d37 100644
@@ -223,9 +223,14 @@ int sanity_check_raw_super(struct f2fs_super_block *raw_super)
 
 int validate_super_block(struct f2fs_sb_info *sbi, int block)
 {
-	u64 offset = (block + 1) * F2FS_SUPER_OFFSET;
+	u64 offset;
 	sbi->raw_super = malloc(sizeof(struct f2fs_super_block));
 
+	if (block == 0)
+		offset = F2FS_SUPER_OFFSET;
+	else
+		offset = F2FS_BLKSIZE + F2FS_SUPER_OFFSET;
+
 	if (dev_read(sbi->raw_super, offset, sizeof(struct f2fs_super_block)))
 		return -1;
 
Signature · 9 lines
2.1.1


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
#2 lore raw

PATCH 3/4 fsck.f2fs: support inline_dentry

In reply to Jaegeuk Kim

This patch implements inline_dentry feature.

---
 fsck/f2fs.h       |   5 +++
 fsck/fsck.c       | 123 ++++++++++++++++++++++++++++++++++++------------------
 fsck/fsck.h       |   2 +
 include/f2fs_fs.h |  20 +++++++++
 4 files changed, 109 insertions(+), 41 deletions(-)
fsck/f2fs.h +5 -0
index cdd61b8..47f785d 100644
@@ -191,6 +191,11 @@ static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
 	return (struct sit_info *)(SM_I(sbi)->sit_info);
 }
 
+static inline void *inline_data_addr(struct f2fs_node *node_blk)
+{
+	return (void *)&(node_blk->i.i_addr[1]);
+}
+
 static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
 {
 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
fsck/fsck.c +82 -41

197 lines not on this page · raw message

fsck/fsck.h +2 -0
index 64b9984..49d6d1d 100644
@@ -93,6 +93,8 @@ extern int fsck_chk_didnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
 extern int fsck_chk_data_blk(struct f2fs_sb_info *sbi, u32, u32 *, u32 *,
 		int, enum FILE_TYPE, u32, u16, u8);
 extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, u32, u32 *, u32 *, int);
+int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
+		u32 *, u32 *);
 
 extern void print_node_info(struct f2fs_node *);
 extern void print_inode_info(struct f2fs_inode *);
include/f2fs_fs.h +20 -0
index df37cdf..ed4abb1 100644
@@ -425,6 +425,8 @@ struct f2fs_extent {
 
 #define F2FS_INLINE_XATTR	0x01	/* file inline xattr flag */
 #define F2FS_INLINE_DATA	0x02	/* file inline data flag */
+#define F2FS_INLINE_DENTRY	0x04	/* file inline dentry flag */
+
 #define MAX_INLINE_DATA		(sizeof(__le32) * (DEF_ADDRS_PER_INODE - \
 						F2FS_INLINE_XATTR_ADDRS - 1))
 
@@ -697,6 +699,24 @@ struct f2fs_dentry_block {
 	__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
 } __attribute__((packed));
 
+/* for inline dir */
+#define NR_INLINE_DENTRY	(MAX_INLINE_DATA * BITS_PER_BYTE / \
+				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
+				BITS_PER_BYTE + 1))
+#define INLINE_DENTRY_BITMAP_SIZE	((NR_INLINE_DENTRY + \
+					BITS_PER_BYTE - 1) / BITS_PER_BYTE)
+#define INLINE_RESERVED_SIZE	(MAX_INLINE_DATA - \
+				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
+				NR_INLINE_DENTRY + INLINE_DENTRY_BITMAP_SIZE))
+
+/* inline directory entry structure */
+struct f2fs_inline_dentry {
+	__u8 dentry_bitmap[INLINE_DENTRY_BITMAP_SIZE];
+	__u8 reserved[INLINE_RESERVED_SIZE];
+	struct f2fs_dir_entry dentry[NR_INLINE_DENTRY];
+	__u8 filename[NR_INLINE_DENTRY][F2FS_SLOT_LEN];
+} __packed;
+
 /* file types used in inode_info->flags */
 enum FILE_TYPE {
 	F2FS_FT_UNKNOWN,
Signature · 9 lines
2.1.1


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
#3 lore raw

PATCH 4/4 fsck.f2fs: fix wrong hash_code made by previous buggy code

In reply to Jaegeuk Kim

The previous f2fs remained wrong hash_code for international characters. So, fsck.f2fs should fix that hash_code with current valid names.

---
 fsck/fsck.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)
fsck/fsck.c +27 -5
index 8e3ecc8..9997d0c 100644
@@ -401,6 +401,10 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 		DBG(3, "ino[0x%x] has inline dentry!\n", nid);
 		ret = fsck_chk_inline_dentries(sbi, node_blk,
 					&child_cnt, &child_files);
+		if (ret < 0) {
+			/* should fix this bug all the time */
+			need_fix = 1;
+		}
 		goto check;
 	}
 
@@ -607,6 +611,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, u32 *child_cnt,
 	u32 hash_code;
 	u16 name_len;;
 	int ret = 0;
+	int fixed = 0;
 	int i;
 
 	for (i = 0; i < max;) {
@@ -621,7 +626,12 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, u32 *child_cnt,
 		hash_code = f2fs_dentry_hash((const unsigned char *)name,
 								name_len);
 
-		ASSERT(le32_to_cpu(dentry[i].hash_code) == hash_code);
+		/* fix hash_code made by old buggy code */
+		if (le32_to_cpu(dentry[i].hash_code) != hash_code) {
+			dentry[i].hash_code = hash_code;
+			fixed = 1;
+			FIX_MSG("hash_code[%d] of %s", i, name);
+		}
 
 		ftype = dentry[i].file_type;
 
@@ -670,7 +680,7 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, u32 *child_cnt,
 		*child_files = *child_files + 1;
 		free(name);
 	}
-	return dentries;
+	return fixed ? -1 : dentries;
 }
 
 int fsck_chk_inline_dentries(struct f2fs_sb_info *sbi,
@@ -688,12 +698,17 @@ int fsck_chk_inline_dentries(struct f2fs_sb_info *sbi,
 			(unsigned long *)de_blk->dentry_bitmap,
 			de_blk->dentry, de_blk->filename,
 			NR_INLINE_DENTRY, 1);
-	DBG(1, "[%3d] Inline Dentry Block Done : "
+	if (dentries < 0) {
+		DBG(1, "[%3d] Inline Dentry Block Fixed hash_codes\n\n",
+			fsck->dentry_depth);
+	} else {
+		DBG(1, "[%3d] Inline Dentry Block Done : "
 				"dentries:%d in %d slots (len:%d)\n\n",
 			fsck->dentry_depth, dentries,
 			(int)NR_INLINE_DENTRY, F2FS_NAME_LEN);
+	}
 	fsck->dentry_depth--;
-	return 0;
+	return dentries;
 }
 
 int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
@@ -715,10 +730,17 @@ int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
 			de_blk->dentry, de_blk->filename,
 			NR_DENTRY_IN_BLOCK, last_blk);
 
-	DBG(1, "[%3d] Dentry Block [0x%x] Done : "
+	if (dentries < 0) {
+		ret = dev_write_block(de_blk, blk_addr);
+		ASSERT(ret >= 0);
+		DBG(1, "[%3d] Dentry Block [0x%x] Fixed hash_codes\n\n",
+			fsck->dentry_depth, blk_addr);
+	} else {
+		DBG(1, "[%3d] Dentry Block [0x%x] Done : "
 				"dentries:%d in %d slots (len:%d)\n\n",
 			fsck->dentry_depth, blk_addr, dentries,
 			NR_DENTRY_IN_BLOCK, F2FS_NAME_LEN);
+	}
 	fsck->dentry_depth--;
 	free(de_blk);
 	return 0;
Signature · 9 lines
2.1.1


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho