diff --git a/include/cdio/iso9660.h b/include/cdio/iso9660.h index 38b11b1d..36787790 100644 --- a/include/cdio/iso9660.h +++ b/include/cdio/iso9660.h @@ -1,5 +1,5 @@ /* - $Id: iso9660.h,v 1.22 2003/09/20 11:53:09 rocky Exp $ + $Id: iso9660.h,v 1.23 2003/09/20 12:33:14 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2003 Rocky Bernstein @@ -37,6 +37,8 @@ #include +#define _delta(from, to) ((to) - (from) + 1) + #define MIN_TRACK_SIZE 4*75 #define MIN_ISO_SIZE MIN_TRACK_SIZE @@ -105,42 +107,55 @@ struct iso9660_dtime { typedef struct iso9660_dtime iso9660_dtime_t; +struct iso9660_ltime { + char lt_year [_delta( 1, 4)]; /* Add 1900 for Julian year */ + char lt_month [_delta( 5, 6)]; /* 1..12. Note starts at 1. */ + char lt_day [_delta( 7, 8)]; + char lt_hour [_delta( 9, 10)]; + char lt_minute [_delta( 11, 12)]; + char lt_second [_delta( 13, 14)]; + char lt_hsecond [_delta( 15, 16)]; /* 1/100's of a second */ + int8_t lt_gmtoff [_delta( 17, 17)]; +} GNUC_PACKED; + +typedef struct iso9660_ltime iso9660_ltime_t; + /* ISO-9660 Primary Volume Descriptor. */ struct iso9660_pvd { - uint8_t type; /* 711 */ - char id[5]; - uint8_t version; /* 711 */ - char unused1[1]; - char system_id[32]; /* achars */ - char volume_id[32]; /* dchars */ - char unused2[8]; - uint64_t volume_space_size; /* 733 */ - char escape_sequences[32]; - uint32_t volume_set_size; /* 723 */ - uint32_t volume_sequence_number; /* 723 */ - uint32_t logical_block_size; /* 723 */ - uint64_t path_table_size; /* 733 */ - uint32_t type_l_path_table; /* 731 */ - uint32_t opt_type_l_path_table; /* 731 */ - uint32_t type_m_path_table; /* 732 */ - uint32_t opt_type_m_path_table; /* 732 */ - char root_directory_record[34]; /* 9.1 */ - char volume_set_id[128]; /* dchars */ - char publisher_id[128]; /* achars */ - char preparer_id[128]; /* achars */ - char application_id[128]; /* achars */ - char copyright_file_id[37]; /* 7.5 dchars */ - char abstract_file_id[37]; /* 7.5 dchars */ - char bibliographic_file_id[37]; /* 7.5 dchars */ - char creation_date[17]; /* 8.4.26.1 */ - char modification_date[17]; /* 8.4.26.1 */ - char expiration_date[17]; /* 8.4.26.1 */ - char effective_date[17]; /* 8.4.26.1 */ - uint8_t file_structure_version; /* 711 */ - char unused4[1]; - char application_data[512]; - char unused5[653]; + uint8_t type; /* 711 */ + char id[5]; + uint8_t version; /* 711 */ + char unused1[1]; + char system_id[32]; /* achars */ + char volume_id[32]; /* dchars */ + char unused2[8]; + uint64_t volume_space_size; /* 733 */ + char escape_sequences[32]; + uint32_t volume_set_size; /* 723 */ + uint32_t volume_sequence_number; /* 723 */ + uint32_t logical_block_size; /* 723 */ + uint64_t path_table_size; /* 733 */ + uint32_t type_l_path_table; /* 731 */ + uint32_t opt_type_l_path_table; /* 731 */ + uint32_t type_m_path_table; /* 732 */ + uint32_t opt_type_m_path_table; /* 732 */ + char root_directory_record[34]; /* 9.1 */ + char volume_set_id[128]; /* dchars */ + char publisher_id[128]; /* achars */ + char preparer_id[128]; /* achars */ + char application_id[128]; /* achars */ + char copyright_file_id[37]; /* 7.5 dchars */ + char abstract_file_id[37]; /* 7.5 dchars */ + char bibliographic_file_id[37]; /* 7.5 dchars */ + iso9660_ltime_t creation_date; /* 8.4.26.1 */ + iso9660_ltime_t modification_date; /* 8.4.26.1 */ + iso9660_ltime_t expiration_date; /* 8.4.26.1 */ + iso9660_ltime_t effective_date; /* 8.4.26.1 */ + uint8_t file_structure_version; /* 711 */ + char unused4[1]; + char application_data[512]; + char unused5[653]; } GNUC_PACKED; typedef struct iso9660_dir iso9660_dir_t; @@ -231,10 +246,16 @@ char *iso9660_strncpy_pad(char dst[], const char src[], size_t len, /*! Set time in format used in ISO 9660 directory index record from a Unix time structure. */ - void iso9660_set_time (const struct tm *tm, - /*out*/ iso9660_dtime_t *idr_date); + void iso9660_set_dtime (const struct tm *tm, + /*out*/ iso9660_dtime_t *idr_date); +/*! + Set "long" time in format used in ISO 9660 primary volume descriptor + from a Unix time structure. */ + void iso9660_set_ltime (const struct tm *_tm, + /*out*/ iso9660_ltime_t *pvd_date); + /*! Get time structure from structure in an ISO 9660 directory index record. Even though tm_wday and tm_yday fields are not explicitly in diff --git a/lib/iso9660.c b/lib/iso9660.c index d7cdb848..4e8506a2 100644 --- a/lib/iso9660.c +++ b/lib/iso9660.c @@ -1,5 +1,5 @@ /* - $Id: iso9660.c,v 1.11 2003/09/20 11:53:09 rocky Exp $ + $Id: iso9660.c,v 1.12 2003/09/20 12:33:14 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2003 Rocky Bernstein @@ -37,7 +37,7 @@ #include #endif -static const char _rcsid[] = "$Id: iso9660.c,v 1.11 2003/09/20 11:53:09 rocky Exp $"; +static const char _rcsid[] = "$Id: iso9660.c,v 1.12 2003/09/20 12:33:14 rocky Exp $"; /* some parameters... */ #define SYSTEM_ID "CD-RTOS CD-BRIDGE" @@ -73,7 +73,7 @@ iso9660_get_time (const iso9660_dtime_t *idr_date, /*out*/ struct tm *tm) Set time in format used in ISO 9660 directory index record from a Unix time structure. */ void -iso9660_set_time (const struct tm *tm, /*out*/ iso9660_dtime_t *idr_date) +iso9660_set_dtime (const struct tm *tm, /*out*/ iso9660_dtime_t *idr_date) { memset (idr_date, 0, 7); @@ -88,22 +88,44 @@ iso9660_set_time (const struct tm *tm, /*out*/ iso9660_dtime_t *idr_date) idr_date->dt_gmtoff = 0x00; /* tz, GMT -48 +52 in 15min intervals */ } -static void -_pvd_set_time (char _pvd_date[], const struct tm *_tm) +/*! + Set "long" time in format used in ISO 9660 primary volume descriptor + from a Unix time structure. */ +void +iso9660_set_ltime (const struct tm *_tm, /*out*/ iso9660_ltime_t *pvd_date) { - memset (_pvd_date, '0', 16); - _pvd_date[16] = (int8_t) 0; /* tz */ + memset (pvd_date->lt_year, '0', sizeof(pvd_date->lt_year)); + memset (pvd_date->lt_month, '0', sizeof(pvd_date->lt_month)); + memset (pvd_date->lt_day, '0', sizeof(pvd_date->lt_day)); + memset (pvd_date->lt_hour, '0', sizeof(pvd_date->lt_hour)); + memset (pvd_date->lt_minute, '0', sizeof(pvd_date->lt_minute)); + memset (pvd_date->lt_second, '0', sizeof(pvd_date->lt_second)); + memset (pvd_date->lt_hsecond, '0', sizeof(pvd_date->lt_hsecond)); + memset (pvd_date->lt_gmtoff, 0, sizeof(pvd_date->lt_gmtoff)); if (!_tm) return; - snprintf(_pvd_date, 17, - "%4.4d%2.2d%2.2d" "%2.2d%2.2d%2.2d" "%2.2d", - _tm->tm_year + 1900, _tm->tm_mon + 1, _tm->tm_mday, - _tm->tm_hour, _tm->tm_min, _tm->tm_sec, - 0 /* 1/100 secs */ ); - - _pvd_date[16] = (int8_t) 0; /* tz */ + snprintf(pvd_date->lt_year, sizeof(pvd_date->lt_year), + "%4.4d", _tm->tm_year + 1900); + + snprintf(pvd_date->lt_month, sizeof(pvd_date->lt_month), + "%2.2d", _tm->tm_mon + 1); + + snprintf(pvd_date->lt_day, sizeof(pvd_date->lt_day), + "%2.2d", _tm->tm_mday); + + snprintf(pvd_date->lt_hour, sizeof(pvd_date->lt_hour), + "%2.2d", _tm->tm_hour); + + snprintf(pvd_date->lt_minute, sizeof(pvd_date->lt_minute), + "%2.2d", _tm->tm_min); + + snprintf(pvd_date->lt_second, sizeof(pvd_date->lt_second), + "%2.2d", _tm->tm_sec); + + snprintf(pvd_date->lt_hsecond, sizeof(pvd_date->lt_hsecond), + "%2.2d", 0); } /*! @@ -330,10 +352,10 @@ iso9660_set_pvd(void *pd, iso9660_strncpy_pad (ipd.abstract_file_id , "", 37, ISO9660_DCHARS); iso9660_strncpy_pad (ipd.bibliographic_file_id, "", 37, ISO9660_DCHARS); - _pvd_set_time (ipd.creation_date, gmtime (pvd_time)); - _pvd_set_time (ipd.modification_date, gmtime (pvd_time)); - _pvd_set_time (ipd.expiration_date, NULL); - _pvd_set_time (ipd.effective_date, NULL); + iso9660_set_ltime (gmtime (pvd_time), &(ipd.creation_date)); + iso9660_set_ltime (gmtime (pvd_time), &(ipd.modification_date)); + iso9660_set_ltime (NULL, &(ipd.expiration_date)); + iso9660_set_ltime (NULL, &(ipd.effective_date)); ipd.file_structure_version = to_711(1); @@ -429,7 +451,7 @@ iso9660_dir_add_entry_su(void *dir, idr->extent = to_733(extent); idr->size = to_733(size); - iso9660_set_time (gmtime(entry_time), &(idr->date)); + iso9660_set_dtime (gmtime(entry_time), &(idr->date)); idr->flags = to_711(flags);