PRB: The Sparse Flag May Not Be Preserved By Using BackupRead() or BackupWrite() (271398)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows 2000
    • the operating system: Microsoft Windows XP

This article was previously published under Q271398

SYMPTOMS

The BackupRead function is used by backup utilities to create a backup of a file in memory; the BackupWrite function is used to restore the file to disk from the memory buffer. If you use these functions to back up and restore a sparse file, the restored file may not have the sparse attribute.

RESOLUTION

It is the responsibility of the backup utility to apply file attributes to a file after it is restored by using BackupWrite. The application should retrieve the attributes by using GetFileAttributes prior to creating a backup with BackupRead. If a file originally had the sparse attribute (FILE_ATTRIBUTE_SPARSE_FILE), the backup utility must explicitly set the attribute on the restored file. The attribute can be set by using the DeviceIoControl function with the FSCTL_SET_SPARSE flag.

STATUS

This behavior is by design.

MORE INFORMATION

If BackupWrite is used to copy a file that has more than one data stream, the sparse attribute will be applied to the copied file. However, this behavior is not by design (it is coincidental) and should not be relied upon. The backup utility must always apply the necessary file attributes.

Modification Type:MajorLast Reviewed:11/18/2003
Keywords:kbAPI kbBug kbFileIO kbKernBase kbprb KB271398