本文整理汇总了C++中IoGetCurrentIrpStackLocation函数的典型用法代码示例。如果您正苦于以下问题:C++ IoGetCurrentIrpStackLocation函数的具体用法?C++ IoGetCurrentIrpStackLocation怎么用?C++ IoGetCurrentIrpStackLocation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IoGetCurrentIrpStackLocation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DokanEventWrite
// user assinged bigger buffer that is enough to return WriteEventContext
NTSTATUS
DokanEventWrite(
__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp
)
{
KIRQL oldIrql;
PLIST_ENTRY thisEntry, nextEntry, listHead;
PIRP_ENTRY irpEntry;
PDokanVCB vcb;
PEVENT_INFORMATION eventInfo;
PIRP writeIrp;
eventInfo = (PEVENT_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
ASSERT(eventInfo != NULL);
DDbgPrint("==> DokanEventWrite [EventInfo #%X]\n", eventInfo->SerialNumber);
vcb = DeviceObject->DeviceExtension;
if (GetIdentifierType(vcb) != VCB) {
return STATUS_INVALID_PARAMETER;
}
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
KeAcquireSpinLock(&vcb->Dcb->PendingIrp.ListLock, &oldIrql);
// search corresponding write IRP through pending IRP list
listHead = &vcb->Dcb->PendingIrp.ListHead;
for (thisEntry = listHead->Flink; thisEntry != listHead; thisEntry = nextEntry) {
PIO_STACK_LOCATION writeIrpSp, eventIrpSp;
PEVENT_CONTEXT eventContext;
ULONG info = 0;
NTSTATUS status;
nextEntry = thisEntry->Flink;
irpEntry = CONTAINING_RECORD(thisEntry, IRP_ENTRY, ListEntry);
// check whehter this is corresponding IRP
//DDbgPrint("SerialNumber irpEntry %X eventInfo %X\n", irpEntry->SerialNumber, eventInfo->SerialNumber);
if (irpEntry->SerialNumber != eventInfo->SerialNumber) {
continue;
}
// do NOT free irpEntry here
writeIrp = irpEntry->Irp;
if (writeIrp == NULL) {
// this IRP has already been canceled
ASSERT(irpEntry->CancelRoutineFreeMemory == FALSE);
DokanFreeIrpEntry(irpEntry);
continue;
}
if (IoSetCancelRoutine(writeIrp, DokanIrpCancelRoutine) == NULL) {
//if (IoSetCancelRoutine(writeIrp, NULL) != NULL) {
// Cancel routine will run as soon as we release the lock
InitializeListHead(&irpEntry->ListEntry);
irpEntry->CancelRoutineFreeMemory = TRUE;
continue;
}
writeIrpSp = irpEntry->IrpSp;
eventIrpSp = IoGetCurrentIrpStackLocation(Irp);
ASSERT(writeIrpSp != NULL);
ASSERT(eventIrpSp != NULL);
eventContext = (PEVENT_CONTEXT)writeIrp->Tail.Overlay.DriverContext[DRIVER_CONTEXT_EVENT];
ASSERT(eventContext != NULL);
// short of buffer length
if (eventIrpSp->Parameters.DeviceIoControl.OutputBufferLength
< eventContext->Length) {
DDbgPrint(" EventWrite: STATUS_INSUFFICIENT_RESOURCE\n");
status = STATUS_INSUFFICIENT_RESOURCES;
} else {
PVOID buffer;
//DDbgPrint(" EventWrite CopyMemory\n");
//DDbgPrint(" EventLength %d, BufLength %d\n", eventContext->Length,
// eventIrpSp->Parameters.DeviceIoControl.OutputBufferLength);
if (Irp->MdlAddress)
buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
else
buffer = Irp->AssociatedIrp.SystemBuffer;
ASSERT(buffer != NULL);
RtlCopyMemory(buffer, eventContext, eventContext->Length);
info = eventContext->Length;
status = STATUS_SUCCESS;
}
DokanFreeEventContext(eventContext);
writeIrp->Tail.Overlay.DriverContext[DRIVER_CONTEXT_EVENT] = 0;
//.........这里部分代码省略.........
示例2: DriverDeviceControl
NTSTATUS
DriverDeviceControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
NTSTATUS Status = STATUS_UNSUCCESSFUL;
PIO_STACK_LOCATION IrpSp;
ULONG IOControlCode = 0;
ULONG dwBytesWritten = 0;
PCHAR pInBuf = NULL, pOutBuf = NULL;
unsigned int _cpu_thread_id = 0;
unsigned int new_cpu_thread_id = 0;
ULONG _num_active_cpus = 0;
KAFFINITY _kaffinity = 0;
UINT32 core_id = 0;
//
// Get the current IRP stack location of this request
//
IrpSp = IoGetCurrentIrpStackLocation (Irp);
IOControlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
DbgPrint( "[chipsec] >>>>>>>>>> IOCTL >>>>>>>>>>\n" );
DbgPrint( "[chipsec] DeviceObject = 0x%x IOCTL = 0x%x\n", DeviceObject, IOControlCode );
DbgPrint( "[chipsec] InputBufferLength = 0x%x, OutputBufferLength = 0x%x\n", IrpSp->Parameters.DeviceIoControl.InputBufferLength, IrpSp->Parameters.DeviceIoControl.OutputBufferLength );
//
// CPU thread ID
//
_num_active_cpus = KeQueryActiveProcessorCount( NULL );
_kaffinity = KeQueryActiveProcessors();
_cpu_thread_id = KeGetCurrentProcessorNumber();
DbgPrint( "[chipsec] Active CPU threads : %d (KeNumberProcessors = %d)\n", _num_active_cpus, KeNumberProcessors );
DbgPrint( "[chipsec] Active CPU mask (KAFFINITY): 0x%08X\n", _kaffinity );
DbgPrint( "[chipsec] Current CPU thread : %d\n", _cpu_thread_id );
//
// Switch on the IOCTL code that is being requested by the user. If the
// operation is a valid one for this device do the needful.
//
Irp -> IoStatus.Information = 0;
switch( IOControlCode )
{
case READ_PCI_CFG_REGISTER:
{
DWORD val;
BYTE size = 0;
WORD bdf[4];
BYTE bus = 0, dev = 0, fun = 0, off = 0;
DbgPrint( "[chipsec] > READ_PCI_CFG_REGISTER\n" );
RtlCopyBytes( bdf,Irp->AssociatedIrp.SystemBuffer, 4*sizeof(WORD) );
RtlCopyBytes( &size, (BYTE*)Irp->AssociatedIrp.SystemBuffer + 4*sizeof(WORD), sizeof(BYTE) );
bus = (UINT8)bdf[0];
dev = (UINT8)bdf[1];
fun = (UINT8)bdf[2];
off = (UINT8)bdf[3];
if( 1 != size && 2 != size && 4 != size)
{
DbgPrint( "[chipsec] ERROR: STATUS_INVALID_PARAMETER\n" );
Status = STATUS_INVALID_PARAMETER;
break;
}
val = ReadPCICfg( bus, dev, fun, off, size );
IrpSp->Parameters.Read.Length = size;
RtlCopyBytes( Irp->AssociatedIrp.SystemBuffer, (VOID*)&val, size );
DbgPrint( "[chipsec][READ_PCI_CFG_REGISTER] B/D/F: %#04x/%#04x/%#04x, OFFSET: %#04x, value = %#010x (size = 0x%x)\n", bus, dev, fun, off, val, size );
dwBytesWritten = IrpSp->Parameters.Read.Length;
Status = STATUS_SUCCESS;
break;
}
case WRITE_PCI_CFG_REGISTER:
{
DWORD val = 0;
WORD bdf[6];
BYTE bus = 0, dev = 0, fun = 0, off = 0;
BYTE size = 0;
DbgPrint( "[chipsec] > WRITE_PCI_CFG_REGISTER\n" );
RtlCopyBytes( bdf, Irp->AssociatedIrp.SystemBuffer, 6 * sizeof(WORD) );
bus = (UINT8)bdf[0];
dev = (UINT8)bdf[1];
fun = (UINT8)bdf[2];
off = (UINT8)bdf[3];
RtlCopyBytes( &size, (BYTE*)Irp->AssociatedIrp.SystemBuffer + 6*sizeof(WORD), sizeof(BYTE) );
val = ((DWORD)bdf[5] << 16) | bdf[4];
DbgPrint( "[chipsec][WRITE_PCI_CFG_REGISTER] B/D/F: %#02x/%#02x/%#02x, OFFSET: %#02x, value = %#010x (size = %#02x)\n", bus, dev, fun, off, val, size );
WritePCICfg( bus, dev, fun, off, size, val );
Status = STATUS_SUCCESS;
break;
}
case IOCTL_READ_PHYSMEM:
{
//.........这里部分代码省略.........
示例3: HelloDDKDeviceIOControl
NTSTATUS HelloDDKDeviceIOControl(IN PDEVICE_OBJECT pDevObj,
IN PIRP pIrp)
{
NTSTATUS status = STATUS_SUCCESS;
KdPrint(("Enter HelloDDKDeviceIOControl\n"));
//得到当前堆栈
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(pIrp);
//得到输入缓冲区大小
ULONG cbin = stack->Parameters.DeviceIoControl.InputBufferLength;
//得到输出缓冲区大小
ULONG cbout = stack->Parameters.DeviceIoControl.OutputBufferLength;
//得到IOCTL码
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
ULONG info = 0;
switch (code)
{ // process request
case READ_PORT:
{
KdPrint(("READ_PORT\n"));
//缓冲区方式IOCTL
//显示输入缓冲区数据
PULONG InputBuffer = (PULONG)pIrp->AssociatedIrp.SystemBuffer;
ULONG port = (ULONG)(*InputBuffer);
InputBuffer++;
UCHAR method = (UCHAR)(*InputBuffer);
KdPrint(("port:%x\n",port));
KdPrint(("method:%x\n",method));
//操作输出缓冲区
PULONG OutputBuffer = (PULONG)pIrp->AssociatedIrp.SystemBuffer;
if (method==1)//8位操作
{
*OutputBuffer = READ_PORT_UCHAR((PUCHAR)port);
}else if(method==2)//16位操作
{
*OutputBuffer = READ_PORT_USHORT((PUSHORT)port);
}else if(method==4)//32位操作
{
*OutputBuffer = READ_PORT_ULONG((PULONG)port);
}
//设置实际操作输出缓冲区长度
info = 4;
break;
}
case WRITE_PORT:
{
KdPrint(("WRITE_PORT\n"));
//缓冲区方式IOCTL
//显示输入缓冲区数据
PULONG InputBuffer = (PULONG)pIrp->AssociatedIrp.SystemBuffer;
ULONG port = (ULONG)(*InputBuffer);
InputBuffer++;
UCHAR method = (UCHAR)(*InputBuffer);
InputBuffer++;
ULONG value = (ULONG)(*InputBuffer);
KdPrint(("port:%x\n",port));
KdPrint(("method:%x\n",method));
KdPrint(("value:%x\n",value));
//操作输出缓冲区
PULONG OutputBuffer = (PULONG)pIrp->AssociatedIrp.SystemBuffer;
if (method==1)//8位操作
{
WRITE_PORT_UCHAR((PUCHAR)port,(UCHAR)value);
}else if(method==2)//16位操作
{
WRITE_PORT_USHORT((PUSHORT)port,(USHORT)value);
}else if(method==4)//32位操作
{
WRITE_PORT_ULONG((PULONG)port,(ULONG)value);
}
//设置实际操作输出缓冲区长度
info = 0;
break;
}
default:
status = STATUS_INVALID_VARIANT;
}
// 完成IRP
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = info; // bytes xfered
IoCompleteRequest( pIrp, IO_NO_INCREMENT );
KdPrint(("Leave HelloDDKDeviceIOControl\n"));
return status;
}
示例4: HandleDeviceQueryPower
NTSTATUS HandleDeviceQueryPower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
NTSTATUS ntStatus;
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
DEVICE_POWER_STATE deviceState;
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceQueryPower: Entered\n"));
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation(Irp);
deviceState = irpStack->Parameters.Power.State.DeviceState;
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceQueryPower: Query for device power state D%X\n"
"FBTUSB: HandleDeviceQueryPower: Current device power state D%X\n",
deviceState - 1,
deviceExtension->DevPower - 1));
if (deviceExtension->WaitWakeEnable && deviceState > deviceExtension->DeviceCapabilities.DeviceWake)
{
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = ntStatus = STATUS_INVALID_DEVICE_STATE;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceQueryPower::"));
FreeBT_IoDecrement(deviceExtension);
return ntStatus;
}
if (deviceState < deviceExtension->DevPower)
{
ntStatus = STATUS_SUCCESS;
}
else
{
ntStatus = HoldIoRequests(DeviceObject, Irp);
if(STATUS_PENDING == ntStatus)
{
return ntStatus;
}
}
// on error complete the Irp.
// on success pass it to the lower layers
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
if(!NT_SUCCESS(ntStatus))
{
IoCompleteRequest(Irp, IO_NO_INCREMENT);
}
else
{
IoSkipCurrentIrpStackLocation(Irp);
ntStatus=PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
}
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceQueryPower::"));
FreeBT_IoDecrement(deviceExtension);
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceQueryPower: Leaving\n"));
return ntStatus;
}
示例5: HandleDeviceSetPower
NTSTATUS HandleDeviceSetPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
KIRQL oldIrql;
NTSTATUS ntStatus;
POWER_STATE newState;
PIO_STACK_LOCATION irpStack;
PDEVICE_EXTENSION deviceExtension;
DEVICE_POWER_STATE newDevState,
oldDevState;
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: Entered\n"));
deviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation(Irp);
oldDevState = deviceExtension->DevPower;
newState = irpStack->Parameters.Power.State;
newDevState = newState.DeviceState;
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: Set request for device power state D%X\n"
"FBTUSB: HandleDeviceSetPower: Current device power state D%X\n",
newDevState - 1,
deviceExtension->DevPower - 1));
if (newDevState < oldDevState)
{
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: Adding power to the device\n"));
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE)FinishDevPoUpIrp,
deviceExtension,
TRUE,
TRUE,
TRUE);
ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
}
else
{
// newDevState >= oldDevState
// hold I/O if transition from D0 -> DX (X = 1, 2, 3)
// if transition from D1 or D2 to deeper sleep states,
// I/O queue is already on hold.
if(PowerDeviceD0 == oldDevState && newDevState > oldDevState)
{
// D0 -> DX transition
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: Removing power from the device\n"));
ntStatus = HoldIoRequests(DeviceObject, Irp);
if (!NT_SUCCESS(ntStatus))
{
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower::"));
FreeBT_IoDecrement(deviceExtension);
return ntStatus;
}
else
{
goto HandleDeviceSetPower_Exit;
}
}
else if (PowerDeviceD0 == oldDevState && PowerDeviceD0 == newDevState)
{
// D0 -> D0
// unblock the queue which may have been blocked processing
// query irp
FreeBT_DbgPrint(3, ("FBTUSB: HandleDeviceSetPower: A SetD0 request\n"));
KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
deviceExtension->QueueState = AllowRequests;
KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
ProcessQueuedRequests(deviceExtension);
}
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE) FinishDevPoDnIrp,
deviceExtension,
TRUE,
TRUE,
TRUE);
//.........这里部分代码省略.........
示例6: NtfsCommonQueryVolumeInfo
NTSTATUS
NtfsCommonQueryVolumeInfo (
IN PIRP_CONTEXT IrpContext,
IN PIRP Irp
)
/*++
Routine Description:
This is the common routine for query Volume Information called by both the
fsd and fsp threads.
Arguments:
Irp - Supplies the Irp to process
Return Value:
NTSTATUS - The return status for the operation
--*/
{
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
PFILE_OBJECT FileObject;
TYPE_OF_OPEN TypeOfOpen;
PVCB Vcb;
PFCB Fcb;
PSCB Scb;
PCCB Ccb;
ULONG Length;
FS_INFORMATION_CLASS FsInformationClass;
PVOID Buffer;
ASSERT_IRP_CONTEXT( IrpContext );
ASSERT_IRP( Irp );
PAGED_CODE();
//
// Get the current stack location
//
IrpSp = IoGetCurrentIrpStackLocation( Irp );
DebugTrace( +1, Dbg, ("NtfsCommonQueryVolumeInfo...\n") );
DebugTrace( 0, Dbg, ("IrpContext = %08lx\n", IrpContext) );
DebugTrace( 0, Dbg, ("Irp = %08lx\n", Irp) );
DebugTrace( 0, Dbg, ("Length = %08lx\n", IrpSp->Parameters.QueryVolume.Length) );
DebugTrace( 0, Dbg, ("FsInformationClass = %08lx\n", IrpSp->Parameters.QueryVolume.FsInformationClass) );
DebugTrace( 0, Dbg, ("Buffer = %08lx\n", Irp->AssociatedIrp.SystemBuffer) );
//
// Reference our input parameters to make things easier
//
Length = IrpSp->Parameters.QueryVolume.Length;
FsInformationClass = IrpSp->Parameters.QueryVolume.FsInformationClass;
Buffer = Irp->AssociatedIrp.SystemBuffer;
//
// Extract and decode the file object to get the Vcb, we don't really
// care what the type of open is.
//
FileObject = IrpSp->FileObject;
TypeOfOpen = NtfsDecodeFileObject( IrpContext, FileObject, &Vcb, &Fcb, &Scb, &Ccb, TRUE );
//
// We need exclusive access to the Vcb because we are going to verify
// it. After we verify the vcb we'll convert our access to shared
//
NtfsAcquireSharedVcb( IrpContext, Vcb, FALSE );
try {
//
// Based on the information class we'll do different actions. Each
// of the procedures that we're calling fills up the output buffer
// if possible and returns true if it successfully filled the buffer
// and false if it couldn't wait for any I/O to complete.
//
switch (FsInformationClass) {
case FileFsVolumeInformation:
Status = NtfsQueryFsVolumeInfo( IrpContext, Vcb, Buffer, &Length );
break;
case FileFsSizeInformation:
Status = NtfsQueryFsSizeInfo( IrpContext, Vcb, Buffer, &Length );
break;
//.........这里部分代码省略.........
示例7: DokanDispatchCleanup
NTSTATUS
DokanDispatchCleanup(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)
/*++
Routine Description:
This device control dispatcher handles Cleanup IRP.
Arguments:
DeviceObject - Context for the activity.
Irp - The device control argument block.
Return Value:
NTSTATUS
--*/
{
PDokanVCB vcb;
PIO_STACK_LOCATION irpSp;
NTSTATUS status = STATUS_INVALID_PARAMETER;
PFILE_OBJECT fileObject;
PDokanCCB ccb = NULL;
PDokanFCB fcb = NULL;
PEVENT_CONTEXT eventContext;
ULONG eventLength;
__try {
DDbgPrint("==> DokanCleanup\n");
irpSp = IoGetCurrentIrpStackLocation(Irp);
fileObject = irpSp->FileObject;
DDbgPrint(" ProcessId %lu\n", IoGetRequestorProcessId(Irp));
DokanPrintFileName(fileObject);
// Cleanup must be success in any case
if (fileObject == NULL) {
DDbgPrint(" fileObject == NULL\n");
status = STATUS_SUCCESS;
__leave;
}
vcb = DeviceObject->DeviceExtension;
if (vcb == NULL) {
DDbgPrint(" No device extension\n");
status = STATUS_SUCCESS;
__leave;
}
if (GetIdentifierType(vcb) != VCB ||
!DokanCheckCCB(vcb->Dcb, fileObject->FsContext2)) {
status = STATUS_SUCCESS;
__leave;
}
ccb = fileObject->FsContext2;
ASSERT(ccb != NULL);
fcb = ccb->Fcb;
ASSERT(fcb != NULL);
FlushFcb(fcb, fileObject);
DokanFCBLockRW(fcb);
eventLength = sizeof(EVENT_CONTEXT) + fcb->FileName.Length;
eventContext = AllocateEventContext(vcb->Dcb, Irp, eventLength, ccb);
if (eventContext == NULL) {
status = STATUS_INSUFFICIENT_RESOURCES;
DokanFCBUnlock(fcb);
__leave;
}
fileObject->Flags |= FO_CLEANUP_COMPLETE;
eventContext->Context = ccb->UserContext;
eventContext->FileFlags |= DokanCCBFlagsGet(ccb);
// DDbgPrint(" get Context %X\n", (ULONG)ccb->UserContext);
// copy the filename to EventContext from ccb
eventContext->Operation.Cleanup.FileNameLength = fcb->FileName.Length;
RtlCopyMemory(eventContext->Operation.Cleanup.FileName,
fcb->FileName.Buffer, fcb->FileName.Length);
// FsRtlCheckOpLock is called with non-NULL completion routine - not blocking.
status = FsRtlCheckOplock(DokanGetFcbOplock(fcb), Irp, eventContext,
DokanOplockComplete, DokanPrePostIrp);
DokanFCBUnlock(fcb);
//
// if FsRtlCheckOplock returns STATUS_PENDING the IRP has been posted
// to service an oplock break and we need to leave now.
//
if (status != STATUS_SUCCESS) {
if (status == STATUS_PENDING) {
//.........这里部分代码省略.........
示例8: FFSMountVolume
__drv_mustHoldCriticalRegion
NTSTATUS
FFSMountVolume(
IN PFFS_IRP_CONTEXT IrpContext)
{
PDEVICE_OBJECT MainDeviceObject;
BOOLEAN GlobalDataResourceAcquired = FALSE;
PIRP Irp;
PIO_STACK_LOCATION IoStackLocation;
PDEVICE_OBJECT TargetDeviceObject;
NTSTATUS Status = STATUS_UNRECOGNIZED_VOLUME;
PDEVICE_OBJECT VolumeDeviceObject = NULL;
PFFS_VCB Vcb;
PFFS_SUPER_BLOCK FFSSb = NULL;
ULONG dwBytes;
DISK_GEOMETRY DiskGeometry;
PAGED_CODE();
_SEH2_TRY
{
ASSERT(IrpContext != NULL);
ASSERT((IrpContext->Identifier.Type == FFSICX) &&
(IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
MainDeviceObject = IrpContext->DeviceObject;
//
// Make sure we can wait.
//
SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT);
//
// This request is only allowed on the main device object
//
if (MainDeviceObject != FFSGlobal->DeviceObject)
{
Status = STATUS_INVALID_DEVICE_REQUEST;
_SEH2_LEAVE;
}
ExAcquireResourceExclusiveLite(
&(FFSGlobal->Resource),
TRUE);
GlobalDataResourceAcquired = TRUE;
if (FlagOn(FFSGlobal->Flags, FFS_UNLOAD_PENDING))
{
Status = STATUS_UNRECOGNIZED_VOLUME;
_SEH2_LEAVE;
}
Irp = IrpContext->Irp;
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
TargetDeviceObject =
IoStackLocation->Parameters.MountVolume.DeviceObject;
dwBytes = sizeof(DISK_GEOMETRY);
Status = FFSDiskIoControl(
TargetDeviceObject,
IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL,
0,
&DiskGeometry,
&dwBytes);
if (!NT_SUCCESS(Status))
{
_SEH2_LEAVE;
}
Status = IoCreateDevice(
MainDeviceObject->DriverObject,
sizeof(FFS_VCB),
NULL,
FILE_DEVICE_DISK_FILE_SYSTEM,
0,
FALSE,
&VolumeDeviceObject);
if (!NT_SUCCESS(Status))
{
_SEH2_LEAVE;
}
VolumeDeviceObject->StackSize = (CCHAR)(TargetDeviceObject->StackSize + 1);
if (TargetDeviceObject->AlignmentRequirement >
VolumeDeviceObject->AlignmentRequirement)
{
VolumeDeviceObject->AlignmentRequirement =
TargetDeviceObject->AlignmentRequirement;
}
//.........这里部分代码省略.........
示例9: CdfsMountVolume
static NTSTATUS
CdfsMountVolume(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
PDEVICE_EXTENSION DeviceExt = NULL;
PDEVICE_OBJECT NewDeviceObject = NULL;
PDEVICE_OBJECT DeviceToMount;
PIO_STACK_LOCATION Stack;
PFCB Fcb = NULL;
PCCB Ccb = NULL;
PVPB Vpb;
NTSTATUS Status;
CDINFO CdInfo;
DPRINT("CdfsMountVolume() called\n");
if (DeviceObject != CdfsGlobalData->DeviceObject)
{
Status = STATUS_INVALID_DEVICE_REQUEST;
goto ByeBye;
}
Stack = IoGetCurrentIrpStackLocation(Irp);
DeviceToMount = Stack->Parameters.MountVolume.DeviceObject;
Vpb = Stack->Parameters.MountVolume.Vpb;
Status = CdfsGetVolumeData(DeviceToMount, &CdInfo);
if (!NT_SUCCESS(Status))
{
goto ByeBye;
}
Status = IoCreateDevice(CdfsGlobalData->DriverObject,
sizeof(DEVICE_EXTENSION),
NULL,
FILE_DEVICE_CD_ROM_FILE_SYSTEM,
DeviceToMount->Characteristics,
FALSE,
&NewDeviceObject);
if (!NT_SUCCESS(Status))
goto ByeBye;
NewDeviceObject->Flags = NewDeviceObject->Flags | DO_DIRECT_IO;
NewDeviceObject->Flags &= ~DO_VERIFY_VOLUME;
DeviceExt = (PVOID)NewDeviceObject->DeviceExtension;
RtlZeroMemory(DeviceExt,
sizeof(DEVICE_EXTENSION));
Vpb->SerialNumber = CdInfo.SerialNumber;
Vpb->VolumeLabelLength = CdInfo.VolumeLabelLength;
RtlCopyMemory(Vpb->VolumeLabel, CdInfo.VolumeLabel, CdInfo.VolumeLabelLength);
RtlCopyMemory(&DeviceExt->CdInfo, &CdInfo, sizeof(CDINFO));
NewDeviceObject->Vpb = DeviceToMount->Vpb;
DeviceExt->VolumeDevice = NewDeviceObject;
DeviceExt->StorageDevice = DeviceToMount;
DeviceExt->StorageDevice->Vpb->DeviceObject = NewDeviceObject;
DeviceExt->StorageDevice->Vpb->RealDevice = DeviceExt->StorageDevice;
DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED;
NewDeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1;
NewDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
/* Close (and cleanup) might be called from IoCreateStreamFileObject
* but we use this resource from CdfsCleanup, therefore it should be
* initialized no later than this. */
ExInitializeResourceLite(&DeviceExt->DirResource);
DeviceExt->StreamFileObject = IoCreateStreamFileObject(NULL,
DeviceExt->StorageDevice);
Fcb = CdfsCreateFCB(NULL);
if (Fcb == NULL)
{
Status = STATUS_INSUFFICIENT_RESOURCES;
goto ByeBye;
}
Ccb = ExAllocatePoolWithTag(NonPagedPool,
sizeof(CCB),
TAG_CCB);
if (Ccb == NULL)
{
Status = STATUS_INSUFFICIENT_RESOURCES;
goto ByeBye;
}
RtlZeroMemory(Ccb,
sizeof(CCB));
DeviceExt->StreamFileObject->ReadAccess = TRUE;
DeviceExt->StreamFileObject->WriteAccess = FALSE;
DeviceExt->StreamFileObject->DeleteAccess = FALSE;
DeviceExt->StreamFileObject->FsContext = Fcb;
DeviceExt->StreamFileObject->FsContext2 = Ccb;
DeviceExt->StreamFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
DeviceExt->StreamFileObject->PrivateCacheMap = NULL;
DeviceExt->StreamFileObject->Vpb = DeviceExt->Vpb;
Ccb->PtrFileObject = DeviceExt->StreamFileObject;
Fcb->FileObject = DeviceExt->StreamFileObject;
Fcb->DevExt = (PDEVICE_EXTENSION)DeviceExt->StorageDevice;
//.........这里部分代码省略.........
示例10: FFSInvalidateVolumes
__drv_mustHoldCriticalRegion
NTSTATUS
FFSInvalidateVolumes(
IN PFFS_IRP_CONTEXT IrpContext)
{
NTSTATUS Status;
PIRP Irp;
PIO_STACK_LOCATION IrpSp;
HANDLE Handle;
PLIST_ENTRY ListEntry;
PFILE_OBJECT FileObject;
PDEVICE_OBJECT DeviceObject;
BOOLEAN GlobalResourceAcquired = FALSE;
LUID Privilege = {SE_TCB_PRIVILEGE, 0};
_SEH2_TRY
{
Irp = IrpContext->Irp;
IrpSp = IoGetCurrentIrpStackLocation(Irp);
if (!SeSinglePrivilegeCheck(Privilege, Irp->RequestorMode))
{
Status = STATUS_PRIVILEGE_NOT_HELD;
_SEH2_LEAVE;
}
if (
#if !defined(_GNU_NTIFS_) || defined(__REACTOS__)
IrpSp->Parameters.FileSystemControl.InputBufferLength
#else
((PEXTENDED_IO_STACK_LOCATION)(IrpSp))->
Parameters.FileSystemControl.InputBufferLength
#endif
!= sizeof(HANDLE))
{
Status = STATUS_INVALID_PARAMETER;
_SEH2_LEAVE;
}
Handle = *(PHANDLE)Irp->AssociatedIrp.SystemBuffer;
Status = ObReferenceObjectByHandle(Handle,
0,
*IoFileObjectType,
KernelMode,
(void **)&FileObject,
NULL);
if (!NT_SUCCESS(Status))
{
_SEH2_LEAVE;
}
else
{
ObDereferenceObject(FileObject);
DeviceObject = FileObject->DeviceObject;
}
FFSPrint((DBG_INFO, "FFSInvalidateVolumes: FileObject=%xh ...\n", FileObject));
ExAcquireResourceExclusiveLite(
&FFSGlobal->Resource,
TRUE);
GlobalResourceAcquired = TRUE;
ListEntry = FFSGlobal->VcbList.Flink;
while (ListEntry != &FFSGlobal->VcbList)
{
PFFS_VCB Vcb;
Vcb = CONTAINING_RECORD(ListEntry, FFS_VCB, Next);
ListEntry = ListEntry->Flink;
FFSPrint((DBG_INFO, "FFSInvalidateVolumes: Vcb=%xh Vcb->Vpb=%xh...\n", Vcb, Vcb->Vpb));
if (Vcb->Vpb && (Vcb->Vpb->RealDevice == DeviceObject))
{
ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
FFSPrint((DBG_INFO, "FFSInvalidateVolumes: FFSPurgeVolume...\n"));
FFSPurgeVolume(Vcb, FALSE);
ClearFlag(Vcb->Flags, VCB_MOUNTED);
ExReleaseResourceLite(&Vcb->MainResource);
//
// Vcb is still attached on the list ......
//
if (ListEntry->Blink == &Vcb->Next)
{
FFSPrint((DBG_INFO, "FFSInvalidateVolumes: FFSCheckDismount...\n"));
FFSCheckDismount(IrpContext, Vcb, FALSE);
}
}
//.........这里部分代码省略.........
示例11: FFSUserFsRequest
__drv_mustHoldCriticalRegion
NTSTATUS
FFSUserFsRequest(
IN PFFS_IRP_CONTEXT IrpContext)
{
PIRP Irp;
PIO_STACK_LOCATION IoStackLocation;
ULONG FsControlCode;
NTSTATUS Status;
PAGED_CODE();
ASSERT(IrpContext);
ASSERT((IrpContext->Identifier.Type == FFSICX) &&
(IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
Irp = IrpContext->Irp;
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
#if !defined(_GNU_NTIFS_) || defined(__REACTOS__)
FsControlCode =
IoStackLocation->Parameters.FileSystemControl.FsControlCode;
#else
FsControlCode = ((PEXTENDED_IO_STACK_LOCATION)
IoStackLocation)->Parameters.FileSystemControl.FsControlCode;
#endif
switch (FsControlCode)
{
case FSCTL_LOCK_VOLUME:
Status = FFSLockVolume(IrpContext);
break;
case FSCTL_UNLOCK_VOLUME:
Status = FFSUnlockVolume(IrpContext);
break;
case FSCTL_DISMOUNT_VOLUME:
Status = FFSDismountVolume(IrpContext);
break;
case FSCTL_IS_VOLUME_MOUNTED:
Status = FFSIsVolumeMounted(IrpContext);
break;
case FSCTL_INVALIDATE_VOLUMES:
Status = FFSInvalidateVolumes(IrpContext);
break;
#if (_WIN32_WINNT >= 0x0500)
case FSCTL_ALLOW_EXTENDED_DASD_IO:
Status = FFSAllowExtendedDasdIo(IrpContext);
break;
#endif //(_WIN32_WINNT >= 0x0500)
default:
FFSPrint((DBG_ERROR, "FFSUserFsRequest: Invalid User Request: %xh.\n", FsControlCode));
Status = STATUS_INVALID_DEVICE_REQUEST;
FFSCompleteIrpContext(IrpContext, Status);
}
return Status;
}
示例12: FFSUnlockVolume
__drv_mustHoldCriticalRegion
NTSTATUS
FFSUnlockVolume(
IN PFFS_IRP_CONTEXT IrpContext)
{
PIO_STACK_LOCATION IrpSp;
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status;
PFFS_VCB Vcb = 0;
BOOLEAN VcbResourceAcquired = FALSE;
PAGED_CODE();
_SEH2_TRY
{
ASSERT(IrpContext != NULL);
ASSERT((IrpContext->Identifier.Type == FFSICX) &&
(IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
DeviceObject = IrpContext->DeviceObject;
//
// This request is not allowed on the main device object
//
if (DeviceObject == FFSGlobal->DeviceObject)
{
Status = STATUS_INVALID_PARAMETER;
_SEH2_LEAVE;
}
Vcb = (PFFS_VCB)DeviceObject->DeviceExtension;
ASSERT(Vcb != NULL);
ASSERT((Vcb->Identifier.Type == FFSVCB) &&
(Vcb->Identifier.Size == sizeof(FFS_VCB)));
ASSERT(IsMounted(Vcb));
IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp);
ExAcquireResourceExclusiveLite(
&Vcb->MainResource,
TRUE);
VcbResourceAcquired = TRUE;
Status = FFSUnlockVcb(Vcb, IrpSp->FileObject);
}
_SEH2_FINALLY
{
if (VcbResourceAcquired)
{
ExReleaseResourceForThreadLite(
&Vcb->MainResource,
ExGetCurrentResourceThread());
}
if (!IrpContext->ExceptionInProgress)
{
FFSCompleteIrpContext(IrpContext, Status);
}
} _SEH2_END;
return Status;
}
示例13: FFSVerifyVolume
__drv_mustHoldCriticalRegion
NTSTATUS
FFSVerifyVolume(
IN PFFS_IRP_CONTEXT IrpContext)
{
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
PFFS_SUPER_BLOCK FFSSb = NULL;
PFFS_VCB Vcb = 0;
BOOLEAN VcbResourceAcquired = FALSE;
BOOLEAN GlobalResourceAcquired = FALSE;
PIRP Irp;
PIO_STACK_LOCATION IoStackLocation;
ULONG ChangeCount;
ULONG dwReturn;
PAGED_CODE();
_SEH2_TRY
{
ASSERT(IrpContext != NULL);
ASSERT((IrpContext->Identifier.Type == FFSICX) &&
(IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
DeviceObject = IrpContext->DeviceObject;
//
// This request is not allowed on the main device object
//
if (DeviceObject == FFSGlobal->DeviceObject)
{
Status = STATUS_INVALID_DEVICE_REQUEST;
_SEH2_LEAVE;
}
ExAcquireResourceExclusiveLite(
&FFSGlobal->Resource,
TRUE);
GlobalResourceAcquired = TRUE;
Vcb = (PFFS_VCB)DeviceObject->DeviceExtension;
ASSERT(Vcb != NULL);
ASSERT((Vcb->Identifier.Type == FFSVCB) &&
(Vcb->Identifier.Size == sizeof(FFS_VCB)));
ExAcquireResourceExclusiveLite(
&Vcb->MainResource,
TRUE);
VcbResourceAcquired = TRUE;
if (!FlagOn(Vcb->TargetDeviceObject->Flags, DO_VERIFY_VOLUME))
{
Status = STATUS_SUCCESS;
_SEH2_LEAVE;
}
if (!IsMounted(Vcb))
{
Status = STATUS_WRONG_VOLUME;
_SEH2_LEAVE;
}
dwReturn = sizeof(ULONG);
Status = FFSDiskIoControl(
Vcb->TargetDeviceObject,
IOCTL_DISK_CHECK_VERIFY,
NULL,
0,
&ChangeCount,
&dwReturn);
if (ChangeCount != Vcb->ChangeCount)
{
Status = STATUS_WRONG_VOLUME;
_SEH2_LEAVE;
}
Irp = IrpContext->Irp;
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
if (((((FFSSb = FFSLoadSuper(Vcb, TRUE, SBLOCK_UFS1)) != NULL) && (FFSSb->fs_magic == FS_UFS1_MAGIC)) ||
(((FFSSb = FFSLoadSuper(Vcb, TRUE, SBLOCK_UFS2)) != NULL) && (FFSSb->fs_magic == FS_UFS2_MAGIC))) &&
(memcmp(FFSSb->fs_id, SUPER_BLOCK->fs_id, 8) == 0) &&
(memcmp(FFSSb->fs_volname, SUPER_BLOCK->fs_volname, 16) == 0))
{
ClearFlag(Vcb->TargetDeviceObject->Flags, DO_VERIFY_VOLUME);
if (FFSIsMediaWriteProtected(IrpContext, Vcb->TargetDeviceObject))
{
SetFlag(Vcb->Flags, VCB_WRITE_PROTECTED);
}
else
{
ClearFlag(Vcb->Flags, VCB_WRITE_PROTECTED);
}
//.........这里部分代码省略.........
示例14: RegisterPendingIrpMain
NTSTATUS
RegisterPendingIrpMain(
__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp,
__in ULONG SerialNumber,
__in PIRP_LIST IrpList,
__in ULONG Flags,
__in ULONG CheckMount
)
{
PIRP_ENTRY irpEntry;
PIO_STACK_LOCATION irpSp;
KIRQL oldIrql;
DDbgPrint("==> DokanRegisterPendingIrpMain\n");
if (GetIdentifierType(DeviceObject->DeviceExtension) == VCB) {
PDokanVCB vcb = DeviceObject->DeviceExtension;
if (CheckMount && !vcb->Dcb->Mounted) {
DDbgPrint(" device is not mounted\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
}
irpSp = IoGetCurrentIrpStackLocation(Irp);
// Allocate a record and save all the event context.
irpEntry = DokanAllocateIrpEntry();
if (NULL == irpEntry) {
DDbgPrint(" can't allocate IRP_ENTRY\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(irpEntry, sizeof(IRP_ENTRY));
InitializeListHead(&irpEntry->ListEntry);
irpEntry->SerialNumber = SerialNumber;
irpEntry->FileObject = irpSp->FileObject;
irpEntry->Irp = Irp;
irpEntry->IrpSp = irpSp;
irpEntry->IrpList = IrpList;
irpEntry->Flags = Flags;
DokanUpdateTimeout(&irpEntry->TickCount, DOKAN_IRP_PENDING_TIMEOUT);
//DDbgPrint(" Lock IrpList.ListLock\n");
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
KeAcquireSpinLock(&IrpList->ListLock, &oldIrql);
IoSetCancelRoutine(Irp, DokanIrpCancelRoutine);
if (Irp->Cancel) {
if (IoSetCancelRoutine(Irp, NULL) != NULL) {
//DDbgPrint(" Release IrpList.ListLock %d\n", __LINE__);
KeReleaseSpinLock(&IrpList->ListLock, oldIrql);
DokanFreeIrpEntry(irpEntry);
return STATUS_CANCELLED;
}
}
IoMarkIrpPending(Irp);
InsertTailList(&IrpList->ListHead, &irpEntry->ListEntry);
irpEntry->CancelRoutineFreeMemory = FALSE;
// save the pointer in order to be accessed by cancel routine
Irp->Tail.Overlay.DriverContext[DRIVER_CONTEXT_IRP_ENTRY] = irpEntry;
KeSetEvent(&IrpList->NotEmpty, IO_NO_INCREMENT, FALSE);
//DDbgPrint(" Release IrpList.ListLock\n");
KeReleaseSpinLock(&IrpList->ListLock, oldIrql);
DDbgPrint("<== DokanRegisterPendingIrpMain\n");
return STATUS_PENDING;;
}
示例15: PciDispatchIrp
NTSTATUS
NTAPI
PciDispatchIrp(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PPCI_FDO_EXTENSION DeviceExtension;
PIO_STACK_LOCATION IoStackLocation;
PPCI_MJ_DISPATCH_TABLE IrpDispatchTable;
BOOLEAN PassToPdo;
NTSTATUS Status;
PPCI_MN_DISPATCH_TABLE TableArray = NULL, Table;
USHORT MaxMinor;
PCI_DISPATCH_STYLE DispatchStyle = 0;
PCI_DISPATCH_FUNCTION DispatchFunction = NULL;
DPRINT1("PCI: Dispatch IRP\n");
/* Get the extension and I/O stack location for this IRP */
DeviceExtension = (PPCI_FDO_EXTENSION)DeviceObject->DeviceExtension;
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
ASSERT((DeviceExtension->ExtensionType == PciPdoExtensionType) ||
(DeviceExtension->ExtensionType == PciFdoExtensionType));
/* Deleted extensions don't respond to IRPs */
if (DeviceExtension->DeviceState == PciDeleted)
{
/* Fail this IRP */
Status = STATUS_NO_SUCH_DEVICE;
PassToPdo = FALSE;
}
else
{
/* Otherwise, get the dispatch table for the extension */
IrpDispatchTable = DeviceExtension->IrpDispatchTable;
/* And choose which function table to use */
switch (IoStackLocation->MajorFunction)
{
case IRP_MJ_POWER:
/* Power Manager IRPs */
TableArray = IrpDispatchTable->PowerIrpDispatchTable;
MaxMinor = IrpDispatchTable->PowerIrpMaximumMinorFunction;
break;
case IRP_MJ_PNP:
/* Plug-and-Play Manager IRPs */
TableArray = IrpDispatchTable->PnpIrpDispatchTable;
MaxMinor = IrpDispatchTable->PnpIrpMaximumMinorFunction;
break;
case IRP_MJ_SYSTEM_CONTROL:
/* WMI IRPs */
DispatchFunction = IrpDispatchTable->SystemControlIrpDispatchFunction;
DispatchStyle = IrpDispatchTable->SystemControlIrpDispatchStyle;
MaxMinor = 0xFFFF;
break;
default:
/* Unrecognized IRPs */
DispatchFunction = IrpDispatchTable->OtherIrpDispatchFunction;
DispatchStyle = IrpDispatchTable->OtherIrpDispatchStyle;
MaxMinor = 0xFFFF;
break;
}
/* Only deal with recognized IRPs */
if (MaxMinor != 0xFFFF)
{
/* Make sure the function is recognized */
if (IoStackLocation->MinorFunction > MaxMinor)
{
/* Pick the terminator, which should return unrecognized */
Table = &TableArray[MaxMinor + 1];
}
else
{
/* Pick the appropriate table for this function */
Table = &TableArray[IoStackLocation->MinorFunction];
}
/* From that table, get the function code and dispatch style */
DispatchStyle = Table->DispatchStyle;
DispatchFunction = Table->DispatchFunction;
}
/* Print out debugging information, and see if we should break */
if (PciDebugIrpDispatchDisplay(IoStackLocation,
DeviceExtension,
MaxMinor))
{
/* The developer/user wants us to break for this IRP, do it */
DbgBreakPoint();
}
/* Check if this IRP should be sent up the stack first */
if (DispatchStyle == IRP_UPWARD)
{
//.........这里部分代码省略.........