1 /*
2 * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include <boot_item.h>
8 #include <util/DoublyLinkedList.h>
9 #include <util/kernel_cpp.h>
10
11 #include <string.h>
12
13
14 // ToDo: the boot items are not supposed to be changed after kernel startup
15 // so no locking is done. So for now, we need to be careful with adding
16 // new items.
17
18 struct boot_item : public DoublyLinkedListLinkImpl<boot_item> {
19 const char *name;
20 void *data;
21 size_t size;
22 };
23
24 typedef DoublyLinkedList<boot_item> ItemList;
25
26
27 static ItemList sItemList;
28
29
30 status_t
add_boot_item(const char * name,void * data,size_t size)31 add_boot_item(const char *name, void *data, size_t size)
32 {
33 boot_item *item = new(nothrow) boot_item;
34 if (item == NULL)
35 return B_NO_MEMORY;
36
37 item->name = name;
38 item->data = data;
39 item->size = size;
40
41 sItemList.Add(item);
42 return B_OK;
43 }
44
45
46 void *
get_boot_item(const char * name,size_t * _size)47 get_boot_item(const char *name, size_t *_size)
48 {
49 if (name == NULL || name[0] == '\0')
50 return NULL;
51
52 // search item
53 for (ItemList::Iterator it = sItemList.GetIterator(); it.HasNext();) {
54 boot_item *item = it.Next();
55
56 if (!strcmp(name, item->name)) {
57 if (_size != NULL)
58 *_size = item->size;
59
60 return item->data;
61 }
62 }
63
64 return NULL;
65 }
66
67
68 status_t
boot_item_init(void)69 boot_item_init(void)
70 {
71 new(&sItemList) ItemList;
72 // static initializers do not work in the kernel,
73 // so we have to do it here, manually
74
75 return B_OK;
76 }
77