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.

2382 lines
61 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. biosdrv.c
  5. Abstract:
  6. Provides the ARC emulation routines for I/O to a device supported by
  7. real-mode INT 13h BIOS calls.
  8. Author:
  9. John Vert (jvert) 7-Aug-1991
  10. Revision History:
  11. --*/
  12. #include "arccodes.h"
  13. #include "bootx86.h"
  14. #include "stdlib.h"
  15. #include "string.h"
  16. #include "flop.h"
  17. #if 0
  18. #define DBGOUT(x) BlPrint x
  19. #define DBGPAUSE while(!GET_KEY());
  20. #else
  21. #define DBGOUT(x)
  22. #define DBGPAUSE
  23. #endif
  24. //
  25. // Defines for buffer alignment and boundary checks in BiosDisk*
  26. // functions.
  27. //
  28. #define BIOSDISK_1MB (1 * 1024 * 1024)
  29. #define BIOSDISK_64KB (64 * 1024)
  30. #define BIOSDISK_64KB_MASK (~(BIOSDISK_64KB - 1))
  31. //
  32. // Definitions for caching the last read sector.
  33. //
  34. #define BL_LAST_SECTOR_CACHE_MAX_SIZE 4096
  35. typedef struct _BL_LAST_SECTOR_CACHE
  36. {
  37. BOOLEAN Initialized;
  38. BOOLEAN Valid;
  39. ULONG DeviceId;
  40. ULONGLONG SectorNumber;
  41. PUCHAR Data;
  42. } BL_LAST_SECTOR_CACHE, *PBL_LAST_SECTOR_CACHE;
  43. //
  44. // This is the global variable used for caching the last sector read
  45. // from the last disk. Callers who access files sequentially but do
  46. // not make sure their offsets are sector aligned end up reading the
  47. // last sector they read again with their next request. This solves
  48. // the problem. Its Data buffer is allocated from the pool at the
  49. // first disk read. It is setup and used in BiosDiskRead, invalidated
  50. // in BiosDiskWrite.
  51. //
  52. BL_LAST_SECTOR_CACHE FwLastSectorCache = {0};
  53. //
  54. // defines for doing console I/O
  55. //
  56. #define CSI 0x95
  57. #define SGR_INVERSE 7
  58. #define SGR_NORMAL 0
  59. //
  60. // static data for console I/O
  61. //
  62. BOOLEAN ControlSequence=FALSE;
  63. BOOLEAN EscapeSequence=FALSE;
  64. BOOLEAN FontSelection=FALSE;
  65. BOOLEAN HighIntensity=FALSE;
  66. BOOLEAN Blink=FALSE;
  67. ULONG PCount=0;
  68. #define CONTROL_SEQUENCE_MAX_PARAMETER 10
  69. ULONG Parameter[CONTROL_SEQUENCE_MAX_PARAMETER];
  70. #define KEY_INPUT_BUFFER_SIZE 16
  71. UCHAR KeyBuffer[KEY_INPUT_BUFFER_SIZE];
  72. ULONG KeyBufferEnd=0;
  73. ULONG KeyBufferStart=0;
  74. //
  75. // array for translating between ANSI colors and the VGA standard
  76. //
  77. UCHAR TranslateColor[] = {0,4,2,6,1,5,3,7};
  78. ARC_STATUS
  79. BiosDiskClose(
  80. IN ULONG FileId
  81. );
  82. VOID
  83. BiosConsoleFillBuffer(
  84. IN ULONG Key
  85. );
  86. //
  87. // There are two sorts of things we can open in this module, disk partitions,
  88. // and raw disk devices. The following device entry tables are
  89. // used for these things.
  90. //
  91. BL_DEVICE_ENTRY_TABLE BiosPartitionEntryTable =
  92. {
  93. (PARC_CLOSE_ROUTINE)BiosPartitionClose,
  94. (PARC_MOUNT_ROUTINE)BlArcNotYetImplemented,
  95. (PARC_OPEN_ROUTINE)BiosPartitionOpen,
  96. (PARC_READ_ROUTINE)BiosPartitionRead,
  97. (PARC_READ_STATUS_ROUTINE)BlArcNotYetImplemented,
  98. (PARC_SEEK_ROUTINE)BiosPartitionSeek,
  99. (PARC_WRITE_ROUTINE)BiosPartitionWrite,
  100. (PARC_GET_FILE_INFO_ROUTINE)BiosPartitionGetFileInfo,
  101. (PARC_SET_FILE_INFO_ROUTINE)BlArcNotYetImplemented,
  102. (PRENAME_ROUTINE)BlArcNotYetImplemented,
  103. (PARC_GET_DIRECTORY_ENTRY_ROUTINE)BlArcNotYetImplemented,
  104. (PBOOTFS_INFO)BlArcNotYetImplemented
  105. };
  106. BL_DEVICE_ENTRY_TABLE BiosDiskEntryTable =
  107. {
  108. (PARC_CLOSE_ROUTINE)BiosDiskClose,
  109. (PARC_MOUNT_ROUTINE)BlArcNotYetImplemented,
  110. (PARC_OPEN_ROUTINE)BiosDiskOpen,
  111. (PARC_READ_ROUTINE)BiosDiskRead,
  112. (PARC_READ_STATUS_ROUTINE)BlArcNotYetImplemented,
  113. (PARC_SEEK_ROUTINE)BiosPartitionSeek,
  114. (PARC_WRITE_ROUTINE)BiosDiskWrite,
  115. (PARC_GET_FILE_INFO_ROUTINE)BiosDiskGetFileInfo,
  116. (PARC_SET_FILE_INFO_ROUTINE)BlArcNotYetImplemented,
  117. (PRENAME_ROUTINE)BlArcNotYetImplemented,
  118. (PARC_GET_DIRECTORY_ENTRY_ROUTINE)BlArcNotYetImplemented,
  119. (PBOOTFS_INFO)BlArcNotYetImplemented
  120. };
  121. BL_DEVICE_ENTRY_TABLE BiosEDDSEntryTable =
  122. {
  123. (PARC_CLOSE_ROUTINE)BiosDiskClose,
  124. (PARC_MOUNT_ROUTINE)BlArcNotYetImplemented,
  125. (PARC_OPEN_ROUTINE)BiosDiskOpen,
  126. (PARC_READ_ROUTINE)BiosElToritoDiskRead,
  127. (PARC_READ_STATUS_ROUTINE)BlArcNotYetImplemented,
  128. (PARC_SEEK_ROUTINE)BiosPartitionSeek,
  129. (PARC_WRITE_ROUTINE)BlArcNotYetImplemented,
  130. (PARC_GET_FILE_INFO_ROUTINE)BiosDiskGetFileInfo,
  131. (PARC_SET_FILE_INFO_ROUTINE)BlArcNotYetImplemented,
  132. (PRENAME_ROUTINE)BlArcNotYetImplemented,
  133. (PARC_GET_DIRECTORY_ENTRY_ROUTINE)BlArcNotYetImplemented,
  134. (PBOOTFS_INFO)BlArcNotYetImplemented
  135. };
  136. ARC_STATUS
  137. BiosDiskClose(
  138. IN ULONG FileId
  139. )
  140. /*++
  141. Routine Description:
  142. Closes the specified device
  143. Arguments:
  144. FileId - Supplies file id of the device to be closed
  145. Return Value:
  146. ESUCCESS - Device closed successfully
  147. !ESUCCESS - Device was not closed.
  148. --*/
  149. {
  150. if (BlFileTable[FileId].Flags.Open == 0) {
  151. #if DBG
  152. BlPrint("ERROR - Unopened fileid %lx closed\n",FileId);
  153. #endif
  154. }
  155. BlFileTable[FileId].Flags.Open = 0;
  156. //
  157. // Invalidate the last read sector cache if it was for this disk.
  158. //
  159. if (FwLastSectorCache.DeviceId == FileId) {
  160. FwLastSectorCache.Valid = FALSE;
  161. }
  162. return(ESUCCESS);
  163. }
  164. ARC_STATUS
  165. BiosPartitionClose(
  166. IN ULONG FileId
  167. )
  168. /*++
  169. Routine Description:
  170. Closes the specified device
  171. Arguments:
  172. FileId - Supplies file id of the device to be closed
  173. Return Value:
  174. ESUCCESS - Device closed successfully
  175. !ESUCCESS - Device was not closed.
  176. --*/
  177. {
  178. if (BlFileTable[FileId].Flags.Open == 0) {
  179. #if DBG
  180. BlPrint("ERROR - Unopened fileid %lx closed\n",FileId);
  181. #endif
  182. }
  183. BlFileTable[FileId].Flags.Open = 0;
  184. return(BiosDiskClose((ULONG)BlFileTable[FileId].u.PartitionContext.DiskId));
  185. }
  186. ARC_STATUS
  187. BiosPartitionOpen(
  188. IN PCHAR OpenPath,
  189. IN OPEN_MODE OpenMode,
  190. OUT PULONG FileId
  191. )
  192. /*++
  193. Routine Description:
  194. Opens the disk partition specified by OpenPath. This routine will open
  195. floppy drives 0 and 1, and any partition on hard drive 0 or 1.
  196. Arguments:
  197. OpenPath - Supplies a pointer to the name of the partition. If OpenPath
  198. is "A:" or "B:" the corresponding floppy drive will be opened.
  199. If it is "C:" or above, this routine will find the corresponding
  200. partition on hard drive 0 or 1 and open it.
  201. OpenMode - Supplies the mode to open the file.
  202. 0 - Read Only
  203. 1 - Write Only
  204. 2 - Read/Write
  205. FileId - Returns the file descriptor for use with the Close, Read, Write,
  206. and Seek routines
  207. Return Value:
  208. ESUCCESS - File successfully opened.
  209. --*/
  210. {
  211. ARC_STATUS Status;
  212. ULONG DiskFileId;
  213. UCHAR PartitionNumber;
  214. ULONG Controller;
  215. ULONG Key;
  216. BOOLEAN IsEisa = FALSE;
  217. //
  218. // BIOS devices are always "multi(0)" (except for EISA flakiness
  219. // where we treat "eisa(0)..." like "multi(0)..." in floppy cases.
  220. //
  221. if(FwGetPathMnemonicKey(OpenPath,"multi",&Key)) {
  222. if(FwGetPathMnemonicKey(OpenPath,"eisa", &Key)) {
  223. return(EBADF);
  224. } else {
  225. IsEisa = TRUE;
  226. }
  227. }
  228. if (Key!=0) {
  229. return(EBADF);
  230. }
  231. //
  232. // If we're opening a floppy drive, there are no partitions
  233. // so we can just return the physical device.
  234. //
  235. if((_stricmp(OpenPath,"multi(0)disk(0)fdisk(0)partition(0)") == 0) ||
  236. (_stricmp(OpenPath,"eisa(0)disk(0)fdisk(0)partition(0)" ) == 0))
  237. {
  238. return(BiosDiskOpen( 0, 0, FileId));
  239. }
  240. if((_stricmp(OpenPath,"multi(0)disk(0)fdisk(1)partition(0)") == 0) ||
  241. (_stricmp(OpenPath,"eisa(0)disk(0)fdisk(1)partition(0)" ) == 0))
  242. {
  243. return(BiosDiskOpen( 1, 0, FileId));
  244. }
  245. if((_stricmp(OpenPath,"multi(0)disk(0)fdisk(0)") == 0) ||
  246. (_stricmp(OpenPath,"eisa(0)disk(0)fdisk(0)" ) == 0))
  247. {
  248. return(BiosDiskOpen( 0, 0, FileId));
  249. }
  250. if((_stricmp(OpenPath,"multi(0)disk(0)fdisk(1)") == 0) ||
  251. (_stricmp(OpenPath,"eisa(0)disk(0)fdisk(1)" ) == 0))
  252. {
  253. return(BiosDiskOpen( 1, 0, FileId));
  254. }
  255. //
  256. // We can't handle eisa(0) cases for hard disks.
  257. //
  258. if(IsEisa) {
  259. return(EBADF);
  260. }
  261. //
  262. // We can only deal with disk controller 0
  263. //
  264. if (FwGetPathMnemonicKey(OpenPath,"disk",&Controller)) {
  265. return(EBADF);
  266. }
  267. if ( Controller!=0 ) {
  268. return(EBADF);
  269. }
  270. if (!FwGetPathMnemonicKey(OpenPath,"cdrom",&Key)) {
  271. //
  272. // Now we have a CD-ROM disk number, so we open that for raw access.
  273. // Use a special bit to indicate CD-ROM, because otherwise
  274. // the BiosDiskOpen routine thinks a third or greater disk is
  275. // a CD-ROM.
  276. //
  277. return(BiosDiskOpen( Key | 0x80000000, 0, FileId ) );
  278. }
  279. if (FwGetPathMnemonicKey(OpenPath,"rdisk",&Key)) {
  280. return(EBADF);
  281. }
  282. //
  283. // Now we have a disk number, so we open that for raw access.
  284. // We need to add 0x80 to translate it to a BIOS number.
  285. //
  286. Status = BiosDiskOpen( 0x80 + Key,
  287. 0,
  288. &DiskFileId );
  289. if (Status != ESUCCESS) {
  290. return(Status);
  291. }
  292. //
  293. // Find the partition number to open
  294. //
  295. if (FwGetPathMnemonicKey(OpenPath,"partition",&Key)) {
  296. BiosPartitionClose(DiskFileId);
  297. return(EBADF);
  298. }
  299. //
  300. // If the partition number was 0, then we are opening the device
  301. // for raw access, so we are already done.
  302. //
  303. if (Key == 0) {
  304. *FileId = DiskFileId;
  305. return(ESUCCESS);
  306. }
  307. //
  308. // Before we open the partition, we need to find an available
  309. // file descriptor.
  310. //
  311. *FileId=2;
  312. while (BlFileTable[*FileId].Flags.Open != 0) {
  313. *FileId += 1;
  314. if (*FileId == BL_FILE_TABLE_SIZE) {
  315. return(ENOENT);
  316. }
  317. }
  318. //
  319. // We found an entry we can use, so mark it as open.
  320. //
  321. BlFileTable[*FileId].Flags.Open = 1;
  322. BlFileTable[*FileId].DeviceEntryTable=&BiosPartitionEntryTable;
  323. //
  324. // Convert to zero-based partition number
  325. //
  326. PartitionNumber = (UCHAR)(Key - 1);
  327. //
  328. // Try to open the MBR partition
  329. //
  330. Status = HardDiskPartitionOpen( *FileId,
  331. DiskFileId,
  332. PartitionNumber);
  333. #ifdef EFI_PARTITION_SUPPORT
  334. if (Status != ESUCCESS) {
  335. //
  336. // Try to open the GPT partition
  337. //
  338. Status = BlOpenGPTDiskPartition( *FileId,
  339. DiskFileId,
  340. PartitionNumber);
  341. }
  342. #endif
  343. return Status;
  344. }
  345. ARC_STATUS
  346. BiosPartitionRead (
  347. IN ULONG FileId,
  348. OUT PVOID Buffer,
  349. IN ULONG Length,
  350. OUT PULONG Count
  351. )
  352. /*++
  353. Routine Description:
  354. Reads from the specified file
  355. NOTE John Vert (jvert) 18-Jun-1991
  356. This only supports block sector reads. Thus, everything
  357. is assumed to start on a sector boundary, and every offset
  358. is considered an offset from the logical beginning of the disk
  359. partition.
  360. Arguments:
  361. FileId - Supplies the file to read from
  362. Buffer - Supplies buffer to hold the data that is read
  363. Length - Supplies maximum number of bytes to read
  364. Count - Returns actual bytes read.
  365. Return Value:
  366. ESUCCESS - Read completed successfully
  367. !ESUCCESS - Read failed.
  368. --*/
  369. {
  370. ARC_STATUS Status;
  371. LARGE_INTEGER PhysicalOffset;
  372. ULONG DiskId;
  373. PhysicalOffset.QuadPart = BlFileTable[FileId].Position.QuadPart +
  374. SECTOR_SIZE * (LONGLONG)BlFileTable[FileId].u.PartitionContext.StartingSector;
  375. DiskId = BlFileTable[FileId].u.PartitionContext.DiskId;
  376. Status = (BlFileTable[DiskId].DeviceEntryTable->Seek)(DiskId,
  377. &PhysicalOffset,
  378. SeekAbsolute );
  379. if (Status != ESUCCESS) {
  380. return(Status);
  381. }
  382. Status = (BlFileTable[DiskId].DeviceEntryTable->Read)(DiskId,
  383. Buffer,
  384. Length,
  385. Count );
  386. BlFileTable[FileId].Position.QuadPart += *Count;
  387. return(Status);
  388. }
  389. ARC_STATUS
  390. BiosPartitionSeek (
  391. IN ULONG FileId,
  392. IN PLARGE_INTEGER Offset,
  393. IN SEEK_MODE SeekMode
  394. )
  395. /*++
  396. Routine Description:
  397. Changes the current offset of the file specified by FileId
  398. Arguments:
  399. FileId - specifies the file on which the current offset is to
  400. be changed.
  401. Offset - New offset into file.
  402. SeekMode - Either SeekAbsolute or SeekRelative
  403. SeekEndRelative is not supported
  404. Return Value:
  405. ESUCCESS - Operation completed succesfully
  406. EBADF - Operation did not complete successfully.
  407. --*/
  408. {
  409. switch (SeekMode) {
  410. case SeekAbsolute:
  411. BlFileTable[FileId].Position = *Offset;
  412. break;
  413. case SeekRelative:
  414. BlFileTable[FileId].Position.QuadPart += Offset->QuadPart;
  415. break;
  416. default:
  417. #if DBG
  418. BlPrint("SeekMode %lx not supported\n",SeekMode);
  419. #endif
  420. return(EACCES);
  421. }
  422. return(ESUCCESS);
  423. }
  424. ARC_STATUS
  425. BiosPartitionWrite(
  426. IN ULONG FileId,
  427. OUT PVOID Buffer,
  428. IN ULONG Length,
  429. OUT PULONG Count
  430. )
  431. /*++
  432. Routine Description:
  433. Writes to the specified file
  434. NOTE John Vert (jvert) 18-Jun-1991
  435. This only supports block sector reads. Thus, everything
  436. is assumed to start on a sector boundary, and every offset
  437. is considered an offset from the logical beginning of the disk
  438. partition.
  439. Arguments:
  440. FileId - Supplies the file to write to
  441. Buffer - Supplies buffer with data to write
  442. Length - Supplies number of bytes to write
  443. Count - Returns actual bytes written.
  444. Return Value:
  445. ESUCCESS - write completed successfully
  446. !ESUCCESS - write failed.
  447. --*/
  448. {
  449. ARC_STATUS Status;
  450. LARGE_INTEGER PhysicalOffset;
  451. ULONG DiskId;
  452. PhysicalOffset.QuadPart = BlFileTable[FileId].Position.QuadPart +
  453. SECTOR_SIZE * (LONGLONG)BlFileTable[FileId].u.PartitionContext.StartingSector;
  454. DiskId = BlFileTable[FileId].u.PartitionContext.DiskId;
  455. Status = (BlFileTable[DiskId].DeviceEntryTable->Seek)(DiskId,
  456. &PhysicalOffset,
  457. SeekAbsolute );
  458. if (Status != ESUCCESS) {
  459. return(Status);
  460. }
  461. Status = (BlFileTable[DiskId].DeviceEntryTable->Write)(DiskId,
  462. Buffer,
  463. Length,
  464. Count );
  465. if(Status == ESUCCESS) {
  466. BlFileTable[FileId].Position.QuadPart += *Count;
  467. }
  468. return(Status);
  469. }
  470. ARC_STATUS
  471. BiosConsoleOpen(
  472. IN PCHAR OpenPath,
  473. IN OPEN_MODE OpenMode,
  474. OUT PULONG FileId
  475. )
  476. /*++
  477. Routine Description:
  478. Attempts to open either the console input or output
  479. Arguments:
  480. OpenPath - Supplies a pointer to the name of the device to open. If
  481. this is either CONSOLE_INPUT_NAME or CONSOLE_OUTPUT_NAME,
  482. a file descriptor is allocated and filled in.
  483. OpenMode - Supplies the mode to open the file.
  484. 0 - Read Only (CONSOLE_INPUT_NAME)
  485. 1 - Write Only (CONSOLE_OUTPUT_NAME)
  486. FileId - Returns the file descriptor for use with the Close, Read and
  487. Write routines
  488. Return Value:
  489. ESUCCESS - Console successfully opened.
  490. --*/
  491. {
  492. if (_stricmp(OpenPath, CONSOLE_INPUT_NAME)==0) {
  493. //
  494. // Open the keyboard for input
  495. //
  496. if (OpenMode != ArcOpenReadOnly) {
  497. return(EACCES);
  498. }
  499. *FileId = 0;
  500. return(ESUCCESS);
  501. }
  502. if (_stricmp(OpenPath, CONSOLE_OUTPUT_NAME)==0) {
  503. //
  504. // Open the display for output
  505. //
  506. if (OpenMode != ArcOpenWriteOnly) {
  507. return(EACCES);
  508. }
  509. *FileId = 1;
  510. return(ESUCCESS);
  511. }
  512. return(ENOENT);
  513. }
  514. ARC_STATUS
  515. BiosConsoleReadStatus(
  516. IN ULONG FileId
  517. )
  518. /*++
  519. Routine Description:
  520. This routine determines if there is a keypress pending
  521. Arguments:
  522. FileId - Supplies the FileId to be read. (should always be 0 for this
  523. function)
  524. Return Value:
  525. ESUCCESS - There is a key pending
  526. EAGAIN - There is not a key pending
  527. --*/
  528. {
  529. ULONG Key;
  530. //
  531. // If we have buffered input...
  532. //
  533. if (KeyBufferEnd != KeyBufferStart) {
  534. return(ESUCCESS);
  535. }
  536. //
  537. // Check for a key
  538. //
  539. Key = GET_KEY();
  540. if (Key != 0) {
  541. //
  542. // We got a key, so we have to stick it back into our buffer
  543. // and return ESUCCESS.
  544. //
  545. BiosConsoleFillBuffer(Key);
  546. return(ESUCCESS);
  547. } else {
  548. //
  549. // no key pending
  550. //
  551. return(EAGAIN);
  552. }
  553. }
  554. ARC_STATUS
  555. BiosConsoleRead(
  556. IN ULONG FileId,
  557. OUT PUCHAR Buffer,
  558. IN ULONG Length,
  559. OUT PULONG Count
  560. )
  561. /*++
  562. Routine Description:
  563. Gets input from the keyboard.
  564. Arguments:
  565. FileId - Supplies the FileId to be read (should always be 0 for this
  566. function)
  567. Buffer - Returns the keyboard input.
  568. Length - Supplies the length of the buffer (in bytes)
  569. Count - Returns the actual number of bytes read
  570. Return Value:
  571. ESUCCESS - Keyboard read completed succesfully.
  572. --*/
  573. {
  574. ULONG Key;
  575. *Count = 0;
  576. while (*Count < Length) {
  577. if (KeyBufferEnd == KeyBufferStart) { // then buffer is presently empty
  578. do {
  579. //
  580. // Poll the keyboard until input is available
  581. //
  582. Key = GET_KEY();
  583. } while ( Key==0 );
  584. BiosConsoleFillBuffer(Key);
  585. }
  586. Buffer[*Count] = KeyBuffer[KeyBufferStart];
  587. KeyBufferStart = (KeyBufferStart+1) % KEY_INPUT_BUFFER_SIZE;
  588. *Count = *Count + 1;
  589. }
  590. return(ESUCCESS);
  591. }
  592. VOID
  593. BiosConsoleFillBuffer(
  594. IN ULONG Key
  595. )
  596. /*++
  597. Routine Description:
  598. Places input from the keyboard into the keyboard buffer, expanding the
  599. special keys as appropriate.
  600. All keys translated here use the ARC translation table, as defined in the
  601. ARC specification, with one exception -- the BACKTAB_KEY, for which the
  602. ARC spec is lacking. I have decided that BACKTAB_KEY is ESC+TAB.
  603. Arguments:
  604. Key - Raw keypress value as returned by GET_KEY().
  605. Return Value:
  606. none.
  607. --*/
  608. {
  609. switch(Key) {
  610. case UP_ARROW:
  611. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  612. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  613. KeyBuffer[KeyBufferEnd] = 'A';
  614. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  615. break;
  616. case DOWN_ARROW:
  617. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  618. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  619. KeyBuffer[KeyBufferEnd] = 'B';
  620. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  621. break;
  622. case RIGHT_KEY:
  623. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  624. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  625. KeyBuffer[KeyBufferEnd] = 'C';
  626. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  627. break;
  628. case LEFT_KEY:
  629. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  630. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  631. KeyBuffer[KeyBufferEnd] = 'D';
  632. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  633. break;
  634. case INS_KEY:
  635. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  636. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  637. KeyBuffer[KeyBufferEnd] = '@';
  638. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  639. break;
  640. case DEL_KEY:
  641. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  642. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  643. KeyBuffer[KeyBufferEnd] = 'P';
  644. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  645. break;
  646. case F1_KEY:
  647. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  648. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  649. KeyBuffer[KeyBufferEnd] = 'O';
  650. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  651. KeyBuffer[KeyBufferEnd] = 'P';
  652. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  653. break;
  654. case F2_KEY:
  655. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  656. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  657. KeyBuffer[KeyBufferEnd] = 'O';
  658. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  659. KeyBuffer[KeyBufferEnd] = 'Q';
  660. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  661. break;
  662. case F3_KEY:
  663. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  664. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  665. KeyBuffer[KeyBufferEnd] = 'O';
  666. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  667. KeyBuffer[KeyBufferEnd] = 'w';
  668. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  669. break;
  670. case F5_KEY:
  671. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  672. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  673. KeyBuffer[KeyBufferEnd] = 'O';
  674. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  675. KeyBuffer[KeyBufferEnd] = 't';
  676. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  677. break;
  678. case F6_KEY:
  679. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  680. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  681. KeyBuffer[KeyBufferEnd] = 'O';
  682. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  683. KeyBuffer[KeyBufferEnd] = 'u';
  684. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  685. break;
  686. case F7_KEY:
  687. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  688. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  689. KeyBuffer[KeyBufferEnd] = 'O';
  690. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  691. KeyBuffer[KeyBufferEnd] = 'q';
  692. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  693. break;
  694. case F8_KEY:
  695. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  696. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  697. KeyBuffer[KeyBufferEnd] = 'O';
  698. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  699. KeyBuffer[KeyBufferEnd] = 'r';
  700. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  701. break;
  702. case F10_KEY:
  703. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  704. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  705. KeyBuffer[KeyBufferEnd] = 'O';
  706. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  707. KeyBuffer[KeyBufferEnd] = 'M';
  708. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  709. break;
  710. case F11_KEY:
  711. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  712. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  713. KeyBuffer[KeyBufferEnd] = 'O';
  714. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  715. KeyBuffer[KeyBufferEnd] = 'A';
  716. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  717. break;
  718. case F12_KEY:
  719. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  720. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  721. KeyBuffer[KeyBufferEnd] = 'O';
  722. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  723. KeyBuffer[KeyBufferEnd] = 'B';
  724. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  725. break;
  726. case HOME_KEY:
  727. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  728. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  729. KeyBuffer[KeyBufferEnd] = 'H';
  730. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  731. break;
  732. case END_KEY:
  733. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  734. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  735. KeyBuffer[KeyBufferEnd] = 'K';
  736. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  737. break;
  738. case ESCAPE_KEY:
  739. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  740. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  741. break;
  742. case BACKTAB_KEY:
  743. KeyBuffer[KeyBufferEnd] = ASCI_CSI_IN;
  744. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  745. KeyBuffer[KeyBufferEnd] = (UCHAR)(TAB_KEY & 0xFF);
  746. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  747. break;
  748. default:
  749. //
  750. // The ASCII code is the low byte of Key
  751. //
  752. KeyBuffer[KeyBufferEnd] = (UCHAR)(Key & 0xff);
  753. KeyBufferEnd = (KeyBufferEnd+1) % KEY_INPUT_BUFFER_SIZE;
  754. }
  755. }
  756. ARC_STATUS
  757. BiosConsoleWrite(
  758. IN ULONG FileId,
  759. OUT PUCHAR Buffer,
  760. IN ULONG Length,
  761. OUT PULONG Count
  762. )
  763. /*++
  764. Routine Description:
  765. Outputs to the console. (In this case, the VGA display)
  766. Arguments:
  767. FileId - Supplies the FileId to be written (should always be 1 for this
  768. function)
  769. Buffer - Supplies characters to be output
  770. Length - Supplies the length of the buffer (in bytes)
  771. Count - Returns the actual number of bytes written
  772. Return Value:
  773. ESUCCESS - Console write completed succesfully.
  774. --*/
  775. {
  776. ARC_STATUS Status;
  777. PUCHAR String;
  778. ULONG Index;
  779. UCHAR a;
  780. PUCHAR p;
  781. //
  782. // Process each character in turn.
  783. //
  784. Status = ESUCCESS;
  785. String = (PUCHAR)Buffer;
  786. for ( *Count = 0 ;
  787. *Count < Length ;
  788. (*Count)++, String++ ) {
  789. //
  790. // If we're in the middle of a control sequence, continue scanning,
  791. // otherwise process character.
  792. //
  793. if (ControlSequence) {
  794. //
  795. // If the character is a digit, update parameter value.
  796. //
  797. if ((*String >= '0') && (*String <= '9')) {
  798. Parameter[PCount] = Parameter[PCount] * 10 + *String - '0';
  799. continue;
  800. }
  801. //
  802. // If we are in the middle of a font selection sequence, this
  803. // character must be a 'D', otherwise reset control sequence.
  804. //
  805. if (FontSelection) {
  806. //if (*String == 'D') {
  807. //
  808. // //
  809. // // Other fonts not implemented yet.
  810. // //
  811. //
  812. //} else {
  813. //}
  814. ControlSequence = FALSE;
  815. FontSelection = FALSE;
  816. continue;
  817. }
  818. switch (*String) {
  819. //
  820. // If a semicolon, move to the next parameter.
  821. //
  822. case ';':
  823. PCount++;
  824. if (PCount > CONTROL_SEQUENCE_MAX_PARAMETER) {
  825. PCount = CONTROL_SEQUENCE_MAX_PARAMETER;
  826. }
  827. Parameter[PCount] = 0;
  828. break;
  829. //
  830. // If a 'J', erase part or all of the screen.
  831. //
  832. case 'J':
  833. switch (Parameter[0]) {
  834. case 0:
  835. //
  836. // Erase to end of the screen
  837. //
  838. TextClearToEndOfDisplay();
  839. break;
  840. case 1:
  841. //
  842. // Erase from the beginning of the screen
  843. //
  844. break;
  845. default:
  846. //
  847. // Erase entire screen
  848. //
  849. TextClearDisplay();
  850. break;
  851. }
  852. ControlSequence = FALSE;
  853. break;
  854. //
  855. // If a 'K', erase part or all of the line.
  856. //
  857. case 'K':
  858. switch (Parameter[0]) {
  859. //
  860. // Erase to end of the line.
  861. //
  862. case 0:
  863. TextClearToEndOfLine();
  864. break;
  865. //
  866. // Erase from the beginning of the line.
  867. //
  868. case 1:
  869. TextClearFromStartOfLine();
  870. break;
  871. //
  872. // Erase entire line.
  873. //
  874. default :
  875. TextClearFromStartOfLine();
  876. TextClearToEndOfLine();
  877. break;
  878. }
  879. ControlSequence = FALSE;
  880. break;
  881. //
  882. // If a 'H', move cursor to position.
  883. //
  884. case 'H':
  885. TextSetCursorPosition(Parameter[1]-1, Parameter[0]-1);
  886. ControlSequence = FALSE;
  887. break;
  888. //
  889. // If a ' ', could be a FNT selection command.
  890. //
  891. case ' ':
  892. FontSelection = TRUE;
  893. break;
  894. case 'm':
  895. //
  896. // Select action based on each parameter.
  897. //
  898. // Blink and HighIntensity are by default disabled
  899. // each time a new SGR is specified, unless they are
  900. // explicitly specified again, in which case these
  901. // will be set to TRUE at that time.
  902. //
  903. HighIntensity = FALSE;
  904. Blink = FALSE;
  905. for ( Index = 0 ; Index <= PCount ; Index++ ) {
  906. switch (Parameter[Index]) {
  907. //
  908. // Attributes off.
  909. //
  910. case 0:
  911. TextSetCurrentAttribute(7);
  912. HighIntensity = FALSE;
  913. Blink = FALSE;
  914. break;
  915. //
  916. // High Intensity.
  917. //
  918. case 1:
  919. TextSetCurrentAttribute(0xf);
  920. HighIntensity = TRUE;
  921. break;
  922. //
  923. // Underscored.
  924. //
  925. case 4:
  926. break;
  927. //
  928. // Blink.
  929. //
  930. case 5:
  931. TextSetCurrentAttribute(0x87);
  932. Blink = TRUE;
  933. break;
  934. //
  935. // Reverse Video.
  936. //
  937. case 7:
  938. TextSetCurrentAttribute(0x70);
  939. HighIntensity = FALSE;
  940. Blink = FALSE;
  941. break;
  942. //
  943. // Font selection, not implemented yet.
  944. //
  945. case 10:
  946. case 11:
  947. case 12:
  948. case 13:
  949. case 14:
  950. case 15:
  951. case 16:
  952. case 17:
  953. case 18:
  954. case 19:
  955. break;
  956. //
  957. // Foreground Color
  958. //
  959. case 30:
  960. case 31:
  961. case 32:
  962. case 33:
  963. case 34:
  964. case 35:
  965. case 36:
  966. case 37:
  967. a = TextGetCurrentAttribute();
  968. a &= 0x70;
  969. a |= TranslateColor[Parameter[Index]-30];
  970. if (HighIntensity) {
  971. a |= 0x08;
  972. }
  973. if (Blink) {
  974. a |= 0x80;
  975. }
  976. TextSetCurrentAttribute(a);
  977. break;
  978. //
  979. // Background Color
  980. //
  981. case 40:
  982. case 41:
  983. case 42:
  984. case 43:
  985. case 44:
  986. case 45:
  987. case 46:
  988. case 47:
  989. a = TextGetCurrentAttribute();
  990. a &= 0x8f;
  991. a |= TranslateColor[Parameter[Index]-40] << 4;
  992. TextSetCurrentAttribute(a);
  993. break;
  994. default:
  995. break;
  996. }
  997. }
  998. default:
  999. ControlSequence = FALSE;
  1000. break;
  1001. }
  1002. //
  1003. // This is not a control sequence, check for escape sequence.
  1004. //
  1005. } else {
  1006. //
  1007. // If escape sequence, check for control sequence, otherwise
  1008. // process single character.
  1009. //
  1010. if (EscapeSequence) {
  1011. //
  1012. // Check for '[', means control sequence, any other following
  1013. // character is ignored.
  1014. //
  1015. if (*String == '[') {
  1016. ControlSequence = TRUE;
  1017. //
  1018. // Initialize first parameter.
  1019. //
  1020. PCount = 0;
  1021. Parameter[0] = 0;
  1022. }
  1023. EscapeSequence = FALSE;
  1024. //
  1025. // This is not a control or escape sequence, process single character.
  1026. //
  1027. } else {
  1028. switch (*String) {
  1029. //
  1030. // Check for escape sequence.
  1031. //
  1032. case ASCI_ESC:
  1033. EscapeSequence = TRUE;
  1034. break;
  1035. default:
  1036. p = TextCharOut(String);
  1037. //
  1038. // Each pass through the loop increments String by 1.
  1039. // If we output a dbcs char we need to increment by
  1040. // one more.
  1041. //
  1042. (*Count) += (p - String) - 1;
  1043. String += (p - String) - 1;
  1044. break;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. return Status;
  1050. }
  1051. ARC_STATUS
  1052. BiosDiskOpen(
  1053. IN ULONG DriveId,
  1054. IN OPEN_MODE OpenMode,
  1055. OUT PULONG FileId
  1056. )
  1057. /*++
  1058. Routine Description:
  1059. Opens a BIOS-accessible disk for raw sector access.
  1060. Arguments:
  1061. DriveId - Supplies the BIOS DriveId of the drive to open
  1062. 0 - Floppy 0
  1063. 1 - Floppy 1
  1064. 0x80 - Hard Drive 0
  1065. 0x81 - Hard Drive 1
  1066. 0x82 - Hard Drive 2
  1067. etc
  1068. High bit set and ID > 0x81 means the device is expected to be
  1069. a CD-ROM drive.
  1070. OpenMode - Supplies the mode of the open
  1071. FileId - Supplies a pointer to a variable that specifies the file
  1072. table entry that is filled in if the open is successful.
  1073. Return Value:
  1074. ESUCCESS is returned if the open operation is successful. Otherwise,
  1075. an unsuccessful status is returned that describes the reason for failure.
  1076. --*/
  1077. {
  1078. USHORT NumberHeads;
  1079. UCHAR NumberSectors;
  1080. USHORT NumberCylinders;
  1081. UCHAR NumberDrives;
  1082. ULONG Result;
  1083. PDRIVE_CONTEXT Context;
  1084. ULONG Retries;
  1085. BOOLEAN IsCd;
  1086. UCHAR *Buffer = FwDiskCache;
  1087. ULONG BufferSize = 512; // sector size
  1088. BOOLEAN xInt13;
  1089. DBGOUT(("BiosDiskOpen: enter, id = 0x%lx\r\n",DriveId));
  1090. //
  1091. // Check special drive number encoding for CD-ROM case
  1092. //
  1093. if(DriveId > 0x80000081) {
  1094. IsCd = TRUE;
  1095. DriveId &= 0x7fffffff;
  1096. } else {
  1097. IsCd = FALSE;
  1098. }
  1099. xInt13 = FALSE;
  1100. //
  1101. // If we are opening Floppy 0 or Floppy 1, we want to read the BPB off
  1102. // the disk so we can deal with all the odd disk formats.
  1103. //
  1104. // If we are opening a hard drive, we can just call the BIOS to find out
  1105. // its characteristics
  1106. //
  1107. if(DriveId < 128) {
  1108. PPACKED_BOOT_SECTOR BootSector;
  1109. BIOS_PARAMETER_BLOCK Bpb;
  1110. //
  1111. // Read the boot sector off the floppy and extract the cylinder,
  1112. // sector, and head information. We fake the CHS values here
  1113. // to allow sector 0 to be read before we actually know the
  1114. // geometry we want to use.
  1115. //
  1116. if(ReadPhysicalSectors((UCHAR)DriveId,0,1,Buffer,1,1,1,FALSE)) {
  1117. DBGOUT(("BiosDiskOpen: error reading from floppy drive\r\n"));
  1118. DBGPAUSE
  1119. return(EIO);
  1120. }
  1121. BootSector = (PPACKED_BOOT_SECTOR)Buffer;
  1122. FatUnpackBios(&Bpb, &(BootSector->PackedBpb));
  1123. NumberHeads = Bpb.Heads;
  1124. NumberSectors = (UCHAR)Bpb.SectorsPerTrack;
  1125. NumberCylinders = Bpb.Sectors / (NumberSectors * NumberHeads);
  1126. } else if(IsCd) {
  1127. //
  1128. // This is an El Torito drive
  1129. // Just use bogus values since CHS values are meaningless for no-emulation El Torito boot
  1130. //
  1131. NumberCylinders = 1;
  1132. NumberHeads = 1;
  1133. NumberSectors = 1;
  1134. } else {
  1135. //
  1136. // Get Drive Parameters via int13 function 8
  1137. // Return of 0 means success; otherwise we get back what the BIOS
  1138. // returned in ax.
  1139. //
  1140. ULONG Retries = 0;
  1141. do {
  1142. if(BIOS_IO(0x08,(UCHAR)DriveId,0,0,0,0,0)) {
  1143. DBGOUT(("BiosDiskOpen: error getting params for drive\r\n"));
  1144. DBGPAUSE
  1145. return(EIO);
  1146. }
  1147. //
  1148. // At this point, ECX looks like this:
  1149. //
  1150. // bits 31..22 - Maximum cylinder
  1151. // bits 21..16 - Maximum sector
  1152. // bits 15..8 - Maximum head
  1153. // bits 7..0 - Number of drives
  1154. //
  1155. // Unpack the information from ecx.
  1156. //
  1157. _asm {
  1158. mov Result, ecx
  1159. }
  1160. NumberDrives = (UCHAR)Result;
  1161. NumberHeads = (((USHORT)Result >> 8) & 0xff) + 1;
  1162. NumberSectors = (UCHAR)((Result >> 16) & 0x3f);
  1163. NumberCylinders = (USHORT)(((Result >> 24) + ((Result >> 14) & 0x300)) + 1);
  1164. ++Retries;
  1165. } while ( ((NumberHeads==0) || (NumberSectors==0) || (NumberCylinders==0))
  1166. && (Retries < 5) );
  1167. DBGOUT((
  1168. "BiosDiskOpen: cyl=%u, heads=%u, sect=%u, drives=%u\r\n",
  1169. NumberCylinders,
  1170. NumberHeads,
  1171. NumberSectors,
  1172. NumberDrives
  1173. ));
  1174. if(((UCHAR)DriveId & 0x7f) >= NumberDrives) {
  1175. //
  1176. // The requested drive does not exist
  1177. //
  1178. DBGOUT(("BiosDiskOpen: invalid drive\r\n"));
  1179. DBGPAUSE
  1180. return(EIO);
  1181. }
  1182. if (Retries == 5) {
  1183. DBGOUT(("Couldn't get BIOS configuration info\n"));
  1184. DBGPAUSE
  1185. return(EIO);
  1186. }
  1187. //
  1188. // Attempt to get extended int13 parameters.
  1189. // Note that we use a buffer that's on the stack, so it's guaranteed
  1190. // to be under the 1 MB line (required when passing buffers to real-mode
  1191. // services).
  1192. //
  1193. // Note that we don't actually care about the parameters, just whether
  1194. // extended int13 services are available.
  1195. //
  1196. RtlZeroMemory(Buffer,BufferSize);
  1197. xInt13 = GET_XINT13_PARAMS(Buffer,(UCHAR)DriveId);
  1198. DBGOUT(("BiosDiskOpen: xint13 for drive: %s\r\n",xInt13 ? "yes" : "no"));
  1199. }
  1200. //
  1201. // Find an available FileId descriptor to open the device with
  1202. //
  1203. *FileId=2;
  1204. while (BlFileTable[*FileId].Flags.Open != 0) {
  1205. *FileId += 1;
  1206. if(*FileId == BL_FILE_TABLE_SIZE) {
  1207. DBGOUT(("BiosDiskOpen: no file table entry available\r\n"));
  1208. DBGPAUSE
  1209. return(ENOENT);
  1210. }
  1211. }
  1212. //
  1213. // We found an entry we can use, so mark it as open.
  1214. //
  1215. BlFileTable[*FileId].Flags.Open = 1;
  1216. BlFileTable[*FileId].DeviceEntryTable = IsCd
  1217. ? &BiosEDDSEntryTable
  1218. : &BiosDiskEntryTable;
  1219. Context = &(BlFileTable[*FileId].u.DriveContext);
  1220. Context->IsCd = IsCd;
  1221. Context->Drive = (UCHAR)DriveId;
  1222. Context->Cylinders = NumberCylinders;
  1223. Context->Heads = NumberHeads;
  1224. Context->Sectors = NumberSectors;
  1225. Context->xInt13 = xInt13;
  1226. DBGOUT(("BiosDiskOpen: exit success\r\n"));
  1227. return(ESUCCESS);
  1228. }
  1229. ARC_STATUS
  1230. BiospWritePartialSector(
  1231. IN UCHAR Int13Unit,
  1232. IN ULONGLONG Sector,
  1233. IN PUCHAR Buffer,
  1234. IN BOOLEAN IsHead,
  1235. IN ULONG Bytes,
  1236. IN UCHAR SectorsPerTrack,
  1237. IN USHORT Heads,
  1238. IN USHORT Cylinders,
  1239. IN BOOLEAN AllowXInt13
  1240. )
  1241. {
  1242. ARC_STATUS Status;
  1243. //
  1244. // Read sector into the write buffer
  1245. //
  1246. Status = ReadPhysicalSectors(
  1247. Int13Unit,
  1248. Sector,
  1249. 1,
  1250. FwDiskCache,
  1251. SectorsPerTrack,
  1252. Heads,
  1253. Cylinders,
  1254. AllowXInt13
  1255. );
  1256. if(Status != ESUCCESS) {
  1257. return(Status);
  1258. }
  1259. //
  1260. // Transfer the appropriate bytes from the user buffer to the write buffer
  1261. //
  1262. RtlMoveMemory(
  1263. IsHead ? (FwDiskCache + Bytes) : FwDiskCache,
  1264. Buffer,
  1265. IsHead ? (SECTOR_SIZE - Bytes) : Bytes
  1266. );
  1267. //
  1268. // Write the sector out
  1269. //
  1270. Status = WritePhysicalSectors(
  1271. Int13Unit,
  1272. Sector,
  1273. 1,
  1274. FwDiskCache,
  1275. SectorsPerTrack,
  1276. Heads,
  1277. Cylinders,
  1278. AllowXInt13
  1279. );
  1280. return(Status);
  1281. }
  1282. ARC_STATUS
  1283. BiosDiskWrite(
  1284. IN ULONG FileId,
  1285. OUT PVOID Buffer,
  1286. IN ULONG Length,
  1287. OUT PULONG Count
  1288. )
  1289. /*++
  1290. Routine Description:
  1291. Writes sectors directly to an open physical disk.
  1292. Arguments:
  1293. FileId - Supplies the file to write to
  1294. Buffer - Supplies buffer with data to write
  1295. Length - Supplies number of bytes to write
  1296. Count - Returns actual bytes written
  1297. Return Value:
  1298. ESUCCESS - write completed successfully
  1299. !ESUCCESS - write failed
  1300. --*/
  1301. {
  1302. ULONGLONG HeadSector,TailSector,CurrentSector;
  1303. UCHAR Int13Unit;
  1304. ULONG HeadOffset,TailByteCount;
  1305. UCHAR SectorsPerTrack;
  1306. USHORT Heads,Cylinders;
  1307. BOOLEAN AllowXInt13;
  1308. ARC_STATUS Status;
  1309. ULONG BytesLeftToTransfer;
  1310. UCHAR SectorsToTransfer;
  1311. BOOLEAN Under1MegLine;
  1312. PVOID TransferBuffer;
  1313. PUCHAR UserBuffer;
  1314. ULONG PhysicalSectors;
  1315. BytesLeftToTransfer = Length;
  1316. PhysicalSectors = SECTOR_SIZE;
  1317. HeadSector = BlFileTable[FileId].Position.QuadPart / PhysicalSectors;
  1318. HeadOffset = (ULONG)(BlFileTable[FileId].Position.QuadPart % PhysicalSectors);
  1319. TailSector = (BlFileTable[FileId].Position.QuadPart + Length) / PhysicalSectors;
  1320. TailByteCount = (ULONG)((BlFileTable[FileId].Position.QuadPart + Length) % PhysicalSectors);
  1321. Int13Unit = BlFileTable[FileId].u.DriveContext.Drive;
  1322. SectorsPerTrack = BlFileTable[FileId].u.DriveContext.Sectors;
  1323. Heads = BlFileTable[FileId].u.DriveContext.Heads;
  1324. Cylinders = BlFileTable[FileId].u.DriveContext.Cylinders;
  1325. AllowXInt13 = BlFileTable[FileId].u.DriveContext.xInt13;
  1326. UserBuffer = Buffer;
  1327. //
  1328. // If this write will even partially write over the sector cached
  1329. // in the last read sector cache, invalidate the cache.
  1330. //
  1331. if (FwLastSectorCache.Initialized &&
  1332. FwLastSectorCache.Valid &&
  1333. (FwLastSectorCache.SectorNumber >= HeadSector) &&
  1334. (FwLastSectorCache.SectorNumber <= TailSector)) {
  1335. FwLastSectorCache.Valid = FALSE;
  1336. }
  1337. //
  1338. // Special case of transfer occuring entirely within one sector
  1339. //
  1340. CurrentSector = HeadSector;
  1341. if(HeadOffset && TailByteCount && (HeadSector == TailSector)) {
  1342. Status = ReadPhysicalSectors(
  1343. Int13Unit,
  1344. CurrentSector,
  1345. 1,
  1346. FwDiskCache,
  1347. SectorsPerTrack,
  1348. Heads,
  1349. Cylinders,
  1350. AllowXInt13
  1351. );
  1352. if(Status != ESUCCESS) {
  1353. goto BiosDiskWriteDone;
  1354. }
  1355. RtlMoveMemory(FwDiskCache+HeadOffset,Buffer,Length);
  1356. Status = WritePhysicalSectors(
  1357. Int13Unit,
  1358. CurrentSector,
  1359. 1,
  1360. FwDiskCache,
  1361. SectorsPerTrack,
  1362. Heads,
  1363. Cylinders,
  1364. AllowXInt13
  1365. );
  1366. if(Status != ESUCCESS) {
  1367. goto BiosDiskWriteDone;
  1368. }
  1369. BytesLeftToTransfer = 0;
  1370. goto BiosDiskWriteDone;
  1371. }
  1372. if(HeadOffset) {
  1373. Status = BiospWritePartialSector(
  1374. Int13Unit,
  1375. HeadSector,
  1376. Buffer,
  1377. TRUE,
  1378. HeadOffset,
  1379. SectorsPerTrack,
  1380. Heads,
  1381. Cylinders,
  1382. AllowXInt13
  1383. );
  1384. if(Status != ESUCCESS) {
  1385. return(Status);
  1386. }
  1387. BytesLeftToTransfer -= PhysicalSectors - HeadOffset;
  1388. UserBuffer += PhysicalSectors - HeadOffset;
  1389. CurrentSector += 1;
  1390. }
  1391. if(TailByteCount) {
  1392. Status = BiospWritePartialSector(
  1393. Int13Unit,
  1394. TailSector,
  1395. (PUCHAR)Buffer + Length - TailByteCount,
  1396. FALSE,
  1397. TailByteCount,
  1398. SectorsPerTrack,
  1399. Heads,
  1400. Cylinders,
  1401. AllowXInt13
  1402. );
  1403. if(Status != ESUCCESS) {
  1404. return(Status);
  1405. }
  1406. BytesLeftToTransfer -= TailByteCount;
  1407. }
  1408. //
  1409. // The following calculation is not inside the transfer loop because
  1410. // it is unlikely that a caller's buffer will *cross* the 1 meg line
  1411. // due to the PC memory map.
  1412. //
  1413. if((ULONG)UserBuffer + BytesLeftToTransfer <= 0x100000) {
  1414. Under1MegLine = TRUE;
  1415. } else {
  1416. Under1MegLine = FALSE;
  1417. }
  1418. //
  1419. // Now handle the middle part. This is some number of whole sectors.
  1420. //
  1421. while(BytesLeftToTransfer) {
  1422. //
  1423. // The number of sectors to transfer is the minimum of:
  1424. // - the number of sectors left in the current track
  1425. // - BytesLeftToTransfer / SECTOR_SIZE
  1426. //
  1427. // Because sectors per track is 1-63 we know this will fit in a UCHAR
  1428. //
  1429. SectorsToTransfer = (UCHAR)min(
  1430. SectorsPerTrack - (CurrentSector % SectorsPerTrack),
  1431. BytesLeftToTransfer / PhysicalSectors
  1432. );
  1433. //
  1434. // Now we'll figure out where to transfer the data from. If the
  1435. // caller's buffer is under the 1 meg line, we can transfer the
  1436. // data directly from the caller's buffer. Otherwise we'll copy the
  1437. // user's buffer to our local buffer and transfer from there.
  1438. // In the latter case we can only transfer in chunks of
  1439. // SCRATCH_BUFFER_SIZE because that's the size of the local buffer.
  1440. //
  1441. // Also make sure the transfer won't cross a 64k boundary.
  1442. //
  1443. if(Under1MegLine) {
  1444. //
  1445. // Check if the transfer would cross a 64k boundary. If so,
  1446. // use the local buffer. Otherwise use the user's buffer.
  1447. //
  1448. if(((ULONG)UserBuffer & 0xffff0000) !=
  1449. (((ULONG)UserBuffer + (SectorsToTransfer * PhysicalSectors) - 1) & 0xffff0000))
  1450. {
  1451. TransferBuffer = FwDiskCache;
  1452. SectorsToTransfer = min(SectorsToTransfer, SCRATCH_BUFFER_SIZE / (USHORT)PhysicalSectors);
  1453. } else {
  1454. TransferBuffer = UserBuffer;
  1455. }
  1456. } else {
  1457. TransferBuffer = FwDiskCache;
  1458. SectorsToTransfer = min(SectorsToTransfer, SCRATCH_BUFFER_SIZE / (USHORT)PhysicalSectors);
  1459. }
  1460. if(TransferBuffer == FwDiskCache) {
  1461. RtlMoveMemory(FwDiskCache,UserBuffer,SectorsToTransfer*PhysicalSectors);
  1462. }
  1463. Status = WritePhysicalSectors(
  1464. Int13Unit,
  1465. CurrentSector,
  1466. SectorsToTransfer,
  1467. TransferBuffer,
  1468. SectorsPerTrack,
  1469. Heads,
  1470. Cylinders,
  1471. AllowXInt13
  1472. );
  1473. if(Status != ESUCCESS) {
  1474. //
  1475. // Tail part isn't contiguous with middle part
  1476. //
  1477. BytesLeftToTransfer += TailByteCount;
  1478. return(Status);
  1479. }
  1480. CurrentSector += SectorsToTransfer;
  1481. BytesLeftToTransfer -= SectorsToTransfer * PhysicalSectors;
  1482. UserBuffer += SectorsToTransfer * PhysicalSectors;
  1483. }
  1484. Status = ESUCCESS;
  1485. BiosDiskWriteDone:
  1486. *Count = Length - BytesLeftToTransfer;
  1487. BlFileTable[FileId].Position.QuadPart += *Count;
  1488. return(Status);
  1489. }
  1490. ARC_STATUS
  1491. pBiosDiskReadWorker(
  1492. IN ULONG FileId,
  1493. OUT PVOID Buffer,
  1494. IN ULONG Length,
  1495. OUT PULONG Count,
  1496. IN USHORT SectorSize,
  1497. IN BOOLEAN xInt13
  1498. )
  1499. /*++
  1500. Routine Description:
  1501. Reads sectors directly from an open physical disk.
  1502. Arguments:
  1503. FileId - Supplies the file to read from
  1504. Buffer - Supplies buffer to hold the data that is read
  1505. Length - Supplies maximum number of bytes to read
  1506. Count - Returns actual bytes read
  1507. Return Value:
  1508. ESUCCESS - Read completed successfully
  1509. !ESUCCESS - Read failed
  1510. --*/
  1511. {
  1512. ULONGLONG HeadSector,TailSector,CurrentSector;
  1513. ULONG HeadOffset,TailByteCount;
  1514. USHORT Heads,Cylinders;
  1515. UCHAR SectorsPerTrack;
  1516. UCHAR Int13Unit;
  1517. ARC_STATUS Status;
  1518. UCHAR SectorsToTransfer;
  1519. ULONG NumBytesToTransfer;
  1520. BOOLEAN Under1MegLine;
  1521. PVOID TransferBuffer;
  1522. BOOLEAN AllowXInt13;
  1523. PUCHAR pDestInUserBuffer;
  1524. PUCHAR pEndOfUserBuffer;
  1525. PUCHAR pTransferDest;
  1526. PUCHAR pSrc;
  1527. ULONG CopyLength;
  1528. ULONG ReadLength;
  1529. PUCHAR pLastReadSector = NULL;
  1530. ULONGLONG LastReadSectorNumber;
  1531. PUCHAR TargetBuffer;
  1532. DBGOUT(("BiosDiskRead: enter; length=0x%lx, sector size=%u, xint13=%u\r\n",Length,SectorSize,xInt13));
  1533. //
  1534. // Reset number of bytes transfered.
  1535. //
  1536. *Count = 0;
  1537. //
  1538. // Complete 0 length requests immediately.
  1539. //
  1540. if (Length == 0) {
  1541. return ESUCCESS;
  1542. }
  1543. //
  1544. // Initialize the last sector cache if it has not been
  1545. // initialized.
  1546. //
  1547. if (!FwLastSectorCache.Initialized) {
  1548. FwLastSectorCache.Data =
  1549. FwAllocatePool(BL_LAST_SECTOR_CACHE_MAX_SIZE);
  1550. if (FwLastSectorCache.Data) {
  1551. FwLastSectorCache.Initialized = TRUE;
  1552. }
  1553. }
  1554. //
  1555. // Gather disk stats.
  1556. //
  1557. SectorsPerTrack = BlFileTable[FileId].u.DriveContext.Sectors;
  1558. Heads = BlFileTable[FileId].u.DriveContext.Heads;
  1559. Cylinders = BlFileTable[FileId].u.DriveContext.Cylinders;
  1560. AllowXInt13 = BlFileTable[FileId].u.DriveContext.xInt13;
  1561. Int13Unit = BlFileTable[FileId].u.DriveContext.Drive;
  1562. DBGOUT(("BiosDiskRead: unit 0x%x CHS=%lu %lu %lu\r\n",
  1563. Int13Unit,
  1564. Cylinders,
  1565. Heads,
  1566. SectorsPerTrack));
  1567. //
  1568. // Initialize locals that denote where we are in satisfying the
  1569. // request.
  1570. //
  1571. //
  1572. // If the buffer is in the first 1MB of KSEG0, we want to use the
  1573. // identity-mapped address
  1574. //
  1575. if (((ULONG_PTR)((PUCHAR)Buffer+Length) & ~KSEG0_BASE) < BIOSDISK_1MB) {
  1576. pDestInUserBuffer = (PUCHAR)((ULONG_PTR)Buffer & ~KSEG0_BASE);
  1577. } else {
  1578. pDestInUserBuffer = Buffer;
  1579. }
  1580. pEndOfUserBuffer = (PUCHAR) pDestInUserBuffer + Length;
  1581. TargetBuffer = pDestInUserBuffer;
  1582. //
  1583. // Calculating these before hand makes it easier to hand the
  1584. // special cases. Note that tail sector is the last sector this
  1585. // read wants bytes from. That is why we subtract one. We handle
  1586. // the Length == 0 case above.
  1587. //
  1588. HeadSector = BlFileTable[FileId].Position.QuadPart / SectorSize;
  1589. HeadOffset = (ULONG)(BlFileTable[FileId].Position.QuadPart % SectorSize);
  1590. TailSector = (BlFileTable[FileId].Position.QuadPart + Length - 1) / SectorSize;
  1591. TailByteCount = (ULONG)((BlFileTable[FileId].Position.QuadPart + Length - 1) % SectorSize);
  1592. TailByteCount ++;
  1593. //
  1594. // While there is data we should read, read.
  1595. //
  1596. CurrentSector = HeadSector;
  1597. while (pDestInUserBuffer != pEndOfUserBuffer) {
  1598. //
  1599. // Look to see if we can find the current sector we have to
  1600. // read in the last sector cache.
  1601. //
  1602. if (FwLastSectorCache.Valid &&
  1603. FwLastSectorCache.DeviceId == FileId &&
  1604. FwLastSectorCache.SectorNumber == CurrentSector) {
  1605. pSrc = FwLastSectorCache.Data;
  1606. CopyLength = SectorSize;
  1607. //
  1608. // Adjust copy parameters depending on whether
  1609. // this sector is the Head and/or Tail sector.
  1610. //
  1611. if (HeadSector == CurrentSector) {
  1612. pSrc += HeadOffset;
  1613. CopyLength -= HeadOffset;
  1614. }
  1615. if (TailSector == CurrentSector) {
  1616. CopyLength -= (SectorSize - TailByteCount);
  1617. }
  1618. //
  1619. // Copy the cached data to users buffer.
  1620. //
  1621. RtlCopyMemory(pDestInUserBuffer, pSrc, CopyLength);
  1622. //
  1623. // Update our status.
  1624. //
  1625. CurrentSector += 1;
  1626. pDestInUserBuffer += CopyLength;
  1627. *Count += CopyLength;
  1628. continue;
  1629. }
  1630. //
  1631. // Calculate number of sectors we have to read. Read a maximum
  1632. // of SCRATCH_BUFFER_SIZE so we can use our local buffer if the
  1633. // user's buffer crosses 64KB boundary or is not under 1MB.
  1634. //
  1635. SectorsToTransfer = (UCHAR)min ((LONG) (TailSector - CurrentSector + 1),
  1636. SCRATCH_BUFFER_SIZE / SectorSize);
  1637. if (!xInt13) {
  1638. //
  1639. // Make sure the number of sectors to transfer does not exceed
  1640. // the number of sectors left in the track.
  1641. //
  1642. SectorsToTransfer = (UCHAR)min(SectorsPerTrack - (CurrentSector % SectorsPerTrack),
  1643. SectorsToTransfer);
  1644. }
  1645. NumBytesToTransfer = SectorsToTransfer * SectorSize;
  1646. //
  1647. // Determine where we want to read into. We can use the
  1648. // current chunk of user buffer only if it is under 1MB and
  1649. // does not cross a 64KB boundary, and it can take all we want
  1650. // to read into it.
  1651. //
  1652. if (((ULONG_PTR) pDestInUserBuffer + NumBytesToTransfer < BIOSDISK_1MB) &&
  1653. (((ULONG_PTR) pDestInUserBuffer & BIOSDISK_64KB_MASK) ==
  1654. (((ULONG_PTR) pDestInUserBuffer + NumBytesToTransfer) & BIOSDISK_64KB_MASK)) &&
  1655. ((pEndOfUserBuffer - pDestInUserBuffer) >= (LONG) NumBytesToTransfer)) {
  1656. pTransferDest = pDestInUserBuffer;
  1657. } else {
  1658. pTransferDest = FwDiskCache;
  1659. }
  1660. //
  1661. // Perform the read.
  1662. //
  1663. if(xInt13) {
  1664. Status = ReadExtendedPhysicalSectors(Int13Unit,
  1665. CurrentSector,
  1666. SectorsToTransfer,
  1667. pTransferDest);
  1668. } else {
  1669. Status = ReadPhysicalSectors(Int13Unit,
  1670. CurrentSector,
  1671. SectorsToTransfer,
  1672. pTransferDest,
  1673. SectorsPerTrack,
  1674. Heads,
  1675. Cylinders,
  1676. AllowXInt13);
  1677. }
  1678. if(Status != ESUCCESS) {
  1679. DBGOUT(("BiosDiskRead: read failed with %u\r\n",Status));
  1680. goto BiosDiskReadDone;
  1681. }
  1682. //
  1683. // Note the last sector that was read from the disk.
  1684. //
  1685. pLastReadSector = pTransferDest + (SectorsToTransfer - 1) * SectorSize;
  1686. LastReadSectorNumber = CurrentSector + SectorsToTransfer - 1;
  1687. //
  1688. // Note the amount read.
  1689. //
  1690. ReadLength = NumBytesToTransfer;
  1691. //
  1692. // Copy transfered data into user's buffer if we did not
  1693. // directly read into that.
  1694. //
  1695. if (pTransferDest != pDestInUserBuffer) {
  1696. pSrc = pTransferDest;
  1697. CopyLength = NumBytesToTransfer;
  1698. //
  1699. // Adjust copy parameters depending on whether
  1700. // we have read the Head and/or Tail sectors.
  1701. //
  1702. if (HeadSector == CurrentSector) {
  1703. pSrc += HeadOffset;
  1704. CopyLength -= HeadOffset;
  1705. }
  1706. if (TailSector == CurrentSector + SectorsToTransfer - 1) {
  1707. CopyLength -= (SectorSize - TailByteCount);
  1708. }
  1709. //
  1710. // Copy the read data to users buffer.
  1711. //
  1712. ASSERT(pDestInUserBuffer >= TargetBuffer);
  1713. ASSERT(pEndOfUserBuffer >= pDestInUserBuffer + CopyLength);
  1714. ASSERT(CopyLength <= SCRATCH_BUFFER_SIZE);
  1715. ASSERT(pSrc >= (PUCHAR) FwDiskCache);
  1716. ASSERT(pSrc < (PUCHAR) FwDiskCache + SCRATCH_BUFFER_SIZE);
  1717. RtlCopyMemory(pDestInUserBuffer, pSrc, CopyLength);
  1718. //
  1719. // Adjust the amount read into user's buffer.
  1720. //
  1721. ReadLength = CopyLength;
  1722. }
  1723. //
  1724. // Update our status.
  1725. //
  1726. CurrentSector += SectorsToTransfer;
  1727. pDestInUserBuffer += ReadLength;
  1728. *Count += ReadLength;
  1729. }
  1730. //
  1731. // Update the last read sector cache.
  1732. //
  1733. if (pLastReadSector &&
  1734. FwLastSectorCache.Initialized &&
  1735. BL_LAST_SECTOR_CACHE_MAX_SIZE >= SectorSize) {
  1736. FwLastSectorCache.DeviceId = FileId;
  1737. FwLastSectorCache.SectorNumber = LastReadSectorNumber;
  1738. RtlCopyMemory(FwLastSectorCache.Data,
  1739. pLastReadSector,
  1740. SectorSize);
  1741. FwLastSectorCache.Valid = TRUE;
  1742. }
  1743. DBGOUT(("BiosDiskRead: exit success\r\n"));
  1744. Status = ESUCCESS;
  1745. BiosDiskReadDone:
  1746. BlFileTable[FileId].Position.QuadPart += *Count;
  1747. return(Status);
  1748. }
  1749. ARC_STATUS
  1750. BiosDiskRead(
  1751. IN ULONG FileId,
  1752. OUT PVOID Buffer,
  1753. IN ULONG Length,
  1754. OUT PULONG Count
  1755. )
  1756. {
  1757. USHORT PhysicalSectors;
  1758. PhysicalSectors = SECTOR_SIZE;
  1759. return(pBiosDiskReadWorker(FileId,Buffer,Length,Count,PhysicalSectors,FALSE));
  1760. }
  1761. ARC_STATUS
  1762. BiosElToritoDiskRead(
  1763. IN ULONG FileId,
  1764. OUT PVOID Buffer,
  1765. IN ULONG Length,
  1766. OUT PULONG Count
  1767. )
  1768. {
  1769. return(pBiosDiskReadWorker(FileId,Buffer,Length,Count,2048,TRUE));
  1770. }
  1771. ARC_STATUS
  1772. BiosPartitionGetFileInfo(
  1773. IN ULONG FileId,
  1774. OUT PFILE_INFORMATION Finfo
  1775. )
  1776. {
  1777. //
  1778. // THIS ROUTINE DOES NOT WORK FOR PARTITION 0.
  1779. //
  1780. PPARTITION_CONTEXT Context;
  1781. RtlZeroMemory(Finfo, sizeof(FILE_INFORMATION));
  1782. Context = &BlFileTable[FileId].u.PartitionContext;
  1783. Finfo->StartingAddress.QuadPart = Context->StartingSector;
  1784. Finfo->StartingAddress.QuadPart = Finfo->StartingAddress.QuadPart << (CCHAR)Context->SectorShift;
  1785. Finfo->EndingAddress.QuadPart = Finfo->StartingAddress.QuadPart + Context->PartitionLength.QuadPart;
  1786. Finfo->Type = DiskPeripheral;
  1787. return ESUCCESS;
  1788. }
  1789. ARC_STATUS
  1790. BiosDiskGetFileInfo(
  1791. IN ULONG FileId,
  1792. OUT PFILE_INFORMATION FileInfo
  1793. )
  1794. /*++
  1795. Routine Description:
  1796. Gets the information about the isk.
  1797. Arguments:
  1798. FileId - The file id to the disk for which information is needed
  1799. FileInfo - Place holder for returning information about the disk
  1800. Return Value:
  1801. ESUCCESS if successful, otherwise appropriate ARC error code.
  1802. --*/
  1803. {
  1804. ARC_STATUS Result = EINVAL;
  1805. if (FileInfo) {
  1806. PDRIVE_CONTEXT DriveContext;
  1807. LONGLONG DriveSize = 0;
  1808. ULONG SectorSize = SECTOR_SIZE;
  1809. DriveContext = &(BlFileTable[FileId].u.DriveContext);
  1810. Result = EIO;
  1811. //
  1812. // NOTE : SectorSize == 512 bytes for everything except
  1813. // Eltorito disks for which sector size is 2048.
  1814. //
  1815. if (DriveContext->IsCd) {
  1816. SectorSize = 2048;
  1817. }
  1818. DriveSize = (DriveContext->Heads * DriveContext->Cylinders *
  1819. DriveContext->Sectors * SectorSize);
  1820. if (DriveSize) {
  1821. RtlZeroMemory(FileInfo, sizeof(FILE_INFORMATION));
  1822. FileInfo->StartingAddress.QuadPart = 0;
  1823. FileInfo->EndingAddress.QuadPart = DriveSize;
  1824. FileInfo->CurrentPosition = BlFileTable[FileId].Position;
  1825. //
  1826. // Any thing less than 3MB is floppy drive
  1827. //
  1828. if (DriveSize <= 0x300000) {
  1829. FileInfo->Type = FloppyDiskPeripheral;
  1830. } else {
  1831. FileInfo->Type = DiskPeripheral;
  1832. }
  1833. Result = ESUCCESS;
  1834. }
  1835. }
  1836. return Result;
  1837. }