/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1980, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031/*32* Dump maps used to describe what is to be dumped.33*/34extern int mapsize; /* size of the state maps */35extern char *usedinomap; /* map of allocated inodes */36extern char *dumpdirmap; /* map of directories to be dumped */37extern char *dumpinomap; /* map of files to be dumped */38/*39* Map manipulation macros.40*/41#define SETINO(ino, map) \42map[(u_int)((ino) - 1) / CHAR_BIT] |= \431 << ((u_int)((ino) - 1) % CHAR_BIT)44#define CLRINO(ino, map) \45map[(u_int)((ino) - 1) / CHAR_BIT] &= \46~(1 << ((u_int)((ino) - 1) % CHAR_BIT))47#define TSTINO(ino, map) \48(map[(u_int)((ino) - 1) / CHAR_BIT] & \49(1 << ((u_int)((ino) - 1) % CHAR_BIT)))5051/*52* All calculations done in 0.1" units!53*/54extern char *disk; /* name of the disk file */55extern char *tape; /* name of the tape file */56extern char *popenout; /* popen(3) per-"tape" command */57extern char *dumpdates; /* name of the file containing dump date info */58extern int lastlevel; /* dump level of previous dump */59extern int level; /* dump level of this dump */60extern int uflag; /* update flag */61extern int diskfd; /* disk file descriptor */62extern int pipeout; /* true => output to standard output */63extern ino_t curino; /* current inumber; used globally */64extern int newtape; /* new tape flag */65extern int density; /* density in 0.1" units */66extern long tapesize; /* estimated tape size, blocks */67extern long tsize; /* tape size in 0.1" units */68extern int etapes; /* estimated number of tapes */69extern int nonodump; /* if set, do not honor UF_NODUMP user flags */70extern int unlimited; /* if set, write to end of medium */71extern int cachesize; /* size of block cache in bytes */72extern int rsync_friendly; /* be friendly with rsync */73extern int notify; /* notify operator flag */74extern int blockswritten; /* number of blocks written on current tape */75extern int tapeno; /* current tape number */76extern int ntrec; /* blocking factor on tape */77extern long blocksperfile; /* number of blocks per output file */78extern int cartridge; /* assume non-cartridge tape */79extern char *host; /* remote host (if any) */80extern time_t tstart_writing; /* when started writing the first tape block */81extern time_t tend_writing; /* after writing the last tape block */82extern int passno; /* current dump pass number */83extern struct fs *sblock; /* the file system super block */84extern long dev_bsize; /* block size of underlying disk device */85extern int dev_bshift; /* log2(dev_bsize) */86extern int tp_bshift; /* log2(TP_BSIZE) */8788/* operator interface functions */89void broadcast(const char *message);90void infosch(int);91void lastdump(int arg); /* int should be char */92void msg(const char *fmt, ...) __printflike(1, 2);93void msgtail(const char *fmt, ...) __printflike(1, 2);94int query(const char *question);95void quit(const char *fmt, ...) __printflike(1, 2);96void timeest(void);97time_t unctime(char *str);9899/* mapping routines */100union dinode;101int mapfiles(ino_t maxino, long *tapesize);102int mapdirs(ino_t maxino, long *tapesize);103104/* file dumping routines */105void blkread(ufs2_daddr_t blkno, char *buf, int size);106ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset);107void dumpino(union dinode *dp, ino_t ino);108void dumpmap(char *map, int type, ino_t ino);109void writeheader(ino_t ino);110111/* tape writing routines */112int alloctape(void);113void close_rewind(void);114void dumpblock(ufs2_daddr_t blkno, int size);115void startnewtape(int top);116void trewind(void);117void writerec(char *dp, int isspcl);118119void Exit(int status) __dead2;120void dumpabort(int signo) __dead2;121void dump_getfstab(void);122123char *rawname(char *cp);124union dinode *getino(ino_t inum, int *mode);125126/* rdump routines */127#ifdef RDUMP128void rmtclose(void);129int rmthost(const char *host);130int rmtopen(const char *tape, int mode);131int rmtwrite(const char *buf, int count);132#endif /* RDUMP */133134void interrupt(int signo); /* in case operator bangs on console */135136/*137* Exit status codes138*/139#define X_FINOK 0 /* normal exit */140#define X_STARTUP 1 /* startup error */141#define X_REWRITE 2 /* restart writing from the check point */142#define X_ABORT 3 /* abort dump; don't attempt checkpointing */143144#define OPGRENT "operator" /* group entry to notify */145146struct fstab *fstabsearch(const char *key); /* search fs_file and fs_spec */147148#ifndef NAME_MAX149#define NAME_MAX 255150#endif151152/*153* The contents of the file _PATH_DUMPDATES is maintained both on154* a linked list, and then (eventually) arrayified.155*/156struct dumpdates {157char dd_name[NAME_MAX+3];158int dd_level;159time_t dd_ddate;160};161extern int nddates; /* number of records (might be zero) */162extern struct dumpdates **ddatev; /* the arrayfied version */163void initdumptimes(void);164void getdumptime(void);165void putdumptime(void);166#define ITITERATE(i, ddp) \167if (ddatev != NULL) \168for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])169170#define DUMPFMTLEN 53 /* max device pathname length */171#define DUMPOUTFMT "%-*s %d %s" /* for printf */172/* name, level, ctime(date) */173#define DUMPINFMT "%s %d %[^\n]\n" /* inverse for scanf */174175void sig(int signo);176177#ifndef _PATH_FSTAB178#define _PATH_FSTAB "/etc/fstab"179#endif180181182