summaryrefslogtreecommitdiff
path: root/include/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-08 14:53:30 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-08 14:53:30 +0200
commit3a851dfe87c88ac1d4dddc2a26cc48b037f852f9 (patch)
treea8a8f34291aa58b25737088d247a91a7f60b4fec /include/sqfs
parent60064dd0412a149fe00cfc4e2f2361c22656db57 (diff)
Replace direct file I/O with abstraction layer
This should make it easier to use libsquashfs with custom setups that embedd a squashfs image inside something else. Also, it should make it easier to port to non unix-like platforms. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/sqfs')
-rw-r--r--include/sqfs/compress.h4
-rw-r--r--include/sqfs/id_table.h4
-rw-r--r--include/sqfs/io.h44
-rw-r--r--include/sqfs/meta_reader.h2
-rw-r--r--include/sqfs/meta_writer.h2
-rw-r--r--include/sqfs/predef.h1
-rw-r--r--include/sqfs/super.h4
-rw-r--r--include/sqfs/table.h4
-rw-r--r--include/sqfs/xattr.h2
9 files changed, 56 insertions, 11 deletions
diff --git a/include/sqfs/compress.h b/include/sqfs/compress.h
index f0e3b76..e781e02 100644
--- a/include/sqfs/compress.h
+++ b/include/sqfs/compress.h
@@ -18,12 +18,12 @@ struct sqfs_compressor_t {
/* Write compressor options to the output file if necessary.
Returns the number of bytes written or -1 on failure.
Internally prints error messages to stderr. */
- int (*write_options)(sqfs_compressor_t *cmp, int fd);
+ int (*write_options)(sqfs_compressor_t *cmp, sqfs_file_t *file);
/* Read compressor options to the input file.
Returns zero on success, -1 on failure.
Internally prints error messages to stderr. */
- int (*read_options)(sqfs_compressor_t *cmp, int fd);
+ int (*read_options)(sqfs_compressor_t *cmp, sqfs_file_t *file);
/*
Compress or uncompress a chunk of data.
diff --git a/include/sqfs/id_table.h b/include/sqfs/id_table.h
index 3610640..6b058ae 100644
--- a/include/sqfs/id_table.h
+++ b/include/sqfs/id_table.h
@@ -25,12 +25,12 @@ SQFS_API int sqfs_id_table_id_to_index(sqfs_id_table_t *tbl, uint32_t id,
/* Write an ID table to a SquashFS image.
Returns 0 on success. Internally prints error message to stderr. */
-SQFS_API int sqfs_id_table_write(sqfs_id_table_t *tbl, int outfd,
+SQFS_API int sqfs_id_table_write(sqfs_id_table_t *tbl, sqfs_file_t *file,
sqfs_super_t *super, sqfs_compressor_t *cmp);
/* Read an ID table from a SquashFS image.
Returns 0 on success. Internally prints error messages to stderr. */
-SQFS_API int sqfs_id_table_read(sqfs_id_table_t *tbl, int fd,
+SQFS_API int sqfs_id_table_read(sqfs_id_table_t *tbl, sqfs_file_t *file,
sqfs_super_t *super, sqfs_compressor_t *cmp);
SQFS_API int sqfs_id_table_index_to_id(const sqfs_id_table_t *tbl,
diff --git a/include/sqfs/io.h b/include/sqfs/io.h
new file mode 100644
index 0000000..f290c2d
--- /dev/null
+++ b/include/sqfs/io.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * io.h
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#ifndef SQFS_IO_H
+#define SQFS_IO_H
+
+#include "sqfs/predef.h"
+
+typedef enum {
+ SQFS_FILE_OPEN_READ_ONLY = 0x01,
+
+ SQFS_FILE_OPEN_OVERWRITE = 0x02,
+
+ SQFS_FILE_OPEN_ALL_FLAGS = 0x03,
+} E_SQFS_FILE_OPEN_FLAGS;
+
+struct sqfs_file_t {
+ void (*destroy)(sqfs_file_t *file);
+
+ int (*read_at)(sqfs_file_t *file, uint64_t offset,
+ void *buffer, size_t size);
+
+ int (*write_at)(sqfs_file_t *file, uint64_t offset,
+ const void *buffer, size_t size);
+
+ uint64_t (*get_size)(sqfs_file_t *file);
+
+ int (*truncate)(sqfs_file_t *file, uint64_t size);
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SQFS_API sqfs_file_t *sqfs_open_file(const char *filename, int flags);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SQFS_IO_H */
diff --git a/include/sqfs/meta_reader.h b/include/sqfs/meta_reader.h
index f5008d4..00a6d65 100644
--- a/include/sqfs/meta_reader.h
+++ b/include/sqfs/meta_reader.h
@@ -19,7 +19,7 @@ extern "C" {
Start offset and limit can be specified to do bounds checking against
a subregion of the filesystem image.
*/
-SQFS_API sqfs_meta_reader_t *sqfs_meta_reader_create(int fd,
+SQFS_API sqfs_meta_reader_t *sqfs_meta_reader_create(sqfs_file_t *file,
sqfs_compressor_t *cmp,
uint64_t start,
uint64_t limit);
diff --git a/include/sqfs/meta_writer.h b/include/sqfs/meta_writer.h
index 9cd1598..3b255f2 100644
--- a/include/sqfs/meta_writer.h
+++ b/include/sqfs/meta_writer.h
@@ -18,7 +18,7 @@ extern "C" {
If keep_in_mem is true, the blocks are collected in memory and must
be explicitly flushed to disk using meta_write_write_to_file.
*/
-SQFS_API sqfs_meta_writer_t *sqfs_meta_writer_create(int fd,
+SQFS_API sqfs_meta_writer_t *sqfs_meta_writer_create(sqfs_file_t *file,
sqfs_compressor_t *cmp,
bool keep_in_mem);
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h
index 6df257c..df08b1b 100644
--- a/include/sqfs/predef.h
+++ b/include/sqfs/predef.h
@@ -47,6 +47,7 @@ typedef struct sqfs_id_table_t sqfs_id_table_t;
typedef struct sqfs_meta_reader_t sqfs_meta_reader_t;
typedef struct sqfs_meta_writer_t sqfs_meta_writer_t;
typedef struct sqfs_xattr_reader_t sqfs_xattr_reader_t;
+typedef struct sqfs_file_t sqfs_file_t;
typedef struct sqfs_fragment_t sqfs_fragment_t;
typedef struct sqfs_dir_header_t sqfs_dir_header_t;
diff --git a/include/sqfs/super.h b/include/sqfs/super.h
index b1ce82b..a8697a1 100644
--- a/include/sqfs/super.h
+++ b/include/sqfs/super.h
@@ -73,10 +73,10 @@ SQFS_API int sqfs_super_init(sqfs_super_t *super, size_t block_size,
E_SQFS_COMPRESSOR compressor);
/* Returns 0 on success. Prints error messages to stderr on failure. */
-SQFS_API int sqfs_super_write(sqfs_super_t *super, int fd);
+SQFS_API int sqfs_super_write(sqfs_super_t *super, sqfs_file_t *file);
/* Returns 0 on success. Prints error messages to stderr on failure. */
-SQFS_API int sqfs_super_read(sqfs_super_t *super, int fd);
+SQFS_API int sqfs_super_read(sqfs_super_t *super, sqfs_file_t *file);
#ifdef __cplusplus
}
diff --git a/include/sqfs/table.h b/include/sqfs/table.h
index f837f6b..7767b9a 100644
--- a/include/sqfs/table.h
+++ b/include/sqfs/table.h
@@ -24,12 +24,12 @@ extern "C" {
Returns 0 on success. Internally prints error messages to stderr.
*/
-SQFS_API int sqfs_write_table(int outfd, sqfs_super_t *super,
+SQFS_API int sqfs_write_table(sqfs_file_t *file, sqfs_super_t *super,
sqfs_compressor_t *cmp,
const void *data, size_t table_size,
uint64_t *start);
-SQFS_API int sqfs_read_table(int fd, sqfs_compressor_t *cmp,
+SQFS_API int sqfs_read_table(sqfs_file_t *file, sqfs_compressor_t *cmp,
size_t table_size, uint64_t location,
uint64_t lower_limit, uint64_t upper_limit,
void **out);
diff --git a/include/sqfs/xattr.h b/include/sqfs/xattr.h
index 0f9cf32..23587d1 100644
--- a/include/sqfs/xattr.h
+++ b/include/sqfs/xattr.h
@@ -58,7 +58,7 @@ SQFS_API int sqfs_xattr_reader_load_locations(sqfs_xattr_reader_t *xr);
SQFS_API void sqfs_xattr_reader_destroy(sqfs_xattr_reader_t *xr);
-SQFS_API sqfs_xattr_reader_t *sqfs_xattr_reader_create(int sqfsfd,
+SQFS_API sqfs_xattr_reader_t *sqfs_xattr_reader_create(sqfs_file_t *file,
sqfs_super_t *super,
sqfs_compressor_t *cmp);