| 868 | } |
| 869 | |
| 870 | static int add_topswap_bootblock(struct buffer *buffer, uint32_t *offset) |
| 871 | { |
| 872 | size_t bb_buf_size = buffer_size(buffer); |
| 873 | |
| 874 | if (bb_buf_size > param.topswap_size) { |
| 875 | ERROR("Bootblock bigger than the topswap boundary\n"); |
| 876 | ERROR("size = %zd, ts = %d\n", bb_buf_size, |
| 877 | param.topswap_size); |
| 878 | return 1; |
| 879 | } |
| 880 | |
| 881 | /* |
| 882 | * Allocate topswap_size*2 bytes for bootblock to |
| 883 | * accommodate the second bootblock. |
| 884 | */ |
| 885 | struct buffer new_bootblock, bb1, bb2; |
| 886 | if (buffer_create(&new_bootblock, 2 * param.topswap_size, |
| 887 | buffer->name)) |
| 888 | return 1; |
| 889 | |
| 890 | buffer_splice(&bb1, &new_bootblock, param.topswap_size - bb_buf_size, |
| 891 | bb_buf_size); |
| 892 | buffer_splice(&bb2, &new_bootblock, |
| 893 | buffer_size(&new_bootblock) - bb_buf_size, |
| 894 | bb_buf_size); |
| 895 | |
| 896 | /* Copy to first bootblock */ |
| 897 | memcpy(buffer_get(&bb1), buffer_get(buffer), bb_buf_size); |
| 898 | /* Copy to second bootblock */ |
| 899 | memcpy(buffer_get(&bb2), buffer_get(buffer), bb_buf_size); |
| 900 | |
| 901 | buffer_delete(buffer); |
| 902 | buffer_clone(buffer, &new_bootblock); |
| 903 | |
| 904 | /* Update the location (offset) of bootblock in the region */ |
| 905 | return convert_region_offset(buffer_size(buffer), offset); |
| 906 | } |
| 907 | |
| 908 | static int cbfs_add_component(const char *filename, |
| 909 | const char *name, |
no test coverage detected