Int 21H [4.0] Function 6CH (108) Extended open file

Given an ASCIIZ pathname, opens, creates or replaces a file in the designated or default directory on the designated or default disk drive. Returns a handle that can be used by the program for subsequent access to the file.

Call with:

AH = 6CH

AL = 00H

BX = open mode

Bit(s) Significance

0—2 access type

000 = read-only

001 = write-only

010 = read/write

3 reserved (0)

4—6 sharing mode

000 = compatibility

001 = deny read/write (deny all)

010 = deny write

011 = deny read

100 = deny none

7 inheritance

0 = child process inherits handle

1 = child does not inherit handle

8—12 reserved (0)

13 critical error handling

0 = execute Int 24H

1 = return error to process

14 write-through

0 = writes may be buffered and deferred

1 = physical write at request time

15 reserved (0)

CX = file attribute (bits may be combined; ignored if open)

Bit(s) Significance (if set)

0 read-only

1 hidden

2 system

3 volume label

4 reserved (0)

5 archive

6—15 reserved (0)

DX = open flag

Bits Significance

0—3 action if file exists

0000 = fail

0001 = open file

0010 = replace file

4—7 action if file doesn't exist

0000 = fail

0001 = create file

8—15 reserved (0)

DS:SI = segment:offset of ASCIIZ pathname

Returns:

If function successful

Carry flag = clear

AX = handle

CX = action taken

1 = file existed and was opened

2 = file did not exist and was created

3 = file existed and was replaced

If function failed

Carry flag = set

AX = error code

Notes:

The function fails if:

any element of the pathname does not exist.

the file is being created in the root directory and the root directory is full.

the file is being created and a file with the same name and the read-only attribute already exists in the specified directory.

the program is running on a network and the user running the program has insufficient access rights.

A file is usually given a normal (0) attribute when it is created. The file's attribute can subsequently be modified with Int 21H Function 43H.

This function combines the capabilities of Int 21H Functions 3CH, 3DH, and 5BH. It was added to MS-DOS for compatibility with the DosOpen function of OS/2.

Example:

Create the file MYFILE.DAT, if it does not already exist, in directory \MYDIR on drive C, and save the handle for subsequent access to the file.

fname db 'C:\MYDIR\MYFILE.DAT',0

fhandle dw ?

.

.

.

mov ax,6c00h ; function number

mov bx,4042h ; read/write, deny none,

; write-through mode

xor cx,cx ; normal attribute

mov dx,0010h ; create if doesn't exist,

; fail if exists

mov si,seg fname ; address of pathname

mov ds,si

mov si,offset fname

int 21h ; transfer to MS-DOS

jc error ; jump if open failed

mov fhandle,ax ; save file handle

.

.

.