diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 2d5c061..ff1b3d2 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -1872,7 +1872,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) } strcpy(target->ascii_disc_label, opts->ascii_disc_label); for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) { - target->hfsplus_blessed[i] = opts->hfsplus_blessed[i]; + target->hfsplus_blessed[i] = src->hfsplus_blessed[i]; if (target->hfsplus_blessed[i] != NULL) iso_node_ref(target->hfsplus_blessed[i]); } @@ -2607,8 +2607,6 @@ int iso_write_opts_new(IsoWriteOpts **opts, int profile) wopts->allow_dir_id_ext = 0; wopts->old_empty = 0; wopts->untranslated_name_len = 0; - for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) - wopts->hfsplus_blessed[i] = NULL; *opts = wopts; return ISO_SUCCESS; @@ -2635,9 +2633,6 @@ void iso_write_opts_free(IsoWriteOpts *opts) for (i = 0; i < ISO_MAX_PARTITIONS; i++) if (opts->appended_partitions[i] != NULL) free(opts->appended_partitions[i]); - for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) - if (opts->hfsplus_blessed[i] != NULL) - iso_node_unref(opts->hfsplus_blessed[i]); free(opts); } @@ -3231,12 +3226,3 @@ int iso_write_opts_set_disc_label(IsoWriteOpts *opts, char *label) return ISO_SUCCESS; } -/* API */ -int iso_write_opts_bless(IsoWriteOpts *opts, enum IsoHfsplusBlessings blessing, - IsoNode *node, int flag) -{ - /* >>> */; - - return 0; -} - diff --git a/libisofs/ecma119.h b/libisofs/ecma119.h index 99ed4b1..29b5f68 100644 --- a/libisofs/ecma119.h +++ b/libisofs/ecma119.h @@ -444,13 +444,6 @@ struct iso_write_opts { */ char ascii_disc_label[ISO_DISC_LABEL_SIZE]; - /* Pointers to directories or files which shall be get a HFS+ blessing. - libisofs/hfsplus.c et.al. will compare these pointers - with the ->node pointer of Ecma119Nodes. - See libisofs.h - */ - IsoNode *hfsplus_blessed[ISO_HFSPLUS_BLESS_MAX]; - }; typedef struct ecma119_image Ecma119Image; diff --git a/libisofs/image.c b/libisofs/image.c index 6290ea7..77276de 100644 --- a/libisofs/image.c +++ b/libisofs/image.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2007 Vreixo Formoso - * Copyright (c) 2009 Thomas Schmitt + * Copyright (c) 2009 - 2012 Thomas Schmitt * * This file is part of the libisofs project; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -93,6 +93,9 @@ int iso_image_new(const char *name, IsoImage **image) img->checksum_idx_count = 0; img->checksum_array = NULL; img->generator_is_running = 0; + for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) + img->hfsplus_blessed[i] = NULL; + *image = img; return ISO_SUCCESS; } @@ -112,20 +115,22 @@ void iso_image_ref(IsoImage *image) */ void iso_image_unref(IsoImage *image) { - if (--image->refcount == 0) { - int nexcl; + int nexcl, i; + if (--image->refcount == 0) { /* we need to free the image */ + if (image->user_data_free != NULL) { /* free attached data */ image->user_data_free(image->user_data); } - for (nexcl = 0; nexcl < image->nexcludes; ++nexcl) { free(image->excludes[nexcl]); } free(image->excludes); - + for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) + if (image->hfsplus_blessed[i] != NULL) + iso_node_unref(image->hfsplus_blessed[i]); iso_node_unref((IsoNode*)image->root); iso_node_builder_unref(image->builder); iso_filesystem_unref(image->fs); @@ -657,3 +662,48 @@ int iso_image_give_up_mips_boot(IsoImage *image, int flag) image->num_mips_boot_files = 0; return ISO_SUCCESS; } + +/* API */ +int iso_image_hfsplus_bless(IsoImage *img, enum IsoHfsplusBlessings blessing, + IsoNode *node, int flag) +{ + unsigned int i, ok = 0; + + if (flag & 2) { + /* Delete any blessing */ + for (i = 0; i < ISO_HFSPLUS_BLESS_MAX; i++) { + if (img->hfsplus_blessed[i] == node || node == NULL) { + img->hfsplus_blessed[i] = NULL; + ok = 1; + } + } + return ok; + } + if (blessing == ISO_HFSPLUS_BLESS_MAX) + return ISO_WRONG_ARG_VALUE; + if (flag & 1) { + /* Delete a particular blessing */ + if (img->hfsplus_blessed[blessing] == node || node == NULL) { + img->hfsplus_blessed[blessing] = NULL; + return 1; + } + return 0; + } + + /* No two hats on one node */ + for (i = 0; i < ISO_HFSPLUS_BLESS_MAX && node != NULL; i++) + if (i != blessing && img->hfsplus_blessed[i] == node) + return 0; + /* Enforce correct file type */ + if (blessing == ISO_HFSPLUS_BLESS_INTEL_BOOTFILE) { + if (node->type != LIBISO_FILE) + return 0; + } else { + if (node->type != LIBISO_DIR) + return 0; + } + + img->hfsplus_blessed[blessing] = node; + return 1; +} + diff --git a/libisofs/image.h b/libisofs/image.h index 873aca0..945d627 100644 --- a/libisofs/image.h +++ b/libisofs/image.h @@ -180,6 +180,13 @@ struct Iso_Image */ int generator_is_running; + /* Pointers to directories or files which shall be get a HFS+ blessing. + * libisofs/hfsplus.c et.al. will compare these pointers + * with the ->node pointer of Ecma119Nodes. + * See libisofs.h + */ + IsoNode *hfsplus_blessed[ISO_HFSPLUS_BLESS_MAX]; + }; diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 1863dce..8a158c3 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -6723,29 +6723,31 @@ enum IsoHfsplusBlessings { * Issue a blessing to a particular IsoNode. If the blessing is already issued * to some file, then it gets revoked from that one. * - * @param opts - * The option set to be manipulated. + * @param image + * The image to manipulate. * @param blessing - * The kind of blessing to be issued. Use + * The kind of blessing to be issued. * @param node * The file that shall be blessed. It must actually be an IsoDir or * IsoFile as is appropriate for the kind of blessing. (See above enum.) * The node may not yet bear a blessing other than the desired one. + * If node is NULL, then the blessing will be revoked from any node + * which bears it. * @param flag * Bitfield for control purposes. - * bit0= Revoke blessing rather than issue it - * bit1= Revoke any blessing of the node, - * regardless of parameter blessing + * bit0= Revoke blessing if node != NULL bears it. + * bit1= Revoke any blessing of the node, regardless of parameter + * blessing. If node is NULL, then revoke all blessings in opts. * @return - * 1 means successful blessing or revokation of an existing blessing - * 0 means that the blessing could not be issued, - * or that the node was not blessed and revokation was desired - * <0 is one of the listed error codes + * 1 means successful blessing or revokation of an existing blessing. + * 0 means the node already bears another blessing, or is of wrong type, + * or that the node was not blessed and revokation was desired. + * <0 is one of the listed error codes. * * @since 1.2.4 */ -int iso_write_opts_bless(IsoWriteOpts *opts, enum IsoHfsplusBlessings blessing, - IsoNode *node, int flag); +int iso_image_hfsplus_bless(IsoImage *img, enum IsoHfsplusBlessings blessing, + IsoNode *node, int flag); /************ Error codes and return values for libisofs ********************/ diff --git a/libisofs/libisofs.ver b/libisofs/libisofs.ver index 0cad54c..aedf021 100644 --- a/libisofs/libisofs.ver +++ b/libisofs/libisofs.ver @@ -105,6 +105,7 @@ iso_image_get_system_id; iso_image_get_volset_id; iso_image_get_volume_id; iso_image_give_up_mips_boot; +iso_image_hfsplus_bless; iso_image_import; iso_image_new; iso_image_ref; @@ -262,7 +263,6 @@ iso_tree_set_replace_mode; iso_tree_set_report_callback; iso_util_decode_md5_tag; iso_write_opts_attach_jte; -iso_write_opts_bless; iso_write_opts_detach_jte; iso_write_opts_free; iso_write_opts_get_data_start;