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
|
|
|
/**
|
|
|
|
* dump.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-06-30 20:57:17 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2018-01-30 11:23:12 +00:00
|
|
|
#include "node.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
|
|
|
#include "fsck.h"
|
2017-11-02 03:56:07 +00:00
|
|
|
#include "xattr.h"
|
|
|
|
#ifdef HAVE_ATTR_XATTR_H
|
|
|
|
#include <attr/xattr.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LINUX_XATTR_H
|
|
|
|
#include <linux/xattr.h>
|
|
|
|
#endif
|
2014-12-13 21:55:59 +00:00
|
|
|
#include <locale.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
|
|
|
|
|
|
|
#define BUF_SZ 80
|
|
|
|
|
2015-03-27 04:27:56 +00:00
|
|
|
const char *seg_type_name[SEG_TYPE_MAX + 1] = {
|
2013-07-18 02:20:05 +00:00
|
|
|
"SEG_TYPE_DATA",
|
|
|
|
"SEG_TYPE_CUR_DATA",
|
|
|
|
"SEG_TYPE_NODE",
|
|
|
|
"SEG_TYPE_CUR_NODE",
|
2015-03-27 04:27:56 +00:00
|
|
|
"SEG_TYPE_NONE",
|
2013-07-18 02:20:05 +00:00
|
|
|
};
|
|
|
|
|
2018-07-02 09:22:41 +00:00
|
|
|
void nat_dump(struct f2fs_sb_info *sbi, nid_t start_nat, nid_t end_nat)
|
2016-06-04 10:03:56 +00:00
|
|
|
{
|
|
|
|
struct f2fs_nat_block *nat_block;
|
|
|
|
struct f2fs_node *node_block;
|
2018-07-02 09:22:41 +00:00
|
|
|
nid_t nid;
|
2016-06-04 10:03:56 +00:00
|
|
|
pgoff_t block_addr;
|
|
|
|
char buf[BUF_SZ];
|
2016-11-19 13:24:41 +00:00
|
|
|
int fd, ret, pack;
|
2016-06-04 10:03:56 +00:00
|
|
|
|
|
|
|
nat_block = (struct f2fs_nat_block *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(nat_block);
|
2018-07-02 09:22:41 +00:00
|
|
|
node_block = (struct f2fs_node *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_block);
|
2016-06-04 10:03:56 +00:00
|
|
|
|
|
|
|
fd = open("dump_nat", O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
|
|
|
ASSERT(fd >= 0);
|
|
|
|
|
2018-07-02 09:22:41 +00:00
|
|
|
for (nid = start_nat; nid < end_nat; nid++) {
|
|
|
|
struct f2fs_nat_entry raw_nat;
|
|
|
|
struct node_info ni;
|
|
|
|
if(nid == 0 || nid == F2FS_NODE_INO(sbi) ||
|
|
|
|
nid == F2FS_META_INO(sbi))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ni.nid = nid;
|
|
|
|
block_addr = current_nat_addr(sbi, nid, &pack);
|
|
|
|
|
|
|
|
if (lookup_nat_in_journal(sbi, nid, &raw_nat) >= 0) {
|
|
|
|
node_info_from_raw_nat(&ni, &raw_nat);
|
|
|
|
ret = dev_read_block(node_block, ni.blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
if (ni.blk_addr != 0x0) {
|
2016-06-04 10:03:56 +00:00
|
|
|
memset(buf, 0, BUF_SZ);
|
2016-10-12 21:11:19 +00:00
|
|
|
snprintf(buf, BUF_SZ,
|
|
|
|
"nid:%5u\tino:%5u\toffset:%5u"
|
|
|
|
"\tblkaddr:%10u\tpack:%d\n",
|
|
|
|
ni.nid, ni.ino,
|
2017-01-19 03:03:40 +00:00
|
|
|
le32_to_cpu(node_block->footer.flag) >>
|
2016-10-12 21:11:19 +00:00
|
|
|
OFFSET_BIT_SHIFT,
|
|
|
|
ni.blk_addr, pack);
|
2016-06-04 10:03:56 +00:00
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
}
|
2018-07-02 09:22:41 +00:00
|
|
|
} else {
|
|
|
|
ret = dev_read_block(nat_block, block_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
node_info_from_raw_nat(&ni,
|
|
|
|
&nat_block->entries[nid % NAT_ENTRY_PER_BLOCK]);
|
|
|
|
if (ni.blk_addr == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = dev_read_block(node_block, ni.blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
memset(buf, 0, BUF_SZ);
|
|
|
|
snprintf(buf, BUF_SZ,
|
|
|
|
"nid:%5u\tino:%5u\toffset:%5u"
|
|
|
|
"\tblkaddr:%10u\tpack:%d\n",
|
|
|
|
ni.nid, ni.ino,
|
|
|
|
le32_to_cpu(node_block->footer.flag) >>
|
|
|
|
OFFSET_BIT_SHIFT,
|
|
|
|
ni.blk_addr, pack);
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
2016-06-04 10:03:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(nat_block);
|
|
|
|
free(node_block);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2016-10-12 21:11:19 +00:00
|
|
|
void sit_dump(struct f2fs_sb_info *sbi, unsigned int start_sit,
|
|
|
|
unsigned int end_sit)
|
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 seg_entry *se;
|
2016-06-04 10:03:56 +00:00
|
|
|
struct sit_info *sit_i = SIT_I(sbi);
|
|
|
|
unsigned int segno;
|
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
|
|
|
char buf[BUF_SZ];
|
|
|
|
u32 free_segs = 0;;
|
|
|
|
u64 valid_blocks = 0;
|
|
|
|
int ret;
|
2016-06-04 10:03:56 +00:00
|
|
|
int fd, i;
|
|
|
|
unsigned int offset;
|
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
|
|
|
|
|
|
|
fd = open("dump_sit", O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
|
|
|
ASSERT(fd >= 0);
|
|
|
|
|
2016-06-04 10:03:56 +00:00
|
|
|
snprintf(buf, BUF_SZ, "segment_type(0:HD, 1:WD, 2:CD, "
|
|
|
|
"3:HN, 4:WN, 5:CN)\n");
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(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
|
|
|
for (segno = start_sit; segno < end_sit; segno++) {
|
|
|
|
se = get_seg_entry(sbi, segno);
|
2016-06-04 10:03:56 +00:00
|
|
|
offset = SIT_BLOCK_OFFSET(sit_i, segno);
|
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
|
|
|
memset(buf, 0, BUF_SZ);
|
2016-10-12 21:11:19 +00:00
|
|
|
snprintf(buf, BUF_SZ,
|
|
|
|
"\nsegno:%8u\tvblocks:%3u\tseg_type:%d\tsit_pack:%d\n\n",
|
|
|
|
segno, se->valid_blocks, se->type,
|
|
|
|
f2fs_test_bit(offset, sit_i->sit_bitmap) ? 2 : 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
|
|
|
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if (se->valid_blocks == 0x0) {
|
|
|
|
free_segs++;
|
2016-10-12 21:11:19 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-04 10:03:56 +00:00
|
|
|
|
2016-10-12 21:11:19 +00:00
|
|
|
ASSERT(se->valid_blocks <= 512);
|
|
|
|
valid_blocks += se->valid_blocks;
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
memset(buf, 0, BUF_SZ);
|
|
|
|
snprintf(buf, BUF_SZ, " %02x",
|
|
|
|
*(se->cur_valid_map + i));
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if ((i + 1) % 16 == 0) {
|
|
|
|
snprintf(buf, BUF_SZ, "\n");
|
2016-06-04 10:03:56 +00:00
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, BUF_SZ);
|
2016-10-12 21:11:19 +00:00
|
|
|
snprintf(buf, BUF_SZ,
|
|
|
|
"valid_blocks:[0x%" PRIx64 "]\tvalid_segs:%d\t free_segs:%d\n",
|
|
|
|
valid_blocks,
|
|
|
|
SM_I(sbi)->main_segments - free_segs,
|
|
|
|
free_segs);
|
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 = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssa_dump(struct f2fs_sb_info *sbi, int start_ssa, int end_ssa)
|
|
|
|
{
|
2015-03-27 04:27:56 +00:00
|
|
|
struct f2fs_summary_block *sum_blk;
|
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
|
|
|
char buf[BUF_SZ];
|
2018-02-06 08:47:14 +00:00
|
|
|
int segno, type, i, 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
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open("dump_ssa", O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
|
|
|
ASSERT(fd >= 0);
|
|
|
|
|
2014-02-05 16:09:36 +00:00
|
|
|
snprintf(buf, BUF_SZ, "Note: dump.f2fs -b blkaddr = 0x%x + segno * "
|
|
|
|
" 0x200 + offset\n",
|
|
|
|
sbi->sm_info->main_blkaddr);
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(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
|
|
|
for (segno = start_ssa; segno < end_ssa; segno++) {
|
2018-02-06 08:47:14 +00:00
|
|
|
sum_blk = get_sum_block(sbi, segno, &type);
|
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
|
|
|
|
|
|
|
memset(buf, 0, BUF_SZ);
|
2018-02-06 08:47:14 +00:00
|
|
|
switch (type) {
|
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
|
|
|
case SEG_TYPE_CUR_NODE:
|
2014-02-05 16:09:36 +00:00
|
|
|
snprintf(buf, BUF_SZ, "\n\nsegno: %x, Current Node\n", segno);
|
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
|
|
|
break;
|
|
|
|
case SEG_TYPE_CUR_DATA:
|
2014-02-05 16:09:36 +00:00
|
|
|
snprintf(buf, BUF_SZ, "\n\nsegno: %x, Current Data\n", segno);
|
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
|
|
|
break;
|
|
|
|
case SEG_TYPE_NODE:
|
2014-02-05 16:09:36 +00:00
|
|
|
snprintf(buf, BUF_SZ, "\n\nsegno: %x, Node\n", segno);
|
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
|
|
|
break;
|
|
|
|
case SEG_TYPE_DATA:
|
2014-02-05 16:09:36 +00:00
|
|
|
snprintf(buf, BUF_SZ, "\n\nsegno: %x, Data\n", segno);
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
for (i = 0; i < ENTRIES_IN_SUM; i++) {
|
|
|
|
memset(buf, 0, BUF_SZ);
|
|
|
|
if (i % 10 == 0) {
|
|
|
|
buf[0] = '\n';
|
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
}
|
2014-02-05 16:09:36 +00:00
|
|
|
snprintf(buf, BUF_SZ, "[%3d: %6x]", i,
|
2015-03-27 04:27:56 +00:00
|
|
|
le32_to_cpu(sum_blk->entries[i].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
|
|
|
ret = write(fd, buf, strlen(buf));
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
}
|
2018-02-06 08:47:14 +00:00
|
|
|
if (type == SEG_TYPE_NODE || type == SEG_TYPE_DATA ||
|
|
|
|
type == SEG_TYPE_MAX)
|
2015-03-27 04:27:56 +00:00
|
|
|
free(sum_blk);
|
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
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2016-10-13 23:04:52 +00:00
|
|
|
static void dump_data_blk(struct f2fs_sb_info *sbi, __u64 offset, u32 blkaddr)
|
2014-08-19 21:05:21 +00:00
|
|
|
{
|
|
|
|
char buf[F2FS_BLKSIZE];
|
|
|
|
|
|
|
|
if (blkaddr == NULL_ADDR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* get data */
|
2016-10-13 23:04:52 +00:00
|
|
|
if (blkaddr == NEW_ADDR || !IS_VALID_BLK_ADDR(sbi, blkaddr)) {
|
2014-08-19 21:05:21 +00:00
|
|
|
memset(buf, 0, F2FS_BLKSIZE);
|
|
|
|
} else {
|
|
|
|
int ret;
|
|
|
|
ret = dev_read_block(buf, blkaddr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write blkaddr */
|
|
|
|
dev_write_dump(buf, offset, F2FS_BLKSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_node_blk(struct f2fs_sb_info *sbi, int ntype,
|
|
|
|
u32 nid, u64 *ofs)
|
|
|
|
{
|
|
|
|
struct node_info ni;
|
|
|
|
struct f2fs_node *node_blk;
|
2014-09-02 17:52:56 +00:00
|
|
|
u32 skip = 0;
|
2019-03-25 13:19:35 +00:00
|
|
|
u32 i, idx = 0;
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
|
|
|
|
node_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk);
|
|
|
|
|
|
|
|
dev_read_block(node_blk, ni.blk_addr);
|
2014-08-19 21:05:21 +00:00
|
|
|
|
|
|
|
switch (ntype) {
|
|
|
|
case TYPE_DIRECT_NODE:
|
2019-03-25 13:19:35 +00:00
|
|
|
skip = idx = ADDRS_PER_BLOCK(&node_blk->i);
|
2014-08-19 21:05:21 +00:00
|
|
|
break;
|
|
|
|
case TYPE_INDIRECT_NODE:
|
|
|
|
idx = NIDS_PER_BLOCK;
|
2019-03-25 13:19:35 +00:00
|
|
|
skip = idx * ADDRS_PER_BLOCK(&node_blk->i);
|
2014-08-19 21:05:21 +00:00
|
|
|
break;
|
|
|
|
case TYPE_DOUBLE_INDIRECT_NODE:
|
|
|
|
skip = 0;
|
|
|
|
idx = NIDS_PER_BLOCK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nid == 0) {
|
|
|
|
*ofs += skip;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < idx; i++, (*ofs)++) {
|
|
|
|
switch (ntype) {
|
|
|
|
case TYPE_DIRECT_NODE:
|
2016-10-13 23:04:52 +00:00
|
|
|
dump_data_blk(sbi, *ofs * F2FS_BLKSIZE,
|
2014-08-19 21:05:21 +00:00
|
|
|
le32_to_cpu(node_blk->dn.addr[i]));
|
|
|
|
break;
|
|
|
|
case TYPE_INDIRECT_NODE:
|
|
|
|
dump_node_blk(sbi, TYPE_DIRECT_NODE,
|
|
|
|
le32_to_cpu(node_blk->in.nid[i]), ofs);
|
|
|
|
break;
|
|
|
|
case TYPE_DOUBLE_INDIRECT_NODE:
|
|
|
|
dump_node_blk(sbi, TYPE_INDIRECT_NODE,
|
|
|
|
le32_to_cpu(node_blk->in.nid[i]), ofs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(node_blk);
|
|
|
|
}
|
|
|
|
|
2017-11-02 03:56:07 +00:00
|
|
|
#ifdef HAVE_FSETXATTR
|
|
|
|
static void dump_xattr(struct f2fs_sb_info *sbi, struct f2fs_node *node_blk)
|
|
|
|
{
|
|
|
|
void *xattr;
|
|
|
|
struct f2fs_xattr_entry *ent;
|
|
|
|
char xattr_name[F2FS_NAME_LEN] = {0};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
xattr = read_all_xattrs(sbi, node_blk);
|
2020-04-07 10:01:07 +00:00
|
|
|
if (!xattr)
|
|
|
|
return;
|
2017-11-02 03:56:07 +00:00
|
|
|
|
|
|
|
list_for_each_xattr(ent, xattr) {
|
|
|
|
char *name = strndup(ent->e_name, ent->e_name_len);
|
|
|
|
void *value = ent->e_name + ent->e_name_len;
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (ent->e_name_index) {
|
|
|
|
case F2FS_XATTR_INDEX_USER:
|
|
|
|
ret = snprintf(xattr_name, F2FS_NAME_LEN, "%s%s",
|
|
|
|
XATTR_USER_PREFIX, name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F2FS_XATTR_INDEX_SECURITY:
|
|
|
|
ret = snprintf(xattr_name, F2FS_NAME_LEN, "%s%s",
|
|
|
|
XATTR_SECURITY_PREFIX, name);
|
|
|
|
break;
|
|
|
|
case F2FS_XATTR_INDEX_TRUSTED:
|
|
|
|
ret = snprintf(xattr_name, F2FS_NAME_LEN, "%s%s",
|
|
|
|
XATTR_TRUSTED_PREFIX, name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MSG(0, "Unknown xattr index 0x%x\n", ent->e_name_index);
|
|
|
|
free(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ret >= F2FS_NAME_LEN) {
|
|
|
|
MSG(0, "XATTR index 0x%x name too long\n", ent->e_name_index);
|
|
|
|
free(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG(1, "fd %d xattr_name %s\n", c.dump_fd, xattr_name);
|
2017-11-14 18:53:32 +00:00
|
|
|
#if defined(__linux__)
|
2017-11-02 03:56:07 +00:00
|
|
|
ret = fsetxattr(c.dump_fd, xattr_name, value,
|
|
|
|
le16_to_cpu(ent->e_value_size), 0);
|
2017-11-14 18:53:32 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
ret = fsetxattr(c.dump_fd, xattr_name, value,
|
|
|
|
le16_to_cpu(ent->e_value_size), 0,
|
|
|
|
XATTR_CREATE);
|
|
|
|
#endif
|
2017-11-02 03:56:07 +00:00
|
|
|
if (ret)
|
|
|
|
MSG(0, "XATTR index 0x%x set xattr failed error %d\n",
|
|
|
|
ent->e_name_index, errno);
|
|
|
|
|
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(xattr);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void dump_xattr(struct f2fs_sb_info *UNUSED(sbi),
|
|
|
|
struct f2fs_node *UNUSED(node_blk))
|
|
|
|
{
|
|
|
|
MSG(0, "XATTR does not support\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-19 21:05:21 +00:00
|
|
|
static void dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
|
|
|
|
struct f2fs_node *node_blk)
|
|
|
|
{
|
|
|
|
u32 i = 0;
|
|
|
|
u64 ofs = 0;
|
|
|
|
|
2017-11-02 03:56:07 +00:00
|
|
|
if((node_blk->i.i_inline & F2FS_INLINE_DATA)) {
|
2014-08-19 21:05:21 +00:00
|
|
|
DBG(3, "ino[0x%x] has inline data!\n", nid);
|
|
|
|
/* recover from inline data */
|
|
|
|
dev_write_dump(((unsigned char *)node_blk) + INLINE_DATA_OFFSET,
|
2017-07-26 14:49:57 +00:00
|
|
|
0, MAX_INLINE_DATA(node_blk));
|
2014-08-19 21:05:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check data blocks in inode */
|
|
|
|
for (i = 0; i < ADDRS_PER_INODE(&node_blk->i); i++, ofs++)
|
2017-07-26 14:49:57 +00:00
|
|
|
dump_data_blk(sbi, ofs * F2FS_BLKSIZE, le32_to_cpu(
|
|
|
|
node_blk->i.i_addr[get_extra_isize(node_blk) + i]));
|
2014-08-19 21:05:21 +00:00
|
|
|
|
|
|
|
/* check node blocks in inode */
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
if (i == 0 || i == 1)
|
|
|
|
dump_node_blk(sbi, TYPE_DIRECT_NODE,
|
2017-01-19 03:03:40 +00:00
|
|
|
le32_to_cpu(node_blk->i.i_nid[i]), &ofs);
|
2014-08-19 21:05:21 +00:00
|
|
|
else if (i == 2 || i == 3)
|
|
|
|
dump_node_blk(sbi, TYPE_INDIRECT_NODE,
|
2017-01-19 03:03:40 +00:00
|
|
|
le32_to_cpu(node_blk->i.i_nid[i]), &ofs);
|
2014-08-19 21:05:21 +00:00
|
|
|
else if (i == 4)
|
|
|
|
dump_node_blk(sbi, TYPE_DOUBLE_INDIRECT_NODE,
|
2017-01-19 03:03:40 +00:00
|
|
|
le32_to_cpu(node_blk->i.i_nid[i]), &ofs);
|
2014-08-19 21:05:21 +00:00
|
|
|
else
|
|
|
|
ASSERT(0);
|
|
|
|
}
|
2017-11-02 03:56:07 +00:00
|
|
|
|
|
|
|
dump_xattr(sbi, node_blk);
|
2014-08-19 21:05:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 23:04:52 +00:00
|
|
|
static void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
|
|
|
|
struct f2fs_node *node_blk, int force)
|
2014-08-19 21:05:21 +00:00
|
|
|
{
|
|
|
|
struct f2fs_inode *inode = &node_blk->i;
|
2018-12-10 03:19:01 +00:00
|
|
|
u32 imode = le16_to_cpu(inode->i_mode);
|
2016-10-13 23:04:52 +00:00
|
|
|
u32 namelen = le32_to_cpu(inode->i_namelen);
|
2017-11-02 03:56:08 +00:00
|
|
|
char name[F2FS_NAME_LEN + 1] = {0};
|
2014-08-19 21:05:21 +00:00
|
|
|
char path[1024] = {0};
|
|
|
|
char ans[255] = {0};
|
2017-11-02 03:56:08 +00:00
|
|
|
int is_encrypted = file_is_encrypt(inode);
|
2014-08-19 21:05:21 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-11-02 03:56:08 +00:00
|
|
|
if (is_encrypted) {
|
|
|
|
MSG(force, "File is encrypted\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-13 23:04:52 +00:00
|
|
|
if (!S_ISREG(imode) || namelen == 0 || namelen > F2FS_NAME_LEN) {
|
|
|
|
MSG(force, "Not a regular file or wrong name info\n\n");
|
2014-08-19 21:05:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-13 23:04:52 +00:00
|
|
|
if (force)
|
|
|
|
goto dump;
|
2014-08-19 21:05:21 +00:00
|
|
|
|
|
|
|
printf("Do you want to dump this file into ./lost_found/? [Y/N] ");
|
|
|
|
ret = scanf("%s", ans);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if (!strcasecmp(ans, "y")) {
|
2016-10-13 23:04:52 +00:00
|
|
|
dump:
|
2014-08-19 21:05:21 +00:00
|
|
|
ret = system("mkdir -p ./lost_found");
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
/* make a file */
|
2017-11-02 03:56:08 +00:00
|
|
|
strncpy(name, (const char *)inode->i_name, namelen);
|
2016-10-13 23:04:52 +00:00
|
|
|
name[namelen] = 0;
|
2014-08-19 21:05:21 +00:00
|
|
|
sprintf(path, "./lost_found/%s", name);
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
c.dump_fd = open(path, O_TRUNC|O_CREAT|O_RDWR, 0666);
|
|
|
|
ASSERT(c.dump_fd >= 0);
|
2014-08-19 21:05:21 +00:00
|
|
|
|
|
|
|
/* dump file's data */
|
|
|
|
dump_inode_blk(sbi, ni->ino, node_blk);
|
|
|
|
|
|
|
|
/* adjust file size */
|
2016-09-17 01:41:00 +00:00
|
|
|
ret = ftruncate(c.dump_fd, le32_to_cpu(inode->i_size));
|
2014-08-19 21:05:21 +00:00
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
close(c.dump_fd);
|
2014-08-19 21:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 03:59:54 +00:00
|
|
|
static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr)
|
|
|
|
{
|
|
|
|
struct seg_entry *se;
|
|
|
|
u32 offset;
|
|
|
|
|
|
|
|
se = get_seg_entry(sbi, GET_SEGNO(sbi, blk_addr));
|
|
|
|
offset = OFFSET_IN_SEG(sbi, blk_addr);
|
|
|
|
|
|
|
|
return f2fs_test_bit(offset,
|
|
|
|
(const char *)se->cur_valid_map) != 0;
|
|
|
|
}
|
|
|
|
|
2016-10-13 23:04:52 +00:00
|
|
|
void dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force)
|
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 node_info ni;
|
|
|
|
struct f2fs_node *node_blk;
|
|
|
|
|
2014-08-27 23:39:23 +00:00
|
|
|
get_node_info(sbi, nid, &ni);
|
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
|
|
|
|
|
|
|
node_blk = calloc(BLOCK_SZ, 1);
|
2018-11-26 13:36:00 +00:00
|
|
|
ASSERT(node_blk);
|
|
|
|
|
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
|
|
|
dev_read_block(node_blk, ni.blk_addr);
|
|
|
|
|
|
|
|
DBG(1, "Node ID [0x%x]\n", nid);
|
|
|
|
DBG(1, "nat_entry.block_addr [0x%x]\n", ni.blk_addr);
|
|
|
|
DBG(1, "nat_entry.version [0x%x]\n", ni.version);
|
|
|
|
DBG(1, "nat_entry.ino [0x%x]\n", ni.ino);
|
|
|
|
|
2020-04-07 10:01:06 +00:00
|
|
|
if (!IS_VALID_BLK_ADDR(sbi, ni.blk_addr)) {
|
|
|
|
MSG(force, "Invalid node blkaddr: %u\n\n", ni.blk_addr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:39:23 +00:00
|
|
|
if (ni.blk_addr == 0x0)
|
2016-10-13 23:04:52 +00:00
|
|
|
MSG(force, "Invalid nat entry\n\n");
|
2018-03-07 03:59:54 +00:00
|
|
|
else if (!is_sit_bitmap_set(sbi, ni.blk_addr))
|
2020-04-07 10:01:06 +00:00
|
|
|
MSG(force, "Invalid sit bitmap, %u\n\n", ni.blk_addr);
|
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
|
|
|
|
|
|
|
DBG(1, "node_blk.footer.ino [0x%x]\n", le32_to_cpu(node_blk->footer.ino));
|
|
|
|
DBG(1, "node_blk.footer.nid [0x%x]\n", le32_to_cpu(node_blk->footer.nid));
|
|
|
|
|
|
|
|
if (le32_to_cpu(node_blk->footer.ino) == ni.ino &&
|
2018-03-07 03:59:54 +00:00
|
|
|
le32_to_cpu(node_blk->footer.nid) == ni.nid) {
|
2017-11-03 04:25:12 +00:00
|
|
|
print_node_info(sbi, node_blk, force);
|
2018-03-07 03:59:54 +00:00
|
|
|
|
|
|
|
if (ni.ino == ni.nid)
|
|
|
|
dump_file(sbi, &ni, node_blk, force);
|
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 {
|
2017-11-03 04:25:12 +00:00
|
|
|
print_node_info(sbi, node_blk, force);
|
2016-10-13 23:04:52 +00:00
|
|
|
MSG(force, "Invalid (i)node block\n\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
|
|
|
}
|
2020-04-07 10:01:06 +00:00
|
|
|
out:
|
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
|
|
|
free(node_blk);
|
|
|
|
}
|
|
|
|
|
2017-11-03 04:25:12 +00:00
|
|
|
static void dump_node_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
2013-07-18 02:20:05 +00:00
|
|
|
struct f2fs_node *node_blk;
|
2014-12-13 21:55:59 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
node_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk);
|
|
|
|
|
|
|
|
ret = dev_read_block(node_blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.dbg_lv > 0)
|
2017-11-03 04:25:12 +00:00
|
|
|
print_node_info(sbi, node_blk, 0);
|
2014-12-13 21:55:59 +00:00
|
|
|
else
|
2017-11-03 04:25:12 +00:00
|
|
|
print_inode_info(sbi, node_blk, 1);
|
2014-12-13 21:55:59 +00:00
|
|
|
|
|
|
|
free(node_blk);
|
|
|
|
}
|
|
|
|
|
2019-08-09 10:52:58 +00:00
|
|
|
unsigned int start_bidx_of_node(unsigned int node_ofs,
|
|
|
|
struct f2fs_node *node_blk)
|
|
|
|
{
|
|
|
|
unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
|
|
|
|
unsigned int bidx;
|
|
|
|
|
|
|
|
if (node_ofs == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (node_ofs <= 2) {
|
|
|
|
bidx = node_ofs - 1;
|
|
|
|
} else if (node_ofs <= indirect_blks) {
|
|
|
|
int dec = (node_ofs - 4) / (NIDS_PER_BLOCK + 1);
|
|
|
|
bidx = node_ofs - 2 - dec;
|
|
|
|
} else {
|
|
|
|
int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
|
|
|
|
bidx = node_ofs - 5 - dec;
|
|
|
|
}
|
2019-03-25 13:19:35 +00:00
|
|
|
return bidx * ADDRS_PER_BLOCK(&node_blk->i) +
|
|
|
|
ADDRS_PER_INODE(&node_blk->i);
|
2019-08-09 10:52:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 21:55:59 +00:00
|
|
|
static void dump_data_offset(u32 blk_addr, int ofs_in_node)
|
|
|
|
{
|
|
|
|
struct f2fs_node *node_blk;
|
2019-08-09 10:52:58 +00:00
|
|
|
unsigned int bidx;
|
2014-12-13 21:55:59 +00:00
|
|
|
unsigned int node_ofs;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
node_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk);
|
|
|
|
|
|
|
|
ret = dev_read_block(node_blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
node_ofs = ofs_of_node(node_blk);
|
|
|
|
|
2019-08-09 10:52:58 +00:00
|
|
|
bidx = start_bidx_of_node(node_ofs, node_blk);
|
2014-12-13 21:55:59 +00:00
|
|
|
bidx += ofs_in_node;
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
MSG(0, " - Data offset : 0x%x (4KB), %'u (bytes)\n",
|
|
|
|
bidx, bidx * 4096);
|
|
|
|
free(node_blk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_node_offset(u32 blk_addr)
|
|
|
|
{
|
|
|
|
struct f2fs_node *node_blk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
node_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk);
|
|
|
|
|
|
|
|
ret = dev_read_block(node_blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
MSG(0, " - Node offset : 0x%x\n", ofs_of_node(node_blk));
|
|
|
|
free(node_blk);
|
|
|
|
}
|
|
|
|
|
2018-01-30 11:23:12 +00:00
|
|
|
static int has_dirent(u32 blk_addr, int is_inline, int *enc_name)
|
|
|
|
{
|
|
|
|
struct f2fs_node *node_blk;
|
|
|
|
int ret, is_dentry = 0;
|
|
|
|
|
|
|
|
node_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk);
|
|
|
|
|
|
|
|
ret = dev_read_block(node_blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if (IS_INODE(node_blk) && S_ISDIR(le16_to_cpu(node_blk->i.i_mode)))
|
|
|
|
is_dentry = 1;
|
|
|
|
|
|
|
|
if (is_inline && !(node_blk->i.i_inline & F2FS_INLINE_DENTRY))
|
|
|
|
is_dentry = 0;
|
|
|
|
|
|
|
|
*enc_name = file_is_encrypt(&node_blk->i);
|
|
|
|
|
|
|
|
free(node_blk);
|
|
|
|
|
|
|
|
return is_dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_dirent(u32 blk_addr, int is_inline, int enc_name)
|
|
|
|
{
|
|
|
|
struct f2fs_dentry_ptr d;
|
|
|
|
void *inline_dentry, *blk;
|
|
|
|
int ret, i = 0;
|
|
|
|
|
|
|
|
blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(blk);
|
|
|
|
|
|
|
|
ret = dev_read_block(blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if (is_inline) {
|
|
|
|
inline_dentry = inline_data_addr((struct f2fs_node *)blk);
|
|
|
|
make_dentry_ptr(&d, blk, inline_dentry, 2);
|
|
|
|
} else {
|
|
|
|
make_dentry_ptr(&d, NULL, blk, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG(1, "%sDentry block:\n", is_inline ? "Inline " : "");
|
|
|
|
|
|
|
|
while (i < d.max) {
|
|
|
|
struct f2fs_dir_entry *de;
|
2019-04-24 17:59:09 +00:00
|
|
|
char en[F2FS_PRINT_NAMELEN];
|
|
|
|
u16 name_len;
|
2018-01-30 11:23:12 +00:00
|
|
|
int enc;
|
|
|
|
|
|
|
|
if (!test_bit_le(i, d.bitmap)) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
de = &d.dentry[i];
|
|
|
|
|
|
|
|
if (!de->name_len) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
name_len = le16_to_cpu(de->name_len);
|
|
|
|
enc = enc_name;
|
|
|
|
|
|
|
|
if (de->file_type == F2FS_FT_DIR) {
|
|
|
|
if ((d.filename[i][0] == '.' && name_len == 1) ||
|
|
|
|
(d.filename[i][0] == '.' &&
|
|
|
|
d.filename[i][1] == '.' && name_len == 2)) {
|
|
|
|
enc = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
pretty_print_filename(d.filename[i], name_len, en, enc);
|
2018-01-30 11:23:12 +00:00
|
|
|
|
|
|
|
DBG(1, "bitmap pos[0x%x] name[%s] len[0x%x] hash[0x%x] ino[0x%x] type[0x%x]\n",
|
|
|
|
i, en,
|
2019-04-24 17:59:09 +00:00
|
|
|
name_len,
|
2018-01-30 11:23:12 +00:00
|
|
|
le32_to_cpu(de->hash_code),
|
|
|
|
le32_to_cpu(de->ino),
|
|
|
|
de->file_type);
|
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
i += GET_DENTRY_SLOTS(name_len);
|
2018-01-30 11:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(blk);
|
|
|
|
}
|
|
|
|
|
2014-12-13 21:55:59 +00:00
|
|
|
int dump_info_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr)
|
|
|
|
{
|
|
|
|
nid_t nid;
|
|
|
|
int type;
|
|
|
|
struct f2fs_summary sum_entry;
|
|
|
|
struct node_info ni, ino_ni;
|
2018-01-30 11:23:12 +00:00
|
|
|
int enc_name;
|
2014-12-13 21:55:59 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
MSG(0, "\n== Dump data from block address ==\n\n");
|
|
|
|
|
|
|
|
if (blk_addr < SM_I(sbi)->seg0_blkaddr) {
|
|
|
|
MSG(0, "\nFS Reserved Area for SEG #0: ");
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else if (blk_addr < SIT_I(sbi)->sit_base_addr) {
|
|
|
|
MSG(0, "\nFS Metadata Area: ");
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else if (blk_addr < NM_I(sbi)->nat_blkaddr) {
|
|
|
|
MSG(0, "\nFS SIT Area: ");
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else if (blk_addr < SM_I(sbi)->ssa_blkaddr) {
|
|
|
|
MSG(0, "\nFS NAT Area: ");
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else if (blk_addr < SM_I(sbi)->main_blkaddr) {
|
|
|
|
MSG(0, "\nFS SSA Area: ");
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else if (blk_addr > __end_block_addr(sbi)) {
|
|
|
|
MSG(0, "\nOut of address space: ");
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
MSG(0, "User data is from 0x%x to 0x%x\n\n",
|
|
|
|
SM_I(sbi)->main_blkaddr,
|
|
|
|
__end_block_addr(sbi));
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-18 02:20:05 +00:00
|
|
|
|
2018-03-07 03:59:54 +00:00
|
|
|
if (!is_sit_bitmap_set(sbi, blk_addr))
|
2018-01-04 01:51:03 +00:00
|
|
|
MSG(0, "\nblkaddr is not valid\n");
|
|
|
|
|
2014-02-05 16:09:36 +00:00
|
|
|
type = get_sum_entry(sbi, blk_addr, &sum_entry);
|
2013-07-18 02:20:05 +00:00
|
|
|
nid = le32_to_cpu(sum_entry.nid);
|
|
|
|
|
2014-08-27 23:39:23 +00:00
|
|
|
get_node_info(sbi, nid, &ni);
|
2013-07-18 02:20:05 +00:00
|
|
|
|
2014-02-05 16:09:36 +00:00
|
|
|
DBG(1, "Note: blkaddr = main_blkaddr + segno * 512 + offset\n");
|
|
|
|
DBG(1, "Block_addr [0x%x]\n", blk_addr);
|
|
|
|
DBG(1, " - Segno [0x%x]\n", GET_SEGNO(sbi, blk_addr));
|
|
|
|
DBG(1, " - Offset [0x%x]\n", OFFSET_IN_SEG(sbi, blk_addr));
|
|
|
|
DBG(1, "SUM.nid [0x%x]\n", nid);
|
2015-03-27 04:27:56 +00:00
|
|
|
DBG(1, "SUM.type [%s]\n", type >= 0 ?
|
|
|
|
seg_type_name[type] :
|
|
|
|
"Broken");
|
2014-02-05 16:09:36 +00:00
|
|
|
DBG(1, "SUM.version [%d]\n", sum_entry.version);
|
2014-12-13 21:55:59 +00:00
|
|
|
DBG(1, "SUM.ofs_in_node [0x%x]\n", sum_entry.ofs_in_node);
|
2014-02-05 16:09:36 +00:00
|
|
|
DBG(1, "NAT.blkaddr [0x%x]\n", ni.blk_addr);
|
|
|
|
DBG(1, "NAT.ino [0x%x]\n", ni.ino);
|
|
|
|
|
2014-12-13 21:55:59 +00:00
|
|
|
get_node_info(sbi, ni.ino, &ino_ni);
|
2013-07-18 02:20:05 +00:00
|
|
|
|
2014-12-13 21:55:59 +00:00
|
|
|
/* inode block address */
|
|
|
|
if (ni.blk_addr == NULL_ADDR || ino_ni.blk_addr == NULL_ADDR) {
|
|
|
|
MSG(0, "FS Userdata Area: Obsolete block from 0x%x\n",
|
|
|
|
blk_addr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-02-05 16:09:36 +00:00
|
|
|
|
2014-12-13 21:55:59 +00:00
|
|
|
/* print inode */
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.dbg_lv > 0)
|
2017-11-03 04:25:12 +00:00
|
|
|
dump_node_from_blkaddr(sbi, ino_ni.blk_addr);
|
2014-12-13 21:55:59 +00:00
|
|
|
|
|
|
|
if (type == SEG_TYPE_CUR_DATA || type == SEG_TYPE_DATA) {
|
|
|
|
MSG(0, "FS Userdata Area: Data block from 0x%x\n", blk_addr);
|
|
|
|
MSG(0, " - Direct node block : id = 0x%x from 0x%x\n",
|
|
|
|
nid, ni.blk_addr);
|
|
|
|
MSG(0, " - Inode block : id = 0x%x from 0x%x\n",
|
|
|
|
ni.ino, ino_ni.blk_addr);
|
2017-11-03 04:25:12 +00:00
|
|
|
dump_node_from_blkaddr(sbi, ino_ni.blk_addr);
|
2014-12-13 21:55:59 +00:00
|
|
|
dump_data_offset(ni.blk_addr,
|
|
|
|
le16_to_cpu(sum_entry.ofs_in_node));
|
2018-01-30 11:23:12 +00:00
|
|
|
|
|
|
|
if (has_dirent(ino_ni.blk_addr, 0, &enc_name))
|
|
|
|
dump_dirent(blk_addr, 0, enc_name);
|
2013-07-18 02:20:05 +00:00
|
|
|
} else {
|
2014-12-13 21:55:59 +00:00
|
|
|
MSG(0, "FS Userdata Area: Node block from 0x%x\n", blk_addr);
|
|
|
|
if (ni.ino == ni.nid) {
|
|
|
|
MSG(0, " - Inode block : id = 0x%x from 0x%x\n",
|
|
|
|
ni.ino, ino_ni.blk_addr);
|
2017-11-03 04:25:12 +00:00
|
|
|
dump_node_from_blkaddr(sbi, ino_ni.blk_addr);
|
2018-01-30 11:23:12 +00:00
|
|
|
|
|
|
|
if (has_dirent(ino_ni.blk_addr, 1, &enc_name))
|
|
|
|
dump_dirent(blk_addr, 1, enc_name);
|
2014-12-13 21:55:59 +00:00
|
|
|
} else {
|
|
|
|
MSG(0, " - Node block : id = 0x%x from 0x%x\n",
|
|
|
|
nid, ni.blk_addr);
|
|
|
|
MSG(0, " - Inode block : id = 0x%x from 0x%x\n",
|
|
|
|
ni.ino, ino_ni.blk_addr);
|
2017-11-03 04:25:12 +00:00
|
|
|
dump_node_from_blkaddr(sbi, ino_ni.blk_addr);
|
2014-12-13 21:55:59 +00:00
|
|
|
dump_node_offset(ni.blk_addr);
|
|
|
|
}
|
2013-07-18 02:20:05 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 21:55:59 +00:00
|
|
|
return 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
|
|
|
}
|