Exemple #1
0
 public static void AddItem(INode inode, String itemName, int itemINodeIndex)
 {
     var dir = new DirectoryBase(inode);
     dir.Load();
     dir.dir[itemName] = itemINodeIndex;
     dir.Save();
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 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();
 }
Exemple #4
0
 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;
 }
Exemple #5
0
 public static List<KeyValuePair<String, int>> ListItems(INode inode)
 {
     var dir = new DirectoryBase(inode);
     dir.Load();
     return dir.List();
 }
Exemple #6
0
 /// <summary>
 /// 将 inode 初始化为一个 Directory
 /// </summary>
 /// <param name="inode"></param>
 public static void Initialize(INode inode)
 {
     var dir = new DirectoryBase(inode);
     dir.Save();
 }
Exemple #7
0
 public static int GetItem(INode inode, String itemName)
 {
     var dir = new DirectoryBase(inode);
     dir.Load();
     return dir.Find(itemName);
 }
Exemple #8
0
 public static int Count(INode inode)
 {
     var dir = new DirectoryBase(inode);
     dir.Load();
     return dir.dir.Count;
 }
Exemple #9
0
 public static Boolean Contains(INode inode, String name)
 {
     var dir = new DirectoryBase(inode);
     dir.Load();
     return dir.Contains(name);
 }
Exemple #10
0
 public DirectoryBase(INode inode)
 {
     this.inode = inode;
     dir = new Dictionary<string,int>();
 }
Exemple #11
0
        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;
            }
        }