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