Read-Write (RW), exclusive access
This lease allows a client to open a file for exclusive access. This lock allows the client to perform read-ahead buffering and read or write caching.Read-Write-Handle (RWH), exclusive access
This lock allows a client to open a file for exclusive access. This lease supports read, write, and handle caching (similar to the Read-Handle lease).Another advantage that a lease has over an oplock is that a file may be cached, even when there are multiple handles opened to the file on the client. (This is a common behavior in many applications.) This is implemented through the use of a lease key
(implemented using a GUID), which is created by the client and associated with the File Control Block (FCB) for the cached file, allowing all handles to the same file to share the same lease state, which provides caching by file rather than caching by handle. Prior to the introduction of the lease, the oplock was broken whenever a new handle was opened to the file, even from the same client. Figure 12-8 shows the oplock behavior, and Figure 12-9 shows the new lease behavior.Prior to SMB 2.1, oplocks could only be granted or broken, but leases can also be converted
. For example, a Read lease may be converted to a Read-Write lease, which greatly reduces network traffic because the cache for a particular file does not need to be invalidated and refilled, as would be the case with an oplock break (of the Level 2 oplock), followed by the request and grant of a Level 1 oplock.
Figure 12-8. Oplock with multiple handles from the same client
Figure 12-9. Lease with multiple handles from the same client
File System Operation
Applications and the system access files in two ways: directly, via file I/O functions (such as ReadFile
and WriteFile), and indirectly, by reading or writing a portion of their address space that represents a mapped file section. (See Chapter 10 for more information on mapped files.) Figure 12-10 is a simplified diagram that shows the components involved in these file system operations and the ways in which they interact. As you can see, an FSD can be invoked through several paths:From a user or system thread performing explicit file I/O
From the memory manager’s modified and mapped page writers
Indirectly from the cache manager’s lazy writer
Indirectly from the cache manager’s read-ahead thread
From the memory manager’s page fault handler
Figure 12-10. Components involved in file system I/O
The following sections describe the circumstances surrounding each of these scenarios and the steps FSDs typically take in response to each one. You’ll see how much FSDs rely on the memory manager and the cache manager.
Explicit File I/O
The most obvious way an application accesses files is by calling Windows I/O functions such as CreateFile, ReadFile
, and WriteFile. An application opens a file with CreateFile and then reads, writes, or deletes the file by passing the handle returned from CreateFile to other Windows functions. The CreateFile function, which is implemented in the Kernel32.dll Windows client-side DLL, invokes the native function NtCreateFile, forming a complete root-relative path name for the path that the application passed to it (processing “.” and “..” symbols in the path name) and prefixing the path with “\??” (for example, \??\C:\Daryl\Todo.txt).The NtCreateFile
system service uses ObOpenObjectByName to open the file, which parses the name starting with the object manager root directory and the first component of the path name (“??”). Chapter 3, “System Mechanisms,” in Part 1 includes a thorough description of object manager name resolution and its use of process device maps, but we’ll review the steps it follows here with a focus on volume drive letter lookup.