diff --git a/fs/ext2/ext2_inode.cpp b/fs/ext2/ext2_inode.cpp index d5361fa..c85905b 100644 --- a/fs/ext2/ext2_inode.cpp +++ b/fs/ext2/ext2_inode.cpp @@ -211,7 +211,7 @@ EXT2_Inode::iterator& EXT2_Inode::iterator::operator++() { if (indexs[level] >= sub_blocks_in_block[level]) { // 小升级! int t = level; - while (t > 0 && indexs[t] >= sub_blocks_in_block[level]) { + while (t > 0 && indexs[t] >= sub_blocks_in_block[t]) { // 重设指针 indexs[t - 1]++; indexs[t] = 0; @@ -228,6 +228,26 @@ EXT2_Inode::iterator& EXT2_Inode::iterator::operator++() { return *this; } +const EXT2_Inode::iterator& EXT2_Inode::iterator::operator--(int) { + return --(*this); +} + +EXT2_Inode::iterator& EXT2_Inode::iterator::operator--() { + if (index_cnt == 0) + return *this; + index_cnt--; + int t = level; + while (t >= 0 && indexs[t] == 0) { + indexs[t] = sub_blocks_in_block[t] - 1; + t--; + } + indexs[t]--; + if (t == 0) + level = indexs[t] < 12? 0: indexs[t] - 11; + load_buf(t); + return *this; +} + bool EXT2_Inode::iterator::operator==(const iterator& ano) const { _error(inode != ano.inode); diff --git a/fs/ext2/ext2_inode.h b/fs/ext2/ext2_inode.h index 56e927b..2a0379a 100644 --- a/fs/ext2/ext2_inode.h +++ b/fs/ext2/ext2_inode.h @@ -44,6 +44,9 @@ namespace EXT2 iterator& operator++(); // a++ const iterator& operator++(int); + iterator& operator--(); + const iterator& operator--(int); + bool operator==(const iterator& ano) const; bool operator!=(const iterator& ano) const; int operator*(); diff --git a/fs/vfs.h b/fs/vfs.h index 1f91d52..6a44ba3 100644 --- a/fs/vfs.h +++ b/fs/vfs.h @@ -63,19 +63,26 @@ namespace VFS virtual void inflate()=0; virtual void load_children()=0; + // 在当前目录项创建文件夹 virtual void mkdir(const std::string& new_name)=0; + // 在当前目录下创建空文件 virtual void create(const std::string& new_name)=0; - virtual void unlink(DEntry*)=0; // 删除子项目,修改自己与子文件夹的引用关系 - virtual void unlink()=0; // 删除自己,释放空间 + // 在当前目录下删除子项目,修改自己与子文件夹的引用关系 + virtual void unlink(DEntry*)=0; + // 删除自己,释放空间,会由ulink(DEntry*)调用 + virtual void unlink()=0; + // 删除一个目录下的所有项目 virtual void unlink_children()=0; - virtual bool empty()=0; // 判断一个目录是否为空 + // 判断一个目录是否为空 + virtual bool empty()=0; // 在另一个目录项中创建自己的硬链接 virtual void link(DEntry *dir, const std::string& s="")=0; - // 自己移动到另一个目录中 + // 把自己移动到另一个目录中 virtual void move(DEntry *dir, const std::string& new_name="")=0; + // 打开文件 + File *open(); File *open(const std::string& name); - File *open(); DEntry* get_child(const std::string& name); DEntry* get_child(const NameI *namei, DEntry **path=nullptr); DEntry *get_path(const NameI *namei, std::string* fname=nullptr);