11558Srgrimes/*-
21558Srgrimes * Copyright (c) 1980, 1993
31558Srgrimes *	The Regents of the University of California.  All rights reserved.
41558Srgrimes *
51558Srgrimes * Redistribution and use in source and binary forms, with or without
61558Srgrimes * modification, are permitted provided that the following conditions
71558Srgrimes * are met:
81558Srgrimes * 1. Redistributions of source code must retain the above copyright
91558Srgrimes *    notice, this list of conditions and the following disclaimer.
101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111558Srgrimes *    notice, this list of conditions and the following disclaimer in the
121558Srgrimes *    documentation and/or other materials provided with the distribution.
131558Srgrimes * 4. Neither the name of the University nor the names of its contributors
141558Srgrimes *    may be used to endorse or promote products derived from this software
151558Srgrimes *    without specific prior written permission.
161558Srgrimes *
171558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201558Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271558Srgrimes * SUCH DAMAGE.
281558Srgrimes *
2923672Speter *	@(#)dump.h	8.2 (Berkeley) 4/28/95
3071787Sphk *
3171787Sphk * $FreeBSD$
321558Srgrimes */
331558Srgrimes
341558Srgrimes/*
351558Srgrimes * Dump maps used to describe what is to be dumped.
361558Srgrimes */
371558Srgrimesint	mapsize;	/* size of the state maps */
381558Srgrimeschar	*usedinomap;	/* map of allocated inodes */
391558Srgrimeschar	*dumpdirmap;	/* map of directories to be dumped */
401558Srgrimeschar	*dumpinomap;	/* map of files to be dumped */
411558Srgrimes/*
421558Srgrimes * Map manipulation macros.
431558Srgrimes */
441558Srgrimes#define	SETINO(ino, map) \
45103949Smike	map[(u_int)((ino) - 1) / CHAR_BIT] |= \
46103949Smike	    1 << ((u_int)((ino) - 1) % CHAR_BIT)
471558Srgrimes#define	CLRINO(ino, map) \
48103949Smike	map[(u_int)((ino) - 1) / CHAR_BIT] &= \
49103949Smike	    ~(1 << ((u_int)((ino) - 1) % CHAR_BIT))
501558Srgrimes#define	TSTINO(ino, map) \
51103949Smike	(map[(u_int)((ino) - 1) / CHAR_BIT] & \
52103949Smike	    (1 << ((u_int)((ino) - 1) % CHAR_BIT)))
531558Srgrimes
541558Srgrimes/*
551558Srgrimes *	All calculations done in 0.1" units!
561558Srgrimes */
571558Srgrimeschar	*disk;		/* name of the disk file */
581558Srgrimeschar	*tape;		/* name of the tape file */
59128175Sgreenchar	*popenout;	/* popen(3) per-"tape" command */
601558Srgrimeschar	*dumpdates;	/* name of the file containing dump date information*/
611558Srgrimeschar	*temp;		/* name of the file for doing rewrite of dumpdates */
62179275Smckusickint	lastlevel;	/* dump level of previous dump */
63179275Smckusickint	level;		/* dump level of this dump */
641558Srgrimesint	uflag;		/* update flag */
651558Srgrimesint	diskfd;		/* disk file descriptor */
661558Srgrimesint	tapefd;		/* tape file descriptor */
671558Srgrimesint	pipeout;	/* true => output to standard output */
681558Srgrimesino_t	curino;		/* current inumber; used globally */
691558Srgrimesint	newtape;	/* new tape flag */
701558Srgrimesint	density;	/* density in 0.1" units */
711558Srgrimeslong	tapesize;	/* estimated tape size, blocks */
721558Srgrimeslong	tsize;		/* tape size in 0.1" units */
731558Srgrimeslong	asize;		/* number of 0.1" units written on current tape */
741558Srgrimesint	etapes;		/* estimated number of tapes */
751558Srgrimesint	nonodump;	/* if set, do not honor UF_NODUMP user flags */
7622192Sjoergint	unlimited;	/* if set, write to end of medium */
77109187Sdillonint	cachesize;	/* size of block cache in bytes */
78179267Smckusickint	rsync_friendly;	/* be friendly with rsync */
791558Srgrimes
801558Srgrimesint	notify;		/* notify operator flag */
811558Srgrimesint	blockswritten;	/* number of blocks written on current tape */
821558Srgrimesint	tapeno;		/* current tape number */
831558Srgrimestime_t	tstart_writing;	/* when started writing the first tape block */
8412377Sjoergtime_t	tend_writing;	/* after writing the last tape block */
8590743Siedowseint	passno;		/* current dump pass number */
86102231Strhodesstruct	fs *sblock;	/* the file system super block */
871558Srgrimeschar	sblock_buf[MAXBSIZE];
881558Srgrimeslong	dev_bsize;	/* block size of underlying disk device */
891558Srgrimesint	dev_bshift;	/* log2(dev_bsize) */
901558Srgrimesint	tp_bshift;	/* log2(TP_BSIZE) */
911558Srgrimes
921558Srgrimes/* operator interface functions */
9392837Simpvoid	broadcast(const char *message);
9492837Simpvoid	infosch(int);
9592837Simpvoid	lastdump(int arg);	/* int should be char */
9692837Simpvoid	msg(const char *fmt, ...) __printflike(1, 2);
9792837Simpvoid	msgtail(const char *fmt, ...) __printflike(1, 2);
9892837Simpint	query(const char *question);
9992837Simpvoid	quit(const char *fmt, ...) __printflike(1, 2);
10092837Simpvoid	timeest(void);
10192837Simptime_t	unctime(char *str);
1021558Srgrimes
1031558Srgrimes/* mapping rouintes */
10498542Smckusickunion	dinode;
10592837Simpint	mapfiles(ino_t maxino, long *tapesize);
10692837Simpint	mapdirs(ino_t maxino, long *tapesize);
1071558Srgrimes
1081558Srgrimes/* file dumping routines */
10998542Smckusickvoid	bread(ufs2_daddr_t blkno, char *buf, int size);
110122047Siedowsessize_t cread(int fd, void *buf, size_t nbytes, off_t offset);
11198542Smckusickvoid	dumpino(union dinode *dp, ino_t ino);
11292837Simpvoid	dumpmap(char *map, int type, ino_t ino);
11392837Simpvoid	writeheader(ino_t ino);
1141558Srgrimes
1151558Srgrimes/* tape writing routines */
11692837Simpint	alloctape(void);
11792837Simpvoid	close_rewind(void);
11898542Smckusickvoid	dumpblock(ufs2_daddr_t blkno, int size);
11992837Simpvoid	startnewtape(int top);
12092837Simpvoid	trewind(void);
12192837Simpvoid	writerec(char *dp, int isspcl);
1221558Srgrimes
12392837Simpvoid	Exit(int status) __dead2;
124243665Seadlervoid	dumpabort(int signo) __dead2;
125113214Smdoddvoid	dump_getfstab(void);
1261558Srgrimes
12792837Simpchar	*rawname(char *cp);
12898542Smckusickunion	dinode *getino(ino_t inum, int *mode);
1291558Srgrimes
1301558Srgrimes/* rdump routines */
1311558Srgrimes#ifdef RDUMP
13292837Simpvoid	rmtclose(void);
13392837Simpint	rmthost(const char *host);
13492837Simpint	rmtopen(const char *tape, int mode);
13592837Simpint	rmtwrite(const char *buf, int count);
1361558Srgrimes#endif /* RDUMP */
1371558Srgrimes
13892837Simpvoid	interrupt(int signo);	/* in case operator bangs on console */
1391558Srgrimes
1401558Srgrimes/*
1411558Srgrimes *	Exit status codes
1421558Srgrimes */
1431558Srgrimes#define	X_FINOK		0	/* normal exit */
14437635Sjkoshy#define	X_STARTUP	1	/* startup error */
1451558Srgrimes#define	X_REWRITE	2	/* restart writing from the check point */
1461558Srgrimes#define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
1471558Srgrimes
1481558Srgrimes#define	OPGRENT	"operator"		/* group entry to notify */
1491558Srgrimes
15092837Simpstruct	fstab *fstabsearch(const char *key); /* search fs_file and fs_spec */
1511558Srgrimes
1521558Srgrimes#ifndef NAME_MAX
1531558Srgrimes#define NAME_MAX 255
1541558Srgrimes#endif
1551558Srgrimes
1561558Srgrimes/*
1571558Srgrimes *	The contents of the file _PATH_DUMPDATES is maintained both on
1581558Srgrimes *	a linked list, and then (eventually) arrayified.
1591558Srgrimes */
1601558Srgrimesstruct dumpdates {
1611558Srgrimes	char	dd_name[NAME_MAX+3];
162179275Smckusick	int	dd_level;
1631558Srgrimes	time_t	dd_ddate;
1641558Srgrimes};
1651558Srgrimesint	nddates;		/* number of records (might be zero) */
1661558Srgrimesstruct	dumpdates **ddatev;	/* the arrayfied version */
16792837Simpvoid	initdumptimes(void);
16892837Simpvoid	getdumptime(void);
16992837Simpvoid	putdumptime(void);
1701558Srgrimes#define	ITITERATE(i, ddp) \
171138314Smaxim    	if (ddatev != NULL) \
172138314Smaxim		for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
1731558Srgrimes
174226520Smckusick#define	DUMPFMTLEN	53			/* max device pathname length */
175226520Smckusick#define	DUMPOUTFMT	"%-*s %d %s"		/* for printf */
176179275Smckusick						/* name, level, ctime(date) */
177226520Smckusick#define	DUMPINFMT	"%s %d %[^\n]\n"	/* inverse for scanf */
178179275Smckusick
17992837Simpvoid	sig(int signo);
1801558Srgrimes
1811558Srgrimes#ifndef	_PATH_FSTAB
1821558Srgrimes#define	_PATH_FSTAB	"/etc/fstab"
1831558Srgrimes#endif
184