Problem with CreateFile

Dear sirs,
I am posting the question here because 1) it is part of my FSD
development and 2) I have performed Google search on this topic with no
result.
Situation:
CreateFile (…,OPEN_EXISTING,…) returns INVALID_HANDLE_VALUE with
GetLastError() returning ERROR_ALREADY_EXISTS. The file in question
exists (but has attributes SYSTEM and HIDDEN).
Question: what does it mean?

You didn’t specify the right attributes on the file. Were I to hazard a
guess, this is the usual way that Win32 maps all rich meaningful OS
level errors into mush to return to unsuspecting application programmers
(we wouldn’t want application programmers to really understand what’s
going on now would we!)

Regards,

Tony

Tony Mason

Consulting Partner

OSR Open Systems Resources, Inc.

http://www.osr.com

Looking forward to seeing you at the next OSR File Systems class in
Boston, MA April 18-21, 2006 (note new date - MS scheduled plugfest the
same week again.)


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Yakov Kaabak
Sent: Wednesday, March 01, 2006 11:06 AM
To: ntfsd redirect
Subject: [ntfsd] Problem with CreateFile

Dear sirs,

I am posting the question here because 1) it is part of my FSD
development and 2) I have performed Google search on this topic with no
result.

Situation:

CreateFile (…,OPEN_EXISTING,…) returns INVALID_HANDLE_VALUE with
GetLastError() returning ERROR_ALREADY_EXISTS. The file in question
exists (but has attributes SYSTEM and HIDDEN).

Question: what does it mean?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

The status ERROR_ALREADY_EXISTS makes sense in this case because the file
attributes themselves are preventing the CREATE from succeeding unless you
specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM in the
dwFlagsAndAttributes argument.

/ted

-----Original Message-----
From: Yakov Kaabak [mailto:xxxxx@parallels.com]
Sent: Wednesday, March 01, 2006 11:06 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Problem with CreateFile

Dear sirs,
I am posting the question here because 1) it is part of my FSD development
and 2) I have performed Google search on this topic with no result.
Situation:
CreateFile (…,OPEN_EXISTING,…) returns INVALID_HANDLE_VALUE with
GetLastError() returning ERROR_ALREADY_EXISTS. The file in question exists
(but has attributes SYSTEM and HIDDEN).
Question: what does it mean?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

> attributes themselves are preventing the CREATE from succeeding unless you

specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM
Not the case, sorry. The following works just fine:

hFile = CreateFile(“C:\cmldr”, GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

for read-only hidden system C:\cmldr.

Most probably OP really screwed up attrs (and/or sharing etc.).
For a file to be RO-S-H is not enough.

From: Ted Hess
> Date: 2006/03/01 Wed PM 12:43:54 EST
> To: “Windows File Systems Devs Interest List”
> Subject: RE: [ntfsd] Problem with CreateFile
>
> The status ERROR_ALREADY_EXISTS makes sense in this case because the file
> attributes themselves are preventing the CREATE from succeeding unless you
> specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM in the
> dwFlagsAndAttributes argument.
>
> /ted
>
> -----Original Message-----
> From: Yakov Kaabak [mailto:xxxxx@parallels.com]
> Sent: Wednesday, March 01, 2006 11:06 AM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Problem with CreateFile
>
>
> Dear sirs,
> I am posting the question here because 1) it is part of my FSD development
> and 2) I have performed Google search on this topic with no result.
> Situation:
> CreateFile (…,OPEN_EXISTING,…) returns INVALID_HANDLE_VALUE with
> GetLastError() returning ERROR_ALREADY_EXISTS. The file in question exists
> (but has attributes SYSTEM and HIDDEN).
> Question: what does it mean?
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@bellsouth.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

You are right. Should put my brain in gear before typing a response
sometimes.

/ted

-----Original Message-----
From: xxxxx@bellsouth.net [mailto:xxxxx@bellsouth.net]
Sent: Wednesday, March 01, 2006 4:00 PM
To: Windows File Systems Devs Interest List
Subject: Re: RE: [ntfsd] Problem with CreateFile

attributes themselves are preventing the CREATE from succeeding unless
you specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM
Not the case, sorry. The following works just fine:

hFile = CreateFile(“C:\cmldr”, GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

for read-only hidden system C:\cmldr.

Most probably OP really screwed up attrs (and/or sharing etc.). For a file
to be RO-S-H is not enough.

From: Ted Hess
> Date: 2006/03/01 Wed PM 12:43:54 EST
> To: “Windows File Systems Devs Interest List”
> Subject: RE: [ntfsd] Problem with CreateFile
>
> The status ERROR_ALREADY_EXISTS makes sense in this case because the
> file attributes themselves are preventing the CREATE from succeeding
> unless you specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM in
> the dwFlagsAndAttributes argument.
>
> /ted
>
> -----Original Message-----
> From: Yakov Kaabak [mailto:xxxxx@parallels.com]
> Sent: Wednesday, March 01, 2006 11:06 AM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] Problem with CreateFile
>
>
> Dear sirs,
> I am posting the question here because 1) it is part of my FSD
> development and 2) I have performed Google search on this topic with
> no result.
> Situation:
> CreateFile (…,OPEN_EXISTING,…) returns INVALID_HANDLE_VALUE with
> GetLastError() returning ERROR_ALREADY_EXISTS. The file in question exists
> (but has attributes SYSTEM and HIDDEN).
> Question: what does it mean?
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@bellsouth.net To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@livevault.com To unsubscribe
send a blank email to xxxxx@lists.osr.com

It is not clear from your message: are you opening file which is located on
the FS you are developing or you are trying to open the file on standard NTFS
or FAT? It would also help if you provide all parameters for CreateFile call.

Alexei.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Yakov Kaabak
Sent: Wednesday, March 01, 2006 8:06 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Problem with CreateFile

Dear sirs,
I am posting the question here because 1) it is part of my FSD development
and 2) I have performed Google search on this topic with no result.
Situation:
CreateFile (…,OPEN_EXISTING,…) returns INVALID_HANDLE_VALUE with
GetLastError() returning ERROR_ALREADY_EXISTS. The file in question exists
(but has attributes SYSTEM and HIDDEN).
Question: what does it mean?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

Thank everybody for response.
My project is Shared folders for Parallels Virtual Machines. It consists
of filesystem driver at the guest side and sort of file server code on
the host side.
The CreateFile in question originates in ifstest program (group
OpenCreateParameters) running in guest system and is called on the host
side in response to guest open file request.

This error appears both on NTFS and on FAT filesystems.

As for FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM, some messages in
ifstest program say about it, that return value must be
ERROR_ACCESS_DENIED rather than ERROR_ALREADY_EXISTS, and I take it into
account.
The arguments to CreateFile are as follows:
CreateFileW ((WCHAR*)m_qName.data(),
SYNCHRONIZE | READ_CONTROL |
FILE_WRITE_ATTRIBUTES |
FILE_READ_ATTRIBUTES |
FILE_WRITE_EA | FILE_READ_DATA |
FILE_WRITE_DATA |
FILE_APPEND_DATA | FILE_READ_EA,
/* 0012019f */
0, NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM, /* 00000006 */
NULL);
Attributes of file in question are
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_ARCHIVE /* 00000027 */.

Now when typing this message I found that file is readonly and I am
requesting write access. But if access can't be granted
ERROR_ACCESS_DENIED must be returned, isn't it?

The original access mask coming from guest side is FILE_WRITE_ATTRIBUTES
(00000100). Prior to calling CreateFile I extend it in this way (Maybe I
am wrong in it): if accessmask & FILE_GENERIC_WRITE is non zero, I add
whole FILE_GENERIC_WRITE to it, and the same regarding
FILE_GENERIC_READ.

I do it because when I ran ifstest DirectoryInformation test I found
file was open without READ_DATA right, but it was attempted to read. It
failed with ERROR_ACCESS_DENIED, ifstest complained.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ted Hess
Sent: Wednesday, March 01, 2006 8:44 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Problem with CreateFile

The status ERROR_ALREADY_EXISTS makes sense in this case because the
file attributes themselves are preventing the CREATE from succeeding
unless you specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM in the
dwFlagsAndAttributes argument.

/ted

-----Original Message-----
From: Yakov Kaabak [mailto:xxxxx@parallels.com]
Sent: Wednesday, March 01, 2006 11:06 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Problem with CreateFile
Dear sirs,
I am posting the question here because 1) it is part of my FSD
development and 2) I have performed Google search on this topic with no
result.
Situation:
CreateFile (...,OPEN_EXISTING,...) returns INVALID_HANDLE_VALUE with
GetLastError() returning ERROR_ALREADY_EXISTS. The file in question
exists (but has attributes SYSTEM and HIDDEN).
Question: what does it mean?


Questions? First check the IFS FAQ at

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

Questions? First check the IFS FAQ at

You are currently subscribed to ntfsd as: xxxxx@parallels.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Am I understand you correctly: on the host you invoked CreateFileW with the
parameters you specified and that call returned ERROR_ALREADY_EXISTS?
That doesn't sound rigth - I would expect to get ERROR_ACCESS_DENIED. You can
use Filemon to get additional information. Or build FAT from source and use
debugger to check what status it returns and why.

Thank you,
Alexei.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Yakov Kaabak
Sent: Thursday, March 02, 2006 1:04 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Problem with CreateFile

Thank everybody for response.
My project is Shared folders for Parallels Virtual Machines. It consists of
filesystem driver at the guest side and sort of file server code on the host
side.
The CreateFile in question originates in ifstest program (group
OpenCreateParameters) running in guest system and is called on the host side
in response to guest open file request.

This error appears both on NTFS and on FAT filesystems.

As for FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM, some messages in
ifstest program say about it, that return value must be ERROR_ACCESS_DENIED
rather than ERROR_ALREADY_EXISTS, and I take it into account.
The arguments to CreateFile are as follows:
CreateFileW ((WCHAR*)m_qName.data(),
SYNCHRONIZE | READ_CONTROL |
FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES |
FILE_WRITE_EA | FILE_READ_DATA |
FILE_WRITE_DATA |
FILE_APPEND_DATA | FILE_READ_EA,
/* 0012019f */
0, NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM,
/* 00000006 */
NULL);
Attributes of file in question are
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY |
FILE_ATTRIBUTE_ARCHIVE /* 00000027 */.

Now when typing this message I found that file is readonly and I am
requesting write access. But if access can't be granted ERROR_ACCESS_DENIED
must be returned, isn't it?

The original access mask coming from guest side is FILE_WRITE_ATTRIBUTES
(00000100). Prior to calling CreateFile I extend it in this way (Maybe I am
wrong in it): if accessmask & FILE_GENERIC_WRITE is non zero, I add whole
FILE_GENERIC_WRITE to it, and the same regarding FILE_GENERIC_READ.

I do it because when I ran ifstest DirectoryInformation test I found file was
open without READ_DATA right, but it was attempted to read. It failed with
ERROR_ACCESS_DENIED, ifstest complained.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ted Hess
Sent: Wednesday, March 01, 2006 8:44 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Problem with CreateFile

The status ERROR_ALREADY_EXISTS makes sense in this case because the file
attributes themselves are preventing the CREATE from succeeding unless you
specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM in the
dwFlagsAndAttributes argument.

/ted

-----Original Message-----
From: Yakov Kaabak [mailto:xxxxx@parallels.com]
Sent: Wednesday, March 01, 2006 11:06 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Problem with CreateFile
Dear sirs,
I am posting the question here because 1) it is part of my FSD development
and 2) I have performed Google search on this topic with no result.
Situation:
CreateFile (...,OPEN_EXISTING,...) returns INVALID_HANDLE_VALUE with
GetLastError() returning ERROR_ALREADY_EXISTS. The file in question exists
(but has attributes SYSTEM and HIDDEN).
Question: what does it mean?


Questions? First check the IFS FAQ at

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

Questions? First check the IFS FAQ at

You are currently subscribed to ntfsd as: xxxxx@parallels.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at

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

Yes, you understand correctly. I try to open existing file and result is
ERROR_ALREADY_EXISTS (STATUS_OBJECT_NAME_COLLISION according to MSDN). I
would expect ERROR_ACCESS_DENIED too. I browsed fastfat sources to find
this word (STATUS_OBJECT_NAME_COLLISION) and found it only in right
places - where there is attempt to create exisiing file. As for filemon,
it doesn't show anything at all about this request. All this means for
me that this status is generated somewhere within Io manager (prior to
sending IRP_MJ_CREATE).
Anyway, thank you for response.
Yakov.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alexei Jelvis
Sent: Thursday, March 02, 2006 10:13 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Problem with CreateFile

Am I understand you correctly: on the host you invoked CreateFileW with
the parameters you specified and that call returned
ERROR_ALREADY_EXISTS?
That doesn't sound rigth - I would expect to get ERROR_ACCESS_DENIED.
You can use Filemon to get additional information. Or build FAT from
source and use debugger to check what status it returns and why.

Thank you,
Alexei.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Yakov Kaabak
Sent: Thursday, March 02, 2006 1:04 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Problem with CreateFile
Thank everybody for response.
My project is Shared folders for Parallels Virtual Machines. It
consists of filesystem driver at the guest side and sort of file server
code on the host side.
The CreateFile in question originates in ifstest program (group
OpenCreateParameters) running in guest system and is called on the host
side in response to guest open file request.

This error appears both on NTFS and on FAT filesystems.

As for FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM, some
messages in ifstest program say about it, that return value must be
ERROR_ACCESS_DENIED rather than ERROR_ALREADY_EXISTS, and I take it into
account.
The arguments to CreateFile are as follows:
CreateFileW ((WCHAR*)m_qName.data(),
SYNCHRONIZE | READ_CONTROL |
FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES
|
FILE_WRITE_EA | FILE_READ_DATA |
FILE_WRITE_DATA |
FILE_APPEND_DATA | FILE_READ_EA,
/* 0012019f */
0, NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM, /* 00000006 */
NULL);
Attributes of file in question are
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE /* 00000027 */.

Now when typing this message I found that file is readonly and I
am requesting write access. But if access can't be granted
ERROR_ACCESS_DENIED must be returned, isn't it?

The original access mask coming from guest side is
FILE_WRITE_ATTRIBUTES (00000100). Prior to calling CreateFile I extend
it in this way (Maybe I am wrong in it): if accessmask &
FILE_GENERIC_WRITE is non zero, I add whole FILE_GENERIC_WRITE to it,
and the same regarding FILE_GENERIC_READ.

I do it because when I ran ifstest DirectoryInformation test I
found file was open without READ_DATA right, but it was attempted to
read. It failed with ERROR_ACCESS_DENIED, ifstest complained.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ted Hess
Sent: Wednesday, March 01, 2006 8:44 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Problem with CreateFile

The status ERROR_ALREADY_EXISTS makes sense in this case because
the file attributes themselves are preventing the CREATE from succeeding
unless you specify FILE_ATTRIBUTE_HIDDEN & FILE_ATTRIBUTE_SYSTEM in the
dwFlagsAndAttributes argument.

/ted

-----Original Message-----
From: Yakov Kaabak [mailto:xxxxx@parallels.com]
Sent: Wednesday, March 01, 2006 11:06 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Problem with CreateFile
Dear sirs,
I am posting the question here because 1) it is part of my FSD
development and 2) I have performed Google search on this topic with no
result.
Situation:
CreateFile (...,OPEN_EXISTING,...) returns INVALID_HANDLE_VALUE
with GetLastError() returning ERROR_ALREADY_EXISTS. The file in question
exists (but has attributes SYSTEM and HIDDEN).
Question: what does it mean?


Questions? First check the IFS FAQ at

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

Questions? First check the IFS FAQ at

You are currently subscribed to ntfsd as: xxxxx@parallels.com
To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the IFS FAQ at

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


Questions? First check the IFS FAQ at

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