]> wimlib.net Git - wimlib/blobdiff - src/compress.c
mount_image.c: rename create_dentry() to create_file()
[wimlib] / src / compress.c
index aed609aa7aff560a05e11a2021af3fabdb227749..ff28ebc0f79d915701a9fdb0ef68ac47e3fbda8c 100644 (file)
@@ -8,35 +8,32 @@
 /*
  * Copyright (C) 2013, 2014 Eric Biggers
  *
- * This file is part of wimlib, a library for working with WIM files.
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version.
  *
- * wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  * details.
  *
- * You should have received a copy of the GNU General Public License
- * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this file; if not, see http://www.gnu.org/licenses/.
  */
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
 #endif
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "wimlib.h"
-#include "wimlib/assert.h"
 #include "wimlib/error.h"
 #include "wimlib/compressor_ops.h"
 #include "wimlib/util.h"
 
-#include <stdlib.h>
-#include <string.h>
-
 struct wimlib_compressor {
        const struct compressor_ops *ops;
        void *private;
@@ -84,12 +81,19 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
                                    size_t max_block_size,
                                    unsigned int compression_level)
 {
+       bool destructive;
        const struct compressor_ops *ops;
        u64 size;
 
+       destructive = (compression_level & WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE);
+       compression_level &= ~WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE;
+
        if (!compressor_ctype_valid(ctype))
                return 0;
 
+       if (compression_level > 0xFFFFFF)
+               return 0;
+
        if (max_block_size == 0)
                return 0;
 
@@ -101,7 +105,8 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
                compression_level = DEFAULT_COMPRESSION_LEVEL;
 
        if (ops->get_needed_memory) {
-               size = ops->get_needed_memory(max_block_size, compression_level);
+               size = ops->get_needed_memory(max_block_size, compression_level,
+                                             destructive);
 
                /* 0 is never valid and indicates an invalid max_block_size.  */
                if (size == 0)
@@ -118,11 +123,18 @@ wimlib_create_compressor(enum wimlib_compression_type ctype,
                         unsigned int compression_level,
                         struct wimlib_compressor **c_ret)
 {
+       bool destructive;
        struct wimlib_compressor *c;
 
+       destructive = (compression_level & WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE);
+       compression_level &= ~WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE;
+
        if (!compressor_ctype_valid(ctype))
                return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
 
+       if (compression_level > 0xFFFFFF)
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (c_ret == NULL)
                return WIMLIB_ERR_INVALID_PARAM;
 
@@ -146,6 +158,7 @@ wimlib_create_compressor(enum wimlib_compression_type ctype,
 
                ret = c->ops->create_compressor(max_block_size,
                                                compression_level,
+                                               destructive,
                                                &c->private);
                if (ret) {
                        FREE(c);