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

📄 sdmemmain.cpp

📁 6410BSP3
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        case IOCTL_DISK_DELETE_SECTORS:
        {
            DELETE_SECTOR_INFO SafeDeleteSectorInfo = {0};
            if (0 == CeSafeCopyMemory((LPVOID)&SafeDeleteSectorInfo, (LPVOID)pInBuf, sizeof(DELETE_SECTOR_INFO))) {
                Status = ERROR_INVALID_PARAMETER;
                break;
            }
            Status = SDMemErase(pHandle, &SafeDeleteSectorInfo);
        }
            break;

        case IOCTL_POWER_CAPABILITIES:
        {
            POWER_CAPABILITIES SafePowerCapabilities = {0};
            SafeBytesReturned = sizeof(POWER_CAPABILITIES);

            // support D0 + PowerStateForIdle (D2, by default)
            SafePowerCapabilities.DeviceDx = DX_MASK(D0) | DX_MASK(pHandle->PowerStateForIdle);

            SafePowerCapabilities.Power[D0] = PwrDeviceUnspecified;
            SafePowerCapabilities.Power[D1] = PwrDeviceUnspecified;
            SafePowerCapabilities.Power[D2] = PwrDeviceUnspecified;
            SafePowerCapabilities.Power[D3] = PwrDeviceUnspecified;
            SafePowerCapabilities.Power[D4] = PwrDeviceUnspecified;

            SafePowerCapabilities.Latency[D0] = 0;
            SafePowerCapabilities.Latency[D1] = 0;
            SafePowerCapabilities.Latency[D2] = 0;
            SafePowerCapabilities.Latency[D3] = 0;
            SafePowerCapabilities.Latency[D4] = 1000;

            // no device wake
            SafePowerCapabilities.WakeFromDx = 0;
            // no inrush
            SafePowerCapabilities.InrushDx = 0;

            if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafePowerCapabilities, sizeof(POWER_CAPABILITIES))) {
                Status = ERROR_INVALID_PARAMETER;
                break;
            }
            Status = ERROR_SUCCESS;
            if (pBytesReturned) {
                if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                    Status = ERROR_INVALID_PARAMETER;
                }
            }
        }
            break;

        case IOCTL_POWER_SET:
        {
            // pOutBuf is a pointer to CEDEVICE_POWER_STATE; this is the device
            // state incd .. which to put the device; if the driver does not support
            // the requested power state, then we return the adjusted power
            // state
            CEDEVICE_POWER_STATE SafeCeDevicePowerState;
            SafeBytesReturned = sizeof(CEDEVICE_POWER_STATE);
            if (0 == CeSafeCopyMemory((LPVOID)&SafeCeDevicePowerState, (LPVOID)pOutBuf, sizeof(CEDEVICE_POWER_STATE))) {
                Status = ERROR_INVALID_PARAMETER;
                break;
            }
            Status = ERROR_SUCCESS;
            HandleIoctlPowerSet(pHandle, &SafeCeDevicePowerState);
            // return the adjusted power state
            if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafeCeDevicePowerState, sizeof(CEDEVICE_POWER_STATE))) {
                Status = ERROR_INVALID_PARAMETER;
                break;
            }
            if (pBytesReturned) {
                if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                    Status = ERROR_INVALID_PARAMETER;
                }
            }
        }
            break;

        default:
            Status = ERROR_INVALID_PARAMETER;
            break;
    }

    RequestEnd(pHandle);

ErrorStatusReturn:

    ReleaseRemovalLock(pHandle);

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: -SMC_IOControl returning %d\n"),Status == ERROR_SUCCESS));

    if (Status != ERROR_SUCCESS) {
        SetLastError(Status);
    }

    return (ERROR_SUCCESS == Status);
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_Open - the open entry point for the memory driver
//  Input:  hDeviceContext - the device context from SMC_Init
//          AccessCode - the desired access
//          ShareMode - the desired share mode
//  Output:
//  Return: open context to device instance
//  Notes:
///////////////////////////////////////////////////////////////////////////////
extern "C" DWORD WINAPI SMC_Open(
    DWORD hDeviceContext,
    DWORD AccessCode,
    DWORD ShareMode
)
{
    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +-SMC_Open\n")));
    return hDeviceContext;
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_PowerDown - the power down entry point for the bus driver
//  Input:  hDeviceContext - the device context from SMC_Init
//  Output:
//  Return:
//  Notes:  preforms no actions
///////////////////////////////////////////////////////////////////////////////
extern "C" VOID WINAPI SMC_PowerDown(DWORD hDeviceContext)
{
        // no prints allowed
    return;
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_PowerUp - the power up entry point for the CE file system wrapper
//  Input:  hDeviceContext - the device context from SMC_Init
//  Output:
//  Return:
//  Notes:  preforms no actions
///////////////////////////////////////////////////////////////////////////////
extern "C" VOID WINAPI SMC_PowerUp(DWORD hDeviceContext)
{
        // no prints allowed
    return;
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_Read - the read entry point for the memory driver
//  Input:  hOpenContext - the context from SMC_Open
//          pBuffer - the user's buffer
//          Count - the size of the transfer
//  Output:
//  Return: zero
//  Notes:  always returns zero (failure)
///////////////////////////////////////////////////////////////////////////////
extern "C" DWORD WINAPI SMC_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +-SMC_Read\n")));
    return 0;
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_Seek - the seek entry point for the memory driver
//  Input:  hOpenContext - the context from SMC_Open
//          Amount - the amount to seek
//          Type - the type of seek
//  Output:
//  Return: zero
//  Notes:  always returns zero (failure)
///////////////////////////////////////////////////////////////////////////////
extern "C" DWORD WINAPI SMC_Seek(DWORD hOpenContext, long Amount, DWORD Type)
{
    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +-SMC_Seek\n")));
    return 0;
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_Write - the write entry point for the memory driver
//  Input:  hOpenContext - the context from SMC_Open
//          pBuffer - the user's buffer
//          Count - the size of the transfer
//  Output:
//  Return: zero
//  Notes:  always returns zero (failure)
///////////////////////////////////////////////////////////////////////////////
extern "C" DWORD WINAPI SMC_Write(DWORD hOpenContext, LPCVOID pBuffer, DWORD Count)
{
    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +-SMC_Write\n")));
    return 0;
}

///////////////////////////////////////////////////////////////////////////////
//  GetDiskInfo      - return disk info in response to DISK_IOCTL_GETINFO
//  Input:  pMemCard - SD memory card structure
//  Output: pInfo    - PDISK_INFO structure containing disk parameters
//  Return: win32 status
//  Notes:
///////////////////////////////////////////////////////////////////////////////
DWORD GetDiskInfo( PSD_MEMCARD_INFO pMemCard, PDISK_INFO pInfo )
{
    *pInfo = pMemCard->DiskInfo;
    return ERROR_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////
//  SetDiskInfo      - store disk info in response to DISK_IOCTL_SETINFO
//  Input:  pMemCard - SD memory card structure
//          pInfo    - PDISK_INFO structure containing disk parameters
//  Output:
//  Return: win32 status
//  Notes
///////////////////////////////////////////////////////////////////////////////
DWORD SetDiskInfo( PSD_MEMCARD_INFO pMemCard, PDISK_INFO pInfo )
{
    pMemCard->DiskInfo = *pInfo;
    return ERROR_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////
//  GetStorageID      - Returns storage ID based on manufactured ID + serial #
//  Input:  pMemCard  - SD memory card structure
//          cBytes    - Size of psid buffer
//  Output: psid      - Storage ID structure
//          pcBytes   - Size of data written to psid
//  Return: win32 status
//  Notes:  The Storage ID gets to written to space allocated after the actual
//          PSTORAGE_IDENTIFICATION structure.
///////////////////////////////////////////////////////////////////////////////
DWORD GetStorageID( PSD_MEMCARD_INFO pMemCard,
                    PSTORAGE_IDENTIFICATION psid,
                    DWORD cBytes,
                    DWORD *pcBytes )
{
    PCHAR pDstOffset;   // destination offset for ID

    DEBUGMSG( SDCARD_ZONE_FUNC, (TEXT("SDMemory: +GetStorageID\r\n")));

        // check enough space exists in buffer
    if( cBytes < (sizeof(*psid)+SD_SIZEOF_STORAGE_ID) ) {
        DEBUGMSG( SDCARD_ZONE_ERROR, (TEXT("SDMemory: GetStorageID Insufficient buffer space\r\nSDMemory: -GetStorageID\r\n")));
        psid->dwSize = (sizeof(*psid)+SD_SIZEOF_STORAGE_ID);
        return ERROR_INSUFFICIENT_BUFFER;
    }

        // point to location after end of PSTORAGE_IDENTIFICATION
    pDstOffset = (PCHAR)(psid+1);

        // form manufacturer ID as string in the structure
    psid->dwManufactureIDOffset = pDstOffset - (PCHAR)psid;
    pDstOffset += sprintf( pDstOffset, "%02X\0", pMemCard->CIDRegister.ManufacturerID );

        // form serial number as string in the structure
    psid->dwSerialNumOffset = pDstOffset - (PCHAR)psid;
    sprintf( pDstOffset, "%08X\0", pMemCard->CIDRegister.ProductSerialNumber );

        // set structure fields
    psid->dwSize = sizeof(*psid) + SD_SIZEOF_STORAGE_ID;
    psid->dwFlags = 0;

    *pcBytes = psid->dwSize;

    DEBUGMSG( SDCARD_ZONE_FUNC, (TEXT("SDMemory: -GetStorageID\r\n")));

    return ERROR_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////
//  GetDeviceInfo  - get the device profile and information
//  Input:  pMemCard - the memory card instance
//          pStorageInfo - storage info structure to fill in
//  Output:
//  Return: returns TRUE if device information was retreived
//  Notes
///////////////////////////////////////////////////////////////////////////////
BOOL GetDeviceInfo(PSD_MEMCARD_INFO pMemCard, PSTORAGEDEVICEINFO pStorageInfo)
{
    HKEY  hDriverKey;   // driver key
    DWORD ValType;      // registry key value type
    DWORD status;       // win32 status
    DWORD dwSize;       // size of key

      // get the FolderName key if it exists
    if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                      pMemCard->pRegPath,
                      0,
                      KEY_ALL_ACCESS,
                      &hDriverKey) != ERROR_SUCCESS) {
        DEBUGMSG(SDCARD_ZONE_ERROR,
                (TEXT("SDemory: GetDeviceInfo - Failed to open reg path %s \r\n"),
                      pMemCard->pRegPath));

        return FALSE;
    }

    if (hDriverKey) {
        dwSize = sizeof(pStorageInfo->szProfile);
        status = RegQueryValueEx(
                    hDriverKey,
                    TEXT("Profile"),
                    NULL,
                    &ValType,
                    (LPBYTE)pStorageInfo->szProfile,
                    &dwSize);
        if ((status != ERROR_SUCCESS) || (dwSize > sizeof(pStorageInfo->szProfile))){
            DEBUGMSG(SDCARD_ZONE_ERROR | SDCARD_ZONE_INIT,
                (TEXT("SDemory: GetDeviceInfo - RegQueryValueEx(Profile) returned %d\r\n"),
                      status));
            wcscpy( pStorageInfo->szProfile, L"Default");
        } else {
            DEBUGMSG(SDCARD_ZONE_INIT,
                (TEXT("SDMemory: GetDeviceInfo - Profile = %s, length = %d\r\n"),
                 pStorageInfo->szProfile, dwSize));
        }
        RegCloseKey(hDriverKey);
    }

    pStorageInfo->dwDeviceClass = STORAGE_DEVICE_CLASS_BLOCK;
    pStorageInfo->dwDeviceType = STORAGE_DEVICE_TYPE_UNKNOWN;
    pStorageInfo->dwDeviceType |= STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA;

    if (pMemCard->WriteProtected) {
        pStorageInfo->dwDeviceFlags = STORAGE_DEVICE_FLAG_READONLY;
    }
    else {
        pStorageInfo->dwDeviceFlags = STORAGE_DEVICE_FLAG_READWRITE;
    }

    return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
//  SMC_PreDeinit - the deinit entry point for the memory driver
//  Input:  hDeviceContext - the context returned from SMC_Init
//  Output:
//  Return: always returns TRUE
//  Notes:
///////////////////////////////////////////////////////////////////////////////
extern "C" BOOL WINAPI SMC_PreDeinit(DWORD hDeviceContext)
{
    PSD_MEMCARD_INFO pDevice;

    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: +SMC_PreDeinit\n")));

    pDevice = (PSD_MEMCARD_INFO)hDeviceContext;

    AcquireRemovalLock(pDevice);
    pDevice->fPreDeinitCalled = TRUE;
    ReleaseRemovalLock(pDevice);

    DEBUGMSG(SDCARD_ZONE_INIT, (TEXT("SDMemory: -SMC_PreDeinit\n")));

    return TRUE;
}


// DO NOT REMOVE --- END EXTERNALLY DEVELOPED SOURCE CODE ID --- DO NOT REMOVE

⌨️ 快捷键说明

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