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.

799 lines
15 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. attrrec.hxx
  5. Abstract:
  6. This module contains the declarations for NTFS_ATTRIBUTE_RECORD,
  7. which models NTFS attribute records.
  8. An Attribute Record may be a template laid over a chunk of
  9. memory; in that case, it does not own the memory. It may
  10. also be told, upon initialization, to allocate its own memory
  11. and copy the supplied data. In that case, it is also responsible
  12. for freeing that memory.
  13. Attribute Records are passed between Attributes and File
  14. Record Segments. A File Record Segment can initialize
  15. an Attribute with a list of Attribute Records; when an
  16. Attribute is Set into a File Record Segment, it packages
  17. itself up into Attribute Records and inserts them into
  18. the File Record Segment.
  19. File Record Segments also use Attribute Records to scan
  20. through their list of attribute records, and to shuffle
  21. them around.
  22. Author:
  23. Bill McJohn (billmc) 14-June-91
  24. Environment:
  25. ULIB, User Mode
  26. --*/
  27. #if !defined( _NTFS_ATTRIBUTE_RECORD_DEFN_ )
  28. #define _NTFS_ATTRIBUTE_RECORD_DEFN_
  29. DECLARE_CLASS( WSTRING );
  30. DECLARE_CLASS( NTFS_EXTENT_LIST );
  31. DECLARE_CLASS( NTFS_ATTRIBUTE_RECORD );
  32. DECLARE_CLASS( NTFS_ATTRIBUTE_COLUMNS );
  33. DECLARE_CLASS( NTFS_UPCASE_TABLE );
  34. // This function is used to compare attribute records, in order
  35. // to determine their ordering in the base FRS. Its definition
  36. // appears in attrrec.cxx.
  37. //
  38. LONG
  39. CompareAttributeRecords(
  40. IN PCNTFS_ATTRIBUTE_RECORD Left,
  41. IN PCNTFS_ATTRIBUTE_RECORD Right,
  42. IN PCNTFS_UPCASE_TABLE UpcaseTable
  43. );
  44. class NTFS_ATTRIBUTE_RECORD : public OBJECT {
  45. public:
  46. UNTFS_EXPORT
  47. DECLARE_CONSTRUCTOR( NTFS_ATTRIBUTE_RECORD );
  48. VIRTUAL
  49. UNTFS_EXPORT
  50. ~NTFS_ATTRIBUTE_RECORD(
  51. );
  52. NONVIRTUAL
  53. BOOLEAN
  54. Initialize(
  55. IN PIO_DP_DRIVE Drive,
  56. IN OUT PVOID Data,
  57. IN ULONG MaximumLength,
  58. IN BOOLEAN MakeCopy DEFAULT FALSE
  59. );
  60. NONVIRTUAL
  61. UNTFS_EXPORT
  62. BOOLEAN
  63. Initialize(
  64. IN PIO_DP_DRIVE Drive,
  65. IN OUT PVOID Data
  66. );
  67. NONVIRTUAL
  68. BOOLEAN
  69. CreateResidentRecord(
  70. IN PCVOID Value,
  71. IN ULONG ValueLength,
  72. IN ATTRIBUTE_TYPE_CODE TypeCode,
  73. IN PCWSTRING Name DEFAULT NULL,
  74. IN USHORT Flags DEFAULT 0,
  75. IN UCHAR ResidentFlags DEFAULT 0
  76. );
  77. NONVIRTUAL
  78. BOOLEAN
  79. CreateNonresidentRecord(
  80. IN PCNTFS_EXTENT_LIST Extents,
  81. IN BIG_INT AllocatedLength,
  82. IN BIG_INT ActualLength,
  83. IN BIG_INT ValidDataLength,
  84. IN ATTRIBUTE_TYPE_CODE TypeCode,
  85. IN PCWSTRING Name DEFAULT NULL,
  86. IN USHORT Flags DEFAULT 0,
  87. IN USHORT CompressionUnit DEFAULT 0,
  88. IN ULONG ClusterSize DEFAULT 0
  89. );
  90. NONVIRTUAL
  91. BOOLEAN
  92. Verify(
  93. IN PCNTFS_ATTRIBUTE_COLUMNS AttributeDefTable OPTIONAL,
  94. IN BOOLEAN BeLenient
  95. ) CONST;
  96. NONVIRTUAL
  97. BOOLEAN
  98. UseClusters(
  99. IN OUT PNTFS_BITMAP VolumeBitmap,
  100. OUT PBIG_INT ClusterCount
  101. ) CONST;
  102. NONVIRTUAL
  103. BOOLEAN
  104. UseClusters(
  105. IN OUT PNTFS_BITMAP VolumeBitmap,
  106. OUT PBIG_INT ClusterCount,
  107. IN ULONG AllowCrossLinkStart,
  108. IN ULONG AllowCrossLinkLength,
  109. OUT PBOOLEAN DidCrossLinkOccur
  110. ) CONST;
  111. NONVIRTUAL
  112. BOOLEAN
  113. UnUseClusters(
  114. IN OUT PNTFS_BITMAP VolumeBitmap,
  115. IN ULONG LeaveInUseStart,
  116. IN ULONG LeaveInUseLength
  117. ) CONST;
  118. NONVIRTUAL
  119. ULONG
  120. QueryRecordLength(
  121. ) CONST;
  122. NONVIRTUAL
  123. ATTRIBUTE_TYPE_CODE
  124. QueryTypeCode(
  125. ) CONST;
  126. NONVIRTUAL
  127. USHORT
  128. QueryFlags(
  129. ) CONST;
  130. NONVIRTUAL
  131. UCHAR
  132. QueryResidentFlags(
  133. ) CONST;
  134. NONVIRTUAL
  135. ULONG
  136. QueryCompressionUnit(
  137. ) CONST;
  138. NONVIRTUAL
  139. BOOLEAN
  140. IsResident(
  141. ) CONST;
  142. NONVIRTUAL
  143. BOOLEAN
  144. IsIndexed(
  145. ) CONST;
  146. NONVIRTUAL
  147. VCN
  148. QueryLowestVcn(
  149. ) CONST;
  150. NONVIRTUAL
  151. PWSTR
  152. GetName(
  153. ) CONST;
  154. NONVIRTUAL
  155. VCN
  156. QueryNextVcn(
  157. ) CONST;
  158. NONVIRTUAL
  159. UNTFS_EXPORT
  160. BOOLEAN
  161. QueryName(
  162. OUT PWSTRING Name
  163. ) CONST;
  164. NONVIRTUAL
  165. ULONG
  166. QueryNameLength(
  167. ) CONST;
  168. NONVIRTUAL
  169. VOID
  170. QueryValueLength(
  171. OUT PBIG_INT ValueLength,
  172. OUT PBIG_INT AllocatedLength DEFAULT NULL,
  173. OUT PBIG_INT ValidLength DEFAULT NULL,
  174. OUT PBIG_INT TotalAllocated DEFAULT NULL
  175. ) CONST;
  176. NONVIRTUAL
  177. VOID
  178. SetTotalAllocated(
  179. IN BIG_INT TotalAllocated
  180. );
  181. NONVIRTUAL
  182. USHORT
  183. QueryInstanceTag(
  184. ) CONST;
  185. NONVIRTUAL
  186. VOID
  187. SetInstanceTag(
  188. USHORT NewTag
  189. );
  190. NONVIRTUAL
  191. PCVOID
  192. GetData(
  193. ) CONST;
  194. NONVIRTUAL
  195. UNTFS_EXPORT
  196. BOOLEAN
  197. QueryExtentList(
  198. OUT PNTFS_EXTENT_LIST ExtentList
  199. ) CONST;
  200. NONVIRTUAL
  201. PCVOID
  202. GetResidentValue(
  203. ) CONST;
  204. NONVIRTUAL
  205. USHORT
  206. QueryResidentValueOffset(
  207. ) CONST;
  208. NONVIRTUAL
  209. ULONG
  210. QueryResidentValueLength(
  211. ) CONST;
  212. NONVIRTUAL
  213. BOOLEAN
  214. IsMatch(
  215. IN ATTRIBUTE_TYPE_CODE Type,
  216. IN PCWSTRING Name DEFAULT NULL,
  217. IN PCVOID Value DEFAULT NULL,
  218. IN ULONG ValueLength DEFAULT 0
  219. ) CONST;
  220. NONVIRTUAL
  221. VOID
  222. DisableUnUse(
  223. IN BOOLEAN NewState DEFAULT TRUE
  224. );
  225. NONVIRTUAL
  226. BOOLEAN
  227. IsUnUseDisabled(
  228. );
  229. private:
  230. NONVIRTUAL
  231. VOID
  232. Construct (
  233. );
  234. NONVIRTUAL
  235. VOID
  236. Destroy(
  237. );
  238. PATTRIBUTE_RECORD_HEADER _Data;
  239. ULONG _MaximumLength;
  240. BOOLEAN _IsOwnBuffer;
  241. //
  242. // DisableUnUse will turn the UnUseClusters operation into a
  243. // no-op.
  244. //
  245. BOOLEAN _DisableUnUse;
  246. PIO_DP_DRIVE _Drive; // in order to obtain message outlet
  247. };
  248. INLINE
  249. ULONG
  250. NTFS_ATTRIBUTE_RECORD::QueryRecordLength(
  251. ) CONST
  252. /*++
  253. Routine Description:
  254. This method returns the length of the attribute record. (Note
  255. that this is the length of the record itself, not the length
  256. of the buffer allotted to it).
  257. Arguments:
  258. None.
  259. Return Value:
  260. The length of the attribute record.
  261. --*/
  262. {
  263. return _Data->RecordLength;
  264. }
  265. INLINE
  266. ATTRIBUTE_TYPE_CODE
  267. NTFS_ATTRIBUTE_RECORD::QueryTypeCode(
  268. ) CONST
  269. /*++
  270. Routine Description:
  271. This method returns the attribute type code.
  272. Arguments:
  273. None.
  274. Return Value:
  275. The attribute type code for this attribute record.
  276. --*/
  277. {
  278. return _Data->TypeCode;
  279. }
  280. INLINE
  281. USHORT
  282. NTFS_ATTRIBUTE_RECORD::QueryFlags(
  283. ) CONST
  284. /*++
  285. Routine Description:
  286. This method returns the attribute's flags.
  287. Arguments:
  288. None.
  289. Return Value:
  290. The flags from the attribute record.
  291. --*/
  292. {
  293. DebugPtrAssert( _Data );
  294. return( _Data->Flags );
  295. }
  296. INLINE
  297. ULONG
  298. NTFS_ATTRIBUTE_RECORD::QueryCompressionUnit(
  299. ) CONST
  300. {
  301. return( (_Data->FormCode == NONRESIDENT_FORM) ?
  302. _Data->Form.Nonresident.CompressionUnit :
  303. 0 );
  304. }
  305. INLINE
  306. UCHAR
  307. NTFS_ATTRIBUTE_RECORD::QueryResidentFlags(
  308. ) CONST
  309. /*++
  310. Routine Description:
  311. This method returns the attribute's resident-form flags.
  312. Arguments:
  313. None.
  314. Return Value:
  315. The resident-form flags from the attribute record. If
  316. if the attribute is nonresident, this method returns zero.
  317. --*/
  318. {
  319. DebugPtrAssert( _Data );
  320. return( (_Data->FormCode == NONRESIDENT_FORM) ?
  321. 0 :
  322. _Data->Form.Resident.ResidentFlags );
  323. }
  324. INLINE
  325. BOOLEAN
  326. NTFS_ATTRIBUTE_RECORD::IsResident(
  327. ) CONST
  328. /*++
  329. Routine Description:
  330. This method returns whether the attribute is resident.
  331. Arguments:
  332. None.
  333. Return Value:
  334. TRUE if the attribute is resident.
  335. --*/
  336. {
  337. return (_Data->FormCode == RESIDENT_FORM);
  338. }
  339. INLINE
  340. BOOLEAN
  341. NTFS_ATTRIBUTE_RECORD::IsIndexed(
  342. ) CONST
  343. /*++
  344. Routine Description:
  345. This method returns whether the attribute is indexed.
  346. Arguments:
  347. None.
  348. Return Value:
  349. TRUE if the attribute is indexed.
  350. --*/
  351. {
  352. return IsResident() &&
  353. (_Data->Form.Resident.ResidentFlags & RESIDENT_FORM_INDEXED);
  354. }
  355. INLINE
  356. VCN
  357. NTFS_ATTRIBUTE_RECORD::QueryLowestVcn(
  358. ) CONST
  359. /*++
  360. Routine Description:
  361. This method returns the lowest VCN covered by this attribute
  362. record. If this attribute record is resident, the the lowest
  363. VCN is zero; if it is nonresident, the lowest VCN is given by
  364. the
  365. Arguments:
  366. None.
  367. Return Value:
  368. The lowest VCN covered by this attribute record.
  369. --*/
  370. {
  371. if( IsResident() ) {
  372. return 0;
  373. } else {
  374. return _Data->Form.Nonresident.LowestVcn;
  375. }
  376. }
  377. INLINE
  378. VCN
  379. NTFS_ATTRIBUTE_RECORD::QueryNextVcn(
  380. ) CONST
  381. /*++
  382. Routine Description:
  383. This method returns the highest VCN covered by this attribute
  384. record. If this attribute record is resident, then the highest
  385. VCN is zero; if it is nonresident, the highest VCN is given by
  386. the
  387. Arguments:
  388. None.
  389. Return Value:
  390. The highest VCN covered by this attribute record.
  391. --*/
  392. {
  393. if( IsResident() ) {
  394. return 1;
  395. } else {
  396. return _Data->Form.Nonresident.HighestVcn + 1;
  397. }
  398. }
  399. INLINE
  400. ULONG
  401. NTFS_ATTRIBUTE_RECORD::QueryNameLength(
  402. ) CONST
  403. /*++
  404. Routine Description:
  405. This method returns the length of the name, in characters.
  406. Zero indicates that the attribute record has no name.
  407. Arguments:
  408. None.
  409. Return Value:
  410. Length of the name, in characters.
  411. --*/
  412. {
  413. return _Data->NameLength;
  414. }
  415. INLINE
  416. USHORT
  417. NTFS_ATTRIBUTE_RECORD::QueryInstanceTag(
  418. ) CONST
  419. /*++
  420. Routine Description:
  421. This method queries the attribute record's unique-within-this-file
  422. attribute instance tag.
  423. Arguments:
  424. None.
  425. Return Value:
  426. The attribute record's instance tag.
  427. --*/
  428. {
  429. return _Data->Instance;
  430. }
  431. INLINE
  432. VOID
  433. NTFS_ATTRIBUTE_RECORD::SetInstanceTag(
  434. USHORT NewTag
  435. )
  436. /*++
  437. Routine Description:
  438. This method sets the attribute record's unique-within-this-file
  439. attribute instance tag.
  440. Arguments:
  441. NewTag -- Supplies the new value for the instance tag.
  442. Return Value:
  443. None.
  444. --*/
  445. {
  446. _Data->Instance = NewTag;
  447. }
  448. INLINE
  449. PWSTR
  450. NTFS_ATTRIBUTE_RECORD::GetName(
  451. ) CONST
  452. /*++
  453. Routine Description:
  454. This method returns a pointer to the wide-character attribute
  455. name.
  456. Arguments:
  457. None.
  458. Return Value:
  459. A pointer to the wide-character name in this attribute record;
  460. NULL if there is no name.
  461. Notes:
  462. This method is provided to permit optimization of the common
  463. attribute look-op operation in File Record Segments.
  464. --*/
  465. {
  466. if( QueryNameLength() == 0 ) {
  467. return NULL;
  468. } else {
  469. return( (PWSTR)( (PBYTE)_Data + _Data->NameOffset ) );
  470. }
  471. }
  472. INLINE
  473. PCVOID
  474. NTFS_ATTRIBUTE_RECORD::GetData(
  475. ) CONST
  476. /*++
  477. Routine Description:
  478. This method returns a pointer to the attribute record's data.
  479. Arguments:
  480. None.
  481. Return Value:
  482. A pointer to the attribute record's data.
  483. --*/
  484. {
  485. return _Data;
  486. }
  487. INLINE
  488. PCVOID
  489. NTFS_ATTRIBUTE_RECORD::GetResidentValue(
  490. ) CONST
  491. /*++
  492. Routine Description:
  493. This method returns a pointer to the attribute record's
  494. resident value. If the attribute record is non-resident,
  495. it returns NULL.
  496. Arguments:
  497. None.
  498. Return Value:
  499. The attribute record's resident value; NULL if the attribute
  500. record is non-resident.
  501. --*/
  502. {
  503. if( _Data->FormCode == NONRESIDENT_FORM ) {
  504. return NULL;
  505. } else {
  506. return ((PBYTE)_Data + _Data->Form.Resident.ValueOffset);
  507. }
  508. }
  509. INLINE
  510. USHORT
  511. NTFS_ATTRIBUTE_RECORD::QueryResidentValueOffset(
  512. ) CONST
  513. /*++
  514. Routine Description:
  515. This method returns the attribute record's resident value offset.
  516. If the attribute record is non-resident, it returns 0.
  517. Arguments:
  518. None.
  519. Return Value:
  520. The attribute record's resident value offset; 0 if the attribute
  521. record is non-resident.
  522. --*/
  523. {
  524. if( _Data->FormCode == NONRESIDENT_FORM ) {
  525. return NULL;
  526. } else {
  527. return _Data->Form.Resident.ValueOffset;
  528. }
  529. }
  530. INLINE
  531. ULONG
  532. NTFS_ATTRIBUTE_RECORD::QueryResidentValueLength(
  533. ) CONST
  534. /*++
  535. Routine Description:
  536. This method returns the attribute record's resident value
  537. length (zero if the attribute is nonresident).
  538. Arguments:
  539. None.
  540. Return Value:
  541. Who Cares.
  542. --*/
  543. {
  544. return( (_Data->FormCode == NONRESIDENT_FORM) ?
  545. 0 :
  546. _Data->Form.Resident.ValueLength );
  547. }
  548. INLINE
  549. VOID
  550. NTFS_ATTRIBUTE_RECORD::DisableUnUse(
  551. IN BOOLEAN NewState
  552. )
  553. {
  554. _DisableUnUse = NewState;
  555. }
  556. INLINE
  557. BOOLEAN
  558. NTFS_ATTRIBUTE_RECORD::IsUnUseDisabled(
  559. )
  560. {
  561. return _DisableUnUse;
  562. }
  563. #endif