X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=programs%2Fimagex.c;h=0d271e43eba4ea145a39d125b21c84bcd340c781;hp=1972505824766aaad8be23eb9b91d5175ff0dcbf;hb=09d5c7b390a18d5cc29a87853dce0c4681e8f153;hpb=2a33c303e30fd740f740e21632fd06b9e414b0c7 diff --git a/programs/imagex.c b/programs/imagex.c index 19725058..0d271e43 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef HAVE_ALLOCA_H #include @@ -73,52 +74,54 @@ enum imagex_op_type { static void usage(int cmd_type); static void usage_all(); + static const char *usage_strings[] = { [APPEND] = -"imagex append (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n" +IMAGEX_PROGNAME" append (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n" " [DESCRIPTION] [--boot] [--check] [--flags EDITION_ID]\n" " [--verbose] [--dereference] [--config=FILE]\n" " [--threads=NUM_THREADS] [--rebuild] [--unix-data]\n" -" [--source-list]\n", +" [--source-list] [--noacls]\n", [APPLY] = -"imagex apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all]\n" +IMAGEX_PROGNAME" apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all]\n" " (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n" -" [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n", +" [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n" +" [--noacls]\n", [CAPTURE] = -"imagex capture (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n" +IMAGEX_PROGNAME" capture (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n" " [DESCRIPTION] [--boot] [--check] [--compress=TYPE]\n" " [--flags EDITION_ID] [--verbose] [--dereference]\n" " [--config=FILE] [--threads=NUM_THREADS] [--unix-data]\n" -" [--source-list]\n", +" [--source-list] [--noacls]\n", [DELETE] = -"imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check] [--soft]\n", +IMAGEX_PROGNAME" delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check] [--soft]\n", [DIR] = -"imagex dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all)\n", +IMAGEX_PROGNAME" dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all)\n", [EXPORT] = -"imagex export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n" +IMAGEX_PROGNAME" export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n" " DEST_WIMFILE [DEST_IMAGE_NAME] [DEST_IMAGE_DESCRIPTION]\n" " [--boot] [--check] [--compress=TYPE] [--ref=\"GLOB\"]\n" " [--threads=NUM_THREADS] [--rebuild]\n", [INFO] = -"imagex info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n" +IMAGEX_PROGNAME" info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n" " [NEW_DESC] [--boot] [--check] [--header] [--lookup-table]\n" " [--xml] [--extract-xml FILE] [--metadata]\n", [JOIN] = -"imagex join [--check] WIMFILE SPLIT_WIM...\n", +IMAGEX_PROGNAME" join [--check] WIMFILE SPLIT_WIM...\n", [MOUNT] = -"imagex mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n" +IMAGEX_PROGNAME" mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n" " [--check] [--debug] [--streams-interface=INTERFACE]\n" " [--ref=\"GLOB\"] [--unix-data] [--allow-other]\n", [MOUNTRW] = -"imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n" +IMAGEX_PROGNAME" mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n" " [--check] [--debug] [--streams-interface=INTERFACE]\n" " [--staging-dir=DIR] [--unix-data] [--allow-other]\n", [OPTIMIZE] = -"imagex optimize WIMFILE [--check] [--recompress] [--compress=TYPE]\n", +IMAGEX_PROGNAME" optimize WIMFILE [--check] [--recompress] [--compress=TYPE]\n", [SPLIT] = -"imagex split WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n", +IMAGEX_PROGNAME" split WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n", [UNMOUNT] = -"imagex unmount DIRECTORY [--commit] [--check] [--rebuild]\n", +IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild]\n", }; static const struct option apply_options[] = { @@ -128,6 +131,7 @@ static const struct option apply_options[] = { {"verbose", no_argument, NULL, 'v'}, {"ref", required_argument, NULL, 'r'}, {"unix-data", no_argument, NULL, 'U'}, + {"noacls", no_argument, NULL, 'N'}, {NULL, 0, NULL, 0}, }; static const struct option capture_or_append_options[] = { @@ -142,6 +146,7 @@ static const struct option capture_or_append_options[] = { {"rebuild", no_argument, NULL, 'R'}, {"unix-data", no_argument, NULL, 'U'}, {"source-list", no_argument, NULL, 'S'}, + {"noacls", no_argument, NULL, 'N'}, {NULL, 0, NULL, 0}, }; static const struct option delete_options[] = { @@ -235,9 +240,9 @@ static int verify_image_exists(int image, const char *image_name, { if (image == WIMLIB_NO_IMAGE) { imagex_error("\"%s\" is not a valid image in `%s'!\n" - " Please specify a 1-based imagex index or " + " Please specify a 1-based image index or " "image name.\n" - " You may use `imagex info' to list the images " + " You may use `"IMAGEX_PROGNAME" info' to list the images " "contained in a WIM.", image_name, wim_name); return -1; @@ -353,9 +358,9 @@ enum { /* * Parses a filename in the source list file format. (See the man page for - * 'imagex capture' for details on this format and the meaning.) Accepted - * formats for filenames are an unquoted string (whitespace-delimited), or a - * double or single-quoted string. + * 'wimlib-imagex capture' for details on this format and the meaning.) + * Accepted formats for filenames are an unquoted string (whitespace-delimited), + * or a double or single-quoted string. * * @line_p: Pointer to the pointer to the line of data. Will be updated * to point past the filename iff the return value is @@ -418,8 +423,8 @@ static int parse_filename(char **line_p, size_t *len_p, char **fn_ret) } /* Parses a line of data (not an empty line or comment) in the source list file - * format. (See the man page for 'imagex capture' for details on this format - * and the meaning.) + * format. (See the man page for 'wimlib-imagex capture' for details on this + * format and the meaning.) * * @line: Line of data to be parsed. line[len - 1] must be '\0', unless * len == 0. The data in @line will be modified by this function call. @@ -462,8 +467,8 @@ static bool is_comment_line(const char *line, size_t len) } } -/* Parses a file in the source list format. (See the man page for 'imagex - * capture' for details on this format and the meaning.) +/* Parses a file in the source list format. (See the man page for + * 'wimlib-imagex capture' for details on this format and the meaning.) * * @source_list_contents: Contents of the source list file. Note that this * buffer will be modified to save memory allocations, @@ -839,6 +844,9 @@ static int imagex_apply(int argc, char **argv) case 'U': extract_flags |= WIMLIB_EXTRACT_FLAG_UNIX_DATA; break; + case 'N': + extract_flags |= WIMLIB_EXTRACT_FLAG_NOACLS; + break; default: usage(APPLY); return -1; @@ -900,11 +908,17 @@ static int imagex_apply(int argc, char **argv) } } +#ifdef __WIN32__ + win32_acquire_restore_privileges(); +#endif ret = wimlib_extract_image(w, image, target, extract_flags, additional_swms, num_additional_swms, imagex_progress_func); if (ret == 0) printf("Done applying WIM image.\n"); +#ifdef __WIN32__ + win32_release_restore_privileges(); +#endif out: wimlib_free(w); if (additional_swms) { @@ -916,8 +930,9 @@ out: } /* Create a WIM image from a directory tree, NTFS volume, or multiple files or - * directory trees. 'imagex capture': create a new WIM file containing the - * desired image. 'imagex append': add a new image to an existing WIM file. */ + * directory trees. 'wimlib-imagex capture': create a new WIM file containing + * the desired image. 'wimlib-imagex append': add a new image to an existing + * WIM file. */ static int imagex_capture_or_append(int argc, char **argv) { int c; @@ -990,6 +1005,9 @@ static int imagex_capture_or_append(int argc, char **argv) case 'S': source_list = true; break; + case 'N': + add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_NO_ACLS; + break; default: usage(cmd); return -1; @@ -1081,6 +1099,9 @@ static int imagex_capture_or_append(int argc, char **argv) } } } +#ifdef __WIN32__ + win32_acquire_capture_privileges(); +#endif ret = wimlib_add_image_multisource(w, capture_sources, num_sources, name, @@ -1091,17 +1112,17 @@ static int imagex_capture_or_append(int argc, char **argv) add_image_flags, imagex_progress_func); if (ret != 0) - goto out; + goto out_release_privs; cur_image = wimlib_get_num_images(w); if (desc) { ret = wimlib_set_image_descripton(w, cur_image, desc); if (ret != 0) - goto out; + goto out_release_privs; } if (flags_element) { ret = wimlib_set_image_flags(w, cur_image, flags_element); if (ret != 0) - goto out; + goto out_release_privs; } if (cmd == APPEND) { ret = wimlib_overwrite(w, write_flags, num_threads, @@ -1114,6 +1135,10 @@ static int imagex_capture_or_append(int argc, char **argv) ret = 0; if (ret != 0) imagex_error("Failed to write the WIM file `%s'", wimfile); +out_release_privs: +#ifdef __WIN32__ + win32_release_capture_privileges(); +#endif out: wimlib_free(w); free(config_str); @@ -2031,7 +2056,7 @@ static const struct imagex_command imagex_commands[] = { static void version() { static const char *s = - "imagex (" PACKAGE ") " PACKAGE_VERSION "\n" + IMAGEX_PROGNAME " (" PACKAGE ") " PACKAGE_VERSION "\n" "Copyright (C) 2012, 2013 Eric Biggers\n" "License GPLv3+; GNU GPL version 3 or later .\n" "This is free software: you are free to change and redistribute it.\n" @@ -2080,7 +2105,7 @@ static void usage(int cmd_type) printf("Usage: %s", usage_strings[cmd_type]); for_imagex_command(cmd) { if (cmd->cmd == cmd_type) - printf("\nTry `man imagex-%s' for more details.\n", + printf("\nTry `man "IMAGEX_PROGNAME"-%s' for more details.\n", cmd->name); } } @@ -2091,22 +2116,24 @@ static void usage_all() for (int i = 0; i < ARRAY_LEN(usage_strings); i++) printf(" %s", usage_strings[i]); static const char *extra = -" imagex --help\n" -" imagex --version\n" +" "IMAGEX_PROGNAME" --help\n" +" "IMAGEX_PROGNAME" --version\n" "\n" " The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n" "\n" -" Try `man imagex' for more information.\n" +" Try `man "IMAGEX_PROGNAME"' for more information.\n" ; fputs(extra, stdout); } -/* Entry point for the 'imagex' program. */ +/* Entry point for wimlib's ImageX implementation */ int main(int argc, char **argv) { const struct imagex_command *cmd; int ret; + setlocale(LC_ALL, ""); + if (argc < 2) { imagex_error("No command specified"); usage_all(); @@ -2122,13 +2149,12 @@ int main(int argc, char **argv) /* The user may like to see more informative error messages. */ wimlib_set_print_errors(true); - /* Calling wimlib_global_init() is not strictly necessary because - * 'imagex' is single-threaded. */ + /* Do any initializations that the library needs */ ret = wimlib_global_init(); if (ret) goto out; - /* Search for the function to handle the 'imagex' subcommand. */ + /* Search for the function to handle the ImageX subcommand. */ for_imagex_command(cmd) { if (strcmp(cmd->name, *argv) == 0) { ret = cmd->func(argc, argv); @@ -2140,9 +2166,9 @@ int main(int argc, char **argv) usage_all(); return 1; out_check_write_error: - /* For 'imagex info' and 'imagex dir', data printed to standard output - * is part of the program's actual behavior and not just for - * informational purposes, so we should set a failure exit status if + /* For 'wimlib-imagex info' and 'wimlib-imagex dir', data printed to + * standard output is part of the program's actual behavior and not just + * for informational purposes, so we should set a failure exit status if * there was a write error. */ if (cmd == &imagex_commands[INFO] || cmd == &imagex_commands[DIR]) { if (ferror(stdout) || fclose(stdout)) { @@ -2152,9 +2178,10 @@ out_check_write_error: } } out: - /* Exit status (ret): -1 indicates an error found by 'imagex' outside - * of the wimlib library code. 0 indicates success. > 0 indicates a - * wimlib error code from which an error message can be printed. */ + /* Exit status (ret): -1 indicates an error found by 'wimlib-imagex' + * outside of the wimlib library code. 0 indicates success. > 0 + * indicates a wimlib error code from which an error message can be + * printed. */ if (ret > 0) { imagex_error("Exiting with error code %d:\n" " %s.", ret, @@ -2162,8 +2189,9 @@ out: if (ret == WIMLIB_ERR_NTFS_3G && errno != 0) imagex_error_with_errno("errno"); } - /* Calling wimlib_global_cleanup() is not strictly necessary because the - * process is exiting anyway. */ + + /* Make the library free any resources it's holding (not strictly + * necessary because the process is ending anyway). */ wimlib_global_cleanup(); return ret; }