32#define MODNAME "ioman"
34IRX_ID(
"IO/File_Manager", 1, 1);
47static int should_print_known_devices = 1;
49#define isnum(c) ((c) >= '0' && (c) <= '9')
55IOMAN_RETURN_VALUE_IMPL(0);
58 IOMAN_RETURN_VALUE(0),
59 IOMAN_RETURN_VALUE(0),
60 IOMAN_RETURN_VALUE(0),
61 IOMAN_RETURN_VALUE(0),
62 IOMAN_RETURN_VALUE(0),
63 IOMAN_RETURN_VALUE(0),
64 IOMAN_RETURN_VALUE(0),
65 IOMAN_RETURN_VALUE(0),
66 IOMAN_RETURN_VALUE(0),
67 IOMAN_RETURN_VALUE(0),
68 IOMAN_RETURN_VALUE(0),
69 IOMAN_RETURN_VALUE(0),
70 IOMAN_RETURN_VALUE(0),
71 IOMAN_RETURN_VALUE(0),
72 IOMAN_RETURN_VALUE(0),
73 IOMAN_RETURN_VALUE(0),
74 IOMAN_RETURN_VALUE(0),
85static int add_tty_device(
void)
87 return io_AddDrv(&tty_device);
90static int open_tty_handles(
void)
96 result = io_open(
"tty00:", 3);
99 return io_open(
"tty00:", 2);
104static int setup_tty_device(
int should_not_add_tty_device)
108 result = io_DelDrv(
"tty");
109 if (should_not_add_tty_device == 0)
112 return open_tty_handles();
117static int print_abort_error_io(
const char *str1,
const char *str2)
119 return Kprintf(
"ioabort exit:%s %s\n", str1, str2);
124static int print_unsupported_operation(
void)
127 const char *unsupported_operation_str =
"io request for unsupported operation\r\n";
128 io_write(1, unsupported_operation_str, strlen(unsupported_operation_str));
134int _start(
int argc,
char *argv[])
140 if(RegisterLibraryEntries(&_exp_ioman) != 0)
142 return MODULE_NO_RESIDENT_END;
146 memset(dev_list, 0,
sizeof(dev_list));
147 memset(file_table, 0,
sizeof(file_table));
151 return MODULE_RESIDENT_END;
158 for (i = 0; i < MAX_DEVICES; i++)
160 if (dev_list[i] == NULL)
164 if (i >= MAX_DEVICES)
169 dev_list[i] = device;
175 if (device->ops->io_init(device) < 0)
181 should_print_known_devices = 1;
186int io_DelDrv(
const char *name)
190 for (i = 0; i < MAX_DEVICES; i++) {
191 if (dev_list[i] != NULL && !strcmp(name, dev_list[i]->name)) {
192 dev_list[i]->ops->io_deinit(dev_list[i]);
201static void print_known_devices(
void)
203 if (should_print_known_devices)
207 Kprintf(
"Known devices are ");
208 for (i = 0; i < MAX_DEVICES; i++)
210 if (dev_list[i] != NULL && dev_list[i]->name != NULL)
212 Kprintf(
" %s:(%s) ", dev_list[i]->name, dev_list[i]->desc);
217 should_print_known_devices = 0;
221static char * find_iop_device(
const char *dev,
int *unit,
iop_io_device_t **device)
224 char *filename, *tail, *d = (
char *)dev;
230 if ((tail = index(d,
':')) == NULL)
233 len = (int)(tail - d);
234 strncpy(canon, d, len);
238 filename = d + len + 1;
241 while (isnum(canon[len - 1]))
247 if (isnum(canon[len])) {
248 num = strtol(canon + len, 0, 10);
255 for (i = 0; i < MAX_DEVICES; i++) {
256 if (dev_list[i] != NULL && !strcmp(canon, dev_list[i]->name)) {
258 *device = dev_list[i];
264 Kprintf(
"Unknown device '%s'\n", canon);
265 print_known_devices();
275 if (file_table[fd].device != NULL)
276 return &file_table[fd];
289 for (i = 0; i < MAX_FILES; i++)
291 if (!file_table[i].device)
303 if (i >= MAX_DEVICES)
305 print_abort_error_io(
"out of file descriptors",
"");
312int io_open(
const char *name,
int mode)
323 if ((filename = find_iop_device(name, &f->
unit, &f->
device)) == (
char *)-1)
330 if ((res = f->
device->ops->io_open(f, filename, mode)) >= 0)
332 res = (int)(f - file_table);
348 if ((f = get_file(fd)) == NULL)
353 res = f->
device->ops->io_close(f);
360int io_read(
int fd,
void *ptr,
size_t size)
364 if (f == NULL || !(f->
mode & FIO_O_RDONLY))
367 return f->
device->ops->io_read(f, ptr, size);
370int io_write(
int fd,
void *ptr,
size_t size)
374 if (f == NULL || !(f->
mode & FIO_O_WRONLY))
377 return f->
device->ops->io_write(f, ptr, size);
380int io_lseek(
int fd,
int offset,
int whence)
387 if (whence < FIO_SEEK_SET || whence > FIO_SEEK_END)
390 const char *invalid_lssek_address_str =
"invalid lseek arg\r\n";
391 io_write(1, (
void *)invalid_lssek_address_str, strlen(invalid_lssek_address_str));
396 return f->
device->ops->io_lseek(f, offset, whence);
399int io_ioctl(
int fd,
unsigned long arg,
void *param)
406 return f->
device->ops->io_ioctl(f, arg, param);
409int io_remove(
const char *name)
420 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
426 res = f->
device->ops->io_remove(f, filename);
437static int path_common(
const char *name,
int arg,
int code)
449 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
458 res = dops->io_mkdir(f, filename);
461 res = dops->io_rmdir(f, filename);
473int io_mkdir(
const char *name)
475 return path_common(name, 0, 4);
478int io_rmdir(
const char *name)
480 return path_common(name, 0, 5);
483int io_dopen(
const char *name,
int mode)
494 if ((filename = find_iop_device(name, &f->
unit, &f->
device)) == (
char *)-1)
501 if ((res = f->
device->ops->io_dopen(f, filename)) >= 0)
502 res = (int)(f - file_table);
517 if ((f = get_file(fd)) == NULL)
522 res = f->
device->ops->io_dclose(f);
534 if ((f = get_file(fd)) == NULL)
539 res = f->
device->ops->io_dread(f, io_dirent);
544int io_getstat(
const char *name,
io_stat_t *stat)
555 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
561 res = f->
device->ops->io_getstat(f, filename, stat);
569int io_chstat(
const char *name,
io_stat_t *stat,
unsigned int mask)
580 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
586 res = f->
device->ops->io_chstat(f, filename, stat, mask);
594int io_format(
const char *dev)
604 if ((find_iop_device(dev, &(f->
unit), &(f->
device))) == (
char *)-1)
610 res = f->
device->ops->io_format(f);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
struct _iop_io_device * device