platform/upstream/f2fs-tools.git
4 years agof2fs-tools: introduce get_checkpoint_version() for cleanup
Chao Yu [Thu, 13 Jun 2019 08:09:03 +0000 (16:09 +0800)]
f2fs-tools: introduce get_checkpoint_version() for cleanup

Just cleanup, no logic change.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs-tools: detect corrupted sit journal
Chao Yu [Fri, 24 May 2019 08:52:41 +0000 (16:52 +0800)]
f2fs-tools: detect corrupted sit journal

Enables to detect corrupted sit journal
a) total count of entries.
b) segment no. in entry.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs-tools: update checkpoint data atomically
Chao Yu [Fri, 24 May 2019 08:26:40 +0000 (16:26 +0800)]
f2fs-tools: update checkpoint data atomically

This patch keeps line with f2fs kernel module for checkpoint update:
1. writeback all blocks inside checkpoint except last cp_park block;
2. fsync;
3. write last cp_park block;
4. fsync;

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs-tools: calculate inode checksum and writeback
Xue Liu [Fri, 24 May 2019 07:28:11 +0000 (15:28 +0800)]
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>
4 years agofsck.f2fs: Fix up nat journal corruption with -a (auto-fix) option
Sahitya Tummala [Fri, 24 May 2019 06:09:47 +0000 (11:39 +0530)]
fsck.f2fs: Fix up nat journal corruption with -a (auto-fix) option

Build segment manager and node manager always to catch and auto-fix
invalid NAT entries found in the NAT journal.

Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agofsck.f2fs: show elapsed time of full scan
Jaegeuk Kim [Tue, 21 May 2019 20:17:24 +0000 (13:17 -0700)]
fsck.f2fs: show elapsed time of full scan

This patch introduces the elapsed time of fsck.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs-tools: Fix device zoned model detection
Shin'ichiro Kawasaki [Mon, 22 Apr 2019 02:04:24 +0000 (11:04 +0900)]
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>
4 years agof2fs-tools: fix to check total valid block count before block allocation
Chao Yu [Mon, 15 Apr 2019 09:14:38 +0000 (17:14 +0800)]
f2fs-tools: fix to check total valid block count before block allocation

Now, kernel can catch incorrect total valid block count which is exceed
max user block count of image.

Then, generic/051,476 of fstest reports below message:

Apr 15 11:08:03 szvp000201624 kernel: [ 2533.515813] F2FS-fs (zram1): Wrong valid_user_blocks: 469505, user_block_count: 469504
Apr 15 11:08:03 szvp000201624 kernel: [ 2533.519166] F2FS-fs (zram1): Failed to get valid F2FS checkpoint

The reason is that when fsck repairs corrupted quota sysfile, it didn't
check max user block count when allocating new block for quota sysfile,
so ckpt.valid_block_count can exceed max user block count, result in
mount failure later.

Adding upper boundary check of block count in reserve_new_block() to
fix this issue.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agomkfs.f2fs: make the default extensions list much more sensical
Park Ju Hyung [Tue, 16 Apr 2019 06:43:54 +0000 (15:43 +0900)]
mkfs.f2fs: make the default extensions list much more sensical

Following extensions are removed:
 - divx: deprecated video format and it's usually wrapped with avi
 - asf: deprecated streaming format
 - asx: redirecting file to asf(small)
 - wmx: redirecting file to wma/wmv(small)
 - rm: deprecated media container
 - video: unused
 - wv: unpopular audio format from 1998

The extensions list is limited to 64 and those don't deserve to be
on this space-precious list.

Common prefixes are introduced and are checked with
https://en.wikipedia.org/wiki/List_of_filename_extensions
to avoid treating possible hot files as cold:
 - mp: covers mp3, mp4, mpeg, mpg
 - wm: covers wma, wmb, wmv
 - og: covers oga, ogg, ogm, ogv
 - jp: covers jpg, jpeg, jp2

Following extensions are added:
 - webm: extremely popular free media container format from Google
         VP8/VP9/AV1 and Vorbis/Opus is often wrapped with this container
 - wav: uncompressed audio format, commonly used with voice recorders
 - svg: vector image format commonly used in web
 - webp: free lossy image format commonly used in web
 - jar: Java archive file
 - deb: Debian software package
 - iso: disk image file
 - gz: gzip compressed file, unable to randomly update
 - xz: xz compressed file, unable to randomly update
 - zst: zstd compressed file, unable to randomly update
 - pdf: PDF document
 - pyc: Python bytecode automatically generated when
        executing python to run .py files
 - ttc, ttf: font files
 - cnt: image alias files commonly used in Android apps
 - exo: EXO player's cache files, commonly used in Android's YouTube app
 - odex, vdex: Android RunTime files found in /data/app/*/oat

Total entries on the list changed from 34 to 36.

Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
4 years agof2fs-tools: Allow using host-aware devices as regular devices
Damien Le Moal [Tue, 2 Apr 2019 02:44:55 +0000 (11:44 +0900)]
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>
4 years agof2fs-tools: Fix multi-device format with zoned devices
Damien Le Moal [Tue, 2 Apr 2019 02:44:54 +0000 (11:44 +0900)]
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>
4 years agof2fs-tools: Improve zoned model check
Damien Le Moal [Tue, 2 Apr 2019 02:44:53 +0000 (11:44 +0900)]
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>
4 years agofsck.f2fs: check only max extra_isize
Jaegeuk Kim [Sat, 17 Aug 2019 01:02:28 +0000 (18:02 -0700)]
fsck.f2fs: check only max extra_isize

If we use later kernel having larger extra_isize, old fsck will delete
entire old files.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: update curseg .next_blkoff/.alloc_type preferential
Chao Yu [Thu, 16 May 2019 12:40:43 +0000 (20:40 +0800)]
fsck.f2fs: update curseg .next_blkoff/.alloc_type preferential

If .next_blkoff is inconsistent, we can update curseg .next_blkoff
to first unused block address, and change .alloc_type to SSR
preferential, instead of move curseg to other position.

This can help to repair fuzzed image which has no more free segment.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: introduce check_curseg_offsets()
Chao Yu [Thu, 16 May 2019 12:40:42 +0000 (20:40 +0800)]
fsck.f2fs: introduce check_curseg_offsets()

Let check_curseg_offset() just check one curseg, and introduce
check_curseg_offsets() to check all cursegs, no logic changes.

In addition, update message printed a bit.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: relocate chksum_offset for large_nat_bitmap feature
Chao Yu [Tue, 14 May 2019 09:33:40 +0000 (17:33 +0800)]
f2fs-tools: relocate chksum_offset for large_nat_bitmap feature

For large_nat_bitmap feature, there is a design flaw:

Previous:

struct f2fs_checkpoint layout:
+--------------------------+  0x0000
| checkpoint_ver           |
| ......                   |
| checksum_offset          |------+
| ......                   |      |
| sit_nat_version_bitmap[] |<-----|-------+
| ......                   |      |       |
| checksum_value           |<-----+       |
+--------------------------+  0x1000      |
|                          |      nat_bitmap + sit_bitmap
| payload blocks           |              |
|                          |              |
+--------------------------|<-------------+

Obviously, if nat_bitmap size + sit_bitmap size is larger than
MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap
checkpoint checksum's position, once checkpoint() is triggered
from kernel, nat or sit bitmap will be damaged by checksum field.

In order to fix this, let's relocate checksum_value's position
to the head of sit_nat_version_bitmap as below, then nat/sit
bitmap and chksum value update will become safe.

After:

struct f2fs_checkpoint layout:
+--------------------------+  0x0000
| checkpoint_ver           |
| ......                   |
| checksum_offset          |------+
| ......                   |      |
| sit_nat_version_bitmap[] |<-----+
| ......                   |<-------------+
|                          |              |
+--------------------------+  0x1000      |
|                          |      nat_bitmap + sit_bitmap
| payload blocks           |              |
|                          |              |
+--------------------------|<-------------+

Related report and discussion:

https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/

In addition, during writing checkpoint, if large_nat_bitmap feature is
enabled, we need to set CP_LARGE_NAT_BITMAP_FLAG flag in checkpoint.

Reported-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: allow unfixed f2fs_checkpoint.checksum_offset
Chao Yu [Tue, 14 May 2019 09:33:39 +0000 (17:33 +0800)]
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>
5 years agofsck.f2fs: fix to repair cp_loads blocks at correct position
Chao Yu [Sun, 19 May 2019 05:05:52 +0000 (13:05 +0800)]
fsck.f2fs: fix to repair cp_loads blocks at correct position

Let's fix the wrong start offset of cp_payload blocks in
fix_checkpoint().

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agosload.f2fs: introduce f2fs_sparse_initialize_meta()
Chao Yu [Mon, 6 May 2019 08:58:06 +0000 (16:58 +0800)]
sload.f2fs: introduce f2fs_sparse_initialize_meta()

This patch fixes to initialize NAT/SIT/CP.payload region in sparse
file mode for sload.

Reported-and-tested-by: zhaowuyun <zhaowuyun@wingtech.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: write fill chunk in sparse file for zeroed block
Chao Yu [Sun, 5 May 2019 07:45:05 +0000 (15:45 +0800)]
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>
5 years agof2fs-tools: get rid of unneeded fields in on-disk inode
Chao Yu [Sun, 28 Apr 2019 09:17:37 +0000 (17:17 +0800)]
f2fs-tools: get rid of unneeded fields in on-disk inode

As Jaegeuk reminded:

Once user updates f2fs-tools which support new fields in inode layout,
but do keep the kernel which can not support those fields, it will cause
old f2fs fail to mount new image due to root_inode's i_extra_isize value
sanity check.

So if f2fs-tools doesn't enable feature which will use new fields of
inode, we don't need to expand i_extra_isize to include them, let's just
let i_extra_isize point to the end of last valid extra field's position.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: improve xattr value printing
Eric Biggers [Wed, 24 Apr 2019 17:57:30 +0000 (10:57 -0700)]
f2fs-tools: improve xattr value printing

- Print the values of xattrs that have an unknown ->e_name_index, rather
  than ignoring them.

- Replace char with u8.  Otherwise xattr values containing bytes >= 0x80
  are printed incorrectly on platforms where char is signed.

- Only parse the encryption xattr if it has a known format number and
  size.  Otherwise print it as hex.

- Remove incorrect le16_to_cpu() on ->e_name_len which has type u8.

- Consolidate the code that prints the xattr value as hex.

- Constify pointers to the xattr entry.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: improve filename printing
Eric Biggers [Wed, 24 Apr 2019 17:59:09 +0000 (10:59 -0700)]
f2fs-tools: improve filename printing

- Make buffers for pretty-printed filenames 341 bytes long, long enough
  for 255 (NAME_MAX) base64-encoded bytes.  Then print encrypted
  filenames in full, base64-encoded.  This will be useful for tests I'm
  writing which verify the correct ciphertext is stored on-disk.

- Rename convert_encrypted_name() to pretty_print_filename(), to make it
  clear that it handles unencrypted names too.  Also make the output
  'char' rather than 'unsigned char', as it's for printing; and remove
  the unnecessary return value.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: open ro disk if we want to check fs only
Jaegeuk Kim [Tue, 16 Apr 2019 18:46:31 +0000 (11:46 -0700)]
fsck.f2fs: open ro disk if we want to check fs only

This patch fixes the "open failure" issue on ro disk, reported by Hagbard.

"
 If I boot with kernel option "ro rootfstype=f2fs
 I get the following halfway trough boot:

  * Checking local filesystems  ...
 Info: Use default preen mode
 Info: Mounted device!
 Info: Check FS only due to RO
         Error: Failed to open the device!
  * Filesystems couldn't be fixed
"

Reported-by: Hagbard Celine <hagbardcelin@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: fix to repair ro mounted device w/ -f
Chao Yu [Tue, 23 Apr 2019 02:42:20 +0000 (10:42 +0800)]
fsck.f2fs: fix to repair ro mounted device w/ -f

As Hagbard Celine reported:

"
Referring to the output from the fsck running against a "ro"
filesystem, especially this line:
Info: Check FS only due to RO

As far as i can tell this says that opposed to other filesystems
running fsck against a "ro" mounted f2fs partition will never fix any
errors.
So I tried running fsck against the same partition mounted "rw":
- mount -o remount,rw /mnt/f2fstest/
- fsck.f2fs  -f /dev/nvme0n1p7
Info: Force to fix corruption
Info: Mounted device!
        Error: Not available on mounted device!

I might be misunderstanding something, but all this tells me that
unless one make a custom initramfs that runs fsck before root is
mounted (something no distributions has, as far as I know), fsck will
never fix an f2fs formatted root partition during boot.
If this is by design and not a bug/unintended behavior, it should be
documented somewhere least more people will experience system crashes
like mine.

All tests above done with kernel 5.0.5 and f2fs-tools 1.12.0 with
"fsck.f2fs: allow to fsck readonly image w/ -f option"-patch by Chao
Yu.
"

We try to make our fsck behavior keeping line with e2fsprogs, but w/
-f option, we can just check a RO mounted device rather repair it, so
let's fix this.

Reported-and-Tested-by: Hagbard Celine <hagbardcelin@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools:fix memory leak in write dquot
Xiaojun Wang [Wed, 24 Apr 2019 06:47:42 +0000 (14:47 +0800)]
f2fs-tools:fix memory leak in write dquot

this patch free ddquot in qtree_write_dquot to avoid memory leak

Signed-off-by: Xiaojun Wang <wangxiaojun11@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: fix to do sanity check with inode.i_inline_xattr_size
Chao Yu [Mon, 4 Mar 2019 09:21:37 +0000 (17:21 +0800)]
fsck.f2fs: fix to do sanity check with inode.i_inline_xattr_size

This patch adds to do sanity check with inode.i_inline_xattr_size,
and once it is corrupted, recover it to default value.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: add missing FIX_MSG during extra_attr field recovery
Chao Yu [Fri, 1 Mar 2019 08:02:27 +0000 (16:02 +0800)]
fsck.f2fs: add missing FIX_MSG during extra_attr field recovery

Add missing printed message during extra_attr field recovery.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck/mount: Gracefully terminate the mount procedure in case the program runs out...
Sotirios-Efstathios Maneas [Thu, 11 Oct 2018 22:21:35 +0000 (18:21 -0400)]
fsck/mount: Gracefully terminate the mount procedure in case the program runs out of memory.

Added the necessary statements so that the mount procedure gracefully terminates in case the program runs out of memory.

Signed-off-by: Sotirios-Efstathios Maneas <smaneas@cs.toronto.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agolib/libf2fs_io.c: Added a missing free statement.
Sotirios-Efstathios Maneas [Thu, 11 Oct 2018 22:21:14 +0000 (18:21 -0400)]
lib/libf2fs_io.c: Added a missing free statement.

Added a missing free statement related to each device’s path.

Signed-off-by: Sotirios-Efstathios Maneas <smaneas@cs.toronto.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: preserve CP_TRIMMED_FLAG
Jaegeuk Kim [Fri, 25 Jan 2019 04:38:10 +0000 (20:38 -0800)]
fsck.f2fs: preserve CP_TRIMMED_FLAG

Let's avoid unnecessary trim.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: fix incorrect boundary of IS_VALID_NID()
Chao Yu [Wed, 9 Jan 2019 02:48:25 +0000 (10:48 +0800)]
fsck.f2fs: fix incorrect boundary of IS_VALID_NID()

nid should never equal to max_nid, fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: check validity of nat journal
Chao Yu [Mon, 14 Jan 2019 01:33:08 +0000 (09:33 +0800)]
fsck.f2fs: check validity of nat journal

As reported by Aravind:

I built f2fs tools from source (at tag v1.12.0) and was able to get this backtrace in gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f8eb54 in f2fs_set_bit (nr=1041170432,
    addr=0x7fffff621010 <error: Cannot access memory at address 0x7fffff621010>) at libf2fs.c:312
312        mask = 1 << (7 - (nr & 0x07));
(gdb) where
    addr=0x7fffff621010 <error: Cannot access memory at address 0x7fffff621010>) at libf2fs.c:312

> [ 5338.040024] nats:8781, sits:6
> [ 5338.040027] F2FS-fs (sda2): Failed to initialize F2FS segment manager
> [ 5338.128893] nats:8781, sits:6
> [ 5338.128895] F2FS-fs (sda2): Failed to initialize F2FS segment manager

nat_count/nid/blkaddr recorded in journal may be corrupted, let's do
sanity check on them, skip loading invalid ones during build_node_manager().

Reported-by: Aravind R S <aravindet@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs_io: exit if system(3) is failed
Jaegeuk Kim [Sat, 23 Mar 2019 10:23:40 +0000 (19:23 +0900)]
f2fs_io: exit if system(3) is failed

Exit the request, if system(3) is failed to be executed.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: Add f2fs_io to .gitignore
Damien Le Moal [Mon, 18 Mar 2019 06:39:56 +0000 (15:39 +0900)]
f2fs-tools: Add f2fs_io to .gitignore

GIT ignore compiled executable tools/f2fs_io/f2fs_io.

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>
5 years agof2fs-tools: Fix various compilation warnings
Damien Le Moal [Mon, 18 Mar 2019 06:39:55 +0000 (15:39 +0900)]
f2fs-tools: Fix various compilation warnings

Avoid various compilation warnings due to strncpy:

libf2fs.c:590:33: warning: â€˜snprintf’ output may be truncated before
the last format character [-Wformat-truncation=]
  snprintf(rootdev, ret, "/dev/%s", buf);

../include/f2fs_fs.h:1384:2: warning: â€˜strncpy’ specified bound
depends on the length of the source argument [-Wstringop-overflow=]
  strncpy(buf, features, strlen(features) + 1);

f2fstat.c:243:3: warning: â€˜strncpy’ output truncated before
terminating nul copying as many bytes from a string as its length
[-Wstringop-truncation]
   strncpy(ptr_buf, name[i], strlen(name[i]));

This patch does not change any functionality.

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>
5 years agof2fs-tools: add c++ for UNUSED
Jaegeuk Kim [Fri, 1 Mar 2019 17:47:13 +0000 (09:47 -0800)]
f2fs-tools: add c++ for UNUSED

This can avoid build failure for f2fscrypt.

Change-Id: I33eddc62eea486dc219c25d089112e011864dd4f
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
5 years agof2fscrypt: avoid to fail android build
Jaegeuk Kim [Wed, 16 Jan 2019 02:52:38 +0000 (18:52 -0800)]
f2fscrypt: avoid to fail android build

This fixes some static build errors.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: fix build breakage
Jaegeuk Kim [Wed, 27 Feb 2019 22:29:09 +0000 (14:29 -0800)]
f2fs-tools: fix build breakage

Fix this first, and will do upstream right away.

Change-Id: I6debbb0988595772452f7a878c2cc177fa2e26f3
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
5 years agof2fs_io: add gc_urgent
Jaegeuk Kim [Wed, 20 Feb 2019 03:07:21 +0000 (19:07 -0800)]
f2fs_io: add gc_urgent

e.g.,
f2fs_io gc_urgent dm-4 [start/end/run] [time in sec]

This controls sysfs/gc_urgent to run f2fs_gc urgently.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs_io: add fiemap
Jaegeuk Kim [Wed, 16 Jan 2019 23:17:25 +0000 (15:17 -0800)]
f2fs_io: add fiemap

f2fs_io fiemap [offset in 4kb] [count] [file_path]

Change-Id: Iee9e8b742ada6a12a9f761b3a6de8d82a60e1b59
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
5 years agof2fs_io: add read
Jaegeuk Kim [Wed, 16 Jan 2019 19:15:59 +0000 (11:15 -0800)]
f2fs_io: add read

f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]

Read data in file_path and print nbytes
IO can be
  buffered : buffered IO
  dio      : direct IO

Change-Id: I912adc4f443c3656ad067d29a1e2f581b79d28e6
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
5 years agof2fs_io: add write
Jaegeuk Kim [Wed, 16 Jan 2019 17:29:42 +0000 (09:29 -0800)]
f2fs_io: add write

f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]

Write given patten data in file_path
pattern can be
  zero     : zeros
  inc_num  : incrementing numbers
  rand     : random numbers
IO can be
  buffered : buffered IO
  dio      : direct IO

Change-Id: Icc866d5b9933423639d1d0e4d5e556ddf4f15feb
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
5 years agofsck.f2fs: check nat_bits separately from bug_on
Jaegeuk Kim [Wed, 28 Nov 2018 23:11:28 +0000 (15:11 -0800)]
fsck.f2fs: check nat_bits separately from bug_on

It checks nat_bits separately, and enable it seamlessly.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: don't ask anything on dry-run
Jaegeuk Kim [Fri, 4 Jan 2019 21:02:22 +0000 (13:02 -0800)]
fsck.f2fs: don't ask anything on dry-run

It doesn't need to ask recovering corruption on dry-run mode.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs_io: add pin_file control command
Jaegeuk Kim [Fri, 4 Jan 2019 00:54:04 +0000 (16:54 -0800)]
f2fs_io: add pin_file control command

This requires a kernel patch "f2fs: export pin_file flag to user".

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agodump.f2fs: fix incorrect endian conversion
Chao Yu [Mon, 10 Dec 2018 03:19:01 +0000 (11:19 +0800)]
dump.f2fs: fix incorrect endian conversion

f2fs_inode.i_mode is variable of __le16 type, during endian converison,
it should to use le16_to_cpu instead of le32_to_cpu, fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck: Fix big endian platforms
Rosen Penev [Sat, 8 Dec 2018 01:45:31 +0000 (17:45 -0800)]
fsck: Fix big endian platforms

Since "fsck.f2fs: integrate sanity_check_inode to __check_inode_mode",
big endian platforms have been broken due to an endianness bug.

More info: https://github.com/openwrt/openwrt/pull/1575

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agotools: add f2fs_io
Jaegeuk Kim [Wed, 28 Nov 2018 18:52:05 +0000 (10:52 -0800)]
tools: add f2fs_io

This is initial commit to support shutdown ioctl.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agoparse.f2fs: fix parsing of f2fs_trace_ios
Sahitya Tummala [Fri, 28 Dec 2018 07:36:43 +0000 (13:06 +0530)]
parse.f2fs: fix parsing of f2fs_trace_ios

It is incorrectly taking blkaddr as len because it missed to parse
op_flags in the trace print of f2fs_trace_ios.

Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: introduce preen mode 2
Chao Yu [Tue, 27 Nov 2018 12:36:35 +0000 (20:36 +0800)]
fsck.f2fs: introduce preen mode 2

As Michael reported:

after updating to f2fs-tools 1.12.0, a routine fsck of my file systems
took quite a while and output ten-thousands instances of the following
line:

> [FIX] (fsck_chk_inode_blk: 954)  --> Regular: 0xXYZ reset i_gc_failures from 0x1 to 0x00

The reason is that:

We start to support reseting .i_gc_failures's value to zero in fsck since
91bb7b21f740 ("f2fs-tools: fix to reset i_gc_failures offline"), this is
because if .i_gc_failures continues increasing and exceed threshold, it
can make f2fs break atomic_write semantics during GC, so I added that
patch to avoid such condition.

But the problem here is even .i_gc_failures's value is one which was
initialized duing inode creation by old kernel, and it never be increased
by GC flow, we will still trigger such fix in fsck. I think it's not
necessary.

As Jaegeuk suggested, we introduce a new preen mode 2 to handle such
condition:
  - 2: same as 0, but skip some checks for old kernel

Suggested-by: Jaegeuk Kim <jaegeuk@kernel.org>
Reported-by: Michael Laß <bevan@bi-co.net>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: allow to fsck readonly image w/ -f option
Chao Yu [Mon, 26 Nov 2018 10:53:37 +0000 (18:53 +0800)]
fsck.f2fs: allow to fsck readonly image w/ -f option

To keep line with e2fsprogs, let's allow to fsck mounted image as
readonly w/ -f option.

Reported-by: Perfect Gentleman <perfect007gentleman@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: fix to check return value of {c,m}alloc()
Chao Yu [Mon, 26 Nov 2018 13:36:00 +0000 (21:36 +0800)]
f2fs-tools: fix to check return value of {c,m}alloc()

It needs to fix to handle error case of {c,m}alloc().

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agolibf2fs: avoid to use static local string for global f2fs_conf
Jaegeuk Kim [Thu, 22 Nov 2018 11:57:06 +0000 (03:57 -0800)]
libf2fs: avoid to use static local string for global f2fs_conf

We don't need to use c.rootdev_name, but do it locally.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: enable VERITY by default
Jaegeuk Kim [Thu, 22 Nov 2018 07:18:14 +0000 (23:18 -0800)]
mkfs.f2fs: enable VERITY by default

This enables VERITY by default for android.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: release 1.12.0 v1.12.0
Jaegeuk Kim [Tue, 28 Aug 2018 06:44:54 +0000 (23:44 -0700)]
f2fs-tools: release 1.12.0

This release includes:
 - add android default configuration
 - fix resgid/resuid
 - add more sanity checks
 - fix corrupted quota in clean umount
 - add superblock checksum

And, there are several bug fixes in fsck.f2fs/sload.f2fs/mkfs.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: create sparse file first before stat
Jaegeuk Kim [Fri, 16 Nov 2018 05:54:02 +0000 (21:54 -0800)]
f2fs-tools: create sparse file first before stat

We must create a sparse file first before calling stat().

Fixes: eb9d8037ed3b ("f2fs-tools: avoid mounting f2fs if tools already open the device")
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: show versions if exist
Jaegeuk Kim [Fri, 16 Nov 2018 01:38:01 +0000 (17:38 -0800)]
f2fs-tools: show versions if exist

If it's not defined, we need to skip to show the definition.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agosload.f2fs: fix memory leak
taebum81.kim [Mon, 5 Nov 2018 06:43:37 +0000 (15:43 +0900)]
sload.f2fs: fix memory leak

Dynamic memory stored in 'xattr_node' allocated through function 'calloc'
at line 98 can be lost at line 111
Dynamic memory stored in 'inode' allocated through function 'calloc'
at line 144 can be lost at line 227

Signed-off-by: taebum81.kim <taebum81.kim@lge.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: add the max chunk size limit in sparse image
Gao Ming [Mon, 15 Oct 2018 13:24:57 +0000 (21:24 +0800)]
f2fs-tools: add the max chunk size limit in sparse image

Malloc Failure occurs in 32bit Windows, when using fastboot.exe flash the
 f2fs sparse image filling with  up to 2G chunk size.

Signed-off-by: Gao Ming <gaoming20@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: Added missing statements related to error checking.
Sotirios-Efstathios Maneas [Thu, 11 Oct 2018 22:20:53 +0000 (18:20 -0400)]
mkfs.f2fs: Added missing statements related to error checking.

The following patch adds a few missing statements related to error checking.

Signed-off-by: Sotirios-Efstathios Maneas <smaneas@cs.toronto.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: give WITH_KERNEL_VERSION to check kernel version only
Jaegeuk Kim [Fri, 19 Oct 2018 22:42:40 +0000 (15:42 -0700)]
f2fs-tools: give WITH_KERNEL_VERSION to check kernel version only

This patch adds a build option to relax kernel version and release string to
trigger full scan.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: support formating large size file in 32-bits platform
Chao Yu [Wed, 17 Oct 2018 01:40:56 +0000 (09:40 +0800)]
mkfs.f2fs: support formating large size file in 32-bits platform

In 32-bits platform, {f,}stat on a large size file during mkfs, it will
cause EOVERFLOW error, this patch fixes to add macro definition
_FILE_OFFSET_BITS to avoid that error.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: do not hard-code encrypted filename length to avoid heap buffer overflow
Randall Huang [Wed, 10 Oct 2018 00:38:01 +0000 (17:38 -0700)]
fsck.f2fs: do not hard-code encrypted filename length to avoid heap buffer overflow

If the len is less than 24, heap buffer overflow is reported.

Signed-off-by: Randall Huang <huangrandall@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: show the info of volume label only when specify it
Tiezhu Yang [Mon, 8 Oct 2018 12:39:07 +0000 (20:39 +0800)]
mkfs.f2fs: show the info of volume label only when specify it

Currently, when format disk used with mkfs.f2fs, even if the volume label
is not specified, it still shows the info of volume label with no content
due to the check condition is always true, this patch fixes it.

[root@localhost home]# mkfs.f2fs -f /dev/sdb1

F2FS-tools: mkfs.f2fs Ver: 1.12.0 (2018-10-08)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Label =
Info: Trim is enabled

Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: don't allocate new blocks on unclean shutdown
Jaegeuk Kim [Mon, 1 Oct 2018 01:16:38 +0000 (18:16 -0700)]
fsck.f2fs: don't allocate new blocks on unclean shutdown

We have to keep data for roll-forward recovery. Without this patch, we're
able to lose there-in data by quota overwrites.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: detect and recover corrupted quota file
Chao Yu [Wed, 19 Sep 2018 01:28:37 +0000 (09:28 +0800)]
fsck.f2fs: detect and recover corrupted quota file

Once quota file is corrupted, kernel will set CP_QUOTA_NEED_FSCK_FLAG
into checkpoint pack, this patch makes fsck supporting to detect the flag
and try to rebuild corrupted quota file.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
5 years agofsck.f2fs: try to recover cp_payload from valid cp pack
Chao Yu [Fri, 28 Sep 2018 12:26:00 +0000 (20:26 +0800)]
fsck.f2fs: try to recover cp_payload from valid cp pack

If sb checksum is not enabled, and cp pack is valid due to no
crc inconsistence, let's try to recover cp_payload based on
cp_pack_start_sum in cp pack.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: introduce sb checksum
Junling Zheng [Fri, 28 Sep 2018 12:25:59 +0000 (20:25 +0800)]
f2fs-tools: introduce sb checksum

This patch introduced crc for superblock.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: unify the updating of superblocks
Junling Zheng [Fri, 28 Sep 2018 12:25:58 +0000 (20:25 +0800)]
fsck.f2fs: unify the updating of superblocks

Rename write_superblock() to update_superblock() and make it support updating
specified one superblock or both two superblocks, then unify all places where
sb needs to be updated.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agoWIP: Add partial shrinking support to f2fs
Daniel Rosenberg [Wed, 9 May 2018 02:48:33 +0000 (19:48 -0700)]
WIP: Add partial shrinking support to f2fs

allow 'safe' resizing leaving the metadata nearly unchanged.

Will likely need to adjust growing for the case where a fs
had previously shrunk without altering data, and the newly grown
fs would be smaller than the original. Probably makes sense to
case it out into metadata size changes, instead of fs size changes

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
5 years agodump.f2fs: allow dump data on mounted image
Chao Yu [Sun, 30 Sep 2018 08:26:13 +0000 (16:26 +0800)]
dump.f2fs: allow dump data on mounted image

xfstests assumes it's allow to dump data on mounted image, for example,
some common functions call dumpe2fs on mounted ext[2|3|4] image to check
feature lists. To adapt such requirement, let's follow that rule in
dump.f2fs.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: support checkpoint=disable
Jaegeuk Kim [Thu, 20 Sep 2018 23:16:07 +0000 (16:16 -0700)]
fsck.f2fs: support checkpoint=disable

This patch shows checkpoint is disabled and keeps the flag for next mount.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: rename CHECKSUM_OFFSET to CP_CHKSUM_OFFSET
Junling Zheng [Wed, 19 Sep 2018 13:53:48 +0000 (21:53 +0800)]
f2fs-tools: rename CHECKSUM_OFFSET to CP_CHKSUM_OFFSET

This patch renamed CHECKSUM_OFFSET to CP_CHKSUM_OFFSET.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agodoc: add versioning rule
Jaegeuk Kim [Wed, 29 Aug 2018 21:06:56 +0000 (14:06 -0700)]
doc: add versioning rule

Ted wrote a very useful versioning rule that newbies must read.
Let me remain it in the tree.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: release 1.11.1
Jaegeuk Kim [Tue, 28 Aug 2018 06:44:54 +0000 (23:44 -0700)]
f2fs-tools: release 1.11.1

This release includes:
 - add android default configuration
 - fix resgid/resuid
 - add more sanity checks

And, there are several bug fixes in fsck.f2fs/sload.f2fs/mkfs.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: Fix cross-build problem caused by AC_CHECK_FILE abuse
Helmut Grohne [Tue, 28 Aug 2018 00:29:41 +0000 (20:29 -0400)]
f2fs-tools: Fix cross-build problem caused by AC_CHECK_FILE abuse

f2fs-tools fails to cross build from source, because its upstream
build system wrongly uses AC_CHECK_FILE. The purpose of the macro is
checking for files on the host system. However here it is used to
check whether a .git directory exists, which is a property of the
build place. A simple "test -d" should be used here. After doing so,
f2fs-tools cross builds successfully.

Addresses-Debian-Bug: #896909

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: supply more check entries for checkpoint
Junling Zheng [Fri, 3 Aug 2018 04:09:05 +0000 (12:09 +0800)]
fsck.f2fs: supply more check entries for checkpoint

Supply some more check entries for checkpoint in sanity_check_ckpt()
and validate_checkpoint() to sync them with kernel.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: print node block address
Chao Yu [Sat, 28 Jul 2018 10:40:59 +0000 (18:40 +0800)]
fsck.f2fs: print node block address

Print block address of unreachable node id in fsck_verify() for better
debugging.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: fix to reset i_gc_failures offline
Chao Yu [Sat, 28 Jul 2018 10:41:35 +0000 (18:41 +0800)]
f2fs-tools: fix to reset i_gc_failures offline

This patch synchronize f2fs_inode structure from kernel side, in
addition, it adds to check .i_gc_failures and do resetting in fsck.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: Fixed typos in several printed messages.
Sotirios-Efstathios Maneas [Thu, 26 Jul 2018 22:02:02 +0000 (18:02 -0400)]
mkfs.f2fs: Fixed typos in several printed messages.

Fixed typos in several printed messages.

Signed-off-by: Sotirios-Efstathios Maneas <smaneas@cs.toronto.edu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agobuild: declare that libf2fs_format uses the blkid library
Theodore Ts'o [Fri, 24 Aug 2018 07:26:32 +0000 (03:26 -0400)]
build: declare that libf2fs_format uses the blkid library

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agoadd configure option --with-root-libdir
Theodore Ts'o [Mon, 20 Aug 2018 03:04:06 +0000 (23:04 -0400)]
add configure option --with-root-libdir

This allows the development link libraries to be installed in
/usr/lib, while the run-libraries are installed in /lib, which is
required by Debian policy.  This can be done via:

    configure --prefix=/ --libdir=/usr/lib --with-root-libdir=/lib

The technique of working around libtool's inflexibility is borrowed
from util-linux.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: add -R 0:0 by default for android
Jaegeuk Kim [Fri, 27 Jul 2018 08:45:57 +0000 (17:45 +0900)]
mkfs.f2fs: add -R 0:0 by default for android

This patch sets "-R 0:0" for android by default.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: add root_owner to give uid/gid
Jaegeuk Kim [Fri, 27 Jul 2018 08:12:32 +0000 (17:12 +0900)]
mkfs.f2fs: add root_owner to give uid/gid

This patch adds an option to mkfs.f2fs in order for user to assign uid/gid
to the target partition.
This requires when vold in android formats a sdcard partition.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agomkfs.f2fs: Add several media formats + exe
Rosen Penev [Sat, 14 Jul 2018 18:08:05 +0000 (11:08 -0700)]
mkfs.f2fs: Add several media formats + exe

These media formats are currently in use.

exe is useful if storing various Windows utilities on the drive.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: set namelen parameter of convert_encrypted_name as unsigned
Sheng Yong [Tue, 10 Jul 2018 14:47:38 +0000 (22:47 +0800)]
f2fs-tools: set namelen parameter of convert_encrypted_name as unsigned

To avoid overflow, set namelen parameter of convert_encrypted_name as
unsigned int. convert_encrypted_name() will check if namelen exceeds the
limitation.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: init quota_file before re-create quota file
Sheng Yong [Thu, 12 Jul 2018 03:36:41 +0000 (11:36 +0800)]
fsck.f2fs: init quota_file before re-create quota file

`quota_handle->qh_qf->filesize' is not initialized by quota_create_file().
It contains random value, which is updated to quota file's i_size in
quota_file_close(). Since quota file is re-created, `filesize' can be
initialized as 0.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: fix to do sanity check with extra_attr feature
Chao Yu [Tue, 10 Jul 2018 12:29:08 +0000 (20:29 +0800)]
fsck.f2fs: fix to do sanity check with extra_attr feature

This patch tries to fix incorrect extra_attr bit or i_extra_isize value
in fsck.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: avoid mounting f2fs if tools already open the device
Sheng Yong [Wed, 4 Jul 2018 09:50:45 +0000 (17:50 +0800)]
f2fs-tools: avoid mounting f2fs if tools already open the device

If the block device is opened by tools, F2FS should not be mounted.
Especially when fsck is running, errors unexpected may happen. So if
tools open a block device, we give it the O_EXCL flag to make sure
the block device is opened exclusivly.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: check extent of inline data/dentry inode
Sheng Yong [Tue, 3 Jul 2018 10:10:04 +0000 (18:10 +0800)]
fsck.f2fs: check extent of inline data/dentry inode

Check extent for inline data/dentry inode. If an inode contains inline
data/dentry, it should have no extent.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=200175
Reported-by: Wen Xu <wen.xu@gatech.edu>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agodump.f2fs: only dump nat inside the specified nid range
Junling Zheng [Mon, 2 Jul 2018 09:22:41 +0000 (17:22 +0800)]
dump.f2fs: only dump nat inside the specified nid range

Only dump nat info of nids inside the specified range.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: fix wrong err message of check quota node
Yunlei He [Tue, 26 Jun 2018 08:06:54 +0000 (16:06 +0800)]
fsck.f2fs: fix wrong err message of check quota node

This patch fix wrong err message of check quota node.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: fix compile errors on AOSP
Junling Zheng [Wed, 20 Jun 2018 13:06:16 +0000 (21:06 +0800)]
f2fs-tools: fix compile errors on AOSP

Include needed header files directly to fix compile errors on AOSP.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agof2fs-tools: do not count free_segs in flush_sit_entries
Sheng Yong [Wed, 13 Jun 2018 10:13:59 +0000 (18:13 +0800)]
f2fs-tools: do not count free_segs in flush_sit_entries

flush_sit_entries() is always called before write_checkpoint(). Since
free_segs is counted in write_checkpoint, there is no need to do that
in flush_sit_entries. Besides, the value of free_segs may be not
correct if we skip uptodate seg_entries.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: introduce fsck_chk_curseg_info
Sheng Yong [Wed, 20 Jun 2018 11:12:13 +0000 (19:12 +0800)]
fsck.f2fs: introduce fsck_chk_curseg_info

If curseg is an empty segment, it will not be checked. This patch
introduces fsck_chk_curseg_info() to check SIT/SSA type of cursegs
to avoid curseg corruption.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agosload.f2fs: update sit entries of cursegs
Sheng Yong [Wed, 13 Jun 2018 01:51:49 +0000 (09:51 +0800)]
sload.f2fs: update sit entries of cursegs

move_curseg_info->reset_curseg changes cursegs, however, new segment
entries are not set as dirty. As a result, flush_sit_entries will not
update entries in SIT, especially when an empty segment is selected
as the new curseg, its seg_entry->type is lost.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: show missing large_nat_bitmap flag in print_ckpt_info
Chao Yu [Thu, 21 Jun 2018 01:20:32 +0000 (09:20 +0800)]
fsck.f2fs: show missing large_nat_bitmap flag in print_ckpt_info

Previously, we forget to print large_nat_bitmap according to CP flag,
fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agofsck.f2fs: do not print content beyond sb->version
Junling Zheng [Fri, 8 Jun 2018 05:11:48 +0000 (13:11 +0800)]
fsck.f2fs: do not print content beyond sb->version

Currently, versions in f2fs_configuration have one more byte than
those in sb, so versions in sb may not end with '\0', and then
print_raw_sb_info() will print something beyond sb->version.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
5 years agoresize.f2fs: skip cursegs when finding next free block
Sheng Yong [Mon, 4 Jun 2018 08:14:36 +0000 (16:14 +0800)]
resize.f2fs: skip cursegs when finding next free block

resize.f2fs (f2fs_defragment) tries to migrate blocks to new positions.
However, if a curseg is selected, and f2fs_defragment is broken by any
error, curseg->next_blkoff is left not updated.

To avoid this, we skip cursegs when finding next free block.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>