From fa61b94ac81588ee277b5c88b77e1121b32eb957 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sun, 22 Dec 2013 19:02:44 +0100 Subject: [PATCH] Consolidated the single copies of IsoWriteOpts members in Ecma119Image by having a copy of the whole IsoWriteOpts in Ecma119Image --- libisofs/ecma119.c | 369 ++++++++++++++++------------------ libisofs/ecma119.h | 124 +----------- libisofs/ecma119_tree.c | 82 ++++---- libisofs/eltorito.c | 10 +- libisofs/filesrc.c | 36 ++-- libisofs/hfsplus.c | 20 +- libisofs/iso1999.c | 12 +- libisofs/joliet.c | 40 ++-- libisofs/make_isohybrid_mbr.c | 2 +- libisofs/md5.c | 22 +- libisofs/rockridge.c | 46 ++--- libisofs/system_area.c | 94 +++++---- libisofs/util.c | 17 ++ libisofs/util.h | 9 + 14 files changed, 400 insertions(+), 483 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index a6cf556..78e05e4 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -56,6 +56,10 @@ #endif /* ! Xorriso_standalonE */ + +int iso_write_opts_clone(IsoWriteOpts *in, IsoWriteOpts **out, int flag); + + /* * TODO #00011 : guard against bad path table usage with more than 65535 dirs * image with more than 65535 directories have path_table related problems @@ -78,6 +82,8 @@ void ecma119_image_free(Ecma119Image *t) if (t->root != NULL) ecma119_node_free(t->root); + if (t->opts != NULL) + iso_write_opts_free(t->opts); if (t->image != NULL) iso_image_unref(t->image); if (t->files != NULL) @@ -90,8 +96,6 @@ void ecma119_image_free(Ecma119Image *t) writer->free_data(writer); free(writer); } - if (t->rr_reloc_dir != NULL) - free(t->rr_reloc_dir); if (t->input_charset != NULL) free(t->input_charset); if (t->output_charset != NULL) @@ -110,13 +114,6 @@ void ecma119_image_free(Ecma119Image *t) free(t->writers); if (t->partition_root != NULL) ecma119_node_free(t->partition_root); - if (t->prep_partition != NULL) - free(t->prep_partition); - if (t->efi_boot_partition != NULL) - free(t->efi_boot_partition); - for (i = 0; i < ISO_MAX_PARTITIONS; i++) - if (t->appended_partitions[i] != NULL) - free(t->appended_partitions[i]); for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) if (t->hfsplus_blessed[i] != NULL) iso_node_unref(t->hfsplus_blessed[i]); @@ -140,11 +137,11 @@ static int show_chunk_to_jte(Ecma119Image *target, char *buf, int count) int ret; - if (target->libjte_handle == NULL) + if (target->opts->libjte_handle == NULL) return ISO_SUCCESS; - ret = libjte_show_data_chunk(target->libjte_handle, buf, count, 1); + ret = libjte_show_data_chunk(target->opts->libjte_handle, buf, count, 1); if (ret <= 0) { - iso_libjte_forward_msgs(target->libjte_handle, + iso_libjte_forward_msgs(target->opts->libjte_handle, target->image->id, ISO_LIBJTE_FILE_FAILED, 0); return ISO_LIBJTE_FILE_FAILED; } @@ -160,7 +157,8 @@ static int show_chunk_to_jte(Ecma119Image *target, char *buf, int count) static int need_version_number(Ecma119Image *t, Ecma119Node *n) { - if ((t->omit_version_numbers & 1) || t->untranslated_name_len > 0) { + if ((t->opts->omit_version_numbers & 1) || + t->opts->max_37_char_filenames || t->opts->untranslated_name_len > 0) { return 0; } if (n->type == ECMA119_DIR || n->type == ECMA119_PLACEHOLDER) { @@ -206,7 +204,7 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce) /* size of "." and ".." entries */ len = 34 + 34; - if (t->rockridge) { + if (t->opts->rockridge) { len += rrip_calc_len(t, dir, 1, 34, &ce_len); *ce += ce_len; len += rrip_calc_len(t, dir, 2, 34, &ce_len); @@ -221,7 +219,7 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce) nsections = (child->type == ECMA119_FILE) ? child->info.file->nsections : 1; for (section = 0; section < nsections; ++section) { size_t dirent_len = calc_dirent_len(t, child); - if (t->rockridge) { + if (t->opts->rockridge) { dirent_len += rrip_calc_len(t, child, 0, dirent_len, &ce_len); *ce += ce_len; } @@ -257,7 +255,7 @@ void calc_dir_pos(Ecma119Image *t, Ecma119Node *dir) dir->info.dir->block = t->curblock; len = calc_dir_size(t, dir, &ce_len); t->curblock += DIV_UP(len, BLOCK_SIZE); - if (t->rockridge) { + if (t->opts->rockridge) { t->curblock += DIV_UP(ce_len, BLOCK_SIZE); } for (i = 0; i < dir->info.dir->nchildren; i++) { @@ -321,13 +319,13 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer) target->curblock += DIV_UP(path_table_size, BLOCK_SIZE); target->path_table_size = path_table_size; - if (target->md5_session_checksum) { + if (target->opts->md5_session_checksum) { /* Account for first tree checksum tag */ target->checksum_tree_tag_pos = target->curblock; target->curblock++; } - if (target->partition_offset > 0) { + if (target->opts->partition_offset > 0) { /* Take into respect the second directory tree */ ndirs = target->ndirs; target->ndirs = 0; @@ -406,7 +404,7 @@ void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id, * the content block address to a dummy value. */ len = 0; - if (! t->old_empty) + if (! t->opts->old_empty) block = t->empty_file_block; else block = 0; @@ -421,13 +419,13 @@ void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id, rec->len_dr[0] = len_dr + (info != NULL ? info->suf_len : 0); iso_bb(rec->block, block - t->eff_partition_offset, 4); iso_bb(rec->length, len, 4); - if (t->dir_rec_mtime & 1) { + if (t->opts->dir_rec_mtime & 1) { iso= node->node; iso_datetime_7(rec->recording_time, t->replace_timestamps ? t->timestamp : iso->mtime, - t->always_gmt); + t->opts->always_gmt); } else { - iso_datetime_7(rec->recording_time, t->now, t->always_gmt); + iso_datetime_7(rec->recording_time, t->now, t->opts->always_gmt); } rec->flags[0] = ((node->type == ECMA119_DIR) ? 2 : 0) | (multi_extend ? 0x80 : 0); iso_bb(rec->vol_seq_number, (uint32_t) 1, 2); @@ -469,50 +467,52 @@ void ecma119_set_voldescr_times(IsoImageWriter *writer, struct ecma119_pri_vol_desc *vol) { Ecma119Image *t = writer->target; + IsoWriteOpts *o; int i; - if (t->vol_uuid[0]) { + o = t->opts; + if (o->vol_uuid[0]) { for(i = 0; i < 16; i++) - if(t->vol_uuid[i] < '0' || t->vol_uuid[i] > '9') + if(o->vol_uuid[i] < '0' || o->vol_uuid[i] > '9') break; else - vol->vol_creation_time[i] = t->vol_uuid[i]; + vol->vol_creation_time[i] = o->vol_uuid[i]; for(; i < 16; i++) vol->vol_creation_time[i] = '1'; vol->vol_creation_time[16] = 0; - } else if (t->vol_creation_time > 0) - iso_datetime_17(vol->vol_creation_time, t->vol_creation_time, - t->always_gmt); + } else if (o->vol_creation_time > 0) + iso_datetime_17(vol->vol_creation_time, o->vol_creation_time, + o->always_gmt); else - iso_datetime_17(vol->vol_creation_time, t->now, t->always_gmt); + iso_datetime_17(vol->vol_creation_time, t->now, o->always_gmt); - if (t->vol_uuid[0]) { + if (o->vol_uuid[0]) { for(i = 0; i < 16; i++) - if(t->vol_uuid[i] < '0' || t->vol_uuid[i] > '9') + if(o->vol_uuid[i] < '0' || o->vol_uuid[i] > '9') break; else - vol->vol_modification_time[i] = t->vol_uuid[i]; + vol->vol_modification_time[i] = o->vol_uuid[i]; for(; i < 16; i++) vol->vol_modification_time[i] = '1'; vol->vol_modification_time[16] = 0; - } else if (t->vol_modification_time > 0) - iso_datetime_17(vol->vol_modification_time, t->vol_modification_time, - t->always_gmt); + } else if (o->vol_modification_time > 0) + iso_datetime_17(vol->vol_modification_time, o->vol_modification_time, + o->always_gmt); else - iso_datetime_17(vol->vol_modification_time, t->now, t->always_gmt); + iso_datetime_17(vol->vol_modification_time, t->now, o->always_gmt); - if (t->vol_expiration_time > 0) { - iso_datetime_17(vol->vol_expiration_time, t->vol_expiration_time, - t->always_gmt); + if (o->vol_expiration_time > 0) { + iso_datetime_17(vol->vol_expiration_time, o->vol_expiration_time, + o->always_gmt); } else { for(i = 0; i < 16; i++) vol->vol_expiration_time[i] = '0'; vol->vol_expiration_time[16] = 0; } - if (t->vol_effective_time > 0) { - iso_datetime_17(vol->vol_effective_time, t->vol_effective_time, - t->always_gmt); + if (o->vol_effective_time > 0) { + iso_datetime_17(vol->vol_effective_time, o->vol_effective_time, + o->always_gmt); } else { for(i = 0; i < 16; i++) vol->vol_effective_time[i] = '0'; @@ -544,7 +544,7 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer) memset(&vol, 0, sizeof(struct ecma119_pri_vol_desc)); - if (t->relaxed_vol_atts) { + if (t->opts->relaxed_vol_atts) { vol_id = get_relaxed_vol_id(t, image->volume_id); volset_id = get_relaxed_vol_id(t, image->volset_id); } else { @@ -633,14 +633,14 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir, Ecma119Node *parent) * RR is very similar */ memset(&info, 0, sizeof(struct susp_info)); - if (t->rockridge) { + if (t->opts->rockridge) { /* initialize the ce_block, it might be needed */ info.ce_block = dir->info.dir->block + DIV_UP(dir->info.dir->len, BLOCK_SIZE); } /* write the "." and ".." entries first */ - if (t->rockridge) { + if (t->opts->rockridge) { ret = rrip_get_susp_fields(t, dir, 1, 34, &info); if (ret < 0) { goto ex; @@ -650,7 +650,7 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir, Ecma119Node *parent) write_one_dir_record(t, dir, 0, buf, 1, &info, 0); buf += len; - if (t->rockridge) { + if (t->opts->rockridge) { ret = rrip_get_susp_fields(t, dir, 2, 34, &info); if (ret < 0) { goto ex; @@ -676,7 +676,7 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir, Ecma119Node *parent) } /* get the SUSP fields if rockridge is enabled */ - if (t->rockridge) { + if (t->opts->rockridge) { ret = rrip_get_susp_fields(t, child, 0, len, &info); if (ret < 0) { goto ex; @@ -862,7 +862,8 @@ int ecma119_writer_write_dirs(IsoImageWriter *writer) if (t->eff_partition_offset > 0) { root = t->partition_root; - if ((t->md5_file_checksums & 1) || t->md5_session_checksum) { + if ((t->opts->md5_file_checksums & 1) || + t->opts->md5_session_checksum) { /* Take into respect the address offset in "isofs.ca" */ ret = iso_node_lookup_attr((IsoNode *) t->image->root, "isofs.ca", &value_length, &value, 0); @@ -891,7 +892,7 @@ int ecma119_writer_write_dirs(IsoImageWriter *writer) ret = write_path_tables(t); if (ret < 0) return ret; - if (t->md5_session_checksum) { + if (t->opts->md5_session_checksum) { /* Write tree checksum tag */ if (t->eff_partition_offset > 0) { /* >>> TWINTREE: >>> For now, tags are only for the @@ -934,15 +935,15 @@ int ecma119_writer_write_data(IsoImageWriter *writer) if (ret < 0) goto ex; - if (t->partition_offset > 0) { - t->eff_partition_offset = t->partition_offset; + if (t->opts->partition_offset > 0) { + t->eff_partition_offset = t->opts->partition_offset; ret = ecma119_writer_write_dirs(writer); t->eff_partition_offset = 0; if (ret < 0) goto ex; } - curblock = (t->bytes_written / 2048) + t->ms_block; + curblock = (t->bytes_written / 2048) + t->opts->ms_block; if (curblock != t->tree_end_block) { LIBISO_ALLOC_MEM(msg, char, 100); sprintf(msg, @@ -1000,9 +1001,9 @@ int ecma119_writer_create(Ecma119Image *target) return ret; } - if(target->partition_offset > 0) { + if(target->opts->partition_offset > 0) { /* Create second tree */ - target->eff_partition_offset = target->partition_offset; + target->eff_partition_offset = target->opts->partition_offset; ret = ecma119_tree_create(target); target->eff_partition_offset = 0; if (ret < 0) @@ -1025,7 +1026,7 @@ int mspad_writer_compute_data_blocks(IsoImageWriter *writer) return ISO_ASSERT_FAILURE; } target = writer->target; - min_size = 32 + target->partition_offset; + min_size = 32 + target->opts->partition_offset; if (target->curblock < min_size) { target->mspad_blocks = min_size - target->curblock; target->curblock = min_size; @@ -1181,13 +1182,13 @@ int tail_writer_compute_data_blocks(IsoImageWriter *writer) if (ret < 0) return ret; data = (struct iso_zero_writer_data_struct *) writer->data; - if (data->num_blocks != target->tail_blocks) { + if (data->num_blocks != target->opts->tail_blocks) { sprintf(msg, "Aligned image size to cylinder size by %d blocks", - target->tail_blocks - data->num_blocks); + target->opts->tail_blocks - data->num_blocks); iso_msgs_submit(0, msg, 0, "NOTE", 0); - data->num_blocks = target->tail_blocks; + data->num_blocks = target->opts->tail_blocks; } - if (target->tail_blocks <= 0) + if (target->opts->tail_blocks <= 0) return ISO_SUCCESS; ret = zero_writer_compute_data_blocks(writer); return ret; @@ -1371,12 +1372,12 @@ int write_head_part2(Ecma119Image *target, int *write_count, int flag) uint8_t *buf = NULL; IsoImageWriter *writer; - if (target->partition_offset <= 0) + if (target->opts->partition_offset <= 0) {ret = ISO_SUCCESS; goto ex;} - /* Write multi-session padding up to target->partition_offset + 16 */ + /* Write multi-session padding up to target->opts->partition_offset + 16 */ LIBISO_ALLOC_MEM(buf, uint8_t, BLOCK_SIZE); - for(; *write_count < (int) target->partition_offset + 16; + for(; *write_count < (int) target->opts->partition_offset + 16; (*write_count)++) { ret = iso_write(target, buf, BLOCK_SIZE); if (ret < 0) @@ -1386,7 +1387,7 @@ int write_head_part2(Ecma119Image *target, int *write_count, int flag) /* Write volume descriptors subtracting target->partiton_offset from any LBA pointer. */ - target->eff_partition_offset = target->partition_offset; + target->eff_partition_offset = target->opts->partition_offset; for (i = 0; i < (int) target->nwriters; ++i) { writer = target->writers[i]; /* Not all writers have an entry in the partion volume descriptor set. @@ -1430,7 +1431,7 @@ int write_head_part(Ecma119Image *target, int flag) return res; /* Write superblock checksum tag */ - if (target->md5_session_checksum && target->checksum_ctx != NULL) { + if (target->opts->md5_session_checksum && target->checksum_ctx != NULL) { res = iso_md5_write_tag(target, 2); if (res < 0) return res; @@ -1452,10 +1453,10 @@ static int finish_libjte(Ecma119Image *target) int ret; - if (target->libjte_handle != NULL) { - ret = libjte_write_footer(target->libjte_handle); + if (target->opts->libjte_handle != NULL) { + ret = libjte_write_footer(target->opts->libjte_handle); if (ret <= 0) { - iso_libjte_forward_msgs(target->libjte_handle, + iso_libjte_forward_msgs(target->opts->libjte_handle, target->image->id, ISO_LIBJTE_END_FAILED, 0); return ISO_LIBJTE_END_FAILED; } @@ -1561,11 +1562,12 @@ void *write_function(void *arg) last_partition = 8; } for (i = first_partition - 1; i <= last_partition - 1; i++) { - if (target->appended_partitions[i] == NULL) + if (target->opts->appended_partitions[i] == NULL) continue; - if (target->appended_partitions[i][0] == 0) + if (target->opts->appended_partitions[i][0] == 0) continue; - res = iso_write_partition_file(target, target->appended_partitions[i], + res = iso_write_partition_file(target, + target->opts->appended_partitions[i], target->appended_part_prepad[i], target->appended_part_size[i], 0); if (res < 0) @@ -1615,7 +1617,7 @@ write_error: ; target->eff_partition_offset = 0; if (res == (int) ISO_CANCELED) { /* canceled */ - if (!target->will_cancel) + if (!target->opts->will_cancel) iso_msg_submit(target->image->id, ISO_IMAGE_WRITE_CANCELED, 0, NULL); } else { @@ -1701,7 +1703,7 @@ int checksum_prepare_nodes(Ecma119Image *target, IsoNode *node, int flag) no_md5 = 1; } } - if (file->from_old_session && target->appendable) { + if (file->from_old_session && target->opts->appendable) { /* Save MD5 data of files from old image which will not be copied and have an MD5 recorded in the old image. */ has_xinfo = iso_node_get_xinfo(node, checksum_md5_xinfo_func, @@ -1712,7 +1714,7 @@ int checksum_prepare_nodes(Ecma119Image *target, IsoNode *node, int flag) */; } else if (has_attr == 1 && img->checksum_array == NULL) { /* No checksum array loaded. Delete "isofs.cx" */ - if (!target->will_cancel) + if (!target->opts->will_cancel) iso_file_set_isofscx((IsoFile *) node, 0, 1); no_md5 = 1; } else if (!(has_attr == 1 && old_cx_value_length == 4)) { @@ -1724,7 +1726,7 @@ int checksum_prepare_nodes(Ecma119Image *target, IsoNode *node, int flag) Omit those from old image which will not be copied and have no MD5. Do not alter the nodes if this is only a will_cancel run. */ - if (!(target->will_cancel || no_md5)) { + if (!(target->opts->will_cancel || no_md5)) { /* Record provisory new index */ ret = iso_file_set_isofscx(file, (unsigned int) 0, 0); if (ret < 0) @@ -1745,18 +1747,19 @@ ex:; } static -int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) +int ecma119_image_new(IsoImage *src, IsoWriteOpts *in_opts, Ecma119Image **img) { int ret, i, voldesc_size, nwriters, tag_pos; int sa_type; Ecma119Image *target; + IsoWriteOpts *opts; IsoImageWriter *writer; int file_src_writer_index = -1; int system_area_options = 0; char *system_area = NULL; int write_count = 0, write_count_mem; - /* 1. Allocate target and copy opts there */ + /* 1. Allocate target and attach a copy of in_opts there */ target = calloc(1, sizeof(Ecma119Image)); if (target == NULL) { return ISO_OUT_OF_MEM; @@ -1765,6 +1768,16 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) bs_free_data. */ target->refcount = 1; + target->opts = NULL; + + /* Record a copy of in_opts. + It is a copy because in_opts is prone to manipulations from the + application thread while the image production thread is running. + */ + ret = iso_write_opts_clone(in_opts, &(target->opts), 0); + if (ret != ISO_SUCCESS) + goto target_cleanup; + opts = target->opts; /* create the tree for file caching */ ret = iso_rbtree_new(iso_file_src_cmp, &(target->files)); @@ -1775,47 +1788,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) target->image = src; iso_image_ref(src); - target->will_cancel = opts->will_cancel; - target->iso_level = opts->level; - target->rockridge = opts->rockridge; - target->joliet = opts->joliet; - target->hfsplus = opts->hfsplus; - target->fat = opts->fat; - target->iso1999 = opts->iso1999; - target->hardlinks = opts->hardlinks; - target->aaip = opts->aaip; - target->always_gmt = opts->always_gmt; - target->old_empty = opts->old_empty; - target->untranslated_name_len = opts->untranslated_name_len; - target->allow_dir_id_ext = opts->allow_dir_id_ext; - target->omit_version_numbers = opts->omit_version_numbers - | opts->max_37_char_filenames; - target->allow_deep_paths = opts->allow_deep_paths; - target->allow_longer_paths = opts->allow_longer_paths; - target->max_37_char_filenames = opts->max_37_char_filenames; - target->no_force_dots = opts->no_force_dots; - target->allow_lowercase = opts->allow_lowercase; - target->allow_full_ascii = opts->allow_full_ascii; - target->allow_7bit_ascii = opts->allow_7bit_ascii; - target->relaxed_vol_atts = opts->relaxed_vol_atts; - target->joliet_longer_paths = opts->joliet_longer_paths; - target->joliet_long_names = opts->joliet_long_names; - target->joliet_utf16 = opts->joliet_utf16; - target->rrip_version_1_10 = opts->rrip_version_1_10; - target->rrip_1_10_px_ino = opts->rrip_1_10_px_ino; - target->aaip_susp_1_10 = opts->aaip_susp_1_10; - target->dir_rec_mtime = opts->dir_rec_mtime; - target->rr_reloc_dir = NULL; - if (opts->rr_reloc_dir != NULL) { - target->rr_reloc_dir = strdup(opts->rr_reloc_dir); - if (target->rr_reloc_dir == NULL) { - ret = ISO_OUT_OF_MEM; - goto target_cleanup; - } - } - target->rr_reloc_flags = opts->rr_reloc_flags; target->rr_reloc_node = NULL; - target->sort_files = opts->sort_files; target->replace_uid = opts->replace_uid ? 1 : 0; target->replace_gid = opts->replace_gid ? 1 : 0; @@ -1828,8 +1801,6 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) target->file_mode = opts->replace_file_mode == 2 ? opts->file_mode : 0444; target->now = time(NULL); - target->ms_block = opts->ms_block; - target->appendable = opts->appendable; target->replace_timestamps = opts->replace_timestamps ? 1 : 0; target->timestamp = opts->replace_timestamps == 2 ? @@ -1881,13 +1852,6 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) } target->system_area_options = system_area_options; - target->vol_creation_time = opts->vol_creation_time; - target->vol_modification_time = opts->vol_modification_time; - target->vol_expiration_time = opts->vol_expiration_time; - target->vol_effective_time = opts->vol_effective_time; - strcpy(target->vol_uuid, opts->vol_uuid); - - target->partition_offset = opts->partition_offset; target->partition_secs_per_head = opts->partition_secs_per_head; target->partition_heads_per_cyl = opts->partition_heads_per_cyl; if (target->partition_secs_per_head == 0) @@ -1917,12 +1881,6 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) goto target_cleanup; } - memcpy(target->hfsp_serial_number, opts->hfsp_serial_number, 8); - - target->md5_file_checksums = opts->md5_file_checksums; - target->md5_session_checksum = opts->md5_session_checksum; - strcpy(target->scdbackup_tag_parm, opts->scdbackup_tag_parm); - target->scdbackup_tag_written = opts->scdbackup_tag_written; target->checksum_idx_counter = 0; target->checksum_ctx = NULL; target->checksum_counter = 0; @@ -1939,12 +1897,10 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) #ifdef Libisofs_with_libjtE /* Eventually start Jigdo Template Extraction */ - target->libjte_handle = NULL; if (opts->libjte_handle != NULL) { - target->libjte_handle = opts->libjte_handle; - ret = libjte_write_header(target->libjte_handle); + ret = libjte_write_header(opts->libjte_handle); if (ret <= 0) { - iso_libjte_forward_msgs(target->libjte_handle, + iso_libjte_forward_msgs(opts->libjte_handle, target->image->id, ISO_LIBJTE_START_FAILED, 0); ret = ISO_LIBJTE_START_FAILED; goto target_cleanup; @@ -1953,8 +1909,6 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) #endif /* Libisofs_with_libjtE */ - target->tail_blocks = opts->tail_blocks; - target->mipsel_e_entry = 0; target->mipsel_p_offset = 0; target->mipsel_p_vaddr = 0; @@ -1967,41 +1921,18 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) target->wthread_is_running = 0; - target->prep_partition = NULL; - if (opts->prep_partition != NULL) { - target->prep_partition = strdup(opts->prep_partition); - if (target->prep_partition == NULL) - return ISO_OUT_OF_MEM; - } target->prep_part_size = 0; - target->efi_boot_partition = NULL; - if (opts->efi_boot_partition != NULL) { - target->efi_boot_partition = strdup(opts->efi_boot_partition); - if (target->efi_boot_partition == NULL) - return ISO_OUT_OF_MEM; - } target->efi_boot_part_size = 0; target->efi_boot_part_filesrc = NULL; for (i = 0; i < ISO_MAX_PARTITIONS; i++) { - target->appended_partitions[i] = NULL; - if (opts->appended_partitions[i] != NULL) { - target->appended_partitions[i] = - strdup(opts->appended_partitions[i]); - if (target->appended_partitions[i] == NULL) - return ISO_OUT_OF_MEM; - target->appended_part_types[i] = opts->appended_part_types[i]; - } target->appended_part_prepad[i] = 0; target->appended_part_start[i] = target->appended_part_size[i] = 0; } - strcpy(target->ascii_disc_label, opts->ascii_disc_label); for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) { target->hfsplus_blessed[i] = src->hfsplus_blessed[i]; if (target->hfsplus_blessed[i] != NULL) iso_node_ref(target->hfsplus_blessed[i]); } - target->apm_block_size = opts->apm_block_size; - target->hfsp_block_size = opts->hfsp_block_size; target->hfsp_cat_node_size = 0; target->hfsp_iso_block_fac = 0; target->hfsp_collision_count = 0; @@ -2035,10 +1966,10 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) * current block. * Finally, create Writer for files. */ - target->curblock = target->ms_block + 16; + target->curblock = opts->ms_block + 16; - if (opts->overwrite != NULL && target->ms_block != 0 && - target->ms_block < target->partition_offset + 32) { + if (opts->overwrite != NULL && opts->ms_block != 0 && + opts->ms_block < opts->partition_offset + 32) { /* Not enough room for superblock relocation */ ret = ISO_OVWRT_MS_TOO_SMALL; goto target_cleanup; @@ -2050,24 +1981,24 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) if (target->eltorito) { nwriters++; } - if (target->joliet) { + if (opts->joliet) { nwriters++; } - if (target->iso1999) { + if (opts->iso1999) { nwriters++; } nwriters++; /* Partition Prepend writer */ - if (target->hfsplus || target->fat) { + if (opts->hfsplus || opts->fat) { nwriters+= 2; } nwriters++; /* GPT backup tail writer */ nwriters++; /* Tail padding writer */ - if ((target->md5_file_checksums & 1) || target->md5_session_checksum) { + if ((opts->md5_file_checksums & 1) || opts->md5_session_checksum) { nwriters++; ret = checksum_prepare_image(src, 0); if (ret < 0) goto target_cleanup; - if (target->appendable) { + if (opts->appendable) { ret = checksum_prepare_nodes(target, (IsoNode *) src->root, 0); if (ret < 0) goto target_cleanup; @@ -2096,7 +2027,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) } /* create writer for Joliet structure */ - if (target->joliet) { + if (opts->joliet) { ret = joliet_writer_create(target); if (ret < 0) { goto target_cleanup; @@ -2104,14 +2035,14 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) } /* create writer for ISO 9660:1999 structure */ - if (target->iso1999) { + if (opts->iso1999) { ret = iso1999_writer_create(target); if (ret < 0) { goto target_cleanup; } } - voldesc_size = target->curblock - target->ms_block - 16; + voldesc_size = target->curblock - opts->ms_block - 16; /* Volume Descriptor Set Terminator */ target->curblock++; @@ -2142,7 +2073,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) /* create writer for HFS+/FAT structure */ /* Impotant: It must be created directly before iso_file_src_writer_create. */ - if (target->hfsplus || target->fat) { + if (opts->hfsplus || opts->fat) { ret = hfsplus_writer_create(target); if (ret < 0) { goto target_cleanup; @@ -2157,7 +2088,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) file_src_writer_index = target->nwriters - 1; /* create writer for HFS+ structure */ - if (target->hfsplus || target->fat) { + if (opts->hfsplus || opts->fat) { ret = hfsplus_tail_writer_create(target); if (ret < 0) { goto target_cleanup; @@ -2188,13 +2119,13 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) /* >>> ??? Why is this important ? */ /* IMPORTANT: This must be the last writer before the checksum writer */ - ret = zero_writer_create(target, target->tail_blocks, 1); + ret = zero_writer_create(target, opts->tail_blocks, 1); if (ret < 0) goto target_cleanup; #endif /* !Libisofs_checksums_before_paddinG */ - if ((target->md5_file_checksums & 1) || target->md5_session_checksum) { + if ((opts->md5_file_checksums & 1) || opts->md5_session_checksum) { ret = checksum_writer_create(target); if (ret < 0) goto target_cleanup; @@ -2202,7 +2133,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) #ifdef Libisofs_checksums_before_paddinG - ret = zero_writer_create(target, target->tail_blocks, 1); + ret = zero_writer_create(target, opts->tail_blocks, 1); if (ret < 0) goto target_cleanup; @@ -2223,17 +2154,16 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) goto target_cleanup; #endif /* Libisofs_gpt_writer_lasT */ - if (target->partition_offset > 0) { + if (opts->partition_offset > 0) { /* After volume descriptors and superblock tag are accounted for: account for second volset */ - if (target->ms_block + target->partition_offset + 16 - < target->curblock) { + if (opts->ms_block + opts->partition_offset + 16 < target->curblock) { /* Overflow of partition system area */ ret = ISO_PART_OFFST_TOO_SMALL; goto target_cleanup; } - target->curblock = target->ms_block + target->partition_offset + 16; + target->curblock = opts->ms_block + opts->partition_offset + 16; /* Account for partition tree volume descriptors */ for (i = 0; i < (int) target->nwriters; ++i) { @@ -2281,9 +2211,9 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) will account resp. write this single block. */ if (i == file_src_writer_index) { - if (! target->old_empty) + if (! opts->old_empty) target->empty_file_block = target->curblock; - opts->data_start_lba = target->curblock; + in_opts->data_start_lba = opts->data_start_lba = target->curblock; } ret = writer->compute_data_blocks(writer); @@ -2305,7 +2235,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) * The volume space size is just the size of the last session, in * case of ms images. */ - target->vol_space_size = target->curblock - target->ms_block; + target->vol_space_size = target->curblock - opts->ms_block; target->total_size = (off_t) target->vol_space_size * BLOCK_SIZE; /* Add sizes of eventually appended partitions */ @@ -2315,7 +2245,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) /* create the ring buffer */ if (opts->overwrite != NULL && - opts->fifo_size < 32 + target->partition_offset) { + opts->fifo_size < 32 + opts->partition_offset) { /* The ring buffer must be large enough to take opts->overwrite */ ret = ISO_OVWRT_FIFO_TOO_SMALL; @@ -2359,7 +2289,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) /* Write relocated superblock checksum tag */ tag_pos = voldesc_size / BLOCK_SIZE + 16 + 1; - if (target->md5_session_checksum) { + if (opts->md5_session_checksum) { target->checksum_rlsb_tag_pos = tag_pos; if (target->checksum_rlsb_tag_pos < 32) { ret = iso_md5_start(&(target->checksum_ctx)); @@ -2408,7 +2338,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) } /* This was possibly altered by above overwrite buffer production */ - target->vol_space_size = target->curblock - target->ms_block; + target->vol_space_size = target->curblock - opts->ms_block; /* */ @@ -2425,7 +2355,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) /* 4. Create and start writing thread */ - if (target->md5_session_checksum) { + if (opts->md5_session_checksum) { /* After any fake writes are done: Initialize image checksum context */ if (target->checksum_ctx != NULL) iso_md5_end(&(target->checksum_ctx), target->image_md5); @@ -2434,11 +2364,11 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) goto target_cleanup; } - if (target->apm_block_size == 0) { + if (opts->apm_block_size == 0) { if (target->gpt_req_count) - target->apm_block_size = 2048; /* Combinable with GPT */ + opts->apm_block_size = 2048; /* Combinable with GPT */ else - target->apm_block_size = 512; /* Mountable on Linux */ + opts->apm_block_size = 512; /* Mountable on Linux */ } /* ensure the thread is created joinable */ @@ -2751,14 +2681,14 @@ int iso_write_opts_new(IsoWriteOpts **opts, int profile) switch (profile) { case 0: - wopts->level = 1; + wopts->iso_level = 1; break; case 1: - wopts->level = 3; + wopts->iso_level = 3; wopts->rockridge = 1; break; case 2: - wopts->level = 2; + wopts->iso_level = 2; wopts->rockridge = 1; wopts->joliet = 1; wopts->replace_dir_mode = 1; @@ -2782,6 +2712,7 @@ int iso_write_opts_new(IsoWriteOpts **opts, int profile) wopts->rr_reloc_dir = NULL; wopts->rr_reloc_flags = 0; wopts->system_area_data = NULL; + wopts->system_area_size = 0; wopts->system_area_options = 0; wopts->vol_creation_time = 0; wopts->vol_modification_time = 0; @@ -2815,6 +2746,54 @@ int iso_write_opts_new(IsoWriteOpts **opts, int profile) return ISO_SUCCESS; } +int iso_write_opts_clone(IsoWriteOpts *in, IsoWriteOpts **out, int flag) +{ + int ret, i; + IsoWriteOpts *o = NULL; + + ret = iso_write_opts_new(&o, 0); + if (ret != 1) + return ret; + *out = o; + + /* Provisory copy of all values and un-managed pointers */ + memcpy(o, in, sizeof(IsoWriteOpts)); + + /* Set managed pointers to NULL */ + o->output_charset = NULL; + o->rr_reloc_dir = NULL; + o->system_area_data = NULL; + o->prep_partition = NULL; + o->efi_boot_partition = NULL; + for (i = 0; i < ISO_MAX_PARTITIONS; i++) + o->appended_partitions[i] = NULL; + + /* Clone managed objects */ + if (iso_clone_mem(in->output_charset, &(o->output_charset), 0) != 1) + goto out_of_mem; + if (iso_clone_mem(in->rr_reloc_dir, &(o->rr_reloc_dir), 0) != 1) + goto out_of_mem; + if (iso_clone_mem(in->system_area_data, &(o->system_area_data), + in->system_area_size) != 1) + goto out_of_mem; + if (iso_clone_mem(in->prep_partition, &(o->prep_partition), 0) != 1) + goto out_of_mem; + if (iso_clone_mem(in->efi_boot_partition, &(o->efi_boot_partition), 0) + != 1) + goto out_of_mem; + for (i = 0; i < ISO_MAX_PARTITIONS; i++) + if (iso_clone_mem(in->appended_partitions[i], + &(o->appended_partitions[i]), 0) != 1) + goto out_of_mem; + + return ISO_SUCCESS; + +out_of_mem:; + if (o != NULL) + iso_write_opts_free(o); + return ISO_OUT_OF_MEM; +} + void iso_write_opts_free(IsoWriteOpts *opts) { int i; @@ -2855,7 +2834,7 @@ int iso_write_opts_set_iso_level(IsoWriteOpts *opts, int level) if (level != 1 && level != 2 && level != 3) { return ISO_WRONG_ARG_VALUE; } - opts->level = level; + opts->iso_level = level; return ISO_SUCCESS; } @@ -3348,6 +3327,7 @@ int iso_write_opts_set_system_area(IsoWriteOpts *opts, char data[32768], if (opts->system_area_data != NULL) free(opts->system_area_data); opts->system_area_data = NULL; + opts->system_area_size = 0; } else if (!(flag & 2)) { if (opts->system_area_data == NULL) { opts->system_area_data = calloc(32768, 1); @@ -3355,6 +3335,7 @@ int iso_write_opts_set_system_area(IsoWriteOpts *opts, char data[32768], return ISO_OUT_OF_MEM; } memcpy(opts->system_area_data, data, 32768); + opts->system_area_size = 32768; } if (!(flag & 4)) opts->system_area_options = options & 0x7fff; diff --git a/libisofs/ecma119.h b/libisofs/ecma119.h index 13b146f..8ae0ab8 100644 --- a/libisofs/ecma119.h +++ b/libisofs/ecma119.h @@ -100,7 +100,7 @@ struct iso_write_opts { int will_cancel; - int level; /**< ISO level to write at. (ECMA-119, 10) */ + int iso_level; /**< ISO level to write at. (ECMA-119, 10) */ /** Which extensions to support. */ unsigned int rockridge :1; @@ -431,6 +431,7 @@ struct iso_write_opts { * See ecma119_image : System Area related information */ char *system_area_data; + int system_area_size; int system_area_options; /* User settable PVD time stamps */ @@ -513,73 +514,19 @@ struct ecma119_image IsoImage *image; Ecma119Node *root; - int will_cancel :1; + IsoWriteOpts *opts; - unsigned int iso_level :2; - - /* extensions */ - unsigned int rockridge :1; - unsigned int joliet :1; + /** Whether El Torito data will be produced */ unsigned int eltorito :1; - unsigned int iso1999 :1; - unsigned int hfsplus :1; - unsigned int fat :1; - unsigned int hardlinks:1; /* see iso_write_opts_set_hardlinks() */ - - unsigned int aaip :1; /* see iso_write_opts_set_aaip() */ - - /* allways write timestamps in GMT */ - unsigned int always_gmt :1; - - /* relaxed constraints */ - unsigned int allow_dir_id_ext :1; - unsigned int omit_version_numbers :2; - unsigned int allow_deep_paths :1; - unsigned int allow_longer_paths :1; - unsigned int max_37_char_filenames :1; - unsigned int no_force_dots :2; - unsigned int allow_lowercase :1; - unsigned int allow_full_ascii :1; - unsigned int allow_7bit_ascii :1; - - unsigned int relaxed_vol_atts : 1; - - /** Allow paths on Joliet tree to be larger than 240 bytes */ - unsigned int joliet_longer_paths :1; - - /** Allow Joliet names up to 103 characters rather than 64 */ - unsigned int joliet_long_names :1; - - /** Use UTF-16BE rather than its subset UCS-2 */ - unsigned int joliet_utf16 :1; - - /** Write old fashioned RRIP-1.10 rather than RRIP-1.12 */ - unsigned int rrip_version_1_10 :1; - - /** Write field PX with file serial number even with RRIP-1.10 */ - unsigned int rrip_1_10_px_ino :1; - - /* Write AAIP as extension according to SUSP 1.10 rather than SUSP 1.12. */ - unsigned int aaip_susp_1_10 :1; - - /* Store in ECMA-119, Joliet, ISO 9660:1999 timestamp the mtime of source - bit0= ECMA-119, bit1= Joliet, bit2= ISO 9660:1999. + /* The ECMA-119 directory node where to store Rock Ridge relocated + directories. (Path is in IsoWriteOpts.rr_reloc_dir) */ - unsigned int dir_rec_mtime :3; - - /* The ECMA-119 directory where to store Rock Ridge relocated directories. - */ - char *rr_reloc_dir; /* IsoNode name in root directory */ - int rr_reloc_flags; Ecma119Node *rr_reloc_node; /* Directory node in ecma119_image */ - unsigned int md5_session_checksum :1; - unsigned int md5_file_checksums :2; - /* * Mode replace. If one of these flags is set, the correspodent values are - * replaced with values below. + * replaced with values below. Both get computed from IsoWriteOpts. */ unsigned int replace_uid :1; unsigned int replace_gid :1; @@ -587,30 +534,17 @@ struct ecma119_image unsigned int replace_dir_mode :1; unsigned int replace_timestamps :1; + /* Mode replacement values. */ uid_t uid; gid_t gid; mode_t file_mode; mode_t dir_mode; time_t timestamp; - unsigned int old_empty :1; - unsigned int untranslated_name_len; - - /** - * if sort files or not. Sorting is based of the weight of each file - */ - int sort_files; - + /* Effective charsets */ char *input_charset; char *output_charset; - /* See iso_write_opts and iso_write_opts_set_hfsp_serial_number(). - * 00...00 means that it shall be generated by libisofs. - */ - uint8_t hfsp_serial_number[8]; - - unsigned int appendable : 1; - uint32_t ms_block; /**< start block for a ms image */ time_t now; /**< Time at which writing began. */ /** Total size of the output. This only includes the current volume. */ @@ -778,14 +712,6 @@ struct ecma119_image Use only underneath ecma119_image_new() and if not NULL*/ - /* ??? Is there a reason why we copy lots of items from IsoWriteOpts - rather than taking ownership of the IsoWriteOpts object which - is submitted with ecma119_image_new() ? - */ - - char scdbackup_tag_parm[100]; - char *scdbackup_tag_written; - /* Buffer for communication between burn_source and writer thread */ IsoRingBuffer *buffer; @@ -794,20 +720,7 @@ struct ecma119_image int wthread_is_running; pthread_attr_t th_attr; - /* User settable PVD time stamps */ - time_t vol_creation_time; - time_t vol_modification_time; - time_t vol_expiration_time; - time_t vol_effective_time; - /* To eventually override vol_creation_time and vol_modification_time - * by unconverted string with timezone 0 - */ - char vol_uuid[17]; - - /* The number of unclaimed 2K blocks before - start of partition 1 as of the MBR in system area. */ - uint32_t partition_offset; - /* Partition table parameter: 1 to 63, 0= disabled/default */ + /* Effective partition table parameter: 1 to 63, 0= disabled/default */ int partition_secs_per_head; /* 1 to 255, 0= disabled/default */ int partition_heads_per_cyl; @@ -828,12 +741,6 @@ struct ecma119_image uint32_t j_part_l_path_table_pos; uint32_t j_part_m_path_table_pos; -#ifdef Libisofs_with_libjtE - struct libjte_env *libjte_handle; -#endif /* Libisofs_with_libjtE */ - - uint32_t tail_blocks; - /* Memorized ELF parameters from MIPS Little Endian boot file */ uint32_t mipsel_e_entry; uint32_t mipsel_p_offset; @@ -845,15 +752,11 @@ struct ecma119_image */ IsoFileSrc *sparc_core_src; - char *appended_partitions[ISO_MAX_PARTITIONS]; - uint8_t appended_part_types[ISO_MAX_PARTITIONS]; /* Counted in blocks of 2048 */ uint32_t appended_part_prepad[ISO_MAX_PARTITIONS]; uint32_t appended_part_start[ISO_MAX_PARTITIONS]; uint32_t appended_part_size[ISO_MAX_PARTITIONS]; - char ascii_disc_label[ISO_DISC_LABEL_SIZE]; - /* See IsoImage and libisofs.h */ IsoNode *hfsplus_blessed[ISO_HFSPLUS_BLESS_MAX]; @@ -861,15 +764,10 @@ struct ecma119_image Only change a block size if it is 0. Set only to 512 or 2048. If it stays 0 then it will become 512 or 2048 in time. */ - /* Blocksize of Apple Partition Map - May be defined to 512 or 2048 before writer thread starts. - */ - int apm_block_size; /* Allocation block size of HFS+ May be defined to 512 or 2048 before hfsplus_writer_create(). */ - int hfsp_block_size; int hfsp_cat_node_size; /* 2 * apm_block_size */ int hfsp_iso_block_fac; /* 2048 / apm_block_size */ @@ -892,7 +790,6 @@ struct ecma119_image struct iso_mbr_partition_request *mbr_req[ISO_MBR_ENTRIES_MAX]; int mbr_req_count; - char *prep_partition; uint32_t prep_part_size; /* GPT description. To be composed during IsoImageWriter @@ -905,7 +802,6 @@ struct ecma119_image /* bit0= GPT partitions may overlap */ int gpt_req_flags; - char *efi_boot_partition; uint32_t efi_boot_part_size; IsoFileSrc *efi_boot_part_filesrc; /* Just a pointer. Do not free. */ diff --git a/libisofs/ecma119_tree.c b/libisofs/ecma119_tree.c index 358c5bf..d723188 100644 --- a/libisofs/ecma119_tree.c +++ b/libisofs/ecma119_tree.c @@ -32,16 +32,17 @@ static int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name) { - int ret, relaxed, free_ascii_name= 0, force_dots = 0; + int ret, relaxed, free_ascii_name = 0, force_dots = 0; char *ascii_name; - char *isoname= NULL; + char *isoname = NULL; + IsoWriteOpts *opts = img->opts; if (iso->name == NULL) { /* it is not necessarily an error, it can be the root */ return ISO_SUCCESS; } - if (img->untranslated_name_len > 0) { + if (opts->untranslated_name_len > 0) { ascii_name = iso->name; ret = 1; } else { @@ -54,27 +55,27 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name) return ret; } - if (img->allow_full_ascii) { + if (opts->allow_full_ascii) { relaxed = 2; } else { - relaxed = (int)img->allow_lowercase; + relaxed = (int)opts->allow_lowercase; } - if (img->allow_7bit_ascii) + if (opts->allow_7bit_ascii) relaxed |= 4; - if (iso->type == LIBISO_DIR && !(img->allow_dir_id_ext)) { - if (img->untranslated_name_len > 0) { - if (strlen(ascii_name) > img->untranslated_name_len) { + if (iso->type == LIBISO_DIR && !(opts->allow_dir_id_ext)) { + if (opts->untranslated_name_len > 0) { + if (strlen(ascii_name) > opts->untranslated_name_len) { needs_transl:; iso_msg_submit(img->image->id, ISO_NAME_NEEDS_TRANSL, 0, "File name too long (%d > %d) for untranslated recording: '%s'", - strlen(ascii_name), img->untranslated_name_len, - ascii_name); + strlen(ascii_name), opts->untranslated_name_len, + ascii_name); return ISO_NAME_NEEDS_TRANSL; } isoname = strdup(ascii_name); - } else if (img->max_37_char_filenames) { + } else if (opts->max_37_char_filenames) { isoname = iso_r_dirid(ascii_name, 37, relaxed); - } else if (img->iso_level == 1) { + } else if (opts->iso_level == 1) { #ifdef Libisofs_old_ecma119_nameS @@ -99,14 +100,15 @@ needs_transl:; } } } else { - force_dots = !((img->no_force_dots & 1) || iso->type == LIBISO_DIR); - if (img->untranslated_name_len > 0) { - if (strlen(ascii_name) > img->untranslated_name_len) + force_dots = !((opts->no_force_dots & 1) || + iso->type == LIBISO_DIR); + if (opts->untranslated_name_len > 0) { + if (strlen(ascii_name) > opts->untranslated_name_len) goto needs_transl; isoname = strdup(ascii_name); - } else if (img->max_37_char_filenames) { + } else if (opts->max_37_char_filenames) { isoname = iso_r_fileid(ascii_name, 36, relaxed, force_dots); - } else if (img->iso_level == 1) { + } else if (opts->iso_level == 1) { #ifdef Libisofs_old_ecma119_nameS @@ -155,7 +157,7 @@ int ecma119_is_dedicated_reloc_dir(Ecma119Image *img, Ecma119Node *node) { if (img->rr_reloc_node == node && node != img->root && node != img->partition_root && - (img->rr_reloc_flags & 2)) + (img->opts->rr_reloc_flags & 2)) return 1; return 0; } @@ -220,7 +222,7 @@ int create_file_src(Ecma119Image *img, IsoFile *iso, IsoFileSrc **src) off_t size; size = iso_stream_get_size(iso->stream); - if (size > (off_t)MAX_ISO_FILE_SECTION_SIZE && img->iso_level != 3) { + if (size > (off_t)MAX_ISO_FILE_SECTION_SIZE && img->opts->iso_level != 3) { char *ipath = iso_tree_get_node_path(ISO_NODE(iso)); ret = iso_msg_submit(img->image->id, ISO_FILE_TOO_BIG, 0, "File \"%s\" can't be added to image because " @@ -361,6 +363,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, int max_path; char *iso_name= NULL, *ipath = NULL; IsoFileSrc *src = NULL; + IsoWriteOpts *opts = image->opts; if (image == NULL || iso == NULL || tree == NULL) { return ISO_NULL_POINTER; @@ -385,16 +388,16 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, goto ex; } max_path = pathlen + 1 + (iso_name ? strlen(iso_name) : 0); - if (!image->rockridge) { + if (!opts->rockridge) { if ((iso->type == LIBISO_DIR && depth > 8) && - !image->allow_deep_paths) { - ipath = iso_tree_get_node_path(iso); + !opts->allow_deep_paths) { + ipath = iso_tree_get_node_path(iso); ret = iso_msg_submit(image->image->id, ISO_FILE_IMGPATH_WRONG, 0, "File \"%s\" can't be added, " "because directory depth " "is greater than 8.", ipath); goto ex; - } else if (max_path > 255 && !image->allow_longer_paths) { + } else if (max_path > 255 && !opts->allow_longer_paths) { ipath = iso_tree_get_node_path(iso); ret = iso_msg_submit(image->image->id, ISO_FILE_IMGPATH_WRONG, 0, "File \"%s\" can't be added, " @@ -418,7 +421,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, ret = 0; /* Hidden means non-existing */ goto ex; } - if (image->rockridge) { + if (opts->rockridge) { ret = create_symlink(image, (IsoSymlink*)iso, &node); } else { /* symlinks are only supported when RR is enabled */ @@ -434,7 +437,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, ret = 0; /* Hidden means non-existing */ goto ex; } - if (image->rockridge) { + if (opts->rockridge) { ret = create_special(image, (IsoSpecial*)iso, &node); } else { /* special files are only supported when RR is enabled */ @@ -472,9 +475,9 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, image->rr_reloc_node = node; } else if (depth == 2) { /* Directories in root may be used as relocation dir */ - if (image->rr_reloc_dir != NULL) - if (image->rr_reloc_dir[0] != 0 && - strcmp(iso->name, image->rr_reloc_dir) == 0) + if (opts->rr_reloc_dir != NULL) + if (opts->rr_reloc_dir[0] != 0 && + strcmp(iso->name, opts->rr_reloc_dir) == 0) image->rr_reloc_node = node; } } @@ -606,7 +609,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, continue; } - if (img->untranslated_name_len) { + if (img->opts->untranslated_name_len) { /* This should not happen because no two IsoNode names should be identical and only unaltered IsoNode names should be seen here. Thus the Ema119Node names should be unique. @@ -635,7 +638,8 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, /* compute name and extension */ dot = strrchr(full_name, '.'); if (dot != NULL && - (children[i]->type != ECMA119_DIR || img->allow_dir_id_ext)) { + (children[i]->type != ECMA119_DIR || + img->opts->allow_dir_id_ext)) { /* * File (normally not dir) with extension @@ -801,11 +805,11 @@ int mangle_tree(Ecma119Image *img, Ecma119Node *dir, int recurse) int max_file, max_dir; Ecma119Node *root; - if (img->untranslated_name_len > 0) { - max_file = max_dir = img->untranslated_name_len; - } else if (img->max_37_char_filenames) { + if (img->opts->untranslated_name_len > 0) { + max_file = max_dir = img->opts->untranslated_name_len; + } else if (img->opts->max_37_char_filenames) { max_file = max_dir = 37; - } else if (img->iso_level == 1) { + } else if (img->opts->iso_level == 1) { max_file = 12; /* 8 + 3 + 1 */ max_dir = 8; } else { @@ -973,9 +977,9 @@ int reorder_tree(Ecma119Image *img, Ecma119Node *dir, /* dir is now the relocated Ecma119Node */ pathlen = 37 + 1; /* The dir name might get longer by mangling */ level = 2; - if (img->rr_reloc_dir != NULL) { + if (img->opts->rr_reloc_dir != NULL) { pathlen += strlen(img->rr_reloc_node->iso_name) + 1; - if(img->rr_reloc_dir[0] != 0) + if(img->opts->rr_reloc_dir[0] != 0) level = 3; } } @@ -1128,7 +1132,7 @@ int match_hardlinks(Ecma119Image *img, Ecma119Node *dir, int flag) goto ex; /* Sort according to id tuples, IsoFileSrc identity, properties, xattr. */ - if (img->hardlinks) + if (img->opts->hardlinks) qsort(nodes, node_count, sizeof(Ecma119Node *), ecma119_node_cmp_hard); else qsort(nodes, node_count, sizeof(Ecma119Node *), @@ -1198,7 +1202,7 @@ int ecma119_tree_create(Ecma119Image *img) return ret; } - if (img->rockridge && !img->allow_deep_paths) { + if (img->opts->rockridge && !img->opts->allow_deep_paths) { /* Relocate deep directories, acording to RRIP, 4.1.5 */ ret = reorder_tree(img, root, 1, 0); diff --git a/libisofs/eltorito.c b/libisofs/eltorito.c index 11e9c14..6b0f5b1 100644 --- a/libisofs/eltorito.c +++ b/libisofs/eltorito.c @@ -1126,7 +1126,7 @@ int patch_boot_info_table(uint8_t *buf, Ecma119Image *t, return iso_msg_submit(t->image->id, ISO_ISOLINUX_CANT_PATCH, 0, "Isolinux image too small. We won't patch it."); } - ret = make_boot_info_table(buf, t->ms_block + (uint32_t) 16, + ret = make_boot_info_table(buf, t->opts->ms_block + (uint32_t) 16, t->bootsrc[idx]->sections[0].block, (uint32_t) imgsize); return ret; @@ -1302,8 +1302,8 @@ int eltorito_writer_create(Ecma119Image *target) } } - if (target->efi_boot_partition != NULL) - if (strcmp(target->efi_boot_partition, "--efi-boot-image") == 0) + if (target->opts->efi_boot_partition != NULL) + if (strcmp(target->opts->efi_boot_partition, "--efi-boot-image") == 0) outsource_efi = 1; for (idx = 0; idx < target->catalog->num_bootimages; idx++) { bootimg = target->catalog->bootimages[idx]->image; @@ -1337,8 +1337,8 @@ int eltorito_writer_create(Ecma119Image *target) if (outsource_efi) { /* Disable EFI Boot partition and complain */ - free(target->efi_boot_partition); - target->efi_boot_partition = NULL; + free(target->opts->efi_boot_partition); + target->opts->efi_boot_partition = NULL; iso_msg_submit(target->image->id, ISO_BOOT_NO_EFI_ELTO, 0, "No newly added El Torito EFI boot image found for exposure as GPT partition"); return ISO_BOOT_NO_EFI_ELTO; diff --git a/libisofs/filesrc.c b/libisofs/filesrc.c index 1704e81..a62a3d7 100644 --- a/libisofs/filesrc.c +++ b/libisofs/filesrc.c @@ -88,8 +88,8 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) } /* fill key and other atts */ - fsrc->no_write = (file->from_old_session && img->appendable); - if (file->from_old_session && img->appendable) { + fsrc->no_write = (file->from_old_session && img->opts->appendable); + if (file->from_old_session && img->opts->appendable) { /* * On multisession discs we keep file sections from old image. */ @@ -127,7 +127,8 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) /* insert the filesrc in the tree */ ret = iso_rbtree_insert(img->files, fsrc, (void**)src); if (ret <= 0) { - if (ret == 0 && (*src)->checksum_index > 0 && !img->will_cancel) { + if (ret == 0 && (*src)->checksum_index > 0 && + !img->opts->will_cancel) { /* Duplicate file source was mapped to previously registered source */ cret = iso_file_set_isofscx(file, (*src)->checksum_index, 0); @@ -140,8 +141,8 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) } iso_stream_ref(fsrc->stream); - if ((img->md5_file_checksums & 1) && - file->from_old_session && img->appendable) { + if ((img->opts->md5_file_checksums & 1) && + file->from_old_session && img->opts->appendable) { ret = iso_node_get_xinfo((IsoNode *) file, checksum_md5_xinfo_func, &xipt); if (ret <= 0) @@ -152,7 +153,8 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) no_md5 = 1; } - if ((img->md5_file_checksums & 1) && !(no_md5 || img->will_cancel)) { + if ((img->opts->md5_file_checksums & 1) && + !(no_md5 || img->opts->will_cancel)) { img->checksum_idx_counter++; if (img->checksum_idx_counter < 0x7fffffff) { fsrc->checksum_index = img->checksum_idx_counter; @@ -244,11 +246,11 @@ int filesrc_writer_pre_compute(IsoImageWriter *writer) /* Normally reserve a single zeroed block for all files which have no block address: symbolic links, device files, empty data files. */ - if (! t->old_empty) + if (! t->opts->old_empty) t->filesrc_blocks++; /* on appendable images, ms files shouldn't be included */ - if (t->appendable) { + if (t->opts->appendable) { inc_item = shall_be_written; } else { inc_item = NULL; @@ -261,7 +263,7 @@ int filesrc_writer_pre_compute(IsoImageWriter *writer) } /* sort files by weight, if needed */ - if (t->sort_files) { + if (t->opts->sort_files) { qsort(filelist, size, sizeof(void*), cmp_by_weight); } @@ -436,7 +438,7 @@ int iso_filesrc_write_data(Ecma119Image *t, IsoFileSrc *file, file_size = iso_file_src_get_size(file); nblocks = DIV_UP(file_size, BLOCK_SIZE); pre_md5_valid = 0; - if (file->checksum_index > 0 && (t->md5_file_checksums & 2)) { + if (file->checksum_index > 0 && (t->opts->md5_file_checksums & 2)) { /* Obtain an MD5 of content by a first read pass */ pre_md5_valid = filesrc_make_md5(t, file, pre_md5, 0); } @@ -494,11 +496,11 @@ int iso_filesrc_write_data(Ecma119Image *t, IsoFileSrc *file, /* >>> HFS: need to align to allocation block size */; #ifdef Libisofs_with_libjtE - if (t->libjte_handle != NULL) { - res = libjte_begin_data_file(t->libjte_handle, name, + if (t->opts->libjte_handle != NULL) { + res = libjte_begin_data_file(t->opts->libjte_handle, name, BLOCK_SIZE, file_size); if (res <= 0) { - res = iso_libjte_forward_msgs(t->libjte_handle, t->image->id, + res = iso_libjte_forward_msgs(t->opts->libjte_handle, t->image->id, ISO_LIBJTE_FILE_FAILED, 0); if (res < 0) { filesrc_close(file); @@ -593,7 +595,7 @@ int iso_filesrc_write_data(Ecma119Image *t, IsoFileSrc *file, res = iso_md5_end(&ctx, md5); if (res <= 0) file->checksum_index = 0; - if ((t->md5_file_checksums & 2) && pre_md5_valid > 0 && + if ((t->opts->md5_file_checksums & 2) && pre_md5_valid > 0 && !was_error) { if (! iso_md5_match(md5, pre_md5)) { /* Issue MISHAP event */ @@ -619,8 +621,8 @@ ex:; #ifdef Libisofs_with_libjtE if (jte_begun) { - res = libjte_end_data_file(t->libjte_handle); - iso_libjte_forward_msgs(t->libjte_handle, t->image->id, + res = libjte_end_data_file(t->opts->libjte_handle); + iso_libjte_forward_msgs(t->opts->libjte_handle, t->image->id, ISO_LIBJTE_END_FAILED, 0); if (res <= 0 && ret >= 0) ret = ISO_LIBJTE_FILE_FAILED; @@ -658,7 +660,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer) files which have no block address: symbolic links, device files, empty data files. */ - if (! t->old_empty) { + if (! t->opts->old_empty) { ret = iso_write(t, buffer, BLOCK_SIZE); if (ret < 0) goto ex; diff --git a/libisofs/hfsplus.c b/libisofs/hfsplus.c index 863a5ff..558d55c 100644 --- a/libisofs/hfsplus.c +++ b/libisofs/hfsplus.c @@ -429,7 +429,7 @@ int hfsplus_tail_writer_compute_data_blocks(IsoImageWriter *writer) } t = writer->target; - block_size = t->hfsp_block_size; + block_size = t->opts->hfsp_block_size; block_fac = t->hfsp_iso_block_fac; #ifdef Libisofs_ts_debuG @@ -485,7 +485,7 @@ int hfsplus_writer_compute_data_blocks(IsoImageWriter *writer) } t = writer->target; - block_size = t->hfsp_block_size; + block_size = t->opts->hfsp_block_size; block_fac = t->hfsp_iso_block_fac; iso_msg_debug(t->image->id, "(b) curblock=%d, nodes =%d", t->curblock, t->hfsp_nnodes); @@ -582,7 +582,7 @@ write_sb (Ecma119Image *t) iso_msg_debug(t->image->id, "Write HFS+ superblock"); - block_size = t->hfsp_block_size; + block_size = t->opts->hfsp_block_size; memset (buffer, 0, sizeof (buffer)); ret = iso_write(t, buffer, 1024); @@ -642,7 +642,7 @@ write_sb (Ecma119Image *t) } - memcpy (&sb.num_serial, &t->hfsp_serial_number, 8); + memcpy (&sb.num_serial, &t->opts->hfsp_serial_number, 8); ret = iso_write(t, &sb, sizeof (sb)); if (ret < 0) return ret; @@ -665,7 +665,7 @@ int hfsplus_writer_write_data(IsoImageWriter *writer) } t = writer->target; - block_size = t->hfsp_block_size; + block_size = t->opts->hfsp_block_size; block_fac = t->hfsp_iso_block_fac; cat_node_size = t->hfsp_cat_node_size; @@ -1033,7 +1033,7 @@ int hfsplus_tail_writer_write_data(IsoImageWriter *writer) } t = writer->target; - block_size = t->hfsp_block_size; + block_size = t->opts->hfsp_block_size; #ifdef Libisofs_ts_debuG iso_msg_debug(t->image->id, "hfsplus tail writer writes at = %.f", @@ -1579,10 +1579,10 @@ int hfsplus_writer_create(Ecma119Image *target) make_hfsplus_decompose_pages(); make_hfsplus_class_pages(); - if (target->hfsp_block_size == 0) - target->hfsp_block_size = HFSPLUS_DEFAULT_BLOCK_SIZE; - target->hfsp_cat_node_size = 2 * target->hfsp_block_size; - target->hfsp_iso_block_fac = 2048 / target->hfsp_block_size; + if (target->opts->hfsp_block_size == 0) + target->opts->hfsp_block_size = HFSPLUS_DEFAULT_BLOCK_SIZE; + target->hfsp_cat_node_size = 2 * target->opts->hfsp_block_size; + target->hfsp_iso_block_fac = 2048 / target->opts->hfsp_block_size; cat_node_size = target->hfsp_cat_node_size; writer->compute_data_blocks = hfsplus_writer_compute_data_blocks; diff --git a/libisofs/iso1999.c b/libisofs/iso1999.c index 26dc2d6..dd503d1 100644 --- a/libisofs/iso1999.c +++ b/libisofs/iso1999.c @@ -125,7 +125,7 @@ int create_node(Ecma119Image *t, IsoNode *iso, Iso1999Node **node) IsoFile *file = (IsoFile*) iso; size = iso_stream_get_size(file->stream); - if (size > (off_t)MAX_ISO_FILE_SECTION_SIZE && t->iso_level != 3) { + if (size > (off_t)MAX_ISO_FILE_SECTION_SIZE && t->opts->iso_level != 3) { char *ipath = iso_tree_get_node_path(iso); ret = iso_msg_submit(t->image->id, ISO_FILE_TOO_BIG, 0, "File \"%s\" can't be added to image because is " @@ -194,7 +194,7 @@ int create_tree(Ecma119Image *t, IsoNode *iso, Iso1999Node **tree, int pathlen) } max_path = pathlen + 1 + (iso_name ? strlen(iso_name): 0); - if (!t->allow_longer_paths && max_path > 255) { + if (!t->opts->allow_longer_paths && max_path > 255) { char *ipath = iso_tree_get_node_path(iso); ret = iso_msg_submit(t->image->id, ISO_FILE_IMGPATH_WRONG, 0, "File \"%s\" can't be added to ISO 9660:1999 tree, " @@ -722,13 +722,13 @@ void write_one_dir_record(Ecma119Image *t, Iso1999Node *node, int file_id, iso_bb(rec->block, block, 4); iso_bb(rec->length, len, 4); - /* was: iso_datetime_7(rec->recording_time, t->now, t->always_gmt); + /* was: iso_datetime_7(rec->recording_time, t->now, t->opts->always_gmt); */ iso= node->node; iso_datetime_7(rec->recording_time, - (t->dir_rec_mtime & 4) ? ( t->replace_timestamps ? - t->timestamp : iso->mtime ) - : t->now, t->always_gmt); + (t->opts->dir_rec_mtime & 4) ? ( t->replace_timestamps ? + t->timestamp : iso->mtime ) + : t->now, t->opts->always_gmt); rec->flags[0] = ((node->type == ISO1999_DIR) ? 2 : 0) | (multi_extend ? 0x80 : 0); iso_bb(rec->vol_seq_number, (uint32_t) 1, 2); diff --git a/libisofs/joliet.c b/libisofs/joliet.c index da8eef8..0ffcfc7 100644 --- a/libisofs/joliet.c +++ b/libisofs/joliet.c @@ -41,7 +41,7 @@ int get_joliet_name(Ecma119Image *t, IsoNode *iso, uint16_t **name) return ISO_SUCCESS; } - if (t->joliet_utf16) { + if (t->opts->joliet_utf16) { ret = str2utf16be(t->input_charset, iso->name, &ucs_name); if (ret < 0) { iso_msg_debug(t->image->id, "Cannot convert to UTF-16 : \"%s\"", @@ -68,10 +68,10 @@ int get_joliet_name(Ecma119Image *t, IsoNode *iso, uint16_t **name) } } if (iso->type == LIBISO_DIR) { - jname = iso_j_dir_id(ucs_name, t->joliet_long_names << 1); + jname = iso_j_dir_id(ucs_name, t->opts->joliet_long_names << 1); } else { jname = iso_j_file_id(ucs_name, - (t->joliet_long_names << 1) | !!(t->no_force_dots & 2)); + (t->opts->joliet_long_names << 1) | !!(t->opts->no_force_dots & 2)); } ret = ISO_SUCCESS; ex:; @@ -151,7 +151,8 @@ int create_node(Ecma119Image *t, IsoNode *iso, JolietNode **node) IsoFile *file = (IsoFile*) iso; size = iso_stream_get_size(file->stream); - if (size > (off_t)MAX_ISO_FILE_SECTION_SIZE && t->iso_level != 3) { + if (size > (off_t)MAX_ISO_FILE_SECTION_SIZE && + t->opts->iso_level != 3) { char *ipath = iso_tree_get_node_path(iso); free(joliet); ret = iso_msg_submit(t->image->id, ISO_FILE_TOO_BIG, 0, @@ -219,7 +220,7 @@ int create_tree(Ecma119Image *t, IsoNode *iso, JolietNode **tree, int pathlen) return ret; } max_path = pathlen + 1 + (jname ? ucslen(jname) * 2 : 0); - if (!t->joliet_longer_paths && max_path > 240) { + if (!t->opts->joliet_longer_paths && max_path > 240) { char *ipath = iso_tree_get_node_path(iso); /* * Wow!! Joliet is even more restrictive than plain ISO-9660, @@ -280,7 +281,7 @@ int create_tree(Ecma119Image *t, IsoNode *iso, JolietNode **tree, int pathlen) { char *ipath = iso_tree_get_node_path(iso); ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0, - "Can't add %s to Joliet tree. %s can only be added to a " + "Cannot add %s to Joliet tree. %s can only be added to a " "Rock Ridge tree.", ipath, (iso->type == LIBISO_SYMLINK ? "Symlinks" : "Special files")); free(ipath); @@ -390,7 +391,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir) nchildren = dir->info.dir->nchildren; children = dir->info.dir->children; - if (t->joliet_long_names) + if (t->opts->joliet_long_names) maxchar = 103; /* a hash table will temporary hold the names, for fast searching */ @@ -629,7 +630,7 @@ size_t calc_dirent_len(Ecma119Image *t, JolietNode *n) { /* note than name len is always even, so we always need the pad byte */ int ret = n->name ? ucslen(n->name) * 2 + 34 : 34; - if (n->type == JOLIET_FILE && !(t->omit_version_numbers & 3)) { + if (n->type == JOLIET_FILE && !(t->opts->omit_version_numbers & 3)) { /* take into account version numbers */ ret += 4; } @@ -748,7 +749,7 @@ int joliet_writer_compute_data_blocks(IsoImageWriter *writer) t->curblock += DIV_UP(path_table_size, BLOCK_SIZE); t->joliet_path_table_size = path_table_size; - if (t->partition_offset > 0) { + if (t->opts->partition_offset > 0) { /* Take into respect second directory tree */ ndirs = t->joliet_ndirs; t->joliet_ndirs = 0; @@ -797,7 +798,7 @@ void write_one_dir_record(Ecma119Image *t, JolietNode *node, int file_id, memcpy(rec->file_id, name, len_fi); - if (node->type == JOLIET_FILE && !(t->omit_version_numbers & 3)) { + if (node->type == JOLIET_FILE && !(t->opts->omit_version_numbers & 3)) { len_dr += 4; rec->file_id[len_fi++] = 0; rec->file_id[len_fi++] = ';'; @@ -832,13 +833,13 @@ void write_one_dir_record(Ecma119Image *t, JolietNode *node, int file_id, iso_bb(rec->block, block - t->eff_partition_offset, 4); iso_bb(rec->length, len, 4); - /* was: iso_datetime_7(rec->recording_time, t->now, t->always_gmt); + /* was: iso_datetime_7(rec->recording_time, t->now, t->opts->always_gmt); */ iso= node->node; iso_datetime_7(rec->recording_time, - (t->dir_rec_mtime & 2) ? ( t->replace_timestamps ? - t->timestamp : iso->mtime ) - : t->now, t->always_gmt); + (t->opts->dir_rec_mtime & 2) ? ( t->replace_timestamps ? + t->timestamp : iso->mtime ) + : t->now, t->opts->always_gmt); rec->flags[0] = ((node->type == JOLIET_DIR) ? 2 : 0) | (multi_extend ? 0x80 : 0); iso_bb(rec->vol_seq_number, (uint32_t) 1, 2); @@ -993,7 +994,8 @@ int write_one_dir(Ecma119Image *t, JolietNode *dir) /* compute len of directory entry */ fi_len = ucslen(child->name) * 2; len = fi_len + 34; - if (child->type == JOLIET_FILE && !(t->omit_version_numbers & 3)) { + if (child->type == JOLIET_FILE && + !(t->opts->omit_version_numbers & 3)) { len += 4; } @@ -1195,8 +1197,8 @@ int joliet_writer_write_data(IsoImageWriter *writer) if (ret < 0) return ret; - if (t->partition_offset > 0) { - t->eff_partition_offset = t->partition_offset; + if (t->opts->partition_offset > 0) { + t->eff_partition_offset = t->opts->partition_offset; ret = joliet_writer_write_dirs(writer); t->eff_partition_offset = 0; if (ret < 0) @@ -1244,9 +1246,9 @@ int joliet_writer_create(Ecma119Image *target) /* add this writer to image */ target->writers[target->nwriters++] = writer; - if(target->partition_offset > 0) { + if(target->opts->partition_offset > 0) { /* Create second tree */ - target->eff_partition_offset = target->partition_offset; + target->eff_partition_offset = target->opts->partition_offset; ret = joliet_tree_create(target); if (ret < 0) { return ret; diff --git a/libisofs/make_isohybrid_mbr.c b/libisofs/make_isohybrid_mbr.c index 9d88fd7..0a453c1 100644 --- a/libisofs/make_isohybrid_mbr.c +++ b/libisofs/make_isohybrid_mbr.c @@ -455,7 +455,7 @@ int assess_isohybrid_gpt_apm(Ecma119Image *t, int *gpt_count, int gpt_idx[128], return ret; /* Prevent gap filling */ t->apm_req_flags |= 2; - t->apm_block_size = 2048; + t->opts->apm_block_size = 2048; } } } diff --git a/libisofs/md5.c b/libisofs/md5.c index 68e508b..ffe5d71 100644 --- a/libisofs/md5.c +++ b/libisofs/md5.c @@ -497,7 +497,7 @@ int checksum_copy_old_nodes(Ecma119Image *target, IsoNode *node, int flag) if (node->type == LIBISO_FILE) { file = (IsoFile *) node; - if (file->from_old_session && target->appendable) { + if (file->from_old_session && target->opts->appendable) { /* Look for checksums at various places */ /* Try checksum directly stored with node */ @@ -527,7 +527,7 @@ int checksum_copy_old_nodes(Ecma119Image *target, IsoNode *node, int flag) if (md5_pt == NULL) return 0; - if (!target->will_cancel) { + if (!target->opts->will_cancel) { ret = iso_node_lookup_attr(node, "isofs.cx", &value_length, &value, 0); if (ret == 1 && value_length == 4) { @@ -571,8 +571,8 @@ int checksum_writer_compute_data_blocks(IsoImageWriter *writer) t = writer->target; t->checksum_array_pos = t->curblock; - /* (t->curblock already contains t->ms_block) */ - t->checksum_range_start = t->ms_block; + /* (t->curblock already contains t->opts->ms_block) */ + t->checksum_range_start = t->opts->ms_block; size = (t->checksum_idx_counter + 2) / 128; if (size * 128 < t->checksum_idx_counter + 2) size++; @@ -712,7 +712,7 @@ int checksum_writer_create(Ecma119Image *target) /* add this writer to image */ target->writers[target->nwriters++] = writer; /* Account for superblock checksum tag */ - if (target->md5_session_checksum) { + if (target->opts->md5_session_checksum) { target->checksum_sb_tag_pos = target->curblock; target->curblock++; } @@ -742,7 +742,7 @@ int iso_md5_write_scdbackup_tag(Ecma119Image *t, char *tag_block, int flag) (unsigned int) (pos % 1000000000)); else sprintf(postext, "%u", (unsigned int) pos); - sprintf(record, "%s %s ", t->scdbackup_tag_parm, postext); + sprintf(record, "%s %s ", t->opts->scdbackup_tag_parm, postext); record_len = strlen(record); for (i = 0; i < 16; i++) sprintf(record + record_len + 2 * i, @@ -764,8 +764,8 @@ int iso_md5_write_scdbackup_tag(Ecma119Image *t, char *tag_block, int flag) block_len+= 32; tag_block[block_len++]= '\n'; - if (t->scdbackup_tag_written != NULL) - strncpy(t->scdbackup_tag_written, tag_block + line_start, + if (t->opts->scdbackup_tag_written != NULL) + strncpy(t->opts->scdbackup_tag_written, tag_block + line_start, block_len - line_start); ret = ISO_SUCCESS; ex:; @@ -827,7 +827,7 @@ int iso_md5_write_tag(Ecma119Image *t, int flag) } else if (mode == 3) { sprintf(tag_block + l, " next=%u", t->checksum_tag_pos); } else if (mode == 4) { - sprintf(tag_block + l, " session_start=%u", t->ms_block); + sprintf(tag_block + l, " session_start=%u", t->opts->ms_block); } strcat(tag_block + l, " md5="); l = strlen(tag_block); @@ -848,8 +848,8 @@ int iso_md5_write_tag(Ecma119Image *t, int flag) } tag_block[l + 32] = '\n'; - if (mode == 1 && t->scdbackup_tag_parm[0]) { - if (t->ms_block > 0) { + if (mode == 1 && t->opts->scdbackup_tag_parm[0]) { + if (t->opts->ms_block > 0) { iso_msg_submit(t->image->id, ISO_SCDBACKUP_TAG_NOT_0, 0, NULL); } else { ret = iso_md5_write_scdbackup_tag(t, tag_block, 0); diff --git a/libisofs/rockridge.c b/libisofs/rockridge.c index 4f9e1d3..79c28e1 100644 --- a/libisofs/rockridge.c +++ b/libisofs/rockridge.c @@ -115,7 +115,7 @@ int rrip_add_PX(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) PX[0] = 'P'; PX[1] = 'X'; - if (t->rrip_1_10_px_ino || !t->rrip_version_1_10 ) { + if (t->opts->rrip_1_10_px_ino || !t->opts->rrip_version_1_10 ) { PX[2] = 44; } else { PX[2] = 36; @@ -125,7 +125,7 @@ int rrip_add_PX(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) iso_bb(&PX[12], (uint32_t) n->nlink, 4); iso_bb(&PX[20], (uint32_t) px_get_uid(t, n), 4); iso_bb(&PX[28], (uint32_t) px_get_gid(t, n), 4); - if (t->rrip_1_10_px_ino || !t->rrip_version_1_10) { + if (t->opts->rrip_1_10_px_ino || !t->opts->rrip_version_1_10) { iso_bb(&PX[36], (uint32_t) n->ino, 4); } @@ -153,11 +153,11 @@ int rrip_add_TF(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) iso = n->node; iso_datetime_7(&TF[5], t->replace_timestamps ? t->timestamp : iso->mtime, - t->always_gmt); + t->opts->always_gmt); iso_datetime_7(&TF[12], t->replace_timestamps ? t->timestamp : iso->atime, - t->always_gmt); + t->opts->always_gmt); iso_datetime_7(&TF[19], t->replace_timestamps ? t->timestamp : iso->ctime, - t->always_gmt); + t->opts->always_gmt); return susp_append(t, susp, TF); } @@ -542,7 +542,7 @@ int aaip_add_AL(Ecma119Image *t, struct susp_info *susp, int ret, done = 0, len, es_extra = 0; uint8_t *aapt, *cpt; - if (!t->aaip_susp_1_10) + if (!t->opts->aaip_susp_1_10) es_extra = 5; if (*sua_free < num_data + es_extra || *ce_len > 0) { *ce_len += num_data + es_extra; @@ -553,7 +553,7 @@ int aaip_add_AL(Ecma119Image *t, struct susp_info *susp, return ISO_SUCCESS; /* If AAIP enabled and announced by ER : Write ES field to announce AAIP */ - if (t->aaip && !t->aaip_susp_1_10) { + if (t->opts->aaip && !t->opts->aaip_susp_1_10) { ret = susp_add_ES(t, susp, (*ce_len > 0), 1); if (ret < 0) return ret; @@ -606,7 +606,7 @@ int rrip_add_ER(Ecma119Image *t, struct susp_info *susp) { unsigned char *ER; - if (!t->rrip_version_1_10) { + if (!t->opts->rrip_version_1_10) { /* According to RRIP 1.12 this is the future form: 4.3 "Specification of the ER System Use Entry Values for RRIP" @@ -851,7 +851,7 @@ int add_zf_field(Ecma119Image *t, Ecma119Node *n, struct susp_info *info, zisofs file header when inquired) */ - if (t->appendable && file->from_old_session) + if (t->opts->appendable && file->from_old_session) will_copy = 0; first_filter = first_stream = last_stream = iso_file_get_stream(file); @@ -1124,7 +1124,7 @@ int susp_calc_nm_sl_al(Ecma119Image *t, Ecma119Node *n, size_t space, /* obtain num_aapt from node */ xipt = NULL; num_aapt = 0; - if (t->aaip) { + if (t->opts->aaip) { ret = iso_node_get_xinfo(n->node, aaip_xinfo_func, &xipt); if (ret == 1) { num_aapt = aaip_count_bytes((unsigned char *) xipt, 0); @@ -1160,7 +1160,7 @@ int add_aa_string(Ecma119Image *t, Ecma119Node *n, struct susp_info *info, void *xipt; size_t num_aapt= 0; - if (!t->aaip) + if (!t->opts->aaip) return 1; ret = iso_node_get_xinfo(n->node, aaip_xinfo_func, &xipt); @@ -1221,7 +1221,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t used_up, su_size = 0; /* If AAIP enabled and announced by ER : account for 5 bytes of ES */; - if (t->aaip && !t->aaip_susp_1_10) + if (t->opts->aaip && !t->opts->aaip_susp_1_10) su_size += 5; #ifdef Libisofs_with_rrip_rR @@ -1230,7 +1230,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t used_up, #endif /* PX and TF, we are sure they always fit in SUA */ - if (t->rrip_1_10_px_ino || !t->rrip_version_1_10) { + if (t->opts->rrip_1_10_px_ino || !t->opts->rrip_version_1_10) { su_size += 44 + 26; } else { su_size += 36 + 26; @@ -1247,7 +1247,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t used_up, su_size += 4; } } else if(ecma119_is_dedicated_reloc_dir(t, n) && - (t->rr_reloc_flags & 1)) { + (t->opts->rr_reloc_flags & 1)) { /* The dedicated relocation directory shall be marked by RE */ su_size += 4; } @@ -1274,7 +1274,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t used_up, /* "." or ".." entry */ - if (!t->rrip_version_1_10) + if (!t->opts->rrip_version_1_10) su_size += 5; /* NM field */ if (type == 1 && n->parent == NULL) { @@ -1285,12 +1285,12 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t used_up, */ su_size += 7 + 28; /* SP + CE */ /* ER of RRIP */ - if (t->rrip_version_1_10) { + if (t->opts->rrip_version_1_10) { *ce = 237; } else { *ce = 182; } - if (t->aaip && !t->aaip_susp_1_10) { + if (t->opts->aaip && !t->opts->aaip_susp_1_10) { *ce += 160; /* ER of AAIP */ } /* Compute length of AAIP string of root node */ @@ -1394,7 +1394,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, } /* If AAIP enabled and announced by ER : Announce RRIP by ES */ - if (t->aaip && !t->aaip_susp_1_10) { + if (t->opts->aaip && !t->opts->aaip_susp_1_10) { ret = susp_add_ES(t, info, 0, 0); if (ret < 0) goto add_susp_cleanup; @@ -1437,7 +1437,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, } } } else if(ecma119_is_dedicated_reloc_dir(t, n) && - (t->rr_reloc_flags & 1)) { + (t->opts->rr_reloc_flags & 1)) { /* The dedicated relocation directory shall be marked by RE */ ret = rrip_add_RE(t, node, info); if (ret < 0) @@ -1740,7 +1740,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, /* "." or ".." entry */ /* write the NM entry */ - if (t->rrip_version_1_10) { + if (t->opts->rrip_version_1_10) { /* RRIP-1.10: "NM" System Use Fields recorded for the ISO 9660 directory records with names (00) and (01), used to designate the @@ -1780,12 +1780,12 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, * Note that SP entry was already added above */ - if (t->rrip_version_1_10) { + if (t->opts->rrip_version_1_10) { rrip_er_len = 237; } else { rrip_er_len = 182; } - if (t->aaip && !t->aaip_susp_1_10) { + if (t->opts->aaip && !t->opts->aaip_susp_1_10) { aaip_er_len = 160; } @@ -1804,7 +1804,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, if (ret < 0) { goto add_susp_cleanup; } - if (t->aaip && !t->aaip_susp_1_10) { + if (t->opts->aaip && !t->opts->aaip_susp_1_10) { ret = aaip_add_ER(t, info, 0); if (ret < 0) { goto add_susp_cleanup; diff --git a/libisofs/system_area.c b/libisofs/system_area.c index 870f2c5..cfb5d4b 100644 --- a/libisofs/system_area.c +++ b/libisofs/system_area.c @@ -138,13 +138,14 @@ int iso_compute_append_partitions(Ecma119Image *t, int flag) else cyl_size /= 4; } - pos = (t->vol_space_size + t->ms_block); + pos = (t->vol_space_size + t->opts->ms_block); for (i = 0; i < ISO_MAX_PARTITIONS; i++) { - if (t->appended_partitions[i] == NULL) + if (t->opts->appended_partitions[i] == NULL) continue; - if (t->appended_partitions[i][0] == 0) + if (t->opts->appended_partitions[i][0] == 0) continue; - ret = compute_partition_size(t->appended_partitions[i], &size, 0); + ret = compute_partition_size(t->opts->appended_partitions[i], &size, + 0); if (ret < 0) return ret; add_pos = 0; @@ -706,8 +707,8 @@ static int make_sun_disk_label(Ecma119Image *t, uint8_t *buf, int flag) memset(buf, 0, 512); /* 0 - 127 | label | ASCII Label */ - if (t->ascii_disc_label[0]) - strncpy((char *) buf, t->ascii_disc_label, 128); + if (t->opts->ascii_disc_label[0]) + strncpy((char *) buf, t->opts->ascii_disc_label, 128); else strcpy((char *) buf, "CD-ROM Disc with Sun sparc boot created by libisofs"); @@ -755,7 +756,7 @@ static int make_sun_disk_label(Ecma119Image *t, uint8_t *buf, int flag) /* Set partition 1 to describe ISO image and compute checksum */ t->appended_part_start[0] = 0; t->appended_part_size[0] = t->curblock; - ret = write_sun_partition_entry(1, t->appended_partitions, + ret = write_sun_partition_entry(1, t->opts->appended_partitions, t->appended_part_start, t->appended_part_size, ISO_SUN_CYL_SIZE, buf, 0); if (ret < 0) @@ -957,7 +958,7 @@ static int fill_apm_gaps(Ecma119Image *t, uint32_t img_blocks) char gap_name[33]; if (t->apm_req_flags & 4) - block_fac = 2048 / t->apm_block_size; + block_fac = 2048 / t->opts->apm_block_size; /* Find out whether an entry with start_block <= 1 is requested */ for (i = 0; i < t->apm_req_count; i++) { @@ -1047,7 +1048,7 @@ static int rectify_apm(Ecma119Image *t) return 1; if (t->gpt_req_count > 0 && - t->apm_block_size != 2048 && t->apm_req_count > 0) { + t->opts->apm_block_size != 2048 && t->apm_req_count > 0) { iso_msgs_submit(0, "GPT and APM requested. APM block size would have to be 2048.", 0, "FAILURE", 0); @@ -1077,7 +1078,7 @@ static int iso_write_apm(Ecma119Image *t, uint32_t img_blocks, uint8_t *buf, }; if (t->apm_req_flags & 4) - block_fac = 2048 / t->apm_block_size; + block_fac = 2048 / t->opts->apm_block_size; if (t->apm_req_count <= 0) return 2; @@ -1097,7 +1098,7 @@ static int iso_write_apm(Ecma119Image *t, uint32_t img_blocks, uint8_t *buf, } /* If block size is larger than 512, then not all 63 entries will fit */ - if ((t->apm_req_count + 1) * t->apm_block_size > 32768) + if ((t->apm_req_count + 1) * t->opts->apm_block_size > 32768) return ISO_BOOT_TOO_MANY_APM; /* Block 1 describes the APM itself */ @@ -1109,15 +1110,15 @@ static int iso_write_apm(Ecma119Image *t, uint32_t img_blocks, uint8_t *buf, possible MBR. */ memcpy(buf, block0_template, 8); - buf[2]= (t->apm_block_size >> 8) & 0xff; + buf[2]= (t->opts->apm_block_size >> 8) & 0xff; buf[3]= 0; } /* Write APM Block 1 to t->apm_req_count */ for (i = 0; i < t->apm_req_count; i++) { - ret = iso_write_apm_entry(t, t->apm_block_size, t->apm_req[i], - buf + (i + 1) * t->apm_block_size, t->apm_req_count, - i == 0); + ret = iso_write_apm_entry(t, t->opts->apm_block_size, t->apm_req[i], + buf + (i + 1) * t->opts->apm_block_size, t->apm_req_count, + i == 0); if (ret < 0) return ret; } @@ -1453,7 +1454,7 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) last_partition = 8; } for (i = first_partition - 1; i <= last_partition - 1; i++) - if (t->appended_partitions[i] != NULL) { + if (t->opts->appended_partitions[i] != NULL) { will_append = 1; break; } @@ -1577,14 +1578,14 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) ret = make_sun_disk_label(t, buf, 0); if (ret != ISO_SUCCESS) return ret; - } else if ((t->partition_offset > 0 || will_append) && sa_type == 0 && - t->mbr_req_count == 0) { + } else if ((t->opts->partition_offset > 0 || will_append) && + sa_type == 0 && t->mbr_req_count == 0) { /* Write a simple partition table. */ ret = make_grub_msdos_label(img_blocks, t->partition_secs_per_head, t->partition_heads_per_cyl, buf, 2); if (ret != ISO_SUCCESS) /* error should never happen */ return ISO_ASSERT_FAILURE; - if (t->partition_offset == 0) { + if (t->opts->partition_offset == 0) { /* Re-write partion entry 1 : start at 0, type Linux */ ret = write_mbr_partition_entry(1, 0x83, (uint64_t) 0, (uint64_t) img_blocks, @@ -1595,12 +1596,13 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) } } - if (t->partition_offset > 0 && sa_type == 0 && t->mbr_req_count == 0) { + if (t->opts->partition_offset > 0 && sa_type == 0 && + t->mbr_req_count == 0) { /* Adjust partition table to partition offset. With t->mbr_req_count > 0 this has already been done, */ img_blocks = t->curblock; /* value might be altered */ - ret = iso_offset_partition_start(img_blocks, t->partition_offset, + ret = iso_offset_partition_start(img_blocks, t->opts->partition_offset, t->partition_secs_per_head, t->partition_heads_per_cyl, buf, 0); if (ret != ISO_SUCCESS) /* error should never happen */ @@ -1611,17 +1613,19 @@ int iso_write_system_area(Ecma119Image *t, uint8_t *buf) made so far. Overwriting those from t->mbr_req is not allowed. */ for (i = first_partition - 1; i <= last_partition - 1; i++) { - if (t->appended_partitions[i] == NULL) + if (t->opts->appended_partitions[i] == NULL) continue; if (i < t->mbr_req_count) return ISO_BOOT_MBR_COLLISION; if (sa_type == 3) { - ret = write_sun_partition_entry(i + 1, t->appended_partitions, + ret = write_sun_partition_entry(i + 1, + t->opts->appended_partitions, t->appended_part_start, t->appended_part_size, ISO_SUN_CYL_SIZE, - buf, t->appended_partitions[i][0] == 0); + buf, t->opts->appended_partitions[i][0] == 0); } else { - ret = write_mbr_partition_entry(i + 1, t->appended_part_types[i], + ret = write_mbr_partition_entry(i + 1, + t->opts->appended_part_types[i], (uint64_t) t->appended_part_start[i], (uint64_t) t->appended_part_size[i], t->partition_secs_per_head, t->partition_heads_per_cyl, @@ -1690,7 +1694,7 @@ int iso_align_isohybrid(Ecma119Image *t, int flag) if (ret < 0) goto ex; - img_blocks = t->curblock + t->tail_blocks + t->gpt_backup_size; + img_blocks = t->curblock + t->opts->tail_blocks + t->gpt_backup_size; imgsize = ((off_t) img_blocks) * (off_t) 2048; if (((t->system_area_options & 3) || always_align) && (off_t) (t->partition_heads_per_cyl * t->partition_secs_per_head @@ -1766,7 +1770,7 @@ int iso_align_isohybrid(Ecma119Image *t, int flag) (int) cylsize); iso_msgs_submit(0, msg, 0, "WARNING", 0); } else { - t->tail_blocks += frac / 2048; + t->opts->tail_blocks += frac / 2048; } ret = ISO_SUCCESS; ex:; @@ -2059,7 +2063,8 @@ static int precompute_gpt(Ecma119Image *t) /* Determine GPT partition start in System Area, */ gpt_part_start = 0; if (t->apm_req_count > 0) - gpt_part_start = (t->apm_req_count + 1) * (t->apm_block_size / 512); + gpt_part_start = (t->apm_req_count + 1) * + (t->opts->apm_block_size / 512); if (gpt_part_start < 2) gpt_part_start = 2; else if (gpt_part_start >= 64) @@ -2222,11 +2227,12 @@ static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer) t = writer->target; with_chrp = ((t->system_area_options & 0x3cff) == 0x0400); - if (t->efi_boot_partition != NULL || (t->hfsplus && !with_chrp) || + if (t->opts->efi_boot_partition != NULL || + (t->opts->hfsplus && !with_chrp) || t->gpt_req_count > 0) will_have_gpt = 1; - if (t->efi_boot_partition != NULL) { + if (t->opts->efi_boot_partition != NULL) { if (t->efi_boot_part_filesrc != NULL) { /* A file in the emerging ISO image shall store its content as prepended partition. @@ -2239,7 +2245,7 @@ static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer) t->efi_boot_part_size += (src->sections[i].size + 2047) / 2048; } } else { - ret = compute_partition_size(t->efi_boot_partition, + ret = compute_partition_size(t->opts->efi_boot_partition, &(t->efi_boot_part_size), 0); if (ret < 0) return ret; @@ -2256,7 +2262,7 @@ static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer) if (with_chrp) { /* CHRP is not compatible with any other partition in MBR */ - if (t->prep_partition != NULL || t->fat || will_have_gpt || + if (t->opts->prep_partition != NULL || t->opts->fat || will_have_gpt || t->mbr_req_count > 0) return ISO_BOOT_MBR_OVERLAP; ret = iso_quick_mbr_entry(t, (uint64_t) 0, (uint64_t) 0, @@ -2266,16 +2272,16 @@ static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer) return ISO_SUCCESS; } - if (t->prep_partition != NULL) { - ret = compute_partition_size(t->prep_partition, &(t->prep_part_size), - 0); + if (t->opts->prep_partition != NULL) { + ret = compute_partition_size(t->opts->prep_partition, + &(t->prep_part_size), 0); if (ret < 0) return ret; } - if (t->prep_part_size > 0 || t->fat || will_have_gpt) { + if (t->prep_part_size > 0 || t->opts->fat || will_have_gpt) { /* Protecting MBR entry for ISO start or whole ISO */ ret = iso_quick_mbr_entry(t, will_have_gpt ? (uint64_t) 1 : - ((uint64_t) t->partition_offset) * 4, + ((uint64_t) t->opts->partition_offset) * 4, (uint64_t) 0, will_have_gpt ? 0xee : 0xcd, 0, 0); if (ret < 0) @@ -2289,11 +2295,11 @@ static int partprepend_writer_compute_data_blocks(IsoImageWriter *writer) return ret; t->curblock += t->prep_part_size; } - if (t->prep_part_size > 0 || t->fat) { + if (t->prep_part_size > 0 || t->opts->fat) { /* FAT partition or protecting MBR entry for ISO end */ ret = iso_quick_mbr_entry(t, ((uint64_t) t->curblock) * 4, (uint64_t) 0, - t->fat ? 0x0c : 0xcd, 0, 0); + t->opts->fat ? 0x0c : 0xcd, 0, 0); if (ret < 0) return ret; } @@ -2315,21 +2321,21 @@ static int partprepend_writer_write_data(IsoImageWriter *writer) t = writer->target; - if (t->efi_boot_partition != NULL && t->efi_boot_part_size) { + if (t->opts->efi_boot_partition != NULL && t->efi_boot_part_size) { if (t->efi_boot_part_filesrc != NULL) { ret = iso_filesrc_write_data(t, t->efi_boot_part_filesrc, NULL, NULL, 0); } else { - ret = iso_write_partition_file(t, t->efi_boot_partition, + ret = iso_write_partition_file(t, t->opts->efi_boot_partition, (uint32_t) 0, t->efi_boot_part_size, 0); } if (ret < 0) return ret; } - if (t->prep_partition != NULL && t->prep_part_size) { - ret = iso_write_partition_file(t, t->prep_partition, (uint32_t) 0, - t->prep_part_size, 0); + if (t->opts->prep_partition != NULL && t->prep_part_size) { + ret = iso_write_partition_file(t, t->opts->prep_partition, + (uint32_t) 0, t->prep_part_size, 0); if (ret < 0) return ret; } diff --git a/libisofs/util.c b/libisofs/util.c index 2d79411..118f209 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -2246,3 +2246,20 @@ void iso_smash_chars_for_joliet(uint16_t *name) set_ucsbe(name + i, '_'); } + +int iso_clone_mem(char *in, char **out, size_t size) +{ + if (in == NULL) { + *out = NULL; + return 1; + } + if (size == 0) + size = strlen(in) + 1; + *out = calloc(1, size); + if (*out == NULL) + return ISO_OUT_OF_MEM; + memcpy(*out, in, size); + return 1; +} + + diff --git a/libisofs/util.h b/libisofs/util.h index f311333..274cf4e 100644 --- a/libisofs/util.h +++ b/libisofs/util.h @@ -611,6 +611,15 @@ void *iso_alloc_mem(size_t size, size_t count, int flag); } +/* + @param in Valid memory or NULL + @param out Returns valid memory or NULL + @param size Number of bytes to copy. 0 means strlen(in)+1 if not NULL. + @return 1 or ISO_OUT_OF_MEM +*/ +int iso_clone_mem(char *in, char **out, size_t size); + + /* ------------------------------------------------------------------------- */