00001 00002 /* 00003 Class struct of libisoburn. 00004 00005 Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es> 00006 and Thomas Schmitt <scdbackup@gmx.net> 00007 */ 00008 00009 #ifndef Isoburn_includeD 00010 #define Isoburn_includeD 00011 00012 00013 /* for uint8_t */ 00014 #include <stdint.h> 00015 00016 /* For emulated TOC of overwriteable media. 00017 Provides minimal info for faking a struct burn_toc_entry. 00018 */ 00019 struct isoburn_toc_entry { 00020 int session; 00021 int track_no; /* point */ 00022 int start_lba; 00023 int track_blocks; 00024 00025 struct isoburn_toc_entry *next; 00026 }; 00027 00028 int isoburn_toc_entry_new(struct isoburn_toc_entry **objpt, 00029 struct isoburn_toc_entry *boss, int flag); 00030 00031 /* @param flag bit0= delete all subordinates too 00032 */ 00033 int isoburn_toc_entry_destroy(struct isoburn_toc_entry **o, int flag); 00034 00035 00036 /* Size of target_iso_head which is to be written during 00037 isoburn_activate_session() 00038 */ 00039 #define Libisoburn_target_head_sizE (32*2048) 00040 00041 struct isoburn { 00042 00043 00044 /* The libburn drive to which this isoburn object is related 00045 Most isoburn calls will use a burn_drive as object handle */ 00046 struct burn_drive *drive; 00047 00048 /* -1= inappropriate media state detected 00049 0= libburn multi-session media, resp. undecided yet 00050 1= random access media */ 00051 int emulation_mode; 00052 00053 /* Although rarely used, libburn can operate on several 00054 drives simultaneously. */ 00055 struct isoburn *prev; 00056 struct isoburn *next; 00057 00058 00059 /* If >= 0, this address is used as reply for isoburn_disc_get_msc1() 00060 */ 00061 int fabricated_msc1; 00062 00063 /* If >= 0, this address is used in isoburn_disc_track_lba_nwa() 00064 as reply parameter nwa. 00065 (The other nwa parameters below apply only to the effective write address 00066 on random access media. msc2 is handed to libisofs but not to libburn.) 00067 */ 00068 int fabricated_msc2; 00069 00070 00071 /* The nwa to be used for a first session on the present kind of overwriteable 00072 media (usually Libisoburn_overwriteable_starT, but might be forced to 0) 00073 */ 00074 int zero_nwa; 00075 00076 /* Start address as given by image examination (bytes, not blocks) */ 00077 off_t min_start_byte; 00078 00079 /* Aligned start address to be used for processing (counted in blocks) */ 00080 int nwa; 00081 00082 00083 /* Truncate to .nwa an eventual regular file serving as output drive */ 00084 int truncate; 00085 00086 /* Eventual freely fabricated isoburn_disc_get_status(). 00087 BURN_DISC_UNREADY means that this variable is disabled 00088 and normally emulated status is in effect. 00089 */ 00090 enum burn_disc_status fabricated_disc_status; 00091 00092 /* Eventual emulated table of content read from the chain of ISO headers 00093 on overwriteable media. 00094 */ 00095 struct isoburn_toc_entry *toc; 00096 00097 /* Indicator wether the most recent burn run worked : 00098 -1 = undetermined, ask libburn , 0 = failure , 1 = success 00099 To be inquired by isoburn_drive_wrote_well() 00100 */ 00101 int wrote_well; 00102 00103 00104 /* Buffered ISO head from media (should that become part of 00105 ecma119_read_opts ?) */ 00106 uint8_t target_iso_head[Libisoburn_target_head_sizE]; 00107 00108 /* Libisofs image context */ 00109 IsoImage *image; 00110 00111 /* The block data source from which the existing image is read. 00112 */ 00113 IsoDataSource *iso_data_source; 00114 00115 /* The burn source which transfers data from libisofs to libburn. 00116 It has its own fifo. 00117 */ 00118 struct burn_source *iso_source; 00119 00120 /* For iso_tree_set_report_callback() */ 00121 int (*read_pacifier)(IsoImage*, IsoFileSource*); 00122 00123 /* For iso_image_attach_data() */ 00124 void *read_pacifier_handle; 00125 00126 /* An application provided method to immediately deliver messages */ 00127 int (*msgs_submit)(void *handle, int error_code, char msg_text[], 00128 int os_errno, char severity[], int flag); 00129 void *msgs_submit_handle; /* specific to application method */ 00130 int msgs_submit_flag; /* specific to application method */ 00131 00132 }; 00133 00134 00135 /* Creation and disposal function */ 00136 int isoburn_new(struct isoburn **objpt, int flag); 00137 int isoburn_destroy(struct isoburn **objpt, int flag); 00138 00139 /* Eventual readers for public attributes */ 00140 /* ( put into separate .h file then ) */ 00141 int isoburn_get_emulation_mode(struct isoburn *o, int *pt, int flag); 00142 int isoburn_get_target_volset(struct isoburn *o, IsoImage **pt, int flag); 00143 00144 /* List management */ 00145 int isoburn_get_prev(struct isoburn *o, struct isoburn **pt, int flag); 00146 int isoburn_get_next(struct isoburn *o, struct isoburn **pt, int flag); 00147 int isoburn_destroy_all(struct isoburn **objpt, int flag); 00148 int isoburn_link(struct isoburn *o, struct isoburn *link, int flag); 00149 int isoburn_count(struct isoburn *o, int flag); 00150 int isoburn_by_idx(struct isoburn *o, int idx, struct isoburn **pt, int flag); 00151 int isoburn_find_by_drive(struct isoburn **pt, struct burn_drive *d, int flag); 00152 00153 00154 /* Non API inner interfaces */ 00155 00156 /* Submit a libisofs error to the libburn messenger. An application message 00157 reader shall recognize the error code range and attribute it to the 00158 libisofs message channel to which one cannot submit via API. 00159 @param iso_error_code return value <= 0 from a libisofs API call. 00160 @param default_msg_text is to be put out if iso_error_code leads to no 00161 error message 00162 @param os_errno operating system errno, submit 0 if none is known 00163 @param min_severity minimum severity, might be be increased if libisofs 00164 error severity surpasses min_severity. 00165 @param flag Bitfield, submit 0 for now 00166 */ 00167 int isoburn_report_iso_error(int iso_error_code, char default_msg_text[], 00168 int os_errno, char min_severity[], int flag); 00169 00170 /* Calls from burn_wrap.c into isofs_wrap.c */ 00171 00172 int isoburn_start_emulation(struct isoburn *o, int flag); 00173 int isoburn_invalidate_iso(struct isoburn *o, int flag); 00174 00175 00176 /* Calls from isofs_wrap.c into burn_wrap.c */ 00177 00178 /** Get an eventual isoburn object which is wrapped around the drive. 00179 @param pt Eventually returns a pointer to the found object. 00180 It is allowed to become NULL if return value is -1 or 0. 00181 In this case, the drive is a genuine libburn drive 00182 with no emulation activated by isoburn. 00183 @param drive The drive to be searched for 00184 @param flag unused yet 00185 @return -1 unsuitable media, 0 generic media, 1 emulated media. 00186 */ 00187 int isoburn_find_emulator(struct isoburn **pt, 00188 struct burn_drive *drive, int flag); 00189 00190 /* Deliver an event message. Either via a non-NULL o->msgs_submit() method 00191 or via burn_msgs_submit() of libburn. 00192 */ 00193 int isoburn_msgs_submit(struct isoburn *o, int error_code, char msg_text[], 00194 int os_errno, char severity[], int flag); 00195 00196 /** Set the start address for an emulated add-on session. The value will 00197 be rounded up to the alignment necessary for the media. The aligned 00198 value will be divided by 2048 and then put into o->nwa . 00199 @param o The isoburn object to be programmed. 00200 @param value The start address in bytes 00201 @param flag unused yet 00202 @return <=0 is failure , >0 success 00203 */ 00204 int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag); 00205 00206 /** Obtains the image address offset to be used with image generation. 00207 This is either the (emulated) drive nwa or a value set by 00208 isoburn_prepare_blind_grow(). 00209 In any case this is the address to tell to iso_write_opts_set_ms_block(). 00210 @param o The isoburn object to be inquired 00211 @param opts If not NULL: write parameters to be set on drive before query 00212 @param msc2 The value to be used with iso_write_opts_set_ms_block() 00213 @param flag unused yet 00214 @return <=0 is failure , >0 success 00215 */ 00216 int isoburn_get_msc2(struct isoburn *o, 00217 struct burn_write_opts *opts, int *msc2, int flag); 00218 00219 /** Get a data source suitable for read from a drive using burn_read_data() 00220 function. 00221 @param d drive to read from. Must be grabbed. 00222 @return the data source, NULL on error. Must be freed with libisofs 00223 iso_data_source_unref() function. Note: this doesn't release 00224 the drive. 00225 */ 00226 IsoDataSource * 00227 isoburn_data_source_new(struct burn_drive *d); 00228 00229 /** Disable read capabilities of a data source which was originally created 00230 by isoburn_data_source_new(). After this any attempt to read will yield 00231 a FATAL programming error event. 00232 This is usually done to allow libburn to release the drive while libisofs 00233 still holds a reference to the data source object. libisofs is not supposed 00234 to use this object for reading any more, nevertheless. The disabled state 00235 of the data source is a safety fence around this daring situation. 00236 @param src The data source to be disabled 00237 @param flag unused yet 00238 @return <=0 is failure , >0 success 00239 */ 00240 int isoburn_data_source_shutdown(IsoDataSource *src, int flag); 00241 00242 00243 /** 00244 * Options for image reading. 00245 (Comments here may be outdated. API getter/setter function descriptions 00246 may override the descriptions here. Any difference is supposed to be a 00247 minor correction only.) 00248 */ 00249 struct isoburn_read_opts { 00250 unsigned int norock:1; /*< Do not read Rock Ridge extensions */ 00251 unsigned int nojoliet:1; /*< Do not read Joliet extensions */ 00252 unsigned int noiso1999:1; /*< Do not read ISO 9660:1999 enhanced tree */ 00253 00254 /* ts A90121 */ 00255 unsigned int noaaip:1; /* Do not read AAIP for ACL and EA */ 00256 unsigned int noacl:1; /* Do not read ACL from external file objects */ 00257 unsigned int noea:1; /* Do not read XFS-style EA from externals */ 00258 00259 unsigned int preferjoliet:1; 00260 /*< When both Joliet and RR extensions are present, the RR 00261 * tree is used. If you prefer using Joliet, set this to 1. */ 00262 uid_t uid; /**< Default uid when no RR */ 00263 gid_t gid; /**< Default uid when no RR */ 00264 mode_t mode; /**< Default mode when no RR (only permissions) */ 00265 mode_t dirmode; /**< Default mode for directories 00266 when no RR (only permissions) */ 00267 00268 /** 00269 * Input charset for RR file names. NULL to use default locale charset. 00270 */ 00271 char *input_charset; 00272 00273 /* modified by the function isoburn_read_image */ 00274 unsigned int hasRR:1; /*< It will be set to 1 if RR extensions are present, 00275 to 0 if not. */ 00276 unsigned int hasJoliet:1; /*< It will be set to 1 if Joliet extensions are 00277 present, to 0 if not. */ 00278 00279 /** 00280 * It will be set to 1 if the image is an ISO 9660:1999, i.e. it has 00281 * a version 2 Enhanced Volume Descriptor. 00282 */ 00283 unsigned int hasIso1999:1; 00284 00285 /** It will be set to 1 if El-Torito boot record is present, to 0 if not.*/ 00286 unsigned int hasElTorito:1; 00287 00288 uint32_t size; /**< Will be filled with the size (in 2048 byte block) of 00289 * the image, as reported in the PVM. */ 00290 unsigned int pretend_blank:1; /* always create empty image */ 00291 }; 00292 00293 00294 /** 00295 * Options for image generation by libisofs and image transport to libburn. 00296 (Comments here may be outdated. API getter/setter function descriptions 00297 may override the descriptions here. Any difference is supposed to be a 00298 minor correction only.) 00299 */ 00300 struct isoburn_imgen_opts { 00301 00302 /* Options for image generation */ 00303 00304 int level; /**< ISO level to write at. */ 00305 00306 /** Which extensions to support. */ 00307 unsigned int rockridge :1; 00308 unsigned int joliet :1; 00309 unsigned int iso1999 :1; 00310 00311 /* ts A90121 */ 00312 unsigned int aaip:1; /* Write eventual AAIP info containing ACL and EA */ 00313 00314 /* relaxed constraints */ 00315 00316 /* 00317 * Relaxed constraints. Setting any of these to 1 break the specifications, 00318 * but it is supposed to work on most moderns systems. Use with caution. 00319 */ 00320 00321 /** 00322 * Omit the version number (";1") at the end of the ISO-9660 identifiers. 00323 * Version numbers are usually not used. 00324 */ 00325 unsigned int omit_version_numbers :1; 00326 00327 /** 00328 * Allow ISO-9660 directory hierarchy to be deeper than 8 levels. 00329 */ 00330 unsigned int allow_deep_paths :1; 00331 00332 /** 00333 * Allow path in the ISO-9660 tree to have more than 255 characters. 00334 */ 00335 unsigned int allow_longer_paths :1; 00336 00337 /** 00338 * Allow a single file or directory hierarchy to have up to 37 characters. 00339 * This is larger than the 31 characters allowed by ISO level 2, and the 00340 * extra space is taken from the version number, so this also forces 00341 * omit_version_numbers. 00342 */ 00343 unsigned int max_37_char_filenames :1; 00344 00345 /** 00346 * ISO-9660 forces filenames to have a ".", that separates file name from 00347 * extension. libisofs adds it if original filename doesn't has one. Set 00348 * this to 1 to prevent this behavior 00349 */ 00350 unsigned int no_force_dots :1; 00351 00352 /** 00353 * Allow lowercase characters in ISO-9660 filenames. By default, only 00354 * uppercase characters, numbers and a few other characters are allowed. 00355 */ 00356 unsigned int allow_lowercase :1; 00357 00358 /** 00359 * Allow all ASCII characters to be appear on an ISO-9660 filename. Note 00360 * that "/" and "\0" characters are never allowed, even in RR names. 00361 */ 00362 unsigned int allow_full_ascii :1; 00363 00364 /** 00365 * Allow paths in the Joliet tree to have more than 240 characters. 00366 */ 00367 unsigned int joliet_longer_paths :1; 00368 00369 /** 00370 * Store timestamps as GMT rather than in local time. 00371 */ 00372 unsigned int always_gmt :1; 00373 00374 /** 00375 * Write Rock Ridge info as of specification RRIP-1.10 rather than 00376 * RRIP-1.12: signature "RRIP_1991A" rather than "IEEE_1282", 00377 * field PX without file serial number 00378 */ 00379 unsigned int rrip_version_1_10 :1; 00380 00381 /** 00382 * Store as ECMA-119 Directory Record timestamp the mtime 00383 * of the source rather than the image creation time. 00384 */ 00385 unsigned int dir_rec_mtime :1; 00386 00387 /** 00388 * Write AAIP as extension according to SUSP 1.10 rather than SUSP 1.12. 00389 * I.e. without announcing it by an ER field and thus without the need 00390 * to preceed the RRIP fields by an ES and to preceed the AA field by ES. 00391 */ 00392 unsigned int aaip_susp_1_10 :1; 00393 00394 unsigned int sort_files:1; 00395 /**< If files should be sorted based on their weight. */ 00396 00397 /** 00398 * The following options set the default values for files and directory 00399 * permissions, gid and uid. All these take one of three values: 0, 1 or 2. 00400 * If 0, the corresponding attribute will be kept as set in the IsoNode. 00401 * Unless you have changed it, it corresponds to the value on disc, so it 00402 * is suitable for backup purposes. If set to 1, the corresponding attrib. 00403 * will be changed by a default suitable value. Finally, if you set it to 00404 * 2, the attrib. will be changed with the value specified in the options 00405 * below. Note that for mode attributes, only the permissions are set, the 00406 * file type remains unchanged. 00407 */ 00408 unsigned int replace_dir_mode :2; 00409 unsigned int replace_file_mode :2; 00410 unsigned int replace_uid :2; 00411 unsigned int replace_gid :2; 00412 00413 mode_t dir_mode; /** Mode to use on dirs when replace_dir_mode == 2. */ 00414 mode_t file_mode; /** Mode to use on files when replace_file_mode == 2. */ 00415 uid_t uid; /** uid to use when replace_uid == 2. */ 00416 gid_t gid; /** gid to use when replace_gid == 2. */ 00417 00418 char *output_charset; /**< NULL to use default charset */ 00419 00420 00421 /* Options for image transport */ 00422 00423 /** The number of bytes to be used for the fifo which decouples libisofs 00424 and libburn for better throughput and for reducing the risk of 00425 interrupting signals hitting the libburn thread which operates the 00426 MMC drive. 00427 The size will be rounded up to the next full 2048. 00428 Minimum is 64kiB, maximum is 1 GiB (but that is too much anyway). 00429 */ 00430 int fifo_size; 00431 00432 00433 /** Output value: Block address of session start as evaluated from media 00434 and other options by libisoburn and libburn. 00435 If <0 : Invalid 00436 If >=0: Valid block number. Block size is always 2 KiB. 00437 */ 00438 int effective_lba; 00439 00440 /** Output value: Block address of data section start as predicted by 00441 libisofs. 00442 If < 16: Invalid 00443 If >=16: Valid block number. Block size is always 2 KiB. 00444 */ 00445 int data_start_lba; 00446 }; 00447 00448 00449 /* Alignment for session starts on overwriteable media. 00450 (Increased from 16 to 32 blocks for aligning to BD-RE clusters.) 00451 */ 00452 #define Libisoburn_nwa_alignemenT 32 00453 00454 00455 /* Alignment for outer session scanning with -ROM drives. 00456 (E.g. my DVD-ROM drive shows any DVD type as 0x10 "DVD-ROM" with 00457 more or less false capacity and TOC.) 00458 */ 00459 #define Libisoburn_toc_scan_alignemenT 16 00460 00461 /* Maximum gap to be bridged during a outer TOC scan. Gaps appear between the 00462 end of a session and the start of the next session. 00463 The longest gap found so far was about 38100 after the first session of a 00464 DVD-R. 00465 */ 00466 #define Libisoburn_toc_scan_max_gaP 65536 00467 00468 00469 /* Creating a chain of image headers which form a TOC: 00470 00471 The header of the first session is written after the LBA 0 header. 00472 So it persists and can give the end of its session. By help of 00473 Libisoburn_nwa_alignemenT it should be possible to predict the start 00474 of the next session header. 00475 The LBA 0 header is written by isoburn_activate_session() already 00476 with the first session. So the media is mountable. 00477 A problem arises with DVD-RW in Intermediate State. They cannot be 00478 written by random access before they were written sequentially. 00479 In this case, no copy of the session 1 header is maintained and no TOC 00480 will be possible. Thus writing begins sequentially at LBA 0. 00481 */ 00482 #define Libisoburn_overwriteable_starT \ 00483 ((off_t) (Libisoburn_target_head_sizE/2048)) 00484 00485 00486 /* Wrappers for emulation of TOC on overwriteable media */ 00487 00488 struct isoburn_toc_track { 00489 /* Either track or toc_entry are supposed to be NULL */ 00490 struct burn_track *track; 00491 struct isoburn_toc_entry *toc_entry; 00492 }; 00493 00494 struct isoburn_toc_session { 00495 /* Either session or tracks and toc_entry are supposed to be NULL */ 00496 struct burn_session *session; 00497 struct isoburn_toc_track **track_pointers; 00498 int track_count; 00499 struct isoburn_toc_entry *toc_entry; 00500 }; 00501 00502 struct isoburn_toc_disc { 00503 /* Either disc or sessions and toc are supposed to be NULL */ 00504 struct burn_disc *disc; 00505 struct isoburn_toc_session *sessions; /* storage array */ 00506 struct isoburn_toc_session **session_pointers; /* storage array */ 00507 struct isoburn_toc_track *tracks; /* storage array */ 00508 struct isoburn_toc_track **track_pointers; /* storage array */ 00509 int session_count; 00510 int track_count; 00511 struct isoburn_toc_entry *toc; 00512 }; 00513 00514 #endif /* Isoburn_includeD */ 00515