struct wim_lookup_table *lookup_table,
FILE *out_fp,
int out_ctype,
+ int write_resource_flags,
wimlib_progress_func_t progress_func,
- union wimlib_progress_info *progress,
- int write_resource_flags)
+ union wimlib_progress_info *progress)
{
- int ret;
+ int ret = 0;
struct wim_lookup_table_entry *lte;
/* For each stream in @stream_list ... */
lookup_table,
&tmp);
if (ret)
- return ret;
+ break;
if (tmp != lte) {
lte = tmp;
/* We found a duplicate stream. */
<e->output_resource_entry,
write_resource_flags);
if (ret)
- return ret;
+ break;
if (lte->unhashed) {
list_del(<e->unhashed_list);
lookup_table_insert(lookup_table, lte);
progress_func,
wim_resource_size(lte));
}
- return 0;
+ return ret;
}
static int
return do_write_stream_list(stream_list,
lookup_table,
out_fp,
- out_ctype, progress_func,
- progress, write_resource_flags);
+ out_ctype,
+ write_resource_flags,
+ progress_func,
+ progress);
}
#ifdef ENABLE_MULTITHREADED_COMPRESSION
if (list_empty(stream_list))
return 0;
+ /* Calculate the total size of the streams to be written. Note: this
+ * will be the uncompressed size, as we may not know the compressed size
+ * yet, and also this will assume that every unhashed stream will be
+ * written (which will not necessarily be the case). */
list_for_each_entry(lte, stream_list, write_streams_list) {
num_streams++;
total_bytes += wim_resource_size(lte);
lte_set_output_res_entry(wim->image_metadata[i]->metadata_lte,
wim);
for_lookup_table_entry(wim->lookup_table, lte_set_output_res_entry, wim);
- INIT_LIST_HEAD(stream_list);
- list_splice(&args.stream_list, stream_list);
+ list_transfer(&args.stream_list, stream_list);
out_destroy_stream_size_table:
destroy_stream_size_table(&args.stream_size_tab);
return ret;
static int
image_find_streams_to_write(WIMStruct *w)
{
- struct wim_image_metadata *imd;
struct find_streams_ctx *ctx;
+ struct wim_image_metadata *imd;
struct wim_inode *inode;
struct wim_lookup_table_entry *lte;
wim->private = &ctx;
ret = for_image(wim, image, image_find_streams_to_write);
destroy_stream_size_table(&ctx.stream_size_tab);
- if (ret == 0) {
- INIT_LIST_HEAD(stream_list);
- list_splice(&ctx.stream_list, stream_list);
- }
+ if (ret == 0)
+ list_transfer(&ctx.stream_list, stream_list);
return ret;
}
* it should be a copy of the resource entry for the image that is
* marked as bootable. This is not well documented... */
if (hdr.boot_idx == 0) {
- memset(&hdr.boot_metadata_res_entry, 0,
- sizeof(struct resource_entry));
+ zero_resource_entry(&hdr.boot_metadata_res_entry);
} else {
- memcpy(&hdr.boot_metadata_res_entry,
- &w->image_metadata[
- hdr.boot_idx - 1]->metadata_lte->output_resource_entry,
- sizeof(struct resource_entry));
+ copy_resource_entry(&hdr.boot_metadata_res_entry,
+ &w->image_metadata[ hdr.boot_idx- 1
+ ]->metadata_lte->output_resource_entry);
}
if (!(write_flags & WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE)) {
if (write_flags & WIMLIB_WRITE_FLAG_CHECKPOINT_AFTER_XML) {
struct wim_header checkpoint_hdr;
memcpy(&checkpoint_hdr, &hdr, sizeof(struct wim_header));
- memset(&checkpoint_hdr.integrity, 0, sizeof(struct resource_entry));
+ zero_resource_entry(&checkpoint_hdr.integrity);
if (fseeko(out, 0, SEEK_SET)) {
ERROR_WITH_ERRNO("Failed to seek to beginning "
"of WIM being written");
if (ret)
goto out_close_wim;
} else {
- memset(&hdr.integrity, 0, sizeof(struct resource_entry));
+ zero_resource_entry(&hdr.integrity);
}
if (fseeko(out, 0, SEEK_SET) != 0) {
ret = wimlib_write(w, tmpfile, WIMLIB_ALL_IMAGES,
write_flags | WIMLIB_WRITE_FLAG_FSYNC,
num_threads, progress_func);
- if (ret != 0) {
+ if (ret) {
ERROR("Failed to write the WIM file `%"TS"'", tmpfile);
- goto err;
+ goto out_unlink;
}
DEBUG("Renaming `%"TS"' to `%"TS"'", tmpfile, w->filename);
ERROR_WITH_ERRNO("Failed to rename `%"TS"' to `%"TS"'",
tmpfile, w->filename);
ret = WIMLIB_ERR_RENAME;
- goto err;
+ goto out_unlink;
}
if (progress_func) {
FREE(w->filename);
w->filename = NULL;
}
- return ret;
-err:
+ goto out;
+out_unlink:
/* Remove temporary file. */
if (tunlink(tmpfile) != 0)
WARNING_WITH_ERRNO("Failed to remove `%"TS"'", tmpfile);
+out:
return ret;
}