diff --git a/src/filesrc.c b/src/filesrc.c index 302e6c7..9d94b44 100644 --- a/src/filesrc.c +++ b/src/filesrc.c @@ -20,7 +20,6 @@ int iso_file_src_cmp(const void *n1, const void *n2) { const IsoFileSrc *f1, *f2; - int res; unsigned int fs_id1, fs_id2; dev_t dev_id1, dev_id2; ino_t ino_id1, ino_id2; @@ -28,10 +27,8 @@ int iso_file_src_cmp(const void *n1, const void *n2) f1 = (const IsoFileSrc *)n1; f2 = (const IsoFileSrc *)n2; - res = iso_stream_get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1); - res = iso_stream_get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2); - - //TODO take care about res <= 0 + iso_stream_get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1); + iso_stream_get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2); if (fs_id1 < fs_id2) { return -1; @@ -52,7 +49,7 @@ int iso_file_src_cmp(const void *n1, const void *n2) int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) { - int res; + int ret; IsoFileSrc *fsrc; unsigned int fs_id; dev_t dev_id; @@ -62,35 +59,24 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) return ISO_NULL_POINTER; } - res = iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id); - if (res < 0) { - return res; - } else if (res == 0) { - // TODO this corresponds to Stream that cannot provide a valid id - // Not implemented for now, but that shouldn't be here, the get_id - // above is not needed at all, the comparison function should take - // care of it - return ISO_ERROR; - } else { - int ret; + iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id); - fsrc = malloc(sizeof(IsoFileSrc)); - if (fsrc == NULL) { - return ISO_MEM_ERROR; - } + fsrc = malloc(sizeof(IsoFileSrc)); + if (fsrc == NULL) { + return ISO_MEM_ERROR; + } - /* fill key and other atts */ - fsrc->prev_img = file->msblock ? 1 : 0; - fsrc->block = file->msblock; - fsrc->sort_weight = file->sort_weight; - fsrc->stream = file->stream; + /* fill key and other atts */ + fsrc->prev_img = file->msblock ? 1 : 0; + fsrc->block = file->msblock; + fsrc->sort_weight = file->sort_weight; + fsrc->stream = file->stream; - /* insert the filesrc in the tree */ - ret = iso_rbtree_insert(img->files, fsrc, (void**)src); - if (ret <= 0) { - free(fsrc); - return ret; - } + /* insert the filesrc in the tree */ + ret = iso_rbtree_insert(img->files, fsrc, (void**)src); + if (ret <= 0) { + free(fsrc); + return ret; } return ISO_SUCCESS; } diff --git a/src/stream.c b/src/stream.c index 417628c..3d12908 100644 --- a/src/stream.c +++ b/src/stream.c @@ -14,6 +14,8 @@ #include #include +ino_t serial_id = (ino_t)1; + typedef struct { IsoFileSource *src; @@ -90,27 +92,18 @@ int fsrc_is_repeatable(IsoStream *stream) } static -int fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, +void fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, ino_t *ino_id) { FSrcStreamData *data; IsoFilesystem *fs; - - if (stream == NULL || fs_id == NULL || dev_id == NULL || ino_id == NULL) { - return ISO_NULL_POINTER; - } + data = (FSrcStreamData*)stream->data; - fs = iso_file_source_get_filesystem(data->src); *fs_id = fs->get_id(fs); - if (fs_id == 0) { - return 0; - } - *dev_id = data->dev_id; *ino_id = data->ino_id; - return ISO_SUCCESS; } static @@ -178,9 +171,27 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream) /* take the ref to IsoFileSource */ data->src = src; - data->dev_id = info.st_dev; - data->ino_id = info.st_ino; data->size = info.st_size; + + /* get the id numbers */ + { + IsoFilesystem *fs; + unsigned int fs_id; + fs = iso_file_source_get_filesystem(data->src); + + fs_id = fs->get_id(fs); + if (fs_id == 0) { + /* + * the filesystem implementation is unable to provide valid + * st_dev and st_ino fields. Use serial_id. + */ + data->dev_id = (dev_t) 0; + data->ino_id = serial_id++; + } else { + data->dev_id = info.st_dev; + data->ino_id = info.st_ino; + } + } str->refcount = 1; str->data = data; diff --git a/src/stream.h b/src/stream.h index 29a4b9d..70e2ef0 100644 --- a/src/stream.h +++ b/src/stream.h @@ -13,6 +13,13 @@ */ #include "fsource.h" +/** + * serial number to be used when you can't get a valid id for a Stream by other + * means. If you use this, both fs_id and dev_id should be set to 0. + * This must be incremented each time you get a reference to it. + */ +extern ino_t serial_id; + /* * Some functions here will be moved to libisofs.h when we expose * Streams. @@ -70,14 +77,9 @@ typedef struct IsoStream_Iface int (*is_repeatable)(IsoStream *stream); /** - * Get an unique identifier for the IsoStream. If your implementation - * is unable to return a valid identifier, this function should return - * 0. - * - * @return - * 1 on success, 0 if idenfier is not valid, < 0 error + * Get an unique identifier for the IsoStream. */ - int (*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); /** @@ -135,10 +137,10 @@ int iso_stream_is_repeatable(IsoStream *stream) } extern inline -int 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) { - return stream->class->get_id(stream, fs_id, dev_id, ino_id); + stream->class->get_id(stream, fs_id, dev_id, ino_id); } extern inline