]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/sysinstall/tape.c
MFS: tweak my wording a little.
[FreeBSD/FreeBSD.git] / release / sysinstall / tape.c
1 /*
2  * The new sysinstall program.
3  *
4  * This is probably the last attempt in the `sysinstall' line, the next
5  * generation being slated to essentially a complete rewrite.
6  *
7  * $FreeBSD$
8  *
9  * Copyright (c) 1995
10  *      Jordan Hubbard.  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer,
17  *    verbatim and that no modifications are made prior to this
18  *    point in the file.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36
37 /* These routines deal with getting things off of tape media */
38
39 #include "sysinstall.h"
40 #include <sys/fcntl.h>
41 #include <sys/param.h>
42
43 static Boolean tapeInitted;
44
45 char *
46 mediaTapeBlocksize(void)
47 {
48     char *cp = variable_get(VAR_TAPE_BLOCKSIZE);
49
50     return cp ? cp : DEFAULT_TAPE_BLOCKSIZE;
51 }
52
53 Boolean
54 mediaInitTape(Device *dev)
55 {
56     /* This is REALLY gross, but we need to do the init later in get due to the fact
57      * that media is initialized BEFORE a filesystem is mounted now.
58      */
59     return TRUE;
60 }
61
62 FILE *
63 mediaGetTape(Device *dev, char *file, Boolean probe)
64 {
65     char buf[PATH_MAX];
66     FILE *fp;
67
68     int i;
69
70     if (!tapeInitted) {
71         msgDebug("Tape init routine called for %s (private dir is %s)\n", dev->name, dev->private);
72         Mkdir(dev->private);
73         if (chdir(dev->private)) {
74             msgConfirm("Unable to CD to %s before extracting tape!\n"
75                        "Tape media is not selected and thus cannot be installed from.", dev->private);
76             return (FILE *)IO_ERROR;
77         }
78         /* We know the tape is already in the drive, so go for it */
79         msgNotify("First extracting distributions from %s...", dev->description);
80         if (!strcmp(dev->name, "rft0"))
81             i = vsystem("ft | cpio -idum %s --block-size %s", cpioVerbosity(), mediaTapeBlocksize());
82         else
83             i = vsystem("cpio -idum %s --block-size %s -I %s", cpioVerbosity(), mediaTapeBlocksize(), dev->devname);
84         if (!i) {
85             tapeInitted = TRUE;
86             msgDebug("Tape initialized successfully.\n");
87         }
88         else {
89             msgConfirm("Tape extract command failed with status %d!\n"
90                        "Unable to use tape media.", i);
91             return (FILE *)IO_ERROR;
92         }
93     }
94
95     sprintf(buf, "%s/%s", (char *)dev->private, file);
96     if (isDebug())
97         msgDebug("Request for %s from tape (looking in %s)\n", file, buf);
98     if (file_readable(buf))
99         fp = fopen(buf, "r");
100     else {
101         sprintf(buf, "%s/releases/%s", (char *)dev->private, file);
102         fp = fopen(buf, "r");
103     }
104     /* Nuke the files behind us to save space */
105     if (fp)
106         unlink(buf);
107     return fp;
108 }
109
110 void
111 mediaShutdownTape(Device *dev)
112 {
113     if (!tapeInitted)
114         return;
115     if (file_readable((char *)dev->private)) {
116         msgNotify("Cleaning up results of tape extract in %s..",
117                   (char *)dev->private);
118         (void)vsystem("rm -rf %s", (char *)dev->private);
119     }
120     tapeInitted = FALSE;
121 }