public int FindFilesProxy(IntPtr rawFileName, IntPtr rawFillFindData, // function pointer ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); FileInformation[] files; int ret = operations.FindFiles(file, out files, ConvertFileInfo(ref rawFileInfo)); FILL_FIND_DATA fill = (FILL_FIND_DATA)Marshal.GetDelegateForFunctionPointer(rawFillFindData, typeof(FILL_FIND_DATA)); if ((ret == 0) && (files != null) ) { // ReSharper disable ForCanBeConvertedToForeach // Used a single entry call to speed up the "enumeration" of the list for (int index = 0; index < files.Length; index++) // ReSharper restore ForCanBeConvertedToForeach { Addto(fill, ref rawFileInfo, files[index]); } } return(ret); } catch (Exception ex) { Log.ErrorException("FindFilesProxy threw: ", ex); return(-1); } }
private void Addto(FILL_FIND_DATA fill, ref DOKAN_FILE_INFO rawFileInfo, FileInformation fi) { WIN32_FIND_DATA data = new WIN32_FIND_DATA { dwFileAttributes = fi.Attributes, ftCreationTime = { dwHighDateTime = (int)(fi.CreationTime.ToFileTime() >> 32), dwLowDateTime = (int)(fi.CreationTime.ToFileTime() & 0xffffffff) }, ftLastAccessTime = { dwHighDateTime = (int)(fi.LastAccessTime.ToFileTime() >> 32), dwLowDateTime = (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff) }, ftLastWriteTime = { dwHighDateTime = (int)(fi.LastWriteTime.ToFileTime() >> 32), dwLowDateTime = (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff) }, nFileSizeLow = (uint)(fi.Length & 0xffffffff), nFileSizeHigh = (uint)(fi.Length >> 32), cFileName = fi.FileName }; //ZeroMemory(&data, sizeof(WIN32_FIND_DATAW)); fill(ref data, ref rawFileInfo); }
public int UnmountProxy(ref DOKAN_FILE_INFO rawFileInfo) { try { return(operations.Unmount(ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("UnmountProxy threw: ", ex); return(-1); } }
public int DeleteDirectoryProxy(IntPtr rawFileName, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); return(operations.DeleteDirectory(file, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("DeleteDirectoryProxy threw: ", ex); return(-1); } }
public int FlushFileBuffersProxy(IntPtr rawFileName, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); int ret = operations.FlushFileBuffers(file, ConvertFileInfo(ref rawFileInfo)); return(ret); } catch (Exception ex) { Log.ErrorException("FlushFileBuffersProxy threw: ", ex); return(-1); } }
public int GetDiskFreeSpaceProxy(ref ulong rawFreeBytesAvailable, ref ulong rawTotalNumberOfBytes, ref ulong rawTotalNumberOfFreeBytes, ref DOKAN_FILE_INFO rawFileInfo) { try { return(operations.GetDiskFreeSpace(ref rawFreeBytesAvailable, ref rawTotalNumberOfBytes, ref rawTotalNumberOfFreeBytes, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("GetDiskFreeSpaceProxy threw: ", ex); return(-1); } }
public int SetAllocationSizeProxy(IntPtr rawFileName, long rawLength, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); return(operations.SetAllocationSize(file, rawLength, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("SetAllocationSizeProxy threw: ", ex); return(-1); } }
public int CloseFileProxy(IntPtr rawFileName, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); int ret = operations.CloseFile(file, ConvertFileInfo(ref rawFileInfo)); rawFileInfo.Context = 0; return(ret); } catch (Exception ex) { Log.ErrorException("CloseFileProxy threw: ", ex); return(-1); } }
/// <summary> /// DOKAN_FILE_INFO is a struct so pass byref to keep things the same (Speed etc) /// </summary> /// <param name="rawInfo">DOKAN_FILE_INFO struct</param> /// <returns>new internal DokanFileInfo class</returns> private static DokanFileInfo ConvertFileInfo(ref DOKAN_FILE_INFO rawInfo) { // TODO: If this proves to be expensive in the GC, then perhaps just pass the rawInfo around as a ref !! return(new DokanFileInfo { refFileHandleContext = rawInfo.Context, IsDirectory = rawInfo.IsDirectory == 1, ProcessId = rawInfo.ProcessId, DeleteOnClose = rawInfo.DeleteOnClose == 1, PagingIo = rawInfo.PagingIo == 1, SynchronousIo = rawInfo.SynchronousIo == 1, Nocache = rawInfo.Nocache == 1, WriteToEndOfFile = rawInfo.WriteToEndOfFile == 1 }); }
public int GetFileSecurity(IntPtr rawFileName, ref SECURITY_INFORMATION rawRequestedInformation, ref SECURITY_DESCRIPTOR rawSecurityDescriptor, uint rawSecurityDescriptorLength, ref uint rawSecurityDescriptorLengthNeeded, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); return(operations.GetFileSecurityNative(file, ref rawRequestedInformation, ref rawSecurityDescriptor, rawSecurityDescriptorLength, ref rawSecurityDescriptorLengthNeeded, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("GetFileSecurity threw: ", ex); return(-1); } }
public int SetFileTimeProxy(IntPtr rawFileName, ref ComTypes.FILETIME rawCreationTime, ref ComTypes.FILETIME rawLastAccessTime, ref ComTypes.FILETIME rawLastWriteTime, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); // http://liquesce.codeplex.com/workitem/8488 return(operations.SetFileTimeNative(file, ref rawCreationTime, ref rawLastAccessTime, ref rawLastWriteTime, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("SetFileTimeProxy threw: ", ex); return(-1); } }
public int SetFileAttributesProxy(IntPtr rawFileName, uint rawAttributes, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); FileAttributes attr = (FileAttributes)rawAttributes; return(operations.SetFileAttributes(file, attr, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("SetFileAttributesProxy threw: ", ex); return(-1); } }
public int CreateDirectoryProxy(IntPtr rawFileName, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); DokanFileInfo info = ConvertFileInfo(ref rawFileInfo); int ret = operations.CreateDirectory(file, info); rawFileInfo.Context = info.refFileHandleContext; rawFileInfo.IsDirectory = Convert.ToByte(info.IsDirectory); return(ret); } catch (Exception ex) { Log.ErrorException("CreateDirectoryProxy threw: ", ex); return(-1); } }
public static extern bool DokanResetTimeout(uint timeout, ref DOKAN_FILE_INFO rawFileInfo);
public int GetVolumeInformationProxy(IntPtr rawVolumeNameBuffer, uint rawVolumeNameSize, ref uint rawVolumeSerialNumber, ref uint rawMaximumComponentLength, ref uint rawFileSystemFlags, IntPtr rawFileSystemNameBuffer, uint rawFileSystemNameSize, ref DOKAN_FILE_INFO fileInfo) { try { byte[] volume = Encoding.Unicode.GetBytes(options.VolumeLabel); int length = volume.Length; byte[] volumeNull = new byte[length + 2]; Array.Copy(volume, volumeNull, length); Marshal.Copy(volumeNull, 0, rawVolumeNameBuffer, Math.Min((int)rawVolumeNameSize, length + 2)); rawVolumeSerialNumber = volumeSerialNumber; rawMaximumComponentLength = 256; //#define FILE_CASE_SENSITIVE_SEARCH 0x00000001 //#define FILE_CASE_PRESERVED_NAMES 0x00000002 //#define FILE_UNICODE_ON_DISK 0x00000004 //#define FILE_PERSISTENT_ACLS 0x00000008 // This sends the data to the Recycler and not Recycled // See http://msdn.microsoft.com/en-us/library/aa364993%28VS.85%29.aspx for more flags // // FILE_FILE_COMPRESSION 0x00000010 // Don't do this.. It causes lot's of problems later on // And the Dokan code does not support it //case FileStreamInformation: // //DbgPrint("FileStreamInformation\n"); // status = STATUS_NOT_IMPLEMENTED; // break; rawFileSystemFlags = 0x0f; byte[] sys = Encoding.Unicode.GetBytes("DOKAN"); length = sys.Length; byte[] sysNull = new byte[length + 2]; Array.Copy(sys, sysNull, length); Marshal.Copy(sysNull, 0, rawFileSystemNameBuffer, Math.Min((int)rawFileSystemNameSize, length + 2)); return(0); } catch (Exception ex) { Log.ErrorException("GetVolumeInformationProxy threw: ", ex); return(-1); } }
public int WriteFileProxy(IntPtr rawFileName, IntPtr rawBuffer, uint rawNumberOfBytesToWrite, ref uint rawNumberOfBytesWritten, long rawOffset, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); // Need to reduce memory footprint from Dokan to .Net !! // http://code.google.com/p/dokan/issues/detail?id=174 return(operations.WriteFileNative(file, rawBuffer, rawNumberOfBytesToWrite, ref rawNumberOfBytesWritten, rawOffset, ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("WriteFileProxy threw: ", ex); return(-1); } }
public int MoveFileProxy(IntPtr rawFileName, IntPtr rawNewFileName, int rawReplaceIfExisting, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); string newfile = GetFileName(rawNewFileName); return(operations.MoveFile(file, newfile, (rawReplaceIfExisting != 0), ConvertFileInfo(ref rawFileInfo))); } catch (Exception ex) { Log.ErrorException("MoveFileProxy threw: ", ex); return(-1); } }
public int GetFileInformationProxy(IntPtr rawFileName, ref BY_HANDLE_FILE_INFORMATION rawHandleFileInformation, ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); FileInformation fi = new FileInformation(); int ret = operations.GetFileInformation(file, ref fi, ConvertFileInfo(ref rawFileInfo)); if (ret == 0) { rawHandleFileInformation.dwFileAttributes = (uint)fi.Attributes /* + FILE_ATTRIBUTE_VIRTUAL*/; rawHandleFileInformation.ftCreationTime.dwHighDateTime = (int)(fi.CreationTime.ToFileTime() >> 32); rawHandleFileInformation.ftCreationTime.dwLowDateTime = (int)(fi.CreationTime.ToFileTime() & 0xffffffff); rawHandleFileInformation.ftLastAccessTime.dwHighDateTime = (int)(fi.LastAccessTime.ToFileTime() >> 32); rawHandleFileInformation.ftLastAccessTime.dwLowDateTime = (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff); rawHandleFileInformation.ftLastWriteTime.dwHighDateTime = (int)(fi.LastWriteTime.ToFileTime() >> 32); rawHandleFileInformation.ftLastWriteTime.dwLowDateTime = (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff); rawHandleFileInformation.dwVolumeSerialNumber = volumeSerialNumber; rawHandleFileInformation.nFileSizeLow = (uint)(fi.Length & 0xffffffff); rawHandleFileInformation.nFileSizeHigh = (uint)(fi.Length >> 32); rawHandleFileInformation.dwNumberOfLinks = 1; rawHandleFileInformation.nFileIndexHigh = 0; rawHandleFileInformation.nFileIndexLow = (uint)fi.FileName.GetHashCode(); } return(ret); } catch (Exception ex) { Log.ErrorException("GetFileInformationProxy threw: ", ex); return(-1); } }
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 int FindFilesWithPatternProxy(IntPtr rawFileName, IntPtr rawSearchPattern, IntPtr rawFillFindData, // function pointer ref DOKAN_FILE_INFO rawFileInfo) { try { string file = GetFileName(rawFileName); string pattern = GetFileName(rawSearchPattern); int ret; FileInformation[] files = null; char[] matchDOS = ("\"<>?").ToCharArray(); if (-1 != pattern.IndexOfAny(matchDOS)) // See http://liquesce.codeplex.com/workitem/7556 { Log.Info("An Application is using DOS_STAR style pattern matching[{0}], Will switch to compatible mode matching", pattern); // PureSync (And maybe others) use the following to get this and / or the subdir contents // DirName<"* // But there is an issue with the code inside dokan see http://code.google.com/p/dokan/issues/detail?id=192 FileInformation[] nonPatternFiles; ret = operations.FindFiles(file, out nonPatternFiles, ConvertFileInfo(ref rawFileInfo)); if (ret == Dokan.DOKAN_SUCCESS) { List <FileInformation> matchedFiles = new List <FileInformation>(); matchedFiles.AddRange(nonPatternFiles.Where(patternFile => DokanDll.DokanIsNameInExpression(pattern, patternFile.FileName, false))); files = matchedFiles.ToArray(); } // * (asterisk) Matches zero or more characters. // ? (question mark) Matches a single character. // #define DOS_DOT (L'"') - Matches either a period or zero characters beyond the name string. // #define DOS_QM (L'>') - Matches any single character or, upon encountering a period or end of name string, // advances the expression to the end of the set of contiguous DOS_QMs. // #define DOS_STAR (L'<') - Matches zero or more characters until encountering and matching the final . in the name. Log.Debug("DOS_STAR style pattern OUT [found {0}]", (files != null) ? files.Length : 0); if (Log.IsTraceEnabled) { if (files != null) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); for (int index = 0; index < files.Length; index++) { FileInformation fileInformation = files[index]; sb.AppendLine(fileInformation.FileName); } Log.Trace(sb.ToString()); } } } else { ret = operations.FindFilesWithPattern(file, pattern, out files, ConvertFileInfo(ref rawFileInfo)); } FILL_FIND_DATA fill = (FILL_FIND_DATA)Marshal.GetDelegateForFunctionPointer(rawFillFindData, typeof(FILL_FIND_DATA)); if ((ret == 0) && (files != null) ) { // ReSharper disable ForCanBeConvertedToForeach // Used a single entry call to speed up the "enumeration" of the list for (int index = 0; index < files.Length; index++) // ReSharper restore ForCanBeConvertedToForeach { Addto(fill, ref rawFileInfo, files[index]); } } return(ret); } catch (Exception ex) { Log.ErrorException("FindFilesProxy threw: ", ex); return(-1); } }