3.2.4.17 Application Requests Enumerating a Directory
The application provides:
A handle to the Open identifying a directory.
The InformationClass of the file information being queried, as specified in [MS-FSCC] section 2.4.
The maximum buffer size it will accept in response.
A Boolean indicating whether the enumeration is restarted.
A Boolean indicating whether only a single entry is returned.
A Boolean indicating whether the file specifier has been changed if the enumeration is being restarted.
A 4-byte index number to resume the enumeration from if the destination file system supports it (optional).
A file specifier string for the enumeration.
If the handle is invalid, or if no Open referenced by the handle is found, the client MUST return an implementation-specific error code. If the handle is valid and Open is found, the client MUST proceed as follows.
For the specified Open, the client MUST select a connection as specified in section 3.2.4.1.7. If no connection is available, the client MUST fail the enumeration operation.
Otherwise, the client initializes an SMB2 QUERY_DIRECTORY Request, following the syntax specified in section 2.2.37. The SMB2 header MUST be initialized as follows:
The Command field is set to SMB2 QUERY_DIRECTORY.
The SessionId field is set to Open.TreeConnect.Session.SessionId.
The TreeId field is set to Open.TreeConnect.TreeConnectId.
The SMB2 QUERY_DIRECTORY Request MUST be initialized as follows:
The FileInformationClass field is set to the InformationClass that is received from the application.
The OutputBufferLength field is set to the maximum output buffer that the calling application will accept.
If a file specifier string is provided, the client copies it into the Buffer[] and sets the FileNameOffset to the offset, in bytes, from the beginning of the SMB2 header to the start of the Buffer[]; and the FileNameLength to the length, in bytes, of the file specifier string. Otherwise, it sets FileNameOffset and FileNameLength to 0.
If a file index was provided by the application, the client sets the value in the FileIndex field and sets SMB2_INDEX_SPECIFIED to TRUE in the Flags field.
The FileId field is set to Open.FileId.
The Flags field MUST be set to a combination of zero or more of the following bit values, as specified in section 2.2.37:
SMB2_RESTART_SCANS if the application requested that the enumeration be restarted.
SMB2_REOPEN if the application requested that the enumeration be restarted and indicated that the file specifier has changed<165>.
SMB2_RETURN_SINGLE_ENTRY if the application requested that only a single entry be returned.
If Connection.Dialect is not "2.0.2" and if Connection.SupportsMultiCredit is TRUE, the CreditCharge field in the SMB2 header MUST be set to ( 1 + (OutputBufferLength – 1) / 65536 ).
The MessageId field in the SMB2 header is set as specified in section 3.2.4.1.3, and the request is sent to the server.