- ret = finish_swm(w, &args.lte_list, write_flags, progress_func);
- if (ret)
- goto out;
-
- if (progress_func) {
- progress_func(WIMLIB_PROGRESS_MSG_SPLIT_END_PART,
- &args.progress);
- }
-
- /* The swms are all ready now, except the total_parts and part_number
- * fields in their headers are wrong (since we don't know the total
- * parts until they are all written). Fix them. */
- 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 {
- tsprintf(swm_base_name + swm_base_name_len, T("%d%"TS),
- i, swm_suffix);
- part_name = swm_base_name;
- }
-
- part_fd = topen(part_name, O_WRONLY | O_BINARY);
- if (part_fd == INVALID_FILEDES) {
- ERROR_WITH_ERRNO("Failed to open `%"TS"'", part_name);
- ret = WIMLIB_ERR_OPEN;
- goto out;
- }
- 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;
- goto out;
- }
- }
- ret = 0;
-out:
- close_wim_writable(w);
- memcpy(&w->hdr, &hdr_save, sizeof(struct wim_header));