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.

433 lines
13 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. RxData.c
  5. Abstract:
  6. This module declares the global data used by the Rx file system.
  7. Author:
  8. JoeLinn [JoeLinn] 1-Dec-94
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #include "stdarg.h"
  14. #include "stdio.h"
  15. #include "string.h"
  16. #include "prefix.h"
  17. #if DBG
  18. LONG RxDebugTraceIndent = 0;
  19. #endif
  20. #if RDBSSTRACE
  21. BOOLEAN RxGlobalTraceSuppress = FALSE;
  22. BOOLEAN RxNextGlobalTraceSuppress = FALSE;
  23. #define MAXIMUM_DEBUGTRACE_CONTROLS 200
  24. ULONG RxMaximumTraceControl;
  25. RX_DEBUG_TRACE_CONTROL RxDebugTraceControl[MAXIMUM_DEBUGTRACE_CONTROLS];
  26. #define DEBUGTRACE_NAMEBUFFERSIZE 800
  27. CHAR RxDebugTraceNameBuffer[DEBUGTRACE_NAMEBUFFERSIZE];
  28. ULONG RxDTNMptr = 0;
  29. BOOLEAN RxDTNMCopy = FALSE;
  30. PCHAR RxStorageTypeNames[256];
  31. PCHAR RxIrpCodeToName[IRP_MJ_MAXIMUM_FUNCTION+1];
  32. ULONG RxIrpCodeCount[IRP_MJ_MAXIMUM_FUNCTION+1];
  33. #endif // RDBSSTRACE
  34. #if RDBSSTRACE
  35. //we declare controlpoints differently in the rdbss than in a minirdr. at some point,
  36. // minirdrs may come and go. for this reason we have to save the name text in
  37. // a nontransient rdbss storage. for rdbss controlpoints, we just use the name
  38. // pointer we're given since it is just as persistent as the copy. whether we copy
  39. // or just point is controlled
  40. #define RXDT_Declare(__x) DEBUG_TRACE_CONTROLPOINT RX_DEBUG_TRACE_##__x
  41. RXDT_Declare(ERROR);
  42. RXDT_Declare(HOOKS);
  43. RXDT_Declare(CATCH_EXCEPTIONS);
  44. RXDT_Declare(UNWIND);
  45. RXDT_Declare(CLEANUP);
  46. RXDT_Declare(CLOSE);
  47. RXDT_Declare(CREATE);
  48. RXDT_Declare(DIRCTRL);
  49. RXDT_Declare(EA);
  50. RXDT_Declare(FILEINFO);
  51. RXDT_Declare(FSCTRL);
  52. RXDT_Declare(LOCKCTRL);
  53. RXDT_Declare(READ);
  54. RXDT_Declare(VOLINFO);
  55. RXDT_Declare(WRITE);
  56. RXDT_Declare(FLUSH);
  57. RXDT_Declare(DEVCTRL);
  58. RXDT_Declare(SHUTDOWN);
  59. RXDT_Declare(PREFIX);
  60. RXDT_Declare(DEVFCB);
  61. RXDT_Declare(ACCHKSUP);
  62. RXDT_Declare(ALLOCSUP);
  63. RXDT_Declare(DIRSUP);
  64. RXDT_Declare(FILOBSUP);
  65. RXDT_Declare(NAMESUP);
  66. RXDT_Declare(VERFYSUP);
  67. RXDT_Declare(CACHESUP);
  68. RXDT_Declare(SPLAYSUP);
  69. RXDT_Declare(DEVIOSUP);
  70. RXDT_Declare(FCBSTRUCTS);
  71. RXDT_Declare(STRUCSUP);
  72. RXDT_Declare(FSP_DISPATCHER);
  73. RXDT_Declare(FSP_DUMP);
  74. RXDT_Declare(RXCONTX);
  75. RXDT_Declare(DISPATCH);
  76. RXDT_Declare(NTFASTIO);
  77. RXDT_Declare(LOWIO);
  78. RXDT_Declare(MINIRDR);
  79. RXDT_Declare(DISCCODE); //for the browser interface stuff
  80. RXDT_Declare(BROWSER);
  81. RXDT_Declare(CONNECT);
  82. RXDT_Declare(NTTIMER);
  83. RXDT_Declare(SCAVTHRD);
  84. RXDT_Declare(SCAVENGER);
  85. RXDT_Declare(SHAREACCESS);
  86. RXDT_Declare(NAMECACHE);
  87. // connection engine stuff
  88. RXDT_Declare(RXCEBINDING);
  89. RXDT_Declare(RXCEDBIMPLEMENTATION);
  90. RXDT_Declare(RXCEMANAGEMENT);
  91. RXDT_Declare(RXCEXMIT);
  92. RXDT_Declare(RXCEPOOL);
  93. RXDT_Declare(RXCETDI);
  94. VOID
  95. RxInitializeDebugTraceControlPoint(
  96. PSZ Name,
  97. PDEBUG_TRACE_CONTROLPOINT ControlPoint
  98. )
  99. {
  100. ULONG i;
  101. RxMaximumTraceControl++;
  102. i = RxMaximumTraceControl;
  103. ASSERT(i<MAXIMUM_DEBUGTRACE_CONTROLS);
  104. RxDebugTraceControl[i].PrintLevel = 1000;
  105. RxDebugTraceControl[i].BreakMask = 0xf0000000;
  106. if (RxDTNMCopy) {
  107. ULONG len = strlen(Name)+1;
  108. ASSERT (RxDTNMptr+len<DEBUGTRACE_NAMEBUFFERSIZE);
  109. RxDebugTraceControl[i].Name= &RxDebugTraceNameBuffer[RxDTNMptr];
  110. RtlCopyMemory(RxDebugTraceControl[i].Name,Name,len);
  111. RxDTNMptr += len;
  112. } else {
  113. RxDebugTraceControl[i].Name=Name;
  114. }
  115. RxDebugTraceControl[i+1].Name=NULL;
  116. ControlPoint->Name=RxDebugTraceControl[i].Name;
  117. ControlPoint->ControlPointNumber = i;
  118. }
  119. #ifdef RxInitializeDebugTrace
  120. #undef RxInitializeDebugTrace
  121. #endif
  122. VOID RxInitializeDebugTrace(void){
  123. int i;
  124. RxDebugTraceIndent = 0;
  125. RxGlobalTraceSuppress = TRUE;
  126. RxNextGlobalTraceSuppress = TRUE;
  127. RxExports.pRxDebugTraceIndent = &RxDebugTraceIndent;
  128. for (i=0;i<=IRP_MJ_MAXIMUM_FUNCTION;i++) {
  129. RxIrpCodeCount[i] = 0;
  130. }
  131. #if RDBSSTRACE
  132. #define OneName(x) { RxInitializeDebugTraceControlPoint(#x, &RX_DEBUG_TRACE_##x); }
  133. RxMaximumTraceControl=0;
  134. OneName(ACCHKSUP);
  135. OneName(ALLOCSUP);
  136. OneName(BROWSER);
  137. OneName(CACHESUP);
  138. OneName(CATCH_EXCEPTIONS);
  139. OneName(CLEANUP);
  140. OneName(CLOSE);
  141. OneName(CONNECT);
  142. OneName(CREATE);
  143. OneName(HOOKS);
  144. OneName(DEVCTRL);
  145. OneName(DEVFCB);
  146. OneName(DEVIOSUP);
  147. OneName(DIRCTRL);
  148. OneName(DIRSUP);
  149. OneName(DISCCODE);
  150. OneName(DISPATCH);
  151. OneName(EA);
  152. OneName(ERROR);
  153. OneName(FCBSTRUCTS);
  154. OneName(FILEINFO);
  155. OneName(FILOBSUP);
  156. OneName(FLUSH);
  157. OneName(FSCTRL);
  158. OneName(FSP_DISPATCHER);
  159. OneName(FSP_DUMP);
  160. OneName(RXCONTX);
  161. OneName(LOCKCTRL);
  162. OneName(LOWIO);
  163. OneName(MINIRDR);
  164. OneName(NAMESUP);
  165. OneName(NTFASTIO);
  166. OneName(NTTIMER);
  167. OneName(PREFIX);
  168. OneName(READ);
  169. OneName(SCAVTHRD);
  170. OneName(SHUTDOWN);
  171. OneName(SPLAYSUP);
  172. OneName(STRUCSUP);
  173. OneName(UNWIND);
  174. OneName(VERFYSUP);
  175. OneName(VOLINFO);
  176. OneName(WRITE);
  177. OneName(SCAVENGER);
  178. OneName(SHAREACCESS);
  179. OneName(NAMECACHE);
  180. OneName(RXCEBINDING); //connection engine
  181. OneName(RXCEDBIMPLEMENTATION);
  182. OneName(RXCEMANAGEMENT);
  183. OneName(RXCEXMIT);
  184. OneName(RXCEPOOL);
  185. OneName(RXCETDI);
  186. RxDTNMCopy = FALSE; // from now on, copy the name
  187. RxDebugTraceControl[RX_DEBUG_TRACE_ALLOCSUP.ControlPointNumber].PrintLevel = 0; //get rid of annoying logof msg
  188. RxDebugTraceControl[RX_DEBUG_TRACE_DISCCODE.ControlPointNumber].PrintLevel = 0; //it's just too much
  189. RxDebugTraceControl[RX_DEBUG_TRACE_BROWSER.ControlPointNumber].PrintLevel = 0; //it's just too much
  190. //RxDebugTraceControl[RX_DEBUG_TRACE_CREATE.ControlPointNumber].PrintLevel = 0;
  191. #endif //rdbsstrace
  192. RxIrpCodeToName[IRP_MJ_CREATE] = "CREATE";
  193. RxIrpCodeToName[IRP_MJ_CREATE_NAMED_PIPE] = "CREATE_NAMED_PIPE";
  194. RxIrpCodeToName[IRP_MJ_CLOSE] = "CLOSE";
  195. RxIrpCodeToName[IRP_MJ_READ] = "READ";
  196. RxIrpCodeToName[IRP_MJ_WRITE] = "WRITE";
  197. RxIrpCodeToName[IRP_MJ_QUERY_INFORMATION] = "QUERY_INFORMATION";
  198. RxIrpCodeToName[IRP_MJ_SET_INFORMATION] = "SET_INFORMATION";
  199. RxIrpCodeToName[IRP_MJ_QUERY_EA] = "QUERY_EA";
  200. RxIrpCodeToName[IRP_MJ_SET_EA] = "SET_EA";
  201. RxIrpCodeToName[IRP_MJ_FLUSH_BUFFERS] = "FLUSH_BUFFERS";
  202. RxIrpCodeToName[IRP_MJ_QUERY_VOLUME_INFORMATION] = "QUERY_VOLUME_INFORMATION";
  203. RxIrpCodeToName[IRP_MJ_SET_VOLUME_INFORMATION] = "SET_VOLUME_INFORMATION";
  204. RxIrpCodeToName[IRP_MJ_DIRECTORY_CONTROL] = "DIRECTORY_CONTROL";
  205. RxIrpCodeToName[IRP_MJ_FILE_SYSTEM_CONTROL] = "FILE_SYSTEM_CONTROL";
  206. RxIrpCodeToName[IRP_MJ_DEVICE_CONTROL] = "DEVICE_CONTROL";
  207. RxIrpCodeToName[IRP_MJ_INTERNAL_DEVICE_CONTROL] = "INTERNAL_DEVICE_CONTROL";
  208. RxIrpCodeToName[IRP_MJ_SHUTDOWN] = "SHUTDOWN";
  209. RxIrpCodeToName[IRP_MJ_LOCK_CONTROL] = "LOCK_CONTROL";
  210. RxIrpCodeToName[IRP_MJ_CLEANUP] = "CLEANUP";
  211. RxIrpCodeToName[IRP_MJ_CREATE_MAILSLOT] = "CREATE_MAILSLOT";
  212. RxIrpCodeToName[IRP_MJ_QUERY_SECURITY] = "QUERY_SECURITY";
  213. RxIrpCodeToName[IRP_MJ_SET_SECURITY] = "SET_SECURITY";
  214. RxIrpCodeToName[IRP_MJ_POWER] = "POWER";
  215. RxIrpCodeToName[IRP_MJ_SYSTEM_CONTROL] = "SYSTEM_CONTROL";
  216. RxIrpCodeToName[IRP_MJ_DEVICE_CHANGE] = "DEVICE_CHANGE";
  217. RxIrpCodeToName[IRP_MJ_QUERY_QUOTA] = "QUERY_QUOTA";
  218. RxIrpCodeToName[IRP_MJ_SET_QUOTA] = "SET_QUOTA";
  219. RxIrpCodeToName[IRP_MJ_PNP_POWER] = "PNP";
  220. }
  221. VOID
  222. RxDebugTraceDebugCommand(
  223. PSZ name,
  224. ULONG level,
  225. ULONG pointcount
  226. )
  227. {
  228. ULONG i,mask;
  229. //RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("name/num/!c %s/%lu/%lu!!\n", name, level, pointcount));
  230. for (i=1;i<RxMaximumTraceControl;i++) {
  231. PRX_DEBUG_TRACE_CONTROL control = &RxDebugTraceControl[i];
  232. ULONG l = strlen(name);
  233. //RxDbgTrace(0, (DEBUG_TRACE_ALWAYS), ("----->checking %s\n",control->Name));
  234. if (strncmp(name,control->Name,l)) continue;
  235. RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("---> got it %s/%lu/%lu !!\n", control->Name, level, pointcount));
  236. if (pointcount==0) {
  237. control->PrintLevel = level;
  238. } else if (pointcount <= 2) {
  239. if (level==0) {
  240. mask = 0xffffffff;
  241. } else {
  242. mask = 1 << (level-1);
  243. }
  244. if (pointcount==1) {
  245. control->BreakMask |= mask;
  246. } else {
  247. control->BreakMask &= ~mask;
  248. }
  249. }
  250. }
  251. }
  252. #ifdef RxDbgTraceDisableGlobally
  253. #undef RxDbgTraceDisableGlobally
  254. #endif
  255. BOOLEAN
  256. RxDbgTraceDisableGlobally(void)
  257. {
  258. BOOLEAN flag = RxGlobalTraceSuppress;
  259. RxGlobalTraceSuppress = TRUE;
  260. return flag;
  261. }
  262. #ifdef RxDbgTraceEnableGlobally
  263. #undef RxDbgTraceEnableGlobally
  264. #endif
  265. VOID
  266. RxDbgTraceEnableGlobally(BOOLEAN flag)
  267. {
  268. RxNextGlobalTraceSuppress = RxGlobalTraceSuppress = flag;
  269. }
  270. VOID
  271. RxDebugTraceZeroAllPrintLevels(
  272. void
  273. )
  274. {
  275. ULONG i;
  276. for (i=1;i<RxMaximumTraceControl;i++) {
  277. PRX_DEBUG_TRACE_CONTROL control = &RxDebugTraceControl[i];
  278. control->PrintLevel = 0; // disable output
  279. }
  280. }
  281. BOOLEAN
  282. RxDbgTraceActualNew (
  283. IN ULONG NewMask,
  284. IN OUT PDEBUG_TRACE_CONTROLPOINT ControlPoint
  285. )
  286. {
  287. /*
  288. This routine has the responsibility to determine if a particular dbgprint is going to be printed and ifso to
  289. fiddle with the indent. so the return value is whether to print; it is also used for just fiddling with the indent
  290. by setting the highoredr bit of the mask.
  291. The Mask is now very complicated owing to the large number of dbgprints i'm trying to control...sigh.
  292. The low order byte is the controlpoint....usually the file. each controlpoint has a current level associated
  293. with it. if the level of a a debugtrace is less that then current control level then the debug is printed.
  294. The next byte is the level of this particular call; again if the level is <= the current level for the control
  295. you get printed. The next byte is the indent. indents are only processed if printing is done.
  296. */
  297. LONG Indent = ((NewMask>>RxDT_INDENT_SHIFT)&RxDT_INDENT_MASK) - RxDT_INDENT_EXCESS;
  298. LONG LevelOfThisWrite = (NewMask) & RxDT_LEVEL_MASK;
  299. BOOLEAN PrintIt = (NewMask&RxDT_SUPPRESS_PRINT)==0;
  300. BOOLEAN OverrideReturn = (NewMask&RxDT_OVERRIDE_RETURN)!=0;
  301. LONG _i;
  302. ASSERT (Indent==1 || Indent==0 || (Indent==-1));
  303. if (RxGlobalTraceSuppress) return FALSE;
  304. #if 0
  305. if (ControlPoint!=NULL){
  306. ULONG ControlPointNumber = ControlPoint->ControlPointNumber;
  307. if (ControlPointNumber==0) {
  308. if (!RxDbgTraceFindControlPointActual(ControlPoint)){
  309. //couldnt find or initialize the control point text.....hmmmmmmmmmmm
  310. ASSERT(!"bad return from findcontrolpoint");
  311. return(FALSE);
  312. }
  313. ControlPointNumber = ControlPoint->ControlPointNumber;
  314. }
  315. ASSERT(ControlPointNumber && ControlPointNumber<=RxMaximumTraceControl);
  316. if (LevelOfThisWrite > RxDebugTraceControl[ControlPointNumber].PrintLevel ) return FALSE;
  317. }
  318. #else
  319. PrintIt = TRUE;
  320. #endif
  321. if ((Indent) > 0) {
  322. RxDebugTraceIndent += (Indent);
  323. }
  324. if (PrintIt) {
  325. _i = (ULONG)((ULONG_PTR)PsGetCurrentThread());
  326. if (RxDebugTraceIndent < 0) {
  327. RxDebugTraceIndent = 0;
  328. }
  329. DbgPrint("%08lx:%-*s",_i,(int)(RxDebugTraceIndent),"");
  330. }
  331. if (Indent < 0) {
  332. RxDebugTraceIndent += (Indent);
  333. }
  334. ASSERT (RxDebugTraceIndent <= 0x40);
  335. return PrintIt||OverrideReturn;
  336. }
  337. PRX_DEBUG_TRACE_CONTROL
  338. RxDbgTraceFindControlPointActual(
  339. IN OUT PDEBUG_TRACE_CONTROLPOINT ControlPoint
  340. )
  341. {
  342. ULONG i,ControlPointNumber;
  343. PUCHAR name;
  344. ASSERT (ControlPoint);
  345. ControlPointNumber = ControlPoint->ControlPointNumber;
  346. if (ControlPointNumber) return (&RxDebugTraceControl[ControlPointNumber]);
  347. //otherwise, we have to look it up..........
  348. name = ControlPoint->Name;
  349. for (i=1;i<RxMaximumTraceControl;i++) {
  350. PRX_DEBUG_TRACE_CONTROL control = &RxDebugTraceControl[i];
  351. ULONG l = strlen(name);
  352. //RxDbgTrace(0, (DEBUG_TRACE_ALWAYS), ("----->checking %s\n",control->Name));
  353. if (strncmp(name,control->Name,l)) continue;
  354. DbgPrint("Controlpointlookup=%08lx<%s> to %08lx\n",
  355. ControlPoint,ControlPoint->Name,i);
  356. ControlPoint->ControlPointNumber = i;
  357. return(control);
  358. }
  359. DbgPrint("Couldn't find ControlPointName=%s...inserting\n",name);
  360. RxInitializeDebugTraceControlPoint(name,ControlPoint); //actually copies the name
  361. return (&RxDebugTraceControl[ControlPoint->ControlPointNumber]);
  362. }
  363. #endif // RDBSSTRACE