BOOL BackupWrite(hFileHandle, lpBuffer, dwBufferLength, lpNumberOfBytesWritten, bAbortOperation, lpContext) | |||
HANDLE hFileHandle; | |||
LPBYTE lpBuffer; | |||
DWORD dwBufferLength; | |||
LPDWORD lpNumberOfBytesWritten; | |||
BOOL bAbortOperation; | |||
LPVOID *lpContext; |
BackupWrite mirrors the BackupRead function, enabling the full recreation and restore of all data pertaining to an opened object. The addition of one additional stream type, LINK, allows the restoration of files with hard links. The LINK stream is defined as a stream header with Type LINK, followed by a stream containing the name of the file to re-establish a link with.
hFileHandle
Handle to file being backed up. Handle is established with CreateFile.
lpBuffer
Buffer containing data.
dwBufferLength
Length of buffer. By definition, the buffer size must be greater than the size of a StreamID structure. The StreamID structure has the following form:
struct StreamID {
DWORD Type;
DWORD Attribute;
DWORD Size;
DWORD HighSize;
DWORD NameLength ;
CHAR Name[ ] ;
}
lpNumberOfBytesWritten
Upon return, the actual length of data written.
bAbortOperation
If TRUE, then BackupWrite operation is aborted, and all buffers deallocated.
lpContext
Internal context structure used only by this function.
The return value is TRUE if the function was successful, or FALSE if an error occurred. To obtain extended error information, use the GetLastError function.
To backup and restore files, FindFirstFile and FindNextFile would be used to traverse a volume's directory tree. Files are opened in sequence. File attributes, unique file id, and number of hard links are determined. If there are hard links, the file's unique ID is saved in a table for future comparisons. The application opens a tape device \\.\Tape0 using the CreateFile function. The first time a file is encountered, the general file information is written to tape. Repeated calls to BackupRead are made, and the various streams are written to tape. The second time a file's unique ID is encountered (checked against the table only when there are hard links as above), the general file information is written, followed by only a LINK stream.
When restoring, files are opened for create, and the BackupWrite function is called with each data stream. If the stream is a LINK stream, then a hard link is established. If the data to establish a link with does not exists (a possible scenario during a selective restore), the BackupWrite fails, and the application can either use a preexisting catalog to locate and restore the original data, or more simply notify the user that the file data to be restored is located in a different location.
BackupWrite