discover: populate sysinfo with block devices
[petitboot] / discover / sysinfo.c
index 870e9a122a53a60f316d738770e4cc80daf7bac2..3c132774e21b3599e0c61e45b6ceaba5ebb847c3 100644 (file)
@@ -53,6 +53,40 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
        discover_server_notify_system_info(server, sysinfo);
 }
 
+void system_info_register_blockdev(const char *name, const char *uuid,
+               const char *mountpoint)
+{
+       struct blockdev_info *bd_info;
+       unsigned int i;
+
+       for (i = 0; i < sysinfo->n_blockdevs; i++) {
+               bd_info = sysinfo->blockdevs[i];
+
+               if (strcmp(bd_info->name, name))
+                       continue;
+
+               /* update the mountpoint and UUID, and we're done */
+               talloc_free(bd_info->mountpoint);
+               bd_info->uuid = talloc_strdup(bd_info, uuid);
+               bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
+               discover_server_notify_system_info(server, sysinfo);
+               return;
+       }
+
+       bd_info = talloc_zero(sysinfo, struct blockdev_info);
+       bd_info->name = talloc_strdup(bd_info, name);
+       bd_info->uuid = talloc_strdup(bd_info, uuid);
+       bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
+
+       sysinfo->n_blockdevs++;
+       sysinfo->blockdevs = talloc_realloc(sysinfo, sysinfo->blockdevs,
+                                               struct blockdev_info *,
+                                               sysinfo->n_blockdevs);
+       sysinfo->blockdevs[sysinfo->n_blockdevs - 1] = bd_info;
+
+       discover_server_notify_system_info(server, sysinfo);
+}
+
 static void system_info_set_identifier(struct system_info *info)
 {
        struct process *process;