X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fsplit.c;h=51c4a91066b905ca722faacc95bcbbed27b76dea;hb=98ba860071982607f705cca55648ba1cb5005855;hp=01bb75fc817f5ba3f211b659252e61c7c5750bf5;hpb=26c7f8bb32e4a32001d409f1693e0df016270ed5;p=wimlib diff --git a/src/split.c b/src/split.c index 01bb75fc..51c4a910 100644 --- a/src/split.c +++ b/src/split.c @@ -7,20 +7,18 @@ /* * Copyright (C) 2012, 2013 Eric Biggers * - * This file is part of wimlib, a library for working with WIM files. + * This file is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. * - * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * - * You should have received a copy of the GNU General Public License - * along with wimlib; if not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License + * along with this file; if not, see http://www.gnu.org/licenses/. */ #ifdef HAVE_CONFIG_H @@ -28,20 +26,16 @@ #endif #include "wimlib.h" +#include "wimlib/alloca.h" #include "wimlib/error.h" #include "wimlib/list.h" #include "wimlib/lookup_table.h" #include "wimlib/metadata.h" +#include "wimlib/progress.h" #include "wimlib/resource.h" #include "wimlib/wim.h" #include "wimlib/write.h" -#ifdef HAVE_ALLOCA_H -# include -#else -# include -#endif - struct swm_part_info { struct list_head stream_list; u64 size; @@ -64,8 +58,7 @@ struct swm_info { static int write_split_wim(WIMStruct *orig_wim, const tchar *swm_name, - struct swm_info *swm_info, int write_flags, - wimlib_progress_func_t progress_func) + struct swm_info *swm_info, int write_flags) { size_t swm_name_len; tchar *swm_name_buf; @@ -97,12 +90,12 @@ write_split_wim(WIMStruct *orig_wim, const tchar *swm_name, for (part_number = 1; part_number <= swm_info->num_parts; part_number++) progress.split.total_bytes += swm_info->parts[part_number - 1].size; progress.split.total_parts = swm_info->num_parts; - progress.split.part_name = swm_name_buf; randomize_byte_array(guid, WIMLIB_GUID_LEN); for (part_number = 1; part_number <= swm_info->num_parts; part_number++) { int part_write_flags; + wimlib_progress_func_t progfunc; if (part_number != 1) { tsprintf(swm_name_buf + swm_base_name_len, @@ -110,34 +103,43 @@ write_split_wim(WIMStruct *orig_wim, const tchar *swm_name, } progress.split.cur_part_number = part_number; - if (progress_func) { - progress_func(WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART, - &progress); - } + progress.split.part_name = swm_name_buf; + + ret = call_progress(orig_wim->progfunc, + WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART, + &progress, + orig_wim->progctx); + if (ret) + return ret; - part_write_flags = write_flags & WIMLIB_WRITE_MASK_PUBLIC; + part_write_flags = write_flags; part_write_flags |= WIMLIB_WRITE_FLAG_USE_EXISTING_TOTALBYTES; if (part_number != 1) part_write_flags |= WIMLIB_WRITE_FLAG_NO_METADATA; + progfunc = orig_wim->progfunc; + orig_wim->progfunc = NULL; ret = write_wim_part(orig_wim, - swm_name_buf, + progress.split.part_name, WIMLIB_ALL_IMAGES, part_write_flags, 1, - NULL, part_number, swm_info->num_parts, &swm_info->parts[part_number - 1].stream_list, guid); + orig_wim->progfunc = progfunc; if (ret) return ret; progress.split.completed_bytes += swm_info->parts[part_number - 1].size; - if (progress_func) { - progress_func(WIMLIB_PROGRESS_MSG_SPLIT_END_PART, - &progress); - } + + ret = call_progress(orig_wim->progfunc, + WIMLIB_PROGRESS_MSG_SPLIT_END_PART, + &progress, + orig_wim->progctx); + if (ret) + return ret; } return 0; } @@ -148,10 +150,12 @@ add_stream_to_swm(struct wim_lookup_table_entry *lte, void *_swm_info) struct swm_info *swm_info = _swm_info; u64 stream_size; - /* We want the compressed size of the stream, but use the uncompressed - * size if the compressed size is not available or not relevant. */ - if (lte->resource_location == RESOURCE_IN_WIM && - (!lte_is_partial(lte) || lte->rspec->size_in_wim < lte->size)) + if (lte_is_partial(lte)) { + ERROR("Splitting of WIM containing solid resources is not supported.\n" + " Export it in non-solid format first."); + return WIMLIB_ERR_UNSUPPORTED; + } + if (lte->resource_location == RESOURCE_IN_WIM) stream_size = lte->rspec->size_in_wim; else stream_size = lte->size; @@ -199,8 +203,7 @@ add_stream_to_swm(struct wim_lookup_table_entry *lte, void *_swm_info) /* API function documented in wimlib.h */ WIMLIBAPI int wimlib_split(WIMStruct *wim, const tchar *swm_name, - u64 part_size, int write_flags, - wimlib_progress_func_t progress_func) + u64 part_size, int write_flags) { struct swm_info swm_info; unsigned i; @@ -209,6 +212,9 @@ wimlib_split(WIMStruct *wim, const tchar *swm_name, if (swm_name == NULL || swm_name[0] == T('\0') || part_size == 0) return WIMLIB_ERR_INVALID_PARAM; + if (write_flags & ~WIMLIB_WRITE_MASK_PUBLIC) + return WIMLIB_ERR_INVALID_PARAM; + if (!wim_has_metadata(wim)) return WIMLIB_ERR_METADATA_NOT_FOUND; @@ -228,8 +234,7 @@ wimlib_split(WIMStruct *wim, const tchar *swm_name, if (ret) goto out_free_swm_info; - ret = write_split_wim(wim, swm_name, &swm_info, write_flags, - progress_func); + ret = write_split_wim(wim, swm_name, &swm_info, write_flags); out_free_swm_info: FREE(swm_info.parts); return ret;