X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsplit.c;h=5b14b924771451fd7c683ff4176209a60857750a;hb=e5c13f94058aedcea95236a9728093fa283d49b3;hp=a24ac4b4c424329482c7c9a215a21741e2cb3aa4;hpb=f3e97b29c4a8c564d54b0fd11cd43a9b4cd6a8ad;p=wimlib diff --git a/src/split.c b/src/split.c index a24ac4b4..5b14b924 100644 --- a/src/split.c +++ b/src/split.c @@ -27,6 +27,8 @@ #include "lookup_table.h" #include "xml.h" #include "buffer_io.h" +#include +#include struct split_args { WIMStruct *w; @@ -46,26 +48,12 @@ static int finish_swm(WIMStruct *w, struct list_head *lte_list, int write_flags, wimlib_progress_func_t progress_func) { - off_t lookup_table_offset = ftello(w->out_fp); int ret; - struct wim_lookup_table_entry *lte; - list_for_each_entry(lte, lte_list, swm_stream_list) { - ret = write_lookup_table_entry(lte, w->out_fp); - if (ret) - return ret; - } - - off_t xml_data_offset = ftello(w->out_fp); - - 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 = - xml_data_offset - lookup_table_offset; - w->hdr.lookup_table_res_entry.original_size = - xml_data_offset - lookup_table_offset; - w->hdr.lookup_table_res_entry.flags = WIM_RESHDR_FLAG_METADATA; + ret = write_lookup_table_from_stream_list(lte_list, w->out_fd, + &w->hdr.lookup_table_res_entry); + if (ret) + return ret; return finish_write(w, WIMLIB_ALL_IMAGES, write_flags | WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE, progress_func); @@ -145,6 +133,10 @@ wimlib_split(WIMStruct *w, const tchar *swm_name, write_flags &= WIMLIB_WRITE_MASK_PUBLIC; + ret = wim_checksum_unhashed_streams(w); + if (ret) + return ret; + swm_name_len = tstrlen(swm_name); tchar swm_base_name[swm_name_len + 20]; @@ -221,6 +213,10 @@ wimlib_split(WIMStruct *w, const tchar *swm_name, int total_parts = args.cur_part_number; for (int i = 1; i <= total_parts; i++) { const tchar *part_name; + int part_fd; + u8 part_data_buf[4]; + size_t bytes_written; + if (i == 1) { part_name = swm_name; } else { @@ -229,26 +225,26 @@ wimlib_split(WIMStruct *w, const tchar *swm_name, part_name = swm_base_name; } - FILE *fp = tfopen(part_name, T("r+b")); - if (!fp) { + part_fd = topen(part_name, O_WRONLY | O_BINARY); + if (part_fd == -1) { ERROR_WITH_ERRNO("Failed to open `%"TS"'", part_name); ret = WIMLIB_ERR_OPEN; goto out; } - u8 buf[4]; - put_u16(&buf[0], i); - put_u16(&buf[2], total_parts); - - 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 `%"TS"'", + put_u16(&part_data_buf[0], i); + put_u16(&part_data_buf[2], total_parts); + + bytes_written = full_pwrite(part_fd, part_data_buf, + sizeof(part_data_buf), 40); + ret = close(part_fd); + if (bytes_written != sizeof(part_data_buf) || ret != 0) { + ERROR_WITH_ERRNO("Error updating header of `%"TS"'", part_name); ret = WIMLIB_ERR_WRITE; - break; + goto out; } } + ret = 0; out: close_wim_writable(w); memcpy(&w->hdr, &hdr_save, sizeof(struct wim_header));