]> wimlib.net Git - wimlib/blobdiff - src/header.c
Fix setting header flag during overwrite
[wimlib] / src / header.c
index 0066d75a3ba7b6d9d5db40a506c4fb9b75154327..5d0b683ba7d6ff361f28de36e84f466ff02fa2a9 100644 (file)
@@ -72,7 +72,7 @@ struct wim_header_disk {
         * the only supported value).  */
        u32 chunk_size;
 
-       /* Globally unique identifier for the WIM file.  Basically bunch of
+       /* Globally unique identifier for the WIM file.  Basically bunch of
         * random bytes. */
        u8 guid[WIM_GID_LEN];
 
@@ -102,9 +102,9 @@ struct wim_header_disk {
        u32 boot_idx;
 
        /* Location and size of the WIM's integrity table, or all zeroes if the
-        * WIM has no integrity table. */
-
-       /* Note the integrity_table_res_entry here is 4-byte aligned even though
+        * WIM has no integrity table.
+        *
+        * Note the integrity_table_res_entry here is 4-byte aligned even though
         * it would ordinarily be 8-byte aligned--- hence, the _packed_attribute
         * on the `struct wim_header_disk' is essential. */
        struct resource_entry_disk integrity_table_res_entry;
@@ -115,11 +115,12 @@ struct wim_header_disk {
 
 /* Reads the header from a WIM file.  */
 int
-read_header(const tchar *filename, int in_fd,
-           struct wim_header *hdr, int open_flags)
+read_header(const tchar *filename, int in_fd, struct wim_header *hdr)
 {
        struct wim_header_disk disk_hdr _aligned_attribute(8);
 
+       BUILD_BUG_ON(sizeof(struct wim_header_disk) != WIM_HEADER_DISK_SIZE);
+
        DEBUG("Reading WIM header from \"%"TS"\"", filename);
 
        if (full_pread(in_fd, &disk_hdr, sizeof(disk_hdr), 0) != sizeof(disk_hdr)) {
@@ -132,7 +133,6 @@ read_header(const tchar *filename, int in_fd,
                return WIMLIB_ERR_NOT_A_WIM_FILE;
        }
 
-       BUILD_BUG_ON(sizeof(struct wim_header_disk) != WIM_HEADER_DISK_SIZE);
        if (le32_to_cpu(disk_hdr.hdr_size) != sizeof(struct wim_header_disk)) {
                ERROR("\"%"TS"\": Header size is invalid (%u bytes)",
                      filename, le32_to_cpu(disk_hdr.hdr_size));
@@ -169,13 +169,6 @@ read_header(const tchar *filename, int in_fd,
                return WIMLIB_ERR_INVALID_PART_NUMBER;
        }
 
-       if (!(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK) && hdr->total_parts != 1)
-       {
-               ERROR("\"%"TS"\": This WIM is part %u of a %u-part WIM",
-                     filename, hdr->part_number, hdr->total_parts);
-               return WIMLIB_ERR_SPLIT_UNSUPPORTED;
-       }
-
        hdr->image_count = le32_to_cpu(disk_hdr.image_count);
 
        DEBUG("part_number = %u, total_parts = %u, image_count = %u",
@@ -235,6 +228,38 @@ write_header(const struct wim_header *hdr, int out_fd)
        return 0;
 }
 
+/* Update just the wim_flags field. */
+int
+write_header_flags(u32 hdr_flags, int out_fd)
+{
+       le32 flags = cpu_to_le32(hdr_flags);
+       if (full_pwrite(out_fd, &flags, sizeof(flags),
+                       offsetof(struct wim_header_disk, wim_flags)) != sizeof(flags))
+       {
+               return WIMLIB_ERR_WRITE;
+       } else {
+               return 0;
+       }
+
+}
+
+/* Update just the part_number and total_parts fields. */
+int
+write_header_part_data(u16 part_number, u16 total_parts, int out_fd)
+{
+       le16 part_data[2] = {
+               cpu_to_le16(part_number),
+               cpu_to_le16(total_parts),
+       };
+       if (full_pwrite(out_fd, &part_data, sizeof(part_data),
+                       offsetof(struct wim_header_disk, part_number)) != sizeof(part_data))
+       {
+               return WIMLIB_ERR_WRITE;
+       } else {
+               return 0;
+       }
+}
+
 /*
  * Initializes the header for a WIM file.
  */