public static void AddItem(INode inode, String itemName, int itemINodeIndex) { var dir = new DirectoryBase(inode); dir.Load(); dir.dir[itemName] = itemINodeIndex; dir.Save(); }
public static INode AllocateNewINode(System.IO.FileAttributes attribute) { var index = GetFreeInodeIndex(); if (index != -1) { iNodes[index] = new INode(index, attribute); return iNodes[index]; } return null; }
public static void DeleteItem(INode inode, String itemName) { var dir = new DirectoryBase(inode); dir.Load(); if (!dir.Contains(itemName)) { throw new System.IO.FileNotFoundException(); } dir.dir.Remove(itemName); dir.Save(); }
public static void RenameItem(INode inode, String itemOldName, String itemNewName) { var dir = new DirectoryBase(inode); dir.Load(); if (!dir.Contains(itemOldName)) { throw new System.IO.FileNotFoundException(); } if (dir.Contains(itemNewName)) { throw new System.IO.IOException(); } var inodeIndex = dir.dir[itemOldName]; dir.dir.Remove(itemOldName); dir.dir[itemNewName] = inodeIndex; }
public static List<KeyValuePair<String, int>> ListItems(INode inode) { var dir = new DirectoryBase(inode); dir.Load(); return dir.List(); }
/// <summary> /// 将 inode 初始化为一个 Directory /// </summary> /// <param name="inode"></param> public static void Initialize(INode inode) { var dir = new DirectoryBase(inode); dir.Save(); }
public static int GetItem(INode inode, String itemName) { var dir = new DirectoryBase(inode); dir.Load(); return dir.Find(itemName); }
public static int Count(INode inode) { var dir = new DirectoryBase(inode); dir.Load(); return dir.dir.Count; }
public static Boolean Contains(INode inode, String name) { var dir = new DirectoryBase(inode); dir.Load(); return dir.Contains(name); }
public DirectoryBase(INode inode) { this.inode = inode; dir = new Dictionary<string,int>(); }
public File(string path, System.IO.FileMode fileMode) { this.path = path; var dir = new Directory(Util.GetPathDirectory(path)); var name = Util.GetPathFileName(path); switch (fileMode) { case System.IO.FileMode.Append: // 不支持 throw new NotImplementedException(); break; case System.IO.FileMode.Create: if (dir.Contains(name)) { this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)]; this.inode.SetEndOfFile(0); } else { this.inode = Disk.AllocateNewINode(System.IO.FileAttributes.Normal); dir.AddItem(name, inode.index); } break; case System.IO.FileMode.CreateNew: //Console.WriteLine("*** CreateNew {0}", name); if (dir.Contains(name)) { throw new System.IO.IOException(); } this.inode = Disk.AllocateNewINode(System.IO.FileAttributes.Normal); dir.AddItem(name, inode.index); break; case System.IO.FileMode.Open: //Console.WriteLine("*** Open {0}", name); if (!dir.Contains(name)) { throw new System.IO.FileNotFoundException(); } this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)]; break; case System.IO.FileMode.OpenOrCreate: if (!dir.Contains(name)) { this.inode = Disk.AllocateNewINode(System.IO.FileAttributes.Normal); dir.AddItem(name, inode.index); } else { this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)]; } break; case System.IO.FileMode.Truncate: if (!dir.Contains(name)) { throw new System.IO.FileNotFoundException(); } this.inode = Disk.iNodes[dir.GetItemINodeIndex(name)]; this.inode.SetEndOfFile(0); break; } }