Home | History | Annotate | Line # | Download | only in dump
      1  1.60  christos /*	$NetBSD: dump.h,v 1.60 2021/06/19 13:56:34 christos 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.37       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  *
     31  1.13     lukem  *	@(#)dump.h	8.2 (Berkeley) 4/28/95
     32   1.1       cgd  */
     33  1.15    bouyer 
     34  1.15    bouyer #include <machine/bswap.h>
     35  1.51  christos #ifdef DUMP_LFS
     36  1.51  christos #include <ufs/lfs/lfs.h>
     37  1.52  dholland #include <ufs/lfs/lfs_accessors.h>
     38  1.51  christos #endif
     39  1.51  christos #include <ufs/ufs/dinode.h>
     40  1.51  christos #include <protocols/dumprestore.h>
     41   1.1       cgd 
     42  1.36      fvdl union dinode {
     43  1.36      fvdl 	struct ufs1_dinode dp1;
     44  1.36      fvdl 	struct ufs2_dinode dp2;
     45  1.51  christos #ifdef DUMP_LFS
     46  1.53  dholland 	struct lfs32_dinode dlp32;
     47  1.53  dholland 	struct lfs64_dinode dlp64;
     48  1.51  christos #endif
     49  1.36      fvdl };
     50  1.36      fvdl #define DIP(dp, field) \
     51  1.36      fvdl 	(is_ufs2 ? (dp)->dp2.di_##field : (dp)->dp1.di_##field)
     52   1.1       cgd 
     53  1.42     skrll #define DIP_SET(dp, field, val) do {		\
     54  1.42     skrll 	if (is_ufs2)				\
     55  1.42     skrll 		(dp)->dp2.di_##field = (val);	\
     56  1.42     skrll 	else					\
     57  1.42     skrll 		(dp)->dp1.di_##field = (val);	\
     58  1.42     skrll } while (0)
     59  1.42     skrll 
     60   1.1       cgd /*
     61  1.19  perseant  * Filestore-independent UFS data, so code can be more easily shared
     62  1.19  perseant  * between ffs, lfs, and maybe ext2fs and others as well.
     63  1.19  perseant  */
     64  1.19  perseant struct ufsi {
     65  1.28     lukem 	int64_t ufs_dsize;	/* file system size, in sectors */
     66  1.19  perseant 	int32_t ufs_bsize;	/* block size */
     67  1.19  perseant 	int32_t ufs_bshift;	/* log2(ufs_bsize) */
     68  1.19  perseant 	int32_t ufs_fsize;	/* fragment size */
     69  1.31     lukem 	int32_t ufs_frag;	/* block size / frag size */
     70  1.19  perseant 	int32_t ufs_fsatoda;	/* disk address conversion constant */
     71  1.19  perseant 	int32_t	ufs_nindir;	/* disk addresses per indirect block */
     72  1.31     lukem 	int32_t ufs_inopb;	/* inodes per block */
     73  1.19  perseant 	int32_t ufs_maxsymlinklen; /* max symlink length */
     74  1.31     lukem 	int32_t ufs_bmask;	/* block mask */
     75  1.31     lukem 	int32_t ufs_fmask;	/* frag mask */
     76  1.31     lukem 	int64_t ufs_qbmask;	/* ~ufs_bmask */
     77  1.31     lukem 	int64_t ufs_qfmask;	/* ~ufs_fmask */
     78  1.19  perseant };
     79  1.19  perseant #define fsatoda(u,a) ((a) << (u)->ufs_fsatoda)
     80  1.19  perseant #define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \
     81  1.31     lukem 	(((size) + (u)->ufs_qfmask) & (u)->ufs_fmask)
     82  1.19  perseant #define ufs_blkoff(u,loc)   /* calculates (loc % u->ufs_bsize) */ \
     83  1.31     lukem 	((loc) & (u)->ufs_qbmask)
     84  1.19  perseant #define ufs_dblksize(u,d,b) \
     85  1.50  dholland 	((((b) >= UFS_NDADDR || DIP((d), size) >= ((b)+1) << (u)->ufs_bshift \
     86  1.19  perseant 		? (u)->ufs_bsize \
     87  1.36      fvdl 		: (ufs_fragroundup((u), ufs_blkoff(u, DIP((d), size)))))))
     88  1.58     joerg extern struct ufsi *ufsib;
     89  1.19  perseant 
     90  1.19  perseant /*
     91   1.1       cgd  * Dump maps used to describe what is to be dumped.
     92   1.1       cgd  */
     93  1.58     joerg extern int	mapsize;	/* size of the state maps */
     94  1.58     joerg extern char	*usedinomap;	/* map of allocated inodes */
     95  1.58     joerg extern char	*dumpdirmap;	/* map of directories to be dumped */
     96  1.58     joerg extern char	*dumpinomap;	/* map of files to be dumped */
     97   1.1       cgd /*
     98   1.1       cgd  * Map manipulation macros.
     99   1.1       cgd  */
    100   1.1       cgd #define	SETINO(ino, map) \
    101   1.1       cgd 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
    102   1.1       cgd #define	CLRINO(ino, map) \
    103   1.1       cgd 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
    104   1.1       cgd #define	TSTINO(ino, map) \
    105   1.1       cgd 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
    106   1.1       cgd 
    107   1.1       cgd /*
    108   1.1       cgd  *	All calculations done in 0.1" units!
    109   1.1       cgd  */
    110  1.58     joerg extern char	*disk;		/* name of the disk file */
    111  1.58     joerg extern char	*disk_dev;	/* name of the raw device we are dumping */
    112  1.58     joerg extern const char *tape;	/* name of the tape file */
    113  1.58     joerg extern const char *dumpdates;	/* name of the file containing dump date information*/
    114  1.58     joerg extern const char *temp;	/* name of the file for doing rewrite of dumpdates */
    115  1.58     joerg extern char	lastlevel;	/* dump level of previous dump */
    116  1.58     joerg extern char	level;		/* dump level of this dump */
    117  1.58     joerg extern int	uflag;		/* update flag */
    118  1.58     joerg extern const char *dumpdev;	/* device name in dumpdates */
    119  1.58     joerg extern int	eflag;		/* eject flag */
    120  1.58     joerg extern int	lflag;		/* autoload flag */
    121  1.58     joerg extern int	diskfd;		/* disk file descriptor */
    122  1.58     joerg extern int	tapefd;		/* tape file descriptor */
    123  1.58     joerg extern int	pipeout;	/* true => output to standard output */
    124  1.58     joerg extern int	trueinc;	/* true => "true incremental", i.e use last 9 as ref */
    125  1.58     joerg extern ino_t	curino;		/* current inumber; used globally */
    126  1.58     joerg extern int	newtape;	/* new tape flag */
    127  1.58     joerg extern u_int64_t	tapesize;	/* estimated tape size, blocks */
    128  1.58     joerg extern long	tsize;		/* tape size in 0.1" units */
    129  1.58     joerg extern long	asize;		/* number of 0.1" units written on current tape */
    130  1.58     joerg extern int	etapes;		/* estimated number of tapes */
    131  1.58     joerg extern int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
    132  1.58     joerg extern int	unlimited;	/* if set, write to end of medium */
    133   1.1       cgd 
    134  1.22  christos extern int	density;	/* density in 0.1" units */
    135  1.22  christos extern int	notify;		/* notify operator flag */
    136  1.31     lukem extern int	timestamp;	/* timestamp messages */
    137  1.59       kre extern u_int64_t	blockswritten;	/* blocks written on current tape */
    138  1.22  christos extern int	tapeno;		/* current tape number */
    139  1.36      fvdl extern int	is_ufs2;
    140  1.22  christos 
    141  1.58     joerg extern time_t	tstart_writing;	/* when started writing the first tape block */
    142  1.58     joerg extern time_t	tstart_volume;	/* when started writing the current volume */
    143  1.58     joerg extern int	xferrate;	/* averaged transfer rate of all volumes */
    144  1.58     joerg extern char	sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
    145  1.21       scw extern long	dev_bsize;	/* block size of underlying disk device */
    146  1.58     joerg extern int	dev_bshift;	/* log2(dev_bsize) */
    147  1.58     joerg extern int	tp_bshift;	/* log2(TP_BSIZE) */
    148  1.58     joerg extern int needswap;	/* file system in swapped byte order */
    149  1.38     lukem 
    150  1.38     lukem 
    151  1.38     lukem /* some inline functions to help the byte-swapping mess */
    152  1.41     perry static inline u_int16_t iswap16(u_int16_t);
    153  1.41     perry static inline u_int32_t iswap32(u_int32_t);
    154  1.41     perry static inline u_int64_t iswap64(u_int64_t);
    155  1.26     lukem 
    156  1.41     perry static inline u_int16_t iswap16(u_int16_t x)
    157  1.26     lukem {
    158  1.14    bouyer 	if (needswap)
    159  1.14    bouyer 		return bswap16(x);
    160  1.26     lukem 	else
    161  1.26     lukem 		return x;
    162  1.14    bouyer }
    163  1.14    bouyer 
    164  1.41     perry static inline u_int32_t iswap32(u_int32_t x)
    165  1.14    bouyer {
    166  1.14    bouyer 	if (needswap)
    167  1.14    bouyer 		return bswap32(x);
    168  1.26     lukem 	else
    169  1.26     lukem 		return x;
    170  1.14    bouyer }
    171  1.14    bouyer 
    172  1.41     perry static inline u_int64_t iswap64(u_int64_t x)
    173  1.14    bouyer {
    174  1.14    bouyer 	if (needswap)
    175  1.14    bouyer 		return bswap64(x);
    176  1.26     lukem 	else
    177  1.26     lukem 		return x;
    178  1.26     lukem }
    179  1.19  perseant 
    180  1.19  perseant /* filestore-specific hooks */
    181  1.26     lukem int	fs_read_sblock(char *);
    182  1.26     lukem struct ufsi *fs_parametrize(void);
    183  1.26     lukem ino_t	fs_maxino(void);
    184  1.36      fvdl void	fs_mapinodes(ino_t, u_int64_t *, int *);
    185   1.7   mycroft 
    186   1.1       cgd /* operator interface functions */
    187  1.40  christos void	broadcast(const char *);
    188  1.26     lukem void	lastdump(char);
    189  1.56  christos void	msg(const char *, ...) __printflike(1, 2);
    190  1.56  christos void	msgtail(const char *, ...) __printflike(1, 2);
    191  1.40  christos int	query(const char *);
    192  1.56  christos void	quit(const char *, ...) __printflike(1, 2);
    193  1.56  christos void	quite(int, const char *, ...) __printflike(2, 3);
    194  1.26     lukem time_t	do_stats(void);
    195  1.26     lukem void	statussig(int);
    196  1.26     lukem void	timeest(void);
    197  1.48  dholland time_t	unctime(const char *);
    198   1.1       cgd 
    199  1.10     lukem /* mapping routines */
    200  1.36      fvdl union	dinode;
    201  1.36      fvdl int64_t	blockest(union dinode *);
    202  1.36      fvdl void	mapfileino(ino_t, u_int64_t *, int *);
    203  1.36      fvdl int	mapfiles(ino_t, u_int64_t *, char *, char * const *);
    204  1.36      fvdl int	mapdirs(ino_t, u_int64_t *);
    205   1.1       cgd 
    206   1.1       cgd /* file dumping routines */
    207  1.36      fvdl void	blksout32(int32_t *, int, ino_t);
    208  1.60  christos void	blksout64(union dinode *, int64_t *, int, ino_t, int);
    209  1.36      fvdl void	dumpino(union dinode *, ino_t);
    210  1.45      matt #ifndef RRESTORE
    211  1.26     lukem void	dumpmap(char *, int, ino_t);
    212  1.45      matt #endif
    213  1.26     lukem void	writeheader(ino_t);
    214  1.16    bouyer 
    215  1.16    bouyer /* data block caching */
    216  1.26     lukem void	bread(daddr_t, char *, int);
    217  1.26     lukem void	rawread(daddr_t, char *, int);
    218  1.26     lukem void	initcache(int, int);
    219  1.26     lukem void	printcachestats(void);
    220   1.1       cgd 
    221   1.1       cgd /* tape writing routines */
    222  1.26     lukem int	alloctape(void);
    223  1.26     lukem void	close_rewind(void);
    224  1.26     lukem void	dumpblock(daddr_t, int);
    225  1.26     lukem void	startnewtape(int);
    226  1.26     lukem void	trewind(int);
    227  1.48  dholland void	writerec(const char *, int);
    228  1.26     lukem 
    229  1.55       mrg void	Exit(int) __dead;
    230  1.26     lukem void	dumpabort(int);
    231  1.26     lukem void	getfstab(void);
    232   1.1       cgd 
    233  1.26     lukem char	*rawname(char *);
    234  1.36      fvdl union	dinode *getino(ino_t);
    235   1.1       cgd 
    236  1.27     lukem void	*xcalloc(size_t, size_t);
    237  1.27     lukem void	*xmalloc(size_t);
    238  1.27     lukem char	*xstrdup(const char *);
    239  1.27     lukem 
    240  1.43  perseant /* LFS snapshot hooks */
    241  1.43  perseant #ifdef DUMP_LFS
    242  1.43  perseant int	lfs_wrap_stop(char *);
    243  1.43  perseant void	lfs_wrap_go(void);
    244  1.43  perseant #endif
    245  1.43  perseant 
    246   1.7   mycroft /* rdump routines */
    247  1.23  christos #if defined(RDUMP) || defined(RRESTORE)
    248  1.26     lukem void	rmtclose(void);
    249  1.40  christos int	rmthost(const char *);
    250  1.40  christos int	rmtopen(const char *, int, int);
    251  1.40  christos int	rmtwrite(const char *, int);
    252  1.30    bouyer int	rmtioctl(int, int);
    253  1.23  christos #endif /* RDUMP || RRESTORE */
    254   1.7   mycroft 
    255  1.26     lukem void	interrupt(int);	/* in case operator bangs on console */
    256   1.1       cgd 
    257   1.1       cgd /*
    258   1.1       cgd  *	Exit status codes
    259   1.1       cgd  */
    260   1.1       cgd #define	X_FINOK		0	/* normal exit */
    261  1.32     lukem #define	X_STARTUP	1	/* startup error */
    262   1.1       cgd #define	X_REWRITE	2	/* restart writing from the check point */
    263   1.6       cgd #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
    264   1.1       cgd 
    265   1.1       cgd #define	OPGRENT	"operator"		/* group entry to notify */
    266   1.1       cgd #define DIALUP	"ttyd"			/* prefix for dialups */
    267   1.1       cgd 
    268  1.27     lukem struct	fstab *fstabsearch(const char *);	/* search fs_file and fs_spec */
    269  1.39  christos struct	statvfs *mntinfosearch(const char *key);
    270   1.6       cgd 
    271   1.6       cgd #ifndef NAME_MAX
    272  1.54  christos #define NAME_MAX 511
    273   1.6       cgd #endif
    274   1.1       cgd 
    275   1.1       cgd /*
    276   1.1       cgd  *	The contents of the file _PATH_DUMPDATES is maintained both on
    277   1.1       cgd  *	a linked list, and then (eventually) arrayified.
    278   1.1       cgd  */
    279   1.1       cgd struct dumpdates {
    280  1.54  christos 	/* see DUMP{IN,OUT}FMT in <protocols/dumprestore.h> */
    281   1.6       cgd 	char	dd_name[NAME_MAX+3];
    282   1.1       cgd 	char	dd_level;
    283   1.1       cgd 	time_t	dd_ddate;
    284   1.1       cgd };
    285  1.22  christos 
    286  1.22  christos extern int	nddates;		/* number of records (might be zero) */
    287  1.22  christos extern struct	dumpdates **ddatev;	/* the arrayfied version */
    288  1.22  christos 
    289  1.26     lukem void	initdumptimes(void);
    290  1.26     lukem void	getdumptime(void);
    291  1.26     lukem void	putdumptime(void);
    292   1.1       cgd #define	ITITERATE(i, ddp) \
    293  1.32     lukem 	if (ddatev != NULL) \
    294  1.32     lukem 		for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
    295   1.1       cgd 
    296  1.26     lukem void	sig(int signo);
    297   1.1       cgd 
    298   1.7   mycroft #ifndef	_PATH_FSTAB
    299   1.7   mycroft #define	_PATH_FSTAB	"/etc/fstab"
    300   1.1       cgd #endif
    301