ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
libmc.h File Reference
#include <libmc-common.h>
+ Include dependency graph for libmc.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mcIcon
 
struct  sceMcTblGetDir
 
struct  mcTable
 

Macros

#define MC_WAIT   0
 
#define MC_NOWAIT   1
 
#define MC_TYPE_PSX   sceMcTypePS1
 
#define MC_TYPE_PS2   sceMcTypePS2
 
#define MC_TYPE_POCKET   sceMcTypePDA
 
#define MC_TYPE_NONE   sceMcTypeNoCard
 
#define MC_FORMATTED   1
 
#define MC_UNFORMATTED   0
 
#define MC_ATTR_READABLE   sceMcFileAttrReadable
 
#define MC_ATTR_WRITEABLE   sceMcFileAttrWriteable
 
#define MC_ATTR_EXECUTABLE   sceMcFileAttrExecutable
 
#define MC_ATTR_PROTECTED   sceMcFileAttrDupProhibit
 
#define MC_ATTR_FILE   sceMcFileAttrFile
 
#define MC_ATTR_SUBDIR   sceMcFileAttrSubdir
 
#define MC_ATTR_OBJECT   (sceMcFileAttrFile|sceMcFileAttrSubdir)
 
#define MC_ATTR_CLOSED   sceMcFileAttrClosed
 
#define MC_ATTR_PDAEXEC   sceMcFileAttrPDAExec
 
#define MC_ATTR_PSX   sceMcFileAttrPS1
 
#define MC_ATTR_HIDDEN   sceMcFileAttrHidden
 
#define MC_TYPE_MC   0
 
#define MC_TYPE_XMC   1
 

Typedefs

typedef int iconIVECTOR[4]
 
typedef float iconFVECTOR[4]
 

Enumerations

enum  MC_FUNC_NUMBERS {
  MC_FUNC_NONE = 0x00 ,
  MC_FUNC_GET_INFO ,
  MC_FUNC_OPEN ,
  MC_FUNC_CLOSE ,
  MC_FUNC_SEEK ,
  MC_FUNC_READ ,
  MC_FUNC_WRITE ,
  MC_FUNC_FLUSH = 0x0A ,
  MC_FUNC_MK_DIR ,
  MC_FUNC_CH_DIR ,
  MC_FUNC_GET_DIR ,
  MC_FUNC_SET_INFO ,
  MC_FUNC_DELETE ,
  MC_FUNC_FORMAT ,
  MC_FUNC_UNFORMAT ,
  MC_FUNC_GET_ENT ,
  MC_FUNC_RENAME ,
  MC_FUNC_CHG_PRITY ,
  MC_FUNC_ERASE_BLOCK = 0x5A ,
  MC_FUNC_READ_PAGE ,
  MC_FUNC_WRITE_PAGE
}
 
enum  MCICON_TYPES {
  MCICON_TYPE_SAVED_DATA = 0 ,
  MCICON_TYPE_SOFTWARE_PS2 ,
  MCICON_TYPE_SOFTWARE_PKT ,
  MCICON_TYPE_SETTINGS_DATA
}
 

Functions

int mcInit (int type)
 
int mcGetInfo (int port, int slot, int *type, int *free, int *format)
 
int mcOpen (int port, int slot, const char *name, int mode)
 
int mcClose (int fd)
 
int mcSeek (int fd, int offset, int origin)
 
int mcRead (int fd, void *buffer, int size)
 
int mcWrite (int fd, const void *buffer, int size)
 
int mcFlush (int fd)
 
int mcMkDir (int port, int slot, const char *name)
 
int mcChdir (int port, int slot, const char *newDir, char *currentDir)
 
int mcGetDir (int port, int slot, const char *name, unsigned mode, int maxent, sceMcTblGetDir *table)
 
int mcSetFileInfo (int port, int slot, const char *name, const sceMcTblGetDir *info, unsigned flags)
 
int mcDelete (int port, int slot, const char *name)
 
int mcFormat (int port, int slot)
 
int mcUnformat (int port, int slot)
 
int mcGetEntSpace (int port, int slot, const char *path)
 
int mcRename (int port, int slot, const char *oldName, const char *newName)
 
int mcEraseBlock (int port, int slot, int block, int mode)
 
int mcReadPage (int port, int slot, unsigned int page, void *buffer)
 
int mcWritePage (int port, int slot, int page, const void *buffer)
 
int mcChangeThreadPriority (int level)
 
int mcSync (int mode, int *cmd, int *result)
 
int mcReset (void)
 

Detailed Description

Macros, structures & function prototypes for mclib.

Definition in file libmc.h.

Macro Definition Documentation

◆ MC_ATTR_CLOSED

#define MC_ATTR_CLOSED   sceMcFileAttrClosed

Definition at line 58 of file libmc.h.

◆ MC_ATTR_EXECUTABLE

#define MC_ATTR_EXECUTABLE   sceMcFileAttrExecutable

Definition at line 52 of file libmc.h.

◆ MC_ATTR_FILE

#define MC_ATTR_FILE   sceMcFileAttrFile

Definition at line 54 of file libmc.h.

◆ MC_ATTR_HIDDEN

#define MC_ATTR_HIDDEN   sceMcFileAttrHidden

not hidden in osdsys, but it is to games

Definition at line 62 of file libmc.h.

◆ MC_ATTR_OBJECT

#define MC_ATTR_OBJECT   (sceMcFileAttrFile|sceMcFileAttrSubdir)

File or directory

Definition at line 57 of file libmc.h.

◆ MC_ATTR_PDAEXEC

#define MC_ATTR_PDAEXEC   sceMcFileAttrPDAExec

Definition at line 59 of file libmc.h.

◆ MC_ATTR_PROTECTED

#define MC_ATTR_PROTECTED   sceMcFileAttrDupProhibit

Definition at line 53 of file libmc.h.

◆ MC_ATTR_PSX

#define MC_ATTR_PSX   sceMcFileAttrPS1

Definition at line 60 of file libmc.h.

◆ MC_ATTR_READABLE

#define MC_ATTR_READABLE   sceMcFileAttrReadable

Definition at line 50 of file libmc.h.

◆ MC_ATTR_SUBDIR

#define MC_ATTR_SUBDIR   sceMcFileAttrSubdir

Definition at line 55 of file libmc.h.

◆ MC_ATTR_WRITEABLE

#define MC_ATTR_WRITEABLE   sceMcFileAttrWriteable

Definition at line 51 of file libmc.h.

◆ MC_FORMATTED

#define MC_FORMATTED   1

Definition at line 46 of file libmc.h.

◆ MC_NOWAIT

#define MC_NOWAIT   1

Definition at line 39 of file libmc.h.

◆ MC_TYPE_MC

#define MC_TYPE_MC   0

Definition at line 195 of file libmc.h.

◆ MC_TYPE_NONE

#define MC_TYPE_NONE   sceMcTypeNoCard

Definition at line 44 of file libmc.h.

◆ MC_TYPE_POCKET

#define MC_TYPE_POCKET   sceMcTypePDA

Definition at line 43 of file libmc.h.

◆ MC_TYPE_PS2

#define MC_TYPE_PS2   sceMcTypePS2

Definition at line 42 of file libmc.h.

◆ MC_TYPE_PSX

#define MC_TYPE_PSX   sceMcTypePS1

Definition at line 41 of file libmc.h.

◆ MC_TYPE_XMC

#define MC_TYPE_XMC   1

Definition at line 196 of file libmc.h.

◆ MC_UNFORMATTED

#define MC_UNFORMATTED   0

Definition at line 47 of file libmc.h.

◆ MC_WAIT

#define MC_WAIT   0

Definition at line 38 of file libmc.h.

Typedef Documentation

◆ iconFVECTOR

typedef float iconFVECTOR[4]

Definition at line 103 of file libmc.h.

◆ iconIVECTOR

typedef int iconIVECTOR[4]

Definition at line 102 of file libmc.h.

Enumeration Type Documentation

◆ MC_FUNC_NUMBERS

function numbers returned by mcSync in the 'cmd' pointer

Enumerator
MC_FUNC_NONE 
MC_FUNC_GET_INFO 
MC_FUNC_OPEN 
MC_FUNC_CLOSE 
MC_FUNC_SEEK 
MC_FUNC_READ 
MC_FUNC_WRITE 
MC_FUNC_FLUSH 
MC_FUNC_MK_DIR 
MC_FUNC_CH_DIR 
MC_FUNC_GET_DIR 
MC_FUNC_SET_INFO 
MC_FUNC_DELETE 
MC_FUNC_FORMAT 
MC_FUNC_UNFORMAT 
MC_FUNC_GET_ENT 
MC_FUNC_RENAME 
MC_FUNC_CHG_PRITY 
MC_FUNC_ERASE_BLOCK 
MC_FUNC_READ_PAGE 
MC_FUNC_WRITE_PAGE 

Definition at line 65 of file libmc.h.

65  {
66  MC_FUNC_NONE = 0x00,
73  MC_FUNC_FLUSH = 0x0A,
84  MC_FUNC_ERASE_BLOCK = 0x5A,
87 };
@ MC_FUNC_GET_ENT
Definition: libmc.h:81
@ MC_FUNC_DELETE
Definition: libmc.h:78
@ MC_FUNC_WRITE_PAGE
Definition: libmc.h:86
@ MC_FUNC_UNFORMAT
Definition: libmc.h:80
@ MC_FUNC_FORMAT
Definition: libmc.h:79
@ MC_FUNC_GET_INFO
Definition: libmc.h:67
@ MC_FUNC_MK_DIR
Definition: libmc.h:74
@ MC_FUNC_CLOSE
Definition: libmc.h:69
@ MC_FUNC_GET_DIR
Definition: libmc.h:76
@ MC_FUNC_WRITE
Definition: libmc.h:72
@ MC_FUNC_SET_INFO
Definition: libmc.h:77
@ MC_FUNC_CH_DIR
Definition: libmc.h:75
@ MC_FUNC_READ_PAGE
Definition: libmc.h:85
@ MC_FUNC_NONE
Definition: libmc.h:66
@ MC_FUNC_SEEK
Definition: libmc.h:70
@ MC_FUNC_RENAME
Definition: libmc.h:82
@ MC_FUNC_CHG_PRITY
Definition: libmc.h:83
@ MC_FUNC_FLUSH
Definition: libmc.h:73
@ MC_FUNC_ERASE_BLOCK
Definition: libmc.h:84
@ MC_FUNC_OPEN
Definition: libmc.h:68
@ MC_FUNC_READ
Definition: libmc.h:71

◆ MCICON_TYPES

These types show up in the OSD browser when set. If the OSD doesn't know the number it'll display "Unrecognizable Data" or so. AFAIK these have no other effects. Known type IDs for icon.sys file:

Enumerator
MCICON_TYPE_SAVED_DATA 
MCICON_TYPE_SOFTWARE_PS2 
MCICON_TYPE_SOFTWARE_PKT 
MCICON_TYPE_SETTINGS_DATA 

Definition at line 95 of file libmc.h.

95  {
96  MCICON_TYPE_SAVED_DATA = 0, // "Saved Data (PlayStation(r)2)"
97  MCICON_TYPE_SOFTWARE_PS2, // "Software (PlayStation(r)2)"
98  MCICON_TYPE_SOFTWARE_PKT, // "Software (PocketStation(r))"
99  MCICON_TYPE_SETTINGS_DATA // "Settings File (PlayStation(r)2)"
100 };
@ MCICON_TYPE_SOFTWARE_PS2
Definition: libmc.h:97
@ MCICON_TYPE_SETTINGS_DATA
Definition: libmc.h:99
@ MCICON_TYPE_SAVED_DATA
Definition: libmc.h:96
@ MCICON_TYPE_SOFTWARE_PKT
Definition: libmc.h:98

Function Documentation

◆ mcChangeThreadPriority()

int mcChangeThreadPriority ( int  level)

change mcserv thread priority (I don't think this is implemented properly) Note: rom0:MCSERV does not support this. mcSync returns: 0 if ok < 0 if error

Parameters
levelthread priority
Returns
0 = success; -1 = error

Definition at line 843 of file libmc.c.

844 {
845  int ret;
846 
847  // check lib is inited
849  return -1;
850  // check nothing else is processing
852  return g_currentCmd;
853 
854  // set global variables
855 // *(u32*)mcCmd.name = level;
856 
857  // call sif function
859  return ret;
861  return ret;
862 }
static mcDescParam_t g_descParam
Definition: libmc.c:120
static int g_mclibInited
Definition: libmc.c:151
@ MC_RPCCMD_CHG_PRITY
Definition: libmc.c:46
static const int mcRpcCmd[2][17]
Definition: libmc.c:56
static SifRpcClientData_t g_cdata
Definition: libmc.c:131
static int g_mcType
Definition: libmc.c:157
static union @26 g_rdata
static unsigned int g_currentCmd
Definition: libmc.c:154
#define MC_TYPE_MC
Definition: libmc.h:195
#define SIF_RPC_M_NOWAIT
Definition: sifrpc.h:24
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
#define NULL
Definition: tamtypes.h:91

References g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_CHG_PRITY, MC_FUNC_NONE, MC_RPCCMD_CHG_PRITY, MC_TYPE_MC, mcRpcCmd, NULL, SIF_RPC_M_NOWAIT, and SifCallRpc().

◆ mcChdir()

int mcChdir ( int  port,
int  slot,
const char *  newDir,
char *  currentDir 
)

change current dir (can also get current dir) mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
newDirnew dir to change to
currentDirbuffer to get current dir (use 0 if not needed)
Returns
0 = successful; < 0 = error

Definition at line 541 of file libmc.c.

542 {
543  int ret;
544 
545  // check mc lib is inited
546  if(!g_mclibInited)
547  return -1;
548  // check nothing else is processing
550  return g_currentCmd;
551 
552  // set global variables
556  strncpy(g_nameParam.name, newDir, 1023);
557  g_nameParam.name[1023] = 0;
558  SifWriteBackDCache(curDir, 1024);
559 
560  // send sif command
562  return ret;
564  return ret;
565 }
@ MC_RPCCMD_CH_DIR
Definition: libmc.c:39
static mcNameParam_t g_nameParam
Definition: libmc.c:115
static char curDir[1024]
Definition: libmc.c:146
static void mcStoreDir(void *arg)
Definition: libmc.c:219
s32 slot
Definition: libpad.c:176
s32 port
Definition: libpad.c:176
void SifWriteBackDCache(void *ptr, int size)
void(* SifRpcEndFunc_t)(void *end_param)
Definition: sifrpc.h:33
int port
Definition: libmc.c:104
char name[1024]
Definition: libmc.c:112
char * curdir
Definition: libmc.c:110
int slot
Definition: libmc.c:105

References mcNameParam_t::curdir, curDir, g_cdata, g_currentCmd, g_mclibInited, g_mcType, g_nameParam, g_rdata, MC_FUNC_CH_DIR, MC_FUNC_NONE, MC_RPCCMD_CH_DIR, mcRpcCmd, mcStoreDir(), mcNameParam_t::name, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), SifWriteBackDCache(), mcNameParam_t::slot, and slot.

◆ mcClose()

int mcClose ( int  fd)

close an open file on memcard mcSync returns: 0 if closed successfully < 0 = error

Parameters
fdfile descriptor of open file
Returns
0 successful; < 0 = error

Definition at line 403 of file libmc.c.

404 {
405  int ret;
406 
407  // check mc lib is inited
408  if(!g_mclibInited)
409  return -1;
410  // check nothing else is processing
412  return g_currentCmd;
413 
414  // set global variables
415  g_descParam.fd = fd;
416 
417  // send sif command
419  return ret;
421  return ret;
422 }
@ MC_RPCCMD_CLOSE
Definition: libmc.c:34

References mcDescParam_t::fd, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_CLOSE, MC_FUNC_NONE, MC_RPCCMD_CLOSE, mcRpcCmd, NULL, SIF_RPC_M_NOWAIT, and SifCallRpc().

◆ mcDelete()

int mcDelete ( int  port,
int  slot,
const char *  name 
)

delete file mcSync returns: 0 if deleted successfully < 0 if error

Parameters
portport number to delete from
slotslot number to delete from
namefilename to delete
Returns
0 = successful; < 0 = error

Definition at line 624 of file libmc.c.

625 {
626  int ret;
627 
628  // check lib is inited
629  if(!g_mclibInited)
630  return -1;
631  // check nothing else is processing
633  return g_currentCmd;
634 
635  // set global variables
638  g_nameParam.flags = 0;
639  strncpy(g_nameParam.name, name, 1023);
640  g_nameParam.name[1023] = 0;
641 
642  // call delete function
644  return ret;
646  return ret;
647 }
@ MC_RPCCMD_DELETE
Definition: libmc.c:42
int flags
Definition: libmc.c:106

References mcNameParam_t::flags, g_cdata, g_currentCmd, g_mclibInited, g_mcType, g_nameParam, g_rdata, MC_FUNC_DELETE, MC_FUNC_NONE, MC_RPCCMD_DELETE, mcRpcCmd, mcNameParam_t::name, NULL, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcNameParam_t::slot, and slot.

◆ mcEraseBlock()

int mcEraseBlock ( int  port,
int  slot,
int  block,
int  mode 
)

Erases a block on the memory card. Note: rom0:XMCSERV does not support this. mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
blockBlock number of the block to be erased.
modeMode: -1 to inhibit ECC recalculation of the erased block's pages (useful if sceMcWritePage is used to fill in its contents later on), 0 for normal operation.
Returns
0 = success; -1 = error

Definition at line 746 of file libmc.c.

746  {
747  int result;
748 
749  // check lib is inited
751  return -1;
752  // check nothing else is processing
754  return g_currentCmd;
755 
758  g_descParam.offset=block;
760 
763  }
764 
765  return result;
766 }
@ MC_RPCCMD_ERASE_BLOCK
Definition: libmc.c:48
s32 result
Definition: libmc.c:136
#define MC_TYPE_XMC
Definition: libmc.h:196
s32 mode
Definition: rpc_client.c:15

◆ mcFlush()

int mcFlush ( int  fd)

flush file cache to memcard mcSync returns: 0 if ok < 0 if error

Parameters
fdfile descriptor
Returns
0 = successful; < 0 = error

Definition at line 511 of file libmc.c.

512 {
513  int ret;
514 
515  // check mc lib is inited
516  if(!g_mclibInited)
517  return -1;
518  // check nothing else is processing
520  return g_currentCmd;
521 
522  // set global variables
523  g_descParam.fd = fd;
524 
525  // send sif command
527  return ret;
529  return ret;
530 }
@ MC_RPCCMD_FLUSH
Definition: libmc.c:38

References mcDescParam_t::fd, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_FLUSH, MC_FUNC_NONE, MC_RPCCMD_FLUSH, mcRpcCmd, NULL, SIF_RPC_M_NOWAIT, and SifCallRpc().

◆ mcFormat()

int mcFormat ( int  port,
int  slot 
)

format memory card mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
Returns
0 = success; -1 = error

Definition at line 649 of file libmc.c.

650 {
651  int ret;
652 
653  // check lib is inited
654  if(!g_mclibInited)
655  return -1;
656  // check nothing else is processing
658  return g_currentCmd;
659 
660  // set global variables
663 
664  // call format function
666  return ret;
668  return ret;
669 }
@ MC_RPCCMD_FORMAT
Definition: libmc.c:43

References g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_FORMAT, MC_FUNC_NONE, MC_RPCCMD_FORMAT, mcRpcCmd, NULL, mcDescParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcDescParam_t::slot, and slot.

◆ mcGetDir()

int mcGetDir ( int  port,
int  slot,
const char *  name,
unsigned  mode,
int  maxent,
sceMcTblGetDir table 
)

get memcard filelist mcSync result: 0 or more = number of file entries obtained (success) -2 = unformatted card -4 = dirname error

Parameters
portport number of memcard
slotslot number of memcard
namefilename to search for (can use wildcard and relative dirs)
modemode: 0 = first call, otherwise = followup call
maxextmaximum number of entries to be written to filetable in 1 call
tablemc table array
Returns
0 = successful; < 0 = error

Definition at line 567 of file libmc.c.

568 {
569  int ret;
570 
571  // check mc lib is inited
572  if(!g_mclibInited)
573  return -1;
574  // check nothing else is processing
576  return g_currentCmd;
577 
578  // set global variables
582  g_nameParam.maxent = maxent;
583  g_nameParam.mcT = table;
584  strncpy(g_nameParam.name, name, 1023);
585  g_nameParam.name[1023] = 0;
586  SifWriteBackDCache(table, maxent * sizeof(sceMcTblGetDir));
587 
588  // send sif command
590  return ret;
592  return ret;
593 }
@ MC_RPCCMD_GET_DIR
Definition: libmc.c:40
int maxent
Definition: libmc.c:107
sceMcTblGetDir * mcT
Definition: libmc.c:109

References mcNameParam_t::flags, g_cdata, g_currentCmd, g_mclibInited, g_mcType, g_nameParam, g_rdata, mcNameParam_t::maxent, MC_FUNC_GET_DIR, MC_FUNC_NONE, MC_RPCCMD_GET_DIR, mcRpcCmd, mcNameParam_t::mcT, mode, mcNameParam_t::name, NULL, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), SifWriteBackDCache(), mcNameParam_t::slot, and slot.

Referenced by main().

◆ mcGetEntSpace()

int mcGetEntSpace ( int  port,
int  slot,
const char *  path 
)

get free space info mcSync returns: 0 or more = number of free entries (success) < 0 if error

Parameters
portport number
slotslot number
pathpath to be checked
Returns
0 or more = number of empty entries; -1 = error

Definition at line 693 of file libmc.c.

694 {
695  int ret;
696 
697  // check lib is inited
699  return -1;
700  // check nothing else is processing
702  return g_currentCmd;
703 
704  // set global variables
707  strncpy(g_nameParam.name, path, 1023);
708  g_nameParam.name[1023] = 0;
709 
710  // call sif function
712  return ret;
714  return ret;
715 }
@ MC_RPCCMD_GET_ENT
Definition: libmc.c:45

References g_cdata, g_currentCmd, g_mclibInited, g_mcType, g_nameParam, g_rdata, MC_FUNC_GET_ENT, MC_FUNC_NONE, MC_RPCCMD_GET_ENT, MC_TYPE_MC, mcRpcCmd, mcNameParam_t::name, NULL, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcNameParam_t::slot, and slot.

◆ mcGetInfo()

int mcGetInfo ( int  port,
int  slot,
int *  type,
int *  free,
int *  format 
)

get memcard state mcSync result: 0 = same card as last getInfo call -1 = formatted card inserted since last getInfo call -2 = unformatted card inserted since last getInfo call < -2 = memcard access error (could be due to accessing psx memcard)

Parameters
portport number
slotslot number
typepointer to get memcard type
freepointer to get number of free clusters
formatpointer to get whether or not the card is formatted (Note: Originally, sceMcGetInfo didn't have a 5th argument for returning the format status. As this is emulated based on the return value of sceMcSync() when rom0:MCSERV is used, please keep track of the return value from sceMcSync instead!)
Returns
0 = successful; < 0 = error

Definition at line 336 of file libmc.c.

337 {
338  int ret;
339 
340  // check mc lib is inited
341  if(!g_mclibInited)
342  return -1;
343  // check nothing else is processing
345  return g_currentCmd;
346 
347  // set global variables
348  if(g_mcType == MC_TYPE_MC)
349  {
352  g_descParam.size = (type) ? 1 : 0;
353  g_descParam.offset = (free) ? 1 : 0;
354  g_descParam.origin = (format) ? 1 : 0;
356  }
357  else
358  {
361  g_descParam.size = (format) ? 1 : 0;
362  g_descParam.offset = (free) ? 1 : 0;
363  g_descParam.origin = (type) ? 1 : 0;
365  }
366  g_pType = type;
367  g_pFree = free;
368  g_pFormat = format;
370 
371  // send sif command
373  return ret;
375  return ret;
376 }
static int endParameter[48]
Definition: libmc.c:145
@ MC_RPCCMD_GET_INFO
Definition: libmc.c:32
static void mcGetInfoApdx(void *info)
Definition: libmc.c:163
static int * g_pFree
Definition: libmc.c:142
static int * g_pFormat
Definition: libmc.c:143
static int * g_pType
Definition: libmc.c:141

References endParameter, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_pFormat, g_pFree, g_pType, g_rdata, MC_FUNC_GET_INFO, MC_FUNC_NONE, MC_RPCCMD_GET_INFO, MC_TYPE_MC, mcGetInfoApdx(), mcRpcCmd, mcDescParam_t::offset, mcDescParam_t::origin, mcDescParam_t::param, mcDescParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), SifWriteBackDCache(), mcDescParam_t::size, mcDescParam_t::slot, and slot.

Referenced by main().

◆ mcInit()

int mcInit ( int  type)

init memcard lib

Parameters
typeMC_TYPE_MC = use MCSERV/MCMAN; MC_TYPE_XMC = use XMCSERV/XMCMAN
Returns
0 = successful; < 0 = error

Definition at line 230 of file libmc.c.

231 {
232  int ret=0;
234  static int _rb_count = 0;
235 
236  if(_rb_count != _iop_reboot_count)
237  {
238  _rb_count = _iop_reboot_count;
239  mcReset();
240  }
241 
242  if(g_mclibInited)
243  return -1;
244 
245  SifInitRpc(0);
246 
247  // set which modules to use
248  g_mcType = type;
249 
250  // bind to mc rpc on iop
251  do
252  {
253  if((ret=SifBindRpc(&g_cdata, 0x80000400, 0)) < 0)
254  {
255  #ifdef MC_DEBUG
256  printf("libmc: bind error\n");
257  #endif
258 
259  return ret;
260  }
261  if(g_cdata.server == NULL)
262  nopdelay();
263  }
264  while (g_cdata.server == NULL);
265 
266  // for some reason calling this init sif function with 'mcserv' makes all other
267  // functions not work properly. although NOT calling it means that detecting
268  // whether or not cards are formatted doesnt seem to work :P
269  if(g_mcType == MC_TYPE_MC)
270  {
271 #ifdef MC_DEBUG
272  printf("libmc: using MCMAN & MCSERV\n");
273 
274 #endif
275  g_descParam.offset = -217;
276 
277  // call init function
278  if((ret = SifCallRpc(&g_cdata, mcRpcCmd[g_mcType][MC_RPCCMD_INIT], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 4, NULL, NULL))>=0)
279  {
280  ret = g_rdata.result;
281  }
282  else{
283  // init error
284 #ifdef MC_DEBUG
285  printf("libmc: initialisation error\n");
286 #endif
287  g_mclibInited = 0;
288  return g_rdata.result - 100;
289  }
290  }
291  else if(g_mcType == MC_TYPE_XMC)
292  {
293 #ifdef MC_DEBUG
294  printf("libmc: using XMCMAN & XMCSERV\n");
295 #endif
296 
297  // call init function
298  if((ret = SifCallRpc(&g_cdata, mcRpcCmd[g_mcType][MC_RPCCMD_INIT], 0, &g_descParam, sizeof(g_descParam), &g_rdata, 12, NULL, NULL)) < 0)
299  {
300  // init error
301 #ifdef MC_DEBUG
302  printf("libmc: initialisation error\n");
303 #endif
304  g_mclibInited = 0;
305  return ret - 100;
306  }
307 
308  // check if old version of mcserv loaded
309  if(rpcStat->mcserv_version < 0x205)
310  {
311 #ifdef MC_DEBUG
312  printf("libmc: mcserv is too old (%x)\n", rpcStat->mcserv_version);
313 #endif
314  g_mclibInited = 0;
315  return -120;
316  }
317 
318  // check if old version of mcman loaded
319  if(rpcStat->mcman_version < 0x206)
320  {
321 #ifdef MC_DEBUG
322  printf("libmc: mcman is too old (%x)\n", rpcStat->mcman_version);
323 #endif
324  g_mclibInited = 0;
325  return -121;
326  }
327  ret = rpcStat->result;
328  }
329 
330  // successfully inited
331  g_mclibInited = 1;
332  g_currentCmd = 0;
333  return ret;
334 }
static void nopdelay(void)
Definition: kernel.h:141
#define UNCACHED_SEG(x)
Definition: kernel.h:35
int mcReset(void)
Definition: libmc.c:905
@ MC_RPCCMD_INIT
Definition: libmc.c:31
int _iop_reboot_count
mcRpcStat_t rpcStat
Definition: libmc.c:137
void SifInitRpc(int mode)
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142
u32 mcserv_version
Definition: libmc-common.h:133

References _iop_reboot_count, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_RPCCMD_INIT, MC_TYPE_MC, MC_TYPE_XMC, mcRpcStat_t::mcman_version, mcReset(), mcRpcCmd, mcRpcStat_t::mcserv_version, nopdelay(), NULL, mcDescParam_t::offset, mcRpcStat_t::result, rpcStat, SifRpcClientData_t::server, SifBindRpc(), SifCallRpc(), SifInitRpc(), and UNCACHED_SEG.

Referenced by main().

◆ mcMkDir()

int mcMkDir ( int  port,
int  slot,
const char *  name 
)

create a dir mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
namedirectory name
Returns
0 = successful; < 0 = error

Definition at line 532 of file libmc.c.

533 {
534  int ret = mcOpen(port, slot, name, 0x40);
535 
536  if(ret != 0)
538  return ret;
539 }
int mcOpen(int port, int slot, const char *name, int mode)
Definition: libmc.c:378

References g_currentCmd, MC_FUNC_MK_DIR, mcOpen(), port, and slot.

◆ mcOpen()

int mcOpen ( int  port,
int  slot,
const char *  name,
int  mode 
)

open a file on memcard mcSync returns: 0 or more = file descriptor (success) < 0 = error

Parameters
portport number
slotslot number
namefilename to open
modeopen file mode (O_RDWR, O_CREAT, etc)
Returns
0 = successful; < 0 = error

Definition at line 378 of file libmc.c.

379 {
380  int ret;
381 
382  // check mc lib is inited
383  if(!g_mclibInited)
384  return -1;
385  // check nothing else is processing
387  return g_currentCmd;
388 
389  // set global variables
393  strncpy(g_nameParam.name, name, 1023);
394  g_nameParam.name[1023] = 0;
395 
396  // send sif command
398  return ret;
400  return ret;
401 }
@ MC_RPCCMD_OPEN
Definition: libmc.c:33

References mcNameParam_t::flags, g_cdata, g_currentCmd, g_mclibInited, g_mcType, g_nameParam, g_rdata, MC_FUNC_NONE, MC_FUNC_OPEN, MC_RPCCMD_OPEN, mcRpcCmd, mode, mcNameParam_t::name, NULL, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcNameParam_t::slot, and slot.

Referenced by mcMkDir().

◆ mcRead()

int mcRead ( int  fd,
void *  buffer,
int  size 
)

read from file on memcard mcSync returns: 0 or more = number of bytes read from memcard < 0 = error

Parameters
fdfile descriptor
bufferbuffer to read to
sizenumber of bytes to read
Returns
0 = successful; < 0 = error

Definition at line 447 of file libmc.c.

448 {
449  int ret;
450 
451  // check mc lib is inited
452  if(!g_mclibInited)
453  return -1;
454  // check nothing else is processing
456  return g_currentCmd;
457 
458  // set global variables
459  g_descParam.fd = fd;
460  g_descParam.size = size;
463  SifWriteBackDCache(buffer, size);
465 
466  // send sif command
468  return ret;
470  return ret;
471 }
@ MC_RPCCMD_READ
Definition: libmc.c:36
u8 buffer[RSIZE]
Definition: libmc.c:138
static void mcReadFixAlign(void *data_raw)
Definition: libmc.c:195

References mcDescParam_t::buffer, buffer, endParameter, mcDescParam_t::fd, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_NONE, MC_FUNC_READ, MC_RPCCMD_READ, mcReadFixAlign(), mcRpcCmd, mcDescParam_t::param, SIF_RPC_M_NOWAIT, SifCallRpc(), SifWriteBackDCache(), and mcDescParam_t::size.

◆ mcReadPage()

int mcReadPage ( int  port,
int  slot,
unsigned int  page,
void *  buffer 
)

Reads a page from the memory card. Note: rom0:XMCSERV does not support this. mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
pagePage number of the page to be read.
bufferPointer to buffer that will contain the read data.
Returns
0 = success; -1 = error

Definition at line 789 of file libmc.c.

789  {
790  int result;
791 
792  // check lib is inited
794  return -1;
795  // check nothing else is processing
797  return g_currentCmd;
798 
799  g_descParam.fd=page;
804 
805  SifWriteBackDCache(buffer, 0x200);
806 
809  }
810 
811  return result;
812 }
@ MC_RPCCMD_READ_PAGE
Definition: libmc.c:49
static struct libmc_PageReadAlignData libmc_ReadPageAlignData
Definition: libmc.c:778
static void libmc_ReadAlignFunction(struct libmc_PageReadAlignData *data)
Definition: libmc.c:780

References mcDescParam_t::buffer, buffer, mcDescParam_t::fd, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, libmc_ReadAlignFunction(), libmc_ReadPageAlignData, MC_FUNC_NONE, MC_FUNC_READ_PAGE, MC_RPCCMD_READ_PAGE, MC_TYPE_XMC, mcRpcCmd, mcDescParam_t::param, mcDescParam_t::port, port, result, SIF_RPC_M_NOWAIT, SifCallRpc(), SifWriteBackDCache(), mcDescParam_t::slot, slot, and UNCACHED_SEG.

◆ mcRename()

int mcRename ( int  port,
int  slot,
const char *  oldName,
const char *  newName 
)

rename file or dir on memcard Note: rom0:MCSERV does not support this. mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
oldNamename of file/dir to rename
newNamenew name to give to file/dir
Returns
1 = success; < 0 = error

Definition at line 717 of file libmc.c.

718 {
719  int ret;
720 
721  // check lib is inited
722  if((!g_mclibInited)||(g_mcType==MC_TYPE_MC)) //I don't think that the old MCSERV module supports this because the v1.00 and v1.01 OSDSYS doesn't seem to have the sceMcRename function at all and the sceMcRename function was only introduced with SCE PS2SDK v1.50. I see that it doesn't work with rom0:MCSERV either way...
723  return -1;
724  // check nothing else is processing
726  return g_currentCmd;
727 
728  // set global variables
731  g_nameParam.flags = 0x10;
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;
737  FlushCache(0);
738 
739  // call sif function
741  return ret;
743  return ret;
744 }
void FlushCache(s32 operation)
static sceMcTblGetDir g_fileInfoBuff
Definition: libmc.c:147
@ MC_RPCCMD_SET_INFO
Definition: libmc.c:41
unsigned char EntryName[32]
Definition: libmc.h:145

References sceMcTblGetDir::EntryName, mcNameParam_t::flags, FlushCache(), g_cdata, g_currentCmd, g_fileInfoBuff, g_mclibInited, g_mcType, g_nameParam, g_rdata, MC_FUNC_NONE, MC_FUNC_RENAME, MC_RPCCMD_SET_INFO, MC_TYPE_MC, mcRpcCmd, mcNameParam_t::mcT, mcNameParam_t::name, NULL, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcNameParam_t::slot, and slot.

◆ mcReset()

int mcReset ( void  )

Reset (force deinit) of library

Returns
0 = success

Definition at line 905 of file libmc.c.

906 {
907  g_mclibInited = 0;
908  g_cdata.server = NULL;
909  return 0;
910 }

References g_cdata, g_mclibInited, NULL, and SifRpcClientData_t::server.

Referenced by mcInit().

◆ mcSeek()

int mcSeek ( int  fd,
int  offset,
int  origin 
)

move memcard file pointer mcSync returns: 0 or more = offset of file pointer from start of file < 0 = error

Parameters
fdfile descriptor
offsetnumber of bytes from origin
origininitial position for offset
Returns
0 = successful; < 0 = error

Definition at line 424 of file libmc.c.

425 {
426  int ret;
427 
428  // check mc lib is inited
429  if(!g_mclibInited)
430  return -1;
431  // check nothing else is processing
433  return g_currentCmd;
434 
435  // set global variables
436  g_descParam.fd = fd;
437  g_descParam.offset = offset;
438  g_descParam.origin = origin;
439 
440  // send sif command
442  return ret;
444  return ret;
445 }
@ MC_RPCCMD_SEEK
Definition: libmc.c:35

References mcDescParam_t::fd, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_NONE, MC_FUNC_SEEK, MC_RPCCMD_SEEK, mcRpcCmd, NULL, mcDescParam_t::offset, mcDescParam_t::origin, SIF_RPC_M_NOWAIT, and SifCallRpc().

◆ mcSetFileInfo()

int mcSetFileInfo ( int  port,
int  slot,
const char *  name,
const sceMcTblGetDir info,
unsigned  flags 
)

change file information mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
namefilename to access
infodata to be changed
flagsflags to show which data is valid
Returns
0 = successful; < 0 = error

Definition at line 595 of file libmc.c.

596 {
597  int ret;
598 
599  // check mc lib is inited
600  if(!g_mclibInited)
601  return -1;
602  // check nothing else is processing
604  return g_currentCmd;
605 
606  // set global variables
609  g_nameParam.flags = flags; // NOTE: this was ANDed with 7 so that u cant turn off copy protect! :)
611  memcpy(&g_fileInfoBuff, info, sizeof(sceMcTblGetDir));
612 
613  strncpy(g_nameParam.name, name, 1023);
614  g_nameParam.name[1023] = 0;
615  FlushCache(0);
616 
617  // send sif command
619  return ret;
621  return ret;
622 }
jpgData * info
Definition: camera-test.c:14

References mcNameParam_t::flags, FlushCache(), g_cdata, g_currentCmd, g_fileInfoBuff, g_mclibInited, g_mcType, g_nameParam, g_rdata, info, MC_FUNC_NONE, MC_FUNC_SET_INFO, MC_RPCCMD_SET_INFO, mcRpcCmd, mcNameParam_t::mcT, mcNameParam_t::name, NULL, mcNameParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcNameParam_t::slot, and slot.

◆ mcSync()

int mcSync ( int  mode,
int *  cmd,
int *  result 
)

wait for mc functions to finish or check if they have finished yet

Parameters
modemode 0=wait till function finishes, 1=check function status
cmdpointer for storing the number of the currenlty processing function
resultpointer for storing result of function if it finishes
Returns
0 = function is still executing (mode=1); 1 = function has finished executing; -1 = no function registered

Definition at line 864 of file libmc.c.

865 {
866  int funcIsExecuting, i;
867 
868  // check if any functions are registered
870  return -1;
871 
872  // check if function is still processing
873  funcIsExecuting = SifCheckStatRpc(&g_cdata);
874 
875  // if mode = 0, wait for function to finish
876  if(mode == 0)
877  {
878  while(SifCheckStatRpc(&g_cdata))
879  {
880  for(i=0; i<100000; i++)
881  ;
882  }
883  // function has finished
884  funcIsExecuting = 0;
885  }
886 
887  // get the function that just finished
888  if(cmd)
889  *cmd = g_currentCmd;
890 
891  // if function is still processing, return 0
892  if(funcIsExecuting == 1)
893  return 0;
894 
895  // function has finished, so clear last command
896  g_currentCmd = 0;
897 
898  // get result
899  if(result)
900  *result = g_rdata.result;
901 
902  return 1;
903 }
int SifCheckStatRpc(SifRpcClientData_t *cd)

References g_cdata, g_currentCmd, g_rdata, MC_FUNC_NONE, mode, result, and SifCheckStatRpc().

Referenced by main().

◆ mcUnformat()

int mcUnformat ( int  port,
int  slot 
)

unformat memory card mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
Returns
0 = success; -1 = error

Definition at line 671 of file libmc.c.

672 {
673  int ret;
674 
675  // check lib is inited
676  if(!g_mclibInited)
677  return -1;
678  // check nothing else is processing
680  return g_currentCmd;
681 
682  // set global variables
685 
686  // call unformat function
688  return ret;
690  return ret;
691 }
@ MC_RPCCMD_UNFORMAT
Definition: libmc.c:44

References g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_NONE, MC_FUNC_UNFORMAT, MC_RPCCMD_UNFORMAT, mcRpcCmd, NULL, mcDescParam_t::port, port, SIF_RPC_M_NOWAIT, SifCallRpc(), mcDescParam_t::slot, and slot.

◆ mcWrite()

int mcWrite ( int  fd,
const void *  buffer,
int  size 
)

write to file on memcard mcSync returns: 0 or more = number of bytes written to memcard < 0 = error

Parameters
fdfile descriptor
bufferto write from write
sizenumber of bytes to read
Returns
0 = successful; < 0 = error

Definition at line 473 of file libmc.c.

474 {
475  int i, ret;
476 
477  // check mc lib is inited
478  if(!g_mclibInited)
479  return -1;
480  // check nothing else is processing
482  return g_currentCmd;
483 
484  // set global variables
485  g_descParam.fd = fd;
486  if(size < 17)
487  {
488  g_descParam.size = 0;
489  g_descParam.origin = size;
490  g_descParam.buffer = 0;
491  }
492  else
493  {
494  g_descParam.size = size - ( ((int)(buffer-1) & 0xFFFFFFF0) - (int)(buffer-16) );
495  g_descParam.origin = ( ((int)(buffer-1) & 0xFFFFFFF0) - (int)(buffer-16) );
496  g_descParam.buffer = (void*)((int)buffer + ( ((int)(buffer-1) & 0xFFFFFFF0) - (int)(buffer-16) ));
497  }
498  for(i=0; i<g_descParam.origin; i++)
499  {
500  g_descParam.data[i] = *(char*)(buffer+i);
501  }
502  FlushCache(0);
503 
504  // send sif command
506  return ret;
508  return ret;
509 }
@ MC_RPCCMD_WRITE
Definition: libmc.c:37

References mcDescParam_t::buffer, buffer, mcDescParam_t::data, mcDescParam_t::fd, FlushCache(), g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_NONE, MC_FUNC_WRITE, MC_RPCCMD_WRITE, mcRpcCmd, NULL, mcDescParam_t::origin, SIF_RPC_M_NOWAIT, SifCallRpc(), and mcDescParam_t::size.

◆ mcWritePage()

int mcWritePage ( int  port,
int  slot,
int  page,
const void *  buffer 
)

Writes a page to the memory card. (The block which the page resides on must be erased first!) Note: rom0:XMCSERV does not support this. mcSync returns: 0 if ok < 0 if error

Parameters
portport number
slotslot number
pagePage number of the page to be written.
bufferPointer to buffer containing data to be written.
Returns
0 = success; -1 = error

Definition at line 814 of file libmc.c.

814  {
815  int result, misaligned;
816 
817  // check lib is inited
819  return -1;
820  // check nothing else is processing
822  return g_currentCmd;
823 
824  g_descParam.fd=page;
827  g_descParam.buffer=(void*)buffer;
828 
829  SifWriteBackDCache((void*)buffer, 512);
830 
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*)(buffer+(16-misaligned)+0x1F0), misaligned);
834  }
835 
838  }
839 
840  return result;
841 }
@ MC_RPCCMD_WRITE_PAGE
Definition: libmc.c:50

References mcDescParam_t::buffer, buffer, mcDescParam_t::data, mcDescParam_t::fd, g_cdata, g_currentCmd, g_descParam, g_mclibInited, g_mcType, g_rdata, MC_FUNC_NONE, MC_FUNC_WRITE_PAGE, MC_RPCCMD_WRITE_PAGE, MC_TYPE_XMC, mcRpcCmd, NULL, mcDescParam_t::port, port, result, SIF_RPC_M_NOWAIT, SifCallRpc(), SifWriteBackDCache(), mcDescParam_t::slot, and slot.