),
[DIR] =
T(
-IMAGEX_PROGNAME" dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all)\n"
+IMAGEX_PROGNAME" dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--path=PATH]\n"
),
[EXPORT] =
T(
IMAGEX_METADATA_OPTION,
IMAGEX_NORPFIX_OPTION,
IMAGEX_NO_ACLS_OPTION,
+ IMAGEX_PATH_OPTION,
IMAGEX_REBUILD_OPTION,
IMAGEX_RECOMPRESS_OPTION,
IMAGEX_RECURSIVE_OPTION,
{NULL, 0, NULL, 0},
};
+static const struct option dir_options[] = {
+ {T("path"), required_argument, NULL, IMAGEX_PATH_OPTION},
+ {NULL, 0, NULL, 0},
+};
+
static const struct option export_options[] = {
{T("boot"), no_argument, NULL, IMAGEX_BOOT_OPTION},
{T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION},
int write_flags = 0;
const tchar *wimfile;
const tchar *image_num_or_name;
- WIMStruct *w;
+ WIMStruct *wim;
int image;
int ret;
write_flags |= WIMLIB_WRITE_FLAG_SOFT_DELETE;
break;
default:
- usage(DELETE);
- return -1;
+ goto out_usage;
}
}
argc -= optind;
imagex_error(T("Must specify a WIM file"));
if (argc < 2)
imagex_error(T("Must specify an image"));
- usage(DELETE);
- return -1;
+ goto out_usage;
}
wimfile = argv[0];
image_num_or_name = argv[1];
- ret = wimlib_open_wim(wimfile, open_flags, &w,
+ ret = wimlib_open_wim(wimfile, open_flags, &wim,
imagex_progress_func);
- if (ret != 0)
- return ret;
+ if (ret)
+ goto out;
- image = wimlib_resolve_image(w, image_num_or_name);
+ image = wimlib_resolve_image(wim, image_num_or_name);
ret = verify_image_exists(image, image_num_or_name, wimfile);
- if (ret != 0)
- goto out;
+ if (ret)
+ goto out_wimlib_free;
- ret = wimlib_delete_image(w, image);
- if (ret != 0) {
- imagex_error(T("Failed to delete image from \"%"TS"\""), wimfile);
- goto out;
+ ret = wimlib_delete_image(wim, image);
+ if (ret) {
+ imagex_error(T("Failed to delete image from \"%"TS"\""),
+ wimfile);
+ goto out_wimlib_free;
}
- ret = wimlib_overwrite(w, write_flags, 0, imagex_progress_func);
- if (ret != 0) {
+ ret = wimlib_overwrite(wim, write_flags, 0, imagex_progress_func);
+ if (ret) {
imagex_error(T("Failed to write the file \"%"TS"\" with image "
"deleted"), wimfile);
}
+out_wimlib_free:
+ wimlib_free(wim);
out:
- wimlib_free(w);
return ret;
+out_usage:
+ usage(DELETE);
+ ret = -1;
+ goto out;
}
static int
-print_full_path(const struct wimlib_wim_dentry *wdentry, void *_ignore)
+print_full_path(const struct wimlib_dir_entry *wdentry, void *_ignore)
{
- tprintf(T("%"TS"\n"), wdentry->full_path);
- return 0;
+ int ret = tprintf(T("%"TS"\n"), wdentry->full_path);
+ return (ret >= 0) ? 0 : -1;
}
/* Print the files contained in an image(s) in a WIM file. */
imagex_dir(int argc, tchar **argv)
{
const tchar *wimfile;
- WIMStruct *w;
+ WIMStruct *wim = NULL;
int image;
int ret;
- int num_images;
+ const tchar *path = T("");
+ int c;
- if (argc < 2) {
+ for_opt(c, dir_options) {
+ switch (c) {
+ case IMAGEX_PATH_OPTION:
+ path = optarg;
+ break;
+ default:
+ goto out_usage;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 1) {
imagex_error(T("Must specify a WIM file"));
- usage(DIR);
- return -1;
+ goto out_usage;
}
- if (argc > 3) {
+ if (argc > 2) {
imagex_error(T("Too many arguments"));
- usage(DIR);
- return -1;
+ goto out_usage;
}
- wimfile = argv[1];
- ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &w,
+ wimfile = argv[0];
+ ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &wim,
imagex_progress_func);
- if (ret != 0)
- return ret;
+ if (ret)
+ goto out;
- if (argc == 3) {
- image = wimlib_resolve_image(w, argv[2]);
- ret = verify_image_exists(image, argv[2], wimfile);
- if (ret != 0)
- goto out;
+ if (argc == 2) {
+ image = wimlib_resolve_image(wim, argv[1]);
+ ret = verify_image_exists(image, argv[1], wimfile);
+ if (ret)
+ goto out_wimlib_free;
} else {
/* Image was not specified. If the WIM only contains one image,
* choose that one; otherwise, print an error. */
- num_images = wimlib_get_num_images(w);
+ int num_images = wimlib_get_num_images(wim);
if (num_images != 1) {
imagex_error(T("\"%"TS"\" contains %d images; Please "
"select one."), wimfile, num_images);
- usage(DIR);
- ret = -1;
- goto out;
+ wimlib_free(wim);
+ goto out_usage;
}
image = 1;
}
- ret = wimlib_iterate_dir_tree(w, image, T(""),
+ ret = wimlib_iterate_dir_tree(wim, image, path,
WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE,
print_full_path, NULL);
+out_wimlib_free:
+ wimlib_free(wim);
out:
- wimlib_free(w);
return ret;
+out_usage:
+ usage(DIR);
+ ret = -1;
+ goto out;
}
/* Exports one, or all, images from a WIM file to a new WIM file or an existing
const tchar *dest_wimfile;
const tchar *dest_name;
const tchar *dest_desc;
- WIMStruct *src_w = NULL;
- WIMStruct *dest_w = NULL;
+ WIMStruct *src_wim;
+ WIMStruct *dest_wim;
int ret;
int image;
struct stat stbuf;
case IMAGEX_COMPRESS_OPTION:
compression_type = get_compression_type(optarg);
if (compression_type == WIMLIB_COMPRESSION_TYPE_INVALID)
- return -1;
+ goto out_err;
compression_type_specified = true;
break;
case IMAGEX_REF_OPTION:
case IMAGEX_THREADS_OPTION:
num_threads = parse_num_threads(optarg);
if (num_threads == UINT_MAX)
- return -1;
+ goto out_err;
break;
case IMAGEX_REBUILD_OPTION:
write_flags |= WIMLIB_WRITE_FLAG_REBUILD;
break;
default:
- usage(EXPORT);
- return -1;
+ goto out_usage;
}
}
argc -= optind;
argv += optind;
- if (argc < 3 || argc > 5) {
- usage(EXPORT);
- return -1;
- }
+ if (argc < 3 || argc > 5)
+ goto out_usage;
src_wimfile = argv[0];
src_image_num_or_name = argv[1];
dest_wimfile = argv[2];
dest_name = (argc >= 4) ? argv[3] : NULL;
dest_desc = (argc >= 5) ? argv[4] : NULL;
ret = wimlib_open_wim(src_wimfile,
- open_flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &src_w,
+ open_flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &src_wim,
imagex_progress_func);
- if (ret != 0)
- return ret;
+ if (ret)
+ goto out;
/* Determine if the destination is an existing file or not.
* If so, we try to append the exported image(s) to it; otherwise, we
imagex_error(T("\"%"TS"\" is not a regular file"),
dest_wimfile);
ret = -1;
- goto out;
+ goto out_free_src_wim;
}
ret = wimlib_open_wim(dest_wimfile, open_flags | WIMLIB_OPEN_FLAG_WRITE_ACCESS,
- &dest_w, imagex_progress_func);
- if (ret != 0)
- goto out;
+ &dest_wim, imagex_progress_func);
+ if (ret)
+ goto out_free_src_wim;
- dest_ctype = wimlib_get_compression_type(dest_w);
- if (compression_type_specified
- && compression_type != dest_ctype)
- {
+ dest_ctype = wimlib_get_compression_type(dest_wim);
+ if (compression_type_specified && compression_type != dest_ctype) {
imagex_error(T("Cannot specify a compression type that is "
"not the same as that used in the "
"destination WIM"));
ret = -1;
- goto out;
+ goto out_free_dest_wim;
}
} else {
- wim_is_new = true;
/* dest_wimfile is not an existing file, so create a new WIM. */
- if (!compression_type_specified)
- compression_type = wimlib_get_compression_type(src_w);
if (errno == ENOENT) {
- ret = wimlib_create_new_wim(compression_type, &dest_w);
- if (ret != 0)
- goto out;
+ wim_is_new = true;
+ if (!compression_type_specified)
+ compression_type = wimlib_get_compression_type(src_wim);
+ ret = wimlib_create_new_wim(compression_type, &dest_wim);
+ if (ret)
+ goto out_free_src_wim;
} else {
imagex_error_with_errno(T("Cannot stat file \"%"TS"\""),
dest_wimfile);
ret = -1;
- goto out;
+ goto out_free_src_wim;
}
}
- image = wimlib_resolve_image(src_w, src_image_num_or_name);
+ image = wimlib_resolve_image(src_wim, src_image_num_or_name);
ret = verify_image_exists(image, src_image_num_or_name, src_wimfile);
- if (ret != 0)
- goto out;
+ if (ret)
+ goto out_free_dest_wim;
if (swm_glob) {
ret = open_swms_from_glob(swm_glob, src_wimfile, open_flags,
&additional_swms,
&num_additional_swms);
- if (ret != 0)
- goto out;
+ if (ret)
+ goto out_free_dest_wim;
}
- ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
+ ret = wimlib_export_image(src_wim, image, dest_wim, dest_name, dest_desc,
export_flags, additional_swms,
num_additional_swms, imagex_progress_func);
- if (ret != 0)
- goto out;
+ if (ret)
+ goto out_free_swms;
if (wim_is_new)
- ret = wimlib_write(dest_w, dest_wimfile, WIMLIB_ALL_IMAGES,
+ ret = wimlib_write(dest_wim, dest_wimfile, WIMLIB_ALL_IMAGES,
write_flags, num_threads,
imagex_progress_func);
else
- ret = wimlib_overwrite(dest_w, write_flags, num_threads,
+ ret = wimlib_overwrite(dest_wim, write_flags, num_threads,
imagex_progress_func);
-out:
- wimlib_free(src_w);
- wimlib_free(dest_w);
+out_free_swms:
if (additional_swms) {
for (unsigned i = 0; i < num_additional_swms; i++)
wimlib_free(additional_swms[i]);
free(additional_swms);
}
+out_free_dest_wim:
+ wimlib_free(dest_wim);
+out_free_src_wim:
+ wimlib_free(src_wim);
+out:
return ret;
+
+out_usage:
+ usage(EXPORT);
+out_err:
+ ret = -1;
+ goto out;
}
static bool
cmds = prepare_extract_commands(argv, argc, extract_flags, dest_dir,
&num_cmds);
- if (!cmds) {
- ret = -1;
- goto out;
- }
+ if (!cmds)
+ goto out_err;
ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
if (ret)
free_extract_commands(cmds, num_cmds, dest_dir);
out:
return ret;
+
out_usage:
usage(EXTRACT);
+out_err:
ret = -1;
goto out;
}
+static void print_byte_field(const uint8_t field[], size_t len)
+{
+ while (len--)
+ tprintf(T("%02hhx"), *field++);
+}
+
+static void
+print_wim_information(const tchar *wimfile, const struct wimlib_wim_info *info)
+{
+ tputs(T("WIM Information:"));
+ tputs(T("----------------"));
+ tprintf(T("Path: %"TS"\n"), wimfile);
+ tprintf(T("GUID: 0x"));
+ print_byte_field(info->guid, sizeof(info->guid));
+ tputchar(T('\n'));
+ tprintf(T("Image Count: %d\n"), info->image_count);
+ tprintf(T("Compression: %"TS"\n"),
+ wimlib_get_compression_type_string(info->compression_type));
+ tprintf(T("Part Number: %d/%d\n"), info->part_number, info->total_parts);
+ tprintf(T("Boot Index: %d\n"), info->boot_index);
+ tprintf(T("Size: %"PRIu64" bytes\n"), info->total_bytes);
+ tprintf(T("Integrity Info: %"TS"\n"),
+ info->has_integrity_table ? T("yes") : T("no"));
+ tprintf(T("Relative path junction: %"TS"\n"),
+ info->has_rpfix ? T("yes") : T("no"));
+ tputchar(T('\n'));
+}
+
+static int
+print_resource(const struct wimlib_resource_entry *resource,
+ void *_ignore)
+{
+
+ tprintf(T("Uncompressed size = %"PRIu64" bytes\n"),
+ resource->uncompressed_size);
+
+ tprintf(T("Compressed size = %"PRIu64" bytes\n"),
+ resource->compressed_size);
+
+ tprintf(T("Offset = %"PRIu64" bytes\n"),
+ resource->offset);
+
+
+ tprintf(T("Part Number = %u\n"), resource->part_number);
+ tprintf(T("Reference Count = %u\n"), resource->reference_count);
+
+ tprintf(T("Hash = 0x"));
+ print_byte_field(resource->sha1_hash, sizeof(resource->sha1_hash));
+ tputchar(T('\n'));
+
+ tprintf(T("Flags = "));
+ if (resource->is_compressed)
+ tprintf(T("WIM_RESHDR_FLAG_COMPRESSED "));
+ if (resource->is_metadata)
+ tprintf(T("WIM_RESHDR_FLAG_METADATA "));
+ if (resource->is_free)
+ tprintf(T("WIM_RESHDR_FLAG_FREE "));
+ if (resource->is_spanned)
+ tprintf(T("WIM_RESHDR_FLAG_SPANNED "));
+ tputchar(T('\n'));
+ tputchar(T('\n'));
+ return 0;
+}
+
+static void
+print_lookup_table(WIMStruct *wim)
+{
+ wimlib_iterate_lookup_table(wim, 0, print_resource, NULL);
+}
+
/* Prints information about a WIM file; also can mark an image as bootable,
* change the name of an image, or change the description of an image. */
static int
int image;
int ret;
int open_flags = WIMLIB_OPEN_FLAG_SPLIT_OK;
- int part_number;
- int total_parts;
- int num_images;
+ struct wimlib_wim_info info;
for_opt(c, info_options) {
switch (c) {
if (ret != 0)
return ret;
- part_number = wimlib_get_part_number(w, &total_parts);
+ wimlib_get_wim_info(w, &info);
image = wimlib_resolve_image(w, image_num_or_name);
if (image == WIMLIB_NO_IMAGE && tstrcmp(image_num_or_name, T("0"))) {
goto out;
}
- num_images = wimlib_get_num_images(w);
-
- if (num_images == 0) {
+ if (info.image_count == 0) {
if (boot) {
imagex_error(T("--boot is meaningless on a WIM with no "
"images"));
}
}
- if (image == WIMLIB_ALL_IMAGES && num_images > 1) {
+ if (image == WIMLIB_ALL_IMAGES && info.image_count > 1) {
if (boot) {
imagex_error(T("Cannot specify the --boot flag "
"without specifying a specific "
}
if (image == WIMLIB_ALL_IMAGES && short_header)
- wimlib_print_wim_information(w);
+ print_wim_information(wimfile, &info);
if (header)
wimlib_print_header(w);
if (lookup_table) {
- if (total_parts != 1) {
- tprintf(T("Warning: Only showing the lookup table "
- "for part %d of a %d-part WIM.\n"),
- part_number, total_parts);
+ if (info.total_parts != 1) {
+ tfprintf(stderr, T("Warning: Only showing the lookup table "
+ "for part %d of a %d-part WIM.\n"),
+ info.part_number, info.total_parts);
}
- wimlib_print_lookup_table(w);
+ print_lookup_table(w);
}
if (xml) {
} else {
tprintf(T("Marking image %d as bootable.\n"),
image);
- ret = wimlib_set_boot_idx(w, image);
+ info.boot_index = image;
+ ret = wimlib_set_wim_info(w, &info, WIMLIB_CHANGE_BOOT_INDEX);
if (ret)
goto out;
}