/// <summary> /// 创建一个文件夹 /// </summary> /// <param name="name"></param> public void CreateDirectory(String name) { VFS.AssertNameValid(name); INode inode = vfs.AllocateINode(1, 2333); if (!dir.Add(name, new INodeDirectory(vfs, inode))) { throw new Exception("创建文件夹失败"); } }
/// <summary> /// 重命名文件或文件夹 /// </summary> /// <param name="oldName"></param> /// <param name="newName"></param> public void Rename(String oldName, String newName) { VFS.AssertNameValid(oldName); VFS.AssertNameValid(newName); if (!dir.Contains(oldName)) { throw new Exception("文件或文件夹未找到"); } if (dir.Contains(newName)) { throw new Exception("新文件名与现有文件或文件夹名称冲突"); } if (!dir.Rename(oldName, newName)) { 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(); } }