📄 main.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*
File: main.c
Contains: VirtualCE FSD DLL main.
Written by: Craig Vinet
Copyright: (c) 2002 Connectix Corporation
*/
#include "vcefsd.h"
#include "file.h"
#include "fserver.h"
#include "find.h"
//--------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------
#ifdef DEBUG
DBGPARAM dpCurSettings =
{
TEXT("VCEFSD"),
{
TEXT("Init"),
TEXT("Api"),
TEXT("Error"),
TEXT("Create"),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT(""),
TEXT("")
},
#if 1
ZONEMASK_ERROR | ZONEMASK_CREATE
#else
0xFFFF
#endif
};
#endif
//--------------------------------------------------------------------------------
// Globals
//--------------------------------------------------------------------------------
VolumeState gVolumeState = { 0 }; // init
CRITICAL_SECTION g_csMain;
HANDLE g_FolderShareMutex;
PUCHAR gvpReadWriteBuffer = NULL; // Virtual addr.
ServerPB* gvpServerPB = NULL; // Virtual addr.
PUCHAR gpReadWriteBuffer = NULL; // Physical addr.
ServerPB* gpServerPB = NULL; // Physical addr.
//--------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------
BOOL VCEFSD_MountDisk( HDSK hdsk )
{
BOOL fSuccess = FALSE;
DWORD error;
DEBUGMSG(ZONE_INIT, (L"VCEFSD: FSD_MountDisk\n"));
EnterCriticalSection(&g_csMain);
if( gVolumeState.vs_Handle == 0 )
{
// Initialize global memory usage...
// DeviceEmulator Folder Sharing Device
v_FolderShareDevice = VirtualAlloc(NULL, sizeof(*v_FolderShareDevice), MEM_RESERVE, PAGE_NOACCESS);
if (v_FolderShareDevice == NULL) {
DEBUGMSG(ZONE_ERROR, (L"VCEFSD_MountDisk ERROR: FolderShareDevice VirtualAlloc Failed\n") );
fSuccess = FALSE;
goto Done;
}
fSuccess = VirtualCopy((LPVOID)v_FolderShareDevice, (PVOID)(0x500f4000>>8), sizeof(*v_FolderShareDevice), PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
if (fSuccess == FALSE) {
error = GetLastError();
DEBUGMSG(ZONE_ERROR, (L"VCEFSD_MountDisk ERROR: FolderShareDevice VirtualCopy Failed\n") );
goto Done;
}
// Read/Write buffer...
gvpReadWriteBuffer = (PUCHAR)VirtualAlloc( 0,
1024 * 64, // 64k
MEM_RESERVE,
PAGE_NOACCESS );
if( gvpReadWriteBuffer == NULL )
{
DEBUGMSG(ZONE_ERROR, (L"VCEFSD_MountDisk ERROR: Read/Write buffer VirtualAlloc Failed\n") );
fSuccess = FALSE;
goto Done;
}
// Then we actually enable the logical address space for use.
fSuccess = VirtualCopy( (LPVOID) gvpReadWriteBuffer,
(LPVOID)(EFSBUF>>8),
1024 * 64,
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL);
if (fSuccess != TRUE )
{
error = GetLastError();
DEBUGMSG(ZONE_ERROR, (L"VCEFSD_MountDisk ERROR: Read/Write buffer VirtualCopy Failed\n") );
goto Done;
}
// Global PB buffer...
gvpServerPB = (ServerPB*)VirtualAlloc( 0,
sizeof( ServerPB ),
MEM_RESERVE,
PAGE_NOACCESS );
if( gvpServerPB == NULL )
{
error = GetLastError();
DEBUGMSG(ZONE_ERROR, (L"VCEFSD_MountDisk ERROR: PB VirtualAlloc Failed\n") );
fSuccess = FALSE;
goto Done;
}
// Then we actually enable the logical address space for use.
fSuccess = VirtualCopy( (LPVOID) gvpServerPB,
(LPVOID)( ( ( EFSBUF + (1024 * 64) ) >> 8 ) ),
sizeof( ServerPB ),
PAGE_READWRITE | PAGE_NOCACHE | PAGE_PHYSICAL );
if (fSuccess != TRUE )
{
DEBUGMSG(ZONE_ERROR, (L"VCEFSD_MountDisk ERROR: PB VirtualCopy Failed\n") );
goto Done;
}
//WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!!
// Set up physical pts for hop across to emulator
gpReadWriteBuffer = (PUCHAR)EFSBUF; // Physical addr.
gpServerPB = (ServerPB*)(EFSBUF + (1024 * 64)); // Physical addr.
memset( gvpServerPB, 0, sizeof( ServerPB ) );
gvpServerPB->fStructureSize = sizeof(ServerPB);
// Ask the server for the drive info
ServerGetDriveConfig( gvpServerPB );
if ( gvpServerPB->fResult != 0 ) // Gack!
{
goto Done;
}
gVolumeState.vs_Handle = FSDMGR_RegisterVolume(hdsk, L"Storage Card", (DWORD)&gVolumeState);
if (gVolumeState.vs_Handle)
{
fSuccess = TRUE;
DEBUGMSG( ZONE_ERROR, (L"Mounted VCEFSD volume '\\Storage Card'\n") );
}
// Get the maximum read and write buffer size.
ServerGetMaxIOSize();
// Happiness in slavery...er, I mean init FSD stuff
InitFiles();
InitFind();
}
Done:;
LeaveCriticalSection(&g_csMain);
return fSuccess;
}
//--------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------
BOOL VCEFSD_UnmountDisk(HDSK hdsk)
{
EnterCriticalSection(&g_csMain);
if( gVolumeState.vs_Handle != 0 )
{
CloseFiles();
FSDMGR_DeregisterVolume( gVolumeState.vs_Handle );
// No more calls to ServerIO functions!
if( gvpReadWriteBuffer != NULL )
VirtualFree( gvpReadWriteBuffer, 0, MEM_RELEASE );
if( gvpServerPB != NULL )
VirtualFree( gvpServerPB, 0, MEM_RELEASE );
gVolumeState.vs_Handle = 0;
}
LeaveCriticalSection(&g_csMain);
return TRUE;
}
SHELLFILECHANGEFUNC_t gpnShellNotify = NULL;
//--------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------
BOOL VCEFSD_RegisterFileSystemFunction(PVOLUME pvol, SHELLFILECHANGEFUNC_t pfn)
{
gpnShellNotify = pfn;
return TRUE;
}
//--------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------
BOOL WINAPI DllMain(HINSTANCE DllInstance, DWORD dwReason, LPVOID Reserved)
{
switch(dwReason) {
case DLL_PROCESS_ATTACH:
{
DisableThreadLibraryCalls( (HMODULE)DllInstance);
DEBUGREGISTER(DllInstance);
DEBUGMSG(ZONE_INIT,(TEXT("VCEFSD!DllMain: DLL_PROCESS_ATTACH\n")));
InitializeCriticalSection(&g_csMain);
g_FolderShareMutex = CreateMutex(NULL, FALSE, L"DeviceEmulatorFolderSharingDevice");
if (g_FolderShareMutex == NULL) {
return FALSE;
}
}
break;
case DLL_PROCESS_DETACH:
{
DeleteCriticalSection(&g_csMain);
CloseHandle(g_FolderShareMutex);
DEBUGMSG(ZONE_INIT,(TEXT("VCEFSD!DllMain: DLL_PROCESS_DETACH\n")));
}
break;
default:
break;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -