ZwCreateFile to open volume handle?

Hi all,
I want to use ZwCreateFile to open a volume handle in dispatchdevicecontrol routine, but the ZwCreateFile returns STATUS_FILE_LOCK_CONFLICT.
The same code works fine in adddevice routine…

How could I get a volume handle in dispatchdevicecontrol routine?

Thanks…

As alternative, you can obtain a DEVICE_OBJECT pointer for the volume
and send IRPs directly.


Best regards,
Vladimir Zinin
mailto:xxxxx@gmail.com

xxxxx@yahoo.com.cn wrote:

Hi all,
I want to use ZwCreateFile to open a volume handle in dispatchdevicecontrol routine, but the ZwCreateFile returns STATUS_FILE_LOCK_CONFLICT.
The same code works fine in adddevice routine…

How could I get a volume handle in dispatchdevicecontrol routine?

Thanks…

Thanks Vladimir Zinin~~
I know how to send IRPs directly to the volume.But I just want to use the volume handle to send FSCTLs to the volume. Or you mean I can send FSCTLs to volume by using IRPs?

Thanks~

Yes, FSCTL irps can be sent directly.

But may be the problem is not in the volume locking.
Based on FATFS sources, the status STATUS_FILE_LOCK_CONFLICT can emit
from here:

//
// If this request is not a “top-level” irp, just complete it.
//

if (FlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_RECURSIVE_CALL)) {

//
// If there is a cache operation above us, commute verify
// to a lock conflict. This will cause retries so that
// we have a chance of getting through without needing
// to return an unaesthetic error for the operation.
//

if (IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP &&
ExceptionCode == STATUS_VERIFY_REQUIRED) {

ExceptionCode = STATUS_FILE_LOCK_CONFLICT;
}

FatCompleteRequest( IrpContext, Irp, ExceptionCode );

return ExceptionCode;
}

Check in the dispatchdevicecontrol routine that
IoGetTopLevelIrp() != (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP.


Best regards,
Vladimir Zinin
mailto:xxxxx@gmail.com

xxxxx@yahoo.com.cn wrote:

Thanks Vladimir Zinin~~
I know how to send IRPs directly to the volume.But I just want to use the volume handle to send FSCTLs to the volume. Or you mean I can send FSCTLs to volume by using IRPs?

Thanks~