]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dde/ddekit/src/block.c
Some minor fixes.
[l4.git] / l4 / pkg / dde / ddekit / src / block.c
1 /*
2  * This file is part of DDEKit.
3  *
4  * (c) 2013 Maksym Planeta <mcsim.planeta@gmail.com>
5  *     economic rights: Technische Universitaet Dresden (Germany)
6  *
7  * This file is part of TUD:OS and distributed under the terms of the
8  * GNU General Public License 2.
9  * Please see the COPYING-GPL-2 file for details.
10  */
11
12 #include <l4/dde/ddekit/thread.h>
13 #include <l4/dde/ddekit/condvar.h>
14 #include <l4/dde/ddekit/panic.h>
15 #include <l4/dde/ddekit/assert.h>
16 #include <l4/dde/ddekit/memory.h>
17 #include <l4/dde/ddekit/block.h>
18 #include "config.h"
19 #include <l4/dde/ddekit/printf.h>
20
21 #include <l4/dde/dde.h>
22 #include <l4/log/log.h>
23 #include <l4/util/util.h>
24 #include <l4/sys/thread.h>
25 #include <l4/sys/debugger.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <pthread-l4.h>
31
32 struct dde_disk
33 {
34   char * name;
35   void * private_data;
36 };
37
38 static struct dde_disk *disk_array;
39 static int dde_disk_count = 0;
40
41 void ddekit_add_disk(char *name, void *private_data)
42 {
43   struct dde_disk * new_array;
44   new_array = realloc (disk_array, sizeof (*disk_array) * (dde_disk_count + 1));
45   if (!new_array)
46     {
47       /* Request failed */
48       ddekit_printf ("No memory for new disk\n");
49       return;
50     }
51
52   disk_array = new_array;
53
54   disk_array[dde_disk_count].name = name;
55   disk_array[dde_disk_count].private_data = private_data;
56   ddekit_printf ("Added new disk %d name: %s data: %p\n", dde_disk_count,
57                  disk_array[dde_disk_count].name, disk_array[dde_disk_count].private_data);
58   dde_disk_count++;
59 }
60
61 void* ddekit_find_disk(const char* name)
62 {
63   struct dde_disk *disk = NULL;
64   int i;
65
66   for (i = 0; i < dde_disk_count; ++i)
67     {
68       if (!strcmp(disk_array[i].name, name))
69         {
70           disk = &disk_array[i];
71           break;
72         }
73     }
74
75   if (!disk)
76     {
77       ddekit_printf("disk <%s> not found\n", name);
78       return NULL;
79     }
80
81   return disk->private_data;
82 }