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

📄 partition.cpp

📁 WinCE5.0部分核心源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
#include <fsdmgrp.h>
#include <storemain.h>
#include <strsafe.h>

void Disk_PowerOn(HANDLE hDsk)
{
    CPartition *pPartition = (CPartition *)hDsk;
    __try {
        if (pPartition && pPartition->m_pBlockDevice) {
            pPartition->m_pBlockDevice->PowerOn();
        }
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        ASSERT(0);
    }
}

void Disk_PowerOff(HANDLE hDsk)
{
    CPartition *pPartition = (CPartition *)hDsk;
    __try {
        if (pPartition && pPartition->m_pBlockDevice) {
            pPartition->m_pBlockDevice->PowerOff();
        }
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        ASSERT(0);
    }
}

BOOL PartitionIoControl(CPartition *pPartition, DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
{
    DWORD dwError;
    if ((dwIoControlCode == IOCTL_DISK_GETNAME) || (dwIoControlCode == DISK_IOCTL_GETNAME)){
        if (lpOutBuf && (nOutBufSize >= FOLDERNAMESIZE) && wcslen(pPartition->m_szFolderName)) {
            VERIFY(SUCCEEDED(StringCchCopy((TCHAR *)lpOutBuf, nOutBufSize, pPartition->m_szFolderName)));
            return TRUE;
        }   
    }
    SetLastError(ERROR_SUCCESS);
    dwError = pPartition->m_pPartDriver->DeviceIoControl( pPartition->m_dwPartitionId, 
                                                      dwIoControlCode, 
                                                      lpInBuf, 
                                                      nInBufSize, 
                                                      lpOutBuf, 
                                                      nOutBufSize, 
                                                      lpBytesReturned);
    if ((dwError != ERROR_SUCCESS) &&
        ((dwIoControlCode == IOCTL_DISK_READ) || 
         (dwIoControlCode == IOCTL_DISK_WRITE) || 
         (dwIoControlCode == DISK_IOCTL_WRITE) ||
         (dwIoControlCode == DISK_IOCTL_READ))) 
    {
        DEBUGMSG( ZONE_ERRORS, (L"PartitionIoControl failed with the following error %ld\r\n", dwError));        
    }
    if (dwError != ERROR_SUCCESS) {
        SetLastError(dwError);
    }
    return (ERROR_SUCCESS == dwError);
}


DWORD CPartDriver::LoadPartitionDriver(TCHAR *szPartDriver)
{
    DWORD dwError = ERROR_SUCCESS;

    m_pOpenStore = (POPENSTORE)PD_OpenStore;
    m_pCloseStore = (PCLOSESTORE)PD_CloseStore;
    m_pFormatStore = (PFORMATSTORE)PD_FormatStore;
    m_pIsStoreFormatted = (PISSTOREFORMATTED)PD_IsStoreFormatted;
    m_pGetStoreInfo = (PGETSTOREINFO)PD_GetStoreInfo;
    m_pCreatePartition = (PCREATEPARTITION)PD_CreatePartition;
    m_pDeletePartition = (PDELETEPARTITION)PD_DeletePartition;
    m_pRenamePartition = (PRENAMEPARTITION)PD_RenamePartition;
    m_pSetPartitionAttrs = (PSETPARTITIONATTRS)PD_SetPartitionAttrs;
    m_pSetPartitionSize = (PSETPARTITIONSIZE)PD_SetPartitionSize;
    m_pFormatPartition = (PFORMATPARTITION)PD_FormatPartition;
    m_pGetPartitionInfo = (PGETPARTITIONINFO)PD_GetPartitionInfo;
    m_pFindPartitionStart = (PFINDPARTITIONSTART)PD_FindPartitionStart;
    m_pFindPartitionNext = (PFINDPARTITIONNEXT)PD_FindPartitionNext;
    m_pFindPartitionClose = (PFINDPARTITIONCLOSE)PD_FindPartitionClose;
    m_pOpenPartition = (POPENPARTITION)PD_OpenPartition;
    m_pClosePartition = (PCLOSEPARTITION)PD_ClosePartition;
    m_pDeviceIoControl = (PPD_DEVICEIOCONTROL)PD_DeviceIoControl;

    if (wcslen(szPartDriver)) {
        m_hPartDriver = LoadDriver( szPartDriver);
        if (m_hPartDriver) {
            DEBUGMSG( 1, (L"Loading partition driver %s hModule=%08X\r\n", szPartDriver, m_hPartDriver));
            m_pOpenStore = (POPENSTORE)FsdGetProcAddress( m_hPartDriver, L"PD_OpenStore");
            m_pCloseStore = (PCLOSESTORE)FsdGetProcAddress( m_hPartDriver, L"PD_CloseStore");
            m_pFormatStore = (PFORMATSTORE)FsdGetProcAddress( m_hPartDriver, L"PD_FormatStore");
            m_pIsStoreFormatted = (PISSTOREFORMATTED)FsdGetProcAddress( m_hPartDriver, L"PD_IsStoreFormatted");
            m_pGetStoreInfo = (PGETSTOREINFO)FsdGetProcAddress( m_hPartDriver, L"PD_GetStoreInfo");
            m_pCreatePartition = (PCREATEPARTITION)FsdGetProcAddress( m_hPartDriver, L"PD_CreatePartition");
            m_pDeletePartition = (PDELETEPARTITION)FsdGetProcAddress( m_hPartDriver, L"PD_DeletePartition");
            m_pRenamePartition = (PRENAMEPARTITION)FsdGetProcAddress( m_hPartDriver, L"PD_RenamePartition");
            m_pSetPartitionAttrs = (PSETPARTITIONATTRS)FsdGetProcAddress( m_hPartDriver, L"PD_SetPartitionAttrs");
            m_pSetPartitionSize = (PSETPARTITIONSIZE)FsdGetProcAddress( m_hPartDriver, L"PD_SetPartitionSize");
            if (!m_pSetPartitionSize) m_pSetPartitionSize = (PSETPARTITIONSIZE)PD_SetPartitionSize;
            m_pFormatPartition = (PFORMATPARTITION)FsdGetProcAddress( m_hPartDriver, L"PD_FormatPartition");
            m_pGetPartitionInfo = (PGETPARTITIONINFO)FsdGetProcAddress( m_hPartDriver, L"PD_GetPartitionInfo");
            m_pFindPartitionStart = (PFINDPARTITIONSTART)FsdGetProcAddress( m_hPartDriver, L"PD_FindPartitionStart");
            m_pFindPartitionNext = (PFINDPARTITIONNEXT)FsdGetProcAddress( m_hPartDriver, L"PD_FindPartitionNext");
            m_pFindPartitionClose = (PFINDPARTITIONCLOSE)FsdGetProcAddress( m_hPartDriver, L"PD_FindPartitionClose");
            m_pOpenPartition = (POPENPARTITION)FsdGetProcAddress( m_hPartDriver, L"PD_OpenPartition");
            m_pClosePartition = (PCLOSEPARTITION)FsdGetProcAddress( m_hPartDriver, L"PD_ClosePartition");
            m_pDeviceIoControl = (PPD_DEVICEIOCONTROL)FsdGetProcAddress( m_hPartDriver, L"PD_DeviceIoControl");

            if (!m_pOpenStore ||
                !m_pCloseStore ||
                !m_pFormatStore ||
                !m_pIsStoreFormatted ||
                !m_pGetStoreInfo ||
                !m_pCreatePartition ||
                !m_pDeletePartition ||
                !m_pRenamePartition ||
                !m_pSetPartitionAttrs ||
                !m_pFormatPartition ||
                !m_pGetPartitionInfo ||
                !m_pFindPartitionStart ||
                !m_pFindPartitionNext ||
                !m_pFindPartitionClose ||
                !m_pOpenPartition ||
                !m_pClosePartition ||
                !m_pDeviceIoControl)
            {    
                DEBUGMSG( 1, (L"Entry points in the driver not found\r\n"));
                dwError = ERROR_BAD_DRIVER;
            }
            DEBUGMSG( 1, (L"Driver %s loaded\r\n", szPartDriver));
        } else {
            DEBUGMSG( 1, (L"Could not find/load partition driver %s\r\n", szPartDriver));
            dwError = ERROR_FILE_NOT_FOUND;
        }    
    } 
    return dwError;
}

BOOL CPartition::GetFSDString( const TCHAR *szValueName, TCHAR *szValue, DWORD dwValueSize)
{
    extern const TCHAR *g_szSTORAGE_PATH;
    TCHAR szRegKey[MAX_PATH];
    HKEY hKey;
    BOOL bSuccess = FALSE;
    
    VERIFY(SUCCEEDED(StringCchPrintf(szRegKey, MAX_PATH, L"%s\\%s", m_szRootKey, m_szFileSys)));
    if (bSuccess = (ERROR_SUCCESS == FsdRegOpenKey( szRegKey, &hKey))) {
        DUMPREGKEY(ZONE_INIT, szRegKey, hKey);
        bSuccess = FsdGetRegistryString(hKey, szValueName, szValue, dwValueSize);
        FsdRegCloseKey( hKey);
    }    
    if (!bSuccess) {
        VERIFY(SUCCEEDED(StringCchPrintf(szRegKey, MAX_PATH, L"%s\\%s", g_szSTORAGE_PATH, m_szFileSys)));
        if (bSuccess = (ERROR_SUCCESS == FsdRegOpenKey( szRegKey, &hKey))) {
            DUMPREGKEY(ZONE_INIT, szRegKey, hKey);
            bSuccess = FsdGetRegistryString(hKey, szValueName, szValue, dwValueSize);
            FsdRegCloseKey( hKey);
        }    
    }
    if (!bSuccess) 
        VERIFY(SUCCEEDED(StringCbCopy( szValue, dwValueSize, L"")));
    return bSuccess;
}

BOOL CPartition::GetFSDValue( const TCHAR *szValueName, LPDWORD pdwValue)
{
    extern const TCHAR *g_szSTORAGE_PATH;
    TCHAR szRegKey[MAX_PATH];
    HKEY hKey;
    BOOL bSuccess = FALSE;
    
    VERIFY(SUCCEEDED(StringCchPrintf(szRegKey, MAX_PATH, L"%s\\%s", m_szRootKey, m_szFileSys)));
    if (bSuccess = (ERROR_SUCCESS == FsdRegOpenKey( szRegKey, &hKey))) {
        DUMPREGKEY(ZONE_INIT, szRegKey, hKey);
        bSuccess = FsdGetRegistryValue(hKey, szValueName, pdwValue);
        FsdRegCloseKey( hKey);
    }    
    if (!bSuccess) {
        VERIFY(SUCCEEDED(StringCchPrintf(szRegKey, MAX_PATH, L"%s\\%s", g_szSTORAGE_PATH, m_szFileSys)));
        if (bSuccess = (ERROR_SUCCESS == FsdRegOpenKey( szRegKey, &hKey))) {
            DUMPREGKEY(ZONE_INIT, szRegKey, hKey);
            bSuccess = FsdGetRegistryValue(hKey, szValueName, pdwValue);
            FsdRegCloseKey( hKey);
        }    
    }
    if (!bSuccess)
        *pdwValue = 0;
    return bSuccess;
}

⌨️ 快捷键说明

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