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.

5311 lines
145 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. NtfsStru.h
  5. Abstract:
  6. This module defines the data structures that make up the major
  7. internal part of the Ntfs file system.
  8. The global data structures start with the NtfsData record. It
  9. contains a pointer to a File System Device object, and a queue of
  10. Vcb's. There is a Vcb for every currently mounted volume. The
  11. Vcb's are allocated as the extension to a volume device object.
  12. +--------+
  13. |NtfsData| +--------+
  14. | | --> |FilSysDo|
  15. | | | |
  16. | | <+ +--------+
  17. +--------+ |
  18. |
  19. | +--------+ +--------+
  20. | |VolDo | |VolDo |
  21. | | | | |
  22. | +--------+ +--------+
  23. +> |Vcb | <-> |Vcb | <-> ...
  24. | | | |
  25. +--------+ +--------+
  26. The File System Device Object contains the global work queue for
  27. NTFS while each volume device object contains an overflow work queue.
  28. Each Vcb contains a table of all Fcbs for the volume indexed by their
  29. file reference (Called the FcbTable). And each Vcb contains a pointer
  30. a root Lcb for the volume. An Lcb is used to connect an indexed Scb
  31. (i.e., a directory) to an Fcb and give it a name.
  32. The following diagram shows the root structure.
  33. +--------+
  34. |Vcb |
  35. | | +---+ +--------+
  36. | | -|Lcb|-> |RootFcb |
  37. +--------+ |'\'| | |
  38. +---+ | |
  39. +--------+
  40. Each Scb will only have one parent Fcb but multiple Fcb children (each
  41. connected via an Lcb). An Fcb can have multiple Scb parents (via
  42. Lcbs) and multiple Scb Children.
  43. Now associated with each Fcb is potentially many Scbs. An Scb
  44. is allocated for each opened stream file object (i.e., an attribute
  45. that the file system is manipulating as a stream file). Each Scb
  46. contains a common fsrtl header and information necessary for doing
  47. I/O to the stream.
  48. +--------+
  49. |Fcb | +--------+ +--------+
  50. | | <-> |Scb | <-> |Scb | <-> ...
  51. +--------+ | | | |
  52. +--------+ +--------+
  53. In the following diagram we have two index scb (Scb1 and Scb2). The
  54. are two file opened under Scb1 both for the same File. The file was
  55. opened once with the name LcbA and another time with the name LcbB.
  56. Scb2 also has two opened file one is Fcb1 and named LcbC and the other
  57. is Fcb2 and named LcbD. Fcb1 has two opened Scbs under it (Scb3 and
  58. Scb4), and Fcb2 has one opened Scb underneath it (Scb5).
  59. +--------+ +--------+
  60. |Scb | |Scb |
  61. | 1 | | 2 |
  62. | | | |
  63. +--------+ +--------+
  64. | | | |
  65. Lcb Lcb Lcb Lcb
  66. A B C D
  67. | | +--------+ | | +--------+
  68. | +---> |Fcb | <---+ +---> |Fcb |
  69. | | 1 | | 2 |
  70. +--------> | | | |
  71. +--------+ +--------+
  72. ^ ^ ^ ^
  73. +------------+ +------------+ +----+ +----+
  74. | | | |
  75. | +--------+ +--------+ | | +--------+ |
  76. +> |Scb | <--> |Scb | <+ +> |Scb | <+
  77. | 3 | | 4 | | 5 |
  78. | | | | | |
  79. +--------+ +--------+ +--------+
  80. In addition off of each Lcb is a list of Ccb and Prefix entries. The
  81. Ccb list is for each ccb that has opened that File (fcb) via the name.
  82. The Prefix list contains the prefix table entries that we are caching.
  83. The NtfsData, all Vcbs, and the paging file Fcb, and all Scbs are
  84. allocated out of nonpaged pool. The Fcbs are allocated out of paged
  85. pool.
  86. The resources protecting the NTFS memory structures are setup as
  87. follows:
  88. 1. There is a global resource in the NtfsData record. This resource
  89. protects the NtfsData record which includes any changes to its
  90. Vcb queue.
  91. 2. There is a resource per Vcb. This resource pretects the Vcb record
  92. which includes adding and removing Fcbs, and Scbs
  93. 3. There is a single resource protecting an Fcb and its assigned
  94. Scbs. This resource protects any changes to the Fcb, and Scb
  95. records. The way this one works is that each Fcb, and Scb point
  96. to the resource. The Scb also contain back pointers to their
  97. parent Fcb but we cannot use this pointer to get the resource
  98. because the Fcb might be in nonpaged pool.
  99. +--------+
  100. |Fcb | +--------+ +--------+
  101. | | <-> |Scb | <-> |Scb | <-> ...
  102. +--------+ | | | |
  103. +--------+ +--------+
  104. |
  105. | | |
  106. | v |
  107. | |
  108. | +--------+ |
  109. +-----> |Resource| <-----+
  110. | |
  111. +--------+
  112. There are several types of opens possible for each file object handled by
  113. NTFS. They are UserFileOpen, UserDirectoryOpen, UserVolumeOpen, StreamFileOpen,
  114. UserViewIndexOpen, and UserProperytSetOpen. The first three types correspond
  115. to user opens on files, directories, and dasd respectively. UserViewIndexOpen
  116. indicates that a user mode application has opened a view index stream such
  117. as the quota or object id index. The last type of open is for any file object
  118. created by NTFS for its stream I/O (e.g., the volume bitmap). The file system
  119. uses the FsContext and FsContext2 fields of the file object to store the
  120. fcb/scb/ccb associated with the file object.
  121. Type of open FsContext FsContext2
  122. ------------ --------- ----------
  123. UserFileOpen Pointer to Scb Pointer to Ccb
  124. UserDirectoryOpen Pointer to Scb Pointer to Ccb
  125. UserVolumeOpen Pointer to Scb Pointer to Ccb
  126. StreamFileOpen Pointer to Scb null
  127. The only part of the NTFS code that actually needs to know this
  128. information is in FilObSup.c. But we talk about it here to help
  129. developers debug the system.
  130. To mount a new NTFS volume requires a bit of juggling. The idea is
  131. to have as little setup in memory as necessary to recoginize the
  132. volume, call a restart routine that will recover the volume, and then
  133. precede with the mounting. To aid in this the regular directory
  134. structures of the Fcb is bypassed. In its place we have a linked list
  135. of Fcbs off of the Vcb. This is done because during recovery we do
  136. not know where an Fcb belongs in the directory hierarchy. So at
  137. restart time all new fcbs get put in this prerestart Fcb list. Then
  138. after restart whenever we create a new Fcb we search this list for a
  139. match (on file reference). If we find one we remove the fcb from this
  140. list and move it to the proper place in the directory hierarchy tree
  141. (fcb tree).
  142. Author:
  143. Brian Andrew [BrianAn] 21-May-1991
  144. David Goebel [DavidGoe]
  145. Gary Kimura [GaryKi]
  146. Tom Miller [TomM]
  147. Revision History:
  148. --*/
  149. #ifndef _NTFSSTRU_
  150. #define _NTFSSTRU_
  151. //
  152. // Forward typedefs
  153. //
  154. typedef struct _SCB *PSCB;
  155. typedef PVOID PBCB; //**** Bcb's are now part of the cache module
  156. typedef enum _NTFS_OWNERSHIP_STATE NTFS_OWNERSHIP_STATE;
  157. typedef enum _NTFS_RESOURCE_NAME NTFS_RESOURCE_NAME;
  158. //
  159. // Define how many freed structures we are willing to keep around
  160. //
  161. #define FREE_FCB_TABLE_SIZE (8)
  162. #define MAX_DELAYED_CLOSE_COUNT (0x10)
  163. #define ASYNC_CLOSE_POST_THRESHOLD (500)
  164. #define INITIAL_DIRTY_TABLE_HINT (0x20)
  165. //
  166. // Checkpoint activity status. There are used to control number of outstanding
  167. // checkpoints. We only want one to be posted at a time so they don't swallow
  168. // up the worker threads in case the current checkpoint is not completed before
  169. // the checkpoint timer fires.
  170. //
  171. #define CHECKPOINT_POSTED (0x00000001)
  172. #define CHECKPOINT_PENDING (0x00000002)
  173. //
  174. // Timer status types. These are used in NtfsSetDirtyBcb synchronization with
  175. // checkpoint-all-volumes activity.
  176. //
  177. typedef enum TIMER_STATUS {
  178. TIMER_SET = 0,
  179. TIMER_NOT_SET = 1,
  180. } TIMER_STATUS;
  181. //
  182. // The NTFS_DATA record is the top record in the NTFS file system
  183. // in-memory data structure. This structure must be allocated from
  184. // non-paged pool.
  185. //
  186. typedef struct _NTFS_DATA {
  187. //
  188. // The type and size of this record (must be NTFS_NTC_DATA_HEADER)
  189. //
  190. NODE_TYPE_CODE NodeTypeCode;
  191. NODE_BYTE_SIZE NodeByteSize;
  192. //
  193. // A pointer to the Driver object we were initialized with
  194. //
  195. PDRIVER_OBJECT DriverObject;
  196. //
  197. // A queue of all the devices that are mounted by the file system.
  198. // Corresponds to the field Vcb->VcbLinks;
  199. //
  200. LIST_ENTRY VcbQueue;
  201. //
  202. // A resource variable to control access to the global NTFS data
  203. // record
  204. //
  205. ERESOURCE Resource;
  206. //
  207. // The following list entry is used for performing closes that can't
  208. // be done in the context of the original caller.
  209. //
  210. LIST_ENTRY AsyncCloseList;
  211. BOOLEAN AsyncCloseActive;
  212. BOOLEAN ReduceDelayedClose;
  213. ULONG AsyncCloseCount;
  214. //
  215. // A pointer to our EPROCESS struct, which is a required input to the
  216. // Cache Management subsystem.
  217. //
  218. PEPROCESS OurProcess;
  219. //
  220. // The following fields describe the deferred close file objects.
  221. //
  222. ULONG DelayedCloseCount;
  223. LIST_ENTRY DelayedCloseList;
  224. //
  225. // This is the ExWorkerItem that does both kinds of deferred closes.
  226. //
  227. WORK_QUEUE_ITEM NtfsCloseItem;
  228. UCHAR FreeFcbTableSize;
  229. UCHAR UnusedUchar[3];
  230. PVOID *FreeFcbTableArray[ FREE_FCB_TABLE_SIZE ];
  231. //
  232. // Free arrays are dynamically sized
  233. //
  234. ULONG FreeEresourceSize;
  235. ULONG FreeEresourceTotal;
  236. ULONG FreeEresourceMiss;
  237. PERESOURCE *FreeEresourceArray;
  238. //
  239. // Cache manager call back structures, which must be passed on each
  240. // call to CcInitializeCacheMap.
  241. //
  242. CACHE_MANAGER_CALLBACKS CacheManagerCallbacks;
  243. CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks;
  244. //
  245. // The following fields are used for the CheckpointVolumes()
  246. // callback.
  247. //
  248. KDPC VolumeCheckpointDpc;
  249. KTIMER VolumeCheckpointTimer;
  250. ULONG VolumeCheckpointStatus;
  251. WORK_QUEUE_ITEM VolumeCheckpointItem;
  252. TIMER_STATUS TimerStatus;
  253. KDPC UsnTimeOutDpc;
  254. KTIMER UsnTimeOutTimer;
  255. WORK_QUEUE_ITEM UsnTimeOutItem;
  256. //
  257. // Flags. These are the flags for the volume.
  258. //
  259. USHORT Flags;
  260. //
  261. // This is a list of all of the threads currently doing read ahead.
  262. // We will not hot fix for these threads.
  263. //
  264. LIST_ENTRY ReadAheadThreads;
  265. //
  266. // The following table of unicode values is the case mapping, with
  267. // the size in number of Unicode characters. We keep a global copy
  268. // and let each Vcb use this copy if the upcase table for the volume
  269. // matches.
  270. //
  271. PWCH UpcaseTable;
  272. ULONG UpcaseTableSize;
  273. //
  274. // Pointer to a default security descriptor.
  275. //
  276. PSECURITY_DESCRIPTOR DefaultDescriptor;
  277. ULONG DefaultDescriptorLength;
  278. //
  279. // Mutex to serialize internal NtfsData structures.
  280. //
  281. FAST_MUTEX NtfsDataLock;
  282. //
  283. // Service and callback table for encryption.
  284. //
  285. ENCRYPTION_CALL_BACK EncryptionCallBackTable;
  286. //
  287. // Useful information when debugging dismount memory leakage, etc.
  288. //
  289. #ifdef DISMOUNT_DBG
  290. ULONG DismountCount;
  291. #endif
  292. ULONG VolumeNameLookupsInProgress;
  293. } NTFS_DATA;
  294. typedef NTFS_DATA *PNTFS_DATA;
  295. #define NTFS_FLAGS_SMALL_SYSTEM (0x0001)
  296. #define NTFS_FLAGS_MEDIUM_SYSTEM (0x0002)
  297. #define NTFS_FLAGS_LARGE_SYSTEM (0x0004)
  298. #define NTFS_FLAGS_CREATE_8DOT3_NAMES (0X0010)
  299. #define NTFS_FLAGS_ALLOW_EXTENDED_CHAR (0x0020)
  300. #define NTFS_FLAGS_DISABLE_LAST_ACCESS (0x0040)
  301. #define NTFS_FLAGS_ENCRYPTION_DRIVER (0x0080)
  302. #define NTFS_FLAGS_DISABLE_UPGRADE (0x0100)
  303. #define NTFS_FLAGS_PERSONAL (0x0200)
  304. //
  305. // The record allocation context structure is used by the routines that
  306. // allocate and deallocate records based on a bitmap (for example the mft
  307. // bitmap or the index bitmap). The context structure needs to be
  308. // defined here because the mft bitmap context is declared as part of the
  309. // vcb.
  310. //
  311. typedef struct _RECORD_ALLOCATION_CONTEXT {
  312. //
  313. // The following field is a pointer to the scb for the data part of
  314. // the file that this bitmap controls. For example, it is a pointer
  315. // to the data attribute for the MFT.
  316. //
  317. // NOTE !!!! The Data Scb must remain the first entry in this
  318. // structure. If we need to uninitialize and reinitialize this
  319. // structure in the running system we don't want to touch this field.
  320. //
  321. // NOTE !!!! The code that clears the record allocation context
  322. // expects the BitmapScb field to follow the Data Scb field.
  323. //
  324. PSCB DataScb;
  325. //
  326. // The following field is used to indicate if the bitmap attribute is
  327. // in a resident form or a nonresident form. If the bitmap is in a
  328. // resident form then the pointer is null, and whenever a bitmap
  329. // routine is called it must also be passed an attribute enumeration
  330. // context to be able to read the bitmap. If the field is not null
  331. // then it points to the scb for the non resident bitmap attribute
  332. //
  333. PSCB BitmapScb;
  334. //
  335. // The following two fields describe the current size of the bitmap
  336. // (in bits) and the number of free bits currently in the bitmap.
  337. // A value of MAXULONG in the CurrentBitmapSize indicates that we
  338. // need to reinitialize the record context structure.
  339. //
  340. ULONG CurrentBitmapSize;
  341. ULONG NumberOfFreeBits;
  342. //
  343. // The following field contains the index of last bit that we know
  344. // to be set. This is used for truncation purposes.
  345. //
  346. LONG IndexOfLastSetBit;
  347. //
  348. // The following three fields are used to indicate the allocation
  349. // size for the bitmap (i.e., each bit in the bitmap represents how
  350. // many bytes in the data attribute). Also it indicates the
  351. // granularity with which we will either extend or shrink the bitmap.
  352. //
  353. ULONG BytesPerRecord;
  354. ULONG ExtendGranularity;
  355. ULONG TruncateGranularity;
  356. //
  357. // Scanning a large bitmap can be inefficient. Use the following fields
  358. // to quickly locate a likely starting position.
  359. //
  360. ULONG StartingHint;
  361. ULONG LowestDeallocatedIndex;
  362. } RECORD_ALLOCATION_CONTEXT;
  363. typedef RECORD_ALLOCATION_CONTEXT *PRECORD_ALLOCATION_CONTEXT;
  364. //
  365. // The Vcb (Volume control Block) record corresponds to every volume
  366. // mounted by the file system. They are ordered in a queue off of
  367. // NtfsData.VcbQueue. This structure must be allocated from non-paged
  368. // pool
  369. //
  370. #define DEFAULT_ATTRIBUTE_TABLE_SIZE (32)
  371. #define DEFAULT_TRANSACTION_TABLE_SIZE (32)
  372. #define DEFAULT_DIRTY_PAGES_TABLE_SIZE (64)
  373. //
  374. // The Restart Pointers structure is the actual structure supported by
  375. // routines and macros to get at a Restart Table. This structure is
  376. // required since the restart table itself may move, so one must first
  377. // acquire the resource to synchronize, then follow the pointer to the
  378. // table.
  379. //
  380. typedef struct _RESTART_POINTERS {
  381. //
  382. // Resource to synchronize with table moves. This resource must
  383. // be held shared while dealing with pointers to table entries,
  384. // and exclusive to move the table.
  385. //
  386. ERESOURCE Resource;
  387. //
  388. // Pointer to the actual Restart Table.
  389. //
  390. struct _RESTART_TABLE *Table;
  391. //
  392. // Spin Lock synchronizing allocates and deletes of entries in the
  393. // table. The resource must be held at least shared.
  394. //
  395. KSPIN_LOCK SpinLock;
  396. //
  397. // Remember if the resource was initialized.
  398. //
  399. BOOLEAN ResourceInitialized;
  400. //
  401. // Are we waiting for the table to empty - currently only used in the
  402. // transaction table - the event used with it is in the Vcb->NoTransactionsEvent
  403. // if all the tables need this capability it should move directly into the
  404. // restart ptrs
  405. //
  406. BOOLEAN DrainPending;
  407. //
  408. // For quad & cache line alignment
  409. //
  410. UCHAR Unused[6];
  411. } RESTART_POINTERS, *PRESTART_POINTERS;
  412. #define NtfsInitializeRestartPointers(P) { \
  413. RtlZeroMemory( (P), sizeof(RESTART_POINTERS) ); \
  414. KeInitializeSpinLock( &(P)->SpinLock ); \
  415. ExInitializeResourceLite( &(P)->Resource ); \
  416. (P)->ResourceInitialized = TRUE; \
  417. }
  418. //
  419. // Our Advanced FCB common header which includes all the normal fields +
  420. // the NTFS specific pending eof advances, compressed fileobject and
  421. // section object ptrs. This used to all be in the FSRTL_ADVANCED_FCB_HEADER
  422. //
  423. #ifdef __cplusplus
  424. typedef struct _NTFS_ADVANCED_FCB_HEADER:FSRTL_ADVANCED_FCB_HEADER {
  425. #else // __cplusplus
  426. typedef struct _NTFS_ADVANCED_FCB_HEADER {
  427. //
  428. // Put in the standard FsRtl header fields
  429. //
  430. FSRTL_ADVANCED_FCB_HEADER ;
  431. #endif // __cplusplus
  432. //
  433. // This is a pointer to a list head which may be used to queue
  434. // up advances to EOF (end of file), via calls to the appropriate
  435. // FsRtl routines. This listhead may be paged.
  436. //
  437. PLIST_ENTRY PendingEofAdvances;
  438. //
  439. // When FSRTL_FLAG_ADVANCED_HEADER is set, the following fields
  440. // are present in the header. If the compressed stream has not
  441. // been initialized, all of the following fields will be NULL.
  442. //
  443. #ifdef COMPRESS_ON_WIRE
  444. //
  445. // This is the FileObect for the stream in which data is cached
  446. // in its compressed form.
  447. //
  448. PFILE_OBJECT FileObjectC;
  449. #endif
  450. } NTFS_ADVANCED_FCB_HEADER, *PNTFS_ADVANCED_FCB_HEADER;
  451. //
  452. // The NTFS MCB structure is a super set of the FsRtl Large Mcb package
  453. //
  454. // This structure is ideally aligned on an odd quadword (address ends in 8).
  455. //
  456. typedef struct _NTFS_MCB_ENTRY {
  457. LIST_ENTRY LruLinks;
  458. struct _NTFS_MCB *NtfsMcb;
  459. struct _NTFS_MCB_ARRAY *NtfsMcbArray;
  460. LARGE_MCB LargeMcb;
  461. } NTFS_MCB_ENTRY;
  462. typedef NTFS_MCB_ENTRY *PNTFS_MCB_ENTRY;
  463. typedef struct _NTFS_MCB_ARRAY {
  464. VCN StartingVcn;
  465. VCN EndingVcn;
  466. PNTFS_MCB_ENTRY NtfsMcbEntry;
  467. PVOID Unused;
  468. } NTFS_MCB_ARRAY;
  469. typedef NTFS_MCB_ARRAY *PNTFS_MCB_ARRAY;
  470. typedef struct _NTFS_MCB {
  471. PNTFS_ADVANCED_FCB_HEADER FcbHeader;
  472. POOL_TYPE PoolType;
  473. ULONG NtfsMcbArraySizeInUse;
  474. ULONG NtfsMcbArraySize;
  475. PNTFS_MCB_ARRAY NtfsMcbArray;
  476. PFAST_MUTEX FastMutex;
  477. } NTFS_MCB;
  478. typedef NTFS_MCB *PNTFS_MCB;
  479. //
  480. // Define some additional Ntfs Mcb structures to accomodate small to
  481. // medium files with fewer pool allocations. This space will be
  482. // unused for large files (more than three ranges).
  483. //
  484. #define MCB_ARRAY_PHASE1_SIZE 1
  485. #define MCB_ARRAY_PHASE2_SIZE 3
  486. typedef union {
  487. //
  488. // For the first phase, embed one array element and its Mcb entry.
  489. //
  490. struct {
  491. NTFS_MCB_ARRAY SingleMcbArrayEntry;
  492. NTFS_MCB_ENTRY McbEntry;
  493. } Phase1;
  494. //
  495. // For the second phase, we can at least store three entries in
  496. // the Mcb Array.
  497. //
  498. struct {
  499. NTFS_MCB_ARRAY ThreeMcbArrayEntries[MCB_ARRAY_PHASE2_SIZE];
  500. } Phase2;
  501. } NTFS_MCB_INITIAL_STRUCTS;
  502. typedef NTFS_MCB_INITIAL_STRUCTS *PNTFS_MCB_INITIAL_STRUCTS;
  503. //
  504. // Structure used to track the deallocated clusters.
  505. //
  506. //
  507. // How many pairs maximum we want stored in an mcb before starting a new one
  508. //
  509. #define NTFS_DEALLOCATED_MCB_LIMIT (PAGE_SIZE / sizeof( LONGLONG ))
  510. typedef struct _DEALLOCATED_CLUSTERS {
  511. LIST_ENTRY Link;
  512. LARGE_MCB Mcb;
  513. LSN Lsn;
  514. LONGLONG ClusterCount;
  515. } DEALLOCATED_CLUSTERS, *PDEALLOCATED_CLUSTERS;
  516. //
  517. // The Ntfs ReservedBitmapRange is used to describe the reserved
  518. // clusters in a range of the file. This data structure comes in
  519. // several forms.
  520. //
  521. // The basic unit is an RtlBitmap and bitmap embedded
  522. // in a single pool block. The entire structure is reallocated
  523. // as it grows past its current size. This is meant to handle
  524. // small files.
  525. //
  526. // As the file gets larger we will allocate a fixed size block
  527. // which descibes a set range in the file.
  528. //
  529. // As the file continues to grow then we will link fixed size
  530. // ranges together. Only the ranges being accessed will need a
  531. // bitmap. We will only allocate the needed space for the
  532. // bitmap.
  533. //
  534. //
  535. // RANGE_SIZE - number of compression units per range.
  536. // RANGE_SHIFT - shift value to convert from compression unit to range.
  537. //
  538. #define NTFS_BITMAP_RANGE_SIZE (0x2000)
  539. #define NTFS_BITMAP_RANGE_MASK (NTFS_BITMAP_RANGE_SIZE - 1)
  540. #define NTFS_BITMAP_RANGE_SHIFT (13)
  541. #define NTFS_BITMAP_MAX_BASIC_SIZE (NTFS_BITMAP_RANGE_SIZE - ((sizeof( RTL_BITMAP ) + sizeof( LIST_ENTRY )) * 8))
  542. //
  543. // Grow the basic bitmap in full pool blocks so we don't constantly reallocate
  544. // as the bitmap grows. Add the requested bits (converted to bytes) to
  545. // the pool header and the header of the bitmap
  546. //
  547. #define NtfsBasicBitmapSize(Size) ( \
  548. ((((Size + 7) / 8) + 8 + sizeof( LIST_ENTRY ) + sizeof( RTL_BITMAP ) + 0x20 - 1) & ~(0x20 - 1)) -8 \
  549. )
  550. #define NtfsBitmapSize(Size) ( \
  551. ((((Size + 7) / 8) + 8 + 0x20 - 1) & ~(0x20 - 1)) - 8 \
  552. )
  553. typedef struct _RESERVED_BITMAP_RANGE {
  554. //
  555. // Overload the first field. The Flink field is NULL if we are using
  556. // the basic structure. The Blink field will be the count of dirty
  557. // bits for the basic case. Keeping track of the dirty bits will allow
  558. // us to cut off the scan if there are no dirty bits.
  559. //
  560. union {
  561. //
  562. // Links for the separate ranges. A NULL in the Flink
  563. // field indicates that this the basic unit and the
  564. // bitmap is integrated into the structure.
  565. //
  566. LIST_ENTRY Links;
  567. struct {
  568. ULONG_PTR Flink;
  569. USHORT BasicDirtyBits;
  570. USHORT BasicUnused;
  571. };
  572. };
  573. //
  574. // Bitmap structure for this range.
  575. //
  576. RTL_BITMAP Bitmap;
  577. //
  578. // The following fields are only valid if this is not
  579. // the basic structure. In the basic structure the
  580. // buffer for the bitmap will begin at the following
  581. // location.
  582. //
  583. //
  584. // Range offset. The size of the bitmap range is
  585. // determined by the range shift and mask values above.
  586. // Each range will describe a certain number of compression
  587. // units. The range offset is the position of this range
  588. // in the file.
  589. //
  590. ULONG RangeOffset;
  591. //
  592. // Number of dirty bits. A zero value indicates that this
  593. // range can be reused.
  594. //
  595. USHORT DirtyBits;
  596. //
  597. // Unused at this point.
  598. //
  599. USHORT Unused;
  600. } RESERVED_BITMAP_RANGE, *PRESERVED_BITMAP_RANGE;
  601. //
  602. // Following structure is embedded in the Vcb to control the Usn delete operation.
  603. //
  604. typedef struct _NTFS_DELETE_JOURNAL_DATA {
  605. FILE_REFERENCE DeleteUsnFileReference;
  606. PSCB PriorJournalScb;
  607. ULONG DeleteState;
  608. NTSTATUS FinalStatus;
  609. } NTFS_DELETE_JOURNAL_DATA, *PNTFS_DELETE_JOURNAL_DATA;
  610. #define DELETE_USN_RESET_MFT (0x00000001)
  611. #define DELETE_USN_REMOVE_JOURNAL (0x00000002)
  612. #define DELETE_USN_FINAL_CLEANUP (0x00000004)
  613. //
  614. // Local structures to manage the cached free clusters.
  615. //
  616. #define NTFS_INITIAL_CACHED_RUNS (0x20)
  617. #define NTFS_MAX_CACHED_RUNS_DELTA (0x200)
  618. //
  619. // Define the maximum run index
  620. //
  621. #define NTFS_CACHED_RUNS_MAX_INDEX (MAXSHORT)
  622. //
  623. // Define a run index that will be used to identify an entry whose
  624. // corresponding entry in the other sorted list no longer refers
  625. // to it. This is used when an entry is deleted from one sorted
  626. // list and hasn't yet been removed from the other.
  627. //
  628. #define NTFS_CACHED_RUNS_DEL_INDEX (MAXUSHORT)
  629. //
  630. // Define the number of bins of run lengths to keep track of.
  631. //
  632. #define NTFS_CACHED_RUNS_BIN_COUNT (32)
  633. //
  634. // Define the number of windows of deleted entries to keep track of for
  635. // each sort table.
  636. //
  637. #define NTFS_CACHED_RUNS_MAX_DEL_WINDOWS (64)
  638. typedef struct _NTFS_LCN_CLUSTER_RUN {
  639. //
  640. // The cluster number where the free run begins
  641. //
  642. LCN Lcn;
  643. //
  644. // The number of clusters in the free run starting at Lcn.
  645. //
  646. LONGLONG RunLength;
  647. //
  648. // This is the index of the corresponding entry in the length-sorted list
  649. //
  650. USHORT LengthIndex;
  651. //
  652. // Pad the structure out to 64-bit alignment
  653. //
  654. USHORT Pad0;
  655. ULONG Pad1;
  656. } NTFS_LCN_CLUSTER_RUN, *PNTFS_LCN_CLUSTER_RUN;
  657. typedef struct _NTFS_DELETED_RUNS {
  658. //
  659. // The starting and ending indices of a window of cached runs that have
  660. // been deleted. These are indices into the Lcn-sorted or length-sorted
  661. // arrays.
  662. //
  663. USHORT StartIndex;
  664. USHORT EndIndex;
  665. } NTFS_DELETED_RUNS, *PNTFS_DELETED_RUNS;
  666. typedef struct _NTFS_CACHED_RUNS {
  667. //
  668. // Pointer to the array of free runs sorted by Lcn
  669. //
  670. PNTFS_LCN_CLUSTER_RUN LcnArray;
  671. //
  672. // Pointer to an array of indices of the Lcn-sorted array
  673. // above, sorted by RunLength, and sub-sorted by Lcn.
  674. //
  675. PUSHORT LengthArray;
  676. //
  677. // Pointer to an array of bins. Each bin contains the number of
  678. // entries in LengthArray of a given run length. BinArray[0] contains
  679. // the count of entries with run length 1. BinArray[1] contains run
  680. // length 2, and so on.
  681. //
  682. // This array is used to keep track of how many small free runs are
  683. // cached so that we keep a sufficient number of them around.
  684. //
  685. PUSHORT BinArray;
  686. //
  687. // An array of windows of cached runs in LcnArray that have been
  688. // deleted.
  689. //
  690. PNTFS_DELETED_RUNS DeletedLcnWindows;
  691. //
  692. // An array of windows of cached runs in LengthArray that have been
  693. // deleted.
  694. //
  695. PNTFS_DELETED_RUNS DeletedLengthWindows;
  696. //
  697. // The longest freed run so far.
  698. //
  699. LONGLONG LongestFreedRun;
  700. //
  701. // The maximum number of entries to which LcnArray should grow. The same
  702. // limit applies to LengthArray.
  703. //
  704. USHORT MaximumSize;
  705. //
  706. // The desired number of small length free runs to keep cached for
  707. // each size.
  708. //
  709. USHORT MinCount;
  710. //
  711. // The allocated number of entries in LcnArray. The same number are
  712. // available in LengthArray.
  713. //
  714. USHORT Avail;
  715. //
  716. // The number of entries used in LcnArray. The same number are used
  717. // in LengthArray.
  718. //
  719. USHORT Used;
  720. //
  721. // The number of entries in DeletedLcnWindows.
  722. //
  723. USHORT DelLcnCount;
  724. //
  725. // The number of entries in DeletedLengthWindows.
  726. //
  727. USHORT DelLengthCount;
  728. //
  729. // The number of entries in BinArray.
  730. //
  731. USHORT Bins;
  732. #ifdef NTFS_CHECK_CACHED_RUNS
  733. struct _VCB *Vcb;
  734. #endif
  735. } NTFS_CACHED_RUNS, *PNTFS_CACHED_RUNS;
  736. //
  737. // The following structures are used for the filename hash table.
  738. //
  739. //
  740. // Constants controlling the total number of buckets
  741. //
  742. #define HASH_MAX_SEGMENT_COUNT (32)
  743. #define HASH_SEGMENT_SHIFT (5)
  744. #define HASH_MAX_INDEX_COUNT (1024)
  745. #define HASH_INDEX_SHIFT (10)
  746. #define HASH_MAX_BUCKET_COUNT (HASH_MAX_SEGMENT_COUNT * HASH_MAX_INDEX_COUNT)
  747. //
  748. // This is the basic structure for a hash entry. A hash entry is described by the
  749. // the hash value computed from a full path name. We will only store hash entries
  750. // for files without DOS-only components.
  751. //
  752. // We will only allow one entry in the table for each (Lcb, string length, hash value)
  753. // triplet. We don't want to store the full string in the table for each entry.
  754. // After a lookup it will be up to the caller to verify the string.
  755. //
  756. // We keep a loose coherency between the hash table and the Lcb. The hash table
  757. // points definitively back to an Lcb but the Lcb only suggests that there is an
  758. // entry in the table. This way if we remove an entry from the table we won't
  759. // have to track down the Lcb.
  760. //
  761. typedef struct _NTFS_HASH_ENTRY {
  762. //
  763. // Pointer to the next entry in the same bucket. Note that the chain
  764. // of entries in the same bucket don't all have the hash value.
  765. //
  766. struct _NTFS_HASH_ENTRY *NextEntry;
  767. //
  768. // The entry is described by the hash value, filename length and the Lcb for the
  769. // last component.
  770. //
  771. struct _LCB *HashLcb;
  772. ULONG HashValue;
  773. ULONG FullNameLength;
  774. } NTFS_HASH_ENTRY, *PNTFS_HASH_ENTRY;
  775. //
  776. // The hash segments consists of an array of hash entry pointers.
  777. //
  778. typedef PNTFS_HASH_ENTRY NTFS_HASH_SEGMENT[ HASH_MAX_INDEX_COUNT ];
  779. typedef NTFS_HASH_SEGMENT *PNTFS_HASH_SEGMENT;
  780. //
  781. // The basic table consists of an array of segments. Each segment contains a fixed
  782. // number of buckets. Once the initial segment has buckets which are deeper than
  783. // our max optimal depth then we will double the number of segments and split the
  784. // existing entries across the new segments. The process of splitting is done bucket
  785. // by bucket until we reach the new size. During this process we need to keep track
  786. // of whether the new entry belongs to a bucket which has already been split.
  787. //
  788. //
  789. // Table state value
  790. //
  791. #define TABLE_STATE_STABLE (0x00000000)
  792. #define TABLE_STATE_EXPANDING (0x00000001)
  793. #define TABLE_STATE_REDUCING (0x00000002)
  794. typedef struct _NTFS_HASH_TABLE {
  795. //
  796. // Max bucket is always 2^n. When we grow the table we double the number of buckets
  797. // but need to split the existing buckets to find which entries should be moved
  798. // to the expanded region. The SplitPoint is our current position to do this
  799. // work.
  800. //
  801. ULONG MaxBucket;
  802. ULONG SplitPoint;
  803. ULONG TableState;
  804. #ifdef NTFS_HASH_DATA
  805. ULONG HashLookupCount;
  806. ULONG SkipHashLookupCount;
  807. ULONG FileMatchCount;
  808. ULONG ParentMatchCount;
  809. ULONG CreateNewFileInsert;
  810. ULONG OpenFileInsert;
  811. ULONG OpenExistingInsert;
  812. ULONG ParentInsert;
  813. ULONG OpenFileConflict;
  814. ULONG OpenExistingConflict;
  815. ULONG ParentConflict;
  816. ULONG CreateScbFails;
  817. ULONG CreateLcbFails;
  818. ULONG Histogram[16];
  819. ULONG ExtendedHistogram[16];
  820. #endif
  821. PNTFS_HASH_SEGMENT HashSegments[ HASH_MAX_SEGMENT_COUNT ];
  822. } NTFS_HASH_TABLE, *PNTFS_HASH_TABLE;
  823. //
  824. // Scrambling values for generating hash
  825. //
  826. #define HASH_STRING_CONVERT_CONSTANT (314159269)
  827. #define HASH_STRING_PRIME (1000000007)
  828. //
  829. // Build an intermediate hash based on processing a number of WCHAR characters
  830. // pointed to by an input string. In most cases this will be a UNICODE_STRING.
  831. // It might also be a pointer though.
  832. //
  833. //
  834. // VOID
  835. // NtfsConvertNameToHash (
  836. // IN PWCHAR Buffer,
  837. // IN ULONG Length,
  838. // IN PWCH UpcaseTable,
  839. // IN OUT PULONG Hash
  840. // );
  841. //
  842. #define NtfsConvertNameToHash(B,L,U,H) { \
  843. PWCHAR _Current = (B); \
  844. PWCHAR _End = Add2Ptr( _Current, (L) ); \
  845. ULONG _Hash = *(H); \
  846. do { \
  847. \
  848. _Hash = 37 * _Hash + (U)[*(_Current)]; \
  849. _Current += 1; \
  850. \
  851. } while (_Current != _End); \
  852. *(H) = _Hash; \
  853. }
  854. //
  855. // ULONG
  856. // NtfsGenerateHashFromUlong (
  857. // IN ULONG Ulong
  858. // );
  859. //
  860. #define NtfsGenerateHashFromUlong(U) ( \
  861. abs( HASH_STRING_CONVERT_CONSTANT * (U) ) % HASH_STRING_PRIME \
  862. )
  863. #ifdef PERF_STATS
  864. //
  865. // Some structures to capture performance statisics during checkpoints
  866. //
  867. typedef struct _CHECKPOINT_ENTRY {
  868. ULONG Reason;
  869. LONGLONG StartTime;
  870. LONGLONG ElapsedTime;
  871. ULONG NumAttributes;
  872. ULONG NumIos;
  873. LSN RestartArea;
  874. ULONG LogFileFulls;
  875. } CHECKPOINT_ENTRY, *PCHECKPOINT_ENTRY;
  876. #define LF_LOG_SPACE 1
  877. #define LF_DIRTY_PAGES 2
  878. #define LF_OPEN_ATTRIBUTES 3
  879. #define LF_TRANSACTION_DRAIN 4
  880. #define LF_FASTIO_CALLBACK 5
  881. #define LF_DEALLOCATED_CLUSTERS 6
  882. #define LF_DEALLOCATED_CLUSTERS_MEM 7
  883. #define LF_RECORD_STACK_CHECK 8
  884. #define LF_DISMOUNT 9
  885. #define LF_COMPRESSION 10
  886. #define LF_SNAPSHOT 11
  887. #define LF_MOUNT 12
  888. #define LF_SHUTDOWN 13
  889. #define LF_RECURSIVE_COMPRESSION 14
  890. #define NUM_CHECKPOINT_ENTRIES 50
  891. #endif
  892. //
  893. // The Vcb structure corresponds to every mounted NTFS volume in the
  894. // system
  895. //
  896. #define VCB_SECURITY_CACHE_BY_ID_SIZE 31
  897. #define VCB_SECURITY_CACHE_BY_HASH_SIZE 31
  898. //
  899. // Default Minimum Usn Journal Size.
  900. //
  901. #define MINIMUM_USN_JOURNAL_SIZE (0x100000)
  902. typedef struct _VCB {
  903. //
  904. // The type and size of this record (must be NTFS_NTC_VCB)
  905. //
  906. // Assumption here is that this structure is embedded within a
  907. // device object and the base of this structure in on an even
  908. // 64-bit boundary. We will put the embedded structures on
  909. // the same boundaries they would be on if allocated from pool
  910. // (odd 64-bit boundary) except if the structure would fit
  911. // within a 16 byte cache line.
  912. //
  913. NODE_TYPE_CODE NodeTypeCode;
  914. NODE_BYTE_SIZE NodeByteSize;
  915. //
  916. // The internal state of the volume. The VcbState is synchronized with the Vcb resource.
  917. //
  918. ULONG VcbState;
  919. //
  920. // The links for the queue of all the Vcbs in the system.
  921. // Corresponds to the filld NtfsData.VcbQueue
  922. //
  923. LIST_ENTRY VcbLinks;
  924. //
  925. // Pointer to the Scb for the special system file. If the field is
  926. // null then we haven't yet built the scb for that system file. Also
  927. // the pointer to the stream file object is located in the scb.
  928. //
  929. // NOTE: AcquireExclusiveFiles depends on this order. Any change
  930. // here should be checked with the code there.
  931. //
  932. PSCB RootIndexScb;
  933. PSCB UsnJournal;
  934. PSCB MftScb;
  935. PSCB Mft2Scb;
  936. PSCB LogFileScb;
  937. PSCB BitmapScb;
  938. PSCB AttributeDefTableScb;
  939. PSCB BadClusterFileScb;
  940. PSCB ExtendDirectory;
  941. PSCB SecurityDescriptorStream;
  942. PSCB SecurityIdIndex;
  943. PSCB SecurityDescriptorHashIndex;
  944. PSCB UpcaseTableScb;
  945. PSCB QuotaTableScb;
  946. PSCB OwnerIdTableScb;
  947. PSCB ReparsePointTableScb;
  948. PSCB ObjectIdTableScb;
  949. PSCB VolumeDasdScb;
  950. PSCB MftBitmapScb;
  951. //
  952. // File object for log file. We always dereference the file object for the
  953. // log file last. This will allow us to synchronize when the Vpb for the
  954. // volume is deleted.
  955. //
  956. PFILE_OBJECT LogFileObject;
  957. //
  958. // A pointer the device object passed in by the I/O system on a mount
  959. // This is the target device object that the file system talks to
  960. // when it needs to do any I/O (e.g., the disk stripper device
  961. // object).
  962. //
  963. //
  964. PDEVICE_OBJECT TargetDeviceObject;
  965. //
  966. // Lfs Log Handle for this volume
  967. //
  968. LFS_LOG_HANDLE LogHandle;
  969. //
  970. // The root Lcb for this volume.
  971. //
  972. struct _LCB *RootLcb;
  973. //
  974. // A pointer to the VPB for the volume passed in by the I/O system on
  975. // a mount.
  976. //
  977. PVPB Vpb;
  978. //
  979. // A count of the number of file objects that have any file/directory
  980. // opened on this volume. And a count of the number of special system
  981. // files that we have open
  982. //
  983. CLONG CleanupCount;
  984. CLONG CloseCount;
  985. CLONG ReadOnlyCloseCount;
  986. CLONG SystemFileCloseCount;
  987. //
  988. // The following fields are used by the BitmpSup routines. The first
  989. // value contains the total number of clusters on the volume, this
  990. // is computed from the boot sector information. The second value
  991. // is the current number of free clusters available for allocation on
  992. // the volume. Allocation is handled by using a free space mcb that
  993. // describes some small window of known clusters that are free.
  994. //
  995. // The last field is for storing local volume specific data needed by
  996. // the bitmap routines
  997. //
  998. LONGLONG TotalClusters;
  999. LONGLONG FreeClusters;
  1000. LONGLONG DeallocatedClusters;
  1001. //
  1002. // Total number of reserved clusters on the volume, must be less than
  1003. // or equal to FreeClusters. Use the security fast mutex as a
  1004. // convenient end resource for this field.
  1005. //
  1006. LONGLONG TotalReserved;
  1007. //
  1008. // If we are growing the volume bitmap then we need to restore the total number of
  1009. // clusters.
  1010. //
  1011. LONGLONG PreviousTotalClusters;
  1012. //
  1013. // This field contains a calculated value which determines when an
  1014. // individual attribute is large enough to be moved to free up file
  1015. // record space. (The calculation of this variable must be
  1016. // considered in conjunction with the constant
  1017. // MAX_MOVEABLE_ATTRIBUTES below.)
  1018. //
  1019. ULONG BigEnoughToMove;
  1020. //
  1021. // The following volume-specific parameters are extracted from the
  1022. // Boot Sector.
  1023. //
  1024. ULONG DefaultBlocksPerIndexAllocationBuffer;
  1025. ULONG DefaultBytesPerIndexAllocationBuffer;
  1026. ULONG BytesPerSector;
  1027. ULONG BytesPerCluster;
  1028. ULONG BytesPerFileRecordSegment;
  1029. //
  1030. // Zero clusters per file record segment indicates that clusters are larger than
  1031. // file records. Zero file record segments per clusters indicates that
  1032. // file records are larger than clusters.
  1033. //
  1034. ULONG ClustersPerFileRecordSegment;
  1035. ULONG FileRecordsPerCluster;
  1036. ULONG ClustersPer4Gig;
  1037. //
  1038. // Clusters per page will be 1 if the cluster size is larger than the page size
  1039. //
  1040. ULONG ClustersPerPage;
  1041. LCN MftStartLcn;
  1042. LCN Mft2StartLcn;
  1043. LONGLONG NumberSectors;
  1044. //
  1045. // The following fields are used to verify that an NTFS volume hasn't
  1046. // changed. The serial number is stored in the boot sector on disk,
  1047. // and the four times are from the standard information field of the
  1048. // volume file.
  1049. //
  1050. LONGLONG VolumeSerialNumber;
  1051. LONGLONG VolumeCreationTime;
  1052. LONGLONG VolumeLastModificationTime;
  1053. LONGLONG VolumeLastChangeTime;
  1054. LONGLONG VolumeLastAccessTime;
  1055. //
  1056. // Convenient constants for the conversion macros. Shift and mask values are for
  1057. //
  1058. // Clusters <=> Bytes
  1059. // FileRecords <=> Bytes
  1060. // FileRecords <=> Clusters
  1061. //
  1062. // Note that you must know whether to shift right or left when using the
  1063. // file record/cluster shift value.
  1064. //
  1065. ULONG ClusterMask; // BytesPerCluster - 1
  1066. LONG InverseClusterMask; // ~ClusterMask - signed for 64-bit system
  1067. ULONG ClusterShift; // 2**ClusterShift == BytesPerCluster
  1068. ULONG MftShift; // 2**MftShift == BytesPerFileRecord
  1069. ULONG MftToClusterShift; // 2**MftClusterShift == ClusterPerFileRecordSegment
  1070. // 2**MftToClusterShift == FileRecordsPerCluster
  1071. ULONG MftReserved;
  1072. ULONG MftCushion;
  1073. //
  1074. // Synchronization objects for checkpoint operations.
  1075. //
  1076. ULONG CheckpointFlags;
  1077. FAST_MUTEX CheckpointMutex;
  1078. KEVENT CheckpointNotifyEvent;
  1079. //
  1080. // Mutex to synchronize access to the Fcb table.
  1081. //
  1082. FAST_MUTEX FcbTableMutex;
  1083. //
  1084. // Mutex to synchronize access to the security descriptors.
  1085. //
  1086. FAST_MUTEX FcbSecurityMutex;
  1087. //
  1088. // Mutex to synchronize access to reserved clusters.
  1089. //
  1090. FAST_MUTEX ReservedClustersMutex;
  1091. //
  1092. // Mutex for the hash table.
  1093. //
  1094. FAST_MUTEX HashTableMutex;
  1095. //
  1096. // We don't allow compression on a system with a cluster size greater than
  1097. // 4k. Use a mask value here to quickly check allowed compression on
  1098. // this volume.
  1099. //
  1100. USHORT AttributeFlagsMask;
  1101. //
  1102. // Remember what version this volume is so we can selectively enable
  1103. // certain features.
  1104. //
  1105. UCHAR MajorVersion;
  1106. UCHAR MinorVersion;
  1107. //
  1108. // The count of free records is based on the size of the Mft and the
  1109. // allocated records. The hole count is the count of how many file
  1110. // records are not allocated.
  1111. //
  1112. ULONG MftHoleGranularity;
  1113. ULONG MftFreeRecords;
  1114. ULONG MftHoleRecords;
  1115. //
  1116. // Variables for Mft hole calculations.
  1117. //
  1118. ULONG MftHoleMask;
  1119. LONG MftHoleInverseMask;
  1120. //
  1121. // The count of the bitmap bits per hole. This is the number of file
  1122. // records per hole. Must be converted to clusters to find a hole in
  1123. // the Mft Mcb.
  1124. //
  1125. ULONG MftClustersPerHole;
  1126. ULONG MftHoleClusterMask;
  1127. ULONG MftHoleClusterInverseMask;
  1128. //
  1129. // The following table of unicode values is the case mapping, with
  1130. // the size in number of Unicode characters. If the upcase table
  1131. // that is stored in NtfsData matches the one for the volume then
  1132. // we'll simply use that one and not allocate a special one for the
  1133. // volume.
  1134. //
  1135. ULONG UpcaseTableSize;
  1136. PWCH UpcaseTable;
  1137. //
  1138. // A pointer to an array of structs to hold performance counters,
  1139. // one array element for each processor. The array is allocated
  1140. // from non-paged pool. If this member is deleted, replace with
  1141. // padding.
  1142. //
  1143. struct _FILE_SYSTEM_STATISTICS *Statistics;
  1144. //
  1145. // Open attribute table.
  1146. //
  1147. LSN LastRestartArea;
  1148. RESTART_POINTERS OpenAttributeTable;
  1149. //
  1150. // Transaction table.
  1151. //
  1152. LSN LastBaseLsn;
  1153. RESTART_POINTERS TransactionTable;
  1154. //
  1155. // Latest Lsn at the beginning of a transaction before LsnWrite returns
  1156. // the actual Lsn used and got stored into the transaction entry.
  1157. // This field is synchronized by acquiring the transaction table.
  1158. //
  1159. LSN LastTransactionLsn;
  1160. //
  1161. // A count of writes to LastTransactionLsn.
  1162. // This field is synchronized by acquiring the transaction table exclusive.
  1163. // There are a few places where we can only share the transaction table,
  1164. // we then decrement this field using Interlocked routines.
  1165. //
  1166. ULONG LastTransactionLsnCount;
  1167. //
  1168. // LSNs of the end of the last checkpoint and the last RestartArea.
  1169. // Normally the RestartArea Lsn is greater than the other one,
  1170. // however if the VcbState indicates that a checkpoint is in
  1171. // progress, then these Lsns are in flux.
  1172. //
  1173. LSN EndOfLastCheckpoint;
  1174. //
  1175. // Current Lsn we used at mount time
  1176. //
  1177. LSN CurrentLsnAtMount;
  1178. //
  1179. // OldestDirtyLsn
  1180. //
  1181. LSN OldestDirtyLsn;
  1182. //
  1183. // The LSN of the restart area at the first logfile full not handled
  1184. // since the last clean checkpoint. This is only incremented for non-top-level
  1185. // request
  1186. //
  1187. LSN LastRestartAreaAtNonTopLevelLogFull;
  1188. //
  1189. // The following string contains the device name for this partition.
  1190. //
  1191. UNICODE_STRING DeviceName;
  1192. //
  1193. // A table of all the fcb that have been created for this volume.
  1194. //
  1195. RTL_GENERIC_TABLE FcbTable;
  1196. //
  1197. // The following is the head of a list of notify Irps for directories.
  1198. //
  1199. LIST_ENTRY DirNotifyList;
  1200. //
  1201. // The following is the head of a list of notify Irps for view indices.
  1202. //
  1203. LIST_ENTRY ViewIndexNotifyList;
  1204. //
  1205. // The following is used to synchronize the dir notify lists.
  1206. //
  1207. PNOTIFY_SYNC NotifySync;
  1208. //
  1209. // The following field is a pointer to the file object that has the
  1210. // volume locked. if the VcbState has the locked flag set.
  1211. //
  1212. PFILE_OBJECT FileObjectWithVcbLocked;
  1213. //
  1214. // The following two fields are used by the bitmap routines to
  1215. // determine what is called the mft zone. The Mft zone are those
  1216. // clusters on the disk were we will try and put the mft and only the
  1217. // mft unless the disk is getting too full.
  1218. //
  1219. LCN MftZoneStart;
  1220. LCN MftZoneEnd;
  1221. //
  1222. // Information to track activity in the volume bitmap. If we are extending
  1223. // the Mft we don't want to constantly force a rescan of the bitmap if
  1224. // there is no activity.
  1225. //
  1226. LONGLONG ClustersRecentlyFreed;
  1227. //
  1228. // The following are used to track the deallocated clusters waiting
  1229. // for a checkpoint. The pointers are used so we can toggle the
  1230. // use of the structures.
  1231. //
  1232. LIST_ENTRY DeallocatedClusterListHead;
  1233. DEALLOCATED_CLUSTERS DeallocatedClusters1;
  1234. DEALLOCATED_CLUSTERS DeallocatedClusters2;
  1235. //
  1236. // Fields associated with the Usn Journal. MaximumSize is the size in
  1237. // bytes that the Journal is allowed to occupy. StartUsn is the lowest Usn
  1238. // in the allocated range of the Journal. LowestOpenUsn remembers a Usn
  1239. // from restart from which a scan for Fcbs not closed at the time of a
  1240. // crash must be done. ModifiedOpenFiles is a listhead of Fcbs with
  1241. // active Usn records but have not written the final cleanup record.
  1242. // These fields and the list are synchronized by the UsnJournal resource.
  1243. //
  1244. USN_JOURNAL_INSTANCE UsnJournalInstance;
  1245. USN FirstValidUsn; // Synchronized by main file resource
  1246. USN LowestOpenUsn;
  1247. FILE_REFERENCE UsnJournalReference;
  1248. LONGLONG UsnCacheBias;
  1249. LIST_ENTRY ModifiedOpenFiles; // Synchronized by the NtfsLockFcb on UsnJournal
  1250. LIST_ENTRY NotifyUsnDeleteIrps; // Synchronized with NtfsLock/UnlockUsnNotify.
  1251. PLIST_ENTRY CurrentTimeOutFiles;
  1252. PLIST_ENTRY AgedTimeOutFiles;
  1253. LIST_ENTRY TimeOutListA;
  1254. LIST_ENTRY TimeOutListB;
  1255. NTFS_DELETE_JOURNAL_DATA DeleteUsnData;
  1256. //
  1257. // A resource variable to control access to the volume specific data
  1258. // structures
  1259. //
  1260. ERESOURCE Resource;
  1261. //
  1262. // Resource to manage mft lazywrite flushes and mft defrag
  1263. //
  1264. ERESOURCE MftFlushResource;
  1265. //
  1266. // Log header reservation. This is the amount to add to the reservation
  1267. // amount to compensate for the commit record. Lfs reserves differently
  1268. // for its log record header and the body of a log record.
  1269. //
  1270. ULONG LogHeaderReservation;
  1271. //
  1272. // Count of outstanding notify handles. If zero we can noop the notify calls.
  1273. //
  1274. ULONG NotifyCount;
  1275. //
  1276. // Count of outstanding view index notify handles. If zero we can noop view
  1277. // index notify calls.
  1278. //
  1279. ULONG ViewIndexNotifyCount;
  1280. //
  1281. // Count of media changes before this volume was mounted. Helps NtfsPingVolume
  1282. // notice when we've missed a media change notification.
  1283. //
  1284. ULONG DeviceChangeCount;
  1285. struct _SHARED_SECURITY **SecurityCacheById[VCB_SECURITY_CACHE_BY_ID_SIZE];
  1286. struct _SHARED_SECURITY *SecurityCacheByHash[VCB_SECURITY_CACHE_BY_HASH_SIZE];
  1287. SECURITY_ID NextSecurityId;
  1288. //
  1289. // Quota state and flags are protected by the QuotaControlLock above
  1290. //
  1291. ULONG QuotaState;
  1292. //
  1293. // QuotaFlags are a copy of the flags from default user index entry.
  1294. //
  1295. ULONG QuotaFlags;
  1296. //
  1297. // The next owner Id to be allocated.
  1298. //
  1299. ULONG QuotaOwnerId;
  1300. //
  1301. // Delete sequence number. The value gets incremented each time
  1302. // an owner id is marked for deletion.
  1303. //
  1304. ULONG QuotaDeleteSecquence;
  1305. //
  1306. // Quota control delete sequence. This values gets incremented each time
  1307. // a quota control block is removed from table.
  1308. //
  1309. ULONG QuotaControlDeleteCount;
  1310. //
  1311. // The following items are for Quota support.
  1312. // The QuotaControlTable is the root of the quota control blocks.
  1313. //
  1314. RTL_GENERIC_TABLE QuotaControlTable;
  1315. //
  1316. // Lock used for QuotaControlTable;
  1317. //
  1318. FAST_MUTEX QuotaControlLock;
  1319. //
  1320. // Current file reference used by the quota repair code.
  1321. //
  1322. FILE_REFERENCE QuotaFileReference;
  1323. //
  1324. // Administrator Owner Id.
  1325. //
  1326. ULONG AdministratorId;
  1327. //
  1328. // ObjectIdState indicates the state of the object id index.
  1329. //
  1330. ULONG ObjectIdState;
  1331. //
  1332. // Quota Control template used addin entry to the quota control table.
  1333. //
  1334. struct _QUOTA_CONTROL_BLOCK *QuotaControlTemplate;
  1335. //
  1336. // This is a pointer to the attribute definitions for the volume
  1337. // which are loaded into nonpaged pool.
  1338. //
  1339. PATTRIBUTE_DEFINITION_COLUMNS AttributeDefinitions;
  1340. //
  1341. // File property (shortname/longname/createtime) tunneling structure
  1342. //
  1343. TUNNEL Tunnel;
  1344. //
  1345. // Size and number of clusters in the sparse file unit.
  1346. // Initially this is 64K.
  1347. //
  1348. ULONG SparseFileUnit;
  1349. ULONG SparseFileClusters;
  1350. //
  1351. // Save away the maximum cluster count for this volume (limit to
  1352. // MAXFILESIZE).
  1353. //
  1354. LONGLONG MaxClusterCount;
  1355. //
  1356. // Embed the Lfs WRITE_DATA structure so we can trim the writes
  1357. // from MM.
  1358. //
  1359. LFS_WRITE_DATA LfsWriteData;
  1360. //
  1361. // Count of AcquireAllFiles.
  1362. //
  1363. ULONG AcquireFilesCount;
  1364. ULONG LogFileFullCount;
  1365. ULONG CleanCheckpointMark;
  1366. ULONG UnhandledLogFileFullCount;
  1367. //
  1368. // What restart version are we currently using.
  1369. //
  1370. ULONG RestartVersion;
  1371. ULONG OatEntrySize;
  1372. //
  1373. // Total number of entries on the async and delayed close queues for this Vcb.
  1374. //
  1375. CLONG QueuedCloseCount;
  1376. //
  1377. // Spare Vpb for dismount. Avoid using MustSucceed pool by preallocating
  1378. // the Vpb that might be needed for a dismount.
  1379. //
  1380. PVPB SpareVpb;
  1381. //
  1382. // Open attribute table to store on disk. It may point to the embedded
  1383. // open attribute table if the on-disk and in-memory version are the same.
  1384. //
  1385. PRESTART_POINTERS OnDiskOat;
  1386. //
  1387. // Linked list of OpenAttribute extended data structures.
  1388. //
  1389. LIST_ENTRY OpenAttributeData;
  1390. //
  1391. // The volume object id, if any. This can only be set for upgraded volumes.
  1392. //
  1393. UCHAR VolumeObjectId[OBJECT_ID_KEY_LENGTH];
  1394. NTFS_CACHED_RUNS CachedRuns;
  1395. //
  1396. // Last Lcn used for fresh allocation
  1397. //
  1398. LCN LastBitmapHint;
  1399. //
  1400. // File name hash table.
  1401. //
  1402. NTFS_HASH_TABLE HashTable;
  1403. //
  1404. // The MftDefragState is synchronized with the CheckpointEvent.
  1405. // The MftReserveFlags are sychronized with the MftScb.
  1406. //
  1407. ULONG MftReserveFlags;
  1408. ULONG MftDefragState;
  1409. //
  1410. // Event for synchronizing when the transaction table is empty
  1411. // if all the tables need this capability it should move directly into the
  1412. // restart ptrs.
  1413. //
  1414. KEVENT TransactionsDoneEvent;
  1415. // Checkpoint owner thread.
  1416. //
  1417. PVOID CheckpointOwnerThread;
  1418. //
  1419. // Hint for dirty page table size
  1420. //
  1421. ULONG DirtyPageTableSizeHint;
  1422. //
  1423. // Reserved mapping we can use to map in user addresses
  1424. //
  1425. PVOID ReservedMapping;
  1426. FAST_MUTEX ReservedMappingMutex;
  1427. #ifdef NTFS_CHECK_BITMAP
  1428. PRTL_BITMAP BitmapCopy;
  1429. ULONG BitmapPages;
  1430. #endif
  1431. #ifdef BENL_DBG
  1432. LIST_ENTRY RestartRedoHead;
  1433. LIST_ENTRY RestartUndoHead;
  1434. #endif
  1435. #ifdef SYSCACHE_DEBUG
  1436. PSCB SyscacheScb;
  1437. #endif
  1438. #ifdef PERF_STATS
  1439. //
  1440. // Create related
  1441. //
  1442. ULONG NumCreates;
  1443. LONGLONG TimePerCreates;
  1444. ULONG IosPerCreates;
  1445. LONGLONG TimePerCreateIos;
  1446. //
  1447. // Checkpoint related
  1448. //
  1449. CHECKPOINT_ENTRY ChkPointEntry[ NUM_CHECKPOINT_ENTRIES ];
  1450. ULONG CurrentCheckpoint;
  1451. #endif
  1452. } VCB;
  1453. typedef VCB *PVCB;
  1454. #ifdef PERF_STATS
  1455. #define IRP_MN_CREATE_NEW 0xff
  1456. #endif
  1457. //
  1458. // These are the VcbState flags. Synchronized with the Vcb resource.
  1459. //
  1460. #define VCB_STATE_VOLUME_MOUNTED (0x00000001)
  1461. #define VCB_STATE_LOCKED (0x00000002)
  1462. #define VCB_STATE_REMOVABLE_MEDIA (0x00000004)
  1463. #define VCB_STATE_VOLUME_MOUNTED_DIRTY (0x00000008)
  1464. #define VCB_STATE_RESTART_IN_PROGRESS (0x00000010)
  1465. #define VCB_STATE_FLAG_SHUTDOWN (0x00000020)
  1466. #define VCB_STATE_NO_SECONDARY_AVAILABLE (0x00000040)
  1467. #define VCB_STATE_RELOAD_FREE_CLUSTERS (0x00000080)
  1468. #define VCB_STATE_PRELOAD_MFT (0x00000100)
  1469. #define VCB_STATE_VOL_PURGE_IN_PROGRESS (0x00000200)
  1470. #define VCB_STATE_TEMP_VPB (0x00000400)
  1471. #define VCB_STATE_PERFORMED_DISMOUNT (0x00000800)
  1472. #define VCB_STATE_VALID_LOG_HANDLE (0x00001000)
  1473. #define VCB_STATE_DELETE_UNDERWAY (0x00002000)
  1474. #define VCB_STATE_REDUCED_MFT (0x00004000)
  1475. #define VCB_STATE_EXPLICIT_LOCK (0x00008000)
  1476. #define VCB_STATE_DISALLOW_DISMOUNT (0x00010000)
  1477. #define VCB_STATE_VALID_OBJECT_ID (0x00020000)
  1478. #define VCB_STATE_OBJECT_ID_CLEANUP (0x00040000)
  1479. #define VCB_STATE_USN_JOURNAL_ACTIVE (0x00080000)
  1480. #define VCB_STATE_USN_DELETE (0x00100000)
  1481. #define VCB_STATE_USN_JOURNAL_PRESENT (0x00200000)
  1482. #define VCB_STATE_INCOMPLETE_USN_DELETE (0x00400000)
  1483. #define VCB_STATE_EXPLICIT_DISMOUNT (0x00800000)
  1484. #define VCB_STATE_LOCK_IN_PROGRESS (0x01000000)
  1485. #define VCB_STATE_MOUNT_READ_ONLY (0x02000000)
  1486. #define VCB_STATE_TARGET_DEVICE_STOPPED (0x08000000)
  1487. #define VCB_STATE_MOUNT_COMPLETED (0x10000000)
  1488. #define VCB_STATE_BAD_RESTART (0x20000000)
  1489. //
  1490. // These are the flags for the Mft and the reserveration state.
  1491. // Although these are in the Vcb they are synchronized with
  1492. // the resource in the MftScb.
  1493. //
  1494. #define VCB_MFT_RECORD_RESERVED (0x00000001)
  1495. #define VCB_MFT_RECORD_15_USED (0x00000002)
  1496. //
  1497. // These are the MftDefragState flags. Synchronized with the
  1498. // CheckpointEvent.
  1499. //
  1500. #define VCB_MFT_DEFRAG_PERMITTED (0x00000001)
  1501. #define VCB_MFT_DEFRAG_ENABLED (0x00000002)
  1502. #define VCB_MFT_DEFRAG_TRIGGERED (0x00000004)
  1503. #define VCB_MFT_DEFRAG_ACTIVE (0x00000008)
  1504. #define VCB_MFT_DEFRAG_EXCESS_MAP (0x00000010)
  1505. //
  1506. // These are the Checkpoint flags. Synchronized with the
  1507. // CheckpointEvent. These flags are in the CheckpointFlags
  1508. // field.
  1509. //
  1510. #define VCB_DUMMY_CHECKPOINT_POSTED (0x00000001)
  1511. #define VCB_CHECKPOINT_IN_PROGRESS (0x00000002)
  1512. #define VCB_LAST_CHECKPOINT_CLEAN (0x00000004)
  1513. #define VCB_DEREFERENCED_LOG_FILE (0x00000008)
  1514. #define VCB_STOP_LOG_CHECKPOINT (0x00000010)
  1515. #define VCB_LAST_CHECKPOINT_PSEUDO_CLEAN (0x00000020)
  1516. #define VCB_CHECKPOINT_SYNC_FLAGS (VCB_CHECKPOINT_IN_PROGRESS | VCB_STOP_LOG_CHECKPOINT)
  1517. //
  1518. // These are Vcb quota state flags. Synchronized with the
  1519. // QuotaControlLock. These flags are in the QuotaState field.
  1520. //
  1521. #define VCB_QUOTA_REPAIR_POSTED (0x00000100)
  1522. #define VCB_QUOTA_CLEAR_RUNNING (0x00000200)
  1523. #define VCB_QUOTA_INDEX_REPAIR (0x00000300)
  1524. #define VCB_QUOTA_OWNER_VERIFY (0x00000400)
  1525. #define VCB_QUOTA_RECALC_STARTED (0x00000500)
  1526. #define VCB_QUOTA_DELETEING_IDS (0x00000600)
  1527. #define VCB_QUOTA_REPAIR_RUNNING (0x00000700)
  1528. #define VCB_QUOTA_SAVE_QUOTA_FLAGS (0x00001000)
  1529. //
  1530. // These are Vcb object id state flags. Synchronized with the
  1531. // ObjectIdTableScb->Resource. These flags are in the ObjectIdState field.
  1532. //
  1533. #define VCB_OBJECT_ID_CORRUPT (0x00000001)
  1534. #define VCB_OBJECT_ID_REPAIR_RUNNING (0x00000002)
  1535. //
  1536. // This is the maximum number of attributes in a file record which could
  1537. // be considered for moving. This value should be changed only in
  1538. // conjunction with the initialization of the BigEnoughToMove field
  1539. // above.
  1540. //
  1541. #define MAX_MOVEABLE_ATTRIBUTES (3)
  1542. //
  1543. // Define the file system statistics struct. Vcb->Statistics points to an
  1544. // array of these (one per processor) and they must be 64 byte aligned to
  1545. // prevent cache line tearing.
  1546. //
  1547. typedef struct _FILE_SYSTEM_STATISTICS {
  1548. //
  1549. // This contains the actual data.
  1550. //
  1551. FILESYSTEM_STATISTICS Common;
  1552. NTFS_STATISTICS Ntfs;
  1553. //
  1554. // Pad this structure to a multiple of 64 bytes.
  1555. //
  1556. UCHAR Pad[64-(sizeof(FILESYSTEM_STATISTICS)+sizeof(NTFS_STATISTICS))%64];
  1557. } FILE_SYSTEM_STATISTICS;
  1558. typedef FILE_SYSTEM_STATISTICS *PFILE_SYSTEM_STATISTICS;
  1559. //
  1560. // The Volume Device Object is an I/O system device object with a
  1561. // workqueue and an VCB record appended to the end. There are multiple
  1562. // of these records, one for every mounted volume, and are created during
  1563. // a volume mount operation. The work queue is for handling an overload
  1564. // of work requests to the volume.
  1565. //
  1566. typedef struct _VOLUME_DEVICE_OBJECT {
  1567. DEVICE_OBJECT DeviceObject;
  1568. //
  1569. // The following field tells how many requests for this volume have
  1570. // either been enqueued to ExWorker threads or are currently being
  1571. // serviced by ExWorker threads. If the number goes above
  1572. // a certain threshold, put the request on the overflow queue to be
  1573. // executed later.
  1574. //
  1575. ULONG PostedRequestCount;
  1576. //
  1577. // The following field indicates the number of IRP's waiting
  1578. // to be serviced in the overflow queue.
  1579. //
  1580. ULONG OverflowQueueCount;
  1581. //
  1582. // The following field contains the queue header of the overflow
  1583. // queue. The Overflow queue is a list of IRP's linked via the IRP's
  1584. // ListEntry field.
  1585. //
  1586. LIST_ENTRY OverflowQueue;
  1587. //
  1588. // Event used to synchronize entry into the queue when its heavily used
  1589. //
  1590. KEVENT OverflowQueueEvent;
  1591. //
  1592. // The following spinlock protects access to all the above fields.
  1593. //
  1594. KSPIN_LOCK OverflowQueueSpinLock;
  1595. //
  1596. // This is the file system specific volume control block.
  1597. //
  1598. VCB Vcb;
  1599. } VOLUME_DEVICE_OBJECT;
  1600. typedef VOLUME_DEVICE_OBJECT *PVOLUME_DEVICE_OBJECT;
  1601. //
  1602. // The following structure is used to perform a quick lookup of an
  1603. // index entry for the update duplicate information call.
  1604. //
  1605. typedef struct _QUICK_INDEX {
  1606. //
  1607. // Change count for the Scb Index stream when this snapshot is made.
  1608. //
  1609. ULONG ChangeCount;
  1610. //
  1611. // This is the offset of the entry in the buffer. A value of zero is
  1612. // used for an entry in the root index.
  1613. //
  1614. ULONG BufferOffset;
  1615. //
  1616. // Captured Lsn for page containing this entry.
  1617. //
  1618. LSN CapturedLsn;
  1619. //
  1620. // This is the IndexBlock for the index bucket.
  1621. //
  1622. LONGLONG IndexBlock;
  1623. } QUICK_INDEX;
  1624. typedef QUICK_INDEX *PQUICK_INDEX;
  1625. //
  1626. // This structure is used to contain a link name and connections into
  1627. // the splay tree for the parent.
  1628. //
  1629. typedef struct _NAME_LINK {
  1630. UNICODE_STRING LinkName;
  1631. RTL_SPLAY_LINKS Links;
  1632. } NAME_LINK, *PNAME_LINK;
  1633. //
  1634. // The Lcb record corresponds to every open path between an Scb and an
  1635. // Fcb. It denotes the name which was used to go from the scb to the fcb
  1636. // and it also contains a queue of ccbs that have opened the fcb via that
  1637. // name and also a queue of Prefix Entries that will get us to this lcb
  1638. //
  1639. typedef struct _OVERLAY_LCB {
  1640. //
  1641. // We will need a FILE_NAME_ATTR in order to lookup the entry
  1642. // for the UpdateDuplicateInfo calls. We would like to keep
  1643. // one around but there are 0x38 bytes in it which will be unused.
  1644. // Instead we will overlay the Lcb with one of these. Then we can
  1645. // store other data within the unused bytes.
  1646. //
  1647. // NOTE - This will save an allocation but the sizes must match exactly
  1648. // or the name will be in the wrong location. This structure will
  1649. // overlay a FILE_NAME attribute exactly. The fields below which are
  1650. // prefaced with 'Overlay' correspond to the fields in the filename
  1651. // attribute which are being used with this structure.
  1652. //
  1653. // We will put an assert in NtfsInit to verify this.
  1654. //
  1655. FILE_REFERENCE OverlayParentDirectory;
  1656. //
  1657. // On 32-bit systems the remainder of the structure members up to the
  1658. // overlay entries previously occupied exactly the required amount of
  1659. // space for the DUPLICATE_INFOMATION structure. On 64-bit systems,
  1660. // this is not true and a little difference layout must be used.
  1661. //
  1662. union {
  1663. DUPLICATED_INFORMATION Alignment;
  1664. struct {
  1665. //
  1666. // This is used for lookups in the directory containing this link.
  1667. //
  1668. QUICK_INDEX QuickIndex;
  1669. //
  1670. // This is the number of references to this link. The parent
  1671. // Scb must be owned to modify this count.
  1672. //
  1673. ULONG ReferenceCount;
  1674. //
  1675. // These are the flags for the changes to this link and the
  1676. // change count for the duplicated information on this link.
  1677. //
  1678. ULONG InfoFlags;
  1679. //
  1680. // Hash value for this Lcb. Note - it is not guaranteed to be in the table.
  1681. //
  1682. ULONG HashValue;
  1683. //
  1684. // This is the number of unclean handles on this link.
  1685. //
  1686. ULONG CleanupCount;
  1687. //
  1688. // Internal reference to FileName attribute either embedded in overlay or external
  1689. // allocation (if size doesn't fit into storage). On Win64 systems this will
  1690. // fill the overlay. On Win32 systems we waste 4 bytes.
  1691. //
  1692. PFILE_NAME FileNameAttr;
  1693. };
  1694. };
  1695. UCHAR OverlayFileNameLength;
  1696. UCHAR OverlayFlags;
  1697. WCHAR OverlayFileName[1];
  1698. } OVERLAY_LCB, *POVERLAY_LCB;
  1699. typedef struct _LCB {
  1700. //
  1701. // Type and size of this record must be NTFS_NTC_LCB
  1702. //
  1703. NODE_TYPE_CODE NodeTypeCode;
  1704. NODE_BYTE_SIZE NodeByteSize;
  1705. //
  1706. // Internal state of the Lcb
  1707. //
  1708. ULONG LcbState;
  1709. //
  1710. // The links for all the Lcbs that emminate out of an Scb and a
  1711. // pointer back to the Scb. Corresponds to Scb->LcbQueue.
  1712. //
  1713. LIST_ENTRY ScbLinks;
  1714. PSCB Scb;
  1715. //
  1716. // The links for all the Lcbs that go into an Fcb and a pointer
  1717. // back to the Fcb. Corresponds to Fcb->LcbQueue.
  1718. //
  1719. struct _FCB *Fcb;
  1720. LIST_ENTRY FcbLinks;
  1721. //
  1722. // The following is the case-insensitive name link.
  1723. //
  1724. NAME_LINK IgnoreCaseLink;
  1725. //
  1726. // The following is the case-sensitive name link.
  1727. //
  1728. // This field is here on the 64-bit system and in the overlay lcb
  1729. // structure on the 32-bit system.
  1730. //
  1731. NAME_LINK ExactCaseLink;
  1732. //
  1733. // A queue of Ccbs that have the Fcb (via this edge) opened.
  1734. // Corresponds to Ccb->LcbLinks
  1735. //
  1736. LIST_ENTRY CcbQueue;
  1737. //
  1738. // We will need a FILE_NAME_ATTR in order to lookup the entry
  1739. // for the UpdateDuplicateInfo calls. We would like to keep
  1740. // one around but there are 0x38 bytes in it which will be unused.
  1741. // Instead we will overlay the Lcb with one of these. Then we can
  1742. // store other data within the unused bytes.
  1743. //
  1744. // NOTE - This will save an allocation but the sizes much match exactly
  1745. // or the name will be in the wrong location.
  1746. //
  1747. union {
  1748. FILE_NAME;
  1749. OVERLAY_LCB;
  1750. };
  1751. } LCB;
  1752. typedef LCB *PLCB;
  1753. #define LCB_STATE_DELETE_ON_CLOSE (0x00000001)
  1754. #define LCB_STATE_LINK_IS_GONE (0x00000002)
  1755. #define LCB_STATE_EXACT_CASE_IN_TREE (0x00000004)
  1756. #define LCB_STATE_IGNORE_CASE_IN_TREE (0x00000008)
  1757. #define LCB_STATE_DESIGNATED_LINK (0x00000010)
  1758. #define LCB_STATE_VALID_HASH_VALUE (0x00000020)
  1759. #define LcbSplitPrimaryLink( LCB ) \
  1760. ((LCB)->FileNameAttr->Flags == FILE_NAME_NTFS \
  1761. || (LCB)->FileNameAttr->Flags == FILE_NAME_DOS )
  1762. #define LcbSplitPrimaryComplement( LCB ) \
  1763. (((LCB)->FileNameAttr->Flags == FILE_NAME_NTFS) ? \
  1764. FILE_NAME_DOS : FILE_NAME_NTFS)
  1765. #define LcbLinkIsDeleted( LCB ) \
  1766. ((FlagOn( (LCB)->LcbState, LCB_STATE_DELETE_ON_CLOSE )) \
  1767. || ((FlagOn( (LCB)->FileNameAttr->Flags, FILE_NAME_DOS | FILE_NAME_NTFS )) \
  1768. && (FlagOn((LCB)->Fcb->FcbState,FCB_STATE_PRIMARY_LINK_DELETED ))))
  1769. #define SIZEOF_LCB (FIELD_OFFSET( LCB, FileName ) + sizeof( WCHAR ))
  1770. //
  1771. // This structure serves as a Usn record buffer for a file, and also is linked
  1772. // into the list of ModifiedOpenFiles to capture the lowest Modified Usn that has
  1773. // not been through cleanup yet.
  1774. //
  1775. // This structure is synchronized by the NtfsLockFcb for the file, however see
  1776. // comments below for Fcb->FcbUsnRecord field. The ModifiedOpenFiles list is
  1777. // synchronized by NtfsLockFcb on the UsnJournal.
  1778. //
  1779. typedef struct _FCB_USN_RECORD {
  1780. //
  1781. // Type and size of this record must be NTFS_NTC_USN
  1782. //
  1783. NODE_TYPE_CODE NodeTypeCode;
  1784. NODE_BYTE_SIZE NodeByteSize;
  1785. //
  1786. // A pointer back to the Fcb
  1787. //
  1788. struct _FCB *Fcb;
  1789. //
  1790. // Links for the aged OpenFiles queue. This is used to generate close records
  1791. // for files which are idle but have pending changes to report. Prime example is
  1792. // mapped page write where MM doesn't dereference the file object for an extended
  1793. // period of time. A NULL flink indicates it is not in this queue.
  1794. //
  1795. LIST_ENTRY TimeOutLinks;
  1796. //
  1797. // Links for the Vcb ModifiedOpenFiles list.
  1798. //
  1799. LIST_ENTRY ModifiedOpenFilesLinks;
  1800. //
  1801. // The Usn Record buffer.
  1802. //
  1803. USN_RECORD UsnRecord;
  1804. } FCB_USN_RECORD;
  1805. typedef FCB_USN_RECORD *PFCB_USN_RECORD;
  1806. //
  1807. // The Fcb record corresponds to every open file and directory, and to
  1808. // every directory on an opened path.
  1809. //
  1810. // The structure is really divided into two parts. FCB can be allocated
  1811. // from paged pool while the SCB must be allocated from non-paged
  1812. // pool. There is an SCB for every file stream associated with the Fcb.
  1813. //
  1814. // Note that the Fcb, multiple Scb records all use the same resource so
  1815. // if we need to grab exclusive access to the Fcb we only need to grab
  1816. // one resource and we've blocked all the scbs
  1817. //
  1818. typedef struct _FCB {
  1819. //
  1820. // Type and size of this record must be NTFS_NTC_FCB
  1821. //
  1822. NODE_TYPE_CODE NodeTypeCode;
  1823. NODE_BYTE_SIZE NodeByteSize;
  1824. //
  1825. // The internal state of the Fcb.
  1826. // Sync: Some flags are set on creation and then left. Safe to test at any time.
  1827. // Otherwise use Fcb X | Fcb S with Fcb mutex to change. Critical flags which
  1828. // reflect state of file (DELETED, etc) will always be changed with Fcb X.
  1829. //
  1830. ULONG FcbState;
  1831. //
  1832. // The following field contains the file reference for the Fcb
  1833. //
  1834. FILE_REFERENCE FileReference;
  1835. //
  1836. // A count of the number of file objects that have been opened for
  1837. // this file, but not yet been cleaned up yet.
  1838. // This count gets decremented in NtfsCommonCleanup,
  1839. // while the CloseCount below gets decremented in NtfsCommonClose.
  1840. // Sync: Vcb X | Vcb S and Fcb X.
  1841. //
  1842. CLONG CleanupCount;
  1843. //
  1844. // A count of the number of file objects that have opened
  1845. // this file.
  1846. // Sync: Use InterlockedIncrement/Decrement to change. Critical users
  1847. // have Vcb X | Vcb S and Fcb X. Other callers will temporarily increment
  1848. // and decrement this value but they always start at a non-zero value.
  1849. //
  1850. CLONG CloseCount;
  1851. //
  1852. // A count of other references to this Fcb.
  1853. // Sync: Use the FcbTable mutex in Vcb.
  1854. //
  1855. CLONG ReferenceCount;
  1856. //
  1857. // Relevant counts for delete checking.
  1858. //
  1859. ULONG FcbDenyDelete;
  1860. ULONG FcbDeleteFile;
  1861. //
  1862. // This is the count of the number of times the current transaction
  1863. // has acquired the main resource.
  1864. //
  1865. USHORT BaseExclusiveCount;
  1866. //
  1867. // This counts the number of times the Ea's on this file have been
  1868. // modified.
  1869. //
  1870. USHORT EaModificationCount;
  1871. //
  1872. // The Queue of all the Lcb that we are part of. The list is
  1873. // actually ordered in a small sense. The get next scb routine that
  1874. // traverses the Fcb/Scb graph always will put the current lcb edge
  1875. // that it is traversing into the front of this queue.
  1876. //
  1877. LIST_ENTRY LcbQueue;
  1878. //
  1879. // A queue of Scb associated with the fcb. Corresponds to Scb->FcbLinks.
  1880. // Sync: Must own Fcb X | Fcb S with FcbMutex.
  1881. //
  1882. LIST_ENTRY ScbQueue;
  1883. //
  1884. // These are the links for the list of exclusively-owned Scbs off of
  1885. // the IrpContext. We need to keep track of the exclusive count
  1886. // in the Fcb before our acquire so we know how many times to release
  1887. // it.
  1888. //
  1889. LIST_ENTRY ExclusiveFcbLinks;
  1890. //
  1891. // A pointer to the Vcb containing this Fcb
  1892. //
  1893. PVCB Vcb;
  1894. //
  1895. // Fast Mutex used to synchronize access to Fcb fields. This is also used as
  1896. // the fast mutex for the individual Scb's except for those that may need their
  1897. // own (Mft, PagingFile, AttributeList).
  1898. //
  1899. PFAST_MUTEX FcbMutex;
  1900. //
  1901. // The following field is used to store a pointer to the resource
  1902. // protecting the Fcb
  1903. //
  1904. PERESOURCE Resource;
  1905. //
  1906. // The following field contains a pointer to the resource
  1907. // synchronizing a changing FileSize with paging Io.
  1908. //
  1909. PERESOURCE PagingIoResource;
  1910. //
  1911. // Copy of the duplicated information for this Fcb.
  1912. // Also a flags field to tell us what has changed in the structure.
  1913. //
  1914. DUPLICATED_INFORMATION Info;
  1915. ULONG InfoFlags;
  1916. //
  1917. // LinkCount is the number of non deleted links to the file
  1918. // TotalLinks is the number of total links - including deleted ones
  1919. //
  1920. USHORT LinkCount;
  1921. USHORT TotalLinks;
  1922. //
  1923. // This is the actual last access for the main stream of this file.
  1924. // We don't store it in the duplicated information until we are ready
  1925. // to write it out to disk. Whenever we update the standard
  1926. // information we will copy the data out of the this field into the
  1927. // duplicate information.
  1928. //
  1929. LONGLONG CurrentLastAccess;
  1930. //
  1931. // The following fields contains a pointer to the security descriptor
  1932. // for this file. The field can start off null and later be loaded
  1933. // in by any of the security support routines. On delete Fcb the
  1934. // field pool should be deallocated when the fcb goes away
  1935. //
  1936. struct _SHARED_SECURITY *SharedSecurity;
  1937. //
  1938. // Pointer to the Quota Control block for the file.
  1939. //
  1940. struct _QUOTA_CONTROL_BLOCK *QuotaControl;
  1941. //
  1942. // The Lsn to flush to before allowing any data to hit the disk. Synchronized
  1943. // by NtfsLockFcb on this file.
  1944. //
  1945. LSN UpdateLsn;
  1946. //
  1947. // Id for file owner, from bidir security index
  1948. //
  1949. ULONG OwnerId;
  1950. //
  1951. // This is the count of file objects for this Fcb on the delayed
  1952. // close queue. Used to determine whether we need to dereference
  1953. // a file object we create in the compressed write path.
  1954. // Synchronize this field with the interlocked routines.
  1955. //
  1956. ULONG DelayedCloseCount;
  1957. //
  1958. // SecurityId for the file - translates via bidir index to
  1959. // granted access Acl.
  1960. //
  1961. ULONG SecurityId;
  1962. //
  1963. // Update sequence number for this file.
  1964. //
  1965. USN Usn;
  1966. //
  1967. // Pointer to the Usn Record buffer for this Fcb, or NULL if none is
  1968. // yet allocated. To test or dereference this field, you must either
  1969. // have the main file resource at least shared (because NtfsSetRenameInfo
  1970. // will reallocate this structure.), or else NtfsLockFcb on the file. To
  1971. // modify the fields of this record, see comments above.
  1972. //
  1973. PFCB_USN_RECORD FcbUsnRecord;
  1974. //
  1975. // Pointer to a context pointer to track operations in recursive calls.
  1976. // Lifespan of this pointer is typically a single request.
  1977. //
  1978. struct _FCB_CONTEXT *FcbContext;
  1979. } FCB;
  1980. typedef FCB *PFCB;
  1981. #define FCB_STATE_FILE_DELETED (0x00000001)
  1982. #define FCB_STATE_NONPAGED (0x00000002)
  1983. #define FCB_STATE_PAGING_FILE (0x00000004)
  1984. #define FCB_STATE_DUP_INITIALIZED (0x00000008)
  1985. #define FCB_STATE_UPDATE_STD_INFO (0x00000010)
  1986. #define FCB_STATE_PRIMARY_LINK_DELETED (0x00000020)
  1987. #define FCB_STATE_IN_FCB_TABLE (0x00000040)
  1988. #define FCB_STATE_SYSTEM_FILE (0x00000100)
  1989. #define FCB_STATE_COMPOUND_DATA (0x00000200)
  1990. #define FCB_STATE_COMPOUND_INDEX (0x00000400)
  1991. #define FCB_STATE_LARGE_STD_INFO (0x00000800)
  1992. #define FCB_STATE_MODIFIED_SECURITY (0x00001000)
  1993. #define FCB_STATE_DIRECTORY_ENCRYPTED (0x00002000)
  1994. #define FCB_STATE_VALID_USN_NAME (0x00004000)
  1995. #define FCB_STATE_USN_JOURNAL (0x00008000)
  1996. #define FCB_STATE_ENCRYPTION_PENDING (0x00010000)
  1997. #define FCB_INFO_CHANGED_CREATE FILE_NOTIFY_CHANGE_CREATION // (0x00000040)
  1998. #define FCB_INFO_CHANGED_LAST_MOD FILE_NOTIFY_CHANGE_LAST_WRITE // (0x00000010)
  1999. #define FCB_INFO_CHANGED_LAST_CHANGE (0x80000000)
  2000. #define FCB_INFO_CHANGED_LAST_ACCESS FILE_NOTIFY_CHANGE_LAST_ACCESS // (0x00000020)
  2001. #define FCB_INFO_CHANGED_ALLOC_SIZE (0x40000000)
  2002. #define FCB_INFO_CHANGED_FILE_SIZE FILE_NOTIFY_CHANGE_SIZE // (0x00000008)
  2003. #define FCB_INFO_CHANGED_FILE_ATTR FILE_NOTIFY_CHANGE_ATTRIBUTES // (0x00000004)
  2004. #define FCB_INFO_CHANGED_EA_SIZE FILE_NOTIFY_CHANGE_EA // (0x00000080)
  2005. #define FCB_INFO_MODIFIED_SECURITY FILE_NOTIFY_CHANGE_SECURITY // (0x00000100)
  2006. #define FCB_INFO_UPDATE_LAST_ACCESS (0x20000000)
  2007. //
  2008. // Subset of the Fcb Info flags used to track duplicate info.
  2009. //
  2010. #define FCB_INFO_DUPLICATE_FLAGS (FCB_INFO_CHANGED_CREATE | \
  2011. FCB_INFO_CHANGED_LAST_MOD | \
  2012. FCB_INFO_CHANGED_LAST_CHANGE | \
  2013. FCB_INFO_CHANGED_LAST_ACCESS | \
  2014. FCB_INFO_CHANGED_ALLOC_SIZE | \
  2015. FCB_INFO_CHANGED_FILE_SIZE | \
  2016. FCB_INFO_CHANGED_FILE_ATTR | \
  2017. FCB_INFO_CHANGED_EA_SIZE )
  2018. //
  2019. // Subset of the Fcb Info flags used to track notifies.
  2020. //
  2021. #define FCB_INFO_NOTIFY_FLAGS (FCB_INFO_CHANGED_CREATE | \
  2022. FCB_INFO_CHANGED_LAST_MOD | \
  2023. FCB_INFO_CHANGED_LAST_ACCESS | \
  2024. FCB_INFO_CHANGED_ALLOC_SIZE | \
  2025. FCB_INFO_CHANGED_FILE_SIZE | \
  2026. FCB_INFO_CHANGED_FILE_ATTR | \
  2027. FCB_INFO_CHANGED_EA_SIZE | \
  2028. FCB_INFO_MODIFIED_SECURITY )
  2029. //
  2030. // Subset of the Fcb Info flags used to track notifies. The allocation flag
  2031. // is removed from the full notify flags because dir notify overloads
  2032. // the file size flag for allocation and file size.
  2033. //
  2034. #define FCB_INFO_VALID_NOTIFY_FLAGS (FCB_INFO_CHANGED_CREATE | \
  2035. FCB_INFO_CHANGED_LAST_MOD | \
  2036. FCB_INFO_CHANGED_LAST_ACCESS | \
  2037. FCB_INFO_CHANGED_FILE_SIZE | \
  2038. FCB_INFO_CHANGED_FILE_ATTR | \
  2039. FCB_INFO_CHANGED_EA_SIZE | \
  2040. FCB_INFO_MODIFIED_SECURITY )
  2041. #define FCB_CREATE_SECURITY_COUNT (5)
  2042. #define FCB_LARGE_ACL_SIZE (512)
  2043. //
  2044. // Fcb Context structure. If a pointer to one of these is in the Fcb then recursive calls will update
  2045. // it as appropriate.
  2046. //
  2047. typedef struct _FCB_CONTEXT {
  2048. BOOLEAN FcbDeleted;
  2049. } FCB_CONTEXT, *PFCB_CONTEXT;
  2050. //
  2051. // The following three structures are the separate union structures for
  2052. // Scb structure.
  2053. //
  2054. typedef enum _RWC_OPERATION {
  2055. SetDirty = 0,
  2056. FullOverwrite,
  2057. StartOfWrite,
  2058. StartOfRead,
  2059. EndOfRead,
  2060. ReadUncompressed,
  2061. ReadZeroes,
  2062. PartialBcb,
  2063. WriteCompressed,
  2064. FaultIntoUncompressed,
  2065. TrimCopyRead,
  2066. ZeroCompressedRead,
  2067. TrimCompressedRead,
  2068. TrimCompressedWrite
  2069. } RWC_OPERATION;
  2070. #ifdef NTFS_RWC_DEBUG
  2071. typedef struct _RWC_HISTORY_ENTRY {
  2072. ULONG Operation;
  2073. ULONG Information;
  2074. ULONG FileOffset;
  2075. ULONG Length;
  2076. } RWC_HISTORY_ENTRY, *PRWC_HISTORY_ENTRY;
  2077. #define MAX_RWC_HISTORY_INDEX (300)
  2078. #endif
  2079. typedef struct _SCB_DATA {
  2080. //
  2081. // Total number of reserved bytes
  2082. //
  2083. LONGLONG TotalReserved;
  2084. //
  2085. // The following field is used by the oplock module
  2086. // to maintain current oplock information.
  2087. //
  2088. OPLOCK Oplock;
  2089. //
  2090. // The following field is used by the filelock module
  2091. // to maintain current byte range locking information.
  2092. //
  2093. PFILE_LOCK FileLock;
  2094. //
  2095. // List of wait for length blocks, for threads waiting for the
  2096. // file to exceed the specified length.
  2097. //
  2098. LIST_ENTRY WaitForNewLength;
  2099. #ifdef COMPRESS_ON_WIRE
  2100. //
  2101. // List of compression synchronization objects.
  2102. //
  2103. LIST_ENTRY CompressionSyncList;
  2104. #endif
  2105. //
  2106. // Pointer to an Mcb describing the reserved space for
  2107. // dirty compression units in compressed files which do
  2108. // not currently have a user section.
  2109. //
  2110. PRESERVED_BITMAP_RANGE ReservedBitMap;
  2111. #ifdef NTFS_RWC_DEBUG
  2112. ULONG RwcIndex;
  2113. PRWC_HISTORY_ENTRY HistoryBuffer;
  2114. #endif
  2115. } SCB_DATA, *PSCB_DATA;
  2116. typedef struct _SCB_INDEX {
  2117. //
  2118. // This is a list of records within the index allocation stream which
  2119. // have been deallocated in the current transaction.
  2120. //
  2121. LIST_ENTRY RecentlyDeallocatedQueue;
  2122. //
  2123. // Record allocation context, for managing the allocation of the
  2124. // INDEX_ALLOCATION_ATTRIBUTE, if one exists.
  2125. //
  2126. RECORD_ALLOCATION_CONTEXT RecordAllocationContext;
  2127. //
  2128. // A queue of all the lcbs that are opened under this Scb.
  2129. // Corresponds to Lcb->ScbLinks
  2130. //
  2131. LIST_ENTRY LcbQueue;
  2132. //
  2133. // The following are the splay links of Lcbs opened under this
  2134. // Scb. Note that not all of the Lcb in the list above may
  2135. // be in the splay links below.
  2136. //
  2137. PRTL_SPLAY_LINKS ExactCaseNode;
  2138. PRTL_SPLAY_LINKS IgnoreCaseNode;
  2139. //
  2140. // Normalized name. This is the path from the root to this directory
  2141. // without any of the short-name-only links. The hash value is based
  2142. // on this NormalizedName.
  2143. //
  2144. // The normalized name can be in an indeterminant state. If the length is zero
  2145. // then the name is invalid (there should be no hash value at that point). However
  2146. // the MaximumLength and Buffer could still be present. A non-NULL buffer indicates
  2147. // that there is cleanup that needs to be done. Anybody changing this field should
  2148. // hold the hash mutex, this means swapping the buffers or changing the length field.
  2149. // Anyone changing the name on the file should hold the main resource exclusive of
  2150. // course.
  2151. //
  2152. UNICODE_STRING NormalizedName;
  2153. #ifdef BENL_DBG
  2154. UNICODE_STRING NormalizedRelativeName;
  2155. ULONG FullNormalizedPathLength;
  2156. #endif
  2157. ULONG HashValue;
  2158. //
  2159. // A change count incremented every time an index buffer is deleted.
  2160. //
  2161. ULONG ChangeCount;
  2162. //
  2163. // Define a union to distinguish directory indices from view indices
  2164. //
  2165. union {
  2166. //
  2167. // For directories we store the following.
  2168. //
  2169. struct {
  2170. //
  2171. // Type of attribute being indexed.
  2172. //
  2173. union {
  2174. ATTRIBUTE_TYPE_CODE AttributeBeingIndexed;
  2175. PVOID Alignment;
  2176. };
  2177. //
  2178. // Collation rule, for how the indexed attribute is collated.
  2179. //
  2180. ULONG_PTR CollationRule;
  2181. };
  2182. //
  2183. // For view indexes we store the CollationFunction and data.
  2184. //
  2185. struct {
  2186. PCOLLATION_FUNCTION CollationFunction;
  2187. PVOID CollationData;
  2188. };
  2189. };
  2190. //
  2191. // Size of Index Allocation Buffer in bytes, or 0 if not yet
  2192. // initialized.
  2193. //
  2194. ULONG BytesPerIndexBuffer;
  2195. //
  2196. // Size of Index Allocation Buffers in units of blocks, or 0
  2197. // if not yet initialized.
  2198. //
  2199. UCHAR BlocksPerIndexBuffer;
  2200. //
  2201. // Shift value when converting from index blocks to bytes.
  2202. //
  2203. UCHAR IndexBlockByteShift;
  2204. //
  2205. // Flag to indicate whether the RecordAllocationContext has been
  2206. // initialized or not. If it is not initialized, this means
  2207. // either that there is no external index allocation, or that
  2208. // it simply has not been initialized yet.
  2209. //
  2210. BOOLEAN AllocationInitialized;
  2211. UCHAR PadUchar;
  2212. //
  2213. // Index Depth Hint
  2214. //
  2215. USHORT IndexDepthHint;
  2216. USHORT PadUshort;
  2217. } SCB_INDEX, *PSCB_INDEX;
  2218. typedef struct _SCB_MFT {
  2219. //
  2220. // NOTE - The following fields must be in the same positions in the Index and Mft
  2221. // specific extensions.
  2222. //
  2223. // RecentlyDeallocatedQueue
  2224. // RecordAllocationContext
  2225. //
  2226. //
  2227. // This is a list of records within the Mft Scb stream which
  2228. // have been deallocated in the current transaction.
  2229. //
  2230. LIST_ENTRY RecentlyDeallocatedQueue;
  2231. //
  2232. // Record allocation context, for managing the allocation of the
  2233. // INDEX_ALLOCATION_ATTRIBUTE, if one exists.
  2234. //
  2235. RECORD_ALLOCATION_CONTEXT RecordAllocationContext;
  2236. //
  2237. // The following Mcb's are used to track clusters being added and
  2238. // removed from the Mcb for the Scb. This Scb must always be fully
  2239. // loaded after an abort. We can't depend on reloading on the next
  2240. // LookupAllocation call. Instead we keep one Mcb with the clusters
  2241. // added and one Mcb with the clusters removed. During the restore
  2242. // phase of abort we will adjust the Mft Mcb by reversing the
  2243. // operations done during the transactions.
  2244. //
  2245. LARGE_MCB AddedClusters;
  2246. LARGE_MCB RemovedClusters;
  2247. //
  2248. // The following are the changes made to the Mft file as file records
  2249. // are added, freed or allocated. Also the change in the number of
  2250. // file records which are part of holes.
  2251. //
  2252. LONG FreeRecordChange;
  2253. LONG HoleRecordChange;
  2254. //
  2255. // The following field contains the index of a reserved free record. To
  2256. // keep us out of the chicken & egg problem of the Mft being able to
  2257. // be self mapping we added the ability to reserve an mft record
  2258. // to describe additional mft data allocation within previous mft
  2259. // run. A value of zero means that index has not been reserved.
  2260. //
  2261. ULONG ReservedIndex;
  2262. ULONG PadUlong;
  2263. } SCB_MFT, *PSCB_MFT;
  2264. //
  2265. // The following is the non-paged part of the scb.
  2266. //
  2267. typedef struct _SCB_NONPAGED {
  2268. //
  2269. // Type and size of this record must be NTFS_NTC_SCB_NONPAGED
  2270. //
  2271. NODE_TYPE_CODE NodeTypeCode;
  2272. NODE_BYTE_SIZE NodeByteSize;
  2273. //
  2274. // Index allocated for this file in the Open Attribute Table.
  2275. //
  2276. ULONG OpenAttributeTableIndex;
  2277. ULONG OnDiskOatIndex;
  2278. //
  2279. // The following field contains a record of special pointers used by
  2280. // MM and Cache to manipluate section objects. Note that the values
  2281. // are set outside of the file system. However the file system on an
  2282. // open/create will set the file object's SectionObject field to
  2283. // point to this field
  2284. //
  2285. SECTION_OBJECT_POINTERS SegmentObject;
  2286. //
  2287. // Copy of the Vcb pointer so we can find the Vcb in the dirty page
  2288. // callback routine.
  2289. //
  2290. PVCB Vcb;
  2291. #ifdef COMPRESS_ON_WIRE
  2292. SECTION_OBJECT_POINTERS SegmentObjectC;
  2293. #endif
  2294. } SCB_NONPAGED, *PSCB_NONPAGED;
  2295. //
  2296. // The following are structures used only in syscache debugging privates
  2297. //
  2298. #define SCE_VDL_CHANGE 0
  2299. #define SCE_ZERO_NC 1
  2300. #define SCE_ZERO_C 2
  2301. #define SCE_READ 3
  2302. #define SCE_WRITE 4
  2303. #define SCE_ZERO_CAV 5
  2304. #define SCE_ZERO_MF 6
  2305. #define SCE_ZERO_FST 7
  2306. #define SCE_CC_FLUSH 8
  2307. #define SCE_CC_FLUSH_AND_PURGE 9
  2308. #define SCE_WRITE_FILE_SIZES 10
  2309. #define SCE_ADD_ALLOCATION 11
  2310. #define SCE_ADD_SP_ALLOCATION 12
  2311. #define SCE_SETCOMP_ADD_ALLOCATION 13
  2312. #define SCE_SETSPARSE_ADD_ALLOCATION 14
  2313. #define SCE_MOD_ATTR_ADD_ALLOCATION 15
  2314. #define SCE_REALLOC1 16
  2315. #define SCE_REALLOC2 17
  2316. #define SCE_REALLOC3 18
  2317. #define SCE_SETCOMPRESS 19
  2318. #define SCE_SETSPARSE 20
  2319. #define SCE_ZERO_STREAM 21
  2320. #define SCE_VDD_CHANGE 22
  2321. #define SCE_CC_SET_SIZE 23
  2322. #define SCE_ZERO_TAIL_COMPRESSED 24
  2323. #define SCE_ZERO_HEAD_COMPRESSED 25
  2324. #define SCE_TRIM_WRITE 26
  2325. #define SCE_DISK_FULL 27
  2326. #define SCE_SKIP_PURGE 28
  2327. #define SCE_ZERO_HEAD_SECTOR 29
  2328. #define SCE_MAX_EVENT 30
  2329. #define SCE_FLAG_WRITE 0x1
  2330. #define SCE_FLAG_READ 0x2
  2331. #define SCE_FLAG_PAGING 0x4
  2332. #define SCE_FLAG_ASYNC 0x8
  2333. #define SCE_FLAG_SET_ALLOC 0x10
  2334. #define SCE_FLAG_SET_EOF 0x20
  2335. #define SCE_FLAG_CANT_WAIT 0x40
  2336. #define SCE_FLAG_SYNC_PAGING 0x80
  2337. #define SCE_FLAG_LAZY_WRITE 0x100
  2338. #define SCE_FLAG_CACHED 0x200
  2339. #define SCE_FLAG_ON_DISK_READ 0x400
  2340. #define SCE_FLAG_RECURSIVE 0x800
  2341. #define SCE_FLAG_NON_CACHED 0x1000
  2342. #define SCE_FLAG_UPDATE_FROM_DISK 0x2000
  2343. #define SCE_FLAG_SET_VDL 0x4000
  2344. #define SCE_FLAG_COMPLETION 0x8000
  2345. #define SCE_FLAG_COMPRESSED 0x10000
  2346. #define SCE_FLAG_FASTIO 0x20000
  2347. #define SCE_FLAG_ZERO 0x40000
  2348. #define SCE_FLAG_PREPARE_BUFFERS 0x80000
  2349. #define SCE_FLAG_END_BUFFER 0x100000
  2350. #define SCE_FLAG_MDL 0x200000
  2351. #define SCE_FLAG_SUB_WRITE 0x400000
  2352. #define SCE_MAX_FLAG 0x800000
  2353. #define NUM_SC_EVENTS 100
  2354. #define NUM_SC_LOGSETS 35
  2355. typedef struct _SYSCACHE_LOG {
  2356. int Event;
  2357. int Flags;
  2358. LONGLONG Start;
  2359. LONGLONG Range;
  2360. LONGLONG Result;
  2361. // ULONG ulDump;
  2362. } SYSCACHE_LOG, *PSYSCACHE_LOG;
  2363. typedef struct _ON_DISK_SYSCACHE_LOG {
  2364. ULONG SegmentNumberUnsafe;
  2365. SYSCACHE_LOG;
  2366. } ON_DISK_SYSCACHE_LOG, *PON_DISK_SYSCACHE_LOG;
  2367. typedef struct _SYSCACHE_LOG_SET {
  2368. PSCB Scb;
  2369. PSYSCACHE_LOG SyscacheLog;
  2370. ULONG SegmentNumberUnsafe;
  2371. } SYSCACHE_LOG_SET, PSYSCACHE_LOG_SET;
  2372. #if defined( SYSCACHE_DEBUG ) || defined( SYSCACHE_DEBUG_ALLOC )
  2373. //
  2374. // Global set of syscache logs
  2375. //
  2376. SYSCACHE_LOG_SET NtfsSyscacheLogSet[NUM_SC_LOGSETS];
  2377. LONG NtfsCurrentSyscacheLogSet;
  2378. LONG NtfsCurrentSyscacheOnDiskEntry;
  2379. #endif
  2380. //
  2381. // The following structure is the stream control block. There can
  2382. // be multiple records per fcb. One is created for each attribute being
  2383. // handled as a stream file.
  2384. //
  2385. typedef struct _SCB {
  2386. //
  2387. // The following field is used for fast I/O. It contains the node
  2388. // type code and size, indicates if fast I/O is possible, contains
  2389. // allocation, file, and valid data size, a resource, and call back
  2390. // pointers for FastIoRead and FastMdlRead.
  2391. //
  2392. // The node type codes for the Scb must be either NTFS_NTC_SCB_INDEX,
  2393. // NTFS_NTC_SCB_ROOT_INDEX, or NTFS_NTC_SCB_DATA. Which one it is
  2394. // determines the state of the union below.
  2395. //
  2396. NTFS_ADVANCED_FCB_HEADER Header;
  2397. //
  2398. // The links for the queue of Scb off of a given Fcb. And a pointer
  2399. // back to the Fcb. Corresponds to Fcb->ScbQueue
  2400. //
  2401. LIST_ENTRY FcbLinks;
  2402. PFCB Fcb;
  2403. //
  2404. // A pointer to the Vcb containing this Scb
  2405. //
  2406. PVCB Vcb;
  2407. //
  2408. // The internal state of the Scb.
  2409. //
  2410. ULONG ScbState;
  2411. //
  2412. // A count of the number of file objects opened on this stream
  2413. // which represent user non-cached handles. We use this count to
  2414. // determine when to flush and purge the data section in only
  2415. // non-cached handles remain on the file.
  2416. //
  2417. CLONG NonCachedCleanupCount;
  2418. //
  2419. // A count of the number of file objects that have been opened for
  2420. // this attribute, but not yet been cleaned up yet.
  2421. // This count gets decremented in NtfsCommonCleanup,
  2422. // while the CloseCount below gets decremented in NtfsCommonClose.
  2423. //
  2424. CLONG CleanupCount;
  2425. //
  2426. // A count of the number of file objects that have opened
  2427. // this attribute.
  2428. //
  2429. CLONG CloseCount;
  2430. //
  2431. // Share Access structure for this stream.
  2432. //
  2433. SHARE_ACCESS ShareAccess;
  2434. //
  2435. // The following two fields identify the actual attribute for this
  2436. // Scb with respect to its file. We identify the attribute by
  2437. // its type code and name.
  2438. //
  2439. ATTRIBUTE_TYPE_CODE AttributeTypeCode;
  2440. UNICODE_STRING AttributeName;
  2441. //
  2442. // Stream File Object for internal use. This field is NULL if the
  2443. // file stream is not being accessed internally.
  2444. //
  2445. PFILE_OBJECT FileObject;
  2446. //
  2447. // These pointers are used to detect writes that eminated from the
  2448. // cache manager's worker thread. It prevents lazy writer threads,
  2449. // who already have the Fcb shared, from trying to acquire it
  2450. // exclusive, and thus causing a deadlock. We have to store two
  2451. // threads, because the second thread could be writing the compressed
  2452. // stream
  2453. //
  2454. #ifdef COMPRESS_ON_WIRE
  2455. PVOID LazyWriteThread[2];
  2456. #endif
  2457. //
  2458. // Pointer to the non-paged section objects and open attribute
  2459. // table index.
  2460. //
  2461. PSCB_NONPAGED NonpagedScb;
  2462. //
  2463. // The following field contains the mcb for this Scb and some initial
  2464. // structures for small and medium files.
  2465. //
  2466. NTFS_MCB Mcb;
  2467. NTFS_MCB_INITIAL_STRUCTS McbStructs;
  2468. //
  2469. // Compression unit from attribute record.
  2470. //
  2471. ULONG CompressionUnit;
  2472. //
  2473. // AttributeFlags and CompressionUnitShift from attribute record
  2474. //
  2475. USHORT AttributeFlags;
  2476. UCHAR CompressionUnitShift;
  2477. UCHAR PadUchar;
  2478. //
  2479. // Valid Data to disk - as updated by NtfsPrepareBuffers
  2480. //
  2481. LONGLONG ValidDataToDisk;
  2482. //
  2483. // Actual allocated bytes for this file.
  2484. //
  2485. LONGLONG TotalAllocated;
  2486. //
  2487. // Used by advanced Scb Header
  2488. //
  2489. LIST_ENTRY EofListHead;
  2490. //
  2491. // Link of all Ccb's that were created for this Scb
  2492. //
  2493. LIST_ENTRY CcbQueue;
  2494. //
  2495. // Pointer to structure containing snapshotted Scb values, or NULL
  2496. // if the values have not been snapshotted.
  2497. //
  2498. struct _SCB_SNAPSHOT * ScbSnapshot;
  2499. //
  2500. // Pointer to encryption context and length.
  2501. //
  2502. PVOID EncryptionContext;
  2503. ULONG EncryptionContextLength;
  2504. //
  2505. // Persistent Scb flags. These are set and cleared synchronized with
  2506. // the main resource and tend to remain in the same state.
  2507. //
  2508. ULONG ScbPersist;
  2509. #if (DBG || defined( NTFS_FREE_ASSERTS ))
  2510. //
  2511. // Keep the thread ID of the thread owning IO at EOF.
  2512. //
  2513. PERESOURCE_THREAD IoAtEofThread;
  2514. #endif
  2515. #ifdef SYSCACHE_DEBUG
  2516. int SyscacheLogEntryCount;
  2517. LONG CurrentSyscacheLogEntry;
  2518. SYSCACHE_LOG * SyscacheLog;
  2519. LONG LogSetNumber;
  2520. #endif
  2521. //
  2522. // Scb Type union, for different types of Scbs
  2523. //
  2524. union {
  2525. SCB_DATA Data;
  2526. SCB_INDEX Index;
  2527. SCB_MFT Mft;
  2528. } ScbType;
  2529. } SCB;
  2530. typedef SCB *PSCB;
  2531. #define SIZEOF_SCB_DATA \
  2532. (FIELD_OFFSET(SCB,ScbType)+sizeof(SCB_DATA))
  2533. #define SIZEOF_SCB_INDEX \
  2534. (FIELD_OFFSET(SCB,ScbType)+sizeof(SCB_INDEX))
  2535. #define SIZEOF_SCB_MFT \
  2536. (FIELD_OFFSET(SCB,ScbType)+sizeof(SCB_MFT))
  2537. //
  2538. // The following flags are bits in the ScbState field.
  2539. //
  2540. #define SCB_STATE_TRUNCATE_ON_CLOSE (0x00000001)
  2541. #define SCB_STATE_DELETE_ON_CLOSE (0x00000002)
  2542. #define SCB_STATE_CHECK_ATTRIBUTE_SIZE (0x00000004)
  2543. #define SCB_STATE_ATTRIBUTE_RESIDENT (0x00000008)
  2544. #define SCB_STATE_UNNAMED_DATA (0x00000010)
  2545. #define SCB_STATE_HEADER_INITIALIZED (0x00000020)
  2546. #define SCB_STATE_NONPAGED (0x00000040)
  2547. #define SCB_STATE_USA_PRESENT (0x00000080)
  2548. #define SCB_STATE_ATTRIBUTE_DELETED (0x00000100)
  2549. #define SCB_STATE_FILE_SIZE_LOADED (0x00000200)
  2550. #define SCB_STATE_MODIFIED_NO_WRITE (0x00000400)
  2551. #define SCB_STATE_SUBJECT_TO_QUOTA (0x00000800)
  2552. #define SCB_STATE_UNINITIALIZE_ON_RESTORE (0x00001000)
  2553. #define SCB_STATE_RESTORE_UNDERWAY (0x00002000)
  2554. #define SCB_STATE_NOTIFY_ADD_STREAM (0x00004000)
  2555. #define SCB_STATE_NOTIFY_REMOVE_STREAM (0x00008000)
  2556. #define SCB_STATE_NOTIFY_RESIZE_STREAM (0x00010000)
  2557. #define SCB_STATE_NOTIFY_MODIFY_STREAM (0x00020000)
  2558. #define SCB_STATE_TEMPORARY (0x00040000)
  2559. #define SCB_STATE_WRITE_COMPRESSED (0x00080000)
  2560. #define SCB_STATE_REALLOCATE_ON_WRITE (0x00100000)
  2561. #define SCB_STATE_DELAY_CLOSE (0x00200000)
  2562. #define SCB_STATE_WRITE_ACCESS_SEEN (0x00400000)
  2563. #define SCB_STATE_CONVERT_UNDERWAY (0x00800000)
  2564. #define SCB_STATE_VIEW_INDEX (0x01000000)
  2565. #define SCB_STATE_DELETE_COLLATION_DATA (0x02000000)
  2566. #define SCB_STATE_VOLUME_DISMOUNTED (0x04000000)
  2567. #define SCB_STATE_PROTECT_SPARSE_MCB (0x08000000)
  2568. #define SCB_STATE_MULTIPLE_OPENS (0x10000000)
  2569. #define SCB_STATE_COMPRESSION_CHANGE (0x20000000)
  2570. #define SCB_STATE_WRITE_FILESIZE_ON_CLOSE (0x40000000)
  2571. //
  2572. // The following flags are bits in the ScbPersist field.
  2573. //
  2574. #define SCB_PERSIST_USN_JOURNAL (0x00000001)
  2575. #define SCB_PERSIST_DENY_DEFRAG (0x00000002)
  2576. #ifdef SYSCACHE_DEBUG
  2577. #define SCB_PERSIST_SYSCACHE_DIR (0x80000000)
  2578. #endif
  2579. #ifdef SYSCACHE
  2580. //
  2581. // Note: this flag's value is now superseded by SCB_STATE_WRITE_FILESIZE_ON_CLOSE
  2582. // code must be modified if this is to be used again
  2583. //
  2584. #define SCB_STATE_SYSCACHE_FILE (0x80000000)
  2585. #define SYSCACHE_SET_FILE_SIZE (0x00000001)
  2586. #define SYSCACHE_SET_ALLOCATION_SIZE (0x00000002)
  2587. #define SYSCACHE_PAGING_WRITE (0x00000003)
  2588. #define SYSCACHE_NORMAL_WRITE (0x00000004)
  2589. //
  2590. // Syscache event list element.
  2591. //
  2592. typedef struct _SYSCACHE_EVENT {
  2593. //
  2594. // Corresponds to scb_data's SyscacheEventList
  2595. //
  2596. LIST_ENTRY EventList;
  2597. //
  2598. // Choose from SYSCACHE_PAGING_WRITE, etc.
  2599. //
  2600. ULONG EventTypeCode;
  2601. ULONG Pad;
  2602. //
  2603. // Write start & size, or truncate point & junk, etc. Unionize?
  2604. //
  2605. LONGLONG Data1;
  2606. LONGLONG Data2;
  2607. } SYSCACHE_EVENT;
  2608. typedef SYSCACHE_EVENT *PSYSCACHE_EVENT;
  2609. #endif
  2610. //
  2611. // Determine whether an attribute type code can be compressed. The current
  2612. // implementation of Ntfs does not allow logged streams to be compressed.
  2613. //
  2614. #define NtfsIsTypeCodeCompressible(C) ((C) == $DATA)
  2615. //
  2616. // Determine whether an attribute type code can be encrypted. The current
  2617. // implementation of Ntfs does not allow logged streams to be encrypted.
  2618. //
  2619. #define NtfsIsTypeCodeEncryptible(C) ((C) == $DATA)
  2620. //
  2621. // Detect whether an attribute contains user data
  2622. //
  2623. #define NtfsIsTypeCodeUserData(C) ((C) == $DATA)
  2624. //
  2625. // Detect whether an attribute should be subject to quota enforcement
  2626. //
  2627. #define NtfsIsTypeCodeSubjectToQuota(C) NtfsIsTypeCodeUserData(C)
  2628. //
  2629. // Detect whether an attribute is a logged utility stream
  2630. //
  2631. #define NtfsIsTypeCodeLoggedUtilityStream(C) ((C) == $LOGGED_UTILITY_STREAM)
  2632. //
  2633. // Define FileObjectFlags flags that should be propagated to stream files
  2634. // so that the Cache Manager will see them.
  2635. //
  2636. #define NTFS_FO_PROPAGATE_TO_STREAM (FO_SEQUENTIAL_ONLY | FO_TEMPORARY_FILE)
  2637. //
  2638. // Structure to contain snapshotted Scb values for error recovery.
  2639. //
  2640. typedef struct _SCB_SNAPSHOT {
  2641. //
  2642. // Links for list snapshot structures off of IrpContext
  2643. //
  2644. LIST_ENTRY SnapshotLinks;
  2645. //
  2646. // Saved values of the corresponding Scb (or FsRtl Header) fields
  2647. // The low bit of allocation size is set to remember when the
  2648. // attribute was resident. The next bit, bit 1, is set to remember
  2649. // when the attribute was compressed.
  2650. //
  2651. LONGLONG AllocationSize;
  2652. LONGLONG FileSize;
  2653. LONGLONG ValidDataLength;
  2654. LONGLONG ValidDataToDisk;
  2655. LONGLONG TotalAllocated;
  2656. VCN LowestModifiedVcn;
  2657. VCN HighestModifiedVcn;
  2658. //
  2659. // Pointer to the Scb which has been snapped.
  2660. //
  2661. PSCB Scb;
  2662. //
  2663. // Used to hold the Scb State.
  2664. //
  2665. ULONG ScbState;
  2666. //
  2667. // IrpContext that owns the snapshot and can use it to rollback the values
  2668. //
  2669. PIRP_CONTEXT OwnerIrpContext;
  2670. } SCB_SNAPSHOT;
  2671. typedef SCB_SNAPSHOT *PSCB_SNAPSHOT;
  2672. //
  2673. // The Ccb record is allocated for every file object. This is the full
  2674. // CCB including the index-specific fields.
  2675. //
  2676. typedef struct _CCB {
  2677. //
  2678. // Type and size of this record (must be NTFS_NTC_CCB_DATA or
  2679. // NTFS_NTC_CCB_INDEX)
  2680. //
  2681. NODE_TYPE_CODE NodeTypeCode;
  2682. NODE_BYTE_SIZE NodeByteSize;
  2683. //
  2684. // Ccb flags.
  2685. //
  2686. ULONG Flags;
  2687. //
  2688. // This is a unicode string for the full filename used to
  2689. // open this file.
  2690. // We use InterlockedExchange of pointers to synchronize this
  2691. // field between NtfsFsdClose and NtfsUpdateFileDupInfo.
  2692. //
  2693. UNICODE_STRING FullFileName;
  2694. USHORT LastFileNameOffset;
  2695. //
  2696. // This is the Ccb Ea modification count. If this count is in
  2697. // sync with the Fcb value, then the above offset is valid.
  2698. //
  2699. USHORT EaModificationCount;
  2700. //
  2701. // This is the offset of the next Ea to return to the user.
  2702. //
  2703. ULONG NextEaOffset;
  2704. //
  2705. // The links for the queue of Ccb off of a given Lcb and a pointer
  2706. // back to the Lcb. Corresponds to Lcb->CcbQueue
  2707. //
  2708. LIST_ENTRY LcbLinks;
  2709. PLCB Lcb;
  2710. //
  2711. // The links for the queue of Ccb's off a given Scb. Corresponds to
  2712. // Scb->CcbQueue
  2713. //
  2714. LIST_ENTRY CcbLinks;
  2715. //
  2716. // Type of Open for this Ccb
  2717. //
  2718. UCHAR TypeOfOpen;
  2719. UCHAR Reserved;
  2720. //
  2721. // Count of the number of times this handle has extended the stream through
  2722. // writes.
  2723. //
  2724. USHORT WriteExtendCount;
  2725. //
  2726. // Keeps the owner id of the opener. Used by quota to determine the
  2727. // amount of free space.
  2728. //
  2729. ULONG OwnerId;
  2730. //
  2731. // Last returned owner id. Used by QueryQuotaInformationFile.
  2732. //
  2733. ULONG LastOwnerId;
  2734. //
  2735. // Usn source information for this handle.
  2736. //
  2737. ULONG UsnSourceInfo;
  2738. //
  2739. // Flags specifying the type of access granted for this handle.
  2740. // The flags, such as BACKUP_ACCESS, are defined in ntfsexp.h.
  2741. //
  2742. USHORT AccessFlags;
  2743. USHORT Alignment;
  2744. #ifdef CCB_FILE_OBJECT
  2745. PFILE_OBJECT FileObject;
  2746. PEPROCESS Process;
  2747. #endif
  2748. //////////////////////////////////////////////////////////////////////////
  2749. // //
  2750. // READ BELOW BEFORE CHANGING THIS STRUCTURE //
  2751. // //
  2752. // All of the enumeration fields must be after this point. Otherwise //
  2753. // we will waste space in the CCB_DATA defined below. //
  2754. // //
  2755. // Also - The first defined field past this point must be used in //
  2756. // defining the CCB_DATA structure below. //
  2757. // //
  2758. //////////////////////////////////////////////////////////////////////////
  2759. //
  2760. // Pointer to the index context structure for enumerations.
  2761. //
  2762. struct _INDEX_CONTEXT *IndexContext;
  2763. //
  2764. // The query template is used to filter directory query requests.
  2765. // It originally is set to null and on the first call the
  2766. // NtQueryDirectory it is set the the input filename or "*" if no
  2767. // name is supplied. All subsquent queries then use this template.
  2768. //
  2769. ULONG QueryLength;
  2770. PVOID QueryBuffer;
  2771. //
  2772. // The last returned value. A copy of an IndexEntry is saved. We
  2773. // only grow this buffer, to avoid always deallocating and
  2774. // reallocating.
  2775. //
  2776. ULONG IndexEntryLength;
  2777. PINDEX_ENTRY IndexEntry;
  2778. //
  2779. // File reference for file record we need to read for another name,
  2780. // and for which Fcb should be found and acquired when restarting
  2781. // an enumeration.
  2782. //
  2783. union {
  2784. LONGLONG LongValue;
  2785. FILE_REFERENCE FileReference;
  2786. } FcbToAcquire;
  2787. //
  2788. // File reference for next file reference to consider when doing a
  2789. // Mft scan looking for the next file owned by a specified Sid
  2790. //
  2791. FILE_REFERENCE MftScanFileReference;
  2792. //
  2793. // Lists of waiters on this Ccb. A NULL value indicates no waiters.
  2794. //
  2795. LIST_ENTRY EnumQueue;
  2796. } CCB;
  2797. typedef CCB *PCCB;
  2798. //
  2799. // The size of the CCB_DATA is the quadaligned size of the common
  2800. // header.
  2801. //
  2802. // NOTE - This define assumes the first field of the index portion is the
  2803. // IndexContext field.
  2804. //
  2805. typedef struct _CCB_DATA {
  2806. LONGLONG Opaque[ (FIELD_OFFSET( CCB, IndexContext ) + 7) / 8 ];
  2807. } CCB_DATA;
  2808. typedef CCB_DATA *PCCB_DATA;
  2809. #define CCB_FLAG_IGNORE_CASE (0x00000001)
  2810. #define CCB_FLAG_OPEN_AS_FILE (0x00000002)
  2811. #define CCB_FLAG_WILDCARD_IN_EXPRESSION (0x00000004)
  2812. #define CCB_FLAG_OPEN_BY_FILE_ID (0x00000008)
  2813. #define CCB_FLAG_USER_SET_LAST_MOD_TIME (0x00000010)
  2814. #define CCB_FLAG_USER_SET_LAST_CHANGE_TIME (0x00000020)
  2815. #define CCB_FLAG_USER_SET_LAST_ACCESS_TIME (0x00000040)
  2816. #define CCB_FLAG_TRAVERSE_CHECK (0x00000080)
  2817. #define CCB_FLAG_RETURN_DOT (0x00000100)
  2818. #define CCB_FLAG_RETURN_DOTDOT (0x00000200)
  2819. #define CCB_FLAG_DOT_RETURNED (0x00000400)
  2820. #define CCB_FLAG_DOTDOT_RETURNED (0x00000800)
  2821. #define CCB_FLAG_DELETE_FILE (0x00001000)
  2822. #define CCB_FLAG_DENY_DELETE (0x00002000)
  2823. #define CCB_FLAG_ALLOCATED_FILE_NAME (0x00004000)
  2824. #define CCB_FLAG_CLEANUP (0x00008000)
  2825. #define CCB_FLAG_SYSTEM_HIVE (0x00010000)
  2826. #define CCB_FLAG_PARENT_HAS_DOS_COMPONENT (0x00020000)
  2827. #define CCB_FLAG_DELETE_ON_CLOSE (0x00040000)
  2828. #define CCB_FLAG_CLOSE (0x00080000)
  2829. #define CCB_FLAG_UPDATE_LAST_MODIFY (0x00100000)
  2830. #define CCB_FLAG_UPDATE_LAST_CHANGE (0x00200000)
  2831. #define CCB_FLAG_SET_ARCHIVE (0x00400000)
  2832. #define CCB_FLAG_DIR_NOTIFY (0x00800000)
  2833. #define CCB_FLAG_ALLOW_XTENDED_DASD_IO (0x01000000)
  2834. #define CCB_FLAG_READ_CONTEXT_ALLOCATED (0x02000000)
  2835. #define CCB_FLAG_DELETE_ACCESS (0x04000000)
  2836. #define CCB_FLAG_DENY_DEFRAG (0x08000000)
  2837. #define CCB_FLAG_PROTECT_NAME (0x10000000)
  2838. #define CCB_FLAG_FLUSH_VOLUME_ON_IO (0x20000000)
  2839. //
  2840. // Reusing a bit from the file name index enumeration path for the view index path
  2841. //
  2842. #define CCB_FLAG_LAST_INDEX_ROW_RETURNED (0x00000800)
  2843. //
  2844. // We will attempt to allocate the following out of a single pool block
  2845. // on a per file basis.
  2846. //
  2847. // FCB, LCB, SCB, CCB, FILE_NAME
  2848. //
  2849. // The following compound Fcb's will be allocated and then the individual
  2850. // components can be allocated out of them. The FCB will never be allocated
  2851. // individually but it is possible that the embedded structures may be.
  2852. // A zero in the node type field means these are available. These sizes are
  2853. // selected to fill the Fcb out to a pool block boundary (0x20) bytes.
  2854. // Note that we leave room for both the exact and ignore case names.
  2855. //
  2856. #define MAX_DATA_FILE_NAME (17)
  2857. #define MAX_INDEX_FILE_NAME (17)
  2858. typedef struct _FCB_DATA {
  2859. FCB Fcb;
  2860. UCHAR Scb[SIZEOF_SCB_DATA];
  2861. CCB_DATA Ccb;
  2862. UCHAR Lcb[SIZEOF_LCB];
  2863. WCHAR FileName[(2*MAX_DATA_FILE_NAME) - 1];
  2864. } FCB_DATA;
  2865. typedef FCB_DATA *PFCB_DATA;
  2866. typedef struct _FCB_INDEX {
  2867. FCB Fcb;
  2868. UCHAR Scb[SIZEOF_SCB_INDEX];
  2869. CCB Ccb;
  2870. UCHAR Lcb[SIZEOF_LCB];
  2871. WCHAR FileName[(2*MAX_INDEX_FILE_NAME) - 1];
  2872. } FCB_INDEX;
  2873. typedef FCB_INDEX *PFCB_INDEX;
  2874. typedef VOID
  2875. (*POST_SPECIAL_CALLOUT) (
  2876. IN struct _IRP_CONTEXT *IrpContext,
  2877. IN OUT PVOID Context
  2878. );
  2879. //
  2880. // The IrpContext contains a cache of file records mapped within the current
  2881. // call. These are used to reduce the number of maps that take place
  2882. //
  2883. typedef struct _IRP_FILE_RECORD_CACHE_ENTRY {
  2884. PFILE_RECORD_SEGMENT_HEADER FileRecord;
  2885. PBCB FileRecordBcb;
  2886. ULONG UnsafeSegmentNumber;
  2887. } IRP_FILE_RECORD_CACHE_ENTRY, *PIRP_FILE_RECORD_CACHE_ENTRY;
  2888. #define IRP_FILE_RECORD_MAP_CACHE_SIZE 4
  2889. //
  2890. // Chained Usn Fcbs. The IrpContext has a built-in UsnFcb but some requests require more than
  2891. // one. In that case we will allocate and chain these together.
  2892. //
  2893. // The flags field has the following flags
  2894. //
  2895. // USN_FCB_FLAG_NEW_REASON - Indicates that we have something to report via
  2896. // WriteUsnJournalChanges. We need something to indicate whether we have any
  2897. // new reasons since we don't clear out the NewReasons field when writing the
  2898. // USN record so the presence of the reasons isn't enough.
  2899. //
  2900. typedef struct _USN_FCB {
  2901. //
  2902. // Chain to next usnfcb record
  2903. //
  2904. struct _USN_FCB *NextUsnFcb;
  2905. //
  2906. // Info to apply to the new record for the given fcb when its written
  2907. //
  2908. PFCB CurrentUsnFcb;
  2909. ULONG NewReasons;
  2910. ULONG RemovedSourceInfo;
  2911. //
  2912. // Flags - see above
  2913. //
  2914. ULONG UsnFcbFlags;
  2915. //
  2916. // For abort purpose - the old fcb state before we changed it only used if
  2917. // USN_FCB_FLAG_NEW_FCB_STATE flag is set
  2918. //
  2919. ULONG OldFcbState;
  2920. } USN_FCB, *PUSN_FCB;
  2921. //
  2922. // USN_FCB_FLAG_NEW_FCB_STATE tracks whether we changed the fcbstate by growing
  2923. // standard info while writing a usn journal record - we'll need to revert it if
  2924. // transaction aborts
  2925. //
  2926. #define USN_FCB_FLAG_NEW_REASON (0x00000001)
  2927. #define USN_FCB_FLAG_NEW_FCB_STATE (0x00000002)
  2928. //
  2929. // The Irp Context record is allocated for every orginating Irp. It is
  2930. // created by the Fsd dispatch routines, and deallocated by the
  2931. // NtfsComplete request routine.
  2932. //
  2933. typedef struct _IRP_CONTEXT {
  2934. //
  2935. // Type and size of this record (must be NTFS_NTC_IRP_CONTEXT)
  2936. //
  2937. // Assumption here is that this structure is allocated from pool so
  2938. // base of structure is on an odd 64-bit boundary.
  2939. //
  2940. NODE_TYPE_CODE NodeTypeCode;
  2941. NODE_BYTE_SIZE NodeByteSize;
  2942. //
  2943. // State of the operation. These flags describe the current state of a request and
  2944. // are reset on either retry or post.
  2945. //
  2946. ULONG Flags;
  2947. //
  2948. // State of the IrpContext. These are persistent through the life of a request and
  2949. // are explicitly set and cleared.
  2950. //
  2951. ULONG State;
  2952. //
  2953. // The following field contains the NTSTATUS value used when we are
  2954. // unwinding due to an exception. We will temporarily store the Ccb
  2955. // for a delayed or deferred close here while the request is queued.
  2956. //
  2957. NTSTATUS ExceptionStatus;
  2958. //
  2959. // Transaction Id for this request, which must be qualified by Vcb.
  2960. // We will store the type of open for a delayed or async close here
  2961. // while the request is queued.
  2962. //
  2963. TRANSACTION_ID TransactionId;
  2964. //
  2965. // Major and minor function codes copied from the Irp
  2966. //
  2967. UCHAR MajorFunction;
  2968. UCHAR MinorFunction;
  2969. //
  2970. // Length of Scb array for transactions below. Zero indicates unused. One indicates
  2971. // to treat it as a pointer to an Scb. Greater than one indicates it is an allocated
  2972. // pool block with an array of Scb's.
  2973. //
  2974. USHORT SharedScbSize;
  2975. //
  2976. // Pointer to Scb acquired shared for transaction or pointer to array of Scb's acquired
  2977. // shared for transaction. Use the SharedScbSize field above to determine
  2978. // meaning of this pointer.
  2979. //
  2980. PVOID SharedScb;
  2981. //
  2982. // This is a pointer to a structure which requires further cleanup when we cleanup the
  2983. // IrpContext. Currently it can be either an Fcb or Scb.
  2984. //
  2985. // Fcb - We need to release the paging Io resource for this.
  2986. // Scb - We need to clear the IOAtEof flag.
  2987. //
  2988. PVOID CleanupStructure;
  2989. //
  2990. // Vcb for the operation this IrpContext is processing.
  2991. //
  2992. PVCB Vcb;
  2993. //
  2994. // A pointer to the originating Irp. We will store the Scb for
  2995. // delayed or async closes here while the request is queued.
  2996. //
  2997. PIRP OriginatingIrp;
  2998. //
  2999. // This is the IrpContext for the top level request.
  3000. //
  3001. struct _IRP_CONTEXT *TopLevelIrpContext;
  3002. union {
  3003. struct {
  3004. //
  3005. // This is a list of exclusively-owned Scbs which may only be
  3006. // released after the transaction is committed.
  3007. //
  3008. LIST_ENTRY ExclusiveFcbList;
  3009. //
  3010. // The following field is used to maintain a queue of records that
  3011. // have been deallocated while processing this irp context.
  3012. //
  3013. LIST_ENTRY RecentlyDeallocatedQueue;
  3014. };
  3015. //
  3016. // This structure is used for posting to the Ex worker threads.
  3017. //
  3018. WORK_QUEUE_ITEM WorkQueueItem;
  3019. };
  3020. //
  3021. // The following is the number of clusters deallocated in the current
  3022. // request. We want to ignore them when figuring if a request for
  3023. // clusters (NtfsAllocateClusters) should free the clusters in the
  3024. // recently deallocated queue.
  3025. //
  3026. LONGLONG DeallocatedClusters;
  3027. //
  3028. // This is the Last Restart Area Lsn captured from the Vcb at
  3029. // the time log file full was raised. The caller will force
  3030. // a checkpoint if this has not changed by the time he gets
  3031. // the global resource exclusive.
  3032. //
  3033. LSN LastRestartArea;
  3034. //
  3035. // This is the change in the free clusters on the volume during the
  3036. // transaction for this IrpContext. If we abort the current request
  3037. // we will subtract these from the current count of free clusters
  3038. // in the Vcb. This is signed because we may be allocating or
  3039. // deallocating the clusters.
  3040. //
  3041. LONGLONG FreeClusterChange;
  3042. //
  3043. // The following union contains pointers to the IoContext for I/O
  3044. // based requests and a pointer to a security context for requests
  3045. // which need to capture the subject context in the calling thread.
  3046. //
  3047. union {
  3048. //
  3049. // The following context block is used for non-cached Io.
  3050. //
  3051. struct _NTFS_IO_CONTEXT *NtfsIoContext;
  3052. //
  3053. // The following field is used for cached compressed reads/writes
  3054. //
  3055. PFSRTL_AUXILIARY_BUFFER AuxiliaryBuffer;
  3056. //
  3057. // The following is the captured subject context.
  3058. //
  3059. PSECURITY_SUBJECT_CONTEXT SubjectContext;
  3060. //
  3061. // The following is used during create for oplock cleanup.
  3062. //
  3063. struct _OPLOCK_CLEANUP *OplockCleanup;
  3064. //
  3065. // The following is used to transfer the create context between fsp and fsp
  3066. // if a create is posted
  3067. //
  3068. struct _CREATE_CONTEXT *CreateContext;
  3069. //
  3070. // The following is used by NtfsPostSpecial to pass the
  3071. // function to be called.
  3072. //
  3073. POST_SPECIAL_CALLOUT PostSpecialCallout;
  3074. //
  3075. // The following is used by NtfsReadFileRecordUsnData for cleanup
  3076. //
  3077. PMDL MdlToCleanup;
  3078. } Union;
  3079. //
  3080. // Collect all of the streams which have been extended which may have waiters
  3081. // on the new length.
  3082. //
  3083. PVOID CheckNewLength;
  3084. //
  3085. // The Fcb for which some new Usn reasons must be journalled, and the reasons.
  3086. //
  3087. USN_FCB Usn;
  3088. ULONG SourceInfo;
  3089. //
  3090. // This structure contains the first ScbSnapshot for a modifying
  3091. // request which acquires files exclusive and snaps Scb values.
  3092. // If the SnapshotLinks field contains NULLs, then no data has
  3093. // been snapshot for this request, and the list is empty. If
  3094. // the links are not NULL, then this snapshot structure is in
  3095. // use. If the SnapshotLinks are not NULL, and do not represent
  3096. // an empty list, then there are addtional dynamically allocated
  3097. // snapshot structures in this list.
  3098. //
  3099. SCB_SNAPSHOT ScbSnapshot;
  3100. //
  3101. // Some calls require reading the base file record for the specified file
  3102. // multiple times. We cache the pointer to the base file record and the
  3103. // BCB for that file record.
  3104. //
  3105. ULONG CacheCount;
  3106. IRP_FILE_RECORD_CACHE_ENTRY FileRecordCache[IRP_FILE_RECORD_MAP_CACHE_SIZE];
  3107. #ifdef NTFS_LOG_FULL_TEST
  3108. //
  3109. // Debugging field for breadth-first verification of log-file-full. When the
  3110. // NextFailCount is non-zero, we decrement the CurrentFailCount. When
  3111. // CurrentFailCount goes to zero, we increment NextFailCount, set
  3112. // CurrentFailCount to NextFailCount and raise STATUS_LOG_FILE_FULL.
  3113. //
  3114. ULONG CurrentFailCount;
  3115. ULONG NextFailCount;
  3116. #endif
  3117. #ifdef MAPCOUNT_DBG
  3118. ULONG MapCount;
  3119. #endif
  3120. #ifdef NTFSDBG
  3121. ULONG FilesOwnedCount;
  3122. NTFS_OWNERSHIP_STATE OwnershipState;
  3123. #endif
  3124. #ifdef PERF_STATS
  3125. LARGE_INTEGER StartTick;
  3126. ULONG Ios;
  3127. ULONG LogFullReason;
  3128. #endif
  3129. } IRP_CONTEXT;
  3130. typedef IRP_CONTEXT *PIRP_CONTEXT;
  3131. //
  3132. // The following are the Irp Context flags. They will be cleared
  3133. // on either retry or post. If we start to run out of bits then we
  3134. // can combine some of these because they are only tested locally and
  3135. // have the same behavior on retry or post.
  3136. //
  3137. #define IRP_CONTEXT_FLAG_LARGE_ALLOCATION (0x00000001)
  3138. #define IRP_CONTEXT_FLAG_WRITE_SEEN (0x00000002)
  3139. #define IRP_CONTEXT_FLAG_CREATE_MOD_SCB (0x00000004)
  3140. #define IRP_CONTEXT_FLAG_DEFERRED_WRITE (0x00000008)
  3141. #define IRP_CONTEXT_FLAG_EXCESS_LOG_FULL (0x00000010)
  3142. #define IRP_CONTEXT_FLAG_WROTE_LOG (0x00000020)
  3143. #define IRP_CONTEXT_FLAG_MFT_REC_15_USED (0x00000040)
  3144. #define IRP_CONTEXT_FLAG_MFT_REC_RESERVED (0x00000080)
  3145. #define IRP_CONTEXT_FLAG_RAISED_STATUS (0x00000100)
  3146. #define IRP_CONTEXT_FLAG_CALL_SELF (0x00000200)
  3147. #define IRP_CONTEXT_FLAG_DONT_DELETE (0x00000400)
  3148. #define IRP_CONTEXT_FLAG_FORCE_POST (0x00000800)
  3149. #define IRP_CONTEXT_FLAG_MODIFIED_BITMAP (0x00001000)
  3150. #define IRP_CONTEXT_FLAG_RELEASE_USN_JRNL (0x00002000)
  3151. #define IRP_CONTEXT_FLAG_RELEASE_MFT (0x00004000)
  3152. #define IRP_CONTEXT_FLAG_DEFERRED_PUSH (0x00008000)
  3153. #define IRP_CONTEXT_FLAG_ACQUIRE_PAGING (0x00010000)
  3154. #define IRP_CONTEXT_FLAG_HOTFIX_UNDERWAY (0x00020000)
  3155. #define IRP_CONTEXT_FLAG_RETAIN_FLAGS (0x00040000)
  3156. #define IRP_CONTEXT_FLAG_ONLY_SYNCH_CHECKPOINT (0x00080000)
  3157. //
  3158. // The following flags need to be cleared when a request is posted.
  3159. //
  3160. #define IRP_CONTEXT_FLAGS_CLEAR_ON_POST \
  3161. (IRP_CONTEXT_FLAG_LARGE_ALLOCATION | \
  3162. IRP_CONTEXT_FLAG_WRITE_SEEN | \
  3163. IRP_CONTEXT_FLAG_CREATE_MOD_SCB | \
  3164. IRP_CONTEXT_FLAG_EXCESS_LOG_FULL | \
  3165. IRP_CONTEXT_FLAG_WROTE_LOG | \
  3166. IRP_CONTEXT_FLAG_MFT_REC_15_USED | \
  3167. IRP_CONTEXT_FLAG_MFT_REC_RESERVED | \
  3168. IRP_CONTEXT_FLAG_RAISED_STATUS | \
  3169. IRP_CONTEXT_FLAG_CALL_SELF | \
  3170. IRP_CONTEXT_FLAG_DONT_DELETE | \
  3171. IRP_CONTEXT_FLAG_FORCE_POST | \
  3172. IRP_CONTEXT_FLAG_MODIFIED_BITMAP | \
  3173. IRP_CONTEXT_FLAG_RELEASE_USN_JRNL | \
  3174. IRP_CONTEXT_FLAG_RELEASE_MFT | \
  3175. IRP_CONTEXT_FLAG_DEFERRED_PUSH | \
  3176. IRP_CONTEXT_FLAG_ACQUIRE_PAGING | \
  3177. IRP_CONTEXT_FLAG_HOTFIX_UNDERWAY | \
  3178. IRP_CONTEXT_FLAG_RETAIN_FLAGS)
  3179. //
  3180. // The following flags need to be cleared when a request is retried.
  3181. //
  3182. #define IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY \
  3183. (IRP_CONTEXT_FLAG_LARGE_ALLOCATION | \
  3184. IRP_CONTEXT_FLAG_WRITE_SEEN | \
  3185. IRP_CONTEXT_FLAG_CREATE_MOD_SCB | \
  3186. IRP_CONTEXT_FLAG_DEFERRED_WRITE | \
  3187. IRP_CONTEXT_FLAG_EXCESS_LOG_FULL | \
  3188. IRP_CONTEXT_FLAG_WROTE_LOG | \
  3189. IRP_CONTEXT_FLAG_MFT_REC_15_USED | \
  3190. IRP_CONTEXT_FLAG_MFT_REC_RESERVED | \
  3191. IRP_CONTEXT_FLAG_RAISED_STATUS | \
  3192. IRP_CONTEXT_FLAG_CALL_SELF | \
  3193. IRP_CONTEXT_FLAG_DONT_DELETE | \
  3194. IRP_CONTEXT_FLAG_FORCE_POST | \
  3195. IRP_CONTEXT_FLAG_MODIFIED_BITMAP | \
  3196. IRP_CONTEXT_FLAG_RELEASE_USN_JRNL | \
  3197. IRP_CONTEXT_FLAG_RELEASE_MFT | \
  3198. IRP_CONTEXT_FLAG_DEFERRED_PUSH | \
  3199. IRP_CONTEXT_FLAG_ACQUIRE_PAGING | \
  3200. IRP_CONTEXT_FLAG_RETAIN_FLAGS)
  3201. //
  3202. // State flags. IrpContext flags which span the life of an IrpContext
  3203. // and must be explicitly set and cleared. If we start to run out
  3204. // of these some of them can be shared be they are only tested
  3205. // in specific operations.
  3206. //
  3207. #define IRP_CONTEXT_STATE_WAIT (0x00000001) // Specifically 1 so we don't have to cast to boolean.
  3208. #define IRP_CONTEXT_STATE_EFS_CREATE (0x00000002)
  3209. #define IRP_CONTEXT_STATE_FAILED_CLOSE (0x00000004)
  3210. #define IRP_CONTEXT_STATE_WRITE_THROUGH (0x00000008)
  3211. #define IRP_CONTEXT_STATE_ALLOC_IO_CONTEXT (0x00000010)
  3212. #define IRP_CONTEXT_STATE_ALLOC_SECURITY (0x00000020)
  3213. #define IRP_CONTEXT_STATE_IN_FSP (0x00000040)
  3214. #define IRP_CONTEXT_STATE_IN_TEARDOWN (0x00000080)
  3215. #define IRP_CONTEXT_STATE_ACQUIRE_EX (0x00000100)
  3216. #define IRP_CONTEXT_STATE_DASD_OPEN (0x00000200)
  3217. #define IRP_CONTEXT_STATE_DASD_UNLOCK (0x00000200) // overloaded
  3218. #define IRP_CONTEXT_STATE_QUOTA_DISABLE (0x00000400)
  3219. #define IRP_CONTEXT_STATE_LAZY_WRITE (0x00000800)
  3220. #define IRP_CONTEXT_STATE_CHECKPOINT_ACTIVE (0x00001000)
  3221. #define IRP_CONTEXT_STATE_FORCE_PUSH (0x00002000)
  3222. #define IRP_CONTEXT_STATE_READ_ONLY_FO (0x00004000)
  3223. #define IRP_CONTEXT_STATE_VOL_UPGR_FAILED (0x00008000)
  3224. #define IRP_CONTEXT_STATE_PERSISTENT (0x00010000)
  3225. #define IRP_CONTEXT_STATE_WRITING_AT_EOF (0x00020000)
  3226. #define IRP_CONTEXT_STATE_DISMOUNT_LOG_FLUSH (0x00040000)
  3227. #define IRP_CONTEXT_STATE_ALLOC_FROM_POOL (0x00080000)
  3228. #define IRP_CONTEXT_STATE_OWNS_TOP_LEVEL (0x00100000)
  3229. #define IRP_CONTEXT_STATE_ENCRYPTION_RETRY (0x00200000)
  3230. #define IRP_CONTEXT_STATE_ALLOC_MDL (0x00400000)
  3231. #define IRP_CONTEXT_STATE_BAD_RESTART (0x00800000)
  3232. #define IRP_CONTEXT_STATE_NO_FAILURES_EXPECTED (0x02000000)
  3233. #ifdef PERF_STATS
  3234. #define IRP_CONTEXT_STATE_TRACK_IOS (0x04000000)
  3235. #endif
  3236. //
  3237. // The top level context is used to determine whether this request has
  3238. // other requests below it on the stack.
  3239. //
  3240. typedef struct _TOP_LEVEL_CONTEXT {
  3241. BOOLEAN TopLevelRequest;
  3242. BOOLEAN ValidSavedTopLevel;
  3243. BOOLEAN OverflowReadThread;
  3244. ULONG Ntfs;
  3245. VCN VboBeingHotFixed;
  3246. PSCB ScbBeingHotFixed;
  3247. PIRP SavedTopLevelIrp;
  3248. PIRP_CONTEXT ThreadIrpContext;
  3249. } TOP_LEVEL_CONTEXT;
  3250. typedef TOP_LEVEL_CONTEXT *PTOP_LEVEL_CONTEXT;
  3251. //
  3252. // The found attribute part of the attribute enumeration context
  3253. // describes an attribute record that had been located or created. It
  3254. // may refer to either a base or attribute list.
  3255. //
  3256. typedef struct _FOUND_ATTRIBUTE {
  3257. //
  3258. // The following identify the attribute which was mapped. These are
  3259. // necessary if forcing the range of bytes into memory by pinning.
  3260. // These include the Bcb on which the attribute was read (if this
  3261. // field is NULL, this is the initial attribute) and the offset of
  3262. // the record segment in the Mft.
  3263. //
  3264. LONGLONG MftFileOffset;
  3265. //
  3266. // Pointer to the Attribute Record
  3267. //
  3268. PATTRIBUTE_RECORD_HEADER Attribute;
  3269. //
  3270. // Pointer to the containing record segment.
  3271. //
  3272. PFILE_RECORD_SEGMENT_HEADER FileRecord;
  3273. //
  3274. // Bcb for mapped/pinned FileRecord
  3275. //
  3276. PBCB Bcb;
  3277. //
  3278. // Some state information.
  3279. //
  3280. BOOLEAN AttributeDeleted;
  3281. } FOUND_ATTRIBUTE;
  3282. typedef FOUND_ATTRIBUTE *PFOUND_ATTRIBUTE;
  3283. //
  3284. // The structure guides enumeration through the attribute list.
  3285. //
  3286. typedef struct _ATTRIBUTE_LIST_CONTEXT {
  3287. //
  3288. // This points to the first attribute list entry; it is advanced
  3289. // when we are searching for a particular exteral attribute.
  3290. //
  3291. PATTRIBUTE_LIST_ENTRY Entry;
  3292. //
  3293. // A Bcb for the attribute list.
  3294. //
  3295. PBCB Bcb;
  3296. //
  3297. // This field is used to remember the location of the Attribute
  3298. // List attribute within the base file record, if existent.
  3299. //
  3300. PATTRIBUTE_RECORD_HEADER AttributeList;
  3301. //
  3302. // This points to the first entry in the attribute list. This is
  3303. // needed when the attribute list is non-resident.
  3304. //
  3305. PATTRIBUTE_LIST_ENTRY FirstEntry;
  3306. //
  3307. // This points just beyond the final attribute list entry.
  3308. //
  3309. PATTRIBUTE_LIST_ENTRY BeyondFinalEntry;
  3310. //
  3311. // This is the Bcb for the data portion of a non-resident attribute.
  3312. //
  3313. PBCB NonresidentListBcb;
  3314. } ATTRIBUTE_LIST_CONTEXT;
  3315. typedef ATTRIBUTE_LIST_CONTEXT *PATTRIBUTE_LIST_CONTEXT;
  3316. //
  3317. // The Attribute Enumeration Context structure returns information on an
  3318. // attribute which has been found by one of the Attribute Lookup or
  3319. // Creation routines. It is also used as an IN OUT structure to perform
  3320. // further lookups/modifications to attributes. It does not have a node
  3321. // type code and size since it is usually allocated on the caller's
  3322. // stack.
  3323. //
  3324. typedef struct _ATTRIBUTE_ENUMERATION_CONTEXT {
  3325. //
  3326. // Contains the actual attribute we found.
  3327. //
  3328. FOUND_ATTRIBUTE FoundAttribute;
  3329. //
  3330. // Allows enumeration through the attribute list.
  3331. //
  3332. ATTRIBUTE_LIST_CONTEXT AttributeList;
  3333. } ATTRIBUTE_ENUMERATION_CONTEXT;
  3334. typedef ATTRIBUTE_ENUMERATION_CONTEXT *PATTRIBUTE_ENUMERATION_CONTEXT;
  3335. //
  3336. // Define struct which will be used to remember the path that was
  3337. // followed to locate a given INDEX_ENTRY or insertion point for an
  3338. // INDEX_ENTRY. This structure is always filled in by LookupIndexEntry.
  3339. //
  3340. // The Index Lookup Stack is generally allocated as a local variable in
  3341. // one of the routines in this module that may be called from another
  3342. // module. A pointer to this stack is then passed in to some of the
  3343. // internal routines.
  3344. //
  3345. // The first entry in the stack describes context in the INDEX attribute
  3346. // in the file record, and all subsequent stack entries refer to Index
  3347. // buffers in the INDEX_ALLOCATION attribute.
  3348. //
  3349. // Outside of indexsup.c, this structure should only be passed as an
  3350. // "opaque" context, and individual fields should not be referenced.
  3351. //
  3352. typedef struct _INDEX_LOOKUP_STACK {
  3353. //
  3354. // Bcb pointer for the Index Buffer. In the "bottom" (first entry)
  3355. // of the stack this field contains a NULL, and the Bcb must be found
  3356. // via the Attribute Enumeration Context.
  3357. //
  3358. PBCB Bcb;
  3359. //
  3360. // Pointer to the start of the File Record or Index Buffer
  3361. //
  3362. PVOID StartOfBuffer;
  3363. //
  3364. // Pointer to Index Header in the File Record or Index Buffer
  3365. //
  3366. PINDEX_HEADER IndexHeader;
  3367. //
  3368. // Pointer to to the current INDEX_ENTRY on search path
  3369. //
  3370. PINDEX_ENTRY IndexEntry;
  3371. //
  3372. // Index block of the index buffer
  3373. //
  3374. LONGLONG IndexBlock;
  3375. //
  3376. // Saved Lsn for faster enumerations
  3377. //
  3378. LSN CapturedLsn;
  3379. } INDEX_LOOKUP_STACK;
  3380. typedef INDEX_LOOKUP_STACK *PINDEX_LOOKUP_STACK;
  3381. #define INDEX_LOOKUP_STACK_SIZE (3)
  3382. //
  3383. // Index Context structure.
  3384. //
  3385. // This structure maintains a context which describes the lookup stack to
  3386. // a given index entry. It includes the Attribute Enumeration Context
  3387. // for the Index Root, the Index lookup stack remembering the path to the
  3388. // index entry, and the current stack pointer within the stack pointing
  3389. // to the stack entry for the current index entry or where we are at in a
  3390. // bucket split or delete operation.
  3391. //
  3392. // Outside of indexsup.c, this structure should only be passed as an
  3393. // "opaque" context, and individual fields should not be referenced.
  3394. //
  3395. typedef struct _INDEX_CONTEXT {
  3396. //
  3397. // Attribute Enumeration Context for the Index Root
  3398. //
  3399. ATTRIBUTE_ENUMERATION_CONTEXT AttributeContext;
  3400. //
  3401. // Captured Lsn of file record containing Index Root. We capture the Lsn
  3402. // of the file record when we find the Index Root. Later, we can
  3403. // check to see if the file record had changed (compare Lsn's) before
  3404. // doing the expensive attribute lookup
  3405. //
  3406. LSN IndexRootFileRecordLsn;
  3407. //
  3408. // Base of dynamically allocated lookup stack - either points
  3409. // to the one above or a dynamically allocated larger one.
  3410. //
  3411. PINDEX_LOOKUP_STACK Base;
  3412. //
  3413. // Stack pointer to top of Lookup Stack. This field essentially
  3414. // remembers how deep the index Btree is.
  3415. //
  3416. PINDEX_LOOKUP_STACK Top;
  3417. //
  3418. // Index lookup stack.
  3419. //
  3420. INDEX_LOOKUP_STACK LookupStack[INDEX_LOOKUP_STACK_SIZE];
  3421. //
  3422. // Stack pointer within the Index Lookup Stack
  3423. //
  3424. PINDEX_LOOKUP_STACK Current;
  3425. //
  3426. // Captured Scb (Index type) change count
  3427. //
  3428. ULONG ScbChangeCount;
  3429. //
  3430. // This field remembers where the index root attribute was last
  3431. // seen, to support correct operation of FindMoveableIndexRoot.
  3432. //
  3433. PATTRIBUTE_RECORD_HEADER OldAttribute;
  3434. //
  3435. // Number of entries allocated in the lookup stack.
  3436. //
  3437. USHORT NumberEntries;
  3438. //
  3439. // Flags
  3440. //
  3441. USHORT Flags;
  3442. //
  3443. // For enumerations via NtOfsReadRecords, the MatchFunction and MatchData
  3444. // are stored here.
  3445. //
  3446. PMATCH_FUNCTION MatchFunction;
  3447. PVOID MatchData;
  3448. //
  3449. // Fcb which was acquired and must be released.
  3450. //
  3451. PFCB AcquiredFcb;
  3452. //
  3453. // Add field to preserve quad & cache line alignment
  3454. //
  3455. ULONG Unused;
  3456. } INDEX_CONTEXT;
  3457. typedef INDEX_CONTEXT *PINDEX_CONTEXT;
  3458. //
  3459. // Fcb table is acquired and must be freed.
  3460. //
  3461. #define INDX_CTX_FLAG_FCB_TABLE_ACQUIRED (01)
  3462. //
  3463. // Context structure for asynchronous I/O calls. Most of these fields
  3464. // are actually only required for the Read/Write Multiple routines, but
  3465. // the caller must allocate one as a local variable anyway before knowing
  3466. // whether there are multiple requests are not. Therefore, a single
  3467. // structure is used for simplicity.
  3468. //
  3469. typedef struct _NTFS_IO_CONTEXT {
  3470. //
  3471. // These two fields are used for multiple run Io
  3472. //
  3473. LONG IrpCount;
  3474. //
  3475. // Flags for the context
  3476. //
  3477. ULONG Flags;
  3478. PIRP MasterIrp;
  3479. union {
  3480. //
  3481. // This element handles the asynchronous non-cached Io
  3482. //
  3483. struct {
  3484. PERESOURCE Resource;
  3485. ERESOURCE_THREAD ResourceThreadId;
  3486. ULONG RequestedByteCount;
  3487. } Async;
  3488. //
  3489. // and this element handles the synchronous non-cached Io.
  3490. //
  3491. KEVENT SyncEvent;
  3492. } Wait;
  3493. } NTFS_IO_CONTEXT;
  3494. typedef NTFS_IO_CONTEXT *PNTFS_IO_CONTEXT;
  3495. //
  3496. // NTFS_IO_CONTEXT Flags
  3497. //
  3498. #define NTFS_IO_CONTEXT_ALLOCATED (0x00000001)
  3499. #define NTFS_IO_CONTEXT_PAGING_IO (0x00000002)
  3500. #define NTFS_IO_CONTEXT_ASYNC (0x00000004)
  3501. #define NTFS_IO_CONTEXT_INLINE_OPLOCK (0x00000008)
  3502. //
  3503. // An array of these structures is passed to NtfsMultipleAsync describing
  3504. // a set of runs to execute in parallel. Risc compilers will add an
  3505. // unused long word anyway to align each array entry.
  3506. //
  3507. typedef struct _IO_RUN {
  3508. VBO StartingVbo;
  3509. LBO StartingLbo;
  3510. ULONG BufferOffset;
  3511. ULONG ByteCount;
  3512. PIRP SavedIrp;
  3513. ULONG Unused;
  3514. } IO_RUN;
  3515. typedef IO_RUN *PIO_RUN;
  3516. //
  3517. // This structure is used by the name manipulation routines to described
  3518. // a parsed file name componant.
  3519. //
  3520. typedef struct _NTFS_NAME_DESCRIPTOR {
  3521. //
  3522. // The follow flag tells which fields were present in the name.
  3523. //
  3524. ULONG FieldsPresent;
  3525. UNICODE_STRING FileName;
  3526. UNICODE_STRING AttributeType;
  3527. UNICODE_STRING AttributeName;
  3528. ULONG VersionNumber;
  3529. } NTFS_NAME_DESCRIPTOR;
  3530. typedef NTFS_NAME_DESCRIPTOR *PNTFS_NAME_DESCRIPTOR;
  3531. //
  3532. // Define the bits in FieldsPresent above.
  3533. //
  3534. #define FILE_NAME_PRESENT_FLAG (1)
  3535. #define ATTRIBUTE_TYPE_PRESENT_FLAG (2)
  3536. #define ATTRIBUTE_NAME_PRESENT_FLAG (4)
  3537. #define VERSION_NUMBER_PRESENT_FLAG (8)
  3538. //
  3539. // The following is used to perform Ea related routines.
  3540. //
  3541. typedef struct _EA_LIST_HEADER {
  3542. //
  3543. // The size of buffer needed to pack these Ea's
  3544. //
  3545. ULONG PackedEaSize;
  3546. //
  3547. // This is the count of Ea's with their NEED_EA
  3548. // bit set.
  3549. //
  3550. USHORT NeedEaCount;
  3551. //
  3552. // The size of the buffer needed to return all Ea's
  3553. // in their unpacked form.
  3554. //
  3555. ULONG UnpackedEaSize;
  3556. //
  3557. // This is the size of the buffer used to store the ea's
  3558. //
  3559. ULONG BufferSize;
  3560. //
  3561. // This is the pointer to the first entry in the list.
  3562. //
  3563. PFILE_FULL_EA_INFORMATION FullEa;
  3564. } EA_LIST_HEADER;
  3565. typedef EA_LIST_HEADER *PEA_LIST_HEADER;
  3566. //
  3567. // The following structure is used to maintain a list of recently
  3568. // deallocated records so that the file system will not reuse a recently
  3569. // deallocated record until it is safe to do so. Each instance of this
  3570. // structure is placed on two queues. One queue is per index SCB and the
  3571. // other queue is per Irp Context.
  3572. //
  3573. // Whenever we delete a record we allocate a new structure if necessary
  3574. // and add it to the scb queue and the irp context queue. We indicate in
  3575. // the structure the index of the record we just deallocated.
  3576. //
  3577. // Whenever we need to allocate a new record we filter out any canidate
  3578. // we want to allocate to avoid allocating one in the scb's recently
  3579. // deallocated queue.
  3580. //
  3581. // Whenever we delete an irp context we scan through its recently
  3582. // deallocated queue removing it from the scb queue.
  3583. //
  3584. #define DEALLOCATED_RECORD_ENTRIES 32
  3585. typedef struct _DEALLOCATED_RECORDS {
  3586. //
  3587. // The following field links this structure into the
  3588. // Scb->RecentlyDeallocatedQueue
  3589. //
  3590. LIST_ENTRY ScbLinks;
  3591. //
  3592. // The following field links this structure into the
  3593. // IrpContext->RecentlyDeallocatedQueue
  3594. //
  3595. LIST_ENTRY IrpContextLinks;
  3596. //
  3597. // This is a pointer to the Scb that this record is part of
  3598. //
  3599. PSCB Scb;
  3600. //
  3601. // The following two fields describe the total size of this structure
  3602. // and the number of entries actually being used. NumberOfEntries is
  3603. // the size of the Index array and NextFreeEntryis the index of the
  3604. // next free slot. If NumberOfEntries is equal to NextFreeEntry then
  3605. // this structure is full
  3606. //
  3607. ULONG NumberOfEntries;
  3608. ULONG NextFreeEntry;
  3609. //
  3610. // This is an array of indices that have been dealloated.
  3611. //
  3612. ULONG Index[DEALLOCATED_RECORD_ENTRIES];
  3613. } DEALLOCATED_RECORDS;
  3614. typedef DEALLOCATED_RECORDS *PDEALLOCATED_RECORDS;
  3615. #define DEALLOCATED_RECORDS_HEADER_SIZE \
  3616. (FIELD_OFFSET( DEALLOCATED_RECORDS, Index ))
  3617. #pragma pack(8)
  3618. typedef struct _FCB_TABLE_ELEMENT {
  3619. FILE_REFERENCE FileReference;
  3620. PFCB Fcb;
  3621. } FCB_TABLE_ELEMENT;
  3622. typedef FCB_TABLE_ELEMENT *PFCB_TABLE_ELEMENT;
  3623. #pragma pack()
  3624. #ifdef NTFS_CACHE_RIGHTS
  3625. //
  3626. // Computed access rights information. This structure is used to cache
  3627. // what access rights a given security token is granted relative to a
  3628. // security descriptors.
  3629. //
  3630. typedef struct _COMPUTED_ACCESS_RIGHTS {
  3631. //
  3632. // The token id. Note that a specific TokenId will only appear once
  3633. // in the cache.
  3634. //
  3635. LUID TokenId;
  3636. //
  3637. // The modification id of the token. This changes whenever the token
  3638. // is updated such that the access rights might change.
  3639. //
  3640. LUID ModifiedId;
  3641. //
  3642. // All of the access rights held by this token that do not require
  3643. // privileges. The rights will also not include MAXIMUM_ALLOWED.
  3644. // Note that we don't include rights that require privileges
  3645. // because we wouldn't be able to determine in a future
  3646. // use of the cached information whether the privileges were needed
  3647. // or not to gain a desired set of rights. The use of privileges
  3648. // affects auditing.
  3649. //
  3650. ACCESS_MASK Rights;
  3651. } COMPUTED_ACCESS_RIGHTS, *PCOMPUTED_ACCESS_RIGHTS;
  3652. //
  3653. // Cached access rights information. This structure is used to cache
  3654. // what access rights are known to be available for all security tokens
  3655. // and for the most recently used specific security tokens.
  3656. //
  3657. #define NTFS_MAX_CACHED_RIGHTS 2
  3658. typedef struct _CACHED_ACCESS_RIGHTS {
  3659. //
  3660. // The list of computed access rights for specific tokens.
  3661. //
  3662. COMPUTED_ACCESS_RIGHTS TokenRights[NTFS_MAX_CACHED_RIGHTS];
  3663. //
  3664. // The access rights that all users are known to have.
  3665. // The rights will not include MAXIMUM_ALLOWED.
  3666. //
  3667. ACCESS_MASK EveryoneRights;
  3668. //
  3669. // The number of valid entries in TokenRights.
  3670. //
  3671. UCHAR Count;
  3672. //
  3673. // The index of the next entry to add to TokenRights.
  3674. //
  3675. UCHAR NextInsert;
  3676. //
  3677. // This indicates whether we have acquired EveryoneRights.
  3678. //
  3679. BOOLEAN HaveEveryoneRights;
  3680. } CACHED_ACCESS_RIGHTS, *PCACHED_ACCESS_RIGHTS;
  3681. #endif
  3682. //
  3683. // Security descriptor information. This structure is used to allow
  3684. // Fcb's to share security descriptors.
  3685. //
  3686. typedef struct _SHARED_SECURITY {
  3687. #ifdef NTFS_CACHE_RIGHTS
  3688. CACHED_ACCESS_RIGHTS CachedRights;
  3689. #endif
  3690. ULONG ReferenceCount;
  3691. SECURITY_DESCRIPTOR_HEADER Header;
  3692. UCHAR SecurityDescriptor[1];
  3693. } SHARED_SECURITY, *PSHARED_SECURITY;
  3694. #define GetSharedSecurityLength(SS) (GETSECURITYDESCRIPTORLENGTH( &(SS)->Header ))
  3695. #define SetSharedSecurityLength(SS,LENGTH) (SetSecurityDescriptorLength( &(SS)->Header,(LENGTH) ))
  3696. //
  3697. // The following structure is used to store the state of an Scb to use
  3698. // during unwind operations. We keep a copy of all of the file sizes.
  3699. //
  3700. typedef struct _OLD_SCB_SNAPSHOT {
  3701. LONGLONG AllocationSize;
  3702. LONGLONG FileSize;
  3703. LONGLONG ValidDataLength;
  3704. LONGLONG TotalAllocated;
  3705. UCHAR CompressionUnit;
  3706. BOOLEAN Resident;
  3707. USHORT AttributeFlags;
  3708. } OLD_SCB_SNAPSHOT, *POLD_SCB_SNAPSHOT;
  3709. //
  3710. // Structure used to track the number of threads doing read ahead, so
  3711. // that we do not hot fix for them.
  3712. //
  3713. typedef struct _READ_AHEAD_THREAD {
  3714. //
  3715. // Links of read ahead structures.
  3716. //
  3717. LIST_ENTRY Links;
  3718. //
  3719. // Thread Id
  3720. //
  3721. PVOID Thread;
  3722. } READ_AHEAD_THREAD, *PREAD_AHEAD_THREAD;
  3723. //
  3724. // Structure used to post to Defrag Mft routine.
  3725. //
  3726. typedef struct _DEFRAG_MFT {
  3727. //
  3728. // This structure is used for posting to the Ex worker threads.
  3729. //
  3730. WORK_QUEUE_ITEM WorkQueueItem;
  3731. PVCB Vcb;
  3732. BOOLEAN DeallocateWorkItem;
  3733. } DEFRAG_MFT, *PDEFRAG_MFT;
  3734. //
  3735. // Structure for remembering file records to delete.
  3736. //
  3737. typedef struct _NUKEM {
  3738. struct _NUKEM *Next;
  3739. ULONG RecordNumbers[4];
  3740. } NUKEM, *PNUKEM;
  3741. //
  3742. // Structure for picking up file name pairs for property tunneling. Space is allocated for
  3743. // the names so that this can be used on the stack. The size of LongBuffer should be sized
  3744. // so that it will capture the vast majority of long names. Fallback code can go to pool
  3745. // if required - but rarely.
  3746. //
  3747. typedef struct _NAME_PAIR {
  3748. //
  3749. // The FILE_NAME_DOS component
  3750. //
  3751. UNICODE_STRING Short;
  3752. //
  3753. // The FILE_NAME_NTFS component
  3754. //
  3755. UNICODE_STRING Long;
  3756. // Allocate space for an 8.3 name and a 26 char name. 26 isn't quite random -
  3757. // it puts this structure at 96 bytes.
  3758. //
  3759. WCHAR ShortBuffer[8+1+3];
  3760. WCHAR LongBuffer[26];
  3761. } NAME_PAIR, *PNAME_PAIR;
  3762. //
  3763. // The following is used to synchronize the create path. It is passed to the completion
  3764. // callback to restore the top level context and signal any waiting thread.
  3765. //
  3766. typedef struct _NTFS_COMPLETION_CONTEXT {
  3767. PIRP_CONTEXT IrpContext;
  3768. KEVENT Event;
  3769. } NTFS_COMPLETION_CONTEXT, *PNTFS_COMPLETION_CONTEXT;
  3770. //
  3771. // Following structure is used at the time a request is posted to the oplock package
  3772. // to perform any cleanup to do at that time.
  3773. //
  3774. typedef struct _OPLOCK_CLEANUP {
  3775. //
  3776. // This is the original name and any allocated name buffer used during create.
  3777. // We must restore the original name in the file object on error.
  3778. //
  3779. // We also store information about the original lengths of the attribute name
  3780. // and attribute code (or type) name.
  3781. //
  3782. UNICODE_STRING OriginalFileName;
  3783. UNICODE_STRING FullFileName;
  3784. UNICODE_STRING ExactCaseName;
  3785. PFILE_OBJECT FileObject;
  3786. ACCESS_MASK RemainingDesiredAccess;
  3787. ACCESS_MASK PreviouslyGrantedAccess;
  3788. ACCESS_MASK DesiredAccess;
  3789. PNTFS_COMPLETION_CONTEXT CompletionContext;
  3790. USHORT AttributeNameLength;
  3791. USHORT AttributeCodeNameLength;
  3792. } OPLOCK_CLEANUP, *POPLOCK_CLEANUP;
  3793. //
  3794. // Context used to track state and cleanup work during create
  3795. //
  3796. typedef struct _CREATE_CONTEXT {
  3797. //
  3798. // The oplock cleanup structure
  3799. //
  3800. OPLOCK_CLEANUP Cleanup;
  3801. //
  3802. // Hash package values
  3803. //
  3804. ULONG FileHashValue;
  3805. ULONG FileHashLength;
  3806. ULONG ParentHashValue;
  3807. ULONG ParentHashLength;
  3808. //
  3809. // Common parameters - these are the current fcb node and the output
  3810. // scb and ccb for the opened file
  3811. //
  3812. PFCB CurrentFcb;
  3813. PSCB ThisScb;
  3814. PCCB ThisCcb;
  3815. //
  3816. // Output buffer to put network info into if its specified - this is optional
  3817. // and implies that the create is not a full one
  3818. //
  3819. PVOID NetworkInfo;
  3820. //
  3821. // Create Flags for the create
  3822. //
  3823. ULONG CreateFlags;
  3824. //
  3825. // A combination of FILE_NEW, etc. to be passed to the encryption callout and
  3826. // to assist in cleaning up after creates that fail in the PostCreate callout.
  3827. //
  3828. ULONG EncryptionFileDirFlags;
  3829. //
  3830. // A context value needs to be preserved throughout an encyrpted file create.
  3831. // Given the importance of making creates fast, adding one more pointer to
  3832. // this struct is better than making create push another parameter to its
  3833. // various local routines like NtfsOpenExistingPrefixFcb.
  3834. //
  3835. PVOID EncryptionContext;
  3836. } CREATE_CONTEXT, *PCREATE_CONTEXT;
  3837. //
  3838. // The following structure is used to serialize the compressed IO path.
  3839. //
  3840. typedef struct _COMPRESSION_SYNC {
  3841. //
  3842. // Links of synchronization objects, attached to Scb.
  3843. // NOTE - this field must appear first. We make this assumption
  3844. // when walking the links.
  3845. //
  3846. LIST_ENTRY CompressionLinks;
  3847. //
  3848. // Offset in the file for the link. Rounded down to cache manager views.
  3849. //
  3850. LONGLONG FileOffset;
  3851. //
  3852. // Resource for synchronization. Allows shared or exclusive access to view.
  3853. //
  3854. ERESOURCE Resource;
  3855. //
  3856. // Backpointer to Scb.
  3857. //
  3858. PSCB Scb;
  3859. //
  3860. // Reference count for number of users of this view. Someone waiting
  3861. // for the offset wants to make sure it doesn't go away when
  3862. // another thread is finished with it.
  3863. //
  3864. ULONG ReferenceCount;
  3865. } COMPRESSION_SYNC, *PCOMPRESSION_SYNC;
  3866. //
  3867. // This is the quota control block which are stored as table elments in the quota
  3868. // control table.
  3869. //
  3870. typedef struct _QUOTA_CONTROL_BLOCK {
  3871. NODE_TYPE_CODE NodeTypeCode;
  3872. NODE_BYTE_SIZE NodeByteSize;
  3873. ULONG OwnerId;
  3874. ULONG Flags;
  3875. LONG ReferenceCount;
  3876. QUICK_INDEX_HINT QuickIndexHint;
  3877. PFAST_MUTEX QuotaControlLock;
  3878. } QUOTA_CONTROL_BLOCK, *PQUOTA_CONTROL_BLOCK;
  3879. //
  3880. // Define the quota control flags.
  3881. //
  3882. #define QUOTA_FLAG_LIMIT_POSTED (0x00000001)
  3883. //
  3884. // Define the minimum amount of time between quota events. Currently this is
  3885. // 1 hour.
  3886. //
  3887. #define MIN_QUOTA_NOTIFY_TIME (60i64 * 60 * 1000 * 1000 * 10)
  3888. //
  3889. // NTFS_TUNNELED_DATA is a structure for keeping the information which is
  3890. // preserved when a file is tunneled. This is the structure that we pass to
  3891. // and get back from the tunneling routines in FsRtl.
  3892. //
  3893. typedef struct _NTFS_TUNNELED_DATA {
  3894. LONGLONG CreationTime;
  3895. FILE_OBJECTID_BUFFER ObjectIdBuffer;
  3896. BOOLEAN HasObjectId;
  3897. } NTFS_TUNNELED_DATA, *PNTFS_TUNNELED_DATA;
  3898. //
  3899. // Following macro is used to initialize UNICODE strings
  3900. //
  3901. #define CONSTANT_UNICODE_STRING(s) { sizeof( s ) - sizeof( WCHAR ), sizeof( s ), s }
  3902. #define USN_PAGE_BOUNDARY (0x2000)
  3903. #define USN_JOURNAL_CACHE_BIAS (0x0000000000400000)
  3904. #define USN_MAXIMUM_JOURNAL_SIZE (0x0000000100000000)
  3905. #ifdef NTFS_RWCMP_TRACE
  3906. extern ULONG NtfsCompressionTrace;
  3907. #define IsSyscache(H) (FlagOn(((PSCB)(H))->ScbState, SCB_STATE_SYSCACHE_FILE))
  3908. #endif
  3909. #ifdef BENL_DBG
  3910. typedef struct {
  3911. LIST_ENTRY Links;
  3912. LSN Lsn;
  3913. ULONG Data;
  3914. ULONG OldData;
  3915. ULONG Length;
  3916. } RESTART_LOG, *PRESTART_LOG;
  3917. #endif
  3918. //
  3919. // Maximum entries in the overflow queue at one time
  3920. //
  3921. #define OVERFLOW_QUEUE_LIMIT 1000
  3922. #define RESERVE_POOL_TAG ('bftN')
  3923. #endif // _NTFSSTRU_