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.

344 lines
7.7 KiB

  1. page ,132
  2. ;/*
  3. ; * Microsoft Confidential
  4. ; * Copyright (C) Microsoft Corporation 1991
  5. ; * All Rights Reserved.
  6. ; */
  7. .xlist
  8. .xcref
  9. include comsw.asm
  10. include dossym.inc
  11. include syscall.inc
  12. include sf.inc
  13. include comseg.asm
  14. include comequ.asm
  15. .list
  16. .cref
  17. TRANDATA segment public byte
  18. extrn DevWMes_Ptr:word
  19. extrn Extend_Buf_Sub:byte
  20. extrn LostErr_Ptr:word
  21. extrn NoSpace_Ptr:word
  22. extrn Overwr_Ptr:word
  23. TRANDATA ends
  24. TRANSPACE segment public byte
  25. extrn Ascii:byte
  26. extrn Binary:byte
  27. extrn CFlag:byte
  28. extrn Concat:byte
  29. extrn DestBuf:byte
  30. extrn DestClosed:byte
  31. extrn DestHand:word
  32. extrn DestIsDev:byte
  33. extrn DestSwitch:word
  34. extrn Inexact:byte
  35. extrn NoWrite:byte
  36. extrn NxtAdd:word
  37. extrn OCtrlZ:byte
  38. extrn OFilePtr_Hi:word
  39. extrn OFilePtr_Lo:word
  40. extrn Plus_Comma:byte
  41. extrn RdEof:byte
  42. extrn SrcIsDev:byte
  43. extrn String_Ptr_2:word
  44. extrn TermRead:byte
  45. extrn Tpa:word
  46. extrn Written:word
  47. TRANSPACE ends
  48. TRANCODE segment public byte
  49. extrn EndCopy:near
  50. public FlshFil
  51. public TryFlush
  52. assume cs:TRANGROUP,ds:TRANGROUP,es:TRANGROUP,ss:NOTHING
  53. ;*** TryFlush - flush copy buffer, double-check for concatenation
  54. ;
  55. ; EXIT ZR set if concatenate flag unchanged
  56. TryFlush:
  57. mov al,Concat
  58. push ax
  59. call FlshFil
  60. pop ax
  61. cmp al,Concat
  62. return
  63. ;*** Flshfil - write out any data remaining in copy buffer.
  64. ;
  65. ; Inputs:
  66. ; [NXTADD] = No. of bytes to write
  67. ; [CFLAG] <> 0 if file has been created
  68. ; Outputs:
  69. ; [NXTADD] = 0
  70. FlshFil:
  71. mov TermRead,0
  72. cmp CFlag,0
  73. je NotExists
  74. jmp Exists
  75. NotExists:
  76. invoke BuildDest ; find out all about the destination
  77. invoke CompName ; source and dest. the same?
  78. jne ProcDest ; if not, go ahead
  79. cmp SrcIsDev,0
  80. jne ProcDest ; same name on device ok
  81. cmp Concat,0 ; concatenation?
  82. mov dx,offset TRANGROUP:Overwr_Ptr
  83. jne No_Concat_Err ; concatenating
  84. jmp CopErr ; not concatenating - overwrite error
  85. No_Concat_Err:
  86. mov NoWrite,1 ; flag not writing (just seeking)
  87. ProcDest:
  88. mov ax,EXTOPEN shl 8 ; open the file
  89. mov si,offset TRANGROUP:DestBuf ; get file name
  90. ;M046
  91. ; For writes, we want to deny writes by anyone else at the same time that we
  92. ;are writing to it. For instance, on a network, 2 workstations could try
  93. ;writing to the same file. Also, because we opened the source file with
  94. ;DENY NONE, it is fine if the source and destination files are the same as
  95. ;would happen when we append to an existing file.
  96. ;
  97. mov bx,DENY_WRITE or WRITE_OPEN_MODE;get open mode for copy; M046
  98. xor cx,cx ; no special files
  99. mov dx,WRITE_OPEN_FLAG ; set up open flags
  100. cmp NoWrite,0
  101. jne DoDestOpen ; don't actually create if nowrite set
  102. mov dx,CREAT_OPEN_FLAG ; set up create flags
  103. DoDestOpen:
  104. int 21h
  105. ; We assume that the error is normal.
  106. ; TriageError will correct the DX value appropriately.
  107. jnc Dest_Open_Okay ;AC030;
  108. Xa_Set_Error: ;AN030; error occurred on XA
  109. invoke Set_Ext_Error_Msg ;AN030; get extended error
  110. Ext_Err_Set: ;AN030;
  111. mov String_Ptr_2,offset TRANGROUP:DestBuf ;AN000; get address of failed string
  112. mov Extend_Buf_Sub,ONE_SUBST ;AN030; put number of subst in control block
  113. CopErrJ2: ;AN030;
  114. jmp CopErr ;AN030; go issue message
  115. Dest_Open_Okay: ;AC030
  116. mov DestHand,ax ; save handle
  117. mov CFlag,1 ; destination now exists
  118. mov bx,ax
  119. mov ax,(IOCTL shl 8)
  120. int 21h ; get device stuff
  121. mov DestIsDev,dl ; set dest info
  122. test dl,DEVID_ISDEV
  123. jz Exists ;AC030; Dest not a device
  124. ; Destination is device.
  125. mov al,byte ptr DestSwitch
  126. and al,SWITCHA+SWITCHB
  127. jnz TestBoth
  128. mov al,Ascii ; neither set, use current setting
  129. or al,Binary
  130. jz ExSetA ; neither set, default to ascii
  131. TestBoth:
  132. jpe Exists ; both are set, ignore
  133. test al,SWITCHB
  134. jz Exists ; leave in cooked mode
  135. mov ax,(IOCTL shl 8) or 1
  136. xor dh,dh
  137. or dl,DEVID_RAW
  138. mov DestIsDev,dl ; new value
  139. int 21h ; set device to raw mode
  140. jmp short Exists
  141. CopErrJ:
  142. jmp CopErr
  143. ExSetA:
  144. ; What we read in may have been in binary mode, flag zapped write OK
  145. mov Ascii,SWITCHA ; set ascii mode
  146. or Inexact,SWITCHA ; ascii -> inexact
  147. Exists:
  148. cmp NoWrite,0
  149. jne NoChecking ; if nowrite don't bother with name check
  150. cmp Plus_Comma,1 ;g don't check if just doing +,,
  151. je NoChecking ;g
  152. invoke CompName ; source and dest. the same?
  153. jne NoChecking ; if not, go ahead
  154. cmp SrcIsDev,0
  155. jne NoChecking ; same name on device ok
  156. ; At this point we know in append (would have gotten overwrite error
  157. ; on first destination create otherwise), and user trying to specify
  158. ; destination which has been scribbled already (if dest had been named
  159. ; first, NoWrite would be set).
  160. mov dx,offset TRANGROUP:LostErr_Ptr ; tell him he's not going to get it
  161. invoke Std_EprintF ;ac022;
  162. mov NxtAdd,0 ; set return
  163. inc TermRead ; tell read to give up
  164. Ret60:
  165. return
  166. NoChecking:
  167. mov bx,DestHand ; get handle
  168. xor cx,cx
  169. xchg cx,NxtAdd
  170. jcxz Ret60 ; if nothing to write, forget it
  171. inc Written ; flag that we wrote something
  172. cmp NoWrite,0 ; if nowrite set, just seek cx bytes
  173. jne SeekEnd
  174. xor dx,dx
  175. push ds
  176. mov ds,Tpa
  177. assume ds:NOTHING
  178. mov ah,WRITE
  179. int 21h
  180. pop ds
  181. assume ds:TRANGROUP
  182. mov dx,offset TRANGROUP:NoSpace_Ptr
  183. jnc @f
  184. jmp Xa_Set_Error ;AC022; failure
  185. @@: sub cx,ax
  186. retz ; wrote all supposed to
  187. test DestIsDev,DEVID_ISDEV
  188. jz CopErr ; is a file, error
  189. test DestIsDev,DEVID_RAW
  190. jnz DevWrtErr ; is a raw device, error
  191. cmp Inexact,0
  192. retnz ; inexact so ok
  193. dec cx
  194. retz ; wrote one byte less (the ^z)
  195. DevWrtErr:
  196. mov dx,offset TRANGROUP:DevWMes_Ptr
  197. jmp short CopErr
  198. SeekEnd:
  199. xor dx,dx ; zero high half of offset
  200. xchg dx,cx ; cx:dx is seek location
  201. mov ax,(LSEEK shl 8) or 1
  202. int 21h ; seek ahead in the file
  203. ; Save the file pointer in DX:AX to restore the file
  204. ; with in case the copy should fail.
  205. mov OFilePtr_Lo,ax
  206. mov OFilePtr_Hi,dx
  207. cmp RdEof,0
  208. retz ; EOF not read yet
  209. ; ^Z has been read - we must set the file size to the current
  210. ; file pointer location
  211. mov ah,WRITE
  212. int 21h ; cx is zero, truncates file
  213. jc Xa_Set_Error_Jmp ;AC022; failure
  214. ; Make note that ^Z was removed, in case the
  215. ; copy should fail and we need to restore the file.
  216. mov OCtrlZ,1Ah
  217. return
  218. public CopErr
  219. CopErr:
  220. invoke Std_EPrintF ;AC022;
  221. CopErrP:
  222. inc DestClosed
  223. cmp CFlag,0
  224. je EndCopyJ ; never actually got it open
  225. mov bx,DestHand
  226. cmp bx,0
  227. jle NoClose
  228. ; Check to see if we should save part of the destination file.
  229. mov cx,OFilePtr_Hi ; CX = hi word of original file ptr
  230. mov dx,OFilePtr_Lo ; DX = lo word of original file ptr
  231. mov ax,cx
  232. or ax,dx
  233. jz ceClose ; null file ptr means nothing to save
  234. ; Destination was also the first source. Do the best we can to
  235. ; restore it. Truncate it back to the size we took from it (which
  236. ; may have been due to a Ctrl-Z, so may not have included the whole
  237. ; file). If a Ctrl-Z was originally read, put it back.
  238. mov ax,LSEEK shl 8
  239. int 21h
  240. xor cx,cx ; CX = # bytes to write = 0
  241. mov ah,WRITE
  242. int 21h ; truncate file
  243. cmp OCtrlZ,0
  244. je @f ; no ctrl-z removed from original
  245. inc cx ; CX = # bytes to write = 1
  246. mov dx,offset TRANGROUP:OCtrlZ ; DS:DX = ptr to original ctrl-z
  247. mov ah,WRITE
  248. int 21h ; write ctrl-z
  249. @@:
  250. mov ah,CLOSE
  251. int 21h ; close it
  252. ;; mov CFlag,0
  253. jmp EndCopy ; and go home
  254. ceClose:
  255. mov ah,CLOSE ; close the file
  256. int 21h
  257. NoClose:
  258. mov dx,offset TRANGROUP:DestBuf
  259. mov ah,UNLINK
  260. int 21h ; and delete it
  261. mov CFlag,0
  262. EndCopyJ:
  263. jmp EndCopy
  264. Xa_Set_Error_Jmp: ;AN022; go set up error message
  265. jmp Xa_Set_Error ;AN022;
  266. TRANCODE ends
  267. end
  268.