| 1 |
#include "vmc.h" |
| 2 |
|
| 3 |
|
| 4 |
// Driver fonctions |
| 5 |
|
| 6 |
#define MODNAME "vmc_fs" |
| 7 |
IRX_ID ( MODNAME, 1, 2 ); |
| 8 |
|
| 9 |
|
| 10 |
// Static variables. |
| 11 |
static iop_device_t s_Vmc_Driver; |
| 12 |
static iop_device_ops_t s_Vmc_Functions; |
| 13 |
|
| 14 |
// Global variables. |
| 15 |
struct global_vmc g_Vmc_Image[ 2 ]; |
| 16 |
int g_Vmc_Remove_Flag; |
| 17 |
int g_Vmc_Initialized; |
| 18 |
|
| 19 |
//---------------------------------------------------------------------------- |
| 20 |
// Initialize vmc driver |
| 21 |
//---------------------------------------------------------------------------- |
| 22 |
int Vmc_Initialize ( iop_device_t * driver ) |
| 23 |
{ |
| 24 |
|
| 25 |
if ( g_Vmc_Initialized ) |
| 26 |
return VMCFS_ERR_NO; |
| 27 |
|
| 28 |
g_Vmc_Initialized = TRUE; |
| 29 |
|
| 30 |
// init the global file descriptor to something negative ( ubergeek like 42, and polo like 35 so - 4235 ) |
| 31 |
g_Vmc_Image[ 0 ].fd = -4235; |
| 32 |
g_Vmc_Image[ 1 ].fd = -4235; |
| 33 |
|
| 34 |
DEBUGPRINT ( 1, "vmcfs: Filesystem Driver Initialized\n" ); |
| 35 |
|
| 36 |
return VMCFS_ERR_NO; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
//---------------------------------------------------------------------------- |
| 41 |
// Deinitialize vmc driver |
| 42 |
//---------------------------------------------------------------------------- |
| 43 |
int Vmc_Deinitialize ( iop_device_t * driver ) |
| 44 |
{ |
| 45 |
|
| 46 |
int i = 0; |
| 47 |
|
| 48 |
if ( !g_Vmc_Initialized ) |
| 49 |
return VMCFS_ERR_INITIALIZED; |
| 50 |
|
| 51 |
g_Vmc_Initialized = FALSE; |
| 52 |
|
| 53 |
for ( i = 0; i < 2; i++ ) |
| 54 |
{ |
| 55 |
|
| 56 |
if( g_Vmc_Image[ i ].fd >=0 ) |
| 57 |
{ |
| 58 |
|
| 59 |
close ( g_Vmc_Image[ i ].fd ); |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
DEBUGPRINT ( 1, "vmcfs: Filesystem Driver Deinitialized\n" ); |
| 66 |
|
| 67 |
return VMCFS_ERR_NO; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
// Entry point of the driver. |
| 72 |
int _start ( int argc, char* * argv ) |
| 73 |
{ |
| 74 |
|
| 75 |
printf ( "vmcfs: Created by ubergeek42\n" ); |
| 76 |
printf ( "vmcfs: ... Improved by Polo35.\n" ); |
| 77 |
printf ( "vmcfs: Version 1.2\n" ); |
| 78 |
|
| 79 |
g_Vmc_Initialized = FALSE; |
| 80 |
g_Vmc_Remove_Flag = FALSE; |
| 81 |
|
| 82 |
s_Vmc_Driver.type = (IOP_DT_FS | IOP_DT_FSEXT); |
| 83 |
s_Vmc_Driver.version = 1; |
| 84 |
s_Vmc_Driver.name = "vmc"; // the name used to access this device ( eg: vmc0: / ) |
| 85 |
s_Vmc_Driver.desc = "Virtual Memory Card s_Vmc_Driver"; |
| 86 |
s_Vmc_Driver.ops = &s_Vmc_Functions; |
| 87 |
|
| 88 |
// Typecasting to ( void* ) eliminates a bunch of warnings. |
| 89 |
s_Vmc_Functions.init = Vmc_Initialize; |
| 90 |
s_Vmc_Functions.deinit = Vmc_Deinitialize; |
| 91 |
s_Vmc_Functions.format = Vmc_Format; |
| 92 |
s_Vmc_Functions.open = Vmc_Open; |
| 93 |
s_Vmc_Functions.close = Vmc_Close; |
| 94 |
s_Vmc_Functions.read = Vmc_Read; |
| 95 |
s_Vmc_Functions.write = Vmc_Write; |
| 96 |
s_Vmc_Functions.lseek = Vmc_Lseek; |
| 97 |
s_Vmc_Functions.ioctl = Vmc_Ioctl; |
| 98 |
s_Vmc_Functions.remove = Vmc_Remove; |
| 99 |
s_Vmc_Functions.mkdir = Vmc_Mkdir; |
| 100 |
s_Vmc_Functions.rmdir = Vmc_Rmdir; |
| 101 |
s_Vmc_Functions.dopen = Vmc_Dopen; |
| 102 |
s_Vmc_Functions.dclose = Vmc_Dclose; |
| 103 |
s_Vmc_Functions.dread = Vmc_Dread; |
| 104 |
s_Vmc_Functions.getstat = Vmc_Getstat; |
| 105 |
s_Vmc_Functions.chstat = Vmc_Chstat; |
| 106 |
/* Extended ops start here. */ |
| 107 |
s_Vmc_Functions.rename = Vmc_Rename; |
| 108 |
s_Vmc_Functions.chdir = Vmc_Chdir; |
| 109 |
s_Vmc_Functions.sync = Vmc_Sync; |
| 110 |
s_Vmc_Functions.mount = Vmc_Mount; |
| 111 |
s_Vmc_Functions.umount = Vmc_Umount; |
| 112 |
s_Vmc_Functions.lseek64 = Vmc_Lseek64; |
| 113 |
s_Vmc_Functions.devctl = Vmc_Devctl; |
| 114 |
s_Vmc_Functions.symlink = Vmc_Symlink; |
| 115 |
s_Vmc_Functions.readlink = Vmc_Readlink; |
| 116 |
s_Vmc_Functions.ioctl2 = Vmc_Ioctl2; |
| 117 |
|
| 118 |
|
| 119 |
// Add the Driver using the ioman export |
| 120 |
DelDrv ( s_Vmc_Driver.name ); |
| 121 |
AddDrv ( &s_Vmc_Driver ); |
| 122 |
|
| 123 |
// And we are done! |
| 124 |
DEBUGPRINT ( 1, "vmcfs: Filesystem Driver %s added!\n", s_Vmc_Driver.name ); |
| 125 |
|
| 126 |
return 0; |
| 127 |
|
| 128 |
} |