11#define MAX_FILES_PER_FOLDER 256
12#define MAX_FILES_OPENED 4
13#define MAX_FOLDERS_OPENED 4
14#define MAX_BYTES_READ 16384
16#define DRIVER_UNIT_NAME "cdfs"
17#define DRIVER_MAJOR_VERSION 2
18#define DRIVER_MINOR_VERSION 2
20#define STRINGIFY(x) #x
21#define TOSTRING(x) STRINGIFY(x)
22#define DRIVER_DESC DRIVER_UNIT_NAME " Filedriver v" TOSTRING(DRIVER_MAJOR_VERSION) "." TOSTRING(DRIVER_MINOR_VERSION)
24IRX_ID(MODNAME, DRIVER_MAJOR_VERSION, DRIVER_MINOR_VERSION);
39 struct TocEntry entries[MAX_FILES_PER_FOLDER];
43static struct fdtable fd_table[MAX_FILES_OPENED];
44static int fd_used[MAX_FILES_OPENED];
47static struct fodtable fod_table[MAX_FOLDERS_OPENED];
48static int fod_used[MAX_FOLDERS_OPENED];
51static int lastsector = -1;
52static int last_bk = 0;
62 printf(
"%s\n", driver->desc);
63 printf(
"Re-edited by fjtrujy\n");
64 printf(
"Original implementation\n");
65 printf(
"by A.Lee (aka Hiryu) & Nicholas Van Veen (aka Sjeep)\n");
66 printf(
"CDFS: Initializing '%s' file driver.\n", driver->name);
76 DPRINTF(
"CDFS: fio_deinit called.\n");
77 DPRINTF(
" kernel_fd.. %p\n", f);
81static int fio_open(
iop_file_t *f,
const char *name,
int mode)
86 DPRINTF(
"CDFS: fio_open called.\n");
87 DPRINTF(
" kernel_fd.. %p\n", f);
88 DPRINTF(
" name....... %s %x\n", name, (
int)name);
89 DPRINTF(
" mode....... %d\n\n", mode);
92 if (cdfs_checkDiskChanged(CHANGED_FIO)) {
98 if (!cdfs_findfile(name, &tocEntry)) {
99 printf(
"***** FILE %s CAN NOT FOUND ******\n\n", name);
103 if (mode != O_RDONLY) {
104 printf(
"mode is different than O_RDONLY, expected %i, received %i\n\n", O_RDONLY, mode);
108 DPRINTF(
"CDFS: fio_open TocEntry info\n");
109 DPRINTF(
" TocEntry....... %p\n", &tocEntry);
110 DPRINTF(
" fileLBA........ %i\n", tocEntry.fileLBA);
111 DPRINTF(
" fileSize....... %i\n", tocEntry.fileSize);
112 DPRINTF(
" fileProperties. %i\n", tocEntry.fileProperties);
113 DPRINTF(
" dateStamp...... %s\n", tocEntry.dateStamp);
114 DPRINTF(
" filename....... %s\n", tocEntry.filename);
117 for (j = 0; j < MAX_FILES_OPENED; j++) {
122 if (j >= MAX_FILES_OPENED) {
123 printf(
"File descriptor overflow!!\n\n");
129 fd_table[j].fileSize = tocEntry.fileSize;
130 fd_table[j].LBA = tocEntry.fileLBA;
131 fd_table[j].filePos = 0;
142 DPRINTF(
"CDFS: fio_close called.\n");
143 DPRINTF(
" kernel fd.. %p\n\n", f);
147 if (i >= MAX_FILES_OPENED) {
148 printf(
"fio_close: ERROR: File does not appear to be open!\n");
157static int fio_read(
iop_file_t *f,
void *buffer,
int size)
166 static u8 local_buffer[9 * 2048];
168 DPRINTF(
"CDFS: fio_read called\n\n");
169 DPRINTF(
" kernel_fd... %p\n", f);
170 DPRINTF(
" buffer...... 0x%X\n", (
int)buffer);
171 DPRINTF(
" size........ %d\n\n", size);
175 if (i >= MAX_FILES_OPENED) {
176 printf(
"fio_read: ERROR: File does not appear to be open!\n");
181 if (fd_table[i].filePos > fd_table[i].fileSize) {
186 if ((fd_table[i].filePos + size) > fd_table[i].fileSize)
187 size = fd_table[i].fileSize - fd_table[i].filePos;
192 if (size > MAX_BYTES_READ)
193 size = MAX_BYTES_READ;
196 start_sector = fd_table[i].LBA + (fd_table[i].filePos >> 11);
197 off_sector = (fd_table[i].filePos & 0x7FF);
199 num_sectors = (off_sector + size);
200 num_sectors = (num_sectors >> 11) + ((num_sectors & 2047) != 0);
202 DPRINTF(
"fio_read: read sectors %d to %d\n", start_sector, start_sector + num_sectors);
205 if (start_sector == lastsector) {
208 memcpy(local_buffer, local_buffer + 2048 * (last_bk), 2048);
212 lastsector = start_sector + num_sectors - 1;
215 if (read == 0 || (read == 1 && num_sectors > 1)) {
216 if (!cdfs_readSect(start_sector + read, num_sectors - read, local_buffer + ((read) << 11))) {
217 DPRINTF(
"Couldn't Read from file for some reason\n");
220 last_bk = num_sectors - 1;
223 memcpy(buffer, local_buffer + off_sector, size);
224 fd_table[i].filePos += size;
229static int fio_write(
iop_file_t *f,
void *buffer,
int size)
237 printf(
"CDFS: dummy fio_write function called, this is not a re-writer xD");
242static int fio_lseek(
iop_file_t *f,
int offset,
int whence)
246 DPRINTF(
"CDFS: fio_lseek called.\n");
247 DPRINTF(
" kernel_fd... %p\n", f);
248 DPRINTF(
" offset...... %d\n", offset);
249 DPRINTF(
" whence...... %d\n\n", whence);
254 DPRINTF(
"fio_lseek: ERROR: File does not appear to be open!\n");
260 fd_table[i].filePos = offset;
264 fd_table[i].filePos += offset;
268 fd_table[i].filePos = fd_table[i].fileSize + offset;
275 if (fd_table[i].filePos < 0)
276 fd_table[i].filePos = 0;
278 if (fd_table[i].filePos > fd_table[i].fileSize)
279 fd_table[i].filePos = fd_table[i].fileSize;
281 return fd_table[i].filePos;
284static int fio_openDir(
iop_file_t *f,
const char *path) {
287 DPRINTF(
"CDFS: fio_openDir called.\n");
288 DPRINTF(
" kernel_fd.. %p\n", f);
289 DPRINTF(
" name....... %s\n", f->
device->name);
290 DPRINTF(
" mode....... %d\n\n", f->
mode);
291 DPRINTF(
" path....... %s\n\n", path);
294 for (j = 0; j < MAX_FOLDERS_OPENED; j++) {
295 if (fod_used[j] == 0)
299 if (j >= MAX_FOLDERS_OPENED)
302 fod_table[j].files = cdfs_getDir(path, fod_table[j].entries, MAX_FILES_PER_FOLDER);
303 if (fod_table[j].files < 0) {
304 printf(
"The path doesn't exist\n\n");
308 fod_table[j].filesIndex = 0;
312 DPRINTF(
"ITEMS %i\n\n", fod_table[j].files);
315 for (index=0; index < fod_table[j].files; index++) {
316 struct TocEntry tocEntry = fod_table[j].entries[index];
318 DPRINTF(
"CDFS: fio_openDir index=%d TocEntry info\n", index);
319 DPRINTF(
" TocEntry....... %p\n", &tocEntry);
320 DPRINTF(
" fileLBA........ %i\n", tocEntry.fileLBA);
321 DPRINTF(
" fileSize....... %i\n", tocEntry.fileSize);
322 DPRINTF(
" fileProperties. %i\n", tocEntry.fileProperties);
323 DPRINTF(
" dateStamp....... %s\n", tocEntry.dateStamp);
324 DPRINTF(
" filename....... %s\n", tocEntry.filename);
337 DPRINTF(
"CDFS: fio_closeDir called.\n");
338 DPRINTF(
" kernel_fd.. %p\n", fd);
340 i = (int)fd->privdata;
342 if (i >= MAX_FOLDERS_OPENED) {
343 printf(
"fio_close: ERROR: File does not appear to be open!\n");
357 DPRINTF(
"CDFS: fio_dread called.\n");
358 DPRINTF(
" kernel_fd.. %p\n", fd);
359 DPRINTF(
" mode....... %p\n\n", dirent);
361 i = (int)fd->privdata;
363 if (i >= MAX_FOLDERS_OPENED) {
364 printf(
"fio_dread: ERROR: Folder does not appear to be open!\n\n");
368 filesIndex = fod_table[i].filesIndex;
369 if (filesIndex >= fod_table[i].files) {
370 printf(
"fio_dread: No more items pending to read!\n\n");
374 entry = fod_table[i].entries[filesIndex];
376 DPRINTF(
"fio_dread: fod_table index=%i, fileIndex=%i\n\n", i, filesIndex);
377 DPRINTF(
"fio_dread: entries=%i\n\n", fod_table[i].files);
378 DPRINTF(
"fio_dread: reading entry\n\n");
379 DPRINTF(
" entry.. %p\n", &entry);
380 DPRINTF(
" filesize....... %i\n\n", entry.fileSize);
381 DPRINTF(
" filename....... %s\n\n", entry.filename);
382 DPRINTF(
" fileproperties.. %i\n\n", entry.fileProperties);
385 dirent->stat.attr = entry.fileProperties;
386 dirent->stat.size = entry.fileSize;
387 memcpy(dirent->stat.ctime, entry.dateStamp,
sizeof(entry.dateStamp));
388 memcpy(dirent->stat.atime, entry.dateStamp,
sizeof(entry.dateStamp));
389 memcpy(dirent->stat.mtime, entry.dateStamp,
sizeof(entry.dateStamp));
390 strncpy(dirent->name, entry.filename,
sizeof(dirent->name));
392 fod_table[i].filesIndex++;
393 return fod_table[i].filesIndex;
403 DPRINTF(
"CDFS: fio_getstat called.\n");
404 DPRINTF(
" kernel_fd.. %p\n", fd);
405 DPRINTF(
" name....... %s\n\n", name);
407 ret = cdfs_findfile(name, &entry);
409 DPRINTF(
" entry.. %p\n", &entry);
410 DPRINTF(
" filesize....... %i\n\n", entry.fileSize);
411 DPRINTF(
" filename....... %s\n\n", entry.filename);
412 DPRINTF(
" fileproperties.. %i\n\n", entry.fileProperties);
415 stat->attr = entry.fileProperties;
416 stat->size = entry.fileSize;
417 memcpy(stat->ctime, entry.dateStamp,
sizeof(entry.dateStamp));
418 memcpy(stat->atime, entry.dateStamp,
sizeof(entry.dateStamp));
419 memcpy(stat->mtime, entry.dateStamp,
sizeof(entry.dateStamp));
424IOMAN_RETURN_VALUE_IMPL(
EIO);
429 IOMAN_RETURN_VALUE(
EIO),
435 IOMAN_RETURN_VALUE(
EIO),
436 IOMAN_RETURN_VALUE(
EIO),
437 IOMAN_RETURN_VALUE(
EIO),
438 IOMAN_RETURN_VALUE(
EIO),
443 IOMAN_RETURN_VALUE(
EIO),
449 DRIVER_MAJOR_VERSION,
454int _start(
int argc,
char *argv[])
462 DelDrv(fio_driver.name);
463 if(AddDrv(&fio_driver) != 0) {
return MODULE_NO_RESIDENT_END; }
465 return MODULE_RESIDENT_END;
struct _iop_device * device