11#ifndef __MCMAN_INTERNAL_H__
12#define __MCMAN_INTERNAL_H__
14#ifndef MCMAN_ENABLE_EXTENDED_DEV_OPS
15#if defined(BUILDING_VMCMAN)
16#define MCMAN_ENABLE_EXTENDED_DEV_OPS 1
18#define MCMAN_ENABLE_EXTENDED_DEV_OPS 0
27#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
32#if MCMAN_ENABLE_EXTENDED_DEV_OPS
44#ifndef BUILDING_VMCMAN
45#ifdef BUILDING_XFROMMAN
60#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
61#define MODNAME "mcman_cex"
62#elif defined(BUILDING_VMCMAN)
63#define MODNAME "vmcman"
64#elif defined(BUILDING_XFROMMAN)
65#define MODNAME "xfromman"
69#ifndef MCMAN_ENTRYPOINT
71#define MCMAN_ENTRYPOINT _start
73#define MCMAN_ENTRYPOINT mcman_start
80 #define DPRINTF(format, args...) \
81 sio_printf(MODNAME ": " format, ##args)
84 #define DPRINTF(format, args...) \
85 printf(MODNAME ": " format, ##args)
87 #define DPRINTF(format, args...)
99#define CF_USE_ECC 0x01
100#define CF_BAD_BLOCK 0x08
101#define CF_ERASE_ZEROES 0x10
103#ifdef BUILDING_VMCMAN
104#define MCMAN_MAXSLOT 10
106#define MCMAN_MAXSLOT 4
108#define MCMAN_CLUSTERSIZE 1024
109#define MCMAN_CLUSTERFATENTRIES 256
112 int entry[MCMAN_CLUSTERFATENTRIES];
115#define MAX_CACHEENTRY 0x24
118 int entry[1 + (MCMAN_CLUSTERFATENTRIES * 2)];
121#define MAX_CACHEDIRENTRY 0x3
144#define MAX_FDHANDLES 3
146#if MCMAN_ENABLE_EXTENDED_DEV_OPS
147#define MC_IO_DEV_T iomanX_iop_device_t
148#define MC_IO_FIL_T iomanX_iop_file_t
149#define MC_IO_DRE_T iox_dirent_t
150#define MC_IO_STA_T iox_stat_t
151#define MC_IO_OPS_T iomanX_iop_device_ops_t
154#define MC_IO_S_RD (FIO_S_IRUSR | FIO_S_IRGRP | FIO_S_IROTH)
155#define MC_IO_S_WR (FIO_S_IWUSR | FIO_S_IWGRP | FIO_S_IWOTH)
156#define MC_IO_S_EX (FIO_S_IXUSR | FIO_S_IXGRP | FIO_S_IXOTH)
157#define MC_IO_S_FL FIO_S_IFREG
158#define MC_IO_S_DR FIO_S_IFDIR
160#define MC_IO_CST_ATTR FIO_CST_ATTR
161#define MC_IO_CST_MODE FIO_CST_MODE
162#define MC_IO_CST_CT FIO_CST_CT
163#define MC_IO_CST_MT FIO_CST_MT
165#define MC_IO_DEV_T iop_device_t
166#define MC_IO_FIL_T iop_file_t
167#define MC_IO_DRE_T io_dirent_t
168#define MC_IO_STA_T io_stat_t
169#define MC_IO_OPS_T iop_device_ops_t
171#define MC_IO_S_RD SCE_STM_R
172#define MC_IO_S_WR SCE_STM_W
173#define MC_IO_S_EX SCE_STM_X
174#define MC_IO_S_FL SCE_STM_F
175#define MC_IO_S_DR SCE_STM_D
177#define MC_IO_CST_ATTR SCE_CST_ATTR
178#define MC_IO_CST_MODE SCE_CST_MODE
179#define MC_IO_CST_CT SCE_CST_CT
180#define MC_IO_CST_MT SCE_CST_MT
184#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
187void long_multiply(u32 v1, u32 v2, u32 *HI, u32 *LO);
188int mcman_chrpos(
const char *str,
int chr);
189void mcman_wmemset(
void *buf,
int size,
int value);
190int mcman_calcEDC(
void *buf,
int size);
191int mcman_checkpath(
const char *str);
192int mcman_checkdirpath(
const char *str1,
const char *str2);
193void mcman_invhandles(
int port,
int slot);
195int mcman_detectcard(
int port,
int slot);
196int mcman_dread(
int fd, MC_IO_DRE_T *dirent);
197int mcman_getstat(
int port,
int slot,
const char *filename, MC_IO_STA_T *stat);
199void mcman_initPS2com(
void);
200void mcman_deinitPS2com(
void);
201#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
202void sio2packet_add(
int port,
int slot,
int cmd, u8 *buf);
204int mcman_eraseblock(
int port,
int slot,
int block,
void **pagebuf,
void *eccbuf);
205int mcman_readpage(
int port,
int slot,
int page,
void *buf,
void *eccbuf);
206int mcman_cardchanged(
int port,
int slot);
207int mcman_resetauth(
int port,
int slot);
208int mcman_probePS2Card2(
int port,
int slot);
209int mcman_probePS2Card(
int port,
int slot);
210#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
213int mcman_getcnum (
int port,
int slot);
214int mcman_correctdata(
void *buf,
void *ecc);
215int mcman_sparesize(
int port,
int slot);
216int mcman_setdevspec(
int port,
int slot);
217int mcman_reportBadBlocks(
int port,
int slot);
218int mcman_setdevinfos(
int port,
int slot);
219int mcman_format2(
int port,
int slot);
220int mcman_fatRseek(
int fd);
221int mcman_fatWseek(
int fd);
222int mcman_findfree2(
int port,
int slot,
int reserve);
223int mcman_dread2(
int fd, MC_IO_DRE_T *dirent);
224int mcman_getstat2(
int port,
int slot,
const char *filename, MC_IO_STA_T *stat);
225int mcman_setinfo2(
int port,
int slot,
const char *filename,
sceMcTblGetDir *
info,
int flags);
226int mcman_read2(
int fd,
void *buffer,
int nbyte);
227int mcman_write2(
int fd,
void *buffer,
int nbyte);
228int mcman_close2(
int fd);
229int mcman_getentspace(
int port,
int slot,
const char *dirname);
230int mcman_cachedirentry(
int port,
int slot,
const char *filename,
McCacheDir *pcacheDir,
McFsEntry **pfse,
int unknown_flag);
231int mcman_getdirinfo(
int port,
int slot,
McFsEntry *pfse,
const char *filename,
McCacheDir *pcd,
int unknown_flag);
232int mcman_open2(
int port,
int slot,
const char *filename,
int flags);
233int mcman_chdir(
int port,
int slot,
const char *newdir,
char *currentdir);
234int mcman_writecluster(
int port,
int slot,
int cluster,
int flag);
235int mcman_getdir2(
int port,
int slot,
const char *dirname,
int flags,
int maxent,
sceMcTblGetDir *
info);
236int mcman_delete2(
int port,
int slot,
const char *filename,
int flags);
237int mcman_checkBackupBlocks(
int port,
int slot);
238int mcman_unformat2(
int port,
int slot);
239void mcman_initPS1PDAcom(
void);
240void mcman_deinitPS1PDAcom(
void);
241int mcman_probePS1Card2(
int port,
int slot);
242int mcman_probePS1Card(
int port,
int slot);
243int mcman_probePDACard(
int port,
int slot);
244int mcman_setPS1devinfos(
int port,
int slot);
245int mcman_format1(
int port,
int slot);
246int mcman_open1(
int port,
int slot,
const char *filename,
int flags);
247int mcman_read1(
int fd,
void *buffer,
int nbyte);
248int mcman_write1(
int fd,
void *buffer,
int nbyte);
249int mcman_getPS1direntry(
int port,
int slot,
const char *filename,
McFsEntryPS1 **pfse,
int flag);
250int mcman_dread1(
int fd, MC_IO_DRE_T *dirent);
251int mcman_getstat1(
int port,
int slot,
const char *filename, MC_IO_STA_T *stat);
252int mcman_setinfo1(
int port,
int slot,
const char *filename,
sceMcTblGetDir *
info,
int flags);
253int mcman_getdir1(
int port,
int slot,
const char *dirname,
int flags,
int maxent,
sceMcTblGetDir *
info);
254int mcman_clearPS1direntry(
int port,
int slot,
int cluster,
int flags);
255int mcman_delete1(
int port,
int slot,
const char *filename,
int flags);
256int mcman_close1(
int fd);
257int mcman_findfree1(
int port,
int slot,
int reserve);
258int mcman_fatRseekPS1(
int fd);
259int mcman_fatWseekPS1(
int fd);
260int mcman_FNC8ca4(
int port,
int slot,
MC_FHANDLE *fh);
261int mcman_PS1pagetest(
int port,
int slot,
int page);
262int mcman_unformat1(
int port,
int slot);
263int mcman_cachePS1dirs(
int port,
int slot);
264int mcman_fillPS1backuparea(
int port,
int slot,
int block);
265void mcman_initcache(
void);
266int mcman_clearcache(
int port,
int slot);
267McCacheEntry *mcman_getcacheentry(
int port,
int slot,
int cluster);
268void mcman_freecluster(
int port,
int slot,
int cluster);
269int mcman_getFATindex(
int port,
int slot,
int num);
273int mcman_readdirentryPS1(
int port,
int slot,
int cluster,
McFsEntryPS1 **pfse);
274int mcman_readclusterPS1(
int port,
int slot,
int cluster,
McCacheEntry **pmce);
275int mcman_replaceBackupBlock(
int port,
int slot,
int block);
276int mcman_fillbackupblock1(
int port,
int slot,
int block,
void **pagedata,
void *eccdata);
277int mcman_clearsuperblock(
int port,
int slot);
278int mcman_ioerrcode(
int errcode);
279int mcman_modloadcb(
const char *filename,
int *port,
int *slot);
280void mcman_unit2card(u32 unit);
281int mcman_initdev(
void);
282void mcman_deinitdev(
void);
284#if defined(BUILDING_VMCMAN)
285int mcman_iomanx_backing_mount(
int port,
int slot,
const char *filename);
286int mcman_iomanx_backing_umount(
int port,
int slot);
287int mcman_iomanx_backing_getcardspec(
int port,
int slot, s16 *pagesize, u16 *blocksize,
int *cardsize, u8 *flags);
288int mcman_iomanx_backing_erase(
int port,
int slot,
int page);
289int mcman_iomanx_backing_write(
int port,
int slot,
int page,
void *pagebuf,
void *eccbuf);
290int mcman_iomanx_backing_read(
int port,
int slot,
int page,
void *pagebuf,
void *eccbuf);
297 u16 pages_per_cluster;
300 u32 clusters_per_card;
308 int bad_block_list[32];
313 u32 FATentries_per_cluster;
314 u32 clusters_per_block;
316 u32 rootdir_cluster2;
319 u32 max_allocatable_clusters;
326 u32 word[1056/
sizeof(u32)];
327 u8
byte[1056/
sizeof(u8)];
328 char magic[1056/
sizeof(char)];
332 u32 word[128/
sizeof(u32)];
333 u16 half[128/
sizeof(u16)];
334 u8
byte[128/
sizeof(u8)];
339extern char SUPERBLOCK_MAGIC[];
340extern char SUPERBLOCK_VERSION[];
342extern int mcman_wr_port;
343extern int mcman_wr_slot;
344extern int mcman_wr_block;
345extern int mcman_wr_flag3;
346extern int mcman_curdircluster;
351#ifndef BUILDING_XFROMMAN
354extern int PS1CardFlag;
356extern McFsEntry mcman_dircache[MAX_CACHEDIRENTRY];
358extern MC_FHANDLE mcman_fdhandles[MAX_FDHANDLES];
359extern MCDevInfo mcman_devinfos[4][MCMAN_MAXSLOT];
361extern u8 mcman_eccdata[512];
364extern u8 mcman_sio2outbufs_PS1PDA[0x90];