- WIMLIB
+ WIMLIB
This is wimlib version 1.0.4 (October 2012). wimlib can be used to read,
write, and mount files in the Windows Imaging Format (WIM files). These
PROGRAMS
wimlib provides a public API for other programs to use, but also comes with two
-programs: `imagex' and `mkwinpeimg'.
+programs: `imagex' and `mkwinpeimg'.
`imagex' is intended to be like the imagex.exe program from Windows. `imagex'
can be used to create, extract, and mount WIM files. Both read-only and
Removes all error messages from the library. If left in, they still
have to explicitly turned on with wimlib_set_print_errors() in order to
see them. Also, error codes will still be returned regardless of
- whether error messages are printed or not.
+ whether error messages are printed or not.
If --disable-error-messages is given, wimlib_set_print_errors() will
fail with WIMLIB_ERR_UNSUPPORTED if the action is to turn error messages
have libntfs-3g 2011-4-12 or later available, you must 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').
+mqueuefs').
wimlib should work on big endian machines but it has not been tested.
There are no plans to port wimlib to Windows since the programming interface on
Windows is very different and Microsoft's imagex.exe is already available.
- REFERENCES
+ REFERENCES
The WIM file format is specified in a document that can be found in the
Microsoft Download Center. There is a similar document that specifies the LZX
lzx-decomp.c, the code to decompress WIM file resources that are compressed
using LZX compression, is originally based on code from the cabextract project
-(http://www.cabextract.org.uk).
+(http://www.cabextract.org.uk).
lzx-comp.c, the code to compress WIM file resources using LZX compression, is
originally based on code written by Matthew Russotto (www.russotto.net/chm/).
An earlier version of wimlib is being used to deploy Windows 7 from the Ultimate
Deployment Appliance. For more information see
-http://www.ultimatedeployment.org/.
+http://www.ultimatedeployment.org/.
-You can see the documentation about Microsoft's version of the imagex program at
+You can see the documentation about Microsoft's version of the imagex program at
http://technet.microsoft.com/en-us/library/cc749447(v=ws.10).aspx, so you can
see how it compares.
wimlib is independently developed and does not contain any code, data, or files
copyrighted by Microsoft. It is not known to be affected by any patents.
- DISCLAIMER
+ DISCLAIMER
wimlib is experimental. Use Microsoft's `imagex.exe' if you want to make sure
your WIM files are made correctly (but beware: Microsoft's version contains some
-bugs).
+bugs).
Please submit a bug report (to ebiggers3@gmail.com) if you find a bug in wimlib.
license=("GPL3")
depends=("openssl" "fuse" "libxml2" "ntfs-3g" "attr")
optdepends=("cdrkit: for making ISO image of Windows PE"
- "mtools: for making disk image of Windows PE"
- "syslinux: for making disk image of Windows PE"
+ "mtools: for making disk image of Windows PE"
+ "syslinux: for making disk image of Windows PE"
"cabextract: for extracting Windows PE from the WAIK"
"ntfsprogs: for making NTFS filesystems")
checkdepends=("ntfsprogs")
}
check() {
- cd "$pkgname-$pkgver"
+ cd "$pkgname-$pkgver"
make check
}
package() {
- cd "$pkgname-$pkgver"
+ cd "$pkgname-$pkgver"
make DESTDIR="$pkgdir" install
}
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT
AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_FILES([Makefile
+AC_CONFIG_FILES([Makefile
doc/Doxyfile
wimlib.pc
doc/imagex.1
AC_SUBST([LIBXML2_CFLAGS], [$LIBXML2_CFLAGS])
AC_MSG_CHECKING([whether to include debugging messages])
-AC_ARG_ENABLE([debug],
+AC_ARG_ENABLE([debug],
AS_HELP_STRING([--enable-debug], [include lots of debugging messages]),
[ENABLE_DEBUG=$enableval],
[ENABLE_DEBUG=no]
)
AC_MSG_RESULT([$ENABLE_DEBUG])
if test "x$ENABLE_DEBUG" = "xyes"; then
- AC_DEFINE([ENABLE_DEBUG], [1],
+ AC_DEFINE([ENABLE_DEBUG], [1],
[Define to 1 if including lots of debug messages.])
fi
AC_MSG_CHECKING([whether to include more debugging messages])
-AC_ARG_ENABLE([more_debug],
- AS_HELP_STRING([--enable-more-debug],
+AC_ARG_ENABLE([more_debug],
+ AS_HELP_STRING([--enable-more-debug],
[include even more debugging messages]),
[ENABLE_MORE_DEBUG=$enableval],
[ENABLE_MORE_DEBUG=no]
)
AC_MSG_RESULT([$ENABLE_MORE_DEBUG])
if test "x$ENABLE_MORE_DEBUG" = "xyes"; then
- AC_DEFINE([ENABLE_MORE_DEBUG], [1],
+ AC_DEFINE([ENABLE_MORE_DEBUG], [1],
[Define to 1 if including even more debug messages.])
fi
AC_MSG_CHECKING([whether to include error messages])
-AC_ARG_ENABLE([error_messages],
- AS_HELP_STRING([--disable-error-messages],
+AC_ARG_ENABLE([error_messages],
+ AS_HELP_STRING([--disable-error-messages],
[do not compile in error messsages]),
[ENABLE_ERROR_MESSAGES=$enableval],
[ENABLE_ERROR_MESSAGES=yes]
)
AC_MSG_RESULT([$ENABLE_ERROR_MESSAGES])
if test "x$ENABLE_ERROR_MESSAGES" = "xyes"; then
- AC_DEFINE([ENABLE_ERROR_MESSAGES], [1],
+ AC_DEFINE([ENABLE_ERROR_MESSAGES], [1],
[Define to 1 if including error messages])
fi
AC_MSG_CHECKING([whether to support custom memory allocation functions])
-AC_ARG_ENABLE([custom_memory_allocator],
- AS_HELP_STRING([--disable-custom-memory-allocator],
+AC_ARG_ENABLE([custom_memory_allocator],
+ AS_HELP_STRING([--disable-custom-memory-allocator],
[do not support the use of custom memory allocation
functions]),
[ENABLE_CUSTOM_MEMORY_ALLOCATOR=$enableval],
)
AC_MSG_RESULT([$ENABLE_CUSTOM_MEMORY_ALLOCATOR])
if test "x$ENABLE_CUSTOM_MEMORY_ALLOCATOR" = "xyes"; then
- AC_DEFINE([ENABLE_CUSTOM_MEMORY_ALLOCATOR], [1],
+ AC_DEFINE([ENABLE_CUSTOM_MEMORY_ALLOCATOR], [1],
[Define to 1 if supporting custom memory allocation functions])
fi
AC_CHECK_LIB([ntfs-3g], [ntfs_mount], [],
[AC_MSG_ERROR([Cannot find libntfs-3g.
- Without libntfs-3g, wimlib cannot include support for capturing and
+ Without libntfs-3g, wimlib cannot include support for capturing and
applying WIMs on NTFS filesystems while preserving NTFS-specific data
such as security descriptors and alternate data streams. You should
either install libntfs-3g, or configure with --without-ntfs-3g to
AC_MSG_CHECKING([whether to include support for mounting WIMs])
AC_ARG_WITH([fuse],
- AS_HELP_STRING([--without-fuse], [build without libfuse.
- This will disable the ability to mount
+ AS_HELP_STRING([--without-fuse], [build without libfuse.
+ This will disable the ability to mount
WIM files.]),
[WITH_FUSE=$withval],
[WITH_FUSE=yes]
AC_CHECK_LIB([fuse], [fuse_main_real], [have_fuse=true],
- [AC_MSG_ERROR([Cannot find libfuse.
+ [AC_MSG_ERROR([Cannot find libfuse.
Without libfuse, wimlib cannot include support for mounting WIMs. You
should either install libfuse, or configure with --without-fuse to
disable support for mounting WIMs.])
[ENABLE_SSSE3_SHA1=$enableval],
[ENABLE_SSSE3_SHA1=no]
)
-
+
AC_MSG_RESULT([$ENABLE_SSSE3_SHA1])
if test "x$ENABLE_SSSE3_SHA1" = "xyes"; then
- AC_DEFINE([ENABLE_SSSE3_SHA1], [1],
+ AC_DEFINE([ENABLE_SSSE3_SHA1], [1],
[Define to 1 if using vectorized implementation of SHA1])
SSSE3_SHA1_OBJ=sha1-ssse3.lo
AX_PROG_NASM
rather than use external libcrypto from
OpenSSL (default is autodetect)]),
[WITH_LIBCRYPTO=$withval],
- [AC_CHECK_LIB([crypto], [SHA1],
+ [AC_CHECK_LIB([crypto], [SHA1],
[WITH_LIBCRYPTO=yes],
[AC_MSG_WARN([Cannot find libcrypto: using stand-alone SHA1 code instead of OpenSSL])
WITH_LIBCRYPTO=no
You should have received a copy of the GNU General Public License along with
this library; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place, Suite 330, Boston, MA 02111-1307 USA
+ Place, Suite 330, Boston, MA 02111-1307 USA
Files: debian/*
Copyright: 2012 Eric Biggers <ebiggers3@gmail.com>
export DH_VERBOSE=1
%:
- dh $@
+ dh $@
static void usage_all();
static const char *usage_strings[] = {
-[APPEND] =
+[APPEND] =
" imagex append (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n"
" [DESCRIPTION] [--boot] [--check] [--flags EDITION_ID]\n"
" [--verbose] [--dereference] [--config=FILE]\n",
-[APPLY] =
+[APPLY] =
" imagex apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all]\n"
" (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n"
" [--symlink] [--verbose] [--ref=\"GLOB\"]\n",
-[CAPTURE] =
+[CAPTURE] =
" imagex capture (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n"
" [DESCRIPTION] [--boot] [--check] [--compress=TYPE]\n"
" [--flags EDITION_ID] [--verbose] [--dereference]\n"
" [--config=FILE]\n",
-[DELETE] =
+[DELETE] =
" imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n",
-[DIR] =
+[DIR] =
" imagex dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all)\n",
-[EXPORT] =
+[EXPORT] =
" imagex export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
" DEST_WIMFILE [DEST_IMAGE_NAME]\n"
" [DEST_IMAGE_DESCRIPTION] [--boot] [--check]\n"
" [--compress=TYPE] [--ref=\"GLOB\"]\n",
-[INFO] =
+[INFO] =
" imagex info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n"
" [NEW_DESC] [--boot] [--check] [--header] [--lookup-table]\n"
" [--xml] [--extract-xml FILE] [--metadata]\n",
-[JOIN] =
+[JOIN] =
" imagex join [--check] WIMFILE SPLIT_WIM...\n",
-[MOUNT] =
+[MOUNT] =
" imagex mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
" [--check] [--debug] [--streams-interface=INTERFACE]\n"
" [--ref=\"GLOB\"]\n",
-[MOUNTRW] =
+[MOUNTRW] =
" imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
" [--check] [--debug] [--streams-interface=INTERFACE]\n",
-[SPLIT] =
+[SPLIT] =
" imagex split WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n",
-[UNMOUNT] =
+[UNMOUNT] =
" imagex unmount DIRECTORY [--commit] [--check]\n",
};
if (ret != 0)
return ret;
- /* Determine if the destination is an existing file or not.
+ /* Determine if the destination is an existing file or not.
* If so, we try to append the exported image(s) to it; otherwise, we
* create a new WIM containing the exported image(s). */
if (stat(dest_wimfile, &stbuf) == 0) {
if (ret != 0)
goto out;
- if (compression_type_specified && compression_type !=
+ if (compression_type_specified && compression_type !=
wimlib_get_compression_type(dest_w)) {
imagex_error("Cannot specify a compression type that is "
"not the same as that used in the "
goto out;
}
- ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
+ ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
export_flags, additional_swms,
num_additional_swms);
if (ret != 0)
if (wim_is_new)
- ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
+ ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
write_flags);
else
ret = wimlib_overwrite(dest_w, write_flags);
FILE *fp;
int image;
int ret;
- int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
+ int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
WIMLIB_OPEN_FLAG_SPLIT_OK;
int part_number;
int total_parts;
new_name = argv[2];
if (argc > 3) {
new_desc = argv[3];
- }
+ }
}
}
image = wimlib_resolve_image(w, image_num_or_name);
if (image == WIM_NO_IMAGE && strcmp(image_num_or_name, "0") != 0) {
- imagex_error("The image `%s' does not exist",
+ imagex_error("The image `%s' does not exist",
image_num_or_name);
if (boot)
imagex_error("If you would like to set the boot "
}
}
if (new_name) {
- if (strcmp(wimlib_get_image_name(w, image),
+ if (strcmp(wimlib_get_image_name(w, image),
new_name) == 0) {
printf("Image %d is already named \"%s\".\n",
image, new_name);
} else {
printf("Changing the description of image %d "
"to \"%s\".\n", image, new_desc);
- ret = wimlib_set_image_descripton(w, image,
+ ret = wimlib_set_image_descripton(w, image,
new_desc);
if (ret != 0)
goto done;
/* Only call wimlib_overwrite_xml_and_header() if something
* actually needs to be changed. */
- if (boot || new_name || new_desc ||
+ if (boot || new_name || new_desc ||
check != wimlib_has_integrity_table(w)) {
- ret = wimlib_overwrite_xml_and_header(w, check ?
- WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
+ ret = wimlib_overwrite_xml_and_header(w, check ?
+ WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
WIMLIB_WRITE_FLAG_SHOW_PROGRESS : 0);
} else {
printf("The file `%s' was not modified because nothing "
if (num_images != 1) {
imagex_error("The file `%s' contains %d images; Please "
"select one", wimfile, num_images);
- usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
+ usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
? MOUNTRW : MOUNT);
ret = WIMLIB_ERR_INVALID_IMAGE;
goto out;
wimlib_free(additional_swms[i]);
return ret;
mount_usage:
- usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
+ usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
? MOUNTRW : MOUNT);
return -1;
}
static void version()
{
- static const char *s =
+ static const char *s =
"imagex (" PACKAGE ") " PACKAGE_VERSION "\n"
"Copyright (C) 2012 Eric Biggers\n"
"License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
puts("IMAGEX: Usage:");
for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
fputs(usage_strings[i], stdout);
- static const char *extra =
+ static const char *extra =
" imagex --help\n"
" imagex --version\n"
"\n"
* including the stream length field (see below). */
#define WIM_ADS_ENTRY_DISK_SIZE 38
-/*
- * Reparse tags documented at
+/*
+ * Reparse tags documented at
* http://msdn.microsoft.com/en-us/library/dd541667(v=prot.10).aspx
*/
#define WIM_IO_REPARSE_TAG_RESERVED_ZERO 0x00000000
entry_1->stream_name_len) == 0;
}
-/*
+/*
* In-memory structure for a WIM directory entry (dentry). There is a directory
- * tree for each image in the WIM.
+ * tree for each image in the WIM.
*
* Note that this is a directory entry and not an inode. Since NTFS allows hard
* links, it's possible for a NTFS inode to correspond to multiple WIM dentries.
struct dentry *next;
struct dentry *prev;
- /*
+ /*
* Size of directory entry on disk, in bytes. Typical size is around
* 104 to 120 bytes.
*
int32_t security_id;
/* %true iff the inode's lookup table entries has been resolved (i.e.
- * the @lte field is valid, but the @hash field is not valid)
+ * the @lte field is valid, but the @hash field is not valid)
*
* (This is not an on-disk field.) */
u8 resolved : 1;
extern int inode_to_stbuf(const struct inode *inode,
struct lookup_table_entry *lte, struct stat *stbuf);
-extern int for_dentry_in_tree(struct dentry *root,
- int (*visitor)(struct dentry*, void*),
+extern int for_dentry_in_tree(struct dentry *root,
+ int (*visitor)(struct dentry*, void*),
void *args);
-extern int for_dentry_in_tree_depth(struct dentry *root,
- int (*visitor)(struct dentry*, void*),
+extern int for_dentry_in_tree_depth(struct dentry *root,
+ int (*visitor)(struct dentry*, void*),
void *args);
extern int calculate_dentry_full_path(struct dentry *dentry, void *ignore);
extern struct dentry *get_dentry(struct WIMStruct *w, const char *path);
extern struct inode *wim_pathname_to_inode(struct WIMStruct *w,
const char *path);
-extern struct dentry *get_dentry_child_with_name(const struct dentry *dentry,
+extern struct dentry *get_dentry_child_with_name(const struct dentry *dentry,
const char *name);
extern struct dentry *get_parent_dentry(struct WIMStruct *w, const char *path);
extern void inode_remove_ads(struct inode *inode, u16 idx,
struct lookup_table *lookup_table);
-extern int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len,
+extern int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len,
u64 offset, struct dentry *dentry);
-extern int read_dentry_tree(const u8 metadata_resource[],
+extern int read_dentry_tree(const u8 metadata_resource[],
u64 metadata_resource_len, struct dentry *dentry);
extern u8 *write_dentry_tree(const struct dentry *tree, u8 *p);
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
return __builtin_bswap32(n);
#else
- return (n << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) |
+ return (n << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) |
(n >> 24);
#endif
}
#ifdef __GNUC__
return __builtin_bswap64(n);
#else
- return (n << 56) | ((n & 0xff00) << 40) | ((n & 0xff0000) << 24) |
- ((n & 0xff000000) << 8) | ((n & 0xff00000000) >> 8) |
- ((n & 0xff0000000000) >> 24) |
+ return (n << 56) | ((n & 0xff00) << 40) | ((n & 0xff0000) << 24) |
+ ((n & 0xff000000) << 8) | ((n & 0xff00000000) >> 8) |
+ ((n & 0xff0000000000) >> 24) |
((n & 0xff000000000000) >> 40) | (n >> 56);
#endif
}
/* Internal */
#define WIMLIB_EXTRACT_FLAG_MULTI_IMAGE 0x80000000
-static int extract_regular_file_linked(const struct dentry *dentry,
+static int extract_regular_file_linked(const struct dentry *dentry,
const char *output_dir,
const char *output_path,
int extract_flags,
wimlib_assert(extract_flags & WIMLIB_EXTRACT_FLAG_SYMLINK);
- num_path_components =
+ num_path_components =
get_num_path_components(dentry->full_path_utf8) - 1;
num_output_dir_path_components =
get_num_path_components(output_dir);
}
static int extract_regular_file_unlinked(WIMStruct *w,
- struct dentry *dentry,
+ struct dentry *dentry,
const char *output_path,
int extract_flags,
struct lookup_table_entry *lte)
return ret;
}
-/*
- * Extracts a regular file from the WIM archive.
+/*
+ * Extracts a regular file from the WIM archive.
*/
-static int extract_regular_file(WIMStruct *w,
- struct dentry *dentry,
+static int extract_regular_file(WIMStruct *w,
+ struct dentry *dentry,
const char *output_dir,
const char *output_path,
int extract_flags)
return 0;
}
-/*
- * Extracts a directory from the WIM archive.
+/*
+ * Extracts a directory from the WIM archive.
*
* @dentry: The directory entry for the directory.
* @output_path: The path to which the directory is to be extracted to.
- * @return: True on success, false on failure.
+ * @return: True on success, false on failure.
*/
static int extract_directory(const char *output_path, bool is_root)
{
const char *output_dir;
};
-/*
+/*
* Extracts a file, directory, or symbolic link from the WIM archive. For use
* in for_dentry_in_tree().
*/
memcpy(buf, output_dir, output_path_len);
buf[output_path_len] = '/';
for (image = 1; image <= w->hdr.image_count; image++) {
-
+
image_name = wimlib_get_image_name(w, image);
if (*image_name) {
strcpy(buf + output_path_len + 1, image_name);
/* NULL NULL
* ^ ^
- * dentry | |
- * / \ ----------- -----------
+ * dentry | |
+ * / \ ----------- -----------
* | dentry<---| struct | | struct |---> dentry
- * \ / | inode | | inode |
+ * \ / | inode | | inode |
* dentry ------------ ------------
* ^ ^
* | |
* ^ ^
* | |
* -----------------
- * inode_table->array | idx 0 | idx 1 |
+ * inode_table->array | idx 0 | idx 1 |
* -----------------
*/
return size;
}
-/*
+/*
* Insert a dentry into the inode table based on its inode
* ID.
*
return 0;
}
-/*
+/*
* Fixes up a nominal inode.
*
* By a nominal inode we mean a group of two or more dentries that share
#include "io.h"
/* First 8 bytes in every WIM file. */
-static const u8 wim_magic_chars[WIM_MAGIC_LEN] = {
+static const u8 wim_magic_chars[WIM_MAGIC_LEN] = {
'M', 'S', 'W', 'I', 'M', '\0', '\0', '\0' };
/* Reads the header for a WIM file. */
u32 chunk_size;
DEBUG("Reading WIM header.");
-
+
bytes_read = fread(buf, 1, WIM_MAGIC_LEN, fp);
if (bytes_read != WIM_MAGIC_LEN)
hdr_rem_size = WIM_HEADER_DISK_SIZE - WIM_MAGIC_LEN - sizeof(u32);
- bytes_read = fread(buf + WIM_MAGIC_LEN + sizeof(u32), 1,
+ bytes_read = fread(buf + WIM_MAGIC_LEN + sizeof(u32), 1,
hdr_rem_size, fp);
if (bytes_read != hdr_rem_size)
goto err;
p = get_u32(p, &hdr->flags);
p = get_u32(p, &chunk_size);
- if (chunk_size != WIM_CHUNK_SIZE &&
+ if (chunk_size != WIM_CHUNK_SIZE &&
(hdr->flags & WIM_HDR_FLAG_COMPRESSION)) {
ERROR("Unexpected chunk size of %u! Ask the author to "
"implement support for other chunk sizes.",
return WIMLIB_ERR_READ;
}
-/*
+/*
* Writes the header for a WIM file.
*
* @hdr: A pointer to a struct wim_header structure that describes the header.
p = put_u32(p, WIM_HEADER_DISK_SIZE);
p = put_u32(p, WIM_VERSION);
p = put_u32(p, hdr->flags);
- p = put_u32(p, (hdr->flags & WIM_HDR_FLAG_COMPRESSION) ?
+ p = put_u32(p, (hdr->flags & WIM_HDR_FLAG_COMPRESSION) ?
WIM_CHUNK_SIZE : 0);
/* byte 24 */
hdr->flags = 0;
break;
case WIM_COMPRESSION_TYPE_LZX:
- hdr->flags = WIM_HDR_FLAG_COMPRESSION |
+ hdr->flags = WIM_HDR_FLAG_COMPRESSION |
WIM_HDR_FLAG_COMPRESS_LZX;
break;
case WIM_COMPRESSION_TYPE_XPRESS:
- hdr->flags = WIM_HDR_FLAG_COMPRESSION |
+ hdr->flags = WIM_HDR_FLAG_COMPRESSION |
WIM_HDR_FLAG_COMPRESS_XPRESS;
break;
default:
printf("Part Number = %hu\n", w->hdr.part_number);
printf("Total Parts = %hu\n", w->hdr.total_parts);
printf("Image Count = %u\n", hdr->image_count);
- printf("Lookup Table Size = %"PRIu64"\n",
+ printf("Lookup Table Size = %"PRIu64"\n",
(u64)hdr->lookup_table_res_entry.size);
- printf("Lookup Table Flags = 0x%hhx\n",
+ printf("Lookup Table Flags = 0x%hhx\n",
hdr->lookup_table_res_entry.flags);
printf("Lookup Table Offset = %"PRIu64"\n",
hdr->lookup_table_res_entry.offset);
- printf("Lookup Table Original_size = %"PRIu64"\n",
+ printf("Lookup Table Original_size = %"PRIu64"\n",
hdr->lookup_table_res_entry.original_size);
- printf("XML Data Size = %"PRIu64"\n",
+ printf("XML Data Size = %"PRIu64"\n",
(u64)hdr->xml_res_entry.size);
- printf("XML Data Flags = 0x%hhx\n",
+ printf("XML Data Flags = 0x%hhx\n",
hdr->xml_res_entry.flags);
- printf("XML Data Offset = %"PRIu64"\n",
+ printf("XML Data Offset = %"PRIu64"\n",
hdr->xml_res_entry.offset);
- printf("XML Data Original Size = %"PRIu64"\n",
+ printf("XML Data Original Size = %"PRIu64"\n",
hdr->xml_res_entry.original_size);
- printf("Boot Metadata Size = %"PRIu64"\n",
+ printf("Boot Metadata Size = %"PRIu64"\n",
(u64)hdr->boot_metadata_res_entry.size);
- printf("Boot Metadata Flags = 0x%hhx\n",
+ printf("Boot Metadata Flags = 0x%hhx\n",
hdr->boot_metadata_res_entry.flags);
- printf("Boot Metadata Offset = %"PRIu64"\n",
+ printf("Boot Metadata Offset = %"PRIu64"\n",
hdr->boot_metadata_res_entry.offset);
- printf("Boot Metadata Original Size = %"PRIu64"\n",
+ printf("Boot Metadata Original Size = %"PRIu64"\n",
hdr->boot_metadata_res_entry.original_size);
printf("Boot Index = %u\n", hdr->boot_idx);
- printf("Integrity Size = %"PRIu64"\n",
+ printf("Integrity Size = %"PRIu64"\n",
(u64)hdr->integrity.size);
- printf("Integrity Flags = 0x%hhx\n",
+ printf("Integrity Flags = 0x%hhx\n",
hdr->integrity.flags);
- printf("Integrity Offset = %"PRIu64"\n",
+ printf("Integrity Offset = %"PRIu64"\n",
hdr->integrity.offset);
- printf("Integrity Original_size = %"PRIu64"\n",
+ printf("Integrity Original_size = %"PRIu64"\n",
hdr->integrity.original_size);
}
#define INTEGRITY_CHUNK_SIZE 10485760
/*
- * Verifies the integrity of a WIM.
+ * Verifies the integrity of a WIM.
*
- * @fp: FILE* of the WIM, currently positioned at the end of the header.
+ * @fp: FILE* of the WIM, currently positioned at the end of the header.
* @num_bytes: Number of bytes to verify the integrity of.
* @chunk_size: Chunk size per SHA1 message digest.
* @sha1sums: Array of SHA1 message digests; 20 bytes each, one per chunk.
* @show_progress: Nonzero if the percent complete is to be printed after every
* chunk.
- * @status: On success, set to WIM_INTEGRITY_OK or WIM_INTEGRITY_NOT_OK
+ * @status: On success, set to WIM_INTEGRITY_OK or WIM_INTEGRITY_NOT_OK
* based on whether the WIM is intact or not.
*/
-static int verify_integrity(FILE *fp, u64 num_bytes, u32 chunk_size,
+static int verify_integrity(FILE *fp, u64 num_bytes, u32 chunk_size,
const u8 *sha1sums, int show_progress,
int *status)
{
bytes_remaining = num_bytes;
while (bytes_remaining != 0) {
if (show_progress) {
- percent_done = (num_bytes - bytes_remaining) * 100 /
+ percent_done = (num_bytes - bytes_remaining) * 100 /
num_bytes;
printf("Verifying integrity of WIM (%"PRIu64" bytes "
- "remaining, %u%% done) \r",
+ "remaining, %u%% done) \r",
bytes_remaining, percent_done);
fflush(stdout);
}
}
/*
- * Verifies the integrity of the WIM.
+ * Verifies the integrity of the WIM.
*
* @show_progress: Nonzero if the percent complete is to be printed after every
* chunk.
if (integrity_table_size != expected_size) {
ERROR("Integrity table is %u bytes, but expected %"PRIu64" "
- "bytes to hold %u entries",
+ "bytes to hold %u entries",
integrity_table_size, expected_size, num_entries);
ret = WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
goto out;
}
/* call verify_integrity(), which does the actual checking of the SHA1
* message digests. */
- ret = verify_integrity(w->fp, bytes_to_check, chunk_size, p,
+ ret = verify_integrity(w->fp, bytes_to_check, chunk_size, p,
show_progress, status);
out:
FREE(buf);
return ret;
}
-/*
+/*
* Writes integrity information to the output stream for a WIM file being
- * written.
+ * written.
*
* @end_header_offset is the offset of the byte after the header, which is the
* beginning of the region that is checksummed.
*
* @end_lookup_table_offset is the offset of the byte after the lookup table,
- * which is the end of the region that is checksummed.
+ * which is the end of the region that is checksummed.
*/
-int write_integrity_table(FILE *out, u64 end_header_offset,
+int write_integrity_table(FILE *out, u64 end_header_offset,
u64 end_lookup_table_offset, int show_progress)
{
u64 bytes_to_check;
while (bytes_remaining != 0) {
- uint percent_done = (bytes_to_check - bytes_remaining) *
+ uint percent_done = (bytes_to_check - bytes_remaining) *
100 / bytes_to_check;
if (show_progress) {
printf("Calculating integrity checksums for WIM "
"(%"PRIu64" bytes remaining, %u%% "
- "done) \r",
+ "done) \r",
bytes_remaining, percent_done);
fflush(stdout);
}
for (unsigned i = 0; i < num_additional_swms; i++) {
if (additional_swms[i]->hdr.total_parts != total_parts) {
ERROR("WIM `%s' says there are %u parts in the spanned set, "
- "but %u parts were provided",
+ "but %u parts were provided",
additional_swms[i]->filename,
additional_swms[i]->hdr.total_parts,
total_parts);
}
if (swm->hdr.part_number == 1) {
ERROR("WIMs `%s' and `%s' both are marked as the "
- "first WIM in the spanned set",
+ "first WIM in the spanned set",
w->filename, swm->filename);
return WIMLIB_ERR_SPLIT_INVALID;
}
return 0;
}
-/*
+/*
* Joins lookup tables from the parts of a split WIM.
*
* @w specifies the first part, while @additional_swms and @num_additional_swms
}
swms[i]->out_fp = out_fp;
swms[i]->hdr.part_number = 1;
- ret = for_lookup_table_entry(swms[i]->lookup_table,
+ ret = for_lookup_table_entry(swms[i]->lookup_table,
copy_resource, swms[i]);
if (ret != 0)
return ret;
}
swms[0]->write_metadata = true;
if (write_flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS)
- printf("Writing %d metadata resources\n",
+ printf("Writing %d metadata resources\n",
swms[0]->hdr.image_count);
for (i = 0; i < swms[0]->hdr.image_count; i++) {
- ret = copy_resource(swms[0]->image_metadata[i].metadata_lte,
+ ret = copy_resource(swms[0]->image_metadata[i].metadata_lte,
swms[0]);
if (ret != 0)
return ret;
return WIMLIB_ERR_WRITE;
}
swms[0]->hdr.lookup_table_res_entry.offset = lookup_table_offset;
- swms[0]->hdr.lookup_table_res_entry.size =
+ swms[0]->hdr.lookup_table_res_entry.size =
xml_data_offset - lookup_table_offset;
}
-WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms,
+WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms,
const char *output_path, int flags)
{
int i;
ZERO_ARRAY(swms);
for (i = 0; i < num_swms; i++) {
- ret = wimlib_open_wim(swm_names[i],
+ ret = wimlib_open_wim(swm_names[i],
flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &swms[i]);
if (ret != 0)
goto out;
struct lookup_table_entry *new_lookup_table_entry()
{
struct lookup_table_entry *lte;
-
+
lte = CALLOC(1, sizeof(struct lookup_table_entry));
if (lte) {
lte->part_number = 1;
* @table: A pointer to the lookup table.
* @entry: A pointer to the entry to insert.
*/
-void lookup_table_insert(struct lookup_table *table,
+void lookup_table_insert(struct lookup_table *table,
struct lookup_table_entry *lte)
{
size_t i = lte->hash_short % table->capacity;
}
#endif
-/*
+/*
* Calls a function on all the entries in the lookup table. Stop early and
* return nonzero if any call to the function returns nonzero.
*/
-int for_lookup_table_entry(struct lookup_table *table,
+int for_lookup_table_entry(struct lookup_table *table,
int (*visitor)(struct lookup_table_entry *, void *),
void *arg)
{
}
cur_entry->wim = w;
cur_entry->resource_location = RESOURCE_IN_WIM;
-
+
p = get_resource_entry(buf, &cur_entry->resource_entry);
p = get_u16(p, &cur_entry->part_number);
p = get_u32(p, &cur_entry->refcnt);
}
-/*
+/*
* Writes a lookup table entry to the output file.
*/
int write_lookup_table_entry(struct lookup_table_entry *lte, void *__out)
putchar('\n');
return;
}
- printf("Offset = %"PRIu64" bytes\n",
+ printf("Offset = %"PRIu64" bytes\n",
lte->resource_entry.offset);
- printf("Size = %"PRIu64" bytes\n",
+ printf("Size = %"PRIu64" bytes\n",
(u64)lte->resource_entry.size);
- printf("Original size = %"PRIu64" bytes\n",
+ printf("Original size = %"PRIu64" bytes\n",
lte->resource_entry.original_size);
printf("Part Number = %hu\n", lte->part_number);
printf("Reference Count = %u\n", lte->refcnt);
}
/*
- * Prints the lookup table of a WIM file.
+ * Prints the lookup table of a WIM file.
*/
WIMLIBAPI void wimlib_print_lookup_table(WIMStruct *w)
{
- for_lookup_table_entry(w->lookup_table,
+ for_lookup_table_entry(w->lookup_table,
do_print_lookup_table_entry,
NULL);
}
-/*
+/*
* Looks up an entry in the lookup table.
*/
struct lookup_table_entry *
}
#ifdef WITH_FUSE
-/*
+/*
* Finds the dentry, lookup table entry, and stream index for a WIM file stream,
* given a path name.
*
inode->resolved = false;
}
-/* Resolve a dentry's lookup table entries
+/* Resolve a dentry's lookup table entries
*
* This replaces the SHA1 hash fields (which are used to lookup an entry in the
* lookup table) with pointers directly to the lookup table entries. A circular
};
#endif
-/*
- * An entry in the lookup table in the WIM file.
+/*
+ * An entry in the lookup table in the WIM file.
*
- * It is used to find data streams for files in the WIM.
+ * It is used to find data streams for files in the WIM.
*
* Metadata resources and reparse point data buffers will also have lookup table
* entries associated with the data.
*
* The lookup_table_entry for a given dentry or alternate stream entry in the
- * WIM is found using the SHA1 message digest field.
+ * WIM is found using the SHA1 message digest field.
*/
struct lookup_table_entry {
extern struct lookup_table *new_lookup_table(size_t capacity);
-extern void lookup_table_insert(struct lookup_table *table,
+extern void lookup_table_insert(struct lookup_table *table,
struct lookup_table_entry *lte);
/* Unlinks a lookup table entry from the table; does not free it. */
-static inline void lookup_table_unlink(struct lookup_table *table,
+static inline void lookup_table_unlink(struct lookup_table *table,
struct lookup_table_entry *lte)
{
hlist_del(<e->hash_list);
extern struct lookup_table_entry *
clone_lookup_table_entry(const struct lookup_table_entry *lte);
-extern int for_lookup_table_entry(struct lookup_table *table,
- int (*visitor)(struct lookup_table_entry *, void *),
+extern int for_lookup_table_entry(struct lookup_table *table,
+ int (*visitor)(struct lookup_table_entry *, void *),
void *arg);
extern struct lookup_table_entry *
}
/* Unlinks and frees an entry from a lookup table. */
-static inline void lookup_table_remove(struct lookup_table *table,
+static inline void lookup_table_remove(struct lookup_table *table,
struct lookup_table_entry *lte)
{
lookup_table_unlink(table, lte);
inode->ads_entries[
stream_idx - 1].hash);
}
-/*
+/*
* Returns the lookup table entry for stream @stream_idx of the inode, where
* stream_idx = 0 means the default un-named file stream, and stream_idx >= 1
* corresponds to an alternate data stream.
return zero_hash;
}
-/*
+/*
* Returns the hash for stream @stream_idx of the inode, where stream_idx = 0
* means the default un-named file stream, and stream_idx >= 1 corresponds to an
* alternate data stream.
* to walk through the hash chain, until the special index `0' is reached,
* indicating the end of the hash chain.
*/
-static inline uint insert_string(u16 hash_tab[], u16 prev_tab[],
+static inline uint insert_string(u16 hash_tab[], u16 prev_tab[],
const u8 window[], uint str_pos, uint hash)
{
hash = update_hash(hash, window[str_pos + LZ_MIN_MATCH - 1]);
* @strstart: The index of the start of the string in the window that
* we are trying to find a match for.
* @prev_tab: The array of prev pointers for the hash table.
- * @cur_match: The index of the head of the hash chain for matches
- * having the hash value of the string beginning
+ * @cur_match: The index of the head of the hash chain for matches
+ * having the hash value of the string beginning
* at index @strstart.
- * @prev_len: The length of the match that was found for the string
+ * @prev_len: The length of the match that was found for the string
* beginning at (@strstart - 1).
* @match_start_ret: A location into which the index of the start of the
* match will be returned.
* Returns the length of the match that was found.
*/
static uint longest_match(const u8 window[], uint bytes_remaining,
- uint strstart, const u16 prev_tab[],
- uint cur_match, uint prev_len,
- uint *match_start_ret,
+ uint strstart, const u16 prev_tab[],
+ uint cur_match, uint prev_len,
+ uint *match_start_ret,
const struct lz_params *params)
{
uint chain_len = params->max_chain_len;
if (len > best_len) {
match_start = cur_match;
best_len = len;
- if (len >= nice_match)
+ if (len >= nice_match)
break;
scan_end1 = scan[best_len - 1];
scan_end = scan[best_len];
-/*
+/*
* Determines the sequence of matches and literals that a block of data will be
* compressed to.
*
* @record_literal: A function that will be called to produce the
* intermediate representation of a literal, given
* the character of the literal. This function
- * should also update the appropriate symbol
- * frequency counts so that any needed Huffman
+ * should also update the appropriate symbol
+ * frequency counts so that any needed Huffman
* codes can be made later.
* @record_match_arg_1:
* @record_match_arg_2: Extra arguments to be passed to @record_match.
* hash_head is set to the index of the previous string in the
* hash bucket, or 0 if there is no such string */
if (uncompressed_len - cur_input_pos >= params->min_match) {
- hash = insert_string(hash_tab, prev_tab,
- uncompressed_data,
+ hash = insert_string(hash_tab, prev_tab,
+ uncompressed_data,
cur_input_pos, hash);
hash_head = prev_tab[cur_input_pos];
} else {
* string of window index 0 (in particular we have to
* avoid a match of the string with itself at the start
* of the input file). */
- match_len = longest_match(uncompressed_data,
+ match_len = longest_match(uncompressed_data,
uncompressed_len - cur_input_pos,
- cur_input_pos, prev_tab,
+ cur_input_pos, prev_tab,
hash_head, prev_len,
&match_start, params);
/*cur_input_pos - 1 - prev_start,*/
/*prev_len);*/
- match = (*record_match)(cur_input_pos - 1 - prev_start,
- prev_len,
+ match = (*record_match)(cur_input_pos - 1 - prev_start,
+ prev_len,
record_match_arg1,
record_match_arg2);
/*
* lzx-comp.c
*
- * LZX compression routines.
+ * LZX compression routines.
*
* This code was originally based on code written by Matthew T. Russotto
* (liblzxcomp).
-/*
+/*
* This file provides lzx_compress(), a function to compress an in-memory buffer
* of data using LZX compression, as used in the WIM file format.
*
* tricky to understand. Basically it is the following:
*
* - Preprocess the input data (LZX-specific)
- * - Go through the input data and determine matches. This part is based on
+ * - Go through the input data and determine matches. This part is based on
* code from zlib, and a hash table of 3-character strings is used to
* accelerate the process of finding matches.
* - Build the Huffman trees based on the frequencies of symbols determined
};
struct lzx_freq_tables {
- u32 main_freq_table[LZX_MAINTREE_NUM_SYMBOLS];
+ u32 main_freq_table[LZX_MAINTREE_NUM_SYMBOLS];
u32 len_freq_table[LZX_LENTREE_NUM_SYMBOLS];
u32 aligned_freq_table[LZX_ALIGNEDTREE_NUM_SYMBOLS];
};
int mid;
/* Calculate position base using binary search of table; if log2 can be
- * done in hardware, approximation might work;
+ * done in hardware, approximation might work;
* trunc(log2(formatted_offset*formatted_offset)) gets either the proper
* position slot or the next one, except for slots 0, 1, and 39-49
*
* Slots 0-1 are handled by the R0-R1 procedures
*
- * Slots 36-49 (formatted_offset >= 262144) can be found by
+ * Slots 36-49 (formatted_offset >= 262144) can be found by
* (formatted_offset/131072) + 34 == (formatted_offset >> 17) + 34;
*/
if (formatted_offset >= 262144) {
* alphabets. The return value is a 32-bit integer that, if the high bit is
* set, contains the match length, the position slot, and the position footer
* for the match. */
-static u32 lzx_record_match(uint match_offset, uint match_len,
+static u32 lzx_record_match(uint match_offset, uint match_len,
void *__freq_tabs, void *__queue)
{
struct lzx_freq_tables *freq_tabs = __freq_tabs;
return match;
}
-/*
+/*
* Writes a compressed literal match to the output.
*
* @out: The output bitstream.
main_symbol = len_pos_header + LZX_NUM_CHARS;
/* Output main symbol. */
- ret = bitstream_put_bits(out, codes->main_codewords[main_symbol],
+ ret = bitstream_put_bits(out, codes->main_codewords[main_symbol],
codes->main_lens[main_symbol]);
if (ret != 0)
return ret;
* aligned offset tree. Otherwise, only the verbatim bits need to be
* output. */
if ((block_type == LZX_BLOCKTYPE_ALIGNED) && (num_extra_bits >= 3)) {
-
+
verbatim_bits = position_footer >> 3;
- ret = bitstream_put_bits(out, verbatim_bits,
+ ret = bitstream_put_bits(out, verbatim_bits,
num_extra_bits - 3);
if (ret != 0)
return ret;
aligned_bits = (position_footer & 7);
- ret = bitstream_put_bits(out,
+ ret = bitstream_put_bits(out,
codes->aligned_codewords[aligned_bits],
codes->aligned_lens[aligned_bits]);
if (ret != 0)
return 0;
}
-/*
+/*
* Writes all compressed literals in a block, both matches and literal bytes, to
* the output bitstream.
*
* @codes: Pointer to a structure that contains the codewords for the
* main, length, and aligned offset Huffman codes.
*/
-static int lzx_write_compressed_literals(struct output_bitstream *ostream,
+static int lzx_write_compressed_literals(struct output_bitstream *ostream,
int block_type,
- const u32 match_tab[],
+ const u32 match_tab[],
uint num_compressed_literals,
const struct lzx_codes *codes)
{
* actual match (1) or a literal uncompressed byte (0) */
if (match & 0x80000000) {
/* match */
- ret = lzx_write_match(ostream, block_type, match,
+ ret = lzx_write_match(ostream, block_type, match,
codes);
if (ret != 0)
return ret;
} else {
/* literal byte */
wimlib_assert(match < LZX_NUM_CHARS);
- ret = bitstream_put_bits(ostream,
+ ret = bitstream_put_bits(ostream,
codes->main_codewords[match],
codes->main_lens[match]);
if (ret != 0)
return 0;
}
-/*
+/*
* Writes a compressed Huffman tree to the output, preceded by the pretree for
* it.
*
* @lens: The code lengths for the Huffman tree, indexed by symbol.
* @num_symbols: The number of symbols in the code.
*/
-static int lzx_write_compressed_tree(struct output_bitstream *out,
- const u8 lens[],
+static int lzx_write_compressed_tree(struct output_bitstream *out,
+ const u8 lens[],
uint num_symbols)
{
/* Frequencies of the length symbols, including the RLE symbols (NOT the
/* Build the pretree from the frequencies of the length symbols. */
- make_canonical_huffman_code(LZX_PRETREE_NUM_SYMBOLS,
- LZX_MAX_CODEWORD_LEN,
- pretree_freqs, pretree_lens,
+ make_canonical_huffman_code(LZX_PRETREE_NUM_SYMBOLS,
+ LZX_MAX_CODEWORD_LEN,
+ pretree_freqs, pretree_lens,
pretree_codewords);
/* Write the lengths of the pretree codes to the output. */
for (i = 0; i < LZX_PRETREE_NUM_SYMBOLS; i++)
- bitstream_put_bits(out, pretree_lens[i],
+ bitstream_put_bits(out, pretree_lens[i],
LZX_PRETREE_ELEMENT_SIZE);
/* Write the length symbols, encoded with the pretree, to the output. */
while (i < output_syms_idx) {
pretree_sym = output_syms[i++];
- bitstream_put_bits(out, pretree_codewords[pretree_sym],
+ bitstream_put_bits(out, pretree_codewords[pretree_sym],
pretree_lens[pretree_sym]);
switch (pretree_sym) {
case 17:
break;
case 19:
bitstream_put_bits(out, output_syms[i++], 1);
- bitstream_put_bits(out,
+ bitstream_put_bits(out,
pretree_codewords[output_syms[i]],
pretree_lens[output_syms[i]]);
i++;
static void lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs,
struct lzx_codes *codes)
{
- make_canonical_huffman_code(LZX_MAINTREE_NUM_SYMBOLS,
+ make_canonical_huffman_code(LZX_MAINTREE_NUM_SYMBOLS,
LZX_MAX_CODEWORD_LEN,
- freq_tabs->main_freq_table,
+ freq_tabs->main_freq_table,
codes->main_lens,
codes->main_codewords);
- make_canonical_huffman_code(LZX_LENTREE_NUM_SYMBOLS,
+ make_canonical_huffman_code(LZX_LENTREE_NUM_SYMBOLS,
LZX_MAX_CODEWORD_LEN,
- freq_tabs->len_freq_table,
+ freq_tabs->len_freq_table,
codes->len_lens,
codes->len_codewords);
make_canonical_huffman_code(LZX_ALIGNEDTREE_NUM_SYMBOLS, 8,
- freq_tabs->aligned_freq_table,
+ freq_tabs->aligned_freq_table,
codes->aligned_lens,
codes->aligned_codewords);
}
* no bit to indicate that it actually is used, unlike in the LZX compressed
* format as used in other file formats such as the cabinet format, where a bit
* is reserved for that purpose. */
-static void do_call_insn_preprocessing(u8 uncompressed_data[],
+static void do_call_insn_preprocessing(u8 uncompressed_data[],
uint uncompressed_data_len)
{
int i = 0;
/* Not enabled in the last 6 bytes, which means the 5-byte call
* instruction cannot start in the last *10* bytes. */
- while (i < uncompressed_data_len - 10) {
+ while (i < uncompressed_data_len - 10) {
if (uncompressed_data[i] != 0xe8) {
i++;
continue;
.too_far = 4096,
};
-/*
+/*
* Performs LZX compression on a block of data.
*
* @__uncompressed_data: Pointer to the data to be compressed.
* @compressed_data and @compressed_len_ret will contain the compressed data and
* its length. A return value of nonzero means that compressing the data did
* not reduce its size, and @compressed_data will not contain the full
- * compressed data.
+ * compressed data.
*/
int lzx_compress(const void *__uncompressed_data, uint uncompressed_len,
void *compressed_data, uint *compressed_len_ret)
/* Write the pre-tree and lengths for the first LZX_NUM_CHARS symbols in the
* main tree. */
- ret = lzx_write_compressed_tree(&ostream, codes.main_lens,
+ ret = lzx_write_compressed_tree(&ostream, codes.main_lens,
LZX_NUM_CHARS);
if (ret != 0)
return ret;
/* Write the pre-tree and symbols for the rest of the main tree. */
- ret = lzx_write_compressed_tree(&ostream, codes.main_lens +
- LZX_NUM_CHARS,
- LZX_MAINTREE_NUM_SYMBOLS -
+ ret = lzx_write_compressed_tree(&ostream, codes.main_lens +
+ LZX_NUM_CHARS,
+ LZX_MAINTREE_NUM_SYMBOLS -
LZX_NUM_CHARS);
if (ret != 0)
return ret;
/* Write the pre-tree and symbols for the length tree. */
- ret = lzx_write_compressed_tree(&ostream, codes.len_lens,
+ ret = lzx_write_compressed_tree(&ostream, codes.len_lens,
LZX_LENTREE_NUM_SYMBOLS);
if (ret != 0)
return ret;
/* Verify that we really get the same thing back when decompressing. */
LZX_DEBUG("Verifying the compressed data.");
u8 buf[uncompressed_len];
- ret = lzx_decompress(compressed_data, compressed_len, buf,
+ ret = lzx_decompress(compressed_data, compressed_len, buf,
uncompressed_len);
if (ret != 0) {
ERROR("lzx_compress(): Failed to decompress data we compressed");
* along with wimlib; if not, see http://www.gnu.org/licenses/.
*/
-/*
+/*
* This file has been modified from code taken from cabextract v0.5, which was,
* itself, a modified version of the lzx decompression code from unlzx. The
* code has been customized for wimlib.
*
*/
-/*
+/*
* Some more notes about errors in Microsoft's documentation:
*
* Microsoft's LZX document and their implementation of the com.ms.util.cab Java
/* Huffman decoding tables and maps from symbols to code lengths. */
struct lzx_tables {
- u16 maintree_decode_table[(1 << LZX_MAINTREE_TABLEBITS) +
+ u16 maintree_decode_table[(1 << LZX_MAINTREE_TABLEBITS) +
(LZX_MAINTREE_NUM_SYMBOLS * 2)];
u8 maintree_lens[LZX_MAINTREE_NUM_SYMBOLS];
- u16 lentree_decode_table[(1 << LZX_LENTREE_TABLEBITS) +
+ u16 lentree_decode_table[(1 << LZX_LENTREE_TABLEBITS) +
(LZX_LENTREE_NUM_SYMBOLS * 2)];
u8 lentree_lens[LZX_LENTREE_NUM_SYMBOLS];
- u16 alignedtree_decode_table[(1 << LZX_ALIGNEDTREE_TABLEBITS) +
+ u16 alignedtree_decode_table[(1 << LZX_ALIGNEDTREE_TABLEBITS) +
(LZX_ALIGNEDTREE_NUM_SYMBOLS * 2)];
u8 alignedtree_lens[LZX_ALIGNEDTREE_NUM_SYMBOLS];
};
-/*
- * Reads a Huffman-encoded symbol using the pre-tree.
+/*
+ * Reads a Huffman-encoded symbol using the pre-tree.
*/
-static inline int read_huffsym_using_pretree(struct input_bitstream *istream,
+static inline int read_huffsym_using_pretree(struct input_bitstream *istream,
const u16 pretree_decode_table[],
const u8 pretree_lens[], uint *n)
{
- return read_huffsym(istream, pretree_decode_table, pretree_lens,
+ return read_huffsym(istream, pretree_decode_table, pretree_lens,
LZX_PRETREE_NUM_SYMBOLS, LZX_PRETREE_TABLEBITS, n,
LZX_MAX_CODEWORD_LEN);
}
/* Reads a Huffman-encoded symbol using the main tree. */
-static inline int read_huffsym_using_maintree(struct input_bitstream *istream,
- const struct lzx_tables *tables,
+static inline int read_huffsym_using_maintree(struct input_bitstream *istream,
+ const struct lzx_tables *tables,
uint *n)
{
- return read_huffsym(istream, tables->maintree_decode_table,
+ return read_huffsym(istream, tables->maintree_decode_table,
tables->maintree_lens, LZX_MAINTREE_NUM_SYMBOLS,
LZX_MAINTREE_TABLEBITS, n, LZX_MAX_CODEWORD_LEN);
}
/* Reads a Huffman-encoded symbol using the length tree. */
-static inline int read_huffsym_using_lentree(struct input_bitstream *istream,
- const struct lzx_tables *tables,
+static inline int read_huffsym_using_lentree(struct input_bitstream *istream,
+ const struct lzx_tables *tables,
uint *n)
{
- return read_huffsym(istream, tables->lentree_decode_table,
- tables->lentree_lens, LZX_LENTREE_NUM_SYMBOLS,
+ return read_huffsym(istream, tables->lentree_decode_table,
+ tables->lentree_lens, LZX_LENTREE_NUM_SYMBOLS,
LZX_LENTREE_TABLEBITS, n, LZX_MAX_CODEWORD_LEN);
}
/* Reads a Huffman-encoded symbol using the aligned offset tree. */
-static inline int read_huffsym_using_alignedtree(struct input_bitstream *istream,
- const struct lzx_tables *tables,
+static inline int read_huffsym_using_alignedtree(struct input_bitstream *istream,
+ const struct lzx_tables *tables,
uint *n)
{
- return read_huffsym(istream, tables->alignedtree_decode_table,
+ return read_huffsym(istream, tables->alignedtree_decode_table,
tables->alignedtree_lens,
- LZX_ALIGNEDTREE_NUM_SYMBOLS,
+ LZX_ALIGNEDTREE_NUM_SYMBOLS,
LZX_ALIGNEDTREE_TABLEBITS, n, 8);
}
-/*
+/*
* Reads the pretree from the input, then uses the pretree to decode @num_lens
- * code length values from the input.
+ * code length values from the input.
*
* @istream: The bit stream for the input. It is positioned on the beginning
* of the pretree for the code length values.
* @lens: An array that contains the length values from the previous time
* the code lengths for this Huffman tree were read, or all
- * 0's if this is the first time.
+ * 0's if this is the first time.
* @num_lens: Number of length values to decode and return.
*
*/
-static int lzx_read_code_lens(struct input_bitstream *istream, u8 lens[],
+static int lzx_read_code_lens(struct input_bitstream *istream, u8 lens[],
uint num_lens)
{
/* Declare the decoding table and length table for the pretree. */
- u16 pretree_decode_table[(1 << LZX_PRETREE_TABLEBITS) +
+ u16 pretree_decode_table[(1 << LZX_PRETREE_TABLEBITS) +
(LZX_PRETREE_NUM_SYMBOLS * 2)];
u8 pretree_lens[LZX_PRETREE_NUM_SYMBOLS];
uint i;
/* Read the code lengths of the pretree codes. There are 20 lengths of
* 4 bits each. */
for (i = 0; i < LZX_PRETREE_NUM_SYMBOLS; i++) {
- ret = bitstream_read_bits(istream, LZX_PRETREE_ELEMENT_SIZE,
+ ret = bitstream_read_bits(istream, LZX_PRETREE_ELEMENT_SIZE,
&len);
if (ret != 0)
return ret;
}
/* Make the decoding table for the pretree. */
- ret = make_huffman_decode_table(pretree_decode_table,
- LZX_PRETREE_NUM_SYMBOLS,
- LZX_PRETREE_TABLEBITS,
- pretree_lens,
+ ret = make_huffman_decode_table(pretree_decode_table,
+ LZX_PRETREE_NUM_SYMBOLS,
+ LZX_PRETREE_TABLEBITS,
+ pretree_lens,
LZX_MAX_CODEWORD_LEN);
if (ret != 0)
return ret;
* input. */
uint tree_code;
uint num_zeroes;
- uint code;
+ uint code;
uint num_same;
char value;
- ret = read_huffsym_using_pretree(istream, pretree_decode_table,
+ ret = read_huffsym_using_pretree(istream, pretree_decode_table,
pretree_lens, &tree_code);
if (ret != 0)
return ret;
return ret;
num_same += 4;
- ret = read_huffsym_using_pretree(istream,
- pretree_decode_table,
+ ret = read_huffsym_using_pretree(istream,
+ pretree_decode_table,
pretree_lens, &code);
if (ret != 0)
return ret;
}
}
-/*
+/*
* Reads the header for an LZX-compressed block.
*
* @istream: The input bitstream.
* in bytes, will be returned.
* @block_type_ret: A pointer to an int into which the type of the block
* (LZX_BLOCKTYPE_*) will be returned.
- * @tables: A pointer to a lzx_tables structure in which the
+ * @tables: A pointer to a lzx_tables structure in which the
* main tree, the length tree, and possibly the
* aligned offset tree will be constructed.
* @queue: A pointer to the least-recently-used queue into which
* R0, R1, and R2 will be written (only for uncompressed
* blocks, which contain this information in the header)
*/
-static int lzx_read_block_header(struct input_bitstream *istream,
- int *block_size_ret, int *block_type_ret,
- struct lzx_tables *tables,
+static int lzx_read_block_header(struct input_bitstream *istream,
+ int *block_size_ret, int *block_type_ret,
+ struct lzx_tables *tables,
struct lru_queue *queue)
{
int ret;
* then build it. */
for (i = 0; i < LZX_ALIGNEDTREE_NUM_SYMBOLS; i++) {
- ret = bitstream_read_bits(istream,
- LZX_ALIGNEDTREE_ELEMENT_SIZE,
+ ret = bitstream_read_bits(istream,
+ LZX_ALIGNEDTREE_ELEMENT_SIZE,
&len);
if (ret != 0)
return ret;
tables->alignedtree_lens[i] = len;
}
-
+
LZX_DEBUG("Building the aligned tree.");
ret = make_huffman_decode_table(tables->alignedtree_decode_table,
- LZX_ALIGNEDTREE_NUM_SYMBOLS,
+ LZX_ALIGNEDTREE_NUM_SYMBOLS,
LZX_ALIGNEDTREE_TABLEBITS,
tables->alignedtree_lens,
8);
LZX_DEBUG("Reading path lengths for main tree.");
/* Read the path lengths for the first 256 elements of the main
* tree. */
- ret = lzx_read_code_lens(istream, tables->maintree_lens,
+ ret = lzx_read_code_lens(istream, tables->maintree_lens,
LZX_NUM_CHARS);
if (ret != 0) {
ERROR("lzx_decompress(): Failed to read the code "
LZX_DEBUG("Reading path lengths for remaining elements of "
"main tree (%d elements).",
LZX_MAINTREE_NUM_SYMBOLS - LZX_NUM_CHARS);
- ret = lzx_read_code_lens(istream,
- tables->maintree_lens + LZX_NUM_CHARS,
+ ret = lzx_read_code_lens(istream,
+ tables->maintree_lens + LZX_NUM_CHARS,
LZX_MAINTREE_NUM_SYMBOLS - LZX_NUM_CHARS);
if (ret != 0) {
ERROR("lzx_decompress(): Failed to read the path "
ret = make_huffman_decode_table(tables->maintree_decode_table,
LZX_MAINTREE_NUM_SYMBOLS,
LZX_MAINTREE_TABLEBITS,
- tables->maintree_lens,
+ tables->maintree_lens,
LZX_MAX_CODEWORD_LEN);
if (ret != 0) {
ERROR("lzx_decompress(): Failed to make the decode "
}
LZX_DEBUG("Reading path lengths for the length tree.");
- ret = lzx_read_code_lens(istream, tables->lentree_lens,
+ ret = lzx_read_code_lens(istream, tables->lentree_lens,
LZX_LENTREE_NUM_SYMBOLS);
if (ret != 0) {
ERROR("lzx_decompress(): Failed to read the path "
LZX_DEBUG("Building the length tree.");
ret = make_huffman_decode_table(tables->lentree_decode_table,
- LZX_LENTREE_NUM_SYMBOLS,
+ LZX_LENTREE_NUM_SYMBOLS,
LZX_LENTREE_TABLEBITS,
- tables->lentree_lens,
+ tables->lentree_lens,
LZX_MAX_CODEWORD_LEN);
if (ret != 0) {
ERROR("lzx_decompress(): Failed to build the length "
return 0;
}
-/*
+/*
* Decodes a compressed literal match value. It refers to some match_offset to
* a point earlier in the window, and some match_len, for which the data is to
* be copied to the current position in the window.
* the amount of data needing to be uncompressed, or match refers to data before
* the window, or the input bitstream ended unexpectedly).
*/
-static int lzx_decode_match(int main_element, int block_type,
- int bytes_remaining, u8 *window, int window_pos,
- const struct lzx_tables *tables,
- struct lru_queue *queue,
+static int lzx_decode_match(int main_element, int block_type,
+ int bytes_remaining, u8 *window, int window_pos,
+ const struct lzx_tables *tables,
+ struct lru_queue *queue,
struct input_bitstream *istream)
{
uint length_header;
* tree, offset by 9 (LZX_MIN_MATCH + LZX_NUM_PRIMARY_LENS) */
match_len = LZX_MIN_MATCH + length_header;
if (length_header == LZX_NUM_PRIMARY_LENS) {
- ret = read_huffsym_using_lentree(istream, tables,
+ ret = read_huffsym_using_lentree(istream, tables,
&additional_len);
if (ret != 0)
return -1;
* equal to 3. (Note that in the case with
* num_extra_bits == 3, the assignment to verbatim_bits
* will just set it to 0. ) */
- ret = bitstream_read_bits(istream, num_extra_bits - 3,
+ ret = bitstream_read_bits(istream, num_extra_bits - 3,
&verbatim_bits);
if (ret != 0)
return -1;
verbatim_bits <<= 3;
- ret = read_huffsym_using_alignedtree(istream, tables,
+ ret = read_huffsym_using_alignedtree(istream, tables,
&aligned_bits);
if (ret != 0)
return -1;
* less than 3 extra bits, the extra bits are added
* directly to the match offset, and the correction for
* the alignment is taken to be 0. */
- ret = bitstream_read_bits(istream, num_extra_bits,
+ ret = bitstream_read_bits(istream, num_extra_bits,
&verbatim_bits);
if (ret != 0)
return -1;
}
/* Calculate the match offset. */
- match_offset = lzx_position_base[position_slot] + verbatim_bits +
+ match_offset = lzx_position_base[position_slot] + verbatim_bits +
aligned_bits - 2;
/* Update the LRU queue. */
* no bit to indicate that it actually is used, unlike in the LZX compressed
* format as used in other file formats, where a bit is reserved for that
* purpose. */
-static void undo_call_insn_preprocessing(u8 uncompressed_data[],
+static void undo_call_insn_preprocessing(u8 uncompressed_data[],
uint uncompressed_data_len)
{
int i = 0;
/* Not enabled in the last 6 bytes, which means the 5-byte call
* instruction cannot start in the last *10* bytes. */
- while (i < uncompressed_data_len - 10) {
+ while (i < uncompressed_data_len - 10) {
if (uncompressed_data[i] != 0xe8) {
i++;
continue;
/* "compensating translation" */
rel_offset = abs_offset + file_size;
}
- *(int32_t*)(uncompressed_data + i + 1) =
+ *(int32_t*)(uncompressed_data + i + 1) =
cpu_to_le32(rel_offset);
}
i += 5;
}
}
-/*
+/*
* Decompresses a compressed block of data from which the header has already
* been read.
*
* @block_size: The size of the block, in bytes.
* @window: Pointer to the decompression window.
* @window_pos: The current position in the window. Will be 0 for the first
- * block.
+ * block.
* @tables: The Huffman decoding tables for the block (main, length, and
* aligned offset, the latter only for LZX_BLOCKTYPE_ALIGNED)
* @queue: The least-recently-used queue for match offsets.
* @istream: The input bitstream for the compressed literals.
*/
-static int lzx_decompress_block(int block_type, int block_size, u8 *window,
- int window_pos,
- const struct lzx_tables *tables,
- struct lru_queue *queue,
+static int lzx_decompress_block(int block_type, int block_size, u8 *window,
+ int window_pos,
+ const struct lzx_tables *tables,
+ struct lru_queue *queue,
struct input_bitstream *istream)
{
uint bytes_remaining;
bytes_remaining = block_size;
while (bytes_remaining > 0) {
- ret = read_huffsym_using_maintree(istream, tables,
+ ret = read_huffsym_using_maintree(istream, tables,
&main_element);
if (ret != 0)
return ret;
if (main_element < LZX_NUM_CHARS) {
/* literal: 0 to LZX_NUM_CHARS - 1 */
- window[window_pos + block_size - bytes_remaining] =
+ window[window_pos + block_size - bytes_remaining] =
main_element;
bytes_remaining--;
} else {
/* match: LZX_NUM_CHARS to LZX_MAINTREE_NUM_SYMBOLS - 1 */
- match_len = lzx_decode_match(main_element,
+ match_len = lzx_decode_match(main_element,
block_type, bytes_remaining, window,
- block_size + window_pos -
+ block_size + window_pos -
bytes_remaining,
tables, queue, istream);
if (match_len == -1)
return 0;
}
-/*
+/*
* Decompresses a block of LZX-compressed data using a window size of 32768.
*
* @compressed_data: A pointer to the compressed data.
- * @compressed_len: The length of the compressed data, in bytes.
+ * @compressed_len: The length of the compressed data, in bytes.
* @uncompressed_data: A pointer to the buffer into which to write the
* uncompressed data.
* @uncompressed_len: The length of the uncompressed data.
*
* Return non-zero on failure.
*/
-int lzx_decompress(const void *compressed_data, uint compressed_len,
+int lzx_decompress(const void *compressed_data, uint compressed_len,
void *uncompressed_data, uint uncompressed_len)
{
struct lzx_tables tables;
while (bytes_remaining != 0) {
LZX_DEBUG("Reading block header.");
- ret = lzx_read_block_header(&istream, &block_size, &block_type,
+ ret = lzx_read_block_header(&istream, &block_size, &block_type,
&tables, &queue);
if (ret != 0)
return ret;
else
LZX_DEBUG("LZX_BLOCKTYPE_ALIGNED");
- ret = lzx_decompress_block(block_type,
+ ret = lzx_decompress_block(block_type,
block_size,
uncompressed_data,
uncompressed_len -
- bytes_remaining,
+ bytes_remaining,
&tables, &queue, &istream);
if (ret != 0)
return ret;
break;
case LZX_BLOCKTYPE_UNCOMPRESSED:
LZX_DEBUG("LZX_BLOCKTYPE_UNCOMPRESSED");
- ret = bitstream_read_bytes(&istream, block_size,
- uncompressed_data +
- uncompressed_len -
+ ret = bitstream_read_bytes(&istream, block_size,
+ uncompressed_data +
+ uncompressed_len -
bytes_remaining);
if (ret != 0)
return ret;
* read_code_lens() function and built using the make_decode_table() function.
* The decode table is not a real tree but rather a table that we can index by
* some number of bits (*_TABLEBITS) of the input to quickly look up the symbol
- * corresponding to a Huffman code.
+ * corresponding to a Huffman code.
*
* The ALIGNED tree is only present on ALIGNED blocks.
*
int R2;
};
-extern int lzx_decompress(const void *compressed_data, uint compressed_len,
+extern int lzx_decompress(const void *compressed_data, uint compressed_len,
void *uncompressed_data, uint uncompressed_len);
extern int lzx_compress(const void *uncompressed_data, uint uncompressed_len,
} else if (dentry_is_symlink(root)) { /* Archiving a symbolic link */
char deref_name_buf[4096];
ssize_t deref_name_len;
-
+
deref_name_len = readlink(root_disk_path, deref_name_buf,
sizeof(deref_name_buf) - 1);
if (deref_name_len >= 0) {
ret = WIMLIB_ERR_INVALID_CAPTURE_CONFIG;
goto out_destroy;
}
-
+
next_p = eol + 1;
bytes_remaining -= (next_p - p);
if (eol == p)
return -EMFILE;
num_new_fds = min(fds_per_alloc,
max_fds - inode->num_allocated_fds);
-
+
fds = REALLOC(inode->fds,
(inode->num_allocated_fds + num_new_fds) *
sizeof(inode->fds[0]));
DEBUG("Creating staging file `%s'", name);
- fd = open(name, open_flags | O_CREAT | O_TRUNC, 0600);
+ fd = open(name, open_flags | O_CREAT | O_TRUNC, 0600);
if (fd == -1) {
errno_save = errno;
FREE(name);
return fd;
}
-/*
+/*
* Extract a WIM resource to the staging directory.
*
* @inode: Inode that contains the stream we are extracting
* opening it read-write. Identify those file descriptors and
* change their lookup table entry pointers to point to the new
* lookup table entry, and open staging file descriptors for
- * them.
+ * them.
*
* At the same time, we need to count the number of these opened
* file descriptors to the new lookup table entry. If there's
return ret;
}
-/*
+/*
* Creates a randomly named staging directory and returns its name into the
* static variable staging_dir_name.
*
}
-/*
- * Deletes the staging directory and all the files contained in it.
+/*
+ * Deletes the staging directory and all the files contained in it.
*/
static int delete_staging_dir()
{
int ret;
-
+
ret = nftw(staging_dir_name, remove_file_or_directory,10, FTW_DEPTH);
staging_dir_name = NULL;
return ret;
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,
+static char *strcat_dup(const char *s1, const char *s2, const char *s3,
const char *s4)
{
size_t len = strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4) + 1;
}
}
-/*
+/*
* Opens two POSIX message queue: one for sending messages from the unmount
* process to the daemon process, and one to go the other way. The names of the
* message queues, which must be system-wide unique, are be based on the mount
else
flags = O_WRONLY | O_CREAT;
- unmount_to_daemon_mq = mq_open(unmount_to_daemon_mq_name, flags,
+ unmount_to_daemon_mq = mq_open(unmount_to_daemon_mq_name, flags,
0700, NULL);
if (unmount_to_daemon_mq == (mqd_t)-1) {
else
flags = O_RDONLY | O_CREAT;
- daemon_to_unmount_mq = mq_open(daemon_to_unmount_mq_name, flags,
+ daemon_to_unmount_mq = mq_open(daemon_to_unmount_mq_name, flags,
0700, NULL);
if (daemon_to_unmount_mq == (mqd_t)-1) {
DEBUG("Waiting for message telling us whether to commit or not, and "
"whether to include integrity checks.");
- bytes_received = mq_timedreceive(unmount_to_daemon_mq, msg,
+ bytes_received = mq_timedreceive(unmount_to_daemon_mq, msg,
msgsize, NULL, &timeout);
commit = msg[0];
check_integrity = msg[1];
}
#endif
-/*
- * Create a directory in the WIM.
+/*
+ * Create a directory in the WIM.
* @mode is currently ignored.
*/
static int wimfs_mkdir(const char *path, mode_t mode)
struct dentry *parent;
struct dentry *newdir;
const char *basename;
-
+
parent = get_parent_dentry(w, path);
if (!parent)
return -ENOENT;
struct inode *inode;
int ret;
struct wimlib_fd *fd = NULL;
-
+
inode = wim_pathname_to_inode(w, path);
if (!inode)
return -ENOENT;
/*
- * Read data from a file in the WIM or in the staging directory.
+ * Read data from a file in the WIM or in the staging directory.
*/
-static int wimfs_read(const char *path, char *buf, size_t size,
+static int wimfs_read(const char *path, char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
struct wimlib_fd *fd = (struct wimlib_fd*)(uintptr_t)fi->fh;
/* Read from WIM */
u64 res_size = wim_resource_size(fd->f_lte);
-
+
if (offset > res_size)
return -EOVERFLOW;
/* Fills in the entries of the directory specified by @path using the
* FUSE-provided function @filler. */
-static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
struct wimlib_fd *fd = (struct wimlib_fd*)(uintptr_t)fi->fh;
/* This rename() implementation currently only supports actual files
* (not alternate data streams) */
-
+
src = get_dentry(w, from);
if (!src)
return -ENOENT;
static int wimfs_rmdir(const char *path)
{
struct dentry *dentry;
-
+
dentry = get_dentry(w, path);
if (!dentry)
return -ENOENT;
struct dentry *dentry_parent, *dentry;
const char *link_name;
struct inode *inode;
-
+
dentry_parent = get_parent_dentry(w, from);
if (!dentry_parent)
return -ENOENT;
u16 stream_idx;
u32 stream_id;
struct inode *inode;
-
+
ret = lookup_resource(w, path, get_lookup_flags(), &dentry,
<e, &stream_idx);
int ret;
u16 stream_idx;
unsigned i;
-
+
ret = lookup_resource(w, path, get_lookup_flags(), &dentry,
<e, &stream_idx);
}
#ifdef HAVE_UTIMENSAT
-/*
- * Change the timestamp on a file dentry.
+/*
+ * Change the timestamp on a file dentry.
*
* Note that alternate data streams do not have their own timestamps.
*/
}
#endif
-/* Writes to a file in the WIM filesystem.
+/* Writes to a file in the WIM filesystem.
* It may be an alternate data stream, but here we don't even notice because we
* just get a lookup table entry. */
-static int wimfs_write(const char *path, const char *buf, size_t size,
+static int wimfs_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
struct wimlib_fd *fd = (struct wimlib_fd*)(uintptr_t)fi->fh;
/* Mounts a WIM file. */
-WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir,
+WIMLIBAPI int wimlib_mount(WIMStruct *wim, int image, const char *dir,
int flags, WIMStruct **additional_swms,
unsigned num_additional_swms)
{
if (flags & WIMLIB_MOUNT_FLAG_DEBUG)
argv[argc++] = "-d";
- /*
+ /*
* We provide the use_ino option because we are going to assign inode
* numbers oursides. We've already numbered the inodes with unique
* numbers in the assign_inode_numbers() function, and the static
}
-/*
+/*
* Unmounts the WIM file that was previously mounted on @dir by using
* wimlib_mount().
*/
msg[0] = (flags & WIMLIB_UNMOUNT_FLAG_COMMIT) ? 1 : 0;
msg[1] = (flags & WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY) ? 1 : 0;
- DEBUG("Sending message: %s, %s",
+ DEBUG("Sending message: %s, %s",
(msg[0] == 0) ? "don't commit" : "commit",
(msg[1] == 0) ? "don't check" : "check");
ret = mq_send(unmount_to_daemon_mq, msg, 2, 1);
* send a message from this process to the filesystem daemon telling
* whether --commit was specified or not. However, after that, the
* unmount process must wait for the filesystem daemon to finish writing
- * the WIM file.
+ * the WIM file.
*/
* filesystem daemon has crashed or failed for some reason.
*
* XXX come up with some method to determine if the filesystem
- * daemon has really crashed or not.
+ * daemon has really crashed or not.
*
* XXX Idea: have mount daemon write its PID into the WIM file header?
* */
return mount_unsupported_error();
}
-WIMLIBAPI int wimlib_mount(WIMStruct *wim_p, int image, const char *dir,
+WIMLIBAPI int wimlib_mount(WIMStruct *wim_p, int image, const char *dir,
int flags, WIMStruct **additional_swms,
unsigned num_additional_swms)
{
WIMStruct *w;
};
-/*
+/*
* Extracts a WIM resource to a NTFS attribute.
*/
static int
if (dentry->d_inode->security_id != -1) {
const struct wim_security_data *sd;
const char *descriptor;
-
+
sd = wim_const_security_data(w);
wimlib_assert(dentry->d_inode->security_id < sd->num_entries);
descriptor = sd->descriptors[dentry->d_inode->security_id];
ret = ntfs_xattr_system_setxattr(&ctx, XATTR_NTFS_ACL,
ni, dir_ni, descriptor,
sd->sizes[dentry->d_inode->security_id], 0);
-
+
if (ret != 0) {
ERROR_WITH_ERRNO("Failed to set security data on `%s'",
dentry->full_path_utf8);
static int do_wim_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni,
WIMStruct *w);
-/*
+/*
* If @dentry is part of a hard link group, search for hard-linked dentries in
* the same directory that have a nonempty DOS (short) filename. There should
* be exactly 0 or 1 such dentries. If there is 1, extract that dentry first,
return 0;
}
-/*
+/*
* Applies a WIM dentry to a NTFS filesystem.
*
* @dentry: The WIM dentry to apply
}
}
- /*
+ /*
* Create a directory or file.
*
* Note: For symbolic links that are not directory junctions, pass
int ret;
struct dentry *root;
struct ntfs_apply_args args;
-
+
DEBUG("Mounting NTFS volume `%s'", device);
vol = ntfs_mount(device, 0);
if (!vol) {
}
-/*
+/*
* API entry point for applying a WIM image to a NTFS volume.
*
* Please note that this is a NTFS *volume* and not a directory. The intention
if (cmp < 0) {
if (root->left)
insert_sd_node(new, root->left);
- else
+ else
root->left = new;
} else if (cmp > 0) {
if (root->right)
insert_sd_node(new, root->right);
- else
+ else
root->right = new;
} else {
wimlib_assert(0);
}
/* Returns the security ID of the security data having a SHA1 message digest of
- * @hash in the security descriptor index tree rooted at @root.
+ * @hash in the security descriptor index tree rooted at @root.
*
* If not found, return -1. */
static int lookup_sd(const u8 hash[SHA1_HASH_SIZE], struct sd_node *root)
return (ntfschar*)((u8*)ar + le16_to_cpu(ar->name_offset));
}
-/* Calculates the SHA1 message digest of a NTFS attribute.
+/* Calculates the SHA1 message digest of a NTFS attribute.
*
* @ni: The NTFS inode containing the attribute.
* @ar: The ATTR_RECORD describing the attribute.
u64 data_size = ntfs_get_attribute_value_length(actx->attr);
u64 name_length = actx->attr->name_length;
- if (data_size == 0) {
+ if (data_size == 0) {
if (errno != 0) {
ERROR_WITH_ERRNO("Failed to get size of attribute of "
"`%s'", path);
goto out_free_lte;
wimlib_assert(new_ads_entry->stream_name_len == name_length * 2);
-
+
new_ads_entry->lte = lte;
}
}
ntfs_volume **ntfs_vol_p = extra_arg;
DEBUG("Mounting NTFS volume `%s' read-only", device);
-
+
vol = ntfs_mount(device, MS_RDONLY);
if (!vol) {
ERROR_WITH_ERRNO("Failed to mount NTFS volume `%s' read-only",
#endif
-/*
+/*
* Reads all or part of a compressed resource into an in-memory buffer.
*
* @fp: The FILE* for the WIM file.
- * @resource_compressed_size: The compressed size of the resource.
+ * @resource_compressed_size: The compressed size of the resource.
* @resource_uncompressed_size: The uncompressed size of the resource.
* @resource_offset: The offset of the start of the resource from
* the start of the stream @fp.
- * @resource_ctype: The compression type of the resource.
+ * @resource_ctype: The compression type of the resource.
* @len: The number of bytes of uncompressed data to read from
* the resource.
* @offset: The offset of the bytes to read within the uncompressed
*
* Returns zero on success, nonzero on failure.
*/
-static int read_compressed_resource(FILE *fp, u64 resource_compressed_size,
- u64 resource_uncompressed_size,
- u64 resource_offset, int resource_ctype,
+static int read_compressed_resource(FILE *fp, u64 resource_compressed_size,
+ u64 resource_uncompressed_size,
+ u64 resource_offset, int resource_ctype,
u64 len, u64 offset, u8 contents_ret[])
{
* The chunk offsets are measured relative to the end of the chunk
* table. The first chunk is omitted from the table in the WIM file
* because its offset is implicitly given by the fact that it directly
- * follows the chunk table and therefore must have an offset of 0.
+ * follows the chunk table and therefore must have an offset of 0.
*/
/* Calculate how many chunks the resource conists of in its entirety. */
/* According to M$'s documentation, if the uncompressed size of
* the file is greater than 4 GB, the chunk entries are 8-byte
* integers. Otherwise, they are 4-byte integers. */
- u64 chunk_entry_size = (resource_uncompressed_size >= (u64)1 << 32) ?
+ u64 chunk_entry_size = (resource_uncompressed_size >= (u64)1 << 32) ?
8 : 4;
/* Size of the full chunk table in the WIM file. */
/* Number of entries we need to actually read from the chunk
* table (excludes the implicit first chunk). */
- u64 num_needed_chunk_entries = (start_chunk == 0) ?
+ u64 num_needed_chunk_entries = (start_chunk == 0) ?
num_needed_chunks - 1 : num_needed_chunks;
/* Skip over unneeded chunk table entries. */
- u64 file_offset_of_needed_chunk_entries = resource_offset +
+ u64 file_offset_of_needed_chunk_entries = resource_offset +
start_table_idx * chunk_entry_size;
if (fseeko(fp, file_offset_of_needed_chunk_entries, SEEK_SET) != 0) {
ERROR_WITH_ERRNO("Failed to seek to byte %"PRIu64" to read "
/* Done with the chunk table now. We must now seek to the first chunk
* that is needed for the read. */
- u64 file_offset_of_first_needed_chunk = resource_offset +
+ u64 file_offset_of_first_needed_chunk = resource_offset +
chunk_table_size + chunk_offsets[0];
if (fseeko(fp, file_offset_of_first_needed_chunk, SEEK_SET) != 0) {
ERROR_WITH_ERRNO("Failed to seek to byte %"PRIu64" to read "
* expand to WIM_CHUNK_SIZE uncompressed, and the amount
* of compressed data for the chunk is given by the
* difference of offsets in the chunk offset table. */
- compressed_chunk_size = chunk_offsets[i + 1 - start_chunk] -
+ compressed_chunk_size = chunk_offsets[i + 1 - start_chunk] -
chunk_offsets[i - start_chunk];
uncompressed_chunk_size = WIM_CHUNK_SIZE;
} else {
* bytes in the file resource, and the last uncompressed
* chunk has size equal to however many bytes are left-
* that is, the remainder of the uncompressed size when
- * divided by WIM_CHUNK_SIZE.
+ * divided by WIM_CHUNK_SIZE.
*
* Note that the resource_compressed_size includes the
* chunk table, so the size of it must be subtracted. */
- compressed_chunk_size = resource_compressed_size -
+ compressed_chunk_size = resource_compressed_size -
chunk_table_size -
chunk_offsets[i - start_chunk];
- uncompressed_chunk_size = resource_uncompressed_size %
+ uncompressed_chunk_size = resource_uncompressed_size %
WIM_CHUNK_SIZE;
/* If the remainder is 0, the last chunk actually
end_offset = WIM_CHUNK_SIZE - 1;
u64 partial_chunk_size = end_offset + 1 - start_offset;
- bool is_partial_chunk = (partial_chunk_size !=
+ bool is_partial_chunk = (partial_chunk_size !=
uncompressed_chunk_size);
DEBUG2("start_offset = %u, end_offset = %u", start_offset,
return WIMLIB_ERR_READ;
}
}
- if (fread(out_p, 1, partial_chunk_size, fp) !=
+ if (fread(out_p, 1, partial_chunk_size, fp) !=
partial_chunk_size)
goto err;
} else {
int ret;
/* Read the compressed data into compressed_buf. */
- if (fread(compressed_buf, 1, compressed_chunk_size,
+ if (fread(compressed_buf, 1, compressed_chunk_size,
fp) != compressed_chunk_size)
goto err;
ret = decompress(compressed_buf,
compressed_chunk_size,
- uncompressed_buf,
+ uncompressed_buf,
uncompressed_chunk_size);
if (ret != 0)
return WIMLIB_ERR_DECOMPRESSION;
return WIMLIB_ERR_READ;
}
-/*
+/*
* Reads uncompressed data from an open file stream.
*/
int read_uncompressed_resource(FILE *fp, u64 offset, u64 len,
}
}
-/*
+/*
* Reads all the data from the resource corresponding to a WIM lookup table
* entry.
*
u64 offsets[0];
};
-/*
+/*
* Allocates and initializes a chunk table, and reserves space for it in the
* output file.
*/
return ret;
}
-/*
+/*
* Compresses a chunk of a WIM resource.
*
* @chunk: Uncompressed data of the chunk.
* @chunk: Uncompressed data of the chunk.
* @chunk_size: Size of the chunk (<= WIM_CHUNK_SIZE)
* @out_fp: FILE * to write tho chunk to.
- * @out_ctype: Compression type to use when writing the chunk (ignored if no
+ * @out_ctype: Compression type to use when writing the chunk (ignored if no
* chunk table provided)
* @chunk_tab: Pointer to chunk table being created. It is updated with the
* offset of the chunk we write.
*chunk_tab->cur_offset_p++ = chunk_tab->cur_offset;
chunk_tab->cur_offset += out_chunk_size;
}
-
+
if (fwrite(out_chunk, 1, out_chunk_size, out_fp) != out_chunk_size) {
ERROR_WITH_ERRNO("Failed to write WIM resource chunk");
return WIMLIB_ERR_WRITE;
return 0;
}
-/*
+/*
* Finishes a WIM chunk tale and writes it to the output file at the correct
* offset.
*
* the same as the compression type of the WIM resource we
* need to read, we simply copy the data (i.e. we do not
* uncompress it, then compress it again).
- * @out_res_entry: If non-NULL, a resource entry that is filled in with the
+ * @out_res_entry: If non-NULL, a resource entry that is filled in with the
* offset, original size, compressed size, and compression flag
* of the output resource.
*
"stream");
return WIMLIB_ERR_WRITE;
}
-
+
/* Are the compression types the same? If so, do a raw copy (copy
* without decompressing and recompressing the data). */
raw = (wim_resource_compression_type(lte) == out_ctype
/* Raw copy: The new compressed size is the same as the old compressed
* size
- *
+ *
* Using WIM_COMPRESSION_TYPE_NONE: The new compressed size is the
* original size
*
return 0;
}
-/*
+/*
* Extracts the first @size bytes of the WIM resource specified by @lte to the
* open file descriptor @fd.
- *
+ *
* Returns 0 on success; nonzero on failure.
*/
int extract_wim_resource_to_fd(const struct lookup_table_entry *lte, int fd,
return 0;
}
-/*
+/*
* Extracts the WIM resource specified by @lte to the open file descriptor @fd.
- *
+ *
* Returns 0 on success; nonzero on failure.
*/
int extract_full_wim_resource_to_fd(const struct lookup_table_entry *lte, int fd)
return extract_wim_resource_to_fd(lte, fd, wim_resource_size(lte));
}
-/*
+/*
* Copies the file resource specified by the lookup table entry @lte from the
* input WIM to the output WIM that has its FILE * given by
* ((WIMStruct*)wim)->out_fp.
return 0;
ret = write_wim_resource(lte, w->out_fp,
- wim_resource_compression_type(lte),
+ wim_resource_compression_type(lte),
<e->output_resource_entry);
if (ret != 0)
return ret;
return 0;
}
-/*
+/*
* Writes a dentry's resources, including the main file resource as well as all
- * alternate data streams, to the output file.
+ * alternate data streams, to the output file.
*
* @dentry: The dentry for the file.
* @wim_p: A pointer to the WIMStruct containing @dentry.
*
- * @return zero on success, nonzero on failure.
+ * @return zero on success, nonzero on failure.
*/
int write_dentry_resources(struct dentry *dentry, void *wim_p)
{
return ret;
}
-/*
+/*
* Reads the metadata metadata resource from the WIM file. The metadata
* resource consists of the security data, followed by the directory entry for
* the root directory, followed by all the other directory entries in the
ret = WIMLIB_ERR_NOMEM;
goto out_free_security_data;
}
-
+
ret = read_dentry(buf, metadata_len, dentry_offset, dentry);
/* This is the root dentry, so set its pointers correctly. */
DEBUG("Writing dentry tree.");
p = write_dentry_tree(root, p);
- /*
+ /*
* Append 20 random bytes to the metadata resource so that we don't have
* identical metadata resources if we happen to append exactly the same
* image twice without any changes in timestamps. If this were to
#include "io.h"
#include "security.h"
-/*
+/*
* This is a hack to work around a problem in libntfs-3g. libntfs-3g validates
* security descriptors with a function named ntfs_valid_descr().
* ntfs_valid_descr() considers a security descriptor that ends in a SACL
}
}
-/*
+/*
* Reads the security data from the metadata resource.
*
* @metadata_resource: An array that contains the uncompressed metadata
return ret;
}
-/*
+/*
* Writes security data to an in-memory buffer.
*/
u8 *write_security_data(const struct wim_security_data *sd, u8 *p)
print_acl(p + dacl_offset, "Discretionary");
}
-/*
+/*
* Prints the security data for a WIM file.
*/
void print_security_data(const struct wim_security_data *sd)
printf("Number of Entries = %"PRIu32"\n", sd->num_entries);
for (u32 i = 0; i < sd->num_entries; i++) {
- printf("[SecurityDescriptor %"PRIu32", length = %"PRIu64"]\n",
+ printf("[SecurityDescriptor %"PRIu32", length = %"PRIu64"]\n",
i, sd->sizes[i]);
print_security_descriptor(sd->descriptors[i], sd->sizes[i]);
putchar('\n');
/* At the start of each type of access control entry. */
typedef struct {
/* enum ace_type, specifies what type of ACE this is. */
- u8 type;
+ u8 type;
/* bitwise OR of the inherit ACE flags #defined above */
u8 flags;
* Parts of this file are based on public domain code written by Steve Reid.
*/
-/*
+/*
* Copyright (C) 2012 Eric Biggers
*
* This file is part of wimlib, a library for working with WIM files.
#include <stdlib.h>
void ssse3_not_found()
{
- fprintf(stderr,
+ fprintf(stderr,
"Cannot calculate SHA1 message digest: CPU does not support SSSE3\n"
"instructions! Recompile wimlib without the --enable-ssse3-sha1 flag\n"
"to use wimlib on this CPU.\n");
off_t lookup_table_offset = ftello(w->out_fp);
int ret;
- DEBUG("Writing lookup table for SWM (offset %"PRIu64")",
+ DEBUG("Writing lookup table for SWM (offset %"PRIu64")",
lookup_table_offset);
while (lte_chain_head != NULL) {
if (lookup_table_offset == -1 || xml_data_offset == -1)
return WIMLIB_ERR_WRITE;
w->hdr.lookup_table_res_entry.offset = lookup_table_offset;
- w->hdr.lookup_table_res_entry.size =
+ w->hdr.lookup_table_res_entry.size =
xml_data_offset - lookup_table_offset;
ret = finish_write(w, WIM_ALL_IMAGES, write_flags, 0);
if (ret != 0)
if (lte->resource_entry.flags & WIM_RESHDR_FLAG_METADATA)
return 0;
- if (args->size_remaining < 0 ||
+ if (args->size_remaining < 0 ||
(u64)args->size_remaining < lte->resource_entry.size) {
/* No space for this resource. Finish the previous swm and
args->lte_chain_tail = NULL;
args->lte_chain_head = NULL;
- sprintf(args->swm_base_name + args->swm_base_name_len, "%d",
+ sprintf(args->swm_base_name + args->swm_base_name_len, "%d",
++args->part_number);
strcat(args->swm_base_name, args->swm_suffix);
if (args->write_flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS)
printf("Writing `%s' (%"PRIu64" of %"PRIu64" bytes, "
- "%.0f%% done)\n",
- args->swm_base_name,
+ "%.0f%% done)\n",
+ args->swm_base_name,
args->total_bytes_written,
args->total_bytes,
(double)args->total_bytes_written /
/* Splits the WIM file @wimfile into multiple parts prefixed by @swm_name with
* size at most @part_size. */
-WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name,
+WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name,
size_t part_size, int flags)
{
int ret;
}
if (write_flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS)
- printf("Writing `%s' (%.2f %% done)\n",
- swm_name,
+ printf("Writing `%s' (%.2f %% done)\n",
+ swm_name,
(double)total_bytes_written /
(double)total_bytes * 100.0);
put_u16(&buf[0], i);
put_u16(&buf[2], total_parts);
- if (fseek(fp, 40, SEEK_SET) != 0 ||
+ if (fseek(fp, 40, SEEK_SET) != 0 ||
fwrite(buf, 1, sizeof(buf), fp) != sizeof(buf)
|| fclose(fp) != 0) {
ERROR_WITH_ERRNO("Error overwriting header of `%s'",
translated_target += 4;
link_target_len -= 4;
/* There's a drive letter, so just leave the backslashes since
- * it won't go anyhwere on UNIX anyway...
+ * it won't go anyhwere on UNIX anyway...
*
* XXX
* NTFS-3g tries to re-map these links to actually point to
buf_len, inode->reparse_tag);
}
-/*
+/*
* Sets @inode to be a symbolic link pointing to @target.
*
* A lookup table entry for the symbolic link data buffer is created and
struct lookup_table_entry *lte = NULL, *existing_lte;
u8 symlink_buf_hash[SHA1_HASH_SIZE];
void *symlink_buf;
-
+
symlink_buf = make_symlink_reparse_data_buf(target, &symlink_buf_len);
if (!symlink_buf)
return WIMLIB_ERR_NOMEM;
DEBUG("Made symlink reparse data buf (len = %zu, name len = %zu)",
symlink_buf_len, symlink_buf_len);
-
+
sha1_buffer(symlink_buf, symlink_buf_len, symlink_buf_hash);
existing_lte = __lookup_resource(lookup_table, symlink_buf_hash);
#ifdef ENABLE_ERROR_MESSAGES
extern bool __wimlib_print_errors;
-extern void wimlib_error(const char *format, ...)
+extern void wimlib_error(const char *format, ...)
FORMAT(printf, 1, 2) COLD;
-extern void wimlib_error_with_errno(const char *format, ...)
+extern void wimlib_error_with_errno(const char *format, ...)
FORMAT(printf, 1, 2) COLD;
extern void wimlib_warning(const char *format, ...)
FORMAT(printf, 1, 2) COLD;
extern char *utf16_to_utf8(const char *utf16_str, size_t utf16_len,
size_t *utf8_len_ret);
-extern char *utf8_to_utf16(const char *utf8_str, size_t utf8_len,
+extern char *utf8_to_utf16(const char *utf8_str, size_t utf8_len,
size_t *utf16_len_ret);
extern void randomize_byte_array(u8 *p, size_t n);
extern void randomize_char_array_with_alnum(char p[], size_t n);
-extern const char *path_next_part(const char *path,
+extern const char *path_next_part(const char *path,
size_t *first_part_len_ret);
extern const char *path_basename(const char *path);
* External header for wimlib.
*/
-/*
+/*
* Copyright (C) 2012 Eric Biggers
*
* This file is part of wimlib, a library for working with WIM files.
* A WIM file may be either stand-alone or split into multiple parts.
*
* \section winpe Windows PE
- *
+ *
* A major use for this library is to create customized images of Windows PE, the
* Windows Preinstallation Environment, without having to rely on Windows. Windows
* PE is a lightweight version of Windows that can run entirely from memory and can
* wimlib comes with the <b>imagex</b> program, which is documented in man pages.
*
* \section mkwinpeimg mkwinpeimg
- *
+ *
* wimlib comes with the <b>mkwinpeimg</b> script, which is documented in a man
* page.
*
#include <stdbool.h>
#ifndef _WIMLIB_INTERNAL_H
-/**
- * Opaque structure that represents a WIM file.
+/**
+ * Opaque structure that represents a WIM file.
*/
typedef struct WIMStruct WIMStruct;
#endif
* alternate file stream name. */
#define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS 0x00000040
-/** Include an integrity table in the new WIM being written during the unmount.
+/** Include an integrity table in the new WIM being written during the unmount.
* Ignored for read-only mounts. */
#define WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY 0x00000001
* @param config_len
* Length of the string @a config in bytes. Ignored if @a config is @c
* NULL.
- *
+ *
* @param flags
* Bitwise OR of flags prefixed with WIMLIB_ADD_IMAGE_FLAG. If
* ::WIMLIB_ADD_IMAGE_FLAG_BOOT is specified, the image in @a wim that is
* discarded so that it appears to be in the same state as when this function
* was called.
*
- * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
+ * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
* There is already an image named @a name in @a w.
- * @retval ::WIMLIB_ERR_INVALID_PARAM
+ * @retval ::WIMLIB_ERR_INVALID_PARAM
* @a dir was @c NULL, @a name was @c NULL, or @a name was the empty string.
* @retval ::WIMLIB_ERR_NOMEM
* Failed to allocate needed memory.
* @a wim is part of a split WIM. Adding an image to a split WIM is
* unsupported.
*/
-extern int wimlib_add_image(WIMStruct *wim, const char *dir,
+extern int wimlib_add_image(WIMStruct *wim, const char *dir,
const char *name, const char *config,
size_t config_len, int flags);
WIMStruct **additional_swms,
unsigned num_additional_swms);
-/**
+/**
* Creates a WIMStruct for a new WIM file.
*
- * @param ctype
+ * @param ctype
* The type of compression to be used in the new WIM file. Must be
* ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
* ::WIM_COMPRESSION_TYPE_XPRESS.
* @retval ::WIMLIB_ERR_INVALID_IMAGE
* @a image does not exist in the WIM and is not ::WIM_ALL_IMAGES.
* @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
- * The metadata resource for @a image in the WIM is invalid.
+ * The metadata resource for @a image in the WIM is invalid.
* @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
- * The security data for @a image in the WIM is invalid.
+ * The security data for @a image in the WIM is invalid.
* @retval ::WIMLIB_ERR_NOMEM
* Failed to allocate needed memory.
* @retval ::WIMLIB_ERR_READ
* @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
* One or more of the names being given to an exported image was already in
* use in the destination WIM.
- * @retval ::WIMLIB_ERR_INVALID_DENTRY
+ * @retval ::WIMLIB_ERR_INVALID_DENTRY
* A directory entry in the metadata resource for @a src_image in @a
* src_wim is invalid.
* @retval ::WIMLIB_ERR_INVALID_IMAGE
* ::WIM_ALL_IMAGES, and @a src_wim contains multiple images; or @a src_wim
* or @a dest_wim was @c NULL.
* @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
- * The metadata resource for @a src_image in @a src_wim is invalid.
+ * The metadata resource for @a src_image in @a src_wim is invalid.
* @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
- * The security data for @a src_image in @a src_wim is invalid.
- * @retval ::WIMLIB_ERR_NOMEM
+ * The security data for @a src_image in @a src_wim is invalid.
+ * @retval ::WIMLIB_ERR_NOMEM
* Failed to allocate needed memory.
* @retval ::WIMLIB_ERR_READ
* Could not read the metadata resource for @a src_image from @a src_wim.
* @a dest_wim is part of a split WIM. Exporting an image to a split WIM
* is unsupported.
*/
-extern int wimlib_export_image(WIMStruct *src_wim, int src_image,
- WIMStruct *dest_wim, const char *dest_name,
+extern int wimlib_export_image(WIMStruct *src_wim, int src_image,
+ WIMStruct *dest_wim, const char *dest_name,
const char *dest_description, int flags,
WIMStruct **additional_swms,
unsigned num_additional_swms);
* @retval ::WIMLIB_ERR_DECOMPRESSION
* Could not decompress a resource (file or metadata) for @a image in @a
* wim.
- * @retval ::WIMLIB_ERR_INVALID_DENTRY
+ * @retval ::WIMLIB_ERR_INVALID_DENTRY
* A directory entry in the metadata resource for @a image in @a wim is
* invalid.
* @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
* The SHA1 message digest of an extracted stream did not match the SHA1
* message digest given in the WIM file.
* @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
- * A resource (file or metadata) for @a image in @a wim is invalid.
+ * A resource (file or metadata) for @a image in @a wim is invalid.
* @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
- * The security data for @a image in @a wim is invalid.
+ * The security data for @a image in @a wim is invalid.
* @retval ::WIMLIB_ERR_LINK
* Failed to create a symbolic link or a hard link.
* @retval ::WIMLIB_ERR_MKDIR
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
- * @param fp
- * @c stdout, or a FILE* opened for writing, to extract the data to.
+ * @param fp
+ * @c stdout, or a FILE* opened for writing, to extract the data to.
*
* @return 0 on success; nonzero on error.
* @retval ::WIMLIB_ERR_WRITE
/**
* Frees all memory allocated for a WIMStruct and closes all files associated
- * with it.
+ * with it.
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
- *
+ *
* @return
* 0 if no image is marked as bootable, or the number of the image marked
* as bootable (numbered starting at 1).
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file
- *
+ *
* @return
* ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
* ::WIM_COMPRESSION_TYPE_XPRESS.
* @param wim
* Pointer to the ::WIMStruct for a WIM file. It may be either a
* standalone WIM or a split WIM part.
- *
+ *
* @return
* The number of images contained in the WIM file.
*/
* If non-@c NULL, the total number of parts in the split WIM (1 for
* non-split WIMs) is written to this location.
*
- * @return
+ * @return
* The part number of the WIM (1 for non-split WIMs)
*/
extern int wimlib_get_part_number(const WIMStruct *wim, int *total_parts_ret);
* Could not decompress the metadata resource for @a image in @a wim.
* @retval ::WIMLIB_ERR_FUSE
* A non-zero status was returned by @c fuse_main().
- * @retval ::WIMLIB_ERR_INVALID_DENTRY
+ * @retval ::WIMLIB_ERR_INVALID_DENTRY
* A directory entry in the metadata resource for @a image in @a wim is
* invalid.
* @retval ::WIMLIB_ERR_INVALID_IMAGE
* @a image is shared among multiple ::WIMStruct's as a result of a call to
* wimlib_export().
* @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
- * The metadata resource for @a image in @a wim is invalid.
+ * The metadata resource for @a image in @a wim is invalid.
* @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
- * The security data for @a image in @a wim is invalid.
+ * The security data for @a image in @a wim is invalid.
* @retval ::WIMLIB_ERR_MKDIR
* ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @a flags, but the staging
* directory could not be created.
/**
* Opens a WIM file and creates a ::WIMStruct for it.
*
- * @param wim_file
+ * @param wim_file
* The path to the WIM file to open.
* @param flags
* Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
* @retval ::WIMLIB_ERR_XML
* The XML data for @a wim_file is invalid.
*/
-extern int wimlib_open_wim(const char *wim_file, int flags,
+extern int wimlib_open_wim(const char *wim_file, int flags,
WIMStruct **wim_ret);
/**
* Pointer to the ::WIMStruct for the WIM file to write. There may have
* been in-memory changes made to it, which are then reflected in the
* output file.
- * @param flags
+ * @param flags
* Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
* ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
*
*
* @param wim
* Pointer to the ::WIMStruct for the WIM file to overwrite.
- * @param flags
+ * @param flags
* Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
* ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
*
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
- * @param image
+ * @param image
* The image about which to print information. Can be the number of an
* image, or ::WIM_ALL_IMAGES to print information about all images in the
* WIM.
- *
+ *
* @return This function has no return value. No error checking is done when
* printing the information. If @a image is invalid, an error message is
* printed.
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
- * @param image
+ * @param image
* Which image to print files for. Can be the number of an image, or
- * ::WIM_ALL_IMAGES to print the files contained in all images.
+ * ::WIM_ALL_IMAGES to print the files contained in all images.
*
* @return 0 on success; nonzero on error.
* @retval ::WIMLIB_ERR_DECOMPRESSION
*/
extern void wimlib_print_header(const WIMStruct *wim);
-/**
+/**
* Prints the lookup table of a WIM file. The lookup table maps SHA1 message
* digests, as found in the directory entry tree in the WIM file, to file
* resources in the WIM file. This table includes one entry for each unique
/**
* Prints the metadata of the specified image in a WIM file. The metadata
* consists of the security data as well as the directory entry tree, and each
- * image has its own metadata.
+ * image has its own metadata.
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
- * @param image
+ * @param image
* Which image to print the metadata for. Can be the number of an image,
* or ::WIM_ALL_IMAGES to print the metadata for all images in the WIM.
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
*
- * @return This function has no return value.
+ * @return This function has no return value.
*/
extern void wimlib_print_wim_information(const WIMStruct *wim);
*
* @param wim
* Pointer to the ::WIMStruct for a WIM file.
- * @param image_name_or_num
+ * @param image_name_or_num
* A string specifying which image. If it begins with a number, it is
* taken to be a string specifying the image number. Otherwise, it is
* taken to be the name of an image, as specified in the XML data for the
* WIM file. It also may be the keyword "all" or the string "*", both of
* which will resolve to ::WIM_ALL_IMAGES.
*
- * @return
+ * @return
* If the string resolved to a single existing image, the number of that
* image, counting starting at 1, is returned. If the keyword "all" was
* specified, ::WIM_ALL_IMAGES is returned. Otherwise, ::WIM_NO_IMAGE is
* @return 0 on success; nonzero on error.
* @retval ::WIMLIB_ERR_INVALID_PARAM
* @a wim was @c NULL.
- * @retval ::WIMLIB_ERR_INVALID_IMAGE
+ * @retval ::WIMLIB_ERR_INVALID_IMAGE
* @a boot_idx does not specify an existing image in @a wim, and it was not
* 0.
* @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
* Failed to allocate the memory needed to duplicate the @a description
* string.
*/
-extern int wimlib_set_image_descripton(WIMStruct *wim, int image,
+extern int wimlib_set_image_descripton(WIMStruct *wim, int image,
const char *description);
/**
* An error occurred when trying to write data to one of the split WIMs.
*
*/
-extern int wimlib_split(const char *wimfile, const char *swm_name,
+extern int wimlib_split(const char *wimfile, const char *swm_name,
size_t part_size, int flags);
/**
* there should be no infinite loops or crashes in the code, so this wouldn't be
* much of a problem. Currently, a timeout of 600 seconds (so long because WIMs
* can be very large) is implemented so that this function will not wait forever
- * before returning failure.
+ * before returning failure.
*
* @param dir
* The directory that the WIM image was mounted on.
* @param image
* The image inside the WIM to write. Use ::WIM_ALL_IMAGES to include all
* images.
- * @param flags
+ * @param flags
* Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
* ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS. If
* ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is given, an integrity table is
* @return 0 on success; nonzero on error.
* @retval ::WIMLIB_ERR_DECOMPRESSION
* Failed to decompress a metadata or file resource in @a wim.
- * @retval ::WIMLIB_ERR_INVALID_DENTRY
+ * @retval ::WIMLIB_ERR_INVALID_DENTRY
* A directory entry in the metadata resource for @a image in @a wim is
* invalid.
* @retval ::WIMLIB_ERR_INVALID_IMAGE
* @retval ::WIMLIB_ERR_INVALID_PARAM
* @a wim or @a path was @c NULL.
* @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
- * The metadata resource for @a image in @a wim is invalid.
+ * The metadata resource for @a image in @a wim is invalid.
* @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
* The security data for @a image in @a wim is invalid.
* @retval ::WIMLIB_ERR_NOMEM
/* Header at the very beginning of the WIM file. */
-struct wim_header {
+struct wim_header {
/* Identifies the file as WIM file. Must be exactly
* {'M', 'S', 'W', 'I', 'M', 0, 0, 0} */
- //u8 magic[WIM_MAGIC_LEN];
+ //u8 magic[WIM_MAGIC_LEN];
/* size of WIM header in bytes. */
//u32 hdr_size;
* WIM_CHUNK_SIZE. M$ incorrectly documents this as "the size of the
* compressed .wim file in bytes".*/
//u32 chunk_size;
-
+
/* A unique identifier for the WIM file. */
u8 guid[WIM_GID_LEN];
/* The index of the bootable image in the WIM file. If 0, there are no
* bootable images available. */
- u32 boot_idx;
+ u32 boot_idx;
/* The location of the optional integrity table used to verify the
* integrity WIM. Zeroed out if there is no integrity table.*/
/* Lock field to prevent multiple writers from writing the WIM concurrently. We
* ignore this flag. */
-#define WIM_HDR_FLAG_WRITE_IN_PROGRESS 0x00000040
+#define WIM_HDR_FLAG_WRITE_IN_PROGRESS 0x00000040
/* Reparse point fixup ???
* This has something to do with absolute targets of reparse points / symbolic
* that wimlib writes, currently), it will be 8 bytes. */
u32 total_length;
- /* The number of security descriptors in the array @descriptors, below.
+ /* The number of security descriptors in the array @descriptors, below.
* It is really an unsigned int, but it must fit into an int because the
* security ID's are signed. (Not like you would ever have more than a
* few hundred security descriptors anyway). */
/* The name of the WIM file that has been opened. */
char *filename;
- /* The lookup table for the WIM file. */
+ /* The lookup table for the WIM file. */
struct lookup_table *lookup_table;
/* Pointer to the XML data read from the WIM file. */
u64 num_entries;
u64 capacity;
- /*
+ /*
* Linked list of "extra" inodes. These may be:
*
* - inodes with link count 1, which are all allowed to have 0 for their
extern int init_header(struct wim_header *hdr, int ctype);
/* integrity.c */
-extern int write_integrity_table(FILE *out, u64 end_header_offset,
+extern int write_integrity_table(FILE *out, u64 end_header_offset,
u64 end_lookup_table_offset,
int show_progress);
extern int check_wim_integrity(WIMStruct *w, int show_progress, int *status);
const char *config_str, size_t config_len,
int flags,
int (*capture_tree)(struct dentry **, const char *,
- struct lookup_table *,
- struct wim_security_data *,
+ struct lookup_table *,
+ struct wim_security_data *,
const struct capture_config *,
int, void *),
void *extra_arg);
/* security.c */
-int read_security_data(const u8 metadata_resource[],
+int read_security_data(const u8 metadata_resource[],
u64 metadata_resource_len, struct wim_security_data **sd_p);
void print_security_data(const struct wim_security_data *sd);
extern int for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *));
/* write.c */
-extern int finish_write(WIMStruct *w, int image, int flags,
+extern int finish_write(WIMStruct *w, int image, int flags,
int write_lookup_table);
extern int begin_write(WIMStruct *w, const char *path, int flags);
-/*
+/*
* Writes a WIM file to the original file that it was read from, overwriting it.
*/
WIMLIBAPI int wimlib_overwrite(WIMStruct *w, int flags)
const char *wimfile_name;
size_t wim_name_len;
int ret;
-
+
if (!w)
return WIMLIB_ERR_INVALID_PARAM;
* the integrity table include neither the header nor the XML data.
* Save it for later if it exists and an integrity table was required.
* */
- if (flags & WIMLIB_WRITE_FLAG_CHECK_INTEGRITY &&
+ if (flags & WIMLIB_WRITE_FLAG_CHECK_INTEGRITY &&
w->hdr.integrity.offset != 0) {
DEBUG("Reading existing integrity table.");
integrity_table = MALLOC(w->hdr.integrity.size);
w->hdr.integrity.offset = xml_end;
if (integrity_table) {
/* The existing integrity table was saved. */
- bytes_written = fwrite(integrity_table, 1,
+ bytes_written = fwrite(integrity_table, 1,
w->hdr.integrity.size, fp);
if (bytes_written != w->hdr.integrity.size) {
ERROR_WITH_ERRNO("Failed to write integrity "
/* There was no existing integrity table, so a new one
* must be calculated. */
ret = write_integrity_table(fp, WIM_HEADER_DISK_SIZE,
- w->hdr.lookup_table_res_entry.offset +
+ w->hdr.lookup_table_res_entry.offset +
w->hdr.lookup_table_res_entry.size,
flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS);
if (ret != 0)
hdr.lookup_table_res_entry.original_size = hdr.lookup_table_res_entry.size;
hdr.lookup_table_res_entry.flags = WIM_RESHDR_FLAG_METADATA;
- ret = write_xml_data(w->wim_info, image, out,
+ ret = write_xml_data(w->wim_info, image, out,
write_lt ? 0 : wim_info_get_total_bytes(w->wim_info));
if (ret != 0)
return ret;
hdr.xml_res_entry.flags = 0;
if (flags & WIMLIB_WRITE_FLAG_CHECK_INTEGRITY) {
- ret = write_integrity_table(out, WIM_HEADER_DISK_SIZE,
- xml_data_offset,
+ ret = write_integrity_table(out, WIM_HEADER_DISK_SIZE,
+ xml_data_offset,
flags & WIMLIB_WRITE_FLAG_SHOW_PROGRESS);
if (ret != 0)
return ret;
DEBUG("Updating WIM header.");
- /*
+ /*
* In the WIM header, there is room for the resource entry for a
* metadata resource labeled as the "boot metadata". This entry should
* be zeroed out if there is no bootable image (boot_idx 0). Otherwise,
*/
if (hdr.boot_idx == 0 || !w->image_metadata
|| (image != WIM_ALL_IMAGES && image != hdr.boot_idx)) {
- memset(&hdr.boot_metadata_res_entry, 0,
+ memset(&hdr.boot_metadata_res_entry, 0,
sizeof(struct resource_entry));
} else {
- memcpy(&hdr.boot_metadata_res_entry,
+ memcpy(&hdr.boot_metadata_res_entry,
&w->image_metadata[
hdr.boot_idx - 1].metadata_lte->output_resource_entry,
sizeof(struct resource_entry));
DEBUG("Opening `%s' for new WIM", path);
/* checking the integrity requires going back over the file to read it.
- * XXX
+ * XXX
* (It also would be possible to keep a running sha1sum as the file
* as written-- this would be faster, but a bit more complicated) */
- if (flags & WIMLIB_WRITE_FLAG_CHECK_INTEGRITY)
+ if (flags & WIMLIB_WRITE_FLAG_CHECK_INTEGRITY)
mode = "w+b";
else
mode = "wb";
if (!w || !path)
return WIMLIB_ERR_INVALID_PARAM;
- if (image != WIM_ALL_IMAGES &&
+ if (image != WIM_ALL_IMAGES &&
(image < 1 || image > w->hdr.image_count))
return WIMLIB_ERR_INVALID_IMAGE;
for_dentry_in_tree(w->image_metadata[image - 1].root_dentry,
calculate_dentry_statistics,
image_info);
-
+
image_info->lookup_table = NULL;
image_info->flags = flags_save;
image_info->last_modification_time = get_wim_timestamp();
};
/* xml.c */
-extern int xml_export_image(const struct wim_info *old_wim_info, int image,
+extern int xml_export_image(const struct wim_info *old_wim_info, int image,
struct wim_info **new_wim_info_p,
const char *dest_image_name,
const char *dest_image_description);
extern void print_image_info(const struct wim_info *wim_info, int image);
-extern int read_xml_data(FILE *fp, const struct resource_entry *res,
+extern int read_xml_data(FILE *fp, const struct resource_entry *res,
u8 **xml_data_ret, struct wim_info **info_ret);
extern int write_xml_data(const struct wim_info *wim_info, int image, FILE *out,
#define XPRESS_MIN_MATCH 3
#define XPRESS_MAX_MATCH 255
-extern int xpress_decompress(const void *__compressed_data, uint compressed_len,
+extern int xpress_decompress(const void *__compressed_data, uint compressed_len,
void *__uncompressed_data, uint uncompressed_len);
extern int xpress_compress(const void *uncompressed_data, uint uncompressed_len,
if ! test "`readlink tmp/subdir/rel_symlink`" = "hello"; then
error "Symlink target not correct"
fi
-
+
rm -rf dir.wim tmp
done
# We try with 5 different combinations of compression types to make sure we go
# through all paths in the resource-handling code.
for i in `seq 1 3`; do
- case $i in
+ case $i in
1)
cflag1="--compress=none";
cflag2="--compress=none";
setfattr -n user.aa -v 1111 file;
setfattr -n user.aaa -v 1111 file;
setfattr -n user.aaaa -v 1111 file;'
-
+
msg "file with named data streams with same contents as other file"
do_test 'echo -n > file;
setfattr -n user.a -v 1111 file;
touch file2;
setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_1.base64` file
setfattr -n system.ntfs_acl -v 0s`cat $srcdir/tests/security_descriptor_2.base64` file'
-
+
msg "files with different security descriptors and some with the same security descriptor"
do_test 'touch file;
touch file2;
-/*
+/*
* A program to compare directory trees
*
* There are two modes: