diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-08 14:53:30 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-08 14:53:30 +0200 |
commit | 3a851dfe87c88ac1d4dddc2a26cc48b037f852f9 (patch) | |
tree | a8a8f34291aa58b25737088d247a91a7f60b4fec /lib/sqfshelper/sqfs_reader.c | |
parent | 60064dd0412a149fe00cfc4e2f2361c22656db57 (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 'lib/sqfshelper/sqfs_reader.c')
-rw-r--r-- | lib/sqfshelper/sqfs_reader.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/sqfshelper/sqfs_reader.c b/lib/sqfshelper/sqfs_reader.c index 598b3c4..e9c9c33 100644 --- a/lib/sqfshelper/sqfs_reader.c +++ b/lib/sqfshelper/sqfs_reader.c @@ -18,13 +18,11 @@ int sqfs_reader_open(sqfs_reader_t *rd, const char *filename, int rdtree_flags) memset(rd, 0, sizeof(*rd)); - rd->sqfsfd = open(filename, O_RDONLY); - if (rd->sqfsfd < 0) { - perror(filename); + rd->file = sqfs_open_file(filename, SQFS_FILE_OPEN_READ_ONLY); + if (rd->file == NULL) return -1; - } - if (sqfs_super_read(&rd->super, rd->sqfsfd)) + if (sqfs_super_read(&rd->super, rd->file)) goto fail_fd; if (!sqfs_compressor_exists(rd->super.compression_id)) { @@ -41,21 +39,21 @@ int sqfs_reader_open(sqfs_reader_t *rd, const char *filename, int rdtree_flags) goto fail_fd; if (rd->super.flags & SQFS_FLAG_COMPRESSOR_OPTIONS) { - if (rd->cmp->read_options(rd->cmp, rd->sqfsfd)) + if (rd->cmp->read_options(rd->cmp, rd->file)) goto fail_cmp; } if (rd->super.flags & SQFS_FLAG_NO_XATTRS) rdtree_flags &= ~RDTREE_READ_XATTR; - if (deserialize_fstree(&rd->fs, &rd->super, rd->cmp, rd->sqfsfd, + if (deserialize_fstree(&rd->fs, &rd->super, rd->cmp, rd->file, rdtree_flags)) { goto fail_cmp; } fstree_gen_file_list(&rd->fs); - rd->data = data_reader_create(rd->sqfsfd, &rd->super, rd->cmp); + rd->data = data_reader_create(rd->file, &rd->super, rd->cmp); if (rd->data == NULL) goto fail_fs; @@ -65,7 +63,7 @@ fail_fs: fail_cmp: rd->cmp->destroy(rd->cmp); fail_fd: - close(rd->sqfsfd); + rd->file->destroy(rd->file); memset(rd, 0, sizeof(*rd)); return -1; } @@ -75,6 +73,6 @@ void sqfs_reader_close(sqfs_reader_t *rd) data_reader_destroy(rd->data); fstree_cleanup(&rd->fs); rd->cmp->destroy(rd->cmp); - close(rd->sqfsfd); + rd->file->destroy(rd->file); memset(rd, 0, sizeof(*rd)); } |