2008-01-10 15:20:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
cc -g -c isofs_wrap.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
libisofs related functions of libisoburn.
|
|
|
|
|
2011-03-13 13:15:41 +00:00
|
|
|
Copyright 2007 - 2011 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
|
2008-05-07 07:14:10 +00:00
|
|
|
Thomas Schmitt <scdbackup@gmx.net>
|
2010-02-14 15:09:05 +00:00
|
|
|
Provided under GPL version 2 or later.
|
2008-01-10 15:20:57 +00:00
|
|
|
*/
|
|
|
|
|
2010-05-16 09:26:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-05-09 20:54:58 +00:00
|
|
|
#include <stdio.h>
|
2008-01-20 10:30:43 +00:00
|
|
|
|
|
|
|
#ifndef Xorriso_standalonE
|
2008-01-10 15:20:57 +00:00
|
|
|
|
|
|
|
#include <libburn/libburn.h>
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
#include <libisofs/libisofs.h>
|
2008-01-10 15:20:57 +00:00
|
|
|
|
2008-01-20 10:30:43 +00:00
|
|
|
#else /* ! Xorriso_standalonE */
|
|
|
|
|
|
|
|
#include "../libisofs/libisofs.h"
|
|
|
|
#include "../libburn/libburn.h"
|
|
|
|
|
|
|
|
#endif /* Xorriso_standalonE */
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
#include "libisoburn.h"
|
2010-09-10 17:10:03 +00:00
|
|
|
#include "isoburn.h"
|
2008-01-10 15:20:57 +00:00
|
|
|
|
|
|
|
#define BP(a,b) [(b) - (a) + 1]
|
|
|
|
|
|
|
|
struct ecma119_pri_vol_desc
|
|
|
|
{
|
|
|
|
uint8_t vol_desc_type BP(1, 1);
|
|
|
|
uint8_t std_identifier BP(2, 6);
|
|
|
|
uint8_t vol_desc_version BP(7, 7);
|
|
|
|
uint8_t unused1 BP(8, 8);
|
|
|
|
uint8_t system_id BP(9, 40);
|
|
|
|
uint8_t volume_id BP(41, 72);
|
|
|
|
uint8_t unused2 BP(73, 80);
|
|
|
|
uint8_t vol_space_size BP(81, 88);
|
|
|
|
uint8_t unused3 BP(89, 120);
|
|
|
|
uint8_t vol_set_size BP(121, 124);
|
|
|
|
uint8_t vol_seq_number BP(125, 128);
|
|
|
|
uint8_t block_size BP(129, 132);
|
|
|
|
uint8_t path_table_size BP(133, 140);
|
|
|
|
uint8_t l_path_table_pos BP(141, 144);
|
|
|
|
uint8_t opt_l_path_table_pos BP(145, 148);
|
|
|
|
uint8_t m_path_table_pos BP(149, 152);
|
|
|
|
uint8_t opt_m_path_table_pos BP(153, 156);
|
|
|
|
uint8_t root_dir_record BP(157, 190);
|
|
|
|
uint8_t vol_set_id BP(191, 318);
|
|
|
|
uint8_t publisher_id BP(319, 446);
|
|
|
|
uint8_t data_prep_id BP(447, 574);
|
|
|
|
uint8_t application_id BP(575, 702);
|
|
|
|
uint8_t copyright_file_id BP(703, 739);
|
|
|
|
uint8_t abstract_file_id BP(740, 776);
|
|
|
|
uint8_t bibliographic_file_id BP(777, 813);
|
|
|
|
uint8_t vol_creation_time BP(814, 830);
|
|
|
|
uint8_t vol_modification_time BP(831, 847);
|
|
|
|
uint8_t vol_expiration_time BP(848, 864);
|
|
|
|
uint8_t vol_effective_time BP(865, 881);
|
|
|
|
uint8_t file_structure_version BP(882, 882);
|
|
|
|
uint8_t reserved1 BP(883, 883);
|
|
|
|
uint8_t app_use BP(884, 1395);
|
|
|
|
uint8_t reserved2 BP(1396, 2048);
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
uint32_t iso_read_lsb(const uint8_t *buf, int bytes)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
for (i=0; i<bytes; i++) {
|
|
|
|
ret += ((uint32_t) buf[i]) << (i*8);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* API function. See libisoburn.h
|
|
|
|
*/
|
|
|
|
IsoImage *isoburn_get_attached_image(struct burn_drive *d)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct isoburn *o= NULL;
|
|
|
|
ret = isoburn_find_emulator(&o, d, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (o == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
iso_image_ref(o->image);
|
|
|
|
return o->image;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-14 10:31:00 +00:00
|
|
|
/* API */
|
|
|
|
int isoburn_get_attached_start_lba(struct burn_drive *d)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct isoburn *o= NULL;
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, d, 0);
|
|
|
|
if (ret < 0 || o == NULL)
|
|
|
|
return -1;
|
|
|
|
if(o->image == NULL)
|
|
|
|
return -1;
|
|
|
|
return o->image_start_lba;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 21:45:31 +00:00
|
|
|
static void isoburn_idle_free_function(void *ignored)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-27 15:02:25 +00:00
|
|
|
int isoburn_root_defaults(IsoImage *image, int flag)
|
|
|
|
{
|
|
|
|
IsoNode *root_node;
|
|
|
|
mode_t root_mode= 0755;
|
|
|
|
|
|
|
|
root_node= (IsoNode *) iso_image_get_root(image);
|
|
|
|
iso_node_set_permissions(root_node, root_mode);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
/* API function. See libisoburn.h
|
|
|
|
*/
|
|
|
|
int isoburn_read_image(struct burn_drive *d,
|
|
|
|
struct isoburn_read_opts *read_opts,
|
|
|
|
IsoImage **image)
|
|
|
|
{
|
2008-05-09 20:54:58 +00:00
|
|
|
int ret, int_num, dummy;
|
2008-01-28 17:20:10 +00:00
|
|
|
IsoReadOpts *ropts= NULL;
|
2008-02-03 15:58:00 +00:00
|
|
|
IsoReadImageFeatures *features= NULL;
|
2008-01-28 17:20:10 +00:00
|
|
|
uint32_t ms_block;
|
2011-05-09 15:49:47 +00:00
|
|
|
char *msg= NULL;
|
2008-01-10 15:20:57 +00:00
|
|
|
enum burn_disc_status status= BURN_DISC_BLANK;
|
|
|
|
IsoDataSource *ds= NULL;
|
|
|
|
struct isoburn *o= NULL;
|
2015-11-09 13:31:59 +00:00
|
|
|
IsoImage *new_image= NULL;
|
2008-01-10 15:20:57 +00:00
|
|
|
|
2011-05-09 15:49:47 +00:00
|
|
|
msg= calloc(1, 160);
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
if(d != NULL) {
|
|
|
|
ret = isoburn_find_emulator(&o, d, 0);
|
2008-02-04 18:47:17 +00:00
|
|
|
if (ret < 0 || o == NULL)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 0; goto ex;}
|
2008-01-10 15:20:57 +00:00
|
|
|
status = isoburn_disc_get_status(d);
|
2012-02-14 10:31:00 +00:00
|
|
|
o->image_start_lba= -1;
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
2008-06-18 16:14:44 +00:00
|
|
|
if(read_opts==NULL) {
|
|
|
|
isoburn_msgs_submit(o, 0x00060000,
|
|
|
|
"Program error: isoburn_read_image: read_opts==NULL",
|
|
|
|
0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= -1; goto ex;}
|
2008-06-18 16:14:44 +00:00
|
|
|
}
|
2008-01-10 15:20:57 +00:00
|
|
|
if (d == NULL || status == BURN_DISC_BLANK || read_opts->pretend_blank) {
|
2008-05-09 20:54:58 +00:00
|
|
|
create_blank_image:;
|
2008-01-10 15:20:57 +00:00
|
|
|
/*
|
|
|
|
* Blank disc, we create a new image without files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (d == NULL) {
|
2008-01-13 20:24:24 +00:00
|
|
|
/* New empty image without relation to a drive */
|
2008-02-04 18:47:17 +00:00
|
|
|
if (image==NULL) {
|
2008-06-18 16:14:44 +00:00
|
|
|
isoburn_msgs_submit(o, 0x00060000,
|
|
|
|
"Program error: isoburn_read_image: image==NULL",
|
|
|
|
0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= -1; goto ex;}
|
2008-02-04 18:47:17 +00:00
|
|
|
}
|
2008-01-10 15:20:57 +00:00
|
|
|
/* create a new image */
|
2008-01-13 20:24:24 +00:00
|
|
|
ret = iso_image_new("ISOIMAGE", image);
|
2008-02-03 13:16:18 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
goto ex;
|
2008-02-03 13:16:18 +00:00
|
|
|
}
|
2011-02-24 19:18:58 +00:00
|
|
|
iso_image_set_ignore_aclea(*image,
|
|
|
|
(!!(read_opts->noacl)) | ((!!read_opts->noea) << 1) );
|
2015-11-09 13:31:59 +00:00
|
|
|
new_image= *image;
|
2008-01-10 15:20:57 +00:00
|
|
|
} else {
|
2008-01-13 20:24:24 +00:00
|
|
|
/* Blank new image for the drive */
|
|
|
|
iso_image_unref(o->image);
|
|
|
|
ret = iso_image_new("ISOIMAGE", &o->image);
|
2008-02-03 13:16:18 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
isoburn_report_iso_error(ret, "Cannot create image", 0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
goto ex;
|
2008-02-03 13:16:18 +00:00
|
|
|
}
|
2011-02-24 19:18:58 +00:00
|
|
|
if (image != NULL) {
|
2008-01-10 15:20:57 +00:00
|
|
|
*image = o->image;
|
|
|
|
iso_image_ref(*image); /*protects object from premature free*/
|
|
|
|
}
|
2011-02-24 19:18:58 +00:00
|
|
|
iso_image_set_ignore_aclea(o->image,
|
2009-01-21 20:39:00 +00:00
|
|
|
(!!(read_opts->noacl)) | ((!!read_opts->noea) << 1) );
|
2012-02-27 15:02:25 +00:00
|
|
|
|
2012-03-21 19:30:38 +00:00
|
|
|
ret= isoburn_root_defaults(o->image, 0);
|
2012-02-27 15:02:25 +00:00
|
|
|
if(ret <= 0)
|
|
|
|
goto ex;
|
2015-11-09 13:31:59 +00:00
|
|
|
new_image= o->image;
|
2011-02-24 19:18:58 +00:00
|
|
|
}
|
2015-11-09 13:31:59 +00:00
|
|
|
ret= iso_image_set_truncate_mode(new_image, read_opts->truncate_mode,
|
2015-09-17 12:05:40 +00:00
|
|
|
read_opts->truncate_length);
|
|
|
|
if(ret < 0)
|
|
|
|
goto ex;
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 1; goto ex;}
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status != BURN_DISC_APPENDABLE && status != BURN_DISC_FULL) {
|
2008-06-18 16:14:44 +00:00
|
|
|
isoburn_msgs_submit(o, 0x00060000,
|
2008-02-04 18:47:17 +00:00
|
|
|
"Program error: isoburn_read_image: incorrect disc status",
|
2008-06-18 16:14:44 +00:00
|
|
|
0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= -4; goto ex;}
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 17:20:10 +00:00
|
|
|
ret = isoburn_disc_get_msc1(d, &int_num);
|
2008-02-04 18:47:17 +00:00
|
|
|
if (ret <= 0)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= -2; goto ex;}
|
2008-01-28 17:20:10 +00:00
|
|
|
ms_block= int_num;
|
2012-02-14 10:31:00 +00:00
|
|
|
if (o != NULL)
|
|
|
|
o->image_start_lba= ms_block;
|
2008-05-09 20:54:58 +00:00
|
|
|
ret = isoburn_read_iso_head(d, int_num, &dummy, NULL, 0);
|
|
|
|
if (ret <= 0) {
|
|
|
|
sprintf(msg, "No ISO 9660 image at LBA %d. Creating blank image.", int_num);
|
2008-06-18 16:14:44 +00:00
|
|
|
isoburn_msgs_submit(o, 0x00060000, msg, 0, "WARNING", 0);
|
2008-05-09 20:54:58 +00:00
|
|
|
goto create_blank_image;
|
|
|
|
}
|
2008-01-10 15:20:57 +00:00
|
|
|
|
2010-11-30 09:39:44 +00:00
|
|
|
if(read_opts->displacement != 0 && abs(read_opts->displacement_sign) == 1) {
|
|
|
|
/* Apply reverse displacement to session start */
|
|
|
|
if(read_opts->displacement_sign == -1) {
|
|
|
|
if(ms_block+ read_opts->displacement < ms_block) {
|
|
|
|
displacement_rollover:;
|
2010-12-04 17:43:30 +00:00
|
|
|
sprintf(msg, "Displacement offset leads outside 32 bit range.");
|
2010-11-30 09:39:44 +00:00
|
|
|
isoburn_msgs_submit(o, 0x00060000, msg, 0, "FAILURE", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 0; goto ex;}
|
2010-11-30 09:39:44 +00:00
|
|
|
}
|
|
|
|
ms_block+= read_opts->displacement;
|
|
|
|
} else {
|
|
|
|
if(ms_block < read_opts->displacement)
|
|
|
|
goto displacement_rollover;
|
|
|
|
ms_block-= read_opts->displacement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
/* create the data source */
|
2008-01-28 17:20:10 +00:00
|
|
|
ret = iso_read_opts_new(&ropts, 0);
|
2008-02-03 13:16:18 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
isoburn_report_iso_error(ret, "Cannot create write opts", 0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
goto ex;
|
2008-02-03 13:16:18 +00:00
|
|
|
}
|
2010-11-30 09:39:44 +00:00
|
|
|
|
2008-01-28 17:20:10 +00:00
|
|
|
/* Important: do not return until iso_read_opts_free() */
|
2010-11-30 09:39:44 +00:00
|
|
|
|
2008-01-28 17:20:10 +00:00
|
|
|
iso_read_opts_set_start_block(ropts, ms_block);
|
|
|
|
iso_read_opts_set_no_rockridge(ropts, read_opts->norock);
|
2009-01-22 13:01:13 +00:00
|
|
|
iso_read_opts_set_no_aaip(ropts, read_opts->noaaip);
|
2011-03-09 07:13:12 +00:00
|
|
|
if(read_opts->nomd5 == 2)
|
|
|
|
int_num= 2;
|
|
|
|
else if(read_opts->nomd5 == 1)
|
|
|
|
int_num= 1;
|
|
|
|
else
|
|
|
|
int_num= 0;
|
|
|
|
iso_read_opts_set_no_md5(ropts, int_num);
|
2015-08-17 20:01:30 +00:00
|
|
|
if(read_opts->do_ecma119_map)
|
|
|
|
iso_read_opts_set_ecma119_map(ropts, read_opts->map_mode);
|
2009-05-09 20:12:39 +00:00
|
|
|
iso_read_opts_set_new_inos(ropts, read_opts->noino);
|
|
|
|
|
2008-01-28 17:20:10 +00:00
|
|
|
iso_read_opts_set_no_joliet(ropts, read_opts->nojoliet);
|
|
|
|
iso_read_opts_set_no_iso1999(ropts, read_opts->noiso1999);
|
|
|
|
iso_read_opts_set_preferjoliet(ropts, read_opts->preferjoliet);
|
2008-01-31 15:22:23 +00:00
|
|
|
iso_read_opts_set_default_permissions(ropts,
|
|
|
|
read_opts->mode, read_opts->dirmode);
|
2008-01-28 17:20:10 +00:00
|
|
|
iso_read_opts_set_default_uid(ropts, read_opts->uid);
|
|
|
|
iso_read_opts_set_default_gid(ropts, read_opts->gid);
|
|
|
|
iso_read_opts_set_input_charset(ropts, read_opts->input_charset);
|
2009-03-20 19:29:04 +00:00
|
|
|
iso_read_opts_auto_input_charset(ropts, read_opts->auto_input_charset);
|
2010-04-16 19:54:54 +00:00
|
|
|
iso_read_opts_load_system_area(ropts, 1);
|
2015-04-23 13:51:44 +00:00
|
|
|
iso_read_opts_keep_import_src(ropts, 1);
|
2015-09-17 12:05:40 +00:00
|
|
|
ret= iso_image_set_truncate_mode(o->image, read_opts->truncate_mode,
|
|
|
|
read_opts->truncate_length);
|
|
|
|
if(ret < 0)
|
|
|
|
goto ex;
|
2008-05-01 12:43:39 +00:00
|
|
|
|
2010-11-30 09:39:44 +00:00
|
|
|
ds = isoburn_data_source_new(d, read_opts->displacement,
|
2012-03-11 16:20:30 +00:00
|
|
|
read_opts->displacement_sign,
|
|
|
|
read_opts->cache_tiles, read_opts->cache_tile_blocks);
|
2010-11-30 09:39:44 +00:00
|
|
|
if (ds == NULL) {
|
|
|
|
isoburn_report_iso_error(ret, "Cannot create IsoDataSource object", 0,
|
|
|
|
"FATAL", 0);
|
2012-03-11 16:20:30 +00:00
|
|
|
ret= -1; goto ex;
|
2010-11-30 09:39:44 +00:00
|
|
|
}
|
2008-07-05 13:25:06 +00:00
|
|
|
if(o->iso_data_source!=NULL)
|
|
|
|
iso_data_source_unref(o->iso_data_source);
|
|
|
|
o->iso_data_source= ds;
|
2008-02-06 21:45:31 +00:00
|
|
|
iso_image_attach_data(o->image, o->read_pacifier_handle,
|
|
|
|
isoburn_idle_free_function);
|
|
|
|
if(o->read_pacifier_handle==NULL)
|
|
|
|
iso_tree_set_report_callback(o->image, NULL);
|
|
|
|
else
|
|
|
|
iso_tree_set_report_callback(o->image, o->read_pacifier);
|
2015-09-17 12:05:40 +00:00
|
|
|
|
2008-01-28 17:20:10 +00:00
|
|
|
ret = iso_image_import(o->image, ds, ropts, &features);
|
2008-02-06 21:45:31 +00:00
|
|
|
iso_tree_set_report_callback(o->image, NULL);
|
2008-01-28 17:20:10 +00:00
|
|
|
iso_read_opts_free(ropts);
|
2012-03-11 16:20:30 +00:00
|
|
|
ropts= NULL;
|
2008-07-05 13:25:06 +00:00
|
|
|
|
2008-02-03 13:16:18 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
isoburn_report_iso_error(ret, "Cannot import image", 0, "FAILURE", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
goto ex;
|
2008-02-03 13:16:18 +00:00
|
|
|
}
|
2008-01-28 17:20:10 +00:00
|
|
|
/* Important: do not return until free(features) */
|
2008-02-03 13:16:18 +00:00
|
|
|
if (image!=NULL) {
|
2008-01-10 15:20:57 +00:00
|
|
|
*image = o->image;
|
|
|
|
iso_image_ref(*image); /*protects object from premature free*/
|
|
|
|
}
|
2008-02-03 15:58:00 +00:00
|
|
|
read_opts->hasRR = iso_read_image_features_has_rockridge(features);
|
|
|
|
read_opts->hasJoliet = iso_read_image_features_has_joliet(features);
|
|
|
|
read_opts->hasIso1999 = iso_read_image_features_has_iso1999(features);
|
|
|
|
read_opts->hasElTorito = iso_read_image_features_has_eltorito(features);
|
|
|
|
read_opts->size = iso_read_image_features_get_size(features);
|
2011-05-09 15:49:47 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(msg != NULL)
|
|
|
|
free(msg);
|
2012-03-11 16:20:30 +00:00
|
|
|
if(ropts != NULL)
|
|
|
|
iso_read_opts_free(ropts);
|
2012-04-19 07:31:18 +00:00
|
|
|
if(features != NULL)
|
|
|
|
iso_read_image_features_destroy(features);
|
2011-05-09 15:49:47 +00:00
|
|
|
return(ret);
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* API function. See libisoburn.h
|
|
|
|
*/
|
|
|
|
int isoburn_attach_image(struct burn_drive *d, IsoImage *image)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct isoburn *o;
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, d, 0);
|
2008-02-04 18:47:17 +00:00
|
|
|
if (ret < 0 || o == NULL)
|
2008-01-10 15:20:57 +00:00
|
|
|
return 0;
|
2008-06-18 16:14:44 +00:00
|
|
|
if (image == NULL) {
|
|
|
|
isoburn_msgs_submit(o, 0x00060000,
|
|
|
|
"Program error: isoburn_attach_image: image==NULL",
|
|
|
|
0, "FATAL", 0);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-01-10 15:20:57 +00:00
|
|
|
if(o->image != NULL)
|
|
|
|
iso_image_unref(o->image);
|
|
|
|
o->image = image;
|
2012-02-14 10:31:00 +00:00
|
|
|
o->image_start_lba = -1;
|
2008-01-10 15:20:57 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-14 10:31:00 +00:00
|
|
|
/* API */
|
|
|
|
int isoburn_attach_start_lba(struct burn_drive *d, int lba, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct isoburn *o;
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, d, 0);
|
|
|
|
if(ret < 0)
|
|
|
|
return ret;
|
|
|
|
if(o == NULL)
|
|
|
|
return 0;
|
|
|
|
if(o->image == NULL)
|
|
|
|
return 0;
|
|
|
|
o->image_start_lba = lba;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
/* API function. See libisoburn.h
|
|
|
|
*/
|
|
|
|
int isoburn_activate_session(struct burn_drive *drive)
|
|
|
|
{
|
2014-04-13 12:05:58 +00:00
|
|
|
int ret, do_sync = 1;
|
2008-01-10 15:20:57 +00:00
|
|
|
struct isoburn *o;
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, drive, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (o->emulation_mode != 1)
|
|
|
|
return 1; /* don't need to activate session */
|
2008-07-05 13:25:06 +00:00
|
|
|
if (o->fabricated_msc2 >= 0)
|
|
|
|
return 1; /* blind growing: do not alter anything outside the session */
|
2008-01-10 15:20:57 +00:00
|
|
|
|
2008-05-06 14:45:49 +00:00
|
|
|
if (!(o->fabricated_disc_status == BURN_DISC_APPENDABLE ||
|
|
|
|
(o->fabricated_disc_status == BURN_DISC_BLANK &&
|
|
|
|
o->zero_nwa > 0)))
|
2008-01-10 15:20:57 +00:00
|
|
|
return 1;
|
2014-04-13 12:05:58 +00:00
|
|
|
ret = burn_drive_get_drive_role(drive);
|
|
|
|
if (ret != 1)
|
|
|
|
do_sync = !! o->do_fsync;
|
|
|
|
|
2008-05-13 13:52:33 +00:00
|
|
|
ret = burn_random_access_write(drive, (off_t) 0, (char*)o->target_iso_head,
|
2014-04-13 12:05:58 +00:00
|
|
|
o->target_iso_head_size, do_sync);
|
2008-01-10 15:20:57 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 12:50:36 +00:00
|
|
|
/** API @since 0.6.2
|
2010-09-10 17:10:03 +00:00
|
|
|
*/
|
|
|
|
int isoburn_get_img_partition_offset(struct burn_drive *drive,
|
|
|
|
uint32_t *block_offset_2k)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct isoburn *o;
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, drive, 0);
|
|
|
|
if(ret < 0 || o == NULL)
|
|
|
|
return -1;
|
|
|
|
*block_offset_2k= o->loaded_partition_offset;
|
|
|
|
if(o->loaded_partition_offset == 0)
|
|
|
|
return(0);
|
|
|
|
if(o->target_iso_head_size == (off_t) Libisoburn_target_head_sizE
|
|
|
|
+ (off_t) 2048 * (off_t) o->loaded_partition_offset)
|
|
|
|
return(1);
|
|
|
|
return(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 12:50:36 +00:00
|
|
|
/* Check for MBR signature and a first partition that starts at a 2k block
|
2010-09-10 17:10:03 +00:00
|
|
|
and ends where the image ends.
|
|
|
|
If not too large or too small, accept its start as partition offset.
|
|
|
|
*/
|
|
|
|
static int isoburn_inspect_partition(struct isoburn *o, uint32_t img_size,
|
|
|
|
int flag)
|
|
|
|
{
|
2011-05-09 15:49:47 +00:00
|
|
|
uint8_t *mbr, *part, *buf= NULL;
|
2010-09-10 17:10:03 +00:00
|
|
|
uint32_t offst, numsec;
|
|
|
|
struct ecma119_pri_vol_desc *pvm;
|
|
|
|
off_t data_count;
|
|
|
|
int ret;
|
2011-05-09 15:49:47 +00:00
|
|
|
char *msg= NULL;
|
2010-09-10 17:10:03 +00:00
|
|
|
static int max_offst= 512 - 32;
|
|
|
|
|
2011-05-09 15:49:47 +00:00
|
|
|
buf= (uint8_t *) calloc(1, 2048);
|
|
|
|
msg= calloc(1, 160);
|
|
|
|
if(buf == NULL || msg == NULL)
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
|
2010-09-10 17:10:03 +00:00
|
|
|
mbr= o->target_iso_head;
|
|
|
|
part= mbr + 446;
|
|
|
|
if(mbr[510] != 0x55 || mbr[511] != 0xAA)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* not an MBR */
|
2010-09-10 17:10:03 +00:00
|
|
|
|
|
|
|
/* Does the first partition entry look credible ? */
|
|
|
|
if(part[0] != 0x80 && part[0] != 0x00)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* Invalid partition status */
|
2010-09-10 17:10:03 +00:00
|
|
|
if(part[1] == 0 && part[2] == 0 && part[3] == 0)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* Zero C/H/S start address */
|
2010-09-10 17:10:03 +00:00
|
|
|
|
|
|
|
/* Does it match the normal ISO image ? */
|
|
|
|
offst= iso_read_lsb(part + 8, 4);
|
|
|
|
numsec= iso_read_lsb(part + 12, 4);
|
|
|
|
if(offst < 64)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* Zero or unusably small partition start */
|
2010-09-10 17:10:03 +00:00
|
|
|
if((offst % 4) || (numsec % 4))
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* Not aligned to 2k */
|
2010-09-10 17:10:03 +00:00
|
|
|
if(numsec < 72)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* No room for volume descriptors */
|
2010-09-10 17:10:03 +00:00
|
|
|
offst/= 4;
|
|
|
|
numsec/= 4;
|
|
|
|
if(offst + numsec != img_size)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* Partition end does not match image end */
|
2010-09-10 17:10:03 +00:00
|
|
|
|
|
|
|
/* Is there a PVD at the partition start ? */
|
|
|
|
ret = burn_read_data(o->drive, (off_t) (offst + 16) * (off_t) 2048,
|
2014-09-23 06:47:05 +00:00
|
|
|
(char*) buf, 2048, &data_count, 32);
|
2010-09-10 17:10:03 +00:00
|
|
|
if(ret <= 0)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;}
|
2010-09-10 17:10:03 +00:00
|
|
|
pvm = (struct ecma119_pri_vol_desc *) buf;
|
|
|
|
if (strncmp((char*) pvm->std_identifier, "CD001", 5) != 0)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* not a PVD */
|
2010-09-10 17:10:03 +00:00
|
|
|
if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
|
|
|
|
|| pvm->file_structure_version[0] != 1 )
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* failed sanity check */
|
2010-09-10 17:10:03 +00:00
|
|
|
|
|
|
|
if(iso_read_lsb(pvm->vol_space_size, 4) + offst != img_size)
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 2; goto ex;} /* Image ends do not match */
|
2010-09-10 17:10:03 +00:00
|
|
|
|
|
|
|
/* Now it is credible. Not yet clear is whether it is acceptable. */
|
|
|
|
o->loaded_partition_offset= offst;
|
|
|
|
|
|
|
|
/* If the partition start is too large: Report but do not accept. */
|
2011-05-09 18:14:29 +00:00
|
|
|
if(offst > (uint32_t) max_offst) {/* Not more than 1 MB of .target_iso_head */
|
2010-09-10 17:10:03 +00:00
|
|
|
sprintf(msg,
|
|
|
|
"Detected partition offset of %.f blocks. Maximum for load buffer is %d",
|
|
|
|
(double) offst, max_offst);
|
|
|
|
isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "WARNING", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 3; goto ex;}
|
2010-09-10 17:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Accept partition start and adjust buffer size */
|
|
|
|
ret= isoburn_adjust_target_iso_head(o, offst, 0);
|
|
|
|
if(ret <= 0)
|
2011-05-09 15:49:47 +00:00
|
|
|
goto ex;
|
|
|
|
|
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(buf != NULL)
|
|
|
|
free(buf);
|
|
|
|
if(msg != NULL)
|
|
|
|
free(msg);
|
|
|
|
return(ret);
|
2010-09-10 17:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
/** Initialize the emulation of multi-session on random access media.
|
|
|
|
The need for emulation is confirmed already.
|
|
|
|
@param o A freshly created isoburn object. isoburn_create_data_source() was
|
|
|
|
already called, nevertheless.
|
2011-03-21 09:31:51 +00:00
|
|
|
@param flag bit0= read-only
|
2008-01-10 15:20:57 +00:00
|
|
|
@return <=0 error , 1 = success
|
|
|
|
*/
|
|
|
|
int isoburn_start_emulation(struct isoburn *o, int flag)
|
|
|
|
{
|
2011-03-21 09:31:51 +00:00
|
|
|
int ret, i, capacity = -1, role, dummy;
|
2009-10-07 07:25:40 +00:00
|
|
|
off_t data_count, to_read;
|
2008-01-10 15:20:57 +00:00
|
|
|
struct burn_drive *drive;
|
|
|
|
struct ecma119_pri_vol_desc *pvm;
|
2011-03-21 09:31:51 +00:00
|
|
|
enum burn_disc_status s;
|
2011-05-09 15:49:47 +00:00
|
|
|
char *path= NULL, *msg= NULL;
|
|
|
|
|
|
|
|
path= calloc(1, BURN_DRIVE_ADR_LEN);
|
|
|
|
msg= calloc(1, 2 * BURN_DRIVE_ADR_LEN);
|
|
|
|
if(path == NULL || msg == NULL)
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
|
2008-02-04 18:47:17 +00:00
|
|
|
if(o==NULL) {
|
2008-06-18 16:14:44 +00:00
|
|
|
isoburn_msgs_submit(NULL, 0x00060000,
|
|
|
|
"Program error: isoburn_start_emulation: o==NULL",
|
|
|
|
0, "FATAL", 0);
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= -1; goto ex;}
|
2008-02-04 18:47:17 +00:00
|
|
|
}
|
2008-01-10 15:20:57 +00:00
|
|
|
|
|
|
|
drive= o->drive;
|
|
|
|
|
2011-03-21 09:31:51 +00:00
|
|
|
if(flag & 1)
|
|
|
|
o->fabricated_disc_status= BURN_DISC_FULL;
|
|
|
|
|
2009-10-07 07:25:40 +00:00
|
|
|
/* We can assume 0 as start block for image.
|
|
|
|
The data there point to the most recent session.
|
|
|
|
*/
|
2010-01-01 12:56:12 +00:00
|
|
|
role = burn_drive_get_drive_role(drive);
|
2009-10-05 16:55:36 +00:00
|
|
|
ret = burn_get_read_capacity(drive, &capacity, 0);
|
2010-01-11 11:31:36 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
capacity = -1;
|
2011-11-02 14:09:45 +00:00
|
|
|
if (role == 5) { /* random access write-only medium */
|
2011-03-21 09:31:51 +00:00
|
|
|
s = burn_disc_get_status(drive);
|
|
|
|
o->fabricated_disc_status= s;
|
|
|
|
burn_disc_track_lba_nwa(drive, NULL, 0, &dummy, &(o->nwa));
|
2011-07-06 19:01:55 +00:00
|
|
|
if(o->nwa < o->zero_nwa)
|
|
|
|
o->zero_nwa= 0;
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 1; goto ex;}
|
2011-03-21 09:31:51 +00:00
|
|
|
} else if (capacity > 0 || role == 2 || role == 4) {
|
2010-01-01 12:56:12 +00:00
|
|
|
/* Might be a block device on a system where libburn cannot determine its
|
|
|
|
size. Try to read anyway. */
|
2010-09-10 17:10:03 +00:00
|
|
|
to_read = o->target_iso_head_size;
|
|
|
|
memset(o->target_iso_head, 0, to_read);
|
2010-01-01 12:56:12 +00:00
|
|
|
if(capacity > 0 && (off_t) capacity * (off_t) 2048 < to_read)
|
2009-10-07 07:25:40 +00:00
|
|
|
to_read = (off_t) capacity * (off_t) 2048;
|
2009-10-05 16:55:36 +00:00
|
|
|
ret = burn_read_data(drive, (off_t) 0, (char*)o->target_iso_head,
|
2014-09-23 06:47:05 +00:00
|
|
|
to_read, &data_count, 32 | 8);
|
2009-10-07 07:25:40 +00:00
|
|
|
if (ret <= 0) {
|
2010-01-11 11:31:36 +00:00
|
|
|
/* an error means a disc with no ISO image */
|
2011-04-22 08:18:41 +00:00
|
|
|
o->media_read_error= 1;
|
2011-03-24 18:25:00 +00:00
|
|
|
if (ret == -2) {
|
|
|
|
path[0]= 0;
|
|
|
|
burn_drive_d_get_adr(drive, path);
|
|
|
|
sprintf(msg, "Pseudo drive '%s' does not allow reading", path);
|
|
|
|
isoburn_msgs_submit(NULL, 0x00060000, msg, 0, "NOTE", 0);
|
|
|
|
o->fabricated_disc_status= BURN_DISC_BLANK;
|
|
|
|
} else if (capacity > 0)
|
2010-01-11 11:31:36 +00:00
|
|
|
o->fabricated_disc_status= BURN_DISC_FULL;
|
2011-03-21 09:31:51 +00:00
|
|
|
else if(!(flag & 1))
|
|
|
|
o->fabricated_disc_status= BURN_DISC_BLANK;
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 1; goto ex;}
|
2009-10-07 07:25:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-11-02 14:09:45 +00:00
|
|
|
/* No read capacity means blank medium */
|
2011-03-21 09:31:51 +00:00
|
|
|
if(!(flag & 1))
|
|
|
|
o->fabricated_disc_status= BURN_DISC_BLANK;
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 1; goto ex;}
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check first 64K. If 0's, the disc is treated as a blank disc, and thus
|
|
|
|
overwritten without extra check. */
|
2008-05-13 13:52:33 +00:00
|
|
|
i = Libisoburn_target_head_sizE;
|
2008-01-10 15:20:57 +00:00
|
|
|
while (i && !o->target_iso_head[i-1])
|
|
|
|
--i;
|
|
|
|
|
|
|
|
if (!i) {
|
2011-03-21 09:31:51 +00:00
|
|
|
if(!(flag & 1))
|
|
|
|
o->fabricated_disc_status= BURN_DISC_BLANK;
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 1; goto ex;}
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
|
|
|
|
|
2010-09-10 17:10:03 +00:00
|
|
|
if (strncmp((char*)pvm->std_identifier, "CD001", 5) == 0) {
|
2008-01-10 15:20:57 +00:00
|
|
|
off_t size;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (pvm->vol_desc_type[0] != 1 || pvm->vol_desc_version[0] != 1
|
|
|
|
|| pvm->file_structure_version[0] != 1 ) {
|
|
|
|
/* TODO for now I treat this as a full disc */
|
|
|
|
o->fabricated_disc_status= BURN_DISC_FULL;
|
2011-05-09 15:49:47 +00:00
|
|
|
{ret= 1; goto ex;}
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ok, PVM found, set size */
|
|
|
|
size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
|
2010-09-10 17:10:03 +00:00
|
|
|
ret= isoburn_inspect_partition(o, (uint32_t) size, 0);
|
|
|
|
if (ret <= 0)
|
2011-05-09 15:49:47 +00:00
|
|
|
goto ex;
|
2008-01-10 15:20:57 +00:00
|
|
|
size *= (off_t) 2048; /* block size in bytes */
|
|
|
|
isoburn_set_start_byte(o, size, 0);
|
2011-03-21 09:31:51 +00:00
|
|
|
if(!(flag & 1))
|
|
|
|
o->fabricated_disc_status= BURN_DISC_APPENDABLE;
|
2011-07-10 11:26:20 +00:00
|
|
|
} else if (strncmp((char*)pvm->std_identifier, "CDXX1", 5) == 0 ||
|
|
|
|
(strncmp((char*)pvm->std_identifier, "CDxx1", 5) == 0 &&
|
|
|
|
pvm->vol_desc_type[0] == 'x')) {
|
2008-01-10 15:20:57 +00:00
|
|
|
|
|
|
|
/* empty image */
|
2008-05-06 14:45:49 +00:00
|
|
|
isoburn_set_start_byte(o, o->zero_nwa * 2048, 0);
|
2011-03-21 09:31:51 +00:00
|
|
|
if(!(flag & 1))
|
|
|
|
o->fabricated_disc_status= BURN_DISC_BLANK;
|
2008-01-10 15:20:57 +00:00
|
|
|
} else {
|
|
|
|
/* treat any disc in an unknown format as full */
|
|
|
|
o->fabricated_disc_status= BURN_DISC_FULL;
|
|
|
|
}
|
2010-09-10 17:10:03 +00:00
|
|
|
|
2011-05-09 15:49:47 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(path != NULL)
|
|
|
|
free(path);
|
|
|
|
if(msg != NULL)
|
|
|
|
free(msg);
|
|
|
|
return(ret);
|
2008-01-10 15:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-02 14:09:45 +00:00
|
|
|
/** Alters and writes the first 64 kB of a "medium" to invalidate
|
2008-01-10 15:20:57 +00:00
|
|
|
an ISO image. (It shall stay restorable by skilled humans, though).
|
2011-11-02 14:09:45 +00:00
|
|
|
The result shall especially keep libisoburn from accepting the medium
|
2008-01-10 15:20:57 +00:00
|
|
|
image as ISO filesystem.
|
|
|
|
@param o A fully activated isoburn object. isoburn_start_emulation()
|
|
|
|
was already called.
|
|
|
|
@return <=0 error , 1 = success
|
|
|
|
*/
|
|
|
|
int isoburn_invalidate_iso(struct isoburn *o, int flag)
|
|
|
|
{
|
2016-05-03 07:57:32 +00:00
|
|
|
int end_ed_found= 0, i;
|
|
|
|
char *head;
|
|
|
|
|
|
|
|
head= (char *) o->target_iso_head;
|
2008-01-10 15:20:57 +00:00
|
|
|
/*
|
|
|
|
* replace CD001 with CDXX1 in PVM.
|
|
|
|
* I think this is enought for invalidating an iso image
|
|
|
|
*/
|
2016-05-03 07:57:32 +00:00
|
|
|
strncpy(head + 16 * 2048 + 1, "CDXX1", 5);
|
|
|
|
|
|
|
|
/* Look for UDF volume recognition sequence and invalidate */
|
|
|
|
for(i= 17 * 2048; i < 32 * 2048; i+= 2048) {
|
|
|
|
if(end_ed_found) {
|
|
|
|
if(head[i] == 0 && strncmp(head + i + 1, "BEA01", 5) == 0)
|
|
|
|
strncpy(head + i + 1, "BEAX1", 5);
|
|
|
|
else if(head[i] == 0 && strncmp(head + i + 1, "NSR", 3) == 0)
|
|
|
|
strncpy(head + i + 1, "NSRX", 4);
|
|
|
|
else if(head[i] == 0 && strncmp(head + i + 1, "TEA", 3) == 0)
|
|
|
|
strncpy(head + i + 1, "TEAX", 4);
|
|
|
|
} else {
|
|
|
|
if(((unsigned char *) head)[i] == 0xff &&
|
|
|
|
strncmp(head + i + 1, "CD001", 5) == 0)
|
|
|
|
end_ed_found= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 15:20:57 +00:00
|
|
|
return isoburn_activate_session(o->drive);
|
|
|
|
}
|
|
|
|
|
2008-02-06 21:45:31 +00:00
|
|
|
|
|
|
|
/* API @since 0.1.0 */
|
|
|
|
int isoburn_set_read_pacifier(struct burn_drive *drive,
|
|
|
|
int (*read_pacifier)(IsoImage*, IsoFileSource*),
|
|
|
|
void *read_handle)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct isoburn *o;
|
|
|
|
|
|
|
|
ret = isoburn_find_emulator(&o, drive, 0);
|
|
|
|
if(ret < 0 || o == NULL)
|
|
|
|
return -1;
|
|
|
|
o->read_pacifier_handle= read_handle;
|
|
|
|
o->read_pacifier= read_pacifier;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|