]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/sysinstall/cdrom.c
This commit was generated by cvs2svn to compensate for changes in r53469,
[FreeBSD/FreeBSD.git] / release / sysinstall / cdrom.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  * Copyright (c) 1995
12  *      Gary J Palmer. All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer,
19  *    verbatim and that no modifications are made prior to this
20  *    point in the file.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  */
38
39 /* These routines deal with getting things off of CDROM media */
40
41 #include "sysinstall.h"
42 #include <sys/stat.h>
43 #include <sys/errno.h>
44 #include <sys/param.h>
45 #include <sys/wait.h>
46 #include <unistd.h>
47 #include <grp.h>
48 #include <fcntl.h>
49 #include <libutil.h>
50
51 #define CD9660
52 #include <sys/mount.h>
53 #include <isofs/cd9660/cd9660_mount.h>
54 #undef CD9660
55
56 static Boolean cdromMounted;
57 static char mountpoint[] = "/dist";
58
59 static properties
60 read_props(char *name)
61 {
62         int fd;
63         properties n;
64
65         fd = open(name, O_RDONLY);
66         if (fd == -1)
67             return NULL;
68         n = properties_read(fd);
69         close(fd);
70         return n;
71 }
72
73 Boolean
74 mediaInitCDROM(Device *dev)
75 {
76     struct iso_args     args;
77     properties cd_attr = NULL;
78     char *cp = NULL;
79     Boolean readInfo = TRUE;
80     static Boolean bogusCDOK = FALSE;
81
82     if (cdromMounted)
83         return TRUE;
84
85     Mkdir(mountpoint);
86     bzero(&args, sizeof(args));
87     args.fspec = dev->devname;
88     args.flags = 0;
89     if (mount("cd9660", mountpoint, MNT_RDONLY, (caddr_t) &args) == -1) {
90         if (errno == EINVAL) {
91             msgConfirm("The CD in your drive looks more like an Audio CD than a FreeBSD release.");
92             return FALSE;
93         }
94         else if (errno != EBUSY) {
95             msgConfirm("Error mounting %s on %s: %s (%u)", dev->devname, mountpoint, strerror(errno), errno);
96             return FALSE;
97         }
98     }
99     cdromMounted = TRUE;
100
101     if (!file_readable(string_concat(mountpoint, "/cdrom.inf")) && !bogusCDOK) {
102         if (msgYesNo("Warning: The CD currently in the drive is either not a FreeBSD\n"
103                      "CD or it is an older (pre 2.1.5) FreeBSD CD which does not\n"
104                      "have a version number on it.  Do you wish to use this CD anyway?") != 0) {
105             unmount(mountpoint, MNT_FORCE);
106             cdromMounted = FALSE;
107             return FALSE;
108         }
109         else {
110             readInfo = FALSE;
111             bogusCDOK = TRUE;
112         }
113     }
114
115     if (readInfo) {
116         if (!(cd_attr = read_props(string_concat(mountpoint, "/cdrom.inf")))
117             || !(cp = property_find(cd_attr, "CD_VERSION"))) {
118             msgConfirm("Unable to find a %s/cdrom.inf file.\n"
119                        "Either this is not a FreeBSD CDROM, there is a problem with\n"
120                        "the CDROM driver or something is wrong with your hardware.\n"
121                        "Please fix this problem (check the console logs on VTY2) and\n"
122                        "try again.", mountpoint);
123         }
124         else {
125             if (variable_cmp(VAR_RELNAME, cp)
126                 && variable_cmp(VAR_RELNAME, "none")
127                 && variable_cmp(VAR_RELNAME, "any") && !bogusCDOK) {
128                 msgConfirm("Warning: The version of the FreeBSD CD currently in the drive\n"
129                            "(%s) does not match the version of the boot floppy\n"
130                            "(%s).\n\n"
131                            "If this is intentional, to avoid this message in the future\n"
132                            "please visit the Options editor to set the boot floppy version\n"
133                            "string to match that of the CD before selecting it as your\n"
134                            "installation media.", cp, variable_get(VAR_RELNAME));
135
136                 if (msgYesNo("Would you like to try and use this CDROM anyway?") != 0) {
137                     unmount(mountpoint, MNT_FORCE);
138                     cdromMounted = FALSE;
139                     properties_free(cd_attr);
140                     return FALSE;
141                 }
142                 else
143                     bogusCDOK = TRUE;
144             }
145             if ((cp = property_find(cd_attr, "CD_MACHINE_ARCH")) != NULL) {
146 #ifdef __alpha__
147                 if (strcmp(cp, "alpha")) {
148 #else
149                 if (strcmp(cp, "x86")) {
150 #endif
151                     msgConfirm("Fatal: The FreeBSD install CD currently in the drive\n"
152                            "is for the %s architecture, not the machine you're using.\n\n"
153
154                            "Please use the correct installation CD for your machine type.", cp);
155
156                     unmount(mountpoint, MNT_FORCE);
157                     cdromMounted = FALSE;
158                     properties_free(cd_attr);
159                     return FALSE;
160                 }
161             }
162         }
163     }
164     if (cd_attr)
165         properties_free(cd_attr);
166     return TRUE;
167 }
168
169 FILE *
170 mediaGetCDROM(Device *dev, char *file, Boolean probe)
171 {
172     return mediaGenericGet(mountpoint, file);
173 }
174
175 void
176 mediaShutdownCDROM(Device *dev)
177 {
178     if (!cdromMounted)
179         return;
180
181     if (unmount(mountpoint, MNT_FORCE) != 0)
182         msgConfirm("Could not unmount the CDROM from %s: %s", mountpoint, strerror(errno));
183     else
184         cdromMounted = FALSE;
185 }