Commit Graph

535 Commits

Author SHA1 Message Date
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
Jaegeuk Kim
f6eef57a69 fsck.f2fs: show superblock features and encryption info
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-04-23 17:36:21 -07:00
Jaegeuk Kim
65950fc736 fsck.f2fs: show ckeckpoint version info
This patch shows the valid checkpoint version number.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-04-10 10:36:06 -07:00
Jaegeuk Kim
1f65c1f61f fsck.f2fs: fix orphan inode's link count
This patch fixes orphan inode's link count as 0.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-31 20:32:12 -07:00
Jaegeuk Kim
f1e4f9c0e9 fsck.f2fs: fix missing dentries
If a directory has no dot and dotdot dentries, fsck.f2fs sets inline_dots for
the inode so that f2fs module can handle that properly.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-30 13:37:24 -07:00
Jaegeuk Kim
56b8930368 fsck.f2fs: clean up child information
This patch adds a child_info data structure to clean up dirty parameters.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-30 13:00:54 -07:00
Jaegeuk Kim
e358413d4c fsck.f2fs: fix missing i_links
If a child is a directory, we should increase parent's i_links.
Previously, it counts direct dentry blocks excluding indirect blocks.
This patch fixes to count child_cnt correctly in order to get precise i_links.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-30 12:27:40 -07:00
Jaegeuk Kim
4d60a126e1 fsck.f2fs: count child directories correctly for i_links
If some of children including directories are corrupted, we should not include
them into i_links of their parent.
This patch fixes that.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-30 10:40:17 -07:00
Jaegeuk Kim
22a8ae0a1f fsck.f2fs: fix corrupted dentries
This patch fixes corrupted dentries such as name_len == 0.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-27 16:34:48 -07:00
Jaegeuk Kim
562ec5aaf9 fsck.f2fs: fix summary block
Previously, if data and node summary was corrupted, the block was deallocated.
But, this patch fixes their summary first, so that we can keep their blocks.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-27 16:34:48 -07:00
Jaegeuk Kim
fce2ff183e fsck.f2fs: return summary block pointer and types
This patch adds to return summry_block pointer to callers, which will be used
when fixing them.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-27 16:34:48 -07:00
Jaegeuk Kim
4a3116409f fsck.f2fs: preserve orphan blocks
If fsck.f2fs found some orphan blocks, previously fsck.f2fs drops them and
fixes checkpoint, resulting in false alarm on corruption.
This patch preserves orphan blocks to avoid such the alarms.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-27 16:34:46 -07:00
Jaegeuk Kim
278863e9ee fsck.f2fs: skip block count fix when i_links is fixed
If i_links is wrong, we should not check block count, since it doesn't count
correctly which results in changing the block count to 1.

This patch fixes that.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-25 19:26:25 -07:00
Jaegeuk Kim
c0feedadd9 fsck.f2fs: fix inodes having wrong i_links
This patch fixes inodes which have wrong i_links.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-25 18:51:53 -07:00
Jaegeuk Kim
e17732608c fsck.f2fs: check file types
If the file type is mismatched, we should drop that inode.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-25 18:18:04 -07:00
Jaegeuk Kim
7d253ac582 fsck.f2fs: remove inconsistent named directories
Each inode has its filename inside inode block.
For directory, the name should be matched all the time.
In other cases, it shouldn't, since there is able to be linked to other file
names.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-25 17:50:06 -07:00
Jaegeuk Kim
a81e54404c fsck.f2fs: reduce redundant message
This assert message is unnecessary to be shown, since caller shows the reason
already.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-25 17:16:51 -07:00
Jaegeuk Kim
fea6162a6d fsck.f2fs: show total sectors consumed by filesystem
This patch shows the information about the number of total sectors composing
filesystem.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-20 17:07:48 -07:00
Jaegeuk Kim
7ba9eec293 fsck.f2fs: show cp_state for fsck.f2fs
This patch adds to show cp_state during fsck.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-20 17:01:41 -07:00
Anthony G. Basile
5792951de2 f2fs-tools: fix build system to make distcheck correctly
The current build system fails to `make distcheck` correctly
for two reasons: 1) Some header files are not listed in the
source files for fsck.f2fs and mkfs.f2fs, and so don't make it
into the dist tarball.  2) By setting a default prefix in
configure.ac, the mock install doesn't add the correct prefix
and instead tries to install directly to the file system.

This patch corrects those problems and also adds an autogen.sh
script for convenience.

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-03-08 20:23:13 -07:00
Jaegeuk Kim
e1f3c00695 fsck.f2fs: remove corrupted data indices in direct node blocks
Previously, only data blocks locating in its inode block could be fixed.
This patch investigates direct node blocks to fix indices too.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-02-24 19:12:46 -08:00
Chao Yu
37580f1c5b fsck.f2fs: support large sector size
Since f2fs support large sector size in commit 55cf9cb63f0e "f2fs: support large
sector size", block device with sector size of 512/1024/2048/4096 bytes can be
supported.

But fsck.f2fs still use default F2FS_LOG_SECTOR_SIZE/F2FS_LOG_SECTORS_PER_BLOCK to
verify related data in f2fs image, it's wrong, let's fix this issue in this patch.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-02-05 18:42:46 -08:00
Jaegeuk Kim
631f8166bb fsck.f2fs: readahead node blocks to speed up
This patch adds readahead system call to speed up node block reads.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-01-29 13:36:54 -08:00
Jaegeuk Kim
b57708aecf dump.f2fs: show checkpoint flag
This patch is to show the checkpoint flag.
With this flag, we can guess the last status of the partition.
And, this can be used by xfstests.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-01-29 13:36:45 -08:00
Jaegeuk Kim
6f7636528f fsck.f2fs: fix sit types seamlessly
SIT types can be wrong when active_logs are 2 or 4.
So, let's fix this implicitly.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-01-23 13:16:03 -08:00
Jaegeuk Kim
9c6617d06d dump.f2fs: dump owner of data given block address
This patch introduces a feature to dump owner information of given block
address.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-12-17 18:39:34 -08:00
Jaegeuk Kim
b76cced47e fsck.f2fs: no need to fix SIT type for COLD_DATA
If hot or warm data blocks were moved to the cold log, we should remain them
in the cold log.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-24 17:43:44 -08:00
Jaegeuk Kim
79c1870af2 fsck.f2fs: remove unused value
Remove build warning.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-13 21:00:39 -08:00
JP Abgrall
e7f175ad77 fsck.f2fs: add a missing 'fixed' during chk_dentries()
One of the cases would update the dentries but not set
fixed=1 causing the update to not be written out.

Change-Id: I111d599f93f7d5306dacd7d62da946fdb5c262ee
Signed-off-by: JP Abgrall <jpa@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-13 16:25:52 -08:00
Jaegeuk Kim
8f521d9172 fsck.f2fs: avoid false alarm on SIT type fix
This patch removed a false alarm when detecting any inconsistency in SIT types.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-13 13:31:52 -08:00
Jaegeuk Kim
025829b7cc fsck.f2fs: remove unneeded return
To show better output.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-08 22:33:49 -08:00
Jaegeuk Kim
ec53a83bcf fsck.f2fs: show orphan inodes when fixing partition
Let's show orphan inode information when fixing partition.
Otherwise, it causes a false alarm.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-08 22:28:42 -08:00
Jaegeuk Kim
762eedf87f mkfs.f2fs: give a kernel version for initial format
This is to identify when the format was done.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-07 13:36:48 -08:00
Jaegeuk Kim
6fa2547e04 fsck.f2fs: trigger fsck.f2fs when new change was made
This patch remains user specified triggering information in superblock.
Then, if the information was changed, fsck.f2fs is triggered.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-07 13:36:45 -08:00
Jaegeuk Kim
232ce7671e fsck.f2fs: fix SIT entry types
Sometimes, SIT entry type is broken, so we need to rebuild it.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-06 18:27:11 -08:00
JP Abgrall
9f87126aed fsck.f2fs: actually flag the fixed dentries as fixed
This is a followup from 056e4b04fc
Now the blk is marked as fixed so that the callers can write it back.

Change-Id: I99c94bc39e772e0d0baab81bd741ce55416ce0e6
Signed-off-by: JP Abgrall <jpa@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-11-03 18:28:29 -08:00
Jaegeuk Kim
4eeaff336d f2fs: use last_blk for print dentries
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-31 12:48:42 -07:00
Jaegeuk Kim
7279f0383c fsck.f2fs: fix DATA_EXIST flag for old partition
This should fix the DATA_EXIST before recent inline_data is enabled.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-31 12:08:40 -07:00
JP Abgrall
056e4b04fc fsck.f2fs: attempt to identify bad dentries
If a dentry has a bad ino (fsck_chk_nod_blk() fails)
and has a name len of 0, then __chk_dentries() will end up stuck:

....
[__chk_dentries: 663] [  4]-[0x0] name[] len[0x0] ino[0x5f1710dc] type[0xd1]
[ASSERT] (sanity_check_nid: 184)  --> nid is not valid. [0x5f1710dc]
[__chk_dentries: 663] [  4]-[0x0] name[] len[0x0] ino[0x5f1710dc] type[0xd1]
[ASSERT] (sanity_check_nid: 184)  --> nid is not valid. [0x5f1710dc]
[__chk_dentries: 663] [  4]-[0x0] name[] len[0x0] ino[0x5f1710dc] type[0xd1]
[ASSERT] (sanity_check_nid: 184)  --> nid is not valid. [0x5f1710dc]
....

This change tries to identify bad dentries:
 - is the ino a valid NID?
 - is the FILE_TYPE a happy type?

Change-Id: I5fb2f3869c96f2c928baaace148de1af102e558e
Signed-off-by: JP Abgrall <jpa@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-28 22:03:22 -07:00
Jaegeuk Kim
5007756839 fsck.f2fs: show inline status of inode
This patch adds to show inline status of each inode.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-18 23:56:04 -07:00
Jaegeuk Kim
2c6bb7900f fsck.f2fs: fix wrongly allocated 0'th block for inline_data
This patch fixes not to allocate any 0'th block for inline_data.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-18 23:56:00 -07:00
Jaegeuk Kim
30b0dfa1a1 fsck.f2fs: fix link count correctly
We should do *goto check* if there is something to fix.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-16 09:40:16 -07:00
Jaegeuk Kim
aafe2ca3dc fsck.f2fs: fix wrong hash_code made by previous buggy code
The previous f2fs remained wrong hash_code for international characters.
So, fsck.f2fs should fix that hash_code with current valid names.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-15 16:56:23 -07:00
Jaegeuk Kim
6d8864014f fsck.f2fs: support inline_dentry
This patch implements inline_dentry feature.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-14 15:31:19 -07:00
Jaegeuk Kim
1dd3bc0a17 fsck.f2fs: fix superblock offset
The second offset should be F2FS_BLKSIZE + F2FS_SUPER_OFFSET.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-09 14:58:40 -07:00
Jaegeuk Kim
59591e45c0 fsck.f2fs: fix wrong block addres of nids
This patch avoids assert when nid has wrong block address.
Let's fix this.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-10-07 15:26:48 -07:00
Jaegeuk Kim
cfeb015e88 f2fs: rearrange options to remove redundant check
This patch summarizes the usage of options.

-a : auto_fix, fix corruption, only if f2fs reported some potential errors
-f : force,    fix corruption entire partition
None : prompt, if fsck.f2fs detets any corruption

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-09-03 19:45:42 -07:00
Jaegeuk Kim
7eb6c5a03b fsck.f2fs: add auto_fix feature
This patch adds an auto_fix feature which fixes inconsistency of f2fs images.

E.g.,

With this option, -a, fsck.f2fs tries to fix inconsistency only if its valid
checkpoint has CP_FSCK_FLAG, written by previous bug_on cases.

So, normally it does fix nothing, so that there is no performance regression.
But, if a sort of corruption was reported by the f2fs module, this tries to
fix potential corrupted partition.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-09-02 18:23:11 -07:00
Jaegeuk Kim
a6a7ac8e9d fsck.f2fs: avoid build warnings
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-09-02 11:07:33 -07:00
Jaegeuk Kim
7d96d138a3 fsck.f2fs: remove list.h
Just use list_head only.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 17:15:09 -07:00
Jaegeuk Kim
a6b2870ddb 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>
2014-08-29 16:37:46 -07:00
Jaegeuk Kim
b700e313b4 fsck.f2fs: fix checkpoint
- fix nat entries
- fix sit entries
- fix checkpoint

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
1dc1edfbcb fsck.f2fs: handle correctly segment summary entries
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
1bc74e1eed fsck.f2fs: remove corrupted xattr block
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
a89223b220 fsck.f2fs: corrupted orphan inode will be removed
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
32edfeaac7 fsck.f2fs: remove dentry if its inode block is corrupted
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
48ffea7ba8 fsck.f2fs: add fixing messeages
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
634dfb1552 fsck.f2fs: fix inode block inconsistency
This patch is to fix inode block inconsistency such as iblocks and ilinks.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
48863d422e fsck.f2fs: give a chance to recover sit entries
This patch skips initial verfication on SIT entries, which checks the number of
valid blocks from its bitmap.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
1ce70c67e3 fsck.f2fs: cleanup mount.c
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
5cd7001f5d fsck.f2fs: handle error cases
Do sanity check first and then update metadata.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
2701c94ab0 fsck.f2fs: remove return value of get_node_info
We don't need to get the return value.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
7aafb1b5f4 fsck.f2fs: handle IS_VALID_BLK_ADDR
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
f6d1d582e9 fsck.f2fs: clean up codes
Fix wrong coding style.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:29 -07:00
Jaegeuk Kim
6f4106c12b fsck.f2fs: retry to fix corrupted image
This patch adds a facility to retry conducting fsck.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 13:43:27 -07:00
Jaegeuk Kim
f46078949b f2fs_dentry_hash: avoid casting unsigned char to singed char
This can hurt when calculating hash value, resulting in false alarm.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-29 10:52:19 -07:00
Jaegeuk Kim
347e94f4b2 fsck.f2fs: show inode numbers
fsck.f2fs -d 1 [dev]
 : shows inode informations
fsck.f2fs -d -1 [dev]
 : shows directory tree with inode number

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-26 17:30:18 -07:00
Jaegeuk Kim
6cd2c51c20 dump.f2fs: support dump_file from image
This patch adds supporting dump_file, which can extract a file from image.

You can simply select [yes|no] when doing dump.f2fs -i [inode number] [img].

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-08-26 17:30:15 -07:00
Mark Salyzyn
58edb106a8 f2fs-tools: 64-bit compile issue
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Change-Id: I9398b877571d3dabbcb29c87a67d59672ea7fbaa
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-07-03 09:27:47 -07:00
Jaegeuk Kim
0575dd1c56 libf2fs, fsck, mkfs: call f2fs_finalize_device before exit
The fsck tool should call f2fs_finalize_device before exit to close the device
file.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-06-13 17:06:02 +09:00
Changman Lee
4ea4f1db27 fsck.f2fs: large volume support
This patch support large volume over about 3TB.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
[Jaegeuk Kim: add missing cp_payload in f2fs_super_block]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2014-06-04 13:32:07 +09:00
JP Abgrall
a68ee58a5d Cleanup various build warnings (signed vs unsigned, unused vars,...)
* removed unused includes.
* removed unused parameters.
* Fixed a bunch of warnings around:
    int i;
    if (i < some_uint) ...
  and
    u32 x;
    ...
    if (x < 0) return error;
* Protect BLKDISCARD usage if it is not available.

Change-Id: Iede035b1beb2df01c961589a69aff47a5258ecd2
Signed-off-by: JP Abgrall <jpa@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2014-05-15 08:40:55 +09:00
Jaegeuk Kim
192d979c61 fsck: remove build warnings
This patch casts some variable types to remove build warnings.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2014-02-25 08:31:49 +09:00
Jaegeuk Kim
858c4039c8 mkfs, fsck: change the results for readability
This patch cleans up several printing formats.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2014-02-06 11:09:41 +09:00
Jaegeuk Kim
4f267323a2 f2fs-tools: resolve build warnings
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2014-01-20 17:42:21 +09:00
Changman Lee
e296161af0 f2fs-tools: move fsck/fibmap.f2fs to tools/
Let's move miscellaneous utilities into tools directory.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2014-01-16 17:29:13 +09:00
Jaegeuk Kim
1aae03594b fibmap: fix wrong block count
This is an obvious bug fix patch.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-12-27 12:57:51 +09:00
Huajun Li
061ee67915 f2fs-tools: add inline data check
Add inline data check

Signed-off-by: Weihong Xu <weihong.xu@intel.com>
Signed-off-by: Huajun Li <huajun.li@intel.com>
Signed-off-by: Haicheng Li <haicheng.li@linux.intel.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-12-16 12:42:43 +09:00
Jaegeuk Kim
f1d452af4a fsck: fix orphan node blocks
Previously, fsck handles only the orphan inode block excpet its indirect node
blocks.
This causes false-alarm, unreachable nat entries [xxx].
This patch fixes to cover indirect node blocks in an orphan inode.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-10-30 11:16:01 +09:00
Jaegeuk Kim
8e678b2edf fsck: fix checking orphan inodes
This patch fixes bugs in the orphan inode procedure.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-10-16 13:52:16 +09:00
Jaegeuk Kim
76a069430a fsck: fix to handle file types correctly
The file type is based on the number, not bit operations.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-10-08 19:17:22 +09:00
Jaegeuk Kim
78b795e05d fsck: skip to check block addresses in device files
The device files use i_addr or i_nid fields for their rdev numbers.
So, fsck should skip to check block addresses inside of them.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-10-08 18:17:33 +09:00
Jaegeuk Kim
cd1e4704d0 fsck, lib: support inline xattr
This patch adjusts the modification to handle inline xattrs.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-08-20 18:12:04 +09:00
Jaegeuk Kim
9455376cd0 fibmap.f2fs: change fibmap to fibmap.f2fs
The fibmap tool is for debugging f2fs especially.

CC: Changman Lee <cm224.lee@samsung.com>
CC: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-08-09 06:41:02 +09:00
Changman Lee
e23d58533c f2fs-tools: add stat information into fibmap
This patch shows stat information about a file with fragmented state.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-08-08 14:53:41 +09:00
Changman Lee
6e8f2d5d22 f2fs-tools: add debug message for checking xattr
This patch adds debug message to confirm xattr block is checked.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-08-07 18:21:24 +09:00
Jaegeuk Kim
2c877a862d libf2fs: check more conditions on mounted filesystem
In the case of lazy umount, "umount -l", some processes are able to use the
file system even if its mountpoint was disconnected.
At this moment, we should not allow mkfs.f2fs.
This patch adds this condition check.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-08-02 17:06:26 +09:00
Changman Lee
57baa23a32 f2fs-tools: add option to display directory tree
This option shows directory tree of f2fs.

Usage: fsck.f2fs -t /dev/sdx

`-- p0
   |-- f4
   `-- d6
        |-- f5e
        |-- cb6
        |-- fdb
        |-- fe8
        `-- l9a

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-30 17:06:44 +09:00
Changman Lee
932f9845f6 f2fs-tools: use either hex or decimal options
This patch supports both hex and decimal when using nid as option.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-30 17:06:44 +09:00
Changman Lee
223fdf3e00 f2fs-tools: cleanup debug statement
The debug message is too verbose therefore decrease message.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-30 17:06:44 +09:00
Changman Lee
c81ded6cf0 f2fs-tools: fix missing function declaration
Explicitly declare function name.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-30 17:06:44 +09:00
Changman Lee
dfe2a3384f f2fs-tools: add fibmap
This is to get physical location of file data.
We can check the percentage of fragmentation on a file.

Note that it uses fsync to get exact blkaddr.

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-22 21:52:03 +09:00
Changman Lee
8843554c8c dump: dump inode information from blkaddr
This patch is to dump inode which blkaddr belongs in.
Usage:
  dump.f2fs /dev/sdx -b blk_addr (in 4KB)

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-18 15:45:30 +09:00
Jaegeuk Kim
0307b93ce2 fsck: fix name search
The next name slots should be calculated by F2FS_SLOT_LEN not F2FS_NAME_LEN.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-18 09:19:54 +09:00
Changman Lee
7f35b548d4 f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
 o When data about used area and its metadata are identical,
   f2fs is considered consistent. To verify such consistency, we use
   three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
   First, each bit in nat_area_bitmap corresponds to a nid in NAT.
   Second, each bit in sit_area_bitmap corresponds to a valid block in a
   segment. This bitmap is same to the total valid_map of f2fs_sit_entries
   in SIT.
   Last, each bit in main_area_bitmap corresponds to a block in main area
   except meta area.
   After a consistency check of each block, we set or clear the
   corresponding bit of each bitmap.
   From the root node, we start consistency check. The verified
   information varies according to block type.
   1. NODE
     - Read information of node block from NAT
     - Check if block address is allocated using node info.
     - Check if the type of f2fs_summary related to nid in SSA is NODE.
     - Update the corresponding bit in nat_area_bitmap.
     - Update the corresponding bit in sit_area_bitmap.
     - Set the corresponding bit in main_area_bitmap to 1.
     - Then, read node block. According to its attribute, explore
       inode/direct node/indirect node/double indirect node
       recursively.
     - If it is an inode block, we also check its xattr and hard link.
   2. DATA
     - Check if the type of f2fs_summary related to nid in SSA is DATA.
     - Set the corresponding bits of sit_area_bitmap and
       main_area_bitmap to visited
     - If it is a dentry block, traverse each dentries that may be
       regular
       file or directory. At this time, it will check inode block again.
   Finally, we verify whether
     - every nat_area_bitmap is visited
     - any unreachable hard link exists
     - values of sit_area_bitmap and main_area_bitmap are identical
     - total_valid_block_count/node_count/inode_count are correct

Usage:
 o fsck.f2fs
   # fsck.f2fs /dev/sdx
   options:
     -d debug level [default:0]
 o dump.f2fs
   # dump.f2fs -i [ino] /dev/sdx
   # dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
   # dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
   options:
     -d debug level [default:0]
     -i inode no (hex)
     -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
     -a [SSA dump segno from #1~#2 (decimal), for all 0~-1]

Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs

Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 23:15:25 +09:00