1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 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. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 /* 33 * Dump maps used to describe what is to be dumped. 34 */ 35 extern int mapsize; /* size of the state maps */ 36 extern char *usedinomap; /* map of allocated inodes */ 37 extern char *dumpdirmap; /* map of directories to be dumped */ 38 extern char *dumpinomap; /* map of files to be dumped */ 39 /* 40 * Map manipulation macros. 41 */ 42 #define SETINO(ino, map) \ 43 map[(u_int)((ino) - 1) / CHAR_BIT] |= \ 44 1 << ((u_int)((ino) - 1) % CHAR_BIT) 45 #define CLRINO(ino, map) \ 46 map[(u_int)((ino) - 1) / CHAR_BIT] &= \ 47 ~(1 << ((u_int)((ino) - 1) % CHAR_BIT)) 48 #define TSTINO(ino, map) \ 49 (map[(u_int)((ino) - 1) / CHAR_BIT] & \ 50 (1 << ((u_int)((ino) - 1) % CHAR_BIT))) 51 52 /* 53 * All calculations done in 0.1" units! 54 */ 55 extern char *disk; /* name of the disk file */ 56 extern char *tape; /* name of the tape file */ 57 extern char *popenout; /* popen(3) per-"tape" command */ 58 extern char *dumpdates; /* name of the file containing dump date info */ 59 extern int lastlevel; /* dump level of previous dump */ 60 extern int level; /* dump level of this dump */ 61 extern int uflag; /* update flag */ 62 extern int diskfd; /* disk file descriptor */ 63 extern int pipeout; /* true => output to standard output */ 64 extern ino_t curino; /* current inumber; used globally */ 65 extern int newtape; /* new tape flag */ 66 extern int density; /* density in 0.1" units */ 67 extern long tapesize; /* estimated tape size, blocks */ 68 extern long tsize; /* tape size in 0.1" units */ 69 extern int etapes; /* estimated number of tapes */ 70 extern int nonodump; /* if set, do not honor UF_NODUMP user flags */ 71 extern int unlimited; /* if set, write to end of medium */ 72 extern int cachesize; /* size of block cache in bytes */ 73 extern int rsync_friendly; /* be friendly with rsync */ 74 extern int notify; /* notify operator flag */ 75 extern int blockswritten; /* number of blocks written on current tape */ 76 extern int tapeno; /* current tape number */ 77 extern int ntrec; /* blocking factor on tape */ 78 extern long blocksperfile; /* number of blocks per output file */ 79 extern int cartridge; /* assume non-cartridge tape */ 80 extern char *host; /* remote host (if any) */ 81 extern time_t tstart_writing; /* when started writing the first tape block */ 82 extern time_t tend_writing; /* after writing the last tape block */ 83 extern int passno; /* current dump pass number */ 84 extern struct fs *sblock; /* the file system super block */ 85 extern long dev_bsize; /* block size of underlying disk device */ 86 extern int dev_bshift; /* log2(dev_bsize) */ 87 extern int tp_bshift; /* log2(TP_BSIZE) */ 88 89 /* operator interface functions */ 90 void broadcast(const char *message); 91 void infosch(int); 92 void lastdump(int arg); /* int should be char */ 93 void msg(const char *fmt, ...) __printflike(1, 2); 94 void msgtail(const char *fmt, ...) __printflike(1, 2); 95 int query(const char *question); 96 void quit(const char *fmt, ...) __printflike(1, 2); 97 void timeest(void); 98 time_t unctime(char *str); 99 100 /* mapping routines */ 101 union dinode; 102 int mapfiles(ino_t maxino, long *tapesize); 103 int mapdirs(ino_t maxino, long *tapesize); 104 105 /* file dumping routines */ 106 void blkread(ufs2_daddr_t blkno, char *buf, int size); 107 ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset); 108 void dumpino(union dinode *dp, ino_t ino); 109 void dumpmap(char *map, int type, ino_t ino); 110 void writeheader(ino_t ino); 111 112 /* tape writing routines */ 113 int alloctape(void); 114 void close_rewind(void); 115 void dumpblock(ufs2_daddr_t blkno, int size); 116 void startnewtape(int top); 117 void trewind(void); 118 void writerec(char *dp, int isspcl); 119 120 void Exit(int status) __dead2; 121 void dumpabort(int signo) __dead2; 122 void dump_getfstab(void); 123 124 char *rawname(char *cp); 125 union dinode *getino(ino_t inum, int *mode); 126 127 /* rdump routines */ 128 #ifdef RDUMP 129 void rmtclose(void); 130 int rmthost(const char *host); 131 int rmtopen(const char *tape, int mode); 132 int rmtwrite(const char *buf, int count); 133 #endif /* RDUMP */ 134 135 void interrupt(int signo); /* in case operator bangs on console */ 136 137 /* 138 * Exit status codes 139 */ 140 #define X_FINOK 0 /* normal exit */ 141 #define X_STARTUP 1 /* startup error */ 142 #define X_REWRITE 2 /* restart writing from the check point */ 143 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */ 144 145 #define OPGRENT "operator" /* group entry to notify */ 146 147 struct fstab *fstabsearch(const char *key); /* search fs_file and fs_spec */ 148 149 #ifndef NAME_MAX 150 #define NAME_MAX 255 151 #endif 152 153 /* 154 * The contents of the file _PATH_DUMPDATES is maintained both on 155 * a linked list, and then (eventually) arrayified. 156 */ 157 struct dumpdates { 158 char dd_name[NAME_MAX+3]; 159 int dd_level; 160 time_t dd_ddate; 161 }; 162 extern int nddates; /* number of records (might be zero) */ 163 extern struct dumpdates **ddatev; /* the arrayfied version */ 164 void initdumptimes(void); 165 void getdumptime(void); 166 void putdumptime(void); 167 #define ITITERATE(i, ddp) \ 168 if (ddatev != NULL) \ 169 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i]) 170 171 #define DUMPFMTLEN 53 /* max device pathname length */ 172 #define DUMPOUTFMT "%-*s %d %s" /* for printf */ 173 /* name, level, ctime(date) */ 174 #define DUMPINFMT "%s %d %[^\n]\n" /* inverse for scanf */ 175 176 void sig(int signo); 177 178 #ifndef _PATH_FSTAB 179 #define _PATH_FSTAB "/etc/fstab" 180 #endif 181