summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-01 02:33:20 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-02 12:40:06 +0200
commitfd22d7851e08ab6c9b57f5857062a9e4cfdc41cc (patch)
tree285ef4a6990ebc38a91495e1453ed1bbcf2f0feb
parent9eec700a703f62e27768f37a1c6c0e859212320c (diff)
cleanup round
- remove debug prints - move id table write out to id table code - dummy remove wrapper function for fragment table Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/id_table.h5
-rw-r--r--include/table.h9
-rw-r--r--lib/sqfs/id_table.c21
-rw-r--r--lib/sqfs/table.c36
-rw-r--r--mkfs/mksquashfs.c47
5 files changed, 39 insertions, 79 deletions
diff --git a/include/id_table.h b/include/id_table.h
index 6d5d416..c49923e 100644
--- a/include/id_table.h
+++ b/include/id_table.h
@@ -5,6 +5,8 @@
#include <stdint.h>
#include <stddef.h>
+#include "compress.h"
+
typedef struct {
uint32_t *ids;
size_t num_ids;
@@ -17,4 +19,7 @@ void id_table_cleanup(id_table_t *tbl);
int id_table_id_to_index(id_table_t *tbl, uint32_t id, uint16_t *out);
+int id_table_write(id_table_t *tbl, int outfd, sqfs_super_t *super,
+ compressor_t *cmp);
+
#endif /* ID_TABLE_H */
diff --git a/include/table.h b/include/table.h
index 5a39797..3eb5655 100644
--- a/include/table.h
+++ b/include/table.h
@@ -8,11 +8,8 @@
#include <stdint.h>
#include <stddef.h>
-int sqfs_write_fragment_table(int outfd, sqfs_super_t *super,
- sqfs_fragment_t *fragments, size_t count,
- compressor_t *cmp);
-
-int sqfs_write_ids(int outfd, sqfs_super_t *super, uint32_t *id_tbl,
- size_t count, compressor_t *cmp);
+int sqfs_write_table(int outfd, sqfs_super_t *super, const void *data,
+ size_t entsize, size_t count, uint64_t *startblock,
+ compressor_t *cmp);
#endif /* TABLE_H */
diff --git a/lib/sqfs/id_table.c b/lib/sqfs/id_table.c
index cd31360..4cc12c6 100644
--- a/lib/sqfs/id_table.c
+++ b/lib/sqfs/id_table.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include "id_table.h"
+#include "table.h"
#include <stdlib.h>
#include <string.h>
@@ -50,3 +51,23 @@ int id_table_id_to_index(id_table_t *tbl, uint32_t id, uint16_t *out)
tbl->ids[tbl->num_ids++] = id;
return 0;
}
+
+int id_table_write(id_table_t *tbl, int outfd, sqfs_super_t *super,
+ compressor_t *cmp)
+{
+ size_t i;
+ int ret;
+
+ for (i = 0; i < tbl->num_ids; ++i)
+ tbl->ids[i] = htole32(tbl->ids[i]);
+
+ super->id_count = tbl->num_ids;
+
+ ret = sqfs_write_table(outfd, super, tbl->ids, sizeof(tbl->ids[0]),
+ tbl->num_ids, &super->id_table_start, cmp);
+
+ for (i = 0; i < tbl->num_ids; ++i)
+ tbl->ids[i] = le32toh(tbl->ids[i]);
+
+ return ret;
+}
diff --git a/lib/sqfs/table.c b/lib/sqfs/table.c
index 2fab3cc..882d9ba 100644
--- a/lib/sqfs/table.c
+++ b/lib/sqfs/table.c
@@ -6,9 +6,9 @@
#include <endian.h>
#include <stdio.h>
-static int sqfs_write_table(int outfd, sqfs_super_t *super, const void *data,
- size_t entsize, size_t count, uint64_t *startblock,
- compressor_t *cmp)
+int sqfs_write_table(int outfd, sqfs_super_t *super, const void *data,
+ size_t entsize, size_t count, uint64_t *startblock,
+ compressor_t *cmp)
{
size_t ent_per_blocks = SQFS_META_BLOCK_SIZE / entsize;
uint64_t blocks[count / ent_per_blocks + 1];
@@ -62,33 +62,3 @@ fail:
meta_writer_destroy(m);
return -1;
}
-
-int sqfs_write_fragment_table(int outfd, sqfs_super_t *super,
- sqfs_fragment_t *fragments, size_t count,
- compressor_t *cmp)
-{
- super->fragment_entry_count = count;
-
- return sqfs_write_table(outfd, super, fragments, sizeof(fragments[0]),
- count, &super->fragment_table_start, cmp);
-}
-
-int sqfs_write_ids(int outfd, sqfs_super_t *super, uint32_t *id_tbl,
- size_t count, compressor_t *cmp)
-{
- size_t i;
- int ret;
-
- for (i = 0; i < count; ++i)
- id_tbl[i] = htole32(id_tbl[i]);
-
- super->id_count = count;
-
- ret = sqfs_write_table(outfd, super, id_tbl, sizeof(id_tbl[0]),
- count, &super->id_table_start, cmp);
-
- for (i = 0; i < count; ++i)
- id_tbl[i] = htole32(id_tbl[i]);
-
- return ret;
-}
diff --git a/mkfs/mksquashfs.c b/mkfs/mksquashfs.c
index e554e62..2f2e508 100644
--- a/mkfs/mksquashfs.c
+++ b/mkfs/mksquashfs.c
@@ -2,39 +2,6 @@
#include "mksquashfs.h"
#include "util.h"
-static void print_tree(int level, tree_node_t *node)
-{
- tree_node_t *n;
- int i;
-
- for (i = 1; i < level; ++i) {
- fputs("| ", stdout);
- }
-
- if (level)
- fputs("+- ", stdout);
-
- if (S_ISDIR(node->mode)) {
- fprintf(stdout, "%s/ (%u, %u, 0%o)\n", node->name,
- node->uid, node->gid, node->mode & 07777);
-
- for (n = node->data.dir->children; n != NULL; n = n->next) {
- print_tree(level + 1, n);
- }
-
- if (node->data.dir->children != NULL) {
- for (i = 0; i < level; ++i)
- fputs("| ", stdout);
-
- if (level)
- fputc('\n', stdout);
- }
- } else {
- fprintf(stdout, "%s (%u, %u, 0%o)\n", node->name,
- node->uid, node->gid, node->mode & 07777);
- }
-}
-
static int padd_file(sqfs_info_t *info)
{
size_t padd_sz = info->super.bytes_used % info->opt.devblksz;
@@ -107,8 +74,6 @@ int main(int argc, char **argv)
fstree_sort(&info.fs);
- print_tree(0, info.fs.root);
-
info.cmp = compressor_create(info.super.compression_id, true,
info.super.block_size);
if (info.cmp == NULL) {
@@ -122,13 +87,15 @@ int main(int argc, char **argv)
if (sqfs_write_inodes(&info))
goto out_cmp;
- if (sqfs_write_fragment_table(info.outfd, &info.super,
- info.fragments, info.num_fragments,
- info.cmp))
+ info.super.fragment_entry_count = info.num_fragments;
+
+ if (sqfs_write_table(info.outfd, &info.super, info.fragments,
+ sizeof(info.fragments[0]), info.num_fragments,
+ &info.super.fragment_table_start, info.cmp)) {
goto out_cmp;
+ }
- if (sqfs_write_ids(info.outfd, &info.super, info.idtbl.ids,
- info.idtbl.num_ids, info.cmp))
+ if (id_table_write(&info.idtbl, info.outfd, &info.super, info.cmp))
goto out_cmp;
if (sqfs_super_write(&info.super, info.outfd))