2.1.4.2 Algorithm for Detecting If Open Files Exist Under a Directory
The inputs for this algorithm are:
RootDirectory: The DirectoryFile indicating the top-level directory under which to search for open files.
Open: The Open for the request that is calling this algorithm.
Operation: A code describing the operation being processed, as specified in section 2.1.4.12.
OpParams: Parameters associated with Operation, passed in from the calling request, as specified in section 2.1.4.12.
The output is a Boolean. If the return value is TRUE, then no open files exist under the directory; if FALSE, then at least one open exists even after attempting to break oplocks.
Pseudocode for the algorithm is as follows:
For each Link in RootDirectory.DirectoryList:
// Check for oplock breaks in this directory.
If Link.File.OpenList contains an Open with Open.Link equal to Link:
For each Stream in Link.File.StreamList:
If Stream.Oplock is not empty and Stream.Oplock.State contains either BATCH_OPLOCK or HANDLE_CACHING, the object store MUST check for an oplock break according to the algorithm in section 2.1.4.12, with input values as follows:
Open equal to this algorithm's Open.
Oplock equal to Stream.Oplock.
Operation equal to this algorithm's Operation.
OpParams equal to this algorithm's OpParams.
EndIf
EndFor
EndIf
// See if all oplock holders have gotten out of the way.
If Link.File.OpenList contains an Open with Open.Link equal to Link:
Return FALSE // An open still exists; deny the operation.
EndIf
// Recurse into any subdirectories.
If Link.File.FileType is DirectoryFile, determine whether Link.File contains open files as specified in section 2.1.4.2, with input values as follows:
RootDirectory equal to Link.File.
Open equal to this algorithms's Open.
Operation equal to this algorithms's Operation.
OpParams equal to this algorithms's OpParams.
EndIf
If Link.File contains open files as determined above:
Return FALSE. // An open exists deeper in the directory hierarchy.
EndIf
EndFor
Return TRUE // No opens remaining.