X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fpb-protocol%2Fpb-protocol.c;h=4a5c75a32437b1e4bd201eba7d5a760288ad55ad;hp=5a056ee7b8150e8034d39b32156d8cd22d4f9d09;hb=e19c5fe83174de749843bb8486a0d12c25adcb82;hpb=20be68872f056457b99cc64164171901be4bc5a3;ds=sidebyside diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index 5a056ee..4a5c75a 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -223,12 +223,20 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo) len = 4 + optional_strlen(sysinfo->type) + 4 + optional_strlen(sysinfo->identifier) + - 4; + 4 + 4; for (i = 0; i < sysinfo->n_interfaces; i++) { struct interface_info *if_info = sysinfo->interfaces[i]; len += 4 + if_info->hwaddr_size + - 4 + optional_strlen(if_info->name); + 4 + optional_strlen(if_info->name) + + sizeof(if_info->link); + } + + for (i = 0; i < sysinfo->n_blockdevs; i++) { + struct blockdev_info *bd_info = sysinfo->blockdevs[i]; + len += 4 + optional_strlen(bd_info->name) + + 4 + optional_strlen(bd_info->uuid) + + 4 + optional_strlen(bd_info->mountpoint); } return len; @@ -271,7 +279,7 @@ int pb_protocol_config_len(const struct config *config) len += 4 + optional_strlen(config->network.dns_servers[i]); len += 4; - len += config->n_boot_priorities * 4; + len += config->n_boot_priorities * 8; return len; } @@ -377,6 +385,20 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo, pos += if_info->hwaddr_size; pos += pb_protocol_serialise_string(pos, if_info->name); + + *(bool *)pos = if_info->link; + pos += sizeof(bool); + } + + *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs); + pos += sizeof(uint32_t); + + for (i = 0; i < sysinfo->n_blockdevs; i++) { + struct blockdev_info *bd_info = sysinfo->blockdevs[i]; + + pos += pb_protocol_serialise_string(pos, bd_info->name); + pos += pb_protocol_serialise_string(pos, bd_info->uuid); + pos += pb_protocol_serialise_string(pos, bd_info->mountpoint); } assert(pos <= buf + buf_len); @@ -442,10 +464,16 @@ int pb_protocol_serialise_config(const struct config *config, *(uint32_t *)pos = __cpu_to_be32(config->n_boot_priorities); pos += 4; for (i = 0; i < config->n_boot_priorities; i++) { - *(uint32_t *)pos = __cpu_to_be32(config->boot_priorities[i].type); + *(uint32_t *)pos = + __cpu_to_be32(config->boot_priorities[i].type); + pos += 4; + *(uint32_t *)pos = + __cpu_to_be32(config->boot_priorities[i].priority); pos += 4; } + pos += pb_protocol_serialise_string(pos, config->boot_device); + assert(pos <= buf + buf_len); (void)buf_len; @@ -747,9 +775,34 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo, if (read_string(if_info, &pos, &len, &if_info->name)) goto out; + if_info->link = *(bool *)pos; + pos += sizeof(if_info->link); + sysinfo->interfaces[i] = if_info; } + /* number of interfaces */ + if (read_u32(&pos, &len, &sysinfo->n_blockdevs)) + goto out; + + sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *, + sysinfo->n_blockdevs); + + for (i = 0; i < sysinfo->n_blockdevs; i++) { + struct blockdev_info *bd_info = talloc(sysinfo, + struct blockdev_info); + + if (read_string(bd_info, &pos, &len, &bd_info->name)) + goto out; + + if (read_string(bd_info, &pos, &len, &bd_info->uuid)) + goto out; + + if (read_string(bd_info, &pos, &len, &bd_info->mountpoint)) + goto out; + + sysinfo->blockdevs[i] = bd_info; + } rc = 0; out: @@ -795,6 +848,7 @@ int pb_protocol_deserialise_config(struct config *config, unsigned int len, i, tmp; const char *pos; int rc = -1; + char *str; len = message->payload_len; pos = message->payload; @@ -827,10 +881,9 @@ int pb_protocol_deserialise_config(struct config *config, config->network.n_dns_servers); for (i = 0; i < config->network.n_dns_servers; i++) { - char *tmp; - if (read_string(config->network.dns_servers, &pos, &len, &tmp)) + if (read_string(config->network.dns_servers, &pos, &len, &str)) goto out; - config->network.dns_servers[i] = tmp; + config->network.dns_servers[i] = str; } if (read_u32(&pos, &len, &config->n_boot_priorities)) @@ -839,11 +892,19 @@ int pb_protocol_deserialise_config(struct config *config, config->n_boot_priorities); for (i = 0; i < config->n_boot_priorities; i++) { + if (read_u32(&pos, &len, &tmp)) + goto out; + config->boot_priorities[i].priority = (int)tmp; if (read_u32(&pos, &len, &tmp)) goto out; config->boot_priorities[i].type = tmp; } + if (read_string(config, &pos, &len, &str)) + goto out; + + config->boot_device = str; + rc = 0; out: