summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-16 04:00:25 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-16 04:00:25 +0100
commitcab741413084e1f6b2bd9288273c7b14dfd4a8d7 (patch)
tree4f3b511eeae52b28556fc06c126b26fe516c2fb8
parente79c669e60d04c4367f597dbadb761cbbf5752ba (diff)
block processor: merge rest of fileapi.c into common.c
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/sqfs/Makemodule.am1
-rw-r--r--lib/sqfs/block_processor/common.c120
-rw-r--r--lib/sqfs/block_processor/fileapi.c128
3 files changed, 120 insertions, 129 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index d1fc934..aada6c6 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -23,7 +23,6 @@ libsquashfs_la_SOURCES += lib/sqfs/inode.c
libsquashfs_la_SOURCES += lib/sqfs/write_super.c lib/sqfs/data_reader.c
libsquashfs_la_SOURCES += lib/sqfs/block_processor/internal.h
libsquashfs_la_SOURCES += lib/sqfs/block_processor/common.c
-libsquashfs_la_SOURCES += lib/sqfs/block_processor/fileapi.c
libsquashfs_la_SOURCES += lib/sqfs/block_processor/xxhash.c
libsquashfs_la_SOURCES += lib/sqfs/str_table.c lib/sqfs/str_table.h
libsquashfs_la_SOURCES += lib/sqfs/alloc.c lib/sqfs/util.h
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index a01b5e9..674e4cf 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -161,6 +161,126 @@ fail:
return err;
}
+static int add_sentinel_block(sqfs_block_processor_t *proc)
+{
+ sqfs_block_t *blk = calloc(1, sizeof(*blk));
+
+ if (blk == NULL)
+ return SQFS_ERROR_ALLOC;
+
+ blk->inode = proc->inode;
+ blk->flags = proc->blk_flags | SQFS_BLK_LAST_BLOCK;
+
+ return append_to_work_queue(proc, blk);
+}
+
+static int flush_block(sqfs_block_processor_t *proc)
+{
+ sqfs_block_t *block = proc->blk_current;
+
+ proc->blk_current = NULL;
+
+ if (block->size < proc->max_block_size &&
+ !(block->flags & SQFS_BLK_DONT_FRAGMENT)) {
+ block->flags |= SQFS_BLK_IS_FRAGMENT;
+ } else {
+ proc->blk_flags &= ~SQFS_BLK_FIRST_BLOCK;
+ }
+
+ return append_to_work_queue(proc, block);
+}
+
+int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc,
+ sqfs_inode_generic_t *inode, sqfs_u32 flags)
+{
+ if (proc->inode != NULL)
+ return SQFS_ERROR_SEQUENCE;
+
+ if (flags & ~SQFS_BLK_USER_SETTABLE_FLAGS)
+ return SQFS_ERROR_UNSUPPORTED;
+
+ proc->inode = inode;
+ proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK;
+ return 0;
+}
+
+int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data,
+ size_t size)
+{
+ sqfs_block_t *new;
+ size_t diff;
+ int err;
+
+ while (size > 0) {
+ if (proc->blk_current == NULL) {
+ new = alloc_flex(sizeof(*new), 1, proc->max_block_size);
+ if (new == NULL)
+ return SQFS_ERROR_ALLOC;
+
+ proc->blk_current = new;
+ proc->blk_current->flags = proc->blk_flags;
+ proc->blk_current->inode = proc->inode;
+ }
+
+ diff = proc->max_block_size - proc->blk_current->size;
+
+ if (diff == 0) {
+ err = flush_block(proc);
+ if (err)
+ return err;
+ continue;
+ }
+
+ if (diff > size)
+ diff = size;
+
+ memcpy(proc->blk_current->data + proc->blk_current->size,
+ data, diff);
+
+ size -= diff;
+ proc->blk_current->size += diff;
+ data = (const char *)data + diff;
+
+ proc->stats.input_bytes_read += diff;
+ }
+
+ if (proc->blk_current != NULL &&
+ proc->blk_current->size == proc->max_block_size) {
+ return flush_block(proc);
+ }
+
+ return 0;
+}
+
+int sqfs_block_processor_end_file(sqfs_block_processor_t *proc)
+{
+ int err;
+
+ if (proc->inode == NULL)
+ return SQFS_ERROR_SEQUENCE;
+
+ if (!(proc->blk_flags & SQFS_BLK_FIRST_BLOCK)) {
+ if (proc->blk_current != NULL &&
+ (proc->blk_flags & SQFS_BLK_DONT_FRAGMENT)) {
+ proc->blk_flags |= SQFS_BLK_LAST_BLOCK;
+ } else {
+ err = add_sentinel_block(proc);
+ if (err)
+ return err;
+ }
+ }
+
+ if (proc->blk_current != NULL) {
+ err = flush_block(proc);
+ if (err)
+ return err;
+ }
+
+ proc->inode = NULL;
+ proc->blk_flags = 0;
+ return 0;
+}
+
const sqfs_block_processor_stats_t
*sqfs_block_processor_get_stats(const sqfs_block_processor_t *proc)
{
diff --git a/lib/sqfs/block_processor/fileapi.c b/lib/sqfs/block_processor/fileapi.c
deleted file mode 100644
index 073d92f..0000000
--- a/lib/sqfs/block_processor/fileapi.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * fileapi.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#define SQFS_BUILDING_DLL
-#include "internal.h"
-
-static int add_sentinel_block(sqfs_block_processor_t *proc)
-{
- sqfs_block_t *blk = calloc(1, sizeof(*blk));
-
- if (blk == NULL)
- return SQFS_ERROR_ALLOC;
-
- blk->inode = proc->inode;
- blk->flags = proc->blk_flags | SQFS_BLK_LAST_BLOCK;
-
- return append_to_work_queue(proc, blk);
-}
-
-static int flush_block(sqfs_block_processor_t *proc)
-{
- sqfs_block_t *block = proc->blk_current;
-
- proc->blk_current = NULL;
-
- if (block->size < proc->max_block_size &&
- !(block->flags & SQFS_BLK_DONT_FRAGMENT)) {
- block->flags |= SQFS_BLK_IS_FRAGMENT;
- } else {
- proc->blk_flags &= ~SQFS_BLK_FIRST_BLOCK;
- }
-
- return append_to_work_queue(proc, block);
-}
-
-int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc,
- sqfs_inode_generic_t *inode, sqfs_u32 flags)
-{
- if (proc->inode != NULL)
- return SQFS_ERROR_SEQUENCE;
-
- if (flags & ~SQFS_BLK_USER_SETTABLE_FLAGS)
- return SQFS_ERROR_UNSUPPORTED;
-
- proc->inode = inode;
- proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK;
- return 0;
-}
-
-int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data,
- size_t size)
-{
- sqfs_block_t *new;
- size_t diff;
- int err;
-
- while (size > 0) {
- if (proc->blk_current == NULL) {
- new = alloc_flex(sizeof(*new), 1, proc->max_block_size);
- if (new == NULL)
- return SQFS_ERROR_ALLOC;
-
- proc->blk_current = new;
- proc->blk_current->flags = proc->blk_flags;
- proc->blk_current->inode = proc->inode;
- }
-
- diff = proc->max_block_size - proc->blk_current->size;
-
- if (diff == 0) {
- err = flush_block(proc);
- if (err)
- return err;
- continue;
- }
-
- if (diff > size)
- diff = size;
-
- memcpy(proc->blk_current->data + proc->blk_current->size,
- data, diff);
-
- size -= diff;
- proc->blk_current->size += diff;
- data = (const char *)data + diff;
-
- proc->stats.input_bytes_read += diff;
- }
-
- if (proc->blk_current != NULL &&
- proc->blk_current->size == proc->max_block_size) {
- return flush_block(proc);
- }
-
- return 0;
-}
-
-int sqfs_block_processor_end_file(sqfs_block_processor_t *proc)
-{
- int err;
-
- if (proc->inode == NULL)
- return SQFS_ERROR_SEQUENCE;
-
- if (!(proc->blk_flags & SQFS_BLK_FIRST_BLOCK)) {
- if (proc->blk_current != NULL &&
- (proc->blk_flags & SQFS_BLK_DONT_FRAGMENT)) {
- proc->blk_flags |= SQFS_BLK_LAST_BLOCK;
- } else {
- err = add_sentinel_block(proc);
- if (err)
- return err;
- }
- }
-
- if (proc->blk_current != NULL) {
- err = flush_block(proc);
- if (err)
- return err;
- }
-
- proc->inode = NULL;
- proc->blk_flags = 0;
- return 0;
-}