Deleted Added
sdiff udiff text old ( 128073 ) new ( 128175 )
full compact
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 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;
68static int pipecmdin = 0;
69static FILE *popenfp = NULL;
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
114setinput(char *source, int ispipecommand)
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
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
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 }
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
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
527 if (!pipecmdin && ioctl(mt, MTIOCTOP, (char *)&tcom) < 0)
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
1020#ifdef RRESTORE
1021 if (host)
1022 rmtclose();
1023 else
1024#endif
1025 (void) close(mt);
1026}
1027

--- 361 unchanged lines hidden ---