Subject: Re: gunzip|dd causes dd to fail w/ new gzip
To: Hubert Feyrer <hubert@feyrer.de>
From: enami tsugutomo <enami@sm.sony.co.jp>
List: tech-userlevel
Date: 07/09/2004 11:27:47
Hubert Feyrer <hubert@feyrer.de> writes:

> On Thu, 8 Jul 2004, Ben Collver wrote:
> > With the above command, the default is ibs=512.  Do pipes guarantee that
> > at least 512 bytes will be read?
> 
> I have no idea, but I don't understand why this is an issue for dd(1),

From bin/dd/dd.c:

		/*
		 * POSIX states that if bs is set and no other conversions
		 * than noerror, notrunc or sync are specified, the block
		 * is output without buffering as it is read.
		 */
		if (flags & C_BS) {
			out.dbcnt = in.dbcnt;
			dd_out(1);
			in.dbcnt = 0;
			continue;
		}

It looks like there is similar description in the manual page also.

> and esp. why it arises after gzip(1) implementation was changed.

The current gzip(1) implementation does output when input buffer
become empty (in addition to when output buffer become full).

From usr.bin/gzip/gzip.c:
		case GZSTATE_READ:
			error = inflate(&z, Z_FINISH);
			/* Z_BUF_ERROR goes with Z_FINISH... */
			if (error == Z_STREAM_END || error == Z_BUF_ERROR) {
				size_t wr = BUFLEN - z.avail_out;

				/* Nothing left? */
				if (wr == 0)
					goto stop;

				if (
#ifndef SMALL
				    /* don't write anything with -t */
				    tflag == 0 &&
#endif
				    write(out, outbuf, wr) != wr) {

enami.