private void remove(ref CompoundCmd cmd, string name, int parent) { inode _node = MemoryInterface.getInstance().getInodeByIndex(parent); cmd.newOpe(new EditCmd(parent)); int id = MemoryInterface.getInstance().getDataBlockByIndex(_node.getBlock(0)).removeInode(name); //找到删除文件的inode _node = MemoryInterface.getInstance().getInodeByIndex(id); cmd.newOpe(new DeleteCmd(id)); if (_node.getType().Equals("文件夹")) { for (int i = 0; ; i++) //释放inodetable中信息 { string _name = MemoryInterface.getInstance().getDataBlockByIndex(_node.getBlock(0)).findInode(2); if (_name != null) { remove(ref cmd, _name, id); } else { break; } } } List <int> b = _node.getBlockPtr().ToList <int>(); //获得该节点占用的全部块 MemoryInterface.getInstance().releaseBlock(b); //释放块位图 MemoryInterface.getInstance().releaseInode(id); //释放节点位图 }
public override void removeEntry(int selectedItem, string name) { entries.RemoveAt(selectedItem); CompoundCmd cmd = new CompoundCmd(); remove(ref cmd, name, node); UndoManager.getInstance().newOpe(cmd); MemoryInterface.getInstance().write(); }
public override string createEntry(string _name, string type) { int parent = -1; UndoableCmd cmd1 = new EditCmd(node); if (_name != null) //点击文件夹创建 { parent = MemoryInterface.getInstance().getInodeIndexByName(node, _name); //选中文件夹为父目录 } else //直接新建 { parent = node; //当前目录为父目录 } List <int> nodeLoc = MemoryInterface.getInstance().getRequireInodes(1); //找到未使用的inode节点 List <int> blockLoc = MemoryInterface.getInstance().getRequireBlocks(1); //找到空闲磁盘块 if (nodeLoc == null || blockLoc == null) //inodeMap或blockMap用尽 { return(null); } string name = null; if (type.Equals("文件夹")) { name = initDir(blockLoc, parent, nodeLoc[0]); entries.Add(new Directory(nodeLoc[0], name)); } else { name = "新建文件"; name = MemoryInterface.getInstance().addNewInodeTableItem(MemoryInterface.getInstance().getInodeByIndex(parent).getBlock(0), name, nodeLoc[0]); inode temp = MemoryInterface.getInstance().getInodeByIndex(nodeLoc[0]); temp.init(nodeLoc[0], blockLoc, "文件", DateTime.Now); entries.Add(new File(temp, name)); } UndoableCmd cmd2 = new AddCmd(nodeLoc[0]); CompoundCmd cmd3 = new CompoundCmd(); cmd3.newOpe(cmd1); cmd3.newOpe(cmd2); UndoManager.getInstance().newOpe(cmd3); MemoryInterface.getInstance().write(); return(name); }