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.

1773 lines
42 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CClusCfgPartitionInfo.cpp
  7. //
  8. // Description:
  9. // This file contains the definition of the CClusCfgPartitionInfo
  10. // class.
  11. //
  12. // The class CClusCfgPartitionInfo represents a disk partition.
  13. // It implements the IClusCfgPartitionInfo interface.
  14. //
  15. // Maintained By:
  16. // Galen Barbee (GalenB) 05-JUN-2000
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////////////////////////////////////////
  20. // Include Files
  21. //////////////////////////////////////////////////////////////////////////////
  22. #include "Pch.h"
  23. #include "CClusCfgPartitionInfo.h"
  24. #include <StdIo.h>
  25. //////////////////////////////////////////////////////////////////////////////
  26. // Constant Definitions
  27. //////////////////////////////////////////////////////////////////////////////
  28. DEFINE_THISCLASS( "CClusCfgPartitionInfo" );
  29. //*************************************************************************//
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CClusCfgPartitionInfo class
  32. /////////////////////////////////////////////////////////////////////////////
  33. //////////////////////////////////////////////////////////////////////////////
  34. //++
  35. //
  36. // CClusCfgPartitionInfo::S_HrCreateInstance
  37. //
  38. // Description:
  39. // Create a CClusCfgPartitionInfo instance.
  40. //
  41. // Arguments:
  42. // ppunkOut.
  43. //
  44. // Return Values:
  45. // Pointer to CClusCfgPartitionInfo instance.
  46. //
  47. //--
  48. //////////////////////////////////////////////////////////////////////////////
  49. HRESULT
  50. CClusCfgPartitionInfo::S_HrCreateInstance(
  51. IUnknown ** ppunkOut
  52. )
  53. {
  54. TraceFunc( "" );
  55. HRESULT hr = S_OK;
  56. hr = THR( S_HrCreateInstance( ppunkOut, NULL ) );
  57. HRETURN( hr );
  58. } //*** CClusCfgPartitionInfo::S_HrCreateInstance
  59. //////////////////////////////////////////////////////////////////////////////
  60. //++
  61. //
  62. // CClusCfgPartitionInfo::S_HrCreateInstance
  63. //
  64. // Description:
  65. // Create a CClusCfgPartitionInfo instance.
  66. //
  67. // Arguments:
  68. // ppunkOut.
  69. //
  70. // Return Values:
  71. // Pointer to CClusCfgPartitionInfo instance.
  72. //
  73. //--
  74. //////////////////////////////////////////////////////////////////////////////
  75. HRESULT
  76. CClusCfgPartitionInfo::S_HrCreateInstance(
  77. IUnknown ** ppunkOut
  78. , BSTR bstrDeviceIDIn
  79. )
  80. {
  81. TraceFunc( "" );
  82. Assert( ppunkOut != NULL );
  83. HRESULT hr = S_OK;
  84. CClusCfgPartitionInfo * pccpi = NULL;
  85. if ( ppunkOut == NULL )
  86. {
  87. hr = THR( E_POINTER );
  88. goto Cleanup;
  89. } // if:
  90. if ( bstrDeviceIDIn == NULL )
  91. {
  92. hr = THR( E_INVALIDARG );
  93. goto Cleanup;
  94. } // if:
  95. pccpi = new CClusCfgPartitionInfo();
  96. if ( pccpi == NULL )
  97. {
  98. hr = THR( E_OUTOFMEMORY );
  99. goto Cleanup;
  100. } // if: error allocating object
  101. hr = THR( pccpi->HrInit( bstrDeviceIDIn ) );
  102. if ( FAILED( hr ) )
  103. {
  104. goto Cleanup;
  105. } // if: HrInit() failed
  106. hr = THR( pccpi->TypeSafeQI( IUnknown, ppunkOut ) );
  107. if ( FAILED( hr ) )
  108. {
  109. goto Cleanup;
  110. } // if: QI failed
  111. Cleanup:
  112. if ( FAILED( hr ) )
  113. {
  114. LogMsg( L"[SRV] CClusCfgPartitionInfo::S_HrCreateInstance() failed. (hr = %#08x)", hr );
  115. } // if:
  116. if ( pccpi != NULL )
  117. {
  118. pccpi->Release();
  119. } // if:
  120. HRETURN( hr );
  121. } //*** CClusCfgPartitionInfo::S_HrCreateInstance
  122. //////////////////////////////////////////////////////////////////////////////
  123. //++
  124. //
  125. // CClusCfgPartitionInfo::CClusCfgPartitionInfo
  126. //
  127. // Description:
  128. // Constructor of the CClusCfgPartitionInfo class. This initializes
  129. // the m_cRef variable to 1 instead of 0 to account of possible
  130. // QueryInterface failure in DllGetClassObject.
  131. //
  132. // Arguments:
  133. // None.
  134. //
  135. // Return Value:
  136. // None.
  137. //
  138. // Remarks:
  139. // None.
  140. //
  141. //--
  142. //////////////////////////////////////////////////////////////////////////////
  143. CClusCfgPartitionInfo::CClusCfgPartitionInfo( void )
  144. : m_cRef( 1 )
  145. {
  146. TraceFunc( "" );
  147. // Increment the count of components in memory so the DLL hosting this
  148. // object cannot be unloaded.
  149. InterlockedIncrement( &g_cObjects );
  150. Assert( m_pIWbemServices == NULL );
  151. Assert( m_bstrName == NULL );
  152. Assert( m_bstrDescription == NULL );
  153. Assert( m_bstrUID == NULL );
  154. Assert( m_prgLogicalDisks == NULL );
  155. Assert( m_idxNextLogicalDisk == 0 );
  156. Assert( m_ulPartitionSize == 0 );
  157. Assert( m_picccCallback == NULL );
  158. Assert( m_bstrDiskDeviceID == NULL );
  159. TraceFuncExit();
  160. } //*** CClusCfgPartitionInfo::CClusCfgPartitionInfo
  161. //////////////////////////////////////////////////////////////////////////////
  162. //++
  163. //
  164. // CClusCfgPartitionInfo::~CClusCfgPartitionInfo
  165. //
  166. // Description:
  167. // Desstructor of the CClusCfgPartitionInfo class.
  168. //
  169. // Arguments:
  170. // None.
  171. //
  172. // Return Value:
  173. // None.
  174. //
  175. // Remarks:
  176. // None.
  177. //
  178. //--
  179. //////////////////////////////////////////////////////////////////////////////
  180. CClusCfgPartitionInfo::~CClusCfgPartitionInfo( void )
  181. {
  182. TraceFunc( "" );
  183. ULONG idx;
  184. TraceSysFreeString( m_bstrName );
  185. TraceSysFreeString( m_bstrDescription );
  186. TraceSysFreeString( m_bstrUID );
  187. TraceSysFreeString( m_bstrDiskDeviceID );
  188. for ( idx = 0; idx < m_idxNextLogicalDisk; idx++ )
  189. {
  190. ((*m_prgLogicalDisks)[ idx ])->Release();
  191. } // for:
  192. TraceFree( m_prgLogicalDisks );
  193. if ( m_pIWbemServices != NULL )
  194. {
  195. m_pIWbemServices->Release();
  196. } // if:
  197. if ( m_picccCallback != NULL )
  198. {
  199. m_picccCallback->Release();
  200. } // if:
  201. // There's going to be one less component in memory. Decrement component count.
  202. InterlockedDecrement( &g_cObjects );
  203. TraceFuncExit();
  204. } //*** CClusCfgPartitionInfo::~CClusCfgPartitionInfo
  205. //*************************************************************************//
  206. /////////////////////////////////////////////////////////////////////////////
  207. // CClusCfgPartitionInfo -- IUknkown interface.
  208. /////////////////////////////////////////////////////////////////////////////
  209. //////////////////////////////////////////////////////////////////////////////
  210. //++
  211. //
  212. // CClusCfgPartitionInfo::AddRef
  213. //
  214. // Description:
  215. // Increment the reference count of this object by one.
  216. //
  217. // Arguments:
  218. // None.
  219. //
  220. // Return Value:
  221. // The new reference count.
  222. //
  223. // Remarks:
  224. // None.
  225. //
  226. //--
  227. //////////////////////////////////////////////////////////////////////////////
  228. STDMETHODIMP_( ULONG )
  229. CClusCfgPartitionInfo::AddRef( void )
  230. {
  231. TraceFunc( "[IUnknown]" );
  232. InterlockedIncrement( &m_cRef );
  233. CRETURN( m_cRef );
  234. } //*** CClusCfgPartitionInfo::AddRef
  235. //////////////////////////////////////////////////////////////////////////////
  236. //++
  237. //
  238. // CClusCfgPartitionInfo::Release
  239. //
  240. // Description:
  241. // Decrement the reference count of this object by one.
  242. //
  243. // Arguments:
  244. // None.
  245. //
  246. // Return Value:
  247. // The new reference count.
  248. //
  249. // Remarks:
  250. // None.
  251. //
  252. //--
  253. //////////////////////////////////////////////////////////////////////////////
  254. STDMETHODIMP_( ULONG )
  255. CClusCfgPartitionInfo::Release( void )
  256. {
  257. TraceFunc( "[IUnknown]" );
  258. LONG cRef;
  259. cRef = InterlockedDecrement( &m_cRef );
  260. if ( cRef == 0 )
  261. {
  262. TraceDo( delete this );
  263. } // if: reference count equal to zero
  264. CRETURN( cRef );
  265. } //*** CClusCfgPartitionInfo::Release
  266. //////////////////////////////////////////////////////////////////////////////
  267. //++
  268. //
  269. // CClusCfgPartitionInfo::QueryInterface
  270. //
  271. // Description:
  272. // Query this object for the passed in interface.
  273. //
  274. // Arguments:
  275. // riidIn
  276. // Id of interface requested.
  277. //
  278. // ppvOut
  279. // Pointer to the requested interface.
  280. //
  281. // Return Value:
  282. // S_OK
  283. // If the interface is available on this object.
  284. //
  285. // E_NOINTERFACE
  286. // If the interface is not available.
  287. //
  288. // E_POINTER
  289. // ppvOut was NULL.
  290. //
  291. // Remarks:
  292. // None.
  293. //
  294. //--
  295. //////////////////////////////////////////////////////////////////////////////
  296. STDMETHODIMP
  297. CClusCfgPartitionInfo::QueryInterface(
  298. REFIID riidIn
  299. , void ** ppvOut
  300. )
  301. {
  302. TraceQIFunc( riidIn, ppvOut );
  303. HRESULT hr = S_OK;
  304. //
  305. // Validate arguments.
  306. //
  307. Assert( ppvOut != NULL );
  308. if ( ppvOut == NULL )
  309. {
  310. hr = THR( E_POINTER );
  311. goto Cleanup;
  312. }
  313. //
  314. // Handle known interfaces.
  315. //
  316. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  317. {
  318. *ppvOut = static_cast< IClusCfgPartitionInfo * >( this );
  319. } // if: IUnknown
  320. else if ( IsEqualIID( riidIn, IID_IClusCfgPartitionInfo ) )
  321. {
  322. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgPartitionInfo, this, 0 );
  323. } // else if: IClusCfgPartitionInfo
  324. else if ( IsEqualIID( riidIn, IID_IClusCfgWbemServices ) )
  325. {
  326. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgWbemServices, this, 0 );
  327. } // else if: IClusCfgWbemServices
  328. else if ( IsEqualIID( riidIn, IID_IClusCfgInitialize ) )
  329. {
  330. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgInitialize, this, 0 );
  331. } // else if: IClusCfgInitialize
  332. else if ( IsEqualIID( riidIn, IID_IClusCfgPartitionProperties ) )
  333. {
  334. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgPartitionProperties, this, 0 );
  335. } // else if: IClusCfgPartitionProperties
  336. else if ( IsEqualIID( riidIn, IID_IClusCfgSetWbemObject ) )
  337. {
  338. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgSetWbemObject, this, 0 );
  339. } // else if: IClusCfgSetWbemObject
  340. else
  341. {
  342. *ppvOut = NULL;
  343. hr = E_NOINTERFACE;
  344. }
  345. //
  346. // Add a reference to the interface if successful.
  347. //
  348. if ( SUCCEEDED( hr ) )
  349. {
  350. ((IUnknown *) *ppvOut)->AddRef();
  351. } // if: success
  352. Cleanup:
  353. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  354. } //*** CClusCfgPartitionInfo::QueryInterface
  355. //*************************************************************************//
  356. /////////////////////////////////////////////////////////////////////////////
  357. // CClusCfgPartitionInfo -- IClusCfgWbemServices interface.
  358. /////////////////////////////////////////////////////////////////////////////
  359. //////////////////////////////////////////////////////////////////////////////
  360. //++
  361. //
  362. // CClusCfgPartitionInfo::SetWbemServices
  363. //
  364. // Description:
  365. // Set the WBEM services provider.
  366. //
  367. // Arguments:
  368. // IN IWbemServices pIWbemServicesIn
  369. //
  370. // Return Value:
  371. // S_OK
  372. // Success
  373. //
  374. // E_POINTER
  375. // The pIWbemServicesIn param is NULL.
  376. //
  377. // Remarks:
  378. // None.
  379. //
  380. //--
  381. //////////////////////////////////////////////////////////////////////////////
  382. STDMETHODIMP
  383. CClusCfgPartitionInfo::SetWbemServices( IWbemServices * pIWbemServicesIn )
  384. {
  385. TraceFunc( "[IClusCfgWbemServices]" );
  386. HRESULT hr = S_OK;
  387. if ( pIWbemServicesIn == NULL )
  388. {
  389. hr = THR( E_POINTER );
  390. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemServices_Partition, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  391. goto Cleanup;
  392. } // if:
  393. m_pIWbemServices = pIWbemServicesIn;
  394. m_pIWbemServices->AddRef();
  395. Cleanup:
  396. HRETURN( hr );
  397. } //*** CClusCfgPartitionInfo::SetWbemServices
  398. //*************************************************************************//
  399. /////////////////////////////////////////////////////////////////////////////
  400. // CClusCfgPartitionInfo -- IClusCfgPartitionInfo interface.
  401. /////////////////////////////////////////////////////////////////////////////
  402. //////////////////////////////////////////////////////////////////////////////
  403. //++
  404. //
  405. // CClusCfgPartitionInfo::GetUID
  406. //
  407. // Description:
  408. //
  409. // Arguments:
  410. //
  411. // Return Value:
  412. //
  413. // Remarks:
  414. // None.
  415. //
  416. //--
  417. //////////////////////////////////////////////////////////////////////////////
  418. STDMETHODIMP
  419. CClusCfgPartitionInfo::GetUID( BSTR * pbstrUIDOut )
  420. {
  421. TraceFunc( "[IClusCfgPartitionInfo]" );
  422. HRESULT hr = S_OK;
  423. if ( pbstrUIDOut == NULL )
  424. {
  425. hr = THR( E_POINTER );
  426. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_PartitionInfo_GetUID_Pointer, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  427. goto Cleanup;
  428. } // if:
  429. //
  430. // If we don't have a UID then simply return S_FALSE to
  431. // indicate that we have no data.
  432. //
  433. if ( m_bstrUID == NULL )
  434. {
  435. hr = S_FALSE;
  436. goto Cleanup;
  437. } // if:
  438. *pbstrUIDOut = SysAllocString( m_bstrUID );
  439. if ( *pbstrUIDOut == NULL )
  440. {
  441. hr = THR( E_OUTOFMEMORY );
  442. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_PartitionInfo_GetUID_Memory, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  443. } // if:
  444. Cleanup:
  445. HRETURN( hr );
  446. } //*** CClusCfgPartitionInfo::GetUID
  447. //////////////////////////////////////////////////////////////////////////////
  448. //++
  449. //
  450. // CClusCfgPartitionInfo::GetName
  451. //
  452. // Description:
  453. //
  454. // Arguments:
  455. //
  456. // Return Value:
  457. //
  458. // Remarks:
  459. // None.
  460. //
  461. //--
  462. //////////////////////////////////////////////////////////////////////////////
  463. STDMETHODIMP
  464. CClusCfgPartitionInfo::GetName( BSTR * pbstrNameOut )
  465. {
  466. TraceFunc( "[IClusCfgPartitionInfo]" );
  467. HRESULT hr = S_OK;
  468. if ( pbstrNameOut == NULL )
  469. {
  470. hr = THR( E_POINTER );
  471. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_PartitionInfo_GetName_Pointer, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  472. goto Cleanup;
  473. } // if:
  474. //
  475. // If we don't have a name then simply return S_FALSE to
  476. // indicate that we have no data.
  477. //
  478. if ( m_bstrName == NULL )
  479. {
  480. hr = S_FALSE;
  481. goto Cleanup;
  482. } // if:
  483. *pbstrNameOut = SysAllocString( m_bstrName );
  484. if (*pbstrNameOut == NULL )
  485. {
  486. hr = THR( E_OUTOFMEMORY );
  487. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetName_Memory, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  488. } // if:
  489. Cleanup:
  490. HRETURN( hr );
  491. } //*** CClusCfgPartitionInfo::GetName
  492. //////////////////////////////////////////////////////////////////////////////
  493. //++
  494. //
  495. // CClusCfgPartitionInfo::SetName
  496. //
  497. // Description:
  498. //
  499. // Arguments:
  500. //
  501. // Return Value:
  502. //
  503. // Remarks:
  504. // None.
  505. //
  506. //--
  507. //////////////////////////////////////////////////////////////////////////////
  508. STDMETHODIMP
  509. CClusCfgPartitionInfo::SetName( LPCWSTR pcszNameIn )
  510. {
  511. TraceFunc1( "[IClusCfgPartitionInfo] pcszNameIn = '%ls'", pcszNameIn == NULL ? L"<null>" : pcszNameIn );
  512. HRESULT hr = THR( E_NOTIMPL );
  513. HRETURN( hr );
  514. } //*** CClusCfgPartitionInfo::SetName
  515. //////////////////////////////////////////////////////////////////////////////
  516. //++
  517. //
  518. // CClusCfgPartitionInfo::GetDescription
  519. //
  520. // Description:
  521. //
  522. // Arguments:
  523. //
  524. // Return Value:
  525. //
  526. // Remarks:
  527. // None.
  528. //
  529. //--
  530. //////////////////////////////////////////////////////////////////////////////
  531. STDMETHODIMP
  532. CClusCfgPartitionInfo::GetDescription( BSTR * pbstrDescriptionOut )
  533. {
  534. TraceFunc( "[IClusCfgPartitionInfo]" );
  535. HRESULT hr = S_OK;
  536. if ( pbstrDescriptionOut == NULL )
  537. {
  538. hr = THR( E_POINTER );
  539. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_PartitionInfo_GetDescription_Pointer, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  540. goto Cleanup;
  541. } // if:
  542. if ( m_bstrDescription == NULL )
  543. {
  544. hr = S_FALSE;
  545. goto Cleanup;
  546. } // if:
  547. *pbstrDescriptionOut = SysAllocString( m_bstrDescription );
  548. if (*pbstrDescriptionOut == NULL )
  549. {
  550. hr = THR( E_OUTOFMEMORY );
  551. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_PartitionInfo_GetDescription_Memory, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  552. } // if:
  553. Cleanup:
  554. HRETURN( hr );
  555. } //*** CClusCfgPartitionInfo::GetDescription
  556. //////////////////////////////////////////////////////////////////////////////
  557. //++
  558. //
  559. // CClusCfgPartitionInfo::SetDescription
  560. //
  561. // Description:
  562. //
  563. // Arguments:
  564. //
  565. // Return Value:
  566. //
  567. // Remarks:
  568. // None.
  569. //
  570. //--
  571. //////////////////////////////////////////////////////////////////////////////
  572. STDMETHODIMP
  573. CClusCfgPartitionInfo::SetDescription( LPCWSTR pcszDescriptionIn )
  574. {
  575. TraceFunc1( "[IClusCfgPartitionInfo] pcszDescriptionIn = '%ls'", pcszDescriptionIn == NULL ? L"<null>" : pcszDescriptionIn );
  576. HRESULT hr;
  577. if ( pcszDescriptionIn == NULL )
  578. {
  579. hr = THR( E_INVALIDARG );
  580. } // if:
  581. else
  582. {
  583. hr = THR( E_NOTIMPL );
  584. } // else:
  585. HRETURN( hr );
  586. } //*** CClusCfgPartitionInfo::SetDescription
  587. //////////////////////////////////////////////////////////////////////////////
  588. //++
  589. //
  590. // CClusCfgPartitionInfo::GetDriveLetterMappings
  591. //
  592. // Description:
  593. //
  594. // Arguments:
  595. //
  596. // Return Value:
  597. //
  598. // Remarks:
  599. // None.
  600. //
  601. //--
  602. //////////////////////////////////////////////////////////////////////////////
  603. STDMETHODIMP
  604. CClusCfgPartitionInfo::GetDriveLetterMappings(
  605. SDriveLetterMapping * pdlmDriveLetterMappingOut
  606. )
  607. {
  608. TraceFunc( "[IClusCfgPartitionInfo]" );
  609. HRESULT hr = S_FALSE;
  610. IWbemClassObject * pLogicalDisk = NULL;
  611. VARIANT var;
  612. ULONG idx;
  613. int idxDrive;
  614. VariantInit( & var );
  615. if ( pdlmDriveLetterMappingOut == NULL )
  616. {
  617. hr = THR( E_POINTER );
  618. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetDriveLetterMappings_Partition, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  619. goto Cleanup;
  620. } // if:
  621. for ( idx = 0; idx < m_idxNextLogicalDisk; idx++ )
  622. {
  623. hr = THR( ((*m_prgLogicalDisks)[ idx ])->TypeSafeQI( IWbemClassObject, &pLogicalDisk ) );
  624. if ( FAILED( hr ) )
  625. {
  626. goto Cleanup;
  627. } // if:
  628. VariantClear( &var );
  629. hr = THR( HrGetWMIProperty( pLogicalDisk, L"Name", VT_BSTR, &var ) );
  630. if ( FAILED( hr ) )
  631. {
  632. goto Cleanup;
  633. } // if:
  634. CharUpper( var.bstrVal );
  635. idxDrive = var.bstrVal[ 0 ] - 'A';
  636. VariantClear( &var );
  637. hr = THR( HrGetWMIProperty( pLogicalDisk, L"DriveType", VT_I4, &var ) );
  638. if ( FAILED( hr ) )
  639. {
  640. goto Cleanup;
  641. } // if:
  642. pdlmDriveLetterMappingOut->dluDrives[ idxDrive ] = (EDriveLetterUsage) var.iVal;
  643. pLogicalDisk->Release();
  644. pLogicalDisk = NULL;
  645. } // for:
  646. Cleanup:
  647. VariantClear( &var );
  648. if ( pLogicalDisk != NULL )
  649. {
  650. pLogicalDisk->Release();
  651. } // if:
  652. HRETURN( hr );
  653. } //*** CClusCfgPartitionInfo::GetDriveLetterMappings
  654. //////////////////////////////////////////////////////////////////////////////
  655. //++
  656. //
  657. // CClusCfgPartitionInfo::SetDriveLetterMappings
  658. //
  659. // Description:
  660. //
  661. // Arguments:
  662. //
  663. // Return Value:
  664. //
  665. // Remarks:
  666. // None.
  667. //
  668. //--
  669. //////////////////////////////////////////////////////////////////////////////
  670. STDMETHODIMP
  671. CClusCfgPartitionInfo::SetDriveLetterMappings(
  672. SDriveLetterMapping dlmDriveLetterMappingIn
  673. )
  674. {
  675. TraceFunc( "[IClusCfgPartitionInfo]" );
  676. HRESULT hr = THR( E_NOTIMPL );
  677. HRETURN( hr );
  678. } //*** CClusCfgPartitionInfo::SetDriveLetterMappings
  679. //////////////////////////////////////////////////////////////////////////////
  680. //++
  681. //
  682. // CClusCfgPartitionInfo::GetSize
  683. //
  684. // Description:
  685. //
  686. // Arguments:
  687. //
  688. // Return Value:
  689. //
  690. // Remarks:
  691. // None.
  692. //
  693. //--
  694. //////////////////////////////////////////////////////////////////////////////
  695. STDMETHODIMP
  696. CClusCfgPartitionInfo::GetSize( ULONG * pcMegaBytes )
  697. {
  698. TraceFunc( "[IClusCfgPartitionInfo]" );
  699. HRESULT hr = S_OK;
  700. if ( pcMegaBytes == NULL )
  701. {
  702. hr = THR( E_POINTER );
  703. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetSize, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  704. goto Cleanup;
  705. } // if:
  706. *pcMegaBytes = m_ulPartitionSize;
  707. Cleanup:
  708. HRETURN( hr );
  709. } //*** CClusCfgPartitionInfo::GetSize
  710. //*************************************************************************//
  711. /////////////////////////////////////////////////////////////////////////////
  712. // CClusCfgPartitionInfo class -- Private Methods.
  713. /////////////////////////////////////////////////////////////////////////////
  714. //////////////////////////////////////////////////////////////////////////////
  715. //++
  716. //
  717. // CClusCfgPartitionInfo::SetWbemObject
  718. //
  719. // Description:
  720. // Initialize this component.
  721. //
  722. // Arguments:
  723. // None.
  724. //
  725. // Return Value:
  726. //
  727. //
  728. // Remarks:
  729. // None.
  730. //
  731. //--
  732. //////////////////////////////////////////////////////////////////////////////
  733. HRESULT
  734. CClusCfgPartitionInfo::SetWbemObject(
  735. IWbemClassObject * pPartitionIn
  736. , bool * pfRetainObjectOut
  737. )
  738. {
  739. TraceFunc( "" );
  740. Assert( pPartitionIn != NULL );
  741. Assert( pfRetainObjectOut != NULL );
  742. HRESULT hr = S_OK;
  743. VARIANT var;
  744. ULONGLONG ull = 0;
  745. int cch = 0;
  746. VariantInit( &var );
  747. hr = THR( HrGetWMIProperty( pPartitionIn, L"Description", VT_BSTR, &var ) );
  748. if ( FAILED( hr ) )
  749. {
  750. goto Cleanup;
  751. } // if:
  752. m_bstrDescription = TraceSysAllocString( var.bstrVal );
  753. if ( m_bstrDescription == NULL )
  754. {
  755. goto OutOfMemory;
  756. } // if:
  757. VariantClear( &var );
  758. hr = THR( HrGetWMIProperty( pPartitionIn, L"DeviceID", VT_BSTR, &var ) );
  759. if ( FAILED( hr ) )
  760. {
  761. goto Cleanup;
  762. } // if:
  763. m_bstrUID = TraceSysAllocString( var.bstrVal );
  764. if ( m_bstrUID == NULL )
  765. {
  766. goto OutOfMemory;
  767. } // if:
  768. VariantClear( &var );
  769. hr = THR( HrGetWMIProperty( pPartitionIn, L"Name", VT_BSTR, &var ) );
  770. if ( FAILED( hr ) )
  771. {
  772. goto Cleanup;
  773. } // if:
  774. m_bstrName = TraceSysAllocString( var.bstrVal );
  775. if ( m_bstrName == NULL )
  776. {
  777. goto OutOfMemory;
  778. } // if:
  779. VariantClear( &var );
  780. hr = THR( HrGetWMIProperty( pPartitionIn, L"Size", VT_BSTR, &var ) );
  781. if ( FAILED( hr ) )
  782. {
  783. goto Cleanup;
  784. } // if:
  785. cch = swscanf( var.bstrVal, L"%I64u", &ull );
  786. Assert( cch > 0 );
  787. m_ulPartitionSize = (ULONG) ( ull / ( 1024 * 1024 ) );
  788. hr = THR( HrGetLogicalDisks( pPartitionIn ) );
  789. *pfRetainObjectOut = true;
  790. goto Cleanup;
  791. OutOfMemory:
  792. hr = THR( E_OUTOFMEMORY );
  793. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_SetWbemObject_Partition, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  794. Cleanup:
  795. VariantClear( &var );
  796. HRETURN( hr );
  797. } //*** CClusCfgPartitionInfo::SetWbemObject
  798. //*************************************************************************//
  799. /////////////////////////////////////////////////////////////////////////////
  800. // CClusCfgPartitionInfo -- IClusCfgInitialize interface.
  801. /////////////////////////////////////////////////////////////////////////////
  802. //////////////////////////////////////////////////////////////////////////////
  803. //++
  804. //
  805. // CClusCfgPartitionInfo::Initialize
  806. //
  807. // Description:
  808. // Initialize this component.
  809. //
  810. // Arguments:
  811. // IN IUknown * punkCallbackIn
  812. //
  813. // IN LCID lcidIn
  814. //
  815. // Return Value:
  816. // S_OK
  817. // Success
  818. //
  819. // Remarks:
  820. // None.
  821. //
  822. //--
  823. //////////////////////////////////////////////////////////////////////////////
  824. STDMETHODIMP
  825. CClusCfgPartitionInfo::Initialize(
  826. IUnknown * punkCallbackIn,
  827. LCID lcidIn
  828. )
  829. {
  830. TraceFunc( "[IClusCfgInitialize]" );
  831. Assert( m_picccCallback == NULL );
  832. HRESULT hr = S_OK;
  833. m_lcid = lcidIn;
  834. if ( punkCallbackIn == NULL )
  835. {
  836. hr = THR( E_POINTER );
  837. goto Cleanup;
  838. } // if:
  839. hr = THR( punkCallbackIn->TypeSafeQI( IClusCfgCallback, &m_picccCallback ) );
  840. Cleanup:
  841. HRETURN( hr );
  842. } //*** CClusCfgPartitionInfo::Initialize
  843. //*************************************************************************//
  844. /////////////////////////////////////////////////////////////////////////////
  845. // CClusCfgPartitionInfo -- IClusCfgPartitionProperties interface.
  846. /////////////////////////////////////////////////////////////////////////////
  847. //////////////////////////////////////////////////////////////////////////////
  848. //++
  849. //
  850. // CClusCfgPartitionInfo::IsThisLogicalDisk
  851. //
  852. // Description:
  853. // Does this partition have the passed in logical disk?
  854. //
  855. // Arguments:
  856. // None.
  857. //
  858. // Return Value:
  859. // S_OK
  860. // Success, the partition has the logical disk.
  861. //
  862. // S_FALSE
  863. // Success, the partition does not have the logical disk.
  864. //
  865. // Remarks:
  866. // None.
  867. //
  868. //--
  869. //////////////////////////////////////////////////////////////////////////////
  870. STDMETHODIMP
  871. CClusCfgPartitionInfo::IsThisLogicalDisk( WCHAR cLogicalDiskIn )
  872. {
  873. TraceFunc( "[IClusCfgPartitionProperties]" );
  874. HRESULT hr = S_FALSE;
  875. DWORD idx;
  876. IWbemClassObject * piwco = NULL;
  877. VARIANT var;
  878. bool fFoundIt = false;
  879. VariantInit( &var );
  880. if ( m_idxNextLogicalDisk == 0 )
  881. {
  882. goto Cleanup;
  883. } // if:
  884. for ( idx = 0; idx < m_idxNextLogicalDisk; idx++ )
  885. {
  886. hr = THR( ((*m_prgLogicalDisks)[ idx ])->TypeSafeQI( IWbemClassObject, &piwco ) );
  887. if ( FAILED( hr ) )
  888. {
  889. goto Cleanup;
  890. } // if:
  891. hr = THR( HrGetWMIProperty( piwco, L"DeviceID", VT_BSTR, &var ) );
  892. if ( FAILED( hr ) )
  893. {
  894. goto Cleanup;
  895. } // if:
  896. if ( cLogicalDiskIn == var.bstrVal[ 0 ] )
  897. {
  898. fFoundIt = true;
  899. break;
  900. } // if:
  901. VariantClear( &var );
  902. piwco->Release();
  903. piwco = NULL;
  904. } // for:
  905. if ( !fFoundIt )
  906. {
  907. hr = S_FALSE;
  908. } // if:
  909. Cleanup:
  910. VariantClear( &var );
  911. if ( piwco != NULL )
  912. {
  913. piwco->Release();
  914. } // if:
  915. HRETURN( hr );
  916. } //*** CClusCfgPartitionInfo::IsThisLogicalDisk
  917. //////////////////////////////////////////////////////////////////////////////
  918. //++
  919. //
  920. // CClusCfgPartitionInfo::IsNTFS
  921. //
  922. // Description:
  923. // Is this an NTFS partition?
  924. //
  925. // Arguments:
  926. // None.
  927. //
  928. // Return Value:
  929. // S_OK
  930. // Success, the partition is NTFS.
  931. //
  932. // S_FALSE
  933. // Success, the partition is not NTFS.
  934. //
  935. // Remarks:
  936. // None.
  937. //
  938. //--
  939. //////////////////////////////////////////////////////////////////////////////
  940. STDMETHODIMP
  941. CClusCfgPartitionInfo::IsNTFS( void )
  942. {
  943. TraceFunc( "[IClusCfgPartitionProperties]" );
  944. HRESULT hr = S_FALSE;
  945. VARIANT var;
  946. ULONG idx;
  947. IWbemClassObject * piwco = NULL;
  948. VariantInit( &var );
  949. for ( idx = 0; idx < m_idxNextLogicalDisk; idx++ )
  950. {
  951. hr = THR( ((*m_prgLogicalDisks)[ idx ])->TypeSafeQI( IWbemClassObject, &piwco ) );
  952. if ( FAILED( hr ) )
  953. {
  954. goto Cleanup;
  955. } // if:
  956. VariantClear( &var );
  957. hr = HrGetWMIProperty( piwco, L"FileSystem", VT_BSTR, &var );
  958. if ( ( hr == E_PROPTYPEMISMATCH ) && ( var.vt == VT_NULL ) )
  959. {
  960. VariantClear( &var );
  961. hr = S_FALSE;
  962. THR( HrGetWMIProperty( piwco, L"DeviceID", VT_BSTR, &var ) );
  963. STATUS_REPORT_STRING_REF(
  964. TASKID_Major_Find_Devices
  965. , TASKID_Minor_Phys_Disk_No_File_System
  966. , IDS_ERROR_PHYSDISK_NO_FILE_SYSTEM
  967. , var.bstrVal
  968. , IDS_ERROR_PHYSDISK_NO_FILE_SYSTEM_REF
  969. , hr );
  970. break;
  971. } // if:
  972. else if ( FAILED( hr ) )
  973. {
  974. THR( hr );
  975. goto Cleanup;
  976. } // else if:
  977. if ( NStringCchCompareCase( var.bstrVal, SysStringLen( var.bstrVal ) + 1, L"NTFS", RTL_NUMBER_OF( L"NTFS" ) ) != 0 )
  978. {
  979. VariantClear( &var );
  980. hr = S_FALSE;
  981. THR( HrGetWMIProperty( piwco, L"DeviceID", VT_BSTR, &var ) );
  982. STATUS_REPORT_STRING_REF(
  983. TASKID_Major_Find_Devices
  984. , TASKID_Minor_Phys_Disk_Not_NTFS
  985. , IDS_WARN_PHYSDISK_NOT_NTFS
  986. , var.bstrVal
  987. , IDS_WARN_PHYSDISK_NOT_NTFS_REF
  988. , hr
  989. );
  990. break;
  991. } // if:
  992. piwco->Release();
  993. piwco = NULL;
  994. } // for:
  995. Cleanup:
  996. VariantClear( &var );
  997. if ( piwco != NULL )
  998. {
  999. piwco->Release();
  1000. } // if:
  1001. HRETURN( hr );
  1002. } //*** CClusCfgPartitionInfo::IsNTFS
  1003. /*
  1004. //////////////////////////////////////////////////////////////////////////////
  1005. //++
  1006. //
  1007. // CClusCfgPartitionInfo::IsNTFS
  1008. //
  1009. // Description:
  1010. // Is this an NTFS partition?
  1011. //
  1012. // Arguments:
  1013. // None.
  1014. //
  1015. // Return Value:
  1016. // S_OK
  1017. // Success, the partition is NTFS.
  1018. //
  1019. // S_FALSE
  1020. // Success, the partition is not NTFS.
  1021. //
  1022. // Remarks:
  1023. // None.
  1024. //
  1025. //--
  1026. //////////////////////////////////////////////////////////////////////////////
  1027. STDMETHODIMP
  1028. CClusCfgPartitionInfo::IsNTFS( void )
  1029. {
  1030. TraceFunc( "[IClusCfgPartitionProperties]" );
  1031. HRESULT hr = S_OK;
  1032. WCHAR szScanFormat[] = { L"Disk #%u, Partition #%u" };
  1033. DWORD dwDisk;
  1034. DWORD dwPartition;
  1035. int cReturned;
  1036. WCHAR szFormat[] = { L"\\\\\?\\GLOBALROOT\\Device\\Harddisk%u\\Partition%u\\" };
  1037. WCHAR szBuf[ 64 ];
  1038. BSTR bstrFileSystem = NULL;
  1039. cReturned = _snwscanf( m_bstrName, wcslen( m_bstrName ), szScanFormat, &dwDisk, &dwPartition );
  1040. if ( cReturned != 2 )
  1041. {
  1042. hr = THR( E_UNEXPECTED );
  1043. goto Cleanup;
  1044. } // if:
  1045. hr = THR( StringCchPrintfW( szBuf, ARRAYSIZE( szBuf ), szFormat, dwDisk, dwPartition + 1 ) );
  1046. if ( FAILED( hr ) )
  1047. {
  1048. goto Cleanup;
  1049. } // if:
  1050. hr = THR( HrGetVolumeInformation( szBuf, NULL, &bstrFileSystem ) );
  1051. if ( FAILED( hr ) )
  1052. {
  1053. hr = S_FALSE;
  1054. goto Cleanup;
  1055. } // if:
  1056. if ( NStringCchCompareNoCase( bstrFileSystem, SysStringLen( bstrFileSystem ) + 1, L"NTFS", RTL_NUMBER_OF( L"NTFS" ) ) == 0 )
  1057. {
  1058. hr = S_OK;
  1059. } // if:
  1060. else
  1061. {
  1062. hr = S_FALSE;
  1063. } // else:
  1064. Cleanup:
  1065. TraceSysFreeString( bstrFileSystem );
  1066. HRETURN( hr );
  1067. } //*** CClusCfgPartitionInfo::IsNTFS
  1068. */
  1069. //////////////////////////////////////////////////////////////////////////////
  1070. //++
  1071. //
  1072. // CClusCfgPartitionInfo::GetFriendlyName
  1073. //
  1074. // Description:
  1075. // Get the friendly name of this partition. This name will be the
  1076. // logical disk names of all logical disks on this partition.
  1077. //
  1078. // Arguments:
  1079. // BSTR * pbstrNameOut
  1080. //
  1081. // Return Value:
  1082. // S_OK
  1083. // Success.
  1084. //
  1085. // Remarks:
  1086. // None.
  1087. //
  1088. //--
  1089. //////////////////////////////////////////////////////////////////////////////
  1090. STDMETHODIMP
  1091. CClusCfgPartitionInfo::GetFriendlyName( BSTR * pbstrNameOut )
  1092. {
  1093. TraceFunc( "[IClusCfgPartitionProperties]" );
  1094. HRESULT hr = S_FALSE;
  1095. DWORD idx;
  1096. IWbemClassObject * piwco = NULL;
  1097. WCHAR * psz = NULL;
  1098. WCHAR * pszTmp = NULL;
  1099. DWORD cch = 0;
  1100. VARIANT var;
  1101. VariantInit( &var );
  1102. if ( m_idxNextLogicalDisk == 0 )
  1103. {
  1104. goto Cleanup;
  1105. } // if:
  1106. if ( pbstrNameOut == NULL )
  1107. {
  1108. hr = THR( E_POINTER );
  1109. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetFriendlyName, IDS_ERROR_NULL_POINTER, IDS_ERROR_NULL_POINTER_REF, hr );
  1110. goto Cleanup;
  1111. } // if:
  1112. for ( idx = 0; idx < m_idxNextLogicalDisk; idx++ )
  1113. {
  1114. hr = THR( ((*m_prgLogicalDisks)[ idx ])->TypeSafeQI( IWbemClassObject, &piwco ) );
  1115. if ( FAILED( hr ) )
  1116. {
  1117. goto Cleanup;
  1118. } // if:
  1119. hr = THR( HrGetWMIProperty( piwco, L"DeviceID", VT_BSTR, &var ) );
  1120. if ( FAILED( hr ) )
  1121. {
  1122. goto Cleanup;
  1123. } // if:
  1124. cch += ( UINT ) wcslen( var.bstrVal ) + 2; // a space and the '\0'
  1125. pszTmp = (WCHAR *) TraceReAlloc( psz, sizeof( WCHAR ) * cch, HEAP_ZERO_MEMORY );
  1126. if ( pszTmp == NULL )
  1127. {
  1128. goto OutOfMemory;
  1129. } // if:
  1130. psz = pszTmp;
  1131. pszTmp = NULL;
  1132. hr = THR( StringCchCatW( psz, cch, L" " ) );
  1133. if ( FAILED( hr ) )
  1134. {
  1135. goto Cleanup;
  1136. } // if:
  1137. hr = THR( StringCchCatW( psz, cch, var.bstrVal ) );
  1138. if ( FAILED( hr ) )
  1139. {
  1140. goto Cleanup;
  1141. } // if:
  1142. VariantClear( &var );
  1143. piwco->Release();
  1144. piwco = NULL;
  1145. } // for:
  1146. *pbstrNameOut = TraceSysAllocString( psz );
  1147. if ( *pbstrNameOut == NULL )
  1148. {
  1149. goto OutOfMemory;
  1150. } // if:
  1151. goto Cleanup;
  1152. OutOfMemory:
  1153. hr = THR( E_OUTOFMEMORY );
  1154. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_GetFriendlyName, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1155. Cleanup:
  1156. VariantClear( &var );
  1157. if ( piwco != NULL )
  1158. {
  1159. piwco->Release();
  1160. } // if:
  1161. if ( psz != NULL )
  1162. {
  1163. TraceFree( psz );
  1164. } // if:
  1165. if ( pszTmp != NULL )
  1166. {
  1167. free( pszTmp );
  1168. } // if:
  1169. HRETURN( hr );
  1170. } //*** CClusCfgPartitionInfo::GetFriendlyName
  1171. //*************************************************************************//
  1172. /////////////////////////////////////////////////////////////////////////////
  1173. // CClusCfgPartitionInfo class -- Private Methods.
  1174. /////////////////////////////////////////////////////////////////////////////
  1175. //////////////////////////////////////////////////////////////////////////////
  1176. //++
  1177. //
  1178. // CClusCfgPartitionInfo::HrInit
  1179. //
  1180. // Description:
  1181. // Initialize this component.
  1182. //
  1183. // Arguments:
  1184. // None.
  1185. //
  1186. // Return Value:
  1187. //
  1188. //
  1189. // Remarks:
  1190. // None.
  1191. //
  1192. //--
  1193. //////////////////////////////////////////////////////////////////////////////
  1194. HRESULT
  1195. CClusCfgPartitionInfo::HrInit(
  1196. BSTR bstrDeviceIDIn // = NULL
  1197. )
  1198. {
  1199. TraceFunc( "" );
  1200. HRESULT hr = S_OK;
  1201. // IUnknown
  1202. Assert( m_cRef == 1 );
  1203. if ( bstrDeviceIDIn != NULL )
  1204. {
  1205. m_bstrDiskDeviceID = TraceSysAllocString( bstrDeviceIDIn );
  1206. if ( m_bstrDiskDeviceID == NULL )
  1207. {
  1208. hr = THR( E_OUTOFMEMORY );
  1209. } // if:
  1210. } // if:
  1211. HRETURN( hr );
  1212. } //*** CClusCfgPartitionInfo::HrInit
  1213. /////////////////////////////////////////////////////////////////////////////
  1214. //++
  1215. //
  1216. // CClusCfgPartitionInfo:HrAddLogicalDiskToArray
  1217. //
  1218. // Description:
  1219. // Add the passed in logical disk to the array of punks that holds the
  1220. // logical disks.
  1221. //
  1222. // Arguments:
  1223. //
  1224. //
  1225. // Return Value:
  1226. // S_OK
  1227. // Success
  1228. //
  1229. // E_OUTOFMEMORY
  1230. // Couldn't allocate memeory.
  1231. //
  1232. // Remarks:
  1233. // None.
  1234. //
  1235. //--
  1236. //////////////////////////////////////////////////////////////////////////////
  1237. HRESULT
  1238. CClusCfgPartitionInfo::HrAddLogicalDiskToArray(
  1239. IWbemClassObject * pLogicalDiskIn
  1240. )
  1241. {
  1242. TraceFunc( "" );
  1243. HRESULT hr = S_OK;
  1244. IUnknown * punk;
  1245. IUnknown * ((*prgpunks)[]) = NULL;
  1246. prgpunks = (IUnknown *((*)[])) TraceReAlloc( m_prgLogicalDisks, sizeof( IUnknown * ) * ( m_idxNextLogicalDisk + 1 ), HEAP_ZERO_MEMORY );
  1247. if ( prgpunks == NULL )
  1248. {
  1249. hr = THR( E_OUTOFMEMORY );
  1250. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrAddLogicalDiskToArray, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1251. goto Cleanup;
  1252. } // else:
  1253. m_prgLogicalDisks = prgpunks;
  1254. hr = THR( pLogicalDiskIn->TypeSafeQI( IUnknown, &punk ) );
  1255. if ( SUCCEEDED( hr ) )
  1256. {
  1257. (*m_prgLogicalDisks)[ m_idxNextLogicalDisk++ ] = punk;
  1258. } // if:
  1259. Cleanup:
  1260. HRETURN( hr );
  1261. } //*** CClusCfgPartitionInfo::HrAddLogicalDiskToArray
  1262. /////////////////////////////////////////////////////////////////////////////
  1263. //++
  1264. //
  1265. // CClusCfgPartitionInfo:HrGetLogicalDisks
  1266. //
  1267. // Description:
  1268. // Get the logical disks for the passed in partition.
  1269. //
  1270. // Arguments:
  1271. //
  1272. //
  1273. // Return Value:
  1274. // S_OK
  1275. // Success
  1276. //
  1277. // S_FALSE
  1278. // The file system was not NTFS.
  1279. //
  1280. // E_OUTOFMEMORY
  1281. // Couldn't allocate memeory.
  1282. //
  1283. // Remarks:
  1284. // None.
  1285. //
  1286. //--
  1287. //////////////////////////////////////////////////////////////////////////////
  1288. HRESULT
  1289. CClusCfgPartitionInfo::HrGetLogicalDisks(
  1290. IWbemClassObject * pPartitionIn
  1291. )
  1292. {
  1293. TraceFunc( "" );
  1294. HRESULT hr;
  1295. VARIANT var;
  1296. WCHAR szBuf[ 256 ];
  1297. IEnumWbemClassObject * pLogicalDisks = NULL;
  1298. IWbemClassObject * pLogicalDisk = NULL;
  1299. ULONG ulReturned;
  1300. BSTR bstrQuery = NULL;
  1301. BSTR bstrWQL = NULL;
  1302. VariantInit( &var );
  1303. bstrWQL = TraceSysAllocString( L"WQL" );
  1304. if ( bstrWQL == NULL )
  1305. {
  1306. hr = THR( E_OUTOFMEMORY );
  1307. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrGetLogicalDisks, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1308. goto Cleanup;
  1309. } // if:
  1310. //
  1311. // Need to enum the logical disk(s) of this partition to determine if it is booted
  1312. // bootable.
  1313. //
  1314. hr = THR( HrGetWMIProperty( pPartitionIn, L"DeviceID", VT_BSTR, &var ) );
  1315. if ( FAILED( hr ) )
  1316. {
  1317. goto Cleanup;
  1318. } // if:
  1319. hr = THR( StringCchPrintfW(
  1320. szBuf
  1321. , ARRAYSIZE( szBuf ), L"Associators of {Win32_DiskPartition.DeviceID='%ws'} where AssocClass=Win32_LogicalDiskToPartition"
  1322. , var.bstrVal
  1323. ) );
  1324. if ( FAILED( hr ) )
  1325. {
  1326. goto Cleanup;
  1327. } // if:
  1328. bstrQuery = TraceSysAllocString( szBuf );
  1329. if ( bstrQuery == NULL )
  1330. {
  1331. hr = THR( E_OUTOFMEMORY );
  1332. STATUS_REPORT_REF( TASKID_Major_Find_Devices, TASKID_Minor_HrGetLogicalDisks, IDS_ERROR_OUTOFMEMORY, IDS_ERROR_OUTOFMEMORY_REF, hr );
  1333. goto Cleanup;
  1334. } // if:
  1335. hr = THR( m_pIWbemServices->ExecQuery( bstrWQL, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pLogicalDisks ) );
  1336. if ( FAILED( hr ) )
  1337. {
  1338. STATUS_REPORT_REF(
  1339. TASKID_Major_Find_Devices
  1340. , TASKID_Minor_WMI_Logical_Disks_Qry_Failed
  1341. , IDS_ERROR_WMI_PHYS_DISKS_QRY_FAILED
  1342. , IDS_ERROR_WMI_PHYS_DISKS_QRY_FAILED_REF
  1343. , hr
  1344. );
  1345. goto Cleanup;
  1346. } // if:
  1347. for ( ; ; )
  1348. {
  1349. hr = pLogicalDisks->Next( WBEM_INFINITE, 1, &pLogicalDisk, &ulReturned );
  1350. if ( ( hr == S_OK ) && ( ulReturned == 1 ) )
  1351. {
  1352. THR( HrLogLogicalDiskInfo( pLogicalDisk, var.bstrVal ) );
  1353. hr = THR( HrAddLogicalDiskToArray( pLogicalDisk ) );
  1354. if ( FAILED( hr ) )
  1355. {
  1356. goto Cleanup;
  1357. } // if:
  1358. pLogicalDisk->Release();
  1359. pLogicalDisk = NULL;
  1360. } // if:
  1361. else if ( ( hr == S_FALSE ) && ( ulReturned == 0 ) )
  1362. {
  1363. hr = S_OK;
  1364. break;
  1365. } // else if:
  1366. else
  1367. {
  1368. STATUS_REPORT_STRING_REF(
  1369. TASKID_Major_Find_Devices
  1370. , TASKID_Minor_HrGetLogicalDisks_Next
  1371. , IDS_ERROR_WQL_QRY_NEXT_FAILED
  1372. , bstrQuery
  1373. , IDS_ERROR_WQL_QRY_NEXT_FAILED_REF
  1374. , hr
  1375. );
  1376. goto Cleanup;
  1377. } // else:
  1378. } // for:
  1379. goto Cleanup;
  1380. Cleanup:
  1381. VariantClear( &var );
  1382. TraceSysFreeString( bstrQuery );
  1383. TraceSysFreeString( bstrWQL );
  1384. if ( pLogicalDisk != NULL )
  1385. {
  1386. pLogicalDisk->Release();
  1387. } // if:
  1388. if ( pLogicalDisks != NULL )
  1389. {
  1390. pLogicalDisks->Release();
  1391. } // if:
  1392. HRETURN( hr );
  1393. } //*** CClusCfgPartitionInfo::HrGetLogicalDisks
  1394. /////////////////////////////////////////////////////////////////////////////
  1395. //++
  1396. //
  1397. // CClusCfgPartitionInfo:HrLogLogicalDiskInfo
  1398. //
  1399. // Description:
  1400. // Log the info about the passed in logical disk.
  1401. //
  1402. // Arguments:
  1403. // pLogicalDiskIn
  1404. //
  1405. // bstrDeviceIDIn
  1406. // The device ID of the current partition to which this logical disk
  1407. // belongs.
  1408. //
  1409. // Return Value:
  1410. // S_OK
  1411. // Success
  1412. //
  1413. // Other HRESULT errors.
  1414. //
  1415. //--
  1416. //////////////////////////////////////////////////////////////////////////////
  1417. HRESULT
  1418. CClusCfgPartitionInfo::HrLogLogicalDiskInfo(
  1419. IWbemClassObject * pLogicalDiskIn
  1420. , BSTR bstrDeviceIDIn
  1421. )
  1422. {
  1423. TraceFunc( "" );
  1424. Assert( m_bstrDiskDeviceID != NULL );
  1425. Assert( pLogicalDiskIn != NULL );
  1426. Assert( bstrDeviceIDIn != NULL );
  1427. HRESULT hr = S_OK;
  1428. VARIANT var;
  1429. VariantInit( &var );
  1430. if ( ( pLogicalDiskIn == NULL ) || ( bstrDeviceIDIn == NULL ) )
  1431. {
  1432. hr = THR( E_INVALIDARG );
  1433. goto Cleanup;
  1434. } // if:
  1435. hr = THR( HrGetWMIProperty( pLogicalDiskIn, L"Name", VT_BSTR, &var ) );
  1436. if ( FAILED( hr ) )
  1437. {
  1438. goto Cleanup;
  1439. } // if:
  1440. LOG_STATUS_REPORT_STRING3(
  1441. L"Found physical disk \"%1!ws!\" with partition \"%2!ws!\" which has the logical disk \"%3!ws!\"."
  1442. , m_bstrDiskDeviceID
  1443. , bstrDeviceIDIn
  1444. , var.bstrVal
  1445. , hr
  1446. );
  1447. Cleanup:
  1448. VariantClear( &var );
  1449. HRETURN( hr );
  1450. } //*** CClusCfgPartitionInfo::HrLogLogicalDiskInfo