!39 fix: f2fs_do_mount维测增强

Merge pull request !39 from nieben/f2fs_do_mount-dfx
This commit is contained in:
openharmony_ci 2024-03-21 07:28:59 +00:00 committed by Gitee
commit be08214cd8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 127 additions and 1 deletions

View File

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

View File

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