From e480a7459377817fbab7029a7dad47c969b8dd97 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 27 Jul 2019 00:17:51 +0200 Subject: Unify common file start/end code from data writer in helper functions Signed-off-by: David Oberhollenzer --- lib/sqfs/data_writer.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c index 9e20889..288bdd7 100644 --- a/lib/sqfs/data_writer.c +++ b/lib/sqfs/data_writer.c @@ -165,18 +165,33 @@ static int flush_data_block(data_writer_t *data, size_t size, return 0; } -int write_data_from_fd(data_writer_t *data, file_info_t *fi, - int infd, int flags) +static int begin_file(data_writer_t *data, file_info_t *fi, int flags) { - uint64_t count; - size_t diff; - if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0) return -1; fi->startblock = data->super->bytes_used; fi->sparse = 0; data->block_idx = 0; + return 0; +} + +static int end_file(data_writer_t *data, int flags) +{ + if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0) + return -1; + + return 0; +} + +int write_data_from_fd(data_writer_t *data, file_info_t *fi, + int infd, int flags) +{ + uint64_t count; + size_t diff; + + if (begin_file(data, fi, flags)) + return -1; for (count = fi->size; count != 0; count -= diff) { diff = count > (uint64_t)data->super->block_size ? @@ -189,10 +204,7 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi, return -1; } - if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0) - return -1; - - return 0; + return end_file(data, flags); } int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi, @@ -202,13 +214,9 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi, sparse_map_t *m; uint64_t offset; - if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0) + if (begin_file(data, fi, flags)) return -1; - fi->startblock = data->super->bytes_used; - fi->sparse = 0; - data->block_idx = 0; - if (map != NULL) { offset = map->offset; @@ -256,10 +264,7 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi, return -1; } - if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0) - return -1; - - return 0; + return end_file(data, flags); fail_map_size: fprintf(stderr, "%s: sparse file map spans beyond file size\n", fi->input_file); -- cgit v1.2.3