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