[project] Rename winvblock__uint32 back to UINT32
[people/sha0/winvblock.git] / src / winvblock / debug.c
1 /**
2  * Copyright (C) 2009-2011, Shao Miller <shao.miller@yrdsb.edu.on.ca>.
3  * Copyright 2006-2008, V.
4  * For WinAoE contact information, see http://winaoe.org/
5  *
6  * This file is part of WinVBlock, derived from WinAoE.
7  *
8  * WinVBlock is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * WinVBlock is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with WinVBlock.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /**
23  * @file
24  *
25  * Debugging specifics.
26  */
27
28 #include <ntddk.h>
29 #include <srb.h>
30 #include <scsi.h>
31 #include <ntddscsi.h>
32 #include <ntddstor.h>
33 #include <ntdddisk.h>
34 #include <ndis.h>
35
36 #include "winvblock.h"
37 #include "wv_stdlib.h"
38 #include "portable.h"
39 #include "driver.h"
40 #include "bus.h"
41 #include "device.h"
42 #include "disk.h"
43 #include "mount.h"
44 #include "aoe.h"
45 #include "debug.h"
46
47 extern int sprintf (
48   char *,
49   const char *,
50   ...
51  );
52
53 typedef struct _DEBUG_IRPLIST
54 {
55   PIRP Irp;
56   UINT32 Number;
57   PCHAR DebugMessage;
58   struct _DEBUG_IRPLIST *Next;
59   struct _DEBUG_IRPLIST *Previous;
60 } DEBUG_IRPLIST,
61 *PDEBUG_IRPLIST;
62
63 static PDEBUG_IRPLIST Debug_Globals_IrpList = NULL;
64 static KSPIN_LOCK Debug_Globals_SpinLock;
65 static UINT32 Debug_Globals_Number = 0;
66
67 /* in this file */
68 static PDEBUG_IRPLIST STDCALL Debug_IrpListRecord (
69   IN PIRP Irp
70  );
71 static void STDCALL Debug_DecodeIrp (
72   IN PDEVICE_OBJECT DeviceObject,
73   IN PIRP Irp,
74   IN PCHAR DebugMessage
75  );
76 static PCHAR STDCALL Debug_MajorFunctionString (
77   IN UCHAR MajorFunction
78  );
79 static PCHAR STDCALL Debug_PnPMinorFunctionString (
80   IN UCHAR MinorFunction
81  );
82 static PCHAR STDCALL Debug_SystemControlMinorFunctionString (
83   IN UCHAR MinorFunction
84  );
85 static PCHAR STDCALL Debug_PowerMinorFunctionString (
86   IN UCHAR MinorFunction
87  );
88 static PCHAR STDCALL Debug_QueryDeviceRelationsString (
89   IN DEVICE_RELATION_TYPE Type
90  );
91 static PCHAR STDCALL Debug_QueryIdString (
92   IN BUS_QUERY_ID_TYPE IdType
93  );
94 static PCHAR STDCALL Debug_SrbFunctionString (
95   IN UCHAR Function
96  );
97 static PCHAR STDCALL Debug_DeviceIoControlString (
98   IN UINT32 IoControlCode
99  );
100 static PCHAR STDCALL Debug_DeviceTextTypeString (
101   IN DEVICE_TEXT_TYPE DeviceTextType
102  );
103 static PCHAR STDCALL Debug_SCSIOPString (
104   IN UCHAR OperationCode
105  );
106
107 WVL_M_LIB NTSTATUS STDCALL
108 xDbgPrint (
109   IN PCHAR File,
110   IN PCHAR Function,
111   IN UINT32 Line
112  )
113 {
114   return DbgPrint ( "%s: %s() @ line %d: ", File, Function, Line );
115 }
116
117 void
118 Debug_Initialize (
119   void
120  )
121 {
122   KeInitializeSpinLock ( &Debug_Globals_SpinLock );
123 }
124
125 static PDEBUG_IRPLIST STDCALL
126 Debug_IrpListRecord (
127   IN PIRP Irp
128  )
129 {
130   PDEBUG_IRPLIST Record;
131   KIRQL Irql;
132
133   KeAcquireSpinLock ( &Debug_Globals_SpinLock, &Irql );
134   Record = Debug_Globals_IrpList;
135   while ( Record != NULL && Record->Irp != Irp )
136     Record = Record->Next;
137   KeReleaseSpinLock ( &Debug_Globals_SpinLock, Irql );
138   return Record;
139 }
140
141 void STDCALL
142 Debug_IrpStart (
143   IN PDEVICE_OBJECT DeviceObject,
144   IN PIRP Irp
145  )
146 {
147   PCHAR DebugMessage;
148   PDEBUG_IRPLIST Record,
149    Temp;
150   KIRQL Irql;
151
152   if ((DebugMessage = wv_malloc(1024)) == NULL) {
153       DBG("wv_malloc DebugMessage\n");
154     }
155   Debug_DecodeIrp ( DeviceObject, Irp, DebugMessage );
156   if ((Record = wv_malloc(sizeof *Record)) == NULL) {
157       DBG("wv_malloc Record\n");
158       DBG ( "IRP %s\n", DebugMessage );
159     }
160   Record->Next = NULL;
161   Record->Previous = NULL;
162   Record->Irp = Irp;
163   Record->DebugMessage = DebugMessage;
164   Record->Number = InterlockedIncrement ( &Debug_Globals_Number );;
165   KeAcquireSpinLock ( &Debug_Globals_SpinLock, &Irql );
166   if ( Debug_Globals_IrpList == NULL )
167     {
168       Debug_Globals_IrpList = Record;
169       Record->Previous = NULL;
170     }
171   else
172     {
173       Temp = Debug_Globals_IrpList;
174       while ( Temp->Next != NULL )
175         Temp = Temp->Next;
176       Temp->Next = Record;
177       Record->Previous = Temp;
178     }
179   KeReleaseSpinLock ( &Debug_Globals_SpinLock, Irql );
180   DBG ( "IRP %d: %s\n", Record->Number, Record->DebugMessage );
181 }
182
183 void STDCALL
184 Debug_IrpEnd (
185   IN PIRP Irp,
186   IN NTSTATUS Status
187  )
188 {
189   PDEBUG_IRPLIST Record;
190   KIRQL Irql;
191
192   if ( ( Record = Debug_IrpListRecord ( Irp ) ) == NULL )
193     {
194       DBG
195         ( "Irp not found in Debug_Globals_IrpList!! (returned 0x%08x, Status)\n" );
196       return;
197     }
198   /*
199    * There is no race condition between getting the record and unlinking in
200    * Debug_Globals_IrpList, unless Debug_IrpEnd is called more than once on
201    * an irp (which itself is a bug, it should only be called one time).
202    */
203   KeAcquireSpinLock ( &Debug_Globals_SpinLock, &Irql );
204   if ( Record->Previous == NULL )
205     {
206       Debug_Globals_IrpList = Record->Next;
207     }
208   else
209     {
210       Record->Previous->Next = Record->Next;
211     }
212   if ( Record->Next != NULL )
213     {
214       Record->Next->Previous = Record->Previous;
215     }
216   KeReleaseSpinLock ( &Debug_Globals_SpinLock, Irql );
217
218   DBG ( "IRP %d: %s -> 0x%08x\n", Record->Number, Record->DebugMessage,
219         Status );
220   wv_free(Record->DebugMessage);
221   wv_free(Record);
222 }
223
224 static void STDCALL
225 Debug_DecodeIrp (
226   IN PDEVICE_OBJECT DeviceObject,
227   IN PIRP Irp,
228   IN PCHAR DebugMessage
229  )
230 {
231   WV_SP_DEV_T dev_ptr = WvDevFromDevObj(DeviceObject);
232   PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation ( Irp );
233   PSCSI_REQUEST_BLOCK Srb;
234   PCDB Cdb;
235   UINT32 StartSector,
236    SectorCount;
237   PSTORAGE_PROPERTY_QUERY StoragePropertyQuery;
238
239   sprintf ( DebugMessage, "%s %s", ( dev_ptr->IsBus ? "Bus" : "Disk" ),
240             Debug_MajorFunctionString ( Stack->MajorFunction ) );
241   switch ( Stack->MajorFunction )
242     {
243       case IRP_MJ_SYSTEM_CONTROL:
244         sprintf ( DebugMessage, "%s %s", DebugMessage,
245                   Debug_SystemControlMinorFunctionString
246                   ( Stack->MinorFunction ) );
247         break;
248       case IRP_MJ_PNP:
249         sprintf ( DebugMessage, "%s %s", DebugMessage,
250                   Debug_PnPMinorFunctionString ( Stack->MinorFunction ) );
251         switch ( Stack->MinorFunction )
252           {
253             case IRP_MN_QUERY_ID:
254               sprintf ( DebugMessage, "%s %s", DebugMessage,
255                         Debug_QueryIdString ( Stack->Parameters.
256                                               QueryId.IdType ) );
257               break;
258             case IRP_MN_QUERY_DEVICE_TEXT:
259               sprintf ( DebugMessage, "%s %s", DebugMessage,
260                         Debug_DeviceTextTypeString ( Stack->Parameters.
261                                                      QueryDeviceText.DeviceTextType ) );
262               break;
263             case IRP_MN_QUERY_DEVICE_RELATIONS:
264               sprintf ( DebugMessage, "%s %s", DebugMessage,
265                         Debug_QueryDeviceRelationsString ( Stack->
266                                                            Parameters.QueryDeviceRelations.Type ) );
267               break;
268           }
269         break;
270       case IRP_MJ_DEVICE_CONTROL:
271         sprintf ( DebugMessage, "%s (0x%08x) %s", DebugMessage,
272                   ( int )Stack->Parameters.DeviceIoControl.IoControlCode,
273                   Debug_DeviceIoControlString ( Stack->Parameters.
274                                                 DeviceIoControl.IoControlCode ) );
275         if ( !dev_ptr->IsBus
276              && Stack->Parameters.DeviceIoControl.IoControlCode ==
277              IOCTL_STORAGE_QUERY_PROPERTY )
278           {
279             StoragePropertyQuery = Irp->AssociatedIrp.SystemBuffer;
280             switch ( StoragePropertyQuery->PropertyId )
281               {
282                 case StorageDeviceProperty:
283                   sprintf ( DebugMessage, "%s StorageDeviceProperty",
284                             DebugMessage );
285                   break;
286                 case StorageAdapterProperty:
287                   sprintf ( DebugMessage, "%s StorageAdapterProperty",
288                             DebugMessage );
289                   break;
290                 default:
291                   sprintf ( DebugMessage, "%s StorageUnknownProperty (%d)",
292                             DebugMessage, StoragePropertyQuery->PropertyId );
293               }
294             switch ( StoragePropertyQuery->QueryType )
295               {
296                 case PropertyStandardQuery:
297                   sprintf ( DebugMessage, "%s PropertyStandardQuery",
298                             DebugMessage );
299                   break;
300                 case PropertyExistsQuery:
301                   sprintf ( DebugMessage, "%s PropertyExistsQuery",
302                             DebugMessage );
303                   break;
304                 default:
305                   sprintf ( DebugMessage, "%s PropertyUnknownQuery (%d)",
306                             DebugMessage, StoragePropertyQuery->QueryType );
307               }
308           }
309         break;
310       case IRP_MJ_SCSI:
311         if ( !dev_ptr->IsBus )
312           {
313             Srb = Stack->Parameters.Scsi.Srb;
314             Cdb = ( PCDB ) Srb->Cdb;
315             sprintf ( DebugMessage, "%s %s", DebugMessage,
316                       Debug_SrbFunctionString ( Srb->Function ) );
317             if ( Srb->Lun == 0 && Srb->Function == SRB_FUNCTION_EXECUTE_SCSI )
318               {
319                 sprintf ( DebugMessage, "%s %s", DebugMessage,
320                           Debug_SCSIOPString ( Cdb->AsByte[0] ) );
321                 if ( Cdb->AsByte[0] == SCSIOP_READ
322                      || Cdb->AsByte[0] == SCSIOP_WRITE
323                      || Cdb->AsByte[0] == SCSIOP_VERIFY )
324                   {
325                     StartSector =
326                       ( Cdb->CDB10.LogicalBlockByte0 << 24 ) +
327                       ( Cdb->CDB10.LogicalBlockByte1 << 16 ) +
328                       ( Cdb->CDB10.LogicalBlockByte2 << 8 ) +
329                       Cdb->CDB10.LogicalBlockByte3;
330                     SectorCount =
331                       ( Cdb->CDB10.TransferBlocksMsb << 8 ) +
332                       Cdb->CDB10.TransferBlocksLsb;
333                     sprintf ( DebugMessage, "%s %d %d", DebugMessage,
334                               ( int )StartSector, ( int )SectorCount );
335                   }
336                 if ( Cdb->AsByte[0] == SCSIOP_READ
337                      || Cdb->AsByte[0] == SCSIOP_WRITE )
338                   {
339                     sprintf ( DebugMessage, "%s (buffersize: %d)",
340                               DebugMessage, ( int )Srb->DataTransferLength );
341                   }
342               }
343           }
344         break;
345     }
346 }
347
348 static PCHAR STDCALL
349 Debug_MajorFunctionString (
350   IN UCHAR MajorFunction
351  )
352 {
353   switch ( MajorFunction )
354     {
355       case IRP_MJ_CREATE:
356         return "CREATE";
357 /*    case IRP_MJ_NAMED_PIPE:               return "NAMED_PIPE";
358  */
359       case IRP_MJ_CLOSE:
360         return "CLOSE";
361       case IRP_MJ_READ:
362         return "READ";
363       case IRP_MJ_WRITE:
364         return "WRITE";
365       case IRP_MJ_QUERY_INFORMATION:
366         return "QUERY_INFORMATION";
367       case IRP_MJ_SET_INFORMATION:
368         return "SET_INFORMATION";
369       case IRP_MJ_QUERY_EA:
370         return "QUERY_EA";
371       case IRP_MJ_SET_EA:
372         return "SET_EA";
373       case IRP_MJ_FLUSH_BUFFERS:
374         return "FLUSH_BUFFERS";
375       case IRP_MJ_QUERY_VOLUME_INFORMATION:
376         return "QUERY_VOLUME_INFORMATION";
377       case IRP_MJ_SET_VOLUME_INFORMATION:
378         return "SET_VOLUME_INFORMATION";
379       case IRP_MJ_DIRECTORY_CONTROL:
380         return "DIRECTORY_CONTROL";
381       case IRP_MJ_FILE_SYSTEM_CONTROL:
382         return "FILE_SYSTEM_CONTROL";
383       case IRP_MJ_DEVICE_CONTROL:
384         return "DEVICE_CONTROL";
385 /*    case IRP_MJ_INTERNAL_DEVICE_CONTROL:  return "INTERNAL_DEVICE_CONTROL";
386  */
387       case IRP_MJ_SCSI:
388         return "SCSI";
389       case IRP_MJ_SHUTDOWN:
390         return "SHUTDOWN";
391       case IRP_MJ_LOCK_CONTROL:
392         return "LOCK_CONTROL";
393       case IRP_MJ_CLEANUP:
394         return "CLEANUP";
395       case IRP_MJ_CREATE_MAILSLOT:
396         return "CREATE_MAILSLOT";
397       case IRP_MJ_QUERY_SECURITY:
398         return "QUERY_SECURITY";
399       case IRP_MJ_SET_SECURITY:
400         return "SET_SECURITY";
401       case IRP_MJ_POWER:
402         return "POWER";
403       case IRP_MJ_SYSTEM_CONTROL:
404         return "SYSTEM_CONTROL";
405       case IRP_MJ_DEVICE_CHANGE:
406         return "DEVICE_CHANGE";
407       case IRP_MJ_QUERY_QUOTA:
408         return "QUERY_QUOTA";
409       case IRP_MJ_SET_QUOTA:
410         return "SET_QUOTA";
411       case IRP_MJ_PNP:
412         return "PNP";
413 /*    case IRP_MJ_PNP_POWER:                return "PNP_POWER";
414  *    case IRP_MJ_MAXIMUM_FUNCTION:         return "MAXIMUM_FUNCTION";
415  */
416       default:
417         return "UNKNOWN";
418     }
419 }
420
421 static PCHAR STDCALL
422 Debug_PnPMinorFunctionString (
423   IN UCHAR MinorFunction
424  )
425 {
426   switch ( MinorFunction )
427     {
428       case IRP_MN_START_DEVICE:
429         return "START_DEVICE";
430       case IRP_MN_QUERY_REMOVE_DEVICE:
431         return "QUERY_REMOVE_DEVICE";
432       case IRP_MN_REMOVE_DEVICE:
433         return "REMOVE_DEVICE";
434       case IRP_MN_CANCEL_REMOVE_DEVICE:
435         return "CANCEL_REMOVE_DEVICE";
436       case IRP_MN_STOP_DEVICE:
437         return "STOP_DEVICE";
438       case IRP_MN_QUERY_STOP_DEVICE:
439         return "QUERY_STOP_DEVICE";
440       case IRP_MN_CANCEL_STOP_DEVICE:
441         return "CANCEL_STOP_DEVICE";
442       case IRP_MN_QUERY_DEVICE_RELATIONS:
443         return "QUERY_DEVICE_RELATIONS";
444       case IRP_MN_QUERY_INTERFACE:
445         return "QUERY_INTERFACE";
446       case IRP_MN_QUERY_CAPABILITIES:
447         return "QUERY_CAPABILITIES";
448       case IRP_MN_QUERY_RESOURCES:
449         return "QUERY_RESOURCES";
450       case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
451         return "QUERY_RESOURCE_REQUIREMENTS";
452       case IRP_MN_QUERY_DEVICE_TEXT:
453         return "QUERY_DEVICE_TEXT";
454       case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
455         return "FILTER_RESOURCE_REQUIREMENTS";
456       case IRP_MN_READ_CONFIG:
457         return "READ_CONFIG";
458       case IRP_MN_WRITE_CONFIG:
459         return "WRITE_CONFIG";
460       case IRP_MN_EJECT:
461         return "EJECT";
462       case IRP_MN_SET_LOCK:
463         return "SET_LOCK";
464       case IRP_MN_QUERY_ID:
465         return "QUERY_ID";
466       case IRP_MN_QUERY_PNP_DEVICE_STATE:
467         return "QUERY_PNP_DEVICE_STATE";
468       case IRP_MN_QUERY_BUS_INFORMATION:
469         return "QUERY_BUS_INFORMATION";
470       case IRP_MN_DEVICE_USAGE_NOTIFICATION:
471         return "DEVICE_USAGE_NOTIFICATION";
472       case IRP_MN_SURPRISE_REMOVAL:
473         return "SURPRISE_REMOVAL";
474       case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
475         return "QUERY_LEGACY_BUS_INFORMATION";
476 /*    case IRP_MN_BUS_RESET:                    return "BUS_RESET"
477  */
478       default:
479         return "UNKNOWN";
480     }
481 }
482
483 static PCHAR STDCALL
484 Debug_SystemControlMinorFunctionString (
485   IN UCHAR MinorFunction
486  )
487 {
488   switch ( MinorFunction )
489     {
490       case IRP_MN_QUERY_ALL_DATA:
491         return "QUERY_ALL_DATA";
492       case IRP_MN_QUERY_SINGLE_INSTANCE:
493         return "QUERY_SINGLE_INSTANCE";
494       case IRP_MN_CHANGE_SINGLE_INSTANCE:
495         return "CHANGE_SINGLE_INSTANCE";
496       case IRP_MN_CHANGE_SINGLE_ITEM:
497         return "CHANGE_SINGLE_ITEM";
498       case IRP_MN_ENABLE_EVENTS:
499         return "ENABLE_EVENTS";
500       case IRP_MN_DISABLE_EVENTS:
501         return "DISABLE_EVENTS";
502       case IRP_MN_ENABLE_COLLECTION:
503         return "ENABLE_COLLECTION";
504       case IRP_MN_DISABLE_COLLECTION:
505         return "DISABLE_COLLECTION";
506       case IRP_MN_REGINFO:
507         return "REGINFO";
508       case IRP_MN_EXECUTE_METHOD:
509         return "EXECUTE_METHOD";
510 /*    case IRP_MN_REGINFO_EX:             return "REGINFO_EX";
511  */
512       default:
513         return "UNKNOWN";
514     }
515 }
516
517 static PCHAR STDCALL
518 Debug_PowerMinorFunctionString (
519   IN UCHAR MinorFunction
520  )
521 {
522   switch ( MinorFunction )
523     {
524       case IRP_MN_WAIT_WAKE:
525         return "WAIT_WAKE";
526       case IRP_MN_POWER_SEQUENCE:
527         return "POWER_SEQUENCE";
528       case IRP_MN_SET_POWER:
529         return "SET_POWER";
530       case IRP_MN_QUERY_POWER:
531         return "QUERY_POWER";
532       default:
533         return "UNKNOWN";
534     }
535 }
536
537 static PCHAR STDCALL
538 Debug_QueryDeviceRelationsString (
539   IN DEVICE_RELATION_TYPE Type
540  )
541 {
542   switch ( Type )
543     {
544       case BusRelations:
545         return "BusRelations";
546       case EjectionRelations:
547         return "EjectionRelations";
548       case RemovalRelations:
549         return "RemovalRelations";
550       case TargetDeviceRelation:
551         return "TargetDeviceRelation";
552       default:
553         return "UnknownRelation";
554     }
555 }
556
557 static PCHAR STDCALL
558 Debug_QueryIdString (
559   IN BUS_QUERY_ID_TYPE IdType
560  )
561 {
562   switch ( IdType )
563     {
564       case BusQueryDeviceID:
565         return "BusQueryDeviceID";
566       case BusQueryHardwareIDs:
567         return "BusQueryHardwareIDs";
568       case BusQueryCompatibleIDs:
569         return "BusQueryCompatibleIDs";
570       case BusQueryInstanceID:
571         return "BusQueryInstanceID";
572       case BusQueryDeviceSerialNumber:
573         return "BusQueryDeviceSerialNumber";
574       default:
575         return "BusQueryUnknown";
576     }
577 }
578
579 static PCHAR STDCALL
580 Debug_SrbFunctionString (
581   IN UCHAR Function
582  )
583 {
584   switch ( Function )
585     {
586       case SRB_FUNCTION_EXECUTE_SCSI:
587         return "EXECUTE_SCSI";
588       case SRB_FUNCTION_CLAIM_DEVICE:
589         return "CLAIM_DEVICE";
590       case SRB_FUNCTION_IO_CONTROL:
591         return "IO_CONTROL";
592       case SRB_FUNCTION_RECEIVE_EVENT:
593         return "RECEIVE_EVENT";
594       case SRB_FUNCTION_RELEASE_QUEUE:
595         return "RELEASE_QUEUE";
596       case SRB_FUNCTION_ATTACH_DEVICE:
597         return "ATTACH_DEVICE";
598       case SRB_FUNCTION_RELEASE_DEVICE:
599         return "RELEASE_DEVICE";
600       case SRB_FUNCTION_SHUTDOWN:
601         return "SHUTDOWN";
602       case SRB_FUNCTION_FLUSH:
603         return "FLUSH";
604       case SRB_FUNCTION_ABORT_COMMAND:
605         return "ABORT_COMMAND";
606       case SRB_FUNCTION_RELEASE_RECOVERY:
607         return "RELEASE_RECOVERY";
608       case SRB_FUNCTION_RESET_BUS:
609         return "RESET_BUS";
610       case SRB_FUNCTION_RESET_DEVICE:
611         return "RESET_DEVICE";
612       case SRB_FUNCTION_TERMINATE_IO:
613         return "TERMINATE_IO";
614       case SRB_FUNCTION_FLUSH_QUEUE:
615         return "FLUSH_QUEUE";
616       case SRB_FUNCTION_REMOVE_DEVICE:
617         return "REMOVE_DEVICE";
618       case SRB_FUNCTION_WMI:
619         return "WMI";
620       case SRB_FUNCTION_LOCK_QUEUE:
621         return "LOCK_QUEUE";
622       case SRB_FUNCTION_UNLOCK_QUEUE:
623         return "UNLOCK_QUEUE";
624 /*    case SRB_FUNCTION_RESET_LOGICAL_UNIT: return "RESET_LOGICAL_UNIT";
625  */
626       default:
627         return "SRB_FUNCTION_UNKNOWN";
628     }
629 }
630
631 static PCHAR STDCALL
632 Debug_DeviceIoControlString (
633   IN UINT32 IoControlCode
634  )
635 {
636   switch ( IoControlCode )
637     {
638       case IOCTL_SCSI_GET_INQUIRY_DATA:
639         return "IOCTL_SCSI_GET_INQUIRY_DATA";
640       case IOCTL_SCSI_GET_CAPABILITIES:
641         return "IOCTL_SCSI_GET_CAPABILITIES";
642       case IOCTL_SCSI_GET_ADDRESS:
643         return "IOCTL_SCSI_GET_ADDRESS";
644       case IOCTL_SCSI_MINIPORT:
645         return "IOCTL_SCSI_MINIPORT";
646       case IOCTL_SCSI_PASS_THROUGH:
647         return "IOCTL_SCSI_PASS_THROUGH";
648       case IOCTL_SCSI_PASS_THROUGH_DIRECT:
649         return "IOCTL_SCSI_PASS_THROUGH_DIRECT";
650       case IOCTL_SCSI_RESCAN_BUS:
651         return "IOCTL_SCSI_RESCAN_BUS";
652       case IOCTL_DISK_CHECK_VERIFY:
653         return "IOCTL_DISK_CHECK_VERIFY";
654       case IOCTL_DISK_CONTROLLER_NUMBER:
655         return "IOCTL_DISK_CONTROLLER_NUMBER";
656 /*    case IOCTL_DISK_CREATE_DISK:
657  *    return "IOCTL_DISK_CREATE_DISK";
658  */
659       case IOCTL_DISK_DELETE_DRIVE_LAYOUT:
660         return "IOCTL_DISK_DELETE_DRIVE_LAYOUT";
661       case IOCTL_DISK_FIND_NEW_DEVICES:
662         return "IOCTL_DISK_FIND_NEW_DEVICES";
663       case IOCTL_DISK_FORMAT_TRACKS:
664         return "IOCTL_DISK_FORMAT_TRACKS";
665       case IOCTL_DISK_FORMAT_TRACKS_EX:
666         return "IOCTL_DISK_FORMAT_TRACKS_EX";
667       case IOCTL_DISK_GET_CACHE_INFORMATION:
668         return "IOCTL_DISK_GET_CACHE_INFORMATION";
669       case IOCTL_DISK_GET_DRIVE_GEOMETRY:
670         return "IOCTL_DISK_GET_DRIVE_GEOMETRY";
671 /*    case IOCTL_DISK_GET_DRIVE_GEOMETRY_EX:
672  *    return "IOCTL_DISK_GET_DRIVE_GEOMETRY_EX";
673  */
674       case IOCTL_DISK_GET_DRIVE_LAYOUT:
675         return "IOCTL_DISK_GET_DRIVE_LAYOUT";
676 /*    case IOCTL_DISK_GET_DRIVE_LAYOUT_EX:
677  *    return "IOCTL_DISK_GET_DRIVE_LAYOUT_EX";
678  */
679       case IOCTL_DISK_GET_MEDIA_TYPES:
680         return "IOCTL_DISK_GET_MEDIA_TYPES";
681 /*    case IOCTL_DISK_GET_LENGTH_INFO:
682  *    return "IOCTL_DISK_GET_LENGTH_INFO";
683  */
684       case IOCTL_DISK_GET_PARTITION_INFO:
685         return "IOCTL_DISK_GET_PARTITION_INFO";
686 /*    case IOCTL_DISK_GET_PARTITION_INFO_EX:
687  *    return "IOCTL_DISK_GET_PARTITION_INFO_EX";
688  */
689       case IOCTL_DISK_GROW_PARTITION:
690         return "IOCTL_DISK_GROW_PARTITION";
691       case IOCTL_DISK_INTERNAL_CLEAR_VERIFY:
692         return "IOCTL_DISK_INTERNAL_CLEAR_VERIFY";
693       case IOCTL_DISK_INTERNAL_SET_VERIFY:
694         return "IOCTL_DISK_INTERNAL_SET_VERIFY";
695       case IOCTL_DISK_IS_WRITABLE:
696         return "IOCTL_DISK_IS_WRITABLE";
697       case IOCTL_DISK_PERFORMANCE:
698         return "IOCTL_DISK_PERFORMANCE";
699 /*    case IOCTL_DISK_PERFORMANCE_OFF:
700  *    return "IOCTL_DISK_PERFORMANCE_OFF";
701  */
702       case IOCTL_DISK_REASSIGN_BLOCKS:
703         return "IOCTL_DISK_REASSIGN_BLOCKS";
704       case IOCTL_DISK_RESERVE:
705         return "IOCTL_DISK_RESERVE";
706       case IOCTL_DISK_SET_CACHE_INFORMATION:
707         return "IOCTL_DISK_SET_CACHE_INFORMATION";
708       case IOCTL_DISK_SET_DRIVE_LAYOUT:
709         return "IOCTL_DISK_SET_DRIVE_LAYOUT";
710 /*    case IOCTL_DISK_SET_DRIVE_LAYOUT_EX:
711  *    return "IOCTL_DISK_SET_DRIVE_LAYOUT_EX";
712  */
713       case IOCTL_DISK_SET_PARTITION_INFO:
714         return "IOCTL_DISK_SET_PARTITION_INFO";
715 /*    case IOCTL_DISK_SET_PARTITION_INFO_EX:
716  *    return "IOCTL_DISK_SET_PARTITION_INFO_EX";
717  */
718       case IOCTL_DISK_VERIFY:
719         return "IOCTL_DISK_VERIFY";
720       case SMART_GET_VERSION:
721         return "SMART_GET_VERSION";
722       case SMART_RCV_DRIVE_DATA:
723         return "SMART_RCV_DRIVE_DATA";
724       case SMART_SEND_DRIVE_COMMAND:
725         return "SMART_SEND_DRIVE_COMMAND";
726       case IOCTL_STORAGE_CHECK_VERIFY:
727         return "IOCTL_STORAGE_CHECK_VERIFY";
728       case IOCTL_STORAGE_CHECK_VERIFY2:
729         return "IOCTL_STORAGE_CHECK_VERIFY2";
730       case IOCTL_STORAGE_EJECT_MEDIA:
731         return "IOCTL_STORAGE_EJECT_MEDIA";
732       case IOCTL_STORAGE_EJECTION_CONTROL:
733         return "IOCTL_STORAGE_EJECTION_CONTROL";
734       case IOCTL_STORAGE_FIND_NEW_DEVICES:
735         return "IOCTL_STORAGE_FIND_NEW_DEVICES";
736       case IOCTL_STORAGE_GET_DEVICE_NUMBER:
737         return "IOCTL_STORAGE_GET_DEVICE_NUMBER";
738 /*    case IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER:
739  *    return "IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER";
740  */
741       case IOCTL_STORAGE_GET_MEDIA_TYPES:
742         return "IOCTL_STORAGE_GET_MEDIA_TYPES";
743       case IOCTL_STORAGE_GET_MEDIA_TYPES_EX:
744         return "IOCTL_STORAGE_GET_MEDIA_TYPES_EX";
745       case IOCTL_STORAGE_LOAD_MEDIA:
746         return "IOCTL_STORAGE_LOAD_MEDIA";
747       case IOCTL_STORAGE_LOAD_MEDIA2:
748         return "IOCTL_STORAGE_LOAD_MEDIA2";
749       case IOCTL_STORAGE_MCN_CONTROL:
750         return "IOCTL_STORAGE_MCN_CONTROL";
751       case IOCTL_STORAGE_MEDIA_REMOVAL:
752         return "IOCTL_STORAGE_MEDIA_REMOVAL";
753       case IOCTL_STORAGE_PREDICT_FAILURE:
754         return "IOCTL_STORAGE_PREDICT_FAILURE";
755       case IOCTL_STORAGE_QUERY_PROPERTY:
756         return "IOCTL_STORAGE_QUERY_PROPERTY";
757       case IOCTL_STORAGE_RELEASE:
758         return "IOCTL_STORAGE_RELEASE";
759       case IOCTL_STORAGE_RESERVE:
760         return "IOCTL_STORAGE_RESERVE";
761       case IOCTL_STORAGE_RESET_BUS:
762         return "IOCTL_STORAGE_RESET_BUS";
763       case IOCTL_STORAGE_RESET_DEVICE:
764         return "IOCTL_STORAGE_RESET_DEVICE";
765       case IOCTL_AOE_SCAN:
766         return "IOCTL_AOE_SCAN";
767       case IOCTL_AOE_SHOW:
768         return "IOCTL_AOE_SHOW";
769       case IOCTL_AOE_MOUNT:
770         return "IOCTL_AOE_MOUNT";
771       case IOCTL_AOE_UMOUNT:
772         return "IOCTL_AOE_UMOUNT";
773       default:
774         return "IOCTL_UNKNOWN";
775     }
776 }
777
778 static PCHAR STDCALL
779 Debug_DeviceTextTypeString (
780   IN DEVICE_TEXT_TYPE DeviceTextType
781  )
782 {
783   switch ( DeviceTextType )
784     {
785       case DeviceTextDescription:
786         return "DeviceTextDescription";
787       case DeviceTextLocationInformation:
788         return "DeviceTextLocationInformation";
789       default:
790         return "DeviceTextUnknown";
791     }
792 }
793
794 static PCHAR STDCALL
795 Debug_SCSIOPString (
796   IN UCHAR OperationCode
797  )
798 {
799   switch ( OperationCode )
800     {
801       case SCSIOP_TEST_UNIT_READY:
802         return "TEST_UNIT_READY";
803       case SCSIOP_READ:
804         return "READ";
805       case SCSIOP_WRITE:
806         return "WRITE";
807       case SCSIOP_VERIFY:
808         return "VERIFY";
809       case SCSIOP_READ_CAPACITY:
810         return "READ_CAPACITY";
811       case SCSIOP_MODE_SENSE:
812         return "MODE_SENSE";
813       case SCSIOP_MEDIUM_REMOVAL:
814         return "MEDIUM_REMOVAL";
815       case SCSIOP_READ16:
816         return "READ16";
817       case SCSIOP_WRITE16:
818         return "WRITE16";
819       case SCSIOP_VERIFY16:
820         return "VERIFY16";
821       case SCSIOP_READ_CAPACITY16:
822         return "CAPACITY16";
823       default:
824         return "SCSIOP_UNKNOWN";
825     }
826 }