platform/upstream/f2fs-tools.git
6 years agof2fs-tools: introduce new option V to show version
Sheng Yong [Tue, 10 Apr 2018 03:28:19 +0000 (11:28 +0800)]
f2fs-tools: introduce new option V to show version

This patch introduces a new option -V to show the version of f2fs tools
and exit after that.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agoresize.f2fs: clear CP_COMPACT_SUM_FLAG when rebuilding checkpoint
Sheng Yong [Sun, 8 Apr 2018 02:14:29 +0000 (10:14 +0800)]
resize.f2fs: clear CP_COMPACT_SUM_FLAG when rebuilding checkpoint

Resize rebuilds checkpoint with 6 summary blocks, so if
CP_COMPACT_SUM_FLAG is set in the old checkpoint, clear it.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: support multiple features with one "-O"
Junling Zheng [Sun, 8 Apr 2018 04:09:13 +0000 (12:09 +0800)]
mkfs.f2fs: support multiple features with one "-O"

Now one "-O" option can support multiple features separated
by a comma or blank, such as:
feature1,feature2,... or "feature1 feature2 ..."

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: fix incorrect cold data location
Chao Yu [Wed, 4 Apr 2018 02:49:14 +0000 (10:49 +0800)]
mkfs.f2fs: fix incorrect cold data location

If last_zone((total_zones >> 2)) is equal or less than
next_zone(CURSEG_COLD_NODE), cold data area will be located in the
same position with hot data, fixes it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: release 1.11.0 v1.11.0
Jaegeuk Kim [Tue, 10 Jul 2018 19:38:57 +0000 (12:38 -0700)]
f2fs-tools: release 1.11.0

This release includes:
 - add sg_write_buffer for UFS firmware update in Android
 - wanted_sector_size to specify sector size explicity
 - support fsverity feature bit
 - support lost+found feature

And, it includes some critical bug fixes.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agoresize.f2fs: fix wrong nat_bits migration
Jaegeuk Kim [Sun, 17 Jun 2018 00:09:23 +0000 (17:09 -0700)]
resize.f2fs: fix wrong nat_bits migration

When wring the last nat_bits in new checkpoint, we call write_nat_bits()
to recover the nat_bits. But, we didn't update nm_i->nat_bitmap which we can
get the up-to-date nat blocks. After sit migration, old checkpoint has no
longer valid nat blocks, resulting in wrong free nid allocation at the following
mount time.

Let's indicate new nat_blocks by adjusting nat_bitmap in nat migration.

Reported-by: Lianjun Huang <huanglianjun@vivo.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: add sanity check nat_bits
Jaegeuk Kim [Sun, 17 Jun 2018 17:56:49 +0000 (10:56 -0700)]
fsck.f2fs: add sanity check nat_bits

This patch adds to check nat_bits is valid or not. If not, it writes correct
nat_bits.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: simplify fsck_chk_quota_node in PREEN_MODE_1
Junling Zheng [Mon, 26 Mar 2018 12:47:37 +0000 (20:47 +0800)]
fsck.f2fs: simplify fsck_chk_quota_node in PREEN_MODE_1

Do not do fsck_chk_node_blk to simplify fsck_chk_quota_node in
PREEN_MODE_1, as well as fsck_chk_orphan_node.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: reconnect unreachable files to lost+found
Sheng Yong [Tue, 6 Mar 2018 03:39:40 +0000 (11:39 +0800)]
fsck.f2fs: reconnect unreachable files to lost+found

This patch introduces lost_found feature to fsck. If a file is found
unreachable by fsck. Fsck tries to reconnect the file to lost+found
directory:
  1. Scan all unreachable file inodes, ignore non-inodes ones and
     directories.
  2. Check them and fix incorrupted data to make sure filesystem
     metadata (mainly counters and main/nat bitmap) are all consistent.
  3. Reconnect these files to lost+found. If lost+found does not exist,
     create it first. During reconnecting, expand lost+found's dentry
     block automatically. Reconnected files are renamed after its ino
     number.
  4. If reconnect fails drop the node and restore filesystem metadata.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: create lost+found directory
Sheng Yong [Tue, 6 Mar 2018 03:39:39 +0000 (11:39 +0800)]
mkfs.f2fs: create lost+found directory

This patch introduces a new feature F2FS_FEATURE_LOST_FOUND. It can be
switched on by indicating `-O lost_found'. If LOST_FOUND feature is
enabled, an empty directory lost+found is created by mkfs.

This is a preparation for fsck. During fsck, the directory is used to
save unreachable files, which have no parent directory or their parent
directory is removed by fsck. Encrypted files are also allowed to be
saved here.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: use uint64_t to avoid build warning]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agodump.f2fs: fix a wrong report for dump an {d,id,did}node
Yunlei He [Wed, 7 Mar 2018 03:59:54 +0000 (11:59 +0800)]
dump.f2fs: fix a wrong report for dump an {d,id,did}node

fix a wrong report for dump an {d,id,did}node like this:

[print_node_info: 283] Node ID [0x6820:26656] is direct node or indirect node.
[0]                     [0x 16b6684 : 23815812]
[1]                     [0x 16b6685 : 23815813]
[2]                     [0x 16b6686 : 23815814]
[3]                     [0x 16b6687 : 23815815]
[4]                     [0x 16b6688 : 23815816]
[5]                     [0x 16b6689 : 23815817]
[6]                     [0x 16b668a : 23815818]
[7]                     [0x 16b668b : 23815819]
[8]                     [0x 16b668c : 23815820]
[9]                     [0x 16b668d : 23815821]
[10]                    [0x 16b668e : 23815822]
Invalid (i)node block

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: treat db's data as hot one
Chao Yu [Wed, 28 Feb 2018 09:03:44 +0000 (17:03 +0800)]
mkfs.f2fs: treat db's data as hot one

DB files like .db, .db-journal, .db-wal, .db-shm are very active, this
patch adds db file type to hot file extension list by default.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: support hot file extension
Chao Yu [Thu, 1 Mar 2018 02:48:47 +0000 (10:48 +0800)]
mkfs.f2fs: support hot file extension

This patch adds new option '-E' to accept user configured hot file
extension, in order to let kernel module handle hot/cold file's datas
separately better.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofibmap: include f2fs_fs.h before other header files
Sheng Yong [Tue, 27 Feb 2018 08:39:33 +0000 (16:39 +0800)]
fibmap: include f2fs_fs.h before other header files

GCC 7.2.0 is unhappy with the usage of major/minor:

fibmap.c: In function â€˜print_stat’:
fibmap.c:70:13: warning: In the GNU C Library, "major" is defined
 by <sys/sysmacros.h>. For historical compatibility, it is
 currently defined by <sys/types.h> as well, but we plan to
 remove this soon. To use "major", include <sys/sysmacros.h>
 directly. If you did not intend to use a system-defined macro
 "major", you should undefine it after including <sys/types.h>.
  printf("dev       [%d:%d]\n", major(st->st_dev), minor(st->st_dev));
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is because config.h is not included first, as a result, macros
defined in config.h is not recognized. So let's include f2fs_fs.h
before other header files.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: read nat block if nat entry is invalid
Sheng Yong [Fri, 23 Feb 2018 03:18:00 +0000 (11:18 +0800)]
fsck.f2fs: read nat block if nat entry is invalid

fsck will cache all valid nat entries in memory. But when we try to
get a nat entry which is not cached, for example allocate a new nid
during reconnecting files, we need to read the uncached nat entry
from nat block again.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: integrate sanity_check_inode to __check_inode_mode
Sheng Yong [Fri, 23 Feb 2018 03:17:58 +0000 (11:17 +0800)]
fsck.f2fs: integrate sanity_check_inode to __check_inode_mode

In sanity_check_nid, __check_inode_mode will check i_mode value of an
inode. So integrate sanity_check_inode to __check_inode_mode to clean
up the code.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: introduce mkfs parameters in f2fs_configuration
Sheng Yong [Fri, 23 Feb 2018 03:17:56 +0000 (11:17 +0800)]
mkfs.f2fs: introduce mkfs parameters in f2fs_configuration

Introduce new parameters in f2fs_configuration for mkfs:
  * next_free_nid: save the next free nid
  * quota_inum: save how many blocks are used for quota inodes
  * quota_dnum: save how many blocks are used for quota data

Use these parameters to avoid duplicated count of these values. And
discard obsolete dnodes after all inodes are created.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: fix typo
Sheng Yong [Fri, 23 Feb 2018 03:17:55 +0000 (11:17 +0800)]
fsck.f2fs: fix typo

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: init f2fs_configuration as 0
Sheng Yong [Tue, 6 Feb 2018 04:31:22 +0000 (12:31 +0800)]
f2fs-tools: init f2fs_configuration as 0

use memset() to zerofy entire value.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agodump.f2fs: correct the seg type in ssa_dump
Junling Zheng [Tue, 6 Feb 2018 08:47:14 +0000 (16:47 +0800)]
dump.f2fs: correct the seg type in ssa_dump

Fix the mixed using of "ret" in ssa_dump.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: fix to handle endianness in f2fs_write_check_point_pack
Chao Yu [Thu, 8 Feb 2018 15:17:11 +0000 (23:17 +0800)]
mkfs.f2fs: fix to handle endianness in f2fs_write_check_point_pack

This patch fixes to handle missing endianness in f2fs_write_check_point_pack.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: fix to check all the types of current offsets
Jaegeuk Kim [Thu, 8 Feb 2018 01:36:46 +0000 (17:36 -0800)]
fsck.f2fs: fix to check all the types of current offsets

We can change the next block offsets sometimes, so we have to check it's
free or not all the time. This fixes that SSR type makes a hole for it.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: expand scalability of nat bitmap
Chao Yu [Thu, 25 Jan 2018 11:45:13 +0000 (19:45 +0800)]
mkfs.f2fs: expand scalability of nat bitmap

Previously, our total node number (nat_bitmap) and total nat segment count
will not monotonously increase along with image size, and max nat_bitmap size
is limited by "CHECKSUM_OFFSET - sizeof(struct f2fs_checkpoint) + 1", it is
with bad scalability when user wants to create more inode/node in larger image.

So this patch tries to relieve the limitation, by default, limitting total nat
entry number with 20% of total block number.

Before:
image_size(GB) nat_bitmap sit_bitmap nat_segment sit_segment
16 3836 64 36 2
32 3836 64 72 2
64 3772 128 116 4
128 3708 192 114 6
256 3580 320 110 10
512 3260 640 100 20
1024 2684 1216 82 38
2048 1468 2432 44 76
4096 3900 4800 120 150

After:
image_size(GB) nat_bitmap sit_bitmap nat_segment sit_segment
16 256 64 8 2
32 512 64 16 2
64 960 128 30 4
128 1856 192 58 6
256 3712 320 116 10
512 7424 640 232 20
1024 14787 1216 462 38
2048 29504 2432 922 76
4096 59008 4800 1844 150

Add a new option '-i' to control turning on/off this feature.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: reduce mem alloc during read sit block
Yunlei He [Mon, 29 Jan 2018 03:22:14 +0000 (11:22 +0800)]
fsck.f2fs: reduce mem alloc during read sit block

This patch reduce mem alloc during read sit block

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: read ahead xattr & direct node blocks
Yunlei He [Mon, 29 Jan 2018 09:37:41 +0000 (17:37 +0800)]
fsck.f2fs: read ahead xattr & direct node blocks

This patch read ahead xattr & direct node blocks, and
keep the order:

1. check data blocks
2. readahead xattr block
3. fsck xattr block
4. readahead {d,id,did}node block
5. fsck {d,id,did}node block

With above order, we can avoid unneeded readahead before
sub-directory iterated traversing or encountering error.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: Fix a bug breaking the right order.]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agodump.f2fs: support to dump dirent from blkaddr
Chao Yu [Tue, 30 Jan 2018 11:23:12 +0000 (19:23 +0800)]
dump.f2fs: support to dump dirent from blkaddr

This patch adds to support to dump dirent info based on block address
from dentry data block or inline dentry node.

[dump_dentry_block: 627] Inline Dentry block:
[dump_dentry_block: 650] bitmap pos[0x0] name[.] len[0x1] hash[0x0] ino[0x4] type[0x2]
[dump_dentry_block: 650] bitmap pos[0x1] name[..] len[0x2] hash[0x0] ino[0x3] type[0x2]

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: allow -p without value
Jaegeuk Kim [Wed, 31 Jan 2018 01:24:57 +0000 (17:24 -0800)]
fsck.f2fs: allow -p without value

This patch allows -p without value.

Suggested-by: Pavol Cupka <pavol.cupka@gmail.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agosload.f2fs: fix the missing of bit mask for file type
Junling Zheng [Thu, 3 May 2018 11:25:06 +0000 (19:25 +0800)]
sload.f2fs: fix the missing of bit mask for file type

Fix the missing of bit mask for the file type bit fields.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agosload.f2fs: give correct file type
Lianjun Huang [Mon, 7 May 2018 18:54:14 +0000 (11:54 -0700)]
sload.f2fs: give correct file type

This fixes permission error due to wrong file type.

Signed-off-by: Lianjun Huang <huanglianjun@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: fix check order in -p1
Jaegeuk Kim [Mon, 7 May 2018 18:49:58 +0000 (11:49 -0700)]
fsck.f2fs: fix check order in -p1

Checking nat entries with nat_area_bitmap should be done before quota check,
since fsck_chk_quota_node() unsets quota inode numbers in nat_area_bitmap.
It causes for -p1 to conduct full scan.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: get kernel version via uname(2)
Jaegeuk Kim [Tue, 1 May 2018 20:54:25 +0000 (13:54 -0700)]
f2fs-tools: get kernel version via uname(2)

This patch introduces uname(2) to get kernel version.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: avoid selinux denial for unnecessary sysfs node
Jaegeuk Kim [Tue, 1 May 2018 02:33:10 +0000 (19:33 -0700)]
mkfs.f2fs: avoid selinux denial for unnecessary sysfs node

This avoids unnecessary sysfs node access causing selinux denial.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agolibf2fs: Track AOSP libsparse API change.
Tao Bao [Thu, 26 Apr 2018 07:40:09 +0000 (00:40 -0700)]
libf2fs: Track AOSP libsparse API change.

The libsparse in AOSP is updating the type for 'len', from 'int' to
'size_t', in the callback parameter of sparse_file_foreach_chunk(). The
value represents a chunk size, which could be legitimately larger than
INT_MAX. This patch tracks the libsparse API change.

The change is guarded with SPARSE_CALLBACK_USES_SIZE_T that's exposed as
part of the libsparse change. This allows f2fs-tools to keep working
against older libsparse versions.

Signed-off-by: Tao Bao <tbao@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: fix stack overflow when reading out nat block
Jaegeuk Kim [Fri, 20 Apr 2018 18:40:18 +0000 (11:40 -0700)]
fsck.f2fs: fix stack overflow when reading out nat block

The size of nat_block is less then 4KB, resulting in stack overflow by dev_read.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: support fsverity feature
Jaegeuk Kim [Thu, 11 Jan 2018 03:33:47 +0000 (19:33 -0800)]
mkfs.f2fs: support fsverity feature

This is aligned to f2fs which reserves fsverity feature bit.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
6 years agof2fs-tools: use pointer and memory alloaction instead of defining "structure stat...
Iris Chang [Mon, 2 Apr 2018 07:59:24 +0000 (15:59 +0800)]
f2fs-tools: use pointer and memory alloaction instead of defining "structure stat" in function stack

Problem:
Function f2fs_dev_is_unmounted() and get_device_info() define local
variable "struct stat xxx". If the callstack is very deep and stack
is smaller, it will result in stack corruption.

Solution:
It is better to use pointer and memory allocation instead of defining
"structure stat" in function stack.

Signed-off-by: Iris Chang <iris.chang@mediatek.com>
[Jaegeuk Kim: fix build errors.]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: change to use #pragma pack(push, 1)
Hyojun Kim [Thu, 1 Mar 2018 21:22:01 +0000 (13:22 -0800)]
f2fs-tools: change to use #pragma pack(push, 1)

It was reported that #pragma pack(1) could create unwanted
influences. pack(push, 1) and pack(pop) are used instead.

Signed-off-by: Hyojun Kim <hyojun@google.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agolibf2fs,mkfs.f2fs: add wanted_sector_size for wanted_total_sectors
katao [Tue, 27 Mar 2018 05:25:46 +0000 (13:25 +0800)]
libf2fs,mkfs.f2fs: add wanted_sector_size for wanted_total_sectors

The wanted_total_sectors was determined by device sector size, but sometimes
we don't know precise sector_size by default. So, let's give wanted_sector_size
in such the ambiguous situation.

Signed-off-by: katao <katao@xiaomi.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
6 years agoresize.f2fs: fix access out-of memory boundary
Jaegeuk Kim [Fri, 23 Mar 2018 01:57:54 +0000 (18:57 -0700)]
resize.f2fs: fix access out-of memory boundary

This fixes out-of memory boundary on nat_bitmap, when resizing small to
large partition.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agotools: sg_write_buffer: add sg_write_buffer for FFU
Hyojun Kim [Thu, 1 Mar 2018 21:42:44 +0000 (13:42 -0800)]
tools: sg_write_buffer: add sg_write_buffer for FFU

sg_write_buffer sources are added for FFU.

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
6 years agof2fs-tools: release 1.10.0 v1.10.0
Jaegeuk Kim [Tue, 30 Jan 2018 22:35:10 +0000 (14:35 -0800)]
f2fs-tools: release 1.10.0

This release includes:
- build support for Mac/Windows
- sparse support for Android build
- --dry-run for fsck.f2fs
- -q to preserve quota limits

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: support inode creation time
Chao Yu [Thu, 25 Jan 2018 06:58:45 +0000 (14:58 +0800)]
f2fs-tools: support inode creation time

This patch supports inode_crtime feature to enable recording inode
creation time in inode layout.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: use mem nat info directly
Yunlei He [Mon, 22 Jan 2018 12:03:46 +0000 (20:03 +0800)]
fsck.f2fs: use mem nat info directly

Use mem nat info directly for we built in fsck init.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: show missing checkpoint flags
Jaegeuk Kim [Sat, 20 Jan 2018 21:55:14 +0000 (13:55 -0800)]
fsck.f2fs: show missing checkpoint flags

This patch shows some missing checkpoint flags.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: allow roll-forward for small checkpoint fix
Jaegeuk Kim [Sat, 20 Jan 2018 21:51:05 +0000 (13:51 -0800)]
fsck.f2fs: allow roll-forward for small checkpoint fix

This allows roll-forward when fsck.f2fs changes checkpoint crc.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agodump.f2fs: do not write nat bits when dumping info
Sheng Yong [Thu, 11 Jan 2018 02:17:21 +0000 (10:17 +0800)]
dump.f2fs: do not write nat bits when dumping info

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: set seed for random checkpoint_ver
Sheng Yong [Thu, 11 Jan 2018 02:17:20 +0000 (10:17 +0800)]
mkfs.f2fs: set seed for random checkpoint_ver

If seed is not set, rand always uses 1 as the default seed.

Signed-off-by: Liu Xue <liuxueliu.liu@huawei.com>
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: show encoded name when unlinking corrupted dentry
Sheng Yong [Thu, 11 Jan 2018 02:17:19 +0000 (10:17 +0800)]
fsck.f2fs: show encoded name when unlinking corrupted dentry

For dentry name, we should check if parent directory is encrypted. If it
is, show digest-encoded name instead of cipher text when unlink corrupted
dir entries.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agodump.f2fs: Test blkaddr is valid or not in option '-b'
Yunlei He [Thu, 4 Jan 2018 01:51:03 +0000 (09:51 +0800)]
dump.f2fs: Test blkaddr is valid or not in option '-b'

Test blkaddr is valid or not in option '-b'

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: Remove unused ckpt_valid_map info
Yunlei He [Fri, 29 Dec 2017 02:11:09 +0000 (10:11 +0800)]
fsck.f2fs: Remove unused ckpt_valid_map info

Remove unused ckpt_valid_map info.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: add -y for generic fsck
Jaegeuk Kim [Thu, 28 Dec 2017 20:33:03 +0000 (12:33 -0800)]
fsck.f2fs: add -y for generic fsck

-y is same as -f, which fixes any corruption all the time.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agoresize.f2fs: fix max_nat_bitmap_size miscalculatation
Gaoxiang (OS) [Fri, 22 Dec 2017 04:20:58 +0000 (04:20 +0000)]
resize.f2fs: fix max_nat_bitmap_size miscalculatation

For the same reason as "mkfs.f2fs: fix to calculate
left space of checkpoint page correctly",
this patch also fixes miscalculatation in resize.f2fs.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: avoid wrong IS_VALID_BLK_ADDR
Jaegeuk Kim [Thu, 28 Dec 2017 02:02:32 +0000 (18:02 -0800)]
fsck.f2fs: avoid wrong IS_VALID_BLK_ADDR

This patch avoids to check next free block offset in current segments, since we
are using IS_VALID_BLK_ADDR during fsck which is able to be valid for a while.
Let's just check this at the end of fsck.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: check and fix i_namelen to avoid double free
Yunlong Song [Mon, 18 Dec 2017 13:25:27 +0000 (21:25 +0800)]
fsck.f2fs: check and fix i_namelen to avoid double free

This checks i_namelen between inode block and its dentry.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: check nid range before use to avoid segmentation fault
Yunlong Song [Mon, 18 Dec 2017 11:53:45 +0000 (19:53 +0800)]
fsck.f2fs: check nid range before use to avoid segmentation fault

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: Limit pragma pack(1) only for Windows Host
Hyojun Kim [Thu, 14 Dec 2017 18:15:47 +0000 (10:15 -0800)]
mkfs.f2fs: Limit pragma pack(1) only for Windows Host

A side-effect was found for #pragma pack(1), which were added for
Windows SDK support. Limiting it with ANDROID_WINDOWS_HOST.

Signed-off-by: Hyojun Kim <hyojun@google.com>
6 years agomkfs.f2fs: Windows Android SDK support
Hyojun Kim [Fri, 1 Dec 2017 23:03:30 +0000 (23:03 +0000)]
mkfs.f2fs: Windows Android SDK support

This patch enables cross compilation for Windows Android SDK
by using ANDROID_WINDOWS_HOST.

Signed-off-by: Hyojun Kim <hyojun@google.com>
6 years agof2fs-tools: enable sparse_file opeartions
Jaegeuk Kim [Thu, 30 Nov 2017 04:34:37 +0000 (20:34 -0800)]
f2fs-tools: enable sparse_file opeartions

This adds reading data from sparse_file.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agosload.f2fs: update build for android
Jaegeuk Kim [Thu, 30 Nov 2017 01:21:12 +0000 (17:21 -0800)]
sload.f2fs: update build for android

This patch updates sload.f2fs for android build.

- do fsck() after sload() to update quota information.
- return success, if there's no source directory

  -C fs_config

  -f source directory [path of the source directory]

  -p product out directory
    : path on fs_config file for uid/gid/mode

  -s file_contexts
    : selabel file

  -t mount point [prefix of target fs path, default:/]
     : path stored in selabel/fs_config files

  -T timestamp

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: allow multiple prog names
Jaegeuk Kim [Thu, 30 Nov 2017 02:49:15 +0000 (18:49 -0800)]
f2fs-tools: allow multiple prog names

This patch allows different prog names like fsck_f2fs, sload_f2fs, etc for
android.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: match uid/gid/projid between root inode and quota info
Jaegeuk Kim [Thu, 30 Nov 2017 19:35:48 +0000 (11:35 -0800)]
mkfs.f2fs: match uid/gid/projid between root inode and quota info

This patch fixes mismatched root inode and quota info.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agomkfs.f2fs: show debug message for quota data writes
Jaegeuk Kim [Thu, 30 Nov 2017 18:40:12 +0000 (10:40 -0800)]
mkfs.f2fs: show debug message for quota data writes

This patch shows debugging message for quota.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: build tools selectively
Jaegeuk Kim [Thu, 30 Nov 2017 01:15:18 +0000 (17:15 -0800)]
f2fs-tools: build tools selectively

This patch enables to build tools except mkfs.f2fs selectively.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agolibf2fs: propagate error from f2fs_{finalize,fsync}_device
Chao Yu [Fri, 24 Nov 2017 09:33:39 +0000 (17:33 +0800)]
libf2fs: propagate error from f2fs_{finalize,fsync}_device

tests/generic/405 of fstest suit expects that mkfs will return error
when it hits EIO, so let's propagate error from
f2fs_{finalize,fsync}_device, then mkfs can be aware of fsync error.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: initialize ret to zero]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: adjust feature name
Chao Yu [Thu, 16 Nov 2017 11:50:58 +0000 (19:50 +0800)]
f2fs-tools: adjust feature name

This patch slightly changes showed feature name.

Before:
Info: superblock features = f9 :  encrypt extra attribute project quota inode checksum flexible inline xattr quota ino

After:
Info: superblock features = f9 :  encrypt extra_attr project_quota inode_checksum flexible_inline_xattr quota_ino

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs: avoid memory leak in f2fs_write_root_inode
Chao Yu [Thu, 16 Nov 2017 11:50:57 +0000 (19:50 +0800)]
f2fs: avoid memory leak in f2fs_write_root_inode

Before exiting f2fs_write_root_inode, we should free in-there allocated
memory.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck.f2fs: fix potential stack overflow issue
Chao Yu [Thu, 16 Nov 2017 11:50:56 +0000 (19:50 +0800)]
fsck.f2fs: fix potential stack overflow issue

In fsck_chk_inode_blk, we will allocate 256 bytes memory in stack before
traversing sub-directory recursively, it's not safe, in order to avoid
potential stack overflow, use malloc instead.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agodump.f2fs: show extra attr only when feature is enabled
Chao Yu [Thu, 16 Nov 2017 11:50:55 +0000 (19:50 +0800)]
dump.f2fs: show extra attr only when feature is enabled

If we don't turn on the feature, don't show related info in dumped data.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: define WITH_ANDROID if __ANDROID__ is defined
Jaegeuk Kim [Thu, 16 Nov 2017 23:47:29 +0000 (15:47 -0800)]
f2fs-tools: define WITH_ANDROID if __ANDROID__ is defined

This matches with __ANDROID__ with WITH_ANDROID.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agof2fs-tools: build binaries in Mac
Jaegeuk Kim [Tue, 14 Nov 2017 18:53:32 +0000 (10:53 -0800)]
f2fs-tools: build binaries in Mac

This patch modifies f2fs-tools to be built in mac.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agolib/libf2fs.c: include <sys/sysmacros.h>
Anthony G. Basile [Sun, 12 Nov 2017 23:07:54 +0000 (18:07 -0500)]
lib/libf2fs.c: include <sys/sysmacros.h>

The macros `major' and `minor' have been moved from <sys/types.h>
to <sys/sysmacros.h>.  We include the latter to avoid deprecated
messages and future proof the code.

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 years agofsck/Makefile.am, mkfs/Makefile.am: fix to `make distcheck` correctly
Anthony G. Basile [Sun, 12 Nov 2017 22:57:41 +0000 (17:57 -0500)]
fsck/Makefile.am, mkfs/Makefile.am: fix to `make distcheck` correctly

We add noinst_HEADERS to include header files which are needed to build
but which do not need to be installed on the file system, and include_HEADERS
which are header files that should be installed in $(includedir).
This fixes 'make distcheck`.

Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
[Jaegeuk Kim: remove list.h]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agodump/fsck: introduce print_xattr_entry
Sheng Yong [Fri, 3 Nov 2017 04:25:12 +0000 (12:25 +0800)]
dump/fsck: introduce print_xattr_entry

This patch exports read_all_xattrs to allow dump/fsck to get all xattrs,
and introduces print_xattr_entry which tries to parse an xattr entry
accroding to its xattr index.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
[Jaegeuk Kim: fix configure.ac]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: add an option to preserve quota limits
Jaegeuk Kim [Wed, 8 Nov 2017 19:20:47 +0000 (11:20 -0800)]
fsck.f2fs: add an option to preserve quota limits

If it detects quota file errors, we can see insane quota limits. In order
to recover that, this patch adds an option to reset them as zeros.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck: check inline_dentry i_addr[0] same as inline_data
Yunlei He [Fri, 3 Nov 2017 06:29:39 +0000 (14:29 +0800)]
fsck: check inline_dentry i_addr[0] same as inline_data

<4>[   30.222442s][pid:1,cpu4,init][<ffffff8008357ffc>] f2fs_evict_inode+0x850/0xa34
<4>[   30.222442s][pid:1,cpu4,init][<ffffff8008209ec4>] evict+0xa0/0x168
<4>[   30.222442s][pid:1,cpu4,init][<ffffff800820ad34>] iput+0x188/0x220
<4>[   30.222473s][pid:1,cpu4,init][<ffffff800836d050>] recover_orphan_inodes+0x2b4/0xa80
<4>[   30.222473s][pid:1,cpu4,init][<ffffff80083648b0>] f2fs_fill_super+0xcf4/0x16a0
<4>[   30.222473s][pid:1,cpu4,init][<ffffff80081f2478>] mount_bdev+0x198/0x1c8
<4>[   30.222473s][pid:1,cpu4,init][<ffffff80083608a8>] f2fs_mount+0x14/0x1c
<4>[   30.222503s][pid:1,cpu4,init][<ffffff80081f2f38>] mount_fs+0x3c/0x15c
<4>[   30.222503s][pid:1,cpu4,init][<ffffff800820e9f8>] vfs_kern_mount+0x7c/0x16c
<4>[   30.222503s][pid:1,cpu4,init][<ffffff8008212548>] do_mount+0x214/0xcf8
<4>[   30.222503s][pid:1,cpu4,init][<ffffff800821338c>] SyS_mount+0xa8/0x164
<4>[   30.222503s][pid:1,cpu4,init][<ffffff80080831b0>] el0_svc_naked+0x24/0x28

Mount failed with message as blow:
recover_orphan_inode: orphan failed (ino=1265), run fsck to fix

One orphan directory with inline_dentry flag, but i_addr[0] is not zero.
By the way, sit bitmap of i_addr[0] is also invalidate.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: format output message of FIX_MSG
Sheng Yong [Thu, 2 Nov 2017 03:56:12 +0000 (11:56 +0800)]
fsck.f2fs: format output message of FIX_MSG

This patch removes an extra '\n' at the end of the string in FIX_MSG.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: remove unused list.h
Sheng Yong [Thu, 2 Nov 2017 03:56:11 +0000 (11:56 +0800)]
f2fs-tools: remove unused list.h

Commit 7d96d138a378 ("fsck.f2fs: remove list.h") has already the usage
of list.h. So let's remove list.h itself.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: introduce sanity_check_inode
Sheng Yong [Thu, 2 Nov 2017 03:56:10 +0000 (11:56 +0800)]
fsck.f2fs: introduce sanity_check_inode

f2fs_iget checks if i_mode is valid. If it is not, the file cannot be
accessed as well as deleted. To make sure such files can be removed,
fsck adds the same check, and removes incorrect inode blocks.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: introduce new option --dry-run
Sheng Yong [Thu, 2 Nov 2017 03:56:09 +0000 (11:56 +0800)]
fsck.f2fs: introduce new option --dry-run

With --dry-run enabled, fsck.f2fs will do all checks and "fixes" except
that all fixes will not be written to storage at last.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agodump.f2fs: do not dump encrypted files
Sheng Yong [Thu, 2 Nov 2017 03:56:08 +0000 (11:56 +0800)]
dump.f2fs: do not dump encrypted files

If a file is encrypted, its content is cipher text on the storage. So
there is no need to dump an encrypted file.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agodump.f2fs: introduce dump_xattr
Sheng Yong [Thu, 2 Nov 2017 03:56:07 +0000 (11:56 +0800)]
dump.f2fs: introduce dump_xattr

This patch introduces dump_xattr to create xattrs for dumped files.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
[Jaegeuk Kim: detect header files]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: do not fix corrupted nat entries in build_nat_area_bitmap
Sheng Yong [Thu, 2 Nov 2017 03:56:05 +0000 (11:56 +0800)]
fsck.f2fs: do not fix corrupted nat entries in build_nat_area_bitmap

Fixing corrupted data depends on c.fix_on. If it's not set, we should not
force fixing corrupted data.  So if nat entries are found invalid when
building nat_area_bitmap, we should just set c.bug_on, and fix it later.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: do not set fix_on directly
Sheng Yong [Thu, 2 Nov 2017 03:56:04 +0000 (11:56 +0800)]
fsck.f2fs: do not set fix_on directly

Do not set fix_on if it is allowed by user.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: fix warnings when building in android
Jaegeuk Kim [Thu, 2 Nov 2017 17:41:16 +0000 (10:41 -0700)]
f2fs-tools: fix warnings when building in android

This patch tries to avoid all the warnings.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
7 years agomkfs.f2fs: set .so to cold files
Jaegeuk Kim [Fri, 3 Nov 2017 03:12:30 +0000 (20:12 -0700)]
mkfs.f2fs: set .so to cold files

This patch adds .so in cold file extention list.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: support quota
Hyojun Kim [Mon, 30 Oct 2017 23:21:09 +0000 (23:21 +0000)]
fsck.f2fs: support quota

This patch let fsck to check and fix quota file contents.

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
7 years agomkfs.f2fs: support quota option in mkfs
Hyojun Kim [Mon, 30 Oct 2017 23:10:27 +0000 (23:10 +0000)]
mkfs.f2fs: support quota option in mkfs

This patch let mkfs to handle quota option and create quota files.

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
7 years agof2fs-tools: f2fs_read() and f2fs_filesize_update() are added
Hyojun Kim [Mon, 30 Oct 2017 21:26:30 +0000 (21:26 +0000)]
f2fs-tools: f2fs_read() and f2fs_filesize_update() are added

This patch adds f2fs_read() and f2fs_filesize_update(). It also refactors
f2fs_write_block() and renamed as f2fs_write().

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
7 years agosload.f2fs: fix bugs in f2fs_write_block()
Hyojun Kim [Mon, 30 Oct 2017 19:12:39 +0000 (12:12 -0700)]
sload.f2fs: fix bugs in f2fs_write_block()

Found and fixed following three bugs in f2fs_write_block() function.
 - Write (4096 - offset) bytes for the first block even for small count.
 - For overwriting, found blkaddr is not used for writing.
 - dn.idirty status can be lost by set_new_dnode().
 - missing inode_checksum

Signed-off-by: Hyojun Kim <hyojun@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
7 years agof2fs-tools: support flexible inline xattr size
Chao Yu [Mon, 4 Sep 2017 10:58:29 +0000 (18:58 +0800)]
f2fs-tools: support flexible inline xattr size

This patch makes mkfs to support flexible inline xattr feature, also
this enables fsck to recognize new disk-layout of inode which be of
flexible inline xattr size.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck: introduce generic function f2fs_fsync_device
Yunlei He [Tue, 17 Oct 2017 07:03:51 +0000 (15:03 +0800)]
fsck: introduce generic function f2fs_fsync_device

We use f2fs_finalize_device to fsync previous data in
checkpoint area before write last CP pack, in order to avoid
cp corruption in sudden-power-off case. But this function will
close the device, so this patch introduce a function to call
fsync() only.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix wrong end blkaddr
Liu Xue [Tue, 10 Oct 2017 12:49:35 +0000 (20:49 +0800)]
mkfs.f2fs: fix wrong end blkaddr

The end blkaddr should use main blkaddr and add main area segments.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: release 1.9.0 v1.9.0
Jaegeuk Kim [Thu, 21 Sep 2017 23:15:40 +0000 (16:15 -0700)]
f2fs-tools: release 1.9.0

This release includes:
 - sparse support
 - inode checksum support
 - nat_bits option
 - encryption management
 - noheap allocation by default
 - add CP_TRIMMED_FLAG

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: move_curseg_info only if check_curseg_offset fails
Yunlong Song [Sun, 10 Sep 2017 16:20:36 +0000 (00:20 +0800)]
f2fs-tools: move_curseg_info only if check_curseg_offset fails

Current design will lose recovery process when check_curseg_offset is OK.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: fix is_set_ckpt_flags for correct bool value
Yunlong Song [Sun, 10 Sep 2017 11:15:29 +0000 (19:15 +0800)]
f2fs-tools: fix is_set_ckpt_flags for correct bool value

If flag bit to check is in 0xFFFFFF00, then the return value will be false,
this is not correct, so fix it.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: add cscope files to .gitignore
Yunlong Song [Thu, 7 Sep 2017 13:09:15 +0000 (21:09 +0800)]
f2fs-tools: add cscope files to .gitignore

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix wrong curseg check
Jaegeuk Kim [Fri, 25 Aug 2017 02:33:10 +0000 (19:33 -0700)]
mkfs.f2fs: fix wrong curseg check

We should avoid i==j, otherwise we always assign 0~5 segments.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agofsck.f2fs: write back last cp block in the end
Yunlei He [Wed, 23 Aug 2017 04:13:04 +0000 (12:13 +0800)]
fsck.f2fs: write back last cp block in the end

Write back last cp block in the end in case of sudden power off
during fsck process

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agomkfs.f2fs: fix missing cpu_to_le64 for checkpoint version
Jaegeuk Kim [Wed, 23 Aug 2017 20:33:00 +0000 (13:33 -0700)]
mkfs.f2fs: fix missing cpu_to_le64 for checkpoint version

The error on mips was reported by Stijn as follow.

Commit 8399a29df92d6867d226df362edbf2e0efa527c1 in f2fs-tools
("mkfs.f2fs: give random checkpoint version") causes a bug when mounting
a filesystem created with it on a MIPS64 device running a 4.4(.83)
kernel. The following kernel warning appears several times per second,
for 30 seconds:

[   23.837262] ------------[ cut here ]------------
[   23.842039] WARNING: CPU: 0 PID: 935 at fs/f2fs/segment.c:718
update_sit_entry+0x1c0/0x2b0()
[   23.850507] Modules linked in: pppoe ppp_async l2tp_ppp iptable_nat
[   24.174064] Call Trace:
[   24.176527] [<ffffffff81126e14>] show_stack+0x68/0xb4
[   24.181595] [<ffffffff81321fc4>] dump_stack+0x8c/0xc4
[   24.186660] [<ffffffff8113d004>] warn_slowpath_common+0xa0/0xd0
[   24.192597] [<ffffffff812e0148>] update_sit_entry+0x1c0/0x2b0
[   24.198353] [<ffffffff812e0a70>] refresh_sit_entry+0x70/0xf8
[   24.204022] [<ffffffff812e251c>] allocate_data_block+0x1f0/0x310
[   24.210038] [<ffffffff812e28d8>] do_write_page+0x29c/0x2bc
[   24.215532] [<ffffffff812e2a88>] write_data_page+0xa0/0xd8
[   24.221028] [<ffffffff812d844c>] do_write_data_page+0xe4/0x384
[   24.226870] [<ffffffff812d88f4>] f2fs_write_data_page+0x208/0x464
[   24.232972] [<ffffffff812d5184>] __f2fs_writepage+0x1c/0x74
[   24.238553] [<ffffffff812d54dc>]
f2fs_write_cache_pages.constprop.7+0x250/0x394
[   24.245869] [<ffffffff812d57f4>] f2fs_write_data_pages+0x130/0x1b0
[   24.252066] [<ffffffff811a9f80>] __filemap_fdatawrite_range+0xa0/0xd4
[   24.258515] [<ffffffff812d2338>] sync_dirty_dir_inodes+0x94/0xd8
[   24.264530] [<ffffffff812d2484>] write_checkpoint+0x108/0xb9c
[   24.270283] [<ffffffff812cc398>] f2fs_sync_fs+0x68/0xb0
[   24.275526] [<ffffffff812c641c>] f2fs_sync_file+0x2e8/0x518
[   24.281107] [<ffffffff81213ff4>] do_fsync+0x38/0x70
[   24.285992] [<ffffffff812142e8>] SyS_fsync+0x14/0x20
[   24.290972] [<ffffffff81103950>] syscall_common+0x34/0x58
[   24.296372]
[   24.298096] ---[ end trace fd3ac44449b218ab ]---

Fix: 8399a29df92d68 ("mkfs.f2fs: give random checkpoint version")
Reported-And-Tested-by: Stijn Tintel <stijn@linux-ipv6.be>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 years agof2fs-tools: support inode checksum
Chao Yu [Wed, 26 Jul 2017 15:01:35 +0000 (23:01 +0800)]
f2fs-tools: support inode checksum

This patch introduce a new option 'inode_checksum' for enabling inode
checksum functionality in mkfs/fsck/sload.

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