4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright (c) 1980 Regents of the University of California.
28 * All rights reserved. The Berkeley software License Agreement
29 * specifies the terms and conditions for redistribution.
37 #include <sys/types.h>
47 #include <sys/param.h> /* for MAXBSIZE */
51 #include <sys/vnode.h> /* needed by inode.h */
57 #include <sys/fssnap_if.h>
65 #define SUPPORTS_MTB_TAPE_FORMAT
66 #include <protocols/dumprestore.h>
71 #define MAXINOPB (MAXBSIZE / sizeof (struct dinode))
72 #define MAXNINDIR (MAXBSIZE / sizeof (daddr32_t))
75 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
78 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
81 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
85 * Define an overflow-free version of howmany so that we don't
86 * run into trouble with large files.
88 #define d_howmany(x, y) ((x) / (y) + ((x) % (y) != 0))
90 #define MWORD(m, i) (m[(ino_t)(i-1)/NBBY])
91 #define MBIT(i) ((1<<((ino_t)(i-1)%NBBY))&0xff)
92 #define BIS(i, w) (MWORD(w, i) |= MBIT(i))
93 #define BIC(i, w) (MWORD(w, i) &= ~MBIT(i))
94 #define BIT(i, w) (MWORD(w, i) & MBIT(i))
105 * All calculations done in 0.1" units!
108 char *disk
; /* name of the disk file */
109 char *dname
; /* name to put in /etc/dumpdates */
110 int disk_dynamic
; /* true if disk refers to dynamic storage */
111 char *tape
; /* name of the tape file */
112 char *host
; /* name of the remote tape host (may be "user@host") */
113 char *dumpdev
; /* hostname:device for current volume */
114 char *sdumpdev
; /* short form of dumpdev (no user name if remote) */
115 char *increm
; /* name of file containing incremental information */
116 char *filesystem
; /* name of the file system */
117 char *myname
; /* argv[0] without leading path components */
118 char lastincno
; /* increment number of previous dump */
119 char incno
; /* increment number */
120 char *tlabel
; /* what goes in tape header c_label field */
121 int uflag
; /* update flag */
122 int fi
; /* disk file descriptor */
123 int to
; /* tape file descriptor */
124 int mapfd
; /* block disk device descriptor for mmap */
125 int pipeout
; /* true => output to standard output */
126 int tapeout
; /* true => output to a tape drive */
127 ino_t ino
; /* current inumber; used globally */
128 off_t pos
; /* starting offset within ino; used globally */
129 int leftover
; /* number of tape recs left over from prev vol */
130 int nsubdir
; /* counts subdirs, for deciding to dump a dir */
131 int newtape
; /* new tape flag */
132 int nadded
; /* number of added sub directories */
133 int dadded
; /* directory added flag */
134 int density
; /* density in 0.1" units */
135 ulong_t tsize
; /* tape size in 0.1" units */
136 u_offset_t esize
; /* estimated tape size, blocks */
137 u_offset_t o_esize
; /* number of header blocks (overhead) */
138 u_offset_t f_esize
; /* number of TP_BSIZE blocks for files/maps */
139 uint_t etapes
; /* estimated number of tapes */
140 uint_t ntrec
; /* 1K records per tape block */
141 int tenthsperirg
; /* 1/10" per tape inter-record gap */
142 dev_t partial_dev
; /* id of BLOCK device used in partial mode */
143 pid_t dumppid
; /* process-ID of top-level process */
145 int verify
; /* verify each volume */
146 int doingverify
; /* true => doing a verify pass */
147 int active
; /* recopy active files */
148 int doingactive
; /* true => redumping active files */
149 int archive
; /* true => saving a archive in archivefile */
150 char *archivefile
; /* name of archivefile */
151 int archive_opened
; /* have opened/created the archivefile */
152 int notify
; /* notify operator flag */
153 int diskette
; /* true if dumping to a diskette */
154 int cartridge
; /* true if dumping to a cartridge tape */
155 uint_t tracks
; /* number of tracks on a cartridge tape */
156 int printsize
; /* just print estimated size and exit */
157 int offline
; /* take tape offline after rewinding */
158 int autoload
; /* wait for next tape to autoload; implies offline */
159 int autoload_tries
; /* number of times to check on autoload */
160 int autoload_period
; /* seconds, tries*period = total wait time */
161 int doposition
; /* move to specified... */
162 daddr32_t filenum
; /* position of dump on 1st volume */
163 int dumpstate
; /* dump output state (see below) */
164 int dumptoarchive
; /* mark records to be archived */
166 int blockswritten
; /* number of blocks written on current tape */
167 uint_t tapeno
; /* current tape number */
169 struct fs
*sblock
; /* the file system super block */
170 int shortmeta
; /* current file has small amount of metadata */
171 union u_shadow c_shadow_save
[1];
173 time_t *telapsed
; /* time spent writing previous tapes */
174 time_t *tstart_writing
; /* when we started writing the latest tape */
175 time_t *tschedule
; /* when next to give a remaining-time estimate */
177 char *debug_chdir
; /* non-NULL means to mkdir this/pid, and chdir there, */
178 /* once for each separate child */
181 * Defines for the msec part of
182 * inode-based times, since we're
183 * not part of the kernel.
185 #define di_atspare di_ic.ic_atspare
186 #define di_mtspare di_ic.ic_mtspare
187 #define di_ctspare di_ic.ic_ctspare
189 #define HOUR (60L*60L)
190 #define DAY (24L*HOUR)
191 #define YEAR (365L*DAY)
208 #define X_FINOK 0 /* normal exit */
209 #define X_REWRITE 2 /* restart writing from the check point */
210 #define X_ABORT 3 /* abort all of dump; no checkpoint restart */
211 #define X_VERIFY 4 /* verify the reel just written */
212 #define X_RESTART 5 /* abort all progress so far; attempt restart */
214 #define NINCREM "/etc/dumpdates" /* new format incremental info */
216 #define TAPE "/dev/rmt/0b" /* default tape device */
217 #define OPGRENT "sys" /* group entry to notify */
218 #define DIALUP "ttyd" /* prefix for dialups */
220 #define DISKETTE "/dev/rfd0c"
222 #define NBUF 64 /* number of output buffers */
223 #define MAXNTREC 256 /* max tape blocking factor (in Kb) */
226 * The contents of the file NINCREM are maintained both on
227 * a linked list and then (eventually) arrayified.
230 char id_name
[MAXNAMLEN
+3];
235 size_t nidates
; /* number of records (might be zero) */
236 struct idates
**idatev
; /* the arrayfied version */
237 #define ITITERATE(i, ip) \
238 for (i = 0; i < nidates && (ip = idatev[i]) != NULL; i++)
241 * Function declarations
247 extern void mnttabread(void);
248 extern struct mntent
*mnttabsearch(char *, int);
249 extern void setmnttab(void);
250 extern struct mntent
*getmnttab(void);
254 extern char *prdate(time_t);
255 extern void inititimes(void);
256 extern void getitime(void);
257 extern void putitime(void);
258 extern void est(struct dinode
*);
259 extern time32_t
is_fssnap_dump(char *);
260 extern void bmapest(uchar_t
*);
264 extern void getlabel(void);
268 extern void child_chdir(void);
269 extern char *unrawname(char *);
270 extern void sigAbort(int);
271 extern char *rawname(char *);
272 extern char *lf_rawname(char *);
273 extern time32_t
timeclock(time32_t
);
275 extern void (*nsignal(int, void (*)(int)))(int);
277 extern int safe_file_open(const char *file
, int mode
, int perms
);
278 extern int safe_device_open(const char *file
, int mode
, int perms
);
279 extern FILE *safe_fopen(const char *filename
, const char *smode
, int perms
);
283 extern void allocino(void);
284 extern void freeino(void);
285 extern void saveino(ino_t
, struct dinode
*);
286 extern void resetino(ino_t
);
287 extern long getigen(ino_t
);
288 extern int lf_ismounted(char *, char *);
289 extern int isoperator(uid_t
, gid_t
);
290 extern int lockfs(char *, char *);
291 extern int openi(ino_t
, long, char *);
292 extern caddr_t
mapfile(int, off_t
, off_t
, int);
293 extern void unmapfile(void);
294 extern void stattoi(struct stat
*, struct dinode
*);
295 extern void dumpfile(int, caddr_t
, off_t
, off_t
, off_t
, int, int);
296 extern void activepass(void);
300 extern int query(char *);
301 extern int query_once(char *, int);
302 extern void interrupt(int);
303 extern void broadcast(char *);
304 extern void timeest(int, int);
306 extern void msg(const char *, ...);
308 extern void msgtail(const char *, ...);
309 extern void lastdump(int);
310 extern char *getresponse(char *, char *);
314 extern void alloctape(void);
315 extern void reset(void);
316 extern void spclrec(void);
317 extern void taprec(uchar_t
*, int, int);
318 extern void dmpblk(daddr32_t
, size_t, off_t
);
319 extern void toslave(void (*)(ino_t
), ino_t
);
320 extern void doinode(ino_t
);
321 extern void dospcl(ino_t
);
322 extern void flushcmds(void);
323 extern void flusht(void);
324 extern void nextdevice(void);
325 extern int isrewind(int);
326 extern void trewind(void);
327 extern void close_rewind(void);
328 extern void changevol(void);
329 extern void otape(int);
330 extern void dumpabort(void);
331 extern void dumpailing(void);
332 extern void Exit(int);
333 extern void positiontape(char *);
337 extern void pass(void (*)(struct dinode
*), uchar_t
*);
338 extern void mark(struct dinode
*);
339 extern void active_mark(struct dinode
*);
340 extern void markshad(struct dinode
*);
341 extern void estshad(struct dinode
*);
342 extern void freeshad();
343 extern void add(struct dinode
*);
344 extern void dirdump(struct dinode
*);
345 extern void dump(struct dinode
*);
346 extern void lf_dump(struct dinode
*);
347 extern void dumpblocks(ino_t
);
348 extern void bitmap(uchar_t
*, int);
349 extern struct dinode
*getino(ino_t
);
350 extern void bread(diskaddr_t
, uchar_t
*, size_t);
351 extern int hasshortmeta(struct dinode
**ip
);
355 extern int lftw(const char *,
356 int (*)(const char *, const struct stat
*, int), int);
357 extern int lf_lftw(const char *,
358 int (*)(const char *, const struct stat64
*, int), int);
362 extern void partial_check(void);
363 extern void lf_partial_check(void);
364 extern int partial_mark(int, char **);
368 extern time_t unctime(char *);
373 extern void mnttabread();
374 extern struct mntent
*mnttabsearch();
375 extern void setmnttab();
376 extern struct mntent
*getmnttab();
380 extern char *prdate();
381 extern void inititimes();
382 extern void getitime();
383 extern void putitime();
385 extern time32_t
is_fssnap_dump();
386 extern void bmapest();
390 extern void getlabel();
394 extern void child_chdir();
395 extern char *unrawname();
396 extern void sigAbort();
397 extern char *rawname();
398 extern char *lf_rawname();
399 extern time_t timeclock();
401 extern void nsignal();
403 extern int safe_file_open();
404 extern int safe_device_open();
405 extern FILE *safe_fopen();
409 extern void allocino();
410 extern void freeino();
411 extern void saveino();
412 extern void resetino();
413 extern long getigen();
414 extern int lf_ismounted();
415 extern int isoperator();
416 extern ulong_t
lockfs();
418 extern caddr_t
mapfile();
419 extern void unmapfile();
420 extern void stattoi();
421 extern void dumpfile();
422 extern void activepass();
427 extern int query_once();
428 extern void interrupt();
429 extern void broadcast();
430 extern void timeest();
432 extern void msgtail();
433 extern void lastdump();
434 extern char *getresponse();
438 extern void alloctape();
440 extern void spclrec();
441 extern void taprec();
442 extern void dmpblk();
443 extern void toslave();
444 extern void doinode();
445 extern void dospcl();
446 extern void flushcmds();
447 extern void flusht();
448 extern void nextdevice();
449 extern int isrewind();
450 extern void trewind();
451 extern void close_rewind();
452 extern void changevol();
454 extern void dumpabort();
455 extern void dumpailing();
457 extern void positiontape();
463 extern void active_mark();
464 extern void markshad();
465 extern void estshad();
466 extern void freeshad();
468 extern void dirdump();
470 extern void lf_dump();
471 extern void dumpblocks();
472 extern void bitmap();
473 extern struct dinode
*getino();
475 extern int hasshortmeta();
480 extern int lf_lftw();
484 extern void partial_check();
485 extern void lf_partial_check();
486 extern int partial_mark();
490 extern time_t unctime();
491 #endif /* __STDC__ */
493 /* Insufficiently-featureful system header files... */
494 NOTE(ALIGNMENT(mmap
, 8))