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