Vladimir
Tue Jul 18 13:21:17 CDT 2006
"Jack Anderson" <spam@spam.org> wrote in message
news:uAFQKLmqGHA.3820@TK2MSFTNGP05.phx.gbl...
[..]
> We found a "hack" which seems to be working for us, and it does flush I
> would like you to give me your opinion and maybe to explain why it seems
> to work, what we do is call CreateFile on a root director e.g. "C:\" with
> FILE_FLAG_BACKUP_SEMANTICS flag and then call FlushFileBuffers, this seems
> to go over all the "children" directories/files that were just created and
> flush.
[..]
> Any ideas why this works ...
FILE_FLAG_BACKUP_SEMANTICS flag does all magic. From
MSDN(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/file_security_and_access_rights.asp):
"There are situations when a backup application must be able to change the
access control settings of a file or directory. An example is when the
access control settings of the disk-resident copy of a file or directory is
different from the backup copy. This would happen if these settings were
changed after the file or directory was backed up, or if it was corrupted.
The FILE_FLAG_BACKUP_SEMANTICS flag specified in the call to CreateFile
gives the backup application process permission to read the access-control
settings of the file or directory. With this permission, the backup
application process can then call GetKernelObjectSecurity and
SetKernelObjectSecurity to read and than reset the access-control settings."
Seems like mentioned above documentation applies to volumes (not only the
files). This makes contradiction with documentation written for
CreateFile(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp):
You can use the CreateFile function to open a physical disk drive or a
volume. The function returns a handle that can be used with the
DeviceIoControl function. This enables you to access the disk partition
table. However, it is potentially dangerous to do so, because an incorrect
write to a disk could make its contents inaccessible. The following
requirements must be met for such a call to succeed:
a.. *The caller must have administrative privileges. For more information,
see Running with Special Privileges.*
b.. The dwCreationDisposition parameter must have the OPEN_EXISTING flag.
c.. When opening a volume or floppy disk, the dwShareMode parameter must
have the FILE_SHARE_WRITE flag.
> ... or if it might not work in certain circumstances ?
IMO MS has two possible variants: change the documentation or change the
implementation of CreateFile...
--
Vladimir (Windows SDK MVP)