From cdda846b47fae4633ba1084472c982766592ac10 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 2 Sep 2012 11:42:45 -0500 Subject: [PATCH] Compile on FreeBSD --- NEWS | 4 ++++ README | 11 ++++++++--- TODO | 1 + config.h.in | 30 ++++++++++++++++++++++++++++++ configure.ac | 8 +++++++- src/endianness.h | 36 +++++++++++++++++------------------- src/mount.c | 35 ++++++++++++++++++++++++++++------- src/ntfs-apply.c | 7 +++++++ src/ntfs-capture.c | 9 +++++++++ src/resource.c | 19 +++++++++++++------ src/util.h | 10 ++++++++++ src/wim.c | 12 ++++++++---- src/wimlib_internal.h | 4 ++-- 13 files changed, 144 insertions(+), 42 deletions(-) diff --git a/NEWS b/NEWS index 56028c75..dc3f218f 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ Only the most important changes more recent than version 0.6 are noted here. +Version 1.0.1: + Fixed problem when exporting images from XPRESS to LZX compressed WIM or + vice versa + Version 1.0.0: Enough changes to call it version 1.0.0! diff --git a/README b/README index 26d7e619..640432bb 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ WIMLIB -This is wimlib version 1.0.0 (September 2012). wimlib can be used to read, +This is wimlib version 1.0.1 (September 2012). wimlib can be used to read, write, and mount files in the Windows Imaging Format (WIM files). These files are normally created by using the `imagex.exe' utility on Windows, but this library provides a free implementation of imagex for UNIX-based @@ -184,8 +184,13 @@ wimlib has mostly been developed and tested on x86_64 (64-bit) GNU/Linux. It has been tested on x86 (32-bit) GNU/Linux occasionally. -I have tested a previous version of wimlib on FreeBSD and it worked, but this is -not well tested, especially with the more recent versions of this software. +wimlib may work on FreeBSD. However, this not well tested. If you do not have +libntfs-3g 2011-4-12 or later available, you may have to configure with +--without-ntfs-3g. Also, GNU coreutils is needed to run the test suite. Before +mounting a WIM you need to load the POSIX message queue module (run `kldload +mqueuefs'). There is no `fusermount' command on FreeBSD, so you must use +`umount' rather than `imagex unmount' to unmount a mounted WIM, but this won't +allow you to commit changes to a read-write mounted WIM... wimlib should work on big endian machines but it has not been tested. diff --git a/TODO b/TODO index 149d4e33..16538e77 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ - Fix bugs - Add more test cases - Implement LZX block splitting to improve compression ratio +- Improve performance of large directories in mounted WIMs. diff --git a/config.h.in b/config.h.in index db9f0e2d..72d81e68 100644 --- a/config.h.in +++ b/config.h.in @@ -27,9 +27,21 @@ /* Define to 1 if using the xattr interface to WIM alternate data streams */ #undef ENABLE_XATTR +/* Define to 1 if you have the header file. */ +#undef HAVE_ALLOCA_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_BYTESWAP_H + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H +/* Define to 1 if you have the header file. */ +#undef HAVE_ENDIAN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_ERRNO_H + /* Define if you have the iconv() function and it works. */ #undef HAVE_ICONV @@ -39,9 +51,15 @@ /* Define to 1 if you have the `ntfs-3g' library (-lntfs-3g). */ #undef HAVE_LIBNTFS_3G +/* Define to 1 if you have the header file. */ +#undef HAVE_MACHINE_ENDIAN_H + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the header file. */ +#undef HAVE_STDARG_H + /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H @@ -54,6 +72,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_BYTEORDER_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_ENDIAN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_PARAM_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H @@ -63,6 +90,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `utimensat' function. */ +#undef HAVE_UTIMENSAT + /* Define as const if the declaration of iconv() needs const. */ #undef ICONV_CONST diff --git a/configure.ac b/configure.ac index 179c2436..24952332 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([wimlib], [1.0.0], [ebiggers3@gmail.com]) +AC_INIT([wimlib], [1.0.1], [ebiggers3@gmail.com]) AC_CONFIG_SRCDIR([src/wim.c]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([build-aux]) @@ -30,6 +30,11 @@ AC_CONFIG_FILES([Makefile AC_PROG_CC AM_PROG_CC_C_O +AC_CHECK_FUNCS([utimensat]) +AC_CHECK_HEADERS([endian.h byteswap.h sys/byteorder.h sys/endian.h \ + sys/param.h machine/endian.h alloca.h stdlib.h stdarg.h \ + errno.h]) + AM_ICONV if test "x$am_cv_func_iconv" != "xyes"; then @@ -40,6 +45,7 @@ if test "x$am_cv_func_iconv" != "xyes"; then libraries.]) fi + AC_ARG_WITH(pkgconfigdir, [ --with-pkgconfigdir=DIR pkgconfig file in DIR @<:@LIBDIR/pkgconfig@:>@], [pkgconfigdir=$withval], diff --git a/src/endianness.h b/src/endianness.h index e0042167..e5f8009c 100644 --- a/src/endianness.h +++ b/src/endianness.h @@ -5,7 +5,16 @@ #include "config.h" #include -/* Changes the endianness of a 32-bit value. */ +#ifdef WORDS_BIGENDIAN + +#ifndef bswap16 +static inline uint16_t bswap16(uint16_t n) +{ + return (n << 8) | (n >> 8); +} +#endif + +#ifndef bswap32 static inline uint32_t bswap32(uint32_t n) { #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) @@ -15,19 +24,10 @@ static inline uint32_t bswap32(uint32_t n) (n >> 24); #endif } - -#ifdef WORDS_BIGENDIAN - -/* Big endian. */ - -/* Changes the endianness of a 16-bit value. */ -static inline uint16_t bswap16(uint16_t n) -{ - return (n << 8) | (n >> 8); -} +#endif -/* Changes the endianness of a 64-bit value. */ +#ifndef bswap64 static inline uint64_t bswap64(uint64_t n) { #ifdef __GNUC__ @@ -39,18 +39,18 @@ static inline uint64_t bswap64(uint64_t n) ((n & 0xff000000000000) >> 40) | (n >> 56); #endif } +#endif /* Not in place */ #define to_le16(n) bswap16(n) #define to_le32(n) bswap32(n) #define to_le64(n) bswap64(n) -#define to_be16(n) (n) -#define to_be32(n) (n) -#define to_be64(n) (n) +#ifndef _NTFS_ENDIANS_H #define le16_to_cpu(n) bswap16(n) #define le32_to_cpu(n) bswap32(n) #define le64_to_cpu(n) bswap64(n) +#endif /* In place */ #define TO_LE16(n) ((n) = to_le16(n)) @@ -82,13 +82,11 @@ static inline void array_to_le64(uint64_t *p, uint64_t n) #define to_le32(n) (n) #define to_le64(n) (n) +#ifndef _NTFS_ENDIANS_H #define le16_to_cpu(n) (n) #define le32_to_cpu(n) (n) #define le64_to_cpu(n) (n) - -#define to_be16(n) (bswap16(n)) -#define to_be32(n) (bswap32(n)) -#define to_be64(n) (bswap64(n)) +#endif /* In place */ #define TO_LE16(n) diff --git a/src/mount.c b/src/mount.c index 5b1e09e3..f152fcd7 100644 --- a/src/mount.c +++ b/src/mount.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifdef ENABLE_XATTR #include @@ -592,8 +593,8 @@ static inline int delete_staging_dir() * commands */ static char *unmount_to_daemon_mq_name; static char *daemon_to_unmount_mq_name; -static int unmount_to_daemon_mq; -static int daemon_to_unmount_mq; +static mqd_t unmount_to_daemon_mq; +static mqd_t daemon_to_unmount_mq; /* Simple function that returns the concatenation of 4 strings. */ static char *strcat_dup(const char *s1, const char *s2, const char *s3, @@ -681,7 +682,7 @@ static int open_message_queues(bool daemon) unmount_to_daemon_mq = mq_open(unmount_to_daemon_mq_name, flags, 0700, NULL); - if (unmount_to_daemon_mq == -1) { + if (unmount_to_daemon_mq == (mqd_t)-1) { ERROR_WITH_ERRNO("mq_open()"); ret = WIMLIB_ERR_MQUEUE; goto err2; @@ -695,7 +696,7 @@ static int open_message_queues(bool daemon) daemon_to_unmount_mq = mq_open(daemon_to_unmount_mq_name, flags, 0700, NULL); - if (daemon_to_unmount_mq == -1) { + if (daemon_to_unmount_mq == (mqd_t)-1) { ERROR_WITH_ERRNO("mq_open()"); ret = WIMLIB_ERR_MQUEUE; goto err3; @@ -1383,11 +1384,11 @@ dentry_link_group_set_times(struct dentry *dentry, u64 times[3]) struct dentry *cur = dentry; do { if (times[0]) - dentry->creation_time = times[0]; + cur->creation_time = times[0]; if (times[1]) - dentry->last_write_time = times[1]; + cur->last_write_time = times[1]; if (times[2]) - dentry->last_access_time = times[2]; + cur->last_access_time = times[2]; } while ((cur = container_of(dentry->link_group_list.next, struct dentry, link_group_list)) != dentry); @@ -1707,6 +1708,7 @@ static int wimfs_unlink(const char *path) return 0; } +#ifdef HAVE_UTIMENSAT /* * Change the timestamp on a file dentry. * @@ -1733,6 +1735,20 @@ static int wimfs_utimens(const char *path, const struct timespec tv[2]) dentry_link_group_set_times(dentry, times); return 0; } +#else +static int wimfs_utime(const char *path, struct utimbuf *times) +{ + struct dentry *dentry = get_dentry(w, path); + if (!dentry) + return -ENOENT; + u64 wim_times[3]; + wim_times[0] = 0; + wim_times[1] = unix_timestamp_to_wim(times->modtime); + wim_times[2] = unix_timestamp_to_wim(times->actime); + dentry_link_group_set_times(dentry, wim_times); + return 0; +} +#endif /* Writes to a file in the WIM filesystem. * It may be an alternate data stream, but here we don't even notice because we @@ -1802,7 +1818,11 @@ static struct fuse_operations wimfs_operations = { .symlink = wimfs_symlink, .truncate = wimfs_truncate, .unlink = wimfs_unlink, +#ifdef HAVE_UTIMENSAT .utimens = wimfs_utimens, +#else + .utime = wimfs_utime, +#endif .write = wimfs_write, }; @@ -2023,6 +2043,7 @@ WIMLIBAPI int wimlib_unmount(const char *dir, int flags) */ mount_dir = dir; + pid = fork(); if (pid == -1) { ERROR_WITH_ERRNO("Failed to fork()"); diff --git a/src/ntfs-apply.c b/src/ntfs-apply.c index d9f6d37a..8d142672 100644 --- a/src/ntfs-apply.c +++ b/src/ntfs-apply.c @@ -24,7 +24,14 @@ * along with wimlib; if not, see http://www.gnu.org/licenses/. */ + #include "config.h" + +#ifdef WITH_NTFS_3G +#include +#include +#endif + #include "wimlib_internal.h" diff --git a/src/ntfs-capture.c b/src/ntfs-capture.c index 2c478b10..9a8991ec 100644 --- a/src/ntfs-capture.c +++ b/src/ntfs-capture.c @@ -24,7 +24,14 @@ * along with wimlib; if not, see http://www.gnu.org/licenses/. */ + #include "config.h" + +#ifdef WITH_NTFS_3G +#include +#include +#endif + #include "wimlib_internal.h" @@ -567,11 +574,13 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p, if (ret != 0) return ret; } else { + #ifdef ENODATA if (errno != ENODATA) { ERROR_WITH_ERRNO("Error getting DOS name " "of `%s'", path); return WIMLIB_ERR_NTFS_3G; } + #endif } } diff --git a/src/resource.c b/src/resource.c index 3baa8f82..5ae2dff2 100644 --- a/src/resource.c +++ b/src/resource.c @@ -22,6 +22,17 @@ * wimlib; if not, see http://www.gnu.org/licenses/. */ +#include "config.h" + +#include +#include + +#ifdef WITH_NTFS_3G +#include +#include +#include +#endif + #include "wimlib_internal.h" #include "lookup_table.h" #include "io.h" @@ -29,17 +40,13 @@ #include "xpress.h" #include "sha1.h" #include "dentry.h" -#include "config.h" #include #include +#ifdef HAVE_ALLOCA_H #include - -#ifdef WITH_NTFS_3G -#include -#include -#include #endif + /* * Reads all or part of a compressed resource into an in-memory buffer. * diff --git a/src/util.h b/src/util.h index b459afd8..a8e06f7d 100644 --- a/src/util.h +++ b/src/util.h @@ -30,17 +30,27 @@ # define HOT #endif /* __GNUC__ */ +#ifndef _NTFS_TYPES_H typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; +#endif typedef unsigned uint; +#ifndef min #define min(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); \ (__a < __b) ? __a : __b; }) +#endif + +#ifndef max #define max(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); \ (__a > __b) ? __a : __b; }) +#endif + +#ifndef swap #define swap(a, b) ({typeof(a) _a = a; (a) = (b); (b) = _a;}) +#endif #define ARRAY_LEN(array) (sizeof(array) / sizeof((array)[0])) diff --git a/src/wim.c b/src/wim.c index 68e54bb8..e4da0a26 100644 --- a/src/wim.c +++ b/src/wim.c @@ -24,16 +24,20 @@ * along with wimlib; if not, see http://www.gnu.org/licenses/. */ -#include "wimlib_internal.h" -#include "io.h" -#include "lookup_table.h" -#include "xml.h" +#include "config.h" #include +#include #ifdef WITH_NTFS_3G #include #endif +#include "wimlib_internal.h" +#include "io.h" +#include "lookup_table.h" +#include "xml.h" + + static int print_metadata(WIMStruct *w) { print_security_data(wim_security_data(w)); diff --git a/src/wimlib_internal.h b/src/wimlib_internal.h index b7b2da26..57188c40 100644 --- a/src/wimlib_internal.h +++ b/src/wimlib_internal.h @@ -193,7 +193,7 @@ struct wim_header { #define WIM_HDR_FLAG_COMPRESS_LZX 0x00040000 #ifdef WITH_NTFS_3G -typedef struct _ntfs_volume ntfs_volume; +struct _ntfs_volume; #endif /* Structure for security data. Each image in the WIM file has its own security @@ -284,7 +284,7 @@ typedef struct WIMStruct { bool write_metadata; }; #ifdef WITH_NTFS_3G - ntfs_volume *ntfs_vol; + struct _ntfs_volume *ntfs_vol; #endif /* The currently selected image, indexed starting at 1. If not 0, -- 2.43.0