1 /* $NetBSD: dump.h,v 1.40 2005/06/27 01:37:32 christos 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. 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 * @(#)dump.h 8.2 (Berkeley) 4/28/95 32 */ 33 34 #include <machine/bswap.h> 35 36 union dinode { 37 struct ufs1_dinode dp1; 38 struct ufs2_dinode dp2; 39 }; 40 #define DIP(dp, field) \ 41 (is_ufs2 ? (dp)->dp2.di_##field : (dp)->dp1.di_##field) 42 43 /* 44 * Filestore-independent UFS data, so code can be more easily shared 45 * between ffs, lfs, and maybe ext2fs and others as well. 46 */ 47 struct ufsi { 48 int64_t ufs_dsize; /* file system size, in sectors */ 49 int32_t ufs_bsize; /* block size */ 50 int32_t ufs_bshift; /* log2(ufs_bsize) */ 51 int32_t ufs_fsize; /* fragment size */ 52 int32_t ufs_frag; /* block size / frag size */ 53 int32_t ufs_fsatoda; /* disk address conversion constant */ 54 int32_t ufs_nindir; /* disk addresses per indirect block */ 55 int32_t ufs_inopb; /* inodes per block */ 56 int32_t ufs_maxsymlinklen; /* max symlink length */ 57 int32_t ufs_bmask; /* block mask */ 58 int32_t ufs_fmask; /* frag mask */ 59 int64_t ufs_qbmask; /* ~ufs_bmask */ 60 int64_t ufs_qfmask; /* ~ufs_fmask */ 61 }; 62 #define fsatoda(u,a) ((a) << (u)->ufs_fsatoda) 63 #define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \ 64 (((size) + (u)->ufs_qfmask) & (u)->ufs_fmask) 65 #define ufs_blkoff(u,loc) /* calculates (loc % u->ufs_bsize) */ \ 66 ((loc) & (u)->ufs_qbmask) 67 #define ufs_dblksize(u,d,b) \ 68 ((((b) >= NDADDR || DIP((d), size) >= ((b)+1) << (u)->ufs_bshift \ 69 ? (u)->ufs_bsize \ 70 : (ufs_fragroundup((u), ufs_blkoff(u, DIP((d), size))))))) 71 struct ufsi *ufsib; 72 73 /* 74 * Dump maps used to describe what is to be dumped. 75 */ 76 int mapsize; /* size of the state maps */ 77 char *usedinomap; /* map of allocated inodes */ 78 char *dumpdirmap; /* map of directories to be dumped */ 79 char *dumpinomap; /* map of files to be dumped */ 80 /* 81 * Map manipulation macros. 82 */ 83 #define SETINO(ino, map) \ 84 map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY) 85 #define CLRINO(ino, map) \ 86 map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY)) 87 #define TSTINO(ino, map) \ 88 (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY))) 89 90 /* 91 * All calculations done in 0.1" units! 92 */ 93 char *disk; /* name of the disk file */ 94 const char *tape; /* name of the tape file */ 95 const char *dumpdates; /* name of the file containing dump date information*/ 96 const char *temp; /* name of the file for doing rewrite of dumpdates */ 97 char lastlevel; /* dump level of previous dump */ 98 char level; /* dump level of this dump */ 99 int uflag; /* update flag */ 100 int eflag; /* eject flag */ 101 int lflag; /* autoload flag */ 102 int diskfd; /* disk file descriptor */ 103 int tapefd; /* tape file descriptor */ 104 int pipeout; /* true => output to standard output */ 105 ino_t curino; /* current inumber; used globally */ 106 int newtape; /* new tape flag */ 107 u_int64_t tapesize; /* estimated tape size, blocks */ 108 long tsize; /* tape size in 0.1" units */ 109 long asize; /* number of 0.1" units written on current tape */ 110 int etapes; /* estimated number of tapes */ 111 int nonodump; /* if set, do not honor UF_NODUMP user flags */ 112 int unlimited; /* if set, write to end of medium */ 113 114 extern int density; /* density in 0.1" units */ 115 extern int notify; /* notify operator flag */ 116 extern int timestamp; /* timestamp messages */ 117 extern int blockswritten; /* number of blocks written on current tape */ 118 extern int tapeno; /* current tape number */ 119 extern int is_ufs2; 120 121 time_t tstart_writing; /* when started writing the first tape block */ 122 time_t tstart_volume; /* when started writing the current volume */ 123 int xferrate; /* averaged transfer rate of all volumes */ 124 char sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */ 125 extern long dev_bsize; /* block size of underlying disk device */ 126 int dev_bshift; /* log2(dev_bsize) */ 127 int tp_bshift; /* log2(TP_BSIZE) */ 128 int needswap; /* file system in swapped byte order */ 129 130 131 /* some inline functions to help the byte-swapping mess */ 132 static __inline u_int16_t iswap16(u_int16_t); 133 static __inline u_int32_t iswap32(u_int32_t); 134 static __inline u_int64_t iswap64(u_int64_t); 135 136 static __inline u_int16_t iswap16(u_int16_t x) 137 { 138 if (needswap) 139 return bswap16(x); 140 else 141 return x; 142 } 143 144 static __inline u_int32_t iswap32(u_int32_t x) 145 { 146 if (needswap) 147 return bswap32(x); 148 else 149 return x; 150 } 151 152 static __inline u_int64_t iswap64(u_int64_t x) 153 { 154 if (needswap) 155 return bswap64(x); 156 else 157 return x; 158 } 159 160 /* filestore-specific hooks */ 161 int fs_read_sblock(char *); 162 struct ufsi *fs_parametrize(void); 163 ino_t fs_maxino(void); 164 void fs_mapinodes(ino_t, u_int64_t *, int *); 165 166 /* operator interface functions */ 167 void broadcast(const char *); 168 void lastdump(char); 169 void msg(const char *fmt, ...) __attribute__((__format__(__printf__,1,2))); 170 void msgtail(const char *fmt, ...) __attribute__((__format__(__printf__,1,2))); 171 int query(const char *); 172 void quit(const char *fmt, ...) __attribute__((__format__(__printf__,1,2))); 173 time_t do_stats(void); 174 void statussig(int); 175 void timeest(void); 176 time_t unctime(char *); 177 178 /* mapping routines */ 179 union dinode; 180 int64_t blockest(union dinode *); 181 void mapfileino(ino_t, u_int64_t *, int *); 182 int mapfiles(ino_t, u_int64_t *, char *, char * const *); 183 int mapdirs(ino_t, u_int64_t *); 184 185 /* file dumping routines */ 186 void blksout32(int32_t *, int, ino_t); 187 void blksout64(int64_t *, int, ino_t); 188 void dumpino(union dinode *, ino_t); 189 void dumpmap(char *, int, ino_t); 190 void writeheader(ino_t); 191 192 /* data block caching */ 193 void bread(daddr_t, char *, int); 194 void rawread(daddr_t, char *, int); 195 void initcache(int, int); 196 void printcachestats(void); 197 198 /* tape writing routines */ 199 int alloctape(void); 200 void close_rewind(void); 201 void dumpblock(daddr_t, int); 202 void startnewtape(int); 203 void trewind(int); 204 void writerec(char *, int); 205 206 void Exit(int); 207 void dumpabort(int); 208 void getfstab(void); 209 210 char *rawname(char *); 211 union dinode *getino(ino_t); 212 213 void *xcalloc(size_t, size_t); 214 void *xmalloc(size_t); 215 char *xstrdup(const char *); 216 217 /* rdump routines */ 218 #if defined(RDUMP) || defined(RRESTORE) 219 void rmtclose(void); 220 int rmthost(const char *); 221 int rmtopen(const char *, int, int); 222 int rmtwrite(const char *, int); 223 int rmtioctl(int, int); 224 #endif /* RDUMP || RRESTORE */ 225 226 void interrupt(int); /* in case operator bangs on console */ 227 228 /* 229 * Exit status codes 230 */ 231 #define X_FINOK 0 /* normal exit */ 232 #define X_STARTUP 1 /* startup error */ 233 #define X_REWRITE 2 /* restart writing from the check point */ 234 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */ 235 236 #define OPGRENT "operator" /* group entry to notify */ 237 #define DIALUP "ttyd" /* prefix for dialups */ 238 239 struct fstab *fstabsearch(const char *); /* search fs_file and fs_spec */ 240 struct statvfs *mntinfosearch(const char *key); 241 242 #ifndef NAME_MAX 243 #define NAME_MAX 255 244 #endif 245 246 /* 247 * The contents of the file _PATH_DUMPDATES is maintained both on 248 * a linked list, and then (eventually) arrayified. 249 */ 250 struct dumpdates { 251 char dd_name[NAME_MAX+3]; 252 char dd_level; 253 time_t dd_ddate; 254 }; 255 256 extern int nddates; /* number of records (might be zero) */ 257 extern struct dumpdates **ddatev; /* the arrayfied version */ 258 259 void initdumptimes(void); 260 void getdumptime(void); 261 void putdumptime(void); 262 #define ITITERATE(i, ddp) \ 263 if (ddatev != NULL) \ 264 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i]) 265 266 void sig(int signo); 267 268 /* 269 * Compatibility with old systems. 270 */ 271 #ifdef COMPAT 272 #include <sys/file.h> 273 #define strchr(a,b) index(a,b) 274 #define strrchr(a,b) rindex(a,b) 275 extern char *strdup(), *ctime(); 276 extern int read(), write(); 277 extern int errno; 278 #endif 279 280 #ifndef _PATH_FSTAB 281 #define _PATH_FSTAB "/etc/fstab" 282 #endif 283