aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-06-07 11:26:27 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-06-07 11:26:27 +0200
commit5179a76bad4b760e76d1e3e18ca4c0a0a1edb6b4 (patch)
tree956a6787d40abd26b3a4da53563db2cde6bf20fd /lib/sqfs
parent7ee3c177dc58dfc15dc7208a17c8756c99f61429 (diff)
libsquashfs: fix block alignment if requested
1) If the block alignment flag is set, the padding bytes must be inserted _before_ recording the start position, otherwise the resulting image is not readable. 2) Also perform alignment if the flag is set on a fragment block. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/block_writer.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c
index f6dea26..54f0c89 100644
--- a/lib/sqfs/block_writer.c
+++ b/lib/sqfs/block_writer.c
@@ -187,15 +187,17 @@ static int write_data_block(sqfs_block_writer_t *base, void *user,
int err;
(void)user;
- if (flags & SQFS_BLK_FIRST_BLOCK) {
- wr->start = wr->file->get_size(wr->file);
- wr->file_start = wr->num_blocks;
-
+ if (flags & (SQFS_BLK_FIRST_BLOCK | SQFS_BLK_FRAGMENT_BLOCK)) {
if (flags & SQFS_BLK_ALIGN) {
err = align_file(wr);
if (err)
return err;
}
+
+ if (flags & SQFS_BLK_FIRST_BLOCK) {
+ wr->start = wr->file->get_size(wr->file);
+ wr->file_start = wr->num_blocks;
+ }
}
offset = wr->file->get_size(wr->file);
@@ -217,13 +219,15 @@ static int write_data_block(sqfs_block_writer_t *base, void *user,
wr->blocks_written = wr->num_blocks;
}
- if (flags & SQFS_BLK_LAST_BLOCK) {
- if (flags & SQFS_BLK_ALIGN) {
+ if (flags & SQFS_BLK_ALIGN) {
+ if (flags & (SQFS_BLK_LAST_BLOCK | SQFS_BLK_FRAGMENT_BLOCK)) {
err = align_file(wr);
if (err)
return err;
}
+ }
+ if (flags & SQFS_BLK_LAST_BLOCK) {
count = wr->num_blocks - wr->file_start;
if (count == 0) {