From 065f34b7e27271ecb4bc324a37c5a6ac91260c7d Mon Sep 17 00:00:00 2001
From: "Jordan K. Hubbard" <jkh@FreeBSD.org>
Date: Mon, 15 Feb 1999 00:49:33 +0000
Subject: [PATCH] Unbreak the fixit floppy. Clean up some of the media handling
 to use common routines.

---
 release/sysinstall/floppy.c   | 25 +++++++++++++++----------
 release/sysinstall/install.c  | 31 +++++++++++++------------------
 release/sysinstall/media.c    |  4 +++-
 release/sysinstall/system.c   |  6 +++---
 usr.sbin/sade/install.c       | 31 +++++++++++++------------------
 usr.sbin/sade/system.c        |  6 +++---
 usr.sbin/sysinstall/floppy.c  | 25 +++++++++++++++----------
 usr.sbin/sysinstall/install.c | 31 +++++++++++++------------------
 usr.sbin/sysinstall/media.c   |  4 +++-
 usr.sbin/sysinstall/system.c  |  6 +++---
 10 files changed, 84 insertions(+), 85 deletions(-)

diff --git a/release/sysinstall/floppy.c b/release/sysinstall/floppy.c
index 6c1ab402abe4..f3b210fa5db9 100644
--- a/release/sysinstall/floppy.c
+++ b/release/sysinstall/floppy.c
@@ -4,7 +4,7 @@
  * This is probably the last attempt in the `sysinstall' line, the next
  * generation being slated to essentially a complete rewrite.
  *
- * $Id: floppy.c,v 1.30 1998/10/12 23:45:06 jkh Exp $
+ * $Id: floppy.c,v 1.31 1998/12/22 12:31:24 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -63,12 +63,14 @@ mediaInitFloppy(Device *dev)
 {
     struct msdosfs_args dosargs;
     struct ufs_args u_args;
+    char *mp;
 
     if (floppyMounted)
 	return TRUE;
 
-    if (Mkdir(mountpoint)) {
-	msgConfirm("Unable to make %s directory mountpoint for %s!", mountpoint, dev->devname);
+    mp = dev->private ? (char *)dev->private : mountpoint;
+    if (Mkdir(mp)) {
+	msgConfirm("Unable to make %s directory mountpoint for %s!", mp, dev->devname);
 	return FALSE;
     }
 
@@ -90,10 +92,10 @@ mediaInitFloppy(Device *dev)
     memset(&u_args, 0, sizeof(u_args));
     u_args.fspec = dev->devname;
 
-    if (mount("msdos", mountpoint, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
-	if (mount("ufs", mountpoint, MNT_RDONLY, (caddr_t)&u_args) == -1) {
+    if (mount("msdos", mp, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
+	if (mount("ufs", mp, MNT_RDONLY, (caddr_t)&u_args) == -1) {
 	    msgConfirm("Error mounting floppy %s (%s) on %s : %s",
-		       dev->name, dev->devname, mountpoint, strerror(errno));
+		       dev->name, dev->devname, mp, strerror(errno));
 	    return FALSE;
 	}
     }
@@ -105,7 +107,7 @@ mediaInitFloppy(Device *dev)
 FILE *
 mediaGetFloppy(Device *dev, char *file, Boolean probe)
 {
-    char	buf[PATH_MAX];
+    char	buf[PATH_MAX], *mp;
     FILE	*fp;
     int		nretries = 5;
 
@@ -114,7 +116,8 @@ mediaGetFloppy(Device *dev, char *file, Boolean probe)
      * to speculatively open files on a floppy disk.  Make user get it
      * right or give up with floppies.
      */
-    snprintf(buf, PATH_MAX, "%s/%s", mountpoint, file);
+    mp = dev->private ? (char *)dev->private : mountpoint;
+    snprintf(buf, PATH_MAX, "%s/%s", mp, file);
     if (!file_readable(buf)) {
 	if (probe)
 	    return NULL;
@@ -139,8 +142,10 @@ void
 mediaShutdownFloppy(Device *dev)
 {
     if (floppyMounted) {
-	if (unmount(mountpoint, MNT_FORCE) != 0)
-	    msgDebug("Umount of floppy on %s failed: %s (%d)\n", mountpoint, strerror(errno), errno);
+    	char *mp = dev->private ? (char *)dev->private : mountpoint;
+
+	if (unmount(mp, MNT_FORCE) != 0)
+	    msgDebug("Umount of floppy on %s failed: %s (%d)\n", mp, strerror(errno), errno);
 	else {
 	    floppyMounted = FALSE;
 	    if (!variable_get(VAR_NONINTERACTIVE))
diff --git a/release/sysinstall/install.c b/release/sysinstall/install.c
index 63edd5cde2db..a01120cb7557 100644
--- a/release/sysinstall/install.c
+++ b/release/sysinstall/install.c
@@ -4,7 +4,7 @@
  * This is probably the last program in the `sysinstall' line - the next
  * generation being essentially a complete rewrite.
  *
- * $Id: install.c,v 1.227 1999/02/09 22:18:10 jkh Exp $
+ * $Id: install.c,v 1.228 1999/02/14 21:26:28 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -272,13 +272,10 @@ installFixitCDROM(dialogMenuItem *self)
     (void)rmdir("/mnt2");
 
     while (1) {
-	msgConfirm("Please insert the second FreeBSD CDROM and press return");
+	msgConfirm("Please insert a FreeBSD live filesystem CDROM and press return");
 	if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS || !mediaDevice || !mediaDevice->init(mediaDevice)) {
 	    /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */
-	    if (mediaDevice) {
-		mediaDevice->shutdown(mediaDevice);
-		mediaDevice = NULL;
-	    }
+	    mediaClose();
 	    if (msgYesNo("Unable to mount the CDROM - do you want to try again?") != 0)
 		return DITEM_FAILURE;
 	}
@@ -325,11 +322,9 @@ installFixitCDROM(dialogMenuItem *self)
 		       "Dynamic executables from the CDROM likely won't work.");
 	}
     }
-
     fixit_common();
-
-    mediaDevice->shutdown(mediaDevice);
-    msgConfirm("Please remove the FreeBSD CDROM now.");
+    mediaClose();
+    msgConfirm("Please remove the FreeBSD fixit CDROM now.");
     return DITEM_SUCCESS;
 }
 
@@ -337,15 +332,13 @@ int
 installFixitFloppy(dialogMenuItem *self)
 {
     struct ufs_args args;
+    extern char *distWanted;
 
     if (!RunningAsInit)
 	return DITEM_SUCCESS;
 
-    variable_set2(SYSTEM_STATE, "fixit", 0);
-    Mkdir("/mnt2");
-
     /* Try to open the floppy drive */
-    if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
+    if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) {
 	msgConfirm("Unable to set media device to floppy.");
 	mediaClose();
 	return DITEM_FAILURE;
@@ -353,10 +346,13 @@ installFixitFloppy(dialogMenuItem *self)
 
     memset(&args, 0, sizeof(args));
     args.fspec = mediaDevice->devname;
+    mediaDevice->private = "/mnt2";
+    distWanted = NULL;
+    Mkdir("/mnt2");
+
+    variable_set2(SYSTEM_STATE, "fixit", 0);
 
     while (1) {
-	msgConfirm("Please insert a writable fixit floppy and press return");
-	mediaDevice->private = "/mnt2";
 	if (!mediaDevice->init(mediaDevice)) {
 	    if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n"
 			 "or unclean filesystem.  Do you want to try again?"))
@@ -368,8 +364,7 @@ installFixitFloppy(dialogMenuItem *self)
     if (!directory_exists("/tmp"))
 	(void)symlink("/mnt2/tmp", "/tmp");
     fixit_common();
-    mediaDevice->shutdown(mediaDevice);
-    mediaDevice = NULL;
+    mediaClose();
     msgConfirm("Please remove the fixit floppy now.");
     return DITEM_SUCCESS;
 }
diff --git a/release/sysinstall/media.c b/release/sysinstall/media.c
index 61640e8a9f40..7384b41c9ec4 100644
--- a/release/sysinstall/media.c
+++ b/release/sysinstall/media.c
@@ -4,7 +4,7 @@
  * This is probably the last attempt in the `sysinstall' line, the next
  * generation being slated to essentially a complete rewrite.
  *
- * $Id: media.c,v 1.94 1998/12/22 12:31:25 jkh Exp $
+ * $Id: media.c,v 1.95 1999/02/05 22:15:50 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -204,6 +204,8 @@ mediaSetFloppy(dialogMenuItem *self)
     }
     else
 	mediaDevice = devs[0];
+    if (mediaDevice)
+	mediaDevice->private = NULL;
     return (mediaDevice ? DITEM_LEAVE_MENU : DITEM_FAILURE) | DITEM_RESTORE;
 }
 
diff --git a/release/sysinstall/system.c b/release/sysinstall/system.c
index ee0aba0a092b..f916555c8826 100644
--- a/release/sysinstall/system.c
+++ b/release/sysinstall/system.c
@@ -4,7 +4,7 @@
  * This is probably the last program in the `sysinstall' line - the next
  * generation being essentially a complete rewrite.
  *
- * $Id: system.c,v 1.89 1999/02/09 22:18:10 jkh Exp $
+ * $Id: system.c,v 1.90 1999/02/14 21:26:29 jkh Exp $
  *
  * Jordan Hubbard
  *
@@ -146,8 +146,8 @@ void
 systemShutdown(int status)
 {
     /* If some media is open, close it down */
-    if (status >=0 && mediaDevice)
-	mediaDevice->shutdown(mediaDevice);
+    if (status >=0)
+	mediaClose();
 
     /* write out any changes to rc.conf .. */
     configRC_conf();
diff --git a/usr.sbin/sade/install.c b/usr.sbin/sade/install.c
index 63edd5cde2db..a01120cb7557 100644
--- a/usr.sbin/sade/install.c
+++ b/usr.sbin/sade/install.c
@@ -4,7 +4,7 @@
  * This is probably the last program in the `sysinstall' line - the next
  * generation being essentially a complete rewrite.
  *
- * $Id: install.c,v 1.227 1999/02/09 22:18:10 jkh Exp $
+ * $Id: install.c,v 1.228 1999/02/14 21:26:28 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -272,13 +272,10 @@ installFixitCDROM(dialogMenuItem *self)
     (void)rmdir("/mnt2");
 
     while (1) {
-	msgConfirm("Please insert the second FreeBSD CDROM and press return");
+	msgConfirm("Please insert a FreeBSD live filesystem CDROM and press return");
 	if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS || !mediaDevice || !mediaDevice->init(mediaDevice)) {
 	    /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */
-	    if (mediaDevice) {
-		mediaDevice->shutdown(mediaDevice);
-		mediaDevice = NULL;
-	    }
+	    mediaClose();
 	    if (msgYesNo("Unable to mount the CDROM - do you want to try again?") != 0)
 		return DITEM_FAILURE;
 	}
@@ -325,11 +322,9 @@ installFixitCDROM(dialogMenuItem *self)
 		       "Dynamic executables from the CDROM likely won't work.");
 	}
     }
-
     fixit_common();
-
-    mediaDevice->shutdown(mediaDevice);
-    msgConfirm("Please remove the FreeBSD CDROM now.");
+    mediaClose();
+    msgConfirm("Please remove the FreeBSD fixit CDROM now.");
     return DITEM_SUCCESS;
 }
 
@@ -337,15 +332,13 @@ int
 installFixitFloppy(dialogMenuItem *self)
 {
     struct ufs_args args;
+    extern char *distWanted;
 
     if (!RunningAsInit)
 	return DITEM_SUCCESS;
 
-    variable_set2(SYSTEM_STATE, "fixit", 0);
-    Mkdir("/mnt2");
-
     /* Try to open the floppy drive */
-    if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
+    if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) {
 	msgConfirm("Unable to set media device to floppy.");
 	mediaClose();
 	return DITEM_FAILURE;
@@ -353,10 +346,13 @@ installFixitFloppy(dialogMenuItem *self)
 
     memset(&args, 0, sizeof(args));
     args.fspec = mediaDevice->devname;
+    mediaDevice->private = "/mnt2";
+    distWanted = NULL;
+    Mkdir("/mnt2");
+
+    variable_set2(SYSTEM_STATE, "fixit", 0);
 
     while (1) {
-	msgConfirm("Please insert a writable fixit floppy and press return");
-	mediaDevice->private = "/mnt2";
 	if (!mediaDevice->init(mediaDevice)) {
 	    if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n"
 			 "or unclean filesystem.  Do you want to try again?"))
@@ -368,8 +364,7 @@ installFixitFloppy(dialogMenuItem *self)
     if (!directory_exists("/tmp"))
 	(void)symlink("/mnt2/tmp", "/tmp");
     fixit_common();
-    mediaDevice->shutdown(mediaDevice);
-    mediaDevice = NULL;
+    mediaClose();
     msgConfirm("Please remove the fixit floppy now.");
     return DITEM_SUCCESS;
 }
diff --git a/usr.sbin/sade/system.c b/usr.sbin/sade/system.c
index ee0aba0a092b..f916555c8826 100644
--- a/usr.sbin/sade/system.c
+++ b/usr.sbin/sade/system.c
@@ -4,7 +4,7 @@
  * This is probably the last program in the `sysinstall' line - the next
  * generation being essentially a complete rewrite.
  *
- * $Id: system.c,v 1.89 1999/02/09 22:18:10 jkh Exp $
+ * $Id: system.c,v 1.90 1999/02/14 21:26:29 jkh Exp $
  *
  * Jordan Hubbard
  *
@@ -146,8 +146,8 @@ void
 systemShutdown(int status)
 {
     /* If some media is open, close it down */
-    if (status >=0 && mediaDevice)
-	mediaDevice->shutdown(mediaDevice);
+    if (status >=0)
+	mediaClose();
 
     /* write out any changes to rc.conf .. */
     configRC_conf();
diff --git a/usr.sbin/sysinstall/floppy.c b/usr.sbin/sysinstall/floppy.c
index 6c1ab402abe4..f3b210fa5db9 100644
--- a/usr.sbin/sysinstall/floppy.c
+++ b/usr.sbin/sysinstall/floppy.c
@@ -4,7 +4,7 @@
  * This is probably the last attempt in the `sysinstall' line, the next
  * generation being slated to essentially a complete rewrite.
  *
- * $Id: floppy.c,v 1.30 1998/10/12 23:45:06 jkh Exp $
+ * $Id: floppy.c,v 1.31 1998/12/22 12:31:24 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -63,12 +63,14 @@ mediaInitFloppy(Device *dev)
 {
     struct msdosfs_args dosargs;
     struct ufs_args u_args;
+    char *mp;
 
     if (floppyMounted)
 	return TRUE;
 
-    if (Mkdir(mountpoint)) {
-	msgConfirm("Unable to make %s directory mountpoint for %s!", mountpoint, dev->devname);
+    mp = dev->private ? (char *)dev->private : mountpoint;
+    if (Mkdir(mp)) {
+	msgConfirm("Unable to make %s directory mountpoint for %s!", mp, dev->devname);
 	return FALSE;
     }
 
@@ -90,10 +92,10 @@ mediaInitFloppy(Device *dev)
     memset(&u_args, 0, sizeof(u_args));
     u_args.fspec = dev->devname;
 
-    if (mount("msdos", mountpoint, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
-	if (mount("ufs", mountpoint, MNT_RDONLY, (caddr_t)&u_args) == -1) {
+    if (mount("msdos", mp, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
+	if (mount("ufs", mp, MNT_RDONLY, (caddr_t)&u_args) == -1) {
 	    msgConfirm("Error mounting floppy %s (%s) on %s : %s",
-		       dev->name, dev->devname, mountpoint, strerror(errno));
+		       dev->name, dev->devname, mp, strerror(errno));
 	    return FALSE;
 	}
     }
@@ -105,7 +107,7 @@ mediaInitFloppy(Device *dev)
 FILE *
 mediaGetFloppy(Device *dev, char *file, Boolean probe)
 {
-    char	buf[PATH_MAX];
+    char	buf[PATH_MAX], *mp;
     FILE	*fp;
     int		nretries = 5;
 
@@ -114,7 +116,8 @@ mediaGetFloppy(Device *dev, char *file, Boolean probe)
      * to speculatively open files on a floppy disk.  Make user get it
      * right or give up with floppies.
      */
-    snprintf(buf, PATH_MAX, "%s/%s", mountpoint, file);
+    mp = dev->private ? (char *)dev->private : mountpoint;
+    snprintf(buf, PATH_MAX, "%s/%s", mp, file);
     if (!file_readable(buf)) {
 	if (probe)
 	    return NULL;
@@ -139,8 +142,10 @@ void
 mediaShutdownFloppy(Device *dev)
 {
     if (floppyMounted) {
-	if (unmount(mountpoint, MNT_FORCE) != 0)
-	    msgDebug("Umount of floppy on %s failed: %s (%d)\n", mountpoint, strerror(errno), errno);
+    	char *mp = dev->private ? (char *)dev->private : mountpoint;
+
+	if (unmount(mp, MNT_FORCE) != 0)
+	    msgDebug("Umount of floppy on %s failed: %s (%d)\n", mp, strerror(errno), errno);
 	else {
 	    floppyMounted = FALSE;
 	    if (!variable_get(VAR_NONINTERACTIVE))
diff --git a/usr.sbin/sysinstall/install.c b/usr.sbin/sysinstall/install.c
index 63edd5cde2db..a01120cb7557 100644
--- a/usr.sbin/sysinstall/install.c
+++ b/usr.sbin/sysinstall/install.c
@@ -4,7 +4,7 @@
  * This is probably the last program in the `sysinstall' line - the next
  * generation being essentially a complete rewrite.
  *
- * $Id: install.c,v 1.227 1999/02/09 22:18:10 jkh Exp $
+ * $Id: install.c,v 1.228 1999/02/14 21:26:28 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -272,13 +272,10 @@ installFixitCDROM(dialogMenuItem *self)
     (void)rmdir("/mnt2");
 
     while (1) {
-	msgConfirm("Please insert the second FreeBSD CDROM and press return");
+	msgConfirm("Please insert a FreeBSD live filesystem CDROM and press return");
 	if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS || !mediaDevice || !mediaDevice->init(mediaDevice)) {
 	    /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */
-	    if (mediaDevice) {
-		mediaDevice->shutdown(mediaDevice);
-		mediaDevice = NULL;
-	    }
+	    mediaClose();
 	    if (msgYesNo("Unable to mount the CDROM - do you want to try again?") != 0)
 		return DITEM_FAILURE;
 	}
@@ -325,11 +322,9 @@ installFixitCDROM(dialogMenuItem *self)
 		       "Dynamic executables from the CDROM likely won't work.");
 	}
     }
-
     fixit_common();
-
-    mediaDevice->shutdown(mediaDevice);
-    msgConfirm("Please remove the FreeBSD CDROM now.");
+    mediaClose();
+    msgConfirm("Please remove the FreeBSD fixit CDROM now.");
     return DITEM_SUCCESS;
 }
 
@@ -337,15 +332,13 @@ int
 installFixitFloppy(dialogMenuItem *self)
 {
     struct ufs_args args;
+    extern char *distWanted;
 
     if (!RunningAsInit)
 	return DITEM_SUCCESS;
 
-    variable_set2(SYSTEM_STATE, "fixit", 0);
-    Mkdir("/mnt2");
-
     /* Try to open the floppy drive */
-    if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
+    if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) {
 	msgConfirm("Unable to set media device to floppy.");
 	mediaClose();
 	return DITEM_FAILURE;
@@ -353,10 +346,13 @@ installFixitFloppy(dialogMenuItem *self)
 
     memset(&args, 0, sizeof(args));
     args.fspec = mediaDevice->devname;
+    mediaDevice->private = "/mnt2";
+    distWanted = NULL;
+    Mkdir("/mnt2");
+
+    variable_set2(SYSTEM_STATE, "fixit", 0);
 
     while (1) {
-	msgConfirm("Please insert a writable fixit floppy and press return");
-	mediaDevice->private = "/mnt2";
 	if (!mediaDevice->init(mediaDevice)) {
 	    if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n"
 			 "or unclean filesystem.  Do you want to try again?"))
@@ -368,8 +364,7 @@ installFixitFloppy(dialogMenuItem *self)
     if (!directory_exists("/tmp"))
 	(void)symlink("/mnt2/tmp", "/tmp");
     fixit_common();
-    mediaDevice->shutdown(mediaDevice);
-    mediaDevice = NULL;
+    mediaClose();
     msgConfirm("Please remove the fixit floppy now.");
     return DITEM_SUCCESS;
 }
diff --git a/usr.sbin/sysinstall/media.c b/usr.sbin/sysinstall/media.c
index 61640e8a9f40..7384b41c9ec4 100644
--- a/usr.sbin/sysinstall/media.c
+++ b/usr.sbin/sysinstall/media.c
@@ -4,7 +4,7 @@
  * This is probably the last attempt in the `sysinstall' line, the next
  * generation being slated to essentially a complete rewrite.
  *
- * $Id: media.c,v 1.94 1998/12/22 12:31:25 jkh Exp $
+ * $Id: media.c,v 1.95 1999/02/05 22:15:50 jkh Exp $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -204,6 +204,8 @@ mediaSetFloppy(dialogMenuItem *self)
     }
     else
 	mediaDevice = devs[0];
+    if (mediaDevice)
+	mediaDevice->private = NULL;
     return (mediaDevice ? DITEM_LEAVE_MENU : DITEM_FAILURE) | DITEM_RESTORE;
 }
 
diff --git a/usr.sbin/sysinstall/system.c b/usr.sbin/sysinstall/system.c
index ee0aba0a092b..f916555c8826 100644
--- a/usr.sbin/sysinstall/system.c
+++ b/usr.sbin/sysinstall/system.c
@@ -4,7 +4,7 @@
  * This is probably the last program in the `sysinstall' line - the next
  * generation being essentially a complete rewrite.
  *
- * $Id: system.c,v 1.89 1999/02/09 22:18:10 jkh Exp $
+ * $Id: system.c,v 1.90 1999/02/14 21:26:29 jkh Exp $
  *
  * Jordan Hubbard
  *
@@ -146,8 +146,8 @@ void
 systemShutdown(int status)
 {
     /* If some media is open, close it down */
-    if (status >=0 && mediaDevice)
-	mediaDevice->shutdown(mediaDevice);
+    if (status >=0)
+	mediaClose();
 
     /* write out any changes to rc.conf .. */
     configRC_conf();