-
-static int dentry_set_unextracted(struct dentry *dentry, void *ignore)
-{
- dentry->is_extracted = false;
- return 0;
-}
-
-static int do_wim_apply_image_ntfs(WIMStruct *w, const char *device, int extract_flags)
-{
- ntfs_volume *vol;
- int ret;
- struct dentry *root;
- struct ntfs_apply_args args;
-
- DEBUG("Mounting NTFS volume `%s'", device);
- vol = ntfs_mount(device, 0);
- if (!vol) {
- ERROR_WITH_ERRNO("Failed to mount NTFS volume `%s'", device);
- return WIMLIB_ERR_NTFS_3G;
- }
- args.vol = vol;
- args.extract_flags = extract_flags;
- args.w = w;
- root = wim_root_dentry(w);
-
- for_dentry_in_tree(root, dentry_set_unextracted, NULL);
- ret = for_dentry_in_tree(root, wim_apply_dentry_ntfs, &args);
- if (ret != 0)
- goto out;
-
- if (extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE)
- printf("Setting timestamps of extracted files on NTFS "
- "volume `%s'\n", device);
- ret = for_dentry_in_tree_depth(root, wim_apply_dentry_timestamps,
- &args);
-
- if (ret == 0 && (extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE))
- printf("Finished applying image %d of %s to NTFS "
- "volume `%s'\n",
- w->current_image,
- w->filename ? w->filename : "WIM",
- device);
-out:
- DEBUG("Unmounting NTFS volume `%s'", device);
- if (ntfs_umount(vol, FALSE) != 0) {
- ERROR_WITH_ERRNO("Failed to unmount NTFS volume `%s'", device);
- if (ret == 0)
- ret = WIMLIB_ERR_NTFS_3G;
- }
- return ret;
-}
-
-
-/*
- * API entry point for applying a WIM image to a NTFS volume.
- *
- * Please note that this is a NTFS *volume* and not a directory. The intention
- * is that the volume contain an empty filesystem, and the WIM image contain a
- * full filesystem to be applied to the volume.
- */
-WIMLIBAPI int wimlib_apply_image_to_ntfs_volume(WIMStruct *w, int image,
- const char *device, int flags,
- WIMStruct **additional_swms,
- unsigned num_additional_swms)
-{
- struct lookup_table *joined_tab, *w_tab_save;
- int ret;
-
- DEBUG("w->filename = %s, image = %d, device = %s, flags = 0x%x, "
- "num_additional_swms = %u",
- w->filename, image, device, flags, num_additional_swms);
-
- if (!w || !device)
- return WIMLIB_ERR_INVALID_PARAM;
- if (image == WIM_ALL_IMAGES) {
- ERROR("Can only apply a single image when applying "
- "directly to a NTFS volume");
- return WIMLIB_ERR_INVALID_PARAM;
- }
- if (flags & (WIMLIB_EXTRACT_FLAG_SYMLINK | WIMLIB_EXTRACT_FLAG_HARDLINK)) {
- ERROR("Cannot specify symlink or hardlink flags when applying ");
- ERROR("directly to a NTFS volume");
- return WIMLIB_ERR_INVALID_PARAM;
- }
-
- ret = verify_swm_set(w, additional_swms, num_additional_swms);
- if (ret != 0)
- return ret;
-
- if (num_additional_swms) {
- ret = new_joined_lookup_table(w, additional_swms,
- num_additional_swms, &joined_tab);
- if (ret != 0)
- return ret;
- w_tab_save = w->lookup_table;
- w->lookup_table = joined_tab;
- }
-
- ret = wimlib_select_image(w, image);
- if (ret != 0)
- goto out;
-
- ret = do_wim_apply_image_ntfs(w, device, flags);
-
-out:
- if (num_additional_swms) {
- free_lookup_table(w->lookup_table);
- w->lookup_table = w_tab_save;
- }
- return ret;
-}
-
-#else /* WITH_NTFS_3G */
-WIMLIBAPI int wimlib_apply_image_to_ntfs_volume(WIMStruct *w, int image,
- const char *device, int flags,
- WIMStruct **additional_swms,
- unsigned num_additional_swms)
-{
- ERROR("wimlib was compiled without support for NTFS-3g, so");
- ERROR("we cannot apply a WIM image directly to a NTFS volume");
- return WIMLIB_ERR_UNSUPPORTED;
-}
-#endif /* WITH_NTFS_3G */