Commit Graph

333 Commits

Author SHA1 Message Date
Jaegeuk Kim
0fe50b6f26 libf2fs: avoid build warning
This avoids the below warnings.

libf2fs_zoned.c:39:8: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
fscanf(file, "%s", str);
      ^
libf2fs_zoned.c: In function 'f2fs_get_zone_blocks':
libf2fs_zoned.c:72:8: warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
fscanf(file, "%s", str);
      ^

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-01 17:27:35 -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
ebbfb5979e mkfs.f2fs: check zoned block devices configuration
Make sure the drive has enough randomly writeable zones from
the beginning of the partition to hold the meta data sections.

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
1e0f68d947 mkfs.f2fs: reset sequential zones on device discard
For a zoned blocks device, trim must reset all sequential zones
of the device.

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
9b51f80a47 mkfs.f2fs: check options for zoned block devices
Trim must not be disabled with zoned mode.
For host-managed zoned block devices, the zoned mode is mandatory.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-01 17:27:34 -07:00
Damien Le Moal
9691420a99 f2fs-tools: introduce support for zoned block devices
With the availability of the BLKREPORTZONE and BLKRESETZONE
ioctls, there is no need for using SG_IO to discover zoned
block devices characteristics. This simplifies the code.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-01 17:27:34 -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
Damien Le Moal
49bdd642dd f2fs-tools: add executable files to .gitignore
Git ignore executables fsck.f2fs, f2fstat, fibmap.f2fs
and parse.f2fs.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-31 14:48:41 -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
6e7c503a80 mkfs.f2fs: fix the discarding size for block device
This patch fixes wrong discarding size.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-18 14:33:07 -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
65f3d40f78 libf2fs: avoid garbage printout
This patch avoids to print garbage data.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-10-13 16:57:30 -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
Tobias Jakobi
e5b3ec89ee libf2fs: increase robustness when called on root device
On some systems '/proc/mounts' contains the entry '/dev/root'
as alias for the root device, while that alias doesn't actually
exist as symlink in /dev.

/proc/mounts:
/dev/root / f2fs rw,noatime,background_gc=on,user_xattr,acl,inline_data,extent_cache,active_logs=6 0 0

mount:
/dev/mmcblk1p1 on / type f2fs (rw,noatime,background_gc=on,user_xattr,acl,inline_data,extent_cache,active_logs=6)

If the root device is mounted RO, and we try to scan it, via
'fsck.f2fs /dev/mmcblk1p1', then fsck.f2fs exits because it can't
find the entry in /proc/mounts.

Try harder to identify the root device of the system first, and
in case we are operating on it, check also for '/dev/root' in mounts.

Signed-off-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-28 15:26:54 -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
Jaegeuk Kim
79b1858e79 libf2fs: use dev_read_block and dev_write_block
This patche tries to use dev_read_block and dev_write_block as much as possible.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-22 19:32:12 -07:00
Jaegeuk Kim
932d596a86 mkfs: get fd for f2fs_trim_device
This patch is to get a parameter for fd in f2fs_trim_device.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-09-22 15:48:13 -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
370f8c47b8 mkfs.f2fs: do not need strdup for parse_feature
strdup is useless here, with no free op with its return value.

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:39:19 -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
c6834e9cc4 libf2fs: show disk information
This adds to show disk information.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-08-04 19:30:02 -07:00
Jaegeuk Kim
d2446560e2 f2fs-tools: release 1.7.0
This version adds Host-managed SMR detection code.

libf2fs_format_la
 - changed its body

libf2fs_la
 - added zbc_scsi_report_zones()

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-07-29 10:14:43 -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
7b9c5fcdf1 mkfs: define DISCARD/SECDISCARD macro
If SECDISCARD/DISCARD is not defined, we can set it.
In Android, we must set -DWITH_BLKDISCARD to discard the partition.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-06-16 21:29:09 -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
Jaegeuk Kim
74673eb7e6 mkfs.f2fs: ZBC device support
This patch adds "-m" option to configure ZBC device.

This is to support host-managed SMR device and configure some major features
and on-disk layout in f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-06-08 10:10:38 -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
e52321f3eb script: add simple test script
This patch adds a script to test sload.f2fs, defrag.f2fs, and resize.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-04-18 21:11:26 -04: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