1 diff -urNp buffer-1.19.orig/buffer.c buffer-1.19/buffer.c
2 --- buffer-1.19.orig/buffer.c 2000-01-04 03:46:11.000000000 +0100
3 +++ buffer-1.19/buffer.c 2008-09-20 01:19:18.000000000 +0200
5 * Christoph Wicki <wicki@iis.ethz.ch>
7 * Revision 1.7 1992/07/23 20:42:03 lmjm
8 - * Added 't' option to print total writen at end.
9 + * Added 't' option to print total written at end.
11 * Revision 1.6 1992/04/07 19:57:30 lmjm
12 * Added Kevins -B and -p options.
14 * Make sofar printing size an option.
16 * Revision 1.3 90/05/15 23:27:46 lmjm
17 - * Added -S option (show how much has been writen).
18 + * Added -S option (show how much has been written).
19 * Added -m option to specify how much shared memory to grab.
20 * Now tries to fill this with blocks.
21 * reader waits for writer to terminate and then frees the shared mem and sems.
34 +#include <sys/time.h>
35 #include <sys/types.h>
42 +#if defined __GNUC__ || __STDC_VERSION__ >= 199901L
43 +#define NUM_K_TYPE unsigned long long
44 +#define NUM_K_FMT "llu"
46 +#define NUM_K_TYPE unsigned long
47 +#define NUM_K_FMT "lu"
50 /* Some forward declarations */
52 void start_reader_and_writer();
53 @@ -162,7 +174,7 @@ void write_block_to_stdout();
57 -/* When showing print a note every this many bytes writen */
58 +/* When showing print a note every this many bytes written */
60 #define PRINT_EVERY 10 K
62 @@ -253,7 +265,9 @@ char *progname = "buffer";
65 /* Number of K output */
66 -unsigned long outk = 0;
69 +struct timeval starttime;
73 @@ -265,6 +279,8 @@ main( argc, argv )
78 + gettimeofday(&starttime, NULL);
80 start_reader_and_writer();
82 @@ -290,7 +306,7 @@ parse_args( argc, argv )
84 while( (c = getopt( argc, argv, "BS:Zdm:s:b:p:u:ti:o:z:" )) != -1 ){
86 - case 't': /* Print to stderr the total no of bytes writen */
87 + case 't': /* Print to stderr the total no of bytes written */
90 case 'u': /* pause after write for given microseconds */
91 @@ -387,8 +403,8 @@ parse_args( argc, argv )
92 fprintf( stderr, "Usage: %s [-B] [-t] [-S size] [-m memsize] [-b blocks] [-p percent] [-s blocksize] [-u pause] [-i infile] [-o outfile] [-z size]\n",
94 fprintf( stderr, "-B = blocked device - pad out last block\n" );
95 - fprintf( stderr, "-t = show total amount writen at end\n" );
96 - fprintf( stderr, "-S size = show amount writen every size bytes\n" );
97 + fprintf( stderr, "-t = show total amount written at end\n" );
98 + fprintf( stderr, "-S size = show amount written every size bytes\n" );
99 fprintf( stderr, "-m size = size of shared mem chunk to grab\n" );
100 fprintf( stderr, "-b num = number of blocks in queue\n" );
101 fprintf( stderr, "-p percent = don't start writing until percent blocks filled\n" );
102 @@ -400,6 +416,11 @@ parse_args( argc, argv )
107 + if (argc > optind) {
108 + fprintf( stderr, "too many arguments\n" );
112 if (zflag) showevery = blocksize;
114 @@ -510,9 +531,9 @@ buffer_allocate()
118 - fprintf( stderr, "%s pbuffer is 0x%08x, buffer_size is %d [%d x %d]\n",
119 + fprintf( stderr, "%s pbuffer is 0x%08lx, buffer_size is %d [%d x %d]\n",
121 - (char *)pbuffer, buffer_size, blocks, blocksize );
122 + (unsigned long)pbuffer, buffer_size, blocks, blocksize );
125 memset( (char *)pbuffer, '\0', buffer_size );
126 @@ -531,7 +552,17 @@ buffer_allocate()
127 pbuffer->blocks_free_lock = 1;
128 /* start this off so lock() can be called on it for each block
129 * till all the blocks are used up */
130 + /* Initializing the semaphore to "blocks - 1" causes a hang when using option
131 + * "-p 100" because it always keeps one block free, so we'll never reach 100% fill
132 + * level. However, there doesn't seem to be a good reason to keep one block free,
133 + * so we initialize the semaphore to "blocks" instead.
134 + * <mbuck@debian.org> 2004-01-11
137 sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks - 1 );
139 + sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks );
142 /* Detattach the shared memory so the fork doesnt do anything odd */
143 shmdt( (char *)pbuffer );
144 @@ -651,7 +682,7 @@ get_next_free_block()
152 static char eof_reached = 0;
153 @@ -710,7 +741,7 @@ writer()
156 int maxfilled = (blocks * percent) / 100;
158 + int first_block = 0;
161 fprintf( stderr, "\tW: Entering writer\n blocks = %d\n maxfilled = %d\n",
162 @@ -745,7 +776,7 @@ writer()
166 - fprintf( stderr, "Kilobytes Out %lu\n", outk );
167 + fprintf( stderr, "Kilobytes Out %" NUM_K_FMT "\n", outk );
171 @@ -786,14 +817,14 @@ write_blocks_to_stdout( filled, first_bl
173 write_block_to_stdout()
175 - static unsigned long out = 0;
176 + unsigned long out = 0;
177 static unsigned long last_gb = 0;
178 - static unsigned long next_k = 0;
179 + static NUM_K_TYPE next_k = 0;
182 if( next_k == 0 && showevery ){
184 - fprintf( stderr, "W: next_k = %lu showevery = %d\n", next_k, showevery );
185 + fprintf( stderr, "W: next_k = %" NUM_K_FMT " showevery = %d\n", next_k, showevery );
186 showevery = showevery / 1024;
189 @@ -801,7 +832,7 @@ write_block_to_stdout()
190 if( (written = write( fdout, curr_block->data, curr_block->bytes )) != curr_block->bytes ){
192 perror( "write of data failed" );
193 - fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10luK\n", curr_block->bytes, written, outk );
194 + fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10" NUM_K_FMT "K\n", curr_block->bytes, written, outk );
198 @@ -828,7 +859,7 @@ write_block_to_stdout()
202 - fprintf( stderr, "W: outk = %lu, next_k = %lu\n",
203 + fprintf( stderr, "W: outk = %" NUM_K_FMT ", next_k = %" NUM_K_FMT "\n",
205 if( outk >= next_k ){
207 @@ -917,13 +948,12 @@ int
216 - sscanf( arg, "%d%s", &ret, format );
218 + sscanf( arg, "%d%c", &ret, &unit );
225 @@ -944,7 +974,36 @@ do_size( arg )
229 - fprintf( stderr, " %10luK\r", outk );
230 + struct timeval now;
231 + unsigned long ms_delta, k_per_s;
233 + gettimeofday(&now, NULL);
234 + ms_delta = (now.tv_sec - starttime.tv_sec) * 1000
235 + + (now.tv_usec - starttime.tv_usec) / 1000;
237 + /* Use increased accuracy for small amounts of data,
238 + * decreased accuracy for *huge* throughputs > 4.1GB/s
239 + * to avoid division by 0. This will overflow if your
240 + * machine's throughput exceeds 4TB/s - you deserve to
241 + * loose if you're still using 32 bit longs on such a
243 + * <mbuck@debian.org>
245 + if (outk < ULONG_MAX / 1000) {
246 + k_per_s = (outk * 1000) / ms_delta;
247 + } else if (ms_delta >= 1000) {
248 + k_per_s = outk / (ms_delta / 1000);
250 + k_per_s = (outk / ms_delta) * 1000;
252 + fprintf( stderr, " %10" NUM_K_FMT "K, %10luK/s\r", outk, k_per_s );
255 + fprintf( stderr, " %10" NUM_K_FMT "K, ?K/s\r", outk );
257 + fprintf( stderr, " 0K, 0K/s\r");
263 diff -urNp buffer-1.19.orig/buffer.man buffer-1.19/buffer.man
264 --- buffer-1.19.orig/buffer.man 2000-01-04 03:44:32.000000000 +0100
265 +++ buffer-1.19/buffer.man 2008-09-20 01:18:48.000000000 +0200
266 @@ -37,7 +37,8 @@ Use the given file as the input file. T
267 Use the given file as the output file. The default is stdout.
270 -After every chunk this size has been writen print out how much been writen so far.
271 +After every chunk of this size has been written, print out how much has
272 +been written so far. Also prints the total througput.
273 By default this is not set.
276 @@ -71,9 +72,9 @@ After every write pause for this many mi
277 throughput on some drives.)
280 -Force each block writen to be padded out to the blocksize. This is needed by some tape
281 +Force each block written to be padded out to the blocksize. This is needed by some tape
282 and cartridge drives. Defaults to unpadded. This only affects the
287 On exiting print to stderr a brief message showing the total number of
288 @@ -82,7 +83,7 @@ bytes written.
290 If reading/writing directly to a character device (like a tape drive)
291 then after each gigabyte perform an lseek to the start of the file.
292 -Use this flag with extreme care. If can only be used on devices where
293 +Use this flag with extreme care. It can only be used on devices where
294 an lseek does not rewind the tape but does reset the kernels position
295 flags. It is used to allow more than 2 gigabytes to be written.
297 diff -urNp buffer-1.19.orig/debian/changelog buffer-1.19/debian/changelog
298 --- buffer-1.19.orig/debian/changelog 1970-01-01 01:00:00.000000000 +0100
299 +++ buffer-1.19/debian/changelog 2008-09-20 01:18:48.000000000 +0200
301 +buffer (1.19-7) unstable; urgency=low
303 + * Really changed priority this time. Sigh.
305 + -- Martin Buck <mbuck@debian.org> Sat, 1 Jan 2005 23:46:26 +0100
307 +buffer (1.19-6) unstable; urgency=low
309 + * Changed priority to optional. Closes: #283803
311 + -- Martin Buck <mbuck@debian.org> Thu, 30 Dec 2004 15:04:31 +0100
313 +buffer (1.19-5) unstable; urgency=low
315 + * Disabled obsolete declaration of shmat(). Closes: #260395
317 + -- Martin Buck <mbuck@debian.org> Tue, 27 Jul 2004 23:50:50 +0200
319 +buffer (1.19-4) unstable; urgency=low
321 + * Fixed hang when using option "-p 100". Closes: #224984
323 + -- Martin Buck <mbuck@debian.org> Sun, 11 Jan 2004 23:20:39 +0100
325 +buffer (1.19-3) unstable; urgency=low
327 + * Added largefile support. Closes: #156847
328 + * Made sure -S/-z works properly with files > 4 TB.
329 + * Upgraded to Standards-Version 3.5.8
331 + -- Martin Buck <mbuck@debian.org> Fri, 31 Jan 2003 23:55:43 +0100
333 +buffer (1.19-2) unstable; urgency=low
335 + * Fixed buffer overrun in option parsing.
336 + Fixed (rather theoretical) potential division by zero in
337 + throughput calculation.
340 + -- Martin Buck <mbuck@debian.org> Tue, 11 Dec 2001 23:34:46 +0100
342 +buffer (1.19-1) unstable; urgency=low
344 + * New upstream version. Closes: #91961
345 + * Added a few spelling fixes from FreeBSD version 1.17.1
346 + * Added (slightly modified version of) patch from Marc Schaefer that prints
347 + the throughput with option -S
348 + * Fixed a few gcc warnings
350 + -- Martin Buck <mbuck@debian.org> Thu, 5 Apr 2001 22:10:07 +0200
352 +buffer (1.17-6) unstable; urgency=low
354 + * Added Build-Depends. Closes: #70332
356 + -- Martin Buck <mbuck@debian.org> Mon, 5 Mar 2001 22:19:09 +0100
358 +buffer (1.17-5) unstable; urgency=low
360 + * Cleaned up debian/rules
361 + * Upgraded to Debian policy 3.0.1.1
363 + -- Martin Buck <mbuck@debian.org> Mon, 13 Sep 1999 23:19:57 +0200
365 +buffer (1.17-4) unstable; urgency=low
367 + * buffer now complains if non-option arguments are found
368 + * Document changes from original version in copyright-file
369 + * Checked conformance with Debian policy 2.5.0
371 + -- Martin Buck <mbuck@debian.org> Sun, 29 Aug 1999 00:57:03 +0200
373 +buffer (1.17-3) unstable; urgency=low
375 + * NMU; added missing SEM_SEMUN_UNDEFINED
379 + -- Hartmut Koptein <koptein@debian.org> Fri, 9 Jul 1999 10:04:49 +0200
381 +buffer (1.17-2) unstable; urgency=low
383 + * Applied patch from Paul Slootman (closes: Bug#26098):
384 + - egcs complains about NULL where union expected. Now it builds on Alpha.
385 + - typos in manpage fixed.
386 + * Switched from debstd to debhelper
388 + -- Martin Buck <mbuck@debian.org> Wed, 9 Sep 1998 22:35:29 +0200
390 +buffer (1.17-1) unstable; urgency=low
394 + -- Martin Buck <mbuck@debian.org> Wed, 27 Aug 1997 01:11:29 +0200
397 +mode: debian-changelog
399 diff -urNp buffer-1.19.orig/debian/control buffer-1.19/debian/control
400 --- buffer-1.19.orig/debian/control 1970-01-01 01:00:00.000000000 +0100
401 +++ buffer-1.19/debian/control 2008-09-20 01:18:48.000000000 +0200
406 +Maintainer: Martin Buck <mbuck@debian.org>
407 +Standards-Version: 3.5.8
408 +Build-Depends: debhelper (>= 4)
412 +Depends: ${shlibs:Depends}
413 +Description: Buffering/reblocking program for tape backups, printing, etc.
414 + Buffer implements double buffering and can be used to keep backup tapes
415 + streaming or printers printing. It can also be used to convert a data
416 + stream to a given output blocksize.
418 + Buffer uses shared memory to convert a variable input data rate to a
419 + constant output data rate. It is typically used in a pipe between a backup
420 + program and the tape device, but there are also other applications like
421 + buffering printer data in lpd's input filter.
422 diff -urNp buffer-1.19.orig/debian/copyright buffer-1.19/debian/copyright
423 --- buffer-1.19.orig/debian/copyright 1970-01-01 01:00:00.000000000 +0100
424 +++ buffer-1.19/debian/copyright 2008-09-20 01:18:48.000000000 +0200
426 +This package was debianized by Martin Buck mbuck@debian.org on
427 +Wed, 27 Aug 1997 01:11:29 +0200.
429 +It was downloaded from
430 +http://sunsite.org.uk/public/public/packages/buffer/
433 +GPL (see /usr/share/common-licenses/GPL)
434 +In addtion under NO circumstances can I (Lee McLoughlin), or Imperial
435 +College, be held liable for any event caused by the running or storing of
436 +this program or its documentation.
437 diff -urNp buffer-1.19.orig/debian/rules buffer-1.19/debian/rules
438 --- buffer-1.19.orig/debian/rules 1970-01-01 01:00:00.000000000 +0100
439 +++ buffer-1.19/debian/rules 2008-09-20 01:18:48.000000000 +0200
443 +export DH_COMPAT = 4
445 +CFLAGS = -g -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
447 +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
458 + make CFLAGS="$(CFLAGS)"
465 + -rm -f build-stamp install-stamp
469 +install: install-stamp
470 +install-stamp: build-stamp
474 + dh_installdirs usr/bin usr/share/man/man1
475 + make install INSTBIN=debian/buffer/usr/bin INSTMAN=debian/buffer/usr/share/man/man1 S=1
476 + touch install-stamp
478 +binary-indep: build install
480 +binary-arch: build install
483 + dh_installdocs README
484 +# dh_installexamples
491 + dh_installchangelogs
503 +binary: binary-indep binary-arch
504 +.PHONY: build clean binary-indep binary-arch binary install
505 diff -urNp buffer-1.19.orig/sem.c buffer-1.19/sem.c
506 --- buffer-1.19.orig/sem.c 2000-01-04 03:49:12.000000000 +0100
507 +++ buffer-1.19/sem.c 2008-09-20 01:18:48.000000000 +0200
513 #include <sys/types.h>
514 #include <sys/stat.h>
516 @@ -103,7 +119,7 @@ new_sems( nsems )
522 do_sem( sem_id, pbuf, err )
525 @@ -157,10 +173,13 @@ void
526 remove_sems( sem_id )
534 - if( semctl( sem_id, 0, IPC_RMID, NULL ) == -1 ){
536 + if( semctl( sem_id, 0, IPC_RMID, arg ) == -1 ){
538 perror( "internal error, failed to remove semaphore" );