Backing Up and Restoring POSIX File Links

A backup application can use the BackupWrite function to recreate POSIX file links.

The BackupRead function does not return POSIX file link data. A backup application must maintain the link information itself. The following pseudocode presents algorithms for backing up and restoring POSIX file link data along with other file information.

PseudoCode Algorithm for Backing Up POSIX File Links

1.  Initialize and empty a list of known links. 
2.  While there are more files to back up 
3.     Read the disk and get the next file. 
4.     Open the file for read. 
5.     Call GetFileInformationByHandle() to get the 
          NumberOfLinks and the FileIndex. 
6.     If the NumberOfLinks is greater than 1 
7.        Search the list of know links looking for 
             the same FileIndex. 
8.           If a match is NOT found 
9.              add the full path of the file and the 
                   FileIndex to the list. 
10.             Call BackupRead() to copy all data to 
                   your backup media. 
10.          Else 
11.             Mark the data as a LINK on your backup media 
11.             store the full path from the list 
                   to your backup media. 
12.          Endif 
13.    Else 
14.       Call BackupRead() to copy all data to your 
             backup media. 
15.    Endif 
16. EndWhile 
 

PseudoCode Algorithm for Restoring POSIX File Links

1.  While there are more files to restore 
2.     If the file is a LINK 
3.        use the full path which was saved as data 
             to open the file. 
4.        Initialize a WIN32_STREAM_ID structure with 
             dwStreamId equal to BACKUP_LINK. 
5.        Initialize the dwStreamAttributes to 0. 
6.        Initialize the dwStreamNameSize to 0. 
7.        Initialize a buffer containing the full path 
             of the file you are restoring in UNICODE. 
8.        Initialize the dwStreamSizeHigh to 0. 
9.        Initialize the dwStreamSizeLow to the size 
             in bytes of the buffer     containing the full path. 
10.       Call BackupWrite() with the WIN32_STREAM_ID 
11.       Call BackupWrite() with the buffer containing 
             the full path. 
13.          Else 
14.       Call BackupWrite() with the data stored on 
             your backup media. 
15.    Endif 
16. EndWhile