ReactOS  0.4.15-dev-1397-g19779b3
kdbg.c
Go to the documentation of this file.
1 /*
2 * FILE: drivers/filesystems/fastfat/kdbg.c
3 * PURPOSE: KDBG extension.
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS kernel
6 * PROGRAMMER: Pierre Schweitzer (pierre@reactos.org)
7 */
8 
9 /* ------------------------------------------------------- INCLUDES */
10 
11 #include "vfat.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 #include <stdio.h>
17 
18 /* -------------------------------------------------------- DEFINES */
19 
20 #ifdef KDBG
21 UNICODE_STRING DebugFile = {0, 0, NULL};
22 
23 BOOLEAN
24 NTAPI
25 vfatKdbgHandler(
27  IN ULONG Argc,
28  IN PCH Argv[])
29 {
30  ULONG Len;
31 
32  Len = strlen(Command);
33  if (Len < sizeof("?fat."))
34  {
35  return FALSE;
36  }
37 
38  if (Command[0] != '?' || Command[1] != 'f' ||
39  Command[2] != 'a' || Command[3] != 't' ||
40  Command[4] != '.')
41  {
42  return FALSE;
43  }
44 
45  Command += (sizeof("?fat.") - sizeof(ANSI_NULL));
46  if (strcmp(Command, "vols") == 0)
47  {
48  ULONG Count = 0;
49  PLIST_ENTRY ListEntry;
50  PDEVICE_EXTENSION DeviceExt;
51 
52  for (ListEntry = VfatGlobalData->VolumeListHead.Flink;
53  ListEntry != &VfatGlobalData->VolumeListHead;
54  ListEntry = ListEntry->Flink)
55  {
56  DeviceExt = CONTAINING_RECORD(ListEntry, DEVICE_EXTENSION, VolumeListEntry);
57  DPRINT1("Volume: %p with VCB: %p\n", DeviceExt->VolumeDevice, DeviceExt);
58  ++Count;
59  }
60 
61  if (Count == 0)
62  {
63  DPRINT1("No volume found\n");
64  }
65  }
66  else if (strcmp(Command, "files") == 0)
67  {
68  if (Argc != 2)
69  {
70  DPRINT1("Please provide a volume or a VCB!\n");
71  }
72  else
73  {
74  PLIST_ENTRY ListEntry;
75  PDEVICE_EXTENSION DeviceExt;
76 
77  for (ListEntry = VfatGlobalData->VolumeListHead.Flink;
78  ListEntry != &VfatGlobalData->VolumeListHead;
79  ListEntry = ListEntry->Flink)
80  {
81  CHAR Volume[17];
82 
83  DeviceExt = CONTAINING_RECORD(ListEntry, DEVICE_EXTENSION, VolumeListEntry);
84  sprintf(Volume, "%p", DeviceExt);
85  if (strcmp(Volume, Argv[1]) == 0)
86  {
87  break;
88  }
89 
90  sprintf(Volume, "%p", DeviceExt->VolumeDevice);
91  if (strcmp(Volume, Argv[1]) == 0)
92  {
93  break;
94  }
95 
96  DeviceExt = NULL;
97  }
98 
99  if (DeviceExt == NULL)
100  {
101  DPRINT1("No volume %s found!\n", Argv[1]);
102  }
103  else
104  {
105  PVFATFCB Fcb;
106 
107  for (ListEntry = DeviceExt->FcbListHead.Flink;
108  ListEntry != &DeviceExt->FcbListHead;
109  ListEntry = ListEntry->Flink)
110  {
111  Fcb = CONTAINING_RECORD(ListEntry, VFATFCB, FcbListEntry);
112  DPRINT1("FCB %p (ref: %d, oc: %d %s %s %s) for FO %p with path: %.*S\n",
114  ((Fcb->Flags & FCB_CLEANED_UP) ? "U" : "NU"),
115  ((Fcb->Flags & FCB_CLOSED) ? "C" : "NC"),
116  ((Fcb->Flags & FCB_DELAYED_CLOSE) ? "D" : "ND"),
117  Fcb->FileObject, Fcb->PathNameU.Length, Fcb->PathNameU.Buffer);
118  }
119  }
120  }
121  }
122  else if (strcmp(Command, "setdbgfile") == 0)
123  {
124  if (Argc < 2)
125  {
126  if (DebugFile.Buffer != NULL)
127  {
128  ExFreePool(DebugFile.Buffer);
129  DebugFile.Length = 0;
130  DebugFile.MaximumLength = 0;
131  }
132 
133  DPRINT1("Debug file reset\n");
134  }
135  else
136  {
139 
140  if (DebugFile.Buffer != NULL)
141  {
142  ExFreePool(DebugFile.Buffer);
143  DebugFile.Length = 0;
144  DebugFile.MaximumLength = 0;
145  }
146 
147  RtlInitAnsiString(&Source, Argv[1]);
149  if (NT_SUCCESS(Status))
150  {
151  DPRINT1("Debug file set to: %.*S\n", DebugFile.Length, DebugFile.Buffer);
152  }
153  }
154  }
155  else
156  {
157  DPRINT1("Unknown command: %s\n", Command);
158  }
159 
160  return TRUE;
161 }
162 #endif
signed char * PCHAR
Definition: retypes.h:7
#define IN
Definition: typedefs.h:39
LIST_ENTRY VolumeListHead
Definition: vfat.h:416
Definition: vfat.h:447
USHORT MaximumLength
Definition: env_spec_w32.h:370
PFILE_OBJECT FileObject
Definition: ntfs.h:516
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
Definition: shell.h:41
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define ANSI_NULL
CHAR * PCH
Definition: ntbasedef.h:392
unsigned char BOOLEAN
LONG RefCount
Definition: ntfs.h:531
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Status
Definition: gdiplustypes.h:24
ULONG OpenHandleCount
Definition: ntfs.h:533
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
int Count
Definition: noreturn.cpp:7
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Len
Definition: deflate.h:82
ULONG Flags
Definition: ntfs.h:532
Definition: typedefs.h:119
#define FCB_DELAYED_CLOSE
Definition: vfat.h:439
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define ExFreePool(addr)
Definition: env_spec_w32.h:352