/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1991, 1993, 19944* The Regents of the University of California. All rights reserved.5*6* This code is derived from software contributed to Berkeley by7* Keith Muller of the University of California, San Diego and Lance8* Visser of Convex Computer Corporation.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435/* Input/output stream state. */36typedef struct {37u_char *db; /* buffer address */38u_char *dbp; /* current buffer I/O address */39ssize_t dbcnt; /* current buffer byte count */40ssize_t dbrcnt; /* last read byte count */41ssize_t dbsz; /* block size */4243#define ISCHR 0x01 /* character device (warn on short) */44#define ISPIPE 0x02 /* pipe-like (see position.c) */45#define ISTAPE 0x04 /* tape */46#define ISSEEK 0x08 /* valid to seek on */47#define NOREAD 0x10 /* not readable */48#define ISTRUNC 0x20 /* valid to ftruncate() */49u_int flags;5051const char *name; /* name */52int fd; /* file descriptor */53off_t offset; /* # of blocks to skip */54off_t seek_offset; /* offset of last seek past output hole */55} IO;5657typedef struct {58uintmax_t in_full; /* # of full input blocks */59uintmax_t in_part; /* # of partial input blocks */60uintmax_t out_full; /* # of full output blocks */61uintmax_t out_part; /* # of partial output blocks */62uintmax_t trunc; /* # of truncated records */63uintmax_t swab; /* # of odd-length swab blocks */64uintmax_t bytes; /* # of bytes written */65struct timespec start; /* start time of dd */66} STAT;6768/* Flags (in ddflags). */69#define C_ASCII 0x0000000000000001ULL70#define C_BLOCK 0x0000000000000002ULL71#define C_BS 0x0000000000000004ULL72#define C_CBS 0x0000000000000008ULL73#define C_COUNT 0x0000000000000010ULL74#define C_EBCDIC 0x0000000000000020ULL75#define C_FILES 0x0000000000000040ULL76#define C_IBS 0x0000000000000080ULL77#define C_IF 0x0000000000000100ULL78#define C_LCASE 0x0000000000000200ULL79#define C_NOERROR 0x0000000000000400ULL80#define C_NOTRUNC 0x0000000000000800ULL81#define C_OBS 0x0000000000001000ULL82#define C_OF 0x0000000000002000ULL83#define C_OSYNC 0x0000000000004000ULL84#define C_PAREVEN 0x0000000000008000ULL85#define C_PARNONE 0x0000000000010000ULL86#define C_PARODD 0x0000000000020000ULL87#define C_PARSET 0x0000000000040000ULL88#define C_SEEK 0x0000000000080000ULL89#define C_SKIP 0x0000000000100000ULL90#define C_SPARSE 0x0000000000200000ULL91#define C_SWAB 0x0000000000400000ULL92#define C_SYNC 0x0000000000800000ULL93#define C_UCASE 0x0000000001000000ULL94#define C_UNBLOCK 0x0000000002000000ULL95#define C_FILL 0x0000000004000000ULL96#define C_STATUS 0x0000000008000000ULL97#define C_NOXFER 0x0000000010000000ULL98#define C_NOINFO 0x0000000020000000ULL99#define C_PROGRESS 0x0000000040000000ULL100#define C_FSYNC 0x0000000080000000ULL101#define C_FDATASYNC 0x0000000100000000ULL102#define C_OFSYNC 0x0000000200000000ULL103#define C_IFULLBLOCK 0x0000000400000000ULL104#define C_IDIRECT 0x0000000800000000ULL105#define C_ODIRECT 0x0000001000000000ULL106107#define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)108109#define BISZERO(p, s) ((s) > 0 && *((const char *)p) == 0 && !memcmp( \110(const void *)(p), (const void *) \111((const char *)p + 1), (s) - 1))112113114