Note: This API call is for DOS and Win16 personality only. Use Family API for portability.

Int 21H, AH=3DH

Version

2 and higher

Brief

“OPEN” - OPEN EXISTING FILE

Family API

Input

AH = 3Dh
AL = access and sharing modes (see #01402)
DS:DX -> ASCIZ filename
CL = attribute mask of files to look for (server call only)

Return

CF clear if successful

AX = file handle
CF set on error
AX = error code (01h,02h,03h,04h,05h,0Ch,56h) (see #01680 at AH=59h)

Notes

Notes: file pointer is set to start of file

if SHARE or a network is loaded, the file open may fail if the file
is already open, depending on the combination of sharing modes
(see #01403,#01404)
file handles which are inherited from a parent also inherit sharing
and access restrictions
files may be opened even if given the hidden or system attributes
under the FlashTek X-32 DOS extender, the pointer is in DS:EDX
DR DOS checks the system password or explicitly supplied password at
the end of the filename (following a semicolon) against the reserved
field in the directory entry before allowing access
sharing modes are only effective on local drives if SHARE is loaded

BUG: Novell DOS 7 SHARE v1.00 would refuse file access in the cases in

#01403 marked with [1] (read-only open of a read-only file
which had previously been opened in compatibility mode); this was
fixed in SHARE v1.01 of 09/29/94

Bitfields for access and sharing modes: Bit(s) Description (Table 01402) 2-0 access mode

000 read only
001 write only
010 read/write
011 (DOS 5+ internal) passed to redirector on EXEC to allow
case-sensitive filenames

3 reserved (0) 6-4 sharing mode (DOS 3.0+) (see #01403)

000 compatibility mode
001 "DENYALL" prohibit both read and write access by others
010 "DENYWRITE" prohibit write access by others
011 "DENYREAD" prohibit read access by others
100 "DENYNONE" allow full access by others
111 network FCB (only available during server call)

7 inheritance

if set, file is private to current process and will not be inherited
by child processes

(Table 01403) Values of DOS 2-6.22 file sharing behavior:

| Second and subsequent Opens

First |Compat Deny Deny Deny Deny Open | All Write Read None

|R W RW R W RW R W RW R W RW R W RW

- - - - -| - - - - - - - - - - - - - - - - - Compat R |Y Y Y N N N 1 N N N N N 1 N N

W |Y Y Y N N N N N N N N N N N N
RW|Y Y Y N N N N N N N N N N N N

- - - - -| Deny R |C C C N N N N N N N N N N N N All W |C C C N N N N N N N N N N N N

RW|C C C N N N N N N N N N N N N

- - - - -| Deny R |2 C C N N N Y N N N N N Y N N Write W |C C C N N N N N N Y N N Y N N

RW|C C C N N N N N N N N N Y N N

- - - - -| Deny R |C C C N N N N Y N N N N N Y N Read W |C C C N N N N N N N Y N N Y N

RW|C C C N N N N N N N N N N Y N

- - - - -| Deny R |2 C C N N N Y Y Y N N N Y Y Y None W |C C C N N N N N N Y Y Y Y Y Y

RW|C C C N N N N N N N N N Y Y Y

Legend: Y = open succeeds, N = open fails with error code 05h

C = open fails, INT 24 generated
1 = open succeeds if file read-only, else fails with error code
2 = open succeeds if file read-only, else fails with INT 24

(Table 01404) Values for DOS 7.x file sharing behavior:

| Second and subsequent Opens

First |Compat Deny Deny Deny Deny Open | All Write Read None

|R W RW A R W RW A R W RW A R W RW A R W RW A

- - - - -| - - - - - - - - - - - - - - - - - - - - - - - - Compat R |Y Y Y Y N N N N Y N N Y N N N Y Y N N Y

W |Y Y Y C N N N N N N N N N N N Y Y N N Y
RW|Y Y Y C N N N N N N N N N N N Y Y N N Y
NA|Y C C Y N N N N Y N N Y N N N Y Y N N Y

- - - - -| Deny R |C C C C N N N N N N N N N N N N N N N N All W |C C C C N N N N N N N N N N N N N N N N

RW|C C C C N N N N N N N N N N N N N N N N
NA|C C C C N N N N N N N N N N N N N N N N

- - - - -| Deny R |Y C C Y N N N N Y N N Y N N N Y Y N N Y Write W |C C C C N N N N N N N N Y N N Y Y N N Y

RW|C C C C N N N N N N N N N N N Y Y N N Y
NA|Y C C Y N N N N Y N N Y N N N Y Y N N Y

- - - - -| Deny R |C C C C N N N N N Y N N N N N N N Y N N Read W |C C C C N N N N N N N N N Y N N N Y N N

RW|C C C C N N N N N N N N N N N N N Y N N
NA|Y Y Y Y N N N N Y Y Y Y N N N Y Y Y Y Y

- - - - -| Deny R |Y Y Y Y N N N N Y Y Y Y N N N Y Y Y Y Y None W |C C C C N N N N N N N N Y Y Y Y Y Y Y Y

RW|C C C C N N N N N N N N N N N Y Y Y Y Y
NA|Y Y Y Y N N N N Y Y Y Y N N N Y Y Y Y Y

Legend: R → reading, W → writing, RW → both reading & writing,

A/NA -> reading without access time update
Y = open succeeds, N = open fails with error code 05h
C = open fails, INT 24 generated

See also

AH=0Fh,AH=3Ch,AX=4301h,AX=5D00h,INT 2F/AX=1116h,INT 2F/AX=1226h

Note

Text based on Ralf Brown Interrupt List Release 61

DOS API
Process manager	INT 20H, INT 21H: 00H, 25H, 26H, 31H, 34H, 35H, 4BH, 4CH, 4DH, 50H, 51H, 52H, 55H, 62H, INT 22H, INT 27H, INT 28H
File manager	INT 25H, INT 26H, INT 21H: 0DH, 0EH, 0FH, 10H, 11H, 12H, 13H, 14H, 15H, 16H, 17H, 19H, 1AH, 1BH, 1CH, 21H, 22H, 23H, 24H, 27H, 28H, 29H, 2EH, 2FH, 32H, 3305H, 36H, 39H, 3AH, 3BH, 3CH, 3DH, 3EH, 3FH, 40H, 41H, 42H, 4300H, 4301H, 45H, 45H, 46H, 4EH, 4FH, 54H, 56H, 5700H, 5701H, 5AH, 5BH, 5c00H, 5c01H, 60H, 67H, 68H, 6900H, 6901H, 6AH, 6CH
Character Device I/O	INT 29H, INT 21H: 01H, 02H, 03H, 04H, 05H, 06H, 07H, 08H, 09H, 0AH, 0BH, 0AH, 0CH, 5D07H, 5D08H, 5D09H, 5D0AH
Signals	INT 23H, INT 24H, INT 21H: 3300H, 3301H, 3302H
Memory manager	INT 21H: 48H, 49H, 4AH, 5800H, 5801H, 5802H, 5803H
Date and Time	INT 21H: 2AH, 2BH, 2CH, 2DH
Misc	INT 21H: 30H, 3306H, 3700H, 3701H, 3702H, 3703H, 59H
NLS	INT 21H: 3303H, 3304H, 3800H, 3801H, 6300H, 6301H, 6301H, 6500H, 6501H, 6502H, 6503H, 6504H, 6505H, 6506H, 6507H, 6520H, 6521H, 6522H, 6523H, 65A0H, 65A1H, 65A2H, 6601H, 6602H
Devices	INT 21H: 4400H, 4401H, 4402H, 4403H, 4404H, 4405H, 4406H, 4407H, 4408H, 4409H, 440AH, 440BH, 440CH, 440DH, 440EH, 440FH, 4410H, 4411H, 53H
Network	INT 21H: 5E00H, 5E01H, 5E02H, 5E03H, 5E04H, 5E05H, 5F00H, 5F01H, 5F02H, 5F03H, 5F04H, 5F05H, 5F07H, 5F08H
osFree Macro Library
Video I/O	@SetMode @SetCurSz @SetCurPos @GetCur @SetPage @ScrollUp @ScrollDn @Scroll @GetChAtr @PutChAtr @PutCh @SetPalet @SetColor @SetDot @GetDot @WrtTTY @VideoState @GetMode @GetDisplay @GetVideoState @GetEGAInfo @Cls
Hardware info	@Equipment @MemSize
Serial I/O	@AuxInit @AuxSendChar @AuxRecieveChar @AuxStatus
Tape I/O	@TapeOn @TapeOff @TapeRead @TapeWrite
Keyboard I/O	@KbdStatus @CharIn @CharPeek
Printer I/O	@PrnPrint @PrnInit @PrnStatus
Disk I/O	@DskReset @DskStatus @DskRead @DskWrite @DskVerify @DskFormat
Date and Time	@SetTime @GetTime
Mouse	@MouInit @MouShowPointer @MouStatus @MouSetPos @MouSetMickey @MouRegion
Memory manager	@ModBlok SET_BLOCK
Family API
DOS	Process Manager	DosBeep DosExit DosSleep DosExecPgm
File Manager	DosChDir DosChgFilePtr DosClose DosDelete DosDupHandle DosMkDir DosMove DosQCurDir DosQCurDisk DosSetFileMode DosOpen DosQFileInfo DosRead DosQFileMode DosQFSInfo DosQVerify DosRmDir DosSelectDisk DosFindClose DosFindFirst DosFindNext DosSetFileInfo DosSetVerify DosWrite DosFileLocks DosSetFHandState DosNewSize DosBufReset DosQFHandState DosSetFSinfo DosShutdown
Memory Manager	DosFreeSeg DosSubAlloc DosSubFree DosSubSet DosAllocHuge DosAllocSeg DosReallocHuge DosReallocSeg DosGetHugeShift DosCreateCSAlias
NLS	DosCaseMap DosGetCtryInfo DosGetDBCSEv DosSetCtryCode DosGetCollate DosGetMessage DosInsMessage DosPutMessage
Date and Time	DosSetDateTime DosGetDateTime
Devices	DosDevConfig DosDevIOCtl DosDevIOCtl2
Signals	DosHoldSignal DosSetSigHandler
Misc	BadDynLink DosGetEnv DosGetMachineMode DosGetVersion DosError DosErrClass DosSetVec
KBD	KbdCharIn KbdFlushBuffer KbdGetStatus KbdSetStatus KbdStringIn KbdPeek
VIO	VioGetBuf VioGetConfig VioGetCurPos VioGetCurType VioGetPhysBuf VioReadCellStr VioReadCharStr VioScrollUp VioScrollDn VioScrollLf VioScrollRt VioScrUnLock VioSetCurPos VioSetCurType VioSetMode VioGetMode VioShowBuf VioWrtCellStr VioWrtCharStr VioWrtCharStrAtt VioWrtNAttr VioWrtNCell VioWrtNChar VioWrtTTY VioScrLock VioPopUp
Tools	BIND
Modules	DOSCALLS.DLL VIOCALLS.DLL KBDCALLS.DLL MSG.DLL
Libraries	API.LIB OS2386.LIB FAPI.LIB DOSCALLS.LIB SUBCALLS.LIB