2012-10-26 12:56:34 +00:00
|
|
|
/**
|
2013-01-25 04:23:23 +00:00
|
|
|
* f2fs_fs.h
|
2012-10-26 12:56:34 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com/
|
libf2fs_io: Add user-space cache
Implemented cache options in F2FS configuration 'c' (i.e. user
options):
* use c.cache_config.num_cache_entry to set the number of
cache entries (in block), minimum 1024, or 0 to disable cache.
* use c.cache_config.max_hash_collision to set maximum hash
collision (max 16).
* use c.cavhe_config.dbg_en to enable printing of debug messages.
Cache properties:
* Per block save based (block size = f2fs block size = 4K Bytes)
* Device block indices are used to hash (simple modular hash
function) to cache indices.
* A hash collision (when a block is hashed to an already occupied
cache block) will trigger offset-based relocation to max 16
other places, at first empty slot found policy.
* A hash collision with all 17 possible relocating places occupied
will evict the oldest used one (replaced by the new read block).
A global 'use' tick is kept ticking-up per block read for this
purpose.
* On write cache hit, it will update the corresponding cached
block.
* On write cache miss, the data won't be cached.
* Write-through policy only: never delayed write.
* On read cache hit, it returns the cached block.
* On read cache miss, it issues an I/O read to the kernel, and
then caches and returns the block.
* Currently read ahead is not implemented. Yet, the read ahead
logic is kept as before, i.e. using kernel's read ahead
mechanism.
Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: Fix one bug in dcache_update_rw()]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-11-18 10:13:07 +00:00
|
|
|
* Copyright (c) 2019 Google Inc.
|
|
|
|
* http://www.google.com/
|
2020-12-08 08:15:54 +00:00
|
|
|
* Copyright (c) 2020 Google Inc.
|
|
|
|
* Robin Hsu <robinhsu@google.com>
|
|
|
|
* : add sload compression support
|
2012-10-26 12:56:34 +00:00
|
|
|
*
|
2014-04-07 03:10:59 +00:00
|
|
|
* Dual licensed under the GPL or LGPL version 2 licenses.
|
2014-09-23 05:22:33 +00:00
|
|
|
*
|
|
|
|
* The byteswap codes are copied from:
|
|
|
|
* samba_3_master/lib/ccan/endian/endian.h under LGPL 2.1
|
2012-10-26 12:56:34 +00:00
|
|
|
*/
|
2013-01-25 04:23:23 +00:00
|
|
|
#ifndef __F2FS_FS_H__
|
|
|
|
#define __F2FS_FS_H__
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2018-04-10 03:28:19 +00:00
|
|
|
#include <stdio.h>
|
2018-06-20 13:06:16 +00:00
|
|
|
#include <stdlib.h>
|
2022-04-21 22:18:20 +00:00
|
|
|
#include <stddef.h>
|
2018-06-20 13:06:16 +00:00
|
|
|
#include <string.h>
|
f2fs-tools: rebuild the quota inode if it is corrupted
commit 1228009520d1d2cb392ae52f8aaf3c6ec42edccf
category: bugfix
issue: #I6VAS0
CVE: NA
Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------
If the following process returns an error,
the quota inode, not the quota file, is damaged.
(fsck_chk_quota_node-->fsck_chk_node_blk-->sanity_check_nid)
The fsck does not have a process to rebuild the quota inode.
Because sanity_check_nid is not passed, fsck->nat_area_bitmap
can not be cleared, and then the NAT of quota will be nullify
during fix_nat_entries.
During the next fsck check, the quota inode check fails
because the address of the quota inode changes to 0.
In addition, in fsck_chk_quota_files-->f2fs_filesize_update,
data is written to address 0.
Therefore, when the quota inode is corrupted, we need to rebuild it.
Signed-off-by: Wang Xiaojun <wangxiaojun11@huawei.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2021-07-20 06:41:18 +00:00
|
|
|
#include <time.h>
|
2012-12-07 01:20:27 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2017-11-16 23:47:29 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
#define WITH_ANDROID
|
|
|
|
#endif
|
|
|
|
|
2017-11-14 18:53:32 +00:00
|
|
|
#ifdef WITH_ANDROID
|
|
|
|
#include <android_config.h>
|
2017-11-30 01:15:18 +00:00
|
|
|
#else
|
|
|
|
#define WITH_DUMP
|
|
|
|
#define WITH_DEFRAG
|
|
|
|
#define WITH_RESIZE
|
|
|
|
#define WITH_SLOAD
|
2021-05-21 10:32:38 +00:00
|
|
|
#define WITH_LABEL
|
2017-11-14 18:53:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#ifdef HAVE_LINUX_TYPES_H
|
2022-03-01 06:25:03 +00:00
|
|
|
#ifndef __SANE_USERSPACE_TYPES__
|
|
|
|
#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
|
|
|
|
#endif
|
2017-11-14 18:53:32 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-10-28 07:57:00 +00:00
|
|
|
#ifdef HAVE_LINUX_BLKZONED_H
|
|
|
|
#include <linux/blkzoned.h>
|
|
|
|
#endif
|
|
|
|
|
2017-11-30 01:21:12 +00:00
|
|
|
#ifdef HAVE_LIBSELINUX
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#include <selinux/label.h>
|
|
|
|
#endif
|
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
#ifdef UNUSED
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
|
|
|
#elif defined(__LCLINT__)
|
|
|
|
# define UNUSED(x) x
|
2019-03-01 17:47:13 +00:00
|
|
|
#elif defined(__cplusplus)
|
|
|
|
# define UNUSED(x)
|
2017-10-30 23:21:09 +00:00
|
|
|
#else
|
|
|
|
# define UNUSED(x) x
|
|
|
|
#endif
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
#ifndef static_assert
|
|
|
|
#define static_assert _Static_assert
|
|
|
|
#endif
|
|
|
|
|
2022-04-21 22:18:12 +00:00
|
|
|
#ifdef _WIN32
|
2017-12-01 23:03:30 +00:00
|
|
|
#undef HAVE_LINUX_TYPES_H
|
|
|
|
#endif
|
|
|
|
|
2020-12-08 08:15:54 +00:00
|
|
|
/* codes from kernel's f2fs.h, GPL-v2.0 */
|
|
|
|
#define MIN_COMPRESS_LOG_SIZE 2
|
|
|
|
#define MAX_COMPRESS_LOG_SIZE 8
|
|
|
|
|
2022-04-21 22:18:11 +00:00
|
|
|
typedef uint64_t u64;
|
|
|
|
typedef uint32_t u32;
|
|
|
|
typedef uint16_t u16;
|
|
|
|
typedef uint8_t u8;
|
2014-02-05 16:09:36 +00:00
|
|
|
typedef u32 block_t;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
typedef u32 nid_t;
|
2017-11-14 18:53:32 +00:00
|
|
|
#ifndef bool
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
typedef u8 bool;
|
2017-11-14 18:53:32 +00:00
|
|
|
#endif
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
typedef unsigned long pgoff_t;
|
2015-12-10 00:18:44 +00:00
|
|
|
typedef unsigned short umode_t;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2017-11-14 18:53:32 +00:00
|
|
|
#ifndef HAVE_LINUX_TYPES_H
|
|
|
|
typedef u8 __u8;
|
|
|
|
typedef u16 __u16;
|
|
|
|
typedef u32 __u32;
|
|
|
|
typedef u64 __u64;
|
|
|
|
typedef u16 __le16;
|
|
|
|
typedef u32 __le32;
|
|
|
|
typedef u64 __le64;
|
|
|
|
typedef u16 __be16;
|
|
|
|
typedef u32 __be32;
|
|
|
|
typedef u64 __be64;
|
|
|
|
#endif
|
|
|
|
|
2020-12-08 08:15:54 +00:00
|
|
|
/*
|
|
|
|
* code borrowed from kernel f2fs dirver: f2fs.h, GPL-2.0
|
|
|
|
* : definitions of COMPRESS_DATA_RESERVED_SIZE,
|
|
|
|
* struct compress_data, COMPRESS_HEADER_SIZE,
|
|
|
|
* and struct compress_ctx
|
|
|
|
*/
|
|
|
|
#define COMPRESS_DATA_RESERVED_SIZE 4
|
|
|
|
struct compress_data {
|
|
|
|
__le32 clen; /* compressed data size */
|
|
|
|
__le32 chksum; /* checksum of compressed data */
|
|
|
|
__le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */
|
|
|
|
u8 cdata[]; /* compressed data */
|
|
|
|
};
|
|
|
|
#define COMPRESS_HEADER_SIZE (sizeof(struct compress_data))
|
|
|
|
/* compress context */
|
|
|
|
struct compress_ctx {
|
|
|
|
unsigned int cluster_size; /* page count in cluster */
|
|
|
|
unsigned int log_cluster_size; /* log of cluster size */
|
|
|
|
void *rbuf; /* compression input buffer */
|
|
|
|
struct compress_data *cbuf; /* comprsssion output header + data */
|
|
|
|
size_t rlen; /* valid data length in rbuf */
|
|
|
|
size_t clen; /* valid data length in cbuf */
|
|
|
|
void *private; /* work buf for compress algorithm */
|
|
|
|
};
|
|
|
|
|
2014-09-23 05:22:33 +00:00
|
|
|
#if HAVE_BYTESWAP_H
|
|
|
|
#include <byteswap.h>
|
|
|
|
#else
|
|
|
|
/**
|
|
|
|
* bswap_16 - reverse bytes in a uint16_t value.
|
|
|
|
* @val: value whose bytes to swap.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* // Output contains "1024 is 4 as two bytes reversed"
|
|
|
|
* printf("1024 is %u as two bytes reversed\n", bswap_16(1024));
|
|
|
|
*/
|
|
|
|
static inline uint16_t bswap_16(uint16_t val)
|
|
|
|
{
|
|
|
|
return ((val & (uint16_t)0x00ffU) << 8)
|
|
|
|
| ((val & (uint16_t)0xff00U) >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bswap_32 - reverse bytes in a uint32_t value.
|
|
|
|
* @val: value whose bytes to swap.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* // Output contains "1024 is 262144 as four bytes reversed"
|
|
|
|
* printf("1024 is %u as four bytes reversed\n", bswap_32(1024));
|
|
|
|
*/
|
|
|
|
static inline uint32_t bswap_32(uint32_t val)
|
|
|
|
{
|
|
|
|
return ((val & (uint32_t)0x000000ffUL) << 24)
|
|
|
|
| ((val & (uint32_t)0x0000ff00UL) << 8)
|
|
|
|
| ((val & (uint32_t)0x00ff0000UL) >> 8)
|
|
|
|
| ((val & (uint32_t)0xff000000UL) >> 24);
|
|
|
|
}
|
|
|
|
#endif /* !HAVE_BYTESWAP_H */
|
|
|
|
|
2014-12-25 17:52:00 +00:00
|
|
|
#if defined HAVE_DECL_BSWAP_64 && !HAVE_DECL_BSWAP_64
|
2014-09-23 05:22:33 +00:00
|
|
|
/**
|
|
|
|
* bswap_64 - reverse bytes in a uint64_t value.
|
|
|
|
* @val: value whose bytes to swap.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* // Output contains "1024 is 1125899906842624 as eight bytes reversed"
|
|
|
|
* printf("1024 is %llu as eight bytes reversed\n",
|
|
|
|
* (unsigned long long)bswap_64(1024));
|
|
|
|
*/
|
|
|
|
static inline uint64_t bswap_64(uint64_t val)
|
|
|
|
{
|
|
|
|
return ((val & (uint64_t)0x00000000000000ffULL) << 56)
|
|
|
|
| ((val & (uint64_t)0x000000000000ff00ULL) << 40)
|
|
|
|
| ((val & (uint64_t)0x0000000000ff0000ULL) << 24)
|
|
|
|
| ((val & (uint64_t)0x00000000ff000000ULL) << 8)
|
|
|
|
| ((val & (uint64_t)0x000000ff00000000ULL) >> 8)
|
|
|
|
| ((val & (uint64_t)0x0000ff0000000000ULL) >> 24)
|
|
|
|
| ((val & (uint64_t)0x00ff000000000000ULL) >> 40)
|
|
|
|
| ((val & (uint64_t)0xff00000000000000ULL) >> 56);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
2022-04-21 22:18:17 +00:00
|
|
|
#define le16_to_cpu(x) ((uint16_t)(x))
|
|
|
|
#define le32_to_cpu(x) ((uint32_t)(x))
|
|
|
|
#define le64_to_cpu(x) ((uint64_t)(x))
|
|
|
|
#define cpu_to_le16(x) ((uint16_t)(x))
|
|
|
|
#define cpu_to_le32(x) ((uint32_t)(x))
|
|
|
|
#define cpu_to_le64(x) ((uint64_t)(x))
|
2022-04-21 22:18:19 +00:00
|
|
|
#define be32_to_cpu(x) __builtin_bswap64(x)
|
2012-10-26 12:56:34 +00:00
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
#define le16_to_cpu(x) bswap_16(x)
|
|
|
|
#define le32_to_cpu(x) bswap_32(x)
|
|
|
|
#define le64_to_cpu(x) bswap_64(x)
|
|
|
|
#define cpu_to_le16(x) bswap_16(x)
|
|
|
|
#define cpu_to_le32(x) bswap_32(x)
|
|
|
|
#define cpu_to_le64(x) bswap_64(x)
|
2022-04-21 22:18:19 +00:00
|
|
|
#define be32_to_cpu(x) ((uint64_t)(x))
|
2012-10-26 12:56:34 +00:00
|
|
|
#endif
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
#define typecheck(type,x) \
|
|
|
|
({ type __dummy; \
|
|
|
|
typeof(x) __dummy2; \
|
|
|
|
(void)(&__dummy == &__dummy2); \
|
|
|
|
1; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define NULL_SEGNO ((unsigned int)~0)
|
|
|
|
|
2013-01-25 08:20:16 +00:00
|
|
|
/*
|
|
|
|
* Debugging interfaces
|
|
|
|
*/
|
2014-08-28 17:27:17 +00:00
|
|
|
#define FIX_MSG(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
printf("[FIX] (%s:%4d) ", __func__, __LINE__); \
|
|
|
|
printf(" --> "fmt"\n", ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
#define ASSERT_MSG(fmt, ...) \
|
2013-01-25 08:20:16 +00:00
|
|
|
do { \
|
2014-08-27 23:16:16 +00:00
|
|
|
printf("[ASSERT] (%s:%4d) ", __func__, __LINE__); \
|
|
|
|
printf(" --> "fmt"\n", ##__VA_ARGS__); \
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 1; \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
|
|
|
#define ASSERT(exp) \
|
|
|
|
do { \
|
|
|
|
if (!(exp)) { \
|
2020-11-04 03:13:08 +00:00
|
|
|
printf("[ASSERT] (%s:%4d) %s\n", \
|
|
|
|
__func__, __LINE__, #exp); \
|
2013-01-25 08:20:16 +00:00
|
|
|
exit(-1); \
|
|
|
|
} \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
#define ERR_MSG(fmt, ...) \
|
|
|
|
do { \
|
2014-08-27 23:16:16 +00:00
|
|
|
printf("[%s:%d] " fmt, __func__, __LINE__, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2013-01-25 08:20:16 +00:00
|
|
|
#define MSG(n, fmt, ...) \
|
|
|
|
do { \
|
2021-06-13 03:42:47 +00:00
|
|
|
if (c.dbg_lv >= n && !c.layout && !c.show_file_map) { \
|
2013-01-25 08:20:16 +00:00
|
|
|
printf(fmt, ##__VA_ARGS__); \
|
|
|
|
} \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
|
|
|
#define DBG(n, fmt, ...) \
|
|
|
|
do { \
|
2021-06-13 03:42:47 +00:00
|
|
|
if (c.dbg_lv >= n && !c.layout && !c.show_file_map) { \
|
2013-01-25 08:20:16 +00:00
|
|
|
printf("[%s:%4d] " fmt, \
|
|
|
|
__func__, __LINE__, ##__VA_ARGS__); \
|
|
|
|
} \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
|
|
|
/* Display on console */
|
|
|
|
#define DISP(fmt, ptr, member) \
|
|
|
|
do { \
|
|
|
|
printf("%-30s" fmt, #member, ((ptr)->member)); \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
#define DISP_u16(ptr, member) \
|
|
|
|
do { \
|
|
|
|
assert(sizeof((ptr)->member) == 2); \
|
2021-05-23 21:23:06 +00:00
|
|
|
if (c.layout) \
|
|
|
|
printf("%-30s %u\n", \
|
|
|
|
#member":", le16_to_cpu(((ptr)->member))); \
|
|
|
|
else \
|
|
|
|
printf("%-30s" "\t\t[0x%8x : %u]\n", \
|
2017-07-26 14:49:57 +00:00
|
|
|
#member, le16_to_cpu(((ptr)->member)), \
|
|
|
|
le16_to_cpu(((ptr)->member))); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-01-25 08:20:16 +00:00
|
|
|
#define DISP_u32(ptr, member) \
|
|
|
|
do { \
|
|
|
|
assert(sizeof((ptr)->member) <= 4); \
|
2021-05-23 21:23:06 +00:00
|
|
|
if (c.layout) \
|
|
|
|
printf("%-30s %u\n", \
|
|
|
|
#member":", le32_to_cpu(((ptr)->member))); \
|
|
|
|
else \
|
|
|
|
printf("%-30s" "\t\t[0x%8x : %u]\n", \
|
2017-01-19 03:03:40 +00:00
|
|
|
#member, le32_to_cpu(((ptr)->member)), \
|
|
|
|
le32_to_cpu(((ptr)->member))); \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
|
|
|
#define DISP_u64(ptr, member) \
|
|
|
|
do { \
|
|
|
|
assert(sizeof((ptr)->member) == 8); \
|
2021-05-23 21:23:06 +00:00
|
|
|
if (c.layout) \
|
2022-04-21 22:18:17 +00:00
|
|
|
printf("%-30s %" PRIu64 "\n", \
|
2021-05-23 21:23:06 +00:00
|
|
|
#member":", le64_to_cpu(((ptr)->member))); \
|
|
|
|
else \
|
2022-04-21 22:18:17 +00:00
|
|
|
printf("%-30s" "\t\t[0x%8" PRIx64 " : %" PRIu64 "]\n", \
|
2017-01-19 03:03:40 +00:00
|
|
|
#member, le64_to_cpu(((ptr)->member)), \
|
|
|
|
le64_to_cpu(((ptr)->member))); \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
|
|
|
#define DISP_utf(ptr, member) \
|
|
|
|
do { \
|
2021-05-23 21:23:06 +00:00
|
|
|
if (c.layout) \
|
|
|
|
printf("%-30s %s\n", #member":", \
|
|
|
|
((ptr)->member)); \
|
|
|
|
else \
|
|
|
|
printf("%-30s" "\t\t[%s]\n", #member, \
|
|
|
|
((ptr)->member)); \
|
2014-08-27 23:16:16 +00:00
|
|
|
} while (0)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
|
|
|
/* Display to buffer */
|
2014-08-27 23:16:16 +00:00
|
|
|
#define BUF_DISP_u32(buf, data, len, ptr, member) \
|
|
|
|
do { \
|
|
|
|
assert(sizeof((ptr)->member) <= 4); \
|
|
|
|
snprintf(buf, len, #member); \
|
|
|
|
snprintf(data, len, "0x%x : %u", ((ptr)->member), \
|
|
|
|
((ptr)->member)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define BUF_DISP_u64(buf, data, len, ptr, member) \
|
|
|
|
do { \
|
|
|
|
assert(sizeof((ptr)->member) == 8); \
|
|
|
|
snprintf(buf, len, #member); \
|
|
|
|
snprintf(data, len, "0x%llx : %llu", ((ptr)->member), \
|
|
|
|
((ptr)->member)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define BUF_DISP_utf(buf, data, len, ptr, member) \
|
|
|
|
snprintf(buf, len, #member)
|
2013-01-25 08:20:16 +00:00
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/* these are defined in kernel */
|
2017-11-14 18:53:32 +00:00
|
|
|
#ifndef PAGE_SIZE
|
2012-10-26 12:56:34 +00:00
|
|
|
#define PAGE_SIZE 4096
|
2017-11-14 18:53:32 +00:00
|
|
|
#endif
|
2012-10-26 12:56:34 +00:00
|
|
|
#define PAGE_CACHE_SIZE 4096
|
|
|
|
#define BITS_PER_BYTE 8
|
2019-11-28 07:59:23 +00:00
|
|
|
#ifndef SECTOR_SHIFT
|
|
|
|
#define SECTOR_SHIFT 9
|
|
|
|
#endif
|
2013-01-25 04:39:34 +00:00
|
|
|
#define F2FS_SUPER_MAGIC 0xF2F52010 /* F2FS Magic Number */
|
2018-09-19 13:53:48 +00:00
|
|
|
#define CP_CHKSUM_OFFSET 4092
|
2018-09-28 12:25:59 +00:00
|
|
|
#define SB_CHKSUM_OFFSET 3068
|
2016-11-02 00:23:40 +00:00
|
|
|
#define MAX_PATH_LEN 64
|
|
|
|
#define MAX_DEVICES 8
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2015-12-10 00:18:44 +00:00
|
|
|
#define F2FS_BYTES_TO_BLK(bytes) ((bytes) >> F2FS_BLKSIZE_BITS)
|
|
|
|
#define F2FS_BLKSIZE_BITS 12
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/* for mkfs */
|
|
|
|
#define F2FS_NUMBER_OF_CHECKPOINT_PACK 2
|
|
|
|
#define DEFAULT_SECTOR_SIZE 512
|
|
|
|
#define DEFAULT_SECTORS_PER_BLOCK 8
|
|
|
|
#define DEFAULT_BLOCKS_PER_SEGMENT 512
|
|
|
|
#define DEFAULT_SEGMENTS_PER_SECTION 1
|
|
|
|
|
2021-07-16 21:57:03 +00:00
|
|
|
#define VERSION_LEN 256
|
|
|
|
#define VERSION_TIMESTAMP_LEN 4
|
|
|
|
#define VERSION_NAME_LEN (VERSION_LEN - VERSION_TIMESTAMP_LEN)
|
2014-11-07 03:34:40 +00:00
|
|
|
|
2018-03-06 03:39:39 +00:00
|
|
|
#define LPF "lost+found"
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
enum f2fs_config_func {
|
2017-11-30 04:34:37 +00:00
|
|
|
MKFS,
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
FSCK,
|
|
|
|
DUMP,
|
2015-10-23 18:45:36 +00:00
|
|
|
DEFRAG,
|
2015-12-09 00:05:09 +00:00
|
|
|
RESIZE,
|
2015-12-10 00:18:44 +00:00
|
|
|
SLOAD,
|
2021-05-21 10:32:38 +00:00
|
|
|
LABEL,
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
};
|
|
|
|
|
2018-04-19 18:33:14 +00:00
|
|
|
enum default_set {
|
|
|
|
CONF_NONE = 0,
|
|
|
|
CONF_ANDROID,
|
|
|
|
};
|
|
|
|
|
2016-11-02 00:23:40 +00:00
|
|
|
struct device_info {
|
|
|
|
char *path;
|
|
|
|
int32_t fd;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t sector_size;
|
|
|
|
uint64_t total_sectors; /* got by get_device_info */
|
|
|
|
uint64_t start_blkaddr;
|
|
|
|
uint64_t end_blkaddr;
|
|
|
|
uint32_t total_segments;
|
2016-11-02 00:23:40 +00:00
|
|
|
|
|
|
|
/* to handle zone block devices */
|
|
|
|
int zoned_model;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t nr_zones;
|
|
|
|
uint32_t nr_rnd_zones;
|
2016-11-02 00:23:40 +00:00
|
|
|
size_t zone_blocks;
|
2022-04-13 12:29:40 +00:00
|
|
|
uint64_t zone_size;
|
2020-07-21 16:38:11 +00:00
|
|
|
size_t *zone_cap_blocks;
|
2016-11-02 00:23:40 +00:00
|
|
|
};
|
|
|
|
|
libf2fs_io: Add user-space cache
Implemented cache options in F2FS configuration 'c' (i.e. user
options):
* use c.cache_config.num_cache_entry to set the number of
cache entries (in block), minimum 1024, or 0 to disable cache.
* use c.cache_config.max_hash_collision to set maximum hash
collision (max 16).
* use c.cavhe_config.dbg_en to enable printing of debug messages.
Cache properties:
* Per block save based (block size = f2fs block size = 4K Bytes)
* Device block indices are used to hash (simple modular hash
function) to cache indices.
* A hash collision (when a block is hashed to an already occupied
cache block) will trigger offset-based relocation to max 16
other places, at first empty slot found policy.
* A hash collision with all 17 possible relocating places occupied
will evict the oldest used one (replaced by the new read block).
A global 'use' tick is kept ticking-up per block read for this
purpose.
* On write cache hit, it will update the corresponding cached
block.
* On write cache miss, the data won't be cached.
* Write-through policy only: never delayed write.
* On read cache hit, it returns the cached block.
* On read cache miss, it issues an I/O read to the kernel, and
then caches and returns the block.
* Currently read ahead is not implemented. Yet, the read ahead
logic is kept as before, i.e. using kernel's read ahead
mechanism.
Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: Fix one bug in dcache_update_rw()]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-11-18 10:13:07 +00:00
|
|
|
typedef struct {
|
|
|
|
/* Value 0 means no cache, minimum 1024 */
|
|
|
|
long num_cache_entry;
|
|
|
|
|
|
|
|
/* Value 0 means always overwrite (no collision allowed). maximum 16 */
|
|
|
|
unsigned max_hash_collision;
|
|
|
|
|
|
|
|
bool dbg_en;
|
|
|
|
} dev_cache_config_t;
|
|
|
|
|
2020-12-08 08:15:54 +00:00
|
|
|
/* f2fs_configration for compression used for sload.f2fs */
|
|
|
|
typedef struct {
|
|
|
|
void (*init)(struct compress_ctx *cc);
|
|
|
|
int (*compress)(struct compress_ctx *cc);
|
|
|
|
void (*reset)(struct compress_ctx *cc);
|
|
|
|
} compress_ops;
|
|
|
|
|
|
|
|
/* Should be aligned to supported_comp_names and support_comp_ops */
|
|
|
|
enum compress_algorithms {
|
|
|
|
COMPR_LZO,
|
|
|
|
COMPR_LZ4,
|
|
|
|
MAX_COMPRESS_ALGS,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum filter_policy {
|
|
|
|
COMPR_FILTER_UNASSIGNED = 0,
|
|
|
|
COMPR_FILTER_ALLOW,
|
|
|
|
COMPR_FILTER_DENY,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
void (*add)(const char *);
|
|
|
|
void (*destroy)(void);
|
|
|
|
bool (*filter)(const char *);
|
|
|
|
} filter_ops;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
bool enabled; /* disabled by default */
|
|
|
|
bool required; /* require to enable */
|
|
|
|
bool readonly; /* readonly to release blocks */
|
|
|
|
struct compress_ctx cc; /* work context */
|
|
|
|
enum compress_algorithms alg; /* algorithm to compress */
|
|
|
|
compress_ops *ops; /* ops per algorithm */
|
|
|
|
unsigned int min_blocks; /* save more blocks than this */
|
|
|
|
enum filter_policy filter; /* filter to try compression */
|
|
|
|
filter_ops *filter_ops; /* filter ops */
|
|
|
|
} compress_config_t;
|
|
|
|
|
2021-08-23 18:38:23 +00:00
|
|
|
#define ALIGN_DOWN(addrs, size) (((addrs) / (size)) * (size))
|
|
|
|
#define ALIGN_UP(addrs, size) ALIGN_DOWN(((addrs) + (size) - 1), (size))
|
2020-12-08 08:15:54 +00:00
|
|
|
|
2016-11-02 00:23:40 +00:00
|
|
|
struct f2fs_configuration {
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t reserved_segments;
|
|
|
|
uint32_t new_reserved_segments;
|
2017-06-16 18:32:58 +00:00
|
|
|
int sparse_mode;
|
2016-11-02 00:23:40 +00:00
|
|
|
int zoned_mode;
|
|
|
|
int zoned_model;
|
|
|
|
size_t zone_blocks;
|
2015-09-25 16:31:04 +00:00
|
|
|
double overprovision;
|
2015-12-09 00:05:09 +00:00
|
|
|
double new_overprovision;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t cur_seg[6];
|
|
|
|
uint32_t segs_per_sec;
|
|
|
|
uint32_t secs_per_zone;
|
|
|
|
uint32_t segs_per_zone;
|
|
|
|
uint32_t start_sector;
|
|
|
|
uint32_t total_segments;
|
|
|
|
uint32_t sector_size;
|
|
|
|
uint64_t device_size;
|
|
|
|
uint64_t total_sectors;
|
|
|
|
uint64_t wanted_total_sectors;
|
|
|
|
uint64_t wanted_sector_size;
|
|
|
|
uint64_t target_sectors;
|
|
|
|
uint64_t max_size;
|
|
|
|
uint32_t sectors_per_blk;
|
|
|
|
uint32_t blks_per_seg;
|
2014-11-07 04:44:57 +00:00
|
|
|
__u8 init_version[VERSION_LEN + 1];
|
2014-11-07 03:34:40 +00:00
|
|
|
__u8 sb_version[VERSION_LEN + 1];
|
|
|
|
__u8 version[VERSION_LEN + 1];
|
2013-04-02 22:15:20 +00:00
|
|
|
char *vol_label;
|
2020-07-09 11:21:11 +00:00
|
|
|
char *vol_uuid;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint16_t s_encoding;
|
|
|
|
uint16_t s_encoding_flags;
|
2013-01-25 04:39:34 +00:00
|
|
|
int heap;
|
2016-11-02 00:23:40 +00:00
|
|
|
int32_t kd;
|
2014-08-19 21:05:21 +00:00
|
|
|
int32_t dump_fd;
|
2016-11-02 00:23:40 +00:00
|
|
|
struct device_info devices[MAX_DEVICES];
|
|
|
|
int ndevs;
|
2018-03-01 02:48:47 +00:00
|
|
|
char *extension_list[2];
|
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>
2016-09-28 17:28:03 +00:00
|
|
|
const char *rootdev_name;
|
2013-01-25 08:20:16 +00:00
|
|
|
int dbg_lv;
|
2017-03-15 13:28:19 +00:00
|
|
|
int show_dentry;
|
2013-04-03 06:26:48 +00:00
|
|
|
int trim;
|
2017-04-28 09:16:31 +00:00
|
|
|
int trimmed;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
int func;
|
|
|
|
void *private;
|
2017-11-02 03:56:09 +00:00
|
|
|
int dry_run;
|
2019-10-14 17:10:31 +00:00
|
|
|
int no_kernel_check;
|
2014-08-27 00:26:01 +00:00
|
|
|
int fix_on;
|
2018-11-26 10:53:37 +00:00
|
|
|
int force;
|
2018-04-19 18:33:14 +00:00
|
|
|
int defset;
|
2014-08-27 00:26:01 +00:00
|
|
|
int bug_on;
|
2018-11-28 23:11:28 +00:00
|
|
|
int bug_nat_bits;
|
2021-10-27 23:46:10 +00:00
|
|
|
bool quota_fixed;
|
2018-10-01 01:16:38 +00:00
|
|
|
int alloc_failed;
|
2014-09-03 01:07:35 +00:00
|
|
|
int auto_fix;
|
2021-05-23 21:23:06 +00:00
|
|
|
int layout;
|
2021-06-13 03:42:47 +00:00
|
|
|
int show_file_map;
|
|
|
|
u64 show_file_map_max_offset;
|
2018-09-19 01:28:37 +00:00
|
|
|
int quota_fix;
|
2016-03-14 06:16:53 +00:00
|
|
|
int preen_mode;
|
2015-11-22 02:53:07 +00:00
|
|
|
int ro;
|
2017-11-08 19:20:47 +00:00
|
|
|
int preserve_limits; /* preserve quota limits */
|
2018-01-25 11:45:13 +00:00
|
|
|
int large_nat_bitmap;
|
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>
2019-05-14 09:33:40 +00:00
|
|
|
int fix_chksum; /* fix old cp.chksum position */
|
2015-04-22 03:03:40 +00:00
|
|
|
__le32 feature; /* defined features */
|
2022-01-04 19:56:16 +00:00
|
|
|
unsigned int quota_bits; /* quota bits */
|
2020-08-18 11:18:50 +00:00
|
|
|
time_t fixed_time;
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2018-02-23 03:17:56 +00:00
|
|
|
/* mkfs parameters */
|
2020-08-18 11:18:07 +00:00
|
|
|
int fake_seed;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t next_free_nid;
|
|
|
|
uint32_t quota_inum;
|
|
|
|
uint32_t quota_dnum;
|
|
|
|
uint32_t lpf_inum;
|
|
|
|
uint32_t lpf_dnum;
|
|
|
|
uint32_t lpf_ino;
|
|
|
|
uint32_t root_uid;
|
|
|
|
uint32_t root_gid;
|
2018-02-23 03:17:56 +00:00
|
|
|
|
2015-10-23 18:45:36 +00:00
|
|
|
/* defragmentation parameters */
|
|
|
|
int defrag_shrink;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint64_t defrag_start;
|
|
|
|
uint64_t defrag_len;
|
|
|
|
uint64_t defrag_target;
|
2015-12-10 00:18:44 +00:00
|
|
|
|
|
|
|
/* sload parameters */
|
|
|
|
char *from_dir;
|
|
|
|
char *mount_point;
|
2017-11-30 01:21:12 +00:00
|
|
|
char *target_out_dir;
|
|
|
|
char *fs_config_file;
|
|
|
|
#ifdef HAVE_LIBSELINUX
|
|
|
|
struct selinux_opt seopt_file[8];
|
|
|
|
int nr_opt;
|
|
|
|
#endif
|
2021-03-15 22:08:53 +00:00
|
|
|
int preserve_perms;
|
2017-07-26 15:01:35 +00:00
|
|
|
|
2018-05-09 02:48:33 +00:00
|
|
|
/* resize parameters */
|
|
|
|
int safe_resize;
|
|
|
|
|
2017-07-26 15:01:35 +00:00
|
|
|
/* precomputed fs UUID checksum for seeding other checksums */
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t chksum_seed;
|
libf2fs_io: Add user-space cache
Implemented cache options in F2FS configuration 'c' (i.e. user
options):
* use c.cache_config.num_cache_entry to set the number of
cache entries (in block), minimum 1024, or 0 to disable cache.
* use c.cache_config.max_hash_collision to set maximum hash
collision (max 16).
* use c.cavhe_config.dbg_en to enable printing of debug messages.
Cache properties:
* Per block save based (block size = f2fs block size = 4K Bytes)
* Device block indices are used to hash (simple modular hash
function) to cache indices.
* A hash collision (when a block is hashed to an already occupied
cache block) will trigger offset-based relocation to max 16
other places, at first empty slot found policy.
* A hash collision with all 17 possible relocating places occupied
will evict the oldest used one (replaced by the new read block).
A global 'use' tick is kept ticking-up per block read for this
purpose.
* On write cache hit, it will update the corresponding cached
block.
* On write cache miss, the data won't be cached.
* Write-through policy only: never delayed write.
* On read cache hit, it returns the cached block.
* On read cache miss, it issues an I/O read to the kernel, and
then caches and returns the block.
* Currently read ahead is not implemented. Yet, the read ahead
logic is kept as before, i.e. using kernel's read ahead
mechanism.
Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: Fix one bug in dcache_update_rw()]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-11-18 10:13:07 +00:00
|
|
|
|
|
|
|
/* cache parameters */
|
|
|
|
dev_cache_config_t cache_config;
|
2020-12-08 08:15:54 +00:00
|
|
|
|
|
|
|
/* compression support for sload.f2fs */
|
|
|
|
compress_config_t compress;
|
2017-06-05 20:44:50 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2014-01-09 21:56:07 +00:00
|
|
|
#ifdef CONFIG_64BIT
|
2012-10-26 12:56:34 +00:00
|
|
|
#define BITS_PER_LONG 64
|
|
|
|
#else
|
|
|
|
#define BITS_PER_LONG 32
|
|
|
|
#endif
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
#define BIT_MASK(nr) (1 << (nr % BITS_PER_LONG))
|
|
|
|
#define BIT_WORD(nr) (nr / BITS_PER_LONG)
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2015-11-22 03:44:29 +00:00
|
|
|
#define set_sb_le64(member, val) (sb->member = cpu_to_le64(val))
|
|
|
|
#define set_sb_le32(member, val) (sb->member = cpu_to_le32(val))
|
|
|
|
#define set_sb_le16(member, val) (sb->member = cpu_to_le16(val))
|
|
|
|
#define get_sb_le64(member) le64_to_cpu(sb->member)
|
|
|
|
#define get_sb_le32(member) le32_to_cpu(sb->member)
|
|
|
|
#define get_sb_le16(member) le16_to_cpu(sb->member)
|
2015-12-09 00:05:09 +00:00
|
|
|
#define get_newsb_le64(member) le64_to_cpu(new_sb->member)
|
|
|
|
#define get_newsb_le32(member) le32_to_cpu(new_sb->member)
|
|
|
|
#define get_newsb_le16(member) le16_to_cpu(new_sb->member)
|
2015-11-22 03:44:29 +00:00
|
|
|
|
|
|
|
#define set_sb(member, val) \
|
|
|
|
do { \
|
|
|
|
typeof(sb->member) t; \
|
|
|
|
switch (sizeof(t)) { \
|
|
|
|
case 8: set_sb_le64(member, val); break; \
|
|
|
|
case 4: set_sb_le32(member, val); break; \
|
|
|
|
case 2: set_sb_le16(member, val); break; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define get_sb(member) \
|
|
|
|
({ \
|
|
|
|
typeof(sb->member) t; \
|
|
|
|
switch (sizeof(t)) { \
|
|
|
|
case 8: t = get_sb_le64(member); break; \
|
|
|
|
case 4: t = get_sb_le32(member); break; \
|
|
|
|
case 2: t = get_sb_le16(member); break; \
|
|
|
|
} \
|
|
|
|
t; \
|
|
|
|
})
|
2015-12-09 00:05:09 +00:00
|
|
|
#define get_newsb(member) \
|
|
|
|
({ \
|
|
|
|
typeof(new_sb->member) t; \
|
|
|
|
switch (sizeof(t)) { \
|
|
|
|
case 8: t = get_newsb_le64(member); break; \
|
|
|
|
case 4: t = get_newsb_le32(member); break; \
|
|
|
|
case 2: t = get_newsb_le16(member); break; \
|
|
|
|
} \
|
|
|
|
t; \
|
|
|
|
})
|
2015-11-22 03:44:29 +00:00
|
|
|
|
|
|
|
#define set_cp_le64(member, val) (cp->member = cpu_to_le64(val))
|
|
|
|
#define set_cp_le32(member, val) (cp->member = cpu_to_le32(val))
|
|
|
|
#define set_cp_le16(member, val) (cp->member = cpu_to_le16(val))
|
|
|
|
#define get_cp_le64(member) le64_to_cpu(cp->member)
|
|
|
|
#define get_cp_le32(member) le32_to_cpu(cp->member)
|
|
|
|
#define get_cp_le16(member) le16_to_cpu(cp->member)
|
|
|
|
|
|
|
|
#define set_cp(member, val) \
|
|
|
|
do { \
|
|
|
|
typeof(cp->member) t; \
|
|
|
|
switch (sizeof(t)) { \
|
|
|
|
case 8: set_cp_le64(member, val); break; \
|
|
|
|
case 4: set_cp_le32(member, val); break; \
|
|
|
|
case 2: set_cp_le16(member, val); break; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define get_cp(member) \
|
|
|
|
({ \
|
|
|
|
typeof(cp->member) t; \
|
|
|
|
switch (sizeof(t)) { \
|
|
|
|
case 8: t = get_cp_le64(member); break; \
|
|
|
|
case 4: t = get_cp_le32(member); break; \
|
|
|
|
case 2: t = get_cp_le16(member); break; \
|
|
|
|
} \
|
|
|
|
t; \
|
|
|
|
})
|
|
|
|
|
2015-12-09 19:44:31 +00:00
|
|
|
/*
|
|
|
|
* Copied from include/linux/kernel.h
|
|
|
|
*/
|
|
|
|
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
|
|
|
|
#define round_down(x, y) ((x) & ~__round_mask(x, y))
|
2017-12-01 23:03:30 +00:00
|
|
|
|
2015-12-09 19:44:31 +00:00
|
|
|
#define min(x, y) ({ \
|
|
|
|
typeof(x) _min1 = (x); \
|
|
|
|
typeof(y) _min2 = (y); \
|
|
|
|
(void) (&_min1 == &_min2); \
|
|
|
|
_min1 < _min2 ? _min1 : _min2; })
|
|
|
|
|
|
|
|
#define max(x, y) ({ \
|
|
|
|
typeof(x) _max1 = (x); \
|
|
|
|
typeof(y) _max2 = (y); \
|
|
|
|
(void) (&_max1 == &_max2); \
|
|
|
|
_max1 > _max2 ? _max1 : _max2; })
|
|
|
|
|
2020-07-21 16:38:11 +00:00
|
|
|
#define round_up(x, y) (((x) + (y) - 1) / (y))
|
2012-10-26 12:56:34 +00:00
|
|
|
/*
|
2013-01-25 04:39:34 +00:00
|
|
|
* Copied from fs/f2fs/f2fs.h
|
2012-10-26 12:56:34 +00:00
|
|
|
*/
|
2013-01-25 04:39:34 +00:00
|
|
|
#define NR_CURSEG_DATA_TYPE (3)
|
|
|
|
#define NR_CURSEG_NODE_TYPE (3)
|
|
|
|
#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CURSEG_HOT_DATA = 0, /* directory entry blocks */
|
|
|
|
CURSEG_WARM_DATA, /* data blocks */
|
|
|
|
CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
|
|
|
|
CURSEG_HOT_NODE, /* direct node blocks of directory files */
|
|
|
|
CURSEG_WARM_NODE, /* direct node blocks of normal files */
|
|
|
|
CURSEG_COLD_NODE, /* indirect node blocks */
|
|
|
|
NO_CHECK_TYPE
|
|
|
|
};
|
|
|
|
|
2016-11-28 22:07:18 +00:00
|
|
|
#define F2FS_MIN_SEGMENTS 9 /* SB + 2 (CP + SIT + NAT) + SSA + MAIN */
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
/*
|
|
|
|
* Copied from fs/f2fs/segment.h
|
|
|
|
*/
|
|
|
|
#define GET_SUM_TYPE(footer) ((footer)->entry_type)
|
|
|
|
#define SET_SUM_TYPE(footer, type) ((footer)->entry_type = type)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copied from include/linux/f2fs_sb.h
|
|
|
|
*/
|
|
|
|
#define F2FS_SUPER_OFFSET 1024 /* byte-size offset */
|
2015-02-05 09:38:09 +00:00
|
|
|
#define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */
|
|
|
|
#define F2FS_MAX_LOG_SECTOR_SIZE 12 /* 12 bits for 4096 bytes */
|
2013-01-25 04:39:34 +00:00
|
|
|
#define F2FS_BLKSIZE 4096 /* support only 4KB block */
|
|
|
|
#define F2FS_MAX_EXTENSION 64 /* # of extension entries */
|
2019-07-31 13:00:45 +00:00
|
|
|
#define F2FS_EXTENSION_LEN 8 /* max size of extension */
|
2014-07-10 06:26:04 +00:00
|
|
|
#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE)
|
2013-01-25 04:39:34 +00:00
|
|
|
|
|
|
|
#define NULL_ADDR 0x0U
|
|
|
|
#define NEW_ADDR -1U
|
2019-03-25 13:19:35 +00:00
|
|
|
#define COMPRESS_ADDR -2U
|
2013-01-25 04:39:34 +00:00
|
|
|
|
|
|
|
#define F2FS_ROOT_INO(sbi) (sbi->root_ino_num)
|
|
|
|
#define F2FS_NODE_INO(sbi) (sbi->node_ino_num)
|
|
|
|
#define F2FS_META_INO(sbi) (sbi->meta_ino_num)
|
|
|
|
|
2017-10-30 23:10:27 +00:00
|
|
|
#define F2FS_MAX_QUOTAS 3
|
|
|
|
#define QUOTA_DATA(i) (2)
|
|
|
|
#define QUOTA_INO(sb,t) (le32_to_cpu((sb)->qf_ino[t]))
|
|
|
|
|
|
|
|
#define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
#define F2FS_ENC_UTF8_12_1 1
|
|
|
|
#define F2FS_ENC_STRICT_MODE_FL (1 << 0)
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
/* This flag is used by node and meta inodes, and by recovery */
|
|
|
|
#define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO)
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
/*
|
|
|
|
* For further optimization on multi-head logs, on-disk layout supports maximum
|
|
|
|
* 16 logs by default. The number, 16, is expected to cover all the cases
|
|
|
|
* enoughly. The implementaion currently uses no more than 6 logs.
|
|
|
|
* Half the logs are used for nodes, and the other half are used for data.
|
|
|
|
*/
|
|
|
|
#define MAX_ACTIVE_LOGS 16
|
|
|
|
#define MAX_ACTIVE_NODE_LOGS 8
|
|
|
|
#define MAX_ACTIVE_DATA_LOGS 8
|
|
|
|
|
2017-07-21 20:49:28 +00:00
|
|
|
#define F2FS_FEATURE_ENCRYPT 0x0001
|
|
|
|
#define F2FS_FEATURE_BLKZONED 0x0002
|
|
|
|
#define F2FS_FEATURE_ATOMIC_WRITE 0x0004
|
2017-07-26 14:49:57 +00:00
|
|
|
#define F2FS_FEATURE_EXTRA_ATTR 0x0008
|
2017-07-26 14:54:18 +00:00
|
|
|
#define F2FS_FEATURE_PRJQUOTA 0x0010
|
2017-07-26 15:01:35 +00:00
|
|
|
#define F2FS_FEATURE_INODE_CHKSUM 0x0020
|
2017-09-04 10:58:29 +00:00
|
|
|
#define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040
|
2017-10-30 23:10:27 +00:00
|
|
|
#define F2FS_FEATURE_QUOTA_INO 0x0080
|
2018-01-25 06:58:45 +00:00
|
|
|
#define F2FS_FEATURE_INODE_CRTIME 0x0100
|
2018-03-06 03:39:39 +00:00
|
|
|
#define F2FS_FEATURE_LOST_FOUND 0x0200
|
2018-01-11 03:33:47 +00:00
|
|
|
#define F2FS_FEATURE_VERITY 0x0400 /* reserved */
|
2018-09-28 12:25:59 +00:00
|
|
|
#define F2FS_FEATURE_SB_CHKSUM 0x0800
|
2019-07-11 20:45:41 +00:00
|
|
|
#define F2FS_FEATURE_CASEFOLD 0x1000
|
2020-06-30 21:03:51 +00:00
|
|
|
#define F2FS_FEATURE_COMPRESSION 0x2000
|
|
|
|
#define F2FS_FEATURE_RO 0x4000
|
2015-04-22 03:03:40 +00:00
|
|
|
|
2015-12-14 22:29:41 +00:00
|
|
|
#define MAX_VOLUME_NAME 512
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
/*
|
|
|
|
* For superblock
|
|
|
|
*/
|
2016-11-02 00:23:40 +00:00
|
|
|
struct f2fs_device {
|
|
|
|
__u8 path[MAX_PATH_LEN];
|
|
|
|
__le32 total_segments;
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2016-11-02 00:23:40 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_device) == 68, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_super_block {
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 magic; /* Magic Number */
|
|
|
|
__le16 major_ver; /* Major Version */
|
|
|
|
__le16 minor_ver; /* Minor Version */
|
|
|
|
__le32 log_sectorsize; /* log2 sector size in bytes */
|
|
|
|
__le32 log_sectors_per_block; /* log2 # of sectors per block */
|
|
|
|
__le32 log_blocksize; /* log2 block size in bytes */
|
|
|
|
__le32 log_blocks_per_seg; /* log2 # of blocks per segment */
|
|
|
|
__le32 segs_per_sec; /* # of segments per section */
|
|
|
|
__le32 secs_per_zone; /* # of sections per zone */
|
|
|
|
__le32 checksum_offset; /* checksum offset inside super block */
|
2022-04-21 22:18:18 +00:00
|
|
|
__le64 block_count __attribute__((packed));
|
|
|
|
/* total # of user blocks */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 section_count; /* total # of sections */
|
|
|
|
__le32 segment_count; /* total # of segments */
|
|
|
|
__le32 segment_count_ckpt; /* # of segments for checkpoint */
|
|
|
|
__le32 segment_count_sit; /* # of segments for SIT */
|
|
|
|
__le32 segment_count_nat; /* # of segments for NAT */
|
|
|
|
__le32 segment_count_ssa; /* # of segments for SSA */
|
|
|
|
__le32 segment_count_main; /* # of segments for main area */
|
|
|
|
__le32 segment0_blkaddr; /* start block address of segment 0 */
|
|
|
|
__le32 cp_blkaddr; /* start block address of checkpoint */
|
|
|
|
__le32 sit_blkaddr; /* start block address of SIT */
|
|
|
|
__le32 nat_blkaddr; /* start block address of NAT */
|
|
|
|
__le32 ssa_blkaddr; /* start block address of SSA */
|
|
|
|
__le32 main_blkaddr; /* start block address of main area */
|
|
|
|
__le32 root_ino; /* root inode number */
|
|
|
|
__le32 node_ino; /* node inode number */
|
|
|
|
__le32 meta_ino; /* meta inode number */
|
|
|
|
__u8 uuid[16]; /* 128-bit uuid for volume */
|
2015-12-14 22:29:41 +00:00
|
|
|
__le16 volume_name[MAX_VOLUME_NAME]; /* volume name */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 extension_count; /* # of extensions below */
|
|
|
|
__u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */
|
2014-05-12 13:03:46 +00:00
|
|
|
__le32 cp_payload;
|
2014-11-07 03:34:40 +00:00
|
|
|
__u8 version[VERSION_LEN]; /* the kernel version */
|
2014-11-07 04:44:57 +00:00
|
|
|
__u8 init_version[VERSION_LEN]; /* the initial kernel version */
|
2015-04-22 03:03:40 +00:00
|
|
|
__le32 feature; /* defined features */
|
|
|
|
__u8 encryption_level; /* versioning level for encryption */
|
|
|
|
__u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
|
2022-04-21 22:18:18 +00:00
|
|
|
struct f2fs_device devs[MAX_DEVICES] __attribute__((packed)); /* device list */
|
|
|
|
__le32 qf_ino[F2FS_MAX_QUOTAS] __attribute__((packed)); /* quota inode numbers */
|
2018-03-01 02:48:47 +00:00
|
|
|
__u8 hot_ext_count; /* # of hot file extension */
|
2019-07-11 20:45:41 +00:00
|
|
|
__le16 s_encoding; /* Filename charset encoding */
|
|
|
|
__le16 s_encoding_flags; /* Filename charset encoding flags */
|
|
|
|
__u8 reserved[306]; /* valid reserved region */
|
2018-09-28 12:25:59 +00:00
|
|
|
__le32 crc; /* checksum of superblock */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_super_block) == 3072, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/*
|
|
|
|
* For checkpoint
|
|
|
|
*/
|
2020-03-24 09:12:50 +00:00
|
|
|
#define CP_RESIZEFS_FLAG 0x00004000
|
2018-09-20 23:16:07 +00:00
|
|
|
#define CP_DISABLED_FLAG 0x00001000
|
2018-09-19 01:28:37 +00:00
|
|
|
#define CP_QUOTA_NEED_FSCK_FLAG 0x00000800
|
2018-01-25 11:45:13 +00:00
|
|
|
#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400
|
2018-01-20 21:51:05 +00:00
|
|
|
#define CP_NOCRC_RECOVERY_FLAG 0x00000200
|
2017-04-28 09:16:31 +00:00
|
|
|
#define CP_TRIMMED_FLAG 0x00000100
|
2017-02-09 02:55:43 +00:00
|
|
|
#define CP_NAT_BITS_FLAG 0x00000080
|
2017-02-09 18:32:19 +00:00
|
|
|
#define CP_CRC_RECOVERY_FLAG 0x00000040
|
2015-01-15 00:18:15 +00:00
|
|
|
#define CP_FASTBOOT_FLAG 0x00000020
|
2014-09-03 01:07:35 +00:00
|
|
|
#define CP_FSCK_FLAG 0x00000010
|
2012-10-29 22:35:21 +00:00
|
|
|
#define CP_ERROR_FLAG 0x00000008
|
|
|
|
#define CP_COMPACT_SUM_FLAG 0x00000004
|
|
|
|
#define CP_ORPHAN_PRESENT_FLAG 0x00000002
|
|
|
|
#define CP_UMOUNT_FLAG 0x00000001
|
|
|
|
|
2019-06-13 08:10:51 +00:00
|
|
|
#define F2FS_CP_PACKS 2 /* # of checkpoint packs */
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_checkpoint {
|
2012-10-31 09:29:45 +00:00
|
|
|
__le64 checkpoint_ver; /* checkpoint block version number */
|
2012-10-26 12:56:34 +00:00
|
|
|
__le64 user_block_count; /* # of user blocks */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le64 valid_block_count; /* # of valid blocks in main area */
|
2012-10-26 12:56:34 +00:00
|
|
|
__le32 rsvd_segment_count; /* # of reserved segments for gc */
|
|
|
|
__le32 overprov_segment_count; /* # of overprovision segments */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 free_segment_count; /* # of free segments in main area */
|
2012-10-26 12:56:34 +00:00
|
|
|
|
|
|
|
/* information of current node segments */
|
|
|
|
__le32 cur_node_segno[MAX_ACTIVE_NODE_LOGS];
|
|
|
|
__le16 cur_node_blkoff[MAX_ACTIVE_NODE_LOGS];
|
|
|
|
/* information of current data segments */
|
|
|
|
__le32 cur_data_segno[MAX_ACTIVE_DATA_LOGS];
|
|
|
|
__le16 cur_data_blkoff[MAX_ACTIVE_DATA_LOGS];
|
|
|
|
__le32 ckpt_flags; /* Flags : umount and journal_present */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 cp_pack_total_block_count; /* total # of one cp pack */
|
2012-10-26 12:56:34 +00:00
|
|
|
__le32 cp_pack_start_sum; /* start block number of data summary */
|
|
|
|
__le32 valid_node_count; /* Total number of valid nodes */
|
|
|
|
__le32 valid_inode_count; /* Total number of valid inodes */
|
|
|
|
__le32 next_free_nid; /* Next free node number */
|
|
|
|
__le32 sit_ver_bitmap_bytesize; /* Default value 64 */
|
|
|
|
__le32 nat_ver_bitmap_bytesize; /* Default value 256 */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 checksum_offset; /* checksum offset inside cp block */
|
|
|
|
__le64 elapsed_time; /* mounted time */
|
2012-10-26 12:56:34 +00:00
|
|
|
/* allocation type of current segment */
|
|
|
|
unsigned char alloc_type[MAX_ACTIVE_LOGS];
|
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
/* SIT and NAT version bitmap */
|
2022-04-21 22:18:14 +00:00
|
|
|
unsigned char sit_nat_version_bitmap[];
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_checkpoint) == 192, "");
|
|
|
|
|
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>
2019-05-14 09:33:40 +00:00
|
|
|
#define CP_BITMAP_OFFSET \
|
|
|
|
(offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap))
|
|
|
|
#define CP_MIN_CHKSUM_OFFSET CP_BITMAP_OFFSET
|
|
|
|
|
|
|
|
#define MIN_NAT_BITMAP_SIZE 64
|
2018-01-25 11:45:13 +00:00
|
|
|
#define MAX_SIT_BITMAP_SIZE_IN_CKPT \
|
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>
2019-05-14 09:33:40 +00:00
|
|
|
(CP_CHKSUM_OFFSET - CP_BITMAP_OFFSET - MIN_NAT_BITMAP_SIZE)
|
2018-01-25 11:45:13 +00:00
|
|
|
#define MAX_BITMAP_SIZE_IN_CKPT \
|
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>
2019-05-14 09:33:40 +00:00
|
|
|
(CP_CHKSUM_OFFSET - CP_BITMAP_OFFSET)
|
2017-12-22 04:20:58 +00:00
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
/*
|
|
|
|
* For orphan inode management
|
|
|
|
*/
|
|
|
|
#define F2FS_ORPHANS_PER_BLOCK 1020
|
|
|
|
|
|
|
|
struct f2fs_orphan_block {
|
|
|
|
__le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */
|
|
|
|
__le32 reserved; /* reserved */
|
|
|
|
__le16 blk_addr; /* block index in current CP */
|
|
|
|
__le16 blk_count; /* Number of orphan inode blocks in CP */
|
|
|
|
__le32 entry_count; /* Total number of orphan nodes in current CP */
|
|
|
|
__le32 check_sum; /* CRC32 for orphan inode block */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2013-01-25 04:39:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_orphan_block) == 4096, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/*
|
|
|
|
* For NODE structure
|
|
|
|
*/
|
|
|
|
struct f2fs_extent {
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 fofs; /* start file offset of the extent */
|
|
|
|
__le32 blk_addr; /* start block address of the extent */
|
|
|
|
__le32 len; /* lengh of the extent */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_extent) == 12, "");
|
|
|
|
|
2013-03-03 05:00:50 +00:00
|
|
|
#define F2FS_NAME_LEN 255
|
2019-04-24 17:59:09 +00:00
|
|
|
|
|
|
|
/* max output length of pretty_print_filename() including null terminator */
|
|
|
|
#define F2FS_PRINT_NAMELEN (4 * ((F2FS_NAME_LEN + 2) / 3) + 1)
|
|
|
|
|
2017-09-04 10:58:29 +00:00
|
|
|
/* 200 bytes for inline xattrs by default */
|
|
|
|
#define DEFAULT_INLINE_XATTR_ADDRS 50
|
2013-08-20 09:05:56 +00:00
|
|
|
#define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode */
|
2017-07-26 14:49:57 +00:00
|
|
|
#define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \
|
|
|
|
__get_extra_isize(inode))
|
2015-12-10 00:18:44 +00:00
|
|
|
#define ADDRS_PER_INODE(i) addrs_per_inode(i)
|
2019-03-25 13:19:35 +00:00
|
|
|
#define DEF_ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */
|
|
|
|
#define ADDRS_PER_BLOCK(i) addrs_per_block(i)
|
2012-10-26 12:56:34 +00:00
|
|
|
#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */
|
|
|
|
|
2013-08-20 09:05:56 +00:00
|
|
|
#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1)
|
|
|
|
#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2)
|
|
|
|
#define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3)
|
|
|
|
#define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4)
|
|
|
|
#define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5)
|
|
|
|
|
|
|
|
#define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */
|
|
|
|
#define F2FS_INLINE_DATA 0x02 /* file inline data flag */
|
2014-10-14 22:15:40 +00:00
|
|
|
#define F2FS_INLINE_DENTRY 0x04 /* file inline dentry flag */
|
2014-10-31 18:06:45 +00:00
|
|
|
#define F2FS_DATA_EXIST 0x08 /* file inline data exist flag */
|
2015-03-30 20:09:16 +00:00
|
|
|
#define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */
|
2017-07-26 14:49:57 +00:00
|
|
|
#define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */
|
2021-05-25 19:00:46 +00:00
|
|
|
#define F2FS_PIN_FILE 0x40 /* file should not be gced */
|
|
|
|
#define F2FS_COMPRESS_RELEASED 0x80 /* file released compressed blocks */
|
2014-10-14 22:15:40 +00:00
|
|
|
|
2019-04-28 09:17:37 +00:00
|
|
|
#define F2FS_EXTRA_ISIZE_OFFSET \
|
|
|
|
offsetof(struct f2fs_inode, i_extra_isize)
|
2017-07-26 14:49:57 +00:00
|
|
|
#define F2FS_TOTAL_EXTRA_ATTR_SIZE \
|
2019-04-28 09:17:37 +00:00
|
|
|
(offsetof(struct f2fs_inode, i_extra_end) - F2FS_EXTRA_ISIZE_OFFSET)
|
2017-07-26 14:49:57 +00:00
|
|
|
|
2017-07-26 14:54:18 +00:00
|
|
|
#define F2FS_DEF_PROJID 0 /* default project ID */
|
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
#define MAX_INLINE_DATA(node) (sizeof(__le32) * \
|
2017-09-04 10:58:29 +00:00
|
|
|
(DEF_ADDRS_PER_INODE - \
|
|
|
|
get_inline_xattr_addrs(&node->i) - \
|
2017-07-26 14:49:57 +00:00
|
|
|
get_extra_isize(node) - \
|
|
|
|
DEF_INLINE_RESERVED_SIZE))
|
|
|
|
#define DEF_MAX_INLINE_DATA (sizeof(__le32) * \
|
2017-09-04 10:58:29 +00:00
|
|
|
(DEF_ADDRS_PER_INODE - \
|
|
|
|
DEFAULT_INLINE_XATTR_ADDRS - \
|
2017-07-26 14:49:57 +00:00
|
|
|
F2FS_TOTAL_EXTRA_ATTR_SIZE - \
|
|
|
|
DEF_INLINE_RESERVED_SIZE))
|
2013-10-25 16:12:40 +00:00
|
|
|
#define INLINE_DATA_OFFSET (PAGE_CACHE_SIZE - sizeof(struct node_footer) \
|
2017-07-26 14:49:57 +00:00
|
|
|
- sizeof(__le32)*(DEF_ADDRS_PER_INODE + 5 - \
|
|
|
|
DEF_INLINE_RESERVED_SIZE))
|
2013-08-20 09:05:56 +00:00
|
|
|
|
2014-02-27 11:12:35 +00:00
|
|
|
#define DEF_DIR_LEVEL 0
|
|
|
|
|
2015-04-28 21:27:18 +00:00
|
|
|
/*
|
|
|
|
* i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
|
|
|
|
*/
|
2018-01-11 03:33:47 +00:00
|
|
|
#define FADVISE_COLD_BIT 0x01
|
|
|
|
#define FADVISE_LOST_PINO_BIT 0x02
|
|
|
|
#define FADVISE_ENCRYPT_BIT 0x04
|
|
|
|
#define FADVISE_ENC_NAME_BIT 0x08
|
|
|
|
#define FADVISE_KEEP_SIZE_BIT 0x10
|
|
|
|
#define FADVISE_HOT_BIT 0x20
|
|
|
|
#define FADVISE_VERITY_BIT 0x40 /* reserved */
|
2015-04-28 21:27:18 +00:00
|
|
|
|
2016-10-24 02:16:03 +00:00
|
|
|
#define file_is_encrypt(fi) ((fi)->i_advise & FADVISE_ENCRYPT_BIT)
|
2017-03-17 13:56:19 +00:00
|
|
|
#define file_enc_name(fi) ((fi)->i_advise & FADVISE_ENC_NAME_BIT)
|
2015-04-28 21:27:18 +00:00
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
#define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */
|
|
|
|
#define IS_CASEFOLDED(dir) ((dir)->i_flags & F2FS_CASEFOLD_FL)
|
|
|
|
|
2021-05-12 12:50:48 +00:00
|
|
|
/*
|
|
|
|
* fsck i_compr_blocks counting helper
|
|
|
|
*/
|
|
|
|
struct f2fs_compr_blk_cnt {
|
|
|
|
/* counting i_compr_blocks, init 0 */
|
|
|
|
u32 cnt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* previous seen compression header (COMPR_ADDR) page offsets,
|
|
|
|
* use CHEADER_PGOFS_NONE for none
|
|
|
|
*/
|
|
|
|
u32 cheader_pgofs;
|
|
|
|
};
|
|
|
|
#define CHEADER_PGOFS_NONE ((u32)-(1 << MAX_COMPRESS_LOG_SIZE))
|
|
|
|
|
2019-03-25 13:19:35 +00:00
|
|
|
/*
|
|
|
|
* inode flags
|
|
|
|
*/
|
|
|
|
#define F2FS_COMPR_FL 0x00000004 /* Compress file */
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_inode {
|
2012-10-31 09:29:45 +00:00
|
|
|
__le16 i_mode; /* file mode */
|
|
|
|
__u8 i_advise; /* file hints */
|
2013-08-20 09:05:56 +00:00
|
|
|
__u8 i_inline; /* file inline flags */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 i_uid; /* user ID */
|
|
|
|
__le32 i_gid; /* group ID */
|
|
|
|
__le32 i_links; /* links count */
|
|
|
|
__le64 i_size; /* file size in bytes */
|
|
|
|
__le64 i_blocks; /* file size in blocks */
|
|
|
|
__le64 i_atime; /* access time */
|
|
|
|
__le64 i_ctime; /* change time */
|
|
|
|
__le64 i_mtime; /* modification time */
|
|
|
|
__le32 i_atime_nsec; /* access time in nano scale */
|
|
|
|
__le32 i_ctime_nsec; /* change time in nano scale */
|
|
|
|
__le32 i_mtime_nsec; /* modification time in nano scale */
|
|
|
|
__le32 i_generation; /* file version (for NFS) */
|
2018-07-28 10:41:35 +00:00
|
|
|
union {
|
|
|
|
__le32 i_current_depth; /* only for directory depth */
|
|
|
|
__le16 i_gc_failures; /*
|
|
|
|
* # of gc failures on pinned file.
|
|
|
|
* only for regular files.
|
|
|
|
*/
|
|
|
|
};
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 i_xattr_nid; /* nid to save xattr */
|
2012-10-26 12:56:34 +00:00
|
|
|
__le32 i_flags; /* file attributes */
|
|
|
|
__le32 i_pino; /* parent inode number */
|
|
|
|
__le32 i_namelen; /* file name length */
|
2013-03-03 05:00:50 +00:00
|
|
|
__u8 i_name[F2FS_NAME_LEN]; /* file name for SPOR */
|
2014-02-27 11:12:35 +00:00
|
|
|
__u8 i_dir_level; /* dentry_level for large dir */
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:18 +00:00
|
|
|
struct f2fs_extent i_ext __attribute__((packed)); /* caching a largest extent */
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
__le16 i_extra_isize; /* extra inode attribute size */
|
2017-09-04 10:58:29 +00:00
|
|
|
__le16 i_inline_xattr_size; /* inline xattr size, unit: 4 bytes */
|
2017-07-26 14:54:18 +00:00
|
|
|
__le32 i_projid; /* project id */
|
2017-07-26 15:01:35 +00:00
|
|
|
__le32 i_inode_checksum;/* inode meta checksum */
|
2018-01-25 06:58:45 +00:00
|
|
|
__le64 i_crtime; /* creation time */
|
|
|
|
__le32 i_crtime_nsec; /* creation time in nano scale */
|
2019-03-25 13:19:35 +00:00
|
|
|
__le64 i_compr_blocks; /* # of compressed blocks */
|
|
|
|
__u8 i_compress_algrithm; /* compress algrithm */
|
|
|
|
__u8 i_log_cluster_size; /* log of cluster size */
|
|
|
|
__le16 i_padding; /* padding */
|
2017-07-26 14:49:57 +00:00
|
|
|
__le32 i_extra_end[0]; /* for attribute size calculation */
|
2018-01-25 06:58:45 +00:00
|
|
|
} __attribute__((packed));
|
2017-07-26 14:49:57 +00:00
|
|
|
__le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */
|
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
__le32 i_nid[5]; /* direct(2), indirect(2),
|
|
|
|
double_indirect(1) node id */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:18 +00:00
|
|
|
static_assert(offsetof(struct f2fs_inode, i_extra_end) -
|
|
|
|
offsetof(struct f2fs_inode, i_extra_isize) == 36, "");
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_inode) == 4072, "");
|
2017-12-01 23:03:30 +00:00
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct direct_node {
|
2019-03-25 13:19:35 +00:00
|
|
|
__le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct direct_node) == 4072, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct indirect_node {
|
2013-01-25 04:39:34 +00:00
|
|
|
__le32 nid[NIDS_PER_BLOCK]; /* array of data block address */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct indirect_node) == 4072, "");
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
enum {
|
|
|
|
COLD_BIT_SHIFT = 0,
|
|
|
|
FSYNC_BIT_SHIFT,
|
|
|
|
DENT_BIT_SHIFT,
|
|
|
|
OFFSET_BIT_SHIFT
|
|
|
|
};
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
|
|
|
|
>> OFFSET_BIT_SHIFT)
|
2012-10-26 12:56:34 +00:00
|
|
|
struct node_footer {
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 nid; /* node id */
|
|
|
|
__le32 ino; /* inode nunmber */
|
2012-10-26 12:56:34 +00:00
|
|
|
__le32 flag; /* include cold/fsync/dentry marks and offset */
|
2022-04-21 22:18:18 +00:00
|
|
|
__le64 cp_ver __attribute__((packed)); /* checkpoint version */
|
2012-10-26 12:56:34 +00:00
|
|
|
__le32 next_blkaddr; /* next node page block address */
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct node_footer) == 24, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_node {
|
2012-10-31 09:29:45 +00:00
|
|
|
/* can be one of three types: inode, direct, and indirect types */
|
2012-10-26 12:56:34 +00:00
|
|
|
union {
|
|
|
|
struct f2fs_inode i;
|
|
|
|
struct direct_node dn;
|
|
|
|
struct indirect_node in;
|
|
|
|
};
|
|
|
|
struct node_footer footer;
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_node) == 4096, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/*
|
|
|
|
* For NAT entries
|
|
|
|
*/
|
2013-01-25 04:39:34 +00:00
|
|
|
#define NAT_ENTRY_PER_BLOCK (PAGE_CACHE_SIZE / sizeof(struct f2fs_nat_entry))
|
2015-12-10 00:18:44 +00:00
|
|
|
#define NAT_BLOCK_OFFSET(start_nid) (start_nid / NAT_ENTRY_PER_BLOCK)
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2018-01-25 11:45:13 +00:00
|
|
|
#define DEFAULT_NAT_ENTRY_RATIO 20
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_nat_entry {
|
2012-10-31 09:29:45 +00:00
|
|
|
__u8 version; /* latest version of cached nat entry */
|
|
|
|
__le32 ino; /* inode number */
|
|
|
|
__le32 block_addr; /* block address */
|
2012-10-26 12:56:34 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_nat_entry) == 9, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_nat_block {
|
|
|
|
struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK];
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_nat_block) == 4095, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/*
|
|
|
|
* For SIT entries
|
2012-10-31 09:29:45 +00:00
|
|
|
*
|
|
|
|
* Each segment is 2MB in size by default so that a bitmap for validity of
|
|
|
|
* there-in blocks should occupy 64 bytes, 512 bits.
|
|
|
|
* Not allow to change this.
|
2012-10-26 12:56:34 +00:00
|
|
|
*/
|
2013-01-25 04:39:34 +00:00
|
|
|
#define SIT_VBLOCK_MAP_SIZE 64
|
2012-10-26 12:56:34 +00:00
|
|
|
#define SIT_ENTRY_PER_BLOCK (PAGE_CACHE_SIZE / sizeof(struct f2fs_sit_entry))
|
|
|
|
|
2014-07-10 06:26:04 +00:00
|
|
|
/*
|
|
|
|
* F2FS uses 4 bytes to represent block address. As a result, supported size of
|
|
|
|
* disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments.
|
|
|
|
*/
|
2018-08-03 04:09:05 +00:00
|
|
|
#define F2FS_MIN_SEGMENT 9 /* SB + 2 (CP + SIT + NAT) + SSA + MAIN */
|
2014-07-10 06:26:04 +00:00
|
|
|
#define F2FS_MAX_SEGMENT ((16 * 1024 * 1024) / 2)
|
2017-11-14 18:53:32 +00:00
|
|
|
#define MAX_SIT_BITMAP_SIZE (SEG_ALIGN(SIZE_ALIGN(F2FS_MAX_SEGMENT, \
|
2016-02-23 13:43:42 +00:00
|
|
|
SIT_ENTRY_PER_BLOCK)) * \
|
2016-09-17 01:41:00 +00:00
|
|
|
c.blks_per_seg / 8)
|
2014-07-10 06:26:04 +00:00
|
|
|
|
2012-10-29 22:35:00 +00:00
|
|
|
/*
|
|
|
|
* Note that f2fs_sit_entry->vblocks has the following bit-field information.
|
|
|
|
* [15:10] : allocation type such as CURSEG_XXXX_TYPE
|
|
|
|
* [9:0] : valid block count
|
|
|
|
*/
|
2013-01-25 04:39:34 +00:00
|
|
|
#define SIT_VBLOCKS_SHIFT 10
|
|
|
|
#define SIT_VBLOCKS_MASK ((1 << SIT_VBLOCKS_SHIFT) - 1)
|
|
|
|
#define GET_SIT_VBLOCKS(raw_sit) \
|
|
|
|
(le16_to_cpu((raw_sit)->vblocks) & SIT_VBLOCKS_MASK)
|
|
|
|
#define GET_SIT_TYPE(raw_sit) \
|
|
|
|
((le16_to_cpu((raw_sit)->vblocks) & ~SIT_VBLOCKS_MASK) \
|
|
|
|
>> SIT_VBLOCKS_SHIFT)
|
2012-10-31 09:29:45 +00:00
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_sit_entry {
|
2012-10-31 09:29:45 +00:00
|
|
|
__le16 vblocks; /* reference above */
|
|
|
|
__u8 valid_map[SIT_VBLOCK_MAP_SIZE]; /* bitmap for valid blocks */
|
|
|
|
__le64 mtime; /* segment age for cleaning */
|
2012-10-26 12:56:34 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_sit_entry) == 74, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_sit_block {
|
|
|
|
struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_sit_block) == 4070, "");
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
/*
|
2012-10-29 22:35:00 +00:00
|
|
|
* For segment summary
|
|
|
|
*
|
2012-10-31 09:29:45 +00:00
|
|
|
* One summary block contains exactly 512 summary entries, which represents
|
|
|
|
* exactly 2MB segment by default. Not allow to change the basic units.
|
|
|
|
*
|
2013-01-25 04:39:34 +00:00
|
|
|
* NOTE: For initializing fields, you must use set_summary
|
2012-10-29 22:35:00 +00:00
|
|
|
*
|
|
|
|
* - If data page, nid represents dnode's nid
|
|
|
|
* - If node page, nid represents the node page's nid.
|
|
|
|
*
|
|
|
|
* The ofs_in_node is used by only data page. It represents offset
|
|
|
|
* from node's page's beginning to get a data block address.
|
|
|
|
* ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node)
|
|
|
|
*/
|
2012-10-31 09:29:45 +00:00
|
|
|
#define ENTRIES_IN_SUM 512
|
2013-01-25 04:39:34 +00:00
|
|
|
#define SUMMARY_SIZE (7) /* sizeof(struct summary) */
|
|
|
|
#define SUM_FOOTER_SIZE (5) /* sizeof(struct summary_footer) */
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
#define SUM_ENTRIES_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM)
|
2012-10-31 09:29:45 +00:00
|
|
|
|
|
|
|
/* a summary entry for a 4KB-sized block in a segment */
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_summary {
|
|
|
|
__le32 nid; /* parent node id */
|
|
|
|
union {
|
|
|
|
__u8 reserved[3];
|
|
|
|
struct {
|
|
|
|
__u8 version; /* node version number */
|
2012-10-29 22:35:00 +00:00
|
|
|
__le16 ofs_in_node; /* block index in parent node */
|
2012-10-26 12:56:34 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
};
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_summary) == 7, "");
|
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
/* summary block type, node or data, is stored to the summary_footer */
|
|
|
|
#define SUM_TYPE_NODE (1)
|
|
|
|
#define SUM_TYPE_DATA (0)
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
struct summary_footer {
|
|
|
|
unsigned char entry_type; /* SUM_TYPE_XXX */
|
2022-04-21 22:18:18 +00:00
|
|
|
__le32 check_sum __attribute__((packed)); /* summary checksum */
|
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct summary_footer) == 5, "");
|
|
|
|
|
2013-01-25 04:39:34 +00:00
|
|
|
#define SUM_JOURNAL_SIZE (F2FS_BLKSIZE - SUM_FOOTER_SIZE -\
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
SUM_ENTRIES_SIZE)
|
2012-10-26 12:56:34 +00:00
|
|
|
#define NAT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
|
|
|
|
sizeof(struct nat_journal_entry))
|
|
|
|
#define NAT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\
|
|
|
|
sizeof(struct nat_journal_entry))
|
|
|
|
#define SIT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
|
|
|
|
sizeof(struct sit_journal_entry))
|
|
|
|
#define SIT_JOURNAL_RESERVED ((SUM_JOURNAL_SIZE - 2) %\
|
|
|
|
sizeof(struct sit_journal_entry))
|
2016-03-11 08:43:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserved area should make size of f2fs_extra_info equals to
|
|
|
|
* that of nat_journal and sit_journal.
|
|
|
|
*/
|
|
|
|
#define EXTRA_INFO_RESERVED (SUM_JOURNAL_SIZE - 2 - 8)
|
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
/*
|
|
|
|
* frequently updated NAT/SIT entries can be stored in the spare area in
|
|
|
|
* summary blocks
|
|
|
|
*/
|
2012-10-26 12:56:34 +00:00
|
|
|
enum {
|
|
|
|
NAT_JOURNAL = 0,
|
|
|
|
SIT_JOURNAL
|
|
|
|
};
|
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
struct nat_journal_entry {
|
|
|
|
__le32 nid;
|
|
|
|
struct f2fs_nat_entry ne;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct nat_journal_entry) == 13, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct nat_journal {
|
|
|
|
struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES];
|
|
|
|
__u8 reserved[NAT_JOURNAL_RESERVED];
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct nat_journal) == 505, "");
|
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
struct sit_journal_entry {
|
|
|
|
__le32 segno;
|
|
|
|
struct f2fs_sit_entry se;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct sit_journal_entry) == 78, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
struct sit_journal {
|
|
|
|
struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES];
|
|
|
|
__u8 reserved[SIT_JOURNAL_RESERVED];
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct sit_journal) == 505, "");
|
|
|
|
|
2016-03-11 08:43:54 +00:00
|
|
|
struct f2fs_extra_info {
|
|
|
|
__le64 kbytes_written;
|
|
|
|
__u8 reserved[EXTRA_INFO_RESERVED];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_extra_info) == 505, "");
|
|
|
|
|
2016-03-11 08:43:54 +00:00
|
|
|
struct f2fs_journal {
|
2012-10-26 12:56:34 +00:00
|
|
|
union {
|
|
|
|
__le16 n_nats;
|
|
|
|
__le16 n_sits;
|
|
|
|
};
|
2016-03-11 08:43:54 +00:00
|
|
|
/* spare area is used by NAT or SIT journals or extra info */
|
2012-10-26 12:56:34 +00:00
|
|
|
union {
|
|
|
|
struct nat_journal nat_j;
|
|
|
|
struct sit_journal sit_j;
|
2016-03-11 08:43:54 +00:00
|
|
|
struct f2fs_extra_info info;
|
2012-10-26 12:56:34 +00:00
|
|
|
};
|
2016-03-11 08:43:54 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_journal) == 507, "");
|
|
|
|
|
2016-03-11 08:43:54 +00:00
|
|
|
/* 4KB-sized summary block structure */
|
|
|
|
struct f2fs_summary_block {
|
|
|
|
struct f2fs_summary entries[ENTRIES_IN_SUM];
|
|
|
|
struct f2fs_journal journal;
|
2012-10-26 12:56:34 +00:00
|
|
|
struct summary_footer footer;
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_summary_block) == 4096, "");
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
/*
|
|
|
|
* For directory operations
|
|
|
|
*/
|
2013-01-25 04:39:34 +00:00
|
|
|
#define F2FS_DOT_HASH 0
|
|
|
|
#define F2FS_DDOT_HASH F2FS_DOT_HASH
|
|
|
|
#define F2FS_MAX_HASH (~((0x3ULL) << 62))
|
|
|
|
#define F2FS_HASH_COL_BIT ((0x1ULL) << 63)
|
|
|
|
|
|
|
|
typedef __le32 f2fs_hash_t;
|
|
|
|
|
2012-10-29 22:35:00 +00:00
|
|
|
/* One directory entry slot covers 8bytes-long file name */
|
2013-03-03 05:00:50 +00:00
|
|
|
#define F2FS_SLOT_LEN 8
|
|
|
|
#define F2FS_SLOT_LEN_BITS 3
|
2013-01-25 04:39:34 +00:00
|
|
|
|
2013-03-03 05:00:50 +00:00
|
|
|
#define GET_DENTRY_SLOTS(x) ((x + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS)
|
2012-10-29 22:35:00 +00:00
|
|
|
|
|
|
|
/* the number of dentry in a block */
|
|
|
|
#define NR_DENTRY_IN_BLOCK 214
|
|
|
|
|
|
|
|
/* MAX level for dir lookup */
|
|
|
|
#define MAX_DIR_HASH_DEPTH 63
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2016-03-16 03:05:14 +00:00
|
|
|
/* MAX buckets in one level of dir */
|
|
|
|
#define MAX_DIR_BUCKETS (1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
|
|
|
|
|
2012-10-26 12:56:34 +00:00
|
|
|
#define SIZE_OF_DIR_ENTRY 11 /* by byte */
|
|
|
|
#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
|
2013-01-25 04:39:34 +00:00
|
|
|
BITS_PER_BYTE)
|
2012-10-26 12:56:34 +00:00
|
|
|
#define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
|
2013-03-03 05:00:50 +00:00
|
|
|
F2FS_SLOT_LEN) * \
|
2012-10-26 12:56:34 +00:00
|
|
|
NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
|
2019-03-04 09:21:37 +00:00
|
|
|
#define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */
|
2012-10-26 12:56:34 +00:00
|
|
|
|
2013-03-03 05:00:50 +00:00
|
|
|
/* One directory entry slot representing F2FS_SLOT_LEN-sized file name */
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_dir_entry {
|
|
|
|
__le32 hash_code; /* hash code of file name */
|
2012-10-31 09:29:45 +00:00
|
|
|
__le32 ino; /* inode number */
|
|
|
|
__le16 name_len; /* lengh of file name */
|
|
|
|
__u8 file_type; /* file type */
|
2012-10-26 12:56:34 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2022-04-21 22:18:15 +00:00
|
|
|
static_assert(sizeof(struct f2fs_dir_entry) == 11, "");
|
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
/* 4KB-sized directory entry block */
|
2012-10-26 12:56:34 +00:00
|
|
|
struct f2fs_dentry_block {
|
2012-10-31 09:29:45 +00:00
|
|
|
/* validity bitmap for directory entries in each block */
|
2012-10-26 12:56:34 +00:00
|
|
|
__u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];
|
|
|
|
__u8 reserved[SIZE_OF_RESERVED];
|
|
|
|
struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
|
2013-03-03 05:00:50 +00:00
|
|
|
__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
|
2022-04-21 22:18:18 +00:00
|
|
|
};
|
2022-04-21 22:18:15 +00:00
|
|
|
|
|
|
|
static_assert(sizeof(struct f2fs_dentry_block) == 4096, "");
|
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
/* for inline stuff */
|
|
|
|
#define DEF_INLINE_RESERVED_SIZE 1
|
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
/* for inline dir */
|
2017-07-26 14:49:57 +00:00
|
|
|
#define NR_INLINE_DENTRY(node) (MAX_INLINE_DATA(node) * BITS_PER_BYTE / \
|
2014-10-14 22:15:40 +00:00
|
|
|
((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
|
|
|
|
BITS_PER_BYTE + 1))
|
2017-07-26 14:49:57 +00:00
|
|
|
#define INLINE_DENTRY_BITMAP_SIZE(node) ((NR_INLINE_DENTRY(node) + \
|
2014-10-14 22:15:40 +00:00
|
|
|
BITS_PER_BYTE - 1) / BITS_PER_BYTE)
|
2017-07-26 14:49:57 +00:00
|
|
|
#define INLINE_RESERVED_SIZE(node) (MAX_INLINE_DATA(node) - \
|
2014-10-14 22:15:40 +00:00
|
|
|
((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
|
2017-07-26 14:49:57 +00:00
|
|
|
NR_INLINE_DENTRY(node) + \
|
|
|
|
INLINE_DENTRY_BITMAP_SIZE(node)))
|
2014-10-14 22:15:40 +00:00
|
|
|
|
2012-10-31 09:29:45 +00:00
|
|
|
/* file types used in inode_info->flags */
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
enum FILE_TYPE {
|
2012-10-26 12:56:34 +00:00
|
|
|
F2FS_FT_UNKNOWN,
|
2013-10-08 09:46:55 +00:00
|
|
|
F2FS_FT_REG_FILE,
|
|
|
|
F2FS_FT_DIR,
|
|
|
|
F2FS_FT_CHRDEV,
|
|
|
|
F2FS_FT_BLKDEV,
|
|
|
|
F2FS_FT_FIFO,
|
|
|
|
F2FS_FT_SOCK,
|
|
|
|
F2FS_FT_SYMLINK,
|
|
|
|
F2FS_FT_MAX,
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
/* added for fsck */
|
2013-10-08 09:46:55 +00:00
|
|
|
F2FS_FT_ORPHAN,
|
2014-08-28 00:06:17 +00:00
|
|
|
F2FS_FT_XATTR,
|
2014-10-29 02:11:52 +00:00
|
|
|
F2FS_FT_LAST_FILE_TYPE = F2FS_FT_XATTR,
|
2012-10-26 12:56:34 +00:00
|
|
|
};
|
|
|
|
|
2020-06-08 18:37:28 +00:00
|
|
|
#define LINUX_S_IFMT 00170000
|
|
|
|
#define LINUX_S_IFREG 0100000
|
|
|
|
#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
/* from f2fs/segment.h */
|
|
|
|
enum {
|
|
|
|
LFS = 0,
|
|
|
|
SSR
|
|
|
|
};
|
|
|
|
|
2022-04-21 22:18:11 +00:00
|
|
|
extern int utf8_to_utf16(uint16_t *, const char *, size_t, size_t);
|
|
|
|
extern int utf16_to_utf8(char *, const uint16_t *, size_t, size_t);
|
|
|
|
extern int log_base_2(uint32_t);
|
2013-10-08 11:04:35 +00:00
|
|
|
extern unsigned int addrs_per_inode(struct f2fs_inode *);
|
2019-03-25 13:19:35 +00:00
|
|
|
extern unsigned int addrs_per_block(struct f2fs_inode *);
|
2021-06-13 03:42:47 +00:00
|
|
|
extern unsigned int f2fs_max_file_offset(struct f2fs_inode *);
|
2017-07-26 15:01:35 +00:00
|
|
|
extern __u32 f2fs_inode_chksum(struct f2fs_node *);
|
2019-05-14 09:33:39 +00:00
|
|
|
extern __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *);
|
2019-05-24 07:28:11 +00:00
|
|
|
extern int write_inode(struct f2fs_node *, u64);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
|
|
|
extern int get_bits_in_byte(unsigned char n);
|
2015-12-15 19:13:25 +00:00
|
|
|
extern int test_and_set_bit_le(u32, u8 *);
|
|
|
|
extern int test_and_clear_bit_le(u32, u8 *);
|
|
|
|
extern int test_bit_le(u32, const u8 *);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
extern int f2fs_test_bit(unsigned int, const char *);
|
|
|
|
extern int f2fs_set_bit(unsigned int, char *);
|
|
|
|
extern int f2fs_clear_bit(unsigned int, char *);
|
2015-12-18 07:57:10 +00:00
|
|
|
extern u64 find_next_bit_le(const u8 *, u64, u64);
|
|
|
|
extern u64 find_next_zero_bit_le(const u8 *, u64, u64);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2022-04-21 22:18:11 +00:00
|
|
|
extern uint32_t f2fs_cal_crc32(uint32_t, void *, int);
|
|
|
|
extern int f2fs_crc_valid(uint32_t blk_crc, void *buf, int len);
|
2013-01-25 08:20:16 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
extern void f2fs_init_configuration(void);
|
2016-11-02 00:23:40 +00:00
|
|
|
extern int f2fs_devs_are_umounted(void);
|
2019-04-23 02:42:20 +00:00
|
|
|
extern int f2fs_dev_is_writable(void);
|
2016-11-02 00:23:40 +00:00
|
|
|
extern int f2fs_dev_is_umounted(char *);
|
2016-09-17 01:41:00 +00:00
|
|
|
extern int f2fs_get_device_info(void);
|
2021-09-10 22:38:11 +00:00
|
|
|
extern int f2fs_get_f2fs_info(void);
|
2019-04-28 09:17:37 +00:00
|
|
|
extern unsigned int calc_extra_isize(void);
|
2016-11-02 00:23:40 +00:00
|
|
|
extern int get_device_info(int);
|
2017-11-30 04:34:37 +00:00
|
|
|
extern int f2fs_init_sparse_file(void);
|
2019-10-31 13:57:59 +00:00
|
|
|
extern void f2fs_release_sparse_resource(void);
|
2017-11-24 09:33:39 +00:00
|
|
|
extern int f2fs_finalize_device(void);
|
|
|
|
extern int f2fs_fsync_device(void);
|
2013-01-25 08:20:16 +00:00
|
|
|
|
libf2fs_io: Add user-space cache
Implemented cache options in F2FS configuration 'c' (i.e. user
options):
* use c.cache_config.num_cache_entry to set the number of
cache entries (in block), minimum 1024, or 0 to disable cache.
* use c.cache_config.max_hash_collision to set maximum hash
collision (max 16).
* use c.cavhe_config.dbg_en to enable printing of debug messages.
Cache properties:
* Per block save based (block size = f2fs block size = 4K Bytes)
* Device block indices are used to hash (simple modular hash
function) to cache indices.
* A hash collision (when a block is hashed to an already occupied
cache block) will trigger offset-based relocation to max 16
other places, at first empty slot found policy.
* A hash collision with all 17 possible relocating places occupied
will evict the oldest used one (replaced by the new read block).
A global 'use' tick is kept ticking-up per block read for this
purpose.
* On write cache hit, it will update the corresponding cached
block.
* On write cache miss, the data won't be cached.
* Write-through policy only: never delayed write.
* On read cache hit, it returns the cached block.
* On read cache miss, it issues an I/O read to the kernel, and
then caches and returns the block.
* Currently read ahead is not implemented. Yet, the read ahead
logic is kept as before, i.e. using kernel's read ahead
mechanism.
Signed-off-by: Robin Hsu <robinhsu@google.com>
[Jaegeuk Kim: Fix one bug in dcache_update_rw()]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-11-18 10:13:07 +00:00
|
|
|
extern void dcache_init(void);
|
|
|
|
extern void dcache_release(void);
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
extern int dev_read(void *, __u64, size_t);
|
2019-08-09 10:52:57 +00:00
|
|
|
#ifdef POSIX_FADV_WILLNEED
|
|
|
|
extern int dev_readahead(__u64, size_t);
|
|
|
|
#else
|
|
|
|
extern int dev_readahead(__u64, size_t UNUSED(len));
|
|
|
|
#endif
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
extern int dev_write(void *, __u64, size_t);
|
2014-08-29 18:46:25 +00:00
|
|
|
extern int dev_write_block(void *, __u64);
|
2014-08-19 21:05:21 +00:00
|
|
|
extern int dev_write_dump(void *, __u64, size_t);
|
2014-03-31 22:33:01 +00:00
|
|
|
/* All bytes in the buffer must be 0 use dev_fill(). */
|
|
|
|
extern int dev_fill(void *, __u64, size_t);
|
2016-09-16 01:44:41 +00:00
|
|
|
extern int dev_fill_block(void *, __u64);
|
2013-01-25 08:20:16 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
extern int dev_read_block(void *, __u64);
|
2014-12-02 22:08:11 +00:00
|
|
|
extern int dev_reada_block(__u64);
|
2013-01-25 08:20:16 +00:00
|
|
|
|
2014-11-07 03:34:40 +00:00
|
|
|
extern int dev_read_version(void *, __u64, size_t);
|
|
|
|
extern void get_kernel_version(__u8 *);
|
2018-05-01 20:54:25 +00:00
|
|
|
extern void get_kernel_uname_version(__u8 *);
|
2019-07-11 20:45:41 +00:00
|
|
|
f2fs_hash_t f2fs_dentry_hash(int, int, const unsigned char *, int);
|
2013-01-25 08:20:16 +00:00
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
static inline bool f2fs_has_extra_isize(struct f2fs_inode *inode)
|
|
|
|
{
|
|
|
|
return (inode->i_inline & F2FS_EXTRA_ATTR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __get_extra_isize(struct f2fs_inode *inode)
|
|
|
|
{
|
|
|
|
if (f2fs_has_extra_isize(inode))
|
|
|
|
return le16_to_cpu(inode->i_extra_isize) / sizeof(__le32);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-04 10:58:29 +00:00
|
|
|
extern struct f2fs_configuration c;
|
|
|
|
static inline int get_inline_xattr_addrs(struct f2fs_inode *inode)
|
|
|
|
{
|
|
|
|
if (c.feature & cpu_to_le32(F2FS_FEATURE_FLEXIBLE_INLINE_XATTR))
|
|
|
|
return le16_to_cpu(inode->i_inline_xattr_size);
|
|
|
|
else if (inode->i_inline & F2FS_INLINE_XATTR ||
|
|
|
|
inode->i_inline & F2FS_INLINE_DENTRY)
|
|
|
|
return DEFAULT_INLINE_XATTR_ADDRS;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
#define get_extra_isize(node) __get_extra_isize(&node->i)
|
|
|
|
|
2016-10-28 07:57:00 +00:00
|
|
|
#define F2FS_ZONED_NONE 0
|
|
|
|
#define F2FS_ZONED_HA 1
|
|
|
|
#define F2FS_ZONED_HM 2
|
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_BLKZONED_H
|
|
|
|
|
2020-12-28 18:41:09 +00:00
|
|
|
/* Let's just use v2, since v1 should be compatible with v2 */
|
|
|
|
#define BLK_ZONE_REP_CAPACITY (1 << 0)
|
|
|
|
struct blk_zone_v2 {
|
|
|
|
__u64 start; /* Zone start sector */
|
|
|
|
__u64 len; /* Zone length in number of sectors */
|
|
|
|
__u64 wp; /* Zone write pointer position */
|
|
|
|
__u8 type; /* Zone type */
|
|
|
|
__u8 cond; /* Zone condition */
|
|
|
|
__u8 non_seq; /* Non-sequential write resources active */
|
|
|
|
__u8 reset; /* Reset write pointer recommended */
|
|
|
|
__u8 resv[4];
|
|
|
|
__u64 capacity; /* Zone capacity in number of sectors */
|
|
|
|
__u8 reserved[24];
|
|
|
|
};
|
|
|
|
#define blk_zone blk_zone_v2
|
|
|
|
|
|
|
|
struct blk_zone_report_v2 {
|
|
|
|
__u64 sector;
|
|
|
|
__u32 nr_zones;
|
|
|
|
__u32 flags;
|
|
|
|
struct blk_zone zones[0];
|
|
|
|
};
|
|
|
|
#define blk_zone_report blk_zone_report_v2
|
|
|
|
|
2016-10-28 07:57:00 +00:00
|
|
|
#define blk_zone_type(z) (z)->type
|
|
|
|
#define blk_zone_conv(z) ((z)->type == BLK_ZONE_TYPE_CONVENTIONAL)
|
|
|
|
#define blk_zone_seq_req(z) ((z)->type == BLK_ZONE_TYPE_SEQWRITE_REQ)
|
|
|
|
#define blk_zone_seq_pref(z) ((z)->type == BLK_ZONE_TYPE_SEQWRITE_PREF)
|
|
|
|
#define blk_zone_seq(z) (blk_zone_seq_req(z) || blk_zone_seq_pref(z))
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
blk_zone_type_str(struct blk_zone *blkz)
|
|
|
|
{
|
|
|
|
switch (blk_zone_type(blkz)) {
|
|
|
|
case BLK_ZONE_TYPE_CONVENTIONAL:
|
|
|
|
return( "Conventional" );
|
|
|
|
case BLK_ZONE_TYPE_SEQWRITE_REQ:
|
|
|
|
return( "Sequential-write-required" );
|
|
|
|
case BLK_ZONE_TYPE_SEQWRITE_PREF:
|
|
|
|
return( "Sequential-write-preferred" );
|
|
|
|
}
|
|
|
|
return( "Unknown-type" );
|
|
|
|
}
|
|
|
|
|
|
|
|
#define blk_zone_cond(z) (z)->cond
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
blk_zone_cond_str(struct blk_zone *blkz)
|
|
|
|
{
|
|
|
|
switch (blk_zone_cond(blkz)) {
|
|
|
|
case BLK_ZONE_COND_NOT_WP:
|
|
|
|
return "Not-write-pointer";
|
|
|
|
case BLK_ZONE_COND_EMPTY:
|
|
|
|
return "Empty";
|
|
|
|
case BLK_ZONE_COND_IMP_OPEN:
|
|
|
|
return "Implicit-open";
|
|
|
|
case BLK_ZONE_COND_EXP_OPEN:
|
|
|
|
return "Explicit-open";
|
|
|
|
case BLK_ZONE_COND_CLOSED:
|
|
|
|
return "Closed";
|
|
|
|
case BLK_ZONE_COND_READONLY:
|
|
|
|
return "Read-only";
|
|
|
|
case BLK_ZONE_COND_FULL:
|
|
|
|
return "Full";
|
|
|
|
case BLK_ZONE_COND_OFFLINE:
|
|
|
|
return "Offline";
|
|
|
|
}
|
|
|
|
return "Unknown-cond";
|
|
|
|
}
|
|
|
|
|
2020-07-21 16:38:11 +00:00
|
|
|
/*
|
|
|
|
* Handle kernel zone capacity support
|
|
|
|
*/
|
|
|
|
#define blk_zone_empty(z) (blk_zone_cond(z) == BLK_ZONE_COND_EMPTY)
|
2016-10-28 07:57:00 +00:00
|
|
|
#define blk_zone_sector(z) (z)->start
|
|
|
|
#define blk_zone_length(z) (z)->len
|
|
|
|
#define blk_zone_wp_sector(z) (z)->wp
|
|
|
|
#define blk_zone_need_reset(z) (int)(z)->reset
|
|
|
|
#define blk_zone_non_seq(z) (int)(z)->non_seq
|
2020-07-21 16:38:11 +00:00
|
|
|
#define blk_zone_capacity(z, f) ((f & BLK_ZONE_REP_CAPACITY) ? \
|
|
|
|
(z)->capacity : (z)->len)
|
2016-10-28 07:57:00 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-04-02 02:44:53 +00:00
|
|
|
extern int f2fs_get_zoned_model(int);
|
2016-11-02 00:23:40 +00:00
|
|
|
extern int f2fs_get_zone_blocks(int);
|
2022-04-21 22:18:11 +00:00
|
|
|
extern int f2fs_report_zone(int, uint64_t, void *);
|
2019-11-28 07:59:23 +00:00
|
|
|
typedef int (report_zones_cb_t)(int i, void *, void *);
|
|
|
|
extern int f2fs_report_zones(int, report_zones_cb_t *, void *);
|
2016-11-02 00:23:40 +00:00
|
|
|
extern int f2fs_check_zones(int);
|
2019-11-28 07:59:25 +00:00
|
|
|
int f2fs_reset_zone(int, void *);
|
2016-11-02 00:23:40 +00:00
|
|
|
extern int f2fs_reset_zones(int);
|
2020-07-21 16:38:11 +00:00
|
|
|
extern uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb);
|
2016-05-27 21:20:43 +00:00
|
|
|
|
2020-12-08 08:15:54 +00:00
|
|
|
#define SIZE_ALIGN(val, size) (((val) + (size) - 1) / (size))
|
2017-11-14 18:53:32 +00:00
|
|
|
#define SEG_ALIGN(blks) SIZE_ALIGN(blks, c.blks_per_seg)
|
|
|
|
#define ZONE_ALIGN(blks) SIZE_ALIGN(blks, c.blks_per_seg * \
|
2016-09-17 01:41:00 +00:00
|
|
|
c.segs_per_zone)
|
2014-11-17 05:03:41 +00:00
|
|
|
|
2015-12-09 01:30:38 +00:00
|
|
|
static inline double get_best_overprovision(struct f2fs_super_block *sb)
|
|
|
|
{
|
|
|
|
double reserved, ovp, candidate, end, diff, space;
|
|
|
|
double max_ovp = 0, max_space = 0;
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t usable_main_segs = f2fs_get_usable_segments(sb);
|
2015-12-09 01:30:38 +00:00
|
|
|
|
|
|
|
if (get_sb(segment_count_main) < 256) {
|
|
|
|
candidate = 10;
|
|
|
|
end = 95;
|
|
|
|
diff = 5;
|
|
|
|
} else {
|
|
|
|
candidate = 0.01;
|
|
|
|
end = 10;
|
|
|
|
diff = 0.01;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; candidate <= end; candidate += diff) {
|
|
|
|
reserved = (2 * (100 / candidate + 1) + 6) *
|
2020-07-21 16:38:11 +00:00
|
|
|
round_up(usable_main_segs, get_sb(section_count));
|
|
|
|
ovp = (usable_main_segs - reserved) * candidate / 100;
|
|
|
|
space = usable_main_segs - reserved - ovp;
|
2015-12-09 01:30:38 +00:00
|
|
|
if (max_space < space) {
|
|
|
|
max_space = space;
|
|
|
|
max_ovp = candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return max_ovp;
|
|
|
|
}
|
|
|
|
|
2017-02-09 02:55:43 +00:00
|
|
|
static inline __le64 get_cp_crc(struct f2fs_checkpoint *cp)
|
|
|
|
{
|
2022-04-21 22:18:11 +00:00
|
|
|
uint64_t cp_ver = get_cp(checkpoint_ver);
|
2017-02-09 02:55:43 +00:00
|
|
|
size_t crc_offset = get_cp(checksum_offset);
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t crc = le32_to_cpu(*(__le32 *)((unsigned char *)cp +
|
2017-02-09 02:55:43 +00:00
|
|
|
crc_offset));
|
|
|
|
|
2022-04-21 22:18:11 +00:00
|
|
|
cp_ver |= ((uint64_t)crc << 32);
|
2017-02-09 02:55:43 +00:00
|
|
|
return cpu_to_le64(cp_ver);
|
|
|
|
}
|
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
static inline int exist_qf_ino(struct f2fs_super_block *sb)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < F2FS_MAX_QUOTAS; i++)
|
|
|
|
if (sb->qf_ino[i])
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-30 23:10:27 +00:00
|
|
|
static inline int is_qf_ino(struct f2fs_super_block *sb, nid_t ino)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < F2FS_MAX_QUOTAS; i++)
|
|
|
|
if (sb->qf_ino[i] == ino)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-10 03:28:19 +00:00
|
|
|
static inline void show_version(const char *prog)
|
|
|
|
{
|
2018-11-16 01:38:01 +00:00
|
|
|
#if defined(F2FS_TOOLS_VERSION) && defined(F2FS_TOOLS_DATE)
|
2018-04-10 03:28:19 +00:00
|
|
|
MSG(0, "%s %s (%s)\n", prog, F2FS_TOOLS_VERSION, F2FS_TOOLS_DATE);
|
2018-11-16 01:38:01 +00:00
|
|
|
#else
|
|
|
|
MSG(0, "%s -- version not supported\n", prog);
|
|
|
|
#endif
|
2018-04-10 03:28:19 +00:00
|
|
|
}
|
|
|
|
|
f2fs-tools: rebuild the quota inode if it is corrupted
commit 1228009520d1d2cb392ae52f8aaf3c6ec42edccf
category: bugfix
issue: #I6VAS0
CVE: NA
Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------
If the following process returns an error,
the quota inode, not the quota file, is damaged.
(fsck_chk_quota_node-->fsck_chk_node_blk-->sanity_check_nid)
The fsck does not have a process to rebuild the quota inode.
Because sanity_check_nid is not passed, fsck->nat_area_bitmap
can not be cleared, and then the NAT of quota will be nullify
during fix_nat_entries.
During the next fsck check, the quota inode check fails
because the address of the quota inode changes to 0.
In addition, in fsck_chk_quota_files-->f2fs_filesize_update,
data is written to address 0.
Therefore, when the quota inode is corrupted, we need to rebuild it.
Signed-off-by: Wang Xiaojun <wangxiaojun11@huawei.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2021-07-20 06:41:18 +00:00
|
|
|
static inline void f2fs_init_qf_inode(struct f2fs_super_block *sb,
|
|
|
|
struct f2fs_node *raw_node, int qtype, time_t mtime)
|
|
|
|
{
|
|
|
|
raw_node->footer.nid = sb->qf_ino[qtype];
|
|
|
|
raw_node->footer.ino = sb->qf_ino[qtype];
|
|
|
|
raw_node->footer.cp_ver = cpu_to_le64(1);
|
|
|
|
raw_node->i.i_mode = cpu_to_le16(0x8180);
|
|
|
|
raw_node->i.i_links = cpu_to_le32(1);
|
|
|
|
raw_node->i.i_uid = cpu_to_le32(c.root_uid);
|
|
|
|
raw_node->i.i_gid = cpu_to_le32(c.root_gid);
|
|
|
|
|
|
|
|
raw_node->i.i_size = cpu_to_le64(1024 * 6); /* Hard coded */
|
|
|
|
raw_node->i.i_blocks = cpu_to_le64(1);
|
|
|
|
|
|
|
|
raw_node->i.i_atime = cpu_to_le32(mtime);
|
|
|
|
raw_node->i.i_atime_nsec = 0;
|
|
|
|
raw_node->i.i_ctime = cpu_to_le32(mtime);
|
|
|
|
raw_node->i.i_ctime_nsec = 0;
|
|
|
|
raw_node->i.i_mtime = cpu_to_le32(mtime);
|
|
|
|
raw_node->i.i_mtime_nsec = 0;
|
|
|
|
raw_node->i.i_generation = 0;
|
|
|
|
raw_node->i.i_xattr_nid = 0;
|
|
|
|
raw_node->i.i_flags = FS_IMMUTABLE_FL;
|
|
|
|
raw_node->i.i_current_depth = cpu_to_le32(0);
|
|
|
|
raw_node->i.i_dir_level = DEF_DIR_LEVEL;
|
|
|
|
|
|
|
|
if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
|
|
|
|
raw_node->i.i_inline = F2FS_EXTRA_ATTR;
|
|
|
|
raw_node->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
|
|
|
|
raw_node->i.i_projid = cpu_to_le32(F2FS_DEF_PROJID);
|
|
|
|
|
|
|
|
raw_node->i.i_ext.fofs = 0;
|
|
|
|
raw_node->i.i_ext.blk_addr = 0;
|
|
|
|
raw_node->i.i_ext.len = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-19 20:41:31 +00:00
|
|
|
struct feature {
|
|
|
|
char *name;
|
|
|
|
u32 mask;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define INIT_FEATURE_TABLE \
|
|
|
|
struct feature feature_table[] = { \
|
|
|
|
{ "encrypt", F2FS_FEATURE_ENCRYPT }, \
|
|
|
|
{ "extra_attr", F2FS_FEATURE_EXTRA_ATTR }, \
|
|
|
|
{ "project_quota", F2FS_FEATURE_PRJQUOTA }, \
|
|
|
|
{ "inode_checksum", F2FS_FEATURE_INODE_CHKSUM }, \
|
|
|
|
{ "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR },\
|
|
|
|
{ "quota", F2FS_FEATURE_QUOTA_INO }, \
|
|
|
|
{ "inode_crtime", F2FS_FEATURE_INODE_CRTIME }, \
|
|
|
|
{ "lost_found", F2FS_FEATURE_LOST_FOUND }, \
|
|
|
|
{ "verity", F2FS_FEATURE_VERITY }, /* reserved */ \
|
2018-09-28 12:25:59 +00:00
|
|
|
{ "sb_checksum", F2FS_FEATURE_SB_CHKSUM }, \
|
2019-07-11 20:45:41 +00:00
|
|
|
{ "casefold", F2FS_FEATURE_CASEFOLD }, \
|
2019-03-25 13:19:35 +00:00
|
|
|
{ "compression", F2FS_FEATURE_COMPRESSION }, \
|
2020-06-30 21:03:51 +00:00
|
|
|
{ "ro", F2FS_FEATURE_RO}, \
|
2018-04-19 20:41:31 +00:00
|
|
|
{ NULL, 0x0}, \
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline u32 feature_map(struct feature *table, char *feature)
|
|
|
|
{
|
|
|
|
struct feature *p;
|
|
|
|
for (p = table; p->name && strcmp(p->name, feature); p++)
|
|
|
|
;
|
|
|
|
return p->mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int set_feature_bits(struct feature *table, char *features)
|
|
|
|
{
|
|
|
|
u32 mask = feature_map(table, features);
|
|
|
|
if (mask) {
|
|
|
|
c.feature |= cpu_to_le32(mask);
|
|
|
|
} else {
|
|
|
|
MSG(0, "Error: Wrong features %s\n", features);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int parse_feature(struct feature *table, const char *features)
|
|
|
|
{
|
|
|
|
char *buf, *sub, *next;
|
|
|
|
|
2019-03-18 06:39:55 +00:00
|
|
|
buf = strdup(features);
|
|
|
|
if (!buf)
|
|
|
|
return -1;
|
2018-04-19 20:41:31 +00:00
|
|
|
|
|
|
|
for (sub = buf; sub && *sub; sub = next ? next + 1 : NULL) {
|
|
|
|
/* Skip the beginning blanks */
|
|
|
|
while (*sub && *sub == ' ')
|
|
|
|
sub++;
|
|
|
|
next = sub;
|
|
|
|
/* Skip a feature word */
|
|
|
|
while (*next && *next != ' ' && *next != ',')
|
|
|
|
next++;
|
|
|
|
|
|
|
|
if (*next == 0)
|
|
|
|
next = NULL;
|
|
|
|
else
|
|
|
|
*next = 0;
|
|
|
|
|
|
|
|
if (set_feature_bits(table, sub)) {
|
|
|
|
free(buf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-27 08:12:32 +00:00
|
|
|
|
|
|
|
static inline int parse_root_owner(char *ids,
|
2022-04-21 22:18:11 +00:00
|
|
|
uint32_t *root_uid, uint32_t *root_gid)
|
2018-07-27 08:12:32 +00:00
|
|
|
{
|
|
|
|
char *uid = ids;
|
|
|
|
char *gid = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* uid:gid */
|
|
|
|
for (i = 0; i < strlen(ids) - 1; i++)
|
|
|
|
if (*(ids + i) == ':')
|
|
|
|
gid = ids + i + 1;
|
|
|
|
if (!gid)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*root_uid = atoi(uid);
|
|
|
|
*root_gid = atoi(gid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
/*
|
|
|
|
* NLS definitions
|
|
|
|
*/
|
|
|
|
struct f2fs_nls_table {
|
|
|
|
int version;
|
|
|
|
const struct f2fs_nls_ops *ops;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct f2fs_nls_ops {
|
|
|
|
int (*casefold)(const struct f2fs_nls_table *charset,
|
|
|
|
const unsigned char *str, size_t len,
|
|
|
|
unsigned char *dest, size_t dlen);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct f2fs_nls_table *f2fs_load_nls_table(int encoding);
|
|
|
|
#define F2FS_ENC_UTF8_12_0 1
|
|
|
|
|
|
|
|
extern int f2fs_str2encoding(const char *string);
|
2020-07-18 03:10:21 +00:00
|
|
|
extern char *f2fs_encoding2str(const int encoding);
|
2019-07-11 20:45:41 +00:00
|
|
|
extern int f2fs_get_encoding_flags(int encoding);
|
|
|
|
extern int f2fs_str2encoding_flags(char **param, __u16 *flags);
|
|
|
|
|
2013-02-12 02:03:24 +00:00
|
|
|
#endif /*__F2FS_FS_H */
|