Commit Graph

535 Commits

Author SHA1 Message Date
Chao Yu
65f453160f f2fs-tools: fix to check return value of {c,m}alloc()
It needs to fix to handle error case of {c,m}alloc().

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-26 16:09:40 -08:00
taebum81.kim
946d8f4583 sload.f2fs: fix memory leak
Dynamic memory stored in 'xattr_node' allocated through function 'calloc'
at line 98 can be lost at line 111
Dynamic memory stored in 'inode' allocated through function 'calloc'
at line 144 can be lost at line 227

Signed-off-by: taebum81.kim <taebum81.kim@lge.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Randall Huang
0057a8c5c2 fsck.f2fs: do not hard-code encrypted filename length to avoid heap buffer overflow
If the len is less than 24, heap buffer overflow is reported.

Signed-off-by: Randall Huang <huangrandall@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Jaegeuk Kim
83c64019e8 fsck.f2fs: don't allocate new blocks on unclean shutdown
We have to keep data for roll-forward recovery. Without this patch, we're
able to lose there-in data by quota overwrites.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Chao Yu
dfede78aa9 fsck.f2fs: detect and recover corrupted quota file
Once quota file is corrupted, kernel will set CP_QUOTA_NEED_FSCK_FLAG
into checkpoint pack, this patch makes fsck supporting to detect the flag
and try to rebuild corrupted quota file.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
2018-11-21 11:38:23 -08:00
Chao Yu
7aab50d895 fsck.f2fs: try to recover cp_payload from valid cp pack
If sb checksum is not enabled, and cp pack is valid due to no
crc inconsistence, let's try to recover cp_payload based on
cp_pack_start_sum in cp pack.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Junling Zheng
886a924bfa f2fs-tools: introduce sb checksum
This patch introduced crc for superblock.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Junling Zheng
238fa8ccf1 fsck.f2fs: unify the updating of superblocks
Rename write_superblock() to update_superblock() and make it support updating
specified one superblock or both two superblocks, then unify all places where
sb needs to be updated.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Daniel Rosenberg
1ccd8313ba WIP: Add partial shrinking support to f2fs
allow 'safe' resizing leaving the metadata nearly unchanged.

Will likely need to adjust growing for the case where a fs
had previously shrunk without altering data, and the newly grown
fs would be smaller than the original. Probably makes sense to
case it out into metadata size changes, instead of fs size changes

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-11-21 11:38:23 -08:00
Chao Yu
38e47ce596 dump.f2fs: allow dump data on mounted image
xfstests assumes it's allow to dump data on mounted image, for example,
some common functions call dumpe2fs on mounted ext[2|3|4] image to check
feature lists. To adapt such requirement, let's follow that rule in
dump.f2fs.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Jaegeuk Kim
a48bda057a fsck.f2fs: support checkpoint=disable
This patch shows checkpoint is disabled and keeps the flag for next mount.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Junling Zheng
a6cbb57192 f2fs-tools: rename CHECKSUM_OFFSET to CP_CHKSUM_OFFSET
This patch renamed CHECKSUM_OFFSET to CP_CHKSUM_OFFSET.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-11-21 11:38:23 -08:00
Junling Zheng
767ac306c8 fsck.f2fs: supply more check entries for checkpoint
Supply some more check entries for checkpoint in sanity_check_ckpt()
and validate_checkpoint() to sync them with kernel.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:52:39 -07:00
Chao Yu
1ab72dec87 fsck.f2fs: print node block address
Print block address of unreachable node id in fsck_verify() for better
debugging.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:52:39 -07:00
Chao Yu
91bb7b21f7 f2fs-tools: fix to reset i_gc_failures offline
This patch synchronize f2fs_inode structure from kernel side, in
addition, it adds to check .i_gc_failures and do resetting in fsck.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:52:39 -07:00
Sheng Yong
d31e1a0d52 f2fs-tools: set namelen parameter of convert_encrypted_name as unsigned
To avoid overflow, set namelen parameter of convert_encrypted_name as
unsigned int. convert_encrypted_name() will check if namelen exceeds the
limitation.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Sheng Yong
e64292caeb fsck.f2fs: init quota_file before re-create quota file
`quota_handle->qh_qf->filesize' is not initialized by quota_create_file().
It contains random value, which is updated to quota file's i_size in
quota_file_close(). Since quota file is re-created, `filesize' can be
initialized as 0.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Chao Yu
ee0cb1c45e fsck.f2fs: fix to do sanity check with extra_attr feature
This patch tries to fix incorrect extra_attr bit or i_extra_isize value
in fsck.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Sheng Yong
356f8627c4 fsck.f2fs: check extent of inline data/dentry inode
Check extent for inline data/dentry inode. If an inode contains inline
data/dentry, it should have no extent.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=200175
Reported-by: Wen Xu <wen.xu@gatech.edu>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Junling Zheng
ddb87f568f dump.f2fs: only dump nat inside the specified nid range
Only dump nat info of nids inside the specified range.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Yunlei He
ffd0179558 fsck.f2fs: fix wrong err message of check quota node
This patch fix wrong err message of check quota node.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Sheng Yong
e2819f24bd f2fs-tools: do not count free_segs in flush_sit_entries
flush_sit_entries() is always called before write_checkpoint(). Since
free_segs is counted in write_checkpoint, there is no need to do that
in flush_sit_entries. Besides, the value of free_segs may be not
correct if we skip uptodate seg_entries.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Sheng Yong
df8065e529 fsck.f2fs: introduce fsck_chk_curseg_info
If curseg is an empty segment, it will not be checked. This patch
introduces fsck_chk_curseg_info() to check SIT/SSA type of cursegs
to avoid curseg corruption.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Sheng Yong
ed1063104d sload.f2fs: update sit entries of cursegs
move_curseg_info->reset_curseg changes cursegs, however, new segment
entries are not set as dirty. As a result, flush_sit_entries will not
update entries in SIT, especially when an empty segment is selected
as the new curseg, its seg_entry->type is lost.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Chao Yu
4a67f25191 fsck.f2fs: show missing large_nat_bitmap flag in print_ckpt_info
Previously, we forget to print large_nat_bitmap according to CP flag,
fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Junling Zheng
cacd1bd102 fsck.f2fs: do not print content beyond sb->version
Currently, versions in f2fs_configuration have one more byte than
those in sb, so versions in sb may not end with '\0', and then
print_raw_sb_info() will print something beyond sb->version.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Sheng Yong
25b71b53ed resize.f2fs: skip cursegs when finding next free block
resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
However, if a curseg is selected, and f2fs_defragment is broken by any
error, curseg->next_blkoff is left not updated.

To avoid this, we skip cursegs when finding next free block.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Yunlong Song
9c6cec2c10 f2fs-tools: fix overflow bug of start_sector when computing zone_align_start_offset
zone_align_start_offset should be u64, but config.start_sector is u32,
so it may be overflow when computing zone_align_start_offset.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Yunlong Song
baf9acd2c4 f2fs-tools: fix to match with the start_sector
f2fs-tools uses ioctl BLKSSZGET to get sector_size, however, this ioctl
will return a value which may be larger than 512 (according to the value
of q->limits.logical_block_size), then this will be inconsistent with
the start_sector, since start_sector is got from ioctl HDIO_GETGEO and
is always in 512 size unit for a sector. To fix this problem, just
change the sector_size to the default value when computing with
start_sector. And fix sectors_per_blk as well.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-08-27 23:49:26 -07:00
Chao Yu
6466b7578a fsck.f2fs: fix to avoid accessing invalid memory address
This patch adds to check return value of calloc in write_superblock().

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-07-13 22:46:00 -07:00
Jaegeuk Kim
689fd9b885 fsck.f2fs: add -O features to tune the bits
This patch add -O features for fsck.f2fs in order to tune the feature bits.
Currently, it supports -O encrypt only.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-07-13 22:46:00 -07:00
Jaegeuk Kim
1772e31423 f2fs-tools: add -g to give default options
This patch adds -g option to set default options for specific environment.
I added it for android as a example.

 # mkfs.f2fs -g android $dev
  : gives "-d1 -f -O encrypt -O quota -w 4096"

 # fsck.f2fs -g android $dev
  : gives "-a"

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-07-13 22:46:00 -07:00
Sheng Yong
8feed81aa9 f2fs-tools: introduce new option V to show version
This patch introduces a new option -V to show the version of f2fs tools
and exit after that.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-07-13 22:46:00 -07:00
Sheng Yong
cc31eb7aba resize.f2fs: clear CP_COMPACT_SUM_FLAG when rebuilding checkpoint
Resize rebuilds checkpoint with 6 summary blocks, so if
CP_COMPACT_SUM_FLAG is set in the old checkpoint, clear it.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-07-13 22:46:00 -07:00
Jaegeuk Kim
1c15c8d551 resize.f2fs: fix wrong nat_bits migration
When wring the last nat_bits in new checkpoint, we call write_nat_bits()
to recover the nat_bits. But, we didn't update nm_i->nat_bitmap which we can
get the up-to-date nat blocks. After sit migration, old checkpoint has no
longer valid nat blocks, resulting in wrong free nid allocation at the following
mount time.

Let's indicate new nat_blocks by adjusting nat_bitmap in nat migration.

Reported-by: Lianjun Huang <huanglianjun@vivo.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-06-28 19:21:49 -07:00
Jaegeuk Kim
154bf70972 fsck.f2fs: add sanity check nat_bits
This patch adds to check nat_bits is valid or not. If not, it writes correct
nat_bits.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-06-28 19:21:46 -07:00
Junling Zheng
41149fbb09 fsck.f2fs: simplify fsck_chk_quota_node in PREEN_MODE_1
Do not do fsck_chk_node_blk to simplify fsck_chk_quota_node in
PREEN_MODE_1, as well as fsck_chk_orphan_node.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Sheng Yong
eb61637ad1 fsck.f2fs: reconnect unreachable files to lost+found
This patch introduces lost_found feature to fsck. If a file is found
unreachable by fsck. Fsck tries to reconnect the file to lost+found
directory:
  1. Scan all unreachable file inodes, ignore non-inodes ones and
     directories.
  2. Check them and fix incorrupted data to make sure filesystem
     metadata (mainly counters and main/nat bitmap) are all consistent.
  3. Reconnect these files to lost+found. If lost+found does not exist,
     create it first. During reconnecting, expand lost+found's dentry
     block automatically. Reconnected files are renamed after its ino
     number.
  4. If reconnect fails drop the node and restore filesystem metadata.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Sheng Yong
ff3782931f mkfs.f2fs: create lost+found directory
This patch introduces a new feature F2FS_FEATURE_LOST_FOUND. It can be
switched on by indicating `-O lost_found'. If LOST_FOUND feature is
enabled, an empty directory lost+found is created by mkfs.

This is a preparation for fsck. During fsck, the directory is used to
save unreachable files, which have no parent directory or their parent
directory is removed by fsck. Encrypted files are also allowed to be
saved here.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: use uint64_t to avoid build warning]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Yunlei He
1325c930bb dump.f2fs: fix a wrong report for dump an {d,id,did}node
fix a wrong report for dump an {d,id,did}node like this:

[print_node_info: 283] Node ID [0x6820:26656] is direct node or indirect node.
[0]                     [0x 16b6684 : 23815812]
[1]                     [0x 16b6685 : 23815813]
[2]                     [0x 16b6686 : 23815814]
[3]                     [0x 16b6687 : 23815815]
[4]                     [0x 16b6688 : 23815816]
[5]                     [0x 16b6689 : 23815817]
[6]                     [0x 16b668a : 23815818]
[7]                     [0x 16b668b : 23815819]
[8]                     [0x 16b668c : 23815820]
[9]                     [0x 16b668d : 23815821]
[10]                    [0x 16b668e : 23815822]
Invalid (i)node block

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Sheng Yong
c265813af3 fsck.f2fs: read nat block if nat entry is invalid
fsck will cache all valid nat entries in memory. But when we try to
get a nat entry which is not cached, for example allocate a new nid
during reconnecting files, we need to read the uncached nat entry
from nat block again.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Sheng Yong
fbcc3b1a00 fsck.f2fs: integrate sanity_check_inode to __check_inode_mode
In sanity_check_nid, __check_inode_mode will check i_mode value of an
inode. So integrate sanity_check_inode to __check_inode_mode to clean
up the code.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Sheng Yong
be4f9a661e fsck.f2fs: fix typo
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Junling Zheng
3e8c8d754d dump.f2fs: correct the seg type in ssa_dump
Fix the mixed using of "ret" in ssa_dump.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Jaegeuk Kim
8a96b6a2bd fsck.f2fs: fix to check all the types of current offsets
We can change the next block offsets sometimes, so we have to check it's
free or not all the time. This fixes that SSR type makes a hole for it.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:38 -07:00
Chao Yu
baaa076b4d mkfs.f2fs: expand scalability of nat bitmap
Previously, our total node number (nat_bitmap) and total nat segment count
will not monotonously increase along with image size, and max nat_bitmap size
is limited by "CHECKSUM_OFFSET - sizeof(struct f2fs_checkpoint) + 1", it is
with bad scalability when user wants to create more inode/node in larger image.

So this patch tries to relieve the limitation, by default, limitting total nat
entry number with 20% of total block number.

Before:
image_size(GB)	nat_bitmap	sit_bitmap	nat_segment	sit_segment
16		3836		64		36		2
32		3836		64		72		2
64		3772		128		116		4
128		3708		192		114		6
256		3580		320		110		10
512		3260		640		100		20
1024		2684		1216		82		38
2048		1468		2432		44		76
4096		3900		4800		120		150

After:
image_size(GB)	nat_bitmap	sit_bitmap	nat_segment	sit_segment
16		256		64		8		2
32		512		64		16		2
64		960		128		30		4
128		1856		192		58		6
256		3712		320		116		10
512		7424		640		232		20
1024		14787		1216		462		38
2048		29504		2432		922		76
4096		59008		4800		1844		150

Add a new option '-i' to control turning on/off this feature.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:37 -07:00
Yunlei He
06addd3c1e fsck.f2fs: reduce mem alloc during read sit block
This patch reduce mem alloc during read sit block

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:37 -07:00
Yunlei He
fffc395e6a fsck.f2fs: read ahead xattr & direct node blocks
This patch read ahead xattr & direct node blocks, and
keep the order:

1. check data blocks
2. readahead xattr block
3. fsck xattr block
4. readahead {d,id,did}node block
5. fsck {d,id,did}node block

With above order, we can avoid unneeded readahead before
sub-directory iterated traversing or encountering error.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: Fix a bug breaking the right order.]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:37 -07:00
Chao Yu
10eea8abb8 dump.f2fs: support to dump dirent from blkaddr
This patch adds to support to dump dirent info based on block address
from dentry data block or inline dentry node.

[dump_dentry_block: 627] Inline Dentry block:
[dump_dentry_block: 650] bitmap pos[0x0] name[.] len[0x1] hash[0x0] ino[0x4] type[0x2]
[dump_dentry_block: 650] bitmap pos[0x1] name[..] len[0x2] hash[0x0] ino[0x3] type[0x2]

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:37 -07:00
Jaegeuk Kim
c56821f0b5 fsck.f2fs: allow -p without value
This patch allows -p without value.

Suggested-by: Pavol Cupka <pavol.cupka@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 14:49:37 -07:00
Junling Zheng
43543b9b5f sload.f2fs: fix the missing of bit mask for file type
Fix the missing of bit mask for the file type bit fields.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 12:03:50 -07:00
Lianjun Huang
2b241e1da9 sload.f2fs: give correct file type
This fixes permission error due to wrong file type.

Signed-off-by: Lianjun Huang <huanglianjun@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 12:03:45 -07:00
Jaegeuk Kim
99b2aa3af6 fsck.f2fs: fix check order in -p1
Checking nat entries with nat_area_bitmap should be done before quota check,
since fsck_chk_quota_node() unsets quota inode numbers in nat_area_bitmap.
It causes for -p1 to conduct full scan.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-07 12:03:40 -07:00
Jaegeuk Kim
595fd57a4f f2fs-tools: get kernel version via uname(2)
This patch introduces uname(2) to get kernel version.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-05-04 12:19:40 -07:00
Jaegeuk Kim
3bea898467 fsck.f2fs: fix stack overflow when reading out nat block
The size of nat_block is less then 4KB, resulting in stack overflow by dev_read.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-04-24 00:23:28 -06:00
Jaegeuk Kim
76cd37753a mkfs.f2fs: support fsverity feature
This is aligned to f2fs which reserves fsverity feature bit.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-04 22:22:33 -07:00
Jaegeuk Kim
58364e9aed resize.f2fs: fix access out-of memory boundary
This fixes out-of memory boundary on nat_bitmap, when resizing small to
large partition.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-03-27 20:14:56 -07:00
Chao Yu
48620808e5 f2fs-tools: support inode creation time
This patch supports inode_crtime feature to enable recording inode
creation time in inode layout.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-25 14:11:32 -08:00
Yunlei He
e8268ce7ac fsck.f2fs: use mem nat info directly
Use mem nat info directly for we built in fsck init.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-25 10:41:28 -08:00
Jaegeuk Kim
e1d2965293 fsck.f2fs: show missing checkpoint flags
This patch shows some missing checkpoint flags.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-22 11:29:06 -08:00
Jaegeuk Kim
f789444b9c fsck.f2fs: allow roll-forward for small checkpoint fix
This allows roll-forward when fsck.f2fs changes checkpoint crc.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-22 11:29:03 -08:00
Sheng Yong
d1eb2d3679 dump.f2fs: do not write nat bits when dumping info
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-11 11:42:03 -08:00
Sheng Yong
ff25d7029b fsck.f2fs: show encoded name when unlinking corrupted dentry
For dentry name, we should check if parent directory is encrypted. If it
is, show digest-encoded name instead of cipher text when unlink corrupted
dir entries.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-11 11:41:33 -08:00
Yunlei He
22084eb15f dump.f2fs: Test blkaddr is valid or not in option '-b'
Test blkaddr is valid or not in option '-b'

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-03 22:25:05 -08:00
Yunlei He
d66457e9b5 fsck.f2fs: Remove unused ckpt_valid_map info
Remove unused ckpt_valid_map info.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-02 19:25:21 -08:00
Jaegeuk Kim
55ee9e7202 fsck.f2fs: add -y for generic fsck
-y is same as -f, which fixes any corruption all the time.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-02 19:25:21 -08:00
Gaoxiang (OS)
2e65d03730 resize.f2fs: fix max_nat_bitmap_size miscalculatation
For the same reason as "mkfs.f2fs: fix to calculate
left space of checkpoint page correctly",
this patch also fixes miscalculatation in resize.f2fs.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2018-01-02 19:25:21 -08:00
Jaegeuk Kim
8f91bf8f59 fsck.f2fs: avoid wrong IS_VALID_BLK_ADDR
This patch avoids to check next free block offset in current segments, since we
are using IS_VALID_BLK_ADDR during fsck which is able to be valid for a while.
Let's just check this at the end of fsck.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-12-27 18:02:32 -08:00
Yunlong Song
ddc2d9b4ec fsck.f2fs: check and fix i_namelen to avoid double free
This checks i_namelen between inode block and its dentry.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-12-19 15:51:16 -08:00
Yunlong Song
2df7363106 fsck.f2fs: check nid range before use to avoid segmentation fault
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-12-19 15:45:14 -08:00
Jaegeuk Kim
789ac2df1f f2fs-tools: enable sparse_file opeartions
This adds reading data from sparse_file.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-12-04 18:48:10 -08:00
Jaegeuk Kim
bb5aa5cd6c sload.f2fs: update build for android
This patch updates sload.f2fs for android build.

- do fsck() after sload() to update quota information.
- return success, if there's no source directory

  -C fs_config

  -f source directory [path of the source directory]

  -p product out directory
    : path on fs_config file for uid/gid/mode

  -s file_contexts
    : selabel file

  -t mount point [prefix of target fs path, default:/]
     : path stored in selabel/fs_config files

  -T timestamp

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-30 22:36:35 -08:00
Jaegeuk Kim
67aeaff06d f2fs-tools: allow multiple prog names
This patch allows different prog names like fsck_f2fs, sload_f2fs, etc for
android.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-30 20:36:23 -08:00
Jaegeuk Kim
3a55b82af8 f2fs-tools: build tools selectively
This patch enables to build tools except mkfs.f2fs selectively.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-29 17:22:11 -08:00
Chao Yu
e813df3194 libf2fs: propagate error from f2fs_{finalize,fsync}_device
tests/generic/405 of fstest suit expects that mkfs will return error
when it hits EIO, so let's propagate error from
f2fs_{finalize,fsync}_device, then mkfs can be aware of fsync error.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: initialize ret to zero]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-27 19:26:50 -08:00
Chao Yu
269c86ce7c f2fs-tools: adjust feature name
This patch slightly changes showed feature name.

Before:
Info: superblock features = f9 :  encrypt extra attribute project quota inode checksum flexible inline xattr quota ino

After:
Info: superblock features = f9 :  encrypt extra_attr project_quota inode_checksum flexible_inline_xattr quota_ino

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-26 20:22:11 -08:00
Chao Yu
877821c8b5 fsck.f2fs: fix potential stack overflow issue
In fsck_chk_inode_blk, we will allocate 256 bytes memory in stack before
traversing sub-directory recursively, it's not safe, in order to avoid
potential stack overflow, use malloc instead.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-26 20:21:48 -08:00
Chao Yu
2a8d6909de dump.f2fs: show extra attr only when feature is enabled
If we don't turn on the feature, don't show related info in dumped data.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-26 20:21:28 -08:00
Jaegeuk Kim
43bb7b6c99 f2fs-tools: build binaries in Mac
This patch modifies f2fs-tools to be built in mac.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-14 19:43:48 -08:00
Anthony G. Basile
01ce370d21 fsck/Makefile.am, mkfs/Makefile.am: fix to make distcheck correctly
We add noinst_HEADERS to include header files which are needed to build
but which do not need to be installed on the file system, and include_HEADERS
which are header files that should be installed in $(includedir).
This fixes 'make distcheck`.

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
[Jaegeuk Kim: remove list.h]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-13 21:04:23 -08:00
Sheng Yong
ace53e2ff4 dump/fsck: introduce print_xattr_entry
This patch exports read_all_xattrs to allow dump/fsck to get all xattrs,
and introduces print_xattr_entry which tries to parse an xattr entry
accroding to its xattr index.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
[Jaegeuk Kim: fix configure.ac]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Jaegeuk Kim
bbdbca4e22 fsck.f2fs: add an option to preserve quota limits
If it detects quota file errors, we can see insane quota limits. In order
to recover that, this patch adds an option to reset them as zeros.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Yunlei He
b62ca9ed3c fsck: check inline_dentry i_addr[0] same as inline_data
<4>[   30.222442s][pid:1,cpu4,init][<ffffff8008357ffc>] f2fs_evict_inode+0x850/0xa34
<4>[   30.222442s][pid:1,cpu4,init][<ffffff8008209ec4>] evict+0xa0/0x168
<4>[   30.222442s][pid:1,cpu4,init][<ffffff800820ad34>] iput+0x188/0x220
<4>[   30.222473s][pid:1,cpu4,init][<ffffff800836d050>] recover_orphan_inodes+0x2b4/0xa80
<4>[   30.222473s][pid:1,cpu4,init][<ffffff80083648b0>] f2fs_fill_super+0xcf4/0x16a0
<4>[   30.222473s][pid:1,cpu4,init][<ffffff80081f2478>] mount_bdev+0x198/0x1c8
<4>[   30.222473s][pid:1,cpu4,init][<ffffff80083608a8>] f2fs_mount+0x14/0x1c
<4>[   30.222503s][pid:1,cpu4,init][<ffffff80081f2f38>] mount_fs+0x3c/0x15c
<4>[   30.222503s][pid:1,cpu4,init][<ffffff800820e9f8>] vfs_kern_mount+0x7c/0x16c
<4>[   30.222503s][pid:1,cpu4,init][<ffffff8008212548>] do_mount+0x214/0xcf8
<4>[   30.222503s][pid:1,cpu4,init][<ffffff800821338c>] SyS_mount+0xa8/0x164
<4>[   30.222503s][pid:1,cpu4,init][<ffffff80080831b0>] el0_svc_naked+0x24/0x28

Mount failed with message as blow:
	recover_orphan_inode: orphan failed (ino=1265), run fsck to fix

One orphan directory with inline_dentry flag, but i_addr[0] is not zero.
By the way, sit bitmap of i_addr[0] is also invalidate.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Sheng Yong
0f9fb720b2 fsck.f2fs: format output message of FIX_MSG
This patch removes an extra '\n' at the end of the string in FIX_MSG.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Sheng Yong
c7963bce03 fsck.f2fs: introduce sanity_check_inode
f2fs_iget checks if i_mode is valid. If it is not, the file cannot be
accessed as well as deleted. To make sure such files can be removed,
fsck adds the same check, and removes incorrect inode blocks.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Sheng Yong
f2f1341ffe fsck.f2fs: introduce new option --dry-run
With --dry-run enabled, fsck.f2fs will do all checks and "fixes" except
that all fixes will not be written to storage at last.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Sheng Yong
2d1a62ee75 dump.f2fs: do not dump encrypted files
If a file is encrypted, its content is cipher text on the storage. So
there is no need to dump an encrypted file.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:07 -08:00
Sheng Yong
7935c4e1f0 dump.f2fs: introduce dump_xattr
This patch introduces dump_xattr to create xattrs for dumped files.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: detect header files]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-11 18:01:04 -08:00
Sheng Yong
79f2c969a5 fsck.f2fs: do not fix corrupted nat entries in build_nat_area_bitmap
Fixing corrupted data depends on c.fix_on. If it's not set, we should not
force fixing corrupted data.  So if nat entries are found invalid when
building nat_area_bitmap, we should just set c.bug_on, and fix it later.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-06 20:07:42 -08:00
Sheng Yong
9d7651bcbe fsck.f2fs: do not set fix_on directly
Do not set fix_on if it is allowed by user.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-06 20:07:42 -08:00
Jaegeuk Kim
e53ad5b071 f2fs-tools: fix warnings when building in android
This patch tries to avoid all the warnings.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-11-06 20:07:42 -08:00
Hyojun Kim
6c6bb35c89 fsck.f2fs: support quota
This patch let fsck to check and fix quota file contents.

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-11-06 20:07:40 -08:00
Hyojun Kim
68593f4981 f2fs-tools: f2fs_read() and f2fs_filesize_update() are added
This patch adds f2fs_read() and f2fs_filesize_update(). It also refactors
f2fs_write_block() and renamed as f2fs_write().

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-10-30 20:41:49 -07:00
Hyojun Kim
5b2dc59ece sload.f2fs: fix bugs in f2fs_write_block()
Found and fixed following three bugs in f2fs_write_block() function.
 - Write (4096 - offset) bytes for the first block even for small count.
 - For overwriting, found blkaddr is not used for writing.
 - dn.idirty status can be lost by set_new_dnode().
 - missing inode_checksum

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-10-30 20:41:49 -07:00
Chao Yu
8d46072f07 f2fs-tools: support flexible inline xattr size
This patch makes mkfs to support flexible inline xattr feature, also
this enables fsck to recognize new disk-layout of inode which be of
flexible inline xattr size.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-10-30 02:16:35 -07:00
Yunlei He
1797a5f092 fsck: introduce generic function f2fs_fsync_device
We use f2fs_finalize_device to fsync previous data in
checkpoint area before write last CP pack, in order to avoid
cp corruption in sudden-power-off case. But this function will
close the device, so this patch introduce a function to call
fsync() only.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-10-26 12:25:27 +02:00
Yunlong Song
d879e7ebde f2fs-tools: move_curseg_info only if check_curseg_offset fails
Current design will lose recovery process when check_curseg_offset is OK.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-09-11 18:22:48 -07:00
Yunlong Song
f4078d7e5b f2fs-tools: fix is_set_ckpt_flags for correct bool value
If flag bit to check is in 0xFFFFFF00, then the return value will be false,
this is not correct, so fix it.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-09-11 18:22:32 -07:00
Yunlei He
8d9885de45 fsck.f2fs: write back last cp block in the end
Write back last cp block in the end in case of sudden power off
during fsck process

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-08-29 10:04:00 -07:00
Chao Yu
7457726261 f2fs-tools: support inode checksum
This patch introduce a new option 'inode_checksum' for enabling inode
checksum functionality in mkfs/fsck/sload.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-07-26 14:38:43 -07:00
Piotr Sokołowski
38c7581ee3 f2fs-tools: fix printing block adresses
This patch allows properly printing all addresses in an inode.
It is useful in commands like dump.f2fs.

Signed-off-by: Piotr Sokołowski <piosoko1@student.pg.edu.pl>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-07-26 14:28:24 -07:00
Chao Yu
a3d9db1f88 f2fs-tools: support project quota
This patch introduce a new option 'project_quota' for enabling project
quota functionality during mkfs.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-07-26 11:42:56 -07:00
Chao Yu
dad33a1ee7 f2fs-tools: enhance on-disk inode structure scalability
This patch adds an option 'extra_attr' in mkfs for enabling v2 f2fs
inode format in kernel codes.

Also this patch makes fsck to support recognize v2 inode format,
below is v2 format description:

Original one:

struct f2fs_inode {
	...
	struct f2fs_extent i_ext;
	__le32 i_addr[DEF_ADDRS_PER_INODE];
	__le32 i_nid[DEF_NIDS_PER_INODE];
}

Extended one:

struct f2fs_inode {
        ...
        struct f2fs_extent i_ext;
	union {
		struct {
			__le16 i_extra_isize;
			__le16 i_padding;
			__le32 i_extra_end[0];
		};
		__le32 i_addr[DEF_ADDRS_PER_INODE];
	};
        __le32 i_nid[DEF_NIDS_PER_INODE];
}

Once F2FS_EXTRA_ATTR is set, we will steal four bytes in the head of
i_addr field for storing i_extra_isize and i_padding. with i_extra_isize,
we can calculate actual size of reserved space in i_addr, available
attribute fields included in total extra attribute fields for current
inode can be described as below:

  +--------------------+
  | .i_mode            |
  | ...                |
  | .i_ext             |
  +--------------------+
  | .i_extra_isize     |-----+
  | .i_padding         |     |
  | .i_prjid           |     |
  | .i_atime_extra     |     |
  | .i_ctime_extra     |     |
  | .i_mtime_extra     |<----+
  | .i_inode_cs        |<----- store blkaddr/inline from here
  | .i_xattr_cs        |
  | ...                |
  +--------------------+
  |                    |
  |    block address   |
  |                    |
  +--------------------+
  | .i_nid             |
  +--------------------+
  |   node_footer      |
  | (nid, ino, offset) |
  +--------------------+

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-07-26 11:42:49 -07:00
Chao Yu
8b4406a5bd f2fs-tools: spread struct f2fs_dentry_ptr for inline path
Use f2fs_dentry_ptr structure to indicate inline dentry structure as
much as possible, so we can wrap inline dentry with size-fixed fields
to the one with size-changeable fields. With this change, we can
handle size-changeable inline dentry more easily.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-07-17 14:35:33 -07:00
Jaegeuk Kim
8e29c2be47 f2fs-tools: avoid build warnings
This patch resolves warnings while building it in android.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-06-05 13:58:50 -07:00
Tiezhu Yang
d9180db7d4 f2fs-tools: fix the wrong message when errno is EBUSY
If f2fs is unmounted with the -l option, the process can still use the
file system. In this case, the command mkfs.f2fs, fsck.f2fs, dump.f2fs,
defrag.f2fs, resize.f2fs and sload.f2fs failed due to the device is in
use by the system. At the moment f2fs is already not mounted, so it is
wrong to print error message "Error: Not available on mounted device!",
this patch fixes it.

[root@localhost home]# mkfs.f2fs -f /dev/sdb1
[root@localhost home]# mkdir -p /mnt/f2fs_mnt_point
[root@localhost home]# mount -t f2fs /dev/sdb1 /mnt/f2fs_mnt_point/
[root@localhost home]# cd /mnt/f2fs_mnt_point/
[root@localhost f2fs_mnt_point]# umount /dev/sdb1
umount: /mnt/f2fs_mnt_point: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@localhost f2fs_mnt_point]# umount -l /dev/sdb1
[root@localhost f2fs_mnt_point]# umount /dev/sdb1
umount: /dev/sdb1: not mounted
[root@localhost f2fs_mnt_point]# mkfs.f2fs -f /dev/sdb1

	F2FS-tools: mkfs.f2fs Ver: 1.8.0 (2017-04-28)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Label =
Info: Trim is enabled
	Error: In use by the system!
	Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# fsck.f2fs /dev/sdb1
	Error: In use by the system!
	Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# dump.f2fs /dev/sdb1
	Error: In use by the system!
	Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# defrag.f2fs /dev/sdb1
	Error: In use by the system!
	Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# resize.f2fs /dev/sdb1
	Error: In use by the system!
	Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# sload.f2fs /dev/sdb1
	Error: In use by the system!
	Error: Not available on mounted device!

Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-05-10 10:22:51 -07:00
Chao Yu
f642b24822 f2fs-tools: support to set and recognize CP_TRIMMED_FLAG
During mkfs, once we have issued discard for all device, we can set
CP_TRIMMED_FLAG in cp pack, this can make kernel module to record
undiscard blocks correctly, it will help to avoid unneeded discard.

Also this patch makes f2fs-tools be with the ability of recognizing
that new flag.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-04-28 12:04:21 -07:00
Jin Qian
892e1542e7 fsck.f2fs: sanity check segno and blk_off when building curseg array
segno and blk_off were read from input image without sanity check. This
could lead to buffer overflow when accessing internal arrays like SIT
sentries and seg_entry cur_valid_map.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-04-27 15:49:54 -07:00
Jin Qian
b79c3ba4ea fsck.f2fs: sanity check cp_payload before reading checkpoint
cp_payload is not sanity checked from input image. A invalid size
can cause buffer overflow when reading checkpoint blks into memory.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-04-27 12:51:09 -07:00
Jin Qian
d87fc37b02 fsck.f2fs: sanity check blk_off for summary block entries
crafted malicious f2fs partition can fill an out of bound blk_off,
which cause overflow when accessing summary block entries.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-04-27 12:42:58 -07:00
Jin Qian
6ab50775fa f2fs-tools: sanity check segment count
make sure segment count in super block doesn't exceed F2FS_MAX_SEGMENT.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-04-25 16:37:37 -07:00
Jin Qian
8a51985120 fsck.f2fs: fix cur_valid_map buffer overflow
blk_off is read from image. Attacker can construct an image with big
blk_off that trigger overflow on se->cur_valid_map.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-04-21 11:42:59 -07:00
Kinglong Mee
0f3045d3e8 sload.f2fs: support sload files into directory includes inline dentry
It seems the new created directory always includes inline dentries,
let sload.f2fs supporting it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-19 18:46:10 -04:00
Kinglong Mee
9a4df3c466 sload.f2fs: let dir_buckets/dir_block_index supports dir_level
The dir_level in the filesystem maybe larger than zero,
supports it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-19 18:45:47 -04:00
Kinglong Mee
7b03ccbb9b fsck.f2fs: check encrypted filename depends FADVISE_ENC_NAME_BIT
An encrypted directory under an unencrypted directory, the filename isn't encrypted.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-19 18:45:37 -04:00
Kinglong Mee
5e6526940e fsck.f2fs: fix bad notice of missing device
The following messages is better than before.

Before,
# fsck.f2fs -d 1
    Error: Need argument for -d

Now,
# fsck.f2fs -d 1
Info: Debug level = 1
        Error: Device not specified

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-19 18:45:21 -04:00
Kinglong Mee
8e710d1d71 sload.f2fs: fix missing SSA updates
If sload many larger files to disk, the SSA that doesn't cached will be missed.

Mar 17 12:04:39 localhost kernel: ------------[ cut here ]------------
Mar 17 12:04:39 localhost kernel: kernel BUG at fs/f2fs/gc.c:899!
Mar 17 12:04:39 localhost kernel: invalid opcode: 0000 [#1] SMP
Mar 17 12:04:39 localhost kernel: Modules linked in: f2fs tun bridge stp llc fuse ip_set nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event snd_ens1371 gameport snd_ac97_codec coretemp ac97_bus crct10dif_pclmul crc32_pclmul ppdev snd_seq snd_pcm ghash_clmulni_intel intel_rapl_perf vmw_balloon snd_rawmidi joydev snd_timer snd_seq_device snd soundcore parport_pc parport nfit acpi_cpufreq tpm_tis tpm_tis_core shpchp vmw_vmci tpm i2c_piix4 nfsd auth_rpcgss nfs_acl lockd grace sunrpc xfs libcrc32c vmwgfx drm_kms_helper ttm drm e1000 crc32c_intel mptspi scsi_transport_spi serio_raw mptscsih mptbase ata_generic pata_acpi fjes
Mar 17 12:04:39 localhost kernel: CPU: 0 PID: 6427 Comm: f2fs_gc-8:33 Tainted: G        W       4.10.0-f2fs+ #25
Mar 17 12:04:39 localhost kernel: Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 07/02/2015
Mar 17 12:04:39 localhost kernel: task: ffff94ba7d998000 task.stack: ffffb6e4c2e50000
Mar 17 12:04:39 localhost kernel: RIP: 0010:do_garbage_collect+0xa39/0xb60 [f2fs]
Mar 17 12:04:39 localhost kernel: RSP: 0018:ffffb6e4c2e53cc0 EFLAGS: 00010213
Mar 17 12:04:39 localhost kernel: RAX: ffff94baa0427000 RBX: 0000000000000001 RCX: 0000000000000002
Mar 17 12:04:39 localhost kernel: RDX: 0000000000000000 RSI: fffff5e2c28109c0 RDI: fffff5e2c28109c0
Mar 17 12:04:39 localhost kernel: RBP: ffffb6e4c2e53dc0 R08: ffff94ba7dfc72f0 R09: fffff5e2c28109dc
Mar 17 12:04:39 localhost kernel: R10: 0000000000000040 R11: ffff94ba7dfc7238 R12: 0000000000000418
Mar 17 12:04:39 localhost kernel: R13: fffff5e2c28109c0 R14: 0000000000000417 R15: ffff94ba3c021000
Mar 17 12:04:39 localhost kernel: FS:  0000000000000000(0000) GS:ffff94babb600000(0000) knlGS:0000000000000000
Mar 17 12:04:39 localhost kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Mar 17 12:04:39 localhost kernel: CR2: 00007fc42a0d7000 CR3: 00000000a7e94000 CR4: 00000000001406f0
Mar 17 12:04:39 localhost kernel: Call Trace:
Mar 17 12:04:39 localhost kernel: ? find_next_bit+0xb/0x10
Mar 17 12:04:39 localhost kernel: f2fs_gc+0x111/0x480 [f2fs]
Mar 17 12:04:39 localhost kernel: ? prepare_to_wait_event+0x79/0x160
Mar 17 12:04:39 localhost kernel: gc_thread_func+0x2d0/0x3f0 [f2fs]
Mar 17 12:04:39 localhost kernel: ? __schedule+0x273/0x860
Mar 17 12:04:39 localhost kernel: ? remove_wait_queue+0x70/0x70
Mar 17 12:04:39 localhost kernel: kthread+0x101/0x140
Mar 17 12:04:39 localhost kernel: ? f2fs_gc+0x480/0x480 [f2fs]
Mar 17 12:04:39 localhost kernel: ? kthread_park+0x90/0x90
Mar 17 12:04:39 localhost kernel: ret_from_fork+0x2c/0x40
Mar 17 12:04:39 localhost kernel: Code: 48 8d 84 24 90 00 00 00 48 89 c7 48 89 44 24 28 e8 7d cc ba e6 e9 17 fa ff ff 48 c7 c6 48 3f 84 c0 48 89 c7 e8 59 8d 9d e6 0f 0b <0f> 0b 48 c7 c6 48 3f 84 c0 4c 89 ff e8 46 8d 9d e6 0f 0b 8b b4
Mar 17 12:04:39 localhost kernel: RIP: do_garbage_collect+0xa39/0xb60 [f2fs] RSP: ffffb6e4c2e53cc0
Mar 17 12:04:39 localhost kernel: ---[ end trace 926d61b064ed1f2d ]---

Fixes: 767a93ea8b ("defrag.f2fs: fix missing SSA updates")
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-17 20:47:08 +08:00
Kinglong Mee
6fb673abc0 fsck.f2fs: a separate option for showing directory tree
Showing directory tree reuses dbg_lv that if setting "-t",
fsck.f2fs does not show any others.
Users may want much information include the debug info and directory tree.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-16 08:16:39 +08:00
Kinglong Mee
802b6499bd fsck.f2fs: sanity check of crc_offset from raw checkpoint
The crc_offset towards or beyond the end of block is wrong,
sanity check it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-16 08:15:12 +08:00
Yunlei He
78ad88d1d2 resize.f2fs: fix a resize fail for sector size mismatch
This patch fix a resize faill for sector size mismatch.
The initial fs comes from an image file, with sector size
512KB, and the block device sector size is equal to block
size.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-03-16 08:13:58 +08:00
Jaegeuk Kim
191573e71b mkfs.f2fs: support nat_bits feature
This patch adds nat_bits in the last one ore two 4KB-sized blocks of first
checkpoint segment. So, now a set of checkpoint *segment* consists of:

< checkpoint segment >
----------------------
| cp page #1         | 4KB
----------------------
| compacted data sum | 4KB
----------------------
| node sum  #1       | 4KB
----------------------
| node sum  #2       | 4KB
----------------------
| node sum  #3       | 4KB
----------------------
| cp page #2         | 4KB
----------------------
...
----------------------
| crc|cpver          | 8 bytes
----------------------
| full NAT bits      | # of NAT segments / 2 * 512 / 8 bytes
----------------------
| empty NAT bits     | # of NAT segments / 2 * 512 / 8 bytes
----------------------

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-02-23 10:11:41 -08:00
Jaegeuk Kim
f081d54ba8 fsck.f2fs: fix wrong usage out
This fixes wrong messages for error out.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-02-23 10:11:41 -08:00
Sheng Yong
2b4b86066b resize.f2fs: correct checkpoint_ver of new checkpoint
resize.f2fs rebuilds a new checkpoint at the new position. Its
checkpoint_ver should be increased.

Signed-off-by: Shuoran Liu <liushuoran@huawei.com>
Signed-off-by: Weichao Guo <guoweichao@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-02-06 14:49:39 -08:00
Jaegeuk Kim
b4436b086e fsck.f2fs: remove wrong dentry due to hash conversion
This patch removes stale dentries remained by hash conversion issue which
happened long time ago.

Fixes: aafe2ca3dc ("fsck.f2fs: fix wrong hash_code made by previous buggy code")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-02-01 10:33:54 -08:00
Liu Xue
5d9032fd1b fsck.f2fs: always fix seg entry type if it is not DATA
If the segment type and sum footer type are node, but its
sit type is corrupted as cold data, this will always trigger
type error crash in do_garbage_collect but not get fixed by fsck,
so fix seg entry type when it is not DATA.

Reported-by: KARBOWSKI Piotr <piotr.karbowski@gmail.com>
Signed-off-by: Liu Xue <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-01-24 13:38:17 +09:00
Jaegeuk Kim
88753dbcf3 fsck.f2fs: show parse errors neatly
This patch is just to clean up.

Cc: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-01-21 14:00:15 +08:00
Jaegeuk Kim
ed031d6b24 fsck.f2fs: support -p without argument
This patch allows fsck run -p without argument. So we could use -p as
-p, -p 0, -p 1. '-p' and '-p 0' have the same meaning as '-a'. '-p 1'
check more meta data than '-a'.

Reported-by: KARBOWSKI Piotr <piotr.karbowski@gmail.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-01-21 13:28:18 +08:00
Sheng Yong
9deb6fd9f2 f2fs-tools: correct endianness
It is reported that fsck.f2fs behaves abnormally when running on MIPS32
rel 2 big endian cpu, since incorrect endianness. So let's correct all
endianess issues of f2fs-tools.

Reported-by: <k@vodka.home.kg>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-01-19 15:29:08 +08:00
Jaegeuk Kim
33dacab9a8 fsck.f2fs: fix wrong i_name check for directory
We should not check the consistency between i_name and its dentry for directory.
The i_name is used only for normal file recovery when conducting roll-forward
recovery.

Moreover, this condition was totally missing encryption case which is breaking by

1. encrypt ./test
2. mkdir ./test/a
3. mkdir ./test/b
4. rename ./test/a ./test/b

-> fsck.f2fs reports wrong inconsistency in terms of i_name.

Reported-by: liushuoran <liushuoran@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-12-22 13:53:18 -08:00
Yunlei He
d466dea52f resize.f2fs: remove unused parameters
This patch remove unused parameters in these three functions:
get_new_sb, migrate_main and rebuild_superblock

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-12-12 11:09:30 -08:00
Junling Zheng
e8768a998d resize.f2fs: fix the number of moved ssa blocks in migrate_ssa
If the offset passed in migrate_ssa is not zero, it means that there're
offset segments of old main will disappear after migrating, then there're
offset blocks of old ssa should be invalidated and removed accordingly.
So, the number of moved ssa blocks should be: TOTAL_SEGS(sbi) - offset,
and the expanded summary, which is filled with zero_blocks, should start
from: new_sum_blkaddr + TOTAL_SEGS(sbi) - offset.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-12-01 15:12:46 -08:00
Sheng Yong
361b0185ed fsck.f2fs: remove duplicated header files
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-28 21:26:15 -08:00
Junling Zheng
1d81a373bd resize.f2fs: correct the max segno in migrate_main
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-28 21:26:15 -08:00
Liu Xue
b88767e606 fsck.f2fs: flush curseg sit entries
Flush curseg sit entries, since type of sit entries may
be changed after move_curseg_info.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-23 10:12:56 -08:00
Yunlei He
b5e7d4449d dump.f2fs: fix an error in dump nat pack num
This patch fix an error in dump nat pack num

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-21 17:02:33 -08:00
Yunlei He
4f1ded4ad2 fsck.f2fs add a simple check orphan inodes in -p 1 mode
This patch add a simple check orphan inodes in -p 1 mode

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-21 17:02:26 -08:00
Jaegeuk Kim
de7e07e011 f2fs-tools: support multiple devices
This patch adds an option to specify multiple devices for an f2fs instance.

Up to 7 devices in addition to the default device can be added.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-09 18:03:47 -08:00
Junling Zheng
ea1bd1ce31 fsck.f2fs: refactor build_nat_area_bitmap to speed up fsck
Refactor build_nat_area_bitmap, move out lookup_nat_in_journal from the
dual loops. Instead of looking up all nids in journals, we traverse nat
journals, whose entries are used to replace the NAT entries with the
corresponding nid to reduce the time build_nat_area_bitmap costs.

For "fsck -p 1", it reduces over half of the time.

		Empty		Fragmented Entirely
32G(ms):
  original	625.8		727.3
  improved	226.3		298.2
64G(ms):
  original	1159		1637.7
  improved	515.8		676.7

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-07 17:05:51 -08:00
Yunlei He
5e056bef17 resize.f2fs: modify condition for resize
it better to decide resize or not by sector num.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-07 09:57:52 -08:00
Yunlei He
890e9b325d fsck.f2fs: add a judgment after calloc
This patch add a judgment after calloc avoid memory alloc
failure

Signed-off-by: Yunlei He <heyunlei@huawei.com>
[Jaegeuk Kim: remove unneeded memset to avoid build warning]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-04 16:08:19 -07:00
Yunlei He
9e341fa6b3 fsck.f2fs: no need to write a new cp if nothing to flush
This patch avoid to write a new cp if no journal info

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-04 16:07:41 -07:00
Jaegeuk Kim
7401b7ce2d resize.f2fs: fill zeros for expanded ssa area
This will avoid wrong behavior after expanding volume.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 22:25:29 -07:00
Jaegeuk Kim
2d7d4ffdd4 f2fs-tools: determine cp_addr by sbi->cur_cp
We don't guarantee cp_addr is fixed by cp_ver due to sload.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 21:19:38 -07:00
Jaegeuk Kim
f3341c3976 sload.f2fs: not support to find or add files in inline_dir directory
Now, sload.f2fs doesn't support inline_dir.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 21:19:37 -07:00
Jaegeuk Kim
8f346ef3a5 resize.f2fs: get latest free segments
The # of free segments can be changed by defragmentation.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 21:19:37 -07:00
Jaegeuk Kim
bfa0743771 f2fs-tools: fix end block addres when finding free block
This patch fixes wrong end_blkaddr condition for free block allocation.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 18:03:28 -07:00
Jaegeuk Kim
b467030078 resize.f2fs: fix wrong end_blkaddr
The end_blkaddr should add main area segments.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 18:01:55 -07:00
Jaegeuk Kim
2f2ee92b34 defrag.f2fs: return error for no space case
This returns error instead of assertion for resize.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 18:01:55 -07:00
Jaegeuk Kim
6ab16edfcf resize.f2fs: fix wrong offset calculation
When we move whole main area into new expanded area, we do not change its
segment numbers from sit and ssa.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 17:02:02 -07:00
Jaegeuk Kim
0033920853 resize.f2fs: add more information in debug messages
Print more information.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 17:02:02 -07:00
Liu Xue
893acfc2e4 fsck.f2fs: add SSR-based allocation when free segment not enough
Add SSR-based allocation when free segment reach the limit of
reserved segments.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 10:58:53 -07:00
Liu Xue
112bf05cb8 fsck.f2fs: rewrite entries info in segment manager
The entries info in segment manager may be not correct, since
corrupted blocks may already cleaned. So rewrite se info with
main area bitmap.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
[Jaegeuk Kim: remove obsolte variable in f2fs_fsck]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-02 10:58:53 -07:00
Damien Le Moal
4b1ecd77a1 fsck.f2fs: check BLKZONED feature on mount
The BLKZONED feature is mandatory for host-managed zoned block
devices. So check that it is set.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-01 17:27:35 -07:00
Damien Le Moal
81c62e2537 f2fs-tools: use zoned block device terminology
SMR stands for "Shingled Magnetic Recording" which makes sense
only for hard disk drives (spinning rust). The ZBC/ZAC standards
enable management of SMR disks, but solid state drives may also
support those standards. So replace "SMR" with "zoned block device"
to avoid a HDD centric terminology.

In particular, rename the HMSMR feature to BLKZONED.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-31 14:52:27 -07:00
Sheng Yong
6471969f78 fsck.f2fs: do not check the first seg in a sec in find_next_free_block
The first segment is already checked, so there is no need to check it
again if we want to make sure the whole section is freed.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-31 10:59:24 -07:00
Sheng Yong
c4c65265da dump/fsck: convert encrypted file name
If fscrypt is enabled, we need to convert the encrypted file name before
printing it. So let's export convert_encrypted_name for other functions,
and make it returns the length of converted string.
This patch also changes the parameter of file_is_encrypt to f2fs_inode.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-31 10:59:24 -07:00
Christian Hesse
b0a2386089 sload.f2fs: allow to build without libselinux
Some systems do not have libselinux. Allow to build sload.f2fs without
support for selinux.

Signed-off-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-23 14:36:49 -07:00
Jaegeuk Kim
390fe587b1 fsck.f2fs: support restore lost files into ./lost_found/
This patch adds to support restoring lost files into ./lost_found/.

For example,

 # fsck.f2fs /dev/sdXX

...
NID[0x87d7] is unreachable
NID[0x87d8] is unreachable
NID[0x87d9] is unreachable
[FSCK] Unreachable nat entries                        [Fail] [0x4988]
[FSCK] SIT valid block bitmap checking                [Fail]
[FSCK] Hard link checking for regular file            [Ok..] [0x0]
[FSCK] valid_block_count matching with CP             [Fail] [0x2]
[FSCK] valid_node_count matcing with CP (de lookup)   [Fail] [0x1]
[FSCK] valid_node_count matcing with CP (nat lookup)  [Ok..] [0x4989]
[FSCK] valid_inode_count matched with CP              [Fail] [0x1]
[FSCK] free segment_count matched with CP             [Ok..] [0x1f7]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]

Do you want to restore lost files into ./lost_found/? [Y/N] y

Then, you can restore unreachable files from ./lost_found/ in its best effort.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-13 16:57:32 -07:00
Jaegeuk Kim
68ef569e44 fsck.f2fs: check condition to avoid wrong memory allocation
This patch should fix the below bug.

Info: checkpoint state = 4 :  compacted_summary sudden-power-off
[FIX] (is_valid_ssa_data_blk: 301)  --> Set data summary 0x1039 -> [0x3] [0x0] [0x0]
[ASSERT] (fsck_chk_data_blk:1459)  --> SIT bitmap is 0x0. blk_addr[0x20b6d8]
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x2 with invalid NID/ino 0x1644b164
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x2 with bad ino 0x1644b164
[ASSERT] (__chk_dentries:1269)  --> Bad dentry 0x0 with unexpected ftype 0x2c
[FIX] (__chk_dentries:1272)  --> Clear bad dentry 0x4 with bad ftype 0x2c
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x5 with invalid NID/ino 0x49000000
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x5 with bad ino 0x49000000
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x7 with invalid NID/ino 0x67706a2e
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x7 with bad ino 0x67706a2e
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x8 with invalid NID/ino 0x4a437044
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x8 with bad ino 0x4a437044
[ASSERT] (__chk_dentries:1269)  --> Bad dentry 0x0 with unexpected ftype 0x0
[FIX] (__chk_dentries:1272)  --> Clear bad dentry 0xf with bad ftype 0x0
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x20 with invalid NID/ino 0x4a150009
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x20 with bad ino 0x4a150009
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x21 with invalid NID/ino 0x1800094a
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x21 with bad ino 0x1800094a
*** buffer overflow detected ***: fsck.f2fs terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7fa56b17b38f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7fa56b212c9c]
/lib/x86_64-linux-gnu/libc.so.6(+0x109b60)[0x7fa56b211b60]
fsck.f2fs[0x4032f6]
fsck.f2fs[0x4063f7]
fsck.f2fs[0x406d09]
fsck.f2fs[0x4046b8]
fsck.f2fs[0x405378]
fsck.f2fs[0x405d86]
fsck.f2fs[0x402071]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fa56b129ec5]

Reported-by: Mirh <mirh@protonmail.ch>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-13 16:57:31 -07:00
Jaegeuk Kim
bdc1a0ac8b f2fs-tools: clean up and avoid build warning
This patch is to clean up and avoid warnings when compiling aosp.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-12 14:57:58 -07:00
Jaegeuk Kim
c499346871 f2fs: avoid AOSP build failure
SCSI-related operations are not permitted to AOSP biuld.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-12 14:44:52 -07:00
Jaegeuk Kim
9a708f0fe4 fsck.f2fs: allocate buffer after condition check
This patch makes buffer allocation be done after condition check.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-04 13:34:51 -07:00
Junling Zheng
3d19ea91bc fsck.f2fs: fix a typo in check_sector_size
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-03 10:57:49 -07:00
Junling Zheng
276571e866 fsck.f2fs: fix incorrect ERR_MSG in f2fs_do_mount
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-03 10:57:49 -07:00
Junling Zheng
d256214da8 fsck.f2fs: free cp_page_1 in validate_checkpoint
Free cp_page_1 in validate_checkpoint to avoid memory leak.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-03 10:57:49 -07:00
Yunlei He
f1ee35104d fsck: porting avoid unneeded loop in build_sit_entries to fsck
This patch porting avoid unneeded loop in build_sit_entries to fsck

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-24 11:22:05 -07:00
Jaegeuk Kim
3ffc5a8f3e f2fs-tools: use shorter config variable name
This patch has no functional change.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-22 19:32:14 -07:00
Yunlong Song
e874f42324 fsck.f2fs: free node_blk to avoid memory leak
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-22 11:40:37 -07:00
Yunlong Song
3b8a88a8d3 fsck: clear useless "continue" in __chk_dentries
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-20 15:27:09 -07:00
Jaegeuk Kim
37dbd83399 fsck: recover symlink with zero i_size
If we have i_blocks, we can recover i_size.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 15:29:09 -07:00
Xue Liu
9884ad4e79 fsck.f2fs: clean up duplicated code
Call current_nat_addr() to calculate nat block address.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:17:47 -07:00
Sheng Yong
49503225c0 f2fs-tools: update the format of output message
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:17:20 -07:00
Sheng Yong
2452568aab fsck.f2fs: free nat entry cache
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:17:11 -07:00
Sheng Yong
ffc7dbc01d fsck.f2fs: fix typo
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:16:59 -07:00
Sheng Yong
278216b5dc fsck.f2fs: correct variable type and name
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:16:34 -07:00
Sheng Yong
89d5d52da8 f2fs.fsck: fix endianess
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:16:15 -07:00
Sheng Yong
11adb13a79 dump.f2fs: show inode->i_dir_level
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-15 10:15:52 -07:00
Jaegeuk Kim
70a8fc3df7 mkfs/fsck: add host-managed smr feature
This feature flag will be used by f2fs to detect HMSMR device.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-06-15 09:43:28 -07:00
Jaegeuk Kim
dc573510a3 fsck.f2fs: allow zero link count for orphan inode
This will be zeroed by f2fs during the mount time.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-06-09 14:16:18 -07:00
Yunlei He
4f105bbaba fsck.f2fs: modify sit dump && add nat dump
modify sit dump && add nat dump like this:

dump_sit:

segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)

segno:      13  vblocks:512     seg_type:2      sit_pack:2

  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff
  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff
  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff
  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff  ff

dump_nat:

nid:    3       ino:    3       offset:    0    blkaddr:   2076417      pack:2
nid: 1042       ino: 1042       offset:    0    blkaddr:   2087156      pack:2
nid:57076       ino:57076       offset:    0    blkaddr:   2071232      pack:2
nid:57118       ino:57118       offset:    0    blkaddr:   2071233      pack:2
Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-06-08 10:10:38 -07:00
Yunlei He
22aa244ad7 fsck.f2fs: check sector size if formatted from a regular file
This patch check sector size if formatted from a regular file,
write the sector info to superblock from device info.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-05-23 13:38:51 -07:00
Jaegeuk Kim
6419842058 fsck.f2fs: reset fsck flag if there is no bug
Let's update checkpoint, if fsck is set without any bug.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-05-03 17:11:13 -07:00
Junling Zheng
43448f9bfd fsck.f2fs: remove duplicated codes in sanity_check_raw_super
Remove duplicated codes in sanity_check_raw_super().

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-04-27 14:07:59 -07:00
Yunlei He
91bd80c441 resize.f2fs: replace the overprovision calculation method
This patch replace the overprovision calculation method from
mkfs tool.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-04-27 14:02:26 -07:00
Jaegeuk Kim
603f8f9d36 sload.f2fs: support loading files into partition directly
This patch implements loading files into the existing partition.
For example,
 # sload.f2fs -f ./ /dev/sdb1

Then, all the directories and files will be loaded into /dev/sdb1.
By default, newly files should have inline_data and inline_xattr, if possible.

Signed-off-by: Hou Pengyang <houpengyang@huawei.com>
Signed-off-by: Liu Shuoran <liushuoran@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-04-18 21:11:26 -04:00
Jaegeuk Kim
d3be08825e resize.f2fs: support to expand partition size
Now user can expand existing partition with resize.f2fs.
Currently, it doesn't support shrink an image.

For example,
 # resize.f2fs -t [# of sectors] [image]

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-04-18 21:11:26 -04:00
Jaegeuk Kim
99ffb3da59 fsck.f2fs: check sanity of superblock and fix any misalignment
This patch detects any corrupted superblock and fix misalignment when it finds,
which is synced with the f2fs kernel module.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-23 11:54:31 -07:00
Jaegeuk Kim
0301f16991 fsck.f2fs: nullify the freed ckpt pointer
Otherwise, we get a double free error by:

In fsck/main.c,

545 out_err:
546         if (sbi->ckpt)
547                 free(sbi->ckpt);

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-23 11:21:38 -07:00
Sheng Yong
bea9d60888 fsck.f2fs: set fix_on if error is detected
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
ce46aed259 fsck.f2fs: check ino in nat entry and node footer
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
31f461cd89 fsck.f2fs: cache all nat entries and check each of them
All nat entries are cached during building nat_area_bitmap, so that, in
fsck_chk_meta, we can get and check blk_addr and ino directly, to see if
they are in the valid range. Also, blk_addr is checked to see if the block
is valid in sit's valid maps.

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
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
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