aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/write_inode.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-03 12:11:51 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-03 14:57:47 +0200
commit6a218f0927c0cced058e14ee5156f10860a149d3 (patch)
treeedc56ce26501ee3cb47ed335922be22efc4843ef /lib/sqfs/write_inode.c
parent9ffad2478a04011805132750644eabcb7f0c0e92 (diff)
Store directory index in generic inode structure
This commit modifies the dir writer to store the directory index directly in the payload area of the inode it creates. The size of the index in bytes is stored in a seperate field. Storing the index is moved to the write inode function. The read inode function is in turn also modified to read the directory index from disk and actually store it in the inode structure in memory for later use. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/write_inode.c')
-rw-r--r--lib/sqfs/write_inode.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index af6b1e6..2e69b80 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -10,6 +10,7 @@
#include "sqfs/meta_writer.h"
#include "sqfs/error.h"
#include "sqfs/inode.h"
+#include "sqfs/dir.h"
#include "compat.h"
static int write_block_sizes(sqfs_meta_writer_t *ir,
@@ -25,6 +26,41 @@ static int write_block_sizes(sqfs_meta_writer_t *ir,
sizeof(sqfs_u32) * n->num_file_blocks);
}
+static int write_dir_index(sqfs_meta_writer_t *ir, const sqfs_u8 *data,
+ size_t count)
+{
+ sqfs_dir_index_t *ent, copy;
+ size_t len;
+ int err;
+
+ while (count > sizeof(*ent)) {
+ ent = (sqfs_dir_index_t *)data;
+ data += sizeof(*ent);
+ count -= sizeof(*ent);
+ len = ent->size + 1;
+
+ if (len > count)
+ return SQFS_ERROR_CORRUPTED;
+
+ copy.start_block = htole32(ent->start_block);
+ copy.index = htole32(ent->index);
+ copy.size = htole32(ent->size);
+
+ err = sqfs_meta_writer_append(ir, &copy, sizeof(copy));
+ if (err)
+ return err;
+
+ err = sqfs_meta_writer_append(ir, data, len);
+ if (err)
+ return err;
+
+ data += len;
+ count -= len;
+ }
+
+ return 0;
+}
+
int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir,
const sqfs_inode_generic_t *n)
{
@@ -102,7 +138,10 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir,
.offset = htole16(n->data.dir_ext.offset),
.xattr_idx = htole32(n->data.dir_ext.xattr_idx),
};
- return sqfs_meta_writer_append(ir, &dir, sizeof(dir));
+ 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);
}
case SQFS_INODE_EXT_FILE: {
sqfs_inode_file_ext_t file = {