Source code of Windows XP (NT5)
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.

517 lines
10 KiB

  1. DOSSEG
  2. .MODEL LARGE
  3. include disk.inc
  4. .DATA?
  5. public DiskList
  6. DiskList dd ?
  7. .CODE
  8. ASSUME ds:NOTHING
  9. extrn InitializeInt13DiskList:far
  10. extrn OpenInt13Disk:far
  11. extrn CloseInt13Disk:far
  12. extrn Int13DiskIo:far
  13. extrn GetInt13DiskInfo:far
  14. .386
  15. ;++
  16. ;
  17. ; UINT
  18. ; _far
  19. ; InitializeDiskList(
  20. ; VOID
  21. ; );
  22. ;
  23. ; Routine Description:
  24. ;
  25. ; This routine initializes internal data structures necessary so that
  26. ; other disk-related routines in this module can be called.
  27. ;
  28. ; A data structure for each disk (currently int13 units only) is built
  29. ; and saved away. The structure contains various info such as
  30. ; drive geometry.
  31. ;
  32. ; This routine may be called multiple times. Subsequent calls after
  33. ; the first simply return the disk count.
  34. ;
  35. ; Arguments:
  36. ;
  37. ; None.
  38. ;
  39. ; Return Value:
  40. ;
  41. ; Total count of all hard drives that we can deal with.
  42. ; 0 if an error occurs.
  43. ;
  44. ;--
  45. public _InitializeDiskList
  46. _InitializeDiskList proc far
  47. push ds
  48. push si
  49. ;
  50. ; See if we're initialized yet by counting items in the DiskList
  51. ; linked list. If 0, then assume not initialized yet.
  52. ;
  53. mov ax,DGROUP
  54. mov ds,ax
  55. mov si,OFFSET DGROUP:DiskList
  56. mov ax,0
  57. idl1:
  58. .errnz DiskInfoNextl
  59. mov cx,[si].DiskInfoNextl
  60. or cx,[si].DiskInfoNexth
  61. jz idl2
  62. inc ax
  63. lds si,[si].DiskInfoNext
  64. jmp short idl1
  65. idl2:
  66. cmp ax,0
  67. jne idl3
  68. ;
  69. ; Currently we deal with int13 disks only.
  70. ;
  71. push ax ; disk ids start at 0
  72. call InitializeInt13DiskList
  73. add sp,2
  74. idl3:
  75. pop si
  76. pop ds
  77. retf
  78. _InitializeDiskList endp
  79. ;++
  80. ;
  81. ; HDISK
  82. ; _far
  83. ; OpenDisk(
  84. ; IN UINT DiskId
  85. ; );
  86. ;
  87. ; Routine Description:
  88. ;
  89. ; This routine "opens" a disk so that i/o can be performed to it.
  90. ; Housekeeping such as locking, etc, is performed.
  91. ; A disk can be opened only once at a time.
  92. ;
  93. ; Arguments:
  94. ;
  95. ; DiskId - supplies an ordinal value for the disk to be opened.
  96. ; Range is 0 - n-1, where n is the value returned by
  97. ; InitializeDiskList().
  98. ;
  99. ; Return Value:
  100. ;
  101. ; Handle, or 0 if an error occurs.
  102. ;
  103. ;--
  104. DiskId equ word ptr [bp+6]
  105. public _OpenDisk
  106. _OpenDisk proc far
  107. push bp
  108. mov bp,sp
  109. push ds
  110. push si
  111. ;
  112. ; Locate the disk record corresponding to this disk id.
  113. ;
  114. mov ax,DiskId
  115. call far ptr pLocateDiskRecord
  116. mov cx,si
  117. or cx,dx
  118. mov ax,0
  119. jz od_done ; dx:ax already 0 for error return
  120. od_gotrec:
  121. ;
  122. ; Make sure disk is not already open
  123. ;
  124. cmp [si].DiskInfoDiskOpen,al
  125. jz @f
  126. mov dx,ax ; dx:ax = 0
  127. jnz od_done ; disk already open, error.
  128. @@:
  129. ;
  130. ; Int13 disks only for now.
  131. ;
  132. push ds
  133. push si
  134. call OpenInt13Disk
  135. pop si
  136. pop ds
  137. cmp ax,0
  138. jnz @f
  139. mov dx,ax
  140. jz od_done ; error, dx:ax set for return
  141. @@: inc [si].DiskInfoDiskOpen
  142. mov dx,ds
  143. mov ax,si ; dx:ax = handle for return
  144. od_done:
  145. pop si
  146. pop ds
  147. leave
  148. retf
  149. _OpenDisk endp
  150. ;++
  151. ;
  152. ; VOID
  153. ; _far
  154. ; CloseDisk(
  155. ; IN HDISK DiskHandle
  156. ; );
  157. ;
  158. ; Routine Description:
  159. ;
  160. ; This routine "closes" a disk previously opened by OpenDisk().
  161. ; Housekeeping such as unlocking, etc, is performed.
  162. ;
  163. ; Arguments:
  164. ;
  165. ; DiskHandle - supplies the handle of the disk to be closed,
  166. ; as previously opened by OpenDisk().
  167. ;
  168. ; Return Value:
  169. ;
  170. ; None.
  171. ;
  172. ;--
  173. DiskHandle equ dword ptr [bp+6]
  174. public _CloseDisk
  175. _CloseDisk proc far
  176. push bp
  177. mov bp,sp
  178. push ds
  179. push si
  180. lds si,DiskHandle
  181. cmp [si].DiskInfoDiskOpen,0
  182. jz cd_done ; not open, nothing to do
  183. ;
  184. ; Int13 disks only for now
  185. ;
  186. push ds
  187. push si
  188. call CloseInt13Disk
  189. pop si
  190. pop ds ; ds:si -> disk record
  191. dec [si].DiskInfoDiskOpen
  192. cd_done:
  193. pop si
  194. pop ds
  195. leave
  196. retf
  197. _CloseDisk endp
  198. ;++
  199. ;
  200. ; BOOL
  201. ; _far
  202. ; GetDiskInfoByHandle(
  203. ; IN HDISK DiskHandle,
  204. ; OUT FPBYTE Int13UnitNumber,
  205. ; OUT FPBYTE SectorsPerTrack,
  206. ; OUT FPUSHORT Heads,
  207. ; OUT FPUSHORT Cylinders,
  208. ; OUT FPULONG ExtendedSectorCount,
  209. ; OUT FPUINT DiskId
  210. ; );
  211. ;
  212. ; BOOL
  213. ; _far
  214. ; GetDiskInfoById(
  215. ; IN UINT DiskId,
  216. ; IN UINT Reserved,
  217. ; OUT FPBYTE Int13UnitNumber,
  218. ; OUT FPBYTE SectorsPerTrack,
  219. ; OUT FPUSHORT Heads,
  220. ; OUT FPUSHORT Cylinders,
  221. ; OUT FPULONG ExtendedSectorCount
  222. ; );
  223. ;
  224. ; Routine Description:
  225. ;
  226. ; These routines fetch information about a disk.
  227. ;
  228. ; Arguments:
  229. ;
  230. ; Return Value:
  231. ;
  232. ; non-0 - success
  233. ; 0 - failure
  234. ;
  235. ;--
  236. DiskHandle equ dword ptr [bp+6]
  237. DiskId equ word ptr [bp+6]
  238. Int13UnitNumber equ dword ptr [bp+10]
  239. SectorsPerTrack equ dword ptr [bp+14]
  240. Heads equ dword ptr [bp+18]
  241. Cylinders equ dword ptr [bp+22]
  242. ExtendedSecCnt equ dword ptr [bp+26]
  243. pDiskId equ dword ptr [bp+30]
  244. public _GetDiskInfoById
  245. _GetDiskInfoById proc far
  246. push bp
  247. mov bp,sp
  248. push ds
  249. push si
  250. ;
  251. ; Locate the disk record.
  252. ;
  253. mov ax,DiskId
  254. call far ptr pLocateDiskRecord
  255. cmp dx,0
  256. jnz gdi_do_it
  257. cmp si,0
  258. jnz gdi_do_it
  259. mov ax,dx
  260. jz gdi_done
  261. gdi_do_it:
  262. ;
  263. ; Int13 disks are the only ones supported now so we can
  264. ; just call the int13-specific disk info routine.
  265. ;
  266. push ExtendedSecCnt
  267. push Cylinders
  268. push Heads
  269. push SectorsPerTrack
  270. push Int13UnitNumber
  271. push ds
  272. push si
  273. call GetInt13DiskInfo
  274. add sp,24
  275. mov ax,1
  276. gdi_done:
  277. pop si
  278. pop ds
  279. leave
  280. retf
  281. _GetDiskInfoById endp
  282. public _GetDiskInfoByHandle
  283. _GetDiskInfoByHandle proc far
  284. push bp
  285. mov bp,sp
  286. push ds
  287. push si
  288. ;
  289. ; Make sure the disk is open.
  290. ;
  291. lds si,DiskHandle
  292. cmp [si].DiskInfoDiskOpen,0
  293. jz @f
  294. ;
  295. ; Set disk id in caller's variable
  296. ;
  297. mov ax,[si].DiskInfoDiskId
  298. lds si,pDiskId
  299. mov [si],ax
  300. lds si,DiskHandle
  301. jmp short gdi_do_it
  302. @@: mov ax,0
  303. jz gdi_done
  304. _GetDiskInfoByHandle endp
  305. ;++
  306. ;
  307. ; BOOL
  308. ; _far
  309. ; ReadDisk(
  310. ; IN HDISK DiskHandle,
  311. ; IN ULONG StartSector,
  312. ; IN BYTE SectorCount,
  313. ; OUT PVOID Buffer
  314. ; );
  315. ;
  316. ; BOOL
  317. ; _far
  318. ; WriteDisk(
  319. ; IN HDISK DiskHandle,
  320. ; IN ULONG StartSector,
  321. ; IN BYTE SectorCount,
  322. ; IN PVOID Buffer
  323. ; );
  324. ;
  325. ; Routine Description:
  326. ;
  327. ; These routines perform i/o to a disk previously opened with
  328. ; OpenDisk().
  329. ;
  330. ; Arguments:
  331. ;
  332. ; DiskHandle - supplies the handle of the disk to be read/written,
  333. ; as previously opened by OpenDisk().
  334. ;
  335. ; StartSector - supplies the physical start sector where the read/write
  336. ; is to begin.
  337. ;
  338. ; SectorCount - supplies the number of sectors to be read/written.
  339. ;
  340. ; Buffer - supplies a buffer for the transfer.
  341. ;
  342. ; Return Value:
  343. ;
  344. ; non-0 - success
  345. ; 0 - failure
  346. ;
  347. ;--
  348. DiskHandle equ dword ptr [bp+6]
  349. StartSector equ dword ptr [bp+10]
  350. SectorCount equ word ptr [bp+14]
  351. Buffer equ dword ptr [bp+16]
  352. public _WriteDisk
  353. _WriteDisk label far
  354. mov ax,1
  355. jmp short DiskIo
  356. public _ReadDisk
  357. _ReadDisk label far
  358. mov ax,0
  359. DiskIo proc far
  360. push bp
  361. mov bp,sp
  362. push ds
  363. push si
  364. lds si,DiskHandle
  365. cmp [si].DiskInfoDiskOpen,0
  366. jnz @f
  367. mov ax,0 ; not open, error out
  368. jz rd_done
  369. ;
  370. ; Int13 disks only for now
  371. ;
  372. @@: push ax
  373. push Buffer
  374. push SectorCount
  375. push StartSector ; only care about low byte
  376. push ds
  377. push si
  378. call Int13DiskIo
  379. add sp,16
  380. rd_done:
  381. pop si
  382. pop ds
  383. leave
  384. retf
  385. DiskIo endp
  386. ;++
  387. ;
  388. ; PVOID
  389. ; _far
  390. ; pLocateDiskRecord(
  391. ; IN UINT DiskId
  392. ; );
  393. ;
  394. ; Routine Description:
  395. ;
  396. ; Internal routine.
  397. ;
  398. ; This routine locates a disk record in the linked list
  399. ; of all disk records as prepared by InitializeDiskList().
  400. ;
  401. ; Arguments:
  402. ;
  403. ; DiskId - supplies an ordinal value identifying the disk.
  404. ; Valid range is 0 - n-1, where n is the number returned
  405. ; from InitializeDiskList().
  406. ;
  407. ; This parameter is passed in ax, not on the stack.
  408. ;
  409. ; Return Value:
  410. ;
  411. ; NULL if record not located.
  412. ; Otherwise fills ds:si and dx:si with a far pointer to the
  413. ; disk record.
  414. ;
  415. ;--
  416. pLocateDiskRecord proc far
  417. mov dx,DGROUP
  418. mov ds,dx
  419. mov si,offset DGROUP:[DiskList] ; ds:si = &DiskList
  420. ;
  421. ; Note that this code depends on the link field in the
  422. ; disk record structure being first!
  423. ;
  424. .errnz DiskInfoNext
  425. ldr_loop:
  426. lds si,[si].DiskInfoNext
  427. mov dx,ds
  428. cmp dx,0
  429. jz ldr_done ; end of list, we're done
  430. cmp [si].DiskInfoDiskId,ax
  431. jz ldr_done
  432. jmp short ldr_loop
  433. ldr_done:
  434. retf
  435. pLocateDiskRecord endp
  436. end