summaryrefslogtreecommitdiff
path: root/ext4_utils
diff options
context:
space:
mode:
authorRaphael Moll <raphael@google.com>2012-02-03 23:02:33 -0800
committerRaphael Moll <raphael@google.com>2012-02-16 13:15:04 -0800
commit4605b3fb8a00fa37f617a8d0fe3a095d0503a845 (patch)
tree648c0e8c3df25c4139cebb442c905b4ddc8ef99a /ext4_utils
parent3ee934fecdf8148ed5ea499932aedcca7530830c (diff)
downloadextras-4605b3fb8a00fa37f617a8d0fe3a095d0503a845.tar.gz
Adapt ext4_utils for windows.
This is not a full port of ext4_utils for windows. Instead it merely enables use to use the library for the 'create an empty fs image' functionality as used by 'fastboot format'. Change-Id: Ia1ffacd64e4233c4fbb369c4ac5927ccd72ac526
Diffstat (limited to 'ext4_utils')
-rw-r--r--ext4_utils/Android.mk41
-rw-r--r--ext4_utils/contents.c4
-rw-r--r--ext4_utils/ext4_utils.c10
-rw-r--r--ext4_utils/ext4_utils.h2
-rw-r--r--ext4_utils/ext4fixup.c5
-rw-r--r--ext4_utils/make_ext4fs.c34
-rw-r--r--ext4_utils/output_file.c33
-rw-r--r--ext4_utils/sha1.c2
-rw-r--r--ext4_utils/sha1.h13
-rw-r--r--ext4_utils/uuid.c5
10 files changed, 123 insertions, 26 deletions
diff --git a/ext4_utils/Android.mk b/ext4_utils/Android.mk
index 9b0dc1b5..f09197c6 100644
--- a/ext4_utils/Android.mk
+++ b/ext4_utils/Android.mk
@@ -4,7 +4,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
libext4_utils_src_files := \
- make_ext4fs.c \
+ make_ext4fs.c \
ext4fixup.c \
ext4_utils.c \
allocate.c \
@@ -15,34 +15,51 @@ libext4_utils_src_files := \
indirect.c \
uuid.c \
sha1.c \
- sparse_crc32.c \
- wipe.c
+ sparse_crc32.c \
+ wipe.c
+
+# -- All host/targets including windows
LOCAL_SRC_FILES := $(libext4_utils_src_files)
LOCAL_MODULE := libext4_utils
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += external/zlib
-LOCAL_SHARED_LIBRARIES := libz
+include $(BUILD_HOST_STATIC_LIBRARY)
-include $(BUILD_SHARED_LIBRARY)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := make_ext4fs_main.c
+LOCAL_MODULE := make_ext4fs
+LOCAL_STATIC_LIBRARIES += libext4_utils libz
+ifeq ($(HOST_OS),windows)
+LOCAL_LDLIBS += -lws2_32
+endif
+
+include $(BUILD_HOST_EXECUTABLE)
include $(CLEAR_VARS)
+# -- All host/targets excluding windows
+
+ifneq ($(HOST_OS),windows)
+
LOCAL_SRC_FILES := $(libext4_utils_src_files)
LOCAL_MODULE := libext4_utils
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += external/zlib
+LOCAL_SHARED_LIBRARIES := libz
-include $(BUILD_STATIC_LIBRARY)
+include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(libext4_utils_src_files)
LOCAL_MODULE := libext4_utils
LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES += external/zlib
-include $(BUILD_HOST_STATIC_LIBRARY)
+include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
@@ -55,14 +72,6 @@ include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := make_ext4fs_main.c
-LOCAL_MODULE := make_ext4fs
-LOCAL_STATIC_LIBRARIES += libext4_utils libz
-
-include $(BUILD_HOST_EXECUTABLE)
-
-include $(CLEAR_VARS)
-
LOCAL_SRC_FILES := ext2simg.c
LOCAL_MODULE := ext2simg
LOCAL_MODULE_TAGS := optional
@@ -160,3 +169,5 @@ LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_IS_HOST_MODULE := true
include $(BUILD_PREBUILT)
+
+endif
diff --git a/ext4_utils/contents.c b/ext4_utils/contents.c
index c7607ab1..d64f7e02 100644
--- a/ext4_utils/contents.c
+++ b/ext4_utils/contents.c
@@ -26,6 +26,10 @@
#include "extent.h"
#include "indirect.h"
+#ifdef USE_MINGW
+#define S_IFLNK 0 /* used by make_link, not needed under mingw */
+#endif
+
static u32 dentry_size(u32 entries, struct dentry *dentries)
{
u32 len = 24;
diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c
index 3d5895e3..9bb523f5 100644
--- a/ext4_utils/ext4_utils.c
+++ b/ext4_utils/ext4_utils.c
@@ -23,12 +23,17 @@
#include "extent.h"
#include <fcntl.h>
-#include <arpa/inet.h>
-#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
+#ifdef USE_MINGW
+#include <winsock2.h>
+#else
+#include <arpa/inet.h>
+#include <sys/ioctl.h>
+#endif
+
#if defined(__linux__)
#include <linux/fs.h>
#elif defined(__APPLE__) && defined(__MACH__)
@@ -514,4 +519,3 @@ u64 parse_num(const char *arg)
return num;
}
-
diff --git a/ext4_utils/ext4_utils.h b/ext4_utils/ext4_utils.h
index bb9c09e8..5b835edb 100644
--- a/ext4_utils/ext4_utils.h
+++ b/ext4_utils/ext4_utils.h
@@ -64,7 +64,9 @@ extern int force;
#define EXT4_SUPER_MAGIC 0xEF53
#define EXT4_JNL_BACKUP_BLOCKS 1
+#ifndef min /* already defined by windows.h */
#define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
#define DIV_ROUND_UP(x, y) (((x) + (y) - 1)/(y))
#define ALIGN(x, y) ((y) * DIV_ROUND_UP((x), (y)))
diff --git a/ext4_utils/ext4fixup.c b/ext4_utils/ext4fixup.c
index 5e04602a..c664ac3a 100644
--- a/ext4_utils/ext4fixup.c
+++ b/ext4_utils/ext4fixup.c
@@ -24,10 +24,13 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
+#ifndef USE_MINGW
+#include <sys/mman.h>
+#endif
+
#if defined(__APPLE__) && defined(__MACH__)
#define lseek64 lseek
#define off64_t off_t
diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c
index dbffc8d1..c11bebbf 100644
--- a/ext4_utils/make_ext4fs.c
+++ b/ext4_utils/make_ext4fs.c
@@ -22,6 +22,7 @@
#include "uuid.h"
#include "backed_block.h"
+#include <assert.h>
#include <dirent.h>
#include <libgen.h>
#include <stdio.h>
@@ -35,6 +36,31 @@
#include <private/android_filesystem_config.h>
#endif
+#ifdef USE_MINGW
+
+#include <winsock2.h>
+
+/* These match the Linux definitions of these flags.
+ L_xx is defined to avoid conflicting with the win32 versions.
+*/
+#define L_S_IRUSR 00400
+#define L_S_IWUSR 00200
+#define L_S_IXUSR 00100
+#define S_IRWXU (L_S_IRUSR | L_S_IWUSR | L_S_IXUSR)
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
+#define S_ISUID 0004000
+#define S_ISGID 0002000
+#define S_ISVTX 0001000
+
+#endif
+
/* TODO: Not implemented:
Allocating blocks in the same block group as the file inode
Hash or binary tree directories
@@ -67,6 +93,7 @@ static u32 build_default_directory_structure()
return root_inode;
}
+#ifndef USE_MINGW
/* Read a local directory and create the same tree in the generated filesystem.
Calls itself recursively with each directory in the given directory */
static u32 build_directory_structure(const char *full_path, const char *dir_path,
@@ -184,6 +211,7 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
free(dentries);
return inode;
}
+#endif
static u32 compute_block_size()
{
@@ -345,10 +373,16 @@ int make_ext4fs_internal(const char *filename, const char *directory,
if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE)
ext4_create_resize_inode();
+#ifdef USE_MINGW
+ // Windows needs only 'create an empty fs image' functionality
+ assert(!directory);
+ root_inode_num = build_default_directory_structure();
+#else
if (directory)
root_inode_num = build_directory_structure(directory, mountpoint, 0, android);
else
root_inode_num = build_default_directory_structure();
+#endif
root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
inode_set_permissions(root_inode_num, root_mode, 0, 0, 0);
diff --git a/ext4_utils/output_file.c b/ext4_utils/output_file.c
index 7b440208..7af48de0 100644
--- a/ext4_utils/output_file.c
+++ b/ext4_utils/output_file.c
@@ -23,12 +23,16 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
-
#include <zlib.h>
+#ifndef USE_MINGW
+#include <sys/mman.h>
+#define O_BINARY 0
+#endif
+
+
#if defined(__APPLE__) && defined(__MACH__)
#define lseek64 lseek
#define off64_t off_t
@@ -370,7 +374,7 @@ struct output_file *open_output_file(const char *filename, int gz, int sparse,
}
} else {
if (strcmp(filename, "-")) {
- out->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ out->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (out->fd < 0) {
error_errno("open");
free(out);
@@ -512,6 +516,7 @@ void write_data_file(struct output_file *out, u64 off, const char *file,
int ret;
off64_t aligned_offset;
int aligned_diff;
+ int buffer_size;
if (off + len >= (u64) info.len) {
error("attempted to write block %llu past end of filesystem",
@@ -519,7 +524,7 @@ void write_data_file(struct output_file *out, u64 off, const char *file,
return;
}
- int file_fd = open(file, O_RDONLY);
+ int file_fd = open(file, O_RDONLY | O_BINARY);
if (file_fd < 0) {
error_errno("open");
return;
@@ -527,14 +532,25 @@ void write_data_file(struct output_file *out, u64 off, const char *file,
aligned_offset = offset & ~(4096 - 1);
aligned_diff = offset - aligned_offset;
+ buffer_size = len + aligned_diff;
- u8 *data = mmap64(NULL, len + aligned_diff, PROT_READ, MAP_SHARED, file_fd,
+#ifndef USE_MINGW
+ u8 *data = mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, file_fd,
aligned_offset);
if (data == MAP_FAILED) {
error_errno("mmap64");
close(file_fd);
return;
}
+#else
+ u8 *data = malloc(buffer_size);
+ if (!data) {
+ error_errno("malloc");
+ close(file_fd);
+ return;
+ }
+ memset(data, 0, buffer_size);
+#endif
if (out->sparse) {
write_chunk_raw(out, off, data + aligned_diff, len);
@@ -549,6 +565,11 @@ void write_data_file(struct output_file *out, u64 off, const char *file,
}
err:
- munmap(data, len + aligned_diff);
+#ifndef USE_MINGW
+ munmap(data, buffer_size);
+#else
+ write(file_fd, data, buffer_size);
+ free(data);
+#endif
close(file_fd);
}
diff --git a/ext4_utils/sha1.c b/ext4_utils/sha1.c
index 1db9134a..463ec388 100644
--- a/ext4_utils/sha1.c
+++ b/ext4_utils/sha1.c
@@ -17,7 +17,9 @@
#define SHA1HANDSOFF /* Copies data before messing with it. */
+#ifndef USE_MINGW
#include <sys/cdefs.h>
+#endif
#include <sys/types.h>
#include <assert.h>
#include <string.h>
diff --git a/ext4_utils/sha1.h b/ext4_utils/sha1.h
index 71334c83..9a8f7e32 100644
--- a/ext4_utils/sha1.h
+++ b/ext4_utils/sha1.h
@@ -9,10 +9,21 @@
#ifndef _SYS_SHA1_H_
#define _SYS_SHA1_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdint.h>
+#ifdef USE_MINGW
+typedef unsigned char u_char;
+typedef unsigned int uint32_t;
+typedef unsigned int u_int32_t;
+typedef unsigned int u_int;
+
+#define __BEGIN_DECLS
+#define __END_DECLS
+#else
+#include <sys/cdefs.h>
+#endif
+
#define SHA1_DIGEST_LENGTH 20
#define SHA1_DIGEST_STRING_LENGTH 41
diff --git a/ext4_utils/uuid.c b/ext4_utils/uuid.c
index d518476a..33d2494a 100644
--- a/ext4_utils/uuid.c
+++ b/ext4_utils/uuid.c
@@ -15,7 +15,12 @@
*/
#include <string.h>
+
+#ifdef USE_MINGW
+#include <winsock2.h>
+#else
#include <arpa/inet.h>
+#endif
#include "ext4_utils.h"
#include "sha1.h"