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.

789 lines
21 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. frs.hxx
  5. Abstract:
  6. This module contains the declarations for the
  7. NTFS_FILE_RECORD_SEGMENT class. This class models File
  8. Record Segments in the NTFS Master File Table; it is the
  9. object through which a file's attributes may be accessed.
  10. Author:
  11. Bill McJohn (billmc) 13-June-91
  12. Environment:
  13. ULIB, User Mode
  14. --*/
  15. #if !defined( _NTFS_FILE_RECORD_SEGMENT_DEFN_ )
  16. #define _NTFS_FILE_RECORD_SEGMENT_DEFN_
  17. #include "frsstruc.hxx"
  18. #include "cannedsd.hxx"
  19. #include "clusrun.hxx"
  20. #include "array.hxx"
  21. #include "hmem.hxx"
  22. #include "list.hxx"
  23. #include "iterator.hxx"
  24. // Possible return codes for SortIndex:
  25. //
  26. // NTFS_SORT_INDEX_NOT_FOUND -- this FRS does not contain an
  27. // index with the specified name.
  28. // NTFS_SORT_INDEX_WELL_ORDERED -- the index was not sorted because
  29. // it was found to be well-ordered.
  30. // NTFS_SORT_INDEX_BADLY_ORDERED -- The index was found to be badly
  31. // ordered, and it was not sorted.
  32. // NTFS_SORT_INDEX_SORTED -- The index was sorted and new
  33. // attributes were inserted into
  34. // the FRS.
  35. // NTFS_SORT_INSERT_FAILED -- An insertion of an index entry
  36. // into the new tree failed.
  37. // (Probable cause: out of space.)
  38. // NTFS_SORT_ERROR -- Sort failed because of an error.
  39. //
  40. //
  41. typedef enum NTFS_SORT_CODE {
  42. NTFS_SORT_INDEX_NOT_FOUND,
  43. NTFS_SORT_INDEX_WELL_ORDERED,
  44. NTFS_SORT_INDEX_BADLY_ORDERED,
  45. NTFS_SORT_INDEX_SORTED,
  46. NTFS_SORT_INSERT_FAILED,
  47. NTFS_SORT_ERROR
  48. };
  49. // Possible return codes for VerifyAndFixQuotaDefaultId:
  50. //
  51. // NTFS_QUOTA_INDEX_NOT_FOUND -- this FRS does not contain an
  52. // index with the specified name.
  53. // NTFS_QUOTA_DEFAULT_ENTRY_MISSING-- the default entry was not found
  54. // in the index
  55. // NTFS_QUOTA_INDEX_FOUND -- Found the default Id entry in the
  56. // index tree.
  57. // NTFS_QUOTA_INDEX_INSERTED -- Inserted the default Id entry into
  58. // the index tree.
  59. // NTFS_QUOTA_INSERT_FAILED -- An insertion of the default Id
  60. // entry into the index tree failed.
  61. // (Probable cause: out of space.)
  62. // NTFS_QUOTA_ERROR -- error occurred. (Possibly out
  63. // of memory or out of space.)
  64. //
  65. typedef enum NTFS_QUOTA_CODE {
  66. NTFS_QUOTA_INDEX_NOT_FOUND,
  67. NTFS_QUOTA_INDEX_FOUND,
  68. NTFS_QUOTA_DEFAULT_ENTRY_MISSING,
  69. NTFS_QUOTA_INDEX_INSERTED,
  70. NTFS_QUOTA_INSERT_FAILED,
  71. NTFS_QUOTA_ERROR
  72. };
  73. // Possible return codes for FindSecurityIndexEntryAndValidate:
  74. //
  75. // NTFS_SECURITY_INDEX_ENTRY_MISSING -- the specified index entry key
  76. // cannot be found in the index
  77. // NTFS_SECURITY_INDEX_FOUND -- the found entry contains
  78. // correct data
  79. // NTFS_SECURITY_INDEX_FIXED -- the found entry contains invalid
  80. // data but is now corrected
  81. // NTFS_SECURITY_INDEX_DATA_ERROR -- The index was found but the data
  82. // data in it is incorrect.
  83. // NTFS_SECURITY_INDEX_INSERTED -- An index was successfully inserted
  84. // into the specified index.
  85. // NTFS_SECURITY_INSERT_FAILED -- An insertion of an index entry
  86. // into the index tree failed.
  87. // (Probable cause: out of space.)
  88. // NTFS_SECURITY_ERROR -- failed because of an error.
  89. // (Probably out of memory or out
  90. // of space.)
  91. //
  92. typedef enum NTFS_SECURITY_CODE {
  93. NTFS_SECURITY_INDEX_ENTRY_MISSING,
  94. NTFS_SECURITY_INDEX_FOUND,
  95. NTFS_SECURITY_INDEX_FIXED,
  96. NTFS_SECURITY_INDEX_DATA_ERROR,
  97. NTFS_SECURITY_INDEX_INSERTED,
  98. NTFS_SECURITY_INSERT_FAILED,
  99. NTFS_SECURITY_ERROR
  100. };
  101. // Forward references
  102. DECLARE_CLASS( IO_DP_DRIVE );
  103. DECLARE_CLASS( NTFS_MASTER_FILE_TABLE );
  104. DECLARE_CLASS( NTFS_MFT_FILE );
  105. DECLARE_CLASS( NTFS_ATTRIBUTE );
  106. DECLARE_CLASS( WSTRING );
  107. DECLARE_CLASS( NTFS_ATTRIBUTE_RECORD );
  108. DECLARE_CLASS( NTFS_ATTRIBUTE_RECORD_LIST );
  109. DECLARE_CLASS( NTFS_FILE_RECORD_SEGMENT );
  110. DECLARE_CLASS( NTFS_ATTRIBUTE_LIST );
  111. DECLARE_CLASS( NTFS_BITMAP );
  112. DECLARE_CLASS( NTFS_BAD_CLUSTER_FILE );
  113. class NTFS_FILE_RECORD_SEGMENT : public NTFS_FRS_STRUCTURE {
  114. public:
  115. UNTFS_EXPORT
  116. DECLARE_CONSTRUCTOR( NTFS_FILE_RECORD_SEGMENT );
  117. VIRTUAL
  118. UNTFS_EXPORT
  119. ~NTFS_FILE_RECORD_SEGMENT (
  120. );
  121. NONVIRTUAL
  122. UNTFS_EXPORT
  123. BOOLEAN
  124. Initialize (
  125. IN VCN FileNumber,
  126. IN OUT PNTFS_MFT_FILE MftFile
  127. );
  128. NONVIRTUAL
  129. UNTFS_EXPORT
  130. BOOLEAN
  131. Initialize (
  132. IN VCN FileNumber,
  133. IN OUT PNTFS_MASTER_FILE_TABLE Mft
  134. );
  135. NONVIRTUAL
  136. UNTFS_EXPORT
  137. BOOLEAN
  138. Initialize(
  139. IN VCN FirstFileNumber,
  140. IN ULONG FrsCount,
  141. IN OUT PNTFS_MASTER_FILE_TABLE Mft
  142. );
  143. NONVIRTUAL
  144. UNTFS_EXPORT
  145. BOOLEAN
  146. Initialize(
  147. );
  148. NONVIRTUAL
  149. UNTFS_EXPORT
  150. BOOLEAN
  151. Create (
  152. IN PCSTANDARD_INFORMATION StandardInformation,
  153. IN USHORT Flags DEFAULT 0
  154. );
  155. NONVIRTUAL
  156. BOOLEAN
  157. Create (
  158. IN PCMFT_SEGMENT_REFERENCE BaseSegment,
  159. IN USHORT Flags DEFAULT 0
  160. );
  161. NONVIRTUAL
  162. BOOLEAN
  163. CreateSystemFile(
  164. IN UCHAR major DEFAULT 0,
  165. IN UCHAR minor DEFAULT 0
  166. );
  167. NONVIRTUAL
  168. BOOLEAN
  169. CreateExtendSystemFile(
  170. IN PCWSTRING file_name_text,
  171. IN USHORT FrsFlags,
  172. IN ULONG FileAttributes DEFAULT 0
  173. );
  174. NONVIRTUAL
  175. BOOLEAN
  176. VerifyAndFixFileNames(
  177. IN OUT PNTFS_BITMAP VolumeBitmap,
  178. IN PCNTFS_CHKDSK_INFO ChkdskInfo,
  179. IN FIX_LEVEL FixLevel,
  180. IN OUT PMESSAGE Message,
  181. IN OUT PBOOLEAN DiskErrorsFound DEFAULT NULL,
  182. IN BOOLEAN FixDupInfo DEFAULT TRUE,
  183. IN BOOLEAN ClearSystemFlags DEFAULT FALSE
  184. );
  185. VIRTUAL
  186. UNTFS_EXPORT
  187. BOOLEAN
  188. Write(
  189. );
  190. NONVIRTUAL
  191. UNTFS_EXPORT
  192. BOOLEAN
  193. Flush(
  194. IN OUT PNTFS_BITMAP VolumeBitmap OPTIONAL,
  195. IN OUT PNTFS_INDEX_TREE ParentIndex DEFAULT NULL,
  196. IN BOOLEAN FrsIsEmpty DEFAULT FALSE
  197. );
  198. NONVIRTUAL
  199. BOOLEAN
  200. AddDataAttribute(
  201. IN ULONG InitialSize,
  202. IN OUT PNTFS_BITMAP VolumeBitmap,
  203. IN BOOLEAN Fill DEFAULT FALSE,
  204. IN CHAR FillCharacter DEFAULT 0
  205. );
  206. NONVIRTUAL
  207. UNTFS_EXPORT
  208. BOOLEAN
  209. AddFileNameAttribute(
  210. IN PFILE_NAME FileNameAttributeValue
  211. );
  212. NONVIRTUAL
  213. BOOLEAN
  214. AddAttribute(
  215. IN ATTRIBUTE_TYPE_CODE Type,
  216. IN PCWSTRING Name OPTIONAL,
  217. IN PCVOID Value OPTIONAL,
  218. IN ULONG Length,
  219. IN OUT PNTFS_BITMAP Bitmap OPTIONAL,
  220. IN BOOLEAN IsIndexed DEFAULT FALSE
  221. );
  222. NONVIRTUAL
  223. UNTFS_EXPORT
  224. BOOLEAN
  225. AddSecurityDescriptor(
  226. IN CANNED_SECURITY_TYPE SecurityType,
  227. IN OUT PNTFS_BITMAP Bitmap
  228. );
  229. NONVIRTUAL
  230. UNTFS_EXPORT
  231. BOOLEAN
  232. AddSecurityDescriptorData(
  233. IN PNTFS_ATTRIBUTE attribute,
  234. IN OUT PVOID buffer,
  235. OUT PSECURITY_ENTRY *SecurityEntry,
  236. IN ULONG SecurityId,
  237. IN CANNED_SECURITY_TYPE SecurityType,
  238. IN OUT PNTFS_BITMAP Bitmap,
  239. IN BOOLEAN FixLevel
  240. );
  241. NONVIRTUAL
  242. BOOLEAN
  243. AddEmptyAttribute(
  244. IN ATTRIBUTE_TYPE_CODE Type,
  245. IN PCWSTRING Name DEFAULT NULL
  246. );
  247. NONVIRTUAL
  248. UNTFS_EXPORT
  249. BOOLEAN
  250. IsAttributePresent (
  251. IN ATTRIBUTE_TYPE_CODE Type,
  252. IN PCWSTRING Name DEFAULT NULL,
  253. IN BOOLEAN IgnoreExternal DEFAULT FALSE
  254. );
  255. NONVIRTUAL
  256. BOOLEAN
  257. QueryAttributeRecord (
  258. OUT PNTFS_ATTRIBUTE_RECORD AttributeRecord,
  259. IN ATTRIBUTE_TYPE_CODE Type,
  260. IN PCWSTRING Name DEFAULT NULL
  261. );
  262. NONVIRTUAL
  263. UNTFS_EXPORT
  264. BOOLEAN
  265. QueryAttribute (
  266. OUT PNTFS_ATTRIBUTE Attribute,
  267. OUT PBOOLEAN Error,
  268. IN ATTRIBUTE_TYPE_CODE Type,
  269. IN PCWSTRING Name DEFAULT NULL
  270. );
  271. NONVIRTUAL
  272. BOOLEAN
  273. Delete(
  274. IN OUT PNTFS_BITMAP VolumeBitmap
  275. );
  276. NONVIRTUAL
  277. UNTFS_EXPORT
  278. BOOLEAN
  279. QueryAttributeListAttribute (
  280. OUT PNTFS_ATTRIBUTE Attribute,
  281. OUT PBOOLEAN Error
  282. );
  283. NONVIRTUAL
  284. UNTFS_EXPORT
  285. BOOLEAN
  286. QueryFileSizes (
  287. OUT PBIG_INT AllocatedLength,
  288. OUT PBIG_INT FileSize,
  289. OUT PBOOLEAN Error
  290. );
  291. NONVIRTUAL
  292. BOOLEAN
  293. QueryResidentAttribute (
  294. OUT PNTFS_ATTRIBUTE Attribute,
  295. OUT PBOOLEAN Error,
  296. IN ATTRIBUTE_TYPE_CODE Type,
  297. IN PCVOID Value,
  298. IN ULONG ValueLength,
  299. IN COLLATION_RULE CollationRule DEFAULT COLLATION_BINARY
  300. );
  301. NONVIRTUAL
  302. UNTFS_EXPORT
  303. BOOLEAN
  304. QueryAttributeByOrdinal (
  305. OUT PNTFS_ATTRIBUTE Attribute,
  306. OUT PBOOLEAN Error,
  307. IN ATTRIBUTE_TYPE_CODE Type,
  308. IN ULONG Ordinal
  309. );
  310. NONVIRTUAL
  311. BOOLEAN
  312. QueryAttributeByTag (
  313. OUT PNTFS_ATTRIBUTE Attribute,
  314. OUT PBOOLEAN Error,
  315. IN ULONG Tag
  316. );
  317. NONVIRTUAL
  318. BOOLEAN
  319. PurgeAttribute (
  320. IN ATTRIBUTE_TYPE_CODE Type,
  321. IN PCWSTRING Name DEFAULT NULL,
  322. IN BOOLEAN IgnoreExternal DEFAULT FALSE
  323. );
  324. NONVIRTUAL
  325. BOOLEAN
  326. DeleteResidentAttribute(
  327. IN ATTRIBUTE_TYPE_CODE Type,
  328. IN PCWSTRING Name OPTIONAL,
  329. IN PCVOID Value,
  330. IN ULONG ValueLength,
  331. OUT PBOOLEAN Deleted,
  332. IN BOOLEAN IgnoreExternal DEFAULT FALSE
  333. );
  334. NONVIRTUAL
  335. BOOLEAN
  336. DeleteResidentAttributeLocal(
  337. IN ATTRIBUTE_TYPE_CODE Type,
  338. IN PCWSTRING Name OPTIONAL,
  339. IN PCVOID Value,
  340. IN ULONG ValueLength,
  341. OUT PBOOLEAN Deleted,
  342. OUT PBOOLEAN IsIndexed,
  343. OUT PUSHORT InstanceTag
  344. );
  345. VIRTUAL
  346. BOOLEAN
  347. InsertAttributeRecord (
  348. IN OUT PNTFS_ATTRIBUTE_RECORD NewRecord,
  349. IN BOOLEAN ForceExternal DEFAULT FALSE
  350. );
  351. NONVIRTUAL
  352. USHORT
  353. QueryNextInstance(
  354. );
  355. NONVIRTUAL
  356. VOID
  357. IncrementNextInstance(
  358. );
  359. NONVIRTUAL
  360. ULONG
  361. QueryFreeSpace(
  362. );
  363. NONVIRTUAL
  364. ULONG
  365. QueryMaximumAttributeRecordSize (
  366. ) CONST;
  367. NONVIRTUAL
  368. BOOLEAN
  369. QueryNextAttribute(
  370. IN OUT PATTRIBUTE_TYPE_CODE TypeCode,
  371. IN OUT PWSTRING Name
  372. );
  373. NONVIRTUAL
  374. BOOLEAN
  375. RecoverFile(
  376. IN OUT PNTFS_BITMAP VolumeBitmap,
  377. IN OUT PNUMBER_SET BadClusterList,
  378. IN UCHAR VolumeMajorVersion,
  379. OUT PULONG BadClusters,
  380. OUT PBIG_INT BytesRecovered,
  381. OUT PBIG_INT TotalBytes
  382. );
  383. NONVIRTUAL
  384. NTFS_SORT_CODE
  385. SortIndex(
  386. IN PCWSTRING IndexName,
  387. IN OUT PNTFS_BITMAP VolumeBitmap,
  388. IN BOOLEAN DuplicatesAllowed,
  389. IN BOOLEAN CheckOnly DEFAULT FALSE
  390. );
  391. NONVIRTUAL
  392. NTFS_QUOTA_CODE
  393. VerifyAndFixQuotaDefaultId(
  394. IN OUT PNTFS_BITMAP VolumeBitmap,
  395. IN BOOLEAN CheckOnly
  396. );
  397. NONVIRTUAL
  398. NTFS_SECURITY_CODE
  399. FindSecurityIndexEntryAndValidate(
  400. IN OUT PNTFS_INDEX_TREE OldTree,
  401. IN PVOID Key,
  402. IN USHORT KeyLength,
  403. IN PSECURITY_DESCRIPTOR_HEADER SecurityDescriptorHeader,
  404. IN OUT PNTFS_BITMAP VolumeBitmap,
  405. IN BOOLEAN CheckOnly
  406. );
  407. NONVIRTUAL
  408. BOOLEAN
  409. QueryDuplicatedInformation(
  410. OUT PDUPLICATED_INFORMATION DuplicatedInformation
  411. );
  412. NONVIRTUAL
  413. BOOLEAN
  414. UpdateFileNames(
  415. IN PDUPLICATED_INFORMATION DuplicatedInformation,
  416. IN OUT PNTFS_INDEX_TREE Index OPTIONAL,
  417. IN BOOLEAN IgnoreExternal
  418. );
  419. NONVIRTUAL
  420. BOOLEAN
  421. Backtrack(
  422. OUT PWSTRING Path
  423. );
  424. NONVIRTUAL
  425. VOID
  426. SetLsn(
  427. IN BIG_INT NewLsn
  428. );
  429. NONVIRTUAL
  430. BOOLEAN
  431. PurgeAttributeList (
  432. );
  433. NONVIRTUAL
  434. BOOLEAN
  435. IsAttributeListPresent(
  436. );
  437. protected:
  438. NONVIRTUAL
  439. BOOLEAN
  440. Initialize(
  441. IN OUT PLOG_IO_DP_DRIVE Drive,
  442. IN LCN StartOfMft,
  443. IN PNTFS_MASTER_FILE_TABLE Mft
  444. );
  445. private:
  446. NONVIRTUAL
  447. VOID
  448. Construct (
  449. );
  450. inline
  451. NONVIRTUAL
  452. VOID
  453. Destroy2 (
  454. );
  455. NONVIRTUAL
  456. VOID
  457. Destroy (
  458. );
  459. NONVIRTUAL
  460. BOOLEAN
  461. Create (
  462. IN USHORT Flags DEFAULT 0
  463. );
  464. NONVIRTUAL
  465. BOOLEAN
  466. SetupAttributeList(
  467. );
  468. NONVIRTUAL
  469. BOOLEAN
  470. CreateAttributeList(
  471. OUT PNTFS_ATTRIBUTE_LIST AttributeList
  472. );
  473. NONVIRTUAL
  474. BOOLEAN
  475. SaveAttributeList(
  476. PNTFS_BITMAP VolumeBitmap
  477. );
  478. NONVIRTUAL
  479. BOOLEAN
  480. InsertExternalAttributeRecord(
  481. IN PNTFS_ATTRIBUTE_RECORD NewRecord
  482. );
  483. NONVIRTUAL
  484. BOOLEAN
  485. BacktrackWorker(
  486. IN OUT PWSTRING Path
  487. );
  488. NONVIRTUAL
  489. PNTFS_FILE_RECORD_SEGMENT
  490. SetupChild(
  491. IN VCN FileNumber
  492. );
  493. NONVIRTUAL
  494. BOOLEAN
  495. AddChild(
  496. PNTFS_FILE_RECORD_SEGMENT ChildFrs
  497. );
  498. NONVIRTUAL
  499. PNTFS_FILE_RECORD_SEGMENT
  500. GetChild(
  501. VCN FileNumber
  502. );
  503. NONVIRTUAL
  504. VOID
  505. DeleteChild(
  506. VCN FileNumber
  507. );
  508. HMEM _Mem;
  509. LIST _Children;
  510. PITERATOR _ChildIterator;
  511. PNTFS_MASTER_FILE_TABLE _Mft;
  512. PNTFS_ATTRIBUTE_LIST _AttributeList;
  513. };
  514. INLINE
  515. USHORT
  516. NTFS_FILE_RECORD_SEGMENT::QueryNextInstance(
  517. )
  518. /*++
  519. Routine Description:
  520. This method fetches the current value of the FRS'
  521. NextAttributeInstance field.
  522. Arguments:
  523. None.
  524. Return Value:
  525. The current value of the FRS' NextAttributeInstance field.
  526. --*/
  527. {
  528. return _FrsData->NextAttributeInstance;
  529. }
  530. INLINE
  531. VOID
  532. NTFS_FILE_RECORD_SEGMENT::IncrementNextInstance(
  533. )
  534. /*++
  535. Routine Description:
  536. This method increments the NextAttributeInstance field of
  537. the File Record Segment.
  538. Arguments:
  539. None.
  540. Return Value:
  541. None.
  542. --*/
  543. {
  544. _FrsData->NextAttributeInstance++;
  545. }
  546. INLINE
  547. ULONG
  548. NTFS_FILE_RECORD_SEGMENT::QueryFreeSpace(
  549. )
  550. /*++
  551. Routine Description:
  552. This method returns the amount of free space following the
  553. last Attribute Record in the File Record Segment.
  554. Arguments:
  555. None.
  556. Return Value:
  557. The amount of free space.
  558. Notes:
  559. This method assumes that the FRS is consistent.
  560. --*/
  561. {
  562. return _FrsData->BytesAvailable - _FrsData->FirstFreeByte;
  563. }
  564. INLINE
  565. ULONG
  566. NTFS_FILE_RECORD_SEGMENT::QueryMaximumAttributeRecordSize (
  567. ) CONST
  568. /*++
  569. Routine Description:
  570. This method returns the size of the largest attribute record
  571. the File Record Segment will accept. Note that this is the
  572. largest record it will ever accept, not what it can currently
  573. accept.
  574. Arguments:
  575. None.
  576. Return Value:
  577. The size of the largest attribute record a File Record Segment
  578. of this size can accept.
  579. --*/
  580. {
  581. ULONG temp;
  582. //
  583. // Take a precaution to make sure this routine never returns a
  584. // "negative" number.
  585. //
  586. temp = _FrsData->FirstAttributeOffset + QuadAlign(sizeof(ATTRIBUTE_TYPE_CODE));
  587. if (temp > QuerySize()) {
  588. return QuerySize();
  589. }
  590. return QuerySize() - temp;
  591. }
  592. INLINE
  593. BOOLEAN
  594. NTFS_FILE_RECORD_SEGMENT::AddEmptyAttribute(
  595. IN ATTRIBUTE_TYPE_CODE Type,
  596. IN PCWSTRING Name
  597. )
  598. /*++
  599. Routine Description:
  600. This method adds an empty, non-indexed, resident attribute of
  601. the specified type to the FRS.
  602. Arguments:
  603. Type -- Supplies the attribute's type code.
  604. Name -- Supplies the attribute's name. May be NULL, in which
  605. case the attribute has no name.
  606. Return Value:
  607. TRUE upon successful completion.
  608. --*/
  609. {
  610. NTFS_ATTRIBUTE Attribute;
  611. return( Attribute.Initialize( GetDrive(),
  612. QueryClusterFactor(),
  613. NULL,
  614. 0,
  615. Type,
  616. Name,
  617. 0 ) &&
  618. Attribute.InsertIntoFile( this, NULL ) );
  619. }
  620. INLINE
  621. BOOLEAN
  622. NTFS_FILE_RECORD_SEGMENT::IsAttributeListPresent(
  623. )
  624. /*++
  625. Routine Description:
  626. This method checks for the presence of an attribute list.
  627. Arguments:
  628. N/A
  629. Return Value:
  630. TRUE if there is an attribute list.
  631. --*/
  632. {
  633. return (_AttributeList != NULL) ||
  634. IsAttributePresent($ATTRIBUTE_LIST, NULL, TRUE);
  635. }
  636. #endif