Commit Graph

212 Commits

Author SHA1 Message Date
zhang-daiyue
1799d79113 Revert "f2fs-tools: give less overprovisioning space"
This reverts commit 76a88baa90.

Signed-off-by: zhang-daiyue <zhangdaiyue1@huawei.com>
Change-Id: Id84af613696213680384d8dd9ef8e0b30c9d177b
2024-06-02 14:54:53 +08:00
Juhyung Park
7a64f18f69 fsck.f2fs: fix sanity check logic for cp_payload
cp_payload is set differently [1] when extended node bitmap feature is
enabled. Commit b79c3ba4ea broke fsck on f2fs file systems created on
2+ TB device with extended node bitmap feature enabled.

As the sanity check is for checking overflows, fix this to assume the max
possible cp_payload size under the extended node bitmap.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/tree/mkfs/f2fs_format.c?h=v1.15.0#n372 [1]
Fixes: b79c3ba4ea ("fsck.f2fs: sanity check cp_payload before reading checkpoint")
Reported-by: Alexander Koskovich <akoskovich@pm.me>
Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:47 +08:00
Jaegeuk Kim
76a88baa90 f2fs-tools: give less overprovisioning space
As f2fs becomes more resilient for GCs, let's give the marginal overprovision
space back to user.

Fix an issue where reserved_space > ovp_space, reported by Shinichiro.

Signed-off-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Chao Yu
b98aab471a fsck.f2fs: trigger repairing if filesystem has inconsistent errors
In auto/preen mode, let's trigger repairing if filesystem has
inconsistent errors.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Chao Yu
d2ab813581 fsck.f2fs: trigger repairing if filesystem was forced to stop
In auto/preen mode, let's trigger repairing if filesystem was forced
to stop.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Chao Yu
04b067cbb9 fsck.f2fs: export valid image size
Change to calculate and export max image size with valid blocks
used of image rather than last used block of image.

[FSCK] Max image size: xx MB, Free space: xx MB

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Robin Lee
a42e1108e1 Always use sparse/sparse.h when building for Android
Change-Id: Ic903ce09c93de75d6deb700a5a283638a912a25b
Test: fastboot erase userdata
2024-04-15 11:31:46 +08:00
Jaegeuk Kim
cd0f88bc6e f2fs-tools: use F2FS_BLKSIZE instead of PAGE_*_SIZE
We don't need to check the running kernel configuration.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
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
b5a09b25b7 Fix the struct f2fs_dentry_block definition
Fix the struct f2fs_dentry_block definition on systems for which
PAGE_SIZE != 4096. This patch does not change the struct f2fs_dentry_block
definition if PAGE_SIZE == 4096.

Cc: Peter Collingbourne <pcc@google.com>
Reported-by: Peter Collingbourne <pcc@google.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Chao Yu <chao@kernel.org>
Reviewed-by: Peter Collingbourne <pcc@google.com>
Tested-by: Peter Collingbourne <pcc@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:31:46 +08:00
Jaegeuk Kim
2205680313 android_config: add time headers
This allows f2fs_io report latency.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:29:16 +08:00
Jaegeuk Kim
839483e940 Check fallthrough in mount.h for Mac
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/os/base.h:128:23: error: missing ')' after 'do'
                      ^~~~~~~~~~~
external/f2fs-tools/include/f2fs_fs.h:81:24: note: expanded from macro 'fallthrough'
                    ~~ ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/os/base.h:128:22: note: to match this '('

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:29:16 +08:00
Martin Stjernholm
163b23d5ac Fix dependencies on linux/blkzoned.h when using Bionic.
This reverts commit adcec10b4dee ("Support zoned device if libc exists).

Signed-off-by: Martin Stjernholm <mast@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2024-04-15 11:29:16 +08:00
Jaegeuk Kim
172234a711 Support zoned device if libc exists
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:29:16 +08:00
Jaegeuk Kim
d0e53cc8aa f2fs-tools: do not use SG_IO in Android
Android security team does not allow to use SG_IO.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:29:16 +08:00
Jaegeuk Kim
e4ef43a7fb android_config: add missing uuid library
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-15 11:29:16 +08:00
Jaegeuk Kim
43aa4d3b7b f2fs-tools: use android config only if there's no config.h
commit 4d9c009c343ce1247d9df583b22110f348201b3d
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
Jaegeuk Kim
38f1e4903f f2fs-tools: use fsync() in Android
commit e5fe1a213698c6765ecf9aabddf1e461b50b9203
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
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
fefda1af29 android_config.h: add missing liblz4
commit a8fefc20bd4c030069f1d9e527ee04a0bb20e419
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
25d83da964 Fix PowerPC format string warnings
commit c491657c0eb68d01dee5cc66ee3909dba5523540
category: bugfix
issue: #I6VAS0
CVE: NA

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

__SANE_USERSPACE_TYPES__ must be defined before <linux/types.h> is
included. Hence this patch that moves the definition of that macro into
the source files that need it.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:50 +08:00
Bart Van Assche
5c5c31ca6b Suppress a compiler warning about integer truncation
commit 70e4139665cbcb7bde42cf004267dd97268f61b7
category: bugfix
issue: #I6VAS0
CVE: NA

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

This patch prevents that older compilers report the following warning:

f2fs_format.c: In function ‘f2fs_prepare_super_block’:
../include/f2fs_fs.h:350:26: error: conversion from ‘unsigned int’ to ‘__uint16_t’ {aka ‘short unsigned int’} changes value from ‘4076150800’ to ‘8208’ [-Werror=overflow]
  350 | #define F2FS_SUPER_MAGIC 0xF2F52010 /* F2FS Magic Number */
      |                          ^~~~~~~~~~
 ../include/f2fs_fs.h:574:49: note: in expansion of macro ‘cpu_to_le16’
  574 | #define set_sb_le16(member, val)  (sb->member = cpu_to_le16(val))
      |                                                 ^~~~~~~~~~~

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
094b306b3b Annotate switch/case fallthrough
commit 7a1206adf33595a50b669d4027b72ad0786fb12f
category: bugfix
issue: #I6VAS0
CVE: NA

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

Just like in the Linux kernel source code, annotate switch/case
fallthrough.

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
20a09c8920 configure.ac: Detect selinux/android.h
commit ef011a49f3c640c59c7e21c3816d01c039711c58
category: bugfix
issue: #I6VAS0
CVE: NA

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

The selinux/android.h header file is available in Android but not in the
Android NDK. Hence this patch that detects presence of that header file
at configure time.

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
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
da00029bf5 Include <stddef.h> instead of defining offsetof()
commit 24663b62275c969f46203ccca2594323a8e07085
category: bugfix
issue: #I6VAS0
CVE: NA

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

Prepare for enabling -Wmacro-redefined.

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
c8dabbba7a Move the be32_to_cpu() definition
commit cdefef0d077de556bc30e79e1bdd527b9bad6bb9
category: bugfix
issue: #I6VAS0
CVE: NA

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

Move the be32_to_cpu() definition next to the little endian conversion
functions. This patch improves portability since the MinGW ntohl()
function exists in another library than the C library.

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
ed86f575e9 Remove unnecessary __attribute__((packed)) annotations
commit 1612bf99de322e2554a90dced7337ff2d8d1ded6
category: bugfix
issue: #I6VAS0
CVE: NA

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

Applying the __attribute__((packed)) annotation to members that do not
need it impacts performance negatively on architectures that do not
support efficient unaligned accesses (e.g. ARMv7). Hence minimize the
__attribute__((packed)) annotations.

See also CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS in the Linux kernel.

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
445873df9c f2fs_fs.h: Use standard fixed width integer types
commit 7a5109ff62c97646276db38aa5cdf805e43ed8ea
category: bugfix
issue: #I6VAS0
CVE: NA

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

Use uint64_t instead of __u64 in the definitions of the endianness
conversion macros. This patch fixes the following compiler warning:

dir.c: In function ‘f2fs_create’:
dir.c:785:16: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 12 has type ‘long long unsigned int’ [-Wformat=]
  785 |         MSG(1, "Info: Create %s -> %s\n"
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
../include/f2fs_fs.h:252:32: note: in definition of macro ‘MSG’
  252 |                         printf(fmt, ##__VA_ARGS__);                     \
      |                                ^~~

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
a86f797930 Verify structure sizes at compile time
commit 9425b47b897e690c71a337c0c93477bfd6fa1997
category: bugfix
issue: #I6VAS0
CVE: NA

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

Before modifying the __attribute__((packed)) annotations, let the
compiler verify the sizes of on-disk data structures.

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
e57ee3aa0b Change one array member into a flexible array member
commit 006bb1305a865e69f6b11f11c5dd017387a6e324
category: bugfix
issue: #I6VAS0
CVE: NA

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

Prepare for verifying structure sizes with static_assert().

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
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
Rosen Penev
de642e2612 f2fs-tools: use proper 64bit types for PPC
commit 46e1b83398523332521899b6bc88baeb9c8c3f91
category: bugfix
issue: #I6VAS0
CVE: NA

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

A specific define is needed. Fixes mostly issues with -Wformat.

Signed-off-by: Rosen Penev <rosenp@gmail.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
d8cf06b01b mkfs.f2fs: set required quota types only
commit 85cd72a2445a7c590852c829f3be23872c2cbe43
category: bugfix
issue: #I6VAS0
CVE: NA

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

This patch modifies enabling quota options in which enables user/group quotas
only if user specifies the "-O quota" especially.

1) -O quota : enables usr/grp
2) -O project_quota -O extra_attr : enabled prj
3) -O quota -O project_quota -O extra_attr : enables usr/grp/proj
4) -g android : enables usr/grp
5) -g android -O project_quota -O extra_attr : enables usr/grp/proj

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
b5cc82829b f2fs-tools: remove false failure alarm when fixing quota
commit ade81b96c9
category: bugfix
issue: #I6VAS0
CVE: NA

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

Even though fsck fixed quota issues, fsck returns failure status and
makes the user code misunderstand like errors are still there.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
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
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
Robin Hsu
32c3ee6915 fsck.f2fs: add basic compress related check/fix
commit 9429e865e8
category: bugfix
issue: #I6VAS0
CVE: NA

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

* check/fix i_compr_blocks
* check/fix compressed flag in i_flags when compression is not
  supported.

Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: minor coding style]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:46 +08:00
Wang Xiaojun
cdca0b4dff f2fs-tools: rebuild the quota inode if it is corrupted
commit 1228009520
category: bugfix
issue: #I6VAS0
CVE: NA

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

If the following process returns an error,
the quota inode, not the quota file, is damaged.
(fsck_chk_quota_node-->fsck_chk_node_blk-->sanity_check_nid)
The fsck does not have a process to rebuild the quota inode.

Because sanity_check_nid is not passed, fsck->nat_area_bitmap
can not be cleared, and then the NAT of quota will be nullify
during fix_nat_entries.

During the next fsck check, the quota inode check fails
because the address of the quota inode changes to 0.
In addition, in fsck_chk_quota_files-->f2fs_filesize_update,
data is written to address 0.

Therefore, when the quota inode is corrupted, we need to rebuild it.

Signed-off-by: Wang Xiaojun <wangxiaojun11@huawei.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
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
5d28af0d5f sload.f2fs: use F2FS_COMPRESS_RELEASED instead of IMMUTABLE bit
commit 820b5e3723
category: bugfix
issue: #I6VAS0
CVE: NA

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

Let's use F2FS_COMPRESS_RELEASED to disallow writes only.

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
Jaegeuk Kim
9ca4326e4a fsck.f2fs: add "-l" to show the layout information
commit a9594c6f56
category: bugfix
issue: #I6VAS0
CVE: NA

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

This patch add an option to print out superblock and checkpoint only.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:45 +08:00
Dongwoo Lee
b0ca57aa78 tools: Introduce f2fslabel
commit 6afd3e9df0
category: bugfix
issue: #I6VAS0
CVE: NA

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

Although many other filesystems provide a tool for changing volume
label, e.g. e2label for ext filesystem, but f2fs has no way to change
volume label except set it while formatting with mkfs.f2fs.

This introduces f2fslabel, simple tool for changing label of f2fs
volume.

Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>

 create mode 100644 man/f2fslabel.8

Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:45 +08:00
Daniel Abrecht
ea01d23fa6 Add -P option to preserve file owner
commit 80dba0f975
category: bugfix
issue: #I6VAS0
CVE: NA

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

I use user namespaces & debootstrap to bootstrap a system, and then
copy that into an image using sload.f2fs. However, without an option to
preserve the owner user & group of files, some files end up being owned
by the wrong user / group (0:0), which causes all kinds of other issues

This patch adds an option -P to preserve the user and group of files.

Signed-off-by: Daniel Abrecht <public@danielabrecht.ch>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:44 +08:00
Jaegeuk Kim
83c124114a libzoned: use blk_zone_v2 and blk_zone_report_v2 by default
commit 73c0871641
category: bugfix
issue: #I6VAS0
CVE: NA

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

Old blk_zone and blk_zone_report should be compatible with v2.
And, old blk_zone_report uses reserved[4] which breaks the build.

struct blk_zone_report {
        __u64           sector;
        __u32           nr_zones;
        __u8            reserved[4];
        struct blk_zone zones[0];
};

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:44 +08:00
Jaegeuk Kim
342053b6d0 f2fs-tools: fix wrong blk_zone_rep_v2 definition
commit 9cb5150afa
category: bugfix
issue: #I6VAS0
CVE: NA

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

If HAVE_BLK_ZONE_REP_V2 id defined, we should set v2.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2023-04-13 14:13:44 +08:00