32#define MODNAME "ioman"
34IRX_ID(
"IO/File_Manager", 1, 1);
45static int should_print_known_devices = 1;
47#define isnum(c) ((c) >= '0' && (c) <= '9')
86static int add_tty_device(
void)
88 return io_AddDrv(&tty_device);
91static int open_tty_handles(
void)
97 result = io_open(
"tty00:", 3);
100 return io_open(
"tty00:", 2);
105static int setup_tty_device(
int should_not_add_tty_device)
109 result = io_DelDrv(
"tty");
110 if (should_not_add_tty_device == 0)
113 return open_tty_handles();
118static int print_abort_error_io(
const char *str1,
const char *str2)
120 return Kprintf(
"ioabort exit:%s %s\n", str1, str2);
125static int print_unsupported_operation(
void)
128 const char *unsupported_operation_str =
"io request for unsupported operation\r\n";
129 io_write(1, unsupported_operation_str, strlen(unsupported_operation_str));
135int _start(
int argc,
char *argv[])
141 if(RegisterLibraryEntries(&_exp_ioman) != 0)
143 return MODULE_NO_RESIDENT_END;
147 memset(dev_list, 0,
sizeof(dev_list));
148 memset(file_table, 0,
sizeof(file_table));
152 return MODULE_RESIDENT_END;
159 for (i = 0; i < MAX_DEVICES; i++)
161 if (dev_list[i] == NULL)
165 if (i >= MAX_DEVICES)
170 dev_list[i] = device;
176 if (device->ops->io_init(device) < 0)
182 should_print_known_devices = 1;
187int io_DelDrv(
const char *name)
191 for (i = 0; i < MAX_DEVICES; i++) {
192 if (dev_list[i] != NULL && !strcmp(name, dev_list[i]->name)) {
193 dev_list[i]->ops->io_deinit(dev_list[i]);
202static void print_known_devices(
void)
204 if (should_print_known_devices)
208 Kprintf(
"Known devices are ");
209 for (i = 0; i < MAX_DEVICES; i++)
211 if (dev_list[i] != NULL && dev_list[i]->name != NULL)
213 Kprintf(
" %s:(%s) ", dev_list[i]->name, dev_list[i]->desc);
218 should_print_known_devices = 0;
222static char * find_iop_device(
const char *dev,
int *unit,
iop_io_device_t **device)
225 char *filename, *tail, *d = (
char *)dev;
231 if ((tail = index(d,
':')) == NULL)
234 len = (int)(tail - d);
235 strncpy(canon, d, len);
239 filename = d + len + 1;
242 while (isnum(canon[len - 1]))
248 if (isnum(canon[len])) {
249 num = strtol(canon + len, 0, 10);
256 for (i = 0; i < MAX_DEVICES; i++) {
257 if (dev_list[i] != NULL && !strcmp(canon, dev_list[i]->name)) {
259 *device = dev_list[i];
265 Kprintf(
"Unknown device '%s'\n", canon);
266 print_known_devices();
276 if (file_table[fd].device != NULL)
277 return &file_table[fd];
290 for (i = 0; i < MAX_FILES; i++)
292 if (!file_table[i].device)
304 if (i >= MAX_DEVICES)
306 print_abort_error_io(
"out of file descriptors",
"");
313int io_open(
const char *name,
int mode)
324 if ((filename = find_iop_device(name, &f->
unit, &f->
device)) == (
char *)-1)
331 if ((res = f->
device->ops->io_open(f, filename, mode)) >= 0)
333 res = (int)(f - file_table);
349 if ((f = get_file(fd)) == NULL)
354 res = f->
device->ops->io_close(f);
361int io_read(
int fd,
void *ptr,
size_t size)
365 if (f == NULL || !(f->
mode & FIO_O_RDONLY))
368 return f->
device->ops->io_read(f, ptr, size);
371int io_write(
int fd,
void *ptr,
size_t size)
375 if (f == NULL || !(f->
mode & FIO_O_WRONLY))
378 return f->
device->ops->io_write(f, ptr, size);
381int io_lseek(
int fd,
int offset,
int whence)
388 if (whence < FIO_SEEK_SET || whence > FIO_SEEK_END)
391 const char *invalid_lssek_address_str =
"invalid lseek arg\r\n";
392 io_write(1, (
void *)invalid_lssek_address_str, strlen(invalid_lssek_address_str));
397 return f->
device->ops->io_lseek(f, offset, whence);
400int io_ioctl(
int fd,
unsigned long arg,
void *param)
407 return f->
device->ops->io_ioctl(f, arg, param);
410int io_remove(
const char *name)
421 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
427 res = f->
device->ops->io_remove(f, filename);
438static int path_common(
const char *name,
int arg,
int code)
450 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
459 res = dops->io_mkdir(f, filename);
462 res = dops->io_rmdir(f, filename);
474int io_mkdir(
const char *name)
476 return path_common(name, 0, 4);
479int io_rmdir(
const char *name)
481 return path_common(name, 0, 5);
484int io_dopen(
const char *name,
int mode)
495 if ((filename = find_iop_device(name, &f->
unit, &f->
device)) == (
char *)-1)
502 if ((res = f->
device->ops->io_dopen(f, filename)) >= 0)
503 res = (int)(f - file_table);
518 if ((f = get_file(fd)) == NULL)
523 res = f->
device->ops->io_dclose(f);
535 if ((f = get_file(fd)) == NULL)
540 res = f->
device->ops->io_dread(f, io_dirent);
545int io_getstat(
const char *name,
io_stat_t *stat)
556 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
562 res = f->
device->ops->io_getstat(f, filename, stat);
570int io_chstat(
const char *name,
io_stat_t *stat,
unsigned int mask)
581 if ((filename = find_iop_device(name, &(f->
unit), &(f->
device))) == (
char *)-1)
587 res = f->
device->ops->io_chstat(f, filename, stat, mask);
595int io_format(
const char *dev)
605 if ((find_iop_device(dev, &(f->
unit), &(f->
device))) == (
char *)-1)
611 res = f->
device->ops->io_format(f);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
struct _iop_io_device * device