xref: /freebsd/sbin/dump/dump.h (revision 26e69f9f)
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  */
318fae3551SRodney W. Grimes 
328fae3551SRodney W. Grimes /*
338fae3551SRodney W. Grimes  * Dump maps used to describe what is to be dumped.
348fae3551SRodney W. Grimes  */
3533ceb489SKirk McKusick extern	int mapsize;		/* size of the state maps */
3633ceb489SKirk McKusick extern	char *usedinomap;	/* map of allocated inodes */
3733ceb489SKirk McKusick extern	char *dumpdirmap;	/* map of directories to be dumped */
3833ceb489SKirk McKusick extern	char *dumpinomap;	/* map of files to be dumped */
398fae3551SRodney W. Grimes /*
408fae3551SRodney W. Grimes  * Map manipulation macros.
418fae3551SRodney W. Grimes  */
428fae3551SRodney W. Grimes #define	SETINO(ino, map) \
4389fdc4e1SMike Barcroft 	map[(u_int)((ino) - 1) / CHAR_BIT] |= \
4489fdc4e1SMike Barcroft 	    1 << ((u_int)((ino) - 1) % CHAR_BIT)
458fae3551SRodney W. Grimes #define	CLRINO(ino, map) \
4689fdc4e1SMike Barcroft 	map[(u_int)((ino) - 1) / CHAR_BIT] &= \
4789fdc4e1SMike Barcroft 	    ~(1 << ((u_int)((ino) - 1) % CHAR_BIT))
488fae3551SRodney W. Grimes #define	TSTINO(ino, map) \
4989fdc4e1SMike Barcroft 	(map[(u_int)((ino) - 1) / CHAR_BIT] & \
5089fdc4e1SMike Barcroft 	    (1 << ((u_int)((ino) - 1) % CHAR_BIT)))
518fae3551SRodney W. Grimes 
528fae3551SRodney W. Grimes /*
538fae3551SRodney W. Grimes  *	All calculations done in 0.1" units!
548fae3551SRodney W. Grimes  */
5533ceb489SKirk McKusick extern	char *disk;		/* name of the disk file */
5633ceb489SKirk McKusick extern	char *tape;		/* name of the tape file */
5733ceb489SKirk McKusick extern	char *popenout;		/* popen(3) per-"tape" command */
5833ceb489SKirk McKusick extern	char *dumpdates;	/* name of the file containing dump date info */
5933ceb489SKirk McKusick extern	int lastlevel;		/* dump level of previous dump */
6033ceb489SKirk McKusick extern	int level;		/* dump level of this dump */
6133ceb489SKirk McKusick extern	int uflag;		/* update flag */
6233ceb489SKirk McKusick extern	int diskfd;		/* disk file descriptor */
6333ceb489SKirk McKusick extern	int pipeout;		/* true => output to standard output */
6433ceb489SKirk McKusick extern	ino_t curino;		/* current inumber; used globally */
6533ceb489SKirk McKusick extern	int newtape;		/* new tape flag */
6633ceb489SKirk McKusick extern	int density;		/* density in 0.1" units */
6733ceb489SKirk McKusick extern	long tapesize;		/* estimated tape size, blocks */
6833ceb489SKirk McKusick extern	long tsize;		/* tape size in 0.1" units */
6933ceb489SKirk McKusick extern	int etapes;		/* estimated number of tapes */
7033ceb489SKirk McKusick extern	int nonodump;		/* if set, do not honor UF_NODUMP user flags */
7133ceb489SKirk McKusick extern	int unlimited;		/* if set, write to end of medium */
7233ceb489SKirk McKusick extern	int cachesize;		/* size of block cache in bytes */
7333ceb489SKirk McKusick extern	int rsync_friendly;	/* be friendly with rsync */
7433ceb489SKirk McKusick extern	int notify;		/* notify operator flag */
7533ceb489SKirk McKusick extern	int blockswritten;	/* number of blocks written on current tape */
7633ceb489SKirk McKusick extern	int tapeno;		/* current tape number */
7733ceb489SKirk McKusick extern	int ntrec;		/* blocking factor on tape */
7833ceb489SKirk McKusick extern	long blocksperfile;	/* number of blocks per output file */
7933ceb489SKirk McKusick extern	int cartridge;		/* assume non-cartridge tape */
8033ceb489SKirk McKusick extern	char *host;		/* remote host (if any) */
8133ceb489SKirk McKusick extern	time_t tstart_writing;	/* when started writing the first tape block */
8233ceb489SKirk McKusick extern	time_t tend_writing;	/* after writing the last tape block */
8333ceb489SKirk McKusick extern	int passno;		/* current dump pass number */
8433ceb489SKirk McKusick extern	struct fs *sblock;	/* the file system super block */
8533ceb489SKirk McKusick extern	long dev_bsize;		/* block size of underlying disk device */
8633ceb489SKirk McKusick extern	int dev_bshift;		/* log2(dev_bsize) */
8733ceb489SKirk McKusick extern	int tp_bshift;		/* log2(TP_BSIZE) */
888fae3551SRodney W. Grimes 
898fae3551SRodney W. Grimes /* operator interface functions */
902db673abSWarner Losh void	broadcast(const char *message);
912db673abSWarner Losh void	infosch(int);
922db673abSWarner Losh void	lastdump(int arg);	/* int should be char */
932db673abSWarner Losh void	msg(const char *fmt, ...) __printflike(1, 2);
942db673abSWarner Losh void	msgtail(const char *fmt, ...) __printflike(1, 2);
952db673abSWarner Losh int	query(const char *question);
962db673abSWarner Losh void	quit(const char *fmt, ...) __printflike(1, 2);
972db673abSWarner Losh void	timeest(void);
982db673abSWarner Losh time_t	unctime(char *str);
998fae3551SRodney W. Grimes 
10026e69f9fSyue0211 /* mapping routines */
1011c85e6a3SKirk McKusick union	dinode;
1022db673abSWarner Losh int	mapfiles(ino_t maxino, long *tapesize);
1032db673abSWarner Losh int	mapdirs(ino_t maxino, long *tapesize);
1048fae3551SRodney W. Grimes 
1058fae3551SRodney W. Grimes /* file dumping routines */
106a770ae06SKirk McKusick void	blkread(ufs2_daddr_t blkno, char *buf, int size);
107ec3f495cSIan Dowse ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset);
1081c85e6a3SKirk McKusick void	dumpino(union dinode *dp, ino_t ino);
1092db673abSWarner Losh void	dumpmap(char *map, int type, ino_t ino);
1102db673abSWarner Losh void	writeheader(ino_t ino);
1118fae3551SRodney W. Grimes 
1128fae3551SRodney W. Grimes /* tape writing routines */
1132db673abSWarner Losh int	alloctape(void);
1142db673abSWarner Losh void	close_rewind(void);
1151c85e6a3SKirk McKusick void	dumpblock(ufs2_daddr_t blkno, int size);
1162db673abSWarner Losh void	startnewtape(int top);
1172db673abSWarner Losh void	trewind(void);
1182db673abSWarner Losh void	writerec(char *dp, int isspcl);
1198fae3551SRodney W. Grimes 
1202db673abSWarner Losh void	Exit(int status) __dead2;
1214787668fSEitan Adler void	dumpabort(int signo) __dead2;
122a3165d16SMatthew N. Dodd void	dump_getfstab(void);
1238fae3551SRodney W. Grimes 
1242db673abSWarner Losh char	*rawname(char *cp);
12507436eebSKirk McKusick union	dinode *getino(ino_t inum, int *mode);
1268fae3551SRodney W. Grimes 
1278fae3551SRodney W. Grimes /* rdump routines */
1288fae3551SRodney W. Grimes #ifdef RDUMP
1292db673abSWarner Losh void	rmtclose(void);
1302db673abSWarner Losh int	rmthost(const char *host);
1312db673abSWarner Losh int	rmtopen(const char *tape, int mode);
1322db673abSWarner Losh int	rmtwrite(const char *buf, int count);
1338fae3551SRodney W. Grimes #endif /* RDUMP */
1348fae3551SRodney W. Grimes 
1352db673abSWarner Losh void	interrupt(int signo);	/* in case operator bangs on console */
1368fae3551SRodney W. Grimes 
1378fae3551SRodney W. Grimes /*
1388fae3551SRodney W. Grimes  *	Exit status codes
1398fae3551SRodney W. Grimes  */
1408fae3551SRodney W. Grimes #define	X_FINOK		0	/* normal exit */
141f69e804dSJoseph Koshy #define	X_STARTUP	1	/* startup error */
1428fae3551SRodney W. Grimes #define	X_REWRITE	2	/* restart writing from the check point */
1438fae3551SRodney W. Grimes #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
1448fae3551SRodney W. Grimes 
1458fae3551SRodney W. Grimes #define	OPGRENT	"operator"		/* group entry to notify */
1468fae3551SRodney W. Grimes 
1472db673abSWarner Losh struct	fstab *fstabsearch(const char *key); /* search fs_file and fs_spec */
1488fae3551SRodney W. Grimes 
1498fae3551SRodney W. Grimes #ifndef NAME_MAX
1508fae3551SRodney W. Grimes #define NAME_MAX 255
1518fae3551SRodney W. Grimes #endif
1528fae3551SRodney W. Grimes 
1538fae3551SRodney W. Grimes /*
1548fae3551SRodney W. Grimes  *	The contents of the file _PATH_DUMPDATES is maintained both on
1558fae3551SRodney W. Grimes  *	a linked list, and then (eventually) arrayified.
1568fae3551SRodney W. Grimes  */
1578fae3551SRodney W. Grimes struct dumpdates {
1588fae3551SRodney W. Grimes 	char	dd_name[NAME_MAX+3];
159f72ab793SKirk McKusick 	int	dd_level;
1608fae3551SRodney W. Grimes 	time_t	dd_ddate;
1618fae3551SRodney W. Grimes };
16233ceb489SKirk McKusick extern	int nddates;			/* number of records (might be zero) */
16333ceb489SKirk McKusick extern	struct dumpdates **ddatev;	/* the arrayfied version */
1642db673abSWarner Losh void	initdumptimes(void);
1652db673abSWarner Losh void	getdumptime(void);
1662db673abSWarner Losh void	putdumptime(void);
1678fae3551SRodney W. Grimes #define	ITITERATE(i, ddp) \
168ad0c89f7SMaxim Konovalov     	if (ddatev != NULL) \
1698fae3551SRodney W. Grimes 		for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
1708fae3551SRodney W. Grimes 
17123ad9069SKirk McKusick #define	DUMPFMTLEN	53			/* max device pathname length */
17223ad9069SKirk McKusick #define	DUMPOUTFMT	"%-*s %d %s"		/* for printf */
173f72ab793SKirk McKusick 						/* name, level, ctime(date) */
17423ad9069SKirk McKusick #define	DUMPINFMT	"%s %d %[^\n]\n"	/* inverse for scanf */
175f72ab793SKirk McKusick 
1762db673abSWarner Losh void	sig(int signo);
1778fae3551SRodney W. Grimes 
1788fae3551SRodney W. Grimes #ifndef	_PATH_FSTAB
1798fae3551SRodney W. Grimes #define	_PATH_FSTAB	"/etc/fstab"
1808fae3551SRodney W. Grimes #endif
181