You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

173 lines
4.6 KiB

/*
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 "../libisofs/libisofs.h"
#include "../libburn/libburn.h"
#include "isoburn.h"
// TODO this are libisofs internals, should then be imported here?
#include "../libisofs/util.h"
#include "../libisofs/ecma119.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 .
*/
/* 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 unsupported image type, maybe not image or damaged image
// should this be an error?
return -2;
}
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);
} else if (!strncmp((char*)pvm->std_identifier, "CDXX1", 5)) {
/* empty image */
isoburn_set_start_byte(o, (off_t) 0, 0);
} else {
// TODO not valid iso image
// should this be an error?
return -2;
}
return 1;
}
// TODO why read is needed? can't I assume 64k are already cached?
// TODO can I assume isoburn_start_emulation was already called and
// disc contains a valid image?
// TODO why "The result shall especially keep libisofs from accepting the
// media image as ISO filesystem"?
/** Reads, 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 libisofs 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);
}