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.

1695 lines
29 KiB

  1. /*++
  2. Copyright (c) 1990-2001 Microsoft Corporation
  3. Module Name:
  4. drive.hxx
  5. Abstract:
  6. The drive class hierarchy models the concept of a drive in various
  7. stages. It looks like this:
  8. DRIVE
  9. DP_DRIVE
  10. IO_DP_DRIVE
  11. LOG_IO_DP_DRIVE
  12. PHYS_IO_DP_DRIVE
  13. DRIVE
  14. -----
  15. DRIVE implements a container for the drive path which is recognizable
  16. by the file system. 'Initialize' takes the path as an argument so
  17. that it can be later queried with 'GetNtDriveName'.
  18. DP_DRIVE
  19. --------
  20. DP_DRIVE (Drive Parameters) implements queries for the geometry of the
  21. drive. 'Initiliaze' queries the information from the drive. What
  22. is returned is the default drive geometry for the drive. The user
  23. may ask by means of 'IsSupported' if the physical device will support
  24. another MEDIA_TYPE.
  25. A protected member function called 'SetMediaType' allows the a derived
  26. class to set the MEDIA_TYPE to another media type which is supported
  27. by the device. This method is protected because only a low-level
  28. format will actually change the media type.
  29. IO_DP_DRIVE
  30. -----------
  31. IO_DP_DRIVE implements the reading and writing of sectors as well
  32. as 'Lock', 'Unlock', and 'Dismount'. The 'FormatVerifyFloppy' method
  33. does a low-level format. A version of this method allows the user
  34. to specify a new MEDIA_TYPE for the media.
  35. LOG_IO_DP_DRIVE and PHYS_IO_DP_DRIVE
  36. ------------------------------------
  37. LOG_IO_DP_DRIVE models logical drive. PHYS_IO_DP_DRIVE models a
  38. physical drive. Currently both implementations just initialize
  39. an IO_DP_DRIVE. The difference is in the drive path specified.
  40. Some drive paths are to logical drives and others are to physical
  41. drives.
  42. Author:
  43. Mark Shavlik (marks) Jun-90
  44. Norbert P. Kusters (norbertk) 22-Feb-91
  45. --*/
  46. #if ! defined( DRIVE_DEFN )
  47. #define DRIVE_DEFN
  48. #include "wstring.hxx"
  49. #include "bigint.hxx"
  50. #if defined ( _AUTOCHECK_ )
  51. #define IFSUTIL_EXPORT
  52. #elif defined ( _IFSUTIL_MEMBER_ )
  53. #define IFSUTIL_EXPORT __declspec(dllexport)
  54. #else
  55. #define IFSUTIL_EXPORT __declspec(dllimport)
  56. #endif
  57. #if !defined(_AUTOCHECK_)
  58. extern "C" {
  59. #include <ntddscsi.h>
  60. #ifndef _NTSRB_
  61. #define _NTSRB_
  62. #endif
  63. #include <scsi.h>
  64. };
  65. #endif
  66. //#define IO_PERF_COUNTERS 1
  67. //
  68. // Forward references
  69. //
  70. DECLARE_CLASS( DRIVE );
  71. DECLARE_CLASS( DP_DRIVE );
  72. DECLARE_CLASS( IO_DP_DRIVE );
  73. DECLARE_CLASS( LOG_IO_DP_DRIVE );
  74. DECLARE_CLASS( PHYS_IO_DP_DRIVE );
  75. DECLARE_CLASS( NUMBER_SET );
  76. DECLARE_CLASS( MESSAGE );
  77. DECLARE_CLASS( DRIVE_CACHE );
  78. #include "ifsentry.hxx"
  79. #if !defined _PARTITION_SYSTEM_ID_DEFINED_
  80. #define _PARTITION_SYSTEM_ID_DEFINED_
  81. #define SYSID_NONE 0x0
  82. #define SYSID_FAT12BIT 0x1
  83. #define SYSID_FAT16BIT 0x4
  84. #define SYSID_FAT32MEG 0x6
  85. #define SYSID_IFS 0x7
  86. #define SYSID_OS2BOOTMGR 0xA
  87. #define SYSID_FAT32BIT 0xB
  88. #define SYSID_EXTENDED 0x5
  89. typedef UCHAR PARTITION_SYSTEM_ID, *PPARTITON_SYSTEM_ID;
  90. #endif
  91. DEFINE_TYPE( ULONG, SECTORCOUNT ); // count of sectors
  92. DEFINE_TYPE( ULONG, LBN ); // Logical buffer number
  93. DEFINE_POINTER_AND_REFERENCE_TYPES( MEDIA_TYPE );
  94. DEFINE_POINTER_AND_REFERENCE_TYPES( DISK_GEOMETRY );
  95. struct _DRTYPE {
  96. MEDIA_TYPE MediaType;
  97. ULONG SectorSize;
  98. BIG_INT Sectors; // w/o hidden sectors.
  99. BIG_INT HiddenSectors;
  100. SECTORCOUNT SectorsPerTrack;
  101. ULONG Heads;
  102. #if defined(FE_SB) && defined(_X86_)
  103. // NEC Oct.24.1994
  104. ULONG PhysicalSectorSize; // used only PC-98
  105. BIG_INT PhysicalHiddenSectors; // used only PC-98
  106. #endif
  107. };
  108. #if !defined(_AUTOCHECK_)
  109. typedef struct {
  110. MODE_PARAMETER_HEADER10 header;
  111. UCHAR vendor_specific_0[3];
  112. UCHAR vendor_specific_2:7;
  113. UCHAR srfp: 1;
  114. UCHAR ms_class;
  115. UCHAR ms_type;
  116. UCHAR bootblock_2[23];
  117. UCHAR assembly_mode_code[3];
  118. UCHAR bootblock_1c[12];
  119. UCHAR controller_function[2];
  120. UCHAR bootblock_2a[12];
  121. UCHAR format_type;
  122. UCHAR bootblock_37[41];
  123. } SONY_MS_MODE_SENSE_DATA, *PSONY_MS_MODE_SENSE_DATA;
  124. typedef struct {
  125. UCHAR data_0[36];
  126. UCHAR device_capability[20];
  127. } SONY_MS_INQUIRY_DATA, *PSONY_MS_INQUIRY_DATA;
  128. #define SENSE_DATA_SKSV_BIT 0x80 // bit at SENSE_DATA.SenseKeySpecific[0]
  129. #endif
  130. // Hosted volumes always have certain values fixed. Define
  131. // those values here:
  132. //
  133. CONST MEDIA_TYPE HostedDriveMediaType = FixedMedia;
  134. CONST ULONG HostedDriveSectorSize = 512;
  135. CONST ULONG64 HostedDriveHiddenSectors = 0;
  136. CONST SECTORCOUNT HostedDriveSectorsPerTrack = 0x11;
  137. CONST SECTORCOUNT HostedDriveHeads = 6;
  138. DEFINE_TYPE( struct _DRTYPE, DRTYPE );
  139. class DRIVE : public OBJECT {
  140. public:
  141. DECLARE_CONSTRUCTOR(DRIVE);
  142. VIRTUAL
  143. ~DRIVE(
  144. );
  145. NONVIRTUAL
  146. BOOLEAN
  147. Initialize(
  148. IN PCWSTRING NtDriveName,
  149. IN OUT PMESSAGE Message DEFAULT NULL
  150. );
  151. NONVIRTUAL
  152. PCWSTRING
  153. GetNtDriveName(
  154. ) CONST;
  155. private:
  156. NONVIRTUAL
  157. VOID
  158. Construct(
  159. );
  160. NONVIRTUAL
  161. VOID
  162. Destroy(
  163. );
  164. DSTRING _name;
  165. };
  166. INLINE
  167. PCWSTRING
  168. DRIVE::GetNtDriveName(
  169. ) CONST
  170. /*++
  171. Routine Description:
  172. This routine returns a pointer string containing the NT drive name.
  173. Arguments:
  174. None.
  175. Return Value:
  176. A pointer to a string containing the NT drive name.
  177. --*/
  178. {
  179. return &_name;
  180. }
  181. class DP_DRIVE : public DRIVE {
  182. public:
  183. IFSUTIL_EXPORT
  184. DECLARE_CONSTRUCTOR(DP_DRIVE);
  185. VIRTUAL
  186. IFSUTIL_EXPORT
  187. ~DP_DRIVE(
  188. );
  189. enum { NONE, ANY, FAT, HPFS, OTHER };
  190. NONVIRTUAL
  191. IFSUTIL_EXPORT
  192. BOOLEAN
  193. Initialize(
  194. IN PCWSTRING NtDriveName,
  195. IN OUT PMESSAGE Message DEFAULT NULL,
  196. IN BOOLEAN IsTransient DEFAULT FALSE,
  197. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  198. IN USHORT FormatType DEFAULT NONE
  199. );
  200. NONVIRTUAL
  201. IFSUTIL_EXPORT
  202. BOOLEAN
  203. Initialize(
  204. IN PCWSTRING NtDriveName,
  205. IN PCWSTRING HostFileName,
  206. IN OUT PMESSAGE Message DEFAULT NULL,
  207. IN BOOLEAN IsTransient DEFAULT FALSE,
  208. IN BOOLEAN ExclusiveWrite DEFAULT FALSE
  209. );
  210. NONVIRTUAL
  211. MEDIA_TYPE
  212. QueryMediaType(
  213. ) CONST;
  214. NONVIRTUAL
  215. IFSUTIL_EXPORT
  216. UCHAR
  217. QueryMediaByte(
  218. ) CONST;
  219. NONVIRTUAL
  220. IFSUTIL_EXPORT
  221. HANDLE
  222. QueryDriveHandle(
  223. ) CONST;
  224. NONVIRTUAL
  225. IFSUTIL_EXPORT
  226. VOID
  227. CloseDriveHandle(
  228. );
  229. VIRTUAL
  230. IFSUTIL_EXPORT
  231. ULONG
  232. QuerySectorSize(
  233. ) CONST;
  234. VIRTUAL
  235. IFSUTIL_EXPORT
  236. BIG_INT
  237. QuerySectors(
  238. ) CONST;
  239. NONVIRTUAL
  240. BIG_INT
  241. QueryHiddenSectors(
  242. ) CONST;
  243. NONVIRTUAL
  244. SECTORCOUNT
  245. QuerySectorsPerTrack(
  246. ) CONST;
  247. #if defined(FE_SB) && defined(_X86_)
  248. // NEC98 supports ATACard. We must judge whether it is ATAcard.
  249. NONVIRTUAL
  250. IFSUTIL_EXPORT
  251. BOOLEAN
  252. IsATformat(
  253. ) CONST;
  254. // NEC98 uses the phsical sectorsize of target disk
  255. NONVIRTUAL
  256. IFSUTIL_EXPORT
  257. ULONG
  258. QueryPhysicalSectorSize(
  259. ) CONST;
  260. // NEC98 uses physical hidden sectors of target disk to support special FAT.
  261. NONVIRTUAL
  262. BIG_INT
  263. QueryPhysicalHiddenSectors(
  264. ) CONST;
  265. #endif
  266. NONVIRTUAL
  267. ULONG
  268. QueryHeads(
  269. ) CONST;
  270. NONVIRTUAL
  271. BIG_INT
  272. QueryTracks(
  273. ) CONST;
  274. NONVIRTUAL
  275. BIG_INT
  276. QueryCylinders(
  277. ) CONST;
  278. NONVIRTUAL
  279. BOOLEAN
  280. IsWriteable(
  281. ) CONST;
  282. NONVIRTUAL
  283. BOOLEAN
  284. IsRemovable(
  285. ) CONST;
  286. NONVIRTUAL
  287. BOOLEAN
  288. IsFloppy(
  289. ) CONST;
  290. NONVIRTUAL
  291. BOOLEAN
  292. IsSuperFloppy(
  293. ) CONST;
  294. NONVIRTUAL
  295. BOOLEAN
  296. IsPrimaryPartition(
  297. ) CONST;
  298. NONVIRTUAL
  299. BOOLEAN
  300. IsSystemPartition(
  301. ) CONST;
  302. #if defined(_AUTOCHECK_)
  303. NONVIRTUAL
  304. DRIVE_TYPE
  305. QueryDriveType(
  306. ) CONST;
  307. #endif
  308. NONVIRTUAL
  309. BOOLEAN
  310. IsFixed(
  311. ) CONST;
  312. NONVIRTUAL
  313. BOOLEAN
  314. IsSupported(
  315. IN MEDIA_TYPE MediaType
  316. ) CONST;
  317. NONVIRTUAL
  318. PCDRTYPE
  319. GetSupportedList(
  320. OUT PINT NumSupported
  321. ) CONST;
  322. NONVIRTUAL
  323. IFSUTIL_EXPORT
  324. MEDIA_TYPE
  325. QueryRecommendedMediaType(
  326. ) CONST;
  327. NONVIRTUAL
  328. ULONG
  329. QueryAlignmentMask(
  330. ) CONST;
  331. NONVIRTUAL
  332. NTSTATUS
  333. QueryLastNtStatus(
  334. ) CONST;
  335. NONVIRTUAL
  336. HANDLE
  337. GetVolumeFileHandle(
  338. ) CONST;
  339. #if !defined(_AUTOCHECK_)
  340. NONVIRTUAL
  341. IFSUTIL_EXPORT
  342. BOOLEAN
  343. SendSonyMSFormatCmd(
  344. );
  345. NONVIRTUAL
  346. IFSUTIL_EXPORT
  347. BOOLEAN
  348. SendSonyMSModeSenseCmd(
  349. OUT PSONY_MS_MODE_SENSE_DATA ModeSenseData
  350. );
  351. NONVIRTUAL
  352. IFSUTIL_EXPORT
  353. BOOLEAN
  354. SendSonyMSRequestSenseCmd(
  355. OUT PSENSE_DATA SenseInfo
  356. );
  357. NONVIRTUAL
  358. IFSUTIL_EXPORT
  359. BOOLEAN
  360. SendSonyMSInquiryCmd(
  361. OUT PSONY_MS_INQUIRY_DATA InquiryData
  362. );
  363. NONVIRTUAL
  364. IFSUTIL_EXPORT
  365. BOOLEAN
  366. SendSonyMSTestUnitReadyCmd(
  367. OUT PSENSE_DATA SenseInfo
  368. );
  369. #endif
  370. BOOLEAN
  371. CheckHotPlugInfo(
  372. );
  373. BOOLEAN
  374. CheckSonyMS(
  375. );
  376. BOOLEAN
  377. IsSonyMS(
  378. );
  379. BOOLEAN
  380. IsSonyMSProgressIndicatorCapable(
  381. );
  382. BOOLEAN
  383. IsSonyMSFmtCmdCapable(
  384. );
  385. BOOLEAN
  386. IsNtfsNotSupported(
  387. );
  388. STATIC
  389. IFSUTIL_EXPORT
  390. NTSTATUS
  391. QueryNtfsSupportInfo(
  392. IN HANDLE DriveHandle,
  393. OUT PBOOLEAN NoNtfsSupport
  394. );
  395. #if defined(FE_SB) && defined(_X86_)
  396. USHORT
  397. QueryFormatType(
  398. );
  399. // NEC98 uses this word in QueryFormatMediaType whether it is AT.
  400. private:
  401. ULONG _next_format_type;
  402. #define FORMAT_MEDIA_98 0
  403. #define FORMAT_MEDIA_AT 1
  404. #define FORMAT_MEDIA_OTHER 2
  405. #endif
  406. protected:
  407. NONVIRTUAL
  408. BOOLEAN
  409. SetMediaType(
  410. IN MEDIA_TYPE MediaType DEFAULT Unknown
  411. );
  412. // On a normal drive, _handle is a handle to the drive
  413. // and _alternate_drive is zero. On a hosted drive,
  414. // however, _handle is a handle to the file which
  415. // contains the volume and _alternate_handle is a handle
  416. // to the volume itself.
  417. //
  418. // When the drive object opens a hosted volume, it must
  419. // first make the host file non-readonly. It caches the
  420. // old attributes of the file so that it can reset them.
  421. //
  422. HANDLE _handle;
  423. HANDLE _alternate_handle;
  424. BOOLEAN _hosted_drive;
  425. ULONG _old_attributes;
  426. NTSTATUS _last_status;
  427. #if defined(RUN_ON_W2K)
  428. PARTITION_INFORMATION _partition_info;
  429. #else
  430. PARTITION_INFORMATION_EX _partition_info;
  431. #endif
  432. private:
  433. NONVIRTUAL
  434. VOID
  435. Construct(
  436. );
  437. NONVIRTUAL
  438. VOID
  439. Destroy(
  440. );
  441. STATIC
  442. NTSTATUS
  443. OpenDrive(
  444. IN PCWSTRING NtDriveName,
  445. IN ACCESS_MASK DesiredAccess,
  446. IN BOOLEAN ExclusiveWrite,
  447. OUT PHANDLE Handle,
  448. OUT PULONG Alignment,
  449. IN OUT PMESSAGE Message
  450. );
  451. STATIC
  452. VOID
  453. DiskGeometryToDriveType(
  454. IN PCDISK_GEOMETRY DiskGeometry,
  455. OUT PDRTYPE DriveType
  456. );
  457. STATIC
  458. VOID
  459. DiskGeometryToDriveType(
  460. IN PCDISK_GEOMETRY DiskGeometry,
  461. IN BIG_INT NumSectors,
  462. IN BIG_INT NumHiddenSectors,
  463. OUT PDRTYPE DriveType
  464. );
  465. BOOLEAN
  466. CheckForPrimaryPartition(
  467. );
  468. BOOLEAN
  469. CheckForSystemPartition(
  470. );
  471. BOOLEAN
  472. QueryBusType(
  473. OUT PSTORAGE_BUS_TYPE BusType
  474. );
  475. #if defined(FE_SB) && defined(_X86_)
  476. VOID
  477. SetFormatType(
  478. IN USHORT FormatType
  479. );
  480. #endif
  481. DRTYPE _actual;
  482. PDRTYPE _supported_list;
  483. INT _num_supported;
  484. ULONG _alignment_mask;
  485. BOOLEAN _super_floppy;
  486. BOOLEAN _is_writeable;
  487. BOOLEAN _is_primary_partition;
  488. BOOLEAN _is_system_partition;
  489. #if defined(_AUTOCHECK_)
  490. DRIVE_TYPE _drive_type;
  491. #endif
  492. #if defined(FE_SB) && defined(_X86_)
  493. USHORT _format_type; // this is for NEC98 stuff to force a FAT format
  494. #endif
  495. BOOLEAN _sony_ms;
  496. BOOLEAN _sony_ms_fmt_cmd;
  497. BOOLEAN _sony_ms_progress_indicator;
  498. BOOLEAN _ntfs_not_supported;
  499. };
  500. INLINE
  501. HANDLE
  502. DP_DRIVE::QueryDriveHandle(
  503. ) CONST
  504. /*++
  505. Routine Description:
  506. This routine returns the drive handle.
  507. Arguments:
  508. None.
  509. Return Value:
  510. Drive handle.
  511. --*/
  512. {
  513. return _handle;
  514. }
  515. INLINE
  516. MEDIA_TYPE
  517. DP_DRIVE::QueryMediaType(
  518. ) CONST
  519. /*++
  520. Routine Description:
  521. This routine computes the media type.
  522. Arguments:
  523. None.
  524. Return Value:
  525. The media type.
  526. --*/
  527. {
  528. return _actual.MediaType;
  529. }
  530. INLINE
  531. BIG_INT
  532. DP_DRIVE::QueryHiddenSectors(
  533. ) CONST
  534. /*++
  535. Routine Description:
  536. This routine computes the number of hidden sectors.
  537. Arguments:
  538. None.
  539. Return Value:
  540. The number of hidden sectors.
  541. --*/
  542. {
  543. return _actual.HiddenSectors;
  544. }
  545. #if defined(FE_SB) && defined(_X86_)
  546. INLINE
  547. BIG_INT
  548. DP_DRIVE::QueryPhysicalHiddenSectors(
  549. ) CONST
  550. /*++
  551. Routine Description:
  552. This routine computes the number of hidden sectors for 98's FAT.
  553. Arguments:
  554. None.
  555. Return Value:
  556. The number of hidden sectors.
  557. --*/
  558. {
  559. return _actual.PhysicalHiddenSectors;
  560. }
  561. #endif
  562. INLINE
  563. SECTORCOUNT
  564. DP_DRIVE::QuerySectorsPerTrack(
  565. ) CONST
  566. /*++
  567. Routine Description:
  568. This routine computes the number of sectors per track.
  569. Arguments:
  570. None.
  571. Return Value:
  572. The number of sectors per track.
  573. --*/
  574. {
  575. return _actual.SectorsPerTrack;
  576. }
  577. INLINE
  578. ULONG
  579. DP_DRIVE::QueryHeads(
  580. ) CONST
  581. /*++
  582. Routine Description:
  583. This routine computes the number of heads.
  584. Arguments:
  585. None.
  586. Return Value:
  587. The number of heads.
  588. --*/
  589. {
  590. return _actual.Heads;
  591. }
  592. INLINE
  593. BIG_INT
  594. DP_DRIVE::QueryTracks(
  595. ) CONST
  596. /*++
  597. Routine Description:
  598. This routine computes the number of tracks on the disk.
  599. Arguments:
  600. None.
  601. Return Value:
  602. The number of tracks on the disk.
  603. --*/
  604. {
  605. return (_actual.Sectors + _actual.HiddenSectors)/_actual.SectorsPerTrack;
  606. }
  607. INLINE
  608. BIG_INT
  609. DP_DRIVE::QueryCylinders(
  610. ) CONST
  611. /*++
  612. Routine Description:
  613. This routine computes the number of cylinders on the disk.
  614. Arguments:
  615. None.
  616. Return Value:
  617. The number of cylinders on the disk.
  618. --*/
  619. {
  620. return QueryTracks()/_actual.Heads;
  621. }
  622. INLINE
  623. BOOLEAN
  624. DP_DRIVE::IsRemovable(
  625. ) CONST
  626. /*++
  627. Routine Description:
  628. This routine computes whether or not the disk is removable.
  629. Arguments:
  630. None.
  631. Return Value:
  632. FALSE - The disk is not removable.
  633. TRUE - The disk is removable.
  634. --*/
  635. {
  636. return _actual.MediaType != FixedMedia;
  637. }
  638. INLINE
  639. BOOLEAN
  640. DP_DRIVE::IsWriteable(
  641. ) CONST
  642. /*++
  643. Routine Description:
  644. This routine checks to see if the drive is writeable.
  645. Arguments:
  646. N/A
  647. Return Value:
  648. TRUE - if the disk is writeable
  649. FALSE - if the disk is write protected
  650. --*/
  651. {
  652. return _is_writeable;
  653. }
  654. INLINE
  655. BOOLEAN
  656. DP_DRIVE::IsPrimaryPartition(
  657. ) CONST
  658. /*++
  659. Routine Description:
  660. This routine checks to see if the volume is on a primary partition.
  661. Arguments:
  662. N/A
  663. Return Value:
  664. TRUE - if the volume is on a primary partition.
  665. FALSE - if the volume is not on a primary partition.
  666. --*/
  667. {
  668. return _is_primary_partition;
  669. }
  670. INLINE
  671. BOOLEAN
  672. DP_DRIVE::IsSystemPartition(
  673. ) CONST
  674. /*++
  675. Routine Description:
  676. This routine checks to see if the volume is a system partition.
  677. Arguments:
  678. N/A
  679. Return Value:
  680. TRUE - if the volume is a system partition.
  681. FALSE - if the volume is not a system partition.
  682. --*/
  683. {
  684. return _is_system_partition;
  685. }
  686. #if defined(_AUTOCHECK_)
  687. INLINE
  688. DRIVE_TYPE
  689. DP_DRIVE::QueryDriveType(
  690. ) CONST
  691. /*++
  692. Routine Description:
  693. This routine returns the drive type.
  694. Arguments:
  695. N/A
  696. Return Value:
  697. UnknownDrive,
  698. RemovableDrive,
  699. FixedDrive,
  700. RemoteDrive,
  701. CdRomDrive,
  702. RamDiskDrive
  703. --*/
  704. {
  705. return _drive_type;
  706. }
  707. #endif
  708. INLINE
  709. BOOLEAN
  710. DP_DRIVE::IsFloppy(
  711. ) CONST
  712. /*++
  713. Routine Description:
  714. This routine computes whether or not the disk is a floppy disk.
  715. Arguments:
  716. None.
  717. Return Value:
  718. FALSE - The disk is not a floppy disk.
  719. TRUE - The disk is a floppy disk.
  720. --*/
  721. {
  722. return IsRemovable() && _actual.MediaType != RemovableMedia;
  723. }
  724. INLINE
  725. BOOLEAN
  726. DP_DRIVE::IsSuperFloppy(
  727. ) CONST
  728. /*++
  729. Routine Description:
  730. This routine tells whether the media is non-floppy unpartitioned
  731. removable media.
  732. Arguments:
  733. None.
  734. Return Value:
  735. FALSE - The disk is not a floppy disk.
  736. TRUE - The disk is a floppy disk.
  737. --*/
  738. {
  739. return _super_floppy;
  740. }
  741. INLINE
  742. BOOLEAN
  743. DP_DRIVE::IsFixed(
  744. ) CONST
  745. /*++
  746. Routine Description:
  747. This routine computes whether or not the disk is a fixed disk.
  748. Arguments:
  749. None.
  750. Return Value:
  751. FALSE - The disk is not a fixed disk.
  752. TRUE - The disk is a fixed disk.
  753. --*/
  754. {
  755. return _actual.MediaType == FixedMedia;
  756. }
  757. INLINE
  758. PCDRTYPE
  759. DP_DRIVE::GetSupportedList(
  760. OUT PINT NumSupported
  761. ) CONST
  762. /*++
  763. Routine Description:
  764. This routine returns a list of the supported media types by the device.
  765. Arguments:
  766. NumSupported - Returns the number of elements in the list.
  767. Return Value:
  768. A list of the supported media types by the device.
  769. --*/
  770. {
  771. *NumSupported = _num_supported;
  772. return _supported_list;
  773. }
  774. INLINE
  775. ULONG
  776. DP_DRIVE::QueryAlignmentMask(
  777. ) CONST
  778. /*++
  779. Routine Description:
  780. This routine returns the memory alignment requirement for the drive.
  781. Arguments:
  782. None.
  783. Return Value:
  784. The memory alignment requirement for the drive in the form of a mask.
  785. --*/
  786. {
  787. return _alignment_mask;
  788. }
  789. INLINE
  790. NTSTATUS
  791. DP_DRIVE::QueryLastNtStatus(
  792. ) CONST
  793. /*++
  794. Routine Description:
  795. This routine returns the last NT status value.
  796. Arguments:
  797. None.
  798. Return Value:
  799. The last NT status value.
  800. --*/
  801. {
  802. return _last_status;
  803. }
  804. #if defined(FE_SB) && defined(_X86_)
  805. INLINE
  806. VOID
  807. DP_DRIVE::SetFormatType(
  808. IN USHORT FileSystem
  809. )
  810. /*++
  811. Routine Description:
  812. This routine sets the format type.
  813. Arguments:
  814. FileSystem - Supplies the format type: FAT HPFS NONE ANY OTHER
  815. Return Value:
  816. None
  817. --*/
  818. {
  819. if (FileSystem != ANY || _format_type == NONE)
  820. _format_type = FileSystem;
  821. }
  822. INLINE
  823. USHORT
  824. DP_DRIVE::QueryFormatType(
  825. )
  826. /*++
  827. Routine Description:
  828. This routine returns the format type.
  829. Arguments:
  830. None.
  831. Return Value:
  832. Format type: FAT HPFS NONE ANY OTHER
  833. --*/
  834. {
  835. return _format_type;
  836. }
  837. #endif
  838. INLINE
  839. BOOLEAN
  840. DP_DRIVE::IsSonyMSProgressIndicatorCapable(
  841. )
  842. /*++
  843. Routine Description:
  844. This routine returns the progress bar capability of the Sony MS reader.
  845. Arguments:
  846. None.
  847. Return Value:
  848. TRUE if device is capable of reporting format progress.
  849. --*/
  850. {
  851. return _sony_ms_progress_indicator;
  852. }
  853. INLINE
  854. BOOLEAN
  855. DP_DRIVE::IsSonyMS(
  856. )
  857. /*++
  858. Routine Description:
  859. This routine tells if the device is a Sony Memory Stick.
  860. Arguments:
  861. None.
  862. Return Value:
  863. TRUE if device is a Sony Memory Stick.
  864. --*/
  865. {
  866. return _sony_ms;
  867. }
  868. INLINE
  869. BOOLEAN
  870. DP_DRIVE::IsSonyMSFmtCmdCapable(
  871. )
  872. /*++
  873. Routine Description:
  874. This routine returns the format capability of the Sony MS reader.
  875. Arguments:
  876. None.
  877. Return Value:
  878. TRUE if device is capable of handling format command.
  879. --*/
  880. {
  881. return _sony_ms_fmt_cmd;
  882. }
  883. INLINE
  884. BOOLEAN
  885. DP_DRIVE::IsNtfsNotSupported(
  886. )
  887. /*++
  888. Routine Description:
  889. This routine returns the progress bar capability of the Sony MS reader.
  890. Arguments:
  891. None.
  892. Return Value:
  893. TRUE if device is capable of reporting format progress.
  894. --*/
  895. {
  896. return _ntfs_not_supported;
  897. }
  898. class IO_DP_DRIVE : public DP_DRIVE {
  899. FRIEND class DRIVE_CACHE;
  900. public:
  901. VIRTUAL
  902. ~IO_DP_DRIVE(
  903. );
  904. NONVIRTUAL
  905. IFSUTIL_EXPORT
  906. BOOLEAN
  907. Read(
  908. IN BIG_INT StartingSector,
  909. IN SECTORCOUNT NumberOfSectors,
  910. OUT PVOID Buffer
  911. );
  912. NONVIRTUAL
  913. IFSUTIL_EXPORT
  914. BOOLEAN
  915. Write(
  916. IN BIG_INT StartingSector,
  917. IN SECTORCOUNT NumberOfSectors,
  918. IN PVOID Buffer
  919. );
  920. NONVIRTUAL
  921. IFSUTIL_EXPORT
  922. BOOLEAN
  923. Verify(
  924. IN BIG_INT StartingSector,
  925. IN BIG_INT NumberOfSectors
  926. );
  927. NONVIRTUAL
  928. IFSUTIL_EXPORT
  929. BOOLEAN
  930. Verify(
  931. IN BIG_INT StartingSector,
  932. IN BIG_INT NumberOfSectors,
  933. IN OUT PNUMBER_SET BadSectors
  934. );
  935. NONVIRTUAL
  936. IFSUTIL_EXPORT
  937. PMESSAGE
  938. GetMessage(
  939. );
  940. NONVIRTUAL
  941. IFSUTIL_EXPORT
  942. BOOLEAN
  943. Lock(
  944. );
  945. NONVIRTUAL
  946. IFSUTIL_EXPORT
  947. BOOLEAN
  948. InvalidateVolume(
  949. );
  950. NONVIRTUAL
  951. BOOLEAN
  952. Unlock(
  953. );
  954. NONVIRTUAL
  955. BOOLEAN
  956. DismountAndUnlock(
  957. );
  958. NONVIRTUAL
  959. BOOLEAN
  960. ForceDirty(
  961. );
  962. NONVIRTUAL
  963. BOOLEAN
  964. FormatVerifyFloppy(
  965. IN MEDIA_TYPE MediaType DEFAULT Unknown,
  966. IN OUT PNUMBER_SET BadSectors DEFAULT NULL,
  967. IN OUT PMESSAGE Message DEFAULT NULL,
  968. IN BOOLEAN IsDmfFormat DEFAULT FALSE
  969. );
  970. NONVIRTUAL
  971. IFSUTIL_EXPORT
  972. VOID
  973. SetCache(
  974. IN OUT PDRIVE_CACHE Cache
  975. );
  976. NONVIRTUAL
  977. IFSUTIL_EXPORT
  978. BOOLEAN
  979. FlushCache(
  980. );
  981. // Note that the following three methods, provided to
  982. // support SimBad, are _not_ in ifsutil.dll.
  983. NONVIRTUAL
  984. BOOLEAN
  985. EnableBadSectorSimulation(
  986. IN BOOLEAN Enable
  987. );
  988. NONVIRTUAL
  989. BOOLEAN
  990. SimulateBadSectors(
  991. IN BOOLEAN Add,
  992. IN ULONG Count,
  993. IN PLBN SectorArray,
  994. IN NTSTATUS Status,
  995. IN ULONG AccessType
  996. );
  997. NONVIRTUAL
  998. BOOLEAN
  999. QuerySimulatedBadSectors(
  1000. OUT PULONG Count,
  1001. IN ULONG MaximumLbnsInBuffer,
  1002. OUT PLBN SectorArray,
  1003. OUT PULONG AccessTypeArray
  1004. );
  1005. #if defined(IO_PERF_COUNTERS)
  1006. NONVIRTUAL
  1007. IFSUTIL_EXPORT
  1008. VOID
  1009. QueryPerformanceCounters(
  1010. PLARGE_INTEGER Wtime,
  1011. PLARGE_INTEGER Rtime,
  1012. PLARGE_INTEGER Ctime,
  1013. PLARGE_INTEGER WSecCount,
  1014. PLARGE_INTEGER WCount,
  1015. PLARGE_INTEGER RRtime,
  1016. PLARGE_INTEGER RSecCount,
  1017. PLARGE_INTEGER RCount
  1018. );
  1019. #endif
  1020. protected:
  1021. DECLARE_CONSTRUCTOR(IO_DP_DRIVE);
  1022. NONVIRTUAL
  1023. BOOLEAN
  1024. Initialize(
  1025. IN PCWSTRING NtDriveName,
  1026. IN OUT PMESSAGE Message DEFAULT NULL,
  1027. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  1028. IN USHORT FormatType DEFAULT NONE
  1029. );
  1030. NONVIRTUAL
  1031. BOOLEAN
  1032. Initialize(
  1033. IN PCWSTRING NtDriveName,
  1034. IN PCWSTRING HostFileName,
  1035. IN OUT PMESSAGE Message DEFAULT NULL,
  1036. IN BOOLEAN ExclusiveWrite DEFAULT FALSE
  1037. );
  1038. private:
  1039. BOOLEAN _is_locked;
  1040. BOOLEAN _is_exclusive_write;
  1041. PDRIVE_CACHE _cache;
  1042. ULONG _ValidBlockLengthForVerify;
  1043. PMESSAGE _message;
  1044. NONVIRTUAL
  1045. VOID
  1046. Construct(
  1047. );
  1048. NONVIRTUAL
  1049. VOID
  1050. Destroy(
  1051. );
  1052. NONVIRTUAL
  1053. BOOLEAN
  1054. VerifyWithRead(
  1055. IN BIG_INT StartingSector,
  1056. IN BIG_INT NumberOfSectors
  1057. );
  1058. NONVIRTUAL
  1059. BOOLEAN
  1060. HardRead(
  1061. IN BIG_INT StartingSector,
  1062. IN SECTORCOUNT NumberOfSectors,
  1063. OUT PVOID Buffer
  1064. );
  1065. NONVIRTUAL
  1066. BOOLEAN
  1067. HardWrite(
  1068. IN BIG_INT StartingSector,
  1069. IN SECTORCOUNT NumberOfSectors,
  1070. IN PVOID Buffer
  1071. );
  1072. NONVIRTUAL
  1073. BOOLEAN
  1074. Dismount(
  1075. );
  1076. #if defined(IO_PERF_COUNTERS)
  1077. STATIC LARGE_INTEGER _wtotal, _rtotal, _ctotal, _rrtotal;
  1078. STATIC LARGE_INTEGER _wcount, _rcount;
  1079. STATIC LARGE_INTEGER _wsize, _rsize;
  1080. #endif
  1081. };
  1082. INLINE
  1083. PMESSAGE
  1084. IO_DP_DRIVE::GetMessage(
  1085. )
  1086. /*++
  1087. Routine Description:
  1088. Retrieve the message object.
  1089. Arguments:
  1090. N/A
  1091. Return Value:
  1092. The message object.
  1093. --*/
  1094. {
  1095. return _message;
  1096. }
  1097. class LOG_IO_DP_DRIVE : public IO_DP_DRIVE {
  1098. public:
  1099. IFSUTIL_EXPORT
  1100. DECLARE_CONSTRUCTOR(LOG_IO_DP_DRIVE);
  1101. VIRTUAL
  1102. IFSUTIL_EXPORT
  1103. ~LOG_IO_DP_DRIVE(
  1104. );
  1105. NONVIRTUAL
  1106. IFSUTIL_EXPORT
  1107. BOOLEAN
  1108. Initialize(
  1109. IN PCWSTRING NtDriveName,
  1110. IN OUT PMESSAGE Message DEFAULT NULL,
  1111. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  1112. IN USHORT FormatType DEFAULT NONE
  1113. );
  1114. NONVIRTUAL
  1115. IFSUTIL_EXPORT
  1116. BOOLEAN
  1117. SetSystemId(
  1118. IN PARTITION_SYSTEM_ID SystemId
  1119. );
  1120. #if defined (FE_SB) && defined (_X86_)
  1121. // NEC98 June.25.1995
  1122. // Add the type definition of function that other DLL is able to
  1123. // call IO_DP_DRIVE::Read and IO_DP_DRIVE::Write.
  1124. NONVIRTUAL
  1125. IFSUTIL_EXPORT
  1126. BOOLEAN
  1127. Read(
  1128. IN BIG_INT StartingSector,
  1129. IN SECTORCOUNT NumberOfSectors,
  1130. OUT PVOID Buffer
  1131. );
  1132. NONVIRTUAL
  1133. IFSUTIL_EXPORT
  1134. BOOLEAN
  1135. Write(
  1136. IN BIG_INT StartingSector,
  1137. IN SECTORCOUNT NumberOfSectors,
  1138. IN PVOID Buffer
  1139. );
  1140. #endif
  1141. NONVIRTUAL
  1142. IFSUTIL_EXPORT
  1143. BOOLEAN
  1144. Initialize(
  1145. IN PCWSTRING NtDriveName,
  1146. IN PCWSTRING HostFileName,
  1147. IN OUT PMESSAGE Message DEFAULT NULL,
  1148. IN BOOLEAN ExclusiveWrite DEFAULT FALSE
  1149. );
  1150. NONVIRTUAL
  1151. UCHAR
  1152. QueryPartitionType(
  1153. ) CONST;
  1154. private:
  1155. NONVIRTUAL
  1156. VOID
  1157. Construct(
  1158. );
  1159. };
  1160. INLINE
  1161. VOID
  1162. LOG_IO_DP_DRIVE::Construct(
  1163. )
  1164. /*++
  1165. Routine Description:
  1166. Constructor for LOG_IO_DP_DRIVE.
  1167. Arguments:
  1168. None.
  1169. Return Value:
  1170. None.
  1171. --*/
  1172. {
  1173. }
  1174. INLINE
  1175. UCHAR
  1176. LOG_IO_DP_DRIVE::QueryPartitionType(
  1177. ) CONST
  1178. /*++
  1179. Routine Description:
  1180. This routine returns the partition type.
  1181. Arguments:
  1182. None.
  1183. Return Value:
  1184. The last partition type value.
  1185. --*/
  1186. {
  1187. #if defined(RUN_ON_W2K)
  1188. return _partition_info.PartitionType;
  1189. #else
  1190. return _partition_info.Mbr.PartitionType;
  1191. #endif
  1192. }
  1193. class PHYS_IO_DP_DRIVE : public IO_DP_DRIVE {
  1194. public:
  1195. DECLARE_CONSTRUCTOR(PHYS_IO_DP_DRIVE);
  1196. VIRTUAL
  1197. ~PHYS_IO_DP_DRIVE(
  1198. );
  1199. NONVIRTUAL
  1200. BOOLEAN
  1201. Initialize(
  1202. IN PCWSTRING NtDriveName,
  1203. IN OUT PMESSAGE Message DEFAULT NULL,
  1204. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  1205. IN USHORT FormatType DEFAULT NONE
  1206. );
  1207. private:
  1208. NONVIRTUAL
  1209. VOID
  1210. Construct(
  1211. );
  1212. };
  1213. INLINE
  1214. VOID
  1215. PHYS_IO_DP_DRIVE::Construct(
  1216. )
  1217. /*++
  1218. Routine Description:
  1219. Constructor for PHYS_IO_DP_DRIVE.
  1220. Arguments:
  1221. None.
  1222. Return Value:
  1223. None.
  1224. --*/
  1225. {
  1226. }
  1227. INLINE
  1228. HANDLE
  1229. DP_DRIVE::GetVolumeFileHandle(
  1230. ) CONST
  1231. /*++
  1232. Routine Description:
  1233. This routine is a hack for NTFS->OFS convert... it returns the
  1234. handle open on the ntfs volume-file.
  1235. Arguments:
  1236. None.
  1237. Return Value:
  1238. The handle.
  1239. --*/
  1240. {
  1241. return _handle;
  1242. }
  1243. #endif // DRIVE_DEFN