⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 instance_physicaldisk.cpp

📁 270的linux说明
💻 CPP
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*/#include "Instance_PhysicalDisk.h"#include "inc/framework/base_Enum.h"#include "inc/base/Layer_Manager.h"#include "storage_util.h"//==============================================================================////	DefaultPhysicalDiskInstanceObject implementation////==============================================================================bool DefaultPhysicalDiskInstanceObject::Initialize( const IntelMobileString& szKey ){	_Log(IntelMobileText("DefaultPhysicalDiskInstanceObject::Initialize(%s)"), szKey.c_str());	m_sKey = szKey;	__szFileName = szKey;	return true;}DefaultPhysicalDiskInstanceObject::~DefaultPhysicalDiskInstanceObject(){	_Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: DefaultPhysicalDiskInstanceObject::~DefaultPhysicalDiskInstanceObject()") );}//==============================================================================//==============================================================================//// PhysicalDisk properties////==============================================================================//==============================================================================//// These all return the true value.  If there is an error, throw // an appropriate HRESULT.  These need to return the true value// because the override the virtual GetValue() function in the // Property base class.void PhysicalDiskIDClass::GetValueImpl(){	DefaultPhysicalDiskInstanceObject* pThis = (DefaultPhysicalDiskInstanceObject*) this->_pThis;	this->SetValueImpl( pThis->__szFileName.c_str() );}void PhysicalDiskIndexClass::GetValueImpl(){	//TODO: Linux	this->SetNull( true );}void PhysicalDiskNumberOfLogicalClass::GetValueImpl(){	// Hard code	//TODO: Linux	//this->SetValueImpl( 1 );	DefaultPhysicalDiskInstanceObject* pThis = (DefaultPhysicalDiskInstanceObject*) this->_pThis;		//support new info model	disk_info_t diskInfo;	list<part_info_t> partList;	/*	strncpy(diskInfo.name, pThis->__szFileName.c_str(), 256);	if(GetPhysicalDiskLogicalDiskList(&diskInfo, partList))	{		this->SetValueImpl(partList.size());	}	else	{		this->SetNull(true);	}	*/	vector<IntelMobileString> partVect;	partVect = pThis->GetLogicalDisks();	this->SetValueImpl(partVect.size());	}void PhysicalDiskManufacturerClass::GetValueImpl(){	/*DefaultPhysicalDiskInstanceObject* pThis = (DefaultPhysicalDiskInstanceObject*) this->_pThis;	HANDLE hPhysicalDisk;	hPhysicalDisk = CreateFile(					pThis->__szFileName.c_str(),  // drive to open					0,                // no access to the drive					FILE_SHARE_READ | // share mode					FILE_SHARE_WRITE, 					NULL,             // default security attributes					OPEN_EXISTING,    // disposition					0,                // file attributes					NULL);            // do not copy file attributes	if (hPhysicalDisk == INVALID_HANDLE_VALUE)  // cannot open the drive	{		this->SetNull( true );	}	BOOL bResult;	DWORD junk;	STORAGE_IDENTIFICATION storageID;	bResult = DeviceIoControl(					hPhysicalDisk,                     // hDevice					IOCTL_DISK_GET_STORAGEID,  // dwIoControlCode					NULL,                      // lpInBuffer					0,                         // nInBufferSize					&storageID,                // output buffer					sizeof(storageID) + 100,   // size of output buffer					&junk,                     // number of bytes returned					(LPOVERLAPPED)NULL);       // OVERLAPPED structure	if (bResult == TRUE)		this->SetValueImpl( (wchar_t*)(&storageID + storageID.dwManufactureIDOffset) );	else		this->SetNull( true );*/	//TODO: Linux	this->SetNull( true );}void PhysicalDiskInterfaceClass::GetValueImpl(){	/*DefaultPhysicalDiskInstanceObject* pThis = (DefaultPhysicalDiskInstanceObject*) this->_pThis;	HANDLE hPhysicalDisk;	hPhysicalDisk = CreateFile(					pThis->__szFileName.c_str(),  // drive to open					0,                // no access to the drive					FILE_SHARE_READ | // share mode					FILE_SHARE_WRITE, 					NULL,             // default security attributes					OPEN_EXISTING,    // disposition					0,                // file attributes					NULL);            // do not copy file attributes	if (hPhysicalDisk == INVALID_HANDLE_VALUE)  // cannot open the drive	{		this->SetNull( true );	}	BOOL bResult;	DWORD junk;	STORAGEDEVICEINFO diskInfo;	diskInfo.cbSize = sizeof(STORAGEDEVICEINFO);	bResult = DeviceIoControl(					hPhysicalDisk,                   // hDevice					IOCTL_DISK_DEVICE_INFO,  // dwIoControlCode					NULL,                    // lpInBuffer					0,                       // nInBufferSize					&diskInfo,               // output buffer					sizeof(diskInfo),        // size of output buffer					&junk,                   // number of bytes returned					(LPOVERLAPPED)NULL);     // OVERLAPPED structure	// TODO*/	//TODO: Linux	this->SetNull( true );}void PhysicalDiskModelIDClass::GetValueImpl(){	//TODO: Linux	this->SetNull( true );}void PhysicalDiskMediaClass::GetValueImpl(){	//TODO: Linux//	this->SetNull( true );	DefaultPhysicalDiskInstanceObject* pThis = (DefaultPhysicalDiskInstanceObject*) this->_pThis;	/*	int ret;	store_info_t sinfo;	if((ret = GetStore(&sinfo, pThis->__szFileName.c_str())) < 0)		this->SetNull(true);	else	{		if(sinfo.interface == INTERNAL)			this->SetValueImpl(Fixed);		else			this->SetValueImpl(Removable);	}	*/	disk_info_t diskInfo;	strncpy(diskInfo.name, pThis->__szFileName.c_str(), 256);	if(GetDiskInfo(&diskInfo))	{		if(diskInfo.interface == INTERNAL || diskInfo.interface == HD)			this->SetValueImpl(PhysicalDiskMediaEnum::Fixed);		else if(diskInfo.interface == CF || diskInfo.interface == SD				|| diskInfo.interface == NET)			this->SetValueImpl(PhysicalDiskMediaEnum::Removable);		else			this->SetValueImpl(PhysicalDiskMediaEnum::Fixed);	}	else	{		this->SetNull(true);	}}void PhysicalDiskSizeClass::GetValueImpl(){	DefaultPhysicalDiskInstanceObject* pThis = (DefaultPhysicalDiskInstanceObject*) this->_pThis;	/*	BOOL bResult;	ULARGE_INTEGER freeAvailable;	ULARGE_INTEGER totalSize;	ULARGE_INTEGER totalFree;	bResult = GetPhysicalDiskFreeSpaceEx(					pThis->__szFileName.c_str(),					&freeAvailable,					&totalSize,					&totalFree);	if (bResult == TRUE)		this->SetValueImpl( totalSize.QuadPart / 1024 );	else		this->SetNull( true );	*/	//TODO: Linux	/*	int ret;	store_info_t sinfo;	if((ret = GetStore(&sinfo, pThis->__szFileName.c_str())) < 0)		this->SetNull(true);	else	{		this->SetValueImpl(sinfo.capacity);	}	*/	disk_info_t diskInfo;	strncpy(diskInfo.name, pThis->__szFileName.c_str(), 256);	if(GetDiskInfo(&diskInfo))	{		this->SetValueImpl(diskInfo.capacity);	}	else	{		this->SetNull(true);	}}//==============================================================================//==============================================================================//// PhysicalDisk methods////==============================================================================//==============================================================================vector<IntelMobileString> DefaultPhysicalDiskInstanceObject::GetLogicalDisks(){	vector<IntelMobileString> vt;	for ( vector<ServerLogicalDiskInstanceObject*>::iterator it = logicaldisklist.begin(); it < logicaldisklist.end(); it++ )	{		vt.push_back( (*it)->GetKey() );			}	return vt;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -