12#include "mcman-internal.h"
15static int mcman_mc_port = 0;
16static int mcman_mc_slot = 0;
17static int mcman_io_sema = 0;
20int mc_init(MC_IO_DEV_T *iop_dev);
21int mc_deinit(MC_IO_DEV_T *dev);
22#if MCMAN_ENABLE_EXTENDED_DEV_OPS
23int mc_open(MC_IO_FIL_T *f,
const char *filename,
int flags,
int mode);
25int mc_open(MC_IO_FIL_T *f,
const char *filename,
int flags);
27int mc_close(MC_IO_FIL_T *f);
28int mc_lseek(MC_IO_FIL_T *f,
int pos,
int where);
29int mc_read(MC_IO_FIL_T *f,
void *buf,
int size);
30int mc_write(MC_IO_FIL_T *f,
void *buf,
int size);
31#if MCMAN_ENABLE_EXTENDED_DEV_OPS
32int mc_format(MC_IO_FIL_T *f,
const char *dev,
const char *blockdev,
void *arg,
int arglen);
34int mc_format(MC_IO_FIL_T *f);
36int mc_remove(MC_IO_FIL_T *f,
const char *filename);
37#if MCMAN_ENABLE_EXTENDED_DEV_OPS
38int mc_mkdir(MC_IO_FIL_T *f,
const char *dirname,
int mode);
40int mc_mkdir(MC_IO_FIL_T *f,
const char *dirname);
42int mc_rmdir(MC_IO_FIL_T *f,
const char *dirname);
43int mc_dopen(MC_IO_FIL_T *f,
const char *dirname);
44int mc_dclose(MC_IO_FIL_T *f);
45int mc_dread(MC_IO_FIL_T *f, MC_IO_DRE_T *dirent);
46int mc_getstat(MC_IO_FIL_T *f,
const char *filename, MC_IO_STA_T *stat);
47int mc_chstat(MC_IO_FIL_T *f,
const char *filename, MC_IO_STA_T *stat,
unsigned int statmask);
48int mc_ioctl(MC_IO_FIL_T *f,
int cmd,
void* param);
50#if MCMAN_ENABLE_EXTENDED_DEV_OPS
51int mc_rename(MC_IO_FIL_T *f,
const char *old,
const char *
new);
52int mc_chdir(MC_IO_FIL_T *f,
const char *name);
53int mc_sync(MC_IO_FIL_T *f,
const char *dev,
int flag);
54int mc_mount(MC_IO_FIL_T *f,
const char *fsname,
const char *devname,
int flag,
void *arg,
int arglen);
55int mc_umount(MC_IO_FIL_T *f,
const char *fsname);
56s64 mc_lseek64(MC_IO_FIL_T *f, s64 pos,
int where);
57int mc_devctl(MC_IO_FIL_T *f,
const char *name,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen);
58int mc_symlink(MC_IO_FIL_T *f,
const char *old,
const char *
new);
59int mc_readlink(MC_IO_FIL_T *f,
const char *path,
char *buf,
unsigned int buflen);
60int mc_ioctl2(MC_IO_FIL_T *f,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen);
64static MC_IO_OPS_T mcman_mcops = {
82#if MCMAN_ENABLE_EXTENDED_DEV_OPS
97static MC_IO_DEV_T mcman_mcdev = {
98#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
100#elif defined(BUILDING_VMCMAN)
102#elif defined(BUILDING_XFROMMAN)
106#if MCMAN_ENABLE_EXTENDED_DEV_OPS
111#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
113#elif defined(BUILDING_VMCMAN)
114 "Virtual Memory Card",
115#elif defined(BUILDING_XFROMMAN)
116 "External flash rom",
122int mc_init(MC_IO_DEV_T *dev)
130int mcman_ioerrcode(
int errcode)
132 register int r = errcode;
166int mcman_modloadcb(
const char *filename,
int *port,
int *slot)
168 register const char *path = filename;
173 while (*path == 0x20)
177 if (((u8)path[0] | 0x20) != mcman_mcdev.name[0])
179 if (((u8)path[1] | 0x20) != mcman_mcdev.name[1])
182 if ((u32)strlen(path) < 2)
return 2;
184 upos = mcman_chrpos(path,
':');
191 if (((u8)path[upos] - 0x30) < 10)
192 *port = (u8)path[upos] - 0x30;
205 for (m = 1; ((u8)path[upos --] - 0x30) < 10; m = v << 1) {
207 *slot += m * (path[upos] - 0x30);
216void mcman_unit2card(u32 unit)
218#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
219 mcman_mc_port = unit & 1;
220 mcman_mc_slot = (unit >> 1) & (MCMAN_MAXSLOT - 1);
221#elif defined(BUILDING_VMCMAN)
223 mcman_mc_slot = unit & (MCMAN_MAXSLOT - 1);
224#elif defined(BUILDING_XFROMMAN)
255int mcman_initdev(
void)
259#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
260 SetCheckKelfPathCallback(mcman_modloadcb);
263#if MCMAN_ENABLE_EXTENDED_DEV_OPS
264 iomanX_DelDrv(mcman_mcdev.name);
265 if (iomanX_AddDrv(&mcman_mcdev)) {
270 DelDrv(mcman_mcdev.name);
271 if (AddDrv(&mcman_mcdev)) {
281 mcman_io_sema = CreateSema(&smp);
287void mcman_deinitdev(
void)
289 WaitSema(mcman_io_sema);
290#if MCMAN_ENABLE_EXTENDED_DEV_OPS
291 iomanX_DelDrv(mcman_mcdev.name);
293 DelDrv(mcman_mcdev.name);
298int mc_deinit(MC_IO_DEV_T *dev)
303 DeleteSema(mcman_io_sema);
309#if MCMAN_ENABLE_EXTENDED_DEV_OPS
310int mc_open(MC_IO_FIL_T *f,
const char *filename,
int flags,
int mode)
312int mc_open(MC_IO_FIL_T *f,
const char *filename,
int flags)
317 WaitSema(mcman_io_sema);
318 mcman_unit2card(f->unit);
320 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
322 r = McOpen(mcman_mc_port, mcman_mc_slot, filename, flags);
324 f->privdata = (
void*)(uiptr)(int)r;
326 SignalSema(mcman_io_sema);
328 return mcman_ioerrcode(r);
332int mc_close(MC_IO_FIL_T *f)
336 WaitSema(mcman_io_sema);
337 r = McClose((
int)(uiptr)f->privdata);
338 SignalSema(mcman_io_sema);
340 return mcman_ioerrcode(r);
344int mc_lseek(MC_IO_FIL_T *f,
int pos,
int where)
348 WaitSema(mcman_io_sema);
349 r = McSeek((
int)(uiptr)f->privdata, pos, where);
350 SignalSema(mcman_io_sema);
352 return mcman_ioerrcode(r);
356int mc_read(MC_IO_FIL_T *f,
void *buf,
int size)
360 WaitSema(mcman_io_sema);
361 r = McRead((
int)(uiptr)f->privdata, buf, size);
362 SignalSema(mcman_io_sema);
364 return mcman_ioerrcode(r);
368int mc_write(MC_IO_FIL_T *f,
void *buf,
int size)
372 WaitSema(mcman_io_sema);
373 r = McWrite((
int)(uiptr)f->privdata, buf, size);
374 SignalSema(mcman_io_sema);
376 return mcman_ioerrcode(r);
380#if MCMAN_ENABLE_EXTENDED_DEV_OPS
381int mc_format(MC_IO_FIL_T *f,
const char *dev,
const char *blockdev,
void *arg,
int arglen)
383int mc_format(MC_IO_FIL_T *f)
388#if MCMAN_ENABLE_EXTENDED_DEV_OPS
395 WaitSema(mcman_io_sema);
396 mcman_unit2card(f->unit);
398 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
400 r = McFormat(mcman_mc_port, mcman_mc_slot);
402 SignalSema(mcman_io_sema);
404 return mcman_ioerrcode(r);
408int mc_remove(MC_IO_FIL_T *f,
const char *filename)
412 WaitSema(mcman_io_sema);
413 mcman_unit2card(f->unit);
415 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
417 r = McDelete(mcman_mc_port, mcman_mc_slot, filename, 0);
419 SignalSema(mcman_io_sema);
421 return mcman_ioerrcode(r);
425#if MCMAN_ENABLE_EXTENDED_DEV_OPS
426int mc_mkdir(MC_IO_FIL_T *f,
const char *dirname,
int mode)
428int mc_mkdir(MC_IO_FIL_T *f,
const char *dirname)
433#if MCMAN_ENABLE_EXTENDED_DEV_OPS
437 WaitSema(mcman_io_sema);
438 mcman_unit2card(f->unit);
440 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
442 r = McOpen(mcman_mc_port, mcman_mc_slot, dirname, 0x40);
444 SignalSema(mcman_io_sema);
446 return mcman_ioerrcode(r);
450int mc_rmdir(MC_IO_FIL_T *f,
const char *dirname)
454 WaitSema(mcman_io_sema);
455 mcman_unit2card(f->unit);
457 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
459 r = McDelete(mcman_mc_port, mcman_mc_slot, dirname, 0);
461 SignalSema(mcman_io_sema);
463 return mcman_ioerrcode(r);
467int mc_dopen(MC_IO_FIL_T *f,
const char *dirname)
471 WaitSema(mcman_io_sema);
472 mcman_unit2card(f->unit);
474 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
476 r = McOpen(mcman_mc_port, mcman_mc_slot, dirname, 0);
478 f->privdata = (
void*)(uiptr)(int)r;
481 SignalSema(mcman_io_sema);
483 return mcman_ioerrcode(r);
487int mc_dclose(MC_IO_FIL_T *f)
491 WaitSema(mcman_io_sema);
492 r = McClose((
int)(uiptr)f->privdata);
493 SignalSema(mcman_io_sema);
495 return mcman_ioerrcode(r);
499int mc_dread(MC_IO_FIL_T *f, MC_IO_DRE_T *dirent)
503 WaitSema(mcman_io_sema);
504 r = mcman_dread((
int)(uiptr)f->privdata, dirent);
505 SignalSema(mcman_io_sema);
507 return mcman_ioerrcode(r);
511int mc_getstat(MC_IO_FIL_T *f,
const char *filename, MC_IO_STA_T *stat)
515 WaitSema(mcman_io_sema);
516 mcman_unit2card(f->unit);
518 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
520 r = mcman_getstat(mcman_mc_port, mcman_mc_slot, filename, stat);
523 SignalSema(mcman_io_sema);
525 return mcman_ioerrcode(r);
529int mc_chstat(MC_IO_FIL_T *f,
const char *filename, MC_IO_STA_T *stat,
unsigned int statmask)
534 WaitSema(mcman_io_sema);
535 mcman_unit2card(f->unit);
537 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
543 if (statmask & MC_IO_CST_ATTR) {
545 mctbl.Reserve2 = stat->attr;
548 if (statmask & MC_IO_CST_MODE) {
551 if (stat->mode & MC_IO_S_RD) mctbl.AttrFile |= sceMcFileAttrReadable;
552 if (stat->mode & MC_IO_S_WR) mctbl.AttrFile |= sceMcFileAttrWriteable;
553 if (stat->mode & MC_IO_S_EX) mctbl.AttrFile |= sceMcFileAttrExecutable;
554#if !MCMAN_ENABLE_EXTENDED_DEV_OPS
555 if (stat->mode & SCE_STM_C) mctbl.AttrFile |= sceMcFileAttrDupProhibit;
556 if (stat->mode & sceMcFileAttrPS1) mctbl.AttrFile |= sceMcFileAttrPS1;
557 if (stat->mode & sceMcFileAttrPDAExec) mctbl.AttrFile |= sceMcFileAttrPDAExec;
561 if (statmask & MC_IO_CST_CT) {
566 if (statmask & MC_IO_CST_MT) {
571 r = McSetFileInfo(mcman_mc_port, mcman_mc_slot, filename, &mctbl, flags);
573 SignalSema(mcman_io_sema);
575 return mcman_ioerrcode(r);
579int mc_ioctl(MC_IO_FIL_T *f,
int cmd,
void* param)
585 WaitSema(mcman_io_sema);
586 SignalSema(mcman_io_sema);
590#if MCMAN_ENABLE_EXTENDED_DEV_OPS
592int mc_rename(MC_IO_FIL_T *f,
const char *old,
const char *
new)
601 WaitSema(mcman_io_sema);
602 mcman_unit2card(f->unit);
604 r = McDetectCard2(mcman_mc_port, mcman_mc_slot);
610 memcpy((
void *)mctbl.EntryName,
new, l);
611 mctbl.EntryName[l] = 0;
612 r = McSetFileInfo(mcman_mc_port, mcman_mc_slot, old, &mctbl, sceMcFileAttrFile);
613 r = mcman_ioerrcode(r);
620 r = mcman_ioerrcode(r);
622 SignalSema(mcman_io_sema);
628int mc_chdir(MC_IO_FIL_T *f,
const char *name)
633 WaitSema(mcman_io_sema);
634 SignalSema(mcman_io_sema);
639int mc_sync(MC_IO_FIL_T *f,
const char *dev,
int flag)
645 WaitSema(mcman_io_sema);
646 SignalSema(mcman_io_sema);
651int mc_mount(MC_IO_FIL_T *f,
const char *fsname,
const char *devname,
int flag,
void *arg,
int arglen)
660 WaitSema(mcman_io_sema);
661 mcman_unit2card(f->unit);
662#if defined(BUILDING_VMCMAN)
663 r = mcman_iomanx_backing_mount(mcman_mc_port, mcman_mc_slot, devname);
667 SignalSema(mcman_io_sema);
672int mc_umount(MC_IO_FIL_T *f,
const char *fsname)
678 WaitSema(mcman_io_sema);
679 mcman_unit2card(f->unit);
680#if defined(BUILDING_VMCMAN)
681 r = mcman_iomanx_backing_umount(mcman_mc_port, mcman_mc_slot);
685 SignalSema(mcman_io_sema);
690s64 mc_lseek64(MC_IO_FIL_T *f, s64 pos,
int where)
692 return mc_lseek(f, pos, where);
696int mc_devctl(MC_IO_FIL_T *f,
const char *name,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen)
706 WaitSema(mcman_io_sema);
707 SignalSema(mcman_io_sema);
712int mc_symlink(MC_IO_FIL_T *f,
const char *old,
const char *
new)
718 WaitSema(mcman_io_sema);
719 SignalSema(mcman_io_sema);
724int mc_readlink(MC_IO_FIL_T *f,
const char *path,
char *buf,
unsigned int buflen)
731 WaitSema(mcman_io_sema);
732 SignalSema(mcman_io_sema);
737int mc_ioctl2(MC_IO_FIL_T *f,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen)
746 WaitSema(mcman_io_sema);
747 SignalSema(mcman_io_sema);