/// <summary> /// Opens the handle. /// </summary> /// <param name="path">The path.</param> /// <param name="info">The info.</param> public override Errno OpenHandle(string path, OpenedPathInfo info) { Errno retVal; if (info.OpenAccess == OpenFlags.O_RDONLY) { String readPath = _pathFactory.CreateVirtualPath4Read(new VirtualRawPath(path)); retVal = base.OpenHandle(readPath, info); } else { // This is a write. // @TODO Write to an existing file is not supported by BitTorrent. // It has to be enforced somewhere. String writePath = _pathFactory.CreateVirtualPath4Write(new VirtualRawPath(path)); retVal = base.OpenHandle(writePath, info); } // Add to filesys context. VirtualPath vp = VirtualPath.CreateFromRawString(path); VirtualFile vf = _fileManager.ReadVirtualFile(vp); FileAccess fa = IOUtil.OpenFlags2FileAccess(info.OpenAccess); var openFileInfo = new OpenFileInfo(info.Handle, vp, vf, fa); _filesysContext.AddOpenFile(info.Handle, openFileInfo); return(retVal); }
public override Errno ReleaseHandle(string path, OpenedPathInfo info) { _filesysContext.RemoveOpenFile(info.Handle); VirtualPath vp = VirtualPath.CreateFromRawString(path); UpdateFileSizeInVirtualFile(vp); return(base.ReleaseHandle(path, info)); }
/// <summary> /// Gets the handle status. This method gets the status of the virtual file /// and replaces the size with that of the real data file. /// </summary> public override Errno GetHandleStatus(string path, OpenedPathInfo info, out Stat buf) { Errno ret; ret = base.GetHandleStatus(path, info, out buf); if ((buf.st_mode & FilePermissions.S_IFREG) != 0) { // Make a change to file size if is a file (S_IFREG) buf.st_size = _fileManager.GetFileLength( VirtualPath.CreateFromRawString(path)); } return(ret); }
/// <summary> /// Creates the handle. /// </summary> /// <param name="path">The path.</param> /// <param name="info">The info.</param> /// <param name="mode">The mode.</param> /// <returns></returns> /// <remarks>This method is for FilesysOp.Write.</remarks> public override Errno CreateHandle(string path, OpenedPathInfo info, FilePermissions mode) { // Create the handle for the write. String writePath = _pathFactory.CreateVirtualPath4Write(new VirtualRawPath(path)); Errno retVal = base.CreateHandle(writePath, info, mode); // Create the VF so the reads afterwards knows about the file. VirtualPath vp = VirtualPath.CreateFromRawString(path); VirtualFile vf = CreateAndWriteVirtualFile(vp); var ofi = new OpenFileInfo(info.Handle, vp, vf, FileAccess.Write); _filesysContext.AddOpenFile(info.Handle, ofi); return(retVal); }