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.

1379 lines
34 KiB

  1. /*++
  2. Copyright (c) 1991-2001 Microsoft Corporation
  3. Module Name:
  4. untfs.h
  5. Abstract:
  6. This module contains basic declarations and definitions for
  7. the NTFS utilities. Note that more extensive description
  8. of the file system structures may be found in ntos\inc\ntfs.h.
  9. Author:
  10. Bill McJohn [BillMc] 23-July-1991
  11. Revision History:
  12. IMPORTANT NOTE:
  13. The NTFS on-disk structure must guarantee natural alignment of all
  14. arithmetic quantities on disk up to and including quad-word (64-bit)
  15. numbers. Therefore, all attribute records are quad-word aligned, etc.
  16. --*/
  17. #if !defined( _UNTFS_DEFN_ )
  18. #define _UNTFS_DEFN_
  19. #define FRIEND friend
  20. #define MIN( a, b ) ( ((a) < (b)) ? (a) : (b) )
  21. // Set up the UNTFS_EXPORT macro for exporting from UNTFS (if the
  22. // source file is a member of UNTFS) or importing from UNTFS (if
  23. // the source file is a client of UNTFS).
  24. //
  25. #if defined ( _AUTOCHECK_ )
  26. #define UNTFS_EXPORT
  27. #elif defined ( _UNTFS_MEMBER_ )
  28. #define UNTFS_EXPORT __declspec(dllexport)
  29. #else
  30. #define UNTFS_EXPORT __declspec(dllimport)
  31. #endif
  32. #include "bigint.hxx"
  33. #include "bpb.hxx"
  34. #include "wstring.hxx"
  35. #include "untfs2.hxx"
  36. #include <pshpack4.h>
  37. // Miscellaneous constants:
  38. // This value represents the number of clusters from the Master
  39. // File Table which are copied to the Master File Table Reflection.
  40. #define REFLECTED_MFT_SEGMENTS (4)
  41. #define BYTES_IN_BOOT_AREA (0x2000)
  42. // This value is used in a mapping-pair to indicate that the run
  43. // described by the mapping pair doesn't really exist. This allows
  44. // NTFS to support sparse files. Note that the actual values
  45. // are LARGE_INTEGERS; the BIG_INT class manages the conversion.
  46. #define LCN_NOT_PRESENT -1
  47. #define INVALID_VCN -1
  48. //
  49. // Temporary definitions ****
  50. //
  51. typedef ULONG COLLATION_RULE;
  52. typedef ULONG DISPLAY_RULE;
  53. // This defines the number of bytes to read at one time
  54. // when processing the MFT.
  55. #define MFT_PRIME_SIZE (16*1024)
  56. // This defines the number of frs'es to read at one time
  57. // when processing the MFT.
  58. #define MFT_READ_CHUNK_SIZE (128)
  59. // The compression chunk size is constant for now, at 4KB.
  60. //
  61. #define NTFS_CHUNK_SIZE (0x1000)
  62. //
  63. // This number is actually the log of the number of clusters per compression
  64. // unit to be stored in a nonresident attribute record header.
  65. //
  66. #define NTFS_CLUSTERS_PER_COMPRESSION (4)
  67. //
  68. // Collation Rules
  69. //
  70. //
  71. // For binary collation, values are collated by a binary compare of their
  72. // bytes, with the first byte being most significant.
  73. //
  74. #define COLLATION_BINARY (0)
  75. //
  76. // For collation of Ntfs file names, file names are collated as Unicode
  77. // strings. See below.
  78. //
  79. #define COLLATION_FILE_NAME (1)
  80. //
  81. // For collation of Unicode strings, the strings are collated by their
  82. // binary Unicode value, with the exception that for characters which may
  83. // be upcased, the lower case value for that character collates immediately
  84. // after the upcased value.
  85. //
  86. #define COLLATION_UNICODE_STRING (2)
  87. #define COLLATION_ULONG (16)
  88. #define COLLATION_SID (17)
  89. #define COLLATION_SECURITY_HASH (18)
  90. #define COLLATION_ULONGS (19)
  91. //
  92. // Total number of collation rules
  93. //
  94. #define COLLATION_NUMBER_RULES (7)
  95. INLINE
  96. BOOLEAN
  97. operator == (
  98. IN RCMFT_SEGMENT_REFERENCE Left,
  99. IN RCMFT_SEGMENT_REFERENCE Right
  100. )
  101. /*++
  102. Routine Description:
  103. This function tests two segment references for equality.
  104. Arguments:
  105. Left -- supplies the left-hand operand
  106. Right -- supplies the right-hand operand
  107. Return Value:
  108. TRUE if they are equal; FALSE if not.
  109. --*/
  110. {
  111. return( Left.HighPart == Right.HighPart &&
  112. Left.LowPart == Right.LowPart &&
  113. Left.SequenceNumber == Right.SequenceNumber );
  114. }
  115. //
  116. // If the ClustersPerFileRecordSegment entry is zero, we use the
  117. // following as the size of our frs's regardless of the cluster
  118. // size.
  119. //
  120. #define SMALL_FRS_SIZE (1024)
  121. //
  122. // If the DefaultClustersPerIndexAllocationBuffer entry is zero,
  123. // we use the following as the size of our buffers regardless of
  124. // the cluster size.
  125. //
  126. #define SMALL_INDEX_BUFFER_SIZE (4096)
  127. //
  128. // If the above NextAttributeInstance field exceeds the following
  129. // value, chkdsk will take steps to prevent it from rolling over.
  130. //
  131. #define ATTRIBUTE_INSTANCE_TAG_THRESHOLD 0xf000
  132. //
  133. // Define a macro to determine the maximum space available for a
  134. // single attribute. For example, this is required when a
  135. // nonresident attribute has to split into multiple file records -
  136. // we need to know how much we can squeeze into a single file
  137. // record. If this macro has any inaccurracy, it must be in the
  138. // direction of returning a slightly smaller number than actually
  139. // required.
  140. //
  141. // ULONG
  142. // NtfsMaximumAttributeSize (
  143. // IN ULONG FileRecordSegmentSize
  144. // );
  145. //
  146. #define NtfsMaximumAttributeSize(FRSS) ( \
  147. (FRSS) - QuadAlign(sizeof(FILE_RECORD_SEGMENT_HEADER)) - \
  148. QuadAlign((((FRSS) / SEQUENCE_NUMBER_STRIDE) * sizeof(UPDATE_SEQUENCE_NUMBER))) - \
  149. QuadAlign(sizeof(ATTRIBUTE_TYPE_CODE)) \
  150. )
  151. //
  152. // Macros for manipulating mapping pair count byte.
  153. //
  154. INLINE
  155. UCHAR
  156. ComputeMappingPairCountByte(
  157. IN UCHAR VcnLength,
  158. IN UCHAR LcnLength
  159. )
  160. {
  161. return VcnLength + 16*LcnLength;
  162. }
  163. INLINE
  164. UCHAR
  165. VcnBytesFromCountByte(
  166. IN UCHAR CountByte
  167. )
  168. {
  169. return CountByte%16;
  170. }
  171. INLINE
  172. UCHAR
  173. LcnBytesFromCountByte(
  174. IN UCHAR CountByte
  175. )
  176. {
  177. return CountByte/16;
  178. }
  179. //
  180. // Standard Information Attribute. This attribute is present in every
  181. // base file record, and must be resident.
  182. //
  183. typedef struct _STANDARD_INFORMATION {
  184. LARGE_INTEGER CreationTime;
  185. LARGE_INTEGER LastModificationTime; // refers to $DATA attribute
  186. LARGE_INTEGER LastChangeTime; // any attribute
  187. LARGE_INTEGER LastAccessTime;
  188. ULONG FileAttributes;
  189. ULONG MaximumVersions;
  190. ULONG VersionNumber;
  191. ULONG Reserved;
  192. };
  193. DEFINE_TYPE( _STANDARD_INFORMATION, STANDARD_INFORMATION );
  194. typedef struct _STANDARD_INFORMATION2 {
  195. LARGE_INTEGER CreationTime;
  196. LARGE_INTEGER LastModificationTime; // refers to $DATA attribute
  197. LARGE_INTEGER LastChangeTime; // any attribute
  198. LARGE_INTEGER LastAccessTime;
  199. ULONG FileAttributes;
  200. ULONG MaximumVersions;
  201. ULONG VersionNumber;
  202. ULONG ClassId;
  203. ULONG OwnerId;
  204. ULONG SecurityId;
  205. LARGE_INTEGER QuotaCharged;
  206. LARGE_INTEGER Usn;
  207. };
  208. DEFINE_TYPE( _STANDARD_INFORMATION2, STANDARD_INFORMATION2 );
  209. #define SIZEOF_NEW_STANDARD_INFORMATION (0x48)
  210. //
  211. // Define the file attributes, starting with the Fat attributes.
  212. //
  213. #define FAT_DIRENT_ATTR_READ_ONLY (0x01)
  214. #define FAT_DIRENT_ATTR_HIDDEN (0x02)
  215. #define FAT_DIRENT_ATTR_SYSTEM (0x04)
  216. #define FAT_DIRENT_ATTR_VOLUME_ID (0x08)
  217. #define FAT_DIRENT_ATTR_ARCHIVE (0x20)
  218. #define FAT_DIRENT_ATTR_DEVICE (0x40)
  219. //
  220. // The FILE_ATTRIBUTE_ENCRYPTED bit coincides with the FILE_ATTRIBUTE_DEVICE on Win9x.
  221. // So we are changing it to a different value. In the meantime, chkdsk should clear
  222. // this bit whenever it sees it on ntfs volume.
  223. //
  224. #define FILE_ATTRIBUTE_ENCRYPTED_OLD (0x40)
  225. //
  226. // This bit is duplicated from the file record, to indicate that
  227. // this file has a file name index present (is a "directory").
  228. //
  229. #define DUP_FILE_NAME_INDEX_PRESENT (0x10000000)
  230. #define DUP_VIEW_INDEX_PRESENT (0x20000000)
  231. //
  232. // Attribute List. Because there is not a special header that goes
  233. // before the list of attribute list entries we do not need to declare
  234. // an attribute list header
  235. //
  236. //
  237. // The Attributes List attribute is an ordered-list of quad-word
  238. // aligned ATTRIBUTE_LIST_ENTRY records. It is ordered first by
  239. // Attribute Type Code, and then by Attribute Name (if present). No two
  240. // attributes may exist with the same type code, name and LowestVcn. This
  241. // also means that at most one occurrence of a given Attribute Type Code
  242. // without a name may exist.
  243. //
  244. // To binary search this attribute, it is first necessary to make a quick
  245. // pass through it and form a list of pointers, since the optional name
  246. // makes it variable-length.
  247. //
  248. typedef struct _ATTRIBUTE_LIST_ENTRY {
  249. ATTRIBUTE_TYPE_CODE AttributeTypeCode;
  250. USHORT RecordLength; // length in bytes
  251. UCHAR AttributeNameLength; // length in characters
  252. UCHAR AttributeNameOffset; // offset from beginning of struct
  253. VCN LowestVcn;
  254. MFT_SEGMENT_REFERENCE SegmentReference;
  255. USHORT Instance; // FRS-unique instance tag
  256. WCHAR AttributeName[1];
  257. };
  258. DEFINE_TYPE( _ATTRIBUTE_LIST_ENTRY, ATTRIBUTE_LIST_ENTRY );
  259. BOOLEAN
  260. operator <= (
  261. IN RCATTRIBUTE_LIST_ENTRY Left,
  262. IN RCATTRIBUTE_LIST_ENTRY Right
  263. );
  264. typedef struct _DUPLICATED_INFORMATION {
  265. BIG_INT CreationTime; // File creation
  266. BIG_INT LastModificationTime; // Last change of $DATA attribute
  267. BIG_INT LastChangeTime; // Last change of any attribute
  268. BIG_INT LastAccessTime; // see ntfs.h for notes
  269. BIG_INT AllocatedLength; // File allocated size
  270. BIG_INT FileSize; // File actual size
  271. ULONG FileAttributes;
  272. union {
  273. struct {
  274. USHORT PackedEaSize;
  275. USHORT Reserved;
  276. };
  277. ULONG ReparsePointTag;
  278. };
  279. };
  280. DEFINE_TYPE( _DUPLICATED_INFORMATION, DUPLICATED_INFORMATION );
  281. //
  282. // File Name attribute. A file has one File Name attribute for every
  283. // directory it is entered into (hard links).
  284. //
  285. typedef struct _FILE_NAME {
  286. FILE_REFERENCE ParentDirectory;
  287. DUPLICATED_INFORMATION Info;
  288. UCHAR FileNameLength; // length in characters
  289. UCHAR Flags; // FILE_NAME_xxx flags
  290. WCHAR FileName[1]; // First character of file name
  291. };
  292. DEFINE_TYPE( _FILE_NAME, FILE_NAME );
  293. // NtfsFileNameGetLength evaluates to the length of a FILE_NAME attribute
  294. // value, which is the FILE_NAME structure plus the length of the name.
  295. // Note that this is the actual length, not the quad-aligned length.
  296. #define NtfsFileNameGetLength(p) ( FIELD_OFFSET( FILE_NAME, FileName ) \
  297. + ((p)->FileNameLength * sizeof( WCHAR )) )
  298. // NtfsFileNameGetName gets the pointer to the name in a FILE_NAME
  299. // structure, which in turn is the value of an NTFS $FILE_NAME attribute.
  300. #define NtfsFileNameGetName(p) ( &((p)->FileName[0]) )
  301. //
  302. // File Name flags
  303. //
  304. #define FILE_NAME_NTFS (0x01)
  305. #define FILE_NAME_DOS (0x02)
  306. //
  307. // The maximum file name length is 255 (in chars)
  308. //
  309. #define NTFS_MAX_FILE_NAME_LENGTH (255)
  310. //
  311. // The maximum number of links on a file is 1024
  312. //
  313. #define NTFS_MAX_LINK_COUNT (1024)
  314. // This is the name of all attributes associated with an index
  315. // over $FILE_NAME:
  316. #define FileNameIndexNameData "$I30"
  317. //
  318. // Object ID attribute.
  319. //
  320. typedef struct _OBJECT_ID {
  321. char x[16];
  322. };
  323. DEFINE_TYPE( _OBJECT_ID, OBJECT_ID );
  324. typedef struct _OBJID_INDEX_ENTRY_VALUE {
  325. OBJECT_ID key;
  326. MFT_SEGMENT_REFERENCE SegmentReference;
  327. char extraInfo[48];
  328. };
  329. DEFINE_TYPE( _OBJID_INDEX_ENTRY_VALUE, OBJID_INDEX_ENTRY_VALUE );
  330. //
  331. // Object Id File Name to appear in the \$Extend directory
  332. //
  333. #define ObjectIdFileName "$ObjId"
  334. #define LObjectIdFileName L"$ObjId"
  335. #define ObjectIdIndexNameData "$O"
  336. //
  337. // Reparse Point Index Entry
  338. //
  339. typedef struct _REPARSE_INDEX_ENTRY_VALUE {
  340. ULONG Tag;
  341. // ULONG Reserved;
  342. MFT_SEGMENT_REFERENCE SegmentReference;
  343. };
  344. DEFINE_TYPE( _REPARSE_INDEX_ENTRY_VALUE, REPARSE_INDEX_ENTRY_VALUE );
  345. //
  346. // Reparse File Name to appear in the \$Extend directory
  347. //
  348. #define ReparseFileName "$Reparse"
  349. #define LReparseFileName L"$Reparse"
  350. #define ReparseIndexNameData "$R"
  351. //
  352. // Volume Version attribute.
  353. //
  354. typedef struct _VOLUME_VERSION {
  355. ULONG CurrentVersion;
  356. ULONG MaximumVersions;
  357. };
  358. DEFINE_TYPE( _VOLUME_VERSION, VOLUME_VERSION );
  359. //
  360. // Security Descriptor attribute. This is just a normal attribute stream
  361. // containing a security descriptor as defined by NT security and is
  362. // really treated pretty opaque by NTFS.
  363. //
  364. #define SecurityIdIndexNameData "$SII"
  365. #define SecurityDescriptorHashIndexNameData "$SDH"
  366. #define SecurityDescriptorStreamNameData "$SDS"
  367. // Security Descriptor Stream data is organized into chunks of 256K bytes
  368. // and it contains a mirror copy of each security descriptor. When writing
  369. // to a security descriptor at location X, another copy will be written at
  370. // location (X+256K). When writing a security descriptor that will
  371. // cross the 256K boundary, the pointer will be advanced by 256K to skip
  372. // over the mirror portion.
  373. #define SecurityDescriptorsBlockSize (0x40000) // 256K
  374. #define SecurityDescriptorMaxSize (0x20000) // 128K
  375. // Volume Name attribute. This attribute is just a normal attribute stream
  376. // containing the unicode characters that make up the volume label. It
  377. // is an attribute of the Volume Dasd File.
  378. //
  379. //
  380. // Common Index Header for Index Root and Index Allocation Buffers.
  381. // This structure is used to locate the Index Entries and describe the free
  382. // space in either of the two structures above.
  383. //
  384. typedef struct _INDEX_HEADER {
  385. //
  386. // Offset from the start of this structure to the first Index Entry.
  387. //
  388. ULONG FirstIndexEntry;
  389. //
  390. // Offset from the start of this structure to the first (quad-word aligned)
  391. // free byte.
  392. //
  393. ULONG FirstFreeByte;
  394. //
  395. // Total number of bytes available, from the start of this structure.
  396. // In the Index Root, this number must always be equal to FirstFreeByte,
  397. // as the total attribute record will be grown and shrunk as required.
  398. //
  399. ULONG BytesAvailable;
  400. //
  401. // INDEX_xxx flags.
  402. //
  403. UCHAR Flags;
  404. //
  405. // Reserved to round up to quad word boundary.
  406. //
  407. UCHAR Reserved[3];
  408. } INDEX_HEADER;
  409. typedef INDEX_HEADER *PINDEX_HEADER;
  410. //
  411. // INDEX_xxx flags
  412. //
  413. //
  414. // This Index or Index Allocation buffer is an intermediate node, as opposed to
  415. // a leaf in the Btree. All Index Entries will have a Vcn down pointer.
  416. //
  417. #define INDEX_NODE (0x01)
  418. //
  419. // Index Root attribute. The index attribute consists of an index
  420. // header record followed by one or more index entries.
  421. //
  422. typedef struct _INDEX_ROOT {
  423. ATTRIBUTE_TYPE_CODE IndexedAttributeType;
  424. COLLATION_RULE CollationRule;
  425. ULONG BytesPerIndexBuffer;
  426. UCHAR ClustersPerIndexBuffer;
  427. UCHAR Reserved[3];
  428. //
  429. // Index Header to describe the Index Entries which follow
  430. //
  431. INDEX_HEADER IndexHeader;
  432. } INDEX_ROOT;
  433. typedef INDEX_ROOT *PINDEX_ROOT;
  434. //
  435. // Index Allocation record is used for non-root clusters of the b-tree
  436. // Each non root cluster is contained in the data part of the index
  437. // allocation attribute. Each cluster starts with an index allocation list
  438. // header and is followed by one or more index entries.
  439. //
  440. typedef struct _INDEX_ALLOCATION_BUFFER {
  441. //
  442. // Multi-Sector Header as defined by the Cache Manager. This structure
  443. // will always contain the signature "INDX" and a description of the
  444. // location and size of the Update Sequence Array.
  445. //
  446. UNTFS_MULTI_SECTOR_HEADER MultiSectorHeader;
  447. //
  448. // Log File Sequence Number of last logged update to this Index Allocation
  449. // Buffer.
  450. //
  451. LSN Lsn;
  452. VCN ThisVcn;
  453. //
  454. // Index Header to describe the Index Entries which follow
  455. //
  456. INDEX_HEADER IndexHeader;
  457. //
  458. // Update Sequence Array to protect multi-sector transfers of the
  459. // Index Allocation Bucket.
  460. //
  461. UPDATE_SEQUENCE_ARRAY UpdateSequenceArray;
  462. } INDEX_ALLOCATION_BUFFER;
  463. typedef INDEX_ALLOCATION_BUFFER *PINDEX_ALLOCATION_BUFFER;
  464. //
  465. // Index Entry. This structure is common to both the resident index list
  466. // attribute and the Index Allocation records
  467. //
  468. typedef struct _INDEX_ENTRY {
  469. //
  470. // Define a union to distinguish directory indices from view indices
  471. //
  472. union {
  473. //
  474. // Reference to file containing the attribute with this
  475. // attribute value.
  476. //
  477. FILE_REFERENCE FileReference; // offset = 0x000
  478. //
  479. // For views, describe the Data Offset and Length in bytes
  480. //
  481. struct {
  482. USHORT DataOffset; // offset = 0x000
  483. USHORT DataLength; // offset = 0x001
  484. ULONG ReservedForZero; // offset = 0x002
  485. };
  486. };
  487. //
  488. // Length of this index entry, in bytes.
  489. //
  490. USHORT Length;
  491. //
  492. // Length of attribute value, in bytes. The attribute value immediately
  493. // follows this record.
  494. //
  495. USHORT AttributeLength;
  496. //
  497. // INDEX_ENTRY_xxx Flags.
  498. //
  499. USHORT Flags;
  500. //
  501. // Reserved to round to quad-word boundary.
  502. //
  503. USHORT Reserved;
  504. //
  505. // If this Index Entry is an intermediate node in the tree, as determined
  506. // by the INDEX_xxx flags, then a VCN is stored at the end of this
  507. // entry at Length - sizeof(VCN).
  508. //
  509. };
  510. DEFINE_TYPE( _INDEX_ENTRY, INDEX_ENTRY );
  511. #define GetDownpointer( x ) \
  512. (*((PVCN)((PBYTE)(x) + (x)->Length - sizeof(VCN))))
  513. #define GetIndexEntryValue( x ) \
  514. ((PBYTE)(x)+sizeof(INDEX_ENTRY))
  515. #define GetNextEntry( x ) \
  516. ((PINDEX_ENTRY)( (PBYTE)(x)+(x)->Length ))
  517. CONST UCHAR NtfsIndexLeafEndEntrySize = QuadAlign( sizeof(INDEX_ENTRY) );
  518. //
  519. // INDEX_ENTRY_xxx flags
  520. //
  521. //
  522. // This entry is currently in the intermediate node form, i.e., it has a
  523. // Vcn at the end.
  524. //
  525. #define INDEX_ENTRY_NODE (0x0001)
  526. //
  527. // This entry is the special END record for the Index or Index Allocation buffer.
  528. //
  529. #define INDEX_ENTRY_END (0x0002)
  530. //
  531. // Define the struture of the quota data in the quota index. The key for
  532. // the quota index is the 32 bit owner id.
  533. //
  534. typedef struct _QUOTA_USER_DATA {
  535. ULONG QuotaVersion;
  536. ULONG QuotaFlags;
  537. ULONGLONG QuotaUsed;
  538. ULONGLONG QuotaChangeTime;
  539. ULONGLONG QuotaThreshold;
  540. ULONGLONG QuotaLimit;
  541. ULONGLONG QuotaExceededTime;
  542. SID QuotaSid;
  543. } QUOTA_USER_DATA, *PQUOTA_USER_DATA;
  544. //
  545. // Define the size of the quota user data structure without the quota SID.
  546. //
  547. #define SIZEOF_QUOTA_USER_DATA FIELD_OFFSET(QUOTA_USER_DATA, QuotaSid)
  548. //
  549. // Define the current version of the quote user data.
  550. //
  551. #define QUOTA_USER_VERSION 1
  552. //
  553. // Define the quota flags.
  554. //
  555. #define QUOTA_FLAG_DEFAULT_LIMITS (0x00000001)
  556. #define QUOTA_FLAG_LIMIT_REACHED (0x00000002)
  557. #define QUOTA_FLAG_ID_DELETED (0x00000004)
  558. #define QUOTA_FLAG_USER_MASK (0x00000007)
  559. //
  560. // The following flags are only stored in the quota defaults index entry.
  561. //
  562. #define QUOTA_FLAG_TRACKING_ENABLED (0x00000010)
  563. #define QUOTA_FLAG_ENFORCEMENT_ENABLED (0x00000020)
  564. #define QUOTA_FLAG_TRACKING_REQUESTED (0x00000040)
  565. #define QUOTA_FLAG_LOG_THRESHOLD (0x00000080)
  566. #define QUOTA_FLAG_LOG_LIMIT (0x00000100)
  567. #define QUOTA_FLAG_OUT_OF_DATE (0x00000200)
  568. #define QUOTA_FLAG_CORRUPT (0x00000400)
  569. #define QUOTA_FLAG_PENDING_DELETES (0x00000800)
  570. //
  571. // Define the quota charge for resident streams.
  572. //
  573. #define QUOTA_RESIDENT_STREAM (1024)
  574. //
  575. // Define special quota owner ids.
  576. //
  577. #define QUOTA_INVALID_ID 0x00000000
  578. #define QUOTA_DEFAULTS_ID 0x00000001
  579. #define QUOTA_FISRT_USER_ID 0x00000100
  580. //
  581. // Quota File Name to appear in the \$Extend directory
  582. //
  583. #define QuotaFileName "$Quota"
  584. #define LQuotaFileName L"$Quota"
  585. //
  586. // Quota Index Names
  587. //
  588. #define Sid2UseridQuotaNameData "$O"
  589. #define Userid2SidQuotaNameData "$Q"
  590. //
  591. // Usn Journal
  592. //
  593. typedef struct {
  594. ULONG RecordLength;
  595. USHORT MajorVersion;
  596. USHORT MinorVersion;
  597. union {
  598. //
  599. // Version 1.0
  600. //
  601. struct {
  602. ULONGLONG FileReferenceNumber;
  603. ULONGLONG ParentFileReferenceNumber;
  604. USN Usn;
  605. LARGE_INTEGER TimeStamp;
  606. ULONG Reason;
  607. ULONG SecurityId;
  608. ULONG FileAttributes;
  609. USHORT FileNameLength;
  610. WCHAR FileName[1];
  611. } u1;
  612. //
  613. // Version 2.0
  614. //
  615. struct {
  616. ULONGLONG FileReferenceNumber;
  617. ULONGLONG ParentFileReferenceNumber;
  618. USN Usn;
  619. LARGE_INTEGER TimeStamp;
  620. ULONG Reason;
  621. ULONG SourceInfo; // Additional info about source of change
  622. ULONG SecurityId;
  623. ULONG FileAttributes;
  624. USHORT FileNameLength;
  625. USHORT FileNameOffset; // Offset to file name
  626. WCHAR FileName[1];
  627. } u2;
  628. } version;
  629. } USN_REC, *PUSN_REC;
  630. #define SIZE_OF_USN_REC_V1 0x38
  631. #define SIZE_OF_USN_REC_V2 0x3E
  632. #define USN_PAGE_SIZE (0x1000) // 4 K
  633. #define USN_MAX_SIZE (1024*1024*8) // 8 MBytes
  634. #define USN_ALLOC_DELTA_MAX_SIZE (1024*1024) // 1 MBytes
  635. #define USN_JRNL_MAX_FILE_SIZE (0x20000000000) // 512 * 2^32
  636. //
  637. // Usn Journal Name to appear in the \$Extend directory
  638. //
  639. #define UsnJournalFileName "$UsnJrnl"
  640. #define LUsnJournalFileName L"$UsnJrnl"
  641. //
  642. // Usn Journal named $DATA attribute Names
  643. //
  644. #define UsnJournalNameData "$J"
  645. #define UsnJournalMaxNameData "$Max"
  646. #define MAXULONGLONG (0xffffffffffffffff)
  647. //
  648. // Key structure for Security Hash index
  649. //
  650. typedef struct _SECURITY_HASH_KEY
  651. {
  652. ULONG Hash; // Hash value for descriptor
  653. ULONG SecurityId; // Security Id (guaranteed unique)
  654. } SECURITY_HASH_KEY, *PSECURITY_HASH_KEY;
  655. //
  656. // Key structure for Security Id index is simply the SECURITY_ID itself
  657. //
  658. //
  659. // Header for security descriptors in the security descriptor stream. This
  660. // is the data format for all indexes and is part of SharedSecurity
  661. //
  662. typedef struct _SECURITY_DESCRIPTOR_HEADER
  663. {
  664. SECURITY_HASH_KEY HashKey; // Hash value for the descriptor
  665. ULONGLONG Offset; // offset to beginning of header
  666. ULONG Length; // Length in bytes
  667. } SECURITY_DESCRIPTOR_HEADER, *PSECURITY_DESCRIPTOR_HEADER;
  668. typedef struct _SECURITY_ENTRY {
  669. SECURITY_DESCRIPTOR_HEADER security_descriptor_header;
  670. SECURITY_DESCRIPTOR security;
  671. } SECURITY_ENTRY, *PSECURITY_ENTRY;
  672. #define GETSECURITYDESCRIPTORLENGTH(HEADER) \
  673. ((HEADER)->Length - sizeof( SECURITY_DESCRIPTOR_HEADER ))
  674. #define SetSecurityDescriptorLength(HEADER,LENGTH) \
  675. ((HEADER)->Length = (LENGTH) + sizeof( SECURITY_DESCRIPTOR_HEADER ))
  676. //
  677. // Define standard values for well-known security IDs
  678. //
  679. #define SECURITY_ID_INVALID (0x00000000)
  680. #define SECURITY_ID_FIRST (0x00000100)
  681. //
  682. // MFT Bitmap attribute
  683. //
  684. // The MFT Bitmap is simply a normal attribute stream in which there is
  685. // one bit to represent the allocation state of each File Record Segment
  686. // in the MFT. Bit clear means free, and bit set means allocated.
  687. //
  688. // Whenever the MFT Data attribute is extended, the MFT Bitmap attribute
  689. // must also be extended. If the bitmap is still in a file record segment
  690. // for the MFT, then it must be extended and the new bits cleared. When
  691. // the MFT Bitmap is in the Nonresident form, then the allocation should
  692. // always be sufficient to store enough bits to describe the MFT, however
  693. // ValidDataLength insures that newly allocated space to the MFT Bitmap
  694. // has an initial value of all 0's. This means that if the MFT Bitmap is
  695. // extended, the newly represented file record segments are automatically in
  696. // the free state.
  697. //
  698. // No structure definition is required; the positional offset of the file
  699. // record segment is exactly equal to the bit offset of its corresponding
  700. // bit in the Bitmap.
  701. //
  702. //
  703. // The utilities attempt to allocate a more disk space than necessary for
  704. // the initial MFT Bitmap to allow for future growth.
  705. //
  706. #define MFT_BITMAP_INITIAL_SIZE 0x2000 /* bytes of bitmap */
  707. //
  708. // Symbolic Link attribute ****TBS
  709. //
  710. typedef struct _SYMBOLIC_LINK {
  711. LARGE_INTEGER Tbs;
  712. } SYMBOLIC_LINK;
  713. typedef SYMBOLIC_LINK *PSYMBOLIC_LINK;
  714. //
  715. // Ea Information attribute
  716. //
  717. typedef struct _EA_INFORMATION {
  718. USHORT PackedEaSize; // Size of buffer to hold in unpacked form
  719. USHORT NeedEaCount; // Count of EA's with NEED_EA bit set
  720. ULONG UnpackedEaSize; // Size of buffer to hold in packed form
  721. } EA_INFORMATION;
  722. typedef EA_INFORMATION *PEA_INFORMATION;
  723. struct PACKED_EA {
  724. UCHAR Flag;
  725. UCHAR NameSize;
  726. UCHAR ValueSize[2]; // Was USHORT.
  727. CHAR Name[1];
  728. };
  729. DEFINE_POINTER_TYPES( PACKED_EA );
  730. #define EA_FLAG_NEED 0x80
  731. //
  732. // SLEAZY_LARGE_INTEGER is used because x86 C8 won't allow us to
  733. // do static init on a union (like LARGE_INTEGER) and we can't use
  734. // BIG_INT for cases where we need to static-init an array with a non-
  735. // default constructor. The bit pattern must be the same as
  736. // LARGE_INTEGER.
  737. //
  738. typedef struct _SLEAZY_LARGE_INTEGER {
  739. ULONG LowPart;
  740. LONG HighPart;
  741. } SLEAZY_LARGE_INTEGER, *PSLEAZY_LARGE_INTEGER;
  742. //
  743. // Attribute Definition Table
  744. //
  745. // The following struct defines the columns of this table. Initially they
  746. // will be stored as simple records, and ordered by Attribute Type Code.
  747. //
  748. typedef struct _ATTRIBUTE_DEFINITION_COLUMNS {
  749. //
  750. // Unicode attribute name.
  751. //
  752. WCHAR AttributeName[64];
  753. //
  754. // Attribute Type Code.
  755. //
  756. ATTRIBUTE_TYPE_CODE AttributeTypeCode;
  757. //
  758. // Default Display Rule for this attribute
  759. //
  760. DISPLAY_RULE DisplayRule;
  761. //
  762. // Default Collation rule
  763. //
  764. COLLATION_RULE CollationRule;
  765. //
  766. // ATTRIBUTE_DEF_xxx flags
  767. //
  768. ULONG Flags;
  769. //
  770. // Minimum Length for attribute, if present.
  771. //
  772. SLEAZY_LARGE_INTEGER MinimumLength;
  773. //
  774. // Maximum Length for attribute.
  775. //
  776. SLEAZY_LARGE_INTEGER MaximumLength;
  777. } ATTRIBUTE_DEFINITION_COLUMNS;
  778. DEFINE_POINTER_TYPES( ATTRIBUTE_DEFINITION_COLUMNS );
  779. //
  780. // ATTRIBUTE_DEF_xxx flags
  781. //
  782. //
  783. // This flag is set if the attribute may be indexed.
  784. //
  785. #define ATTRIBUTE_DEF_INDEXABLE (0x00000002)
  786. //
  787. // This flag is set if the attribute may occur more than once, such as is
  788. // allowed for the File Name attribute.
  789. //
  790. #define ATTRIBUTE_DEF_DUPLICATES_ALLOWED (0x00000004)
  791. //
  792. // This flag is set if the value of the attribute may not be entirely
  793. // null, i.e., all binary 0's.
  794. //
  795. #define ATTRIBUTE_DEF_MAY_NOT_BE_NULL (0x00000008)
  796. //
  797. // This attribute must be indexed, and no two attributes may exist with
  798. // the same value in the same file record segment.
  799. //
  800. #define ATTRIBUTE_DEF_MUST_BE_INDEXED (0x00000010)
  801. //
  802. // This attribute must be named, and no two attributes may exist with
  803. // the same name in the same file record segment.
  804. //
  805. #define ATTRIBUTE_DEF_MUST_BE_NAMED (0x00000020)
  806. //
  807. // This attribute must be in the Resident Form.
  808. //
  809. #define ATTRIBUTE_DEF_MUST_BE_RESIDENT (0x00000040)
  810. //
  811. // Modifications to this attribute should be logged even if the
  812. // attribute is nonresident.
  813. //
  814. #define ATTRIBUTE_DEF_LOG_NONRESIDENT (0X00000080)
  815. //
  816. // The remaining stuff in this file describes some of the lfs data
  817. // structures; some of these are used by chkdsk, and some are used
  818. // only by diskedit.
  819. //
  820. typedef struct _MULTI_SECTOR_HEADER {
  821. //
  822. // Space for a four-character signature
  823. //
  824. UCHAR Signature[4];
  825. //
  826. // Offset to Update Sequence Array, from start of structure. The Update
  827. // Sequence Array must end before the last USHORT in the first "sector"
  828. // of size SEQUENCE_NUMBER_STRIDE. (I.e., with the current constants,
  829. // the sum of the next two fields must be <= 510.)
  830. //
  831. USHORT UpdateSequenceArrayOffset;
  832. //
  833. // Size of Update Sequence Array (from above formula)
  834. //
  835. USHORT UpdateSequenceArraySize;
  836. } MULTI_SECTOR_HEADER, *PMULTI_SECTOR_HEADER;
  837. typedef struct _LFS_RESTART_PAGE_HEADER {
  838. //
  839. // Cache multisector protection header.
  840. //
  841. MULTI_SECTOR_HEADER MultiSectorHeader;
  842. //
  843. // This is the last Lsn found by checkdisk for this volume.
  844. //
  845. LSN ChkDskLsn;
  846. //
  847. //
  848. ULONG SystemPageSize;
  849. ULONG LogPageSize;
  850. //
  851. // Lfs restart area offset. This is the offset from the start of this
  852. // structure to the Lfs restart area.
  853. //
  854. USHORT RestartOffset;
  855. USHORT MinorVersion;
  856. USHORT MajorVersion;
  857. //
  858. // Update Sequence Array. Used to protect the page blcok.
  859. //
  860. UPDATE_SEQUENCE_ARRAY UpdateSequenceArray;
  861. } LFS_RESTART_PAGE_HEADER, *PLFS_RESTART_PAGE_HEADER;
  862. //
  863. // Log Client Record. A log client record exists for each client user of
  864. // the log file. One of these is in each Lfs restart area.
  865. //
  866. #define LFS_NO_CLIENT 0xffff
  867. #define LFS_CLIENT_NAME_MAX 64
  868. typedef struct _LFS_CLIENT_RECORD {
  869. //
  870. // Oldest Lsn. This is the oldest Lsn that this client requires to
  871. // be in the log file.
  872. //
  873. LSN OldestLsn;
  874. //
  875. // Client Restart Lsn. This is the Lsn of the latest client restart
  876. // area written to the disk. A reserved Lsn will indicate that no
  877. // restart area exists for this client.
  878. //
  879. LSN ClientRestartLsn;
  880. //
  881. //
  882. // Previous/Next client area. These are the indexes into an array of
  883. // Log Client Records for the previous and next client records.
  884. //
  885. USHORT PrevClient;
  886. USHORT NextClient;
  887. //
  888. // Sequence Number. Incremented whenever this record is reused. This
  889. // will happen whenever a client opens (reopens) the log file and has
  890. // no current restart area.
  891. USHORT SeqNumber;
  892. //
  893. // Alignment field.
  894. //
  895. USHORT AlignWord;
  896. //
  897. // Align the entire record.
  898. //
  899. ULONG AlignDWord;
  900. //
  901. // The following fields are used to describe the client name. A client
  902. // name consists of at most 32 Unicode character (64 bytes). The Log
  903. // file service will treat client names as case sensitive.
  904. //
  905. ULONG ClientNameLength;
  906. WCHAR ClientName[LFS_CLIENT_NAME_MAX];
  907. } LFS_CLIENT_RECORD, *PLFS_CLIENT_RECORD;
  908. typedef struct _LFS_RESTART_AREA {
  909. //
  910. // Current Lsn. This is periodic snapshot of the current logical end of
  911. // log file to facilitate restart.
  912. //
  913. LSN CurrentLsn;
  914. //
  915. // Number of Clients. This is the maximum number of clients supported
  916. // for this log file.
  917. //
  918. USHORT LogClients;
  919. //
  920. // The following are indexes into the client record arrays. The client
  921. // records are linked into two lists. A free list of client records and
  922. // an in-use list of records.
  923. //
  924. USHORT ClientFreeList;
  925. USHORT ClientInUseList;
  926. //
  927. // Flag field.
  928. //
  929. // RESTART_SINGLE_PAGE_IO All log pages written 1 by 1
  930. // LFS_CLEAN_SHUTDOWN
  931. //
  932. USHORT Flags;
  933. //
  934. // The following is the number of bits to use for the sequence number.
  935. //
  936. ULONG SeqNumberBits;
  937. //
  938. // Length of this restart area.
  939. //
  940. USHORT RestartAreaLength;
  941. //
  942. // Offset from the start of this structure to the client array.
  943. // Ignored in versions prior to 1.1
  944. //
  945. USHORT ClientArrayOffset;
  946. //
  947. // Usable log file size. We will stop sharing the value in the page header.
  948. //
  949. LONGLONG FileSize;
  950. //
  951. // DataLength of last Lsn. This doesn't include the length of
  952. // the Lfs header.
  953. //
  954. ULONG LastLsnDataLength;
  955. //
  956. // The following apply to log pages. This is the log page data offset and
  957. // the length of the log record header. Ignored in versions prior to 1.1
  958. //
  959. USHORT RecordHeaderLength;
  960. USHORT LogPageDataOffset;
  961. //
  962. // Log file open count. Used to determine if there has been a change to the disk.
  963. //
  964. ULONG RestartOpenLogCount;
  965. //
  966. // Track log flush failures
  967. //
  968. ULONG LastFailedFlushStatus;
  969. LONGLONG LastFailedFlushOffset;
  970. LSN LastFailedFlushLsn;
  971. //
  972. // Keep this structure quadword aligned.
  973. //
  974. //
  975. // Client data.
  976. //
  977. LFS_CLIENT_RECORD LogClientArray[1];
  978. } LFS_RESTART_AREA, *PLFS_RESTART_AREA;
  979. //
  980. // Flags definition in LFS_RESTART_AREA
  981. //
  982. #define LFS_CLEAN_SHUTDOWN (0x0002)
  983. #include <poppack.h>
  984. BOOLEAN
  985. GetSystemFileName(
  986. IN UCHAR Major,
  987. IN VCN FileNumber,
  988. OUT PWSTRING FileName,
  989. OUT PBOOLEAN NoName
  990. );
  991. #endif // _UNTFS_DEFN_