]>
wirehaze git hosting - MS-DOS.git/blob - v4.0/src/DOS/DIR.ASM
1 ; SCCSID = @(#)dir.asm 1.1 85/04/10
2 ; SCCSID = @(#)dir.asm 1.1 85/04/10
3 TITLE DIR
- Directory
and path cracking
5 ; Main Path cracking routines, low level search routines
20 ; A000 version 4.00 Jan. 1988
24 ; get the appropriate segment definitions
30 CODE SEGMENT BYTE PUBLIC 'CODE'
31 ASSUME
SS:DOSGROUP
,CS:DOSGROUP
52 i_need SecClusPos
,BYTE
54 i_need NxtClusNum
,WORD
55 i_need DirSec
,DWORD ;AN000;
56 I_need FastOpenFlg
,BYTE ;AN000;
57 I_need HIGH_SECTOR
,WORD ;AN000;
59 Break <FINDENTRY
-- LOOK FOR AN
ENTRY>
64 ; [DIRSEC] = Starting directory sector number
65 ; [CLUSNUM] = Next cluster of directory
66 ; [CLUSFAC] = Sectors/Cluster
67 ; [NAME1] = Name to look for
69 ; Find file name in disk directory.
70 ; "?" matches any character.
72 ; Carry set if name not found
74 ; Zero set if attributes match (always except when creating)
75 ; AH = Device ID (bit 7 set if not disk)
76 ; [THISDPB] = Base of drive parameters
79 ; [CURBUF+2]:BX = Pointer into directory buffer
80 ; [CURBUF+2]:SI = Pointer to First Cluster field in directory entry
81 ; [CURBUF] has directory record with match
82 ; [NAME1] has file name
83 ; [LASTENT] is entry number of the entry
84 ; All other registers destroyed.
89 DOSAssume
CS,<DS>,"FindEntry"
94 AND AL,NOT attr_ignore
; Ignore useless bits
95 CMP AL,attr_volume_id
; Looking for vol ID only ?
97 CALL SETROOTSRCH
; Yes force search of root
106 MOV DS,WORD PTR [CURBUF
+2]
109 OR AH,AH ; End of directory?
111 CMP AH,BYTE PTR [DELALL
] ; Free entry?
113 TEST BYTE PTR [BX+11],attr_volume_id
123 MOV DI,OFFSET DOSGROUP
:NAME1
125 CMP BYTE PTR [NAME1
],0E5H ; special char check
127 MOV BYTE PTR [NAME1
],05H
135 DOSAssume
CS,<DS>,"NextEnt"
137 Assert ISDPB
,<<WORD PTR THISDPB
+2>,<WORD PTR THISDPB
>>,"NextEnt"
146 DOSAssume
CS,<DS>,"DIR/Free"
152 CMP AH,BYTE PTR [DELALL
] ; At end of directory?
154 JZ NEXTENT
; No - continue search
161 ; We have a file with a matching name. We must now consider the attributes:
164 ; Volume_ID Is Volume_ID in test?
165 ; Otherwise If no create then Is ATTRIB+extra superset of test?
166 ; If create then Is ATTRIB equal to test?
168 MOV CH,[SI] ; Attributes of file
170 DOSAssume
CS,<DS>,"DIR/found"
171 MOV AH,Attrib
; Attributes of search
172 AND AH,NOT attr_ignore
173 LEA SI,[SI+Dir_First
-Dir_Attr
] ; point to firclus field
174 TEST CH,attr_volume_id
; Volume ID file?
175 JZ check_one_volume_id
; Nope check other attributes
176 TEST AH,attr_volume_id
; Can we find Volume ID?
177 JZ NEXTENTJ
; Nope, (not even $FCB_CREATE)
178 XOR AH,AH ; Set zero flag for $FCB_CREATE
179 JMP SHORT RETFF
; Found Volume ID
181 CMP AH,attr_volume_id
; Looking only for Volume ID?
182 JZ NEXTENTJ
; Yes, continue search
183 invoke MatchAttributes
185 TEST BYTE PTR [CREATING
],-1 ; Pass back mismatch if creating
186 JZ NEXTENTJ
; Otherwise continue searching
189 MOV AH,ES:[BP.dpb_drive
]
197 ; DS:SI -> 11 character FCB style name NO '?'
198 ; Typically this is a directory entry. It MUST be in upper case
199 ; ES:DI -> 11 character FCB style name with possible '?'
200 ; Typically this is a FCB or SFT. It MUST be in upper case
202 ; Compare FCB style names allowing for ? match to any char
204 ; Zero if match else NZ
205 ; Destroys CX,SI,DI all others preserved
207 procedure MetaCompare
,near
208 ASSUME
DS:NOTHING
,ES:NOTHING
211 ;-------------------- Start of DBCS ;AN000;
212 CMP BYTE PTR DS:[SI],05H ;AN000;; Special case for lead byte of 05h
213 JNE WILDCRD2
;AN000;; Compare as normal if not an 05h
214 CMP BYTE PTR ES:[DI],0E5H ;AN000;; 05h and 0E5h equivalent for lead byte
215 JNE WILDCRD2
;AN000;; Compare as normal if not an 05h
216 DEC CX ;AN000;; One less byte to compare
217 INC SI ;AN000;; Bypass lead byte in source and
218 INC DI ;AN000;; destination when 05h and 0E5h found.
220 PUSH AX ;AN000;;KK. save ax
222 CMP CX,0 ;AN000;;KK. end of compare ?
223 JLE metaend2
;AN000;;KK. yes
224 MOV AL,[SI] ;AN000;;KK. is it a Kanji
225 invoke testkanj
;AN000;;KK.
226 JZ notdb
;AN000;;KK. no
227 MOV AX,'??' ;AN000;;KK.
228 CMP ES:[DI],AX ;AN000;;KK. is es:di pointing to '??'
229 JNZ metaend3
;AN000;;KK. no
231 ADD DI,2 ;AN000;;KK. update pointers and count
234 JMP cagain
;AN000;;KK.
235 metaend3: ;AN000;;KK.
237 JNZ metaend2
;AN000;;KK.
238 JMP subcx
;AN000;;KK.
240 CMPSB ;AN000;;KK. same code ?
241 JZ sameco
;AN000;;KK. yes
242 CMP BYTE PTR ES:[DI-1],"?" ;AN000;;KK. ?
243 JNZ metaend2
;AN000;;KK. no
245 DEC CX ;AN000;;KK. decrement count
246 JMP cagain
;AN000;;KK.
250 ;-------------------- End of DBCS ;AN000; KK.
254 JZ MetaRet
; most of the time we will fail.
256 CMP BYTE PTR ES:[DI-1],"?"
260 return
; Zero set, Match
263 Break <NEXTENTRY
-- STEP THROUGH DIRECTORY
>
266 ; Same as outputs of GETENTRY, above
268 ; Update BX, and [LASTENT] for next directory entry.
269 ; Carry set if no more.
272 DOSAssume
CS,<DS>,"NextEntry"
282 MOV BL,BYTE PTR [SECCLUSPOS
]
284 CMP BL,BYTE PTR [CLUSFAC
]
303 MOV BYTE PTR [SECCLUSPOS
],BL
308 MOV DX,WORD PTR [DI.buf_sector
+2] ;AN000; >32mb
309 MOV [HIGH_SECTOR
],DX ;AN000; >32mb
310 MOV DX,WORD PTR [DI.buf_sector
] ;AN000; >32mb
312 ADD DX,1 ;AN000; >32mb
313 ADC [HIGH_SECTOR
],0 ;AN000; >32mb
315 DOSAssume
CS,<DS>,"DIR/SameClus"
322 ; [LASTENT] has directory entry
323 ; ES:BP points to drive parameters
324 ; [DIRSEC],[CLUSNUM],[CLUSFAC],[ENTLAST] set for DIR involved
326 ; Locates directory entry in preparation for search
327 ; GETENT provides entry for passing desired entry in AX
329 ; [CURBUF+2]:BX = Pointer to next directory entry in CURBUF
330 ; [CURBUF+2]:DX = Pointer to first byte after end of CURBUF
331 ; [LASTENT] = New directory entry number
332 ; [NXTCLUSNUM],[SECCLUSPOS] set via DIRREAD
333 ; Carry set if error (currently user FAILed to I 24)
335 Procedure GETENTRY
,NEAR
336 DOSAssume
CS,<DS>,"GetEntry"
343 Assert ISDPB
,<ES,BP>,"GetEntry/GetEnt"
346 ; Convert the entry number in AX into a byte offset from the beginning of the
349 mov cl,5 ; shift left by 5 = mult by 32
350 rol ax,cl ; keep hight order bits
352 and ax, NOT (32-1) ; mask off high order bits
353 and dx, 32-1 ; mask off low order bits
355 ; DX:AX contain the byte offset of the required directory entry from the
356 ; beginning of the directory. Convert this to a sector number. Round the
357 ; sector size down to a multiple of 32.
359 MOV BX,ES:[BP.dpb_sector_size
]
360 AND BL,255-31 ; Must be multiple of 32
362 MOV BX,DX ; Position within sector
368 MOV DX,WORD PTR [CURBUF
]
371 ADD DX,ES:[BP.dpb_sector_size
] ; Always clears carry
375 Break <SETDIRSRCH SETROOTSRCH
-- Set Search environments
>
378 ; BX cluster number of start of directory
379 ; ES:BP Points to DPB
380 ; DI next cluster number from fastopen extended info. DOS 3.3 only
382 ; Set up a directory search
385 ; [CLUSFAC],[CLUSNUM],[SECCLUSPOS],[DIRSEC] set
386 ; Carry set if error (currently user FAILed to I 24)
390 DOSAssume
CS,<DS>,"SetDirSrch"
393 Assert ISDPB
,<ES,BP>,"SetDirSrch"
397 MOV AL,ES:[BP.dpb_cluster_mask
]
399 MOV BYTE PTR [CLUSFAC
],AL
400 ; DOS 3.3 for FastOPen F.C. 6/12/86
402 TEST [FastOpenFlg
],Lookup_Success
405 ; DOS 3.3 for FastOPen F.C. 6/12/86
415 MOV BYTE PTR [SECCLUSPOS
],BL
418 PUSH DX ;AN000; >32mb
419 MOV DX,[HIGH_SECTOR
] ;AN000; >32mb
420 MOV WORD PTR [DIRSEC
+2],DX ;AN000; >32mb
422 MOV WORD PTR [DIRSEC
],DX
427 DOSAssume
CS,<DS>,"SetRootSrch"
431 MOV BYTE PTR [SECCLUSPOS
],AL
434 MOV AX,ES:[BP.dpb_first_sector
]
435 MOV DX,ES:[BP.dpb_dir_sector
]
437 MOV BYTE PTR [CLUSFAC
],AL
438 MOV WORD PTR [DIRSEC
],DX ;F.C. >32mb
439 MOV WORD PTR [DIRSEC
+2],0 ;F.C. >32mb