From fd5c9f1259d0191af57b20f06dda35e62acb6275 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 13 Jun 2023 23:44:19 +0200 Subject: Overhaul sqfs_istream_t/sqfs_ostream_t error handling Report an error number from the implementations, change the users to forward that error number (which also means libtar write header/link now returns an error code) and all subsequent binaries to use sqfs_perror() instead of relying on the function to print an error internally. Also, make sure to preserve errno/GetLastError() in the implementations and print out a stringified error in sqfs_perror() if the error code indicates an I/O error. Signed-off-by: David Oberhollenzer --- bin/gensquashfs/Makemodule.am | 2 +- bin/gensquashfs/src/filemap_xattr.c | 8 ++++++-- bin/gensquashfs/src/fstree_from_file.c | 6 ++++-- bin/gensquashfs/src/mkfs.c | 6 ++++-- 4 files changed, 15 insertions(+), 7 deletions(-) (limited to 'bin/gensquashfs') diff --git a/bin/gensquashfs/Makemodule.am b/bin/gensquashfs/Makemodule.am index 98153cb..dd32d5a 100644 --- a/bin/gensquashfs/Makemodule.am +++ b/bin/gensquashfs/Makemodule.am @@ -26,7 +26,7 @@ test_filemap_xattr_SOURCES = bin/gensquashfs/test/filemap_xattr.c \ test_filemap_xattr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src test_filemap_xattr_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/xattr1.txt test_filemap_xattr_LDADD = libio.a libsquashfs.la libfstree.a libutil.a -test_filemap_xattr_LDADD += libcompat.a +test_filemap_xattr_LDADD += libcommon.a libcompat.a test_fstree_from_file_SOURCES = bin/gensquashfs/test/fstree_from_file.c \ bin/gensquashfs/src/fstree_from_file.c \ diff --git a/bin/gensquashfs/src/filemap_xattr.c b/bin/gensquashfs/src/filemap_xattr.c index 89624f4..8843c46 100644 --- a/bin/gensquashfs/src/filemap_xattr.c +++ b/bin/gensquashfs/src/filemap_xattr.c @@ -159,8 +159,12 @@ xattr_open_map_file(const char *path) { struct XattrMap *map; size_t line_num = 1; char *p = NULL; - sqfs_istream_t *file = istream_open_file(path); - if (file == NULL) { + sqfs_istream_t *file = NULL; + int ret; + + ret = istream_open_file(&file, path); + if (ret) { + sqfs_perror(path, NULL, ret); return NULL; } diff --git a/bin/gensquashfs/src/fstree_from_file.c b/bin/gensquashfs/src/fstree_from_file.c index efb5d43..f392b34 100644 --- a/bin/gensquashfs/src/fstree_from_file.c +++ b/bin/gensquashfs/src/fstree_from_file.c @@ -313,9 +313,11 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath) sqfs_istream_t *fp; int ret; - fp = istream_open_file(filename); - if (fp == NULL) + ret = istream_open_file(&fp, filename); + if (ret) { + sqfs_perror(filename, NULL, ret); return -1; + } ret = fstree_from_file_stream(fs, fp, basepath); diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index cdef359..de291fa 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -160,9 +160,11 @@ int main(int argc, char **argv) } if (opt.sortfile != NULL) { - sortfile = istream_open_file(opt.sortfile); - if (sortfile == NULL) + int ret = istream_open_file(&sortfile, opt.sortfile); + if (ret) { + sqfs_perror(opt.sortfile, NULL, ret); goto out; + } } if (opt.infile == NULL) { -- cgit v1.2.3