From d87e5721db63bb7bf1d07247ab49ee2730b6179e Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 15 Apr 2009 13:22:20 +0200 Subject: [PATCH] Removed some development remarks and implemented skipping of zisofs headers larger than 16 bytes. --- libisofs/filters/external.c | 18 ++-------------- libisofs/filters/gzip.c | 11 +++++----- libisofs/filters/zisofs.c | 41 ++++++++----------------------------- libisofs/libisofs.h | 4 ++++ libisofs/messages.c | 2 ++ libisofs/rockridge.c | 6 ++++-- 6 files changed, 26 insertions(+), 56 deletions(-) diff --git a/libisofs/filters/external.c b/libisofs/filters/external.c index fd1cc13..ae72a98 100644 --- a/libisofs/filters/external.c +++ b/libisofs/filters/external.c @@ -243,9 +243,6 @@ int extf_stream_open_flag(IsoStream *stream, int flag) return ret; } stream_open = 1; - - /* >>> ??? should one replace non-blocking read() by select () ? */ - /* Make filter outlet non-blocking */ ret = fcntl(recv_pipe[0], F_GETFL); if (ret != -1) { @@ -401,9 +398,6 @@ int extf_stream_read(IsoStream *stream, void *buf, size_t desired) while (1) { if (running->in_eof && !blocking) { - - /* >>> ??? should one replace non-blocking read() by select () ? */ - /* Make filter outlet blocking */ ret = fcntl(running->recv_fd, F_GETFL); if (ret != -1) { @@ -415,9 +409,6 @@ int extf_stream_read(IsoStream *stream, void *buf, size_t desired) /* Try to read desired amount from filter */; while (1) { - - /* >>> ??? should one replace non-blocking read() by select () ? */ - ret = read(running->recv_fd, ((char *) buf) + fill, desired - fill); if (ret < 0) { @@ -436,9 +427,6 @@ int extf_stream_read(IsoStream *stream, void *buf, size_t desired) } if (running->in_eof) { - - /* >>> ??? should one replace non-blocking read() by select () ? */ - usleep(1000); /* just in case it is still non-blocking */ continue; } @@ -476,10 +464,8 @@ int extf_stream_read(IsoStream *stream, void *buf, size_t desired) #ifdef Libisofs_external_filters_selecT - /* >>> ??? should one replace non-blocking read() - by select () ? */ - - /* This saves 10 % CPU load but needs 50 % more real time*/ + /* This select() based waiting saves 10 % CPU load but + needs 50 % more real time */ ret = extf_wait_for_io(running->recv_fd, running->send_fd, 100000, 0); diff --git a/libisofs/filters/gzip.c b/libisofs/filters/gzip.c index 1899d72..f88d914 100644 --- a/libisofs/filters/gzip.c +++ b/libisofs/filters/gzip.c @@ -138,7 +138,10 @@ static off_t gunzip_ref_count = 0; #ifdef Libisofs_with_zliB /* Parameter for deflateInit2() , see */ -/* >>> ??? get this from zisofs.c ziso_compression_level ? */ +/* ??? get this from zisofs.c ziso_compression_level ? + * ??? have an own global parameter API ? + * For now level 6 seems to be a fine compromise between speed and size. + */ static int gzip_compression_level = 6; #endif /* Libisofs_with_zliB */ @@ -359,10 +362,8 @@ int gzip_stream_convert(IsoStream *stream, void *buf, size_t desired, int flag) return (rng->error_ret = ret); if (ret == 0) { if (flag & 2) { - - /* >>> ??? what to do on (early) input EOF ? */; - return (rng->error_ret = ISO_ZLIB_COMPR_ERR); - + /* Early input EOF */ + return (rng->error_ret = ISO_ZLIB_EARLY_EOF); } else { /* Tell zlib by the next call that it is over */ rng->do_flush = Z_FINISH; diff --git a/libisofs/filters/zisofs.c b/libisofs/filters/zisofs.c index 7494d03..c7e3b75 100644 --- a/libisofs/filters/zisofs.c +++ b/libisofs/filters/zisofs.c @@ -507,12 +507,8 @@ int ziso_stream_uncompress(IsoStream *stream, void *buf, size_t desired) size_t fill = 0; char *cbuf = buf; uLongf buf_len; - -#ifndef NIX uint32_t uncompressed_size; -#else - char zisofs_head[16]; -#endif + char waste_word[4]; if (stream == NULL) { return ISO_NULL_POINTER; @@ -530,8 +526,6 @@ int ziso_stream_uncompress(IsoStream *stream, void *buf, size_t desired) while (1) { if (rng->state == 0) { /* Reading file header */ - -#ifndef NIX ret = ziso_parse_zisofs_head(data->orig, &header_size, &bs_log2, &uncompressed_size, 0); if (ret < 0) @@ -539,34 +533,15 @@ int ziso_stream_uncompress(IsoStream *stream, void *buf, size_t desired) nstd->header_size_div4 = header_size; header_size *= 4; data->size = uncompressed_size; -#else - ret = iso_stream_read(data->orig, zisofs_head, 16); - if (ret < 0) - return (rng->error_ret = ret); - header_size = ((unsigned char *) zisofs_head)[12] * 4; - bs_log2 = ((unsigned char *) zisofs_head)[13]; - if (ret != 16 || memcmp(zisofs_head, zisofs_magic, 8) != 0 || - header_size < 16 || bs_log2 < 15 || bs_log2 > 17) { - return (rng->error_ret = ISO_ZISOFS_WRONG_INPUT); - } - data->size = iso_read_lsb(((uint8_t *) zisofs_head) + 8, 4); - nstd->header_size_div4 = header_size / 4; -#endif /* NIX */ - nstd->block_size_log2 = bs_log2; rng->block_size = 1 << bs_log2; - if (header_size > 16) { - /* Skip surplus header bytes */ - -/* >>> This must be a loop - ret = iso_stream_read(data->orig, zisofs_head, header_size-16); - if (ret < 0) - return (rng->error_ret = ret); - if (ret != header_size - 16) -*/ - return (rng->error_ret = ISO_ZISOFS_WRONG_INPUT); - - + for (i = 16; i < header_size; i += 4) { + /* Skip surplus header words */ + ret = iso_stream_read(data->orig, waste_word, 4); + if (ret < 0) + return (rng->error_ret = ret); + if (ret != 4) + return (rng->error_ret = ISO_ZISOFS_WRONG_INPUT); } if (desired == 0) { diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 43c5bb8..9c46efd 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -4729,6 +4729,10 @@ int iso_local_set_attrs(char *disk_path, size_t num_attrs, char **names, (FAILURE, HIGH, -350) */ #define ISO_ZISOFS_PARAM_LOCK 0xE830FEA2 +/* ts A90415 */ +/** Premature EOF of zlib input stream (FAILURE, HIGH, -351) */ +#define ISO_ZLIB_EARLY_EOF 0xE830FEA1 + /* --------------------------- Filters in General -------------------------- */ diff --git a/libisofs/messages.c b/libisofs/messages.c index b70a64f..60a2091 100644 --- a/libisofs/messages.c +++ b/libisofs/messages.c @@ -261,6 +261,8 @@ const char *iso_error_to_msg(int errcode) return "Input stream is not in zisofs format"; case ISO_ZISOFS_PARAM_LOCK: return "Cannot set global zisofs parameters while filters exist"; + case ISO_ZLIB_EARLY_EOF: + return "Premature EOF of zlib input stream"; default: return "Unknown error"; } diff --git a/libisofs/rockridge.c b/libisofs/rockridge.c index e4924c7..84d4359 100644 --- a/libisofs/rockridge.c +++ b/libisofs/rockridge.c @@ -827,11 +827,13 @@ int add_zf_field(Ecma119Image *t, Ecma119Node *n, struct susp_info *info, It gets copied and the last stream is a ziso stream, or it had a ZF entry and is unfiltered - >>> or its last stream delivers a zisofs file header + or it has a zf xinfo record (because its last stream delivered a + zisofs file header when inquired) or it stays uncopied and the first filter is an osiz stream, or it had a ZF entry - >>> or its first stream delivers a zisofs file header + or it has a zf xinfo record (because its first stream delivered a + zisofs file header when inquired) */ if (t->appendable && file->from_old_session)