📄 storemain.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
#include <windows.h>
#include <store.h>
#include <partdrv.h>
#include <fsdmgrp.h>
#include <storemain.h>
#ifdef UNDER_CE
#include <msgqueue.h>
#include <pnp.h>
#include <windev.h>
#endif
CRITICAL_SECTION g_csStoreMgr;
CStore *g_pStoreRoot = NULL;
PSTOREHANDLE g_pRootHandle = NULL;
HANDLE g_hFindStoreApi = NULL;
HANDLE g_hFindPartApi = NULL;
HANDLE g_hStoreApi = NULL;
HANDLE g_hSTRMGRApi = NULL;
HANDLE g_hBlockDevApi = NULL;
HANDLE g_hPNPQueue = NULL;
HANDLE g_hPNPThread = NULL;
HANDLE g_hPNPUpdateEvent = NULL;
DWORD g_dwUpdateState = 0;
DWORD g_dwWaitIODelay = 0;
HANDLE g_hAutoLoadEvent = NULL;
HANDLE STRMGR_CreateFileW(DWORD dwData, HANDLE hProc, PCWSTR pwsFileName, DWORD dwAccess, DWORD dwShareMode, PSECURITY_ATTRIBUTES pSecurityAttributes, DWORD dwCreate, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
BOOL STRMGR_RefreshStore(DWORD dwData, PWSTR pwsFileName, PCWSTR szReserved);
HANDLE STRMGR_FindFirstFileW(DWORD dwData, HANDLE hProc, PCWSTR pwsFileSpec, PWIN32_FIND_DATAW pfd);
BOOL STRMGR_CloseAllHandles(DWORD dwData, HANDLE hProc);
DWORD STRMGR_StubFunction(){ return 0;}
typedef HANDLE (* PREQUESTDEVICENOT)(const GUID *devclass, HANDLE hMsgQ, BOOL fAll);
typedef BOOL (* PSTOPDEVICENOT)(HANDLE h);
#ifdef UNDER_CE
CONST PFNAPI apfnFindStoreAPIs[NUM_FIND_APIS] = {
(PFNAPI)STG_FindCloseStore,
(PFNAPI)NULL,
(PFNAPI)STG_FindNextStore,
};
CONST DWORD asigFindStoreAPIs[NUM_FIND_APIS] = {
FNSIG1(DW), // FindClose
FNSIG0(), //
FNSIG2(DW, PTR) // FindNextFileW
};
CONST PFNAPI apfnFindPartAPIs[NUM_FIND_APIS] = {
(PFNAPI)STG_FindClosePartition,
(PFNAPI)NULL,
(PFNAPI)STG_FindNextPartition,
};
CONST DWORD asigFindPartAPIs[NUM_FIND_APIS] = {
FNSIG1(DW), // FindClose
FNSIG0(), //
FNSIG2(DW, PTR) // FindNextFileW
};
#define NUM_STG_APIS 15
CONST PFNAPI apfnSTGAPIs[NUM_STG_APIS] = {
(PFNAPI)STG_CloseHandle,
(PFNAPI)STG_GetStoreInfo,
(PFNAPI)STG_DismountStore,
(PFNAPI)STG_FormatStore,
(PFNAPI)STG_CreatePartition,
(PFNAPI)STG_DeletePartition,
(PFNAPI)STG_OpenPartition,
(PFNAPI)STG_MountPartition,
(PFNAPI)STG_DismountPartition,
(PFNAPI)STG_RenamePartition,
(PFNAPI)STG_SetPartitionAttributes,
(PFNAPI)STG_DeviceIoControl,
(PFNAPI)STG_GetPartitionInfo,
(PFNAPI)STG_FormatPartition,
(PFNAPI)STG_FindFirstPartition
};
CONST DWORD asigSTGAPIs[NUM_STG_APIS] = {
FNSIG1(DW), // CloseHandle
FNSIG2(DW, PTR), // GetStoreInfo
FNSIG1(DW), // DismountStore
FNSIG1(DW), // FormatStore
FNSIG5(DW, PTR, DW, DW, DW), // CreatePartition
FNSIG2(DW, PTR), // DeletePartition
FNSIG2(DW, PTR), // OpenPartition
FNSIG1(DW), // MountPartition,
FNSIG1(DW), // DismountPartition
FNSIG2(DW, PTR), // RenamePartition
FNSIG2(DW, DW), // SetPartitionAttributes
FNSIG8(DW, DW, PTR, DW, PTR, DW, PTR, PTR), // DeviceIoControl
FNSIG2(DW, PTR), // GetPartitionInfo
FNSIG3(DW, DW, DW), // FormatPartition
FNSIG2(DW, PTR), // FindFirstPartition
};
CONST PFNAPI apfnSTGMGRAPIs[NUM_AFS_APIS] = {
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)NULL,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_CreateFileW,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_RefreshStore,
(PFNAPI)STRMGR_FindFirstFileW,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_CloseAllHandles,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
(PFNAPI)STRMGR_StubFunction,
};
CONST DWORD asigSTGMGRAPIs[NUM_AFS_APIS] = {
FNSIG1(DW), // CloseVolume
FNSIG0(), //
FNSIG3(DW, PTR, PTR), // CreateDirectoryW
FNSIG2(DW, PTR), // RemoveDirectoryW
FNSIG2(DW, PTR), // GetFileAttributesW
FNSIG3(DW, PTR, DW), // SetFileAttributesW
FNSIG9(DW, DW, PTR, DW, DW, PTR, DW, DW, DW), // CreateFileW
FNSIG2(DW, PTR), // DeleteFileW
FNSIG3(DW, PTR, PTR), // MoveFileW
FNSIG4(DW, DW, PTR, PTR), // FindFirstFileW
FNSIG2(DW, DW), // CeRegisterFileSystemNotification
FNSIG3(DW, DW, PTR), // CeOidGetInfo
FNSIG3(DW, PTR, PTR), // PrestoChangoFileName
FNSIG2(DW, DW), // CloseAllFiles
FNSIG6(DW, PTR, PTR, PTR, PTR, PTR), // GetDiskFreeSpace
FNSIG2(DW, DW), // Notify
FNSIG2(DW, DW), // CeRegisterFileSystemFunction
FNSIG5(DW, DW, PTR, DW, DW), // FindFirstChangeNotification
FNSIG0(), // FindNextChangeNotification
FNSIG0(), // FindCloseChangeNotification
FNSIG0(), // CeGetFileNotificaitonInfo
FNSIG8(DW, DW, PTR, DW, PTR, DW, PTR, PTR) // FsIoControl
};
const PFNVOID DevFileApiMethods[] = {
(PFNVOID)FS_DevCloseFileHandle,
(PFNVOID)0,
(PFNVOID)FS_DevReadFile,
(PFNVOID)FS_DevWriteFile,
(PFNVOID)FS_DevGetFileSize,
(PFNVOID)FS_DevSetFilePointer,
(PFNVOID)FS_DevGetFileInformationByHandle,
(PFNVOID)FS_DevFlushFileBuffers,
(PFNVOID)FS_DevGetFileTime,
(PFNVOID)FS_DevSetFileTime,
(PFNVOID)FS_DevSetEndOfFile,
(PFNVOID)FS_DevDeviceIoControl,
};
#define NUM_FAPIS (sizeof(DevFileApiMethods)/sizeof(DevFileApiMethods[0]))
const DWORD DevFileApiSigs[NUM_FAPIS] = {
FNSIG1(DW), // CloseFileHandle
FNSIG0(),
FNSIG5(DW,PTR,DW,PTR,PTR), // ReadFile
FNSIG5(DW,PTR,DW,PTR,PTR), // WriteFile
FNSIG2(DW,PTR), // GetFileSize
FNSIG4(DW,DW,PTR,DW), // SetFilePointer
FNSIG2(DW,PTR), // GetFileInformationByHandle
FNSIG1(DW), // FlushFileBuffers
FNSIG4(DW,PTR,PTR,PTR), // GetFileTime
FNSIG4(DW,PTR,PTR,PTR), // SetFileTime
FNSIG1(DW), // SetEndOfFile,
FNSIG8(DW, DW, PTR, DW, PTR, DW, PTR, PTR), // DeviceIoControl
};
#endif // UNDER_CE
BOOL STRMGR_CloseAllHandles(DWORD dwData, HANDLE hProc)
{
return TRUE;
}
BOOL IsValidStore(CStore *pStore)
{
if (!pStore || (pStore == INVALID_STORE))
return FALSE;
LockStoreMgr();
CStore *pTemp = g_pStoreRoot;
while( pTemp) {
if (pTemp == pStore) {
break;
}
pTemp = pTemp->m_pNextStore;
}
UnlockStoreMgr();
return pTemp != NULL;
}
void AddStore(CStore *pStore)
{
// TODO: Add in the order of Disk Index ???
if (g_pStoreRoot) {
CStore *pTemp = g_pStoreRoot;
while(pTemp->m_pNextStore) {
pTemp = pTemp->m_pNextStore;
}
pTemp->m_pNextStore = pStore;
} else {
g_pStoreRoot = pStore;
}
}
void DeleteStore(CStore *pStore)
{
CStore *pTemp = g_pStoreRoot;
if (g_pStoreRoot == pStore) {
g_pStoreRoot = pStore->m_pNextStore;
} else {
while(pTemp) {
if (pTemp->m_pNextStore && (pTemp->m_pNextStore == pStore)) {
break;
}
pTemp = pTemp->m_pNextStore;
}
if (pTemp) {
pTemp->m_pNextStore = pStore->m_pNextStore;
}
}
delete pStore;
}
CStore *FindStore(TCHAR *szDeviceName)
{
CStore *pTemp = g_pStoreRoot;
while(pTemp) {
if (wcsicmp(szDeviceName, pTemp->m_szDeviceName) == 0) {
break;
}
pTemp = pTemp->m_pNextStore;
}
return pTemp;
}
BOOL CompareStore(CStore *pStore1, CStore *pStore2)
{
BOOL bRet = FALSE;
if (pStore1->m_pStorageId && pStore2->m_pStorageId) {
DWORD dwSize1 = ((STORAGE_IDENTIFICATION *)(pStore1->m_pStorageId))->dwSize;
DWORD dwSize2 = ((STORAGE_IDENTIFICATION *)(pStore2->m_pStorageId))->dwSize;
if (dwSize1 != dwSize2)
goto exit;
if (memcmp( pStore1->m_pStorageId, pStore2->m_pStorageId, dwSize1) != 0)
goto exit;
} else {
if (pStore1->m_pStorageId && !pStore2->m_pStorageId)
goto exit;
if (!pStore1->m_pStorageId && pStore2->m_pStorageId)
goto exit;
}
if (memcmp( &pStore1->m_si, &pStore2->m_si, sizeof(PD_STOREINFO)) != 0)
goto exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -