diff --git a/dev/mock_disk.cpp b/dev/mock_disk.cpp index 237de9c..f1c9170 100644 --- a/dev/mock_disk.cpp +++ b/dev/mock_disk.cpp @@ -1,6 +1,7 @@ #include "mock_disk.h" #include #include +#include "delog/delog.h" using namespace Dev; @@ -24,6 +25,7 @@ _u32 MockDisk::tell() { } void MockDisk::seek(_u32 pos) { + _si(pos); fseek(f, pos, SEEK_SET); } diff --git a/fs/ext2/ext2_fs.cpp b/fs/ext2/ext2_fs.cpp index 03e2581..e147b9b 100644 --- a/fs/ext2/ext2_fs.cpp +++ b/fs/ext2/ext2_fs.cpp @@ -21,7 +21,7 @@ void EXT2_FS::printFS() { cout << "文件系统中空闲块数目 " << sb->free_blocks_count << endl; cout << "文件系统中空闲Inode数量 " << sb->free_inodes_count << endl; cout << "第一个使用的块号 " << sb->first_data_block << endl; - cout << "块大小 " << 1024 * (1 << sb->log_block_size) << endl; + cout << "块大小 " << block_size << endl; cout << "逻辑片大小 " << sb->log_frag_size << endl; cout << "每组块数 " << sb->blocks_per_group << endl; cout << "每组碎片数 " << sb->frags_per_group << endl; @@ -45,8 +45,33 @@ void EXT2_FS::printFS() { } } +void EXT2_FS::printInode(Inode* i) { + using namespace std; + cout << "\nInode:" << endl; + cout << "文件类型和访问权限 " << i->mode << endl; + cout << "拥有者 " << i->uid << endl; + cout << "文件长度 " << i->size << endl; + cout << "最后一次访问时间 " << i->atime << endl; + cout << "索引节点最后改变的时间 " << i->ctime << endl; + cout << "文件内容最后改变的时间 " << i->mtime << endl; + cout << "文件删除的时间 " << i->dtime << endl; + cout << "组id " << i->gid << endl; + cout << "硬链接计数器 " << i->links_count << endl; + cout << "文件的数据块数 " << i->blocks << endl; + cout << "文件标志 " << i->flags << endl; + cout << "文件版本 " << i->generation << endl; + cout << "文件访问控制列表 " << i->file_acl << endl; + cout << "目录访问控制列表 " << i->dir_acl << endl; + cout << "片地址 " << i->faddr << endl; + cout << "数据块指针 "; + for (int j = 0; j < i->blocks;j++) + cout << i->block[j] << " "; + cout << endl; +} + int EXT2_FS::block_to_pos(int block) { - return (block - 1) * sb->log_block_size + 1024; + _si(block); + return (block - 1) * block_size + 1024; } void EXT2_FS::mount() { @@ -61,8 +86,8 @@ void EXT2_FS::mount() { _si(sb->blocks_per_group); // 1024 * (1 << sb->log_block_size) * 8; - - dev->seek(1024 * (1 << sb->log_block_size) + 1024); // 指向GDT + block_size = 1024 * (1 << sb->log_block_size); + dev->seek(block_size + 1024); // 指向GDT int group_cnt = 8 * sb->blocks_count / sb->blocks_per_group; for (int i = 0; i < group_cnt; i++) { @@ -73,11 +98,19 @@ void EXT2_FS::mount() { } // 数据块位图 - dev->seek(block_to_pos(gdt_list.front()->block_bitmap)); - dev->read(sb_buf, sb->log_block_size); - _sa(sb_buf.data + 5, 5); - + dev->seek(block_to_pos(gdt_list.front()->inode_bitmap)); + dev->read(sb_buf, block_size); + _sa(sb_buf.data, 1024); + + // 第一个索引节点 / + dev->seek(block_to_pos(gdt_list.front()->inode_table)); + dev->read(sb_buf, sizeof(Inode)); + dev->read(sb_buf, sizeof(Inode)); + Inode* root_inode = new Inode(); + memmove(root_inode, sb_buf.data, sizeof(Inode)); + // _sa(sb_buf.data, 1024); printFS(); + printInode(root_inode); } EXT2_FS::~EXT2_FS() { @@ -85,4 +118,23 @@ EXT2_FS::~EXT2_FS() { delete x; } delete sb; +} + +EXT2_Inode::EXT2_Inode(EXT2_FS *fs, EXT2::Inode *i): VFS::Inode(fs) { + ino = 0; + counter = 0; + mode = i->mode; + nlink = i->links_count; + uid = i->uid; + gid = i->gid; + dev = fs->dev; + size = i->size; + atime = i->atime; + mtime = i->mtime; + ctime = i->ctime; + blkbits = 0; + version = i->generation; + blocks = i->blocks; + bytes = 0; + sock = 1; } \ No newline at end of file diff --git a/fs/ext2/ext2_fs.h b/fs/ext2/ext2_fs.h index 9ef6845..168599a 100644 --- a/fs/ext2/ext2_fs.h +++ b/fs/ext2/ext2_fs.h @@ -157,15 +157,23 @@ struct DirEntry { _u8 name[NAME_LEN]; // 文件名 }; -class EXT2_FS: VFS::FS { +class EXT2_FS: public VFS::FS { std::list gdt_list; SuperBlock* sb; + _u32 block_size; void printFS(); + void printInode(Inode*); int block_to_pos(int block); public: EXT2_FS(Dev::BlockDevice* dev); void mount(); ~EXT2_FS(); }; + +class EXT2_Inode: public VFS::Inode { +public: + EXT2_Inode(EXT2_FS*, EXT2::Inode*); +}; + } diff --git a/fs/vfs.h b/fs/vfs.h index a59286c..e166cb8 100644 --- a/fs/vfs.h +++ b/fs/vfs.h @@ -9,13 +9,19 @@ namespace VFS { - class File; + class Inode; + class FS; - class Directory { + /** + * 一个目录项 + */ + class DEntry { public: - std::list files; - std::list directorys; - + FS* fs; + Inode* inode; + DEntry* parent; + + std::string name; }; @@ -25,14 +31,15 @@ namespace VFS _u32 flag; // 安装标志 _u32 magic; // 文件系统标志 - Directory* root = nullptr; // 根目录 + DEntry* root = nullptr; // 根目录 _i32 count; // 引用计数器 void** xattr; // 指向扩展属性的指针 FS(Dev::BlockDevice* dev): dev(dev) {} }; - class File { + class Inode { + public: _u32 ino; // 索引节点号 _i32 counter; // 引用计数器 _u16 mode; // 文件类型与访问权限 @@ -53,9 +60,9 @@ namespace VFS FS* fs; public: - File(FS* fs1):fs(fs1), dev(fs1->dev) {} + Inode(FS* fs1):fs(fs1), dev(fs1->dev) {} - void create(Directory*, int mode); // 为与目录项相关联的普通文件创建一个索引节点 + void create(DEntry*, int mode); // 为与目录项相关联的普通文件创建一个索引节点 }; diff --git a/makefile b/makefile index 5817247..9723d8a 100644 --- a/makefile +++ b/makefile @@ -39,6 +39,13 @@ include .depend $(OBJ_PATH)/%.o: g++ -c $< $(CC_FLAG) -o $@ +# $(BIN_PATH)/%.out: +# TEST_NAME = $(notdir $@) +# TEST_FILE = $(patsubst %.out, %.cpp, $(TEST_NAME)) +# TEST_FILE = $(shell find . -name $(TEST_FILE).cpp) + + + rebuild: clean build clean: