From 7bbd03a7f450e59ebd7481cd1af0639131630f42 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 17 May 2013 15:02:56 -0500 Subject: [PATCH] WIM chunk size: Calculate with existing macros when possible --- include/wimlib/lookup_table.h | 2 +- src/resource.c | 4 ++-- src/write.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/wimlib/lookup_table.h b/include/wimlib/lookup_table.h index 2b2cfcd9..d6bd5ee3 100644 --- a/include/wimlib/lookup_table.h +++ b/include/wimlib/lookup_table.h @@ -259,7 +259,7 @@ wim_resource_size(const struct wim_lookup_table_entry *lte) static inline u64 wim_resource_chunks(const struct wim_lookup_table_entry *lte) { - return (wim_resource_size(lte) + WIM_CHUNK_SIZE - 1) / WIM_CHUNK_SIZE; + return DIV_ROUND_UP(wim_resource_size(lte), WIM_CHUNK_SIZE); } static inline u64 diff --git a/src/resource.c b/src/resource.c index d60f5476..29bfcd7f 100644 --- a/src/resource.c +++ b/src/resource.c @@ -97,8 +97,8 @@ read_compressed_resource(int in_fd, /* Calculate how many chunks the resource consists of in its entirety. * */ - u64 num_chunks = (resource_uncompressed_size + WIM_CHUNK_SIZE - 1) / - WIM_CHUNK_SIZE; + u64 num_chunks = DIV_ROUND_UP(resource_uncompressed_size, WIM_CHUNK_SIZE); + /* As mentioned, the first chunk has no entry in the chunk table. */ u64 num_chunk_entries = num_chunks - 1; diff --git a/src/write.c b/src/write.c index 8451b391..fde7e939 100644 --- a/src/write.c +++ b/src/write.c @@ -104,7 +104,7 @@ begin_wim_resource_chunk_tab(const struct wim_lookup_table_entry *lte, struct chunk_table **chunk_tab_ret) { u64 size = wim_resource_size(lte); - u64 num_chunks = (size + WIM_CHUNK_SIZE - 1) / WIM_CHUNK_SIZE; + u64 num_chunks = wim_resource_chunks(lte); size_t alloc_size = sizeof(struct chunk_table) + num_chunks * sizeof(u64); struct chunk_table *chunk_tab = CALLOC(1, alloc_size); @@ -118,7 +118,7 @@ begin_wim_resource_chunk_tab(const struct wim_lookup_table_entry *lte, chunk_tab->file_offset = file_offset; chunk_tab->num_chunks = num_chunks; chunk_tab->original_resource_size = size; - chunk_tab->bytes_per_chunk_entry = (size >= (1ULL << 32)) ? 8 : 4; + chunk_tab->bytes_per_chunk_entry = (size > (1ULL << 32)) ? 8 : 4; chunk_tab->table_disk_size = chunk_tab->bytes_per_chunk_entry * (num_chunks - 1); chunk_tab->cur_offset = 0; -- 2.43.0