Determining the Buffering Method for an I/O Operation
Like device drivers, file systems are responsible for transferring data between user-mode applications and a system's devices. The operating system provides the following three methods for accessing data buffers:
In buffered I/O, the I/O manager allocates a system buffer for the operation from nonpaged pool. The I/O manager copies data from this system buffer into the application's user buffer, and vice versa, in the context of the thread that initiated the I/O operation.
In direct I/O, the I/O manager probes and locks the user buffer. It then creates a memory descriptor list (MDL) to map the locked buffer. The I/O manager accesses the buffer in the context of the thread that initiated the I/O operation.
In neither buffered nor direct I/O, the I/O manager does not allocate a system buffer and does not lock or map the user buffer. Instead, it simply passes the buffer's original user-space virtual address to the file system stack. Drivers are responsible for ensuring that they are executing in the context of the initiating thread and that the buffer addresses are valid.
Minifilter drivers must validate any address in user space before trying to use it. The I/O manager and filter manager do not validate such addresses and do not validate pointers that are embedded in buffers that are passed to minifilter drivers.
All standard Microsoft file systems use neither buffered nor direct I/O for most I/O processing.
For more information about buffering methods, see Methods for Accessing Data Buffers.
For IRP-based I/O operations, the buffering method used is operation-specific and is determined by the following factors:
The type of I/O operation that is being performed
The value of the Flags member of the DEVICE_OBJECT structure for the file system volume
For I/O control (IOCTL) and file system control (FSCTL) operations, the value of the TransferType parameter that was passed to the CTL_CODE macro when the IOCTL or FSCTL was defined
Fast I/O operations that have buffers always use neither buffered nor direct I/O.
File system callback operations do not have buffers.
This section includes: