Add silly volume identifier. More #defines removed in favor of enums.
This commit is contained in:
@@ -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 <rocky@panix.com>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -54,6 +54,25 @@
|
||||
|
||||
#include <cdio/types.h>
|
||||
|
||||
/**
|
||||
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
|
||||
|
||||
@@ -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 <rocky@panix.com>
|
||||
|
||||
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.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
debug_ecma_167_enums1
|
||||
debug_file_characteristics
|
||||
debug_tagid
|
||||
debug_udf_enums1
|
||||
|
||||
@@ -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 <rocky@panix.com>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user