Compile time check of libisoburn. Enforced minimum track size of 300 sectors.

This commit is contained in:
Thomas Schmitt 2008-02-02 18:13:03 +00:00
parent 9e1dccb40b
commit 0ce9be5c2d
2 changed files with 74 additions and 5 deletions

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.02.02.131903" #define Xorriso_timestamP "2008.02.02.181200"

View File

@ -71,6 +71,9 @@ int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
S_ISSOCK(iso_node_get_mode(node))) S_ISSOCK(iso_node_get_mode(node)))
#define Xorriso_min_track_sizE 300
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
@ -80,6 +83,49 @@ int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
char *handler_prefix= NULL; char *handler_prefix= NULL;
char *queue_sev, *print_sev, reason[1024]; char *queue_sev, *print_sev, reason[1024];
/* First an ugly compile time check for header version compatibility.
If everthing matches, then no C code is produced. In case of mismatch,
intentionally faulty C code will be inserted.
*/
/* The minimum requirement of xorriso towards the libisoburn header
at compile time is defined in xorriso/xorrisoburn.h
xorriso_libisoburn_req_major
xorriso_libisoburn_req_minor
xorriso_libisoburn_req_micro
It gets compared against the version macros in libburn/libburn.h :
isoburn_header_version_major
isoburn_header_version_minor
isoburn_header_version_micro
If the header is too old then the following code shall cause failure of
cdrskin compilation rather than to allow production of a program with
unpredictable bugs or memory corruption.
The compiler messages supposed to appear in this case are:
error: 'LIBISOBURN_MISCONFIGURATION' undeclared (first use in this function)
error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c' undeclared (first use in this function)
error: 'LIBISOBURN_MISCONFIGURATION_' undeclared (first use in this function)
*/
/* The indendation is an advise of man gcc to help old compilers ignoring */
#if xorriso_libisoburn_req_major > isoburn_header_version_major
#define Isoburn_libisoburn_dot_h_too_olD 1
#endif
#if xorriso_libisoburn_req_major == isoburn_header_version_major && xorriso_libisoburn_req_minor > isoburn_header_version_minor
#define Isoburn_libisoburn_dot_h_too_olD 1
#endif
#if xorriso_libisoburn_req_minor == isoburn_header_version_minor && xorriso_libisoburn_req_micro > isoburn_header_version_micro
#define Isoburn_libisoburn_dot_h_too_olD 1
#endif
#ifdef Isoburn_libisoburn_dot_h_too_olD
LIBISOBURN_MISCONFIGURATION = 0;
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c = 0;
LIBISOBURN_MISCONFIGURATION_ = 0;
#endif
/* End of ugly compile time test (scroll up for explanation) */
sprintf(xorriso->info_text, "Starting up libraries ...\n"); sprintf(xorriso->info_text, "Starting up libraries ...\n");
Xorriso_info(xorriso, 0); Xorriso_info(xorriso, 0);
@ -546,7 +592,7 @@ int Xorriso_make_write_options(
*/ */
int Xorriso_write_session(struct XorrisO *xorriso, int flag) int Xorriso_write_session(struct XorrisO *xorriso, int flag)
{ {
int ret, media_space; int ret, media_space, img_sectors;
struct isoburn_imgen_opts *sopts= NULL; struct isoburn_imgen_opts *sopts= NULL;
struct burn_drive_info *dinfo, *source_dinfo; struct burn_drive_info *dinfo, *source_dinfo;
struct burn_drive *drive, *source_drive; struct burn_drive *drive, *source_drive;
@ -635,19 +681,42 @@ int Xorriso_write_session(struct XorrisO *xorriso, int flag)
if(ret<=0) if(ret<=0)
goto ex; goto ex;
ret= burn_disc_get_sectors(disc); ret= img_sectors= burn_disc_get_sectors(disc);
if(flag&1) if(flag&1)
goto ex; goto ex;
media_space= burn_disc_available_space(drive, burn_options) / (off_t) 2048; media_space= burn_disc_available_space(drive, burn_options) / (off_t) 2048;
if(media_space < ret) { if(media_space < img_sectors || media_space < Xorriso_min_track_sizE) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Image size %ds exceeds free space on media %ds", sprintf(xorriso->info_text,"Image size %ds exceeds free space on media %ds",
ret, media_space); (img_sectors < Xorriso_min_track_sizE ? Xorriso_min_track_sizE
: img_sectors ),
media_space);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;} {ret= 0; goto ex;}
} }
if(img_sectors < Xorriso_min_track_sizE) {
sessions= burn_disc_get_sessions(disc, &num_sessions);
if(sessions==NULL || num_sessions < 1) {
no_track:;
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"Program error : no track in prepared disc");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
{ret= -1; goto ex;}
}
tracks= burn_session_get_tracks(sessions[0], &num_tracks);
if(tracks==NULL || num_tracks < 1)
goto no_track;
burn_track_define_data(tracks[0], 0,
(Xorriso_min_track_sizE - img_sectors) * 2048,
0, BURN_MODE1);
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text, "Expanded track to minimum size of %d sectors",
Xorriso_min_track_sizE);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
}
isoburn_disc_write(burn_options, disc); isoburn_disc_write(burn_options, disc);
burn_write_opts_free(burn_options); burn_write_opts_free(burn_options);