aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-09 00:06:08 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-09 00:06:08 +0200
commit8b5a2d64fa95cb964540b950ca237545d9e51822 (patch)
tree26ea184513e90ccd2f704b3cd1f884b7fa3d2c94 /lib
parent3eb3ba3d309ff5e560b5428ccf01694aeb62663e (diff)
libcommon: get rid of write_data_from_file
Modify gensquashfs to pack data using an istream wrapper, similar to tar2sqfs. To implement the no-tail-pack option, we need the file size, so we simply open a raw handle first, and query it (using libsquashfs API) and then create the stream wrapper. For the output side, we create a block-processor ostream wrapper and splice it. Since gensquashfs is the only, remaining user of the pack-a-file functon, we can then remove it from libcommon. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Makemodule.am3
-rw-r--r--lib/common/src/data_writer.c54
2 files changed, 1 insertions, 56 deletions
diff --git a/lib/common/Makemodule.am b/lib/common/Makemodule.am
index e0cc551..a50ddcb 100644
--- a/lib/common/Makemodule.am
+++ b/lib/common/Makemodule.am
@@ -1,8 +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/compress.c \
- lib/common/src/comp_opt.c lib/common/src/data_writer.c \
+ lib/common/src/compress.c lib/common/src/comp_opt.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 \
lib/common/src/writer/serialize_fstree.c lib/common/src/writer/finish.c\
diff --git a/lib/common/src/data_writer.c b/lib/common/src/data_writer.c
deleted file mode 100644
index ceccaac..0000000
--- a/lib/common/src/data_writer.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * data_writer.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "common.h"
-
-static sqfs_u8 buffer[4096];
-
-int write_data_from_file(const char *filename, sqfs_block_processor_t *data,
- sqfs_inode_generic_t **inode, sqfs_file_t *file,
- int flags)
-{
- sqfs_u64 filesz, offset;
- size_t diff;
- int ret;
-
- ret = sqfs_block_processor_begin_file(data, inode, NULL, flags);
- if (ret) {
- sqfs_perror(filename, "beginning file data blocks", ret);
- return -1;
- }
-
- filesz = file->get_size(file);
-
- for (offset = 0; offset < filesz; offset += diff) {
- if (filesz - offset > sizeof(buffer)) {
- diff = sizeof(buffer);
- } else {
- diff = filesz - offset;
- }
-
- ret = file->read_at(file, offset, buffer, diff);
- if (ret) {
- sqfs_perror(filename, "reading file range", ret);
- return -1;
- }
-
- ret = sqfs_block_processor_append(data, buffer, diff);
- if (ret) {
- sqfs_perror(filename, "packing file data", ret);
- return -1;
- }
- }
-
- ret = sqfs_block_processor_end_file(data);
- if (ret) {
- sqfs_perror(filename, "finishing file data", ret);
- return -1;
- }
-
- return 0;
-}