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.

407 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. diskkd.c
  5. Abstract:
  6. Debugger Extension Api for interpretting cdrom structure
  7. Author:
  8. Henry Gabryjelski (henrygab) 16-Feb-1999
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. #include "classpnp.h" // #defines ALLOCATE_SRB_FROM_POOL as needed
  15. #include "classp.h" // Classpnp's private definitions
  16. #include "disk.h"
  17. #include "classkd.h" // routines that are useful for all class drivers
  18. /*
  19. FLAG_NAME XAFlags[] = {
  20. FLAG_NAME(XA_USE_6_BYTE), // 0x01
  21. FLAG_NAME(XA_USE_10_BYTE), // 0x02
  22. FLAG_NAME(XA_USE_READ_CD), // 0x04
  23. FLAG_NAME(XA_NOT_SUPPORTED), // 0x08
  24. FLAG_NAME(XA_PLEXTOR_CDDA), // 0x10
  25. FLAG_NAME(XA_NEC_CDDA), // 0x20
  26. {0,0}
  27. };
  28. */
  29. VOID
  30. ClassDumpDiskData(
  31. IN ULONG64 CdData,
  32. ULONG Detail,
  33. ULONG Depth
  34. );
  35. DECLARE_API(diskext)
  36. /*++
  37. Routine Description:
  38. Dumps the cdrom specific data for a given device object or
  39. given device extension
  40. Arguments:
  41. args - string containing the address of the device object or device
  42. extension
  43. Return Value:
  44. none
  45. --*/
  46. {
  47. ULONG64 address;
  48. ULONG result;
  49. ULONG detail = 0;
  50. BOOLEAN IsFdo;
  51. ULONG64 DriverData;
  52. ASSERTMSG("data block too small to hold CDROM_DATA\n",
  53. sizeof(FUNCTIONAL_DEVICE_EXTENSION) > sizeof(DISK_DATA));
  54. ASSERTMSG("data block too small to hold DEVICE_OBJECT\n",
  55. sizeof(FUNCTIONAL_DEVICE_EXTENSION) > sizeof(DEVICE_OBJECT));
  56. GetAddressAndDetailLevel64(args, &address, &detail);
  57. //
  58. // Convert the supplied address into a device extension if it is
  59. // the address of a device object.
  60. //
  61. address = GetDeviceExtension(address);
  62. dprintf("DeviceExtension:%p\n", address);
  63. InitTypeRead(address, classpnp!_COMMON_DEVICE_EXTENSION);
  64. IsFdo = (BOOLEAN)ReadField(IsFdo);
  65. DriverData = ReadField(DriverData);
  66. dprintf("DriverData:%p\n", DriverData);
  67. if(!IsFdo) {
  68. xdprintfEx(0, ("Not an FDO\n"));
  69. return E_FAIL;
  70. }
  71. //
  72. // dump the class-specific information if detail != 0
  73. //
  74. if (detail != 0) {
  75. ClassDumpCommonExtension(address,
  76. detail,
  77. 0);
  78. }
  79. ClassDumpDiskData(DriverData,
  80. detail,
  81. 0);
  82. return S_OK;
  83. }
  84. VOID
  85. ClassDumpDiskData(
  86. IN ULONG64 DiskData,
  87. IN ULONG Detail,
  88. IN ULONG Depth
  89. )
  90. {
  91. ULONG result;
  92. ULONG PartitionStyle;
  93. ULONG PartitionOrdinal;
  94. ULONG MbrSignature;
  95. ULONG MbrCheckSum;
  96. UCHAR MbrPartitionType;
  97. BOOLEAN MbrBootIndicator;
  98. ULONG MbrHiddenSectors;
  99. ULONG GeometrySource;
  100. ULONG64 RGCylinders;
  101. ULONG RGMediaType;
  102. ULONG RGTracksPerCylinder;
  103. ULONG RGSectorsPerTrack;
  104. ULONG RGBytesPerSector;
  105. ULONG ReadyStatus;
  106. ULONG FailurePredictionCapability;
  107. BOOLEAN AllowFPPerfHit;
  108. BOOLEAN LSWellKnownNameCreated;
  109. BOOLEAN LSPhysicalDriveLinkCreated;
  110. ULONG64 PartitionInterfaceStringBuffer;
  111. USHORT PartitionInterfaceStringLength;
  112. ULONG64 DiskInterfaceStringBuffer;
  113. USHORT DiskInterfaceStringLength;
  114. FIELD_INFO deviceFields[] = {
  115. {"PartitionStyle", NULL, 0, COPY, 0, (PVOID) &PartitionStyle},
  116. {"PartitionOrdinal", NULL, 0, COPY, 0, (PVOID) &PartitionOrdinal},
  117. {"Mbr.Signature", NULL, 0, COPY, 0, (PVOID) &MbrSignature},
  118. {"Mbr.MbrCheckSum", NULL, 0, COPY, 0, (PVOID) &MbrCheckSum},
  119. {"Mbr.PartitionType", NULL, 0, COPY, 0, (PVOID) &MbrPartitionType},
  120. {"Mbr.BootIndicator", NULL, 0, COPY, 0, (PVOID) &MbrBootIndicator},
  121. {"Mbr.HiddenSectors", NULL, 0, COPY, 0, (PVOID) &MbrHiddenSectors},
  122. {"GeometrySource", NULL, 0, COPY, 0, (PVOID) &GeometrySource},
  123. {"RealGeometry.Cylinders", NULL, 0, COPY, 0, (PVOID) &RGCylinders},
  124. {"RealGeometry.MediaType", NULL, 0, COPY, 0, (PVOID) &RGMediaType},
  125. {"RealGeometry.TracksPerCylinder", NULL, 0, COPY, 0, (PVOID) &RGTracksPerCylinder},
  126. {"RealGeometry.SectorsPerTrack", NULL, 0, COPY, 0, (PVOID) &RGSectorsPerTrack},
  127. {"RealGeometry.BytesPerSector", NULL, 0, COPY, 0, (PVOID) &RGBytesPerSector},
  128. {"ReadyStatus", NULL, 0, COPY, 0, (PVOID) &ReadyStatus},
  129. {"FailurePredictionCapability", NULL, 0, COPY, 0, (PVOID) &FailurePredictionCapability},
  130. {"AllowFPPerfHit", NULL, 0, COPY, 0, (PVOID) &AllowFPPerfHit},
  131. {"LinkStatus.WellKnownNameCreated", NULL, 0, COPY, 0, (PVOID) &LSWellKnownNameCreated},
  132. {"LinkStatus.PhysicalDriveLinkCreated", NULL, 0, COPY, 0, (PVOID) &LSPhysicalDriveLinkCreated},
  133. {"PartitionInterfaceString.Buffer", NULL, 0, COPY, 0, (PVOID) &PartitionInterfaceStringBuffer},
  134. {"PartitionInterfaceString.Length", NULL, 0, COPY, 0, (PVOID) &PartitionInterfaceStringLength},
  135. {"DiskInterfaceString.Buffer", NULL, 0, COPY, 0, (PVOID) &DiskInterfaceStringBuffer},
  136. {"DiskInterfaceString.Length", NULL, 0, COPY, 0, (PVOID) &DiskInterfaceStringLength},
  137. };
  138. FIELD_INFO deviceFields64[] = {
  139. {"PartitionStyle", NULL, 0, COPY, 0, (PVOID) &PartitionStyle},
  140. {"PartitionOrdinal", NULL, 0, COPY, 0, (PVOID) &PartitionOrdinal},
  141. {"Mbr.Signature", NULL, 0, COPY, 0, (PVOID) &MbrSignature},
  142. {"Mbr.MbrCheckSum", NULL, 0, COPY, 0, (PVOID) &MbrCheckSum},
  143. {"Mbr.PartitionType", NULL, 0, COPY, 0, (PVOID) &MbrPartitionType},
  144. {"Mbr.BootIndicator", NULL, 0, COPY, 0, (PVOID) &MbrBootIndicator},
  145. {"Mbr.HiddenSectors", NULL, 0, COPY, 0, (PVOID) &MbrHiddenSectors},
  146. {"ReadyStatus", NULL, 0, COPY, 0, (PVOID) &ReadyStatus},
  147. {"FailurePredictionCapability", NULL, 0, COPY, 0, (PVOID) &FailurePredictionCapability},
  148. {"AllowFPPerfHit", NULL, 0, COPY, 0, (PVOID) &AllowFPPerfHit},
  149. {"LinkStatus.WellKnownNameCreated", NULL, 0, COPY, 0, (PVOID) &LSWellKnownNameCreated},
  150. {"LinkStatus.PhysicalDriveLinkCreated", NULL, 0, COPY, 0, (PVOID) &LSPhysicalDriveLinkCreated},
  151. {"PartitionInterfaceString.Buffer", NULL, 0, COPY, 0, (PVOID) &PartitionInterfaceStringBuffer},
  152. {"PartitionInterfaceString.Length", NULL, 0, COPY, 0, (PVOID) &PartitionInterfaceStringLength},
  153. {"DiskInterfaceString.Buffer", NULL, 0, COPY, 0, (PVOID) &DiskInterfaceStringBuffer},
  154. {"DiskInterfaceString.Length", NULL, 0, COPY, 0, (PVOID) &DiskInterfaceStringLength},
  155. };
  156. SYM_DUMP_PARAM DevSym = {
  157. sizeof (SYM_DUMP_PARAM),
  158. "disk!_DISK_DATA",
  159. DBG_DUMP_NO_PRINT,
  160. DiskData,
  161. NULL, NULL, NULL,
  162. sizeof (deviceFields) / sizeof (FIELD_INFO),
  163. &deviceFields[0]
  164. };
  165. SYM_DUMP_PARAM DevSym64 = {
  166. sizeof (SYM_DUMP_PARAM),
  167. "disk!_DISK_DATA",
  168. DBG_DUMP_NO_PRINT,
  169. DiskData,
  170. NULL, NULL, NULL,
  171. sizeof (deviceFields64) / sizeof (FIELD_INFO),
  172. &deviceFields64[0]
  173. };
  174. if (IsPtr64()) {
  175. result = Ioctl(IG_DUMP_SYMBOL_INFO, &DevSym64, DevSym64.size);
  176. } else {
  177. result = Ioctl(IG_DUMP_SYMBOL_INFO, &DevSym, DevSym.size);
  178. }
  179. if (result) {
  180. SCSIKD_PRINT_ERROR(result);
  181. return;
  182. }
  183. xdprintfEx(Depth, ("DiskData @ %p:\n", DiskData));
  184. Depth +=1;
  185. if (PartitionStyle == PARTITION_STYLE_GPT) {
  186. xdprintfEx (Depth, ("ERROR: GPT disks are not yet supported\n"));
  187. return;
  188. }
  189. xdprintfEx(Depth, ("Signature %x MbrCheckSum %x\n",
  190. MbrSignature,
  191. MbrCheckSum
  192. ));
  193. xdprintfEx(Depth, ("Partition %x Type %x Bootable %x HiddenSectors %x\n",
  194. PartitionOrdinal,
  195. MbrPartitionType,
  196. MbrBootIndicator,
  197. MbrHiddenSectors
  198. ));
  199. if (!IsPtr64()) {
  200. PUCHAR source[] = {
  201. "Unknown", "FromBios", "FromPort", "FromNec98",
  202. "GuessedFromBios", "FromDefault"
  203. };
  204. PUCHAR media[] = {
  205. "Unknown",
  206. "5.25\" 1.20MB 512 bytes per sector",
  207. "3.5\" 1.44MB 512 bytes per sector",
  208. "3.5\" 2.88MB 512 bytes per sector",
  209. "3.5\" 20.8MB 512 bytes per sector",
  210. "3.5\" 720KB 512 bytes per sector",
  211. "5.25\" 360KB 512 bytes per sector",
  212. "5.25\" 320KB 512 bytes per sector",
  213. "5.25\" 320KB 1024 bytes per sector",
  214. "5.25\" 180KB 512 bytes per sector",
  215. "5.25\" 160KB 512 bytes per sector",
  216. "Removable media other than floppy",
  217. "Fixed hard disk media",
  218. "3.5\" 120MB Floppy",
  219. "3.5\" 640KB 512 bytes per sector",
  220. "5.25\" 640KB 512 bytes per sector",
  221. "5.25\" 720KB 512 bytes per sector",
  222. "3.5\" 1.20MB 512 bytes per sector",
  223. "3.5\" 1.23MB 1024 bytes per sector",
  224. "5.25\" 1.23MB 1024 bytes per sector",
  225. "3.5\" MO 128MB 512 bytes per sector",
  226. "3.5\" MO 230MB 512 bytes per sector",
  227. "8\" 256KB 128 bytes per sector"
  228. };
  229. if (RGMediaType >
  230. (sizeof(media)/sizeof(PUCHAR))
  231. ) {
  232. xdprintfEx(Depth, ("New Media Type: %x (?)\n",
  233. RGMediaType
  234. ));
  235. RGMediaType = 0;
  236. }
  237. xdprintfEx(Depth, ("MediaType: %s\n",
  238. media[RGMediaType]
  239. ));
  240. xdprintfEx(Depth, ("Geometry Source: %s\n",
  241. source[GeometrySource]
  242. ));
  243. xdprintfEx(Depth, ("Cylinders: %I64x Tracks Per Cylinder %x\n",
  244. RGCylinders,
  245. RGTracksPerCylinder
  246. ));
  247. xdprintfEx(Depth, ("Sectors Per Track %x Bytes Per Sector %x\n",
  248. RGSectorsPerTrack,
  249. RGBytesPerSector
  250. ));
  251. }
  252. if (!NT_SUCCESS(ReadyStatus)) {
  253. xdprintfEx(Depth, ("Disk is in non-ready status %x\n",
  254. ReadyStatus
  255. ));
  256. }
  257. //
  258. // print fault-predication state
  259. //
  260. {
  261. PUCHAR fpTypes[] = {
  262. "No fault prediction available",
  263. "IOCTL available to derive fault prediction",
  264. "S.M.A.R.T. available to report fault prediction",
  265. "Sense data available to derive fault prediction"
  266. };
  267. if (FailurePredictionCapability >
  268. (sizeof(fpTypes)/sizeof(PUCHAR))
  269. ) {
  270. xdprintfEx(Depth, ("Unknown fault-prediction method %x\n",
  271. FailurePredictionCapability));
  272. } else {
  273. xdprintfEx(Depth, ("%s\n",
  274. fpTypes[FailurePredictionCapability]
  275. ));
  276. }
  277. xdprintfEx(Depth, ("Performance hit%s allowed for fault-prediction code\n",
  278. (AllowFPPerfHit ? "" : " not")
  279. ));
  280. }
  281. xdprintfEx(Depth, ("Well-known name was%s created\n",
  282. (LSWellKnownNameCreated ? "" : " not")
  283. ));
  284. xdprintfEx(Depth, ("Physical drive link was%s created\n",
  285. (LSPhysicalDriveLinkCreated ? "" : " not")
  286. ));
  287. {
  288. UNICODE_STRING string;
  289. WCHAR buffer[250];
  290. ULONG64 stringAddress;
  291. ULONG result;
  292. string.MaximumLength = 250;
  293. string.Buffer = buffer;
  294. xdprintfEx(Depth, ("Partition Name: "));
  295. stringAddress = PartitionInterfaceStringBuffer;
  296. string.Length = PartitionInterfaceStringLength;
  297. if (string.Length == 0) {
  298. dprintf("NULL\n");
  299. } else if (string.Length > string.MaximumLength) {
  300. dprintf("Too long (@ %p)\n", stringAddress);
  301. } else if (!ReadMemory(stringAddress,
  302. (PVOID)buffer,
  303. string.Length,
  304. &result)) {
  305. dprintf("Cound not be read (@ %p)\n", stringAddress);
  306. } else {
  307. dprintf("trying\n\t\t");
  308. dprintf("%wZ\n", &string);
  309. }
  310. xdprintfEx(Depth, ("Partition Name: "));
  311. stringAddress = DiskInterfaceStringBuffer;
  312. string.Length = DiskInterfaceStringLength;
  313. if (string.Length == 0) {
  314. dprintf("NULL\n");
  315. } else if (string.Length > string.MaximumLength) {
  316. dprintf("Too long (@ %p)\n", stringAddress);
  317. } else if (!ReadMemory(stringAddress,
  318. (PVOID)buffer,
  319. string.Length,
  320. &result)) {
  321. dprintf("Cound not be read (@ %p)\n", stringAddress);
  322. } else {
  323. dprintf("%wZ\n", &string);
  324. }
  325. }
  326. return;
  327. }