tape.c revision 1.56 1 1.56 christos /* $NetBSD: tape.c,v 1.56 2006/10/16 03:12:23 christos Exp $ */
2 1.16 cgd
3 1.10 cgd /*
4 1.11 mycroft * Copyright (c) 1983, 1993
5 1.11 mycroft * The Regents of the University of California. All rights reserved.
6 1.10 cgd * (c) UNIX System Laboratories, Inc.
7 1.10 cgd * All or some portions of this file are derived from material licensed
8 1.10 cgd * to the University of California by American Telephone and Telegraph
9 1.10 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.10 cgd * the permission of UNIX System Laboratories, Inc.
11 1.10 cgd *
12 1.10 cgd * Redistribution and use in source and binary forms, with or without
13 1.10 cgd * modification, are permitted provided that the following conditions
14 1.10 cgd * are met:
15 1.10 cgd * 1. Redistributions of source code must retain the above copyright
16 1.10 cgd * notice, this list of conditions and the following disclaimer.
17 1.10 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.10 cgd * notice, this list of conditions and the following disclaimer in the
19 1.10 cgd * documentation and/or other materials provided with the distribution.
20 1.49 agc * 3. Neither the name of the University nor the names of its contributors
21 1.10 cgd * may be used to endorse or promote products derived from this software
22 1.10 cgd * without specific prior written permission.
23 1.10 cgd *
24 1.10 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.10 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.10 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.10 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.10 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.10 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.10 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.10 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.10 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.10 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.10 cgd * SUCH DAMAGE.
35 1.10 cgd */
36 1.10 cgd
37 1.28 lukem #include <sys/cdefs.h>
38 1.10 cgd #ifndef lint
39 1.16 cgd #if 0
40 1.29 lukem static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
41 1.16 cgd #else
42 1.56 christos __RCSID("$NetBSD: tape.c,v 1.56 2006/10/16 03:12:23 christos Exp $");
43 1.16 cgd #endif
44 1.10 cgd #endif /* not lint */
45 1.10 cgd
46 1.10 cgd #include <sys/param.h>
47 1.10 cgd #include <sys/file.h>
48 1.10 cgd #include <sys/ioctl.h>
49 1.10 cgd #include <sys/mtio.h>
50 1.10 cgd #include <sys/stat.h>
51 1.10 cgd
52 1.11 mycroft #include <ufs/ufs/dinode.h>
53 1.10 cgd #include <protocols/dumprestore.h>
54 1.10 cgd
55 1.51 bouyer #include <err.h>
56 1.10 cgd #include <errno.h>
57 1.26 lukem #include <paths.h>
58 1.10 cgd #include <setjmp.h>
59 1.10 cgd #include <stdio.h>
60 1.10 cgd #include <stdlib.h>
61 1.10 cgd #include <string.h>
62 1.36 kleink #include <time.h>
63 1.10 cgd #include <unistd.h>
64 1.10 cgd
65 1.50 enami #include <md5.h>
66 1.55 elad #include <crypto/rmd160.h>
67 1.50 enami #include <sha1.h>
68 1.50 enami
69 1.10 cgd #include "restore.h"
70 1.10 cgd #include "extern.h"
71 1.10 cgd
72 1.28 lukem static u_int32_t fssize = MAXBSIZE;
73 1.10 cgd static int mt = -1;
74 1.10 cgd static int pipein = 0;
75 1.10 cgd static char magtape[BUFSIZ];
76 1.10 cgd static int blkcnt;
77 1.10 cgd static int numtrec;
78 1.10 cgd static char *tapebuf;
79 1.10 cgd static union u_spcl endoftapemark;
80 1.28 lukem static int blksread; /* blocks read since last header */
81 1.28 lukem static int tpblksread = 0; /* TP_BSIZE blocks read */
82 1.28 lukem static int tapesread;
83 1.10 cgd static jmp_buf restart;
84 1.10 cgd static int gettingfile = 0; /* restart has a valid frame */
85 1.47 taca #ifdef RRESTORE
86 1.53 christos static const char *host = NULL;
87 1.47 taca #endif
88 1.10 cgd
89 1.10 cgd static int ofile;
90 1.10 cgd static char *map;
91 1.10 cgd static char lnkbuf[MAXPATHLEN + 1];
92 1.10 cgd static int pathlen;
93 1.10 cgd
94 1.10 cgd int oldinofmt; /* old inode format conversion required */
95 1.10 cgd int Bcvt; /* Swap Bytes (for CCI or sun) */
96 1.10 cgd
97 1.50 enami const struct digest_desc *ddesc;
98 1.50 enami const struct digest_desc digest_descs[] = {
99 1.50 enami { "MD5",
100 1.50 enami (void (*)(void *))MD5Init,
101 1.50 enami (void (*)(void *, const u_char *, u_int))MD5Update,
102 1.50 enami (char *(*)(void *, void *))MD5End, },
103 1.50 enami { "SHA1",
104 1.50 enami (void (*)(void *))SHA1Init,
105 1.50 enami (void (*)(void *, const u_char *, u_int))SHA1Update,
106 1.50 enami (char *(*)(void *, void *))SHA1End, },
107 1.50 enami { "RMD160",
108 1.50 enami (void (*)(void *))RMD160Init,
109 1.50 enami (void (*)(void *, const u_char *, u_int))RMD160Update,
110 1.50 enami (char *(*)(void *, void *))RMD160End, },
111 1.56 christos { .dd_name = NULL },
112 1.50 enami };
113 1.50 enami
114 1.50 enami static union digest_context {
115 1.50 enami MD5_CTX dc_md5;
116 1.50 enami SHA1_CTX dc_sha1;
117 1.50 enami RMD160_CTX dc_rmd160;
118 1.50 enami } dcontext;
119 1.50 enami
120 1.50 enami union digest_buffer {
121 1.50 enami char db_md5[32 + 1];
122 1.50 enami char db_sha1[40 + 1];
123 1.50 enami char db_rmd160[40 + 1];
124 1.50 enami };
125 1.50 enami
126 1.10 cgd #define FLUSHTAPEBUF() blkcnt = ntrec + 1
127 1.10 cgd
128 1.48 fvdl union u_ospcl {
129 1.48 fvdl char dummy[TP_BSIZE];
130 1.48 fvdl struct s_ospcl {
131 1.48 fvdl int32_t c_type;
132 1.48 fvdl int32_t c_date;
133 1.48 fvdl int32_t c_ddate;
134 1.48 fvdl int32_t c_volume;
135 1.48 fvdl int32_t c_tapea;
136 1.48 fvdl u_int16_t c_inumber;
137 1.48 fvdl int32_t c_magic;
138 1.48 fvdl int32_t c_checksum;
139 1.48 fvdl struct odinode {
140 1.48 fvdl unsigned short odi_mode;
141 1.48 fvdl u_int16_t odi_nlink;
142 1.48 fvdl u_int16_t odi_uid;
143 1.48 fvdl u_int16_t odi_gid;
144 1.48 fvdl int32_t odi_size;
145 1.48 fvdl int32_t odi_rdev;
146 1.48 fvdl char odi_addr[36];
147 1.48 fvdl int32_t odi_atime;
148 1.48 fvdl int32_t odi_mtime;
149 1.48 fvdl int32_t odi_ctime;
150 1.48 fvdl } c_odinode;
151 1.48 fvdl int32_t c_count;
152 1.48 fvdl char c_addr[256];
153 1.48 fvdl } s_ospcl;
154 1.48 fvdl };
155 1.48 fvdl
156 1.52 xtraeme static void accthdr(struct s_spcl *);
157 1.52 xtraeme static int checksum(int *);
158 1.52 xtraeme static void findinode(struct s_spcl *);
159 1.52 xtraeme static void findtapeblksize(void);
160 1.52 xtraeme static int gethead(struct s_spcl *);
161 1.52 xtraeme static void readtape(char *);
162 1.52 xtraeme static void setdumpnum(void);
163 1.52 xtraeme static void terminateinput(void);
164 1.52 xtraeme static void xtrfile(char *, long);
165 1.52 xtraeme static void xtrlnkfile(char *, long);
166 1.52 xtraeme static void xtrlnkskip(char *, long);
167 1.52 xtraeme static void xtrmap(char *, long);
168 1.52 xtraeme static void xtrmapskip(char *, long);
169 1.52 xtraeme static void xtrskip(char *, long);
170 1.52 xtraeme static void swap_header(struct s_spcl *);
171 1.52 xtraeme static void swap_old_header(struct s_ospcl *);
172 1.10 cgd
173 1.50 enami const struct digest_desc *
174 1.52 xtraeme digest_lookup(const char *name)
175 1.50 enami {
176 1.50 enami const struct digest_desc *dd;
177 1.50 enami
178 1.50 enami for (dd = digest_descs; dd->dd_name != NULL; dd++)
179 1.50 enami if (strcasecmp(dd->dd_name, name) == 0)
180 1.50 enami return (dd);
181 1.50 enami
182 1.50 enami return (NULL);
183 1.50 enami }
184 1.50 enami
185 1.10 cgd /*
186 1.10 cgd * Set up an input source
187 1.10 cgd */
188 1.10 cgd void
189 1.53 christos setinput(const char *source)
190 1.10 cgd {
191 1.53 christos char *cp;
192 1.10 cgd FLUSHTAPEBUF();
193 1.10 cgd if (bflag)
194 1.10 cgd newtapebuf(ntrec);
195 1.10 cgd else
196 1.10 cgd newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC);
197 1.10 cgd terminal = stdin;
198 1.10 cgd
199 1.10 cgd #ifdef RRESTORE
200 1.53 christos if ((cp = strchr(source, ':')) != NULL) {
201 1.10 cgd host = source;
202 1.53 christos /* Ok, because const strings don't have : */
203 1.53 christos *cp++ = '\0';
204 1.53 christos source = cp;
205 1.10 cgd if (rmthost(host) == 0)
206 1.15 mycroft exit(1);
207 1.10 cgd } else
208 1.10 cgd #endif
209 1.10 cgd if (strcmp(source, "-") == 0) {
210 1.10 cgd /*
211 1.10 cgd * Since input is coming from a pipe we must establish
212 1.10 cgd * our own connection to the terminal.
213 1.10 cgd */
214 1.10 cgd terminal = fopen(_PATH_TTY, "r");
215 1.10 cgd if (terminal == NULL) {
216 1.10 cgd (void)fprintf(stderr, "cannot open %s: %s\n",
217 1.10 cgd _PATH_TTY, strerror(errno));
218 1.10 cgd terminal = fopen(_PATH_DEVNULL, "r");
219 1.10 cgd if (terminal == NULL) {
220 1.10 cgd (void)fprintf(stderr, "cannot open %s: %s\n",
221 1.10 cgd _PATH_DEVNULL, strerror(errno));
222 1.15 mycroft exit(1);
223 1.10 cgd }
224 1.10 cgd }
225 1.10 cgd pipein++;
226 1.10 cgd }
227 1.10 cgd (void) strcpy(magtape, source);
228 1.10 cgd }
229 1.10 cgd
230 1.10 cgd void
231 1.52 xtraeme newtapebuf(long size)
232 1.10 cgd {
233 1.35 mrg static int tapebufsize = -1;
234 1.10 cgd
235 1.10 cgd ntrec = size;
236 1.10 cgd if (size <= tapebufsize)
237 1.10 cgd return;
238 1.10 cgd if (tapebuf != NULL)
239 1.10 cgd free(tapebuf);
240 1.10 cgd tapebuf = malloc(size * TP_BSIZE);
241 1.10 cgd if (tapebuf == NULL) {
242 1.10 cgd fprintf(stderr, "Cannot allocate space for tape buffer\n");
243 1.15 mycroft exit(1);
244 1.10 cgd }
245 1.10 cgd tapebufsize = size;
246 1.10 cgd }
247 1.10 cgd
248 1.10 cgd /*
249 1.10 cgd * Verify that the tape drive can be accessed and
250 1.10 cgd * that it actually is a dump tape.
251 1.10 cgd */
252 1.10 cgd void
253 1.52 xtraeme setup(void)
254 1.10 cgd {
255 1.10 cgd int i, j, *ip;
256 1.10 cgd struct stat stbuf;
257 1.10 cgd
258 1.10 cgd vprintf(stdout, "Verify tape and initialize maps\n");
259 1.10 cgd #ifdef RRESTORE
260 1.10 cgd if (host)
261 1.11 mycroft mt = rmtopen(magtape, 0);
262 1.10 cgd else
263 1.10 cgd #endif
264 1.10 cgd if (pipein)
265 1.10 cgd mt = 0;
266 1.10 cgd else
267 1.10 cgd mt = open(magtape, O_RDONLY, 0);
268 1.10 cgd if (mt < 0) {
269 1.10 cgd fprintf(stderr, "%s: %s\n", magtape, strerror(errno));
270 1.15 mycroft exit(1);
271 1.10 cgd }
272 1.10 cgd volno = 1;
273 1.10 cgd setdumpnum();
274 1.10 cgd FLUSHTAPEBUF();
275 1.10 cgd if (!pipein && !bflag)
276 1.10 cgd findtapeblksize();
277 1.10 cgd if (gethead(&spcl) == FAIL) {
278 1.10 cgd blkcnt--; /* push back this block */
279 1.10 cgd blksread--;
280 1.10 cgd tpblksread--;
281 1.10 cgd cvtflag++;
282 1.10 cgd if (gethead(&spcl) == FAIL) {
283 1.10 cgd fprintf(stderr, "Tape is not a dump tape\n");
284 1.15 mycroft exit(1);
285 1.10 cgd }
286 1.10 cgd fprintf(stderr, "Converting to new file system format.\n");
287 1.10 cgd }
288 1.10 cgd if (pipein) {
289 1.48 fvdl endoftapemark.s_spcl.c_magic = cvtflag ? OFS_MAGIC :
290 1.48 fvdl FS_UFS2_MAGIC;
291 1.10 cgd endoftapemark.s_spcl.c_type = TS_END;
292 1.10 cgd ip = (int *)&endoftapemark;
293 1.10 cgd j = sizeof(union u_spcl) / sizeof(int);
294 1.10 cgd i = 0;
295 1.10 cgd do
296 1.10 cgd i += *ip++;
297 1.10 cgd while (--j);
298 1.10 cgd endoftapemark.s_spcl.c_checksum = CHECKSUM - i;
299 1.10 cgd }
300 1.10 cgd if (vflag || command == 't')
301 1.10 cgd printdumpinfo();
302 1.10 cgd dumptime = spcl.c_ddate;
303 1.10 cgd dumpdate = spcl.c_date;
304 1.10 cgd if (stat(".", &stbuf) < 0) {
305 1.10 cgd fprintf(stderr, "cannot stat .: %s\n", strerror(errno));
306 1.15 mycroft exit(1);
307 1.10 cgd }
308 1.22 cgd if (stbuf.st_blksize >= TP_BSIZE && stbuf.st_blksize <= MAXBSIZE)
309 1.10 cgd fssize = stbuf.st_blksize;
310 1.10 cgd if (((fssize - 1) & fssize) != 0) {
311 1.10 cgd fprintf(stderr, "bad block size %d\n", fssize);
312 1.15 mycroft exit(1);
313 1.10 cgd }
314 1.10 cgd if (spcl.c_volume != 1) {
315 1.10 cgd fprintf(stderr, "Tape is not volume 1 of the dump\n");
316 1.15 mycroft exit(1);
317 1.10 cgd }
318 1.10 cgd if (gethead(&spcl) == FAIL) {
319 1.10 cgd dprintf(stdout, "header read failed at %d blocks\n", blksread);
320 1.10 cgd panic("no header after volume mark!\n");
321 1.10 cgd }
322 1.10 cgd findinode(&spcl);
323 1.10 cgd if (spcl.c_type != TS_CLRI) {
324 1.10 cgd fprintf(stderr, "Cannot find file removal list\n");
325 1.15 mycroft exit(1);
326 1.10 cgd }
327 1.10 cgd maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1;
328 1.54 christos dprintf(stdout, "maxino = %llu\n", (unsigned long long)maxino);
329 1.10 cgd map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
330 1.10 cgd if (map == NULL)
331 1.14 mycroft panic("no memory for active inode map\n");
332 1.14 mycroft usedinomap = map;
333 1.10 cgd curfile.action = USING;
334 1.10 cgd getfile(xtrmap, xtrmapskip);
335 1.10 cgd if (spcl.c_type != TS_BITS) {
336 1.10 cgd fprintf(stderr, "Cannot find file dump list\n");
337 1.15 mycroft exit(1);
338 1.10 cgd }
339 1.10 cgd map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY));
340 1.10 cgd if (map == (char *)NULL)
341 1.10 cgd panic("no memory for file dump list\n");
342 1.10 cgd dumpmap = map;
343 1.10 cgd curfile.action = USING;
344 1.10 cgd getfile(xtrmap, xtrmapskip);
345 1.14 mycroft /*
346 1.14 mycroft * If there may be whiteout entries on the tape, pretend that the
347 1.14 mycroft * whiteout inode exists, so that the whiteout entries can be
348 1.14 mycroft * extracted.
349 1.14 mycroft */
350 1.14 mycroft if (oldinofmt == 0)
351 1.14 mycroft SETINO(WINO, dumpmap);
352 1.10 cgd }
353 1.10 cgd
354 1.10 cgd /*
355 1.10 cgd * Prompt user to load a new dump volume.
356 1.10 cgd * "Nextvol" is the next suggested volume to use.
357 1.10 cgd * This suggested volume is enforced when doing full
358 1.10 cgd * or incremental restores, but can be overrridden by
359 1.10 cgd * the user when only extracting a subset of the files.
360 1.10 cgd */
361 1.10 cgd void
362 1.52 xtraeme getvol(int nextvol)
363 1.10 cgd {
364 1.28 lukem int newvol, savecnt, wantnext, i;
365 1.10 cgd union u_spcl tmpspcl;
366 1.10 cgd # define tmpbuf tmpspcl.s_spcl
367 1.10 cgd char buf[TP_BSIZE];
368 1.10 cgd
369 1.28 lukem newvol = savecnt = wantnext = 0;
370 1.10 cgd if (nextvol == 1) {
371 1.10 cgd tapesread = 0;
372 1.10 cgd gettingfile = 0;
373 1.10 cgd }
374 1.10 cgd if (pipein) {
375 1.10 cgd if (nextvol != 1)
376 1.10 cgd panic("Changing volumes on pipe input?\n");
377 1.10 cgd if (volno == 1)
378 1.10 cgd return;
379 1.10 cgd goto gethdr;
380 1.10 cgd }
381 1.10 cgd savecnt = blksread;
382 1.10 cgd again:
383 1.10 cgd if (pipein)
384 1.15 mycroft exit(1); /* pipes do not get a second chance */
385 1.10 cgd if (command == 'R' || command == 'r' || curfile.action != SKIP) {
386 1.10 cgd newvol = nextvol;
387 1.10 cgd wantnext = 1;
388 1.10 cgd } else {
389 1.10 cgd newvol = 0;
390 1.10 cgd wantnext = 0;
391 1.10 cgd }
392 1.10 cgd while (newvol <= 0) {
393 1.10 cgd if (tapesread == 0) {
394 1.10 cgd fprintf(stderr, "%s%s%s%s%s",
395 1.10 cgd "You have not read any tapes yet.\n",
396 1.10 cgd "Unless you know which volume your",
397 1.10 cgd " file(s) are on you should start\n",
398 1.10 cgd "with the last volume and work",
399 1.24 cjs " towards the first.\n");
400 1.38 lukem fprintf(stderr,
401 1.38 lukem "(Use 1 for the first volume/tape, etc.)\n");
402 1.10 cgd } else {
403 1.10 cgd fprintf(stderr, "You have read volumes");
404 1.10 cgd strcpy(buf, ": ");
405 1.10 cgd for (i = 1; i < 32; i++)
406 1.10 cgd if (tapesread & (1 << i)) {
407 1.10 cgd fprintf(stderr, "%s%d", buf, i);
408 1.10 cgd strcpy(buf, ", ");
409 1.10 cgd }
410 1.10 cgd fprintf(stderr, "\n");
411 1.10 cgd }
412 1.10 cgd do {
413 1.10 cgd fprintf(stderr, "Specify next volume #: ");
414 1.10 cgd (void) fflush(stderr);
415 1.10 cgd (void) fgets(buf, BUFSIZ, terminal);
416 1.10 cgd } while (!feof(terminal) && buf[0] == '\n');
417 1.10 cgd if (feof(terminal))
418 1.15 mycroft exit(1);
419 1.10 cgd newvol = atoi(buf);
420 1.10 cgd if (newvol <= 0) {
421 1.10 cgd fprintf(stderr,
422 1.10 cgd "Volume numbers are positive numerics\n");
423 1.10 cgd }
424 1.10 cgd }
425 1.10 cgd if (newvol == volno) {
426 1.10 cgd tapesread |= 1 << volno;
427 1.10 cgd return;
428 1.10 cgd }
429 1.10 cgd closemt();
430 1.10 cgd fprintf(stderr, "Mount tape volume %d\n", newvol);
431 1.10 cgd fprintf(stderr, "Enter ``none'' if there are no more tapes\n");
432 1.10 cgd fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape);
433 1.10 cgd (void) fflush(stderr);
434 1.10 cgd (void) fgets(buf, BUFSIZ, terminal);
435 1.10 cgd if (feof(terminal))
436 1.15 mycroft exit(1);
437 1.10 cgd if (!strcmp(buf, "none\n")) {
438 1.10 cgd terminateinput();
439 1.10 cgd return;
440 1.10 cgd }
441 1.10 cgd if (buf[0] != '\n') {
442 1.10 cgd (void) strcpy(magtape, buf);
443 1.10 cgd magtape[strlen(magtape) - 1] = '\0';
444 1.10 cgd }
445 1.10 cgd #ifdef RRESTORE
446 1.10 cgd if (host)
447 1.10 cgd mt = rmtopen(magtape, 0);
448 1.10 cgd else
449 1.10 cgd #endif
450 1.10 cgd mt = open(magtape, O_RDONLY, 0);
451 1.10 cgd
452 1.10 cgd if (mt == -1) {
453 1.10 cgd fprintf(stderr, "Cannot open %s\n", magtape);
454 1.10 cgd volno = -1;
455 1.10 cgd goto again;
456 1.10 cgd }
457 1.10 cgd gethdr:
458 1.10 cgd volno = newvol;
459 1.10 cgd setdumpnum();
460 1.10 cgd FLUSHTAPEBUF();
461 1.10 cgd if (gethead(&tmpbuf) == FAIL) {
462 1.10 cgd dprintf(stdout, "header read failed at %d blocks\n", blksread);
463 1.10 cgd fprintf(stderr, "tape is not dump tape\n");
464 1.10 cgd volno = 0;
465 1.10 cgd goto again;
466 1.10 cgd }
467 1.10 cgd if (tmpbuf.c_volume != volno) {
468 1.38 lukem fprintf(stderr,
469 1.38 lukem "Volume mismatch: expecting %d, tape header claims it is %d\n",
470 1.38 lukem volno, tmpbuf.c_volume);
471 1.10 cgd volno = 0;
472 1.10 cgd goto again;
473 1.10 cgd }
474 1.10 cgd if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) {
475 1.44 lukem time_t ttime = tmpbuf.c_date;
476 1.10 cgd fprintf(stderr, "Wrong dump date\n\tgot: %s",
477 1.44 lukem ctime(&ttime));
478 1.10 cgd fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
479 1.10 cgd volno = 0;
480 1.10 cgd goto again;
481 1.10 cgd }
482 1.10 cgd tapesread |= 1 << volno;
483 1.10 cgd blksread = savecnt;
484 1.10 cgd /*
485 1.10 cgd * If continuing from the previous volume, skip over any
486 1.10 cgd * blocks read already at the end of the previous volume.
487 1.10 cgd *
488 1.10 cgd * If coming to this volume at random, skip to the beginning
489 1.10 cgd * of the next record.
490 1.10 cgd */
491 1.10 cgd dprintf(stdout, "read %ld recs, tape starts with %ld\n",
492 1.28 lukem (long)tpblksread, (long)tmpbuf.c_firstrec);
493 1.10 cgd if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER)) {
494 1.10 cgd if (!wantnext) {
495 1.10 cgd tpblksread = tmpbuf.c_firstrec;
496 1.10 cgd for (i = tmpbuf.c_count; i > 0; i--)
497 1.10 cgd readtape(buf);
498 1.10 cgd } else if (tmpbuf.c_firstrec > 0 &&
499 1.10 cgd tmpbuf.c_firstrec < tpblksread - 1) {
500 1.10 cgd /*
501 1.10 cgd * -1 since we've read the volume header
502 1.10 cgd */
503 1.10 cgd i = tpblksread - tmpbuf.c_firstrec - 1;
504 1.10 cgd dprintf(stderr, "Skipping %d duplicate record%s.\n",
505 1.10 cgd i, i > 1 ? "s" : "");
506 1.10 cgd while (--i >= 0)
507 1.10 cgd readtape(buf);
508 1.10 cgd }
509 1.10 cgd }
510 1.10 cgd if (curfile.action == USING) {
511 1.10 cgd if (volno == 1)
512 1.10 cgd panic("active file into volume 1\n");
513 1.10 cgd return;
514 1.10 cgd }
515 1.10 cgd /*
516 1.10 cgd * Skip up to the beginning of the next record
517 1.10 cgd */
518 1.10 cgd if (tmpbuf.c_type == TS_TAPE && (tmpbuf.c_flags & DR_NEWHEADER))
519 1.10 cgd for (i = tmpbuf.c_count; i > 0; i--)
520 1.10 cgd readtape(buf);
521 1.10 cgd (void) gethead(&spcl);
522 1.10 cgd findinode(&spcl);
523 1.10 cgd if (gettingfile) {
524 1.10 cgd gettingfile = 0;
525 1.10 cgd longjmp(restart, 1);
526 1.10 cgd }
527 1.10 cgd }
528 1.10 cgd
529 1.10 cgd /*
530 1.10 cgd * Handle unexpected EOF.
531 1.10 cgd */
532 1.10 cgd static void
533 1.52 xtraeme terminateinput(void)
534 1.10 cgd {
535 1.10 cgd
536 1.10 cgd if (gettingfile && curfile.action == USING) {
537 1.10 cgd printf("Warning: %s %s\n",
538 1.10 cgd "End-of-input encountered while extracting", curfile.name);
539 1.10 cgd }
540 1.10 cgd curfile.name = "<name unknown>";
541 1.10 cgd curfile.action = UNKNOWN;
542 1.48 fvdl curfile.mode = 0;
543 1.10 cgd curfile.ino = maxino;
544 1.10 cgd if (gettingfile) {
545 1.10 cgd gettingfile = 0;
546 1.10 cgd longjmp(restart, 1);
547 1.10 cgd }
548 1.10 cgd }
549 1.10 cgd
550 1.10 cgd /*
551 1.10 cgd * handle multiple dumps per tape by skipping forward to the
552 1.10 cgd * appropriate one.
553 1.10 cgd */
554 1.10 cgd static void
555 1.52 xtraeme setdumpnum(void)
556 1.10 cgd {
557 1.10 cgd struct mtop tcom;
558 1.10 cgd
559 1.10 cgd if (dumpnum == 1 || volno != 1)
560 1.10 cgd return;
561 1.10 cgd if (pipein) {
562 1.10 cgd fprintf(stderr, "Cannot have multiple dumps on pipe input\n");
563 1.15 mycroft exit(1);
564 1.10 cgd }
565 1.10 cgd tcom.mt_op = MTFSF;
566 1.10 cgd tcom.mt_count = dumpnum - 1;
567 1.10 cgd #ifdef RRESTORE
568 1.10 cgd if (host)
569 1.10 cgd rmtioctl(MTFSF, dumpnum - 1);
570 1.10 cgd else
571 1.10 cgd #endif
572 1.10 cgd if (ioctl(mt, (int)MTIOCTOP, (char *)&tcom) < 0)
573 1.10 cgd fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno));
574 1.10 cgd }
575 1.10 cgd
576 1.10 cgd void
577 1.52 xtraeme printdumpinfo(void)
578 1.10 cgd {
579 1.44 lukem time_t ttime;
580 1.44 lukem
581 1.44 lukem ttime = spcl.c_date;
582 1.44 lukem fprintf(stdout, "Dump date: %s", ctime(&ttime));
583 1.44 lukem ttime = spcl.c_ddate;
584 1.10 cgd fprintf(stdout, "Dumped from: %s",
585 1.44 lukem (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&ttime));
586 1.10 cgd fprintf(stderr, "Level %d dump of %s on %s:%s\n",
587 1.39 sommerfe spcl.c_level, spcl.c_filesys,
588 1.39 sommerfe *spcl.c_host? spcl.c_host: "[unknown]", spcl.c_dev);
589 1.10 cgd fprintf(stderr, "Label: %s\n", spcl.c_label);
590 1.51 bouyer
591 1.51 bouyer if (Mtreefile) {
592 1.51 bouyer ttime = spcl.c_date;
593 1.51 bouyer fprintf(Mtreefile, "#Dump date: %s", ctime(&ttime));
594 1.51 bouyer ttime = spcl.c_ddate;
595 1.51 bouyer fprintf(Mtreefile, "#Dumped from: %s",
596 1.51 bouyer (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&ttime));
597 1.51 bouyer fprintf(Mtreefile, "#Level %d dump of %s on %s:%s\n",
598 1.51 bouyer spcl.c_level, spcl.c_filesys,
599 1.51 bouyer *spcl.c_host? spcl.c_host: "[unknown]", spcl.c_dev);
600 1.51 bouyer fprintf(Mtreefile, "#Label: %s\n", spcl.c_label);
601 1.51 bouyer fprintf(Mtreefile, "/set uname=root gname=wheel\n");
602 1.51 bouyer if (ferror(Mtreefile))
603 1.51 bouyer err(1, "error writing to mtree file");
604 1.51 bouyer }
605 1.10 cgd }
606 1.10 cgd
607 1.10 cgd int
608 1.52 xtraeme extractfile(char *name)
609 1.10 cgd {
610 1.50 enami union digest_buffer dbuffer;
611 1.14 mycroft int flags;
612 1.30 enami uid_t uid;
613 1.30 enami gid_t gid;
614 1.14 mycroft mode_t mode;
615 1.48 fvdl struct timeval mtimep[2], ctimep[2];
616 1.10 cgd struct entry *ep;
617 1.48 fvdl int setbirth;
618 1.10 cgd
619 1.10 cgd curfile.name = name;
620 1.10 cgd curfile.action = USING;
621 1.48 fvdl mtimep[0].tv_sec = curfile.atime_sec;
622 1.48 fvdl mtimep[0].tv_usec = curfile.atime_nsec / 1000;
623 1.48 fvdl mtimep[1].tv_sec = curfile.mtime_sec;
624 1.48 fvdl mtimep[1].tv_usec = curfile.mtime_nsec / 1000;
625 1.48 fvdl
626 1.48 fvdl setbirth = curfile.birthtime_sec != 0;
627 1.48 fvdl
628 1.48 fvdl if (setbirth) {
629 1.48 fvdl ctimep[0].tv_sec = curfile.atime_sec;
630 1.48 fvdl ctimep[0].tv_usec = curfile.atime_nsec / 1000;
631 1.48 fvdl ctimep[1].tv_sec = curfile.birthtime_sec;
632 1.48 fvdl ctimep[1].tv_usec = curfile.birthtime_nsec / 1000;
633 1.48 fvdl }
634 1.48 fvdl uid = curfile.uid;
635 1.48 fvdl gid = curfile.gid;
636 1.48 fvdl mode = curfile.mode;
637 1.48 fvdl flags = curfile.file_flags;
638 1.10 cgd switch (mode & IFMT) {
639 1.10 cgd
640 1.10 cgd default:
641 1.10 cgd fprintf(stderr, "%s: unknown file mode 0%o\n", name, mode);
642 1.10 cgd skipfile();
643 1.10 cgd return (FAIL);
644 1.10 cgd
645 1.10 cgd case IFSOCK:
646 1.10 cgd vprintf(stdout, "skipped socket %s\n", name);
647 1.10 cgd skipfile();
648 1.10 cgd return (GOOD);
649 1.10 cgd
650 1.10 cgd case IFDIR:
651 1.10 cgd if (mflag) {
652 1.10 cgd ep = lookupname(name);
653 1.10 cgd if (ep == NULL || ep->e_flags & EXTRACT)
654 1.10 cgd panic("unextracted directory %s\n", name);
655 1.10 cgd skipfile();
656 1.10 cgd return (GOOD);
657 1.10 cgd }
658 1.10 cgd vprintf(stdout, "extract file %s\n", name);
659 1.10 cgd return (genliteraldir(name, curfile.ino));
660 1.10 cgd
661 1.10 cgd case IFLNK:
662 1.10 cgd lnkbuf[0] = '\0';
663 1.10 cgd pathlen = 0;
664 1.10 cgd getfile(xtrlnkfile, xtrlnkskip);
665 1.10 cgd if (pathlen == 0) {
666 1.10 cgd vprintf(stdout,
667 1.10 cgd "%s: zero length symbolic link (ignored)\n", name);
668 1.10 cgd return (GOOD);
669 1.10 cgd }
670 1.37 christos if (uflag)
671 1.37 christos (void) unlink(name);
672 1.30 enami if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
673 1.48 fvdl if (setbirth)
674 1.48 fvdl (void) lutimes(name, ctimep);
675 1.48 fvdl (void) lutimes(name, mtimep);
676 1.31 mycroft (void) lchown(name, uid, gid);
677 1.31 mycroft (void) lchmod(name, mode);
678 1.51 bouyer if (Mtreefile) {
679 1.51 bouyer writemtree(name, "link",
680 1.51 bouyer uid, gid, mode, flags);
681 1.51 bouyer } else
682 1.51 bouyer (void) lchflags(name, flags);
683 1.30 enami return (GOOD);
684 1.30 enami }
685 1.30 enami return (FAIL);
686 1.12 mycroft
687 1.14 mycroft case IFCHR:
688 1.14 mycroft case IFBLK:
689 1.14 mycroft vprintf(stdout, "extract special file %s\n", name);
690 1.12 mycroft if (Nflag) {
691 1.12 mycroft skipfile();
692 1.12 mycroft return (GOOD);
693 1.12 mycroft }
694 1.37 christos if (uflag)
695 1.37 christos (void) unlink(name);
696 1.34 enami if (mknod(name, (mode & (IFCHR | IFBLK)) | 0600,
697 1.48 fvdl (int)curfile.rdev) < 0) {
698 1.14 mycroft fprintf(stderr, "%s: cannot create special file: %s\n",
699 1.12 mycroft name, strerror(errno));
700 1.12 mycroft skipfile();
701 1.12 mycroft return (FAIL);
702 1.12 mycroft }
703 1.32 enami skipfile();
704 1.48 fvdl if (setbirth)
705 1.48 fvdl (void) utimes(name, ctimep);
706 1.48 fvdl (void) utimes(name, mtimep);
707 1.32 enami (void) chown(name, uid, gid);
708 1.12 mycroft (void) chmod(name, mode);
709 1.51 bouyer if (Mtreefile) {
710 1.51 bouyer writemtree(name,
711 1.51 bouyer ((mode & (S_IFBLK | IFCHR)) == IFBLK) ?
712 1.51 bouyer "block" : "char",
713 1.51 bouyer uid, gid, mode, flags);
714 1.51 bouyer } else
715 1.51 bouyer (void) chflags(name, flags);
716 1.12 mycroft return (GOOD);
717 1.10 cgd
718 1.14 mycroft case IFIFO:
719 1.14 mycroft vprintf(stdout, "extract fifo %s\n", name);
720 1.10 cgd if (Nflag) {
721 1.10 cgd skipfile();
722 1.10 cgd return (GOOD);
723 1.10 cgd }
724 1.37 christos if (uflag)
725 1.37 christos (void) unlink(name);
726 1.33 enami if (mkfifo(name, 0600) < 0) {
727 1.14 mycroft fprintf(stderr, "%s: cannot create fifo: %s\n",
728 1.10 cgd name, strerror(errno));
729 1.10 cgd skipfile();
730 1.10 cgd return (FAIL);
731 1.10 cgd }
732 1.32 enami skipfile();
733 1.48 fvdl if (setbirth)
734 1.48 fvdl (void) utimes(name, ctimep);
735 1.48 fvdl (void) utimes(name, mtimep);
736 1.32 enami (void) chown(name, uid, gid);
737 1.10 cgd (void) chmod(name, mode);
738 1.51 bouyer if (Mtreefile) {
739 1.51 bouyer writemtree(name, "fifo",
740 1.51 bouyer uid, gid, mode, flags);
741 1.51 bouyer } else
742 1.51 bouyer (void) chflags(name, flags);
743 1.10 cgd return (GOOD);
744 1.10 cgd
745 1.10 cgd case IFREG:
746 1.10 cgd vprintf(stdout, "extract file %s\n", name);
747 1.37 christos if (uflag)
748 1.37 christos (void) unlink(name);
749 1.50 enami if (!Nflag && (ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
750 1.32 enami 0600)) < 0) {
751 1.10 cgd fprintf(stderr, "%s: cannot create file: %s\n",
752 1.10 cgd name, strerror(errno));
753 1.10 cgd skipfile();
754 1.10 cgd return (FAIL);
755 1.10 cgd }
756 1.50 enami if (Dflag)
757 1.50 enami (*ddesc->dd_init)(&dcontext);
758 1.32 enami getfile(xtrfile, xtrskip);
759 1.50 enami if (Dflag) {
760 1.50 enami (*ddesc->dd_end)(&dcontext, &dbuffer);
761 1.50 enami for (ep = lookupname(name); ep != NULL;
762 1.50 enami ep = ep->e_links)
763 1.50 enami fprintf(stdout, "%s (%s) = %s\n",
764 1.50 enami ddesc->dd_name, myname(ep),
765 1.50 enami (char *)&dbuffer);
766 1.50 enami }
767 1.50 enami if (Nflag)
768 1.50 enami return (GOOD);
769 1.48 fvdl if (setbirth)
770 1.48 fvdl (void) futimes(ofile, ctimep);
771 1.48 fvdl (void) futimes(ofile, mtimep);
772 1.32 enami (void) fchown(ofile, uid, gid);
773 1.10 cgd (void) fchmod(ofile, mode);
774 1.51 bouyer if (Mtreefile) {
775 1.51 bouyer writemtree(name, "file",
776 1.51 bouyer uid, gid, mode, flags);
777 1.51 bouyer } else
778 1.51 bouyer (void) fchflags(ofile, flags);
779 1.10 cgd (void) close(ofile);
780 1.10 cgd return (GOOD);
781 1.10 cgd }
782 1.10 cgd /* NOTREACHED */
783 1.10 cgd }
784 1.10 cgd
785 1.10 cgd /*
786 1.10 cgd * skip over bit maps on the tape
787 1.10 cgd */
788 1.10 cgd void
789 1.52 xtraeme skipmaps(void)
790 1.10 cgd {
791 1.10 cgd
792 1.10 cgd while (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI)
793 1.10 cgd skipfile();
794 1.10 cgd }
795 1.10 cgd
796 1.10 cgd /*
797 1.10 cgd * skip over a file on the tape
798 1.10 cgd */
799 1.10 cgd void
800 1.52 xtraeme skipfile(void)
801 1.10 cgd {
802 1.10 cgd
803 1.10 cgd curfile.action = SKIP;
804 1.10 cgd getfile(xtrnull, xtrnull);
805 1.10 cgd }
806 1.10 cgd
807 1.10 cgd /*
808 1.10 cgd * Extract a file from the tape.
809 1.10 cgd * When an allocated block is found it is passed to the fill function;
810 1.10 cgd * when an unallocated block (hole) is found, a zeroed buffer is passed
811 1.10 cgd * to the skip function.
812 1.10 cgd */
813 1.10 cgd void
814 1.52 xtraeme getfile(void (*fill)(char *buf, long size),
815 1.52 xtraeme void (*skip)(char *buf, long size))
816 1.10 cgd {
817 1.25 lukem int i;
818 1.10 cgd int curblk = 0;
819 1.48 fvdl quad_t size = spcl.c_size;
820 1.10 cgd static char clearedbuf[MAXBSIZE];
821 1.10 cgd char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
822 1.10 cgd char junk[TP_BSIZE];
823 1.10 cgd
824 1.28 lukem #ifdef __GNUC__ /* XXX: to shut up gcc warnings */
825 1.28 lukem (void)&curblk;
826 1.28 lukem (void)&size;
827 1.28 lukem #endif
828 1.28 lukem
829 1.10 cgd if (spcl.c_type == TS_END)
830 1.10 cgd panic("ran off end of tape\n");
831 1.48 fvdl if (spcl.c_magic != FS_UFS2_MAGIC)
832 1.10 cgd panic("not at beginning of a file\n");
833 1.10 cgd if (!gettingfile && setjmp(restart) != 0)
834 1.10 cgd return;
835 1.10 cgd gettingfile++;
836 1.10 cgd loop:
837 1.10 cgd for (i = 0; i < spcl.c_count; i++) {
838 1.40 enami if (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI ||
839 1.40 enami spcl.c_addr[i]) {
840 1.10 cgd readtape(&buf[curblk++][0]);
841 1.10 cgd if (curblk == fssize / TP_BSIZE) {
842 1.29 lukem (*fill)((char *)buf, (long)(size > TP_BSIZE ?
843 1.29 lukem fssize : (curblk - 1) * TP_BSIZE + size));
844 1.10 cgd curblk = 0;
845 1.10 cgd }
846 1.10 cgd } else {
847 1.10 cgd if (curblk > 0) {
848 1.29 lukem (*fill)((char *)buf, (long)(size > TP_BSIZE ?
849 1.29 lukem curblk * TP_BSIZE :
850 1.29 lukem (curblk - 1) * TP_BSIZE + size));
851 1.10 cgd curblk = 0;
852 1.10 cgd }
853 1.29 lukem (*skip)(clearedbuf, (long)(size > TP_BSIZE ?
854 1.29 lukem TP_BSIZE : size));
855 1.10 cgd }
856 1.10 cgd if ((size -= TP_BSIZE) <= 0) {
857 1.41 enami if (spcl.c_type == TS_BITS || spcl.c_type == TS_CLRI) {
858 1.41 enami /*
859 1.41 enami * In this case, the following expression
860 1.41 enami * should always be false since the size was
861 1.48 fvdl * initially set to spcl.c_size and
862 1.41 enami * it is initialized to spcl.c_count * TP_BSIZE
863 1.41 enami * in gethead().
864 1.41 enami */
865 1.41 enami if (!(size == 0 && i == spcl.c_count - 1))
866 1.41 enami panic("inconsistent map size\n");
867 1.41 enami } else {
868 1.40 enami for (i++; i < spcl.c_count; i++)
869 1.40 enami if (spcl.c_addr[i])
870 1.40 enami readtape(junk);
871 1.40 enami }
872 1.10 cgd break;
873 1.10 cgd }
874 1.10 cgd }
875 1.10 cgd if (gethead(&spcl) == GOOD && size > 0) {
876 1.10 cgd if (spcl.c_type == TS_ADDR)
877 1.10 cgd goto loop;
878 1.10 cgd dprintf(stdout,
879 1.10 cgd "Missing address (header) block for %s at %d blocks\n",
880 1.10 cgd curfile.name, blksread);
881 1.10 cgd }
882 1.10 cgd if (curblk > 0)
883 1.29 lukem (*fill)((char *)buf, (long)((curblk * TP_BSIZE) + size));
884 1.10 cgd findinode(&spcl);
885 1.10 cgd gettingfile = 0;
886 1.10 cgd }
887 1.10 cgd
888 1.10 cgd /*
889 1.10 cgd * Write out the next block of a file.
890 1.10 cgd */
891 1.10 cgd static void
892 1.52 xtraeme xtrfile(char *buf, long size)
893 1.10 cgd {
894 1.10 cgd
895 1.50 enami if (Dflag)
896 1.50 enami (*ddesc->dd_update)(&dcontext, buf, size);
897 1.10 cgd if (Nflag)
898 1.10 cgd return;
899 1.10 cgd if (write(ofile, buf, (int) size) == -1) {
900 1.10 cgd fprintf(stderr,
901 1.54 christos "write error extracting inode %llu, name %s\nwrite: %s\n",
902 1.54 christos (unsigned long long)curfile.ino, curfile.name,
903 1.54 christos strerror(errno));
904 1.15 mycroft exit(1);
905 1.10 cgd }
906 1.10 cgd }
907 1.10 cgd
908 1.10 cgd /*
909 1.10 cgd * Skip over a hole in a file.
910 1.10 cgd */
911 1.10 cgd /* ARGSUSED */
912 1.10 cgd static void
913 1.52 xtraeme xtrskip(char *buf, long size)
914 1.10 cgd {
915 1.10 cgd
916 1.50 enami if (Dflag)
917 1.50 enami (*ddesc->dd_update)(&dcontext, buf, size);
918 1.50 enami if (Nflag)
919 1.50 enami return;
920 1.10 cgd if (lseek(ofile, size, SEEK_CUR) == -1) {
921 1.10 cgd fprintf(stderr,
922 1.54 christos "seek error extracting inode %llu, name %s\nlseek: %s\n",
923 1.54 christos (unsigned long long)curfile.ino, curfile.name,
924 1.54 christos strerror(errno));
925 1.15 mycroft exit(1);
926 1.10 cgd }
927 1.10 cgd }
928 1.10 cgd
929 1.10 cgd /*
930 1.10 cgd * Collect the next block of a symbolic link.
931 1.10 cgd */
932 1.10 cgd static void
933 1.52 xtraeme xtrlnkfile(char *buf, long size)
934 1.10 cgd {
935 1.10 cgd
936 1.10 cgd pathlen += size;
937 1.10 cgd if (pathlen > MAXPATHLEN) {
938 1.10 cgd fprintf(stderr, "symbolic link name: %s->%s%s; too long %d\n",
939 1.10 cgd curfile.name, lnkbuf, buf, pathlen);
940 1.15 mycroft exit(1);
941 1.10 cgd }
942 1.10 cgd (void) strcat(lnkbuf, buf);
943 1.10 cgd }
944 1.10 cgd
945 1.10 cgd /*
946 1.10 cgd * Skip over a hole in a symbolic link (should never happen).
947 1.10 cgd */
948 1.10 cgd /* ARGSUSED */
949 1.10 cgd static void
950 1.52 xtraeme xtrlnkskip(char *buf, long size)
951 1.10 cgd {
952 1.10 cgd
953 1.10 cgd fprintf(stderr, "unallocated block in symbolic link %s\n",
954 1.10 cgd curfile.name);
955 1.15 mycroft exit(1);
956 1.10 cgd }
957 1.10 cgd
958 1.10 cgd /*
959 1.10 cgd * Collect the next block of a bit map.
960 1.10 cgd */
961 1.10 cgd static void
962 1.52 xtraeme xtrmap(char *buf, long size)
963 1.10 cgd {
964 1.10 cgd
965 1.29 lukem memmove(map, buf, size);
966 1.10 cgd map += size;
967 1.10 cgd }
968 1.10 cgd
969 1.10 cgd /*
970 1.10 cgd * Skip over a hole in a bit map (should never happen).
971 1.10 cgd */
972 1.10 cgd /* ARGSUSED */
973 1.10 cgd static void
974 1.52 xtraeme xtrmapskip(char *buf, long size)
975 1.10 cgd {
976 1.10 cgd
977 1.10 cgd panic("hole in map\n");
978 1.10 cgd map += size;
979 1.10 cgd }
980 1.10 cgd
981 1.10 cgd /*
982 1.10 cgd * Noop, when an extraction function is not needed.
983 1.10 cgd */
984 1.10 cgd /* ARGSUSED */
985 1.10 cgd void
986 1.52 xtraeme xtrnull(char *buf, long size)
987 1.10 cgd {
988 1.10 cgd
989 1.10 cgd return;
990 1.10 cgd }
991 1.10 cgd
992 1.10 cgd /*
993 1.10 cgd * Read TP_BSIZE blocks from the input.
994 1.10 cgd * Handle read errors, and end of media.
995 1.10 cgd */
996 1.10 cgd static void
997 1.52 xtraeme readtape(char *buf)
998 1.10 cgd {
999 1.28 lukem int rd, newvol, i;
1000 1.10 cgd int cnt, seek_failed;
1001 1.10 cgd
1002 1.10 cgd if (blkcnt < numtrec) {
1003 1.29 lukem memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
1004 1.10 cgd blksread++;
1005 1.10 cgd tpblksread++;
1006 1.10 cgd return;
1007 1.10 cgd }
1008 1.10 cgd for (i = 0; i < ntrec; i++)
1009 1.10 cgd ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
1010 1.10 cgd if (numtrec == 0)
1011 1.10 cgd numtrec = ntrec;
1012 1.10 cgd cnt = ntrec * TP_BSIZE;
1013 1.10 cgd rd = 0;
1014 1.10 cgd getmore:
1015 1.10 cgd #ifdef RRESTORE
1016 1.10 cgd if (host)
1017 1.10 cgd i = rmtread(&tapebuf[rd], cnt);
1018 1.10 cgd else
1019 1.10 cgd #endif
1020 1.10 cgd i = read(mt, &tapebuf[rd], cnt);
1021 1.10 cgd /*
1022 1.10 cgd * Check for mid-tape short read error.
1023 1.10 cgd * If found, skip rest of buffer and start with the next.
1024 1.10 cgd */
1025 1.10 cgd if (!pipein && numtrec < ntrec && i > 0) {
1026 1.10 cgd dprintf(stdout, "mid-media short read error.\n");
1027 1.10 cgd numtrec = ntrec;
1028 1.10 cgd }
1029 1.10 cgd /*
1030 1.10 cgd * Handle partial block read.
1031 1.10 cgd */
1032 1.10 cgd if (pipein && i == 0 && rd > 0)
1033 1.10 cgd i = rd;
1034 1.10 cgd else if (i > 0 && i != ntrec * TP_BSIZE) {
1035 1.10 cgd if (pipein) {
1036 1.10 cgd rd += i;
1037 1.10 cgd cnt -= i;
1038 1.10 cgd if (cnt > 0)
1039 1.10 cgd goto getmore;
1040 1.10 cgd i = rd;
1041 1.10 cgd } else {
1042 1.10 cgd /*
1043 1.10 cgd * Short read. Process the blocks read.
1044 1.10 cgd */
1045 1.10 cgd if (i % TP_BSIZE != 0)
1046 1.10 cgd vprintf(stdout,
1047 1.10 cgd "partial block read: %d should be %d\n",
1048 1.10 cgd i, ntrec * TP_BSIZE);
1049 1.10 cgd numtrec = i / TP_BSIZE;
1050 1.10 cgd }
1051 1.10 cgd }
1052 1.10 cgd /*
1053 1.10 cgd * Handle read error.
1054 1.10 cgd */
1055 1.10 cgd if (i < 0) {
1056 1.10 cgd fprintf(stderr, "Tape read error while ");
1057 1.10 cgd switch (curfile.action) {
1058 1.10 cgd default:
1059 1.10 cgd fprintf(stderr, "trying to set up tape\n");
1060 1.10 cgd break;
1061 1.10 cgd case UNKNOWN:
1062 1.10 cgd fprintf(stderr, "trying to resynchronize\n");
1063 1.10 cgd break;
1064 1.10 cgd case USING:
1065 1.10 cgd fprintf(stderr, "restoring %s\n", curfile.name);
1066 1.10 cgd break;
1067 1.10 cgd case SKIP:
1068 1.54 christos fprintf(stderr, "skipping over inode %llu\n",
1069 1.54 christos (unsigned long long)curfile.ino);
1070 1.10 cgd break;
1071 1.10 cgd }
1072 1.10 cgd if (!yflag && !reply("continue"))
1073 1.15 mycroft exit(1);
1074 1.10 cgd i = ntrec * TP_BSIZE;
1075 1.13 mycroft memset(tapebuf, 0, i);
1076 1.10 cgd #ifdef RRESTORE
1077 1.10 cgd if (host)
1078 1.10 cgd seek_failed = (rmtseek(i, 1) < 0);
1079 1.10 cgd else
1080 1.10 cgd #endif
1081 1.10 cgd seek_failed = (lseek(mt, i, SEEK_CUR) == (off_t)-1);
1082 1.10 cgd
1083 1.10 cgd if (seek_failed) {
1084 1.10 cgd fprintf(stderr,
1085 1.10 cgd "continuation failed: %s\n", strerror(errno));
1086 1.15 mycroft exit(1);
1087 1.10 cgd }
1088 1.10 cgd }
1089 1.10 cgd /*
1090 1.10 cgd * Handle end of tape.
1091 1.10 cgd */
1092 1.10 cgd if (i == 0) {
1093 1.10 cgd vprintf(stdout, "End-of-tape encountered\n");
1094 1.10 cgd if (!pipein) {
1095 1.10 cgd newvol = volno + 1;
1096 1.10 cgd volno = 0;
1097 1.10 cgd numtrec = 0;
1098 1.10 cgd getvol(newvol);
1099 1.10 cgd readtape(buf);
1100 1.10 cgd return;
1101 1.10 cgd }
1102 1.10 cgd if (rd % TP_BSIZE != 0)
1103 1.10 cgd panic("partial block read: %d should be %d\n",
1104 1.10 cgd rd, ntrec * TP_BSIZE);
1105 1.10 cgd terminateinput();
1106 1.29 lukem memmove(&tapebuf[rd], &endoftapemark, (long)TP_BSIZE);
1107 1.10 cgd }
1108 1.10 cgd blkcnt = 0;
1109 1.29 lukem memmove(buf, &tapebuf[(blkcnt++ * TP_BSIZE)], (long)TP_BSIZE);
1110 1.10 cgd blksread++;
1111 1.10 cgd tpblksread++;
1112 1.10 cgd }
1113 1.10 cgd
1114 1.10 cgd static void
1115 1.52 xtraeme findtapeblksize(void)
1116 1.10 cgd {
1117 1.25 lukem long i;
1118 1.10 cgd
1119 1.10 cgd for (i = 0; i < ntrec; i++)
1120 1.10 cgd ((struct s_spcl *)&tapebuf[i * TP_BSIZE])->c_magic = 0;
1121 1.10 cgd blkcnt = 0;
1122 1.10 cgd #ifdef RRESTORE
1123 1.10 cgd if (host)
1124 1.10 cgd i = rmtread(tapebuf, ntrec * TP_BSIZE);
1125 1.10 cgd else
1126 1.10 cgd #endif
1127 1.10 cgd i = read(mt, tapebuf, ntrec * TP_BSIZE);
1128 1.10 cgd
1129 1.10 cgd if (i <= 0) {
1130 1.10 cgd fprintf(stderr, "tape read error: %s\n", strerror(errno));
1131 1.15 mycroft exit(1);
1132 1.10 cgd }
1133 1.10 cgd if (i % TP_BSIZE != 0) {
1134 1.28 lukem fprintf(stderr, "Tape block size (%ld) %s (%ld)\n",
1135 1.28 lukem (long)i, "is not a multiple of dump block size",
1136 1.28 lukem (long)TP_BSIZE);
1137 1.15 mycroft exit(1);
1138 1.10 cgd }
1139 1.10 cgd ntrec = i / TP_BSIZE;
1140 1.10 cgd numtrec = ntrec;
1141 1.10 cgd vprintf(stdout, "Tape block size is %d\n", ntrec);
1142 1.10 cgd }
1143 1.10 cgd
1144 1.10 cgd void
1145 1.52 xtraeme closemt(void)
1146 1.10 cgd {
1147 1.10 cgd
1148 1.10 cgd if (mt < 0)
1149 1.10 cgd return;
1150 1.10 cgd #ifdef RRESTORE
1151 1.10 cgd if (host)
1152 1.10 cgd rmtclose();
1153 1.10 cgd else
1154 1.10 cgd #endif
1155 1.10 cgd (void) close(mt);
1156 1.10 cgd }
1157 1.10 cgd
1158 1.10 cgd /*
1159 1.10 cgd * Read the next block from the tape.
1160 1.10 cgd * Check to see if it is one of several vintage headers.
1161 1.10 cgd * If it is an old style header, convert it to a new style header.
1162 1.10 cgd * If it is not any valid header, return an error.
1163 1.10 cgd */
1164 1.10 cgd static int
1165 1.52 xtraeme gethead(struct s_spcl *buf)
1166 1.10 cgd {
1167 1.48 fvdl union u_ospcl u_ospcl;
1168 1.10 cgd
1169 1.10 cgd if (!cvtflag) {
1170 1.10 cgd readtape((char *)buf);
1171 1.48 fvdl if (buf->c_magic != NFS_MAGIC &&
1172 1.48 fvdl buf->c_magic != FS_UFS2_MAGIC) {
1173 1.48 fvdl if (bswap32(buf->c_magic) != NFS_MAGIC &&
1174 1.48 fvdl bswap32(buf->c_magic) != FS_UFS2_MAGIC)
1175 1.10 cgd return (FAIL);
1176 1.10 cgd if (!Bcvt) {
1177 1.10 cgd vprintf(stdout, "Note: Doing Byte swapping\n");
1178 1.10 cgd Bcvt = 1;
1179 1.10 cgd }
1180 1.10 cgd }
1181 1.10 cgd if (checksum((int *)buf) == FAIL)
1182 1.10 cgd return (FAIL);
1183 1.10 cgd if (Bcvt)
1184 1.48 fvdl swap_header(buf);
1185 1.10 cgd goto good;
1186 1.10 cgd }
1187 1.48 fvdl
1188 1.10 cgd readtape((char *)(&u_ospcl.s_ospcl));
1189 1.48 fvdl if (checksum((int *)(&u_ospcl.s_ospcl)) == FAIL)
1190 1.48 fvdl return (FAIL);
1191 1.48 fvdl if (u_ospcl.s_ospcl.c_magic != OFS_MAGIC) {
1192 1.48 fvdl if (bswap32(u_ospcl.s_ospcl.c_magic) != OFS_MAGIC)
1193 1.48 fvdl return (FAIL);
1194 1.48 fvdl if (!Bcvt) {
1195 1.48 fvdl vprintf(stdout, "Note: Doing Byte swapping\n");
1196 1.48 fvdl Bcvt = 1;
1197 1.48 fvdl }
1198 1.48 fvdl swap_old_header(&u_ospcl.s_ospcl);
1199 1.48 fvdl }
1200 1.48 fvdl
1201 1.13 mycroft memset(buf, 0, (long)TP_BSIZE);
1202 1.10 cgd buf->c_type = u_ospcl.s_ospcl.c_type;
1203 1.10 cgd buf->c_date = u_ospcl.s_ospcl.c_date;
1204 1.10 cgd buf->c_ddate = u_ospcl.s_ospcl.c_ddate;
1205 1.10 cgd buf->c_volume = u_ospcl.s_ospcl.c_volume;
1206 1.10 cgd buf->c_tapea = u_ospcl.s_ospcl.c_tapea;
1207 1.10 cgd buf->c_inumber = u_ospcl.s_ospcl.c_inumber;
1208 1.10 cgd buf->c_checksum = u_ospcl.s_ospcl.c_checksum;
1209 1.48 fvdl buf->c_mode = u_ospcl.s_ospcl.c_odinode.odi_mode;
1210 1.48 fvdl buf->c_uid = u_ospcl.s_ospcl.c_odinode.odi_uid;
1211 1.48 fvdl buf->c_gid = u_ospcl.s_ospcl.c_odinode.odi_gid;
1212 1.48 fvdl buf->c_size = u_ospcl.s_ospcl.c_odinode.odi_size;
1213 1.48 fvdl buf->c_rdev = u_ospcl.s_ospcl.c_odinode.odi_rdev;
1214 1.48 fvdl buf->c_atime = u_ospcl.s_ospcl.c_odinode.odi_atime;
1215 1.48 fvdl buf->c_mtime = u_ospcl.s_ospcl.c_odinode.odi_mtime;
1216 1.10 cgd buf->c_count = u_ospcl.s_ospcl.c_count;
1217 1.29 lukem memmove(buf->c_addr, u_ospcl.s_ospcl.c_addr, (long)256);
1218 1.48 fvdl buf->c_magic = FS_UFS2_MAGIC;
1219 1.10 cgd good:
1220 1.10 cgd switch (buf->c_type) {
1221 1.10 cgd
1222 1.10 cgd case TS_CLRI:
1223 1.10 cgd case TS_BITS:
1224 1.10 cgd /*
1225 1.10 cgd * Have to patch up missing information in bit map headers
1226 1.10 cgd */
1227 1.10 cgd buf->c_inumber = 0;
1228 1.48 fvdl buf->c_size = buf->c_count * TP_BSIZE;
1229 1.10 cgd break;
1230 1.10 cgd
1231 1.10 cgd case TS_TAPE:
1232 1.10 cgd if ((buf->c_flags & DR_NEWINODEFMT) == 0)
1233 1.10 cgd oldinofmt = 1;
1234 1.10 cgd /* fall through */
1235 1.10 cgd case TS_END:
1236 1.10 cgd buf->c_inumber = 0;
1237 1.10 cgd break;
1238 1.10 cgd
1239 1.10 cgd case TS_INODE:
1240 1.48 fvdl if (buf->c_magic == NFS_MAGIC) {
1241 1.48 fvdl buf->c_tapea = buf->c_old_tapea;
1242 1.48 fvdl buf->c_firstrec = buf->c_old_firstrec;
1243 1.48 fvdl buf->c_date = buf->c_old_date;
1244 1.48 fvdl buf->c_ddate = buf->c_old_ddate;
1245 1.48 fvdl buf->c_atime = buf->c_old_atime;
1246 1.48 fvdl buf->c_mtime = buf->c_old_mtime;
1247 1.48 fvdl buf->c_birthtime = 0;
1248 1.48 fvdl buf->c_birthtimensec = 0;
1249 1.48 fvdl buf->c_atimensec = buf->c_mtimensec = 0;
1250 1.48 fvdl }
1251 1.48 fvdl
1252 1.10 cgd case TS_ADDR:
1253 1.10 cgd break;
1254 1.10 cgd
1255 1.10 cgd default:
1256 1.10 cgd panic("gethead: unknown inode type %d\n", buf->c_type);
1257 1.10 cgd break;
1258 1.10 cgd }
1259 1.48 fvdl
1260 1.48 fvdl buf->c_magic = FS_UFS2_MAGIC;
1261 1.48 fvdl
1262 1.10 cgd /*
1263 1.10 cgd * If we are restoring a filesystem with old format inodes,
1264 1.10 cgd * copy the uid/gid to the new location.
1265 1.10 cgd */
1266 1.10 cgd if (oldinofmt) {
1267 1.48 fvdl buf->c_uid = buf->c_spare1[1];
1268 1.48 fvdl buf->c_gid = buf->c_spare1[2];
1269 1.10 cgd }
1270 1.10 cgd if (dflag)
1271 1.10 cgd accthdr(buf);
1272 1.10 cgd return(GOOD);
1273 1.10 cgd }
1274 1.10 cgd
1275 1.10 cgd /*
1276 1.10 cgd * Check that a header is where it belongs and predict the next header
1277 1.10 cgd */
1278 1.10 cgd static void
1279 1.52 xtraeme accthdr(struct s_spcl *header)
1280 1.10 cgd {
1281 1.10 cgd static ino_t previno = 0x7fffffff;
1282 1.10 cgd static int prevtype;
1283 1.10 cgd static long predict;
1284 1.10 cgd long blks, i;
1285 1.10 cgd
1286 1.10 cgd if (header->c_type == TS_TAPE) {
1287 1.10 cgd fprintf(stderr, "Volume header (%s inode format) ",
1288 1.10 cgd oldinofmt ? "old" : "new");
1289 1.10 cgd if (header->c_firstrec)
1290 1.48 fvdl fprintf(stderr, "begins with record %lld",
1291 1.48 fvdl (long long)header->c_firstrec);
1292 1.10 cgd fprintf(stderr, "\n");
1293 1.10 cgd previno = 0x7fffffff;
1294 1.10 cgd return;
1295 1.10 cgd }
1296 1.10 cgd if (previno == 0x7fffffff)
1297 1.10 cgd goto newcalc;
1298 1.10 cgd switch (prevtype) {
1299 1.10 cgd case TS_BITS:
1300 1.14 mycroft fprintf(stderr, "Dumped inodes map header");
1301 1.10 cgd break;
1302 1.10 cgd case TS_CLRI:
1303 1.14 mycroft fprintf(stderr, "Used inodes map header");
1304 1.10 cgd break;
1305 1.10 cgd case TS_INODE:
1306 1.54 christos fprintf(stderr, "File header, ino %llu",
1307 1.54 christos (unsigned long long)previno);
1308 1.10 cgd break;
1309 1.10 cgd case TS_ADDR:
1310 1.54 christos fprintf(stderr, "File continuation header, ino %llu",
1311 1.54 christos (unsigned long long)previno);
1312 1.10 cgd break;
1313 1.10 cgd case TS_END:
1314 1.10 cgd fprintf(stderr, "End of tape header");
1315 1.10 cgd break;
1316 1.10 cgd }
1317 1.10 cgd if (predict != blksread - 1)
1318 1.28 lukem fprintf(stderr, "; predicted %ld blocks, got %ld blocks",
1319 1.28 lukem (long)predict, (long)(blksread - 1));
1320 1.10 cgd fprintf(stderr, "\n");
1321 1.10 cgd newcalc:
1322 1.10 cgd blks = 0;
1323 1.40 enami switch (header->c_type) {
1324 1.40 enami case TS_END:
1325 1.40 enami break;
1326 1.40 enami case TS_CLRI:
1327 1.40 enami case TS_BITS:
1328 1.40 enami blks = header->c_count;
1329 1.40 enami break;
1330 1.40 enami default:
1331 1.10 cgd for (i = 0; i < header->c_count; i++)
1332 1.10 cgd if (header->c_addr[i] != 0)
1333 1.10 cgd blks++;
1334 1.40 enami break;
1335 1.40 enami }
1336 1.10 cgd predict = blks;
1337 1.10 cgd blksread = 0;
1338 1.10 cgd prevtype = header->c_type;
1339 1.10 cgd previno = header->c_inumber;
1340 1.10 cgd }
1341 1.10 cgd
1342 1.10 cgd /*
1343 1.10 cgd * Find an inode header.
1344 1.10 cgd * Complain if had to skip, and complain is set.
1345 1.10 cgd */
1346 1.10 cgd static void
1347 1.52 xtraeme findinode(struct s_spcl *header)
1348 1.10 cgd {
1349 1.10 cgd static long skipcnt = 0;
1350 1.10 cgd long i;
1351 1.10 cgd char buf[TP_BSIZE];
1352 1.10 cgd
1353 1.10 cgd curfile.name = "<name unknown>";
1354 1.10 cgd curfile.action = UNKNOWN;
1355 1.48 fvdl curfile.mode = 0;
1356 1.10 cgd curfile.ino = 0;
1357 1.45 perseant top:
1358 1.10 cgd do {
1359 1.48 fvdl if (header->c_magic != FS_UFS2_MAGIC) {
1360 1.10 cgd skipcnt++;
1361 1.10 cgd while (gethead(header) == FAIL ||
1362 1.10 cgd header->c_date != dumpdate)
1363 1.10 cgd skipcnt++;
1364 1.10 cgd }
1365 1.10 cgd switch (header->c_type) {
1366 1.10 cgd
1367 1.10 cgd case TS_ADDR:
1368 1.10 cgd /*
1369 1.10 cgd * Skip up to the beginning of the next record
1370 1.10 cgd */
1371 1.10 cgd for (i = 0; i < header->c_count; i++)
1372 1.10 cgd if (header->c_addr[i])
1373 1.10 cgd readtape(buf);
1374 1.10 cgd while (gethead(header) == FAIL ||
1375 1.10 cgd header->c_date != dumpdate)
1376 1.10 cgd skipcnt++;
1377 1.45 perseant /* We've read a header; don't drop it. */
1378 1.45 perseant goto top;
1379 1.10 cgd
1380 1.10 cgd case TS_INODE:
1381 1.48 fvdl curfile.mode = header->c_mode;
1382 1.48 fvdl curfile.uid = header->c_uid;
1383 1.48 fvdl curfile.gid = header->c_gid;
1384 1.48 fvdl curfile.file_flags = header->c_file_flags;
1385 1.48 fvdl curfile.rdev = header->c_rdev;
1386 1.48 fvdl curfile.atime_sec = header->c_atime;
1387 1.48 fvdl curfile.atime_nsec = header->c_atimensec;
1388 1.48 fvdl curfile.mtime_sec = header->c_mtime;
1389 1.48 fvdl curfile.mtime_nsec = header->c_mtimensec;
1390 1.48 fvdl curfile.birthtime_sec = header->c_birthtime;
1391 1.48 fvdl curfile.birthtime_nsec = header->c_birthtimensec;
1392 1.48 fvdl curfile.size = header->c_size;
1393 1.10 cgd curfile.ino = header->c_inumber;
1394 1.10 cgd break;
1395 1.10 cgd
1396 1.10 cgd case TS_END:
1397 1.10 cgd curfile.ino = maxino;
1398 1.10 cgd break;
1399 1.10 cgd
1400 1.10 cgd case TS_CLRI:
1401 1.10 cgd curfile.name = "<file removal list>";
1402 1.10 cgd break;
1403 1.10 cgd
1404 1.10 cgd case TS_BITS:
1405 1.10 cgd curfile.name = "<file dump list>";
1406 1.10 cgd break;
1407 1.10 cgd
1408 1.10 cgd case TS_TAPE:
1409 1.10 cgd panic("unexpected tape header\n");
1410 1.43 enami break;
1411 1.10 cgd
1412 1.10 cgd default:
1413 1.10 cgd panic("unknown tape header type %d\n", spcl.c_type);
1414 1.43 enami break;
1415 1.10 cgd
1416 1.10 cgd }
1417 1.10 cgd } while (header->c_type == TS_ADDR);
1418 1.10 cgd if (skipcnt > 0)
1419 1.28 lukem fprintf(stderr, "resync restore, skipped %ld blocks\n",
1420 1.28 lukem (long)skipcnt);
1421 1.10 cgd skipcnt = 0;
1422 1.10 cgd }
1423 1.10 cgd
1424 1.10 cgd static int
1425 1.52 xtraeme checksum(int *buf)
1426 1.10 cgd {
1427 1.25 lukem int i, j;
1428 1.10 cgd
1429 1.10 cgd j = sizeof(union u_spcl) / sizeof(int);
1430 1.10 cgd i = 0;
1431 1.10 cgd if(!Bcvt) {
1432 1.10 cgd do
1433 1.10 cgd i += *buf++;
1434 1.10 cgd while (--j);
1435 1.10 cgd } else {
1436 1.10 cgd do
1437 1.48 fvdl i += bswap32(*buf++);
1438 1.10 cgd while (--j);
1439 1.10 cgd }
1440 1.10 cgd
1441 1.10 cgd if (i != CHECKSUM) {
1442 1.54 christos fprintf(stderr, "Checksum error %o, inode %llu file %s\n", i,
1443 1.54 christos (unsigned long long)curfile.ino, curfile.name);
1444 1.10 cgd return(FAIL);
1445 1.10 cgd }
1446 1.10 cgd return(GOOD);
1447 1.10 cgd }
1448 1.10 cgd
1449 1.10 cgd #ifdef RRESTORE
1450 1.10 cgd #include <stdarg.h>
1451 1.10 cgd
1452 1.10 cgd void
1453 1.10 cgd msg(const char *fmt, ...)
1454 1.10 cgd {
1455 1.10 cgd va_list ap;
1456 1.46 wiz
1457 1.10 cgd va_start(ap, fmt);
1458 1.10 cgd (void)vfprintf(stderr, fmt, ap);
1459 1.10 cgd va_end(ap);
1460 1.10 cgd }
1461 1.10 cgd #endif /* RRESTORE */
1462 1.10 cgd
1463 1.48 fvdl static void
1464 1.48 fvdl swap_header(struct s_spcl *s)
1465 1.10 cgd {
1466 1.48 fvdl s->c_type = bswap32(s->c_type);
1467 1.48 fvdl s->c_old_date = bswap32(s->c_old_date);
1468 1.48 fvdl s->c_old_ddate = bswap32(s->c_old_ddate);
1469 1.48 fvdl s->c_volume = bswap32(s->c_volume);
1470 1.48 fvdl s->c_old_tapea = bswap32(s->c_old_tapea);
1471 1.48 fvdl s->c_inumber = bswap32(s->c_inumber);
1472 1.48 fvdl s->c_magic = bswap32(s->c_magic);
1473 1.48 fvdl s->c_checksum = bswap32(s->c_checksum);
1474 1.48 fvdl
1475 1.48 fvdl s->c_mode = bswap16(s->c_mode);
1476 1.48 fvdl s->c_size = bswap64(s->c_size);
1477 1.48 fvdl s->c_old_atime = bswap32(s->c_old_atime);
1478 1.48 fvdl s->c_atimensec = bswap32(s->c_atimensec);
1479 1.48 fvdl s->c_old_mtime = bswap32(s->c_old_mtime);
1480 1.48 fvdl s->c_mtimensec = bswap32(s->c_mtimensec);
1481 1.48 fvdl s->c_rdev = bswap32(s->c_rdev);
1482 1.48 fvdl s->c_birthtimensec = bswap32(s->c_birthtimensec);
1483 1.48 fvdl s->c_birthtime = bswap64(s->c_birthtime);
1484 1.48 fvdl s->c_atime = bswap64(s->c_atime);
1485 1.48 fvdl s->c_mtime = bswap64(s->c_mtime);
1486 1.48 fvdl s->c_file_flags = bswap32(s->c_file_flags);
1487 1.48 fvdl s->c_uid = bswap32(s->c_uid);
1488 1.48 fvdl s->c_gid = bswap32(s->c_gid);
1489 1.48 fvdl
1490 1.48 fvdl s->c_count = bswap32(s->c_count);
1491 1.48 fvdl s->c_level = bswap32(s->c_level);
1492 1.48 fvdl s->c_flags = bswap32(s->c_flags);
1493 1.48 fvdl s->c_old_firstrec = bswap32(s->c_old_firstrec);
1494 1.48 fvdl
1495 1.48 fvdl s->c_date = bswap64(s->c_date);
1496 1.48 fvdl s->c_ddate = bswap64(s->c_ddate);
1497 1.48 fvdl s->c_tapea = bswap64(s->c_tapea);
1498 1.48 fvdl s->c_firstrec = bswap64(s->c_firstrec);
1499 1.10 cgd
1500 1.48 fvdl /*
1501 1.48 fvdl * These are ouid and ogid.
1502 1.48 fvdl */
1503 1.48 fvdl s->c_spare1[1] = bswap16(s->c_spare1[1]);
1504 1.48 fvdl s->c_spare1[2] = bswap16(s->c_spare1[2]);
1505 1.10 cgd }
1506 1.10 cgd
1507 1.48 fvdl static void
1508 1.48 fvdl swap_old_header(struct s_ospcl *os)
1509 1.10 cgd {
1510 1.48 fvdl os->c_type = bswap32(os->c_type);
1511 1.48 fvdl os->c_date = bswap32(os->c_date);
1512 1.48 fvdl os->c_ddate = bswap32(os->c_ddate);
1513 1.48 fvdl os->c_volume = bswap32(os->c_volume);
1514 1.48 fvdl os->c_tapea = bswap32(os->c_tapea);
1515 1.48 fvdl os->c_inumber = bswap16(os->c_inumber);
1516 1.48 fvdl os->c_magic = bswap32(os->c_magic);
1517 1.48 fvdl os->c_checksum = bswap32(os->c_checksum);
1518 1.48 fvdl
1519 1.48 fvdl os->c_odinode.odi_mode = bswap16(os->c_odinode.odi_mode);
1520 1.48 fvdl os->c_odinode.odi_nlink = bswap16(os->c_odinode.odi_nlink);
1521 1.48 fvdl os->c_odinode.odi_uid = bswap16(os->c_odinode.odi_uid);
1522 1.48 fvdl os->c_odinode.odi_gid = bswap16(os->c_odinode.odi_gid);
1523 1.48 fvdl
1524 1.48 fvdl os->c_odinode.odi_size = bswap32(os->c_odinode.odi_size);
1525 1.48 fvdl os->c_odinode.odi_rdev = bswap32(os->c_odinode.odi_rdev);
1526 1.48 fvdl os->c_odinode.odi_atime = bswap32(os->c_odinode.odi_atime);
1527 1.48 fvdl os->c_odinode.odi_mtime = bswap32(os->c_odinode.odi_mtime);
1528 1.48 fvdl os->c_odinode.odi_ctime = bswap32(os->c_odinode.odi_ctime);
1529 1.10 cgd
1530 1.48 fvdl os->c_count = bswap32(os->c_count);
1531 1.10 cgd }
1532