Initial structure for ECMA-119 writer.

This commit is contained in:
Vreixo Formoso 2007-12-17 23:22:19 +01:00
parent 159b775d22
commit 5e2de57aa9
7 changed files with 139 additions and 25 deletions

View File

@ -95,7 +95,7 @@ int main(int argc, char **argv)
ecma119->image = image;
/* create low level tree */
result = ecma119_tree_create(ecma119, iso_image_get_root(image));
result = ecma119_tree_create(ecma119);
if (result < 0) {
printf ("Error creating ecma-119 tree: %d\n", result);
return 1;

View File

@ -19,11 +19,87 @@
#include <stdlib.h>
#include <time.h>
static
void ecma119_image_free(Ecma119Image *t)
{
size_t i;
ecma119_node_free(t->root);
iso_image_unref(t->image);
iso_file_src_free(t);
for (i = 0; i < t->nwriters; ++i) {
IsoImageWriter *writer = t->writers[i];
writer->free_data(writer);
free(writer);
}
free(t->writers);
free(t);
}
static
int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
{
//TODO to implement
return -1;
}
static
int ecma119_writer_write_vol_desc(IsoImageWriter *writer)
{
//TODO to implement
return -1;
}
static
int ecma119_writer_write_data(IsoImageWriter *writer)
{
//TODO to implement
return -1;
}
static
int ecma119_writer_free_data(IsoImageWriter *writer)
{
//TODO to implement
return -1;
}
int ecma119_writer_create(Ecma119Image *target)
{
int ret;
IsoImageWriter *writer;
writer = malloc(sizeof(IsoImageWriter));
if (writer == NULL) {
return ISO_MEM_ERROR;
}
writer->compute_data_blocks = ecma119_writer_compute_data_blocks;
writer->write_vol_desc = ecma119_writer_write_vol_desc;
writer->write_data = ecma119_writer_write_data;
writer->free_data = ecma119_writer_free_data;
writer->data = NULL;
writer->target = target;
/* add this writer to image */
target->writers[target->nwriters++] = writer;
ret = ecma119_tree_create(target);
if (ret < 0) {
return ret;
}
/* we need the volume descriptor */
target->curblock++;
return ISO_SUCCESS;
}
static
int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
Ecma119Image **img)
{
int ret;
int ret, i;
Ecma119Image *target;
/* 1. Allocate target and copy opts there */
@ -33,16 +109,12 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
}
target->image = src;
iso_image_ref(src);
target->iso_level = opts->level;
target->now = time(NULL);
ret = ecma119_tree_create(target, src->root);
if (ret < 0) {
// TODO free image data
return ret;
}
/*
* 2. Based on those options, create needed writers: iso, joliet...
* Each writer inits its structures and stores needed info into
@ -51,6 +123,25 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
* current block.
* Finally, create Writer for files.
*/
target->curblock = 16;
/* the number of writers is dependent of the extensions */
target->writers = malloc(2 * sizeof(void*));
if (target->writers == NULL) {
iso_image_unref(src);
free(target);
return ISO_MEM_ERROR;
}
/* create writer for ECMA-119 structure */
ret = ecma119_writer_create(target);
if (ret < 0) {
goto target_cleanup;
}
/* Volume Descriptor Set Terminator */
target->curblock++;
/*
* 3.
@ -58,12 +149,24 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
* That function computes the size needed by its structures and
* increments image current block propertly.
*/
for (i = 0; i < target->nwriters; ++i) {
IsoImageWriter *writer = target->writers[i];
ret = writer->compute_data_blocks(writer);
if (ret < 0) {
goto target_cleanup;
}
}
/* 4. Start writting thread */
*img = target;
return ISO_SUCCESS;
target_cleanup:;
ecma119_image_free(target);
return ret;
}
static int
@ -83,12 +186,7 @@ bs_get_size(struct burn_source *bs)
static void
bs_free_data(struct burn_source *bs)
{
Ecma119Image *t = (Ecma119Image*)bs->data;
ecma119_node_free(t->root);
iso_image_unref(t->image);
iso_file_src_free(t);
free(t);
ecma119_image_free((Ecma119Image*)bs->data);
}
static

View File

@ -11,6 +11,8 @@
#include "libisofs.h"
#include <stdint.h>
typedef struct ecma119_image Ecma119Image;
typedef struct ecma119_node Ecma119Node;
typedef struct Iso_File_Src IsoFileSrc;
@ -20,8 +22,6 @@ struct ecma119_image {
IsoImage *image;
Ecma119Node *root;
//int volnum;
unsigned int iso_level:2;
// int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */
@ -47,6 +47,15 @@ struct ecma119_image {
* includes the current volume. */
//uint32_t vol_space_size;
/*
* Block being processed, either during image writing or structure
* size calculation.
*/
uint32_t curblock;
size_t nwriters;
IsoImageWriter **writers;
/* tree of files sources */
void *file_srcs;
int file_count;

View File

@ -13,6 +13,7 @@
#include "util.h"
#include "filesrc.h"
#include "messages.h"
#include "image.h"
#include <stdlib.h>
#include <string.h>
@ -132,6 +133,9 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node)
void ecma119_node_free(Ecma119Node *node)
{
if (node == NULL) {
return;
}
if (node->type == ECMA119_DIR) {
int i;
for (i = 0; i < node->info.dir.nchildren; i++) {
@ -492,12 +496,12 @@ int mangle_tree(Ecma119Image *img)
}
int ecma119_tree_create(Ecma119Image *img, IsoDir *iso)
int ecma119_tree_create(Ecma119Image *img)
{
int ret;
Ecma119Node *root;
ret = create_tree(img, (IsoNode*)iso, &root, 1, 0);
ret = create_tree(img, (IsoNode*)img->image->root, &root, 1, 0);
if (ret < 0) {
return ret;
}

View File

@ -55,7 +55,7 @@ struct ecma119_node
/**
*
*/
int ecma119_tree_create(Ecma119Image *img, IsoDir *iso);
int ecma119_tree_create(Ecma119Image *img);
/**
* Free an Ecma119Node, and its children if node is a dir

View File

@ -115,5 +115,7 @@ void free_node(void *nodep)
void iso_file_src_free(Ecma119Image *img)
{
tdestroy(img->file_srcs, free_node);
if (img->file_srcs != NULL) {
tdestroy(img->file_srcs, free_node);
}
}

View File

@ -17,15 +17,16 @@ struct Iso_Image_Writer
*/
int (*compute_data_blocks)(IsoImageWriter *writer);
int (*write_vol_desc)(IsoImageWriter *writer, int fd);
int (*write_vol_desc)(IsoImageWriter *writer);
int (*write_data)(IsoImageWriter *writer, int fd);
int (*write_data)(IsoImageWriter *writer);
int (*free_data)(IsoImageWriter *writer);
void *data;
Ecma119Image *image;
IsoImageWriter *next;
Ecma119Image *target;
};
int ecma119_writer_create(Ecma119Image *target);
#endif /*LIBISO_IMAGE_WRITER_H_*/