Commit Graph

23 Commits

Author SHA1 Message Date
Bart Van Assche
cdd66bafeb Improve compile-time type checking for f2fs_report_zone()
Change the type of the third argument of f2fs_report_zone() from void *
into struct blk_zone * to enable type checking.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Bart Van Assche
a491213a0d Fix f2fs_report_zone()
The definition of struct blk_zone_report is as follows:

	struct blk_zone_report {
		__u64		sector;
		__u32		nr_zones;
		__u32		flags;
		struct blk_zone zones[0];
	};

Since f2fs_report_zone() allocates the above data structure with
malloc() and since f2fs_report_zone() only initializes the sector and
nr_zones members, the flags member is not initialized. Modify
f2fs_report_zone() such that 0 is passed as flags to the
BLKREPORTZONE ioctl instead of a random value. This has been
discovered by reading the source code.

Cc: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fixes: 6d7c7b785f ("libf2fs_zoned: Introduce f2fs_report_zone() helper function")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Jaegeuk Kim
72de6cc108 libzone: remove duplicate header
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:29:16 +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
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
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
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
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
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
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
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
Hyojun Kim
b44f7262a1 mkfs.f2fs: Windows Android SDK support
This patch enables cross compilation for Windows Android SDK
by using ANDROID_WINDOWS_HOST.

Signed-off-by: Hyojun Kim <hyojun@google.com>
2017-12-04 18:48:12 -08:00
Jaegeuk Kim
f407393385 f2fs-tools: initialize and avoid build warning for android
This patch initialize one variable for android build.
In addition, it avoids there-in build warnings.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2016-11-10 14:17:16 -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
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
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