PS2SDK
PS2 Homebrew Libraries
libmc.c File Reference
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <string.h>
#include "libmc.h"
+ Include dependency graph for libmc.c:

Go to the source code of this file.

Data Structures

struct  mcNameParam_t
 
struct  libmc_PageReadAlignData
 
union  mcNameParam_t.__unnamed__
 

Macros

#define RSIZE   2048
 

Enumerations

enum  MC_RPCCMD_NUMBERS {
  MC_RPCCMD_INIT = 0x00, MC_RPCCMD_GET_INFO, MC_RPCCMD_OPEN, MC_RPCCMD_CLOSE,
  MC_RPCCMD_SEEK, MC_RPCCMD_READ, MC_RPCCMD_WRITE, MC_RPCCMD_FLUSH,
  MC_RPCCMD_CH_DIR, MC_RPCCMD_GET_DIR, MC_RPCCMD_SET_INFO, MC_RPCCMD_DELETE,
  MC_RPCCMD_FORMAT, MC_RPCCMD_UNFORMAT, MC_RPCCMD_GET_ENT, MC_RPCCMD_CHG_PRITY,
  MC_RPCCMD_CHECK_BLOCK, MC_RPCCMD_ERASE_BLOCK = 0x0E, MC_RPCCMD_READ_PAGE, MC_RPCCMD_WRITE_PAGE
}
 

Functions

static mcNameParam_t g_nameParam __attribute__ ((aligned(64)))
 
static void mcGetInfoApdx (void *info)
 
static void mcReadFixAlign (void *data_raw)
 
static void mcStoreDir (void *arg)
 
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)
 
static void libmc_ReadAlignFunction (struct libmc_PageReadAlignData *data)
 
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)
 

Variables

static const int mcRpcCmd [2][17]
 
int _iop_reboot_count
 
s32 result
 
mcRpcStat_t rpcStat
 
u8 buffer [RSIZE]
 
static int * g_pType = NULL
 
static int * g_pFree = NULL
 
static int * g_pFormat = NULL
 
static int g_mclibInited = 0
 
static unsigned int g_currentCmd = 0
 
static int g_mcType = MC_TYPE_MC
 
struct libmc_PageReadAlignData __attribute__
 

Detailed Description

Function defenitions for mclib.

Definition in file libmc.c.


Data Structure Documentation

◆ libmc_PageReadAlignData

struct libmc_PageReadAlignData

Definition at line 800 of file libmc.c.

Data Fields
unsigned int size1
unsigned int size2
void * dest1
void * dest2
unsigned char data1[16]
unsigned char data2[16]
unsigned char padding[16]

◆ mcNameParam_t.__unnamed__

union mcNameParam_t.__unnamed__

Definition at line 108 of file libmc.c.

Data Fields
sceMcTblGetDir * mcT
char * curdir

Macro Definition Documentation

◆ RSIZE

#define RSIZE   2048

rpc receive data buffer

Definition at line 134 of file libmc.c.

Enumeration Type Documentation

◆ MC_RPCCMD_NUMBERS

rpc command function numbers

Definition at line 30 of file libmc.c.

Function Documentation

◆ __attribute__()

static mcNameParam_t g_nameParam __attribute__ ( (aligned(64))  )
static

file descriptor related mc command used by: mcInit, mcClose, mcSeek, mcRead, mcWrite, mcGetinfo, mcFormat, mcFlush, mcUnformat, mcChangeThreadPriority

rpc client data

◆ mcGetInfoApdx()

static void mcGetInfoApdx ( void *  info)
static

function that gets called when mcGetInfo ends and interrupts are disabled

Definition at line 163 of file libmc.c.

◆ mcReadFixAlign()

static void mcReadFixAlign ( void *  data_raw)
static

function that gets called when mcRead ends and interrupts are disabled

Definition at line 195 of file libmc.c.

◆ mcStoreDir()

static void mcStoreDir ( void *  arg)
static

function that gets called when mcChDir ends and interrupts are disabled

Definition at line 219 of file libmc.c.

◆ mcInit()

int mcInit ( int  type)

init memcard lib

Parameters
typeRetained for backwards compatibility. Nominally specify MC_TYPE_MC.
Returns
0 = successful; < 0 = error

Definition at line 230 of file libmc.c.

◆ 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 368 of file libmc.c.

◆ 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 410 of file libmc.c.

◆ 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 435 of file libmc.c.

◆ 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 456 of file libmc.c.

◆ 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 479 of file libmc.c.

◆ 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 505 of file libmc.c.

◆ 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 543 of file libmc.c.

◆ 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 564 of file libmc.c.

◆ 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 573 of file libmc.c.

References g_currentCmd, and g_mclibInited.

◆ 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 599 of file libmc.c.

◆ 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 627 of file libmc.c.

◆ 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 656 of file libmc.c.

◆ 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 681 of file libmc.c.

References g_currentCmd, and g_mclibInited.

◆ 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 703 of file libmc.c.

References g_currentCmd, and g_mclibInited.

◆ 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 725 of file libmc.c.

◆ 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 749 of file libmc.c.

References g_mclibInited, and g_mcType.

◆ 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 778 of file libmc.c.

◆ 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 821 of file libmc.c.

◆ 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 846 of file libmc.c.

◆ 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 875 of file libmc.c.

References g_mclibInited, and g_mcType.

◆ 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 898 of file libmc.c.

◆ mcReset()

int mcReset ( void  )

Reset (force deinit) of library

Returns
0 = success

Definition at line 940 of file libmc.c.

References g_mclibInited.

Variable Documentation

◆ mcRpcCmd

const int mcRpcCmd[2][17]
static

rpc command function numbers mcRpcCmd[MC_TYPE_??][MC_RPCCMD_???]

Definition at line 56 of file libmc.c.

◆ _iop_reboot_count

int _iop_reboot_count

external IOP reboot count

Referenced by poweroffInit().

◆ g_mclibInited

int g_mclibInited = 0
static

whether or not mc lib has been inited

Definition at line 151 of file libmc.c.

Referenced by mcChangeThreadPriority(), mcChdir(), mcFormat(), mcRename(), mcReset(), and mcUnformat().

◆ g_currentCmd

unsigned int g_currentCmd = 0
static

stores command currently being executed on the iop

Definition at line 154 of file libmc.c.

Referenced by mcChdir(), mcFormat(), and mcUnformat().

◆ g_mcType

int g_mcType = MC_TYPE_MC
static

specifies whether using MCSERV or XMCSERV modules

Definition at line 157 of file libmc.c.

Referenced by mcChangeThreadPriority(), and mcRename().