FSCTL_GET_VOLUME_BITMAP in kernel

hi, all
i want to use FSCTL_GET_VOLUME_BITMAP in kernel to get the volume’s bitmap,
but when i use ZwFsControlFile with FSCTL_GET_VOLUME_BITMAP, the api failed
with status == STATUS_INVALID_DEVICE_REQUEST, what’s the wrong thing i do?

here is my code:

========================================================================

NTSTATUS status;
HANDLE fileHandle;
IO_STATUS_BLOCK iosb;
OBJECT_ATTRIBUTES objectAttributes;
STARTING_LCN_INPUT_BUFFER slib;
PVOID buffer;
ULONG bufferLength;
UNICODE_STRING fileName;
PVOLUME_BITMAP_BUFFER pvbb;

do {
RtlInitUnicodeString(&fileName, L"\??\C:");

InitializeObjectAttributes(&objectAttributes, &fileName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL, NULL);

status = ZwOpenFile(&fileHandle, SYNCHRONIZE | FILE_READ_ATTRIBUTES,
&objectAttributes, &iosb, FILE_SHARE_READ |
FILE_SHARE_WRITE,
FILE_NON_DIRECTORY_FILE |
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(status)) {
break;
}

bufferLength = 4 * 1024 * 1024;
buffer = ExAllocatePool(PagedPool, bufferLength);
if (!buffer) {
ZwClose(fileHandle);
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}

slib.StartingVcn.QuadPart = 0;
status = STATUS_UNSUCCESSFUL;
while (!NT_SUCCESS(status)) {
status = ZwFsControlFile(fileHandle, NULL, NULL, NULL, &iosb,
FSCTL_GET_VOLUME_BITMAP, &slib,
sizeof(slib), buffer, bufferLength);
if (!NT_SUCCESS(status)) {
if ((STATUS_BUFFER_TOO_SMALL == status) ||
(STATUS_BUFFER_OVERFLOW == status)) {

ExFreePool(buffer);
bufferLength *= 2;
buffer = ExAllocatePool(PagedPool, bufferLength);
if (!buffer) {
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
} else {
break;
}
}
}

ZwClose(fileHandle);

if (!NT_SUCCESS(status)) {
break;
}

ExFreePool(buffer);

} while (FALSE);

return status;

========================================================================

Thanks.

haha, *^_^*

i change

status = ZwOpenFile(&fileHandle, SYNCHRONIZE | FILE_READ_ATTRIBUTES,
&objectAttributes, &iosb, FILE_SHARE_READ |
FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT);

to

status = ZwOpenFile(&fileHandle, SYNCHRONIZE | GENERIC_READ,
&objectAttributes, &iosb, FILE_SHARE_READ |
FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT);

it works at once, but why the status is STATUS_INVALID_DEVICE_REQUEST when i
call
ZwFsControlFile, why not STATUS_ACCESS_DENIED or others

“Xu Ge” дÈëÏûÏ¢ÐÂÎÅ:xxxxx@ntdev…
> hi, all
> i want to use FSCTL_GET_VOLUME_BITMAP in kernel to get the volume’s
> bitmap,
> but when i use ZwFsControlFile with FSCTL_GET_VOLUME_BITMAP, the api
> failed
> with status == STATUS_INVALID_DEVICE_REQUEST, what’s the wrong thing i do?
>
> here is my code:
>
> ========================================================================
>
> NTSTATUS status;
> HANDLE fileHandle;
> IO_STATUS_BLOCK iosb;
> OBJECT_ATTRIBUTES objectAttributes;
> STARTING_LCN_INPUT_BUFFER slib;
> PVOID buffer;
> ULONG bufferLength;
> UNICODE_STRING fileName;
> PVOLUME_BITMAP_BUFFER pvbb;
>
> do {
> RtlInitUnicodeString(&fileName, L"\??\C:");
>
> InitializeObjectAttributes(&objectAttributes, &fileName,
> OBJ_CASE_INSENSITIVE |
> OBJ_KERNEL_HANDLE,
> NULL, NULL);
>
> status = ZwOpenFile(&fileHandle, SYNCHRONIZE |
> FILE_READ_ATTRIBUTES,
> &objectAttributes, &iosb, FILE_SHARE_READ |
> FILE_SHARE_WRITE,
> FILE_NON_DIRECTORY_FILE |
> FILE_SYNCHRONOUS_IO_NONALERT);
> if (!NT_SUCCESS(status)) {
> break;
> }
>
> bufferLength = 4 * 1024 * 1024;
> buffer = ExAllocatePool(PagedPool, bufferLength);
> if (!buffer) {
> ZwClose(fileHandle);
> status = STATUS_INSUFFICIENT_RESOURCES;
> break;
> }
>
> slib.StartingVcn.QuadPart = 0;
> status = STATUS_UNSUCCESSFUL;
> while (!NT_SUCCESS(status)) {
> status = ZwFsControlFile(fileHandle, NULL, NULL, NULL, &iosb,
> FSCTL_GET_VOLUME_BITMAP, &slib,
> sizeof(slib), buffer, bufferLength);
> if (!NT_SUCCESS(status)) {
> if ((STATUS_BUFFER_TOO_SMALL == status) ||
> (STATUS_BUFFER_OVERFLOW == status)) {
>
> ExFreePool(buffer);
> bufferLength *= 2;
> buffer = ExAllocatePool(PagedPool, bufferLength);
> if (!buffer) {
> status = STATUS_INSUFFICIENT_RESOURCES;
> break;
> }
> } else {
> break;
> }
> }
> }
>
> ZwClose(fileHandle);
>
> if (!NT_SUCCESS(status)) {
> break;
> }
>
> ExFreePool(buffer);
>
> } while (FALSE);
>
> return status;
>
> ========================================================================
>
> Thanks.
>
>
>

I do just what you are trying to do and I open it LIKE:

open = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
share = FILE_SHARE_READ | FILE_SHARE_WRITE;
options = FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT |
FILE_RANDOM_ACCESS | FILE_NO_INTERMEDIATE_BUFFERING;
status_nt = ZwCreateFile (volhandle, open, &objattr, &iosb, NULL,
FILE_ATTRIBUTE_NORMAL, share, FILE_OPEN,
options, NULL, 0);

After I do the ZwFsControlFile I do the following to wait for
any pending I/O:

if (status_nt == STATUS_PENDING)
{
ZwWaitForSingleObject (osfree->volhandle, FALSE, NULL);
status_nt = iosb.Status;
}

Rick Cadruvi…

STATUS_ACCESS_DENIED is returned on create requests when you do not have the
correct access rights, not later on when you attempt to perform an operation
using a valid handle for which you did not request the correct access modes.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Xu Ge
Sent: Friday, July 29, 2005 12:53 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] FSCTL_GET_VOLUME_BITMAP in kernel

haha, *^_^*

i change

status = ZwOpenFile(&fileHandle, SYNCHRONIZE |
FILE_READ_ATTRIBUTES,
&objectAttributes, &iosb,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT);

to

status = ZwOpenFile(&fileHandle, SYNCHRONIZE | GENERIC_READ,
&objectAttributes, &iosb,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT);

it works at once, but why the status is
STATUS_INVALID_DEVICE_REQUEST when i call ZwFsControlFile,
why not STATUS_ACCESS_DENIED or others

“Xu Ge” д???Ϣ???:xxxxx@ntdev…
> > hi, all
> > i want to use FSCTL_GET_VOLUME_BITMAP in kernel to get the volume’s
> > bitmap,
> > but when i use ZwFsControlFile with
> FSCTL_GET_VOLUME_BITMAP, the api
> > failed
> > with status == STATUS_INVALID_DEVICE_REQUEST, what’s the
> wrong thing i do?
> >
> > here is my code:
> >
> >
> ==============================================================
> ==========
> >
> > NTSTATUS status;
> > HANDLE fileHandle;
> > IO_STATUS_BLOCK iosb;
> > OBJECT_ATTRIBUTES objectAttributes;
> > STARTING_LCN_INPUT_BUFFER slib;
> > PVOID buffer;
> > ULONG bufferLength;
> > UNICODE_STRING fileName;
> > PVOLUME_BITMAP_BUFFER pvbb;
> >
> > do {
> > RtlInitUnicodeString(&fileName, L"\??\C:");
> >
> > InitializeObjectAttributes(&objectAttributes, &fileName,
> > OBJ_CASE_INSENSITIVE |
> > OBJ_KERNEL_HANDLE,
> > NULL, NULL);
> >
> > status = ZwOpenFile(&fileHandle, SYNCHRONIZE |
> > FILE_READ_ATTRIBUTES,
> > &objectAttributes, &iosb,
> FILE_SHARE_READ |
> > FILE_SHARE_WRITE,
> > FILE_NON_DIRECTORY_FILE |
> > FILE_SYNCHRONOUS_IO_NONALERT);
> > if (!NT_SUCCESS(status)) {
> > break;
> > }
> >
> > bufferLength = 4 * 1024 * 1024;
> > buffer = ExAllocatePool(PagedPool, bufferLength);
> > if (!buffer) {
> > ZwClose(fileHandle);
> > status = STATUS_INSUFFICIENT_RESOURCES;
> > break;
> > }
> >
> > slib.StartingVcn.QuadPart = 0;
> > status = STATUS_UNSUCCESSFUL;
> > while (!NT_SUCCESS(status)) {
> > status = ZwFsControlFile(fileHandle, NULL, NULL,
> NULL, &iosb,
> > FSCTL_GET_VOLUME_BITMAP, &slib,
> > sizeof(slib), buffer,
> bufferLength);
> > if (!NT_SUCCESS(status)) {
> > if ((STATUS_BUFFER_TOO_SMALL == status) ||
> > (STATUS_BUFFER_OVERFLOW == status)) {
> >
> > ExFreePool(buffer);
> > bufferLength *= 2;
> > buffer = ExAllocatePool(PagedPool, bufferLength);
> > if (!buffer) {
> > status = STATUS_INSUFFICIENT_RESOURCES;
> > break;
> > }
> > } else {
> > break;
> > }
> > }
> > }
> >
> > ZwClose(fileHandle);
> >
> > if (!NT_SUCCESS(status)) {
> > break;
> > }
> >
> > ExFreePool(buffer);
> >
> > } while (FALSE);
> >
> > return status;
> >
> >
> ==============================================================
> ==========
> >
> > Thanks.
> >
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@hollistech.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Thanks.
Mark

“Mark Roddy” ???:xxxxx@ntdev…
STATUS_ACCESS_DENIED is returned on create requests when you do not have the
correct access rights, not later on when you attempt to perform an operation
using a valid handle for which you did not request the correct access modes.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Xu Ge
> Sent: Friday, July 29, 2005 12:53 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] FSCTL_GET_VOLUME_BITMAP in kernel
>
> haha, :slight_smile:
>
> i change
>
> status = ZwOpenFile(&fileHandle, SYNCHRONIZE |
> FILE_READ_ATTRIBUTES,
> &objectAttributes, &iosb,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_SYNCHRONOUS_IO_NONALERT);
>
> to
>
> status = ZwOpenFile(&fileHandle, SYNCHRONIZE | GENERIC_READ,
> &objectAttributes, &iosb,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> FILE_SYNCHRONOUS_IO_NONALERT);
>
>
> it works at once, but why the status is
> STATUS_INVALID_DEVICE_REQUEST when i call ZwFsControlFile,
> why not STATUS_ACCESS_DENIED or others
>
>
> “Xu Ge” дÈëÏûÏ¢ÐÂÎÅ:xxxxx@ntdev…
> > hi, all
> > i want to use FSCTL_GET_VOLUME_BITMAP in kernel to get the volume’s
> > bitmap,
> > but when i use ZwFsControlFile with
> FSCTL_GET_VOLUME_BITMAP, the api
> > failed
> > with status == STATUS_INVALID_DEVICE_REQUEST, what’s the
> wrong thing i do?
> >
> > here is my code:
> >
> >
> ==============================================================
> ==========
> >
> > NTSTATUS status;
> > HANDLE fileHandle;
> > IO_STATUS_BLOCK iosb;
> > OBJECT_ATTRIBUTES objectAttributes;
> > STARTING_LCN_INPUT_BUFFER slib;
> > PVOID buffer;
> > ULONG bufferLength;
> > UNICODE_STRING fileName;
> > PVOLUME_BITMAP_BUFFER pvbb;
> >
> > do {
> > RtlInitUnicodeString(&fileName, L"\??\C:");
> >
> > InitializeObjectAttributes(&objectAttributes, &fileName,
> > OBJ_CASE_INSENSITIVE |
> > OBJ_KERNEL_HANDLE,
> > NULL, NULL);
> >
> > status = ZwOpenFile(&fileHandle, SYNCHRONIZE |
> > FILE_READ_ATTRIBUTES,
> > &objectAttributes, &iosb,
> FILE_SHARE_READ |
> > FILE_SHARE_WRITE,
> > FILE_NON_DIRECTORY_FILE |
> > FILE_SYNCHRONOUS_IO_NONALERT);
> > if (!NT_SUCCESS(status)) {
> > break;
> > }
> >
> > bufferLength = 4 * 1024 * 1024;
> > buffer = ExAllocatePool(PagedPool, bufferLength);
> > if (!buffer) {
> > ZwClose(fileHandle);
> > status = STATUS_INSUFFICIENT_RESOURCES;
> > break;
> > }
> >
> > slib.StartingVcn.QuadPart = 0;
> > status = STATUS_UNSUCCESSFUL;
> > while (!NT_SUCCESS(status)) {
> > status = ZwFsControlFile(fileHandle, NULL, NULL,
> NULL, &iosb,
> > FSCTL_GET_VOLUME_BITMAP, &slib,
> > sizeof(slib), buffer,
> bufferLength);
> > if (!NT_SUCCESS(status)) {
> > if ((STATUS_BUFFER_TOO_SMALL == status) ||
> > (STATUS_BUFFER_OVERFLOW == status)) {
> >
> > ExFreePool(buffer);
> > bufferLength *= 2;
> > buffer = ExAllocatePool(PagedPool, bufferLength);
> > if (!buffer) {
> > status = STATUS_INSUFFICIENT_RESOURCES;
> > break;
> > }
> > } else {
> > break;
> > }
> > }
> > }
> >
> > ZwClose(fileHandle);
> >
> > if (!NT_SUCCESS(status)) {
> > break;
> > }
> >
> > ExFreePool(buffer);
> >
> > } while (FALSE);
> >
> > return status;
> >
> >
> ==============================================================
> ==========
> >
> > Thanks.
> >
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@hollistech.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

thanks.

дÈëÏûÏ¢ÐÂÎÅ:xxxxx@ntdev…
>I do just what you are trying to do and I open it LIKE:
>
> open = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
> share = FILE_SHARE_READ | FILE_SHARE_WRITE;
> options = FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT |
> FILE_RANDOM_ACCESS | FILE_NO_INTERMEDIATE_BUFFERING;
> status_nt = ZwCreateFile (volhandle, open, &objattr, &iosb, NULL,
> FILE_ATTRIBUTE_NORMAL, share, FILE_OPEN,
> options, NULL, 0);
>
> After I do the ZwFsControlFile I do the following to wait for
> any pending I/O:
>
> if (status_nt == STATUS_PENDING)
> {
> ZwWaitForSingleObject (osfree->volhandle, FALSE, NULL);
> status_nt = iosb.Status;
> }
>
>
> Rick Cadruvi…
>