From 2087cc237cd0fe1ed29ebf891648bacb46f4833b Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 26 Jun 2022 16:45:52 +0200 Subject: Cleanup: move libutil headers to sub directory Move all the libutil stuff from the toplevel include/ to a util/ sub directory and fix up the includes that make use of them. Signed-off-by: David Oberhollenzer --- COPYING.md | 2 +- include/array.h | 79 ----------------------- include/hash_table.h | 92 -------------------------- include/mempool.h | 31 --------- include/rbtree.h | 74 --------------------- include/str_table.h | 63 ------------------ include/threadpool.h | 125 ------------------------------------ include/util.h | 38 ----------- include/util/array.h | 79 +++++++++++++++++++++++ include/util/hash_table.h | 92 ++++++++++++++++++++++++++ include/util/mempool.h | 31 +++++++++ include/util/rbtree.h | 74 +++++++++++++++++++++ include/util/str_table.h | 63 ++++++++++++++++++ include/util/threadpool.h | 125 ++++++++++++++++++++++++++++++++++++ include/util/util.h | 38 +++++++++++ include/util/w32threadwrap.h | 105 ++++++++++++++++++++++++++++++ include/w32threadwrap.h | 105 ------------------------------ lib/common/hardlink.c | 2 +- lib/sqfs/Makemodule.am | 10 +-- lib/sqfs/block_processor/internal.h | 6 +- lib/sqfs/block_writer.c | 2 +- lib/sqfs/comp/internal.h | 2 +- lib/sqfs/data_reader.c | 2 +- lib/sqfs/dir_reader/internal.h | 4 +- lib/sqfs/dir_writer.c | 4 +- lib/sqfs/frag_table.c | 2 +- lib/sqfs/id_table.c | 2 +- lib/sqfs/inode.c | 2 +- lib/sqfs/meta_reader.c | 2 +- lib/sqfs/meta_writer.c | 2 +- lib/sqfs/read_inode.c | 2 +- lib/sqfs/read_super.c | 2 +- lib/sqfs/read_table.c | 2 +- lib/sqfs/write_table.c | 2 +- lib/sqfs/xattr/xattr_reader.c | 2 +- lib/sqfs/xattr/xattr_writer.h | 8 +-- lib/util/Makemodule.am | 13 ++-- lib/util/alloc.c | 2 +- lib/util/array.c | 2 +- lib/util/hash_table.c | 2 +- lib/util/is_memory_zero.c | 2 +- lib/util/mempool.c | 2 +- lib/util/rbtree.c | 2 +- lib/util/str_table.c | 4 +- lib/util/threadpool.c | 6 +- lib/util/threadpool_serial.c | 4 +- lib/util/xxhash.c | 2 +- tests/libutil/is_memory_zero.c | 2 +- tests/libutil/rbtree.c | 2 +- tests/libutil/str_table.c | 2 +- tests/libutil/threadpool.c | 2 +- tests/libutil/xxhash.c | 2 +- 52 files changed, 664 insertions(+), 663 deletions(-) delete mode 100644 include/array.h delete mode 100644 include/hash_table.h delete mode 100644 include/mempool.h delete mode 100644 include/rbtree.h delete mode 100644 include/str_table.h delete mode 100644 include/threadpool.h delete mode 100644 include/util.h create mode 100644 include/util/array.h create mode 100644 include/util/hash_table.h create mode 100644 include/util/mempool.h create mode 100644 include/util/rbtree.h create mode 100644 include/util/str_table.h create mode 100644 include/util/threadpool.h create mode 100644 include/util/util.h create mode 100644 include/util/w32threadwrap.h delete mode 100644 include/w32threadwrap.h diff --git a/COPYING.md b/COPYING.md index ff98c72..574aad6 100644 --- a/COPYING.md +++ b/COPYING.md @@ -11,7 +11,7 @@ with the following exceptions: - `lib/lz4` contains files extracted from the LZ4 compression library. See `lib/lz4/README` for details and `licenses/LZ4.txt` for copyright and licensing information (2 clause BSD license). - - `lib/util/hash_table.c`, `include/hash_table.h` and + - `lib/util/hash_table.c`, `include/util/hash_table.h` and `lib/util/fast_urem_by_const.h` contain a hash table implementation (MIT license). See `licenses/hash_table.txt` for details. diff --git a/include/array.h b/include/array.h deleted file mode 100644 index cbac7c2..0000000 --- a/include/array.h +++ /dev/null @@ -1,79 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * array.h - * - * Copyright (C) 2021 David Oberhollenzer - */ -#ifndef ARRAY_H -#define ARRAY_H - -#include "sqfs/predef.h" -#include "sqfs/error.h" - -#include -#include -#include - -typedef struct { - /* sizeof a single element */ - size_t size; - - /* total number of elements available */ - size_t count; - - /* actually used number of elements available */ - size_t used; - - void *data; -} array_t; - -static SQFS_INLINE void *array_get(array_t *array, size_t index) -{ - if (index >= array->used) - return NULL; - - return (char *)array->data + array->size * index; -} - -static SQFS_INLINE int array_set(array_t *array, size_t index, const void *data) -{ - if (index >= array->used) - return SQFS_ERROR_OUT_OF_BOUNDS; - - memcpy((char *)array->data + array->size * index, data, array->size); - return 0; -} - -static SQFS_INLINE void array_sort_range(array_t *array, size_t start, - size_t count, - int (*compare_fun)(const void *a, - const void *b)) -{ - if (start < array->used) { - if (count > (array->used - start)) - count = array->used - start; - - qsort((char *)array->data + array->size * start, count, - array->size, compare_fun); - } -} - -#ifdef __cplusplus -extern "C" { -#endif - -SQFS_INTERNAL int array_init(array_t *array, size_t size, size_t capacity); - -SQFS_INTERNAL int array_init_copy(array_t *array, const array_t *src); - -SQFS_INTERNAL void array_cleanup(array_t *array); - -SQFS_INTERNAL int array_append(array_t *array, const void *data); - -SQFS_INTERNAL int array_set_capacity(array_t *array, size_t capacity); - -#ifdef __cplusplus -} -#endif - -#endif /* ARRAY_H */ diff --git a/include/hash_table.h b/include/hash_table.h deleted file mode 100644 index 813e059..0000000 --- a/include/hash_table.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright © 2009,2012 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - * Authors: - * Eric Anholt - * - */ - -#ifndef _HASH_TABLE_H -#define _HASH_TABLE_H - -#include -#include -#include - -#include "sqfs/predef.h" - -struct hash_entry { - sqfs_u32 hash; - const void *key; - void *data; -}; - -struct hash_table { - struct hash_entry *table; - sqfs_u32 (*key_hash_function)(void *user, const void *key); - bool (*key_equals_function)(void *user, const void *a, const void *b); - const void *deleted_key; - void *user; - sqfs_u32 size; - sqfs_u32 rehash; - sqfs_u64 size_magic; - sqfs_u64 rehash_magic; - sqfs_u32 max_entries; - sqfs_u32 size_index; - sqfs_u32 entries; - sqfs_u32 deleted_entries; -}; - -SQFS_INTERNAL struct hash_table * -hash_table_create(sqfs_u32 (*key_hash_function)(void *user, const void *key), - bool (*key_equals_function)(void *user, const void *a, - const void *b)); - -SQFS_INTERNAL struct hash_table * -hash_table_clone(struct hash_table *src); - -SQFS_INTERNAL void -hash_table_destroy(struct hash_table *ht, - void (*delete_function)(struct hash_entry *entry)); - -SQFS_INTERNAL struct hash_entry * -hash_table_insert_pre_hashed(struct hash_table *ht, sqfs_u32 hash, - const void *key, void *data); - -SQFS_INTERNAL struct hash_entry * -hash_table_search_pre_hashed(struct hash_table *ht, sqfs_u32 hash, - const void *key); - -SQFS_INTERNAL struct hash_entry *hash_table_next_entry(struct hash_table *ht, - struct hash_entry *entry); - -/** - * This foreach function is safe against deletion (which just replaces - * an entry's data with the deleted marker), but not against insertion - * (which may rehash the table, making entry a dangling pointer). - */ -#define hash_table_foreach(ht, entry) \ - for (struct hash_entry *entry = hash_table_next_entry(ht, NULL); \ - entry != NULL; \ - entry = hash_table_next_entry(ht, entry)) - -#endif /* _HASH_TABLE_H */ diff --git a/include/mempool.h b/include/mempool.h deleted file mode 100644 index c946c31..0000000 --- a/include/mempool.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * mempool.h - * - * Copyright (C) 2021 David Oberhollenzer - */ -#ifndef MEMPOOL_H -#define MEMPOOL_H - -#include "compat.h" -#include "sqfs/predef.h" - -typedef struct mem_pool_t mem_pool_t; - -#ifdef __cplusplus -extern "C" { -#endif - -SQFS_INTERNAL mem_pool_t *mem_pool_create(size_t obj_size); - -SQFS_INTERNAL void mem_pool_destroy(mem_pool_t *mem); - -SQFS_INTERNAL void *mem_pool_allocate(mem_pool_t *mem); - -SQFS_INTERNAL void mem_pool_free(mem_pool_t *mem, void *ptr); - -#ifdef __cplusplus -} -#endif - -#endif /* MEMPOOL_H */ diff --git a/include/rbtree.h b/include/rbtree.h deleted file mode 100644 index aac175b..0000000 --- a/include/rbtree.h +++ /dev/null @@ -1,74 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * rbtree.h - * - * Copyright (C) 2019 David Oberhollenzer - */ -#ifndef SQFS_RBTREE_H -#define SQFS_RBTREE_H - -#include "config.h" -#include "sqfs/predef.h" -#include "mempool.h" -#include "compat.h" - -#include - -typedef struct rbtree_node_t { - struct rbtree_node_t *left; - struct rbtree_node_t *right; - sqfs_u32 value_offset; - sqfs_u32 is_red : 1; - sqfs_u32 pad0 : 31; - - sqfs_u8 data[]; -} rbtree_node_t; - -typedef struct rbtree_t { - rbtree_node_t *root; - -#ifndef NO_CUSTOM_ALLOC - mem_pool_t *pool; -#endif - - int (*key_compare)(const void *ctx, - const void *lhs, const void *hrs); - - size_t key_size; - size_t key_size_padded; - - size_t value_size; - - void *key_context; -} rbtree_t; - -static SQFS_INLINE void *rbtree_node_key(rbtree_node_t *n) -{ - return n->data; -} - -static SQFS_INLINE void *rbtree_node_value(rbtree_node_t *n) -{ - return n->data + n->value_offset; -} - -SQFS_INTERNAL int rbtree_init(rbtree_t *tree, size_t keysize, size_t valuesize, - int(*key_compare)(const void *, const void *, - const void *)); - -SQFS_INTERNAL void rbtree_cleanup(rbtree_t *tree); - -SQFS_INTERNAL int rbtree_copy(const rbtree_t *tree, rbtree_t *out); - -SQFS_INTERNAL int rbtree_insert(rbtree_t *tree, const void *key, - const void *value); - -SQFS_INTERNAL rbtree_node_t *rbtree_lookup(const rbtree_t *tree, - const void *key); - -#ifdef __cplusplus -} -#endif - -#endif /* TOOLS_RBTREE_H */ - diff --git a/include/str_table.h b/include/str_table.h deleted file mode 100644 index 206fa3a..0000000 --- a/include/str_table.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * str_table.h - * - * Copyright (C) 2019 David Oberhollenzer - */ -#ifndef STR_TABLE_H -#define STR_TABLE_H - -#include "sqfs/predef.h" -#include "array.h" -#include "hash_table.h" - -typedef struct { - size_t index; - size_t refcount; - char string[]; -} str_bucket_t; - -/* Stores strings in a hash table and assigns an incremental, unique ID to - each string. Subsequent additions return the existing ID. The ID can be - used for (hopefully) constant time lookup of the original string. */ -typedef struct { - /* an array that resolves index to bucket pointer */ - array_t bucket_ptrs; - - /* hash table with the string buckets attached */ - struct hash_table *ht; - - /* the next ID we are going to allocate */ - size_t next_index; -} str_table_t; - -/* the number of strings currently stored in the table */ -static SQFS_INLINE size_t str_table_count(const str_table_t *table) -{ - return table->next_index; -} - -/* `size` is the number of hash table buckets to use internally. */ -SQFS_INTERNAL int str_table_init(str_table_t *table); - -SQFS_INTERNAL void str_table_cleanup(str_table_t *table); - -SQFS_INTERNAL int str_table_copy(str_table_t *dst, const str_table_t *src); - -/* Resolve a string to an incremental, unique ID. */ -SQFS_INTERNAL -int str_table_get_index(str_table_t *table, const char *str, size_t *idx); - -/* Resolve a unique ID to the string it represents. - Returns NULL if the ID is unknown, i.e. out of bounds. */ -SQFS_INTERNAL -const char *str_table_get_string(const str_table_t *table, size_t index); - -SQFS_INTERNAL void str_table_add_ref(str_table_t *table, size_t index); - -SQFS_INTERNAL void str_table_del_ref(str_table_t *table, size_t index); - -SQFS_INTERNAL -size_t str_table_get_ref_count(const str_table_t *table, size_t index); - -#endif /* STR_TABLE_H */ diff --git a/include/threadpool.h b/include/threadpool.h deleted file mode 100644 index f25c497..0000000 --- a/include/threadpool.h +++ /dev/null @@ -1,125 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * threadpool.h - * - * Copyright (C) 2021 David Oberhollenzer - */ -#ifndef THREADPOOL_H -#define THREADPOOL_H - -#include "sqfs/predef.h" - -typedef int (*thread_pool_worker_t)(void *user, void *work_item); - -/** - * @struct thread_pool_t - * - * @brief A thread pool with a ticket number based work item ordering. - * - * While the order in which items are non-deterministic, the thread pool - * implementation internally uses a ticket system to ensure the completed - * items are deqeueued in the same order that they were enqueued. - */ -typedef struct thread_pool_t { - /** - * @brief Shutdown and destroy a thread pool. - * - * @param pool A pointer to a pool returned by thread_pool_create - */ - void (*destroy)(struct thread_pool_t *pool); - - /** - * @brief Get the actual number of worker threads available. - * - * @return A number greater or equal to 1. - */ - size_t (*get_worker_count)(struct thread_pool_t *pool); - - /** - * @brief Change the user data pointer for a thread pool worker - * by index. - * - * @param idx A zero-based index into the worker list. - * @param ptr A user pointer that this specific worker thread should - * pass to the worker callback. - */ - void (*set_worker_ptr)(struct thread_pool_t *pool, size_t idx, - void *ptr); - - /** - * @brief Submit a work item to a thread pool. - * - * This function will fail on allocation failure or if the internal - * error state is set was set by one of the workers. - * - * @param ptr A pointer to a work object to enqueue. - * - * @return Zero on success. - */ - int (*submit)(struct thread_pool_t *pool, void *ptr); - - /** - * @brief Wait for a work item to be completed. - * - * This function dequeues a single completed work item. It may block - * until one of the worker threads signals completion of an additional - * item. - * - * This function guarantees to return the items in the same order as - * they were submitted, so the function can actually block longer than - * necessary, because it has to wait until the next item in sequence - * is finished. - * - * @return A pointer to a new work item or NULL if there are none - * in the pipeline. - */ - void *(*dequeue)(struct thread_pool_t *pool); - - /** - * @brief Get the internal worker return status value. - * - * If the worker functions returns a non-zero exit status in one of the - * worker threads, the thread pool stors the value internally and shuts - * down. This function can be used to retrieve the value. - * - * @return A non-zero value returned by the worker callback or zero if - * everything is A-OK. - */ - int (*get_status)(struct thread_pool_t *pool); -} thread_pool_t; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Create a thread pool instance. - * - * @param num_jobs The number of worker threads to launch. - * @param worker A function to call from the worker threads to process - * the work items. - * - * @return A pointer to a thread pool on success, NULL on failure. - */ -SQFS_INTERNAL thread_pool_t *thread_pool_create(size_t num_jobs, - thread_pool_worker_t worker); - -/** - * @brief Create a serial mockup thread pool implementation. - * - * This returns a @ref thread_pool_t implementation that, instead of running a - * thread pool actually does the work in-situ when dequeueing. - * - * @param worker A function to call from the worker threads to process - * the work items. - * - * @return A pointer to a thread pool on success, NULL on failure. - */ -SQFS_INTERNAL -thread_pool_t *thread_pool_create_serial(thread_pool_worker_t worker); - -#ifdef __cplusplus -} -#endif - -#endif /* THREADPOOL_H */ diff --git a/include/util.h b/include/util.h deleted file mode 100644 index 4b05340..0000000 --- a/include/util.h +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * util.h - * - * Copyright (C) 2019 David Oberhollenzer - */ -#ifndef SQFS_UTIL_H -#define SQFS_UTIL_H - -#include "config.h" -#include "sqfs/predef.h" -#include "compat.h" - -#include - -/* - Helper for allocating data structures with flexible array members. - - 'base_size' is the size of the struct itself, 'item_size' the size of a - single array element and 'nmemb' the number of elements. - - Iternally checks for arithmetic overflows when allocating the combined thing. - */ -SQFS_INTERNAL -void *alloc_flex(size_t base_size, size_t item_size, size_t nmemb); - -/* Basically the same as calloc, but *ALWAYS* does overflow checking */ -SQFS_INTERNAL -void *alloc_array(size_t item_size, size_t nmemb); - -SQFS_INTERNAL sqfs_u32 xxh32(const void *input, const size_t len); - -/* - Returns true if the given region of memory is filled with zero-bytes only. - */ -SQFS_INTERNAL bool is_memory_zero(const void *blob, size_t size); - -#endif /* SQFS_UTIL_H */ diff --git a/include/util/array.h b/include/util/array.h new file mode 100644 index 0000000..cbac7c2 --- /dev/null +++ b/include/util/array.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * array.h + * + * Copyright (C) 2021 David Oberhollenzer + */ +#ifndef ARRAY_H +#define ARRAY_H + +#include "sqfs/predef.h" +#include "sqfs/error.h" + +#include +#include +#include + +typedef struct { + /* sizeof a single element */ + size_t size; + + /* total number of elements available */ + size_t count; + + /* actually used number of elements available */ + size_t used; + + void *data; +} array_t; + +static SQFS_INLINE void *array_get(array_t *array, size_t index) +{ + if (index >= array->used) + return NULL; + + return (char *)array->data + array->size * index; +} + +static SQFS_INLINE int array_set(array_t *array, size_t index, const void *data) +{ + if (index >= array->used) + return SQFS_ERROR_OUT_OF_BOUNDS; + + memcpy((char *)array->data + array->size * index, data, array->size); + return 0; +} + +static SQFS_INLINE void array_sort_range(array_t *array, size_t start, + size_t count, + int (*compare_fun)(const void *a, + const void *b)) +{ + if (start < array->used) { + if (count > (array->used - start)) + count = array->used - start; + + qsort((char *)array->data + array->size * start, count, + array->size, compare_fun); + } +} + +#ifdef __cplusplus +extern "C" { +#endif + +SQFS_INTERNAL int array_init(array_t *array, size_t size, size_t capacity); + +SQFS_INTERNAL int array_init_copy(array_t *array, const array_t *src); + +SQFS_INTERNAL void array_cleanup(array_t *array); + +SQFS_INTERNAL int array_append(array_t *array, const void *data); + +SQFS_INTERNAL int array_set_capacity(array_t *array, size_t capacity); + +#ifdef __cplusplus +} +#endif + +#endif /* ARRAY_H */ diff --git a/include/util/hash_table.h b/include/util/hash_table.h new file mode 100644 index 0000000..813e059 --- /dev/null +++ b/include/util/hash_table.h @@ -0,0 +1,92 @@ +/* + * Copyright © 2009,2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt + * + */ + +#ifndef _HASH_TABLE_H +#define _HASH_TABLE_H + +#include +#include +#include + +#include "sqfs/predef.h" + +struct hash_entry { + sqfs_u32 hash; + const void *key; + void *data; +}; + +struct hash_table { + struct hash_entry *table; + sqfs_u32 (*key_hash_function)(void *user, const void *key); + bool (*key_equals_function)(void *user, const void *a, const void *b); + const void *deleted_key; + void *user; + sqfs_u32 size; + sqfs_u32 rehash; + sqfs_u64 size_magic; + sqfs_u64 rehash_magic; + sqfs_u32 max_entries; + sqfs_u32 size_index; + sqfs_u32 entries; + sqfs_u32 deleted_entries; +}; + +SQFS_INTERNAL struct hash_table * +hash_table_create(sqfs_u32 (*key_hash_function)(void *user, const void *key), + bool (*key_equals_function)(void *user, const void *a, + const void *b)); + +SQFS_INTERNAL struct hash_table * +hash_table_clone(struct hash_table *src); + +SQFS_INTERNAL void +hash_table_destroy(struct hash_table *ht, + void (*delete_function)(struct hash_entry *entry)); + +SQFS_INTERNAL struct hash_entry * +hash_table_insert_pre_hashed(struct hash_table *ht, sqfs_u32 hash, + const void *key, void *data); + +SQFS_INTERNAL struct hash_entry * +hash_table_search_pre_hashed(struct hash_table *ht, sqfs_u32 hash, + const void *key); + +SQFS_INTERNAL struct hash_entry *hash_table_next_entry(struct hash_table *ht, + struct hash_entry *entry); + +/** + * This foreach function is safe against deletion (which just replaces + * an entry's data with the deleted marker), but not against insertion + * (which may rehash the table, making entry a dangling pointer). + */ +#define hash_table_foreach(ht, entry) \ + for (struct hash_entry *entry = hash_table_next_entry(ht, NULL); \ + entry != NULL; \ + entry = hash_table_next_entry(ht, entry)) + +#endif /* _HASH_TABLE_H */ diff --git a/include/util/mempool.h b/include/util/mempool.h new file mode 100644 index 0000000..c946c31 --- /dev/null +++ b/include/util/mempool.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * mempool.h + * + * Copyright (C) 2021 David Oberhollenzer + */ +#ifndef MEMPOOL_H +#define MEMPOOL_H + +#include "compat.h" +#include "sqfs/predef.h" + +typedef struct mem_pool_t mem_pool_t; + +#ifdef __cplusplus +extern "C" { +#endif + +SQFS_INTERNAL mem_pool_t *mem_pool_create(size_t obj_size); + +SQFS_INTERNAL void mem_pool_destroy(mem_pool_t *mem); + +SQFS_INTERNAL void *mem_pool_allocate(mem_pool_t *mem); + +SQFS_INTERNAL void mem_pool_free(mem_pool_t *mem, void *ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* MEMPOOL_H */ diff --git a/include/util/rbtree.h b/include/util/rbtree.h new file mode 100644 index 0000000..aac175b --- /dev/null +++ b/include/util/rbtree.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * rbtree.h + * + * Copyright (C) 2019 David Oberhollenzer + */ +#ifndef SQFS_RBTREE_H +#define SQFS_RBTREE_H + +#include "config.h" +#include "sqfs/predef.h" +#include "mempool.h" +#include "compat.h" + +#include + +typedef struct rbtree_node_t { + struct rbtree_node_t *left; + struct rbtree_node_t *right; + sqfs_u32 value_offset; + sqfs_u32 is_red : 1; + sqfs_u32 pad0 : 31; + + sqfs_u8 data[]; +} rbtree_node_t; + +typedef struct rbtree_t { + rbtree_node_t *root; + +#ifndef NO_CUSTOM_ALLOC + mem_pool_t *pool; +#endif + + int (*key_compare)(const void *ctx, + const void *lhs, const void *hrs); + + size_t key_size; + size_t key_size_padded; + + size_t value_size; + + void *key_context; +} rbtree_t; + +static SQFS_INLINE void *rbtree_node_key(rbtree_node_t *n) +{ + return n->data; +} + +static SQFS_INLINE void *rbtree_node_value(rbtree_node_t *n) +{ + return n->data + n->value_offset; +} + +SQFS_INTERNAL int rbtree_init(rbtree_t *tree, size_t keysize, size_t valuesize, + int(*key_compare)(const void *, const void *, + const void *)); + +SQFS_INTERNAL void rbtree_cleanup(rbtree_t *tree); + +SQFS_INTERNAL int rbtree_copy(const rbtree_t *tree, rbtree_t *out); + +SQFS_INTERNAL int rbtree_insert(rbtree_t *tree, const void *key, + const void *value); + +SQFS_INTERNAL rbtree_node_t *rbtree_lookup(const rbtree_t *tree, + const void *key); + +#ifdef __cplusplus +} +#endif + +#endif /* TOOLS_RBTREE_H */ + diff --git a/include/util/str_table.h b/include/util/str_table.h new file mode 100644 index 0000000..206fa3a --- /dev/null +++ b/include/util/str_table.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * str_table.h + * + * Copyright (C) 2019 David Oberhollenzer + */ +#ifndef STR_TABLE_H +#define STR_TABLE_H + +#include "sqfs/predef.h" +#include "array.h" +#include "hash_table.h" + +typedef struct { + size_t index; + size_t refcount; + char string[]; +} str_bucket_t; + +/* Stores strings in a hash table and assigns an incremental, unique ID to + each string. Subsequent additions return the existing ID. The ID can be + used for (hopefully) constant time lookup of the original string. */ +typedef struct { + /* an array that resolves index to bucket pointer */ + array_t bucket_ptrs; + + /* hash table with the string buckets attached */ + struct hash_table *ht; + + /* the next ID we are going to allocate */ + size_t next_index; +} str_table_t; + +/* the number of strings currently stored in the table */ +static SQFS_INLINE size_t str_table_count(const str_table_t *table) +{ + return table->next_index; +} + +/* `size` is the number of hash table buckets to use internally. */ +SQFS_INTERNAL int str_table_init(str_table_t *table); + +SQFS_INTERNAL void str_table_cleanup(str_table_t *table); + +SQFS_INTERNAL int str_table_copy(str_table_t *dst, const str_table_t *src); + +/* Resolve a string to an incremental, unique ID. */ +SQFS_INTERNAL +int str_table_get_index(str_table_t *table, const char *str, size_t *idx); + +/* Resolve a unique ID to the string it represents. + Returns NULL if the ID is unknown, i.e. out of bounds. */ +SQFS_INTERNAL +const char *str_table_get_string(const str_table_t *table, size_t index); + +SQFS_INTERNAL void str_table_add_ref(str_table_t *table, size_t index); + +SQFS_INTERNAL void str_table_del_ref(str_table_t *table, size_t index); + +SQFS_INTERNAL +size_t str_table_get_ref_count(const str_table_t *table, size_t index); + +#endif /* STR_TABLE_H */ diff --git a/include/util/threadpool.h b/include/util/threadpool.h new file mode 100644 index 0000000..f25c497 --- /dev/null +++ b/include/util/threadpool.h @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * threadpool.h + * + * Copyright (C) 2021 David Oberhollenzer + */ +#ifndef THREADPOOL_H +#define THREADPOOL_H + +#include "sqfs/predef.h" + +typedef int (*thread_pool_worker_t)(void *user, void *work_item); + +/** + * @struct thread_pool_t + * + * @brief A thread pool with a ticket number based work item ordering. + * + * While the order in which items are non-deterministic, the thread pool + * implementation internally uses a ticket system to ensure the completed + * items are deqeueued in the same order that they were enqueued. + */ +typedef struct thread_pool_t { + /** + * @brief Shutdown and destroy a thread pool. + * + * @param pool A pointer to a pool returned by thread_pool_create + */ + void (*destroy)(struct thread_pool_t *pool); + + /** + * @brief Get the actual number of worker threads available. + * + * @return A number greater or equal to 1. + */ + size_t (*get_worker_count)(struct thread_pool_t *pool); + + /** + * @brief Change the user data pointer for a thread pool worker + * by index. + * + * @param idx A zero-based index into the worker list. + * @param ptr A user pointer that this specific worker thread should + * pass to the worker callback. + */ + void (*set_worker_ptr)(struct thread_pool_t *pool, size_t idx, + void *ptr); + + /** + * @brief Submit a work item to a thread pool. + * + * This function will fail on allocation failure or if the internal + * error state is set was set by one of the workers. + * + * @param ptr A pointer to a work object to enqueue. + * + * @return Zero on success. + */ + int (*submit)(struct thread_pool_t *pool, void *ptr); + + /** + * @brief Wait for a work item to be completed. + * + * This function dequeues a single completed work item. It may block + * until one of the worker threads signals completion of an additional + * item. + * + * This function guarantees to return the items in the same order as + * they were submitted, so the function can actually block longer than + * necessary, because it has to wait until the next item in sequence + * is finished. + * + * @return A pointer to a new work item or NULL if there are none + * in the pipeline. + */ + void *(*dequeue)(struct thread_pool_t *pool); + + /** + * @brief Get the internal worker return status value. + * + * If the worker functions returns a non-zero exit status in one of the + * worker threads, the thread pool stors the value internally and shuts + * down. This function can be used to retrieve the value. + * + * @return A non-zero value returned by the worker callback or zero if + * everything is A-OK. + */ + int (*get_status)(struct thread_pool_t *pool); +} thread_pool_t; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a thread pool instance. + * + * @param num_jobs The number of worker threads to launch. + * @param worker A function to call from the worker threads to process + * the work items. + * + * @return A pointer to a thread pool on success, NULL on failure. + */ +SQFS_INTERNAL thread_pool_t *thread_pool_create(size_t num_jobs, + thread_pool_worker_t worker); + +/** + * @brief Create a serial mockup thread pool implementation. + * + * This returns a @ref thread_pool_t implementation that, instead of running a + * thread pool actually does the work in-situ when dequeueing. + * + * @param worker A function to call from the worker threads to process + * the work items. + * + * @return A pointer to a thread pool on success, NULL on failure. + */ +SQFS_INTERNAL +thread_pool_t *thread_pool_create_serial(thread_pool_worker_t worker); + +#ifdef __cplusplus +} +#endif + +#endif /* THREADPOOL_H */ diff --git a/include/util/util.h b/include/util/util.h new file mode 100644 index 0000000..4b05340 --- /dev/null +++ b/include/util/util.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * util.h + * + * Copyright (C) 2019 David Oberhollenzer + */ +#ifndef SQFS_UTIL_H +#define SQFS_UTIL_H + +#include "config.h" +#include "sqfs/predef.h" +#include "compat.h" + +#include + +/* + Helper for allocating data structures with flexible array members. + + 'base_size' is the size of the struct itself, 'item_size' the size of a + single array element and 'nmemb' the number of elements. + + Iternally checks for arithmetic overflows when allocating the combined thing. + */ +SQFS_INTERNAL +void *alloc_flex(size_t base_size, size_t item_size, size_t nmemb); + +/* Basically the same as calloc, but *ALWAYS* does overflow checking */ +SQFS_INTERNAL +void *alloc_array(size_t item_size, size_t nmemb); + +SQFS_INTERNAL sqfs_u32 xxh32(const void *input, const size_t len); + +/* + Returns true if the given region of memory is filled with zero-bytes only. + */ +SQFS_INTERNAL bool is_memory_zero(const void *blob, size_t size); + +#endif /* SQFS_UTIL_H */ diff --git a/include/util/w32threadwrap.h b/include/util/w32threadwrap.h new file mode 100644 index 0000000..6b7344c --- /dev/null +++ b/include/util/w32threadwrap.h @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * w32threadwrap.h + * + * Copyright (C) 2021 David Oberhollenzer + */ +#ifndef W32THREADWRAP_H +#define W32THREADWRAP_H + +#include "sqfs/predef.h" + +#define WIN32_LEAN_AND_MEAN +#define VC_EXTRALEAN +#include + +typedef unsigned int sigset_t; +typedef HANDLE pthread_t; +typedef CRITICAL_SECTION pthread_mutex_t; +typedef CONDITION_VARIABLE pthread_cond_t; + +static inline int pthread_create(pthread_t *thread, const void *attr, + LPTHREAD_START_ROUTINE proc, LPVOID arg) +{ + HANDLE hnd = CreateThread(NULL, 0, proc, arg, 0, 0); + (void)attr; + + if (hnd == NULL) + return -1; + + *thread = hnd; + return 0; +} + +static int pthread_join(pthread_t thread, void **retval) +{ + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + if (retval != NULL) + *retval = NULL; + return 0; +} + +static inline int pthread_mutex_init(pthread_mutex_t *mutex, const void *attr) +{ + (void)attr; + InitializeCriticalSection(mutex); + return 0; +} + +static inline int pthread_mutex_lock(pthread_mutex_t *mutex) +{ + EnterCriticalSection(mutex); + return 0; +} + +static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + LeaveCriticalSection(mutex); + return 0; +} + +static inline void pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + DeleteCriticalSection(mutex); +} + +static inline int pthread_cond_init(pthread_cond_t *cond, const void *attr) +{ + (void)attr; + InitializeConditionVariable(cond); + return 0; +} + +static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mtx) +{ + return SleepConditionVariableCS(cond, mtx, INFINITE) != 0; +} + +static inline int pthread_cond_broadcast(pthread_cond_t *cond) +{ + WakeAllConditionVariable(cond); + return 0; +} + +static inline void pthread_cond_destroy(pthread_cond_t *cond) +{ + (void)cond; +} + +#define SIG_SETMASK (0) + +static inline int sigfillset(sigset_t *set) +{ + *set = 0xFFFFFFFF; + return 0; +} + +static inline int pthread_sigmask(int how, const sigset_t *set, + const sigset_t *old) +{ + (void)how; (void)set; (void)old; + return 0; +} + +#endif /* W32THREADWRAP_H */ diff --git a/include/w32threadwrap.h b/include/w32threadwrap.h deleted file mode 100644 index 6b7344c..0000000 --- a/include/w32threadwrap.h +++ /dev/null @@ -1,105 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* - * w32threadwrap.h - * - * Copyright (C) 2021 David Oberhollenzer - */ -#ifndef W32THREADWRAP_H -#define W32THREADWRAP_H - -#include "sqfs/predef.h" - -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRALEAN -#include - -typedef unsigned int sigset_t; -typedef HANDLE pthread_t; -typedef CRITICAL_SECTION pthread_mutex_t; -typedef CONDITION_VARIABLE pthread_cond_t; - -static inline int pthread_create(pthread_t *thread, const void *attr, - LPTHREAD_START_ROUTINE proc, LPVOID arg) -{ - HANDLE hnd = CreateThread(NULL, 0, proc, arg, 0, 0); - (void)attr; - - if (hnd == NULL) - return -1; - - *thread = hnd; - return 0; -} - -static int pthread_join(pthread_t thread, void **retval) -{ - WaitForSingleObject(thread, INFINITE); - CloseHandle(thread); - if (retval != NULL) - *retval = NULL; - return 0; -} - -static inline int pthread_mutex_init(pthread_mutex_t *mutex, const void *attr) -{ - (void)attr; - InitializeCriticalSection(mutex); - return 0; -} - -static inline int pthread_mutex_lock(pthread_mutex_t *mutex) -{ - EnterCriticalSection(mutex); - return 0; -} - -static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) -{ - LeaveCriticalSection(mutex); - return 0; -} - -static inline void pthread_mutex_destroy(pthread_mutex_t *mutex) -{ - DeleteCriticalSection(mutex); -} - -static inline int pthread_cond_init(pthread_cond_t *cond, const void *attr) -{ - (void)attr; - InitializeConditionVariable(cond); - return 0; -} - -static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mtx) -{ - return SleepConditionVariableCS(cond, mtx, INFINITE) != 0; -} - -static inline int pthread_cond_broadcast(pthread_cond_t *cond) -{ - WakeAllConditionVariable(cond); - return 0; -} - -static inline void pthread_cond_destroy(pthread_cond_t *cond) -{ - (void)cond; -} - -#define SIG_SETMASK (0) - -static inline int sigfillset(sigset_t *set) -{ - *set = 0xFFFFFFFF; - return 0; -} - -static inline int pthread_sigmask(int how, const sigset_t *set, - const sigset_t *old) -{ - (void)how; (void)set; (void)old; - return 0; -} - -#endif /* W32THREADWRAP_H */ diff --git a/lib/common/hardlink.c b/lib/common/hardlink.c index ab19671..c64ec4a 100644 --- a/lib/common/hardlink.c +++ b/lib/common/hardlink.c @@ -5,7 +5,7 @@ * Copyright (C) 2019 David Oberhollenzer */ #include "common.h" -#include "rbtree.h" +#include "util/rbtree.h" #include #include diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am index aaf63d8..d49482e 100644 --- a/lib/sqfs/Makemodule.am +++ b/lib/sqfs/Makemodule.am @@ -44,14 +44,14 @@ libsquashfs_la_LIBADD += $(ZSTD_LIBS) $(PTHREAD_LIBS) # directly "import" stuff from libutil libsquashfs_la_SOURCES += lib/util/str_table.c lib/util/alloc.c libsquashfs_la_SOURCES += lib/util/xxhash.c -libsquashfs_la_SOURCES += lib/util/hash_table.c include/hash_table.h -libsquashfs_la_SOURCES += lib/util/rbtree.c include/rbtree.h -libsquashfs_la_SOURCES += lib/util/array.c include/array.h +libsquashfs_la_SOURCES += lib/util/hash_table.c include/util/hash_table.h +libsquashfs_la_SOURCES += lib/util/rbtree.c include/util/rbtree.h +libsquashfs_la_SOURCES += lib/util/array.c include/util/array.h libsquashfs_la_SOURCES += lib/util/is_memory_zero.c -libsquashfs_la_SOURCES += include/threadpool.h +libsquashfs_la_SOURCES += include/util/threadpool.h if CUSTOM_ALLOC -libsquashfs_la_SOURCES += lib/util/mempool.c include/mempool.h +libsquashfs_la_SOURCES += lib/util/mempool.c include/util/mempool.h endif if WINDOWS diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h index 1c184c5..0b2c88d 100644 --- a/lib/sqfs/block_processor/internal.h +++ b/lib/sqfs/block_processor/internal.h @@ -19,9 +19,9 @@ #include "sqfs/block.h" #include "sqfs/io.h" -#include "hash_table.h" -#include "threadpool.h" -#include "util.h" +#include "util/hash_table.h" +#include "util/threadpool.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c index 54f0c89..1230c2d 100644 --- a/lib/sqfs/block_writer.c +++ b/lib/sqfs/block_writer.c @@ -11,7 +11,7 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/comp/internal.h b/lib/sqfs/comp/internal.h index 0566683..e4c3dd8 100644 --- a/lib/sqfs/comp/internal.h +++ b/lib/sqfs/comp/internal.h @@ -14,7 +14,7 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" SQFS_INTERNAL int sqfs_generic_write_options(sqfs_file_t *file, const void *data, diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c index e3a2eef..1033db9 100644 --- a/lib/sqfs/data_reader.c +++ b/lib/sqfs/data_reader.c @@ -15,7 +15,7 @@ #include "sqfs/table.h" #include "sqfs/inode.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/dir_reader/internal.h b/lib/sqfs/dir_reader/internal.h index 4b2ed21..7275cd2 100644 --- a/lib/sqfs/dir_reader/internal.h +++ b/lib/sqfs/dir_reader/internal.h @@ -17,8 +17,8 @@ #include "sqfs/inode.h" #include "sqfs/error.h" #include "sqfs/dir.h" -#include "rbtree.h" -#include "util.h" +#include "util/rbtree.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/dir_writer.c b/lib/sqfs/dir_writer.c index ad44458..a02faa7 100644 --- a/lib/sqfs/dir_writer.c +++ b/lib/sqfs/dir_writer.c @@ -15,8 +15,8 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "sqfs/dir.h" -#include "array.h" -#include "util.h" +#include "util/array.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/frag_table.c b/lib/sqfs/frag_table.c index f15da5c..71627df 100644 --- a/lib/sqfs/frag_table.c +++ b/lib/sqfs/frag_table.c @@ -13,7 +13,7 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "compat.h" -#include "array.h" +#include "util/array.h" #include #include diff --git a/lib/sqfs/id_table.c b/lib/sqfs/id_table.c index 746a5cc..cebf64b 100644 --- a/lib/sqfs/id_table.c +++ b/lib/sqfs/id_table.c @@ -12,7 +12,7 @@ #include "sqfs/table.h" #include "sqfs/error.h" #include "compat.h" -#include "array.h" +#include "util/array.h" #include #include diff --git a/lib/sqfs/inode.c b/lib/sqfs/inode.c index 01e5ebe..0fb4809 100644 --- a/lib/sqfs/inode.c +++ b/lib/sqfs/inode.c @@ -14,7 +14,7 @@ #include #include -#include "util.h" +#include "util/util.h" static int inverse_type[] = { [SQFS_INODE_DIR] = SQFS_INODE_EXT_DIR, diff --git a/lib/sqfs/meta_reader.c b/lib/sqfs/meta_reader.c index 94da268..cddcda6 100644 --- a/lib/sqfs/meta_reader.c +++ b/lib/sqfs/meta_reader.c @@ -12,7 +12,7 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/meta_writer.c b/lib/sqfs/meta_writer.c index 80f0fdd..2314e06 100644 --- a/lib/sqfs/meta_writer.c +++ b/lib/sqfs/meta_writer.c @@ -12,7 +12,7 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/read_inode.c b/lib/sqfs/read_inode.c index 4f9fd3c..12bef48 100644 --- a/lib/sqfs/read_inode.c +++ b/lib/sqfs/read_inode.c @@ -12,7 +12,7 @@ #include "sqfs/super.h" #include "sqfs/inode.h" #include "sqfs/dir.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/read_super.c b/lib/sqfs/read_super.c index 919e720..11bc314 100644 --- a/lib/sqfs/read_super.c +++ b/lib/sqfs/read_super.c @@ -10,7 +10,7 @@ #include "sqfs/super.h" #include "sqfs/error.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include diff --git a/lib/sqfs/read_table.c b/lib/sqfs/read_table.c index 1c9c8ad..8f9bddd 100644 --- a/lib/sqfs/read_table.c +++ b/lib/sqfs/read_table.c @@ -12,7 +12,7 @@ #include "sqfs/table.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include diff --git a/lib/sqfs/write_table.c b/lib/sqfs/write_table.c index b198941..7f1b201 100644 --- a/lib/sqfs/write_table.c +++ b/lib/sqfs/write_table.c @@ -13,7 +13,7 @@ #include "sqfs/table.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include diff --git a/lib/sqfs/xattr/xattr_reader.c b/lib/sqfs/xattr/xattr_reader.c index d3adc46..a55ad2f 100644 --- a/lib/sqfs/xattr/xattr_reader.c +++ b/lib/sqfs/xattr/xattr_reader.c @@ -14,7 +14,7 @@ #include "sqfs/error.h" #include "sqfs/block.h" #include "sqfs/io.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/sqfs/xattr/xattr_writer.h b/lib/sqfs/xattr/xattr_writer.h index 6f414b8..792cfae 100644 --- a/lib/sqfs/xattr/xattr_writer.h +++ b/lib/sqfs/xattr/xattr_writer.h @@ -18,10 +18,10 @@ #include "sqfs/block.h" #include "sqfs/io.h" -#include "str_table.h" -#include "rbtree.h" -#include "array.h" -#include "util.h" +#include "util/str_table.h" +#include "util/rbtree.h" +#include "util/array.h" +#include "util/util.h" #include #include diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am index c66c786..01ffa31 100644 --- a/lib/util/Makemodule.am +++ b/lib/util/Makemodule.am @@ -1,11 +1,12 @@ -libutil_a_SOURCES = include/util.h include/str_table.h include/hash_table.h +libutil_a_SOURCES = include/util/util.h include/util/str_table.h +libutil_a_SOURCES += include/util/hash_table.h libutil_a_SOURCES += lib/util/str_table.c lib/util/alloc.c -libutil_a_SOURCES += lib/util/rbtree.c include/rbtree.h -libutil_a_SOURCES += lib/util/array.c include/array.h +libutil_a_SOURCES += lib/util/rbtree.c include/util/rbtree.h +libutil_a_SOURCES += lib/util/array.c include/util/array.h libutil_a_SOURCES += lib/util/xxhash.c lib/util/hash_table.c libutil_a_SOURCES += lib/util/fast_urem_by_const.h -libutil_a_SOURCES += include/threadpool.h -libutil_a_SOURCES += include/w32threadwrap.h +libutil_a_SOURCES += include/util/threadpool.h +libutil_a_SOURCES += include/util/w32threadwrap.h libutil_a_SOURCES += lib/util/threadpool_serial.c libutil_a_SOURCES += lib/util/is_memory_zero.c libutil_a_CFLAGS = $(AM_CFLAGS) @@ -27,7 +28,7 @@ endif endif if CUSTOM_ALLOC -libutil_a_SOURCES += lib/util/mempool.c include/mempool.h +libutil_a_SOURCES += lib/util/mempool.c include/util/mempool.h endif noinst_LIBRARIES += libutil.a diff --git a/lib/util/alloc.c b/lib/util/alloc.c index e8305d8..359fef5 100644 --- a/lib/util/alloc.c +++ b/lib/util/alloc.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "util.h" +#include "util/util.h" #include #include diff --git a/lib/util/array.c b/lib/util/array.c index 3697a07..40bac50 100644 --- a/lib/util/array.c +++ b/lib/util/array.c @@ -6,7 +6,7 @@ */ #include "config.h" #include "compat.h" -#include "array.h" +#include "util/array.h" #include "sqfs/error.h" diff --git a/lib/util/hash_table.c b/lib/util/hash_table.c index a78aeee..0010e9f 100644 --- a/lib/util/hash_table.c +++ b/lib/util/hash_table.c @@ -45,7 +45,7 @@ #include #include "fast_urem_by_const.h" -#include "hash_table.h" +#include "util/hash_table.h" # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/lib/util/is_memory_zero.c b/lib/util/is_memory_zero.c index 3974ee2..aabd45d 100644 --- a/lib/util/is_memory_zero.c +++ b/lib/util/is_memory_zero.c @@ -5,7 +5,7 @@ * Copyright (C) 2021 David Oberhollenzer */ #include "config.h" -#include "util.h" +#include "util/util.h" #include diff --git a/lib/util/mempool.c b/lib/util/mempool.c index 5191fa2..229ab28 100644 --- a/lib/util/mempool.c +++ b/lib/util/mempool.c @@ -4,7 +4,7 @@ * * Copyright (C) 2021 David Oberhollenzer */ -#include "mempool.h" +#include "util/mempool.h" #include #include diff --git a/lib/util/rbtree.c b/lib/util/rbtree.c index 8839f82..8b43e43 100644 --- a/lib/util/rbtree.c +++ b/lib/util/rbtree.c @@ -7,7 +7,7 @@ #include "config.h" #include "sqfs/error.h" -#include "rbtree.h" +#include "util/rbtree.h" #include #include diff --git a/lib/util/str_table.c b/lib/util/str_table.c index 2816ff8..2d3e354 100644 --- a/lib/util/str_table.c +++ b/lib/util/str_table.c @@ -11,8 +11,8 @@ #include #include "sqfs/error.h" -#include "str_table.h" -#include "util.h" +#include "util/str_table.h" +#include "util/util.h" /* R5 hash function (borrowed from reiserfs) */ static sqfs_u32 strhash(const char *s) diff --git a/lib/util/threadpool.c b/lib/util/threadpool.c index d20fe8b..c7357cd 100644 --- a/lib/util/threadpool.c +++ b/lib/util/threadpool.c @@ -4,14 +4,14 @@ * * Copyright (C) 2021 David Oberhollenzer */ -#include "threadpool.h" -#include "util.h" +#include "util/threadpool.h" +#include "util/util.h" #include #include #if defined(_WIN32) || defined(__WINDOWS__) -#include "w32threadwrap.h" +#include "util/w32threadwrap.h" #define THREAD_FUN(funname, argname) DWORD WINAPI funname(LPVOID argname) #define THREAD_EXIT_SUCCESS (0) diff --git a/lib/util/threadpool_serial.c b/lib/util/threadpool_serial.c index 834cfa7..fb24ee8 100644 --- a/lib/util/threadpool_serial.c +++ b/lib/util/threadpool_serial.c @@ -4,8 +4,8 @@ * * Copyright (C) 2021 David Oberhollenzer */ -#include "threadpool.h" -#include "util.h" +#include "util/threadpool.h" +#include "util/util.h" #include #include diff --git a/lib/util/xxhash.c b/lib/util/xxhash.c index 0644e75..60467fb 100644 --- a/lib/util/xxhash.c +++ b/lib/util/xxhash.c @@ -35,7 +35,7 @@ * - xxHash source repository: https://github.com/Cyan4973/xxHash */ #include "config.h" -#include "util.h" +#include "util/util.h" #include diff --git a/tests/libutil/is_memory_zero.c b/tests/libutil/is_memory_zero.c index 0d10dd8..967e2e8 100644 --- a/tests/libutil/is_memory_zero.c +++ b/tests/libutil/is_memory_zero.c @@ -7,7 +7,7 @@ #include "config.h" #include "../test.h" -#include "util.h" +#include "util/util.h" int main(int argc, char **argv) { diff --git a/tests/libutil/rbtree.c b/tests/libutil/rbtree.c index 05f7aa3..d7b475a 100644 --- a/tests/libutil/rbtree.c +++ b/tests/libutil/rbtree.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "rbtree.h" +#include "util/rbtree.h" #include "../test.h" static int key_compare(const void *ctx, const void *a, const void *b) diff --git a/tests/libutil/str_table.c b/tests/libutil/str_table.c index b75bb91..a69a9c4 100644 --- a/tests/libutil/str_table.c +++ b/tests/libutil/str_table.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "str_table.h" +#include "util/str_table.h" #include "fstream.h" #include "compat.h" #include "../test.h" diff --git a/tests/libutil/threadpool.c b/tests/libutil/threadpool.c index cd52ad3..4b07935 100644 --- a/tests/libutil/threadpool.c +++ b/tests/libutil/threadpool.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "threadpool.h" +#include "util/threadpool.h" #include "../test.h" #if defined(_WIN32) || defined(__WINDOWS__) diff --git a/tests/libutil/xxhash.c b/tests/libutil/xxhash.c index b0b1bac..cccbb68 100644 --- a/tests/libutil/xxhash.c +++ b/tests/libutil/xxhash.c @@ -6,7 +6,7 @@ */ #include "config.h" -#include "util.h" +#include "util/util.h" #include "../test.h" static const struct { -- cgit v1.2.3