X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fexport_image.c;h=34b92422c1aabafb25e156034c6c784df2f6c0c3;hb=c0a64271ae792a19b7ed584f8e3da4a70f58c691;hp=bfeef97ad6b41afc83970afd6315f072e991c4d3;hpb=11db44d91c4023f322a8fdb09f8ec5eddce2dab8;p=wimlib diff --git a/src/export_image.c b/src/export_image.c index bfeef97a..34b92422 100644 --- a/src/export_image.c +++ b/src/export_image.c @@ -36,8 +36,9 @@ static int inode_export_streams(struct wim_inode *inode, - const struct wim_lookup_table *src_lookup_table, - struct wim_lookup_table *dest_lookup_table) + struct wim_lookup_table *src_lookup_table, + struct wim_lookup_table *dest_lookup_table, + bool gift) { unsigned i; const u8 *hash; @@ -62,9 +63,14 @@ inode_export_streams(struct wim_inode *inode, if (!src_lte) return stream_not_found_error(inode, hash); - dest_lte = clone_lookup_table_entry(src_lte); - if (!dest_lte) - return WIMLIB_ERR_NOMEM; + if (gift) { + dest_lte = src_lte; + lookup_table_unlink(src_lookup_table, src_lte); + } else { + dest_lte = clone_lookup_table_entry(src_lte); + if (!dest_lte) + return WIMLIB_ERR_NOMEM; + } dest_lte->refcnt = 0; dest_lte->out_refcnt = 0; lookup_table_insert(dest_lookup_table, dest_lte); @@ -87,10 +93,12 @@ lte_unexport(struct wim_lookup_table_entry *lte, void *_lookup_table) { struct wim_lookup_table *lookup_table = _lookup_table; - lte->refcnt -= lte->out_refcnt; - if (lte->refcnt == 0) { - lookup_table_unlink(lookup_table, lte); - free_lookup_table_entry(lte); + if (lte->out_refcnt) { + lte->refcnt -= lte->out_refcnt; + if (lte->refcnt == 0) { + lookup_table_unlink(lookup_table, lte); + free_lookup_table_entry(lte); + } } return 0; } @@ -102,8 +110,7 @@ wimlib_export_image(WIMStruct *src_wim, WIMStruct *dest_wim, const tchar *dest_name, const tchar *dest_description, - int export_flags, - wimlib_progress_func_t progress_func) + int export_flags) { int ret; int start_image; @@ -115,7 +122,9 @@ wimlib_export_image(WIMStruct *src_wim, /* Check for sane parameters. */ if (export_flags & ~(WIMLIB_EXPORT_FLAG_BOOT | WIMLIB_EXPORT_FLAG_NO_NAMES | - WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS)) + WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS | + WIMLIB_EXPORT_FLAG_GIFT | + WIMLIB_EXPORT_FLAG_WIMBOOT)) return WIMLIB_ERR_INVALID_PARAM; if (src_wim == NULL || dest_wim == NULL) @@ -220,7 +229,8 @@ wimlib_export_image(WIMStruct *src_wim, image_for_each_inode(inode, src_imd) { ret = inode_export_streams(inode, src_wim->lookup_table, - dest_wim->lookup_table); + dest_wim->lookup_table, + export_flags & WIMLIB_EXPORT_FLAG_GIFT); if (ret) goto out_rollback; } @@ -253,11 +263,23 @@ wimlib_export_image(WIMStruct *src_wim, dest_wim->hdr.boot_idx = dest_wim->hdr.image_count; } + /* Possibly set WIMBoot flag */ + if (export_flags & WIMLIB_EXPORT_FLAG_WIMBOOT) { + wim_info_set_wimboot(dest_wim->wim_info, + dest_wim->hdr.image_count, + true); + } + } /* Set the reparse point fixup flag on the destination WIM if the flag * is set on the source WIM. */ if (src_wim->hdr.flags & WIM_HDR_FLAG_RP_FIX) dest_wim->hdr.flags |= WIM_HDR_FLAG_RP_FIX; + + if (export_flags & WIMLIB_EXPORT_FLAG_GIFT) { + free_lookup_table(src_wim->lookup_table); + src_wim->lookup_table = NULL; + } DEBUG("Export operation successful."); return 0;