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.

999 lines
18 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. frsstruc.hxx
  5. Abstract:
  6. This class models a file record segment structure.
  7. Author:
  8. Norbert P. Kusters (norbertk) 17-Sep-91
  9. Environment:
  10. ULIB, User Mode
  11. --*/
  12. #if !defined( _NTFS_FRS_STRUCTURE_DEFN_ )
  13. #define _NTFS_FRS_STRUCTURE_DEFN_
  14. #include "volume.hxx"
  15. #include "ntfssa.hxx"
  16. #include "tlink.hxx"
  17. DECLARE_CLASS( NTFS_FRS_STRUCTURE );
  18. DECLARE_CLASS( MEM );
  19. DECLARE_CLASS( NTFS_ATTRIBUTE );
  20. DECLARE_CLASS( LOG_IO_DP_DRIVE );
  21. DECLARE_CLASS( NTFS_CLUSTER_RUN );
  22. DECLARE_CLASS( WSTRING );
  23. DECLARE_CLASS( MESSAGE );
  24. DECLARE_CLASS( NTFS_ATTRIBUTE_COLUMNS );
  25. DECLARE_CLASS( NTFS_ATTRIBUTE_LIST );
  26. DECLARE_CLASS( NTFS_BITMAP );
  27. DECLARE_CLASS( NTFS_UPCASE_TABLE );
  28. class NTFS_FRS_STRUCTURE : public OBJECT {
  29. public:
  30. UNTFS_EXPORT
  31. DECLARE_CONSTRUCTOR( NTFS_FRS_STRUCTURE );
  32. VIRTUAL
  33. UNTFS_EXPORT
  34. ~NTFS_FRS_STRUCTURE(
  35. );
  36. NONVIRTUAL
  37. UNTFS_EXPORT
  38. BOOLEAN
  39. Initialize(
  40. IN OUT PMEM Mem,
  41. IN OUT PNTFS_ATTRIBUTE MftData,
  42. IN VCN FileNumber,
  43. IN ULONG ClusterFactor,
  44. IN BIG_INT VolumeSectors,
  45. IN ULONG FrsSize,
  46. IN PNTFS_UPCASE_TABLE UpcaseTable OPTIONAL
  47. );
  48. UNTFS_EXPORT
  49. BOOLEAN
  50. Initialize(
  51. IN OUT PMEM Mem,
  52. IN OUT PNTFS_ATTRIBUTE MftData,
  53. IN VCN FirstFileNumber,
  54. IN ULONG FrsCount,
  55. IN ULONG ClusterFactor,
  56. IN BIG_INT VolumeSectors,
  57. IN ULONG FrsSize,
  58. IN PNTFS_UPCASE_TABLE UpcaseTable
  59. );
  60. NONVIRTUAL
  61. UNTFS_EXPORT
  62. BOOLEAN
  63. Initialize(
  64. IN OUT PMEM Mem,
  65. IN OUT PLOG_IO_DP_DRIVE Drive,
  66. IN LCN StartOfMft,
  67. IN ULONG ClusterFactor,
  68. IN BIG_INT VolumeSectors,
  69. IN ULONG FrsSize,
  70. IN PNTFS_UPCASE_TABLE UpcaseTable DEFAULT NULL,
  71. IN ULONG Offset DEFAULT 0
  72. );
  73. NONVIRTUAL
  74. BOOLEAN
  75. VerifyAndFix(
  76. IN FIX_LEVEL FixLevel,
  77. IN OUT PMESSAGE Message,
  78. IN PCNTFS_ATTRIBUTE_COLUMNS AttributeDefTable OPTIONAL,
  79. IN OUT PBOOLEAN DiskErrorsFound DEFAULT NULL
  80. );
  81. #if defined(LOCATE_DELETED_FILE)
  82. NONVIRTUAL
  83. BOOLEAN
  84. LocateUnuseFrs(
  85. IN FIX_LEVEL FixLevel,
  86. IN OUT PMESSAGE Message,
  87. IN PCNTFS_ATTRIBUTE_COLUMNS AttributeDefTable OPTIONAL,
  88. IN OUT PBOOLEAN DiskErrorsFound DEFAULT NULL
  89. );
  90. #endif
  91. NONVIRTUAL
  92. BOOLEAN
  93. LoneFrsAllocationCheck(
  94. IN OUT PNTFS_BITMAP VolumeBitmap,
  95. IN OUT PNTFS_CHKDSK_REPORT ChkdskReport,
  96. IN OUT PNTFS_CHKDSK_INFO ChkdskInfo,
  97. IN FIX_LEVEL FixLevel,
  98. IN OUT PMESSAGE Message,
  99. IN OUT PBOOLEAN DiskErrorsFound DEFAULT NULL
  100. );
  101. NONVIRTUAL
  102. BOOLEAN
  103. CheckInstanceTags(
  104. IN FIX_LEVEL FixLevel,
  105. IN BOOLEAN Verbose,
  106. IN OUT PMESSAGE Message,
  107. OUT PBOOLEAN Changes,
  108. IN OUT PNTFS_ATTRIBUTE_LIST AttributeList DEFAULT NULL
  109. );
  110. VIRTUAL
  111. UNTFS_EXPORT
  112. BOOLEAN
  113. Read(
  114. );
  115. UNTFS_EXPORT
  116. BOOLEAN
  117. ReadNext(
  118. IN VCN FileNumber
  119. );
  120. UNTFS_EXPORT
  121. BOOLEAN
  122. ReadAgain(
  123. IN VCN FileNumber
  124. );
  125. UNTFS_EXPORT
  126. BOOLEAN
  127. ReadSet(
  128. IN OUT PTLINK Link
  129. );
  130. NONVIRTUAL
  131. UNTFS_EXPORT
  132. BOOLEAN
  133. Write(
  134. );
  135. NONVIRTUAL
  136. UNTFS_EXPORT
  137. PVOID
  138. GetNextAttributeRecord(
  139. IN PCVOID AttributeRecord,
  140. IN OUT PMESSAGE Message DEFAULT NULL,
  141. OUT PBOOLEAN ErrorsFound DEFAULT NULL
  142. );
  143. NONVIRTUAL
  144. VOID
  145. DeleteAttributeRecord(
  146. IN OUT PVOID AttributeRecord
  147. );
  148. NONVIRTUAL
  149. BOOLEAN
  150. InsertAttributeRecord(
  151. IN OUT PVOID Position,
  152. IN PCVOID AttributeRecord
  153. );
  154. NONVIRTUAL
  155. UNTFS_EXPORT
  156. BOOLEAN
  157. QueryAttributeList(
  158. OUT PNTFS_ATTRIBUTE_LIST AttributeList
  159. );
  160. NONVIRTUAL
  161. PVOID
  162. GetAttribute(
  163. IN ULONG TypeCode
  164. );
  165. NONVIRTUAL
  166. PVOID
  167. GetAttributeList(
  168. );
  169. NONVIRTUAL
  170. BOOLEAN
  171. UpdateAttributeList(
  172. IN PCNTFS_ATTRIBUTE_LIST AttributeList,
  173. IN BOOLEAN WriteList
  174. );
  175. NONVIRTUAL
  176. UNTFS_EXPORT
  177. BOOLEAN
  178. SafeQueryAttribute(
  179. IN ATTRIBUTE_TYPE_CODE TypeCode,
  180. IN OUT PNTFS_ATTRIBUTE MftData,
  181. OUT PNTFS_ATTRIBUTE Attribute
  182. );
  183. NONVIRTUAL
  184. MFT_SEGMENT_REFERENCE
  185. QuerySegmentReference(
  186. ) CONST;
  187. NONVIRTUAL
  188. FILE_REFERENCE
  189. QueryBaseFileRecordSegment(
  190. ) CONST;
  191. NONVIRTUAL
  192. BOOLEAN
  193. IsBase(
  194. ) CONST;
  195. NONVIRTUAL
  196. BOOLEAN
  197. IsInUse(
  198. ) CONST;
  199. NONVIRTUAL
  200. VOID
  201. ClearInUse(
  202. );
  203. NONVIRTUAL
  204. BOOLEAN
  205. IsSystemFile(
  206. ) CONST;
  207. NONVIRTUAL
  208. VOID
  209. SetSystemFile(
  210. );
  211. NONVIRTUAL
  212. BOOLEAN
  213. IsViewIndexPresent(
  214. ) CONST;
  215. NONVIRTUAL
  216. VOID
  217. SetViewIndexPresent(
  218. );
  219. NONVIRTUAL
  220. VOID
  221. ClearViewIndexPresent(
  222. );
  223. NONVIRTUAL
  224. BOOLEAN
  225. IsIndexPresent(
  226. ) CONST;
  227. NONVIRTUAL
  228. VOID
  229. SetIndexPresent(
  230. );
  231. NONVIRTUAL
  232. VOID
  233. ClearIndexPresent(
  234. );
  235. NONVIRTUAL
  236. VCN
  237. QueryFileNumber(
  238. ) CONST;
  239. NONVIRTUAL
  240. ULONG
  241. QueryClusterFactor(
  242. ) CONST;
  243. NONVIRTUAL
  244. ULONG
  245. QuerySize(
  246. ) CONST;
  247. NONVIRTUAL
  248. PLOG_IO_DP_DRIVE
  249. GetDrive(
  250. );
  251. NONVIRTUAL
  252. VOID
  253. SetFrsData(
  254. IN VCN FileNumber,
  255. IN PFILE_RECORD_SEGMENT_HEADER frsdata
  256. );
  257. NONVIRTUAL
  258. USHORT
  259. QueryReferenceCount(
  260. ) CONST;
  261. NONVIRTUAL
  262. VOID
  263. SetReferenceCount(
  264. IN USHORT ReferenceCount
  265. );
  266. NONVIRTUAL
  267. BIG_INT
  268. QueryVolumeSectors(
  269. ) CONST;
  270. NONVIRTUAL
  271. PNTFS_UPCASE_TABLE
  272. GetUpcaseTable(
  273. );
  274. NONVIRTUAL
  275. VOID
  276. SetUpcaseTable(
  277. IN PNTFS_UPCASE_TABLE UpcaseTable
  278. );
  279. NONVIRTUAL
  280. LSN
  281. QueryLsn(
  282. ) CONST;
  283. protected:
  284. NONVIRTUAL
  285. ULONG
  286. QueryAvailableSpace(
  287. );
  288. PFILE_RECORD_SEGMENT_HEADER _FrsData;
  289. private:
  290. NONVIRTUAL
  291. BOOLEAN
  292. Sort(
  293. OUT PBOOLEAN Changes,
  294. OUT PBOOLEAN Duplicates
  295. );
  296. NONVIRTUAL
  297. VOID
  298. Construct(
  299. );
  300. NONVIRTUAL
  301. VOID
  302. Destroy(
  303. );
  304. PSECRUN _secrun;
  305. PNTFS_ATTRIBUTE _mftdata;
  306. PNTFS_UPCASE_TABLE _upcase_table;
  307. VCN _file_number;
  308. VCN _first_file_number;
  309. ULONG _frs_count;
  310. BOOLEAN _frs_state;
  311. BOOLEAN _read_status;
  312. ULONG _cluster_factor;
  313. ULONG _size;
  314. PLOG_IO_DP_DRIVE _drive;
  315. BIG_INT _volume_sectors;
  316. UCHAR _usa_check;
  317. };
  318. INLINE
  319. MFT_SEGMENT_REFERENCE
  320. NTFS_FRS_STRUCTURE::QuerySegmentReference(
  321. ) CONST
  322. /*++
  323. Routine Description:
  324. This routine computes the segment reference value for this FRS.
  325. Arguments:
  326. None.
  327. Return Value:
  328. The segment reference value for this FRS.
  329. --*/
  330. {
  331. MFT_SEGMENT_REFERENCE SegmentReference;
  332. DebugAssert( _FrsData );
  333. SegmentReference.LowPart = _file_number.GetLowPart();
  334. SegmentReference.HighPart = (USHORT) _file_number.GetHighPart();
  335. SegmentReference.SequenceNumber = _FrsData->SequenceNumber;
  336. return SegmentReference;
  337. }
  338. INLINE
  339. FILE_REFERENCE
  340. NTFS_FRS_STRUCTURE::QueryBaseFileRecordSegment(
  341. ) CONST
  342. /*++
  343. Routine Description:
  344. This field contains a pointer to the base file record segment for
  345. this file record segment.
  346. Arguments:
  347. None.
  348. Return Value:
  349. A FILE_REFERENCE to the base file record segment for this file
  350. record segment.
  351. --*/
  352. {
  353. DebugAssert( _FrsData );
  354. return _FrsData->BaseFileRecordSegment;
  355. }
  356. INLINE
  357. BOOLEAN
  358. NTFS_FRS_STRUCTURE::IsBase(
  359. ) CONST
  360. /*++
  361. Routine Description:
  362. This method determines whether this File Record Segment is the
  363. Base File Record Segment for its file.
  364. Arguments:
  365. None.
  366. Return Value:
  367. TRUE if this is a Base File Record Segment; FALSE otherwise.
  368. --*/
  369. {
  370. return( _FrsData->BaseFileRecordSegment.LowPart == 0 &&
  371. _FrsData->BaseFileRecordSegment.HighPart == 0 &&
  372. _FrsData->BaseFileRecordSegment.SequenceNumber == 0 );
  373. }
  374. INLINE
  375. BOOLEAN
  376. NTFS_FRS_STRUCTURE::IsInUse(
  377. ) CONST
  378. /*++
  379. Routine Description:
  380. This routine computes whether or not this file record segment is in
  381. use.
  382. Arguments:
  383. None.
  384. Return Value:
  385. FALSE - This file record segment is not in use.
  386. TRUE - This file record segment is in use.
  387. --*/
  388. {
  389. DebugAssert( _FrsData );
  390. return (_FrsData->Flags & FILE_RECORD_SEGMENT_IN_USE) ? TRUE : FALSE;
  391. }
  392. INLINE
  393. VOID
  394. NTFS_FRS_STRUCTURE::ClearInUse(
  395. )
  396. /*++
  397. Routine Description:
  398. This routine clears the in use bit on this file record segment.
  399. Arguments:
  400. None.
  401. Return Value:
  402. None.
  403. --*/
  404. {
  405. DebugAssert( _FrsData );
  406. _FrsData->Flags &= ~FILE_RECORD_SEGMENT_IN_USE;
  407. }
  408. INLINE
  409. BOOLEAN
  410. NTFS_FRS_STRUCTURE::IsSystemFile(
  411. ) CONST
  412. /*++
  413. Routine Description:
  414. This routine computes whether or not this file record segment is a
  415. system file.
  416. Arguments:
  417. None.
  418. Return Value:
  419. FALSE - This file record segment is not a system file.
  420. TRUE - This file record segment is a system file.
  421. --*/
  422. {
  423. DebugAssert( _FrsData );
  424. return (_FrsData->Flags & FILE_SYSTEM_FILE) ? TRUE : FALSE;
  425. }
  426. INLINE
  427. VOID
  428. NTFS_FRS_STRUCTURE::SetSystemFile(
  429. )
  430. /*++
  431. Routine Description:
  432. This routine sets the system file bit on this file record segment.
  433. Arguments:
  434. None.
  435. Return Value:
  436. None.
  437. --*/
  438. {
  439. DebugAssert( _FrsData );
  440. _FrsData->Flags |= FILE_SYSTEM_FILE;
  441. }
  442. INLINE
  443. BOOLEAN
  444. NTFS_FRS_STRUCTURE::IsViewIndexPresent(
  445. ) CONST
  446. /*++
  447. Routine Description:
  448. This routine computes whether or not the indices of file record segment
  449. can be viewed.
  450. Arguments:
  451. None.
  452. Return Value:
  453. FALSE - The indices of this file record segment cannot be viewed.
  454. TRUE - The indices of this file record segment can be viewed.
  455. --*/
  456. {
  457. DebugAssert( _FrsData );
  458. return (_FrsData->Flags & FILE_VIEW_INDEX_PRESENT) ? TRUE : FALSE;
  459. }
  460. INLINE
  461. VOID
  462. NTFS_FRS_STRUCTURE::SetViewIndexPresent(
  463. )
  464. /*++
  465. Routine Description:
  466. This routine sets the view index present bit on this file record segment.
  467. Arguments:
  468. None.
  469. Return Value:
  470. None.
  471. --*/
  472. {
  473. DebugAssert( _FrsData );
  474. _FrsData->Flags |= FILE_VIEW_INDEX_PRESENT;
  475. }
  476. INLINE
  477. VOID
  478. NTFS_FRS_STRUCTURE::ClearViewIndexPresent(
  479. )
  480. /*++
  481. Routine Description:
  482. This routine clears the view index present bit on this file record segment.
  483. Arguments:
  484. None.
  485. Return Value:
  486. None.
  487. --*/
  488. {
  489. DebugAssert( _FrsData );
  490. _FrsData->Flags &= ~FILE_VIEW_INDEX_PRESENT;
  491. }
  492. INLINE
  493. BOOLEAN
  494. NTFS_FRS_STRUCTURE::IsIndexPresent(
  495. ) CONST
  496. /*++
  497. Routine Description:
  498. This routine computes whether or not this file record segment's
  499. FILE_NAME_INDEX_PRESENT flag is set.
  500. Arguments:
  501. None.
  502. Return Value:
  503. FALSE - This file record segment's FILE_NAME_INDEX_PRESENT is NOT set.
  504. TRUE - This file record segment's FILE_NAME_INDEX_PRESENT is set.
  505. --*/
  506. {
  507. DebugAssert( _FrsData );
  508. return (_FrsData->Flags & FILE_FILE_NAME_INDEX_PRESENT) ? TRUE : FALSE;
  509. }
  510. INLINE
  511. VOID
  512. NTFS_FRS_STRUCTURE::ClearIndexPresent(
  513. )
  514. /*++
  515. Routine Description:
  516. This routine clears the index present bit on this file record segment.
  517. Arguments:
  518. None.
  519. Return Value:
  520. None.
  521. --*/
  522. {
  523. DebugAssert( _FrsData );
  524. _FrsData->Flags &= ~FILE_FILE_NAME_INDEX_PRESENT;
  525. }
  526. INLINE
  527. VOID
  528. NTFS_FRS_STRUCTURE::SetIndexPresent(
  529. )
  530. /*++
  531. Routine Description:
  532. This routine sets the index present bit on this file record segment.
  533. Arguments:
  534. None.
  535. Return Value:
  536. None.
  537. --*/
  538. {
  539. DebugAssert( _FrsData );
  540. _FrsData->Flags |= FILE_FILE_NAME_INDEX_PRESENT;
  541. }
  542. INLINE
  543. ULONG
  544. NTFS_FRS_STRUCTURE::QuerySize(
  545. ) CONST
  546. /*++
  547. Routine Description:
  548. This routine computes the number of bytes in this file
  549. record segment.
  550. Arguments:
  551. None.
  552. Return Value:
  553. The number of bytes in this file record segment.
  554. --*/
  555. {
  556. return _size;
  557. }
  558. INLINE
  559. VCN
  560. NTFS_FRS_STRUCTURE::QueryFileNumber(
  561. ) CONST
  562. /*++
  563. Routine Description:
  564. This method returns the File Number of the File Record Segment.
  565. Arguments:
  566. None.
  567. Return Value:
  568. the File Number (i.e. ordinal number within the MFT) of this
  569. File Record Segment.
  570. --*/
  571. {
  572. return _file_number;
  573. }
  574. INLINE
  575. ULONG
  576. NTFS_FRS_STRUCTURE::QueryClusterFactor(
  577. ) CONST
  578. /*++
  579. Routine Description:
  580. This method returns the cluster factor.
  581. Arguments:
  582. None.
  583. Return Value:
  584. The cluster factor with which this File Record Segment was initialized.
  585. --*/
  586. {
  587. return _cluster_factor;
  588. }
  589. INLINE
  590. PLOG_IO_DP_DRIVE
  591. NTFS_FRS_STRUCTURE::GetDrive(
  592. )
  593. /*++
  594. Routine Description:
  595. This method returns the drive on which the File Record Segment
  596. resides. This functionality enables clients to initialize
  597. other File Record Segments on the same drive.
  598. Arguments:
  599. None.
  600. Return Value:
  601. The drive on which the File Record Segment resides.
  602. --*/
  603. {
  604. return _drive;
  605. }
  606. INLINE
  607. USHORT
  608. NTFS_FRS_STRUCTURE::QueryReferenceCount(
  609. ) CONST
  610. /*++
  611. Routine Description:
  612. This routine returns the value of the reference count field
  613. in this frs.
  614. Arguments:
  615. None.
  616. Return Value:
  617. The value of the reference count field in this frs.
  618. --*/
  619. {
  620. return _FrsData->ReferenceCount;
  621. }
  622. INLINE
  623. VOID
  624. NTFS_FRS_STRUCTURE::SetReferenceCount(
  625. IN USHORT ReferenceCount
  626. )
  627. /*++
  628. Routine Description:
  629. This routine sets the value of the reference count field
  630. in this frs.
  631. Arguments:
  632. ReferenceCount - Supplies the new reference count.
  633. Return Value:
  634. None.
  635. --*/
  636. {
  637. _FrsData->ReferenceCount = ReferenceCount;
  638. }
  639. INLINE
  640. BIG_INT
  641. NTFS_FRS_STRUCTURE::QueryVolumeSectors(
  642. ) CONST
  643. /*++
  644. Routine Description:
  645. This routine returns the number of sectors on the volume as recorded in
  646. the boot sector.
  647. Arguments:
  648. None.
  649. Return Value:
  650. The number of volume sectors.
  651. --*/
  652. {
  653. return _volume_sectors;
  654. }
  655. INLINE
  656. PNTFS_UPCASE_TABLE
  657. NTFS_FRS_STRUCTURE::GetUpcaseTable(
  658. )
  659. /*++
  660. Routine Description:
  661. This method fetches the upcase table for the volume on which
  662. this FRS resides.
  663. Arguments:
  664. None.
  665. Return Value:
  666. The volume upcase table.
  667. --*/
  668. {
  669. return _upcase_table;
  670. }
  671. INLINE
  672. VOID
  673. NTFS_FRS_STRUCTURE::SetUpcaseTable(
  674. IN PNTFS_UPCASE_TABLE UpcaseTable
  675. )
  676. /*++
  677. Routine Description:
  678. This method sets the upcase table for the volume on which
  679. this FRS resides.
  680. Arguments:
  681. UpcaseTable -- Supplies the volume upcase table.
  682. Return Value:
  683. None.
  684. --*/
  685. {
  686. _upcase_table = UpcaseTable;
  687. }
  688. INLINE
  689. LSN
  690. NTFS_FRS_STRUCTURE::QueryLsn(
  691. ) CONST
  692. /*++
  693. Routine Description:
  694. This routine returns the logical sequence number for this file
  695. record segment.
  696. Arguments:
  697. None.
  698. Return Value:
  699. The logical sequence number for this file record segment.
  700. --*/
  701. {
  702. DebugAssert( _FrsData );
  703. return _FrsData->Lsn;
  704. }
  705. #endif // _NTFS_FRS_STRUCTURE_DEFN_