public INodeDirectory(VFSCore vfs, INode inode) { this.vfs = vfs; this.inode = inode; this.entries = new Dictionary<String, UInt32>(); }
/// <summary> /// 根据 inode 建立 INodeDirectory /// </summary> /// <param name="vfs"></param> /// <param name="inode"></param> /// <returns></returns> public static INodeDirectory Load(VFSCore vfs, INode inode) { INodeDirectory t = new INodeDirectory(vfs, inode); t.Load(); return t; }
/// <summary> /// 添加一个文件目录项 /// </summary> /// <param name="name"></param> /// <param name="inodeIndex"></param> /// <returns></returns> public Boolean Add(String name, INode inode) { if (Contains(name)) { return false; } entries[name] = inode.index; inode.data.linkCount++; inode.Save(); Save(); return true; }
/// <summary> /// 通过打开现有文件来初始化该类 /// </summary> /// <param name="dir"></param> /// <param name="name"></param> private void OpenFile(INodeDirectory dir, String name) { inode = INode.Load(vfs, dir.Find(name)); }
/// <summary> /// 通过创建一个新文件来初始化该类 /// </summary> /// <param name="vfs"></param> /// <param name="name"></param> /// <param name="dir"></param> private void CreateFile(INodeDirectory dir, String name) { inode = vfs.AllocateINode(0, 2333); dir.Add(name, inode); }
/// <summary> /// 从存储介质中获取 inode /// </summary> /// <param name="vfs"></param> /// <param name="index"></param> /// <returns></returns> public static INode Load(VFSCore vfs, UInt32 index) { if (index >= vfs.GetSuperBlock().data.inodeCapacity) { throw new Exception("无效 inode 编号"); } INode inode = null; if (inodeInstances.ContainsKey(index)) { inode = inodeInstances[index]; return inode; } else { _INode data = vfs.GetDevice().Read<_INode>(GetPosition(vfs, index)); inode = new INode(vfs, data, index); inodeInstances[index] = inode; } inode.data.accessTime = (UInt64)DateTime.Now.Ticks; inode.Save(); return inode; }
/// <summary> /// 创建一个新的 inode /// </summary> /// <param name="vfs"></param> /// <param name="index"></param> /// <returns></returns> public static INode Create(VFSCore vfs, UInt32 index, UInt32 flags, UInt32 owner) { if (index >= vfs.GetSuperBlock().data.inodeCapacity) { throw new Exception("无效 inode 编号"); } _INode data = new _INode(flags, owner); INode inode = new INode(vfs, data, index); inode.Save(); inodeInstances[index] = inode; return inode; }