From 3d84c998673ba7acf82ec5c26769a41e28a2cc7b Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 15 Aug 2013 12:12:26 -0500 Subject: [PATCH] Miscellaneous fixes and cleanups --- Makefile.am | 4 +- NEWS | 17 +++-- doc/imagex.1.in | 20 ++--- include/wimlib.h | 7 +- include/wimlib/dentry.h | 2 +- include/wimlib/file_io.h | 3 + include/wimlib/header.h | 5 +- include/wimlib/lookup_table.h | 6 +- programs/imagex.c | 6 +- rpm/wimlib-without-fuse-or-ntfs-3g.spec | 78 -------------------- rpm/wimlib.spec | 80 -------------------- rpm/wimtools.spec | 98 +++++++++++++++++++++++++ src/extract.c | 11 +-- src/mount_image.c | 14 ++-- src/ntfs-3g_apply.c | 39 +++++----- src/resource.c | 11 ++- src/unix_apply.c | 2 +- src/wim.c | 8 +- tests/test-imagex | 2 +- 19 files changed, 185 insertions(+), 228 deletions(-) delete mode 100644 rpm/wimlib-without-fuse-or-ntfs-3g.spec delete mode 100644 rpm/wimlib.spec create mode 100644 rpm/wimtools.spec diff --git a/Makefile.am b/Makefile.am index 4cf31bf9..6d24bdf1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,8 +186,8 @@ install-data-hook: uninstall-hook: if [ "@IMAGEX_PROGNAME@" != imagex ]; then \ - rm -f $(DESTDIR)$(bindir)/"@IMAGEX_PROGNAME@" \ - rm -f $(DESTDIR)$(bindir)/imagex \ + rm -f $(DESTDIR)$(bindir)/"@IMAGEX_PROGNAME@"; \ + rm -f $(DESTDIR)$(bindir)/imagex; \ fi for cmd in $(imagex_cmds); do \ rm -f $(DESTDIR)$(bindir)/wim$${cmd}; \ diff --git a/NEWS b/NEWS index 6175eb36..23b79dbc 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,13 @@ Only the most important changes more recent than version 0.6 are noted here. Version 1.5.0: - Added support for "pipable" WIMs. This support allows capturing images - to standard output or applying images from standard input, but they are + Added support for "pipable" WIMs. Pipable WIMs allow capturing images + to standard output and applying images from standard input, but they are not compatible with Microsoft's software and are not created by default. - See documentation for --pipable flag of `wimlib-imagex capture' for more - information. Two new functions have been added to the library to fully - support this: wimlib_write_to_fd() and wimlib_extract_image_from_pipe(). + See the documentation for --pipable flag of `wimlib-imagex capture' for + more information. Two new functions have been added to the library to + fully support this: wimlib_write_to_fd() and + wimlib_extract_image_from_pipe(). wimlib now preserve WIM integrity tables by default, even if WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is not specified. This changes the @@ -44,6 +45,12 @@ Version 1.5.0: and NTFS-3g). For example, hard-linked extraction mode (--hardlink) is now supported on all backends, not just UNIX. + The LZX compression and decompression code now compiles correctly on the + ARM architecture (where 'char' is unsigned). + + wimlib_split() progress messages now report the total number of parts + being written. + A few changes were made to the error codes returned by library routines. To make wimlib easier to use on Windows, wimlib_global_init() now diff --git a/doc/imagex.1.in b/doc/imagex.1.in index fc0edd28..7d4c9afc 100644 --- a/doc/imagex.1.in +++ b/doc/imagex.1.in @@ -51,31 +51,31 @@ or if you invoke it incorrectly, the full documentation for each \fB@IMAGEX_PROGNAME@\fR command can be found in the appropriate manual page. .PP Note: to save typing, if appropriate hard links or batch files have been -installed, a command \fB@IMAGEX_PROGNAME@ \fICOMMAND\fR can be accessed as +installed, a command \fB@IMAGEX_PROGNAME@ \fICOMMAND\fR can also be accessed as simply \fBwim\fICOMMAND\fR; for example, \fBwimapply\fR for \fB@IMAGEX_PROGNAME@ apply\fR. .SH SUPPORTED FEATURES The following are some of the main features currently supported by \fB@IMAGEX_PROGNAME@\fR, and pointers to the relevant commands: .IP \[bu] 4 -Create a stand-alone WIM from a directory or NTFS volume (\fB@IMAGEX_PROGNAME@ capture\fR) +Create a standalone WIM from a directory or NTFS volume (\fB@IMAGEX_PROGNAME@ capture\fR) .IP \[bu] Capture a WIM image directly to standard output in a special pipable format (\fB@IMAGEX_PROGNAME@ capture\fR) .IP \[bu] -Append a directory or NTFS volume onto a stand-alone WIM as a new image (\fB@IMAGEX_PROGNAME@ +Append a directory or NTFS volume onto a standalone WIM as a new image (\fB@IMAGEX_PROGNAME@ append\fR) .IP \[bu] -Apply an image from a stand-alone or split WIM to a directory or NTFS volume +Apply an image from a standalone or split WIM to a directory or NTFS volume (\fB@IMAGEX_PROGNAME@ apply\fR) .IP \[bu] Apply an image from a special pipable WIM format sent over standard input (\fB@IMAGEX_PROGNAME@ apply\fR) .IP \[bu] -Mount an image from a stand-alone or split WIM read-only (\fB@IMAGEX_PROGNAME@ +Mount an image from a standalone or split WIM read-only (\fB@IMAGEX_PROGNAME@ mount\fR) (not available on Windows) .IP \[bu] -Mount an image from a stand-alone WIM read-write (\fB@IMAGEX_PROGNAME@ +Mount an image from a standalone WIM read-write (\fB@IMAGEX_PROGNAME@ mountrw\fR) (not available on Windows) .IP \[bu] Extract individual files or directories from a WIM without mounting it @@ -83,9 +83,9 @@ Extract individual files or directories from a WIM without mounting it .IP \[bu] Make changes to a WIM image without mounting it (\fB@IMAGEX_PROGNAME@ update\fR) .IP \[bu] -Delete image(s) from a stand-alone WIM (\fB@IMAGEX_PROGNAME@ delete\fR) +Delete image(s) from a standalone WIM (\fB@IMAGEX_PROGNAME@ delete\fR) .IP \[bu] -Export image(s) from a stand-alone or split WIM (\fB@IMAGEX_PROGNAME@ export\fR) +Export image(s) from a standalone or split WIM (\fB@IMAGEX_PROGNAME@ export\fR) .IP \[bu] Display information about a WIM file (\fB@IMAGEX_PROGNAME@ info\fR, \fB@IMAGEX_PROGNAME@ dir\fR) .IP \[bu] @@ -93,9 +93,9 @@ Change the name or description of an image in the WIM (\fB@IMAGEX_PROGNAME@ info .IP \[bu] Change which image in a WIM is bootable (\fB@IMAGEX_PROGNAME@ info\fR) .IP \[bu] -Combine split WIMs into one stand-alone WIM (\fB@IMAGEX_PROGNAME@ join\fR) +Combine split WIMs into one standalone WIM (\fB@IMAGEX_PROGNAME@ join\fR) .IP \[bu] -Split a stand-alone WIM into multiple parts (\fB@IMAGEX_PROGNAME@ split\fR) +Split a standalone WIM into multiple parts (\fB@IMAGEX_PROGNAME@ split\fR) .IP \[bu] Support for all WIM compression types, both compression and decompression (LZX, XPRESS, and none) diff --git a/include/wimlib.h b/include/wimlib.h index af167428..a7e068ae 100644 --- a/include/wimlib.h +++ b/include/wimlib.h @@ -1856,10 +1856,9 @@ wimlib_extract_files(WIMStruct *wim, * Failed to set security descriptor on a file * (only if ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS) specified in @p * extract_flags. - * @retval ::WIMLIB_ERR_SET_SECURITY - * Failed to set security descriptor on a file - * (only if ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS) specified in @p - * extract_flags. + * @retval ::WIMLIB_ERR_SET_TIMESTAMPS + * Failed to set timestamps on a file (only if + * ::WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS) specified in @p extract_flags. * @retval ::WIMLIB_ERR_SPLIT_INVALID * The WIM is a split WIM, but the parts specified do not form a complete * split WIM because they do not include all the parts of the original WIM, diff --git a/include/wimlib/dentry.h b/include/wimlib/dentry.h index 6d8c557e..ad8b0328 100644 --- a/include/wimlib/dentry.h +++ b/include/wimlib/dentry.h @@ -575,7 +575,7 @@ inode_get_unix_data(const struct wim_inode *inode, extern int inode_set_unix_data(struct wim_inode *inode, uid_t uid, gid_t gid, mode_t mode, struct wim_lookup_table *lookup_table, int which); -#endif /* __WIN32__ */ +#endif /* !__WIN32__ */ extern bool inode_has_unix_data(const struct wim_inode *inode); diff --git a/include/wimlib/file_io.h b/include/wimlib/file_io.h index de59cfa0..85f293f1 100644 --- a/include/wimlib/file_io.h +++ b/include/wimlib/file_io.h @@ -4,6 +4,9 @@ #include #include +/* Wrapper around a file descriptor that keeps track of offset (including in + * pipes, which don't support lseek()) and a cached flag that tells whether the + * file descriptor is a pipe or not. */ struct filedes { int fd; unsigned int is_pipe : 1; diff --git a/include/wimlib/header.h b/include/wimlib/header.h index 238b6b22..637a4fef 100644 --- a/include/wimlib/header.h +++ b/include/wimlib/header.h @@ -16,8 +16,9 @@ * compatibility with Microsoft's software is desired). */ #define WIM_CHUNK_SIZE 32768 -/* Version of the WIM file. There is an older version, but wimlib doesn't - * support it. The differences between the versions are undocumented. */ +/* Version of the WIM file. There is an older version (used for prerelease + * versions of Windows Vista), but wimlib doesn't support it. The differences + * between the versions are undocumented. */ #define WIM_VERSION 0x10d00 /* WIM magic characters, translated to a single 64-bit little endian number. */ diff --git a/include/wimlib/lookup_table.h b/include/wimlib/lookup_table.h index e9532971..28862d5a 100644 --- a/include/wimlib/lookup_table.h +++ b/include/wimlib/lookup_table.h @@ -237,6 +237,9 @@ struct wim_lookup_table_entry { /* Used temporarily during WIM file writing */ struct { struct hlist_node hash_list_2; + + /* Links streams being written to the WIM. */ + struct list_head write_streams_list; }; /* Used temporarily during WIM file writing (after above) */ @@ -281,9 +284,6 @@ struct wim_lookup_table_entry { /* Links streams that are still unhashed after being been added * to a WIM. */ struct list_head unhashed_list; - - /* Links streams being written to the WIM. */ - struct list_head write_streams_list; }; static inline u64 diff --git a/programs/imagex.c b/programs/imagex.c index c97f2d73..e99202b1 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -3562,9 +3562,9 @@ static const tchar *get_cmd_string(int cmd, bool nospace) static void version(void) { - static const tchar *format = + static const tchar *s = T( -"%"TS" (" PACKAGE ") " PACKAGE_VERSION "\n" +IMAGEX_PROGNAME " (" PACKAGE ") " PACKAGE_VERSION "\n" "Copyright (C) 2012, 2013 Eric Biggers\n" "License GPLv3+; GNU GPL version 3 or later .\n" "This is free software: you are free to change and redistribute it.\n" @@ -3572,7 +3572,7 @@ version(void) "\n" "Report bugs to "PACKAGE_BUGREPORT".\n" ); - tprintf(format, invocation_name); + tfputs(s, stdout); } diff --git a/rpm/wimlib-without-fuse-or-ntfs-3g.spec b/rpm/wimlib-without-fuse-or-ntfs-3g.spec deleted file mode 100644 index 81761f9d..00000000 --- a/rpm/wimlib-without-fuse-or-ntfs-3g.spec +++ /dev/null @@ -1,78 +0,0 @@ -Summary: Library to extract, create, modify, and mount WIM files -Name: wimlib -Version: 1.5.0 -Release: 1 -License: GPLv3+ -Group: System/Libraries -URL: http://sourceforge.net/projects/wimlib -Packager: Eric Biggers -Source: http://downloads.sourceforge.net/wimlib/wimlib-%{version}.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root - -Requires: libxml2, openssl -BuildRequires: libxml2-devel, openssl-devel -%description -wimlib is a C library for creating, extracting, modifying, and mounting files in -the Windows Imaging Format (WIM files). It is similar to Microsoft's WIMGAPI -but is designed for both UNIX and Windows. - -%package devel -Summary: Development files for wimlib -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} -%description devel -Development files for wimlib - -%package -n wimtools -Summary: Tools to create, extract, modify, and mount WIM files -Group: Applications/System -Requires: %{name} = %{version}-%{release} -%description -n wimtools -Tools to create, extract, modify, 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 package contains a free implementation of ImageX called -"wimlib-imagex" that is designed to work on both UNIX and Windows. - -%prep -%setup -q -n %{name}-%{version} - -%build -%configure --prefix=/usr \ - --disable-rpath \ - --with-libcrypto \ - --without-ntfs-3g \ - --without-fuse \ - --disable-xattr -make %{?_smp_mflags} - -%check -make check - -%install -rm -rf %{buildroot} -make DESTDIR=%{buildroot} install - -%clean -rm -rf %{buildroot} - -%post -p /sbin/ldconfig -%postun -p /sbin/ldconfig - -%files -%defattr(-, root, root) -%doc AUTHORS COPYING README -%{_libdir}/libwim.so.* - -%files -n wimtools -%defattr(-, root, root) -%{_bindir}/wimlib-imagex -%{_bindir}/mkwinpeimg -%doc %{_mandir}/man1/*.1.gz - -%files devel -%defattr(-, root, root) -%{_libdir}/libwim.a -%{_libdir}/libwim.so -%exclude %{_libdir}/libwim.la -%{_includedir}/wimlib.h -%{_libdir}/pkgconfig/wimlib.pc diff --git a/rpm/wimlib.spec b/rpm/wimlib.spec deleted file mode 100644 index 7ea2f068..00000000 --- a/rpm/wimlib.spec +++ /dev/null @@ -1,80 +0,0 @@ -Summary: Library to extract, create, modify, and mount WIM files -Name: wimlib -Version: 1.5.0 -Release: 1 -License: GPLv3+ -Group: System/Libraries -URL: http://sourceforge.net/projects/wimlib -Packager: Eric Biggers -Source: http://downloads.sourceforge.net/wimlib/wimlib-%{version}.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root - -Requires: libxml2, fuse-libs, fuse, openssl -Requires: ntfs-3g >= 2:2011.4.12 -BuildRequires: libxml2-devel, fuse, fuse-devel, openssl-devel, libattr-devel -BuildRequires: ntfs-3g-devel >= 2:2011.4.12, ntfsprogs -%description -wimlib is a C library for creating, extracting, modifying, and mounting files in -the Windows Imaging Format (WIM files). It is similar to Microsoft's WIMGAPI -but is designed for both UNIX and Windows. - -%package devel -Summary: Development files for wimlib -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} -%description devel -Development files for wimlib - -%package -n wimtools -Summary: Tools to create, extract, modify, and mount WIM files -Group: Applications/System -Requires: %{name} = %{version}-%{release} -%description -n wimtools -Tools to create, extract, modify, 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 package contains a free implementation of ImageX called -"wimlib-imagex" that is designed to work on both UNIX and Windows. - -%prep -%setup -q -n %{name}-%{version} - -%build -%configure --prefix=/usr \ - --disable-rpath \ - --with-libcrypto \ - --with-ntfs-3g \ - --with-fuse \ - --enable-xattr -make %{?_smp_mflags} - -%check -make check - -%install -rm -rf %{buildroot} -make DESTDIR=%{buildroot} install - -%clean -rm -rf %{buildroot} - -%post -p /sbin/ldconfig -%postun -p /sbin/ldconfig - -%files -%defattr(-, root, root) -%doc AUTHORS COPYING README -%{_libdir}/libwim.so.* - -%files -n wimtools -%defattr(-, root, root) -%{_bindir}/wimlib-imagex -%{_bindir}/mkwinpeimg -%doc %{_mandir}/man1/*.1.gz - -%files devel -%defattr(-, root, root) -%{_libdir}/libwim.a -%{_libdir}/libwim.so -%exclude %{_libdir}/libwim.la -%{_includedir}/wimlib.h -%{_libdir}/pkgconfig/wimlib.pc diff --git a/rpm/wimtools.spec b/rpm/wimtools.spec new file mode 100644 index 00000000..d457f9a5 --- /dev/null +++ b/rpm/wimtools.spec @@ -0,0 +1,98 @@ +Summary: Library to extract, create, modify, and mount WIM files +Name: wimtools +Version: 1.5.0 +Release: 1 +License: GPLv3+ +URL: http://sourceforge.net/projects/wimlib +Packager: Eric Biggers +Source: http://downloads.sourceforge.net/wimlib/wimlib-%{version}.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root + +Requires: libxml2, libfuse2, fuse, openssl +Requires: ntfs-3g +BuildRequires: libxml2-devel, fuse, fuse-devel, openssl-devel, libattr-devel +BuildRequires: ntfs-3g-devel, ntfsprogs, libtool, pkg-config + +Summary: Tools to create, extract, modify, and mount WIM files +Group: Applications/System +Requires: libwim9 +%description +Tools to extract, create, modify, and mount WIM (Windows Imaging) files. WIM is +an archive format designed primarily for archiving Windows filesystems. It +features single-instancing and LZ77-based compression and is used by Microsoft +to distribute and deploy Windows Vista and later. WIM files are normally +created by using the `imagex.exe' utility on Windows, but this package contains +a free implementation of ImageX called "wimlib-imagex" that is designed to work +on both UNIX and Windows. + +In addition to the usual extract/create/update support, wimlib-imagex allows you +to mount WIM images readonly or read-write, and it even allows you to extract or +create a WIM image directly to/from an unmounted NTFS volume. This makes it +possible to, from Linux, back up or deploy a Windows OS directly to or from a +WIM file, such as the install.wim distributed on the Windows installation media. + +This package also contains a script to make a customized Windows PE image based +on the capabilities provided by wimlib-imagex. + +%package devel +Summary: Development files for wimlib +Group: System/Libraries +%description devel +Development files for wimlib + +%package -n libwim9 +Summary: Library to extract, create, modify, and mount WIM files +Group: Development/Libraries +%description -n libwim9 +wimlib is a C library for extracting, creating, modifying, and mounting WIM +(Windows Imaging) files. WIM is an archive format designed primarily for +archiving Windows filesystems. It features single-instancing and LZ77-based +compression, and is used by Microsoft to distribute and deploy Windows Vista and +later. wimlib is an independent implementation of an API for handling WIM +files, available on both UNIX and Windows, that provides features similar to +Microsoft's WIMGAPI, as well as additional features such as support for pipable +WIM files and programatically making changes to WIM images without mounting +them. +%post -n libwim9 -p /sbin/ldconfig +%postun -n libwim9 -p /sbin/ldconfig + +%prep +%setup -q -n wimlib-%{version} + +%build +autoreconf -i -f +%configure --prefix=/usr \ + --disable-rpath \ + --with-libcrypto \ + --with-ntfs-3g \ + --with-fuse \ + --enable-xattr +make %{?_smp_mflags} + +%install +rm -rf %{buildroot} +make DESTDIR=%{buildroot} install + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-, root, root) +%{_bindir}/* +%doc %{_mandir}/man1/*.1.gz +%doc %{_mandir}/man1/*.1 + +%files devel +%defattr(-, root, root) +%{_libdir}/libwim.a +%{_libdir}/libwim.so +%exclude %{_libdir}/libwim.la +%{_includedir}/wimlib.h +%{_libdir}/pkgconfig/wimlib.pc +%doc AUTHORS COPYING README + +%files -n libwim9 +%defattr(-, root, root) +%{_libdir}/libwim.so.* + diff --git a/src/extract.c b/src/extract.c index 092c8c40..b96367b6 100644 --- a/src/extract.c +++ b/src/extract.c @@ -1203,8 +1203,7 @@ extract_stream_list(struct apply_ctx *ctx) bool can_seek; int ret; - can_seek = !(lseek(ctx->wim->in_fd.fd, 0, SEEK_CUR) == (off_t)-1 && - errno == ESPIPE); + can_seek = (lseek(ctx->wim->in_fd.fd, 0, SEEK_CUR) != -1); list_for_each_entry(lte, &ctx->stream_list, extraction_list) { ret = extract_stream_instances(lte, ctx, can_seek); if (ret) @@ -2022,8 +2021,7 @@ extract_tree(WIMStruct *wim, const tchar *wim_source_path, const tchar *target, * output. In that case, "root" should be a single file, not a * directory tree. (If not, extract_dentry_to_stdout() will * return an error.) */ - if (extract_flags & WIMLIB_EXTRACT_FLAG_TO_STDOUT && - !(extract_flags & WIMLIB_EXTRACT_FLAG_FROM_PIPE)) { + if (extract_flags & WIMLIB_EXTRACT_FLAG_TO_STDOUT) { ret = extract_dentry_to_stdout(root); goto out_teardown_stream_list; } @@ -2276,8 +2274,7 @@ do_wimlib_extract_files(WIMStruct *wim, return ret; /* Make sure there are no streams in the WIM that have not been - * checksummed yet. Needed at least because 'unhashed_list' aliases - * 'extraction_list' in `struct wim_lookup_table_entry'. */ + * checksummed yet. */ ret = wim_checksum_unhashed_streams(wim); if (ret) return ret; @@ -2461,12 +2458,10 @@ extract_all_images(WIMStruct *wim, extract_flags |= WIMLIB_EXTRACT_FLAG_MULTI_IMAGE; -#ifdef WITH_NTFS_3G if (extract_flags & WIMLIB_EXTRACT_FLAG_NTFS) { ERROR("Cannot extract multiple images in NTFS extraction mode."); return WIMLIB_ERR_INVALID_PARAM; } -#endif if (tstat(target, &stbuf)) { if (errno == ENOENT) { diff --git a/src/mount_image.c b/src/mount_image.c index d54fd236..12b193e3 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -567,7 +567,8 @@ extract_resource_to_staging_dir(struct wim_inode *inode, /* Extract the stream to the staging file (possibly truncated) */ if (old_lte) { - struct filedes wimlib_fd = {.fd = fd}; + struct filedes wimlib_fd; + filedes_init(&wimlib_fd, fd); extract_size = min(wim_resource_size(old_lte), size); ret = extract_wim_resource_to_fd(old_lte, &wimlib_fd, extract_size); @@ -1667,9 +1668,12 @@ wimfs_getxattr(const char *path, const char *name, char *value, return -ERANGE; ret = read_full_resource_into_buf(lte, value); - if (ret) - return -errno; - + if (ret) { + if (errno) + return -errno; + else + return -EIO; + } return res_size; } #endif @@ -2192,7 +2196,7 @@ wimfs_truncate(const char *path, off_t size) if (lte == NULL && size == 0) return 0; - if (lte->resource_location == RESOURCE_IN_STAGING_FILE) { + if (lte != NULL && lte->resource_location == RESOURCE_IN_STAGING_FILE) { ret = truncate(lte->staging_file_name, size); if (ret) ret = -errno; diff --git a/src/ntfs-3g_apply.c b/src/ntfs-3g_apply.c index 39509fc1..b8aabe86 100644 --- a/src/ntfs-3g_apply.c +++ b/src/ntfs-3g_apply.c @@ -40,6 +40,12 @@ #include #include +#ifdef HAVE_ALLOCA_H +# include +#else +# include +#endif + #include "wimlib/apply.h" #include "wimlib/encoding.h" #include "wimlib/error.h" @@ -86,18 +92,13 @@ ntfs_3g_extract_wim_chunk(const void *buf, size_t len, void *_ctx) static ntfs_inode * ntfs_3g_open_parent_inode(const char *path, ntfs_volume *vol) { - char orig, *p; + char *p; ntfs_inode *dir_ni; - p = strchr(path, '\0'); - do { - p--; - } while (*p != '/'); - - orig = *p; + p = strrchr(path, '/'); *p = '\0'; dir_ni = ntfs_pathname_to_inode(vol, NULL, path); - *p = orig; + *p = '/'; return dir_ni; } @@ -177,7 +178,6 @@ ntfs_3g_create_hardlink(const char *oldpath, const char *newpath, &name_utf16le, &name_utf16le_nbytes); if (ret) goto out_close_dir_ni; - ret = 0; if (ntfs_link(ni, dir_ni, name_utf16le, name_utf16le_nbytes / 2)) ret = WIMLIB_ERR_NTFS_3G; @@ -196,7 +196,7 @@ out: * Extract a stream (default or alternate data) to an attribute of a NTFS file. */ static int -ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, +ntfs_3g_extract_stream(const char *path, const utf16lechar *raw_stream_name, size_t stream_name_nchars, struct wim_lookup_table_entry *lte, struct apply_ctx *ctx) { @@ -204,11 +204,16 @@ ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, ntfs_attr *na; int ret; struct ntfs_attr_extract_ctx extract_ctx; - utf16lechar stream_name_copy[stream_name_nchars + 1]; - - memcpy(stream_name_copy, stream_name, - stream_name_nchars * sizeof(utf16lechar)); - stream_name_copy[stream_name_nchars] = 0; + utf16lechar *stream_name; + + if (stream_name_nchars == 0) { + stream_name = AT_UNNAMED; + } else { + stream_name = alloca((stream_name_nchars + 1) * sizeof(utf16lechar)); + memcpy(stream_name, raw_stream_name, + stream_name_nchars * sizeof(utf16lechar)); + stream_name[stream_name_nchars] = 0; + } ret = 0; if (!stream_name_nchars && !lte) @@ -223,7 +228,7 @@ ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, /* Add the stream if it's not the default (unnamed) stream. */ ret = WIMLIB_ERR_NTFS_3G; if (stream_name_nchars) - if (ntfs_attr_add(ni, AT_DATA, stream_name_copy, + if (ntfs_attr_add(ni, AT_DATA, stream_name, stream_name_nchars, NULL, 0)) goto out_close; @@ -234,7 +239,7 @@ ntfs_3g_extract_stream(const char *path, const utf16lechar *stream_name, /* Open the stream (NTFS attribute). */ ret = WIMLIB_ERR_NTFS_3G; - na = ntfs_attr_open(ni, AT_DATA, stream_name_copy, stream_name_nchars); + na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_nchars); if (!na) goto out_close; diff --git a/src/resource.c b/src/resource.c index 03d6e0c4..bb3dda97 100644 --- a/src/resource.c +++ b/src/resource.c @@ -400,6 +400,7 @@ read_compressed_resource(const struct wim_lookup_table_entry *lte, uncompressed_buf, uncompressed_chunk_size); if (ret) { + ERROR("Failed to decompress data."); ret = WIMLIB_ERR_DECOMPRESSION; errno = EINVAL; goto out_free_chunk_offsets; @@ -412,6 +413,7 @@ read_compressed_resource(const struct wim_lookup_table_entry *lte, out_p, uncompressed_chunk_size); if (ret) { + ERROR("Failed to decompress data."); ret = WIMLIB_ERR_DECOMPRESSION; errno = EINVAL; goto out_free_chunk_offsets; @@ -618,10 +620,11 @@ invalid: * * Return values: * WIMLIB_ERR_SUCCESS (0) - * WIMLIB_ERR_READ (errno set) - * WIMLIB_ERR_NOMEM (errno set to ENOMEM) - * WIMLIB_ERR_DECOMPRESSION (errno set to EINVAL) - * WIMLIB_ERR_INVALID_PIPABLE_WIM (errno set to EINVAL) + * WIMLIB_ERR_READ (errno set) + * WIMLIB_ERR_UNEXPECTED_END_OF_FILE (errno set to 0) + * WIMLIB_ERR_NOMEM (errno set to ENOMEM) + * WIMLIB_ERR_DECOMPRESSION (errno set to EINVAL) + * WIMLIB_ERR_INVALID_PIPABLE_WIM (errno set to EINVAL) * * or other error code returned by the @cb function. */ diff --git a/src/unix_apply.c b/src/unix_apply.c index e27accff..fd5d972d 100644 --- a/src/unix_apply.c +++ b/src/unix_apply.c @@ -124,7 +124,7 @@ unix_set_unix_data(const tchar *path, const struct wimlib_unix_data *data, struct stat stbuf; if (lstat(path, &stbuf)) - return WIMLIB_ERR_STAT; + return WIMLIB_ERR_SET_SECURITY; if (!S_ISLNK(stbuf.st_mode)) if (chmod(path, data->mode)) return WIMLIB_ERR_SET_SECURITY; diff --git a/src/wim.c b/src/wim.c index ee28a581..bf382a64 100644 --- a/src/wim.c +++ b/src/wim.c @@ -869,10 +869,10 @@ wimlib_free(WIMStruct *wim) if (!wim) return; - if (wim->in_fd.fd != -1) - close(wim->in_fd.fd); - if (wim->out_fd.fd != -1) - close(wim->out_fd.fd); + if (filedes_valid(&wim->in_fd)) + filedes_close(&wim->in_fd); + if (filedes_valid(&wim->out_fd)) + filedes_close(&wim->out_fd); free_lookup_table(wim->lookup_table); diff --git a/tests/test-imagex b/tests/test-imagex index c523b12d..177cd2b3 100755 --- a/tests/test-imagex +++ b/tests/test-imagex @@ -429,7 +429,7 @@ if test "`imagex info new.wim | grep 'Image Count' | awk '{print $3}'`" != 2; th error "Exporting single image to existing WIM wasn't done correctly" fi echo "Testing export of single image to existing WIM using wrong compression type" -if imagex export dir.wim dir2 new.wim newname --compress=maximum; then +if imagex export dir.wim dir2 new.wim newname --compress=xpress; then error "Successfully exported image using wrong compression type" fi rm -f new.wim -- 2.43.0