forked from gligli/xell
-
Notifications
You must be signed in to change notification settings - Fork 12
/
diskio.c
48 lines (42 loc) · 983 Bytes
/
diskio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <diskio.h>
#include <string.h>
#include <vsprintf.h>
#define MAX_DEVICES 16
struct bdev devices[MAX_DEVICES];
struct bdev *register_bdev(void *ctx, struct bdev_ops *ops, const char *name)
{
int i;
for (i = 0; i < MAX_DEVICES; ++i)
{
if (!devices[i].ops)
break;
}
if (i == MAX_DEVICES)
return 0;
devices[i].ctx = ctx;
strcpy(devices[i].name, name); /* strlen(name)>=16 and i'll kill you! */
devices[i].ops = ops;
printf("registered new device: %s\n", name);
return devices + i;
}
struct bdev *register_bdev_child(struct bdev *parent, lba_t offset, int index)
{
struct bdev *c = register_bdev(parent->ctx, parent->ops, "");
if (!c)
return 0;
sprintf(c->name, "%s%d", parent->name, index);
c->offset = offset;
return c;
}
void unregister_bdev(struct bdev *bdev)
{
bdev->disabled = 1;
}
struct bdev *bdev_open(const char *name)
{
int i;
for (i = 0; i < MAX_DEVICES; ++i)
if (!strcmp(devices[i].name, name))
return devices + i;
return 0;
}