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 unsigned int preferjoliet:1; 00254 /*< When both Joliet and RR extensions are present, the RR 00255 * tree is used. If you prefer using Joliet, set this to 1. */ 00256 uid_t uid; /**< Default uid when no RR */ 00257 gid_t gid; /**< Default uid when no RR */ 00258 mode_t mode; /**< Default mode when no RR (only permissions) */ 00259 mode_t dirmode; /**< Default mode for directories 00260 when no RR (only permissions) */ 00261 00262 /** 00263 * Input charset for RR file names. NULL to use default locale charset. 00264 */ 00265 char *input_charset; 00266 00267 /* modified by the function isoburn_read_image */ 00268 unsigned int hasRR:1; /*< It will be set to 1 if RR extensions are present, 00269 to 0 if not. */ 00270 unsigned int hasJoliet:1; /*< It will be set to 1 if Joliet extensions are 00271 present, to 0 if not. */ 00272 00273 /** 00274 * It will be set to 1 if the image is an ISO 9660:1999, i.e. it has 00275 * a version 2 Enhanced Volume Descriptor. 00276 */ 00277 unsigned int hasIso1999:1; 00278 00279 /** It will be set to 1 if El-Torito boot record is present, to 0 if not.*/ 00280 unsigned int hasElTorito:1; 00281 00282 uint32_t size; /**< Will be filled with the size (in 2048 byte block) of 00283 * the image, as reported in the PVM. */ 00284 unsigned int pretend_blank:1; /* always create empty image */ 00285 }; 00286 00287 00288 /** 00289 * Options for image generation by libisofs and image transport to libburn. 00290 (Comments here may be outdated. API getter/setter function descriptions 00291 may override the descriptions here. Any difference is supposed to be a 00292 minor correction only.) 00293 */ 00294 struct isoburn_imgen_opts { 00295 00296 /* Options for image generation */ 00297 00298 int level; /**< ISO level to write at. */ 00299 00300 /** Which extensions to support. */ 00301 unsigned int rockridge :1; 00302 unsigned int joliet :1; 00303 unsigned int iso1999 :1; 00304 00305 /* relaxed constraints */ 00306 00307 /* 00308 * Relaxed constraints. Setting any of these to 1 break the specifications, 00309 * but it is supposed to work on most moderns systems. Use with caution. 00310 */ 00311 00312 /** 00313 * Omit the version number (";1") at the end of the ISO-9660 identifiers. 00314 * Version numbers are usually not used. 00315 */ 00316 unsigned int omit_version_numbers :1; 00317 00318 /** 00319 * Allow ISO-9660 directory hierarchy to be deeper than 8 levels. 00320 */ 00321 unsigned int allow_deep_paths :1; 00322 00323 /** 00324 * Allow path in the ISO-9660 tree to have more than 255 characters. 00325 */ 00326 unsigned int allow_longer_paths :1; 00327 00328 /** 00329 * Allow a single file or directory hierarchy to have up to 37 characters. 00330 * This is larger than the 31 characters allowed by ISO level 2, and the 00331 * extra space is taken from the version number, so this also forces 00332 * omit_version_numbers. 00333 */ 00334 unsigned int max_37_char_filenames :1; 00335 00336 /** 00337 * ISO-9660 forces filenames to have a ".", that separates file name from 00338 * extension. libisofs adds it if original filename doesn't has one. Set 00339 * this to 1 to prevent this behavior 00340 */ 00341 unsigned int no_force_dots :1; 00342 00343 /** 00344 * Allow lowercase characters in ISO-9660 filenames. By default, only 00345 * uppercase characters, numbers and a few other characters are allowed. 00346 */ 00347 unsigned int allow_lowercase :1; 00348 00349 /** 00350 * Allow all ASCII characters to be appear on an ISO-9660 filename. Note 00351 * that "/" and "\0" characters are never allowed, even in RR names. 00352 */ 00353 unsigned int allow_full_ascii :1; 00354 00355 /** 00356 * Allow paths in the Joliet tree to have more than 240 characters. 00357 */ 00358 unsigned int joliet_longer_paths :1; 00359 00360 /** 00361 * Store timestamps as GMT rather than in local time. 00362 */ 00363 unsigned int always_gmt :1; 00364 00365 /** 00366 * Write Rock Ridge info as of specification RRIP-1.10 rather than 00367 * RRIP-1.12: signature "RRIP_1991A" rather than "IEEE_1282", 00368 * field PX without file serial number 00369 */ 00370 unsigned int rrip_version_1_10 :1; 00371 00372 /** 00373 * Store as ECMA-119 Directory Record timestamp the mtime 00374 * of the source rather than the image creation time. 00375 */ 00376 unsigned int dir_rec_mtime :1; 00377 00378 unsigned int sort_files:1; 00379 /**< If files should be sorted based on their weight. */ 00380 00381 /** 00382 * The following options set the default values for files and directory 00383 * permissions, gid and uid. All these take one of three values: 0, 1 or 2. 00384 * If 0, the corresponding attribute will be kept as set in the IsoNode. 00385 * Unless you have changed it, it corresponds to the value on disc, so it 00386 * is suitable for backup purposes. If set to 1, the corresponding attrib. 00387 * will be changed by a default suitable value. Finally, if you set it to 00388 * 2, the attrib. will be changed with the value specified in the options 00389 * below. Note that for mode attributes, only the permissions are set, the 00390 * file type remains unchanged. 00391 */ 00392 unsigned int replace_dir_mode :2; 00393 unsigned int replace_file_mode :2; 00394 unsigned int replace_uid :2; 00395 unsigned int replace_gid :2; 00396 00397 mode_t dir_mode; /** Mode to use on dirs when replace_dir_mode == 2. */ 00398 mode_t file_mode; /** Mode to use on files when replace_file_mode == 2. */ 00399 uid_t uid; /** uid to use when replace_uid == 2. */ 00400 gid_t gid; /** gid to use when replace_gid == 2. */ 00401 00402 char *output_charset; /**< NULL to use default charset */ 00403 00404 00405 /* Options for image transport */ 00406 00407 /** The number of bytes to be used for the fifo which decouples libisofs 00408 and libburn for better throughput and for reducing the risk of 00409 interrupting signals hitting the libburn thread which operates the 00410 MMC drive. 00411 The size will be rounded up to the next full 2048. 00412 Minimum is 64kiB, maximum is 1 GiB (but that is too much anyway). 00413 */ 00414 int fifo_size; 00415 00416 00417 /** Output value: Block address of session start as evaluatedfrom media 00418 and other options by libisoburn and libburn. 00419 If <0 : Invalid 00420 If >=0: Valid block number. Block size is always 2 KiB. 00421 */ 00422 int effective_lba; 00423 }; 00424 00425 00426 /* Alignment for session starts on overwriteable media. 00427 (Increased from 16 to 32 blocks for aligning to BD-RE clusters.) 00428 */ 00429 #define Libisoburn_nwa_alignemenT 32 00430 00431 00432 /* Alignment for outer session scanning with -ROM drives. 00433 (E.g. my DVD-ROM drive shows any DVD type as 0x10 "DVD-ROM" with 00434 more or less false capacity and TOC.) 00435 */ 00436 #define Libisoburn_toc_scan_alignemenT 16 00437 00438 /* Maximum gap to be bridged during a outer TOC scan. Gaps appear between the 00439 end of a session and the start of the next session. 00440 The longest gap found so far was about 38100 after the first session of a 00441 DVD-R. 00442 */ 00443 #define Libisoburn_toc_scan_max_gaP 65536 00444 00445 00446 /* Creating a chain of image headers which form a TOC: 00447 00448 The header of the first session is written after the LBA 0 header. 00449 So it persists and can give the end of its session. By help of 00450 Libisoburn_nwa_alignemenT it should be possible to predict the start 00451 of the next session header. 00452 The LBA 0 header is written by isoburn_activate_session() already 00453 with the first session. So the media is mountable. 00454 A problem arises with DVD-RW in Intermediate State. They cannot be 00455 written by random access before they were written sequentially. 00456 In this case, no copy of the session 1 header is maintained and no TOC 00457 will be possible. Thus writing begins sequentially at LBA 0. 00458 */ 00459 #define Libisoburn_overwriteable_starT \ 00460 ((off_t) (Libisoburn_target_head_sizE/2048)) 00461 00462 00463 /* Wrappers for emulation of TOC on overwriteable media */ 00464 00465 struct isoburn_toc_track { 00466 /* Either track or toc_entry are supposed to be NULL */ 00467 struct burn_track *track; 00468 struct isoburn_toc_entry *toc_entry; 00469 }; 00470 00471 struct isoburn_toc_session { 00472 /* Either session or tracks and toc_entry are supposed to be NULL */ 00473 struct burn_session *session; 00474 struct isoburn_toc_track **track_pointers; 00475 int track_count; 00476 struct isoburn_toc_entry *toc_entry; 00477 }; 00478 00479 struct isoburn_toc_disc { 00480 /* Either disc or sessions and toc are supposed to be NULL */ 00481 struct burn_disc *disc; 00482 struct isoburn_toc_session *sessions; /* storage array */ 00483 struct isoburn_toc_session **session_pointers; /* storage array */ 00484 struct isoburn_toc_track *tracks; /* storage array */ 00485 struct isoburn_toc_track **track_pointers; /* storage array */ 00486 int session_count; 00487 int track_count; 00488 struct isoburn_toc_entry *toc; 00489 }; 00490 00491 #endif /* Isoburn_includeD */ 00492
1.5.6