]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
AOSP: build mke2fs for windows using android mingw library
authorJin Qian <jinqian@google.com>
Wed, 12 Jul 2017 22:18:33 +0000 (15:18 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 26 Feb 2018 17:23:00 +0000 (12:23 -0500)
Bug: 23686092
Change-Id: I4c7b0c69e3e3c48321d3a0a964ad65c87fc32bbd
From AOSP commit: 83da0276c3ff0a1c33f9042798b319542e254060

24 files changed:
include/mingw/grp.h [new file with mode: 0644]
include/mingw/linux/types.h [new file with mode: 0644]
include/mingw/pwd.h [new file with mode: 0644]
include/mingw/sys/stat.h [new file with mode: 0644]
include/mingw/sys/sysmacros.h [new file with mode: 0644]
include/mingw/sys/types.h [new file with mode: 0644]
include/mingw/unistd.h [new file with mode: 0644]
lib/blkid/Android.bp
lib/blkid/list.h
lib/blkid/save.c
lib/config.h [new file with mode: 0644]
lib/e2p/Android.bp
lib/e2p/fgetversion.c
lib/e2p/fsetversion.c
lib/e2p/getversion.c
lib/e2p/setversion.c
lib/ext2fs/Android.bp
lib/support/Android.bp
lib/uuid/Android.bp
lib/uuid/gen_uuid.c
misc/Android.bp
misc/create_inode.c
misc/mk_hugefiles.c
misc/mke2fs.c

diff --git a/include/mingw/grp.h b/include/mingw/grp.h
new file mode 100644 (file)
index 0000000..67f62d9
--- /dev/null
@@ -0,0 +1,16 @@
+
+#pragma once
+
+#include <sys/types.h>
+
+__inline struct group * getgrnam(char* g){return 0;}
+
+struct group
+  {
+    char *gr_name;
+    char *gr_passwd;
+    __gid_t gr_gid;
+    char **gr_mem;
+  };
+
+#define getgrgid(i) NULL
diff --git a/include/mingw/linux/types.h b/include/mingw/linux/types.h
new file mode 100644 (file)
index 0000000..eb87011
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef _LINUX_TYPES_H
+#define _LINUX_TYPES_H
+
+//#ifndef _MSC_VER
+//#error  _MSC_VER not defined
+//#endif
+
+#include <sys/types.h>
+
+typedef unsigned __int8 __u8;
+typedef signed __int8 __s8;
+
+typedef signed   __int64 __s64;
+typedef unsigned __int64 __u64;
+
+typedef        signed   __int16        __s16;
+typedef        unsigned __int16        __u16;
+
+typedef        signed   __int32        __s32;
+typedef        unsigned __int32        __u32;
+
+typedef        signed   __int64        __s64;
+typedef        unsigned __int64        __u64;
+
+
+//typedef __u32 ino_t;
+typedef __u32 dev_t;
+typedef __u32 uid_t;
+typedef __u32 gid_t;
+
+#include <stdint.h>
+
+#endif /* LINUX_TYPES_H */
diff --git a/include/mingw/pwd.h b/include/mingw/pwd.h
new file mode 100644 (file)
index 0000000..d048842
--- /dev/null
@@ -0,0 +1,20 @@
+
+#pragma once
+
+#include <sys/types.h>
+
+__inline struct passwd* getpwnam (char* g){return 0;}
+
+struct passwd
+{
+  char *pw_name;
+  char *pw_passwd;
+  __uid_t pw_uid;
+  __gid_t pw_gid;
+  char *pw_gecos;
+  char *pw_dir;
+  char *pw_shell;
+};
+
+#define getpwuid(i) NULL
+
diff --git a/include/mingw/sys/stat.h b/include/mingw/sys/stat.h
new file mode 100644 (file)
index 0000000..0ca1d1b
--- /dev/null
@@ -0,0 +1,20 @@
+
+#pragma once
+
+#if HAVE_SYS_STAT_H
+#include_next <sys/stat.h>
+#endif
+
+#ifndef lstat
+#define lstat stat
+#endif
+
+#ifndef S_ISLNK
+#ifdef __S_IFLNK
+#define S_ISLNK(mode)  __S_ISTYPE((mode), __S_IFLNK)
+#else
+#define S_ISLNK(mode)  0
+#endif
+#endif
+
+#define link(a, b)     CreateHardLink((a), (b), NULL)
diff --git a/include/mingw/sys/sysmacros.h b/include/mingw/sys/sysmacros.h
new file mode 100644 (file)
index 0000000..18fcaaa
--- /dev/null
@@ -0,0 +1,11 @@
+
+#pragma once
+
+/*
+ * Fall back to Linux's definitions of makedev and major are needed.
+ * The search_sysfs_block() function is highly unlikely to work on
+ * non-Linux systems anyway.
+ */
+#ifndef makedev
+#define makedev(maj, min) (((maj) << 8) + (min))
+#endif
\ No newline at end of file
diff --git a/include/mingw/sys/types.h b/include/mingw/sys/types.h
new file mode 100644 (file)
index 0000000..9d048fc
--- /dev/null
@@ -0,0 +1,9 @@
+
+#pragma once
+
+#include_next <sys/types.h>
+
+#include <linux/types.h>
+
+typedef unsigned short __uid_t;
+typedef unsigned short __gid_t;
diff --git a/include/mingw/unistd.h b/include/mingw/unistd.h
new file mode 100644 (file)
index 0000000..9c0dc81
--- /dev/null
@@ -0,0 +1,13 @@
+
+#pragma once
+
+#include_next <unistd.h>
+
+__inline __uid_t getuid(void){return 0;}
+__inline int geteuid(void){return 1;}
+
+__inline __gid_t getgid(void){return 0;}
+__inline __gid_t getegid(void){return 0;}
+
+// no-oped sync
+__inline void sync(void){};
index 9b385f9c6398389521c9a98327c0453255473db2..53381df82ac4e61dfbcad2bc89406010cfd090d6 100644 (file)
@@ -20,11 +20,20 @@ cc_library {
     ],
     shared_libs: ["libext2_uuid"],
 
+    target: {
+        windows: {
+            include_dirs: [ "external/e2fsprogs/include/mingw" ],
+            cflags: [
+                "-Wno-pointer-to-int-cast",
+            ],
+            enabled: true
+        },
+    },
+
     cflags: [
         "-W",
         "-Wall",
         "-fno-strict-aliasing",
-        "-Wno-macro-redefined",
     ],
 
     header_libs: ["libext2-headers"],
index 26a5ac1b4cb58afe21e86555119685cbad5bf8c2..7e0ccd77dcdc6f4bea57ed348345ebecc82ee4a4 100644 (file)
@@ -146,7 +146,7 @@ _INLINE_ void list_splice(struct list_head *list, struct list_head *head)
  * @member:    the name of the list_struct within the struct.
  */
 #define list_entry(ptr, type, member) \
-       ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+       ((type *)((char *)(ptr)-(unsigned long)(intptr_t)(&((type *)0)->member)))
 
 /**
  * list_for_each - iterate over elements in a list
index 762ffefd7313ce11b4f8e696b976c930ba5bcd53..036f07a4a5a5b09b95fefcb1f534e2502f0df96d 100644 (file)
 #endif
 #include "blkidP.h"
 
+#ifdef _WIN32
+#include "windows.h"
+#endif
+
 static int save_dev(blkid_dev dev, FILE *file)
 {
        struct list_head *p;
@@ -102,7 +106,11 @@ int blkid_flush_cache(blkid_cache cache)
                                file = fdopen(fd, "w");
                                opened = tmp;
                        }
+#ifndef _WIN32
                        fchmod(fd, 0644);
+#else
+                       chmod(tmp, 0644);
+#endif
                }
        }
 
diff --git a/lib/config.h b/lib/config.h
new file mode 100644 (file)
index 0000000..029f7da
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef __APPLE__
+#define HAVE_MALLOC_H 1
+#endif
+
+#define ROOT_SYSCONFDIR "/etc"
+
+#define ENABLE_LIBSPARSE 1
+
+#define DISABLE_BACKTRACE 1
+#define HAVE_DIRENT_H 1
+#define HAVE_ERRNO_H 1
+#define HAVE_GETOPT_H 1
+#define HAVE_GETPWUID_R 1
+#define HAVE_INTPTR_T 1
+#define HAVE_INTTYPES_H 1
+#ifdef __linux__
+#define HAVE_LSEEK64 1
+#define HAVE_LSEEK64_PROTOTYPE 1
+#endif
+#define HAVE_MMAP 1
+#ifdef __linux__
+#define HAVE_MNTENT_H 1
+#endif
+#define HAVE_SETJMP_H 1
+#ifdef __linux__
+#define HAVE_SETMNTENT 1
+#endif
+#define HAVE_SNPRINTF 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRDUP 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRNLEN 1
+#define HAVE_STRPTIME 1
+#define HAVE_SYSCONF 1
+#define HAVE_TYPE_SSIZE_T 1
+#define HAVE_UNISTD_H 1
+#define HAVE_UTIME_H 1
+
+#define HAVE_SYS_STAT_H 1
+#define HAVE_SYS_TIME_H 1
+#define HAVE_SYS_TYPES_H 1
+
+#if defined(_WIN32)
+# define HAVE_LINUX_TYPES_H 1
+# define HAVE_WINSOCK_H 1
+# define HAVE_SYS_SYSMACROS_H 1
+#endif
+#if defined(__APPLE__) || defined(__linux__)
+# define HAVE_FCNTL 1
+# define HAVE_FSYNC 1
+# define HAVE_GETPAGESIZE 1
+# define HAVE_NET_IF_H 1
+# define HAVE_NETINET_IN_H 1
+# define HAVE_PREAD 1
+# define HAVE_PWRITE 1
+# define HAVE_POSIX_MEMALIGN 1
+# define HAVE_SYS_IOCTL_H 1
+# define HAVE_SYS_MMAN_H 1
+# define HAVE_SYS_MOUNT_H 1
+# define HAVE_SYS_PARAM_H 1
+# define HAVE_SYS_RESOURCE_H 1
+# define HAVE_SYS_SELECT_H 1
+# define HAVE_SYS_WAIT_H 1
+#endif
+#if defined(__linux__)
+# define HAVE_EXT2_IOCTLS 1
+# define HAVE_FALLOCATE 1
+# define HAVE_LINUX_FD_H 1
+# define HAVE_LINUX_TYPES_H 1
+# define HAVE_LSEEK64 1
+# define HAVE_LSEEK64_PROTOTYPE 1
+# define HAVE_PREAD64 1
+# define HAVE_PWRITE64 1
+# define HAVE_SYS_PRCTL_H 1
+# define HAVE_SYS_SYSMACROS_H 1
+#endif
index db516707abedfcbc4b6d377530519344b066741c..9d5b0b619641485b64b60140b72859ae0df62865 100644 (file)
@@ -35,6 +35,13 @@ cc_library {
         "-Wno-macro-redefined",
     ],
 
+    target: {
+        windows: {
+            include_dirs: [ "external/e2fsprogs/include/mingw" ],
+            enabled: true
+        },
+    },
+
     header_libs: ["libext2-headers"],
     export_include_dirs: ["."],
     export_header_lib_headers: ["libext2-headers"],
index 33becfe35b0e086daa03370112dea28ab8183c22..a65e9a5c5ff89f95d713ba44582957d16ecd842a 100644 (file)
@@ -31,7 +31,9 @@
 #include <unistd.h>
 #endif
 #include <fcntl.h>
+#if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "e2p.h"
 
index dcbff5b9250364a416408c3ec70b3e8d3c16551d..c2e04559162fd7a2b44f3424e6aa48803b4ff075 100644 (file)
@@ -31,7 +31,9 @@
 #include <unistd.h>
 #endif
 #include <fcntl.h>
+#if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "e2p.h"
 
index 71031ffc327495cc54d24a859ed2322737b870b2..9f719b4a9ced1f3f0cdf7fca8fb63b2444d594b9 100644 (file)
@@ -20,7 +20,9 @@
 #if HAVE_ERRNO_H
 #include <errno.h>
 #endif
+#if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "e2p.h"
 
index 202834f15cfc2bc9de6c4dc2a3ee6570f031dd4f..2bc933749475af573ffbede41b8facf48804b038 100644 (file)
@@ -20,7 +20,9 @@
 #if HAVE_ERRNO_H
 #include <errno.h>
 #endif
+#if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "e2p.h"
 
index df07a9b7e7bc10742ccdc1eb4203c277c720807a..cc28de17a6caa1308b97185db8ba810d530f402c 100644 (file)
@@ -114,15 +114,10 @@ cc_library {
             ],
         },
         windows: {
-            // include/nonunix is used as an overlay on top of the system
-            // include directory. Some empty header files in include/nonunix
-            // hide the ones in the system include path. This setup doesn't work
-            // unless we pass the include/nonunix as an -isystem flag.
-            // TODO(deymo): Enable windows
-            enabled: false,
+            enabled: true,
+            include_dirs: [ "external/e2fsprogs/include/mingw" ],
             cflags: [
                 "-Wno-format",
-            //    "-isystem external/e2fsprogs/include/nonunix",
             ],
             host_ldlibs: ["-lws2_32"],
         },
index 24414a45ecf2d6302dca0889023c26c2b5140f97..4a89b8f32bc41002a4bdf560f00c6da0799f3ab8 100644 (file)
@@ -18,10 +18,15 @@ cc_library {
     ],
     shared_libs: [
         "libext2fs",
-        "libext2_com_err",
         "libext2_blkid",
     ],
 
+    target: {
+        windows: {
+            enabled: true
+        },
+    },
+
     cflags: [
         "-W",
         "-Wall",
index d173788a912e196a06e770cfb58afd480fc734ad..b6664f9911966977f134fd97f441ef5709e091e9 100644 (file)
@@ -22,7 +22,12 @@ cc_library {
         "-Wno-unused-function",
         "-Wno-unused-parameter",
     ],
-
+    target: {
+        windows: {
+            include_dirs: [ "external/e2fsprogs/include/mingw" ],
+            enabled: true
+        },
+    },
     header_libs: ["libext2-headers"],
     export_include_dirs: ["."],
     export_header_lib_headers: ["libext2-headers"],
index af5509352d2a590eba5ad132e772a204d93bc218..43ecc8ae48094fd6fc5e7c1ded8c0b6ad17d969a 100644 (file)
@@ -60,7 +60,9 @@
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <sys/stat.h>
 #ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
@@ -113,6 +115,7 @@ THREAD_LOCAL unsigned short jrand_seed[3];
 #endif
 
 #ifdef _WIN32
+#ifndef USE_MINGW
 static void gettimeofday (struct timeval *tv, void *dummy)
 {
        FILETIME        ftime;
@@ -129,11 +132,7 @@ static void gettimeofday (struct timeval *tv, void *dummy)
        tv->tv_sec = n / 1000000;
        tv->tv_usec = n % 1000000;
 }
-
-static int getuid (void)
-{
-       return 1;
-}
+#endif
 #endif
 
 static int get_random_fd(void)
@@ -317,7 +316,9 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
        THREAD_LOCAL FILE               *state_f;
        THREAD_LOCAL uint16_t           clock_seq;
        struct timeval                  tv;
+#ifndef _WIN32
        struct flock                    fl;
+#endif
        uint64_t                        clock_reg;
        mode_t                          save_umask;
        int                             len;
@@ -335,6 +336,7 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
                        }
                }
        }
+#ifndef _WIN32
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_SET;
        fl.l_start = 0;
@@ -350,6 +352,7 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
                        break;
                }
        }
+#endif
        if (state_fd >= 0) {
                unsigned int cl;
                unsigned long tv1, tv2;
@@ -413,11 +416,13 @@ try_again:
                        fflush(state_f);
                }
                rewind(state_f);
+#ifndef _WIN32
                fl.l_type = F_UNLCK;
                if (fcntl(state_fd, F_SETLK, &fl) < 0) {
                        fclose(state_f);
                        state_fd = -1;
                }
+#endif
        }
 
        *clock_high = clock_reg >> 32;
index e388d1ef477e11143b15ebf5582d239d4069cdee..0d315f20c1a5caab08a85c9c4eb06c669a55f8c9 100644 (file)
@@ -6,10 +6,17 @@ cc_library {
     name: "libext2_misc",
     host_supported: true,
 
+    target: {
+        windows: {
+            include_dirs: [ "external/e2fsprogs/include/mingw" ],
+            enabled: true
+        },
+    },
+
     srcs: [
         "create_inode.c",
     ],
-    cflags: ["-W", "-Wall", "-Wno-macro-redefined"],
+    cflags: ["-W", "-Wall"],
     shared_libs: [
         "libext2_quota",
         "libext2fs",
@@ -50,6 +57,13 @@ cc_binary {
                 "libz",
             ],
         },
+        windows: {
+            include_dirs: [ "external/e2fsprogs/include/mingw" ],
+            cflags: ["-D_POSIX", "-D__USE_MINGW_ALARM"],
+            ldflags: ["-static"],
+            host_ldlibs: ["-lws2_32"],
+            enabled: true
+        },
         android: {
             shared_libs: [
                 "libext2fs",
index 51d25f8fb0056ec96e6d69f651f432cec60e4f68..fb0a88f7631b051994fa49512784753250fc3953 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "config.h"
 #include <time.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <limits.h> /* for PATH_MAX */
@@ -23,7 +24,9 @@
 #elif defined HAVE_ATTR_XATTR_H
 #include <attr/xattr.h>
 #endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #ifdef HAVE_SYS_SYSMACROS_H
 #include <sys/sysmacros.h>
 #endif
@@ -229,6 +232,7 @@ static errcode_t set_inode_xattr(ext2_filsys fs EXT2FS_ATTR((unused)),
 }
 #endif  /* HAVE_LLISTXATTR */
 
+#ifndef _WIN32
 /* Make a special files (block and character devices), fifo's, and sockets  */
 errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
                            struct stat *st)
@@ -252,10 +256,12 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
                mode = LINUX_S_IFIFO;
                filetype = EXT2_FT_FIFO;
                break;
+#ifndef _WIN32
        case S_IFSOCK:
                mode = LINUX_S_IFSOCK;
                filetype = EXT2_FT_SOCK;
                break;
+#endif
        default:
                return EXT2_ET_INVALID_ARGUMENT;
        }
@@ -313,6 +319,7 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
 
        return retval;
 }
+#endif
 
 /* Make a symlink name -> target */
 errcode_t do_symlink_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
@@ -786,6 +793,7 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                case S_IFCHR:
                case S_IFBLK:
                case S_IFIFO:
+#ifndef _WIN32
                case S_IFSOCK:
                        retval = do_mknod_internal(fs, parent_ino, name, &st);
                        if (retval) {
@@ -830,6 +838,7 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                                goto out;
                        }
                        break;
+#endif
                case S_IFREG:
                        retval = do_write_internal(fs, parent_ino, name, name,
                                                   root);
index f34fa411d39aa506f56a23f963cd28f449a533dd..fe35a4baf6f6ba1c581b006caf9f5e445f3d6436 100644 (file)
@@ -32,7 +32,9 @@ extern int optind;
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #ifdef HAVE_SYS_SYSMACROS_H
index 7e82482367d5c9bbec47177fa2769c400d0dd12c..0321fc4e281227e7213a74072d7feb5d505f6a95 100644 (file)
@@ -43,7 +43,9 @@ extern int optind;
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <libgen.h>
 #include <limits.h>
 #include <blkid/blkid.h>
@@ -1899,10 +1901,15 @@ profile_error:
                dev_size = fs_blocks_count;
                retval = 0;
        } else
+#ifndef _WIN32
                retval = ext2fs_get_device_size2(device_name,
                                                 EXT2_BLOCK_SIZE(&fs_param),
                                                 &dev_size);
-
+#else
+               retval = ext2fs_get_device_size(device_name,
+                                               EXT2_BLOCK_SIZE(&fs_param),
+                                               &dev_size);
+#endif
        if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
                com_err(program_name, retval, "%s",
                        _("while trying to determine filesystem size"));