Source code of Windows XP (NT5)
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.

789 lines
25 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. NtfsData.h
  5. Abstract:
  6. This module declares the global data used by the Ntfs file system.
  7. Author:
  8. Gary Kimura [GaryKi] 28-Dec-1989
  9. Revision History:
  10. --*/
  11. #ifndef _NTFSDATA_
  12. #define _NTFSDATA_
  13. //
  14. // The following are used to determine what level of protection to attach
  15. // to system files and attributes.
  16. //
  17. extern BOOLEAN NtfsProtectSystemFiles;
  18. extern BOOLEAN NtfsProtectSystemAttributes;
  19. //
  20. // The following is used to indicate the multiplier value for the Mft zone.
  21. //
  22. extern ULONG NtfsMftZoneMultiplier;
  23. //
  24. // Debug code for finding corruption.
  25. //
  26. /*
  27. #if (DBG || defined( NTFS_FREE_ASSERTS ))
  28. */
  29. extern BOOLEAN NtfsBreakOnCorrupt;
  30. /*
  31. #endif
  32. */
  33. //
  34. // Enable compression on the wire.
  35. //
  36. extern BOOLEAN NtfsEnableCompressedIO;
  37. //
  38. // Default restart version.
  39. //
  40. extern ULONG NtfsDefaultRestartVersion;
  41. //
  42. // Performance statistics
  43. //
  44. extern ULONG NtfsMaxDelayedCloseCount;
  45. extern ULONG NtfsMinDelayedCloseCount;
  46. extern ULONG NtfsThrottleCreates;
  47. extern ULONG NtfsFailedHandedOffPagingFileOps;
  48. extern ULONG NtfsFailedPagingFileOps;
  49. extern ULONG NtfsFailedLfsRestart;
  50. extern ULONG NtfsCleanCheckpoints;
  51. extern ULONG NtfsPostRequests;
  52. //
  53. // The global fsd data record
  54. //
  55. extern NTFS_DATA NtfsData;
  56. //
  57. // Mutant to synchronize creation of stream files. This can be acquired recursively
  58. // which we need in this case
  59. //
  60. extern KMUTANT StreamFileCreationMutex;
  61. //
  62. // Notification event for creation of encrypted files.
  63. //
  64. extern KEVENT NtfsEncryptionPendingEvent;
  65. #ifdef KEITHKA
  66. extern ULONG EncryptionPendingCount;
  67. #endif
  68. //
  69. // A mutex and queue of NTFS MCBS that will be freed
  70. // if we reach over a certain threshold
  71. //
  72. extern FAST_MUTEX NtfsMcbFastMutex;
  73. extern LIST_ENTRY NtfsMcbLruQueue;
  74. extern ULONG NtfsMcbHighWaterMark;
  75. extern ULONG NtfsMcbLowWaterMark;
  76. extern ULONG NtfsMcbCurrentLevel;
  77. extern BOOLEAN NtfsMcbCleanupInProgress;
  78. extern WORK_QUEUE_ITEM NtfsMcbWorkItem;
  79. //
  80. // The following are global large integer constants used throughout ntfs
  81. // We declare the actual name using Ntfs prefixes to avoid any linking
  82. // conflicts but internally in the file system we'll use smaller Li prefixes
  83. // to denote the values.
  84. //
  85. extern LARGE_INTEGER NtfsLarge0;
  86. extern LARGE_INTEGER NtfsLarge1;
  87. extern LARGE_INTEGER NtfsLargeMax;
  88. extern LARGE_INTEGER NtfsLargeEof;
  89. extern LONGLONG NtfsLastAccess;
  90. #define Li0 (NtfsLarge0)
  91. #define Li1 (NtfsLarge1)
  92. #define LiMax (NtfsLargeMax)
  93. #define LiEof (NtfsLargeEof)
  94. #define MAXULONGLONG (0xffffffffffffffff)
  95. #define UNUSED_LCN ((LONGLONG)(-1))
  96. //
  97. // Maximum file size is limited by MM's shift from file size to number of pages.
  98. //
  99. #define MAXFILESIZE (0xfffffff0000)
  100. //
  101. // Maximum clusters per Ntfs Mcb range. We currently only support (2^32 - 1)
  102. // clusters in an Mcb.
  103. //
  104. #define MAX_CLUSTERS_PER_RANGE (0x100000000 - 1)
  105. //
  106. // The following fields are used to allocate nonpaged structures
  107. // using a lookaside list, and other fixed sized structures from a
  108. // small cache.
  109. //
  110. extern NPAGED_LOOKASIDE_LIST NtfsIoContextLookasideList;
  111. extern NPAGED_LOOKASIDE_LIST NtfsIrpContextLookasideList;
  112. extern NPAGED_LOOKASIDE_LIST NtfsKeventLookasideList;
  113. extern NPAGED_LOOKASIDE_LIST NtfsScbNonpagedLookasideList;
  114. extern NPAGED_LOOKASIDE_LIST NtfsScbSnapshotLookasideList;
  115. extern NPAGED_LOOKASIDE_LIST NtfsCompressSyncLookasideList;
  116. extern PAGED_LOOKASIDE_LIST NtfsCcbLookasideList;
  117. extern PAGED_LOOKASIDE_LIST NtfsCcbDataLookasideList;
  118. extern PAGED_LOOKASIDE_LIST NtfsDeallocatedRecordsLookasideList;
  119. extern PAGED_LOOKASIDE_LIST NtfsFcbDataLookasideList;
  120. extern PAGED_LOOKASIDE_LIST NtfsFcbIndexLookasideList;
  121. extern PAGED_LOOKASIDE_LIST NtfsIndexContextLookasideList;
  122. extern PAGED_LOOKASIDE_LIST NtfsLcbLookasideList;
  123. extern PAGED_LOOKASIDE_LIST NtfsNukemLookasideList;
  124. extern PAGED_LOOKASIDE_LIST NtfsScbDataLookasideList;
  125. //
  126. // This is the string for the name of the index allocation attributes.
  127. //
  128. extern const UNICODE_STRING NtfsFileNameIndex;
  129. //
  130. // This is the string for the attribute code for index allocation.
  131. // $INDEX_ALLOCATION.
  132. //
  133. extern const UNICODE_STRING NtfsIndexAllocation;
  134. //
  135. // This is the string for the data attribute, $DATA.
  136. //
  137. extern const UNICODE_STRING NtfsDataString;
  138. //
  139. // This is the string for the bitmap attribute, $BITMAP.
  140. //
  141. extern const UNICODE_STRING NtfsBitmapString;
  142. //
  143. // This is the string for the attribute list attribute, $ATTRIBUTE_LIST.
  144. //
  145. extern const UNICODE_STRING NtfsAttrListString;
  146. //
  147. // This is the string for the reparse pt. attribute, $REPARSE_POINT
  148. //
  149. extern const UNICODE_STRING NtfsReparsePointString;
  150. //
  151. // These strings are used as the Scb->AttributeName for
  152. // user-opened general indices.
  153. //
  154. extern const UNICODE_STRING NtfsObjId;
  155. extern const UNICODE_STRING NtfsQuota;
  156. extern const UNICODE_STRING JournalStreamName;
  157. //
  158. // These are the strings for the files in the extend directory.
  159. //
  160. extern const UNICODE_STRING NtfsExtendName;
  161. extern const UNICODE_STRING NtfsUsnJrnlName;
  162. extern const UNICODE_STRING NtfsQuotaName;
  163. extern const UNICODE_STRING NtfsObjectIdName;
  164. extern const UNICODE_STRING NtfsMountTableName;
  165. //
  166. // This strings are used for informational popups.
  167. //
  168. extern const UNICODE_STRING NtfsSystemFiles[];
  169. //
  170. // This is the '.' string to use to lookup the parent entry.
  171. //
  172. extern const UNICODE_STRING NtfsRootIndexString;
  173. extern const UNICODE_STRING NtfsInternalUseFile[];
  174. #define CHANGEATTRIBUTEVALUE_FILE_NUMBER (0) // $ChangeAttributeValue
  175. #define CHANGEATTRIBUTEVALUE2_FILE_NUMBER (1) // $ChangeAttributeValue2
  176. #define COMMONCLEANUP_FILE_NUMBER (2) // $CommonCleanup
  177. #define CONVERTTONONRESIDENT_FILE_NUMBER (3) // $ConvertToNonresident
  178. #define CREATENONRESIDENTWITHVALUE_FILE_NUMBER (4) // $CreateNonresidentWithValue
  179. #define DEALLOCATERECORD_FILE_NUMBER (5) // $DeallocateRecord
  180. #define DELETEALLOCATIONFROMRECORD_FILE_NUMBER (6) // $DeleteAllocationFromRecord
  181. #define DIRECTORY_FILE_NUMBER (7) // $Directory
  182. #define INITIALIZERECORDALLOCATION_FILE_NUMBER (8) // $InitializeRecordAllocation
  183. #define MAPATTRIBUTEVALUE_FILE_NUMBER (9) // $MapAttributeValue
  184. #define NONCACHEDIO_FILE_NUMBER (10) // $NonCachedIo
  185. #define PERFORMHOTFIX_FILE_NUMBER (11) // $PerformHotFix
  186. #define PREPARETOSHRINKFILESIZE_FILE_NUMBER (12) // $PrepareToShrinkFileSize
  187. #define REPLACEATTRIBUTE_FILE_NUMBER (13) // $ReplaceAttribute
  188. #define REPLACEATTRIBUTE2_FILE_NUMBER (14) // $ReplaceAttribute2
  189. #define SETALLOCATIONINFO_FILE_NUMBER (15) // $SetAllocationInfo
  190. #define SETENDOFFILEINFO_FILE_NUMBER (16) // $SetEndOfFileInfo
  191. #define ZERORANGEINSTREAM_FILE_NUMBER (17) // $ZeroRangeInStream
  192. #define ZERORANGEINSTREAM2_FILE_NUMBER (18) // $ZeroRangeInStream2
  193. #define ZERORANGEINSTREAM3_FILE_NUMBER (19) // $ZeroRangeInStream3
  194. //
  195. // This is the empty string. This can be used to pass a string with
  196. // no length.
  197. //
  198. extern const UNICODE_STRING NtfsEmptyString;
  199. //
  200. // The following file references are used to identify system files.
  201. //
  202. extern const FILE_REFERENCE MftFileReference;
  203. extern const FILE_REFERENCE Mft2FileReference;
  204. extern const FILE_REFERENCE LogFileReference;
  205. extern const FILE_REFERENCE VolumeFileReference;
  206. extern const FILE_REFERENCE AttrDefFileReference;
  207. extern const FILE_REFERENCE RootIndexFileReference;
  208. extern const FILE_REFERENCE BitmapFileReference;
  209. extern const FILE_REFERENCE BootFileReference;
  210. extern const FILE_REFERENCE ExtendFileReference;
  211. extern const FILE_REFERENCE FirstUserFileReference;
  212. //
  213. // The number of attributes in the attribute definition table, including the end record
  214. //
  215. extern ULONG NtfsAttributeDefinitionsCount;
  216. //
  217. // The global structure used to contain our fast I/O callbacks
  218. //
  219. extern FAST_IO_DISPATCH NtfsFastIoDispatch;
  220. #ifdef BRIANDBG
  221. extern ULONG NtfsIgnoreReserved;
  222. #endif
  223. extern const UCHAR BaadSignature[4];
  224. extern const UCHAR IndexSignature[4];
  225. extern const UCHAR FileSignature[4];
  226. extern const UCHAR HoleSignature[4];
  227. extern const UCHAR ChkdskSignature[4];
  228. //
  229. // Reserved buffers needed.
  230. //
  231. // RESERVED_BUFFER_ONE_NEEDED - User only needs one buffer to complete request, any buffer will do.
  232. // RESERVED_BUFFER_TWO_NEEDED - User may need a second buffer after this one.
  233. // RESERVED_BUFFER_WORKSPACE_NEEDED - This is second buffer of two needed.
  234. //
  235. #define RESERVED_BUFFER_ONE_NEEDED (0x0)
  236. #define RESERVED_BUFFER_TWO_NEEDED (0x1)
  237. #define RESERVED_BUFFER_WORKSPACE_NEEDED (0x2)
  238. //
  239. // Large Reserved Buffer Context
  240. //
  241. extern ULONG NtfsReservedInUse;
  242. extern PVOID NtfsReserved1;
  243. extern PVOID NtfsReserved2;
  244. extern ULONG NtfsReserved2Count;
  245. extern PVOID NtfsReserved3;
  246. extern PVOID NtfsReserved1Thread;
  247. extern PVOID NtfsReserved2Thread;
  248. extern PVOID NtfsReserved3Thread;
  249. extern PFCB NtfsReserved12Fcb;
  250. extern PFCB NtfsReserved3Fcb;
  251. extern PVOID NtfsReservedBufferThread;
  252. extern BOOLEAN NtfsBufferAllocationFailure;
  253. extern FAST_MUTEX NtfsReservedBufferMutex;
  254. extern ERESOURCE NtfsReservedBufferResource;
  255. extern LARGE_INTEGER NtfsShortDelay;
  256. extern FAST_MUTEX NtfsScavengerLock;
  257. extern PIRP_CONTEXT NtfsScavengerWorkList;
  258. extern BOOLEAN NtfsScavengerRunning;
  259. extern ULONGLONG NtfsMaxQuotaNotifyRate;
  260. extern ULONG NtfsAsyncPostThreshold;
  261. #define LARGE_BUFFER_SIZE (0x10000)
  262. #ifdef _WIN64
  263. #define WORKSPACE_BUFFER_SIZE (LARGE_BUFFER_SIZE + PAGE_SIZE)
  264. #else
  265. #define WORKSPACE_BUFFER_SIZE (LARGE_BUFFER_SIZE)
  266. #endif
  267. extern UCHAR NtfsZeroExtendedInfo[48];
  268. #ifdef NTFS_RWC_DEBUG
  269. //
  270. // Range to include in COW checks.
  271. //
  272. extern LONGLONG NtfsRWCLowThreshold;
  273. extern LONGLONG NtfsRWCHighThreshold;
  274. #endif
  275. //
  276. // The following is the number of minutes for the last access increment
  277. //
  278. #define LAST_ACCESS_INCREMENT_MINUTES (60)
  279. //
  280. // Read ahead amount used for normal data files
  281. //
  282. #define READ_AHEAD_GRANULARITY (0x10000)
  283. //
  284. // Define maximum number of parallel Reads or Writes that will be generated
  285. // per one request.
  286. //
  287. #define NTFS_MAX_PARALLEL_IOS ((ULONG)8)
  288. //
  289. // Define a symbol which states the maximum number of runs that will be
  290. // added or deleted in one transaction per attribute. Note that the per-run
  291. // cost of deleting a run is 8-bytes in the BITMAP_RANGE, an average of
  292. // four bytes in the mapping array, and 16 bytes in the LCN_RANGE - for a total
  293. // of 28-bytes. Allocations do not log an LCN_RANGE, so their per-run cost is
  294. // 12 bytes. The worst problem is deleteing large fragmented files, where you
  295. // must add the cost of the rest of the log records for deleting all the attributes.
  296. //
  297. #define MAXIMUM_RUNS_AT_ONCE (128)
  298. //
  299. // Turn on pseudo-asserts if NTFS_FREE_ASSERTS is defined.
  300. //
  301. #if (!DBG && defined( NTFS_FREE_ASSERTS )) || defined( NTFSDBG )
  302. #undef ASSERT
  303. #undef ASSERTMSG
  304. #define ASSERT(exp) \
  305. ((exp) ? TRUE : \
  306. (DbgPrint( "%s:%d %s\n",__FILE__,__LINE__,#exp ), \
  307. DbgBreakPoint(), \
  308. TRUE))
  309. #define ASSERTMSG(msg,exp) \
  310. ((exp) ? TRUE : \
  311. (DbgPrint( "%s:%d %s %s\n",__FILE__,__LINE__,msg,#exp ), \
  312. DbgBreakPoint(), \
  313. TRUE))
  314. #endif
  315. #ifdef NTFS_LOG_FULL_TEST
  316. extern LONG NtfsFailCheck;
  317. extern LONG NtfsFailFrequency;
  318. extern LONG NtfsPeriodicFail;
  319. //
  320. // Perform log-file-full testing.
  321. //
  322. #define FailCheck(I,S) { \
  323. PIRP_CONTEXT FailTopContext = (I)->TopLevelIrpContext; \
  324. if (FailTopContext->NextFailCount != 0) { \
  325. if (--FailTopContext->CurrentFailCount == 0) { \
  326. FailTopContext->NextFailCount++; \
  327. FailTopContext->CurrentFailCount = FailTopContext->NextFailCount; \
  328. ExRaiseStatus( S ); \
  329. } \
  330. } \
  331. }
  332. #define LogFileFullFailCheck(I) FailCheck( I, STATUS_LOG_FILE_FULL )
  333. #endif
  334. //
  335. // The following debug macros are used in ntfs and defined in this module
  336. //
  337. // DebugTrace( Indent, Level, (DbgPrint list) );
  338. //
  339. // DebugUnwind( NonquotedString );
  340. //
  341. // DebugDoit( Statement );
  342. //
  343. // DbgDoit( Statement );
  344. //
  345. // The following assertion macros ensure that the indicated structure
  346. // is valid
  347. //
  348. // ASSERT_VCB( IN PVCB Vcb );
  349. // ASSERT_OPTIONAL_VCB( IN PVCB Vcb OPTIONAL );
  350. //
  351. // ASSERT_FCB( IN PFCB Fcb );
  352. // ASSERT_OPTIONAL_FCB( IN PFCB Fcb OPTIONAL );
  353. //
  354. // ASSERT_SCB( IN PSCB Scb );
  355. // ASSERT_OPTIONAL_SCB( IN PSCB Scb OPTIONAL );
  356. //
  357. // ASSERT_CCB( IN PSCB Ccb );
  358. // ASSERT_OPTIONAL_CCB( IN PSCB Ccb OPTIONAL );
  359. //
  360. // ASSERT_LCB( IN PLCB Lcb );
  361. // ASSERT_OPTIONAL_LCB( IN PLCB Lcb OPTIONAL );
  362. //
  363. // ASSERT_PREFIX_ENTRY( IN PPREFIX_ENTRY PrefixEntry );
  364. // ASSERT_OPTIONAL_PREFIX_ENTRY( IN PPREFIX_ENTRY PrefixEntry OPTIONAL );
  365. //
  366. // ASSERT_IRP_CONTEXT( IN PIRP_CONTEXT IrpContext );
  367. // ASSERT_OPTIONAL_IRP_CONTEXT( IN PIRP_CONTEXT IrpContext OPTIONAL );
  368. //
  369. // ASSERT_IRP( IN PIRP Irp );
  370. // ASSERT_OPTIONAL_IRP( IN PIRP Irp OPTIONAL );
  371. //
  372. // ASSERT_FILE_OBJECT( IN PFILE_OBJECT FileObject );
  373. // ASSERT_OPTIONAL_FILE_OBJECT( IN PFILE_OBJECT FileObject OPTIONAL );
  374. //
  375. // The following macros are used to check the current thread owns
  376. // the indicated resource
  377. //
  378. // ASSERT_EXCLUSIVE_RESOURCE( IN PERESOURCE Resource );
  379. //
  380. // ASSERT_SHARED_RESOURCE( IN PERESOURCE Resource );
  381. //
  382. // ASSERT_RESOURCE_NOT_MINE( IN PERESOURCE Resource );
  383. //
  384. // The following macros are used to check whether the current thread
  385. // owns the resoures in the given structures.
  386. //
  387. // ASSERT_EXCLUSIVE_FCB( IN PFCB Fcb );
  388. //
  389. // ASSERT_SHARED_FCB( IN PFCB Fcb );
  390. //
  391. // ASSERT_EXCLUSIVE_SCB( IN PSCB Scb );
  392. //
  393. // ASSERT_SHARED_SCB( IN PSCB Scb );
  394. //
  395. // The following macro is used to check that we are not trying to
  396. // manipulate an lcn that does not exist
  397. //
  398. // ASSERT_LCN_RANGE( IN PVCB Vcb, IN LCN Lcn );
  399. //
  400. #ifdef NTFSDBG
  401. extern LONG NtfsDebugTraceLevel;
  402. extern LONG NtfsDebugTraceIndent;
  403. extern LONG NtfsReturnStatusFilter;
  404. #define DEBUG_TRACE_ERROR (0x00000001)
  405. #define DEBUG_TRACE_QUOTA (0x00000002)
  406. #define DEBUG_TRACE_OBJIDSUP (0x00000002) // shared with Quota
  407. #define DEBUG_TRACE_CATCH_EXCEPTIONS (0x00000004)
  408. #define DEBUG_TRACE_UNWIND (0x00000008)
  409. #define DEBUG_TRACE_CLEANUP (0x00000010)
  410. #define DEBUG_TRACE_CLOSE (0x00000020)
  411. #define DEBUG_TRACE_CREATE (0x00000040)
  412. #define DEBUG_TRACE_DIRCTRL (0x00000080)
  413. #define DEBUG_TRACE_VIEWSUP (0x00000080) // shared with DirCtrl
  414. #define DEBUG_TRACE_EA (0x00000100)
  415. #define DEBUG_TRACE_PROP_FSCTL (0x00000100) // shared with EA
  416. #define DEBUG_TRACE_FILEINFO (0x00000200)
  417. #define DEBUG_TRACE_SEINFO (0x00000200) // shared with FileInfo
  418. #define DEBUG_TRACE_FSCTRL (0x00000400)
  419. #define DEBUG_TRACE_SHUTDOWN (0x00000400) // shared with FsCtrl
  420. #define DEBUG_TRACE_LOCKCTRL (0x00000800)
  421. #define DEBUG_TRACE_READ (0x00001000)
  422. #define DEBUG_TRACE_VOLINFO (0x00002000)
  423. #define DEBUG_TRACE_WRITE (0x00004000)
  424. #define DEBUG_TRACE_FLUSH (0x00008000)
  425. #define DEBUG_TRACE_DEVCTRL (0x00010000)
  426. #define DEBUG_TRACE_PNP (0x00010000) // shared with DevCtrl
  427. #define DEBUG_TRACE_LOGSUP (0x00020000)
  428. #define DEBUG_TRACE_BITMPSUP (0x00040000)
  429. #define DEBUG_TRACE_ALLOCSUP (0x00080000)
  430. #define DEBUG_TRACE_MFTSUP (0x00100000)
  431. #define DEBUG_TRACE_INDEXSUP (0x00200000)
  432. #define DEBUG_TRACE_ATTRSUP (0x00400000)
  433. #define DEBUG_TRACE_FILOBSUP (0x00800000)
  434. #define DEBUG_TRACE_NAMESUP (0x01000000)
  435. #define DEBUG_TRACE_SECURSUP (0x01000000) // shared with NameSup
  436. #define DEBUG_TRACE_VERFYSUP (0x02000000)
  437. #define DEBUG_TRACE_CACHESUP (0x04000000)
  438. #define DEBUG_TRACE_PREFXSUP (0x08000000)
  439. #define DEBUG_TRACE_HASHSUP (0x08000000) // shared with PrefxSup
  440. #define DEBUG_TRACE_DEVIOSUP (0x10000000)
  441. #define DEBUG_TRACE_STRUCSUP (0x20000000)
  442. #define DEBUG_TRACE_FSP_DISPATCHER (0x40000000)
  443. #define DEBUG_TRACE_ACLINDEX (0x80000000)
  444. __inline BOOLEAN
  445. NtfsDebugTracePre(LONG Indent, LONG Level)
  446. {
  447. if (Level == 0 || (NtfsDebugTraceLevel & Level) != 0) {
  448. DbgPrint( "%08lx:", PsGetCurrentThread( ));
  449. if (Indent < 0) {
  450. NtfsDebugTraceIndent += Indent;
  451. if (NtfsDebugTraceIndent < 0) {
  452. NtfsDebugTraceIndent = 0;
  453. }
  454. }
  455. DbgPrint( "%*s", NtfsDebugTraceIndent, "" );
  456. return TRUE;
  457. } else {
  458. return FALSE;
  459. }
  460. }
  461. __inline void
  462. NtfsDebugTracePost( LONG Indent )
  463. {
  464. if (Indent > 0) {
  465. NtfsDebugTraceIndent += Indent;
  466. }
  467. }
  468. #define DebugTrace(INDENT,LEVEL,M) { \
  469. if (NtfsDebugTracePre( (INDENT), (LEVEL))) { \
  470. DbgPrint M; \
  471. NtfsDebugTracePost( (INDENT) ); \
  472. } \
  473. }
  474. #define DebugUnwind(X) { \
  475. if (AbnormalTermination()) { \
  476. DebugTrace( 0, DEBUG_TRACE_UNWIND, (#X ", Abnormal termination.\n") ); \
  477. } \
  478. }
  479. #define DebugDoit(X) X
  480. #define DebugPrint(X) (DbgPrint X, TRUE)
  481. //
  482. // The following variables are used to keep track of the total amount
  483. // of requests processed by the file system, and the number of requests
  484. // that end up being processed by the Fsp thread. The first variable
  485. // is incremented whenever an Irp context is created (which is always
  486. // at the start of an Fsd entry point) and the second is incremented
  487. // by read request.
  488. //
  489. extern ULONG NtfsFsdEntryCount;
  490. extern ULONG NtfsFspEntryCount;
  491. extern ULONG NtfsIoCallDriverCount;
  492. #else
  493. #define DebugTrace(INDENT,LEVEL,M) {NOTHING;}
  494. #define DebugUnwind(X) {NOTHING;}
  495. #define DebugDoit(X) NOTHING
  496. #define DebugPrint(X) NOTHING
  497. #endif // NTFSDBG
  498. //
  499. // The following macro is for all people who compile with the DBG switch
  500. // set, not just NTFSDBG users
  501. //
  502. #ifdef NTFSDBG
  503. #define DbgDoit(X) {X;}
  504. #define ASSERT_VCB(V) { \
  505. ASSERT((NodeType(V) == NTFS_NTC_VCB)); \
  506. }
  507. #define ASSERT_OPTIONAL_VCB(V) { \
  508. ASSERT(((V) == NULL) || \
  509. (NodeType(V) == NTFS_NTC_VCB)); \
  510. }
  511. #define ASSERT_FCB(F) { \
  512. ASSERT((NodeType(F) == NTFS_NTC_FCB)); \
  513. }
  514. #define ASSERT_OPTIONAL_FCB(F) { \
  515. ASSERT(((F) == NULL) || \
  516. (NodeType(F) == NTFS_NTC_FCB)); \
  517. }
  518. #define ASSERT_SCB(S) { \
  519. ASSERT((NodeType(S) == NTFS_NTC_SCB_DATA) || \
  520. (NodeType(S) == NTFS_NTC_SCB_MFT) || \
  521. (NodeType(S) == NTFS_NTC_SCB_INDEX) || \
  522. (NodeType(S) == NTFS_NTC_SCB_ROOT_INDEX)); \
  523. }
  524. #define ASSERT_OPTIONAL_SCB(S) { \
  525. ASSERT(((S) == NULL) || \
  526. (NodeType(S) == NTFS_NTC_SCB_DATA) || \
  527. (NodeType(S) == NTFS_NTC_SCB_MFT) || \
  528. (NodeType(S) == NTFS_NTC_SCB_INDEX) || \
  529. (NodeType(S) == NTFS_NTC_SCB_ROOT_INDEX)); \
  530. }
  531. #define ASSERT_CCB(C) { \
  532. ASSERT((NodeType(C) == NTFS_NTC_CCB_DATA) || \
  533. (NodeType(C) == NTFS_NTC_CCB_INDEX)); \
  534. }
  535. #define ASSERT_OPTIONAL_CCB(C) { \
  536. ASSERT(((C) == NULL) || \
  537. ((NodeType(C) == NTFS_NTC_CCB_DATA) || \
  538. (NodeType(C) == NTFS_NTC_CCB_INDEX))); \
  539. }
  540. #define ASSERT_LCB(L) { \
  541. ASSERT((NodeType(L) == NTFS_NTC_LCB)); \
  542. }
  543. #define ASSERT_OPTIONAL_LCB(L) { \
  544. ASSERT(((L) == NULL) || \
  545. (NodeType(L) == NTFS_NTC_LCB)); \
  546. }
  547. #define ASSERT_PREFIX_ENTRY(P) { \
  548. ASSERT((NodeType(P) == NTFS_NTC_PREFIX_ENTRY)); \
  549. }
  550. #define ASSERT_OPTIONAL_PREFIX_ENTRY(P) { \
  551. ASSERT(((P) == NULL) || \
  552. (NodeType(P) == NTFS_NTC_PREFIX_ENTRY)); \
  553. }
  554. #define ASSERT_IRP_CONTEXT(I) { \
  555. ASSERT((NodeType(I) == NTFS_NTC_IRP_CONTEXT)); \
  556. }
  557. #define ASSERT_OPTIONAL_IRP_CONTEXT(I) { \
  558. ASSERT(((I) == NULL) || \
  559. (NodeType(I) == NTFS_NTC_IRP_CONTEXT)); \
  560. }
  561. #define ASSERT_IRP(I) { \
  562. ASSERT(((I)->Type == IO_TYPE_IRP)); \
  563. }
  564. #define ASSERT_OPTIONAL_IRP(I) { \
  565. ASSERT(((I) == NULL) || \
  566. ((I)->Type == IO_TYPE_IRP)); \
  567. }
  568. #define ASSERT_FILE_OBJECT(F) { \
  569. ASSERT(((F)->Type == IO_TYPE_FILE)); \
  570. }
  571. #define ASSERT_OPTIONAL_FILE_OBJECT(F) { \
  572. ASSERT(((F) == NULL) || \
  573. ((F)->Type == IO_TYPE_FILE)); \
  574. }
  575. #define ASSERT_EXCLUSIVE_RESOURCE(R) { \
  576. ASSERTMSG("ASSERT_EXCLUSIVE_RESOURCE ", ExIsResourceAcquiredExclusiveLite(R)); \
  577. }
  578. #define ASSERT_SHARED_RESOURCE(R) \
  579. ASSERTMSG( "ASSERT_RESOURCE_NOT_MINE ", ExIsResourceAcquiredSharedLite(R));
  580. #define ASSERT_RESOURCE_NOT_MINE(R) \
  581. ASSERTMSG( "ASSERT_RESOURCE_NOT_MINE ", !ExIsResourceAcquiredSharedLite(R));
  582. #define ASSERT_EXCLUSIVE_FCB(F) { \
  583. if (NtfsSegmentNumber( &(F)->FileReference ) \
  584. >= FIRST_USER_FILE_NUMBER) { \
  585. ASSERT_EXCLUSIVE_RESOURCE(F->Resource); \
  586. } \
  587. } \
  588. #define ASSERT_SHARED_FCB(F) { \
  589. if (NtfsSegmentNumber( &(F)->FileReference ) \
  590. >= FIRST_USER_FILE_NUMBER) { \
  591. ASSERT_SHARED_RESOURCE(F->Resource); \
  592. } \
  593. } \
  594. #define ASSERT_EXCLUSIVE_SCB(S) ASSERT_EXCLUSIVE_FCB(S->Fcb)
  595. #define ASSERT_SHARED_SCB(S) ASSERT_SHARED_FCB(S->Fcb)
  596. #define ASSERT_LCN_RANGE_CHECKING(V,L) { \
  597. ASSERTMSG("ASSERT_LCN_RANGE_CHECKING ", \
  598. ((V)->TotalClusters == 0) || ((L) <= (V)->TotalClusters)); \
  599. }
  600. #else
  601. #define DbgDoit(X) {NOTHING;}
  602. #define ASSERT_VCB(V) {DBG_UNREFERENCED_PARAMETER(V);}
  603. #define ASSERT_OPTIONAL_VCB(V) {DBG_UNREFERENCED_PARAMETER(V);}
  604. #define ASSERT_FCB(F) {DBG_UNREFERENCED_PARAMETER(F);}
  605. #define ASSERT_OPTIONAL_FCB(F) {DBG_UNREFERENCED_PARAMETER(F);}
  606. #define ASSERT_SCB(S) {DBG_UNREFERENCED_PARAMETER(S);}
  607. #define ASSERT_OPTIONAL_SCB(S) {DBG_UNREFERENCED_PARAMETER(S);}
  608. #define ASSERT_CCB(C) {DBG_UNREFERENCED_PARAMETER(C);}
  609. #define ASSERT_OPTIONAL_CCB(C) {DBG_UNREFERENCED_PARAMETER(C);}
  610. #define ASSERT_LCB(L) {DBG_UNREFERENCED_PARAMETER(L);}
  611. #define ASSERT_OPTIONAL_LCB(L) {DBG_UNREFERENCED_PARAMETER(L);}
  612. #define ASSERT_PREFIX_ENTRY(P) {DBG_UNREFERENCED_PARAMETER(P);}
  613. #define ASSERT_OPTIONAL_PREFIX_ENTRY(P) {DBG_UNREFERENCED_PARAMETER(P);}
  614. #define ASSERT_IRP_CONTEXT(I) {DBG_UNREFERENCED_PARAMETER(I);}
  615. #define ASSERT_OPTIONAL_IRP_CONTEXT(I) {DBG_UNREFERENCED_PARAMETER(I);}
  616. #define ASSERT_IRP(I) {DBG_UNREFERENCED_PARAMETER(I);}
  617. #define ASSERT_OPTIONAL_IRP(I) {DBG_UNREFERENCED_PARAMETER(I);}
  618. #define ASSERT_FILE_OBJECT(F) {DBG_UNREFERENCED_PARAMETER(F);}
  619. #define ASSERT_OPTIONAL_FILE_OBJECT(F) {DBG_UNREFERENCED_PARAMETER(F);}
  620. #define ASSERT_EXCLUSIVE_RESOURCE(R) {NOTHING;}
  621. #define ASSERT_SHARED_RESOURCE(R) {NOTHING;}
  622. #define ASSERT_RESOURCE_NOT_MINE(R) {NOTHING;}
  623. #define ASSERT_EXCLUSIVE_FCB(F) {NOTHING;}
  624. #define ASSERT_SHARED_FCB(F) {NOTHING;}
  625. #define ASSERT_EXCLUSIVE_SCB(S) {NOTHING;}
  626. #define ASSERT_SHARED_SCB(S) {NOTHING;}
  627. #define ASSERT_LCN_RANGE_CHECKING(V,L) {NOTHING;}
  628. #endif // DBG
  629. #endif // _NTFSDATA_