diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-16 19:46:46 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-17 15:27:19 +0200 |
commit | 0abe1816da2706f87432c4e04918ad0eec902479 (patch) | |
tree | bae50f863a3784ddd709911cdabac06c5e759679 /lib/sqfs | |
parent | 230453fc840c112bbe2c18708338fd897f1174ec (diff) |
Move data writer ostream into libsquashfs
It is mainly a very thin wrapper on top of the block processor so far.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r-- | lib/sqfs/Makemodule.am | 1 | ||||
-rw-r--r-- | lib/sqfs/src/block_processor/ostream.c | 99 |
2 files changed, 100 insertions, 0 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am index 170cf6b..e929286 100644 --- a/lib/sqfs/Makemodule.am +++ b/lib/sqfs/Makemodule.am @@ -29,6 +29,7 @@ libsquashfs_la_SOURCES = $(LIBSQFS_HEARDS) lib/sqfs/src/id_table.c \ lib/sqfs/src/block_processor/frontend.c \ lib/sqfs/src/block_processor/block_processor.c \ lib/sqfs/src/block_processor/backend.c \ + lib/sqfs/src/block_processor/ostream.c \ lib/sqfs/src/frag_table.c lib/sqfs/src/block_writer.c \ lib/sqfs/src/misc.c lib/sqfs/src/io/istream.c \ lib/sqfs/src/io/ostream.c lib/sqfs/src/io/file.c \ diff --git a/lib/sqfs/src/block_processor/ostream.c b/lib/sqfs/src/block_processor/ostream.c new file mode 100644 index 0000000..b734e08 --- /dev/null +++ b/lib/sqfs/src/block_processor/ostream.c @@ -0,0 +1,99 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * ostream.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#define SQFS_BUILDING_DLL +#include "internal.h" + +#include <stdlib.h> + +typedef struct{ + sqfs_ostream_t base; + + sqfs_block_processor_t *proc; + char filename[]; +} block_processor_ostream_t; + +static int stream_append(sqfs_ostream_t *base, const void *data, size_t size) +{ + block_processor_ostream_t *strm = (block_processor_ostream_t *)base; + + if (strm->proc == NULL) + return SQFS_ERROR_SEQUENCE; + + return sqfs_block_processor_append(strm->proc, data, size); +} + +static int stream_flush(sqfs_ostream_t *base) +{ + block_processor_ostream_t *strm = (block_processor_ostream_t *)base; + int ret; + + if (strm->proc == NULL) + return SQFS_ERROR_SEQUENCE; + + ret = sqfs_block_processor_end_file(strm->proc); + strm->proc = sqfs_drop(strm->proc); + + return ret; +} + +static const char *stream_get_filename(sqfs_ostream_t *strm) +{ + return ((block_processor_ostream_t *)strm)->filename; +} + +static void stream_destroy(sqfs_object_t *base) +{ + block_processor_ostream_t *strm = (block_processor_ostream_t *)base; + + if (strm->proc != NULL) { + sqfs_block_processor_end_file(strm->proc); + sqfs_drop(strm->proc); + } + + free(strm); +} + +int sqfs_block_processor_create_ostream(sqfs_ostream_t **out, + const char *filename, + sqfs_block_processor_t *proc, + sqfs_inode_generic_t **inode, + sqfs_u32 flags) +{ + block_processor_ostream_t *strm; + sqfs_ostream_t *base; + size_t size, namelen; + int ret; + + *out = NULL; + + namelen = strlen(filename); + size = sizeof(*strm) + 1; + if (SZ_ADD_OV(namelen, size, &size)) + return SQFS_ERROR_ALLOC; + + strm = calloc(1, size); + base = (sqfs_ostream_t *)strm; + if (strm == NULL) + return SQFS_ERROR_ALLOC; + + sqfs_object_init(strm, stream_destroy, NULL); + memcpy(strm->filename, filename, namelen); + + ret = sqfs_block_processor_begin_file(proc, inode, NULL, flags); + if (ret != 0) { + free(strm); + return ret; + } + + strm->proc = sqfs_grab(proc); + base->append = stream_append; + base->flush = stream_flush; + base->get_filename = stream_get_filename; + + *out = base; + return 0; +} |