aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqfs/Makemodule.am5
-rw-r--r--lib/sqfs/dir_reader/dir_reader.c (renamed from lib/sqfs/dir_reader.c)105
-rw-r--r--lib/sqfs/dir_reader/find_by_path.c82
-rw-r--r--lib/sqfs/dir_reader/internal.h42
-rw-r--r--lib/sqfs/dir_reader/read_tree.c (renamed from lib/sqfs/read_tree.c)15
5 files changed, 130 insertions, 119 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index df6e3ce..c37301b 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -18,7 +18,10 @@ libsquashfs_la_SOURCES += lib/sqfs/read_inode.c lib/sqfs/write_inode.c
libsquashfs_la_SOURCES += lib/sqfs/dir_writer.c lib/sqfs/xattr/xattr_reader.c
libsquashfs_la_SOURCES += lib/sqfs/read_table.c lib/sqfs/comp/compressor.c
libsquashfs_la_SOURCES += lib/sqfs/comp/internal.h
-libsquashfs_la_SOURCES += lib/sqfs/dir_reader.c lib/sqfs/read_tree.c
+libsquashfs_la_SOURCES += lib/sqfs/dir_reader/dir_reader.c
+libsquashfs_la_SOURCES += lib/sqfs/dir_reader/find_by_path.c
+libsquashfs_la_SOURCES += lib/sqfs/dir_reader/read_tree.c
+libsquashfs_la_SOURCES += lib/sqfs/dir_reader/internal.h
libsquashfs_la_SOURCES += lib/sqfs/inode.c lib/sqfs/xattr/xattr_writer.c
libsquashfs_la_SOURCES += lib/sqfs/xattr/xattr_writer_flush.c
libsquashfs_la_SOURCES += lib/sqfs/xattr/xattr_writer_record.c
diff --git a/lib/sqfs/dir_reader.c b/lib/sqfs/dir_reader/dir_reader.c
index f560069..969b71d 100644
--- a/lib/sqfs/dir_reader.c
+++ b/lib/sqfs/dir_reader/dir_reader.c
@@ -5,36 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#define SQFS_BUILDING_DLL
-#include "config.h"
-
-#include "sqfs/meta_reader.h"
-#include "sqfs/dir_reader.h"
-#include "sqfs/compressor.h"
-#include "sqfs/super.h"
-#include "sqfs/inode.h"
-#include "sqfs/error.h"
-#include "sqfs/dir.h"
-#include "util.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-struct sqfs_dir_reader_t {
- sqfs_object_t base;
-
- sqfs_meta_reader_t *meta_dir;
- sqfs_meta_reader_t *meta_inode;
- const sqfs_super_t *super;
-
- sqfs_dir_header_t hdr;
- sqfs_u64 dir_block_start;
- size_t entries;
- size_t size;
-
- size_t start_size;
- sqfs_u16 dir_offset;
- sqfs_u16 inode_offset;
-};
+#include "internal.h"
static void dir_reader_destroy(sqfs_object_t *obj)
{
@@ -259,77 +230,3 @@ int sqfs_dir_reader_get_root_inode(sqfs_dir_reader_t *rd,
return sqfs_meta_reader_read_inode(rd->meta_inode, rd->super,
block_start, offset, inode);
}
-
-int sqfs_dir_reader_find_by_path(sqfs_dir_reader_t *rd,
- const sqfs_inode_generic_t *start,
- const char *path, sqfs_inode_generic_t **out)
-{
- sqfs_inode_generic_t *inode;
- sqfs_dir_entry_t *ent;
- const char *ptr;
- int ret = 0;
-
- if (start == NULL) {
- ret = sqfs_dir_reader_get_root_inode(rd, &inode);
- } else {
- inode = alloc_flex(sizeof(*inode), 1,
- start->payload_bytes_used);
- if (inode == NULL) {
- ret = SQFS_ERROR_ALLOC;
- } else {
- memcpy(inode, start,
- sizeof(*start) + start->payload_bytes_used);
- }
- }
-
- if (ret)
- return ret;
-
- while (*path != '\0') {
- if (*path == '/') {
- while (*path == '/')
- ++path;
- continue;
- }
-
- ret = sqfs_dir_reader_open_dir(rd, inode, 0);
- free(inode);
- if (ret)
- return ret;
-
- ptr = strchr(path, '/');
- if (ptr == NULL) {
-
- if (ptr == NULL) {
- for (ptr = path; *ptr != '\0'; ++ptr)
- ;
- }
- }
-
- do {
- ret = sqfs_dir_reader_read(rd, &ent);
- if (ret < 0)
- return ret;
-
- if (ret == 0) {
- ret = strncmp((const char *)ent->name,
- path, ptr - path);
- if (ret == 0)
- ret = ent->name[ptr - path];
- free(ent);
- }
- } while (ret < 0);
-
- if (ret > 0)
- return SQFS_ERROR_NO_ENTRY;
-
- ret = sqfs_dir_reader_get_inode(rd, &inode);
- if (ret)
- return ret;
-
- path = ptr;
- }
-
- *out = inode;
- return 0;
-}
diff --git a/lib/sqfs/dir_reader/find_by_path.c b/lib/sqfs/dir_reader/find_by_path.c
new file mode 100644
index 0000000..0cd800f
--- /dev/null
+++ b/lib/sqfs/dir_reader/find_by_path.c
@@ -0,0 +1,82 @@
+/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/*
+ * find_by_path.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#define SQFS_BUILDING_DLL
+#include "internal.h"
+
+int sqfs_dir_reader_find_by_path(sqfs_dir_reader_t *rd,
+ const sqfs_inode_generic_t *start,
+ const char *path, sqfs_inode_generic_t **out)
+{
+ sqfs_inode_generic_t *inode;
+ sqfs_dir_entry_t *ent;
+ const char *ptr;
+ int ret = 0;
+
+ if (start == NULL) {
+ ret = sqfs_dir_reader_get_root_inode(rd, &inode);
+ } else {
+ inode = alloc_flex(sizeof(*inode), 1,
+ start->payload_bytes_used);
+ if (inode == NULL) {
+ ret = SQFS_ERROR_ALLOC;
+ } else {
+ memcpy(inode, start,
+ sizeof(*start) + start->payload_bytes_used);
+ }
+ }
+
+ if (ret)
+ return ret;
+
+ while (*path != '\0') {
+ if (*path == '/') {
+ while (*path == '/')
+ ++path;
+ continue;
+ }
+
+ ret = sqfs_dir_reader_open_dir(rd, inode, 0);
+ free(inode);
+ if (ret)
+ return ret;
+
+ ptr = strchr(path, '/');
+ if (ptr == NULL) {
+
+ if (ptr == NULL) {
+ for (ptr = path; *ptr != '\0'; ++ptr)
+ ;
+ }
+ }
+
+ do {
+ ret = sqfs_dir_reader_read(rd, &ent);
+ if (ret < 0)
+ return ret;
+
+ if (ret == 0) {
+ ret = strncmp((const char *)ent->name,
+ path, ptr - path);
+ if (ret == 0)
+ ret = ent->name[ptr - path];
+ free(ent);
+ }
+ } while (ret < 0);
+
+ if (ret > 0)
+ return SQFS_ERROR_NO_ENTRY;
+
+ ret = sqfs_dir_reader_get_inode(rd, &inode);
+ if (ret)
+ return ret;
+
+ path = ptr;
+ }
+
+ *out = inode;
+ return 0;
+}
diff --git a/lib/sqfs/dir_reader/internal.h b/lib/sqfs/dir_reader/internal.h
new file mode 100644
index 0000000..ff162ff
--- /dev/null
+++ b/lib/sqfs/dir_reader/internal.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/*
+ * internal.h
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#ifndef DIR_READER_INTERNAL_H
+#define DIR_READER_INTERNAL_H
+
+#include "config.h"
+
+#include "sqfs/meta_reader.h"
+#include "sqfs/dir_reader.h"
+#include "sqfs/compressor.h"
+#include "sqfs/id_table.h"
+#include "sqfs/super.h"
+#include "sqfs/inode.h"
+#include "sqfs/error.h"
+#include "sqfs/dir.h"
+#include "util.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+struct sqfs_dir_reader_t {
+ sqfs_object_t base;
+
+ sqfs_meta_reader_t *meta_dir;
+ sqfs_meta_reader_t *meta_inode;
+ const sqfs_super_t *super;
+
+ sqfs_dir_header_t hdr;
+ sqfs_u64 dir_block_start;
+ size_t entries;
+ size_t size;
+
+ size_t start_size;
+ sqfs_u16 dir_offset;
+ sqfs_u16 inode_offset;
+};
+
+#endif /* DIR_READER_INTERNAL_H */
diff --git a/lib/sqfs/read_tree.c b/lib/sqfs/dir_reader/read_tree.c
index feda691..d173ef7 100644
--- a/lib/sqfs/read_tree.c
+++ b/lib/sqfs/dir_reader/read_tree.c
@@ -5,20 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#define SQFS_BUILDING_DLL
-#include "config.h"
-
-#include "sqfs/meta_reader.h"
-#include "sqfs/dir_reader.h"
-#include "sqfs/compressor.h"
-#include "sqfs/id_table.h"
-#include "sqfs/super.h"
-#include "sqfs/inode.h"
-#include "sqfs/error.h"
-#include "sqfs/dir.h"
-#include "util.h"
-
-#include <string.h>
-#include <stdlib.h>
+#include "internal.h"
static int should_skip(int type, unsigned int flags)
{