private void CanFileBeDeleted(CallbackFileSystem Sender, CbFsFileInfo fileInfo, CbFsHandleInfo HandleInfo, ref bool CanBeDeleted) { bool canBeDeleted = false; CBFSWinUtil.Invoke("CanFileBeDeleted", () => canBeDeleted = CanFileBeDeleted(fileInfo, HandleInfo)); CanBeDeleted = canBeDeleted; }
private void IsDirectoryEmpty(CallbackFileSystem Sender, CbFsFileInfo directoryInfo, string DirectoryName, ref bool IsEmpty) { bool isEmpty = false; CBFSWinUtil.Invoke("IsDirectoryEmpty", () => isEmpty = IsDirectoryEmpty(directoryInfo, DirectoryName)); IsEmpty = isEmpty; }
public static bool CheckStatus(string productNameCBFS) { bool isInstalled = false; int VersionHigh = 0, VersionLow = 0; SERVICE_STATUS status = new SERVICE_STATUS(); CallbackFileSystem.GetModuleStatus(productNameCBFS, CallbackFileSystem.CBFS_MODULE_DRIVER, ref isInstalled, ref VersionHigh, ref VersionLow, ref status); Log.Fatal("Driver (ver {0}.{1}.{2}.{3}) installed[{4}] for [{5}]", VersionHigh >> 16, VersionHigh & 0xFFFF, VersionLow >> 16, VersionLow & 0xFFFF, isInstalled, productNameCBFS); if (isInstalled) { string state; switch (status.currentState) { case (int)CbFsDriverState.CBFS_SERVICE_CONTINUE_PENDING: state = "continue is pending"; break; case (int)CbFsDriverState.CBFS_SERVICE_PAUSE_PENDING: state = "pause is pending"; break; case (int)CbFsDriverState.CBFS_SERVICE_PAUSED: state = "is paused"; break; case (int)CbFsDriverState.CBFS_SERVICE_RUNNING: state = "is running"; break; case (int)CbFsDriverState.CBFS_SERVICE_START_PENDING: state = "is starting"; break; case (int)CbFsDriverState.CBFS_SERVICE_STOP_PENDING: state = "is stopping"; break; case (int)CbFsDriverState.CBFS_SERVICE_STOPPED: state = "is stopped"; break; default: state = string.Format("in undefined state [{0}]", status.currentState); break; } Log.Fatal("Service state: {0}", state); } else { Log.Fatal("Driver not installed"); } return(isInstalled); }
private void GetVolumeSize(CallbackFileSystem Sender, ref long TotalNumberOfSectors, ref long NumberOfFreeSectors) { Log.Trace("GetVolumeSize IN"); try { GetVolumeSize(out TotalNumberOfSectors, out NumberOfFreeSectors); } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { Log.Trace("GetVolumeSize OUT"); } }
private void GetVolumeId(CallbackFileSystem Sender, ref uint volumeID) { Log.Trace("GetVolumeId IN"); try { volumeID = VolumeId; } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { Log.Trace("GetVolumeId OUT"); } }
private void SetVolumeLabel(CallbackFileSystem Sender, string volumeLabel) { Log.Trace("SetVolumeLabel IN"); try { VolumeLabel = volumeLabel; } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { Log.Trace("SetVolumeLabel OUT"); } }
protected CBFSHandlers() { CbFs = new CallbackFileSystem { OnMount = Mount, OnUnmount = UnMount, OnGetVolumeSize = GetVolumeSize, OnGetVolumeLabel = GetVolumeLabel, OnSetVolumeLabel = SetVolumeLabel, OnGetVolumeId = GetVolumeId, OnCreateFile = CreateFile, OnCleanupFile = CleanupFile, OnOpenFile = OpenFile, OnCloseFile = CloseFile, OnGetFileInfo = GetFileInfo, OnEnumerateDirectory = EnumerateDirectory, OnCloseDirectoryEnumeration = CloseDirectoryEnumeration, OnFlushFile = FlushFile, OnSetAllocationSize = SetAllocationSize, OnSetEndOfFile = SetEndOfFile, OnSetFileAttributes = SetFileAttributes, OnCanFileBeDeleted = CanFileBeDeleted, OnDeleteFile = DeleteFile, OnRenameOrMoveFile = RenameOrMoveFile, OnReadFile = ReadFile, OnWriteFile = WriteFile, OnIsDirectoryEmpty = IsDirectoryEmpty, CallAllOpenCloseCallbacks = true, UseFileCreationFlags = true }; /* * If the file is opened successfully, the opened file is used for the next file open operations, * which happen while the original file handle is opened. Usually this works correctly, but if * the file is opened with different access mode, such scheme is not acceptable. To disable the * described behaviour and have OnOpenFile callback be called every time, * set CallAllOpenCloseCallbacks property to true. * To make use of the security checks you must first set CallAllOpenCloseCallbacks property to true. * */ // UseFileCreationFlags = true // When this property is set to true, the value of dwFlagsAndAttributes // parameter of CreateFile() WinAPI function is propagated to OnCreateFile/OnCloseFile callbacks. }
private void GetFileInfo(CallbackFileSystem Sender, string FileName, ref bool FileExists, ref DateTime CreationTime, ref DateTime LastAccessTime, ref DateTime LastWriteTime, ref long lengthOfFile, ref long AllocationSize, ref CBFS_LARGE_INTEGER FileId, ref uint FileAttributes, ref string ShortFileName, ref string RealFileName) { Log.Trace("GetFileInfo IN"); try { GetFileInfo(FileName, ref FileExists, ref CreationTime, ref LastAccessTime, ref LastWriteTime, ref lengthOfFile, ref AllocationSize, ref FileId, ref FileAttributes, ref ShortFileName, ref RealFileName); } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { Log.Trace("GetFileInfo OUT"); } }
private void ReadFile(CallbackFileSystem Sender, CbFsFileInfo fileInfo, long Position, byte[] Buffer, int BytesToRead, ref int bytesRead) { Log.Trace("ReadFile IN"); uint read = 0; try { ReadFile(fileInfo, Position, Buffer, (uint)BytesToRead, out read); } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { bytesRead = (int)read; Log.Trace("ReadFile OUT"); } }
private void WriteFile(CallbackFileSystem Sender, CbFsFileInfo fileInfo, long Position, byte[] Buffer, int BytesToWrite, ref int bytesWritten) { Log.Trace("WriteFile IN"); uint written = 0; try { WriteFile(fileInfo, Position, Buffer, (uint)BytesToWrite, out written); } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { bytesWritten = (int)written; Log.Trace("WriteFile OUT"); } }
private void EnumerateDirectory(CallbackFileSystem Sender, CbFsFileInfo directoryInfo, CbFsHandleInfo HandleInfo, CbFsDirectoryEnumerationInfo DirectoryEnumerationInfo, string Mask, int Index, [MarshalAs(UnmanagedType.U1)] bool Restart, ref bool FileFound, ref string FileName, ref string ShortFileName, ref DateTime CreationTime, ref DateTime LastAccessTime, ref DateTime LastWriteTime, ref long lengthOfFile, ref long AllocationSize, ref CBFS_LARGE_INTEGER FileId, ref uint FileAttributes) { Log.Trace("EnumerateDirectory IN"); try { EnumerateDirectory(directoryInfo, HandleInfo, DirectoryEnumerationInfo, Mask, Restart, ref FileFound, ref FileName, ref ShortFileName, ref CreationTime, ref LastAccessTime, ref LastWriteTime, ref lengthOfFile, ref AllocationSize, ref FileId, ref FileAttributes); } catch (Exception ex) { CBFSWinUtil.BestAttemptToECBFSError(ex); } finally { Log.Trace("EnumerateDirectory OUT"); } }
private void CloseDirectoryEnumeration(CallbackFileSystem Sender, CbFsFileInfo directoryInfo, CbFsDirectoryEnumerationInfo directoryEnumerationInfo) { CBFSWinUtil.Invoke("CloseDirectoryEnumeration", () => CloseDirectoryEnumeration(directoryInfo, directoryEnumerationInfo)); }
private void SetFileAttributes(CallbackFileSystem Sender, CbFsFileInfo fileInfo, CbFsHandleInfo userContextInfo, DateTime CreationTime, DateTime LastAccessTime, DateTime LastWriteTime, uint FileAttributes) { CBFSWinUtil.Invoke("SetFileAttributes", () => SetFileAttributes(fileInfo, userContextInfo, CreationTime, LastAccessTime, LastWriteTime, FileAttributes)); }
private void SetEndOfFile(CallbackFileSystem Sender, CbFsFileInfo fileInfo, long EndOfFile) { CBFSWinUtil.Invoke("SetEndOfFile", () => SetEndOfFile(fileInfo, EndOfFile)); }
public void RegisterAndInit(string salt, string productNameCbfs, uint threadPoolSize, CbFsStorageType storageType, bool useInternalCaches) { CallbackFileSystem.SetRegistrationKey(salt.FromBuffer()); CallbackFileSystem.Initialize(productNameCbfs); CreateStorage(storageType, threadPoolSize, useInternalCaches); }
private void FlushFile(CallbackFileSystem sender, CbFsFileInfo fileInfo) { CBFSWinUtil.Invoke("FlushFile", () => FlushFile(fileInfo)); }
private void SetAllocationSize(CallbackFileSystem Sender, CbFsFileInfo fileInfo, long AllocationSize) { CBFSWinUtil.Invoke("SetAllocationSize", () => SetAllocationSize(fileInfo, AllocationSize)); }
private void CbFsReadFile( CallbackFileSystem sender, CbFsFileInfo FileInfo, long Position, byte[] Buffer, int BytesToRead, ref int BytesRead ) { //Console.WriteLine("{0}::{1}", "CbFsReadFile", "Event Call....."); //Console.WriteLine("{0}::{1}", "\t FileInfo.FileName", FileInfo.FileName); //Console.WriteLine("{0}::{1}", "\t\t\t\t CbFsReadFile.Position", Position); ACCESS_MASK processId = new ACCESS_MASK() ; sender.GetOriginatorProcessId(ref processId); GCHandle gch = GCHandle.FromIntPtr(FileInfo.UserContext); VirtualFile vfile = (VirtualFile)gch.Target; if (vfile.EndOfFile <= 5242880) { // 5242880 5MB // 한번에 받기 if ( !vfile.IsGetStreamToRemote ) { MemoryStream ms = new MemoryStream(); g_OccamFile.ReadFile(FileInfo.FileName, ref ms); byte[] buffer = new byte[8192]; int bytesRead; long ps = Position; int readByte = 0; ms.Seek(0, SeekOrigin.Begin); while ((bytesRead = ms.Read(buffer, 0, buffer.Length)) > 0) { vfile.Write(buffer, ps, bytesRead, ref readByte); ps += readByte; } vfile.IsGetStreamToRemote = true; } vfile.Read(Buffer, Position, BytesToRead, ref BytesRead); } else { if (!vfile.CanReadToCache(Position, BytesToRead)) { //vfile.CloseAndNewCache(); int readSize = (int)BytesToRead * 200; if (vfile.EndOfFile < readSize) readSize = (int)vfile.EndOfFile; byte[] readBuffer = new byte[readSize]; int bytesRead1 = 0; int bytesRead2 = 0; g_OccamFile.ReadFile(FileInfo.FileName, readBuffer, Position, readSize, ref bytesRead1); vfile.WriteCache(readBuffer, Position, bytesRead1, ref bytesRead2); } vfile.ReadCache(Buffer, Position, BytesToRead, ref BytesRead); /* if (!vfile.CanReadToStream(Position, BytesToRead)) { vfile.CloseReadFileStream(); int bytesToReadStream = (vfile.EndOfFile > (Position + BytesToRead * 100)) ? (int)(BytesToRead * 100) : (int)(vfile.EndOfFile - Position); g_OccamFile.CreateReadFileStream(FileInfo.FileName, Position, bytesToReadStream, ref vfile.ReadFileStreamOfRemote); vfile.SetStreamInfo(Position, Position + (long) bytesToReadStream); } bool IsEnd = (vfile.EndOfFile == (Position + BytesToRead)) ? true : false; vfile.Read(Buffer, Position, BytesToRead, ref BytesRead, IsEnd); */ //g_OccamFile.ReadFile(FileInfo.FileName, Buffer, Position, BytesToRead, ref BytesRead); /* // 캐싱 함 long cachedSize = vfile.GetCachedSize(); if (cachedSize >= (Position + BytesToRead)) { // 캐싱되어 있음. vfile.Read(Buffer, Position, BytesToRead, ref BytesRead); } else { // 캐싱 노노 int readSize = (int)BytesToRead * 50; if (vfile.EndOfFile < readSize) readSize = (int)vfile.EndOfFile; byte[] readBuffer = new byte[readSize]; int bytesRead1 = 0; int bytesRead2 = 0; g_OccamFile.ReadFile(FileInfo.FileName, readBuffer, Position, readSize, ref bytesRead1); vfile.Write(readBuffer, Position, bytesRead1, ref bytesRead2); vfile.Read(Buffer, Position, BytesToRead, ref BytesRead); }*/ } // 기본 다운로드는 스트림 연결 // 또는 작은 파일은 파일 전체를 한번에 받아 캐싱하고 이후에 콜백에 요청만큼 던져준다. // 큰 파일은 }
private void DeleteFile(CallbackFileSystem Sender, CbFsFileInfo fileInfo) { CBFSWinUtil.Invoke("DeleteFile", () => DeleteFile(fileInfo)); }
private void CloseFile(CallbackFileSystem Sender, CbFsFileInfo fileInfo, CbFsHandleInfo userContextInfo) { CBFSWinUtil.Invoke("CloseFile", () => CloseFile(fileInfo, userContextInfo)); }
private void OpenFile(CallbackFileSystem Sender, string FileName, uint DesiredAccess, uint fileAttributes, uint ShareMode, CbFsFileInfo fileInfo, CbFsHandleInfo userContextInfo) { CBFSWinUtil.Invoke("OpenFile", () => OpenFile(FileName, DesiredAccess, fileAttributes, ShareMode, fileInfo, userContextInfo)); }
private void UnMount(CallbackFileSystem Sender) { CBFSWinUtil.Invoke("UnMount", UnMount); }
private void RenameOrMoveFile(CallbackFileSystem Sender, CbFsFileInfo fileInfo, string NewFileName) { CBFSWinUtil.Invoke("RenameOrMoveFile", () => RenameOrMoveFile(fileInfo, NewFileName)); }
private void VDiskForm_Load(object sender, EventArgs e) { mCbFs = new CallbackFileSystem(); mCbFs.OnMount = new CbFsMountEvent(CbFsMount); mCbFs.OnUnmount = new CbFsUnmountEvent(CbFsUnmount); mCbFs.OnGetVolumeSize = new CbFsGetVolumeSizeEvent(CbFsGetVolumeSize); mCbFs.OnGetVolumeLabel = new CbFsGetVolumeLabelEvent(CbFsGetVolumeLabel); mCbFs.OnSetVolumeLabel = new CbFsSetVolumeLabelEvent(CbFsSetVolumeLabel); mCbFs.OnGetVolumeId = new CbFsGetVolumeIdEvent(CbFsGetVolumeId); mCbFs.OnCreateFile = new CbFsCreateFileEvent(CbFsCreateFile); mCbFs.OnOpenFile = new CbFsOpenFileEvent(CbFsOpenFile); mCbFs.OnCloseFile = new CbFsCloseFileEvent(CbFsCloseFile); mCbFs.OnGetFileInfo = new CbFsGetFileInfoEvent(CbFsGetFileInfo); mCbFs.OnEnumerateDirectory = new CbFsEnumerateDirectoryEvent(CbFsEnumerateDirectory); mCbFs.OnCloseDirectoryEnumeration = new CbFsCloseDirectoryEnumerationEvent(CbFsCloseDirectoryEnumeration); mCbFs.OnSetAllocationSize = new CbFsSetAllocationSizeEvent(CbFsSetAllocationSize); mCbFs.OnSetEndOfFile = new CbFsSetEndOfFileEvent(CbFsSetEndOfFile); mCbFs.OnSetFileAttributes = new CbFsSetFileAttributesEvent(CbFsSetFileAttributes); mCbFs.OnCanFileBeDeleted = new CbFsCanFileBeDeletedEvent(CbFsCanFileBeDeleted); mCbFs.OnDeleteFile = new CbFsDeleteFileEvent(CbFsDeleteFile); mCbFs.OnRenameOrMoveFile = new CbFsRenameOrMoveFileEvent(CbFsRenameOrMoveFile); mCbFs.OnReadFile = new CbFsReadFileEvent(CbFsReadFile); mCbFs.OnWriteFile = new CbFsWriteFileEvent(CbFsWriteFile); mCbFs.OnIsDirectoryEmpty = new CbFsIsDirectoryEmptyEvent(CbFsIsDirectoryEmpty); mCbFs.FileCacheEnabled = false; //mCbFs.MaxReadWriteBlockSize //mCbFs.MaxWorkerThreadCount = 2; //mCbFs.MinWorkerThreadCount = 2; UpdateDriverStatus(); }