f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
/**
|
|
|
|
* fsck.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.
|
|
|
|
*/
|
|
|
|
#include "fsck.h"
|
2019-03-04 09:21:37 +00:00
|
|
|
#include "xattr.h"
|
2017-10-30 23:21:09 +00:00
|
|
|
#include "quotaio.h"
|
2018-03-06 03:39:40 +00:00
|
|
|
#include <time.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
|
|
|
|
2013-07-30 07:39:06 +00:00
|
|
|
char *tree_mark;
|
2014-05-14 00:02:55 +00:00
|
|
|
uint32_t tree_mark_size = 256;
|
2013-07-30 07:39:06 +00:00
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
int f2fs_set_main_bitmap(struct f2fs_sb_info *sbi, u32 blk, int type)
|
2014-08-27 23:16:16 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2014-11-06 04:25:49 +00:00
|
|
|
struct seg_entry *se;
|
2015-09-24 16:45:16 +00:00
|
|
|
int fix = 0;
|
2014-11-06 04:25:49 +00:00
|
|
|
|
|
|
|
se = get_seg_entry(sbi, GET_SEGNO(sbi, blk));
|
2016-01-13 19:51:33 +00:00
|
|
|
if (se->type >= NO_CHECK_TYPE)
|
2015-09-24 16:45:16 +00:00
|
|
|
fix = 1;
|
|
|
|
else if (IS_DATASEG(se->type) != IS_DATASEG(type))
|
|
|
|
fix = 1;
|
|
|
|
|
|
|
|
/* just check data and node types */
|
|
|
|
if (fix) {
|
|
|
|
DBG(1, "Wrong segment type [0x%x] %x -> %x",
|
2014-11-06 04:25:49 +00:00
|
|
|
GET_SEGNO(sbi, blk), se->type, type);
|
2015-09-24 16:45:16 +00:00
|
|
|
se->type = type;
|
2014-11-06 04:25:49 +00:00
|
|
|
}
|
2014-08-27 23:16:16 +00:00
|
|
|
return f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, blk), fsck->main_area_bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int f2fs_test_main_bitmap(struct f2fs_sb_info *sbi, u32 blk)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
|
|
|
|
return f2fs_test_bit(BLKOFF_FROM_MAIN(sbi, blk),
|
|
|
|
fsck->main_area_bitmap);
|
|
|
|
}
|
|
|
|
|
2018-03-06 03:39:40 +00:00
|
|
|
static inline int f2fs_clear_main_bitmap(struct f2fs_sb_info *sbi, u32 blk)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
|
|
|
|
return f2fs_clear_bit(BLKOFF_FROM_MAIN(sbi, blk),
|
|
|
|
fsck->main_area_bitmap);
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
static inline int f2fs_test_sit_bitmap(struct f2fs_sb_info *sbi, u32 blk)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
|
|
|
|
return f2fs_test_bit(BLKOFF_FROM_MAIN(sbi, blk), fsck->sit_area_bitmap);
|
|
|
|
}
|
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
int f2fs_set_sit_bitmap(struct f2fs_sb_info *sbi, u32 blk)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
|
|
|
|
return f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, blk), fsck->sit_area_bitmap);
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
static int add_into_hard_link_list(struct f2fs_sb_info *sbi,
|
|
|
|
u32 nid, u32 link_cnt)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct hard_link_node *node = NULL, *tmp = NULL, *prev = NULL;
|
|
|
|
|
|
|
|
node = calloc(sizeof(struct hard_link_node), 1);
|
|
|
|
ASSERT(node != NULL);
|
|
|
|
|
|
|
|
node->nid = nid;
|
|
|
|
node->links = link_cnt;
|
2015-03-26 01:26:44 +00:00
|
|
|
node->actual_links = 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
|
|
|
node->next = NULL;
|
|
|
|
|
|
|
|
if (fsck->hard_link_list_head == NULL) {
|
|
|
|
fsck->hard_link_list_head = node;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = fsck->hard_link_list_head;
|
|
|
|
|
|
|
|
/* Find insertion position */
|
|
|
|
while (tmp && (nid < tmp->nid)) {
|
|
|
|
ASSERT(tmp->nid != nid);
|
|
|
|
prev = tmp;
|
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp == fsck->hard_link_list_head) {
|
|
|
|
node->next = tmp;
|
|
|
|
fsck->hard_link_list_head = node;
|
|
|
|
} else {
|
|
|
|
prev->next = node;
|
|
|
|
node->next = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
DBG(2, "ino[0x%x] has hard links [0x%x]\n", nid, link_cnt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_and_dec_hard_link_list(struct f2fs_sb_info *sbi, u32 nid)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct hard_link_node *node = NULL, *prev = NULL;
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
if (fsck->hard_link_list_head == NULL)
|
|
|
|
return -EINVAL;
|
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 = fsck->hard_link_list_head;
|
|
|
|
|
|
|
|
while (node && (nid < node->nid)) {
|
|
|
|
prev = node;
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
if (node == NULL || (nid != node->nid))
|
|
|
|
return -EINVAL;
|
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
|
|
|
|
|
|
|
/* Decrease link count */
|
|
|
|
node->links = node->links - 1;
|
2015-03-26 01:26:44 +00:00
|
|
|
node->actual_links++;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
|
|
|
/* if link count becomes one, remove the node */
|
|
|
|
if (node->links == 1) {
|
|
|
|
if (fsck->hard_link_list_head == node)
|
|
|
|
fsck->hard_link_list_head = node->next;
|
|
|
|
else
|
|
|
|
prev->next = node->next;
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
|
|
|
|
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
|
|
|
{
|
2015-03-27 04:49:43 +00:00
|
|
|
struct f2fs_summary_block *sum_blk;
|
|
|
|
struct f2fs_summary *sum_entry;
|
2016-01-30 02:26:29 +00:00
|
|
|
struct seg_entry * se;
|
2015-03-27 04:49:43 +00:00
|
|
|
u32 segno, offset;
|
|
|
|
int need_fix = 0, ret = 0;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
segno = GET_SEGNO(sbi, blk_addr);
|
|
|
|
offset = OFFSET_IN_SEG(sbi, blk_addr);
|
|
|
|
|
|
|
|
sum_blk = get_sum_block(sbi, segno, &type);
|
|
|
|
|
|
|
|
if (type != SEG_TYPE_NODE && type != SEG_TYPE_CUR_NODE) {
|
|
|
|
/* can't fix current summary, then drop the block */
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on || type < 0) {
|
2015-03-27 04:49:43 +00:00
|
|
|
ASSERT_MSG("Summary footer is not for node segment");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2016-01-30 02:26:29 +00:00
|
|
|
|
2015-03-27 04:49:43 +00:00
|
|
|
need_fix = 1;
|
2016-01-30 02:26:29 +00:00
|
|
|
se = get_seg_entry(sbi, segno);
|
|
|
|
if(IS_NODESEG(se->type)) {
|
|
|
|
FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
|
|
|
|
sum_blk->footer.entry_type = SUM_TYPE_NODE;
|
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-27 04:49:43 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-03-27 04:49:43 +00:00
|
|
|
sum_entry = &(sum_blk->entries[offset]);
|
|
|
|
|
|
|
|
if (le32_to_cpu(sum_entry->nid) != nid) {
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on || type < 0) {
|
2015-03-27 04:49:43 +00:00
|
|
|
DBG(0, "nid [0x%x]\n", nid);
|
|
|
|
DBG(0, "target blk_addr [0x%x]\n", blk_addr);
|
|
|
|
DBG(0, "summary blk_addr [0x%x]\n",
|
|
|
|
GET_SUM_BLKADDR(sbi,
|
|
|
|
GET_SEGNO(sbi, blk_addr)));
|
|
|
|
DBG(0, "seg no / offset [0x%x / 0x%x]\n",
|
|
|
|
GET_SEGNO(sbi, blk_addr),
|
|
|
|
OFFSET_IN_SEG(sbi, blk_addr));
|
|
|
|
DBG(0, "summary_entry.nid [0x%x]\n",
|
|
|
|
le32_to_cpu(sum_entry->nid));
|
|
|
|
DBG(0, "--> node block's nid [0x%x]\n", nid);
|
|
|
|
ASSERT_MSG("Invalid node seg summary\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else {
|
|
|
|
FIX_MSG("Set node summary 0x%x -> [0x%x] [0x%x]",
|
|
|
|
segno, nid, blk_addr);
|
|
|
|
sum_entry->nid = cpu_to_le32(nid);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2014-08-28 20:49:04 +00:00
|
|
|
}
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable()) {
|
2015-03-27 04:49:43 +00:00
|
|
|
u64 ssa_blk;
|
|
|
|
int ret2;
|
2014-08-28 20:49:04 +00:00
|
|
|
|
2015-03-27 04:49:43 +00:00
|
|
|
ssa_blk = GET_SUM_BLKADDR(sbi, segno);
|
|
|
|
ret2 = dev_write_block(sum_blk, ssa_blk);
|
|
|
|
ASSERT(ret2 >= 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
|
|
|
}
|
2015-03-27 04:49:43 +00:00
|
|
|
out:
|
|
|
|
if (type == SEG_TYPE_NODE || type == SEG_TYPE_DATA ||
|
|
|
|
type == SEG_TYPE_MAX)
|
|
|
|
free(sum_blk);
|
|
|
|
return ret;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 01:19:53 +00:00
|
|
|
static int is_valid_summary(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
|
|
|
|
u32 blk_addr)
|
|
|
|
{
|
|
|
|
u16 ofs_in_node = le16_to_cpu(sum->ofs_in_node);
|
|
|
|
u32 nid = le32_to_cpu(sum->nid);
|
|
|
|
struct f2fs_node *node_blk = NULL;
|
|
|
|
__le32 target_blk_addr;
|
|
|
|
struct node_info ni;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk != NULL);
|
|
|
|
|
|
|
|
if (!IS_VALID_NID(sbi, nid))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
|
|
|
|
if (!IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* read node_block */
|
|
|
|
ret = dev_read_block(node_blk, ni.blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if (le32_to_cpu(node_blk->footer.nid) != nid)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* check its block address */
|
2017-07-26 14:49:57 +00:00
|
|
|
if (node_blk->footer.nid == node_blk->footer.ino) {
|
|
|
|
int ofs = get_extra_isize(node_blk);
|
|
|
|
|
|
|
|
target_blk_addr = node_blk->i.i_addr[ofs + ofs_in_node];
|
|
|
|
} else {
|
2015-07-02 01:19:53 +00:00
|
|
|
target_blk_addr = node_blk->dn.addr[ofs_in_node];
|
2017-07-26 14:49:57 +00:00
|
|
|
}
|
2015-07-02 01:19:53 +00:00
|
|
|
|
|
|
|
if (blk_addr == le32_to_cpu(target_blk_addr))
|
|
|
|
ret = 1;
|
|
|
|
out:
|
|
|
|
free(node_blk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
|
|
|
|
u32 parent_nid, u16 idx_in_node, u8 version)
|
|
|
|
{
|
2015-03-27 04:49:43 +00:00
|
|
|
struct f2fs_summary_block *sum_blk;
|
|
|
|
struct f2fs_summary *sum_entry;
|
2016-01-30 02:26:29 +00:00
|
|
|
struct seg_entry * se;
|
2015-03-27 04:49:43 +00:00
|
|
|
u32 segno, offset;
|
|
|
|
int need_fix = 0, ret = 0;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
segno = GET_SEGNO(sbi, blk_addr);
|
|
|
|
offset = OFFSET_IN_SEG(sbi, blk_addr);
|
|
|
|
|
|
|
|
sum_blk = get_sum_block(sbi, segno, &type);
|
|
|
|
|
|
|
|
if (type != SEG_TYPE_DATA && type != SEG_TYPE_CUR_DATA) {
|
|
|
|
/* can't fix current summary, then drop the block */
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on || type < 0) {
|
2015-03-27 04:49:43 +00:00
|
|
|
ASSERT_MSG("Summary footer is not for data segment");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2016-01-30 02:26:29 +00:00
|
|
|
|
2015-03-27 04:49:43 +00:00
|
|
|
need_fix = 1;
|
2016-01-30 02:26:29 +00:00
|
|
|
se = get_seg_entry(sbi, segno);
|
|
|
|
if (IS_DATASEG(se->type)) {
|
|
|
|
FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
|
|
|
|
sum_blk->footer.entry_type = SUM_TYPE_DATA;
|
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-08-28 20:49:04 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-03-27 04:49:43 +00:00
|
|
|
sum_entry = &(sum_blk->entries[offset]);
|
|
|
|
|
|
|
|
if (le32_to_cpu(sum_entry->nid) != parent_nid ||
|
|
|
|
sum_entry->version != version ||
|
|
|
|
le16_to_cpu(sum_entry->ofs_in_node) != idx_in_node) {
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on || type < 0) {
|
2015-03-27 04:49:43 +00:00
|
|
|
DBG(0, "summary_entry.nid [0x%x]\n",
|
|
|
|
le32_to_cpu(sum_entry->nid));
|
|
|
|
DBG(0, "summary_entry.version [0x%x]\n",
|
|
|
|
sum_entry->version);
|
|
|
|
DBG(0, "summary_entry.ofs_in_node [0x%x]\n",
|
|
|
|
le16_to_cpu(sum_entry->ofs_in_node));
|
|
|
|
DBG(0, "parent nid [0x%x]\n",
|
|
|
|
parent_nid);
|
|
|
|
DBG(0, "version from nat [0x%x]\n", version);
|
|
|
|
DBG(0, "idx in parent node [0x%x]\n",
|
|
|
|
idx_in_node);
|
|
|
|
|
|
|
|
DBG(0, "Target data block addr [0x%x]\n", blk_addr);
|
|
|
|
ASSERT_MSG("Invalid data seg summary\n");
|
|
|
|
ret = -EINVAL;
|
2015-07-02 01:19:53 +00:00
|
|
|
} else if (is_valid_summary(sbi, sum_entry, blk_addr)) {
|
|
|
|
/* delete wrong index */
|
|
|
|
ret = -EINVAL;
|
2015-03-27 04:49:43 +00:00
|
|
|
} else {
|
|
|
|
FIX_MSG("Set data summary 0x%x -> [0x%x] [0x%x] [0x%x]",
|
|
|
|
segno, parent_nid, version, idx_in_node);
|
|
|
|
sum_entry->nid = cpu_to_le32(parent_nid);
|
|
|
|
sum_entry->version = version;
|
|
|
|
sum_entry->ofs_in_node = cpu_to_le16(idx_in_node);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable()) {
|
2015-03-27 04:49:43 +00:00
|
|
|
u64 ssa_blk;
|
|
|
|
int ret2;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-03-27 04:49:43 +00:00
|
|
|
ssa_blk = GET_SUM_BLKADDR(sbi, segno);
|
|
|
|
ret2 = dev_write_block(sum_blk, ssa_blk);
|
|
|
|
ASSERT(ret2 >= 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
|
|
|
}
|
2015-03-27 04:49:43 +00:00
|
|
|
out:
|
|
|
|
if (type == SEG_TYPE_NODE || type == SEG_TYPE_DATA ||
|
|
|
|
type == SEG_TYPE_MAX)
|
|
|
|
free(sum_blk);
|
|
|
|
return ret;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 01:45:31 +00:00
|
|
|
static int __check_inode_mode(u32 nid, enum FILE_TYPE ftype, u16 mode)
|
2015-03-26 00:43:57 +00:00
|
|
|
{
|
|
|
|
if (ftype >= F2FS_FT_MAX)
|
|
|
|
return 0;
|
2018-02-23 03:17:58 +00:00
|
|
|
/* f2fs_iget will return -EIO if mode is not valid file type */
|
|
|
|
if (!S_ISLNK(mode) && !S_ISREG(mode) && !S_ISDIR(mode) &&
|
|
|
|
!S_ISCHR(mode) && !S_ISBLK(mode) && !S_ISFIFO(mode) &&
|
|
|
|
!S_ISSOCK(mode)) {
|
|
|
|
ASSERT_MSG("inode [0x%x] unknown file type i_mode [0x%x]",
|
|
|
|
nid, mode);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:43:57 +00:00
|
|
|
if (S_ISLNK(mode) && ftype != F2FS_FT_SYMLINK)
|
|
|
|
goto err;
|
|
|
|
if (S_ISREG(mode) && ftype != F2FS_FT_REG_FILE)
|
|
|
|
goto err;
|
|
|
|
if (S_ISDIR(mode) && ftype != F2FS_FT_DIR)
|
|
|
|
goto err;
|
|
|
|
if (S_ISCHR(mode) && ftype != F2FS_FT_CHRDEV)
|
|
|
|
goto err;
|
|
|
|
if (S_ISBLK(mode) && ftype != F2FS_FT_BLKDEV)
|
|
|
|
goto err;
|
|
|
|
if (S_ISFIFO(mode) && ftype != F2FS_FT_FIFO)
|
|
|
|
goto err;
|
|
|
|
if (S_ISSOCK(mode) && ftype != F2FS_FT_SOCK)
|
|
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
err:
|
2018-02-23 03:17:58 +00:00
|
|
|
ASSERT_MSG("inode [0x%x] mismatch i_mode [0x%x vs. 0x%x]",
|
|
|
|
nid, ftype, mode);
|
2015-03-26 00:43:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
|
|
|
|
struct f2fs_node *node_blk,
|
|
|
|
enum FILE_TYPE ftype, enum NODE_TYPE ntype,
|
2017-06-05 20:44:50 +00:00
|
|
|
struct node_info *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
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2014-08-28 00:06:17 +00:00
|
|
|
int ret;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-08-27 23:32:06 +00:00
|
|
|
if (!IS_VALID_NID(sbi, nid)) {
|
2014-08-27 23:16:16 +00:00
|
|
|
ASSERT_MSG("nid is not valid. [0x%x]", nid);
|
2014-08-28 00:06:17 +00:00
|
|
|
return -EINVAL;
|
2014-08-27 23:32:06 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
get_node_info(sbi, nid, ni);
|
2016-01-30 09:16:38 +00:00
|
|
|
if (ni->ino == 0) {
|
|
|
|
ASSERT_MSG("nid[0x%x] ino is 0", nid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
if (ni->blk_addr == NEW_ADDR) {
|
|
|
|
ASSERT_MSG("nid is NEW_ADDR. [0x%x]", nid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
if (!IS_VALID_BLK_ADDR(sbi, ni->blk_addr)) {
|
2016-07-15 12:01:22 +00:00
|
|
|
ASSERT_MSG("blkaddress is not valid. [0x%x]", ni->blk_addr);
|
2014-08-28 00:06:17 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
ret = dev_read_block(node_blk, ni->blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
if (ntype == TYPE_INODE &&
|
|
|
|
node_blk->footer.nid != node_blk->footer.ino) {
|
|
|
|
ASSERT_MSG("nid[0x%x] footer.nid[0x%x] footer.ino[0x%x]",
|
|
|
|
nid, le32_to_cpu(node_blk->footer.nid),
|
|
|
|
le32_to_cpu(node_blk->footer.ino));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-07-15 12:01:20 +00:00
|
|
|
if (ni->ino != le32_to_cpu(node_blk->footer.ino)) {
|
2016-02-22 17:01:15 +00:00
|
|
|
ASSERT_MSG("nid[0x%x] nat_entry->ino[0x%x] footer.ino[0x%x]",
|
2016-01-30 09:16:39 +00:00
|
|
|
nid, ni->ino, le32_to_cpu(node_blk->footer.ino));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-08-28 00:06:17 +00:00
|
|
|
if (ntype != TYPE_INODE &&
|
|
|
|
node_blk->footer.nid == node_blk->footer.ino) {
|
|
|
|
ASSERT_MSG("nid[0x%x] footer.nid[0x%x] footer.ino[0x%x]",
|
|
|
|
nid, le32_to_cpu(node_blk->footer.nid),
|
|
|
|
le32_to_cpu(node_blk->footer.ino));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (le32_to_cpu(node_blk->footer.nid) != nid) {
|
|
|
|
ASSERT_MSG("nid[0x%x] blk_addr[0x%x] footer.nid[0x%x]",
|
|
|
|
nid, ni->blk_addr,
|
|
|
|
le32_to_cpu(node_blk->footer.nid));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntype == TYPE_XATTR) {
|
|
|
|
u32 flag = le32_to_cpu(node_blk->footer.flag);
|
|
|
|
|
|
|
|
if ((flag >> OFFSET_BIT_SHIFT) != XATTR_NODE_OFFSET) {
|
|
|
|
ASSERT_MSG("xnid[0x%x] has wrong ofs:[0x%x]",
|
|
|
|
nid, flag);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ntype == TYPE_INODE && ftype == F2FS_FT_DIR) ||
|
|
|
|
(ntype == TYPE_XATTR && ftype == F2FS_FT_XATTR)) {
|
|
|
|
/* not included '.' & '..' */
|
|
|
|
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) != 0) {
|
|
|
|
ASSERT_MSG("Duplicated node blk. nid[0x%x][0x%x]\n",
|
|
|
|
nid, ni->blk_addr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-08-27 23:32:06 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-03-26 01:26:44 +00:00
|
|
|
/* this if only from fix_hard_links */
|
|
|
|
if (ftype == F2FS_FT_MAX)
|
|
|
|
return 0;
|
|
|
|
|
2015-03-26 00:43:57 +00:00
|
|
|
if (ntype == TYPE_INODE &&
|
2018-12-08 01:45:31 +00:00
|
|
|
__check_inode_mode(nid, ftype, le16_to_cpu(node_blk->i.i_mode)))
|
2015-03-26 00:43:57 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
/* workaround to fix later */
|
|
|
|
if (ftype != F2FS_FT_ORPHAN ||
|
2018-03-06 03:39:40 +00:00
|
|
|
f2fs_test_bit(nid, fsck->nat_area_bitmap) != 0) {
|
2014-08-28 00:06:17 +00:00
|
|
|
f2fs_clear_bit(nid, fsck->nat_area_bitmap);
|
2018-03-06 03:39:40 +00:00
|
|
|
/* avoid reusing nid when reconnecting files */
|
|
|
|
f2fs_set_bit(nid, NM_I(sbi)->nid_bitmap);
|
|
|
|
} else
|
2014-08-28 00:06:17 +00:00
|
|
|
ASSERT_MSG("orphan or xattr nid is duplicated [0x%x]\n",
|
|
|
|
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
|
|
|
|
2016-01-30 02:26:29 +00:00
|
|
|
if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
|
|
|
|
ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
if (f2fs_test_sit_bitmap(sbi, ni->blk_addr) == 0)
|
|
|
|
ASSERT_MSG("SIT bitmap is 0x0. blk_addr[0x%x]",
|
|
|
|
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
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 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
|
|
|
fsck->chk.valid_blk_cnt++;
|
|
|
|
fsck->chk.valid_node_cnt++;
|
|
|
|
}
|
2014-08-28 00:06:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 17:56:14 +00:00
|
|
|
static int fsck_chk_xattr_blk(struct f2fs_sb_info *sbi, u32 ino,
|
|
|
|
u32 x_nid, u32 *blk_cnt)
|
|
|
|
{
|
|
|
|
struct f2fs_node *node_blk = NULL;
|
|
|
|
struct node_info ni;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (x_nid == 0x0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk != NULL);
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (sanity_check_nid(sbi, x_nid, node_blk,
|
2017-06-05 20:44:50 +00:00
|
|
|
F2FS_FT_XATTR, TYPE_XATTR, &ni)) {
|
2014-08-28 17:56:14 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
*blk_cnt = *blk_cnt + 1;
|
2014-11-06 04:25:49 +00:00
|
|
|
f2fs_set_main_bitmap(sbi, ni.blk_addr, CURSEG_COLD_NODE);
|
2014-08-28 17:56:14 +00:00
|
|
|
DBG(2, "ino[0x%x] x_nid[0x%x]\n", ino, x_nid);
|
|
|
|
out:
|
|
|
|
free(node_blk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
int fsck_chk_node_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
|
2017-06-05 20:44:50 +00:00
|
|
|
u32 nid, enum FILE_TYPE ftype, enum NODE_TYPE ntype,
|
2016-03-16 03:07:07 +00:00
|
|
|
u32 *blk_cnt, struct child_info *child)
|
2014-08-28 00:06:17 +00:00
|
|
|
{
|
|
|
|
struct node_info ni;
|
|
|
|
struct f2fs_node *node_blk = NULL;
|
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 = (struct f2fs_node *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk != NULL);
|
|
|
|
|
2017-06-05 20:44:50 +00:00
|
|
|
if (sanity_check_nid(sbi, nid, node_blk, ftype, ntype, &ni))
|
2014-08-28 00:06:17 +00:00
|
|
|
goto err;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
|
|
|
if (ntype == TYPE_INODE) {
|
2017-10-30 23:21:09 +00:00
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2017-11-02 03:56:10 +00:00
|
|
|
|
2017-12-18 13:25:27 +00:00
|
|
|
fsck_chk_inode_blk(sbi, nid, ftype, node_blk, blk_cnt, &ni, child);
|
2017-10-30 23:21:09 +00:00
|
|
|
quota_add_inode_usage(fsck->qctx, nid, &node_blk->i);
|
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 {
|
|
|
|
switch (ntype) {
|
|
|
|
case TYPE_DIRECT_NODE:
|
2014-11-06 04:25:49 +00:00
|
|
|
f2fs_set_main_bitmap(sbi, ni.blk_addr,
|
|
|
|
CURSEG_WARM_NODE);
|
2014-08-28 00:06:17 +00:00
|
|
|
fsck_chk_dnode_blk(sbi, inode, nid, ftype, node_blk,
|
2016-03-16 03:07:07 +00:00
|
|
|
blk_cnt, child, &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
|
|
|
break;
|
|
|
|
case TYPE_INDIRECT_NODE:
|
2014-11-06 04:25:49 +00:00
|
|
|
f2fs_set_main_bitmap(sbi, ni.blk_addr,
|
|
|
|
CURSEG_COLD_NODE);
|
2014-08-28 00:06:17 +00:00
|
|
|
fsck_chk_idnode_blk(sbi, inode, ftype, node_blk,
|
2016-03-16 03:07:07 +00:00
|
|
|
blk_cnt, child);
|
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 TYPE_DOUBLE_INDIRECT_NODE:
|
2014-11-06 04:25:49 +00:00
|
|
|
f2fs_set_main_bitmap(sbi, ni.blk_addr,
|
|
|
|
CURSEG_COLD_NODE);
|
2014-08-28 00:06:17 +00:00
|
|
|
fsck_chk_didnode_blk(sbi, inode, ftype, node_blk,
|
2016-03-16 03:07:07 +00:00
|
|
|
blk_cnt, child);
|
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;
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(node_blk);
|
|
|
|
return 0;
|
2014-08-28 00:06:17 +00:00
|
|
|
err:
|
|
|
|
free(node_blk);
|
|
|
|
return -EINVAL;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
static inline void get_extent_info(struct extent_info *ext,
|
|
|
|
struct f2fs_extent *i_ext)
|
2015-12-08 22:53:21 +00:00
|
|
|
{
|
2016-03-16 03:07:07 +00:00
|
|
|
ext->fofs = le32_to_cpu(i_ext->fofs);
|
|
|
|
ext->blk = le32_to_cpu(i_ext->blk_addr);
|
|
|
|
ext->len = le32_to_cpu(i_ext->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_extent_info(struct child_info *child,
|
|
|
|
block_t blkaddr, int last)
|
|
|
|
{
|
|
|
|
struct extent_info *ei = &child->ei;
|
|
|
|
u32 pgofs = child->pgofs;
|
|
|
|
int is_hole = 0;
|
|
|
|
|
|
|
|
if (!ei->len)
|
|
|
|
return;
|
2015-12-08 22:53:21 +00:00
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
if (child->state & FSCK_UNMATCHED_EXTENT)
|
2015-12-08 22:53:21 +00:00
|
|
|
return;
|
|
|
|
|
2018-07-03 10:10:04 +00:00
|
|
|
if ((child->state & FSCK_INLINE_INODE) && ei->len)
|
|
|
|
goto unmatched;
|
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
if (last) {
|
|
|
|
/* hole exist in the back of extent */
|
|
|
|
if (child->last_blk != ei->blk + ei->len - 1)
|
|
|
|
child->state |= FSCK_UNMATCHED_EXTENT;
|
|
|
|
return;
|
|
|
|
}
|
2015-12-08 22:53:21 +00:00
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
if (blkaddr == NULL_ADDR || blkaddr == NEW_ADDR)
|
|
|
|
is_hole = 1;
|
2015-12-08 22:53:21 +00:00
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
if (pgofs >= ei->fofs && pgofs < ei->fofs + ei->len) {
|
|
|
|
/* unmatched blkaddr */
|
|
|
|
if (is_hole || (blkaddr != pgofs - ei->fofs + ei->blk))
|
|
|
|
goto unmatched;
|
|
|
|
|
|
|
|
if (!child->last_blk) {
|
|
|
|
/* hole exists in the front of extent */
|
|
|
|
if (pgofs != ei->fofs)
|
|
|
|
goto unmatched;
|
|
|
|
} else if (child->last_blk + 1 != blkaddr) {
|
|
|
|
/* hole exists in the middle of extent */
|
|
|
|
goto unmatched;
|
|
|
|
}
|
|
|
|
child->last_blk = blkaddr;
|
|
|
|
return;
|
2015-12-08 22:53:21 +00:00
|
|
|
}
|
2016-03-16 03:07:07 +00:00
|
|
|
|
|
|
|
if (is_hole)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (blkaddr < ei->blk || blkaddr >= ei->blk + ei->len)
|
|
|
|
return;
|
|
|
|
/* unmatched file offset */
|
|
|
|
unmatched:
|
|
|
|
child->state |= FSCK_UNMATCHED_EXTENT;
|
2015-12-08 22:53:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 09:37:41 +00:00
|
|
|
void fsck_reada_node_block(struct f2fs_sb_info *sbi, u32 nid)
|
|
|
|
{
|
|
|
|
struct node_info ni;
|
|
|
|
|
|
|
|
if (nid != 0 && IS_VALID_NID(sbi, nid)) {
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
|
|
|
|
dev_reada_block(ni.blk_addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fsck_reada_all_direct_node_blocks(struct f2fs_sb_info *sbi,
|
|
|
|
struct f2fs_node *node_blk)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NIDS_PER_BLOCK; i++) {
|
|
|
|
u32 nid = le32_to_cpu(node_blk->in.nid[i]);
|
|
|
|
|
|
|
|
fsck_reada_node_block(sbi, nid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
/* start with valid nid and blkaddr */
|
|
|
|
void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
|
|
|
|
enum FILE_TYPE ftype, struct f2fs_node *node_blk,
|
2017-12-18 13:25:27 +00:00
|
|
|
u32 *blk_cnt, struct node_info *ni, struct child_info *child_d)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2016-10-12 21:11:19 +00:00
|
|
|
struct child_info child;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
enum NODE_TYPE ntype;
|
|
|
|
u32 i_links = le32_to_cpu(node_blk->i.i_links);
|
2016-07-15 17:27:23 +00:00
|
|
|
u64 i_size = le64_to_cpu(node_blk->i.i_size);
|
2013-07-30 07:39:06 +00:00
|
|
|
u64 i_blocks = le64_to_cpu(node_blk->i.i_blocks);
|
2019-08-12 11:45:26 +00:00
|
|
|
nid_t i_xattr_nid = le32_to_cpu(node_blk->i.i_xattr_nid);
|
2018-07-10 12:29:08 +00:00
|
|
|
int ofs;
|
2019-04-24 17:59:09 +00:00
|
|
|
char *en;
|
2018-07-10 14:47:38 +00:00
|
|
|
u32 namelen;
|
2014-05-14 00:02:55 +00:00
|
|
|
unsigned int idx = 0;
|
2018-07-28 10:41:35 +00:00
|
|
|
unsigned short i_gc_failures;
|
2014-08-29 18:46:25 +00:00
|
|
|
int need_fix = 0;
|
2014-08-28 00:06:17 +00:00
|
|
|
int 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
|
|
|
|
2016-10-12 21:11:19 +00:00
|
|
|
memset(&child, 0, sizeof(child));
|
|
|
|
child.links = 2;
|
|
|
|
child.p_ino = nid;
|
|
|
|
child.pp_ino = le32_to_cpu(node_blk->i.i_pino);
|
|
|
|
child.dir_level = node_blk->i.i_dir_level;
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 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
|
|
|
fsck->chk.valid_inode_cnt++;
|
|
|
|
|
2013-10-08 09:46:55 +00:00
|
|
|
if (ftype == F2FS_FT_DIR) {
|
2014-11-06 04:25:49 +00:00
|
|
|
f2fs_set_main_bitmap(sbi, ni->blk_addr, CURSEG_HOT_NODE);
|
2013-10-08 09:46:55 +00:00
|
|
|
} else {
|
2014-08-27 23:16:16 +00:00
|
|
|
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0) {
|
2014-11-06 04:25:49 +00:00
|
|
|
f2fs_set_main_bitmap(sbi, ni->blk_addr,
|
|
|
|
CURSEG_WARM_NODE);
|
2017-10-30 23:21:09 +00:00
|
|
|
if (i_links > 1 && ftype != F2FS_FT_ORPHAN &&
|
|
|
|
!is_qf_ino(F2FS_RAW_SUPER(sbi), 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
|
|
|
/* First time. Create new hard link node */
|
|
|
|
add_into_hard_link_list(sbi, nid, i_links);
|
|
|
|
fsck->chk.multi_hard_link_files++;
|
|
|
|
}
|
|
|
|
} else {
|
2014-08-28 00:06:17 +00:00
|
|
|
DBG(3, "[0x%x] has hard links [0x%x]\n", nid, i_links);
|
|
|
|
if (find_and_dec_hard_link_list(sbi, nid)) {
|
|
|
|
ASSERT_MSG("[0x%x] needs more i_links=0x%x",
|
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
|
|
|
nid, i_links);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2014-08-29 18:46:25 +00:00
|
|
|
node_blk->i.i_links =
|
|
|
|
cpu_to_le32(i_links + 1);
|
|
|
|
need_fix = 1;
|
2014-08-28 17:27:17 +00:00
|
|
|
FIX_MSG("File: 0x%x "
|
|
|
|
"i_links= 0x%x -> 0x%x",
|
|
|
|
nid, i_links, i_links + 1);
|
2014-08-29 18:46:25 +00:00
|
|
|
}
|
2015-03-26 02:26:25 +00:00
|
|
|
goto skip_blkcnt_fix;
|
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
|
|
|
}
|
|
|
|
/* No need to go deep into the node */
|
2014-08-28 00:06:17 +00:00
|
|
|
return;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 09:37:41 +00:00
|
|
|
/* readahead xattr node block */
|
2019-08-12 11:45:26 +00:00
|
|
|
fsck_reada_node_block(sbi, i_xattr_nid);
|
2018-01-29 09:37:41 +00:00
|
|
|
|
2019-08-12 11:45:26 +00:00
|
|
|
if (fsck_chk_xattr_blk(sbi, nid, i_xattr_nid, blk_cnt)) {
|
2019-08-12 11:45:25 +00:00
|
|
|
if (c.fix_on) {
|
|
|
|
node_blk->i.i_xattr_nid = 0;
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
|
2019-08-12 11:45:26 +00:00
|
|
|
nid, i_xattr_nid);
|
2019-08-12 11:45:25 +00:00
|
|
|
}
|
2014-08-28 17:56:14 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2013-10-08 09:46:55 +00:00
|
|
|
if (ftype == F2FS_FT_CHRDEV || ftype == F2FS_FT_BLKDEV ||
|
|
|
|
ftype == F2FS_FT_FIFO || ftype == F2FS_FT_SOCK)
|
2013-10-08 09:17:33 +00:00
|
|
|
goto check;
|
2014-10-19 06:49:30 +00:00
|
|
|
|
2018-07-03 10:10:04 +00:00
|
|
|
/* init extent info */
|
|
|
|
get_extent_info(&child.ei, &node_blk->i.i_ext);
|
|
|
|
child.last_blk = 0;
|
|
|
|
|
2018-07-10 12:29:08 +00:00
|
|
|
if (f2fs_has_extra_isize(&node_blk->i)) {
|
|
|
|
if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
|
2019-08-12 11:45:25 +00:00
|
|
|
unsigned int isize =
|
|
|
|
le16_to_cpu(node_blk->i.i_extra_isize);
|
|
|
|
if (isize > 4 * DEF_ADDRS_PER_INODE) {
|
|
|
|
ASSERT_MSG("[0x%x] wrong i_extra_isize=0x%x",
|
|
|
|
nid, isize);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("ino[0x%x] recover i_extra_isize "
|
|
|
|
"from %u to %u",
|
|
|
|
nid, isize,
|
|
|
|
calc_extra_isize());
|
|
|
|
node_blk->i.i_extra_isize =
|
|
|
|
cpu_to_le16(calc_extra_isize());
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2018-07-10 12:29:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-08-12 11:45:25 +00:00
|
|
|
ASSERT_MSG("[0x%x] wrong extra_attr flag", nid);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("ino[0x%x] remove F2FS_EXTRA_ATTR "
|
|
|
|
"flag in i_inline:%u",
|
|
|
|
nid, node_blk->i.i_inline);
|
|
|
|
/* we don't support tuning F2FS_FEATURE_EXTRA_ATTR now */
|
|
|
|
node_blk->i.i_inline &= ~F2FS_EXTRA_ATTR;
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2018-07-10 12:29:08 +00:00
|
|
|
}
|
2019-03-04 09:21:37 +00:00
|
|
|
|
|
|
|
if ((c.feature &
|
|
|
|
cpu_to_le32(F2FS_FEATURE_FLEXIBLE_INLINE_XATTR)) &&
|
|
|
|
(node_blk->i.i_inline & F2FS_INLINE_XATTR)) {
|
|
|
|
unsigned int inline_size =
|
|
|
|
le16_to_cpu(node_blk->i.i_inline_xattr_size);
|
|
|
|
|
|
|
|
if (!inline_size ||
|
|
|
|
inline_size > MAX_INLINE_XATTR_SIZE) {
|
2019-08-12 11:45:25 +00:00
|
|
|
ASSERT_MSG("[0x%x] wrong inline_xattr_size:%u",
|
|
|
|
nid, inline_size);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("ino[0x%x] recover inline xattr size "
|
|
|
|
"from %u to %u",
|
|
|
|
nid, inline_size,
|
|
|
|
DEFAULT_INLINE_XATTR_ADDRS);
|
|
|
|
node_blk->i.i_inline_xattr_size =
|
|
|
|
cpu_to_le16(DEFAULT_INLINE_XATTR_ADDRS);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2019-03-04 09:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-10 12:29:08 +00:00
|
|
|
}
|
|
|
|
ofs = get_extra_isize(node_blk);
|
|
|
|
|
fsck: check inline_dentry i_addr[0] same as inline_data
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff8008357ffc>] f2fs_evict_inode+0x850/0xa34
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff8008209ec4>] evict+0xa0/0x168
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff800820ad34>] iput+0x188/0x220
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff800836d050>] recover_orphan_inodes+0x2b4/0xa80
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80083648b0>] f2fs_fill_super+0xcf4/0x16a0
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80081f2478>] mount_bdev+0x198/0x1c8
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80083608a8>] f2fs_mount+0x14/0x1c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff80081f2f38>] mount_fs+0x3c/0x15c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff800820e9f8>] vfs_kern_mount+0x7c/0x16c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff8008212548>] do_mount+0x214/0xcf8
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff800821338c>] SyS_mount+0xa8/0x164
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff80080831b0>] el0_svc_naked+0x24/0x28
Mount failed with message as blow:
recover_orphan_inode: orphan failed (ino=1265), run fsck to fix
One orphan directory with inline_dentry flag, but i_addr[0] is not zero.
By the way, sit bitmap of i_addr[0] is also invalidate.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-03 06:29:39 +00:00
|
|
|
if ((node_blk->i.i_inline & F2FS_INLINE_DATA)) {
|
2019-08-14 08:44:26 +00:00
|
|
|
unsigned int inline_size = MAX_INLINE_DATA(node_blk);
|
2019-08-12 11:45:25 +00:00
|
|
|
block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs]);
|
2019-08-14 08:44:26 +00:00
|
|
|
|
2019-08-12 11:45:25 +00:00
|
|
|
if (blkaddr != 0) {
|
|
|
|
ASSERT_MSG("[0x%x] wrong inline reserve blkaddr:%u",
|
|
|
|
nid, blkaddr);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("inline_data has wrong 0'th block = %x",
|
|
|
|
blkaddr);
|
|
|
|
node_blk->i.i_addr[ofs] = 0;
|
|
|
|
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2014-10-19 06:49:30 +00:00
|
|
|
}
|
2019-08-14 08:44:26 +00:00
|
|
|
if (i_size > inline_size) {
|
2019-08-12 11:45:25 +00:00
|
|
|
ASSERT_MSG("[0x%x] wrong inline size:%lu",
|
|
|
|
nid, (unsigned long)i_size);
|
|
|
|
if (c.fix_on) {
|
|
|
|
node_blk->i.i_size = cpu_to_le64(inline_size);
|
|
|
|
FIX_MSG("inline_data has wrong i_size %lu",
|
|
|
|
(unsigned long)i_size);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2019-08-14 08:44:26 +00:00
|
|
|
}
|
2014-10-31 18:06:45 +00:00
|
|
|
if (!(node_blk->i.i_inline & F2FS_DATA_EXIST)) {
|
2017-07-26 14:49:57 +00:00
|
|
|
char buf[MAX_INLINE_DATA(node_blk)];
|
|
|
|
memset(buf, 0, MAX_INLINE_DATA(node_blk));
|
2014-10-31 18:06:45 +00:00
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
if (memcmp(buf, inline_data_addr(node_blk),
|
|
|
|
MAX_INLINE_DATA(node_blk))) {
|
2019-08-12 11:45:25 +00:00
|
|
|
ASSERT_MSG("[0x%x] junk inline data", nid);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("inline_data has DATA_EXIST");
|
|
|
|
node_blk->i.i_inline |= F2FS_DATA_EXIST;
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
2014-10-31 18:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 16:12:40 +00:00
|
|
|
DBG(3, "ino[0x%x] has inline data!\n", nid);
|
2018-07-03 10:10:04 +00:00
|
|
|
child.state |= FSCK_INLINE_INODE;
|
2013-10-25 16:12:40 +00:00
|
|
|
goto check;
|
|
|
|
}
|
fsck: check inline_dentry i_addr[0] same as inline_data
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff8008357ffc>] f2fs_evict_inode+0x850/0xa34
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff8008209ec4>] evict+0xa0/0x168
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff800820ad34>] iput+0x188/0x220
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff800836d050>] recover_orphan_inodes+0x2b4/0xa80
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80083648b0>] f2fs_fill_super+0xcf4/0x16a0
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80081f2478>] mount_bdev+0x198/0x1c8
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80083608a8>] f2fs_mount+0x14/0x1c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff80081f2f38>] mount_fs+0x3c/0x15c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff800820e9f8>] vfs_kern_mount+0x7c/0x16c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff8008212548>] do_mount+0x214/0xcf8
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff800821338c>] SyS_mount+0xa8/0x164
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff80080831b0>] el0_svc_naked+0x24/0x28
Mount failed with message as blow:
recover_orphan_inode: orphan failed (ino=1265), run fsck to fix
One orphan directory with inline_dentry flag, but i_addr[0] is not zero.
By the way, sit bitmap of i_addr[0] is also invalidate.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-03 06:29:39 +00:00
|
|
|
|
|
|
|
if ((node_blk->i.i_inline & F2FS_INLINE_DENTRY)) {
|
2019-08-12 11:45:25 +00:00
|
|
|
block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs]);
|
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
DBG(3, "ino[0x%x] has inline dentry!\n", nid);
|
2019-08-12 11:45:25 +00:00
|
|
|
if (blkaddr != 0) {
|
|
|
|
ASSERT_MSG("[0x%x] wrong inline reserve blkaddr:%u",
|
|
|
|
nid, blkaddr);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("inline_dentry has wrong 0'th block = %x",
|
|
|
|
blkaddr);
|
|
|
|
node_blk->i.i_addr[ofs] = 0;
|
|
|
|
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
fsck: check inline_dentry i_addr[0] same as inline_data
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff8008357ffc>] f2fs_evict_inode+0x850/0xa34
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff8008209ec4>] evict+0xa0/0x168
<4>[ 30.222442s][pid:1,cpu4,init][<ffffff800820ad34>] iput+0x188/0x220
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff800836d050>] recover_orphan_inodes+0x2b4/0xa80
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80083648b0>] f2fs_fill_super+0xcf4/0x16a0
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80081f2478>] mount_bdev+0x198/0x1c8
<4>[ 30.222473s][pid:1,cpu4,init][<ffffff80083608a8>] f2fs_mount+0x14/0x1c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff80081f2f38>] mount_fs+0x3c/0x15c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff800820e9f8>] vfs_kern_mount+0x7c/0x16c
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff8008212548>] do_mount+0x214/0xcf8
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff800821338c>] SyS_mount+0xa8/0x164
<4>[ 30.222503s][pid:1,cpu4,init][<ffffff80080831b0>] el0_svc_naked+0x24/0x28
Mount failed with message as blow:
recover_orphan_inode: orphan failed (ino=1265), run fsck to fix
One orphan directory with inline_dentry flag, but i_addr[0] is not zero.
By the way, sit bitmap of i_addr[0] is also invalidate.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2017-11-03 06:29:39 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 19:57:10 +00:00
|
|
|
ret = fsck_chk_inline_dentries(sbi, node_blk, &child);
|
2014-10-15 23:53:25 +00:00
|
|
|
if (ret < 0) {
|
2019-08-12 11:45:25 +00:00
|
|
|
if (c.fix_on)
|
|
|
|
need_fix = 1;
|
2014-10-15 23:53:25 +00:00
|
|
|
}
|
2018-07-03 10:10:04 +00:00
|
|
|
child.state |= FSCK_INLINE_INODE;
|
2014-10-14 22:15:40 +00:00
|
|
|
goto check;
|
|
|
|
}
|
2013-10-08 09:17:33 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
/* check data blocks in inode */
|
2016-03-16 03:05:14 +00:00
|
|
|
for (idx = 0; idx < ADDRS_PER_INODE(&node_blk->i);
|
|
|
|
idx++, child.pgofs++) {
|
2017-07-26 14:49:57 +00:00
|
|
|
block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs + idx]);
|
2015-12-08 22:53:21 +00:00
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
/* check extent info */
|
|
|
|
check_extent_info(&child, blkaddr, 0);
|
|
|
|
|
2015-12-08 22:53:21 +00:00
|
|
|
if (blkaddr != 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
|
|
|
ret = fsck_chk_data_blk(sbi,
|
2019-07-11 20:45:41 +00:00
|
|
|
IS_CASEFOLDED(&node_blk->i),
|
2015-12-08 22:53:21 +00:00
|
|
|
blkaddr,
|
2015-03-30 19:57:10 +00:00
|
|
|
&child, (i_blocks == *blk_cnt),
|
2015-04-28 21:27:18 +00:00
|
|
|
ftype, nid, idx, ni->version,
|
2018-01-11 02:17:19 +00:00
|
|
|
file_is_encrypt(&node_blk->i));
|
2014-08-29 18:46:25 +00:00
|
|
|
if (!ret) {
|
2014-08-28 00:06:17 +00:00
|
|
|
*blk_cnt = *blk_cnt + 1;
|
2016-09-17 01:41:00 +00:00
|
|
|
} else if (c.fix_on) {
|
2017-07-26 14:49:57 +00:00
|
|
|
node_blk->i.i_addr[ofs + idx] = 0;
|
2014-08-29 18:46:25 +00:00
|
|
|
need_fix = 1;
|
2017-07-26 14:49:57 +00:00
|
|
|
FIX_MSG("[0x%x] i_addr[%d] = 0",
|
|
|
|
nid, ofs + idx);
|
2014-08-29 18:46:25 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 09:37:41 +00:00
|
|
|
/* readahead node blocks */
|
|
|
|
for (idx = 0; idx < 5; idx++) {
|
|
|
|
u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]);
|
|
|
|
fsck_reada_node_block(sbi, 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
|
|
|
/* check node blocks in inode */
|
|
|
|
for (idx = 0; idx < 5; idx++) {
|
2016-07-15 12:01:21 +00:00
|
|
|
nid_t i_nid = le32_to_cpu(node_blk->i.i_nid[idx]);
|
2015-12-08 22:53:21 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
if (idx == 0 || idx == 1)
|
|
|
|
ntype = TYPE_DIRECT_NODE;
|
|
|
|
else if (idx == 2 || idx == 3)
|
|
|
|
ntype = TYPE_INDIRECT_NODE;
|
|
|
|
else if (idx == 4)
|
|
|
|
ntype = TYPE_DOUBLE_INDIRECT_NODE;
|
|
|
|
else
|
|
|
|
ASSERT(0);
|
|
|
|
|
2016-07-15 12:01:21 +00:00
|
|
|
if (i_nid == 0x0)
|
2016-03-16 03:05:14 +00:00
|
|
|
goto skip;
|
|
|
|
|
2016-07-15 12:01:21 +00:00
|
|
|
ret = fsck_chk_node_blk(sbi, &node_blk->i, i_nid,
|
2017-06-05 20:44:50 +00:00
|
|
|
ftype, ntype, blk_cnt, &child);
|
2016-03-16 03:05:14 +00:00
|
|
|
if (!ret) {
|
|
|
|
*blk_cnt = *blk_cnt + 1;
|
|
|
|
} else if (ret == -EINVAL) {
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2014-08-29 18:46:25 +00:00
|
|
|
node_blk->i.i_nid[idx] = 0;
|
|
|
|
need_fix = 1;
|
2014-08-28 17:27:17 +00:00
|
|
|
FIX_MSG("[0x%x] i_nid[%d] = 0", nid, idx);
|
2014-08-29 18:46:25 +00:00
|
|
|
}
|
2016-03-16 03:05:14 +00:00
|
|
|
skip:
|
|
|
|
if (ntype == TYPE_DIRECT_NODE)
|
|
|
|
child.pgofs += ADDRS_PER_BLOCK;
|
|
|
|
else if (ntype == TYPE_INDIRECT_NODE)
|
|
|
|
child.pgofs += ADDRS_PER_BLOCK * NIDS_PER_BLOCK;
|
|
|
|
else
|
|
|
|
child.pgofs += ADDRS_PER_BLOCK *
|
|
|
|
NIDS_PER_BLOCK * NIDS_PER_BLOCK;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
2016-03-16 03:05:14 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
2016-03-16 03:07:07 +00:00
|
|
|
|
2018-07-03 10:10:04 +00:00
|
|
|
check:
|
2016-03-16 03:07:07 +00:00
|
|
|
/* check uncovered range in the back of extent */
|
|
|
|
check_extent_info(&child, 0, 1);
|
|
|
|
|
|
|
|
if (child.state & FSCK_UNMATCHED_EXTENT) {
|
|
|
|
ASSERT_MSG("ino: 0x%x has wrong ext: [pgofs:%u, blk:%u, len:%u]",
|
|
|
|
nid, child.ei.fofs, child.ei.blk, child.ei.len);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on)
|
2015-12-08 22:53:21 +00:00
|
|
|
need_fix = 1;
|
|
|
|
}
|
2018-07-03 10:10:04 +00:00
|
|
|
|
2015-03-26 02:26:25 +00:00
|
|
|
if (i_blocks != *blk_cnt) {
|
|
|
|
ASSERT_MSG("ino: 0x%x has i_blocks: %08"PRIx64", "
|
|
|
|
"but has %u blocks",
|
|
|
|
nid, i_blocks, *blk_cnt);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2015-03-26 02:26:25 +00:00
|
|
|
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("[0x%x] i_blocks=0x%08"PRIx64" -> 0x%x",
|
|
|
|
nid, i_blocks, *blk_cnt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skip_blkcnt_fix:
|
2019-04-24 17:59:09 +00:00
|
|
|
en = malloc(F2FS_PRINT_NAMELEN);
|
2017-11-16 11:50:56 +00:00
|
|
|
ASSERT(en);
|
|
|
|
|
2017-12-18 13:25:27 +00:00
|
|
|
namelen = le32_to_cpu(node_blk->i.i_namelen);
|
|
|
|
if (namelen > F2FS_NAME_LEN) {
|
|
|
|
if (child_d && child_d->i_namelen <= F2FS_NAME_LEN) {
|
|
|
|
ASSERT_MSG("ino: 0x%x has i_namelen: 0x%x, "
|
|
|
|
"but has %d characters for name",
|
|
|
|
nid, namelen, child_d->i_namelen);
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("[0x%x] i_namelen=0x%x -> 0x%x", nid, namelen,
|
|
|
|
child_d->i_namelen);
|
|
|
|
node_blk->i.i_namelen = cpu_to_le32(child_d->i_namelen);
|
|
|
|
need_fix = 1;
|
|
|
|
}
|
|
|
|
namelen = child_d->i_namelen;
|
|
|
|
} else
|
|
|
|
namelen = F2FS_NAME_LEN;
|
|
|
|
}
|
2019-04-24 17:59:09 +00:00
|
|
|
pretty_print_filename(node_blk->i.i_name, namelen, en,
|
|
|
|
file_enc_name(&node_blk->i));
|
2013-10-16 04:48:45 +00:00
|
|
|
if (ftype == F2FS_FT_ORPHAN)
|
2014-08-27 23:16:16 +00:00
|
|
|
DBG(1, "Orphan Inode: 0x%x [%s] i_blocks: %u\n\n",
|
|
|
|
le32_to_cpu(node_blk->footer.ino),
|
2016-10-24 02:16:03 +00:00
|
|
|
en, (u32)i_blocks);
|
2014-08-29 18:46:25 +00:00
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
if (is_qf_ino(F2FS_RAW_SUPER(sbi), nid))
|
|
|
|
DBG(1, "Quota Inode: 0x%x [%s] i_blocks: %u\n\n",
|
|
|
|
le32_to_cpu(node_blk->footer.ino),
|
|
|
|
en, (u32)i_blocks);
|
|
|
|
|
2015-03-30 20:09:16 +00:00
|
|
|
if (ftype == F2FS_FT_DIR) {
|
|
|
|
DBG(1, "Directory Inode: 0x%x [%s] depth: %d has %d files\n\n",
|
2016-10-24 02:16:03 +00:00
|
|
|
le32_to_cpu(node_blk->footer.ino), en,
|
2015-03-30 20:09:16 +00:00
|
|
|
le32_to_cpu(node_blk->i.i_current_depth),
|
|
|
|
child.files);
|
|
|
|
|
|
|
|
if (i_links != child.links) {
|
|
|
|
ASSERT_MSG("ino: 0x%x i_links: %u, real links: %u",
|
|
|
|
nid, i_links, child.links);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2015-03-30 20:09:16 +00:00
|
|
|
node_blk->i.i_links = cpu_to_le32(child.links);
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("Dir: 0x%x i_links= 0x%x -> 0x%x",
|
2015-03-30 19:57:10 +00:00
|
|
|
nid, i_links, child.links);
|
2015-03-30 20:09:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (child.dots < 2 &&
|
|
|
|
!(node_blk->i.i_inline & F2FS_INLINE_DOTS)) {
|
|
|
|
ASSERT_MSG("ino: 0x%x dots: %u",
|
|
|
|
nid, child.dots);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2015-03-30 20:09:16 +00:00
|
|
|
node_blk->i.i_inline |= F2FS_INLINE_DOTS;
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("Dir: 0x%x set inline_dots", nid);
|
|
|
|
}
|
2014-08-29 18:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-16 11:50:56 +00:00
|
|
|
|
2018-07-28 10:41:35 +00:00
|
|
|
i_gc_failures = le16_to_cpu(node_blk->i.i_gc_failures);
|
2018-11-27 12:36:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* old kernel initialized i_gc_failures as 0x01, in preen mode 2,
|
|
|
|
* let's skip repairing.
|
|
|
|
*/
|
|
|
|
if (ftype == F2FS_FT_REG_FILE && i_gc_failures &&
|
|
|
|
(c.preen_mode != PREEN_MODE_2 || i_gc_failures != 0x01)) {
|
2018-07-28 10:41:35 +00:00
|
|
|
|
|
|
|
DBG(1, "Regular Inode: 0x%x [%s] depth: %d\n\n",
|
|
|
|
le32_to_cpu(node_blk->footer.ino), en,
|
|
|
|
i_gc_failures);
|
|
|
|
|
|
|
|
if (c.fix_on) {
|
|
|
|
node_blk->i.i_gc_failures = cpu_to_le16(0);
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("Regular: 0x%x reset i_gc_failures from 0x%x to 0x00",
|
|
|
|
nid, i_gc_failures);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 11:50:56 +00:00
|
|
|
free(en);
|
|
|
|
|
2019-08-12 11:45:27 +00:00
|
|
|
if (ftype == F2FS_FT_SYMLINK && i_size == 0 &&
|
|
|
|
i_blocks == (i_xattr_nid ? 3 : 2)) {
|
2019-08-12 11:45:25 +00:00
|
|
|
ASSERT_MSG("ino: 0x%x i_blocks: %lu with zero i_size\n",
|
2017-11-14 18:53:32 +00:00
|
|
|
nid, (unsigned long)i_blocks);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2019-08-12 11:45:27 +00:00
|
|
|
node_blk->i.i_size = cpu_to_le64(F2FS_BLKSIZE);
|
2016-07-15 17:27:23 +00:00
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("Symlink: recover 0x%x with i_size=%lu",
|
2019-08-12 11:45:27 +00:00
|
|
|
nid, (unsigned long)F2FS_BLKSIZE);
|
2016-07-15 17:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-29 18:46:25 +00:00
|
|
|
|
2015-04-01 02:37:40 +00:00
|
|
|
if (ftype == F2FS_FT_ORPHAN && i_links) {
|
2019-08-12 11:45:25 +00:00
|
|
|
ASSERT_MSG("ino: 0x%x is orphan inode, but has i_links: %u",
|
2014-08-29 18:46:25 +00:00
|
|
|
nid, i_links);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2015-04-01 02:37:40 +00:00
|
|
|
node_blk->i.i_links = 0;
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("ino: 0x%x orphan_inode, i_links= 0x%x -> 0",
|
|
|
|
nid, i_links);
|
|
|
|
}
|
|
|
|
}
|
2017-07-26 15:01:35 +00:00
|
|
|
|
|
|
|
/* drop extent information to avoid potential wrong access */
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable())
|
2015-07-02 01:37:48 +00:00
|
|
|
node_blk->i.i_ext.len = 0;
|
2017-07-26 15:01:35 +00:00
|
|
|
|
|
|
|
if ((c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM)) &&
|
|
|
|
f2fs_has_extra_isize(&node_blk->i)) {
|
|
|
|
__u32 provided, calculated;
|
|
|
|
|
|
|
|
provided = le32_to_cpu(node_blk->i.i_inode_checksum);
|
|
|
|
calculated = f2fs_inode_chksum(node_blk);
|
|
|
|
|
|
|
|
if (provided != calculated) {
|
|
|
|
ASSERT_MSG("ino: 0x%x chksum:0x%x, but calculated one is: 0x%x",
|
|
|
|
nid, provided, calculated);
|
|
|
|
if (c.fix_on) {
|
|
|
|
node_blk->i.i_inode_checksum =
|
|
|
|
cpu_to_le32(calculated);
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("ino: 0x%x recover, i_inode_checksum= 0x%x -> 0x%x",
|
|
|
|
nid, provided, calculated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable()) {
|
2014-08-29 18:46:25 +00:00
|
|
|
ret = dev_write_block(node_blk, ni->blk_addr);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
int fsck_chk_dnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
|
|
|
|
u32 nid, enum FILE_TYPE ftype, struct f2fs_node *node_blk,
|
2016-03-16 03:07:07 +00:00
|
|
|
u32 *blk_cnt, struct child_info *child, struct node_info *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
|
|
|
{
|
2014-08-28 00:06:17 +00:00
|
|
|
int idx, ret;
|
2015-02-24 18:09:07 +00:00
|
|
|
int need_fix = 0;
|
2016-02-26 06:42:13 +00:00
|
|
|
child->p_ino = nid;
|
|
|
|
child->pp_ino = le32_to_cpu(inode->i_pino);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2016-03-16 03:05:14 +00:00
|
|
|
for (idx = 0; idx < ADDRS_PER_BLOCK; idx++, child->pgofs++) {
|
2015-12-08 22:53:21 +00:00
|
|
|
block_t blkaddr = le32_to_cpu(node_blk->dn.addr[idx]);
|
|
|
|
|
2016-03-16 03:07:07 +00:00
|
|
|
check_extent_info(child, blkaddr, 0);
|
|
|
|
|
2015-12-08 22:53:21 +00:00
|
|
|
if (blkaddr == 0x0)
|
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
|
|
|
continue;
|
2019-07-11 20:45:41 +00:00
|
|
|
ret = fsck_chk_data_blk(sbi, IS_CASEFOLDED(inode),
|
2015-12-08 22:53:21 +00:00
|
|
|
blkaddr, child,
|
|
|
|
le64_to_cpu(inode->i_blocks) == *blk_cnt, ftype,
|
2015-04-28 21:27:18 +00:00
|
|
|
nid, idx, ni->version,
|
2018-01-11 02:17:19 +00:00
|
|
|
file_is_encrypt(inode));
|
2015-02-24 18:09:07 +00:00
|
|
|
if (!ret) {
|
2014-08-28 00:06:17 +00:00
|
|
|
*blk_cnt = *blk_cnt + 1;
|
2016-09-17 01:41:00 +00:00
|
|
|
} else if (c.fix_on) {
|
2015-02-24 18:09:07 +00:00
|
|
|
node_blk->dn.addr[idx] = 0;
|
|
|
|
need_fix = 1;
|
|
|
|
FIX_MSG("[0x%x] dn.addr[%d] = 0", nid, idx);
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable()) {
|
2015-02-24 18:09:07 +00:00
|
|
|
ret = dev_write_block(node_blk, ni->blk_addr);
|
|
|
|
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
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
int fsck_chk_idnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
|
2015-03-30 19:09:36 +00:00
|
|
|
enum FILE_TYPE ftype, struct f2fs_node *node_blk, u32 *blk_cnt,
|
2016-03-16 03:07:07 +00:00
|
|
|
struct child_info *child)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
2016-02-19 17:14:58 +00:00
|
|
|
int need_fix = 0, 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 i = 0;
|
|
|
|
|
2018-01-29 09:37:41 +00:00
|
|
|
fsck_reada_all_direct_node_blocks(sbi, node_blk);
|
|
|
|
|
2016-03-16 03:05:14 +00:00
|
|
|
for (i = 0; i < NIDS_PER_BLOCK; i++) {
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
if (le32_to_cpu(node_blk->in.nid[i]) == 0x0)
|
2016-03-16 03:05:14 +00:00
|
|
|
goto skip;
|
2014-08-28 00:06:17 +00:00
|
|
|
ret = fsck_chk_node_blk(sbi, inode,
|
2017-06-05 20:44:50 +00:00
|
|
|
le32_to_cpu(node_blk->in.nid[i]),
|
2016-03-16 03:07:07 +00:00
|
|
|
ftype, TYPE_DIRECT_NODE, blk_cnt, child);
|
2014-08-28 00:06:17 +00:00
|
|
|
if (!ret)
|
|
|
|
*blk_cnt = *blk_cnt + 1;
|
2016-02-19 17:14:58 +00:00
|
|
|
else if (ret == -EINVAL) {
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on)
|
2016-02-19 17:14:58 +00:00
|
|
|
printf("should delete in.nid[i] = 0;\n");
|
|
|
|
else {
|
|
|
|
node_blk->in.nid[i] = 0;
|
|
|
|
need_fix = 1;
|
2017-11-02 03:56:12 +00:00
|
|
|
FIX_MSG("Set indirect node 0x%x -> 0", i);
|
2016-02-19 17:14:58 +00:00
|
|
|
}
|
2016-03-16 03:05:14 +00:00
|
|
|
skip:
|
|
|
|
child->pgofs += ADDRS_PER_BLOCK;
|
2016-02-19 17:14:58 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
2016-02-19 17:14:58 +00:00
|
|
|
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable()) {
|
2016-02-19 17:14:58 +00:00
|
|
|
struct node_info ni;
|
|
|
|
nid_t nid = le32_to_cpu(node_blk->footer.nid);
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
ret = dev_write_block(node_blk, ni.blk_addr);
|
|
|
|
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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
|
2015-03-30 19:09:36 +00:00
|
|
|
enum FILE_TYPE ftype, struct f2fs_node *node_blk, u32 *blk_cnt,
|
2016-03-16 03:07:07 +00:00
|
|
|
struct child_info *child)
|
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 i = 0;
|
2016-02-19 17:14:58 +00:00
|
|
|
int need_fix = 0, 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
|
|
|
|
2018-01-29 09:37:41 +00:00
|
|
|
fsck_reada_all_direct_node_blocks(sbi, 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
|
|
|
for (i = 0; i < NIDS_PER_BLOCK; i++) {
|
|
|
|
if (le32_to_cpu(node_blk->in.nid[i]) == 0x0)
|
2016-03-16 03:05:14 +00:00
|
|
|
goto skip;
|
2014-08-28 00:06:17 +00:00
|
|
|
ret = fsck_chk_node_blk(sbi, inode,
|
2017-06-05 20:44:50 +00:00
|
|
|
le32_to_cpu(node_blk->in.nid[i]),
|
2016-03-16 03:07:07 +00:00
|
|
|
ftype, TYPE_INDIRECT_NODE, blk_cnt, child);
|
2014-08-28 00:06:17 +00:00
|
|
|
if (!ret)
|
|
|
|
*blk_cnt = *blk_cnt + 1;
|
2016-02-19 17:14:58 +00:00
|
|
|
else if (ret == -EINVAL) {
|
2016-09-17 01:41:00 +00:00
|
|
|
if (!c.fix_on)
|
2016-02-19 17:14:58 +00:00
|
|
|
printf("should delete in.nid[i] = 0;\n");
|
|
|
|
else {
|
|
|
|
node_blk->in.nid[i] = 0;
|
|
|
|
need_fix = 1;
|
2017-11-02 03:56:12 +00:00
|
|
|
FIX_MSG("Set double indirect node 0x%x -> 0", i);
|
2016-02-19 17:14:58 +00:00
|
|
|
}
|
2016-03-16 03:05:14 +00:00
|
|
|
skip:
|
|
|
|
child->pgofs += ADDRS_PER_BLOCK * NIDS_PER_BLOCK;
|
2016-02-19 17:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 02:42:20 +00:00
|
|
|
if (need_fix && f2fs_dev_is_writable()) {
|
2016-02-19 17:14:58 +00:00
|
|
|
struct node_info ni;
|
|
|
|
nid_t nid = le32_to_cpu(node_blk->footer.nid);
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
ret = dev_write_block(node_blk, ni.blk_addr);
|
|
|
|
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
|
|
|
}
|
2016-02-19 17:14:58 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-10 21:20:25 +00:00
|
|
|
static const char *lookup_table =
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
|
|
|
|
|
|
|
|
/**
|
2019-04-24 17:59:09 +00:00
|
|
|
* base64_encode() -
|
2016-02-10 21:20:25 +00:00
|
|
|
*
|
2019-04-24 17:59:09 +00:00
|
|
|
* Encodes the input string using characters from the set [A-Za-z0-9+,].
|
2016-02-10 21:20:25 +00:00
|
|
|
* The encoded string is roughly 4/3 times the size of the input string.
|
|
|
|
*/
|
2019-04-24 17:59:09 +00:00
|
|
|
static int base64_encode(const u8 *src, int len, char *dst)
|
2016-02-10 21:20:25 +00:00
|
|
|
{
|
2019-04-24 17:59:09 +00:00
|
|
|
int i, bits = 0, ac = 0;
|
2016-02-10 21:20:25 +00:00
|
|
|
char *cp = dst;
|
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
ac += src[i] << bits;
|
2016-02-10 21:20:25 +00:00
|
|
|
bits += 8;
|
|
|
|
do {
|
|
|
|
*cp++ = lookup_table[ac & 0x3f];
|
|
|
|
ac >>= 6;
|
|
|
|
bits -= 6;
|
|
|
|
} while (bits >= 6);
|
|
|
|
}
|
|
|
|
if (bits)
|
|
|
|
*cp++ = lookup_table[ac & 0x3f];
|
|
|
|
return cp - dst;
|
|
|
|
}
|
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
void pretty_print_filename(const u8 *raw_name, u32 len,
|
|
|
|
char out[F2FS_PRINT_NAMELEN], int enc_name)
|
2015-04-28 21:27:18 +00:00
|
|
|
{
|
2019-04-24 17:59:09 +00:00
|
|
|
len = min(len, (u32)F2FS_NAME_LEN);
|
2015-04-28 21:27:18 +00:00
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
if (enc_name)
|
|
|
|
len = base64_encode(raw_name, len, out);
|
|
|
|
else
|
|
|
|
memcpy(out, raw_name, len);
|
|
|
|
out[len] = 0;
|
2015-04-28 21:27:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 07:39:06 +00:00
|
|
|
static void print_dentry(__u32 depth, __u8 *name,
|
2015-12-15 19:13:25 +00:00
|
|
|
u8 *bitmap, struct f2fs_dir_entry *dentry,
|
2017-03-17 13:56:19 +00:00
|
|
|
int max, int idx, int last_blk, int enc_name)
|
2013-07-30 07:39:06 +00:00
|
|
|
{
|
|
|
|
int last_de = 0;
|
|
|
|
int next_idx = 0;
|
2018-07-10 14:47:38 +00:00
|
|
|
u32 name_len;
|
2014-05-14 00:02:55 +00:00
|
|
|
unsigned int i;
|
2013-07-30 07:39:06 +00:00
|
|
|
int bit_offset;
|
2019-04-24 17:59:09 +00:00
|
|
|
char new[F2FS_PRINT_NAMELEN];
|
2013-07-30 07:39:06 +00:00
|
|
|
|
2017-03-15 13:28:19 +00:00
|
|
|
if (!c.show_dentry)
|
2013-07-30 07:39:06 +00:00
|
|
|
return;
|
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
name_len = le16_to_cpu(dentry[idx].name_len);
|
2013-07-30 07:39:06 +00:00
|
|
|
next_idx = idx + (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN;
|
|
|
|
|
2015-12-09 19:44:31 +00:00
|
|
|
bit_offset = find_next_bit_le(bitmap, max, next_idx);
|
2014-10-14 22:15:40 +00:00
|
|
|
if (bit_offset >= max && last_blk)
|
2013-07-30 07:39:06 +00:00
|
|
|
last_de = 1;
|
|
|
|
|
|
|
|
if (tree_mark_size <= depth) {
|
|
|
|
tree_mark_size *= 2;
|
2015-12-14 11:31:28 +00:00
|
|
|
ASSERT(tree_mark_size != 0);
|
2015-12-14 17:37:30 +00:00
|
|
|
tree_mark = realloc(tree_mark, tree_mark_size);
|
2015-12-14 11:31:28 +00:00
|
|
|
ASSERT(tree_mark != NULL);
|
2013-07-30 07:39:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (last_de)
|
|
|
|
tree_mark[depth] = '`';
|
|
|
|
else
|
|
|
|
tree_mark[depth] = '|';
|
|
|
|
|
|
|
|
if (tree_mark[depth - 1] == '`')
|
|
|
|
tree_mark[depth - 1] = ' ';
|
|
|
|
|
|
|
|
for (i = 1; i < depth; i++)
|
|
|
|
printf("%c ", tree_mark[i]);
|
2015-04-28 21:27:18 +00:00
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
pretty_print_filename(name, name_len, new, enc_name);
|
2015-04-28 21:27:18 +00:00
|
|
|
|
|
|
|
printf("%c-- %s <ino = 0x%x>, <encrypted (%d)>\n",
|
|
|
|
last_de ? '`' : '|',
|
|
|
|
new, le32_to_cpu(dentry[idx].ino),
|
2017-03-17 13:56:19 +00:00
|
|
|
enc_name);
|
2015-04-28 21:27:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
static int f2fs_check_hash_code(int encoding, int casefolded,
|
|
|
|
struct f2fs_dir_entry *dentry,
|
2017-03-17 13:56:19 +00:00
|
|
|
const unsigned char *name, u32 len, int enc_name)
|
2015-04-28 21:27:18 +00:00
|
|
|
{
|
2019-07-11 20:45:41 +00:00
|
|
|
f2fs_hash_t hash_code = f2fs_dentry_hash(encoding, casefolded, name, len);
|
2015-04-28 21:27:18 +00:00
|
|
|
/* fix hash_code made by old buggy code */
|
|
|
|
if (dentry->hash_code != hash_code) {
|
2019-04-24 17:59:09 +00:00
|
|
|
char new[F2FS_PRINT_NAMELEN];
|
2015-04-28 21:27:18 +00:00
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
pretty_print_filename(name, len, new, enc_name);
|
2015-04-28 21:27:18 +00:00
|
|
|
FIX_MSG("Mismatch hash_code for \"%s\" [%x:%x]",
|
|
|
|
new, le32_to_cpu(dentry->hash_code),
|
|
|
|
hash_code);
|
|
|
|
dentry->hash_code = cpu_to_le32(hash_code);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2013-07-30 07:39:06 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:05:14 +00:00
|
|
|
|
|
|
|
static int __get_current_level(int dir_level, u32 pgofs)
|
|
|
|
{
|
|
|
|
unsigned int bidx = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DIR_HASH_DEPTH; i++) {
|
|
|
|
bidx += dir_buckets(i, dir_level) * bucket_blocks(i);
|
|
|
|
if (bidx > pgofs)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
static int f2fs_check_dirent_position(int encoding, int casefolded,
|
|
|
|
u8 *name, u16 name_len, u32 pgofs,
|
2016-03-16 03:05:14 +00:00
|
|
|
u8 dir_level, u32 pino)
|
|
|
|
{
|
2019-07-11 20:45:41 +00:00
|
|
|
f2fs_hash_t namehash = f2fs_dentry_hash(encoding, casefolded, name, name_len);
|
2016-03-16 03:05:14 +00:00
|
|
|
unsigned int nbucket, nblock;
|
|
|
|
unsigned int bidx, end_block;
|
|
|
|
int level;
|
|
|
|
|
|
|
|
level = __get_current_level(dir_level, pgofs);
|
|
|
|
|
|
|
|
nbucket = dir_buckets(level, dir_level);
|
|
|
|
nblock = bucket_blocks(level);
|
|
|
|
|
|
|
|
bidx = dir_block_index(level, dir_level,
|
|
|
|
le32_to_cpu(namehash) % nbucket);
|
|
|
|
end_block = bidx + nblock;
|
|
|
|
|
|
|
|
if (pgofs >= bidx && pgofs < end_block)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ASSERT_MSG("Wrong position of dirent pino:%u, name:%s, level:%d, "
|
|
|
|
"dir_level:%d, pgofs:%u, correct range:[%u, %u]\n",
|
|
|
|
pino, name, level, dir_level, pgofs, bidx, end_block - 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-26 06:42:13 +00:00
|
|
|
static int __chk_dots_dentries(struct f2fs_sb_info *sbi,
|
2019-07-11 20:45:41 +00:00
|
|
|
int casefolded,
|
2016-02-26 06:42:13 +00:00
|
|
|
struct f2fs_dir_entry *dentry,
|
|
|
|
struct child_info *child,
|
|
|
|
u8 *name, int len,
|
|
|
|
__u8 (*filename)[F2FS_SLOT_LEN],
|
2017-03-17 13:56:19 +00:00
|
|
|
int enc_name)
|
2016-02-26 06:42:13 +00:00
|
|
|
{
|
|
|
|
int fixed = 0;
|
|
|
|
|
|
|
|
if ((name[0] == '.' && len == 1)) {
|
|
|
|
if (le32_to_cpu(dentry->ino) != child->p_ino) {
|
|
|
|
ASSERT_MSG("Bad inode number[0x%x] for '.', parent_ino is [0x%x]\n",
|
|
|
|
le32_to_cpu(dentry->ino), child->p_ino);
|
|
|
|
dentry->ino = cpu_to_le32(child->p_ino);
|
|
|
|
fixed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name[0] == '.' && name[1] == '.' && len == 2) {
|
|
|
|
if (child->p_ino == F2FS_ROOT_INO(sbi)) {
|
|
|
|
if (le32_to_cpu(dentry->ino) != F2FS_ROOT_INO(sbi)) {
|
|
|
|
ASSERT_MSG("Bad inode number[0x%x] for '..'\n",
|
|
|
|
le32_to_cpu(dentry->ino));
|
|
|
|
dentry->ino = cpu_to_le32(F2FS_ROOT_INO(sbi));
|
|
|
|
fixed = 1;
|
|
|
|
}
|
|
|
|
} else if (le32_to_cpu(dentry->ino) != child->pp_ino) {
|
|
|
|
ASSERT_MSG("Bad inode number[0x%x] for '..', parent parent ino is [0x%x]\n",
|
|
|
|
le32_to_cpu(dentry->ino), child->pp_ino);
|
|
|
|
dentry->ino = cpu_to_le32(child->pp_ino);
|
|
|
|
fixed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
if (f2fs_check_hash_code(get_encoding(sbi), casefolded, dentry, name, len, enc_name))
|
2016-02-26 06:42:13 +00:00
|
|
|
fixed = 1;
|
|
|
|
|
|
|
|
if (name[len] != '\0') {
|
|
|
|
ASSERT_MSG("'.' is not NULL terminated\n");
|
|
|
|
name[len] = '\0';
|
|
|
|
memcpy(*filename, name, len);
|
|
|
|
fixed = 1;
|
|
|
|
}
|
|
|
|
return fixed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nullify_dentry(struct f2fs_dir_entry *dentry, int offs,
|
|
|
|
__u8 (*filename)[F2FS_SLOT_LEN], u8 **bitmap)
|
|
|
|
{
|
|
|
|
memset(dentry, 0, sizeof(struct f2fs_dir_entry));
|
|
|
|
test_and_clear_bit_le(offs, *bitmap);
|
|
|
|
memset(*filename, 0, F2FS_SLOT_LEN);
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
static int __chk_dentries(struct f2fs_sb_info *sbi, int casefolded,
|
|
|
|
struct child_info *child,
|
2015-12-15 19:13:25 +00:00
|
|
|
u8 *bitmap, struct f2fs_dir_entry *dentry,
|
2014-10-14 22:15:40 +00:00
|
|
|
__u8 (*filenames)[F2FS_SLOT_LEN],
|
2017-03-17 13:56:19 +00:00
|
|
|
int max, int last_blk, int enc_name)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2014-10-14 22:15:40 +00:00
|
|
|
enum FILE_TYPE ftype;
|
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 dentries = 0;
|
2014-10-14 22:15:40 +00:00
|
|
|
u32 blk_cnt;
|
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
|
|
|
u8 *name;
|
2019-04-24 17:59:09 +00:00
|
|
|
char en[F2FS_PRINT_NAMELEN];
|
|
|
|
u16 name_len;
|
2014-10-14 22:15:40 +00:00
|
|
|
int ret = 0;
|
2014-10-15 23:53:25 +00:00
|
|
|
int fixed = 0;
|
2015-03-27 21:40:37 +00:00
|
|
|
int i, slots;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-12-02 22:08:11 +00:00
|
|
|
/* readahead inode blocks */
|
2015-03-27 20:32:17 +00:00
|
|
|
for (i = 0; i < max; i++) {
|
2016-01-13 19:51:33 +00:00
|
|
|
u32 ino;
|
|
|
|
|
2015-12-15 18:10:15 +00:00
|
|
|
if (test_bit_le(i, bitmap) == 0)
|
2014-12-02 22:08:11 +00:00
|
|
|
continue;
|
2015-03-27 20:32:17 +00:00
|
|
|
|
2014-12-02 22:08:11 +00:00
|
|
|
ino = le32_to_cpu(dentry[i].ino);
|
|
|
|
|
|
|
|
if (IS_VALID_NID(sbi, ino)) {
|
|
|
|
struct node_info ni;
|
|
|
|
|
|
|
|
get_node_info(sbi, ino, &ni);
|
2015-03-27 20:32:17 +00:00
|
|
|
if (IS_VALID_BLK_ADDR(sbi, ni.blk_addr)) {
|
2014-12-02 22:08:11 +00:00
|
|
|
dev_reada_block(ni.blk_addr);
|
2015-03-27 20:32:17 +00:00
|
|
|
name_len = le16_to_cpu(dentry[i].name_len);
|
|
|
|
if (name_len > 0)
|
|
|
|
i += (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN - 1;
|
|
|
|
}
|
2014-12-02 22:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
for (i = 0; i < max;) {
|
2015-12-15 18:10:15 +00:00
|
|
|
if (test_bit_le(i, bitmap) == 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
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-29 02:11:52 +00:00
|
|
|
if (!IS_VALID_NID(sbi, le32_to_cpu(dentry[i].ino))) {
|
2015-03-27 20:32:17 +00:00
|
|
|
ASSERT_MSG("Bad dentry 0x%x with invalid NID/ino 0x%x",
|
|
|
|
i, le32_to_cpu(dentry[i].ino));
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2014-10-29 02:11:52 +00:00
|
|
|
FIX_MSG("Clear bad dentry 0x%x with bad ino 0x%x",
|
|
|
|
i, le32_to_cpu(dentry[i].ino));
|
2015-12-15 18:10:15 +00:00
|
|
|
test_and_clear_bit_le(i, bitmap);
|
2014-11-03 21:27:42 +00:00
|
|
|
fixed = 1;
|
2014-10-29 02:11:52 +00:00
|
|
|
}
|
2015-03-27 20:32:17 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
2014-10-29 02:11:52 +00:00
|
|
|
}
|
2015-03-27 20:32:17 +00:00
|
|
|
|
2014-10-29 02:11:52 +00:00
|
|
|
ftype = dentry[i].file_type;
|
2015-03-27 20:32:17 +00:00
|
|
|
if ((ftype <= F2FS_FT_UNKNOWN || ftype > F2FS_FT_LAST_FILE_TYPE)) {
|
2016-01-13 19:51:33 +00:00
|
|
|
ASSERT_MSG("Bad dentry 0x%x with unexpected ftype 0x%x",
|
|
|
|
le32_to_cpu(dentry[i].ino), ftype);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2014-10-29 02:11:52 +00:00
|
|
|
FIX_MSG("Clear bad dentry 0x%x with bad ftype 0x%x",
|
|
|
|
i, ftype);
|
2015-12-15 18:10:15 +00:00
|
|
|
test_and_clear_bit_le(i, bitmap);
|
2014-11-03 21:27:42 +00:00
|
|
|
fixed = 1;
|
2014-10-29 02:11:52 +00:00
|
|
|
}
|
2015-03-27 20:32:17 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
2014-10-29 02:11:52 +00:00
|
|
|
}
|
2015-03-27 20:32:17 +00:00
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
name_len = le16_to_cpu(dentry[i].name_len);
|
2015-03-27 20:32:17 +00:00
|
|
|
|
2016-10-13 21:40:28 +00:00
|
|
|
if (name_len == 0 || name_len > F2FS_NAME_LEN) {
|
|
|
|
ASSERT_MSG("Bad dentry 0x%x with invalid name_len", i);
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.fix_on) {
|
2015-03-27 20:32:17 +00:00
|
|
|
FIX_MSG("Clear bad dentry 0x%x", i);
|
2015-12-15 18:10:15 +00:00
|
|
|
test_and_clear_bit_le(i, bitmap);
|
2015-03-27 20:32:17 +00:00
|
|
|
fixed = 1;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
name = calloc(name_len + 1, 1);
|
2018-11-26 13:36:00 +00:00
|
|
|
ASSERT(name);
|
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
memcpy(name, filenames[i], name_len);
|
2015-03-27 21:40:37 +00:00
|
|
|
slots = (name_len + F2FS_SLOT_LEN - 1) / F2FS_SLOT_LEN;
|
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
|
|
|
|
|
|
|
/* Becareful. 'dentry.file_type' is not imode. */
|
2013-10-08 09:46:55 +00:00
|
|
|
if (ftype == F2FS_FT_DIR) {
|
2014-08-27 23:16:16 +00:00
|
|
|
if ((name[0] == '.' && name_len == 1) ||
|
|
|
|
(name[0] == '.' && name[1] == '.' &&
|
|
|
|
name_len == 2)) {
|
2019-07-11 20:45:41 +00:00
|
|
|
ret = __chk_dots_dentries(sbi, casefolded, &dentry[i],
|
2016-02-26 06:42:13 +00:00
|
|
|
child, name, name_len, &filenames[i],
|
2017-03-17 13:56:19 +00:00
|
|
|
enc_name);
|
2016-02-26 06:42:13 +00:00
|
|
|
switch (ret) {
|
|
|
|
case 1:
|
|
|
|
fixed = 1;
|
|
|
|
case 0:
|
|
|
|
child->dots++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child->dots > 2) {
|
|
|
|
ASSERT_MSG("More than one '.' or '..', should delete the extra one\n");
|
|
|
|
nullify_dentry(&dentry[i], i,
|
|
|
|
&filenames[i], &bitmap);
|
|
|
|
child->dots--;
|
|
|
|
fixed = 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
|
|
|
i++;
|
|
|
|
free(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
if (f2fs_check_hash_code(get_encoding(sbi), casefolded, dentry + i, name, name_len, enc_name))
|
2015-04-28 21:27:18 +00:00
|
|
|
fixed = 1;
|
|
|
|
|
2017-02-01 18:33:54 +00:00
|
|
|
if (max == NR_DENTRY_IN_BLOCK) {
|
2019-07-11 20:45:41 +00:00
|
|
|
ret = f2fs_check_dirent_position(get_encoding(sbi), casefolded,
|
|
|
|
name, name_len, child->pgofs,
|
2017-02-01 18:33:54 +00:00
|
|
|
child->dir_level, child->p_ino);
|
|
|
|
if (ret) {
|
|
|
|
if (c.fix_on) {
|
|
|
|
FIX_MSG("Clear bad dentry 0x%x", i);
|
|
|
|
test_and_clear_bit_le(i, bitmap);
|
|
|
|
fixed = 1;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
free(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 03:05:14 +00:00
|
|
|
|
2019-04-24 17:59:09 +00:00
|
|
|
pretty_print_filename(name, name_len, en, enc_name);
|
2014-08-27 23:16:16 +00:00
|
|
|
DBG(1, "[%3u]-[0x%x] name[%s] len[0x%x] ino[0x%x] type[0x%x]\n",
|
2016-10-24 02:16:03 +00:00
|
|
|
fsck->dentry_depth, i, en, name_len,
|
2014-10-14 22:15:40 +00:00
|
|
|
le32_to_cpu(dentry[i].ino),
|
|
|
|
dentry[i].file_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
|
|
|
|
2014-10-14 22:15:40 +00:00
|
|
|
print_dentry(fsck->dentry_depth, name, bitmap,
|
2017-03-17 13:56:19 +00:00
|
|
|
dentry, max, i, last_blk, enc_name);
|
2013-07-30 07:39:06 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
blk_cnt = 1;
|
2017-12-18 13:25:27 +00:00
|
|
|
child->i_namelen = name_len;
|
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 = fsck_chk_node_blk(sbi,
|
2017-06-05 20:44:50 +00:00
|
|
|
NULL, le32_to_cpu(dentry[i].ino),
|
2017-12-18 13:25:27 +00:00
|
|
|
ftype, TYPE_INODE, &blk_cnt, child);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2016-09-17 01:41:00 +00:00
|
|
|
if (ret && c.fix_on) {
|
2014-08-29 18:26:57 +00:00
|
|
|
int j;
|
2015-03-27 21:40:37 +00:00
|
|
|
|
2014-08-29 18:26:57 +00:00
|
|
|
for (j = 0; j < slots; j++)
|
2015-12-15 18:10:15 +00:00
|
|
|
test_and_clear_bit_le(i + j, bitmap);
|
2014-08-29 18:26:57 +00:00
|
|
|
FIX_MSG("Unlink [0x%x] - %s len[0x%x], type[0x%x]",
|
2014-10-14 22:15:40 +00:00
|
|
|
le32_to_cpu(dentry[i].ino),
|
2018-01-11 02:17:19 +00:00
|
|
|
en, name_len,
|
2014-10-14 22:15:40 +00:00
|
|
|
dentry[i].file_type);
|
2014-11-13 23:20:05 +00:00
|
|
|
fixed = 1;
|
2015-03-27 21:40:37 +00:00
|
|
|
} else if (ret == 0) {
|
|
|
|
if (ftype == F2FS_FT_DIR)
|
2015-03-30 19:57:10 +00:00
|
|
|
child->links++;
|
2015-03-27 21:40:37 +00:00
|
|
|
dentries++;
|
2015-03-30 19:57:10 +00:00
|
|
|
child->files++;
|
2014-08-29 18:26:57 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-03-27 21:40:37 +00:00
|
|
|
i += slots;
|
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(name);
|
|
|
|
}
|
2014-10-15 23:53:25 +00:00
|
|
|
return fixed ? -1 : dentries;
|
2014-10-14 22:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int fsck_chk_inline_dentries(struct f2fs_sb_info *sbi,
|
2015-03-30 19:57:10 +00:00
|
|
|
struct f2fs_node *node_blk, struct child_info *child)
|
2014-10-14 22:15:40 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2017-07-16 07:12:49 +00:00
|
|
|
struct f2fs_dentry_ptr d;
|
|
|
|
void *inline_dentry;
|
2014-10-14 22:15:40 +00:00
|
|
|
int dentries;
|
|
|
|
|
2017-07-16 07:12:49 +00:00
|
|
|
inline_dentry = inline_data_addr(node_blk);
|
|
|
|
ASSERT(inline_dentry != NULL);
|
|
|
|
|
2017-07-26 14:49:57 +00:00
|
|
|
make_dentry_ptr(&d, node_blk, inline_dentry, 2);
|
2014-10-14 22:15:40 +00:00
|
|
|
|
|
|
|
fsck->dentry_depth++;
|
2019-07-11 20:45:41 +00:00
|
|
|
dentries = __chk_dentries(sbi, IS_CASEFOLDED(&node_blk->i), child,
|
2017-07-16 07:12:49 +00:00
|
|
|
d.bitmap, d.dentry, d.filename, d.max, 1,
|
2019-07-11 20:45:41 +00:00
|
|
|
file_is_encrypt(&node_blk->i));// pass through
|
2014-10-15 23:53:25 +00:00
|
|
|
if (dentries < 0) {
|
|
|
|
DBG(1, "[%3d] Inline Dentry Block Fixed hash_codes\n\n",
|
|
|
|
fsck->dentry_depth);
|
|
|
|
} else {
|
|
|
|
DBG(1, "[%3d] Inline Dentry Block Done : "
|
2014-10-14 22:15:40 +00:00
|
|
|
"dentries:%d in %d slots (len:%d)\n\n",
|
|
|
|
fsck->dentry_depth, dentries,
|
2017-07-16 07:12:49 +00:00
|
|
|
d.max, F2FS_NAME_LEN);
|
2014-10-15 23:53:25 +00:00
|
|
|
}
|
2014-10-14 22:15:40 +00:00
|
|
|
fsck->dentry_depth--;
|
2014-10-15 23:53:25 +00:00
|
|
|
return dentries;
|
2014-10-14 22:15:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
int fsck_chk_dentry_blk(struct f2fs_sb_info *sbi, int casefolded, u32 blk_addr,
|
2017-03-17 13:56:19 +00:00
|
|
|
struct child_info *child, int last_blk, int enc_name)
|
2014-10-14 22:15:40 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_dentry_block *de_blk;
|
|
|
|
int dentries, ret;
|
|
|
|
|
|
|
|
de_blk = (struct f2fs_dentry_block *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(de_blk != NULL);
|
|
|
|
|
|
|
|
ret = dev_read_block(de_blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
fsck->dentry_depth++;
|
2019-07-11 20:45:41 +00:00
|
|
|
dentries = __chk_dentries(sbi, casefolded, child,
|
2015-12-09 19:44:31 +00:00
|
|
|
de_blk->dentry_bitmap,
|
2014-10-14 22:15:40 +00:00
|
|
|
de_blk->dentry, de_blk->filename,
|
2017-03-17 13:56:19 +00:00
|
|
|
NR_DENTRY_IN_BLOCK, last_blk, enc_name);
|
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
|
|
|
|
2019-04-23 02:42:20 +00:00
|
|
|
if (dentries < 0 && f2fs_dev_is_writable()) {
|
2014-10-15 23:53:25 +00:00
|
|
|
ret = dev_write_block(de_blk, blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
DBG(1, "[%3d] Dentry Block [0x%x] Fixed hash_codes\n\n",
|
|
|
|
fsck->dentry_depth, blk_addr);
|
|
|
|
} else {
|
|
|
|
DBG(1, "[%3d] Dentry Block [0x%x] Done : "
|
2014-08-27 23:16:16 +00:00
|
|
|
"dentries:%d in %d slots (len:%d)\n\n",
|
|
|
|
fsck->dentry_depth, blk_addr, dentries,
|
|
|
|
NR_DENTRY_IN_BLOCK, F2FS_NAME_LEN);
|
2014-10-15 23:53:25 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
fsck->dentry_depth--;
|
|
|
|
free(de_blk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:41 +00:00
|
|
|
int fsck_chk_data_blk(struct f2fs_sb_info *sbi, int casefolded,
|
|
|
|
u32 blk_addr, struct child_info *child, int last_blk,
|
2015-04-28 21:27:18 +00:00
|
|
|
enum FILE_TYPE ftype, u32 parent_nid, u16 idx_in_node, u8 ver,
|
2017-03-17 13:56:19 +00:00
|
|
|
int enc_name)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2013-10-08 09:17:33 +00:00
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
/* Is it reserved block? */
|
|
|
|
if (blk_addr == NEW_ADDR) {
|
|
|
|
fsck->chk.valid_blk_cnt++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:32:06 +00:00
|
|
|
if (!IS_VALID_BLK_ADDR(sbi, blk_addr)) {
|
2016-07-15 12:01:22 +00:00
|
|
|
ASSERT_MSG("blkaddress is not valid. [0x%x]", blk_addr);
|
2014-08-28 20:49:04 +00:00
|
|
|
return -EINVAL;
|
2014-08-27 23:32:06 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-08-28 20:49:04 +00:00
|
|
|
if (is_valid_ssa_data_blk(sbi, blk_addr, parent_nid,
|
|
|
|
idx_in_node, ver)) {
|
|
|
|
ASSERT_MSG("summary data block is not valid. [0x%x]",
|
|
|
|
parent_nid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
if (f2fs_test_sit_bitmap(sbi, blk_addr) == 0)
|
2014-08-28 00:15:55 +00:00
|
|
|
ASSERT_MSG("SIT bitmap is 0x0. blk_addr[0x%x]", 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
|
|
|
|
2014-08-27 23:16:16 +00:00
|
|
|
if (f2fs_test_main_bitmap(sbi, blk_addr) != 0)
|
|
|
|
ASSERT_MSG("Duplicated data [0x%x]. pnid[0x%x] idx[0x%x]",
|
|
|
|
blk_addr, parent_nid, idx_in_node);
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
fsck->chk.valid_blk_cnt++;
|
|
|
|
|
2014-11-06 04:25:49 +00:00
|
|
|
if (ftype == F2FS_FT_DIR) {
|
|
|
|
f2fs_set_main_bitmap(sbi, blk_addr, CURSEG_HOT_DATA);
|
2019-07-11 20:45:41 +00:00
|
|
|
return fsck_chk_dentry_blk(sbi, casefolded, blk_addr, child,
|
2017-03-17 13:56:19 +00:00
|
|
|
last_blk, enc_name);
|
2014-11-06 04:25:49 +00:00
|
|
|
} else {
|
|
|
|
f2fs_set_main_bitmap(sbi, blk_addr, CURSEG_WARM_DATA);
|
|
|
|
}
|
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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-19 13:24:40 +00:00
|
|
|
int fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
|
|
|
u32 blk_cnt = 0;
|
|
|
|
block_t start_blk, orphan_blkaddr, i, j;
|
2015-03-26 20:41:22 +00:00
|
|
|
struct f2fs_orphan_block *orphan_blk, *new_blk;
|
2015-11-22 04:02:18 +00:00
|
|
|
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
|
2015-03-26 20:41:22 +00:00
|
|
|
u32 entry_count;
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-11-22 04:02:18 +00:00
|
|
|
if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG))
|
2016-11-19 13:24:40 +00:00
|
|
|
return 0;
|
2014-08-28 00:06:17 +00:00
|
|
|
|
2015-11-22 04:02:18 +00:00
|
|
|
start_blk = __start_cp_addr(sbi) + 1 + get_sb(cp_payload);
|
2016-03-16 10:03:05 +00:00
|
|
|
orphan_blkaddr = __start_sum_addr(sbi) - 1 - get_sb(cp_payload);
|
2015-03-26 20:41:22 +00:00
|
|
|
|
2019-08-09 10:52:57 +00:00
|
|
|
f2fs_ra_meta_pages(sbi, start_blk, orphan_blkaddr, META_CP);
|
|
|
|
|
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
|
|
|
orphan_blk = calloc(BLOCK_SZ, 1);
|
2015-03-26 20:41:22 +00:00
|
|
|
ASSERT(orphan_blk);
|
|
|
|
|
|
|
|
new_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(new_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
|
|
|
|
|
|
|
for (i = 0; i < orphan_blkaddr; i++) {
|
2014-08-28 00:06:17 +00:00
|
|
|
int ret = dev_read_block(orphan_blk, start_blk + i);
|
2015-03-26 20:41:22 +00:00
|
|
|
u32 new_entry_count = 0;
|
2014-08-28 00:06:17 +00:00
|
|
|
|
|
|
|
ASSERT(ret >= 0);
|
2015-03-26 20:41:22 +00:00
|
|
|
entry_count = le32_to_cpu(orphan_blk->entry_count);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
|
2015-03-26 20:41:22 +00:00
|
|
|
for (j = 0; j < entry_count; j++) {
|
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
|
|
|
nid_t ino = le32_to_cpu(orphan_blk->ino[j]);
|
2014-02-05 16:09:36 +00:00
|
|
|
DBG(1, "[%3d] ino [0x%x]\n", i, ino);
|
2016-11-19 13:24:40 +00:00
|
|
|
struct node_info 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
|
|
|
blk_cnt = 1;
|
2016-11-19 13:24:40 +00:00
|
|
|
|
|
|
|
if (c.preen_mode == PREEN_MODE_1 && !c.fix_on) {
|
|
|
|
get_node_info(sbi, ino, &ni);
|
|
|
|
if (!IS_VALID_NID(sbi, ino) ||
|
|
|
|
!IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-05 20:44:50 +00:00
|
|
|
ret = fsck_chk_node_blk(sbi, NULL, ino,
|
2015-03-30 19:09:36 +00:00
|
|
|
F2FS_FT_ORPHAN, TYPE_INODE, &blk_cnt,
|
2016-03-16 03:07:07 +00:00
|
|
|
NULL);
|
2015-03-26 20:41:22 +00:00
|
|
|
if (!ret)
|
|
|
|
new_blk->ino[new_entry_count++] =
|
|
|
|
orphan_blk->ino[j];
|
2016-09-17 01:41:00 +00:00
|
|
|
else if (ret && c.fix_on)
|
2015-03-26 20:41:22 +00:00
|
|
|
FIX_MSG("[0x%x] remove from orphan list", ino);
|
|
|
|
else if (ret)
|
|
|
|
ASSERT_MSG("[0x%x] wrong orphan inode", ino);
|
|
|
|
}
|
2019-04-23 02:42:20 +00:00
|
|
|
if (f2fs_dev_is_writable() && c.fix_on &&
|
2015-11-22 02:53:07 +00:00
|
|
|
entry_count != new_entry_count) {
|
2015-03-26 20:41:22 +00:00
|
|
|
new_blk->entry_count = cpu_to_le32(new_entry_count);
|
|
|
|
ret = dev_write_block(new_blk, start_blk + i);
|
|
|
|
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(orphan_blk, 0, BLOCK_SZ);
|
2015-03-26 20:41:22 +00:00
|
|
|
memset(new_blk, 0, BLOCK_SZ);
|
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(orphan_blk);
|
2015-03-26 20:41:22 +00:00
|
|
|
free(new_blk);
|
2016-11-19 13:24:40 +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
|
|
|
}
|
|
|
|
|
2017-10-30 23:21:09 +00:00
|
|
|
int fsck_chk_quota_node(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
|
|
|
|
enum quota_type qtype;
|
|
|
|
int ret = 0;
|
|
|
|
u32 blk_cnt = 0;
|
|
|
|
|
|
|
|
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
|
|
|
if (sb->qf_ino[qtype] == 0)
|
|
|
|
continue;
|
|
|
|
nid_t ino = QUOTA_INO(sb, qtype);
|
|
|
|
struct node_info ni;
|
|
|
|
|
2018-06-26 08:06:54 +00:00
|
|
|
DBG(1, "qtype [%d] ino [0x%x]\n", qtype, ino);
|
2017-10-30 23:21:09 +00:00
|
|
|
blk_cnt = 1;
|
|
|
|
|
|
|
|
if (c.preen_mode == PREEN_MODE_1 && !c.fix_on) {
|
|
|
|
get_node_info(sbi, ino, &ni);
|
|
|
|
if (!IS_VALID_NID(sbi, ino) ||
|
|
|
|
!IS_VALID_BLK_ADDR(sbi, ni.blk_addr))
|
|
|
|
return -EINVAL;
|
2018-03-26 12:47:37 +00:00
|
|
|
continue;
|
2017-10-30 23:21:09 +00:00
|
|
|
}
|
|
|
|
ret = fsck_chk_node_blk(sbi, NULL, ino,
|
|
|
|
F2FS_FT_REG_FILE, TYPE_INODE, &blk_cnt, NULL);
|
|
|
|
if (ret)
|
2018-06-26 08:06:54 +00:00
|
|
|
ASSERT_MSG("wrong quota inode, qtype [%d] ino [0x%x]",
|
|
|
|
qtype, ino);
|
2017-10-30 23:21:09 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fsck_chk_quota_files(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
|
|
|
|
enum quota_type qtype;
|
|
|
|
f2fs_ino_t ino;
|
|
|
|
int ret = 0;
|
|
|
|
int needs_writeout;
|
|
|
|
|
|
|
|
/* Return if quota feature is disabled */
|
|
|
|
if (!fsck->qctx)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
|
|
|
|
ino = sb->qf_ino[qtype];
|
|
|
|
if (!ino)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DBG(1, "Checking Quota file ([%3d] ino [0x%x])\n", qtype, ino);
|
|
|
|
needs_writeout = 0;
|
2017-11-08 19:20:47 +00:00
|
|
|
ret = quota_compare_and_update(sbi, qtype, &needs_writeout,
|
|
|
|
c.preserve_limits);
|
2017-10-30 23:21:09 +00:00
|
|
|
if (ret == 0 && needs_writeout == 0) {
|
|
|
|
DBG(1, "OK\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Something is wrong */
|
|
|
|
if (c.fix_on) {
|
|
|
|
DBG(0, "Fixing Quota file ([%3d] ino [0x%x])\n",
|
|
|
|
qtype, ino);
|
|
|
|
f2fs_filesize_update(sbi, ino, 0);
|
|
|
|
ret = quota_write_inode(sbi, qtype);
|
|
|
|
if (!ret) {
|
|
|
|
c.bug_on = 1;
|
|
|
|
DBG(1, "OK\n");
|
|
|
|
} else {
|
|
|
|
ASSERT_MSG("Unable to write quota file");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ASSERT_MSG("Quota file is missing or invalid"
|
|
|
|
" quota file content found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-03-14 06:16:53 +00:00
|
|
|
int fsck_chk_meta(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
|
|
|
|
struct seg_entry *se;
|
|
|
|
unsigned int sit_valid_segs = 0, sit_node_blks = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* 1. check sit usage with CP: curseg is lost? */
|
|
|
|
for (i = 0; i < TOTAL_SEGS(sbi); i++) {
|
|
|
|
se = get_seg_entry(sbi, i);
|
|
|
|
if (se->valid_blocks != 0)
|
|
|
|
sit_valid_segs++;
|
2018-06-04 08:14:36 +00:00
|
|
|
else if (IS_CUR_SEGNO(sbi, i)) {
|
2016-03-14 06:16:53 +00:00
|
|
|
/* curseg has not been written back to device */
|
|
|
|
MSG(1, "\tInfo: curseg %u is counted in valid segs\n", i);
|
|
|
|
sit_valid_segs++;
|
|
|
|
}
|
|
|
|
if (IS_NODESEG(se->type))
|
|
|
|
sit_node_blks += se->valid_blocks;
|
|
|
|
}
|
|
|
|
if (fsck->chk.sit_free_segs + sit_valid_segs != TOTAL_SEGS(sbi)) {
|
|
|
|
ASSERT_MSG("SIT usage does not match: sit_free_segs %u, "
|
|
|
|
"sit_valid_segs %u, total_segs %u",
|
|
|
|
fsck->chk.sit_free_segs, sit_valid_segs,
|
|
|
|
TOTAL_SEGS(sbi));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2. check node count */
|
|
|
|
if (fsck->chk.valid_nat_entry_cnt != sit_node_blks) {
|
|
|
|
ASSERT_MSG("node count does not match: valid_nat_entry_cnt %u,"
|
|
|
|
" sit_node_blks %u",
|
|
|
|
fsck->chk.valid_nat_entry_cnt, sit_node_blks);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 3. check SIT with CP */
|
|
|
|
if (fsck->chk.sit_free_segs != le32_to_cpu(cp->free_segment_count)) {
|
|
|
|
ASSERT_MSG("free segs does not match: sit_free_segs %u, "
|
|
|
|
"free_segment_count %u",
|
|
|
|
fsck->chk.sit_free_segs,
|
|
|
|
le32_to_cpu(cp->free_segment_count));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 4. check NAT with CP */
|
|
|
|
if (fsck->chk.valid_nat_entry_cnt !=
|
|
|
|
le32_to_cpu(cp->valid_node_count)) {
|
|
|
|
ASSERT_MSG("valid node does not match: valid_nat_entry_cnt %u,"
|
|
|
|
" valid_node_count %u",
|
|
|
|
fsck->chk.valid_nat_entry_cnt,
|
|
|
|
le32_to_cpu(cp->valid_node_count));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-11-19 13:24:40 +00:00
|
|
|
/* 4. check orphan inode simply */
|
|
|
|
if (fsck_chk_orphan_node(sbi))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-05-07 18:49:58 +00:00
|
|
|
/* 5. check nat entry -- must be done before quota check */
|
2016-03-14 06:16:55 +00:00
|
|
|
for (i = 0; i < fsck->nr_nat_entries; i++) {
|
|
|
|
u32 blk = le32_to_cpu(fsck->entries[i].block_addr);
|
|
|
|
nid_t ino = le32_to_cpu(fsck->entries[i].ino);
|
|
|
|
|
|
|
|
if (!blk)
|
|
|
|
/*
|
|
|
|
* skip entry whose ino is 0, otherwise, we will
|
|
|
|
* get a negative number by BLKOFF_FROM_MAIN(sbi, blk)
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!IS_VALID_BLK_ADDR(sbi, blk)) {
|
|
|
|
MSG(0, "\tError: nat entry[ino %u block_addr 0x%x]"
|
|
|
|
" is in valid\n",
|
|
|
|
ino, blk);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f2fs_test_sit_bitmap(sbi, blk)) {
|
|
|
|
MSG(0, "\tError: nat entry[ino %u block_addr 0x%x]"
|
|
|
|
" not find it in sit_area_bitmap\n",
|
|
|
|
ino, blk);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IS_VALID_NID(sbi, ino)) {
|
|
|
|
MSG(0, "\tError: nat_entry->ino %u exceeds the range"
|
|
|
|
" of nat entries %u\n",
|
|
|
|
ino, fsck->nr_nat_entries);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f2fs_test_bit(ino, fsck->nat_area_bitmap)) {
|
|
|
|
MSG(0, "\tError: nat_entry->ino %u is not set in"
|
|
|
|
" nat_area_bitmap\n", ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 18:49:58 +00:00
|
|
|
/* 6. check quota inode simply */
|
|
|
|
if (fsck_chk_quota_node(sbi))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (fsck->nat_valid_inode_cnt != le32_to_cpu(cp->valid_inode_count)) {
|
|
|
|
ASSERT_MSG("valid inode does not match: nat_valid_inode_cnt %u,"
|
|
|
|
" valid_inode_count %u",
|
|
|
|
fsck->nat_valid_inode_cnt,
|
|
|
|
le32_to_cpu(cp->valid_inode_count));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-03-14 06:16:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
f2fs-tools: relocate chksum_offset for large_nat_bitmap feature
For large_nat_bitmap feature, there is a design flaw:
Previous:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----|-------+
| ...... | | |
| checksum_value |<-----+ |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Obviously, if nat_bitmap size + sit_bitmap size is larger than
MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap
checkpoint checksum's position, once checkpoint() is triggered
from kernel, nat or sit bitmap will be damaged by checksum field.
In order to fix this, let's relocate checksum_value's position
to the head of sit_nat_version_bitmap as below, then nat/sit
bitmap and chksum value update will become safe.
After:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----+
| ...... |<-------------+
| | |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Related report and discussion:
https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/
In addition, during writing checkpoint, if large_nat_bitmap feature is
enabled, we need to set CP_LARGE_NAT_BITMAP_FLAG flag in checkpoint.
Reported-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-05-14 09:33:40 +00:00
|
|
|
void fsck_chk_checkpoint(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
|
|
|
|
|
|
|
|
if (get_cp(ckpt_flags) & CP_LARGE_NAT_BITMAP_FLAG) {
|
|
|
|
if (get_cp(checksum_offset) != CP_MIN_CHKSUM_OFFSET) {
|
|
|
|
ASSERT_MSG("Deprecated layout of large_nat_bitmap, "
|
|
|
|
"chksum_offset:%u", get_cp(checksum_offset));
|
|
|
|
c.fix_chksum = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 00:06:17 +00:00
|
|
|
void fsck_init(struct f2fs_sb_info *sbi)
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_sm_info *sm_i = SM_I(sbi);
|
|
|
|
|
|
|
|
/*
|
2014-08-27 23:16:16 +00:00
|
|
|
* We build three bitmap for main/sit/nat so that may check consistency
|
|
|
|
* of filesystem.
|
|
|
|
* 1. main_area_bitmap will be used to check whether all blocks of main
|
|
|
|
* area is used or not.
|
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
|
|
|
* 2. nat_area_bitmap has bitmap information of used nid in NAT.
|
|
|
|
* 3. sit_area_bitmap has bitmap information of used main block.
|
|
|
|
* At Last sequence, we compare main_area_bitmap with sit_area_bitmap.
|
|
|
|
*/
|
|
|
|
fsck->nr_main_blks = sm_i->main_segments << sbi->log_blocks_per_seg;
|
|
|
|
fsck->main_area_bitmap_sz = (fsck->nr_main_blks + 7) / 8;
|
|
|
|
fsck->main_area_bitmap = calloc(fsck->main_area_bitmap_sz, 1);
|
|
|
|
ASSERT(fsck->main_area_bitmap != NULL);
|
|
|
|
|
|
|
|
build_nat_area_bitmap(sbi);
|
|
|
|
|
|
|
|
build_sit_area_bitmap(sbi);
|
|
|
|
|
2015-12-14 11:31:28 +00:00
|
|
|
ASSERT(tree_mark_size != 0);
|
2013-07-30 07:39:06 +00:00
|
|
|
tree_mark = calloc(tree_mark_size, 1);
|
2014-08-28 00:06:17 +00:00
|
|
|
ASSERT(tree_mark != NULL);
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:26:44 +00:00
|
|
|
static void fix_hard_links(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct hard_link_node *tmp, *node;
|
|
|
|
struct f2fs_node *node_blk = NULL;
|
|
|
|
struct node_info ni;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (fsck->hard_link_list_head == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
node_blk = (struct f2fs_node *)calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(node_blk != NULL);
|
|
|
|
|
|
|
|
node = fsck->hard_link_list_head;
|
|
|
|
while (node) {
|
|
|
|
/* Sanity check */
|
|
|
|
if (sanity_check_nid(sbi, node->nid, node_blk,
|
2017-06-05 20:44:50 +00:00
|
|
|
F2FS_FT_MAX, TYPE_INODE, &ni))
|
2015-03-26 01:26:44 +00:00
|
|
|
FIX_MSG("Failed to fix, rerun fsck.f2fs");
|
|
|
|
|
|
|
|
node_blk->i.i_links = cpu_to_le32(node->actual_links);
|
|
|
|
|
|
|
|
FIX_MSG("File: 0x%x i_links= 0x%x -> 0x%x",
|
|
|
|
node->nid, node->links, node->actual_links);
|
|
|
|
|
|
|
|
ret = dev_write_block(node_blk, ni.blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
tmp = node;
|
|
|
|
node = node->next;
|
|
|
|
free(tmp);
|
|
|
|
}
|
2016-09-21 13:01:55 +00:00
|
|
|
free(node_blk);
|
2015-03-26 01:26:44 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 21:55:07 +00:00
|
|
|
static void fix_nat_entries(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2014-09-02 17:52:56 +00:00
|
|
|
u32 i;
|
2014-08-28 21:55:07 +00:00
|
|
|
|
|
|
|
for (i = 0; i < fsck->nr_nat_entries; i++)
|
|
|
|
if (f2fs_test_bit(i, fsck->nat_area_bitmap) != 0)
|
|
|
|
nullify_nat_entry(sbi, i);
|
|
|
|
}
|
|
|
|
|
2016-11-23 12:40:06 +00:00
|
|
|
static void flush_curseg_sit_entries(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct sit_info *sit_i = SIT_I(sbi);
|
2018-01-29 03:22:14 +00:00
|
|
|
struct f2fs_sit_block *sit_blk;
|
2016-11-23 12:40:06 +00:00
|
|
|
int i;
|
|
|
|
|
2018-01-29 03:22:14 +00:00
|
|
|
sit_blk = calloc(BLOCK_SZ, 1);
|
|
|
|
ASSERT(sit_blk);
|
2016-11-23 12:40:06 +00:00
|
|
|
/* update curseg sit entries, since we may change
|
|
|
|
* a segment type in move_curseg_info
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NO_CHECK_TYPE; i++) {
|
|
|
|
struct curseg_info *curseg = CURSEG_I(sbi, i);
|
|
|
|
struct f2fs_sit_entry *sit;
|
|
|
|
struct seg_entry *se;
|
|
|
|
|
|
|
|
se = get_seg_entry(sbi, curseg->segno);
|
2018-01-29 03:22:14 +00:00
|
|
|
get_current_sit_page(sbi, curseg->segno, sit_blk);
|
2016-11-23 12:40:06 +00:00
|
|
|
sit = &sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, curseg->segno)];
|
|
|
|
sit->vblocks = cpu_to_le16((se->type << SIT_VBLOCKS_SHIFT) |
|
|
|
|
se->valid_blocks);
|
|
|
|
rewrite_current_sit_page(sbi, curseg->segno, sit_blk);
|
|
|
|
}
|
2018-01-29 03:22:14 +00:00
|
|
|
|
|
|
|
free(sit_blk);
|
2016-11-23 12:40:06 +00:00
|
|
|
}
|
|
|
|
|
f2fs-tools: relocate chksum_offset for large_nat_bitmap feature
For large_nat_bitmap feature, there is a design flaw:
Previous:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----|-------+
| ...... | | |
| checksum_value |<-----+ |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Obviously, if nat_bitmap size + sit_bitmap size is larger than
MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap
checkpoint checksum's position, once checkpoint() is triggered
from kernel, nat or sit bitmap will be damaged by checksum field.
In order to fix this, let's relocate checksum_value's position
to the head of sit_nat_version_bitmap as below, then nat/sit
bitmap and chksum value update will become safe.
After:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----+
| ...... |<-------------+
| | |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Related report and discussion:
https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/
In addition, during writing checkpoint, if large_nat_bitmap feature is
enabled, we need to set CP_LARGE_NAT_BITMAP_FLAG flag in checkpoint.
Reported-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-05-14 09:33:40 +00:00
|
|
|
static void fix_checksum(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
|
|
|
|
struct f2fs_nm_info *nm_i = NM_I(sbi);
|
|
|
|
struct sit_info *sit_i = SIT_I(sbi);
|
|
|
|
void *bitmap_offset;
|
|
|
|
|
|
|
|
if (!c.fix_chksum)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bitmap_offset = cp->sit_nat_version_bitmap + sizeof(__le32);
|
|
|
|
|
|
|
|
memcpy(bitmap_offset, nm_i->nat_bitmap, nm_i->bitmap_size);
|
|
|
|
memcpy(bitmap_offset + nm_i->bitmap_size,
|
|
|
|
sit_i->sit_bitmap, sit_i->bitmap_size);
|
|
|
|
}
|
|
|
|
|
2014-08-28 21:55:07 +00:00
|
|
|
static void fix_checkpoint(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2015-11-22 04:02:18 +00:00
|
|
|
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
|
|
|
|
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
|
2014-08-28 21:55:07 +00:00
|
|
|
unsigned long long cp_blk_no;
|
2018-10-01 01:16:38 +00:00
|
|
|
u32 flags = c.alloc_failed ? CP_FSCK_FLAG: CP_UMOUNT_FLAG;
|
2015-03-26 20:41:22 +00:00
|
|
|
block_t orphan_blks = 0;
|
2018-10-01 01:16:38 +00:00
|
|
|
block_t cp_blocks;
|
2014-09-02 17:52:56 +00:00
|
|
|
u32 i;
|
|
|
|
int ret;
|
2014-08-28 21:55:07 +00:00
|
|
|
u_int32_t crc = 0;
|
|
|
|
|
2019-08-05 09:44:06 +00:00
|
|
|
/* should call from fsck */
|
|
|
|
ASSERT(c.func == FSCK);
|
|
|
|
|
2015-11-22 04:02:18 +00:00
|
|
|
if (is_set_ckpt_flags(cp, CP_ORPHAN_PRESENT_FLAG)) {
|
2015-03-26 20:41:22 +00:00
|
|
|
orphan_blks = __start_sum_addr(sbi) - 1;
|
|
|
|
flags |= CP_ORPHAN_PRESENT_FLAG;
|
|
|
|
}
|
2019-01-25 04:38:10 +00:00
|
|
|
if (is_set_ckpt_flags(cp, CP_TRIMMED_FLAG))
|
|
|
|
flags |= CP_TRIMMED_FLAG;
|
2018-09-20 23:16:07 +00:00
|
|
|
if (is_set_ckpt_flags(cp, CP_DISABLED_FLAG))
|
|
|
|
flags |= CP_DISABLED_FLAG;
|
f2fs-tools: relocate chksum_offset for large_nat_bitmap feature
For large_nat_bitmap feature, there is a design flaw:
Previous:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----|-------+
| ...... | | |
| checksum_value |<-----+ |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Obviously, if nat_bitmap size + sit_bitmap size is larger than
MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap
checkpoint checksum's position, once checkpoint() is triggered
from kernel, nat or sit bitmap will be damaged by checksum field.
In order to fix this, let's relocate checksum_value's position
to the head of sit_nat_version_bitmap as below, then nat/sit
bitmap and chksum value update will become safe.
After:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----+
| ...... |<-------------+
| | |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Related report and discussion:
https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/
In addition, during writing checkpoint, if large_nat_bitmap feature is
enabled, we need to set CP_LARGE_NAT_BITMAP_FLAG flag in checkpoint.
Reported-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-05-14 09:33:40 +00:00
|
|
|
if (is_set_ckpt_flags(cp, CP_LARGE_NAT_BITMAP_FLAG)) {
|
|
|
|
flags |= CP_LARGE_NAT_BITMAP_FLAG;
|
|
|
|
set_cp(checksum_offset, CP_MIN_CHKSUM_OFFSET);
|
|
|
|
} else {
|
|
|
|
set_cp(checksum_offset, CP_CHKSUM_OFFSET);
|
|
|
|
}
|
2015-03-26 20:41:22 +00:00
|
|
|
|
2018-10-01 01:16:38 +00:00
|
|
|
if (flags & CP_UMOUNT_FLAG)
|
|
|
|
cp_blocks = 8;
|
|
|
|
else
|
|
|
|
cp_blocks = 5;
|
|
|
|
|
|
|
|
set_cp(cp_pack_total_block_count, cp_blocks +
|
|
|
|
orphan_blks + get_sb(cp_payload));
|
2014-08-28 21:55:07 +00:00
|
|
|
|
2017-02-09 02:55:43 +00:00
|
|
|
flags = update_nat_bits_flags(sb, cp, flags);
|
2018-01-20 21:51:05 +00:00
|
|
|
flags |= CP_NOCRC_RECOVERY_FLAG;
|
2017-02-09 02:55:43 +00:00
|
|
|
set_cp(ckpt_flags, flags);
|
|
|
|
|
2016-11-02 10:17:18 +00:00
|
|
|
set_cp(free_segment_count, get_free_segments(sbi));
|
2015-11-22 04:02:18 +00:00
|
|
|
set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
|
|
|
|
set_cp(valid_node_count, fsck->chk.valid_node_cnt);
|
|
|
|
set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
|
2014-08-28 21:55:07 +00:00
|
|
|
|
2019-05-14 09:33:39 +00:00
|
|
|
crc = f2fs_checkpoint_chksum(cp);
|
|
|
|
*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
|
|
|
|
cpu_to_le32(crc);
|
2014-08-28 21:55:07 +00:00
|
|
|
|
2015-11-22 04:02:18 +00:00
|
|
|
cp_blk_no = get_sb(cp_blkaddr);
|
2014-08-28 21:55:07 +00:00
|
|
|
if (sbi->cur_cp == 2)
|
2015-11-22 04:02:18 +00:00
|
|
|
cp_blk_no += 1 << get_sb(log_blocks_per_seg);
|
2014-08-28 21:55:07 +00:00
|
|
|
|
2015-11-22 04:02:18 +00:00
|
|
|
ret = dev_write_block(cp, cp_blk_no++);
|
2014-08-28 21:55:07 +00:00
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
2015-11-22 04:02:18 +00:00
|
|
|
for (i = 0; i < get_sb(cp_payload); i++) {
|
2019-05-19 05:05:52 +00:00
|
|
|
ret = dev_write_block(((unsigned char *)cp) +
|
|
|
|
(i + 1) * F2FS_BLKSIZE, cp_blk_no++);
|
2014-08-28 21:55:07 +00:00
|
|
|
ASSERT(ret >= 0);
|
|
|
|
}
|
|
|
|
|
2015-03-26 20:41:22 +00:00
|
|
|
cp_blk_no += orphan_blks;
|
|
|
|
|
2014-08-28 21:55:07 +00:00
|
|
|
for (i = 0; i < NO_CHECK_TYPE; i++) {
|
|
|
|
struct curseg_info *curseg = CURSEG_I(sbi, i);
|
|
|
|
|
2018-10-01 01:16:38 +00:00
|
|
|
if (!(flags & CP_UMOUNT_FLAG) && IS_NODESEG(i))
|
|
|
|
continue;
|
|
|
|
|
2014-08-28 21:55:07 +00:00
|
|
|
ret = dev_write_block(curseg->sum_blk, cp_blk_no++);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
}
|
|
|
|
|
2017-02-09 02:55:43 +00:00
|
|
|
/* Write nat bits */
|
|
|
|
if (flags & CP_NAT_BITS_FLAG)
|
|
|
|
write_nat_bits(sbi, sb, cp, sbi->cur_cp);
|
2019-05-24 08:26:40 +00:00
|
|
|
|
|
|
|
ret = f2fs_fsync_device();
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
ret = dev_write_block(cp, cp_blk_no++);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
ret = f2fs_fsync_device();
|
|
|
|
ASSERT(ret >= 0);
|
2014-08-28 21:55:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-17 01:28:51 +00:00
|
|
|
static void fix_checkpoints(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
/* copy valid checkpoint to its mirror position */
|
|
|
|
duplicate_checkpoint(sbi);
|
|
|
|
|
|
|
|
/* repair checkpoint at CP #0 position */
|
|
|
|
sbi->cur_cp = 1;
|
|
|
|
fix_checkpoint(sbi);
|
|
|
|
}
|
|
|
|
|
2019-05-16 12:40:42 +00:00
|
|
|
int check_curseg_offset(struct f2fs_sb_info *sbi, int type)
|
2014-08-28 23:55:45 +00:00
|
|
|
{
|
2019-05-16 12:40:42 +00:00
|
|
|
struct curseg_info *curseg = CURSEG_I(sbi, type);
|
|
|
|
struct seg_entry *se;
|
|
|
|
int j, nblocks;
|
2014-08-28 23:55:45 +00:00
|
|
|
|
2019-05-16 12:40:42 +00:00
|
|
|
if ((curseg->next_blkoff >> 3) >= SIT_VBLOCK_MAP_SIZE) {
|
|
|
|
ASSERT_MSG("Next block offset:%u is invalid, type:%d",
|
|
|
|
curseg->next_blkoff, type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
se = get_seg_entry(sbi, curseg->segno);
|
|
|
|
if (f2fs_test_bit(curseg->next_blkoff,
|
|
|
|
(const char *)se->cur_valid_map)) {
|
|
|
|
ASSERT_MSG("Next block offset is not free, type:%d", type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (curseg->alloc_type == SSR)
|
|
|
|
return 0;
|
2014-08-28 23:55:45 +00:00
|
|
|
|
2019-05-16 12:40:42 +00:00
|
|
|
nblocks = sbi->blocks_per_seg;
|
|
|
|
for (j = curseg->next_blkoff + 1; j < nblocks; j++) {
|
|
|
|
if (f2fs_test_bit(j, (const char *)se->cur_valid_map)) {
|
|
|
|
ASSERT_MSG("For LFS curseg, space after .next_blkoff "
|
|
|
|
"should be unused, type:%d", type);
|
2014-08-28 23:55:45 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2019-05-16 12:40:42 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-10 04:30:41 +00:00
|
|
|
|
2019-05-16 12:40:42 +00:00
|
|
|
int check_curseg_offsets(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < NO_CHECK_TYPE; i++) {
|
|
|
|
ret = check_curseg_offset(sbi, i);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-08-28 23:55:45 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-16 12:40:43 +00:00
|
|
|
static void fix_curseg_info(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
int i, need_update = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < NO_CHECK_TYPE; i++) {
|
|
|
|
if (check_curseg_offset(sbi, i)) {
|
|
|
|
update_curseg_info(sbi, i);
|
|
|
|
need_update = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_update) {
|
|
|
|
write_curseg_info(sbi);
|
|
|
|
flush_curseg_sit_entries(sbi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 21:30:24 +00:00
|
|
|
int check_sit_types(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < TOTAL_SEGS(sbi); i++) {
|
|
|
|
struct seg_entry *se;
|
|
|
|
|
|
|
|
se = get_seg_entry(sbi, i);
|
|
|
|
if (se->orig_type != se->type) {
|
2017-01-24 02:45:47 +00:00
|
|
|
if (se->orig_type == CURSEG_COLD_DATA &&
|
|
|
|
se->type <= CURSEG_COLD_DATA) {
|
2014-11-25 01:43:44 +00:00
|
|
|
se->type = se->orig_type;
|
|
|
|
} else {
|
|
|
|
FIX_MSG("Wrong segment type [0x%x] %x -> %x",
|
|
|
|
i, se->orig_type, se->type);
|
|
|
|
err = -EINVAL;
|
|
|
|
}
|
2014-11-13 21:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-03-06 03:39:40 +00:00
|
|
|
static struct f2fs_node *fsck_get_lpf(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_node *node;
|
|
|
|
struct node_info ni;
|
|
|
|
nid_t lpf_ino;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* read root inode first */
|
|
|
|
node = calloc(F2FS_BLKSIZE, 1);
|
|
|
|
ASSERT(node);
|
|
|
|
get_node_info(sbi, F2FS_ROOT_INO(sbi), &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
/* lookup lost+found in root directory */
|
|
|
|
lpf_ino = f2fs_lookup(sbi, node, (u8 *)LPF, strlen(LPF));
|
|
|
|
if (lpf_ino) { /* found */
|
|
|
|
get_node_info(sbi, lpf_ino, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
DBG(1, "Found lost+found 0x%x at blkaddr [0x%x]\n",
|
|
|
|
lpf_ino, ni.blk_addr);
|
|
|
|
if (!S_ISDIR(le16_to_cpu(node->i.i_mode))) {
|
|
|
|
ASSERT_MSG("lost+found is not directory [0%o]\n",
|
|
|
|
le16_to_cpu(node->i.i_mode));
|
|
|
|
/* FIXME: give up? */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else { /* not found, create it */
|
|
|
|
struct dentry de;
|
|
|
|
|
|
|
|
memset(&de, 0, sizeof(de));
|
|
|
|
de.name = (u8 *) LPF;
|
|
|
|
de.len = strlen(LPF);
|
|
|
|
de.mode = 0x41c0;
|
|
|
|
de.pino = F2FS_ROOT_INO(sbi),
|
|
|
|
de.file_type = F2FS_FT_DIR,
|
|
|
|
de.uid = getuid();
|
|
|
|
de.gid = getgid();
|
|
|
|
de.mtime = time(NULL);
|
|
|
|
|
|
|
|
err = f2fs_mkdir(sbi, &de);
|
|
|
|
if (err) {
|
|
|
|
ASSERT_MSG("Failed create lost+found");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_node_info(sbi, de.ino, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
DBG(1, "Create lost+found 0x%x at blkaddr [0x%x]\n",
|
|
|
|
de.ino, ni.blk_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
c.lpf_ino = le32_to_cpu(node->footer.ino);
|
|
|
|
return node;
|
|
|
|
out:
|
|
|
|
free(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fsck_do_reconnect_file(struct f2fs_sb_info *sbi,
|
|
|
|
struct f2fs_node *lpf,
|
|
|
|
struct f2fs_node *fnode)
|
|
|
|
{
|
|
|
|
char name[80];
|
|
|
|
size_t namelen;
|
|
|
|
nid_t ino = le32_to_cpu(fnode->footer.ino);
|
|
|
|
struct node_info ni;
|
|
|
|
int ftype, ret;
|
|
|
|
|
|
|
|
namelen = snprintf(name, 80, "%u", ino);
|
|
|
|
if (namelen >= 80)
|
|
|
|
/* ignore terminating '\0', should never happen */
|
|
|
|
namelen = 79;
|
|
|
|
|
|
|
|
if (f2fs_lookup(sbi, lpf, (u8 *)name, namelen)) {
|
|
|
|
ASSERT_MSG("Name %s already exist in lost+found", name);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_node_info(sbi, le32_to_cpu(lpf->footer.ino), &ni);
|
|
|
|
ftype = map_de_type(le16_to_cpu(fnode->i.i_mode));
|
|
|
|
ret = f2fs_add_link(sbi, lpf, (unsigned char *)name, namelen,
|
|
|
|
ino, ftype, ni.blk_addr, 0);
|
|
|
|
if (ret) {
|
|
|
|
ASSERT_MSG("Failed to add inode [0x%x] to lost+found", ino);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update fnode */
|
|
|
|
memcpy(fnode->i.i_name, name, namelen);
|
|
|
|
fnode->i.i_namelen = cpu_to_le32(namelen);
|
|
|
|
fnode->i.i_pino = c.lpf_ino;
|
|
|
|
get_node_info(sbi, le32_to_cpu(fnode->footer.ino), &ni);
|
|
|
|
ret = dev_write_block(fnode, ni.blk_addr);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
|
|
|
|
DBG(1, "Reconnect inode [0x%x] to lost+found\n", ino);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fsck_failed_reconnect_file_dnode(struct f2fs_sb_info *sbi,
|
|
|
|
nid_t nid)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_node *node;
|
|
|
|
struct node_info ni;
|
|
|
|
u32 addr;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
node = calloc(F2FS_BLKSIZE, 1);
|
|
|
|
ASSERT(node);
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
fsck->chk.valid_node_cnt--;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
f2fs_clear_main_bitmap(sbi, ni.blk_addr);
|
|
|
|
|
|
|
|
for (i = 0; i < ADDRS_PER_BLOCK; i++) {
|
|
|
|
addr = le32_to_cpu(node->dn.addr[i]);
|
|
|
|
if (!addr)
|
|
|
|
continue;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
if (addr == NEW_ADDR)
|
|
|
|
continue;
|
|
|
|
f2fs_clear_main_bitmap(sbi, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fsck_failed_reconnect_file_idnode(struct f2fs_sb_info *sbi,
|
|
|
|
nid_t nid)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_node *node;
|
|
|
|
struct node_info ni;
|
|
|
|
nid_t tmp;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
node = calloc(F2FS_BLKSIZE, 1);
|
|
|
|
ASSERT(node);
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
fsck->chk.valid_node_cnt--;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
f2fs_clear_main_bitmap(sbi, ni.blk_addr);
|
|
|
|
|
|
|
|
for (i = 0; i < NIDS_PER_BLOCK; i++) {
|
|
|
|
tmp = le32_to_cpu(node->in.nid[i]);
|
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
fsck_failed_reconnect_file_dnode(sbi, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fsck_failed_reconnect_file_didnode(struct f2fs_sb_info *sbi,
|
|
|
|
nid_t nid)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_node *node;
|
|
|
|
struct node_info ni;
|
|
|
|
nid_t tmp;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
node = calloc(F2FS_BLKSIZE, 1);
|
|
|
|
ASSERT(node);
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
fsck->chk.valid_node_cnt--;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
f2fs_clear_main_bitmap(sbi, ni.blk_addr);
|
|
|
|
|
|
|
|
for (i = 0; i < NIDS_PER_BLOCK; i++) {
|
|
|
|
tmp = le32_to_cpu(node->in.nid[i]);
|
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
fsck_failed_reconnect_file_idnode(sbi, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Counters and main_area_bitmap are already changed during checking
|
|
|
|
* inode block, so clear them. There is no need to clear new blocks
|
|
|
|
* allocted to lost+found.
|
|
|
|
*/
|
|
|
|
static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_node *node;
|
|
|
|
struct node_info ni;
|
|
|
|
nid_t nid;
|
|
|
|
int ofs, i, err;
|
|
|
|
|
|
|
|
node = calloc(F2FS_BLKSIZE, 1);
|
|
|
|
ASSERT(node);
|
|
|
|
|
|
|
|
get_node_info(sbi, ino, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
/* clear inode counters */
|
|
|
|
fsck->chk.valid_inode_cnt--;
|
|
|
|
fsck->chk.valid_node_cnt--;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
f2fs_clear_main_bitmap(sbi, ni.blk_addr);
|
|
|
|
|
|
|
|
/* clear xnid counters */
|
|
|
|
if (node->i.i_xattr_nid) {
|
|
|
|
nid = le32_to_cpu(node->i.i_xattr_nid);
|
|
|
|
fsck->chk.valid_node_cnt--;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
f2fs_clear_main_bitmap(sbi, ni.blk_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear data counters */
|
|
|
|
if(!(node->i.i_inline & F2FS_INLINE_DATA)) {
|
|
|
|
ofs = get_extra_isize(node);
|
|
|
|
for (i = 0; i < ADDRS_PER_INODE(&node->i); i++) {
|
|
|
|
block_t addr = le32_to_cpu(node->i.i_addr[ofs + i]);
|
|
|
|
if (!addr)
|
|
|
|
continue;
|
|
|
|
fsck->chk.valid_blk_cnt--;
|
|
|
|
if (addr == NEW_ADDR)
|
|
|
|
continue;
|
|
|
|
f2fs_clear_main_bitmap(sbi, addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
nid = le32_to_cpu(node->i.i_nid[i]);
|
|
|
|
if (!nid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0: /* direct node */
|
|
|
|
case 1:
|
|
|
|
fsck_failed_reconnect_file_dnode(sbi, nid);
|
|
|
|
break;
|
|
|
|
case 2: /* indirect node */
|
|
|
|
case 3:
|
|
|
|
fsck_failed_reconnect_file_idnode(sbi, nid);
|
|
|
|
break;
|
|
|
|
case 4: /* double indirect node */
|
|
|
|
fsck_failed_reconnect_file_didnode(sbi, nid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan unreachable nids and find only regular file inodes. If these files
|
|
|
|
* are not corrupted, reconnect them to lost+found.
|
|
|
|
*
|
|
|
|
* Since all unreachable nodes are already checked, we can allocate new
|
|
|
|
* blocks safely.
|
|
|
|
*
|
|
|
|
* This function returns the number of files been reconnected.
|
|
|
|
*/
|
|
|
|
static int fsck_reconnect_file(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct f2fs_node *lpf_node, *node;
|
|
|
|
struct node_info ni;
|
|
|
|
char *reconnect_bitmap;
|
|
|
|
u32 blk_cnt;
|
|
|
|
nid_t nid;
|
|
|
|
int err, cnt = 0, ftype;
|
|
|
|
|
|
|
|
node = calloc(F2FS_BLKSIZE, 1);
|
|
|
|
ASSERT(node);
|
|
|
|
|
|
|
|
reconnect_bitmap = calloc(fsck->nat_area_bitmap_sz, 1);
|
|
|
|
ASSERT(reconnect_bitmap);
|
|
|
|
|
|
|
|
for (nid = 0; nid < fsck->nr_nat_entries; nid++) {
|
|
|
|
if (f2fs_test_bit(nid, fsck->nat_area_bitmap)) {
|
|
|
|
if (is_qf_ino(F2FS_RAW_SUPER(sbi), nid)) {
|
|
|
|
DBG(1, "Not support quota inode [0x%x]\n",
|
|
|
|
nid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
/* reconnection will restore these nodes if needed */
|
|
|
|
if (node->footer.ino != node->footer.nid) {
|
|
|
|
DBG(1, "Not support non-inode node [0x%x]\n",
|
|
|
|
nid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISDIR(le16_to_cpu(node->i.i_mode))) {
|
|
|
|
DBG(1, "Not support directory inode [0x%x]\n",
|
|
|
|
nid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ftype = map_de_type(le16_to_cpu(node->i.i_mode));
|
|
|
|
if (sanity_check_nid(sbi, nid, node, ftype,
|
|
|
|
TYPE_INODE, &ni)) {
|
|
|
|
ASSERT_MSG("Invalid nid [0x%x]\n", nid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG(1, "Check inode 0x%x\n", nid);
|
|
|
|
blk_cnt = 1;
|
|
|
|
fsck_chk_inode_blk(sbi, nid, ftype, node,
|
|
|
|
&blk_cnt, &ni, NULL);
|
|
|
|
|
|
|
|
f2fs_set_bit(nid, reconnect_bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lpf_node = fsck_get_lpf(sbi);
|
|
|
|
if (!lpf_node)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (nid = 0; nid < fsck->nr_nat_entries; nid++) {
|
|
|
|
if (f2fs_test_bit(nid, reconnect_bitmap)) {
|
|
|
|
get_node_info(sbi, nid, &ni);
|
|
|
|
err = dev_read_block(node, ni.blk_addr);
|
|
|
|
ASSERT(err >= 0);
|
|
|
|
|
|
|
|
if (fsck_do_reconnect_file(sbi, lpf_node, node)) {
|
|
|
|
DBG(1, "Failed to reconnect inode [0x%x]\n",
|
|
|
|
nid);
|
|
|
|
fsck_failed_reconnect_file(sbi, nid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
quota_add_inode_usage(fsck->qctx, nid, &node->i);
|
|
|
|
|
|
|
|
DBG(1, "Reconnected inode [0x%x] to lost+found\n", nid);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(node);
|
|
|
|
free(lpf_node);
|
|
|
|
free(reconnect_bitmap);
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:12:13 +00:00
|
|
|
int fsck_chk_curseg_info(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct curseg_info *curseg;
|
|
|
|
struct seg_entry *se;
|
|
|
|
struct f2fs_summary_block *sum_blk;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < NO_CHECK_TYPE; i++) {
|
|
|
|
curseg = CURSEG_I(sbi, i);
|
|
|
|
se = get_seg_entry(sbi, curseg->segno);
|
|
|
|
sum_blk = curseg->sum_blk;
|
|
|
|
|
|
|
|
if (se->type != i) {
|
|
|
|
ASSERT_MSG("Incorrect curseg [%d]: segno [0x%x] "
|
|
|
|
"type(SIT) [%d]", i, curseg->segno,
|
|
|
|
se->type);
|
|
|
|
if (c.fix_on || c.preen_mode)
|
|
|
|
se->type = i;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
if (i <= CURSEG_COLD_DATA && IS_SUM_DATA_SEG(sum_blk->footer)) {
|
|
|
|
continue;
|
|
|
|
} else if (i > CURSEG_COLD_DATA && IS_SUM_NODE_SEG(sum_blk->footer)) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
ASSERT_MSG("Incorrect curseg [%d]: segno [0x%x] "
|
|
|
|
"type(SSA) [%d]", i, curseg->segno,
|
|
|
|
sum_blk->footer.entry_type);
|
|
|
|
if (c.fix_on || c.preen_mode)
|
|
|
|
sum_blk->footer.entry_type =
|
|
|
|
i <= CURSEG_COLD_DATA ?
|
|
|
|
SUM_TYPE_DATA : SUM_TYPE_NODE;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
int fsck_verify(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
2014-05-14 00:02:55 +00:00
|
|
|
unsigned int i = 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
|
|
|
int ret = 0;
|
2015-01-09 10:59:57 +00:00
|
|
|
int force = 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
|
|
|
u32 nr_unref_nid = 0;
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
|
|
|
struct hard_link_node *node = NULL;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
2018-03-06 03:39:40 +00:00
|
|
|
if (c.feature & cpu_to_le32(F2FS_FEATURE_LOST_FOUND)) {
|
|
|
|
for (i = 0; i < fsck->nr_nat_entries; i++)
|
|
|
|
if (f2fs_test_bit(i, fsck->nat_area_bitmap) != 0)
|
|
|
|
break;
|
|
|
|
if (i < fsck->nr_nat_entries) {
|
|
|
|
i = fsck_reconnect_file(sbi);
|
|
|
|
printf("[FSCK] Reconnect %u files to lost+found\n", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 (i = 0; i < fsck->nr_nat_entries; i++) {
|
|
|
|
if (f2fs_test_bit(i, fsck->nat_area_bitmap) != 0) {
|
2018-07-28 10:40:59 +00:00
|
|
|
struct node_info ni;
|
|
|
|
|
|
|
|
get_node_info(sbi, i, &ni);
|
|
|
|
printf("NID[0x%x] is unreachable, blkaddr:0x%x\n",
|
|
|
|
i, 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
|
|
|
nr_unref_nid++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fsck->hard_link_list_head != NULL) {
|
|
|
|
node = fsck->hard_link_list_head;
|
|
|
|
while (node) {
|
|
|
|
printf("NID[0x%x] has [0x%x] more unreachable links\n",
|
|
|
|
node->nid, node->links);
|
|
|
|
node = node->next;
|
|
|
|
}
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] Unreachable nat entries ");
|
|
|
|
if (nr_unref_nid == 0x0) {
|
|
|
|
printf(" [Ok..] [0x%x]\n", nr_unref_nid);
|
|
|
|
} else {
|
|
|
|
printf(" [Fail] [0x%x]\n", nr_unref_nid);
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] SIT valid block bitmap checking ");
|
2014-08-27 23:16:16 +00:00
|
|
|
if (memcmp(fsck->sit_area_bitmap, fsck->main_area_bitmap,
|
|
|
|
fsck->sit_area_bitmap_sz) == 0x0) {
|
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
|
|
|
printf("[Ok..]\n");
|
|
|
|
} else {
|
|
|
|
printf("[Fail]\n");
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] Hard link checking for regular file ");
|
|
|
|
if (fsck->hard_link_list_head == NULL) {
|
|
|
|
printf(" [Ok..] [0x%x]\n", fsck->chk.multi_hard_link_files);
|
|
|
|
} else {
|
|
|
|
printf(" [Fail] [0x%x]\n", fsck->chk.multi_hard_link_files);
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] valid_block_count matching with CP ");
|
|
|
|
if (sbi->total_valid_block_count == fsck->chk.valid_blk_cnt) {
|
2014-02-24 23:07:25 +00:00
|
|
|
printf(" [Ok..] [0x%x]\n", (u32)fsck->chk.valid_blk_cnt);
|
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 {
|
2014-02-24 23:07:25 +00:00
|
|
|
printf(" [Fail] [0x%x]\n", (u32)fsck->chk.valid_blk_cnt);
|
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 = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] valid_node_count matcing with CP (de lookup) ");
|
|
|
|
if (sbi->total_valid_node_count == fsck->chk.valid_node_cnt) {
|
|
|
|
printf(" [Ok..] [0x%x]\n", fsck->chk.valid_node_cnt);
|
|
|
|
} else {
|
|
|
|
printf(" [Fail] [0x%x]\n", fsck->chk.valid_node_cnt);
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] valid_node_count matcing with CP (nat lookup) ");
|
|
|
|
if (sbi->total_valid_node_count == fsck->chk.valid_nat_entry_cnt) {
|
|
|
|
printf(" [Ok..] [0x%x]\n", fsck->chk.valid_nat_entry_cnt);
|
|
|
|
} else {
|
|
|
|
printf(" [Fail] [0x%x]\n", fsck->chk.valid_nat_entry_cnt);
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
|
|
|
|
|
|
|
printf("[FSCK] valid_inode_count matched with CP ");
|
|
|
|
if (sbi->total_valid_inode_count == fsck->chk.valid_inode_cnt) {
|
|
|
|
printf(" [Ok..] [0x%x]\n", fsck->chk.valid_inode_cnt);
|
|
|
|
} else {
|
|
|
|
printf(" [Fail] [0x%x]\n", fsck->chk.valid_inode_cnt);
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 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
|
|
|
}
|
2014-08-28 21:55:07 +00:00
|
|
|
|
|
|
|
printf("[FSCK] free segment_count matched with CP ");
|
|
|
|
if (le32_to_cpu(F2FS_CKPT(sbi)->free_segment_count) ==
|
|
|
|
fsck->chk.sit_free_segs) {
|
|
|
|
printf(" [Ok..] [0x%x]\n", fsck->chk.sit_free_segs);
|
|
|
|
} else {
|
|
|
|
printf(" [Fail] [0x%x]\n", fsck->chk.sit_free_segs);
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 1;
|
2014-08-28 21:55:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 23:55:45 +00:00
|
|
|
printf("[FSCK] next block offset is free ");
|
2019-05-16 12:40:42 +00:00
|
|
|
if (check_curseg_offsets(sbi) == 0) {
|
2014-08-28 23:55:45 +00:00
|
|
|
printf(" [Ok..]\n");
|
|
|
|
} else {
|
|
|
|
printf(" [Fail]\n");
|
|
|
|
ret = EXIT_ERR_CODE;
|
2016-09-17 01:41:00 +00:00
|
|
|
c.bug_on = 1;
|
2014-08-28 23:55:45 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 10:59:57 +00:00
|
|
|
printf("[FSCK] fixing SIT types\n");
|
|
|
|
if (check_sit_types(sbi) != 0)
|
|
|
|
force = 1;
|
2014-11-13 21:30:24 +00:00
|
|
|
|
2014-08-28 21:55:07 +00:00
|
|
|
printf("[FSCK] other corrupted bugs ");
|
2016-09-17 01:41:00 +00:00
|
|
|
if (c.bug_on == 0) {
|
2014-08-28 21:55:07 +00:00
|
|
|
printf(" [Ok..]\n");
|
|
|
|
} else {
|
|
|
|
printf(" [Fail]\n");
|
|
|
|
ret = EXIT_ERR_CODE;
|
|
|
|
}
|
|
|
|
|
2016-10-13 23:04:52 +00:00
|
|
|
#ifndef WITH_ANDROID
|
|
|
|
if (nr_unref_nid && !c.ro) {
|
|
|
|
char ans[255] = {0};
|
|
|
|
|
|
|
|
printf("\nDo you want to restore lost files into ./lost_found/? [Y/N] ");
|
|
|
|
ret = scanf("%s", ans);
|
|
|
|
ASSERT(ret >= 0);
|
|
|
|
if (!strcasecmp(ans, "y")) {
|
|
|
|
for (i = 0; i < fsck->nr_nat_entries; i++) {
|
|
|
|
if (f2fs_test_bit(i, fsck->nat_area_bitmap))
|
|
|
|
dump_node(sbi, i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-07-17 01:28:51 +00:00
|
|
|
|
2014-08-28 21:55:07 +00:00
|
|
|
/* fix global metadata */
|
2019-04-23 02:42:20 +00:00
|
|
|
if (force || (c.fix_on && f2fs_dev_is_writable())) {
|
2016-05-03 23:58:57 +00:00
|
|
|
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
|
|
|
|
|
2018-11-28 23:11:28 +00:00
|
|
|
if (force || c.bug_on || c.bug_nat_bits) {
|
2018-06-17 17:56:49 +00:00
|
|
|
/* flush nats to write_nit_bits below */
|
|
|
|
flush_journal_entries(sbi);
|
2016-05-03 23:58:57 +00:00
|
|
|
fix_hard_links(sbi);
|
|
|
|
fix_nat_entries(sbi);
|
2016-11-02 10:17:18 +00:00
|
|
|
rewrite_sit_area_bitmap(sbi);
|
2019-05-16 12:40:43 +00:00
|
|
|
fix_curseg_info(sbi);
|
f2fs-tools: relocate chksum_offset for large_nat_bitmap feature
For large_nat_bitmap feature, there is a design flaw:
Previous:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----|-------+
| ...... | | |
| checksum_value |<-----+ |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Obviously, if nat_bitmap size + sit_bitmap size is larger than
MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap
checkpoint checksum's position, once checkpoint() is triggered
from kernel, nat or sit bitmap will be damaged by checksum field.
In order to fix this, let's relocate checksum_value's position
to the head of sit_nat_version_bitmap as below, then nat/sit
bitmap and chksum value update will become safe.
After:
struct f2fs_checkpoint layout:
+--------------------------+ 0x0000
| checkpoint_ver |
| ...... |
| checksum_offset |------+
| ...... | |
| sit_nat_version_bitmap[] |<-----+
| ...... |<-------------+
| | |
+--------------------------+ 0x1000 |
| | nat_bitmap + sit_bitmap
| payload blocks | |
| | |
+--------------------------|<-------------+
Related report and discussion:
https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/
In addition, during writing checkpoint, if large_nat_bitmap feature is
enabled, we need to set CP_LARGE_NAT_BITMAP_FLAG flag in checkpoint.
Reported-by: Park Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2019-05-14 09:33:40 +00:00
|
|
|
fix_checksum(sbi);
|
2019-07-17 01:28:51 +00:00
|
|
|
fix_checkpoints(sbi);
|
2018-09-19 01:28:37 +00:00
|
|
|
} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG) ||
|
|
|
|
is_set_ckpt_flags(cp, CP_QUOTA_NEED_FSCK_FLAG)) {
|
2019-07-17 01:28:51 +00:00
|
|
|
write_checkpoints(sbi);
|
2016-05-03 23:58:57 +00:00
|
|
|
}
|
2014-08-28 21:55:07 +00:00
|
|
|
}
|
f2fs-tools: add fsck.f2fs and dump.f2fs
fsck.f2fs checks file system consistency, but does not repair a broken
file system yet.
dump.f2fs shows the information of a specific inode and makes dump file
of SSA and SIT.
f2fs checks file system consistency as follows:
o When data about used area and its metadata are identical,
f2fs is considered consistent. To verify such consistency, we use
three bitmaps: nat_area_bitmap, sit_area_bitmap, and main_area_bitmap.
First, each bit in nat_area_bitmap corresponds to a nid in NAT.
Second, each bit in sit_area_bitmap corresponds to a valid block in a
segment. This bitmap is same to the total valid_map of f2fs_sit_entries
in SIT.
Last, each bit in main_area_bitmap corresponds to a block in main area
except meta area.
After a consistency check of each block, we set or clear the
corresponding bit of each bitmap.
From the root node, we start consistency check. The verified
information varies according to block type.
1. NODE
- Read information of node block from NAT
- Check if block address is allocated using node info.
- Check if the type of f2fs_summary related to nid in SSA is NODE.
- Update the corresponding bit in nat_area_bitmap.
- Update the corresponding bit in sit_area_bitmap.
- Set the corresponding bit in main_area_bitmap to 1.
- Then, read node block. According to its attribute, explore
inode/direct node/indirect node/double indirect node
recursively.
- If it is an inode block, we also check its xattr and hard link.
2. DATA
- Check if the type of f2fs_summary related to nid in SSA is DATA.
- Set the corresponding bits of sit_area_bitmap and
main_area_bitmap to visited
- If it is a dentry block, traverse each dentries that may be
regular
file or directory. At this time, it will check inode block again.
Finally, we verify whether
- every nat_area_bitmap is visited
- any unreachable hard link exists
- values of sit_area_bitmap and main_area_bitmap are identical
- total_valid_block_count/node_count/inode_count are correct
Usage:
o fsck.f2fs
# fsck.f2fs /dev/sdx
options:
-d debug level [default:0]
o dump.f2fs
# dump.f2fs -i [ino] /dev/sdx
# dump.f2fs -s 0~-1 /dev/sdx (SIT dump)
# dump.f2fs -a 0~-1 /dev/sdx (SSA dump)
options:
-d debug level [default:0]
-i inode no (hex)
-s [SIT dump segno from #1~#2 (decimal), for all 0~-1]
-a [SSA dump segno from #1~#2 (decimal), for all 0~-1]
Note: To use dump.f2fs, please run make install or ln -s fsck.f2fs
dump.f2fs
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Byoung Geun Kim <bgbg.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
2013-07-04 08:11:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fsck_free(struct f2fs_sb_info *sbi)
|
|
|
|
{
|
|
|
|
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
|
2017-10-30 23:21:09 +00:00
|
|
|
|
|
|
|
if (fsck->qctx)
|
|
|
|
quota_release_context(&fsck->qctx);
|
|
|
|
|
2013-07-18 02:20:05 +00:00
|
|
|
if (fsck->main_area_bitmap)
|
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(fsck->main_area_bitmap);
|
|
|
|
|
|
|
|
if (fsck->nat_area_bitmap)
|
|
|
|
free(fsck->nat_area_bitmap);
|
|
|
|
|
|
|
|
if (fsck->sit_area_bitmap)
|
|
|
|
free(fsck->sit_area_bitmap);
|
2013-07-30 07:39:06 +00:00
|
|
|
|
2016-07-15 12:01:23 +00:00
|
|
|
if (fsck->entries)
|
|
|
|
free(fsck->entries);
|
|
|
|
|
2013-07-30 07:39:06 +00:00
|
|
|
if (tree_mark)
|
|
|
|
free(tree_mark);
|
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
|
|
|
}
|