662 lines
17 KiB
C
662 lines
17 KiB
C
/*
|
|
* RetroNFS95 VxD C half.
|
|
*
|
|
* This module owns the Win9x-side mapping table and the DeviceIoControl
|
|
* contract used by RETRONP.DLL. The remaining DDK-dependent step is wiring
|
|
* these mappings into IFSMgr's network FSD dispatch path.
|
|
*/
|
|
|
|
#include "../include/retro_ioctl.h"
|
|
|
|
typedef unsigned long DWORD;
|
|
typedef int BOOL;
|
|
|
|
#ifdef __WATCOMC__
|
|
#define RETRO_FAR __far
|
|
#else
|
|
#define RETRO_FAR
|
|
#endif
|
|
|
|
#define TRUE 1
|
|
#define FALSE 0
|
|
#define NO_ERROR 0
|
|
#define ERROR_INVALID_PARAMETER 87
|
|
#define ERROR_NOT_SUPPORTED 50
|
|
#define ERROR_NOT_CONNECTED 2250
|
|
#define ERROR_INVALID_FUNCTION 1
|
|
#define ERROR_TOO_MANY_OPEN_FILES 4
|
|
#define ERROR_ACCESS_DENIED 5
|
|
#define ERROR_NO_MORE_FILES 18
|
|
|
|
#define DIOC_OPEN 0xffffffffUL
|
|
#define DIOC_CLOSEHANDLE 0xfffffffeUL
|
|
|
|
#define IFSMGR_DEVICE_ID 0x0040
|
|
#define RETRO_FSD_ORDINAL 1
|
|
|
|
#ifndef IFSFN_CONNECT
|
|
#define IFSFN_CONNECT 0x00
|
|
#endif
|
|
#ifndef IFSFN_DISCONNECT
|
|
#define IFSFN_DISCONNECT 0x01
|
|
#endif
|
|
#ifndef IFSFN_OPEN
|
|
#define IFSFN_OPEN 0x02
|
|
#endif
|
|
#ifndef IFSFN_CLOSE
|
|
#define IFSFN_CLOSE 0x03
|
|
#endif
|
|
#ifndef IFSFN_READ
|
|
#define IFSFN_READ 0x04
|
|
#endif
|
|
#ifndef IFSFN_WRITE
|
|
#define IFSFN_WRITE 0x05
|
|
#endif
|
|
#ifndef IFSFN_FINDNEXT
|
|
#define IFSFN_FINDNEXT 0x0b
|
|
#endif
|
|
#ifndef IFSFN_FINDFIRST
|
|
#define IFSFN_FINDFIRST 0x0e
|
|
#endif
|
|
#ifndef IFSFN_GETDISKINFO
|
|
#define IFSFN_GETDISKINFO 0x18
|
|
#endif
|
|
|
|
#define RETRO_IFS_SUCCESS 0
|
|
#define RETRO_IFS_ERROR 0xffffffffUL
|
|
#define RETRO_MAX_OPEN_FILES 64
|
|
#define RETRO_MAX_PATH_LEN 260
|
|
|
|
typedef struct DIOCPARAMETERS {
|
|
DWORD dwIoControlCode;
|
|
void RETRO_FAR* lpvInBuffer;
|
|
DWORD cbInBuffer;
|
|
void RETRO_FAR* lpvOutBuffer;
|
|
DWORD cbOutBuffer;
|
|
DWORD RETRO_FAR* lpcbBytesReturned;
|
|
void RETRO_FAR* lpoOverlapped;
|
|
} DIOCPARAMETERS;
|
|
|
|
typedef struct RETRO_MAPPING_SLOT {
|
|
int used;
|
|
RETRO_MAPPING_INFO info;
|
|
} RETRO_MAPPING_SLOT;
|
|
|
|
typedef struct IFS_PARM {
|
|
unsigned short ip_fsd;
|
|
unsigned short ip_func;
|
|
unsigned long ip_result;
|
|
unsigned long ip_drv;
|
|
unsigned long ip_user;
|
|
unsigned long ip_pid;
|
|
} IFS_PARM;
|
|
|
|
typedef struct IFS_OPEN_PARM {
|
|
unsigned short iop_mode;
|
|
unsigned short iop_action;
|
|
unsigned long iop_attr;
|
|
char RETRO_FAR* iop_pathname;
|
|
} IFS_OPEN_PARM;
|
|
|
|
typedef struct IFS_RW_PARM {
|
|
unsigned short irp_handle;
|
|
void RETRO_FAR* irp_buffer;
|
|
unsigned long irp_count;
|
|
unsigned long irp_offset;
|
|
} IFS_RW_PARM;
|
|
|
|
typedef struct IFS_FIND_PARM {
|
|
unsigned short ifp_handle;
|
|
unsigned short ifp_attrib;
|
|
unsigned long ifp_unique;
|
|
char RETRO_FAR* ifp_search_pattern;
|
|
char RETRO_FAR* ifp_find_buffer;
|
|
} IFS_FIND_PARM;
|
|
|
|
typedef struct FSD_ENTRY {
|
|
unsigned long fsd_ordinal;
|
|
unsigned long fsd_entry_point;
|
|
} FSD_ENTRY;
|
|
|
|
typedef struct RETRO_FILE_HANDLE {
|
|
int in_use;
|
|
unsigned long drive_index;
|
|
char server_path[RETRO_MAX_PATH_LEN];
|
|
unsigned long nfs_cookie;
|
|
} RETRO_FILE_HANDLE;
|
|
|
|
static RETRO_MAPPING_SLOT g_mappings[RETRO_MAX_MAPPINGS];
|
|
static RETRO_FILE_HANDLE g_open_files[RETRO_MAX_OPEN_FILES];
|
|
static FSD_ENTRY g_fsd_entry;
|
|
static int g_ifs_ready = 0;
|
|
static int g_ifs_registered = 0;
|
|
|
|
DWORD __stdcall RetroIFS_Dispatch(IFS_PARM RETRO_FAR* pifs);
|
|
DWORD __stdcall RETROVXD_IFSMgr_Register(void* fsd_entry);
|
|
DWORD __stdcall RETROVXD_IFSMgr_Deregister(void* fsd_entry);
|
|
|
|
static void retro_zero(void RETRO_FAR* p, unsigned long n) {
|
|
unsigned char RETRO_FAR* b = (unsigned char RETRO_FAR*)p;
|
|
while (n--) *b++ = 0;
|
|
}
|
|
|
|
static void retro_copy(char RETRO_FAR* dst,
|
|
unsigned long dst_len,
|
|
const char RETRO_FAR* src) {
|
|
unsigned long i = 0;
|
|
if (!dst || dst_len == 0) return;
|
|
if (src) {
|
|
while (i + 1 < dst_len && src[i]) {
|
|
dst[i] = src[i];
|
|
++i;
|
|
}
|
|
}
|
|
dst[i] = 0;
|
|
}
|
|
|
|
static char retro_upper(char c) {
|
|
if (c >= 'a' && c <= 'z') return (char)(c - 'a' + 'A');
|
|
return c;
|
|
}
|
|
|
|
static int retro_prefix_i(const char RETRO_FAR* value, const char* prefix) {
|
|
if (!value || !prefix) return FALSE;
|
|
while (*prefix) {
|
|
if (retro_upper(*value) != retro_upper(*prefix)) return FALSE;
|
|
++value;
|
|
++prefix;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
static int retro_drive_index(const char RETRO_FAR* local) {
|
|
char d;
|
|
if (!local || !local[0]) return -1;
|
|
d = retro_upper(local[0]);
|
|
if (d < 'A' || d > 'Z') return -1;
|
|
if (local[1] && local[1] != ':') return -1;
|
|
return d - 'A';
|
|
}
|
|
|
|
static unsigned long retro_mapping_count(void) {
|
|
unsigned long i;
|
|
unsigned long n = 0;
|
|
for (i = 0; i < RETRO_MAX_MAPPINGS; ++i) {
|
|
if (g_mappings[i].used) ++n;
|
|
}
|
|
return n;
|
|
}
|
|
|
|
static int retro_parse_remote(const char RETRO_FAR* remote,
|
|
char RETRO_FAR* server,
|
|
unsigned long server_len,
|
|
char RETRO_FAR* export_path,
|
|
unsigned long export_len) {
|
|
const char RETRO_FAR* p;
|
|
unsigned long i;
|
|
|
|
if (!remote || !retro_prefix_i(remote, "\\\\RetroNFS\\")) {
|
|
return FALSE;
|
|
}
|
|
|
|
p = remote + 11;
|
|
if (!*p) return FALSE;
|
|
|
|
i = 0;
|
|
while (*p && *p != '\\' && i + 1 < server_len) {
|
|
server[i++] = *p++;
|
|
}
|
|
server[i] = 0;
|
|
|
|
if (!server[0] || *p != '\\') return FALSE;
|
|
++p;
|
|
if (!*p) return FALSE;
|
|
|
|
export_path[0] = '/';
|
|
i = 1;
|
|
while (*p && i + 1 < export_len) {
|
|
export_path[i++] = (*p == '\\') ? '/' : *p;
|
|
++p;
|
|
}
|
|
export_path[i] = 0;
|
|
return TRUE;
|
|
}
|
|
|
|
static DWORD retro_write_info(DIOCPARAMETERS* p,
|
|
const RETRO_MAPPING_INFO RETRO_FAR* info) {
|
|
if (!p || !p->lpvOutBuffer || p->cbOutBuffer < sizeof(RETRO_MAPPING_INFO)) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
*((RETRO_MAPPING_INFO*)p->lpvOutBuffer) = *info;
|
|
if (p->lpcbBytesReturned) {
|
|
*p->lpcbBytesReturned = sizeof(RETRO_MAPPING_INFO);
|
|
}
|
|
return NO_ERROR;
|
|
}
|
|
|
|
static DWORD retro_status(DIOCPARAMETERS* p) {
|
|
RETRO_STATUS_INFO info;
|
|
|
|
if (!p || !p->lpvOutBuffer || p->cbOutBuffer < sizeof(RETRO_STATUS_INFO)) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
retro_zero(&info, sizeof(info));
|
|
info.status = RETRO_STATUS_OK;
|
|
info.mapping_count = retro_mapping_count();
|
|
info.max_mappings = RETRO_MAX_MAPPINGS;
|
|
if (g_ifs_ready) {
|
|
info.driver_flags |= RETRO_DRIVER_FLAG_IFS_STUB;
|
|
}
|
|
if (g_ifs_registered) {
|
|
info.driver_flags |= RETRO_DRIVER_FLAG_IFS_REGISTERED;
|
|
}
|
|
|
|
*((RETRO_STATUS_INFO*)p->lpvOutBuffer) = info;
|
|
if (p->lpcbBytesReturned) {
|
|
*p->lpcbBytesReturned = sizeof(RETRO_STATUS_INFO);
|
|
}
|
|
return NO_ERROR;
|
|
}
|
|
|
|
static DWORD retro_map_drive(DIOCPARAMETERS* p) {
|
|
RETRO_MAP_REQUEST* req;
|
|
RETRO_MAPPING_INFO info;
|
|
int idx;
|
|
|
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_MAP_REQUEST)) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
req = (RETRO_MAP_REQUEST*)p->lpvInBuffer;
|
|
idx = retro_drive_index(req->local);
|
|
if (idx < 0 || !req->remote[0]) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
retro_zero(&info, sizeof(info));
|
|
info.status = RETRO_STATUS_OK;
|
|
info.index = (unsigned long)idx;
|
|
retro_copy(info.local, sizeof(info.local), req->local);
|
|
retro_copy(info.remote, sizeof(info.remote), req->remote);
|
|
|
|
if (!retro_parse_remote(info.remote,
|
|
info.server,
|
|
sizeof(info.server),
|
|
info.export_path,
|
|
sizeof(info.export_path))) {
|
|
info.status = RETRO_STATUS_BAD_REMOTE;
|
|
if (p->lpvOutBuffer && p->cbOutBuffer >= sizeof(info)) {
|
|
retro_write_info(p, &info);
|
|
}
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
g_mappings[idx].used = TRUE;
|
|
g_mappings[idx].info = info;
|
|
|
|
/*
|
|
* TODO with Win98 DDK:
|
|
* Register/refresh this drive with IFSMgr and attach an FSD context that
|
|
* points at g_mappings[idx]. Until then, the provider can configure and
|
|
* inspect mappings, but Win32 file I/O will not reach the NFS core.
|
|
*/
|
|
if (p->lpvOutBuffer && p->cbOutBuffer >= sizeof(info)) {
|
|
return retro_write_info(p, &info);
|
|
}
|
|
if (p->lpcbBytesReturned) {
|
|
*p->lpcbBytesReturned = 0;
|
|
}
|
|
return NO_ERROR;
|
|
}
|
|
|
|
static DWORD retro_unmap_drive(DIOCPARAMETERS* p) {
|
|
RETRO_QUERY_REQUEST* req;
|
|
int idx;
|
|
|
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_QUERY_REQUEST)) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
req = (RETRO_QUERY_REQUEST*)p->lpvInBuffer;
|
|
idx = retro_drive_index(req->local);
|
|
if (idx < 0) return ERROR_INVALID_PARAMETER;
|
|
|
|
if (!g_mappings[idx].used) return ERROR_NOT_CONNECTED;
|
|
|
|
retro_zero(&g_mappings[idx], sizeof(g_mappings[idx]));
|
|
if (p->lpcbBytesReturned) {
|
|
*p->lpcbBytesReturned = 0;
|
|
}
|
|
return NO_ERROR;
|
|
}
|
|
|
|
static DWORD retro_query_drive(DIOCPARAMETERS* p) {
|
|
RETRO_QUERY_REQUEST* req;
|
|
int idx;
|
|
|
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_QUERY_REQUEST)) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
req = (RETRO_QUERY_REQUEST*)p->lpvInBuffer;
|
|
idx = retro_drive_index(req->local);
|
|
if (idx < 0) return ERROR_INVALID_PARAMETER;
|
|
|
|
if (!g_mappings[idx].used) return ERROR_NOT_CONNECTED;
|
|
return retro_write_info(p, &g_mappings[idx].info);
|
|
}
|
|
|
|
static DWORD retro_enum_drive(DIOCPARAMETERS* p) {
|
|
RETRO_ENUM_REQUEST* req;
|
|
unsigned long i;
|
|
unsigned long seen = 0;
|
|
|
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_ENUM_REQUEST)) {
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
req = (RETRO_ENUM_REQUEST*)p->lpvInBuffer;
|
|
for (i = 0; i < RETRO_MAX_MAPPINGS; ++i) {
|
|
if (!g_mappings[i].used) continue;
|
|
if (seen == req->index) {
|
|
return retro_write_info(p, &g_mappings[i].info);
|
|
}
|
|
++seen;
|
|
}
|
|
return ERROR_NOT_CONNECTED;
|
|
}
|
|
|
|
static void retro_reset_open_files(void) {
|
|
retro_zero(g_open_files, sizeof(g_open_files));
|
|
}
|
|
|
|
static DWORD retro_ifs_register(void) {
|
|
if (g_ifs_registered) {
|
|
return TRUE;
|
|
}
|
|
|
|
/*
|
|
* Keep the FSD entry in static storage so IFSMgr never receives a pointer
|
|
* to a stack frame that disappears after init.
|
|
*/
|
|
g_fsd_entry.fsd_ordinal = RETRO_FSD_ORDINAL;
|
|
g_fsd_entry.fsd_entry_point = (unsigned long)&RetroIFS_Dispatch;
|
|
|
|
#ifdef RETRO_ENABLE_REAL_IFSMGR_REGISTER
|
|
if (!RETROVXD_IFSMgr_Register(&g_fsd_entry)) {
|
|
retro_zero(&g_fsd_entry, sizeof(g_fsd_entry));
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
|
|
g_ifs_registered = TRUE;
|
|
return TRUE;
|
|
}
|
|
|
|
static DWORD retro_ifs_unregister(void) {
|
|
if (!g_ifs_registered) {
|
|
return TRUE;
|
|
}
|
|
|
|
#ifdef RETRO_ENABLE_REAL_IFSMGR_REGISTER
|
|
if (!RETROVXD_IFSMgr_Deregister(&g_fsd_entry)) {
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
|
|
g_ifs_registered = FALSE;
|
|
retro_zero(&g_fsd_entry, sizeof(g_fsd_entry));
|
|
return TRUE;
|
|
}
|
|
|
|
static void RETRO_FAR* retro_ifs_tail(IFS_PARM RETRO_FAR* pifs) {
|
|
return (void RETRO_FAR*)(((char RETRO_FAR*)pifs) + sizeof(IFS_PARM));
|
|
}
|
|
|
|
static int retro_alloc_file_handle(void) {
|
|
int i;
|
|
for (i = 0; i < RETRO_MAX_OPEN_FILES; ++i) {
|
|
if (!g_open_files[i].in_use) {
|
|
g_open_files[i].in_use = TRUE;
|
|
g_open_files[i].drive_index = 0xffffffffUL;
|
|
g_open_files[i].nfs_cookie = 0;
|
|
g_open_files[i].server_path[0] = 0;
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
static int retro_valid_file_handle(unsigned int handle) {
|
|
if (handle >= RETRO_MAX_OPEN_FILES) return FALSE;
|
|
return g_open_files[handle].in_use ? TRUE : FALSE;
|
|
}
|
|
|
|
static void retro_free_file_handle(unsigned int handle) {
|
|
if (handle < RETRO_MAX_OPEN_FILES) {
|
|
retro_zero(&g_open_files[handle], sizeof(g_open_files[handle]));
|
|
}
|
|
}
|
|
|
|
static void retro_set_ifs_result(IFS_PARM RETRO_FAR* pifs, DWORD result) {
|
|
if (pifs) {
|
|
pifs->ip_result = result;
|
|
}
|
|
}
|
|
|
|
static DWORD retro_ifs_fail(IFS_PARM RETRO_FAR* pifs, DWORD error) {
|
|
retro_set_ifs_result(pifs, error);
|
|
return error;
|
|
}
|
|
|
|
static DWORD retro_ifs_connect(IFS_PARM RETRO_FAR* pifs) {
|
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
|
return RETRO_IFS_SUCCESS;
|
|
}
|
|
|
|
static DWORD retro_ifs_disconnect(IFS_PARM RETRO_FAR* pifs) {
|
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
|
return RETRO_IFS_SUCCESS;
|
|
}
|
|
|
|
static DWORD retro_ifs_open(IFS_PARM RETRO_FAR* pifs) {
|
|
IFS_OPEN_PARM RETRO_FAR* iop;
|
|
int handle;
|
|
|
|
iop = (IFS_OPEN_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
|
if (!iop) {
|
|
return retro_ifs_fail(pifs, ERROR_INVALID_PARAMETER);
|
|
}
|
|
|
|
/*
|
|
* Read-only scaffold: allocate an internal handle and preserve the path
|
|
* for the later NFS LOOKUP/READ implementation. Write access is blocked
|
|
* until the redirector has real NFS write support; iop_action is left for
|
|
* live Win9x validation because the exact action values differ by call
|
|
* shape in the DDK-era IFSMgr layouts.
|
|
*/
|
|
if ((iop->iop_mode & 0x0003) != 0) {
|
|
return retro_ifs_fail(pifs, ERROR_ACCESS_DENIED);
|
|
}
|
|
|
|
handle = retro_alloc_file_handle();
|
|
if (handle < 0) {
|
|
return retro_ifs_fail(pifs, ERROR_TOO_MANY_OPEN_FILES);
|
|
}
|
|
|
|
retro_copy(g_open_files[handle].server_path,
|
|
sizeof(g_open_files[handle].server_path),
|
|
iop->iop_pathname);
|
|
|
|
retro_set_ifs_result(pifs, (DWORD)handle);
|
|
return RETRO_IFS_SUCCESS;
|
|
}
|
|
|
|
static DWORD retro_ifs_close(IFS_PARM RETRO_FAR* pifs) {
|
|
IFS_RW_PARM RETRO_FAR* irp;
|
|
unsigned int handle;
|
|
|
|
irp = (IFS_RW_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
|
handle = (unsigned int)irp->irp_handle;
|
|
if (!retro_valid_file_handle(handle)) {
|
|
return retro_ifs_fail(pifs, ERROR_INVALID_PARAMETER);
|
|
}
|
|
|
|
retro_free_file_handle(handle);
|
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
|
return RETRO_IFS_SUCCESS;
|
|
}
|
|
|
|
static DWORD retro_ifs_read(IFS_PARM RETRO_FAR* pifs) {
|
|
IFS_RW_PARM RETRO_FAR* irp;
|
|
unsigned int handle;
|
|
|
|
irp = (IFS_RW_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
|
handle = (unsigned int)irp->irp_handle;
|
|
if (!retro_valid_file_handle(handle)) {
|
|
return retro_ifs_fail(pifs, ERROR_INVALID_PARAMETER);
|
|
}
|
|
|
|
/*
|
|
* NFS READ will fill this buffer later. Returning zero bytes now gives
|
|
* callers a deterministic read-only EOF instead of a fake payload.
|
|
*/
|
|
irp->irp_count = 0;
|
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
|
return RETRO_IFS_SUCCESS;
|
|
}
|
|
|
|
static DWORD retro_ifs_write(IFS_PARM RETRO_FAR* pifs) {
|
|
return retro_ifs_fail(pifs, ERROR_ACCESS_DENIED);
|
|
}
|
|
|
|
static DWORD retro_ifs_find(IFS_PARM RETRO_FAR* pifs) {
|
|
IFS_FIND_PARM RETRO_FAR* ifp;
|
|
|
|
ifp = (IFS_FIND_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
|
(void)ifp;
|
|
|
|
retro_set_ifs_result(pifs, RETRO_IFS_ERROR);
|
|
return ERROR_NO_MORE_FILES;
|
|
}
|
|
|
|
static DWORD retro_ifs_getdiskinfo(IFS_PARM RETRO_FAR* pifs) {
|
|
unsigned long RETRO_FAR* disk_info;
|
|
|
|
disk_info = (unsigned long RETRO_FAR*)retro_ifs_tail(pifs);
|
|
disk_info[0] = 64;
|
|
disk_info[1] = 2048;
|
|
disk_info[2] = 512;
|
|
disk_info[3] = 8192;
|
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
|
return RETRO_IFS_SUCCESS;
|
|
}
|
|
|
|
/*
|
|
* IFSMgr entry point scaffold.
|
|
*
|
|
* This now decodes the first simplified parameter tails and enforces a
|
|
* read-only contract. The remaining production work is replacing the EOF and
|
|
* no-entry fallbacks with NFS LOOKUP/READ/READDIR calls and validating the
|
|
* final Win9x IFSMgr layouts against a live DDK target.
|
|
*/
|
|
DWORD __stdcall RetroIFS_Dispatch(IFS_PARM RETRO_FAR* pifs) {
|
|
DWORD rc;
|
|
|
|
if (!pifs) {
|
|
return RETRO_IFS_ERROR;
|
|
}
|
|
|
|
switch (pifs->ip_func) {
|
|
case IFSFN_CONNECT:
|
|
rc = retro_ifs_connect(pifs);
|
|
break;
|
|
case IFSFN_DISCONNECT:
|
|
rc = retro_ifs_disconnect(pifs);
|
|
break;
|
|
case IFSFN_OPEN:
|
|
rc = retro_ifs_open(pifs);
|
|
break;
|
|
case IFSFN_READ:
|
|
rc = retro_ifs_read(pifs);
|
|
break;
|
|
case IFSFN_WRITE:
|
|
rc = retro_ifs_write(pifs);
|
|
break;
|
|
case IFSFN_CLOSE:
|
|
rc = retro_ifs_close(pifs);
|
|
break;
|
|
case IFSFN_FINDFIRST:
|
|
case IFSFN_FINDNEXT:
|
|
rc = retro_ifs_find(pifs);
|
|
break;
|
|
case IFSFN_GETDISKINFO:
|
|
rc = retro_ifs_getdiskinfo(pifs);
|
|
break;
|
|
default:
|
|
rc = retro_ifs_fail(pifs, ERROR_INVALID_FUNCTION);
|
|
break;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
DWORD __stdcall RetroIFS_Init(void) {
|
|
retro_reset_open_files();
|
|
if (!retro_ifs_register()) {
|
|
g_ifs_ready = 0;
|
|
return FALSE;
|
|
}
|
|
g_ifs_ready = 1;
|
|
return TRUE;
|
|
}
|
|
|
|
DWORD __stdcall RetroIFS_Exit(void) {
|
|
DWORD ok;
|
|
|
|
g_ifs_ready = 0;
|
|
ok = retro_ifs_unregister();
|
|
retro_reset_open_files();
|
|
return ok ? TRUE : FALSE;
|
|
}
|
|
|
|
DWORD __stdcall RETROVXD_Dynamic_Init(void) {
|
|
retro_zero(g_mappings, sizeof(g_mappings));
|
|
return RetroIFS_Init();
|
|
}
|
|
|
|
DWORD __stdcall RETROVXD_Dynamic_Exit(void) {
|
|
RetroIFS_Exit();
|
|
retro_zero(g_mappings, sizeof(g_mappings));
|
|
return TRUE;
|
|
}
|
|
|
|
DWORD __stdcall RETROVXD_W32_DeviceIoControl(DWORD service,
|
|
DWORD ddb,
|
|
DWORD hDevice,
|
|
DIOCPARAMETERS* p) {
|
|
(void)ddb;
|
|
(void)hDevice;
|
|
|
|
if (service == DIOC_OPEN || service == DIOC_CLOSEHANDLE) {
|
|
return NO_ERROR;
|
|
}
|
|
|
|
switch (service) {
|
|
case RETRO_IOCTL_MAP:
|
|
return retro_map_drive(p);
|
|
case RETRO_IOCTL_UNMAP:
|
|
return retro_unmap_drive(p);
|
|
case RETRO_IOCTL_QUERY:
|
|
return retro_query_drive(p);
|
|
case RETRO_IOCTL_ENUM:
|
|
return retro_enum_drive(p);
|
|
case RETRO_IOCTL_STATUS:
|
|
return retro_status(p);
|
|
default:
|
|
return ERROR_NOT_SUPPORTED;
|
|
}
|
|
}
|