- u8 buf[WIM_HEADER_DISK_SIZE];
- u8 *p;
- DEBUG("Writing WIM header.");
-
- 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);
- /* byte 24 */
-
- p = put_bytes(p, WIM_GID_LEN, hdr->guid);
- p = put_u16(p, hdr->part_number);
-
- /* byte 40 */
-
- p = put_u16(p, hdr->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_fp) != sizeof(buf)) {
+ struct wim_header_disk disk_hdr _aligned_attribute(8);
+ int ret;
+
+ disk_hdr.magic = cpu_to_le64(hdr->magic);
+ disk_hdr.hdr_size = cpu_to_le32(sizeof(struct wim_header_disk));
+ disk_hdr.wim_version = cpu_to_le32(hdr->wim_version);
+ disk_hdr.wim_flags = cpu_to_le32(hdr->flags);
+ disk_hdr.chunk_size = cpu_to_le32(hdr->chunk_size);
+ copy_guid(disk_hdr.guid, hdr->guid);
+ 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_wim_reshdr(&hdr->blob_table_reshdr, &disk_hdr.blob_table_reshdr);
+ put_wim_reshdr(&hdr->xml_data_reshdr, &disk_hdr.xml_data_reshdr);
+ put_wim_reshdr(&hdr->boot_metadata_reshdr, &disk_hdr.boot_metadata_reshdr);
+ disk_hdr.boot_idx = cpu_to_le32(hdr->boot_idx);
+ put_wim_reshdr(&hdr->integrity_table_reshdr, &disk_hdr.integrity_table_reshdr);
+ memset(disk_hdr.unused, 0, sizeof(disk_hdr.unused));
+
+ if (offset == out_fd->offset)
+ ret = full_write(out_fd, &disk_hdr, sizeof(disk_hdr));
+ else
+ ret = full_pwrite(out_fd, &disk_hdr, sizeof(disk_hdr), offset);
+ if (ret)