Deleted Added
full compact
fifolog_reader.c (209871) fifolog_reader.c (219027)
1/*-
2 * Copyright (c) 2005-2008 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2005-2008 Poul-Henning Kamp
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/usr.sbin/fifolog/lib/fifolog_reader.c 209871 2010-07-10 11:40:31Z keramida $
26 * $FreeBSD: head/usr.sbin/fifolog/lib/fifolog_reader.c 219027 2011-02-25 09:40:17Z phk $
27 */
28
29#include <stdio.h>
30#include <unistd.h>
31#include <assert.h>
32#include <err.h>
33#include <time.h>
34#include <string.h>

--- 8 unchanged lines hidden (view full) ---

43
44/*--------------------------------------------------------------------*/
45
46struct fifolog_reader {
47 unsigned magic;
48#define FIFOLOG_READER_MAGIC 0x1036d139
49 struct fifolog_file *ff;
50 unsigned olen;
27 */
28
29#include <stdio.h>
30#include <unistd.h>
31#include <assert.h>
32#include <err.h>
33#include <time.h>
34#include <string.h>

--- 8 unchanged lines hidden (view full) ---

43
44/*--------------------------------------------------------------------*/
45
46struct fifolog_reader {
47 unsigned magic;
48#define FIFOLOG_READER_MAGIC 0x1036d139
49 struct fifolog_file *ff;
50 unsigned olen;
51 unsigned char *obuf;
51 unsigned char *obuf;
52 time_t now;
53};
54
55struct fifolog_reader *
56fifolog_reader_open(const char *fname)
57{
58 const char *retval;
59 struct fifolog_reader *fr;

--- 10 unchanged lines hidden (view full) ---

70 fr->olen = fr->ff->recsize * 16;
71 fr->obuf = calloc(fr->olen, 1);
72 if (fr->obuf == NULL)
73 err(1, "Cannot malloc");
74
75 i = inflateInit(fr->ff->zs);
76 assert(i == Z_OK);
77
52 time_t now;
53};
54
55struct fifolog_reader *
56fifolog_reader_open(const char *fname)
57{
58 const char *retval;
59 struct fifolog_reader *fr;

--- 10 unchanged lines hidden (view full) ---

70 fr->olen = fr->ff->recsize * 16;
71 fr->obuf = calloc(fr->olen, 1);
72 if (fr->obuf == NULL)
73 err(1, "Cannot malloc");
74
75 i = inflateInit(fr->ff->zs);
76 assert(i == Z_OK);
77
78 fr->magic = FIFOLOG_READER_MAGIC;
78 fr->magic = FIFOLOG_READER_MAGIC;
79 return (fr);
80}
81
82/*
83 * Find the next SYNC block
84 *
85 * Return:
86 * 0 - empty fifolog

--- 52 unchanged lines hidden (view full) ---

139
140 /*
141 * First, find the first SYNC block
142 */
143 o = 0;
144 e = fifolog_reader_findsync(fr->ff, &o);
145 if (e == 0)
146 return (0); /* empty fifolog */
79 return (fr);
80}
81
82/*
83 * Find the next SYNC block
84 *
85 * Return:
86 * 0 - empty fifolog

--- 52 unchanged lines hidden (view full) ---

139
140 /*
141 * First, find the first SYNC block
142 */
143 o = 0;
144 e = fifolog_reader_findsync(fr->ff, &o);
145 if (e == 0)
146 return (0); /* empty fifolog */
147 assert(e == 1);
147 assert(e == 1);
148
149 assert(fr->ff->recbuf[4] & FIFOLOG_FLG_SYNC);
150 seq = be32dec(fr->ff->recbuf);
151 t = be32dec(fr->ff->recbuf + 5);
152
153 if (t > t0) {
154 /* Check if there is a second older part we can use */
155 retval = fifolog_int_findend(fr->ff, &s);

--- 136 unchanged lines hidden (view full) ---

292 fprintf(stderr,
293 "Z_BUF_ERROR [%d,%d] [%d,%d,%d]\n",
294 (int)(zs->next_in - fr->ff->recbuf),
295 zs->avail_in,
296 (int)(zs->next_out - fr->obuf),
297 zs->avail_out, fr->olen);
298 exit (250);
299#else
148
149 assert(fr->ff->recbuf[4] & FIFOLOG_FLG_SYNC);
150 seq = be32dec(fr->ff->recbuf);
151 t = be32dec(fr->ff->recbuf + 5);
152
153 if (t > t0) {
154 /* Check if there is a second older part we can use */
155 retval = fifolog_int_findend(fr->ff, &s);

--- 136 unchanged lines hidden (view full) ---

292 fprintf(stderr,
293 "Z_BUF_ERROR [%d,%d] [%d,%d,%d]\n",
294 (int)(zs->next_in - fr->ff->recbuf),
295 zs->avail_in,
296 (int)(zs->next_out - fr->obuf),
297 zs->avail_out, fr->olen);
298 exit (250);
299#else
300
300
301 i = Z_OK;
302#endif
303 }
304 if (i == Z_STREAM_END) {
305 i = inflateReset(zs);
306 }
307 if (i != Z_OK) {
308 fprintf(stderr, "inflate = %d\n", i);
309 exit (250);
310 }
311 assert(i == Z_OK);
312 if (zs->avail_out != fr->olen) {
313 q = fr->obuf + (fr->olen - zs->avail_out);
314 p = fifolog_reader_chop(fr, func, priv);
301 i = Z_OK;
302#endif
303 }
304 if (i == Z_STREAM_END) {
305 i = inflateReset(zs);
306 }
307 if (i != Z_OK) {
308 fprintf(stderr, "inflate = %d\n", i);
309 exit (250);
310 }
311 assert(i == Z_OK);
312 if (zs->avail_out != fr->olen) {
313 q = fr->obuf + (fr->olen - zs->avail_out);
314 p = fifolog_reader_chop(fr, func, priv);
315 if (p < q)
315 if (p < q)
316 (void)memmove(fr->obuf, p, q - p);
317 zs->avail_out = fr->olen - (q - p);
318 zs->next_out = fr->obuf + (q - p);
319 }
320 }
321 }
322}
316 (void)memmove(fr->obuf, p, q - p);
317 zs->avail_out = fr->olen - (q - p);
318 zs->next_out = fr->obuf + (q - p);
319 }
320 }
321 }
322}