Leaked source code of windows server 2003
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.

562 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Npfskd.c
  5. Abstract:
  6. KD Extension Api for examining Npfs specific data structures
  7. Author:
  8. Narayanan Ganapathy - 9/21/99
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "NpProcs.h"
  14. //
  15. // This file should not include wdbgexts.h as it includes windows.h
  16. // windows.h defines a structure called _DCB that clashes with the DCB for NPFS.
  17. // So the debugger functions are called from kdexts.c and indirectly called from this function
  18. //
  19. BOOLEAN NpDumpEventTableEntry(IN PEVENT_TABLE_ENTRY Ptr);
  20. BOOLEAN NpDumpDataQueue(IN PDATA_QUEUE Ptr);
  21. BOOLEAN NpDumpDataEntry(IN PDATA_ENTRY Ptr);
  22. BOOLEAN NpDump(IN PVOID Ptr);
  23. BOOLEAN NpDumpVcb(IN PVCB Ptr);
  24. BOOLEAN NpDumpRootDcb(IN PROOT_DCB Ptr);
  25. BOOLEAN NpDumpFcb(IN PFCB Ptr);
  26. BOOLEAN NpDumpCcb(IN PCCB Ptr);
  27. BOOLEAN NpDumpNonpagedCcb(IN PNONPAGED_CCB Ptr);
  28. BOOLEAN NpDumpRootDcbCcb(IN PROOT_DCB_CCB Ptr);
  29. extern VOID NpfskdPrint(PCHAR, ULONG_PTR);
  30. extern VOID NpfskdPrintString(PCHAR, PCHAR);
  31. extern VOID NpfskdPrintWideString(PWCHAR, PWCHAR);
  32. extern BOOLEAN NpfskdReadMemory(PVOID, PVOID, ULONG);
  33. extern ULONG NpfskdCheckControlC(VOID);
  34. extern ULONG NpDumpFlags;
  35. ULONG NpDumpCurrentColumn;
  36. #define DumpField(Field) NpfskdPrint( #Field , (ULONG_PTR)Ptr->Field)
  37. #define DumpListEntry(Links) \
  38. NpfskdPrint( #Links "->Flink", (ULONG_PTR)Ptr->Links.Flink); \
  39. NpfskdPrint( #Links "->Blink", (ULONG_PTR)Ptr->Links.Blink)
  40. #define DumpName(Field) { \
  41. ULONG i; \
  42. WCHAR _String[64]; \
  43. if (!NpfskdReadMemory(Ptr->Field, _String, sizeof(_String))) \
  44. return FALSE; \
  45. NpfskdPrintWideString(L#Field, _String); \
  46. }
  47. #define DumpTitle(Title, Value) { \
  48. NpfskdPrint("\n "#Title"@ ", (Value)); \
  49. }
  50. #define TestForNull(Name) { \
  51. if (targetPtr == NULL) { \
  52. NpfskdPrintString("Cannot dump a NULL pointer\n", Name); \
  53. return FALSE; \
  54. } \
  55. }
  56. #define NP_READ_MEMORY(targetPtr, localStore, localPtr) \
  57. { \
  58. if (!NpfskdReadMemory((targetPtr), \
  59. &(localStore), \
  60. sizeof(localStore))) { \
  61. return FALSE; \
  62. } \
  63. localPtr = &(localStore); \
  64. }
  65. #define NPFS_FULL_INFORMATION 1
  66. #define NPFS_WALK_LISTS 2
  67. BOOLEAN
  68. NpDumpEventTableEntry (
  69. IN PEVENT_TABLE_ENTRY targetPtr
  70. )
  71. {
  72. PEVENT_TABLE_ENTRY Ptr;
  73. EVENT_TABLE_ENTRY Event;
  74. TestForNull ("NpDumpEventTableEntry");
  75. DumpTitle (EventTableEntry, (ULONG_PTR)(targetPtr));
  76. NP_READ_MEMORY(targetPtr, Event, Ptr);
  77. DumpField (Ccb);
  78. DumpField (NamedPipeEnd);
  79. DumpField (EventHandle);
  80. DumpField (Event);
  81. DumpField (KeyValue);
  82. DumpField (Process);
  83. return TRUE;
  84. }
  85. BOOLEAN NpDumpDataQueue (
  86. IN PDATA_QUEUE targetPtr
  87. )
  88. {
  89. PDATA_ENTRY Entry;
  90. DATA_ENTRY DataEntry;
  91. PDATA_QUEUE Ptr;
  92. DATA_QUEUE Dqueue;
  93. TestForNull ("NpDumpDataQueue");
  94. DumpTitle (DataQueue, (ULONG_PTR)(targetPtr));
  95. NP_READ_MEMORY(targetPtr, Dqueue, Ptr);
  96. DumpField (QueueState);
  97. DumpField (BytesInQueue);
  98. DumpField (EntriesInQueue);
  99. DumpField (Quota);
  100. DumpField (QuotaUsed);
  101. DumpField (Queue.Flink);
  102. DumpField (Queue.Blink);
  103. DumpField (NextByteOffset);
  104. Entry = (PDATA_ENTRY) Ptr->Queue.Flink;
  105. if (!(NpDumpFlags & NPFS_WALK_LISTS)) {
  106. return TRUE;
  107. }
  108. while (Entry != (PDATA_ENTRY) &Ptr->Queue){
  109. if (!NpfskdReadMemory(Entry, &DataEntry, sizeof(DataEntry))) {
  110. return FALSE;
  111. }
  112. NpDumpDataEntry( Entry );
  113. if (NpfskdCheckControlC()) {
  114. NpfskdPrintString("^C Typed. Bailing out","");
  115. return FALSE;
  116. }
  117. Entry = (PDATA_ENTRY) DataEntry.Queue.Flink;
  118. }
  119. return TRUE;
  120. }
  121. BOOLEAN NpDumpDataEntry (
  122. IN PDATA_ENTRY targetPtr
  123. )
  124. {
  125. DATA_ENTRY Dentry;
  126. PDATA_ENTRY Ptr;
  127. TestForNull ("NpDumpDataEntry");
  128. DumpTitle (DataEntry, (ULONG_PTR)(targetPtr));
  129. NP_READ_MEMORY(targetPtr, Dentry, Ptr);
  130. DumpField (DataEntryType);
  131. DumpField (Queue.Flink);
  132. DumpField (Irp);
  133. DumpField (DataSize);
  134. DumpField (SecurityClientContext);
  135. return TRUE;
  136. }
  137. BOOLEAN NpDump (
  138. IN PVOID Ptr
  139. )
  140. /*++
  141. Routine Description:
  142. This routine determines the type of internal record reference by ptr and
  143. calls the appropriate dump routine.
  144. Arguments:
  145. Ptr - Supplies the pointer to the record to be dumped
  146. Return Value:
  147. None
  148. --*/
  149. {
  150. NODE_TYPE_CODE NodeType;
  151. PNODE_TYPE_CODE pNodeType;
  152. BOOLEAN Ret;
  153. //
  154. // We'll switch on the node type code
  155. //
  156. NP_READ_MEMORY(Ptr, NodeType, pNodeType);
  157. switch (NodeType) {
  158. case NPFS_NTC_VCB: Ret = NpDumpVcb((PVCB)Ptr); break;
  159. case NPFS_NTC_ROOT_DCB: Ret = NpDumpRootDcb((PDCB)Ptr); break;
  160. case NPFS_NTC_FCB: Ret = NpDumpFcb((PFCB)Ptr); break;
  161. case NPFS_NTC_CCB: Ret = NpDumpCcb((PCCB)Ptr); break;
  162. case NPFS_NTC_NONPAGED_CCB: Ret = NpDumpNonpagedCcb((PNONPAGED_CCB)Ptr); break;
  163. case NPFS_NTC_ROOT_DCB_CCB: Ret = NpDumpRootDcbCcb((PROOT_DCB_CCB)Ptr); break;
  164. default :
  165. Ret = TRUE;
  166. NpfskdPrint("NpDump - Unknown Node type code ", NodeType);
  167. break;
  168. }
  169. return Ret;
  170. }
  171. BOOLEAN NpDumpVcb (
  172. IN PVCB targetPtr
  173. )
  174. /*++
  175. Routine Description:
  176. Dump an Vcb structure
  177. Arguments:
  178. Ptr - Supplies the Device record to be dumped
  179. Return Value:
  180. None
  181. --*/
  182. {
  183. VCB Vcb;
  184. PVCB Ptr;
  185. TestForNull ("NpDumpVcb");
  186. DumpTitle (Vcb, (ULONG_PTR)(targetPtr));
  187. NP_READ_MEMORY(targetPtr, Vcb, Ptr);
  188. DumpField (NodeTypeCode);
  189. DumpField (RootDcb);
  190. DumpField (OpenCount);
  191. NpDump (Ptr->RootDcb);
  192. return TRUE;
  193. }
  194. BOOLEAN NpDumpRootDcb (
  195. IN PROOT_DCB targetPtr
  196. )
  197. /*++
  198. Routine Description:
  199. Dump a root dcb structure
  200. Arguments:
  201. Ptr - Supplies the Root Dcb record to be dumped
  202. Return Value:
  203. None
  204. --*/
  205. {
  206. PLIST_ENTRY Links;
  207. LIST_ENTRY NextEntry;
  208. ROOT_DCB RootDcb;
  209. PROOT_DCB Ptr;
  210. TestForNull ("NpDumpRootDcb");
  211. DumpTitle (RootDcb, (ULONG_PTR)(targetPtr));
  212. NP_READ_MEMORY(targetPtr, RootDcb, Ptr);
  213. DumpField (NodeTypeCode);
  214. DumpListEntry (ParentDcbLinks);
  215. DumpField (ParentDcb);
  216. DumpField (OpenCount);
  217. DumpField (FullFileName.Length);
  218. DumpField (FullFileName.Buffer);
  219. DumpName (FullFileName.Buffer);
  220. DumpField (LastFileName.Length);
  221. DumpName (LastFileName.Buffer);
  222. DumpListEntry (Specific.Dcb.NotifyFullQueue);
  223. DumpListEntry (Specific.Dcb.NotifyPartialQueue);
  224. DumpListEntry (Specific.Dcb.ParentDcbQueue);
  225. Links = Ptr->Specific.Dcb.ParentDcbQueue.Flink;
  226. if (!(NpDumpFlags & NPFS_WALK_LISTS)) {
  227. return TRUE;
  228. }
  229. while (Links != &Ptr->Specific.Dcb.ParentDcbQueue) {
  230. if (!NpfskdReadMemory(Links, &NextEntry, sizeof(NextEntry))) {
  231. return FALSE;
  232. }
  233. if (!NpDump(CONTAINING_RECORD(Links, FCB, ParentDcbLinks))) {
  234. return FALSE;
  235. }
  236. if (NpfskdCheckControlC()) {
  237. NpfskdPrintString("^C Typed. Bailing out","");
  238. return FALSE;
  239. }
  240. Links = NextEntry.Flink;
  241. }
  242. return TRUE;
  243. }
  244. BOOLEAN NpDumpFcb (
  245. IN PFCB targetPtr
  246. )
  247. /*++
  248. Routine Description:
  249. Dump an Fcb structure
  250. Arguments:
  251. Ptr - Supplies the Fcb record to be dumped
  252. Return Value:
  253. None
  254. --*/
  255. {
  256. PLIST_ENTRY Links;
  257. LIST_ENTRY NextEntry;
  258. FCB Fcb;
  259. PFCB Ptr;
  260. TestForNull ("NpDumpFcb");
  261. DumpTitle (Fcb, (ULONG_PTR)(targetPtr));
  262. NP_READ_MEMORY(targetPtr, Fcb , Ptr);
  263. DumpField (NodeTypeCode);
  264. DumpField (FullFileName.Length);
  265. DumpField (FullFileName.Buffer);
  266. DumpName (FullFileName.Buffer);
  267. if (NpDumpFlags & NPFS_FULL_INFORMATION) {
  268. DumpListEntry (ParentDcbLinks);
  269. DumpField (ParentDcb);
  270. DumpField (OpenCount);
  271. DumpField (LastFileName.Length);
  272. DumpName (LastFileName.Buffer);
  273. DumpField (Specific.Fcb.NamedPipeConfiguration);
  274. DumpField (Specific.Fcb.NamedPipeType);
  275. DumpField (Specific.Fcb.MaximumInstances);
  276. DumpField (Specific.Fcb.DefaultTimeOut.LowPart);
  277. DumpField (Specific.Fcb.DefaultTimeOut.HighPart);
  278. DumpListEntry (Specific.Fcb.CcbQueue);
  279. }
  280. if (!(NpDumpFlags & NPFS_WALK_LISTS)) {
  281. return TRUE;
  282. }
  283. Links = Ptr->Specific.Fcb.CcbQueue.Flink;
  284. while (Links != &Ptr->Specific.Fcb.CcbQueue) {
  285. if (!NpfskdReadMemory(Links, &NextEntry, sizeof(NextEntry))) {
  286. return FALSE;
  287. }
  288. if (!NpDump(CONTAINING_RECORD(Links, CCB, CcbLinks))) {
  289. return FALSE;
  290. }
  291. if (NpfskdCheckControlC()) {
  292. NpfskdPrintString("^C Typed. Bailing out","");
  293. return FALSE;
  294. }
  295. Links = NextEntry.Flink;
  296. }
  297. return TRUE;
  298. }
  299. BOOLEAN NpDumpCcb (
  300. IN PCCB targetPtr
  301. )
  302. /*++
  303. Routine Description:
  304. Dump a Ccb structure
  305. Arguments:
  306. Ptr - Supplies the Ccb record to be dumped
  307. Return Value:
  308. None
  309. --*/
  310. {
  311. PCCB Ptr;
  312. CCB Ccb;
  313. TestForNull ("NpDumpCcb");
  314. DumpTitle (Ccb, (ULONG_PTR)(targetPtr));
  315. NP_READ_MEMORY(targetPtr, Ccb, Ptr);
  316. DumpField (NodeTypeCode);
  317. DumpField (Fcb);
  318. DumpField (FileObject[FILE_PIPE_CLIENT_END]);
  319. DumpField (FileObject[FILE_PIPE_SERVER_END]);
  320. if (NpDumpFlags & NPFS_FULL_INFORMATION) {
  321. DumpField (NamedPipeState);
  322. DumpField (SecurityClientContext);
  323. DumpListEntry (ListeningQueue);
  324. }
  325. if (!NpDumpDataQueue(&targetPtr->DataQueue[FILE_PIPE_CLIENT_END])) {
  326. return FALSE;
  327. }
  328. if (!NpDumpDataQueue(&targetPtr->DataQueue[FILE_PIPE_SERVER_END])) {
  329. return FALSE;
  330. }
  331. return NpDump (Ptr->NonpagedCcb);
  332. }
  333. BOOLEAN NpDumpNonpagedCcb (
  334. IN PNONPAGED_CCB targetPtr
  335. )
  336. /*++
  337. Routine Description:
  338. Dump a Nonpaged Ccb structure
  339. Arguments:
  340. Ptr - Supplies the Nonpaged Ccb record to be dumped
  341. Return Value:
  342. None
  343. --*/
  344. {
  345. NONPAGED_CCB Ccb;
  346. PNONPAGED_CCB Ptr;
  347. TestForNull ("NpDumpNonpagedCcb");
  348. DumpTitle (NonpagedCcb, (ULONG_PTR)(targetPtr));
  349. NP_READ_MEMORY(targetPtr, Ccb, Ptr);
  350. DumpField (NodeTypeCode);
  351. DumpField (EventTableEntry[FILE_PIPE_CLIENT_END]);
  352. DumpField (EventTableEntry[FILE_PIPE_SERVER_END]);
  353. return TRUE;
  354. }
  355. BOOLEAN NpDumpRootDcbCcb (
  356. IN PROOT_DCB_CCB targetPtr
  357. )
  358. /*++
  359. Routine Description:
  360. Dump a Root Dcb Ccb structure
  361. Arguments:
  362. Ptr - Supplies the Root Dcb Ccb record to be dumped
  363. Return Value:
  364. None
  365. --*/
  366. {
  367. ROOT_DCB_CCB RootDcbCcb;
  368. PROOT_DCB_CCB Ptr;
  369. TestForNull ("NpDumpRootDcbCcb");
  370. DumpTitle (RootDcbCcb, (ULONG_PTR)(targetPtr));
  371. NP_READ_MEMORY(targetPtr, RootDcbCcb, Ptr);
  372. DumpField (NodeTypeCode);
  373. DumpField (IndexOfLastCcbReturned);
  374. return TRUE;
  375. }