Reparse Points
A file or directory can contain a reparse point, which is a collection of user-defined data. The format of this data is understood by the application which stores the data, and a file system filter, which you install to interpret the data and process the file. When an application sets a reparse point, it stores this data, plus a reparse tag, which uniquely identifies the data it is storing. When the file system opens a file with a reparse point, it attempts to find the file system filter associated with the data format identified by the reparse tag. If a file system filter is found, the filter processes the file as directed by the reparse data. If a file system filter is not found, the file open operation fails.
For example, reparse points are used to implement NTFS file system links and the Microsoft Remote Storage Server (RSS). RSS uses an administrator-defined set of rules to move infrequently used files to long term storage, such as tape or optical media. It uses reparse points to store information about the file in the file system. This information is stored in a stub file that contains a reparse point whose data points to the device where the actual file is now located. The file system filter can use this information to retrieve the file. Reparse points are also used to implement mounted folders. The following restrictions apply to reparse points:
Reparse Point Tags
Each reparse point has an identifier tag so that you can efficiently differentiate between the different types of reparse points, without having to examine the user-defined data in the reparse point. The system uses a set of predefined tags and a range of tags reserved for Microsoft. If you use any of the reserved tags when setting a reparse point, the operation fails. Tags not included in these ranges are not reserved and are available for your application. When you set a reparse point, you must tag the data to be placed in the reparse point. After the reparse point has been established, a new set operation fails if the tag for the new data does not match the tag for the existing data. If the tags match, the set operation overwrites the existing reparse point. To retrieve the reparse point tag, use the FindFirstFile() function. If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, then the dwReserved0 member specifies the reparse point.
Tag Contents
Reparse tags are stored as DWORD values. The bits define certain attributes, as shown in the following diagram.
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+-+-+-+-+-----------------------+-------------------------------+
|M|R|N|R| Reserved bits | Reparse tag value |
+-+-+-+-+-----------------------+-------------------------------+
The low 16 bits determine the kind of reparse point. The high 16 bits have 12 bits reserved for future use and 4 bits that denote specific attributes of the tags and the data represented by the reparse point. The following table describes these bits.
|
Bit |
Description |
|
M |
Microsoft bit. If this bit is set, the tag is owned by Microsoft. All other tags must use zero for this bit. |
|
R |
Reserved; must be zero for all non-Microsoft tags. |
|
N |
Name surrogate bit. If this bit is set, the file or directory represents another named entity in the system. |
The following macros exist to assist in testing tags:
Each macro returns a nonzero value if the associated bit is set. The following are Microsoft's predefined reparse tag values; they are defined in Winnt.h:
To ensure uniqueness of tags, Microsoft provides a mechanism to distribute new tags as explained in the Installable File System (IFS) Kit. Also available the Installable File System Filter test, which verifies whether the behavior in the file system stack is consistent with the typical behavior of a file system. This is a regression test suite.
Reparse Point Operations
To determine whether a file system supports reparse points, call the GetVolumeInformation() function and examine the FILE_SUPPORTS_REPARSE_POINTS bit flag. The DeviceIoControl() function enables you to set, modify, obtain, and remove reparse points. The following table describes the reparse point operations that you can perform using DeviceIoControl().
|
Operation |
Description |
|
FSCTL_SET_REPARSE_POINT |
Allows the calling program to set a new reparse point, or to modify an existing one. |
|
FSCTL_GET_REPARSE_POINT |
Obtains the information stored in an existing reparse point. |
|
FSCTL_DELETE_REPARSE_POINT |
Removes an existing reparse point. |
If you are modifying, getting, or deleting a reparse point, you must specify the same reparse tag in the operation that is contained in the file. Otherwise, the operation will fail with the error ERROR_REPARSE_TAG_MISMATCH. If you are modifying or deleting a reparse point, you must also specify the reparse GUID in the operation that is contained in the file. Otherwise, the operation will fail with the error ERROR_REPARSE_ATTRIBUTE_CONFLICT. To determine whether a file or directory contains a reparse point, use the GetFileAttributes() function. If the file or directory has an associated reparse point, the FILE_ATTRIBUTE_REPARSE_POINT attribute is set. To overwrite an existing reparse point without already having a handle to the file or directory, call CreateFile() with FILE_FLAG_OPEN_REPARSE_POINT. This flag allows you to open the file whether or not the corresponding file system filter is installed and working correctly.
Reparse Points and File Operations
Reparse points enable file system behavior that departs from the behavior most Windows developers may be accustomed to, therefore being aware of these behaviors when writing applications that manipulate files is vital to robust and reliable applications intended to access file systems that support reparse points. The extent of these considerations will depend on the specific implementation and associated file system filter behavior of a particular reparse point, which can be user-defined. Consider the following examples regarding NTFS reparse point implementations, which include mounted folders, linked files, and the Microsoft Remote Storage Server: