]> git.ozlabs.org Git - petitboot/blob - discover/sysinfo.c
discover/platform-powerpc: Set IPMI OS boot sensor
[petitboot] / discover / sysinfo.c
1
2 #include <string.h>
3
4 #include <talloc/talloc.h>
5 #include <process/process.h>
6
7 #include "discover-server.h"
8 #include "platform.h"
9 #include "sysinfo.h"
10
11 static struct system_info *sysinfo;
12 static struct discover_server *server;
13
14 const struct system_info *system_info_get(void)
15 {
16         return sysinfo;
17 }
18
19 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
20                 const char *name, bool link)
21 {
22         struct interface_info *if_info;
23         unsigned int i;
24
25         for (i = 0; i < sysinfo->n_interfaces; i++) {
26                 bool changed = false;
27
28                 if_info = sysinfo->interfaces[i];
29
30                 if (if_info->hwaddr_size != hwaddr_size)
31                         continue;
32
33                 if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
34                         continue;
35
36                 /* Found an existing interface. Notify clients on any name or
37                  * link changes */
38                 if (strcmp(if_info->name, name)) {
39                         talloc_free(if_info->name);
40                         if_info->name = talloc_strdup(if_info, name);
41                         changed = true;
42                 }
43
44                 if (if_info->link != link) {
45                         if_info->link = link;
46                         changed = true;
47                 }
48
49                 if (changed)
50                         discover_server_notify_system_info(server, sysinfo);
51
52                 return;
53         }
54
55         if_info = talloc_zero(sysinfo, struct interface_info);
56         if_info->hwaddr_size = hwaddr_size;
57         if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
58         if_info->name = talloc_strdup(if_info, name);
59         if_info->link = link;
60
61         sysinfo->n_interfaces++;
62         sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
63                                                 struct interface_info *,
64                                                 sysinfo->n_interfaces);
65         sysinfo->interfaces[sysinfo->n_interfaces - 1] = if_info;
66
67         discover_server_notify_system_info(server, sysinfo);
68 }
69
70 void system_info_register_blockdev(const char *name, const char *uuid,
71                 const char *mountpoint)
72 {
73         struct blockdev_info *bd_info;
74         unsigned int i;
75
76         for (i = 0; i < sysinfo->n_blockdevs; i++) {
77                 bd_info = sysinfo->blockdevs[i];
78
79                 if (strcmp(bd_info->name, name))
80                         continue;
81
82                 /* update the mountpoint and UUID, and we're done */
83                 talloc_free(bd_info->mountpoint);
84                 bd_info->uuid = talloc_strdup(bd_info, uuid);
85                 bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
86                 discover_server_notify_system_info(server, sysinfo);
87                 return;
88         }
89
90         bd_info = talloc_zero(sysinfo, struct blockdev_info);
91         bd_info->name = talloc_strdup(bd_info, name);
92         bd_info->uuid = talloc_strdup(bd_info, uuid);
93         bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
94
95         sysinfo->n_blockdevs++;
96         sysinfo->blockdevs = talloc_realloc(sysinfo, sysinfo->blockdevs,
97                                                 struct blockdev_info *,
98                                                 sysinfo->n_blockdevs);
99         sysinfo->blockdevs[sysinfo->n_blockdevs - 1] = bd_info;
100
101         discover_server_notify_system_info(server, sysinfo);
102 }
103
104 void system_info_init(struct discover_server *s)
105 {
106         server = s;
107         sysinfo = talloc_zero(server, struct system_info);
108         platform_get_sysinfo(sysinfo);
109 }