xref: /freebsd/sbin/dump/dump.h (revision a770ae06)
18fae3551SRodney W. Grimes /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
48fae3551SRodney W. Grimes  * Copyright (c) 1980, 1993
58fae3551SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
68fae3551SRodney W. Grimes  *
78fae3551SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
88fae3551SRodney W. Grimes  * modification, are permitted provided that the following conditions
98fae3551SRodney W. Grimes  * are met:
108fae3551SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
118fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
128fae3551SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
138fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
148fae3551SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
168fae3551SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
178fae3551SRodney W. Grimes  *    without specific prior written permission.
188fae3551SRodney W. Grimes  *
198fae3551SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208fae3551SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218fae3551SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228fae3551SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238fae3551SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248fae3551SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258fae3551SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268fae3551SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278fae3551SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288fae3551SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298fae3551SRodney W. Grimes  * SUCH DAMAGE.
308fae3551SRodney W. Grimes  *
31a37c38b8SPeter Wemm  *	@(#)dump.h	8.2 (Berkeley) 4/28/95
32941ee632SPoul-Henning Kamp  *
33941ee632SPoul-Henning Kamp  * $FreeBSD$
348fae3551SRodney W. Grimes  */
358fae3551SRodney W. Grimes 
368fae3551SRodney W. Grimes /*
378fae3551SRodney W. Grimes  * Dump maps used to describe what is to be dumped.
388fae3551SRodney W. Grimes  */
398fae3551SRodney W. Grimes int	mapsize;	/* size of the state maps */
408fae3551SRodney W. Grimes char	*usedinomap;	/* map of allocated inodes */
418fae3551SRodney W. Grimes char	*dumpdirmap;	/* map of directories to be dumped */
428fae3551SRodney W. Grimes char	*dumpinomap;	/* map of files to be dumped */
438fae3551SRodney W. Grimes /*
448fae3551SRodney W. Grimes  * Map manipulation macros.
458fae3551SRodney W. Grimes  */
468fae3551SRodney W. Grimes #define	SETINO(ino, map) \
4789fdc4e1SMike Barcroft 	map[(u_int)((ino) - 1) / CHAR_BIT] |= \
4889fdc4e1SMike Barcroft 	    1 << ((u_int)((ino) - 1) % CHAR_BIT)
498fae3551SRodney W. Grimes #define	CLRINO(ino, map) \
5089fdc4e1SMike Barcroft 	map[(u_int)((ino) - 1) / CHAR_BIT] &= \
5189fdc4e1SMike Barcroft 	    ~(1 << ((u_int)((ino) - 1) % CHAR_BIT))
528fae3551SRodney W. Grimes #define	TSTINO(ino, map) \
5389fdc4e1SMike Barcroft 	(map[(u_int)((ino) - 1) / CHAR_BIT] & \
5489fdc4e1SMike Barcroft 	    (1 << ((u_int)((ino) - 1) % CHAR_BIT)))
558fae3551SRodney W. Grimes 
568fae3551SRodney W. Grimes /*
578fae3551SRodney W. Grimes  *	All calculations done in 0.1" units!
588fae3551SRodney W. Grimes  */
598fae3551SRodney W. Grimes char	*disk;		/* name of the disk file */
608fae3551SRodney W. Grimes char	*tape;		/* name of the tape file */
61c51d70c6SBrian Feldman char	*popenout;	/* popen(3) per-"tape" command */
628fae3551SRodney W. Grimes char	*dumpdates;	/* name of the file containing dump date information*/
638fae3551SRodney W. Grimes char	*temp;		/* name of the file for doing rewrite of dumpdates */
64f72ab793SKirk McKusick int	lastlevel;	/* dump level of previous dump */
65f72ab793SKirk McKusick int	level;		/* dump level of this dump */
668fae3551SRodney W. Grimes int	uflag;		/* update flag */
678fae3551SRodney W. Grimes int	diskfd;		/* disk file descriptor */
688fae3551SRodney W. Grimes int	tapefd;		/* tape file descriptor */
698fae3551SRodney W. Grimes int	pipeout;	/* true => output to standard output */
708fae3551SRodney W. Grimes ino_t	curino;		/* current inumber; used globally */
718fae3551SRodney W. Grimes int	newtape;	/* new tape flag */
728fae3551SRodney W. Grimes int	density;	/* density in 0.1" units */
738fae3551SRodney W. Grimes long	tapesize;	/* estimated tape size, blocks */
748fae3551SRodney W. Grimes long	tsize;		/* tape size in 0.1" units */
758fae3551SRodney W. Grimes long	asize;		/* number of 0.1" units written on current tape */
768fae3551SRodney W. Grimes int	etapes;		/* estimated number of tapes */
778fae3551SRodney W. Grimes int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
78af00957eSJoerg Wunsch int	unlimited;	/* if set, write to end of medium */
795941e412SMatthew Dillon int	cachesize;	/* size of block cache in bytes */
80693c40a3SKirk McKusick int	rsync_friendly;	/* be friendly with rsync */
818fae3551SRodney W. Grimes 
828fae3551SRodney W. Grimes int	notify;		/* notify operator flag */
838fae3551SRodney W. Grimes int	blockswritten;	/* number of blocks written on current tape */
848fae3551SRodney W. Grimes int	tapeno;		/* current tape number */
858fae3551SRodney W. Grimes time_t	tstart_writing;	/* when started writing the first tape block */
86019420a5SJoerg Wunsch time_t	tend_writing;	/* after writing the last tape block */
872bb823d2SIan Dowse int	passno;		/* current dump pass number */
888fae3551SRodney W. Grimes struct	fs *sblock;	/* the file system super block */
898fae3551SRodney W. Grimes char	sblock_buf[MAXBSIZE];
908fae3551SRodney W. Grimes long	dev_bsize;	/* block size of underlying disk device */
918fae3551SRodney W. Grimes int	dev_bshift;	/* log2(dev_bsize) */
928fae3551SRodney W. Grimes int	tp_bshift;	/* log2(TP_BSIZE) */
938fae3551SRodney W. Grimes 
948fae3551SRodney W. Grimes /* operator interface functions */
952db673abSWarner Losh void	broadcast(const char *message);
962db673abSWarner Losh void	infosch(int);
972db673abSWarner Losh void	lastdump(int arg);	/* int should be char */
982db673abSWarner Losh void	msg(const char *fmt, ...) __printflike(1, 2);
992db673abSWarner Losh void	msgtail(const char *fmt, ...) __printflike(1, 2);
1002db673abSWarner Losh int	query(const char *question);
1012db673abSWarner Losh void	quit(const char *fmt, ...) __printflike(1, 2);
1022db673abSWarner Losh void	timeest(void);
1032db673abSWarner Losh time_t	unctime(char *str);
1048fae3551SRodney W. Grimes 
1058fae3551SRodney W. Grimes /* mapping rouintes */
1061c85e6a3SKirk McKusick union	dinode;
1072db673abSWarner Losh int	mapfiles(ino_t maxino, long *tapesize);
1082db673abSWarner Losh int	mapdirs(ino_t maxino, long *tapesize);
1098fae3551SRodney W. Grimes 
1108fae3551SRodney W. Grimes /* file dumping routines */
111a770ae06SKirk McKusick void	blkread(ufs2_daddr_t blkno, char *buf, int size);
112ec3f495cSIan Dowse ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset);
1131c85e6a3SKirk McKusick void	dumpino(union dinode *dp, ino_t ino);
1142db673abSWarner Losh void	dumpmap(char *map, int type, ino_t ino);
1152db673abSWarner Losh void	writeheader(ino_t ino);
1168fae3551SRodney W. Grimes 
1178fae3551SRodney W. Grimes /* tape writing routines */
1182db673abSWarner Losh int	alloctape(void);
1192db673abSWarner Losh void	close_rewind(void);
1201c85e6a3SKirk McKusick void	dumpblock(ufs2_daddr_t blkno, int size);
1212db673abSWarner Losh void	startnewtape(int top);
1222db673abSWarner Losh void	trewind(void);
1232db673abSWarner Losh void	writerec(char *dp, int isspcl);
1248fae3551SRodney W. Grimes 
1252db673abSWarner Losh void	Exit(int status) __dead2;
1264787668fSEitan Adler void	dumpabort(int signo) __dead2;
127a3165d16SMatthew N. Dodd void	dump_getfstab(void);
1288fae3551SRodney W. Grimes 
1292db673abSWarner Losh char	*rawname(char *cp);
130a770ae06SKirk McKusick union	dinode *getinode(ino_t inum, int *mode);
1318fae3551SRodney W. Grimes 
1328fae3551SRodney W. Grimes /* rdump routines */
1338fae3551SRodney W. Grimes #ifdef RDUMP
1342db673abSWarner Losh void	rmtclose(void);
1352db673abSWarner Losh int	rmthost(const char *host);
1362db673abSWarner Losh int	rmtopen(const char *tape, int mode);
1372db673abSWarner Losh int	rmtwrite(const char *buf, int count);
1388fae3551SRodney W. Grimes #endif /* RDUMP */
1398fae3551SRodney W. Grimes 
1402db673abSWarner Losh void	interrupt(int signo);	/* in case operator bangs on console */
1418fae3551SRodney W. Grimes 
1428fae3551SRodney W. Grimes /*
1438fae3551SRodney W. Grimes  *	Exit status codes
1448fae3551SRodney W. Grimes  */
1458fae3551SRodney W. Grimes #define	X_FINOK		0	/* normal exit */
146f69e804dSJoseph Koshy #define	X_STARTUP	1	/* startup error */
1478fae3551SRodney W. Grimes #define	X_REWRITE	2	/* restart writing from the check point */
1488fae3551SRodney W. Grimes #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
1498fae3551SRodney W. Grimes 
1508fae3551SRodney W. Grimes #define	OPGRENT	"operator"		/* group entry to notify */
1518fae3551SRodney W. Grimes 
1522db673abSWarner Losh struct	fstab *fstabsearch(const char *key); /* search fs_file and fs_spec */
1538fae3551SRodney W. Grimes 
1548fae3551SRodney W. Grimes #ifndef NAME_MAX
1558fae3551SRodney W. Grimes #define NAME_MAX 255
1568fae3551SRodney W. Grimes #endif
1578fae3551SRodney W. Grimes 
1588fae3551SRodney W. Grimes /*
1598fae3551SRodney W. Grimes  *	The contents of the file _PATH_DUMPDATES is maintained both on
1608fae3551SRodney W. Grimes  *	a linked list, and then (eventually) arrayified.
1618fae3551SRodney W. Grimes  */
1628fae3551SRodney W. Grimes struct dumpdates {
1638fae3551SRodney W. Grimes 	char	dd_name[NAME_MAX+3];
164f72ab793SKirk McKusick 	int	dd_level;
1658fae3551SRodney W. Grimes 	time_t	dd_ddate;
1668fae3551SRodney W. Grimes };
1678fae3551SRodney W. Grimes int	nddates;		/* number of records (might be zero) */
1688fae3551SRodney W. Grimes struct	dumpdates **ddatev;	/* the arrayfied version */
1692db673abSWarner Losh void	initdumptimes(void);
1702db673abSWarner Losh void	getdumptime(void);
1712db673abSWarner Losh void	putdumptime(void);
1728fae3551SRodney W. Grimes #define	ITITERATE(i, ddp) \
173ad0c89f7SMaxim Konovalov     	if (ddatev != NULL) \
1748fae3551SRodney W. Grimes 		for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
1758fae3551SRodney W. Grimes 
17623ad9069SKirk McKusick #define	DUMPFMTLEN	53			/* max device pathname length */
17723ad9069SKirk McKusick #define	DUMPOUTFMT	"%-*s %d %s"		/* for printf */
178f72ab793SKirk McKusick 						/* name, level, ctime(date) */
17923ad9069SKirk McKusick #define	DUMPINFMT	"%s %d %[^\n]\n"	/* inverse for scanf */
180f72ab793SKirk McKusick 
1812db673abSWarner Losh void	sig(int signo);
1828fae3551SRodney W. Grimes 
1838fae3551SRodney W. Grimes #ifndef	_PATH_FSTAB
1848fae3551SRodney W. Grimes #define	_PATH_FSTAB	"/etc/fstab"
1858fae3551SRodney W. Grimes #endif
186