summaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/meta_reader.c21
-rw-r--r--lib/sqfs/read_inode.c60
-rw-r--r--lib/sqfs/read_table.c12
-rw-r--r--lib/sqfs/readdir.c11
-rw-r--r--lib/sqfs/xattr_reader.c42
5 files changed, 75 insertions, 71 deletions
diff --git a/lib/sqfs/meta_reader.c b/lib/sqfs/meta_reader.c
index 0183255..0fd892e 100644
--- a/lib/sqfs/meta_reader.c
+++ b/lib/sqfs/meta_reader.c
@@ -14,7 +14,7 @@
#include <string.h>
#include <stdio.h>
-struct meta_reader_t {
+struct sqfs_meta_reader_t {
uint64_t start;
uint64_t limit;
size_t data_used;
@@ -41,10 +41,10 @@ struct meta_reader_t {
uint8_t scratch[SQFS_META_BLOCK_SIZE];
};
-meta_reader_t *meta_reader_create(int fd, compressor_t *cmp,
- uint64_t start, uint64_t limit)
+sqfs_meta_reader_t *sqfs_meta_reader_create(int fd, compressor_t *cmp,
+ uint64_t start, uint64_t limit)
{
- meta_reader_t *m = calloc(1, sizeof(*m));
+ sqfs_meta_reader_t *m = calloc(1, sizeof(*m));
if (m == NULL) {
perror("creating meta data reader");
@@ -58,12 +58,13 @@ meta_reader_t *meta_reader_create(int fd, compressor_t *cmp,
return m;
}
-void meta_reader_destroy(meta_reader_t *m)
+void sqfs_meta_reader_destroy(sqfs_meta_reader_t *m)
{
free(m);
}
-int meta_reader_seek(meta_reader_t *m, uint64_t block_start, size_t offset)
+int sqfs_meta_reader_seek(sqfs_meta_reader_t *m, uint64_t block_start,
+ size_t offset)
{
bool compressed;
uint16_t header;
@@ -139,14 +140,14 @@ fail_range:
return -1;
}
-void meta_reader_get_position(meta_reader_t *m, uint64_t *block_start,
- size_t *offset)
+void sqfs_meta_reader_get_position(sqfs_meta_reader_t *m, uint64_t *block_start,
+ size_t *offset)
{
*block_start = m->block_offset;
*offset = m->offset;
}
-int meta_reader_read(meta_reader_t *m, void *data, size_t size)
+int sqfs_meta_reader_read(sqfs_meta_reader_t *m, void *data, size_t size)
{
size_t diff;
@@ -154,7 +155,7 @@ int meta_reader_read(meta_reader_t *m, void *data, size_t size)
diff = m->data_used - m->offset;
if (diff == 0) {
- if (meta_reader_seek(m, m->next_block, 0))
+ if (sqfs_meta_reader_seek(m, m->next_block, 0))
return -1;
diff = m->data_used;
}
diff --git a/lib/sqfs/read_inode.c b/lib/sqfs/read_inode.c
index 6da9653..90cc060 100644
--- a/lib/sqfs/read_inode.c
+++ b/lib/sqfs/read_inode.c
@@ -72,7 +72,7 @@ static uint64_t get_block_count(uint64_t size, uint64_t block_size,
return count;
}
-static sqfs_inode_generic_t *read_inode_file(meta_reader_t *ir,
+static sqfs_inode_generic_t *read_inode_file(sqfs_meta_reader_t *ir,
sqfs_inode_t *base,
size_t block_size)
{
@@ -80,7 +80,7 @@ static sqfs_inode_generic_t *read_inode_file(meta_reader_t *ir,
sqfs_inode_file_t file;
uint64_t i, count;
- if (meta_reader_read(ir, &file, sizeof(file)))
+ if (sqfs_meta_reader_read(ir, &file, sizeof(file)))
return NULL;
SWAB32(file.blocks_start);
@@ -102,7 +102,8 @@ static sqfs_inode_generic_t *read_inode_file(meta_reader_t *ir,
out->block_sizes = (uint32_t *)out->extra;
out->num_file_blocks = count;
- if (meta_reader_read(ir, out->block_sizes, count * sizeof(uint32_t))) {
+ if (sqfs_meta_reader_read(ir, out->block_sizes,
+ count * sizeof(uint32_t))) {
free(out);
return NULL;
}
@@ -113,7 +114,7 @@ static sqfs_inode_generic_t *read_inode_file(meta_reader_t *ir,
return out;
}
-static sqfs_inode_generic_t *read_inode_file_ext(meta_reader_t *ir,
+static sqfs_inode_generic_t *read_inode_file_ext(sqfs_meta_reader_t *ir,
sqfs_inode_t *base,
size_t block_size)
{
@@ -121,7 +122,7 @@ static sqfs_inode_generic_t *read_inode_file_ext(meta_reader_t *ir,
sqfs_inode_generic_t *out;
uint64_t i, count;
- if (meta_reader_read(ir, &file, sizeof(file)))
+ if (sqfs_meta_reader_read(ir, &file, sizeof(file)))
return NULL;
SWAB64(file.blocks_start);
@@ -146,7 +147,8 @@ static sqfs_inode_generic_t *read_inode_file_ext(meta_reader_t *ir,
out->block_sizes = (uint32_t *)out->extra;
out->num_file_blocks = count;
- if (meta_reader_read(ir, out->block_sizes, count * sizeof(uint32_t))) {
+ if (sqfs_meta_reader_read(ir, out->block_sizes,
+ count * sizeof(uint32_t))) {
free(out);
return NULL;
}
@@ -157,14 +159,14 @@ static sqfs_inode_generic_t *read_inode_file_ext(meta_reader_t *ir,
return out;
}
-static sqfs_inode_generic_t *read_inode_slink(meta_reader_t *ir,
+static sqfs_inode_generic_t *read_inode_slink(sqfs_meta_reader_t *ir,
sqfs_inode_t *base)
{
sqfs_inode_generic_t *out;
sqfs_inode_slink_t slink;
size_t size;
- if (meta_reader_read(ir, &slink, sizeof(slink)))
+ if (sqfs_meta_reader_read(ir, &slink, sizeof(slink)))
return NULL;
SWAB32(slink.nlink);
@@ -184,7 +186,7 @@ static sqfs_inode_generic_t *read_inode_slink(meta_reader_t *ir,
out->base = *base;
out->data.slink = slink;
- if (meta_reader_read(ir, out->slink_target, slink.target_size)) {
+ if (sqfs_meta_reader_read(ir, out->slink_target, slink.target_size)) {
free(out);
return NULL;
}
@@ -195,14 +197,14 @@ fail:
return NULL;
}
-static sqfs_inode_generic_t *read_inode_slink_ext(meta_reader_t *ir,
+static sqfs_inode_generic_t *read_inode_slink_ext(sqfs_meta_reader_t *ir,
sqfs_inode_t *base)
{
sqfs_inode_generic_t *out = read_inode_slink(ir, base);
uint32_t xattr;
if (out != NULL) {
- if (meta_reader_read(ir, &xattr, sizeof(xattr))) {
+ if (sqfs_meta_reader_read(ir, &xattr, sizeof(xattr))) {
free(out);
return NULL;
}
@@ -213,10 +215,10 @@ static sqfs_inode_generic_t *read_inode_slink_ext(meta_reader_t *ir,
return out;
}
-sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
- sqfs_super_t *super,
- uint64_t block_start,
- size_t offset)
+sqfs_inode_generic_t *sqfs_meta_reader_read_inode(sqfs_meta_reader_t *ir,
+ sqfs_super_t *super,
+ uint64_t block_start,
+ size_t offset)
{
sqfs_inode_generic_t *out;
sqfs_inode_t inode;
@@ -224,10 +226,10 @@ sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
/* read base inode */
block_start += super->inode_table_start;
- if (meta_reader_seek(ir, block_start, offset))
+ if (sqfs_meta_reader_seek(ir, block_start, offset))
return NULL;
- if (meta_reader_read(ir, &inode, sizeof(inode)))
+ if (sqfs_meta_reader_read(ir, &inode, sizeof(inode)))
return NULL;
SWAB16(inode.type);
@@ -265,8 +267,8 @@ sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
switch (inode.type) {
case SQFS_INODE_DIR:
- if (meta_reader_read(ir, &out->data.dir,
- sizeof(out->data.dir))) {
+ if (sqfs_meta_reader_read(ir, &out->data.dir,
+ sizeof(out->data.dir))) {
goto fail_free;
}
SWAB32(out->data.dir.start_block);
@@ -277,8 +279,8 @@ sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
break;
case SQFS_INODE_BDEV:
case SQFS_INODE_CDEV:
- if (meta_reader_read(ir, &out->data.dev,
- sizeof(out->data.dev))) {
+ if (sqfs_meta_reader_read(ir, &out->data.dev,
+ sizeof(out->data.dev))) {
goto fail_free;
}
SWAB32(out->data.dev.nlink);
@@ -286,15 +288,15 @@ sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
break;
case SQFS_INODE_FIFO:
case SQFS_INODE_SOCKET:
- if (meta_reader_read(ir, &out->data.ipc,
- sizeof(out->data.ipc))) {
+ if (sqfs_meta_reader_read(ir, &out->data.ipc,
+ sizeof(out->data.ipc))) {
goto fail_free;
}
SWAB32(out->data.ipc.nlink);
break;
case SQFS_INODE_EXT_DIR:
- if (meta_reader_read(ir, &out->data.dir_ext,
- sizeof(out->data.dir_ext))) {
+ if (sqfs_meta_reader_read(ir, &out->data.dir_ext,
+ sizeof(out->data.dir_ext))) {
goto fail_free;
}
SWAB32(out->data.dir_ext.nlink);
@@ -307,8 +309,8 @@ sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
break;
case SQFS_INODE_EXT_BDEV:
case SQFS_INODE_EXT_CDEV:
- if (meta_reader_read(ir, &out->data.dev_ext,
- sizeof(out->data.dev_ext))) {
+ if (sqfs_meta_reader_read(ir, &out->data.dev_ext,
+ sizeof(out->data.dev_ext))) {
goto fail_free;
}
SWAB32(out->data.dev_ext.nlink);
@@ -317,8 +319,8 @@ sqfs_inode_generic_t *meta_reader_read_inode(meta_reader_t *ir,
break;
case SQFS_INODE_EXT_FIFO:
case SQFS_INODE_EXT_SOCKET:
- if (meta_reader_read(ir, &out->data.ipc_ext,
- sizeof(out->data.ipc_ext))) {
+ if (sqfs_meta_reader_read(ir, &out->data.ipc_ext,
+ sizeof(out->data.ipc_ext))) {
goto fail_free;
}
SWAB32(out->data.ipc_ext.nlink);
diff --git a/lib/sqfs/read_table.c b/lib/sqfs/read_table.c
index e7ba08a..1470fac 100644
--- a/lib/sqfs/read_table.c
+++ b/lib/sqfs/read_table.c
@@ -20,7 +20,7 @@ void *sqfs_read_table(int fd, compressor_t *cmp, size_t table_size,
{
size_t diff, block_count, blk_idx = 0;
uint64_t start, *locations;
- meta_reader_t *m;
+ sqfs_meta_reader_t *m;
void *data, *ptr;
data = malloc(table_size);
@@ -48,7 +48,7 @@ void *sqfs_read_table(int fd, compressor_t *cmp, size_t table_size,
}
/* Read the actual data */
- m = meta_reader_create(fd, cmp, lower_limit, upper_limit);
+ m = sqfs_meta_reader_create(fd, cmp, lower_limit, upper_limit);
if (m == NULL)
goto fail_idx;
@@ -57,25 +57,25 @@ void *sqfs_read_table(int fd, compressor_t *cmp, size_t table_size,
while (table_size > 0) {
start = le64toh(locations[blk_idx++]);
- if (meta_reader_seek(m, start, 0))
+ if (sqfs_meta_reader_seek(m, start, 0))
goto fail;
diff = SQFS_META_BLOCK_SIZE;
if (diff > table_size)
diff = table_size;
- if (meta_reader_read(m, ptr, diff))
+ if (sqfs_meta_reader_read(m, ptr, diff))
goto fail;
ptr = (char *)ptr + diff;
table_size -= diff;
}
- meta_reader_destroy(m);
+ sqfs_meta_reader_destroy(m);
free(locations);
return data;
fail:
- meta_reader_destroy(m);
+ sqfs_meta_reader_destroy(m);
fail_idx:
free(locations);
fail_data:
diff --git a/lib/sqfs/readdir.c b/lib/sqfs/readdir.c
index 31e4c63..310929c 100644
--- a/lib/sqfs/readdir.c
+++ b/lib/sqfs/readdir.c
@@ -12,9 +12,10 @@
#include <string.h>
#include <stdio.h>
-int meta_reader_read_dir_header(meta_reader_t *m, sqfs_dir_header_t *hdr)
+int sqfs_meta_reader_read_dir_header(sqfs_meta_reader_t *m,
+ sqfs_dir_header_t *hdr)
{
- if (meta_reader_read(m, hdr, sizeof(*hdr)))
+ if (sqfs_meta_reader_read(m, hdr, sizeof(*hdr)))
return -1;
hdr->count = le32toh(hdr->count);
@@ -30,12 +31,12 @@ int meta_reader_read_dir_header(meta_reader_t *m, sqfs_dir_header_t *hdr)
return 0;
}
-sqfs_dir_entry_t *meta_reader_read_dir_ent(meta_reader_t *m)
+sqfs_dir_entry_t *sqfs_meta_reader_read_dir_ent(sqfs_meta_reader_t *m)
{
sqfs_dir_entry_t ent, *out;
uint16_t *diff_u16;
- if (meta_reader_read(m, &ent, sizeof(ent)))
+ if (sqfs_meta_reader_read(m, &ent, sizeof(ent)))
return NULL;
diff_u16 = (uint16_t *)&ent.inode_diff;
@@ -52,7 +53,7 @@ sqfs_dir_entry_t *meta_reader_read_dir_ent(meta_reader_t *m)
}
*out = ent;
- if (meta_reader_read(m, out->name, ent.size + 1)) {
+ if (sqfs_meta_reader_read(m, out->name, ent.size + 1)) {
free(out);
return NULL;
}
diff --git a/lib/sqfs/xattr_reader.c b/lib/sqfs/xattr_reader.c
index 3e74424..d7bcbf7 100644
--- a/lib/sqfs/xattr_reader.c
+++ b/lib/sqfs/xattr_reader.c
@@ -23,8 +23,8 @@ struct sqfs_xattr_reader_t {
uint64_t *id_block_starts;
- meta_reader_t *idrd;
- meta_reader_t *kvrd;
+ sqfs_meta_reader_t *idrd;
+ sqfs_meta_reader_t *kvrd;
sqfs_super_t *super;
};
@@ -90,7 +90,7 @@ sqfs_xattr_entry_t *sqfs_xattr_reader_read_key(sqfs_xattr_reader_t *xr)
const char *prefix;
size_t plen, total;
- if (meta_reader_read(xr->kvrd, &key, sizeof(key)))
+ if (sqfs_meta_reader_read(xr->kvrd, &key, sizeof(key)))
return NULL;
key.type = le16toh(key.type);
@@ -119,7 +119,7 @@ sqfs_xattr_entry_t *sqfs_xattr_reader_read_key(sqfs_xattr_reader_t *xr)
*out = key;
memcpy(out->key, prefix, plen);
- if (meta_reader_read(xr->kvrd, out->key + plen, key.size)) {
+ if (sqfs_meta_reader_read(xr->kvrd, out->key + plen, key.size)) {
free(out);
return NULL;
}
@@ -137,14 +137,14 @@ sqfs_xattr_value_t *sqfs_xattr_reader_read_value(sqfs_xattr_reader_t *xr,
sqfs_xattr_value_t value, *out;
uint64_t ref, start, new_start;
- if (meta_reader_read(xr->kvrd, &value, sizeof(value)))
+ if (sqfs_meta_reader_read(xr->kvrd, &value, sizeof(value)))
return NULL;
if (key->type & SQFS_XATTR_FLAG_OOL) {
- if (meta_reader_read(xr->kvrd, &ref, sizeof(ref)))
+ if (sqfs_meta_reader_read(xr->kvrd, &ref, sizeof(ref)))
return NULL;
- meta_reader_get_position(xr->kvrd, &start, &offset);
+ sqfs_meta_reader_get_position(xr->kvrd, &start, &offset);
new_start = xr->xattr_start + (ref >> 16);
new_offset = ref & 0xFFFF;
@@ -161,7 +161,7 @@ sqfs_xattr_value_t *sqfs_xattr_reader_read_value(sqfs_xattr_reader_t *xr,
return NULL;
}
- if (meta_reader_seek(xr->kvrd, new_start, new_offset))
+ if (sqfs_meta_reader_seek(xr->kvrd, new_start, new_offset))
return NULL;
}
@@ -179,11 +179,11 @@ sqfs_xattr_value_t *sqfs_xattr_reader_read_value(sqfs_xattr_reader_t *xr,
*out = value;
- if (meta_reader_read(xr->kvrd, out->value, value.size))
+ if (sqfs_meta_reader_read(xr->kvrd, out->value, value.size))
goto fail;
if (key->type & SQFS_XATTR_FLAG_OOL) {
- if (meta_reader_seek(xr->kvrd, start, offset))
+ if (sqfs_meta_reader_seek(xr->kvrd, start, offset))
goto fail;
}
@@ -202,7 +202,7 @@ int sqfs_xattr_reader_seek_kv(sqfs_xattr_reader_t *xr,
uint32_t offset = desc->xattr & 0xFFFF;
uint64_t block = xr->xattr_start + (desc->xattr >> 16);
- return meta_reader_seek(xr->kvrd, block, offset);
+ return sqfs_meta_reader_seek(xr->kvrd, block, offset);
}
int sqfs_xattr_reader_get_desc(sqfs_xattr_reader_t *xr, uint32_t idx,
@@ -227,10 +227,10 @@ int sqfs_xattr_reader_get_desc(sqfs_xattr_reader_t *xr, uint32_t idx,
offset = (idx * sizeof(*desc)) % SQFS_META_BLOCK_SIZE;
block = (idx * sizeof(*desc)) / SQFS_META_BLOCK_SIZE;
- if (meta_reader_seek(xr->idrd, xr->id_block_starts[block], offset))
+ if (sqfs_meta_reader_seek(xr->idrd, xr->id_block_starts[block], offset))
return -1;
- if (meta_reader_read(xr->idrd, desc, sizeof(*desc)))
+ if (sqfs_meta_reader_read(xr->idrd, desc, sizeof(*desc)))
return -1;
desc->xattr = le64toh(desc->xattr);
@@ -246,10 +246,10 @@ fail_bounds:
void sqfs_xattr_reader_destroy(sqfs_xattr_reader_t *xr)
{
if (xr->kvrd != NULL)
- meta_reader_destroy(xr->kvrd);
+ sqfs_meta_reader_destroy(xr->kvrd);
if (xr->idrd != NULL)
- meta_reader_destroy(xr->idrd);
+ sqfs_meta_reader_destroy(xr->idrd);
free(xr->id_block_starts);
free(xr);
@@ -274,15 +274,15 @@ sqfs_xattr_reader_t *sqfs_xattr_reader_create(int sqfsfd, sqfs_super_t *super,
if (get_id_block_locations(xr, sqfsfd, super))
goto fail;
- xr->idrd = meta_reader_create(sqfsfd, cmp,
- super->id_table_start,
- super->bytes_used);
+ xr->idrd = sqfs_meta_reader_create(sqfsfd, cmp,
+ super->id_table_start,
+ super->bytes_used);
if (xr->idrd == NULL)
goto fail;
- xr->kvrd = meta_reader_create(sqfsfd, cmp,
- super->id_table_start,
- super->bytes_used);
+ xr->kvrd = sqfs_meta_reader_create(sqfsfd, cmp,
+ super->id_table_start,
+ super->bytes_used);
if (xr->kvrd == NULL)
goto fail;