/// <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="vfs"></param> /// <returns></returns> public static INodeDirectory Create(VFSCore vfs) { INode inode = vfs.AllocateINode(1, 2333); INodeDirectory t = new INodeDirectory(vfs, inode); t.AddSelf(); return t; }
/// <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> /// 创建一个新目录 /// </summary> /// <param name="vfs"></param> /// <returns></returns> public static INodeDirectory Create(VFSCore vfs) { INode inode = vfs.AllocateINode(1, 2333); INodeDirectory t = new INodeDirectory(vfs, inode); t.AddSelf(); return(t); }
/// <summary> /// 创建一个全新的 SuperBlock /// </summary> /// <param name="vfs"></param> /// <param name="inodeCapacity"></param> /// <param name="blockSize"></param> /// <param name="blockCapacity"></param> /// <returns></returns> public static SuperBlock Create(VFSCore vfs, UInt32 inodeCapacity, UInt16 blockSize, UInt32 blockCapacity) { var _superBlock = new _SuperBlock(inodeCapacity, blockSize, blockCapacity); var superBlock = new SuperBlock(vfs, _superBlock); superBlock.Save(); return(superBlock); }
public SuperBlock(VFSCore vfs, _SuperBlock data) { this.vfs = vfs; this.data = data; if (data.IsValid()) { init(); } }
public INode(VFSCore vfs, _INode data, UInt32 index = UInt32.MaxValue) { this.vfs = vfs; this.data = data; this.index = index; UInt32 blockSize = vfs.GetSuperBlock().data.blockSize; UInt32 IndexPerBlock = blockSize / sizeof(UInt32); BoundLv0 = 12 * blockSize; BoundLv1 = BoundLv0 + IndexPerBlock * blockSize; }
/// <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); }
public Directory(VFSCore vfs, String path) { this.vfs = vfs; if (!path.EndsWith("/")) { path += "/"; } this.path = path; dir = INodeDirectory.Resolve(vfs, path); if (dir == null) { throw new Exception("无效路径"); } }
/// <summary> /// 根据路径解析目录,路径必须以 / 结尾 /// </summary> /// <param name="path"></param> /// <returns></returns> public static INodeDirectory Resolve(VFSCore vfs, String path) { INodeDirectory root = Load(vfs, 0); var pathCom = path.Split('/'); var node = root; for (var i = 1; i < pathCom.Length - 1; ++i) { if (node.Contains(pathCom[i]) && INode.Load(vfs, node.Find(pathCom[i])).IsDirectory()) { node = Load(vfs, node.Find(pathCom[i])); } else { return(null); } } return(node); }
/// <summary> /// 根据路径解析目录,路径必须以 / 结尾 /// </summary> /// <param name="path"></param> /// <returns></returns> public static INodeDirectory Resolve(VFSCore vfs, String path) { INodeDirectory root = Load(vfs, 0); var pathCom = path.Split('/'); var node = root; for (var i = 1; i < pathCom.Length - 1; ++i) { if (node.Contains(pathCom[i]) && INode.Load(vfs, node.Find(pathCom[i])).IsDirectory()) { node = Load(vfs, node.Find(pathCom[i])); } else { return null; } } return node; }
public VFS(AbstractDevice device) { vfs = new VFSCore(device); }
/// <summary> /// 从存储介质上还原 SuperBlock /// </summary> /// <param name="vfs"></param> /// <returns></returns> public static SuperBlock Load(VFSCore vfs) { var _superBlock = vfs.GetDevice().Read<_SuperBlock>(0); return new SuperBlock(vfs, _superBlock); }
/// <summary> /// 创建一个全新的 SuperBlock /// </summary> /// <param name="vfs"></param> /// <param name="inodeCapacity"></param> /// <param name="blockSize"></param> /// <param name="blockCapacity"></param> /// <returns></returns> public static SuperBlock Create(VFSCore vfs, UInt32 inodeCapacity, UInt16 blockSize, UInt32 blockCapacity) { var _superBlock = new _SuperBlock(inodeCapacity, blockSize, blockCapacity); var superBlock = new SuperBlock(vfs, _superBlock); superBlock.Save(); return superBlock; }
public File(VFSCore vfs, String path, FileMode fileMode) { this.vfs = vfs; var directory = VFS.GetPathDirectory(path); var name = VFS.GetPathName(path); VFS.AssertNameValid(name); INodeDirectory dir = INodeDirectory.Resolve(vfs, directory); if (dir == null) { throw new Exception("无法访问目录"); } switch (fileMode) { case FileMode.CreateNew: if (dir.Contains(name)) { throw new Exception("文件已存在"); } CreateFile(dir, name); break; case FileMode.Create: if (dir.Contains(name)) { OpenFile(dir, name); inode.Resize(0); } else { CreateFile(dir, name); } break; case FileMode.Open: if (!dir.Contains(name)) { throw new Exception("文件未找到"); } OpenFile(dir, name); break; case FileMode.OpenOrCreate: if (dir.Contains(name)) { OpenFile(dir, name); } else { CreateFile(dir, name); } break; case FileMode.Truncate: if (!dir.Contains(name)) { throw new Exception("文件未找到"); } OpenFile(dir, name); inode.Resize(0); break; case FileMode.Append: if (!dir.Contains(name)) { CreateFile(dir, name); } else { OpenFile(dir, name); position = inode.data.sizeByte; } break; default: throw new ArgumentException(); } }
public static UInt32 GetPosition(VFSCore vfs, UInt32 index) { return(vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize <_INode>()); }
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> /// 根据 inode index 建立 INodeDirectory /// </summary> /// <param name="vfs"></param> /// <param name="inodeIndex"></param> /// <returns></returns> public static INodeDirectory Load(VFSCore vfs, UInt32 inodeIndex) { INode inode = INode.Load(vfs, inodeIndex); return Load(vfs, inode); }
/// <summary> /// 从存储介质上还原 SuperBlock /// </summary> /// <param name="vfs"></param> /// <returns></returns> public static SuperBlock Load(VFSCore vfs) { var _superBlock = vfs.GetDevice().Read <_SuperBlock>(0); return(new SuperBlock(vfs, _superBlock)); }
public INodeDirectory(VFSCore vfs, INode inode) { this.vfs = vfs; this.inode = inode; this.entries = new Dictionary<String, UInt32>(); }
public static UInt32 GetPosition(VFSCore vfs, UInt32 index) { return vfs.GetSuperBlock().pInodeData + index * (uint)Utils.GetStructSize<_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; }
/// <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 index 建立 INodeDirectory /// </summary> /// <param name="vfs"></param> /// <param name="inodeIndex"></param> /// <returns></returns> public static INodeDirectory Load(VFSCore vfs, UInt32 inodeIndex) { INode inode = INode.Load(vfs, inodeIndex); return(Load(vfs, inode)); }