Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Unify handling of CDROM device names.
details: https://anonhg.NetBSD.org/src/rev/d62fb8e9409f
branches: trunk
changeset: 445647:d62fb8e9409f
user: martin <martin%NetBSD.org@localhost>
date: Wed Nov 07 21:20:23 2018 +0000
description:
Unify handling of CDROM device names.
Skip CDs when looking for install targets (we do not support installing
onto a blueray with UDF).
Fix search for the default CDROM device and the CD we booted from
for ports with nonstandard CDROM device names.
diffstat:
usr.sbin/sysinst/arch/emips/md.h | 4 +-
usr.sbin/sysinst/arch/i386/md.h | 4 +-
usr.sbin/sysinst/arch/vax/md.h | 4 +-
usr.sbin/sysinst/defs.h | 6 +-
usr.sbin/sysinst/disks.c | 61 ++++++++++++++++--
usr.sbin/sysinst/main.c | 4 +-
usr.sbin/sysinst/util.c | 125 ++++++++++++++++++++++----------------
7 files changed, 137 insertions(+), 71 deletions(-)
diffs (truncated from 348 to 300 lines):
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/arch/emips/md.h
--- a/usr.sbin/sysinst/arch/emips/md.h Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/arch/emips/md.h Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */
+/* $NetBSD: md.h,v 1.3 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -80,4 +80,4 @@
#ifdef CD_NAMES
#undef CD_NAMES
#endif
-#define CD_NAMES "ace1a"
+#define CD_NAMES "ace1"
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/arch/i386/md.h
--- a/usr.sbin/sysinst/arch/i386/md.h Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/arch/i386/md.h Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */
+/* $NetBSD: md.h,v 1.3 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -101,7 +101,7 @@
#ifdef CD_NAMES
#undef CD_NAMES
#endif
-#define CD_NAMES "cd0a","mcd0a"
+#define CD_NAMES "cd*","mcd*"
/*
* prototypes for MD code.
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/arch/vax/md.h
--- a/usr.sbin/sysinst/arch/vax/md.h Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/arch/vax/md.h Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */
+/* $NetBSD: md.h,v 1.3 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -69,4 +69,4 @@
#ifdef CD_NAMES
#undef CD_NAMES
#endif
-#define CD_NAMES "cd0a","racd0a"
+#define CD_NAMES "cd*","racd*"
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/defs.h Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.20 2018/10/06 18:45:37 martin Exp $ */
+/* $NetBSD: defs.h,v 1.21 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -179,7 +179,7 @@
(p)->pi_fstype == FS_BSDFFS)
/* standard cd0 device */
-#define CD_NAMES "cd0a"
+#define CD_NAMES "cd*"
/* Types */
@@ -473,7 +473,7 @@
void toplevel(void);
/* from disks.c */
-const char *get_default_cdrom(void);
+bool get_default_cdrom(char *, size_t);
int find_disks(const char *);
struct menudesc;
void fmt_fspart(struct menudesc *, int, void *);
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/disks.c Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disks.c,v 1.17 2018/11/05 19:45:56 martin Exp $ */
+/* $NetBSD: disks.c,v 1.18 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -355,10 +355,10 @@
* returns the first entry in hw.disknames matching a cdrom_device, or
* first entry on error or no match
*/
-const char *
-get_default_cdrom(void)
+bool
+get_default_cdrom(char *cd, size_t max_len)
{
- static const char *cdrom_devices[] = { CD_NAMES, 0};
+ static const char *cdrom_devices[] = { CD_NAMES, 0 };
static const char mib_name[] = "hw.disknames";
size_t len;
char *disknames;
@@ -502,8 +502,40 @@
return res;
}
+/*
+ * Does this device match an entry in our default CDROM device list?
+ */
+static bool
+is_cdrom_device(const char *dev)
+{
+ static const char *cdrom_devices[] = { CD_NAMES, 0 };
+ char pat[SSTRSIZE], *star;
+ const char **dev_pat;
+
+ for (dev_pat = cdrom_devices; *dev_pat; dev_pat++) {
+ strcpy(pat, *dev_pat);
+ star = strchr(pat, '*');
+ if (star)
+ *star = 0;
+
+ if (strcmp(dev, pat) == 0)
+ return true;
+ }
+
+ return false;
+}
+
+/*
+ * Multi-purpose helper function:
+ * iterate all known disks, either
+ * - skip all CD devices
+ * - recognize the first available CD device and set its name
+ * When doing non-CDs, optionally skip non-partionable devices
+ * (i.e. wedges).
+ */
static int
-get_disks(struct disk_desc *dd, bool with_non_partitionable)
+get_disks(struct disk_desc *dd, bool with_non_partitionable,
+ char *cd_dev, size_t max_len)
{
static const int mib[] = { CTL_HW, HW_DISKNAMES };
static const unsigned int miblen = __arraycount(mib);
@@ -528,6 +560,18 @@
}
for (xd = strtok(disk_names, " "); xd != NULL; xd = strtok(NULL, " ")) {
+ /* is this a CD device? */
+ if (is_cdrom_device(xd)) {
+ if (cd_dev && max_len) {
+ /* return first found CD device name */
+ strlcpy(cd_dev, xd, max_len);
+ return 1;
+ } else {
+ /* skip this device */
+ continue;
+ }
+ }
+
strlcpy(dd->dd_name, xd, sizeof dd->dd_name - 2);
dd->dd_no_mbr = false;
dd->dd_no_part = false;
@@ -600,7 +644,7 @@
pm_devs_t *pm_i, *pm_last = NULL;
/* Find disks. */
- numdisks = get_disks(disks, partman_go <= 0);
+ numdisks = get_disks(disks, partman_go <= 0, NULL, 0);
/* need a redraw here, kernel messages hose everything */
touchwin(stdscr);
@@ -1187,12 +1231,15 @@
#endif
}
+ if (cdrom_dev[0] == 0)
+ get_default_cdrom(cdrom_dev, sizeof(cdrom_dev));
+
/* Add /kern, /proc and /dev/pts to fstab and make mountpoint. */
scripting_fprintf(f, "kernfs\t\t/kern\tkernfs\trw\n");
scripting_fprintf(f, "ptyfs\t\t/dev/pts\tptyfs\trw\n");
scripting_fprintf(f, "procfs\t\t/proc\tprocfs\trw\n");
scripting_fprintf(f, "/dev/%s\t\t/cdrom\tcd9660\tro,noauto\n",
- get_default_cdrom());
+ cdrom_dev);
scripting_fprintf(f, "%stmpfs\t\t/var/shm\ttmpfs\trw,-m1777,-sram%%25\n",
tmpfs_on_var_shm() ? "" : "#");
make_target_dir("/kern");
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/main.c
--- a/usr.sbin/sysinst/main.c Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/main.c Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.12 2018/11/03 18:30:00 martin Exp $ */
+/* $NetBSD: main.c,v 1.13 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -148,7 +148,7 @@
for (arg = fflagopts; arg->name != NULL; arg++) {
if (arg->var == cdrom_dev)
- strlcpy(arg->var, get_default_cdrom(), arg->size);
+ get_default_cdrom(arg->var, arg->size);
else
strlcpy(arg->var, arg->dflt, arg->size);
}
diff -r 202b44be20fe -r d62fb8e9409f usr.sbin/sysinst/util.c
--- a/usr.sbin/sysinst/util.c Wed Nov 07 17:05:54 2018 +0000
+++ b/usr.sbin/sysinst/util.c Wed Nov 07 21:20:23 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.13 2018/11/05 17:04:03 martin Exp $ */
+/* $NetBSD: util.c,v 1.14 2018/11/07 21:20:23 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -419,64 +419,83 @@
static int
get_available_cds(void)
{
- char dname[16], volname[80];
+ static const char *cdrom_devices[] = { CD_NAMES, 0 };
+ char dname[16], volname[80], fmt[80], tmp[80], *star;
struct cd_info *info = cds;
struct disklabel label;
int i, part, dev, error, sess, ready, count = 0;
- for (i = 0; i < MAX_CD_DEVS; i++) {
- sprintf(dname, "/dev/rcd%d%c", i, 'a'+RAW_PART);
- dev = open(dname, O_RDONLY, 0);
- if (dev == -1)
- break;
- ready = 0;
- error = ioctl(dev, DIOCTUR, &ready);
- if (error != 0 || ready == 0) {
+ for (const char **dev_pat = cdrom_devices; *dev_pat; dev_pat++) {
+ for (i = 0; i < MAX_CD_DEVS; i++) {
+ strcpy(fmt, *dev_pat);
+ star = strchr(fmt, '*');
+ if (star) {
+ strcpy(star, "%d");
+ sprintf(tmp, "/dev/r%s%%c", fmt);
+ sprintf(dname, tmp, i, 'a'+RAW_PART);
+ } else {
+ sprintf(dname, "/dev/r%s%c", fmt,
+ 'a'+RAW_PART);
+ }
+ dev = open(dname, O_RDONLY, 0);
+ if (dev == -1)
+ continue;
+ ready = 0;
+ error = ioctl(dev, DIOCTUR, &ready);
+ if (error != 0 || ready == 0) {
+ close(dev);
+ continue;
+ }
+ error = ioctl(dev, DIOCGDINFO, &label);
close(dev);
- continue;
+ if (error == 0) {
+ for (part = 0; part < label.d_npartitions;
+ part++) {
+ if (label.d_partitions[part].p_fstype
+ == FS_UNUSED
+ || label.d_partitions[part].p_size == 0)
+ continue;
+ if (label.d_partitions[part].p_fstype
+ == FS_ISO9660) {
+ sess = label.d_partitions[part]
+ .p_cdsession;
+ sprintf(dname, "/dev/rcd%d%c", i,
+ 'a'+part);
+ dev = open(dname, O_RDONLY, 0);
+ if (dev == -1)
+ continue;
+ error = get_iso9660_volname(dev, sess,
+ volname);
+ close(dev);
+ if (error) continue;
+ sprintf(info->device_name, "cd%d%c",
+ i, 'a'+part);
+ sprintf(info->menu, "%s (%s)",
+ info->device_name,
+ volname);
+ } else {
+ /*
+ * All install CDs use partition
+ * a for the sets.
+ */
+ if (part > 0)
+ continue;
+ sprintf(info->device_name, "cd%d%c",
+ i, 'a'+part);
+ strcpy(info->menu, info->device_name);
+ }
+ info++;
+ if (++count >= MAX_CD_INFOS)
+ break;
+ }
+ }
+ if (++count >= MAX_CD_INFOS)
+ break;
+ if (!star)
+ break;
Home |
Main Index |
Thread Index |
Old Index