public FuserFileHandler GetFileHandler(string filename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { FuserFileHandler ret = null; if (rawHFile.Context != 0) { int index = (int)rawHFile.Context; // TODO: remove casting lock (this.handlers) { if (index > 0 && index <= this.ListHandlerMaxID) { PVCStoredHandle sh = this.handlers[index]; if (sh != null) { ret = CreateFileHandler(filename, sh.FileHandle, rawHFile); } } } } if (ret == null) { ret = RegisterFileHandler(filename, ref rawHFile); } return(ret); }
public int DeleteDirectory(IntPtr rawFilename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { return(ConvReturnCodeToInt(this.fsDevice.DeleteDirectory(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile)))); } catch (Exception e) { this.fsDevice.LogErrorMessage("DeleteDirectory", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int LockFile(IntPtr rawFilename, long rawByteOffset, long rawLength, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { return(ConvReturnCodeToInt(this.fsDevice.LockFile(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), rawByteOffset, rawLength))); } catch (Exception e) { this.fsDevice.LogErrorMessage("LockFile", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int SetFileAttributes(IntPtr rawFilename, uint rawAttributes, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { FileAttributes attr = (FileAttributes)rawAttributes; return(ConvReturnCodeToInt(this.fsDevice.SetFileAttributes(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), attr))); } catch (Exception e) { this.fsDevice.LogErrorMessage("SetFileAttributes", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int CloseFile(IntPtr rawFilename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { Win32Returncode ret = this.fsDevice.CloseFile(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile)); this.hManager.RemoveFileHandler(ref rawHFile); return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.fsDevice.LogErrorMessage("CloseFile", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public FuserFileHandler RegisterFileHandler(string filename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { FileHandler fh = new FileHandler(filename); lock (this.handlers) { //int n = this.handlers.Count + 1; bool InsertNewItem = true; if (this.reserve.Count > 0 && this.reserve.Count >= LIMIT_MIN_COUNT_RESERVE) { // try to take an item from the reserve list. PVCStoredHandle sh = this.reserve.Peek(); if (sh == null) { System.Diagnostics.Debugger.Break(); } if (sh.CheckReInsert()) { sh = this.reserve.Dequeue(); int index = sh.GetHandleID; if (this.handlers[index] != null) { return(null); } this.handlers[index] = new PVCStoredHandle(index, fh); if (this.handlers[index].GetHandleID != index) { return(null); } rawHFile.Context = (ulong)index; // TODO: remove casting InsertNewItem = false; } } if (InsertNewItem) { ListHandlerMaxID++; this.handlers.Add(new PVCStoredHandle(ListHandlerMaxID, fh)); if (this.handlers[ListHandlerMaxID].GetHandleID != ListHandlerMaxID) { return(null); } rawHFile.Context = (ulong)ListHandlerMaxID; // TODO: remove casting } } return(CreateFileHandler(filename, fh, rawHFile)); }
public int CreateDirectory(IntPtr rawFilename, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { Win32Returncode ret = this.fsDevice.CreateDirectory(this.hManager.RegisterFileHandler(GetFilename(rawFilename), ref rawHFile)); if (ret != Win32Returncode.SUCCESS) { this.hManager.RemoveFileHandler(ref rawHFile); } return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.hManager.RemoveFileHandler(ref rawHFile); this.fsDevice.LogErrorMessage("Cleanup", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public void RemoveFileHandler(ref FuserDefinition.FUSER_FILE_INFO rawHFile) { if (rawHFile.Context != 0) { int index = (int)rawHFile.Context; // TODO: remove casting lock (this.handlers) { rawHFile.Context = 0; // immediately removes the reference if (index > 0 && index <= this.ListHandlerMaxID) { PVCStoredHandle sh = this.handlers[index]; this.handlers[index] = null; // Removes saved handles if (sh != null) { sh.Close(); this.reserve.Enqueue(sh); } } } } }
public int FindFiles(IntPtr rawFilename, IntPtr FunctionFillFindData, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { FuserDefinition.BY_HANDLE_FILE_INFORMATION rawFI = new FuserDefinition.BY_HANDLE_FILE_INFORMATION(); List <FuserFileInformation> files = new List <FuserFileInformation>(); Win32Returncode ret = this.fsDevice.FindFiles(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), files); FuserDefinition.FILL_FIND_DATA rawListAdd = (FuserDefinition.FILL_FIND_DATA)Marshal.GetDelegateForFunctionPointer(FunctionFillFindData, typeof(FuserDefinition.FILL_FIND_DATA)); // Function pointer if (ret == Win32Returncode.SUCCESS) { foreach (FuserFileInformation fi in files) { if (!(fi.CreationTime == DateTime.MinValue || fi.LastAccessTime == DateTime.MinValue || fi.LastWriteTime == DateTime.MinValue)) { FuserDefinition.WIN32_FIND_DATA data = new FuserDefinition.WIN32_FIND_DATA(); ConvertFileInfoToRAW(fi, ref rawFI); data.ftCreationTime = rawFI.ftCreationTime; data.ftLastAccessTime = rawFI.ftLastAccessTime; data.ftLastWriteTime = rawFI.ftLastWriteTime; data.nFileSizeLow = rawFI.nFileSizeLow; data.nFileSizeHigh = rawFI.nFileSizeHigh; data.dwFileAttributes = fi.Attributes; data.cFileName = fi.Filename; rawListAdd(ref data, ref rawHFile); } } } return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.fsDevice.LogErrorMessage("FindFiles", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
private FuserFileHandler CreateFileHandler(string filename, FileHandler fileHandle, FuserDefinition.FUSER_FILE_INFO rawHFile) { return(new FuserFileHandler(filename, fileHandle, (rawHFile.IsDirectory == 1), (rawHFile.DeleteOnClose == 1))); }
public int Unmount(ref FuserDefinition.FUSER_FILE_INFO rawHFile) // TODO: remove or change { return(0); }
private delegate int GetVolumeInformationDelegate(IntPtr rawVolumenameBuffer, uint rawVolumenameSize, ref uint rawSerialnumber, ref uint rawMaximumComponentLength, ref uint rawFileSystemFlags, IntPtr rawFileSystemnameBuffer, uint rawFileSystemnameSize, ref FuserDefinition.FUSER_FILE_INFO rawHFile); // TODO: remove rawHFile public int GetVolumeInformation(IntPtr rawVolumenameBuffer, uint rawVolumenameSize, ref uint rawSerialnumber, ref uint rawMaximumComponentLength, ref uint rawFileSystemFlags, IntPtr rawFileSystemnameBuffer, uint rawFileSystemnameSize, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { byte[] volumelabel = System.Text.Encoding.Unicode.GetBytes(this.volumelabel); byte[] filesystem = System.Text.Encoding.Unicode.GetBytes(this.filesystem); Marshal.Copy(volumelabel, 0, rawVolumenameBuffer, Math.Min((int)rawVolumenameSize, volumelabel.Length)); // TODO: check if change from uint to int is possible for rawVolumenameSize, then remove casting Marshal.Copy(filesystem, 0, rawFileSystemnameBuffer, Math.Min((int)rawFileSystemnameSize, filesystem.Length)); // TODO: check if change from uint to int is possible for rawVolumenameSize, then remove casting rawSerialnumber = this.serialnumber; //rawFileSystemFlags = (uint) (FuserDefinition.FileSystemFlags.FILE_CASE_PRESERVED_NAMES | FuserDefinition.FileSystemFlags.FILE_UNICODE_ON_DISK | FuserDefinition.FileSystemFlags.FILE_CASE_SENSITIVE_SEARCH); rawFileSystemFlags = 7; // The above code corresponds to 7 // rawFileSystemFlags += 8;//ACL rawMaximumComponentLength = 256; return(ConvReturnCodeToInt(Win32Returncode.SUCCESS)); } catch (Exception e) { this.fsDevice.LogErrorMessage("GetVolumeInformation", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
private delegate int GetDiskFreeSpaceDelegate(ref ulong rawFreeBytesAvailable, ref ulong rawTotalNumberOfBytes, ref ulong rawTotalNumberOfFreeBytes, ref FuserDefinition.FUSER_FILE_INFO rawHFile); // TODO: remove rawHFile public int GetDiskFreeSpace(ref ulong rawFreeBytesAvailable, ref ulong rawTotalNumberOfBytes, ref ulong rawTotalNumberOfFreeBytes, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { return(ConvReturnCodeToInt(this.fsDevice.GetDiskFreeSpace(ref rawFreeBytesAvailable, ref rawTotalNumberOfBytes, ref rawTotalNumberOfFreeBytes))); } catch (Exception e) { this.fsDevice.LogErrorMessage("GetDiskFreeSpace", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int ReadFile(IntPtr rawFilename, IntPtr rawBuffer, uint rawBufferLength, ref uint rawReadLength, long rawOffset, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { byte[] buf = new byte[rawBufferLength]; uint readLength = 0; Win32Returncode ret = this.fsDevice.ReadFile(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), buf, ref readLength, rawOffset); if (ret == Win32Returncode.SUCCESS) { rawReadLength = readLength; Marshal.Copy(buf, 0, rawBuffer, (int)rawBufferLength); // TODO: check if change from uint to int is possible for rawBufferLength, then remove casting } return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.fsDevice.LogErrorMessage("ReadFile", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int SetFileTime(IntPtr rawFilename, ref ComTypes.FILETIME rawCreationTime, ref ComTypes.FILETIME rawLastAccessTime, ref ComTypes.FILETIME rawLastWriteTime, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { return(ConvReturnCodeToInt(this.fsDevice.SetFileTime(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), ConvDateTimeFromRAW(rawCreationTime), ConvDateTimeFromRAW(rawLastAccessTime), ConvDateTimeFromRAW(rawLastWriteTime)))); } catch (Exception e) { this.fsDevice.LogErrorMessage("SetFileTime", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int GetFileInformation(IntPtr rawFilename, ref FuserDefinition.BY_HANDLE_FILE_INFORMATION rawHandleFileInformation, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { FuserFileInformation fi = new FuserFileInformation(); Win32Returncode ret = this.fsDevice.GetFileInformation(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), fi); if (ret == Win32Returncode.SUCCESS) { if (fi.CreationTime == DateTime.MinValue || fi.LastAccessTime == DateTime.MinValue || fi.LastWriteTime == DateTime.MinValue) { ret = Win32Returncode.DEFAULT_UNKNOWN_ERROR; } } if (ret == Win32Returncode.SUCCESS) { ConvertFileInfoToRAW(fi, ref rawHandleFileInformation); } return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.fsDevice.LogErrorMessage("GetFileInformation", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int WriteFile(IntPtr rawFilename, IntPtr rawBuffer, uint rawNumberOfBytesToWrite, ref uint rawNumberOfBytesWritten, long rawOffset, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { byte[] buf = new byte[rawNumberOfBytesToWrite]; Marshal.Copy(rawBuffer, buf, 0, (int)rawNumberOfBytesToWrite); // TODO: check if change from uint to int is possible for rawNumberOfBytesToWrite, then remove casting uint bytesWritten = 0; Win32Returncode ret = this.fsDevice.WriteFile(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), buf, ref bytesWritten, rawOffset); if (ret == Win32Returncode.SUCCESS) { rawNumberOfBytesWritten = bytesWritten; } return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.fsDevice.LogErrorMessage("WriteFile", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }
public int CreateFile(IntPtr rawFilname, uint rawAccessMode, uint rawShare, uint rawCreationDisposition, uint rawFlagsAndAttributes, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { FuserFileHandler hFile = this.hManager.RegisterFileHandler(GetFilename(rawFilname), ref rawHFile); FuserFileAccess access = FuserFileAccess.None; FileAttributes newFileAttr; try { newFileAttr = (FileAttributes)rawFlagsAndAttributes; } catch { newFileAttr = 0; } FileShare share = FileShare.None; FileMode mode = FileMode.Open; FileOptions options = FileOptions.None; if ((rawAccessMode & FuserDefinition.FILE_READ_DATA) != 0 && (rawAccessMode & FuserDefinition.FILE_WRITE_DATA) != 0) { access = FuserFileAccess.ReadWrite; } else if ((rawAccessMode & FuserDefinition.FILE_WRITE_DATA) != 0) { access = FuserFileAccess.Write; } else if ((rawAccessMode & FuserDefinition.FILE_READ_DATA) != 0) { access = FuserFileAccess.Read; } if ((rawShare & FuserDefinition.FILE_SHARE_READ) != 0) { share = FileShare.Read; } if ((rawShare & FuserDefinition.FILE_SHARE_WRITE) != 0) { share |= FileShare.Write; } if ((rawShare & FuserDefinition.FILE_SHARE_DELETE) != 0) { share |= FileShare.Delete; } switch (rawCreationDisposition) { case FuserDefinition.CREATE_NEW: mode = FileMode.CreateNew; break; case FuserDefinition.CREATE_ALWAYS: mode = FileMode.Create; break; case FuserDefinition.OPEN_EXISTING: mode = FileMode.Open; break; case FuserDefinition.OPEN_ALWAYS: mode = FileMode.OpenOrCreate; break; case FuserDefinition.TRUNCATE_EXISTING: mode = FileMode.Truncate; break; } Win32Returncode ret = this.fsDevice.CreateFile(hFile, access, share, mode, options, newFileAttr); if (hFile.IsDirectory) { rawHFile.IsDirectory = 1; // TODO: directory problem //rawFlagsAndAttributes |= 0x02000000; } if (ret != Win32Returncode.SUCCESS) { this.hManager.RemoveFileHandler(ref rawHFile); } return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.hManager.RemoveFileHandler(ref rawHFile); this.fsDevice.LogErrorMessage("CreateFile", e.Message); return(ConvReturnCodeToInt(Win32Returncode.ERROR_FILE_NOT_FOUND)); } }
public int MoveFile(IntPtr rawFilename, IntPtr rawNewFilename, int rawReplaceIfExisting, ref FuserDefinition.FUSER_FILE_INFO rawHFile) { try { string newFilename = GetFilename(rawNewFilename); Win32Returncode ret = this.fsDevice.MoveFile(this.hManager.GetFileHandler(GetFilename(rawFilename), ref rawHFile), newFilename, (rawReplaceIfExisting != 0)); return(ConvReturnCodeToInt(ret)); } catch (Exception e) { this.fsDevice.LogErrorMessage("MoveFile", e.Message); return(ConvReturnCodeToInt(Win32Returncode.DEFAULT_UNKNOWN_ERROR)); } }