Platform SDK: Win32 API

Int 21h Function 6Ch (FAT32)

Opens or creates a file that has the given name and attributes.

mov ah, 6Ch             ; Extended Open/Create
mov bx, ModeAndFlags    ; See below
mov cx, Attributes      ; See below
mov dx, Action          ; See below
mov si, seg Filename    ; See below
mov ds, si
mov si, offset Filename
int 21h

jc error_handler        ; Carry set means error

mov [Handle], ax        ; file handle
mov [ActionTaken], cx   ; action taken to open file

Parameters

ModeAndFlags
A combination of access mode, sharing mode, and open flags. This parameter can be a combination of one value from the access and sharing modes and any combination of open flags:
Access mode Meaning
OPEN_ACCESS_READONLY (0000h) Opens the file for reading only.
OPEN_ACCESS_WRITEONLY (0001h) Opens the file for writing only.
OPEN_ACCESS_READWRITE (0002h) Opens the file for reading and writing.
0003h Reserved; do not use.
OPEN_ACCESS_RO_NOMODLASTACCESS (0004h) Opens the file for reading only without modifying the file's last access date.

Sharing mode Meaning
OPEN_SHARE_COMPATIBLE (0000h) Opens the file in compatibility mode, allowing any process on a given computer to open the file any number of times.
OPEN_SHARE_DENYREADWRITE (0010h) Opens the file and denies both read and write access to other processes.
OPEN_SHARE_DENYWRITE (0020h) Opens the file and denies write access to other processes.
OPEN_SHARE_DENYREAD (0030h) Opens the file and denies read access to other processes.
OPEN_SHARE_DENYNONE (0040h) Opens the file without denying read or write access to other processes, but no process may open the file in compatibility mode.

Open flags Meaning
OPEN_FLAGS_NOINHERIT (0080h) Child processes created with Load and Execute Program (Interrupt 21h Function 4B00h) do not inherit the file handle. If the handle is needed by a child process, the parent process must pass the handle value to the child process. If this flag is not set, child processes inherit the file handle.
EXTENDED_SIZE (1000h) The file is opened in extended mode. This allows access to files up to 4GB minus 2 bytes. Access includes open and create functions.
OPEN_FLAGS_NOCRITERR (2000h) If a critical error occurs while MS-DOS is opening this file, Critical-Error Handler (Interrupt 24h) is not called. Instead, MS-DOS simply returns an error value to the program.
OPEN_FLAGS_COMMIT (4000h) After each write operation, MS-DOS commits the file (flushes the contents of the cache buffer to disk).

Attributes
Attributes for files that are created or truncated. This parameter may be a combination of these values.
Value Description
FILE_ATTRIBUTE_NORMAL (0000h) The file can be read from or written to. This value is valid only if used alone.
FILE_ATTRIBUTE_READONLY (0001h) The file can be read from, but not written to.
FILE_ATTRIBUTE_HIDDEN (0002h) The file is hidden and does not appear in an ordinary directory listing.
FILE_ATTRIBUTE_SYSTEM (0004h) The file is part of the operating system or is used exclusively by it.
FILE_ATTRIBUTE_VOLUME (0008h) The name specified by Filename is used as the volume label for the current medium.
FILE_ATTRIBUTE_ARCHIVE (0020h) The file is an archive file. Applications use this value to mark files for backup or removal.

Action
Action to take it the file exists or does not exist. This parameter can be a limited combination of the following values.
Value Description
FILE_CREATE (0010h) Creates a new file if it does not already exist or fails if the file already exists.
FILE_OPEN (0001h) Opens the file. The function fails if the file does not exist.
FILE_TRUNCATE (0002h) Opens the file and truncates it to zero length (replaces the existing file). The function fails if the file does not exist.

Note that valid combinations of the above values are limited to FILE_CREATE combined with FILE_OPEN or FILE_CREATE combined with FILE_TRUNCATE.

Filename
Pointer to a null-terminated string specifying the name of the file to be opened or created. The name must be in the standard MS-DOS 8.3 filename format. The string must be a valid path for the volume associated with the given drive.

Return Values

If the function is successful, clears the carry flag, copies the file handle to the AX register, and sets CX to one of the following values.

Otherwise, sets the carry flag and sets the AX register to one of the following error values.

Remarks

This function does not support long filenames. If the specified name is too long, this function truncates the name to the standard 8.3 format following the same naming scheme that the system uses when creating an alias for a long filename.

A file on a remote directory-that is, a directory on the network-cannot be opened, unless appropriate permissions for the directory exist.