xref: /freebsd/sbin/dump/dump.h (revision 4787668f1aaff6ffafc4f51b885355b6761787b7)
18fae3551SRodney W. Grimes /*-
28fae3551SRodney W. Grimes  * Copyright (c) 1980, 1993
38fae3551SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
48fae3551SRodney W. Grimes  *
58fae3551SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
68fae3551SRodney W. Grimes  * modification, are permitted provided that the following conditions
78fae3551SRodney W. Grimes  * are met:
88fae3551SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
98fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
108fae3551SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
118fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
128fae3551SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
138fae3551SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
148fae3551SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
158fae3551SRodney W. Grimes  *    without specific prior written permission.
168fae3551SRodney W. Grimes  *
178fae3551SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
188fae3551SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
198fae3551SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
208fae3551SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
218fae3551SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
228fae3551SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
238fae3551SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
248fae3551SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
258fae3551SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
268fae3551SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
278fae3551SRodney W. Grimes  * SUCH DAMAGE.
288fae3551SRodney W. Grimes  *
29a37c38b8SPeter Wemm  *	@(#)dump.h	8.2 (Berkeley) 4/28/95
30941ee632SPoul-Henning Kamp  *
31941ee632SPoul-Henning Kamp  * $FreeBSD$
328fae3551SRodney W. Grimes  */
338fae3551SRodney W. Grimes 
348fae3551SRodney W. Grimes /*
358fae3551SRodney W. Grimes  * Dump maps used to describe what is to be dumped.
368fae3551SRodney W. Grimes  */
378fae3551SRodney W. Grimes int	mapsize;	/* size of the state maps */
388fae3551SRodney W. Grimes char	*usedinomap;	/* map of allocated inodes */
398fae3551SRodney W. Grimes char	*dumpdirmap;	/* map of directories to be dumped */
408fae3551SRodney W. Grimes char	*dumpinomap;	/* map of files to be dumped */
418fae3551SRodney W. Grimes /*
428fae3551SRodney W. Grimes  * Map manipulation macros.
438fae3551SRodney W. Grimes  */
448fae3551SRodney W. Grimes #define	SETINO(ino, map) \
4589fdc4e1SMike Barcroft 	map[(u_int)((ino) - 1) / CHAR_BIT] |= \
4689fdc4e1SMike Barcroft 	    1 << ((u_int)((ino) - 1) % CHAR_BIT)
478fae3551SRodney W. Grimes #define	CLRINO(ino, map) \
4889fdc4e1SMike Barcroft 	map[(u_int)((ino) - 1) / CHAR_BIT] &= \
4989fdc4e1SMike Barcroft 	    ~(1 << ((u_int)((ino) - 1) % CHAR_BIT))
508fae3551SRodney W. Grimes #define	TSTINO(ino, map) \
5189fdc4e1SMike Barcroft 	(map[(u_int)((ino) - 1) / CHAR_BIT] & \
5289fdc4e1SMike Barcroft 	    (1 << ((u_int)((ino) - 1) % CHAR_BIT)))
538fae3551SRodney W. Grimes 
548fae3551SRodney W. Grimes /*
558fae3551SRodney W. Grimes  *	All calculations done in 0.1" units!
568fae3551SRodney W. Grimes  */
578fae3551SRodney W. Grimes char	*disk;		/* name of the disk file */
588fae3551SRodney W. Grimes char	*tape;		/* name of the tape file */
59c51d70c6SBrian Feldman char	*popenout;	/* popen(3) per-"tape" command */
608fae3551SRodney W. Grimes char	*dumpdates;	/* name of the file containing dump date information*/
618fae3551SRodney W. Grimes char	*temp;		/* name of the file for doing rewrite of dumpdates */
62f72ab793SKirk McKusick int	lastlevel;	/* dump level of previous dump */
63f72ab793SKirk McKusick int	level;		/* dump level of this dump */
648fae3551SRodney W. Grimes int	uflag;		/* update flag */
658fae3551SRodney W. Grimes int	diskfd;		/* disk file descriptor */
668fae3551SRodney W. Grimes int	tapefd;		/* tape file descriptor */
678fae3551SRodney W. Grimes int	pipeout;	/* true => output to standard output */
688fae3551SRodney W. Grimes ino_t	curino;		/* current inumber; used globally */
698fae3551SRodney W. Grimes int	newtape;	/* new tape flag */
708fae3551SRodney W. Grimes int	density;	/* density in 0.1" units */
718fae3551SRodney W. Grimes long	tapesize;	/* estimated tape size, blocks */
728fae3551SRodney W. Grimes long	tsize;		/* tape size in 0.1" units */
738fae3551SRodney W. Grimes long	asize;		/* number of 0.1" units written on current tape */
748fae3551SRodney W. Grimes int	etapes;		/* estimated number of tapes */
758fae3551SRodney W. Grimes int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
76af00957eSJoerg Wunsch int	unlimited;	/* if set, write to end of medium */
775941e412SMatthew Dillon int	cachesize;	/* size of block cache in bytes */
78693c40a3SKirk McKusick int	rsync_friendly;	/* be friendly with rsync */
798fae3551SRodney W. Grimes 
808fae3551SRodney W. Grimes int	notify;		/* notify operator flag */
818fae3551SRodney W. Grimes int	blockswritten;	/* number of blocks written on current tape */
828fae3551SRodney W. Grimes int	tapeno;		/* current tape number */
838fae3551SRodney W. Grimes time_t	tstart_writing;	/* when started writing the first tape block */
84019420a5SJoerg Wunsch time_t	tend_writing;	/* after writing the last tape block */
852bb823d2SIan Dowse int	passno;		/* current dump pass number */
868fae3551SRodney W. Grimes struct	fs *sblock;	/* the file system super block */
878fae3551SRodney W. Grimes char	sblock_buf[MAXBSIZE];
888fae3551SRodney W. Grimes long	dev_bsize;	/* block size of underlying disk device */
898fae3551SRodney W. Grimes int	dev_bshift;	/* log2(dev_bsize) */
908fae3551SRodney W. Grimes int	tp_bshift;	/* log2(TP_BSIZE) */
918fae3551SRodney W. Grimes 
928fae3551SRodney W. Grimes /* operator interface functions */
932db673abSWarner Losh void	broadcast(const char *message);
942db673abSWarner Losh void	infosch(int);
952db673abSWarner Losh void	lastdump(int arg);	/* int should be char */
962db673abSWarner Losh void	msg(const char *fmt, ...) __printflike(1, 2);
972db673abSWarner Losh void	msgtail(const char *fmt, ...) __printflike(1, 2);
982db673abSWarner Losh int	query(const char *question);
992db673abSWarner Losh void	quit(const char *fmt, ...) __printflike(1, 2);
1002db673abSWarner Losh void	timeest(void);
1012db673abSWarner Losh time_t	unctime(char *str);
1028fae3551SRodney W. Grimes 
1038fae3551SRodney W. Grimes /* mapping rouintes */
1041c85e6a3SKirk McKusick union	dinode;
1052db673abSWarner Losh int	mapfiles(ino_t maxino, long *tapesize);
1062db673abSWarner Losh int	mapdirs(ino_t maxino, long *tapesize);
1078fae3551SRodney W. Grimes 
1088fae3551SRodney W. Grimes /* file dumping routines */
1091c85e6a3SKirk McKusick void	bread(ufs2_daddr_t blkno, char *buf, int size);
110ec3f495cSIan Dowse ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset);
1111c85e6a3SKirk McKusick void	dumpino(union dinode *dp, ino_t ino);
1122db673abSWarner Losh void	dumpmap(char *map, int type, ino_t ino);
1132db673abSWarner Losh void	writeheader(ino_t ino);
1148fae3551SRodney W. Grimes 
1158fae3551SRodney W. Grimes /* tape writing routines */
1162db673abSWarner Losh int	alloctape(void);
1172db673abSWarner Losh void	close_rewind(void);
1181c85e6a3SKirk McKusick void	dumpblock(ufs2_daddr_t blkno, int size);
1192db673abSWarner Losh void	startnewtape(int top);
1202db673abSWarner Losh void	trewind(void);
1212db673abSWarner Losh void	writerec(char *dp, int isspcl);
1228fae3551SRodney W. Grimes 
1232db673abSWarner Losh void	Exit(int status) __dead2;
124*4787668fSEitan Adler void	dumpabort(int signo) __dead2;
125a3165d16SMatthew N. Dodd void	dump_getfstab(void);
1268fae3551SRodney W. Grimes 
1272db673abSWarner Losh char	*rawname(char *cp);
1281c85e6a3SKirk McKusick union	dinode *getino(ino_t inum, int *mode);
1298fae3551SRodney W. Grimes 
1308fae3551SRodney W. Grimes /* rdump routines */
1318fae3551SRodney W. Grimes #ifdef RDUMP
1322db673abSWarner Losh void	rmtclose(void);
1332db673abSWarner Losh int	rmthost(const char *host);
1342db673abSWarner Losh int	rmtopen(const char *tape, int mode);
1352db673abSWarner Losh int	rmtwrite(const char *buf, int count);
1368fae3551SRodney W. Grimes #endif /* RDUMP */
1378fae3551SRodney W. Grimes 
1382db673abSWarner Losh void	interrupt(int signo);	/* in case operator bangs on console */
1398fae3551SRodney W. Grimes 
1408fae3551SRodney W. Grimes /*
1418fae3551SRodney W. Grimes  *	Exit status codes
1428fae3551SRodney W. Grimes  */
1438fae3551SRodney W. Grimes #define	X_FINOK		0	/* normal exit */
144f69e804dSJoseph Koshy #define	X_STARTUP	1	/* startup error */
1458fae3551SRodney W. Grimes #define	X_REWRITE	2	/* restart writing from the check point */
1468fae3551SRodney W. Grimes #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
1478fae3551SRodney W. Grimes 
1488fae3551SRodney W. Grimes #define	OPGRENT	"operator"		/* group entry to notify */
1498fae3551SRodney W. Grimes 
1502db673abSWarner Losh struct	fstab *fstabsearch(const char *key); /* search fs_file and fs_spec */
1518fae3551SRodney W. Grimes 
1528fae3551SRodney W. Grimes #ifndef NAME_MAX
1538fae3551SRodney W. Grimes #define NAME_MAX 255
1548fae3551SRodney W. Grimes #endif
1558fae3551SRodney W. Grimes 
1568fae3551SRodney W. Grimes /*
1578fae3551SRodney W. Grimes  *	The contents of the file _PATH_DUMPDATES is maintained both on
1588fae3551SRodney W. Grimes  *	a linked list, and then (eventually) arrayified.
1598fae3551SRodney W. Grimes  */
1608fae3551SRodney W. Grimes struct dumpdates {
1618fae3551SRodney W. Grimes 	char	dd_name[NAME_MAX+3];
162f72ab793SKirk McKusick 	int	dd_level;
1638fae3551SRodney W. Grimes 	time_t	dd_ddate;
1648fae3551SRodney W. Grimes };
1658fae3551SRodney W. Grimes int	nddates;		/* number of records (might be zero) */
1668fae3551SRodney W. Grimes struct	dumpdates **ddatev;	/* the arrayfied version */
1672db673abSWarner Losh void	initdumptimes(void);
1682db673abSWarner Losh void	getdumptime(void);
1692db673abSWarner Losh void	putdumptime(void);
1708fae3551SRodney W. Grimes #define	ITITERATE(i, ddp) \
171ad0c89f7SMaxim Konovalov     	if (ddatev != NULL) \
1728fae3551SRodney W. Grimes 		for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
1738fae3551SRodney W. Grimes 
17423ad9069SKirk McKusick #define	DUMPFMTLEN	53			/* max device pathname length */
17523ad9069SKirk McKusick #define	DUMPOUTFMT	"%-*s %d %s"		/* for printf */
176f72ab793SKirk McKusick 						/* name, level, ctime(date) */
17723ad9069SKirk McKusick #define	DUMPINFMT	"%s %d %[^\n]\n"	/* inverse for scanf */
178f72ab793SKirk McKusick 
1792db673abSWarner Losh void	sig(int signo);
1808fae3551SRodney W. Grimes 
1818fae3551SRodney W. Grimes #ifndef	_PATH_FSTAB
1828fae3551SRodney W. Grimes #define	_PATH_FSTAB	"/etc/fstab"
1838fae3551SRodney W. Grimes #endif
184