summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 01:56:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-11 01:56:28 +0200
commit8825f5973740ae2baaab4d61ac16bc870873c167 (patch)
tree41b5eb84a35898b60315133fe039cae4cf0ea10f
parent5038c4b33ea403203b8edd82b44a8db06464409b (diff)
Split process_file function
Add a generic one that reads and processes N bytes from an input file descriptor. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--mkfs/block.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/mkfs/block.c b/mkfs/block.c
index f023876..896cefc 100644
--- a/mkfs/block.c
+++ b/mkfs/block.c
@@ -82,19 +82,14 @@ static int flush_fragments(sqfs_info_t *info)
return 0;
}
-static int process_file(sqfs_info_t *info, file_info_t *fi)
+static int write_data_from_fd(sqfs_info_t *info, file_info_t *fi, int infd)
{
- int infd, ret, blk_idx = 0;
uint64_t count = fi->size;
+ int blk_idx = 0;
uint32_t out;
+ ssize_t ret;
size_t diff;
- infd = open(fi->input_file, O_RDONLY);
- if (infd < 0) {
- perror(fi->input_file);
- return -1;
- }
-
fi->startblock = info->super.bytes_used;
while (count != 0) {
@@ -110,7 +105,7 @@ static int process_file(sqfs_info_t *info, file_info_t *fi)
if (diff < info->super.block_size) {
if (info->frag_offset + diff > info->super.block_size) {
if (flush_fragments(info))
- goto fail;
+ return -1;
}
fi->fragment_offset = info->frag_offset;
@@ -122,7 +117,7 @@ static int process_file(sqfs_info_t *info, file_info_t *fi)
} else {
if (write_compressed(info, info->block,
info->super.block_size, &out)) {
- goto fail;
+ return -1;
}
fi->blocksizes[blk_idx++] = out;
@@ -131,17 +126,29 @@ static int process_file(sqfs_info_t *info, file_info_t *fi)
count -= diff;
}
- close(infd);
return 0;
-fail:
- close(infd);
- return -1;
fail_read:
fprintf(stderr, "read from %s: %s\n", fi->input_file, strerror(errno));
- goto fail;
+ return -1;
fail_trunc:
fprintf(stderr, "%s: truncated read\n", fi->input_file);
- goto fail;
+ return -1;
+}
+
+static int process_file(sqfs_info_t *info, file_info_t *fi)
+{
+ int ret, infd;
+
+ infd = open(fi->input_file, O_RDONLY);
+ if (infd < 0) {
+ perror(fi->input_file);
+ return -1;
+ }
+
+ ret = write_data_from_fd(info, fi, infd);
+
+ close(infd);
+ return ret;
}
static void print_name(tree_node_t *n)