]> wimlib.net Git - wimlib/blobdiff - src/metadata_resource.c
lz77.c: Coding style
[wimlib] / src / metadata_resource.c
index b55609e667d74e598dc867f576a5a649cc7a0dc8..8bd9734e8c545a4a407fa73f0485a81ecb167502 100644 (file)
  * wimlib; if not, see http://www.gnu.org/licenses/.
  */
 
-#include "wimlib_internal.h"
-#include "dentry.h"
-#include "lookup_table.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "wimlib/dentry.h"
+#include "wimlib/error.h"
+#include "wimlib/file_io.h"
+#include "wimlib/lookup_table.h"
+#include "wimlib/metadata.h"
+#include "wimlib/resource.h"
+#include "wimlib/security.h"
 
 /*
  * Reads a metadata resource for an image in the WIM file.  The metadata
@@ -194,7 +202,7 @@ recalculate_security_data_length(struct wim_security_data *sd)
  * the buffer to @hash.  */
 static int
 write_wim_resource_from_buffer(const void *buf, size_t buf_size,
-                              filedes_t out_fd, int out_ctype,
+                              int out_fd, int out_ctype,
                               struct resource_entry *out_res_entry,
                               u8 hash[SHA1_HASH_SIZE])
 {
@@ -225,16 +233,26 @@ write_metadata_resource(WIMStruct *w)
        struct wim_lookup_table_entry *lte;
        u64 metadata_original_size;
        struct wim_security_data *sd;
+       struct wim_image_metadata *imd;
 
-       wimlib_assert(w->out_fd != INVALID_FILEDES);
+       wimlib_assert(w->out_fd != -1);
        wimlib_assert(w->current_image != WIMLIB_NO_IMAGE);
 
        DEBUG("Writing metadata resource for image %d (offset = %"PRIu64")",
              w->current_image, filedes_offset(w->out_fd));
 
+       imd = w->image_metadata[w->current_image - 1];
 
-       root = wim_root_dentry(w);
-       sd = wim_security_data(w);
+       root = imd->root_dentry;
+       sd = imd->security_data;
+
+       if (!root) {
+               /* Empty image; create a dummy root. */
+               ret = new_filler_directory(T(""), &root);
+               if (ret)
+                       return ret;
+               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