Module Name:    src
Committed By:   sborrill
Date:           Thu Nov  5 08:10:21 UTC 2020

Modified Files:
        src/usr.sbin/sysinst [netbsd-9]: menus.mi msg.mi.de msg.mi.en msg.mi.es
            msg.mi.fr msg.mi.pl util.c

Log Message:
Pull up the following revisions(s) (requested by martin in ticket #1121):
        usr.sbin/sysinst/menus.mi:      revision 1.22-1.23
        usr.sbin/sysinst/msg.mi.de:     revision 1.25-1.26
        usr.sbin/sysinst/msg.mi.en:     revision 1.33-1.34
        usr.sbin/sysinst/msg.mi.pl:     revision 1.33-1.34
        usr.sbin/sysinst/msg.mi.es:     revision 1.27-1.28
        usr.sbin/sysinst/msg.mi.fr:     revision 1.32-1.33
        usr.sbin/sysinst/util.c:        revision 1.49-1.52

- When looking for available CD media, skip those that are already mounted.
- When no medium with sets is found, show a new error message and return
  to the source selection menu.
- Rearrange all source option menus to have the proper set suffix available
  (either .tgz or .tar.xz).
- Relax an assertion, the first getvfsstat() call may overestimate the file
  systems visible to us. Fixes PR 55752
- When we did not magically find any CD medium with sets, offer a manual
  override (so ISO images on USB sticks or Xen's xbd(4) work).


To generate a diff of this commit:
cvs rdiff -u -r1.19.2.1 -r1.19.2.2 src/usr.sbin/sysinst/menus.mi
cvs rdiff -u -r1.13.2.8 -r1.13.2.9 src/usr.sbin/sysinst/msg.mi.de
cvs rdiff -u -r1.19.2.9 -r1.19.2.10 src/usr.sbin/sysinst/msg.mi.en
cvs rdiff -u -r1.14.2.8 -r1.14.2.9 src/usr.sbin/sysinst/msg.mi.es
cvs rdiff -u -r1.17.2.9 -r1.17.2.10 src/usr.sbin/sysinst/msg.mi.fr
cvs rdiff -u -r1.20.2.9 -r1.20.2.10 src/usr.sbin/sysinst/msg.mi.pl
cvs rdiff -u -r1.29.2.7 -r1.29.2.8 src/usr.sbin/sysinst/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/menus.mi
diff -u src/usr.sbin/sysinst/menus.mi:1.19.2.1 src/usr.sbin/sysinst/menus.mi:1.19.2.2
--- src/usr.sbin/sysinst/menus.mi:1.19.2.1	Tue Jan 28 10:17:58 2020
+++ src/usr.sbin/sysinst/menus.mi	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: menus.mi,v 1.19.2.1 2020/01/28 10:17:58 msaitoh Exp $	*/
+/*	$NetBSD: menus.mi,v 1.19.2.2 2020/11/05 08:10:21 sborrill Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -362,8 +362,10 @@ menu distset, title MSG_Select_your_dist
 
 menu ftpsource, y=-4, x=0, w=70, no box, no clear,
 	    exitstring MSG_Get_Distribution;
-	display action { msg_fmt_display(MSG_ftpsource, "%s",
-	    url_proto((uintptr_t)((arg_rv*)arg)->arg)); };
+	display action {
+		msg_display_subst(MSG_ftpsource, 2, "." SETS_TAR_SUFF,
+		    url_proto((uintptr_t)((arg_rv*)arg)->arg));
+	    };
 	option {src_legend(menu, MSG_Host, ftp.xfer_host[(uintptr_t)((arg_rv*)arg)->arg]);},
 		action { src_prompt(MSG_Host, ftp.xfer_host[(uintptr_t)((arg_rv*)arg)->arg], sizeof ftp.xfer_host[(uintptr_t)((arg_rv*)arg)->arg]); };
 	option {src_legend(menu, MSG_Base_dir, ftp.dir);},
@@ -412,7 +414,8 @@ menu ftpsource, y=-4, x=0, w=70, no box,
 
 menu nfssource, y=-4, x=0, w=70, no box, no clear,
 	    exitstring MSG_Get_Distribution;
-	display action { msg_display(MSG_nfssource); };
+	display action { const char suff[] = "." SETS_TAR_SUFF;
+		msg_display_subst(MSG_nfssource, 1, &suff); };
 	option {src_legend(menu, MSG_Host, nfs_host);},
 		action { src_prompt(MSG_Host, nfs_host, sizeof nfs_host); };
 	option {src_legend(menu, MSG_Base_dir, nfs_dir);},
@@ -459,17 +462,20 @@ menu floppysource, y=-4, x=0, w=70, no b
 	option MSG_exit_menu_generic, exit, action { *((int*)arg) = SET_RETRY; };
 
 menu cdromsource, y=-4, x=0, w=70, no box, no clear, exitstring MSG_Continue;
-	display action { msg_display(MSG_cdromsource); };
+	display action { const char suff[] = "." SETS_TAR_SUFF;
+		msg_display_add_subst(MSG_cdromsource, 1, &suff); };
 	option {src_legend(menu, MSG_Device, cdrom_dev);},
 		action { src_prompt(MSG_dev, cdrom_dev, sizeof cdrom_dev); };
 	option {src_legend(menu, MSG_Set_dir_bin, set_dir_bin);},
 		action { src_prompt(MSG_Set_dir_bin, set_dir_bin, sizeof set_dir_bin); };
 	option {src_legend(menu, MSG_Set_dir_src, set_dir_src);},
 		action { src_prompt(MSG_Set_dir_src, set_dir_src, sizeof set_dir_src); };
-	option MSG_exit_menu_generic, exit, action { *((int*)arg) = SET_RETRY; };
+	option MSG_abort_install, exit, action { *((int*)arg) = SET_ABANDON; };
+	option MSG_source_sel_retry, exit, action { *((int*)arg) = SET_RETRY; };
 
 menu localfssource, y=-4, x=0, w=70, no box, no clear, exitstring MSG_Continue;
-	display action { msg_display(MSG_localfssource); };
+	display action { const char suff[] = "." SETS_TAR_SUFF;
+		msg_display_subst(MSG_localfssource, 1, &suff); };
 	option {src_legend(menu, MSG_Device, localfs_dev);},
 		action { src_prompt(MSG_dev, localfs_dev, sizeof localfs_dev);};
 	option {src_legend(menu, MSG_File_system, localfs_fs);},
@@ -483,7 +489,8 @@ menu localfssource, y=-4, x=0, w=70, no 
 	option MSG_exit_menu_generic, exit, action { *((int*)arg) = SET_RETRY; };
 
 menu localdirsource, y=-4, x=0, w=70, no box, no clear, exitstring MSG_Continue;
-	display action { msg_display(MSG_localdir); };
+	display action { const char suff[] = "." SETS_TAR_SUFF;
+		msg_display_subst(MSG_localdir, 1, &suff); };
 	option {src_legend(menu, MSG_Base_dir, localfs_dir);},
 		action { src_prompt(MSG_Base_dir, localfs_dir, 60); };
 	option {src_legend(menu, MSG_Set_dir_bin, set_dir_bin);},

Index: src/usr.sbin/sysinst/msg.mi.de
diff -u src/usr.sbin/sysinst/msg.mi.de:1.13.2.8 src/usr.sbin/sysinst/msg.mi.de:1.13.2.9
--- src/usr.sbin/sysinst/msg.mi.de:1.13.2.8	Thu Oct 15 19:36:50 2020
+++ src/usr.sbin/sysinst/msg.mi.de	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.de,v 1.13.2.8 2020/10/15 19:36:50 bouyer Exp $	*/
+/*	$NetBSD: msg.mi.de,v 1.13.2.9 2020/11/05 08:10:21 sborrill Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -507,8 +507,12 @@ alle Pakete (volle Installation) zu inst
 definierten Satz auszuw�hlen.
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ *  $1 = URL protocol used		ftp
+ */
 message ftpsource
-{Dies sind die Daten zum Aufbau einer %s-Verbindung.
+{Dies sind die Daten zum Aufbau einer $1-Verbindung.
 Falls der Benutzer "ftp" ist, ben�tigen Sie kein Passwort.
 
 }
@@ -519,10 +523,13 @@ message email
 message dev
 {Laufwerk}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message nfssource
 {Geben Sie den NFS-Server samt Verzeichnis an, auf dem die Distribution zu
 finden ist.
-(Das Verzeichnis muss .tgz Dateien enthalten und �ber NFS mountbar sein.)
+(Das Verzeichnis muss $0 Dateien enthalten und �ber NFS mountbar sein.)
 
 }
 
@@ -533,13 +540,28 @@ Verzeichnis der Diskette liegen.
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message cdromsource
 {Geben Sie das CD-Laufwerk und das entsprechende Verzeichnis an, in dem
 die Distribution zu finden ist.
-(Das Verzeichnis muss .tgz Dateien enthalten.)
+(Das Verzeichnis muss $0 Dateien enthalten.)
+
+}
 
+message No_cd_found
+{Kein CD Laufwerk enth�lt eine CD mit den Distributions-Dateien!  
+Geben Sie die korrekten Daten manuel ein, oder legen Sie eine CD
+ein und versuchen Sie es erneut. 
 }
 
+message abort_install
+{Installation abbrechen}
+
+message source_sel_retry
+{Zur�ck zur Quellauswahl}
+
 message Available_cds
 {Verf�gbare CDs}
 
@@ -550,17 +572,23 @@ message cd_path_not_found
 {Die Installationsdateien wurden auf der ausgew�hlten CD nicht gefunden. Bitte
 pr�fen Sie den Ger�tenamen und Pfad der Installationsdateien.}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localfssource
 {Geben Sie das noch nicht gemountete lokale Ger�t und dessen entsprechendes
 Verzeichnis an, in dem die Distribution zu finden ist.
-(Das Verzeichnis muss .tgz Dateien enthalten.)
+(Das Verzeichnis muss $0 Dateien enthalten.)
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localdir
 {Geben Sie das Verzeichnis des bereits gemounteten lokalen Ger�ts an, in dem
 die Distribution zu finden ist.
-(Das Verzeichnis muss .tgz Dateien enthalten.)
+(Das Verzeichnis muss $0 Dateien enthalten.)
 
 }
 

Index: src/usr.sbin/sysinst/msg.mi.en
diff -u src/usr.sbin/sysinst/msg.mi.en:1.19.2.9 src/usr.sbin/sysinst/msg.mi.en:1.19.2.10
--- src/usr.sbin/sysinst/msg.mi.en:1.19.2.9	Thu Oct 15 19:36:51 2020
+++ src/usr.sbin/sysinst/msg.mi.en	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.en,v 1.19.2.9 2020/10/15 19:36:51 bouyer Exp $	*/
+/*	$NetBSD: msg.mi.en,v 1.19.2.10 2020/11/05 08:10:21 sborrill Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -487,8 +487,12 @@ a core set (Minimal installation), all o
 group of sets (Custom installation).
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ *  $1 = URL protocol used		ftp
+ */
 message ftpsource
-{The following are the %s site, directory, user, and password that
+{The following are the $1 site, directory, user, and password that
 will be used.  If "user" is "ftp", then the password is not needed.
 
 }
@@ -499,9 +503,12 @@ message email
 message dev
 {device}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message nfssource
 {Enter the nfs host and server directory where the distribution is located. 
-Remember, the directory should contain the .tgz files and
+Remember, the directory should contain the $0 files and
 must be nfs mountable.
 
 }
@@ -512,13 +519,27 @@ file system.  The set files must be in t
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message cdromsource
 {Enter the CDROM device to be used and directory on the CDROM where
 the distribution is located. 
-Remember, the directory should contain the .tgz files.
+Remember, the directory should contain the $0 files.
+
+}
 
+message No_cd_found
+{Could not locate a CD medium in any drive with the distribution sets! 
+Enter the correct data manually, or insert a disk and retry. 
 }
 
+message abort_install
+{Cancel installation}
+
+message source_sel_retry
+{Back to source selection & retry}
+
 message Available_cds
 {Available CDs }
 
@@ -529,16 +550,22 @@ message cd_path_not_found
 {The installation sets have not been found at the default location on this
 CD.  Please check the device and path name.}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localfssource
 {Enter the unmounted local device and directory on that device where
 the distribution is located. 
-Remember, the directory should contain the .tgz files.
+Remember, the directory should contain the $0 files.
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localdir
 {Enter the already-mounted local directory where the distribution is located. 
-Remember, the directory should contain the .tgz files.
+Remember, the directory should contain the $0 files.
 
 }
 

Index: src/usr.sbin/sysinst/msg.mi.es
diff -u src/usr.sbin/sysinst/msg.mi.es:1.14.2.8 src/usr.sbin/sysinst/msg.mi.es:1.14.2.9
--- src/usr.sbin/sysinst/msg.mi.es:1.14.2.8	Thu Oct 15 19:36:51 2020
+++ src/usr.sbin/sysinst/msg.mi.es	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.es,v 1.14.2.8 2020/10/15 19:36:51 bouyer Exp $	*/
+/*	$NetBSD: msg.mi.es,v 1.14.2.9 2020/11/05 08:10:21 sborrill Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -502,8 +502,12 @@ instalaciones.  Puede escoger para insta
 seleccionar de entre los conjuntos de distribuci�n opcionales.
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ *  $1 = URL protocol used		ftp
+ */
 message ftpsource
-{Lo siguiente son el sitio %s, directorio, usuario y contrase�a que se
+{Lo siguiente son el sitio $1, directorio, usuario y contrase�a que se
 usar�n.  Si �usuario� es �ftp�, no se necesita contrase�a..
 
 }
@@ -514,9 +518,12 @@ message email
 message dev
 {dispositivo}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message nfssource
 {Introduzca el servidor nfs y el directorio del servidor donde se encuentre
-la distribuci�n.  Recuerde: el directorio debe contener los archivos .tgz y
+la distribuci�n.  Recuerde: el directorio debe contener los archivos $0 y
 debe ser montable por nfs.
 
 }
@@ -528,13 +535,27 @@ en el directorio ra�z de los disquetes.
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message cdromsource
 {Introduzca el dispositivo de CDROM a usar y el directorio del CDROM
 donde se encuentre la distribuci�n.
-Recuerde, el directorio debe contener los archivos .tgz.
+Recuerde, el directorio debe contener los archivos $0.
+
+}
 
+message No_cd_found
+{Could not locate a CD medium in any drive with the distribution sets! 
+Enter the correct data manually, or insert a disk and retry. 
 }
 
+message abort_install
+{Cancel installation}
+
+message source_sel_retry
+{Back to source selection & retry}
+
 message Available_cds
 {Available CDs}
 
@@ -545,16 +566,22 @@ message cd_path_not_found
 {The installation sets have not been found at the default location on this
 CD. Please check device and path name.}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localfssource
 {Introduzca el dispositivo local desmontado y el directorio de ese
 dispositivo donde se encuentre la distribuci�n. 
-Recuerde, el directorio debe contener los archivos .tgz.
+Recuerde, el directorio debe contener los archivos $0.
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localdir
 {Introduzca el directorio local ya montado donde se encuentre la distribuci�n.
-Recuerde, el directorio debe contener los archivos .tgz.
+Recuerde, el directorio debe contener los archivos $0.
 
 }
 

Index: src/usr.sbin/sysinst/msg.mi.fr
diff -u src/usr.sbin/sysinst/msg.mi.fr:1.17.2.9 src/usr.sbin/sysinst/msg.mi.fr:1.17.2.10
--- src/usr.sbin/sysinst/msg.mi.fr:1.17.2.9	Thu Oct 15 19:36:50 2020
+++ src/usr.sbin/sysinst/msg.mi.fr	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.fr,v 1.17.2.9 2020/10/15 19:36:50 bouyer Exp $	*/
+/*	$NetBSD: msg.mi.fr,v 1.17.2.10 2020/11/05 08:10:21 sborrill Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -498,13 +498,17 @@ Trois types d'installations vous sont pr
 personnalis�e.
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ *  $1 = URL protocol used		ftp
+ */
 message ftpsource
-{Voici la configuration actuelle pour : nom du site (%s), r�pertoire, nom
+{Voici la configuration actuelle pour : nom du site ($1), r�pertoire, nom
 d'utilisateur et mot de passe.
 Si vous utilisez le mode FTP, le mot de passe n'est pas requis.
 Le r�pertoire contenant les composants doit �tre d�fini par
 rapport au r�pertoire de base, et contenir chaque composant sous
-la forme de fichiers .tgz
+la forme de fichiers $0
 
 }
 
@@ -537,6 +541,16 @@ tgz.
 
 }
 
+message No_cd_found
+{Could not locate a CD medium in any drive with the distribution sets! 
+Enter the correct data manually, or insert a disk and retry. 
+}
+
+message abort_install
+{Cancel installation}
+
+message source_sel_retry
+{Back to source selection & retry}
 
 message Available_cds
 {CD-ROM disponibles}

Index: src/usr.sbin/sysinst/msg.mi.pl
diff -u src/usr.sbin/sysinst/msg.mi.pl:1.20.2.9 src/usr.sbin/sysinst/msg.mi.pl:1.20.2.10
--- src/usr.sbin/sysinst/msg.mi.pl:1.20.2.9	Thu Oct 15 19:36:51 2020
+++ src/usr.sbin/sysinst/msg.mi.pl	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.pl,v 1.20.2.9 2020/10/15 19:36:51 bouyer Exp $	*/
+/*	$NetBSD: msg.mi.pl,v 1.20.2.10 2020/11/05 08:10:21 sborrill Exp $	*/
 /*	Based on english version: */
 /*	NetBSD: msg.mi.pl,v 1.36 2004/04/17 18:55:35 atatat Exp       */
 
@@ -480,10 +480,12 @@ takze zainstalowac tylko podstawowy zest
 wybrac te, ktore chcesz (Inna instalacja)
 }
 
-
-
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ *  $1 = URL protocol used		ftp
+ */
 message ftpsource
-{Ponizej masz site %s, katalog, uzytkownika, oraz haslo gotowe do uzycia.
+{Ponizej masz site $1, katalog, uzytkownika, oraz haslo gotowe do uzycia.
 Jesli "uzytkownik" to "ftp", wtedy haslo nie jest wymagane.
 
 }
@@ -494,9 +496,12 @@ message email
 message dev
 {urzadzenie}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message nfssource
 {Wprowadz hosta NFS oraz katalog gdzie znajduje sie dystrybucja. 
-Pamietaj, ze katalog musi zawierac pliki .tgz, oraz musi byc
+Pamietaj, ze katalog musi zawierac pliki $0, oraz musi byc
 dostepny przez NFS.
 
 }
@@ -508,13 +513,27 @@ znajdowac sie w glownym katalogu dyskiet
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message cdromsource
 {Podaj urzadzenie CDROM oraz katalog na CDROMie, w ktorym znajduje sie
 dystrybucja. 
-Pamietaj, ze katalog musi zawierac pliki .tgz.
+Pamietaj, ze katalog musi zawierac pliki $0.
 
 }
 
+message No_cd_found
+{Could not locate a CD medium in any drive with the distribution sets! 
+Enter the correct data manually, or insert a disk and retry. 
+}
+
+message abort_install
+{Cancel installation}
+
+message source_sel_retry
+{Back to source selection & retry}
+
 message Available_cds
 {Dostepne napedy CD}
 
@@ -526,16 +545,22 @@ message cd_path_not_found
 {Zbiory instalacyjne nie zostaly znalezione w domyslnym polozeniu na tym
 CD. Prosze sprawdzic urzadzenie i sciezke.}
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localfssource
 {Podaj niezamontowane lokalne urzadzenie oraz katalog na nim, gdzie
 znajduje sie dystrybucja. 
-Pamietaj, ze katalog musi zawierac pliki .tgz.
+Pamietaj, ze katalog musi zawierac pliki $0.
 
 }
 
+/* Called with: 			Example
+ *  $0 = sets suffix			.tgz
+ */
 message localdir
 {Podaj aktualnie zamontowany lokalny katalog, gdzie znajduje sie dystrybucja. 
-Pamietaj, ze katalog musi zawierac pliki .tgz.
+Pamietaj, ze katalog musi zawierac pliki $0.
 
 }
 

Index: src/usr.sbin/sysinst/util.c
diff -u src/usr.sbin/sysinst/util.c:1.29.2.7 src/usr.sbin/sysinst/util.c:1.29.2.8
--- src/usr.sbin/sysinst/util.c:1.29.2.7	Thu Oct 15 19:36:50 2020
+++ src/usr.sbin/sysinst/util.c	Thu Nov  5 08:10:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.29.2.7 2020/10/15 19:36:50 bouyer Exp $	*/
+/*	$NetBSD: util.c,v 1.29.2.8 2020/11/05 08:10:21 sborrill Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -414,6 +414,8 @@ get_iso9660_volname(int dev, int sess, c
  * Local state while iterating CDs and collecting volumes
  */
 struct get_available_cds_state {
+	size_t num_mounted;
+	struct statvfs *mounted;
 	struct cd_info *info;
 	size_t count;
 };
@@ -425,14 +427,26 @@ static bool
 get_available_cds_helper(void *arg, const char *device)
 {
 	struct get_available_cds_state *state = arg;
-	char dname[16], volname[80];
+	char dname[16], tname[16], volname[80], *t;
 	struct disklabel label;
-	int part, dev, error, sess, ready;
+	int part, dev, error, sess, ready, tlen;
 
 	if (!is_cdrom_device(device, false))
 		return true;
 
 	sprintf(dname, "/dev/r%s%c", device, 'a'+RAW_PART);
+	tlen = sprintf(tname, "/dev/%s", device);
+
+	/* check if this is mounted already */
+	for (size_t i = 0; i < state->num_mounted; i++) {
+		if (strncmp(state->mounted[i].f_mntfromname, tname, tlen)
+		    == 0) {
+			t = state->mounted[i].f_mntfromname + tlen;
+			if (t[0] >= 'a' && t[0] <= 'z' && t[1] == 0)
+				return true;
+		}
+	}
+
 	dev = open(dname, O_RDONLY, 0);
 	if (dev == -1)
 		return true;
@@ -495,18 +509,35 @@ static int
 get_available_cds(void)
 {
 	struct get_available_cds_state data;
+	int n, m;
 
+	memset(&data, 0, sizeof data);
 	data.info = cds;
-	data.count = 0;
+
+	n = getvfsstat(NULL, 0, ST_NOWAIT);
+	if (n > 0) {
+		data.mounted = calloc(n, sizeof(*data.mounted));
+		m = getvfsstat(data.mounted, n*sizeof(*data.mounted),
+		    ST_NOWAIT);
+		assert(m >= 0 && m <= n);
+		data.num_mounted = m;
+	}
 
 	enumerate_disks(&data, get_available_cds_helper);
 
+	free(data.mounted);
+
 	return data.count;
 }
 
 static int
 cd_has_sets(void)
 {
+
+	/* sanity check */
+	if (cdrom_dev[0] == 0)
+		return 0;
+
 	/* Mount it */
 	if (run_program(RUN_SILENT, "/sbin/mount -rt cd9660 /dev/%s /mnt2",
 	    cdrom_dev) != 0)
@@ -564,7 +595,6 @@ get_via_cdrom(void)
 	menu_ent cd_menu[MAX_CD_INFOS];
 	struct stat sb;
 	int rv, num_cds, menu_cd, i, selected_cd = 0;
-	bool silent = false;
 	int mib[2];
 	char rootdev[SSTRSIZE] = "";
 	size_t varlen;
@@ -584,7 +614,8 @@ get_via_cdrom(void)
 	memset(cd_menu, 0, sizeof(cd_menu));
 	num_cds = get_available_cds();
 	if (num_cds <= 0) {
-		silent = true;
+		msg_display(MSG_No_cd_found);
+		cdrom_dev[0] = 0;
 	} else if (num_cds == 1) {
 		/* single CD found, check for sets on it */
 		strcpy(cdrom_dev, cds[0].device_name);
@@ -611,9 +642,7 @@ get_via_cdrom(void)
 			return SET_OK;
 	}
 
-	if (silent)
-		msg_display("");
-	else {
+	if (num_cds >= 1 && mnt2_mounted) {
 		umount_mnt2();
 		hit_enter_to_continue(MSG_cd_path_not_found, NULL);
 	}
@@ -621,8 +650,8 @@ get_via_cdrom(void)
 	/* ask for paths on the CD */
 	rv = -1;
 	process_menu(MENU_cdromsource, &rv);
-	if (rv == SET_RETRY)
-		return SET_RETRY;
+	if (rv == SET_RETRY || rv == SET_ABANDON)
+		return rv;
 
 	if (cd_has_sets())
 		return SET_OK;

Reply via email to