#include "device_struct.h"
#include <floppy.h>
#include <consts.h>
#include <config.h>
#include <stddef.h>
static void init_device(struct device_struct *device, const char *name, int type, const struct block_driver_struct *block_driver)
{
device->name = name;
device->type = type;
if (type == FT_BLK) {
device->block_driver = block_driver;
device->file_system = NULL;
device->data = NULL;
device->count = 0;
}
}
static struct device_table_entry {
struct device_struct device;
unsigned present : 1;
} device_table[NR_DEVICES];
static const unsigned int device_table_size = sizeof device_table / sizeof *device_table;
void device_manager_init()
{
struct device_table_entry *entry;
int id;
for (entry = &device_table[0], id = 0; entry < &device_table[device_table_size]; entry++, id++) {
entry->device.id = id;
entry->present = 0;
}
entry = &device_table[DEV_FD];
init_device(&entry->device, "fd", FT_BLK, &floppy_driver);
entry = &device_table[DEV_CONSOLE];
init_device(&entry->device, "console", FT_CHR, NULL);
entry->present = 1;
entry = &device_table[DEV_NULL];
init_device(&entry->device, "null", FT_CHR, NULL);
entry->present = 1;
entry = &device_table[DEV_ZERO];
init_device(&entry->device, "zero", FT_CHR, NULL);
entry->present = 1;
entry = &device_table[DEV_FULL];
init_device(&entry->device, "full", FT_CHR, NULL);
entry->present = 1;
}
void device_set_present(int id)
{
device_table[id].present = 1;
}
struct device_struct *get_device(int id)
{
return device_table[id].present ? &device_table[id].device : NULL;
}