Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2474 lines
68 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 internal
  7. part of the Ntfs file system.
  8. The global data structures start with the NtfsData record. It contains
  9. a pointer to a File System Device object, and a queue of Vcb's. There
  10. is a Vcb for every currently mounted volume. The Vcb's are allocated as
  11. 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 (i.e.,
  31. 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 Lcbs)
  42. 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 that
  45. the file system is manipulating as a stream file). Each Scb contains
  46. a common fsrtl header and information necessary for doing I/O to the
  47. 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 opened
  55. once with the name LcbA and another time with the name LcbB. Scb2 also has
  56. two opened file one is Fcb1 and named LcbC and the other is Fcb2 and named
  57. LcbD. Fcb1 has two opened Scbs under it (Scb3 and Scb4), and Fcb2 has
  58. 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 Ccb list
  81. is for each ccb that has opened that File (fcb) via the name. The Prefix list
  82. contains the prefix table entries that we are caching.
  83. The NtfsData, all Vcbs, and the paging file Fcb, and all Scbs are allocated
  84. out of nonpaged pool. The Fcbs are allocated out of paged pool.
  85. The resources protecting the NTFS memory structures are setup as follows:
  86. 1. There is a global resource in the NtfsData record. This resource
  87. protects the NtfsData record which includes any changes to its
  88. Vcb queue.
  89. 2. There is a resource per Vcb. This resource pretects the Vcb record
  90. which includes adding and removing Fcbs, and Scbs
  91. 3. There is a single resource protecting an Fcb and its assigned
  92. Scbs. This resource protects any changes to the Fcb, and Scb
  93. records. The way this one works is that each Fcb, and Scb point
  94. to the resource. The Scb also contain back pointers to their parent
  95. Fcb but we cannot use this pointer to get the resource because
  96. the Fcb might be in nonpaged pool.
  97. +--------+
  98. |Fcb | +--------+ +--------+
  99. | | <-> |Scb | <-> |Scb | <-> ...
  100. +--------+ | | | |
  101. +--------+ +--------+
  102. |
  103. | | |
  104. | v |
  105. | |
  106. | +--------+ |
  107. +-----> |Resource| <-----+
  108. | |
  109. +--------+
  110. There are four types of opens possible for each file object handled by
  111. NTFS. They are UserFileOpen, UserDirectoryOpen, UserVolumeOpen, and
  112. StreamFileOpen. The first three types correspond to user opens on
  113. files, directories, and dasd respectively. The last type is for any
  114. file object created by NTFS for its stream I/O (e.g., the volume
  115. bitmap). The file system uses the FsContext and FsContext2 fields of
  116. the file object to store information about the type of open and the
  117. fcb/scb/ccb associated with the file object. We can overload the low
  118. bits of the fields to be more than pointers because they must always
  119. point to longword aligned records. The fields are used as follows:
  120. Type of open FsContext FsContext2
  121. ------------ --------- ----------
  122. UserFileOpen Pointer to Scb with Pointer to Ccb
  123. 0 in the last two bits
  124. UserDirectoryOpen Pointer to Scb with Pointer to Ccb
  125. 1 in the last two bits
  126. UserVolumeOpen Pointer to Scb with Pointer to Ccb
  127. 2 in the last two bits
  128. StreamFileOpen Pointer to Scb null
  129. The only part of the NTFS code that actually needs to know this
  130. information is in FilObSup.c. But we talk about it here to help
  131. developers debug the system.
  132. To mount a new NTFS volume requires a bit of juggling. The idea is
  133. to have as little setup in memory as necessary to recoginize the volume,
  134. call a restart routine that will recover the volume, and then precede with
  135. the mounting. To aid in this the regular directory structures of the
  136. Fcb is bypassed. In its place we have a linked list of Fcbs off
  137. of the Vcb. This is done because during recovery we do not know where
  138. an Fcb belongs in the directory hierarchy. So at restart time all
  139. new fcbs get put in this prerestart Fcb list. Then after restart whenever
  140. we create a new Fcb we search this list for a match (on file reference).
  141. If we find one we remove the fcb from this list and move it to the proper
  142. place in the directory hierarchy tree (fcb tree).
  143. Author:
  144. Brian Andrew [BrianAn] 21-May-1991
  145. David Goebel [DavidGoe]
  146. Gary Kimura [GaryKi]
  147. Tom Miller [TomM]
  148. Revision History:
  149. --*/
  150. #ifndef _NTFSSTRU_
  151. #define _NTFSSTRU_
  152. typedef PVOID PBCB; //**** Bcb's are now part of the cache module
  153. //
  154. // Define who many freed structures we are willing to keep around
  155. //
  156. #define FREE_CCB_SIZE (8)
  157. #define FREE_FCB_SIZE (8)
  158. #define FREE_LCB_SIZE (8)
  159. #define FREE_SCB_DATA_SIZE (4)
  160. #define FREE_SCB_SHARE_DATA_SIZE (8)
  161. #define FREE_SCB_INDEX_SIZE (8)
  162. #define FREE_SCB_NONPAGED_SIZE (8)
  163. #define FREE_DEALLOCATED_RECORDS_SIZE (8)
  164. #define FREE_ERESOURCE_SIZE (8)
  165. #define FREE_INDEX_CONTEXT_SIZE (8)
  166. #define FREE_KEVENT_SIZE (8)
  167. #define FREE_NUKEM_SIZE (8)
  168. #define FREE_SCB_SNAPSHOT_SIZE (8)
  169. #define FREE_IO_CONTEXT_SIZE (8)
  170. #define FREE_FILE_LOCK_SIZE (8)
  171. #define FREE_FCB_TABLE_SIZE (8)
  172. #define FREE_128_BYTE_SIZE (16)
  173. #define FREE_256_BYTE_SIZE (16)
  174. #define FREE_512_BYTE_SIZE (16)
  175. #define MAX_DELAYED_CLOSE_COUNT_SMALL (20)
  176. #define MAX_DELAYED_CLOSE_COUNT_MEDIUM (100)
  177. #define MAX_DELAYED_CLOSE_COUNT_LARGE (500)
  178. //
  179. // The NTFS_DATA record is the top record in the NTFS file system in-memory
  180. // data structure. This structure must be allocated from non-paged pool.
  181. //
  182. typedef struct _NTFS_DATA {
  183. //
  184. // The type and size of this record (must be NTFS_NTC_DATA_HEADER)
  185. //
  186. NODE_TYPE_CODE NodeTypeCode;
  187. NODE_BYTE_SIZE NodeByteSize;
  188. //
  189. // A queue of all the devices that are mounted by the file system.
  190. // Corresponds to the field Vcb->VcbLinks;
  191. //
  192. LIST_ENTRY VcbQueue;
  193. //
  194. // A pointer to the Driver object we were initialized with
  195. //
  196. PDRIVER_OBJECT DriverObject;
  197. //
  198. // A resource variable to control access to the global NTFS data record
  199. //
  200. ERESOURCE Resource;
  201. //
  202. // A pointer to our EPROCESS struct, which is a required input to the
  203. // Cache Management subsystem.
  204. //
  205. PEPROCESS OurProcess;
  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. //
  214. // The following fields describe the deferred close file objects.
  215. //
  216. ULONG DelayedCloseCount;
  217. LIST_ENTRY DelayedCloseList;
  218. //
  219. // This is the ExWorkerItem that does both kinds of deferred closes.
  220. //
  221. WORK_QUEUE_ITEM NtfsCloseItem;
  222. //
  223. // The following fields are used to allocate IRP context structures
  224. // using the zone allocator, and other fixed sized structures from a
  225. // small cache. The spinlock protects access to the zone/lists
  226. //
  227. KSPIN_LOCK StrucSupSpinLock;
  228. ZONE_HEADER IrpContextZone;
  229. struct _CCB *FreeCcbArray[FREE_CCB_SIZE];
  230. struct _FCB *FreeFcbArray[FREE_FCB_SIZE];
  231. struct _LCB *FreeLcbArray[FREE_LCB_SIZE];
  232. struct _SCB *FreeScbDataArray[FREE_SCB_DATA_SIZE];
  233. struct _SCB *FreeScbShareDataArray[FREE_SCB_SHARE_DATA_SIZE];
  234. struct _SCB *FreeScbIndexArray[FREE_SCB_INDEX_SIZE];
  235. struct _SCB_NONPAGED *FreeScbNonpagedArray[FREE_SCB_NONPAGED_SIZE];
  236. struct _DEALLOCATED_RECORDS *FreeDeallocatedRecordsArray[FREE_DEALLOCATED_RECORDS_SIZE];
  237. struct _ERESOURCE *FreeEresourceArray [FREE_ERESOURCE_SIZE];
  238. struct _INDEX_CONTEXT *FreeIndexContextArray [FREE_INDEX_CONTEXT_SIZE];
  239. struct _KEVENT *FreeKeventArray [FREE_KEVENT_SIZE];
  240. struct _NUKEM *FreeNukemArray [FREE_NUKEM_SIZE];
  241. struct _SCB_SNAPSHOT *FreeScbSnapshotArray [FREE_SCB_SNAPSHOT_SIZE];
  242. struct _NTFS_IO_CONTEXT *FreeIoContextArray [FREE_IO_CONTEXT_SIZE];
  243. struct _FILE_LOCK *FreeFileLockArray [FREE_FILE_LOCK_SIZE];
  244. PVOID *FreeFcbTableArray[FREE_FCB_TABLE_SIZE];
  245. PVOID *Free128ByteArray[FREE_128_BYTE_SIZE];
  246. PVOID *Free256ByteArray[FREE_256_BYTE_SIZE];
  247. PVOID *Free512ByteArray[FREE_512_BYTE_SIZE];
  248. UCHAR FreeCcbSize;
  249. UCHAR FreeFcbSize;
  250. UCHAR FreeLcbSize;
  251. UCHAR FreeScbDataSize;
  252. UCHAR FreeScbShareDataSize;
  253. UCHAR FreeScbIndexSize;
  254. UCHAR FreeScbNonpagedSize;
  255. UCHAR FreeDeallocatedRecordsSize;
  256. UCHAR FreeEresourceSize;
  257. UCHAR FreeIndexContextSize;
  258. UCHAR FreeKeventSize;
  259. UCHAR FreeNukemSize;
  260. UCHAR FreeScbSnapshotSize;
  261. UCHAR FreeIoContextSize;
  262. UCHAR FreeFileLockSize;
  263. UCHAR FreeFcbTableSize;
  264. UCHAR Free128ByteSize;
  265. UCHAR Free256ByteSize;
  266. UCHAR Free512ByteSize;
  267. //
  268. // Cache manager call back structures, which must be passed on each call
  269. // to CcInitializeCacheMap.
  270. //
  271. CACHE_MANAGER_CALLBACKS CacheManagerCallbacks;
  272. CACHE_MANAGER_CALLBACKS CacheManagerVolumeCallbacks;
  273. //
  274. // This is a list of all of the threads currently doing read ahead.
  275. // We will not hot fix for these threads.
  276. //
  277. LIST_ENTRY ReadAheadThreads;
  278. //
  279. // The following fields are used for the CheckpointVolumes() callback.
  280. //
  281. KDPC VolumeCheckpointDpc;
  282. KTIMER VolumeCheckpointTimer;
  283. KSPIN_LOCK VolumeCheckpointSpinLock;
  284. WORK_QUEUE_ITEM VolumeCheckpointItem;
  285. BOOLEAN Modified;
  286. BOOLEAN ExtraCheckpoint;
  287. BOOLEAN TimerSet;
  288. } NTFS_DATA;
  289. typedef NTFS_DATA *PNTFS_DATA;
  290. //
  291. // The record allocation context structure is used by the routines that allocate
  292. // and deallocate records based on a bitmap (for example the mft bitmap or the
  293. // index bitmap). The context structure needs to be defined here because
  294. // the mft bitmap context is declared as part of the vcb.
  295. //
  296. typedef struct _RECORD_ALLOCATION_CONTEXT {
  297. //
  298. // The following field is a pointer to the scb for the data part of
  299. // the file that this bitmap controls. For example, it is a pointer to
  300. // the data attribute for the MFT.
  301. //
  302. // NOTE !!!! The Data Scb must remain the first entry in this structure.
  303. // If we need to uninitialize and reinitialize this structure in the
  304. // running system we don't want to touch this field.
  305. //
  306. // NOTE !!!! The code that clears the record allocation context expects
  307. // the BitmapScb field to follow the Data Scb field.
  308. //
  309. struct _SCB *DataScb;
  310. //
  311. // The following field is used to indicate if the bitmap attribute is
  312. // in a resident form or a nonresident form. If the bitmap is in a
  313. // resident form then the pointer is null, and whenever a bitmap
  314. // routine is called it must also be passed an attribute enumeration
  315. // context to be able to read the bitmap. If the field is not null
  316. // then it points to the scb for the non resident bitmap attribute
  317. //
  318. struct _SCB *BitmapScb;
  319. //
  320. // The following two fields describe the current size of the bitmap
  321. // (in bits) and the number of free bits currently in the bitmap.
  322. // A value of MAXULONG in the CurrentBitmapSize indicates that we need
  323. // to reinitialize the record context structure.
  324. //
  325. ULONG CurrentBitmapSize;
  326. ULONG NumberOfFreeBits;
  327. //
  328. // The following three fields are used to indicate the allocation
  329. // size for the bitmap (i.e., each bit in the bitmap represents how
  330. // many bytes in the data attribute). Also it indicates the granularity
  331. // with which we will either extend or shrink the bitmap.
  332. //
  333. ULONG BytesPerRecord;
  334. ULONG ExtendGranularity;
  335. ULONG TruncateGranularity;
  336. //
  337. // The following field contains the index of last bit that we know
  338. // to be set. This is used for truncation purposes.
  339. //
  340. LONG IndexOfLastSetBit;
  341. } RECORD_ALLOCATION_CONTEXT;
  342. typedef RECORD_ALLOCATION_CONTEXT *PRECORD_ALLOCATION_CONTEXT;
  343. //
  344. // The Vcb (Volume control Block) record corresponds to every volume mounted
  345. // by the file system. They are ordered in a queue off of NtfsData.VcbQueue.
  346. // This structure must be allocated from non-paged pool
  347. //
  348. #define DEFAULT_ATTRIBUTE_TABLE_SIZE (32)
  349. #define DEFAULT_TRANSACTION_TABLE_SIZE (32)
  350. #define DEFAULT_DIRTY_PAGES_TABLE_SIZE (64)
  351. //
  352. // The Restart Pointers structure is the actual structure supported by
  353. // routines and macros to get at a Restart Table. This structure is
  354. // required since the restart table itself may move, so one must first
  355. // acquire the resource to synchronize, then follow the pointer to the table.
  356. //
  357. typedef struct _RESTART_POINTERS {
  358. //
  359. // Pointer to the actual Restart Table.
  360. //
  361. struct _RESTART_TABLE *Table;
  362. //
  363. // Resource to synchronize with table moves. This resource must
  364. // be held shared while dealing with pointers to table entries,
  365. // and exclusive to move the table.
  366. //
  367. ERESOURCE Resource;
  368. //
  369. // Remember if the resource was initialized.
  370. //
  371. BOOLEAN ResourceInitialized;
  372. //
  373. // Spin Lock synchronizing allocates and deletes of entries in the
  374. // table. The resource must be held at least shared.
  375. //
  376. KSPIN_LOCK SpinLock;
  377. } RESTART_POINTERS, *PRESTART_POINTERS;
  378. //
  379. // Structure used to track the deallocated clusters.
  380. //
  381. typedef struct _DEALLOCATED_CLUSTERS {
  382. LSN Lsn;
  383. LONGLONG ClusterCount;
  384. LARGE_MCB Mcb;
  385. } DEALLOCATED_CLUSTERS, *PDEALLOCATED_CLUSTERS;
  386. //
  387. // The Vcb structure corresponds to every mounted NTFS volume in the system
  388. //
  389. typedef struct _VCB {
  390. //
  391. // The type and size of this record (must be NTFS_NTC_VCB)
  392. //
  393. NODE_TYPE_CODE NodeTypeCode;
  394. NODE_BYTE_SIZE NodeByteSize;
  395. //
  396. // The links for the queue of all the Vcbs in the system.
  397. // Corresponds to the filld NtfsData.VcbQueue
  398. //
  399. LIST_ENTRY VcbLinks;
  400. //
  401. // Pointer to the Scb for the special system file. If the field is null
  402. // then we haven't yet built the scb for that system file. Also the pointer
  403. // to the stream file object is located in the scb.
  404. //
  405. // NOTE: AcquireExclusiveFiles depends on this order. Any change here
  406. // should be checked with the code there.
  407. //
  408. struct _SCB *MftScb;
  409. struct _SCB *Mft2Scb;
  410. struct _SCB *LogFileScb;
  411. struct _SCB *VolumeDasdScb;
  412. struct _SCB *AttributeDefTableScb;
  413. struct _SCB *UpcaseTableScb;
  414. struct _SCB *RootIndexScb;
  415. struct _SCB *BitmapScb;
  416. struct _SCB *BootFileScb;
  417. struct _SCB *BadClusterFileScb;
  418. struct _SCB *QuotaTableScb;
  419. struct _SCB *MftBitmapScb;
  420. //
  421. // The root Lcb for this volume.
  422. //
  423. struct _LCB *RootLcb;
  424. //
  425. // A pointer the device object passed in by the I/O system on a mount
  426. // This is the target device object that the file system talks to when it
  427. // needs to do any I/O (e.g., the disk stripper device object).
  428. //
  429. //
  430. PDEVICE_OBJECT TargetDeviceObject;
  431. //
  432. // A pointer to the VPB for the volume passed in by the I/O system on
  433. // a mount.
  434. //
  435. PVPB Vpb;
  436. //
  437. // The internal state of the volume. This is a collection of Vcb
  438. // state flags. The VcbState is synchronized with the Vcb resource.
  439. // The MftDefragState is synchronized with the CheckpointEvent.
  440. // The MftReserveFlags are sychronized with the MftScb.
  441. //
  442. ULONG VcbState;
  443. ULONG MftReserveFlags;
  444. ULONG MftDefragState;
  445. //
  446. // A count of the number of file objects that have any file/directory
  447. // opened on this volume. And a count of the number of special system
  448. // files that we have open
  449. //
  450. CLONG CleanupCount;
  451. CLONG CloseCount;
  452. CLONG ReadOnlyCloseCount;
  453. CLONG SystemFileCloseCount;
  454. //
  455. // A resource variable to control access to the volume specific data
  456. // structures
  457. //
  458. ERESOURCE Resource;
  459. //
  460. // The following events are used to synchronize the Fcb table and
  461. // the shared security structures.
  462. //
  463. KEVENT FcbTableEvent;
  464. PVOID FcbTableThread;
  465. KEVENT FcbSecurityEvent;
  466. PVOID FcbSecurityThread;
  467. //
  468. // Following events are used to control the volume checkpoint
  469. // operations.
  470. //
  471. KEVENT CheckpointEvent;
  472. PVOID CheckpointThread;
  473. KEVENT CheckpointNotifyEvent;
  474. PVOID CheckpointNotifyThread;
  475. ULONG CheckpointFlags;
  476. //
  477. // The following field is a pointer to the file object that has the
  478. // volume locked. if the VcbState has the locked flag set.
  479. //
  480. PFILE_OBJECT FileObjectWithVcbLocked;
  481. //
  482. // The following volume-specific parameters are extracted from the
  483. // Boot Sector.
  484. //
  485. ULONG BytesPerSector;
  486. ULONG BytesPerCluster;
  487. ULONG BytesPerFileRecordSegment;
  488. LONGLONG NumberSectors;
  489. LCN MftStartLcn;
  490. LCN Mft2StartLcn;
  491. ULONG ClustersPerFileRecordSegment;
  492. ULONG DefaultClustersPerIndexAllocationBuffer;
  493. //
  494. // This field contains a calculated value which determines when an
  495. // individual attribute is large enough to be moved to free up file
  496. // record space. (The calculation of this variable must be considered
  497. // in conjunction with the constant MAX_MOVEABLE_ATTRIBUTES below.)
  498. //
  499. ULONG BigEnoughToMove;
  500. //
  501. // The following fields are used to verify that an NTFS volume hasn't
  502. // changed. The serial number is stored in the boot sector on disk,
  503. // and the four times are from the standard information field of the
  504. // volume file.
  505. //
  506. LONGLONG VolumeSerialNumber;
  507. LONGLONG VolumeCreationTime;
  508. LONGLONG VolumeLastModificationTime;
  509. LONGLONG VolumeLastChangeTime;
  510. LONGLONG VolumeLastAccessTime;
  511. //
  512. // The following table of unicode values is the case mapping, with the
  513. // size in number of Unicode characters.
  514. //
  515. PWCH UpcaseTable;
  516. ULONG UpcaseTableSize;
  517. //
  518. // This is a pointer to the attribute definitions for the volume
  519. // which are loaded into nonpaged pool.
  520. //
  521. PATTRIBUTE_DEFINITION_COLUMNS AttributeDefinitions;
  522. //
  523. // Convenient constants for the conversion macros
  524. //
  525. ULONG ClusterMask; // BytesPerCluster - 1
  526. ULONG InverseClusterMask; // ~ClusterMask
  527. ULONG ClusterShift; // 2**ClusterShift == BytesPerCluster
  528. ULONG MftShift; //
  529. ULONG MftToClusterShift;
  530. ULONG ClustersPerPage;
  531. ULONG MftReserved;
  532. ULONG MftCushion;
  533. //
  534. // Lfs Log Handle for this volume
  535. //
  536. LFS_LOG_HANDLE LogHandle;
  537. //
  538. // LSNs of the end of the last checkpoint and the last RestartArea.
  539. // Normally the RestartArea Lsn is greater than the other one, however
  540. // if the VcbState indicates that a checkpoint is in progress, then these
  541. // Lsns are in flux.
  542. //
  543. LSN EndOfLastCheckpoint;
  544. LSN LastRestartArea;
  545. LSN LastBaseLsn;
  546. //
  547. // Open attribute table.
  548. //
  549. RESTART_POINTERS OpenAttributeTable;
  550. //
  551. // Transaction table.
  552. //
  553. RESTART_POINTERS TransactionTable;
  554. //
  555. // A table of all the fcb that have been created for this volume.
  556. //
  557. RTL_GENERIC_TABLE FcbTable;
  558. //
  559. // The following fields are used by the BitmpSup routines. The first
  560. // value contains the total number of clusters on the volume, this
  561. // is computed from the boot sector information. The second value
  562. // is the current number of free clusters available for allocation on
  563. // the volume. Allocation is handled by using two MCBs: FreeSpace
  564. // describes some small window of known clusters that are free.
  565. // RecentlyAllocated describes those clusters that have been recently
  566. // allocated.
  567. //
  568. // In addition there are two simply LRU arrays used by BitmpSup to keep
  569. // the size of the corresponding MCB within limits. The array field
  570. // points to an array of lcn entries which is maintained in a round-robin
  571. // lru fashion. The size field denotes the number of Lcn entries
  572. // allocated to the array, and tail and head are indices into the array.
  573. //
  574. // The last field is for storing local volume specific data needed by
  575. // the bitmap routines
  576. //
  577. LONGLONG TotalClusters;
  578. LONGLONG FreeClusters;
  579. LONGLONG DeallocatedClusters;
  580. LARGE_MCB FreeSpaceMcb;
  581. PLCN FreeSpaceLruArray;
  582. ULONG FreeSpaceLruSize;
  583. ULONG FreeSpaceLruTail;
  584. ULONG FreeSpaceLruHead;
  585. LARGE_MCB RecentlyAllocatedMcb;
  586. PLCN RecentlyAllocatedLruArray;
  587. ULONG RecentlyAllocatedLruSize;
  588. ULONG RecentlyAllocatedLruTail;
  589. ULONG RecentlyAllocatedLruHead;
  590. LCN LastBitmapHint; // Last Lcn used for fresh allocation
  591. //
  592. // The following are used to track the deallocated clusters waiting
  593. // for a checkpoint. The pointers are used so we can toggle the
  594. // use of the structures.
  595. //
  596. DEALLOCATED_CLUSTERS DeallocatedClusters1;
  597. DEALLOCATED_CLUSTERS DeallocatedClusters2;
  598. PDEALLOCATED_CLUSTERS PriorDeallocatedClusters;
  599. PDEALLOCATED_CLUSTERS ActiveDeallocatedClusters;
  600. //
  601. // The following field is also used by the bitmap allocation routines
  602. // to keep track of recently deallocated clusters. A cluster that has
  603. // been recently deallocated will not be reallocated until the
  604. // operation (transaction) is complete. That way if the operation
  605. // needs to abort itself the space it had deallocated can easily be
  606. // unwound. NtfsDeallocateClusters adds to this mcb and
  607. // NtfsDeallocateClusterComplete removes entries from it.
  608. //
  609. LARGE_MCB RecentlyDeallocatedMcb;
  610. //
  611. // The following field is used for mft bitmap allocation
  612. //
  613. RECORD_ALLOCATION_CONTEXT MftBitmapAllocationContext;
  614. //
  615. // The following two fields are used by the bitmap routines to determine
  616. // what is called the mft zone. The Mft zone are those clusters on the
  617. // disk were we will try and put the mft and only the mft unless the disk
  618. // is getting too full.
  619. //
  620. LCN MftZoneStart;
  621. LCN MftZoneEnd;
  622. //
  623. // The following string contains the device name for this partition.
  624. //
  625. UNICODE_STRING DeviceName;
  626. //
  627. // The following is the head of a list of notify Irps.
  628. //
  629. LIST_ENTRY DirNotifyList;
  630. //
  631. // The following mutex is used to manage the list of Irps pending
  632. // dir notify.
  633. //
  634. KMUTEX DirNotifyMutex;
  635. //
  636. // The following fields are used for the Mft defrag operation. In addition
  637. // we use the number of free clusters stored earlier in this structure.
  638. //
  639. // The upper and lower thresholds are used to determine if the number of free
  640. // file records in the Mft will cause us to trigger or cease defragging.
  641. //
  642. // The count of free records is based on the size of the Mft and the allocated
  643. // records. The hole count is the count of how many file records are not
  644. // allocated.
  645. //
  646. // The count of the bitmap bits per hole. This is the number of file records
  647. // per hole. Must be converted to clusters to find a hole in the Mft Mcb.
  648. //
  649. ULONG MftDefragUpperThreshold;
  650. ULONG MftDefragLowerThreshold;
  651. ULONG MftFreeRecords;
  652. ULONG MftHoleRecords;
  653. ULONG MftHoleGranularity;
  654. ULONG MftClustersPerHole;
  655. ULONG MftHoleMask;
  656. ULONG MftHoleInverseMask;
  657. } VCB;
  658. typedef VCB *PVCB;
  659. //
  660. // These are the VcbState flags. Synchronized with the Vcb resource.
  661. //
  662. #define VCB_STATE_VOLUME_MOUNTED (0x00000001)
  663. #define VCB_STATE_LOCKED (0x00000002)
  664. #define VCB_STATE_REMOVABLE_MEDIA (0x00000004)
  665. #define VCB_STATE_VOLUME_MOUNTED_DIRTY (0x00000008)
  666. #define VCB_STATE_RESTART_IN_PROGRESS (0x00000010)
  667. #define VCB_STATE_FLAG_SHUTDOWN (0x00000020)
  668. #define VCB_STATE_NO_SECONDARY_AVAILABLE (0x00000040)
  669. #define VCB_STATE_RELOAD_FREE_CLUSTERS (0x00000080)
  670. #define VCB_STATE_ALREADY_BALANCED (0x00000100)
  671. #define VCB_STATE_VOL_PURGE_IN_PROGRESS (0x00000200)
  672. //
  673. // These are the flags for the Mft and the reserveration state.
  674. // Although these are in the Vcb they are synchronized with
  675. // the resource in the MftScb.
  676. //
  677. #define VCB_MFT_RECORD_RESERVED (0x00000001)
  678. #define VCB_MFT_RECORD_15_USED (0x00000002)
  679. //
  680. // These are the MftDefragState flags. Synchronized with the
  681. // CheckpointEvent.
  682. //
  683. #define VCB_MFT_DEFRAG_PERMITTED (0x00000001)
  684. #define VCB_MFT_DEFRAG_ENABLED (0x00000002)
  685. #define VCB_MFT_DEFRAG_TRIGGERED (0x00000004)
  686. #define VCB_MFT_DEFRAG_ACTIVE (0x00000008)
  687. #define VCB_MFT_DEFRAG_EXCESS_MAP (0x00000010)
  688. //
  689. // These are the Checkpoint flags. Synchronized with the
  690. // CheckpointEvent. These flags are in the MftDefragState
  691. // flags field.
  692. //
  693. #define VCB_CHECKPOINT_IN_PROGRESS (0x00000020)
  694. #define VCB_LAST_CHECKPOINT_CLEAN (0x00000040)
  695. //
  696. // This is the maximum number of attributes in a file record which could
  697. // be considered for moving. This value should be changed only in conjunction
  698. // with the initialization of the BigEnoughToMove field above.
  699. //
  700. #define MAX_MOVEABLE_ATTRIBUTES (3)
  701. //
  702. // The Volume Device Object is an I/O system device object with a workqueue
  703. // and an VCB record appended to the end. There are multiple of these
  704. // records, one for every mounted volume, and are created during
  705. // a volume mount operation. The work queue is for handling an overload of
  706. // work requests to the volume.
  707. //
  708. typedef struct _VOLUME_DEVICE_OBJECT {
  709. DEVICE_OBJECT DeviceObject;
  710. //
  711. // The following field tells how many requests for this volume have
  712. // either been enqueued to ExWorker threads or are currently being
  713. // serviced by ExWorker threads. If the number goes above
  714. // a certain threshold, put the request on the overflow queue to be
  715. // executed later.
  716. //
  717. ULONG PostedRequestCount;
  718. //
  719. // The following field indicates the number of IRP's waiting
  720. // to be serviced in the overflow queue.
  721. //
  722. ULONG OverflowQueueCount;
  723. //
  724. // The following field contains the queue header of the overflow queue.
  725. // The Overflow queue is a list of IRP's linked via the IRP's ListEntry
  726. // field.
  727. //
  728. LIST_ENTRY OverflowQueue;
  729. //
  730. // The following spinlock protects access to all the above fields.
  731. //
  732. KSPIN_LOCK OverflowQueueSpinLock;
  733. //
  734. // This is the file system specific volume control block.
  735. //
  736. VCB Vcb;
  737. } VOLUME_DEVICE_OBJECT;
  738. typedef VOLUME_DEVICE_OBJECT *PVOLUME_DEVICE_OBJECT;
  739. //
  740. // This structure is used to contain a link name and connections into
  741. // the splay tree for the parent.
  742. //
  743. typedef struct _NAME_LINK {
  744. UNICODE_STRING LinkName;
  745. RTL_SPLAY_LINKS Links;
  746. } NAME_LINK, *PNAME_LINK;
  747. //
  748. // The Lcb record corresponds to every open path between an Scb and an Fcb.
  749. // It denotes the name which was used to go from the scb to the fcb and
  750. // it also contains a queue of ccbs that have opened the fcb via that name
  751. // and also a queue of Prefix Entries that will get us to this lcb
  752. //
  753. typedef struct _LCB {
  754. //
  755. // Type and size of this record must be NTFS_NTC_LCB
  756. //
  757. NODE_TYPE_CODE NodeTypeCode;
  758. NODE_BYTE_SIZE NodeByteSize;
  759. //
  760. // The links for all the Lcbs that emminate out of an Scb and a pointer
  761. // back to the Scb. Corresponds to Scb->LcbQueue.
  762. //
  763. LIST_ENTRY ScbLinks;
  764. struct _SCB *Scb;
  765. //
  766. // The links for all the Lcbs that go into an Fcb and a pointer
  767. // back to the Fcb. Corresponds to Fcb->LcbQueue.
  768. //
  769. LIST_ENTRY FcbLinks;
  770. struct _FCB *Fcb;
  771. //
  772. // This is the number of unclean handles on this link.
  773. //
  774. ULONG CleanupCount;
  775. //
  776. // This is the number of references to this link. The parent
  777. // Scb must be owned to modify this count.
  778. //
  779. ULONG ReferenceCount;
  780. UCHAR FileNameFlags;
  781. //
  782. // These are the flags for the changes to this link and the
  783. // change count for the duplicated information on this link.
  784. //
  785. UCHAR InfoFlags;
  786. //
  787. // The following are the case-sensitive and case-insensitive
  788. // name links.
  789. //
  790. NAME_LINK IgnoreCaseLink;
  791. NAME_LINK ExactCaseLink;
  792. //
  793. // A queue of Ccbs that have the Fcb (via this edge) opened.
  794. // Corresponds to Ccb->LcbLinks
  795. //
  796. LIST_ENTRY CcbQueue;
  797. //
  798. // Internal state of the Lcb
  799. //
  800. ULONG LcbState;
  801. } LCB;
  802. typedef LCB *PLCB;
  803. #define LCB_STATE_DELETE_ON_CLOSE (0x00000001)
  804. #define LCB_STATE_LINK_IS_GONE (0x00000002)
  805. #define LCB_STATE_EXACT_CASE_IN_TREE (0x00000004)
  806. #define LCB_STATE_IGNORE_CASE_IN_TREE (0x00000008)
  807. #define LcbSplitPrimaryLink( LCB ) \
  808. ((LCB)->FileNameFlags == FILE_NAME_NTFS || (LCB)->FileNameFlags == FILE_NAME_DOS )
  809. #define LcbSplitPrimaryComplement( LCB ) \
  810. (((LCB)->FileNameFlags == FILE_NAME_NTFS) ? FILE_NAME_DOS : FILE_NAME_NTFS)
  811. #define LcbLinkIsDeleted( LCB ) \
  812. ((FlagOn( (LCB)->LcbState, LCB_STATE_DELETE_ON_CLOSE )) \
  813. || ((FlagOn( (LCB)->FileNameFlags, FILE_NAME_DOS | FILE_NAME_NTFS )) \
  814. && (FlagOn( (LCB)->Fcb->FcbState, FCB_STATE_PRIMARY_LINK_DELETED ))))
  815. //
  816. // The Fcb record corresponds to every open file and directory, and to
  817. // every directory on an opened path.
  818. //
  819. // The structure is really divided into two parts. FCB can be allocated
  820. // from paged pool while the SCB must be allocated from non-paged
  821. // pool. There is an SCB for every file stream associated with the Fcb.
  822. //
  823. // Note that the Fcb, multiple Scb records all use the same resource so
  824. // if we need to grab exclusive access to the Fcb we only need to grab one
  825. // resource and we've blocked all the scbs
  826. //
  827. typedef struct _FCB {
  828. //
  829. // Type and size of this record must be NTFS_NTC_FCB
  830. //
  831. NODE_TYPE_CODE NodeTypeCode;
  832. NODE_BYTE_SIZE NodeByteSize;
  833. //
  834. // The Queue of all the Lcb that we are part of. The list is actually
  835. // ordered in a small sense. The get next scb routine that traverses the
  836. // Fcb/Scb graph always will put the current lcb edge that it is traversing
  837. // into the front of this queue.
  838. //
  839. LIST_ENTRY LcbQueue;
  840. //
  841. // A pointer to the Vcb containing this Fcb
  842. //
  843. PVCB Vcb;
  844. //
  845. // The internal state of the Fcb. This is a collection Fcb state flags.
  846. // Also the delete relavent counts for the file.
  847. //
  848. ULONG FcbState;
  849. ULONG FcbDenyDelete;
  850. ULONG FcbDeleteFile;
  851. //
  852. // A count of the number of file objects that have been opened for
  853. // this file, but not yet been cleaned up yet.
  854. // This count gets decremented in NtfsCommonCleanup,
  855. // while the CloseCount below gets decremented in NtfsCommonClose.
  856. //
  857. CLONG CleanupCount;
  858. //
  859. // A count of the number of file objects that have opened
  860. // this file.
  861. //
  862. CLONG CloseCount;
  863. //
  864. // A count of other references to this Fcb.
  865. //
  866. CLONG ReferenceCount;
  867. //
  868. // The following field contains the file reference for the Fcb
  869. //
  870. FILE_REFERENCE FileReference;
  871. //
  872. // A queue of Scb associated with the fcb.
  873. // Corresponds to Scb->FcbLinks
  874. //
  875. LIST_ENTRY ScbQueue;
  876. //
  877. // These are the links for the list of exclusively-owned Scbs off of
  878. // the IrpContext. We need to keep track of the exclusive count
  879. // in the Fcb before our acquire so we know how many times to release it.
  880. //
  881. LIST_ENTRY ExclusiveFcbLinks;
  882. //
  883. // This is the links for all paging Io resources acquired for a transaction.
  884. //
  885. LIST_ENTRY ExclusivePagingIoLinks;
  886. USHORT BaseExclusiveCount;
  887. USHORT BaseExclusivePagingIoCount;
  888. //
  889. // This counts the number of times the Ea's on this file have been
  890. // modified.
  891. //
  892. USHORT EaModificationCount;
  893. //
  894. // The following field is used to store a pointer to the resource
  895. // protecting the Fcb
  896. //
  897. PERESOURCE Resource;
  898. //
  899. // The following field contains a pointer to the resource synchronizing
  900. // a changing FileSize with paging Io.
  901. //
  902. PERESOURCE PagingIoResource;
  903. //
  904. // Copy of the duplicated information for this Fcb.
  905. // Also a flags field to tell us what has changed in the structure.
  906. //
  907. LONGLONG CurrentLastAccess;
  908. DUPLICATED_INFORMATION Info;
  909. ULONG InfoFlags;
  910. ULONG LinkCount;
  911. //
  912. // The following fields contains a pointer to the security descriptor for this
  913. // file. The field can start off null and later be loaded in by any of the
  914. // security support routines. On delete Fcb the field pool should be deallocated
  915. // when the fcb goes away
  916. //
  917. struct _SHARED_SECURITY *SharedSecurity;
  918. ULONG CreateSecurityCount;
  919. //
  920. // This is a pointer to a shared security descriptor for
  921. // a non-index child of this directory. Ignored for non-directory files.
  922. //
  923. struct _SHARED_SECURITY *ChildSharedSecurity;
  924. } FCB;
  925. typedef FCB *PFCB;
  926. #define FCB_STATE_FILE_DELETED (0x00000001)
  927. #define FCB_STATE_NONPAGED (0x00000002)
  928. #define FCB_STATE_PAGING_FILE (0x00000004)
  929. #define FCB_STATE_FROM_PRERESTART (0x00000008)
  930. #define FCB_STATE_DUP_INITIALIZED (0x00000010)
  931. #define FCB_STATE_NO_ACL (0x00000020)
  932. #define FCB_STATE_UPDATE_STD_INFO (0x00000040)
  933. #define FCB_STATE_PRIMARY_LINK_DELETED (0x00000080)
  934. #define FCB_STATE_EA_SCB_INVALID (0x00000100)
  935. #define FCB_STATE_IN_FCB_TABLE (0x00000200)
  936. #define FCB_STATE_MODIFIED_SECURITY (0x00000400)
  937. #define FCB_INFO_CHANGED_CREATE (0x00000001)
  938. #define FCB_INFO_CHANGED_LAST_MOD (0x00000002)
  939. #define FCB_INFO_CHANGED_LAST_CHANGE (0x00000004)
  940. #define FCB_INFO_CHANGED_LAST_ACCESS (0x00000008)
  941. #define FCB_INFO_CHANGED_ALLOC_SIZE (0x00000010)
  942. #define FCB_INFO_CHANGED_FILE_SIZE (0x00000020)
  943. #define FCB_INFO_CHANGED_FILE_ATTR (0x00000040)
  944. #define FCB_INFO_CHANGED_EA_SIZE (0x00000080)
  945. #define FCB_CREATE_SECURITY_COUNT (5)
  946. #define FCB_LARGE_ACL_SIZE (512)
  947. //
  948. // The following three structures are the separate union structures for
  949. // Scb structure.
  950. //
  951. typedef struct _SCB_DATA {
  952. //
  953. // The following field is used by the oplock module
  954. // to maintain current oplock information.
  955. //
  956. OPLOCK Oplock;
  957. //
  958. // The following field is used by the filelock module
  959. // to maintain current byte range locking information.
  960. //
  961. PFILE_LOCK FileLock;
  962. //
  963. // Share Access structure for this stream. May not be present
  964. // in this Scb. Check the flag in the Scb.
  965. //
  966. SHARE_ACCESS ShareAccess;
  967. } SCB_DATA, *PSCB_DATA;
  968. typedef struct _SCB_INDEX {
  969. //
  970. // This is a list of records within the index allocation stream which
  971. // have been deallocated in the current transaction.
  972. //
  973. LIST_ENTRY RecentlyDeallocatedQueue;
  974. //
  975. // A queue of all the lcbs that are opened under this Scb.
  976. // Corresponds to Lcb->ScbLinks
  977. //
  978. LIST_ENTRY LcbQueue;
  979. //
  980. // A change count incremented every time an index buffer is deleted.
  981. //
  982. ULONG ChangeCount;
  983. //
  984. // Type of attribute being indexed.
  985. //
  986. ATTRIBUTE_TYPE_CODE AttributeBeingIndexed;
  987. //
  988. // Collation rule, for how the indexed attribute is collated.
  989. //
  990. ULONG CollationRule;
  991. //
  992. // Size of Index Allocation Buffer in bytes, or 0 if not yet
  993. // initialized.
  994. //
  995. ULONG BytesPerIndexBuffer;
  996. //
  997. // Size of Index Allocation Buffers in units of clusters, or 0
  998. // if not yet initialized.
  999. //
  1000. UCHAR ClustersPerIndexBuffer;
  1001. //
  1002. // Flag to indicate whether the RecordAllocationContext has been
  1003. // initialized or not. If it is not initialized, this means
  1004. // either that there is no external index allocation, or that
  1005. // it simply has not been initialized yet.
  1006. //
  1007. BOOLEAN AllocationInitialized;
  1008. //
  1009. // Index Depth Hint
  1010. //
  1011. USHORT IndexDepthHint;
  1012. //
  1013. // Record allocation context, for managing the allocation of the
  1014. // INDEX_ALLOCATION_ATTRIBUTE, if one exists.
  1015. //
  1016. RECORD_ALLOCATION_CONTEXT RecordAllocationContext;
  1017. //
  1018. // The following are the splay links of Lcbs opened under this
  1019. // Scb. Note that not all of the Lcb in the list above may
  1020. // be in the splay links below.
  1021. //
  1022. PRTL_SPLAY_LINKS ExactCaseNode;
  1023. PRTL_SPLAY_LINKS IgnoreCaseNode;
  1024. //
  1025. // Share access structure for this file.
  1026. //
  1027. SHARE_ACCESS ShareAccess;
  1028. } SCB_INDEX, *PSCB_INDEX;
  1029. typedef struct _SCB_MFT {
  1030. //
  1031. // This is a list of records within the Mft Scb stream which
  1032. // have been deallocated in the current transaction.
  1033. //
  1034. LIST_ENTRY RecentlyDeallocatedQueue;
  1035. //
  1036. // The following field contains index of a reserved free record. To
  1037. // keep us out of the chicken & egg problem of the Mft being able to
  1038. // be self mapping we added the ability to reserve an mft record
  1039. // to describe additional mft data allocation within previous mft
  1040. // run. A value of zero means that index has not been reserved.
  1041. //
  1042. ULONG ReservedIndex;
  1043. //
  1044. // The following Mcb's are used to track clusters being added and removed
  1045. // from the Mcb for the Scb. This Scb must always be fully loaded after
  1046. // an abort. We can't depend on reloading on the next LookupAllocation
  1047. // call. Instead we keep one Mcb with the clusters added and one Mcb
  1048. // with the clusters removed. During the restore phase of abort we
  1049. // will adjust the Mft Mcb by reversing the operations done during the
  1050. // transactions.
  1051. //
  1052. LARGE_MCB AddedClusters;
  1053. LARGE_MCB RemovedClusters;
  1054. //
  1055. // The following are the changes made to the Mft file as file records are added,
  1056. // freed or allocated. Also the change in the number of file records which are
  1057. // part of holes.
  1058. //
  1059. LONG FreeRecordChange;
  1060. LONG HoleRecordChange;
  1061. } SCB_MFT, *PSCB_MFT;
  1062. //
  1063. // The following is the non-paged part of the scb.
  1064. //
  1065. typedef struct _SCB_NONPAGED {
  1066. //
  1067. // Type and size of this record must be NTFS_NTC_SCB_NONPAGED
  1068. //
  1069. NODE_TYPE_CODE NodeTypeCode;
  1070. NODE_BYTE_SIZE NodeByteSize;
  1071. //
  1072. // The following field contains a record of special pointers used by
  1073. // MM and Cache to manipluate section objects. Note that the values
  1074. // are set outside of the file system. However the file system on an
  1075. // open/create will set the file object's SectionObject field to point
  1076. // to this field
  1077. //
  1078. SECTION_OBJECT_POINTERS SegmentObject;
  1079. //
  1080. // Index allocated for this file in the Open Attribute Table.
  1081. //
  1082. ULONG OpenAttributeTableIndex;
  1083. //
  1084. // Copy of the Vcb pointer so we can find the Vcb in the dirty page callback
  1085. // routine.
  1086. //
  1087. PVCB Vcb;
  1088. } SCB_NONPAGED, *PSCB_NONPAGED;
  1089. //
  1090. // The following structure is the stream control block. There can
  1091. // be multiple records per fcb. One is created for each attribute being
  1092. // handled as a stream file.
  1093. //
  1094. typedef struct _SCB {
  1095. //
  1096. // The following field is used for fast I/O. It contains the node type code
  1097. // and size, indicates if fast I/O is possible, contains allocation, file,
  1098. // and valid data size, a resource, and call back pointers for FastIoRead and
  1099. // FastMdlRead.
  1100. //
  1101. // The node type codes for the Scb must be either NTFS_NTC_SCB_INDEX,
  1102. // NTFS_NTC_SCB_ROOT_INDEX, or NTFS_NTC_SCB_DATA. Which one it is determines
  1103. // the state of the union below.
  1104. //
  1105. FSRTL_COMMON_FCB_HEADER Header;
  1106. //
  1107. // The links for the queue of Scb off of a given Fcb. And a pointer back
  1108. // to the Fcb. Corresponds to Fcb->ScbQueue
  1109. //
  1110. LIST_ENTRY FcbLinks;
  1111. PFCB Fcb;
  1112. //
  1113. // A pointer to the Vcb containing this Scb
  1114. //
  1115. PVCB Vcb;
  1116. //
  1117. // The internal state of the Scb.
  1118. //
  1119. ULONG ScbState;
  1120. //
  1121. // The following two fields identify the actual attribute for this
  1122. // Scb with respect to its file. We identify the attribute by
  1123. // its type code and name.
  1124. //
  1125. ATTRIBUTE_TYPE_CODE AttributeTypeCode;
  1126. UNICODE_STRING AttributeName;
  1127. //
  1128. // Stream File Object for internal use. This field is NULL if the file
  1129. // stream is not being accessed internally.
  1130. //
  1131. PFILE_OBJECT FileObject;
  1132. //
  1133. // A count of the number of file objects that have been opened for
  1134. // this attribute, but not yet been cleaned up yet.
  1135. // This count gets decremented in NtfsCommonCleanup,
  1136. // while the CloseCount below gets decremented in NtfsCommonClose.
  1137. //
  1138. CLONG CleanupCount;
  1139. //
  1140. // A count of the number of file objects that have opened
  1141. // this attribute.
  1142. //
  1143. CLONG CloseCount;
  1144. //
  1145. // This pointer is used to detect writes that eminated from the
  1146. // cache manager's worker thread. It prevents lazy writer threads,
  1147. // who already have the Fcb shared, from trying to acquire it
  1148. // exclusive, and thus causing a deadlock.
  1149. //
  1150. PVOID LazyWriteThread;
  1151. //
  1152. // Pointer to structure containing snapshotted Scb values, or NULL
  1153. // if the values have not been snapshotted.
  1154. //
  1155. struct _SCB_SNAPSHOT * ScbSnapshot;
  1156. //
  1157. // First unknown Vcn in the Mcb. This field is maintained every time
  1158. // allocation is looked up by someone currently holding the Scb exclusive,
  1159. // in order to not "reload" space into the Mcb when deleting files with
  1160. // multiple file records.
  1161. //
  1162. VCN FirstUnknownVcn;
  1163. //
  1164. // The following field contains the mcb for this Scb
  1165. //
  1166. LARGE_MCB Mcb;
  1167. //
  1168. // Pointer to the non-paged section objects and open attribute
  1169. // table index.
  1170. //
  1171. PSCB_NONPAGED NonpagedScb;
  1172. //
  1173. // Compression unit from attribute record.
  1174. //
  1175. ULONG CompressionUnit;
  1176. //
  1177. // Highest Vcn written to disk, important for file compression.
  1178. //
  1179. VCN HighestVcnToDisk;
  1180. //
  1181. // Number of clusters added due to Split Mcb calls. The user has
  1182. // not asked for this allocation.
  1183. //
  1184. LONGLONG ExcessFromSplitMcb;
  1185. //
  1186. // Scb Type union, for different types of Scbs
  1187. //
  1188. union {
  1189. SCB_DATA Data;
  1190. SCB_INDEX Index;
  1191. SCB_MFT Mft;
  1192. } ScbType;
  1193. } SCB;
  1194. typedef SCB *PSCB;
  1195. #define SIZEOF_SCB_DATA (FIELD_OFFSET( SCB, ScbType ) + FIELD_OFFSET( SCB_DATA, ShareAccess ))
  1196. #define SIZEOF_SCB_SHARE_DATA (FIELD_OFFSET( SCB, ScbType ) + sizeof( SCB_DATA ))
  1197. #define SIZEOF_SCB_INDEX (FIELD_OFFSET( SCB, ScbType ) + sizeof( SCB_INDEX ))
  1198. #define SIZEOF_SCB_MFT (FIELD_OFFSET( SCB, ScbType ) + sizeof( SCB_MFT ))
  1199. #define SCB_STATE_TRUNCATE_ON_CLOSE (0x00000001)
  1200. #define SCB_STATE_DELETE_ON_CLOSE (0x00000002)
  1201. #define SCB_STATE_CHECK_ATTRIBUTE_SIZE (0x00000004)
  1202. #define SCB_STATE_ATTRIBUTE_RESIDENT (0x00000008)
  1203. #define SCB_STATE_UNNAMED_DATA (0x00000010)
  1204. #define SCB_STATE_HEADER_INITIALIZED (0x00000020)
  1205. #define SCB_STATE_NONPAGED (0x00000040)
  1206. #define SCB_STATE_USA_PRESENT (0x00000080)
  1207. #define SCB_STATE_INTERNAL_ATTR_STREAM (0x00000100)
  1208. #define SCB_STATE_ATTRIBUTE_DELETED (0x00000200)
  1209. #define SCB_STATE_FILE_SIZE_LOADED (0x00000400)
  1210. #define SCB_STATE_MODIFIED_NO_WRITE (0x00000800)
  1211. #define SCB_STATE_USE_PAGING_IO_RESOURCE (0x00001000)
  1212. #define SCB_STATE_CC_HAS_PAGING_IO_RESOURCE (0x00002000)
  1213. #define SCB_STATE_CREATE_MODIFIED_SCB (0x00004000)
  1214. #define SCB_STATE_UNINITIALIZE_ON_RESTORE (0x00008000)
  1215. #define SCB_STATE_RESTORE_UNDERWAY (0x00010000)
  1216. #define SCB_STATE_SHARE_ACCESS (0x00020000)
  1217. #define SCB_STATE_NOTIFY_ADD_STREAM (0x00040000)
  1218. #define SCB_STATE_NOTIFY_REMOVE_STREAM (0x00080000)
  1219. #define SCB_STATE_NOTIFY_RESIZE_STREAM (0x00100000)
  1220. #define SCB_STATE_NOTIFY_MODIFY_STREAM (0x00200000)
  1221. #define SCB_STATE_TEMPORARY (0x00400000)
  1222. #define SCB_STATE_COMPRESSED (0x00800000)
  1223. #define SCB_STATE_REALLOCATE_ON_WRITE (0x01000000)
  1224. #define SCB_STATE_DELAY_CLOSE (0x02000000)
  1225. #define MAX_SCB_ASYNC_ACQUIRE (0xf000)
  1226. //
  1227. // Structure to contain snapshotted Scb values for error recovery.
  1228. //
  1229. typedef struct _SCB_SNAPSHOT {
  1230. //
  1231. // Links for list snapshot structures off of IrpContext
  1232. //
  1233. LIST_ENTRY SnapshotLinks;
  1234. //
  1235. // Saved values of the corresponding Scb (or FsRtl Header) fields
  1236. // The low bit of allocation size is set to remember when the
  1237. // attribute was resident. The next bit, bit 1, is set to remember
  1238. // when the attribute was compressed.
  1239. //
  1240. LONGLONG AllocationSize;
  1241. LONGLONG FileSize;
  1242. LONGLONG ValidDataLength;
  1243. VCN LowestModifiedVcn;
  1244. //
  1245. // Compression Unit
  1246. //
  1247. ULONG CompressionUnit;
  1248. //
  1249. // Pointer to the Scb which has been snapped.
  1250. //
  1251. PSCB Scb;
  1252. } SCB_SNAPSHOT;
  1253. typedef SCB_SNAPSHOT *PSCB_SNAPSHOT;
  1254. //
  1255. // The Ccb record is allocated for every file object
  1256. //
  1257. typedef struct _CCB {
  1258. //
  1259. // Type and size of this record (must be NTFS_NTC_CCB)
  1260. //
  1261. NODE_TYPE_CODE NodeTypeCode;
  1262. NODE_BYTE_SIZE NodeByteSize;
  1263. //
  1264. // The query template is used to filter directory query requests.
  1265. // It originally is set to null and on the first call the NtQueryDirectory
  1266. // it is set the the input filename or "*" if no name is supplied.
  1267. // All subsquent queries then use this template.
  1268. //
  1269. ULONG QueryLength;
  1270. PVOID QueryBuffer;
  1271. //
  1272. // The last returned value. A copy of an IndexEntry is saved. We only
  1273. // grow this buffer, to avoid always deallocating and reallocating.
  1274. //
  1275. ULONG IndexEntryLength;
  1276. PINDEX_ENTRY IndexEntry;
  1277. //
  1278. // Pointer to the index context structure for enumerations
  1279. //
  1280. struct _INDEX_CONTEXT *IndexContext;
  1281. //
  1282. // This is the offset of the next Ea to return to the user.
  1283. //
  1284. ULONG NextEaOffset;
  1285. //
  1286. // This is the Ccb Ea modification count. If this count is in
  1287. // sync with the Fcb value, then the above offset is valid.
  1288. //
  1289. USHORT EaModificationCount;
  1290. //
  1291. // Ccb flags.
  1292. //
  1293. ULONG Flags;
  1294. //
  1295. // The links for the queue of Ccb off of a given Lcb and a pointer
  1296. // back to the Lcb. Corresponds to Lcb->CcbQueue
  1297. //
  1298. LIST_ENTRY LcbLinks;
  1299. PLCB Lcb;
  1300. //
  1301. // This is a unicode string for the full filename used to
  1302. // open this file.
  1303. //
  1304. UNICODE_STRING FullFileName;
  1305. USHORT LastFileNameOffset;
  1306. } CCB;
  1307. typedef CCB *PCCB;
  1308. #define CCB_FLAG_IGNORE_CASE (0x00000001)
  1309. #define CCB_FLAG_OPEN_AS_FILE (0x00000002)
  1310. #define CCB_FLAG_WILDCARD_IN_EXPRESSION (0x00000004)
  1311. #define CCB_FLAG_OPEN_BY_FILE_ID (0x00000008)
  1312. #define CCB_FLAG_USER_SET_LAST_MOD_TIME (0x00000010)
  1313. #define CCB_FLAG_USER_SET_LAST_CHANGE_TIME (0x00000020)
  1314. #define CCB_FLAG_USER_SET_LAST_ACCESS_TIME (0x00000040)
  1315. #define CCB_FLAG_TRAVERSE_CHECK (0x00000080)
  1316. #define CCB_FLAG_RETURN_DOT (0x00000100)
  1317. #define CCB_FLAG_RETURN_DOTDOT (0x00000200)
  1318. #define CCB_FLAG_DOT_RETURNED (0x00000400)
  1319. #define CCB_FLAG_DOTDOT_RETURNED (0x00000800)
  1320. #define CCB_FLAG_DELETE_FILE (0x00001000)
  1321. #define CCB_FLAG_DENY_DELETE (0x00002000)
  1322. #define CCB_FLAG_ALLOCATED_FILE_NAME (0x00004000)
  1323. #define CCB_FLAG_CLEANUP (0x00008000)
  1324. //
  1325. // The Irp Context record is allocated for every orginating Irp. It is
  1326. // created by the Fsd dispatch routines, and deallocated by the NtfsComplete
  1327. // request routine.
  1328. //
  1329. typedef struct _IRP_CONTEXT {
  1330. //
  1331. // Type and size of this record (must be NTFS_NTC_IRP_CONTEXT)
  1332. //
  1333. // NOTE: THIS STRUCTURE MUST REMAIN 64-bit ALIGNED IN SIZE, SINCE
  1334. // IT IS ZONE ALLOCATED
  1335. //
  1336. NODE_TYPE_CODE NodeTypeCode;
  1337. NODE_BYTE_SIZE NodeByteSize;
  1338. //
  1339. // This structure is used for posting to the Ex worker threads.
  1340. //
  1341. WORK_QUEUE_ITEM WorkQueueItem;
  1342. //
  1343. // This is a list of exclusively-owned Scbs which may only be
  1344. // released after the transaction is committed.
  1345. //
  1346. LIST_ENTRY ExclusiveFcbList;
  1347. //
  1348. // This is a list of exclusively-owned paging Io resources which may only be
  1349. // released after the transaction is committed.
  1350. //
  1351. LIST_ENTRY ExclusivePagingIoList;
  1352. //
  1353. // This structure contains the first ScbSnapshot for a modifying
  1354. // request which acquires files exclusive and snaps Scb values.
  1355. // If the SnapshotLinks field contains NULLs, then no data has
  1356. // been snapshot for this request, and the list is empty. If
  1357. // the links are not NULL, then this snapshot structure is in
  1358. // use. If the SnapshotLinks are not NULL, and do not represent
  1359. // an empty list, then there are addtional dynamically allocated
  1360. // snapshot structures in this list.
  1361. //
  1362. SCB_SNAPSHOT ScbSnapshot;
  1363. //
  1364. // This is the Last Restart Area Lsn captured from the Vcb at
  1365. // the time log file full was raised. The caller will force
  1366. // a checkpoint if this has not changed by the time he gets
  1367. // the global resource exclusive.
  1368. //
  1369. LSN LastRestartArea;
  1370. //
  1371. // A pointer to the originating Irp. We will store the Scb for
  1372. // delayed or async closes here while the request is queued.
  1373. //
  1374. PIRP OriginatingIrp;
  1375. //
  1376. // Originating Device (required for workque algorithms)
  1377. //
  1378. PDEVICE_OBJECT RealDevice;
  1379. //
  1380. // Major and minor function codes copied from the Irp
  1381. //
  1382. UCHAR MajorFunction;
  1383. UCHAR MinorFunction;
  1384. //
  1385. // Irp Context flags
  1386. //
  1387. ULONG Flags;
  1388. //
  1389. // The following field contains the NTSTATUS value used when we are
  1390. // unwinding due to an exception. We will temporarily store the Ccb
  1391. // for a delayed or deferred close here while the request is queued.
  1392. //
  1393. NTSTATUS ExceptionStatus;
  1394. //
  1395. // Transaction Id for this request, which must be qualified by Vcb.
  1396. // We will store the type of open for a delayed or async close here
  1397. // while the request is queued.
  1398. //
  1399. PVCB Vcb;
  1400. TRANSACTION_ID TransactionId;
  1401. //
  1402. // The following field is used to maintain a queue of records that have been
  1403. // deallocated while processing this irp context.
  1404. //
  1405. LIST_ENTRY RecentlyDeallocatedQueue;
  1406. //
  1407. // The following union contains pointers to the IoContext for I/O based requests
  1408. // and a pointer to a security context for requests which need to capture the
  1409. // subject context in the calling thread.
  1410. //
  1411. union {
  1412. //
  1413. // The following context block is used for non-cached Io.
  1414. //
  1415. struct _NTFS_IO_CONTEXT *NtfsIoContext;
  1416. //
  1417. // The following is the captured subject context.
  1418. //
  1419. PSECURITY_SUBJECT_CONTEXT SubjectContext;
  1420. } Union;
  1421. //
  1422. // This is the IrpContext for the top level request.
  1423. //
  1424. struct _IRP_CONTEXT *TopLevelIrpContext;
  1425. } IRP_CONTEXT;
  1426. typedef IRP_CONTEXT *PIRP_CONTEXT;
  1427. #define IRP_CONTEXT_FLAG_FROM_POOL (0x00000002)
  1428. #define IRP_CONTEXT_FLAG_WAIT (0x00000004)
  1429. #define IRP_CONTEXT_FLAG_WRITE_THROUGH (0x00000008)
  1430. #define IRP_CONTEXT_LARGE_ALLOCATION (0x00000010)
  1431. #define IRP_CONTEXT_DEFERRED_WRITE (0x00000020)
  1432. #define IRP_CONTEXT_FLAG_ALLOC_CONTEXT (0x00000040)
  1433. #define IRP_CONTEXT_FLAG_ALLOC_SECURITY (0x00000080)
  1434. #define IRP_CONTEXT_MFT_RECORD_15_USED (0x00000100)
  1435. #define IRP_CONTEXT_MFT_RECORD_RESERVED (0x00000200)
  1436. #define IRP_CONTEXT_FLAG_IN_FSP (0x00000400)
  1437. #define IRP_CONTEXT_FLAG_RAISED_STATUS (0x00000800)
  1438. #define IRP_CONTEXT_FLAG_IN_TEARDOWN (0x00001000)
  1439. #define IRP_CONTEXT_FLAG_ACQUIRE_VCB_EX (0x00002000)
  1440. #define IRP_CONTEXT_FLAG_READ_ONLY_FO (0x00004000)
  1441. //
  1442. // The top level context is used to determine whether this request has other
  1443. // requests below it on the stack.
  1444. //
  1445. typedef struct _TOP_LEVEL_CONTEXT {
  1446. BOOLEAN TopLevelRequest;
  1447. ULONG Ntfs;
  1448. VCN VboBeingHotFixed;
  1449. PSCB ScbBeingHotFixed;
  1450. PIRP SavedTopLevelIrp;
  1451. PIRP_CONTEXT TopLevelIrpContext;
  1452. } TOP_LEVEL_CONTEXT;
  1453. typedef TOP_LEVEL_CONTEXT *PTOP_LEVEL_CONTEXT;
  1454. //
  1455. // The found attribute part of the attribute enumeration context describes
  1456. // an attribute record that had been located or created. It may refer to
  1457. // either a base or attribute list.
  1458. //
  1459. typedef struct _FOUND_ATTRIBUTE {
  1460. //
  1461. // The following identify the attribute which was mapped. These are
  1462. // necessary if forcing the range of bytes into memory by pinning.
  1463. // These include the Bcb on which the attribute was read (if this field
  1464. // is NULL, this is the initial attribute) and the offset of the
  1465. // record segment in the Mft.
  1466. //
  1467. PBCB Bcb;
  1468. LONGLONG MftFileOffset;
  1469. //
  1470. // Pointer to the Attribute Record
  1471. //
  1472. PATTRIBUTE_RECORD_HEADER Attribute;
  1473. //
  1474. // Pointer to the containing record segment.
  1475. //
  1476. PFILE_RECORD_SEGMENT_HEADER FileRecord;
  1477. //
  1478. // Some state information.
  1479. //
  1480. BOOLEAN AttributeDeleted;
  1481. BOOLEAN AttributeAllocationDeleted;
  1482. } FOUND_ATTRIBUTE;
  1483. typedef FOUND_ATTRIBUTE *PFOUND_ATTRIBUTE;
  1484. //
  1485. // The structure guides enumeration through the attribute list.
  1486. //
  1487. typedef struct _ATTRIBUTE_LIST_CONTEXT {
  1488. //
  1489. // This field is used to remember the location of the Attribute
  1490. // List attribute within the base file record, if existent.
  1491. //
  1492. PATTRIBUTE_RECORD_HEADER AttributeList;
  1493. //
  1494. // A Bcb for the attribute list.
  1495. //
  1496. PBCB Bcb;
  1497. //
  1498. // This points to the first entry in the attribute list. This is
  1499. // needed when the attribute list is non-resident.
  1500. //
  1501. PATTRIBUTE_LIST_ENTRY FirstEntry;
  1502. //
  1503. // This points to the first attribute list entry; it is advanced
  1504. // when we are searching for a particular exteral attribute.
  1505. //
  1506. PATTRIBUTE_LIST_ENTRY Entry;
  1507. //
  1508. // This points just beyond the final attribute list entry.
  1509. //
  1510. PATTRIBUTE_LIST_ENTRY BeyondFinalEntry;
  1511. } ATTRIBUTE_LIST_CONTEXT;
  1512. typedef ATTRIBUTE_LIST_CONTEXT *PATTRIBUTE_LIST_CONTEXT;
  1513. //
  1514. // The Attribute Enumeration Context structure returns information on an
  1515. // attribute which has been found by one of the Attribute Lookup or Creation
  1516. // routines. It is also used as an IN OUT structure to perform further
  1517. // lookups/modifications to attributes. It does not have a node type code
  1518. // and size since it is usually allocated on the caller's stack.
  1519. //
  1520. typedef struct _ATTRIBUTE_ENUMERATION_CONTEXT {
  1521. //
  1522. // Contains the actual attribute we found.
  1523. //
  1524. FOUND_ATTRIBUTE FoundAttribute;
  1525. //
  1526. // Allows enumeration through the attribute list.
  1527. //
  1528. ATTRIBUTE_LIST_CONTEXT AttributeList;
  1529. } ATTRIBUTE_ENUMERATION_CONTEXT;
  1530. typedef ATTRIBUTE_ENUMERATION_CONTEXT *PATTRIBUTE_ENUMERATION_CONTEXT;
  1531. //
  1532. // Define struct which will be used to remember the path that was followed
  1533. // to locate a given INDEX_ENTRY or insertion point for an INDEX_ENTRY.
  1534. // This structure is always filled in by LookupIndexEntry.
  1535. //
  1536. // The Index Lookup Stack is generally allocated as a local variable in
  1537. // one of the routines in this module that may be called from another module.
  1538. // A pointer to this stack is then passed in to some of the internal routines.
  1539. //
  1540. // The first entry in the stack describes context in the INDEX attribute in the
  1541. // file record, and all subsequent stack entries refer to Index buffers in
  1542. // the INDEX_ALLOCATION attribute.
  1543. //
  1544. // Outside of indexsup.c, this structure should only be passed as an "opaque"
  1545. // context, and individual fields should not be referenced.
  1546. //
  1547. typedef struct _INDEX_LOOKUP_STACK {
  1548. //
  1549. // Bcb pointer for the Index Buffer. In the "bottom" (first entry) of
  1550. // the stack this field contains a NULL, and the Bcb must be found via
  1551. // the Attribute Enumeration Context.
  1552. //
  1553. PBCB Bcb;
  1554. //
  1555. // Pointer to the start of the File Record or Index Buffer
  1556. //
  1557. PVOID StartOfBuffer;
  1558. //
  1559. // Pointer to Index Header in the File Record or Index Buffer
  1560. //
  1561. PINDEX_HEADER IndexHeader;
  1562. //
  1563. // Pointer to to the current INDEX_ENTRY on search path
  1564. //
  1565. PINDEX_ENTRY IndexEntry;
  1566. //
  1567. // Vcn of IndexBuffer
  1568. //
  1569. VCN Vcn;
  1570. //
  1571. // Saved Lsn for faster enumerations
  1572. //
  1573. LSN CapturedLsn;
  1574. } INDEX_LOOKUP_STACK;
  1575. typedef INDEX_LOOKUP_STACK *PINDEX_LOOKUP_STACK;
  1576. #define INDEX_LOOKUP_STACK_SIZE (3)
  1577. //
  1578. // Index Context structure.
  1579. //
  1580. // This structure maintains a context which describes the lookup stack to a
  1581. // given index entry. It includes the Attribute Enumeration Context for the
  1582. // Index Root, the Index lookup stack remembering the path to the index entry,
  1583. // and the current stack pointer within the stack pointing to the stack entry
  1584. // for the current index entry or where we are at in a bucket split or delete
  1585. // operation.
  1586. //
  1587. // Outside of indexsup.c, this structure should only be passed as an "opaque"
  1588. // context, and individual fields should not be referenced.
  1589. //
  1590. typedef struct _INDEX_CONTEXT {
  1591. //
  1592. // Index lookup stack.
  1593. //
  1594. INDEX_LOOKUP_STACK LookupStack[INDEX_LOOKUP_STACK_SIZE];
  1595. //
  1596. // Base of dynamically allocated lookup stack - either points
  1597. // to the one above or a dynamically allocated larger one.
  1598. //
  1599. PINDEX_LOOKUP_STACK Base;
  1600. //
  1601. // Stack pointer within the Index Lookup Stack
  1602. //
  1603. PINDEX_LOOKUP_STACK Current;
  1604. //
  1605. // Stack pointer to top of Lookup Stack. This field essentially
  1606. // remembers how deep the index Btree is.
  1607. //
  1608. PINDEX_LOOKUP_STACK Top;
  1609. //
  1610. // Captured Scb (Index type) change count
  1611. //
  1612. ULONG ScbChangeCount;
  1613. //
  1614. // This field remembers where the index root attribute was last
  1615. // seen, to support correct operation of FindMoveableIndexRoot.
  1616. //
  1617. PATTRIBUTE_RECORD_HEADER OldAttribute;
  1618. //
  1619. // Number of entries allocated in the lookup stack.
  1620. //
  1621. USHORT NumberEntries;
  1622. //
  1623. // Reserved...
  1624. //
  1625. USHORT Reserved;
  1626. //
  1627. // Attribute Enumeration Context for the Index Root
  1628. //
  1629. ATTRIBUTE_ENUMERATION_CONTEXT AttributeContext;
  1630. } INDEX_CONTEXT;
  1631. typedef INDEX_CONTEXT *PINDEX_CONTEXT;
  1632. //
  1633. // Context structure for asynchronous I/O calls. Most of these fields
  1634. // are actually only required for the Read/Write Multiple routines, but
  1635. // the caller must allocate one as a local variable anyway before knowing
  1636. // whether there are multiple requests are not. Therefore, a single
  1637. // structure is used for simplicity.
  1638. //
  1639. typedef struct _NTFS_IO_CONTEXT {
  1640. //
  1641. // These two fields are used for multiple run Io
  1642. //
  1643. LONG IrpCount;
  1644. PIRP MasterIrp;
  1645. UCHAR IrpSpFlags;
  1646. BOOLEAN AllocatedContext;
  1647. union {
  1648. //
  1649. // This element handles the asynchronous non-cached Io
  1650. //
  1651. struct {
  1652. PERESOURCE Resource;
  1653. ERESOURCE_THREAD ResourceThreadId;
  1654. ULONG RequestedByteCount;
  1655. } Async;
  1656. //
  1657. // and this element handles the synchronous non-cached Io.
  1658. //
  1659. KEVENT SyncEvent;
  1660. } Wait;
  1661. } NTFS_IO_CONTEXT;
  1662. typedef NTFS_IO_CONTEXT *PNTFS_IO_CONTEXT;
  1663. //
  1664. // An array of these structures is passed to NtfsMultipleAsync describing
  1665. // a set of runs to execute in parallel.
  1666. //
  1667. typedef struct _IO_RUN {
  1668. VBO StartingVbo;
  1669. LBO StartingLbo;
  1670. ULONG BufferOffset;
  1671. ULONG ByteCount;
  1672. PIRP SavedIrp;
  1673. } IO_RUN;
  1674. typedef IO_RUN *PIO_RUN;
  1675. //
  1676. // This structure is used by the name manipulation routines to described a
  1677. // parsed file name componant.
  1678. //
  1679. typedef struct _NTFS_NAME_DESCRIPTOR {
  1680. //
  1681. // The follow flag tells which fields were present in the name.
  1682. //
  1683. ULONG FieldsPresent;
  1684. UNICODE_STRING FileName;
  1685. UNICODE_STRING AttributeType;
  1686. UNICODE_STRING AttributeName;
  1687. ULONG VersionNumber;
  1688. } NTFS_NAME_DESCRIPTOR;
  1689. typedef NTFS_NAME_DESCRIPTOR *PNTFS_NAME_DESCRIPTOR;
  1690. //
  1691. // Define the bits in FieldsPresent above.
  1692. //
  1693. #define FILE_NAME_PRESENT_FLAG (1)
  1694. #define ATTRIBUTE_TYPE_PRESENT_FLAG (2)
  1695. #define ATTRIBUTE_NAME_PRESENT_FLAG (4)
  1696. #define VERSION_NUMBER_PRESENT_FLAG (8)
  1697. //
  1698. // The following is used to perform Ea related routines.
  1699. //
  1700. typedef struct _EA_LIST_HEADER {
  1701. //
  1702. // The size of buffer needed to pack these Ea's
  1703. //
  1704. ULONG PackedEaSize;
  1705. //
  1706. // This is the count of Ea's with their NEED_EA
  1707. // bit set.
  1708. //
  1709. USHORT NeedEaCount;
  1710. //
  1711. // The size of the buffer needed to return all Ea's
  1712. // in their unpacked form.
  1713. //
  1714. ULONG UnpackedEaSize;
  1715. //
  1716. // This is the size of the buffer used to store the ea's
  1717. //
  1718. ULONG BufferSize;
  1719. //
  1720. // This is the pointer to the first entry in the list.
  1721. //
  1722. PFILE_FULL_EA_INFORMATION FullEa;
  1723. } EA_LIST_HEADER;
  1724. typedef EA_LIST_HEADER *PEA_LIST_HEADER;
  1725. //
  1726. // The following structure is used to maintain a list of recently deallocated
  1727. // records so that the file system will not reuse a recently deallocated record
  1728. // until it is safe to do so. Each instance of this structure is placed on
  1729. // two queues. One queue is per index SCB and the other queue is per Irp Context.
  1730. //
  1731. // Whenever we delete a record we allocate a new structure if necessary and add
  1732. // it to the scb queue and the irp context queue. We indicate in the structure
  1733. // the index of the record we just deallocated.
  1734. //
  1735. // Whenever we need to allocate a new record we filter out any canidate we want
  1736. // to allocate to avoid allocating one in the scb's recently deallocated queue.
  1737. //
  1738. // Whenever we delete an irp context we scan through its recently deallocated
  1739. // queue removing it from the scb queue.
  1740. //
  1741. #define DEALLOCATED_RECORD_ENTRIES 32
  1742. typedef struct _DEALLOCATED_RECORDS {
  1743. //
  1744. // The following field links this structure into the Scb->RecentlyDeallocatedQueue
  1745. //
  1746. LIST_ENTRY ScbLinks;
  1747. //
  1748. // The following field links this structure into the IrpContext->RecentlyDeallocatedQueue
  1749. //
  1750. LIST_ENTRY IrpContextLinks;
  1751. //
  1752. // This is a pointer to the Scb that this record is part of
  1753. //
  1754. PSCB Scb;
  1755. //
  1756. // The following two fields describe the total size of this structure and
  1757. // the number of entries actually being used. NumberOfEntries is the size
  1758. // of the Index array and NextFreeEntryis the index of the next free slot.
  1759. // If NumberOfEntries is equal to NextFreeEntry then this structure is full
  1760. //
  1761. ULONG NumberOfEntries;
  1762. ULONG NextFreeEntry;
  1763. //
  1764. // This is an array of indices that have been dealloated.
  1765. //
  1766. ULONG Index[DEALLOCATED_RECORD_ENTRIES];
  1767. } DEALLOCATED_RECORDS;
  1768. typedef DEALLOCATED_RECORDS *PDEALLOCATED_RECORDS;
  1769. #define DEALLOCATED_RECORDS_HEADER_SIZE (FIELD_OFFSET( DEALLOCATED_RECORDS, Index ))
  1770. typedef struct _FCB_TABLE_ELEMENT {
  1771. FILE_REFERENCE FileReference;
  1772. PFCB Fcb;
  1773. } FCB_TABLE_ELEMENT;
  1774. typedef FCB_TABLE_ELEMENT *PFCB_TABLE_ELEMENT;
  1775. //
  1776. // Security descriptor information. This structure is used to allow
  1777. // Fcb's to share security descriptors.
  1778. //
  1779. typedef struct _SHARED_SECURITY {
  1780. PFCB ParentFcb;
  1781. ULONG ReferenceCount;
  1782. ULONG SecurityDescriptorLength;
  1783. UCHAR SecurityDescriptor[1];
  1784. } SHARED_SECURITY, *PSHARED_SECURITY;
  1785. //
  1786. // The following structure is used to store the state of an Scb to use during
  1787. // unwind operations. We keep a copy of all of the file sizes.
  1788. //
  1789. typedef struct _OLD_SCB_SNAPSHOT {
  1790. LONGLONG AllocationSize;
  1791. LONGLONG FileSize;
  1792. LONGLONG ValidDataLength;
  1793. UCHAR CompressionUnit;
  1794. BOOLEAN Resident;
  1795. BOOLEAN Compressed;
  1796. } OLD_SCB_SNAPSHOT, *POLD_SCB_SNAPSHOT;
  1797. //
  1798. // Structure used to track the number of threads doing read ahead, so that
  1799. // we do not hot fix for them.
  1800. //
  1801. typedef struct _READ_AHEAD_THREAD {
  1802. //
  1803. // Links of read ahead structures.
  1804. //
  1805. LIST_ENTRY Links;
  1806. //
  1807. // Thread Id
  1808. //
  1809. PVOID Thread;
  1810. } READ_AHEAD_THREAD, *PREAD_AHEAD_THREAD;
  1811. //
  1812. // Structure used to post to Defrag Mft routine.
  1813. //
  1814. typedef struct _DEFRAG_MFT {
  1815. //
  1816. // This structure is used for posting to the Ex worker threads.
  1817. //
  1818. WORK_QUEUE_ITEM WorkQueueItem;
  1819. PVCB Vcb;
  1820. BOOLEAN DeallocateWorkItem;
  1821. } DEFRAG_MFT, *PDEFRAG_MFT;
  1822. #endif // _NTFSSTRU_