17#include "irx_imports.h"
32#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
33IRX_ID(
"IOX/File_Manager", 1, 1);
35IRX_ID(
"IO/File_Manager", 2, 3);
40#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
47#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
55#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
56void iomanX_StdioInit(
int mode);
57static int open_tty_handles(
const char *tty_name);
59static int xx_stat(
int op,
const char *name,
iox_stat_t *stat,
unsigned int statmask);
60static int xx_rename(
int op,
const char *oldname,
const char *newname);
61static int xx_dir(
int op,
const char *name,
int mode);
62static int _ioabort(
const char *str1,
const char *str2);
67#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
68static int tty_noop(
void);
69unsigned int iomanX_GetDevType(
int fd);
71static void ShowDrv(
void);
72#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
73static void register_tty(
void);
74static void register_dummytty(
void);
77#ifdef IOMANX_USE_DEVICE_LINKED_LIST
78struct ioman_dev_listentry
80 struct ioman_dev_listentry *next;
85static int showdrvflag = 1;
86#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
88IOMANX_RETURN_VALUE_IMPL(0);
91 IOMANX_RETURN_VALUE(0),
92 IOMANX_RETURN_VALUE(0),
93 IOMANX_RETURN_VALUE(0),
94 IOMANX_RETURN_VALUE(0),
95 IOMANX_RETURN_VALUE(0),
96 IOMANX_RETURN_VALUE(0),
97 IOMANX_RETURN_VALUE(0),
98 IOMANX_RETURN_VALUE(0),
99 IOMANX_RETURN_VALUE(0),
100 IOMANX_RETURN_VALUE(0),
101 IOMANX_RETURN_VALUE(0),
102 IOMANX_RETURN_VALUE(0),
103 IOMANX_RETURN_VALUE(0),
104 IOMANX_RETURN_VALUE(0),
105 IOMANX_RETURN_VALUE(0),
106 IOMANX_RETURN_VALUE(0),
107 IOMANX_RETURN_VALUE(0),
108 IOMANX_RETURN_VALUE(0),
109 IOMANX_RETURN_VALUE(0),
110 IOMANX_RETURN_VALUE(0),
111 IOMANX_RETURN_VALUE(0),
112 IOMANX_RETURN_VALUE(0),
113 IOMANX_RETURN_VALUE_S64(0),
114 IOMANX_RETURN_VALUE(0),
115 IOMANX_RETURN_VALUE(0),
116 IOMANX_RETURN_VALUE(0),
117 IOMANX_RETURN_VALUE(0),
124 &dev_tty_dev_operations,
131 &dev_tty_dev_operations,
134static int adddeldrv_in_process;
135#ifdef IOMANX_USE_ERRNO
136static int errno_local;
138#ifdef IOMANX_USE_DEVICE_LINKED_LIST
139static struct ioman_dev_listentry *device_entry_empty_list_head;
140static struct ioman_dev_listentry *device_entry_used_list_head;
142#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
146#ifdef IOMANX_USE_DEVICE_LINKED_LIST
147static struct ioman_dev_listentry device_entry_list[MAX_DEVICES];
153#define isnum(c) ((c) >= '0' && (c) <= '9')
158#define EUNSUP ENOTSUP
164#define HANDLE_RESULT_CLEAR_INFO 1
165#define HANDLE_RESULT_CLEAR_INFO_ON_ERROR 2
166#define HANDLE_RESULT_RETURN_ZERO 4
167#define HANDLE_RESULT_RETURN_FD 8
169static inline void write_str_to_stdout(
const char *in_str)
171 iomanX_write(1, (
void *)in_str, strlen(in_str));
174static inline int set_errno(
int in_errno)
176#ifdef IOMANX_USE_ERRNO
177 errno_local = in_errno;
184 if ( (op & HANDLE_RESULT_CLEAR_INFO) )
192 if ( (op & HANDLE_RESULT_CLEAR_INFO_ON_ERROR) )
194 if ( f && (in_result < 0) )
203 handle_result_pre(in_result, f, op);
205 return set_errno(-in_result);
206 if ( (op & HANDLE_RESULT_RETURN_ZERO) )
208 if ( (op & HANDLE_RESULT_RETURN_FD) )
209 return f - file_table;
215 handle_result_pre(in_result, f, op);
217 return set_errno(-(
int)in_result);
218 if ( (op & HANDLE_RESULT_RETURN_ZERO) )
220 if ( (op & HANDLE_RESULT_RETURN_FD) )
221 return f - file_table;
225#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
226extern int hook_ioman();
227extern int unhook_ioman();
230#ifndef IOMANX_ENTRYPOINT
232#define IOMANX_ENTRYPOINT _start
234#define IOMANX_ENTRYPOINT iomanX_start
238#ifndef IOMANX_CLEANUP
239#define IOMANX_CLEANUP shutdown
242int IOMANX_ENTRYPOINT(
int ac,
char **av)
244#ifdef IOMANX_USE_DEVICE_LINKED_LIST
252#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
253 if ( RegisterLibraryEntries(&_exp_iomanx) )
254 return MODULE_NO_RESIDENT_END;
256 if ( RegisterLibraryEntries(&_exp_ioman) )
257 return MODULE_NO_RESIDENT_END;
259 SetRebootTimeLibraryHandlingMode(&_exp_ioman, 2);
262 _exp_ioman.mode &= ~6;
263 _exp_ioman.mode |= 2;
267 adddeldrv_in_process = 0;
268#ifdef IOMANX_USE_DEVICE_LINKED_LIST
270 memset(device_entry_list, 0,
sizeof(device_entry_list));
271 device_entry_used_list_head = NULL;
272 device_entry_empty_list_head = device_entry_list;
274 for ( i = 0; i < ((
sizeof(device_entry_list) /
sizeof(device_entry_list[0])) - 1); i += 1 )
275 device_entry_list[i].next = &device_entry_list[i + 1];
277 memset(device_table, 0,
sizeof(device_table));
280 memset(file_table, 0,
sizeof(file_table));
281#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
283 return MODULE_NO_RESIDENT_END;
287 return MODULE_RESIDENT_END;
290int IOMANX_CLEANUP(
int arg)
292#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
294 return MODULE_NO_RESIDENT_END;
296#ifdef IOMANX_USE_DEVICE_LINKED_LIST
297 struct ioman_dev_listentry *i;
304#ifdef IOMANX_USE_DEVICE_LINKED_LIST
305 for ( i = device_entry_used_list_head; i; i = i->next )
307 i->device->ops->deinit(i->device);
311 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
313 if ( device_table[i] )
315 device_table[i]->ops->deinit(device_table[i]);
316 device_table[i] = NULL;
321 return MODULE_RESIDENT_END;
325#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
331int mode2modex(
int mode)
335 if ( FIO_SO_ISLNK(mode) )
337 if ( FIO_SO_ISREG(mode) )
339 if ( FIO_SO_ISDIR(mode) )
353int modex2mode(
int modex)
357 if ( FIO_S_ISLNK(modex) )
359 if ( FIO_S_ISREG(modex) )
361 if ( FIO_S_ISDIR(modex) )
381#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
382void iomanX_StdioInit(
int mode)
390 BootMode = QueryBootMode(3);
391 if ( BootMode && (BootMode[1] & 4) )
393 ReferThreadStatus(0, &thinfo);
394 ChangeThreadPriority(0, 4);
404 open_tty_handles(
"tty:");
412 open_tty_handles(
"dummytty:");
422 open_tty_handles(
"tty:");
425 ChangeThreadPriority(0, thinfo.currentPriority);
429static int open_tty_handles(
const char *tty_name)
431 if ( iomanX_open(tty_name, 3) != 0 || iomanX_open(tty_name, 2) != 1 )
437int iomanX_open(
const char *name,
int flags, ...)
440 const char *parsefile_res;
445 mode = va_arg(va,
int);
449 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
450 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
451 if ( !parsefile_res )
452 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
454 return handle_result(
455 f->
device->ops->open(f, parsefile_res, flags, mode),
457 HANDLE_RESULT_CLEAR_INFO_ON_ERROR | HANDLE_RESULT_RETURN_FD);
460int iomanX_lseek(
int fd,
int offset,
int mode)
466 return handle_result(-
EBADF, f, 0);
472 return handle_result(f->
device->ops->lseek(f, offset, mode), f, 0);
474 write_str_to_stdout(
"invalid lseek arg\r\n");
475 return handle_result(-
EINVAL, f, 0);
479s64 iomanX_lseek64(
int fd, s64 offset,
int whence)
485 return handle_result(-
EBADF, f, 0);
487 return handle_result(-
EUNSUP, f, 0);
493 return handle_result64(f->
device->ops->lseek64(f, offset, whence), f, 0);
495 write_str_to_stdout(
"invalid lseek arg\r\n");
496 return handle_result(-
EINVAL, f, 0);
500int iomanX_read(
int fd,
void *ptr,
int size)
505 if ( !f || !(f->
mode & FIO_O_RDONLY) )
506 return handle_result(-
EBADF, f, 0);
507 return handle_result(f->
device->ops->read(f, ptr, size), f, 0);
510int iomanX_write(
int fd,
void *ptr,
int size)
515 if ( !f || !(f->
mode & FIO_O_WRONLY) )
516 return handle_result(-
EBADF, f, 0);
517 return handle_result(f->
device->ops->write(f, ptr, size), f, 0);
520int iomanX_close(
int fd)
526 return handle_result(-
EBADF, f, 0);
527 return handle_result(
528 (f->
mode & FIO_O_DIROPEN) ? f->
device->ops->dclose(f) : f->device->ops->close(f),
530 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_FD);
533int iomanX_ioctl(
int fd,
int cmd,
void *param)
539 return handle_result(-
EBADF, f, 0);
540 return handle_result(f->
device->ops->ioctl(f, cmd, param), f, 0);
543int iomanX_ioctl2(
int fd,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen)
549 return handle_result(-
EBADF, f, 0);
552 return handle_result(-
EUNSUP, f, 0);
553 return handle_result(f->
device->ops->ioctl2(f, cmd, arg, arglen, buf, buflen), f, 0);
556int iomanX_dopen(
const char *path)
559 const char *parsefile_res;
563 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
564 parsefile_res = parsefile(path, &(f->
device), &(f->
unit));
565 if ( !parsefile_res )
566 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
567 f->
mode = FIO_O_DIROPEN;
568 return handle_result(
569 f->
device->ops->dopen(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR | HANDLE_RESULT_RETURN_FD);
577 if ( !f || !(f->
mode & FIO_O_DIROPEN) )
578 return handle_result(-
EBADF, f, 0);
579#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
587 io_dread_t *io_dread;
589 io_dread = (io_dread_t *)f->
device->ops->dread;
590 res = io_dread(f, &io_dirent);
592 buf->stat.mode = mode2modex(io_dirent.stat.mode);
594 buf->stat.attr = io_dirent.stat.attr;
595 buf->stat.size = io_dirent.stat.size;
596 memcpy(buf->stat.ctime, io_dirent.stat.ctime,
sizeof(io_dirent.stat.ctime));
597 memcpy(buf->stat.atime, io_dirent.stat.atime,
sizeof(io_dirent.stat.atime));
598 memcpy(buf->stat.mtime, io_dirent.stat.mtime,
sizeof(io_dirent.stat.mtime));
599 buf->stat.hisize = io_dirent.stat.hisize;
601 strncpy(buf->name, io_dirent.name,
sizeof(buf->name));
602 return handle_result(res, f, 0);
605 return handle_result(f->
device->ops->dread(f, buf), f, 0);
608int iomanX_remove(
const char *name)
611 const char *parsefile_res;
612#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
616#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
621 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
623 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
624 if ( !parsefile_res )
625 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
626 return handle_result(
627 f->
device->ops->remove(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
630int iomanX_mkdir(
const char *path,
int mode)
632 return xx_dir(4, path, mode);
635int iomanX_rmdir(
const char *path)
637 return xx_dir(5, path, 0);
640static int xx_stat(
int op,
const char *name,
iox_stat_t *stat,
unsigned int statmask)
643 const char *parsefile_res;
644#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
648#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
653 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
655 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
656 if ( !parsefile_res )
657 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
662#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
669 memcpy(&stat_tmp, stat,
sizeof(stat_tmp));
670 stat_tmp.mode = modex2mode(stat->mode);
671 return handle_result(
672 f->
device->ops->chstat(f, parsefile_res, &stat_tmp, statmask),
674 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
677 return handle_result(
678 f->
device->ops->chstat(f, parsefile_res, stat, statmask),
680 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
684#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
691 res = f->
device->ops->getstat(f, parsefile_res, stat);
693 stat->mode = mode2modex(stat->mode);
694 return handle_result(res, f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
697 return handle_result(
698 f->
device->ops->getstat(f, parsefile_res, stat), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
702 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
706int iomanX_getstat(
const char *name,
iox_stat_t *stat)
708 return xx_stat(2, name, stat, 0);
711int iomanX_chstat(
const char *name,
iox_stat_t *stat,
unsigned int statmask)
713 return xx_stat(1, name, stat, statmask);
716int iomanX_format(
const char *dev,
const char *blockdev,
void *arg,
int arglen)
719 const char *parsefile_res;
720#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
724#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
729 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
731 parsefile_res = parsefile(dev, &(f->
device), &(f->
unit));
732 if ( !parsefile_res )
733 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
734 return handle_result(
735 f->
device->ops->format(f, parsefile_res, blockdev, arg, arglen),
737 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
740static int xx_rename(
int op,
const char *oldname,
const char *newname)
743 const char *parsefile_res;
744 const char *parsefile_res_new;
747#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
751#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
756 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
758 parsefile_res = parsefile(oldname, &(f->
device), &(f->
unit));
759 if ( !parsefile_res )
760 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
762 parsefile_res_new = newname;
765 if ( newname && index(newname,
':') )
766 parsefile_res_new = parsefile(newname, &device_new, &unit_new);
768 if ( !parsefile_res_new || (device_new != f->
device) || (unit_new != f->
unit) )
769 return handle_result(-
EXDEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
772 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
776 return handle_result(
777 f->
device->ops->rename(f, parsefile_res, parsefile_res_new),
779 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
781 return handle_result(
782 f->
device->ops->symlink(f, parsefile_res, parsefile_res_new),
784 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
787 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
792int iomanX_rename(
const char *oldname,
const char *newname)
794 return xx_rename(7, oldname, newname);
798int iomanX_symlink(
const char *oldname,
const char *newname)
800 return xx_rename(8, oldname, newname);
803int iomanX_chdir(
const char *name)
805 return xx_dir(0x103, name, 0);
811static int xx_dir(
int op,
const char *name,
int mode)
814 const char *parsefile_res;
815#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
819#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
824 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
826 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
827 if ( !parsefile_res )
828 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
831 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
835 return handle_result(
836 f->
device->ops->mkdir(f, parsefile_res, mode), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
838 return handle_result(
839 f->
device->ops->rmdir(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
841 return handle_result(
842 f->
device->ops->chdir(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
844 return handle_result(
845 f->
device->ops->sync(f, parsefile_res, mode), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
848 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
852int iomanX_sync(
const char *dev,
int flag)
854 return xx_dir(0x106, dev, flag);
857int iomanX_mount(
const char *fsname,
const char *devname,
int flag,
void *arg,
int arglen)
860 const char *parsefile_res;
861#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
865#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
870 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
872 parsefile_res = parsefile(fsname, &(f->
device), &(f->
unit));
873 if ( !parsefile_res )
874 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
877 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
878 return handle_result(
879 f->
device->ops->mount(f, parsefile_res, devname, flag, arg, arglen),
881 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
884int iomanX_umount(
const char *fsname)
887 const char *parsefile_res;
888#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
892#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
897 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
899 parsefile_res = parsefile(fsname, &(f->
device), &(f->
unit));
900 if ( !parsefile_res )
901 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
904 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
905 return handle_result(
906 f->
device->ops->umount(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
909int iomanX_devctl(
const char *name,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen)
912 const char *parsefile_res;
913#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
917#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
922 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
924 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
925 if ( !parsefile_res )
926 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
929 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
930 return handle_result(
931 f->
device->ops->devctl(f, parsefile_res, cmd, arg, arglen, buf, buflen), f, HANDLE_RESULT_CLEAR_INFO);
934int iomanX_readlink(
const char *path,
char *buf,
unsigned int buflen)
937 const char *parsefile_res;
938#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
942#ifdef IOMAN_USE_FILE_STRUCT_TEMP_STACK
947 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
949 parsefile_res = parsefile(path, &(f->
device), &(f->
unit));
950 if ( !parsefile_res )
951 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
954 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
955 return handle_result(f->
device->ops->readlink(f, parsefile_res, buf, buflen), f, HANDLE_RESULT_CLEAR_INFO);
958static int _ioabort(
const char *str1,
const char *str2)
960 return Kprintf(
"ioabort exit:%s %s\n", str1, str2);
971 file_table_entry = NULL;
972 while ( fd < (
int)(
sizeof(file_table) /
sizeof(file_table[0])) )
974 if ( !file_table[fd].device )
976 file_table_entry = &file_table[fd];
982 if ( file_table_entry )
985 if ( !file_table_entry )
986 _ioabort(
"out of file descriptors",
"[too many open]");
987 return file_table_entry;
992 if ( (fd < 0) || (fd >= (
int)(
sizeof(file_table) /
sizeof(file_table[0]))) || (!file_table[fd].device) )
994 return &file_table[fd];
999#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1000 struct ioman_dev_listentry *entry;
1008#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1009 entry = device_entry_used_list_head;
1010 while ( entry && strcmp(name, entry->device->name) )
1011 entry = entry->next;
1012 if ( !entry && show_unkdev_msg )
1014 Kprintf(
"Unknown device '%s'\n", name);
1019 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1021 if ( device_table[i] && !strcmp(name, device_table[i]->name) )
1023 device = device_table[i];
1027 if ( !device && show_unkdev_msg )
1029 Kprintf(
"Unknown device '%s'\n", name);
1034#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1035 return entry ? entry->device : NULL;
1041static const char *parsefile(
const char *path,
iomanX_iop_device_t **p_device,
int *p_unit)
1043 const char *path_trimmed;
1050 path_trimmed = path;
1051 while ( *path_trimmed ==
' ' )
1053 colon_index = index(path_trimmed,
':');
1057 Kprintf(
"Unknown device '%s'\n", path_trimmed);
1060 devname_len = colon_index - path_trimmed;
1062 if ( devname_len > (
sizeof(canon) - 1) )
1064 strncpy(canon, path_trimmed, devname_len);
1065 canon[devname_len] = 0;
1068 while ( isnum(canon[devname_len - 1]) )
1070 if ( isnum(canon[devname_len]) )
1071 unit = strtol(&canon[devname_len], 0, 10);
1072 canon[devname_len] = 0;
1074 device = lookup_dev(canon, 1);
1082 return colon_index + 1;
1089#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1090 struct ioman_dev_listentry *entry;
1091 struct ioman_dev_listentry *old_head;
1098 if ( adddeldrv_in_process )
1100 Kprintf(
"AddDrv()/DelDrv() recursive/mutithread call error !!");
1105 adddeldrv_in_process = 1;
1107#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1108 entry = device_entry_empty_list_head;
1110 if ( !entry || lookup_dev(device->name, 0) )
1112 adddeldrv_in_process = 0;
1115 entry->device = device;
1116 device_entry_empty_list_head = entry->next;
1117 if ( device->ops->init(device) < 0 )
1119 old_head = device_entry_empty_list_head;
1120 entry->device = NULL;
1121 device_entry_empty_list_head = entry;
1122 entry->next = old_head;
1123 adddeldrv_in_process = 0;
1126 old_head = device_entry_used_list_head;
1127 device_entry_used_list_head = entry;
1128 entry->next = old_head;
1130 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1132 if ( !device_table[i] )
1136 if ( i >= (
sizeof(device_table) /
sizeof(device_table[0])) )
1138 adddeldrv_in_process = 0;
1142 device_table[i] = device;
1146 if ( device->ops->init(device) < 0 )
1148 device_table[i] = NULL;
1149 adddeldrv_in_process = 0;
1154 adddeldrv_in_process = 0;
1158int iomanX_DelDrv(
const char *name)
1160#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1161 struct ioman_dev_listentry *entry;
1162 struct ioman_dev_listentry **p_next;
1163 struct ioman_dev_listentry *old_head;
1170 if ( adddeldrv_in_process )
1172 Kprintf(
"AddDrv()/DelDrv() recursive/mutithread call error !!");
1176 adddeldrv_in_process = 1;
1178#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1179 entry = device_entry_used_list_head;
1180 p_next = &device_entry_used_list_head;
1181 while ( entry && strcmp(name, entry->device->name) )
1183 p_next = &entry->next;
1184 entry = entry->next;
1186 if ( !entry || entry->device->ops->deinit(entry->device) < 0 )
1188 adddeldrv_in_process = 0;
1191 old_head = device_entry_empty_list_head;
1192 entry->device = NULL;
1193 device_entry_empty_list_head = entry;
1194 *p_next = entry->next;
1195 entry->next = old_head;
1196 adddeldrv_in_process = 0;
1199 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1201 if ( device_table[i] && !strcmp(name, device_table[i]->name) )
1203 device_table[i]->ops->deinit(device_table[i]);
1204 device_table[i] = NULL;
1205 adddeldrv_in_process = 0;
1210 adddeldrv_in_process = 0;
1215#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
1216unsigned int iomanX_GetDevType(
int fd)
1222 return handle_result(-
EBADF, f, 0);
1227static void ShowDrv(
void)
1229#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1230 struct ioman_dev_listentry *i;
1237 Kprintf(
"Known devices are ");
1238#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1239 for ( i = device_entry_used_list_head; i; i = i->next )
1240 Kprintf(
" %s:(%s) ", i->device->name, i->device->desc);
1242 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1243 if ( device_table[i] != NULL && device_table[i]->name != NULL )
1244 Kprintf(
" %s:(%s) ", device_table[i]->name, device_table[i]->desc);
1250#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
1251static void register_tty(
void)
1253 iomanX_DelDrv(dev_tty.name);
1254 iomanX_AddDrv(&dev_tty);
1257static void register_dummytty(
void)
1259 iomanX_DelDrv(dev_dummytty.name);
1260 iomanX_AddDrv(&dev_dummytty);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
int iomanX_format(const char *dev, const char *blockdev, void *arg, int arglen)
struct _iomanX_iop_device * device