aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/rdsquashfs/src/fill_files.c4
-rw-r--r--bin/sqfsdiff/src/extract.c2
-rw-r--r--include/io/file.h11
-rw-r--r--include/sqfs/io.h9
-rw-r--r--lib/io/src/unix/ostream.c7
-rw-r--r--lib/io/src/win32/istream.c3
-rw-r--r--lib/io/src/win32/ostream.c25
7 files changed, 36 insertions, 25 deletions
diff --git a/bin/rdsquashfs/src/fill_files.c b/bin/rdsquashfs/src/fill_files.c
index 372752a..f482abe 100644
--- a/bin/rdsquashfs/src/fill_files.c
+++ b/bin/rdsquashfs/src/fill_files.c
@@ -139,10 +139,10 @@ static int fill_files(sqfs_data_reader_t *data, int flags)
ostream_t *fp;
size_t i;
- openflags = OSTREAM_OPEN_OVERWRITE;
+ openflags = SQFS_FILE_OPEN_OVERWRITE;
if (flags & UNPACK_NO_SPARSE)
- openflags |= OSTREAM_OPEN_NO_SPARSE;
+ openflags |= SQFS_FILE_OPEN_NO_SPARSE;
for (i = 0; i < num_files; ++i) {
fp = ostream_open_file(files[i].path, openflags);
diff --git a/bin/sqfsdiff/src/extract.c b/bin/sqfsdiff/src/extract.c
index a956480..3c8b568 100644
--- a/bin/sqfsdiff/src/extract.c
+++ b/bin/sqfsdiff/src/extract.c
@@ -21,7 +21,7 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode,
return -1;
*ptr = '/';
- fp = ostream_open_file(temp, OSTREAM_OPEN_OVERWRITE);
+ fp = ostream_open_file(temp, SQFS_FILE_OPEN_OVERWRITE);
if (fp == NULL) {
perror(temp);
return -1;
diff --git a/include/io/file.h b/include/io/file.h
index 297047f..d4f6fc1 100644
--- a/include/io/file.h
+++ b/include/io/file.h
@@ -18,11 +18,6 @@ typedef HANDLE os_file_t;
typedef int os_file_t;
#endif
-enum {
- OSTREAM_OPEN_OVERWRITE = 0x01,
- OSTREAM_OPEN_NO_SPARSE = 0x02,
-};
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -48,7 +43,7 @@ SQFS_INTERNAL istream_t *istream_open_handle(const char *path, os_file_t fd);
*
* @memberof ostream_t
*
- * If the flag OSTREAM_OPEN_NO_SPARSE is set, the underlying implementation
+ * If the flag SQFS_FILE_OPEN_NO_SPARSE is set, the underlying implementation
* always writes chunks of zero bytes when passing a NULL pointer to append.
* Otherwise, it tries to use seek/truncate style APIs to create sparse output
* files.
@@ -79,10 +74,10 @@ SQFS_INTERNAL istream_t *istream_open_file(const char *path);
* @memberof ostream_t
*
* If the file does not yet exist, it is created. If it does exist this
- * function fails, unless the flag OSTREAM_OPEN_OVERWRITE is set, in which
+ * function fails, unless the flag SQFS_FILE_OPEN_OVERWRITE is set, in which
* case the file is opened and its contents are discarded.
*
- * If the flag OSTREAM_OPEN_NO_SPARSE is set, the underlying implementation
+ * If the flag SQFS_FILE_OPEN_NO_SPARSE is set, the underlying implementation
* always writes chunks of zero bytes when passing a NULL pointer to append.
* Otherwise, it tries to use seek/truncate style APIs to create sparse output
* files.
diff --git a/include/sqfs/io.h b/include/sqfs/io.h
index 4cdb574..a1fb169 100644
--- a/include/sqfs/io.h
+++ b/include/sqfs/io.h
@@ -76,7 +76,14 @@ typedef enum {
*/
SQFS_FILE_OPEN_NO_CHARSET_XFRM = 0x04,
- SQFS_FILE_OPEN_ALL_FLAGS = 0x07,
+ /**
+ * @brief Do not use sparse file I/O APIs, always fill in zero bytes
+ *
+ * This flag currently has no effect on @ref sqfs_open_file.
+ */
+ SQFS_FILE_OPEN_NO_SPARSE = 0x08,
+
+ SQFS_FILE_OPEN_ALL_FLAGS = 0x0F,
} SQFS_FILE_OPEN_FLAGS;
/**
diff --git a/lib/io/src/unix/ostream.c b/lib/io/src/unix/ostream.c
index bc69f32..7093cc2 100644
--- a/lib/io/src/unix/ostream.c
+++ b/lib/io/src/unix/ostream.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "../internal.h"
+#include "sqfs/io.h"
typedef struct {
ostream_t base;
@@ -49,7 +50,7 @@ static int realize_sparse(file_ostream_t *file)
if (file->sparse_count == 0)
return 0;
- if (file->flags & OSTREAM_OPEN_NO_SPARSE) {
+ if (file->flags & SQFS_FILE_OPEN_NO_SPARSE) {
bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count;
buffer = calloc(1, bufsz);
if (buffer == NULL)
@@ -179,7 +180,7 @@ ostream_t *ostream_open_file(const char *path, int flags)
ostream_t *out;
int fd;
- if (flags & OSTREAM_OPEN_OVERWRITE) {
+ if (flags & SQFS_FILE_OPEN_OVERWRITE) {
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
} else {
fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
@@ -195,5 +196,5 @@ ostream_t *ostream_open_file(const char *path, int flags)
ostream_t *ostream_open_stdout(void)
{
return ostream_open_handle("stdout", STDOUT_FILENO,
- OSTREAM_OPEN_NO_SPARSE);
+ SQFS_FILE_OPEN_NO_SPARSE);
}
diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c
index 46bed30..d140142 100644
--- a/lib/io/src/win32/istream.c
+++ b/lib/io/src/win32/istream.c
@@ -153,10 +153,11 @@ fail_free:
istream_t *istream_open_file(const char *path)
{
- WCHAR *wpath = path_to_windows(path);
+ WCHAR *wpath = NULL;
istream_t *out;
HANDLE hnd;
+ wpath = path_to_windows(path);
if (wpath == NULL)
return NULL;
diff --git a/lib/io/src/win32/ostream.c b/lib/io/src/win32/ostream.c
index edbefc7..26d6f96 100644
--- a/lib/io/src/win32/ostream.c
+++ b/lib/io/src/win32/ostream.c
@@ -5,6 +5,7 @@
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "../internal.h"
+#include "sqfs/io.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -43,7 +44,7 @@ static int realize_sparse(file_ostream_t *file)
if (file->sparse_count == 0)
return 0;
- if (file->flags & OSTREAM_OPEN_NO_SPARSE) {
+ if (file->flags & SQFS_FILE_OPEN_NO_SPARSE) {
bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count;
buffer = calloc(1, bufsz);
@@ -175,24 +176,30 @@ fail_free:
ostream_t *ostream_open_file(const char *path, int flags)
{
- WCHAR *wpath = path_to_windows(path);
int access_flags, creation_mode;
+ WCHAR *wpath = NULL;
ostream_t *out;
HANDLE hnd;
- if (wpath == NULL)
- return NULL;
-
access_flags = GENERIC_WRITE;
- if (flags & OSTREAM_OPEN_OVERWRITE) {
+ if (flags & SQFS_FILE_OPEN_OVERWRITE) {
creation_mode = CREATE_ALWAYS;
} else {
creation_mode = CREATE_NEW;
}
- hnd = CreateFileW(wpath, access_flags, 0, NULL, creation_mode,
- FILE_ATTRIBUTE_NORMAL, NULL);
+ if (flags & SQFS_FILE_OPEN_NO_CHARSET_XFRM) {
+ hnd = CreateFileA(path, access_flags, 0, NULL, creation_mode,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ } else {
+ wpath = path_to_windows(path);
+ if (wpath == NULL)
+ return NULL;
+
+ hnd = CreateFileW(wpath, access_flags, 0, NULL, creation_mode,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ }
if (hnd == INVALID_HANDLE_VALUE) {
w32_perror(path);
@@ -213,5 +220,5 @@ ostream_t *ostream_open_stdout(void)
{
HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE);
- return ostream_open_handle("stdout", hnd, OSTREAM_OPEN_NO_SPARSE);
+ return ostream_open_handle("stdout", hnd, SQFS_FILE_OPEN_NO_SPARSE);
}