📄 system.c
字号:
/* OpenDriverKey */
/* DESCRIPTION */
/* This function opens the driver key specified by the active key */
/* PARAMETERS */
/* ActiveKey Handle to a currently open key or any of the */
/* following predefined reserved handle values */
/* RETURN VALUES */
/* Return values is HKEY value of "[ActiveKey]\[Key]", The caller is */
/* responsible for closing the returned HKEY */
/* */
/*****************************************************************************/
static HKEY
OpenDriverKey(LPTSTR ActiveKey)
{
TCHAR DevKey[256];
HKEY hDevKey;
HKEY hActive;
DWORD ValType;
DWORD ValLen;
DWORD status;
//
// Get the device key from active device registry key
//
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, /* Handle to a currently open key */
ActiveKey, /* Pointer to subkey */
0, /* Option : Reserved - set to 0 */
0, /* samDesired : Not supported - set to 0 */
&hActive); /* Pointer for receved handele */
if (ERROR_SUCCESS != status)
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:OpenDriverKey RegOpenKeyEx(HLM\\%s) returned %d!!!\r\n"),
ActiveKey, status));
return NULL;
}
hDevKey = NULL;
ValLen = sizeof(DevKey);
status = RegQueryValueEx(hActive, /* Handle to a currently open key */
DEVLOAD_DEVKEY_VALNAME,/* Pointer to quary */
NULL, /* Reserved - set to NULL */
&ValType, /* Pointer to type of data */
(PUCHAR)DevKey, /* Pointer to data */
&ValLen); /* the Length of data */
if (ERROR_SUCCESS != status)
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:OpenDriverKey - RegQueryValueEx(%s) returned %d\r\n"),
DEVLOAD_DEVKEY_VALNAME, status));
RegCloseKey(hActive);
return hDevKey;
}
//
// Get the geometry values from the device key
//
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, /* Handle to a currently open key */
DevKey, /* Pointer to subkey */
0, /* Option : Reserved - set to 0 */
0, /* samDesired : Not supported - set to 0 */
&hDevKey); /* Pointer for receved handele */
if (ERROR_SUCCESS != status)
{
hDevKey = NULL;
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:OpenDriverKey RegOpenKeyEx - DevKey(HLM\\%s) returned %d!!!\r\n"),
DevKey, status));
}
RegCloseKey(hActive);
return hDevKey;
}
/*****************************************************************************/
/* */
/* NAME */
/* GetFolderName */
/* DESCRIPTION */
/* Function to retrieve the folder name value from the driver key */
/* The folder name is used by File System Driver to name this disk volume*/
/* PARAMETERS */
/* pDisk BIBDRV_PS driver own structure pointer */
/* FolderName
/* cBytes
/* pcBytes
/* RETURN VALUES */
/* If it successes, it returns TRUE. otherwize it returns FALSE */
/* */
/*****************************************************************************/
static BOOL
GetFolderName(PDISK pDisk,
LPWSTR FolderName,
DWORD cBytes,
DWORD *pcBytes)
{
HKEY DriverKey;
DWORD ValType;
DWORD status;
DriverKey = OpenDriverKey(pDisk->d_ActivePath);
if (NULL != DriverKey)
{
*pcBytes = cBytes;
status = RegQueryValueEx(DriverKey, /* Handle to a currently open key */
TEXT("Folder"), /* Pointer to quary */
NULL, /* Reserved - set to NULL */
&ValType, /* Pointer to type of data */
(PUCHAR)FolderName,/* Pointer to data */
pcBytes); /* the Length of data */
if (ERROR_SUCCESS != status)
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:GetFolderName - RegQueryValueEx(Folder) returned %d\r\n"),
status));
*pcBytes = 0;
}
else
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:GetFolderName - FolderName = %s, length = %d\r\n"),
FolderName, *pcBytes));
*pcBytes += sizeof(WCHAR); // account for terminating 0.
}
RegCloseKey(DriverKey);
if ((ERROR_SUCCESS != status) || (0 == *pcBytes))
{
return FALSE;
}
return TRUE;
}
return FALSE;
}
/*****************************************************************************/
/* */
/* NAME */
/* GetFSDName */
/* DESCRIPTION */
/* Function to retrieve the FSD(file system driver) value from the */
/* driver key. The FSD is used to load file system driver */
/* PARAMETERS */
/* pDisk BIBDRV_PS driver own structure pointer */
/* FSDName
/* cBytes
/* pcBytes
/* RETURN VALUES */
/* If it successes, it returns TRUE. otherwize it returns FALSE */
/* */
/*****************************************************************************/
static BOOL
GetFSDName(PDISK pDisk,
LPWSTR FSDName,
DWORD cBytes,
DWORD *pcBytes)
{
HKEY DriverKey;
DWORD ValType;
DWORD status;
DriverKey = OpenDriverKey(pDisk->d_ActivePath);
if (NULL != DriverKey)
{
*pcBytes = cBytes;
status = RegQueryValueEx(DriverKey, /* Handle to a currently open key */
TEXT("FSD"), /* Pointer to quary */
NULL, /* Reserved - set to NULL */
&ValType, /* Pointer to type of data */
(PUCHAR)FSDName, /* Pointer to data */
pcBytes); /* the Length of data */
if (ERROR_SUCCESS != status)
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:GetFSDName - RegQueryValueEx(FSD) returned %d\r\n"),
status));
*pcBytes = 0;
}
else
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:GetFSDName - FSDName = %s, length = %d\r\n"),
FSDName, *pcBytes));
*pcBytes += sizeof(WCHAR); // account for terminating 0.
}
RegCloseKey(DriverKey);
if ((ERROR_SUCCESS != status) || (0 == *pcBytes))
{
return FALSE;
}
return TRUE;
}
return FALSE;
}
#if (CE_MAJOR_VER > 0x0003)
static BOOL
GetDeviceInfo(PDISK pDisk,
PSTORAGEDEVICEINFO psdi)
{
HKEY DriverKey;
DWORD ValType;
DWORD status;
DWORD dwSize;
DriverKey = OpenDriverKey(pDisk->d_ActivePath);
if (DriverKey)
{
dwSize = sizeof(psdi->szProfile);
status = RegQueryValueEx(DriverKey, /* Handle to a currently open key */
TEXT("Profile"), /* Pointer to quary */
NULL, /* Reserved - set to NULL */
&ValType, /* Pointer to type of data */
(LPBYTE)psdi->szProfile, /* Pointer to data */
&dwSize); /* the Length of data */
if ((status != ERROR_SUCCESS) || (dwSize > sizeof(psdi->szProfile)))
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:GetFolderName - RegQueryValueEx(Profile) returned %d\r\n"),
status));
wcscpy( psdi->szProfile, L"Default");
}
else
{
BIBDRV_RTL_PRINT((TEXT("BIBDRV_PS:GetProfileName - Profile = %s, length = %d\r\n"),
psdi->szProfile, dwSize));
}
RegCloseKey(DriverKey);
}
psdi->cbSize = sizeof(STORAGEDEVICEINFO);
psdi->dwDeviceClass = STORAGE_DEVICE_CLASS_BLOCK;
psdi->dwDeviceType = STORAGE_DEVICE_TYPE_ATA; //STORAGE_DEVICE_TYPE_FLASH;
psdi->dwDeviceFlags = STORAGE_DEVICE_FLAG_READONLY; //STORAGE_DEVICE_FLAG_READWRITE;
return TRUE;
}
#endif //(CE_MAJOR_VER > 0x0003)
/*****************************************************************************/
/* */
/* NAME */
/* CloseDisk */
/* DESCRIPTION */
/* free all resources associated with the specified disk */
/* PARAMETERS */
/* pDisk BIBDRV_PS driver own structure pointer */
/* RETURN VALUES */
/* none */
/* */
/*****************************************************************************/
static VOID
CloseDisk(PDISK pDisk)
{
PDISK pd;
BIBDRV_LOG_PRINT((TEXT("[BIBDRV: IN] ++CloseDisk() pDisk=0x%x\r\n"), pDisk));
//
// Remove it from the global list of disks
//
EnterCriticalSection(&gDiskCrit);
#if defined(_BIBDRV_SECTOR_ACCESS_STATISTIC_)
LocalFree(pDisk->pSecHitStat);
#endif //(_BIBDRV_SECTOR_ACCESS_STATISTIC_)
#if defined(_BIBDRV_CACHING_SECTORS_)
BIBDRVCache_Deinit(pDisk->pCacheBuf);
#endif //(_BIBDRV_CACHING_SECTORS_)
if (pDisk == gDiskList)
{
gDiskList = pDisk->pd_next;
}
else
{
pd = gDiskList;
while (pd->pd_next != NULL)
{
if (pd->pd_next == pDisk)
{
pd->pd_next = pDisk->pd_next;
break;
}
pd = pd->pd_next;
}
}
LeaveCriticalSection(&gDiskCrit);
//
// Try to ensure this is the only thread holding the disk crit sec
//
Sleep(50);
EnterCriticalSection (&(pDisk->d_DiskCardCrit));
LeaveCriticalSection (&(pDisk->d_DiskCardCrit));
DeleteCriticalSection (&(pDisk->d_DiskCardCrit));
LocalFree(pDisk);
BIBDRV_LOG_PRINT((TEXT("[BIBDRV:OUT] --CloseDisk() pDisk=0x%x\r\n"), pDisk));
}
/*****************************************************************************/
/* */
/* NAME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -