You don’t appear to have deleted the file between the two runs, note that in
your second version the file already has a non-zero AllocationSize and
EndOfFile. So it would appear that you’re mixing cached I/O and non-cached
I/O to the same file.
Try writing a new file out using non-cached I/O and see if you get different
results.
-scott
OSR
@OSRDrivers
wrote in message news:xxxxx@ntfsd…
According to “Windows Internals” (Chapter 11, Cache Manager):
“Keep in mind that the cache manager is involved in file I/O only when a
file is opened without the FILE_FLAG_NO_BUFFERING flag
and then read from or written to using the Windows I/O functions (for
example, using the Windows ReadFile and WriteFile functions).”
I wrote a simple utility that writes zeros to an existing file.
It writes zeros in 4K buffers, and at the end it sets the size to be the
original size of the file.
The first version of the utility opens the file without any special flags,
the second version (xzero_no_buff) opens the file with the flag
FILE_FLAG_NO_BUFFERING.
* First version Process Monitor output:
2:51:16.3944250 PM xzero.exe 6412 CreateFile E:\Downloads\test.jpg SUCCESS
Desired Access: Generic Write, Read Attributes, Disposition: Open, Options:
Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode:
None, AllocationSize: n/a, OpenResult: Opened
2:51:16.3944703 PM xzero.exe 6412 QueryStandardInformationFile
E:\Downloads\test.jpg SUCCESS AllocationSize: 2,363,392, EndOfFile:
2,360,642, NumberOfLinks: 1, DeletePending: False, Directory: False
2:51:16.3944834 PM xzero.exe 6412 WriteFile E:\Downloads\test.jpg SUCCESS
Offset: 0, Length: 4,096, Priority: Normal
2:51:16.3945298 PM xzero.exe 6412 WriteFile E:\Downloads\test.jpg SUCCESS
Offset: 4,096, Length: 4,096
…
2:51:16.4019936 PM xzero.exe 6412 WriteFile E:\Downloads\test.jpg SUCCESS
Offset: 2,355,200, Length: 4,096
2:51:16.4020009 PM xzero.exe 6412 WriteFile E:\Downloads\test.jpg SUCCESS
Offset: 2,359,296, Length: 4,096
2:51:16.4020285 PM xzero.exe 6412 SetEndOfFileInformationFile
E:\Downloads\test.jpg SUCCESS EndOfFile: 2,360,642
2:51:16.4090436 PM xzero.exe 6412 CloseFile E:\Downloads\test.jpg SUCCESS
2:51:16.4094012 PM MsMpEng.exe 372 CreateFileMapping E:\Downloads\test.jpg
FILE LOCKED WITH WRITERS SyncType: SyncTypeCreateSection, PageProtection:
PAGE_EXECUTE_READ|PAGE_NOCACHE
2:51:16.4094244 PM MsMpEng.exe 372 QueryStandardInformationFile
E:\Downloads\test.jpg SUCCESS AllocationSize: 2,363,392, EndOfFile:
2,360,642, NumberOfLinks: 1, DeletePending: False, Directory: False
2:51:17.0794587 PM System 4 WriteFile E:\Downloads\test.jpg SUCCESS Offset:
0, Length: 1,048,576, I/O Flags: Non-cached, Paging I/O, Synchronous Paging
I/O, Priority: Very Low
2:51:17.0821091 PM System 4 CreateFileMapping E:\Downloads\test.jpg SUCCESS
SyncType: SyncTypeOther
2:51:18.3802095 PM System 4 WriteFile E:\Downloads\test.jpg SUCCESS Offset:
1,048,576, Length: 1,048,576, I/O Flags: Non-cached, Paging I/O, Synchronous
Paging I/O, Priority: Very Low
2:51:18.3829431 PM System 4 CreateFileMapping E:\Downloads\test.jpg SUCCESS
SyncType: SyncTypeOther
2:51:19.7413443 PM System 4 WriteFile E:\Downloads\test.jpg SUCCESS Offset:
2,097,152, Length: 266,240, I/O Flags: Non-cached, Paging I/O, Synchronous
Paging I/O, Priority: Very Low
2:51:19.7424212 PM System 4 SetEndOfFileInformationFile
E:\Downloads\test.jpg SUCCESS EndOfFile: 2,360,642
2:51:19.7424416 PM System 4 CreateFileMapping E:\Downloads\test.jpg SUCCESS
SyncType: SyncTypeOther
* Second version Process Monitor output:
3:04:27.8110033 PM xzero_no_buff.exe 7016 CreateFile E:\Downloads\test.jpg
SUCCESS Desired Access: Generic Write, Read Attributes, Disposition: Open,
Options: No Buffering, Synchronous IO Non-Alert, Non-Directory File,
Attributes: N, ShareMode: None, AllocationSize: n/a, OpenResult: Opened
3:04:27.8207308 PM xzero_no_buff.exe 7016 QueryStandardInformationFile
E:\Downloads\test.jpg SUCCESS AllocationSize: 2,363,392, EndOfFile:
2,360,642, NumberOfLinks: 1, DeletePending: False, Directory: False
3:04:27.8207705 PM xzero_no_buff.exe 7016 WriteFile E:\Downloads\test.jpg
SUCCESS Offset: 0, Length: 4,096, I/O Flags: Non-cached, Priority: Normal
3:04:27.8211333 PM xzero_no_buff.exe 7016 WriteFile E:\Downloads\test.jpg
SUCCESS Offset: 4,096, Length: 4,096, I/O Flags: Non-cached, Priority:
Normal
…
3:04:27.9064179 PM xzero_no_buff.exe 7016 WriteFile E:\Downloads\test.jpg
SUCCESS Offset: 2,359,296, Length: 4,096, I/O Flags: Non-cached, Priority:
Normal
3:04:27.9065758 PM xzero_no_buff.exe 7016 SetEndOfFileInformationFile
E:\Downloads\test.jpg SUCCESS EndOfFile: 2,360,642
3:04:27.9066143 PM xzero_no_buff.exe 7016 ReadFile E:\Downloads\test.jpg
SUCCESS Offset: 2,359,296, Length: 4,096, I/O Flags: Non-cached, Paging I/O,
Priority: Normal
3:04:27.9086864 PM xzero_no_buff.exe 7016 CloseFile E:\Downloads\test.jpg
SUCCESS
3:04:27.9090498 PM MsMpEng.exe 372 CreateFileMapping E:\Downloads\test.jpg
FILE LOCKED WITH WRITERS SyncType: SyncTypeCreateSection, PageProtection:
PAGE_EXECUTE_READ|PAGE_NOCACHE
3:04:27.9090725 PM MsMpEng.exe 372 QueryStandardInformationFile
E:\Downloads\test.jpg SUCCESS AllocationSize: 2,363,392, EndOfFile:
2,360,642, NumberOfLinks: 1, DeletePending: False, Directory: False
3:04:27.9091353 PM MsMpEng.exe 372 ReadFile E:\Downloads\test.jpg SUCCESS
Offset: 0, Length: 32,768, I/O Flags: Non-cached, Paging I/O, Synchronous
Paging I/O, Priority: Normal
…
3:04:30.8326217 PM System 4 CreateFileMapping C:\test\Downloads\test.jpg
SUCCESS SyncType: SyncTypeOther
3:04:30.8445425 PM System 4 SetEndOfFileInformationFile
E:\Downloads\test.jpg SUCCESS EndOfFile: 2,359,296
3:04:30.8445975 PM System 4 CreateFileMapping E:\Downloads\test.jpg SUCCESS
SyncType: SyncTypeOther
3:04:32.1532605 PM System 4 WriteFile E:\Downloads\test.jpg SUCCESS Offset:
2,359,296, Length: 4,096, I/O Flags: Non-cached, Paging I/O, Synchronous
Paging I/O, Priority: Very Low
3:04:32.1566545 PM System 4 SetEndOfFileInformationFile
E:\Downloads\test.jpg SUCCESS EndOfFile: 2,360,642
3:04:32.1567095 PM System 4 CreateFileMapping E:\Downloads\test.jpg SUCCESS
SyncType: SyncTypeOther
As you can see, in the first version the entire file is written by the cache
manager, while in the second version only the last 4KB frame is written.
I suspect that the last frame is being written because I set the file size.
How can I make the SetEndOfFileInformationFile a non-cached operation?