summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-18 16:09:31 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-18 22:53:32 +0200
commit50385e06ec207af0171c021f1909e9ef38c00519 (patch)
tree690bfe53cef9f901c68f76f4fe50c1917e368fe2
parent58c5d7c933a714096ef0dd42bd1446a6e1a25a16 (diff)
Replace update_crc32 helper function with crc32 from zlib
It is optimized to the maximum and if we already use zlib anyway, why not use zlib crc32? This also makes zlib a hard dependency which also means the whole "do we have a compressor" sanity check in the build system can be removed. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--configure.ac27
-rw-r--r--include/util.h2
-rw-r--r--lib/Makemodule.am7
-rw-r--r--lib/comp/process_block.c3
-rw-r--r--lib/sqfs/data_writer.c3
-rw-r--r--lib/util/crc32.c36
-rw-r--r--tests/Makemodule.am7
-rw-r--r--tests/crc32.c40
8 files changed, 14 insertions, 111 deletions
diff --git a/configure.ac b/configure.ac
index 78ede8f..a13a64c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,10 +42,6 @@ AC_SUBST([WARN_CFLAGS])
##### config options #####
-AC_ARG_WITH([gzip],
- [AS_HELP_STRING([--with-gzip], [Build with gzip compression support])],
- [want_gzip="${withval}"], [want_gzip="maybe"])
-
AC_ARG_WITH([xz],
[AS_HELP_STRING([--with-xz], [Build with xz compression support])],
[want_xz="${withval}"], [want_xz="maybe"])
@@ -69,9 +65,8 @@ AC_ARG_WITH([selinux],
##### search for dependencies #####
-PKG_CHECK_MODULES(ZLIB, [zlib],
- [AM_CONDITIONAL([WITH_GZIP], [true])],
- [AM_CONDITIONAL([WITH_GZIP], [false])])
+AM_CONDITIONAL([WITH_GZIP], [true])
+PKG_CHECK_MODULES(ZLIB, [zlib], [], [AC_MSG_ERROR([cannot find zlib])])
PKG_CHECK_MODULES(XZ, [liblzma >= 5.0.0],
[AM_CONDITIONAL([WITH_XZ], [true])],
@@ -113,11 +108,6 @@ if test "x$want_selinux" != "xno"; then
[AM_CONDITIONAL([WITH_SELINUX], [false])])
fi
-case "$want_gzip" in
-yes) AM_COND_IF([WITH_GZIP], [], [AC_MSG_ERROR([cannot find zlib])]) ;;
-no) AM_CONDITIONAL([WITH_GZIP], [false]) ;;
-esac
-
case "$want_xz" in
yes) AM_COND_IF([WITH_XZ], [], [AC_MSG_ERROR([cannot find xz sdk])]) ;;
no) AM_CONDITIONAL([WITH_XZ], [false]) ;;
@@ -147,19 +137,6 @@ have_pthread="no"
AX_PTHREAD([have_pthread="yes"], [])
AM_CONDITIONAL([HAVE_PTHREAD], [test "x$have_pthread" != "xno"])
-##### sanity check #####
-
-have_compressor="no"
-AM_COND_IF([WITH_GZIP], [have_compressor="yes"])
-AM_COND_IF([WITH_XZ], [have_compressor="yes"])
-AM_COND_IF([WITH_LZO], [have_compressor="yes"])
-AM_COND_IF([WITH_LZ4], [have_compressor="yes"])
-AM_COND_IF([WITH_ZSTD], [have_compressor="yes"])
-
-if test "x$have_compressor" != "xyes"; then
- AC_MSG_ERROR([no compressor available. At lest one is required])
-fi
-
##### additional checks #####
AX_COMPILE_CHECK_SIZEOF(time_t)
diff --git a/include/util.h b/include/util.h
index 82e3177..99418f9 100644
--- a/include/util.h
+++ b/include/util.h
@@ -81,8 +81,6 @@ int popd(void);
*/
int padd_file(int outfd, uint64_t size, size_t blocksize);
-uint32_t update_crc32(uint32_t crc, const void *data, size_t size);
-
/*
If the environment variable SOURCE_DATE_EPOCH is set to a parsable number
that fits into an unsigned 32 bit value, return its value. Otherwise,
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index 3c206d6..6301435 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -47,8 +47,10 @@ libutil_a_SOURCES += lib/util/read_data.c include/util.h
libutil_a_SOURCES += lib/util/print_version.c lib/util/mkdir_p.c
libutil_a_SOURCES += lib/util/str_table.c include/str_table.h
libutil_a_SOURCES += lib/util/dirstack.c lib/util/padd_file.c
-libutil_a_SOURCES += lib/util/read_data_at.c lib/util/crc32.c
+libutil_a_SOURCES += lib/util/read_data_at.c
libutil_a_SOURCES += lib/util/source_date_epoch.c
+libutil_a_CFLAGS = $(AM_CFLAGS)
+libutil_a_CPPFLAGS = $(AM_CPPFLAGS)
if HAVE_PTHREAD
libcompress_a_SOURCES += lib/comp/block_processor_parallel.c
@@ -62,6 +64,9 @@ libcompress_a_SOURCES += lib/comp/gzip.c
libcompress_a_CFLAGS += $(ZLIB_CFLAGS)
libcompress_a_CPPFLAGS += -DWITH_GZIP
+
+libutil_a_CFLAGS += $(ZLIB_CFLAGS)
+libutil_a_CPPFLAGS += -DWITH_GZIP
endif
if WITH_XZ
diff --git a/lib/comp/process_block.c b/lib/comp/process_block.c
index 76cd07d..0fcbae0 100644
--- a/lib/comp/process_block.c
+++ b/lib/comp/process_block.c
@@ -10,6 +10,7 @@
#include "util.h"
#include <string.h>
+#include <zlib.h>
int process_block(block_t *block, compressor_t *cmp,
uint8_t *scratch, size_t scratch_size)
@@ -17,7 +18,7 @@ int process_block(block_t *block, compressor_t *cmp,
ssize_t ret;
if (!(block->flags & BLK_DONT_CHECKSUM))
- block->checksum = update_crc32(0, block->data, block->size);
+ block->checksum = crc32(0, block->data, block->size);
if (!(block->flags & BLK_DONT_COMPRESS)) {
ret = cmp->do_block(cmp, block->data, block->size,
diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c
index 55c92ad..c584f1e 100644
--- a/lib/sqfs/data_writer.c
+++ b/lib/sqfs/data_writer.c
@@ -16,6 +16,7 @@
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
+#include <zlib.h>
struct data_writer_t {
block_t *frag_block;
@@ -229,7 +230,7 @@ static int handle_fragment(data_writer_t *data, block_t *blk)
{
file_info_t *fi = blk->user, *ref;
- fi->fragment_chksum = update_crc32(0, blk->data, blk->size);
+ fi->fragment_chksum = crc32(0, blk->data, blk->size);
ref = fragment_by_chksum(fi, fi->fragment_chksum, blk->size,
data->list, data->super->block_size);
diff --git a/lib/util/crc32.c b/lib/util/crc32.c
deleted file mode 100644
index 27c5b85..0000000
--- a/lib/util/crc32.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * crc32.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "util.h"
-
-/*
- Karl Malbrain's compact CRC-32. See "A compact CCITT crc16 and crc32 C
- implementation that balances processor cache usage against speed"
- */
-static const uint32_t s_crc32[16] = {
- 0x00000000, 0x1DB71064, 0x3B6E20C8, 0x26D930AC,
- 0x76DC4190, 0x6B6B51F4, 0x4DB26158, 0x5005713C,
- 0xEDB88320, 0xF00F9344, 0xD6D6A3E8, 0xCB61B38C,
- 0x9B64C2B0, 0x86D3D2D4, 0xA00AE278, 0xBDBDF21C
-};
-
-uint32_t update_crc32(uint32_t crc, const void *data, size_t size)
-{
- const uint8_t *ptr = data;
- uint8_t b;
-
- crc = ~crc;
-
- while (size--) {
- b = *ptr++;
-
- crc = (crc >> 4) ^ s_crc32[(crc & 0x0F) ^ (b & 0x0F)];
- crc = (crc >> 4) ^ s_crc32[(crc & 0x0F) ^ (b >> 4)];
- }
-
- return ~crc;
-}
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index e681a33..60312dc 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -73,15 +73,12 @@ test_str_table_SOURCES = tests/str_table.c
test_str_table_LDADD = libutil.a
test_str_table_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests
-test_crc32_SOURCES = tests/crc32.c
-test_crc32_LDADD = libutil.a
-
check_PROGRAMS += test_canonicalize_name test_mknode_simple test_mknode_slink
check_PROGRAMS += test_mknode_reg test_mknode_dir test_gen_inode_table
check_PROGRAMS += test_add_by_path test_get_path test_fstree_sort
check_PROGRAMS += test_fstree_from_file test_fstree_init test_fstree_xattr
check_PROGRAMS += test_tar_ustar test_tar_pax test_tar_gnu test_tar_sparse_gnu
-check_PROGRAMS += test_tar_sparse_gnu1 test_tar_sparse_gnu2 test_crc32
+check_PROGRAMS += test_tar_sparse_gnu1 test_tar_sparse_gnu2
check_PROGRAMS += test_tar_xattr_bsd test_tar_xattr_schily test_str_table
TESTS += test_canonicalize_name test_mknode_simple test_mknode_slink
@@ -90,6 +87,6 @@ TESTS += test_add_by_path test_get_path test_fstree_sort test_fstree_from_file
TESTS += test_fstree_init test_fstree_xattr test_tar_ustar test_tar_pax
TESTS += test_tar_gnu test_tar_sparse_gnu test_tar_sparse_gnu1
TESTS += test_tar_sparse_gnu2 test_tar_xattr_bsd test_tar_xattr_schily
-TESTS += test_str_table test_crc32
+TESTS += test_str_table
EXTRA_DIST += $(top_srcdir)/tests/tar $(top_srcdir)/tests/words.txt
diff --git a/tests/crc32.c b/tests/crc32.c
deleted file mode 100644
index 669c6a4..0000000
--- a/tests/crc32.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * crc32.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "config.h"
-#include "util.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-static const struct {
- const char *str;
- uint32_t result;
-} test_vectors[] = {
- { "", 0 },
- { "Hello, World!", 0xEC4AC3D0 },
- { "The quick brown fox jumps over the lazy dog", 0x414FA339 },
-};
-
-int main(void)
-{
- uint32_t crc;
- size_t i;
-
- for (i = 0; i < sizeof(test_vectors) / sizeof(test_vectors[0]); ++i) {
- crc = update_crc32(0, test_vectors[i].str,
- strlen(test_vectors[i].str));
-
- if (crc != test_vectors[i].result) {
- fprintf(stderr, "Case %zu failed: %08X != %08X\n", i,
- crc, test_vectors[i].result);
- return EXIT_FAILURE;
- }
- }
-
- return EXIT_SUCCESS;
-}