Remove IsoStream->get_name(), add version and type fields instead.

This commit is contained in:
Vreixo Formoso 2008-02-24 16:58:07 +01:00
parent 811743a147
commit 37f69d5360
5 changed files with 41 additions and 59 deletions

View File

@ -617,12 +617,6 @@ void catalog_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
*ino_id = 0; *ino_id = 0;
} }
static
char *catalog_get_name(IsoStream *stream)
{
return strdup("El-Torito Boot Catalog");
}
static static
void catalog_free(IsoStream *stream) void catalog_free(IsoStream *stream)
{ {
@ -630,13 +624,14 @@ void catalog_free(IsoStream *stream)
} }
IsoStreamIface catalog_stream_class = { IsoStreamIface catalog_stream_class = {
0,
"boot",
catalog_open, catalog_open,
catalog_close, catalog_close,
catalog_get_size, catalog_get_size,
catalog_read, catalog_read,
catalog_is_repeatable, catalog_is_repeatable,
catalog_get_id, catalog_get_id,
catalog_get_name,
catalog_free catalog_free
}; };

View File

@ -15,6 +15,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
int iso_file_src_cmp(const void *n1, const void *n2) int iso_file_src_cmp(const void *n1, const void *n2)
{ {
@ -243,7 +244,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
Ecma119Image *t; Ecma119Image *t;
IsoFileSrc *file; IsoFileSrc *file;
IsoFileSrc **filelist; IsoFileSrc **filelist;
char *name; char name[PATH_MAX];
char buffer[BLOCK_SIZE]; char buffer[BLOCK_SIZE];
if (writer == NULL) { if (writer == NULL) {
@ -266,16 +267,15 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
uint32_t nblocks = DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE); uint32_t nblocks = DIV_UP(iso_file_src_get_size(file), BLOCK_SIZE);
res = filesrc_open(file); res = filesrc_open(file);
iso_stream_get_file_name(file->stream, name);
if (res < 0) { if (res < 0) {
/* /*
* UPS, very ugly error, the best we can do is just to write * UPS, very ugly error, the best we can do is just to write
* 0's to image * 0's to image
*/ */
name = iso_stream_get_name(file->stream);
iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0); iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0);
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, res, res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, res,
"File \"%s\" can't be opened. Filling with 0s.", name); "File \"%s\" can't be opened. Filling with 0s.", name);
free(name);
if (res < 0) { if (res < 0) {
return res; /* aborted due to error severity */ return res; /* aborted due to error severity */
} }
@ -289,12 +289,10 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
} }
continue; continue;
} else if (res > 1) { } else if (res > 1) {
name = iso_stream_get_name(file->stream);
iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0); iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0);
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0, res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0,
"Size of file \"%s\" has changed. It will be %s", name, "Size of file \"%s\" has changed. It will be %s", name,
(res == 2 ? "truncated" : "padded with 0's")); (res == 2 ? "truncated" : "padded with 0's"));
free(name);
if (res < 0) { if (res < 0) {
filesrc_close(file); filesrc_close(file);
return res; /* aborted due to error severity */ return res; /* aborted due to error severity */
@ -302,9 +300,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
} }
#ifdef LIBISOFS_VERBOSE_DEBUG #ifdef LIBISOFS_VERBOSE_DEBUG
else { else {
name = iso_stream_get_name(file->stream);
iso_msg_debug(t->image->id, "Writing file %s", name); iso_msg_debug(t->image->id, "Writing file %s", name);
free(name);
} }
#endif #endif
@ -328,7 +324,6 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
if (b < nblocks) { if (b < nblocks) {
/* premature end of file, due to error or eof */ /* premature end of file, due to error or eof */
char *name = iso_stream_get_name(file->stream);
iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0); iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0);
if (res < 0) { if (res < 0) {
/* error */ /* error */
@ -339,7 +334,6 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0, res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0,
"Premature end of file %s.", name); "Premature end of file %s.", name);
} }
free(name);
if (res < 0) { if (res < 0) {
return res; /* aborted due error severity */ return res; /* aborted due error severity */

View File

@ -675,6 +675,18 @@ extern ino_t serial_id;
*/ */
struct IsoStream_Iface struct IsoStream_Iface
{ {
/* reserved for future usage, set to 0 */
int version;
/**
* Type of Stream.
* "fsrc" -> Read from file source
* "mem " -> Read from memory
* "boot" -> Boot catalog
* "user" -> User supplied stream
*/
char type[4];
/** /**
* Opens the stream. * Opens the stream.
* *
@ -727,14 +739,6 @@ struct IsoStream_Iface
void (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, void (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
ino_t *ino_id); ino_t *ino_id);
/**
* Get a name that identifies the Stream contents. It is used only for
* informational or debug purposes, so you can return anything you
* consider suitable for identification of the source, such as the path
* of the file on disc.
*/
char *(*get_name)(IsoStream *stream);
/** /**
* Free implementation specific data. Should never be called by user. * Free implementation specific data. Should never be called by user.
* Use iso_stream_unref() instead. * Use iso_stream_unref() instead.
@ -3203,17 +3207,6 @@ int iso_stream_is_repeatable(IsoStream *stream);
void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
ino_t *ino_id); ino_t *ino_id);
/**
* Get a name that identifies the Stream contents. It is used only for
* informational or debug purposes, so you can return anything you
* consider suitable for identification of the source, such as the path
* of the file on disc.
* Returned string should be freed when no more needed.
*
* @since 0.6.4
*/
char *iso_stream_get_name(IsoStream *stream);
/************ Error codes and return values for libisofs ********************/ /************ Error codes and return values for libisofs ********************/
/** successfully execution */ /** successfully execution */

View File

@ -13,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
ino_t serial_id = (ino_t)1; ino_t serial_id = (ino_t)1;
ino_t mem_serial_id = (ino_t)1; ino_t mem_serial_id = (ino_t)1;
@ -123,14 +124,6 @@ void fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
*ino_id = data->ino_id; *ino_id = data->ino_id;
} }
static
char *fsrc_get_name(IsoStream *stream)
{
FSrcStreamData *data;
data = (FSrcStreamData*)stream->data;
return iso_file_source_get_path(data->src);
}
static static
void fsrc_free(IsoStream *stream) void fsrc_free(IsoStream *stream)
{ {
@ -141,13 +134,14 @@ void fsrc_free(IsoStream *stream)
} }
IsoStreamIface fsrc_stream_class = { IsoStreamIface fsrc_stream_class = {
0,
"fsrc",
fsrc_open, fsrc_open,
fsrc_close, fsrc_close,
fsrc_get_size, fsrc_get_size,
fsrc_read, fsrc_read,
fsrc_is_repeatable, fsrc_is_repeatable,
fsrc_get_id, fsrc_get_id,
fsrc_get_name,
fsrc_free fsrc_free
}; };
@ -311,12 +305,6 @@ void mem_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
*ino_id = data->ino_id; *ino_id = data->ino_id;
} }
static
char *mem_get_name(IsoStream *stream)
{
return strdup("[MEMORY SOURCE]");
}
static static
void mem_free(IsoStream *stream) void mem_free(IsoStream *stream)
{ {
@ -327,13 +315,14 @@ void mem_free(IsoStream *stream)
} }
IsoStreamIface mem_stream_class = { IsoStreamIface mem_stream_class = {
0,
"mem ",
mem_open, mem_open,
mem_close, mem_close,
mem_get_size, mem_get_size,
mem_read, mem_read,
mem_is_repeatable, mem_is_repeatable,
mem_get_id, mem_get_id,
mem_get_name,
mem_free mem_free
}; };
@ -427,8 +416,19 @@ void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
stream->class->get_id(stream, fs_id, dev_id, ino_id); stream->class->get_id(stream, fs_id, dev_id, ino_id);
} }
inline void iso_stream_get_file_name(IsoStream *stream, char *name)
char *iso_stream_get_name(IsoStream *stream)
{ {
return stream->class->get_name(stream); char *type = stream->class->type;
if (!strncmp(type, "fsrc", 4)) {
FSrcStreamData *data = stream->data;
char *path = iso_file_source_get_path(data->src);
strncpy(name, path, PATH_MAX);
} else if (!strncmp(type, "boot", 4)) {
strcpy(name, "BOOT CATALOG");
} else if (!strncmp(type, "mem ", 4)) {
strcpy(name, "MEM SOURCE");
} else {
strcpy(name, "UNKNOWN SOURCE");
}
} }

View File

@ -13,12 +13,12 @@
*/ */
#include "fsource.h" #include "fsource.h"
/* TODO consider removing this header */ /**
* Get an identifier for the file of the source, for debug purposes
/* * @param name
* Some functions here will be moved to libisofs.h when we expose * Should provide at least PATH_MAX bytes
* Streams.
*/ */
void iso_stream_get_file_name(IsoStream *stream, char *name);
/** /**
* Create a stream to read from a IsoFileSource. * Create a stream to read from a IsoFileSource.