Can't return all errors to CreateFile

I think I’m missing something here but my IRP_MJ_CREATE handler doesn’t seem to produce the correct result.

This makes the file handle returned from CreateFile NULL and GetLastError returns 5.

Irp->IoStatus.Information = 0; // seems to not matter what I put here
Irp->IoStatus.Status = STATUS_ACCESS_DENIED; // seems to matter
IoCompleteRequest(Irp, IO_NO_INCREMENT);

return STATUS_SUCCESS;

This makes the file handle returned from CreateFile 0x28 and GetLastError returns 0.

Irp->IoStatus.Information = 0; // seems to not matter what I put here
Irp->IoStatus.Status = FILE_DOES_NOT_EXIST;//STATUS_ACCESS_DENIED;
IoCompleteRequest(Irp, IO_NO_INCREMENT);

return STATUS_SUCCESS;

Can someone explain the rules for this? Or am I missing something completely obvious? I can’t seem to find an elaboration in the wdk doc.

This is a simple wdm driver.

Thanks.

> Irp->IoStatus.Status = FILE_DOES_NOT_EXIST;//STATUS_ACCESS_DENIED;

Stop ever using Win32 error codes like FILE_DOES_NOT_EXIST for NTSTATUS values.

They are completely different and not interchangeable.

Any kmode code only uses NTSTATUS and not Win32.

Just look at the NTSTATUS version of FILE_DOES_NOT_EXIST and use it.

The mapping from NTSTATUS to Win32 errors is published as MS KB article.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

Wow. I went completely blind on that one.
I pretty much knew what you said, I just couldn’t see it.

Thanks a million. That was it.

You must also return the same ntstatus value as the one you put into the irp

d

Bent from my phone


From: xxxxx@yahoo.commailto:xxxxx
Sent: ?10/?22/?2014 5:45 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Can’t return all errors to CreateFile

Wow. I went completely blind on that one.
I pretty much knew what you said, I just couldn’t see it.

Thanks a million. That was it.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>