]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/sysinstall/tape.c
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / usr.sbin / 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         WINDOW *w = savescr();
72
73         msgDebug("Tape init routine called for %s (private dir is %s)\n", dev->name, dev->private);
74         Mkdir(dev->private);
75         if (chdir(dev->private)) {
76             msgConfirm("Unable to CD to %s before extracting tape!\n"
77                        "Tape media is not selected and thus cannot be installed from.", dev->private);
78             return (FILE *)IO_ERROR;
79         }
80         /* We know the tape is already in the drive, so go for it */
81         msgNotify("First extracting distributions from %s...", dev->description);
82         if (!strcmp(dev->name, "rft0"))
83             i = vsystem("ft | cpio -idum %s --block-size %s", cpioVerbosity(), mediaTapeBlocksize());
84         else
85             i = vsystem("cpio -idum %s --block-size %s -I %s", cpioVerbosity(), mediaTapeBlocksize(), dev->devname);
86         if (!i) {
87             tapeInitted = TRUE;
88             msgDebug("Tape initialized successfully.\n");
89         }
90         else {
91             msgConfirm("Tape extract command failed with status %d!\n"
92                        "Unable to use tape media.", i);
93             restorescr(w);
94             return (FILE *)IO_ERROR;
95         }
96         restorescr(w);
97     }
98
99     sprintf(buf, "%s/%s", (char *)dev->private, file);
100     if (isDebug())
101         msgDebug("Request for %s from tape (looking in %s)\n", file, buf);
102     if (file_readable(buf))
103         fp = fopen(buf, "r");
104     else {
105         sprintf(buf, "%s/releases/%s", (char *)dev->private, file);
106         fp = fopen(buf, "r");
107     }
108     /* Nuke the files behind us to save space */
109     if (fp)
110         unlink(buf);
111     return fp;
112 }
113
114 void
115 mediaShutdownTape(Device *dev)
116 {
117     if (!tapeInitted)
118         return;
119     if (file_readable((char *)dev->private)) {
120         msgDebug("Cleaning up results of tape extract in %s..",
121                   (char *)dev->private);
122         (void)vsystem("rm -rf %s", (char *)dev->private);
123     }
124     tapeInitted = FALSE;
125 }