[Hardware OS Device Driver Interface] Keep track of device drivers in the HWOS. More...
#include "hstructures.h"
Go to the source code of this file.
Defines | |
#define | HDEV_PATH_SIZE 40 |
Longest allowed path for device file. | |
Functions | |
int | hdev_size () |
Size of the device list. | |
struct hdev * | hdev_get_by_major (int major) |
Get device by major number. | |
struct hdev * | hdev_add (int major, char *device_path) |
Add a device description. | |
int | hdev_remove (struct hdev *device) |
Remove a device from the HWOS. | |
int | hdev_get_major (struct hdev *device) |
Get major number for device. | |
int | hdev_remove_by_major (int major) |
Remove device by major number. | |
int | hdev_remove_all () |
Remove all devices in the system. | |
struct hdev * | hdev_get_first () |
Get first device in list. | |
struct hdev * | hdev_get_last () |
Get last device in list. | |
struct hdev * | hdev_get_next (struct hdev *device) |
Get next device in list. | |
struct hdev * | hdev_get_prev (struct hdev *device) |
Get previous device in list. |
[Hardware OS Device Driver Interface] Keep track of device drivers in the HWOS.
This functionality is not really used in this version of the HWOS. The module can function as a base for further development. It is probably a good idea to perform the actual creation of a device driver in hdev_add (now it only adds a description to a list).
Based on devicelist by Vegard Endresen. Sindre Hansen (2011): Rewritten.
Definition in file hdev.h.
struct hdev* hdev_add | ( | int | major, | |
char * | device_path | |||
) | [read] |
Add a device description.
This adds a description of a character device with a path and a major number.
major | The major number of the device. | |
device_path | Path of the device. |
Definition at line 148 of file hdev.c.
{ if (hdev_get_by_major(major) != NULL) return NULL; struct hdev* device = calloc(1, sizeof(struct hdev)); set_major_(device, major); set_path_(device, device_path); if (hdev_size() == 0) set_first_(device); set_prev_(device, hdev_get_last()); set_next_(device, NULL); set_next_(hdev_get_last(), device); set_last_(device); increment_size_(); return device; }
struct hdev* hdev_get_by_major | ( | int | major | ) | [read] |
Get device by major number.
Definition at line 126 of file hdev.c.
{ if (hdev_size() == 0) return NULL; struct hdev* device = hdev_get_first(); if (hdev_get_major(device) == major) return device; // TODO: What if get_next never returns NULL? while (hdev_get_next(device) != NULL) { device = hdev_get_next(device); if (hdev_get_major(device) == major) return device; } // Nothing found => return NULL. return NULL; }
struct hdev* hdev_get_first | ( | ) | [read] |
struct hdev* hdev_get_last | ( | ) | [read] |
int hdev_get_major | ( | struct hdev * | device | ) |
int hdev_remove | ( | struct hdev * | device | ) |
Remove a device from the HWOS.
device | Pointer to the struct representing the device. |
Definition at line 173 of file hdev.c.
{ if (device == NULL) return -1; set_prev_(hdev_get_next(device), hdev_get_prev(device)); set_next_(hdev_get_prev(device), hdev_get_next(device)); if (hdev_get_last() == device) set_last_(hdev_get_prev(device)); if (hdev_get_first() == device) set_first_(hdev_get_next(device)); free(device); decrement_size_(); return 0; }
int hdev_remove_all | ( | ) |
Remove all devices in the system.
Definition at line 201 of file hdev.c.
{ struct hdev* device = hdev_get_first(); int number_removed = 0; while (hdev_get_next(device) != NULL) { device = hdev_get_next(device); if (hdev_remove(hdev_get_prev(device)) == 0) number_removed += 1; } if (hdev_remove(device) == 0) number_removed += 1; return number_removed; }
int hdev_remove_by_major | ( | int | major | ) |