I’m looking at an issue where my driver has problem executing FSCTL_LOCK_VOLUME control code. The drive does issue FSCTL_DISMOUNT_VOLUME command (kind of dangerous, but don’t have other option) and the try to lock it. It appears that FSCTL_DISMOUNT_VOLUME causes other drivers to do FLUSH, so I endup having open handle. I want to handle this situation by doing synchronous call ZwFsControlFile(FSCTL_DISMOUNT_VOLUME) and wondering how I do that . My existing code is
status = ZwCreateFile( &(pVolumeExtension->hVolume),
SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE, // 0,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH | FILE_NO_INTERMEDIATE_BUFFERING,
NULL,
0);
status = ZwFsControlFile( pVolumeExtension->hVolume,
NULL, NULL,
NULL, &IoStatus,
FSCTL_DISMOUNT_VOLUME,
NULL, 0, NULL, 0 );
What should be my next step. Documents say that I can wait on FileHandle, but now sure how can I do that. Do I need to define and pass handle to an kEvent to ZwFsControlFile() and then call KeWaitForSingleObject(). Are args to ZwCreateFile() OK. I want to make sure that DISMOUNT has been completed all the way down to file system.