public NtStatus CreateDirectory(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (mode == FileMode.CreateNew) { if (Provider.Exist(fileName)) { return(DokanResult.AlreadyExists); } FSNode n = Provider.CreateDir(fileName).Result; if (n == null) { return(DokanResult.PathNotFound); } info.Context = new object(); return(DokanResult.Success); } FSNode node = Provider.FetchItem(fileName).Result; if (node == null) { return(DokanResult.PathNotFound); } if (!node.IsDirectory) { return(DokanResult.NotADirectory); } info.Context = new object(); return(DokanResult.Success); }
public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { try { fileName = FilterPath(fileName); bool isDirectory = Fs.DirectoryExists(fileName); if (info.IsDirectory || isDirectory) { info.IsDirectory = true; if (Fs.FileExists(fileName)) { return(DokanResult.NotADirectory); } else if (Fs.DirectoryExists(fileName)) { return(DokanResult.Success); } Fs.CreateDirectory(fileName); } else { bool exists = Fs.FileExists(fileName); if (mode == FileMode.Open && exists) { return(DokanResult.Success); } switch (mode) { case FileMode.Create: case FileMode.OpenOrCreate: case FileMode.CreateNew: if (exists) { return(DokanResult.AlreadyExists); } lock (IOLock) Fs.CreateFile(fileName, 0, CreateFileOptions.None); if (Fs.FileExists(fileName)) { return(NtStatus.Success); } break; } if (!exists) { return(DokanResult.FileNotFound); } } return(NtStatus.Success); } catch (NotImplementedException) { return(NtStatus.NotImplemented); } }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (mode != FileMode.Open && mode != FileMode.OpenOrCreate) { return(NtStatus.AccessDenied); } if (info.Context == null) { var node = this.GetNode(fileName); if (node == null) { if (mode == FileMode.OpenOrCreate) { return(NtStatus.AccessDenied); } return(NtStatus.ObjectPathNotFound); } info.IsDirectory = node.IsDirectory; info.Context = node; } return(NtStatus.Success); }
// Create file does nothing except validate that the file requested is okay to create. // Actual creation of a corresponding blob in cloud storage is done when the file is actually written. public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (info.IsDirectory) { return(CreateDirectory(fileName, info)); } // When trying to open a file for reading, succeed only if the file already exists. if (mode == FileMode.Open && (access == FileAccess.GenericRead || access == FileAccess.GenericWrite)) { FileInformation fileInfo; if (GetFileInformation(fileName, out fileInfo, info) == 0) { return(0); } else { return(DokanResult.FileNotFound); } } // When creating a file, always succeed. (Empty directories will be implicitly created as needed.) else if (mode == FileMode.Create || mode == FileMode.OpenOrCreate) { // Since we're creating a file, we don't need to track the parents (up the tree) as empty directories any longer. RemoveEmptyDirectories(Path.GetDirectoryName(fileName)); return(0); } else { throw new NotImplementedException(); } }
public override NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (IsBadName(fileName)) { return(NtStatus.ObjectNameInvalid); } if ((access & ModificationAttributes) != 0) { return(NtStatus.DiskFull); } var item = GetFile(fileName); if (item == null) { return(DokanResult.FileNotFound); } if (item.Info.FileName != null && !item.Info.IsDirectory) { if ((access & DokanNet.FileAccess.ReadData) != 0) { Console.WriteLine("ReadData: " + fileName); info.Context = cache.OpenStream(item, (long)item.Info.Size); } return(NtStatus.Success); } else { info.IsDirectory = true; return(NtStatus.Success); } }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { var entry = layerService.GetEntry(fileName); if (info.IsDirectory) { } else { if (entry.IsDirectory) { return(DokanResult.Success); } IFileHandle handle; var result = entry.Open(access, share, mode, options, attributes, out handle); if (result == DokanResult.Success) { info.Context = handle; } return(result); } return(DokanResult.Success); }
private NtStatus MainOpenFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { bool readAccess = (access & DataReadAccess) != 0; bool writeAccess = (access & DataWriteAccess) != 0; if (writeAccess && ReadOnly) { return(DokanResult.AccessDenied); } var ioaccess = System.IO.FileAccess.Read; if (!readAccess && writeAccess) { ioaccess = System.IO.FileAccess.Write; } if (readAccess && writeAccess) { ioaccess = System.IO.FileAccess.ReadWrite; } var result = provider.OpenFile(fileName, mode, ioaccess, share, options); if (result == null) { return(DokanResult.AccessDenied); } info.Context = result; return(DokanResult.Success); }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { try { var res = MainCreateFile(fileName, access, share, mode, options, attributes, info); #if TRACE bool readWriteAttributes = (access & DataAccess) == 0; if (!(readWriteAttributes || info.IsDirectory) || (res != DokanResult.Success && !(lastFilePath == fileName && res == DokanResult.FileNotFound))) { if (!(info.Context is NewFileBlockWriter || info.Context is FileBlockReader || info.Context is SmallFileBlockReaderWriter || info.Context is BufferedAmazonBlockReader)) { Log.Trace($"{fileName}\r\n Access:[{access}]\r\n Share:[{share}]\r\n Mode:[{mode}]\r\n Options:[{options}]\r\n Attr:[{attributes}]\r\nStatus:{res}"); } lastFilePath = fileName; } #endif return(res); } catch (Exception e) { Log.Error($"{fileName}\r\n Access:[{access}]\r\n Share:[{share}]\r\n Mode:[{mode}]\r\n Options:[{options}]\r\n Attr:[{attributes}]\r\n\r\n{e}"); return(DokanResult.Error); } }
public NtStatus Open(FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, out IFileHandle handle) { var readAccess = (access & DataWriteAccess) == 0; if (!Writable && !readAccess) { handle = null; return(DokanResult.AccessDenied); } if (Writable) { handle = new FileStreamFileHandle(this, RealPath, readAccess? System.IO.FileAccess.Read:System.IO.FileAccess.Write, share, mode, options); return(DokanResult.Success); } else { if (mode == FileMode.OpenOrCreate && !IsExists || mode != FileMode.Open) { handle = null; return(DokanResult.AccessDenied); } handle = new FileStreamFileHandle(this, RealPath, System.IO.FileAccess.Read, share, mode, options); return(DokanResult.Success); } }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { NtStatus success; return(Trace("CreateFile" + (info.IsDirectory ? " Dir" : " File"), fileName, success = client.CreateFile(fileName, mode, info.IsDirectory), success == NtStatus.Success ? ConsoleColor.Green : ConsoleColor.Yellow)); }
NtStatus IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (info.IsDirectory) { if (mode == FileMode.Open) { return(OpenDirectory(fileName, info)); } if (mode == FileMode.CreateNew) { return(CreateDirectory(fileName, info)); } return(NtStatus.NotImplemented); } if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) { return(NtStatus.NoSuchFile); } SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenFile", fileName, drive, "Mode:{0}", mode); if (drive != null) { LogFSActionSuccess("OpenFile", fileName, drive, "Mode:{0} NonVFS", mode); IDokanOperations idops = GetSubSystemOperations(drive); return(idops?.CreateFile(fileName, access, share, mode, options, attributes, info) ?? NtStatus.AccessDenied); //AccessDenied happens if mounting failed } //check against mountpoints if virtual dir exists string path = fileName.Substring(1); if (path == "") { //info.IsDirectory = true; info.Context = null; LogFSActionSuccess("OpenFile", fileName, null, "VFS root"); return(NtStatus.Success); } foreach (var drive2 in this._subsytems.Where(drive2 => drive2.MountPoint.Length > 0) .Where(drive2 => drive2.MountPoint.IndexOf(path) == 0)) { info.IsDirectory = true; info.Context = drive2; LogFSActionSuccess("OpenFile", fileName, drive2, "VFS (sub)mountpoint"); return(NtStatus.Success); } //pathnotfound detection? LogFSActionError("OpenFile", fileName, null, "File not found"); return(NtStatus.NoSuchFile); }
public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (fileName == @"\" || mode == FileMode.Open) { return(DokanResult.Success); } return(DokanResult.DiskFull); }
public virtual NtStatus CreateDirectory(string fileName, FileAccess access, FileShare share, FileOptions options, FileAttributes attributes, DokanFileInfo info) { F file = NewFile(true); info.Context = file; return(file.Create(fileName, access, share, false, options, attributes, info)); }
public virtual NtStatus OpenFile(string fileName, FileAccess access, FileShare share, bool create, bool append, FileOptions options, FileAttributes attributes, DokanFileInfo info) { F file = NewFile(false); info.Context = file; return(file.Open(fileName, access, share, create, append, options, attributes, info)); }
public virtual NtStatus TruncateFile(string fileName, FileAccess access, FileShare share, FileOptions options, FileAttributes attributes, DokanFileInfo info) { F file = NewFile(false); info.Context = file; return(file.Truncate(fileName, access, share, options, attributes, info)); }
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { #if TRACE logger.Debug(($"{method}('{fileName}', {info}, [{access}], [{share}], [{mode}], [{options}], [{attributes}]) -> {result}")); #endif return(result); }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (fileName.Equals(@"\carftCodeCrew.txt")) { info.Context = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(FileContent)); } return(DokanResult.Success); }
DokanError IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) //.... { return(DokanError.ErrorFileNotFound); } SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenFile", fileName, drive, "Mode:{0}", mode); if (drive != null) { LogFSActionSuccess("OpenFile", fileName, drive, "Mode:{0} NonVFS", mode); IDokanOperations idops = GetSubSystemOperations(drive); if (idops == null) { //this happens if mounting failed return(DokanError.ErrorAccessDenied); } return(idops.CreateFile(fileName, access, share, mode, options, attributes, info)); } //check against mountpoints if virtual dir exists string path = fileName.Substring(1); if (path == "") { info.IsDirectory = true; info.Context = null; LogFSActionSuccess("OpenFile", fileName, null, "VFS root"); return(DokanError.ErrorSuccess); } foreach (SftpDrive drive2 in this._subsytems) { if (drive2.MountPoint.Length > 0) { if (drive2.MountPoint.IndexOf(path) == 0) { info.IsDirectory = true; info.Context = drive2; LogFSActionSuccess("OpenFile", fileName, drive2, "VFS (sub)mountpoint"); return(DokanError.ErrorSuccess); } } } //pathnotfound detection? LogFSActionError("OpenFile", fileName, null, "File not found"); return(DokanError.ErrorFileNotFound); }
public override NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (IsBadName(fileName)) { return(NtStatus.ObjectNameInvalid); } if ((access & ModificationAttributes) != 0) { return(NtStatus.DiskFull); } var item = GetFile(fileName); if (item == null) { return(DokanResult.FileNotFound); } if (item.Info.Key != null && !item.Info.IsDirectory) { if ((access & (DokanNet.FileAccess.ReadData | DokanNet.FileAccess.GenericRead)) != 0) { LastAccessed = DateTime.Now; Console.WriteLine("SharpCompressFs ReadData: " + fileName); lock (this) { var entry = extractor.Entries.First(a => a.Key.EndsWith(fileName)); if (((SharpCompress.Common.Rar.Headers.FileHeader)entry.RarParts.First().FileHeader).IsStored) { // stored info.Context = new RarStoreStream(entry); } else { // 5mb if (entry.CompressedSize <= 1024 * 1024 * 5) { info.Context = new MemoryStream(); entry.OpenEntryStream().CopyTo((MemoryStream)info.Context); return(NtStatus.Success); } //info.Context = new MemoryStream(entry.OpenEntryStream()); return(NtStatus.AccessDenied); } } } return(NtStatus.Success); } else { info.IsDirectory = true; return(NtStatus.Success); } }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { bool pathExists = this.isoReader.Exists(fileName); bool pathIsDirectory = this.isoReader.DirectoryExists(fileName); bool readWriteAttributes = (access & DataAccess) == 0; bool readAccess = (access & DataWriteAccess) == 0; switch (mode) { case FileMode.Append: case FileMode.OpenOrCreate: case FileMode.Open: if (pathExists) { if (pathIsDirectory) { info.IsDirectory = true; info.Context = new object(); } else { info.IsDirectory = false; info.Context = this.isoReader.OpenFile(fileName, mode, System.IO.FileAccess.Read) as Stream; } } else { return(DokanResult.FileNotFound); } break; case FileMode.Truncate: if (!pathExists) { return(DokanResult.FileNotFound); } return(DokanResult.Error); case FileMode.CreateNew: if (pathExists) { return(DokanResult.AlreadyExists); } return(DokanResult.Error); case FileMode.Create: return(DokanResult.Error); } return(DokanResult.Success); }
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { #if TRACE Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}('{1}', {2}, [{3}], [{4}], [{5}], [{6}], [{7}]) -> {8}", method, fileName, ToTrace(info), access, share, mode, options, attributes, result)); #endif return result; }
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { #if TRACE Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} {1}('{2}', {3}, [{4}], [{5}], [{6}], [{7}], [{8}]) -> {9}", traceLineId++, method, fileName, ToTrace(info), access, share, mode, options, attributes, result)); #endif return(result); }
public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (/*mode == FileMode.Open && */ Find(fileName) != null) { return(NtStatus.Success); } else { return(NtStatus.Error); } }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { var r = Storage.Create(fileName, !info.IsDirectory, FileAccessConverter.Get(access), share, mode, options, attributes, out var node); info.Context = node; if (node != null) { info.IsDirectory = !node.IsFile(); } return(r.GetNtStatus()); }
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { #if TRACE logger.Debug(string.Format(CultureInfo.InvariantCulture, "{0}('{1}', {2}, [{3}], [{4}], [{5}], [{6}], [{7}]) -> {8}", method, fileName, ToTrace(info), access, share, mode, options, attributes, result)); #endif return(result); }
public NtStatus CreateFile(string filename, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { NtStatus ret = NtStatus.Success; if (filename.EndsWith(":SSHFSProperty.Cache")) { System.Diagnostics.Debug.WriteLine("SSHFS.Cache: " + filename); filename = filename.Remove(filename.IndexOf(":SSHFSProperty.Cache")); CacheEntry entry = cache_.Lookup(filename); entry.RemoveAllCache(); return(NtStatus.Success); } if (mode == FileMode.Open || mode == FileMode.OpenOrCreate) { CacheEntry entry = cache_.Lookup(filename); if (mode == FileMode.OpenOrCreate) { if (entry.Parrent != null) { entry.Parrent.RemoveFindFilesCache(); } } if (entry.CreateFileRet == NtStatus.MaximumNtStatus) { ret = ope_.CreateFile(filename, access, share, mode, options, attributes, info); entry.CreateFileRet = ret; } else { ret = entry.CreateFileRet; } } else { ret = ope_.CreateFile(filename, access, share, mode, options, attributes, info); if (mode == FileMode.Create || mode == FileMode.CreateNew) { CacheEntry entry = cache_.Lookup(filename); if (entry.Parrent != null) { entry.Parrent.RemoveFindFilesCache(); } } } return(ret); }
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { #if TRACE logger.Debug( DokanFormat( $"{method}('{fileName}', {info}, [{access}], [{share}], [{mode}], [{options}], [{attributes}]) -> {result}")); #endif return result; }
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { if (_doLogging) { EventLog.WriteEntry(logSource, DokanFormat( $"{method}('{fileName}', {info}, [{access}], [{share}], [{mode}], [{options}], [{attributes}]) -> {result}")); } return(result); }
public NtStatus CreateFile( string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (info.IsDirectory && mode == FileMode.CreateNew) return DokanResult.AccessDenied; return DokanResult.Success; }
public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (mode != FileMode.Open) { return(NtStatus.AccessDenied); } if (!this.method_9(fileName)) { return(NtStatus.ObjectNameNotFound); } info.IsDirectory = Path.GetExtension(fileName) == ""; info.Context = new object(); return(NtStatus.Success); }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (info.IsDirectory) { return(Backend.CreateFolder(fileName, access, share, mode, options, attributes, info)); } else { var status = Backend.CreateFile(fileName, access, share, mode, options, attributes, out var context, out var isDirectory); info.Context = context; info.IsDirectory = isDirectory; return(status); } }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { _log.Debug("MainFS CreateFile " + fileName); if (mode == FileMode.Open) { _log.Debug("MainFS CreateFile " + fileName + " GetFileInformation"); FileInformation fileInfo; var res = GetFileInformation(fileName, out fileInfo, info); _log.Debug("MainFS CreateFile " + fileName + " ok"); return(res); } _log.Debug("MainFS CreateFile " + fileName + " mode not open"); return(DokanResult.Error); }
public NtStatus CreateFile( string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info) { if (info.IsDirectory && mode == FileMode.CreateNew) { return(DokanResult.AccessDenied); } return(DokanResult.Success); }
public DokanResult CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { Console.WriteLine("CreateFile Running..."+fileName); var path = GetPath(fileName); // Console.WriteLine("N"+fileName); // Console.WriteLine("G"+GetPath(fileName)); // Console.WriteLine("A"+AutoGetPath(fileName)); var pathExists = true; var pathIsDirectory = false; var readWriteAttributes = (access & DataAccess) == 0; var readAccess = (access & DataWriteAccess) == 0; try { pathIsDirectory = File.GetAttributes(path).HasFlag(FileAttributes.Directory); } catch (IOException) { pathExists = false; } switch (mode) { case FileMode.Open: if (pathExists) { if (readWriteAttributes || pathIsDirectory) //check if only wants to read attributes,security info or open directory { info.IsDirectory = pathIsDirectory; info.Context = new object(); // Must set it to someting if you return DokanError.Success return DokanResult.Success; } } else { return DokanResult.FileNotFound; } break; case FileMode.CreateNew: if (pathExists) return DokanResult.AlreadyExists; break; case FileMode.Truncate: if (!pathExists) return DokanResult.FileNotFound; break; default: break; } try { info.Context = new FileStream(path, mode, readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite, share, 4096, options); } catch (UnauthorizedAccessException) // Don't have access rights { return DokanResult.AccessDenied; } return DokanResult.Success; }
public abstract DokanError CreateFile(string fileName, FileAccess access, System.IO.FileShare share, System.IO.FileMode mode, System.IO.FileOptions options, System.IO.FileAttributes attributes, DokanFileInfo info);
private NtStatus Trace(string method, string fileName, DokanFileInfo info, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, NtStatus result) { logger?.Trace($"{System.Threading.Thread.CurrentThread.ManagedThreadId:D2} / {method}({fileName}, {ToTrace(info)}, [{access}], [{share}], [{mode}], [{options}], [{attributes}]) -> {result}"); return result; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { bool pathExists = this.isoReader.Exists(fileName); bool pathIsDirectory = this.isoReader.DirectoryExists(fileName); bool readWriteAttributes = (access & DataAccess) == 0; bool readAccess = (access & DataWriteAccess) == 0; switch(mode) { case FileMode.Append: case FileMode.OpenOrCreate: case FileMode.Open: if (pathExists) { if (pathIsDirectory) { info.IsDirectory = true; info.Context = new object(); } else { info.IsDirectory = false; info.Context = this.isoReader.OpenFile(fileName, mode, System.IO.FileAccess.Read) as Stream; } } else { return DokanResult.FileNotFound; } break; case FileMode.Truncate: if (!pathExists) return DokanResult.FileNotFound; return DokanResult.Error; case FileMode.CreateNew: if (pathExists) return DokanResult.AlreadyExists; return DokanResult.Error; case FileMode.Create: return DokanResult.Error; } return DokanResult.Success; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { // HACK: Fix for Bug in Dokany related to a missing trailing slash for directory names if (string.IsNullOrEmpty(fileName)) fileName = @"\"; if (fileName == @"\") { info.IsDirectory = true; return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.Success); } fileName = fileName.TrimEnd(Path.DirectorySeparatorChar); var parent = GetItem(Path.GetDirectoryName(fileName)) as CloudDirectoryNode; if (parent == null) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.PathNotFound); var itemName = Path.GetFileName(fileName); var item = parent.GetChildItemByName(drive, itemName); var fileItem = default(CloudFileNode); switch (mode) { case FileMode.Create: fileItem = item as CloudFileNode; if (fileItem != null) fileItem.Truncate(drive); else fileItem = parent.NewFileItem(drive, itemName); info.Context = new StreamContext(fileItem, FileAccess.WriteData); return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.Success); case FileMode.Open: fileItem = item as CloudFileNode; if (fileItem != null) { if (access.HasFlag(FileAccess.ReadData)) info.Context = new StreamContext(fileItem, FileAccess.ReadData) { Stream = Stream.Synchronized(fileItem.GetContent(drive)) }; else if (access.HasFlag(FileAccess.WriteData)) info.Context = new StreamContext(fileItem, FileAccess.WriteData); else if (access.HasFlag(FileAccess.Delete)) info.Context = new StreamContext(fileItem, FileAccess.Delete); } else { info.IsDirectory = item != null; } return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, item != null ? DokanResult.Success : DokanResult.FileNotFound); case FileMode.OpenOrCreate: fileItem = item as CloudFileNode ?? parent.NewFileItem(drive, itemName); if (access.HasFlag(FileAccess.ReadData) && !access.HasFlag(FileAccess.WriteData)) info.Context = new StreamContext(fileItem, FileAccess.ReadData) { Stream = Stream.Synchronized(fileItem.GetContent(drive)) }; else info.Context = new StreamContext(fileItem, FileAccess.WriteData); return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.Success); case FileMode.CreateNew: if (item != null) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, info.IsDirectory ? DokanResult.AlreadyExists : DokanResult.FileExists); if (info.IsDirectory) { parent.NewDirectoryItem(drive, itemName); } else { fileItem = parent.NewFileItem(drive, itemName); info.Context = new StreamContext(fileItem, FileAccess.WriteData); } return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.Success); case FileMode.Append: return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.NotImplemented); case FileMode.Truncate: fileItem = item as CloudFileNode; if (fileItem == null) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.FileNotFound); fileItem.Truncate(drive); info.Context = new StreamContext(fileItem, FileAccess.WriteData); return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.Success); default: return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.NotImplemented); } }
public StreamContext(CloudFileNode file, FileAccess access) { File = file; Access = access; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { //Debug.WriteLine(@"{0} : {1} {2}", fileName, mode.ToString(), access.ToString()); fileName = ToUnixStylePath(fileName); if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) { return DokanResult.FileNotFound; } bool exists = sftpClient.Exists(fileName); // todo : add to memory cache if (info.IsDirectory) { try { switch (mode) { case FileMode.Open: if (!exists) return DokanResult.PathNotFound; break; case FileMode.CreateNew: if(exists) return DokanResult.FileExists; sftpClient.CreateDirectory(fileName); break; } } catch (Renci.SshNet.Common.SshException) { return DokanResult.AccessDenied; } } else { bool readWriteAttributes = (access & DataAccess) == 0; bool readAccess = (access & DataWriteAccess) == 0; System.IO.FileAccess acs = readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite; switch (mode) { case FileMode.Open: if (!exists) return DokanResult.FileNotFound; SftpFileAttributes attr = sftpClient.GetAttributes(fileName); if (readWriteAttributes || attr.IsDirectory) { info.IsDirectory = attr.IsDirectory; info.Context = new object(); return DokanResult.Success; } break; case FileMode.CreateNew: if (exists) return DokanResult.FileExists; // cache invalidate break; case FileMode.Truncate: if (!exists) return DokanResult.FileNotFound; // cache invalidate break; default: // cache invalidate break; } try { info.Context = sftpClient.Open(fileName, mode, acs) as SftpFileStream; } catch (Renci.SshNet.Common.SshException) { return DokanResult.AccessDenied; } } return DokanResult.Success; }
DokanError IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) //.... { return DokanError.ErrorFileNotFound; } LogFSActionInit("OpenFile", fileName, (SftpContext)info.Context, "Mode:{0} Options:{1}", mode,options); string path = GetUnixPath(fileName); // var sftpFileAttributes = GetAttributes(path); //var sftpFileAttributes = _cache.Get(path) as SftpFileAttributes; var sftpFileAttributes = this.CacheGetAttr(path); if (sftpFileAttributes == null) { //Log("cache miss"); sftpFileAttributes = GetAttributes(path); if (sftpFileAttributes != null) //_cache.Add(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout)); CacheAddAttr(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout)); else { LogFSActionOther("OpenFile", fileName, (SftpContext)info.Context, "get attributes failed"); } } /*Log("Open| Name:{0},\n Mode:{1},\n Share{2},\n Disp:{3},\n Flags{4},\n Attr:{5},\nPagingIO:{6} NoCache:{7} SynIO:{8}\n", fileName, access, share, mode, options, attributes, info.PagingIo, info.NoCache, info.SynchronousIo);*/ switch (mode) { case FileMode.Open: if (sftpFileAttributes != null) { if (((uint)access & 0xe0000027) == 0 || sftpFileAttributes.IsDirectory) //check if only wants to read attributes,security info or open directory { //Log("JustInfo:{0},{1}", fileName, sftpFileAttributes.IsDirectory); info.IsDirectory = sftpFileAttributes.IsDirectory; if (options.HasFlag(FileOptions.DeleteOnClose)) { return DokanError.ErrorError;//this will result in calling DeleteFile in Windows Explorer } info.Context = new SftpContext(sftpFileAttributes, false); LogFSActionOther("OpenFile", fileName, (SftpContext)info.Context, "Dir open or get attrs"); return DokanError.ErrorSuccess; } } else { LogFSActionError("OpenFile", fileName, (SftpContext)info.Context, "File not found"); return DokanError.ErrorFileNotFound; } break; case FileMode.CreateNew: if (sftpFileAttributes != null) return DokanError.ErrorAlreadyExists; CacheResetParent(path); break; case FileMode.Truncate: if (sftpFileAttributes == null) return DokanError.ErrorFileNotFound; CacheResetParent(path); //_cache.Remove(path); this.CacheReset(path); break; default: CacheResetParent(path); break; } //Log("NotJustInfo:{0}-{1}", info.Context, mode); try { info.Context = new SftpContext(_sftpSession, path, mode, ((ulong) access & 0x40010006) == 0 ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite, sftpFileAttributes); } catch (SshException ex) // Don't have access rights or try to read broken symlink { var ownerpath = path.Substring(0, path.LastIndexOf('/')); //var sftpPathAttributes = _cache.Get(ownerpath) as SftpFileAttributes; var sftpPathAttributes = CacheGetAttr(ownerpath); if (sftpPathAttributes == null) { //Log("cache miss"); sftpPathAttributes = GetAttributes(ownerpath); if (sftpPathAttributes != null) //_cache.Add(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout)); CacheAddAttr(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout)); else { //Log("Up directory must be created"); LogFSActionError("OpenFile", fileName, (SftpContext)info.Context, "Up directory mising:{0}", ownerpath); return DokanError.ErrorPathNotFound; } } LogFSActionError("OpenFile", fileName, (SftpContext)info.Context, "Access denied"); return DokanError.ErrorAccessDenied; } LogFSActionSuccess("OpenFile", fileName, (SftpContext)info.Context, "Mode:{0}", mode); return DokanError.ErrorSuccess; }
DokanError IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) //.... { return DokanError.ErrorFileNotFound; } SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenFile", fileName, drive, "Mode:{0}", mode); if (drive != null) { LogFSActionSuccess("OpenFile", fileName, drive, "Mode:{0} NonVFS", mode); IDokanOperations idops = GetSubSystemOperations(drive); if (idops == null) { //this happens if mounting failed return DokanError.ErrorAccessDenied; } return idops.CreateFile(fileName, access, share, mode, options, attributes, info); } //check against mountpoints if virtual dir exists string path = fileName.Substring(1); if (path == "") { info.IsDirectory = true; info.Context = null; LogFSActionSuccess("OpenFile", fileName, null, "VFS root"); return DokanError.ErrorSuccess; } foreach (SftpDrive drive2 in this._subsytems) { if (drive2.MountPoint.Length > 0) { if (drive2.MountPoint.IndexOf(path) == 0) { info.IsDirectory = true; info.Context = drive2; LogFSActionSuccess("OpenFile", fileName, drive2, "VFS (sub)mountpoint"); return DokanError.ErrorSuccess; } } } //pathnotfound detection? LogFSActionError("OpenFile", fileName, null, "File not found"); return DokanError.ErrorFileNotFound; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { Console.Error.WriteLine("Attempted to write {0}", fileName); return NtStatus.Success; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { Debug.Print("[CreateFile] fileName : {0}, mode : {1}", fileName, mode); if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) { return DokanResult.FileNotFound; } string path = ToUnixStylePath(fileName); string id = GetIdByPath(path); bool exists = (id != null) ? true : false; if (info.IsDirectory && mode == System.IO.FileMode.CreateNew) return DokanResult.AccessDenied; if (info.IsDirectory) { switch (mode) { case FileMode.Open: if (!exists) return DokanResult.PathNotFound; break; case FileMode.CreateNew: if (exists) return DokanResult.FileExists; //create directory CreateDirectory(path); break; } } else { switch (mode) { case FileMode.Open: if (!exists) return DokanResult.FileNotFound; info.Context = GetFileById(id); info.IsDirectory = IsDirectory(info.Context as Google.Apis.Drive.v2.Data.File); break; default: break; } } //else //{ // bool readWriteAttributes = (access & DataAccess) == 0; // bool readAccess = (access & DataWriteAccess) == 0; // System.IO.FileAccess acs = readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite; // Google.Apis.Drive.v2.Data.File file_obj = GetFileById(id); // switch (mode) // { // case FileMode.Open: // if (!exists) // return DokanResult.FileNotFound; // bool isDir = IsDirectory(file_obj); // if (readWriteAttributes || isDir) // { // info.IsDirectory = isDir; // info.Context = new object(); // return DokanResult.Success; // } // break; // case FileMode.CreateNew: // if (exists) // return DokanResult.FileExists; // // upload empty file // // cache invalidate // break; // case FileMode.Truncate: // if (!exists) // return DokanResult.FileNotFound; // // cache invalidate // break; // default: // // cache invalidate // break; // } // try // { // //var web_stream = _driveService.HttpClient.GetStreamAsync(file_obj.DownloadUrl); // //web_stream.Wait(); // //info.Context = web_stream.Result; // info.Context = file_obj; // } // catch (Exception e) // { // return DokanResult.AccessDenied; // } //} return DokanResult.Success; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { return DokanResult.Success; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { NtStatus result = NtStatus.Success; var filePath = GetPath(fileName); if (info.IsDirectory) { try { switch (mode) { case FileMode.Open: if (!Directory.Exists(filePath)) { try { if (!File.GetAttributes(filePath).HasFlag(FileAttributes.Directory)) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, NtStatus.NotADirectory); } catch (Exception) { return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.FileNotFound); } return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.PathNotFound); } new DirectoryInfo(filePath).EnumerateFileSystemInfos().Any(); // you can't list the directory break; case FileMode.CreateNew: if (Directory.Exists(filePath)) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.FileExists); try { File.GetAttributes(filePath).HasFlag(FileAttributes.Directory); return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.AlreadyExists); } catch (IOException) { } Directory.CreateDirectory(GetPath(fileName)); break; } } catch (UnauthorizedAccessException) { return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.AccessDenied); } } else { var pathExists = true; var pathIsDirectory = false; var readWriteAttributes = (access & DataAccess) == 0; var readAccess = (access & DataWriteAccess) == 0; try { pathExists = (Directory.Exists(filePath) || File.Exists(filePath)); pathIsDirectory = File.GetAttributes(filePath).HasFlag(FileAttributes.Directory); } catch (IOException) { } switch (mode) { case FileMode.Open: if (pathExists) { if (readWriteAttributes || pathIsDirectory) // check if driver only wants to read attributes, security info, or open directory { if (pathIsDirectory && (access & FileAccess.Delete) == FileAccess.Delete && (access & FileAccess.Synchronize) != FileAccess.Synchronize) //It is a DeleteFile request on a directory return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.AccessDenied); info.IsDirectory = pathIsDirectory; info.Context = new object(); // must set it to someting if you return DokanError.Success return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.Success); } } else { return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.FileNotFound); } break; case FileMode.CreateNew: if (pathExists) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.FileExists); break; case FileMode.Truncate: if (!pathExists) return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.FileNotFound); break; } try { info.Context = new FileStream(filePath, mode, readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite, share, 4096, options); if (pathExists && (mode == FileMode.OpenOrCreate || mode == FileMode.Create)) result = DokanResult.AlreadyExists; if (mode == FileMode.CreateNew || mode == FileMode.Create) //Files are always created as Archive attributes |= FileAttributes.Archive; File.SetAttributes(filePath, attributes); } catch (UnauthorizedAccessException) // don't have access rights { return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.AccessDenied); } catch (DirectoryNotFoundException) { return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.PathNotFound); } catch (Exception ex) { var hr = (uint) Marshal.GetHRForException(ex); switch (hr) { case 0x80070020: //Sharing violation return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, DokanResult.SharingViolation); default: throw; } } } return Trace(nameof(CreateFile), fileName, info, access, share, mode, options, attributes, result); }
public DokanError CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { //Clennup debug code if (fileName.Contains("auto") || fileName.Contains("desktop") || fileName.Contains("Auto")) { return DokanError.ErrorFileNotFound; } var path = GetSPath( fileName ); bool pathExists = true; bool pathIsDirectory = false; bool readWriteAttributes = (access & DataAccess) == 0; bool readAccess = (access & DataWriteAccess) == 0; try { pathIsDirectory = !Path.HasExtension( path ); } catch (IOException) { pathExists = false; } switch (mode) { case FileMode.Open: if (pathExists) { if (readWriteAttributes || pathIsDirectory) //check if only wants to read attributes,security info or open directory { info.IsDirectory = pathIsDirectory; info.Context = new object(); // Must set it to someting if you return DokanError.ErrorSuccess return DokanError.ErrorSuccess; } } else { smille_debug("This dose not exist and need to return error or we die! :" + fileName); if (!Path.HasExtension(fileName)) { smille_debug("Allow for virtual folder:" + fileName); info.IsDirectory = true; info.Context = new object(); return DokanError.ErrorSuccess; } return DokanError.ErrorFileNotFound; } break; case FileMode.CreateNew: if (pathExists) return DokanError.ErrorAlreadyExists; break; case FileMode.Truncate: if (!pathExists) return DokanError.ErrorFileNotFound; break; default: break; } info.Context = new object(); smille_debug("Path:" + pathExists); smille_debug("Mode:" + mode); smille_debug("Createing file:"+fileName); return DokanError.ErrorSuccess; }
DokanError IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) //.... { return DokanError.ErrorFileNotFound; } string path = GetUnixPath(fileName); // var sftpFileAttributes = GetAttributes(path); var sftpFileAttributes = _cache.Get(path) as SftpFileAttributes; if (sftpFileAttributes == null) { Log("cache miss"); sftpFileAttributes = GetAttributes(path); if (sftpFileAttributes != null) _cache.Add(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout)); } Log("Open| Name:{0},\n Mode:{1},\n Share{2},\n Disp:{3},\n Flags{4},\n Attr:{5}\n", fileName, access, share, mode, options, attributes); switch (mode) { case FileMode.Open: if (sftpFileAttributes != null) { if (((uint) access & 0xe0000027) == 0 || sftpFileAttributes.IsDirectory) //check if only wants to read attributes,security info or open directory { Log("JustInfo:{0},{1}", fileName, sftpFileAttributes.IsDirectory); info.IsDirectory = sftpFileAttributes.IsDirectory; info.Context = new SftpContext(sftpFileAttributes); return DokanError.ErrorSuccess; } } else return DokanError.ErrorFileNotFound; break; case FileMode.CreateNew: if (sftpFileAttributes != null) return DokanError.ErrorAlreadyExists; InvalidateParentCache(fileName); // cache invalidate break; case FileMode.Truncate: if (sftpFileAttributes == null) return DokanError.ErrorFileNotFound; InvalidateParentCache(fileName); _cache.Remove(path); break; default: InvalidateParentCache(fileName); break; } Log("NotJustInfo:{0}-{1}", info.Context, mode); try { info.Context = new SftpContext(_sftpSession, path, mode, ((ulong) access & 0x40010006) == 0 ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite, sftpFileAttributes); } catch (SshException) // Don't have access rights or try to read broken symlink { return DokanError.ErrorAccessDenied; } return DokanError.ErrorSuccess; }
public NtStatus CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { var path = GetPath(fileName); bool pathExists = true; bool pathIsDirectory = false; bool readWriteAttributes = (access & DataAccess) == 0; bool readAccess = (access & DataWriteAccess) == 0; try { pathIsDirectory = File.GetAttributes(path).HasFlag(FileAttributes.Directory); } catch (IOException) { pathExists = false; } switch (mode) { case FileMode.Open: if (pathExists) { if (readWriteAttributes || pathIsDirectory) // check if driver only wants to read attributes, security info, or open directory { info.IsDirectory = pathIsDirectory; info.Context = new object(); // must set it to someting if you return DokanError.Success return Trace("CreateFile", fileName, info, access, share, mode, options, attributes, DokanResult.Success); } } else { return Trace("CreateFile", fileName, info, access, share, mode, options, attributes, DokanResult.FileNotFound); } break; case FileMode.CreateNew: if (pathExists) return Trace("CreateFile", fileName, info, access, share, mode, options, attributes, DokanResult.FileExists); break; case FileMode.Truncate: if (!pathExists) return Trace("CreateFile", fileName, info, access, share, mode, options, attributes, DokanResult.FileNotFound); break; default: break; } try { info.Context = new FileStream(path, mode, readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite, share, 4096, options); } catch (UnauthorizedAccessException) // don't have access rights { return Trace("CreateFile", fileName, info, access, share, mode, options, attributes, DokanResult.AccessDenied); } return Trace("CreateFile", fileName, info, access, share, mode, options, attributes, DokanResult.Success); }
public override DokanError CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info) { log.Info(String.Format("CreateFile call - {0}", fileName)); IChip chip = rfidListener.GetChip(); if (chip == null) return DokanError.ErrorNotReady; info.Context = new RFIDContext(); if (fileName == "\\" || (attributes & FileAttributes.Directory) != 0) { if (!CheckDirectoryPath(fileName)) { log.Error("Path not found"); return DokanError.ErrorFileNotFound; } return DokanError.ErrorSuccess; } else { bool exists = false; lock (cacheFiles) { if (!CacheExists(fileName)) { if (CacheCount() > 0) { log.Error("Cache already initialized and cannot found file"); return DokanError.ErrorFileNotFound; } DokanError payloadRet = ReadAndCachePayload(nfcConfig.CSNAsRoot ? "\\" + chip.ChipIdentifier : String.Empty); if (payloadRet == DokanError.ErrorSuccess) { exists = CacheExists(fileName); } else return payloadRet; } else { exists = true; } } log.Info(String.Format("Exists? {0}", exists)); switch (mode) { case FileMode.Open: { log.Info("FileMode Open"); if (exists) return DokanError.ErrorSuccess; else { log.Error("File not found."); return DokanError.ErrorFileNotFound; } } case FileMode.CreateNew: { log.Info("FileMode CreateNew"); if (exists) return DokanError.ErrorAlreadyExists; InitCache(fileName); return DokanError.ErrorSuccess; } case FileMode.Create: { log.Info("FileMode Create"); InitCache(fileName); return DokanError.ErrorSuccess; } case FileMode.OpenOrCreate: { log.Info("FileMode OpenOrCreate"); if (!exists) { InitCache(fileName); } return DokanError.ErrorSuccess; } case FileMode.Truncate: { log.Info("FileMode Truncate"); if (!exists) return DokanError.ErrorFileNotFound; InitCache(fileName); return DokanError.ErrorSuccess; } case FileMode.Append: { log.Info("FileMode Append"); if (!exists) return DokanError.ErrorFileNotFound; return DokanError.ErrorSuccess; } default: { log.Error(String.Format("Error unknown FileMode {0}", mode)); return DokanError.ErrorError; } } } }