diff --git a/libisofs/eltorito.c b/libisofs/eltorito.c index f8e94c9..c7d95e3 100644 --- a/libisofs/eltorito.c +++ b/libisofs/eltorito.c @@ -617,12 +617,6 @@ void catalog_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, *ino_id = 0; } -static -char *catalog_get_name(IsoStream *stream) -{ - return strdup("El-Torito Boot Catalog"); -} - static void catalog_free(IsoStream *stream) { @@ -630,13 +624,14 @@ void catalog_free(IsoStream *stream) } IsoStreamIface catalog_stream_class = { + 0, + "boot", catalog_open, catalog_close, catalog_get_size, catalog_read, catalog_is_repeatable, catalog_get_id, - catalog_get_name, catalog_free }; diff --git a/libisofs/filesrc.c b/libisofs/filesrc.c index a4a2bfc..2c57ce5 100644 --- a/libisofs/filesrc.c +++ b/libisofs/filesrc.c @@ -15,6 +15,7 @@ #include #include +#include int iso_file_src_cmp(const void *n1, const void *n2) { @@ -243,7 +244,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer) Ecma119Image *t; IsoFileSrc *file; IsoFileSrc **filelist; - char *name; + char name[PATH_MAX]; char buffer[BLOCK_SIZE]; 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); res = filesrc_open(file); + iso_stream_get_file_name(file->stream, name); if (res < 0) { /* * UPS, very ugly error, the best we can do is just to write * 0's to image */ - name = iso_stream_get_name(file->stream); iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0); res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, res, "File \"%s\" can't be opened. Filling with 0s.", name); - free(name); if (res < 0) { return res; /* aborted due to error severity */ } @@ -289,12 +289,10 @@ int filesrc_writer_write_data(IsoImageWriter *writer) } continue; } else if (res > 1) { - name = iso_stream_get_name(file->stream); iso_report_errfile(name, ISO_FILE_CANT_WRITE, 0, 0); res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0, "Size of file \"%s\" has changed. It will be %s", name, (res == 2 ? "truncated" : "padded with 0's")); - free(name); if (res < 0) { filesrc_close(file); return res; /* aborted due to error severity */ @@ -302,9 +300,7 @@ int filesrc_writer_write_data(IsoImageWriter *writer) } #ifdef LIBISOFS_VERBOSE_DEBUG else { - name = iso_stream_get_name(file->stream); iso_msg_debug(t->image->id, "Writing file %s", name); - free(name); } #endif @@ -328,7 +324,6 @@ int filesrc_writer_write_data(IsoImageWriter *writer) if (b < nblocks) { /* 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); if (res < 0) { /* error */ @@ -339,7 +334,6 @@ int filesrc_writer_write_data(IsoImageWriter *writer) res = iso_msg_submit(t->image->id, ISO_FILE_CANT_WRITE, 0, "Premature end of file %s.", name); } - free(name); if (res < 0) { return res; /* aborted due error severity */ diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index d7b5040..2531f35 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -675,6 +675,18 @@ extern ino_t serial_id; */ 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. * @@ -727,14 +739,6 @@ struct IsoStream_Iface void (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_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. * Use iso_stream_unref() instead. @@ -3202,17 +3206,6 @@ int iso_stream_is_repeatable(IsoStream *stream); */ void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_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 ********************/ diff --git a/libisofs/stream.c b/libisofs/stream.c index 710ed8f..aa84208 100644 --- a/libisofs/stream.c +++ b/libisofs/stream.c @@ -13,6 +13,7 @@ #include #include +#include ino_t 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; } -static -char *fsrc_get_name(IsoStream *stream) -{ - FSrcStreamData *data; - data = (FSrcStreamData*)stream->data; - return iso_file_source_get_path(data->src); -} - static void fsrc_free(IsoStream *stream) { @@ -141,13 +134,14 @@ void fsrc_free(IsoStream *stream) } IsoStreamIface fsrc_stream_class = { + 0, + "fsrc", fsrc_open, fsrc_close, fsrc_get_size, fsrc_read, fsrc_is_repeatable, fsrc_get_id, - fsrc_get_name, 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; } -static -char *mem_get_name(IsoStream *stream) -{ - return strdup("[MEMORY SOURCE]"); -} - static void mem_free(IsoStream *stream) { @@ -327,13 +315,14 @@ void mem_free(IsoStream *stream) } IsoStreamIface mem_stream_class = { + 0, + "mem ", mem_open, mem_close, mem_get_size, mem_read, mem_is_repeatable, mem_get_id, - mem_get_name, 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); } -inline -char *iso_stream_get_name(IsoStream *stream) +void iso_stream_get_file_name(IsoStream *stream, char *name) { - 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"); + } } diff --git a/libisofs/stream.h b/libisofs/stream.h index eb12cd9..804faf1 100644 --- a/libisofs/stream.h +++ b/libisofs/stream.h @@ -13,12 +13,12 @@ */ #include "fsource.h" -/* TODO consider removing this header */ - -/* - * Some functions here will be moved to libisofs.h when we expose - * Streams. +/** + * Get an identifier for the file of the source, for debug purposes + * @param name + * Should provide at least PATH_MAX bytes */ +void iso_stream_get_file_name(IsoStream *stream, char *name); /** * Create a stream to read from a IsoFileSource.