From 63ddfc1c9443c0d5e2b74c885552819863ee8963 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 11 Apr 2009 15:25:40 +0200 Subject: [PATCH] Global reference counters for both zisofs filter types and new API function iso_zisofs_get_refcounts() --- libisofs/filters/zisofs.c | 29 +++++++++++++++++++++++++++-- libisofs/libisofs.h | 17 +++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/libisofs/filters/zisofs.c b/libisofs/filters/zisofs.c index d9dacd9..1e8c074 100644 --- a/libisofs/filters/zisofs.c +++ b/libisofs/filters/zisofs.c @@ -145,6 +145,14 @@ failed: static unsigned char zisofs_magic[9] = {0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07}; +/* Counts the number of active compression filters */ +static off_t ziso_ref_count = 0; + +/* Counts the number of active uncompression filters */ +static off_t ziso_osiz_ref_count = 0; + + + #ifdef Libisofs_with_zliB /* Parameter for compress2() , see */ @@ -700,6 +708,7 @@ static void ziso_stream_free(IsoStream *stream) { ZisofsFilterStreamData *data; + ZisofsComprStreamData *nstd; if (stream == NULL) { return; @@ -708,11 +717,15 @@ void ziso_stream_free(IsoStream *stream) if (data->running != NULL) { ziso_stream_close(stream); } - if (stream->class->read != &ziso_stream_uncompress) { - ZisofsComprStreamData *nstd; + if (stream->class->read == &ziso_stream_uncompress) { + if (--ziso_osiz_ref_count < 0) + ziso_osiz_ref_count = 0; + } else { nstd = stream->data; if (nstd->block_pointers != NULL) free((char *) nstd->block_pointers); + if (--ziso_ref_count < 0) + ziso_ref_count = 0; } iso_stream_unref(data->orig); free(data); @@ -824,10 +837,12 @@ int ziso_filter_get_filter(FilterContext *filter, IsoStream *original, unstd->header_size_div4 = 0; unstd->block_size_log2 = 0; str->class = &ziso_stream_uncompress_class; + ziso_osiz_ref_count++; } else { cnstd->orig_size = 0; cnstd->block_pointers = NULL; str->class = &ziso_stream_compress_class; + ziso_ref_count++; } *filtered = str; @@ -950,12 +965,22 @@ int ziso_add_filter(IsoFile *file, int flag) } +/* API function */ int iso_file_add_zisofs_filter(IsoFile *file, int flag) { return ziso_add_filter(file, flag & ~8); } +/* API function */ +int iso_zisofs_get_refcounts(off_t *ziso_count, off_t *osiz_count, int flag) +{ + *ziso_count = ziso_ref_count; + *osiz_count = ziso_osiz_ref_count; + return ISO_SUCCESS; +} + + int ziso_add_osiz_filter(IsoFile *file, uint8_t header_size_div4, uint8_t block_size_log2, uint32_t uncompressed_size, int flag) diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 7fa5092..cc6ab88 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -4922,6 +4922,23 @@ int iso_stream_get_external_filter(IsoStream *stream, */ int iso_file_add_zisofs_filter(IsoFile *file, int flag); +/** + * Inquire the number of zisofs compression and uncompression filters which + * are in use. + * @param ziso_count + * Will return the number of currently installed compression filters. + * @param osiz_count + * Will return the number of currently installed uncompression filters. + * @param flag + * Bitfield for control purposes, unused yet, submit 0 + * @return + * 1 on success, <0 on error + * + * @since 0.6.18 + */ +int iso_zisofs_get_refcounts(off_t *ziso_count, off_t *osiz_count, int flag); + + /* ------------------------------------------------------------------------- */