xorriso  1.5.4.pl02
About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.
  Fossies Dox: xorriso-1.5.4.pl02.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

util.c File Reference
#include "util.h"
#include "libisofs.h"
#include "messages.h"
#include "joliet.h"
#include "node.h"
#include <stdlib.h>
#include <wchar.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <stdio.h>
#include <limits.h>
#include <iconv.h>
#include <locale.h>
#include <langinfo.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Include dependency graph for util.c:

Go to the source code of this file.

Data Structures

struct  iso_iconv_handle
 

Macros

#define ICONV_CONST
 
#define Libburnia_timezonE   timezone
 
#define Libisofs_use_putenV   yes
 

Functions

static int iso_iconv_open (struct iso_iconv_handle *handle, char *tocode, char *fromcode, int flag)
 
static size_t iso_iconv (struct iso_iconv_handle *handle, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int flag)
 
static int iso_iconv_close (struct iso_iconv_handle *handle, int flag)
 
int int_pow (int base, int power)
 
int iso_set_local_charset (char *name, int flag)
 
char * iso_get_local_charset (int flag)
 
int strconv (const char *str, const char *icharset, const char *ocharset, char **output)
 
int strnconvl (const char *str, const char *icharset, const char *ocharset, size_t len, char **output, size_t *out_len)
 
int strnconv (const char *str, const char *icharset, const char *ocharset, size_t len, char **output)
 
static int str2wchar (const char *icharset, const char *input, wchar_t **output)
 
int str2ascii (const char *icharset, const char *input, char **output)
 
static void set_ucsbe (uint16_t *ucs, char c)
 
static int cmp_ucsbe (const uint16_t *ucs, char c)
 
int str2ucs (const char *icharset, const char *input, uint16_t **output)
 
int str2utf16be (const char *icharset, const char *input, uint16_t **output)
 
static int valid_d_char (char c)
 
static int valid_a_char (char c)
 
static int valid_j_char (uint16_t c)
 
static char map_fileid_char (char c, int relaxed)
 
static char * iso_dirid (const char *src, int size, int relaxed)
 
char * iso_1_dirid (const char *src, int relaxed)
 
char * iso_2_dirid (const char *src)
 
char * iso_1_fileid (const char *src, int relaxed, int force_dots)
 
char * iso_2_fileid (const char *src)
 
char * iso_r_dirid (const char *src, int size, int relaxed)
 
char * iso_r_fileid (const char *src, size_t len, int relaxed, int forcedot)
 
uint16_t * iso_j_file_id (const uint16_t *src, int flag)
 
uint16_t * iso_j_dir_id (const uint16_t *src, int flag)
 
size_t ucslen (const uint16_t *str)
 
uint16_t * ucsrchr (const uint16_t *str, char c)
 
uint16_t * ucsdup (const uint16_t *str)
 
int ucscmp (const uint16_t *s1, const uint16_t *s2)
 
uint16_t * ucscpy (uint16_t *dest, const uint16_t *src)
 
uint16_t * ucsncpy (uint16_t *dest, const uint16_t *src, size_t n)
 
int str2d_char (const char *icharset, const char *input, char **output)
 
int str2a_char (const char *icharset, const char *input, char **output)
 
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)
 
void iso_bb (uint8_t *buf, uint32_t num, int bytes)
 
int iso_lsb_to_buf (char **wpt, uint32_t value, int bytes, int flag)
 
uint32_t iso_read_lsb (const uint8_t *buf, int bytes)
 
uint32_t iso_read_msb (const uint8_t *buf, int bytes)
 
uint32_t iso_read_bb (const uint8_t *buf, int bytes, int *error)
 
uint64_t iso_read_lsb64 (const uint8_t *buf)
 
uint64_t iso_read_msb64 (const uint8_t *buf)
 
void iso_datetime_7 (unsigned char *buf, time_t t, int always_gmt)
 
void iso_datetime_17 (unsigned char *buf, time_t t, int always_gmt)
 
static time_t env_timegm (struct tm *tm)
 
static int ts_is_leapyear (int tm_year)
 
static time_t ts_timegm (struct tm *tm)
 
static time_t timegm (struct tm *tm)
 
time_t iso_datetime_read_7 (const uint8_t *buf)
 
time_t iso_datetime_read_17 (const uint8_t *buf)
 
int iso_eaccess (const char *path)
 
char * iso_util_strcopy (const char *buf, size_t len)
 
char * iso_util_strcopy_untail (const char *buf, size_t len_in)
 
void strncpy_pad (char *dest, const char *src, size_t max)
 
char * ucs2str (const char *buf, size_t len)
 
void iso_lib_version (int *major, int *minor, int *micro)
 
int iso_lib_is_compatible (int major, int minor, int micro)
 
int iso_init_locale (int flag)
 
int iso_util_encode_len_bytes (uint32_t data, char *buffer, int data_len, int *result_len, int flag)
 
int iso_util_decode_len_bytes (uint32_t *data, char *buffer, int *data_len, int buffer_len, int flag)
 
int iso_util_dec_to_uint32 (char *dec, uint32_t *value, int flag)
 
int iso_util_bin_to_hex (char *target, uint8_t *bytes, int num_bytes, int flag)
 
int iso_util_hex_to_bin (char *hex, char *bin, int bin_size, int *bin_count, int flag)
 
int iso_util_tag_magic (int tag_type, char **tag_magic, int *len, int flag)
 
int iso_util_decode_md5_tag (char data[2048], int *tag_type, uint32_t *pos, uint32_t *range_start, uint32_t *range_size, uint32_t *next_tag, char md5[16], int flag)
 
int iso_util_eval_md5_tag (char *block, int desired, uint32_t lba, void *ctx, uint32_t ctx_start_lba, int *tag_type, uint32_t *next_tag, int flag)
 
void * iso_alloc_mem (size_t size, size_t count, int flag)
 
uint16_t iso_ntohs (uint16_t v)
 
uint16_t iso_htons (uint16_t v)
 
void iso_handle_split_utf16 (uint16_t *utf_word)
 
int iso_clone_mem (char *in, char **out, size_t size)
 
int iso_clone_mgtd_mem (char *in, char **out, size_t size)
 
off_t iso_scanf_io_size (char *text, int flag)
 
static int find_utf8_start (char *name, int idx, int flag)
 
int iso_truncate_rr_name (int truncate_mode, int truncate_length, char *name, int flag)
 
int iso_truncate_leaf_name (int mode, int length, char *name, int flag)
 
int iso_nowtime (time_t *now, int flag)
 

Variables

static int iso_iconv_debug = 0
 
static char libisofs_local_charset [4096] = {""}
 

Macro Definition Documentation

◆ ICONV_CONST

#define ICONV_CONST

◆ Libburnia_timezonE

#define Libburnia_timezonE   timezone

◆ Libisofs_use_putenV

#define Libisofs_use_putenV   yes

Definition at line 1705 of file util.c.

Function Documentation

◆ cmp_ucsbe()

static int cmp_ucsbe ( const uint16_t *  ucs,
char  c 
)
static
Returns
-1, 0, 1 if *ucs <, == or > than c

Definition at line 546 of file util.c.

Referenced by iso_j_file_id(), ucsrchr(), and valid_j_char().

◆ env_timegm()

static time_t env_timegm ( struct tm *  tm)
static

Definition at line 1708 of file util.c.

Referenced by timegm().

◆ find_utf8_start()

static int find_utf8_start ( char *  name,
int  idx,
int  flag 
)
static

Definition at line 2403 of file util.c.

Referenced by iso_truncate_rr_name().

◆ int_pow()

int int_pow ( int  base,
int  power 
)

Definition at line 159 of file util.c.

Referenced by mangle_single_dir().

◆ iso_1_dirid()

char* iso_1_dirid ( const char *  src,
int  relaxed 
)

Create a level 1 directory identifier.

Parameters
srcThe identifier, in ASCII encoding.
relaxed0 only allow d-characters, 1 allow also lowe case chars, 2 allow all characters

Definition at line 882 of file util.c.

References iso_dirid().

Referenced by iso_get_ecma119_name().

◆ iso_1_fileid()

char* iso_1_fileid ( const char *  src,
int  relaxed,
int  force_dots 
)

Create a level 1 file identifier that consists of a name, in 8.3 format. Note that version number is not added to the file name

Parameters
srcThe identifier, in ASCII encoding.
relaxed0 only allow d-characters, 1 allow also lowe case chars, 2 allow all characters
force_dotsIf 1 then prepend empty extension by SEPARATOR1 = '.'

Definition at line 892 of file util.c.

References map_fileid_char(), and valid_d_char().

Referenced by iso_get_ecma119_name().

◆ iso_2_dirid()

char* iso_2_dirid ( const char *  src)

Create a level 2 directory identifier.

Parameters
srcThe identifier, in ASCII encoding.

Definition at line 887 of file util.c.

References iso_dirid().

Referenced by iso_get_ecma119_name().

◆ iso_2_fileid()

char* iso_2_fileid ( const char *  src)

Create a level 2 file identifier. Note that version number is not added to the file name

Parameters
srcThe identifier, in ASCII encoding.

Definition at line 960 of file util.c.

References valid_d_char().

Referenced by iso_get_ecma119_name().

◆ iso_alloc_mem()

void* iso_alloc_mem ( size_t  size,
size_t  count,
int  flag 
)

Definition at line 2297 of file util.c.

References iso_msg_submit(), and ISO_OUT_OF_MEM.

Referenced by iso_impsysa_report_blockpath().

◆ iso_bb()

◆ iso_clone_mem()

int iso_clone_mem ( char *  in,
char **  out,
size_t  size 
)

Definition at line 2336 of file util.c.

References ISO_OUT_OF_MEM, and ISO_SUCCESS.

Referenced by iso_clone_mgtd_mem(), iso_get_rr_name(), and iso_write_opts_clone().

◆ iso_clone_mgtd_mem()

int iso_clone_mgtd_mem ( char *  in,
char **  out,
size_t  size 
)

Definition at line 2352 of file util.c.

References iso_clone_mem().

Referenced by hppa_palo_set_path(), and iso_image_set_hppa_palo().

◆ iso_datetime_17()

void iso_datetime_17 ( unsigned char *  buf,
time_t  t,
int  always_gmt 
)

Definition at line 1633 of file util.c.

References Libburnia_timezonE, and MIN.

Referenced by ecma119_set_voldescr_times().

◆ iso_datetime_7()

void iso_datetime_7 ( unsigned char *  buf,
time_t  t,
int  always_gmt 
)

Definition at line 1574 of file util.c.

References Libburnia_timezonE.

Referenced by rrip_add_TF(), and write_one_dir_record().

◆ iso_datetime_read_17()

time_t iso_datetime_read_17 ( const uint8_t *  buf)

Definition at line 1841 of file util.c.

References timegm().

Referenced by ecma119_determine_now_time(), and read_rr_TF().

◆ iso_datetime_read_7()

time_t iso_datetime_read_7 ( const uint8_t *  buf)

Definition at line 1826 of file util.c.

References timegm().

Referenced by read_rr_TF().

◆ iso_dirid()

static char* iso_dirid ( const char *  src,
int  size,
int  relaxed 
)
static

Definition at line 854 of file util.c.

References map_fileid_char(), and valid_d_char().

Referenced by iso_1_dirid(), and iso_2_dirid().

◆ iso_eaccess()

int iso_eaccess ( const char *  path)

Check whether the caller process has read access to the given local file.

Returns
1 on success (i.e, the process has read access), < 0 on error (including ISO_FILE_ACCESS_DENIED on access denied to the specified file or any directory on the path).

Definition at line 1866 of file util.c.

References ISO_FILE_ACCESS_DENIED, ISO_FILE_BAD_PATH, ISO_FILE_DOESNT_EXIST, ISO_FILE_ERROR, ISO_OUT_OF_MEM, and ISO_SUCCESS.

Referenced by iso_data_source_new_from_file(), and lfs_access().

◆ iso_get_local_charset()

char* iso_get_local_charset ( int  flag)

Obtain the local charset as currently assumed by libisofs. The result points to internal memory. It is volatile and must not be altered.

Parameters
flagUnused yet. Submit 0.
Since
0.6.12

Definition at line 185 of file util.c.

References libisofs_local_charset.

Referenced by ecma119_image_new(), iso_conv_name_chars(), iso_image_filesystem_new(), ucs2str(), and Xorriso_get_local_charset().

◆ iso_handle_split_utf16()

void iso_handle_split_utf16 ( uint16_t *  utf_word)

Check whether utf_word is the first surrogate word of a pair. If so, change it to UTF-16 character '_'.

Definition at line 2326 of file util.c.

References set_ucsbe().

Referenced by iso_j_dir_id(), iso_j_file_id(), ucsncpy(), and ucsncpy_pad().

◆ iso_htons()

uint16_t iso_htons ( uint16_t  v)

Definition at line 2313 of file util.c.

References iso_msb().

Referenced by iso_get_hfsplus_name().

◆ iso_iconv()

static size_t iso_iconv ( struct iso_iconv_handle handle,
char **  inbuf,
size_t *  inbytesleft,
char **  outbuf,
size_t *  outbytesleft,
int  flag 
)
static

◆ iso_iconv_close()

static int iso_iconv_close ( struct iso_iconv_handle handle,
int  flag 
)
static

◆ iso_iconv_open()

static int iso_iconv_open ( struct iso_iconv_handle handle,
char *  tocode,
char *  fromcode,
int  flag 
)
static

◆ iso_init_locale()

int iso_init_locale ( int  flag)

Set up locale by LC_* environment variables.

Definition at line 2038 of file util.c.

Referenced by iso_init_with_flag().

◆ iso_j_dir_id()

uint16_t* iso_j_dir_id ( const uint16_t *  src,
int  flag 
)

Create a Joliet directory identifier that consists of name and optionally extension. The combined name and extension length will not exceed 128 bytes, and the name and extension will be separated (.). All characters consist of 2 bytes and the resulting string is NULL-terminated by a 2-byte NULL.

Parameters
flagbit1= allow 103 characters rather than 64
Returns
NULL if the original name and extension both are of length 0.

Definition at line 1298 of file util.c.

References iso_handle_split_utf16(), LIBISO_ALLOC_MEM_VOID, LIBISO_FREE_MEM, LIBISO_JOLIET_NAME_MAX, set_ucsbe(), ucsdup(), ucslen(), and valid_j_char().

Referenced by iso_get_joliet_name().

◆ iso_j_file_id()

uint16_t* iso_j_file_id ( const uint16_t *  src,
int  flag 
)

Create a Joliet file identifier that consists of name and extension. The combined name and extension length will normally not exceed 64 characters (= 128 bytes). The name and the extension will be separated (.). All characters consist of 2 bytes and the resulting string is NULL-terminated by a 2-byte NULL.

Note that version number and (;1) is not appended.

Parameters
flagbit0= no_force_dots bit1= allow 103 characters rather than 64
Returns
NULL if the original name and extension both are of length 0.

Definition at line 1215 of file util.c.

References cmp_ucsbe(), iso_handle_split_utf16(), LIBISO_ALLOC_MEM_VOID, LIBISO_FREE_MEM, LIBISO_JOLIET_NAME_MAX, set_ucsbe(), ucsdup(), ucslen(), ucsrchr(), and valid_j_char().

Referenced by iso_get_joliet_name().

◆ iso_lib_is_compatible()

int iso_lib_is_compatible ( int  major,
int  minor,
int  micro 
)

Check at runtime if the library is ABI compatible with the given version. NOTE: This function may be called before iso_init().

Returns
1 lib is compatible, 0 is not.
Since
0.6.2

Definition at line 2024 of file util.c.

References iso_lib_version().

Referenced by isoburn_initialize().

◆ iso_lib_version()

void iso_lib_version ( int *  major,
int *  minor,
int *  micro 
)

Get version of the libisofs library at runtime. NOTE: This function may be called before iso_init().

Since
0.6.2

Definition at line 2008 of file util.c.

References iso_lib_header_version_major, iso_lib_header_version_micro, and iso_lib_header_version_minor.

Referenced by iso_lib_is_compatible(), isoburn_initialize(), Xorriso_preparer_string(), and Xorriso_report_lib_versions().

◆ iso_lsb()

◆ iso_lsb64()

void iso_lsb64 ( uint8_t *  buf,
uint64_t  num 
)

Definition at line 1486 of file util.c.

Referenced by ziso_stream_compress(), and zisofs_add_ZF().

◆ iso_lsb_to_buf()

int iso_lsb_to_buf ( char **  wpt,
uint32_t  value,
int  bytes,
int  flag 
)

Definition at line 1510 of file util.c.

Referenced by iso_write_gpt_entry(), and iso_write_gpt_header_block().

◆ iso_msb()

◆ iso_nowtime()

int iso_nowtime ( time_t *  now,
int  flag 
)

Inquire and maybe define the time which is considered to be "now" and used for timestamps of freshly created ISO nodes and as default of image timestamps. If ever, this should normally be enabled and defined before iso_image_new(). If it is disabled, time(NULL) is considered to be "now".

Parameters
nowReturns the "now" value and maybe submits it as definition.
flagBitfield for control purposes bit0= *now contains the time to be set as nowtime override. Enable the override if not bit1 is set, too. bit1= Disable the nowtime override
Returns
1= *now is not overridden , 2= *now is overridden
Since
1.5.2

Definition at line 2494 of file util.c.

Referenced by ecma119_determine_now_time(), iso_node_new_root(), iso_tree_add_boot_node(), iso_tree_add_new_dir(), iso_tree_add_new_file(), iso_tree_add_new_special(), iso_tree_add_new_symlink(), and Xorriso_set_libisofs_now().

◆ iso_ntohs()

uint16_t iso_ntohs ( uint16_t  v)

Definition at line 2308 of file util.c.

References iso_read_msb().

Referenced by get_class(), and iso_get_hfsplus_name().

◆ iso_r_dirid()

char* iso_r_dirid ( const char *  src,
int  size,
int  relaxed 
)

Create a dir name suitable for an ISO image with relaxed constraints.

Parameters
sizeMax len for the name
relaxedbit0+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)

Definition at line 1026 of file util.c.

References map_fileid_char(), and valid_d_char().

Referenced by iso_get_ecma119_name().

◆ iso_r_fileid()

char* iso_r_fileid ( const char *  src,
size_t  len,
int  relaxed,
int  forcedot 
)

Create a file name suitable for an ISO image with level > 1 and with relaxed constraints.

Parameters
lenMax len for the name, without taken the "." into account.
relaxedbit0+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)
forcedotWhether to ensure that "." is added

Definition at line 1090 of file util.c.

References map_fileid_char(), and valid_d_char().

Referenced by iso_get_ecma119_name().

◆ iso_read_bb()

uint32_t iso_read_bb ( const uint8_t *  buf,
int  bytes,
int *  error 
)

if error != NULL it will be set to 1 if LSB and MSB integers don't match.

Definition at line 1542 of file util.c.

References iso_read_lsb(), and iso_read_msb().

Referenced by iso_file_source_new_ifs(), iso_image_filesystem_new(), read_dir(), read_pvd_block(), read_pvm(), read_rr_PN(), read_rr_PX(), read_zisofs_ZF(), and susp_iter_next().

◆ iso_read_lsb()

uint32_t iso_read_lsb ( const uint8_t *  buf,
int  bytes 
)

Definition at line 1520 of file util.c.

Referenced by iso_read_bb().

◆ iso_read_lsb64()

◆ iso_read_msb()

uint32_t iso_read_msb ( const uint8_t *  buf,
int  bytes 
)

◆ iso_read_msb64()

uint64_t iso_read_msb64 ( const uint8_t *  buf)

Definition at line 1564 of file util.c.

Referenced by iso_analyze_sun().

◆ iso_scanf_io_size()

off_t iso_scanf_io_size ( char *  text,
int  flag 
)

Convert a text into a number of type double and multiply it by unit code [kmgt] (2^10 to 2^40) or [s] (2048) or [d] (512). (Also accepts capital letters.)

Parameters
textInput like "42", "223062s", "3m" or "-1g"
flagBitfield for control purposes: bit0= return -1 rather than 0 on failure bit1= if scaled then compute the last byte of the last unit
Returns
The derived value

Definition at line 2369 of file util.c.

Referenced by iso_ivr_read_number().

◆ iso_set_local_charset()

int iso_set_local_charset ( char *  name,
int  flag 
)

Override the reply of libc function nl_langinfo(CODESET) which may or may not give the name of the character set which is in effect for your environment. So this call can compensate for inconsistent terminal setups. Another use case is to choose UTF-8 as intermediate character set for a conversion from an exotic input character set to an exotic output set.

Parameters
nameName of the character set to be assumed as "local" one.
flagUnused yet. Submit 0.
Returns
1 indicates success, <=0 failure
Since
0.6.12

Definition at line 176 of file util.c.

References libisofs_local_charset.

Referenced by Xorriso_set_local_charset().

◆ iso_truncate_leaf_name()

int iso_truncate_leaf_name ( int  mode,
int  length,
char *  name,
int  flag 
)

Immediately apply the given truncate mode and length to the given string.

Parameters
modeSee iso_image_set_truncate_mode()
lengthSee iso_image_set_truncate_mode()
nameThe string to be inspected and truncated if mode says so.
flagBitfield for control purposes. Unused yet. Submit 0.
Returns
ISO_SUCCESS, ISO_WRONG_ARG_VALUE, ISO_RR_NAME_TOO_LONG
Since
1.4.2

Definition at line 2477 of file util.c.

References iso_truncate_rr_name(), ISO_WRONG_ARG_VALUE, and LIBISOFS_NODE_NAME_MAX.

Referenced by Xorriso_tree_graft_node(), Xorriso_truncate_path_comps(), and Xorriso_truncate_uniquely().

◆ iso_truncate_rr_name()

◆ iso_util_bin_to_hex()

int iso_util_bin_to_hex ( char *  target,
uint8_t *  bytes,
int  num_bytes,
int  flag 
)

Definition at line 2096 of file util.c.

Referenced by iso_analyze_gpt_backup(), iso_eltorito_report(), and iso_impsysa_report().

◆ iso_util_dec_to_uint32()

int iso_util_dec_to_uint32 ( char *  dec,
uint32_t *  value,
int  flag 
)

Definition at line 2084 of file util.c.

Referenced by iso_util_decode_md5_tag().

◆ iso_util_decode_len_bytes()

int iso_util_decode_len_bytes ( uint32_t *  data,
char *  buffer,
int *  data_len,
int  buffer_len,
int  flag 
)

Decode an integer as LEN,BYTES for being a component in certain AAIP attribute values.

Parameters
datareturns the decoded value
buffercontains the encoded value
data_lenreturns the number of value bytes (without len byte)
buffer_lentells the number of valid buffer bytes

Definition at line 2069 of file util.c.

References ISO_SUCCESS.

Referenced by iso_root_get_isofsca(), and iso_root_get_isofsnt().

◆ iso_util_decode_md5_tag()

int iso_util_decode_md5_tag ( char  data[2048],
int *  tag_type,
uint32_t *  pos,
uint32_t *  range_start,
uint32_t *  range_size,
uint32_t *  next_tag,
char  md5[16],
int  flag 
)

Check a data block whether it is a libisofs session checksum tag and eventually obtain its recorded parameters. These tags get written after volume descriptors, directory tree and checksum array and can be detected without loading the image tree. One may start reading and computing MD5 at the suspected image session start and look out for a session tag on the fly. See doc/checksum.txt .

Parameters
dataA complete and aligned data block read from an ISO image session.
tag_type0= no tag 1= session tag 2= superblock tag 3= tree tag 4= relocated 64 kB superblock tag (at LBA 0 of overwritable media)
posReturns the LBA where the tag supposes itself to be stored. If this does not match the data block LBA then the tag might be image data payload and should be ignored for image checksumming.
range_startReturns the block address where the session is supposed to start. If this does not match the session start on media then the image volume descriptors have been been relocated. A proper checksum will only emerge if computing started at range_start.
range_sizeReturns the number of blocks beginning at range_start which are covered by parameter md5.
next_tagReturns the predicted block address of the next tag. next_tag is valid only if not 0 and only with return values 2, 3, 4. With tag types 2 and 3, reading shall go on sequentially and the MD5 computation shall continue up to that address. With tag type 4, reading shall resume either at LBA 32 for the first session or at the given address for the session which is to be loaded by default. In both cases the MD5 computation shall be re-started from scratch.
md5Returns 16 byte of MD5 checksum.
flagBitfield for control purposes: bit0-bit7= tag type being looked for 0= any checksum tag 1= session tag 2= superblock tag 3= tree tag 4= relocated superblock tag
Returns
0= not a checksum tag, return parameters are invalid 1= checksum tag found, return parameters are valid <0= error (return parameters are valid with error ISO_MD5_AREA_CORRUPTED but not trustworthy because the tag seems corrupted)
Since
0.6.22

Definition at line 2150 of file util.c.

References ISO_MD5_AREA_CORRUPTED, iso_md5_compute(), iso_md5_end(), iso_md5_start(), iso_util_dec_to_uint32(), iso_util_hex_to_bin(), iso_util_tag_magic(), and ISO_WRONG_ARG_VALUE.

Referenced by ecma119_image_new(), iso_util_eval_md5_tag(), Xorriso_adjust_session_size(), Xorriso_chunk_md5(), Xorriso_find_sb_checksum(), Xorriso_refresh_ts_tags(), and Xorriso_verify_sb_tag().

◆ iso_util_encode_len_bytes()

int iso_util_encode_len_bytes ( uint32_t  data,
char *  buffer,
int  data_len,
int *  result_len,
int  flag 
)

Encode an integer as LEN,BYTES for being a component in certain AAIP attribute values.

Definition at line 2045 of file util.c.

References ISO_SUCCESS.

Referenced by iso_root_set_isofsca(), and iso_root_set_isofsnt().

◆ iso_util_eval_md5_tag()

int iso_util_eval_md5_tag ( char *  block,
int  desired,
uint32_t  lba,
void *  ctx,
uint32_t  ctx_start_lba,
int *  tag_type,
uint32_t *  next_tag,
int  flag 
)

◆ iso_util_hex_to_bin()

int iso_util_hex_to_bin ( char *  hex,
char *  bin,
int  bin_size,
int *  bin_count,
int  flag 
)

Definition at line 2107 of file util.c.

Referenced by iso_util_decode_md5_tag().

◆ iso_util_strcopy()

char* iso_util_strcopy ( const char *  buf,
size_t  len 
)

Copy up to len chars from buf and return this newly allocated string. The new string is null-terminated.

Definition at line 1912 of file util.c.

Referenced by iso_util_strcopy_untail(), read_rr_NM(), and read_rr_SL().

◆ iso_util_strcopy_untail()

char* iso_util_strcopy_untail ( const char *  buf,
size_t  len 
)

Copy up to len chars from buf and return this newly allocated string. The new string is null-terminated. Any trailing blanks will be removed.

Definition at line 1925 of file util.c.

References iso_util_strcopy().

Referenced by read_pvm().

◆ iso_util_tag_magic()

int iso_util_tag_magic ( int  tag_type,
char **  tag_magic,
int *  len,
int  flag 
)

Definition at line 2130 of file util.c.

References ISO_WRONG_ARG_VALUE.

Referenced by iso_md5_write_tag(), and iso_util_decode_md5_tag().

◆ map_fileid_char()

static char map_fileid_char ( char  c,
int  relaxed 
)
static

Definition at line 830 of file util.c.

References valid_d_char().

Referenced by iso_1_fileid(), iso_dirid(), iso_r_dirid(), and iso_r_fileid().

◆ set_ucsbe()

static void set_ucsbe ( uint16_t *  ucs,
char  c 
)
static

Definition at line 534 of file util.c.

Referenced by iso_handle_split_utf16(), iso_j_dir_id(), iso_j_file_id(), str2ucs(), and str2utf16be().

◆ str2a_char()

int str2a_char ( const char *  icharset,
const char *  input,
char **  output 
)

allow NULL input

Definition at line 1444 of file util.c.

References ISO_OUT_OF_MEM, ISO_SUCCESS, str2ascii(), and valid_a_char().

Referenced by ecma119_writer_write_vol_desc(), and iso1999_writer_write_vol_desc().

◆ str2ascii()

int str2ascii ( const char *  icharset,
const char *  input,
char **  output 
)

Convert a given string from any input charset to ASCII

Parameters
icharsetInput charset. Must be supported by iconv
inputInput string
outputLocation where the pointer to the output string will be stored
Returns
1 on success, < 0 on error

Definition at line 392 of file util.c.

References ISO_CHARSET_CONV_ERROR, iso_iconv(), iso_iconv_close(), iso_iconv_open(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, and str2wchar().

Referenced by iso_get_ecma119_name(), str2a_char(), and str2d_char().

◆ str2d_char()

int str2d_char ( const char *  icharset,
const char *  input,
char **  output 
)

Convert a given input string to d-chars.

Returns
1 on success, < 0 error, 0 if input was null (output is set to null)

allow NULL input

Definition at line 1410 of file util.c.

References ISO_OUT_OF_MEM, ISO_SUCCESS, str2ascii(), and valid_d_char().

Referenced by ecma119_writer_write_vol_desc().

◆ str2ucs()

int str2ucs ( const char *  icharset,
const char *  input,
uint16_t **  output 
)

Convert a given string from any input charset to UCS-2BE charset, used for Joliet file identifiers.

Parameters
icharsetInput charset. Must be supported by iconv
inputInput string
outputLocation where the pointer to the output string will be stored
Returns
1 on success, < 0 on error

Definition at line 558 of file util.c.

References ISO_CHARSET_CONV_ERROR, iso_iconv(), iso_iconv_close(), iso_iconv_open(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, set_ucsbe(), and str2wchar().

Referenced by iso_get_joliet_name(), joliet_create_mangled_name(), and joliet_writer_write_vol_desc().

◆ str2utf16be()

int str2utf16be ( const char *  icharset,
const char *  input,
uint16_t **  output 
)

Convert a given string from any input charset to UTF-16BE charset, used for HFS+ file identifiers. (UTF-16 differs from older UCS-2 by having multi word characters.)

Parameters
icharsetInput charset. Must be supported by iconv
inputInput string
outputLocation where the pointer to the output string will be stored
Returns
1 on success, < 0 on error

Definition at line 687 of file util.c.

References ISO_CHARSET_CONV_ERROR, iso_iconv(), iso_iconv_close(), iso_iconv_open(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, set_ucsbe(), and str2wchar().

Referenced by iso_get_hfsplus_name(), and iso_get_joliet_name().

◆ str2wchar()

static int str2wchar ( const char *  icharset,
const char *  input,
wchar_t **  output 
)
static

Convert a str in a specified codeset to WCHAR_T. The result must be free() when no more needed

Returns
1 success, < 0 error

Definition at line 312 of file util.c.

References ISO_CHARSET_CONV_ERROR, iso_iconv(), iso_iconv_close(), iso_iconv_open(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, and ISO_SUCCESS.

Referenced by str2ascii(), str2ucs(), and str2utf16be().

◆ strconv()

int strconv ( const char *  input,
const char *  icharset,
const char *  ocharset,
char **  output 
)

Convert the charset encoding of a given string.

Parameters
inputInput string
icharsetInput charset. Must be supported by iconv
ocharsetOutput charset. Must be supported by iconv
outputLocation where the pointer to the output string will be stored
Returns
1 on success, < 0 on error

Definition at line 192 of file util.c.

References ISO_CHARSET_CONV_ERROR, iso_iconv(), iso_iconv_close(), iso_iconv_open(), ISO_OUT_OF_MEM, and ISO_SUCCESS.

Referenced by get_iso1999_name(), get_relaxed_vol_id(), and iso_get_rr_name().

◆ strnconv()

int strnconv ( const char *  str,
const char *  icharset,
const char *  ocharset,
size_t  len,
char **  output 
)

Definition at line 295 of file util.c.

References strnconvl().

Referenced by get_name().

◆ strnconvl()

int strnconvl ( const char *  str,
const char *  icharset,
const char *  ocharset,
size_t  len,
char **  output,
size_t *  out_len 
)

◆ strncpy_pad()

void strncpy_pad ( char *  dest,
const char *  src,
size_t  max 
)

Copy up to max characters from src to dest. If src has less than max characters, we pad dest with " " characters.

Definition at line 1947 of file util.c.

References MIN.

Referenced by ecma119_writer_write_vol_desc(), and iso1999_writer_write_vol_desc().

◆ timegm()

static time_t timegm ( struct tm *  tm)
static

Definition at line 1793 of file util.c.

References env_timegm(), and ts_timegm().

Referenced by iso_datetime_read_17(), and iso_datetime_read_7().

◆ ts_is_leapyear()

static int ts_is_leapyear ( int  tm_year)
static

Definition at line 1746 of file util.c.

Referenced by ts_timegm().

◆ ts_timegm()

static time_t ts_timegm ( struct tm *  tm)
static

Definition at line 1759 of file util.c.

References ts_is_leapyear().

Referenced by timegm().

◆ ucs2str()

char* ucs2str ( const char *  buf,
size_t  len 
)

Convert a Joliet string with a length of len bytes to a new string in local charset.

Definition at line 1963 of file util.c.

References iso_get_local_charset(), iso_iconv(), iso_iconv_close(), and iso_iconv_open().

◆ ucscmp()

int ucscmp ( const uint16_t *  s1,
const uint16_t *  s2 
)

Although each character is 2 bytes, we actually compare byte-by-byte because the words are big-endian. Comparing possibly swapped words would make the sorting order depend on the machine byte order.

Definition at line 1371 of file util.c.

References MIN, and ucslen().

Referenced by cmp_node(), cmp_node_name(), iso_get_joliet_name(), and mangle_single_dir().

◆ ucscpy()

uint16_t* ucscpy ( uint16_t *  dest,
const uint16_t *  src 
)

Like strcpy, but for Joliet strings.

Definition at line 1394 of file util.c.

References ucslen().

Referenced by mangle_single_dir().

◆ ucsdup()

uint16_t* ucsdup ( const uint16_t *  str)

Like strdup, but for Joliet strings.

Definition at line 1352 of file util.c.

References ucslen().

Referenced by iso_j_dir_id(), iso_j_file_id(), and mangle_single_dir().

◆ ucslen()

◆ ucsncpy()

uint16_t* ucsncpy ( uint16_t *  dest,
const uint16_t *  src,
size_t  n 
)

Like strncpy, but for Joliet strings.

Parameters
nMaximum number of characters to copy (2 bytes per char).

Definition at line 1401 of file util.c.

References iso_handle_split_utf16(), MIN, and ucslen().

Referenced by joliet_create_mangled_name().

◆ ucsrchr()

uint16_t* ucsrchr ( const uint16_t *  str,
char  c 
)

Like strrchr, but for Joliet strings.

Definition at line 1340 of file util.c.

References cmp_ucsbe(), and ucslen().

Referenced by iso_j_file_id(), and mangle_single_dir().

◆ valid_a_char()

static int valid_a_char ( char  c)
static

Definition at line 811 of file util.c.

Referenced by str2a_char().

◆ valid_d_char()

static int valid_d_char ( char  c)
static

◆ valid_j_char()

static int valid_j_char ( uint16_t  c)
static

Definition at line 817 of file util.c.

References cmp_ucsbe().

Referenced by iso_j_dir_id(), and iso_j_file_id().

Variable Documentation

◆ iso_iconv_debug

int iso_iconv_debug = 0
static

Definition at line 44 of file util.c.

Referenced by iso_iconv(), iso_iconv_close(), and iso_iconv_open().

◆ libisofs_local_charset

char libisofs_local_charset[4096] = {""}
static

Definition at line 173 of file util.c.

Referenced by iso_get_local_charset(), and iso_set_local_charset().