iso9660.h

Go to the documentation of this file.
00001 /*
00002     $Id: iso9660.h,v 1.102 2008/07/16 00:28:54 rocky Exp $
00003 
00004     Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
00005                   Rocky Bernstein <rocky@gnu.org>
00006     Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
00007 
00008     See also iso9660.h by Eric Youngdale (1993).
00009 
00010     Copyright 1993 Yggdrasil Computing, Incorporated
00011 
00012     This program is free software: you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation, either version 3 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00024 */
00035 
00036 #ifndef __CDIO_ISO9660_H__
00037 #define __CDIO_ISO9660_H__
00038 
00039 #include <time.h>
00040 
00041 #include <cdio/cdio.h>
00042 #include <cdio/ds.h>
00043 #include <cdio/posix.h>
00044 
00051 typedef uint8_t  iso711_t; 
00052 typedef int8_t   iso712_t; 
00053 typedef uint16_t iso721_t; 
00054 typedef uint16_t iso722_t; 
00055 typedef uint32_t iso723_t; 
00056 typedef uint32_t iso731_t; 
00057 typedef uint32_t iso732_t; 
00058 typedef uint64_t iso733_t; 
00060 typedef char     achar_t;  
00061 typedef char     dchar_t;  
00063 #ifndef  EMPTY_ARRAY_SIZE
00064 #define EMPTY_ARRAY_SIZE 0
00065 #endif
00066 
00067 #include <cdio/types.h>
00068 #include <cdio/xa.h>
00069 
00070 #ifdef ISODCL
00071 #undef ISODCL
00072 #endif
00073 /* This part borrowed from the bsd386 isofs */
00074 #define ISODCL(from, to)        ((to) - (from) + 1)
00075 
00076 #define MIN_TRACK_SIZE 4*75
00077 #define MIN_ISO_SIZE MIN_TRACK_SIZE
00078 
00085 extern enum iso_enum1_s {
00086   ISO_PVD_SECTOR      =   16, 
00087   ISO_EVD_SECTOR      =   17, 
00088   LEN_ISONAME         =   31, 
00090   ISO_MAX_SYSTEM_ID   =   32, 
00092   MAX_ISONAME         =   37, 
00094   ISO_MAX_PREPARER_ID =  128, 
00096   MAX_ISOPATHNAME     =  255, 
00098   ISO_BLOCKSIZE       = 2048  
00100 } iso_enums1;
00101 
00109 extern enum iso_flag_enum_s {
00110   ISO_FILE            =   0,   
00111   ISO_EXISTENCE       =   1,   
00112   ISO_DIRECTORY       =   2,   
00113   ISO_ASSOCIATED      =   4,   
00114   ISO_RECORD          =   8,   
00115   ISO_PROTECTION      =  16,   
00116   ISO_DRESERVED1      =  32,   
00117   ISO_DRESERVED2      =  64,   
00118   ISO_MULTIEXTENT     = 128,   
00119 } iso_flag_enums;
00120 
00122 extern enum iso_vd_enum_s {
00123   ISO_VD_BOOT_RECORD   =  0,  
00124   ISO_VD_PRIMARY       =  1,  
00125   ISO_VD_SUPPLEMENTARY =  2,  
00126   ISO_VD_PARITION      =  3,  
00127   ISO_VD_END           = 255
00128 } iso_vd_enums;
00129 
00130   
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;    
00274   iso711_t         filename_len;      
00275   char             filename[EMPTY_ARRAY_SIZE];
00276 } GNUC_PACKED;
00277 
00281 struct iso9660_pvd_s {
00282   iso711_t         type;                         
00283   char             id[5];                        
00285   iso711_t         version;                      
00286   char             unused1[1];                   
00287   achar_t          system_id[ISO_MAX_SYSTEM_ID]; 
00288   dchar_t          volume_id[ISO_MAX_VOLUME_ID]; 
00289   uint8_t          unused2[8];                   
00290   iso733_t         volume_space_size;            
00292   uint8_t          unused3[32];                  
00293   iso723_t         volume_set_size;              
00294   iso723_t         volume_sequence_number;       
00295   iso723_t         logical_block_size;           
00296   iso733_t         path_table_size;              
00297   iso731_t         type_l_path_table;            
00299   iso731_t         opt_type_l_path_table;        
00301   iso732_t         type_m_path_table;            
00303   iso732_t         opt_type_m_path_table;        
00305   iso9660_dir_t    root_directory_record;        
00308   char             root_directory_filename;      
00311   dchar_t          volume_set_id[ISO_MAX_VOLUMESET_ID]; 
00315   achar_t          publisher_id[ISO_MAX_PUBLISHER_ID];  
00326   achar_t          preparer_id[ISO_MAX_PREPARER_ID]; 
00337   achar_t          application_id[ISO_MAX_APPLICATION_ID]; 
00349   dchar_t          copyright_file_id[37];     
00356   dchar_t          abstract_file_id[37];      
00358   dchar_t          bibliographic_file_id[37]; 
00360   iso9660_ltime_t  creation_date;             
00363   iso9660_ltime_t  modification_date;         
00367   iso9660_ltime_t  expiration_date;           
00370   iso9660_ltime_t  effective_date;            
00374   iso711_t         file_structure_version;    
00375   uint8_t           unused4[1];                
00376   char             application_data[512];     
00378   uint8_t          unused5[653];              
00379 } GNUC_PACKED;
00380 
00381 typedef struct iso9660_pvd_s  iso9660_pvd_t;
00382 
00390 struct iso9660_svd_s {
00391   iso711_t         type;                         
00393   char             id[5];                        
00395   iso711_t         version;                      
00396   char             flags;                        
00397   achar_t          system_id[ISO_MAX_SYSTEM_ID]; 
00399   dchar_t          volume_id[ISO_MAX_VOLUME_ID]; 
00401   char             unused2[8];
00402   iso733_t         volume_space_size;            
00404   char             escape_sequences[32];         
00405   iso723_t         volume_set_size;              
00406   iso723_t         volume_sequence_number;       
00407   iso723_t         logical_block_size;           
00408   iso733_t         path_table_size;              
00410   iso731_t         type_l_path_table;            
00412   iso731_t         opt_type_l_path_table;        
00415   iso732_t         type_m_path_table;            
00417   iso732_t         opt_type_m_path_table;        
00420   iso9660_dir_t    root_directory_record;        
00422   char             root_directory_filename;      
00425   dchar_t          volume_set_id[ISO_MAX_VOLUMESET_ID];    
00427   achar_t          publisher_id[ISO_MAX_PUBLISHER_ID]; 
00439   achar_t          preparer_id[ISO_MAX_PREPARER_ID]; 
00451   achar_t          application_id[ISO_MAX_APPLICATION_ID]; 
00463   dchar_t          copyright_file_id[37];     
00470   dchar_t          abstract_file_id[37];      
00472   dchar_t          bibliographic_file_id[37]; 
00474   iso9660_ltime_t  creation_date;             
00477   iso9660_ltime_t  modification_date;         
00481   iso9660_ltime_t  expiration_date;           
00484   iso9660_ltime_t  effective_date;            
00488   iso711_t         file_structure_version;    
00489   uint8_t           unused4[1];                
00490   char             application_data[512];     
00492   uint8_t          unused5[653];              
00493 } GNUC_PACKED;
00494 
00495 typedef struct iso9660_svd_s  iso9660_svd_t;
00496 
00497 PRAGMA_END_PACKED
00498 
00508 struct iso9660_stat_s { /* big endian!! */
00509 
00510   iso_rock_statbuf_t rr;              
00512   struct tm          tm;              
00514   lsn_t              lsn;             
00515   uint32_t           size;            
00516   uint32_t           secsize;         
00517   iso9660_xa_t       xa;              
00518   enum { _STAT_FILE = 1, _STAT_DIR = 2 } type;
00519   bool               b_xa;
00520   char         filename[EMPTY_ARRAY_SIZE]; 
00521 };
00522 
00525 typedef uint8_t iso_extension_mask_t;
00526 
00532 extern enum iso_extension_enum_s {
00533   ISO_EXTENSION_JOLIET_LEVEL1 = 0x01,
00534   ISO_EXTENSION_JOLIET_LEVEL2 = 0x02,
00535   ISO_EXTENSION_JOLIET_LEVEL3 = 0x04,
00536   ISO_EXTENSION_ROCK_RIDGE    = 0x08,
00537   ISO_EXTENSION_HIGH_SIERRA   = 0x10
00538 } iso_extension_enums;
00539   
00540 
00541 #define ISO_EXTENSION_ALL           0xFF
00542 #define ISO_EXTENSION_NONE          0x00
00543 #define ISO_EXTENSION_JOLIET     \
00544   (ISO_EXTENSION_JOLIET_LEVEL1 | \
00545    ISO_EXTENSION_JOLIET_LEVEL2 | \
00546    ISO_EXTENSION_JOLIET_LEVEL3 )
00547   
00548 
00550 typedef struct _iso9660_s iso9660_t; 
00551 
00559   bool iso9660_close (iso9660_t * p_iso);
00560 
00561 
00566   iso9660_t *iso9660_open (const char *psz_path /*flags, mode */);
00567   
00575   iso9660_t *iso9660_open_ext (const char *psz_path, 
00576                                iso_extension_mask_t iso_extension_mask);
00577   
00592   iso9660_t *iso9660_open_fuzzy (const char *psz_path /*flags, mode */,
00593                                  uint16_t i_fuzz);
00594 
00604   iso9660_t *iso9660_open_fuzzy_ext (const char *psz_path,
00605                                      iso_extension_mask_t iso_extension_mask,
00606                                      uint16_t i_fuzz
00607                                      /*flags, mode */);
00608 
00615   bool iso9660_ifs_fuzzy_read_superblock (iso9660_t *p_iso, 
00616                                           iso_extension_mask_t iso_extension_mask,
00617                                           uint16_t i_fuzz);
00618   
00635   long int iso9660_iso_seek_read (const iso9660_t *p_iso, /*out*/ void *ptr, 
00636                                   lsn_t start, long int i_size);
00637   
00642   bool iso9660_fs_read_pvd ( const CdIo_t *p_cdio, 
00643                              /*out*/ iso9660_pvd_t *p_pvd );
00644   
00649   bool iso9660_ifs_read_pvd (const iso9660_t *p_iso, 
00650                              /*out*/ iso9660_pvd_t *p_pvd);
00651   
00657   bool iso9660_fs_read_superblock (CdIo_t *p_cdio, 
00658                                    iso_extension_mask_t iso_extension_mask);
00659   
00665   bool iso9660_ifs_read_superblock (iso9660_t *p_iso,
00666                                     iso_extension_mask_t iso_extension_mask);
00667 
00668 
00669 /*====================================================
00670   Time conversion 
00671  ====================================================*/
00675   void iso9660_set_dtime (const struct tm *tm, 
00676                           /*out*/ iso9660_dtime_t *idr_date);
00677 
00678 
00682   void iso9660_set_ltime (const struct tm *_tm, 
00683                           /*out*/ iso9660_ltime_t *p_pvd_date);
00684   
00693   bool iso9660_get_dtime (const iso9660_dtime_t *idr_date, bool b_localtime,
00694                           /*out*/ struct tm *tm);
00695   
00696   
00701   bool iso9660_get_ltime (const iso9660_ltime_t *p_ldate, 
00702                           /*out*/ struct tm *p_tm);
00703   
00704   /*====================================================
00705     Character Classification and String Manipulation
00706     ====================================================*/
00712   bool iso9660_is_dchar (int c);
00713   
00719   bool iso9660_is_achar (int c);
00720   
00732   int iso9660_name_translate(const char *psz_oldname, 
00733                              /*out*/ char *psz_newname);
00734   
00750   int iso9660_name_translate_ext(const char *psz_oldname, char *psz_newname, 
00751                                  uint8_t i_joliet_level);
00752   
00764   char *iso9660_strncpy_pad(char dst[], const char src[], size_t len, 
00765                             enum strncpy_pad_check _check);
00766   
00767   /*=====================================================================
00768     File and Directory Names 
00769     ======================================================================*/
00770   
00781   bool iso9660_dirname_valid_p (const char psz_path[]);
00782   
00789   char *iso9660_pathname_isofy (const char psz_path[], uint16_t i_version);
00790   
00802   bool iso9660_pathname_valid_p (const char psz_path[]);
00803 
00804 /*=====================================================================
00805   directory tree 
00806 ======================================================================*/
00807 
00808 void
00809 iso9660_dir_init_new (void *dir, uint32_t self, uint32_t ssize, 
00810                       uint32_t parent, uint32_t psize, 
00811                       const time_t *dir_time);
00812 
00813 void
00814 iso9660_dir_init_new_su (void *dir, uint32_t self, uint32_t ssize, 
00815                          const void *ssu_data, unsigned int ssu_size, 
00816                          uint32_t parent, uint32_t psize, 
00817                          const void *psu_data, unsigned int psu_size,
00818                          const time_t *dir_time);
00819 
00820 void
00821 iso9660_dir_add_entry_su (void *dir, const char filename[], uint32_t extent,
00822                           uint32_t size, uint8_t file_flags, 
00823                           const void *su_data,
00824                           unsigned int su_size, const time_t *entry_time);
00825 
00826 unsigned int 
00827 iso9660_dir_calc_record_size (unsigned int namelen, unsigned int su_len);
00828 
00836 #define iso9660_fs_find_lsn  iso9660_find_fs_lsn 
00837 iso9660_stat_t *iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn);
00838 
00839 
00847 iso9660_stat_t *iso9660_fs_find_lsn_with_path(CdIo_t *p_cdio, lsn_t i_lsn,
00848                                               /*out*/ char **ppsz_path);
00849 
00857 iso9660_stat_t *iso9660_ifs_find_lsn(iso9660_t *p_iso, lsn_t i_lsn);
00858 
00859 
00874 iso9660_stat_t *iso9660_ifs_find_lsn_with_path(iso9660_t *p_iso, 
00875                                                lsn_t i_lsn,
00876                                                /*out*/ char **ppsz_path);
00877 
00878 
00897 iso9660_stat_t *iso9660_fs_stat (CdIo_t *p_cdio, const char psz_path[]);
00898   
00899 
00907 iso9660_stat_t *iso9660_fs_stat_translate (CdIo_t *p_cdio, 
00908                                            const char psz_path[], 
00909                                            bool b_mode2);
00910 
00914 iso9660_stat_t *iso9660_ifs_stat (iso9660_t *p_iso, const char psz_path[]);
00915 
00916 
00921 iso9660_stat_t *iso9660_ifs_stat_translate (iso9660_t *p_iso, 
00922                                             const char psz_path[]);
00923 
00930 CdioList_t * iso9660_fs_readdir (CdIo_t *p_cdio, const char psz_path[], 
00931                                  bool b_mode2);
00932 
00937 CdioList_t * iso9660_ifs_readdir (iso9660_t *p_iso, const char psz_path[]);
00938 
00943 char * iso9660_get_application_id(iso9660_pvd_t *p_pvd);
00944   
00949 bool iso9660_ifs_get_application_id(iso9660_t *p_iso,
00950                                     /*out*/ cdio_utf8_t **p_psz_app_id);
00951 
00955 uint8_t iso9660_ifs_get_joliet_level(iso9660_t *p_iso);
00956 
00957 uint8_t iso9660_get_dir_len(const iso9660_dir_t *p_idr);
00958 
00959 #if FIXME
00960 uint8_t iso9660_get_dir_size(const iso9660_dir_t *p_idr);
00961 
00962 lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
00963 #endif
00964 
00971   char * iso9660_dir_to_name (const iso9660_dir_t *p_iso9660_dir);
00972   
00976   mode_t iso9660_get_posix_filemode(const iso9660_stat_t *p_iso_dirent);
00977 
00982   char *iso9660_get_preparer_id(const iso9660_pvd_t *p_pvd);
00983   
00988   bool iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
00989                                    /*out*/ cdio_utf8_t **p_psz_preparer_id);
00990   
00995   char *iso9660_get_publisher_id(const iso9660_pvd_t *p_pvd);
00996   
01001   bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
01002                                     /*out*/ cdio_utf8_t **p_psz_publisher_id);
01003   
01004   uint8_t iso9660_get_pvd_type(const iso9660_pvd_t *p_pvd);
01005   
01006   const char * iso9660_get_pvd_id(const iso9660_pvd_t *p_pvd);
01007   
01008   int iso9660_get_pvd_space_size(const iso9660_pvd_t *p_pvd);
01009   
01010   int iso9660_get_pvd_block_size(const iso9660_pvd_t *p_pvd) ;
01011   
01015   int iso9660_get_pvd_version(const iso9660_pvd_t *pvd) ;
01016   
01021   char *iso9660_get_system_id(const iso9660_pvd_t *p_pvd);
01022   
01027   bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
01028                                  /*out*/ cdio_utf8_t **p_psz_system_id);
01029   
01030   
01034   lsn_t iso9660_get_root_lsn(const iso9660_pvd_t *p_pvd);
01035   
01040   char *iso9660_get_volume_id(const iso9660_pvd_t *p_pvd);
01041   
01046   bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
01047                                  /*out*/ cdio_utf8_t **p_psz_volume_id);
01048   
01053   char *iso9660_get_volumeset_id(const iso9660_pvd_t *p_pvd);
01054   
01059   bool iso9660_ifs_get_volumeset_id(iso9660_t *p_iso,
01060                                     /*out*/ cdio_utf8_t **p_psz_volumeset_id);
01061   
01062   /* pathtable */
01063   
01065   void iso9660_pathtable_init (void *pt);
01066   
01067   unsigned int iso9660_pathtable_get_size (const void *pt);
01068   
01069   uint16_t iso9660_pathtable_l_add_entry (void *pt, const char name[], 
01070                                           uint32_t extent, uint16_t parent);
01071   
01072   uint16_t iso9660_pathtable_m_add_entry (void *pt, const char name[], 
01073                                           uint32_t extent, uint16_t parent);
01074   
01079   void iso9660_set_pvd (void *pd, const char volume_id[], 
01080                         const char application_id[], 
01081                         const char publisher_id[], const char preparer_id[],
01082                         uint32_t iso_size, const void *root_dir, 
01083                         uint32_t path_table_l_extent, 
01084                         uint32_t path_table_m_extent,
01085                         uint32_t path_table_size, const time_t *pvd_time);
01086 
01087   void iso9660_set_evd (void *pd);
01088 
01092   bool iso9660_ifs_is_xa (const iso9660_t * p_iso);
01093 
01094 
01095 #ifndef DO_NOT_WANT_COMPATIBILITY
01096 
01097 #define iso9660_isdchar       iso9660_is_dchar
01098 #define iso9660_isachar       iso9660_is_achar
01099 #endif /*DO_NOT_WANT_COMPATIBILITY*/
01100 
01101 #ifdef __cplusplus
01102 }
01103 #endif /* __cplusplus */
01104 
01105 #undef ISODCL
01106 #endif /* __CDIO_ISO9660_H__ */
01107 
01108 /* 
01109  * Local variables:
01110  *  c-file-style: "gnu"
01111  *  tab-width: 8
01112  *  indent-tabs-mode: nil
01113  * End:
01114  */

Generated for libcdio by doxygen 1.4.7