/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "device_struct.h" #include #include #include #include /* device */ 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; } } /* device_manager */ 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; } /* DEV_FD */ entry = &device_table[DEV_FD]; init_device(&entry->device, "fd", FT_BLK, &floppy_driver); /* DEV_CONSOLE */ entry = &device_table[DEV_CONSOLE]; init_device(&entry->device, "console", FT_CHR, NULL); entry->present = 1; /* DEV_NULL */ entry = &device_table[DEV_NULL]; init_device(&entry->device, "null", FT_CHR, NULL); entry->present = 1; /* DEV_ZERO */ entry = &device_table[DEV_ZERO]; init_device(&entry->device, "zero", FT_CHR, NULL); entry->present = 1; /* DEV_FULL */ 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; }