]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
AOSP: mke2fs, libext2fs: fix bugs on windows
authorJin Qian <jinqian@google.com>
Mon, 24 Jul 2017 21:18:16 +0000 (14:18 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 26 Feb 2018 17:22:57 +0000 (12:22 -0500)
Added O_BINARY to open output files on windows, otherwise they're
written as text files and have invalid data.

Use '(filename):block_count:block_size' for sparse file name because
windows file name can contain ':', e.g. 'c:\output_file'.

Bug: 23686092

Change-Id: I731c13e5df0be8c831464c431b8949d33438fb24
From AOSP commit: 0dcf8ec6a429ce4f024fe7838fee2d5636e8ba4d

contrib/android/e2fsdroid.c
lib/ext2fs/initialize.c
lib/ext2fs/sparse_io.c
misc/mke2fs.c

index 1ae133d5e8ecf2d12d63ca8f92bc1708417ba795..223ea687473b8a5c3cffab58ec0c24be0f3def61 100644 (file)
@@ -118,9 +118,17 @@ int main(int argc, char *argv[])
                fprintf(stderr, "Expected filename after options\n");
                exit(EXIT_FAILURE);
        }
-       in_file = strdup(argv[optind]);
 
-       io_mgr = android_sparse_file ? sparse_io_manager: unix_io_manager;
+       if (android_sparse_file) {
+               io_mgr = sparse_io_manager;
+               if (asprintf(&in_file, "(%s)", argv[optind]) == -1) {
+                       fprintf(stderr, "Failed to allocate file name\n");
+                       exit(EXIT_FAILURE);
+               }
+       } else {
+               io_mgr = unix_io_manager;
+               in_file = strdup(argv[optind]);
+       }
        retval = ext2fs_open(in_file, flags, 0, 0, io_mgr, &fs);
        if (retval) {
                com_err(prog_name, retval, "while opening file %s\n", in_file);
index 32f43210a23543c79dd5202fde95d5e60af1cb2d..99fedcd36b9396a568a54040359f2bc53587787b 100644 (file)
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #if defined(__linux__)    &&   defined(EXT2_OS_LINUX)
 #define CREATOR_OS EXT2_OS_LINUX
 #else
@@ -124,6 +128,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
                io_flags |= IO_FLAG_EXCLUSIVE;
        if (flags & EXT2_FLAG_DIRECT_IO)
                io_flags |= IO_FLAG_DIRECT_IO;
+       io_flags |= O_BINARY;
        retval = manager->open(name, io_flags, &fs->io);
        if (retval)
                goto cleanup;
index a307859f88602846b32d9d4e10bf553d689da56d..a83baf1f5c20397208a81a47de7fc6a05a9c5b9d 100644 (file)
@@ -7,6 +7,10 @@
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 #if !defined(ENABLE_LIBSPARSE)
 static errcode_t sparse_open(const char *name EXT2FS_ATTR((unused)),
                             int flags EXT2FS_ATTR((unused)),
@@ -155,7 +159,7 @@ static errcode_t io_manager_configure(struct sparse_io_params *params,
                        goto err_alloc;
                }
                if (params->fd < 0) {
-                       sm->fd = open(params->file, O_CREAT | O_RDWR | O_TRUNC,
+                       sm->fd = open(params->file, O_CREAT | O_RDWR | O_TRUNC | O_BINARY,
                                      0644);
                        if (sm->fd < 0) {
                                retval = errno;
@@ -206,11 +210,11 @@ static errcode_t read_sparse_argv(const char *name, bool is_fd,
        }
 
        if (is_fd) {
-               ret = sscanf(name, "%d:%llu:%u", &sparse_params->fd,
+               ret = sscanf(name, "(%d):%llu:%u", &sparse_params->fd,
                             (unsigned long long *)&sparse_params->blocks_count,
                             &sparse_params->block_size);
        } else {
-               ret = sscanf(name, "%[^:]%*[:]%llu%*[:]%u", sparse_params->file,
+               ret = sscanf(name, "(%[^)])%*[:]%llu%*[:]%u", sparse_params->file,
                             (unsigned long long *)&sparse_params->blocks_count,
                             &sparse_params->block_size);
        }
index cfb10bc45c0d55e5004ff22160606ac9579f753c..7e82482367d5c9bbec47177fa2769c400d0dd12c 100644 (file)
@@ -2854,7 +2854,7 @@ int main (int argc, char *argv[])
                                _("in malloc for android_sparse_params"));
                        exit(1);
                }
-               snprintf(android_sparse_params, PATH_MAX + 32, "%s:%u:%u",
+               snprintf(android_sparse_params, PATH_MAX + 32, "(%s):%u:%u",
                         device_name, fs_param.s_blocks_count,
                         1024 << fs_param.s_log_block_size);
                retval = ext2fs_initialize(android_sparse_params, flags,