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 *dumpdev
; /* hostname:device for current volume */
113 char *sdumpdev
; /* short form of dumpdev (no user name if remote) */
114 char *increm
; /* name of file containing incremental information */
115 char *filesystem
; /* name of the file system */
116 char *myname
; /* argv[0] without leading path components */
117 char lastincno
; /* increment number of previous dump */
118 char incno
; /* increment number */
119 char *tlabel
; /* what goes in tape header c_label field */
120 int uflag
; /* update flag */
121 int fi
; /* disk file descriptor */
122 int to
; /* tape file descriptor */
123 int mapfd
; /* block disk device descriptor for mmap */
124 int pipeout
; /* true => output to standard output */
125 int tapeout
; /* true => output to a tape drive */
126 ino_t ino
; /* current inumber; used globally */
127 off_t pos
; /* starting offset within ino; used globally */
128 int leftover
; /* number of tape recs left over from prev vol */
129 int nsubdir
; /* counts subdirs, for deciding to dump a dir */
130 int newtape
; /* new tape flag */
131 int nadded
; /* number of added sub directories */
132 int dadded
; /* directory added flag */
133 int density
; /* density in 0.1" units */
134 ulong_t tsize
; /* tape size in 0.1" units */
135 uoff_t esize
; /* estimated tape size, blocks */
136 uoff_t o_esize
; /* number of header blocks (overhead) */
137 uoff_t f_esize
; /* number of TP_BSIZE blocks for files/maps */
138 uint_t etapes
; /* estimated number of tapes */
139 uint_t ntrec
; /* 1K records per tape block */
140 int tenthsperirg
; /* 1/10" per tape inter-record gap */
141 dev_t partial_dev
; /* id of BLOCK device used in partial mode */
142 pid_t dumppid
; /* process-ID of top-level process */
144 int verify
; /* verify each volume */
145 int doingverify
; /* true => doing a verify pass */
146 int active
; /* recopy active files */
147 int doingactive
; /* true => redumping active files */
148 int archive
; /* true => saving a archive in archivefile */
149 char *archivefile
; /* name of archivefile */
150 int archive_opened
; /* have opened/created the archivefile */
151 int notify
; /* notify operator flag */
152 int diskette
; /* true if dumping to a diskette */
153 int cartridge
; /* true if dumping to a cartridge tape */
154 uint_t tracks
; /* number of tracks on a cartridge tape */
155 int printsize
; /* just print estimated size and exit */
156 int offline
; /* take tape offline after rewinding */
157 int autoload
; /* wait for next tape to autoload; implies offline */
158 int autoload_tries
; /* number of times to check on autoload */
159 int autoload_period
; /* seconds, tries*period = total wait time */
160 int doposition
; /* move to specified... */
161 daddr32_t filenum
; /* position of dump on 1st volume */
162 int dumpstate
; /* dump output state (see below) */
163 int dumptoarchive
; /* mark records to be archived */
165 int blockswritten
; /* number of blocks written on current tape */
166 uint_t tapeno
; /* current tape number */
168 struct fs
*sblock
; /* the file system super block */
169 int shortmeta
; /* current file has small amount of metadata */
170 union u_shadow c_shadow_save
[1];
172 time_t *telapsed
; /* time spent writing previous tapes */
173 time_t *tstart_writing
; /* when we started writing the latest tape */
174 time_t *tschedule
; /* when next to give a remaining-time estimate */
176 char *debug_chdir
; /* non-NULL means to mkdir this/pid, and chdir there, */
177 /* once for each separate child */
180 * Defines for the msec part of
181 * inode-based times, since we're
182 * not part of the kernel.
184 #define di_atspare di_ic.ic_atspare
185 #define di_mtspare di_ic.ic_mtspare
186 #define di_ctspare di_ic.ic_ctspare
188 #define HOUR (60L*60L)
189 #define DAY (24L*HOUR)
190 #define YEAR (365L*DAY)
207 #define X_FINOK 0 /* normal exit */
208 #define X_REWRITE 2 /* restart writing from the check point */
209 #define X_ABORT 3 /* abort all of dump; no checkpoint restart */
210 #define X_VERIFY 4 /* verify the reel just written */
211 #define X_RESTART 5 /* abort all progress so far; attempt restart */
213 #define NINCREM "/etc/dumpdates" /* new format incremental info */
215 #define TAPE "/dev/rmt/0b" /* default tape device */
216 #define OPGRENT "sys" /* group entry to notify */
217 #define DIALUP "ttyd" /* prefix for dialups */
219 #define DISKETTE "/dev/rfd0c"
221 #define NBUF 64 /* number of output buffers */
222 #define MAXNTREC 256 /* max tape blocking factor (in Kb) */
225 * The contents of the file NINCREM are maintained both on
226 * a linked list and then (eventually) arrayified.
229 char id_name
[MAXNAMLEN
+3];
234 size_t nidates
; /* number of records (might be zero) */
235 struct idates
**idatev
; /* the arrayfied version */
236 #define ITITERATE(i, ip) \
237 for (i = 0; i < nidates && (ip = idatev[i]) != NULL; i++)
240 * Function declarations
246 extern void mnttabread(void);
247 extern struct mntent
*mnttabsearch(char *, int);
248 extern void setmnttab(void);
249 extern struct mntent
*getmnttab(void);
253 extern char *prdate(time_t);
254 extern void inititimes(void);
255 extern void getitime(void);
256 extern void putitime(void);
257 extern void est(struct dinode
*);
258 extern time32_t
is_fssnap_dump(char *);
259 extern void bmapest(uchar_t
*);
263 extern void getlabel(void);
267 extern void child_chdir(void);
268 extern char *unrawname(char *);
269 extern void sigAbort(int);
270 extern char *rawname(char *);
271 extern char *lf_rawname(char *);
272 extern time32_t
timeclock(time32_t
);
274 extern void (*nsignal(int, void (*)(int)))(int);
276 extern int safe_file_open(const char *file
, int mode
, int perms
);
277 extern int safe_device_open(const char *file
, int mode
, int perms
);
278 extern FILE *safe_fopen(const char *filename
, const char *smode
, int perms
);
282 extern void allocino(void);
283 extern void freeino(void);
284 extern void saveino(ino_t
, struct dinode
*);
285 extern void resetino(ino_t
);
286 extern long getigen(ino_t
);
287 extern int lf_ismounted(char *, char *);
288 extern int isoperator(uid_t
, gid_t
);
289 extern int lockfs(char *, char *);
290 extern int openi(ino_t
, long, char *);
291 extern caddr_t
mapfile(int, off_t
, off_t
, int);
292 extern void unmapfile(void);
293 extern void stattoi(struct stat
*, struct dinode
*);
294 extern void dumpfile(int, caddr_t
, off_t
, off_t
, off_t
, int, int);
295 extern void activepass(void);
299 extern int query(char *);
300 extern int query_once(char *, int);
301 extern void interrupt(int);
302 extern void broadcast(char *);
303 extern void timeest(int, int);
305 extern void msg(const char *, ...);
307 extern void msgtail(const char *, ...);
308 extern void lastdump(int);
309 extern char *getresponse(char *, char *);
313 extern void alloctape(void);
314 extern void reset(void);
315 extern void spclrec(void);
316 extern void taprec(uchar_t
*, int, int);
317 extern void dmpblk(daddr32_t
, size_t, off_t
);
318 extern void toslave(void (*)(ino_t
), ino_t
);
319 extern void doinode(ino_t
);
320 extern void dospcl(ino_t
);
321 extern void flushcmds(void);
322 extern void flusht(void);
323 extern void nextdevice(void);
324 extern int isrewind(int);
325 extern void trewind(void);
326 extern void close_rewind(void);
327 extern void changevol(void);
328 extern void otape(int);
329 extern void dumpabort(void);
330 extern void dumpailing(void);
331 extern void Exit(int);
332 extern void positiontape(char *);
336 extern void pass(void (*)(struct dinode
*), uchar_t
*);
337 extern void mark(struct dinode
*);
338 extern void active_mark(struct dinode
*);
339 extern void markshad(struct dinode
*);
340 extern void estshad(struct dinode
*);
341 extern void freeshad();
342 extern void add(struct dinode
*);
343 extern void dirdump(struct dinode
*);
344 extern void dump(struct dinode
*);
345 extern void lf_dump(struct dinode
*);
346 extern void dumpblocks(ino_t
);
347 extern void bitmap(uchar_t
*, int);
348 extern struct dinode
*getino(ino_t
);
349 extern void bread(diskaddr_t
, uchar_t
*, size_t);
350 extern int hasshortmeta(struct dinode
**ip
);
354 extern int lftw(const char *,
355 int (*)(const char *, const struct stat
*, int), int);
356 extern int lf_lftw(const char *,
357 int (*)(const char *, const struct stat64
*, int), int);
361 extern void partial_check(void);
362 extern void lf_partial_check(void);
363 extern int partial_mark(int, char **);
367 extern time_t unctime(char *);
372 extern void mnttabread();
373 extern struct mntent
*mnttabsearch();
374 extern void setmnttab();
375 extern struct mntent
*getmnttab();
379 extern char *prdate();
380 extern void inititimes();
381 extern void getitime();
382 extern void putitime();
384 extern time32_t
is_fssnap_dump();
385 extern void bmapest();
389 extern void getlabel();
393 extern void child_chdir();
394 extern char *unrawname();
395 extern void sigAbort();
396 extern char *rawname();
397 extern char *lf_rawname();
398 extern time_t timeclock();
400 extern void nsignal();
402 extern int safe_file_open();
403 extern int safe_device_open();
404 extern FILE *safe_fopen();
408 extern void allocino();
409 extern void freeino();
410 extern void saveino();
411 extern void resetino();
412 extern long getigen();
413 extern int lf_ismounted();
414 extern int isoperator();
415 extern ulong_t
lockfs();
417 extern caddr_t
mapfile();
418 extern void unmapfile();
419 extern void stattoi();
420 extern void dumpfile();
421 extern void activepass();
426 extern int query_once();
427 extern void interrupt();
428 extern void broadcast();
429 extern void timeest();
431 extern void msgtail();
432 extern void lastdump();
433 extern char *getresponse();
437 extern void alloctape();
439 extern void spclrec();
440 extern void taprec();
441 extern void dmpblk();
442 extern void toslave();
443 extern void doinode();
444 extern void dospcl();
445 extern void flushcmds();
446 extern void flusht();
447 extern void nextdevice();
448 extern int isrewind();
449 extern void trewind();
450 extern void close_rewind();
451 extern void changevol();
453 extern void dumpabort();
454 extern void dumpailing();
456 extern void positiontape();
462 extern void active_mark();
463 extern void markshad();
464 extern void estshad();
465 extern void freeshad();
467 extern void dirdump();
469 extern void lf_dump();
470 extern void dumpblocks();
471 extern void bitmap();
472 extern struct dinode
*getino();
474 extern int hasshortmeta();
479 extern int lf_lftw();
483 extern void partial_check();
484 extern void lf_partial_check();
485 extern int partial_mark();
489 extern time_t unctime();
490 #endif /* __STDC__ */
492 /* Insufficiently-featureful system header files... */
493 NOTE(ALIGNMENT(mmap
, 8))