18791Sjkh/* 28791Sjkh * The new sysinstall program. 38791Sjkh * 48791Sjkh * This is probably the last attempt in the `sysinstall' line, the next 58791Sjkh * generation being slated to essentially a complete rewrite. 68791Sjkh * 750479Speter * $FreeBSD$ 88791Sjkh * 98791Sjkh * Copyright (c) 1995 108791Sjkh * Jordan Hubbard. All rights reserved. 118791Sjkh * Copyright (c) 1995 128791Sjkh * Gary J Palmer. All rights reserved. 138791Sjkh * 148791Sjkh * Redistribution and use in source and binary forms, with or without 158791Sjkh * modification, are permitted provided that the following conditions 168791Sjkh * are met: 178791Sjkh * 1. Redistributions of source code must retain the above copyright 188881Srgrimes * notice, this list of conditions and the following disclaimer, 198881Srgrimes * verbatim and that no modifications are made prior to this 208791Sjkh * point in the file. 218791Sjkh * 2. Redistributions in binary form must reproduce the above copyright 228791Sjkh * notice, this list of conditions and the following disclaimer in the 238791Sjkh * documentation and/or other materials provided with the distribution. 248791Sjkh * 258791Sjkh * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 268791Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 278791Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 288791Sjkh * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 298791Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 308791Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 318791Sjkh * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 328791Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 338791Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 348791Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 358791Sjkh * SUCH DAMAGE. 368791Sjkh * 378791Sjkh */ 388791Sjkh 398803Sjkh/* These routines deal with getting things off of floppy media */ 408791Sjkh 418791Sjkh#include "sysinstall.h" 428791Sjkh#include <sys/fcntl.h> 438791Sjkh#include <sys/stat.h> 448791Sjkh#include <sys/errno.h> 458791Sjkh#include <sys/param.h> 468791Sjkh#include <sys/wait.h> 478791Sjkh#include <unistd.h> 488791Sjkh#include <grp.h> 498791Sjkh 508791Sjkh#define MSDOSFS 518791Sjkh#include <sys/mount.h> 5277162Sru#include <fs/msdosfs/msdosfsmount.h> 538791Sjkh#undef MSDOSFS 548791Sjkh 5524597Sjkh#include <ufs/ufs/ufsmount.h> 568791Sjkhstatic Boolean floppyMounted; 578791Sjkh 5818310Sjkhchar *distWanted; 5942005Sjkhstatic char mountpoint[] = "/dist"; 609202Srgrimes 618791SjkhBoolean 628791SjkhmediaInitFloppy(Device *dev) 638791Sjkh{ 648791Sjkh struct msdosfs_args dosargs; 6512661Speter struct ufs_args u_args; 6644029Sjkh char *mp; 678791Sjkh 688791Sjkh if (floppyMounted) 698791Sjkh return TRUE; 708791Sjkh 7144029Sjkh mp = dev->private ? (char *)dev->private : mountpoint; 7244029Sjkh if (Mkdir(mp)) { 7344029Sjkh msgConfirm("Unable to make %s directory mountpoint for %s!", mp, dev->devname); 748791Sjkh return FALSE; 758791Sjkh } 7621937Sjkh 7712661Speter msgDebug("Init floppy called for %s distribution.\n", distWanted ? distWanted : "some"); 7812661Speter 7937735Sjkh if (!variable_get(VAR_NONINTERACTIVE)) { 8037735Sjkh if (!distWanted) 8137735Sjkh msgConfirm("Please insert floppy in %s", dev->description); 8237735Sjkh else 8337735Sjkh msgConfirm("Please insert floppy containing %s in %s", 8437735Sjkh distWanted, dev->description); 8537735Sjkh } 8637735Sjkh 879202Srgrimes memset(&dosargs, 0, sizeof dosargs); 888791Sjkh dosargs.fspec = dev->devname; 899202Srgrimes dosargs.uid = dosargs.gid = 0; 909202Srgrimes dosargs.mask = 0777; 9112661Speter 9212661Speter memset(&u_args, 0, sizeof(u_args)); 9312661Speter u_args.fspec = dev->devname; 9412661Speter 9577580Sru if (mount("msdosfs", mp, MNT_RDONLY, (caddr_t)&dosargs) != -1) 9661277Snyan goto success; 9761277Snyan if (mount("ufs", mp, MNT_RDONLY, (caddr_t)&u_args) != -1) 9861277Snyan goto success; 9961277Snyan 10061277Snyan msgConfirm("Error mounting floppy %s (%s) on %s : %s", 10161277Snyan dev->name, dev->devname, mp, strerror(errno)); 10261277Snyan return FALSE; 10361277Snyan 10461277Snyansuccess: 1058791Sjkh floppyMounted = TRUE; 10612661Speter distWanted = NULL; 1078791Sjkh return TRUE; 1088791Sjkh} 1098791Sjkh 11020315SjkhFILE * 11114321SjkhmediaGetFloppy(Device *dev, char *file, Boolean probe) 1128791Sjkh{ 11344029Sjkh char buf[PATH_MAX], *mp; 11420315Sjkh FILE *fp; 11520315Sjkh int nretries = 5; 1168791Sjkh 11742005Sjkh /* 11842005Sjkh * floppies don't use mediaGenericGet() because it's too expensive 11942005Sjkh * to speculatively open files on a floppy disk. Make user get it 12042005Sjkh * right or give up with floppies. 12142005Sjkh */ 12244029Sjkh mp = dev->private ? (char *)dev->private : mountpoint; 12344029Sjkh snprintf(buf, PATH_MAX, "%s/%s", mp, file); 12412661Speter if (!file_readable(buf)) { 12514321Sjkh if (probe) 12620315Sjkh return NULL; 1279202Srgrimes else { 12812661Speter while (!file_readable(buf)) { 1299202Srgrimes if (!--nretries) { 13012661Speter msgConfirm("GetFloppy: Failed to get %s after retries;\ngiving up.", buf); 13120315Sjkh return NULL; 1329202Srgrimes } 1339202Srgrimes distWanted = buf; 13412661Speter mediaShutdownFloppy(dev); 13512661Speter if (!mediaInitFloppy(dev)) 13620315Sjkh return NULL; 1379202Srgrimes } 1389202Srgrimes } 1399202Srgrimes } 14020315Sjkh fp = fopen(buf, "r"); 14120315Sjkh return fp; 1428791Sjkh} 1438791Sjkh 1448791Sjkhvoid 1458791SjkhmediaShutdownFloppy(Device *dev) 1468791Sjkh{ 1478791Sjkh if (floppyMounted) { 14844029Sjkh char *mp = dev->private ? (char *)dev->private : mountpoint; 14944029Sjkh 15044029Sjkh if (unmount(mp, MNT_FORCE) != 0) 15144029Sjkh msgDebug("Umount of floppy on %s failed: %s (%d)\n", mp, strerror(errno), errno); 1528803Sjkh else { 1538791Sjkh floppyMounted = FALSE; 15445055Sjkh if (!variable_get(VAR_NONINTERACTIVE) && variable_cmp(SYSTEM_STATE, "fixit")) 15542005Sjkh msgConfirm("You may remove the floppy from %s", dev->description); 1568803Sjkh } 1578791Sjkh } 1588791Sjkh} 159