Moved source to src/, created bootstrap

This commit is contained in:
Mario Danic
2007-09-14 04:14:21 +00:00
parent e71dec2c1e
commit e84f17f6a6
7 changed files with 7 additions and 0 deletions

View File

@ -0,0 +1,398 @@
/*
cc -g -c \
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE \
burn_wrap.c
*/
/* libburn wrappers for libisoburn
Copyright 2007 Thomas Schmitt, <scdbackup@gmx.net>
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../libburn/libburn.h"
#include "../libisofs/libisofs.h"
#include "libisoburn.h"
#include "isoburn.h"
/* The global list of isoburn objects. Usually there is only one. */
extern struct isoburn *isoburn_list_start; /* in isoburn.c */
int isoburn_initialize(void)
{
if(!iso_init())
return(0);
if(!burn_initialize())
return(0);
isoburn_destroy_all(&isoburn_list_start, 0); /* isoburn_list_start= NULL */
return(1);
}
/** Examine the media and sets appropriate emulation if needed.
*/
static int isoburn_welcome_media(struct isoburn **o, struct burn_drive *d,
int flag)
{
int ret;
struct burn_multi_caps *caps= NULL;
ret= burn_disc_get_multi_caps(d, BURN_WRITE_NONE, &caps, 0);
if(ret<=0)
goto ex;
ret= isoburn_new(o, 0);
if(ret<=0)
goto ex;
(*o)->drive= d;
if(caps->start_adr) { /* set emulation to overwriteable */
(*o)->emulation_mode= 1;
ret= isoburn_start_emulation(*o, 0);
if(ret<=0) {
(*o)->emulation_mode= -1;
goto ex;
}
} else {
/* >>> recognize unsuitable media */;
}
/* <<< now planned to be done by app
ret = isoburn_read_volset(*o);
if(ret<=0) {
(*o)->emulation_mode= -1;
goto ex;
}
*/
ret= 1;
ex:
if(caps!=NULL)
burn_disc_free_multi_caps(&caps);
return(ret);
}
int isoburn_drive_scan_and_grab(struct burn_drive_info *drive_infos[],
char *adr, int load)
{
int ret, treatment= 0;
struct stat stbuf;
char libburn_drive_adr[BURN_DRIVE_ADR_LEN], *adrpt, *stdio_adr= NULL;
struct isoburn *o= NULL;
adrpt= adr;
if(strncmp(adr, "grow:", 5)==0) {
treatment= 1;
adrpt+= 5;
if(stat(adrpt,&stbuf)!=-1)
if(S_ISREG(stbuf.st_mode) || S_ISBLK(stbuf.st_mode)) {
stdio_adr= calloc(strlen(adrpt)+6+1, 1);
if(stdio_adr==NULL)
{ret= -1; goto ex;}
sprintf(stdio_adr, "stdio:%s", adrpt); /* use pseudo-drive */
adrpt= stdio_adr;
}
} else if(strncmp(adr, "modify:", 7)==0) {
treatment= 2;
adrpt+= 7;
}
ret= burn_drive_convert_fs_adr(adrpt, libburn_drive_adr);
if(treatment==0) {
if(ret>0)
treatment= 1;
else
treatment= 2;
} else if(treatment==1 && ret<=0) {
/* >>> unsuitable drive address */;
ret= 0; goto ex;
}
o->treatment= treatment;
if(treatment==1) {
ret= burn_drive_scan_and_grab(drive_infos, adrpt, load);
if(ret<=0)
goto ex;
ret= isoburn_welcome_media(&o, (*drive_infos)[0].drive, 0);
if(ret<=0)
goto ex;
} else {
if(stat(adrpt,&stbuf)!=-1)
if(! S_ISREG(stbuf.st_mode)) {
/* >>> unsuitable target for modify */;
ret= 0; goto ex;
}
/* >>> welcome file for modfication treatment */;
}
ret= 1;
ex:
if(ret<=0)
isoburn_destroy(&o,0);
if(stdio_adr!=NULL)
free(stdio_adr);
return(ret);
}
int isoburn_drive_grab(struct burn_drive *drive, int load)
{
int ret;
struct isoburn *o= NULL;
ret= burn_drive_grab(drive, load);
if(ret<=0)
goto ex;
ret= isoburn_welcome_media(&o, drive, 0);
if(ret<=0)
goto ex;
ret= 1;
ex:
if(ret<=0)
isoburn_destroy(&o,0);
return(ret);
}
/** Retrieve media emulation and eventual isoburn emulator of drive.
@return -1 unsuitable media, 0 generic media, 1 emulated media.
*/
int isoburn_find_emulator(struct isoburn **pt,
struct burn_drive *drive, int flag)
{
int ret;
ret= isoburn_find_by_drive(pt, drive, 0);
if(ret<=0)
return(0);
if((*pt)->emulation_mode==-1)
return(-1);
if((*pt)->emulation_mode==0)
return(0);
return(1);
}
enum burn_disc_status isoburn_disc_get_status(struct burn_drive *drive)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return(BURN_DISC_UNSUITABLE);
if(o!=NULL)
if(o->fabricated_disc_status!=BURN_DISC_UNREADY)
return(o->fabricated_disc_status);
if(ret==0)
return(burn_disc_get_status(drive));
/* emulated status */
if(o->emulation_mode==-1)
return(BURN_DISC_UNSUITABLE);
if(o->nwa>0)
return(BURN_DISC_APPENDABLE);
return(BURN_DISC_BLANK);
}
int isoburn_disc_erasable(struct burn_drive *d)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, d, 0);
if(ret>0)
if(o->emulation_mode==1)
return(1);
return burn_disc_erasable(d);
}
void isoburn_disc_erase(struct burn_drive *drive, int fast)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, drive, 0);
if(ret>0) {
if(o->emulation_mode==-1) {
/* To cause a negative reply with burn_drive_wrote_well() */
burn_drive_cancel(drive);
return;
}
if(o->emulation_mode>0) {
ret= isoburn_invalidate_iso(o, 0);
if(ret<=0)
burn_drive_cancel(drive);
return;
}
}
burn_disc_erase(drive, fast);
}
int isoburn_disc_get_msc1(struct burn_drive *d, int *start_lba)
{
int ret;
struct isoburn *o;
if(isoburn_disc_get_status(d)!=BURN_DISC_APPENDABLE)
return(0);
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(0);
if(ret>0) if(o->emulation_mode>0) {
*start_lba= 0;
return(1);
}
return(burn_disc_get_msc1(d, start_lba));
}
int isoburn_disc_track_lba_nwa(struct burn_drive *d,
struct burn_write_opts *opts,
int trackno, int *lba, int *nwa)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
return(0);
if(ret>0) if(o->emulation_mode>0) {
*lba= 0;
*nwa= o->nwa;
return(1);
}
return(burn_disc_track_lba_nwa(d, opts, trackno, lba, nwa));
}
void isoburn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
{
int ret, multi= 1;
struct isoburn *o;
struct burn_drive *drive;
drive= burn_write_opts_get_drive(opts);
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return;
if(o!=NULL) {
if(o->emulation_mode!=0) {
multi= 0;
if(o->emulation_mode>0 && o->nwa >= 0)
burn_write_opts_set_start_byte(opts, ((off_t) o->nwa) * (off_t) 2048);
}
}
burn_write_opts_set_multi(opts, multi);
burn_disc_write(opts, disc);
}
void isoburn_drive_release(struct burn_drive *drive, int eject)
{
int ret;
struct isoburn *o;
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return;
if(o!=NULL)
isoburn_destroy(&o, 0);
burn_drive_release(drive, eject);
}
void isoburn_finish(void)
{
isoburn_destroy_all(&isoburn_list_start, 0);
burn_finish();
iso_finish();
}
int isoburn_needs_emulation(struct burn_drive *drive)
{
int ret;
struct isoburn *o;
enum burn_disc_status s;
s= isoburn_disc_get_status(drive);
if(s!=BURN_DISC_BLANK && s!=BURN_DISC_APPENDABLE)
return(-1);
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<0)
return(-1);
if(ret>0)
if(o->emulation_mode>0)
return(1);
return(0);
}
int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag)
{
int ret;
struct burn_drive *drive = o->drive;
struct burn_multi_caps *caps= NULL;
ret= burn_disc_get_multi_caps(drive, BURN_WRITE_NONE, &caps, 0);
if(ret<=0)
goto ex;
if(!caps->start_adr)
{ret= 0; goto ex;}
o->min_start_byte= value;
if(value % caps->start_alignment)
value+= caps->start_alignment - (value % caps->start_alignment);
o->nwa= value/2048;
ret= 1;
ex:
if(caps!=NULL)
burn_disc_free_multi_caps(&caps);
return(ret);
}
#ifdef Libburn_obsoleted_on_its_way_ouT
void isoburn_write_opts_set_start_byte(struct burn_write_opts *opts,
off_t value)
{
int ret;
struct isoburn *o;
struct burn_drive *drive;
drive= burn_write_opts_get_drive(opts);
ret= isoburn_find_emulator(&o, drive, 0);
if(ret<=0) /* no emulation, no burn_write_opts_set_start_byte() */
return;
ret = isoburn_set_start_byte(o, value, 0);
if(ret<=0)
return;
burn_write_opts_set_start_byte(opts, ((off_t) o->nwa) * (off_t) 2048);
}
#endif /* Libburn_obsoleted_on_its_way_ouT */

View File

@ -0,0 +1,86 @@
/*
data source for libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
*/
#include <assert.h>
#include <stdlib.h>
#include "isoburn.h"
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
struct disc_data_src {
struct burn_drive *d;
int nblocks;
};
static int
ds_read_block(struct data_source *src, int lba, unsigned char *buffer)
{
int ret;
struct disc_data_src *data;
off_t count;
assert(src && buffer);
data = (struct disc_data_src*)src->data;
/* if (lba >= data->nblocks)
* return BLOCK_OUT_OF_FILE;
*/
ret = burn_read_data(data->d, (off_t) lba * (off_t) 2048, buffer, 2048, &count, 0);
if (ret <= 0 )
return -1; //error
return 0;
}
static int
ds_get_size(struct data_source *src)
{
struct disc_data_src *data;
assert(src);
data = (struct disc_data_src*)src->data;
return data->nblocks;
}
static void
ds_free_data(struct data_source *src)
{
free(src->data);
}
static struct data_source *
isoburn_data_source_new(struct burn_drive *d)
{
struct disc_data_src *data;
struct data_source *ret;
assert(d);
data = malloc(sizeof(struct disc_data_src));
if (!data)
return NULL;
data->d = d;
//TODO should be filled with the size of disc (or track?)
data->nblocks = 0;
ret = malloc(sizeof(struct data_source));
if (!ret) {
free(data);
return NULL;
}
ret->refcount = 1;
ret->read_block = ds_read_block;
ret->get_size = ds_get_size;
ret->free_data = ds_free_data;
ret->data = data;
return ret;
}

View File

@ -0,0 +1,237 @@
/*
cc -g -c isoburn.c
*/
/*
Class core of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/
/* ( derived from stub generated by CgeN on Sat, 01 Sep 2007 12:04:36 GMT ) */
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#include "isoburn.h"
/* -------------------------- isoburn ----------------------- */
/* The global list of isoburn objects. Usually there is only one.
>>> we are not ready for multiple control threads yet. See >>> mutex .
Multiple burns under one control thread should work.
*/
struct isoburn *isoburn_list_start= NULL;
int isoburn_new(struct isoburn **objpt, int flag)
{
struct isoburn *o;
int i;
int isoburn_new_rwopts(struct isoburn *o);
*objpt= o= (struct isoburn *) malloc(sizeof(struct isoburn));
if(o==NULL)
return(-1);
o->drive= NULL;
o->emulation_mode= 0;
o->min_start_byte= 0;
o->nwa= 0;
o->treatment= 1;
o->target_ropts= NULL;
o->new_wopts= NULL;
o->fabricated_disc_status= BURN_DISC_UNREADY;
for(i=0;i<65536;i++)
o->target_iso_head[i]= 0;
o->target_volset= NULL;
o->prev= NULL;
o->next= NULL;
if(isoburn_new_rwopts(o)<=0)
goto failed;
isoburn_link(o, isoburn_list_start, 1);
return(1);
failed:;
isoburn_destroy(objpt,0);
return(-1);
}
int isoburn_destroy(struct isoburn **objpt, int flag)
{
struct isoburn *o;
int isoburn_free_rwopts(struct isoburn *o);
o= *objpt;
if(o==NULL)
return(0);
/* >>> mutex */
if(o==isoburn_list_start)
isoburn_list_start= o->next;
if(o->prev!=NULL)
o->prev->next= o->next;
if(o->next!=NULL)
o->next->prev= o->prev;
/* >>> end mutex */
if(o->drive!=NULL)
burn_drive_release(o->drive, 0);
isoburn_free_rwopts(o);
if(o->target_volset!=NULL)
iso_volset_free(o->target_volset);
free((char *) o);
*objpt= NULL;
return(1);
}
int isoburn_destroy_all(struct isoburn **objpt, int flag)
{
struct isoburn *o,*n;
o= *objpt;
if(o==NULL)
return(0);
for(;o->prev!=NULL;o= o->prev);
for(;o!=NULL;o= n) {
n= o->next;
isoburn_destroy(&o,0);
}
*objpt= NULL;
return(1);
}
int isoburn_get_emulation_mode(struct isoburn *o, int *pt, int flag)
{
*pt= o->emulation_mode;
return(1);
}
int isoburn_get_target_volset(struct isoburn *o, struct iso_volset **pt,
int flag)
{
*pt= o->target_volset;
return(1);
}
int isoburn_get_prev(struct isoburn *o, struct isoburn **pt, int flag)
{
*pt= o->prev;
return(1);
}
int isoburn_get_next(struct isoburn *o, struct isoburn **pt, int flag)
{
*pt= o->next;
return(1);
}
int isoburn_link(struct isoburn *o, struct isoburn *link, int flag)
/*
bit0= insert as link->prev rather than as link->next
*/
{
/* >>> mutex */
if(isoburn_list_start==NULL ||
(isoburn_list_start==link && (flag&1)))
isoburn_list_start= o;
if(o->prev!=NULL)
o->prev->next= o->next;
if(o->next!=NULL)
o->next->prev= o->prev;
o->prev= o->next= NULL;
if(link==NULL)
return(1);
if(flag&1) {
o->next= link;
o->prev= link->prev;
if(o->prev!=NULL)
o->prev->next= o;
link->prev= o;
} else {
o->prev= link;
o->next= link->next;
if(o->next!=NULL)
o->next->prev= o;
link->next= o;
}
/* >>> end mutex */
return(1);
}
int isoburn_count(struct isoburn *o, int flag)
/* flag: bit1= count from start of list */
{
int counter= 0;
if(flag&2)
for(;o->prev!=NULL;o= o->prev);
for(;o!=NULL;o= o->next)
counter++;
return(counter);
}
int isoburn_by_idx(struct isoburn *o, int idx, struct isoburn **pt, int flag)
/* flag: bit0= fetch first (idx<0) or last (idx>0) item in list
bit1= address from start of list */
{
int i,abs_idx;
struct isoburn *npt;
if(flag&2)
for(;o->prev!=NULL;o= o->prev);
abs_idx= (idx>0?idx:-idx);
*pt= o;
for(i= 0;(i<abs_idx || (flag&1)) && *pt!=NULL;i++) {
if(idx>0)
npt= o->next;
else
npt= o->prev;
if(npt==NULL && (flag&1))
break;
*pt= npt;
}
return(*pt!=NULL);
}
int isoburn_find_by_drive(struct isoburn **pt, struct burn_drive *d, int flag)
{
struct isoburn *o;
*pt= NULL;
for(o= isoburn_list_start;o->prev!=NULL;o= o->prev)
if(o->drive==d) {
*pt= o;
return(1);
}
return(0);
}

View File

@ -0,0 +1,141 @@
/*
Class struct of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/
#ifndef Isoburn_includeD
#define Isoburn_includeD
/* for uint8_t */
#include <stdint.h>
struct isoburn {
/* The libburn drive to which this isoburn object is related
Most isoburn calls will use a burn_drive as object handle */
struct burn_drive *drive;
/* -1= inappropriate media state detected
0= libburn multi-session media, resp. undecided yet
1= random access media */
int emulation_mode;
/* Although rarely used, libburn can operate on several
drives simultaneously. */
struct isoburn *prev;
struct isoburn *next;
/* --- My part --- */
/* Start address as given by image examination (bytes, not blocks) */
off_t min_start_byte;
/* Aligned start address to be used for processing (counted in blocks) */
int nwa;
/* Eventual freely fabricated isoburn_disc_get_status().
BURN_DISC_UNREADY means that normally emulated status is in effect.
*/
enum burn_disc_status fabricated_disc_status;
/* --- Vreixo's part --- */
/* Expansion treatment strategy: 1= grow, 2= modify, (any use for 0 ?) */
int treatment;
/* The options for reading the old image.
target_ropts.size will contain the number of blocks of the image. */
struct ecma119_read_opts *target_ropts;
/* Buffered ISO head from media (should that become part of
ecma119_read_opts ?) */
uint8_t target_iso_head[65536];
/* The filesystem structure of the old image from media. */
struct iso_volset *target_volset;
/* The output options of the current run of libisofs.
Element .overwrite eventually points to a buffered new head
with size fields describing the new size alone, not the
new combined size counted from block 0.
(This head is to be merged with above target_iso_head.) */
struct ecma119_source_opts *new_wopts;
};
/* Creation and disposal function */
int isoburn_new(struct isoburn **objpt, int flag);
int isoburn_destroy(struct isoburn **objpt, int flag);
/* Eventual readers for public attributes */
/* ( put into separate .h file then ) */
int isoburn_get_emulation_mode(struct isoburn *o, int *pt, int flag);
int isoburn_get_target_volset(struct isoburn *o, struct iso_volset **pt,
int flag);
/* List management */
int isoburn_get_prev(struct isoburn *o, struct isoburn **pt, int flag);
int isoburn_get_next(struct isoburn *o, struct isoburn **pt, int flag);
int isoburn_destroy_all(struct isoburn **objpt, int flag);
int isoburn_link(struct isoburn *o, struct isoburn *link, int flag);
int isoburn_count(struct isoburn *o, int flag);
int isoburn_by_idx(struct isoburn *o, int idx, struct isoburn **pt, int flag);
int isoburn_find_by_drive(struct isoburn **pt, struct burn_drive *d, int flag);
/* Non API inner interfaces */
/* Calls from burn_wrap.c into isofs_wrap.c */
int isoburn_start_emulation(struct isoburn *o, int flag);
int isoburn_new_rwopts(struct isoburn *o);
int isoburn_free_rwopts(struct isoburn *o);
int isoburn_invalidate_iso(struct isoburn *o, int flag);
/* Calls from isofs_wrap.c into burn_wrap.c */
/** Get an eventual isoburn object which is wrapped around the drive.
@param pt Eventually returns a pointer to the found object.
It is allowed to become NULL if return value is -1 or 0.
In this case, the drive is a genuine libburn drive
with no emulation activated by isoburn.
@param drive The drive to be searched for
@param flag unused yet
@return -1 unsuitable media, 0 generic media, 1 emulated media.
*/
int isoburn_find_emulator(struct isoburn **pt,
struct burn_drive *drive, int flag);
/** Set the start address for an emulated add-on session. The value will
be rounded up to the alignment necessary for the media. The aligned
value will be divided by 2048 and then put into o->nwa .
@param o The isoburn object to be programmed.
@param value The start address in bytes
@param flag unused yet
@return <=0 is failure , >0 success
*/
int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag);
/** Get a data source suitable for read from a drive using burn_read_data()
function.
@param d drive to read from. Must be grabbed.
@return the data source, NULL on error. Must be freed with libisofs
data_source_free() function. Note that that doesn't release the
drive.
*/
struct data_source *
isoburn_data_source_new(struct burn_drive *d);
#endif /* Isoburn_includeD */

View File

@ -0,0 +1,268 @@
/*
cc -g -c isofs_wrap.c
*/
/*
libisofs related functions of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#include "isoburn.h"
/* Vreixo:
This is now all yours. My text here is only a snapshot
of what i think we discussed in the last days.
If you change the prototypes of the functions listed
in this initial stub, then you have to change isoburn.h
and eventually libisoburn.h. And you have to tell me so
i can adjust burn_wrap.c .
*/
#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
*/
int isoburn_read_volset(struct burn_drive *d, struct isoburn_read_opts *read_opts,
struct iso_volset **volset)
{
int ret;
struct ecma119_read_opts ropts;
struct data_source *src;
struct isoburn *o;
assert(d && read_opts && volset);
ret = isoburn_find_emulator(&o, d, 0);
if (ret < 0)
return 0;
if (o->fabricated_disc_status == BURN_DISC_BLANK) {
// FIXME construct an empty volset!!
*volset = NULL;
return 1;
}
ret = isoburn_disc_get_msc1(d, &ropts.block);
if (ret < 0)
return -1;
ropts.norock = read_opts->norock;
ropts.nojoliet = read_opts->nojoliet;
ropts.preferjoliet = read_opts->preferjoliet;
ropts.mode = read_opts->mode;
ropts.uid = read_opts->uid;
ropts.gid = read_opts->gid;
src = isoburn_data_source_new(d);
if (!src)
return -2;
*volset = iso_volset_read(src, &ropts);
data_source_free(src);
if (!(*volset))
return -3;
o->target_volset = *volset;
read_opts->hasRR = ropts.hasRR;
read_opts->hasJoliet = ropts.hasJoliet;
return 1;
}
/* API function. See libisoburn.h
*/
int isoburn_activate_session(struct burn_drive *drive)
{
int ret;
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 */
ret = burn_random_access_write(drive, 0, o->target_iso_head, 64*2048, 0);
return ret;
}
/** Allocate and initialize memory for libisofs related objects in
struct isoburn.
@param o A freshly created isoburn object with NULL pointers
@return <=0 error , 1 = success
*/
int isoburn_new_rwopts(struct isoburn *o)
{
struct ecma119_source_opts *wopts;
/* >>> code <<< */
/* create and initialize target_ropts read options */
o->target_ropts = calloc(1, sizeof(struct ecma119_read_opts));
if (!p->target_ropts)
return -1;
/* TODO mmm, maybe we don't need struct ecma119_read_opts in libisoburn */
/* create and initialize new_wopts write options for new image */
wopts = calloc(1, sizeof(struct ecma119_source_opts));
if (!wopts)
return -1;
wopts->overwrite = o->target_iso_head;
o->new_wopts = wopts;
return 1;
}
/** Dispose memory objects created by isoburn_new_rwopts(). This function
expect that the pointers in struct isoburn might still be NULL, i.e.
that isoburn_new_rwopts() was not called before.
@return <=0 error , 1 = success
*/
int isoburn_free_rwopts(struct isoburn *o)
{
free(o->target_ropts);
free(o->new_wopts);
return 1;
}
/** 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_new_rwopts() was
already called, nevertheless.
@return <=0 error , 1 = success
*/
int isoburn_start_emulation(struct isoburn *o, int flag)
{
int ret;
off_t *data_count;
struct burn_drive *drive;
struct ecma119_pri_vol_desc *pvm;
drive= o->drive;
/* we can assume 0 as start block for image */
// TODO what about ms? where we validate valid iso image in ms disc?
ret = burn_read_data(drive, (off_t) 0, o->target_iso_head,
sizeof(o->target_iso_head), &data_count, 0);
if (ret <= 0)
return -1;
pvm = (struct ecma119_pri_vol_desc *)(o->target_iso_head + 16 * 2048);
/* 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;
return 1;
}
if (!strncmp((char*)pvm->std_identifier, "CD001", 5)) {
off_t size;
/* ok, PVM found, set size */
size = (off_t) iso_read_lsb(pvm->vol_space_size, 4);
size *= (off_t) 2048; /* block size in bytes */
isoburn_set_start_byte(o, size, 0);
o->fabricated_disc_status= BURN_DISC_APPENDABLE;
} else if (!strncmp((char*)pvm->std_identifier, "CDXX1", 5)) {
/* empty image */
isoburn_set_start_byte(o, (off_t) 0, 0);
o->fabricated_disc_status= BURN_DISC_BLANK;
} else {
// TODO for now I treat this as a full disc
o->fabricated_disc_status= BURN_DISC_FULL;
}
return 1;
}
/** Alters and writes the first 64 kB of a "media" to invalidate
an ISO image. (It shall stay restorable by skilled humans, though).
The result shall especially keep libisoburn from accepting the media
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)
{
/*
* replace CD001 with CDXX1 in PVM.
* I think this is enought for invalidating an iso image
*/
strncpy(o->target_iso_head + 16 * 2048 + 1, "CDXX1", 5);
return isoburn_activate_session(o->drive);
}

View File

@ -0,0 +1,222 @@
/*
API definition of libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
and Thomas Schmitt <scdbackup@gmx.net>
*/
/**
libisoburn is a frontend for libraries libburn and libisofs which enables
creation and expansion of ISO-9660 filesystems on all CD/DVD media supported
by libburn. This includes media like DVD+RW, which do not support multi-session
management on media level and even plain disk files or block devices.
The price for that is thorough specialization on data files in ISO-9660
filesystem images. So libisoburn is not suitable for audio (CD-DA) or any
other CD layout which does not entirely consist of ISO-9660 sessions.
The priciple of this frontend is that you may use any call of libisofs or
libburn unless it has a isoburn_*() wrapper listed in the following function
documentation.
E.g. call isoburn_initialize() rather than iso_init(); burn_initialize()
and call isoburn_drive_scan_and_grab() rather than burn_drive_scan_and_grab().
But you may call burn_disc_get_profile() directly if you want to display
the media type.
>>>
>>> Take into respect Vreixo's (mandatory ?) shortcuts which are to come
>>>
The usage model is like with libburn: the target is a "media" in a "drive".
The wrappers will transparently provide the necessary emulations which
are appropriate for particular target "drives".
*/
/* API functions */
/** Initialize libisoburn, libisofs and libburn.
Wrapper for : iso_init() and burn_initialize()
@return 1 indicates success, 0 is failure
*/
int isoburn_initialize(void);
/** Aquire a target drive by its filesystem path resp. libburn persistent
address.
Wrapper for: burn_drive_scan_and_grab()
*/
int isoburn_drive_scan_and_grab(struct burn_drive_info *drive_infos[],
char* adr, int load);
/** Aquire a drive from the burn_drive_info[] array which was obtained by
a previous call of burn_drive_scan().
Wrapper for: burn_drive_grab()
*/
int isoburn_drive_grab(struct burn_drive *drive, int load);
/** Inquire the media status. Expect the whole spectrum of libburn BURN_DISC_*
with multi-session media. Emulated states with random access media are
BURN_DISC_BLANK and BURN_DISC_APPENDABLE.
Wrapper for: burn_disc_get_status()
*/
enum burn_disc_status isoburn_disc_get_status(struct burn_drive *drive);
/** Tells whether the media can be treated by isoburn_disc_erase().
Wrapper for: burn_disc_erasable()
*/
int isoburn_disc_erasable(struct burn_drive *d);
/** Mark the media as blank. With multi-session media this will call
burn_disc_erase(). With random access media, an eventual ISO-9660
filesystem will get invalidated by altering its start blocks on media.
In case of success, the media is in status BURN_DISC_BLANK afterwards.
Wrapper for: burn_disc_erase()
*/
void isoburn_disc_erase(struct burn_drive *drive, int fast);
/**
* Options for image reading.
*/
struct isoburn_read_opts {
unsigned int norock:1; /*< Do not read Rock Ridge extensions */
unsigned int nojoliet:1; /*< Do not read Joliet extensions */
unsigned int preferjoliet:1;
/*< When both Joliet and RR extensions are present, the RR
* tree is used. If you prefer using Joliet, set this to 1. */
uid_t uid; /**< Default uid when no RR */
gid_t gid; /**< Default uid when no RR */
mode_t mode; /**< Default mode when no RR (only permissions) */
/* modified by the function isoburn_read_volset */
unsigned int hasRR:1; /*< It will be set to 1 if RR extensions are present,
to 0 if not. */
unsigned int hasJoliet:1; /*< It will be set to 1 if Joliet extensions are
present, to 0 if not. */
uint32_t size; /**< Will be filled with the size (in 2048 byte block) of
* the image, as reported in the PVM. */
};
/** Load the ISO filesystem directory tree from the media in the given drive.
This will give libisoburn the base on which it can let libisofs perform
image growing or image modification. The loaded volset gets attached
to the drive object and is not publicly available.
Not a wrapper, but peculiar to libisoburn.
@param d The drive which holds an existing ISO filesystem
@param read_opts The read options which can be chosen by the application
@param volset the volset that represents the image, or NULL if the image is
empty.
<<<<< What about return a volset without file if image is
empty <<<<<<<<<
@return <=0 error , 1 = success
>>>>> error means damaged or unsupported image
error code is stored in ecma119_read_opts in libisofs
also error msgs are enqueued. Any need to pass them to usr? <<<<<<
*/
int isoburn_read_volset(struct burn_drive *d, struct isoburn_read_opts *read_opts,
struct iso_volset **volset);
/** Obtain the start block number of the most recent session on media. In
case of random access media this will always be 0. Succesfull return is
not a guarantee that there is a ISO-9660 image at all. The call will fail,
nevertheless,if isoburn_disc_get_status() returns not BURN_DISC_APPENDABLE.
Wrapper for: burn_disc_get_msc1()
*/
int isoburn_disc_get_msc1(struct burn_drive *d, int *start_lba);
/** Use this with trackno==0 to obtain the predicted start block number of the
new session. The interesting number is returned in parameter nwa.
Wrapper for: burn_disc_track_lba_nwa()
*/
int isoburn_disc_track_lba_nwa(struct burn_drive *d, struct burn_write_opts *o,
int trackno, int *lba, int *nwa);
/** Prepare a disc for writting the new session.
@param disc A burn_disc suitable to pass to isoburn_disc_write.
@return <=0 error , 1 = success
*/
int isoburn_prepare_disc(struct burn_drive *d, struct burn_disc **disc);
/** Start writing of the new session.
This call is asynchrounous. I.e. it returns quite soon and the progress has
to be watched by a loop with call burn_drive_get_status() until
BURN_DRIVE_IDLE is returned.
Wrapper for: burn_disc_write()
*/
void isoburn_disc_write(struct burn_write_opts *o, struct burn_disc *disc);
/** Call this after isoburn_disc_write has finished and burn_drive_wrote_well()
indicates success. It will eventually complete the emulation of
multi-session functionality, if needed at all. Let libisoburn decide.
Not a wrapper, but peculiar to libisoburn.
*/
int isoburn_activate_session(struct burn_drive *drive);
/** Write a new session to a disc.
This is a synchrounous call equivalent to isoburn_prepare_disc +
isoburn_disc_write + isoburn_activate_session
@param pacifier_func If not NULL: a function to produce appeasing messages.
See burn_abort_pacifier() in libburn.h for an example.
*/
int isoburn_perform_write(struct burn_write_opts *o,
int (*pacifier_func)(void *handle, int patience,
int elapsed));
/** Release an aquired drive.
Wrapper for: burn_drive_release()
*/
void isoburn_drive_release(struct burn_drive *drive, int eject);
/** Shutdown all three libraries.
Wrapper for : iso_finish() and burn_finish().
*/
void isoburn_finish(void);
/*
The following two calls are for expert applications only.
An application should have a special reason to use them.
*/
/** Inquire wether the media needs emulation or would be suitable for
generic multi-session via libburn.
@return 0 is generic multi-session
1 is emulated multi-session
-1 is not suitable for isoburn
*/
int isoburn_needs_emulation(struct burn_drive *drive);
#ifdef Libburn_obsoleted_on_its_way_ouT
/** Caution: Use this with great care. It is not needed normally.
This call can set the nwa block number to an arbitrary value. If ever, do
this before preparing the session by libisofs. The drive must be grabbed,
though. This overrides the automated address computation. Call
isoburn_disc_track_lba_nwa() afterwards to learn the effective new
address which might be somewhat higher than set by parameter value.
Wrapper for: burn_write_opts_set_start_byte (if ever)
*/
void isoburn_write_opts_set_start_byte(struct burn_write_opts *opts,
off_t value);
#endif /* Libburn_obsoleted_on_its_way_ouT */