From eadeee25d9e284c805af810f6ccff450498588ce Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 17 Apr 2019 12:21:08 +0200 Subject: [PATCH] pkg2sqfs: move some functions to more approrpiate places Signed-off-by: David Oberhollenzer --- sqfs/block.c | 10 ---------- sqfs/meta.c | 9 --------- sqfs/pkg2sqfs.c | 36 ++++++++++++++++++++++++++++++++++++ sqfs/pkg2sqfs.h | 5 ----- sqfs/super.c | 36 ------------------------------------ sqfs/table.c | 23 +++++++++++++++++++++-- 6 files changed, 57 insertions(+), 62 deletions(-) diff --git a/sqfs/block.c b/sqfs/block.c index c97a36a..e0ec99c 100644 --- a/sqfs/block.c +++ b/sqfs/block.c @@ -200,13 +200,3 @@ fail_trunc: pkg_reader_get_filename(info->rd)); return -1; } - -int sqfs_write_fragment_table(sqfs_info_t *info) -{ - info->super.fragment_entry_count = info->num_fragments; - - return sqfs_write_table(info, info->fragments, - sizeof(info->fragments[0]), - info->num_fragments, - &info->super.fragment_table_start); -} diff --git a/sqfs/meta.c b/sqfs/meta.c index 0ff6217..1886fb7 100644 --- a/sqfs/meta.c +++ b/sqfs/meta.c @@ -294,12 +294,3 @@ fail_tmp: fclose(tmp); return -1; } - -int sqfs_write_ids(sqfs_info_t *info) -{ - info->super.flags |= SQFS_FLAG_UNCOMPRESSED_IDS; - - return sqfs_write_table(info, info->fs.id_tbl, - sizeof(info->fs.id_tbl[0]), - info->fs.num_ids, &info->super.id_table_start); -} diff --git a/sqfs/pkg2sqfs.c b/sqfs/pkg2sqfs.c index 330fb65..3ce5432 100644 --- a/sqfs/pkg2sqfs.c +++ b/sqfs/pkg2sqfs.c @@ -99,6 +99,42 @@ static long read_number(const char *name, const char *str, long min, long max) return result; } +static int sqfs_padd_file(sqfs_info_t *info) +{ + size_t padd_sz = info->super.bytes_used % info->dev_blk_size; + uint8_t *buffer; + ssize_t ret; + off_t off; + + if (padd_sz == 0) + return 0; + + off = lseek(info->outfd, 0, SEEK_END); + if (off == (off_t)-1) { + perror("seek on output file"); + return -1; + } + + padd_sz = info->dev_blk_size - padd_sz; + buffer = alloca(padd_sz); + memset(buffer, 0, padd_sz); + + ret = write_retry(info->outfd, buffer, padd_sz); + + if (ret < 0) { + perror("Error padding squashfs image to page size"); + return -1; + } + + if (ret == 0) { + fputs("Truncated write trying to padd squashfs image\n", + stderr); + return -1; + } + + return 0; +} + int main(int argc, char **argv) { uint32_t blocksize = SQFS_DEFAULT_BLOCK_SIZE, timestamp = 0; diff --git a/sqfs/pkg2sqfs.h b/sqfs/pkg2sqfs.h index 5240012..bd9e878 100644 --- a/sqfs/pkg2sqfs.h +++ b/sqfs/pkg2sqfs.h @@ -133,9 +133,4 @@ int meta_writer_flush(meta_writer_t *m); int meta_writer_append(meta_writer_t *m, const void *data, size_t size); -int sqfs_write_table(sqfs_info_t *info, const void *data, size_t entsize, - size_t count, uint64_t *start); - -int sqfs_padd_file(sqfs_info_t *info); - #endif /* PKG2SQFS_H */ diff --git a/sqfs/super.c b/sqfs/super.c index 8b27132..0241866 100644 --- a/sqfs/super.c +++ b/sqfs/super.c @@ -97,39 +97,3 @@ int sqfs_super_write(sqfs_info_t *info) return 0; } - -int sqfs_padd_file(sqfs_info_t *info) -{ - size_t padd_sz = info->super.bytes_used % info->dev_blk_size; - uint8_t *buffer; - ssize_t ret; - off_t off; - - if (padd_sz == 0) - return 0; - - off = lseek(info->outfd, 0, SEEK_END); - if (off == (off_t)-1) { - perror("seek on output file"); - return -1; - } - - padd_sz = info->dev_blk_size - padd_sz; - buffer = alloca(padd_sz); - memset(buffer, 0, padd_sz); - - ret = write_retry(info->outfd, buffer, padd_sz); - - if (ret < 0) { - perror("Error padding squashfs image to page size"); - return -1; - } - - if (ret == 0) { - fputs("Truncated write trying to padd squashfs image\n", - stderr); - return -1; - } - - return 0; -} diff --git a/sqfs/table.c b/sqfs/table.c index 64a0dff..4024b83 100644 --- a/sqfs/table.c +++ b/sqfs/table.c @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: ISC */ #include "pkg2sqfs.h" -int sqfs_write_table(sqfs_info_t *info, const void *data, size_t entsize, - size_t count, uint64_t *startblock) +static int sqfs_write_table(sqfs_info_t *info, const void *data, + size_t entsize, size_t count, uint64_t *startblock) { size_t ent_per_blocks = SQFS_META_BLOCK_SIZE / entsize; uint64_t blocks[count / ent_per_blocks + 1]; @@ -56,3 +56,22 @@ fail: meta_writer_destroy(m); return -1; } + +int sqfs_write_fragment_table(sqfs_info_t *info) +{ + info->super.fragment_entry_count = info->num_fragments; + + return sqfs_write_table(info, info->fragments, + sizeof(info->fragments[0]), + info->num_fragments, + &info->super.fragment_table_start); +} + +int sqfs_write_ids(sqfs_info_t *info) +{ + info->super.flags |= SQFS_FLAG_UNCOMPRESSED_IDS; + + return sqfs_write_table(info, info->fs.id_tbl, + sizeof(info->fs.id_tbl[0]), + info->fs.num_ids, &info->super.id_table_start); +}