diff --git a/delog/delog.cpp b/delog/delog.cpp index a3e72f2..ad07edb 100644 --- a/delog/delog.cpp +++ b/delog/delog.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "delog.h" #define wmj_null (_I)-1 @@ -289,6 +290,8 @@ _wmj_delog_END: #define fmt_ext_hex(s, n) fmt_str(s, n, "XX ") #define fmt_continue(s, n, num) fmt_str(s, n, ".. (mode %d bytes not show)\n", num) #define fmt_new_line(s, n, addr) fmt_str(s, n, "\n0x%08x : ", _Lclr(addr, 4)) +#define fmt_ascii(s, n, d) fmt_str(s, n, "%c", isprint(d)?(_u8)(d):'.') +#define fmt_dot(s, n) fmt_str(s, n, "x") #define DEF_SHOW_MAX 256 #define LINEBSIZE 4 @@ -300,17 +303,28 @@ _I print_bin(_s s, _I size, _u8 *p, _I len) { _I suffixnum; _I i = 0, j = 0, re = 0, n = size; if (prefixnum) { + // 有前缀X fmt_new_line(s, n, (_u32)(_i64)(p + i)); } - //printf("%x\n%s\n", prefixnum, ms_buf); - + //printf("%x\n%s\n", prefixnum, ms_buf); while (i < prefixnum) { + // 打印X fmt_ext_hex(s, n); i++; } + _I last_i = i; while ((i < DEF_SHOW_MAX) && (len > 0)) { if ((i & _BITS_MASK(LINEBSIZE)) == 0) { + last_i = LINENUM; + if (j > 0 && j < LINENUM + 1) { + for (int t = 0; t < LINENUM - j; t++) + fmt_dot(s, n); + last_i = j; + } + while (j > 0 && last_i--) { + fmt_ascii(s, n, p[j - last_i - 1]); + } fmt_new_line(s, n, (_u32)(_i64)(p + i)); } fmt_one_hex(s, n, p[j]); @@ -318,10 +332,37 @@ _I print_bin(_s s, _I size, _u8 *p, _I len) { j++; len--; } - suffixnum = _LNclr(LINENUM - i, 4); - while (suffixnum) { + i = suffixnum = _LNclr(LINENUM - i, 4); + i = 0; + while (i < suffixnum) { fmt_ext_hex(s, n); - suffixnum--; + i++; + } + + i = 0; + if (len) { + last_i = LINENUM; + if (j > 0 && j < LINENUM + 1) { + for (int t = 0; t < LINENUM - j; t++) + fmt_dot(s, n); + last_i = j; + } + while (j > 0 && last_i--) { + fmt_ascii(s, n, p[j - last_i - 1]); + } + } else { + last_i = LINENUM - suffixnum; + if (j < LINENUM) + last_i -= prefixnum; + if (j + prefixnum < LINENUM) + while(prefixnum--) + fmt_dot(s, n); + while (last_i--) { + fmt_ascii(s, n, p[j - last_i]); + } + } + while (suffixnum--) { + fmt_dot(s, n); } if (len > 0) { fmt_new_line(s, n, (_u32)(_i64)(p + i)); diff --git a/fs/ext2/ext2_fs.cpp b/fs/ext2/ext2_fs.cpp index d848a0a..03e2581 100644 --- a/fs/ext2/ext2_fs.cpp +++ b/fs/ext2/ext2_fs.cpp @@ -16,12 +16,12 @@ void EXT2_FS::printFS() { using namespace std; cout << endl; cout << "文件系统中Inode数量 " << sb->inodes_count << endl; - cout << "文件系统中总块数 " << sb->blocks_count << endl; + cout << "以块为单位的文件系统大小 " << sb->blocks_count << endl; cout << "文件系统中保留块数目 " << sb->r_blocks_count << endl; cout << "文件系统中空闲块数目 " << sb->free_blocks_count << endl; cout << "文件系统中空闲Inode数量 " << sb->free_inodes_count << endl; - cout << "第一个数据块的位置 " << sb->first_data_block << endl; - cout << "块大小 " << 1024 * pow(2, sb->log_block_size) << endl; + cout << "第一个使用的块号 " << sb->first_data_block << endl; + cout << "块大小 " << 1024 * (1 << sb->log_block_size) << endl; cout << "逻辑片大小 " << sb->log_frag_size << endl; cout << "每组块数 " << sb->blocks_per_group << endl; cout << "每组碎片数 " << sb->frags_per_group << endl; @@ -45,6 +45,10 @@ void EXT2_FS::printFS() { } } +int EXT2_FS::block_to_pos(int block) { + return (block - 1) * sb->log_block_size + 1024; +} + void EXT2_FS::mount() { sb = new SuperBlock(); dev->seek(1024); // 跳过引导块 @@ -55,16 +59,24 @@ void EXT2_FS::mount() { _si(sb->log_block_size); _si(sb->blocks_count); _si(sb->blocks_per_group); + + // 1024 * (1 << sb->log_block_size) * 8; dev->seek(1024 * (1 << sb->log_block_size) + 1024); // 指向GDT - int group_cnt = sb->blocks_count / sb->blocks_per_group; + int group_cnt = 8 * sb->blocks_count / sb->blocks_per_group; for (int i = 0; i < group_cnt; i++) { GroupDescriptor* gtp = new GroupDescriptor(); dev->read(sb_buf, sizeof(GroupDescriptor)); - memmove(gtp, sb_buf.data, 1024); + memmove(gtp, sb_buf.data, sizeof(GroupDescriptor)); gdt_list.push_back(gtp); } + + // 数据块位图 + dev->seek(block_to_pos(gdt_list.front()->block_bitmap)); + dev->read(sb_buf, sb->log_block_size); + _sa(sb_buf.data + 5, 5); + printFS(); } diff --git a/fs/ext2/ext2_fs.h b/fs/ext2/ext2_fs.h index 3456f12..9ef6845 100644 --- a/fs/ext2/ext2_fs.h +++ b/fs/ext2/ext2_fs.h @@ -159,8 +159,10 @@ struct DirEntry { class EXT2_FS: VFS::FS { std::list gdt_list; - void printFS(); SuperBlock* sb; + + void printFS(); + int block_to_pos(int block); public: EXT2_FS(Dev::BlockDevice* dev); void mount();