From fcd818f4ba6baf7ec592bd009685a260b66b82a5 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 25 Oct 2005 03:13:13 +0000 Subject: [PATCH] Add silly volume identifier. More #defines removed in favor of enums. --- example/udf1.c | 10 +++++- include/cdio/ecma_167.h | 37 ++++++++++++++------ include/cdio/udf.h | 15 ++++++-- lib/udf/libudf.sym | 1 + lib/udf/udf_fs.c | 76 ++++++++++++++++++++++++++++++----------- 5 files changed, 104 insertions(+), 35 deletions(-) diff --git a/example/udf1.c b/example/udf1.c index 5b544ecc..a5037f3e 100644 --- a/example/udf1.c +++ b/example/udf1.c @@ -1,5 +1,5 @@ /* - $Id: udf1.c,v 1.3 2005/10/25 01:19:48 rocky Exp $ + $Id: udf1.c,v 1.4 2005/10/25 03:13:13 rocky Exp $ Copyright (C) 2005 Rocky Bernstein @@ -101,6 +101,14 @@ main(int argc, const char *argv[]) psz_fname); return 1; } + + { + char volid[UDF_VOLID_SIZE] = ""; + + if (0 < udf_get_volume_id(p_udf, volid, sizeof(volid)) ) + printf("volume id: %s\n", volid); + } + list_files(p_udf, p_udf_file, strdup(udf_get_name(p_udf_file))); udf_file_free(p_udf_file); diff --git a/include/cdio/ecma_167.h b/include/cdio/ecma_167.h index 3975a2c2..d92f7b55 100644 --- a/include/cdio/ecma_167.h +++ b/include/cdio/ecma_167.h @@ -54,6 +54,25 @@ #include +/** + Imagine the below #define'd values rather than distinct values of + an enum. +*/ +typedef enum { + VSD_STD_ID_SIZE = 5, /** Volume Structure Descriptor (ECMA 167r3 + 2/9.1) */ + UDF_REGID_ID_SIZE = 23, /**< See identifier (ECMA 167r3 1/7.4) */ + UDF_VOLID_SIZE = 32, + UDF_FID_SIZE = 38, + UDF_VOLSET_ID_SIZE = 128 +} ecma_167_enum1_t ; + +/** This variable is trickery to force the above enum symbol value to + be recorded in debug symbol tables. It is used to allow one refer + to above enumeration values in a debugger and debugger + expressions */ +extern ecma_167_enum1_t debug_ecma_167_enums1; + /** Tag Identifier (ECMA 167r3 3/7.2.1) */ typedef enum { @@ -137,7 +156,6 @@ typedef struct udf_timestamp_s udf_timestamp_t; #define TIMESTAMP_TIMEZONE_MASK 0x0FFF /** Entity identifier (ECMA 167r3 1/7.4) */ -#define UDF_REGID_ID_SIZE 23 struct udf_regid_s { udf_Uint8_t flags; @@ -152,11 +170,10 @@ typedef struct udf_regid_s udf_regid_t; #define ENTITYID_FLAGS_PROTECTED 0x01 /** Volume Structure Descriptor (ECMA 167r3 2/9.1) */ -#define VSD_STD_ID_LEN 5 struct vol_struct_desc_s { udf_Uint8_t struct_type; - udf_Uint8_t std_id[VSD_STD_ID_LEN]; + udf_Uint8_t std_id[VSD_STD_ID_SIZE]; udf_Uint8_t struct_version; udf_Uint8_t struct_data[2041]; } GNUC_PACKED; @@ -186,7 +203,7 @@ extern const char VSD_STD_ID_TEA01[sizeof("TEA01")-1]; struct beginning_extended_area_desc_s { udf_Uint8_t struct_type; - udf_Uint8_t std_id[VSD_STD_ID_LEN]; + udf_Uint8_t std_id[VSD_STD_ID_SIZE]; udf_Uint8_t struct_version; udf_Uint8_t struct_data[2041]; } GNUC_PACKED; @@ -195,7 +212,7 @@ struct beginning_extended_area_desc_s struct terminating_extended_area_desc_s { udf_Uint8_t struct_type; - udf_Uint8_t std_id[VSD_STD_ID_LEN]; + udf_Uint8_t std_id[VSD_STD_ID_SIZE]; udf_Uint8_t struct_version; udf_Uint8_t struct_data[2041]; } GNUC_PACKED; @@ -204,7 +221,7 @@ struct terminating_extended_area_desc_s struct boot_desc_s { udf_Uint8_t struct_type; - udf_Uint8_t std_ident[VSD_STD_ID_LEN]; + udf_Uint8_t std_ident[VSD_STD_ID_SIZE]; udf_Uint8_t struct_version; udf_Uint8_t reserved1; udf_regid_t arch_type; @@ -250,7 +267,7 @@ typedef struct udf_tag_s udf_tag_t; struct NSR_desc_s { udf_Uint8_t struct_type; - udf_Uint8_t std_id[VSD_STD_ID_LEN]; + udf_Uint8_t std_id[VSD_STD_ID_SIZE]; udf_Uint8_t struct_version; udf_Uint8_t reserved; udf_Uint8_t struct_data[2040]; @@ -262,14 +279,14 @@ struct udf_pvd_s udf_tag_t tag; udf_Uint32_t vol_desc_seq_num; udf_Uint32_t primary_vol_desc_num; - udf_dstring vol_ident[32]; + udf_dstring vol_ident[UDF_VOLID_SIZE]; udf_Uint16_t vol_seq_num; udf_Uint16_t max_vol_seqnum; udf_Uint16_t interchange_lvl; udf_Uint16_t max_interchange_lvl; udf_Uint32_t charset_list; udf_Uint32_t max_charset_list; - udf_dstring volSet_id[128]; + udf_dstring volset_id[UDF_VOLSET_ID_SIZE]; udf_charspec_t desc_charset; udf_charspec_t explanatory_charset; udf_extent_ad_t vol_abstract; @@ -542,8 +559,6 @@ struct udf_fileid_desc_s typedef struct udf_fileid_desc_s udf_fileid_desc_t; -#define UDF_FID_SIZE 38 - /** File Characteristics (ECMA 167r3 4/14.4.3) Imagine the below enumeration values are #defines to be used in a diff --git a/include/cdio/udf.h b/include/cdio/udf.h index 40d33b86..d8094e5b 100644 --- a/include/cdio/udf.h +++ b/include/cdio/udf.h @@ -1,5 +1,5 @@ /* - $Id: udf.h,v 1.7 2005/10/24 10:14:58 rocky Exp $ + $Id: udf.h,v 1.8 2005/10/25 03:13:13 rocky Exp $ Copyright (C) 2005 Rocky Bernstein This program is free software; you can redistribute it and/or modify @@ -20,8 +20,8 @@ /*! * \file udf.h * - * \brief The top-level interface header for libudf: the ISO-9660 - * filesystem library; applications include this. + * \brief The top-level interface header for libudf: UDF filesystem + * library; applications include this. * */ @@ -82,6 +82,15 @@ udf_t *udf_open (const char *psz_path); udf_file_t *udf_get_root (udf_t *p_udf, bool b_any_partition, partition_num_t i_partition); +/** + * Gets the Volume Identifier string, in 8bit unicode (latin-1) + * psz_volid, place to put the string + * i_volid_size, size of the buffer volid points to + * returns the size of buffer needed for all data + */ +int udf_get_volume_id(udf_t *p_udf, /*out*/ char *psz_volid, + unsigned int i_volid); + /*! Return a file pointer matching pzz_name. If b_any_partition is false then the root must be in the given partition. diff --git a/lib/udf/libudf.sym b/lib/udf/libudf.sym index 9dc7a99a..a95913ed 100644 --- a/lib/udf/libudf.sym +++ b/lib/udf/libudf.sym @@ -1,3 +1,4 @@ +debug_ecma_167_enums1 debug_file_characteristics debug_tagid debug_udf_enums1 diff --git a/lib/udf/udf_fs.c b/lib/udf/udf_fs.c index 622b2f6c..ad8ccec6 100644 --- a/lib/udf/udf_fs.c +++ b/lib/udf/udf_fs.c @@ -1,5 +1,5 @@ /* - $Id: udf_fs.c,v 1.4 2005/10/25 01:19:48 rocky Exp $ + $Id: udf_fs.c,v 1.5 2005/10/25 03:13:13 rocky Exp $ Copyright (C) 2005 Rocky Bernstein @@ -77,8 +77,8 @@ const char VSD_STD_ID_TEA01[] = {'T', 'E', 'A', '0', '1'}; */ tag_id_t debug_tagid; file_characteristics_t debug_file_characteristics; -udf_enum1_t debug_udf_enums1; - +udf_enum1_t debug_udf_enum1; +ecma_167_enum1_t ecma167_enum1; /* * The UDF specs are pretty clear on how each data structure is made @@ -251,22 +251,19 @@ udf_find_file(udf_t *p_udf, const char *psz_name, bool b_any_partition, Wonder if iconv can be used here */ static int -unicode16_decode( uint8_t *data, int len, char **ppsz_target ) +unicode16_decode( const uint8_t *data, int i_len, char *target ) { - int p = 1, i = 0; - - if (strlen(*ppsz_target) < len) - *ppsz_target = realloc(*ppsz_target, sizeof(char)*len+1); - - if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do { - if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */ - if( p < len ) { - (*ppsz_target)[ i++ ] = data[ p++ ]; - } - } while( p < len ); - - (*ppsz_target)[ i ] = '\0'; - return 0; + int p = 1, i = 0; + + if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do { + if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */ + if( p < i_len ) { + target[ i++ ] = data[ p++ ]; + } + } while( p < i_len ); + + target[ i ] = '\0'; + return 0; } @@ -389,6 +386,36 @@ udf_open (const char *psz_path) return NULL; } +/** + * Gets the Volume Identifier string, in 8bit unicode (latin-1) + * psz_volid, place to put the string + * i_volid_size, size of the buffer volid points to + * returns the size of buffer needed for all data + */ +int +udf_get_volume_id(udf_t *p_udf, /*out*/ char *psz_volid, unsigned int i_volid) +{ + uint8_t data[UDF_BLOCKSIZE]; + const udf_pvd_t *p_pvd = (udf_pvd_t *) &data; + unsigned int volid_len; + + /* get primary volume descriptor */ + if ( DRIVER_OP_SUCCESS != udf_read_sectors(p_udf, &data, p_udf->pvd_lba, 1) ) + return 0; + + volid_len = p_pvd->vol_ident[31]; + if(volid_len > 31) { + /* this field is only 32 bytes something is wrong */ + volid_len = 31; + } + if(i_volid > volid_len) { + i_volid = volid_len; + } + unicode16_decode((uint8_t *) p_pvd->vol_ident, i_volid, psz_volid); + + return volid_len; +} + /*! Get the root in p_udf. If b_any_partition is false then the root must be in the given partition. @@ -563,8 +590,17 @@ udf_get_next(const udf_t *p_udf, udf_file_t *p_udf_file) (p_udf_file->fid->file_characteristics & UDF_FILE_DIRECTORY) != 0; p_udf_file->b_parent = (p_udf_file->fid->file_characteristics & UDF_FILE_PARENT) != 0; - unicode16_decode(p_udf_file->fid->imp_use + p_udf_file->fid->i_imp_use, - p_udf_file->fid->i_file_id, &(p_udf_file->psz_name)); + + { + const unsigned int i_len = p_udf_file->fid->i_file_id; + if (strlen(p_udf_file->psz_name) < i_len) + p_udf_file->psz_name = (char *) + realloc(p_udf_file->psz_name, sizeof(char)*i_len+1); + + unicode16_decode(p_udf_file->fid->imp_use + + p_udf_file->fid->i_imp_use, + i_len, p_udf_file->psz_name); + } return p_udf_file; } return NULL;