Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
12 KiB

  1. page ,132
  2. ;/*
  3. ; * Microsoft Confidential
  4. ; * Copyright (C) Microsoft Corporation 1991
  5. ; * All Rights Reserved.
  6. ; */
  7. ;
  8. ; Revision History
  9. ; ================
  10. ;
  11. ;M031 SR 10/11/90 Bug #3069. Use deny write sharing mode to open files
  12. ; instead of compatibility mode. This gives lesser
  13. ; sharing violations when files are opened for read on
  14. ; a copy operation.
  15. ;
  16. ;
  17. .xlist
  18. .xcref
  19. include comsw.asm
  20. include dossym.inc
  21. include syscall.inc
  22. include sf.inc
  23. include comseg.asm
  24. include comequ.asm
  25. .list
  26. .cref
  27. TRANDATA segment public byte
  28. extrn FulDir_Ptr:word ;AN052;
  29. TRANDATA ends
  30. TRANSPACE segment public byte
  31. extrn Ascii:byte
  32. extrn Binary:byte
  33. extrn Concat:byte
  34. extrn DestBuf:byte
  35. extrn DestFcb:byte
  36. extrn DestInfo:byte
  37. extrn DestIsDir:byte
  38. extrn DestTail:word
  39. extrn DestVars:byte
  40. extrn DirBuf:byte
  41. extrn DirChar:byte
  42. extrn FirstDest:byte
  43. extrn Inexact:byte
  44. extrn MelCopy:byte
  45. extrn NxtAdd:word
  46. extrn Plus:byte
  47. extrn SDirBuf:byte
  48. extrn SrcInfo:byte
  49. extrn SrcXName:byte
  50. extrn Tpa:word
  51. extrn TrgXName:byte
  52. extrn UserDir1:byte
  53. TRANSPACE ends
  54. TRANCODE segment public byte
  55. extrn BadPath_Err:near ;AN022;
  56. extrn CopErr:near ;AN052;
  57. extrn Extend_Setup:near ;AN022;
  58. public BuildPath
  59. public SetStars
  60. public SetAsc
  61. ASSUME cs:TRANGROUP,ds:TRANGROUP,es:TRANGROUP,ss:NOTHING
  62. ;*** SetAsc - set Ascii, Binary, Inexact flags based on switches
  63. ;
  64. ; Given switch vector in AX,
  65. ; Set Ascii flag if /a is set
  66. ; Clear Ascii flag if /b is set
  67. ; Binary set if /b specified
  68. ; Leave Ascii unchanged if neither or both are set
  69. ; Also sets Inexact if Ascii is ever set.
  70. ; AL = Ascii on exit, flags set
  71. ;
  72. SetAsc:
  73. and al,SWITCHA+SWITCHB ; AL = /a, /b flags
  74. jpe LoadSw ; even parity - both or neither
  75. push ax
  76. and al,SWITCHB
  77. mov Binary,al
  78. pop ax
  79. and al,SWITCHA
  80. mov Ascii,al
  81. or Inexact,al
  82. LoadSw:
  83. mov al,Ascii
  84. or al,al
  85. return
  86. ;*** BuildDest
  87. public BuildDest
  88. BuildDest:
  89. cmp DestIsDir,-1
  90. jne KnowAboutDest ; figuring already done
  91. mov di,offset TRANGROUP:UserDir1
  92. mov bp,offset TRANGROUP:DestVars
  93. call BuildPath
  94. invoke RestUDir1
  95. ; We now know all about the destination.
  96. KnowAboutDest:
  97. xor al,al
  98. xchg al,FirstDest
  99. or al,al
  100. jnz FirstDst
  101. jmp NotFirstDest
  102. FirstDst:
  103. ; Create an fcb of the original dest.
  104. mov si,DestTail
  105. mov di,offset TRANGROUP:DestFcb
  106. mov ax,PARSE_FILE_DESCRIPTOR shl 8
  107. int 21h
  108. cmp byte ptr [si],0
  109. je GoodParse
  110. ;AD052; mov byte ptr [di+1],"|" ; must be illegal file name character
  111. mov dx,offset TRANGROUP:FulDir_Ptr ;AN052; issue "file creation error"
  112. jmp CopErr ;AN052;
  113. GoodParse:
  114. mov ax,word ptr DestBuf ; AX = possible "d:"
  115. cmp ah,':'
  116. je @f
  117. mov al,'@'
  118. @@:
  119. ; AX = "d:" for following FCB drive computation
  120. mov cl,Ascii ; CL = saved Ascii flag
  121. or al,20h
  122. sub al,60h
  123. mov DestFcb,al ; store drive # in FCB
  124. ;* Figure out what copy mode we're in.
  125. ; Letters stand for unambiguous, * for ambiguous pathnames.
  126. ; +n stands for additional sources delimited by +'s.
  127. ;
  128. ; copy a b not concatenating
  129. ; copy a * not concatenating
  130. ; copy * a concatenating
  131. ; copy * * not concatenating
  132. ; copy a+n b concatenating
  133. ; copy *+n a concatenating
  134. ; copy *+n * concatenating, Mel Hallorman style
  135. ; Bugbug: copy *.a+a.b *.t picks up only 1st *.a file.. Why?
  136. ; copy a.b+*.a *.t picks up all *.a files.
  137. mov al,DestInfo ; AL = destination CParse flags
  138. mov ah,SrcInfo ; AH = source CParse flags
  139. and ax,0202h ; AH,AL = source,dest wildcard flags
  140. or al,al
  141. jz NotMelCopy ; no destination wildcard
  142. ; Destination is wildcarded.
  143. cmp al,ah
  144. jne NotMelCopy ; no source wildcard
  145. ; Source and destination are both wildcarded.
  146. cmp Plus,0
  147. je NotMelCopy ; no +'s in source
  148. ; Source and destination are wildcarded, and source includes +'s.
  149. ; It's Mel Hallorman copy time.
  150. inc MelCopy ; 'Mel copy' = true
  151. xor al,al
  152. jmp short SetConc
  153. NotMelCopy:
  154. xor al,2 ; AL=0 -> ambiguous destination, 2 otherwise
  155. and al,ah
  156. shr al,1 ; AL=1 -> ambiguous source, unambiguous dest
  157. ; (implies concatenation)
  158. SetConc:
  159. or al,Plus ; "+" always infers concatenation
  160. ; Whew. AL = 1 if concatenating, 0 if not.
  161. mov Concat,al
  162. shl al,1
  163. shl al,1
  164. mov Inexact,al ; concatenation -> inexact copy
  165. cmp Binary,0
  166. jne NotFirstDest ; explicit binary copy
  167. mov Ascii,al ; otherwise, concatenate in ascii mode
  168. or cl,cl
  169. jnz NotFirstDest ; Ascii flag set before, data read correctly
  170. or al,al
  171. jz NotFirstDest ; Ascii flag did not change state
  172. ; At this point there may already be binary read data in the read
  173. ; buffer. We need to find the first ^Z (if there is one) and trim the
  174. ; amount of data in the buffer correctly.
  175. mov cx,NxtAdd
  176. jcxz NotFirstDest ; no data, everything ok
  177. mov al,1Ah
  178. push es
  179. xor di,di
  180. mov es,Tpa
  181. repne scasb ; scan for EOF
  182. pop es
  183. jne NotFirstDest ; no ^z in buffer, everything ok
  184. dec di ; point at ^z
  185. mov NxtAdd,di ; new buffer length
  186. NOTFIRSTDEST:
  187. mov bx,offset trangroup:DIRBUF+1 ; Source of replacement chars
  188. cmp CONCAT,0
  189. jz GOTCHRSRC ; Not a concat
  190. mov bx,offset trangroup:SDIRBUF+1 ; Source of replacement chars
  191. GOTCHRSRC:
  192. mov si,offset trangroup:DESTFCB+1 ; Original dest name
  193. mov di,DESTTAIL ; Where to put result
  194. public buildname
  195. BUILDNAME:
  196. ifdef DBCS ; ### if DBCS ###
  197. mov cx,8
  198. call make_name
  199. cmp byte ptr [si],' '
  200. jz @f ; if no extention
  201. mov al,dot_chr
  202. stosb
  203. mov cx,3
  204. call make_name
  205. @@:
  206. xor al,al
  207. stosb ; nul terminate
  208. return
  209. else ; ### if Not DBCS ###
  210. mov cx,8
  211. BUILDMAIN:
  212. lodsb
  213. cmp al,'?'
  214. jnz NOTAMBIG
  215. mov al,byte ptr [BX]
  216. NOTAMBIG:
  217. cmp al,' '
  218. jz NOSTORE
  219. stosb
  220. NOSTORE:
  221. inc bx
  222. loop BUILDMAIN
  223. mov cl,3
  224. mov al,' '
  225. cmp byte ptr [SI],al
  226. jz ENDDEST ; No extension
  227. mov al,dot_chr
  228. stosb
  229. BUILDEXT:
  230. lodsb
  231. cmp al,'?'
  232. jnz NOTAMBIGE
  233. mov al,byte ptr [BX]
  234. NOTAMBIGE:
  235. cmp al,' '
  236. jz NOSTOREE
  237. stosb
  238. NOSTOREE:
  239. inc bx
  240. loop BUILDEXT
  241. ENDDEST:
  242. xor al,al
  243. stosb ; NUL terminate
  244. return
  245. endif ; ### end if Not DBCS ###
  246. ifdef DBCS ; ### if DBCS ###
  247. make_name:
  248. mov ah,0 ; reset DBCS flag
  249. mov dh,cl ; save length to do
  250. mkname_loop:
  251. cmp ah,1 ; if it was lead byte
  252. jz mkname_dbcs
  253. mov ah,0 ; reset if it was single or tail byte
  254. mov al,[bx] ; get source char
  255. invoke testkanj
  256. jz mkname_load ; if not lead byte
  257. mkname_dbcs:
  258. inc ah ; set dbcs flag
  259. mkname_load:
  260. lodsb ; get raw char
  261. cmp al,'?'
  262. jnz mkname_store ; if not '?'
  263. cmp ah,0
  264. jz mkname_conv ; if source is single
  265. cmp ah,1
  266. jnz mkname_pass ; if source is not lead
  267. cmp cl,dh
  268. jnz mkname_lead ; if this is not 1st char
  269. cmp byte ptr [si],' '
  270. jz mkname_double ; if this is the end
  271. mkname_lead:
  272. cmp byte ptr [si],'?'
  273. jnz mkname_pass ; if no '?' for tail byte
  274. cmp cx,1
  275. jbe mkname_pass ; if no room for tail byte
  276. mkname_double:
  277. mov al,[bx]
  278. stosb
  279. inc bx
  280. inc si
  281. dec cx
  282. inc ah ; tail byte will be loaded
  283. mkname_conv:
  284. mov al,[bx]
  285. mkname_store:
  286. cmp al,' '
  287. jz mkname_pass
  288. stosb ; store in destination
  289. mkname_pass:
  290. inc bx
  291. loop mkname_loop
  292. return
  293. endif ; ### end if DBCS ###
  294. BUILDPATH:
  295. test [BP.INFO],2
  296. jnz NOTPFILE ; If ambig don't bother with open
  297. mov dx,bp
  298. add dx,BUF ; Set DX to spec
  299. push di ;AN000;
  300. MOV AX,EXTOPEN SHL 8 ;AC000; open the file
  301. mov bx,DENY_NONE or READ_OPEN_MODE ; open mode for COPY ;M046
  302. xor cx,cx ;AN000; no special files
  303. mov si,dx ;AN030; get file name offset
  304. mov dx,read_open_flag ;AN000; set up open flags
  305. INT 21h
  306. pop di ;AN000;
  307. jnc pure_file ;AN022; is pure file
  308. invoke get_ext_error_number ;AN022; get the extended error
  309. cmp ax,error_file_not_found ;AN022; if file not found - okay
  310. jz notpfile ;AN022;
  311. cmp ax,error_path_not_found ;AN022; if path not found - okay
  312. jz notpfile ;AN022;
  313. cmp ax,error_access_denied ;AN022; if access denied - okay
  314. jz notpfile ;AN022;
  315. jmp extend_setup ;AN022; exit with error
  316. pure_file:
  317. mov bx,ax ; Is pure file
  318. mov ax,IOCTL SHL 8
  319. INT 21h
  320. mov ah,CLOSE
  321. INT 21h
  322. test dl,devid_ISDEV
  323. jnz ISADEV ; If device, done
  324. test [BP.INFO],4
  325. jz ISSIMPFILE ; If no path seps, done
  326. NOTPFILE:
  327. mov dx,word ptr [BP.BUF]
  328. cmp dl,0 ;AN034; If no drive specified, get
  329. jz set_drive_spec ;AN034; default drive dir
  330. cmp dh,':'
  331. jz DRVSPEC5
  332. set_drive_spec: ;AN034;
  333. mov dl,'@'
  334. DRVSPEC5:
  335. or dl,20h
  336. sub dl,60h ; A = 1
  337. invoke SAVUDIR1
  338. jnc curdir_ok ;AN022; if error - exit
  339. invoke get_ext_error_number ;AN022; get the extended error
  340. jmp extend_setup ;AN022; exit with error
  341. curdir_ok: ;AN022;
  342. mov dx,bp
  343. add dx,BUF ; Set DX for upcomming CHDIRs
  344. mov bh,[BP.INFO]
  345. and bh,6
  346. cmp bh,6 ; Ambig and path ?
  347. jnz CHECKAMB ; jmp if no
  348. mov si,[BP.TTAIL]
  349. mov bl,':'
  350. cmp byte ptr [si-2],bl
  351. jnz KNOWNOTSPEC
  352. mov [BP.ISDIR],2 ; Know is d:/file
  353. jmp short DOPCDJ
  354. KNOWNOTSPEC:
  355. mov [BP.ISDIR],1 ; Know is path/file
  356. dec si ; Point to the /
  357. DOPCDJ:
  358. jmp DOPCD ;AC022; need long jump
  359. CHECKAMB:
  360. cmp bh,2
  361. jnz CHECKCD
  362. ISSIMPFILE:
  363. ISADEV:
  364. mov [BP.ISDIR],0 ; Know is file since ambig but no path
  365. return
  366. CHECKCD:
  367. invoke SETREST1
  368. mov ah,CHDIR
  369. INT 21h
  370. jc NOTPDIR
  371. mov di,dx
  372. xor ax,ax
  373. mov cx,ax
  374. dec cx
  375. Kloop: ;AN000; 3/3/KK
  376. MOV AL,ES:[DI] ;AN000; 3/3/KK
  377. INC DI ;AN000; 3/3/KK
  378. OR AL,AL ;AN000; 3/3/KK
  379. JZ Done ;AN000; 3/3/KK
  380. xor ah,ah ;AN000; 3/3/KK
  381. invoke Testkanj ;AN000; 3/3/KK
  382. JZ Kloop ;AN000; 3/3/KK
  383. INC DI ;AN000; 3/3/KK
  384. INC AH ;AN000; 3/3/KK
  385. jmp Kloop ;AN000; 3/3/KK
  386. Done: ;AN000; 3/3/KK
  387. dec di
  388. mov al,DIRCHAR
  389. mov [bp.ISDIR],2 ; assume d:/file
  390. OR AH, AH ;AN000; 3/3/KK
  391. JNZ Store_pchar ;AN000; 3/3/KK this is the trailing byte of ECS code
  392. cmp al,[di-1]
  393. jz GOTSRCSLSH
  394. Store_pchar: ;AN000; 3/3/KK
  395. stosb
  396. mov [bp.ISDIR],1 ; know path/file
  397. GOTSRCSLSH:
  398. or [bp.INFO],6
  399. call SETSTARS
  400. return
  401. NOTPDIR:
  402. invoke get_ext_error_number ;AN022; get the extended error
  403. cmp ax,error_path_not_found ;AN022; if path not found - okay
  404. jz notpdir_try ;AN022;
  405. cmp ax,error_access_denied ;AN022; if access denied - okay
  406. jnz extend_setupj ;AN022; otherwise - exit error
  407. notpdir_try: ;AN022;
  408. mov [bp.ISDIR],0 ; assume pure file
  409. mov bh,[bp.INFO]
  410. test bh,4
  411. retz ; Know pure file, no path seps
  412. mov [bp.ISDIR],2 ; assume d:/file
  413. mov si,[bp.TTAIL]
  414. cmp byte ptr [si],0
  415. jz BADCDERRJ2 ; Trailing '/'
  416. mov bl,dot_chr
  417. cmp byte ptr [si],bl
  418. jz BADCDERRJ2 ; If . or .. pure cd should have worked
  419. mov bl,':'
  420. cmp byte ptr [si-2],bl
  421. jz DOPCD ; Know d:/file
  422. mov [bp.ISDIR],1 ; Know path/file
  423. dec si ; Point at last '/'
  424. DOPCD:
  425. xor bl,bl
  426. xchg bl,[SI] ; Stick in a NUL
  427. invoke SETREST1
  428. CMP DX,SI ;AN000; 3/3/KK
  429. JAE LookBack ;AN000; 3/3/KK
  430. PUSH SI ;AN000; 3/3/KK
  431. PUSH CX ;AN000; 3/3/KK
  432. MOV CX,SI ;AN000; 3/3/KK
  433. MOV SI,DX ;AN000; 3/3/KK
  434. Kloop2: ;AN000; 3/3/KK
  435. LODSB ;AN000; 3/3/KK
  436. invoke TestKanj ;AN000; 3/3/KK
  437. jz NotKanj4 ;AN000; 3/3/KK
  438. LODSB ;AN000; 3/3/KK
  439. CMP SI,CX ;AN000; 3/3/KK
  440. JB Kloop2 ;AN000; 3/3/KK
  441. POP CX ;AN000; 3/3/KK
  442. POP SI ;AN000; 3/3/KK
  443. JMP SHORT DoCdr ;AN000; 3/3/KK Last char is ECS code, don't check for
  444. ; trailing path sep
  445. NotKanj4: ;AN000; 3/3/KK
  446. CMP SI,CX ;AN000; 3/3/KK
  447. JB Kloop2 ;AN000; 3/3/KK
  448. POP CX ;AN000; 3/3/KK
  449. POP SI ;AN000; 3/3/KK
  450. LookBack: ;AN000; 3/3/KK
  451. CMP BL,[SI-1] ; if double slash, then complain.
  452. JZ BadCDErrJ2
  453. DoCdr: ;AN000; 3/3/KK
  454. mov ah,CHDIR
  455. INT 21h
  456. xchg bl,[SI]
  457. retnc
  458. invoke get_ext_error_number ;AN022; get the extended error
  459. EXTEND_SETUPJ: ;AN022;
  460. JMP EXTEND_SETUP ;AN022; go issue the error message
  461. BADCDERRJ2:
  462. jmp badpath_err ;AC022; go issue path not found message
  463. SETSTARS:
  464. mov [bp.TTAIL],DI
  465. add [bp.SIZ],12
  466. mov ax,dot_qmark
  467. mov cx,8
  468. rep stosb
  469. xchg al,ah
  470. stosb
  471. xchg al,ah
  472. mov cl,3
  473. rep stosb
  474. xor al,al
  475. stosb
  476. return
  477. PUBLIC CompName
  478. COMPNAME:
  479. mov si,offset trangroup:DESTBUF ;g do name translate of target
  480. mov di,offset trangroup:TRGXNAME ;g save for name comparison
  481. mov ah,xnametrans ;g
  482. int 21h ;g
  483. MOV si,offset trangroup:SRCXNAME ;g get name translate of source
  484. MOV di,offset trangroup:TRGXNAME ;g get name translate of target
  485. invoke STRCOMP
  486. return
  487. TRANCODE ENDS
  488. END
  489.