Function 6Ch Extended Open/Create

mov bx, OpenMode ;access and sharing values

mov cx, Attributes ;file attributes

mov dx, Action ;action to take if file exists/does not exist

mov si, seg FileName

mov ds, si

mov si, offset FileName ;ds:si points to filename

mov ah, 6Ch ;Extended Open/Create

int 21h

jc error_handler ;carry set means error

mov ActionTaken, cx ;action taken: open, create, or truncate

Extended Open/Create (Function 6Ch) combines Create File with Handle (Function 3Ch), Open File with Handle (Function 3Dh), and Commit File (Function 68h).

Parameters

OpenMode

Specifies the modes with which to open the file. It consists of one access value, one sharing value, and, optionally, other values, which can be given in any combination.

Value Meaning

OPEN_ACCESS_READONLY (0000h) Open the file for read-only access.
OPEN_ACCESS_WRITEONLY (0001h) Open the file for write-only access.
OPEN_ACCESS_READWRITE (0002h) Open the file for read-and-write access.
OPEN_SHARE_COMPATIBILITY (0000h) Permit other programs any access to the file. On a given computer, any program can open the file any number of times with this value. This is the default value.
OPEN_SHARE_DENYREADWRITE (0010h) Do not permit any other program to open the file.
OPEN_SHARE_DENYWRITE (0020h) Do not permit any other program to open the file for write access.
OPEN_SHARE_DENYREAD (0030h) Do not permit any other program to open the file for read access.
OPEN_SHARE_DENYNONE (0040h) Permit other programs read or write access, but no program may open the file for compatibility access.
OPEN_FLAGS_NOINHERIT (0080h) A child program created with Load and Execute Program (Function 4B00h) does not inherit the file handle. If this mode is not set, child programs inherit the file handle.
OPEN_FLAGS_NOCRIT_ERR (2000h) Critical-Error Handler (Interrupt 24h) will not be called if a critical error occurs while MS-DOS is opening this file. Instead, MS-DOS simply returns an error value to the program.
OPEN_FLAGS_COMMIT (4000h) MS-DOS commits the file (updates file contents on disk) after each write operation.

Attributes

Specifies the attributes to assign to the file if the specified file is created. This parameter can be a combination of the following values:

Value Meaning

ATTR_NORMAL (0000h) File can be read from or written to.
ATTR_READONLY (0001h) File can be read from, but not written to.
ATTR_HIDDEN (0002h) File does not appear in a directory listing.
ATTR_SYSTEM (0004h) File is a system file.
ATTR_ARCHIVE (0020h) File is marked for archiving.

If the file is opened instead of created, this parameter is ignored.

Action

Specifies the action to take if the file exists or if it does not exist. This parameter can be a combination of the following values:

Value Meaning

FILE_CREATE (0010h) Create a new file if the file does not already exist.
FILE_OPEN (0001h) Open the file. Fail if the file does not exist.
FILE_TRUNCATE (0020h) Open the file and and truncate it to zero length (replace the existing file). Fail if the file does not exist.

FileName

Points to a zero-terminated ASCII string that specifies the file to open or create. The name must be a valid MS-DOS filename.

Return Value

If the function is successful, the carry flag is clear, the AX register contains the file handle, and the CX register contains a value specifying the action taken. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value Name

0001h ERROR_INVALID_FUNCTION
0002h ERROR_FILE_NOT_FOUND
0003h ERROR_PATH_NOT_FOUND
0004h ERROR_TOO_MANY_OPEN_FILES
0005h ERROR_ACCESS_DENIED

Comment

If the function is successful, the CX register contains one of the following values:

Value Meaning

0001h ACTION_OPENED
0002h ACTION_CREATED_OPENED
0003h ACTION_REPLACED_OPENED

If the specified file is on a network drive, the function creates the file only if network grants create access to the drive or directory. Similarly, the function opens the file only if the network grants read, write, or both read and write access to the drive or directory.

See Also

Function 3Ch Create File with Handle
Function 3Dh Open File with Handle
Function 58h Create New File
Function 68h Commit File
Interrupt 24h Critical-Error Handler