summaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-05 17:10:33 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-05 17:12:04 +0200
commitdd5d7adaa914982e8947bfe76fa3f195ed11cdb1 (patch)
tree541325774fa90814fbef1e9f9c5677c8330ef8c1 /lib/sqfs
parentd5f89c52d219332c48a46aa297bb4896e8c159aa (diff)
Cleanup: add sqfs_* prefix to meta writer
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/dir_writer.c26
-rw-r--r--lib/sqfs/meta_writer.c27
-rw-r--r--lib/sqfs/write_inode.c41
-rw-r--r--lib/sqfs/write_table.c14
4 files changed, 59 insertions, 49 deletions
diff --git a/lib/sqfs/dir_writer.c b/lib/sqfs/dir_writer.c
index 3ef3bc7..2fb655a 100644
--- a/lib/sqfs/dir_writer.c
+++ b/lib/sqfs/dir_writer.c
@@ -43,7 +43,7 @@ struct sqfs_dir_writer_t {
uint64_t dir_ref;
size_t dir_size;
size_t idx_size;
- meta_writer_t *dm;
+ sqfs_meta_writer_t *dm;
};
static int get_type(mode_t mode)
@@ -85,7 +85,7 @@ static void writer_reset(sqfs_dir_writer_t *writer)
writer->idx_size = 0;
}
-sqfs_dir_writer_t *sqfs_dir_writer_create(meta_writer_t *dm)
+sqfs_dir_writer_t *sqfs_dir_writer_create(sqfs_meta_writer_t *dm)
{
sqfs_dir_writer_t *writer = calloc(1, sizeof(*writer));
@@ -111,7 +111,7 @@ int sqfs_dir_writer_begin(sqfs_dir_writer_t *writer)
writer_reset(writer);
- meta_writer_get_position(writer->dm, &block, &offset);
+ sqfs_meta_writer_get_position(writer->dm, &block, &offset);
writer->dir_ref = (block << 16) | offset;
return 0;
}
@@ -185,7 +185,7 @@ static int add_header(sqfs_dir_writer_t *writer, size_t count,
hdr.start_block = htole32(ref->inode_ref >> 16);
hdr.inode_number = htole32(ref->inode_num);
- if (meta_writer_append(writer->dm, &hdr, sizeof(hdr)))
+ if (sqfs_meta_writer_append(writer->dm, &hdr, sizeof(hdr)))
return -1;
idx = calloc(1, sizeof(*idx));
@@ -220,7 +220,7 @@ int sqfs_dir_writer_end(sqfs_dir_writer_t *writer)
uint64_t block;
for (it = writer->list; it != NULL; ) {
- meta_writer_get_position(writer->dm, &block, &offset);
+ sqfs_meta_writer_get_position(writer->dm, &block, &offset);
count = get_conseq_entry_count(offset, it);
if (add_header(writer, count, it, block))
@@ -237,11 +237,15 @@ int sqfs_dir_writer_end(sqfs_dir_writer_t *writer)
diff_u16 = (uint16_t *)&ent.inode_diff;
*diff_u16 = htole16(*diff_u16);
- if (meta_writer_append(writer->dm, &ent, sizeof(ent)))
+ if (sqfs_meta_writer_append(writer->dm, &ent,
+ sizeof(ent))) {
return -1;
+ }
- if (meta_writer_append(writer->dm, it->name, it->name_len))
+ if (sqfs_meta_writer_append(writer->dm, it->name,
+ it->name_len)) {
return -1;
+ }
it = it->next;
}
@@ -266,7 +270,7 @@ size_t sqfs_dir_writer_get_index_size(sqfs_dir_writer_t *writer)
}
int sqfs_dir_writer_write_index(sqfs_dir_writer_t *writer,
- meta_writer_t *im)
+ sqfs_meta_writer_t *im)
{
sqfs_dir_index_t ent;
index_ent_t *idx;
@@ -276,11 +280,13 @@ int sqfs_dir_writer_write_index(sqfs_dir_writer_t *writer,
ent.index = htole32(idx->index);
ent.size = htole32(idx->ent->name_len - 1);
- if (meta_writer_append(im, &ent, sizeof(ent)))
+ if (sqfs_meta_writer_append(im, &ent, sizeof(ent)))
return -1;
- if (meta_writer_append(im, idx->ent->name, idx->ent->name_len))
+ if (sqfs_meta_writer_append(im, idx->ent->name,
+ idx->ent->name_len)) {
return -1;
+ }
}
return 0;
diff --git a/lib/sqfs/meta_writer.c b/lib/sqfs/meta_writer.c
index 1f7825a..c85a12e 100644
--- a/lib/sqfs/meta_writer.c
+++ b/lib/sqfs/meta_writer.c
@@ -22,7 +22,7 @@ typedef struct meta_block_t {
uint8_t data[SQFS_META_BLOCK_SIZE + 2];
} meta_block_t;
-struct meta_writer_t {
+struct sqfs_meta_writer_t {
/* A byte offset into the uncompressed data of the current block */
size_t offset;
@@ -51,9 +51,10 @@ static int write_block(int fd, meta_block_t *outblk)
outblk->data, count + 2);
}
-meta_writer_t *meta_writer_create(int fd, compressor_t *cmp, bool keep_in_mem)
+sqfs_meta_writer_t *sqfs_meta_writer_create(int fd, compressor_t *cmp,
+ bool keep_in_mem)
{
- meta_writer_t *m = calloc(1, sizeof(*m));
+ sqfs_meta_writer_t *m = calloc(1, sizeof(*m));
if (m == NULL) {
perror("creating meta data writer");
@@ -66,7 +67,7 @@ meta_writer_t *meta_writer_create(int fd, compressor_t *cmp, bool keep_in_mem)
return m;
}
-void meta_writer_destroy(meta_writer_t *m)
+void sqfs_meta_writer_destroy(sqfs_meta_writer_t *m)
{
meta_block_t *blk;
@@ -79,7 +80,7 @@ void meta_writer_destroy(meta_writer_t *m)
free(m);
}
-int meta_writer_flush(meta_writer_t *m)
+int sqfs_meta_writer_flush(sqfs_meta_writer_t *m)
{
meta_block_t *outblk;
size_t count;
@@ -129,7 +130,8 @@ int meta_writer_flush(meta_writer_t *m)
return ret;
}
-int meta_writer_append(meta_writer_t *m, const void *data, size_t size)
+int sqfs_meta_writer_append(sqfs_meta_writer_t *m, const void *data,
+ size_t size)
{
size_t diff;
@@ -137,7 +139,7 @@ int meta_writer_append(meta_writer_t *m, const void *data, size_t size)
diff = sizeof(m->data) - m->offset;
if (diff == 0) {
- if (meta_writer_flush(m))
+ if (sqfs_meta_writer_flush(m))
return -1;
diff = sizeof(m->data);
}
@@ -152,25 +154,26 @@ int meta_writer_append(meta_writer_t *m, const void *data, size_t size)
}
if (m->offset == sizeof(m->data))
- return meta_writer_flush(m);
+ return sqfs_meta_writer_flush(m);
return 0;
}
-void meta_writer_get_position(const meta_writer_t *m, uint64_t *block_start,
- uint32_t *offset)
+void sqfs_meta_writer_get_position(const sqfs_meta_writer_t *m,
+ uint64_t *block_start,
+ uint32_t *offset)
{
*block_start = m->block_offset;
*offset = m->offset;
}
-void meta_writer_reset(meta_writer_t *m)
+void sqfs_meta_writer_reset(sqfs_meta_writer_t *m)
{
m->block_offset = 0;
m->offset = 0;
}
-int meta_write_write_to_file(meta_writer_t *m)
+int sqfs_meta_write_write_to_file(sqfs_meta_writer_t *m)
{
meta_block_t *blk;
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index 258f516..408e428 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -8,7 +8,7 @@
#include "sqfs/inode.h"
-static int write_block_sizes(meta_writer_t *ir, sqfs_inode_generic_t *n)
+static int write_block_sizes(sqfs_meta_writer_t *ir, sqfs_inode_generic_t *n)
{
uint32_t sizes[n->num_file_blocks];
size_t i;
@@ -16,11 +16,12 @@ static int write_block_sizes(meta_writer_t *ir, sqfs_inode_generic_t *n)
for (i = 0; i < n->num_file_blocks; ++i)
sizes[i] = htole32(n->block_sizes[i]);
- return meta_writer_append(ir, sizes,
- sizeof(uint32_t) * n->num_file_blocks);
+ return sqfs_meta_writer_append(ir, sizes,
+ sizeof(uint32_t) * n->num_file_blocks);
}
-int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
+int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir,
+ sqfs_inode_generic_t *n)
{
sqfs_inode_t base;
@@ -31,7 +32,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
base.mod_time = htole32(n->base.mod_time);
base.inode_number = htole32(n->base.inode_number);
- if (meta_writer_append(ir, &base, sizeof(base)))
+ if (sqfs_meta_writer_append(ir, &base, sizeof(base)))
return -1;
switch (n->base.type) {
@@ -43,7 +44,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
.offset = htole16(n->data.dir.offset),
.parent_inode = htole32(n->data.dir.parent_inode),
};
- return meta_writer_append(ir, &dir, sizeof(dir));
+ return sqfs_meta_writer_append(ir, &dir, sizeof(dir));
}
case SQFS_INODE_FILE: {
sqfs_inode_file_t file = {
@@ -53,7 +54,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
htole32(n->data.file.fragment_offset),
.file_size = htole32(n->data.file.file_size),
};
- if (meta_writer_append(ir, &file, sizeof(file)))
+ if (sqfs_meta_writer_append(ir, &file, sizeof(file)))
return -1;
return write_block_sizes(ir, n);
}
@@ -62,10 +63,10 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
.nlink = htole32(n->data.slink.nlink),
.target_size = htole32(n->data.slink.target_size),
};
- if (meta_writer_append(ir, &slink, sizeof(slink)))
+ if (sqfs_meta_writer_append(ir, &slink, sizeof(slink)))
return -1;
- return meta_writer_append(ir, n->slink_target,
- n->data.slink.target_size);
+ return sqfs_meta_writer_append(ir, n->slink_target,
+ n->data.slink.target_size);
}
case SQFS_INODE_BDEV:
case SQFS_INODE_CDEV: {
@@ -73,14 +74,14 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
.nlink = htole32(n->data.dev.nlink),
.devno = htole32(n->data.dev.devno),
};
- return meta_writer_append(ir, &dev, sizeof(dev));
+ return sqfs_meta_writer_append(ir, &dev, sizeof(dev));
}
case SQFS_INODE_FIFO:
case SQFS_INODE_SOCKET: {
sqfs_inode_ipc_t ipc = {
.nlink = htole32(n->data.ipc.nlink),
};
- return meta_writer_append(ir, &ipc, sizeof(ipc));
+ return sqfs_meta_writer_append(ir, &ipc, sizeof(ipc));
}
case SQFS_INODE_EXT_DIR: {
sqfs_inode_dir_ext_t dir = {
@@ -92,7 +93,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
.offset = htole16(n->data.dir_ext.offset),
.xattr_idx = htole32(n->data.dir_ext.xattr_idx),
};
- return meta_writer_append(ir, &dir, sizeof(dir));
+ return sqfs_meta_writer_append(ir, &dir, sizeof(dir));
}
case SQFS_INODE_EXT_FILE: {
sqfs_inode_file_ext_t file = {
@@ -105,7 +106,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
htole32(n->data.file_ext.fragment_offset),
.xattr_idx = htole32(n->data.file_ext.xattr_idx),
};
- if (meta_writer_append(ir, &file, sizeof(file)))
+ if (sqfs_meta_writer_append(ir, &file, sizeof(file)))
return -1;
return write_block_sizes(ir, n);
}
@@ -116,13 +117,13 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
};
uint32_t xattr = htole32(n->data.slink_ext.xattr_idx);
- if (meta_writer_append(ir, &slink, sizeof(slink)))
+ if (sqfs_meta_writer_append(ir, &slink, sizeof(slink)))
return -1;
- if (meta_writer_append(ir, n->slink_target,
- n->data.slink_ext.target_size)) {
+ if (sqfs_meta_writer_append(ir, n->slink_target,
+ n->data.slink_ext.target_size)) {
return -1;
}
- return meta_writer_append(ir, &xattr, sizeof(xattr));
+ return sqfs_meta_writer_append(ir, &xattr, sizeof(xattr));
}
case SQFS_INODE_EXT_BDEV:
case SQFS_INODE_EXT_CDEV: {
@@ -131,7 +132,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
.devno = htole32(n->data.dev_ext.devno),
.xattr_idx = htole32(n->data.dev_ext.xattr_idx),
};
- return meta_writer_append(ir, &dev, sizeof(dev));
+ return sqfs_meta_writer_append(ir, &dev, sizeof(dev));
}
case SQFS_INODE_EXT_FIFO:
case SQFS_INODE_EXT_SOCKET: {
@@ -139,7 +140,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
.nlink = htole32(n->data.ipc_ext.nlink),
.xattr_idx = htole32(n->data.ipc_ext.xattr_idx),
};
- return meta_writer_append(ir, &ipc, sizeof(ipc));
+ return sqfs_meta_writer_append(ir, &ipc, sizeof(ipc));
}
}
diff --git a/lib/sqfs/write_table.c b/lib/sqfs/write_table.c
index a2814a4..7c24087 100644
--- a/lib/sqfs/write_table.c
+++ b/lib/sqfs/write_table.c
@@ -19,7 +19,7 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, compressor_t *cmp,
{
size_t block_count, list_size, diff, blkidx = 0;
uint64_t block, *locations;
- meta_writer_t *m;
+ sqfs_meta_writer_t *m;
uint32_t offset;
int ret = -1;
@@ -35,29 +35,29 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, compressor_t *cmp,
}
/* Write actual data */
- m = meta_writer_create(outfd, cmp, false);
+ m = sqfs_meta_writer_create(outfd, cmp, false);
if (m == NULL)
goto out_idx;
while (table_size > 0) {
- meta_writer_get_position(m, &block, &offset);
+ sqfs_meta_writer_get_position(m, &block, &offset);
locations[blkidx++] = htole64(super->bytes_used + block);
diff = SQFS_META_BLOCK_SIZE;
if (diff > table_size)
diff = table_size;
- if (meta_writer_append(m, data, diff))
+ if (sqfs_meta_writer_append(m, data, diff))
goto out;
data = (const char *)data + diff;
table_size -= diff;
}
- if (meta_writer_flush(m))
+ if (sqfs_meta_writer_flush(m))
goto out;
- meta_writer_get_position(m, &block, &offset);
+ sqfs_meta_writer_get_position(m, &block, &offset);
super->bytes_used += block;
/* write location list */
@@ -72,7 +72,7 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, compressor_t *cmp,
/* cleanup */
ret = 0;
out:
- meta_writer_destroy(m);
+ sqfs_meta_writer_destroy(m);
out_idx:
free(locations);
return ret;