Some initial code for libisofs related wraps.

This commit is contained in:
Vreixo Formoso Lopes 2007-09-06 16:57:22 +00:00
parent fec717d2a1
commit 5ca9c9cef6

View File

@ -9,6 +9,16 @@
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:
@ -25,11 +35,21 @@
/* API function. See libisoburn.h
*/
int isoburn_update_iso_descriptors(struct burn_drive *drive)
int isoburn_activate_session(struct burn_drive *drive)
{
int ret;
struct isoburn *o;
/* >>> code <<< */
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;
}
@ -40,9 +60,26 @@ int isoburn_update_iso_descriptors(struct burn_drive *drive)
*/
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;
}
@ -53,9 +90,9 @@ int isoburn_new_rwopts(struct isoburn *o)
*/
int isoburn_free_rwopts(struct isoburn *o)
{
/* >>> code <<< */
free(o->target_ropts);
free(o->new_wopts);
return 1;
}
@ -67,12 +104,60 @@ int isoburn_free_rwopts(struct isoburn *o)
*/
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;
/* >>> code <<< */
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 */
// TODO where I get the struct burn_write_opts * from?
// why that function doesn't receive a struct isoburn
isoburn_write_opts_set_start_byte(XXXXXX, size);
} else if (!strncmp((char*)pvm->std_identifier, "CDXX1", 5)) {
/* empty image */
// TODO where I get the struct burn_write_opts * from?
// why that function doesn't receive a struct isoburn
isoburn_write_opts_set_start_byte(XXXXXX, (off_t) 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
@ -83,9 +168,11 @@ int isoburn_start_emulation(struct isoburn *o, int flag)
*/
int isoburn_invalidate_iso(struct isoburn *o, int flag)
{
/* >>> code <<< */
/*
* 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);
}