4 * This is a "minimal" program to apply an image from a stand-alone WIM file.
5 * It's intended to be statically linked to the WIM library to create a small
6 * executable containing only the functions needed to apply a WIM file.
8 * This is not installed by default since the 'apply' subcommand of 'imagex'
9 * covers all this functionality and more.
11 * Compile with something like:
13 * $ ./configure --without-fuse --disable-error-messages \
14 * --disable-assertions --disable-custom-memory-allocator
16 * $ gcc -O2 -fwhole-program -flto -s wimapply.c -o wimapply \
17 * ../src/*.c -I/usr/include/libxml2 -I.. -D_FILE_OFFSET_BITS=64 \
18 * -D_GNU_SOURCE -std=gnu99 -lxml2 -lcrypto -lpthread -lntfs-3g
19 * $ stat -c %s wimapply
23 * $ stat -c %s /usr/lib/libwim.so.1.0.0
25 * $ stat -c %s /usr/bin/imagex
29 * $ wimapply install.wim 5 /dev/sda2
39 int main(int argc, char **argv)
42 const char *image_num;
48 int extract_flags = WIMLIB_EXTRACT_FLAG_SEQUENTIAL;
51 fprintf(stderr, "Usage: wimapply WIMFILE IMAGE_NUM TARGET\n");
59 image = atoi(image_num);
61 ret = stat(target, &stbuf);
63 fprintf(stderr, "Cannot stat `%s': %s\n",
64 target, strerror(errno));
68 if (!S_ISDIR(stbuf.st_mode))
69 extract_flags |= WIMLIB_EXTRACT_FLAG_NTFS;
71 ret = wimlib_open_wim(wimfile, 0, &w, NULL);
73 fprintf(stderr, "Failed to open `%s'!\n", wimfile);
74 fprintf(stderr, "Error code: %s\n", wimlib_get_error_string(ret));
78 ret = wimlib_extract_image(w, image, target,
79 WIMLIB_EXTRACT_FLAG_SEQUENTIAL,
82 fputs("Failed to apply WIM image\n", stderr);
83 fprintf(stderr, "Error code: %s\n", wimlib_get_error_string(ret));
86 /* Not calling wimlib_free() because the process is ending anyway. */