How to send an FSCTL_XXX IRP to a filehandle in Kernel Mode

Hi All,

I have been trying to send an FSCTL_XXX (say GET_RETRIEVAL_POINTERS) to
a file that I opened in kernel mode (so I have its handle). So far, I
have tried to get the file object from the handle and read the device
object from this file object - however, the device object seems to the
storage stack object related rather than the file system. I have also
tried to simply cast the file object to Device Object pointer, but that
does not work either.

What is the right way to send a File System related IRP to a file handle
in the kernel mode?

Thanks in advance,
Udas

Use IoBuildDeviceIoControlRequest. Use IoGetRelatedDeviceObject to get
the correct device object given the file object. Or use
ZwDeviceIoControlFile with a valid handle.

If you are working at this level you need the ifs kit.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of udas2980
Sent: Tuesday, July 12, 2005 10:01 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to send an FSCTL_XXX IRP to a filehandle in Kernel
Mode

Hi All,

I have been trying to send an FSCTL_XXX (say GET_RETRIEVAL_POINTERS) to
a file that I opened in kernel mode (so I have its handle). So far, I
have tried to get the file object from the handle and read the device
object from this file object - however, the device object seems to the
storage stack object related rather than the file system. I have also
tried to simply cast the file object to Device Object pointer, but that
does not work either.

What is the right way to send a File System related IRP to a file handle

in the kernel mode?

Thanks in advance,
Udas


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Don’t you mean ZwFsControlFile ?

Yup. ZwFsControlFile. Either way the correct bits are defined in ntifs.h

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
Sent: Wednesday, July 13, 2005 2:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to send an FSCTL_XXX IRP to a filehandle in
Kernel Mode

Don’t you mean ZwFsControlFile ?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks for the replies. I do have the IFS kit.

However, I am confused about the difference between ZwFsControlFile and
ZwDeviceIoControlFile. I do not see any difference in IFS kit doc pages
for the two.

Regards
Udas

Roddy, Mark wrote:

Yup. ZwFsControlFile. Either way the correct bits are defined in ntifs.h

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
Sent: Wednesday, July 13, 2005 2:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to send an FSCTL_XXX IRP to a filehandle in
Kernel Mode

Don’t you mean ZwFsControlFile ?


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

One sends MJ_DEVICE_CONTROL, another sends MJ_FILE_SYSTEM_CONROL.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “udas2980”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Thursday, July 14, 2005 3:27 AM
Subject: Re:[ntdev] How to send an FSCTL_XXX IRP to a filehandle in Kernel Mode

> Thanks for the replies. I do have the IFS kit.
>
> However, I am confused about the difference between ZwFsControlFile and
> ZwDeviceIoControlFile. I do not see any difference in IFS kit doc pages
> for the two.
>
> Regards
> Udas
>
> Roddy, Mark wrote:
> > Yup. ZwFsControlFile. Either way the correct bits are defined in ntifs.h
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
> > Sent: Wednesday, July 13, 2005 2:08 PM
> > To: Windows System Software Devs Interest List
> > Subject: RE: [ntdev] How to send an FSCTL_XXX IRP to a filehandle in
> > Kernel Mode
> >
> > Don’t you mean ZwFsControlFile ?
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown lmsubst tag argument:
> > ‘’
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Thank you. Is it correct to assume IO manager knows (based on the
control code, perhaps) whether to use MJ_DEVICE_CONTROL or
MJ_FILE_SYSTEM_CONTROL when a user mode app does DeviceIoControl on a
device / file ?

Regards
Udas

Maxim S. Shatskih wrote:

One sends MJ_DEVICE_CONTROL, another sends MJ_FILE_SYSTEM_CONROL.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “udas2980”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Thursday, July 14, 2005 3:27 AM
> Subject: Re:[ntdev] How to send an FSCTL_XXX IRP to a filehandle in Kernel Mode
>
>
>
>>Thanks for the replies. I do have the IFS kit.
>>
>>However, I am confused about the difference between ZwFsControlFile and
>>ZwDeviceIoControlFile. I do not see any difference in IFS kit doc pages
>>for the two.
>>
>>Regards
>>Udas
>>
>>Roddy, Mark wrote:
>>
>>>Yup. ZwFsControlFile. Either way the correct bits are defined in ntifs.h
>>>
>>>-----Original Message-----
>>>From: xxxxx@lists.osr.com
>>>[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
>>>Sent: Wednesday, July 13, 2005 2:08 PM
>>>To: Windows System Software Devs Interest List
>>>Subject: RE: [ntdev] How to send an FSCTL_XXX IRP to a filehandle in
>>>Kernel Mode
>>>
>>>Don’t you mean ZwFsControlFile ?
>>>
>>>—
>>>Questions? First check the Kernel Driver FAQ at
>>>http://www.osronline.com/article.cfm?id=256
>>>
>>>You are currently subscribed to ntdev as: unknown lmsubst tag argument:
>>>‘’
>>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>>>
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>
> http://www.osronline.com/article.cfm?id=256
>
>>You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

Yes. FSCTL_xxx codes are mapped to ZwFsControlFile.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “udas2980”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Thursday, July 14, 2005 7:43 AM
Subject: Re:[ntdev] How to send an FSCTL_XXX IRP to a filehandle in Kernel Mode

> Thank you. Is it correct to assume IO manager knows (based on the
> control code, perhaps) whether to use MJ_DEVICE_CONTROL or
> MJ_FILE_SYSTEM_CONTROL when a user mode app does DeviceIoControl on a
> device / file ?
>
> Regards
> Udas
>
>
> Maxim S. Shatskih wrote:
> > One sends MJ_DEVICE_CONTROL, another sends MJ_FILE_SYSTEM_CONROL.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> > ----- Original Message -----
> > From: “udas2980”
> > Newsgroups: ntdev
> > To: “Windows System Software Devs Interest List”
> > Sent: Thursday, July 14, 2005 3:27 AM
> > Subject: Re:[ntdev] How to send an FSCTL_XXX IRP to a filehandle in Kernel
Mode
> >
> >
> >
> >>Thanks for the replies. I do have the IFS kit.
> >>
> >>However, I am confused about the difference between ZwFsControlFile and
> >>ZwDeviceIoControlFile. I do not see any difference in IFS kit doc pages
> >>for the two.
> >>
> >>Regards
> >>Udas
> >>
> >>Roddy, Mark wrote:
> >>
> >>>Yup. ZwFsControlFile. Either way the correct bits are defined in ntifs.h
> >>>
> >>>-----Original Message-----
> >>>From: xxxxx@lists.osr.com
> >>>[mailto:xxxxx@lists.osr.com] On Behalf Of Satya Das
> >>>Sent: Wednesday, July 13, 2005 2:08 PM
> >>>To: Windows System Software Devs Interest List
> >>>Subject: RE: [ntdev] How to send an FSCTL_XXX IRP to a filehandle in
> >>>Kernel Mode
> >>>
> >>>Don’t you mean ZwFsControlFile ?
> >>>
> >>>—
> >>>Questions? First check the Kernel Driver FAQ at
> >>>http://www.osronline.com/article.cfm?id=256
> >>>
> >>>You are currently subscribed to ntdev as: unknown lmsubst tag argument:
> >>>‘’
> >>>To unsubscribe send a blank email to xxxxx@lists.osr.com
> >>>
> >>
> >>—
> >>Questions? First check the Kernel Driver FAQ at
> >
> > http://www.osronline.com/article.cfm?id=256
> >
> >>You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> >>To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com