f2fs_do_mount-dfx

Signed-off-by: nieben <nieben1@huawei.com>
This commit is contained in:
nieben 2024-03-18 11:14:08 +08:00
parent 22d5d3737b
commit f505165a60
4 changed files with 127 additions and 1 deletions

View File

@ -23,6 +23,7 @@ config("f2fs-defaults") {
ohos_executable("fsck.f2fs") { ohos_executable("fsck.f2fs") {
configs = [ ":f2fs-defaults" ] configs = [ ":f2fs-defaults" ]
sources = [ sources = [
"../tools/debug_tools/fsck_debug.c",
"compress.c", "compress.c",
"defrag.c", "defrag.c",
"dict.c", "dict.c",
@ -44,6 +45,7 @@ ohos_executable("fsck.f2fs") {
include_dirs = [ include_dirs = [
".", ".",
"../tools/debug_tools",
"//third_party/f2fs-tools", "//third_party/f2fs-tools",
"//third_party/f2fs-tools/include", "//third_party/f2fs-tools/include",
"//third_party/f2fs-tools/lib", "//third_party/f2fs-tools/lib",

View File

@ -9,6 +9,7 @@
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include "fsck.h" #include "fsck.h"
#include "fsck_debug.h"
#include "node.h" #include "node.h"
#include "xattr.h" #include "xattr.h"
#include <locale.h> #include <locale.h>
@ -3594,9 +3595,11 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
ret = validate_super_block(sbi, SB0_ADDR); ret = validate_super_block(sbi, SB0_ADDR);
if (ret) { if (ret) {
ret = validate_super_block(sbi, SB1_ADDR); ret = validate_super_block(sbi, SB1_ADDR);
if (ret) if (ret) {
dump_sbi_info(sbi);
return -1; return -1;
} }
}
sb = F2FS_RAW_SUPER(sbi); sb = F2FS_RAW_SUPER(sbi);
ret = check_sector_size(sb); ret = check_sector_size(sb);
@ -3610,6 +3613,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
ret = get_valid_checkpoint(sbi); ret = get_valid_checkpoint(sbi);
if (ret) { if (ret) {
ERR_MSG("Can't find valid checkpoint\n"); ERR_MSG("Can't find valid checkpoint\n");
dump_sbi_info(sbi);
print_ckpt_info(sbi);
return -1; return -1;
} }
@ -3617,6 +3622,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
if (sanity_check_ckpt(sbi)) { if (sanity_check_ckpt(sbi)) {
ERR_MSG("Checkpoint is polluted\n"); ERR_MSG("Checkpoint is polluted\n");
dump_sbi_info(sbi);
print_ckpt_info(sbi);
return -1; return -1;
} }
cp = F2FS_CKPT(sbi); cp = F2FS_CKPT(sbi);

View File

@ -0,0 +1,69 @@
/**
* fsck_debug.c
*
* Copyright (C) 2024 Huawei Ltd.
*
* 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_debug.h"
void dump_sbi_info(struct f2fs_sb_info *sbi)
{
if (sbi == NULL) {
MSG(0, "sbi is null\n");
return;
}
MSG(0, "\n");
MSG(0, "+--------------------------------------------------------+\n");
MSG(0, "| SBI |\n");
MSG(0, "+--------------------------------------------------------+\n");
MSG(0, "total_count %u\n", total_segments(sbi));
MSG(0, "resvd_segs %u\n", reserved_segments(sbi));
MSG(0, "overp_segs %u\n", overprov_segments(sbi));
MSG(0, "valid_count %u\n", of_valid_block_count(sbi));
MSG(0, "utilization %u\n", f2fs_utilization(sbi));
MSG(0, "\n");
hex_info_dump("f2fs_sb_info", sbi,
sizeof(struct f2fs_sb_info));
MSG(0, "\n");
}
#define LINE_MAX_LEN 80
#define LINE_MAX_INTS 16
#define BATCH_INTS 8
#define HEX_SHIFT_12 12
#define HEX_SHIFT_8 8
#define HEX_SHIFT_4 4
#define HEX_MASK 0x0F
void hex_info_dump(const char *prompts, const unsigned char *buf,
unsigned int len)
{
static const unsigned char hex_ascii[] = "0123456789abcdef";
unsigned char line[LINE_MAX_LEN];
unsigned int i, j, k, line_len;
unsigned int rest = len;
MSG(0, "===HEX DUMP START: %.25s, len %u===\n",
prompts, len);
for (i = 0; i < len; i += LINE_MAX_INTS) {
line_len = rest > LINE_MAX_INTS ? LINE_MAX_INTS : rest;
k = 0;
line[k++] = hex_ascii[(i >> HEX_SHIFT_12) & HEX_MASK];
line[k++] = hex_ascii[(i >> HEX_SHIFT_8) & HEX_MASK];
line[k++] = hex_ascii[(i >> HEX_SHIFT_4) & HEX_MASK];
line[k++] = hex_ascii[i & HEX_MASK];
line[k++] = ':';
for (j = 0; j < line_len; j++) {
j % BATCH_INTS == 0 ? line[k++] = ' ' : 1;
line[k++] = hex_ascii[(buf[i + j] >> HEX_SHIFT_4) & HEX_MASK];
line[k++] = hex_ascii[(buf[i + j] & HEX_MASK)];
}
line[k++] = '\0';
rest -= line_len;
MSG(0, "%s\n", line);
}
MSG(0, "===HEX DUMP END===\n");
}

View File

@ -0,0 +1,48 @@
/**
* fsck_debug.h
*
* Copyright (C) 2024 Huawei Ltd.
*
* 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.
*/
#ifndef _FSCK_DEBUG_H_
#define _FSCK_DEBUG_H_
#include "f2fs.h"
void dump_sbi_info(struct f2fs_sb_info *);
void hex_info_dump(const char *, const unsigned char *,
unsigned int);
static inline unsigned int total_segments(struct f2fs_sb_info *sbi)
{
return sbi->blocks_per_seg == 0 ?
0 : ((unsigned int)sbi->user_block_count) /
((unsigned int)sbi->blocks_per_seg);
}
static inline unsigned int reserved_segments(struct f2fs_sb_info *sbi)
{
return sbi->sm_info == NULL ? 0 : sbi->sm_info->reserved_segments;
}
static inline unsigned int overprov_segments(struct f2fs_sb_info *sbi)
{
return sbi->sm_info == NULL ? 0 : sbi->sm_info->ovp_segments;
}
static inline block_t of_valid_block_count(struct f2fs_sb_info *sbi)
{
return sbi->total_valid_block_count;
}
static inline unsigned int f2fs_utilization(struct f2fs_sb_info *sbi)
{
/* valid block percentage of sbi */
return sbi->user_block_count == 0 ?
0 : (of_valid_block_count(sbi) * 100) / sbi->user_block_count;
}
#endif /* _FSCK_DEBUG_H_ */