New API calls iso_assess_written_features(), iso_read_image_feature_named(), iso_read_image_features_text()

This commit is contained in:
Thomas Schmitt 2022-09-20 09:51:39 +02:00
parent 9b7ccc9727
commit 83e5832ed0
9 changed files with 1060 additions and 48 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2007 Vreixo Formoso
* Copyright (c) 2009 - 2015 Thomas Schmitt
* Copyright (c) 2009 - 2022 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
@ -204,6 +204,10 @@ int iso_image_new(const char *name, IsoImage **image)
img->collision_warnings = 0;
img->imported_sa_info = NULL;
img->blind_on_local_get_attrs = 0;
img->do_deeper_tree_inspection = 0;
img->tree_loaded = 0;
img->rr_loaded = 0;
img->tree_compliance = NULL;
*image = img;
return ISO_SUCCESS;
@ -271,6 +275,8 @@ void iso_image_unref(IsoImage *image)
free(image->system_area_data);
iso_image_free_checksums(image, 0);
iso_imported_sa_unref(&(image->imported_sa_info), 0);
if (image->tree_compliance != NULL)
iso_write_opts_free(image->tree_compliance);
free(image);
}
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2007 Vreixo Formoso
* Copyright (c) 2009 - 2017 Thomas Schmitt
* Copyright (c) 2009 - 2022 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
@ -252,6 +252,13 @@ struct Iso_Image
*/
int blind_on_local_get_attrs;
/* Deeper tree inspection when reading an IsoImage assesses traces of the
used write options.
*/
int do_deeper_tree_inspection;
int tree_loaded; /* 0=ISO 9660/ECMA-119 1=Joliet 2=ISO 9660:1999 */
int rr_loaded; /* 0=plain ISO 9660/ECMA-119 1=Rock Ridge */
IsoWriteOpts *tree_compliance;
};
@ -443,5 +450,9 @@ int iso_imported_sa_new(struct iso_imported_sys_area **sa_info, int flag);
int iso_imported_sa_unref(struct iso_imported_sys_area **sa_info, int flag);
void iso_image_assess_ecma119_name(IsoImage *image, struct stat *info,
char *path, char *name);
void iso_image_assess_joliet_name(IsoImage *image, struct stat *info,
char *path, char *name);
#endif /*LIBISO_IMAGE_H_*/

View File

@ -3245,7 +3245,40 @@ int iso_image_import(IsoImage *image, IsoDataSource *src, IsoReadOpts *opts,
IsoReadImageFeatures **features);
/**
* Destroy an IsoReadImageFeatures object obtained with iso_image_import.
* Assess features of the importable directory trees of src and an estimation
* of the write options which would cause the recognized features.
* This goes deeper than the feature assessment of iso_image_import(), e.g. by
* inspecting file names.
*
* For the parameters "src", "opts", and "features" see also the description of
* iso_image_import().
*
* @param src
* Data Source from which old image will be read.
* @param opts
* Options for image import. Settings about tree choice will be ignored.
* @param features
* Returns the pointer to a newly allocated and filled IsoReadImageFeatures
* object. NULL is not allowed, other than with iso_image_import().
* If *features is returned as non-NULL, then it should be freed with
* iso_read_image_features_destroy() when no more needed.
* @param write_opts
* Returns the pointer to a newly allocated and filled IsoWriteOpts object.
* If *write_opts is returned as non-NULL, then it should be freed with
* iso_write_opts_free() when no more needed.
*
* @return
* 1 on success, < 0 on error
*
* @since 1.5.6
*/
int iso_assess_written_features(IsoDataSource *src, IsoReadOpts *opts,
IsoReadImageFeatures **features,
IsoWriteOpts **write_opts);
/**
* Destroy an IsoReadImageFeatures object obtained with iso_image_import() or
* iso_assess_written_features().
*
* @since 0.6.2
*/
@ -3303,6 +3336,99 @@ int iso_read_image_features_tree_loaded(IsoReadImageFeatures *f);
*/
int iso_read_image_features_rr_loaded(IsoReadImageFeatures *f);
/**
* Get a named feature as text, num_value, or pt_value depending on its type.
* The set of named features includes the features which can be inquired by
* own iso_read_image_features_*() functions:
* size See iso_read_image_features_get_size()
* rockridge See iso_read_image_features_has_rockridge()
* iso_write_opts_set_rockridge()
* joliet See iso_read_image_features_has_joliet()
* iso_write_opts_set_joliet()
* iso1999 See iso_read_image_features_has_iso1999()
* iso_write_opts_set_iso1999()
* eltorito See iso_read_image_features_has_eltorito()
* tree_loaded See iso_read_image_features_tree_loaded()
* rr_loaded See iso_read_image_features_rr_loaded()
* Other named features are:
* tree_loaded_text Text form of "tree_loaded":
* 0="ISO9660", 1="Joliet", 2="ISO9660:1999"
* aaip 1=AAIP information was seen, 0= no AAIP seen
* Detected traces of potential write option settings:
* iso_level See iso_write_opts_set_iso_level()
* untranslated_name_len See iso_write_opts_set_untranslated_name_len()
* allow_dir_id_ext See iso_write_opts_set_allow_dir_id_ext()
* omit_version_numbers See iso_write_opts_set_omit_version_numbers()
* allow_deep_paths See iso_write_opts_set_allow_deep_paths()
* allow_longer_paths See iso_write_opts_set_allow_longer_paths()
* max_37_char_filenames See iso_write_opts_set_max_37_char_filenames()
* no_force_dots See iso_write_opts_set_no_force_dots()
* allow_lowercase See iso_write_opts_set_allow_lowercase()
* allow_full_ascii See iso_write_opts_set_allow_full_ascii()
* relaxed_vol_atts See iso_write_opts_set_relaxed_vol_atts()
* joliet_longer_paths See iso_write_opts_set_joliet_longer_paths()
* joliet_long_names See iso_write_opts_set_joliet_long_names()
* joliet_utf16 See iso_write_opts_set_joliet_utf16()
* rrip_version_1_10 See iso_write_opts_set_rrip_version_1_10()
* rrip_1_10_px_ino See iso_write_opts_set_rrip_1_10_px_ino()
* aaip_susp_1_10 See iso_write_opts_set_aaip_susp_1_10()
* record_md5_session See iso_write_opts_set_record_md5() param session
* record_md5_files See iso_write_opts_set_record_md5() param files
*
* @param f
* A features object returned by iso_image_import() or
* iso_assess_written_features().
* @param name
* The name of the feature to be inquired.
* @param text
* If text is not NULL, *text returns a textual representation of the
* reply. Dispose *text by free(2) when no longer needed.
* @param type
* Returns which of num_value or pt_value is valid:
* 0= *num_value is valid
* 1= *pt_value is valid
* @param num_value
* Returns the numerical value of the feature if type == 0.
* @param pt_value
* Returns a pointer to a memory area inside the features object if type
* is 1. The area is not necessarily 0-terminated.
* Do _not_ dispose *pt_value and do not use it after f was disposed.
* @param pt_size
* Returns the size of the pt_value memory area if type is 1.
* This counting includes a terminating 0-byte if it is present.
* @return
* 0 = Feature was not yet examined. Reply is not valid.
* 1 = Reply is valid
* ISO_UNDEF_READ_FEATURE = Given name is not known
* <0 = other error
*
* @since 1.5.6
*/
int iso_read_image_feature_named(IsoReadImageFeatures *f, char *name,
char **text, int *type,
int64_t *num_value, void **pt_value,
size_t *pt_size);
/**
* Get all validly assessed named features as one single 0-terminated string
* consisting of single lines for each feature.
*
* @param f
* A features object returned by iso_image_import() or
* iso_assess_written_features().
* @param with_values
* If set to 1: return lines of form name=value\n
* If set to 0: return lines of form name\n
* @param feature_text
* Returns the result string. Dispose by free(2) when no longer needed.
* @return
* 1 = result is valid, <0 indicates error
*
* @since 1.5.6
*/
int iso_read_image_features_text(IsoReadImageFeatures *f, int with_values,
char **feature_text);
/**
* Increments the reference counting of the given image.
*
@ -9272,6 +9398,10 @@ int iso_conv_name_chars(IsoWriteOpts *opts, char *name, size_t name_len,
/** Cannot obtain size of zisofs compressed stream (FAILURE, HIGH, -425) */
#define ISO_ZISOFS_UNKNOWN_SIZE 0xE830FE57
/** Undefined IsoReadImageFeatures name (SORRY, HIGH, -426) */
#define ISO_UNDEF_READ_FEATURE 0xE030FE56
/* Internal developer note:
Place new error codes directly above this comment.

View File

@ -21,6 +21,7 @@ el_torito_set_load_seg;
el_torito_set_load_size;
el_torito_set_no_bootable;
el_torito_set_selection_crit;
iso_assess_written_features;
iso_conv_name_chars;
iso_crc32_gpt;
iso_data_source_new_from_file;
@ -229,6 +230,7 @@ iso_node_xinfo_make_clonable;
iso_node_zf_by_magic;
iso_nowtime;
iso_obtain_msgs;
iso_read_image_feature_named;
iso_read_image_features_destroy;
iso_read_image_features_get_size;
iso_read_image_features_has_eltorito;
@ -236,6 +238,7 @@ iso_read_image_features_has_iso1999;
iso_read_image_features_has_joliet;
iso_read_image_features_has_rockridge;
iso_read_image_features_rr_loaded;
iso_read_image_features_text;
iso_read_image_features_tree_loaded;
iso_read_opts_auto_input_charset;
iso_read_opts_free;

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2007 Vreixo Formoso
* Copyright (c) 2009 - 2016 Thomas Schmitt
* Copyright (c) 2009 - 2022 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
@ -392,8 +392,10 @@ const char *iso_error_to_msg(int errcode)
case ISO_AAIP_BAD_AASTRING:
return "Error with decoding AAIP info for ACL or xattr";
case ISO_AAIP_NO_GET_LOCAL:
case ISO_AAIP_NO_GET_LOCAL_S:
return "Error with reading ACL or xattr from local file";
case ISO_AAIP_NO_SET_LOCAL:
case ISO_AAIP_NO_SET_LOCAL_S:
return "Error with attaching ACL or xattr to local file";
case ISO_AAIP_NON_USER_NAME:
return "Unallowed attempt to set an xattr with non-userspace name";
@ -563,6 +565,8 @@ const char *iso_error_to_msg(int errcode)
return "Prevented zisofs block pointer counter underrun";
case ISO_ZISOFS_UNKNOWN_SIZE:
return "Cannot obtain size of zisofs compressed stream";
case ISO_UNDEF_READ_FEATURE:
return "Undefined IsoReadImageFeatures name";
default:
return "Unknown error";
}

View File

@ -24,6 +24,7 @@
#include "messages.h"
#include "tree.h"
#include "util.h"
#include "ecma119.h"
#include <stdlib.h>
#include <string.h>
@ -1051,6 +1052,17 @@ int iso_add_dir_src_rec(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
"Error when adding file %s", path);
goto dir_rec_continue;
}
if (image->do_deeper_tree_inspection) {
if (image->tree_loaded == 0 && image->rr_loaded == 0) {
iso_image_assess_ecma119_name(image, &info, path, name);
} else if (image->tree_loaded == 1) {
iso_image_assess_joliet_name(image, &info, path, name);
}
if (info.st_size > MAX_ISO_FILE_SECTION_SIZE &&
image->tree_compliance != NULL)
image->tree_compliance->iso_level = 3;
}
if (check_excludes(image, path)) {
iso_msg_debug(image->id, "Skipping excluded file %s", path);

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2007 Vreixo Formoso
* Copyright (c) 2007 Mario Danic
* Copyright (c) 2009 - 2019 Thomas Schmitt
* Copyright (c) 2009 - 2022 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
@ -803,18 +803,18 @@ int str2utf16be(const char *icharset, const char *input, uint16_t **output)
return ISO_SUCCESS;
}
static int valid_d_char(char c)
int valid_d_char(char c)
{
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c == '_');
}
static int valid_a_char(char c)
int valid_a_char(char c)
{
return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?') ||
(c >= 'A' && c <= 'Z') || (c == '_');
}
static int valid_j_char(uint16_t c)
int valid_j_char(uint16_t c)
{
return cmp_ucsbe(&c, ' ') != -1 && cmp_ucsbe(&c, '*') && cmp_ucsbe(&c, '/')
&& cmp_ucsbe(&c, ':') && cmp_ucsbe(&c, ';') && cmp_ucsbe(&c, '?')

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2007 Vreixo Formoso
* Copyright (c) 2009 - 2012 Thomas Schmitt
* Copyright (c) 2009 - 2022 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
@ -263,6 +263,12 @@ void iso_handle_split_utf16(uint16_t *utf_word);
int str2d_char(const char *icharset, const char *input, char **output);
int str2a_char(const char *icharset, const char *input, char **output);
/* Check for membership in the d-, a-, or j-character set */
int valid_d_char(char c);
int valid_a_char(char c);
int valid_j_char(uint16_t c);
void iso_lsb(uint8_t *buf, uint32_t num, int bytes);
void iso_lsb64(uint8_t *buf, uint64_t num);
void iso_msb(uint8_t *buf, uint32_t num, int bytes);