11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993, 1994 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Keith Muller of the University of California, San Diego and Lance 71556Srgrimes * Visser of Convex Computer Corporation. 81556Srgrimes * 91556Srgrimes * Redistribution and use in source and binary forms, with or without 101556Srgrimes * modification, are permitted provided that the following conditions 111556Srgrimes * are met: 121556Srgrimes * 1. Redistributions of source code must retain the above copyright 131556Srgrimes * notice, this list of conditions and the following disclaimer. 141556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151556Srgrimes * notice, this list of conditions and the following disclaimer in the 161556Srgrimes * documentation and/or other materials provided with the distribution. 171556Srgrimes * 4. Neither the name of the University nor the names of its contributors 181556Srgrimes * may be used to endorse or promote products derived from this software 191556Srgrimes * without specific prior written permission. 201556Srgrimes * 211556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311556Srgrimes * SUCH DAMAGE. 321556Srgrimes */ 331556Srgrimes 341556Srgrimes#ifndef lint 3535773Scharnier#if 0 3636007Scharnierstatic char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; 3735773Scharnier#endif 381556Srgrimes#endif /* not lint */ 3999109Sobrien#include <sys/cdefs.h> 4099109Sobrien__FBSDID("$FreeBSD$"); 411556Srgrimes 4236007Scharnier#include <sys/types.h> 4319720Sphk#include <sys/time.h> 441556Srgrimes 4531746Seivind#include <errno.h> 46111629Smarkm#include <inttypes.h> 47250469Seadler#include <signal.h> 481556Srgrimes#include <stdio.h> 4978469Sdes#include <stdlib.h> 5098061Skeramida#include <string.h> 511556Srgrimes#include <unistd.h> 521556Srgrimes 531556Srgrimes#include "dd.h" 541556Srgrimes#include "extern.h" 551556Srgrimes 561556Srgrimesvoid 5790108Simpsummary(void) 581556Srgrimes{ 5919694Sphk struct timeval tv; 6019720Sphk double secs; 611556Srgrimes 62264577Sdelphij if (ddflags & C_NOINFO) 63264577Sdelphij return; 64264577Sdelphij 65239991Sed (void)gettimeofday(&tv, NULL); 6619720Sphk secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start; 6719720Sphk if (secs < 1e-6) 6819720Sphk secs = 1e-6; 69250469Seadler (void)fprintf(stderr, 70111629Smarkm "%ju+%ju records in\n%ju+%ju records out\n", 711556Srgrimes st.in_full, st.in_part, st.out_full, st.out_part); 72250469Seadler if (st.swab) 73250469Seadler (void)fprintf(stderr, "%ju odd length swab %s\n", 741556Srgrimes st.swab, (st.swab == 1) ? "block" : "blocks"); 75250469Seadler if (st.trunc) 76250469Seadler (void)fprintf(stderr, "%ju truncated %s\n", 771556Srgrimes st.trunc, (st.trunc == 1) ? "block" : "blocks"); 78264577Sdelphij if (!(ddflags & C_NOXFER)) { 79264577Sdelphij (void)fprintf(stderr, 80264577Sdelphij "%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n", 81264577Sdelphij st.bytes, secs, st.bytes / secs); 82264577Sdelphij } 83250469Seadler need_summary = 0; 841556Srgrimes} 851556Srgrimes 861556Srgrimes/* ARGSUSED */ 871556Srgrimesvoid 88250469Seadlersiginfo_handler(int signo __unused) 891556Srgrimes{ 901556Srgrimes 91250469Seadler need_summary = 1; 921556Srgrimes} 931556Srgrimes 941556Srgrimes/* ARGSUSED */ 951556Srgrimesvoid 9690108Simpterminate(int sig) 971556Srgrimes{ 981556Srgrimes 9978755Sdd summary(); 10078688Sdd _exit(sig == 0 ? 0 : 1); 1011556Srgrimes} 102