14b88c807SRodney W. Grimes /*- 28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 38a16b7a1SPedro F. Giffuni * 44b88c807SRodney W. Grimes * Copyright (c) 1991, 1993, 1994 54b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 64b88c807SRodney W. Grimes * 74b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 84b88c807SRodney W. Grimes * Keith Muller of the University of California, San Diego and Lance 94b88c807SRodney W. Grimes * Visser of Convex Computer Corporation. 104b88c807SRodney W. Grimes * 114b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 124b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 134b88c807SRodney W. Grimes * are met: 144b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 154b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 164b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 174b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 184b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 19fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 204b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 214b88c807SRodney W. Grimes * without specific prior written permission. 224b88c807SRodney W. Grimes * 234b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 244b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 254b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 264b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 274b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 284b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 294b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 304b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 314b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 324b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 334b88c807SRodney W. Grimes * SUCH DAMAGE. 344b88c807SRodney W. Grimes */ 354b88c807SRodney W. Grimes 364b88c807SRodney W. Grimes /* Input/output stream state. */ 374b88c807SRodney W. Grimes typedef struct { 384b88c807SRodney W. Grimes u_char *db; /* buffer address */ 394b88c807SRodney W. Grimes u_char *dbp; /* current buffer I/O address */ 4077a798b3SAlan Somers ssize_t dbcnt; /* current buffer byte count */ 4177a798b3SAlan Somers ssize_t dbrcnt; /* last read byte count */ 4277a798b3SAlan Somers ssize_t dbsz; /* block size */ 434b88c807SRodney W. Grimes 444b88c807SRodney W. Grimes #define ISCHR 0x01 /* character device (warn on short) */ 45c15c898eSBrian Feldman #define ISPIPE 0x02 /* pipe-like (see position.c) */ 467599187eSBrian Feldman #define ISTAPE 0x04 /* tape */ 4732952d4bSBrian Feldman #define ISSEEK 0x08 /* valid to seek on */ 48769e5815SBrian Feldman #define NOREAD 0x10 /* not readable */ 49c15c898eSBrian Feldman #define ISTRUNC 0x20 /* valid to ftruncate() */ 504b88c807SRodney W. Grimes u_int flags; 514b88c807SRodney W. Grimes 52c15c898eSBrian Feldman const char *name; /* name */ 534b88c807SRodney W. Grimes int fd; /* file descriptor */ 54767bc8adSBrian Feldman off_t offset; /* # of blocks to skip */ 55cd1832feSThomas Quinot off_t seek_offset; /* offset of last seek past output hole */ 564b88c807SRodney W. Grimes } IO; 574b88c807SRodney W. Grimes 584b88c807SRodney W. Grimes typedef struct { 59f4cfd28bSKurt Jaeger uintmax_t in_full; /* # of full input blocks */ 60f4cfd28bSKurt Jaeger uintmax_t in_part; /* # of partial input blocks */ 61f4cfd28bSKurt Jaeger uintmax_t out_full; /* # of full output blocks */ 62f4cfd28bSKurt Jaeger uintmax_t out_part; /* # of partial output blocks */ 63f4cfd28bSKurt Jaeger uintmax_t trunc; /* # of truncated records */ 64f4cfd28bSKurt Jaeger uintmax_t swab; /* # of odd-length swab blocks */ 65f4cfd28bSKurt Jaeger uintmax_t bytes; /* # of bytes written */ 66540c7825SAlan Somers struct timespec start; /* start time of dd */ 674b88c807SRodney W. Grimes } STAT; 684b88c807SRodney W. Grimes 694b88c807SRodney W. Grimes /* Flags (in ddflags). */ 703b96efbdSMatt Macy #define C_ASCII 0x0000000000000001ULL 713b96efbdSMatt Macy #define C_BLOCK 0x0000000000000002ULL 723b96efbdSMatt Macy #define C_BS 0x0000000000000004ULL 733b96efbdSMatt Macy #define C_CBS 0x0000000000000008ULL 743b96efbdSMatt Macy #define C_COUNT 0x0000000000000010ULL 753b96efbdSMatt Macy #define C_EBCDIC 0x0000000000000020ULL 763b96efbdSMatt Macy #define C_FILES 0x0000000000000040ULL 773b96efbdSMatt Macy #define C_IBS 0x0000000000000080ULL 783b96efbdSMatt Macy #define C_IF 0x0000000000000100ULL 793b96efbdSMatt Macy #define C_LCASE 0x0000000000000200ULL 803b96efbdSMatt Macy #define C_NOERROR 0x0000000000000400ULL 813b96efbdSMatt Macy #define C_NOTRUNC 0x0000000000000800ULL 823b96efbdSMatt Macy #define C_OBS 0x0000000000001000ULL 833b96efbdSMatt Macy #define C_OF 0x0000000000002000ULL 843b96efbdSMatt Macy #define C_OSYNC 0x0000000000004000ULL 853b96efbdSMatt Macy #define C_PAREVEN 0x0000000000008000ULL 863b96efbdSMatt Macy #define C_PARNONE 0x0000000000010000ULL 873b96efbdSMatt Macy #define C_PARODD 0x0000000000020000ULL 883b96efbdSMatt Macy #define C_PARSET 0x0000000000040000ULL 893b96efbdSMatt Macy #define C_SEEK 0x0000000000080000ULL 903b96efbdSMatt Macy #define C_SKIP 0x0000000000100000ULL 913b96efbdSMatt Macy #define C_SPARSE 0x0000000000200000ULL 923b96efbdSMatt Macy #define C_SWAB 0x0000000000400000ULL 933b96efbdSMatt Macy #define C_SYNC 0x0000000000800000ULL 943b96efbdSMatt Macy #define C_UCASE 0x0000000001000000ULL 953b96efbdSMatt Macy #define C_UNBLOCK 0x0000000002000000ULL 963b96efbdSMatt Macy #define C_FILL 0x0000000004000000ULL 973b96efbdSMatt Macy #define C_STATUS 0x0000000008000000ULL 983b96efbdSMatt Macy #define C_NOXFER 0x0000000010000000ULL 993b96efbdSMatt Macy #define C_NOINFO 0x0000000020000000ULL 1003b96efbdSMatt Macy #define C_PROGRESS 0x0000000040000000ULL 1013b96efbdSMatt Macy #define C_FSYNC 0x0000000080000000ULL 1023b96efbdSMatt Macy #define C_FDATASYNC 0x0000000100000000ULL 103919156e3SMatt Macy #define C_OFSYNC 0x0000000200000000ULL 104b52c534bSMatt Macy #define C_IFULLBLOCK 0x0000000400000000ULL 105*f4b4526fSRichard Scheffenegger #define C_IDIRECT 0x0000000800000000ULL 106*f4b4526fSRichard Scheffenegger #define C_ODIRECT 0x0000001000000000ULL 1076a3d33acSPoul-Henning Kamp 108d493ed0fSBruce Evans #define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET) 109dead7b5eSMaxim Sobolev 110dead7b5eSMaxim Sobolev #define BISZERO(p, s) ((s) > 0 && *((const char *)p) == 0 && !memcmp( \ 111dead7b5eSMaxim Sobolev (const void *)(p), (const void *) \ 112dead7b5eSMaxim Sobolev ((const char *)p + 1), (s) - 1)) 113