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
121 &dev_tty_dev_operations,
128 &dev_tty_dev_operations,
131static int adddeldrv_in_process;
132#ifdef IOMANX_USE_ERRNO
133static int errno_local;
135#ifdef IOMANX_USE_DEVICE_LINKED_LIST
136static struct ioman_dev_listentry *device_entry_empty_list_head;
137static struct ioman_dev_listentry *device_entry_used_list_head;
139#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
143#ifdef IOMANX_USE_DEVICE_LINKED_LIST
144static struct ioman_dev_listentry device_entry_list[MAX_DEVICES];
150#define isnum(c) ((c) >= '0' && (c) <= '9')
155#define EUNSUP ENOTSUP
161#define HANDLE_RESULT_CLEAR_INFO 1
162#define HANDLE_RESULT_CLEAR_INFO_ON_ERROR 2
163#define HANDLE_RESULT_RETURN_ZERO 4
164#define HANDLE_RESULT_RETURN_FD 8
166static inline void write_str_to_stdout(
const char *in_str)
168 iomanX_write(1, (
void *)in_str, strlen(in_str));
171static inline int set_errno(
int in_errno)
173#ifdef IOMANX_USE_ERRNO
174 errno_local = in_errno;
181 if ( (op & HANDLE_RESULT_CLEAR_INFO) )
189 if ( (op & HANDLE_RESULT_CLEAR_INFO_ON_ERROR) )
191 if ( f && (in_result < 0) )
202 handle_result_pre(in_result, f, op);
204 return set_errno(-in_result);
205 if ( (op & HANDLE_RESULT_RETURN_ZERO) )
207 if ( (op & HANDLE_RESULT_RETURN_FD) )
208 return f - file_table;
214 handle_result_pre(in_result, f, op);
216 return set_errno(-(
int)in_result);
217 if ( (op & HANDLE_RESULT_RETURN_ZERO) )
219 if ( (op & HANDLE_RESULT_RETURN_FD) )
220 return f - file_table;
224#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
225extern int hook_ioman();
226extern int unhook_ioman();
229#ifndef IOMANX_ENTRYPOINT
231#define IOMANX_ENTRYPOINT _start
233#define IOMANX_ENTRYPOINT iomanX_start
237#ifndef IOMANX_CLEANUP
238#define IOMANX_CLEANUP shutdown
241int IOMANX_ENTRYPOINT(
int ac,
char **av)
243#ifdef IOMANX_USE_DEVICE_LINKED_LIST
251#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
252 if ( RegisterLibraryEntries(&_exp_iomanx) )
253 return MODULE_NO_RESIDENT_END;
255 if ( RegisterLibraryEntries(&_exp_ioman) )
256 return MODULE_NO_RESIDENT_END;
258 SetRebootTimeLibraryHandlingMode(&_exp_ioman, 2);
261 _exp_ioman.mode &= ~6;
262 _exp_ioman.mode |= 2;
266 adddeldrv_in_process = 0;
267#ifdef IOMANX_USE_DEVICE_LINKED_LIST
269 memset(device_entry_list, 0,
sizeof(device_entry_list));
270 device_entry_used_list_head = NULL;
271 device_entry_empty_list_head = device_entry_list;
273 for ( i = 0; i < ((
sizeof(device_entry_list) /
sizeof(device_entry_list[0])) - 1); i += 1 )
274 device_entry_list[i].next = &device_entry_list[i + 1];
276 memset(device_table, 0,
sizeof(device_table));
279 memset(file_table, 0,
sizeof(file_table));
280#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
282 return MODULE_NO_RESIDENT_END;
286 return MODULE_RESIDENT_END;
289int IOMANX_CLEANUP(
int arg)
291#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
293 return MODULE_NO_RESIDENT_END;
295#ifdef IOMANX_USE_DEVICE_LINKED_LIST
296 struct ioman_dev_listentry *i;
303#ifdef IOMANX_USE_DEVICE_LINKED_LIST
304 for ( i = device_entry_used_list_head; i; i = i->next )
306 i->device->ops->deinit(i->device);
310 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
312 if ( device_table[i] )
314 device_table[i]->ops->deinit(device_table[i]);
315 device_table[i] = NULL;
320 return MODULE_RESIDENT_END;
324#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
330int mode2modex(
int mode)
334 if ( FIO_SO_ISLNK(mode) )
336 if ( FIO_SO_ISREG(mode) )
338 if ( FIO_SO_ISDIR(mode) )
352int modex2mode(
int modex)
356 if ( FIO_S_ISLNK(modex) )
358 if ( FIO_S_ISREG(modex) )
360 if ( FIO_S_ISDIR(modex) )
380#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
381void iomanX_StdioInit(
int mode)
389 BootMode = QueryBootMode(3);
390 if ( BootMode && (BootMode[1] & 4) )
392 ReferThreadStatus(0, &thinfo);
393 ChangeThreadPriority(0, 4);
403 open_tty_handles(
"tty:");
411 open_tty_handles(
"dummytty:");
421 open_tty_handles(
"tty:");
424 ChangeThreadPriority(0, thinfo.currentPriority);
428static int open_tty_handles(
const char *tty_name)
430 if ( iomanX_open(tty_name, 3) != 0 || iomanX_open(tty_name, 2) != 1 )
436int iomanX_open(
const char *name,
int flags, ...)
439 const char *parsefile_res;
444 mode = va_arg(va,
int);
448 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
449 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
450 if ( !parsefile_res )
451 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
453 return handle_result(
454 f->
device->ops->open(f, parsefile_res, flags, mode),
456 HANDLE_RESULT_CLEAR_INFO_ON_ERROR | HANDLE_RESULT_RETURN_FD);
459int iomanX_lseek(
int fd,
int offset,
int mode)
465 return handle_result(-
EBADF, f, 0);
471 return handle_result(f->
device->ops->lseek(f, offset, mode), f, 0);
473 write_str_to_stdout(
"invalid lseek arg\r\n");
474 return handle_result(-
EINVAL, f, 0);
478s64 iomanX_lseek64(
int fd, s64 offset,
int whence)
484 return handle_result(-
EBADF, f, 0);
486 return handle_result(-
EUNSUP, f, 0);
492 return handle_result64(f->
device->ops->lseek64(f, offset, whence), f, 0);
494 write_str_to_stdout(
"invalid lseek arg\r\n");
495 return handle_result(-
EINVAL, f, 0);
499int iomanX_read(
int fd,
void *ptr,
int size)
504 if ( !f || !(f->
mode & FIO_O_RDONLY) )
505 return handle_result(-
EBADF, f, 0);
506 return handle_result(f->
device->ops->read(f, ptr, size), f, 0);
509int iomanX_write(
int fd,
void *ptr,
int size)
514 if ( !f || !(f->
mode & FIO_O_WRONLY) )
515 return handle_result(-
EBADF, f, 0);
516 return handle_result(f->
device->ops->write(f, ptr, size), f, 0);
519int iomanX_close(
int fd)
525 return handle_result(-
EBADF, f, 0);
526 return handle_result(
527 (f->
mode & FIO_O_DIROPEN) ? f->
device->ops->dclose(f) : f->device->ops->close(f),
529 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_FD);
532int iomanX_ioctl(
int fd,
int cmd,
void *param)
538 return handle_result(-
EBADF, f, 0);
539 return handle_result(f->
device->ops->ioctl(f, cmd, param), f, 0);
542int iomanX_ioctl2(
int fd,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen)
548 return handle_result(-
EBADF, f, 0);
551 return handle_result(-
EUNSUP, f, 0);
552 return handle_result(f->
device->ops->ioctl2(f, cmd, arg, arglen, buf, buflen), f, 0);
555int iomanX_dopen(
const char *path)
558 const char *parsefile_res;
562 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
563 parsefile_res = parsefile(path, &(f->
device), &(f->
unit));
564 if ( !parsefile_res )
565 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
566 f->
mode = FIO_O_DIROPEN;
567 return handle_result(
568 f->
device->ops->dopen(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR | HANDLE_RESULT_RETURN_FD);
576 if ( !f || !(f->
mode & FIO_O_DIROPEN) )
577 return handle_result(-
EBADF, f, 0);
578#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
586 io_dread_t *io_dread;
588 io_dread = (io_dread_t *)f->
device->ops->dread;
589 res = io_dread(f, &io_dirent);
591 buf->stat.mode = mode2modex(io_dirent.stat.mode);
593 buf->stat.attr = io_dirent.stat.attr;
594 buf->stat.size = io_dirent.stat.size;
595 memcpy(buf->stat.ctime, io_dirent.stat.ctime,
sizeof(io_dirent.stat.ctime));
596 memcpy(buf->stat.atime, io_dirent.stat.atime,
sizeof(io_dirent.stat.atime));
597 memcpy(buf->stat.mtime, io_dirent.stat.mtime,
sizeof(io_dirent.stat.mtime));
598 buf->stat.hisize = io_dirent.stat.hisize;
600 strncpy(buf->name, io_dirent.name,
sizeof(buf->name));
601 return handle_result(res, f, 0);
604 return handle_result(f->
device->ops->dread(f, buf), f, 0);
607int iomanX_remove(
const char *name)
610 const char *parsefile_res;
614 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
615 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
616 if ( !parsefile_res )
617 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
618 return handle_result(
619 f->
device->ops->remove(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
622int iomanX_mkdir(
const char *path,
int mode)
624 return xx_dir(4, path, mode);
627int iomanX_rmdir(
const char *path)
629 return xx_dir(5, path, 0);
632static int xx_stat(
int op,
const char *name,
iox_stat_t *stat,
unsigned int statmask)
635 const char *parsefile_res;
639 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
640 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
641 if ( !parsefile_res )
642 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
647#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
654 memcpy(&stat_tmp, stat,
sizeof(stat_tmp));
655 stat_tmp.mode = modex2mode(stat->mode);
656 return handle_result(
657 f->
device->ops->chstat(f, parsefile_res, &stat_tmp, statmask),
659 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
662 return handle_result(
663 f->
device->ops->chstat(f, parsefile_res, stat, statmask),
665 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
669#ifdef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
676 res = f->
device->ops->getstat(f, parsefile_res, stat);
678 stat->mode = mode2modex(stat->mode);
679 return handle_result(res, f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
682 return handle_result(
683 f->
device->ops->getstat(f, parsefile_res, stat), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
687 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
691int iomanX_getstat(
const char *name,
iox_stat_t *stat)
693 return xx_stat(2, name, stat, 0);
696int iomanX_chstat(
const char *name,
iox_stat_t *stat,
unsigned int statmask)
698 return xx_stat(1, name, stat, statmask);
701int iomanX_format(
const char *dev,
const char *blockdev,
void *arg,
int arglen)
704 const char *parsefile_res;
708 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
709 parsefile_res = parsefile(dev, &(f->
device), &(f->
unit));
710 if ( !parsefile_res )
711 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
712 return handle_result(
713 f->
device->ops->format(f, parsefile_res, blockdev, arg, arglen),
715 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
718static int xx_rename(
int op,
const char *oldname,
const char *newname)
721 const char *parsefile_res;
722 const char *parsefile_res_new;
728 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
729 parsefile_res = parsefile(oldname, &(f->
device), &(f->
unit));
730 if ( !parsefile_res )
731 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
733 parsefile_res_new = newname;
736 if ( newname && index(newname,
':') )
737 parsefile_res_new = parsefile(newname, &device_new, &unit_new);
739 if ( !parsefile_res_new || (device_new != f->
device) || (unit_new != f->
unit) )
740 return handle_result(-
EXDEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
743 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
747 return handle_result(
748 f->
device->ops->rename(f, parsefile_res, parsefile_res_new),
750 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
752 return handle_result(
753 f->
device->ops->symlink(f, parsefile_res, parsefile_res_new),
755 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
758 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
763int iomanX_rename(
const char *oldname,
const char *newname)
765 return xx_rename(7, oldname, newname);
769int iomanX_symlink(
const char *oldname,
const char *newname)
771 return xx_rename(8, oldname, newname);
774int iomanX_chdir(
const char *name)
776 return xx_dir(0x103, name, 0);
782static int xx_dir(
int op,
const char *name,
int mode)
785 const char *parsefile_res;
789 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
790 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
791 if ( !parsefile_res )
792 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
795 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
799 return handle_result(
800 f->
device->ops->mkdir(f, parsefile_res, mode), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
802 return handle_result(
803 f->
device->ops->rmdir(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
805 return handle_result(
806 f->
device->ops->chdir(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
808 return handle_result(
809 f->
device->ops->sync(f, parsefile_res, mode), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
812 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
816int iomanX_sync(
const char *dev,
int flag)
818 return xx_dir(0x106, dev, flag);
821int iomanX_mount(
const char *fsname,
const char *devname,
int flag,
void *arg,
int arglen)
824 const char *parsefile_res;
828 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
829 parsefile_res = parsefile(fsname, &(f->
device), &(f->
unit));
830 if ( !parsefile_res )
831 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
834 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
835 return handle_result(
836 f->
device->ops->mount(f, parsefile_res, devname, flag, arg, arglen),
838 HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
841int iomanX_umount(
const char *fsname)
844 const char *parsefile_res;
848 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
849 parsefile_res = parsefile(fsname, &(f->
device), &(f->
unit));
850 if ( !parsefile_res )
851 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
854 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
855 return handle_result(
856 f->
device->ops->umount(f, parsefile_res), f, HANDLE_RESULT_CLEAR_INFO | HANDLE_RESULT_RETURN_ZERO);
859int iomanX_devctl(
const char *name,
int cmd,
void *arg,
unsigned int arglen,
void *buf,
unsigned int buflen)
862 const char *parsefile_res;
866 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
867 parsefile_res = parsefile(name, &(f->
device), &(f->
unit));
868 if ( !parsefile_res )
869 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
872 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
873 return handle_result(
874 f->
device->ops->devctl(f, parsefile_res, cmd, arg, arglen, buf, buflen), f, HANDLE_RESULT_CLEAR_INFO);
877int iomanX_readlink(
const char *path,
char *buf,
unsigned int buflen)
880 const char *parsefile_res;
884 return handle_result(-
EMFILE, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
885 parsefile_res = parsefile(path, &(f->
device), &(f->
unit));
886 if ( !parsefile_res )
887 return handle_result(-
ENODEV, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
890 return handle_result(-
EUNSUP, f, HANDLE_RESULT_CLEAR_INFO_ON_ERROR);
891 return handle_result(f->
device->ops->readlink(f, parsefile_res, buf, buflen), f, HANDLE_RESULT_CLEAR_INFO);
894static int _ioabort(
const char *str1,
const char *str2)
896 return Kprintf(
"ioabort exit:%s %s\n", str1, str2);
905 file_table_entry = file_table;
906 while ( (file_table_entry < &file_table[
sizeof(file_table) /
sizeof(file_table[0])]) && file_table_entry->
mode )
907 file_table_entry += 1;
908 if ( file_table_entry >= &file_table[
sizeof(file_table) /
sizeof(file_table[0])] )
909 file_table_entry = NULL;
911 if ( file_table_entry )
912 file_table_entry->
mode = -20;
914 if ( !file_table_entry )
915 _ioabort(
"out of file descriptors",
"[too many open]");
916 return file_table_entry;
921 if ( ((
unsigned int)fd >= (
sizeof(file_table) /
sizeof(file_table[0]))) || (!file_table[fd].device) )
923 return &file_table[fd];
928#ifdef IOMANX_USE_DEVICE_LINKED_LIST
929 struct ioman_dev_listentry *entry;
937#ifdef IOMANX_USE_DEVICE_LINKED_LIST
938 entry = device_entry_used_list_head;
939 while ( entry && strcmp(name, entry->device->name) )
941 if ( !entry && show_unkdev_msg )
943 Kprintf(
"Unknown device '%s'\n", name);
948 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
950 if ( device_table[i] && !strcmp(name, device_table[i]->name) )
952 device = device_table[i];
956 if ( !device && show_unkdev_msg )
958 Kprintf(
"Unknown device '%s'\n", name);
963#ifdef IOMANX_USE_DEVICE_LINKED_LIST
964 return entry ? entry->device : NULL;
972 const char *path_trimmed;
980 while ( *path_trimmed ==
' ' )
982 colon_index = index(path_trimmed,
':');
986 Kprintf(
"Unknown device '%s'\n", path_trimmed);
989 devname_len = colon_index - path_trimmed;
991 if ( devname_len > (
sizeof(canon) - 1) )
993 strncpy(canon, path_trimmed, devname_len);
996 while ( isnum(canon[devname_len - 1]) )
998 if ( isnum(canon[devname_len]) )
999 unit = strtol(&canon[devname_len], 0, 10);
1000 canon[devname_len] = 0;
1002 device = lookup_dev(canon, 1);
1010 return colon_index + 1;
1015#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
1016static int tty_noop(
void)
1024#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1025 struct ioman_dev_listentry *entry;
1026 struct ioman_dev_listentry *old_head;
1033 if ( adddeldrv_in_process )
1035 Kprintf(
"AddDrv()/DelDrv() recursive/mutithread call error !!");
1040 adddeldrv_in_process = 1;
1042#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1043 entry = device_entry_empty_list_head;
1045 if ( !entry || lookup_dev(device->name, 0) )
1047 adddeldrv_in_process = 0;
1050 entry->device = device;
1051 device_entry_empty_list_head = entry->next;
1052 if ( device->ops->init(device) < 0 )
1054 old_head = device_entry_empty_list_head;
1055 entry->device = NULL;
1056 device_entry_empty_list_head = entry;
1057 entry->next = old_head;
1058 adddeldrv_in_process = 0;
1061 old_head = device_entry_used_list_head;
1062 device_entry_used_list_head = entry;
1063 entry->next = old_head;
1065 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1067 if ( !device_table[i] )
1071 if ( i >= (
sizeof(device_table) /
sizeof(device_table[0])) )
1073 adddeldrv_in_process = 0;
1077 device_table[i] = device;
1081 if ( device->ops->init(device) < 0 )
1083 device_table[i] = NULL;
1084 adddeldrv_in_process = 0;
1089 adddeldrv_in_process = 0;
1093int iomanX_DelDrv(
const char *name)
1095#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1096 struct ioman_dev_listentry *entry;
1097 struct ioman_dev_listentry **p_next;
1098 struct ioman_dev_listentry *old_head;
1105 if ( adddeldrv_in_process )
1107 Kprintf(
"AddDrv()/DelDrv() recursive/mutithread call error !!");
1111 adddeldrv_in_process = 1;
1113#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1114 entry = device_entry_used_list_head;
1115 p_next = &device_entry_used_list_head;
1116 while ( entry && strcmp(name, entry->device->name) )
1118 p_next = &entry->next;
1119 entry = entry->next;
1121 if ( !entry || entry->device->ops->deinit(entry->device) < 0 )
1123 adddeldrv_in_process = 0;
1126 old_head = device_entry_empty_list_head;
1127 entry->device = NULL;
1128 device_entry_empty_list_head = entry;
1129 *p_next = entry->next;
1130 entry->next = old_head;
1131 adddeldrv_in_process = 0;
1134 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1136 if ( device_table[i] && !strcmp(name, device_table[i]->name) )
1138 device_table[i]->ops->deinit(device_table[i]);
1139 device_table[i] = NULL;
1140 adddeldrv_in_process = 0;
1145 adddeldrv_in_process = 0;
1150#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
1151unsigned int iomanX_GetDevType(
int fd)
1157 return handle_result(-
EBADF, f, 0);
1162static void ShowDrv(
void)
1164#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1165 struct ioman_dev_listentry *i;
1172 Kprintf(
"Known devices are ");
1173#ifdef IOMANX_USE_DEVICE_LINKED_LIST
1174 for ( i = device_entry_used_list_head; i; i = i->next )
1175 Kprintf(
" %s:(%s) ", i->device->name, i->device->desc);
1177 for ( i = 0; i < (
sizeof(device_table) /
sizeof(device_table[0])); i += 1 )
1178 if ( device_table[i] != NULL && device_table[i]->name != NULL )
1179 Kprintf(
" %s:(%s) ", device_table[i]->name, device_table[i]->desc);
1185#ifndef IOMANX_ENABLE_LEGACY_IOMAN_HOOK
1186static void register_tty(
void)
1188 iomanX_DelDrv(dev_tty.name);
1189 iomanX_AddDrv(&dev_tty);
1192static void register_dummytty(
void)
1194 iomanX_DelDrv(dev_dummytty.name);
1195 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