summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 23:16:34 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-06-10 23:16:53 +0200
commit576e195ba5476ebf428bac51365d829d713e6907 (patch)
tree1dc5a487ae278cfd9287dbd233a7975489612ffc
parent4d2e87b767d1e025699286783c23926ec5eff857 (diff)
cleanup: move tree deserialization to libsqfs.a
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/highlevel.h27
-rw-r--r--lib/Makemodule.am2
-rw-r--r--lib/sqfs/deserialize_fstree.c (renamed from unpack/read_fstree.c)27
-rw-r--r--lib/sqfs/tree_node_from_inode.c (renamed from unpack/tree_node_from_inode.c)6
-rw-r--r--unpack/Makemodule.am3
-rw-r--r--unpack/rdsquashfs.c14
-rw-r--r--unpack/rdsquashfs.h20
7 files changed, 64 insertions, 35 deletions
diff --git a/include/highlevel.h b/include/highlevel.h
index e69e337..f61ad0b 100644
--- a/include/highlevel.h
+++ b/include/highlevel.h
@@ -10,6 +10,14 @@
#include <stdint.h>
#include <stddef.h>
+enum RDTREE_FLAGS {
+ RDTREE_NO_DEVICES = 0x01,
+ RDTREE_NO_SOCKETS = 0x02,
+ RDTREE_NO_FIFO = 0x04,
+ RDTREE_NO_SLINKS = 0x08,
+ RDTREE_NO_EMPTY = 0x10,
+};
+
/*
Convenience function for writing meta data to a SquashFS image
@@ -40,4 +48,23 @@ int sqfs_write_table(int outfd, sqfs_super_t *super, const void *data,
int sqfs_serialize_fstree(int outfd, sqfs_super_t *super, fstree_t *fs,
compressor_t *cmp, id_table_t *idtbl);
+/*
+ Convert a generic squashfs tree node to an fstree_t node.
+
+ Prints error messages to stderr on failure.
+ */
+tree_node_t *tree_node_from_inode(sqfs_inode_generic_t *inode,
+ const id_table_t *idtbl,
+ const char *name,
+ size_t block_size);
+
+/*
+ Restore a file system tree from a squashfs image. The given flags are a
+ combination of RDTREE_FLAGS.
+
+ Returns 0 on success. Prints error messages to stderr on failure.
+ */
+int deserialize_fstree(fstree_t *out, sqfs_super_t *super, compressor_t *cmp,
+ int fd, int flags);
+
#endif /* HIGHLEVEL_H */
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index ff63a7f..9496a9d 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -20,6 +20,8 @@ libsquashfs_a_SOURCES += lib/sqfs/id_table_read.c lib/sqfs/read_inode.c
libsquashfs_a_SOURCES += lib/sqfs/readdir.c lib/sqfs/frag_reader.c
libsquashfs_a_SOURCES += lib/sqfs/write_dir.c lib/sqfs/write_inode.c
libsquashfs_a_SOURCES += lib/sqfs/serialize_fstree.c
+libsquashfs_a_SOURCES += lib/sqfs/tree_node_from_inode.c
+libsquashfs_a_SOURCES += lib/sqfs/deserialize_fstree.c
libsquashfs_a_SOURCES += include/frag_reader.h
libutil_a_SOURCES = lib/util/canonicalize_name.c lib/util/write_retry.c
diff --git a/unpack/read_fstree.c b/lib/sqfs/deserialize_fstree.c
index 544af83..95dce98 100644
--- a/unpack/read_fstree.c
+++ b/lib/sqfs/deserialize_fstree.c
@@ -1,6 +1,10 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
-#include "rdsquashfs.h"
+#include "meta_reader.h"
+#include "highlevel.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
static int should_skip(int type, int flags)
{
@@ -9,16 +13,16 @@ static int should_skip(int type, int flags)
case SQFS_INODE_CDEV:
case SQFS_INODE_EXT_CDEV:
case SQFS_INODE_EXT_BDEV:
- return (flags & UNPACK_NO_DEVICES);
+ return (flags & RDTREE_NO_DEVICES);
case SQFS_INODE_SLINK:
case SQFS_INODE_EXT_SLINK:
- return (flags & UNPACK_NO_SLINKS);
+ return (flags & RDTREE_NO_SLINKS);
case SQFS_INODE_SOCKET:
case SQFS_INODE_EXT_SOCKET:
- return(flags & UNPACK_NO_SOCKETS);
+ return(flags & RDTREE_NO_SOCKETS);
case SQFS_INODE_FIFO:
case SQFS_INODE_EXT_FIFO:
- return (flags & UNPACK_NO_FIFO);
+ return (flags & RDTREE_NO_FIFO);
}
return 0;
}
@@ -93,7 +97,7 @@ static int fill_dir(meta_reader_t *ir, meta_reader_t *dr, tree_node_t *root,
return -1;
if (n->data.dir->children == NULL &&
- (flags & UNPACK_NO_EMPTY)) {
+ (flags & RDTREE_NO_EMPTY)) {
if (prev == NULL) {
root->data.dir->children = n->next;
free(n);
@@ -114,7 +118,8 @@ static int fill_dir(meta_reader_t *ir, meta_reader_t *dr, tree_node_t *root,
return 0;
}
-int read_fstree(fstree_t *out, sqfs_super_t *super, unsqfs_info_t *info)
+int deserialize_fstree(fstree_t *out, sqfs_super_t *super, compressor_t *cmp,
+ int fd, int flags)
{
sqfs_inode_generic_t *root;
meta_reader_t *ir, *dr;
@@ -123,18 +128,18 @@ int read_fstree(fstree_t *out, sqfs_super_t *super, unsqfs_info_t *info)
int status = -1;
size_t offset;
- ir = meta_reader_create(info->sqfsfd, info->cmp);
+ ir = meta_reader_create(fd, cmp);
if (ir == NULL)
return -1;
- dr = meta_reader_create(info->sqfsfd, info->cmp);
+ dr = meta_reader_create(fd, cmp);
if (dr == NULL)
goto out_ir;
if (id_table_init(&idtbl))
goto out_dr;
- if (id_table_read(&idtbl, info->sqfsfd, super, info->cmp))
+ if (id_table_read(&idtbl, fd, super, cmp))
goto out_id;
block_start = super->root_inode_ref >> 16;
@@ -165,7 +170,7 @@ int read_fstree(fstree_t *out, sqfs_super_t *super, unsqfs_info_t *info)
if (out->root == NULL)
goto out_id;
- if (fill_dir(ir, dr, out->root, super, &idtbl, info->flags))
+ if (fill_dir(ir, dr, out->root, super, &idtbl, flags))
goto fail_fs;
fstree_sort(out);
diff --git a/unpack/tree_node_from_inode.c b/lib/sqfs/tree_node_from_inode.c
index 0fd7da1..f9a6599 100644
--- a/unpack/tree_node_from_inode.c
+++ b/lib/sqfs/tree_node_from_inode.c
@@ -1,5 +1,9 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
-#include "rdsquashfs.h"
+#include "highlevel.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
static size_t compute_size(sqfs_inode_generic_t *inode, const char *name,
size_t block_size)
diff --git a/unpack/Makemodule.am b/unpack/Makemodule.am
index 6829681..5f4269e 100644
--- a/unpack/Makemodule.am
+++ b/unpack/Makemodule.am
@@ -1,5 +1,4 @@
-rdsquashfs_SOURCES = unpack/rdsquashfs.c unpack/tree_node_from_inode.c
-rdsquashfs_SOURCES += unpack/rdsquashfs.h unpack/read_fstree.c
+rdsquashfs_SOURCES = unpack/rdsquashfs.c unpack/rdsquashfs.h
rdsquashfs_SOURCES += unpack/list_files.c unpack/extract_file.c
rdsquashfs_SOURCES += unpack/restore_fstree.c unpack/describe.c
rdsquashfs_LDADD = libsquashfs.a libfstree.a libcompress.a libutil.a
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index 11f0a32..81da226 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -177,16 +177,16 @@ int main(int argc, char **argv)
switch (i) {
case 'D':
- info.flags |= UNPACK_NO_DEVICES;
+ info.rdtree_flags |= RDTREE_NO_DEVICES;
break;
case 'S':
- info.flags |= UNPACK_NO_SOCKETS;
+ info.rdtree_flags |= RDTREE_NO_SOCKETS;
break;
case 'F':
- info.flags |= UNPACK_NO_FIFO;
+ info.rdtree_flags |= RDTREE_NO_FIFO;
break;
case 'L':
- info.flags |= UNPACK_NO_SLINKS;
+ info.rdtree_flags |= RDTREE_NO_SLINKS;
break;
case 'C':
info.flags |= UNPACK_CHMOD;
@@ -195,7 +195,7 @@ int main(int argc, char **argv)
info.flags |= UNPACK_CHOWN;
break;
case 'E':
- info.flags |= UNPACK_NO_EMPTY;
+ info.rdtree_flags |= RDTREE_NO_EMPTY;
break;
case 'c':
op = OP_CAT;
@@ -276,8 +276,10 @@ int main(int argc, char **argv)
goto out_cmp;
}
- if (read_fstree(&fs, &super, &info))
+ if (deserialize_fstree(&fs, &super, info.cmp,
+ info.sqfsfd, info.rdtree_flags)) {
goto out_cmp;
+ }
info.block_size = super.block_size;
diff --git a/unpack/rdsquashfs.h b/unpack/rdsquashfs.h
index f1cd131..a615bb5 100644
--- a/unpack/rdsquashfs.h
+++ b/unpack/rdsquashfs.h
@@ -4,6 +4,7 @@
#include "meta_reader.h"
#include "frag_reader.h"
+#include "highlevel.h"
#include "squashfs.h"
#include "compress.h"
#include "id_table.h"
@@ -20,20 +21,16 @@
#include <stdio.h>
enum UNPACK_FLAGS {
- UNPACK_NO_DEVICES = 0x01,
- UNPACK_NO_SOCKETS = 0x02,
- UNPACK_NO_FIFO = 0x04,
- UNPACK_NO_SLINKS = 0x08,
- UNPACK_NO_EMPTY = 0x10,
- UNPACK_CHMOD = 0x20,
- UNPACK_CHOWN = 0x40,
- UNPACK_QUIET = 0x80,
+ UNPACK_CHMOD = 0x01,
+ UNPACK_CHOWN = 0x02,
+ UNPACK_QUIET = 0x04,
};
typedef struct {
compressor_t *cmp;
size_t block_size;
frag_reader_t *frag;
+ int rdtree_flags;
int sqfsfd;
int flags;
@@ -41,13 +38,6 @@ typedef struct {
void *scratch;
} unsqfs_info_t;
-tree_node_t *tree_node_from_inode(sqfs_inode_generic_t *inode,
- const id_table_t *idtbl,
- const char *name,
- size_t block_size);
-
-int read_fstree(fstree_t *out, sqfs_super_t *super, unsqfs_info_t *info);
-
void list_files(tree_node_t *node);
int extract_file(file_info_t *fi, unsqfs_info_t *info, int outfd);