📄 cfc_info.c
字号:
/***************************************************************************
* File: cfc_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 "cfcard.h"
//------------------------------------------------------------------------------
// Global Macros in CF_INFO.C
//------------------------------------------------------------------------------
#define REG_PROFILE_KEY _T("Profile")
#define DEFAULT_PROFILE _T("Default")
//------------------------------------------------------------------------------
//
// Get device information
//
// Arguments:
// pDisk - the opened instance
// pInfo - pointer to the buffer storaged the device information
//
//------------------------------------------------------------------------------
BOOL
CFC_GetDeviceInfo(
PDISK pDisk,
PSTORAGEDEVICEINFO pInfo
)
{
BOOL fRet = FALSE;
HKEY hKeyDriver;
unsigned long dwBytes;
unsigned long dwStatus;
unsigned long dwValType;
if (pDisk && pInfo)
{
_tcsncpy(pInfo->szProfile, DEFAULT_PROFILE, PROFILENAMESIZE);
hKeyDriver = CFC_OpenDriverKey(pDisk->d_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("CFCARD: GetDeviceInfo - Device Class: 0x%x\r\n"), pInfo->dwDeviceClass));
pInfo->dwDeviceType = STORAGE_DEVICE_TYPE_UNKNOWN;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDeviceInfo - Device Type: 0x%x\r\n"), pInfo->dwDeviceType));
pInfo->dwDeviceFlags = STORAGE_DEVICE_FLAG_READWRITE;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDeviceInfo - Device Flags: 0x%x\r\n"), pInfo->dwDeviceFlags));
fRet = TRUE;
}
else
fRet = FALSE;
return fRet;
}
//------------------------------------------------------------------------------
//
// Get folder name - as the folder's name if this card controled well by
// FAT system and treat as a folder
//
// Arguments:
// pDisk - the opened instance
// FolderName - record the name
// cBytes - length of the string stored the name
// pcBytes - a pointer used in the string
//
//------------------------------------------------------------------------------
BOOL
CFC_GetFolderName(
PDISK pDisk,
LPWSTR FolderName,
unsigned long cBytes,
unsigned long * pcBytes
)
{
BOOL fRet = FALSE;
HKEY DriverKey;
unsigned long ValType;
unsigned long status;
DriverKey = CFC_OpenDriverKey(pDisk->d_ActivePath);
if (DriverKey)
{
*pcBytes = cBytes;
status = RegQueryValueEx(DriverKey, _T("Folder"), NULL,
&ValType, (unsigned char *)FolderName, pcBytes);
if (status != ERROR_SUCCESS)
{
RETAILMSG(MSG_INFO, (_T("CFCARD: GetFolderName - RegQueryValueEx(Folder) returned %d\r\n"),status));
*pcBytes = 0;
}
else
{
RETAILMSG(MSG_INFO, (_T("CFCARD: 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;
}
//------------------------------------------------------------------------------
//
// Get disk information - important for FAT system to manage the card
//
// Arguments:
// pDisk - the opened instance
// pInfo - structure of disk information
//
//------------------------------------------------------------------------------
unsigned long
CFC_GetDiskInfo(
PDISK pDisk,
PDISK_INFO pInfo
)
{
PCFRegs regs = (PCFRegs) pDisk->d_pCFCardRegs;
unsigned long k = SleepCircle;
unsigned char status, error;
unsigned short buf[(BYTES_PER_SECTOR/2)];
unsigned long i;
AtaSetCommand(regs, ATA_CMD_IDENTIFY);
while (k--)
{
AtaReadStatus(regs, status);
if (status == 0x58) //addr7, status
break;
if (status & (0x01))
{
AtaReadError(regs, error);
return 0;
}
}
if (!k)
{
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Wrong Status\r\n")));
return 0;
}
i=0;
while (i < (int)(BYTES_PER_SECTOR/2))
{
AtaReadData(regs, buf[i++]);
AtaReadStatus(regs, error);
if (error == 0x50)
break;
if (error & 0x01)
return 0;
}
pInfo->di_total_sectors = *((unsigned long *) ((unsigned char *)buf+60*2));
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Total Sectors: 0x%x\r\n"), pInfo->di_total_sectors));
pInfo->di_bytes_per_sect = BYTES_PER_SECTOR;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Bytes per Sector: 0x%x\r\n"), pInfo->di_bytes_per_sect));
pInfo->di_cylinders = ((PIDENTIFY_DATA) buf)->NumberOfCylinders;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Cylinders: 0x%x\r\n"), pInfo->di_cylinders));
pInfo->di_heads = ((PIDENTIFY_DATA) buf)->NumberOfHeads;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Heads: 0x%x\r\n"), pInfo->di_heads));
pInfo->di_sectors = ((PIDENTIFY_DATA) buf)->SectorsPerTrack;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Sectors: 0x%x\r\n"), pInfo->di_sectors));
pInfo->di_flags = DISK_INFO_FLAG_MBR;
RETAILMSG(MSG_INFO, (_T("CFCARD: GetDiskInfo - Flags: 0x%x\r\n"), pInfo->di_flags));
return 1;
} // GetDiskInfo
//------------------------------------------------------------------------------
//
// Open the drivers corresponding key in register and get the device key
//
// Arguments:
// ActiveKey - active device registry key
//
//------------------------------------------------------------------------------
HKEY
CFC_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("CFCARD: 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("CFCARD: 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("CFCARD: OpenDriverKey RegOpenKeyEx - DevKey(HLM\\%s) returned %d\r\n"),
DevKey, status));
}
odk_fail:
RegCloseKey(hActive);
return hDevKey;
} // OpenDriverKey
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -