summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-02 08:06:48 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-03 21:45:46 +0200
commit83183717feca5c673d614e341bfca49fae9a8001 (patch)
tree9fcb5ea12e01852f6fbb255ae4e6d2b612edbb43 /lib
parent1796ff184ba862508fc578c985dd9ebcc15a048d (diff)
Add helper function for reading dir entries to meta reader
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makemodule.am1
-rw-r--r--lib/sqfs/readdir.c58
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index b521a7e..a1bf0f2 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -14,6 +14,7 @@ libsquashfs_a_SOURCES += lib/sqfs/table.c include/table.h
libsquashfs_a_SOURCES += lib/sqfs/read_super.c lib/sqfs/meta_reader.c
libsquashfs_a_SOURCES += include/meta_reader.h lib/sqfs/id_table_write.c
libsquashfs_a_SOURCES += lib/sqfs/id_table_read.c lib/sqfs/read_inode.c
+libsquashfs_a_SOURCES += lib/sqfs/readdir.c
libutil_a_SOURCES = lib/util/canonicalize_name.c lib/util/write_retry.c
libutil_a_SOURCES += lib/util/read_retry.c include/util.h
diff --git a/lib/sqfs/readdir.c b/lib/sqfs/readdir.c
new file mode 100644
index 0000000..142bafb
--- /dev/null
+++ b/lib/sqfs/readdir.c
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "meta_reader.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+int meta_reader_read_dir_header(meta_reader_t *m, sqfs_dir_header_t *hdr)
+{
+ if (meta_reader_read(m, hdr, sizeof(*hdr)))
+ return -1;
+
+ hdr->count = le32toh(hdr->count);
+ hdr->start_block = le32toh(hdr->start_block);
+ hdr->inode_number = le32toh(hdr->inode_number);
+ return 0;
+}
+
+sqfs_dir_entry_t *meta_reader_read_dir_ent(meta_reader_t *m)
+{
+ sqfs_dir_entry_t ent, *out;
+
+ if (meta_reader_read(m, &ent, sizeof(ent)))
+ return NULL;
+
+ ent.offset = le16toh(ent.offset);
+ ent.inode_number = le16toh(ent.inode_number);
+ ent.type = le16toh(ent.type);
+ ent.size = le16toh(ent.size);
+
+ out = calloc(1, sizeof(*out) + ent.size + 2);
+ if (out == NULL) {
+ perror("reading dir entry");
+ return NULL;
+ }
+
+ *out = ent;
+ if (meta_reader_read(m, out->name, ent.size + 1)) {
+ free(out);
+ return NULL;
+ }
+
+ if (strchr((char *)out->name, '/') != NULL ||
+ strchr((char *)out->name, '\\') != NULL) {
+ fputs("Found a file name that contains slashes\n", stderr);
+ free(out);
+ return NULL;
+ }
+
+ if (strcmp((char *)out->name, "..") == 0 ||
+ strcmp((char *)out->name, ".") == 0) {
+ fputs("Found '..' or '.' in file names\n", stderr);
+ free(out);
+ return NULL;
+ }
+
+ return out;
+}