-static int imagex_append(int argc, const char **argv)
-{
- int c;
- const char *flags_element = NULL;
- int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
- int add_image_flags = 0;
- int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
- const char *dir;
- const char *wimfile;
- const char *name;
- const char *desc;
- const char *config_file = NULL;
- const char *config_str = NULL;
- size_t config_len = 0;
- WIMStruct *w;
- int ret;
- int cur_image;
-
- for_opt(c, append_options) {
- switch (c) {
- case 'b':
- add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
- break;
- case 'c':
- open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
- write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
- break;
- case 'C':
- config_file = optarg;
- break;
- case 'f':
- flags_element = optarg;
- break;
- case 'L':
- add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE;
- break;
- case 'v':
- add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_VERBOSE;
- break;
- default:
- usage(APPEND);
- return -1;
- }
- }
- argc -= optind;
- argv += optind;
- if (argc < 2 || argc > 4) {
- usage(APPEND);
- return -1;
- }
- dir = argv[0];
- wimfile = argv[1];
- name = (argc >= 3) ? argv[2] : path_basename(dir);
- desc = (argc >= 4) ? argv[3] : NULL;
-
- if (config_file) {
- config_str = file_get_contents(config_file, &config_len);
- if (!config_str)
- return -1;
- }
-
- ret = wimlib_open_wim(wimfile, open_flags, &w);
- if (ret != 0)
- return ret;
-
-#ifdef WITH_NTFS_3G
- struct stat stbuf;
-
- ret = stat(dir, &stbuf);
- if (ret == 0) {
- if (S_ISBLK(stbuf.st_mode) || S_ISREG(stbuf.st_mode)) {
- const char *ntfs_device = dir;
- printf("Capturing WIM image NTFS filesystem on `%s'\n",
- ntfs_device);
- ret = wimlib_add_image_from_ntfs_volume(w, ntfs_device,
- name,
- config_str,
- config_len,
- add_image_flags);
- goto out_write;
- }
- } else {
- if (errno != ENOENT)
- imagex_error_with_errno("Failed to stat `%s'", dir);
- }
-#endif
- ret = wimlib_add_image(w, dir, name, config_str, config_len,
- add_image_flags);
-
-out_write:
- if (ret != 0)
- goto out;
- cur_image = wimlib_get_num_images(w);
- if (desc) {
- ret = wimlib_set_image_descripton(w, cur_image, desc);
- if (ret != 0)
- goto out;
- }
- if (flags_element) {
- ret = wimlib_set_image_flags(w, cur_image, flags_element);
- if (ret != 0)
- goto out;
- }
- ret = wimlib_overwrite(w, write_flags);
-out:
- wimlib_free(w);
- return ret;
-}