diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-07-18 21:54:50 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-08-10 09:28:27 +0200 |
commit | 5a3b741b92b793be7221a481efca316aec208ebe (patch) | |
tree | 81eaa29e7f4510f4419a3dc2f0b29120aa5114ab /lib/common | |
parent | 9d431639effb4e33169110031a689fd1e9d435cf (diff) |
Add a data reader based sqfs_istream_t implementation
To the sqfs_data_reader_t is added, an sqfs_istream_t implementation
that internally reads through the data reader. The uses of the
data_reader_dump function are removed and the function is subsequently
removed from libcommon.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/Makemodule.am | 2 | ||||
-rw-r--r-- | lib/common/src/data_reader_dump.c | 67 |
2 files changed, 1 insertions, 68 deletions
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am index 61d87d4..e0cc551 100644 --- a/lib/common/Makemodule.am +++ b/lib/common/Makemodule.am @@ -1,7 +1,7 @@ libcommon_a_SOURCES = include/common.h include/simple_writer.h \ include/compress_cli.h \ lib/common/src/hardlink.c lib/common/src/print_version.c \ - lib/common/src/data_reader_dump.c lib/common/src/compress.c \ + lib/common/src/compress.c \ lib/common/src/comp_opt.c lib/common/src/data_writer.c \ lib/common/src/parse_size.c lib/common/src/print_size.c \ lib/common/src/writer/init.c lib/common/src/writer/cleanup.c \ diff --git a/lib/common/src/data_reader_dump.c b/lib/common/src/data_reader_dump.c deleted file mode 100644 index 920b2bd..0000000 --- a/lib/common/src/data_reader_dump.c +++ /dev/null @@ -1,67 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * data_reader_dump.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - */ -#include "common.h" - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> - -int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, - const sqfs_inode_generic_t *inode, - sqfs_ostream_t *fp, size_t block_size) -{ - size_t i, diff, chunk_size; - sqfs_u64 filesz; - sqfs_u8 *chunk; - int err; - - sqfs_inode_get_file_size(inode, &filesz); - - for (i = 0; i < sqfs_inode_get_file_block_count(inode); ++i) { - diff = (filesz < block_size) ? filesz : block_size; - - if (SQFS_IS_SPARSE_BLOCK(inode->extra[i])) { - err = fp->append(fp, NULL, diff); - } else { - err = sqfs_data_reader_get_block(data, inode, i, - &chunk_size, &chunk); - if (err) { - sqfs_perror(name, "reading data block", err); - return -1; - } - - err = fp->append(fp, chunk, chunk_size); - free(chunk); - } - - if (err) - goto fail_io; - - filesz -= diff; - } - - if (filesz > 0) { - err = sqfs_data_reader_get_fragment(data, inode, - &chunk_size, &chunk); - if (err) { - sqfs_perror(name, "reading fragment block", err); - return -1; - } - - err = fp->append(fp, chunk, chunk_size); - free(chunk); - - if (err) - goto fail_io; - } - - return 0; -fail_io: - sqfs_perror(fp->get_filename(fp), "writing data block", err); - return -1; -} |