]>
wirehaze git hosting - MS-DOS.git/blob - v4.0/src/DOS/RENAME.ASM
1 ; SCCSID = @(#)rename.asm 1.1 85/04/10
2 TITLE DOS_RENAME
- Internal RENAME
call for
MS-DOS
4 ; Low level routine for renaming files
8 ; Modification history:
10 ; Created: ARR 30 March 1983
14 ; get the appropriate segment definitions
19 CODE SEGMENT BYTE PUBLIC 'CODE'
20 ASSUME
SS:DOSGROUP
,CS:DOSGROUP
39 i_need CURR_DIR_END
,WORD
49 i_need EXTERR_LOCUS
,BYTE
53 ; [WFP_START] Points to SOURCE WFP string ("d:/" must be first 3
54 ; chars, NUL terminated)
55 ; [CURR_DIR_END] Points to end of Current dir part of string [SOURCE]
56 ; ( = -1 if current dir not involved, else
57 ; Points to first char after last "/" of current dir part)
58 ; [REN_WFP] Points to DEST WFP string ("d:/" must be first 3
59 ; chars, NUL terminated)
60 ; [THISCDS] Points to CDS being used
61 ; (Low word = -1 if NUL CDS (Net direct request))
62 ; [SATTRIB] Is attribute of search, determines what files can be found
64 ; Rename the specified file(s)
65 ; NOTE: This routine uses most of AUXSTACK as a temp buffer.
71 ; error_file_not_found
72 ; No match for source, or dest path invalid
73 ; error_not_same_device
74 ; Source and dest are on different devices
76 ; Directory specified (not simple rename),
77 ; Device name given, Destination exists.
78 ; NOTE: In third case some renames may have
80 ; error_path_not_found
81 ; Bad path (not in curr dir part if present)
84 ; Bad path in current directory part of path
86 ; error_sharing_violation
87 ; Deny both access required, generates an INT 24.
88 ; DS preserved, others destroyed
90 procedure DOS_RENAME
,NEAR
91 DOSAssume
CS,<DS>,"DOS_Rename"
96 ; invoke OWN_SHARE2 ;IFS. IFS owns share ? ;AN000;
97 ; JZ ifsshare ;IFS. yes ;AN000;
98 ; PUSH WORD PTR [DMAADD+2] ;IFS. save DMAADD ;AN000;
99 ; PUSH WORD PTR [DMAADD] ;IFS. ;AN000;
101 ; invoke IFS_SEARCH_FIRST ;IFS. search source name ;AN000;
102 ; JC nofiles ;IFS. not found ;AN000;
104 ; invoke IFS_REN_DEL_CHECK ;IFS. do share check ;AN000;
105 ; JNC share_okok ;IFS. share ok ;AN000;
106 ; MOV AX,error_sharing_violation ;IFS. share error ;AN000;
107 ; JMP SHORT nofiles ;IFS. ;AN000;
109 ; PUSH CS ;IFS. ;AN000;
110 ; POP ES ;IFS. ;AN000;
111 ; MOV SI,[REN_WFP] ;IFS. ds:si -> destination name ;AN000;
112 ; MOV BX,SI ;IFS. ;AN000;
113 fndnxt: ;IFS. ;AN000;
114 ; LODSB ;IFS. ;AN000;
115 ; CMP AL,0 ;IFS. ;AN000;
116 ; JNZ fndnxt ;IFS. ;AN000;
117 ; MOV DI,SI ;IFS. es:di -> end of destinatio ;AN000;
118 ; ADD BX,2 ;IFS. ;AN000;
119 ; invoke SkipBack ;IFS. ;AN000;
120 ; INC DI ;IFS. es:di -> last component of ;AN000;
121 ; MOV SI,DI ;IFS. dstination ;AN000;
122 ; MOV BX,[SAVE_BX] ;IFS. ds:bx -> last component of ;AN000;
123 ; CALL NEW_RENAME ;IFS. source ;AN000;
124 ; MOV AX,(multNET SHL 8) OR 17 ;IFS. replace ? chars with ;AN000;
125 ; INT 2FH ;IFS. source and issue RENAME ;AN000;
126 ; JC nofiles ;IFS. error ;AN000;
127 ; invoke DOS_SEARCH_NEXT ;IFS. serch next source ;AN000;
128 ; JNC rename_next_file ;IFS. rename next ;AN000;
129 ; CLC ;IFS. no more files ;AN000;
131 ; POP WORD PTR [DMAADD] ;IFS. restore DMAADD ;AN000;
132 ; POP WORD PTR [DMAADD+2] ;IFS. ;AN000;
133 ; ret ;IFS. return ;AN000;
139 MOV AX,(multNET
SHL 8) OR 17
145 MOV [EXTERR_LOCUS
],errLOC_Disk
150 OR AX,2020H
; Lower case
153 MOV AX,error_not_same_device
158 PUSH WORD PTR [DMAADD
+2]
159 PUSH WORD PTR [DMAADD
]
160 MOV WORD PTR [DMAADD
+2],DS
161 MOV WORD PTR [DMAADD
],OFFSET DOSGROUP
:RENAMEDMA
162 MOV [Found_dev
],0 ; Rename fails on DEVS, assume not a dev
164 invoke DOS_SEARCH_FIRST
; Sets [NoSetDir] to 1, [CURBUF+2]:BX
167 CMP AX,error_no_more_files
169 MOV AX,error_file_not_found
173 POP WORD PTR [DMAADD
]
174 POP WORD PTR [DMAADD
+2]
179 MOV AX,error_access_denied
; Assume error
181 PUSH DS ;PTM. ;AN000;
182 LDS SI,[DMAADD
] ;PTM. chek if source a dir ;AN000;
183 ADD SI,find_buf_attr
;PTM. ;AN000;
184 TEST [SI.dir_attr
],attr_directory
;PTM. ;AN000;
185 JZ notdir
;PTM. ;AN000;
186 MOV SI,[REN_WFP
] ;PTM. if yes, make sure path ;AN000;
187 invoke Check_Pathlen2
;PTM. length < 67 ;AN000;
190 JA GOTERR
;PTM. ;AN000;
194 ; At this point a source has been found. There is search continuation info (a
195 ; la DOS_SEARCH_NEXT) for the source at RENAMEDMA, together with the first
196 ; directory entry found.
197 ; [THISCDS], [THISDPB], and [THISDRV] are set and will remain correct
198 ; throughout the RENAME since it is known at this point that the source and
199 ; destination are both on the same device.
200 ; [SATTRIB] is also set.
205 MOV AX,error_sharing_violation
208 REN_OK1: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
209 invoke FastOpen_Delete
; delete dir info in fastopen DOS 3.3
210 MOV SI,[REN_WFP
] ; Swap source and destination
212 MOV [CURR_DIR_END
],-1 ; No current dir on dest
213 MOV WORD PTR [CREATING
],0E5FFH ; Creating, not DEL *.*
214 ; A rename is like a CREATE_NEW as far
215 ; as the destination is concerned.
217 ; If this Getpath fails due to file not found, we know all renames will work
218 ; since no files match the destination name. If it fails for any other
219 ; reason, the rename fails on a path not found, or whatever (also fails if
220 ; we find a device or directory). If the Getpath succeeds, we aren't sure
221 ; if the rename should fail because we haven't built an explicit name by
222 ; substituting for the meta chars in it. In this case the destination file
223 ; spec with metas is in [NAME1] and the explicit source name is at RENAMEDMA
224 ; in the directory entry part.
226 ;; JZ BAD_ACC ; Dest string is a directory ;AC000;
228 JNS SAVEDEST
; No, continue
230 MOV AX,error_access_denied
233 PUSHF ; Save carry state
234 PUSH AX ; and error code (if carry set)
239 JNZ BAD_ERR
; User FAILed to I 24
245 MOV AX,error_path_not_found
251 JNZ BAD_PATH
; Search for dest failed because user FAILed on
256 MOV AX,error_path_not_found
262 MOV DI,OFFSET DOSGROUP
:NAME2
263 MOV SI,OFFSET DOSGROUP
:NAME1
265 REP MOVSB ; Save dest with metas at NAME2
269 Context
ES ; needed due to JMP BUILDDEST below
270 MOV BX,OFFSET DOSGROUP
:RENAMEDMA
+ 21 ; Source of replace chars
271 MOV DI,OFFSET DOSGROUP
:NAME1
; Real dest name goes here
272 MOV SI,OFFSET DOSGROUP
:NAME2
; Raw dest
274 CALL NEW_RENAME
;IFS. replace ? chars ;AN000;
276 MOV [ATTRIB
],attr_all
; Stop duplicates with any attributes
278 invoke DEVNAME
; Check if we built a device name
283 invoke SetDirSrch
; Reset search to start of dir
284 JC BAD_ACC
; Screw up
285 invoke FINDENTRY
; See if new name already exists
286 JNC BAD_ACC
; Error if found
288 JNZ BAD_ACCJ
; Find failed because user FAILed to I 24
289 MOV AX,[DESTSTART
] ; DIRSTART of dest
290 CMP AX,WORD PTR [RENAMEDMA
+ 15] ; DIRSTART of source
291 JZ SIMPLE_RENAME
; If =, just give new name
293 MOV AL,[RENAMEDMA
+ 21 + dir_attr
]
294 TEST AL,attr_directory
295 JNZ BAD_ACCJ
; Can only do a simple rename on dirs,
296 ; otherwise the . and .. entries get
299 MOV WORD PTR [THISSFT
+2],DS
300 MOV SI,OFFSET DOSGROUP
:AUXSTACK
- SIZE SF_ENTRY
301 MOV WORD PTR [THISSFT
],SI
302 MOV [SI].sf_mode
,sharing_compat
+open_for_both
303 XOR CX,CX ; Set "device ID" for call into makenode
304 invoke RENAME_MAKE
; This is in mknode
311 LES DI,ThisSFT
; Rename_make entered this into sharing
312 Invoke ShareEnd
; we need to remove it.
314 ; A zero length entry with the correct new name has now been made at
317 Assert ISBUF
,<ES,DI>,"Got_Dest"
319 TEST ES:[DI.buf_flags
],buf_dirty
;LB. if already dirty ;AN000;
320 JNZ yesdirty
;LB. don't increment dirty count ;AN000;
321 invoke INC_DIRTY_COUNT
;LB. ;AN000;
322 OR ES:[DI.buf_flags
],buf_dirty
325 ADD DI,dir_attr
; Skip name
326 MOV SI,OFFSET DOSGROUP
:RENAMEDMA
+ 21 + dir_attr
327 MOV CX,(SIZE dir_entry
) - dir_attr
332 MOV ES,WORD PTR [CURBUF
+2]
334 STOSB ; "free" the source
338 CALL GET_SOURCE
; Get the source back
341 MOV ES,WORD PTR [CURBUF
+2]
342 MOV SI,OFFSET DOSGROUP
:NAME1
; New Name
346 MOV DI,WORD PTR [CURBUF
]
348 TEST ES:[DI.buf_flags
],buf_dirty
;LB. if already dirty ;AN000;
349 JNZ yesdirty2
;LB. don't increment dirty count ;AN000;
350 invoke INC_DIRTY_COUNT
;LB. ;AN000;
351 OR ES:[DI.buf_flags
],buf_dirty
353 Assert ISBUF
,<ES,DI>,"Dirty_it"
355 MOV SI,OFFSET DOSGROUP
:RENAMEDMA
+ 1 ;Name
357 ; WARNING! Rename_Next leaves the disk critical section *ALWAYS*. We need
358 ; to enter it before going to RENAME_Next.
361 MOV [CREATING
],0 ; Correct setting for search (we changed it
362 ; to FF when we made the prev new file).
365 ; Note, now, that we have exited the previous ENTER and so are back to where
369 LEA SI,[BX].dir_First
372 MOV AX,error_sharing_violation
375 REN_OK2: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376 invoke FastOpen_Delete
; delete dir info in fastopen DOS 3.3
384 ; RENAMEDMA has source info
389 ; [CURBUF+2]:BX points to entry
390 ; Carry set if error (currently user FAILed to I 24)
391 ; DS preserved, others destroyed
394 DOSAssume
CS,<DS>,"Get_Source"
397 MOV BX,WORD PTR [RENAMEDMA
+ 15] ; DirStart
402 MOV AX,WORD PTR [RENAMEDMA
+ 13] ; Lastent
408 ;Input: DS:SI -> raw string with ?
409 ; ES:DI -> destination string
410 ; DS:BX -> source string
411 ;Function: replace ? chars of raw string with chars in source string and
412 ; put in destination string
413 ;Output: ES:DI-> new string
417 procedure NEW_RENAME
,NEAR
418 DOSAssume
CS,<DS>,"DOS_Rename"
424 MOV AL,[BX] ; Get replace char
427 INC BX ; Next replace char