summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/meta.c35
-rw-r--r--mkfs/xattr.c26
2 files changed, 38 insertions, 23 deletions
diff --git a/mkfs/meta.c b/mkfs/meta.c
index 58f82d7..ee37054 100644
--- a/mkfs/meta.c
+++ b/mkfs/meta.c
@@ -65,16 +65,19 @@ static int write_dir(meta_writer_t *dm, dir_info_t *dir, dir_index_t **index)
sqfs_dir_header_t hdr;
sqfs_dir_entry_t ent;
tree_node_t *c, *d;
+ uint32_t offset;
+ uint64_t block;
c = dir->children;
dir->size = 0;
- dir->start_block = dm->block_offset;
- dir->block_offset = dm->offset;
+ meta_writer_get_position(dm, &dir->start_block, &dir->block_offset);
while (c != NULL) {
+ meta_writer_get_position(dm, &block, &offset);
+
count = 0;
- size = (dm->offset + sizeof(hdr)) % SQFS_META_BLOCK_SIZE;
+ size = (offset + sizeof(hdr)) % SQFS_META_BLOCK_SIZE;
for (d = c; d != NULL; d = d->next) {
if ((d->inode_ref >> 16) != (c->inode_ref >> 16))
@@ -96,10 +99,12 @@ static int write_dir(meta_writer_t *dm, dir_info_t *dir, dir_index_t **index)
if (dir_index_grow(index))
return -1;
+ meta_writer_get_position(dm, &block, &offset);
+
i = (*index)->num_nodes++;
(*index)->idx_nodes[i].node = c;
- (*index)->idx_nodes[i].block = dm->block_offset;
- (*index)->idx_nodes[i].offset = dm->offset;
+ (*index)->idx_nodes[i].block = block;
+ (*index)->idx_nodes[i].offset = offset;
hdr.count = htole32(count - 1);
hdr.start_block = htole32(c->inode_ref >> 16);
@@ -136,9 +141,9 @@ static int write_inode(sqfs_info_t *info, meta_writer_t *im, meta_writer_t *dm,
uint16_t uid_idx, gid_idx;
file_info_t *fi = NULL;
dir_info_t *di = NULL;
+ uint32_t bs, offset;
sqfs_inode_t base;
- uint32_t bs;
- uint64_t i;
+ uint64_t i, block;
if (id_table_id_to_index(&info->idtbl, node->uid, &uid_idx))
return -1;
@@ -146,7 +151,8 @@ static int write_inode(sqfs_info_t *info, meta_writer_t *im, meta_writer_t *dm,
if (id_table_id_to_index(&info->idtbl, node->gid, &gid_idx))
return -1;
- node->inode_ref = (im->block_offset << 16) | im->offset;
+ meta_writer_get_position(im, &block, &offset);
+ node->inode_ref = (block << 16) | offset;
node->inode_num = info->inode_counter++;
info->super.inode_count += 1;
@@ -433,6 +439,9 @@ static int write_child_inodes(sqfs_info_t *info, meta_writer_t *im,
int sqfs_write_inodes(sqfs_info_t *info)
{
meta_writer_t *im, *dm;
+ uint8_t buffer[1024];
+ uint32_t offset;
+ uint64_t block;
size_t diff;
ssize_t ret;
FILE *tmp;
@@ -470,11 +479,13 @@ int sqfs_write_inodes(sqfs_info_t *info)
info->super.root_inode_ref = info->fs.root->inode_ref;
+ meta_writer_get_position(im, &block, &offset);
info->super.inode_table_start = info->super.bytes_used;
- info->super.bytes_used += im->block_offset;
+ info->super.bytes_used += block;
info->super.directory_table_start = info->super.bytes_used;
- info->super.bytes_used += dm->block_offset;
+ meta_writer_get_position(dm, &block, &offset);
+ info->super.bytes_used += block;
if (lseek(tmpfd, 0, SEEK_SET) == (off_t)-1) {
perror("rewind on directory temp file");
@@ -482,7 +493,7 @@ int sqfs_write_inodes(sqfs_info_t *info)
}
for (;;) {
- ret = read_retry(tmpfd, dm->data, sizeof(dm->data));
+ ret = read_retry(tmpfd, buffer, sizeof(buffer));
if (ret < 0) {
perror("read from temp file");
@@ -492,7 +503,7 @@ int sqfs_write_inodes(sqfs_info_t *info)
break;
diff = ret;
- ret = write_retry(info->outfd, dm->data, diff);
+ ret = write_retry(info->outfd, buffer, diff);
if (ret < 0) {
perror("write to image file");
diff --git a/mkfs/xattr.c b/mkfs/xattr.c
index 8f1a816..b7f433e 100644
--- a/mkfs/xattr.c
+++ b/mkfs/xattr.c
@@ -89,12 +89,13 @@ static int write_kv_pairs(sqfs_info_t *info, meta_writer_t *mw,
int write_xattr(sqfs_info_t *info)
{
- uint64_t kv_start, id_start, *tbl;
+ uint64_t kv_start, id_start, block, *tbl;
size_t i = 0, count = 0, blocks;
sqfs_xattr_id_table_t idtbl;
sqfs_xattr_id_t id_ent;
meta_writer_t *mw;
tree_xattr_t *it;
+ uint32_t offset;
ssize_t ret;
if (info->fs.xattr == NULL)
@@ -108,8 +109,7 @@ int write_xattr(sqfs_info_t *info)
kv_start = info->super.bytes_used;
for (it = info->fs.xattr; it != NULL; it = it->next) {
- it->block = mw->block_offset;
- it->offset = mw->offset;
+ meta_writer_get_position(mw, &it->block, &it->offset);
it->size = 0;
if (write_kv_pairs(info, mw, it))
@@ -121,8 +121,10 @@ int write_xattr(sqfs_info_t *info)
if (meta_writer_flush(mw))
goto fail_mw;
- info->super.bytes_used += mw->block_offset;
- mw->block_offset = 0;
+ meta_writer_get_position(mw, &block, &offset);
+ meta_writer_reset(mw);
+
+ info->super.bytes_used += block;
/* allocate location table */
blocks = (count * sizeof(id_ent)) / SQFS_META_BLOCK_SIZE;
@@ -138,8 +140,8 @@ int write_xattr(sqfs_info_t *info)
}
/* write ID table referring to key value pairs, record offsets */
- id_start = mw->block_offset;
- tbl[i++] = htole64(info->super.bytes_used + id_start);
+ id_start = 0;
+ tbl[i++] = htole64(info->super.bytes_used);
for (it = info->fs.xattr; it != NULL; it = it->next) {
id_ent.xattr = htole64((it->block << 16) | it->offset);
@@ -149,8 +151,10 @@ int write_xattr(sqfs_info_t *info)
if (meta_writer_append(mw, &id_ent, sizeof(id_ent)))
goto fail_tbl;
- if (mw->block_offset != id_start) {
- id_start = mw->block_offset;
+ meta_writer_get_position(mw, &block, &offset);
+
+ if (block != id_start) {
+ id_start = block;
tbl[i++] = htole64(info->super.bytes_used + id_start);
}
}
@@ -158,8 +162,8 @@ int write_xattr(sqfs_info_t *info)
if (meta_writer_flush(mw))
goto fail_tbl;
- info->super.bytes_used += mw->block_offset;
- mw->block_offset = 0;
+ meta_writer_get_position(mw, &block, &offset);
+ info->super.bytes_used += block;
/* write offset table */
idtbl.xattr_table_start = htole64(kv_start);