Need Help with IoBuildSynchronousFsdRequest.

Hello, I am trying to write code that will write to a floppy disk sector.
The code is attached below. The problem is that the function throws an
access violation exception (from somewhere in the fastfat.sys driver) after
calling IoCallDriver to pass the Irp down. I have a similar
ReadFloppySector func that works just fine. Any help would be appreciated,
I am at my wits end with this one. I call the function with a sector number
of 0 (zero). and a valid data buffer of approximately 400 bytes.

NTSTATUS WriteFloppySector(PDEVICE_OBJECT pDeviceObj,
PLARGE_INTEGER sectorNum,
BYTE *pData,
ULONG dataSize)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT pFloppyDevObj = NULL;
PFILE_OBJECT pFileObj = NULL;
BYTE *pBuffer = NULL;
UNICODE_STRING ntFloppyString;

ASSERT(dataSize <= 512);
ASSERT(sectorNum);

__try
{
__try
{
pBuffer = (BYTE *)ExAllocatePool(NonPagedPool, 512);
if (!pBuffer)
return STATUS_INSUFFICIENT_RESOURCES;

RtlZeroMemory(pBuffer, 512);
RtlInitUnicodeString(&ntFloppyString, L"\DosDevices\A:");

status = IoGetDeviceObjectPointer(&ntFloppyString,
FILE_WRITE_DATA,
&pFileObj,
&pFloppyDevObj);
if (NT_SUCCESS(status))
{
IO_STATUS_BLOCK ioStatus;
KEVENT event;
PIRP pIrp;

// Take out a reference on the object.
ObReferenceObjectByPointer(pFloppyDevObj,
FILE_WRITE_DATA,
NULL,
KernelMode);

// If pData is NULL, we just write out the
// zeroed memory clearing the disk sector.
if (pData)
RtlCopyMemory(pBuffer, pData, dataSize);

KeInitializeEvent(&event, NotificationEvent, FALSE);

pIrp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
pFloppyDevObj,
pBuffer,
512,
sectorNum,
&event,
&ioStatus);
if (pIrp)
{
status = IoCallDriver(pFloppyDevObj, pIrp);
if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event,
Executive,
KernelMode,
FALSE,
NULL);

status = ioStatus.Status;
}
}
else
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
}
}
__except(ExceptionFilter(GetExceptionInformation(), pDeviceObj))
{
status = STATUS_ACCESS_VIOLATION;
}
}

__finally
{
if (NULL != pFileObj)
ObDereferenceObject(pFileObj);

if (NULL != pBuffer)
ExFreePool(pBuffer);
}
return status;
}// WriteFloppySector()


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com