/// <summary> /// Creates an instance of a flow and registers it with this IoFlowRuntime instance. /// </summary> /// <param name="flowId">An id unique to this flow e.g. from GetNextFreeFlowId(). </param> /// <param name="context">Additional context you want to keep for this flow.</param> /// <param name="accountName">A Windows account name for use in I/O classification.</param> /// <param name="sid">A Windows SID for use in I/O classification.</param> /// <param name="fileName">A windows file name used in I/O classification.</param> /// <param name="callbackPreCreate">Optional PreOp callback on CREATE IRPs.</param> /// <param name="callbackPostCreate">Optional PostOp callback on CREATE IRPs.</param> /// <param name="callbackPreRead">Optional PreOp callback on READ IRPs.</param> /// <param name="callbackPostRead">Optional PostOp callback on READ IRPs.</param> /// <param name="callbackPreWrite">Optional PreOp callback on WRITE IRPs.</param> /// <param name="callbackPostWrite">Optional PostOp callback on READ IRPs.</param> /// <param name="callbackPreCleanup">Optional PreOp callback on CLEANUP IRPs.</param> /// <param name="callbackPostCleanup">Optional PostOp callback on CLEANUP IRPs.</param> /// <param name="callbackPreLockControl">Optional PreOp callback on LOCKCONTROL IRPs.</param> public IoFlow( uint flowId, object context, string accountName, SecurityIdentifier sid, string fileName, CallbackPreCreate callbackPreCreate, CallbackPostCreate callbackPostCreate, CallbackPreRead callbackPreRead, CallbackPostRead callbackPostRead, CallbackPreWrite callbackPreWrite, CallbackPostWrite callbackPostWrite, CallbackPreCleanup callbackPreCleanup, CallbackPostCleanup callbackPostCleanup, CallbackPreLockControl callbackPreLockControl) { this.flowId = flowId; this.context = context; this.accountName = accountName; this.fileName = fileName; this.sid = sid; flags = 0x00; flags |= (callbackPreCreate != null ? (uint)IoFlowFlags.PreCreate : flags); flags |= (callbackPostCreate != null ? (uint)IoFlowFlags.PostCreate : flags); flags |= (callbackPreRead != null ? (uint)IoFlowFlags.PreRead : flags); flags |= (callbackPostRead != null ? (uint)IoFlowFlags.PostRead : flags); flags |= (callbackPreWrite != null ? (uint)IoFlowFlags.PreWrite : flags); flags |= (callbackPostWrite != null ? (uint)IoFlowFlags.PostWrite : flags); flags |= (callbackPreCleanup != null ? (uint)IoFlowFlags.PreCleanup : flags); flags |= (callbackPostCleanup != null ? (uint)IoFlowFlags.PostCleanup : flags); flags |= (callbackPreLockControl != null ? (uint)IoFlowFlags.PreLockControl : flags); this.callbackPreCreate = (callbackPreCreate != null ? callbackPreCreate : InvalidPreCreate); this.callbackPostCreate = (callbackPostCreate != null ? callbackPostCreate : InvalidPostCreate); this.callbackPreRead = (callbackPreRead != null ? callbackPreRead : InvalidPreRead); this.callbackPostRead = (callbackPostRead != null ? callbackPostRead : InvalidPostRead); this.callbackPreWrite = (callbackPreWrite != null ? callbackPreWrite : InvalidPreWrite); this.callbackPostWrite = (callbackPostWrite != null ? callbackPostWrite : InvalidPostWrite); this.callbackPreCleanup = (callbackPreCleanup != null ? callbackPreCleanup : InvalidPreCleanup); this.callbackPostCleanup = (callbackPostCleanup != null ? callbackPostCleanup : InvalidPostCleanup); this.callbackPreLockControl = (callbackPreLockControl != null ? callbackPreLockControl : InvalidPreLockControl); IrpList = new Queue <IRP>(); }
/// <summary> /// Creates an instance of a flow and registers it with this IoFlowRuntime instance. /// </summary> /// <param name="flowId">An id unique to this flow e.g. from GetNextFreeFlowId(). </param> /// <param name="context">Additional context you want to keep for this flow.</param> /// <param name="accountName">A Windows account name for use in I/O classification.</param> /// <param name="sid">A Windows SID for use in I/O classification.</param> /// <param name="fileName">A windows file name used in I/O classification.</param> /// <param name="callbackPreCreate">Optional PreOp callback on CREATE IRPs.</param> /// <param name="callbackPostCreate">Optional PostOp callback on CREATE IRPs.</param> /// <param name="callbackPreRead">Optional PreOp callback on READ IRPs.</param> /// <param name="callbackPostRead">Optional PostOp callback on READ IRPs.</param> /// <param name="callbackPreWrite">Optional PreOp callback on WRITE IRPs.</param> /// <param name="callbackPostWrite">Optional PostOp callback on READ IRPs.</param> /// <param name="callbackPreCleanup">Optional PreOp callback on CLEANUP IRPs.</param> /// <param name="callbackPostCleanup">Optional PostOp callback on CLEANUP IRPs.</param> /// <param name="callbackPreLockControl">Optional PreOp callback on LOCKCONTROL IRPs.</param> public IoFlow( uint flowId, object context, string accountName, SecurityIdentifier sid, string fileName, CallbackPreCreate callbackPreCreate, CallbackPostCreate callbackPostCreate, CallbackPreRead callbackPreRead, CallbackPostRead callbackPostRead, CallbackPreWrite callbackPreWrite, CallbackPostWrite callbackPostWrite, CallbackPreCleanup callbackPreCleanup, CallbackPostCleanup callbackPostCleanup, CallbackPreLockControl callbackPreLockControl) { this.flowId = flowId; this.context = context; this.accountName = accountName; this.fileName = fileName; this.sid = sid; flags = 0x00; flags |= (callbackPreCreate != null ? (uint)IoFlowFlags.PreCreate : flags); flags |= (callbackPostCreate != null ? (uint)IoFlowFlags.PostCreate : flags); flags |= (callbackPreRead != null ? (uint)IoFlowFlags.PreRead : flags); flags |= (callbackPostRead != null ? (uint)IoFlowFlags.PostRead : flags); flags |= (callbackPreWrite != null ? (uint)IoFlowFlags.PreWrite : flags); flags |= (callbackPostWrite != null ? (uint)IoFlowFlags.PostWrite : flags); flags |= (callbackPreCleanup != null ? (uint)IoFlowFlags.PreCleanup : flags); flags |= (callbackPostCleanup != null ? (uint)IoFlowFlags.PostCleanup : flags); flags |= (callbackPreLockControl != null ? (uint)IoFlowFlags.PreLockControl : flags); this.callbackPreCreate = (callbackPreCreate != null ? callbackPreCreate : InvalidPreCreate); this.callbackPostCreate = (callbackPostCreate != null ? callbackPostCreate : InvalidPostCreate); this.callbackPreRead = ( callbackPreRead != null ? callbackPreRead : InvalidPreRead ); this.callbackPostRead = ( callbackPostRead != null ? callbackPostRead : InvalidPostRead ); this.callbackPreWrite = ( callbackPreWrite != null ? callbackPreWrite : InvalidPreWrite ); this.callbackPostWrite = ( callbackPostWrite != null ? callbackPostWrite : InvalidPostWrite ); this.callbackPreCleanup = (callbackPreCleanup != null ? callbackPreCleanup : InvalidPreCleanup); this.callbackPostCleanup = (callbackPostCleanup != null ? callbackPostCleanup : InvalidPostCleanup); this.callbackPreLockControl = (callbackPreLockControl != null ? callbackPreLockControl : InvalidPreLockControl); IrpList = new Queue<IRP>(); }
/// <summary> /// Creates an IoFlow structure in runtime and corresponding structures (Flow and RAP) /// in the driver. /// </summary> /// <param name="accountName">A valid NT security account of form EUROPE\gregos.</param> /// <param name="fileName">A valid file name of form C:\tmp\gregos.txt or \Device\HarddiskVolumen\tmp\gregos.txt</param> /// <param name="callbackPreCreate">Callback func to invoke for IRPs on PreCreate path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostCreate">Callback func to invoke for IRPs on PostCreate path. /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="callbackPreRead">Callback func to invoke for IRPs on PreRead path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostRead">Callback func to invoke for IRPs on PostRead path /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="callbackPreWrite">Callback func to invoke for IRPs on PreWrite path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostWrite">Callback func to invoke for IRPs on PostWrite path. /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="callbackPreCleanup">Callback func to invoke for IRPs on PreCleanup path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostCreate">Callback func to invoke for IRPs on PostCleanup path. /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="context">Some object reference of your own for additional state associated with thie IoFlow</param> /// <returns></returns> public IoFlow CreateFlow( uint flowId, string accountName, string fileName, CallbackPreCreate callbackPreCreate, CallbackPostCreate callbackPostCreate, CallbackPreRead callbackPreRead, CallbackPostRead callbackPostRead, CallbackPreWrite callbackPreWrite, CallbackPostWrite callbackPostWrite, CallbackPreCleanup callbackPreCleanup, CallbackPostCleanup callbackPostCleanup, CallbackPreLockControl callbackPreLockControl, object context) { IoFlow ioFlow = null; // // Validate fileName, transforming drive letters to volume names. // fileName = fileName.ToLower(); string origFilename = fileName; if (string.IsNullOrEmpty(fileName) || string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentNullException("fileName"); } else if (fileName.Length < 2) { throw new ArgumentOutOfRangeException("fileName", "too short"); } else if (fileName.Substring(1, 1).Equals(@":")) { string driveName = fileName.Substring(0, 2); // think "C:" string deviceName = ""; if (DriveNameToVolumeName.TryGetValue(driveName, out deviceName)) { fileName = deviceName + fileName.Substring(2); } } if (fileName.ToLower().StartsWith(DeviceMup.ToLower())) { Debug.Assert(0 == 1); //XXXIS: don't use \device\mup in the paths in the config file } else if (fileName.ToLower().StartsWith(RemoteDeviceSlash.ToLower())) { fileName = DeviceMup + fileName; } else if (fileName.ToLower().StartsWith(RemoteDeviceDoubleSlash.ToLower())) { fileName = DeviceMup + fileName.Substring(1); } else if (!fileName.ToLower().StartsWith(DeviceHarddiskVolume)) { throw new ArgumentException(@"must be format e.g. C: or \Device\HarddiskVolume", "fileName"); } #if gregos // "XXXET: not used, just for testing" crashes on launch due to FileToBlock.dll not found // for lock drives, test physical offset code // XXXET: not used, just for testing if (fileName.Substring(1, 1).Equals(@":") || origFilename.ToLower().StartsWith(DeviceHarddiskVolume)) { if (origFilename.ToLower().StartsWith(DeviceHarddiskVolume)) { origFilename = getDriveLetterFileName(origFilename); } Int64 poffset = FileToBlock.GetPhysicalOffset(origFilename); Console.WriteLine("File {0} starts in physical offset {1}", origFilename, poffset); } #endif // // Get SID for the given account name. // SecurityIdentifier sid = SidLookup(accountName); // // Create IoFlow object. // LockIoFlow.EnterWriteLock(); try { ioFlow = new IoFlow(flowId, context, accountName, sid, fileName, callbackPreCreate, callbackPostCreate, callbackPreRead, callbackPostRead, callbackPreWrite, callbackPostWrite, callbackPreCleanup, callbackPostCleanup, callbackPreLockControl); DictIoFlow.Add(flowId, ioFlow); Driver.CreateFlow.Request(hControlPort, TenantId, flowId, ioFlow.Flags); Driver.CreateRap.Request(hControlPort, TenantId, flowId, accountName, sid, fileName); } catch (ExceptionIoFlow) { DriverReset(); throw; } LockIoFlow.ExitWriteLock(); return(ioFlow); }
/// <summary> /// Creates an IoFlow structure in runtime and corresponding structures (Flow and RAP) /// in the driver. /// </summary> /// <param name="accountName">A valid NT security account of form EUROPE\gregos.</param> /// <param name="fileName">A valid file name of form C:\tmp\gregos.txt or \Device\HarddiskVolumen\tmp\gregos.txt</param> /// <param name="callbackPreCreate">Callback func to invoke for IRPs on PreCreate path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostCreate">Callback func to invoke for IRPs on PostCreate path. /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="callbackPreRead">Callback func to invoke for IRPs on PreRead path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostRead">Callback func to invoke for IRPs on PostRead path /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="callbackPreWrite">Callback func to invoke for IRPs on PreWrite path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostWrite">Callback func to invoke for IRPs on PostWrite path. /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="callbackPreCleanup">Callback func to invoke for IRPs on PreCleanup path. /// Corresponds to an IFS Minifilter PRE_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551109(v=vs.85).aspx</param> /// <param name="callbackPostCreate">Callback func to invoke for IRPs on PostCleanup path. /// Corresponds to an IFS Minifilter POST_OPERATION callback ref http://msdn.microsoft.com/en-us/library/windows/hardware/ff551107(v=vs.85).aspx</param> /// <param name="context">Some object reference of your own for additional state associated with thie IoFlow</param> /// <returns></returns> public IoFlow CreateFlow( uint flowId, string accountName, string fileName, CallbackPreCreate callbackPreCreate, CallbackPostCreate callbackPostCreate, CallbackPreRead callbackPreRead, CallbackPostRead callbackPostRead, CallbackPreWrite callbackPreWrite, CallbackPostWrite callbackPostWrite, CallbackPreCleanup callbackPreCleanup, CallbackPostCleanup callbackPostCleanup, CallbackPreLockControl callbackPreLockControl, object context) { IoFlow ioFlow = null; // // Validate fileName, transforming drive letters to volume names. // fileName = fileName.ToLower(); string origFilename = fileName; if (string.IsNullOrEmpty(fileName) || string.IsNullOrWhiteSpace(fileName)) throw new ArgumentNullException("fileName"); else if (fileName.Length < 2) throw new ArgumentOutOfRangeException("fileName", "too short"); else if (fileName.Substring(1, 1).Equals(@":")) { string driveName = fileName.Substring(0, 2); // think "C:" string deviceName = ""; if (DriveNameToVolumeName.TryGetValue(driveName, out deviceName)) fileName = deviceName + fileName.Substring(2); } if (fileName.ToLower().StartsWith(DeviceMup.ToLower())) { Debug.Assert(0 == 1); //XXXIS: don't use \device\mup in the paths in the config file } else if (fileName.ToLower().StartsWith(RemoteDeviceSlash.ToLower())) { fileName = DeviceMup + fileName; } else if (fileName.ToLower().StartsWith(RemoteDeviceDoubleSlash.ToLower())) { fileName = DeviceMup + fileName.Substring(1); } else if (!fileName.ToLower().StartsWith(DeviceHarddiskVolume)) throw new ArgumentException(@"must be format e.g. C: or \Device\HarddiskVolume", "fileName"); #if gregos // "XXXET: not used, just for testing" crashes on launch due to FileToBlock.dll not found // for lock drives, test physical offset code // XXXET: not used, just for testing if (fileName.Substring(1, 1).Equals(@":") || origFilename.ToLower().StartsWith(DeviceHarddiskVolume)) { if (origFilename.ToLower().StartsWith(DeviceHarddiskVolume)) { origFilename = getDriveLetterFileName(origFilename); } Int64 poffset = FileToBlock.GetPhysicalOffset(origFilename); Console.WriteLine("File {0} starts in physical offset {1}", origFilename, poffset); } #endif // // Get SID for the given account name. // SecurityIdentifier sid = SidLookup(accountName); // // Create IoFlow object. // LockIoFlow.EnterWriteLock(); try { ioFlow = new IoFlow(flowId, context, accountName, sid, fileName, callbackPreCreate, callbackPostCreate, callbackPreRead, callbackPostRead, callbackPreWrite, callbackPostWrite, callbackPreCleanup, callbackPostCleanup, callbackPreLockControl); DictIoFlow.Add(flowId, ioFlow); Driver.CreateFlow.Request(hControlPort, TenantId, flowId, ioFlow.Flags); Driver.CreateRap.Request(hControlPort, TenantId, flowId, accountName, sid, fileName); } catch (ExceptionIoFlow) { DriverReset(); throw; } LockIoFlow.ExitWriteLock(); return ioFlow; }