From 849e6718448793b12d7c6641d59779ca12a2ba08 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 15 Jun 2023 16:21:05 +0200 Subject: libsquashfs: cleanup the flag situation on istream/ostream functions - The ostream creation functions already have flag arguments, but make them an sqfs_u32 instead of int. - Add flag arguments to the istream functions, sanitzie and forward them when opening the handle. Signed-off-by: David Oberhollenzer --- lib/sqfs/src/unix/istream.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib/sqfs/src/unix/istream.c') diff --git a/lib/sqfs/src/unix/istream.c b/lib/sqfs/src/unix/istream.c index fd2f120..a0a3469 100644 --- a/lib/sqfs/src/unix/istream.c +++ b/lib/sqfs/src/unix/istream.c @@ -113,11 +113,16 @@ static void file_destroy(sqfs_object_t *obj) } int sqfs_istream_open_handle(sqfs_istream_t **out, const char *path, - sqfs_file_handle_t fd) + sqfs_file_handle_t fd, sqfs_u32 flags) { - file_istream_t *file = calloc(1, sizeof(*file)); - sqfs_istream_t *strm = (sqfs_istream_t *)file; + file_istream_t *file; + sqfs_istream_t *strm; + if (flags & ~(SQFS_FILE_OPEN_ALL_FLAGS)) + return SQFS_ERROR_UNSUPPORTED; + + file = calloc(1, sizeof(*file)); + strm = (sqfs_istream_t *)file; if (file == NULL) return SQFS_ERROR_ALLOC; @@ -149,16 +154,22 @@ int sqfs_istream_open_handle(sqfs_istream_t **out, const char *path, return 0; } -int sqfs_istream_open_file(sqfs_istream_t **out, const char *path) +int sqfs_istream_open_file(sqfs_istream_t **out, const char *path, + sqfs_u32 flags) { sqfs_file_handle_t fd; int ret; - ret = sqfs_open_native_file(&fd, path, SQFS_FILE_OPEN_READ_ONLY); + flags |= SQFS_FILE_OPEN_READ_ONLY; + + if (flags & (SQFS_FILE_OPEN_OVERWRITE | SQFS_FILE_OPEN_NO_SPARSE)) + return SQFS_ERROR_ARG_INVALID; + + ret = sqfs_open_native_file(&fd, path, flags); if (ret) return ret; - ret = sqfs_istream_open_handle(out, path, fd); + ret = sqfs_istream_open_handle(out, path, fd, flags); if (ret != 0) { int temp = errno; close(fd); -- cgit v1.2.3