Commit Graph

983 Commits

Author SHA1 Message Date
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
Mike Frysinger
0e14e39d38 fibmap: pull in sys/sysmacros.h for major/minor
These funcs are provided by sys/sysmacros.h, so include the header
directly.  Building with alternative C libraries can fail otherwise
like so:

fibmap.c: In function 'print_stat':
fibmap.c:36:32: warning: implicit declaration of function 'major' [-Wimplicit-function-declaration]
  printf("dev       [%d:%d]\n", major(st->st_dev), minor(st->st_dev));
                                ^
fibmap.c:36:51: warning: implicit declaration of function 'minor' [-Wimplicit-function-declaration]
  printf("dev       [%d:%d]\n", major(st->st_dev), minor(st->st_dev));
                                                   ^
fibmap.o: In function 'print_stat':
tools/fibmap.c:36: undefined reference to 'minor'
tools/fibmap.c:36: undefined reference to 'major'
fibmap.o: In function 'stat_bdev':
tools/fibmap.c:59: undefined reference to 'minor'
tools/fibmap.c:59: undefined reference to 'major'

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-04-18 21:10:59 -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
Jaegeuk Kim
759df520ae f2fs-tools: release 1.6.1
This version mostly fixes the bugs in fsck.f2fs.
Especially, this fixes a segfault bug when executing "fsck.f2fs -a".

Note that, some body codes (not interfaces) in libf2fs_format.la and libf2fs.la
were changed.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-22 14:06:51 -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
Fan Li
b385e9f93a mkfs.f2fs: set segment_count in super block correctly
Now f2fs will check statistics recorded in super block in
sanity_check_area_boundary() during mount. If the number of segments
per zone is greater than 1, and the disk space isn't aligned with zone,
mount will fail due to following condition:

main_blkaddr + (segment_count_main << log_blocks_per_seg) !=
		segment0_blkaddr + (segment_count << log_blocks_per_seg)

This is because when the length of main area isn't aligned with zone,
mkfs doesn't add those excess segments to segment_count_main, but adds
them to segment_count.

Here align segment_count with zone size as well as segment_count_main
to prevent such problem.

Signed-off-by: Fan Li <fanofcode.li@samsung.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-03-16 12:46:13 -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
Junling Zheng
ecc43cc53f f2fs-tools: redefine MAX_SIT_BITMAP_SIZE
During mkfs, segment_count_sit is calculated using ALIGN and
SEG_ALIGN, which are both upward. Then, in some extreme scenarios,
such as 16TB, sit_ver_bitmap_bytesize got from segment_count_sit
will exceed MAX_SIT_BITMAP_SIZE, which is calculated in a downward
method.

Unify the two calculating methods and redefine MAX_SIT_BITMAP_SIZE
to prevent sit_ver_bitmap_bytesize overflowing.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-24 09:57:18 -08:00
Junling Zheng
ea34c1ce14 libf2fs: limit the total size up to 16T
F2FS can support 16T bytes at most. Limit the config.total_sectors
so that most parameters calculated according to it in sb/cp can be
limited correctly too.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-24 09:57:09 -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
50aa77b1d3 fsck.f2fs: check /proc/mounts first to detect readonly
Once f2fs_stop_checkpoint makes f2fs as readonly, only /proc/mounts shows
RDONLY whereas /etc/mtab does not.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-18 17:38:42 -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
Sheng Yong
1952ab467c f2fs-tools: fix endianness of on-disk check_sum in summary_footer
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-02-01 16:27:46 -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
ad042d9194 mkfs.f2fs: reset dnode with zeros
This patch fixes resetting dnode blocks recursively.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-23 22:29: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
Yunlei He
e9dfbbbce9 mkfs.f2fs: introduce zone align for main area
This patch calculate main area begin from a new zone,
avoid misalign if segments per zone is not 1.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Shuoran Liu <liushuoran@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-01-08 11:47:41 -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
d3258fa034 man: modify mkfs.f2fs man page
This patch adds missing [sectors] option in mkfs.f2fs, and removes
meaningless version.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-22 16:19:44 -08:00
Jaegeuk Kim
52dedc6b2f man: add missing man pages
This patch adds missing man pages.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-22 16:19:44 -08:00
Jaegeuk Kim
ffd8d0514a f2fs-tools: release 1.6.0
This version introduces defrag.f2fs newly, and some major bug fixes too.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-21 09:57:10 -08:00
Liu Xue
e12a3c3a82 mkfs.f2fs: fix check error when calloc sum_compact failure
We should check sum_compact value when deal with sum_compact
calloc failure.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-21 09:48:58 -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
Chao Yu
dbe78ae529 libf2fs: fix incorrect type define of declaration
When compiling f2fs toolset in 32-bits machine, following error was
reported:

libf2fs.c:342:5: error: conflicting types for 'find_next_bit_le'
../include/f2fs_fs.h:864:22: note: previous declaration of 'find_next_bit_le' was here
libf2fs.c:348:5: error: conflicting types for 'find_next_zero_bit_le'
../include/f2fs_fs.h:865:22: note: previous declaration of 'find_next_zero_bit_le' was here

This is because our type of return value(u64 in define) and (unsigned long
in declaration) of find_next_{,zero_}bit_le were not same in non-64-bits
machine:

extern unsigned long find_next_bit_le(const u8 *, u64, u64);
u64 find_next_bit_le(const u8 *addr, u64 size, u64 offset)

Fix it.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2015-12-18 14:13:05 -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