📄 sd_info.c
字号:
/***************************************************************************
* File: sd_info.c - Get information from register and card
*
* The content of this file or document is CONFIDENTIAL and PROPRIETARY
* to Jade Technologies Co., Ltd. It is subject to the terms of a
* License Agreement between Licensee and Jade Technologies Co., Ltd.
* restricting among other things, the use, reproduction, distribution
* and transfer. Each of the embodiments, including this information
* and any derivative work shall retain this copyright notice.
*
* Copyright (c) 2005 Jade Technologies Co., Ltd.
* All rights reserved.
****************************************************************************/
#include "sd.h"
//------------------------------------------------------------------------------
// Global Macros in SD_INFO.C
//------------------------------------------------------------------------------
#define REG_PROFILE_KEY _T("Profile")
#define DEFAULT_PROFILE _T("Default")
//------------------------------------------------------------------------------
//
// Get device information
//
// Arguments:
// ActivePath - path of active device registry key
// pInfo - pointer to the buffer storaged the device information
//
//------------------------------------------------------------------------------
BOOL SDI_GetDeviceInfo(
LPWSTR ActivePath,
PSTORAGEDEVICEINFO pInfo
)
{
BOOL fRet = FALSE;
HKEY hKeyDriver;
unsigned long dwBytes;
unsigned long dwStatus;
unsigned long dwValType;
if (pInfo)
{
_tcsncpy(pInfo->szProfile, DEFAULT_PROFILE, PROFILENAMESIZE);
hKeyDriver = SDI_OpenDriverKey(ActivePath);
if (hKeyDriver)
{
// read the profile string from the active reg key if it exists
dwBytes = sizeof(pInfo->szProfile);
dwStatus = RegQueryValueEx(hKeyDriver, REG_PROFILE_KEY, NULL, &dwValType,
(unsigned char *)&pInfo->szProfile, &dwBytes);
// if this fails, szProfile will contain the default string
}
// set our class, type, and flags
pInfo->dwDeviceClass = STORAGE_DEVICE_CLASS_BLOCK;
RETAILMSG(MSG_INFO, (_T("SD: SDI_GetDeviceInfo - Device Class: 0x%x\r\n"), pInfo->dwDeviceClass));
pInfo->dwDeviceType = STORAGE_DEVICE_TYPE_UNKNOWN;
RETAILMSG(MSG_INFO, (_T("SD: SDI_GetDeviceInfo - Device Type: 0x%x\r\n"), pInfo->dwDeviceType));
pInfo->dwDeviceFlags = STORAGE_DEVICE_FLAG_READWRITE;
RETAILMSG(MSG_INFO, (_T("SD: SDI_GetDeviceInfo - Device Flags: 0x%x\r\n"), pInfo->dwDeviceFlags));
fRet = TRUE;
}
else
fRet = FALSE;
return fRet;
} // SDI_GetDeviceInfo
//------------------------------------------------------------------------------
//
// Get folder name - as the folder's name if this card controled well by
// FAT system and treat as a folder
//
// Arguments:
// ActivePath - path of active device registry key
// FolderName - record the name
// cBytes - length of the string stored the name
// pcBytes - a pointer used in the string
//
//------------------------------------------------------------------------------
BOOL SDI_GetFolderName(
LPWSTR ActivePath,
LPWSTR FolderName,
unsigned long cBytes,
unsigned long * pcBytes
)
{
BOOL fRet = FALSE;
HKEY DriverKey;
unsigned long ValType;
unsigned long status;
DriverKey = SDI_OpenDriverKey(ActivePath);
if (DriverKey)
{
*pcBytes = cBytes;
status = RegQueryValueEx(
DriverKey,
_T("Folder"),
NULL,
&ValType,
(unsigned char *)FolderName,
pcBytes);
if (status != ERROR_SUCCESS)
{
RETAILMSG(MSG_INFO, (_T("SD: SDI_GetFolderName - RegQueryValueEx(Folder) returned %d\r\n"),status));
*pcBytes = 0;
}
else
{
RETAILMSG(MSG_INFO, (_T("SD: SDI_GetFolderName - FolderName = %s, length = %d\r\n"),FolderName, *pcBytes));
*pcBytes += sizeof(WCHAR); // account for terminating 0.
}
RegCloseKey(DriverKey);
fRet = TRUE;
if (status || (*pcBytes == 0))
fRet = FALSE; // Use default
}
return fRet;
} // SDI_GetFolderName
//------------------------------------------------------------------------------
//
// Open the drivers corresponding key in register and get the device key
//
// Arguments:
// ActiveKey - active device registry key
//
//------------------------------------------------------------------------------
HKEY SDI_OpenDriverKey(
LPTSTR ActiveKey
)
{
TCHAR DevKey[256];
HKEY hDevKey;
HKEY hActive;
unsigned long ValType;
unsigned long ValLen;
unsigned long status;
// Get the device key from active device registry key
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ActiveKey, 0, 0, &hActive);
if (status)
{
RETAILMSG(MSG_INFO, (_T("SD: SDI_OpenDriverKey - RegOpenKeyEx(HLM\\%s) returned %d\r\n"),
ActiveKey, status));
return NULL;
}
hDevKey = NULL;
ValLen = sizeof(DevKey);
status = RegQueryValueEx(
hActive,
DEVLOAD_DEVKEY_VALNAME,
NULL,
&ValType,
(unsigned char *)DevKey,
&ValLen);
if (status != ERROR_SUCCESS) {
RETAILMSG(MSG_INFO, (_T("SD: SDI_OpenDriverKey - RegQueryValueEx(%s) returned %d\r\n"),
DEVLOAD_DEVKEY_VALNAME, status));
goto odk_fail;
}
// Get the geometry values from the device key
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, DevKey, 0, 0, &hDevKey);
if (status)
{
hDevKey = NULL;
RETAILMSG(MSG_INFO, (_T("SD: SDI_OpenDriverKey RegOpenKeyEx - DevKey(HLM\\%s) returned %d\r\n"),
DevKey, status));
}
odk_fail:
RegCloseKey(hActive);
return hDevKey;
} // SDI_OpenDriverKey
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -