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 FSException(Win32Returncode errorcode) : base(errorcode.ToString()) { this.pError = errorcode; if (this.pError == Win32Returncode.SUCCESS) { this.pError = Win32Returncode.DEFAULT_UNKNOWN_ERROR; } }
private Win32Returncode pLastErrorCode; // always returns an error code that best fits. public PathResolver(IFuserFilesystemDirectory root, string path) { this.pPath = null; this.pFileitem = null; this.pPathInvalid = true; this.pLastErrorCode = Win32Returncode.DEFAULT_UNKNOWN_ERROR; resolve(root, path); }
public FuserPathResolveResult(IFuserFilesystemDirectory root, string path) { this.path = path; this.root = root; this.curDir = root; this.pItemname = ""; this.pHasError = false; this.errorcode = Win32Returncode.SUCCESS; }
public FuserPathResolveResult(FSException exception) { this.path = null; this.root = null; this.curDir = null; this.pItemname = ""; this.pHasError = true; this.errorcode = exception.Error; }
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)); } }
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 Win32Returncode UnlockFile(FuserFileHandler hFile, long offset, long length) { string funcname = "UnlockFile"; string param = ""; try { //param = ; Win32Returncode r = sourceSystem.UnlockFile(hFile, offset, length); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode GetFileInformation(FuserFileHandler hFile, FuserFileInformation fileinfo) { string funcname = "GetFileInformation"; string param = ""; try { //param = ; Win32Returncode r = sourceSystem.GetFileInformation(hFile, fileinfo); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode WriteFile(FuserFileHandler hFile, byte[] buffer, ref uint writtenBytes, long offset) { string funcname = "WriteFile"; string param = ""; try { param = buffer.Length + ";" + writtenBytes + ";" + offset; Win32Returncode r = sourceSystem.WriteFile(hFile, buffer, ref writtenBytes, offset); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode SetFileAttributes(FuserFileHandler hFile, FileAttributes attr) { string funcname = "SetFileAttributes"; string param = ""; try { //param = ; Win32Returncode r = sourceSystem.SetFileAttributes(hFile, attr); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode FindFiles(FuserFileHandler hFile, List <FuserFileInformation> files) { string funcname = "FindFiles"; string param = ""; try { //param = ; Win32Returncode r = sourceSystem.FindFiles(hFile, files); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode CreateFile(FuserFileHandler hFile, FuserFileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attribut) { string funcname = "CreateFile"; string param = ""; try { param = access + ";" + share + ";" + mode + ";" + options + " Attribute: " + attribut; Win32Returncode r = sourceSystem.CreateFile(hFile, access, share, mode, options, attribut); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode SetFileTime(FuserFileHandler hFile, DateTime CreationTime, DateTime LastAccessTime, DateTime LastWriteTime) { string funcname = "SetFileTime"; string param = ""; try { param = CreationTime + ";" + LastAccessTime + ";" + LastWriteTime; Win32Returncode r = sourceSystem.SetFileTime(hFile, CreationTime, LastAccessTime, LastWriteTime); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode Mount(string MountPoint, string RawDevice) { string funcname = "Mount"; string param = "MP: " + MountPoint + " DN: " + RawDevice; try { //param = ; Win32Returncode r = sourceSystem.Mount(MountPoint, RawDevice); LogEvent(funcname, r, param, null); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, null); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode GetDiskFreeSpace(ref ulong freeBytesAvailable, ref ulong totalBytes, ref ulong totalFreeBytes) { string funcname = "GetDiskFreeSpace"; string param = ""; try { param = freeBytesAvailable + ";" + totalBytes + ";" + totalFreeBytes; Win32Returncode r = sourceSystem.GetDiskFreeSpace(ref freeBytesAvailable, ref totalBytes, ref totalFreeBytes); LogEvent(funcname, r, param, null); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, null); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
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 Win32Returncode SetAllocationSize(FuserFileHandler hFile, long length) { string funcname = "SetAllocationSize"; string param = ""; try { param = length.ToString(); Win32Returncode r = sourceSystem.SetAllocationSize(hFile, length); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode MoveFile(FuserFileHandler hFile, string newFilename, bool replace) { string funcname = "MoveFile"; string param = ""; try { param = newFilename + ";" + replace; Win32Returncode r = sourceSystem.MoveFile(hFile, newFilename, replace); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(Win32Returncode.DEFAULT_UNKNOWN_ERROR); } }
public Win32Returncode OpenDirectory(FuserFileHandler hFile) { string funcname = "OpenDirectory"; string param = ""; try { //param = ; Win32Returncode r = sourceSystem.OpenDirectory(hFile); LogEvent(funcname, r, param, hFile); return(r); } catch (Exception e) { LogEvent(funcname, Win32Returncode.DEFAULT_UNKNOWN_ERROR, param, hFile); LogException(funcname, e); return(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 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)); } }
private void LogEvent(string funcName, Win32Returncode returnValue, string Param, FuserFileHandler hFile) { string filename; if (hFile == null) { filename = ""; } else { filename = hFile.filename; } LogMessage(funcName + "[" + (returnValue.ToString() + " " + Param).Trim() + "]: " + filename); //if (filename == @"\test") { // LogMessage(funcName + "[" + (returnValue + " " + Param).Trim() + "]: " + filename); //} //LogMessage(funcName + ": " + InfoToString(info)); }
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 int ConvReturnCodeToInt(Win32Returncode rcode) { // TODO: remove this method return(-(int)rcode); }
private void resolve(IFuserFilesystemDirectory root, string path) { FuserPathResolveResult vpr = null; try { vpr = ResolvePath(root, path); this.pPath = vpr; if (vpr.returncode != Win32Returncode.SUCCESS) { this.pPathInvalid = true; this.pLastErrorCode = vpr.returncode; return; } } catch { // should never occur this.pPathInvalid = true; this.pLastErrorCode = Win32Returncode.ERROR_PATH_NOT_FOUND; this.pPath = null; return; } if (vpr != null) { if (vpr.HasError) { vpr = null; } } if (vpr != null) { if (vpr.returncode != Win32Returncode.SUCCESS) { vpr = null; } } if (vpr == null) { this.pPathInvalid = true; this.pLastErrorCode = Win32Returncode.ERROR_PATH_NOT_FOUND; this.pPath = null; } else { this.pPathInvalid = false; this.pLastErrorCode = Win32Returncode.DEFAULT_UNKNOWN_ERROR; this.pFileitem = null; if (vpr.currentDirectory == root && vpr.itemname == "") { this.pFileitem = root; } else { if (vpr.itemname == "") { // path not found this.pLastErrorCode = Win32Returncode.ERROR_PATH_NOT_FOUND; this.pPathInvalid = true; } else { try { lock (vpr.currentDirectory) { this.pFileitem = vpr.currentDirectory.GetItem(vpr.itemname); } } catch { this.pFileitem = null; } } } } }
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)); } }