aboutsummaryrefslogtreecommitdiff
path: root/fsck/f2fs.h
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2014-08-28 16:55:45 -0700
committerJaegeuk Kim <jaegeuk@kernel.org>2014-08-29 16:37:46 -0700
commita6b2870ddb760ab2e2f662db0c09f220d02c6d9e (patch)
tree9056660ef37f7d2a746007e36c625a125148ebe6 /fsck/f2fs.h
parentb700e313b4ad390fce7f610c51d0bb2dc52661bb (diff)
downloadf2fs-tools-a6b2870ddb760ab2e2f662db0c09f220d02c6d9e.tar.gz
fsck.f2fs: check next block is free or not
If block allocation is made to the next block offset, we should drop that block. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fsck/f2fs.h')
-rw-r--r--fsck/f2fs.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index 8c31981..f674ede 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -266,10 +266,15 @@ static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
#define GET_SEGNO_FROM_SEG0(sbi, blk_addr) \
(GET_SEGOFF_FROM_SEG0(sbi, blk_addr) >> sbi->log_blocks_per_seg)
-#define FREE_I_START_SEGNO(sbi) GET_SEGNO_FROM_SEG0(sbi, SM_I(sbi)->main_blkaddr)
+#define GET_BLKOFF_FROM_SEG0(sbi, blk_addr) \
+ (GET_SEGOFF_FROM_SEG0(sbi, blk_addr) & (sbi->blocks_per_seg - 1))
+
+#define FREE_I_START_SEGNO(sbi) \
+ GET_SEGNO_FROM_SEG0(sbi, SM_I(sbi)->main_blkaddr)
#define GET_R2L_SEGNO(sbi, segno) (segno + FREE_I_START_SEGNO(sbi))
-#define START_BLOCK(sbi, segno) (SM_I(sbi)->main_blkaddr + (segno << sbi->log_blocks_per_seg))
+#define START_BLOCK(sbi, segno) (SM_I(sbi)->main_blkaddr + \
+ (segno << sbi->log_blocks_per_seg))
static inline struct curseg_info *CURSEG_I(struct f2fs_sb_info *sbi, int type)
{
@@ -311,6 +316,8 @@ static inline bool IS_VALID_NID(struct f2fs_sb_info *sbi, u32 nid)
static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
{
+ int i;
+
if (addr >= F2FS_RAW_SUPER(sbi)->block_count ||
addr < SM_I(sbi)->main_blkaddr) {
DBG(0, "block addr [0x%x]\n", addr);
@@ -318,6 +325,14 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info *sbi, u32 addr)
ASSERT(addr >= SM_I(sbi)->main_blkaddr);
return 0;
}
+
+ for (i = 0; i < NO_CHECK_TYPE; i++) {
+ struct curseg_info *curseg = CURSEG_I(sbi, i);
+
+ if (START_BLOCK(sbi, curseg->segno) +
+ curseg->next_blkoff == addr)
+ return 0;
+ }
return 1;
}