2007-12-15 12:13:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Vreixo Formoso
|
2008-08-17 19:59:48 +00:00
|
|
|
*
|
|
|
|
* This file is part of the libisofs project; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2 as
|
2007-12-15 12:13:49 +00:00
|
|
|
* published by the Free Software Foundation. See COPYING file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "filesrc.h"
|
|
|
|
#include "node.h"
|
2007-12-19 23:25:25 +00:00
|
|
|
#include "util.h"
|
2007-12-20 21:17:18 +00:00
|
|
|
#include "writer.h"
|
|
|
|
#include "messages.h"
|
2007-12-30 21:04:41 +00:00
|
|
|
#include "image.h"
|
2007-12-15 12:13:49 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2007-12-20 21:17:18 +00:00
|
|
|
#include <string.h>
|
2008-02-24 15:58:07 +00:00
|
|
|
#include <limits.h>
|
2007-12-16 18:10:47 +00:00
|
|
|
|
2007-12-19 23:25:25 +00:00
|
|
|
int iso_file_src_cmp(const void *n1, const void *n2)
|
2007-12-15 12:13:49 +00:00
|
|
|
{
|
|
|
|
const IsoFileSrc *f1, *f2;
|
2007-12-18 19:46:28 +00:00
|
|
|
unsigned int fs_id1, fs_id2;
|
|
|
|
dev_t dev_id1, dev_id2;
|
|
|
|
ino_t ino_id1, ino_id2;
|
2009-03-07 07:28:35 +00:00
|
|
|
off_t size1, size2;
|
2007-12-15 12:13:49 +00:00
|
|
|
f1 = (const IsoFileSrc *)n1;
|
|
|
|
f2 = (const IsoFileSrc *)n2;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-10 16:56:39 +00:00
|
|
|
iso_stream_get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1);
|
|
|
|
iso_stream_get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2);
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-18 19:46:28 +00:00
|
|
|
if (fs_id1 < fs_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return -1;
|
2007-12-18 19:46:28 +00:00
|
|
|
} else if (fs_id1 > fs_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* files belong to the same fs */
|
2007-12-18 19:46:28 +00:00
|
|
|
if (dev_id1 > dev_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return -1;
|
2007-12-18 19:46:28 +00:00
|
|
|
} else if (dev_id1 < dev_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return 1;
|
2009-03-07 07:28:35 +00:00
|
|
|
} else if (ino_id1 < ino_id2) {
|
2009-03-10 14:34:09 +00:00
|
|
|
return -1;
|
|
|
|
} else if (ino_id1 > ino_id2) {
|
2009-03-07 07:28:35 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
size1 = iso_stream_get_size(f1->stream);
|
|
|
|
size2 = iso_stream_get_size(f2->stream);
|
|
|
|
if (size1 < size2) {
|
|
|
|
return -1;
|
|
|
|
} else if (size1 > size2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2007-12-15 12:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
|
|
|
|
{
|
2008-01-10 16:56:39 +00:00
|
|
|
int ret;
|
2007-12-15 12:13:49 +00:00
|
|
|
IsoFileSrc *fsrc;
|
|
|
|
unsigned int fs_id;
|
|
|
|
dev_t dev_id;
|
|
|
|
ino_t ino_id;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-15 12:13:49 +00:00
|
|
|
if (img == NULL || file == NULL || src == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-10 16:56:39 +00:00
|
|
|
iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id);
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-08-19 00:45:20 +00:00
|
|
|
fsrc = calloc(1, sizeof(IsoFileSrc));
|
2008-01-10 16:56:39 +00:00
|
|
|
if (fsrc == NULL) {
|
2008-01-20 21:28:27 +00:00
|
|
|
return ISO_OUT_OF_MEM;
|
2008-01-10 16:56:39 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-10 16:56:39 +00:00
|
|
|
/* fill key and other atts */
|
2008-08-19 00:45:20 +00:00
|
|
|
fsrc->prev_img = file->from_old_session;
|
2008-08-19 18:54:27 +00:00
|
|
|
if (file->from_old_session && img->appendable) {
|
|
|
|
/*
|
|
|
|
* On multisession discs we keep file sections from old image.
|
|
|
|
*/
|
2008-08-19 00:45:20 +00:00
|
|
|
int ret = iso_file_get_old_image_sections(file, &(fsrc->nsections),
|
|
|
|
&(fsrc->sections), 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(fsrc);
|
|
|
|
return ISO_OUT_OF_MEM;
|
|
|
|
}
|
2008-08-19 18:54:27 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For new files, or for image copy, we compute our own file sections.
|
|
|
|
* Block and size of each section will be filled later.
|
|
|
|
*/
|
|
|
|
off_t section_size = iso_stream_get_size(file->stream);
|
|
|
|
if (section_size > (off_t) MAX_ISO_FILE_SECTION_SIZE) {
|
|
|
|
fsrc->nsections = DIV_UP(section_size - (off_t) MAX_ISO_FILE_SECTION_SIZE,
|
|
|
|
(off_t)ISO_EXTENT_SIZE) + 1;
|
|
|
|
} else {
|
|
|
|
fsrc->nsections = 1;
|
|
|
|
}
|
|
|
|
fsrc->sections = calloc(fsrc->nsections, sizeof(struct iso_file_section));
|
2008-08-19 00:45:20 +00:00
|
|
|
}
|
2008-01-10 16:56:39 +00:00
|
|
|
fsrc->sort_weight = file->sort_weight;
|
|
|
|
fsrc->stream = file->stream;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-10 16:56:39 +00:00
|
|
|
/* insert the filesrc in the tree */
|
|
|
|
ret = iso_rbtree_insert(img->files, fsrc, (void**)src);
|
|
|
|
if (ret <= 0) {
|
2008-08-19 00:45:20 +00:00
|
|
|
free(fsrc->sections);
|
2008-01-10 16:56:39 +00:00
|
|
|
free(fsrc);
|
|
|
|
return ret;
|
2007-12-15 12:13:49 +00:00
|
|
|
}
|
2008-01-11 14:43:39 +00:00
|
|
|
iso_stream_ref(fsrc->stream);
|
2007-12-15 12:13:49 +00:00
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-01-10 17:53:39 +00:00
|
|
|
/**
|
|
|
|
* Add a given IsoFileSrc to the given image target.
|
2008-08-17 19:59:48 +00:00
|
|
|
*
|
|
|
|
* The IsoFileSrc will be cached in a tree to prevent the same file for
|
2008-01-10 17:53:39 +00:00
|
|
|
* being written several times to image. If you call again this function
|
|
|
|
* with a node that refers to the same source file, the previously
|
|
|
|
* created one will be returned.
|
2008-08-17 19:59:48 +00:00
|
|
|
*
|
2008-01-10 17:53:39 +00:00
|
|
|
* @param img
|
|
|
|
* The image where this file is to be written
|
|
|
|
* @param new
|
|
|
|
* The IsoFileSrc to add
|
|
|
|
* @param src
|
|
|
|
* Will be filled with a pointer to the IsoFileSrc really present in
|
|
|
|
* the tree. It could be different than new if the same file already
|
2008-08-17 19:59:48 +00:00
|
|
|
* exists in the tree.
|
2008-01-10 17:53:39 +00:00
|
|
|
* @return
|
|
|
|
* 1 on success, 0 if file already exists on tree, < 0 error
|
|
|
|
*/
|
|
|
|
int iso_file_src_add(Ecma119Image *img, IsoFileSrc *new, IsoFileSrc **src)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (img == NULL || new == NULL || src == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2008-08-17 19:59:48 +00:00
|
|
|
|
2008-01-10 17:53:39 +00:00
|
|
|
/* insert the filesrc in the tree */
|
|
|
|
ret = iso_rbtree_insert(img->files, new, (void**)src);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-12-19 23:25:25 +00:00
|
|
|
void iso_file_src_free(void *node)
|
2007-12-16 18:10:47 +00:00
|
|
|
{
|
2008-01-11 14:43:39 +00:00
|
|
|
iso_stream_unref(((IsoFileSrc*)node)->stream);
|
2008-08-19 00:45:20 +00:00
|
|
|
free(((IsoFileSrc*)node)->sections);
|
2007-12-19 23:25:25 +00:00
|
|
|
free(node);
|
2007-12-16 18:10:47 +00:00
|
|
|
}
|
2007-12-18 19:46:28 +00:00
|
|
|
|
|
|
|
off_t iso_file_src_get_size(IsoFileSrc *file)
|
|
|
|
{
|
2007-12-20 19:58:03 +00:00
|
|
|
return iso_stream_get_size(file->stream);
|
2007-12-18 19:46:28 +00:00
|
|
|
}
|
2007-12-20 21:17:18 +00:00
|
|
|
|
2007-12-28 21:10:17 +00:00
|
|
|
static int cmp_by_weight(const void *f1, const void *f2)
|
2007-12-20 21:17:18 +00:00
|
|
|
{
|
|
|
|
IsoFileSrc *f = *((IsoFileSrc**)f1);
|
|
|
|
IsoFileSrc *g = *((IsoFileSrc**)f2);
|
|
|
|
/* higher weighted first */
|
|
|
|
return g->sort_weight - f->sort_weight;
|
|
|
|
}
|
|
|
|
|
2008-01-04 22:54:31 +00:00
|
|
|
static
|
|
|
|
int is_ms_file(void *arg)
|
|
|
|
{
|
|
|
|
IsoFileSrc *f = (IsoFileSrc *)arg;
|
|
|
|
return f->prev_img ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
static
|
|
|
|
int filesrc_writer_compute_data_blocks(IsoImageWriter *writer)
|
|
|
|
{
|
|
|
|
size_t i, size;
|
|
|
|
Ecma119Image *t;
|
|
|
|
IsoFileSrc **filelist;
|
2008-01-04 22:54:31 +00:00
|
|
|
int (*inc_item)(void *);
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
if (writer == NULL) {
|
2008-01-23 19:28:57 +00:00
|
|
|
return ISO_ASSERT_FAILURE;
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
t = writer->target;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-04 22:54:31 +00:00
|
|
|
/* on appendable images, ms files shouldn't be included */
|
|
|
|
if (t->appendable) {
|
|
|
|
inc_item = is_ms_file;
|
|
|
|
} else {
|
|
|
|
inc_item = NULL;
|
|
|
|
}
|
2008-08-17 19:59:48 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* store the filesrcs in a array */
|
2008-01-04 22:54:31 +00:00
|
|
|
filelist = (IsoFileSrc**)iso_rbtree_to_array(t->files, inc_item, &size);
|
2007-12-20 21:17:18 +00:00
|
|
|
if (filelist == NULL) {
|
2008-01-20 21:28:27 +00:00
|
|
|
return ISO_OUT_OF_MEM;
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
|
|
|
/* sort files by weight, if needed */
|
2007-12-20 21:17:18 +00:00
|
|
|
if (t->sort_files) {
|
2008-01-04 09:11:25 +00:00
|
|
|
qsort(filelist, size, sizeof(void*), cmp_by_weight);
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* fill block value */
|
|
|
|
for (i = 0; i < size; ++i) {
|
2008-08-19 00:45:20 +00:00
|
|
|
int extent = 0;
|
2007-12-20 21:17:18 +00:00
|
|
|
IsoFileSrc *file = filelist[i];
|
2008-08-19 00:45:20 +00:00
|
|
|
|
|
|
|
off_t section_size = iso_stream_get_size(file->stream);
|
|
|
|
for (extent = 0; extent < file->nsections - 1; ++extent) {
|
2008-08-19 17:44:47 +00:00
|
|
|
file->sections[extent].block = t->curblock + extent *
|
|
|
|
(ISO_EXTENT_SIZE / BLOCK_SIZE);
|
|
|
|
file->sections[extent].size = ISO_EXTENT_SIZE;
|
|
|
|
section_size -= (off_t) ISO_EXTENT_SIZE;
|
2008-08-19 00:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* final section
|
|
|
|
*/
|
2008-08-19 17:44:47 +00:00
|
|
|
file->sections[extent].block = t->curblock + extent * (ISO_EXTENT_SIZE / BLOCK_SIZE);
|
2008-08-19 18:54:27 +00:00
|
|
|
file->sections[extent].size = (uint32_t)section_size;
|
2008-08-19 00:45:20 +00:00
|
|
|
|
2008-01-19 12:45:56 +00:00
|
|
|
t->curblock += DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE);
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* the list is only needed by this writer, store locally */
|
|
|
|
writer->data = filelist;
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int filesrc_writer_write_vol_desc(IsoImageWriter *writer)
|
|
|
|
{
|
|
|
|
/* nothing needed */
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a file, i.e., its Stream */
|
|
|
|
static inline
|
|
|
|
int filesrc_open(IsoFileSrc *file)
|
|
|
|
{
|
|
|
|
return iso_stream_open(file->stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
int filesrc_close(IsoFileSrc *file)
|
|
|
|
{
|
|
|
|
return iso_stream_close(file->stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return
|
|
|
|
* 1 ok, 0 EOF, < 0 error
|
|
|
|
*/
|
2007-12-28 21:10:17 +00:00
|
|
|
static
|
2007-12-20 21:17:18 +00:00
|
|
|
int filesrc_read(IsoFileSrc *file, char *buf, size_t count)
|
|
|
|
{
|
|
|
|
size_t bytes = 0;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* loop to ensure the full buffer is filled */
|
|
|
|
do {
|
|
|
|
ssize_t result;
|
|
|
|
result = iso_stream_read(file->stream, buf + bytes, count - bytes);
|
2007-12-28 21:10:17 +00:00
|
|
|
if (result < 0) {
|
|
|
|
/* fill buffer with 0s and return */
|
2007-12-20 21:17:18 +00:00
|
|
|
memset(buf + bytes, 0, count - bytes);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (result == 0)
|
|
|
|
break;
|
2007-12-28 21:10:17 +00:00
|
|
|
bytes += result;
|
2007-12-20 21:17:18 +00:00
|
|
|
} while (bytes < count);
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
if (bytes < count) {
|
|
|
|
/* eof */
|
|
|
|
memset(buf + bytes, 0, count - bytes);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int filesrc_writer_write_data(IsoImageWriter *writer)
|
|
|
|
{
|
|
|
|
int res;
|
2008-01-04 22:54:31 +00:00
|
|
|
size_t i, b;
|
2007-12-20 21:17:18 +00:00
|
|
|
Ecma119Image *t;
|
2008-01-04 22:54:31 +00:00
|
|
|
IsoFileSrc *file;
|
2007-12-20 21:17:18 +00:00
|
|
|
IsoFileSrc **filelist;
|
2008-02-24 15:58:07 +00:00
|
|
|
char name[PATH_MAX];
|
2007-12-20 21:17:18 +00:00
|
|
|
char buffer[BLOCK_SIZE];
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
if (writer == NULL) {
|
2008-01-23 19:28:57 +00:00
|
|
|
return ISO_ASSERT_FAILURE;
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
t = writer->target;
|
|
|
|
filelist = writer->data;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-19 01:48:12 +00:00
|
|
|
iso_msg_debug(t->image->id, "Writing Files...");
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-04 22:54:31 +00:00
|
|
|
i = 0;
|
|
|
|
while ((file = filelist[i++]) != NULL) {
|
2007-12-20 21:17:18 +00:00
|
|
|
|
2008-01-19 12:45:56 +00:00
|
|
|
uint32_t nblocks = DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE);
|
2007-12-20 21:17:18 +00:00
|
|
|
|
|
|
|
res = filesrc_open(file);
|
2008-02-24 15:58:07 +00:00
|
|
|
iso_stream_get_file_name(file->stream, name);
|
2007-12-20 21:17:18 +00:00
|
|
|
if (res < 0) {
|
2008-08-17 19:59:48 +00:00
|
|
|
/*
|
2007-12-20 21:17:18 +00:00
|
|
|
* UPS, very ugly error, the best we can do is just to write
|
|
|
|
* 0's to image
|
|
|
|
*/
|
2008-02-22 18:39:09 +00:00
|
|
|
iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0);
|
2008-08-17 19:59:48 +00:00
|
|
|
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, res,
|
2008-01-23 19:28:57 +00:00
|
|
|
"File \"%s\" can't be opened. Filling with 0s.", name);
|
2008-01-22 20:12:27 +00:00
|
|
|
if (res < 0) {
|
|
|
|
return res; /* aborted due to error severity */
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
memset(buffer, 0, BLOCK_SIZE);
|
|
|
|
for (b = 0; b < nblocks; ++b) {
|
2007-12-20 21:17:18 +00:00
|
|
|
res = iso_write(t, buffer, BLOCK_SIZE);
|
|
|
|
if (res < 0) {
|
|
|
|
/* ko, writer error, we need to go out! */
|
|
|
|
return res;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
}
|
|
|
|
continue;
|
2008-02-06 17:04:51 +00:00
|
|
|
} else if (res > 1) {
|
2008-02-22 18:39:09 +00:00
|
|
|
iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0);
|
2008-08-17 19:59:48 +00:00
|
|
|
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0,
|
2008-02-06 17:04:51 +00:00
|
|
|
"Size of file \"%s\" has changed. It will be %s", name,
|
|
|
|
(res == 2 ? "truncated" : "padded with 0's"));
|
|
|
|
if (res < 0) {
|
|
|
|
filesrc_close(file);
|
|
|
|
return res; /* aborted due to error severity */
|
|
|
|
}
|
2008-02-09 16:15:58 +00:00
|
|
|
}
|
|
|
|
#ifdef LIBISOFS_VERBOSE_DEBUG
|
|
|
|
else {
|
|
|
|
iso_msg_debug(t->image->id, "Writing file %s", name);
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2008-02-09 16:15:58 +00:00
|
|
|
#endif
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* write file contents to image */
|
|
|
|
for (b = 0; b < nblocks; ++b) {
|
|
|
|
int wres;
|
|
|
|
res = filesrc_read(file, buffer, BLOCK_SIZE);
|
2008-02-08 21:32:33 +00:00
|
|
|
if (res < 0) {
|
2008-02-08 09:31:09 +00:00
|
|
|
/* read error */
|
|
|
|
break;
|
|
|
|
}
|
2007-12-20 21:17:18 +00:00
|
|
|
wres = iso_write(t, buffer, BLOCK_SIZE);
|
|
|
|
if (wres < 0) {
|
|
|
|
/* ko, writer error, we need to go out! */
|
2008-02-04 00:17:33 +00:00
|
|
|
filesrc_close(file);
|
2007-12-20 21:17:18 +00:00
|
|
|
return wres;
|
|
|
|
}
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-02-04 00:17:33 +00:00
|
|
|
filesrc_close(file);
|
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
if (b < nblocks) {
|
|
|
|
/* premature end of file, due to error or eof */
|
2008-02-22 18:39:09 +00:00
|
|
|
iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0);
|
2007-12-20 21:17:18 +00:00
|
|
|
if (res < 0) {
|
|
|
|
/* error */
|
2008-01-22 20:36:24 +00:00
|
|
|
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, res,
|
2008-01-22 20:12:27 +00:00
|
|
|
"Read error in file %s.", name);
|
2007-12-20 21:17:18 +00:00
|
|
|
} else {
|
|
|
|
/* eof */
|
2008-01-22 20:36:24 +00:00
|
|
|
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0,
|
2007-12-29 00:58:42 +00:00
|
|
|
"Premature end of file %s.", name);
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-29 00:58:42 +00:00
|
|
|
|
2008-01-22 20:12:27 +00:00
|
|
|
if (res < 0) {
|
|
|
|
return res; /* aborted due error severity */
|
|
|
|
}
|
2008-08-17 19:59:48 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* fill with 0s */
|
2008-01-22 20:36:24 +00:00
|
|
|
iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0,
|
|
|
|
"Filling with 0");
|
2007-12-20 21:17:18 +00:00
|
|
|
memset(buffer, 0, BLOCK_SIZE);
|
|
|
|
while (b++ < nblocks) {
|
|
|
|
res = iso_write(t, buffer, BLOCK_SIZE);
|
|
|
|
if (res < 0) {
|
|
|
|
/* ko, writer error, we need to go out! */
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int filesrc_writer_free_data(IsoImageWriter *writer)
|
|
|
|
{
|
|
|
|
/* free the list of files (contents are free together with the tree) */
|
|
|
|
free(writer->data);
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iso_file_src_writer_create(Ecma119Image *target)
|
|
|
|
{
|
|
|
|
IsoImageWriter *writer;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
writer = malloc(sizeof(IsoImageWriter));
|
|
|
|
if (writer == NULL) {
|
2008-01-23 19:28:57 +00:00
|
|
|
return ISO_ASSERT_FAILURE;
|
2007-12-20 21:17:18 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
writer->compute_data_blocks = filesrc_writer_compute_data_blocks;
|
|
|
|
writer->write_vol_desc = filesrc_writer_write_vol_desc;
|
|
|
|
writer->write_data = filesrc_writer_write_data;
|
|
|
|
writer->free_data = filesrc_writer_free_data;
|
|
|
|
writer->data = NULL;
|
|
|
|
writer->target = target;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-20 21:17:18 +00:00
|
|
|
/* add this writer to image */
|
|
|
|
target->writers[target->nwriters++] = writer;
|
|
|
|
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|