]> wimlib.net Git - wimlib/blobdiff - src/write.c
Merge LZX compressor updates
[wimlib] / src / write.c
index 0639fd76a0e6385ebb0c2eac1ebca77d18c1c267..ca5a230ee19938512eac02c7f948de73e74e95fc 100644 (file)
 #  include <sys/uio.h> /* for `struct iovec' */
 #endif
 
-static int
-alloc_lzx_context(int write_resource_flags, struct wimlib_lzx_context **ctx_pp)
-{
-       struct wimlib_lzx_params params;
-       params.size_of_this = sizeof(params);
-       if (write_resource_flags & WIMLIB_WRITE_RESOURCE_FLAG_COMPRESS_SLOW)
-               params.algorithm = WIMLIB_LZX_ALGORITHM_SLOW;
-       else
-               params.algorithm = WIMLIB_LZX_ALGORITHM_FAST;
-       params.use_defaults = 1;
-       return wimlib_lzx_alloc_context(&params, ctx_pp);
-}
-
 static unsigned
 compress_chunk(const void * uncompressed_data,
               unsigned uncompressed_len,
@@ -378,11 +365,13 @@ error:
  * @resource_flags:
  *     * WIMLIB_WRITE_RESOURCE_FLAG_RECOMPRESS to force data to be recompressed even
  *       if it could otherwise be copied directly from the input;
- *     * WIMLIB_WRITE_RESOURCE_FLAG_COMPRESS_SLOW to compress the data as much
- *       as possible;
  *     * WIMLIB_WRITE_RESOURCE_FLAG_PIPABLE if writing a resource for a pipable WIM
  *       (and the output file descriptor may be a pipe).
  *
+ * @comp_ctx:
+ *     Location of LZX compression context pointer, which will be allocated or
+ *     updated if needed.  (Initialize to NULL.)
+ *
  * Additional notes:  The SHA1 message digest of the uncompressed data is
  * calculated (except when doing a raw copy --- see below).  If the @unhashed
  * flag is set on the lookup table entry, this message digest is simply copied
@@ -448,7 +437,7 @@ write_wim_resource(struct wim_lookup_table_entry *lte,
                if (!(resource_flags & WIMLIB_READ_RESOURCE_FLAG_RAW)) {
                        write_ctx.out_ctype = out_ctype;
                        if (out_ctype == WIMLIB_COMPRESSION_TYPE_LZX) {
-                               ret = alloc_lzx_context(resource_flags, comp_ctx);
+                               ret = wimlib_lzx_alloc_context(NULL, comp_ctx);
                                if (ret)
                                        goto out;
                        }
@@ -946,8 +935,6 @@ write_flags_to_resource_flags(int write_flags)
 
        if (write_flags & WIMLIB_WRITE_FLAG_RECOMPRESS)
                resource_flags |= WIMLIB_WRITE_RESOURCE_FLAG_RECOMPRESS;
-       if (write_flags & WIMLIB_WRITE_FLAG_COMPRESS_SLOW)
-               resource_flags |= WIMLIB_WRITE_RESOURCE_FLAG_COMPRESS_SLOW;
        if (write_flags & WIMLIB_WRITE_FLAG_PIPABLE)
                resource_flags |= WIMLIB_WRITE_RESOURCE_FLAG_PIPABLE;
        return resource_flags;
@@ -1536,8 +1523,7 @@ write_stream_list_parallel(struct list_head *stream_list,
                params[i].compressed_res_queue = &compressed_res_queue;
                params[i].out_ctype = out_ctype;
                if (out_ctype == WIMLIB_COMPRESSION_TYPE_LZX) {
-                       ret = alloc_lzx_context(write_resource_flags,
-                                               &params[i].comp_ctx);
+                       ret = wimlib_lzx_alloc_context(NULL, &params[i].comp_ctx);
                        if (ret)
                                goto out_free_params;
                }
@@ -2136,10 +2122,12 @@ close_wim_writable(WIMStruct *wim, int write_flags)
 {
        int ret = 0;
 
-       if (!(write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR))
+       if (!(write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR)) {
+               DEBUG("Closing WIM file.");
                if (filedes_valid(&wim->out_fd))
                        if (filedes_close(&wim->out_fd))
                                ret = WIMLIB_ERR_WRITE;
+       }
        filedes_invalidate(&wim->out_fd);
        return ret;
 }
@@ -2202,6 +2190,8 @@ finish_write(WIMStruct *wim, int image, int write_flags,
        off_t new_lookup_table_end;
        u64 xml_totalbytes;
 
+       DEBUG("image=%d, write_flags=%08x", image, write_flags);
+
        write_resource_flags = write_flags_to_resource_flags(write_flags);
 
        /* In the WIM header, there is room for the resource entry for a
@@ -2276,6 +2266,7 @@ finish_write(WIMStruct *wim, int image, int write_flags,
        hdr_offset = 0;
        if (write_flags & WIMLIB_WRITE_FLAG_HEADER_AT_END)
                hdr_offset = wim->out_fd.offset;
+       DEBUG("Writing new header @ %"PRIu64".", hdr_offset);
        ret = write_wim_header_at_offset(&wim->hdr, &wim->out_fd, hdr_offset);
        if (ret)
                return ret;
@@ -2287,6 +2278,7 @@ finish_write(WIMStruct *wim, int image, int write_flags,
         * operation has been written to disk, but the new file data has not.
         */
        if (write_flags & WIMLIB_WRITE_FLAG_FSYNC) {
+               DEBUG("Syncing WIM file.");
                if (fsync(wim->out_fd.fd)) {
                        ERROR_WITH_ERRNO("Error syncing data to WIM file");
                        return WIMLIB_ERR_WRITE;
@@ -2683,6 +2675,7 @@ write_wim_part(WIMStruct *wim,
 out_restore_hdr:
        memcpy(&wim->hdr, &hdr_save, sizeof(struct wim_header));
        (void)close_wim_writable(wim, write_flags);
+       DEBUG("ret=%d", ret);
        return ret;
 }