     1                                  ;	SCCSID = @(#)open.asm	1.1 85/04/10
     2                                  ;TITLE	DOS_OPEN - Internal OPEN call for MS-DOS
     3                                  ;NAME	DOS_OPEN
     4                                  ; Low level routines for openning a file from a file spec.
     5                                  ;   Also misc routines for sharing errors
     6                                  ;
     7                                  ;   DOS_Open
     8                                  ;   Check_Access_AX
     9                                  ;   SHARE_ERROR
    10                                  ;   SET_SFT_MODE
    11                                  ;   Code_Page_Mismatched_Error		   ; DOS 4.00
    12                                  ;
    13                                  ;   Revision history:
    14                                  ;
    15                                  ;	Created: ARR 30 March 1983
    16                                  ;	A000	version 4.00   Jan. 1988
    17                                  ;
    18                                  
    19                                  ;
    20                                  ; get the appropriate segment definitions
    21                                  ;
    22                                  [list -]
    22          ******************       warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14          ******************  <4>  warning: redefining multi-line macro `__@@_next' [-w+pp-macro-redef-multi]
    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
    25                                  
    26                                  [list +]
    27                                  section DOSCODECODE
    28                                  [list -]
    28          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    28          ******************       warning: out: BPB.INC... [-w+user]
    28          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    28          ******************       warning: out: DEVSYM.INC... [-w+user]
    38                                  
    39                                  %iassign Installed TRUE
    40                                  
    41                                  	i_need	NoSetDir,BYTE
    42                                  	i_need	THISSFT,DWORD
    43                                  	i_need	THISCDS,DWORD
    44                                  	i_need	CURBUF,DWORD
    45                                  	i_need	CurrentPDB,WORD
    46                                  	i_need	CURR_DIR_END,WORD
    47                                  	I_need	RetryCount,WORD
    48                                  	I_need	Open_Access,BYTE
    49                                  	I_need	fSharing,BYTE
    50                                  	i_need	JShare,DWORD
    51                                  	I_need	FastOpenFlg,byte
    52                                  	I_need	EXTOPEN_ON,BYTE 		  ;AN000;; DOS 4.00
    53                                  	I_need	ALLOWED,BYTE			  ;AN000;; DOS 4.00
    54                                  	I_need	EXTERR,WORD			  ;AN000;; DOS 4.00
    55                                  	I_need	EXTERR_LOCUS,BYTE		  ;AN000;; DOS 4.00
    56                                  	I_need	EXTERR_ACTION,BYTE		  ;AN000;; DOS 4.00
    57                                  	I_need	EXTERR_CLASS,BYTE		  ;AN000;; DOS 4.00
    58                                  	I_need	CPSWFLAG,BYTE			  ;AN000;; DOS 4.00
    59                                  	I_need	EXITHOLD,DWORD			  ;AN000;; DOS 4.00
    60                                  	I_need	THISDPB,DWORD			  ;AN000;; DOS 4.00
    61                                  	I_need	SAVE_CX,WORD			  ;AN000;; DOS 4.00
    62                                  
    63                                   assume nocheck, ss:DOSGROUP
    64                                  
    65                                  Break	<DOS_Open - internal file access>
    66                                  
    67                                  ; Inputs:
    68                                  ;	[WFP_START] Points to WFP string ("d:/" must be first 3 chars, NUL
    69                                  ;		terminated)
    70                                  ;	[CURR_DIR_END] Points to end of Current dir part of string
    71                                  ;		( = -1 if current dir not involved, else
    72                                  ;		 Points to first char after last "/" of current dir part)
    73                                  ;	[THISCDS] Points to CDS being used
    74                                  ;		(Low word = -1 if NUL CDS (Net direct request))
    75                                  ;	[THISSFT] Points to SFT to fill in if file found
    76                                  ;		(sf_mode field set so that FCB may be detected)
    77                                  ;	[SATTRIB] Is attribute of search, determines what files can be found
    78                                  ;	AX is Access and Sharing mode
    79                                  ;	  High NIBBLE of AL (Sharing Mode)
    80                                  ;		sharing_compat	   file is opened in compatibility mode
    81                                  ;		sharing_deny_none  file is opened Multi reader, Multi writer
    82                                  ;		sharing_deny_read  file is opened Only reader, Multi writer
    83                                  ;		sharing_deny_write file is opened Multi reader, Only writer
    84                                  ;		sharing_deny_both  file is opened Only reader, Only writer
    85                                  ;	  Low NIBBLE of AL (Access Mode)
    86                                  ;		open_for_read	file is opened for reading
    87                                  ;		open_for_write	file is opened for writing
    88                                  ;		open_for_both	file is opened for both reading and writing.
    89                                  ;
    90                                  ;	  For FCB SFTs AL should = sharing_compat + open_for_both
    91                                  ;		(not checked)
    92                                  ; Function:
    93                                  ;	Try to open the specified file
    94                                  ; Outputs:
    95                                  ;	sf_ref_count is NOT altered
    96                                  ;	CARRY CLEAR
    97                                  ;	    THISSFT filled in.
    98                                  ;	CARRY SET
    99                                  ;	    AX is error code
   100                                  ;		error_file_not_found
   101                                  ;			Last element of path not found
   102                                  ;		error_path_not_found
   103                                  ;			Bad path (not in curr dir part if present)
   104                                  ;		error_bad_curr_dir
   105                                  ;			Bad path in current directory part of path
   106                                  ;		error_invalid_access
   107                                  ;			Bad sharing mode or bad access mode or bad combination
   108                                  ;		error_access_denied
   109                                  ;			Attempt to open read only file for writting, or
   110                                  ;			open a directory
   111                                  ;		error_sharing_violation
   112                                  ;			The sharing mode was correct but not allowed
   113                                  ;			generates an INT 24 on compatibility mode SFTs
   114                                  ; DS preserved, others destroyed
   115                                  
   116                                  	procedure   DOS_Open,NEAR
   116          ******************       warning: proc DOS_Open... [-w+user]
   117                                  	DOSAssume   CS,<DS>,"DOS_Open"
   118                                  	ASSUME	ES:NOTHING
   119                                  
   120 00000000 C606[0000]00            	MOV	byte [NoSetDir],0
   121 00000005 E86201                  	CALL	Check_Access_AX
   122 00000008 7301C3                  	retc
   123 0000000B C43E[0000]              	LES	DI,[THISSFT]
   124                                   assume es:nothing
   125 0000000F 30E4                    	XOR	AH,AH
   126                                  ; sleaze! move only access/sharing mode in.  Leave sf_isFCB unchanged
   127 00000011 26884502                	MOV	BYTE PTR [ES:DI + sf_mode],AL ; For moment do this on FCBs too
   128 00000015 06                      	PUSH	ES
   129 00000016 C436[0000]              	LES	SI,[THISCDS]
   130 0000001A 83FEFF                  	CMP	SI,-1
   131 0000001D 752C                    	JNZ	TEST_RE_NET
   132 0000001F 07                      	POP	ES
   133                                   assume es:nothing
   134                                  ;Extended open hooks
   135                                  
   136 00000020 F606[0000]01            	TEST	byte [EXTOPEN_ON],ext_open_on    ;FT. from extnded open		;AN000;
   137 00000025 741C                    	JZ	NOEXTOP 		    ;FT. no, do normal			;AN000;
   138                                  IFS_extopen:									;AN000;
   139                                  
   140                                  	public IFS_extopen_shared
   141                                  IFS_extopen_shared:
   142 00000027 A0[0000]                	MOV	AL,byte ptr [SAVE_CX]	    ;FT. al= create attribute		;AN000;
   143 0000002A 50                      	PUSH	AX			    ;FT. pass create attr to IFS	;AN000;
   144                                  multNET equ MultNET	; NASM port equate
   145 0000002B B82E11                  	MOV	AX,(multNET << 8) | 46    ;FT. issue extended open verb	;AN000;
   146 0000002E CD2F                    	INT	2FH			    ;FT.				;AN000;
   147 00000030 5B                      	POP	BX			    ;FT. trash bx			;AN000;
   148 00000031 C606[0000]00            	MOV	byte [EXTOPEN_ON],0		    ;FT.				;AN000;
   149 00000036 720A                    	jc @F
   150 00000038 1E                      	push ds
   151 00000039 56                      	push si
   152 0000003A E8(0000)                	invoke get_user_stack
   153 0000003D 894C04                  	mov [SI + user_CX], cx
   154 00000040 5E                      	pop si
   155 00000041 1F                      	pop ds
   156                                   assume ds:DOSGROUP
   157                                  		; ecm: this is a no-op
   158                                  	; jmp	update_size		    ;IFS. file may be opened		;AN000;
   159                                  @@:
   160 00000042 C3                      	return				    ;FT.				;AN000;
   161                                  NOEXTOP:
   162                                  ;Extended open hooks
   163                                  
   164                                  
   165                                  %IFN Installed
   166                                  	transfer NET_SEQ_OPEN
   167                                  %ELSE
   168 00000043 50                      	PUSH	AX
   169 00000044 B81611                  	MOV	AX,(multNET << 8) | 22
   170 00000047 CD2F                    	INT	2FH
   171 00000049 5B                      	POP	BX			; clean stack
   172 0000004A C3                      	return
   173                                  %ENDIF
   174                                  
   175                                  TEST_RE_NET:
   176 0000004B 26F744430080            	TEST	word [ES:SI + curdir_flags],curdir_isnet
   177 00000051 07                      	POP	ES
   178                                   assume es:nothing
   179 00000052 740F                    	JZ	LOCAL_OPEN
   180                                  ;	CALL	IFS_SHARE_CHECK 	;IFS. check IFS share,may create share	;AN000;
   181                                  ;	JC	nomore			;IFS. share violation			;AN000;
   182                                  ;Extended open hooks
   183                                  
   184 00000054 F606[0000]01            	TEST	byte [EXTOPEN_ON],ext_open_on    ;FT. from extnded open		;AN000;
   185 00000059 75CC                    	JNZ	IFS_extopen		    ;FT. isuue extended open		;AN000;
   186                                  ;Extended open hooks
   187                                  
   188                                  %IFN Installed
   189                                  	transfer NET_OPEN
   190                                  %ELSE
   191 0000005B 50                      	PUSH	AX
   192 0000005C B81611                  	MOV	AX,(multNET << 8) | 22
   193 0000005F CD2F                    	INT	2FH
   194 00000061 5B                      	POP	BX			; clean stack
   195                                  ;	JC	nomore			;IFS. error				;AN000;
   196                                  update_size:									;AN000;
   197                                  ;	CALL	OWN_SHARE		;IFS. IFS owns share ?			;AN000;
   198                                  ;	JZ	nomore2 		;IFS. yes				;AN000;
   199                                  ;	MOV	AX,3			;IFS. update file size for all SFT	;AN000;
   200                                  ;	LES	DI,ThisSFT		;IFS.					;AN000;
   201                                  ;	call	JShare + 14 * 4 	;IFS. call ShSu 			;AN000;
   202                                  nomore2:
   203                                  ;	CLC
   204                                  nomore:
   205 00000062 C3                      	return
   206                                  %ENDIF
   207                                  
   208                                  LOCAL_OPEN:
   209 00000063 E8(0000)                	EnterCrit   critDisk
   210                                  
   211                                  ; DOS 3.3 FastOPen 6/16/86
   212                                  
   213 00000066 800E[0000]05            	OR	byte [FastOpenFlg],FastOpen_Set+Special_Fill_Set   ;  only open can
   214 0000006B E8(0000)                	invoke	GetPath
   215                                  
   216                                  
   217                                  ; DOS 3.3 FastOPen 6/16/86
   218                                  
   219 0000006E 7320                    	JNC	Open_found
   220 00000070 7514                    	JNZ	bad_path
   221 00000072 08C9                    	OR	CL,CL
   222 00000074 7410                    	JZ	bad_path
   223                                  OpenFNF:
   224 00000076 B80200                  	MOV	AX,error_file_not_found
   225                                  OpenBadRet:
   226 00000079 368026[0000]80          	AND	BYTE PTR [ss:FastOpenFlg],Fast_yes    ;; DOS 3.3
   227 0000007F F9                      	STC
   228 00000080 E8(0000)                	LeaveCrit   critDisk
   229 00000083 E9A100                  	JMP	Clear_FastOpen
   230                                  
   231                                  bad_path:
   232 00000086 B80300                  	MOV	AX,error_path_not_found
   233 00000089 EBEE                    	JMP	OpenBadRet
   234                                  
   235                                  open_bad_access:
   236 0000008B B80500                  	MOV	AX,error_access_denied
   237 0000008E EBE9                    	JMP	OpenBadRet
   238                                  
   239                                  Open_found:
   240                                  Open_Bad_Access equ open_bad_access	; NASM port label
   241 00000090 74F9                    	JZ	Open_Bad_Access 	; test for directories
   242 00000092 08E4                    	OR	AH,AH
   243 00000094 783F                    	JS	open_ok 		; Devices don't have attributes
   244 00000096 8E06[0200]              	MOV	ES,WORD PTR [CURBUF+2]	; get buffer location
   245                                   assume es:nothing
   246 0000009A 268A470B                	MOV	AL,[ES:BX + dir_attr]
   247 0000009E A808                    	TEST	AL,attr_volume_id	; can't open volume ids
   248 000000A0 75E9                    	JNZ	open_bad_access
   249 000000A2 A801                    	TEST	AL,attr_read_only	; check write on read only
   250 000000A4 742F                    	JZ	open_ok
   251                                  ;
   252                                  ; The file is marked READ-ONLY.  We verify that the open mode allows access to
   253                                  ; the read-only file.  Unfortunately, with FCB's and net-FCB's we cannot
   254                                  ; determine at the OPEN time if such access is allowed.  Thus, we defer such
   255                                  ; processing until the actual write operation:
   256                                  ;
   257                                  ; If FCB, then we change the mode to be read_only.
   258                                  ; If net_FCB, then we change the mode to be read_only.
   259                                  ; If not open for read then error.
   260                                  ;
   261 000000A6 1E56                    	SaveReg <DS,SI>
   262 000000A8 C536[0000]              	LDS	SI,[THISSFT]
   263 000000AC 8B4C02                  	MOV	CX,[SI + sf_mode]
   264                                  sf_isFCB equ sf_isfcb	; NASM port equate
   265 000000AF F7C10080                	TEST	CX,sf_isFCB		; is it FCB?
   266 000000B3 750A                    	JNZ	ResetAccess		; yes, reset the access
   267 000000B5 88CA                    	MOV	DL,CL
   268 000000B7 80E2F0                  	AND	DL,sharing_mask
   269 000000BA 80FA70                  	CMP	DL,sharing_net_FCB	; is it net FCB?
   270 000000BD 7508                    	JNZ	NormalOpen		; no
   271                                  ResetAccess:
   272 000000BF 83E1F0                  	AND	CX,~ access_mask	; clear access
   273                                  	errnz	open_for_read
   274                                  ;	OR	CX,open_for_read	; stick in open_for_read
   275 000000C2 894C02                  	MOV	[SI + sf_mode],CX
   276 000000C5 EB0C                    	JMP	SHORT FillSFT
   277                                  ;
   278                                  ; The SFT is normal.  See if the requested access is open_for_read
   279                                  ;
   280                                  NormalOpen:
   281 000000C7 80E10F                  	AND	CL,access_mask		; remove extras
   282 000000CA 80F900                  	CMP	CL,open_for_read	; is it open for read?
   283 000000CD 7404                    	JZ	FillSFT
   284 000000CF 5E1F                    	RestoreReg  <SI,DS>
   285 000000D1 EBB8                    	JMP	short open_bad_access
   286                                  ;
   287                                  ; All done, restore registers and fill the SFT.
   288                                  ;
   289                                  FillSFT:
   290 000000D3 5E1F                    	RestoreReg  <SI,DS>
   291                                  open_ok:
   292                                  ;;; File Tagging DOS 4.00
   293                                  ;	OR	AH,AH		       ;FT. device ?				;AN000;
   294                                  ;	JS	NORM0		       ;FT. yes, don't do code page matching    ;AN000;
   295                                  ;	CMP	[CPSWFLAG],0	       ;FT. code page matching on		;AN000;
   296                                  ;	JZ	NORM0		       ;FT. no					;AN000;
   297                                  ;	CMP	[ES:BX].dir_CODEPG,0   ;FT. code page 0 			;AN000;
   298                                  ;	JZ	NORM0		       ;FT. yes do nothing			;AN000;
   299                                  ;	PUSH	AX		       ;FT.					;AN000;
   300                                  ;	invoke	Get_Global_CdPg        ;FT. get global code page		;AN000;
   301                                  ;	CMP	[ES:BX].dir_CODEPG,AX  ;FT. equal to global code page		;AN000;
   302                                  ;	JZ	NORM1		       ;FT. yes 				;AN000;
   303                                  ;	call	Code_Page_Mismatched_Error ;FT. 				;AN000;
   304                                  ;	CMP	AL,0		       ;FT. ignore ?				;AN000;
   305                                  ;	JZ	NORM1		       ;FT.					;AN000;
   306                                  ;	POP	AX		       ;FT.					;AN000;
   307                                  ;	JMP	open_bad_access        ;FT. set carry and return		;AN000;
   308                                  NORM1:										;AN000;
   309                                  ;	POP	AX		       ;FT.					;AN000;
   310                                  NORM0:
   311                                  
   312                                  ;;; File Tagging DOS 4.00
   313 000000D5 E8(0000)                	invoke	DOOPEN			; Fill in SFT
   314 000000D8 368026[0000]80          	AND	BYTE PTR [ss:FastOpenFlg],Fast_yes    ;; DOS 3.3
   315 000000DE E86500                  	CALL	DO_SHARE_CHECK		;
   316                                  Share_Ok equ SHARE_OK	; NASM port label
   317 000000E1 7306                    	JNC	Share_Ok
   318 000000E3 E8(0000)                	LeaveCrit   critDisk
   319                                  Clear_FastOPen equ Clear_FastOpen	; NASM port label
   320 000000E6 EB3F                    	JMP	Clear_FastOPen
   321 000000E8 90                      	nop	; identicalise
   322                                  
   323                                  SHARE_OK:
   324 000000E9 B80300                  	MOV	AX,3
   325                                  ThisSFT equ THISSFT	; NASM port label
   326 000000EC C43E[0000]              	LES	DI,[ThisSFT]
   327                                  %if installed
   328 000000F0 FF1E[3800]              	call	far [JShare + 14 * 4]
   329                                  %else
   330                                  	Call	ShSU
   331                                  %endif
   332                                  ;; DOS 4.00 10/27/86
   333 000000F4 C43E[0000]              	LES	DI,[ThisSFT]			   ; if this is a newly 	;AN000;
   334 000000F8 26837D0B00              	CMP	word [ES:DI + sf_firclus],0		   ; created file then		;AN000;
   335 000000FD 740E                    	JZ	no_fastseek			   ; do nothing 		;AN000;
   336 000000FF 268B4D0B                	MOV	CX,[ES:DI + sf_firclus]		   ; first cluster #		;AN000;
   337 00000103 26C47D07                	LES	DI,[ES:DI + sf_devptr]		   ; pointer to DPB		;AN000;
   338 00000107 268A15                  	MOV	DL,[ES:DI + dpb_drive]		   ; drive #			;AN000;
   339 0000010A E8(0000)                	invoke	FastSeek_Open			   ; call fastseek		;AN000;
   340                                  no_fastseek:
   341                                  
   342                                  ;; DOS 4.00 10/27/86
   343                                  
   344 0000010D E8(0000)                	LeaveCrit   critDisk
   345                                  
   346                                  ;
   347                                  ; Finish SFT initialization for new reference.	Set the correct mode.
   348                                  ;
   349                                  ;   Inputs:
   350                                  ;	ThisSFT points to SFT
   351                                  ;
   352                                  ;   Outputs:
   353                                  ;	Carry clear
   354                                  ;   Registers modified: AX.
   355                                  
   356                                  	entry	SET_SFT_MODE
   357                                  	DOSAssume   CS,<DS>,"Set_SFT_Mode"
   358                                  	ASSUME	ES:NOTHING
   359                                  
   360 00000110 C43E[0000]              	LES	DI,[ThisSFT]
   361 00000114 E8(0000)                	invoke	DEV_OPEN_SFT
   362 00000117 26F745020080            	TEST	word [ES:DI + sf_mode],sf_isfcb; Clears carry
   363 0000011D 7501C3                  	retz				; sf_mode correct
   364 00000120 A1[0000]                	MOV	AX,[CurrentPDB]
   365 00000123 26894531                	MOV	[ES:DI + sf_PID],AX	; For FCB sf_PID=PID
   366                                  
   367                                  Clear_FastOpen:
   368 00000127 C3                      	return			       ;;;;; DOS 3.3
   369                                  
   370                                  EndProc DOS_Open
   370          ******************       warning: ***** Possible stack size error in DOS_Open ***** [-w+user]
   371                                  
   372                                  ; Called on sharing violations. ES:DI points to SFT. AX has error code
   373                                  ; If SFT is FCB or compatibility mode gens INT 24 error.
   374                                  ; Returns carry set AX=error_sharing_violation if user says ignore (can't
   375                                  ; really ignore).  Carry clear
   376                                  ; if user wants a retry. ES, DI, DS preserved
   377                                  
   378                                  procedure SHARE_ERROR,NEAR
   378          ******************       warning: proc SHARE_ERROR... [-w+user]
   379                                  	DOSAssume   CS,<DS>,"Share_Error"
   380                                  	ASSUME	ES:NOTHING
   381 00000128 26F745020080            	TEST	word [ES:DI + sf_mode],sf_isfcb
   382 0000012E 750C                    	JNZ	HARD_ERR
   383 00000130 268A4D02                	MOV	CL,BYTE PTR [ES:DI + sf_mode]
   384 00000134 80E1F0                  	AND	CL,sharing_mask
   385 00000137 80F900                  	CMP	CL,sharing_compat
   386 0000013A 7505                    	JNE	NO_HARD_ERR
   387                                  HARD_ERR:
   388 0000013C E8(0000)                	invoke	SHARE_VIOLATION
   389 0000013F 73E6                    	retnc				; User wants retry
   390                                  NO_HARD_ERR:
   391 00000141 B82000                  	MOV	AX,error_sharing_violation
   392 00000144 F9                      	STC
   393 00000145 C3                      	return
   394                                  
   395                                  EndProc SHARE_ERROR
   396                                  
   397                                  
   398                                  ; Input: THISDPB, WFP_Start, THISSFT set
   399                                  ; Functions: check file sharing mode is valid
   400                                  ; Output: carry set, error
   401                                  ;	  carry clear, share ok
   402                                  
   403                                  procedure DO_SHARE_CHECK,NEAR
   403          ******************       warning: proc DO_SHARE_CHECK... [-w+user]
   404                                  	DOSAssume   CS,<DS>,"DO_SHARE__CHECK"
   405                                  	ASSUME	ES:NOTHING
   406 00000146 E8(0000)                	EnterCrit   critDisk		; enter critical section
   407                                  
   408                                  OPN_RETRY:
   409 00000149 8B0E[0000]              	MOV	CX,[RetryCount]		; Get # tries to do
   410                                  OpenShareRetry:
   411 0000014D 51                      	SaveReg <CX>			; Save number left to do
   412 0000014E E8(0000)                	invoke	SHARE_CHECK		; Final Check
   413 00000151 59                      	RestoreReg  <CX>		; CX = # left
   414 00000152 730E                    	JNC	Share_Ok2		; No problem with access
   415 00000154 E8(0000)                	Invoke	Idle
   416 00000157 E2F4                    	LOOP	OpenShareRetry		; One more retry used up
   417                                  OpenShareFail:
   418                                  ThisSft equ THISSFT	; NASM port label
   419 00000159 C43E[0000]              	LES	DI,[ThisSft]
   420 0000015D E8C8FF                  	invoke	SHARE_ERROR
   421 00000160 73E7                    	JNC	OPN_RETRY		; User wants more retry
   422                                  Share_Ok2:
   423 00000162 E8(0000)                	LeaveCrit   critDisk		; leave critical section
   424 00000165 C3                      	return
   425                                  
   426                                  EndProc DO_SHARE_CHECK
   427                                  
   428                                  
   429                                  ; Input: ES:DI -> SFT
   430                                  ; Functions: check if IFS owns SHARE
   431                                  ; Output: Zero set, use IFS SHARE
   432                                  ;	  otherwise, use DOS SHARE
   433                                  
   434                                  procedure OWN_SHARE,NEAR		;AN000;
   434          ******************       warning: proc OWN_SHARE... [-w+user]
   435                                  	DOSAssume   CS,<DS>,"OWN_SHARE" ;AN000;
   436                                  	ASSUME	ES:NOTHING		;AN000;
   437                                  
   438                                  ;	PUSH	DS			;IFS. save reg				;AN000;
   439                                  ;	PUSH	SI			;IFS. save reg				;AN000;
   440                                  ;	LDS	SI,[ES:DI.sf_IFS_HDR]	;IFS. ds:si-> IFS header		;AN000;
   441                                  ;	TEST	[SI.IFS_ATTRIBUTE],IFSUSESHARE	;IFS. save reg			;AN000;
   442                                  ;	POP	SI			;IFS. retore reg			;AN000;
   443                                  ;	POP	DS			;IFS. restore reg			;AN000;
   444 00000166 C3                      	return				;IFS. return				;AN000;
   445                                  
   446                                  EndProc OWN_SHARE			;AN000;
   447                                  
   448                                  
   449                                  ; Input: THISCDS -> CDS
   450                                  ; Functions: check if IFS owns SHARE
   451                                  ; Output: Zero set, use IFS SHARE
   452                                  ;	  otherwise, use DOS SHARE
   453                                  
   454                                  procedure OWN_SHARE2,NEAR		  ;AN000;
   454          ******************       warning: proc OWN_SHARE2... [-w+user]
   455                                  	DOSAssume   CS,<DS>,"OWN_SHARE2"  ;AN000;
   456                                  	ASSUME	ES:NOTHING		  ;AN000;
   457                                  
   458                                  ;	CMP	WORD PTR [THISCDS],-1	;IFS. UNC ?				;AN000;
   459                                  ;	JZ	ifs_hasit		;IFS. yes				;AN000;
   460                                  ;	PUSH	DS			;IFS. save reg				;AN000;
   461                                  ;	PUSH	SI			;IFS. save reg				;AN000;
   462                                  ;	LDS	SI,[THISCDS]		;IFS. DS:SI -> ThisCDS			;AN000;
   463                                  ;	LDS	SI,[SI.curdir_IFS_HDR]	;IFS. ds:si-> IFS header		;AN000;
   464                                  ;	TEST	[SI.IFS_ATTRIBUTE],IFSUSESHARE	;IFS.				;AN000;
   465                                  ;	POP	SI			;IFS. retore reg			;AN000;
   466                                  ;	POP	DS			;IFS. restore reg			;AN000;
   467                                  ifs_hasit:				;AN000;
   468 00000167 C3                      	return				;IFS. return				;AN000;
   469                                  
   470                                  EndProc OWN_SHARE2			;AN000;
   471                                  
   472                                  
   473                                  ; Input: ES:DI -> SFT
   474                                  ; Functions: set THISDPB
   475                                  ; Output: none
   476                                  
   477                                  procedure SET_THISDPB,NEAR		       ;AN000;
   477          ******************       warning: proc SET_THISDPB... [-w+user]
   478                                  	DOSAssume   CS,<DS>,"SET_THISDPB"      ;AN000;
   479                                  	ASSUME	ES:NOTHING		       ;AN000;
   480                                  
   481                                  ;	PUSH	DS			;IFS. save reg				;AN000;
   482                                  ;	PUSH	SI			;IFS. save reg				;AN000;
   483                                  ;	LDS	SI,[THISCDS]		;IFS. ds:si-> CDS			;AN000;
   484                                  ;	LDS	SI,[SI.CURDIR_DEVPTR]	;IFS. ds:si-> DPB			;AN000;
   485                                  ;	MOV	WORD PTR [THISDPB],SI	;IFS. set THISDPB			;AN000;
   486                                  ;	MOV	WORD PTR [THISDPB+2],DS ;IFS.					;AN000;
   487                                  ;	POP	SI			;IFS. retore reg			;AN000;
   488                                  ;	POP	DS			;IFS. restore reg			;AN000;
   489 00000168 C3                      	return				;IFS. return				;AN000;
   490                                  
   491                                  EndProc SET_THISDPB			;AN000;
   492                                  
   493                                  
   494                                  ; Input: ES:DI -> SFT
   495                                  ; Functions: check IFS share
   496                                  ; Output: none
   497                                  
   498                                  procedure IFS_SHARE_CHECK,NEAR			   ;AN000;
   498          ******************       warning: proc IFS_SHARE_CHECK... [-w+user]
   499                                  	DOSAssume   CS,<DS>,"IFS_SHARE_CHECK"      ;AN000;
   500                                  	ASSUME	ES:NOTHING			   ;AN000;
   501                                  
   502                                  
   503                                  ;	CALL	OWN_SHARE		;IFS. IFS owns share			;AN000;
   504                                  ;	JZ	IFSSHARE		;IFS. yes				;AN000;
   505                                  ;	PUSH	AX			;IFS. save mode 			;AN000;
   506                                  ;	CALL	SET_THISDPB		;IFS. set THISDPB for SHARE_VIOLATION	;AN000;
   507                                  ;	CALL	DO_SHARE_CHECK		;IFS. check share			;AN000;
   508                                  ;	POP	AX			;IFS. restore mode and share ok 	;AN000;
   509                                  IFSSHARE:				;AN000;
   510 00000169 C3                      	return				;IFS. return				;AN000;
   511                                  
   512                                  EndProc IFS_SHARE_CHECK 		;AN000;
   513                                  
   514                                  ; Inputs:
   515                                  ;	AX is mode
   516                                  ;	  High NIBBLE of AL (Sharing Mode)
   517                                  ;		sharing_compat	   file is opened in compatibility mode
   518                                  ;		sharing_deny_none  file is opened Multi reader, Multi writer
   519                                  ;		sharing_deny_read  file is opened Only reader, Multi writer
   520                                  ;		sharing_deny_write file is opened Multi reader, Only writer
   521                                  ;		sharing_deny_both  file is opened Only reader, Only writer
   522                                  ;	  Low NIBBLE of AL (Access Mode)
   523                                  ;		open_for_read	file is opened for reading
   524                                  ;		open_for_write	file is opened for writing
   525                                  ;		open_for_both	file is opened for both reading and writing.
   526                                  ; Function:
   527                                  ;	Check this access mode for correctness
   528                                  ; Outputs:
   529                                  ;	[open_access] = AL input
   530                                  ;	Carry Clear
   531                                  ;		Mode is correct
   532                                  ;		AX unchanged
   533                                  ;	Carry Set
   534                                  ;		Mode is bad
   535                                  ;		AX = error_invalid_access
   536                                  ; No other registers effected
   537                                  
   538                                  	procedure Check_Access_AX
   538          ******************       warning: proc Check_Access_AX... [-w+user]
   539                                  	DOSAssume   CS,<DS>,"Check_Access"
   540                                  	ASSUME	ES:NOTHING
   541                                  
   542 0000016A A2[0000]                	MOV	[Open_Access],AL
   543 0000016D 53                      	PUSH	BX
   544                                  ;
   545                                  ; If sharing, then test for special sharing mode for FCBs
   546                                  ;
   547 0000016E 88C3                    	MOV	BL,AL
   548 00000170 80E3F0                  	AND	BL,sharing_mask
   549 00000173 803E[0000]FF            	CMP	byte [fSharing],-1
   550 00000178 7505                    	JNZ	CheckShareMode		; not through server call, must be ok
   551                                  sharing_NET_FCB equ sharing_net_FCB	; NASM port equate
   552 0000017A 80FB70                  	CMP	BL,sharing_NET_FCB
   553 0000017D 7405                    	JZ	CheckAccessMode 	; yes, we have an FCB
   554                                  CheckShareMode:
   555 0000017F 80FB40                  	CMP	BL,40h			; is this a good sharing mode?
   556                                  Make_Bad_Access equ make_bad_access	; NASM port label
   557 00000182 770D                    	JA	Make_Bad_Access
   558                                  CheckAccessMode:
   559 00000184 88C3                    	MOV	BL,AL
   560 00000186 80E30F                  	AND	BL,access_mask
   561 00000189 80FB02                  	CMP	BL,2
   562 0000018C 7703                    	JA	Make_Bad_Access
   563 0000018E 5B                      	POP	BX
   564 0000018F F8                      	CLC
   565 00000190 C3                      	return
   566                                  
   567                                  make_bad_access:
   568 00000191 B80C00                  	MOV	AX,error_invalid_access
   569 00000194 5B                      	POP	BX
   570 00000195 F9                      	STC
   571 00000196 C3                      	return
   572                                  
   573                                  EndProc Check_Access_AX
   574                                  
   575                                  ; Input: none
   576                                  ; Function: Issue Code Page Mismatched INT 24 Critical Error
   577                                  ; OutPut: AL =0    ignore
   578                                  ;	     =3    fail
   579                                  
   580                                  %if 0
   581                                  procedure Code_Page_Mismatched_Error,NEAR		 ;AN000;
   582                                  	DOSAssume   CS,<DS>,"Code_Page_Mismatched_Error" ;AN000;
   583                                  	ASSUME	ES:NOTHING				 ;AN000;
   584                                  
   585                                  ;	PUSH	DS		       ;FT.					;AN000;
   586                                  ;	Context DS		       ;FT. ds=cs				;AN000;
   587                                  ;	MOV	AH,0A9H 	       ;FT. fail,ignore,device,write		;AN000;
   588                                  ;	MOV	DI,error_I24_gen_failure		 ;FT. set error 	;AN000;
   589                                  ;	MOV	[EXTERR],error_Code_Page_Mismatched	 ;FT.			;AN000;
   590                                  ;	MOV	[EXTERR_CLASS],errCLASS_NotFnd		 ;FT.			;AN000;
   591                                  ;	MOV	[EXTERR_ACTION],errACT_Abort		 ;FT.			;AN000;
   592                                  ;	MOV	[EXTERR_LOCUS],errLOC_Unk		 ;FT.			;AN000;
   593                                  ;	MOV	word ptr [EXITHOLD + 2],ES		 ;FT. save es:bp	;AN000;
   594                                  ;	MOV	word ptr [EXITHOLD],BP			 ;FT.			;AN000;
   595                                  ;	invoke	NET_I24_ENTRY				 ;FT. issue int 24H	;AN000;
   596                                  ;	POP	DS					 ;FT.			;AN000;
   597                                  ;	return						 ;FT.			;AN000;
   598                                  
   599                                  EndProc Code_Page_Mismatched_Error			 ;AN000;
   600                                  %endif
   601                                  
   602                                      END
