     1                                  ;	SCCSID = @(#)file.asm	1.2 85/07/23
     2                                  ;	SCCSID = @(#)file.asm	1.2 85/07/23
     3                                  ;TITLE	FILE - Pathname related system calls
     4                                  ;NAME	FILE
     5                                  
     6                                  ;
     7                                  ; Pathname related system calls.  These will be passed direct text of the
     8                                  ; pathname from the user.  They will need to be passed through the macro
     9                                  ; expander prior to being sent through the low-level stuff.  I/O specs are
    10                                  ; defined in DISPATCH.	The system calls are:
    11                                  ;
    12                                  ;   $Open	      written
    13                                  ;   $Creat	      written
    14                                  ;   $ChMod	      written
    15                                  ;   $Unlink	      written
    16                                  ;   $Rename	      written
    17                                  ;   $CreateTempFile   written
    18                                  ;   $CreateNewFile    written
    19                                  ;   $Extended_Open    written  DOS 4.00
    20                                  ;   GetIOParms	      written  DOS 4.00
    21                                  ;
    22                                  ;   Revision history:
    23                                  ;
    24                                  ;	Created: MZ 4 April 1983
    25                                  ;	A000   version 4.00  Jan. 1988
    26                                  
    27                                  [list -]
    27          ******************       warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14                              <3> [list -]
     3                              <2> 
     4                              <2> addsection DOSSTART, align=16 PUBLIC class=DOSSTART
     5                              <2> ; (no prior section) ; DOSSTART		ENDS
     6                              <2> 
     7                              <2> addsection DOSSTARTJUMP, align=1 PUBLIC class=START
     8                              <2> ; (no prior section) ; DOSSTARTJUMP		ENDS
     9                              <2> 
    10                              <2> addsection CONSTANTS, align=2 PUBLIC class=CONST
    11                              <2> ; (no prior section) ; CONSTANTS	ENDS
    12                              <2> 
    13                              <2> addsection DATA, align=2 PUBLIC class=DATA
    14                              <2> ; (no prior section) ; DATA		ENDS
    15                              <2> 
    16                              <2> addsection TABLE, align=2 PUBLIC class=TABLE
    17                              <2> ; (no prior section) ; TABLE		ENDS
    18                              <2> 
    19                              <2> addsection DOSDATATABLE, align=2 PUBLIC class=DOSDATACODE
    20                              <2> ; (no prior section) ; DOSDATATABLE		ENDS
    21                              <2> 
    22                              <2> addsection DOSDATACODE, align=1 PUBLIC class=DOSDATACODE
    23                              <2> ; (no prior section) ; DOSDATACODE		ENDS
    24                              <2> 
    25                              <2> addsection DOSBIODATA, align=2 PUBLIC class=DOSBIODATA
    26                              <2> 
    27                              <2> addsection LAST, align=16 PUBLIC class=LAST
    28                              <2> ; (no prior section) ; LAST		ENDS
    29                              <2> 
    30                              <2> group DOSGROUP DOSSTART DOSSTARTJUMP CONSTANTS DATA TABLE DOSDATATABLE DOSDATACODE DOSBIODATA LAST
     8                              <1> 
     9                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
    10                              <1> 
    11                              <1> section LAST
    12                              <1> ; (no prior section) ; LAST		ENDS
    32                                  
    33                                  [list +]
    34                                  section DOSCODECODE
    35                                  [list -]
    35          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    35          ******************       warning: out: BPB.INC... [-w+user]
    35          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    35          ******************       warning: out: DEVSYM.INC... [-w+user]
    35          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    45                                  ;.sall
    46                                  
    47                                  	EXTRN	DOS_OPEN:NEAR,DOS_CREATE:NEAR,DOS_Create_New:NEAR
    48                                  
    49                                  %IFN IBMCOPYRIGHT
    50                                  	extrn	Set_EXT_mode:near
    51                                  %ENDIF
    52                                  
    53                                  	I_need	WFP_Start,WORD		; pointer to beginning of expansion
    54                                  	I_Need	ThisCDS,DWORD		; pointer to curdir in use
    55                                  	I_need	ThisSft,DWORD		; SFT pointer for DOS_Open
    56                                  	I_need	pJFN,DWORD		; temporary spot for pointer to JFN
    57                                  	I_need	JFN,WORD		; word JFN for process
    58                                  	I_need	SFN,WORD		; word SFN for process
    59                                  	I_Need	OpenBuf,128		; buffer for filename
    60                                  	I_Need	RenBuf,128		; buffer for filename in rename
    61                                  	I_need	Sattrib,BYTE		; byte attribute to search for
    62                                  	I_need	Ren_WFP,WORD		; pointer to real path
    63                                  	I_need	cMeta,BYTE
    64                                  	I_need	EXTERR,WORD		; extended error code
    65                                  	I_need	EXTERR_LOCUS,BYTE	; Extended Error Locus
    66                                  	i_need	JShare,DWORD		; share jump table
    67                                  	I_need	fSharing,BYTE		; TRUE => via ServerDOSCall
    68                                  	I_need	FastOpenTable,BYTE
    69                                  	I_need	CPSWFLAG,BYTE		;AN000;FT. cpsw falg
    70                                  	I_need	EXTOPEN_FLAG,WORD	;AN000;FT. extended file open flag
    71                                  	I_need	EXTOPEN_ON,BYTE 	;AN000;FT. extended open flag
    72                                  	I_need	EXTOPEN_IO_MODE,WORD	;AN000;FT. IO mode
    73                                  	I_need	XA_from,BYTE		;AN000;;FT. for get/set XA
    74                                  	I_need	SAVE_ES,WORD		;AN000;;FT. for get/set XA
    75                                  	I_need	SAVE_DI,WORD		;AN000;;FT. for get/set XA
    76                                  	I_need	SAVE_DS,WORD		;AN000;;FT. for get/set XA
    77                                  	I_need	SAVE_SI,WORD		;AN000;;FT. for get/set XA
    78                                  	I_need	SAVE_DX,WORD		;AN000;;FT. for get/set XA
    79                                  	I_need	SAVE_BX,WORD		;AN000;;FT. for get/set XA
    80                                  	I_need	SAVE_CX,WORD		;AN000;;FT. for get/set XA
    81                                  	I_need	NO_FILTER_DPATH,DWORD	;AN000;; pointer to original path of dest
    82                                  	I_need	Temp_Var,WORD		;AN000;;
    83                                  	I_need	DOS34_FLAG,WORD 	;AN000;;
    84                                  	I_need	Temp_Var2,WORD		;AN000;;
    85                                  %if debug
    86                                  	I_need	BugLev,WORD
    87                                  	I_need	BugTyp,WORD
    88                                  %include "bugtyp.nas"
    89                                  %endif
    90                                  
    91                                  BREAK <$Open - open a file from a path string>
    92                                  
    93                                  ;
    94                                  ;   $Open - given a path name in DS:DX and an open mode in AL, access the file
    95                                  ;	and return a handle
    96                                  ;   Inputs:	DS:DX - pointer to asciz name
    97                                  ;		AL - open mode
    98                                  ;   Outputs:	Carry Set - AX has error code for invalid open
    99                                  ;		Carry Clear - AX has per process handle number
   100                                  ;   Registers modified: most
   101                                  
   102                                  Procedure   D_Open,NEAR
   102          ******************       warning: proc D_Open... [-w+user]
   103                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   104                                  	fmt TypSysCall,LevLog,<"Open\n">
   105                                  	fmt TypSysCall,LevArgs,<" Mode = $x file = '$S'\n">,<AX,DS,DX>
   106 00000000 30E4                    	XOR	AH,AH
   107                                  Entry D_Open2				;AN000;
   108 00000002 B516                    	mov	ch,attr_hidden+attr_system+attr_directory
   109 00000004 E86202                  	call	SetAttrib
   110                                  DOSGroup equ DOSGROUP	; NASM port equate
   111                                  DOS_Open equ DOS_OPEN	; NASM port label
   112 00000007 B9[0000]                	MOV	CX,OFFSET DOS_Open	; address of routine to call
   113 0000000A 50                      	SaveReg <AX>			; Save mode on stack
   114                                  %IF DBCS 				;AN000;
   115                                  	MOV	word [ss:Temp_Var],0		;AN000;KK. set variable with 0
   116                                  %ENDIF					;AN000;
   117                                  
   118                                  AccessFile:
   119                                  ;
   120                                  ; Grab a free SFT.
   121                                  ;
   122                                  %IF  DBCS				;AN000;
   123                                  	TEST	word [ss:Temp_Var],8		;AN000;;KK. volume id bit set		       ;AN000;
   124                                  	JZ	novol			;AN000;;KK. no				       ;AN000;
   125                                  	OR	word [ss:DOS34_FLAG],DBCS_VOLID ;AN000;;KK. set bit for transpath	       ;AN000;
   126                                  novol:					;AN000;
   127                                  %ENDIF					;AN000;
   128 0000000B E8(0000)                	EnterCrit   critSFT
   129 0000000E E8(0000)                	invoke	SFNFree 		; get a free sfn
   130 00000011 E8(0000)                	LeaveCrit   critSFT
   131 00000014 7214                    	JC	OpenFailJ		; oops, no free sft's
   132 00000016 36891E[0000]            	MOV	[ss:SFN],BX			; save the SFN for later
   133                                  	fmt	TypAccess,LevSFN,<"AccessFile setting SFN to $x\n">,<BX>
   134                                  ThisSFT equ ThisSft	; NASM port label
   135 0000001B 36893E[0000]            	MOV	WORD PTR [ss:ThisSFT],DI	; save the SF offset
   136 00000020 368C06[0200]            	MOV	WORD PTR [ss:ThisSFT+2],ES ; save the SF segment
   137                                  ;
   138                                  ; Find a free area in the user's JFN table.
   139                                  ;
   140 00000025 E8(0000)                	invoke	JFNFree 		; get a free jfn
   141 00000028 7303                    	JNC	SaveJFN
   142                                  OpenFailJ:
   143 0000002A E99900                  	JMP	OpenFail		; there were free JFNs... try SFN
   144                                  SaveJFN:
   145 0000002D 36893E[0000]            	MOV	WORD PTR [ss:pJFN],DI	; save the jfn offset
   146 00000032 368C06[0200]            	MOV	WORD PTR [ss:pJFN+2],ES	; save the jfn segment
   147 00000037 36891E[0000]            	MOV	[ss:JFN],BX		; save the jfn itself
   148                                  ;
   149                                  ; We have been given an JFN.  We lock it down to prevent other tasks from
   150                                  ; reusing the same JFN.
   151                                  ;
   152 0000003C 368B1E[0000]            	MOV	BX,[ss:SFN]
   153 00000041 26881D                  	MOV	[ES:DI],BL		; assign the JFN
   154 00000044 89D6                    	MOV	SI,DX			; get name in appropriate place
   155 00000046 BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGroup  ; appropriate buffer
   156 00000049 51                      	SaveReg <CX>			; save routine to call
   157 0000004A E8(0000)                	invoke	TransPath		; convert the path
   158 0000004D 5B                      	RestoreReg  <BX>		; restore routine to call
   159 0000004E 36C536[0000]            	LDS	SI,[ss:ThisSFT]
   160                                  	ASSUME	DS:NOTHING
   161 00000053 720A                    	JC	OpenCleanJ		; no error, go and open file
   162 00000055 36803E[0000]FF          	CMP	byte [ss:cMeta],-1
   163 0000005B 7405                    	JZ	SetSearch
   164 0000005D B002                    	MOV	AL,error_file_not_found ; no meta chars allowed
   165                                  OpenCleanJ:
   166 0000005F EB56                    	JMP	OpenClean
   167 00000061 90                      	nop	; identicalise
   168                                  SetSearch:
   169 00000062 58                      	RestoreReg  <AX>		; Mode (Open), Attributes (Create)
   170                                  ;
   171                                  ; We need to get the new inheritance bits.
   172                                  ;
   173 00000063 31C9                    	xor	cx,cx
   174 00000065 81FB[0000]              	CMP	BX,OFFSET DOS_OPEN
   175 00000069 7509                    	JNZ	DoOper
   176 0000006B A880                    	TEST	AL,sharing_no_inherit	; look for no inher
   177 0000006D 7405                    	JZ	DoOper
   178 0000006F 247F                    	AND	AL,07Fh 		; mask off inherit bit
   179 00000071 B90010                  	MOV	CX,sf_no_inherit
   180                                  DoOper:
   181 00000074 C744020000              	MOV	word [SI + sf_mode],0		; initialize mode field to 0
   182                                  SF_mft equ sf_MFT	; NASM port equate
   183 00000079 C744330000              	MOV	word [SI + SF_mft],0		; clean out sharing info
   184                                  ;
   185                                  ;------------------------------------------------------------HKN 8/7/88
   186                                  ;	Check if this is an extended open. If so you must set the 
   187                                  ;	modes in sf_mode. Call Set_EXT_mode to do all this. See
   188                                  ;	Set_EXT_mode in creat.asm
   189                                  ;
   190                                  %IFN IBMCOPYRIGHT
   191                                  
   192 0000007E 06                      	push	es	; set up es:di to point to SFT
   193 0000007F 57                      	push	di
   194 00000080 1E                      	push	ds
   195 00000081 07                      	pop	es
   196                                   assume es:nothing
   197 00000082 56                      	push	si
   198 00000083 5F                      	pop	di
   199 00000084 E8(0000)                	call	Set_EXT_mode
   200 00000087 5F                      	pop	di
   201 00000088 07                      	pop	es
   202                                   assume es:nothing
   203                                  
   204                                  %ENDIF
   205                                  
   206                                  ;-----------------------------------------------------------------------
   207                                  
   208 00000089 161F                    	Context DS
   209 0000008B 51                      	SaveReg <CX>
   210 0000008C FFD3                    	CALL	BX			; blam!
   211 0000008E 59                      	RestoreReg  <CX>
   212 0000008F C536[0000]              	LDS	SI,[ThisSFT]
   213                                  	ASSUME	DS:NOTHING
   214 00000093 721A                    	JC	OpenE2			;AN000;FT. chek extended open hooks first
   215                                  ;
   216                                  ; The SFT was successfully opened.  Remove busy mark.
   217                                  ;
   218                                  OpenOK:
   219                                  	ASSUME	DS:NOTHING
   220                                  ;	MOV	AL,[SI].sf_attr_hi	;AN000;FT. save file type for EXEC
   221                                  ;	MOV	BYTE PTR [Temp_Var2],AL ;AN000;FT.
   222 00000095 C7040100                	MOV	word [SI + sf_ref_count],1
   223 00000099 094C05                  	OR	[SI + sf_flags],CX	; set no inherit bit if necessary
   224                                  ;
   225                                  ; If the open mode is 70, we scan the system for other SFT's with the same
   226                                  ; contents.  If we find one, then we can 'collapse' thissft onto the already
   227                                  ; opened one.  Otherwise we use this new one.  We compare uid/pid/mode/mft
   228                                  ;
   229                                  ; Since this is only relevant on sharer systems, we stick this code into the
   230                                  ; sharer.
   231                                  ;
   232 0000009C 36A1[0000]              	MOV	AX,[ss:JFN]
   233                                  %if installed
   234 000000A0 36FF1E[3000]            	Call	far [ss:JShare + 12 * 4]
   235                                  %else
   236                                  	Call	ShCol
   237                                  %endif
   238                                  	fmt	TypAccess,LevSFN,<"AccessFile setting SFN to -1\n">
   239 000000A5 36C706[0000]FFFF        	MOV	word [ss:SFN],-1			; clear out sfn pointer
   240                                  	fmt	TypSysCall,LevLog,<"Open/CreateXX: return $x\n">,<AX>
   241 000000AC E9(0000)                	transfer    Sys_Ret_OK		; bye with no errors
   242                                  ;Extended Open hooks check
   243                                  OpenE2: 				   ;AN000;;EO.
   244 000000AF 83F857                  	CMP	AX,error_invalid_parameter ;AN000;;EO. IFS extended open ?
   245 000000B2 7504                    	JNZ	OpenE			   ;AN000;;EO. no.
   246 000000B4 EB12                    	JMP	OpenCritLeave		   ;AN000;;EO. keep handle
   247 000000B6 90                      	nop	; identicalise
   248                                  
   249                                  ;Extended Open hooks check
   250                                  ;
   251                                  ; AL has error code.  Stack has argument to dos_open/dos_create.
   252                                  ;
   253                                  OpenClean:
   254                                  	fmt TypSysCall,LevLog,<"Return value from transpath $x\n">,<AX>
   255 000000B7 5B                      	RestoreReg  <bx>		; clean off stack
   256                                  OpenE:
   257                                  SF_Ref_Count equ sf_ref_count	; NASM port equate
   258 000000B8 C7040000                	MOV	word [SI + SF_Ref_Count],0	; release SFT
   259 000000BC 36C536[0000]            	LDS	SI,[ss:pJFN]
   260 000000C1 C604FF                  	MOV	BYTE PTR [SI],0FFh	; free the SFN...
   261 000000C4 EB02                    	JMP	SHORT OpenCritLeave
   262                                  
   263                                  OpenFail:
   264 000000C6 FB                      	STI
   265 000000C7 59                      	RestoreReg  <CX>		; Clean stack
   266                                  OpenCritLeave:
   267 000000C8 36C706[0000]FFFF        	MOV	word [ss:SFN],-1			; remove mark.
   268                                  	fmt TypSysCall,LevLog,<"Open/CreateXX: error $x\n">,<AX>
   269                                  ;; File Tagging DOS 4.00
   270 000000CF 36833E[0000]25          	CMP	word [ss:EXTERR],error_Code_Page_Mismatched	;AN000;;FT. code page mismatch
   271 000000D5 7503                    	JNZ	NORERR					;AN000;;FT. no
   272 000000D7 E9(0000)                	transfer From_GetSet				;AN000;;FT. yes
   273                                  NORERR: 						;AN000;
   274                                  
   275                                  ;; File Tagging DOS 4.00
   276 000000DA E9(0000)                	transfer    Sys_Ret_Err 	; no free, return error
   277                                  
   278                                  EndProc D_Open
   278          ******************       warning: ***** Possible stack size error in D_Open ***** [-w+user]
   279                                  
   280                                  BREAK <$Creat - create a brand-new file>
   281                                  
   282                                  ;
   283                                  ;   $Creat - create the directory entry specified in DS:DX and give it the
   284                                  ;	initial attributes contained in CX
   285                                  ;   Inputs:	DS:DX - ASCIZ path name
   286                                  ;		CX - initial attributes
   287                                  ;   Outputs:	Carry set - AX has error code
   288                                  ;		Carry reset - AX has handle
   289                                  ;   Registers modified: all
   290                                  
   291                                  Procedure   D_Creat,NEAR
   291          ******************       warning: proc D_Creat... [-w+user]
   292                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   293                                  	fmt TypSysCall,LevLog,<"Create\n">
   294                                  	fmt TypSysCall,LevArgs,<" Att = $x file = '$S'\n">,<CX,DS,DX>
   295                                  %IF DBCS 				;AN000;
   296                                  	MOV	[ss:Temp_Var],CX		;AN000;KK. set variable with attribute	      ;AN000;
   297                                  %ENDIF					;AN000;
   298 000000DD 51                      	SaveReg <CX>			; Save attributes on stack
   299                                  DOS_Create equ DOS_CREATE	; NASM port label
   300 000000DE B9[0000]                	MOV	CX,OFFSET DOS_Create	; routine to call
   301                                  AccessSet:
   302                                  SAttrib equ Sattrib	; NASM port label
   303 000000E1 36C606[0000]06          	mov	byte [ss:SAttrib],attr_hidden+attr_system
   304 000000E7 E921FF                  	JMP	AccessFile		; use good ol' open
   305                                  EndProc D_Creat
   305          ******************       warning: ***** Possible stack size error in D_Creat ***** [-w+user]
   306                                  
   307                                  BREAK <$CHMOD - change file attributes>
   308                                  ;
   309                                  ;   Assembler usage:
   310                                  ;	    LDS     DX, name
   311                                  ;	    MOV     CX, attributes
   312                                  ;	    MOV     AL,func (0=get, 1=set)
   313                                  ;	    INT     21h
   314                                  ;   Error returns:
   315                                  ;	    AX = error_path_not_found
   316                                  ;	    AX = error_access_denied
   317                                  ;
   318                                  
   319                                  	procedure D_CHMOD,NEAR
   319          ******************       warning: proc D_CHMOD... [-w+user]
   320                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   321 000000EA BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGroup  ; appropriate buffer
   322 000000ED 5051                    	SaveReg <AX,CX> 		; save function and attributes
   323 000000EF 89D6                    	MOV	SI,DX			; get things in appropriate places
   324 000000F1 E8(0000)                	invoke	TransPathSet		; get correct path
   325 000000F4 5958                    	RestoreReg  <CX,AX>		; and get function and attrs back
   326 000000F6 7233                    	JC	ChModErr		; errors get mapped to path not found
   327 000000F8 161F                    	Context DS			; set up for later possible calls
   328 000000FA 803E[0000]FF            	CMP	byte [cMeta],-1
   329 000000FF 752A                    	JNZ	ChModErr
   330 00000101 C606[0000]16            	MOV	byte [SAttrib],attr_hidden+attr_system+attr_directory
   331 00000106 2C01                    	SUB	AL,1			; fast way to discriminate
   332 00000108 720B                    	JB	ChModGet		; 0 -> go get value
   333 0000010A 7416                    	JZ	ChModSet		; 1 -> go set value
   334                                  errLoc_Unk equ errLOC_Unk	; NASM port equate
   335 0000010C C606[0000]01            	MOV	byte [EXTERR_LOCUS],errLoc_Unk ; Extended Error Locus
   336 00000111 B001EBC5                	error	error_invalid_function	; bad value
   337                                  ChModGet:
   338 00000115 E8(0000)                	invoke	Get_File_Info		; suck out the ol' info
   339                                  ChModE equ ChmodE	; NASM port label
   340 00000118 7213                    	JC	ChModE			; error codes are already set for ret
   341 0000011A E8(0000)                	invoke	Get_User_stack		; point to user saved vaiables
   342                                  User_CX equ user_CX	; NASM port equate
   343 0000011D 894404                  	MOV	[SI + User_CX],AX 	; return the attributes
   344 00000120 EB8A                    	transfer    Sys_Ret_OK		; say sayonara
   345                                  ChModSet:
   346 00000122 89C8                    	MOV	AX,CX			; get attrs in position
   347 00000124 E8(0000)                	invoke	Set_File_Attribute	; go set
   348 00000127 7204                    	JC	ChModE			; errors are set
   349 00000129 EBF5                    	transfer    Sys_Ret_OK
   350                                  ChModErr:
   351 0000012B B003                    	mov	al,error_path_not_found
   352                                  ChmodE:
   353 0000012D EBE4                    	Transfer    SYS_RET_ERR
   354                                  EndProc D_ChMod
   355                                  
   356                                  BREAK <$UNLINK - delete a file entry>
   357                                  ;
   358                                  ;   Assembler usage:
   359                                  ;	    LDS     DX, name
   360                                  ;	    IF VIA SERVER DOS CALL
   361                                  ;	     MOV     CX,SEARCH_ATTRIB
   362                                  ;	    MOV     AH, Unlink
   363                                  ;	    INT     21h
   364                                  ;
   365                                  ;   Error returns:
   366                                  ;	    AX = error_file_not_found
   367                                  ;	       = error_access_denied
   368                                  ;
   369                                  
   370                                  	procedure D_UNLINK,NEAR
   370          ******************       warning: proc D_UNLINK... [-w+user]
   371                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   372 0000012F 51                      	SaveReg <CX>			; Save possible CX input parm
   373 00000130 89D6                    	MOV	SI,DX			; Point at input string
   374 00000132 BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGroup  ; temp spot for path
   375 00000135 E8(0000)                	invoke	TransPathSet		; go get normalized path
   376 00000138 59                      	RestoreReg <CX>
   377 00000139 72F0                    	JC	ChModErr		; badly formed path
   378 0000013B 36803E[0000]FF          	CMP	byte [ss:cMeta],-1		; meta chars?
   379 00000141 750E                    	JNZ	NotFound
   380 00000143 161F                    	Context DS
   381 00000145 B506                    	mov	ch,attr_hidden+attr_system   ; unlink appropriate files
   382 00000147 E81F01                  	call	SetAttrib
   383 0000014A E8(0000)                	invoke	DOS_Delete		; remove that file
   384 0000014D 7204                    	JC	UnlinkE 		; error is there
   385                                  
   386                                  
   387 0000014F EBD8                    	transfer    Sys_Ret_OK		; okey doksy
   388                                  NotFound:
   389 00000151 B003                    	MOV	AL,error_path_not_found
   390                                  UnlinkE:
   391 00000153 EBD8                    	transfer    Sys_Ret_Err 	; bye
   392                                  EndProc D_UnLink
   393                                  
   394                                  BREAK <$RENAME - move directory entries around>
   395                                  ;
   396                                  ;   Assembler usage:
   397                                  ;	    LDS     DX, source
   398                                  ;	    LES     DI, dest
   399                                  ;	    IF VIA SERVER DOS CALL
   400                                  ;	     MOV     CX,SEARCH_ATTRIB
   401                                  ;	    MOV     AH, Rename
   402                                  ;	    INT     21h
   403                                  ;
   404                                  ;   Error returns:
   405                                  ;	    AX = error_file_not_found
   406                                  ;	       = error_not_same_device
   407                                  ;	       = error_access_denied
   408                                  
   409                                  	procedure D_RENAME,NEAR
   409          ******************       warning: proc D_RENAME... [-w+user]
   410                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   411 00000155 511E52                  	SaveReg <CX,DS,DX>		; save source and possible CX arg
   412 00000158 06                      	PUSH	ES
   413 00000159 1F                      	POP	DS			; move dest to source
   414                                   assume ds:nothing
   415 0000015A 89FE                    	MOV	SI,DI			; save for offsets
   416 0000015C BF[0000]                	MOV	DI,OFFSET RenBuf wrt DOSGroup
   417                                  
   418 0000015F 368936[0000]            	MOV	WORD PTR [ss:NO_FILTER_DPATH],SI	;AN000;;IFS. save them for IFS
   419 00000164 368C1E[0200]            	MOV	WORD PTR [ss:NO_FILTER_DPATH+2],DS ;AN000;;IFS.
   420                                  
   421 00000169 E8(0000)                	invoke	TransPathSet		; munge the paths
   422 0000016C 36FF36[0000]            	PUSH	word [ss:WFP_Start]		; get pointer
   423 00000171 368F06[0000]            	POP	word [ss:Ren_WFP] 		; stash it
   424 00000176 5E1F59                  	RestoreReg <SI,DS,CX>		; get back source and possible CX arg
   425                                   assume ds:nothing
   426 00000179 72B0                    epjc2:	JC	ChModErr		; get old error
   427 0000017B 36803E[0000]FF          	CMP	byte [ss:cMeta],-1
   428 00000181 75CE                    	JNZ	NotFound
   429 00000183 51                      	SaveReg <CX>			; Save possible CX arg
   430 00000184 BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGroup  ; appropriate buffer
   431 00000187 E8(0000)                	invoke	TransPathSet		; wham
   432 0000018A 59                      	RestoreReg <CX>
   433                                  EPJC2 equ epjc2	; NASM port label
   434 0000018B 72EC                    	JC	EPJC2
   435 0000018D 161F                    	Context DS
   436 0000018F 803E[0000]FF            	CMP	byte [cMeta],-1
   437 00000194 72BB                    	JB	NotFound
   438                                  
   439                                  THISCDS equ ThisCDS	; NASM port label
   440 00000196 FF36[0000]              	PUSH	WORD PTR [THISCDS]	   ;AN000;;MS.save thiscds
   441 0000019A FF36[0200]              	PUSH	WORD PTR [THISCDS+2]	   ;AN000;;MS.
   442 0000019E BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGROUP ;AN000;;MS.
   443 000001A1 16                      	PUSH	SS			   ;AN000;;MS.
   444 000001A2 07                      	POP	ES			   ;AN000;;MS.es:di-> source
   445                                   assume es:DOSGROUP
   446 000001A3 30C0                    	XOR	AL,AL			   ;AN000;;MS.scan all CDS
   447                                  rnloop: 				   ;AN000;
   448 000001A5 E8(0000)                	invoke	GetCDSFromDrv		   ;AN000;;MS.
   449 000001A8 7210                    	JC	dorn			   ;AN000;;MS.	end of CDS
   450 000001AA E8(0000)                	invoke	StrCmp			   ;AN000;;MS.	current dir ?
   451 000001AD 7404                    	JZ	rnerr			   ;AN000;;MS.	yes
   452 000001AF FEC0                    	INC	AL			   ;AN000;;MS.	next
   453 000001B1 EBF2                    	JMP	rnloop			   ;AN000;;MS.
   454                                  rnerr:					   ;AN000;
   455 000001B3 83C404                  	ADD	SP,4			   ;AN000;;MS. pop thiscds
   456 000001B6 B010EB99                	error	error_current_directory    ;AN000;;MS.
   457                                  dorn:					   ;AN000;
   458 000001BA 368F06[0200]            	POP	WORD PTR [SS:THISCDS+2]    ;AN000;;MS.
   459 000001BF 368F06[0000]            	POP	WORD PTR [SS:THISCDS]	   ;AN000;;MS.
   460 000001C4 161F                    	Context DS
   461 000001C6 B516                    	mov	ch,attr_directory+attr_hidden+attr_system; rename appropriate files
   462 000001C8 E89E00                  	call	SetAttrib
   463 000001CB E8(0000)                	invoke	DOS_Rename		; do the deed
   464 000001CE 7283                    	JC	UnlinkE 		; errors
   465                                  
   466                                  
   467 000001D0 E9(0000)                	transfer    Sys_Ret_OK
   468                                  EndProc D_Rename
   469                                  
   470                                  Break <$CreateNewFile - Create a new directory entry>
   471                                  
   472                                  ;
   473                                  ;   CreateNew - Create a new directory entry.  Return a file handle if there
   474                                  ;	was no previous directory entry, and fail if a directory entry with
   475                                  ;	the same name existed previously.
   476                                  ;
   477                                  ;   Inputs:	DS:DX point to an ASCIZ file name
   478                                  ;		CX contains default file attributes
   479                                  ;   Outputs:	Carry Clear:
   480                                  ;		    AX has file handle opened for read/write
   481                                  ;		Carry Set:
   482                                  ;		    AX has error code
   483                                  ;   Registers modified: All
   484                                  
   485                                  	Procedure D_CreateNewFile,NEAR
   485          ******************       warning: proc D_CreateNewFile... [-w+user]
   486                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   487                                  	fmt TypSysCall,LevLog,<"CreateNew\n">
   488                                  	fmt TypSysCall,LevArgs,<" Att = $x file = '$S'\n">,<CX,DS,DX>
   489                                  %IF DBCS 				;AN000;
   490                                  	MOV	[ss:Temp_Var],CX		;AN000;KK. set variable with attribute
   491                                  %ENDIF					;AN000;
   492 000001D3 51                      	SaveReg <CX>			; Save attributes on stack
   493 000001D4 B9[0000]                	MOV	CX,OFFSET DOS_Create_New; routine to call
   494 000001D7 E907FF                  	JMP	AccessSet		; use good ol' open
   495                                  EndProc D_CreateNewFile
   495          ******************       warning: ***** Possible stack size error in D_CreateNewFile ***** [-w+user]
   496                                  
   497                                  Break	<HexToAsciz - convert a number to hex and store it in memory>
   498                                  
   499                                  ;
   500                                  ;   HexToAsciz - used to convert register into a hex number.
   501                                  ;
   502                                  ;   Inputs:	AX contains the number
   503                                  ;		ES:DI point to destination
   504                                  ;   Outputs:	ES:DI updated
   505                                  ;   Registers modified: DI,CX
   506                                  
   507                                  Procedure   HexToAsciz,NEAR
   507          ******************       warning: proc HexToAsciz... [-w+user]
   508 000001DA B90400                  	mov	cx,4			; 4 digits in AX
   509                                  GetDigit:
   510 000001DD 51                      	SaveReg <CX>			; preserve count
   511 000001DE B104                    	mov	cl,4
   512 000001E0 D3C0                    	ROL	AX,CL			; move leftmost nibble into rightmost
   513 000001E2 50                      	SaveReg <AX>			; preserve remainder of digits
   514 000001E3 240F                    	AND	AL,0Fh			; grab low nibble
   515 000001E5 0441                    	ADD	AL,'A'                  ; turn into a letter (A to P)
   516 000001E7 AA                      	STOSB				; drop in the character
   517 000001E8 5859                    	RestoreReg <AX,CX>		; regain the number and count
   518 000001EA E2F1                    	loop	GetDigit		; while there's more digits, go do 'em
   519 000001EC C3                      	return
   520                                  EndProc HexToAsciz
   521                                  
   522                                  Break	<$CreateTempFile - create a unique name>
   523                                  
   524                                  ;
   525                                  ;   $CreateTemp - given a directory, create a unique name in that directory.
   526                                  ;	Method used is to get the current time, convert to a name and attempt
   527                                  ;	a create new.  Repeat until create new succeeds.
   528                                  ;
   529                                  ;   Inputs:	DS:DX point to a null terminated directory name.
   530                                  ;		CX  contains default attributes
   531                                  ;   Outputs:	Unique name is appended to DS:DX directory.
   532                                  ;		AX has handle
   533                                  ;   Registers modified: all
   534                                  
   535                                  	Procedure D_CreateTempFile,NEAR
   535          ******************       warning: proc D_CreateTempFile... [-w+user]
   536                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGroup
   537                                  	fmt TypSysCall,LevLog,<"CreateTmp\n">
   538                                  	fmt TypSysCall,LevArgs,<" Att = $x dir = '$S'\n">,<CX,DS,DX>
   539                                  PUBLIC FILE001S,FILE001E
   540                                  FILE001S:
   541                                  	LocalVar    EndPtr,DWORD
   542                                  	LocalVar    FilPtr,DWORD
   543                                  	LocalVar    Attr,WORD
   544                                  FILE001E:
   545 000001ED 5589E583EC0A            	Enter
   546 000001F3 F7C1D8FF                	TEST	CX,~ attr_changeable
   547 000001F7 7405                    	JZ	OKatts			; Ok if no non-changeable bits set
   548                                  ;
   549                                  ; We need this "hook" here to detect these cases (like user sets one both of
   550                                  ; vol_id and dir bits) because of the structure of the or $CreateNewFile loop
   551                                  ; below.  The code loops on error_access_denied, but if one of the non
   552                                  ; changeable attributes is specified, the loop COULD be infinite or WILL be
   553                                  ; infinite because CreateNewFile will fail with access_denied always.  Thus we
   554                                  ; need to detect these cases before getting to the loop.
   555                                  ;
   556 000001F9 B80500                  	MOV	AX,error_access_denied
   557 000001FC EB5F                    	JMP	SHORT SETTMPERR
   558                                  
   559                                  OKatts:
   560 000001FE 894EF6                  	MOV	[attr],CX 		; save attribute
   561 00000201 8956F8                  	MOV	[FilPtrL],DX		; pointer to file
   562 00000204 8C5EFA                  	MOV	[FilPtrH],DS
   563 00000207 8C5EFE                  	MOV	[EndPtrH],DS		; seg pointer to end of dir
   564 0000020A 1E                      	PUSH	DS
   565 0000020B 07                      	POP	ES			; destination for nul search
   566                                   assume es:nothing
   567 0000020C 89D7                    	MOV	DI,DX
   568 0000020E 89F9                    	MOV	CX,DI
   569 00000210 F7D9                    	NEG	CX			; number of bytes remaining in segment
   570                                   %IF  DBCS				;AN000;
   571                                  Kloop:					;AN000;; 2/13/KK
   572                                  	MOV	AL, BYTE PTR [ES:DI]	;AN000;; 2/13/KK
   573                                  	INC	DI			;AN000;; 2/13/KK
   574                                  	OR	AL,AL			;AN000;; 2/13/KK
   575                                  	JZ	GOTEND			;AN000;; 2/13/KK
   576                                  	invoke	testkanj		;AN000;; 2/13/KK
   577                                  	jz	Kloop			;AN000;; 2/13/KK
   578                                  	inc	di			;AN000;; Skip over second kanji byte 2/13/KK
   579                                  	CMP	BYTE PTR [ES:DI],0	;AN000;; 2/13/KK
   580                                  	JZ	STOREPTH		;AN000; When char before NUL is sec Kanji byte
   581                                  					;AN000; do not look for path char. 2/13/KK
   582                                  	jmp	Kloop			;AN000; 2/13/KK
   583                                  GOTEND: 				;AN000; 2/13/KK
   584                                   %ELSE					;AN000;
   585 00000212 09C9                    	OR	CX,CX			;AN000;MS.  cx=0 ? ds:dx on segment boundary
   586 00000214 7503                    	JNZ	okok			;AN000;MS.  no
   587 00000216 B9FFFF                  	MOV	CX,-1			;AN000;MS.
   588                                  okok:					;AN000;
   589 00000219 31C0                    	XOR	AX,AX			;AN000;
   590 0000021B F2AE                    	REPNZ	SCASB			;AN000;
   591                                   %ENDIF					;AN000;
   592 0000021D 4F                      	DEC	DI			; point back to the null
   593 0000021E 268A45FF                	MOV	AL,[ES:DI-1]		; Get char before the NUL
   594 00000222 E8(0000)                	invoke	PathChrCmp		; Is it a path separator?
   595 00000225 7403                    	JZ	SETENDPTR		; Yes
   596                                  STOREPTH:
   597 00000227 B05C                    	MOV	AL,'\'
   598 00000229 AA                      	STOSB				; Add a path separator (and INC DI)
   599                                  SETENDPTR:
   600 0000022A 897EFC                  	MOV	[EndPtrL],DI		; pointer to the tail
   601                                  CreateLoop:
   602 0000022D 161F                    	Context DS			; let ReadTime see variables
   603 0000022F 55                      	SaveReg <BP>
   604 00000230 E8(0000)                	invoke	ReadTime		; go get time
   605 00000233 5D                      	RestoreReg  <BP>
   606                                  ;
   607                                  ; Time is in CX:DX.  Go drop it into the string.
   608                                  ;
   609 00000234 C47EFC                  	les	di,[EndPtr]		; point to the string
   610 00000237 89C8                    	mov	ax,cx
   611 00000239 E89EFF                  	call	HexToAsciz		; store upper word
   612 0000023C 89D0                    	mov	ax,dx
   613 0000023E E899FF                  	call	HexToAsciz		; store lower word
   614 00000241 30C0                    	xor	al,al
   615 00000243 AA                      	STOSB				; nul terminate
   616 00000244 C556F8                  	LDS	DX,[FilPtr]		; get name
   617                                  ASSUME	DS:NOTHING
   618 00000247 8B4EF6                  	MOV	CX,[Attr] 		; get attr
   619 0000024A 55                      	SaveReg <BP>
   620 0000024B E885FF                  	CALL	D_CreateNewFile		; try to create a new file
   621 0000024E 5D                      	RestoreReg  <BP>
   622 0000024F 730D                    	JNC	CreateDone		; failed, go try again
   623                                  ;
   624                                  ; The operation failed and the error has been mapped in AX.  Grab the extended
   625                                  ; error and figure out what to do.
   626                                  ;
   627                                  ExtErr equ EXTERR	; NASM port label
   628 00000251 36A1[0000]              	mov	ax,[ss:ExtErr]
   629 00000255 3C50                    	cmp	al,error_file_exists
   630 00000257 74D4                    	jz	CreateLoop		; file existed => try with new name
   631 00000259 3C05                    	cmp	al,error_access_denied
   632 0000025B 74D0                    	jz	CreateLoop		; access denied (attr mismatch)
   633                                  
   634                                  ;	CMP	AL,error_file_exists	; certain errors cause failure
   635                                  ;	JZ	CreateLoop
   636                                  ;	CMP	AL,error_access_denied
   637                                  ;	JNZ	SETTMPERR		; Error out
   638                                  ;	CMP	[EXTERR],error_cannot_make  ; See if it's REALLY an att mismatch
   639                                  ;	JNZ	CreateLoop		; It was, try again
   640                                  ;	MOV	AL,error_cannot_make	; Return this "extended" error
   641                                  
   642                                  SETTMPERR:
   643 0000025D F9                      	STC
   644                                  CreateDone:
   645 0000025E 89EC5D                  	Leave
   646 00000261 7203                    	JC	CreateFail
   647 00000263 E9(0000)                	transfer    Sys_Ret_OK		; success!
   648                                  CreateFail:
   649 00000266 E9(0000)                	transfer    Sys_Ret_Err
   650                                  EndProc D_CreateTempFile
   651                                  
   652                                  Break	<SetAttrib - set the search attrib>
   653                                  
   654                                  ;
   655                                  ;   SetAttrib will set the search attribute (SAttrib) either to the normal
   656                                  ;   (CH) or to the value in CL if the current system call is through
   657                                  ;   serverdoscall.
   658                                  ;
   659                                  ;   Inputs:	fSharing == FALSE => set sattrib to CH
   660                                  ;		fSharing == TRUE => set sattrib to CL
   661                                  ;   Outputs:	none
   662                                  ;   Registers changed:	CX
   663                                  
   664                                  procedure   SetAttrib,NEAR
   664          ******************       warning: proc SetAttrib... [-w+user]
   665                                  	assume	ds:nothing,es:nothing
   666 00000269 36F606[0000]FF          	test	byte [ss:fSharing],-1
   667 0000026F 7502                    	jnz	Set
   668 00000271 88E9                    	mov	cl,ch
   669                                  Set:
   670 00000273 36880E[0000]            	mov	[ss:SAttrib],cl
   671 00000278 C3                      	return
   672                                  EndProc SetAttrib
   673                                  
   674                                  
   675                                  Break	<Extended_Open- Extended open the file>
   676                                  
   677                                  ; Input: AL= 0 reserved  AH=6CH
   678                                  ;	 BX= mode
   679                                  ;	 CL= create attribute  CH=search attribute (from server)
   680                                  ;	 DX= flag
   681                                  ;	 DS:SI = file name
   682                                  ;	 ES:DI = parm list
   683                                  ;			   DD  SET EA list (-1) null
   684                                  ;			   DW  n  parameters
   685                                  ;			   DB  type (TTTTTTLL)
   686                                  ;			   DW  IOMODE
   687                                  ; Function: Extended Open
   688                                  ; Output: carry clear
   689                                  ;		     AX= handle
   690                                  ;		     CX=1 file opened
   691                                  ;			2 file created/opened
   692                                  ;			3 file replaced/opened
   693                                  ;	  carry set: AX has error code
   694                                  ;
   695                                  
   696                                  
   697                                  procedure   D_Extended_Open,NEAR 			       ;AN000;
   697          ******************       warning: proc D_Extended_Open... [-w+user]
   698                                   ASSUME DS:NOTHING,ES:NOTHING,SS:DOSGROUP  ;AN000;
   699                                  
   700 00000279 36C606[0000]00          	MOV	byte [ss:XA_from],0		  ;AN000;EO. init for set XA
   701 0000027F 368916[0000]            	MOV	[ss:EXTOPEN_FLAG],DX	  ;AN000;EO. save ext. open flag
   702 00000284 36C706[0000]0000        	MOV	word [ss:EXTOPEN_IO_MODE],0	  ;AN000;EO. initialize IO mode
   703 0000028B F7C200FE                	TEST	DX,reserved_bits_mask	  ;AN000;EO. reserved bits 0  ?
   704 0000028F 7545                    	JNZ	ext_inval2		  ;AN000;EO. no
   705 00000291 88D4                    	MOV	AH,DL			  ;AN000;EO. make sure flag is right
   706 00000293 80FA00                  	CMP	DL,0			  ;AN000;EO. all fail ?
   707 00000296 743E                    	JZ	ext_inval2		  ;AN000;EO. yes, error
   708 00000298 80E20F                  	AND	DL,exists_mask		  ;AN000;EO. get exists action byte
   709 0000029B 80FA02                  	CMP	DL,2			  ;AN000;EO, > 02
   710 0000029E 7736                    	JA	ext_inval2		  ;AN000;EO. yes ,error
   711 000002A0 80E4F0                  	AND	AH,not_exists_mask	  ;AN000;EO. get no exists action byte
   712 000002A3 80FC10                  	CMP	AH,10H			  ;AN000;EO. > 10
   713 000002A6 772E                    	JA	ext_inval2		  ;AN000;EO. yes error
   714                                  
   715                                  ;	CMP	DI,-1			  ;AN000;EO. null parm list
   716                                  ;	JZ	no_parm 		  ;AN000;EO. yes
   717                                  ;					  ;AN000;EO
   718                                  ;	PUSH	CX			  ;AN000;EO.
   719                                  ;					  ;AN000;EO.
   720                                  ;	MOV	CX,[ES:DI.EXT_NUM_OF_PARM];AN000;EO. get number of parms
   721                                  ;	OR	CX,CX			  ;AN000;EO. 0 pamrs ?
   722                                  ;	JZ	parmend 		  ;AN000;EO. yes
   723                                  ;	PUSH	SI			  ;AN000;EO.
   724                                  ;	PUSH	DS			  ;AN000;EO.
   725                                  ;	MOV	SI,DI			  ;AN000;EO.
   726                                  ;	ADD	SI,size EXT_OPEN_PARM	  ;AN000;EO. position to 1st parm
   727                                  ;	PUSH	ES			  ;AN000;EO.
   728                                  ;	POP	DS			  ;AN000;EO. ds:si -> parm list
   729                                  ;	CALL	GetIOParms		  ;AN000;EO.
   730                                  ;	POP	DS			  ;AN000;EO.
   731                                  ;	POP	SI			  ;AN000;EO.
   732                                  ;parmend:				  ;AN000;EO
   733                                  ;	POP	CX			  ;AN000;EO. restore CX
   734                                  ;no_parm:				  ;AN000;EO.
   735 000002A8 368C06[0000]            	MOV	[ss:SAVE_ES],ES		  ;AN000;EO. save API parms
   736 000002AD 36893E[0000]            	MOV	[ss:SAVE_DI],DI		  ;AN000;EO.
   737 000002B2 36FF36[0000]            	PUSH	word [ss:EXTOPEN_FLAG]		  ;AN000;EO.
   738 000002B7 368F06[0000]            	POP	word [ss:SAVE_DX]		  ;AN000;EO.
   739 000002BC 36890E[0000]            	MOV	[ss:SAVE_CX],CX		  ;AN000;EO.
   740 000002C1 36891E[0000]            	MOV	[ss:SAVE_BX],BX		  ;AN000;EO.
   741 000002C6 368C1E[0000]            	MOV	[ss:SAVE_DS],DS		  ;AN000;EO.
   742 000002CB 368936[0000]            	MOV	[ss:SAVE_SI],SI		  ;AN000;EO.
   743 000002D0 89F2                    	MOV	DX,SI			  ;AN000;EO. ds:dx points to file name
   744 000002D2 89D8                    	MOV	AX,BX			  ;AN000;EO. ax= mode
   745                                  
   746                                  ;	TEST	[EXTOPEN_FLAG],no_code_page_check    ;AN000;EO. check no  code page
   747                                  ;	JNZ	no_cdpg_chk			 ;AN000;;EO.  no
   748 000002D4 EB0B                    	JMP	SHORT goopen2			 ;AN000;;EO.  do nromal
   749                                  ext_inval2:					 ;AN000;;EO.
   750                                  error_Invalid_Function equ error_invalid_function	; NASM port equate
   751 000002D6 B001EB8C                	error	error_Invalid_Function		 ;AN000;EO..  invalid function
   752                                  ext_inval_parm: 				 ;AN000;EO..
   753 000002DA 59                      	POP	CX				 ;AN000;EO..  pop up satck
   754 000002DB 5E                      	POP	SI				 ;AN000;EO..
   755                                  error_Invalid_data equ error_invalid_data	; NASM port equate
   756 000002DC B00DEBF8                	error	error_Invalid_data		 ;AN000;EO..  invalid parms
   757                                  error_return:					 ;AN000;EO.
   758 000002E0 C3                      	ret					 ;AN000;EO..  return with error
   759                                  ;no_cdpg_chk:						EO.
   760                                  ;	MOV	[CPSWFLAG],0			 ;AN000;EO..  set CPSW flag off
   761                                  goopen2:					 ;AN000;
   762 000002E1 F7C30020                	TEST	BX,int_24_error 		 ;AN000;EO..  disable INT 24 error ?
   763 000002E5 7406                    	JZ	goopen				 ;AN000;EO..  no
   764                                  EXT_OPEN_I24_OFF equ ext_open_I24_off	; NASM port equate
   765 000002E7 36800E[0000]02          	OR	byte [ss:EXTOPEN_ON],EXT_OPEN_I24_OFF	 ;AN000;EO..  set bit to disable
   766                                  
   767                                  goopen: 					 ;AN000;
   768                                  EXT_OPEN_ON equ ext_open_on	; NASM port equate
   769 000002ED 36800E[0000]01          	OR	byte [ss:EXTOPEN_ON],EXT_OPEN_ON	 ;AN000;EO..  set Extended Open active
   770 000002F3 368126[0000]FF00        	AND	word [ss:EXTOPEN_FLAG],0FFH		 ;AN000;EO.create new ?
   771 000002FA 36833E[0000]10          	CMP	word [ss:EXTOPEN_FLAG],ext_exists_fail + ext_nexists_create ;AN000;FT.
   772 00000300 7520                    	JNZ	chknext 			 ;AN000;;EO.  no
   773 00000302 E8CEFE                  	invoke	D_CreateNewFile			 ;AN000;;EO.  yes
   774 00000305 72D9                    	JC	error_return			 ;AN000;;EO.  error
   775 00000307 36803E[0000]00          	CMP	byte [ss:EXTOPEN_ON],0			 ;AN000;;EO.  IFS does it
   776 0000030D 7410                    	JZ	ok_return2			 ;AN000;;EO.  yes
   777 0000030F 36C706[0000]0200        	MOV	word [ss:EXTOPEN_FLAG],action_created_opened ;AN000;EO. creted/opened
   778 00000316 36C606[0000]02          	MOV	byte [ss:XA_from],By_Create		 ;AN000;;EO.  for set xa
   779 0000031C E99500                  	JMP	setXAttr			 ;AN000;;EO.  set XAs
   780                                  ok_return2:
   781 0000031F E9(0000)                	transfer SYS_RET_OK			 ;AN000;;EO.
   782                                  chknext:
   783 00000322 36F706[0000]0100        	TEST	word [ss:EXTOPEN_FLAG],ext_exists_open	 ;AN000;;EO.  exists open
   784 00000329 7532                    	JNZ	exist_open			 ;AN000;;EO.  yes
   785 0000032B E8AFFD                  	invoke	D_Creat				 ;AN000;;EO.  must be replace open
   786 0000032E 72B0                    	JC	error_return			 ;AN000;;EO.  return with error
   787 00000330 36803E[0000]00          	CMP	byte [ss:EXTOPEN_ON],0			 ;AN000;;EO.  IFS does it
   788 00000336 74E7                    	JZ	ok_return2			 ;AN000;;EO.  yes
   789 00000338 36C706[0000]0200        	MOV	word [ss:EXTOPEN_FLAG],action_created_opened  ;AN000;EO. prsume create/open
   790 0000033F 36C606[0000]02          	MOV	byte [ss:XA_from],By_Create		 ;AN000;EO.  for set xa
   791 00000345 36F606[0000]04          	TEST	byte [ss:EXTOPEN_ON],ext_file_not_exists      ;AN000;;EO. file not exists ?
   792 0000034B 7567                    	JNZ	setXAttr			      ;AN000;;EO. no
   793 0000034D 36C706[0000]0300        	MOV	word [ss:EXTOPEN_FLAG],action_replaced_opened ;AN000;;EO. replaced/opened
   794 00000354 36C606[0000]00          	MOV	byte [ss:XA_from],0			      ;AN000;EO. for set xa
   795 0000035A EB58                    	JMP	SHORT setXAttr			      ;AN000;;EO. set XAs
   796                                  error_return2:
   797 0000035C C3                      	ret					 ;AN000;;EO.  return with error
   798                                  						 ;AN000;
   799                                  exist_open:					 ;AN000;
   800 0000035D 36F606[0000]FF          	test	byte [ss:fSharing],-1			 ;AN000;;EO. server doscall?
   801 00000363 7402                    	jz	noserver			 ;AN000;;EO. no
   802 00000365 88E9                    	MOV	CL,CH				 ;AN000;;EO. cl=search attribute
   803                                  
   804                                  noserver:
   805 00000367 E898FC                  	invoke	D_Open2				 ;AN000;;EO.  do open
   806 0000036A 7339                    	JNC	ext_ok				 ;AN000;;EO.
   807 0000036C 36803E[0000]00          	CMP	byte [ss:EXTOPEN_ON],0			 ;AN000;;EO.  error and IFS call
   808 00000372 74E8                    	JZ	error_return2			 ;AN000;;EO.  return with error
   809                                  local_extopen:
   810                                  
   811 00000374 83F802                  	CMP	AX,error_file_not_found 	 ;AN000;;EO.  file not found error
   812 00000377 75E3                    	JNZ	error_return2			 ;AN000;;EO.  no,
   813 00000379 36F706[0000]1000        	TEST	word [ss:EXTOPEN_FLAG],ext_nexists_create;AN000;;EO.  want to fail
   814 00000380 7503                    	JNZ	do_creat			 ;AN000;;EO.  yes
   815 00000382 EB65                    	JMP	extexit 			 ;AN000;;EO.  yes
   816 00000384 90                      	nop	; identicalise
   817                                  do_creat:
   818 00000385 36C606[0000]02          	MOV	byte [ss:XA_from],By_Create		 ;AN000;;EO.  for set xa
   819 0000038B 368B0E[0000]            	MOV	CX,[ss:SAVE_CX]			 ;AN000;;EO.  get ds:dx for file name
   820 00000390 36C536[0000]            	LDS	SI,[ss:SAVE_SI]		 ;AN000;;EO.  cx = attribute
   821 00000395 89F2                    	MOV	DX,SI				 ;AN000;;EO.
   822 00000397 E843FD                  	invoke	D_Creat				 ;AN000;;EO.  do create
   823 0000039A 724D                    	JC	extexit 			 ;AN000;;EO.  error
   824 0000039C 36C706[0000]0200        	MOV	word [ss:EXTOPEN_FLAG],action_created_opened  ;AN000;;EO. is created/opened
   825 000003A3 EB0F                    	JMP	SHORT setXAttr			      ;AN000;;EO.   set XAs
   826                                  
   827                                  ext_ok:
   828 000003A5 36803E[0000]00          	CMP	byte [ss:EXTOPEN_ON],0			 ;AN000;;EO.  IFS call ?
   829 000003AB 7415                    	JZ	ok_return			 ;AN000;;EO.  yes
   830 000003AD 36C706[0000]0100        	MOV	word [ss:EXTOPEN_FLAG],action_opened	 ;AN000;;EO.  opened
   831                                  setXAttr:
   832                                  ;	LES	DI,DWORD PTR [SAVE_DI]	;AN000;EO.
   833 000003B4 50                      	PUSH	AX			;AN000;;EO. save handle for final
   834                                  ;	MOV	BX,AX			;AN000;;EO. bx= handle
   835                                  ;	MOV	AX,04H			;AN000;;EO. set extended attr by handle
   836                                  ;	PUSH	DS			;AN000;;EO. save file name addr
   837                                  ;	PUSH	DX			;AN000;;EO.
   838                                  ;	CMP	DI,-1			;AN000;;EO. null parm list
   839                                  ;	JZ	nosetea 		;AN000;;EO. yes
   840                                  ;	CMP	WORD PTR [ES:DI],-1	;AN000;;EO. null set list
   841                                  ;	JZ	nosetea 		;AN000;;EO. yes
   842                                  ;	LES	DI,DWORD PTR [ES:DI]	;AN000;;EO. es:di -> set list
   843                                  ;	invoke	$File_times		;AN000;;EO.
   844                                  ;nosetea:				;AN000; EO
   845                                  ;	POP	DX			;AN000;;EO. restore file name addr
   846                                  ;	POP	DS			;AN000;;EO.
   847                                  ;	JC	extexit2		;AN000;;EO.
   848 000003B5 E8(0000)                	invoke	get_user_stack		;AN000;;EO.
   849 000003B8 36A1[0000]              	MOV	AX,[ss:EXTOPEN_FLAG]	;AN000;;EO.
   850                                  USER_CX equ user_CX	; NASM port equate
   851 000003BC 894404                  	MOV	[SI + USER_CX],AX 	;AN000;;EO. set action code for cx
   852 000003BF 58                      	POP	AX			;AN000;;EO.
   853                                  USER_AX equ user_AX	; NASM port equate
   854 000003C0 8904                    	MOV	[SI + USER_AX],AX 	;AN000;;EO. set handle for ax
   855                                  
   856                                  ok_return:				;AN000;
   857 000003C2 E9(0000)                	transfer SYS_RET_OK		;AN000;;EO.
   858                                  
   859                                  extexit2:				;AN000; ERROR RECOVERY
   860                                  
   861 000003C5 5B                      	POP	BX			;AN000;EO. close the handle
   862 000003C6 50                      	PUSH	AX			;AN000;EO. save error code from set XA
   863 000003C7 36833E[0000]02          	CMP	word [ss:EXTOPEN_FLAG],action_created_opened	;AN000;EO. from create
   864 000003CD 750C                    	JNZ	justopen		;AN000;EO.
   865 000003CF 36C536[0000]            	LDS	SI,[ss:SAVE_SI]		 ;AN000;EO.  cx = attribute
   866 000003D4 C514                    	LDS	DX,[SI]		 ;AN000;EO.
   867 000003D6 E856FD                  	invoke	D_UNLINK 		;AN000;EO. delete the file
   868 000003D9 EB03                    	JMP	SHORT reserror		;AN000;EO.
   869                                  
   870                                  justopen:				;AN000;
   871 000003DB E8(0000)                	invoke	D_close			;AN000;EO. pretend never happend
   872                                  reserror:				;AN000;
   873 000003DE 58                      	POP	AX			;AN000;EO. retore error code from set XA
   874 000003DF EB08                    	JMP	SHORT extexit		;AN000;EO.
   875                                  
   876                                  
   877                                  ext_file_unfound:			;AN000;
   878 000003E1 B80200                  	MOV	AX,error_file_not_found ;AN000;EO.
   879 000003E4 EB03                    	JMP	SHORT extexit		;AN000;EO.
   880                                  ext_inval:				 ;AN000;
   881 000003E6 B80100                  	MOV	AX,error_invalid_function;AN000;EO.
   882                                  extexit:
   883 000003E9 E9(0000)                	transfer SYS_RET_ERR		;AN000;EO.
   884                                  
   885                                  EndProc D_Extended_Open			;AN000;
   886                                  
   887                                  
   888                                  Break	<GetIOParms - get IO parms form extended open parm list>
   889                                  
   890                                  ;
   891                                  ;
   892                                  ;   Inputs: DS:SI -> IO parm list
   893                                  ;	    CX= number of parms
   894                                  ;   Function: get IO parms from parm list
   895                                  ;   Outputs:  [EXT_IOMODE]= IO mode parm
   896                                  
   897                                  ;procedure   GetIOParms,NEAR
   898                                  ;	assume	ds:nothing,es:nothing
   899                                  ;
   900                                  ;	LODSB					; get parm type 		;AN000;
   901                                  ;	CMP	AL,0*100B+10B			; have IOMODE			;AN000;
   902                                  ;	JE	SET_IOMODE							;AN000;
   903                                  ;	AND	AL,00000011B			; decode it			;AN000;
   904                                  ;	JZ	SKIP_ASCIIZ							;AN000;
   905                                  ;	DEC	AL								;AN000;
   906                                  ;	JZ	SKIP_LEN							;AN000;
   907                                  ;;	DEC	AL								;AN000;
   908                                  ;	JZ	SKIP_WORD							;AN000;
   909                                  ;SKIP_DWORD:					 ; copy DWORD parm		 ;AN000;
   910                                  ;	LODSW									;AN000;
   911                                  ;SKIP_WORD:					 ; copy WORD parm		 ;AN000;
   912                                  ;	LODSW									;AN000;
   913                                  ;	JMP	SHORT NEXT_PARM 						;AN000;
   914                                  ;SET_IOMODE:					 ; copy IOMODE			 ;AN000;
   915                                  ;	LODSW									;AN000;
   916                                  ;	MOV	[EXTOPEN_IO_MODE],AX						;AN000;
   917                                  ;	JMP	SHORT NEXT_PARM 						;AN000;
   918                                  ;SKIP_LEN:					 ; copy LENGTH parm		 ;AN000;
   919                                  ;	LODSW									;AN000;
   920                                  ;	ADD	SI,AX								;AN000;
   921                                  ;	JMP	SHORT NEXT_PARM 						;AN000;
   922                                  ;SKIP_ASCIIZ:					 ; copy ASCIIZ parm		 ;AN000;
   923                                  ;	LODSB									;AN000;
   924                                  ;	OR	AL,AL								;AN000;
   925                                  ;	JNE	SKIP_ASCIIZ							;AN000;
   926                                  ;NEXT_PARM:									 ;AN000;
   927                                  ;	LOOP	GetIOParms							;AN000;
   928                                  ;	return									;AN000;
   929                                  ;EndProc GetIOParms								 ;AN000;
   930                                  
   931                                  END
   932                                  
   933                                  
