platform/upstream/f2fs-tools.git
7 years agof2fs-tools: avoid build warnings
Jaegeuk Kim [Mon, 5 Jun 2017 20:44:50 +0000 (13:44 -0700)]
f2fs-tools: avoid build warnings

This patch resolves warnings while building it in android.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: avoid wrong discard of dnode
Jaegeuk Kim [Fri, 26 May 2017 02:17:44 +0000 (19:17 -0700)]
mkfs.f2fs: avoid wrong discard of dnode

This can drop root inode, which can be caused by previous stale data.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: fix the wrong message when errno is EBUSY
Tiezhu Yang [Wed, 10 May 2017 13:16:46 +0000 (21:16 +0800)]
f2fs-tools: fix the wrong message when errno is EBUSY

If f2fs is unmounted with the -l option, the process can still use the
file system. In this case, the command mkfs.f2fs, fsck.f2fs, dump.f2fs,
defrag.f2fs, resize.f2fs and sload.f2fs failed due to the device is in
use by the system. At the moment f2fs is already not mounted, so it is
wrong to print error message "Error: Not available on mounted device!",
this patch fixes it.

[root@localhost home]# mkfs.f2fs -f /dev/sdb1
[root@localhost home]# mkdir -p /mnt/f2fs_mnt_point
[root@localhost home]# mount -t f2fs /dev/sdb1 /mnt/f2fs_mnt_point/
[root@localhost home]# cd /mnt/f2fs_mnt_point/
[root@localhost f2fs_mnt_point]# umount /dev/sdb1
umount: /mnt/f2fs_mnt_point: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@localhost f2fs_mnt_point]# umount -l /dev/sdb1
[root@localhost f2fs_mnt_point]# umount /dev/sdb1
umount: /dev/sdb1: not mounted
[root@localhost f2fs_mnt_point]# mkfs.f2fs -f /dev/sdb1

F2FS-tools: mkfs.f2fs Ver: 1.8.0 (2017-04-28)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Label =
Info: Trim is enabled
Error: In use by the system!
Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# fsck.f2fs /dev/sdb1
Error: In use by the system!
Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# dump.f2fs /dev/sdb1
Error: In use by the system!
Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# defrag.f2fs /dev/sdb1
Error: In use by the system!
Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# resize.f2fs /dev/sdb1
Error: In use by the system!
Error: Not available on mounted device!
[root@localhost f2fs_mnt_point]# sload.f2fs /dev/sdb1
Error: In use by the system!
Error: Not available on mounted device!

Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: support to set and recognize CP_TRIMMED_FLAG
Chao Yu [Fri, 28 Apr 2017 09:16:31 +0000 (17:16 +0800)]
f2fs-tools: support to set and recognize CP_TRIMMED_FLAG

During mkfs, once we have issued discard for all device, we can set
CP_TRIMMED_FLAG in cp pack, this can make kernel module to record
undiscard blocks correctly, it will help to avoid unneeded discard.

Also this patch makes f2fs-tools be with the ability of recognizing
that new flag.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: sanity check segno and blk_off when building curseg array
Jin Qian [Thu, 27 Apr 2017 22:45:28 +0000 (15:45 -0700)]
fsck.f2fs: sanity check segno and blk_off when building curseg array

segno and blk_off were read from input image without sanity check. This
could lead to buffer overflow when accessing internal arrays like SIT
sentries and seg_entry cur_valid_map.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: sanity check cp_payload before reading checkpoint
Jin Qian [Thu, 27 Apr 2017 19:12:22 +0000 (12:12 -0700)]
fsck.f2fs: sanity check cp_payload before reading checkpoint

cp_payload is not sanity checked from input image. A invalid size
can cause buffer overflow when reading checkpoint blks into memory.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: sanity check blk_off for summary block entries
Jin Qian [Thu, 27 Apr 2017 18:29:22 +0000 (11:29 -0700)]
fsck.f2fs: sanity check blk_off for summary block entries

crafted malicious f2fs partition can fill an out of bound blk_off,
which cause overflow when accessing summary block entries.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix wrong segment assignment
Jaegeuk Kim [Wed, 26 Apr 2017 00:49:17 +0000 (17:49 -0700)]
mkfs.f2fs: fix wrong segment assignment

We must guarantee that current segments should be different between different
logs.
This should resolve xfstests/generic/015 panic.

Fixes: 8f9327c0c02ee1 ("mkfs.f2fs: use noheap by default")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: sanity check segment count
Jin Qian [Tue, 25 Apr 2017 23:25:11 +0000 (16:25 -0700)]
f2fs-tools: sanity check segment count

make sure segment count in super block doesn't exceed F2FS_MAX_SEGMENT.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: fix cur_valid_map buffer overflow
Jin Qian [Tue, 18 Apr 2017 17:58:05 +0000 (10:58 -0700)]
fsck.f2fs: fix cur_valid_map buffer overflow

blk_off is read from image. Attacker can construct an image with big
blk_off that trigger overflow on se->cur_valid_map.

Signed-off-by: Jin Qian <jinqian@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoFix mkfs out of tree builds
Yong, Jonathan [Thu, 30 Mar 2017 08:03:37 +0000 (08:03 +0000)]
Fix mkfs out of tree builds

Libraries are built in builddir, not srcdir, fix Makefile.am
accordingly.

Signed-off-by: Yong, Jonathan <jonathan.yong@intel.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: use noheap by default
Jaegeuk Kim [Sat, 25 Mar 2017 00:56:24 +0000 (20:56 -0400)]
mkfs.f2fs: use noheap by default

Let's set noheap by default.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agolibf2fs: avoid overwrite the c.start_sector by non-root device
Kinglong Mee [Sat, 18 Mar 2017 08:00:10 +0000 (16:00 +0800)]
libf2fs: avoid overwrite the c.start_sector by non-root device

For multiple devices, the c.start_sector will be overwrite by the non-root devices.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agosload.f2fs: support sload files into directory includes inline dentry
Kinglong Mee [Fri, 17 Mar 2017 14:01:12 +0000 (22:01 +0800)]
sload.f2fs: support sload files into directory includes inline dentry

It seems the new created directory always includes inline dentries,
let sload.f2fs supporting it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agosload.f2fs: let dir_buckets/dir_block_index supports dir_level
Kinglong Mee [Fri, 17 Mar 2017 14:01:04 +0000 (22:01 +0800)]
sload.f2fs: let dir_buckets/dir_block_index supports dir_level

The dir_level in the filesystem maybe larger than zero,
supports it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: check encrypted filename depends FADVISE_ENC_NAME_BIT
Kinglong Mee [Fri, 17 Mar 2017 13:56:19 +0000 (21:56 +0800)]
fsck.f2fs: check encrypted filename depends FADVISE_ENC_NAME_BIT

An encrypted directory under an unencrypted directory, the filename isn't encrypted.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: fix bad notice of missing device
Kinglong Mee [Fri, 17 Mar 2017 13:55:50 +0000 (21:55 +0800)]
fsck.f2fs: fix bad notice of missing device

The following messages is better than before.

Before,
# fsck.f2fs -d 1
    Error: Need argument for -d

Now,
# fsck.f2fs -d 1
Info: Debug level = 1
        Error: Device not specified

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agosload.f2fs: fix missing SSA updates
Kinglong Mee [Fri, 17 Mar 2017 11:08:21 +0000 (19:08 +0800)]
sload.f2fs: fix missing SSA updates

If sload many larger files to disk, the SSA that doesn't cached will be missed.

Mar 17 12:04:39 localhost kernel: ------------[ cut here ]------------
Mar 17 12:04:39 localhost kernel: kernel BUG at fs/f2fs/gc.c:899!
Mar 17 12:04:39 localhost kernel: invalid opcode: 0000 [#1] SMP
Mar 17 12:04:39 localhost kernel: Modules linked in: f2fs tun bridge stp llc fuse ip_set nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event snd_ens1371 gameport snd_ac97_codec coretemp ac97_bus crct10dif_pclmul crc32_pclmul ppdev snd_seq snd_pcm ghash_clmulni_intel intel_rapl_perf vmw_balloon snd_rawmidi joydev snd_timer snd_seq_device snd soundcore parport_pc parport nfit acpi_cpufreq tpm_tis tpm_tis_core shpchp vmw_vmci tpm i2c_piix4 nfsd auth_rpcgss nfs_acl lockd grace sunrpc xfs libcrc32c vmwgfx drm_kms_helper ttm drm e1000 crc32c_intel mptspi scsi_transport_spi serio_raw mptscsih mptbase ata_generic pata_acpi fjes
Mar 17 12:04:39 localhost kernel: CPU: 0 PID: 6427 Comm: f2fs_gc-8:33 Tainted: G        W       4.10.0-f2fs+ #25
Mar 17 12:04:39 localhost kernel: Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 07/02/2015
Mar 17 12:04:39 localhost kernel: task: ffff94ba7d998000 task.stack: ffffb6e4c2e50000
Mar 17 12:04:39 localhost kernel: RIP: 0010:do_garbage_collect+0xa39/0xb60 [f2fs]
Mar 17 12:04:39 localhost kernel: RSP: 0018:ffffb6e4c2e53cc0 EFLAGS: 00010213
Mar 17 12:04:39 localhost kernel: RAX: ffff94baa0427000 RBX: 0000000000000001 RCX: 0000000000000002
Mar 17 12:04:39 localhost kernel: RDX: 0000000000000000 RSI: fffff5e2c28109c0 RDI: fffff5e2c28109c0
Mar 17 12:04:39 localhost kernel: RBP: ffffb6e4c2e53dc0 R08: ffff94ba7dfc72f0 R09: fffff5e2c28109dc
Mar 17 12:04:39 localhost kernel: R10: 0000000000000040 R11: ffff94ba7dfc7238 R12: 0000000000000418
Mar 17 12:04:39 localhost kernel: R13: fffff5e2c28109c0 R14: 0000000000000417 R15: ffff94ba3c021000
Mar 17 12:04:39 localhost kernel: FS:  0000000000000000(0000) GS:ffff94babb600000(0000) knlGS:0000000000000000
Mar 17 12:04:39 localhost kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Mar 17 12:04:39 localhost kernel: CR2: 00007fc42a0d7000 CR3: 00000000a7e94000 CR4: 00000000001406f0
Mar 17 12:04:39 localhost kernel: Call Trace:
Mar 17 12:04:39 localhost kernel: ? find_next_bit+0xb/0x10
Mar 17 12:04:39 localhost kernel: f2fs_gc+0x111/0x480 [f2fs]
Mar 17 12:04:39 localhost kernel: ? prepare_to_wait_event+0x79/0x160
Mar 17 12:04:39 localhost kernel: gc_thread_func+0x2d0/0x3f0 [f2fs]
Mar 17 12:04:39 localhost kernel: ? __schedule+0x273/0x860
Mar 17 12:04:39 localhost kernel: ? remove_wait_queue+0x70/0x70
Mar 17 12:04:39 localhost kernel: kthread+0x101/0x140
Mar 17 12:04:39 localhost kernel: ? f2fs_gc+0x480/0x480 [f2fs]
Mar 17 12:04:39 localhost kernel: ? kthread_park+0x90/0x90
Mar 17 12:04:39 localhost kernel: ret_from_fork+0x2c/0x40
Mar 17 12:04:39 localhost kernel: Code: 48 8d 84 24 90 00 00 00 48 89 c7 48 89 44 24 28 e8 7d cc ba e6 e9 17 fa ff ff 48 c7 c6 48 3f 84 c0 48 89 c7 e8 59 8d 9d e6 0f 0b <0f> 0b 48 c7 c6 48 3f 84 c0 4c 89 ff e8 46 8d 9d e6 0f 0b 8b b4
Mar 17 12:04:39 localhost kernel: RIP: do_garbage_collect+0xa39/0xb60 [f2fs] RSP: ffffb6e4c2e53cc0
Mar 17 12:04:39 localhost kernel: ---[ end trace 926d61b064ed1f2d ]---

Fixes: 767a93ea8b ("defrag.f2fs: fix missing SSA updates")
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: a separate option for showing directory tree
Kinglong Mee [Wed, 15 Mar 2017 13:28:19 +0000 (21:28 +0800)]
fsck.f2fs: a separate option for showing directory tree

Showing directory tree reuses dbg_lv that if setting "-t",
fsck.f2fs does not show any others.
Users may want much information include the debug info and directory tree.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fscrypt: add a tool for encryption management in the f2fs filesystem
Kinglong Mee [Wed, 15 Mar 2017 13:16:40 +0000 (21:16 +0800)]
f2fscrypt: add a tool for encryption management in the f2fs filesystem

It's migrated from e4crypt.
Adds an example to the f2fscrypt manpages.

v3, add /tools/f2fscrypt to .gitignore
v2, migrate those micro defines for encrypt to f2fs internal,
    drop unless of libsha etc.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: sanity check of crc_offset from raw checkpoint
Kinglong Mee [Wed, 15 Mar 2017 13:12:10 +0000 (21:12 +0800)]
fsck.f2fs: sanity check of crc_offset from raw checkpoint

The crc_offset towards or beyond the end of block is wrong,
sanity check it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: fix a resize fail for sector size mismatch
Yunlei He [Wed, 8 Mar 2017 12:20:54 +0000 (20:20 +0800)]
resize.f2fs: fix a resize fail for sector size mismatch

This patch fix a resize faill for sector size mismatch.
The initial fs comes from an image file, with sector size
512KB, and the block device sector size is equal to block
size.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: check overwrite before make filesystem
Kinglong Mee [Sun, 5 Mar 2017 13:05:01 +0000 (21:05 +0800)]
mkfs.f2fs: check overwrite before make filesystem

Mkfs.f2fs doesn't check the overwrite of exist filesystem.
Avoid formatting an exist filesystem by mistake, a notice is important.
The code is modified from xfsprogs.

v3, add the missing update of SYNOPSIS
v2, add the manpages description of -f.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: clearfiy the help message and manpages
Kinglong Mee [Sun, 5 Mar 2017 13:04:46 +0000 (21:04 +0800)]
mkfs.f2fs: clearfiy the help message and manpages

Add some missing options in manpages, also order those options.

v3, add the missing update of SYNOPSIS

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: support nat_bits feature
Jaegeuk Kim [Thu, 9 Feb 2017 02:55:43 +0000 (18:55 -0800)]
mkfs.f2fs: support nat_bits feature

This patch adds nat_bits in the last one ore two 4KB-sized blocks of first
checkpoint segment. So, now a set of checkpoint *segment* consists of:

< checkpoint segment >
----------------------
| cp page #1         | 4KB
----------------------
| compacted data sum | 4KB
----------------------
| node sum  #1       | 4KB
----------------------
| node sum  #2       | 4KB
----------------------
| node sum  #3       | 4KB
----------------------
| cp page #2         | 4KB
----------------------
...
----------------------
| crc|cpver          | 8 bytes
----------------------
| full NAT bits      | # of NAT segments / 2 * 512 / 8 bytes
----------------------
| empty NAT bits     | # of NAT segments / 2 * 512 / 8 bytes
----------------------

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: fix wrong usage out
Jaegeuk Kim [Sat, 11 Feb 2017 00:12:33 +0000 (16:12 -0800)]
fsck.f2fs: fix wrong usage out

This fixes wrong messages for error out.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: catch up up-to-date checkpoint flag
Jaegeuk Kim [Thu, 9 Feb 2017 18:32:19 +0000 (10:32 -0800)]
f2fs-tools: catch up up-to-date checkpoint flag

It needs to use up-to-date ckpt flag.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: make sure clean all reset dnodes
Kinglong Mee [Tue, 7 Feb 2017 02:43:09 +0000 (10:43 +0800)]
mkfs.f2fs: make sure clean all reset dnodes

memset(raw_node, 0, F2FS_BLKSIZE) sets the next_blkaddr to zero,
so that, only one reset dnode is cleaned always.

Fixes: ad042d9194f5 "mkfs.f2fs: reset dnode with zeros",
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: check the c.overprovision with zero before using it
Kinglong Mee [Mon, 6 Feb 2017 09:58:43 +0000 (17:58 +0800)]
mkfs.f2fs: check the c.overprovision with zero before using it

The using of c.overprovision when it equal zero as,

        c.reserved_segments =
                        (2 * (100 / c.overprovision + 1) + 6)
                        * c.segs_per_sec;

may cause problem, although it doesn't happen.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: correct checkpoint_ver of new checkpoint
Sheng Yong [Sat, 4 Feb 2017 06:45:59 +0000 (14:45 +0800)]
resize.f2fs: correct checkpoint_ver of new checkpoint

resize.f2fs rebuilds a new checkpoint at the new position. Its
checkpoint_ver should be increased.

Signed-off-by: Shuoran Liu <liushuoran@huawei.com>
Signed-off-by: Weichao Guo <guoweichao@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: release 1.8.0 v1.8.0
Jaegeuk Kim [Sat, 4 Feb 2017 00:00:20 +0000 (16:00 -0800)]
f2fs-tools: release 1.8.0

This release includes:
 - enhance fsck.f2fs mostly.
 - retrieve lost files from dump.f2fs.
 - support zoned device and multiple devices.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix bad assignment of total_sectors for f2fs_configuration
Kinglong Mee [Tue, 24 Jan 2017 02:42:53 +0000 (10:42 +0800)]
mkfs.f2fs: fix bad assignment of total_sectors for f2fs_configuration

wanted_total_sectors is introduced instead total_sectors,
so that, the initialize is a fault, drop it.

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: remove wrong dentry due to hash conversion
Jaegeuk Kim [Wed, 1 Feb 2017 18:33:54 +0000 (10:33 -0800)]
fsck.f2fs: remove wrong dentry due to hash conversion

This patch removes stale dentries remained by hash conversion issue which
happened long time ago.

Fixes: aafe2ca3dc72 ("fsck.f2fs: fix wrong hash_code made by previous buggy code")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: always fix seg entry type if it is not DATA
Liu Xue [Tue, 24 Jan 2017 02:45:47 +0000 (10:45 +0800)]
fsck.f2fs: always fix seg entry type if it is not DATA

If the segment type and sum footer type are node, but its
sit type is corrupted as cold data, this will always trigger
type error crash in do_garbage_collect but not get fixed by fsck,
so fix seg entry type when it is not DATA.

Reported-by: KARBOWSKI Piotr <piotr.karbowski@gmail.com>
Signed-off-by: Liu Xue <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix a segfault when setting more than 7 devices
Kinglong Mee [Sun, 22 Jan 2017 09:16:39 +0000 (17:16 +0800)]
mkfs.f2fs: fix a segfault when setting more than 7 devices

[root@localhost f2fs-tools]# mkfs.f2fs -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 /dev/sdb1

kernel: mkfs.f2fs[9047]: segfault at 2b78a60f ip 0000000000401356 sp 00007fffde05c9c0 error 6 in mkfs.f2fs[400000+5000]

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: show parse errors neatly
Jaegeuk Kim [Sat, 21 Jan 2017 05:52:52 +0000 (13:52 +0800)]
fsck.f2fs: show parse errors neatly

This patch is just to clean up.

Cc: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: support -p without argument
Jaegeuk Kim [Sat, 21 Jan 2017 05:12:17 +0000 (13:12 +0800)]
fsck.f2fs: support -p without argument

This patch allows fsck run -p without argument. So we could use -p as
-p, -p 0, -p 1. '-p' and '-p 0' have the same meaning as '-a'. '-p 1'
check more meta data than '-a'.

Reported-by: KARBOWSKI Piotr <piotr.karbowski@gmail.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: correct endianness
Sheng Yong [Thu, 19 Jan 2017 03:03:40 +0000 (11:03 +0800)]
f2fs-tools: correct endianness

It is reported that fsck.f2fs behaves abnormally when running on MIPS32
rel 2 big endian cpu, since incorrect endianness. So let's correct all
endianess issues of f2fs-tools.

Reported-by: <k@vodka.home.kg>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoAdd a configure option for SELinux support
Sergey Kvachonok [Fri, 13 Jan 2017 08:02:02 +0000 (11:02 +0300)]
Add a configure option for SELinux support

./configure --without-selinux :: unconditionally disable SELinux support

./configure --with-selinux :: enable SELinux support and abort if
libselinux is not found

When no configure option is specified the current libselinux
autodetection behaviour is preserved.

Signed-off-by: Sergey Kvachonok <ravenexp@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: fix wrong i_name check for directory
Jaegeuk Kim [Thu, 22 Dec 2016 21:47:27 +0000 (13:47 -0800)]
fsck.f2fs: fix wrong i_name check for directory

We should not check the consistency between i_name and its dentry for directory.
The i_name is used only for normal file recovery when conducting roll-forward
recovery.

Moreover, this condition was totally missing encryption case which is breaking by

1. encrypt ./test
2. mkdir ./test/a
3. mkdir ./test/b
4. rename ./test/a ./test/b

-> fsck.f2fs reports wrong inconsistency in terms of i_name.

Reported-by: liushuoran <liushuoran@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: remove unused parameters
Yunlei He [Mon, 12 Dec 2016 03:48:56 +0000 (11:48 +0800)]
resize.f2fs: remove unused parameters

This patch remove unused parameters in these three functions:
get_new_sb, migrate_main and rebuild_superblock

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: fix the number of moved ssa blocks in migrate_ssa
Junling Zheng [Wed, 30 Nov 2016 03:23:42 +0000 (11:23 +0800)]
resize.f2fs: fix the number of moved ssa blocks in migrate_ssa

If the offset passed in migrate_ssa is not zero, it means that there're
offset segments of old main will disappear after migrating, then there're
offset blocks of old ssa should be invalidated and removed accordingly.
So, the number of moved ssa blocks should be: TOTAL_SEGS(sbi) - offset,
and the expanded summary, which is filled with zero_blocks, should start
from: new_sum_blkaddr + TOTAL_SEGS(sbi) - offset.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: remove duplicated header files
Sheng Yong [Fri, 25 Nov 2016 14:49:56 +0000 (22:49 +0800)]
fsck.f2fs: remove duplicated header files

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: correct the max segno in migrate_main
Junling Zheng [Mon, 28 Nov 2016 06:37:03 +0000 (14:37 +0800)]
resize.f2fs: correct the max segno in migrate_main

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: detect small partition by overprovision ratio and # of segments
Jaegeuk Kim [Mon, 28 Nov 2016 22:07:18 +0000 (14:07 -0800)]
mkfs.f2fs: detect small partition by overprovision ratio and # of segments

We should avoid zero overprovision ratio or # of segments caused by too small
device.

Reported-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: give random checkpoint version
Jaegeuk Kim [Thu, 24 Nov 2016 20:46:50 +0000 (12:46 -0800)]
mkfs.f2fs: give random checkpoint version

This is to avoid wrong recovery during xfstests.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: flush curseg sit entries
Liu Xue [Wed, 23 Nov 2016 12:40:06 +0000 (20:40 +0800)]
fsck.f2fs: flush curseg sit entries

Flush curseg sit entries, since type of sit entries may
be changed after move_curseg_info.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agodump.f2fs: fix an error in dump nat pack num
Yunlei He [Sat, 19 Nov 2016 13:24:41 +0000 (21:24 +0800)]
dump.f2fs: fix an error in dump nat pack num

This patch fix an error in dump nat pack num

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs add a simple check orphan inodes in -p 1 mode
Yunlei He [Sat, 19 Nov 2016 13:24:40 +0000 (21:24 +0800)]
fsck.f2fs add a simple check orphan inodes in -p 1 mode

This patch add a simple check orphan inodes in -p 1 mode

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoREADME: revisit README to fix typos and so on
Jaegeuk Kim [Tue, 15 Nov 2016 00:31:38 +0000 (16:31 -0800)]
README: revisit README to fix typos and so on

This patch fixes typos and enhance description.

Suggested-by: Rob Maris <rob@maris-ee.eu>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: initialize and avoid build warning for android
Jaegeuk Kim [Thu, 10 Nov 2016 22:15:13 +0000 (14:15 -0800)]
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>
7 years agof2fs-tools: support multiple devices
Jaegeuk Kim [Wed, 2 Nov 2016 00:23:40 +0000 (17:23 -0700)]
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>
7 years agofsck.f2fs: refactor build_nat_area_bitmap to speed up fsck
Junling Zheng [Tue, 8 Nov 2016 00:48:10 +0000 (08:48 +0800)]
fsck.f2fs: refactor build_nat_area_bitmap to speed up fsck

Refactor build_nat_area_bitmap, move out lookup_nat_in_journal from the
dual loops. Instead of looking up all nids in journals, we traverse nat
journals, whose entries are used to replace the NAT entries with the
corresponding nid to reduce the time build_nat_area_bitmap costs.

For "fsck -p 1", it reduces over half of the time.

Empty Fragmented Entirely
32G(ms):
  original 625.8 727.3
  improved 226.3 298.2
64G(ms):
  original 1159 1637.7
  improved 515.8 676.7

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: modify condition for resize
Yunlei He [Mon, 7 Nov 2016 13:25:58 +0000 (21:25 +0800)]
resize.f2fs: modify condition for resize

it better to decide resize or not by sector num.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: add a judgment after calloc
Yunlei He [Fri, 4 Nov 2016 09:34:11 +0000 (17:34 +0800)]
fsck.f2fs: add a judgment after calloc

This patch add a judgment after calloc avoid memory alloc
failure

Signed-off-by: Yunlei He <heyunlei@huawei.com>
[Jaegeuk Kim: remove unneeded memset to avoid build warning]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: no need to write a new cp if nothing to flush
Yunlei He [Fri, 4 Nov 2016 09:34:10 +0000 (17:34 +0800)]
fsck.f2fs: no need to write a new cp if nothing to flush

This patch avoid to write a new cp if no journal info

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: fill zeros for expanded ssa area
Jaegeuk Kim [Thu, 3 Nov 2016 05:23:24 +0000 (22:23 -0700)]
resize.f2fs: fill zeros for expanded ssa area

This will avoid wrong behavior after expanding volume.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: determine cp_addr by sbi->cur_cp
Jaegeuk Kim [Thu, 3 Nov 2016 04:10:15 +0000 (21:10 -0700)]
f2fs-tools: determine cp_addr by sbi->cur_cp

We don't guarantee cp_addr is fixed by cp_ver due to sload.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agosload.f2fs: not support to find or add files in inline_dir directory
Jaegeuk Kim [Thu, 3 Nov 2016 01:59:35 +0000 (18:59 -0700)]
sload.f2fs: not support to find or add files in inline_dir directory

Now, sload.f2fs doesn't support inline_dir.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: get latest free segments
Jaegeuk Kim [Thu, 3 Nov 2016 01:20:05 +0000 (18:20 -0700)]
resize.f2fs: get latest free segments

The # of free segments can be changed by defragmentation.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: fix end block addres when finding free block
Jaegeuk Kim [Thu, 3 Nov 2016 01:00:48 +0000 (18:00 -0700)]
f2fs-tools: fix end block addres when finding free block

This patch fixes wrong end_blkaddr condition for free block allocation.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: fix wrong end_blkaddr
Jaegeuk Kim [Thu, 3 Nov 2016 00:59:35 +0000 (17:59 -0700)]
resize.f2fs: fix wrong end_blkaddr

The end_blkaddr should add main area segments.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agodefrag.f2fs: return error for no space case
Jaegeuk Kim [Thu, 3 Nov 2016 00:58:31 +0000 (17:58 -0700)]
defrag.f2fs: return error for no space case

This returns error instead of assertion for resize.f2fs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: fix wrong offset calculation
Jaegeuk Kim [Wed, 2 Nov 2016 22:17:15 +0000 (15:17 -0700)]
resize.f2fs: fix wrong offset calculation

When we move whole main area into new expanded area, we do not change its
segment numbers from sit and ssa.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agoresize.f2fs: add more information in debug messages
Jaegeuk Kim [Wed, 2 Nov 2016 22:15:02 +0000 (15:15 -0700)]
resize.f2fs: add more information in debug messages

Print more information.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: add SSR-based allocation when free segment not enough
Liu Xue [Wed, 2 Nov 2016 12:55:56 +0000 (20:55 +0800)]
fsck.f2fs: add SSR-based allocation when free segment not enough

Add SSR-based allocation when free segment reach the limit of
reserved segments.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: rewrite entries info in segment manager
Liu Xue [Wed, 2 Nov 2016 10:17:18 +0000 (18:17 +0800)]
fsck.f2fs: rewrite entries info in segment manager

The entries info in segment manager may be not correct, since
corrupted blocks may already cleaned. So rewrite se info with
main area bitmap.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
[Jaegeuk Kim: remove obsolte variable in f2fs_fsck]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agolibf2fs: avoid build warning
Jaegeuk Kim [Tue, 1 Nov 2016 04:04:01 +0000 (21:04 -0700)]
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>
7 years agofsck.f2fs: check BLKZONED feature on mount
Damien Le Moal [Fri, 28 Oct 2016 07:57:04 +0000 (16:57 +0900)]
fsck.f2fs: check BLKZONED feature on mount

The BLKZONED feature is mandatory for host-managed zoned block
devices. So check that it is set.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: check zoned block devices configuration
Damien Le Moal [Fri, 28 Oct 2016 07:57:03 +0000 (16:57 +0900)]
mkfs.f2fs: check zoned block devices configuration

Make sure the drive has enough randomly writeable zones from
the beginning of the partition to hold the meta data sections.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: reset sequential zones on device discard
Damien Le Moal [Fri, 28 Oct 2016 07:57:02 +0000 (16:57 +0900)]
mkfs.f2fs: reset sequential zones on device discard

For a zoned blocks device, trim must reset all sequential zones
of the device.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: check options for zoned block devices
Damien Le Moal [Fri, 28 Oct 2016 07:57:01 +0000 (16:57 +0900)]
mkfs.f2fs: check options for zoned block devices

Trim must not be disabled with zoned mode.
For host-managed zoned block devices, the zoned mode is mandatory.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: introduce support for zoned block devices
Damien Le Moal [Fri, 28 Oct 2016 07:57:00 +0000 (16:57 +0900)]
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>
7 years agof2fs-tools: use zoned block device terminology
Damien Le Moal [Fri, 28 Oct 2016 07:56:59 +0000 (16:56 +0900)]
f2fs-tools: use zoned block device terminology

SMR stands for "Shingled Magnetic Recording" which makes sense
only for hard disk drives (spinning rust). The ZBC/ZAC standards
enable management of SMR disks, but solid state drives may also
support those standards. So replace "SMR" with "zoned block device"
to avoid a HDD centric terminology.

In particular, rename the HMSMR feature to BLKZONED.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: add executable files to .gitignore
Damien Le Moal [Fri, 28 Oct 2016 07:56:57 +0000 (16:56 +0900)]
f2fs-tools: add executable files to .gitignore

Git ignore executables fsck.f2fs, f2fstat, fibmap.f2fs
and parse.f2fs.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: do not check the first seg in a sec in find_next_free_block
Sheng Yong [Mon, 24 Oct 2016 02:16:04 +0000 (10:16 +0800)]
fsck.f2fs: do not check the first seg in a sec in find_next_free_block

The first segment is already checked, so there is no need to check it
again if we want to make sure the whole section is freed.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agodump/fsck: convert encrypted file name
Sheng Yong [Mon, 24 Oct 2016 02:16:03 +0000 (10:16 +0800)]
dump/fsck: convert encrypted file name

If fscrypt is enabled, we need to convert the encrypted file name before
printing it. So let's export convert_encrypted_name for other functions,
and make it returns the length of converted string.
This patch also changes the parameter of file_is_encrypt to f2fs_inode.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agosload.f2fs: allow to build without libselinux
Christian Hesse [Sat, 22 Oct 2016 20:06:54 +0000 (22:06 +0200)]
sload.f2fs: allow to build without libselinux

Some systems do not have libselinux. Allow to build sload.f2fs without
support for selinux.

Signed-off-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix the discarding size for block device
Jaegeuk Kim [Tue, 18 Oct 2016 21:31:32 +0000 (14:31 -0700)]
mkfs.f2fs: fix the discarding size for block device

This patch fixes wrong discarding size.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: support restore lost files into ./lost_found/
Jaegeuk Kim [Thu, 13 Oct 2016 23:04:52 +0000 (16:04 -0700)]
fsck.f2fs: support restore lost files into ./lost_found/

This patch adds to support restoring lost files into ./lost_found/.

For example,

 # fsck.f2fs /dev/sdXX

...
NID[0x87d7] is unreachable
NID[0x87d8] is unreachable
NID[0x87d9] is unreachable
[FSCK] Unreachable nat entries                        [Fail] [0x4988]
[FSCK] SIT valid block bitmap checking                [Fail]
[FSCK] Hard link checking for regular file            [Ok..] [0x0]
[FSCK] valid_block_count matching with CP             [Fail] [0x2]
[FSCK] valid_node_count matcing with CP (de lookup)   [Fail] [0x1]
[FSCK] valid_node_count matcing with CP (nat lookup)  [Ok..] [0x4989]
[FSCK] valid_inode_count matched with CP              [Fail] [0x1]
[FSCK] free segment_count matched with CP             [Ok..] [0x1f7]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]

Do you want to restore lost files into ./lost_found/? [Y/N] y

Then, you can restore unreachable files from ./lost_found/ in its best effort.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: check condition to avoid wrong memory allocation
Jaegeuk Kim [Thu, 13 Oct 2016 21:40:28 +0000 (14:40 -0700)]
fsck.f2fs: check condition to avoid wrong memory allocation

This patch should fix the below bug.

Info: checkpoint state = 4 :  compacted_summary sudden-power-off
[FIX] (is_valid_ssa_data_blk: 301)  --> Set data summary 0x1039 -> [0x3] [0x0] [0x0]
[ASSERT] (fsck_chk_data_blk:1459)  --> SIT bitmap is 0x0. blk_addr[0x20b6d8]
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x2 with invalid NID/ino 0x1644b164
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x2 with bad ino 0x1644b164
[ASSERT] (__chk_dentries:1269)  --> Bad dentry 0x0 with unexpected ftype 0x2c
[FIX] (__chk_dentries:1272)  --> Clear bad dentry 0x4 with bad ftype 0x2c
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x5 with invalid NID/ino 0x49000000
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x5 with bad ino 0x49000000
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x7 with invalid NID/ino 0x67706a2e
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x7 with bad ino 0x67706a2e
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x8 with invalid NID/ino 0x4a437044
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x8 with bad ino 0x4a437044
[ASSERT] (__chk_dentries:1269)  --> Bad dentry 0x0 with unexpected ftype 0x0
[FIX] (__chk_dentries:1272)  --> Clear bad dentry 0xf with bad ftype 0x0
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x20 with invalid NID/ino 0x4a150009
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x20 with bad ino 0x4a150009
[ASSERT] (__chk_dentries:1255)  --> Bad dentry 0x21 with invalid NID/ino 0x1800094a
[FIX] (__chk_dentries:1258)  --> Clear bad dentry 0x21 with bad ino 0x1800094a
*** buffer overflow detected ***: fsck.f2fs terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7fa56b17b38f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7fa56b212c9c]
/lib/x86_64-linux-gnu/libc.so.6(+0x109b60)[0x7fa56b211b60]
fsck.f2fs[0x4032f6]
fsck.f2fs[0x4063f7]
fsck.f2fs[0x406d09]
fsck.f2fs[0x4046b8]
fsck.f2fs[0x405378]
fsck.f2fs[0x405d86]
fsck.f2fs[0x402071]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fa56b129ec5]

Reported-by: Mirh <mirh@protonmail.ch>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agolibf2fs: avoid garbage printout
Jaegeuk Kim [Thu, 13 Oct 2016 21:39:16 +0000 (14:39 -0700)]
libf2fs: avoid garbage printout

This patch avoids to print garbage data.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: clean up and avoid build warning
Jaegeuk Kim [Wed, 12 Oct 2016 21:11:19 +0000 (14:11 -0700)]
f2fs-tools: clean up and avoid build warning

This patch is to clean up and avoid warnings when compiling aosp.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs: avoid AOSP build failure
Jaegeuk Kim [Wed, 12 Oct 2016 21:42:16 +0000 (14:42 -0700)]
f2fs: avoid AOSP build failure

SCSI-related operations are not permitted to AOSP biuld.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: allocate buffer after condition check
Jaegeuk Kim [Thu, 29 Sep 2016 22:00:07 +0000 (15:00 -0700)]
fsck.f2fs: allocate buffer after condition check

This patch makes buffer allocation be done after condition check.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: fix a typo in check_sector_size
Junling Zheng [Thu, 29 Sep 2016 10:38:36 +0000 (18:38 +0800)]
fsck.f2fs: fix a typo in check_sector_size

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: fix incorrect ERR_MSG in f2fs_do_mount
Junling Zheng [Thu, 29 Sep 2016 10:38:35 +0000 (18:38 +0800)]
fsck.f2fs: fix incorrect ERR_MSG in f2fs_do_mount

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: free cp_page_1 in validate_checkpoint
Junling Zheng [Thu, 29 Sep 2016 10:38:34 +0000 (18:38 +0800)]
fsck.f2fs: free cp_page_1 in validate_checkpoint

Free cp_page_1 in validate_checkpoint to avoid memory leak.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agolibf2fs: increase robustness when called on root device
Tobias Jakobi [Wed, 28 Sep 2016 17:28:03 +0000 (19:28 +0200)]
libf2fs: increase robustness when called on root device

On some systems '/proc/mounts' contains the entry '/dev/root'
as alias for the root device, while that alias doesn't actually
exist as symlink in /dev.

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

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

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

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

Signed-off-by: Tobias Jakobi <tjakobi@math.uni-bielefeld.de>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck: porting avoid unneeded loop in build_sit_entries to fsck
Yunlei He [Sat, 24 Sep 2016 04:29:17 +0000 (12:29 +0800)]
fsck: porting avoid unneeded loop in build_sit_entries to fsck

This patch porting avoid unneeded loop in build_sit_entries to fsck

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: use shorter config variable name
Jaegeuk Kim [Sat, 17 Sep 2016 01:41:00 +0000 (18:41 -0700)]
f2fs-tools: use shorter config variable name

This patch has no functional change.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agolibf2fs: use dev_read_block and dev_write_block
Jaegeuk Kim [Fri, 16 Sep 2016 01:44:41 +0000 (18:44 -0700)]
libf2fs: use dev_read_block and dev_write_block

This patche tries to use dev_read_block and dev_write_block as much as possible.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs: get fd for f2fs_trim_device
Jaegeuk Kim [Fri, 2 Sep 2016 17:33:44 +0000 (10:33 -0700)]
mkfs: get fd for f2fs_trim_device

This patch is to get a parameter for fd in f2fs_trim_device.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: free node_blk to avoid memory leak
Yunlong Song [Wed, 21 Sep 2016 13:01:55 +0000 (21:01 +0800)]
fsck.f2fs: free node_blk to avoid memory leak

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: do not need strdup for parse_feature
Yunlong Song [Wed, 21 Sep 2016 10:09:18 +0000 (18:09 +0800)]
mkfs.f2fs: do not need strdup for parse_feature

strdup is useless here, with no free op with its return value.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck: clear useless "continue" in __chk_dentries
Yunlong Song [Tue, 20 Sep 2016 12:43:48 +0000 (20:43 +0800)]
fsck: clear useless "continue" in __chk_dentries

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agolibf2fs: show disk information
Jaegeuk Kim [Fri, 5 Aug 2016 02:30:02 +0000 (19:30 -0700)]
libf2fs: show disk information

This adds to show disk information.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agof2fs-tools: release 1.7.0 v1.7.0
Jaegeuk Kim [Thu, 28 Jul 2016 20:10:46 +0000 (13:10 -0700)]
f2fs-tools: release 1.7.0

This version adds Host-managed SMR detection code.

libf2fs_format_la
 - changed its body

libf2fs_la
 - added zbc_scsi_report_zones()

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agofsck: recover symlink with zero i_size
Jaegeuk Kim [Fri, 15 Jul 2016 17:27:23 +0000 (10:27 -0700)]
fsck: recover symlink with zero i_size

If we have i_blocks, we can recover i_size.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 years agofsck.f2fs: clean up duplicated code
Xue Liu [Fri, 15 Jul 2016 12:01:25 +0000 (20:01 +0800)]
fsck.f2fs: clean up duplicated code

Call current_nat_addr() to calculate nat block address.

Signed-off-by: Xue Liu <liuxueliu.liu@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>