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.

184 lines
6.9 KiB

  1. #include <windows.h>
  2. #include <string.h>
  3. #include "driveex.h"
  4. #if 0
  5. /* // See the "MS-DOS Programmer's Reference" for further information
  6. // about this structure. */
  7. typedef struct tagDEVICEPARAMS
  8. {
  9. BYTE bSpecFunc; /* Special functions */
  10. BYTE bDevType; /* Device type */
  11. WORD wDevAttr; /* Device attributes */
  12. WORD wCylinders; /* Number of cylinders */
  13. BYTE bMediaType; /* Media type */
  14. /* Beginning of BIOS parameter block (BPB) */
  15. WORD wBytesPerSec; /* Bytes per sector */
  16. BYTE bSecPerClust; /* Sectors per cluster */
  17. WORD wResSectors; /* Number of reserved sectors */
  18. BYTE bFATs; /* Number of FATs */
  19. WORD wRootDirEnts; /* Number of root-directory entries */
  20. WORD wSectors; /* Total number of sectors */
  21. BYTE bMedia; /* Media descriptor */
  22. WORD wFATsecs; /* Number of sectors per FAT */
  23. WORD wSecPerTrack; /* Number of sectors per track */
  24. WORD wHeads; /* Number of heads */
  25. DWORD dwHiddenSecs; /* Number of hidden sectors */
  26. DWORD dwHugeSectors; /* Number of sectors if wSectors == 0 */
  27. /* End of BIOS parameter block (BPB) */
  28. } DEVICEPARAMS, FAR * LPDEVICEPARAMS;
  29. /* Function prototypes */
  30. BOOL GetDeviceParameters (int nDrive, LPDEVICEPARAMS dp);
  31. BOOL IsCDRomDrive (int nDrive);
  32. /*----------------------------------------------------------------- */
  33. /* GetDeviceParameters() */
  34. /* */
  35. /* Fills a DEVICEPARAMS struct with info about the given drive. */
  36. /* Calls DOS IOCTL Get Device Parameters (440Dh, 60h) function. */
  37. /* */
  38. /* Parameters */
  39. /* nDrive Drive number 0 = A, 1 = B, 2 = C, and so on. */
  40. /* dp Pointer to a structure that will contain the drive's */
  41. /* parameters. */
  42. /* */
  43. /* Returns TRUE if it succeeded, FALSE if it failed. */
  44. /*----------------------------------------------------------------- */
  45. #pragma warning(disable:4704) /* in-line asm precludes global optimizations */
  46. BOOL GetDeviceParameters (int nDrive, LPDEVICEPARAMS dp)
  47. {
  48. BOOL bResult = TRUE; /* Assume success */
  49. __asm {
  50. push ds
  51. mov bx, nDrive
  52. inc bx /* Convert 0-based #'s to 1-based #s */
  53. mov ch, 08h /* Device category--must be 08h */
  54. mov cl, 60h /* MS-DOS IOCTL Get Device Parameters */
  55. lds dx, dp
  56. mov ax, 440Dh
  57. int 21h
  58. jnc gdp_done /* CF SET if error */
  59. mov bResult, FALSE
  60. gdp_done:
  61. pop ds
  62. }
  63. return (bResult);
  64. }
  65. #pragma warning(default:4704) /* in-line asm precludes global optimizations */
  66. /*----------------------------------------------------------------- */
  67. /* IsCDRomDrive() */
  68. /* */
  69. /* Determines if a drive is a CD-ROM. Calls MSCDEX and checks */
  70. /* that MSCDEX is loaded, and that MSCDEX reports the drive is a */
  71. /* CD-ROM. */
  72. /* */
  73. /* Parameters */
  74. /* nDrive Drive number 0 = A, 1 = B, 2 = C, and so forth. */
  75. /* */
  76. /* Returns TRUE if nDrive is a CD-ROM drive, FALSE if it isn't. */
  77. /*----------------------------------------------------------------- */
  78. #pragma warning(disable:4704) /* in-line asm precludes global optimizations */
  79. BOOL IsCDRomDrive (int nDrive)
  80. {
  81. BOOL bResult = FALSE; /* Assume not a CD-ROM drive */
  82. __asm {
  83. mov ax, 150Bh /* MSCDEX CD-ROM Drive Check */
  84. xor bx, bx
  85. mov cx, nDrive
  86. int 2Fh
  87. cmp bx, 0ADADh /* Check MSCDEX signature */
  88. jne not_cd_drive
  89. or ax, ax /* Check the drive type */
  90. jz not_cd_drive /* 0 (zero) means not CD-ROM */
  91. mov bResult, TRUE
  92. not_cd_drive:
  93. }
  94. return (bResult);
  95. }
  96. #pragma warning(default:4704) /* in-line asm precludes global optimizations */
  97. #endif
  98. /*----------------------------------------------------------------- */
  99. /* GetDriveTypeEx() */
  100. /* */
  101. /* Determines the type of a drive. Calls Windows's GetDriveType */
  102. /* to determine if a drive is valid, fixed, remote, or removeable, */
  103. /* then breaks down these categories further to specific device */
  104. /* types. */
  105. /* */
  106. /* Parameters */
  107. /* nDrive Drive number 0 = A, 1 = B, 2 = C, etc. */
  108. /* */
  109. /* Returns one of: */
  110. /* EX_DRIVE_INVALID -- Drive not detected */
  111. /* EX_DRIVE_REMOVABLE -- Unknown removable-media type drive */
  112. /* EX_DRIVE_FIXED -- Hard disk drive */
  113. /* EX_DRIVE_REMOTE -- Remote drive on a network */
  114. /* EX_DRIVE_CDROM -- CD-ROM drive */
  115. /* EX_DRIVE_FLOPPY -- Floppy disk drive */
  116. /* EX_DRIVE_RAMDISK -- RAM disk */
  117. /*----------------------------------------------------------------- */
  118. UINT GetDriveTypeEx (int nDrive)
  119. {
  120. #if 0
  121. DEVICEPARAMS dp;
  122. UINT uType;
  123. _fmemset (&dp, 0, sizeof(dp)); /* Init device params struct */
  124. uType = GetDriveType (nDrive);
  125. switch (uType)
  126. {
  127. case DRIVE_REMOTE:
  128. /* GetDriveType() reports CD-ROMs as Remote drives. Need */
  129. /* to see if the drive is a CD-ROM or a network drive. */
  130. if (IsCDRomDrive (nDrive))
  131. return (EX_DRIVE_CDROM);
  132. else
  133. return (EX_DRIVE_REMOTE);
  134. break;
  135. case DRIVE_REMOVABLE:
  136. /* Check for a floppy disk drive. If it isn't, then we */
  137. /* don't know what kind of removable media it is. */
  138. /* For example, could be a Bernoulli box or something new... */
  139. if (GetDeviceParameters (nDrive, &dp))
  140. switch (dp.bDevType)
  141. {
  142. /* Floppy disk drive types */
  143. case 0x0: case 0x1: case 0x2: case 0x3:
  144. case 0x4: case 0x7: case 0x8:
  145. return (EX_DRIVE_FLOPPY);
  146. }
  147. return (EX_DRIVE_REMOVABLE); /* Unknown removable media type */
  148. break;
  149. case DRIVE_FIXED:
  150. /* GetDeviceParameters returns a device type of 0x05 for */
  151. /* hard disks. Because hard disks and RAM disks are the two */
  152. /* types of fixed-media drives, we assume that any fixed- */
  153. /* media drive that isn't a hard disk is a RAM disk. */
  154. if (GetDeviceParameters (nDrive, &dp) && dp.bDevType == 0x05)
  155. return (EX_DRIVE_FIXED);
  156. else
  157. return (EX_DRIVE_RAMDISK);
  158. break;
  159. #endif
  160. UINT uType;
  161. CHAR achRoot[4];
  162. achRoot[0] = 'A'+nDrive;
  163. achRoot[1] = ':';
  164. achRoot[2] = '\\';
  165. achRoot[3] = 0;
  166. uType = GetDriveTypeA (achRoot);
  167. switch (uType)
  168. {
  169. case DRIVE_REMOVABLE:
  170. return (EX_DRIVE_REMOVABLE); /* Unknown removable media type */
  171. case DRIVE_FIXED:
  172. return (EX_DRIVE_FIXED);
  173. case DRIVE_REMOTE:
  174. return (EX_DRIVE_REMOTE);
  175. case DRIVE_CDROM:
  176. return (EX_DRIVE_CDROM);
  177. case DRIVE_RAMDISK:
  178. return (EX_DRIVE_RAMDISK);
  179. }
  180. return (EX_DRIVE_INVALID); /* Drive is invalid if we get here. */
  181. }