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 *	@(#)dd.h	8.3 (Berkeley) 4/2/94
3450471Speter * $FreeBSD: stable/11/bin/dd/dd.h 342167 2018-12-17 15:19:48Z sobomax $
351556Srgrimes */
361556Srgrimes
371556Srgrimes/* Input/output stream state. */
381556Srgrimestypedef struct {
3951249Sgreen	u_char		*db;		/* buffer address */
4051249Sgreen	u_char		*dbp;		/* current buffer I/O address */
41273743Spi	/* XXX ssize_t? */
42273743Spi	size_t		dbcnt;		/* current buffer byte count */
43273743Spi	size_t		dbrcnt;		/* last read byte count */
44273743Spi	size_t		dbsz;		/* block size */
451556Srgrimes
461556Srgrimes#define	ISCHR		0x01		/* character device (warn on short) */
4762311Sgreen#define	ISPIPE		0x02		/* pipe-like (see position.c) */
4851249Sgreen#define	ISTAPE		0x04		/* tape */
4951212Sgreen#define	ISSEEK		0x08		/* valid to seek on */
5048802Sgreen#define	NOREAD		0x10		/* not readable */
5162311Sgreen#define	ISTRUNC		0x20		/* valid to ftruncate() */
5251249Sgreen	u_int		flags;
531556Srgrimes
54126690Sbde	const char	*name;		/* name */
5551249Sgreen	int		fd;		/* file descriptor */
5651249Sgreen	off_t		offset;		/* # of blocks to skip */
57295749Sthomas	off_t		seek_offset;	/* offset of last seek past output hole */
581556Srgrimes} IO;
591556Srgrimes
601556Srgrimestypedef struct {
61273743Spi	uintmax_t	in_full;	/* # of full input blocks */
62273743Spi	uintmax_t	in_part;	/* # of partial input blocks */
63273743Spi	uintmax_t	out_full;	/* # of full output blocks */
64273743Spi	uintmax_t	out_part;	/* # of partial output blocks */
65273743Spi	uintmax_t	trunc;		/* # of truncated records */
66273743Spi	uintmax_t	swab;		/* # of odd-length swab blocks */
67273743Spi	uintmax_t	bytes;		/* # of bytes written */
68265698Sasomers	struct timespec	start;		/* start time of dd */
691556Srgrimes} STAT;
701556Srgrimes
711556Srgrimes/* Flags (in ddflags). */
72264067Sdelphij#define	C_ASCII		0x00000001
73264067Sdelphij#define	C_BLOCK		0x00000002
74264067Sdelphij#define	C_BS		0x00000004
75264067Sdelphij#define	C_CBS		0x00000008
76264067Sdelphij#define	C_COUNT		0x00000010
77264067Sdelphij#define	C_EBCDIC	0x00000020
78264067Sdelphij#define	C_FILES		0x00000040
79264067Sdelphij#define	C_IBS		0x00000080
80264067Sdelphij#define	C_IF		0x00000100
81264067Sdelphij#define	C_LCASE		0x00000200
82264067Sdelphij#define	C_NOERROR	0x00000400
83264067Sdelphij#define	C_NOTRUNC	0x00000800
84264067Sdelphij#define	C_OBS		0x00001000
85264067Sdelphij#define	C_OF		0x00002000
86264067Sdelphij#define	C_OSYNC		0x00004000
87264067Sdelphij#define	C_PAREVEN	0x00008000
88264067Sdelphij#define	C_PARNONE	0x00010000
89264067Sdelphij#define	C_PARODD	0x00020000
90264067Sdelphij#define	C_PARSET	0x00040000
91264067Sdelphij#define	C_SEEK		0x00080000
92264067Sdelphij#define	C_SKIP		0x00100000
93264067Sdelphij#define	C_SPARSE	0x00200000
94264067Sdelphij#define	C_SWAB		0x00400000
95264067Sdelphij#define	C_SYNC		0x00800000
96264067Sdelphij#define	C_UCASE		0x01000000
97264067Sdelphij#define	C_UNBLOCK	0x02000000
98264067Sdelphij#define	C_FILL		0x04000000
99264067Sdelphij#define	C_STATUS	0x08000000
100264067Sdelphij#define	C_NOXFER	0x10000000
101264067Sdelphij#define	C_NOINFO	0x20000000
102338364Skevans#define	C_PROGRESS	0x40000000
103126667Sphk
104126690Sbde#define	C_PARITY	(C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
105342167Ssobomax
106342167Ssobomax#define	BISZERO(p, s)	((s) > 0 && *((const char *)p) == 0 && !memcmp( \
107342167Ssobomax			    (const void *)(p), (const void *) \
108342167Ssobomax			    ((const char *)p + 1), (s) - 1))
109