Using a File Handle

The following table lists the operations that drivers can perform on a file handle and the corresponding routines that carry out those operations.

Operation Routine to call

Read data from the file.

ZwReadFile

Write data to the file.

ZwWriteFile

Read metadata for the file or file handle.

ZwQueryInformationFile

Write metadata for the file or file handle.

ZwSetInformationFile

To indicate where in the file to begin reading or writing data, you pass a ByteOffset parameter to ZwReadFile or ZwWriteFile, respectively.

If you opened the handle with FILE_APPEND_DATA access, all data is written to the end of the file, and the ByteOffset parameter is ignored.

Under certain conditions, the I/O manager maintains a current file-position pointer for the file. You can begin a read or write operation at that position by specifying NULL for ByteOffset. For more information about when the current file-position pointer exists, see Using the Current File Position later in this section.

To examine or change information about a file, call ZwQueryInformationFile or ZwSetInformationFile, respectively. You specify the particular type of information as the FileInformationClass parameter to each routine. For example, setting FileInformationClass to FileBasicInformation allows you to examine or change a FILE_BASIC_INFORMATION structure, which contains members for the file-creation time and the last-access time, among others. For information about all the possible values for FileInformationClass, see FILE_INFORMATION_CLASS.