diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-01-19 20:05:13 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-01-19 20:05:13 +0100 |
commit | 4a091b656c0861e3f9335c38af25040cb3ff03c8 (patch) | |
tree | 263ee5a322bd263125ae07ef40ef5fed31812b29 /lib | |
parent | 001d3dc914d19b3d85aa04f2a042837cef4af0e4 (diff) |
Cleanup: remove the payload pointers from sqfs_inode_generic_t
There are 3 types of extra payload:
- Directory index
- File block sizes
- Symlink target
This commit removes the type specific pointers and modifies the code
to use the payload area directly. To simplify the file block case and
mitigate alignment issues, the type of the extra field is changed to
sqfs_u32.
For symlink target, the extra field can simply be cast to a character
pointer (it had to be cast anyway for most uses). For block sizes,
probably the most common usecase, it can be used as is. For directory
indices, there is a helper function anyway.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common/data_reader_dump.c | 3 | ||||
-rw-r--r-- | lib/common/serialize_fstree.c | 1 | ||||
-rw-r--r-- | lib/sqfs/data_reader.c | 15 | ||||
-rw-r--r-- | lib/sqfs/data_writer/block.c | 2 | ||||
-rw-r--r-- | lib/sqfs/data_writer/fileapi.c | 2 | ||||
-rw-r--r-- | lib/sqfs/dir_writer.c | 3 | ||||
-rw-r--r-- | lib/sqfs/inode.c | 3 | ||||
-rw-r--r-- | lib/sqfs/read_inode.c | 19 | ||||
-rw-r--r-- | lib/sqfs/write_inode.c | 9 |
9 files changed, 23 insertions, 34 deletions
diff --git a/lib/common/data_reader_dump.c b/lib/common/data_reader_dump.c index 96103ce..bf418c6 100644 --- a/lib/common/data_reader_dump.c +++ b/lib/common/data_reader_dump.c @@ -60,8 +60,7 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, for (i = 0; i < inode->num_file_blocks; ++i) { diff = (filesz < block_size) ? filesz : block_size; - if (SQFS_IS_SPARSE_BLOCK(inode->block_sizes[i]) && - allow_sparse) { + if (SQFS_IS_SPARSE_BLOCK(inode->extra[i]) && allow_sparse) { if (fseek(fp, diff, SEEK_CUR) < 0) goto fail_sparse; } else { diff --git a/lib/common/serialize_fstree.c b/lib/common/serialize_fstree.c index f20ae07..c69f0ea 100644 --- a/lib/common/serialize_fstree.c +++ b/lib/common/serialize_fstree.c @@ -38,7 +38,6 @@ static sqfs_inode_generic_t *tree_node_to_inode(tree_node_t *node) inode->base.type = SQFS_INODE_SLINK; inode->data.slink.nlink = node->link_count; inode->data.slink.target_size = extra; - inode->slink_target = (char *)inode->extra; memcpy(inode->extra, node->data.target, extra); break; case S_IFBLK: diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c index 6a0db35..af15b9b 100644 --- a/lib/sqfs/data_reader.c +++ b/lib/sqfs/data_reader.c @@ -219,14 +219,13 @@ int sqfs_data_reader_get_block(sqfs_data_reader_t *data, return SQFS_ERROR_OUT_OF_BOUNDS; for (i = 0; i < index; ++i) { - off += SQFS_ON_DISK_BLOCK_SIZE(inode->block_sizes[i]); + off += SQFS_ON_DISK_BLOCK_SIZE(inode->extra[i]); filesz -= data->block_size; } unpacked_size = filesz < data->block_size ? filesz : data->block_size; - return get_block(data, off, inode->block_sizes[index], - unpacked_size, out); + return get_block(data, off, inode->extra[index], unpacked_size, out); } int sqfs_data_reader_get_fragment(sqfs_data_reader_t *data, @@ -285,7 +284,7 @@ sqfs_s32 sqfs_data_reader_read(sqfs_data_reader_t *data, i = 0; while (offset > data->block_size && i < inode->num_file_blocks) { - off += SQFS_ON_DISK_BLOCK_SIZE(inode->block_sizes[i++]); + off += SQFS_ON_DISK_BLOCK_SIZE(inode->extra[i++]); offset -= data->block_size; if (filesz >= data->block_size) { @@ -301,17 +300,15 @@ sqfs_s32 sqfs_data_reader_read(sqfs_data_reader_t *data, if (size < diff) diff = size; - if (SQFS_IS_SPARSE_BLOCK(inode->block_sizes[i])) { + if (SQFS_IS_SPARSE_BLOCK(inode->extra[i])) { memset(buffer, 0, diff); } else { - if (precache_data_block(data, off, - inode->block_sizes[i])) { + if (precache_data_block(data, off, inode->extra[i])) return -1; - } memcpy(buffer, (char *)data->data_block->data + offset, diff); - off += SQFS_ON_DISK_BLOCK_SIZE(inode->block_sizes[i]); + off += SQFS_ON_DISK_BLOCK_SIZE(inode->extra[i]); } if (filesz >= data->block_size) { diff --git a/lib/sqfs/data_writer/block.c b/lib/sqfs/data_writer/block.c index 9396e4a..5967e59 100644 --- a/lib/sqfs/data_writer/block.c +++ b/lib/sqfs/data_writer/block.c @@ -116,7 +116,7 @@ int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk) proc->fragments[blk->index].pad0 = 0; proc->fragments[blk->index].size = htole32(out); } else { - blk->inode->block_sizes[blk->index] = out; + blk->inode->extra[blk->index] = out; } err = store_block_location(proc, offset, out, blk->checksum); diff --git a/lib/sqfs/data_writer/fileapi.c b/lib/sqfs/data_writer/fileapi.c index de77690..89bac0b 100644 --- a/lib/sqfs/data_writer/fileapi.c +++ b/lib/sqfs/data_writer/fileapi.c @@ -67,7 +67,7 @@ static int flush_block(sqfs_data_writer_t *proc, sqfs_block_t *block) sqfs_inode_make_extended(proc->inode); proc->inode->data.file_ext.sparse += block->size; proc->inode->num_file_blocks += 1; - proc->inode->block_sizes[block->index] = 0; + proc->inode->extra[block->index] = 0; free(block); return 0; } diff --git a/lib/sqfs/dir_writer.c b/lib/sqfs/dir_writer.c index 78256a1..53e5800 100644 --- a/lib/sqfs/dir_writer.c +++ b/lib/sqfs/dir_writer.c @@ -419,7 +419,8 @@ sqfs_inode_generic_t ent.index = idx->index; ent.size = idx->ent->name_len - 1; - ptr = inode->extra + inode->num_dir_idx_bytes; + ptr = (sqfs_u8 *)inode->extra + + inode->num_dir_idx_bytes; memcpy(ptr, &ent, sizeof(ent)); memcpy(ptr + sizeof(ent), idx->ent->name, idx->ent->name_len); diff --git a/lib/sqfs/inode.c b/lib/sqfs/inode.c index 3a4ec09..815cc0f 100644 --- a/lib/sqfs/inode.c +++ b/lib/sqfs/inode.c @@ -72,9 +72,6 @@ int sqfs_inode_copy(const sqfs_inode_generic_t *src, return SQFS_ERROR_ALLOC; memcpy(copy, src, size); - copy->block_sizes = (sqfs_u32 *)copy->extra; - copy->slink_target = (char *)copy->extra; - *out = copy; return 0; } diff --git a/lib/sqfs/read_inode.c b/lib/sqfs/read_inode.c index f7bfff0..8653928 100644 --- a/lib/sqfs/read_inode.c +++ b/lib/sqfs/read_inode.c @@ -101,18 +101,16 @@ static int read_inode_file(sqfs_meta_reader_t *ir, sqfs_inode_t *base, out->base = *base; out->data.file = file; - out->block_sizes = (sqfs_u32 *)out->extra; out->num_file_blocks = count; - err = sqfs_meta_reader_read(ir, out->block_sizes, - count * sizeof(sqfs_u32)); + err = sqfs_meta_reader_read(ir, out->extra, count * sizeof(sqfs_u32)); if (err) { free(out); return err; } for (i = 0; i < count; ++i) - SWAB32(out->block_sizes[i]); + SWAB32(out->extra[i]); *result = out; return 0; @@ -149,18 +147,16 @@ static int read_inode_file_ext(sqfs_meta_reader_t *ir, sqfs_inode_t *base, out->base = *base; out->data.file_ext = file; - out->block_sizes = (sqfs_u32 *)out->extra; out->num_file_blocks = count; - err = sqfs_meta_reader_read(ir, out->block_sizes, - count * sizeof(sqfs_u32)); + err = sqfs_meta_reader_read(ir, out->extra, count * sizeof(sqfs_u32)); if (err) { free(out); return err; } for (i = 0; i < count; ++i) - SWAB32(out->block_sizes[i]); + SWAB32(out->extra[i]); *result = out; return 0; @@ -190,11 +186,10 @@ static int read_inode_slink(sqfs_meta_reader_t *ir, sqfs_inode_t *base, if (out == NULL) return SQFS_ERROR_ALLOC; - out->slink_target = (char *)out->extra; out->base = *base; out->data.slink = slink; - err = sqfs_meta_reader_read(ir, out->slink_target, slink.target_size); + err = sqfs_meta_reader_read(ir, (void *)out->extra, slink.target_size); if (err) { free(out); return err; @@ -290,10 +285,10 @@ static int read_inode_dir_ext(sqfs_meta_reader_t *ir, sqfs_inode_t *base, index_max = new_sz; } - memcpy(out->extra + index_used, &ent, sizeof(ent)); + memcpy((char *)out->extra + index_used, &ent, sizeof(ent)); index_used += sizeof(ent); - err = sqfs_meta_reader_read(ir, out->extra + index_used, + err = sqfs_meta_reader_read(ir, (char *)out->extra + index_used, ent.size + 1); if (err) { free(out); diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c index 5f0ef4c..b5ba905 100644 --- a/lib/sqfs/write_inode.c +++ b/lib/sqfs/write_inode.c @@ -22,7 +22,7 @@ static int write_block_sizes(sqfs_meta_writer_t *ir, size_t i; for (i = 0; i < n->num_file_blocks; ++i) - sizes[i] = htole32(n->block_sizes[i]); + sizes[i] = htole32(n->extra[i]); return sqfs_meta_writer_append(ir, sizes, sizeof(sqfs_u32) * n->num_file_blocks); @@ -112,7 +112,7 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir, ret = sqfs_meta_writer_append(ir, &slink, sizeof(slink)); if (ret) return ret; - return sqfs_meta_writer_append(ir, n->slink_target, + return sqfs_meta_writer_append(ir, n->extra, n->data.slink.target_size); } case SQFS_INODE_BDEV: @@ -143,7 +143,8 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir, ret = sqfs_meta_writer_append(ir, &dir, sizeof(dir)); if (ret) return ret; - return write_dir_index(ir, n->extra, n->num_dir_idx_bytes); + return write_dir_index(ir, (const sqfs_u8 *)n->extra, + n->num_dir_idx_bytes); } case SQFS_INODE_EXT_FILE: { sqfs_inode_file_ext_t file = { @@ -171,7 +172,7 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir, ret = sqfs_meta_writer_append(ir, &slink, sizeof(slink)); if (ret) return ret; - ret = sqfs_meta_writer_append(ir, n->slink_target, + ret = sqfs_meta_writer_append(ir, n->extra, n->data.slink_ext.target_size); if (ret) return ret; |