1 --- buffer-1.19.orig/buffer.man
2 +++ buffer-1.19/buffer.man
4 Use the given file as the output file. The default is stdout.
7 -After every chunk this size has been writen print out how much been writen so far.
8 +After every chunk of this size has been written, print out how much has
9 +been written so far. Also prints the total througput.
10 By default this is not set.
14 throughput on some drives.)
17 -Force each block writen to be padded out to the blocksize. This is needed by some tape
18 +Force each block written to be padded out to the blocksize. This is needed by some tape
19 and cartridge drives. Defaults to unpadded. This only affects the
24 On exiting print to stderr a brief message showing the total number of
27 If reading/writing directly to a character device (like a tape drive)
28 then after each gigabyte perform an lseek to the start of the file.
29 -Use this flag with extreme care. If can only be used on devices where
30 +Use this flag with extreme care. It can only be used on devices where
31 an lseek does not rewind the tape but does reset the kernels position
32 flags. It is used to allow more than 2 gigabytes to be written.
34 --- buffer-1.19.orig/buffer.c
35 +++ buffer-1.19/buffer.c
37 * Christoph Wicki <wicki@iis.ethz.ch>
39 * Revision 1.7 1992/07/23 20:42:03 lmjm
40 - * Added 't' option to print total writen at end.
41 + * Added 't' option to print total written at end.
43 * Revision 1.6 1992/04/07 19:57:30 lmjm
44 * Added Kevins -B and -p options.
46 * Make sofar printing size an option.
48 * Revision 1.3 90/05/15 23:27:46 lmjm
49 - * Added -S option (show how much has been writen).
50 + * Added -S option (show how much has been written).
51 * Added -m option to specify how much shared memory to grab.
52 * Now tries to fill this with blocks.
53 * reader waits for writer to terminate and then frees the shared mem and sems.
68 +#include <sys/time.h>
72 static char *rcsid = "$Header: /a/swan/home/swan/staff/csg/lmjm/src/buffer/RCS/buffer.c,v 1.19 1995/08/24 17:46:28 lmjm Exp lmjm $";
79 +#endif /* __linux__ */
87 +#if defined __GNUC__ || __STDC_VERSION__ >= 199901L
88 +#define NUM_K_TYPE unsigned long long
89 +#define NUM_K_FMT "llu"
91 +#define NUM_K_TYPE unsigned long
92 +#define NUM_K_FMT "lu"
95 /* Some forward declarations */
97 void start_reader_and_writer();
102 -/* When showing print a note every this many bytes writen */
103 +/* When showing print a note every this many bytes written */
105 #define PRINT_EVERY 10 K
109 char print_total = 0;
110 /* Number of K output */
111 -unsigned long outk = 0;
112 +NUM_K_TYPE outk = 0;
114 +struct timeval starttime;
123 + gettimeofday(&starttime, NULL);
125 start_reader_and_writer();
129 while( (c = getopt( argc, argv, "BS:Zdm:s:b:p:u:ti:o:z:" )) != -1 ){
131 - case 't': /* Print to stderr the total no of bytes writen */
132 + case 't': /* Print to stderr the total no of bytes written */
135 case 'u': /* pause after write for given microseconds */
137 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",
139 fprintf( stderr, "-B = blocked device - pad out last block\n" );
140 - fprintf( stderr, "-t = show total amount writen at end\n" );
141 - fprintf( stderr, "-S size = show amount writen every size bytes\n" );
142 + fprintf( stderr, "-t = show total amount written at end\n" );
143 + fprintf( stderr, "-S size = show amount written every size bytes\n" );
144 fprintf( stderr, "-m size = size of shared mem chunk to grab\n" );
145 fprintf( stderr, "-b num = number of blocks in queue\n" );
146 fprintf( stderr, "-p percent = don't start writing until percent blocks filled\n" );
152 + if (argc > optind) {
153 + fprintf( stderr, "too many arguments\n" );
157 if (zflag) showevery = blocksize;
163 - fprintf( stderr, "%s pbuffer is 0x%08x, buffer_size is %d [%d x %d]\n",
164 + fprintf( stderr, "%s pbuffer is 0x%08lx, buffer_size is %d [%d x %d]\n",
166 - (char *)pbuffer, buffer_size, blocks, blocksize );
167 + (unsigned long)pbuffer, buffer_size, blocks, blocksize );
170 memset( (char *)pbuffer, '\0', buffer_size );
172 pbuffer->blocks_free_lock = 1;
173 /* start this off so lock() can be called on it for each block
174 * till all the blocks are used up */
175 + /* Initializing the semaphore to "blocks - 1" causes a hang when using option
176 + * "-p 100" because it always keeps one block free, so we'll never reach 100% fill
177 + * level. However, there doesn't seem to be a good reason to keep one block free,
178 + * so we initialize the semaphore to "blocks" instead.
179 + * <mbuck@debian.org> 2004-01-11
182 sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks - 1 );
184 + sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks );
187 /* Detattach the shared memory so the fork doesnt do anything odd */
188 shmdt( (char *)pbuffer );
197 static char eof_reached = 0;
201 int maxfilled = (blocks * percent) / 100;
203 + int first_block = 0;
206 fprintf( stderr, "\tW: Entering writer\n blocks = %d\n maxfilled = %d\n",
211 - fprintf( stderr, "Kilobytes Out %lu\n", outk );
212 + fprintf( stderr, "Kilobytes Out %" NUM_K_FMT "\n", outk );
216 @@ -783,14 +814,14 @@
218 write_block_to_stdout()
220 - static unsigned long out = 0;
221 + unsigned long out = 0;
222 static unsigned long last_gb = 0;
223 - static unsigned long next_k = 0;
224 + static NUM_K_TYPE next_k = 0;
227 if( next_k == 0 && showevery ){
229 - fprintf( stderr, "W: next_k = %lu showevery = %d\n", next_k, showevery );
230 + fprintf( stderr, "W: next_k = %" NUM_K_FMT " showevery = %d\n", next_k, showevery );
231 showevery = showevery / 1024;
235 if( (written = write( fdout, curr_block->data, curr_block->bytes )) != curr_block->bytes ){
237 perror( "write of data failed" );
238 - fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10luK\n", curr_block->bytes, written, outk );
239 + fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10" NUM_K_FMT "K\n", curr_block->bytes, written, outk );
247 - fprintf( stderr, "W: outk = %lu, next_k = %lu\n",
248 + fprintf( stderr, "W: outk = %" NUM_K_FMT ", next_k = %" NUM_K_FMT "\n",
250 if( outk >= next_k ){
252 @@ -914,13 +945,12 @@
261 - sscanf( arg, "%d%s", &ret, format );
263 + sscanf( arg, "%d%c", &ret, &unit );
274 - fprintf( stderr, " %10luK\r", outk );
275 + struct timeval now;
276 + unsigned long ms_delta, k_per_s;
278 + gettimeofday(&now, NULL);
279 + ms_delta = (now.tv_sec - starttime.tv_sec) * 1000
280 + + (now.tv_usec - starttime.tv_usec) / 1000;
282 + /* Use increased accuracy for small amounts of data,
283 + * decreased accuracy for *huge* throughputs > 4.1GB/s
284 + * to avoid division by 0. This will overflow if your
285 + * machine's throughput exceeds 4TB/s - you deserve to
286 + * loose if you're still using 32 bit longs on such a
288 + * <mbuck@debian.org>
290 + if (outk < ULONG_MAX / 1000) {
291 + k_per_s = (outk * 1000) / ms_delta;
292 + } else if (ms_delta >= 1000) {
293 + k_per_s = outk / (ms_delta / 1000);
295 + k_per_s = (outk / ms_delta) * 1000;
297 + fprintf( stderr, " %10" NUM_K_FMT "K, %10luK/s\r", outk, k_per_s );
300 + fprintf( stderr, " %10" NUM_K_FMT "K, ?K/s\r", outk );
302 + fprintf( stderr, " 0K, 0K/s\r");
308 --- buffer-1.19.orig/sem.c
309 +++ buffer-1.19/sem.c
315 #include <sys/types.h>
316 #include <sys/stat.h>
322 +/* If we've got a version of glibc that doesn't define union semun, we do
323 + * it ourseleves like in semctl(2). Otherwise, fall back to the original
324 + * buffer behaviour of defining it (differetly!) only on some systems.
326 + * mbuck@debian.org, 1999/08/29
328 +#if defined(__GNU_LIBRARY__) && defined(_SEM_SEMUN_UNDEFINED)
330 + int val; /* value for SETVAL */
331 + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
332 + unsigned short int *array; /* array for GETALL & SETALL */
333 + struct seminfo *__buf; /* buffer for IPC_INFO */
336 #if defined(SYS5) || defined(ultrix) || defined(_AIX)
353 do_sem( sem_id, pbuf, err )
356 @@ -149,10 +165,13 @@
357 remove_sems( sem_id )
365 - if( semctl( sem_id, 0, IPC_RMID, NULL ) == -1 ){
367 + if( semctl( sem_id, 0, IPC_RMID, arg ) == -1 ){
369 perror( "internal error, failed to remove semaphore" );