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.

731 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. NtfsKd.c
  5. Abstract:
  6. KD Extension Api for examining Ntfs specific data structures
  7. Author:
  8. Keith Kaplan [KeithKa] 24-Apr-96
  9. Portions by Jeff Havens
  10. Environment:
  11. User Mode.
  12. Revision History:
  13. --*/
  14. #include "pch.h"
  15. KDDEBUGGER_DATA64 KdDebuggerData;
  16. //
  17. // The help strings printed out
  18. //
  19. static LPSTR Extensions[] = {
  20. "NTFS Debugger Extensions:\n",
  21. "cachedrecords Dump all threads with cached filerecord bcbs",
  22. "cachedruns [addr] Dump the given cached run array ",
  23. "ccb [addr] Dump Cache Control Block",
  24. "fcb [addr] [1|2|...] Dump File Control Block",
  25. "fcbtable [addr] [1|2|...] Dump File Control Block Table",
  26. "file [addr] [1|2|...] Dump File Object",
  27. "filerecord [addr] Dump the on-disk file record if cached, addr can be a fileobj, fcb or scb",
  28. "foirp [addr] [1|2|...] Dump File Object by IRP address",
  29. "hashtable [addr] Dump an lcb hashtable",
  30. "icthread [addr] [1|2|...] Dump IrpContext by thread address",
  31. "irpcontext [addr] [1|2|...] Dump IrpContext structure",
  32. "lcb [addr] Dump Link Control Block",
  33. "mcb [addr] Dump Map Control Block",
  34. "ntfsdata [1|2|...] Dump NtfsData structure",
  35. "ntfshelp Dump this display",
  36. "scb [addr] [1|2|...] Dump Stream Control Block",
  37. "transaction [addr] Dump the transaction attached to an irpcontext",
  38. "vcb [addr] [0|1|2] Dump Volume Control Block",
  39. 0
  40. };
  41. VOID
  42. ParseAndDump (
  43. IN PCHAR args,
  44. IN BOOL NoOptions,
  45. IN STRUCT_DUMP_ROUTINE DumpFunction,
  46. IN USHORT Processor,
  47. IN HANDLE hCurrentThread
  48. )
  49. /*++
  50. Routine Description:
  51. Parse command line arguments and dump an ntfs structure.
  52. Arguments:
  53. Args - String of arguments to parse.
  54. DumpFunction - Function to call with parsed arguments.
  55. Return Value:
  56. None
  57. --*/
  58. {
  59. CHAR StringStructToDump[1024];
  60. CHAR StringStructToDump2[1024];
  61. ULONG64 StructToDump = 0;
  62. ULONG64 StructToDump2 = 0;
  63. LONG Options;
  64. //
  65. // If the caller specified an address then that's the item we dump
  66. //
  67. StructToDump = 0;
  68. Options = 0;
  69. StringStructToDump[0] = '\0';
  70. if (*args) {
  71. if (NoOptions) {
  72. sscanf(args,"%s %s", StringStructToDump, StringStructToDump2 );
  73. if (!GetExpressionEx(args,&StructToDump, &args)) {
  74. dprintf("unable to get expression %s\n",StringStructToDump);
  75. return;
  76. }
  77. if (!GetExpressionEx(args,&StructToDump2, &args)) {
  78. dprintf("unable to get expression %s\n",StringStructToDump2);
  79. return;
  80. }
  81. } else {
  82. sscanf(args,"%s %lx", StringStructToDump, &Options );
  83. if (!GetExpressionEx(args,&StructToDump, &args)) {
  84. dprintf("unable to get expression %s\n",StringStructToDump);
  85. return;
  86. }
  87. }
  88. }
  89. (*DumpFunction) ( StructToDump, StructToDump2, Options, Processor, hCurrentThread );
  90. dprintf( "\n" );
  91. }
  92. VOID
  93. PrintHelp (
  94. VOID
  95. )
  96. /*++
  97. Routine Description:
  98. Dump out one line of help for each DECLARE_API
  99. Arguments:
  100. None
  101. Return Value:
  102. None
  103. --*/
  104. {
  105. int i;
  106. for( i=0; Extensions[i]; i++ ) {
  107. dprintf( " %s\n", Extensions[i] );
  108. }
  109. }
  110. DECLARE_API( ccb )
  111. /*++
  112. Routine Description:
  113. Dump ccb struct
  114. Arguments:
  115. arg - [Address] [options]
  116. Return Value:
  117. None
  118. --*/
  119. {
  120. INIT_API();
  121. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpCcb, (USHORT)dwProcessor, hCurrentThread );
  122. }
  123. DECLARE_API( fcb )
  124. /*++
  125. Routine Description:
  126. Dump fcb struct
  127. Arguments:
  128. arg - [Address] [options]
  129. Return Value:
  130. None
  131. --*/
  132. {
  133. INIT_API();
  134. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpFcb, (USHORT)dwProcessor, hCurrentThread );
  135. }
  136. DECLARE_API( fcbtable )
  137. /*++
  138. Routine Description:
  139. Dump fcb table struct
  140. Arguments:
  141. arg - [Address] [options]
  142. Return Value:
  143. None
  144. --*/
  145. {
  146. INIT_API();
  147. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpFcbTable, (USHORT)dwProcessor, hCurrentThread );
  148. }
  149. DECLARE_API( file )
  150. /*++
  151. Routine Description:
  152. Dump FileObject struct
  153. Arguments:
  154. arg - [Address] [options]
  155. Return Value:
  156. None
  157. --*/
  158. {
  159. INIT_API();
  160. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpFileObject, (USHORT)dwProcessor, hCurrentThread );
  161. }
  162. DECLARE_API( filerecord )
  163. /*++
  164. Routine Description:
  165. Dump file record struct
  166. Arguments:
  167. arg - [Address] [options]
  168. Return Value:
  169. None
  170. --*/
  171. {
  172. INIT_API();
  173. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpFileRecord, (USHORT)dwProcessor, hCurrentThread );
  174. }
  175. DECLARE_API( foirp )
  176. /*++
  177. Routine Description:
  178. Dump FileObject struct, given an irp
  179. Arguments:
  180. arg - [Address] [options]
  181. Return Value:
  182. None
  183. --*/
  184. {
  185. INIT_API();
  186. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpFileObjectFromIrp, (USHORT)dwProcessor, hCurrentThread );
  187. }
  188. DECLARE_API( icthread )
  189. /*++
  190. Routine Description:
  191. Dump IrpContext struct, given a Thread
  192. Arguments:
  193. arg - [Address] [options]
  194. Return Value:
  195. None
  196. --*/
  197. {
  198. INIT_API();
  199. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpIrpContextFromThread, (USHORT)dwProcessor, hCurrentThread );
  200. }
  201. DECLARE_API( irpcontext )
  202. /*++
  203. Routine Description:
  204. Dump IrpContext
  205. Arguments:
  206. arg - [Address] [options]
  207. Return Value:
  208. None
  209. --*/
  210. {
  211. INIT_API();
  212. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpIrpContext, (USHORT)dwProcessor, hCurrentThread );
  213. }
  214. DECLARE_API( lcb )
  215. /*++
  216. Routine Description:
  217. Dump lcb struct
  218. Arguments:
  219. arg - [Address] [options]
  220. Return Value:
  221. None
  222. --*/
  223. {
  224. INIT_API();
  225. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpLcb, (USHORT)dwProcessor, hCurrentThread );
  226. }
  227. DECLARE_API( logfile )
  228. /*++
  229. Routine Description:
  230. Dump log file
  231. Arguments:
  232. arg - [Address] [options]
  233. Return Value:
  234. None
  235. --*/
  236. {
  237. INIT_API();
  238. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpLogFile, (USHORT)dwProcessor, hCurrentThread );
  239. }
  240. DECLARE_API( mcb )
  241. /*++
  242. Routine Description:
  243. Dump mcb struct
  244. Arguments:
  245. arg - [Address] [options]
  246. Return Value:
  247. None
  248. --*/
  249. {
  250. INIT_API();
  251. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpMcb, (USHORT)dwProcessor, hCurrentThread );
  252. }
  253. DECLARE_API( ntfsdata )
  254. /*++
  255. Routine Description:
  256. Dump the NtfsData struct
  257. Arguments:
  258. arg - [options]
  259. Return Value:
  260. None
  261. --*/
  262. {
  263. INIT_API();
  264. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpNtfsData, (USHORT)dwProcessor, hCurrentThread );
  265. }
  266. DECLARE_API( ntfshelp )
  267. /*++
  268. Routine Description:
  269. Dump help message
  270. Arguments:
  271. None
  272. Return Value:
  273. None
  274. --*/
  275. {
  276. INIT_API();
  277. PrintHelp();
  278. }
  279. DECLARE_API( scb )
  280. /*++
  281. Routine Description:
  282. Dump Scb struct
  283. Arguments:
  284. arg - [Address] [options]
  285. Return Value:
  286. None
  287. --*/
  288. {
  289. INIT_API();
  290. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpScb, (USHORT)dwProcessor, hCurrentThread );
  291. }
  292. DECLARE_API( vcb )
  293. /*++
  294. Routine Description:
  295. Dump Vcb struct
  296. Arguments:
  297. arg - [Address] [options]
  298. Return Value:
  299. None
  300. --*/
  301. {
  302. INIT_API();
  303. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpVcb, (USHORT)dwProcessor, hCurrentThread );
  304. }
  305. DECLARE_API( dsc )
  306. /*++
  307. Routine Description:
  308. Dump private syscache log from SCB
  309. Arguments:
  310. arg - [scb address]
  311. Return Value:
  312. None
  313. --*/
  314. {
  315. INIT_API();
  316. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpSysCache, (USHORT)dwProcessor, hCurrentThread );
  317. }
  318. DECLARE_API( cachedrecords )
  319. /*++
  320. Routine Description:
  321. Dump private syscache log from SCB
  322. Arguments:
  323. arg - [scb address]
  324. Return Value:
  325. None
  326. --*/
  327. {
  328. INIT_API();
  329. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpCachedRecords, (USHORT)dwProcessor, hCurrentThread );
  330. }
  331. DECLARE_API( extents )
  332. /*++
  333. Routine Description:
  334. Dump private syscache log from SCB
  335. Arguments:
  336. arg - [scb address]
  337. Return Value:
  338. None
  339. --*/
  340. {
  341. INIT_API();
  342. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpExtents, (USHORT)dwProcessor, hCurrentThread );
  343. }
  344. DECLARE_API( hashtable )
  345. /*++
  346. Routine Description:
  347. Dump private syscache log from SCB
  348. Arguments:
  349. arg - [scb address]
  350. Return Value:
  351. None
  352. --*/
  353. {
  354. INIT_API();
  355. ParseAndDump( (PCHAR) args, TRUE, (STRUCT_DUMP_ROUTINE) DumpHashTable, (USHORT)dwProcessor, hCurrentThread );
  356. }
  357. DECLARE_API( dumpchain )
  358. /*++
  359. Routine Description:
  360. Dump private syscache log from SCB
  361. Arguments:
  362. arg - [scb address]
  363. Return Value:
  364. None
  365. --*/
  366. {
  367. INIT_API();
  368. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpFcbLcbChain, (USHORT)dwProcessor, hCurrentThread );
  369. }
  370. DECLARE_API( overflow )
  371. /*++
  372. Routine Description:
  373. Dump private syscache log from SCB
  374. Arguments:
  375. arg - [scb address]
  376. Return Value:
  377. None
  378. --*/
  379. {
  380. INIT_API();
  381. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpOverflow, (USHORT)dwProcessor, hCurrentThread );
  382. }
  383. DECLARE_API( cachedruns )
  384. /*++
  385. Routine Description:
  386. Dump the cached runs structure
  387. Arguments:
  388. arg - [cached runs address]
  389. Return Value:
  390. None
  391. --*/
  392. {
  393. INIT_API();
  394. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpCachedRuns, (USHORT)dwProcessor, hCurrentThread );
  395. }
  396. DECLARE_API( transaction )
  397. /*++
  398. Routine Description:
  399. Dump the transaction associated with the given irpcontext
  400. Arguments:
  401. arg - [irpcontext]
  402. Return Value:
  403. None
  404. --*/
  405. {
  406. INIT_API();
  407. ParseAndDump( (PCHAR) args, FALSE, (STRUCT_DUMP_ROUTINE) DumpTransaction, (USHORT)dwProcessor, hCurrentThread );
  408. }