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.

1705 lines
31 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. NONVIRTUAL
  303. IFSUTIL_EXPORT
  304. DRIVE_TYPE
  305. QueryDriveType(
  306. ) CONST;
  307. NONVIRTUAL
  308. BOOLEAN
  309. IsFixed(
  310. ) CONST;
  311. NONVIRTUAL
  312. BOOLEAN
  313. IsSupported(
  314. IN MEDIA_TYPE MediaType
  315. ) CONST;
  316. NONVIRTUAL
  317. PCDRTYPE
  318. GetSupportedList(
  319. OUT PINT NumSupported
  320. ) CONST;
  321. NONVIRTUAL
  322. IFSUTIL_EXPORT
  323. MEDIA_TYPE
  324. QueryRecommendedMediaType(
  325. ) CONST;
  326. NONVIRTUAL
  327. ULONG
  328. QueryAlignmentMask(
  329. ) CONST;
  330. NONVIRTUAL
  331. NTSTATUS
  332. QueryLastNtStatus(
  333. ) CONST;
  334. NONVIRTUAL
  335. HANDLE
  336. GetVolumeFileHandle(
  337. ) CONST;
  338. #if !defined(_AUTOCHECK_)
  339. NONVIRTUAL
  340. IFSUTIL_EXPORT
  341. BOOLEAN
  342. SendSonyMSFormatCmd(
  343. );
  344. NONVIRTUAL
  345. IFSUTIL_EXPORT
  346. BOOLEAN
  347. SendSonyMSModeSenseCmd(
  348. OUT PSONY_MS_MODE_SENSE_DATA ModeSenseData
  349. );
  350. NONVIRTUAL
  351. IFSUTIL_EXPORT
  352. BOOLEAN
  353. SendSonyMSRequestSenseCmd(
  354. OUT PSENSE_DATA SenseInfo
  355. );
  356. NONVIRTUAL
  357. IFSUTIL_EXPORT
  358. BOOLEAN
  359. SendSonyMSInquiryCmd(
  360. OUT PSONY_MS_INQUIRY_DATA InquiryData
  361. );
  362. NONVIRTUAL
  363. IFSUTIL_EXPORT
  364. BOOLEAN
  365. SendSonyMSTestUnitReadyCmd(
  366. OUT PSENSE_DATA SenseInfo
  367. );
  368. #endif
  369. BOOLEAN
  370. CheckHotPlugInfo(
  371. );
  372. BOOLEAN
  373. CheckSonyMS(
  374. );
  375. BOOLEAN
  376. IsSonyMS(
  377. );
  378. BOOLEAN
  379. IsSonyMSProgressIndicatorCapable(
  380. );
  381. BOOLEAN
  382. IsSonyMSFmtCmdCapable(
  383. );
  384. BOOLEAN
  385. IsNtfsNotSupported(
  386. );
  387. STATIC
  388. IFSUTIL_EXPORT
  389. NTSTATUS
  390. QueryNtfsSupportInfo(
  391. IN HANDLE DriveHandle,
  392. OUT PBOOLEAN NoNtfsSupport
  393. );
  394. STATIC
  395. IFSUTIL_EXPORT
  396. BOOLEAN
  397. QueryMrwSupport(
  398. IN HANDLE DriveHandle
  399. );
  400. #if defined(FE_SB) && defined(_X86_)
  401. USHORT
  402. QueryFormatType(
  403. );
  404. // NEC98 uses this word in QueryFormatMediaType whether it is AT.
  405. private:
  406. ULONG _next_format_type;
  407. #define FORMAT_MEDIA_98 0
  408. #define FORMAT_MEDIA_AT 1
  409. #define FORMAT_MEDIA_OTHER 2
  410. #endif
  411. protected:
  412. NONVIRTUAL
  413. BOOLEAN
  414. SetMediaType(
  415. IN MEDIA_TYPE MediaType DEFAULT Unknown
  416. );
  417. // On a normal drive, _handle is a handle to the drive
  418. // and _alternate_drive is zero. On a hosted drive,
  419. // however, _handle is a handle to the file which
  420. // contains the volume and _alternate_handle is a handle
  421. // to the volume itself.
  422. //
  423. // When the drive object opens a hosted volume, it must
  424. // first make the host file non-readonly. It caches the
  425. // old attributes of the file so that it can reset them.
  426. //
  427. HANDLE _handle;
  428. HANDLE _alternate_handle;
  429. BOOLEAN _hosted_drive;
  430. ULONG _old_attributes;
  431. NTSTATUS _last_status;
  432. #if defined(RUN_ON_W2K)
  433. PARTITION_INFORMATION _partition_info;
  434. #else
  435. PARTITION_INFORMATION_EX _partition_info;
  436. #endif
  437. private:
  438. NONVIRTUAL
  439. VOID
  440. Construct(
  441. );
  442. NONVIRTUAL
  443. VOID
  444. Destroy(
  445. );
  446. STATIC
  447. NTSTATUS
  448. OpenDrive(
  449. IN PCWSTRING NtDriveName,
  450. IN ACCESS_MASK DesiredAccess,
  451. IN BOOLEAN ExclusiveWrite,
  452. OUT PHANDLE Handle,
  453. OUT PULONG Alignment,
  454. IN OUT PMESSAGE Message
  455. );
  456. STATIC
  457. VOID
  458. DiskGeometryToDriveType(
  459. IN PCDISK_GEOMETRY DiskGeometry,
  460. OUT PDRTYPE DriveType
  461. );
  462. STATIC
  463. VOID
  464. DiskGeometryToDriveType(
  465. IN PCDISK_GEOMETRY DiskGeometry,
  466. IN BIG_INT NumSectors,
  467. IN BIG_INT NumHiddenSectors,
  468. OUT PDRTYPE DriveType
  469. );
  470. BOOLEAN
  471. CheckForPrimaryPartition(
  472. );
  473. BOOLEAN
  474. CheckForSystemPartition(
  475. );
  476. BOOLEAN
  477. QueryBusType(
  478. OUT PSTORAGE_BUS_TYPE BusType
  479. );
  480. #if defined(FE_SB) && defined(_X86_)
  481. VOID
  482. SetFormatType(
  483. IN USHORT FormatType
  484. );
  485. #endif
  486. DRTYPE _actual;
  487. PDRTYPE _supported_list;
  488. INT _num_supported;
  489. ULONG _alignment_mask;
  490. BOOLEAN _super_floppy;
  491. BOOLEAN _is_writeable;
  492. BOOLEAN _is_primary_partition;
  493. BOOLEAN _is_system_partition;
  494. DRIVE_TYPE _drive_type;
  495. #if defined(FE_SB) && defined(_X86_)
  496. USHORT _format_type; // this is for NEC98 stuff to force a FAT format
  497. #endif
  498. BOOLEAN _sony_ms;
  499. BOOLEAN _sony_ms_fmt_cmd;
  500. BOOLEAN _sony_ms_progress_indicator;
  501. BOOLEAN _ntfs_not_supported;
  502. };
  503. INLINE
  504. HANDLE
  505. DP_DRIVE::QueryDriveHandle(
  506. ) CONST
  507. /*++
  508. Routine Description:
  509. This routine returns the drive handle.
  510. Arguments:
  511. None.
  512. Return Value:
  513. Drive handle.
  514. --*/
  515. {
  516. return _handle;
  517. }
  518. INLINE
  519. MEDIA_TYPE
  520. DP_DRIVE::QueryMediaType(
  521. ) CONST
  522. /*++
  523. Routine Description:
  524. This routine computes the media type.
  525. Arguments:
  526. None.
  527. Return Value:
  528. The media type.
  529. --*/
  530. {
  531. return _actual.MediaType;
  532. }
  533. INLINE
  534. BIG_INT
  535. DP_DRIVE::QueryHiddenSectors(
  536. ) CONST
  537. /*++
  538. Routine Description:
  539. This routine computes the number of hidden sectors.
  540. Arguments:
  541. None.
  542. Return Value:
  543. The number of hidden sectors.
  544. --*/
  545. {
  546. return _actual.HiddenSectors;
  547. }
  548. #if defined(FE_SB) && defined(_X86_)
  549. INLINE
  550. BIG_INT
  551. DP_DRIVE::QueryPhysicalHiddenSectors(
  552. ) CONST
  553. /*++
  554. Routine Description:
  555. This routine computes the number of hidden sectors for 98's FAT.
  556. Arguments:
  557. None.
  558. Return Value:
  559. The number of hidden sectors.
  560. --*/
  561. {
  562. return _actual.PhysicalHiddenSectors;
  563. }
  564. #endif
  565. INLINE
  566. SECTORCOUNT
  567. DP_DRIVE::QuerySectorsPerTrack(
  568. ) CONST
  569. /*++
  570. Routine Description:
  571. This routine computes the number of sectors per track.
  572. Arguments:
  573. None.
  574. Return Value:
  575. The number of sectors per track.
  576. --*/
  577. {
  578. return _actual.SectorsPerTrack;
  579. }
  580. INLINE
  581. ULONG
  582. DP_DRIVE::QueryHeads(
  583. ) CONST
  584. /*++
  585. Routine Description:
  586. This routine computes the number of heads.
  587. Arguments:
  588. None.
  589. Return Value:
  590. The number of heads.
  591. --*/
  592. {
  593. return _actual.Heads;
  594. }
  595. INLINE
  596. BIG_INT
  597. DP_DRIVE::QueryTracks(
  598. ) CONST
  599. /*++
  600. Routine Description:
  601. This routine computes the number of tracks on the disk.
  602. Arguments:
  603. None.
  604. Return Value:
  605. The number of tracks on the disk.
  606. --*/
  607. {
  608. return (_actual.Sectors + _actual.HiddenSectors)/_actual.SectorsPerTrack;
  609. }
  610. INLINE
  611. BIG_INT
  612. DP_DRIVE::QueryCylinders(
  613. ) CONST
  614. /*++
  615. Routine Description:
  616. This routine computes the number of cylinders on the disk.
  617. Arguments:
  618. None.
  619. Return Value:
  620. The number of cylinders on the disk.
  621. --*/
  622. {
  623. return QueryTracks()/_actual.Heads;
  624. }
  625. INLINE
  626. BOOLEAN
  627. DP_DRIVE::IsRemovable(
  628. ) CONST
  629. /*++
  630. Routine Description:
  631. This routine computes whether or not the disk is removable.
  632. Arguments:
  633. None.
  634. Return Value:
  635. FALSE - The disk is not removable.
  636. TRUE - The disk is removable.
  637. --*/
  638. {
  639. return _actual.MediaType != FixedMedia;
  640. }
  641. INLINE
  642. BOOLEAN
  643. DP_DRIVE::IsWriteable(
  644. ) CONST
  645. /*++
  646. Routine Description:
  647. This routine checks to see if the drive is writeable.
  648. Arguments:
  649. N/A
  650. Return Value:
  651. TRUE - if the disk is writeable
  652. FALSE - if the disk is write protected
  653. --*/
  654. {
  655. return _is_writeable;
  656. }
  657. INLINE
  658. BOOLEAN
  659. DP_DRIVE::IsPrimaryPartition(
  660. ) CONST
  661. /*++
  662. Routine Description:
  663. This routine checks to see if the volume is on a primary partition.
  664. Arguments:
  665. N/A
  666. Return Value:
  667. TRUE - if the volume is on a primary partition.
  668. FALSE - if the volume is not on a primary partition.
  669. --*/
  670. {
  671. return _is_primary_partition;
  672. }
  673. INLINE
  674. BOOLEAN
  675. DP_DRIVE::IsSystemPartition(
  676. ) CONST
  677. /*++
  678. Routine Description:
  679. This routine checks to see if the volume is a system partition.
  680. Arguments:
  681. N/A
  682. Return Value:
  683. TRUE - if the volume is a system partition.
  684. FALSE - if the volume is not a system partition.
  685. --*/
  686. {
  687. return _is_system_partition;
  688. }
  689. INLINE
  690. DRIVE_TYPE
  691. DP_DRIVE::QueryDriveType(
  692. ) CONST
  693. /*++
  694. Routine Description:
  695. This routine returns the drive type.
  696. Arguments:
  697. N/A
  698. Return Value:
  699. UnknownDrive,
  700. RemovableDrive,
  701. FixedDrive,
  702. RemoteDrive,
  703. CdRomDrive,
  704. RamDiskDrive
  705. --*/
  706. {
  707. return _drive_type;
  708. }
  709. INLINE
  710. BOOLEAN
  711. DP_DRIVE::IsFloppy(
  712. ) CONST
  713. /*++
  714. Routine Description:
  715. This routine computes whether or not the disk is a floppy disk.
  716. Arguments:
  717. None.
  718. Return Value:
  719. FALSE - The disk is not a floppy disk.
  720. TRUE - The disk is a floppy disk.
  721. --*/
  722. {
  723. return IsRemovable() && _actual.MediaType != RemovableMedia;
  724. }
  725. INLINE
  726. BOOLEAN
  727. DP_DRIVE::IsSuperFloppy(
  728. ) CONST
  729. /*++
  730. Routine Description:
  731. This routine tells whether the media is non-floppy unpartitioned
  732. removable media.
  733. Arguments:
  734. None.
  735. Return Value:
  736. FALSE - The disk is not a floppy disk.
  737. TRUE - The disk is a floppy disk.
  738. --*/
  739. {
  740. return _super_floppy;
  741. }
  742. INLINE
  743. BOOLEAN
  744. DP_DRIVE::IsFixed(
  745. ) CONST
  746. /*++
  747. Routine Description:
  748. This routine computes whether or not the disk is a fixed disk.
  749. Arguments:
  750. None.
  751. Return Value:
  752. FALSE - The disk is not a fixed disk.
  753. TRUE - The disk is a fixed disk.
  754. --*/
  755. {
  756. return _actual.MediaType == FixedMedia;
  757. }
  758. INLINE
  759. PCDRTYPE
  760. DP_DRIVE::GetSupportedList(
  761. OUT PINT NumSupported
  762. ) CONST
  763. /*++
  764. Routine Description:
  765. This routine returns a list of the supported media types by the device.
  766. Arguments:
  767. NumSupported - Returns the number of elements in the list.
  768. Return Value:
  769. A list of the supported media types by the device.
  770. --*/
  771. {
  772. *NumSupported = _num_supported;
  773. return _supported_list;
  774. }
  775. INLINE
  776. ULONG
  777. DP_DRIVE::QueryAlignmentMask(
  778. ) CONST
  779. /*++
  780. Routine Description:
  781. This routine returns the memory alignment requirement for the drive.
  782. Arguments:
  783. None.
  784. Return Value:
  785. The memory alignment requirement for the drive in the form of a mask.
  786. --*/
  787. {
  788. return _alignment_mask;
  789. }
  790. INLINE
  791. NTSTATUS
  792. DP_DRIVE::QueryLastNtStatus(
  793. ) CONST
  794. /*++
  795. Routine Description:
  796. This routine returns the last NT status value.
  797. Arguments:
  798. None.
  799. Return Value:
  800. The last NT status value.
  801. --*/
  802. {
  803. return _last_status;
  804. }
  805. #if defined(FE_SB) && defined(_X86_)
  806. INLINE
  807. VOID
  808. DP_DRIVE::SetFormatType(
  809. IN USHORT FileSystem
  810. )
  811. /*++
  812. Routine Description:
  813. This routine sets the format type.
  814. Arguments:
  815. FileSystem - Supplies the format type: FAT HPFS NONE ANY OTHER
  816. Return Value:
  817. None
  818. --*/
  819. {
  820. if (FileSystem != ANY || _format_type == NONE)
  821. _format_type = FileSystem;
  822. }
  823. INLINE
  824. USHORT
  825. DP_DRIVE::QueryFormatType(
  826. )
  827. /*++
  828. Routine Description:
  829. This routine returns the format type.
  830. Arguments:
  831. None.
  832. Return Value:
  833. Format type: FAT HPFS NONE ANY OTHER
  834. --*/
  835. {
  836. return _format_type;
  837. }
  838. #endif
  839. INLINE
  840. BOOLEAN
  841. DP_DRIVE::IsSonyMSProgressIndicatorCapable(
  842. )
  843. /*++
  844. Routine Description:
  845. This routine returns the progress bar capability of the Sony MS reader.
  846. Arguments:
  847. None.
  848. Return Value:
  849. TRUE if device is capable of reporting format progress.
  850. --*/
  851. {
  852. return _sony_ms_progress_indicator;
  853. }
  854. INLINE
  855. BOOLEAN
  856. DP_DRIVE::IsSonyMS(
  857. )
  858. /*++
  859. Routine Description:
  860. This routine tells if the device is a Sony Memory Stick.
  861. Arguments:
  862. None.
  863. Return Value:
  864. TRUE if device is a Sony Memory Stick.
  865. --*/
  866. {
  867. return _sony_ms;
  868. }
  869. INLINE
  870. BOOLEAN
  871. DP_DRIVE::IsSonyMSFmtCmdCapable(
  872. )
  873. /*++
  874. Routine Description:
  875. This routine returns the format capability of the Sony MS reader.
  876. Arguments:
  877. None.
  878. Return Value:
  879. TRUE if device is capable of handling format command.
  880. --*/
  881. {
  882. return _sony_ms_fmt_cmd;
  883. }
  884. INLINE
  885. BOOLEAN
  886. DP_DRIVE::IsNtfsNotSupported(
  887. )
  888. /*++
  889. Routine Description:
  890. This routine returns the progress bar capability of the Sony MS reader.
  891. Arguments:
  892. None.
  893. Return Value:
  894. TRUE if device is capable of reporting format progress.
  895. --*/
  896. {
  897. return _ntfs_not_supported;
  898. }
  899. class IO_DP_DRIVE : public DP_DRIVE {
  900. FRIEND class DRIVE_CACHE;
  901. public:
  902. VIRTUAL
  903. ~IO_DP_DRIVE(
  904. );
  905. NONVIRTUAL
  906. IFSUTIL_EXPORT
  907. BOOLEAN
  908. Read(
  909. IN BIG_INT StartingSector,
  910. IN SECTORCOUNT NumberOfSectors,
  911. OUT PVOID Buffer
  912. );
  913. NONVIRTUAL
  914. IFSUTIL_EXPORT
  915. BOOLEAN
  916. Write(
  917. IN BIG_INT StartingSector,
  918. IN SECTORCOUNT NumberOfSectors,
  919. IN PVOID Buffer
  920. );
  921. NONVIRTUAL
  922. IFSUTIL_EXPORT
  923. BOOLEAN
  924. Verify(
  925. IN BIG_INT StartingSector,
  926. IN BIG_INT NumberOfSectors
  927. );
  928. NONVIRTUAL
  929. IFSUTIL_EXPORT
  930. BOOLEAN
  931. Verify(
  932. IN BIG_INT StartingSector,
  933. IN BIG_INT NumberOfSectors,
  934. IN OUT PNUMBER_SET BadSectors
  935. );
  936. NONVIRTUAL
  937. IFSUTIL_EXPORT
  938. PMESSAGE
  939. GetMessage(
  940. );
  941. NONVIRTUAL
  942. IFSUTIL_EXPORT
  943. BOOLEAN
  944. Lock(
  945. );
  946. NONVIRTUAL
  947. IFSUTIL_EXPORT
  948. BOOLEAN
  949. InvalidateVolume(
  950. );
  951. NONVIRTUAL
  952. BOOLEAN
  953. Unlock(
  954. );
  955. NONVIRTUAL
  956. BOOLEAN
  957. DismountAndUnlock(
  958. );
  959. NONVIRTUAL
  960. IFSUTIL_EXPORT
  961. BOOLEAN
  962. DismountAndLock(
  963. );
  964. NONVIRTUAL
  965. BOOLEAN
  966. ForceDirty(
  967. );
  968. NONVIRTUAL
  969. BOOLEAN
  970. FormatVerifyFloppy(
  971. IN MEDIA_TYPE MediaType DEFAULT Unknown,
  972. IN OUT PNUMBER_SET BadSectors DEFAULT NULL,
  973. IN OUT PMESSAGE Message DEFAULT NULL,
  974. IN BOOLEAN IsDmfFormat DEFAULT FALSE
  975. );
  976. NONVIRTUAL
  977. IFSUTIL_EXPORT
  978. VOID
  979. SetCache(
  980. IN OUT PDRIVE_CACHE Cache
  981. );
  982. NONVIRTUAL
  983. IFSUTIL_EXPORT
  984. BOOLEAN
  985. FlushCache(
  986. );
  987. // Note that the following three methods, provided to
  988. // support SimBad, are _not_ in ifsutil.dll.
  989. NONVIRTUAL
  990. BOOLEAN
  991. EnableBadSectorSimulation(
  992. IN BOOLEAN Enable
  993. );
  994. NONVIRTUAL
  995. BOOLEAN
  996. SimulateBadSectors(
  997. IN BOOLEAN Add,
  998. IN ULONG Count,
  999. IN PLBN SectorArray,
  1000. IN NTSTATUS Status,
  1001. IN ULONG AccessType
  1002. );
  1003. NONVIRTUAL
  1004. BOOLEAN
  1005. QuerySimulatedBadSectors(
  1006. OUT PULONG Count,
  1007. IN ULONG MaximumLbnsInBuffer,
  1008. OUT PLBN SectorArray,
  1009. OUT PULONG AccessTypeArray
  1010. );
  1011. #if defined(IO_PERF_COUNTERS)
  1012. NONVIRTUAL
  1013. IFSUTIL_EXPORT
  1014. VOID
  1015. QueryPerformanceCounters(
  1016. PLARGE_INTEGER Wtime,
  1017. PLARGE_INTEGER Rtime,
  1018. PLARGE_INTEGER Ctime,
  1019. PLARGE_INTEGER WSecCount,
  1020. PLARGE_INTEGER WCount,
  1021. PLARGE_INTEGER RRtime,
  1022. PLARGE_INTEGER RSecCount,
  1023. PLARGE_INTEGER RCount
  1024. );
  1025. #endif
  1026. protected:
  1027. DECLARE_CONSTRUCTOR(IO_DP_DRIVE);
  1028. NONVIRTUAL
  1029. BOOLEAN
  1030. Initialize(
  1031. IN PCWSTRING NtDriveName,
  1032. IN OUT PMESSAGE Message DEFAULT NULL,
  1033. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  1034. IN USHORT FormatType DEFAULT NONE
  1035. );
  1036. NONVIRTUAL
  1037. BOOLEAN
  1038. Initialize(
  1039. IN PCWSTRING NtDriveName,
  1040. IN PCWSTRING HostFileName,
  1041. IN OUT PMESSAGE Message DEFAULT NULL,
  1042. IN BOOLEAN ExclusiveWrite DEFAULT FALSE
  1043. );
  1044. private:
  1045. BOOLEAN _is_locked;
  1046. BOOLEAN _is_exclusive_write;
  1047. PDRIVE_CACHE _cache;
  1048. ULONG _ValidBlockLengthForVerify;
  1049. PMESSAGE _message;
  1050. NONVIRTUAL
  1051. VOID
  1052. Construct(
  1053. );
  1054. NONVIRTUAL
  1055. VOID
  1056. Destroy(
  1057. );
  1058. NONVIRTUAL
  1059. BOOLEAN
  1060. VerifyWithRead(
  1061. IN BIG_INT StartingSector,
  1062. IN BIG_INT NumberOfSectors
  1063. );
  1064. NONVIRTUAL
  1065. BOOLEAN
  1066. HardRead(
  1067. IN BIG_INT StartingSector,
  1068. IN SECTORCOUNT NumberOfSectors,
  1069. OUT PVOID Buffer
  1070. );
  1071. NONVIRTUAL
  1072. BOOLEAN
  1073. HardWrite(
  1074. IN BIG_INT StartingSector,
  1075. IN SECTORCOUNT NumberOfSectors,
  1076. IN PVOID Buffer
  1077. );
  1078. NONVIRTUAL
  1079. BOOLEAN
  1080. Dismount(
  1081. );
  1082. #if defined(IO_PERF_COUNTERS)
  1083. STATIC LARGE_INTEGER _wtotal, _rtotal, _ctotal, _rrtotal;
  1084. STATIC LARGE_INTEGER _wcount, _rcount;
  1085. STATIC LARGE_INTEGER _wsize, _rsize;
  1086. #endif
  1087. };
  1088. INLINE
  1089. PMESSAGE
  1090. IO_DP_DRIVE::GetMessage(
  1091. )
  1092. /*++
  1093. Routine Description:
  1094. Retrieve the message object.
  1095. Arguments:
  1096. N/A
  1097. Return Value:
  1098. The message object.
  1099. --*/
  1100. {
  1101. return _message;
  1102. }
  1103. class LOG_IO_DP_DRIVE : public IO_DP_DRIVE {
  1104. public:
  1105. IFSUTIL_EXPORT
  1106. DECLARE_CONSTRUCTOR(LOG_IO_DP_DRIVE);
  1107. VIRTUAL
  1108. IFSUTIL_EXPORT
  1109. ~LOG_IO_DP_DRIVE(
  1110. );
  1111. NONVIRTUAL
  1112. IFSUTIL_EXPORT
  1113. BOOLEAN
  1114. Initialize(
  1115. IN PCWSTRING NtDriveName,
  1116. IN OUT PMESSAGE Message DEFAULT NULL,
  1117. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  1118. IN USHORT FormatType DEFAULT NONE
  1119. );
  1120. NONVIRTUAL
  1121. IFSUTIL_EXPORT
  1122. BOOLEAN
  1123. SetSystemId(
  1124. IN PARTITION_SYSTEM_ID SystemId
  1125. );
  1126. #if defined (FE_SB) && defined (_X86_)
  1127. // NEC98 June.25.1995
  1128. // Add the type definition of function that other DLL is able to
  1129. // call IO_DP_DRIVE::Read and IO_DP_DRIVE::Write.
  1130. NONVIRTUAL
  1131. IFSUTIL_EXPORT
  1132. BOOLEAN
  1133. Read(
  1134. IN BIG_INT StartingSector,
  1135. IN SECTORCOUNT NumberOfSectors,
  1136. OUT PVOID Buffer
  1137. );
  1138. NONVIRTUAL
  1139. IFSUTIL_EXPORT
  1140. BOOLEAN
  1141. Write(
  1142. IN BIG_INT StartingSector,
  1143. IN SECTORCOUNT NumberOfSectors,
  1144. IN PVOID Buffer
  1145. );
  1146. #endif
  1147. NONVIRTUAL
  1148. IFSUTIL_EXPORT
  1149. BOOLEAN
  1150. Initialize(
  1151. IN PCWSTRING NtDriveName,
  1152. IN PCWSTRING HostFileName,
  1153. IN OUT PMESSAGE Message DEFAULT NULL,
  1154. IN BOOLEAN ExclusiveWrite DEFAULT FALSE
  1155. );
  1156. NONVIRTUAL
  1157. UCHAR
  1158. QueryPartitionType(
  1159. ) CONST;
  1160. private:
  1161. NONVIRTUAL
  1162. VOID
  1163. Construct(
  1164. );
  1165. };
  1166. INLINE
  1167. VOID
  1168. LOG_IO_DP_DRIVE::Construct(
  1169. )
  1170. /*++
  1171. Routine Description:
  1172. Constructor for LOG_IO_DP_DRIVE.
  1173. Arguments:
  1174. None.
  1175. Return Value:
  1176. None.
  1177. --*/
  1178. {
  1179. }
  1180. INLINE
  1181. UCHAR
  1182. LOG_IO_DP_DRIVE::QueryPartitionType(
  1183. ) CONST
  1184. /*++
  1185. Routine Description:
  1186. This routine returns the partition type.
  1187. Arguments:
  1188. None.
  1189. Return Value:
  1190. The last partition type value.
  1191. --*/
  1192. {
  1193. #if defined(RUN_ON_W2K)
  1194. return _partition_info.PartitionType;
  1195. #else
  1196. return _partition_info.Mbr.PartitionType;
  1197. #endif
  1198. }
  1199. class PHYS_IO_DP_DRIVE : public IO_DP_DRIVE {
  1200. public:
  1201. DECLARE_CONSTRUCTOR(PHYS_IO_DP_DRIVE);
  1202. VIRTUAL
  1203. ~PHYS_IO_DP_DRIVE(
  1204. );
  1205. NONVIRTUAL
  1206. BOOLEAN
  1207. Initialize(
  1208. IN PCWSTRING NtDriveName,
  1209. IN OUT PMESSAGE Message DEFAULT NULL,
  1210. IN BOOLEAN ExclusiveWrite DEFAULT FALSE,
  1211. IN USHORT FormatType DEFAULT NONE
  1212. );
  1213. private:
  1214. NONVIRTUAL
  1215. VOID
  1216. Construct(
  1217. );
  1218. };
  1219. INLINE
  1220. VOID
  1221. PHYS_IO_DP_DRIVE::Construct(
  1222. )
  1223. /*++
  1224. Routine Description:
  1225. Constructor for PHYS_IO_DP_DRIVE.
  1226. Arguments:
  1227. None.
  1228. Return Value:
  1229. None.
  1230. --*/
  1231. {
  1232. }
  1233. INLINE
  1234. HANDLE
  1235. DP_DRIVE::GetVolumeFileHandle(
  1236. ) CONST
  1237. /*++
  1238. Routine Description:
  1239. This routine is a hack for NTFS->OFS convert... it returns the
  1240. handle open on the ntfs volume-file.
  1241. Arguments:
  1242. None.
  1243. Return Value:
  1244. The handle.
  1245. --*/
  1246. {
  1247. return _handle;
  1248. }
  1249. #endif // DRIVE_DEFN