Hi,
I have written test application to write data into a file and then observing calls in the filespy utility.
for(int nCount = 0; nCount < NUMBER; nCount++)
{
hFile = CreateFile(FileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
WriteFile(hFile,cBuffer,(DWORD)(strlen(cBuffer)),&dwLength,NULL)
CloseHandle(hFile);
}
File spy output for NUMBER=1 below:
- Create request sent by SYSTEM process and the result returned is STATUS_OBJECT_NAME_NOT_FOUND. FileObject used is F1 [All requests on F1 are in context of System process].
- Create request sent by my process. This succeeds. Fileobject is say F2 [All request on F2 are in context of the test application].
- Cached write received for the file object F2. [Offset: 0-0 ToWrite: 1A1C60 Written: 1A1C60]
- Cleanup received for the file object F2.
- Create request is now observed on F1. This is followed by query of basic information.
- We then get a cleanup and a close on F1.
- Once again there is a create followed by 3 fastio query standard info on F1.
- This is again followed by a cleaup and close on F1.
- Now a close is seen on F2.
- Now I can see the non cached paging write on F1. [Offset: 0-180000 ToWrite: 10000 Written: 10000]
- Now I can see non cached set information which sets the end of file [Endoffile: 0-190000].
- Again I can see the non cached paging write on F1. [Offset: 0-190000 ToWrite: 10000 Written: 10000]
- Again I can see non cached set information which sets the end of file. [Endoffile: 0-1A0000].
- Again I can see the non cached paging write on F1. [Offset: 0-1A0000 ToWrite: 2000 Written: 1C60]
- Again I can see non cached set information which sets the end of file. [Endoffile: 0-1A1C60]
- Close is seen for F1.
- After this there is no other call that is seen.
General questions:
- Why is request 1 sent?
- Why are requests from 5-9 sent?
- Why can I see 3 non cached writes and non cached set information? Why could'nt this be done in a single call?
- Why does request 10 not start with offset 0. Also I do not understand why the end of file values are the way they are.
- If I run this application in a loop [NUMBER=10] and each time the data size written is different its always the case that requests from 10 to 17 are seen only at the end. How is this ensured?
- The same is true if I run my application twice simultaneously.
Now my createfile looked like CreateFile(FileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
Also sometimes one of the process fails with error that other process is using the file. What are the semantics of FILE_SHARE_WRITE? I read about this in some of the articles but did not get the exact meaning.
File size related questions:
- Here I can increase the file size in the request 3 which is a cached write by changing the write length.
- In case of request 10 I can insert the header in the file in the file and shift the actual data.
- As per the archive posts my header will be of 1 page size.
Thanks,
Trav