{
int c;
int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
- int image;
- int ret;
const char *output_path;
for_opt(c, join_options) {
/* Mounts an image using a FUSE mount. */
static int imagex_mount_rw_or_ro(int argc, const char **argv)
{
- bool ro;
int c;
int mount_flags = 0;
int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG;
break;
default:
- usage(ro ? MOUNT : MOUNTRW);
+ usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
+ ? MOUNTRW : MOUNT);
return -1;
}
}
argc -= optind;
argv += optind;
if (argc != 2 && argc != 3) {
- usage(ro ? MOUNT : MOUNTRW);
+ usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
+ ? MOUNTRW : MOUNT);
return -1;
}
if (num_images != 1) {
imagex_error("The file `%s' contains %d images; Please "
"select one.\n", wimfile, num_images);
- usage(ro ? MOUNT : MOUNTRW);
+ usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
+ ? MOUNTRW : MOUNT);
ret = WIMLIB_ERR_INVALID_IMAGE;
goto done;
}
p = get_u32(p, &dentry->attributes);
#ifdef ENABLE_SECURITY_DATA
- p = get_u32(p, &dentry->security_id);
+ p = get_u32(p, (u32*)&dentry->security_id);
#else
p += sizeof(u32);
#endif
u32 hdr_size;
u32 wim_version;
u32 chunk_size;
- u16 part_number;
- u16 total_parts;
DEBUG("Reading WIM header.\n");
struct lookup_table_entry *lte)
{
size_t pos;
- pos = *(size_t*)lte->hash % table->capacity;
+ pos = lte->hash_short % table->capacity;
lte->next = table->array[pos];
table->array[pos] = lte;
/* XXX Make the table grow when too many entries have been inserted. */
size_t pos;
struct lookup_table_entry *prev, *cur_entry, *next;
- pos = *(size_t*)lte->hash % table->capacity;
+ pos = lte->hash_short % table->capacity;
prev = NULL;
cur_entry = table->array[pos];
/* Number of times this lookup table entry is referenced by dentries. */
u32 refcnt;
- /* SHA1 hash of the file resource pointed to by this lookup table entry */
- u8 hash[WIM_HASH_SIZE];
+ union {
+ /* SHA1 hash of the file resource pointed to by this lookup
+ * table entry */
+ u8 hash[WIM_HASH_SIZE];
+
+ /* First 4 or 8 bytes of the SHA1 hash, used for inserting the
+ * entry into the hash table. Since the SHA1 hashes can be
+ * considered random, we don't really need the full 20 byte hash
+ * just to insert the entry in a hash table. */
+ size_t hash_short;
+ };
/* If @file_on_disk != NULL, the file resource indicated by this lookup
* table entry is not in the WIM file, but rather a file on disk; this
if (delta < 0)
delta += 17;
pretree_freqs[19]++;
- pretree_freqs[delta]++;
+ pretree_freqs[(unsigned char)delta]++;
output_syms[output_syms_idx++] = 19;
output_syms[output_syms_idx++] = additional_bits;
output_syms[output_syms_idx++] = delta;
if (delta < 0)
delta += 17;
- pretree_freqs[delta]++;
+ pretree_freqs[(unsigned char)delta]++;
output_syms[output_syms_idx++] = delta;
}
const char *dest_description,
int flags)
{
- int boot_idx;
int i;
int ret;
struct dentry *root;
/* multi-image export. */
- if (flags & WIMLIB_EXPORT_FLAG_BOOT) {
-
+ if ((flags & WIMLIB_EXPORT_FLAG_BOOT) &&
+ (src_wim->hdr.boot_idx == 0))
+ {
/* Specifying the boot flag on a multi-image
* source WIM makes the boot index default to
* the bootable image in the source WIM. It is
* an error if there is no such bootable image.
* */
-
- if (src_wim->hdr.boot_idx == 0) {
- ERROR("Cannot specify `boot' flag "
- "when exporting multiple "
- "images from a WIM with no "
- "bootable images!\n");
- return WIMLIB_ERR_INVALID_PARAM;
- } else {
- boot_idx = src_wim->hdr.boot_idx;
- }
+ ERROR("Cannot specify `boot' flag when "
+ "exporting multiple images from a WIM "
+ "with no bootable images!\n");
+ return WIMLIB_ERR_INVALID_PARAM;
}
if (dest_name || dest_description) {
- ERROR("Image name or image description "
- "was specified, but we are exporting "
- "multiple images!\n");
+ ERROR("Image name or image description was "
+ "specified, but we are exporting "
+ "multiple images!\n");
return WIMLIB_ERR_INVALID_PARAM;
}
for (i = 1; i <= src_wim->hdr.image_count; i++) {
int export_flags = flags;
- if (i != boot_idx)
+ if (i != src_wim->hdr.boot_idx)
export_flags &= ~WIMLIB_EXPORT_FLAG_BOOT;
ret = wimlib_export_image(src_wim, i, dest_wim,
/* no lookup table entry, so the file must be empty. Create a
* lookup table entry for the file. */
char *tmpfile_name;
- int err;
int fd;
lte = new_lookup_table_entry();
fd = create_staging_file(&tmpfile_name);
if (fd == -1) {
- err = errno;
+ int err = errno;
free(lte);
- return -errno;
+ return -err;
}
lte->resource_entry.original_size = 0;
randomize_byte_array(lte->hash, WIM_HASH_SIZE);
struct lookup_table_entry *lte,
u64 size)
{
- int err, fd;
+ int fd;
bool ret;
char *staging_file_name;
struct lookup_table_entry *new_lte;
u8 *buf;
u8 *p;
int ret;
- off_t subdir_offset;
+ u64 subdir_offset;
struct dentry *root;
struct lookup_table_entry *lte;
struct resource_entry *res_entry;
u64 size_no_descriptors = 8 + sizes_size;
if (size_no_descriptors > sd->total_length) {
- ERROR("Security data total length of %"PRIu64" is too short because\n"
+ ERROR("Security data total length of %u is too short because\n"
"there must be at least %"PRIu64" bytes of security "
"data!\n", sd->total_length,
8 + sizes_size);
for (uint i = 0; i < sd->num_entries; i++) {
total_len += sd->sizes[i];
if (total_len > sd->total_length) {
- ERROR("Security data total length of %"PRIu64" is too "
+ ERROR("Security data total length of %u is too "
"short because there are at least %"PRIu64" "
"bytes of security data!\n",
sd->total_length, total_len);
{
struct args *args = (struct args*)__args;
WIMStruct *w = args->w;
- FILE *out_fp = w->out_fp;
int ret;
/* metadata resources were already written. */
ERROR("Failed to open `%s': %m\n", p);
return WIMLIB_ERR_OPEN;
}
- char buf[4];
- put_u16(buf, i);
- put_u16(buf + 2, total_parts);
+ u8 buf[4];
+ put_u16(&buf[0], i);
+ put_u16(&buf[2], total_parts);
if (fseek(fp, 40, SEEK_SET) != 0 ||
fwrite(buf, 1, sizeof(buf), fp) != sizeof(buf)
xml_set_memory_allocator(wimlib_malloc_func, wimlib_free_func,
wimlib_realloc_func);
+ return 0;
#else
ERROR("Cannot set custom memory allocator functions:\n");
ERROR("wimlib was compiled with the "
*/
int for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *))
{
- int ret;
+ int ret = 0;
int i;
int image_count;
off_t end_offset;
off_t integrity_size;
int ret;
- int i;
struct wim_header hdr;
FILE *out = w->out_fp;