- u8 buf[WIM_HEADER_DISK_SIZE];
- u8 *p;
- DEBUG("Writing WIM header.\n");
-
- p = put_bytes(buf, WIM_MAGIC_LEN, wim_magic_chars);
- p = put_u32(p, WIM_HEADER_DISK_SIZE);
- p = put_u32(p, WIM_VERSION);
- p = put_u32(p, hdr->flags);
- p = put_u32(p, (hdr->flags & WIM_HDR_FLAG_COMPRESSION) ?
- WIM_CHUNK_SIZE : 0);
- randomize_byte_array(p, WIM_GID_LEN);
- p += WIM_GID_LEN;
- p = put_u16(p, 1); /* part number */
- p = put_u16(p, 1); /* total parts */
- p = put_u32(p, hdr->image_count);
- p = put_resource_entry(p, &hdr->lookup_table_res_entry);
- p = put_resource_entry(p, &hdr->xml_res_entry);
- p = put_resource_entry(p, &hdr->boot_metadata_res_entry);
- p = put_u32(p, hdr->boot_idx);
- p = put_resource_entry(p, &hdr->integrity);
- memset(p, 0, WIM_UNUSED_LEN);
- if (fwrite(buf, 1, sizeof(buf), out) != sizeof(buf)) {
- DEBUG("Failed to write WIM header: %m\n");
+ struct wim_header_disk disk_hdr _aligned_attribute(8);
+ DEBUG("Writing WIM header.");
+
+ disk_hdr.magic = WIM_MAGIC;
+ disk_hdr.hdr_size = cpu_to_le32(sizeof(struct wim_header_disk));
+ disk_hdr.wim_version = cpu_to_le32(WIM_VERSION);
+ disk_hdr.wim_flags = cpu_to_le32(hdr->flags);
+ disk_hdr.chunk_size = cpu_to_le32((hdr->flags & WIM_HDR_FLAG_COMPRESSION) ?
+ WIM_CHUNK_SIZE : 0);
+ memcpy(disk_hdr.guid, hdr->guid, WIM_GID_LEN);
+
+ disk_hdr.part_number = cpu_to_le16(hdr->part_number);
+ disk_hdr.total_parts = cpu_to_le16(hdr->total_parts);
+ disk_hdr.image_count = cpu_to_le32(hdr->image_count);
+ put_resource_entry(&hdr->lookup_table_res_entry, &disk_hdr.lookup_table_res_entry);
+ put_resource_entry(&hdr->xml_res_entry, &disk_hdr.xml_data_res_entry);
+ put_resource_entry(&hdr->boot_metadata_res_entry, &disk_hdr.boot_metadata_res_entry);
+ disk_hdr.boot_idx = cpu_to_le32(hdr->boot_idx);
+ put_resource_entry(&hdr->integrity, &disk_hdr.integrity_table_res_entry);
+ memset(disk_hdr.unused, 0, sizeof(disk_hdr.unused));
+
+ if (full_pwrite(out_fd, &disk_hdr, sizeof(disk_hdr), 0) != sizeof(disk_hdr)) {
+ ERROR_WITH_ERRNO("Failed to write WIM header");