You can do this through WDF by formatting the request with WdfRequestWdmFormatUsingStackLocation. You would set the IO_STACK_LOCATION to IRP_MJ_FILE_SYSTEM_CONTROL, set the Parameters.IoControlCode to the desired IOCTL value.
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Chris Hall
Sent: Wednesday, September 03, 2008 3:34 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:RE:Is there a way of creating a WDFDEVICE for an arbitrary WDM DEVICE_OBJECT
I think I’ve finally figured this out. I used irpTracker on the target
system to confirm that I was indeed targeting the correct device. During
this process I discovered the problem. I’ve been sending the requests as
IRP_MJ_DEVICE_CONTROL, however when I sent the FSCTL from user mode I
noticed that by the time it is sent to the Ntfs driver it is an
IRP_MJ_FILE_SYSTEM_CONTROL.
Based on this discovery I am now able to use the DeviceObject from my
FILE_OBJECT Vpb and send the FSCTL to the file system driver as an
IRP_MJ_FILE_SYSTEM_CONTROL. I also have to set the FileObject member of the
stack location to stop the system bug checking (found that by searching the
ntdev archives). With these changes in place the FSCTL works just fine.
However, as I have to change the MajorFunction code and I would much prefer
to make this FSCTL request synchronously I can’t see a way of doing it with
WDF as there does not appear to be a WdfRequest… or a WdfIoTargetSend…
function to send an existing Request object synchronously.
For now I can at least progress using WDM mechanisms to send my FSCTL. I’d
be very interested to know if there is a way of synchronously sending a WDF
request that has been created by using one of the WDF request formatting
functions.
Thanks for all the help to get me this far.
Chris.
“Chris Hall” wrote in message
news:xxxxx@ntdev…
> If I open “\Device\Harddisk0\Partition0” I get this from WinDbg
>
> kd> !devobj 0x82215eb8
> Device object (82215eb8) is for:
> \FileSystem\RAW DriverObject 823aaf38
> Current Irp 00000000 RefCount 0 Type 00000008 Flags 00000010
> DevExt 82215f70 DevObjExt 82215fd0
> ExtensionFlags (0000000000)
> Device queue is not busy.
> kd> !devstack 0x82215eb8
> !DevObj !DrvObj !DevExt ObjectName
>> 82215eb8 \FileSystem\RAW 82215f70
>
> If I open “\Device\HarddiskVolume1” I get this and the status returned by
> the FSCTL is C0000002
>
> kd> !devobj 0x82373020
> Device object (82373020) is for:
> \FileSystem\Ntfs DriverObject 823d5a18
> Current Irp 00000000 RefCount 0 Type 00000008 Flags 00000000
> DevExt 823730d8 DevObjExt 82373880
> ExtensionFlags (0000000000)
> AttachedDevice (Upper) 823902d8 \FileSystem\sr
> Device queue is not busy.
> kd> !devstack 0x82373020
> !DevObj !DrvObj !DevExt ObjectName
> 823902d8 \FileSystem\sr 82390390
>> 82373020 \FileSystem\Ntfs 823730d8
>
> if I open “\Device\HarddiskVolume1" I get this and the status returned by
> the FSCTL is C000000D
>
> kd> !devobj 0x82373020
> Device object (82373020) is for:
> \FileSystem\Ntfs DriverObject 823d5a18
> Current Irp 00000000 RefCount 0 Type 00000008 Flags 00000000
> DevExt 823730d8 DevObjExt 82373880
> ExtensionFlags (0000000000)
> AttachedDevice (Upper) 823902d8 \FileSystem\sr
> Device queue is not busy.
> kd> !devstack 0x82373020
> !DevObj !DrvObj !DevExt ObjectName
> 823902d8 \FileSystem\sr 82390390
>> 82373020 \FileSystem\Ntfs 823730d8
>
> I’ve checked that the volume file system does support
> FSCTL_IS_VOLUME_MOUNTED by sending it from user mode and all is well.
>
> Any suggestions?
>
> Thanks
>
> Chris
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> Run
>
> !devobj
> And
> !devstack
>
> Where is the value of pFileObject->Vpb->DeviceObject. Is it
> really the file systems devobj?
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Chris Hall
> Sent: Tuesday, September 02, 2008 9:36 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] RE:Is there a way of creating a WDFDEVICE for an
> arbitrary WDM DEVICE_OBJECT
>
> Thanks,
>
> thats helped but I am still ultimately stuck.
>
> You might have noticed my other thread “Sending FSCTL_GET_VOLUME_BITMAP
> from
> a volume filter”. This is all related to that.
>
> I have now progressed to the point where I believe I have the
> DEVICE_OBJECT
> for the file system driver for my volume as obtained from the Vpb in a
> FILE_OBJECT in turn obtained from a handle created by opening the volume
> “\Device\HardDiskVolume1” (I have also tried
> “\Device\Harddisk0\Partition0”).
>
> Using the DEVICE_OBJECT and the FILE_OBJECT I am initialising and opening
> an
> IoTarget and sending my FSCTL to the target. However all I get is erro
> 0xC0000002 STATUS_NOT_IMPLEMENTED.
>
> I wonder if one of you knowlegable people would be able to take a look at
> the code below or just comment on the approach and perhaps suggest a way
> in
> whihc I can get to send a FSCTL to the file system that is in control of
> the
> mounted volume that I am filtering.
>
> Note in the code below I am using FSCTL_IS_VOLUME_MOUNTED because it is
> simple for testing, ultimately I need to send FSCTL_GET_VOLUME_BITMAP.
>
> Many thanks
>
> Chris
>
> The Code:
>
> OBJECT_ATTRIBUTES ObjAttr={0};
> IO_STATUS_BLOCK IoStatus={0};
> HANDLE hVol = NULL;
>
> UNICODE_STRING name;
> RtlInitUnicodeString(&name,L”\Device\Harddisk0\Partition0");
> InitializeObjectAttributes ( &ObjAttr,&name, OBJ_CASE_INSENSITIVE, NULL,
> NULL );
> status = ZwOpenFile(&hVol,GENERIC_READ,&ObjAttr,&IoStatus,FILE_SHARE_WRITE
> |
> FILE_SHARE_READ,0);
>
> if(NT_SUCCESS(status))
> {
> PFILE_OBJECT pFileObject;
> status =
> ObReferenceObjectByHandle(hVol,GENERIC_READ,NULL,(KPROCESSOR_MODE)KernelMode,(PVOID
> *)&pFileObject,NULL);
> if(NT_SUCCESS(status))
> {
> WDFIOTARGET fsIoTarget;
>
> WdfIoTargetCreate(WdfIoTargetGetDevice(pDevCont->TargetToSendRequestsTo),WDF_NO_OBJECT_ATTRIBUTES,&fsIoTarget);
> WDF_IO_TARGET_OPEN_PARAMS openParams;
>
> WDF_IO_TARGET_OPEN_PARAMS_INIT_EXISTING_DEVICE(&openParams,pFileObject->Vpb->DeviceObject);
> openParams.TargetFileObject = pFileObject;
> status = WdfIoTargetOpen(fsIoTarget,&openParams);
>
> // Now see if we can send an IO control to the FSD
> ULONG bytesReturned;
> status = WdfIoTargetSendIoctlSynchronously(fsIoTarget,
> NULL,
> FSCTL_IS_VOLUME_MOUNTED,
> NULL,
> NULL,
> NULL,
> &bytesReturned);
> }
> }
>
>
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> Not to disagree with Peter, his underlying answer is correct, but you
> should
> use WDF_IO_TARGET_OPEN_PARAMS_INIT_EXISTING_DEVICE to init the
> WDF_IO_TARGET_OPEN_PARAMS, it will set the appropriate fields for you.
>
> To take a step back for a second, how did you get the other driver’s
> PDEVICE_OBJECT in the first place? If it was by calling
> IoGetDeviceObjectPointer or ZwCreateFile, you can have the WDFIOTARGET do
> the work for you to get the PDEVICE_OBJECT by using
> WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN/CREATE_BY_NAME instead
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
> Sent: Tuesday, September 02, 2008 7:45 AM
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] Is there a way of creating a WDFDEVICE for an
> arbitrary
> WDM DEVICE_OBJECT
>
> To SEND a request to???
>
> You want WdfIoTargetCreate, followed by WdfIoTargetOpen specifying the
> DEVICE_OBJECT * and WdfIoTargetOpenUseExistingDevice.
>
> Peter
> OSR
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer