aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-16 19:29:27 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-16 22:47:59 +0200
commitbfd876dbf151df164b4d87de20aec39b24f205f9 (patch)
tree53ac348da6c430b1ecf5f546ee4758ac73cb16e0 /lib/sqfs
parent74a064d9f15fa2d534e8b2d1ade68d10d5b65dfd (diff)
cleanup: move error handling into write_retry
If write_retry fails to write everything, it is *always* an error. This commit renames write_retry to write_data and moves error handling into the function, making a lot of error handling code redundant. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/data_reader.c26
-rw-r--r--lib/sqfs/data_writer.c14
-rw-r--r--lib/sqfs/meta_writer.c20
-rw-r--r--lib/sqfs/super.c13
-rw-r--r--lib/sqfs/table.c11
-rw-r--r--lib/sqfs/write_xattr.c23
6 files changed, 22 insertions, 85 deletions
diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c
index ec85412..7f857b2 100644
--- a/lib/sqfs/data_reader.c
+++ b/lib/sqfs/data_reader.c
@@ -133,12 +133,10 @@ int data_reader_dump_file(data_reader_t *data, file_info_t *fi, int outfd,
ptr = data->buffer;
}
- ret = write_retry(outfd, ptr, unpackedsz);
- if (ret < 0)
- goto fail_wr;
-
- if ((size_t)ret < bs)
- goto fail_wr_trunc;
+ if (write_data("writing uncompressed block",
+ outfd, ptr, unpackedsz)) {
+ return -1;
+ }
}
}
@@ -152,12 +150,10 @@ int data_reader_dump_file(data_reader_t *data, file_info_t *fi, int outfd,
return -1;
}
- ret = write_retry(outfd, data->buffer, fragsz);
- if (ret < 0)
- goto fail_wr;
-
- if ((size_t)ret < fragsz)
- goto fail_wr_trunc;
+ if (write_data("writing uncompressed fragment",
+ outfd, data->buffer, fragsz)) {
+ return -1;
+ }
}
return 0;
@@ -167,12 +163,6 @@ fail_sparse:
fail_seek:
perror("seek on squashfs");
return -1;
-fail_wr:
- perror("writing uncompressed block");
- return -1;
-fail_wr_trunc:
- fputs("writing uncompressed block: truncated write\n", stderr);
- return -1;
fail_rd:
perror("reading from squashfs");
return -1;
diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c
index cbe2351..eebd2a4 100644
--- a/lib/sqfs/data_writer.c
+++ b/lib/sqfs/data_writer.c
@@ -41,24 +41,16 @@ static int write_compressed(data_writer_t *data, const void *in, size_t size,
if (ret > 0 && (size_t)ret < size) {
size = ret;
- ret = write_retry(data->outfd, data->scratch, size);
+ in = data->scratch;
*outsize = size;
} else {
- ret = write_retry(data->outfd, in, size);
*outsize = size | (1 << 24);
}
- if (ret < 0) {
- perror("writing to output file");
+ if (write_data("writing data block", data->outfd, in, size))
return -1;
- }
-
- if ((size_t)ret < size) {
- fputs("write to output file truncated\n", stderr);
- return -1;
- }
- data->super->bytes_used += ret;
+ data->super->bytes_used += size;
return 0;
}
diff --git a/lib/sqfs/meta_writer.c b/lib/sqfs/meta_writer.c
index ef869e7..d55af3d 100644
--- a/lib/sqfs/meta_writer.c
+++ b/lib/sqfs/meta_writer.c
@@ -38,24 +38,10 @@ struct meta_writer_t {
static int write_block(int fd, meta_block_t *outblk)
{
- size_t count;
- ssize_t ret;
-
- count = le16toh(((uint16_t *)outblk->data)[0]) & 0x7FFF;
-
- ret = write_retry(fd, outblk->data, count + 2);
-
- if (ret < 0) {
- perror("writing meta data block");
- return -1;
- }
-
- if ((size_t)ret < count) {
- fputs("meta data written to file was truncated\n", stderr);
- return -1;
- }
+ size_t count = le16toh(((uint16_t *)outblk->data)[0]) & 0x7FFF;
- return 0;
+ return write_data("writing meta data block", fd,
+ outblk->data, count + 2);
}
meta_writer_t *meta_writer_create(int fd, compressor_t *cmp, bool keep_in_mem)
diff --git a/lib/sqfs/super.c b/lib/sqfs/super.c
index d3b79c6..59eb366 100644
--- a/lib/sqfs/super.c
+++ b/lib/sqfs/super.c
@@ -47,7 +47,6 @@ int sqfs_super_init(sqfs_super_t *super, size_t block_size, uint32_t mtime,
int sqfs_super_write(sqfs_super_t *super, int fd)
{
sqfs_super_t copy;
- ssize_t ret;
copy.magic = htole32(super->magic);
copy.inode_count = htole32(super->inode_count);
@@ -72,18 +71,8 @@ int sqfs_super_write(sqfs_super_t *super, int fd)
if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
goto fail_seek;
- ret = write_retry(fd, &copy, sizeof(copy));
-
- if (ret < 0) {
- perror("squashfs writing super block");
+ if (write_data("writing super block", fd, &copy, sizeof(copy)))
return -1;
- }
-
- if ((size_t)ret < sizeof(copy)) {
- fputs("squashfs writing super block: truncated write\n",
- stderr);
- return -1;
- }
if (lseek(fd, 0, SEEK_END) == (off_t)-1)
goto fail_seek;
diff --git a/lib/sqfs/table.c b/lib/sqfs/table.c
index fb6bddc..81e7691 100644
--- a/lib/sqfs/table.c
+++ b/lib/sqfs/table.c
@@ -15,7 +15,6 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, const void *data,
size_t i, blkidx = 0, tblsize;
meta_writer_t *m;
uint32_t offset;
- ssize_t ret;
/* Write actual data. Whenever we cross a block boundary, remember
the block start offset */
@@ -49,16 +48,8 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, const void *data,
*startblock = super->bytes_used;
tblsize = sizeof(blocks[0]) * blkidx;
- ret = write_retry(outfd, blocks, tblsize);
- if (ret < 0) {
- perror("writing index table");
+ if (write_data("writing table index", outfd, blocks, tblsize))
return -1;
- }
-
- if ((size_t)ret < tblsize) {
- fputs("index table truncated\n", stderr);
- return -1;
- }
super->bytes_used += tblsize;
return 0;
diff --git a/lib/sqfs/write_xattr.c b/lib/sqfs/write_xattr.c
index 0e11757..31fdf50 100644
--- a/lib/sqfs/write_xattr.c
+++ b/lib/sqfs/write_xattr.c
@@ -105,7 +105,6 @@ int write_xattr(int outfd, fstree_t *fs, sqfs_super_t *super,
meta_writer_t *mw;
tree_xattr_t *it;
uint32_t offset;
- ssize_t ret;
if (fs->xattr == NULL)
return 0;
@@ -179,17 +178,13 @@ int write_xattr(int outfd, fstree_t *fs, sqfs_super_t *super,
idtbl.xattr_ids = htole32(count);
idtbl.unused = 0;
- ret = write_retry(outfd, &idtbl, sizeof(idtbl));
- if (ret < 0)
- goto fail_wr;
- if ((size_t)ret < sizeof(idtbl))
- goto fail_trunc;
+ if (write_data("writing xattr ID table", outfd, &idtbl, sizeof(idtbl)))
+ goto fail_tbl;
- ret = write_retry(outfd, tbl, sizeof(tbl[0]) * blocks);
- if (ret < 0)
- goto fail_wr;
- if ((size_t)ret < sizeof(tbl[0]) * blocks)
- goto fail_trunc;
+ if (write_data("writing xattr ID table",
+ outfd, tbl, sizeof(tbl[0]) * blocks)) {
+ goto fail_tbl;
+ }
super->xattr_id_table_start = super->bytes_used;
super->bytes_used += sizeof(idtbl) + sizeof(tbl[0]) * blocks;
@@ -197,12 +192,6 @@ int write_xattr(int outfd, fstree_t *fs, sqfs_super_t *super,
free(tbl);
meta_writer_destroy(mw);
return 0;
-fail_wr:
- perror("writing xattr ID table");
- goto fail_tbl;
-fail_trunc:
- fputs("writing xattr ID table: truncated write\n", stderr);
- goto fail_tbl;
fail_tbl:
free(tbl);
fail_mw: