1 TITLE DIRCALL
- Directory manipulation internal calls
11 CODE SEGMENT BYTE PUBLIC 'CODE'
12 ASSUME
SS:DOSGROUP
,CS:DOSGROUP
37 i_need SWITCH_CHARACTER
,BYTE
39 extrn sys_ret_ok
:near,sys_ret_err
:near
43 BREAK <$MkDir
- Make a directory
entry>
45 NODEEXISTSJ: JMP NODEEXISTS
47 ASSUME
DS:NOTHING
,ES:NOTHING
50 ; DS:DX Points to asciz name
52 ; Make a new directory
55 ; AX = mkdir_path_not_found if path bad
56 ; AX = mkdir_access_denied If
57 ; Directory cannot be created
60 ; Disk or directory(root) full
64 MOV WORD PTR [THISFCB
+2],SS
65 MOV WORD PTR [THISFCB
],OFFSET DOSGROUP
:AUXSTACK
-40 ; Scratch space
67 MOV WORD PTR [CREATING
],0E500h
70 MOV AL,mkdir_path_not_found
76 PUSH SI ; Pointer to fcb_FIRCLUS
77 PUSH [DI.BUFSECNO
] ; Sector of new node
81 PUSH [DIRSTART
] ; Parent for .. entry
83 MOV [DIRSTART
],AX ; Null directory
85 JC NODEEXISTSPOPDEL
; No room
86 invoke GETENT
; First entry
88 MOV ES:[DI.BUFDIRTY
],1
89 ADD DI,BUFINSIZ
; Point at buffer
92 MOV DX,[DIRSTART
] ; Point at itself
106 POP SI ; fcb_Firclus pointer
117 MOV AL,ES:[BP.dpb_drive
]
124 POP DX ; Entry sector
130 POP SI ; dir_first pointer
132 SUB SI,dir_first
; Point back to start of dir entry
133 MOV BYTE PTR [SI],0E5H ; Free the entry
136 MOV AL,mkdir_access_denied
141 BREAK <$ChDir
-- Change current directory
on a drive
>
142 procedure $CHDIR
,NEAR
143 ASSUME
DS:NOTHING
,ES:NOTHING
146 ; DS:DX Points to asciz name
148 ; Change current directory
151 ; AX = chdir_path_not_found if error
165 XCHG BX,ES:[BP.dpb_current_dir
]
184 JMP SHORT COPYTHESTRINGBXZ
186 OR BX,BX ; Previous path root?
187 JZ COPYTHESTRING
; Yes
190 CMP BYTE PTR ES:[DI],0
197 CMP AL,[switch_character
]
199 MOV AL,'\' ; Use the alternate character
209 error error_path_not_found
240 STOSB ; Correctly terminate the path
241 MOV ES:[BP.dpb_current_dir],-1 ; Force re-validation
242 JMP SHORT PATHTOOLONG
246 OR AL,AL ; Check for null
249 JNZ COPYTHESTRING ; eat ./
250 CALL DELELMES ; have ..
252 OR AL,AL ; Check for null
254 JMP SHORT COPYTHESTRING
256 ; Copy one element from DS:SI to ES:DI include trailing / not trailing null
257 ; LODSB has already been done
259 PUSH DI ; Save in case too long
261 MOV CX,800h ; length of filename
262 MOV AH,'.' ; char to stop on
263 CALL CopyPiece ; go for it!
264 CALL BXCHK ; did we go over?
265 JAE POPCXDI ; yep, go home
266 CMP AH,AL ; did we stop on .?
267 JZ CopyExt ; yes, go copy ext
268 OR AL,AL ; did we end on nul?
269 JZ DECSIRet ; yes, bye
271 STOSB ; save the path char
272 CALL INCBXCHK ; was there room for it?
274 INC SI ; guard against following dec
276 DEC SI ; point back at null
278 POP AX ; toss away saved DI
282 POP DI ; point back...
286 CALL INCBXCHK ; room?
288 LODSB ; get next char
290 MOV CX,300h ; at most 3 chars
291 CALL CopyPiece ; go copy it
292 CALL BXCHK ; did we go over
294 OR AL,AL ; sucessful end?
296 JMP CopyPathEnd ; go stash path char
299 ; Delete one path element from ES:DI
323 MOV DX,DI ; Point to char after '/'
330 SUB AX,DI ; Distance moved
331 SUB BX,AX ; Set correct BX
350 DEC DI ; Back up over trailing /
355 ; copy a piece CH chars max until the char in AH (or path or NUL)
357 STOSB ; store the character
358 INC CL ; moved a byte
359 CALL INCBXCHK ; room enough?
360 JAE CopyPieceRet ; no, pop CX and DI
361 OR AL,AL ; end of string?
362 JZ CopyPieceRet ; yes, dec si and return
365 CALL TestKanj ; was it kanji?
367 MOVSB ; move the next byte
368 CALL INCBXCHK ; room for it?
369 JAE CopyPieceRet ; nope
370 INC CL ; moved a byte
374 CMP CL,CH ; move too many?
375 JBE CopyPieceNext ; nope
378 CALL TestKanj ; was the last byte kanji
379 JZ NotKanj2 ; no only single byte backup
380 DEC DI ; back up a char
385 DEC DI ; back up a char
388 LODSB ; get next character
389 invoke PathChrCmp ; end of road?
390 JZ CopyPieceRet ; yep, return and don't dec SI
391 CMP AL,AH ; end of filename?
392 JNZ CopyPiece ; go do name
398 BREAK <$RmDir -- Remove a directory>
401 procedure $RMDIR,NEAR ; System call 47
402 ASSUME DS:NOTHING,ES:NOTHING
405 ; DS:DX Points to asciz name
407 ; Delete directory if empty
410 ; AX = rmdir_path_not_found If path bad
411 ; AX = rmdir_access_denied If
412 ; Directory not empty
414 ; Root directory specified
415 ; Directory malformed (. and .. not first two entries)
416 ; AX = rmdir_current_directory
428 MOV CX,ES:[BP.dpb_current_dir]
430 JNZ rmdir_current_dir_check
432 invoke Get_user_stack
441 error error_access_denied
443 rmdir_current_dir_check:
446 error error_current_directory
452 PUSH BX ; Save entry pointer
453 PUSH [DI.BUFSECNO] ; Save sector number
459 MOV DI,OFFSET DOSGROUP:NAME1
467 MOV DS,WORD PTR [CURBUF+2]
471 CMP AX,(' ' SHL 8) OR '.'
475 CMP AX,('.' SHL 8) OR '.'
480 MOV [LASTENT],2 ; Skip . and ..
482 MOV [ATTRIB],attr_directory+attr_hidden+attr_system
495 MOV BYTE PTR [BX],0E5H ; Free the entry
499 error error_path_not_found