summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 21:20:00 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 21:24:46 +0200
commit395e301d554a233dd00a3c7abff4880ad7e681a1 (patch)
tree5c5ea9186d0181b6751c39c4670f7a3122309098 /mkfs
parent856e8ae89a3ba86526b71bc811573c7e10d161d4 (diff)
Generate a flat inode table from the fstree ahead of time
Instead of allocating inode numbers as we go, generate and populat an inode table from the fstree ahead of time. This makes processing nodes a little bit simpler and we will need that table anyway for NFS export support later on. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/meta.c49
-rw-r--r--mkfs/mkfs.c5
-rw-r--r--mkfs/mkfs.h1
3 files changed, 12 insertions, 43 deletions
diff --git a/mkfs/meta.c b/mkfs/meta.c
index 1510524..9c305b1 100644
--- a/mkfs/meta.c
+++ b/mkfs/meta.c
@@ -64,9 +64,6 @@ static int write_inode(sqfs_info_t *info, meta_writer_t *im, meta_writer_t *dm,
meta_writer_get_position(im, &block, &offset);
node->inode_ref = (block << 16) | offset;
- node->inode_num = info->inode_counter++;
-
- info->super.inode_count += 1;
type = get_type(node);
@@ -293,44 +290,13 @@ out_file_blocks:
return 0;
}
-static int write_child_inodes(sqfs_info_t *info, meta_writer_t *im,
- meta_writer_t *dm, tree_node_t *root)
-{
- bool has_subdirs = false;
- tree_node_t *it;
-
- for (it = root->data.dir->children; it != NULL; it = it->next) {
- if (S_ISDIR(it->mode)) {
- has_subdirs = true;
- break;
- }
- }
-
- if (has_subdirs) {
- for (it = root->data.dir->children; it != NULL; it = it->next) {
- if (!S_ISDIR(it->mode))
- continue;
-
- if (write_child_inodes(info, im, dm, it))
- return -1;
- }
- }
-
- for (it = root->data.dir->children; it != NULL; it = it->next) {
- if (write_inode(info, im, dm, it))
- return -1;
- }
-
- return 0;
-}
-
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;
+ size_t i, diff;
ssize_t ret;
FILE *tmp;
int tmpfd;
@@ -351,13 +317,12 @@ int sqfs_write_inodes(sqfs_info_t *info)
if (dm == NULL)
goto fail_im;
- info->inode_counter = 2;
-
- if (write_child_inodes(info, im, dm, info->fs.root))
- goto fail;
-
- if (write_inode(info, im, dm, info->fs.root))
- goto fail;
+ for (i = 0; i < info->fs.inode_tbl_size; ++i) {
+ if (info->fs.inode_table[i] != NULL) {
+ if (write_inode(info, im, dm, info->fs.inode_table[i]))
+ goto fail;
+ }
+ }
if (meta_writer_flush(im))
goto fail;
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index a6f19f1..405d6fd 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -89,6 +89,11 @@ int main(int argc, char **argv)
fstree_sort(&info.fs);
+ if (fstree_gen_inode_table(&info.fs))
+ goto out_fstree;
+
+ info.super.inode_count = info.fs.inode_tbl_size - 2;
+
info.cmp = compressor_create(info.super.compression_id, true,
info.super.block_size,
info.opt.comp_extra);
diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h
index 15d349e..e3e3c5d 100644
--- a/mkfs/mkfs.h
+++ b/mkfs/mkfs.h
@@ -65,7 +65,6 @@ typedef struct {
size_t frag_offset;
id_table_t idtbl;
- size_t inode_counter;
compressor_t *cmp;
} sqfs_info_t;