Commit Graph

144 Commits

Author SHA1 Message Date
Sheng Yong
bc28669d6b fsck.f2fs: count the number of inodes during building nat_area_bitmap
The nid and ino of an inode are the same. So during building
nat_area_bitmap, we can know which nat entry represents an
inode, thus, we can count the number of inodes.

Then in fsck_chk_meta, the amount of inodes can be compared
with that recorded in CP.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-22 14:10:00 -07:00
Sheng Yong
6e225697bd fsck.f2fs: introduce -p option to check meta
This patch introduces a new option '-p' to do more checks on NAT/SIT areas.
'-p' has 2 levels: level 1 has the same sematics as '-a'; level 2 checks
NAT/SIT counters to see if they matches the status in SB and CP.

A new function, fsck_chk_meta, is called by '-p 1' to implement these
comparsion. If errors are detected, fix_on is set, which means fsck will
do a 'fsck -f' immediately.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-22 14:10:00 -07:00
Junling Zheng
890e4e0c59 fsck.f2fs: calculate orphan_blkaddr correctly
Commit 4ea4f1db ("fsck.f2fs: large volume support") added the support
for large volume over about 3TB. The "cp_payload" is added to start_blk,
but not removed from orphan_blkaddr.

Fixes: 4ea4f1db ("fsck.f2fs: large volume support")
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-17 16:31:52 -07:00
Chao Yu
2a802319c3 fsck.f2fs: refactor extent info verification flow
There are some issues in original approach:
- memory allocated in i_extent.map will leak
- do not convert fields in i_ext from on-disk format to cpu format
- do not support checking file offset with extent info

This patch refactors the flow for fixing above issues and supporting
file offset check.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-16 12:49:34 -07:00
Chao Yu
c8327c909f fsck.f2fs: check dirent position
This patch enables fsck.f2fs to detect incorrect position where dirent
locates in an hierarchical hash structure directory.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-16 12:46:58 -07:00
Sheng Yong
323c8c8238 fsck.f2fs: check nat_entry->ino for all nodes
Commit 843f5b9388 ("fsck.f2fs: check ino of an inode") checks
nat_entry->ino for inode. However, the checking is irrelevant to node
type, and if ino of other kinds of nodes gets corrupted, fsck.f2fs
cannot detect it. This patch fixes the commit.

Fixes: 843f5b9388 ("fsck.f2fs: check ino of an inode")
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-14 09:26:53 -07:00
Chao Yu
f102ca4c3f f2fs-tools: rebase struct f2fs_summary_block with upstream
Struct f2fs_summary_block has been changed in upstream commits:
 - commit 8f1dbbbbdfe9 ("f2fs: introduce lifetime write IO statistics")
 - commit dfc08a12e49a ("f2fs: introduce f2fs_journal struct to wrap journal info")

This patch does the sync work for f2fs_summary_block structure between
f2fs-utils and f2fs kernel module.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-14 09:26:53 -07:00
Junling Zheng
9b09631c8f fsck.f2fs: fix incorrect block_addr of node/meta
Fix incorrect block_addr of node or meta inode into 0x1 during
build_nat_area_bitmap().

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Liu Xue <liuxueliu.liu@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-07 15:36:27 -08:00
Junling Zheng
bc6f686893 fsck.f2fs: calculate the total size correctly
Correctly calculate the total FS size in init_sb_info(), for sector
size may not be 512 bytes.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-29 09:20:54 -08:00
Liu Xue
22778016fb fsck.f2fs: check valid values for dot dentries
Check valid values for '.' and '..', such as ino, hash_code, and the
number of dot or dotdot in the directory.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Yong Sheng <shengyong1@huawei.com>
Reviewed-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-29 09:18:41 -08:00
Sheng Yong
c00fe85bc7 fsck.f2fs: fix corrupted nat entry [0]
The first nat entry must be null. If it is corrupted, we set its bit in
nat_area_bitmap, without increasing valid_nat_entry_cnt, fsck_verify will
nullify it at last.

Reported-by: Cheng Yinchao <chengyinchao@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-24 09:56:54 -08:00
Sheng Yong
c6e8a6bdc4 fsck.f2fs: remove corrupted nid entry from indirect/double-indirect node
For indirect/double-indirect node, if the blk_addr in its nat entry is
corrupted, fsck could figure this out and nullify the nat entry. However,
the indirect/double-indirect node still keeps the corrupted nid. As a
result, fsck reports valid blkaddr but fixes nothing each time during
scanning all nodes, like:

=============================
[ASSERT] (sanity_check_nid: 356)  --> blkaddres is not valid. [0x0]
delete in.nid[i] = 0;
[ASSERT] (sanity_check_nid: 356)  --> blkaddres is not valid. [0x0]
delete in.nid[i] = 0;

[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x0]
[FSCK] valid_block_count matching with CP             [Ok..] [0xa51b]
[FSCK] valid_node_count matcing with CP (de lookup)   [Ok..] [0x98]
[FSCK] valid_node_count matcing with CP (nat lookup)  [Ok..] [0x98]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x7b]
[FSCK] free segment_count matched with CP             [Ok..] [0x1a]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]
=============================

So let's clean it.

Reported-by: Chen Yinchao <chengyinchao@huawei.com>
Signed-off-by: Liu Xue <liuxueliu.liu@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-22 09:22:19 -08:00
Jaegeuk Kim
f8bc97b333 fsck.f2fs: show encrypted filenames matched with kernel
This patch follows the kernel's encrypted name resolution.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-15 15:46:10 -08:00
Sheng Yong
843f5b9388 fsck.f2fs: check ino of an inode
If the node is an inode, its ino in the nat entry should be equal to the
ino in its node footer. Otherwise, we drop the file.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-01 16:28:25 -08:00
Sheng Yong
a9cd90e531 fsck.f2fs: check ino of an used nat entry
If a nid is valid, the ino in its nat entry should record its parent nid.
However if the ino is zero, we should drop the node.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-01 16:28:15 -08:00
Yunlei He
d9a6b189a9 fsck.f2fs: avoid fix ssa in some case
In some case, we need confirm node or data blkaddr is ok at first,
and then fix the conflict in ssa block. If the node blkaddr happen to
locate in data type segment caused by something error, may be we 'd
better ignore it, and it's same with data blkaddr.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-01 16:05:36 -08:00
Jaegeuk Kim
e92fd42618 fsck.f2fs: nullify raw_super pointer
Otherwise it will cause double free.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-21 21:13:56 +08:00
Jaegeuk Kim
bbc4176aa7 fsck.f2fs: return 0 for no error was reported
When skipping fsck, return 0 with message.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-14 20:44:13 -08:00
Jaegeuk Kim
231fc70f6e fsck.f2fs: assign checkpoint pointer correctly
This patch fixes a bug that cp pointer is not assigned correctly.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-14 20:36:20 -08:00
Sheng Yong
b9eb1dc383 fsck.f2fs: swap checkpoint crc to CPU endian
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-14 15:57:06 -08:00
Jaegeuk Kim
25b2e75312 f2fs-tools: avoid failure and warnings for android build
This patch fixes to resolve build failure and warnings when compiling it
under AOSP.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-13 17:18:22 -08:00
Sheng Yong
2d3ea141cc fsck.f2fs: fix double free invalid checkpoint
The invalid checkpoin is freed in validate_checkpoint().

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-28 14:33:12 -08:00
Jaegeuk Kim
a828ebb234 fsck.f2fs: fix losing journal entries
If fsck.f2fs reports a bug, move_curseg_info tries to change the current
segment info.
When it changes the new summary block, it overwrites the existing journal
entries.
This patch fixes it not to overwrite journal entry space.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-19 23:42:31 -08:00
Jaegeuk Kim
767a93ea8b defrag.f2fs: fix missing SSA updates
Previously SSA is updated if it is not included in current segment info.
But, defrag.f2fs doesn't handle current segment info during the process, and
instead lastly update the whole current segment info at a time.
So, we need to update summary entries all the time.
Otherwise, we can lose the SSA entry.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-19 03:27:12 -08:00
Jaegeuk Kim
f66104cf3a defrag.f2fs: enhance allocation speed
This patch improves the allocation speed.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-19 03:27:11 -08:00
Jaegeuk Kim
d6147940b9 defrag.f2fs: return error if there is no space
This patch checks whether there is a space or not to allocate new blocks.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-16 18:54:22 -08:00
Jaegeuk Kim
17acba6d3d defrag.f2fs: eliminate unexpected journal entries
When moving data or node blocks, it changes current segment information
dynamtically. Meanwhile, its journal entry space is recovered by old
stale data.
This patch makes sure that its journal space is zeroed out.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-16 17:46:32 -08:00
Jaegeuk Kim
552d6a8f4b defrag.f2fs: fix not to allocate current segment
This patch fixes allocating wrong segment which has zero data but is registered
as a current segment.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-15 18:14:48 -08:00
Jaegeuk Kim
b008605e99 lib: use u8/u32/u64 for bit operations
This cleans up the bit operations.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-15 11:15:00 -08:00
Jaegeuk Kim
ee65f6ebf2 lib: fix test_bit_le functions
This patch fixes test_bit_le functions for dentry bit operations.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-15 10:40:37 -08:00
Jaegeuk Kim
9e5c021b67 mkfs.f2fs: fix storing volume label correctly in utf16
This patch fixes to store volume label as utf16 correctly.

Many conversion codes are copied from exfat-tools.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-14 16:35:39 -08:00
Liu Xue
0ff98a3679 fsck.f2fs: deal with realloc size and realloc failure
Deal with realloc failure to avoid memory leak and memory free,
and assert realloc size to avoid double free for tree_mark.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-14 10:11:48 -08:00
Jaegeuk Kim
25e7128efa Revert "fsck.f2fs: deal with realloc failure"
This reverts commit 43095ca4c2.
2015-12-14 10:11:48 -08:00
Jaegeuk Kim
2c1ebe237a defrag.f2fs: introduce defragmentation tool
This tool tries to move the valid blocks ranging from blkaddr to blkaddr + len
to targeted blkaddr with a direction like expand or shrink.

The option includes:
 -d debug level [default:0]
 -s start block address [default: main_blkaddr]
 -l length [default:512 (2MB)]
 -t target block address [default: main_blkaddr + 2MB]
 -i set direction as shrink [default: expand]

For example,
 # defrag.f2fs -s 0x100 -l 0x10 -t 0x4000 /dev/sdb1

This will move data blocks between 0x100 and 0x110 to the right side of
0x4000 space.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-11 15:58:50 -08:00
Jaegeuk Kim
003b102d8a fsck.f2fs: LFS alloc_type must have free segment after blkoff
This patch checks alloc_type of current segment type.
If it is LFS, the last of segment should have no valid block.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-11 15:57:51 -08:00
Jaegeuk Kim
1a35b5e29d f2fs-tools: export print_raw_sb_info
This patch exports print_raw_sb_info().

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-10 19:46:28 -08:00
Jaegeuk Kim
c605c5eb4c fsck.f2fs: sanity_check for extent_cache entry
This patch adds to check the stored extent_cache entry is consistent or not.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-10 19:46:28 -08:00
Jaegeuk Kim
1ea31c47f4 libf2fs: enhance the bit operations
This patch modifies the existing bit operations.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-10 19:46:22 -08:00
Jaegeuk Kim
0e0b9f2844 fsck.f2fs: use get_{sb|cp} and set_{sb|cp} macros
We can use get_cp, set_cp, get_sb, and set_sb in fsck.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-02 21:36:03 -08:00
Liu Xue
43095ca4c2 fsck.f2fs: deal with realloc failure
Deal with realloc failure to avoid memory leak and memory free.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-02 13:35:46 -08:00
Jaegeuk Kim
67de42f76a fsck.f2fs: support a readonly filesystem
If f2fs is mounted as ro, we can do fsck.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-11-22 11:26:52 +08:00
Jaegeuk Kim
ee48fd2ced fsck.f2fs: declare static function
This avoids the following warning.

mount.c:783:27: warning: SM_I is static but used in inline function
check_seg_range which is not static.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-11-22 11:26:52 +08:00
Jaegeuk Kim
5489249c23 fsck.f2fs: support a preen mode
Generic fsck uses -p, preen mode, and fsck.f2fs can support it as -a for now.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-10-23 14:03:29 -07:00
Jaegeuk Kim
e8766f2887 fsck.f2fs: check sit types for node or data only
Previously, check_sit_types didn't handle different numbers of active logs and
SSR cases. But, it didn't cause any problem since fixing sit types is harmless.
Nevertheless, we still don't need to change them all.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-09-24 09:52:14 -07:00
Yunlei He
e9f8ae8b3e fsck.f2fs: add segment type in sit_dump
Add segment type information in sit_dump:

	[sit_dump:  48] SIT[0x12905] : 0x  1 : 0
	[sit_dump:  48] SIT[0x12906] : 0x  1 : 5
	[sit_dump:  48] SIT[0x12907] : 0x  7 : 4
	[sit_dump:  48] SIT[0x12908] : 0x  1 : 3

The last column output message on behalf of segment type like
CURSEG_XXX_TYPE.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-07-16 13:39:55 -07:00
Jaegeuk Kim
ca1436eeef fsck.f2fs: drop extent_info to avoid potential wrong access
This patch avoids wrong extent information modified by fixing block addresses.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-07-01 18:54:00 -07:00
Jaegeuk Kim
7ac070116b fsck.f2fs: select to update the latest valid summary
If two dnode blocks indicate one block address, it needs to keep the latest
valid address selectively.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-07-01 18:53:58 -07:00
Jaegeuk Kim
d24f1bb16d fsck.f2fs: add hash conversion for encrypted dentries
If dentry is encrypted, we should convert its hash value.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-05-07 15:50:49 -07:00
Jaegeuk Kim
641d98f26d fsck.f2fs: avoid build warning
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-05-07 15:48:18 -07:00
Jaegeuk Kim
4476615d26 dump.f2fs: show i_advise field in inode
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-04-23 18:40:52 -07:00