Home | History | Annotate | Line # | Download | only in dump
dump.h revision 1.15
      1 /*	$NetBSD: dump.h,v 1.15 1999/01/15 13:32:06 bouyer Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1980, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)dump.h	8.2 (Berkeley) 4/28/95
     36  */
     37 
     38 #include <machine/bswap.h>
     39 
     40 #define MAXINOPB	(MAXBSIZE / sizeof(struct dinode))
     41 #define MAXNINDIR	(MAXBSIZE / sizeof(daddr_t))
     42 
     43 /*
     44  * Dump maps used to describe what is to be dumped.
     45  */
     46 int	mapsize;	/* size of the state maps */
     47 char	*usedinomap;	/* map of allocated inodes */
     48 char	*dumpdirmap;	/* map of directories to be dumped */
     49 char	*dumpinomap;	/* map of files to be dumped */
     50 /*
     51  * Map manipulation macros.
     52  */
     53 #define	SETINO(ino, map) \
     54 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
     55 #define	CLRINO(ino, map) \
     56 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
     57 #define	TSTINO(ino, map) \
     58 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
     59 
     60 /*
     61  *	All calculations done in 0.1" units!
     62  */
     63 char	*disk;		/* name of the disk file */
     64 char	*tape;		/* name of the tape file */
     65 char	*dumpdates;	/* name of the file containing dump date information*/
     66 char	*temp;		/* name of the file for doing rewrite of dumpdates */
     67 char	lastlevel;	/* dump level of previous dump */
     68 char	level;		/* dump level of this dump */
     69 int	uflag;		/* update flag */
     70 int	diskfd;		/* disk file descriptor */
     71 int	tapefd;		/* tape file descriptor */
     72 int	pipeout;	/* true => output to standard output */
     73 ino_t	curino;		/* current inumber; used globally */
     74 int	newtape;	/* new tape flag */
     75 int	density;	/* density in 0.1" units */
     76 long	tapesize;	/* estimated tape size, blocks */
     77 long	tsize;		/* tape size in 0.1" units */
     78 long	asize;		/* number of 0.1" units written on current tape */
     79 int	etapes;		/* estimated number of tapes */
     80 int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
     81 
     82 int	notify;		/* notify operator flag */
     83 int	blockswritten;	/* number of blocks written on current tape */
     84 int	tapeno;		/* current tape number */
     85 time_t	tstart_writing;	/* when started writing the first tape block */
     86 int	xferrate;	/* averaged transfer rate of all volumes */
     87 struct	fs *sblock;	/* the file system super block */
     88 char	sblock_buf[MAXBSIZE];
     89 long	dev_bsize;	/* block size of underlying disk device */
     90 int	dev_bshift;	/* log2(dev_bsize) */
     91 int	tp_bshift;	/* log2(TP_BSIZE) */
     92 int needswap;	/* file system in swapped byte order */
     93 /* some inline functs to help the byte-swapping mess */
     94 static __inline u_int16_t iswap16 __P((u_int16_t));
     95 static __inline u_int32_t iswap32 __P((u_int32_t));
     96 static __inline u_int64_t iswap64 __P((u_int64_t));
     97 
     98 static __inline u_int16_t iswap16(x)
     99 	u_int16_t x;
    100 {
    101 	if (needswap)
    102 		return bswap16(x);
    103 	else return x;
    104 }
    105 
    106 static __inline u_int32_t iswap32(x)
    107     u_int32_t x;
    108 {
    109 	if (needswap)
    110 		return bswap32(x);
    111 	else return x;
    112 }
    113 
    114 static __inline u_int64_t iswap64(x)
    115 	u_int64_t x;
    116 {
    117 	if (needswap)
    118 		return bswap64(x);
    119 	else return x;
    120 }
    121 
    122 #ifndef __P
    123 #include <sys/cdefs.h>
    124 #endif
    125 
    126 /* operator interface functions */
    127 void	broadcast __P((char *message));
    128 void	lastdump __P((int arg));	/* int should be char */
    129 void	msg __P((const char *fmt, ...));
    130 void	msgtail __P((const char *fmt, ...));
    131 int	query __P((char *question));
    132 void	quit __P((const char *fmt, ...));
    133 void	set_operators __P((void));
    134 time_t	do_stats __P((void));
    135 void	statussig __P((int));
    136 void	timeest __P((void));
    137 time_t	unctime __P((char *str));
    138 
    139 /* mapping routines */
    140 struct	dinode;
    141 long	blockest __P((struct dinode *dp));
    142 void	mapfileino __P((ino_t, long *, int *));
    143 int	mapfiles __P((ino_t maxino, long *tapesize, char *disk,
    144 		    char * const *dirv));
    145 int	mapdirs __P((ino_t maxino, long *tapesize));
    146 
    147 /* file dumping routines */
    148 void	blksout __P((daddr_t *blkp, int frags, ino_t ino));
    149 void	bread __P((daddr_t blkno, char *buf, int size));
    150 void	dumpino __P((struct dinode *dp, ino_t ino));
    151 void	dumpmap __P((char *map, int type, ino_t ino));
    152 void	writeheader __P((ino_t ino));
    153 
    154 /* tape writing routines */
    155 int	alloctape __P((void));
    156 void	close_rewind __P((void));
    157 void	dumpblock __P((daddr_t blkno, int size));
    158 void	startnewtape __P((int top));
    159 void	trewind __P((void));
    160 void	writerec __P((char *dp, int isspcl));
    161 
    162 void	Exit __P((int status));
    163 void	dumpabort __P((int signo));
    164 void	getfstab __P((void));
    165 
    166 char	*rawname __P((char *cp));
    167 struct	dinode *getino __P((ino_t inum));
    168 
    169 /* rdump routines */
    170 #ifdef RDUMP
    171 void	rmtclose __P((void));
    172 int	rmthost __P((char *host));
    173 int	rmtopen __P((char *tape, int mode));
    174 int	rmtwrite __P((char *buf, int count));
    175 #endif /* RDUMP */
    176 
    177 void	interrupt __P((int signo));	/* in case operator bangs on console */
    178 
    179 /*
    180  *	Exit status codes
    181  */
    182 #define	X_FINOK		0	/* normal exit */
    183 #define	X_REWRITE	2	/* restart writing from the check point */
    184 #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
    185 
    186 #define	OPGRENT	"operator"		/* group entry to notify */
    187 #define DIALUP	"ttyd"			/* prefix for dialups */
    188 
    189 struct	fstab *fstabsearch __P((char *key));	/* search fs_file and fs_spec */
    190 
    191 #ifndef NAME_MAX
    192 #define NAME_MAX 255
    193 #endif
    194 
    195 /*
    196  *	The contents of the file _PATH_DUMPDATES is maintained both on
    197  *	a linked list, and then (eventually) arrayified.
    198  */
    199 struct dumpdates {
    200 	char	dd_name[NAME_MAX+3];
    201 	char	dd_level;
    202 	time_t	dd_ddate;
    203 };
    204 struct dumptime {
    205 	struct	dumpdates dt_value;
    206 	struct	dumptime *dt_next;
    207 };
    208 struct	dumptime *dthead;	/* head of the list version */
    209 int	nddates;		/* number of records (might be zero) */
    210 int	ddates_in;		/* we have read the increment file */
    211 struct	dumpdates **ddatev;	/* the arrayfied version */
    212 void	initdumptimes __P((void));
    213 void	getdumptime __P((void));
    214 void	putdumptime __P((void));
    215 #define	ITITERATE(i, ddp) \
    216 	for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
    217 
    218 void	sig __P((int signo));
    219 
    220 /*
    221  * Compatibility with old systems.
    222  */
    223 #ifdef COMPAT
    224 #include <sys/file.h>
    225 #define	strchr(a,b)	index(a,b)
    226 #define	strrchr(a,b)	rindex(a,b)
    227 extern char *strdup(), *ctime();
    228 extern int read(), write();
    229 extern int errno;
    230 #endif
    231 
    232 #ifndef	_PATH_UTMP
    233 #define	_PATH_UTMP	"/etc/utmp"
    234 #endif
    235 #ifndef	_PATH_FSTAB
    236 #define	_PATH_FSTAB	"/etc/fstab"
    237 #endif
    238 
    239 #ifdef sunos
    240 extern char *calloc();
    241 extern char *malloc();
    242 extern long atol();
    243 extern char *strcpy();
    244 extern char *strncpy();
    245 extern char *strcat();
    246 extern time_t time();
    247 extern void endgrent();
    248 extern void exit();
    249 extern off_t lseek();
    250 extern const char *strerror();
    251 #endif
    252