third_party_f2fs-tools/fsck/main.c

1266 lines
30 KiB
C
Raw Normal View History

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/
* Copyright (c) 2015 Jaegeuk Kim <jaegeuk@kernel.org>
* : implement defrag.f2fs
* Copyright (C) 2015 Huawei Ltd.
* Hou Pengyang <houpengyang@huawei.com>
* Liu Shuoran <liushuoran@huawei.com>
* Jaegeuk Kim <jaegeuk@kernel.org>
* : add sload.f2fs
* Copyright (c) 2019 Google Inc.
* Robin Hsu <robinhsu@google.com>
* : add cache layer
* Copyright (c) 2020 Google Inc.
* Robin Hsu <robinhsu@google.com>
* : add sload compression support
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>
#include <ctype.h>
#include <time.h>
#include <getopt.h>
#include <stdbool.h>
#include "quotaio.h"
#include "compress.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
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
INIT_FEATURE_TABLE;
#ifdef WITH_SLOAD
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;
}
#endif
f2fs-tools: add fsck.f2fs and dump.f2fs fsck.f2fs checks file system consistency, but does not repair a broken file system yet. dump.f2fs shows the information of a specific inode and makes dump file of SSA and SIT. f2fs checks file system consistency as follows: o When data about used area and its metadata are identical, f2fs is considered consistent. To verify such consistency, we use three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap. First, each bit in nat_area_bitmap corresponds to a nid in NAT. Second, each bit in sit_area_bitmap corresponds to a valid block in a segment. This bitmap is same to the total valid_map of f2fs_sit_entries in SIT. Last, each bit in main_area_bitmap corresponds to a block in main area except meta area. After a consistency check of each block, we set or clear the corresponding bit of each bitmap. From the root node, we start consistency check. The verified information varies according to block type. 1. NODE - Read information of node block from NAT - Check if block address is allocated using node info. - Check if the type of f2fs_summary related to nid in SSA is NODE. - Update the corresponding bit in nat_area_bitmap. - Update the corresponding bit in sit_area_bitmap. - Set the corresponding bit in main_area_bitmap to 1. - Then, read node block. According to its attribute, explore inode/direct node/indirect node/double indirect node recursively. - If it is an inode block, we also check its xattr and hard link. 2. DATA - Check if the type of f2fs_summary related to nid in SSA is DATA. - Set the corresponding bits of sit_area_bitmap and main_area_bitmap to visited - If it is a dentry block, traverse each dentries that may be regular file or directory. At this time, it will check inode block again. Finally, we verify whether - every nat_area_bitmap is visited - any unreachable hard link exists - values of sit_area_bitmap and main_area_bitmap are identical - total_valid_block_count/node_count/inode_count are correct Usage: o fsck.f2fs # fsck.f2fs /dev/sdx options: -d debug level [default:0] o dump.f2fs # dump.f2fs -i [ino] /dev/sdx # dump.f2fs -s 0~-1 /dev/sdx (SIT dump) # dump.f2fs -a 0~-1 /dev/sdx (SSA dump) options: -d debug level [default:0] -i inode no (hex) -s [SIT dump segno from #1~#2 (decimal), for all 0~-1] -a [SSA dump segno from #1~#2 (decimal), for all 0~-1] Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs dump.f2fs Signed-off-by: Changman Lee <cm224.lee@samsung.com> Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
void fsck_usage()
{
MSG(0, "\nUsage: fsck.f2fs [options] device\n");
MSG(0, "[options]:\n");
MSG(0, " -a check/fix potential corruption, reported by f2fs\n");
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");
MSG(0, " -f check/fix entire partition\n");
MSG(0, " -g add default options\n");
MSG(0, " -l show superblock/checkpoint\n");
MSG(0, " -M show a file map\n");
MSG(0, " -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
MSG(0, " -p preen mode [default:0 the same as -a [0|1|2]]\n");
MSG(0, " -S sparse_mode\n");
MSG(0, " -t show directory tree\n");
MSG(0, " -q preserve quota limits\n");
MSG(0, " -y fix all the time\n");
MSG(0, " -V print the version number and exit\n");
MSG(0, " --dry-run do not really fix corruptions\n");
MSG(0, " --no-kernel-check skips detecting kernel change\n");
MSG(0, " --kernel-check checks kernel change\n");
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");
MSG(0, " -I inode no (hex) scan full disk\n");
MSG(0, " -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n");
MSG(0, " -M show a block map\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");
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");
MSG(0, " -b blk_addr (in 4KB)\n");
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);
}
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");
MSG(0, " -S sparse_mode\n");
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");
MSG(0, " -V print the version number and exit\n");
exit(1);
}
void resize_usage()
{
MSG(0, "\nUsage: resize.f2fs [options] device\n");
MSG(0, "[options]:\n");
MSG(0, " -d debug level [default:0]\n");
MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n");
MSG(0, " -o overprovision percentage [default:auto]\n");
MSG(0, " -s safe resize (Does not resize metadata)\n");
MSG(0, " -t target sectors [default: device size]\n");
MSG(0, " -O feature1[,feature2,...] e.g. \"fsprojquota,fscasefold\"\n");
MSG(0, " -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
MSG(0, " -V print the version number and exit\n");
exit(1);
}
void sload_usage()
{
MSG(0, "\nUsage: sload.f2fs [options] device\n");
MSG(0, "[options]:\n");
MSG(0, " -C fs_config\n");
MSG(0, " -f source directory [path of the source directory]\n");
MSG(0, " -p product out directory\n");
MSG(0, " -s file_contexts\n");
MSG(0, " -S sparse_mode\n");
MSG(0, " -t mount point [prefix of target fs path, default:/]\n");
MSG(0, " -T timestamp\n");
MSG(0, " -P preserve owner: user and group\n");
MSG(0, " -c enable compression (default allow policy)\n");
MSG(0, " ------------ Compression sub-options -----------------\n");
MSG(0, " -L <log-of-blocks-per-cluster>, default 2\n");
MSG(0, " -a <algorithm> compression algorithm, default LZ4\n");
MSG(0, " -x <ext> compress files except for these extensions.\n");
MSG(0, " -i <ext> compress files with these extensions only.\n");
MSG(0, " * -i or -x: use it many times for multiple extensions.\n");
MSG(0, " * -i and -x cannot be used together..\n");
MSG(0, " -m <num> min compressed blocks per cluster\n");
MSG(0, " -r read only (to release unused blocks) for compressed "
"files\n");
MSG(0, " ------------------------------------------------------\n");
MSG(0, " -d debug level [default:0]\n");
MSG(0, " -V print the version number and exit\n");
exit(1);
}
void label_usage()
{
MSG(0, "\nUsage: f2fslabel [options] device [volume-label]\n");
MSG(0, "[options]:\n");
MSG(0, " -V print the version number and exit\n");
exit(1);
}
static int is_digits(char *optarg)
{
unsigned int i;
for (i = 0; i < strlen(optarg); i++)
if (!isdigit(optarg[i]))
break;
return i == strlen(optarg);
}
static void error_out(char *prog)
{
if (!strcmp("fsck.f2fs", prog))
fsck_usage();
else if (!strcmp("dump.f2fs", prog))
dump_usage();
else if (!strcmp("defrag.f2fs", prog))
defrag_usage();
else if (!strcmp("resize.f2fs", prog))
resize_usage();
else if (!strcmp("sload.f2fs", prog))
sload_usage();
else if (!strcmp("f2fslabel", prog))
label_usage();
else
MSG(0, "\nWrong program.\n");
}
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();
}
c.quota_fix = 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
void f2fs_parse_options(int argc, char *argv[])
{
int option = 0;
char *prog = basename(argv[0]);
int err = NOERROR;
#ifdef WITH_ANDROID
int i;
/* Allow prog names (e.g, sload_f2fs, fsck_f2fs, etc) */
for (i = 0; i < strlen(prog); i++) {
if (prog[i] == '_')
prog[i] = '.';
}
#endif
if (argc < 2) {
MSG(0, "\tError: Device not specified\n");
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
if (!strcmp("fsck.f2fs", prog)) {
const char *option_string = ":aC:c:m:Md:fg:lO:p:q:StyV";
int opt = 0, val;
char *token;
struct option long_opt[] = {
{"dry-run", no_argument, 0, 1},
{"no-kernel-check", no_argument, 0, 2},
{"kernel-check", no_argument, 0, 3},
{"debug-cache", no_argument, 0, 4},
{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
c.func = FSCK;
c.cache_config.max_hash_collision = 16;
c.cache_config.dbg_en = false;
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) {
case 1:
c.dry_run = 1;
MSG(0, "Info: Dry run\n");
break;
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;
case 4:
c.cache_config.dbg_en = true;
break;
case 'a':
c.auto_fix = 1;
MSG(0, "Info: Fix the reported corruption.\n");
break;
case 'c':
c.cache_config.num_cache_entry = atoi(optarg);
break;
case 'm':
c.cache_config.max_hash_collision =
atoi(optarg);
break;
case 'g':
if (!strcmp(optarg, "android")) {
c.defset = CONF_ANDROID;
MSG(0, "Info: Set conf for android\n");
}
break;
case 'l':
c.layout = 1;
break;
case 'M':
c.show_file_map = 1;
break;
case 'O':
if (parse_feature(feature_table, optarg))
fsck_usage();
break;
case 'p':
/* preen mode has different levels:
* 0: default level, the same as -a
* 1: check meta
* 2: same as 0, but will skip some
* check for old kernel
*/
if (optarg[0] == '-' || !is_digits(optarg) ||
optind == argc) {
MSG(0, "Info: Use default preen mode\n");
c.preen_mode = PREEN_MODE_0;
c.auto_fix = 1;
optind--;
break;
}
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;
if (c.preen_mode == PREEN_MODE_0 ||
c.preen_mode == PREEN_MODE_2)
c.auto_fix = 1;
MSG(0, "Info: Fix the reported corruption in "
"preen mode %d\n", c.preen_mode);
break;
case 'd':
if (optarg[0] == '-') {
err = ENEED_ARG;
break;
} else if (!is_digits(optarg)) {
err = EWRONG_OPT;
break;
}
c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n", c.dbg_lv);
break;
case 'f':
case 'y':
c.fix_on = 1;
c.force = 1;
MSG(0, "Info: Force to fix corruption\n");
break;
case 'q':
c.preserve_limits = atoi(optarg);
MSG(0, "Info: Preserve quota limits = %d\n",
c.preserve_limits);
break;
case 'S':
c.sparse_mode = 1;
break;
case 't':
c.show_dentry = 1;
break;
case ':':
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;
}
break;
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;
case 'V':
show_version(prog);
exit(0);
case '?':
option = optopt;
fallthrough;
default:
err = EUNKNOWN_OPT;
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
}
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)) {
#ifdef WITH_DUMP
const char *option_string = "d:i:I:n:Ms: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 = {
.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,
.blk_addr = -1,
.scan_nid = 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
};
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) {
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) {
case 'd':
if (!is_digits(optarg)) {
err = EWRONG_OPT;
break;
}
c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
c.dbg_lv);
break;
case 'i':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%d",
&dump_opt.nid);
else
ret = sscanf(optarg, "%x",
&dump_opt.nid);
break;
case 'I':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%d",
&dump_opt.scan_nid);
else
ret = sscanf(optarg, "%x",
&dump_opt.scan_nid);
break;
case 'n':
ret = sscanf(optarg, "%d~%d",
&dump_opt.start_nat,
&dump_opt.end_nat);
break;
case 'M':
c.show_file_map = 1;
break;
case 's':
ret = sscanf(optarg, "%d~%d",
&dump_opt.start_sit,
&dump_opt.end_sit);
break;
case 'S':
c.sparse_mode = 1;
break;
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;
case 'V':
show_version(prog);
exit(0);
default:
err = EUNKNOWN_OPT;
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
}
ASSERT(ret >= 0);
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
}
c.private = &dump_opt;
#endif
} else if (!strcmp("defrag.f2fs", prog)) {
#ifdef WITH_DEFRAG
const char *option_string = "d:s:Sl:t:iV";
c.func = DEFRAG;
while ((option = getopt(argc, argv, option_string)) != EOF) {
int ret = 0;
switch (option) {
case 'd':
if (!is_digits(optarg)) {
err = EWRONG_OPT;
break;
}
c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
c.dbg_lv);
break;
case 's':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
&c.defrag_start);
else
ret = sscanf(optarg, "%"PRIx64"",
&c.defrag_start);
break;
case 'S':
c.sparse_mode = 1;
break;
case 'l':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
&c.defrag_len);
else
ret = sscanf(optarg, "%"PRIx64"",
&c.defrag_len);
break;
case 't':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
&c.defrag_target);
else
ret = sscanf(optarg, "%"PRIx64"",
&c.defrag_target);
break;
case 'i':
c.defrag_shrink = 1;
break;
case 'V':
show_version(prog);
exit(0);
default:
err = EUNKNOWN_OPT;
break;
}
ASSERT(ret >= 0);
if (err != NOERROR)
break;
}
#endif
} else if (!strcmp("resize.f2fs", prog)) {
#ifdef WITH_RESIZE
const char *option_string = "d:fst:O:C:io:V";
int val;
char *token;
c.func = RESIZE;
while ((option = getopt(argc, argv, option_string)) != EOF) {
int ret = 0;
switch (option) {
case 'd':
if (!is_digits(optarg)) {
err = EWRONG_OPT;
break;
}
c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
c.dbg_lv);
break;
case 'f':
c.force = 1;
MSG(0, "Info: Force to resize\n");
break;
case 's':
c.safe_resize = 1;
break;
case 't':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%"PRIu64"",
&c.target_sectors);
else
ret = sscanf(optarg, "%"PRIx64"",
&c.target_sectors);
break;
case 'i':
c.large_nat_bitmap = 1;
break;
case 'O':
if (parse_feature(feature_table, optarg))
resize_usage();
break;
case 'C':
token = strtok(optarg, ":");
val = f2fs_str2encoding(token);
if (val < 0) {
MSG(0, "\tError: Unknown encoding %s\n", token);
}
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);
}
c.feature |= cpu_to_le32(F2FS_FEATURE_CASEFOLD);
case 'o':
c.new_overprovision = atof(optarg);
break;
case 'V':
show_version(prog);
exit(0);
default:
err = EUNKNOWN_OPT;
break;
}
ASSERT(ret >= 0);
if (err != NOERROR)
break;
}
#endif
} else if (!strcmp("sload.f2fs", prog)) {
#ifdef WITH_SLOAD
const char *option_string = "cL:a:i:x:m:rC:d:f:p:s:St:T:VP";
#ifdef HAVE_LIBSELINUX
int max_nr_opt = (int)sizeof(c.seopt_file) /
sizeof(c.seopt_file[0]);
char *token;
#endif
char *p;
c.func = SLOAD;
c.compress.cc.log_cluster_size = 2;
c.compress.alg = COMPR_LZ4;
c.compress.min_blocks = 1;
c.compress.filter_ops = &ext_filter;
while ((option = getopt(argc, argv, option_string)) != EOF) {
unsigned int i;
int val;
switch (option) {
case 'c': /* compression support */
c.compress.enabled = true;
break;
case 'L': /* compression: log of blocks-per-cluster */
c.compress.required = true;
val = atoi(optarg);
if (val < MIN_COMPRESS_LOG_SIZE ||
val > MAX_COMPRESS_LOG_SIZE) {
MSG(0, "\tError: log of blocks per"
" cluster must be in the range"
" of %d .. %d.\n",
MIN_COMPRESS_LOG_SIZE,
MAX_COMPRESS_LOG_SIZE);
error_out(prog);
}
c.compress.cc.log_cluster_size = val;
break;
case 'a': /* compression: choose algorithm */
c.compress.required = true;
c.compress.alg = MAX_COMPRESS_ALGS;
for (i = 0; i < MAX_COMPRESS_ALGS; i++) {
if (!strcmp(supported_comp_names[i],
optarg)) {
c.compress.alg = i;
break;
}
}
if (c.compress.alg == MAX_COMPRESS_ALGS) {
MSG(0, "\tError: Unknown compression"
" algorithm %s\n", optarg);
error_out(prog);
}
break;
case 'i': /* compress only these extensions */
c.compress.required = true;
if (c.compress.filter == COMPR_FILTER_ALLOW) {
MSG(0, "\tError: could not mix option"
" -i and -x\n");
error_out(prog);
}
c.compress.filter = COMPR_FILTER_DENY;
c.compress.filter_ops->add(optarg);
break;
case 'x': /* compress except for these extensions */
c.compress.required = true;
if (c.compress.filter == COMPR_FILTER_DENY) {
MSG(0, "\tError: could not mix option"
" -i and -x\n");
error_out(prog);
}
c.compress.filter = COMPR_FILTER_ALLOW;
c.compress.filter_ops->add(optarg);
break;
case 'm': /* minimum compressed blocks per cluster */
c.compress.required = true;
val = atoi(optarg);
if (val <= 0) {
MSG(0, "\tError: minimum compressed"
" blocks per cluster must be"
" positive.\n");
error_out(prog);
}
c.compress.min_blocks = val;
break;
case 'r': /* for setting FI_COMPRESS_RELEASED */
c.compress.required = true;
c.compress.readonly = true;
break;
case 'C':
c.fs_config_file = absolute_path(optarg);
break;
case 'd':
if (!is_digits(optarg)) {
err = EWRONG_OPT;
break;
}
c.dbg_lv = atoi(optarg);
MSG(0, "Info: Debug level = %d\n",
c.dbg_lv);
break;
case 'f':
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
break;
case 'S':
c.sparse_mode = 1;
break;
case 't':
c.mount_point = (char *)optarg;
break;
case 'T':
c.fixed_time = strtoul(optarg, &p, 0);
break;
case 'V':
show_version(prog);
exit(0);
case 'P':
c.preserve_perms = 1;
break;
default:
err = EUNKNOWN_OPT;
break;
}
if (err != NOERROR)
break;
}
if (c.compress.required && !c.compress.enabled) {
MSG(0, "\tError: compression sub-options are used"
" without the compression enable (-c) option\n"
);
error_out(prog);
}
if (err == NOERROR && c.compress.enabled) {
c.compress.cc.cluster_size = 1
<< c.compress.cc.log_cluster_size;
if (c.compress.filter == COMPR_FILTER_UNASSIGNED)
c.compress.filter = COMPR_FILTER_ALLOW;
if (c.compress.min_blocks >=
c.compress.cc.cluster_size) {
MSG(0, "\tError: minimum reduced blocks by"
" compression per cluster must be at"
" most one less than blocks per"
" cluster, i.e. %d\n",
c.compress.cc.cluster_size - 1);
error_out(prog);
}
}
#endif /* WITH_SLOAD */
} else if (!strcmp("f2fslabel", prog)) {
#ifdef WITH_LABEL
const char *option_string = "V";
c.func = LABEL;
while ((option = getopt(argc, argv, option_string)) != EOF) {
switch (option) {
case 'V':
show_version(prog);
exit(0);
default:
err = EUNKNOWN_OPT;
break;
}
if (err != NOERROR)
break;
}
if (argc > (optind + 2)) { /* unknown argument(s) is(are) passed */
optind += 2;
err = EUNKNOWN_ARG;
} else if (argc == (optind + 2)) { /* change label */
c.vol_label = argv[optind + 1];
argc--;
} else { /* print label */
/*
* Since vol_label was initialized as "", in order to
* distinguish between clear label and print, set
* vol_label as NULL for print case
*/
c.vol_label = NULL;
}
#endif /* WITH_LABEL */
f2fs-tools: add fsck.f2fs and dump.f2fs fsck.f2fs checks file system consistency, but does not repair a broken file system yet. dump.f2fs shows the information of a specific inode and makes dump file of SSA and SIT. f2fs checks file system consistency as follows: o When data about used area and its metadata are identical, f2fs is considered consistent. To verify such consistency, we use three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap. First, each bit in nat_area_bitmap corresponds to a nid in NAT. Second, each bit in sit_area_bitmap corresponds to a valid block in a segment. This bitmap is same to the total valid_map of f2fs_sit_entries in SIT. Last, each bit in main_area_bitmap corresponds to a block in main area except meta area. After a consistency check of each block, we set or clear the corresponding bit of each bitmap. From the root node, we start consistency check. The verified information varies according to block type. 1. NODE - Read information of node block from NAT - Check if block address is allocated using node info. - Check if the type of f2fs_summary related to nid in SSA is NODE. - Update the corresponding bit in nat_area_bitmap. - Update the corresponding bit in sit_area_bitmap. - Set the corresponding bit in main_area_bitmap to 1. - Then, read node block. According to its attribute, explore inode/direct node/indirect node/double indirect node recursively. - If it is an inode block, we also check its xattr and hard link. 2. DATA - Check if the type of f2fs_summary related to nid in SSA is DATA. - Set the corresponding bits of sit_area_bitmap and main_area_bitmap to visited - If it is a dentry block, traverse each dentries that may be regular file or directory. At this time, it will check inode block again. Finally, we verify whether - every nat_area_bitmap is visited - any unreachable hard link exists - values of sit_area_bitmap and main_area_bitmap are identical - total_valid_block_count/node_count/inode_count are correct Usage: o fsck.f2fs # fsck.f2fs /dev/sdx options: -d debug level [default:0] o dump.f2fs # dump.f2fs -i [ino] /dev/sdx # dump.f2fs -s 0~-1 /dev/sdx (SIT dump) # dump.f2fs -a 0~-1 /dev/sdx (SSA dump) options: -d debug level [default:0] -i inode no (hex) -s [SIT dump segno from #1~#2 (decimal), for all 0~-1] -a [SSA dump segno from #1~#2 (decimal), for all 0~-1] Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs dump.f2fs Signed-off-by: Changman Lee <cm224.lee@samsung.com> Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
}
if (err == NOERROR) {
add_default_options();
if (optind >= argc) {
MSG(0, "\tError: Device not specified\n");
error_out(prog);
}
c.devices[0].path = strdup(argv[optind]);
if (argc > (optind + 1)) {
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;
}
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
}
static int 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
{
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;
struct f2fs_compr_blk_cnt cbc;
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
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
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);
fsck_chk_curseg_info(sbi);
if (!c.fix_on && !c.bug_on) {
switch (c.preen_mode) {
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 FSCK_SUCCESS;
}
if (!c.ro)
c.fix_on = 1;
break;
}
} else if (c.preen_mode) {
/*
* 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
*/
c.fix_on = 1;
}
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);
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
/* 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;
cbc.cnt = 0;
cbc.cheader_pgofs = CHEADER_PGOFS_NONE;
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_OPERATIONAL_ERROR;
}
}
fsck_chk_orphan_node(sbi);
fsck_chk_node_blk(sbi, NULL, sbi->root_ino_num,
F2FS_FT_DIR, TYPE_INODE, &blk_cnt, &cbc, NULL);
fsck_chk_quota_files(sbi);
ret = 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);
if (!c.bug_on)
return FSCK_SUCCESS;
if (!ret)
return FSCK_ERROR_CORRECTED;
return FSCK_ERRORS_LEFT_UNCORRECTED;
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
}
#ifdef WITH_DUMP
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
{
struct dump_option *opt = (struct dump_option *)c.private;
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
u32 flag = le32_to_cpu(ckpt->ckpt_flags);
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;
if (opt->start_nat != -1)
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);
if (opt->blk_addr != -1)
dump_info_from_blkaddr(sbi, opt->blk_addr);
if (opt->nid)
dump_node(sbi, opt->nid, 0);
if (opt->scan_nid)
dump_node_scan_disk(sbi, opt->scan_nid);
print_cp_state(flag);
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
}
#endif
f2fs-tools: add fsck.f2fs and dump.f2fs fsck.f2fs checks file system consistency, but does not repair a broken file system yet. dump.f2fs shows the information of a specific inode and makes dump file of SSA and SIT. f2fs checks file system consistency as follows: o When data about used area and its metadata are identical, f2fs is considered consistent. To verify such consistency, we use three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap. First, each bit in nat_area_bitmap corresponds to a nid in NAT. Second, each bit in sit_area_bitmap corresponds to a valid block in a segment. This bitmap is same to the total valid_map of f2fs_sit_entries in SIT. Last, each bit in main_area_bitmap corresponds to a block in main area except meta area. After a consistency check of each block, we set or clear the corresponding bit of each bitmap. From the root node, we start consistency check. The verified information varies according to block type. 1. NODE - Read information of node block from NAT - Check if block address is allocated using node info. - Check if the type of f2fs_summary related to nid in SSA is NODE. - Update the corresponding bit in nat_area_bitmap. - Update the corresponding bit in sit_area_bitmap. - Set the corresponding bit in main_area_bitmap to 1. - Then, read node block. According to its attribute, explore inode/direct node/indirect node/double indirect node recursively. - If it is an inode block, we also check its xattr and hard link. 2. DATA - Check if the type of f2fs_summary related to nid in SSA is DATA. - Set the corresponding bits of sit_area_bitmap and main_area_bitmap to visited - If it is a dentry block, traverse each dentries that may be regular file or directory. At this time, it will check inode block again. Finally, we verify whether - every nat_area_bitmap is visited - any unreachable hard link exists - values of sit_area_bitmap and main_area_bitmap are identical - total_valid_block_count/node_count/inode_count are correct Usage: o fsck.f2fs # fsck.f2fs /dev/sdx options: -d debug level [default:0] o dump.f2fs # dump.f2fs -i [ino] /dev/sdx # dump.f2fs -s 0~-1 /dev/sdx (SIT dump) # dump.f2fs -a 0~-1 /dev/sdx (SSA dump) options: -d debug level [default:0] -i inode no (hex) -s [SIT dump segno from #1~#2 (decimal), for all 0~-1] -a [SSA dump segno from #1~#2 (decimal), for all 0~-1] Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs dump.f2fs Signed-off-by: Changman Lee <cm224.lee@samsung.com> Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
#ifdef WITH_DEFRAG
static int do_defrag(struct f2fs_sb_info *sbi)
{
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
if (get_sb(feature) & cpu_to_le32(F2FS_FEATURE_RO)) {
MSG(0, "Not support on readonly image.\n");
return -1;
}
if (c.defrag_start > get_sb(block_count))
goto out_range;
if (c.defrag_start < SM_I(sbi)->main_blkaddr)
c.defrag_start = SM_I(sbi)->main_blkaddr;
if (c.defrag_len == 0)
c.defrag_len = sbi->blocks_per_seg;
if (c.defrag_start + c.defrag_len > get_sb(block_count))
c.defrag_len = get_sb(block_count) - c.defrag_start;
if (c.defrag_target == 0) {
c.defrag_target = c.defrag_start - 1;
if (!c.defrag_shrink)
c.defrag_target += c.defrag_len + 1;
}
if (c.defrag_target < SM_I(sbi)->main_blkaddr ||
c.defrag_target > get_sb(block_count))
goto out_range;
if (c.defrag_target >= c.defrag_start &&
c.defrag_target < c.defrag_start + c.defrag_len)
goto out_range;
if (c.defrag_start > c.defrag_target)
MSG(0, "Info: Move 0x%"PRIx64" <- [0x%"PRIx64"-0x%"PRIx64"]\n",
c.defrag_target,
c.defrag_start,
c.defrag_start + c.defrag_len - 1);
else
MSG(0, "Info: Move [0x%"PRIx64"-0x%"PRIx64"] -> 0x%"PRIx64"\n",
c.defrag_start,
c.defrag_start + c.defrag_len - 1,
c.defrag_target);
return f2fs_defragment(sbi, c.defrag_start, c.defrag_len,
c.defrag_target, c.defrag_shrink);
out_range:
ASSERT_MSG("Out-of-range [0x%"PRIx64" ~ 0x%"PRIx64"] to 0x%"PRIx64"",
c.defrag_start,
c.defrag_start + c.defrag_len - 1,
c.defrag_target);
return -1;
}
#endif
#ifdef WITH_RESIZE
static int do_resize(struct f2fs_sb_info *sbi)
{
if (!c.target_sectors)
c.target_sectors = c.total_sectors;
if (c.target_sectors > c.total_sectors) {
ASSERT_MSG("Out-of-range Target=0x%"PRIx64" / 0x%"PRIx64"",
c.target_sectors, c.total_sectors);
return -1;
}
return f2fs_resize(sbi);
}
#endif
#ifdef WITH_SLOAD
static int init_compr(struct f2fs_sb_info *sbi)
{
if (!c.compress.enabled)
return 0;
if (!(sbi->raw_super->feature
& cpu_to_le32(F2FS_FEATURE_COMPRESSION))) {
MSG(0, "Error: Compression (-c) was requested "
"but the file system is not created "
"with such feature.\n");
return -1;
}
if (!supported_comp_ops[c.compress.alg].init) {
MSG(0, "Error: The selected compression algorithm is not"
" supported\n");
return -1;
}
c.compress.ops = supported_comp_ops + c.compress.alg;
c.compress.ops->init(&c.compress.cc);
c.compress.ops->reset(&c.compress.cc);
c.compress.cc.rlen = c.compress.cc.cluster_size * F2FS_BLKSIZE;
return 0;
}
static int do_sload(struct f2fs_sb_info *sbi)
{
if (!c.from_dir) {
MSG(0, "Info: No source directory, but it's okay.\n");
return 0;
}
if (!c.mount_point)
c.mount_point = "/";
if (init_compr(sbi))
return -1;
return f2fs_sload(sbi);
}
#endif
#ifdef WITH_LABEL
static int do_label(struct f2fs_sb_info *sbi)
{
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
if (!c.vol_label) {
char label[MAX_VOLUME_NAME];
utf16_to_utf8(label, sb->volume_name,
MAX_VOLUME_NAME, MAX_VOLUME_NAME);
MSG(0, "Info: volume label = %s\n", label);
return 0;
}
if (strlen(c.vol_label) > MAX_VOLUME_NAME) {
ERR_MSG("Label should not exceed %d characters\n", MAX_VOLUME_NAME);
return -1;
}
utf8_to_utf16(sb->volume_name, (const char *)c.vol_label,
MAX_VOLUME_NAME, strlen(c.vol_label));
update_superblock(sb, SB_MASK_ALL);
MSG(0, "Info: volume label is changed to %s\n", c.vol_label);
return 0;
}
#endif
#ifdef HAVE_MACH_TIME_H
static u64 get_boottime_ns()
{
return mach_absolute_time();
}
#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_BOOTTIME)
static u64 get_boottime_ns()
{
struct timespec t;
t.tv_sec = t.tv_nsec = 0;
clock_gettime(CLOCK_BOOTTIME, &t);
return (u64)t.tv_sec * 1000000000LL + t.tv_nsec;
}
#else
static u64 get_boottime_ns()
{
return 0;
}
#endif
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
{
struct f2fs_sb_info *sbi;
int ret = 0, ret2;
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
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);
if (c.func != DUMP && f2fs_devs_are_umounted() < 0) {
if (errno == EBUSY) {
ret = -1;
if (c.func == FSCK)
ret = FSCK_OPERATIONAL_ERROR;
goto quick_err;
}
if (!c.ro || c.func == DEFRAG) {
MSG(0, "\tError: Not available on mounted device!\n");
ret = -1;
if (c.func == FSCK)
ret = FSCK_OPERATIONAL_ERROR;
goto quick_err;
}
/* allow ro-mounted partition */
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;
}
}
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 */
mkfs.f2fs: wipe other FS magics given -f commit 1603a3d1de98031b4c2d020999d50e7a34b731ad category: bugfix issue: #I6VAS0 CVE: NA Signed-off-by: DongSenhao <dongsenhao2@huawei.com> --------------------------------------- This patch fixes the below stale magic info. $ mkfs.btrfs -f test.img btrfs-progs v5.10.1 See http://btrfs.wiki.kernel.org for more information. Label: (null) UUID: 941d2db7-3ece-4090-8b22-c4ea548b5dae Node size: 16384 Sector size: 4096 Filesystem size: 1.00GiB Block group profiles: Data: single 8.00MiB Metadata: DUP 51.19MiB System: DUP 8.00MiB SSD detected: no Incompat features: extref, skinny-metadata Runtime features: Checksum: crc32c Number of devices: 1 Devices: ID SIZE PATH 1 1.00GiB test.img $ hexdump -s 0x10000 -n 128 -C test.img 00010000 81 29 94 0a 00 00 00 00 00 00 00 00 00 00 00 00 |.)..............| 00010010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00010020 94 1d 2d b7 3e ce 40 90 8b 22 c4 ea 54 8b 5d ae |..-.>.@.."..T.].| 00010030 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00 |................| 00010040 5f 42 48 52 66 53 5f 4d 05 00 00 00 00 00 00 00 |_BHRfS_M........| 00010050 00 40 d2 01 00 00 00 00 00 40 50 01 00 00 00 00 |.@.......@P.....| 00010060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00010070 00 00 00 40 00 00 00 00 00 00 02 00 00 00 00 00 |...@............| 00010080 $ mkfs.f2fs -t 0 -f test.img F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-12-28) Info: Disable heap-based policy Info: Debug level = 0 Info: Trim is disabled Info: Segments per section = 1 Info: Sections per zone = 1 Info: sector size = 512 Info: total sectors = 2097152 (1024 MB) Info: zone aligned segment0 blkaddr: 512 Info: format version with "Linux version 5.10.46-4rodete1-amd64 (glinux-team@google.com) (gcc-10 (Debian 10.2.1-6+build2) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.46-4rodete1 (2021-08-20)" Info: Overprovision ratio = 6.360% Info: Overprovision segments = 68 (GC reserved = 39) Info: format successful $hexdump -s 0x10000 -n 128 -C test.img 00010000 c2 8a c8 26 00 00 00 00 00 00 00 00 00 00 00 00 |...&............| 00010010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00010020 92 ab 3f c6 b7 82 49 5e 93 23 e8 c9 e9 45 7d ac |..?...I^.#...E}.| 00010030 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00 |................| 00010040 5f 42 48 52 66 53 5f 4d 05 00 00 00 00 00 00 00 |_BHRfS_M........| 00010050 00 40 d2 01 00 00 00 00 00 40 50 01 00 00 00 00 |.@.......@P.....| 00010060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00010070 00 00 00 40 00 00 00 00 00 00 02 00 00 00 00 00 |...@............| 00010080 --- After this patch --- $ mkfs.f2fs -t 0 -f test.img F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-12-28) Info: Disable heap-based policy Info: Debug level = 0 Info: Trim is disabled test.img appears to contain an existing filesystem (btrfs). Info: Segments per section = 1 Info: Sections per zone = 1 Info: sector size = 512 Info: total sectors = 2097152 (1024 MB) Info: zone aligned segment0 blkaddr: 512 Info: format version with "Linux version 5.10.46-4rodete1-amd64 (glinux-team@google.com) (gcc-10 (Debian 10.2.1-6+build2) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.46-4rodete1 (2021-08-20)" Info: Overprovision ratio = 6.360% Info: Overprovision segments = 68 (GC reserved = 39) Info: format successful $ hexdump -s 0x10000 -n 128 -C test.img 00010000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00010080 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
2021-09-10 22:38:11 +00:00
if (f2fs_get_device_info() < 0 || f2fs_get_f2fs_info() < 0) {
ret = -1;
if (c.func == FSCK)
ret = FSCK_OPERATIONAL_ERROR;
goto quick_err;
}
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
ret = f2fs_do_mount(sbi);
if (ret != 0) {
if (ret == 1) {
MSG(0, "Info: No error was reported\n");
ret = 0;
}
goto out_err;
}
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 (c.func) {
case FSCK:
ret = do_fsck(sbi);
break;
#ifdef WITH_DUMP
case DUMP:
do_dump(sbi);
break;
#endif
#ifdef WITH_DEFRAG
case DEFRAG:
ret = do_defrag(sbi);
if (ret)
goto out_err;
break;
#endif
#ifdef WITH_RESIZE
case RESIZE:
if (do_resize(sbi))
goto out_err;
break;
#endif
#ifdef WITH_SLOAD
case SLOAD:
if (do_sload(sbi))
goto out_err;
ret = f2fs_sparse_initialize_meta(sbi);
if (ret < 0)
goto out_err;
f2fs_do_umount(sbi);
/* fsck to fix missing quota */
c.func = FSCK;
c.fix_on = 1;
goto fsck_again;
#endif
#ifdef WITH_LABEL
case LABEL:
if (do_label(sbi))
goto out_err;
break;
#endif
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
}
f2fs_do_umount(sbi);
if (c.func == FSCK && c.bug_on) {
if (!c.ro && c.fix_on == 0 && c.auto_fix == 0 && !c.dry_run) {
char ans[255] = {0};
retry:
printf("Do you want to fix this partition? [Y/N] ");
ret2 = scanf("%s", ans);
ASSERT(ret2 >= 0);
if (!strcasecmp(ans, "y"))
c.fix_on = 1;
else if (!strcasecmp(ans, "n"))
c.fix_on = 0;
else
goto retry;
if (c.fix_on)
goto fsck_again;
}
}
ret2 = f2fs_finalize_device();
if (ret2) {
if (c.func == FSCK)
return FSCK_OPERATIONAL_ERROR;
return ret2;
}
if (c.func == SLOAD)
c.compress.filter_ops->destroy();
if (!c.show_file_map)
printf("\nDone: %lf secs\n", (get_boottime_ns() - start) / 1000000000.0);
return ret;
out_err:
if (sbi->ckpt)
free(sbi->ckpt);
if (sbi->raw_super)
free(sbi->raw_super);
quick_err:
f2fs_release_sparse_resource();
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
}