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
|
|
|
/**
|
|
|
|
* main.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com/
|
2015-10-23 18:45:36 +00:00
|
|
|
* Copyright (c) 2015 Jaegeuk Kim <jaegeuk@kernel.org>
|
|
|
|
* : implement defrag.f2fs
|
2015-12-10 00:18:44 +00:00
|
|
|
* Copyright (C) 2015 Huawei Ltd.
|
|
|
|
* Hou Pengyang <houpengyang@huawei.com>
|
|
|
|
* Liu Shuoran <liushuoran@huawei.com>
|
|
|
|
* Jaegeuk Kim <jaegeuk@kernel.org>
|
|
|
|
* : add sload.f2fs
|
2019-11-18 10:13:21 +00:00
|
|
|
* Copyright (c) 2019 Google Inc.
|
|
|
|
* Robin Hsu <robinhsu@google.com>
|
|
|
|
* : add cache layer
|
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
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include "fsck.h"
|
|
|
|
#include <libgen.h>
|
2017-01-21 05:12:17 +00:00
|
|
|
#include <ctype.h>
|
2019-05-21 20:17:24 +00:00
|
|
|
#include <time.h>
|
2017-11-02 03:56:09 +00:00
|
|
|
#include <getopt.h>
|
2019-11-18 10:13:21 +00:00
|
|
|
#include <stdbool.h>
|
2017-10-30 23:21:09 +00:00
|
|
|
#include "quotaio.h"
|
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
|
|
|
|
2014-08-27 00:26:01 +00:00
|
|
|
struct f2fs_fsck gfsck;
|
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-30 04:34:37 +00:00
|
|
|
#ifdef WITH_ANDROID
|
|
|
|
#include <sparse/sparse.h>
|
|
|
|
extern struct sparse_file *f2fs_sparse_file;
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 20:53:31 +00:00
|
|
|
INIT_FEATURE_TABLE;
|
|
|
|
|
2017-11-30 01:21:12 +00:00
|
|
|
static char *absolute_path(const char *file)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
char cwd[PATH_MAX];
|
|
|
|
|
|
|
|
if (file[0] != '/') {
|
|
|
|
if (getcwd(cwd, PATH_MAX) == NULL) {
|
|
|
|
fprintf(stderr, "Failed to getcwd\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
ret = malloc(strlen(cwd) + 1 + strlen(file) + 1);
|
|
|
|
if (ret)
|
|
|
|
sprintf(ret, "%s/%s", cwd, file);
|
|
|
|
} else
|
|
|
|
ret = strdup(file);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void fsck_usage()
|
|
|
|
{
|
|
|
|
MSG(0, "\nUsage: fsck.f2fs [options] device\n");
|
|
|
|
MSG(0, "[options]:\n");
|
2014-09-04 02:41:44 +00:00
|
|
|
MSG(0, " -a check/fix potential corruption, reported by f2fs\n");
|
2019-11-18 10:13:21 +00:00
|
|
|
MSG(0, " -c <num-cache-entry> set number of cache entries"
|
|
|
|
" (default 0)\n");
|
|
|
|
MSG(0, " -m <max-hash-collision> set max cache hash collision"
|
|
|
|
" (default 16)\n");
|
|
|
|
MSG(0, " -C encoding[:flag1,flag2] Set options for enabling"
|
|
|
|
" casefolding\n");
|
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
|
|
|
MSG(0, " -d debug level [default:0]\n");
|
2014-09-04 02:41:44 +00:00
|
|
|
MSG(0, " -f check/fix entire partition\n");
|
2018-04-19 18:33:14 +00:00
|
|
|
MSG(0, " -g add default options\n");
|
2018-04-19 20:53:31 +00:00
|
|
|
MSG(0, " -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
|
2016-03-14 06:16:53 +00:00
|
|
|
MSG(0, " -p preen mode [default:0 the same as -a [0|1]]\n");
|
2017-11-30 04:34:37 +00:00
|
|
|
MSG(0, " -S sparse_mode\n");
|
2017-03-15 13:28:19 +00:00
|
|
|
MSG(0, " -t show directory tree\n");
|
2017-11-08 19:20:47 +00:00
|
|
|
MSG(0, " -q preserve quota limits\n");
|
2017-12-28 20:33:03 +00:00
|
|
|
MSG(0, " -y fix all the time\n");
|
2018-04-10 03:28:19 +00:00
|
|
|
MSG(0, " -V print the version number and exit\n");
|
2017-11-02 03:56:09 +00:00
|
|
|
MSG(0, " --dry-run do not really fix corruptions\n");
|
2019-10-14 17:10:31 +00:00
|
|
|
MSG(0, " --no-kernel-check skips detecting kernel change\n");
|
|
|
|
MSG(0, " --kernel-check checks kernel change\n");
|
2019-11-18 10:13:21 +00:00
|
|
|
MSG(0, " --debug-cache to debug cache when -c is used\n");
|
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
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_usage()
|
|
|
|
{
|
|
|
|
MSG(0, "\nUsage: dump.f2fs [options] device\n");
|
|
|
|
MSG(0, "[options]:\n");
|
|
|
|
MSG(0, " -d debug level [default:0]\n");
|
|
|
|
MSG(0, " -i inode no (hex)\n");
|
2018-07-02 09:22:41 +00:00
|
|
|
MSG(0, " -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n");
|
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
|
|
|
MSG(0, " -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]\n");
|
2017-11-30 04:34:37 +00:00
|
|
|
MSG(0, " -S sparse_mode\n");
|
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
|
|
|
MSG(0, " -a [SSA dump segno from #1~#2 (decimal), for all 0~-1]\n");
|
2013-07-18 02:20:05 +00:00
|
|
|
MSG(0, " -b blk_addr (in 4KB)\n");
|
2018-04-10 03:28:19 +00:00
|
|
|
MSG(0, " -V print the version number and exit\n");
|
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
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-10-23 18:45:36 +00:00
|
|
|
void defrag_usage()
|
|
|
|
{
|
|
|
|
MSG(0, "\nUsage: defrag.f2fs [options] device\n");
|
|
|
|
MSG(0, "[options]:\n");
|
|
|
|
MSG(0, " -d debug level [default:0]\n");
|
|
|
|
MSG(0, " -s start block address [default: main_blkaddr]\n");
|
2017-11-30 04:34:37 +00:00
|
|
|
MSG(0, " -S sparse_mode\n");
|
2015-10-23 18:45:36 +00:00
|
|
|
MSG(0, " -l length [default:512 (2MB)]\n");
|
|
|
|
MSG(0, " -t target block address [default: main_blkaddr + 2MB]\n");
|
|
|
|
MSG(0, " -i set direction as shrink [default: expand]\n");
|
2018-04-10 03:28:19 +00:00
|
|
|
MSG(0, " -V print the version number and exit\n");
|
2015-10-23 18:45:36 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:05:09 +00:00
|
|
|
void resize_usage()
|
|
|
|
{
|
|
|
|
MSG(0, "\nUsage: resize.f2fs [options] device\n");
|
|
|
|
MSG(0, "[options]:\n");
|
|
|
|
MSG(0, " -d debug level [default:0]\n");
|
2020-01-13 06:52:30 +00:00
|
|
|
MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n");
|
2018-05-09 02:48:33 +00:00
|
|
|
MSG(0, " -s safe resize (Does not resize metadata)");
|
2015-12-09 00:05:09 +00:00
|
|
|
MSG(0, " -t target sectors [default: device size]\n");
|
2018-04-10 03:28:19 +00:00
|
|
|
MSG(0, " -V print the version number and exit\n");
|
2015-12-09 00:05:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-12-10 00:18:44 +00:00
|
|
|
void sload_usage()
|
|
|
|
{
|
|
|
|
MSG(0, "\nUsage: sload.f2fs [options] device\n");
|
|
|
|
MSG(0, "[options]:\n");
|
2017-11-30 01:21:12 +00:00
|
|
|
MSG(0, " -C fs_config\n");
|
2015-12-10 00:18:44 +00:00
|
|
|
MSG(0, " -f source directory [path of the source directory]\n");
|
2017-11-30 01:21:12 +00:00
|
|
|
MSG(0, " -p product out directory\n");
|
|
|
|
MSG(0, " -s file_contexts\n");
|
2017-11-30 04:34:37 +00:00
|
|
|
MSG(0, " -S sparse_mode\n");
|
2015-12-10 00:18:44 +00:00
|
|
|
MSG(0, " -t mount point [prefix of target fs path, default:/]\n");
|
2017-11-30 01:21:12 +00:00
|
|
|
MSG(0, " -T timestamp\n");
|
2015-12-10 00:18:44 +00:00
|
|
|
MSG(0, " -d debug level [default:0]\n");
|
2018-04-10 03:28:19 +00:00
|
|
|
MSG(0, " -V print the version number and exit\n");
|
2015-12-10 00:18:44 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-01-21 05:12:17 +00:00
|
|
|
static int is_digits(char *optarg)
|
|
|
|
{
|
2017-06-05 20:44:50 +00:00
|
|
|
unsigned int i;
|
2017-01-21 05:12:17 +00:00
|
|
|
|
|
|
|
for (i = 0; i < strlen(optarg); i++)
|
|
|
|
if (!isdigit(optarg[i]))
|
|
|
|
break;
|
|
|
|
return i == strlen(optarg);
|
|
|
|
}
|
|
|
|
|
2017-02-11 00:12:33 +00:00
|
|
|
static void error_out(char *prog)
|
2017-01-21 05:52:52 +00:00
|
|
|
{
|
2017-02-11 00:12:33 +00:00
|
|
|
if (!strcmp("fsck.f2fs", prog))
|
2017-01-21 05:52:52 +00:00
|
|
|
fsck_usage();
|
2017-02-11 00:12:33 +00:00
|
|
|
else if (!strcmp("dump.f2fs", prog))
|
2017-01-21 05:52:52 +00:00
|
|
|
dump_usage();
|
2017-02-11 00:12:33 +00:00
|
|
|
else if (!strcmp("defrag.f2fs", prog))
|
2017-01-21 05:52:52 +00:00
|
|
|
defrag_usage();
|
2017-02-11 00:12:33 +00:00
|
|
|
else if (!strcmp("resize.f2fs", prog))
|
2017-01-21 05:52:52 +00:00
|
|
|
resize_usage();
|
2017-02-11 00:12:33 +00:00
|
|
|
else if (!strcmp("sload.f2fs", prog))
|
2017-01-21 05:52:52 +00:00
|
|
|
sload_usage();
|
2017-02-11 00:12:33 +00:00
|
|
|
else
|
2018-02-23 03:17:55 +00:00
|
|
|
MSG(0, "\nWrong program.\n");
|
2017-01-21 05:52:52 +00:00
|
|
|
}
|
|
|
|
|
2018-04-19 18:33:14 +00:00
|
|
|
static void __add_fsck_options(void)
|
|
|
|
{
|
|
|
|
/* -a */
|
|
|
|
c.auto_fix = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_default_options(void)
|
|
|
|
{
|
|
|
|
switch (c.defset) {
|
|
|
|
case CONF_ANDROID:
|
|
|
|
__add_fsck_options();
|
|
|
|
}
|
2018-09-19 01:28:37 +00:00
|
|
|
c.quota_fix = 1;
|
2018-04-19 18:33:14 +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
|
|
|
void f2fs_parse_options(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int option = 0;
|
|
|
|
char *prog = basename(argv[0]);
|
2017-01-21 05:52:52 +00:00
|
|
|
int err = NOERROR;
|
2017-11-30 02:49:15 +00:00
|
|
|
#ifdef WITH_ANDROID
|
|
|
|
int i;
|
2017-01-21 05:12:17 +00:00
|
|
|
|
2017-11-30 02:49:15 +00:00
|
|
|
/* Allow prog names (e.g, sload_f2fs, fsck_f2fs, etc) */
|
|
|
|
for (i = 0; i < strlen(prog); i++) {
|
|
|
|
if (prog[i] == '_')
|
|
|
|
prog[i] = '.';
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-21 05:12:17 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
MSG(0, "\tError: Device not specified\n");
|
2017-02-11 00:12:33 +00:00
|
|
|
error_out(prog);
|
2017-01-21 05:12:17 +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
|
|
|
|
|
|
|
if (!strcmp("fsck.f2fs", prog)) {
|
2019-11-18 10:13:21 +00:00
|
|
|
const char *option_string = ":aC:c:m:d:fg:O:p:q:StyV";
|
2019-07-11 20:45:41 +00:00
|
|
|
int opt = 0, val;
|
|
|
|
char *token;
|
2017-11-02 03:56:09 +00:00
|
|
|
struct option long_opt[] = {
|
|
|
|
{"dry-run", no_argument, 0, 1},
|
2019-10-14 17:10:31 +00:00
|
|
|
{"no-kernel-check", no_argument, 0, 2},
|
|
|
|
{"kernel-check", no_argument, 0, 3},
|
2019-11-18 10:13:21 +00:00
|
|
|
{"debug-cache", no_argument, 0, 4},
|
2017-11-02 03:56:09 +00:00
|
|
|
{0, 0, 0, 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
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.func = FSCK;
|
2019-11-18 10:13:21 +00:00
|
|
|
c.cache_config.max_hash_collision = 16;
|
|
|
|
c.cache_config.dbg_en = false;
|
2017-11-02 03:56:09 +00:00
|
|
|
while ((option = getopt_long(argc, argv, option_string,
|
|
|
|
long_opt, &opt)) != EOF) {
|
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
|
|
|
switch (option) {
|
2017-11-02 03:56:09 +00:00
|
|
|
case 1:
|
|
|
|
c.dry_run = 1;
|
|
|
|
MSG(0, "Info: Dry run\n");
|
|
|
|
break;
|
2019-10-14 17:10:31 +00:00
|
|
|
case 2:
|
|
|
|
c.no_kernel_check = 1;
|
|
|
|
MSG(0, "Info: No Kernel Check\n");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
c.no_kernel_check = 0;
|
|
|
|
MSG(0, "Info: Do Kernel Check\n");
|
|
|
|
break;
|
2019-11-18 10:13:21 +00:00
|
|
|
case 4:
|
|
|
|
c.cache_config.dbg_en = true;
|
|
|
|
break;
|
2014-09-03 01:07:35 +00:00
|
|
|
case 'a':
|
2016-09-17 01:41:00 +00:00
|
|
|
c.auto_fix = 1;
|
2014-09-03 01:07:35 +00:00
|
|
|
MSG(0, "Info: Fix the reported corruption.\n");
|
|
|
|
break;
|
2019-11-18 10:13:21 +00:00
|
|
|
case 'c':
|
|
|
|
c.cache_config.num_cache_entry = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
c.cache_config.max_hash_collision =
|
|
|
|
atoi(optarg);
|
|
|
|
break;
|
2018-04-19 18:33:14 +00:00
|
|
|
case 'g':
|
|
|
|
if (!strcmp(optarg, "android"))
|
|
|
|
c.defset = CONF_ANDROID;
|
|
|
|
break;
|
2018-04-19 20:53:31 +00:00
|
|
|
case 'O':
|
|
|
|
if (parse_feature(feature_table, optarg))
|
|
|
|
fsck_usage();
|
|
|
|
break;
|
2016-03-14 06:16:53 +00:00
|
|
|
case 'p':
|
|
|
|
/* preen mode has different levels:
|
|
|
|
* 0: default level, the same as -a
|
|
|
|
* 1: check meta
|
2018-11-27 12:36:35 +00:00
|
|
|
* 2: same as 0, but will skip some
|
|
|
|
* check for old kernel
|
2016-03-14 06:16:53 +00:00
|
|
|
*/
|
2018-01-31 01:24:57 +00:00
|
|
|
if (optarg[0] == '-' || !is_digits(optarg) ||
|
|
|
|
optind == argc) {
|
|
|
|
MSG(0, "Info: Use default preen mode\n");
|
2017-01-21 05:12:17 +00:00
|
|
|
c.preen_mode = PREEN_MODE_0;
|
2018-01-31 01:24:57 +00:00
|
|
|
c.auto_fix = 1;
|
2017-01-21 05:12:17 +00:00
|
|
|
optind--;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.preen_mode = atoi(optarg);
|
|
|
|
if (c.preen_mode < 0)
|
|
|
|
c.preen_mode = PREEN_MODE_0;
|
|
|
|
else if (c.preen_mode >= PREEN_MODE_MAX)
|
|
|
|
c.preen_mode = PREEN_MODE_MAX - 1;
|
2018-11-27 12:36:35 +00:00
|
|
|
if (c.preen_mode == PREEN_MODE_0 ||
|
|
|
|
c.preen_mode == PREEN_MODE_2)
|
2016-09-17 01:41:00 +00:00
|
|
|
c.auto_fix = 1;
|
2016-03-14 06:16:53 +00:00
|
|
|
MSG(0, "Info: Fix the reported corruption in "
|
2016-09-17 01:41:00 +00:00
|
|
|
"preen mode %d\n", c.preen_mode);
|
2016-03-14 06:16:53 +00:00
|
|
|
break;
|
2014-08-27 00:26:01 +00:00
|
|
|
case 'd':
|
2017-01-21 05:12:17 +00:00
|
|
|
if (optarg[0] == '-') {
|
2017-01-21 05:52:52 +00:00
|
|
|
err = ENEED_ARG;
|
2017-01-21 05:12:17 +00:00
|
|
|
break;
|
|
|
|
} else if (!is_digits(optarg)) {
|
2017-01-21 05:52:52 +00:00
|
|
|
err = EWRONG_OPT;
|
2017-01-21 05:12:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv = atoi(optarg);
|
2017-01-21 05:12:17 +00:00
|
|
|
MSG(0, "Info: Debug level = %d\n", c.dbg_lv);
|
2014-08-27 00:26:01 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2017-12-28 20:33:03 +00:00
|
|
|
case 'y':
|
2016-09-17 01:41:00 +00:00
|
|
|
c.fix_on = 1;
|
2018-11-26 10:53:37 +00:00
|
|
|
c.force = 1;
|
2014-08-27 00:26:01 +00:00
|
|
|
MSG(0, "Info: Force to fix corruption\n");
|
|
|
|
break;
|
2017-11-08 19:20:47 +00:00
|
|
|
case 'q':
|
|
|
|
c.preserve_limits = atoi(optarg);
|
|
|
|
MSG(0, "Info: Preserve quota limits = %d\n",
|
|
|
|
c.preserve_limits);
|
|
|
|
break;
|
2017-11-30 04:34:37 +00:00
|
|
|
case 'S':
|
|
|
|
c.sparse_mode = 1;
|
|
|
|
break;
|
2014-09-03 01:07:35 +00:00
|
|
|
case 't':
|
2017-03-15 13:28:19 +00:00
|
|
|
c.show_dentry = 1;
|
2014-09-03 01:07:35 +00:00
|
|
|
break;
|
2017-01-21 05:12:17 +00:00
|
|
|
case ':':
|
2017-01-21 05:52:52 +00:00
|
|
|
if (optopt == 'p') {
|
|
|
|
MSG(0, "Info: Use default preen mode\n");
|
|
|
|
c.preen_mode = PREEN_MODE_0;
|
|
|
|
c.auto_fix = 1;
|
|
|
|
} else {
|
|
|
|
option = optopt;
|
|
|
|
err = ENEED_ARG;
|
|
|
|
break;
|
|
|
|
}
|
2017-01-21 05:12:17 +00:00
|
|
|
break;
|
2019-07-11 20:45:41 +00:00
|
|
|
case 'C':
|
|
|
|
token = strtok(optarg, ":");
|
|
|
|
val = f2fs_str2encoding(token);
|
|
|
|
if (val < 0) {
|
|
|
|
MSG(0, "\tError: Unknown encoding %s\n", token);
|
|
|
|
fsck_usage();
|
|
|
|
}
|
|
|
|
c.s_encoding = val;
|
|
|
|
token = strtok(NULL, "");
|
|
|
|
val = f2fs_str2encoding_flags(&token, &c.s_encoding_flags);
|
|
|
|
if (val) {
|
|
|
|
MSG(0, "\tError: Unknown flag %s\n", token);
|
|
|
|
fsck_usage();
|
|
|
|
}
|
|
|
|
c.feature |= cpu_to_le32(F2FS_FEATURE_CASEFOLD);
|
|
|
|
break;
|
2018-04-10 03:28:19 +00:00
|
|
|
case 'V':
|
|
|
|
show_version(prog);
|
|
|
|
exit(0);
|
2017-01-21 05:12:17 +00:00
|
|
|
case '?':
|
2017-01-21 05:52:52 +00:00
|
|
|
option = optopt;
|
2014-08-27 00:26:01 +00:00
|
|
|
default:
|
2017-01-21 05:52:52 +00:00
|
|
|
err = EUNKNOWN_OPT;
|
2014-08-27 00:26:01 +00:00
|
|
|
break;
|
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-01-21 05:52:52 +00:00
|
|
|
if (err != NOERROR)
|
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
} else if (!strcmp("dump.f2fs", prog)) {
|
2018-04-10 03:28:19 +00:00
|
|
|
const char *option_string = "d:i:n:s:Sa:b:V";
|
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
|
|
|
static struct dump_option dump_opt = {
|
2016-06-04 10:03:56 +00:00
|
|
|
.nid = 0, /* default root ino */
|
|
|
|
.start_nat = -1,
|
|
|
|
.end_nat = -1,
|
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
|
|
|
.start_sit = -1,
|
|
|
|
.end_sit = -1,
|
|
|
|
.start_ssa = -1,
|
|
|
|
.end_ssa = -1,
|
2013-07-18 02:20:05 +00:00
|
|
|
.blk_addr = -1,
|
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
|
|
|
};
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.func = DUMP;
|
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
|
|
|
while ((option = getopt(argc, argv, option_string)) != EOF) {
|
2014-08-27 00:26:01 +00:00
|
|
|
int ret = 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
|
|
|
switch (option) {
|
2014-08-27 00:26:01 +00:00
|
|
|
case 'd':
|
2017-01-21 05:52:52 +00:00
|
|
|
if (!is_digits(optarg)) {
|
|
|
|
err = EWRONG_OPT;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv = atoi(optarg);
|
2014-08-27 00:26:01 +00:00
|
|
|
MSG(0, "Info: Debug level = %d\n",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv);
|
2014-08-27 00:26:01 +00:00
|
|
|
break;
|
2018-04-19 18:33:14 +00:00
|
|
|
case 'g':
|
|
|
|
if (!strcmp(optarg, "android")) {
|
|
|
|
c.defset = CONF_ANDROID;
|
|
|
|
MSG(0, "Info: Set conf for android\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = EWRONG_OPT;
|
|
|
|
break;
|
2014-08-27 00:26:01 +00:00
|
|
|
case 'i':
|
|
|
|
if (strncmp(optarg, "0x", 2))
|
|
|
|
ret = sscanf(optarg, "%d",
|
|
|
|
&dump_opt.nid);
|
|
|
|
else
|
|
|
|
ret = sscanf(optarg, "%x",
|
|
|
|
&dump_opt.nid);
|
|
|
|
break;
|
2016-06-04 10:03:56 +00:00
|
|
|
case 'n':
|
|
|
|
ret = sscanf(optarg, "%d~%d",
|
|
|
|
&dump_opt.start_nat,
|
|
|
|
&dump_opt.end_nat);
|
|
|
|
break;
|
2014-08-27 00:26:01 +00:00
|
|
|
case 's':
|
|
|
|
ret = sscanf(optarg, "%d~%d",
|
|
|
|
&dump_opt.start_sit,
|
|
|
|
&dump_opt.end_sit);
|
|
|
|
break;
|
2017-11-30 04:34:37 +00:00
|
|
|
case 'S':
|
|
|
|
c.sparse_mode = 1;
|
|
|
|
break;
|
2014-08-27 00:26:01 +00:00
|
|
|
case 'a':
|
|
|
|
ret = sscanf(optarg, "%d~%d",
|
|
|
|
&dump_opt.start_ssa,
|
|
|
|
&dump_opt.end_ssa);
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
if (strncmp(optarg, "0x", 2))
|
|
|
|
ret = sscanf(optarg, "%d",
|
|
|
|
&dump_opt.blk_addr);
|
|
|
|
else
|
|
|
|
ret = sscanf(optarg, "%x",
|
|
|
|
&dump_opt.blk_addr);
|
|
|
|
break;
|
2018-04-10 03:28:19 +00:00
|
|
|
case 'V':
|
|
|
|
show_version(prog);
|
|
|
|
exit(0);
|
2014-08-27 00:26:01 +00:00
|
|
|
default:
|
2017-01-21 05:52:52 +00:00
|
|
|
err = EUNKNOWN_OPT;
|
2014-08-27 00:26:01 +00:00
|
|
|
break;
|
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
|
|
|
}
|
2014-08-27 00:26:01 +00:00
|
|
|
ASSERT(ret >= 0);
|
2017-01-21 05:52:52 +00:00
|
|
|
if (err != NOERROR)
|
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.private = &dump_opt;
|
2015-10-23 18:45:36 +00:00
|
|
|
} else if (!strcmp("defrag.f2fs", prog)) {
|
2018-04-10 03:28:19 +00:00
|
|
|
const char *option_string = "d:s:Sl:t:iV";
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.func = DEFRAG;
|
2015-10-23 18:45:36 +00:00
|
|
|
while ((option = getopt(argc, argv, option_string)) != EOF) {
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case 'd':
|
2017-01-21 05:52:52 +00:00
|
|
|
if (!is_digits(optarg)) {
|
|
|
|
err = EWRONG_OPT;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv = atoi(optarg);
|
2015-10-23 18:45:36 +00:00
|
|
|
MSG(0, "Info: Debug level = %d\n",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv);
|
2015-10-23 18:45:36 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (strncmp(optarg, "0x", 2))
|
|
|
|
ret = sscanf(optarg, "%"PRIu64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.defrag_start);
|
2015-10-23 18:45:36 +00:00
|
|
|
else
|
|
|
|
ret = sscanf(optarg, "%"PRIx64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.defrag_start);
|
2015-10-23 18:45:36 +00:00
|
|
|
break;
|
2017-11-30 04:34:37 +00:00
|
|
|
case 'S':
|
|
|
|
c.sparse_mode = 1;
|
|
|
|
break;
|
2015-10-23 18:45:36 +00:00
|
|
|
case 'l':
|
|
|
|
if (strncmp(optarg, "0x", 2))
|
|
|
|
ret = sscanf(optarg, "%"PRIu64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.defrag_len);
|
2015-10-23 18:45:36 +00:00
|
|
|
else
|
|
|
|
ret = sscanf(optarg, "%"PRIx64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.defrag_len);
|
2015-10-23 18:45:36 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (strncmp(optarg, "0x", 2))
|
|
|
|
ret = sscanf(optarg, "%"PRIu64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.defrag_target);
|
2015-10-23 18:45:36 +00:00
|
|
|
else
|
|
|
|
ret = sscanf(optarg, "%"PRIx64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.defrag_target);
|
2015-10-23 18:45:36 +00:00
|
|
|
break;
|
|
|
|
case 'i':
|
2016-09-17 01:41:00 +00:00
|
|
|
c.defrag_shrink = 1;
|
2015-10-23 18:45:36 +00:00
|
|
|
break;
|
2018-04-10 03:28:19 +00:00
|
|
|
case 'V':
|
|
|
|
show_version(prog);
|
|
|
|
exit(0);
|
2015-10-23 18:45:36 +00:00
|
|
|
default:
|
2017-01-21 05:52:52 +00:00
|
|
|
err = EUNKNOWN_OPT;
|
2015-10-23 18:45:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ASSERT(ret >= 0);
|
2017-01-21 05:52:52 +00:00
|
|
|
if (err != NOERROR)
|
|
|
|
break;
|
2015-10-23 18:45:36 +00:00
|
|
|
}
|
2015-12-09 00:05:09 +00:00
|
|
|
} else if (!strcmp("resize.f2fs", prog)) {
|
2020-01-13 06:52:30 +00:00
|
|
|
const char *option_string = "d:st:iV";
|
2015-12-09 00:05:09 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.func = RESIZE;
|
2015-12-09 00:05:09 +00:00
|
|
|
while ((option = getopt(argc, argv, option_string)) != EOF) {
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case 'd':
|
2017-01-21 05:52:52 +00:00
|
|
|
if (!is_digits(optarg)) {
|
|
|
|
err = EWRONG_OPT;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv = atoi(optarg);
|
2015-12-09 00:05:09 +00:00
|
|
|
MSG(0, "Info: Debug level = %d\n",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv);
|
2015-12-09 00:05:09 +00:00
|
|
|
break;
|
2018-05-09 02:48:33 +00:00
|
|
|
case 's':
|
|
|
|
c.safe_resize = 1;
|
|
|
|
break;
|
2015-12-09 00:05:09 +00:00
|
|
|
case 't':
|
|
|
|
if (strncmp(optarg, "0x", 2))
|
|
|
|
ret = sscanf(optarg, "%"PRIu64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.target_sectors);
|
2015-12-09 00:05:09 +00:00
|
|
|
else
|
|
|
|
ret = sscanf(optarg, "%"PRIx64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
&c.target_sectors);
|
2015-12-09 00:05:09 +00:00
|
|
|
break;
|
2020-01-13 06:52:30 +00:00
|
|
|
case 'i':
|
|
|
|
c.large_nat_bitmap = 1;
|
|
|
|
break;
|
2018-04-10 03:28:19 +00:00
|
|
|
case 'V':
|
|
|
|
show_version(prog);
|
|
|
|
exit(0);
|
2015-12-09 00:05:09 +00:00
|
|
|
default:
|
2017-01-21 05:52:52 +00:00
|
|
|
err = EUNKNOWN_OPT;
|
2015-12-09 00:05:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ASSERT(ret >= 0);
|
2017-01-21 05:52:52 +00:00
|
|
|
if (err != NOERROR)
|
|
|
|
break;
|
2015-12-09 00:05:09 +00:00
|
|
|
}
|
2015-12-10 00:18:44 +00:00
|
|
|
} else if (!strcmp("sload.f2fs", prog)) {
|
2018-04-10 03:28:19 +00:00
|
|
|
const char *option_string = "C:d:f:p:s:St:T:V";
|
2017-11-30 01:21:12 +00:00
|
|
|
#ifdef HAVE_LIBSELINUX
|
|
|
|
int max_nr_opt = (int)sizeof(c.seopt_file) /
|
|
|
|
sizeof(c.seopt_file[0]);
|
|
|
|
char *token;
|
|
|
|
#endif
|
|
|
|
char *p;
|
2015-12-10 00:18:44 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.func = SLOAD;
|
2015-12-10 00:18:44 +00:00
|
|
|
while ((option = getopt(argc, argv, option_string)) != EOF) {
|
|
|
|
switch (option) {
|
2017-11-30 01:21:12 +00:00
|
|
|
case 'C':
|
|
|
|
c.fs_config_file = absolute_path(optarg);
|
|
|
|
break;
|
2015-12-10 00:18:44 +00:00
|
|
|
case 'd':
|
2017-01-21 05:52:52 +00:00
|
|
|
if (!is_digits(optarg)) {
|
|
|
|
err = EWRONG_OPT;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv = atoi(optarg);
|
2015-12-10 00:18:44 +00:00
|
|
|
MSG(0, "Info: Debug level = %d\n",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dbg_lv);
|
2015-12-10 00:18:44 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
2017-11-30 01:21:12 +00:00
|
|
|
c.from_dir = absolute_path(optarg);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
c.target_out_dir = absolute_path(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
#ifdef HAVE_LIBSELINUX
|
|
|
|
token = strtok(optarg, ",");
|
|
|
|
while (token) {
|
|
|
|
if (c.nr_opt == max_nr_opt) {
|
|
|
|
MSG(0, "\tError: Expected at most %d selinux opts\n",
|
|
|
|
max_nr_opt);
|
|
|
|
error_out(prog);
|
|
|
|
}
|
|
|
|
c.seopt_file[c.nr_opt].type =
|
|
|
|
SELABEL_OPT_PATH;
|
|
|
|
c.seopt_file[c.nr_opt].value =
|
|
|
|
absolute_path(token);
|
|
|
|
c.nr_opt++;
|
|
|
|
token = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MSG(0, "Info: Not support selinux opts\n");
|
|
|
|
#endif
|
2015-12-10 00:18:44 +00:00
|
|
|
break;
|
2017-11-30 04:34:37 +00:00
|
|
|
case 'S':
|
|
|
|
c.sparse_mode = 1;
|
|
|
|
break;
|
2015-12-10 00:18:44 +00:00
|
|
|
case 't':
|
2016-09-17 01:41:00 +00:00
|
|
|
c.mount_point = (char *)optarg;
|
2015-12-10 00:18:44 +00:00
|
|
|
break;
|
2017-11-30 01:21:12 +00:00
|
|
|
case 'T':
|
|
|
|
c.fixed_time = strtoul(optarg, &p, 0);
|
|
|
|
break;
|
2018-04-10 03:28:19 +00:00
|
|
|
case 'V':
|
|
|
|
show_version(prog);
|
|
|
|
exit(0);
|
2015-12-10 00:18:44 +00:00
|
|
|
default:
|
2017-01-21 05:52:52 +00:00
|
|
|
err = EUNKNOWN_OPT;
|
2015-12-10 00:18:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-21 05:52:52 +00:00
|
|
|
if (err != NOERROR)
|
|
|
|
break;
|
2015-12-10 00:18:44 +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
|
|
|
}
|
2017-03-17 13:55:50 +00:00
|
|
|
|
2018-04-19 18:33:14 +00:00
|
|
|
add_default_options();
|
|
|
|
|
2017-03-17 13:55:50 +00:00
|
|
|
if (optind >= argc) {
|
|
|
|
MSG(0, "\tError: Device not specified\n");
|
|
|
|
error_out(prog);
|
|
|
|
}
|
|
|
|
|
|
|
|
c.devices[0].path = strdup(argv[optind]);
|
|
|
|
if (argc > (optind + 1)) {
|
2017-01-21 05:52:52 +00:00
|
|
|
c.dbg_lv = 0;
|
|
|
|
err = EUNKNOWN_ARG;
|
|
|
|
}
|
|
|
|
if (err == NOERROR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* print out error */
|
|
|
|
switch (err) {
|
|
|
|
case EWRONG_OPT:
|
|
|
|
MSG(0, "\tError: Wrong option -%c %s\n", option, optarg);
|
|
|
|
break;
|
|
|
|
case ENEED_ARG:
|
|
|
|
MSG(0, "\tError: Need argument for -%c\n", option);
|
|
|
|
break;
|
|
|
|
case EUNKNOWN_OPT:
|
|
|
|
MSG(0, "\tError: Unknown option %c\n", option);
|
|
|
|
break;
|
|
|
|
case EUNKNOWN_ARG:
|
|
|
|
MSG(0, "\tError: Unknown argument %s\n", argv[optind]);
|
|
|
|
break;
|
|
|
|
}
|
2017-02-11 00:12:33 +00:00
|
|
|
error_out(prog);
|
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
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
static void do_fsck(struct f2fs_sb_info *sbi)
|
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
|
|
|
{
|
2015-03-20 23:57:47 +00:00
|
|
|
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
|
|
|
u32 flag = le32_to_cpu(ckpt->ckpt_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
|
|
|
u32 blk_cnt;
|
2017-10-30 23:21:09 +00:00
|
|
|
errcode_t ret;
|
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
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
fsck_init(sbi);
|
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
|
|
|
|
2015-03-20 23:57:47 +00:00
|
|
|
print_cp_state(flag);
|
|
|
|
|
fsck: Check write pointer consistency of open zones
On sudden f2fs shutdown, write pointers of zoned block devices can go
further but f2fs meta data keeps current segments at positions before the
write operations. After remounting the f2fs, this inconsistency causes
write operations not at write pointers and "Unaligned write command"
error is reported.
To avoid the error, have f2fs.fsck check consistency of write pointers
of open zones that current segments point to. Compare each current
segment's position and the write pointer position of the open zone. If
inconsistency is found and 'fix_on' flag is set, assign a new zone to the
current segment and check the newly assigned zone has write pointer at
the zone start. Leave the original zone as is to keep data recorded in
it.
To care about fsync data, refer each seg_entry's ckpt_valid_map to get
the last valid block in the zone. If the last valid block is beyond the
current segments position, fsync data exits in the zone. In case fsync
data exists, do not assign a new zone to the current segment not to lose
the fsync data. It is expected that the kernel replay the fsync data and
fix the write pointer inconsistency at mount time.
Also check consistency between write pointer of the zone the current
segment points to with valid block maps of the zone. If the last valid
block is beyond the write pointer position, report to indicate a bug. If
'fix_on' flag is set, assign a new zone to the current segment.
When inconsistencies are found, turn on 'bug_on' flag in fsck_verify() to
ask users to fix them or not. When inconsistencies get fixed, turn on
'force' flag in fsck_verify() to enforce fixes in following checks.
This check and fix is done twice. The first is done at the beginning of
do_fsck() function so that other fixes can reflect the current segment
modification. The second is done in fsck_verify() to reflect updated meta
data by other fixes.
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-11-28 07:59:29 +00:00
|
|
|
fsck_chk_and_fix_write_pointers(sbi);
|
|
|
|
|
2018-06-20 11:12:13 +00:00
|
|
|
fsck_chk_curseg_info(sbi);
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on && !c.bug_on) {
|
|
|
|
switch (c.preen_mode) {
|
2016-03-14 06:16:53 +00:00
|
|
|
case PREEN_MODE_1:
|
|
|
|
if (fsck_chk_meta(sbi)) {
|
|
|
|
MSG(0, "[FSCK] F2FS metadata [Fail]");
|
|
|
|
MSG(0, "\tError: meta does not match, "
|
|
|
|
"force check all\n");
|
|
|
|
} else {
|
|
|
|
MSG(0, "[FSCK] F2FS metadata [Ok..]");
|
|
|
|
fsck_free(sbi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.ro)
|
|
|
|
c.fix_on = 1;
|
2016-03-14 06:16:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-11-02 03:56:04 +00:00
|
|
|
} else if (c.preen_mode) {
|
|
|
|
/*
|
2016-03-14 06:16:59 +00:00
|
|
|
* we can hit this in 3 situations:
|
|
|
|
* 1. fsck -f, fix_on has already been set to 1 when
|
|
|
|
* parsing options;
|
|
|
|
* 2. fsck -a && CP_FSCK_FLAG is set, fix_on has already
|
|
|
|
* been set to 1 when checking CP_FSCK_FLAG;
|
|
|
|
* 3. fsck -p 1 && error is detected, then bug_on is set,
|
|
|
|
* we set fix_on = 1 here, so that fsck can fix errors
|
|
|
|
* automatically
|
|
|
|
*/
|
2016-09-17 01:41:00 +00:00
|
|
|
c.fix_on = 1;
|
2016-03-14 06:16:53 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
fsck_chk_checkpoint(sbi);
|
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
fsck_chk_quota_node(sbi);
|
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
|
|
|
|
2014-08-27 00:26:01 +00:00
|
|
|
/* Traverse all block recursively from root inode */
|
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
|
|
|
blk_cnt = 1;
|
2017-10-30 23:21:09 +00:00
|
|
|
|
|
|
|
if (c.feature & cpu_to_le32(F2FS_FEATURE_QUOTA_INO)) {
|
|
|
|
ret = quota_init_context(sbi);
|
|
|
|
if (ret) {
|
|
|
|
ASSERT_MSG("quota_init_context failure: %d", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fsck_chk_orphan_node(sbi);
|
2017-06-05 20:44:50 +00:00
|
|
|
fsck_chk_node_blk(sbi, NULL, sbi->root_ino_num,
|
2016-03-16 03:07:07 +00:00
|
|
|
F2FS_FT_DIR, TYPE_INODE, &blk_cnt, NULL);
|
2017-10-30 23:21:09 +00:00
|
|
|
fsck_chk_quota_files(sbi);
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
fsck_verify(sbi);
|
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_free(sbi);
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
static void do_dump(struct f2fs_sb_info *sbi)
|
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
|
|
|
{
|
2016-09-17 01:41:00 +00:00
|
|
|
struct dump_option *opt = (struct dump_option *)c.private;
|
2015-01-15 00:18:15 +00:00
|
|
|
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
|
|
|
u32 flag = le32_to_cpu(ckpt->ckpt_flags);
|
2013-07-18 02:20:05 +00:00
|
|
|
|
2016-06-04 10:03:56 +00:00
|
|
|
if (opt->end_nat == -1)
|
|
|
|
opt->end_nat = NM_I(sbi)->max_nid;
|
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
|
|
|
if (opt->end_sit == -1)
|
|
|
|
opt->end_sit = SM_I(sbi)->main_segments;
|
|
|
|
if (opt->end_ssa == -1)
|
|
|
|
opt->end_ssa = SM_I(sbi)->main_segments;
|
2016-06-04 10:03:56 +00:00
|
|
|
if (opt->start_nat != -1)
|
2018-07-02 09:22:41 +00:00
|
|
|
nat_dump(sbi, opt->start_nat, opt->end_nat);
|
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
|
|
|
if (opt->start_sit != -1)
|
|
|
|
sit_dump(sbi, opt->start_sit, opt->end_sit);
|
|
|
|
if (opt->start_ssa != -1)
|
|
|
|
ssa_dump(sbi, opt->start_ssa, opt->end_ssa);
|
2016-06-04 10:03:56 +00:00
|
|
|
if (opt->blk_addr != -1)
|
2014-12-13 21:55:59 +00:00
|
|
|
dump_info_from_blkaddr(sbi, opt->blk_addr);
|
2016-06-04 10:03:56 +00:00
|
|
|
if (opt->nid)
|
2016-10-13 23:04:52 +00:00
|
|
|
dump_node(sbi, opt->nid, 0);
|
2015-01-15 00:18:15 +00:00
|
|
|
|
2015-03-20 23:57:47 +00:00
|
|
|
print_cp_state(flag);
|
2015-01-15 00:18:15 +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
|
|
|
}
|
|
|
|
|
2015-10-23 18:45:36 +00:00
|
|
|
static int do_defrag(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_start > get_sb(block_count))
|
2015-10-23 18:45:36 +00:00
|
|
|
goto out_range;
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_start < SM_I(sbi)->main_blkaddr)
|
|
|
|
c.defrag_start = SM_I(sbi)->main_blkaddr;
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_len == 0)
|
|
|
|
c.defrag_len = sbi->blocks_per_seg;
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_start + c.defrag_len > get_sb(block_count))
|
|
|
|
c.defrag_len = get_sb(block_count) - c.defrag_start;
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_target == 0) {
|
|
|
|
c.defrag_target = c.defrag_start - 1;
|
|
|
|
if (!c.defrag_shrink)
|
|
|
|
c.defrag_target += c.defrag_len + 1;
|
2015-10-23 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_target < SM_I(sbi)->main_blkaddr ||
|
|
|
|
c.defrag_target > get_sb(block_count))
|
2015-10-23 18:45:36 +00:00
|
|
|
goto out_range;
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_target >= c.defrag_start &&
|
|
|
|
c.defrag_target < c.defrag_start + c.defrag_len)
|
2015-10-23 18:45:36 +00:00
|
|
|
goto out_range;
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.defrag_start > c.defrag_target)
|
2015-10-23 18:45:36 +00:00
|
|
|
MSG(0, "Info: Move 0x%"PRIx64" <- [0x%"PRIx64"-0x%"PRIx64"]\n",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.defrag_target,
|
|
|
|
c.defrag_start,
|
|
|
|
c.defrag_start + c.defrag_len - 1);
|
2015-10-23 18:45:36 +00:00
|
|
|
else
|
|
|
|
MSG(0, "Info: Move [0x%"PRIx64"-0x%"PRIx64"] -> 0x%"PRIx64"\n",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.defrag_start,
|
|
|
|
c.defrag_start + c.defrag_len - 1,
|
|
|
|
c.defrag_target);
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
return f2fs_defragment(sbi, c.defrag_start, c.defrag_len,
|
|
|
|
c.defrag_target, c.defrag_shrink);
|
2015-10-23 18:45:36 +00:00
|
|
|
out_range:
|
|
|
|
ASSERT_MSG("Out-of-range [0x%"PRIx64" ~ 0x%"PRIx64"] to 0x%"PRIx64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.defrag_start,
|
|
|
|
c.defrag_start + c.defrag_len - 1,
|
|
|
|
c.defrag_target);
|
2015-10-23 18:45:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:05:09 +00:00
|
|
|
static int do_resize(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.target_sectors)
|
|
|
|
c.target_sectors = c.total_sectors;
|
2015-12-09 00:05:09 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.target_sectors > c.total_sectors) {
|
2015-12-09 00:05:09 +00:00
|
|
|
ASSERT_MSG("Out-of-range Target=0x%"PRIx64" / 0x%"PRIx64"",
|
2016-09-17 01:41:00 +00:00
|
|
|
c.target_sectors, c.total_sectors);
|
2015-12-09 00:05:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return f2fs_resize(sbi);
|
|
|
|
}
|
|
|
|
|
2015-12-10 00:18:44 +00:00
|
|
|
static int do_sload(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.from_dir) {
|
2017-11-30 01:21:12 +00:00
|
|
|
MSG(0, "Info: No source directory, but it's okay.\n");
|
|
|
|
return 0;
|
2015-12-10 00:18:44 +00:00
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.mount_point)
|
|
|
|
c.mount_point = "/";
|
2015-12-10 00:18:44 +00:00
|
|
|
|
2017-11-30 01:21:12 +00:00
|
|
|
return f2fs_sload(sbi);
|
2015-12-10 00:18:44 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 20:24:38 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
static u64 get_boottime_ns()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_MACH_TIME_H
|
|
|
|
return mach_absolute_time();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static u64 get_boottime_ns()
|
|
|
|
{
|
2020-03-09 19:54:27 +00:00
|
|
|
struct timespec t;
|
|
|
|
t.tv_sec = t.tv_nsec = 0;
|
|
|
|
clock_gettime(CLOCK_BOOTTIME, &t);
|
|
|
|
return (u64)t.tv_sec * 1000000000LL + t.tv_nsec;
|
|
|
|
}
|
2020-04-01 20:24:38 +00:00
|
|
|
#endif
|
2020-03-09 19:54:27 +00:00
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
int main(int argc, char **argv)
|
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
|
|
|
{
|
2014-08-27 00:26:01 +00:00
|
|
|
struct f2fs_sb_info *sbi;
|
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 ret = 0;
|
2020-03-09 19:54:27 +00:00
|
|
|
u64 start = get_boottime_ns();
|
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
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
f2fs_init_configuration();
|
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
|
|
|
|
|
|
|
f2fs_parse_options(argc, argv);
|
|
|
|
|
2018-09-30 08:26:13 +00:00
|
|
|
if (c.func != DUMP && f2fs_devs_are_umounted() < 0) {
|
2019-10-31 13:57:59 +00:00
|
|
|
if (errno == EBUSY) {
|
|
|
|
ret = -1;
|
|
|
|
goto quick_err;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.ro || c.func == DEFRAG) {
|
2015-11-22 02:53:07 +00:00
|
|
|
MSG(0, "\tError: Not available on mounted device!\n");
|
2019-10-31 13:57:59 +00:00
|
|
|
ret = -1;
|
|
|
|
goto quick_err;
|
2015-11-22 02:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allow ro-mounted partition */
|
2019-04-23 02:42:20 +00:00
|
|
|
if (c.force) {
|
|
|
|
MSG(0, "Info: Force to check/repair FS on RO mounted device\n");
|
|
|
|
} else {
|
|
|
|
MSG(0, "Info: Check FS only on RO mounted device\n");
|
|
|
|
c.fix_on = 0;
|
|
|
|
c.auto_fix = 0;
|
|
|
|
}
|
2015-11-22 02:53:07 +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
|
|
|
|
|
|
|
/* Get device */
|
2019-10-31 13:57:59 +00:00
|
|
|
if (f2fs_get_device_info() < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto quick_err;
|
|
|
|
}
|
2017-11-30 04:34:37 +00:00
|
|
|
|
2014-08-27 00:26:01 +00:00
|
|
|
fsck_again:
|
|
|
|
memset(&gfsck, 0, sizeof(gfsck));
|
|
|
|
gfsck.sbi.fsck = &gfsck;
|
|
|
|
sbi = &gfsck.sbi;
|
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
|
|
|
|
2014-09-03 01:07:35 +00:00
|
|
|
ret = f2fs_do_mount(sbi);
|
2016-01-15 04:44:13 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
if (ret == 1) {
|
|
|
|
MSG(0, "Info: No error was reported\n");
|
|
|
|
ret = 0;
|
|
|
|
}
|
2015-10-23 18:45:36 +00:00
|
|
|
goto out_err;
|
2016-01-15 04:44:13 +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
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
switch (c.func) {
|
2014-08-27 00:26:01 +00:00
|
|
|
case FSCK:
|
2014-08-28 00:06:17 +00:00
|
|
|
do_fsck(sbi);
|
2014-08-27 00:26:01 +00:00
|
|
|
break;
|
2017-11-30 01:15:18 +00:00
|
|
|
#ifdef WITH_DUMP
|
2014-08-27 00:26:01 +00:00
|
|
|
case DUMP:
|
2014-08-28 00:06:17 +00:00
|
|
|
do_dump(sbi);
|
2014-08-27 00:26:01 +00:00
|
|
|
break;
|
2017-11-30 01:15:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_DEFRAG
|
2015-10-23 18:45:36 +00:00
|
|
|
case DEFRAG:
|
2016-01-15 04:44:13 +00:00
|
|
|
ret = do_defrag(sbi);
|
|
|
|
if (ret)
|
2015-10-23 18:45:36 +00:00
|
|
|
goto out_err;
|
|
|
|
break;
|
2017-11-30 01:15:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_RESIZE
|
2015-12-09 00:05:09 +00:00
|
|
|
case RESIZE:
|
|
|
|
if (do_resize(sbi))
|
|
|
|
goto out_err;
|
|
|
|
break;
|
2017-11-30 01:15:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_SLOAD
|
2015-12-10 00:18:44 +00:00
|
|
|
case SLOAD:
|
2017-11-30 01:21:12 +00:00
|
|
|
if (do_sload(sbi))
|
|
|
|
goto out_err;
|
|
|
|
|
2019-05-06 08:58:06 +00:00
|
|
|
ret = f2fs_sparse_initialize_meta(sbi);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_err;
|
|
|
|
|
2017-11-30 01:21:12 +00:00
|
|
|
f2fs_do_umount(sbi);
|
|
|
|
|
|
|
|
/* fsck to fix missing quota */
|
|
|
|
c.func = FSCK;
|
|
|
|
c.fix_on = 1;
|
|
|
|
goto fsck_again;
|
2016-10-12 21:42:16 +00:00
|
|
|
#endif
|
2017-11-30 01:15:18 +00:00
|
|
|
default:
|
|
|
|
ERR_MSG("Wrong program name\n");
|
|
|
|
ASSERT(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-07-18 02:20:05 +00:00
|
|
|
f2fs_do_umount(sbi);
|
2015-10-23 18:45:36 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.func == FSCK && c.bug_on) {
|
2019-01-04 21:02:22 +00:00
|
|
|
if (!c.ro && c.fix_on == 0 && c.auto_fix == 0 && !c.dry_run) {
|
2014-08-27 00:26:01 +00:00
|
|
|
char ans[255] = {0};
|
|
|
|
retry:
|
|
|
|
printf("Do you want to fix this partition? [Y/N] ");
|
|
|
|
ret = scanf("%s", ans);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
if (!strcasecmp(ans, "y"))
|
2016-09-17 01:41:00 +00:00
|
|
|
c.fix_on = 1;
|
2014-08-27 00:26:01 +00:00
|
|
|
else if (!strcasecmp(ans, "n"))
|
2016-09-17 01:41:00 +00:00
|
|
|
c.fix_on = 0;
|
2014-08-27 00:26:01 +00:00
|
|
|
else
|
|
|
|
goto retry;
|
2014-09-04 02:41:44 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on)
|
2014-09-04 02:41:44 +00:00
|
|
|
goto fsck_again;
|
2014-08-27 00:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-24 09:33:39 +00:00
|
|
|
ret = f2fs_finalize_device();
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2014-06-13 07:51:32 +00:00
|
|
|
|
2020-03-09 19:54:27 +00:00
|
|
|
printf("\nDone: %lf secs\n", (get_boottime_ns() - start) / 1000000000.0);
|
2014-08-28 00:06:17 +00:00
|
|
|
return 0;
|
2015-10-23 18:45:36 +00:00
|
|
|
|
|
|
|
out_err:
|
|
|
|
if (sbi->ckpt)
|
|
|
|
free(sbi->ckpt);
|
|
|
|
if (sbi->raw_super)
|
|
|
|
free(sbi->raw_super);
|
2019-10-31 13:57:59 +00:00
|
|
|
quick_err:
|
|
|
|
f2fs_release_sparse_resource();
|
2016-01-15 04:44:13 +00:00
|
|
|
return ret;
|
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
|
|
|
}
|