OSRLogo
OSRLogoOSRLogoOSRLogo x Seminar Ad
OSRLogo
x

Everything Windows Driver Development

x
x
x
GoToHomePage xLoginx
 
 

    Thu, 02 Sep 2010     81215 members

   Login
   Join


 
 
Contents
  About This Site
What's New?
Hector's Memos
The NT Insider
The Basics
File Systems
Downloads
ListServer / Forum
Driver Jobs
Store
  Express Links
  · It's Here: The NT Insider -- Digital Edition!
  · WDK Community Bug Bash 2010 -- Submit a Bug... Get FREE STUFF!
  · File Systems and Filters: A Specialty
  · It's All About The Basics
  · The NT Insider - Digital Edition

Mapping Win32 to Internal File Creation Options

The NTFSD list has discussed the semantics of file creation and we thought it would be a good idea to capture that information (and add it to the database of information we have for Windows file systems).

Specifically, the Win32 API defines five different creation options.  Each of these maps to underlying Windows behavior:

  • OPEN_EXISTING - this maps to the Windows FILE_OPEN option, and causes the file to be opened if it exists.  If it does not exist, the call fails.
  • CREATE_NEW - this maps to the Windows FILE_CREATE option, and causes the file to be newly created.  If it exists, the call fails.
  • OPEN_ALWAYS - this maps to the Windows FILE_OPEN_IF option, and causes the file to be opened if it exists, created if it does not.
  • CREATE_ALWAYS - this maps to the Windows FILE_OVERWRITE_IF option, and causes the file to be opened and truncated if it exists (including all streams of the file).  If the file does not exist, it is newly created.
  • TRUNCATE_EXISTING - this maps to the Windows FILE_OPEN but is then followed by an IRP_MJ_SET_INFORMATION call to set the size of the file to zero.  If the file dos not exist, this call fails.

This mapping, and the corresponding semantics are not necessarily clear:

  • FILE_OVERWRITE_IF will destroy all named streams in an NTFS file.
  • FILE_SUPERSEDE requires FILE_DELETE access
  • FILE_OVERWRITE and FILE_OVERWRITE_IF require FILE_WRITE_DATA access.
  • FILE_OVERWRITE_IF requires FILE_DELETE access on any data streams currently open for the given file.

Note that the semantic differences between FILE_OVERWRITE_IF and FILE_SUPSERSEDE are small and subtle.  For example, if a file is overwritten, the state of the attribute bits of the file are preserved (system, hidden, archive) while if the file is superseded, the attribute bits of the file are reset.  Of course, there is no mapping from Win32 semantics to FILE_SUPERSEDE for any of the cases anyway, so this is not a frequently observed operation.

 

User Comments
Rate this article and give us feedback. Do you find anything missing? Share your opinion with the community!
Post Your Comment

"TRUNCATE_EXISTING"
Juat a note about TRUNCATE_EXISTING. We see that the IRP_MJ_SET_INFORMATION which follows the FILE_OPEN is for information class FILE_ALLOCATION_INFORMATION with ((PFILE_ALLOCATION_INFORMATION)(pIrp->AssociatedIrp.SystemBuffer))->AllocationSize.QuadPart equal to zero.

Rating:
30-Jun-04, Lyndon Clarke


""FILE_SUPERCEDE""
From ntifs.h:

#define FILE_SUPERSEDE 0x00000000

09-Jun-04, Daniel Root


"FILE_SUPERCEDE"
Not FILE_SUPERSEDE

Rating:
08-Jun-04, benson margulies


Post Your Comments.
Print this article.
Email this article.

Writing WDM Drivers LAB
Seattle, WA
16-Aug-2010 to 20-Aug-2010

Writing WDF Drivers LAB
Santa Clara, CA
27-Sept-2010 to 1-Oct-2010

Kernel Debugging &
Crash Analysis LAB

Portland, OR
18-Oct-2010 to 22-Oct-2010

Developing File Systems
Santa Clara, CA
26-Oct-2010 to 29-Oct-2010

Windows Internals &
Software Drivers LAB

Santa Clara, CA
15-Nov-2010 to 19-Nov-2010

 
 

Windows Debugger
V6.12.2.633 -- 26 Feb 10

Checked Build Downloads
29-Apr-10

Debugging Symbols
5-Oct-09
 

WDK Doc Updates
Now updated bi-monthly!

Windows WDK
V7.1.0 -- 26 Feb 10

 
 
x
LetUsHelp
 

Need to develop a Windows file system solution?

We've got a kit for that.

Need Windows internals or kernel driver expertise?

Bring us your most challenging project - we can help!

System hangs/crashes?

We've got a special diagnostic team that's standing by.

Visit the OSR Corporate Web site for more information about how OSR can help!

 
bottom nav links