FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED

Hi

I am writing a native application to defragment a given file.

For this I am opening the volume handles as below

ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
&objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);

But when I use this handle in NtFsControlFile with FSCTL_GET_VOLUME_BITMAP,
I am getting STATUS_ACCESS_DENIED (0xc0000022).

I succeeded in doing the above operation with CreateFile and DeviceIOControl
in a Win32 application with the above access rights.

Could you please let me know if I am doing anything wrong in opening the
handle.

Thanks in advance,
Ramananda

From my quick read of the docs, your flags are set wrong. In your
second param you have a GENERIC flag.

The flags used here in opening the file are defined in the docs by
ZwCreateFile’s flags which state,
“The caller can only specifies a generic access right, GENERIC_XXX, for
a file, *not a directory*.”.

In your last param for NtOpenFile, you have FILE_DIRECTORY_FILE specified.

Just guessing…

Ramananda Ramachandra wrote:

Hi

I am writing a native application to defragment a given file.

For this I am opening the volume handles as below

ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
&objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);

But when I use this handle in NtFsControlFile with FSCTL_GET_VOLUME_BITMAP,
I am getting STATUS_ACCESS_DENIED (0xc0000022).

I succeeded in doing the above operation with CreateFile and DeviceIOControl
in a Win32 application with the above access rights.

Could you please let me know if I am doing anything wrong in opening the
handle.

Thanks in advance,
Ramananda


Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

The following works for me…

NtCreateFile(VolumeHandle,
GENERIC_ALL|GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE, &ObjectAttributes,
&IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
It’s overkill I think, but reduce it until you get it to work. Also, in
Win32 land I have no problems with using only FILE_GENERIC_READ, which isn’t
the same as GENERIC_READ, but haven’t tested it in a native app.

  • JeremyB

“Ramananda Ramachandra” wrote in message
news:xxxxx@ntfsd…
> Hi
>
> I am writing a native application to defragment a given file.
>
> For this I am opening the volume handles as below
>
> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>
> But when I use this handle in NtFsControlFile with
> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>
> I succeeded in doing the above operation with CreateFile and
> DeviceIOControl in a Win32 application with the above access rights.
>
> Could you please let me know if I am doing anything wrong in opening the
> handle.
>
> Thanks in advance,
> Ramananda
>
>

Hi

I am able to open the handle to the volume and the same handle works fine
for FSCTL_GET_NTFS_VOLUME_DATA.
When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
(STATUS_ACCESS_DENIED)

I tried different combinations in opening the volume handle without any
success.
The one I tried is
ntStatVolume = NtCreateFile(&g_hVolume,
FILE_READ_ATTRIBUTES,
&objAttrsVolume,
&ioStatusVolume,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_DIRECTORY_FILE,
NULL,
0);

Is there any restriction in getting the volume bitmap from a native
application.

Thanks for your help in advance,

Cheers
Ramananda

“Ramananda Ramachandra” wrote in message
news:xxxxx@ntfsd…
> Hi
>
> I am writing a native application to defragment a given file.
>
> For this I am opening the volume handles as below
>
> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>
> But when I use this handle in NtFsControlFile with
> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>
> I succeeded in doing the above operation with CreateFile and
> DeviceIOControl in a Win32 application with the above access rights.
>
> Could you please let me know if I am doing anything wrong in opening the
> handle.
>
> Thanks in advance,
> Ramananda
>
>

The documentation says:

“The handle used here must be a Volume handle and have been opened with any
access. Note that only Administrators can open Volume handles.”

So open with GENERIC_READ | GENERIC_WRITE and make sure you’re an
administrator.

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
Ramachandra
Sent: Thursday, December 07, 2006 4:13 AM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED

Hi

I am able to open the handle to the volume and the same handle works fine
for FSCTL_GET_NTFS_VOLUME_DATA.
When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
(STATUS_ACCESS_DENIED)

I tried different combinations in opening the volume handle without any
success.
The one I tried is
ntStatVolume = NtCreateFile(&g_hVolume,
FILE_READ_ATTRIBUTES,
&objAttrsVolume,
&ioStatusVolume,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_DIRECTORY_FILE,
NULL,
0);

Is there any restriction in getting the volume bitmap from a native
application.

Thanks for your help in advance,

Cheers
Ramananda

“Ramananda Ramachandra” wrote in message
news:xxxxx@ntfsd…
> Hi
>
> I am writing a native application to defragment a given file.
>
> For this I am opening the volume handles as below
>
> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>
> But when I use this handle in NtFsControlFile with
> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>
> I succeeded in doing the above operation with CreateFile and
> DeviceIOControl in a Win32 application with the above access rights.
>
> Could you please let me know if I am doing anything wrong in opening the
> handle.
>
> Thanks in advance,
> Ramananda
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

Since he is writing a native app which launches before win32 is active,
wouldn’t he be in the system
account at this point (automatically having admin rights)?

Ken Cross wrote:

The documentation says:

“The handle used here must be a Volume handle and have been opened with any
access. Note that only Administrators can open Volume handles.”

So open with GENERIC_READ | GENERIC_WRITE and make sure you’re an
administrator.

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
Ramachandra
Sent: Thursday, December 07, 2006 4:13 AM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED

Hi

I am able to open the handle to the volume and the same handle works fine
for FSCTL_GET_NTFS_VOLUME_DATA.
When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
(STATUS_ACCESS_DENIED)

I tried different combinations in opening the volume handle without any
success.
The one I tried is
ntStatVolume = NtCreateFile(&g_hVolume,
FILE_READ_ATTRIBUTES,
&objAttrsVolume,
&ioStatusVolume,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_DIRECTORY_FILE,
NULL,
0);

Is there any restriction in getting the volume bitmap from a native
application.

Thanks for your help in advance,

Cheers
Ramananda

“Ramananda Ramachandra” wrote in message
>news:xxxxx@ntfsd…
>
>
>>Hi
>>
>>I am writing a native application to defragment a given file.
>>
>>For this I am opening the volume handles as below
>>
>>ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
>>&objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
>>FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>>
>>But when I use this handle in NtFsControlFile with
>>FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>>
>>I succeeded in doing the above operation with CreateFile and
>>DeviceIOControl in a Win32 application with the above access rights.
>>
>>Could you please let me know if I am doing anything wrong in opening the
>>handle.
>>
>>Thanks in advance,
>>Ramananda
>>
>>
>>
>>
>
>
>
>—
>Questions? First check the IFS FAQ at
>https://www.osronline.com/article.cfm?id=17
>
>You are currently subscribed to ntfsd as: xxxxx@comcast.net
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>—
>Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17
>
>You are currently subscribed to ntfsd as: xxxxx@comcast.net
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

I suspect (given that the open succeeds with FILE_DIRECTORY_FILE), that you
have a handle to the root directory, not a handle to the volume.

Open ??\D: not ??\D:.

  • Dan.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
Ramachandra
Sent: Thursday, December 07, 2006 2:13 AM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED

Hi

I am able to open the handle to the volume and the same handle works fine
for FSCTL_GET_NTFS_VOLUME_DATA.
When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
(STATUS_ACCESS_DENIED)

I tried different combinations in opening the volume handle without any
success.
The one I tried is
ntStatVolume = NtCreateFile(&g_hVolume,
FILE_READ_ATTRIBUTES,
&objAttrsVolume,
&ioStatusVolume,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_DIRECTORY_FILE,
NULL,
0);

Is there any restriction in getting the volume bitmap from a native
application.

Thanks for your help in advance,

Cheers
Ramananda

“Ramananda Ramachandra” wrote in message
news:xxxxx@ntfsd…
> Hi
>
> I am writing a native application to defragment a given file.
>
> For this I am opening the volume handles as below
>
> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>
> But when I use this handle in NtFsControlFile with
> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>
> I succeeded in doing the above operation with CreateFile and
> DeviceIOControl in a Win32 application with the above access rights.
>
> Could you please let me know if I am doing anything wrong in opening
> the
> handle.
>
> Thanks in advance,
> Ramananda
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

Hi Dan/Everyone

I would like to thank you all for attempting to help me in resoling this
issue.
I am opening a handle to the volume itself. ie ??\C:
But then am I right in specifying it as FILE_DIRECTORY_FILE.
Could you please share the list of flags that are essential to open a volume
handle. The document doesnt describe much about opening volume handles.

But the other point to note here is that I am able to query
FSCTL_GET_NTFS_VOLUME_DATA successfully which indicates its a volume handle.
Only for FSCTL_GET_VOLUME_BITMAP I am getting access denied.

But the same works from a Win32 application that I wrote for testing
purpose. Please let me know if I am missing something.

Cheers
Ramananda

“Dan Kyler” wrote in message news:xxxxx@ntfsd…
>I suspect (given that the open succeeds with FILE_DIRECTORY_FILE), that you
> have a handle to the root directory, not a handle to the volume.
>
> Open ??\D: not ??\D:.
>
> - Dan.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
> Ramachandra
> Sent: Thursday, December 07, 2006 2:13 AM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED
>
>
> Hi
>
> I am able to open the handle to the volume and the same handle works fine
> for FSCTL_GET_NTFS_VOLUME_DATA.
> When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
> (STATUS_ACCESS_DENIED)
>
> I tried different combinations in opening the volume handle without any
> success.
> The one I tried is
> ntStatVolume = NtCreateFile(&g_hVolume,
> FILE_READ_ATTRIBUTES,
> &objAttrsVolume,
> &ioStatusVolume,
> 0,
> FILE_ATTRIBUTE_NORMAL,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_OPEN,
> FILE_DIRECTORY_FILE,
> NULL,
> 0);
>
> Is there any restriction in getting the volume bitmap from a native
> application.
>
> Thanks for your help in advance,
>
> Cheers
> Ramananda
>
>
> “Ramananda Ramachandra” wrote in message
> news:xxxxx@ntfsd…
>> Hi
>>
>> I am writing a native application to defragment a given file.
>>
>> For this I am opening the volume handles as below
>>
>> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
>> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
>> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>>
>> But when I use this handle in NtFsControlFile with
>> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>>
>> I succeeded in doing the above operation with CreateFile and
>> DeviceIOControl in a Win32 application with the above access rights.
>>
>> Could you please let me know if I am doing anything wrong in opening
>> the
>> handle.
>>
>> Thanks in advance,
>> Ramananda
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@privtek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Dan

I changed FILE_DIRECTORY_FILE to FILE_NON_DIRECTORY_FILE and I am able to
open the volume handle properly. Thanks for the pointer.

Now the strange problem is that it is telling STATUS_INVALID_DEVICE_REQUEST
when I call FSCTL_GET_VOLUME_BITMAP.
I am running on NTFS with XP SP2.

Cheers
Ramananda

“Dan Kyler” wrote in message news:xxxxx@ntfsd…
>I suspect (given that the open succeeds with FILE_DIRECTORY_FILE), that you
> have a handle to the root directory, not a handle to the volume.
>
> Open ??\D: not ??\D:.
>
> - Dan.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
> Ramachandra
> Sent: Thursday, December 07, 2006 2:13 AM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED
>
>
> Hi
>
> I am able to open the handle to the volume and the same handle works fine
> for FSCTL_GET_NTFS_VOLUME_DATA.
> When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
> (STATUS_ACCESS_DENIED)
>
> I tried different combinations in opening the volume handle without any
> success.
> The one I tried is
> ntStatVolume = NtCreateFile(&g_hVolume,
> FILE_READ_ATTRIBUTES,
> &objAttrsVolume,
> &ioStatusVolume,
> 0,
> FILE_ATTRIBUTE_NORMAL,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_OPEN,
> FILE_DIRECTORY_FILE,
> NULL,
> 0);
>
> Is there any restriction in getting the volume bitmap from a native
> application.
>
> Thanks for your help in advance,
>
> Cheers
> Ramananda
>
>
> “Ramananda Ramachandra” wrote in message
> news:xxxxx@ntfsd…
>> Hi
>>
>> I am writing a native application to defragment a given file.
>>
>> For this I am opening the volume handles as below
>>
>> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
>> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
>> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>>
>> But when I use this handle in NtFsControlFile with
>> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>>
>> I succeeded in doing the above operation with CreateFile and
>> DeviceIOControl in a Win32 application with the above access rights.
>>
>> Could you please let me know if I am doing anything wrong in opening
>> the
>> handle.
>>
>> Thanks in advance,
>> Ramananda
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@privtek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Ramananda Ramachandra wrote:

Dan

I changed FILE_DIRECTORY_FILE to FILE_NON_DIRECTORY_FILE and I am able to
open the volume handle properly. Thanks for the pointer.

Now the strange problem is that it is telling STATUS_INVALID_DEVICE_REQUEST
when I call FSCTL_GET_VOLUME_BITMAP.
I am running on NTFS with XP SP2.

Cheers
Ramananda

“Dan Kyler” wrote in message news:xxxxx@ntfsd…
>
>> I suspect (given that the open succeeds with FILE_DIRECTORY_FILE), that you
>> have a handle to the root directory, not a handle to the volume.
>>
>> Open ??\D: not ??\D:.
>>
>> - Dan.
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
>> Ramachandra
>> Sent: Thursday, December 07, 2006 2:13 AM
>> To: Windows File Systems Devs Interest List
>> Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED
>>
>>
>> Hi
>>
>> I am able to open the handle to the volume and the same handle works fine
>> for FSCTL_GET_NTFS_VOLUME_DATA.
>> When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
>> (STATUS_ACCESS_DENIED)
>>
>> I tried different combinations in opening the volume handle without any
>> success.
>> The one I tried is
>> ntStatVolume = NtCreateFile(&g_hVolume,
>> FILE_READ_ATTRIBUTES,
>> &objAttrsVolume,
>> &ioStatusVolume,
>> 0,
>> FILE_ATTRIBUTE_NORMAL,
>> FILE_SHARE_READ | FILE_SHARE_WRITE,
>> FILE_OPEN,
>> FILE_DIRECTORY_FILE,
>> NULL,
>> 0);
>>
>> Is there any restriction in getting the volume bitmap from a native
>> application.
>>
>> Thanks for your help in advance,
>>
>> Cheers
>> Ramananda
>>
>>
>> “Ramananda Ramachandra” wrote in message
>> news:xxxxx@ntfsd…
>>
>>> Hi
>>>
>>> I am writing a native application to defragment a given file.
>>>
>>> For this I am opening the volume handles as below
>>>
>>> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
>>> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
>>> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>>>
>>> But when I use this handle in NtFsControlFile with
>>> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
>>>
>>> I succeeded in doing the above operation with CreateFile and
>>> DeviceIOControl in a Win32 application with the above access rights.
>>>
>>> Could you please let me know if I am doing anything wrong in opening
>>> the
>>> handle.
>>>
>>> Thanks in advance,
>>> Ramananda
>>>
>>>

>>> Hi
>>>
You don’t need FILE_DIRECTORY_FILE. This is used when you need to open a
handle to the keyboard.
Try this.
//------------------//
// Create Handle //
//------------------//
status = NtCreateFile(
hDevice,
GENERIC_READ | SYNCHRONIZE,
&oaCreateFile,
&isbCreateFile,
NULL,
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
0,
NULL,
0
);

//-----------------------//
// Get Volume Bitmap //
//-----------------------//

NtCreateEvent(
&hDevIoCtlDone,
EVENT_ALL_ACCESS,
NULL,
SynchronizationEvent,
FALSE
);

status = NtFsControlFile(
hDevice, // [In] Handle
returned from CoreCreateFile
hDevIoCtlDone, // [In] Event to
signal upon completion (or NULL).
NULL, // [In] Callback
to call upon completion (or NULL).
NULL, // [In] Context
for ApcRoutine (or NULL).
&isbDevIoCtl, // [Out] Receives
information about the operation on return.
FSCTL_GET_VOLUME_BITMAP, // [In] Control
code for the operation to perform.
&starting_lcn, // [In] Source for
any input data required (or NULL).
sizeof(starting_lcn), // [In] Size of
InputBuffer.
pVolumeBitmap, // [Out] Source for any
output data returned (or NULL).
pVolumeBitmapSize // [In] Size of OutputBuffer.
);

if(STATUS_PENDING == status)
{ // STATUS_PENDING
status= NtWaitForSingleObject(hDevIoCtlDone,FALSE,NULL);
}

In Native api i use
WCHAR szDrvName=(L"\??\A:“);
In Win32 i use
WCHAR szDrvName=(L”\\.\A:");

This worked fine on Win Xp Sp2
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@privtek.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@icode.ro
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>

Request more access than FILE_READ_ATTRIBUTES. F_R_A access will not cause
a filesystem mount to occur. Anything else will. With the volume not
mounted, your FS Control goes to the storage stack, where it is an invalid
request.

  • Dan.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
Ramachandra
Sent: Thursday, December 07, 2006 9:47 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED

Dan

I changed FILE_DIRECTORY_FILE to FILE_NON_DIRECTORY_FILE and I am able to
open the volume handle properly. Thanks for the pointer.

Now the strange problem is that it is telling STATUS_INVALID_DEVICE_REQUEST
when I call FSCTL_GET_VOLUME_BITMAP.
I am running on NTFS with XP SP2.

Cheers
Ramananda

“Dan Kyler” wrote in message news:xxxxx@ntfsd…
>I suspect (given that the open succeeds with FILE_DIRECTORY_FILE), that
>you have a handle to the root directory, not a handle to the volume.
>
> Open ??\D: not ??\D:.
>
> - Dan.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
> Ramachandra
> Sent: Thursday, December 07, 2006 2:13 AM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving
> STATUS_ACCESS_DENIED
>
>
> Hi
>
> I am able to open the handle to the volume and the same handle works
> fine for FSCTL_GET_NTFS_VOLUME_DATA. When I use this handle for
> FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
> (STATUS_ACCESS_DENIED)
>
> I tried different combinations in opening the volume handle without
> any success. The one I tried is
> ntStatVolume = NtCreateFile(&g_hVolume,
> FILE_READ_ATTRIBUTES,
> &objAttrsVolume,
> &ioStatusVolume,
> 0,
> FILE_ATTRIBUTE_NORMAL,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_OPEN,
> FILE_DIRECTORY_FILE,
> NULL,
> 0);
>
> Is there any restriction in getting the volume bitmap from a native
> application.
>
> Thanks for your help in advance,
>
> Cheers
> Ramananda
>
>
> “Ramananda Ramachandra” wrote in message
> news:xxxxx@ntfsd…
>> Hi
>>
>> I am writing a native application to defragment a given file.
>>
>> For this I am opening the volume handles as below
>>
>> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
>> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
>> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
>>
>> But when I use this handle in NtFsControlFile with
>> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED
>> (0xc0000022).
>>
>> I succeeded in doing the above operation with CreateFile and
>> DeviceIOControl in a Win32 application with the above access rights.
>>
>> Could you please let me know if I am doing anything wrong in opening
>> the handle.
>>
>> Thanks in advance,
>> Ramananda
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@privtek.com To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

> I am opening a handle to the volume itself. ie ??\C:

But then am I right in specifying it as FILE_DIRECTORY_FILE.

No, this is not correct.

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

I think that NtDeviceIoControlFile - unlike DeviceIoControl - has a special
BOOLEAN parameter which is set to TRUE for FSCTLs and to FALSE for usual
IOCTLs.

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

----- Original Message -----
From: “Ramananda Ramachandra”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Friday, December 08, 2006 7:46 AM
Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED

> Dan
>
> I changed FILE_DIRECTORY_FILE to FILE_NON_DIRECTORY_FILE and I am able to
> open the volume handle properly. Thanks for the pointer.
>
> Now the strange problem is that it is telling STATUS_INVALID_DEVICE_REQUEST
> when I call FSCTL_GET_VOLUME_BITMAP.
> I am running on NTFS with XP SP2.
>
> Cheers
> Ramananda
>
> “Dan Kyler” wrote in message news:xxxxx@ntfsd…
> >I suspect (given that the open succeeds with FILE_DIRECTORY_FILE), that you
> > have a handle to the root directory, not a handle to the volume.
> >
> > Open ??\D: not ??\D:.
> >
> > - Dan.
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Ramananda
> > Ramachandra
> > Sent: Thursday, December 07, 2006 2:13 AM
> > To: Windows File Systems Devs Interest List
> > Subject: Re:[ntfsd] FSCTL_GET_VOLUME_BITMAP giving STATUS_ACCESS_DENIED
> >
> >
> > Hi
> >
> > I am able to open the handle to the volume and the same handle works fine
> > for FSCTL_GET_NTFS_VOLUME_DATA.
> > When I use this handle for FSCTL_GET_VOLUME_BITMAP, I get 0xC0000022
> > (STATUS_ACCESS_DENIED)
> >
> > I tried different combinations in opening the volume handle without any
> > success.
> > The one I tried is
> > ntStatVolume = NtCreateFile(&g_hVolume,
> > FILE_READ_ATTRIBUTES,
> > &objAttrsVolume,
> > &ioStatusVolume,
> > 0,
> > FILE_ATTRIBUTE_NORMAL,
> > FILE_SHARE_READ | FILE_SHARE_WRITE,
> > FILE_OPEN,
> > FILE_DIRECTORY_FILE,
> > NULL,
> > 0);
> >
> > Is there any restriction in getting the volume bitmap from a native
> > application.
> >
> > Thanks for your help in advance,
> >
> > Cheers
> > Ramananda
> >
> >
> > “Ramananda Ramachandra” wrote in message
> > news:xxxxx@ntfsd…
> >> Hi
> >>
> >> I am writing a native application to defragment a given file.
> >>
> >> For this I am opening the volume handles as below
> >>
> >> ntStatVolume = NtOpenFile(&g_hVolume, GENERIC_READ | SYNCHRONIZE,
> >> &objAttrs, &ioStatus, FILE_SHARE_READ | FILE_SHARE_WRITE,
> >> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT);
> >>
> >> But when I use this handle in NtFsControlFile with
> >> FSCTL_GET_VOLUME_BITMAP, I am getting STATUS_ACCESS_DENIED (0xc0000022).
> >>
> >> I succeeded in doing the above operation with CreateFile and
> >> DeviceIOControl in a Win32 application with the above access rights.
> >>
> >> Could you please let me know if I am doing anything wrong in opening
> >> the
> >> handle.
> >>
> >> Thanks in advance,
> >> Ramananda
> >>
> >>
> >
> >
> >
> > —
> > Questions? First check the IFS FAQ at
> > https://www.osronline.com/article.cfm?id=17
> >
> > You are currently subscribed to ntfsd as: xxxxx@privtek.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com