aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Antonio Alvarez <pauloaalvarez@gmail.com>2020-12-22 15:15:51 -0300
committerTheodore Ts'o <tytso@mit.edu>2021-03-31 16:09:14 -0400
commit86b6db9f5a431691fd93e24d5d07cb5f7a4351de (patch)
tree3d3d70744f5dfc3d1d6218c025beaf363994cc80
parentd04f34a050e3334456e9ee80f95869dc47b0fd9f (diff)
downloade2fsprogs-86b6db9f5a431691fd93e24d5d07cb5f7a4351de.tar.gz
libext2fs: code adaptation to use the Windows IO manager
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--include/mingw/unistd.h51
-rw-r--r--lib/ext2fs/ext2_io.h5
-rw-r--r--lib/ext2fs/getsectsize.c15
-rw-r--r--lib/ext2fs/getsize.c16
-rw-r--r--lib/support/plausible.c7
-rw-r--r--util/subst.c4
6 files changed, 88 insertions, 10 deletions
diff --git a/include/mingw/unistd.h b/include/mingw/unistd.h
index 9c0dc81ac..b2018584a 100644
--- a/include/mingw/unistd.h
+++ b/include/mingw/unistd.h
@@ -1,13 +1,54 @@
-
#pragma once
+// Copyright transferred from Raider Solutions, Inc to
+// Kern Sibbald and John Walker by express permission.
+//
+// Copyright (C) 2004-2006 Kern Sibbald
+// Copyright (C) 2014 Adam Kropelin
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this program; if not, write to the Free
+// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+
+#ifndef __COMPAT_UNISTD_H_
+#define __COMPAT_UNISTD_H_
+
#include_next <unistd.h>
-__inline __uid_t getuid(void){return 0;}
-__inline int geteuid(void){return 1;}
+#define _PC_PATH_MAX 1
+#define _PC_NAME_MAX 2
+
+#ifdef __cplusplus
+extern "C" {
+#endif
-__inline __gid_t getgid(void){return 0;}
-__inline __gid_t getegid(void){return 0;}
+long pathconf(const char *, int);
+#define getpid _getpid
+#define getppid() 0
+
+unsigned int sleep(unsigned int seconds);
+
+#define getuid() 0
+#define getgid() 0
+#define geteuid() 1
+#define getegid() 0
// no-oped sync
__inline void sync(void){};
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* __COMPAT_UNISTD_H_ */ \ No newline at end of file
diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index 95c25a7b1..8fe5b3235 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -142,9 +142,14 @@ extern errcode_t io_channel_cache_readahead(io_channel io,
unsigned long long block,
unsigned long long count);
+#ifdef _WIN32
+/* windows_io.c */
+extern io_manager windows_io_manager;
+#else
/* unix_io.c */
extern io_manager unix_io_manager;
extern io_manager unixfd_io_manager;
+#endif
/* sparse_io.c */
extern io_manager sparse_io_manager;
diff --git a/lib/ext2fs/getsectsize.c b/lib/ext2fs/getsectsize.c
index d6bc3767d..3a461eb9c 100644
--- a/lib/ext2fs/getsectsize.c
+++ b/lib/ext2fs/getsectsize.c
@@ -51,6 +51,11 @@
*/
errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
{
+#ifdef _WIN64
+ *sectsize = 512; // just guessing
+ return 0;
+#else // not _WIN64
+
int fd;
fd = ext2fs_open_file(file, O_RDONLY, 0);
@@ -72,6 +77,8 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
*sectsize = 0;
close(fd);
return 0;
+
+#endif // ifdef _WIN64
}
/*
@@ -110,6 +117,12 @@ int ext2fs_get_dio_alignment(int fd)
*/
errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
{
+#ifdef _WIN64
+
+ return ext2fs_get_device_sectsize(file, sectsize);
+
+#else // not _WIN64
+
int fd;
fd = ext2fs_open_file(file, O_RDONLY, 0);
@@ -133,4 +146,6 @@ errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
*sectsize = 0;
close(fd);
return 0;
+
+#endif // ifdef _WIN64
}
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index be067755f..726568214 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -71,6 +71,8 @@
#define HAVE_GET_FILE_SIZE_EX 1
#endif
+HANDLE windows_get_handle(io_channel channel);
+
errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
blk64_t *retblocks)
{
@@ -84,12 +86,17 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
DWORD filesize;
#endif /* HAVE_GET_FILE_SIZE_EX */
- dev = CreateFile(file, GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE ,
- NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ io_channel data_io = 0;
+ int retval;
+
+ retval = windows_io_manager->open(file, 0, &data_io);
+ if (retval)
+ return retval;
+ dev = windows_get_handle(data_io);
if (dev == INVALID_HANDLE_VALUE)
return EBADF;
+
if (DeviceIoControl(dev, IOCTL_DISK_GET_PARTITION_INFO,
&pi, sizeof(PARTITION_INFORMATION),
&pi, sizeof(PARTITION_INFORMATION),
@@ -120,7 +127,8 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
}
#endif /* HAVE_GET_FILE_SIZE_EX */
- CloseHandle(dev);
+ windows_io_manager->close(data_io);
+
return 0;
}
diff --git a/lib/support/plausible.c b/lib/support/plausible.c
index 024f205e8..2a3ae1407 100644
--- a/lib/support/plausible.c
+++ b/lib/support/plausible.c
@@ -103,7 +103,12 @@ static void print_ext2_info(const char *device)
time_t tm;
retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0,
- unix_io_manager, &fs);
+#ifdef _WIN64
+ windows_io_manager,
+#else
+ unix_io_manager,
+#endif
+ &fs);
if (retval)
return;
sb = fs->super;
diff --git a/util/subst.c b/util/subst.c
index 66d7d9a9e..c0eda5cf8 100644
--- a/util/subst.c
+++ b/util/subst.c
@@ -434,16 +434,20 @@ int main(int argc, char **argv)
printf("Using original atime\n");
set_utimes(outfn, fileno(old), tv);
}
+#ifndef _WIN64
if (ofd >= 0)
(void) fchmod(ofd, 0444);
+#endif
fclose(out);
if (unlink(newfn) < 0)
perror("unlink");
} else {
if (verbose)
printf("Creating or replacing %s.\n", outfn);
+#ifndef _WIN64
if (ofd >= 0)
(void) fchmod(ofd, 0444);
+#endif
fclose(out);
if (old)
fclose(old);