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("无效路径"); } }
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(); } }