ZwCreateFile failing with status 0xC0000043L - STATUS_SHARING_VIOLATION

Hi

The code is as follows

Opening the file

NTSTATUS status;
OBJECT_ATTRIBUTES ObjectAttributes;
FILE_STANDARD_INFORMATION StandardInfo;

InitializeObjectAttributes ( &ObjectAttributes,
unicodeName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL );

status = ZwCreateFile( &fileHandle,
FILE_WRITE_DATA,
&ObjectAttributes,
&m_iosbCreateStatus,
(PLARGE_INTEGER)&allocationSize,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_CREATE,
FILE_NO_INTERMEDIATE_BUFFERING,
NULL, // eabuffer
0 ); // ealength

if (NT_SUCCESS(status)) {
status = ObReferenceObjectByHandle(
fileHandle,
0,
*IoFileObjectType,
KernelMode,
(PVOID *) &fileObject,
NULL);

osDevice = IoGetRelatedDeviceObject(fileObject);
// bugbug error processing if any of these fails
} else {
fileHandle = 0;
fileObject = NULL;
osDevice = NULL;
}

Then I am writing using that file and then closing the filehandle.

Then later I want to delete it. So, I am opening that file but it is failing with STATUS_SHARING_VIOLATION. The Code is as follows

Status = File.Open(FileName,
DELETE,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_ALERT,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
0);

NTSTATUS status;
OBJECT_ATTRIBUTES ObjectAttributes;
FILE_STANDARD_INFORMATION StandardInfo;

InitializeObjectAttributes ( &ObjectAttributes,
unicodeName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL );

status = ZwCreateFile( &fileHandle,
DELETE,
&ObjectAttributes,
&m_iosbCreateStatus,
(PLARGE_INTEGER)&allocationSize,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN,
FILE_NO_INTERMEDIATE_BUFFERING,
NULL, // eabuffer
0 ); // ealength

Chat on a cool, new interface. No download required. Go to http://in.messenger.yahoo.com/webmessengerpromo.php

Hi

Earlier mail was sent accidently. Sorry for that.
I am earlier opening the file with shareaccess as 0. Then Write it and close it. Later when I tried to open it with shareaccess as
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE. Then it was failing with status STATUS_SHARING_VIOLATION

For Opening the file

NTSTATUS status;
OBJECT_ATTRIBUTES ObjectAttributes;
FILE_STANDARD_INFORMATION StandardInfo;

InitializeObjectAttributes ( &ObjectAttributes,
unicodeName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL );

status = ZwCreateFile( &fileHandle,
FILE_WRITE_DATA,
&ObjectAttributes,
&iosbCreateStatus,
(PLARGE_INTEGER)&allocationSize,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_CREATE,
FILE_NO_INTERMEDIATE_BUFFERING,
NULL, // eabuffer
0 ); // ealength

Then I am writing using the file handle and then closing the filehandle.

Then later I need to delete it. So, I am opening that file but it is failing with STATUS_SHARING_VIOLATION. The Code is as follows

NTSTATUS status;
OBJECT_ATTRIBUTES ObjectAttributes;
FILE_STANDARD_INFORMATION StandardInfo;

InitializeObjectAttributes ( &ObjectAttributes,
unicodeName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL );

status = ZwCreateFile( &fileHandle,
DELETE,
&ObjectAttributes,
&iosbCreateStatus,
(PLARGE_INTEGER)&allocationSize,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE |FILE_SHARE_DELETE,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_ALERT,
NULL, // eabuffer
0}

Please, tell me how to achieve the same

Thanks and Regards
Pankaj

Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/

In your first example you are calling ObReferenceObjectByHandle to get the file object for the handle. Are you calling ObDereferenceObject after closing the handle? If not the file object will never go away.

Hi

I have modified the code where I am not referencing the object. I am performing above procedure for almost more than 20 files. But, this error condition I am getting once in while.

Thanks and Regards
Pankaj

Meet people who discuss and share your passions. Go to http://in.promos.yahoo.com/groups

Please try shared access as FILE_SHARE_READ | FILE_SHARE_WRITE |FILE_SHARE_DELETE in earlier open also.

I tried using that but it is not solving the problem. ZwCreateFile() is still failing with status 0xC0000043L - STATUS_SHARING_VIOLATION

  • Pankaj

Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/

So obviously the file is still open. Your code has left an outstanding
reference on the fileobject somewhere.

On Jan 25, 2008 6:56 AM, pankaj kale wrote:

> I tried using that but it is not solving the problem. ZwCreateFile() is
> still failing with status 0xC0000043L - STATUS_SHARING_VIOLATION
>
> - Pankaj
>
>
> Unlimited freedom, unlimited storage. Get it now, on
> http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Mark Roddy

The point I think is that the OP really does not want to share anything on
the first access. He then closes the file but it appears as if he has not
correctly closed all of his many references to the first file object, so
that when he tries to open the file subsequently with more generous share
access, it fails. He is not completely cleaning up from the original
unshared access.

On Jan 25, 2008 2:26 AM, wrote:

> Please try shared access as FILE_SHARE_READ | FILE_SHARE_WRITE
> |FILE_SHARE_DELETE in earlier open also.
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule debugging and file system seminars
> (including our new fs mini-filter seminar) visit:
> http://www.osr.com/seminars
>
> You are currently subscribed to ntfsd as: xxxxx@hollistech.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Mark Roddy

Try to modify the share flags or adjust process privileges

??2008-01-25??“pankaj kale” д???

Hi

I have modified the code where I am not referencing the object. I am performing above procedure for almost more than 20 files. But, this error condition I am getting once in while.

Thanks and Regards
Pankaj

Meet people who discuss and share your passions. Go to http://in.promos.yahoo.com/groups


NTFSD is sponsored by OSR

For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

| liyuncheng : wrote

Try to modify the share flags or adjust process privileges

>>I tried sharing (FILE_SHARE_READ | FILE_SHARE_WRITE |FILE_SHARE_DELETE)
on >>the first access. Still, the problem is there as I mentioned earlier.

Mark Roddy wrote:

The point I think is that the OP really does not want to share anything
on the first access. He then closes the file but it appears as if he
has not correctly closed all of his many references to the first file
object, so that when he tries to open the file subsequently with more
generous share access, it fails. He is not completely cleaning up from
the original unshared access.

>>I have not referenced
the file object. I was doing all the file operations in System Worker >>Thread. I have
seen the handles for system process it does not show me the handle for
>>that file. ZwClose() also works fine for the first open.

Is there any way, I can check if the there may be reference left to the file object

-Pankaj

|


Meet people who discuss and share your passions. Join them now.

I thought of one scenario which might be a possible cause for this problem.
At the first time when you close the file using ZwClose()( ZwClose() is a
cleanup for file handle not for file object), it might be possible that
Close IRP for this file has not yet reached and you tried to open the file
again before close IRP reaches file system

James

Is there any way to check for the possibility which James mentioned ?

-Pankaj

Chat on a cool, new interface. No download required. Go to http://in.messenger.yahoo.com/webmessengerpromo.php

>>I thought of one scenario which might be a possible cause for this >>problem.At the first time when you close the file using ZwClose()( >>ZwClose() is a cleanup for file handle not for file object), it might be >>possible that Close IRP for this file has not yet reached and you tried >>to open the file again before close IRP reaches file system

I think what, what James is pointing may be correct. I am retrying to delete the file in a loop and after a no of failures that file got opened with ZwCreateFile() and got successfully deleted.

Please, tell me the correct reason why it succeeded after a no of tries and not on first.

One more thing I observed is that I stored the fileobject pointer somewhere when I first opened the file But I am not referencing the file object. I am checking this fileobject pointer when ZwCreateFile() fails with status STATUS_SHARING_VIOLATION while deleting the file.

When I did a !object on the file object pointer I got some different file name in it. Does this tells earlier file object got closed.

Please, correct me if I am wrong

-Pankaj

Now you can chat without downloading messenger. Go to http://in.messenger.yahoo.com/webmessengerpromo.php

After ZwCreateFile() returning STATUS_SHARING_VIOLATION, I retried with a delay of 10 sec. ZwCreateFile() succeeded and file got deleted successfully.
Can someone tell why this is happening ?

Chat on a cool, new interface. No download required. Go to http://in.messenger.yahoo.com/webmessengerpromo.php

I can’t tell you why it is happening but I had the same problem in two
different drivers. I got around the error by retrying the operation.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of pankaj kale
Sent: Friday, February 15, 2008 12:46 AM
To: Windows File Systems Devs Interest List
Subject: Re: RE:[ntfsd] ZwCreateFile failing with status 0xC0000043L -
STATUS_SHARING_VIOLATION

After ZwCreateFile() returning STATUS_SHARING_VIOLATION, I retried with a
delay of 10 sec. ZwCreateFile() succeeded and file got deleted successfully.
Can someone tell why this is happening ?

Chat on a cool, new interface. No download required. Go to
http://in.messenger.yahoo.com/webmessengerpromo.php


NTFSD is sponsored by OSR

For our schedule debugging and file system seminars (including our new fs
mini-filter seminar) visit:
http://www.osr.com/seminars

You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

In my case, after first ZwCreateFile() failure, first retry (after a delay of 10 sec) ZwCreateFile() succeeds every time. I am seeing this consistently. Can I assume that same will happen consistently ?

Save all your chat conversations. Find them online at http://in.messenger.yahoo.com/webmessengerpromo.php