📄 instance_logicaldisk.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_LogicalDisk.h"#include "inc/framework/base_Enum.h"#include "inc/base/Layer_Manager.h"#include "storage_util.h"//==============================================================================//// DefaultLogicalDiskInstanceObject implementation////==============================================================================bool DefaultLogicalDiskInstanceObject::Initialize( const IntelMobileString& szKey ){ _Log(IntelMobileText("DefaultLogicalDiskInstanceObject::Initialize(%s)"), szKey.c_str()); m_sKey = szKey; __szFileName = szKey; this->Id.SetValue( szKey ); return true;}LPTSTR DefaultLogicalDiskInstanceObject::GetLogicalDiskFileName(IntelMobileString& Internalkey){ //No use on embedded Linux return NULL; /*try { Lock(); LPTSTR partitionfilename=(LPTSTR)malloc(4*sizeof(TCHAR)); HANDLE hDevice; DWORD nBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION_EX) + sizeof(PARTITION_INFORMATION_EX)*100; PDRIVE_LAYOUT_INFORMATION_EX drivelayoutinfo = (PDRIVE_LAYOUT_INFORMATION_EX)malloc(nBufferSize); ULONG lpBytesReturned; LARGE_INTEGER mValue; LARGE_INTEGER mLength; int NumberOfPartition = 0; hDevice= ::CreateFile( (GetDevicePath(__szFileName,NumberOfPartition)).c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if(hDevice == INVALID_HANDLE_VALUE) { Unlock(); return NULL; }; BOOL status = DeviceIoControl( (HANDLE) hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, NULL, 0, drivelayoutinfo, (DWORD) nBufferSize, &lpBytesReturned, NULL ); int CurrentNumberofPartition = NumberOfPartition; if(status) { while(drivelayoutinfo->PartitionEntry[NumberOfPartition].PartitionNumber != CurrentNumberofPartition+1) { NumberOfPartition++; } CurrentNumberofPartition++; mValue.HighPart = drivelayoutinfo->PartitionEntry[NumberOfPartition].StartingOffset.HighPart; mValue.LowPart = drivelayoutinfo->PartitionEntry[NumberOfPartition].StartingOffset.LowPart; mLength.HighPart = drivelayoutinfo->PartitionEntry[NumberOfPartition].PartitionLength.HighPart; mLength.LowPart = drivelayoutinfo->PartitionEntry[NumberOfPartition].PartitionLength.LowPart; if ( hDevice != NULL ) { CloseHandle ( hDevice ); }; DWORD pnBufferSize = sizeof(PARTITION_INFORMATION_EX); PARTITION_INFORMATION_EX pdrivelayoutinfo; ULONG plpBytesReturned; LPTSTR a = (LPTSTR)malloc(7*sizeof(TCHAR)); int DSLength = GetLogicalDriveStrings(0,NULL); wchar_t* DStr = new wchar_t[DSLength]; GetLogicalDriveStrings(DSLength,(LPTSTR)DStr); int si=0; wchar_t dir; for(int i=0;i<DSLength/4;++i) { dir=DStr[si]; a[0] = L'\\'; a[1] = L'\\'; a[2] = L'.'; a[3] = L'\\'; a[4] = dir; a[5] = L':'; a[6] = L'\0'; LPTSTR ma = (LPTSTR)a; HANDLE hDevice; if (( hDevice = CreateFile( ma, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE) { if ( DeviceIoControl( hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &pdrivelayoutinfo, pnBufferSize, &plpBytesReturned, NULL ) ) { if((pdrivelayoutinfo.StartingOffset.HighPart == mValue.HighPart)&&(pdrivelayoutinfo.StartingOffset.LowPart == mValue.LowPart) &&(pdrivelayoutinfo.PartitionLength.HighPart == mLength.HighPart)&&(pdrivelayoutinfo.PartitionLength.LowPart == mLength.LowPart)) { partitionfilename[0] = a[4]; partitionfilename[1] = a[5]; partitionfilename[2] = L'\\'; partitionfilename[3] = L'\0'; Unlock(); return partitionfilename; } } } if ( hDevice != NULL ) { CloseHandle ( hDevice ); }; si+=4; }//endfor }//endif Unlock(); return NULL; } catch(...) { Unlock(); THROWIMEXCEPTION(ExceptionNumber+2); }*/}IntelMobileString DefaultLogicalDiskInstanceObject::GetDevicePath(IntelMobileString& Internalkey,/*out*/ int& NumberOfPartition){ //No use on embedded Linux IntelMobileString ret(""); return ret; /*try { Lock(); IntelMobileString DevicePath; bool flag = false; for ( IntelMobileString::iterator it = Internalkey.begin(); it < Internalkey.end(); it++ ) { if ((*it) == L'\\') { flag = true; break; } else { NumberOfPartition = (int)(*it)-49; } } if (flag) { for ( IntelMobileString::iterator it1 = it; it1 < Internalkey.end(); it1++ ) { DevicePath += (*it1); } } Unlock(); return DevicePath; } catch(...) { Unlock(); THROWIMEXCEPTION(ExceptionNumber+3); }*/}DefaultLogicalDiskInstanceObject::~DefaultLogicalDiskInstanceObject(){ _Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace: DefaultLogicalDiskInstanceObject::~DefaultLogicalDiskInstanceObject()") );}//==============================================================================//==============================================================================//// LogicalDisk 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 LogicalDiskIDClass::GetValueImpl(){ //TODO: Linux this->SetValueImpl( IntelMobileText("") );}bool LogicalDiskLabelClass::SetValueImplOnDevice ( IntelMobileString value ){ //No use on embedded Linux DefaultLogicalDiskInstanceObject *pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; if(!pThis) return false; this->SetNull(true); return false;/* try { pThis->Lock(); if(!(pThis->Pnet)) { LPTSTR LogicalDiskFileName = pThis->GetLogicalDiskFileName(pThis->__szFileName); BOOL Ret = SetVolumeLabel(LogicalDiskFileName,value.c_str() ); if(Ret) { pThis->Unlock(); return true; } else { SetNull(true); pThis->Unlock(); return false; } } else { this->SetNull(true); pThis->Unlock(); return false; } } catch(...) { pThis->Unlock(); THROWIMEXCEPTION(ExceptionNumber+4); } */}void LogicalDiskLabelClass::GetValueImpl(){ //TODO: Linux this->SetValueImpl( IntelMobileText("") );}void LogicalDiskEntryPathsClass::GetValueImpl(){ this->Clear(); DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; /* wstring ws(IntelMobileText("\\")); ws.append(pThis->__szFileName); this->InsertValueImpl( ws.c_str() ); */ //TODO: Linux /* int ret; store_info_t sinfo; if((ret = GetStore(&sinfo, pThis->__szFileName.c_str())) < 0) this->InsertValueImpl( IntelMobileText("") ); else this->InsertValueImpl(sinfo.mount_dir); */ part_info_t partInfo; strncpy(partInfo.name, pThis->__szFileName.c_str(), 256); //if(GetLogicalDiskInfo(&partInfo)) if(GetPartitionInfo(&partInfo)) { this->InsertValueImpl(partInfo.mount_dir); } else { this->InsertValueImpl(IntelMobileText("")); }}void LogicalDiskAccessClass::GetValueImpl(){ //TODO: Linux /* int ret; store_info_t sinfo; DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; if((ret = GetStore(&sinfo, pThis->__szFileName.c_str())) < 0) this->SetNull( true ); else { switch(sinfo.access) { case RO: this->SetValueImpl(ReadOnly); break; case RW: this->SetValueImpl(ReadWrite); break; case UNKNOWN_ACCESS: this->SetNull(true); break; } } */ part_info_t sinfo; DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; strncpy(sinfo.name, pThis->__szFileName.c_str(), 256); if(!GetPartitionInfo(&sinfo)) this->SetNull( true ); else { switch(sinfo.access) { case RO: this->SetValueImpl(LogicalDiskAccessEnum::ReadOnly); break; case RW: this->SetValueImpl(LogicalDiskAccessEnum::ReadWrite); break; case UNKNOWN_ACCESS: this->SetNull(true); break; } }}void LogicalDiskFormatClass::GetValueImpl(){ //TODO: Linux //this->SetNull( true ); /* int ret; store_info_t sinfo; DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; if((ret = GetStore(&sinfo, pThis->__szFileName.c_str())) < 0) this->SetNull( true ); else { switch(sinfo.fs_type) { case VFATFS: this->SetValueImpl(FAT16); break; case JJFS: this->SetValueImpl(JFS); break; case EXT2FS: this->SetValueImpl(EXT2); break; case EXT3FS: this->SetValueImpl(EXT3); break; default: this->SetValueImpl(UnknownFormat); break; } } */ part_info_t sinfo; DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; strncpy(sinfo.name, pThis->__szFileName.c_str(), 256); if(!GetPartitionInfo(&sinfo)) this->SetNull( true ); else { switch(sinfo.fs_type) { case VFATFS: this->SetValueImpl(LogicalDiskFormatEnum::Fat16); break; case JJFS: this->SetValueImpl(LogicalDiskFormatEnum::Jfs); break; case EXT2FS: this->SetValueImpl(LogicalDiskFormatEnum::Ext2); break; case EXT3FS: this->SetValueImpl(LogicalDiskFormatEnum::Ext3); break; default: this->SetValueImpl(LogicalDiskFormatEnum::Unknown); break; } }}void LogicalDiskLocationClass::GetValueImpl(){ //hard code //TODO: Linux //this->SetValueImpl( Local ); DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; //if(pThis->bNet) if(pThis->Pnet) { this->SetValueImpl(LogicalDiskLocationEnum::Remote); } else { this->SetValueImpl(LogicalDiskLocationEnum::Local); } //printf(",bug in LogicalDiskLocationClass::GetValueImp\n"); }void LogicalDiskCapacityClass::GetValueImpl(){ /* 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 part_info_t sinfo; DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; strncpy(sinfo.name, pThis->__szFileName.c_str(), 256); if(!GetPartitionInfo(&sinfo)) this->SetNull(true); else this->SetValueImpl(sinfo.capacity);}void LogicalDiskFreeSpaceClass::GetValueImpl(){ /* 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( freeAvailable.QuadPart / 1024 ); else this->SetNull( true ); */ //TODO: Linux //this->SetNull( true ); part_info_t sinfo; DefaultLogicalDiskInstanceObject* pThis = (DefaultLogicalDiskInstanceObject*) this->_pThis; strncpy(sinfo.name, pThis->__szFileName.c_str(), 256); if(!GetPartitionInfo(&sinfo)) this->SetNull(true); else this->SetValueImpl(sinfo.free);}//==============================================================================//==============================================================================//// LogicalDisk methods////==============================================================================//==============================================================================/*PhysicalDiskList DefaultLogicalDiskInstanceObject::GetPhysicalDisks(){ PhysicalDiskList diskVector; ServerInstanceObject *pInc; ServerPhysicalDiskInstanceObject *pPhysicalDiskInstance; ServerPhysicalDiskClassObject *pPhysicalDiskClass = reinterpret_cast<ServerPhysicalDiskClassObject *>(&(GetLayer()->GetLayerClassObject(IntelMobileText("PhysicalDisk")))); ServerInstanceCollection *pPhysicalDiskCollection = pPhysicalDiskClass->GetInstances(); if ( pPhysicalDiskCollection != NULL ) { long lChangedIndex; int iEnumIndex = 0; pPhysicalDiskCollection->Reset(&lChangedIndex); while ( pPhysicalDiskCollection->HasNext(iEnumIndex, lChangedIndex) ) { pPhysicalDiskCollection->Next(&pInc, &iEnumIndex, lChangedIndex); if ( pInc != NULL ) { pPhysicalDiskInstance = reinterpret_cast<ServerPhysicalDiskInstanceObject*>(pInc); if ( pPhysicalDiskInstance->ID.GetValue() == this->__szFileName ) { diskVector.push_back( pPhysicalDiskInstance ); break; } } } } return diskVector;}*/vector<IntelMobileString> DefaultLogicalDiskInstanceObject::GetPhysicalDisks(){ vector<IntelMobileString> vt; for ( vector<ServerPhysicalDiskInstanceObject*>::iterator it = physicaldisklist.begin(); it < physicaldisklist.end(); it++ ) { vt.push_back( (*it)->GetKey() ); } return vt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -