OPEN: Open File

This message is sent to obtain a file handle for a data file. This returned fid is used in subsequent client requests such as read, write, close, etc.

Client Request
==================================
Description
=================================
UCHAR WordCount; Count of parameter words = 2
USHORT DesiredAccess; Mode - read/write/share
USHORT SearchAttributes;
USHORT ByteCount; Count of data bytes; min = 2
UCHAR BufferFormat; 0x04
STRING FileName[]; File name

filename is the fully qualified file name, relative to the root of the share specified in the tid field of the SMB header. If tid in the SMB header refers to a print share, this SMB creates a new file which will be spooled to the printer when closed. In this case, filename is ignored.

searchattributes specifies the type of file desired. The encoding is described in the "File Attribute Encoding" section.

desiredaccess controls the mode under which the file is opened, and the file will be opened only if the client has the appropriate permissions. The encoding of desiredaccess is discussed in the section entitled "Access Mode Encoding".

Server Response
==================================
Description
=================================
UCHAR WordCount; Count of parameter words = 7
USHORT Fid; File handle
USHORT FileAttributes; Attributes of opened file
UTIME LastWriteTime; Time file was last written
ULONG DataSize; File size
USHORT GrantedAccess; Access allowed
USHORT ByteCount; Count of data bytes = 0

fid is the handle value which should be used for subsequent file operations.

fileattributes specifies the type of file obtained. The encoding is described in the "File Attribute Encoding" section.

grantedaccess indicates the access permissions actually allowed, and may have one of the following values:

0 read-only
1 write-only
2 read/write

File Handles (fids) are scoped per client. A pid may reference any fid established by itself or any other pid on the client (so far as the server is concerned). The actual accesses allowed through the fid depends on the open and deny modes specified when the file was opened (see below).

The MS-DOS compatibility mode of file open provides exclusion at the client level. A file open in compatibility mode may be opened (also in compatibility mode) any number of times for any combination of reading and writing (subject to the user's permissions) by any pid on the same client. If the first client has the file open for writing, then the file may not be opened in any way by any other client. If the first client has the file open only for reading, then other clients may open the file, in compatibility mode, for reading.. The above notwithstanding, if the filename has an extension of .EXE, .DLL, .SYM, or .COM other clients are permitted to open the file regardless of read/write open modes of other compatibility mode opens. However, once multiple clients have the file open for reading, no client is permitted to open the file for writing and no other client may open the file in any mode other than compatibility mode.

The other file exclusion modes (Deny read/write, Deny write, Deny read, Deny none) provide exclusion at the file level. A file opened in any "Deny" mode may be opened again only for the accesses allowed by the Deny mode (subject to the user's permissions). This is true regardless of the identity of the second opener -a different client, a pid from the same client, or the pid that already has the file open. For example, if a file is open in "Deny write" mode a second open may only obtain read permission to the file.

Although fids are available to all pids on a client, pids other than the owner may not have the full access rights specified in the open mode by the fid's creator. If the open creating the fid specified a deny mode, then any pid using the fid, other than the creating pid, will have only those access rights determined by "anding" the open mode rights and the deny mode rights, i.e., the deny mode is checked on all file accesses. For example, if a file is opened for Read/Write in Deny write mode, then other clients may only read the file and cannot write; if a file is opened for Read in Deny read mode, then the other clients can neither read nor write the file.