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