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.

705 lines
16 KiB

  1. ;/*
  2. ; * Microsoft Confidential
  3. ; * Copyright (C) Microsoft Corporation 1991
  4. ; * All Rights Reserved.
  5. ; */
  6. ; SCCSID = @(#)forproc.asm 1.2 85/07/25
  7. .xlist
  8. .xcref
  9. BREAK MACRO subtitle
  10. SUBTTL subtitle
  11. PAGE
  12. ENDM
  13. include bpb.inc
  14. INCLUDE FORCHNG.INC
  15. INCLUDE SYSCALL.INC
  16. INCLUDE FOREQU.INC
  17. INCLUDE FORMACRO.INC
  18. INCLUDE FORSWTCH.INC
  19. INCLUDE IOCTL.INC
  20. .cref
  21. .list
  22. data segment public para 'DATA'
  23. data ends
  24. code segment public para 'CODE'
  25. assume cs:code,ds:data
  26. PUBLIC FormatAnother?,Yes?,REPORT,USER_STRING
  27. public fdsksiz,fdsksizM100s,badsiz,badsizM100s
  28. public syssiz,datasiz,datasizM100s,biosiz
  29. public AllocSize,AllocNum,MegSizes
  30. public Get_Free_Space
  31. extrn std_printf:near,crlf:near,PrintString:near
  32. extrn Multiply_32_Bits:near
  33. extrn AddToSystemSize:near
  34. ;No more SAFE module
  35. ; EXTRN UpdateSystemSize:NEAR
  36. data segment public para 'DATA'
  37. extrn driveLetter:byte
  38. extrn msgInsertDisk:byte
  39. extrn msgFormatAnother?:byte
  40. extrn msgQuickFormatAnother?:byte
  41. extrn msgTotalDiskSpace:byte
  42. extrn msgTotalDiskSpaceMeg:byte
  43. extrn msgSystemSpace:byte
  44. extrn msgBadSpace:byte
  45. extrn msgBadSpaceMeg:byte
  46. extrn msgDataSpace:byte
  47. extrn msgDataSpaceMeg:byte
  48. extrn Read_Write_Relative:byte
  49. extrn msgAllocSize:byte
  50. extrn MsgAllocNum:Byte
  51. extrn deviceParameters:byte
  52. EXTRN fBig32Fat:BYTE
  53. extrn bios:byte
  54. extrn dos:byte
  55. extrn command:byte
  56. IFDEF DBLSPACE_HOOKS
  57. extrn DblSpaceBin:byte
  58. ENDIF
  59. extrn Serial_Num_Low:Word
  60. extrn Serial_Num_High:Word
  61. extrn msgSerialNumber:Byte
  62. extrn SwitchMap:Word
  63. extrn SwitchCopy:Word
  64. extrn inbuff:byte
  65. MegSizes db 0
  66. fdsksiz dd 0
  67. fdsksizM100s dw 0
  68. syssiz dd 0
  69. biosiz dd 0
  70. badsiz dd 0
  71. badsizM100s dw 0
  72. datasiz dd 0
  73. datasizM100s dw 0
  74. AllocSize dd 0
  75. AllocNum dd 0
  76. dw offset driveLetter
  77. ExtFreePacket ExtGetDskFreSpcStruc <>
  78. data ends
  79. ;***************************************************************************
  80. ; Wait for key. If yes return carry clear, else no. Insures
  81. ; explicit Y or N answer.
  82. ;***************************************************************************
  83. FormatAnother? proc near
  84. test SwitchCopy,SWITCH_Q ;use different message with /Q
  85. jz @F
  86. Message msgQuickFormatAnother?
  87. jmp SHORT CheckResponse
  88. @@:
  89. Message msgFormatAnother?
  90. CheckResponse:
  91. CALL Yes?
  92. pushf ; save result
  93. call CrLf ; send a new line
  94. popf ; retrieve the result
  95. jnc WAIT20
  96. jz Wait20
  97. JMP SHORT FormatAnother?
  98. WAIT20:
  99. RET
  100. FormatAnother? endp
  101. ;***************************************************************************
  102. ;Routine name:Yes?
  103. ;***************************************************************************
  104. ;
  105. ;Description: Validate that input is valid Y/N for the country dependent info
  106. ; Wait for key. If YES return carry clear,else carry set.
  107. ; If carry is set, Z is set if explicit NO, else key was not Yes or No.
  108. ;
  109. ;Called Procedures: Message (macro)
  110. ; User_String
  111. ;
  112. ;Change History: Created 4/32/87 MT
  113. ;
  114. ;Input: None
  115. ;
  116. ;Output: CY = 0 Yes is entered
  117. ; CY = 1, Z = No
  118. ; CY = 1, NZ = other
  119. ;
  120. ;Psuedocode
  121. ;----------
  122. ;
  123. ; Get input (CALL USER STRING)
  124. ; IF got character
  125. ; Check for country dependent Y/N (INT 21h, AX=6523h Get Ext Country)
  126. ; IF Yes
  127. ; clc
  128. ; ELSE (No)
  129. ; IF No
  130. ; stc
  131. ; Set Zero flag
  132. ; ELSE (Other)
  133. ; stc
  134. ; Set NZ
  135. ; ENDIF
  136. ; ENDIF
  137. ; ELSE (nothing entered)
  138. ; stc
  139. ; Set NZ flag
  140. ; ENDIF
  141. ; ret
  142. ;***************************************************************************
  143. Procedure YES?
  144. call User_String ;Get character
  145. jz $$IF1 ;Got one if returned NZ
  146. mov AL,23h ;See if it is Y/N
  147. mov dl,[InBuff+2] ;Get character
  148. DOS_Call GetExtCntry ;Get country info call
  149. cmp AX,Found_Yes ;Which one?
  150. jne $$IF2 ;Got a Yes
  151. clc ;Clear CY for return
  152. jmp SHORT $$EN2 ;Not a Yes
  153. $$IF2:
  154. cmp AX,Found_No ;Is it No?
  155. jne $$IF4 ;Yep
  156. stc ;Set CY for return
  157. jmp SHORT $$EN4 ;Something else we don't want
  158. $$IF4:
  159. xor AL,AL ;Set NZ flag for ret
  160. cmp AL,1 ; " " " "
  161. stc ;And CY flag for good measure
  162. $$EN4:
  163. $$EN2:
  164. jmp SHORT $$EN1 ;No char found at all
  165. $$IF1:
  166. xor AL,AL ;Set NZ flag for ret
  167. cmp AL,1
  168. stc ;And CY flag for good measure
  169. $$EN1:
  170. ret
  171. Yes? endp
  172. ;***************************************************************************
  173. ; Get a string from user. Z is set if user typed no chars (imm CR)
  174. ; We need to flush a second time to get rid of incoming Kanji characters also.
  175. ;***************************************************************************
  176. Procedure USER_STRING
  177. mov AX,(STD_CON_INPUT_FLUSH SHL 8) + 0 ; Clean out input
  178. int 21h
  179. mov DX,OFFSET InBuff
  180. mov AH,STD_CON_STRING_INPUT
  181. int 21h
  182. mov AX,(STD_CON_INPUT_FLUSH SHL 8) + 0 ; Clean out input
  183. int 21h
  184. cmp byte ptr [InBuff+1],0
  185. ret
  186. USER_STRING endp
  187. ;*********************************************
  188. ; Make a status report including the following information:
  189. ; Total disk capacity
  190. ; Total system area used
  191. ; Total bad space allocated
  192. ; Total data space available
  193. ; Number of allocation units
  194. ; Size of allocation units
  195. Procedure Report
  196. call crlf
  197. call Calc_System_Space ;calc system space
  198. call Calc_Total_Addressible_Space ;calc total space
  199. cmp MegSizes,0
  200. jne IsHuge3
  201. jmp NotHuge3
  202. IsHuge3:
  203. Message msgTotalDiskSpaceMeg
  204. ;call std_printf
  205. cmp word ptr SysSiz,0
  206. jnz SHOWSYSh
  207. cmp word ptr SysSiz+2,0
  208. jz CHKBADh
  209. ShowSysh:
  210. Message msgSystemSpace
  211. ;CALL std_printf
  212. ;Report space used by system
  213. ChkBadh:
  214. cmp word ptr BadSiz,0
  215. jnz ShowBadh
  216. cmp word ptr BadSiz+2,0
  217. jnz ShowBadh
  218. cmp BadSizM100s,0
  219. jz ShowDatah
  220. ShowBadh:
  221. Message msgBadSpaceMeg
  222. ;call std_printf
  223. ShowDatah:
  224. .386
  225. mov eax,SysSiz
  226. xor edx,edx
  227. mov ebx,1024*1024
  228. div ebx ;EAX is MEG, EDX remainder
  229. ;; push eax
  230. db 066h,050h
  231. ;;
  232. mov eax,edx
  233. xor edx,edx
  234. mov ebx,(1024 * 1024) / 100
  235. div ebx
  236. shr ebx,1
  237. cmp edx,ebx
  238. jb short NoRnd3
  239. inc eax
  240. NoRnd3:
  241. ;; pop ecx
  242. db 066h,059h
  243. ;;
  244. movzx ebx,BadSizM100s
  245. add eax,ebx
  246. add ecx,BadSiz ;ECX.EAX is bad+sys size in MEG
  247. mov ebx,Fdsksiz
  248. movzx edx,FdsksizM100s
  249. ChkBorrow:
  250. cmp edx,eax
  251. jae short NoSubAdj
  252. dec ebx
  253. add edx,100
  254. jmp short ChkBorrow
  255. NoSubAdj:
  256. sub edx,eax
  257. mov eax,edx
  258. sub ebx,ecx
  259. mov datasiz,ebx
  260. .8086
  261. mov datasizM100s,AX
  262. Message msgDataSpaceMeg ;call std_printf
  263. jmp short Huge3
  264. NotHuge3:
  265. Message msgTotalDiskSpace
  266. ;call std_printf
  267. cmp word ptr SysSiz,0
  268. jnz SHOWSYS
  269. cmp word ptr SysSiz+2,0
  270. jz CHKBAD
  271. ShowSys:
  272. Message msgSystemSpace
  273. ;CALL std_printf
  274. ;Report space used by system
  275. ChkBad:
  276. cmp word ptr BadSiz,0
  277. jnz ShowBad
  278. cmp word ptr BadSiz+2,0
  279. jz ShowData
  280. ShowBad:
  281. Message msgBadSpace
  282. ;call std_printf
  283. ShowData:
  284. mov CX,word ptr Fdsksiz
  285. mov BX,word ptr Fdsksiz+2
  286. sub CX,word ptr BadSiz
  287. sbb BX,word ptr BadSiz+2
  288. sub CX,word ptr SysSiz
  289. sbb BX,word ptr SysSiz+2
  290. mov word ptr datasiz,CX
  291. mov word ptr datasiz+2,BX
  292. Message msgDataSpace ;call std_printf
  293. Huge3:
  294. call crlf
  295. mov AX,deviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector ;
  296. mov CL,deviceParameters.DP_BPB.oldBPB.BPB_SectorsPerCluster ;
  297. .errnz EDP_BPB NE DP_BPB
  298. xor CH,CH
  299. mul CX ;Get bytes per alloc
  300. mov word ptr AllocSize,AX ;Save allocation size
  301. mov word ptr AllocSize+2,DX ; for message
  302. Message msgAllocSize ;Print size of cluster
  303. call Get_Free_Space ;get disk space
  304. .386
  305. mov AllocNum,EBX ;Put result in msg
  306. .8086
  307. Message msgAllocNum ; = cluster/disk
  308. call crlf
  309. test switchmap, SWITCH_8 ;If 8 tracks, don't display
  310. jnz NoSerialNumber ;serial number
  311. Message msgSerialNumber ;Spit out serial number
  312. call crlf
  313. NoSerialNumber:
  314. ret
  315. Report endp
  316. ;***************************************************************************
  317. ;Routine name: Read_Disk
  318. ;***************************************************************************
  319. ;
  320. ;description: Read in data using Generic IOCtl
  321. ;
  322. ;Called Procedures: None
  323. ;
  324. ;
  325. ;Change History: Created 5/13/87 MT
  326. ;
  327. ;Input: AL = Drive number (0=A)
  328. ; DS:BX = Transfer address
  329. ; CX = Number of sectors
  330. ; Read_Write_Relative.Start_Sector_High = Logical start sector high
  331. ; DX = logical start sector number low
  332. ;
  333. ;Output: CY if error
  334. ; AH = INT 25h error code
  335. ;
  336. ;Psuedocode
  337. ;----------
  338. ; Save registers
  339. ; Setup structure for function call
  340. ; Read the disk (AX=440Dh, CL = 6Fh)
  341. ; Restore registers
  342. ; ret
  343. ;***************************************************************************
  344. Procedure Read_Disk
  345. push BX ;Save registers
  346. push CX
  347. push DX
  348. push SI
  349. push DI
  350. push BP
  351. push ES
  352. push DS
  353. mov SI,data
  354. mov ES,SI
  355. assume ES:data,DS:nothing
  356. ;Get transfer buffer add
  357. mov ES:Read_Write_Relative.Buffer_Offset,BX
  358. mov BX,DS
  359. mov ES:Read_Write_Relative.Buffer_Segment,BX ;Get segment
  360. mov BX,data ;Point DS at parameter list
  361. mov DS,BX
  362. assume DS:data,ES:data
  363. mov Read_Write_Relative.Number_Sectors,CX ;Number of sec to read
  364. mov Read_Write_Relative.Start_Sector_Low,DX ;Start sector
  365. mov BX,offset Read_Write_Relative
  366. mov CX,0ffffh ;Read relative sector
  367. mov dl,al ;Drive # to DL
  368. inc dl ;1 based
  369. mov ax,(Get_Set_DriveInfo SHL 8) OR Ext_ABSDiskReadWrite
  370. mov si,0 ;READ
  371. int 21h ;Do the read
  372. pop DS
  373. pop ES
  374. pop BP
  375. pop DI
  376. pop SI
  377. pop DX ;Restore registers
  378. pop CX
  379. pop BX
  380. ret
  381. Read_Disk endp
  382. ;***************************************************************************
  383. ;Routine name: Write_Disk
  384. ;***************************************************************************
  385. ;
  386. ;description: Write Data using Generic IOCtl
  387. ;
  388. ;Called Procedures: None
  389. ;
  390. ;
  391. ;Change History: Created 5/13/87 MT
  392. ;
  393. ;Input: AL = Drive number (0=A)
  394. ; DS:BX = Transfer address
  395. ; CX = Number of sectors
  396. ; Read_Write_Relative.Start_Sector_High = Logical start sector high
  397. ; DX = logical start sector number low
  398. ;
  399. ;Output: CY if error
  400. ; AH = INT 26h error code
  401. ;
  402. ;Psuedocode
  403. ;----------
  404. ; Save registers
  405. ; Setup structure for function call
  406. ; Write to disk (AX=440Dh, CL = 4Fh)
  407. ; Restore registers
  408. ; ret
  409. ;***************************************************************************
  410. Procedure Write_Disk
  411. push BX ;Save registers
  412. push CX
  413. push DX
  414. push SI
  415. push DI
  416. push BP
  417. push ES
  418. push DS
  419. mov SI,data
  420. mov ES,SI
  421. assume ES:data, DS:nothing
  422. ;Get transfer buffer add
  423. mov ES:Read_Write_Relative.Buffer_Offset,BX
  424. mov BX,DS
  425. mov ES:Read_Write_Relative.Buffer_Segment,BX ;Get segment
  426. mov BX,data ;Point DS at parameter list
  427. mov DS,BX
  428. assume DS:data, ES:data
  429. mov Read_Write_Relative.Number_Sectors,CX ;Number of sec to write
  430. mov Read_Write_Relative.Start_Sector_Low,DX ;Start sector
  431. mov BX,offset Read_Write_Relative
  432. mov CX,0ffffh ;Write relative sector
  433. mov dl,al ;Drive # to DL
  434. inc dl ;1 based
  435. mov ax,(Get_Set_DriveInfo SHL 8) OR Ext_ABSDiskReadWrite
  436. mov si,1 ;WRITE
  437. int 21h ;Do the write
  438. pop DS
  439. pop ES
  440. pop BP
  441. pop DI
  442. pop SI
  443. pop DX ;Restore registers
  444. pop CX
  445. pop BX
  446. ret
  447. Write_Disk endp
  448. ;=========================================================================
  449. ; Calc_Total_Addressible_Space : Calculate the total space that is
  450. ; addressible on the the disk by DOS.
  451. ;
  452. ; Inputs : none
  453. ;
  454. ; Outputs : Fdsksiz - Size in bytes of the disk
  455. ;=========================================================================
  456. Procedure Calc_Total_Addressible_Space
  457. push AX ;save affected regs
  458. push DX
  459. push BX
  460. call Get_Free_Space ;get free disk space
  461. .386
  462. ;; Manual assemble to prevent compile warning
  463. ;; push EBX ;save avail. cluster
  464. ;; push EDX ;save total. cluster
  465. db 066h,053h
  466. db 066h,052h
  467. ;;
  468. movzx ecx,DeviceParameters.DP_BPB.oldBPB.BPB_SectorsPerCluster
  469. movzx eax,DeviceParameters.DP_BPB.oldBPB.BPB_BytesPerSector
  470. .errnz EDP_BPB NE DP_BPB
  471. mul ecx
  472. mov ecx,eax ;ECX = bytes/clus
  473. ;; Manual assemble to prevent compile warning
  474. ;; pop eax ;Recover Total Clus
  475. ;; push eax
  476. db 066h,058h
  477. db 066h,050h
  478. ;;
  479. mul ecx ;EDX:EAX = Total Bytes
  480. mov FdskSiz,eax
  481. or edx,edx ;Disk >= 4Gig?
  482. jz short NotHuge1 ;No
  483. mov MegSizes,1
  484. mov ebx,1024*1024
  485. div ebx ; EAX is MEG, EDX remainder
  486. mov FdskSiz,EAX
  487. mov eax,edx
  488. xor edx,edx
  489. mov ebx,(1024 * 1024) / 100
  490. div ebx
  491. shr ebx,1
  492. cmp edx,ebx
  493. jb short NoRnd1
  494. inc eax
  495. NoRnd1:
  496. mov fdsksizM100s,ax
  497. cmp eax,100
  498. jb short NotHuge1
  499. inc FdskSiz
  500. mov fdsksizM100s,0
  501. NotHuge1:
  502. ;; Manual assemble to prevent compile warning
  503. ;; pop EDX ;get total clusters
  504. ;; pop EBX ;get avail clusters
  505. db 066h,05Ah
  506. db 066h,05Bh
  507. ;;
  508. mov EAX,EDX ;get total clusters
  509. sub EAX,EBX ;get bad+sys clusters
  510. test fBig32FAT,0ffh
  511. jz short NotFAT32
  512. dec eax ;FAT32 volumes have one
  513. ; cluster allocated to the
  514. ; root dir
  515. NotFAT32:
  516. mul ecx ;EDX:EAX bad+sys bytes
  517. sub EAX,SysSiz ;Remove sys bytes
  518. sbb EDX,0
  519. mov ecx,edx
  520. or ecx,eax ;ECX != 0 if any bad clusters
  521. mov badsiz,EAX
  522. cmp MegSizes,0 ;Disk >= 4Gig?
  523. je short NotHuge2 ;No
  524. mov ebx,1024*1024
  525. div ebx ;EAX is MEG, EDX remainder
  526. mov badsiz,EAX
  527. mov eax,edx
  528. xor edx,edx
  529. mov ebx,(1024 * 1024) / 100
  530. div ebx
  531. shr ebx,1
  532. cmp edx,ebx
  533. jb short NoRnd2
  534. inc eax
  535. NoRnd2:
  536. mov badsizM100s,ax
  537. cmp eax,100
  538. jb short ChkZr
  539. inc badsiz
  540. mov badsizM100s,0
  541. ChkZr:
  542. cmp badsiz,0
  543. jnz short NotHuge2
  544. cmp badsizM100s,0
  545. jnz short NotHuge2
  546. or ecx,ecx ;Were there any bad clusters?
  547. jz short NotHuge2 ;No
  548. ;
  549. ; There WERE bad clusters, but there were less than .01 MEG worth of them.
  550. ; Need to cheat so that the displayed count is != 0
  551. ;
  552. inc badsizM100s
  553. NotHuge2:
  554. .8086
  555. pop BX
  556. pop DX ;restore regs
  557. pop AX
  558. ret
  559. Calc_Total_Addressible_Space endp
  560. ;=========================================================================
  561. ; Get_Free_Space : Get the free space on the disk.
  562. ;
  563. ; Inputs : none
  564. ;
  565. ; Outputs : EBX - Available space in clusters
  566. ; EDX - Total space in clusters
  567. ;=========================================================================
  568. Procedure Get_Free_Space
  569. .386
  570. push di
  571. xor ebx,ebx
  572. mov ax,(Get_Set_DriveInfo SHL 8) OR Get_ExtFreeSpace
  573. mov cx,SIZE ExtGetDskFreSpcStruc
  574. push ds
  575. pop es
  576. mov di,offset ExtFreePacket
  577. mov DX,offset DriveLetter
  578. int 21h
  579. mov edx,ebx
  580. jc short IsDone
  581. mov ebx,[di.ExtFree_AvailableClusters]
  582. mov edx,[di.ExtFree_TotalClusters]
  583. .8086
  584. IsDone:
  585. pop di
  586. ret
  587. Get_Free_Space endp
  588. ;=========================================================================
  589. ; Calc_System_Space : This routine calculates the space occupied by
  590. ; the system on the disk.
  591. ;
  592. ; Inputs : BIOS.FileSizeInBytes
  593. ; Command.FileSizeInBytes
  594. ;
  595. ; Outputs : SysSiz - Size of the system
  596. ;=========================================================================
  597. Procedure Calc_System_Space
  598. push AX ;save regs
  599. push DX
  600. mov word ptr SysSiz+0,00h ;clear variable
  601. mov word ptr SysSiz+2,00h
  602. mov AX,word ptr [Dos.FileSizeInBytes+0] ;get dos size
  603. mov DX,word ptr [Dos.FileSizeInBytes+2]
  604. call AddToSystemSize ;add in values
  605. mov AX,word ptr [Bios.FileSizeInBytes+0] ;get bios size
  606. mov DX,word ptr [Bios.FileSizeInBytes+2]
  607. call AddToSystemSize ;add in values
  608. mov AX,word ptr [Command.FileSizeInBytes+0] ;get command size
  609. mov DX,word ptr [Command.FileSizeInBytes+2]
  610. call AddToSystemSize ;add in values
  611. IFDEF DBLSPACE_HOOKS
  612. mov ax, word ptr [DblSpaceBin.FileSizeInBytes] ;get dblspace
  613. mov dx, word ptr [DblSpaceBin.FileSizeInBytes+2] ; size--may be
  614. call AddToSystemSize ; zero
  615. ENDIF
  616. pop DX ;restore regs
  617. pop AX
  618. ret
  619. Calc_System_Space endp
  620. code ends
  621. end