Commit Graph

141 Commits

Author SHA1 Message Date
y30045862
2ba6b2b207 f2fs-tools构建规范化整改
Signed-off-by: yangjingbo10 <yangjingbo10@huawei.com>

Change-Id: I1aae1cb27162594dae1e395f46fcf0833750e6d0
2023-06-21 09:25:04 +08:00
Jaegeuk Kim
b844b4b34c f2fs-tools: show segment/section layout correctly
commit 3af62be37cd2407da1f44396cd9390bd560ed01f
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This patch fixes wrong segment/section print-outs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:52 +08:00
Jaegeuk Kim
89c91958fa f2fs-tools: support zoned device in Android
commit ea9921f4f5b947084a70a94573c472bd953e1c0d
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This requires to change Android.bp in AOSP.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Change-Id: I28a4a701513cb2420cdf0e0e2aa3f60e712f2fcb
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:51 +08:00
Jaegeuk Kim
70c040387e libf2fs_io: add unused mactor to avoid build failure
commit 0c54cf767f5a10c8293358a991ba432d8ff0476d
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:51 +08:00
Bart Van Assche
5a3dc5cd85 Change #ifdef _WIN32 checks into #ifdef HAVE_.*
commit b964b79d495d058f645f5a63357699a6c295025e
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

It is recommended to test a HAVE_* macro instead of directly testing the
host type in source code. Hence this patch.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:50 +08:00
Bart Van Assche
89274e8c32 configure.ac: Detect the sparse/sparse.h header
commit 2e59ab8fa6519e1169631189bd50810cb6b49426
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

The <sparse/sparse.h> header is available in Android but not in the
Android NDK. Hence this patch that only includes the sparse header file
if it is available.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:49 +08:00
Bart Van Assche
b85e86c3c0 Change the ANDROID_WINDOWS_HOST macro into _WIN32
commit f3033fbc8ab80a026740171cdbad44d8bd5fd882
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This makes it easier to build f2fs-tools for Windows.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:48 +08:00
Bart Van Assche
a8c6a6d93f Switch from the u_int to the uint types
commit 87d7a95e3134b668e9f1e8519a19f390509fac60
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

Many format strings use one of the PRI* macros. These macros are compatible
with the uint types but not with the u_int types. Hence this patch
that switches from the u_int to the uint types.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:48 +08:00
Luis Chamberlain
e5e0cf64a2 libf2fs: don't allow mkfs / fsck on non power-of-2 zoned devices
commit 6afcf6493578e77528abe65ab8b12f3e1c16749f
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

f2fs currently only work with zoned storage devices with a zone
size which is a power of 2 (PO2). So check if a non-power of 2
zoned device is found, and if so disallow its use. This prevents
users from incorrectly using these devices.

This is a non-issue today given today's kernel does not allow NPO2
zoned devices to exist as a block device. But NPO2 zoned devices do exist
so proactively put a stop-gap measure in place to prevent it from being
incorrectly used.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:47 +08:00
Jaegeuk Kim
01d4637451 mkfs.f2fs: fix wrong indentation and clean up
commit 97ce230ab6074acfe2717ed99a7196d7a6502f16
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:47 +08:00
Jaegeuk Kim
5433e0e2fb mkfs.f2fs: wipe other FS magics given -f
commit 1603a3d1de
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This patch fixes the below stale magic info.

$ mkfs.btrfs -f test.img
btrfs-progs v5.10.1
See http://btrfs.wiki.kernel.org for more information.

Label:              (null)
UUID:               941d2db7-3ece-4090-8b22-c4ea548b5dae
Node size:          16384
Sector size:        4096
Filesystem size:    1.00GiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP              51.19MiB
  System:           DUP               8.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Runtime features:
Checksum:           crc32c
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1     1.00GiB  test.img

$ hexdump -s 0x10000 -n 128 -C test.img
00010000  81 29 94 0a 00 00 00 00  00 00 00 00 00 00 00 00  |.)..............|
00010010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00010020  94 1d 2d b7 3e ce 40 90  8b 22 c4 ea 54 8b 5d ae  |..-.>.@.."..T.].|
00010030  00 00 01 00 00 00 00 00  01 00 00 00 00 00 00 00  |................|
00010040  5f 42 48 52 66 53 5f 4d  05 00 00 00 00 00 00 00  |_BHRfS_M........|
00010050  00 40 d2 01 00 00 00 00  00 40 50 01 00 00 00 00  |.@.......@P.....|
00010060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00010070  00 00 00 40 00 00 00 00  00 00 02 00 00 00 00 00  |...@............|
00010080

$ mkfs.f2fs -t 0 -f test.img

        F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-12-28)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is disabled
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 2097152 (1024 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
  "Linux version 5.10.46-4rodete1-amd64 (glinux-team@google.com) (gcc-10 (Debian 10.2.1-6+build2) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.46-4rodete1 (2021-08-20)"
Info: Overprovision ratio = 6.360%
Info: Overprovision segments = 68 (GC reserved = 39)
Info: format successful

$hexdump -s 0x10000 -n 128 -C test.img
00010000  c2 8a c8 26 00 00 00 00  00 00 00 00 00 00 00 00  |...&............|
00010010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00010020  92 ab 3f c6 b7 82 49 5e  93 23 e8 c9 e9 45 7d ac  |..?...I^.#...E}.|
00010030  00 00 01 00 00 00 00 00  01 00 00 00 00 00 00 00  |................|
00010040  5f 42 48 52 66 53 5f 4d  05 00 00 00 00 00 00 00  |_BHRfS_M........|
00010050  00 40 d2 01 00 00 00 00  00 40 50 01 00 00 00 00  |.@.......@P.....|
00010060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00010070  00 00 00 40 00 00 00 00  00 00 02 00 00 00 00 00  |...@............|
00010080

--- After this patch ---
$ mkfs.f2fs -t 0 -f test.img

        F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-12-28)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is disabled
        test.img appears to contain an existing filesystem (btrfs).
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 2097152 (1024 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
  "Linux version 5.10.46-4rodete1-amd64 (glinux-team@google.com) (gcc-10 (Debian 10.2.1-6+build2) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.46-4rodete1 (2021-08-20)"
Info: Overprovision ratio = 6.360%
Info: Overprovision segments = 68 (GC reserved = 39)
Info: format successful

$ hexdump -s 0x10000 -n 128 -C test.img
00010000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00010080

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:46 +08:00
Jaegeuk Kim
5ff868458b Avoid redefined ALIGN_UP
commit 3fd996cc16
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This tries to avoid build warning.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:46 +08:00
Daeho Jeong
958d9fe877 f2fs-tools: add periodic check in kernel version check
commit 9ee091e819
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

In previous, we did a full scan right after kernel version is changed
and it triggered many unnecessary full scan whenever a newly built
kernel is downloaded. Plus, we are lack of a periodic health check of
on-disk filesystem images. So, I added a monthly periodic check after
a new vesion is updated.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:46 +08:00
Jaegeuk Kim
b7bb88a0ba fsck|dump.f2fs: add -M to get file map
commit acd2518e26
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This option shows all the file names in the disk.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:45 +08:00
Jaegeuk Kim
8109355601 f2fs-tools: support small RO partition
commit 1d2683f551
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

This patch adds a readonly feature on small partitions by eliminating
on-disk layout for data writes such as provisioning/reserved space and
SSA.

This requires f2fs updates to understand RO feature in superblock.

Tested 4 cases:
 sload.f2fs -c -a lz0 -f kernel/fs $DEV
 sload.f2fs -c -a lz4 -f kernel/fs $DEV
 sload.f2fs -c -r -a lz4 -f kernel/fs $DEV
 sload.f2fs -c -L 3 -r -a lz4 -f kernel/fs $DEV

after:
 mkfs.f2fs -O ro,compression,extra_attr -f $DEV
 fsck.f2fs $DEV

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:45 +08:00
lijiazi
0c15655e55 f2fs-tools: correct get kernel version logic
commit 3218ff95d9
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

Current implementation, If define WITH_KERNEL_VERSION
get_kernel_uname_version just return release info, not define
WITH_KERNEL_VERSION, return release and version info.
So remove "!" in get_kernel_uname_version, make logic more clear.

Signed-off-by: lijiazi <lijiazi@xiaomi.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:45 +08:00
Jaegeuk Kim
7774d00ba2 resize.f2fs: fix wrong ovp calculation
commit f056fbeff0
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

beroal reported a mount failure due to broken valid_user_blocks.
[ 6890.647749] F2FS-fs (loop0): Wrong valid_user_blocks: 16040048,
user_block_count: 10016768

From fsck,

segment_count_main                      [0x    9a95 : 39573]
-> 39573 * 2MB = 78GB as user space

overprov_segment_count                  [0x    4e29 : 20009]
-> 20009 * 2MB = 40GB as overprovisioned space which user can't see.

But,
[FSCK] valid_block_count matching with CP             [Ok..] [0xf4c070]
-> 0xf4c070 = 16040048

valid_block_count                       [0x  f4c070 : 16040048]
-> So, this is correct.

It turns out resize.f2fs gave very large and wrong overprovisioning space
result in shortage of user blocks. The root cause was f2fs_get_usable_segments()
didn't consider resize case which needs segment_count_main from new superblock.

Fixes: f8410857b7 ("f2fs-tools: zns zone-capacity support")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:44 +08:00
Junyong Sun
ce1c9b8e99 libf2fs: fix memory leak caused by get_rootdev()
commit f0fda11925
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

memory which malloc for uevent don't free at get_rootdev(),
it would cause memory leak, so free it before return.

Signed-off-by: Junyong Sun <sunjy516@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:44 +08:00
Robin Hsu
ecdcd6189d f2fs-tools:sload.f2fs compression support
commit b585244e72
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

Add F2FS compression support for sload
* Support file extension filter, either default-accept or default-deny
  policy
* Support choice of compression algorithm, LZO (version 2) or LZ4
  (default)
* Support custom log of cluster size
* Support minimum number of compressed blocks per cluster (default 1).
  A cluster will not be compressed if the number can not be met.
* suuport -r (read-only) option
  This releases compressed blocks to secure free space in advance. Note that,
  all compressed files will have the immutable bit.
* Added manpage update
* Remove unecessary qbuf allocation (Jaegeuk, suggested by Satya)

Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: fix some bugs and refactor names]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>

 create mode 100644 fsck/compress.c
 create mode 100644 fsck/compress.h

Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:44 +08:00
张文迪
f8224a8bdc f2fs_tools部件化
Signed-off-by: 张文迪 <zhangwendi3@huawei.com>
2022-08-23 10:40:59 +08:00
张文迪
4278e853b7 fix updater /data
Signed-off-by: 张文迪 <zhangwendi3@huawei.com>
2022-08-16 10:09:28 +08:00
jiahaoluo
567e0db420 change part name to storage_service
Signed-off-by: jiahaoluo <luojiahao5@huawei.com>
2022-02-09 15:01:50 +08:00
xlfeng
a48316a6e8 BUILD,gn文件中subsystem_name的值改为filemanagement,路径/e2fsprogs/f2fs-tools-1.14.0改为/f2fs-tools/,config名称e2fsprogs-defaults改为f2fs-defaults。fsck/BUILD.gn增加symlink_target_name。
Signed-off-by: xlfeng <xulifeng7@huawei.com>
2022-01-12 17:11:18 +08:00
xlfeng
059d1b3f4c BUILD.gn and config.h modify Huawei license to GPL-2.0 license.Add #ifndef CONFIG_H #define CONFIG_H on the head of file and #endif on the end of config.h. Modify the value of Name in README.OpenSource.
Signed-off-by: xlfeng <xulifeng7@huawei.com>
2021-12-20 21:44:20 +08:00
xlfeng
81c31712a5 Build successful,add one config.h and four BUILD.gn, modify seven files to relsove macro redefined,.Delete two Android.bp files.Add OAT related files,OAT.xml,README.OpenSource and README.md.
Signed-off-by: xlfeng <xulifeng7@huawei.com>
2021-12-15 10:45:47 +08:00
Aravind Ramesh
f8410857b7 f2fs-tools: zns zone-capacity support
NVM Express Zoned Namespace (ZNS) devices can have zone-capacity(zc) less
than the zone-size. ZNS defines a per zone capacity which can be equal
or less than the zone-size. Zone-capacity is the number of usable blocks
in the zone. If zone-capacity is less than zone-size, then the segments
which start at/after zone-capacity are considered unusable. Only those
segments which start before the zone-capacity are considered as usable
and added to the free_segment_count and free_segment_bitmap of the kernel.
In such cases, the filesystem should not write/read beyond the
zone-capacity.

Update the super block with the usable number of blocks and free segment
count in the ZNS device zones, if zone-capacity is less than zone-size.
Set reserved segment count and overprovision ratio based on the usable
segments in the zone.

Allow fsck to find the free_segment_count based on the zone-capacity and
compare with checkpoint values.

Signed-off-by: Aravind Ramesh <aravind.ramesh@wdc.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
[Jaegeuk Kim: add UNUSED to is_usable_seg()]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-08-20 09:08:34 -07:00
Jaegeuk Kim
3aef9bc820 mkfs.f2fs: add casefolding and project quota config
This can be used for Android build support.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-07-20 17:39:02 -07:00
Jaegeuk Kim
ec0f3c910e mkfs.f2fs: should initialize sparse file in Windows
Otherwise it fails to format in Windows.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-07-20 17:39:02 -07:00
Jaegeuk Kim
a60cd1a3f9 libf2fs: fix build error on Windows
Windows doesn't support S_ISREG, so let's avoid depedency.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-06-08 11:37:28 -07:00
Chao Yu
88d1bd9615 fsck.f2fs: fix wrong addrs_per_{inode,block}
generic/339 reports below assertion on image w/ compression feature
enabled.

[ASSERT] (f2fs_check_dirent_position:1366)  -->
Wrong position of dirent pino:4521, name:"....", level:9, dir_level:0,
pgofs:1880, correct range:[1882, 1883]

The root cause is we calculate blkaddr number in direct node
incorrectly for directory inode, since during calculation, we only
need align blkaddr number to cluster size for regular inode rather
than directory inode, let's fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-05-06 07:41:06 -07:00
Chao Yu
64750e90d6 fsck.f2fs: allow --dry-run to check readonly mounted fs
As Ondřej Jirman <megi@xff.cz> reported:

I was trying to run: fsck.f2fs --dry-run /dev/mmcblk0p2 on a RO mounted device,
and fsck refuses to run. Strace shows that it tries to open the block device
with O_EXCL even in RO mode, which will always fail if the block device
is mounted.

fsck.f2fs --dry-run /dev/mmcblk0p2
Info: Dry run
Info: Mounted device!
Info: Check FS only on RO mounted device
	Error: Failed to open the device!

I suggest not using O_EXCL for --dry-run check.

Let's change to allow --dry-run to check readonly mounted fs.

Reported-by: Ondřej Jirman <megi@xff.cz>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-02-24 14:01:53 -08:00
Chao Yu
fdd47b2ea7 f2fs-tools: support data compression
This patch adds to support compression, introducing '-O compression'
option to enable this feature in image.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-01-14 07:42:54 -08:00
Robin Hsu
70c5bab971 libf2fs_io: Add user-space cache
Implemented cache options in F2FS configuration 'c' (i.e. user
options):
    * use c.cache_config.num_cache_entry to set the number of
      cache entries (in block), minimum 1024, or 0 to disable cache.
    * use c.cache_config.max_hash_collision to set maximum hash
      collision (max 16).
    * use c.cavhe_config.dbg_en to enable printing of debug messages.

Cache properties:
    * Per block save based (block size = f2fs block size = 4K Bytes)
    * Device block indices are used to hash (simple modular hash
      function) to cache indices.
    * A hash collision (when a block is hashed to an already occupied
      cache block) will trigger offset-based relocation to max 16
      other places, at first empty slot found policy.
    * A hash collision with all 17 possible relocating places occupied
      will evict the oldest used one (replaced by the new read block).
      A global 'use' tick is kept ticking-up per block read for this
      purpose.
    * On write cache hit, it will update the corresponding cached
      block.
    * On write cache miss, the data won't be cached.
    * Write-through policy only: never delayed write.
    * On read cache hit, it returns the cached block.
    * On read cache miss, it issues an I/O read to the kernel, and
      then caches and returns the block.
    * Currently read ahead is not implemented.  Yet, the read ahead
      logic is kept as before, i.e. using kernel's read ahead
      mechanism.

Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: Fix one bug in dcache_update_rw()]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-01-14 07:42:02 -08:00
Jaegeuk Kim
75cf4ec7e7 f2fs-tools: handle /sys is not mounted
Format a partition, even if /sys is not mounted.

Reported-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-01-14 07:42:02 -08:00
Jaegeuk Kim
1126e38155 fsck.f2fs: add --{no-}kernel-check to bypass kernel version diff or not
Given this option, fsck.f2fs does not run fsck forcefully, even if kernel
is updated. Android devices will do --kernel-check by default, while others
will not.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2020-01-14 07:42:02 -08:00
Robin Hsu
27be95ee8f f2fs-tools: reuse same pointer, exit on error without clean-up
This patch tries to fix memory leak problem reported in Android.

Fixed the following problems in fsck.f2fs, make_f2fs and sload_f2fs:
    * reuse of same pointer without clean-up
    * exit on error without clean-up

Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: add missing definition to avoid build error]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-12-19 09:39:14 -08:00
Jaegeuk Kim
17a7e7e0f0 f2fs-tools: avoid unused parameter build errors
This patch specifies unused parameters explicitly to avoid build errors.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-12-18 17:37:22 -08:00
Shin'ichiro Kawasaki
1d145cb86b libf2fs_zoned: Introduce f2fs_reset_zone() helper function
To prepare for write pointer consistency fix by fsck, add
f2fs_reset_zone() helper function which calls RESET ZONE command. The
function is added to lib/libf2fs_zoned which gathers zoned block device
related functions.

When f2fs-tools are built without blkzoned.h kernel header, the helper
function f2fs_reset_zone() prints an error message as other helper
functions in lib/libf2fs_zoned print. To make the message consistent
through the all helper functions, modify message strings in
f2fs_check_zones() and f2fs_reset_zones().

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-12-09 17:23:19 -08:00
Shin'ichiro Kawasaki
6d7c7b785f libf2fs_zoned: Introduce f2fs_report_zone() helper function
To prepare for write pointer consistency check by fsck, add
f2fs_report_zone() helper function which calls REPORT ZONE command to
get write pointer status of a single zone. The function is added to
lib/libf2fs_zoned which gathers zoned block device related functions.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-12-09 17:23:19 -08:00
Shin'ichiro Kawasaki
512b8426ac libf2fs_zoned: Introduce f2fs_report_zones() helper function
To prepare for write pointer consistency check by fsck, add
f2fs_report_zones() helper function which calls REPORT ZONE command to
get write pointer status. The function is added to lib/libf2fs_zoned
which gathers zoned block device related functions.

To check write pointer consistency with f2fs meta data, fsck needs to
refer both of reported zone information and f2fs super block structure
"f2fs_sb_info". However, libf2fs_zoned does not import f2fs_sb_info. To
keep f2fs_sb_info structure out of libf2fs_zoned, provide a callback
function in fsck to f2fs_report_zones() and call it for each zone.

Add SECTOR_SHIFT definition in include/f2fs_fs.h to avoid a magic number
to convert bytes into 512B sectors.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-12-09 17:23:19 -08:00
Daniel Rosenberg
ce64ea0815 f2fs-tools: Add support for Casefolding
This adds support for f2fs casefolding. Similarly to ext4 casefolding,
this is controlled per-folder via the +F attribute. It can be toggled on
empty directories only. It is not currently compatible with encryption,
but that will likely change.

When enabling the casefold feature, use the -C flag. The format is:
-C encoding[:flag1,flag2,etc]

Signed-off-by: Daniel Rosenberg <drosen@google.com>
[Jaegeuk Kim: print "casefold" in sb->feature]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-27 14:51:05 -07:00
Surbhi Palande
fe154d5250 libf2fs: Throw an error when zone dev info not found
When the -m option is specified to format a Zoned device,
do not fall back to the non-zoned mode in case information
about the device is not found.

Explicitly specify this error to the user.

Signed-off-by: Surbhi Palande <csurbhi@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:58 -07:00
Chao Yu
523e36856f dump.f2fs: allow to dump data on mounted device
In generic/38[3456], we use quotactl(2) to check if prjquota is
enabled on the given device (src/feature -P $dev in _require_prjquota),
and quotactl(2) requires the given device is a mounted device.

So it requires dump.f2fs to list/check enabled features on a mounted
device, let's relieve to allow such operation.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:58 -07:00
Xue Liu
ee0025a13f f2fs-tools: calculate inode checksum and writeback
Calculate inode checksum and writeback when processing
sload or resize.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
[Chao Yu: change commit message and code]
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:51 -07:00
Shin'ichiro Kawasaki
19ca76f101 f2fs-tools: Fix device zoned model detection
A partition device does not have the "zoned" nor "chunk_sectors" sysfs
attribute files. Only the owner block device of the partition has these
files. This causes the detection of the zoned model and zone size of a
partition device to fail when executing mkfs.f2fs.

Fix this problem by using the owner device sysfs directory as the base
directory for accessing the zoned and chunk_sectors files. This is done
by using the device major:minor symbolic link under the /sys/dev/block
directory, reading this link and removing the partition device name from
the link path for a partition device (which is indicated by the presence
of the "partition" file under the directory).

Also add a check for the ENOENT error when opening the device "zoned"
sysfs attribute file. The absence of this file indicates that the
kernel does not support zoned block devices. Since the device file is
already open, it exists, and so the device can safely be assumed as not
being zoned.

Changes from v2:
* Addressed Chao Yu's comment on snprintf buffer length

Changes from v1:
* Addressed Chao Yu's comment on ENOENT and return value checks
* Rewrite of sysfs file handling (simplified)
* Rebased on dev-test tree

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:51 -07:00
Damien Le Moal
23b8762113 f2fs-tools: Allow using host-aware devices as regular devices
Host-aware zoned block devices can accept random writes anywhere and so
do not require to be handled under F2FS_ZONED_HM mode. Allow host aware
disks to be treated as regular devices if c.zoned_mode is false, that
is, if the -m option is not specified in mkfs.f2fs.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: fixed wrong spaces]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:51 -07:00
Damien Le Moal
35f8b3cd37 f2fs-tools: Fix multi-device format with zoned devices
There is no need to require conventional zones for a zoned block device
that is not the first device of a multi-device volume. As a result,
there is no need to check the number of conventional zones of the
device if the device index is not 0.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:51 -07:00
Damien Le Moal
658a0c8f20 f2fs-tools: Improve zoned model check
Return an error if an unknown zoned model is reported for a device or
if parsing of the device zoned model fails. Also add comments to
briefly explain the zone models and what to do in the absence of a
kernel reported zoned model for a device.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
[Jaegeuk Kim: Fix one missing function def change]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-08-20 11:23:51 -07:00
Chao Yu
24dec562ae f2fs-tools: allow unfixed f2fs_checkpoint.checksum_offset
Previously, f2fs_checkpoint.checksum_offset points fixed position of
f2fs_checkpoint structure:

"#define CP_CHKSUM_OFFSET	4092"

It is unnecessary, and it breaks the consecutiveness of nat and sit
bitmap stored across checkpoint park block and payload blocks.

This patch allows f2fs-tools to handle unfixed .checksum_offset.

In addition, for the case checksum value is stored in the middle of
checkpoint park, calculating checksum value with superposition method
like we did for inode_checksum.

In addition, add below change:
- using MAX_BITMAP_SIZE_IN_CKPT to clean up codes.
- introduce verify_checksum_chksum() to verify chksum_{offset,value}

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-05-20 17:29:55 -07:00
Chao Yu
37e7403810 mkfs.f2fs: write fill chunk in sparse file for zeroed block
As zhaowuyun reported:

we met one problem of f2fs, and found one issue of make_f2fs, so I write
this email to search for your help to confirm this issue.

The issue was found on one of Android projects. We use f2fs as the filesystem
of userdata, and make sparse userdata.img using following command, which
invoked in script mkf2fsuserimg.sh
make_f2fs -S $SIZE -f -O encrypt -O quota -O verity $MKFS_OPTS $OUTPUT_FILE

use fastboot to flash this userdata.img to device, and it encountered f2fs
problem and leading to the mount fail of data partition.

we can make this issue 100% persent reproduced by making the data partition
dirty before flashing userdata.img.

suspect that issue is caused by the dirty data in the data partition.
so we checked that source code of make_f2fs in f2fs-tool, found that when
making f2fs, it use dev_fill to do some process:

...

we change code to the following, and the issue is gone.

if (c.sparse_mode)
       return dev_write(buf, offset, len);

Chao Yu:
>
> After checking the codes, IIUC, I guess the problem here is, unlike
> img2simg, mkfs.f2fs won't record zeroed block in sparse image, so
> during transforming to normal image, some critical region like
> NAT/SIT/CP.payload area weren't be zeroed correctly, later kernel may
> load obsoleting data from those region.
>
> Also, The way you provide will obviously increase the size of sparse
> file, since with it we need to write all zeroed blocks of
> NAT/SIT/CP.payload to sparse file, it's not needed.
>
> Not sure, maybe we should use sparse_file_add_fill() to record zeroed
> blocks, so that this will make formatted image more like img2simged one.

Jaegeuk:
> We have to call sparse_file_add_fill() for dev_fill().

This patch fixes to support writing fill chunk sparse file for those
zeroed blocks in mkfs.f2fs.

Reported-and-tested-by: zhaowuyun <zhaowuyun@wingtech.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-05-20 17:29:50 -07:00