If we need it future, we can bring them back on demand from git repo. No need to keep it in the source file. Signed-off-by: Liu Yuan <namei.unix at gmail.com> --- include/util.h | 4 --- lib/util.c | 83 ---------------------------------------------------------- 2 files changed, 87 deletions(-) diff --git a/include/util.h b/include/util.h index 5976ef9..f0dae12 100644 --- a/include/util.h +++ b/include/util.h @@ -119,10 +119,6 @@ const char *my_exe_path(void); int split_path(const char *path, size_t nr_segs, char **segs); void make_path(char *path, size_t size, size_t nr_segs, const char **segs); -void find_zero_blocks(const void *buf, uint64_t *poffset, uint32_t *plen); -void trim_zero_blocks(void *buf, uint64_t *offset, uint32_t *len); -void untrim_zero_blocks(void *buf, uint64_t offset, uint32_t len, - uint32_t requested_len); int atomic_create_and_write(const char *path, const char *buf, size_t len, bool force_create); diff --git a/lib/util.c b/lib/util.c index 64753db..7035512 100644 --- a/lib/util.c +++ b/lib/util.c @@ -396,89 +396,6 @@ int rmdir_r(const char *dir_path) return ret; } -/* - * Find zero blocks from the beginning and end of buffer - * - * The caller passes the offset of 'buf' with 'poffset' so that this funciton - * can align the return values to BLOCK_SIZE. 'plen' points the length of the - * buffer. If there are zero blocks at the beginning of the buffer, this - * function increases the offset and decreases the length on condition that - * '*poffset' is block-aligned. If there are zero blocks at the end of the - * buffer, this function also decreases the length on condition that '*plen' is - * block-aligned. - */ -void find_zero_blocks(const void *buf, uint64_t *poffset, uint32_t *plen) -{ - const uint8_t zero[BLOCK_SIZE] = {0}; - const uint8_t *p = buf; - uint64_t start = *poffset; - uint64_t offset = 0; - uint32_t len = *plen; - - /* trim zero blocks from the beginning of buffer */ - while (len >= BLOCK_SIZE) { - size_t size = BLOCK_SIZE - (start + offset) % BLOCK_SIZE; - - if (memcmp(p + offset, zero, size) != 0) - break; - - offset += size; - len -= size; - } - - /* trim zero sectors from the end of buffer */ - while (len >= BLOCK_SIZE) { - size_t size = (start + offset + len) % BLOCK_SIZE; - if (size == 0) - size = BLOCK_SIZE; - - if (memcmp(p + offset + len - size, zero, size) != 0) - break; - - len -= size; - } - - *plen = len; - *poffset = start + offset; -} - -/* - * Trim zero blocks from the beginning and end of buffer - * - * This function is similar to find_zero_blocks(), but this updates 'buf' so - * that the zero block are removed from the beginning of buffer. - */ -void trim_zero_blocks(void *buf, uint64_t *poffset, uint32_t *plen) -{ - uint8_t *p = buf; - uint64_t orig_offset = *poffset; - - find_zero_blocks(buf, poffset, plen); - if (orig_offset < *poffset) - memmove(p, p + *poffset - orig_offset, *plen); -} - -/* - * Untrim zero blocks to the beginning and end of buffer - * - * 'offset' is the offset of 'buf' in the original buffer, 'len' is the length - * of 'buf', and 'requested_len' is the length of the original buffer. 'buf' - * must have enough spaces to contain 'requested_len' bytes. - */ -void untrim_zero_blocks(void *buf, uint64_t offset, uint32_t len, - uint32_t requested_len) -{ - uint8_t *p = buf; - - if (offset > 0) { - memmove(p + offset, buf, len); - memset(p, 0, offset); - } - - if (offset + len < requested_len) - memset(p + offset + len, 0, requested_len - offset - len); -} - bool is_numeric(const char *s) { const char *p = s; -- 1.8.1.2 |