     1                                  ;       SCCSID = @(#)mknode.asm 1.5 85/08/29
     2                                  ;TITLE   MKNODE - Node maker
     3                                  ;NAME    MKNODE
     4                                  ; Low level routines for making a new local file system node
     5                                  ;   and filling in an SFT from a directory entry
     6                                  ;
     7                                  ;   BUILDDIR
     8                                  ;   SETDOTENT
     9                                  ;   MakeNode
    10                                  ;   NEWENTRY
    11                                  ;   FREEENT
    12                                  ;   NEWDIR
    13                                  ;   DOOPEN
    14                                  ;   RENAME_MAKE
    15                                  ;   CHECK_VIRT_OPEN
    16                                  ;
    17                                  ;   Revision history:
    18                                  ;
    19                                  ;    AN000  version 4.0  Jan. 1988
    20                                  ;    A004   PTM 3680  --- Make SFT NAME field offset same as 3.30
    21                                  
    22                                  ;
    23                                  ; get the appropriate segment definitions
    24                                  ;
    25                                  [list -]
    25          ******************       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
    28                                  %include "fastopen.mac"
     1                              <1> ;
     2                              <1> ; EXPORT DATE: 9/11
     3                              <1> ;Equates for FASTOPEN.
     4                              <1> 
     5                              <1> ;FASTOPEN NAME CACHING Subfunctions
     6                              <1> FONC_Look_up	equ	1
     7                              <1> FONC_insert	equ	2
     8                              <1> FONC_delete	equ	3
     9                              <1> FONC_update	equ	4
    10                              <1> FONC_purge	equ	5		;reserved for the future use.
    11                              <1> 
    12                              <1> ;FASTOPEN EXTENT  CACHING Subfunctions
    13                              <1> FSK_Open       equ     11					       ;AN000;
    14                              <1> FSK_Close      equ     12					       ;AN000;
    15                              <1> FSK_Delete     equ     13					       ;AN000;
    16                              <1> FSK_Lookup     equ     14					       ;AN000;
    17                              <1> FSK_Insert     equ     15					       ;AN000;
    18                              <1> FSK_Trunc      equ     16					       ;AN000;
    19                              <1> 
    20                              <1> HeaderSize     equ    8        ; size of file header (8 bytes)	       ;AN000;
    21                              <1> ExtendSize     equ    8        ; size of extend (8 bytes)	       ;AN000;
    22                              <1> Num_Of_Pages   equ    1        ; number of pages		       ;AN000;
    23                              <1> Num_Of_Segs    equ    2        ; number of frame segments	       ;AN000;
    24                              <1> Stayresident  equ    04ch     ; terminate and stay resident function code
    25                              <1> 
    26                              <1> 
    27                              <1> ;Equates used in DOS.
    28                              <1> FastOpen_Set	       equ     00000001B
    29                              <1> FastOpen_Reset	       equ     11111110B
    30                              <1> Lookup_Success	       equ     00000010B
    31                              <1> Lookup_Reset	       equ     11111101B
    32                              <1> Special_Fill_Set       equ     00000100B
    33                              <1> Special_Fill_Reset     equ     11111011B
    34                              <1> No_Lookup	       equ     00001000B
    35                              <1> Set_For_Search	       equ     00010000B	     ;DCR 167
    36                              <1> 
    37                              <1> 
    38                              <1> ;============= FastOpen Data Structures =====================
    39                              <1> 
    40                              <1> Fastopen_Entry	STRUC			;Fastopen Entry pointer in DOS
    41 00000000 ????                <1> Fastopen_Entry_size	dw	?	;size of the following
    42 00000002 ????????            <1> Fastopen_Name_Caching	dd	?
    43                              <1> ;Fastopen_FatChain_Caching dd	  ?	;reserved for future use
    44                              <1> Fastopen_Entry	ENDS
    45                              <1> ;
    46                              <1> 
    47                              <1> 
    48                              <1> CMPCT_DIR_INFO	STRUC			;compact version of Dir Info.
    49 00000000 <res Bh>            <1> CDI_file_name	db	11 dup (?)
    50 0000000B ??                  <1> CDI_file_attr	db	?
    51 0000000C ????                <1> CDI_codepage	dw	?
    52 0000000E ????                <1> CDI_extcluster	dw	?
    53 00000010 ??                  <1> CDI_attr2	db	?
    54 00000011 ????                <1> CDI_time	dw	?
    55 00000013 ????                <1> CDI_date	dw	?
    56 00000015 ????                <1> CDI_cluster	dw	?
    57 00000017 ????????            <1> CDI_filesize	dd	?
    58                              <1> CMPCT_DIR_INFO	ENDS
    59                              <1> ;
    60                              <1> 
    61                              <1> ORIG_DIR_INFO	STRUC
    62 00000000 <res 11h>           <1> ODI_head	db	17 dup (?)
    63 00000011 ??????????          <1> ODI_skip	db	5  dup (?)	;reserved for DOS. FASTOPEN does not
    64 00000016 <res Ah>            <1> ODI_tail	db	10 dup (?)	;  use ODI_skip part.
    65                              <1> ORIG_DIR_INFO	ENDS
    66                              <1> ;
    67                              <1> 
    68                              <1> ODI_head_leng	equ	17
    69                              <1> ODI_skip_leng	equ	5
    70                              <1> ODI_tail_leng	equ	10
    71                              <1> ;
    72                              <1> 
    73                              <1> FASTOPEN_EXTENDED_INFO	STRUC
    74 00000000 ??                  <1> FEI_dirpos	db	?
    75 00000001 ????????            <1> FEI_dirsec	dd	?
    76 00000005 ????                <1> FEI_clusnum	dw	?
    77 00000007 ????                <1> FEI_lastent	dw	?		; for search first
    78 00000009 ????                <1> FEI_dirstart	dw	?		; for search first
    79                              <1> FASTOPEN_EXTENDED_INFO	ENDS
    80                              <1> ;
    81                              <1> 
    82                              <1> NAME_RECORD	STRUC
    83 00000000 ????                <1> nLRU_ptr	dw	?
    84 00000002 ????                <1> nMRU_ptr	dw	?		;reverse of nLRU_ptr
    85 00000004 ????                <1> nChild_ptr	dw	?
    86 00000006 ????                <1> nSibling_ptr	dw	?
    87 00000008 ????                <1> nBackward_ptr	dw	?		;points to preceding node
    88                              <1> Cmpct_Dir_Info_struc_size equ CMPCT_DIR_INFO_struc_size	; NASM port equate
    89 0000000A <res 1Bh>           <1> nCmpct_Dir_Info db	Cmpct_Dir_Info_struc_size dup (?)
    90                              <1> Fastopen_Extended_Info_struc_size equ FASTOPEN_EXTENDED_INFO_struc_size	; NASM port equate
    91 00000025 <res Bh>            <1> nExtended_Info	db	Fastopen_Extended_Info_struc_size dup (?)
    92                              <1> NAME_RECORD	ENDS
    93                              <1> ;
    94                              <1> 
    95                              <1> DRIVE_CACHE_HEADER	STRUC		;drive cache header
    96 00000000 ????                <1> DCH_LRU_ROOT	 dw	 ?		;Header of the LRU chain of this drive
    97 00000002 ????                <1> DCH_MRU_ROOT	 dw	 ?		;offset to the last entry of LRU chain
    98 00000004 ????                <1> DCH_Child_ptr	 dw	 ?		;the first child in Name cache seg.
    99 00000006 ????                <1> DCH_Sibling_ptr  dw	 ?		;points to the next drive cache header
   100 00000008 ??                  <1> DCH_Drive_letter db	?             ;drive letter
   101 00000009 ????                <1> DCH_Num_Entries  dw	 ?		;Number of entries in the Name cache.
   102 0000000B ????                <1> DCH_Name_Buff	 dw	 ?		;pointer to name cahe buffer
   103                              <1> DRIVE_CACHE_HEADER	ENDS
   104                              <1> ;
   105                              <1> 
   106                              <1> 
   107                              <1> 
   108                              <1> 
   109                              <1> 
   110                              <1> ;======== FAST SEEK FUNCTION  DATA  STRUCTURES =======================
   111                              <1> 
   112                              <1> DRIVE_HEADER	STRUC		   ; Drive header structure		;AN000;
   113 00000000 ????                <1> Drive_Number	     dw     ?	   ; drive number			;AN000;
   114 00000002 ????                <1> Extent_Count	     dw     ?	   ; reserved for debugging
   115 00000004 ????                <1> MRU_Hdr_Ptr	     dw     ?	   ; pointer to OPEN Queue
   116 00000006 ????                <1> Free_ptr	     dw     ?	   ; pointer to FREE buffer		;AN000;
   117 00000008 ????                <1> Close_Ptr	     dw     ?	   ; pointer to CLOSE Queue	     ;AN000;
   118 0000000A ????                <1> Buff_Size	     dw     ?	   ; cache buffer size including header ;AN000;
   119 0000000C ????                <1> Free_Size	     dw     ?	   ; size of Free area in bytes
   120 0000000E ????                <1> Next_Drv_Hdr_Ptr     dw     ?	   ; pointer to next drive header
   121                              <1> DRIVE_HEADER   ENDS
   122                              <1> 
   123                              <1> 
   124                              <1> 
   125                              <1> FILE_HEADER	STRUC		   ; File header structure		;AN000;
   126 00000000 ????                <1> FH_Phys_Clus_Num     dw     ?	   ; starting physcial clustnum of file ;AN000;
   127 00000002 ????                <1> FH_Refer_Count	     dw     ?	   ; reference count			;AN000;
   128 00000004 ????                <1> FH_Next_Extn_Ptr     dw     ?	   ; pointer to first extent of the file;AN000;
   129 00000006 ????                <1> FH_Next_Hdr_Ptr      dw     ?	   ; pointer to next file header	;AN000;
   130 00000008 ????                <1> FH_MRU_Extn_Ptr      dw     ?	   ; pointer to  MRU extent
   131 0000000A ????                <1> 		     dw     ?
   132 0000000C ????                <1> 		     dw     ?
   133 0000000E ????                <1> 		     dw     ?
   134                              <1> FILE_HEADER	ENDS							;AN000;
   135                              <1> 
   136                              <1> 
   137                              <1> 
   138                              <1> EXTENT_HEADER	STRUC		   ; extend header structure		;AN000;
   139 00000000 ????                <1> EH_Logic_Clus_Num    dw     ?	   ; starting logical clus num of extent;AN000;
   140 00000002 ????                <1> EH_Phys_Clus_Num     dw     ?	   ; starting physical clus numof  extnt;AN000;
   141 00000004 ????                <1> EH_Count	     dw     ?	   ; range of logical clusnum in the extnt
   142 00000006 ????                <1> EH_Next_Extn_Ptr     dw     ?	   ; pointer to next extent		;AN000;
   143 00000008 ????                <1> EH_Prev_Extn_Ptr     dw     ?	   ; pointer to previous extent  ;AN000;
   144 0000000A ????                <1> EH_Next_LRU_Ptr      dw     ?	   ; pointer to next LRU extent
   145 0000000C ????                <1> EH_Prev_LRU_Ptr      dw     ?	   ; pointer tp previous LRU extent
   146 0000000E ????                <1> 		     dw     ?
   147                              <1> EXTENT_HEADER	ENDS
   148                              <1> 
   149                              <1> 
   150                              <1> 
    29                                  
    30                                  [list +]
    31                                  section DOSCODECODE
    32                                  [list -]
    32          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    32          ******************       warning: out: BPB.INC... [-w+user]
    32          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    32          ******************       warning: out: DEVSYM.INC... [-w+user]
    39                                  
    40                                          i_need  EntFree,WORD
    41                                          i_need  DirStart,WORD
    42                                          i_need  LastEnt,WORD
    43                                          i_need  ClusNum,WORD
    44                                          i_need  CurBuf,DWORD
    45                                          i_need  Attrib,BYTE
    46                                          i_need  VolID,BYTE
    47                                          i_need  Name1,BYTE
    48                                          i_need  ThisDPB,DWORD
    49                                          i_need  EntLast,WORD
    50                                          i_need  Creating,BYTE
    51                                          i_need  SecClusPos,BYTE
    52                                          i_need  ClusFac,BYTE
    53                                  	i_need	Cluster_Factor_EDR,WORD
    54                                          i_need  NxtClusNum,WORD
    55                                          i_need  DirSec,WORD
    56                                          i_need  NoSetDir,BYTE
    57                                          i_need  THISSFT,DWORD
    58                                          i_need  SATTRIB,BYTE
    59                                          i_need  ALLOWED,BYTE
    60                                          i_need  FAILERR,BYTE
    61                                          i_need  VIRTUAL_OPEN
    62                                          I_need  FastOpen_Ext_info,BYTE        ; DOS 3.3
    63                                          I_need  FastOpenFlg,BYTE              ; DOS 3.3
    64                                          I_need  CPSWFLAG,BYTE                 ;FT. DOS 3.4                      ;AN000;
    65                                          I_need  EXTOPEN_ON,BYTE               ;FT. DOS 3.4                      ;AN000;
    66                                          I_need  EXTOPEN_FLAG,WORD             ;FT. DOS 3.4                      ;AN000;
    67                                          I_need  EXTOPEN_IO_MODE,WORD          ;FT. DOS 3.4                      ;AN000;
    68                                          I_need  HIGH_SECTOR,WORD              ;>32mb                            ;AN000;
    69                                  %ifndef BUF2
    70                                          I_need  ACT_PAGE,WORD                 ;>32mb                            ;AN000;
    71                                  %endif
    72                                  
    73                                   assume nocheck, ss:DOSGROUP
    74                                  
    75                                  Break   <BUILDDIR,NEWDIR -- ALLOCATE DIRECTORIES>
    76                                  
    77                                  ; Inputs:
    78                                  ;       ES:BP Points to DPB
    79                                  ;       [THISSFT] Set if using NEWDIR entry point
    80                                  ;               (used by ALLOCATE)
    81                                  ;       [LASTENT] current last valid entry number in directory if no free
    82                                  ;               entries
    83                                  ;       [DIRSTART] Points to first cluster of dir (0 means root)
    84                                  ; Function:
    85                                  ;       Grow directory if no free entries and not root
    86                                  ; Outputs:
    87                                  ;       CARRY SET IF FAILURE
    88                                  ;       ELSE
    89                                  ;          AX entry number of new entry
    90                                  ;          If a new dir [DIRSTART],[CLUSFAC],[CLUSNUM],[DIRSEC] set
    91                                  ;               AX = first entry of new dir
    92                                  ;       GETENT should be called to set [LASTENT]
    93                                  
    94                                          procedure   BUILDDIR,NEAR
    94          ******************       warning: proc BUILDDIR... [-w+user]
    95                                          DOSAssume   CS,<DS>,"BuildDir"
    96                                          ASSUME  ES:NOTHING
    97                                  
    98                                  ENTFREE equ EntFree	; NASM port label
    99 00000000 A1[0000]                        MOV     AX,[ENTFREE]
   100 00000003 83F8FF                          CMP     AX,-1
   101 00000006 7402                            JZ      CHECK_IF_ROOT
   102 00000008 F8                              CLC
   103 00000009 C3                              return
   104                                  
   105                                  CHECK_IF_ROOT:
   106                                  DIRSTART equ DirStart	; NASM port label
   107 0000000A 833E[0000]00                    CMP     word [DIRSTART],0
   108 0000000F 7502                            JNZ     NEWDIR
   109 00000011 F9                              STC
   110 00000012 C3                              return                  ; Can't grow root
   111                                  
   112                                          entry   NEWDIR
   113 00000013 8B1E[0000]                      MOV     BX,[DIRSTART]
   114 00000017 09DB                            OR      BX,BX
   115 00000019 7405                            JZ      NULLDIR
   116 0000001B E8(0000)                        invoke  GETEOF
   117 0000001E 72F2                            retc                    ; Screw up
   118                                  NULLDIR:
   119 00000020 B90100                          MOV     CX,1
   120 00000023 E8(0000)                        invoke  ALLOCATE
   121 00000026 72EA                            retc
   122 00000028 8B16[0000]                      MOV     DX,[DIRSTART]
   123 0000002C 09D2                            OR      DX,DX
   124 0000002E 750D                            JNZ     ADDINGDIR
   125 00000030 E8(0000)                        invoke  SETDIRSRCH
   126 00000033 72DD                            retc
   127                                  LASTENT equ LastEnt	; NASM port label
   128 00000035 C706[0000]FFFF                  MOV     word [LASTENT],-1
   129 0000003B EB2B                            JMP     SHORT GOTDIRREC
   130                                  ADDINGDIR:
   131 0000003D 53                              PUSH    BX
   132 0000003E 8B1E[0000]                      MOV     BX,[ClusNum]
   133 00000042 E8(0000)                        Invoke  IsEof
   134 00000045 5B                              POP     BX
   135 00000046 7219                            JB      NOTFIRSTGROW
   136                                  ;;;; 10/17/86 update CLUSNUM in the fastopen cache
   137                                  CLUSNUM equ ClusNum	; NASM port label
   138 00000048 891E[0000]                      MOV     [CLUSNUM],BX
   139 0000004C 51                              PUSH    CX
   140 0000004D 50                              PUSH    AX
   141 0000004E 55                              PUSH    BP
   142 0000004F B401                            MOV     AH,1                       ; CLUSNUM update
   143 00000051 268A5600                        MOV     DL,[ES:BP + dpb_drive]       ; drive #
   144 00000055 8B0E[0000]                      MOV     CX,[DIRSTART]              ; first cluster #
   145 00000059 89DD                            MOV     BP,BX                      ; CLUSNUM
   146 0000005B E8(0000)                        invoke  FastOpen_Update
   147 0000005E 5D                              POP     BP
   148 0000005F 58                              POP     AX
   149 00000060 59                              POP     CX
   150                                  
   151                                  ;;;; 10/17/86 update CLUSNUM in the fastopen cache
   152                                  NOTFIRSTGROW:
   153 00000061 89DA                            MOV     DX,BX
   154 00000063 30DB                            XOR     BL,BL
   155 00000065 E8(0000)                        invoke  FIGREC
   156                                  GOTDIRREC:
   157 00000068 268A4E04                        MOV     CL,[ES:BP + dpb_cluster_mask]
   158 0000006C 30ED                            XOR     CH,CH
   159 0000006E 41                              inc cx
   160                                  ZERODIR:
   161 0000006F 51                              PUSH    CX
   162                                  allowed_FAIL equ Allowed_FAIL	; NASM port equate
   163                                  allowed_RETRY equ Allowed_RETRY	; NASM port equate
   164 00000070 C606[0000]18                    MOV     byte [ALLOWED],allowed_FAIL + allowed_RETRY
   165 00000075 B0FF                            MOV     AL,0FFH
   166 00000077 E8(0000)                        invoke  GETBUFFR
   167 0000007A 7302                            JNC     GET_SSIZE
   168 0000007C 59                              POP     CX
   169 0000007D C3                              return
   170                                  
   171                                  GET_SSIZE:
   172 0000007E 268B4E02                        MOV     CX,[ES:BP + dpb_sector_size]
   173 00000082 06                              PUSH    ES
   174                                  CURBUF equ CurBuf	; NASM port label
   175 00000083 C43E[0000]                      LES     DI,[CURBUF]
   176 00000087 26804D0504                      OR      byte [ES:DI + buf_flags],buf_isDIR
   177 0000008C 57                              PUSH    DI
   178 0000008D 83C710                          ADD     DI,BUFINSIZ
   179 00000090 31C0                            XOR     AX,AX
   180 00000092 D1E9                            SHR     CX,1
   181 00000094 F3AB                            REP     STOSW
   182 00000096 7301                            JNC     EVENZ
   183 00000098 AA                              STOSB
   184                                  EVENZ:
   185 00000099 5F                              POP     DI
   186                                  
   187 0000009A 26F6450540                      TEST    byte [ES:DI + buf_flags],buf_dirty  ;LB. if already dirty              ;AN000;
   188 0000009F 7508                            JNZ     yesdirty                  ;LB.    don't increment dirty count   ;AN000;
   189 000000A1 E8(0000)                        invoke  INC_DIRTY_COUNT           ;LB.                                  ;AN000;
   190 000000A4 26804D0540                      OR      byte [ES:DI + buf_flags],buf_dirty
   191                                  yesdirty:
   192 000000A9 07                              POP     ES
   193                                   assume es:DPB
   194 000000AA 59                              POP     CX
   195 000000AB 42                              INC     DX
   196 000000AC 7504                    	jnz @F
   197 000000AE FF06[0000]              	inc word ptr [HIGH_SECTOR]
   198                                  @@:
   199 000000B2 E2BB                            LOOP    ZERODIR
   200 000000B4 A1[0000]                        MOV     AX,[LASTENT]
   201 000000B7 40                              INC     AX
   202 000000B8 F8                              CLC
   203 000000B9 C3                              return
   204                                  
   205                                  EndProc BUILDDIR
   206                                  
   207                                  ;
   208                                  ; set up a . or .. directory entry for a directory.
   209                                  ;
   210                                  ;   Inputs:     ES:DI point to the beginning of a directory entry.
   211                                  ;               AX contains ". " or ".."
   212                                  ;               DX contains first cluster of entry
   213                                  ;
   214                                          procedure   SETDOTENT,NEAR
   214          ******************       warning: proc SETDOTENT... [-w+user]
   215                                          DOSAssume   CS,<DS>,"SetDotEnt"
   216                                  ;
   217                                  ; Fill in name field
   218                                  ;
   219 000000BA AB                              STOSW
   220 000000BB B90400                          MOV     CX,4
   221 000000BE B82020                          MOV     AX,"  "
   222 000000C1 F3AB                            REP     STOSW
   223 000000C3 AA                              STOSB
   224                                  ;
   225                                  ; Set up attribute
   226                                  ;
   227 000000C4 B010                            MOV     AL,attr_directory
   228                                          errnz   dir_attr-(dir_name+11)
   229 000000C6 AA                              STOSB
   230                                  ;
   231                                  ; Initialize time and date of creation
   232                                  ;
   233 000000C7 83C70A                          ADD     DI,10
   234 000000CA 8B36[0000]                      MOV     SI,WORD PTR [THISSFT]
   235 000000CE 8B440D                          MOV     AX,[SI + sf_time]
   236                                          errnz   dir_time-(dir_attr+1+10)
   237 000000D1 AB                              STOSW
   238 000000D2 8B440F                          MOV     AX,[SI + sf_date]
   239                                          errnz   dir_date-(dir_time+2)
   240 000000D5 AB                              STOSW
   241                                  ;
   242                                  ; Set up first cluster field
   243                                  ;
   244 000000D6 89D0                            MOV     AX,DX
   245                                          errnz   dir_first-(dir_date+2)
   246 000000D8 AB                              STOSW
   247                                  ;
   248                                  ; 0 file size
   249                                  ;
   250 000000D9 31C0                            XOR     AX,AX
   251                                          errnz   dir_size_l-(dir_first+2)
   252 000000DB AB                              STOSW
   253 000000DC AB                              STOSW
   254                                          errnz   <(dir_entry_struc_size)-(dir_size_l+4)>
   255 000000DD C3                              return
   256                                  EndProc SETDOTENT
   257                                  
   258                                  Break   <MAKENODE -- CREATE A NEW NODE>
   259                                  
   260                                  ; Inputs:
   261                                  ;       AL - attribute to create
   262                                  ;       AH = 0 if it is ok to truncate a file already by this name
   263                                  ;       AH = Non 0 if this is an error
   264                                  ;               (AH ignored on dirs and devices)
   265                                  ;        NOTE: When making a DIR or volume ID, AH need not be set since
   266                                  ;               a name already existant is ALWAYS an error in these cases.
   267                                  ;       [WFP_START] Points to WFP string ("d:/" must be first 3 chars, NUL
   268                                  ;               terminated)
   269                                  ;       [CURR_DIR_END] Points to end of Current dir part of string
   270                                  ;               ( = -1 if current dir not involved, else
   271                                  ;                Points to first char after last "/" of current dir part)
   272                                  ;       [THISCDS] Points to CDS being used
   273                                  ;       [THISSFT] Points to an empty SFT. EXCEPT sf_mode filled in.
   274                                  ; Function:
   275                                  ;       Make a new node
   276                                  ; Outputs:
   277                                  ;       Sets EXTERR_LOCUS = errLOC_Disk or errLOC_Unk via GetPathNoset
   278                                  ;       CARRY SET IF ERROR
   279                                  ;          AX = 1 A node by this name exists and is a directory
   280                                  ;          AX = 2 A new node could not be created
   281                                  ;          AX = 3 A node by this name exists and is a disk file
   282                                  ;               (AH was NZ on input)
   283                                  ;          AX = 4 Bad Path
   284                                  ;               SI return from GetPath maintained
   285                                  ;          AX = 5 Attribute mismatch
   286                                  ;          AX = 6 Sharing Violation
   287                                  ;               (INT 24 generated ALWAYS since create is always compat mode
   288                                  ;          AX = 7 file not found for Extended Open (not exists and fails)
   289                                  ;       ELSE
   290                                  ;          AX = 0       Disk Node
   291                                  ;          AX = 3       Device Node (error in some cases)
   292                                  ;          [DIRSTART],[DIRSEC],[CLUSFAC],[CLUSNUM] set to directory
   293                                  ;               containing new node.
   294                                  ;          [CURBUF+2]:BX Points to entry
   295                                  ;          [CURBUF+2]:SI Points to entry.dir_first
   296                                  ;          [THISSFT] is filled in
   297                                  ;               sf_mode = unchanged.
   298                                  ;          Attribute byte in entry is input AL
   299                                  ; DS preserved, others destroyed
   300                                  
   301                                          procedure   MakeNode,NEAR
   301          ******************       warning: proc MakeNode... [-w+user]
   302                                          DOSAssume   CS,<DS>,"MakeNode"
   303                                          ASSUME  ES:NOTHING
   304                                  
   305                                  CREATING equ Creating	; NASM port label
   306 000000DE C706[0000]FFE5                  MOV     WORD PTR [CREATING],0E5FFH      ; Creating, not DEL *.*
   307 000000E4 50                              PUSH    AX              ; Save AH value
   308 000000E5 C606[0000]00                    MOV     byte [NoSetDir],0
   309 000000EA A2[0000]                        MOV     [SATTRIB],AL
   310 000000ED E8(0000)                        invoke  GetPathNoSet
   311 000000F0 88CA                            MOV     DL,CL           ; Save CL info
   312 000000F2 89C1                            MOV     CX,AX           ; Device ID to CH
   313 000000F4 58                              POP     AX              ; Get back AH
   314 000000F5 7330                            JNC     make_exists     ; File existed
   315 000000F7 7505                            JNZ     make_err_4      ; Path bad
   316 000000F9 80FA80                          CMP     DL,80H          ; Check "CL" return from GETPATH
   317 000000FC 7406                            JZ      make_type       ; Name simply not found, and no metas
   318                                  make_err_4:
   319 000000FE B004                            MOV     AL,4            ; case 1 bad path
   320                                  make_err_ret:
   321 00000100 30E4                            XOR     AH,AH
   322 00000102 F9                              STC
   323 00000103 C3                              return
   324                                  
   325                                          entry   RENAME_MAKE     ; Used by DOS_RENAME to "copy" a node
   326                                  
   327                                  make_type:
   328                                  ;Extended Open hooks
   329 00000104 F606[0000]01                    TEST   byte [EXTOPEN_ON],ext_open_on  ;FT. from extended open                ;AN000;
   330 00000109 7412                            JZ     make_type2                ;FT. no                                ;AN000;
   331 0000010B 800E[0000]04                    OR     byte [EXTOPEN_ON],ext_file_not_exists ;FT. set for extended open      ;AN000;
   332 00000110 F706[0000]F000                  TEST   word [EXTOPEN_FLAG],0F0H       ;FT. not exists and fails              ;AN000;
   333 00000116 7505                            JNZ    make_type2                ;FT. no                                ;AN000;
   334 00000118 F9                              STC                              ;FT. set carry                         ;AN000;
   335 00000119 B80700                          MOV    AX,7                      ;FT. file not found                    ;AN000;
   336 0000011C C3                              return                           ;FT.                                   ;AN000;
   337                                  make_type2:
   338                                  ;Extended Open hooks
   339 0000011D C43E[0000]                      LES     DI,[THISSFT]
   340                                  ;       MOV     [ES:DI.sf_mode],sharing_compat + open_for_both
   341 00000121 31C0                            XOR     AX,AX           ; nothing exists Disk Node
   342 00000123 F9                              STC                     ; Not found
   343 00000124 EB5B                            JMP     make_new
   344 00000126 90                      	nop	; identicalise
   345                                  
   346                                  ;
   347                                  ; The node exists.  It may be either a device, directory or file:
   348                                  ;   Zero set => directory
   349                                  ;   High bit of CH on => device
   350                                  ;   else => file
   351                                  make_exists:
   352 00000127 7448                            JZ      make_exists_dir
   353 00000129 B003                            MOV     AL,3            ; file exists type 3  (error or device node)
   354                                  ATTRIB equ Attrib	; NASM port label
   355 0000012B F606[0000]18                    TEST    BYTE PTR [ATTRIB],(attr_volume_id+attr_directory)
   356 00000130 753B                            JNZ     make_err_ret_5  ; Cannot already exist as Disk or Device Node
   357                                                                  ;       if making DIR or Volume ID
   358 00000132 08ED                            OR      CH,CH
   359 00000134 781A                            JS      make_share      ; No further checks on attributes if device
   360 00000136 08E4                            OR      AH,AH
   361 00000138 75C6                            JNZ     make_err_ret    ; truncating NOT OK (AL = 3)
   362 0000013A 51                              PUSH    CX              ; Save device ID
   363 0000013B 8E06[0200]                      MOV     ES,WORD PTR [CURBUF+2]
   364                                   assume es:nothing
   365 0000013F 268A6F0B                        MOV     CH,[ES:BX+dir_attr] ; Get file attributes
   366 00000143 F6C501                          TEST    CH,attr_read_only
   367 00000146 7524                            JNZ     make_err_ret_5P ; Cannot create on read only files
   368 00000148 E8(0000)                        invoke  MatchAttributes
   369 0000014B 59                              POP     CX              ; Devid back in CH
   370 0000014C 751F                            JNZ     make_err_ret_5  ; Attributes not ok
   371 0000014E 30C0                            XOR     AL,AL           ; AL = 0, Disk Node
   372                                  make_share:
   373 00000150 30E4                            XOR     AH,AH
   374 00000152 50                              PUSH    AX              ; Save Disk or Device node
   375 00000153 51                              PUSH    CX              ; Save Device ID
   376 00000154 88EC                            MOV     AH,CH           ; Device ID to AH
   377 00000156 E84701                          CALL    DOOPEN          ; Fill in SFT for share check
   378 00000159 C43E[0000]                      LES     DI,[THISSFT]
   379                                  ;       MOV     [ES:DI.sf_mode],sharing_compat + open_for_both
   380 0000015D 5653                            SaveReg <SI,BX>         ; Save CURBUF pointers
   381 0000015F E8(0000)                        invoke  ShareEnter
   382 00000162 735A                            jnc     MakeEndShare
   383                                  ;
   384                                  ; User failed request.
   385                                  ;
   386 00000164 5B5E5958                        RestoreReg  <BX,SI,CX,AX>
   387                                  Make_Share_ret:
   388 00000168 B006                            MOV     AL,6
   389 0000016A EB94                            JMP     make_err_ret
   390                                  
   391                                  make_err_ret_5P:
   392 0000016C 59                              POP     CX              ; Get back device ID
   393                                  make_err_ret_5:
   394 0000016D B005                            MOV     AL,5            ; Attribute mismatch
   395 0000016F EB8F                            JMP     make_err_ret
   396                                  
   397                                  make_exists_dir:
   398 00000171 B001                            MOV     AL,1            ; exists as directory, always an error
   399 00000173 EB8B                            JMP     make_err_ret
   400                                  
   401                                  make_save:
   402 00000175 50                              PUSH    AX              ; Save whether Disk or File
   403 00000176 89C8                            MOV     AX,CX           ; Device ID to AH
   404                                  NewEntry equ NEWENTRY	; NASM port label
   405 00000178 E87400                          CALL    NewEntry
   406 0000017B 58                              POP     AX              ; 0 if Disk, 3 if File
   407 0000017C 739E                            retnc
   408 0000017E B002                            MOV     AL,2            ; create failed case 2
   409 00000180 C3                              return
   410                                  
   411                                  make_new:
   412 00000181 E8F1FF                          call    make_save
   413 00000184 72FA                            retc                    ; case 2 fail
   414 00000186 F606[0000]10                    TEST    BYTE PTR [ATTRIB],attr_directory
   415 0000018B 75F3                            retnz                   ; Don't "open" directories, so don't
   416                                                                  ;   tell the sharer about them
   417 0000018D 505356                          SaveReg <AX,BX,SI>      ; Save AL code
   418 00000190 E8(0000)                        invoke  ShareEnter
   419 00000193 5E5B58                          RestoreReg  <SI,BX,AX>
   420 00000196 73E8                            retnc
   421                                  ;
   422                                  ; We get here by having the user FAIL a share problem.  Typically a failure of
   423                                  ; this nature is an out-of-space or an internal error.  We clean up as best as
   424                                  ; possible:  delete the newly created directory entry and return share_error.
   425                                  ;
   426 00000198 50                              PUSH    AX
   427 00000199 C43E[0000]                      LES     DI,[CurBuf]
   428 0000019D 26C607E5                        MOV     BYTE PTR [ES:BX],0E5H   ; nuke newly created entry.
   429                                  
   430 000001A1 26F6450540                      TEST    byte [ES:DI + buf_flags],buf_dirty  ;LB. if already dirty              ;AN000;
   431 000001A6 7508                            JNZ     yesdirty2                 ;LB.    don't increment dirty count   ;AN000;
   432 000001A8 E8(0000)                        invoke  INC_DIRTY_COUNT           ;LB.                                  ;AN000;
   433 000001AB 26804D0540                      OR      byte [ES:DI + buf_flags],buf_dirty ; flag buffer as dirty
   434                                  yesdirty2:
   435 000001B0 C42E[0000]                      LES     BP,[ThisDPB]
   436                                  DPB_Drive equ dpb_drive	; NASM port equate
   437 000001B4 268A4600                        MOV     AL,[ES:BP + DPB_Drive]    ; get drive for flush
   438 000001B8 E8(0000)                        Invoke  FlushBuf                ; write out buffer.
   439 000001BB 58                              POP     AX
   440                                  make_Share_ret equ Make_Share_ret	; NASM port label
   441 000001BC EBAA                            jmp     make_Share_ret
   442                                  ;
   443                                  ; We have found an existing file.  We have also entered it into the share set.
   444                                  ; At this point we need to call newentry to correctly address the problem of
   445                                  ; getting rid of old data (create an existing file) or creating a new
   446                                  ; directory entry (create a new file).  Unfortunately, this operation may
   447                                  ; result in an INT 24 that the user doesn't return from, thus locking the file
   448                                  ; irretrievably into the share set.  The correct solution is for us to LEAVE
   449                                  ; the share set now, do the operation and then reassert the share access.
   450                                  ;
   451                                  ; We are allowed to do this!  There is no window!  After all, we are in
   452                                  ; critDisk here and for someone else to get in, they must enter critDisk also.
   453                                  ;
   454                                  MakeEndShare:
   455                                  ThisSFT equ THISSFT	; NASM port label
   456 000001BE C43E[0000]                      LES     DI,[ThisSFT]              ; grab SFT
   457 000001C2 31C0                            XOR     AX,AX
   458 000001C4 E8(0000)                        EnterCrit   critSFT
   459 000001C7 268705                          XCHG    AX,[ES:DI + sf_ref_count]
   460 000001CA 505706                          SaveReg <AX,DI,ES>
   461 000001CD 9C                              PUSHF
   462 000001CE E8(0000)                        invoke  ShareEnd                ; remove sharing
   463 000001D1 9D                              POPF
   464 000001D2 075F268F05                      RestoreReg  <ES,DI,word [ES:DI + sf_ref_count]>
   465 000001D7 E8(0000)                        LeaveCrit   critSFT
   466 000001DA 5B5E5958                        RestoreReg  <BX,SI,CX,AX>
   467 000001DE E894FF                          CALL    make_save
   468                                  ;
   469                                  ; If the user failed, we do not reenter into the sharing set.
   470                                  ;
   471 000001E1 729D                            retc                            ; bye if error
   472 000001E3 505356                          SaveReg <AX,BX,SI>
   473 000001E6 9C                              PUSHF
   474 000001E7 E8(0000)                        invoke  ShareEnter
   475 000001EA 9D                              POPF
   476 000001EB 5E5B58                          RestoreReg  <SI,BX,AX>
   477                                  ;
   478                                  ; If Share_check fails, then we have an internal ERROR!!!!!
   479                                  ;
   480 000001EE C3                              return
   481                                  EndProc MakeNode
   481          ******************       warning: ***** Possible stack size error in MakeNode ***** [-w+user]
   482                                  
   483                                  ; Inputs:
   484                                  ;       [THISSFT] set
   485                                  ;       [THISDPB] set
   486                                  ;       [LASTENT] current last valid entry number in directory if no free
   487                                  ;               entries
   488                                  ;       [VOLID] set if a volume ID was found during search
   489                                  ;       [ATTRIB] Contains attributes for new file
   490                                  ;       [DIRSTART] Points to first cluster of dir (0 means root)
   491                                  ;       CARRY FLAG INDICATES STATUS OF SEARCH FOR FILE
   492                                  ;               NC means file existed (device)
   493                                  ;               C  means file did not exist
   494                                  ;       AH = Device ID byte
   495                                  ;       If FILE
   496                                  ;           [CURBUF+2]:BX points to start of directory entry
   497                                  ;           [CURBUF+2]:SI points to dir_first of directory entry
   498                                  ;       If device
   499                                  ;           DS:BX points to start of "fake" directory entry
   500                                  ;           DS:SI points to dir_first of "fake" directory entry
   501                                  ;               (has DWORD pointer to device header)
   502                                  ; Function:
   503                                  ;       Make a new directory entry
   504                                  ;       If an old one existed it is truncated first
   505                                  ; Outputs:
   506                                  ;       Carry set if error
   507                                  ;               Can't grow dir, atts didn't match, attempt to make 2nd
   508                                  ;               vol ID, user FAILed to I 24
   509                                  ;       else
   510                                  ;               outputs of DOOPEN
   511                                  ; DS, BX, SI preserved (meaning on SI BX, not value), others destroyed
   512                                  
   513                                          procedure NEWENTRY,NEAR
   513          ******************       warning: proc NEWENTRY... [-w+user]
   514                                          DOSAssume   CS,<DS>,"NewEntry"
   515                                          ASSUME  ES:NOTHING
   516                                  
   517                                  THISDPB equ ThisDPB	; NASM port label
   518 000001EF C42E[0000]                      LES     BP,[THISDPB]
   519                                  ASSUME  ES:NOTHING
   520 000001F3 7316                            JNC     EXISTENT
   521 000001F5 803E[0000]00                    CMP     byte [FAILERR],0
   522 000001FA F9                              STC
   523 000001FB 75F1                            retnz                   ; User FAILed, node might exist
   524 000001FD E800FE                          CALL    BUILDDIR        ; Try to build dir
   525 00000200 72EC                            retc                    ; Failed
   526 00000202 E8(0000)                        invoke  GETENT          ; Point at that free entry
   527 00000205 72E7                            retc                    ; Failed
   528 00000207 EB0E                            JMP     SHORT FREESPOT
   529                                  
   530                                  ERRRET3:
   531 00000209 F9                              STC
   532 0000020A C3                              return
   533                                  
   534                                  EXISTENT:
   535                                          DOSAssume   CS,<DS>,"MKNODE/ExistEnt"
   536 0000020B 08E4                            OR      AH,AH           ; Check if file is I/O device
   537 0000020D 7903                            JNS     NOT_DEV1
   538 0000020F E98E00                          JMP     DOOPEN          ; If so, proceed with open
   539                                  
   540                                  NOT_DEV1:
   541 00000212 E82A01                          invoke  FREEENT         ; Free cluster chain
   542 00000215 72F3                            retc                    ; Failed
   543                                  FREESPOT:
   544 00000217 F606[0000]08                    TEST    BYTE PTR [ATTRIB],attr_volume_id
   545 0000021C 7407                            JZ      NOTVOLID
   546                                  VOLID equ VolID	; NASM port label
   547 0000021E 803E[0000]00                    CMP     BYTE PTR [VOLID],0
   548 00000223 75E4                            JNZ     ERRRET3         ; Can't create a second volume ID
   549                                  NOTVOLID:
   550 00000225 8E06[0200]                      MOV     ES,WORD PTR [CURBUF+2]
   551                                   assume es:nothing
   552 00000229 89DF                            MOV     DI,BX
   553                                  NAME1 equ Name1	; NASM port label
   554 0000022B BE[0000]                        MOV     SI,OFFSET NAME1 wrt DOSGROUP
   555 0000022E B90500                          MOV     CX,5
   556 00000231 F3A5                            REP     MOVSW
   557 00000233 A4                              MOVSB                   ; Move name into dir entry
   558 00000234 A0[0000]                        MOV     AL,[ATTRIB]
   559                                          errnz   dir_attr-(dir_name+11)
   560 00000237 AA                              STOSB                   ; Attributes
   561                                  ;; File Tagging for Create DOS 4.00
   562 00000238 B105                            MOV     CL,5            ;FT. assume normal                              ;AN000;
   563                                  ;       CMP     [CPSWFLAG],0    ;FT. code page matching on                      ;AN000;
   564                                  ;       JZ      NORMFT          ;FT. no, make null code page                    ;AN000;
   565                                  ;       invoke  Get_Global_CdPg ;FT. get global code page                       ;AN000;
   566                                  ;       STOSW                   ;FT. tag this file with global code page        ;AN000;
   567                                  ;       DEC     CL              ;FT. only 4                                     ;AN000;
   568                                  ;NORMFT:                        ;FT.                                            ;AN000;
   569                                  
   570                                  ;; File Tagging for Create DOS 4.00
   571 0000023A 31C0                            XOR     AX,AX
   572 0000023C F3AB                            REP     STOSW           ; Zero pad
   573 0000023E E8(0000)                        invoke  DATE16
   574 00000241 92                              XCHG    AX,DX
   575                                          errnz   dir_time-(dir_attr+1+2*5)
   576 00000242 AB                              STOSW                   ; dir_time
   577 00000243 92                              XCHG    AX,DX
   578                                          errnz   dir_date-(dir_time+2)
   579 00000244 AB                              STOSW                   ; dir_date
   580 00000245 31C0                            XOR     AX,AX
   581 00000247 57                              PUSH    DI              ; Correct SI input value (recomputed for new buffer)
   582                                  
   583                                          errnz   dir_first-(dir_date+2)
   584 00000248 AB                              STOSW                   ; Zero dir_first and size
   585                                          errnz   dir_size_l-(dir_first+2)
   586 00000249 AB                              STOSW
   587 0000024A AB                              STOSW
   588                                  updnxt:
   589                                          errnz   <(dir_entry_struc_size)-(dir_size_l+4)>
   590 0000024B 8B36[0000]                      MOV     SI,WORD PTR [CURBUF]
   591                                  
   592 0000024F 26F6440540                      TEST    byte [ES:SI + buf_flags],buf_dirty  ;LB. if already dirty              ;AN000;
   593 00000254 7508                            JNZ     yesdirty3                 ;LB.    don't increment dirty count   ;AN000;
   594 00000256 E8(0000)                        invoke  INC_DIRTY_COUNT           ;LB.                                  ;AN000;
   595 00000259 26804C0540                      OR      byte [ES:SI + buf_flags],buf_dirty
   596                                  yesdirty3:
   597 0000025E C42E[0000]                      LES     BP,[THISDPB]
   598 00000262 268A4600                        MOV     AL,[ES:BP + dpb_drive]    ; Sets AH value again (in AL)
   599 00000266 50                              PUSH    AX
   600 00000267 53                              PUSH    BX
   601                                  ; If we have a file, we need to increment the open ref. count so that
   602                                  ; we have some protection against invalid media changes if an Int 24
   603                                  ; error occurs.
   604                                  ; Do nothing for a device.
   605 00000268 0657                            SaveReg <ES,DI>
   606 0000026A C43E[0000]                      LES     DI,[THISSFT]
   607 0000026E 26F745058000                    test    word [es:di + sf_flags],devid_device
   608 00000274 751A                            jnz     GotADevice
   609 00000276 1E53                            SaveReg <DS,BX>
   610 00000278 C51E[0000]                      LDS     BX,[THISDPB]
   611 0000027C 26895D07                        MOV     word ptr [ES:DI + sf_devptr],BX
   612 00000280 8CDB                            MOV     BX,DS
   613 00000282 26895D09                        MOV     word ptr [ES:DI + sf_devptr+2],BX
   614 00000286 5B1F                            RestoreReg <BX,DS>      ; need to use DS for segment later on
   615 00000288 E8(0000)                        invoke  Dev_Open_SFT    ; increment ref. count
   616 0000028B C606[0000]01                    mov     byte [VIRTUAL_OPEN],1; set flag
   617                                  GotADevice:
   618 00000290 5F07                            RestoreReg <DI,ES>
   619                                  
   620                                  %ifdef BUF2
   621 00000292 E8(0000)                        invoke  FLUSHBUF
   622                                  %else
   623                                          PUSH    word [ACT_PAGE]      ;LB. save EMS page for curbuf                   ;AN000;
   624                                          invoke  FLUSHBUF
   625                                          POP     BX              ;LB. restore EMS page for curbuf                ;AN000;
   626                                          PUSHF                   ;LB. save flushbuf falg                         ;AN000;
   627                                          CMP     BX,-1           ;BL-NETWORK PTM #-?
   628                                          JE      Page_ok         ;BL-NETWORK PTM #-?
   629                                          invoke  SET_MAP_PAGE    ;LB. remap curbuf                               ;AN000;
   630                                  Page_ok:                        ;BL-NETWORK PTM #-?
   631                                          POPF                    ;LB. restore flush flag                         ;AN000;
   632                                  %endif
   633 00000295 E8F900                          Call    CHECK_VIRT_OPEN ; decrement ref. count                          ;AN000;
   634 00000298 5B                              POP     BX
   635 00000299 58                              POP     AX
   636 0000029A 5E                              POP     SI              ; Get SI input back
   637 0000029B 88C4                            MOV     AH,AL           ; Get I/O driver number back
   638 0000029D 7301C3                          retc                    ; Failed
   639                                  
   640                                  
   641                                  ;NOTE FALL THROUGH
   642                                  
   643                                  ; Inputs:
   644                                  ;       [THISDPB] points to DPB if file
   645                                  ;       [THISSFT] points to SFT being used
   646                                  ;       AH = Device ID byte
   647                                  ;       If FILE
   648                                  ;           [CURBUF+2]:BX points to start of directory entry
   649                                  ;           [CURBUF+2]:SI points to dir_first of directory entry
   650                                  ;       If device
   651                                  ;           DS:BX points to start of "fake" directory entry
   652                                  ;           DS:SI points to dir_first of "fake" directory entry
   653                                  ;               (has DWORD pointer to device header)
   654                                  ; Function:
   655                                  ;       Fill in SFT from dir entry
   656                                  ; Outputs:
   657                                  ;       CARRY CLEAR
   658                                  ;       sf_ref_count and sf_mode fields not altered
   659                                  ;       sf_flags high byte = 0
   660                                  ;       sf_flags low byte = AH except
   661                                  ;       sf_flags Bit 6 set (not dirty or not EOF)
   662                                  ;       sf_attr sf_date sf_time sf_name set from entry
   663                                  ;       sf_position = 0
   664                                  ;       If device
   665                                  ;           sf_devptr = dword at dir_first (pointer to device header)
   666                                  ;           sf_size = 0
   667                                  ;       If file
   668                                  ;           sf_firclus sf_size set from entry
   669                                  ;           sf_devptr = [THISDPB]
   670                                  ;           sf_cluspos = 0
   671                                  ;           sf_lstclus = sf_firclus
   672                                  ;           sf_dirsec sf_dirpos set
   673                                  ; DS,SI,BX preserved, others destroyed
   674                                  
   675                                      entry   DOOPEN
   676                                          DOSAssume   CS,<DS>,"DoOpen"
   677                                          ASSUME  ES:NOTHING
   678                                  
   679                                  ;
   680                                  ; Generate and store attribute
   681                                  ;
   682 000002A0 88E6                            MOV     DH,AH           ; AH to different place
   683 000002A2 C43E[0000]                      LES     DI,[THISSFT]
   684 000002A6 83C704                          ADD     DI,sf_attr      ; Skip ref_count and mode fields
   685 000002A9 30C0                            XOR     AL,AL           ; Assume it's a device, devices have an
   686                                                                  ;   attribute of 0 (for R/O testing etc).
   687 000002AB 08F6                            OR      DH,DH           ; See if our assumption good.
   688 000002AD 7807                            JS      DEV_SFT1        ; If device DS=DOSGROUP
   689 000002AF 8E1E[0200]                      MOV     DS,WORD PTR [CURBUF+2]
   690                                  ASSUME  DS:NOTHING
   691 000002B3 8A470B                          MOV     AL,[BX + dir_attr] ; If file, get attrib from dir entry
   692                                  DEV_SFT1:
   693 000002B6 AA                              STOSB                   ; sf_attr, ES:DI -> sf_flags
   694                                  ;
   695                                  ; Generate and store flags word
   696                                  ;
   697 000002B7 31C0                            XOR     AX,AX
   698 000002B9 88F0                            MOV     AL,DH
   699 000002BB 0C40                            OR      AL,devid_file_clean
   700 000002BD AB                              STOSW                   ; sf_flags, ES:DI -> sf_devptr
   701                                  ;
   702                                  ; Generate and store device pointer
   703                                  ;
   704 000002BE 1E                              PUSH    DS
   705 000002BF C5471A                          LDS     AX,[BX + dir_first]       ; Assume device
   706                                   assume ds:nothing
   707 000002C2 08F6                            OR      DH,DH
   708 000002C4 7805                            JS      DEV_SFT2
   709 000002C6 36C506[0000]                    LDS     AX,[ss:THISDPB]            ; Was file
   710                                   assume ds:DPB
   711                                  DEV_SFT2:
   712 000002CB AB                              STOSW                           ; store offset
   713 000002CC 8CD8                            MOV     AX,DS
   714 000002CE 1F                              POP     DS
   715                                   assume ds:nothing
   716 000002CF AB                              STOSW                           ; store segment
   717                                                                          ; ES:DI -> sf_firclus
   718                                  ;
   719                                  ; Generate pointer to, generate and store first cluster (irrelevant  for
   720                                  ; devices)
   721                                  ;
   722 000002D0 56                              PUSH    SI              ; Save pointer to dir_first
   723 000002D1 A5                              MOVSW                   ; dir_first -> sf_firclus
   724                                                                  ; DS:SI -> dir_size_l, ES:DI -> sf_time
   725                                  ;
   726                                  ; Copy time/date of last modification
   727                                  ;
   728 000002D2 83EE06                          SUB     SI,dir_size_l - dir_time        ; DS:SI->dir_time
   729 000002D5 A5                              MOVSW                   ; dir_time -> sf_time
   730                                                                  ; DS:SI -> dir_date, ES:DI -> sf_date
   731 000002D6 A5                              MOVSW                   ; dir_date -> sf_date
   732                                                                  ; DS:SI -> dir_first, ES:DI -> sf_size
   733                                  ;
   734                                  ; Generate and store file size (0 for devices)
   735                                  ;
   736 000002D7 AD                              LODSW                   ; skip dir_first, DS:SI -> dir_size_l
   737 000002D8 AD                              LODSW                   ; dir_size_l in AX , DS:SI -> dir_size_h
   738 000002D9 89C1                            MOV     CX,AX           ; dir_size_l in CX
   739 000002DB AD                              LODSW                   ; dir_size_h (size AX:CX), DS:SI -> ????
   740 000002DC 08F6                            OR      DH,DH
   741 000002DE 7904                            JNS     FILE_SFT1
   742 000002E0 31C0                            XOR     AX,AX
   743 000002E2 89C1                            MOV     CX,AX           ; Devices are open ended
   744                                  FILE_SFT1:
   745 000002E4 91                              XCHG    AX,CX
   746 000002E5 AB                              STOSW                   ; Low word of sf_size
   747 000002E6 91                              XCHG    AX,CX
   748 000002E7 AB                              STOSW                   ; High word of sf_size
   749                                                                  ; ES:DI -> sf_position
   750                                  ;
   751                                  ; Initialize position to 0
   752                                  ;
   753 000002E8 31C0                            XOR     AX,AX
   754 000002EA AB                              STOSW
   755 000002EB AB                              STOSW                   ; sf_position
   756                                                                  ; ES:DI -> sf_cluspos
   757                                  ;
   758                                  ; Generate cluster optimizations for files
   759                                  ;
   760 000002EC 08F6                            OR      DH,DH
   761 000002EE 7840                            JS      DEV_SFT3
   762 000002F0 AB                              STOSW                   ; sf_cluspos
   763 000002F1 8B471A                          MOV     AX,[BX + dir_first]
   764                                  ;;;;    STOSW                   ; sf_lstclus
   765 000002F4 2689451A                        MOV     [ES:DI - sf_dirsec + sf_lstclus],AX  ;AN004; save it
   766                                  
   767                                  
   768                                  ; DOS 3.3  FastOpen  6/13/86
   769                                  
   770 000002F8 1E                              PUSH   DS
   771 000002F9 161F                            context DS
   772 000002FB F606[0000]04                    TEST   byte [FastOpenFlg],Special_Fill_Set
   773 00000300 7412                            JZ     Not_FastOpen
   774                                  FastOpen_Ext_Info equ FastOpen_Ext_info	; NASM port label
   775 00000302 BE[0000]                        MOV     SI,OFFSET FastOpen_Ext_Info wrt DOSGROUP
   776 00000305 8B4401                          MOV     AX,WORD PTR [SI + FEI_dirsec]
   777 00000308 AB                              STOSW                   ; sf_dirsec
   778 00000309 8B4403                          MOV     AX,WORD PTR [SI + FEI_dirsec+2]  ;;; changed for >32mb
   779 0000030C AB                              STOSW                   ; sf_dirsec
   780 0000030D 8A04                            MOV     AL,[SI + FEI_dirpos]
   781 0000030F AA                              STOSB                   ; sf_dirpos
   782 00000310 1F                              POP     DS
   783                                   assume ds:nothing
   784 00000311 EB1B                            JMP     Next_Name
   785 00000313 90                      	nop	; identicalise
   786                                  
   787                                  ; DOS 3.3  FastOpen  6/13/86
   788                                  
   789                                  Not_FastOpen:
   790 00000314 1F                              POP     DS                      ; normal path
   791                                  ASSUME  DS:NOTHING
   792 00000315 368B36[0000]                    MOV     SI,WORD PTR [ss:CURBUF]    ; DS:SI->buffer header
   793 0000031A 8B4408                          MOV     AX,WORD PTR [SI + buf_sector]     ;F.C. >32mb                        ;AN000;
   794 0000031D AB                              STOSW                   ; sf_dirsec     ;F.C. >32mb                        ;AN000;
   795 0000031E 8B440A                          MOV     AX,WORD PTR [SI + buf_sector+2]   ;F.C. >32mb                        ;AN000;
   796 00000321 AB                              STOSW                   ; sf_dirsec     ;F.C. >32mb                        ;AN000;
   797 00000322 89D8                            MOV     AX,BX
   798 00000324 83C610                          ADD     SI,BUFINSIZ     ; DS:SI-> start of data in buffer
   799 00000327 29F0                            SUB     AX,SI           ; AX = BX relative to start of sector
   800 00000329 B120                            MOV     CL,dir_entry_struc_size
   801 0000032B F6F1                            DIV     CL
   802 0000032D AA                              STOSB                   ; sf_dirpos
   803                                  
   804                                  Next_Name:
   805                                          errnz   sf_name-(sf_dirpos+1)
   806 0000032E EB03                            JMP     SHORT FILE_SFT2
   807                                  
   808                                  DEV_SFT3:
   809 00000330 83C707                          ADD     DI,sf_name - sf_cluspos
   810                                  FILE_SFT2:
   811                                  ;
   812                                  ; Copy in the object's name
   813                                  ;
   814 00000333 89DE                            MOV     SI,BX           ; DS:SI points to dir_name
   815 00000335 B90B00                          MOV     CX,11
   816 00000338 F3A4                            REP     MOVSB           ; sf_name
   817 0000033A 5E                              POP     SI              ; recover DS:SI -> dir_first
   818                                  ;; File tagging , code page and XA cluster must be after name
   819                                  ;       MOV     AX,[BX.dir_CODEPG]       ;FT. set file's code page                 ;AN000;
   820                                  ;       STOSW                            ;FT.                                      ;AN000;
   821                                  ;       MOV     AX,[BX.dir_EXTCLUSTER]   ;FT. set XA cluster                       ;AN000;
   822                                  ;       STOSW                            ;FT.                                      ;AN000;
   823                                  ;       MOV     AX,[EXTOPEN_IO_MODE]     ;FT. extended open                        ;AN000;
   824                                  ;       STOSW                            ;FT.                                      ;AN000;
   825                                  ;       MOV     AL,[BX.dir_attr2]        ;FT. high attribute                       ;AN000;
   826                                  ;       STOSB                            ;FT.                                      ;AN000;
   827                                  
   828                                  ;; File tagging , code page and XA cluster must be after name
   829                                  
   830 0000033B 161F                            context DS
   831 0000033D F8                              CLC
   832 0000033E C3                              return
   833                                  
   834                                  EndProc NEWENTRY
   835                                  
   836                                  ; Inputs:
   837                                  ;       ES:BP -> DPB
   838                                  ;       [CURBUF] Set
   839                                  ;       [CURBUF+2]:BX points to directory entry
   840                                  ;       [CURBUF+2]:SI points to above dir_first
   841                                  ; Function:
   842                                  ;       Free the cluster chain for the entry if present
   843                                  ; Outputs:
   844                                  ;       Carry set if error (currently user FAILed to I 24)
   845                                  ;       (NOTE dir_firclus and dir_size_l/h are wrong)
   846                                  ; DS BX SI ES BP preserved (BX,SI in meaning, not value) others destroyed
   847                                  
   848                                          procedure FREEENT,NEAR
   848          ******************       warning: proc FREEENT... [-w+user]
   849                                          DOSAssume   CS,<DS>,"FreeEnt"
   850                                          ASSUME  ES:NOTHING
   851                                  
   852 0000033F 1E                              PUSH    DS
   853 00000340 C53E[0000]                      LDS     DI,[CURBUF]
   854                                  ASSUME  DS:NOTHING
   855 00000344 8B0C                            MOV     CX,[SI]         ; Get pointer to clusters
   856 00000346 8B550A                          MOV     DX,WORD PTR [DI + buf_sector+2]  ;F.C. >32mb                      ;AN000;
   857 00000349 368916[0000]                    MOV     [ss:HIGH_SECTOR],DX               ;F.C. >32mb                      ;AN000;
   858 0000034E 8B5508                          MOV     DX,WORD PTR [DI + buf_sector]
   859 00000351 1F                              POP     DS
   860                                          DOSAssume   CS,<DS>,"MKNODE/FreeEnt"
   861 00000352 83F902                          CMP     CX,2
   862 00000355 7238                            JB      RET1            ; Was 0 length file (or mucked Firclus if CX=1)
   863 00000357 263B4E0D                        CMP     CX,[ES:BP + dpb_max_cluster]
   864 0000035B 7732                            JA      RET1            ; Treat like zero length file (firclus mucked)
   865 0000035D 29FB                            SUB     BX,DI
   866 0000035F 53                              PUSH    BX              ; Save offset
   867 00000360 FF36[0000]                      PUSH    word [HIGH_SECTOR]                  ;F.C. >32mb                      ;AN000;
   868 00000364 52                              PUSH    DX              ; Save sector number
   869                                  
   870 00000365 89CB                            MOV     BX,CX
   871 00000367 E8(0000)                        invoke  Delete_FSeek    ; FS. delete Fastseek Clusters                  ;AN000;
   872 0000036A E8(0000)                        invoke  RELEASE         ; Free any data allocated
   873 0000036D 5A                              POP     DX
   874 0000036E 8F06[0000]                      POP     word [HIGH_SECTOR]                  ;F.C. >32mb                      ;AN000;
   875 00000372 7302                            JNC     GET_BUF_BACK
   876 00000374 5B                              POP     BX
   877 00000375 C3                              return                  ; Screw up
   878                                  
   879                                  GET_BUF_BACK:
   880                                  
   881 00000376 C606[0000]18                    MOV     byte [ALLOWED],allowed_RETRY + allowed_FAIL
   882 0000037B 30C0                            XOR     AL,AL
   883 0000037D E8(0000)                        invoke  GETBUFFR        ; Get sector back
   884 00000380 5B                              POP     BX              ; Get offset back
   885 00000381 72F2                            retc
   886 00000383 E8(0000)                        invoke  SET_BUF_AS_DIR
   887 00000386 031E[0000]                      ADD     BX,WORD PTR [CURBUF]    ; Correct it for new buffer
   888 0000038A 89DE                            MOV     SI,BX
   889 0000038C 83C61A                          ADD     SI,dir_first    ; Get corrected SI
   890                                  RET1:
   891 0000038F F8                              CLC
   892 00000390 C3                              return
   893                                  EndProc FREEENT
   894                                  
   895                                  ;
   896                                  ; CHECK_VIRT_OPEN checks to see if we had performed a "virtual open" (by
   897                                  ; examining the flag [VIRTUAL_OPEN] to see if it is 1). If we did, then
   898                                  ; it calls Dev_Close_SFT to decrement the ref. count. It also resets the
   899                                  ; flag [VIRTUAL_OPEN].
   900                                  ; No registers affected (including flags).
   901                                  ; On input, [THISSFT] points to current SFT.
   902                                  ;
   903                                          Procedure CHECK_VIRT_OPEN,NEAR
   903          ******************       warning: proc CHECK_VIRT_OPEN... [-w+user]
   904                                          DOSAssume   CS,<DS>,"Check_Virt_Open"
   905                                  
   906 00000391 50                              PUSH    AX
   907 00000392 9F                              lahf                    ; preserve flags
   908 00000393 803E[0000]00                    CMP     byte [VIRTUAL_OPEN],0
   909 00000398 7410                            JZ      ALL_CLOSED
   910 0000039A C606[0000]00                    mov     byte [VIRTUAL_OPEN],0        ; reset flag
   911 0000039F 0657                            SaveReg <ES,DI>
   912 000003A1 C43E[0000]                      LES     DI,[THISSFT]
   913 000003A5 E8(0000)                        INVOKE  DEV_CLOSE_SFT
   914 000003A8 5F07                            RestoreReg <DI,ES>
   915                                  
   916                                  ALL_CLOSED:
   917 000003AA 9E                              sahf                    ; restore flags
   918 000003AB 58                              POP     AX
   919 000003AC C3                              return
   920                                  
   921                                  EndProc CHECK_VIRT_OPEN
   922                                  
   923                                      END
   924                                  
   925                                  
