libcdio  0.90
iso9660.h
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012
00003                   Rocky Bernstein <rocky@gnu.org>
00004     Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
00005 
00006     See also iso9660.h by Eric Youngdale (1993).
00007 
00008     Copyright 1993 Yggdrasil Computing, Incorporated
00009 
00010     This program is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00033 
00034 #ifndef CDIO_ISO9660_H_
00035 #define CDIO_ISO9660_H_
00036 
00037 #include <time.h>
00038 
00039 #include <cdio/cdio.h>
00040 #include <cdio/ds.h>
00041 #include <cdio/posix.h>
00042 
00049 typedef uint8_t  iso711_t; 
00050 typedef int8_t   iso712_t; 
00051 typedef uint16_t iso721_t; 
00052 typedef uint16_t iso722_t; 
00053 typedef uint32_t iso723_t; 
00054 typedef uint32_t iso731_t; 
00055 typedef uint32_t iso732_t; 
00056 typedef uint64_t iso733_t; 
00058 typedef char     achar_t;  
00059 typedef char     dchar_t;  
00061 #ifndef EMPTY_ARRAY_SIZE
00062 #define EMPTY_ARRAY_SIZE 0
00063 #endif
00064 
00065 #include <cdio/types.h>
00066 #include <cdio/xa.h>
00067 
00068 #ifdef ISODCL
00069 #undef ISODCL
00070 #endif
00071 /* This part borrowed from the bsd386 isofs */
00072 #define ISODCL(from, to)        ((to) - (from) + 1)
00073 
00074 #define MIN_TRACK_SIZE 4*75
00075 #define MIN_ISO_SIZE MIN_TRACK_SIZE
00076 
00083 extern enum iso_enum1_s {
00084   ISO_PVD_SECTOR      =   16, 
00085   ISO_EVD_SECTOR      =   17, 
00086   LEN_ISONAME         =   31, 
00088   ISO_MAX_SYSTEM_ID   =   32, 
00090   MAX_ISONAME         =   37, 
00092   ISO_MAX_PREPARER_ID =  128, 
00094   MAX_ISOPATHNAME     =  255, 
00096   ISO_BLOCKSIZE       = 2048  
00098 } iso_enums1;
00099 
00107 extern enum iso_flag_enum_s {
00108   ISO_FILE            =   0,   
00109   ISO_EXISTENCE       =   1,   
00110   ISO_DIRECTORY       =   2,   
00111   ISO_ASSOCIATED      =   4,   
00112   ISO_RECORD          =   8,   
00113   ISO_PROTECTION      =  16,   
00114   ISO_DRESERVED1      =  32,   
00115   ISO_DRESERVED2      =  64,   
00116   ISO_MULTIEXTENT     = 128,   
00117 } iso_flag_enums;
00118 
00120 extern enum iso_vd_enum_s {
00121   ISO_VD_BOOT_RECORD   =  0,  
00122   ISO_VD_PRIMARY       =  1,  
00123   ISO_VD_SUPPLEMENTARY =  2,  
00124   ISO_VD_PARITION      =  3,  
00125   ISO_VD_END           = 255
00126 } iso_vd_enums;
00127 
00128   
00148 #define ISO_MAX_PUBLISHER_ID 128
00149 
00151 #define ISO_MAX_APPLICATION_ID 128
00152 
00154 #define ISO_MAX_VOLUME_ID 32
00155 
00157 #define ISO_MAX_VOLUMESET_ID 128
00158 
00162 extern const char ISO_STANDARD_ID[sizeof("CD001")-1];
00163 
00164 #define ISO_STANDARD_ID      "CD001" 
00165 
00166 #ifdef __cplusplus
00167 extern "C" {
00168 #endif /* __cplusplus */
00169 
00170 typedef enum strncpy_pad_check {
00171   ISO9660_NOCHECK = 0,
00172   ISO9660_7BIT,
00173   ISO9660_ACHARS,
00174   ISO9660_DCHARS
00175 } strncpy_pad_check_t;
00176 
00177 PRAGMA_BEGIN_PACKED
00178 
00184 struct  iso9660_dtime_s {
00185   iso711_t      dt_year;   
00186   iso711_t      dt_month;  
00188   iso711_t      dt_day;    
00189   iso711_t      dt_hour;   
00190   iso711_t      dt_minute; 
00191   iso711_t      dt_second; 
00192   iso712_t      dt_gmtoff; 
00194 } GNUC_PACKED;
00195 
00196 typedef struct iso9660_dtime_s  iso9660_dtime_t;
00197 
00207 struct  iso9660_ltime_s {
00208   char   lt_year        [ISODCL(   1,   4)];   
00211   char   lt_month       [ISODCL(   5,   6)];   
00215   char   lt_day         [ISODCL(   7,   8)];   
00216   char   lt_hour        [ISODCL(   9,   10)];  
00217   char   lt_minute      [ISODCL(  11,   12)];  
00218   char   lt_second      [ISODCL(  13,   14)];  
00219   char   lt_hsecond     [ISODCL(  15,   16)];  
00222   iso712_t lt_gmtoff;  
00226 } GNUC_PACKED;
00227 
00228 typedef struct iso9660_ltime_s  iso9660_ltime_t;
00229 typedef struct iso9660_dir_s    iso9660_dir_t;
00230 typedef struct iso9660_stat_s   iso9660_stat_t;
00231 
00232 #include <cdio/rock.h>
00233 
00248 struct iso9660_dir_s {
00249   iso711_t         length;            
00250   iso711_t         xa_length;         
00252   iso733_t         extent;            
00254   iso733_t         size;              
00257   iso9660_dtime_t  recording_time;    
00258   uint8_t          file_flags;        
00261   iso711_t         file_unit_size;    
00265   iso711_t         interleave_gap;    
00269   iso723_t volume_sequence_number;    
00282   union { 
00283     iso711_t        len;
00284     char            str[1];
00285   } filename;
00286 } GNUC_PACKED;
00287 
00291 struct iso9660_pvd_s {
00292   iso711_t         type;                         
00293   char             id[5];                        
00295   iso711_t         version;                      
00296   char             unused1[1];                   
00297   achar_t          system_id[ISO_MAX_SYSTEM_ID]; 
00298   dchar_t          volume_id[ISO_MAX_VOLUME_ID]; 
00299   uint8_t          unused2[8];                   
00300   iso733_t         volume_space_size;            
00302   uint8_t          unused3[32];                  
00303   iso723_t         volume_set_size;              
00304   iso723_t         volume_sequence_number;       
00305   iso723_t         logical_block_size;           
00306   iso733_t         path_table_size;              
00307   iso731_t         type_l_path_table;            
00309   iso731_t         opt_type_l_path_table;        
00311   iso732_t         type_m_path_table;            
00313   iso732_t         opt_type_m_path_table;        
00315   iso9660_dir_t    root_directory_record;        
00318   char             root_directory_filename;      
00321   dchar_t          volume_set_id[ISO_MAX_VOLUMESET_ID]; 
00325   achar_t          publisher_id[ISO_MAX_PUBLISHER_ID];  
00336   achar_t          preparer_id[ISO_MAX_PREPARER_ID]; 
00347   achar_t          application_id[ISO_MAX_APPLICATION_ID]; 
00359   dchar_t          copyright_file_id[37];     
00366   dchar_t          abstract_file_id[37];      
00368   dchar_t          bibliographic_file_id[37]; 
00370   iso9660_ltime_t  creation_date;             
00373   iso9660_ltime_t  modification_date;         
00377   iso9660_ltime_t  expiration_date;           
00380   iso9660_ltime_t  effective_date;            
00384   iso711_t         file_structure_version;    
00385   uint8_t           unused4[1];                
00386   char             application_data[512];     
00388   uint8_t          unused5[653];              
00389 } GNUC_PACKED;
00390 
00391 typedef struct iso9660_pvd_s  iso9660_pvd_t;
00392 
00400 struct iso9660_svd_s {
00401   iso711_t         type;                         
00403   char             id[5];                        
00405   iso711_t         version;                      
00406   char             flags;                        
00407   achar_t          system_id[ISO_MAX_SYSTEM_ID]; 
00409   dchar_t          volume_id[ISO_MAX_VOLUME_ID]; 
00411   char             unused2[8];
00412   iso733_t         volume_space_size;            
00414   char             escape_sequences[32];         
00415   iso723_t         volume_set_size;              
00416   iso723_t         volume_sequence_number;       
00417   iso723_t         logical_block_size;           
00418   iso733_t         path_table_size;              
00420   iso731_t         type_l_path_table;            
00422   iso731_t         opt_type_l_path_table;        
00425   iso732_t         type_m_path_table;            
00427   iso732_t         opt_type_m_path_table;        
00430   iso9660_dir_t    root_directory_record;        
00432   char             root_directory_filename;      
00435   dchar_t          volume_set_id[ISO_MAX_VOLUMESET_ID];    
00437   achar_t          publisher_id[ISO_MAX_PUBLISHER_ID]; 
00449   achar_t          preparer_id[ISO_MAX_PREPARER_ID]; 
00461   achar_t          application_id[ISO_MAX_APPLICATION_ID]; 
00473   dchar_t          copyright_file_id[37];     
00480   dchar_t          abstract_file_id[37];      
00482   dchar_t          bibliographic_file_id[37]; 
00484   iso9660_ltime_t  creation_date;             
00487   iso9660_ltime_t  modification_date;         
00491   iso9660_ltime_t  expiration_date;           
00494   iso9660_ltime_t  effective_date;            
00498   iso711_t         file_structure_version;    
00499   uint8_t           unused4[1];                
00500   char             application_data[512];     
00502   uint8_t          unused5[653];              
00503 } GNUC_PACKED;
00504 
00505 typedef struct iso9660_svd_s  iso9660_svd_t;
00506 
00507 PRAGMA_END_PACKED
00508 
00518 struct iso9660_stat_s { /* big endian!! */
00519 
00520   iso_rock_statbuf_t rr;              
00522   struct tm          tm;              
00524   lsn_t              lsn;             
00525   uint32_t           size;            
00526   uint32_t           secsize;         
00527   iso9660_xa_t       xa;              
00528   enum { _STAT_FILE = 1, _STAT_DIR = 2 } type;
00529   bool               b_xa;
00530   char         filename[EMPTY_ARRAY_SIZE]; 
00531 };
00532 
00535 typedef uint8_t iso_extension_mask_t;
00536 
00542 extern enum iso_extension_enum_s {
00543   ISO_EXTENSION_JOLIET_LEVEL1 = 0x01,
00544   ISO_EXTENSION_JOLIET_LEVEL2 = 0x02,
00545   ISO_EXTENSION_JOLIET_LEVEL3 = 0x04,
00546   ISO_EXTENSION_ROCK_RIDGE    = 0x08,
00547   ISO_EXTENSION_HIGH_SIERRA   = 0x10
00548 } iso_extension_enums;
00549   
00550 
00551 #define ISO_EXTENSION_ALL           0xFF
00552 #define ISO_EXTENSION_NONE          0x00
00553 #define ISO_EXTENSION_JOLIET     \
00554   (ISO_EXTENSION_JOLIET_LEVEL1 | \
00555    ISO_EXTENSION_JOLIET_LEVEL2 | \
00556    ISO_EXTENSION_JOLIET_LEVEL3 )
00557   
00558 
00560 typedef struct _iso9660_s iso9660_t; 
00561 
00569   bool iso9660_close (iso9660_t * p_iso);
00570 
00571 
00576   iso9660_t *iso9660_open (const char *psz_path /*flags, mode */);
00577   
00585   iso9660_t *iso9660_open_ext (const char *psz_path, 
00586                                iso_extension_mask_t iso_extension_mask);
00587   
00602   iso9660_t *iso9660_open_fuzzy (const char *psz_path /*flags, mode */,
00603                                  uint16_t i_fuzz);
00604 
00614   iso9660_t *iso9660_open_fuzzy_ext (const char *psz_path,
00615                                      iso_extension_mask_t iso_extension_mask,
00616                                      uint16_t i_fuzz
00617                                      /*flags, mode */);
00618 
00625   bool iso9660_ifs_fuzzy_read_superblock (iso9660_t *p_iso, 
00626                                           iso_extension_mask_t iso_extension_mask,
00627                                           uint16_t i_fuzz);
00628   
00645   long int iso9660_iso_seek_read (const iso9660_t *p_iso, /*out*/ void *ptr, 
00646                                   lsn_t start, long int i_size);
00647   
00652   bool iso9660_fs_read_pvd ( const CdIo_t *p_cdio, 
00653                              /*out*/ iso9660_pvd_t *p_pvd );
00654   
00659   bool iso9660_ifs_read_pvd (const iso9660_t *p_iso, 
00660                              /*out*/ iso9660_pvd_t *p_pvd);
00661   
00667   bool iso9660_fs_read_superblock (CdIo_t *p_cdio, 
00668                                    iso_extension_mask_t iso_extension_mask);
00669   
00675   bool iso9660_ifs_read_superblock (iso9660_t *p_iso,
00676                                     iso_extension_mask_t iso_extension_mask);
00677 
00678 
00679 /*====================================================
00680   Time conversion 
00681  ====================================================*/
00682 
00687   void iso9660_set_dtime (const struct tm *tm, 
00688                           /*out*/ iso9660_dtime_t *idr_date);
00689     
00690     
00696   void iso9660_set_dtime_with_timezone (const struct tm *p_tm, 
00697                                         int timezone,
00698                                         /*out*/ iso9660_dtime_t *p_idr_date);
00699     
00703   void iso9660_set_ltime (const struct tm *_tm, 
00704                           /*out*/ iso9660_ltime_t *p_pvd_date);
00705   
00709   void iso9660_set_ltime_with_timezone (const struct tm *_tm, 
00710                                         int timezone,
00711                                         /*out*/ iso9660_ltime_t *p_pvd_date);
00712   
00721   bool iso9660_get_dtime (const iso9660_dtime_t *idr_date, bool b_localtime,
00722                           /*out*/ struct tm *tm);
00723   
00724   
00729   bool iso9660_get_ltime (const iso9660_ltime_t *p_ldate, 
00730                           /*out*/ struct tm *p_tm);
00731   
00732   /*====================================================
00733     Character Classification and String Manipulation
00734     ====================================================*/
00740   bool iso9660_is_dchar (int c);
00741   
00747   bool iso9660_is_achar (int c);
00748   
00760   int iso9660_name_translate(const char *psz_oldname, 
00761                              /*out*/ char *psz_newname);
00762   
00778   int iso9660_name_translate_ext(const char *psz_oldname, char *psz_newname, 
00779                                  uint8_t i_joliet_level);
00780   
00792   char *iso9660_strncpy_pad(char dst[], const char src[], size_t len, 
00793                             enum strncpy_pad_check _check);
00794   
00795   /*=====================================================================
00796     File and Directory Names 
00797     ======================================================================*/
00798   
00809   bool iso9660_dirname_valid_p (const char psz_path[]);
00810   
00817   char *iso9660_pathname_isofy (const char psz_path[], uint16_t i_version);
00818   
00830   bool iso9660_pathname_valid_p (const char psz_path[]);
00831 
00832 /*=====================================================================
00833   directory tree 
00834 ======================================================================*/
00835 
00836 void
00837 iso9660_dir_init_new (void *dir, uint32_t self, uint32_t ssize, 
00838                       uint32_t parent, uint32_t psize, 
00839                       const time_t *dir_time);
00840 
00841 void
00842 iso9660_dir_init_new_su (void *dir, uint32_t self, uint32_t ssize, 
00843                          const void *ssu_data, unsigned int ssu_size, 
00844                          uint32_t parent, uint32_t psize, 
00845                          const void *psu_data, unsigned int psu_size,
00846                          const time_t *dir_time);
00847 
00848 void
00849 iso9660_dir_add_entry_su (void *dir, const char filename[], uint32_t extent,
00850                           uint32_t size, uint8_t file_flags, 
00851                           const void *su_data,
00852                           unsigned int su_size, const time_t *entry_time);
00853 
00854 unsigned int 
00855 iso9660_dir_calc_record_size (unsigned int namelen, unsigned int su_len);
00856 
00864 #define iso9660_fs_find_lsn  iso9660_find_fs_lsn 
00865 iso9660_stat_t *iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn);
00866 
00867 
00875 iso9660_stat_t *iso9660_fs_find_lsn_with_path(CdIo_t *p_cdio, lsn_t i_lsn,
00876                                               /*out*/ char **ppsz_path);
00877 
00885 iso9660_stat_t *iso9660_ifs_find_lsn(iso9660_t *p_iso, lsn_t i_lsn);
00886 
00887 
00902 iso9660_stat_t *iso9660_ifs_find_lsn_with_path(iso9660_t *p_iso, 
00903                                                lsn_t i_lsn,
00904                                                /*out*/ char **ppsz_path);
00905 
00906 
00925 iso9660_stat_t *iso9660_fs_stat (CdIo_t *p_cdio, const char psz_path[]);
00926   
00927 
00935 iso9660_stat_t *iso9660_fs_stat_translate (CdIo_t *p_cdio, 
00936                                            const char psz_path[], 
00937                                            bool b_mode2);
00938 
00942 iso9660_stat_t *iso9660_ifs_stat (iso9660_t *p_iso, const char psz_path[]);
00943 
00944 
00949 iso9660_stat_t *iso9660_ifs_stat_translate (iso9660_t *p_iso, 
00950                                             const char psz_path[]);
00951 
00958 CdioList_t * iso9660_fs_readdir (CdIo_t *p_cdio, const char psz_path[], 
00959                                  bool b_mode2);
00960 
00965 CdioList_t * iso9660_ifs_readdir (iso9660_t *p_iso, const char psz_path[]);
00966 
00971 char * iso9660_get_application_id(iso9660_pvd_t *p_pvd);
00972   
00977 bool iso9660_ifs_get_application_id(iso9660_t *p_iso,
00978                                     /*out*/ cdio_utf8_t **p_psz_app_id);
00979 
00983 uint8_t iso9660_ifs_get_joliet_level(iso9660_t *p_iso);
00984 
00985 uint8_t iso9660_get_dir_len(const iso9660_dir_t *p_idr);
00986 
00987 #ifdef FIXME
00988 uint8_t iso9660_get_dir_size(const iso9660_dir_t *p_idr);
00989 
00990 lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
00991 #endif
00992 
00999   char * iso9660_dir_to_name (const iso9660_dir_t *p_iso9660_dir);
01000   
01004   mode_t iso9660_get_posix_filemode(const iso9660_stat_t *p_iso_dirent);
01005 
01010   char *iso9660_get_preparer_id(const iso9660_pvd_t *p_pvd);
01011   
01016   bool iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
01017                                    /*out*/ cdio_utf8_t **p_psz_preparer_id);
01018   
01023   char *iso9660_get_publisher_id(const iso9660_pvd_t *p_pvd);
01024   
01029   bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
01030                                     /*out*/ cdio_utf8_t **p_psz_publisher_id);
01031   
01032   uint8_t iso9660_get_pvd_type(const iso9660_pvd_t *p_pvd);
01033   
01034   const char * iso9660_get_pvd_id(const iso9660_pvd_t *p_pvd);
01035   
01036   int iso9660_get_pvd_space_size(const iso9660_pvd_t *p_pvd);
01037   
01038   int iso9660_get_pvd_block_size(const iso9660_pvd_t *p_pvd) ;
01039   
01043   int iso9660_get_pvd_version(const iso9660_pvd_t *pvd) ;
01044   
01049   char *iso9660_get_system_id(const iso9660_pvd_t *p_pvd);
01050   
01055   bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
01056                                  /*out*/ cdio_utf8_t **p_psz_system_id);
01057   
01058   
01062   lsn_t iso9660_get_root_lsn(const iso9660_pvd_t *p_pvd);
01063   
01068   char *iso9660_get_volume_id(const iso9660_pvd_t *p_pvd);
01069   
01074   bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
01075                                  /*out*/ cdio_utf8_t **p_psz_volume_id);
01076   
01081   char *iso9660_get_volumeset_id(const iso9660_pvd_t *p_pvd);
01082   
01087   bool iso9660_ifs_get_volumeset_id(iso9660_t *p_iso,
01088                                     /*out*/ cdio_utf8_t **p_psz_volumeset_id);
01089   
01090   /* pathtable */
01091   
01093   void iso9660_pathtable_init (void *pt);
01094   
01095   unsigned int iso9660_pathtable_get_size (const void *pt);
01096   
01097   uint16_t iso9660_pathtable_l_add_entry (void *pt, const char name[], 
01098                                           uint32_t extent, uint16_t parent);
01099   
01100   uint16_t iso9660_pathtable_m_add_entry (void *pt, const char name[], 
01101                                           uint32_t extent, uint16_t parent);
01102   
01107   void iso9660_set_pvd (void *pd, const char volume_id[], 
01108                         const char application_id[], 
01109                         const char publisher_id[], const char preparer_id[],
01110                         uint32_t iso_size, const void *root_dir, 
01111                         uint32_t path_table_l_extent, 
01112                         uint32_t path_table_m_extent,
01113                         uint32_t path_table_size, const time_t *pvd_time);
01114 
01115   void iso9660_set_evd (void *pd);
01116 
01120   bool iso9660_ifs_is_xa (const iso9660_t * p_iso);
01121 
01122 
01123 #ifndef DO_NOT_WANT_COMPATIBILITY
01124 
01125 #define iso9660_isdchar       iso9660_is_dchar
01126 #define iso9660_isachar       iso9660_is_achar
01127 #endif /*DO_NOT_WANT_COMPATIBILITY*/
01128 
01129 #ifdef __cplusplus
01130 }
01131 #endif /* __cplusplus */
01132 
01133 #undef ISODCL
01134 #endif /* CDIO_ISO9660_H_ */
01135 
01136 /* 
01137  * Local variables:
01138  *  c-file-style: "gnu"
01139  *  tab-width: 8
01140  *  indent-tabs-mode: nil
01141  * End:
01142  */