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.

2807 lines
64 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumPhysicalDisks.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CEnumPhysicalDisks
  10. // class.
  11. //
  12. // The class CEnumPhysicalDisks is the enumeration of cluster
  13. // storage devices. It implements the IEnumClusCfgManagedResources
  14. // interface.
  15. //
  16. // Documentation:
  17. //
  18. // Header File:
  19. // CEnumPhysicalDisks.h
  20. //
  21. // Maintained By:
  22. // Galen Barbee (GalenB) 23-FEB-2000
  23. //
  24. //////////////////////////////////////////////////////////////////////////////
  25. //////////////////////////////////////////////////////////////////////////////
  26. // Include Files
  27. //////////////////////////////////////////////////////////////////////////////
  28. #include "pch.h"
  29. #include "CEnumPhysicalDisks.h"
  30. #include "CPhysicalDisk.h"
  31. #include <PropList.h>
  32. //////////////////////////////////////////////////////////////////////////////
  33. // Constant Definitions
  34. //////////////////////////////////////////////////////////////////////////////
  35. DEFINE_THISCLASS( "CEnumPhysicalDisks" );
  36. //*************************************************************************//
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CEnumPhysicalDisks class
  39. /////////////////////////////////////////////////////////////////////////////
  40. //////////////////////////////////////////////////////////////////////////////
  41. //++
  42. //
  43. // CEnumPhysicalDisks::S_HrCreateInstance
  44. //
  45. // Description:
  46. // Create a CEnumPhysicalDisks instance.
  47. //
  48. // Arguments:
  49. // None.
  50. //
  51. // Return Values:
  52. // S_OK
  53. // Success.
  54. //
  55. // E_POINTER
  56. // The passed in ppunk is NULL.
  57. //
  58. // other HRESULTs
  59. // Object creation failed.
  60. //
  61. //--
  62. //////////////////////////////////////////////////////////////////////////////
  63. HRESULT
  64. CEnumPhysicalDisks::S_HrCreateInstance( IUnknown ** ppunkOut )
  65. {
  66. TraceFunc( "" );
  67. HRESULT hr;
  68. CEnumPhysicalDisks * pccpd = NULL;
  69. if ( ppunkOut == NULL )
  70. {
  71. hr = THR( E_POINTER );
  72. goto Cleanup;
  73. } // if:
  74. pccpd = new CEnumPhysicalDisks();
  75. if ( pccpd == NULL )
  76. {
  77. hr = THR( E_OUTOFMEMORY );
  78. goto Cleanup;
  79. } // if: error allocating object
  80. hr = THR( pccpd->HrInit() );
  81. if ( FAILED( hr ) )
  82. {
  83. goto Cleanup;
  84. } // if: HrInit() failed
  85. hr = THR( pccpd->TypeSafeQI( IUnknown, ppunkOut ) );
  86. Cleanup:
  87. if ( FAILED( hr ) )
  88. {
  89. LogMsg( L"[SRV] CEnumPhysicalDisks::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  90. } // if:
  91. if ( pccpd != NULL )
  92. {
  93. pccpd->Release();
  94. } // if:
  95. HRETURN( hr );
  96. } //*** CEnumPhysicalDisks::S_HrCreateInstance
  97. //////////////////////////////////////////////////////////////////////////////
  98. //++
  99. //
  100. // IUnknown *
  101. // CEnumPhysicalDisks::S_RegisterCatIDSupport
  102. //
  103. // Description:
  104. // Registers/unregisters this class with the categories that it belongs
  105. // to.
  106. //
  107. // Arguments:
  108. // IN ICatRegister * picrIn
  109. // Used to register/unregister our CATID support.
  110. //
  111. // IN BOOL fCreateIn
  112. // When true we are registering the server. When false we are
  113. // un-registering the server.
  114. //
  115. // Return Values:
  116. // S_OK
  117. // Success.
  118. //
  119. // E_INVALIDARG
  120. // The passed in ICatRgister pointer was NULL.
  121. //
  122. // other HRESULTs
  123. // Registration/Unregistration failed.
  124. //
  125. //--
  126. //////////////////////////////////////////////////////////////////////////////
  127. HRESULT
  128. CEnumPhysicalDisks::S_RegisterCatIDSupport(
  129. ICatRegister * picrIn,
  130. BOOL fCreateIn
  131. )
  132. {
  133. TraceFunc( "" );
  134. HRESULT hr = S_OK;
  135. CATID rgCatIds[ 1 ];
  136. if ( picrIn == NULL )
  137. {
  138. hr = THR( E_INVALIDARG );
  139. goto Cleanup;
  140. } // if:
  141. rgCatIds[ 0 ] = CATID_EnumClusCfgManagedResources;
  142. if ( fCreateIn )
  143. {
  144. hr = THR( picrIn->RegisterClassImplCategories( CLSID_EnumPhysicalDisks, 1, rgCatIds ) );
  145. } // if:
  146. Cleanup:
  147. HRETURN( hr );
  148. } //*** CEnumPhysicalDisks::S_RegisterCatIDSupport
  149. //////////////////////////////////////////////////////////////////////////////
  150. //++
  151. //
  152. // CEnumPhysicalDisks::CEnumPhysicalDisks
  153. //
  154. // Description:
  155. // Constructor of the CEnumPhysicalDisks class. This initializes
  156. // the m_cRef variable to 1 instead of 0 to account of possible
  157. // QueryInterface failure in DllGetClassObject.
  158. //
  159. // Arguments:
  160. // None.
  161. //
  162. // Return Value:
  163. // None.
  164. //
  165. // Remarks:
  166. // None.
  167. //
  168. //--
  169. //////////////////////////////////////////////////////////////////////////////
  170. CEnumPhysicalDisks::CEnumPhysicalDisks( void )
  171. : m_cRef( 1 )
  172. , m_lcid( LOCALE_NEUTRAL )
  173. , m_fLoadedDevices( false )
  174. {
  175. TraceFunc( "" );
  176. // Increment the count of components in memory so the DLL hosting this
  177. // object cannot be unloaded.
  178. InterlockedIncrement( &g_cObjects );
  179. Assert( m_picccCallback == NULL );
  180. Assert( m_pIWbemServices == NULL );
  181. Assert( m_prgDisks == NULL );
  182. Assert( m_idxNext == 0 );
  183. Assert( m_idxEnumNext == 0 );
  184. Assert( m_bstrNodeName == NULL );
  185. Assert( m_bstrBootDevice == NULL );
  186. Assert( m_bstrSystemDevice == NULL );
  187. Assert( m_bstrBootLogicalDisk == NULL );
  188. Assert( m_bstrSystemLogicalDisk == NULL );
  189. Assert( m_bstrSystemWMIDeviceID == NULL );
  190. Assert( m_cDiskCount == 0 );
  191. TraceFuncExit();
  192. } //*** CEnumPhysicalDisks::CEnumPhysicalDisks
  193. //////////////////////////////////////////////////////////////////////////////
  194. //++
  195. //
  196. // CEnumPhysicalDisks::~CEnumPhysicalDisks
  197. //
  198. // Description:
  199. // Desstructor of the CEnumPhysicalDisks class.
  200. //
  201. // Arguments:
  202. // None.
  203. //
  204. // Return Value:
  205. // None.
  206. //
  207. // Remarks:
  208. // None.
  209. //
  210. //--
  211. //////////////////////////////////////////////////////////////////////////////
  212. CEnumPhysicalDisks::~CEnumPhysicalDisks( void )
  213. {
  214. TraceFunc( "" );
  215. ULONG idx;
  216. if ( m_pIWbemServices != NULL )
  217. {
  218. m_pIWbemServices->Release();
  219. } // if:
  220. if ( m_picccCallback != NULL )
  221. {
  222. m_picccCallback->Release();
  223. } // if:
  224. for ( idx = 0; idx < m_idxNext; idx++ )
  225. {
  226. if ( (*m_prgDisks)[ idx ] != NULL )
  227. {
  228. ((*m_prgDisks)[ idx ])->Release();
  229. } // end if:
  230. } // for:
  231. TraceFree( m_prgDisks );
  232. TraceSysFreeString( m_bstrNodeName );
  233. TraceSysFreeString( m_bstrBootDevice );
  234. TraceSysFreeString( m_bstrSystemDevice );
  235. TraceSysFreeString( m_bstrBootLogicalDisk );
  236. TraceSysFreeString( m_bstrSystemLogicalDisk );
  237. TraceSysFreeString( m_bstrSystemWMIDeviceID );
  238. // There's going to be one less component in memory. Decrement component count.
  239. InterlockedDecrement( &g_cObjects );
  240. TraceFuncExit();
  241. } //*** CEnumPhysicalDisks::~CEnumPhysicalDisks
  242. //*************************************************************************//
  243. /////////////////////////////////////////////////////////////////////////////
  244. // CEnumPhysicalDisks -- IUnknown interface.
  245. /////////////////////////////////////////////////////////////////////////////
  246. //////////////////////////////////////////////////////////////////////////////
  247. //++
  248. //
  249. // STDMETHODIMP_( ULONG )
  250. // CEnumPhysicalDisks:: [IUNKNOWN] AddRef
  251. //
  252. // Description:
  253. // Increment the reference count of this object by one.
  254. //
  255. // Arguments:
  256. // None.
  257. //
  258. // Return Value:
  259. // The new reference count.
  260. //
  261. // Remarks:
  262. // None.
  263. //
  264. //--
  265. //////////////////////////////////////////////////////////////////////////////
  266. STDMETHODIMP_( ULONG )
  267. CEnumPhysicalDisks::AddRef( void )
  268. {
  269. TraceFunc( "[IUnknown]" );
  270. InterlockedIncrement( & m_cRef );
  271. RETURN( m_cRef );
  272. } //*** CEnumPhysicalDisks::AddRef
  273. //////////////////////////////////////////////////////////////////////////////
  274. //++
  275. //
  276. // STDMETHODIMP_( ULONG )
  277. // CEnumPhysicalDisks:: [IUNKNOWN] Release
  278. //
  279. // Description:
  280. // Decrement the reference count of this object by one.
  281. //
  282. // Arguments:
  283. // None.
  284. //
  285. // Return Value:
  286. // The new reference count.
  287. //
  288. // Remarks:
  289. // None.
  290. //
  291. //--
  292. //////////////////////////////////////////////////////////////////////////////
  293. STDMETHODIMP_( ULONG )
  294. CEnumPhysicalDisks::Release( void )
  295. {
  296. TraceFunc( "[IUnknown]" );
  297. LONG cRef;
  298. cRef = InterlockedDecrement( &m_cRef );
  299. if ( cRef == 0 )
  300. {
  301. TraceDo( delete this );
  302. } // if: reference count equal to zero
  303. RETURN( cRef );
  304. } //*** CEnumPhysicalDisks::Release
  305. //////////////////////////////////////////////////////////////////////////////
  306. //++
  307. //
  308. // CEnumPhysicalDisks:: [INKNOWN] QueryInterface
  309. //
  310. // Description:
  311. // Query this object for the passed in interface.
  312. //
  313. // Arguments:
  314. // IN REFIID riid,
  315. // Id of interface requested.
  316. //
  317. // OUT void ** ppv
  318. // Pointer to the requested interface.
  319. //
  320. // Return Value:
  321. // S_OK
  322. // If the interface is available on this object.
  323. //
  324. // E_NOINTERFACE
  325. // If the interface is not available.
  326. //
  327. // Remarks:
  328. // None.
  329. //
  330. //--
  331. //////////////////////////////////////////////////////////////////////////////
  332. STDMETHODIMP
  333. CEnumPhysicalDisks::QueryInterface( REFIID riid, void ** ppv )
  334. {
  335. TraceQIFunc( riid, ppv );
  336. HRESULT hr = E_NOINTERFACE;
  337. if ( IsEqualIID( riid, IID_IUnknown ) )
  338. {
  339. *ppv = static_cast< IEnumClusCfgManagedResources * >( this );
  340. hr = S_OK;
  341. } // if: IUnknown
  342. else if ( IsEqualIID( riid, IID_IEnumClusCfgManagedResources ) )
  343. {
  344. *ppv = TraceInterface( __THISCLASS__, IEnumClusCfgManagedResources, this, 0 );
  345. hr = S_OK;
  346. } // else if:
  347. else if ( IsEqualIID( riid, IID_IClusCfgWbemServices ) )
  348. {
  349. *ppv = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  350. hr = S_OK;
  351. } // else if:
  352. else if ( IsEqualIID( riid, IID_IClusCfgInitialize ) )
  353. {
  354. *ppv = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  355. hr = S_OK;
  356. } // else if:
  357. if ( SUCCEEDED( hr ) )
  358. {
  359. ((IUnknown *) *ppv)->AddRef( );
  360. } // if: success
  361. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  362. } //*** CEnumPhysicalDisks::QueryInterface
  363. //*************************************************************************//
  364. /////////////////////////////////////////////////////////////////////////////
  365. // CEnumPhysicalDisks -- IClusCfgWbemServices interface.
  366. /////////////////////////////////////////////////////////////////////////////
  367. //////////////////////////////////////////////////////////////////////////////
  368. //++
  369. //
  370. // CEnumPhysicalDisks::SetWbemServices
  371. //
  372. // Description:
  373. // Set the WBEM services provider.
  374. //
  375. // Arguments:
  376. // IN IWbemServices pIWbemServicesIn
  377. //
  378. // Return Value:
  379. // S_OK
  380. // Success
  381. //
  382. // E_POINTER
  383. // The pIWbemServicesIn param is NULL.
  384. //
  385. // Remarks:
  386. // None.
  387. //
  388. //--
  389. //////////////////////////////////////////////////////////////////////////////
  390. STDMETHODIMP
  391. CEnumPhysicalDisks::SetWbemServices( IWbemServices * pIWbemServicesIn )
  392. {
  393. TraceFunc( "[IClusCfgWbemServices]" );
  394. HRESULT hr = S_OK;
  395. if ( pIWbemServicesIn == NULL )
  396. {
  397. hr = THR( E_POINTER );
  398. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Enum_PhysDisk, IDS_ERROR_NULL_POINTER, hr );
  399. goto Cleanup;
  400. } // if:
  401. m_pIWbemServices = pIWbemServicesIn;
  402. m_pIWbemServices->AddRef();
  403. hr = THR( HrGetSystemDevice( &m_bstrSystemDevice ) );
  404. if ( FAILED( hr ) )
  405. {
  406. goto Cleanup;
  407. } // if:
  408. hr = THR( HrConvertDeviceVolumeToLogicalDisk( m_bstrSystemDevice, &m_bstrSystemLogicalDisk ) );
  409. //
  410. // system volume is an EFI volume on IA64 and won't have a logical disk.
  411. //
  412. if ( HRESULT_CODE( hr ) == ERROR_INVALID_FUNCTION )
  413. {
  414. hr = THR( HrConvertDeviceVolumeToWMIDeviceID( m_bstrSystemDevice, &m_bstrSystemWMIDeviceID ) );
  415. Assert( m_bstrSystemLogicalDisk == NULL );
  416. Assert( m_bstrSystemWMIDeviceID != NULL );
  417. } // if:
  418. if ( FAILED( hr ) )
  419. {
  420. goto Cleanup;
  421. } // if:
  422. hr = THR( HrGetBootLogicalDisk( &m_bstrBootLogicalDisk ) );
  423. if ( FAILED( hr ) )
  424. {
  425. goto Cleanup;
  426. } // if:
  427. hr = STHR( HrIsLogicalDiskNTFS( m_bstrBootLogicalDisk ) );
  428. if ( hr == S_FALSE )
  429. {
  430. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Boot_Partition_Not_NTFS, IDS_WARNING_BOOT_PARTITION_NOT_NTFS, hr );
  431. hr = S_OK;
  432. } // if:
  433. Cleanup:
  434. HRETURN( hr );
  435. } //*** CEnumPhysicalDisks::SetWbemServices
  436. //*************************************************************************//
  437. /////////////////////////////////////////////////////////////////////////////
  438. // CEnumPhysicalDisks -- IClusCfgInitialize interface.
  439. /////////////////////////////////////////////////////////////////////////////
  440. //////////////////////////////////////////////////////////////////////////////
  441. //++
  442. //
  443. // CEnumPhysicalDisks::Initialize
  444. //
  445. // Description:
  446. // Initialize this component.
  447. //
  448. // Arguments:
  449. // IN IUknown * punkCallbackIn
  450. //
  451. // IN LCID lcidIn
  452. //
  453. // Return Value:
  454. // S_OK
  455. // Success
  456. //
  457. // Remarks:
  458. // None.
  459. //
  460. //--
  461. //////////////////////////////////////////////////////////////////////////////
  462. STDMETHODIMP
  463. CEnumPhysicalDisks::Initialize(
  464. IUnknown * punkCallbackIn,
  465. LCID lcidIn
  466. )
  467. {
  468. TraceFunc( "[IClusCfgInitialize]" );
  469. Assert( m_picccCallback == NULL );
  470. HRESULT hr = S_OK;
  471. m_lcid = lcidIn;
  472. if ( punkCallbackIn == NULL )
  473. {
  474. hr = THR( E_POINTER );
  475. goto Cleanup;
  476. } // if:
  477. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  478. if ( FAILED( hr ) )
  479. {
  480. goto Cleanup;
  481. } // if:
  482. hr = THR( HrGetComputerName( ComputerNameNetBIOS, &m_bstrNodeName ) );
  483. Cleanup:
  484. HRETURN( hr );
  485. } //*** CEnumPhysicalDisks::Initialize
  486. //*************************************************************************//
  487. /////////////////////////////////////////////////////////////////////////////
  488. // CEnumPhysicalDisks -- IEnumClusCfgManagedResources interface.
  489. /////////////////////////////////////////////////////////////////////////////
  490. //////////////////////////////////////////////////////////////////////////////
  491. //++
  492. //
  493. // CEnumPhysicalDisks::Next
  494. //
  495. // Description:
  496. //
  497. // Arguments:
  498. //
  499. // Return Value:
  500. //
  501. // Remarks:
  502. // None.
  503. //
  504. //--
  505. //////////////////////////////////////////////////////////////////////////////
  506. STDMETHODIMP
  507. CEnumPhysicalDisks::Next(
  508. ULONG cNumberRequestedIn,
  509. IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut,
  510. ULONG * pcNumberFetchedOut
  511. )
  512. {
  513. TraceFunc( "[IEnumClusCfgManagedResources]" );
  514. HRESULT hr = S_FALSE;
  515. ULONG cFetched = 0;
  516. IClusCfgManagedResourceInfo * pccsdi;
  517. IUnknown * punk;
  518. ULONG ulStop;
  519. if ( rgpManagedResourceInfoOut == NULL )
  520. {
  521. hr = THR( E_POINTER );
  522. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Next_Enum_PhysDisk, IDS_ERROR_NULL_POINTER, hr );
  523. goto Cleanup;
  524. } // if:
  525. if ( !m_fLoadedDevices )
  526. {
  527. hr = THR( HrLoadEnum() );
  528. if ( FAILED( hr ) )
  529. {
  530. goto Cleanup;
  531. } // if:
  532. } // if:
  533. ulStop = min( cNumberRequestedIn, ( m_idxNext - m_idxEnumNext ) );
  534. for ( hr = S_OK; ( cFetched < ulStop ) && ( m_idxEnumNext < m_idxNext ); m_idxEnumNext++ )
  535. {
  536. punk = (*m_prgDisks)[ m_idxEnumNext ];
  537. if ( punk != NULL )
  538. {
  539. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceInfo, &pccsdi ) );
  540. if ( FAILED( hr ) )
  541. {
  542. break;
  543. } // if:
  544. rgpManagedResourceInfoOut[ cFetched++ ] = pccsdi;
  545. } // if:
  546. } // for:
  547. if ( FAILED( hr ) )
  548. {
  549. m_idxEnumNext -= cFetched;
  550. while ( cFetched != 0 )
  551. {
  552. (rgpManagedResourceInfoOut[ --cFetched ])->Release();
  553. } // for:
  554. goto Cleanup;
  555. } // if:
  556. if ( cFetched < cNumberRequestedIn )
  557. {
  558. hr = S_FALSE;
  559. } // if:
  560. Cleanup:
  561. if ( pcNumberFetchedOut != NULL )
  562. {
  563. *pcNumberFetchedOut = cFetched;
  564. } // if:
  565. HRETURN( hr );
  566. } //*** CEnumPhysicalDisks::Next
  567. //////////////////////////////////////////////////////////////////////////////
  568. //++
  569. //
  570. // CEnumPhysicalDisks::Skip
  571. //
  572. // Description:
  573. //
  574. // Arguments:
  575. //
  576. // Return Value:
  577. //
  578. // Remarks:
  579. // None.
  580. //
  581. //--
  582. //////////////////////////////////////////////////////////////////////////////
  583. STDMETHODIMP
  584. CEnumPhysicalDisks::Skip( ULONG cNumberToSkipIn )
  585. {
  586. TraceFunc( "[IEnumClusCfgManagedResources]" );
  587. HRESULT hr = S_OK;
  588. m_idxEnumNext += cNumberToSkipIn;
  589. if ( m_idxEnumNext >= m_idxNext )
  590. {
  591. m_idxEnumNext = m_idxNext;
  592. hr = STHR( S_FALSE );
  593. } // if:
  594. HRETURN( hr );
  595. } //*** CEnumPhysicalDisks::Skip
  596. //////////////////////////////////////////////////////////////////////////////
  597. //++
  598. //
  599. // CEnumPhysicalDisks::Reset
  600. //
  601. // Description:
  602. //
  603. // Arguments:
  604. //
  605. // Return Value:
  606. //
  607. // Remarks:
  608. // None.
  609. //
  610. //--
  611. //////////////////////////////////////////////////////////////////////////////
  612. STDMETHODIMP
  613. CEnumPhysicalDisks::Reset( void )
  614. {
  615. TraceFunc( "[IEnumClusCfgManagedResources]" );
  616. m_idxEnumNext = 0;
  617. HRETURN( S_OK );
  618. } //*** CEnumPhysicalDisks::Reset
  619. //////////////////////////////////////////////////////////////////////////////
  620. //++
  621. //
  622. // CEnumPhysicalDisks::Clone
  623. //
  624. // Description:
  625. //
  626. // Arguments:
  627. //
  628. // Return Value:
  629. //
  630. // Remarks:
  631. // None.
  632. //
  633. //--
  634. //////////////////////////////////////////////////////////////////////////////
  635. STDMETHODIMP
  636. CEnumPhysicalDisks::Clone(
  637. IEnumClusCfgManagedResources ** ppEnumClusCfgStorageDevicesOut
  638. )
  639. {
  640. TraceFunc( "[IEnumClusCfgManagedResources]" );
  641. HRESULT hr = S_OK;
  642. if ( ppEnumClusCfgStorageDevicesOut == NULL )
  643. {
  644. hr = THR( E_POINTER );
  645. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Clone_Enum_PhysDisk, IDS_ERROR_NULL_POINTER, hr );
  646. goto Cleanup;
  647. } // if:
  648. hr = THR( E_NOTIMPL );
  649. Cleanup:
  650. HRETURN( hr );
  651. } //*** CEnumPhysicalDisks::Clone
  652. //////////////////////////////////////////////////////////////////////////////
  653. //++
  654. //
  655. // CEnumPhysicalDisks::Count
  656. //
  657. // Description:
  658. // Return the count of items in the Enum.
  659. //
  660. // Arguments:
  661. //
  662. // Return Value:
  663. //
  664. // Remarks:
  665. // None.
  666. //
  667. //--
  668. //////////////////////////////////////////////////////////////////////////////
  669. STDMETHODIMP
  670. CEnumPhysicalDisks::Count( DWORD * pnCountOut )
  671. {
  672. TraceFunc( "[IEnumClusCfgManagedResources]" );
  673. HRESULT hr = S_OK;
  674. if ( pnCountOut == NULL )
  675. {
  676. hr = THR( E_POINTER );
  677. goto Cleanup;
  678. } // if:
  679. if ( !m_fLoadedDevices )
  680. {
  681. hr = THR( HrLoadEnum() );
  682. if ( FAILED( hr ) )
  683. {
  684. goto Cleanup;
  685. } // if:
  686. } // if:
  687. *pnCountOut = m_cDiskCount;
  688. Cleanup:
  689. HRETURN( hr );
  690. } //*** CEnumPhysicalDisks::Count
  691. //*************************************************************************//
  692. /////////////////////////////////////////////////////////////////////////////
  693. // CEnumPhysicalDisks class -- Private Methods.
  694. /////////////////////////////////////////////////////////////////////////////
  695. //////////////////////////////////////////////////////////////////////////////
  696. //++
  697. //
  698. // CEnumPhysicalDisks::HrInit
  699. //
  700. // Description:
  701. // Initialize this component.
  702. //
  703. // Arguments:
  704. // None.
  705. //
  706. // Return Value:
  707. //
  708. //
  709. // Remarks:
  710. // None.
  711. //
  712. //--
  713. //////////////////////////////////////////////////////////////////////////////
  714. HRESULT
  715. CEnumPhysicalDisks::HrInit( void )
  716. {
  717. TraceFunc( "" );
  718. HRESULT hr = S_OK;
  719. HRETURN( hr );
  720. } //*** CEnumPhysicalDisks::HrInit
  721. /////////////////////////////////////////////////////////////////////////////
  722. //++
  723. //
  724. // CEnumPhysicalDisks::HrGetDisks
  725. //
  726. // Description:
  727. //
  728. // Arguments:
  729. //
  730. //
  731. // Return Value:
  732. //
  733. //
  734. // Remarks:
  735. // None.
  736. //
  737. //--
  738. //////////////////////////////////////////////////////////////////////////////
  739. HRESULT
  740. CEnumPhysicalDisks::HrGetDisks( void )
  741. {
  742. TraceFunc( "" );
  743. HRESULT hr = S_FALSE;
  744. BSTR bstrClass;
  745. IEnumWbemClassObject * pDisks = NULL;
  746. ULONG ulReturned;
  747. IWbemClassObject * pDisk = NULL;
  748. bstrClass = TraceSysAllocString( L"Win32_DiskDrive" );
  749. if ( bstrClass == NULL )
  750. {
  751. goto OutOfMemory;
  752. } // if:
  753. hr = THR( m_pIWbemServices->CreateInstanceEnum( bstrClass, WBEM_FLAG_SHALLOW, NULL, &pDisks ) );
  754. if ( FAILED( hr ) )
  755. {
  756. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_WMI_Phys_Disks_Qry_Failed, IDS_ERROR_WMI_PHYS_DISKS_QRY_FAILED, hr );
  757. goto Cleanup;
  758. } // if:
  759. for ( ; ; )
  760. {
  761. hr = pDisks->Next( WBEM_INFINITE, 1, &pDisk, &ulReturned );
  762. if ( ( hr == S_OK ) && ( ulReturned == 1 ) )
  763. {
  764. hr = STHR( HrLogDiskInfo( pDisk ) );
  765. if ( FAILED( hr ) )
  766. {
  767. goto Cleanup;
  768. } // if:
  769. hr = STHR( IsDiskSCSI( pDisk ) );
  770. if ( FAILED( hr ) )
  771. {
  772. goto Cleanup;
  773. } // if:
  774. if ( hr == S_OK )
  775. {
  776. hr = STHR( HrCreateAndAddDiskToArray( pDisk ) );
  777. if ( FAILED( hr ) )
  778. {
  779. goto Cleanup;
  780. } // if:
  781. } // if:
  782. pDisk->Release();
  783. pDisk = NULL;
  784. } // if:
  785. else if ( ( hr == S_FALSE ) && ( ulReturned == 0 ) )
  786. {
  787. hr = S_OK;
  788. break;
  789. } // else if:
  790. else
  791. {
  792. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_WQL_Disk_Qry_Next_Failed, IDS_ERROR_WQL_QRY_NEXT_FAILED, bstrClass, hr );
  793. goto Cleanup;
  794. } // else:
  795. } // for:
  796. m_idxEnumNext = 0;
  797. m_fLoadedDevices = TRUE;
  798. goto Cleanup;
  799. OutOfMemory:
  800. hr = THR( E_OUTOFMEMORY );
  801. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrGetDisks, IDS_ERROR_OUTOFMEMORY, hr );
  802. Cleanup:
  803. if ( pDisk != NULL )
  804. {
  805. pDisk->Release();
  806. } // if:
  807. if ( pDisks != NULL )
  808. {
  809. pDisks->Release();
  810. } // if:
  811. TraceSysFreeString( bstrClass );
  812. HRETURN( hr );
  813. } //*** CEnumPhysicalDisks::HrGetDisks
  814. /////////////////////////////////////////////////////////////////////////////
  815. //++
  816. //
  817. // CEnumPhysicalDisks::HrCreateAndAddDiskToArray
  818. //
  819. // Description:
  820. // Create a IClusCfgStorageDevice object and add the passed in disk to
  821. // the array of punks that holds the disks.
  822. //
  823. // Arguments:
  824. //
  825. //
  826. // Return Value:
  827. // S_OK
  828. // Success
  829. //
  830. // E_OUTOFMEMORY
  831. // Couldn't allocate memeory.
  832. //
  833. // Remarks:
  834. // None.
  835. //
  836. //--
  837. //////////////////////////////////////////////////////////////////////////////
  838. HRESULT
  839. CEnumPhysicalDisks::HrCreateAndAddDiskToArray( IWbemClassObject * pDiskIn )
  840. {
  841. TraceFunc( "" );
  842. HRESULT hr = S_FALSE;
  843. IUnknown * punk = NULL;
  844. IClusCfgSetWbemObject * piccswo = NULL;
  845. bool fRetainObject = true;
  846. hr = THR( CPhysicalDisk::S_HrCreateInstance( &punk ) );
  847. if ( FAILED( hr ) )
  848. {
  849. goto Exit;
  850. } // if:
  851. punk = TraceInterface( L"CPhysicalDisk", IUnknown, punk, 1 );
  852. hr = THR( HrSetInitialize( punk, m_picccCallback, m_lcid ) );
  853. if ( FAILED( hr ) )
  854. {
  855. goto Cleanup;
  856. } // if:
  857. hr = THR( HrSetWbemServices( punk, m_pIWbemServices ) );
  858. if ( FAILED( hr ) )
  859. {
  860. goto Cleanup;
  861. } // if:
  862. hr = THR( punk->TypeSafeQI( IClusCfgSetWbemObject, &piccswo ) );
  863. if ( FAILED( hr ) )
  864. {
  865. goto Cleanup;
  866. } // if:
  867. hr = STHR( piccswo->SetWbemObject( pDiskIn, &fRetainObject ) );
  868. if ( FAILED( hr ) )
  869. {
  870. goto Cleanup;
  871. } // if:
  872. if ( fRetainObject )
  873. {
  874. hr = THR( HrAddDiskToArray( punk ) );
  875. } // if:
  876. Cleanup:
  877. if ( piccswo != NULL )
  878. {
  879. piccswo->Release();
  880. } // if:
  881. punk->Release();
  882. Exit:
  883. HRETURN( hr );
  884. } //*** CEnumPhysicalDisks::HrCreateAndAddDiskToArray
  885. /////////////////////////////////////////////////////////////////////////////
  886. //++
  887. //
  888. // CEnumPhysicalDisks::HrPruneSystemDisks
  889. //
  890. // Description:
  891. // Prune all system disks from the list. System disks are disks that
  892. // are booted, are running the OS, or have page files.
  893. //
  894. // Arguments:
  895. //
  896. //
  897. // Return Value:
  898. // S_OK
  899. // Success
  900. //
  901. // E_OUTOFMEMORY
  902. // Couldn't allocate memeory.
  903. //
  904. // Remarks:
  905. //
  906. //--
  907. //////////////////////////////////////////////////////////////////////////////
  908. HRESULT
  909. CEnumPhysicalDisks::HrPruneSystemDisks( void )
  910. {
  911. TraceFunc( "" );
  912. HRESULT hr = S_OK;
  913. ULONG idx;
  914. ULONG ulSCSIBus;
  915. ULONG ulSCSIPort;
  916. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  917. IUnknown * punk;
  918. ULONG cRemoved = 0;
  919. ULONG cTemp = 0;
  920. bool fSystemAndBootTheSame = ( m_bstrSystemLogicalDisk != NULL ) ? ( m_bstrBootLogicalDisk[ 0 ] == m_bstrSystemLogicalDisk[ 0 ] ) : false;
  921. WCHAR szPageFileDisks[ 26 ];
  922. int cPageFileDisks = 0;
  923. int idxPageFileDisk;
  924. bool fPruneBus = false;
  925. hr = STHR( HrIsSystemBusManaged() );
  926. if ( FAILED( hr ) )
  927. {
  928. goto Cleanup;
  929. } // if:
  930. //
  931. // If the system bus is not managed then we need to prune the disks on those buses
  932. // that contain system, boot, and pagefile disks.
  933. //
  934. if ( hr == S_FALSE )
  935. {
  936. fPruneBus = true;
  937. } // if:
  938. //
  939. // Prune the disks on the system buses. If the system disks are IDE they won't
  940. // be in the list.
  941. //
  942. //
  943. // Find the boot disk
  944. //
  945. hr = STHR( HrFindDiskWithLogicalDisk( m_bstrBootLogicalDisk[ 0 ], &idx ) );
  946. if ( FAILED( hr ) )
  947. {
  948. goto Cleanup;
  949. } // if:
  950. if ( hr == S_OK )
  951. {
  952. //
  953. // Should we prune the whole bus, or just the boot disk itself?
  954. //
  955. if ( fPruneBus )
  956. {
  957. hr = THR( HrGetSCSIInfo( idx, &ulSCSIBus, &ulSCSIPort ) );
  958. if ( FAILED( hr ) )
  959. {
  960. goto Cleanup;
  961. } // if:
  962. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Pruning_Boot_Disk_Bus, IDS_INFO_PRUNING_BOOTDISK_BUS, hr );
  963. hr = THR( HrPruneDisks( ulSCSIBus, ulSCSIPort, &cTemp, IDS_INFO_BOOTDISK_PRUNED ) );
  964. if ( FAILED( hr ) )
  965. {
  966. goto Cleanup;
  967. } // if:
  968. cRemoved += cTemp;
  969. } // if:
  970. else
  971. {
  972. RemoveDiskFromArray( idx );
  973. cRemoved++;
  974. } // else:
  975. } // if:
  976. //
  977. // Prune the system disk bus if it is not the same as the boot disk bus.
  978. //
  979. if ( !fSystemAndBootTheSame )
  980. {
  981. if ( m_bstrSystemLogicalDisk != NULL )
  982. {
  983. Assert( m_bstrSystemWMIDeviceID == NULL );
  984. hr = STHR( HrFindDiskWithLogicalDisk( m_bstrSystemLogicalDisk[ 0 ], &idx ) );
  985. } // if:
  986. else
  987. {
  988. Assert( m_bstrSystemLogicalDisk == NULL );
  989. hr = STHR( HrFindDiskWithWMIDeviceID( m_bstrSystemWMIDeviceID, &idx ) );
  990. } // else:
  991. if ( FAILED( hr ) )
  992. {
  993. goto Cleanup;
  994. } // if:
  995. if ( hr == S_OK )
  996. {
  997. //
  998. // Should we prune the whole bus, or just the system disk itself?
  999. //
  1000. if ( fPruneBus )
  1001. {
  1002. hr = THR( HrGetSCSIInfo( idx, &ulSCSIBus, &ulSCSIPort ) );
  1003. if ( FAILED( hr ) )
  1004. {
  1005. goto Cleanup;
  1006. } // if:
  1007. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Pruning_System_Disk_Bus, IDS_INFO_PRUNING_SYSTEMDISK_BUS, hr );
  1008. hr = THR( HrPruneDisks( ulSCSIBus, ulSCSIPort, &cTemp, IDS_INFO_SYSTEMDISK_PRUNED ) );
  1009. if ( FAILED( hr ) )
  1010. {
  1011. goto Cleanup;
  1012. } // if:
  1013. cRemoved += cTemp;
  1014. } // if:
  1015. else
  1016. {
  1017. RemoveDiskFromArray( idx );
  1018. cRemoved++;
  1019. } // else:
  1020. } // if:
  1021. } // if:
  1022. //
  1023. // Prune the bus with disks that have paging files.
  1024. //
  1025. hr = THR( HrGetPageFileLogicalDisks( m_picccCallback, m_pIWbemServices, szPageFileDisks, &cPageFileDisks ) );
  1026. if ( FAILED( hr ) )
  1027. {
  1028. goto Cleanup;
  1029. } // if:
  1030. if ( cPageFileDisks > 0 )
  1031. {
  1032. for ( idxPageFileDisk = 0; idxPageFileDisk < cPageFileDisks; idxPageFileDisk++ )
  1033. {
  1034. hr = STHR( HrFindDiskWithLogicalDisk( szPageFileDisks[ idxPageFileDisk ], &idx ) );
  1035. if ( FAILED( hr ) )
  1036. {
  1037. goto Cleanup;
  1038. } // if:
  1039. if ( hr == S_OK )
  1040. {
  1041. //
  1042. // Should we prune the whole bus, or just the system disk itself?
  1043. //
  1044. if ( fPruneBus )
  1045. {
  1046. hr = THR( HrGetSCSIInfo( idx, &ulSCSIBus, &ulSCSIPort ) );
  1047. if ( FAILED( hr ) )
  1048. {
  1049. goto Cleanup;
  1050. } // if:
  1051. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_Pruning_PageFile_Disk_Bus, IDS_INFO_PRUNING_PAGEFILEDISK_BUS, hr );
  1052. hr = THR( HrPruneDisks( ulSCSIBus, ulSCSIPort, &cTemp, IDS_INFO_PAGEFILEDISK_PRUNED ) );
  1053. if ( FAILED( hr ) )
  1054. {
  1055. goto Cleanup;
  1056. } // if:
  1057. cRemoved += cTemp;
  1058. } // if:
  1059. else
  1060. {
  1061. RemoveDiskFromArray( idx );
  1062. cRemoved++;
  1063. } // else:
  1064. } // if:
  1065. } // for:
  1066. } // if:
  1067. //
  1068. // Last ditch effort to properly set the managed state of the remaining disks.
  1069. //
  1070. for ( idx = 0; ( cRemoved < m_idxNext ) && ( idx < m_idxNext ); idx++ )
  1071. {
  1072. punk = (*m_prgDisks)[ idx ]; // don't ref
  1073. if ( punk != NULL )
  1074. {
  1075. hr = THR( punk->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  1076. if ( FAILED( hr ) )
  1077. {
  1078. LOG_STATUS_REPORT( L"Could not query for the IClusCfgPhysicalDiskProperties interface.", hr );
  1079. goto Cleanup;
  1080. } // if:
  1081. //
  1082. // Give the disk a chance to figure out for itself if it should be managed.
  1083. //
  1084. hr = STHR( piccpdp->CanBeManaged() );
  1085. if ( FAILED( hr ) )
  1086. {
  1087. goto Cleanup;
  1088. } // if:
  1089. piccpdp->Release();
  1090. piccpdp = NULL;
  1091. } // if:
  1092. } // for:
  1093. //
  1094. // Minor optimization. If we removed all of the elements reset the enum next to 0.
  1095. //
  1096. if ( cRemoved == m_idxNext )
  1097. {
  1098. m_idxNext = 0;
  1099. } // if:
  1100. hr = S_OK;
  1101. Cleanup:
  1102. if ( piccpdp != NULL )
  1103. {
  1104. piccpdp->Release();
  1105. } // if:
  1106. HRETURN( hr );
  1107. } //*** CEnumPhysicalDisks::HrPruneSystemDisks
  1108. /////////////////////////////////////////////////////////////////////////////
  1109. //++
  1110. //
  1111. // CEnumPhysicalDisks::IsDiskSCSI
  1112. //
  1113. // Description:
  1114. //
  1115. // Arguments:
  1116. //
  1117. //
  1118. // Return Value:
  1119. // S_OK
  1120. // Disk is SCSI.
  1121. //
  1122. // S_FALSE
  1123. // Disk is not SCSI.
  1124. //
  1125. // E_OUTOFMEMORY
  1126. // Couldn't allocate memeory.
  1127. //
  1128. // Remarks:
  1129. //
  1130. //--
  1131. //////////////////////////////////////////////////////////////////////////////
  1132. HRESULT
  1133. CEnumPhysicalDisks::IsDiskSCSI( IWbemClassObject * pDiskIn )
  1134. {
  1135. TraceFunc( "" );
  1136. Assert( pDiskIn != NULL );
  1137. HRESULT hr;
  1138. VARIANT var;
  1139. VariantInit( &var );
  1140. hr = THR( HrGetWMIProperty( pDiskIn, L"InterfaceType", VT_BSTR, &var ) );
  1141. if ( SUCCEEDED( hr ) )
  1142. {
  1143. if ( ( wcscmp( L"SCSI", var.bstrVal ) == 0 ) )
  1144. {
  1145. hr = S_OK;
  1146. } // if:
  1147. else
  1148. {
  1149. hr = S_FALSE;
  1150. } // else:
  1151. } // if:
  1152. VariantClear( &var );
  1153. HRETURN( hr );
  1154. } //*** CEnumPhysicalDisks::IsDiskSCSI
  1155. /////////////////////////////////////////////////////////////////////////////
  1156. //++
  1157. //
  1158. // CEnumPhysicalDisks:HrAddDiskToArray
  1159. //
  1160. // Description:
  1161. // Add the passed in disk to the array of punks that holds the disks.
  1162. //
  1163. // Arguments:
  1164. //
  1165. //
  1166. // Return Value:
  1167. // S_OK
  1168. // Success
  1169. //
  1170. // E_OUTOFMEMORY
  1171. // Couldn't allocate memeory.
  1172. //
  1173. // Remarks:
  1174. // None.
  1175. //
  1176. //--
  1177. //////////////////////////////////////////////////////////////////////////////
  1178. HRESULT
  1179. CEnumPhysicalDisks::HrAddDiskToArray( IUnknown * punkIn )
  1180. {
  1181. TraceFunc( "" );
  1182. Assert( punkIn != NULL );
  1183. HRESULT hr = S_OK;
  1184. IUnknown * ((*prgpunks)[]) = NULL;
  1185. prgpunks = (IUnknown *((*)[])) TraceReAlloc( m_prgDisks, sizeof( IUnknown * ) * ( m_idxNext + 1 ), HEAP_ZERO_MEMORY );
  1186. if ( prgpunks == NULL )
  1187. {
  1188. hr = THR( E_OUTOFMEMORY );
  1189. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrAddDiskToArray, IDS_ERROR_OUTOFMEMORY, hr );
  1190. goto Cleanup;
  1191. } // if:
  1192. m_prgDisks = prgpunks;
  1193. (*m_prgDisks)[ m_idxNext++ ] = punkIn;
  1194. punkIn->AddRef();
  1195. m_cDiskCount += 1;
  1196. Cleanup:
  1197. HRETURN( hr );
  1198. } //*** CEnumPhysicalDisks::HrAddDiskToArray
  1199. /////////////////////////////////////////////////////////////////////////////
  1200. //++
  1201. //
  1202. // CEnumPhysicalDisks:HrFixupDisks
  1203. //
  1204. // Description:
  1205. // Tweak the disks to better reflect how they are managed by this node.
  1206. //
  1207. // Arguments:
  1208. // None.
  1209. //
  1210. // Return Value:
  1211. // S_OK
  1212. // Success.
  1213. //
  1214. // Win32 Error
  1215. // something failed.
  1216. //
  1217. // Remarks:
  1218. // None.
  1219. //
  1220. //--
  1221. //////////////////////////////////////////////////////////////////////////////
  1222. HRESULT
  1223. CEnumPhysicalDisks::HrFixupDisks( void )
  1224. {
  1225. TraceFunc( "" );
  1226. HRESULT hr;
  1227. ULONG idx;
  1228. IUnknown * punk = NULL;
  1229. IClusCfgManagedResourceInfo * piccmri = NULL;
  1230. //
  1231. // KB: 14-JUN-2000 GalenB
  1232. //
  1233. // Clear the managed bit on all remaing disks. These bits will be turned
  1234. // back on for the disks this node owns. That happens in
  1235. // HrNodeResourceCallback().
  1236. //
  1237. //
  1238. // BUGBUG: 02-MAY-2001 GalenB
  1239. //
  1240. // Hmmm... Maybe clearing the managed state from all disks is a mistake. What if we
  1241. // have new disks that are not already in the cluster for this clustered node?
  1242. //
  1243. for ( idx = 0; idx < m_idxNext; idx++ )
  1244. {
  1245. punk = (*m_prgDisks)[ idx ]; // don't ref
  1246. if ( punk != NULL )
  1247. {
  1248. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceInfo, &piccmri ) );
  1249. if ( FAILED( hr ) )
  1250. {
  1251. goto Cleanup;
  1252. } // if:
  1253. hr = THR( piccmri->SetManaged( false ) );
  1254. if ( FAILED( hr ) )
  1255. {
  1256. goto Cleanup;
  1257. } // if:
  1258. piccmri->Release();
  1259. piccmri = NULL;
  1260. } // if:
  1261. } // for:
  1262. hr = THR( HrEnumNodeResources( m_bstrNodeName ) );
  1263. Cleanup:
  1264. if ( piccmri != NULL )
  1265. {
  1266. piccmri->Release();
  1267. } // if:
  1268. HRETURN( hr );
  1269. } //*** CEnumPhysicalDisks::HrFixupDisks
  1270. /////////////////////////////////////////////////////////////////////////////
  1271. //++
  1272. //
  1273. // CEnumPhysicalDisks:HrNodeResourceCallback
  1274. //
  1275. // Description:
  1276. // Called by CClusterUtils::HrEnumNodeResources() when it finds a
  1277. // resource for this node.
  1278. //
  1279. // Arguments:
  1280. //
  1281. //
  1282. // Return Value:
  1283. // S_OK
  1284. // Success.
  1285. //
  1286. // Win32 Error
  1287. // something failed.
  1288. //
  1289. // Remarks:
  1290. // None.
  1291. //
  1292. //--
  1293. //////////////////////////////////////////////////////////////////////////////
  1294. HRESULT
  1295. CEnumPhysicalDisks::HrNodeResourceCallback(
  1296. HCLUSTER hClusterIn,
  1297. HRESOURCE hResourceIn
  1298. )
  1299. {
  1300. TraceFunc( "" );
  1301. HRESULT hr = S_OK;
  1302. CLUS_SCSI_ADDRESS csa;
  1303. DWORD dwSignature;
  1304. BOOL fIsQuorum;
  1305. BSTR bstrResourceName = NULL;
  1306. hr = STHR( HrIsResourceOfType( hResourceIn, L"Physical Disk" ) );
  1307. if ( FAILED( hr ) )
  1308. {
  1309. goto Cleanup;
  1310. } // if:
  1311. //
  1312. // If this resource is not a physical disk then we simply want to
  1313. // skip it.
  1314. //
  1315. if ( hr == S_FALSE )
  1316. {
  1317. goto Cleanup;
  1318. } // if:
  1319. hr = STHR( HrIsCoreResource( hResourceIn ) );
  1320. if ( FAILED( hr ) )
  1321. {
  1322. goto Cleanup;
  1323. } // if:
  1324. fIsQuorum = ( hr == S_OK );
  1325. hr = THR( HrGetClusterDiskInfo( hClusterIn, hResourceIn, &csa, &dwSignature ) );
  1326. if ( FAILED( hr ) )
  1327. {
  1328. goto Cleanup;
  1329. } // if:
  1330. hr = THR( HrGetClusterProperties( hResourceIn, &bstrResourceName ) );
  1331. if ( FAILED( hr ) )
  1332. {
  1333. goto Cleanup;
  1334. } // if:
  1335. hr = THR( HrSetThisDiskToBeManaged( csa.TargetId, csa.Lun, fIsQuorum, bstrResourceName, dwSignature ) );
  1336. Cleanup:
  1337. TraceSysFreeString( bstrResourceName );
  1338. HRETURN( hr );
  1339. } //*** CEnumPhysicalDisks::HrNodeResourceCallback
  1340. /////////////////////////////////////////////////////////////////////////////
  1341. //++
  1342. //
  1343. // CEnumPhysicalDisks:HrGetClusterDiskInfo
  1344. //
  1345. // Description:
  1346. //
  1347. //
  1348. // Arguments:
  1349. //
  1350. //
  1351. // Return Value:
  1352. // S_OK
  1353. // Success.
  1354. //
  1355. // Win32 Error
  1356. // something failed.
  1357. //
  1358. // Remarks:
  1359. // None.
  1360. //
  1361. //--
  1362. //////////////////////////////////////////////////////////////////////////////
  1363. HRESULT
  1364. CEnumPhysicalDisks::HrGetClusterDiskInfo(
  1365. HCLUSTER hClusterIn,
  1366. HRESOURCE hResourceIn,
  1367. CLUS_SCSI_ADDRESS * pcsaOut,
  1368. DWORD * pdwSignatureOut
  1369. )
  1370. {
  1371. TraceFunc( "" );
  1372. HRESULT hr = S_OK;
  1373. DWORD sc;
  1374. CClusPropValueList cpvl;
  1375. CLUSPROP_BUFFER_HELPER cbhValue = { NULL };
  1376. sc = TW32( cpvl.ScGetResourceValueList( hResourceIn, CLUSCTL_RESOURCE_STORAGE_GET_DISK_INFO ) );
  1377. if ( sc != ERROR_SUCCESS )
  1378. {
  1379. goto MakeHr;
  1380. } // if:
  1381. sc = TW32( cpvl.ScMoveToFirstValue() );
  1382. if ( sc != ERROR_SUCCESS )
  1383. {
  1384. goto MakeHr;
  1385. } // if:
  1386. for ( ; ; )
  1387. {
  1388. cbhValue = cpvl;
  1389. switch ( cbhValue.pSyntax->dw )
  1390. {
  1391. case CLUSPROP_SYNTAX_PARTITION_INFO :
  1392. {
  1393. break;
  1394. } // case: CLUSPROP_SYNTAX_PARTITION_INFO
  1395. case CLUSPROP_SYNTAX_DISK_SIGNATURE :
  1396. {
  1397. *pdwSignatureOut = cbhValue.pDiskSignatureValue->dw;
  1398. break;
  1399. } // case: CLUSPROP_SYNTAX_DISK_SIGNATURE
  1400. case CLUSPROP_SYNTAX_SCSI_ADDRESS :
  1401. {
  1402. pcsaOut->dw = cbhValue.pScsiAddressValue->dw;
  1403. break;
  1404. } // case: CLUSPROP_SYNTAXscSI_ADDRESS
  1405. case CLUSPROP_SYNTAX_DISK_NUMBER :
  1406. {
  1407. break;
  1408. } // case: CLUSPROP_SYNTAX_DISK_NUMBER
  1409. } // switch:
  1410. sc = cpvl.ScMoveToNextValue();
  1411. if ( sc == ERROR_SUCCESS )
  1412. {
  1413. continue;
  1414. } // if:
  1415. if ( sc == ERROR_NO_MORE_ITEMS )
  1416. {
  1417. break;
  1418. } // if: error occurred moving to the next value
  1419. TW32( sc );
  1420. goto MakeHr;
  1421. } // for:
  1422. goto Cleanup;
  1423. MakeHr:
  1424. hr = HRESULT_FROM_WIN32( sc );
  1425. Cleanup:
  1426. HRETURN( hr );
  1427. } //*** CEnumPhysicalDisks::HrGetClusterDiskInfo
  1428. /////////////////////////////////////////////////////////////////////////////
  1429. //++
  1430. //
  1431. // CEnumPhysicalDisks:HrSetThisDiskToBeManaged
  1432. //
  1433. // Description:
  1434. //
  1435. //
  1436. // Arguments:
  1437. //
  1438. //
  1439. // Return Value:
  1440. // S_OK
  1441. // Success.
  1442. //
  1443. // Win32 Error
  1444. // something failed.
  1445. //
  1446. // Remarks:
  1447. // None.
  1448. //
  1449. //--
  1450. //////////////////////////////////////////////////////////////////////////////
  1451. HRESULT
  1452. CEnumPhysicalDisks::HrSetThisDiskToBeManaged(
  1453. ULONG ulSCSITidIn
  1454. , ULONG ulSCSILunIn
  1455. , BOOL fIsQuorumIn
  1456. , BSTR bstrResourceNameIn
  1457. , DWORD dwSignatureIn
  1458. )
  1459. {
  1460. TraceFunc( "" );
  1461. HRESULT hr = S_OK;
  1462. ULONG idx;
  1463. IUnknown * punk = NULL;
  1464. IClusCfgManagedResourceInfo * piccmri = NULL;
  1465. WCHAR sz[ 64 ];
  1466. BSTR bstrUID = NULL;
  1467. DWORD dwSignature;
  1468. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  1469. _snwprintf( sz, ARRAYSIZE( sz ), L"SCSI Tid %ld, SCSI Lun %ld", ulSCSITidIn, ulSCSILunIn );
  1470. //
  1471. // KB: 15-JUN-2000 GalenB
  1472. //
  1473. // Find the disk that has the passes in TID and Lun and set it
  1474. // to be managed.
  1475. //
  1476. for ( idx = 0; idx < m_idxNext; idx++ )
  1477. {
  1478. punk = (*m_prgDisks)[ idx ]; // don't ref
  1479. if ( punk != NULL )
  1480. {
  1481. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceInfo, &piccmri ) );
  1482. if ( FAILED( hr ) )
  1483. {
  1484. goto Cleanup;
  1485. } // if:
  1486. hr = THR( piccmri->GetUID( &bstrUID ) );
  1487. if ( FAILED( hr ) )
  1488. {
  1489. goto Cleanup;
  1490. } // if:
  1491. TraceMemoryAddBSTR( bstrUID );
  1492. if ( _wcsicmp( bstrUID, sz ) == 0 )
  1493. {
  1494. hr = THR( piccmri->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  1495. if ( FAILED( hr ) )
  1496. {
  1497. goto Cleanup;
  1498. } // if:
  1499. hr = THR( piccpdp->HrGetSignature( &dwSignature ) );
  1500. if ( FAILED( hr ) )
  1501. {
  1502. goto Cleanup;
  1503. } // if:
  1504. hr = THR( piccpdp->HrSetFriendlyName( bstrResourceNameIn ) );
  1505. if ( FAILED( hr ) )
  1506. {
  1507. goto Cleanup;
  1508. } // if:
  1509. piccpdp->Release();
  1510. piccpdp = NULL;
  1511. //
  1512. // May want to do more with this later...
  1513. //
  1514. Assert( dwSignatureIn == dwSignature );
  1515. hr = THR( piccmri->SetManaged( TRUE ) );
  1516. if ( FAILED( hr ) )
  1517. {
  1518. goto Cleanup;
  1519. } // if:
  1520. hr = THR( piccmri->SetQuorumedDevice( fIsQuorumIn ) );
  1521. if ( FAILED( hr ) )
  1522. {
  1523. goto Cleanup;
  1524. } // if:
  1525. break;
  1526. } // if:
  1527. TraceSysFreeString( bstrUID );
  1528. bstrUID = NULL;
  1529. piccmri->Release();
  1530. piccmri = NULL;
  1531. } // if:
  1532. } // for:
  1533. Cleanup:
  1534. if ( piccpdp != NULL )
  1535. {
  1536. piccpdp->Release();
  1537. } // if:
  1538. if ( piccmri != NULL )
  1539. {
  1540. piccmri->Release();
  1541. } // if:
  1542. TraceSysFreeString( bstrUID );
  1543. HRETURN( hr );
  1544. } //*** CEnumPhysicalDisks::HrSetThisDiskToBeManaged
  1545. /////////////////////////////////////////////////////////////////////////////
  1546. //++
  1547. //
  1548. // CEnumPhysicalDisks:HrFindDiskWithLogicalDisk
  1549. //
  1550. // Description:
  1551. // Find the disk with the passed in logical disk ID.
  1552. //
  1553. // Arguments:
  1554. // None.
  1555. //
  1556. // Return Value:
  1557. // S_OK
  1558. // Success. Found the disk.
  1559. //
  1560. // S_FALSE
  1561. // Success. Did not find the disk.
  1562. //
  1563. // Win32 Error
  1564. // something failed.
  1565. //
  1566. // Remarks:
  1567. // None.
  1568. //
  1569. //--
  1570. //////////////////////////////////////////////////////////////////////////////
  1571. HRESULT
  1572. CEnumPhysicalDisks::HrFindDiskWithLogicalDisk(
  1573. WCHAR cLogicalDiskIn,
  1574. ULONG * pidxDiskOut
  1575. )
  1576. {
  1577. TraceFunc( "" );
  1578. Assert( pidxDiskOut != NULL );
  1579. HRESULT hr = S_OK;
  1580. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  1581. ULONG idx;
  1582. bool fFoundIt = false;
  1583. IUnknown * punk;
  1584. for ( idx = 0; idx < m_idxNext; idx++ )
  1585. {
  1586. punk = (*m_prgDisks)[ idx ]; // don't ref
  1587. if ( punk != NULL )
  1588. {
  1589. hr = THR( punk->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  1590. if ( FAILED( hr ) )
  1591. {
  1592. goto Cleanup;
  1593. } // if:
  1594. hr = STHR( piccpdp->IsThisLogicalDisk( cLogicalDiskIn ) );
  1595. if ( FAILED( hr ) )
  1596. {
  1597. goto Cleanup;
  1598. } // if:
  1599. if ( hr == S_OK )
  1600. {
  1601. fFoundIt = true;
  1602. break;
  1603. } // if:
  1604. piccpdp->Release();
  1605. piccpdp = NULL;
  1606. } // if:
  1607. } // for:
  1608. if ( !fFoundIt )
  1609. {
  1610. hr = S_FALSE;
  1611. } // if:
  1612. if ( pidxDiskOut != NULL )
  1613. {
  1614. *pidxDiskOut = idx;
  1615. } // if:
  1616. Cleanup:
  1617. if ( piccpdp != NULL )
  1618. {
  1619. piccpdp->Release();
  1620. } // if:
  1621. HRETURN( hr );
  1622. } //*** CEnumPhysicalDisks::HrFindDiskWithLogicalDisk
  1623. /////////////////////////////////////////////////////////////////////////////
  1624. //++
  1625. //
  1626. // CEnumPhysicalDisks:HrGetSCSIInfo
  1627. //
  1628. // Description:
  1629. // Get the SCSI info for the disk at the passed in index.
  1630. //
  1631. // Arguments:
  1632. // None.
  1633. //
  1634. // Return Value:
  1635. // S_OK
  1636. // Success.
  1637. //
  1638. // Win32 Error
  1639. // something failed.
  1640. //
  1641. // Remarks:
  1642. // None.
  1643. //
  1644. //--
  1645. //////////////////////////////////////////////////////////////////////////////
  1646. HRESULT
  1647. CEnumPhysicalDisks::HrGetSCSIInfo(
  1648. ULONG idxDiskIn,
  1649. ULONG * pulSCSIBusOut,
  1650. ULONG * pulSCSIPortOut
  1651. )
  1652. {
  1653. TraceFunc( "" );
  1654. Assert( pulSCSIBusOut != NULL );
  1655. Assert( pulSCSIPortOut != NULL );
  1656. HRESULT hr = S_OK;
  1657. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  1658. hr = THR( ((*m_prgDisks)[ idxDiskIn ])->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  1659. if ( FAILED( hr ) )
  1660. {
  1661. goto Cleanup;
  1662. } // if:
  1663. hr = THR( piccpdp->HrGetSCSIBus( pulSCSIBusOut ) );
  1664. if ( FAILED( hr ) )
  1665. {
  1666. goto Cleanup;
  1667. } // if:
  1668. hr = THR( piccpdp->HrGetSCSIPort( pulSCSIPortOut ) );
  1669. Cleanup:
  1670. if ( piccpdp != NULL )
  1671. {
  1672. piccpdp->Release();
  1673. } // if:
  1674. HRETURN( hr );
  1675. } //*** CEnumPhysicalDisks::HrGetSCSIInfo
  1676. /////////////////////////////////////////////////////////////////////////////
  1677. //++
  1678. //
  1679. // CEnumPhysicalDisks:HrPruneDisks
  1680. //
  1681. // Description:
  1682. // Get the SCSI info for the disk at the passed in index.
  1683. //
  1684. // Arguments:
  1685. // None.
  1686. //
  1687. // Return Value:
  1688. // S_OK
  1689. // Success.
  1690. //
  1691. // Win32 Error
  1692. // something failed.
  1693. //
  1694. // Remarks:
  1695. // None.
  1696. //
  1697. //--
  1698. //////////////////////////////////////////////////////////////////////////////
  1699. HRESULT
  1700. CEnumPhysicalDisks::HrPruneDisks(
  1701. ULONG ulSCSIBusIn
  1702. , ULONG ulSCSIPortIn
  1703. , ULONG * pulRemovedOut
  1704. , int nMsgId
  1705. )
  1706. {
  1707. TraceFunc( "" );
  1708. Assert( pulRemovedOut != NULL );
  1709. HRESULT hr = S_OK;
  1710. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  1711. ULONG idx;
  1712. IUnknown * punk;
  1713. ULONG ulSCSIBus;
  1714. ULONG ulSCSIPort;
  1715. ULONG cRemoved = 0;
  1716. for ( idx = 0; idx < m_idxNext; idx++ )
  1717. {
  1718. punk = (*m_prgDisks)[ idx ]; // don't ref
  1719. if ( punk != NULL )
  1720. {
  1721. hr = THR( punk->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  1722. if ( FAILED( hr ) )
  1723. {
  1724. goto Cleanup;
  1725. } // if:
  1726. hr = THR( piccpdp->HrGetSCSIBus( &ulSCSIBus ) );
  1727. if ( FAILED( hr ) )
  1728. {
  1729. goto Cleanup;
  1730. } // if:
  1731. hr = THR( piccpdp->HrGetSCSIPort( &ulSCSIPort ) );
  1732. if ( FAILED( hr ) )
  1733. {
  1734. goto Cleanup;
  1735. } // if:
  1736. if ( ( ulSCSIBusIn == ulSCSIBus ) && ( ulSCSIPortIn == ulSCSIPort ) )
  1737. {
  1738. BSTR bstr = NULL;
  1739. IClusCfgManagedResourceInfo * piccmri = NULL;
  1740. LogPrunedDisk( punk, ulSCSIBusIn, ulSCSIPortIn );
  1741. THR( ((*m_prgDisks)[ idx ])->TypeSafeQI( IClusCfgManagedResourceInfo, &piccmri ) );
  1742. THR( piccmri->GetName( &bstr ) );
  1743. if ( piccmri != NULL )
  1744. {
  1745. piccmri->Release();
  1746. } // if:
  1747. TraceMemoryAddBSTR( bstr );
  1748. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_Pruned_Disk_From_Bus, nMsgId, bstr != NULL ? bstr : L"????", hr );
  1749. RemoveDiskFromArray( idx );
  1750. cRemoved++;
  1751. TraceSysFreeString( bstr );
  1752. } // if:
  1753. piccpdp->Release();
  1754. piccpdp = NULL;
  1755. } // if:
  1756. } // for:
  1757. if ( pulRemovedOut != NULL )
  1758. {
  1759. *pulRemovedOut = cRemoved;
  1760. } // if:
  1761. Cleanup:
  1762. if ( piccpdp != NULL )
  1763. {
  1764. piccpdp->Release();
  1765. } // if:
  1766. HRETURN( hr );
  1767. } //*** CEnumPhysicalDisks::HrPruneDisks
  1768. /////////////////////////////////////////////////////////////////////////////
  1769. //++
  1770. //
  1771. // CEnumPhysicalDisks:LogPrunedDisk
  1772. //
  1773. // Description:
  1774. // Get the SCSI info for the disk at the passed in index.
  1775. //
  1776. // Arguments:
  1777. // None.
  1778. //
  1779. // Return Value:
  1780. // S_OK
  1781. // Success.
  1782. //
  1783. // Win32 Error
  1784. // something failed.
  1785. //
  1786. // Remarks:
  1787. // None.
  1788. //
  1789. //--
  1790. //////////////////////////////////////////////////////////////////////////////
  1791. void
  1792. CEnumPhysicalDisks::LogPrunedDisk(
  1793. IUnknown * punkIn,
  1794. ULONG ulSCSIBusIn,
  1795. ULONG ulSCSIPortIn
  1796. )
  1797. {
  1798. TraceFunc( "" );
  1799. Assert( punkIn != NULL );
  1800. HRESULT hr = S_OK;
  1801. IClusCfgManagedResourceInfo * piccmri = NULL;
  1802. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  1803. BSTR bstrName = NULL;
  1804. BSTR bstrUID = NULL;
  1805. BSTR bstr = NULL;
  1806. hr = THR( punkIn->TypeSafeQI( IClusCfgManagedResourceInfo, &piccmri ) );
  1807. if ( SUCCEEDED( hr ) )
  1808. {
  1809. hr = THR( piccmri->GetUID( &bstrUID ) );
  1810. piccmri->Release();
  1811. } // if:
  1812. if ( FAILED( hr ) )
  1813. {
  1814. bstrUID = TraceSysAllocString( L"<Unknown>" );
  1815. } // if:
  1816. else
  1817. {
  1818. TraceMemoryAddBSTR( bstrUID );
  1819. } // else:
  1820. hr = THR( punkIn->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  1821. if ( SUCCEEDED( hr ) )
  1822. {
  1823. hr = THR( piccpdp->HrGetDeviceID( &bstrName ) );
  1824. piccpdp->Release();
  1825. } // if:
  1826. if ( FAILED( hr ) )
  1827. {
  1828. bstrName = TraceSysAllocString( L"<Unknown>" );
  1829. } // if:
  1830. hr = THR( HrFormatStringIntoBSTR(
  1831. L"Pruning SCSI disk '%1!ws!', on Bus '%2!d!' and Port '%3!d!'; at '%4!ws!'"
  1832. , &bstr
  1833. , bstrName
  1834. , ulSCSIBusIn
  1835. , ulSCSIPortIn
  1836. , bstrUID
  1837. ) );
  1838. if ( FAILED( hr ) )
  1839. {
  1840. goto Cleanup;
  1841. } // if:
  1842. LOG_STATUS_REPORT( bstr, hr );
  1843. Cleanup:
  1844. TraceSysFreeString( bstrName );
  1845. TraceSysFreeString( bstrUID );
  1846. TraceSysFreeString( bstr );
  1847. TraceFuncExit();
  1848. } //*** CEnumPhysicalDisks::LogPrunedDisk
  1849. /////////////////////////////////////////////////////////////////////////////
  1850. //++
  1851. //
  1852. // CEnumPhysicalDisks:HrIsLogicalDiskNTFS
  1853. //
  1854. // Description:
  1855. // Is the passed in logical disk NTFS?
  1856. //
  1857. // Arguments:
  1858. // bstrLogicalDiskIn
  1859. //
  1860. // Return Value:
  1861. // S_OK
  1862. // The disk is NTFS.
  1863. //
  1864. // S_FALSE
  1865. // The disk is not NTFS.
  1866. //
  1867. // Win32 Error
  1868. // something failed.
  1869. //
  1870. // Remarks:
  1871. // None.
  1872. //
  1873. //--
  1874. //////////////////////////////////////////////////////////////////////////////
  1875. HRESULT
  1876. CEnumPhysicalDisks::HrIsLogicalDiskNTFS( BSTR bstrLogicalDiskIn )
  1877. {
  1878. TraceFunc1( "bstrLogicalDiskIn = '%ls'", bstrLogicalDiskIn == NULL ? L"<null>" : bstrLogicalDiskIn );
  1879. Assert( bstrLogicalDiskIn != NULL );
  1880. HRESULT hr = S_OK;
  1881. IWbemClassObject * pLogicalDisk = NULL;
  1882. BSTR bstrPath = NULL;
  1883. WCHAR sz[ 64 ];
  1884. VARIANT var;
  1885. size_t cch;
  1886. VariantInit( &var );
  1887. cch = wcslen( bstrLogicalDiskIn );
  1888. if ( cch > 3 )
  1889. {
  1890. hr = THR( E_INVALIDARG );
  1891. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrIsLogicalDiskNTFS_InvalidArg, IDS_ERROR_INVALIDARG, hr );
  1892. goto Cleanup;
  1893. } // if:
  1894. //
  1895. // truncate off any trailing \'s
  1896. //
  1897. if ( bstrLogicalDiskIn[ cch - 1 ] == L'\\' )
  1898. {
  1899. bstrLogicalDiskIn[ cch - 1 ] = '\0';
  1900. } // if:
  1901. //
  1902. // If we got just the logical disk without the trailing colon...
  1903. //
  1904. if ( wcslen( bstrLogicalDiskIn ) == 1 )
  1905. {
  1906. _snwprintf( sz, ARRAYSIZE( sz ), L"Win32_LogicalDisk.DeviceID=\"%s:\"", bstrLogicalDiskIn );
  1907. } // if:
  1908. else
  1909. {
  1910. _snwprintf( sz, ARRAYSIZE( sz ), L"Win32_LogicalDisk.DeviceID=\"%s\"", bstrLogicalDiskIn );
  1911. } // else:
  1912. bstrPath = TraceSysAllocString( sz );
  1913. if ( bstrPath == NULL )
  1914. {
  1915. hr = THR( E_OUTOFMEMORY );
  1916. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrIsLogicalDiskNTFS, IDS_ERROR_OUTOFMEMORY, hr );
  1917. } // if:
  1918. hr = THR( m_pIWbemServices->GetObject( bstrPath, WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &pLogicalDisk, NULL ) );
  1919. if ( FAILED( hr ) )
  1920. {
  1921. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_WMI_Get_LogicalDisk_Failed, IDS_ERROR_WMI_GET_LOGICALDISK_FAILED, bstrLogicalDiskIn, hr );
  1922. goto Cleanup;
  1923. } // if:
  1924. hr = THR( HrGetWMIProperty( pLogicalDisk, L"FileSystem", VT_BSTR, &var ) );
  1925. if (FAILED( hr ) )
  1926. {
  1927. goto Cleanup;
  1928. } // if:
  1929. CharUpper( var.bstrVal );
  1930. if ( wcscmp( var.bstrVal, L"NTFS" ) != 0 )
  1931. {
  1932. hr = S_FALSE;
  1933. } // if:
  1934. Cleanup:
  1935. if ( pLogicalDisk != NULL )
  1936. {
  1937. pLogicalDisk->Release();
  1938. } // if:
  1939. VariantClear( &var );
  1940. TraceSysFreeString( bstrPath );
  1941. HRETURN( hr );
  1942. } //*** CEnumPhysicalDisks::HrIsLogicalDiskNTFS
  1943. /////////////////////////////////////////////////////////////////////////////
  1944. //++
  1945. //
  1946. // CEnumPhysicalDisks:HrLogDiskInfo
  1947. //
  1948. // Description:
  1949. // Write the info about this disk into the log.
  1950. //
  1951. // Arguments:
  1952. // pDiskIn
  1953. //
  1954. // Return Value:
  1955. // S_OK
  1956. //
  1957. // Win32 Error
  1958. // something failed.
  1959. //
  1960. // Remarks:
  1961. // None.
  1962. //
  1963. //--
  1964. //////////////////////////////////////////////////////////////////////////////
  1965. HRESULT
  1966. CEnumPhysicalDisks::HrLogDiskInfo( IWbemClassObject * pDiskIn )
  1967. {
  1968. TraceFunc( "" );
  1969. Assert( pDiskIn != NULL );
  1970. HRESULT hr = S_OK;
  1971. VARIANT varDeviceID;
  1972. VARIANT varSCSIBus;
  1973. VARIANT varSCSIPort;
  1974. VARIANT varSCSILun;
  1975. VARIANT varSCSITid;
  1976. BSTR bstr = NULL;
  1977. VariantInit( &varDeviceID );
  1978. VariantInit( &varSCSIBus );
  1979. VariantInit( &varSCSIPort );
  1980. VariantInit( &varSCSILun );
  1981. VariantInit( &varSCSITid );
  1982. hr = THR( HrGetWMIProperty( pDiskIn, L"DeviceID", VT_BSTR, &varDeviceID ) );
  1983. if ( FAILED( hr ) )
  1984. {
  1985. goto Cleanup;
  1986. } // if:
  1987. hr = STHR( IsDiskSCSI( pDiskIn ) );
  1988. if ( FAILED( hr ) )
  1989. {
  1990. goto Cleanup;
  1991. } // if:
  1992. //
  1993. // Disk is SCSI...
  1994. //
  1995. if ( hr == S_OK )
  1996. {
  1997. hr = THR( HrGetWMIProperty( pDiskIn, L"SCSIBus", VT_I4, &varSCSIBus ) );
  1998. if ( FAILED( hr ) )
  1999. {
  2000. goto Cleanup;
  2001. } // if:
  2002. hr = THR( HrGetWMIProperty( pDiskIn, L"SCSITargetId", VT_I4, &varSCSITid ) );
  2003. if ( FAILED( hr ) )
  2004. {
  2005. goto Cleanup;
  2006. } // if:
  2007. hr = THR( HrGetWMIProperty( pDiskIn, L"SCSILogicalUnit", VT_I4, &varSCSILun ) );
  2008. if ( FAILED( hr ) )
  2009. {
  2010. goto Cleanup;
  2011. } // if:
  2012. hr = THR( HrGetWMIProperty( pDiskIn, L"SCSIPort", VT_I4, &varSCSIPort ) );
  2013. if ( FAILED( hr ) )
  2014. {
  2015. goto Cleanup;
  2016. } // if:
  2017. hr = THR( HrFormatStringIntoBSTR(
  2018. L"Found SCSI disk '%1!ws!' on Bus '%2!d!' and Port '%3!d!'; at TID '%4!d!' and LUN '%5!d!'"
  2019. , &bstr
  2020. , varDeviceID.bstrVal
  2021. , varSCSIBus.iVal
  2022. , varSCSIPort.iVal
  2023. , varSCSITid.iVal
  2024. , varSCSILun.iVal
  2025. ) );
  2026. if ( FAILED( hr ) )
  2027. {
  2028. goto Cleanup;
  2029. } // if:
  2030. LOG_STATUS_REPORT( bstr, hr );
  2031. } // if:
  2032. else
  2033. {
  2034. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_Found_Non_SCSI_Disk, IDS_ERROR_FOUND_NON_SCSI_DISK, varDeviceID.bstrVal, hr );
  2035. } // else:
  2036. Cleanup:
  2037. VariantClear( &varDeviceID );
  2038. VariantClear( &varSCSIBus );
  2039. VariantClear( &varSCSIPort );
  2040. VariantClear( &varSCSILun );
  2041. VariantClear( &varSCSITid );
  2042. TraceSysFreeString( bstr );
  2043. HRETURN( hr );
  2044. } //*** CEnumPhysicalDisks::HrLogDiskInfo
  2045. /////////////////////////////////////////////////////////////////////////////
  2046. //++
  2047. //
  2048. // CEnumPhysicalDisks:HrFindDiskWithWMIDeviceID
  2049. //
  2050. // Description:
  2051. // Find the disk with the passed in WMI device ID.
  2052. //
  2053. // Arguments:
  2054. // None.
  2055. //
  2056. // Return Value:
  2057. // S_OK
  2058. // Success. Found the disk.
  2059. //
  2060. // S_FALSE
  2061. // Success. Did not find the disk.
  2062. //
  2063. // Win32 Error
  2064. // something failed.
  2065. //
  2066. // Remarks:
  2067. // None.
  2068. //
  2069. //--
  2070. //////////////////////////////////////////////////////////////////////////////
  2071. HRESULT
  2072. CEnumPhysicalDisks::HrFindDiskWithWMIDeviceID(
  2073. BSTR bstrWMIDeviceIDIn,
  2074. ULONG * pidxDiskOut
  2075. )
  2076. {
  2077. TraceFunc( "" );
  2078. Assert( pidxDiskOut != NULL );
  2079. HRESULT hr = S_OK;
  2080. IClusCfgPhysicalDiskProperties * piccpdp = NULL;
  2081. ULONG idx;
  2082. bool fFoundIt = false;
  2083. IUnknown * punk;
  2084. BSTR bstrDeviceID = NULL;
  2085. for ( idx = 0; idx < m_idxNext; idx++ )
  2086. {
  2087. punk = (*m_prgDisks)[ idx ]; // don't ref
  2088. if ( punk != NULL )
  2089. {
  2090. hr = THR( punk->TypeSafeQI( IClusCfgPhysicalDiskProperties, &piccpdp ) );
  2091. if ( FAILED( hr ) )
  2092. {
  2093. goto Cleanup;
  2094. } // if:
  2095. hr = STHR( piccpdp->HrGetDeviceID( &bstrDeviceID ) );
  2096. if ( FAILED( hr ) )
  2097. {
  2098. goto Cleanup;
  2099. } // if:
  2100. if ( wcscmp( bstrWMIDeviceIDIn, bstrDeviceID ) == 0 )
  2101. {
  2102. fFoundIt = true;
  2103. break;
  2104. } // if:
  2105. piccpdp->Release();
  2106. piccpdp = NULL;
  2107. TraceSysFreeString( bstrDeviceID );
  2108. bstrDeviceID = NULL;
  2109. } // if:
  2110. } // for:
  2111. if ( !fFoundIt )
  2112. {
  2113. hr = S_FALSE;
  2114. } // if:
  2115. if ( pidxDiskOut != NULL )
  2116. {
  2117. *pidxDiskOut = idx;
  2118. } // if:
  2119. Cleanup:
  2120. if ( piccpdp != NULL )
  2121. {
  2122. piccpdp->Release();
  2123. } // if:
  2124. TraceSysFreeString( bstrDeviceID );
  2125. HRETURN( hr );
  2126. } //*** CEnumPhysicalDisks::HrFindDiskWithWMIDeviceID
  2127. /////////////////////////////////////////////////////////////////////////////
  2128. //++
  2129. //
  2130. // CEnumPhysicalDisks:HrIsSystemBusManaged
  2131. //
  2132. // Description:
  2133. // Is the system bus managed by the cluster service?
  2134. //
  2135. // Arguments:
  2136. // None.
  2137. //
  2138. // Return Value:
  2139. // S_OK
  2140. // Success. The system bus is managed.
  2141. //
  2142. // S_FALSE
  2143. // Success. The system bus is not managed.
  2144. //
  2145. // Win32 Error
  2146. // something failed.
  2147. //
  2148. // Remarks:
  2149. // None.
  2150. //
  2151. //--
  2152. //////////////////////////////////////////////////////////////////////////////
  2153. HRESULT
  2154. CEnumPhysicalDisks::HrIsSystemBusManaged( void )
  2155. {
  2156. TraceFunc( "" );
  2157. HRESULT hr = S_FALSE;
  2158. DWORD sc;
  2159. HKEY hKey = NULL;
  2160. DWORD dwData;
  2161. DWORD cbData = sizeof( dwData );
  2162. sc = RegOpenKeyEx( HKEY_LOCAL_MACHINE, L"SYSTEM\\CURRENTCONTROLSET\\SERVICES\\ClusSvc\\Parameters", 0, KEY_READ, &hKey );
  2163. if ( sc == ERROR_FILE_NOT_FOUND )
  2164. {
  2165. goto Cleanup; // not yet a cluster node. Return S_FALSE.
  2166. } // if:
  2167. if ( sc != ERROR_SUCCESS )
  2168. {
  2169. TW32( sc );
  2170. LogMsg( L"[SRV] RegOpenKeyEx() failed. (hr = %#08x)", hr );
  2171. goto Win32Error;
  2172. } // if:
  2173. sc = RegQueryValueEx( hKey, L"ManageDisksOnSystemBuses", NULL, NULL, (LPBYTE) &dwData, &cbData );
  2174. if ( sc == ERROR_FILE_NOT_FOUND )
  2175. {
  2176. goto Cleanup; // value not found. Return S_FALSE.
  2177. } // if:
  2178. if ( sc != ERROR_SUCCESS )
  2179. {
  2180. TW32( sc );
  2181. LogMsg( L"[SRV] RegQueryValueEx() failed. (hr = %#08x)", hr );
  2182. goto Win32Error;
  2183. } // if:
  2184. if ( dwData > 0 )
  2185. {
  2186. hr = S_OK;
  2187. } // if:
  2188. goto Cleanup;
  2189. Win32Error:
  2190. hr = HRESULT_FROM_WIN32( sc );
  2191. Cleanup:
  2192. if ( hKey != NULL )
  2193. {
  2194. RegCloseKey( hKey );
  2195. } // if:
  2196. HRETURN( hr );
  2197. } //*** CEnumPhysicalDisks::HrIsSystemBusManaged
  2198. /////////////////////////////////////////////////////////////////////////////
  2199. //++
  2200. //
  2201. // CEnumPhysicalDisks:HrGetClusterProperties
  2202. //
  2203. // Description:
  2204. // Return the asked for cluster properties.
  2205. //
  2206. // Arguments:
  2207. //
  2208. //
  2209. // Return Value:
  2210. // S_OK
  2211. // Success.
  2212. //
  2213. // Win32 Error
  2214. // something failed.
  2215. //
  2216. // Remarks:
  2217. // None.
  2218. //
  2219. //--
  2220. //////////////////////////////////////////////////////////////////////////////
  2221. HRESULT
  2222. CEnumPhysicalDisks::HrGetClusterProperties(
  2223. HRESOURCE hResourceIn
  2224. , BSTR * pbstrResourceNameOut
  2225. )
  2226. {
  2227. TraceFunc( "" );
  2228. Assert( pbstrResourceNameOut != NULL );
  2229. HRESULT hr = S_OK;
  2230. CClusPropList cpl;
  2231. CLUSPROP_BUFFER_HELPER cpbh;
  2232. DWORD sc;
  2233. sc = TW32( cpl.ScGetResourceProperties( hResourceIn, CLUSCTL_RESOURCE_GET_RO_COMMON_PROPERTIES ) );
  2234. if ( sc != ERROR_SUCCESS )
  2235. {
  2236. goto MakeHr;
  2237. } // if:
  2238. sc = TW32( cpl.ScMoveToPropertyByName( L"Name" ) );
  2239. if ( sc != ERROR_SUCCESS )
  2240. {
  2241. goto MakeHr;
  2242. } // if:
  2243. cpbh = cpl.CbhCurrentValue();
  2244. Assert( cpbh.pSyntax->dw == CLUSPROP_SYNTAX_LIST_VALUE_SZ );
  2245. if ( ( cpbh.pStringValue->sz != NULL ) && ( wcscmp( cpbh.pStringValue->sz, L"" ) != 0 ) )
  2246. {
  2247. *pbstrResourceNameOut = TraceSysAllocString( cpbh.pStringValue->sz );
  2248. if ( *pbstrResourceNameOut == NULL )
  2249. {
  2250. hr = THR( E_OUTOFMEMORY );
  2251. goto Cleanup;
  2252. } // if:
  2253. } // if:
  2254. else
  2255. {
  2256. hr = THR( E_UNEXPECTED );
  2257. LOG_STATUS_REPORT( L"The name of a physical disk resource was empty!", hr );
  2258. } // else:
  2259. goto Cleanup;
  2260. MakeHr:
  2261. hr = HRESULT_FROM_WIN32( sc );
  2262. Cleanup:
  2263. HRETURN( hr );
  2264. } //*** CEnumPhysicalDisks::HrGetClusterProperties
  2265. /////////////////////////////////////////////////////////////////////////////
  2266. //++
  2267. //
  2268. // CEnumPhysicalDisks::RemoveDiskFromArray
  2269. //
  2270. // Description:
  2271. // Release the disk at the specified index in the array and decrease the disk count.
  2272. //
  2273. // Arguments:
  2274. // idxDiskIn - the index of the disk to remove; must be less than the array size.
  2275. //
  2276. // Return Value:
  2277. // None.
  2278. //
  2279. // Remarks:
  2280. // None.
  2281. //
  2282. //--
  2283. //////////////////////////////////////////////////////////////////////////////
  2284. void
  2285. CEnumPhysicalDisks::RemoveDiskFromArray( ULONG idxDiskIn )
  2286. {
  2287. TraceFunc( "" );
  2288. Assert( idxDiskIn < m_idxNext );
  2289. ((*m_prgDisks)[ idxDiskIn ])->Release();
  2290. (*m_prgDisks)[ idxDiskIn ] = NULL;
  2291. m_cDiskCount -= 1;
  2292. TraceFuncExit();
  2293. } //*** CEnumPhysicalDisks::RemoveDiskFromArray
  2294. /////////////////////////////////////////////////////////////////////////////
  2295. //++
  2296. //
  2297. // CEnumPhysicalDisks::HrLoadEnum
  2298. //
  2299. // Description:
  2300. // Load the enum and filter out any devices that don't belong.
  2301. //
  2302. // Arguments:
  2303. // None.
  2304. //
  2305. // Return Value:
  2306. // S_OK
  2307. // Success.
  2308. //
  2309. // Other HRESULT errors.
  2310. //
  2311. // Remarks:
  2312. // None.
  2313. //
  2314. //--
  2315. //////////////////////////////////////////////////////////////////////////////
  2316. HRESULT
  2317. CEnumPhysicalDisks::HrLoadEnum( void )
  2318. {
  2319. TraceFunc( "" );
  2320. HRESULT hr = S_OK;
  2321. hr = THR( HrGetDisks() );
  2322. if ( FAILED( hr ) )
  2323. {
  2324. goto Cleanup;
  2325. } // if:
  2326. hr = THR( HrPruneSystemDisks() );
  2327. if ( FAILED( hr ) )
  2328. {
  2329. goto Cleanup;
  2330. } // if:
  2331. hr = STHR( HrIsNodeClustered() );
  2332. if ( FAILED( hr ) )
  2333. {
  2334. goto Cleanup;
  2335. } // if:
  2336. if ( hr == S_OK )
  2337. {
  2338. hr = THR( HrFixupDisks() );
  2339. if ( FAILED( hr ) )
  2340. {
  2341. goto Cleanup;
  2342. } // if:
  2343. } // if:
  2344. hr = S_OK; // could have been S_FALSE
  2345. Cleanup:
  2346. HRETURN( hr );
  2347. } //*** CEnumPysicalDisks::HrLoadEnum