2 * The new sysinstall program.
4 * This is probably the last attempt in the `sysinstall' line, the next
5 * generation being slated to essentially a complete rewrite.
7 * $Id: floppy.c,v 1.32 1999/02/15 00:49:33 jkh Exp $
10 * Jordan Hubbard. All rights reserved.
12 * Gary J Palmer. All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
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
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.
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
39 /* These routines deal with getting things off of floppy media */
41 #include "sysinstall.h"
42 #include <sys/fcntl.h>
44 #include <sys/errno.h>
45 #include <sys/param.h>
51 #include <sys/mount.h>
52 #include <msdosfs/msdosfsmount.h>
55 #include <ufs/ufs/ufsmount.h>
56 static Boolean floppyMounted;
59 static char mountpoint[] = "/dist";
62 mediaInitFloppy(Device *dev)
64 struct msdosfs_args dosargs;
65 struct ufs_args u_args;
71 mp = dev->private ? (char *)dev->private : mountpoint;
73 msgConfirm("Unable to make %s directory mountpoint for %s!", mp, dev->devname);
77 msgDebug("Init floppy called for %s distribution.\n", distWanted ? distWanted : "some");
79 if (!variable_get(VAR_NONINTERACTIVE)) {
81 msgConfirm("Please insert floppy in %s", dev->description);
83 msgConfirm("Please insert floppy containing %s in %s",
84 distWanted, dev->description);
87 memset(&dosargs, 0, sizeof dosargs);
88 dosargs.fspec = dev->devname;
89 dosargs.uid = dosargs.gid = 0;
92 memset(&u_args, 0, sizeof(u_args));
93 u_args.fspec = dev->devname;
95 if (mount("msdos", mp, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
96 if (mount("ufs", mp, MNT_RDONLY, (caddr_t)&u_args) == -1) {
97 msgConfirm("Error mounting floppy %s (%s) on %s : %s",
98 dev->name, dev->devname, mp, strerror(errno));
102 floppyMounted = TRUE;
108 mediaGetFloppy(Device *dev, char *file, Boolean probe)
110 char buf[PATH_MAX], *mp;
115 * floppies don't use mediaGenericGet() because it's too expensive
116 * to speculatively open files on a floppy disk. Make user get it
117 * right or give up with floppies.
119 mp = dev->private ? (char *)dev->private : mountpoint;
120 snprintf(buf, PATH_MAX, "%s/%s", mp, file);
121 if (!file_readable(buf)) {
125 while (!file_readable(buf)) {
127 msgConfirm("GetFloppy: Failed to get %s after retries;\ngiving up.", buf);
131 mediaShutdownFloppy(dev);
132 if (!mediaInitFloppy(dev))
137 fp = fopen(buf, "r");
142 mediaShutdownFloppy(Device *dev)
145 char *mp = dev->private ? (char *)dev->private : mountpoint;
147 if (unmount(mp, MNT_FORCE) != 0)
148 msgDebug("Umount of floppy on %s failed: %s (%d)\n", mp, strerror(errno), errno);
150 floppyMounted = FALSE;
151 if (!variable_get(VAR_NONINTERACTIVE) && variable_cmp(SYSTEM_STATE, "fixit"))
152 msgConfirm("You may remove the floppy from %s", dev->description);