2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
10 # $Id: pfs.c 1491 2009-01-04 23:46:22Z oopo $
11 # PFS startup and misc code
16 IRX_ID("pfs_driver", 1, 1);
18 ///////////////////////////////////////////////////////////////////////////////
21 iop_device_ops_t pfsOps
= {
46 pfsUnsupported
/*pfsSymlink*/,
47 pfsUnsupported
/*pfsReadlink*/,
51 iop_device_t pfsFioDev
= {
53 (IOP_DT_FS
| IOP_DT_FSEXT
),
59 pfs_config_t pfsConfig
= { 1, 2 };
60 pfs_mount_t
*pfsMountBuf
;
61 char *pfsFilename
= NULL
;
62 u32 metaSize
= 1024; // size of each metadata structure
65 ///////////////////////////////////////////////////////////////////////////////
66 // Local function declerations
69 int printPfsArgError();
70 int allocateMountBuffer(int size
);
71 int allocateBuffers(u32 numBuf
, u32 bufSize
);
73 ///////////////////////////////////////////////////////////////////////////////
74 // Function defenitions
78 printf("ps2fs: Playstation Filesystem Driver v%d.%d\nps2fs: (c) 2003 Sjeep, Vector and Florin Sasu\n", PFS_MAJOR
, PFS_MINOR
);
81 int printPfsArgError()
83 printf("ps2fs: ERROR: Usage: %s [-m <maxmount>] [-o <maxopen>] [-n <numbuffer>]\n", pfsFilename
);
85 return MODULE_NO_RESIDENT_END
;
88 int allocateMountBuffer(int size
)
90 int tsize
= size
* sizeof(pfs_mount_t
);
92 pfsMountBuf
= allocMem(tsize
);
96 memset(pfsMountBuf
, 0, tsize
);
102 void clearMount(pfs_mount_t
*pfsMount
)
104 memset(pfsMount
, 0, sizeof(pfs_mount_t
));
107 pfs_mount_t
* getMountedUnit(u32 unit
)
108 { // get mounted unit
109 if(unit
>=pfsConfig
.maxMount
)
112 if(!(pfsMountBuf
[unit
].flags
& MOUNT_BUSY
))
115 return &pfsMountBuf
[unit
];
118 int _start(int argc
, char *argv
[])
128 // Get filename of IRX
129 filename
= strrchr(argv
[0], '/');
131 pfsFilename
= filename
;
133 pfsFilename
= argv
[0];
141 if(argv
[0][0] != '-')
144 if(!strcmp(argv
[0], "-m"))
147 return printPfsArgError();
150 number
= strtol(argv
[0], 0, 10);
153 pfsConfig
.maxMount
= number
;
155 else if(!strcmp(argv
[0], "-o"))
158 return printPfsArgError();
161 number
= strtol(argv
[0], 0, 10);
164 pfsConfig
.maxOpen
= number
;
166 else if(!strcmp(argv
[0], "-n"))
169 return printPfsArgError();
172 number
= strtol(argv
[0], 0, 10);
178 printf("ps2fs: ERROR: Number of buffers is larger than 127!\n");
182 else if(!strcmp(argv
[0], "-debug"))
185 return printPfsArgError();
191 printf("ps2fs: Max mount: %ld, Max open: %ld, Number of buffers: %d\n", pfsConfig
.maxMount
,
192 pfsConfig
.maxOpen
, numBuf
);
194 // Do we have enough buffers ?
195 reqBuf
= (pfsConfig
.maxOpen
* 2) + 8;
197 printf("ps2fs: Warning: %d buffers may be needed, but only %d buffers are allocated\n", reqBuf
, numBuf
);
199 if(allocateMountBuffer(pfsConfig
.maxMount
) < 0)
200 return MODULE_NO_RESIDENT_END
;
202 // Allocate and zero memory for file slots
203 size
= pfsConfig
.maxOpen
* sizeof(pfs_file_slot_t
);
204 fileSlots
= allocMem(size
);
206 printf("ps2fs: Error: Failed to allocate memory!\n");
207 return MODULE_NO_RESIDENT_END
;
210 memset(fileSlots
, 0, size
);
212 if(cacheInit(numBuf
, metaSize
) < 0)
213 return MODULE_NO_RESIDENT_END
;
218 printf("ps2fs: Driver start.\n");
220 return MODULE_RESIDENT_END
;