From c65bf912f69200bdccc38380132c50c3021a618d Mon Sep 17 00:00:00 2001 From: short <> Date: Fri, 18 Jul 2003 18:42:29 +0000 Subject: [PATCH] captive_giochannel_setup(): Turn off GIOChannel buffering. captive_giochannel_blind_io_read(): +Sanity protected read of unbuffered data. - Applies only to 'giochannel_orig==NULL' (non-fallbacked) blinders. --- src/libcaptive/client/giochannel-blind.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/libcaptive/client/giochannel-blind.c b/src/libcaptive/client/giochannel-blind.c index 6f6b28c..b591702 100644 --- a/src/libcaptive/client/giochannel-blind.c +++ b/src/libcaptive/client/giochannel-blind.c @@ -35,8 +35,6 @@ /* CONFIG: */ /* It should be the divisor of all offsets/sizes written by W32 filesystems. - * Otherwise access of non-GIOCHANNEL_BLIND_BLOCK_SIZE aligned smaller block - * would wastefully exceed to the following block to fill GIOChannel buffer. */ #define GIOCHANNEL_BLIND_BLOCK_SIZE 512 @@ -148,15 +146,8 @@ gsize bytes_read; (guint64)window_now,(gulong)(transfer_bottom-giochannel_blind->offset),(guint64)transfer_bottom, (gulong)(transfer_top-transfer_bottom)); if (!giochannel_blind->giochannel_orig) { - /* FIXME: GIOChannel alignment problems. */ - g_message("%s: Missing block at offset 0x%llX",G_STRLOC,(unsigned long long)window_now); - /* Do not just skip over g_io_channel_read_chars() with bytes_read==0 - * as it would EOF our read while we may need to read some further block - * which may be available. - */ - bytes_read=transfer_top-transfer_bottom; - memset(buf+transfer_bottom-giochannel_blind->offset,0,bytes_read); - goto read_done; + g_error("%s: Missing block at offset 0x%llX",G_STRLOC,(unsigned long long)window_now); + g_return_val_if_reached(G_IO_STATUS_ERROR); } errgiostatus=g_io_channel_seek_position( giochannel_blind->giochannel_orig, /* channel */ @@ -202,7 +193,6 @@ guint64 *keyp; } blind_block->was_read=TRUE; } -read_done: maxread=transfer_bottom+bytes_read; if (bytes_read==transfer_top-transfer_bottom) g_return_val_if_fail(transfer_bottom+bytes_read<=giochannel_blind->size,G_IO_STATUS_ERROR); @@ -436,11 +426,18 @@ GIOStatus erriostatus; g_return_if_fail(giochannel!=NULL); - erriostatus=g_io_channel_set_encoding(giochannel, - NULL, /* encoding; force binary data */ + if (g_io_channel_get_encoding(giochannel)) { + if (!g_io_channel_get_buffered(giochannel)) /* Prevent: Need to have NULL encoding to set the buffering state ... */ + g_io_channel_set_buffered(giochannel,TRUE); /* Prevent: Need to set the channel buffered before setting the encoding. */ + erriostatus=g_io_channel_set_encoding(giochannel, + NULL, /* encoding; force binary data */ + NULL); /* error */ + g_assert(erriostatus==G_IO_STATUS_NORMAL); + } + erriostatus=g_io_channel_flush(giochannel, NULL); /* error */ g_assert(erriostatus==G_IO_STATUS_NORMAL); - g_io_channel_set_buffer_size(giochannel,GIOCHANNEL_BLIND_BLOCK_SIZE); + g_io_channel_set_buffered(giochannel,FALSE); } -- 1.8.3.1