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); }
internal NtStatus ZwCreateFileProxy(string rawFileName, IntPtr SecurityContext, uint rawDesiredAccess, uint rawFileAttributes, uint rawShareAccess, uint rawCreateDisposition, uint rawCreateOptions, DokanFileInfo dokanFileInfo) { try { FileOptions fileOptions = 0; FileAttributes fileAttributes = 0; int fileAttributesAndFlags = 0; int creationDisposition = 0; DokanNativeMethods.DokanMapKernelToUserCreateFileFlags(rawFileAttributes, rawCreateOptions, rawCreateDisposition, ref fileAttributesAndFlags, ref creationDisposition); foreach (FileOptions fileOption in Enum.GetValues(typeof(FileOptions))) { if (((FileOptions)(fileAttributesAndFlags & 0xffffc000) & fileOption) == fileOption) { fileOptions |= fileOption; } } foreach (FileAttributes fileAttribute in Enum.GetValues(typeof(FileAttributes))) { if (((FileAttributes)(fileAttributesAndFlags & 0x3fff) & fileAttribute) == fileAttribute) { fileAttributes |= fileAttribute; } } NtStatus result = _operations.CreateFile(rawFileName, (FileAccess)rawDesiredAccess, (FileShare)rawShareAccess, (FileMode)creationDisposition, fileOptions, fileAttributes, dokanFileInfo); return(result); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("Dokan exception: ", ex); return(DokanResult.Unsuccessful); } }
public NtStatus CreateFileProxy(string rawFileName, uint rawAccessMode, uint rawShare, uint rawCreationDisposition, uint rawFlagsAndAttributes, DokanFileInfo rawFileInfo) { try { Trace("\nCreateFileProxy : " + rawFileName); Trace("\tCreationDisposition\t" + (FileMode)rawCreationDisposition); Trace("\tFileAccess\t" + (FileAccess)rawAccessMode); Trace("\tFileShare\t" + (FileShare)rawShare); Trace("\tFileOptions\t" + (FileOptions)(rawFlagsAndAttributes & 0xffffc000)); Trace("\tFileAttributes\t" + (FileAttributes)(rawFlagsAndAttributes & 0x3fff)); Trace("\tContext\t" + ToTrace(rawFileInfo)); NtStatus result = operations.CreateFile(rawFileName, (FileAccess)rawAccessMode, (FileShare)rawShare, (FileMode)rawCreationDisposition, (FileOptions)(rawFlagsAndAttributes & 0xffffc000), (FileAttributes)(rawFlagsAndAttributes & 0x3fff), rawFileInfo); Trace("CreateFileProxy : " + rawFileName + " Return : " + result); return(result); } #pragma warning disable 0168 catch (Exception ex) #pragma warning restore 0168 { Trace("CreateFileProxy : " + rawFileName + " Throw : " + ex.Message); return(DokanResult.Unsuccessful); } }
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); }
private NtStatus OpenDirectory(string fileName, IDokanFileInfo info) { SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName); LogFSActionInit("OpenDir", fileName, drive, ""); if (drive != null) { lastActiveSubsytem = drive; IDokanOperations ops = GetSubSystemOperations(drive); if (ops == null) { LogFSActionError("OpenDir", fileName, drive, "Cannot open, mount failed?"); return(NtStatus.AccessDenied); } LogFSActionSuccess("OpenDir", fileName, drive, "Found, subsytem"); return(ops.CreateFile(fileName, FileAccess.GenericRead, FileShare.None, FileMode.Open, FileOptions.None, FileAttributes.Directory, info)); } if (fileName.Length == 1) //root dir { LogFSActionSuccess("OpenDir", fileName, drive, "Found, VFS root"); info.IsDirectory = true; return(NtStatus.Success); } //root test should keep lastactive if drag and drop(win8) lastActiveSubsytem = null; string path = fileName.Substring(1); //cut leading \ foreach (SftpDrive subdrive in _subsytems) { string mp = subdrive.MountPoint; // mp1 || mp1\mp2 ... if (path == mp) { info.Context = subdrive; info.IsDirectory = true; LogFSActionSuccess("OpenDir", fileName, drive, "Found, final mountpoint"); return(NtStatus.Success); } if (mp.IndexOf(path + '\\') == 0) { //path is part of mount point info.Context = subdrive; info.IsDirectory = true; LogFSActionSuccess("OpenDir", fileName, drive, "Found, part of mountpoint"); return(NtStatus.Success); } } LogFSActionError("OpenDir", fileName, drive, "Path not found"); return(NtStatus.ObjectPathNotFound); }
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); }
/// <summary> /// Called when a file is to be created /// See https://msdn.microsoft.com/en-us/library/windows/hardware/ff566424(v=vs.85).aspx /// </summary> public NtStatus ZwCreateFileProxy(string rawFileName, IntPtr securityContext, uint rawDesiredAccess, uint rawFileAttributes, uint rawShareAccess, uint rawCreateDisposition, uint rawCreateOptions, DokanFileInfo rawFileInfo) { try { FileOptions fileOptions = 0; FileAttributes fileAttributes = 0; var fileAttributesAndFlags = 0; var creationDisposition = 0; NativeMethods.DokanMapKernelToUserCreateFileFlags(rawFileAttributes, rawCreateOptions, rawCreateDisposition, ref fileAttributesAndFlags, ref creationDisposition); foreach (FileOptions fileOption in Enum.GetValues(typeof(FileOptions))) { if (((FileOptions)(fileAttributesAndFlags & 0xffffc000) & fileOption) == fileOption) { fileOptions |= fileOption; } } foreach (FileAttributes fileAttribute in Enum.GetValues(typeof(FileAttributes))) { if (((FileAttributes)(fileAttributesAndFlags & 0x3fff) & fileAttribute) == fileAttribute) { fileAttributes |= fileAttribute; } } logger.Debug("CreateFileProxy : {0}", rawFileName); logger.Debug("\tCreationDisposition\t{0}", (FileMode)creationDisposition); logger.Debug("\tFileAccess\t{0}", (FileAccess)rawDesiredAccess); logger.Debug("\tFileShare\t{0}", (FileShare)rawShareAccess); logger.Debug("\tFileOptions\t{0}", fileOptions); logger.Debug("\tFileAttributes\t{0}", fileAttributes); logger.Debug("\tContext\t{0}", rawFileInfo); var result = operations.CreateFile(rawFileName, (FileAccess)rawDesiredAccess, (FileShare)rawShareAccess, (FileMode)creationDisposition, fileOptions, fileAttributes, rawFileInfo); logger.Debug("CreateFileProxy : {0} Return : {1}", rawFileName, result); return(result); } catch (Exception ex) { logger.Error("CreateFileProxy : {0} Throw : {1}", rawFileName, ex.Message); return(DokanResult.Unsuccessful); } }
public int CreateFileProxy(string rawFileName, uint rawAccessMode, uint rawShare, uint rawCreationDisposition, uint rawFlagsAndAttributes, DokanFileInfo rawFileInfo) { try { return((int)_operations.CreateFile(rawFileName, (FileAccess)rawAccessMode, (FileShare)rawShare, (FileMode)rawCreationDisposition, (FileOptions)(rawFlagsAndAttributes & 0xffffc000), //& 0xffffc000 (FileAttributes)(rawFlagsAndAttributes & 0x3fff), rawFileInfo)); //& 0x3ffflower 14 bits i think are file atributes and rest are file options WRITE_TROUGH etc. } catch { #if DEBUG throw; #else return(ERROR_FILE_NOT_FOUND); #endif } }
public int CreateFileProxy(IntPtr rawFileName, uint rawAccessMode, uint rawShare, uint rawCreationDisposition, uint rawFlagsAndAttributes, ref DOKAN_FILE_INFO rawFileInfo) { try { Log.Trace("CreateFileProxy IN rawFileName[{0}], rawAccessMode[{1}], rawShare[{2}], rawCreationDisposition[{3}], rawFlagsAndAttributes[{4}]", rawFileName, rawAccessMode, rawShare, rawCreationDisposition, rawFlagsAndAttributes); string file = GetFileName(rawFileName); DokanFileInfo info = ConvertFileInfo(ref rawFileInfo); int ret = operations.CreateFile(file, rawAccessMode, rawShare, rawCreationDisposition, rawFlagsAndAttributes, info); rawFileInfo.Context = info.refFileHandleContext; rawFileInfo.IsDirectory = Convert.ToByte(info.IsDirectory); return(ret); } catch (Exception ex) { Log.ErrorException("CreateFileProxy threw:", ex); return(Dokan.ERROR_FILE_NOT_FOUND); } }
public NtStatus ZwCreateFileProxy(string rawFileName, IntPtr SecurityContext, uint rawDesiredAccess, uint rawFileAttributes, uint rawShareAccess, uint rawCreateDisposition, uint rawCreateOptions, DokanFileInfo rawFileInfo) { try { int FileAttributesAndFlags = 0; int CreationDisposition = 0; NativeMethods.DokanMapKernelToUserCreateFileFlags(rawFileAttributes, rawCreateOptions, rawCreateDisposition, ref FileAttributesAndFlags, ref CreationDisposition); Trace("\nCreateFileProxy : " + rawFileName); Trace("\tCreationDisposition\t" + (FileMode)CreationDisposition); Trace("\tFileAccess\t" + (FileAccess)rawDesiredAccess); Trace("\tFileShare\t" + (FileShare)rawShareAccess); Trace("\tFileOptions\t" + (FileOptions)(FileAttributesAndFlags & 0xffffc000)); Trace("\tFileAttributes\t" + (FileAttributes)(FileAttributesAndFlags & 0x3fff)); Trace("\tContext\t" + ToTrace(rawFileInfo)); NtStatus result = operations.CreateFile(rawFileName, (FileAccess)rawDesiredAccess, (FileShare)rawShareAccess, (FileMode)CreationDisposition, (FileOptions)(FileAttributesAndFlags & 0xffffc000), (FileAttributes)(FileAttributesAndFlags & 0x3fff), rawFileInfo); Trace("CreateFileProxy : " + rawFileName + " Return : " + result); return(result); } #pragma warning disable 0168 catch (Exception ex) #pragma warning restore 0168 { Trace("CreateFileProxy : " + rawFileName + " Throw : " + ex.Message); return(DokanResult.Unsuccessful); } }