31 MC_RPCCMD_INIT = 0x00,
47 MC_RPCCMD_CHECK_BLOCK,
48 MC_RPCCMD_ERASE_BLOCK = 0x0E,
141static int* g_pType = NULL;
142static int* g_pFree = NULL;
143static int* g_pFormat = NULL;
173 *g_pType = ptr->type;
176 *g_pFree = ptr->free;
178 if(g_pFormat != NULL)
179 *g_pFormat = (ptr->type == MC_TYPE_NONE || g_rdata.result == -2) ? 0 : 1;
182 *g_pType = ptrNew->type;
185 *g_pFree = ptrNew->free;
187 if(g_pFormat != NULL)
188 *g_pFormat = ptrNew->formatted;
204 for(i = 0,dest = (u8*)ptr->dest1; i < ptr->size1; i++)
205 dest[i] = ptr->src1[i];
206 for(i = 0,dest = (u8*)ptr->dest2; i < ptr->size2; i++)
207 dest[i] = ptr->src2[i];
209 for(i = 0,dest = (u8*)ptrNew->dest1; i < ptrNew->size1; i++)
210 dest[i] = ptrNew->src1[i];
211 for(i = 0,dest = (u8*)ptrNew->dest2; i < ptrNew->size2; i++)
212 dest[i] = ptrNew->src2[i];
222 char *currentDir = UNCACHED_SEG(curDir);
223 len = strlen(currentDir);
225 len = strlen(currentDir+1023);
226 memcpy(arg, currentDir, len);
227 *(currentDir+len) = 0;
234 static int _rb_count = 0;
253 if((ret=SifBindRpc(&g_cdata, 0x80000400, 0)) < 0)
256 printf(
"libmc: bind error\n");
261 if(g_cdata.server == NULL)
264 while (g_cdata.server == NULL);
272 printf(
"libmc: using MCMAN & MCSERV\n");
275 g_descParam.offset = -217;
278 if((ret = SifCallRpc(&g_cdata,
mcRpcCmd[
g_mcType][MC_RPCCMD_INIT], 0, &g_descParam,
sizeof(g_descParam), &g_rdata, 4, NULL, NULL))>=0)
280 ret = g_rdata.result;
285 printf(
"libmc: initialisation error\n");
288 return g_rdata.result - 100;
294 printf(
"libmc: using XMCMAN & XMCSERV\n");
298 if((ret = SifCallRpc(&g_cdata,
mcRpcCmd[
g_mcType][MC_RPCCMD_INIT], 0, &g_descParam,
sizeof(g_descParam), &g_rdata, 12, NULL, NULL)) < 0)
302 printf(
"libmc: initialisation error\n");
309 if(rpcStat->mcserv_version < 0x205)
312 printf(
"libmc: mcserv is too old (%x)\n", rpcStat->mcserv_version);
319 if(rpcStat->mcman_version < 0x206)
322 printf(
"libmc: mcman is too old (%x)\n", rpcStat->mcman_version);
327 ret = rpcStat->result;
336int mcGetInfo(
int port,
int slot,
int* type,
int* free,
int* format)
350 g_descParam.port = port;
351 g_descParam.slot = slot;
352 g_descParam.size = (type) ? 1 : 0;
353 g_descParam.offset = (free) ? 1 : 0;
354 g_descParam.origin = (format) ? 1 : 0;
355 g_descParam.param = endParameter;
359 g_descParam.port = port;
360 g_descParam.slot = slot;
361 g_descParam.size = (format) ? 1 : 0;
362 g_descParam.offset = (free) ? 1 : 0;
363 g_descParam.origin = (type) ? 1 : 0;
364 g_descParam.param = endParameter;
369 SifWriteBackDCache(endParameter, 192);
378int mcOpen(
int port,
int slot,
const char *name,
int mode)
390 g_nameParam.port = port;
391 g_nameParam.slot = slot;
392 g_nameParam.flags = mode;
393 strncpy(g_nameParam.name, name, 1023);
394 g_nameParam.name[1023] = 0;
424int mcSeek(
int fd,
int offset,
int origin)
437 g_descParam.offset = offset;
438 g_descParam.origin = origin;
447int mcRead(
int fd,
void *buffer,
int size)
460 g_descParam.size = size;
461 g_descParam.buffer = buffer;
462 g_descParam.param = endParameter;
463 SifWriteBackDCache(buffer, size);
464 SifWriteBackDCache(endParameter, 192);
473int mcWrite(
int fd,
const void *buffer,
int size)
488 g_descParam.size = 0;
489 g_descParam.origin = size;
490 g_descParam.buffer = 0;
494 g_descParam.size = size - ( ((int)((
const u8 *)buffer-1) & 0xFFFFFFF0) - (int)((
const u8 *)buffer-16) );
495 g_descParam.origin = ( ((int)((
const u8 *)buffer-1) & 0xFFFFFFF0) - (int)((
const u8 *)buffer-16) );
496 g_descParam.buffer = (
void*)((
int)(
const u8 *)buffer + ( ((
int)((
const u8 *)buffer-1) & 0xFFFFFFF0) - (
int)((
const u8 *)buffer-16) ));
498 for(i=0; i<g_descParam.origin; i++)
500 g_descParam.data[i] = *(
char*)((
const u8 *)buffer+i);
532int mcMkDir(
int port,
int slot,
const char* name)
534 int ret =
mcOpen(port, slot, name, 0x40);
541int mcChdir(
int port,
int slot,
const char* newDir,
char* currentDir)
553 g_nameParam.port = port;
554 g_nameParam.slot = slot;
555 g_nameParam.curdir = curDir;
556 strncpy(g_nameParam.name, newDir, 1023);
557 g_nameParam.name[1023] = 0;
558 SifWriteBackDCache(curDir, 1024);
579 g_nameParam.port = port;
580 g_nameParam.slot = slot;
581 g_nameParam.flags = mode;
582 g_nameParam.maxent = maxent;
583 g_nameParam.mcT = table;
584 strncpy(g_nameParam.name, name, 1023);
585 g_nameParam.name[1023] = 0;
607 g_nameParam.port = port;
608 g_nameParam.slot = slot;
609 g_nameParam.flags = flags;
610 g_nameParam.mcT = &g_fileInfoBuff;
613 strncpy(g_nameParam.name, name, 1023);
614 g_nameParam.name[1023] = 0;
636 g_nameParam.port = port;
637 g_nameParam.slot = slot;
638 g_nameParam.flags = 0;
639 strncpy(g_nameParam.name, name, 1023);
640 g_nameParam.name[1023] = 0;
661 g_descParam.port = port;
662 g_descParam.slot = slot;
683 g_descParam.port = port;
684 g_descParam.slot = slot;
705 g_nameParam.port = port;
706 g_nameParam.slot = slot;
707 strncpy(g_nameParam.name, path, 1023);
708 g_nameParam.name[1023] = 0;
717int mcRename(
int port,
int slot,
const char* oldName,
const char* newName)
729 g_nameParam.port = port;
730 g_nameParam.slot = slot;
731 g_nameParam.flags = 0x10;
732 g_nameParam.mcT = &g_fileInfoBuff;
733 strncpy(g_nameParam.name, oldName, 1023);
734 g_nameParam.name[1023] = 0;
735 strncpy((
char*)g_fileInfoBuff.EntryName, newName, 31);
736 g_fileInfoBuff.EntryName[31] = 0;
756 g_descParam.port=port;
757 g_descParam.slot=slot;
758 g_descParam.offset=block;
759 g_descParam.origin=mode;
761 if((result = SifCallRpc(&g_cdata,
mcRpcCmd[
g_mcType][MC_RPCCMD_ERASE_BLOCK],
SIF_RPC_M_NOWAIT, &g_descParam,
sizeof(g_descParam), &g_rdata, 4, NULL, NULL))==0){
773 unsigned char data1[16];
774 unsigned char data2[16];
775 unsigned char padding[16];
781 unsigned int misaligned;
783 if((misaligned=(
unsigned int)data->dest1&0xF)!=0){
784 memcpy(UNCACHED_SEG(data->dest1), UNCACHED_SEG(data->data1), 16-misaligned);
785 memcpy(UNCACHED_SEG((
unsigned int)data->dest1+(16-misaligned)), UNCACHED_SEG((
unsigned int)data->data1+(16-misaligned)+0x1F0), misaligned);
789int mcReadPage(
int port,
int slot,
unsigned int page,
void *buffer){
800 g_descParam.port=port;
801 g_descParam.slot=slot;
802 g_descParam.buffer=buffer;
803 g_descParam.param=&libmc_ReadPageAlignData;
805 SifWriteBackDCache(buffer, 0x200);
807 if((result = SifCallRpc(&g_cdata,
mcRpcCmd[
g_mcType][MC_RPCCMD_READ_PAGE],
SIF_RPC_M_NOWAIT, &g_descParam,
sizeof(g_descParam), &g_rdata, 4, (
void*)&libmc_ReadAlignFunction, UNCACHED_SEG(&libmc_ReadPageAlignData)))==0){
815 int result, misaligned;
825 g_descParam.port=port;
826 g_descParam.slot=slot;
827 g_descParam.buffer=(
void*)buffer;
829 SifWriteBackDCache((
void*)buffer, 512);
831 if((misaligned=(
unsigned int)buffer&0xF)!=0){
832 memcpy(g_descParam.data, buffer, 16-misaligned);
833 memcpy((
void*)(g_descParam.data+(16-misaligned)), (
void*)((
const u8 *)buffer+(16-misaligned)+0x1F0), misaligned);
836 if((result = SifCallRpc(&g_cdata,
mcRpcCmd[
g_mcType][MC_RPCCMD_WRITE_PAGE],
SIF_RPC_M_NOWAIT, &g_descParam,
sizeof(g_descParam), &g_rdata, 4, NULL, NULL))==0){
860 if((ret = SifCallRpc(&g_cdata,
mcRpcCmd[
g_mcType][MC_RPCCMD_CHG_PRITY],
SIF_RPC_M_NOWAIT, &g_descParam,
sizeof(g_descParam), &g_rdata, 4, NULL, NULL)) != 0)
866int mcSync(
int mode,
int *cmd,
int *result)
875 funcIsExecuting = SifCheckStatRpc(&g_cdata);
880 while(SifCheckStatRpc(&g_cdata))
883 for(i=0; i<100000; i++)
895 if(funcIsExecuting == 1)
903 *result = g_rdata.result;
911 g_cdata.server = NULL;
int mcGetEntSpace(int port, int slot, const char *path)
int mcUnformat(int port, int slot)
int mcSeek(int fd, int offset, int origin)
int mcRead(int fd, void *buffer, int size)
int mcMkDir(int port, int slot, const char *name)
static const int mcRpcCmd[2][17]
int mcWritePage(int port, int slot, int page, const void *buffer)
int mcEraseBlock(int port, int slot, int block, int mode)
int mcOpen(int port, int slot, const char *name, int mode)
int mcRename(int port, int slot, const char *oldName, const char *newName)
int mcChdir(int port, int slot, const char *newDir, char *currentDir)
int mcSetFileInfo(int port, int slot, const char *name, const sceMcTblGetDir *info, unsigned flags)
int mcReadPage(int port, int slot, unsigned int page, void *buffer)
int mcGetDir(int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir *table)
static void mcStoreDir(void *arg)
static void mcReadFixAlign(void *data_raw)
static void mcGetInfoApdx(void *info)
int mcGetInfo(int port, int slot, int *type, int *free, int *format)
int mcDelete(int port, int slot, const char *name)
int mcFormat(int port, int slot)
int mcWrite(int fd, const void *buffer, int size)
int mcChangeThreadPriority(int level)
int mcSync(int mode, int *cmd, int *result)
static unsigned int g_currentCmd