📄 ondisk.c
字号:
/*****************************************************************************/
/* */
/* PROJECT : PocketStoreII */
/* MODULE : Block Driver for supporting FAT File system */
/* FILE : ONDisk.c */
/* PURPOSE : This file implements Windows CE Block device driver interface */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* COPYRIGHT 2003-2006 SAMSUNG ELECTRONICS CO., LTD. */
/* ALL RIGHTS RESERVED */
/* */
/* Permission is hereby granted to licensees of Samsung Electronics */
/* Co., Ltd. products to use or abstract this computer program for the */
/* sole purpose of implementing a product based on Samsung */
/* Electronics Co., Ltd. products. No other rights to reproduce, use, */
/* or disseminate this computer program, whether in part or in whole, */
/* are granted. */
/* */
/* Samsung Electronics Co., Ltd. makes no representation or warranties */
/* with respect to the performance of this computer program, and */
/* specifically disclaims any responsibility for any damages, */
/* special or consequential, connected with the use of this program. */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* REVISION HISTORY */
/* */
/* 18-OCT-2006 [Seungkyu Kim] : first writing */
/* */
/*****************************************************************************/
#include <windows.h>
#include <bldver.h>
#include <windev.h>
#include <types.h>
#include <excpt.h>
#include <tchar.h>
#include <devload.h>
#include <diskio.h>
#include <storemgr.h>
#include <WMRConfig.h>
#include <WMRTypes.h>
#include "ONDisk.h"
#include <VFLBuffer.h>
#include <HALWrapper.h>
#include <config.h>
#include <WMR.h>
#include <WMR_Utils.h>
/*****************************************************************************/
/* STL Configuration */
/*****************************************************************************/
#define PSII_MAX_READ_BUF_SIZE (WMR_SECTOR_SIZE * 16)
/*****************************************************************************/
/* Debug Definitions */
/*****************************************************************************/
#define STDRV_RTL_PRINT(x) PSII_DBG_PRINT(x)
#if STDRV_ERR_MSG_ON
#define STDRV_ERR_PRINT(x) PSII_DBG_PRINT(x)
#else
#define STDRV_ERR_PRINT(x)
#endif /* #if STDRV_ERR_MSG_ON */
#if STDRV_LOG_MSG_ON
#define STDRV_LOG_PRINT(x) PSII_DBG_PRINT(x)
#else
#define STDRV_LOG_PRINT(x)
#endif /* #if STDRV_LOG_MSG_ON */
#if STDRV_INF_MSG_ON
#define STDRV_INF_PRINT(x) PSII_DBG_PRINT(x)
#else
#define STDRV_INF_PRINT(x)
#endif /* #if STDRV_INF_MSG_ON */
#define STL_DELETE_DBG 0
/*****************************************************************************/
/* Global Variables */
/*****************************************************************************/
CRITICAL_SECTION v_DiskCrit;
PDISK v_DiskList; // initialized to 0 in bss
/* Debug Zones.
*/
#ifdef DEBUG
DBGPARAM dpCurSettings = {
L"ONDISK", {
L"Undefined", L"Undefined", L"Undefined", L"Undefined",
L"Undefined", L"Undefined", L"Undefined", L"Undefined",
L"Undefined", L"Undefined", L"Undefined", L"Undefined",
L"Undefined", L"Undefined", L"Undefined", L"Undefined"
},
0x0000
};
#endif
/*****************************************************************************/
/* Imported variable declarations */
/*****************************************************************************/
/*****************************************************************************/
/* Imported function declarations */
/*****************************************************************************/
/*****************************************************************************/
/* Local #define */
/*****************************************************************************/
#undef RESERVED_REGION_SUPPORT
/*****************************************************************************/
// Local constant definitions
/*****************************************************************************/
/*****************************************************************************/
// Local typedefs
/*****************************************************************************/
/*****************************************************************************/
// Local function prototypes
/*****************************************************************************/
static HKEY OpenDriverKey(LPTSTR ActiveKey);
static BOOL GetFolderName(PDISK pDisk, LPWSTR FolderName, DWORD cBytes, DWORD *pcBytes);
static BOOL GetBmlPartitionId(PDISK pDisk);
//static BOOL GetFSDName(PDISK pDisk, LPWSTR FSDName, DWORD cBytes, DWORD *pcBytes);
static VOID CloseDisk(PDISK pDisk);
static DWORD DoDiskRead(PDISK pDisk, PVOID pData);
static DWORD DoDiskWrite(PDISK pDisk, PVOID pData);
static DWORD DoDiskDeleteSectors(PDISK pDisk, PVOID pData);
static BOOL GetDeviceInfo(PDISK pDisk, PSTORAGEDEVICEINFO psdi);
static BOOL GetStorageID(PDISK pDisk, PSTORAGE_IDENTIFICATION psid, DWORD cBytes, DWORD * pcBytes);
static DWORD GetDiskInfo (PDISK pDisk, PDISK_INFO pInfo);
static DWORD SetDiskInfo (PDISK pDisk, PDISK_INFO pInfo);
static PDISK CreateDiskObject (VOID);
static BOOL IsValidDisk (PDISK pDisk);
static BOOL InitializeFTL (PDISK pDisk);
static BOOL InitDisk (PDISK pDisk, LPTSTR ActiveKey);
/*****************************************************************************/
// Function definitions
/*****************************************************************************/
/*****************************************************************************/
/* */
/* NAME */
/* 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 = 0;
STDRV_RTL_PRINT((TEXT("[OND:OUT] ++OpenDriverKey()\r\n")));
//
// Get the device key from active device registry key
//
STDRV_RTL_PRINT((TEXT("[OND: ] OpenDriverKey RegOpenKeyEx(HLM\\%s) returned %d!!!\r\n"),
ActiveKey, status));
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)
{
STDRV_LOG_PRINT((TEXT("[OND: ] OpenDriverKey RegOpenKeyEx(HLM\\%s) returned %d!!!\r\n"),
ActiveKey, status));
STDRV_RTL_PRINT((TEXT("[OND: ] OpenDriverKey RegOpenKeyEx(HLM\\%s) returned %d!!!\r\n"),
ActiveKey, status));
return NULL;
}
hDevKey = NULL;
ValLen = sizeof(DevKey);
STDRV_RTL_PRINT((TEXT("[OND: ] OpenDriverKey - RegQueryValueEx(%s) returned %d\r\n"),
DEVLOAD_DEVKEY_VALNAME, status));
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)
{
STDRV_LOG_PRINT((TEXT("[OND: ] OpenDriverKey - RegQueryValueEx(%s) returned %d\r\n"),
DEVLOAD_DEVKEY_VALNAME, status));
STDRV_RTL_PRINT((TEXT("[OND: ] 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;
STDRV_LOG_PRINT((TEXT("[OND: ] OpenDriverKey RegOpenKeyEx - DevKey(HLM\\%s) returned %d!!!\r\n"),
DevKey, status));
STDRV_RTL_PRINT((TEXT("[OND: ] OpenDriverKey RegOpenKeyEx - DevKey(HLM\\%s) returned %d!!!\r\n"),
DevKey, status));
}
RegCloseKey(hActive);
STDRV_RTL_PRINT((TEXT("[OND:OUT] --OpenDriverKey()\r\n")));
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 PocketStoreII 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;
// HKEY hActive;
DWORD ValType;
DWORD status;
// Get Profile from Builtin Key
EnterCriticalSection(&(pDisk->d_DiskCardCrit));
{
DriverKey = OpenDriverKey(pDisk->d_ActivePath);
if (NULL == DriverKey)
{
return FALSE;
}
*pcBytes = cBytes;
status = RegQueryValueEx(DriverKey,
TEXT("Folder"),
NULL,
&ValType,
(PUCHAR)FolderName,
pcBytes);
if (ERROR_SUCCESS != status)
{
STDRV_RTL_PRINT((TEXT("[OND: ] GetFolderName - RegQueryValueEx(Folder) returned %d\r\n"),
status));
*pcBytes = 0;
}
else
{
STDRV_RTL_PRINT((TEXT("[OND:MSG] GetFolderName - Folder = %s, length = %d\r\n"),
FolderName, *pcBytes));
*pcBytes += sizeof(WCHAR); // account for terminating 0.
}
RegCloseKey(DriverKey);
if ((ERROR_SUCCESS != status) || (0 == *pcBytes))
{
return FALSE;
}
}
LeaveCriticalSection(&(pDisk->d_DiskCardCrit));
return TRUE;
}
/*****************************************************************************/
/* */
/* NAME */
/* GetBmlPartitionId */
/* DESCRIPTION */
/* Function to retrieve BML partition ID for STL API */
/* PARAMETERS */
/* pDisk PocketStoreII driver own structure pointer */
/* RETURN VALUES */
/* If it successes, it returns TRUE. otherwize it returns FALSE */
/* */
/*****************************************************************************/
static BOOL
GetBmlPartitionId(PDISK pDisk)
{
HKEY DriverKey;
DWORD ValType;
DWORD status;
DWORD nBytes=4;
EnterCriticalSection(&(pDisk->d_DiskCardCrit));
DriverKey = OpenDriverKey(pDisk->d_ActivePath);
if (NULL == DriverKey)
{
return FALSE;
}
// Get BmlPartitionId from Builtin Key
status = RegQueryValueEx(DriverKey,
TEXT("BmlPartitionId"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -