X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fsplit.c;h=4167ecdfdb59648676f6d242f1bd87f9c7ebabe9;hb=6f72d2a3e264460898eedbbf99c132f34441b98f;hp=8370ab3b30a30b136b9ebc7119cec100f1c10691;hpb=db046c7191d39535dfb49e9b9bdfc0751a8c17b4;p=wimlib diff --git a/src/split.c b/src/split.c index 8370ab3b..4167ecdf 100644 --- a/src/split.c +++ b/src/split.c @@ -10,16 +10,16 @@ * This file is part of wimlib, a library for working with WIM files. * * wimlib 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 2.1 of the License, or (at your option) + * 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 Lesser General Public License for more + * A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * - * You should have received a copy of the GNU Lesser General Public License + * You should have received a copy of the GNU General Public License * along with wimlib; if not, see http://www.gnu.org/licenses/. */ @@ -28,7 +28,7 @@ #include "xml.h" #include "io.h" -struct args { +struct split_args { WIMStruct *w; char *swm_base_name; size_t swm_base_name_len; @@ -49,12 +49,10 @@ static int finish_swm(WIMStruct *w, struct lookup_table_entry *lte_chain_head, off_t lookup_table_offset = ftello(w->out_fp); int ret; - DEBUG("Writing lookup table for SWM (offset %"PRIu64")", + DEBUG("Writing lookup table for SWM (offset %"PRIu64")", lookup_table_offset); while (lte_chain_head != NULL) { - print_lookup_table_entry(lte_chain_head); - ret = write_lookup_table_entry(lte_chain_head, w->out_fp); if (ret != 0) return ret; @@ -67,22 +65,15 @@ static int finish_swm(WIMStruct *w, struct lookup_table_entry *lte_chain_head, if (lookup_table_offset == -1 || xml_data_offset == -1) return WIMLIB_ERR_WRITE; w->hdr.lookup_table_res_entry.offset = lookup_table_offset; - w->hdr.lookup_table_res_entry.size = + w->hdr.lookup_table_res_entry.size = xml_data_offset - lookup_table_offset; - ret = finish_write(w, WIM_ALL_IMAGES, write_flags, 0); - if (ret != 0) - return ret; - - ret = fclose(w->out_fp); - if (ret != 0) - ret = WIMLIB_ERR_WRITE; - w->out_fp = NULL; - return ret; + return finish_write(w, WIM_ALL_IMAGES, + write_flags | WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE); } static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) { - struct args *args = (struct args*)__args; + struct split_args *args = (struct split_args*)__args; WIMStruct *w = args->w; int ret; @@ -90,7 +81,7 @@ static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) if (lte->resource_entry.flags & WIM_RESHDR_FLAG_METADATA) return 0; - if (args->size_remaining < 0 || + if (args->size_remaining < 0 || (u64)args->size_remaining < lte->resource_entry.size) { /* No space for this resource. Finish the previous swm and @@ -101,16 +92,15 @@ static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) args->lte_chain_tail = NULL; args->lte_chain_head = NULL; - sprintf(args->swm_base_name + args->swm_base_name_len, "%d", - ++args->part_number); - strcat(args->swm_base_name, args->swm_suffix); + sprintf(args->swm_base_name + args->swm_base_name_len, "%d%s", + ++args->part_number, args->swm_suffix); w->hdr.part_number = args->part_number; if (args->write_flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS) printf("Writing `%s' (%"PRIu64" of %"PRIu64" bytes, " - "%.0f%% done)\n", - args->swm_base_name, + "%.0f%% done)\n", + args->swm_base_name, args->total_bytes_written, args->total_bytes, (double)args->total_bytes_written / @@ -133,7 +123,7 @@ static int copy_resource_to_swm(struct lookup_table_entry *lte, void *__args) /* Splits the WIM file @wimfile into multiple parts prefixed by @swm_name with * size at most @part_size. */ -WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, +WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, size_t part_size, int flags) { int ret; @@ -179,8 +169,8 @@ WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, } if (write_flags & WIMLIB_OPEN_FLAG_SHOW_PROGRESS) - printf("Writing `%s' (%.2f %% done)\n", - swm_name, + printf("Writing `%s' (%.2f %% done)\n", + swm_name, (double)total_bytes_written / (double)total_bytes * 100.0); @@ -204,7 +194,7 @@ WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, } w->write_metadata = false; - struct args args = { + struct split_args args = { .w = w, .swm_base_name = name, .swm_base_name_len = swm_base_name_len, @@ -250,7 +240,7 @@ WIMLIBAPI int wimlib_split(const char *wimfile, const char *swm_name, put_u16(&buf[0], i); put_u16(&buf[2], total_parts); - if (fseek(fp, 40, SEEK_SET) != 0 || + if (fseek(fp, 40, SEEK_SET) != 0 || fwrite(buf, 1, sizeof(buf), fp) != sizeof(buf) || fclose(fp) != 0) { ERROR_WITH_ERRNO("Error overwriting header of `%s'",