tape.c (128073) | tape.c (128175) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 23 unchanged lines hidden (view full) --- 32 * SUCH DAMAGE. 33 */ 34 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95"; 38#endif 39static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 23 unchanged lines hidden (view full) --- 32 * SUCH DAMAGE. 33 */ 34 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95"; 38#endif 39static const char rcsid[] = |
40 "$FreeBSD: head/sbin/restore/tape.c 128073 2004-04-09 19:58:40Z markm $"; | 40 "$FreeBSD: head/sbin/restore/tape.c 128175 2004-04-13 02:58:06Z green $"; |
41#endif /* not lint */ 42 43#include <sys/param.h> 44#include <sys/file.h> 45#include <sys/mtio.h> 46#include <sys/stat.h> 47#include <sys/time.h> 48 --- 11 unchanged lines hidden (view full) --- 60#include <unistd.h> 61 62#include "restore.h" 63#include "extern.h" 64 65static long fssize = MAXBSIZE; 66static int mt = -1; 67static int pipein = 0; | 41#endif /* not lint */ 42 43#include <sys/param.h> 44#include <sys/file.h> 45#include <sys/mtio.h> 46#include <sys/stat.h> 47#include <sys/time.h> 48 --- 11 unchanged lines hidden (view full) --- 60#include <unistd.h> 61 62#include "restore.h" 63#include "extern.h" 64 65static long fssize = MAXBSIZE; 66static int mt = -1; 67static int pipein = 0; |
68static int pipecmdin = 0; 69static FILE *popenfp = NULL; |
|
68static char *magtape; 69static int blkcnt; 70static int numtrec; 71static char *tapebuf; 72static union u_spcl endoftapemark; 73static long blksread; /* blocks read since last header */ 74static int64_t tapeaddr = 0; /* current TP_BSIZE tape record */ 75static long tapesread; --- 28 unchanged lines hidden (view full) --- 104static void xtrmap(char *, long); 105static void xtrmapskip(char *, long); 106static void xtrskip(char *, long); 107 108/* 109 * Set up an input source 110 */ 111void | 70static char *magtape; 71static int blkcnt; 72static int numtrec; 73static char *tapebuf; 74static union u_spcl endoftapemark; 75static long blksread; /* blocks read since last header */ 76static int64_t tapeaddr = 0; /* current TP_BSIZE tape record */ 77static long tapesread; --- 28 unchanged lines hidden (view full) --- 106static void xtrmap(char *, long); 107static void xtrmapskip(char *, long); 108static void xtrskip(char *, long); 109 110/* 111 * Set up an input source 112 */ 113void |
112setinput(char *source) | 114setinput(char *source, int ispipecommand) |
113{ 114 FLUSHTAPEBUF(); 115 if (bflag) 116 newtapebuf(ntrec); 117 else 118 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC); 119 terminal = stdin; 120 | 115{ 116 FLUSHTAPEBUF(); 117 if (bflag) 118 newtapebuf(ntrec); 119 else 120 newtapebuf(NTREC > HIGHDENSITYTREC ? NTREC : HIGHDENSITYTREC); 121 terminal = stdin; 122 |
123 if (ispipecommand) 124 pipecmdin++; 125 else |
|
121#ifdef RRESTORE 122 if (strchr(source, ':')) { 123 host = source; 124 source = strchr(host, ':'); 125 *source++ = '\0'; 126 if (rmthost(host) == 0) 127 done(1); 128 } else --- 48 unchanged lines hidden (view full) --- 177 */ 178void 179setup(void) 180{ 181 int i, j, *ip; 182 struct stat stbuf; 183 184 vprintf(stdout, "Verify tape and initialize maps\n"); | 126#ifdef RRESTORE 127 if (strchr(source, ':')) { 128 host = source; 129 source = strchr(host, ':'); 130 *source++ = '\0'; 131 if (rmthost(host) == 0) 132 done(1); 133 } else --- 48 unchanged lines hidden (view full) --- 182 */ 183void 184setup(void) 185{ 186 int i, j, *ip; 187 struct stat stbuf; 188 189 vprintf(stdout, "Verify tape and initialize maps\n"); |
190 if (pipecmdin) { 191 if (setenv("RESTORE_VOLUME", "1", 1) == -1) { 192 fprintf(stderr, "Cannot set $RESTORE_VOLUME: %s\n", 193 strerror(errno)); 194 done(1); 195 } 196 popenfp = popen(magtape, "r"); 197 mt = popenfp ? fileno(popenfp) : -1; 198 } else |
|
185#ifdef RRESTORE 186 if (host) 187 mt = rmtopen(magtape, 0); 188 else 189#endif 190 if (pipein) 191 mt = 0; 192 else --- 106 unchanged lines hidden (view full) --- 299 if (nextvol != 1) { 300 panic("Changing volumes on pipe input?\n"); 301 /* Avoid looping if we couldn't ask the user. */ 302 if (yflag || ferror(terminal) || feof(terminal)) 303 done(1); 304 } 305 if (volno == 1) 306 return; | 199#ifdef RRESTORE 200 if (host) 201 mt = rmtopen(magtape, 0); 202 else 203#endif 204 if (pipein) 205 mt = 0; 206 else --- 106 unchanged lines hidden (view full) --- 313 if (nextvol != 1) { 314 panic("Changing volumes on pipe input?\n"); 315 /* Avoid looping if we couldn't ask the user. */ 316 if (yflag || ferror(terminal) || feof(terminal)) 317 done(1); 318 } 319 if (volno == 1) 320 return; |
321 if (pipecmdin) { 322 closemt(); 323 goto getpipecmdhdr; 324 } |
|
307 goto gethdr; 308 } 309again: 310 if (pipein) 311 done(1); /* pipes do not get a second chance */ 312 if (command == 'R' || command == 'r' || curfile.action != SKIP) 313 newvol = nextvol; 314 else --- 44 unchanged lines hidden (view full) --- 359 if (!strcmp(buf, "none\n")) { 360 terminateinput(); 361 return; 362 } 363 if (buf[0] != '\n') { 364 (void) strcpy(magtape, buf); 365 magtape[strlen(magtape) - 1] = '\0'; 366 } | 325 goto gethdr; 326 } 327again: 328 if (pipein) 329 done(1); /* pipes do not get a second chance */ 330 if (command == 'R' || command == 'r' || curfile.action != SKIP) 331 newvol = nextvol; 332 else --- 44 unchanged lines hidden (view full) --- 377 if (!strcmp(buf, "none\n")) { 378 terminateinput(); 379 return; 380 } 381 if (buf[0] != '\n') { 382 (void) strcpy(magtape, buf); 383 magtape[strlen(magtape) - 1] = '\0'; 384 } |
385 if (pipecmdin) { 386 char volno[sizeof("2147483647")]; 387 388getpipecmdhdr: 389 (void)sprintf(volno, "%d", newvol); 390 if (setenv("RESTORE_VOLUME", volno, 1) == -1) { 391 fprintf(stderr, "Cannot set $RESTORE_VOLUME: %s\n", 392 strerror(errno)); 393 done(1); 394 } 395 popenfp = popen(magtape, "r"); 396 mt = popenfp ? fileno(popenfp) : -1; 397 } else |
|
367#ifdef RRESTORE 368 if (host) 369 mt = rmtopen(magtape, 0); 370 else 371#endif 372 mt = open(magtape, O_RDONLY, 0); 373 374 if (mt == -1) { --- 113 unchanged lines hidden (view full) --- 488 } 489 tcom.mt_op = MTFSF; 490 tcom.mt_count = dumpnum - 1; 491#ifdef RRESTORE 492 if (host) 493 rmtioctl(MTFSF, dumpnum - 1); 494 else 495#endif | 398#ifdef RRESTORE 399 if (host) 400 mt = rmtopen(magtape, 0); 401 else 402#endif 403 mt = open(magtape, O_RDONLY, 0); 404 405 if (mt == -1) { --- 113 unchanged lines hidden (view full) --- 519 } 520 tcom.mt_op = MTFSF; 521 tcom.mt_count = dumpnum - 1; 522#ifdef RRESTORE 523 if (host) 524 rmtioctl(MTFSF, dumpnum - 1); 525 else 526#endif |
496 if (ioctl(mt, MTIOCTOP, (char *)&tcom) < 0) | 527 if (!pipecmdin && ioctl(mt, MTIOCTOP, (char *)&tcom) < 0) |
497 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno)); 498} 499 500void 501printdumpinfo(void) 502{ 503 time_t t; 504 t = _time64_to_time(spcl.c_date); --- 472 unchanged lines hidden (view full) --- 977} 978 979void 980closemt(void) 981{ 982 983 if (mt < 0) 984 return; | 528 fprintf(stderr, "ioctl MTFSF: %s\n", strerror(errno)); 529} 530 531void 532printdumpinfo(void) 533{ 534 time_t t; 535 t = _time64_to_time(spcl.c_date); --- 472 unchanged lines hidden (view full) --- 1008} 1009 1010void 1011closemt(void) 1012{ 1013 1014 if (mt < 0) 1015 return; |
1016 if (pipecmdin) { 1017 pclose(popenfp); 1018 popenfp = NULL; 1019 } else |
|
985#ifdef RRESTORE 986 if (host) 987 rmtclose(); 988 else 989#endif 990 (void) close(mt); 991} 992 --- 361 unchanged lines hidden --- | 1020#ifdef RRESTORE 1021 if (host) 1022 rmtclose(); 1023 else 1024#endif 1025 (void) close(mt); 1026} 1027 --- 361 unchanged lines hidden --- |