]> wimlib.net Git - wimlib/blobdiff - src/metadata_resource.c
Use more comprehensive public domain dedications
[wimlib] / src / metadata_resource.c
index a3faa9c904e41d48a6c73a689a5d906b0e47a9de..4cd53032cbbca435f3a0c3b824acc61fe8303e16 100644 (file)
@@ -73,36 +73,31 @@ read_metadata_resource(struct wim_image_metadata *imd)
        const struct blob_descriptor *metadata_blob;
        void *buf;
        int ret;
+       u8 hash[SHA1_HASH_SIZE];
        struct wim_security_data *sd;
        struct wim_dentry *root;
 
        metadata_blob = imd->metadata_blob;
 
-       DEBUG("Reading metadata resource (size=%"PRIu64").", metadata_blob->size);
-
        /* Read the metadata resource into memory.  (It may be compressed.)  */
        ret = read_blob_into_alloc_buf(metadata_blob, &buf);
        if (ret)
                return ret;
 
        /* Checksum the metadata resource.  */
-       if (!metadata_blob->dont_check_metadata_hash) {
-               u8 hash[SHA1_HASH_SIZE];
-
-               sha1_buffer(buf, metadata_blob->size, hash);
-               if (!hashes_equal(metadata_blob->hash, hash)) {
-                       ERROR("Metadata resource is corrupted "
-                             "(invalid SHA-1 message digest)!");
-                       ret = WIMLIB_ERR_INVALID_METADATA_RESOURCE;
-                       goto out_free_buf;
-               }
+       sha1_buffer(buf, metadata_blob->size, hash);
+       if (!hashes_equal(metadata_blob->hash, hash)) {
+               ERROR("Metadata resource is corrupted "
+                     "(invalid SHA-1 message digest)!");
+               ret = WIMLIB_ERR_INVALID_METADATA_RESOURCE;
+               goto out_free_buf;
        }
 
        /* Parse the metadata resource.
         *
         * Notes: The metadata resource consists of the security data, followed
         * by the directory entry for the root directory, followed by all the
-        * other directory entries in the filesystem.  The subdir_offset field
+        * other directory entries in the filesystem.  The subdir offset field
         * of each directory entry gives the start of its child entries from the
         * beginning of the metadata resource.  An end-of-directory is signaled
         * by a directory entry of length '0', really of length 8, because
@@ -132,7 +127,6 @@ read_metadata_resource(struct wim_image_metadata *imd)
        imd->root_dentry = root;
        imd->security_data = sd;
        INIT_LIST_HEAD(&imd->unhashed_blobs);
-       DEBUG("Done parsing metadata resource.");
        return 0;
 
 out_free_dentry_tree:
@@ -150,7 +144,7 @@ recalculate_security_data_length(struct wim_security_data *sd)
        u32 total_length = sizeof(u64) * sd->num_entries + 2 * sizeof(u32);
        for (u32 i = 0; i < sd->num_entries; i++)
                total_length += sd->sizes[i];
-       sd->total_length = (total_length + 7) & ~7;
+       sd->total_length = ALIGN(total_length, 8);
 }
 
 static int
@@ -166,8 +160,6 @@ prepare_metadata_resource(WIMStruct *wim, int image,
        struct wim_security_data *sd;
        struct wim_image_metadata *imd;
 
-       DEBUG("Preparing metadata resource for image %d", image);
-
        ret = select_wim_image(wim, image);
        if (ret)
                return ret;
@@ -185,16 +177,12 @@ prepare_metadata_resource(WIMStruct *wim, int image,
                imd->root_dentry = root;
        }
 
-       /* Offset of first child of the root dentry.  It's equal to:
-        * - The total length of the security data, rounded to the next 8-byte
-        *   boundary,
-        * - plus the total length of the root dentry,
-        * - plus 8 bytes for an end-of-directory entry following the root
-        *   dentry (shouldn't really be needed, but just in case...)
-        */
+       /* The offset of the first child of the root dentry is equal to the
+        * total length of the security data, plus the total length of the root
+        * dentry, plus 8 bytes for an end-of-directory entry following the root
+        * dentry (shouldn't really be needed, but just in case...)  */
        recalculate_security_data_length(sd);
-       subdir_offset = (((u64)sd->total_length + 7) & ~7) +
-                       dentry_out_total_length(root) + 8;
+       subdir_offset = sd->total_length + dentry_out_total_length(root) + 8;
 
        /* Calculate the subdirectory offsets for the entire dentry tree.  */
        calculate_subdir_offsets(root, &subdir_offset);
@@ -254,9 +242,6 @@ write_metadata_resource(WIMStruct *wim, int image, int write_resource_flags)
                                             imd->metadata_blob->hash,
                                             write_resource_flags);
 
-       /* Original checksum was overridden; set a flag so it isn't used.  */
-       imd->metadata_blob->dont_check_metadata_hash = 1;
-
        FREE(buf);
        return ret;
 }