/// <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 void AddOpenFile(IntPtr fileHandle, OpenFileInfo openFileInfo) { lock (_openFiles) { _openFiles[fileHandle] = openFileInfo; Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format("Open file {0}:{1} added to filesys context.", fileHandle, openFileInfo.VirtualPath)); } }
/// <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); }
/// <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; }
/// <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; }
public bool TryGetOpenFileInfo(IntPtr fileHandle, out OpenFileInfo openFileInfo) { lock (_openFiles) { return(_openFiles.TryGetValue(fileHandle, out openFileInfo)); } }
public bool TryGetOpenFileInfo(IntPtr fileHandle, out OpenFileInfo openFileInfo) { lock (_openFiles) { return _openFiles.TryGetValue(fileHandle, out openFileInfo); } }