1/** 2 * fsck_debug.c 3 * 4 * Copyright (C) 2024 Huawei Ltd. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10#include "fsck_debug.h" 11 12void dump_sbi_info(struct f2fs_sb_info *sbi) 13{ 14 if (sbi == NULL) { 15 MSG(0, "sbi is null\n"); 16 return; 17 } 18 19 MSG(0, "\n"); 20 MSG(0, "+--------------------------------------------------------+\n"); 21 MSG(0, "| SBI |\n"); 22 MSG(0, "+--------------------------------------------------------+\n"); 23 MSG(0, "total_count %u\n", total_segments(sbi)); 24 MSG(0, "resvd_segs %u\n", reserved_segments(sbi)); 25 MSG(0, "overp_segs %u\n", overprov_segments(sbi)); 26 MSG(0, "valid_count %u\n", of_valid_block_count(sbi)); 27 MSG(0, "utilization %u\n", f2fs_utilization(sbi)); 28 MSG(0, "\n"); 29 hex_info_dump("f2fs_sb_info", sbi, 30 sizeof(struct f2fs_sb_info)); 31 MSG(0, "\n"); 32} 33 34#define LINE_MAX_LEN 80 35#define LINE_MAX_INTS 16 36#define BATCH_INTS 8 37#define HEX_SHIFT_12 12 38#define HEX_SHIFT_8 8 39#define HEX_SHIFT_4 4 40#define HEX_MASK 0x0F 41void hex_info_dump(const char *prompts, const unsigned char *buf, 42 unsigned int len) 43{ 44 static const unsigned char hex_ascii[] = "0123456789abcdef"; 45 unsigned char line[LINE_MAX_LEN]; 46 unsigned int i, j, k, line_len; 47 unsigned int rest = len; 48 49 MSG(0, "===HEX DUMP START: %.25s, len %u===\n", 50 prompts, len); 51 for (i = 0; i < len; i += LINE_MAX_INTS) { 52 line_len = rest > LINE_MAX_INTS ? LINE_MAX_INTS : rest; 53 k = 0; 54 line[k++] = hex_ascii[(i >> HEX_SHIFT_12) & HEX_MASK]; 55 line[k++] = hex_ascii[(i >> HEX_SHIFT_8) & HEX_MASK]; 56 line[k++] = hex_ascii[(i >> HEX_SHIFT_4) & HEX_MASK]; 57 line[k++] = hex_ascii[i & HEX_MASK]; 58 line[k++] = ':'; 59 for (j = 0; j < line_len; j++) { 60 j % BATCH_INTS == 0 ? line[k++] = ' ' : 1; 61 line[k++] = hex_ascii[(buf[i + j] >> HEX_SHIFT_4) & HEX_MASK]; 62 line[k++] = hex_ascii[(buf[i + j] & HEX_MASK)]; 63 } 64 line[k++] = '\0'; 65 rest -= line_len; 66 MSG(0, "%s\n", line); 67 } 68 MSG(0, "===HEX DUMP END===\n"); 69}