Hi Guys,
Can someone just check the following piece of code over quickly, Im going mad here! :) It must be something really stupid. Basically I have a driver that excepts an IOCTL to send the IRP_MJ_FLUSH_BUFFERS command to a specified drive, but this function just refuses to do it. It returns success but if I monitor the actual activity of the drive (using filespy from ifs kit) I don
t see anything.
Here is my function
VOID FlushVolume( WCHAR Volume )
{
NTSTATUS status;
WCHAR wDrive = L"\??\@:";
UNICODE_STRING us;
PFILE_OBJECT pFileObject;
PDEVICE_OBJECT pDeviceObject;
IO_STATUS_BLOCK iosb;
// Format drive into string
wDrive[4] = Volume;
RtlInitUnicodeString( &us, wDrive );
// Get Fileobject
// I have tried all sorts of access_mask in this call, all with no
success!
status = IoGetDeviceObjectPointer( &us, FILE_GENERIC_WRITE,
&pFileObject, &pDeviceObject );
if( !NT_SUCCESS( status ) )
{
DbgPrint( “Failed open disk : %x\n”, status );
}
else
{
KEVENT event;
PIRP irp;
KeInitializeEvent( &event, NotificationEvent, FALSE );
irp = IoBuildSynchronousFsdRequest( IRP_MJ_FLUSH_BUFFERS,
pDeviceObject,
NULL,
0,
NULL,
&event,
&iosb );
if( !irp )
{
DbgPrint( “Failed to allocate irp for flush : %x\n”,
status );
}
else
{
// Put the fileobject in the iostack location
PIO_STACK_LOCATION iostack =
IoGetNextIrpStackLocation( irp );
iostack->FileObject = pFileObject;
DbgPrint( “About to flush drive…\n”) ;
status = IoCallDriver( pDeviceObject, irp );
if( status == STATUS_PENDING )
{
// DbgPrint( “IoCallDriver returned pending so
wait…\n” ) ;
KeWaitForSingleObject( &event, Executive,
KernelMode, FALSE, NULL );
status = iosb.Status;
}
DbgPrint( “Status from flush buffers : %x\n”,
iosb.Status ) ;
}
ObDereferenceObject( pFileObject );
}
}
Funny thing is that if I use my little console app to do much the same thing
(using flushfilebuffers with a handle to the drive) then it works fine.
Am I missing a trick here
Ben Curley
DESlock+ Lead Programmer
Data Encryption Systems Ltd.
Tel: +44 (0)1823 352357 (Main)
Tel: +44 (0)1823 358320 (Direct Dial)