From 8a2fa9fe2eb50f8f363c1441e04b428cecbf11ec Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 22 Mar 2012 11:18:44 +0100 Subject: [PATCH] New API call iso_write_opts_set_allow_7bit_ascii(). --- libisofs/ecma119.c | 11 +++++++++++ libisofs/ecma119.h | 8 ++++++++ libisofs/ecma119_tree.c | 4 +++- libisofs/libisofs.h | 16 ++++++++++++++++ libisofs/libisofs.ver | 1 + libisofs/util.c | 28 ++++++++++++++++++++++------ 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 3d18479..05aec12 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -1674,6 +1674,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) 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; @@ -2756,6 +2757,16 @@ int iso_write_opts_set_allow_full_ascii(IsoWriteOpts *opts, int allow) return ISO_SUCCESS; } +int iso_write_opts_set_allow_7bit_ascii(IsoWriteOpts *opts, int allow) +{ + if (opts == NULL) { + return ISO_NULL_POINTER; + } + opts->allow_7bit_ascii = allow ? 1 : 0; + return ISO_SUCCESS; +} + + int iso_write_opts_set_relaxed_vol_atts(IsoWriteOpts *opts, int allow) { if (opts == NULL) { diff --git a/libisofs/ecma119.h b/libisofs/ecma119.h index 97d6f3a..b45ea73 100644 --- a/libisofs/ecma119.h +++ b/libisofs/ecma119.h @@ -149,6 +149,13 @@ struct iso_write_opts { */ unsigned int allow_full_ascii :1; + /** + * If not allow_full_ascii is set: allow all 7 bit characters that would + * be allowed by allow_full_ascii. But still map lowercase to uppercase if + * not allow_lowercase is set to 1. + */ + unsigned int allow_7bit_ascii :1; + /** * Allow all characters to be part of Volume and Volset identifiers on * the Primary Volume Descriptor. This breaks ISO-9660 contraints, but @@ -477,6 +484,7 @@ struct ecma119_image 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; diff --git a/libisofs/ecma119_tree.c b/libisofs/ecma119_tree.c index e19a47a..6fe0869 100644 --- a/libisofs/ecma119_tree.c +++ b/libisofs/ecma119_tree.c @@ -59,6 +59,8 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name) } else { relaxed = (int)img->allow_lowercase; } + if (img->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) { @@ -1234,7 +1236,7 @@ int ecma119_tree_create(Ecma119Image *img) /* * and we need to remangle the root directory, as the function - * above could insert new directories into the root. + * above could insert new directories into the relocation directory. * Note that recurse = 0, as we don't need to recurse. */ diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index fe322e0..feeacbe 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -1615,6 +1615,8 @@ int iso_write_opts_set_no_force_dots(IsoWriteOpts *opts, int no); * Allow lowercase characters in ISO-9660 filenames. By default, only * uppercase characters, numbers and a few other characters are allowed. * This breaks ECMA-119 specification. Use with caution. + * If lowercase is not allowed then those letters get mapped to uppercase + * letters. * * @since 0.6.2 */ @@ -1629,6 +1631,20 @@ int iso_write_opts_set_allow_lowercase(IsoWriteOpts *opts, int allow); */ int iso_write_opts_set_allow_full_ascii(IsoWriteOpts *opts, int allow); +/** + * If not iso_write_opts_set_allow_full_ascii() is set to 1: + * Allow all 7-bit characters that would be allowed by allow_full_ascii, but + * map lowercase to uppercase if iso_write_opts_set_allow_lowercase() + * is not set to 1. + * @param opts + * The option set to be manipulated. + * @param allow + * If not zero, then allow what is described above. + * + * @since 1.2.2 + */ +int iso_write_opts_set_allow_7bit_ascii(IsoWriteOpts *opts, int allow); + /** * Allow all characters to be part of Volume and Volset identifiers on * the Primary Volume Descriptor. This breaks ISO-9660 contraints, but diff --git a/libisofs/libisofs.ver b/libisofs/libisofs.ver index c894ba2..1119218 100644 --- a/libisofs/libisofs.ver +++ b/libisofs/libisofs.ver @@ -265,6 +265,7 @@ iso_write_opts_get_data_start; iso_write_opts_new; iso_write_opts_set_aaip; iso_write_opts_set_aaip_susp_1_10; +iso_write_opts_set_allow_7bit_ascii; iso_write_opts_set_allow_deep_paths; iso_write_opts_set_allow_dir_id_ext; iso_write_opts_set_allow_full_ascii; diff --git a/libisofs/util.c b/libisofs/util.c index d40bfe7..6f06cba 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -685,17 +685,27 @@ static int valid_j_char(uint16_t c) && cmp_ucsbe(&c, '\\'); } +/* @param relaxed bit0+1 0= strict ECMA-119 + 1= additionally allow lowercase (else map to upper) + 2= allow all 8-bit characters + bit2 allow all 7-bit characters (but map to upper if + not bit0+1 == 2) +*/ static char map_fileid_char(char c, int relaxed) { char upper; - if (relaxed == 2) /* all chars are allowed */ + if (c == '/') /* Allowing slashes would cause lots of confusion */ + return '_'; + if ((relaxed & 3) == 2) return c; if (valid_d_char(c)) return c; + if ((relaxed & 4) && (c & 0x7f) == c && (c < 'a' || c > 'z')) + return c; upper= toupper(c); if (valid_d_char(upper)) { - if (relaxed) { + if (relaxed & 3) { /* lower chars are allowed */ return c; } @@ -871,8 +881,11 @@ char *iso_2_fileid(const char *src) * @param size * Max len for the name * @param relaxed - * 0 only allow d-characters, 1 allow also lowe case chars, - * 2 allow all characters + * bit0+1: 0 only allow d-characters, + * 1 allow also lowe case chars, + * 2 allow all 8-bit characters, + * bit2: allow 7-bit characters (but map lowercase to uppercase if + * not bit0+1 == 2) */ char *iso_r_dirid(const char *src, int size, int relaxed) { @@ -930,8 +943,11 @@ char *iso_r_dirid(const char *src, int size, int relaxed) * @param len * Max len for the name, without taken the "." into account. * @param relaxed - * 0 only allow d-characters, 1 allow also lowe case chars, - * 2 allow all characters + * bit0+1: 0 only allow d-characters, + * 1 allow also lowe case chars, + * 2 allow all 8-bit characters, + * bit2: allow 7-bit characters (but map lowercase to uppercase if + * not bit0+1 == 2) * @param forcedot * Whether to ensure that "." is added */