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