Global reference counters for both zisofs filter types and

new API function iso_zisofs_get_refcounts()
This commit is contained in:
Thomas Schmitt 2009-04-11 15:25:40 +02:00
parent 6886777ea0
commit 63ddfc1c94
2 changed files with 44 additions and 2 deletions

View File

@ -145,6 +145,14 @@ failed:
static unsigned char zisofs_magic[9] = static unsigned char zisofs_magic[9] =
{0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07}; {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 #ifdef Libisofs_with_zliB
/* Parameter for compress2() , see <zlib.h> */ /* Parameter for compress2() , see <zlib.h> */
@ -700,6 +708,7 @@ static
void ziso_stream_free(IsoStream *stream) void ziso_stream_free(IsoStream *stream)
{ {
ZisofsFilterStreamData *data; ZisofsFilterStreamData *data;
ZisofsComprStreamData *nstd;
if (stream == NULL) { if (stream == NULL) {
return; return;
@ -708,11 +717,15 @@ void ziso_stream_free(IsoStream *stream)
if (data->running != NULL) { if (data->running != NULL) {
ziso_stream_close(stream); ziso_stream_close(stream);
} }
if (stream->class->read != &ziso_stream_uncompress) { if (stream->class->read == &ziso_stream_uncompress) {
ZisofsComprStreamData *nstd; if (--ziso_osiz_ref_count < 0)
ziso_osiz_ref_count = 0;
} else {
nstd = stream->data; nstd = stream->data;
if (nstd->block_pointers != NULL) if (nstd->block_pointers != NULL)
free((char *) nstd->block_pointers); free((char *) nstd->block_pointers);
if (--ziso_ref_count < 0)
ziso_ref_count = 0;
} }
iso_stream_unref(data->orig); iso_stream_unref(data->orig);
free(data); free(data);
@ -824,10 +837,12 @@ int ziso_filter_get_filter(FilterContext *filter, IsoStream *original,
unstd->header_size_div4 = 0; unstd->header_size_div4 = 0;
unstd->block_size_log2 = 0; unstd->block_size_log2 = 0;
str->class = &ziso_stream_uncompress_class; str->class = &ziso_stream_uncompress_class;
ziso_osiz_ref_count++;
} else { } else {
cnstd->orig_size = 0; cnstd->orig_size = 0;
cnstd->block_pointers = NULL; cnstd->block_pointers = NULL;
str->class = &ziso_stream_compress_class; str->class = &ziso_stream_compress_class;
ziso_ref_count++;
} }
*filtered = str; *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) int iso_file_add_zisofs_filter(IsoFile *file, int flag)
{ {
return ziso_add_filter(file, flag & ~8); 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, int ziso_add_osiz_filter(IsoFile *file, uint8_t header_size_div4,
uint8_t block_size_log2, uint32_t uncompressed_size, uint8_t block_size_log2, uint32_t uncompressed_size,
int flag) int flag)

View File

@ -4922,6 +4922,23 @@ int iso_stream_get_external_filter(IsoStream *stream,
*/ */
int iso_file_add_zisofs_filter(IsoFile *file, int flag); 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);
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */