Tech Support > Microsoft Windows > Drivers > Help with ZwWriteFile - Vista
Help with ZwWriteFile - Vista
Posted by vs on September 28th, 2007


Hi,

I am using a driver to write a special partition on the hard drive -
not the boot volume - using ZwWriteFile. The write goes through for
the first LBA of this partition but for all other LBA, the write fails
with access denied.

I am opening the file as below:
---------------
RtlInitUnicodeString(&hdd, L"\\??\\PhysicalDrive0");
InitializeObjectAttributes(&obj_attr, &hdd, OBJ_CASE_INSENSITIVE |
OBJ_KERNEL_HANDLE, NULL, NULL);
if ( (rc = ZwCreateFile(file_handle_ptr,
GENERIC_READ | GENERIC_WRITE,
&obj_attr, &io_status, NULL, FILE_ATTRIBUTE_NORMAL,
0, FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT |
FILE_NON_DIRECTORY_FILE,
NULL, 0) != STATUS_SUCCESS) )
return rc;
---------------
and using below to do the write. Here first_part_lba is the first LBA
of the partition and the write_lba is the offset into that partition.
If I pass write_lba as 0, my write goes through but all other writes
faile due to access denied.
---------------
offset.QuadPart = (write_lba + first_part_lba) * 512;
if ( (rc = ZwWriteFile(file_handle, NULL, NULL, NULL,
&io_status,
buffer, out_bfr_len, &offset, NULL)) ==
STATUS_SUCCESS )
irp->IoStatus.Information = MmGetMdlByteCount(irp-
DbgPrint("error = %x\n", rc);
----------------
As you can see from the write code snippet, the write is happening on
behalf of a user space application that sends me an IOCTL.

The partition I am writing to has a properietary type - 0x99. So there
is no drive letter associated with it and is shown as a simple,basic,
primary partition by the disk manager.

Much appreciate any help on this topic. Thanks in advance.


Posted by vs on September 29th, 2007


I was able to resolve this by opening the specific partition that I am
interested in instead of the drive.


vs wrote:


Similar Posts