Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/sysinst - Replace the CD_NAME definition with ...



details:   https://anonhg.NetBSD.org/src/rev/499adb108641
branches:  trunk
changeset: 779852:499adb108641
user:      abs <abs%NetBSD.org@localhost>
date:      Fri Jun 22 20:54:39 2012 +0000

description:
- Replace the CD_NAME definition with a CD_NAMES comma separate list,
  the default remains "cd0a", but i386 sets "cd0a", "mcd0a" while vax
  takes "cd0a", "racd0a"
- Add get_default_cdrom() to disks.c, which is called in init(). This
  checks the contents of hw.disknames against CD_NAMES. The first one
  found (minus partition letter) is picked, otherwise the first entry
  in CD_NAMES is used
The primary beneficiary is vax systems with an MSCP but no SCSI CD
drive, which now default to (a valid) racd0a rather than an invalid
cd0a.  The obvious example being simh-vax

diffstat:

 distrib/utils/sysinst/arch/emips/md.h |   9 +++---
 distrib/utils/sysinst/arch/i386/md.h  |   8 ++++-
 distrib/utils/sysinst/arch/vax/md.h   |   8 +++++-
 distrib/utils/sysinst/defs.h          |   9 +++---
 distrib/utils/sysinst/disks.c         |  45 +++++++++++++++++++++++++++++++++-
 distrib/utils/sysinst/main.c          |  11 +++++++-
 6 files changed, 73 insertions(+), 17 deletions(-)

diffs (198 lines):

diff -r 4d6e6b53c6e7 -r 499adb108641 distrib/utils/sysinst/arch/emips/md.h
--- a/distrib/utils/sysinst/arch/emips/md.h     Fri Jun 22 20:42:22 2012 +0000
+++ b/distrib/utils/sysinst/arch/emips/md.h     Fri Jun 22 20:54:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.h,v 1.3 2011/04/04 08:30:22 mbalmer Exp $   */
+/*     $NetBSD: md.h,v 1.4 2012/06/22 20:54:39 abs Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -83,8 +83,7 @@
 #define MD_SETS_VALID  SET_KERNEL, SET_SYSTEM, SET_X11_NOSERVERS
 
 /* default install CD device is ace1a */
-/* XXX: not pretty */
-#ifdef CD_NAME
-#undef CD_NAME
+#ifdef CD_NAMES
+#undef CD_NAMES
 #endif
-#define CD_NAME "ace1a"
+#define CD_NAMES "ace1a"
diff -r 4d6e6b53c6e7 -r 499adb108641 distrib/utils/sysinst/arch/i386/md.h
--- a/distrib/utils/sysinst/arch/i386/md.h      Fri Jun 22 20:42:22 2012 +0000
+++ b/distrib/utils/sysinst/arch/i386/md.h      Fri Jun 22 20:54:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.h,v 1.68 2011/04/04 08:30:32 mbalmer Exp $  */
+/*     $NetBSD: md.h,v 1.69 2012/06/22 20:54:39 abs Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -105,8 +105,12 @@
 
 extern struct mbr_bootsel *mbs;
 
+/* i386 can still have old mcd ISA devices */
+#ifdef CD_NAMES
+#undef CD_NAMES
+#endif
+#define CD_NAMES "cd0a","mcd0a"
 
 /*
  *  prototypes for MD code.
  */
-
diff -r 4d6e6b53c6e7 -r 499adb108641 distrib/utils/sysinst/arch/vax/md.h
--- a/distrib/utils/sysinst/arch/vax/md.h       Fri Jun 22 20:42:22 2012 +0000
+++ b/distrib/utils/sysinst/arch/vax/md.h       Fri Jun 22 20:54:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.h,v 1.20 2011/04/04 08:30:44 mbalmer Exp $  */
+/*     $NetBSD: md.h,v 1.21 2012/06/22 20:54:39 abs Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -69,3 +69,9 @@
  * the hand-edited disklabel will NOT be written by MI code.
  */
 #define        DISKLABEL_CMD   "disklabel -w -r"
+
+/* VAX can have cd* or racd* devices */
+#ifdef CD_NAMES
+#undef CD_NAMES
+#endif
+#define CD_NAMES "cd0a","racd0a"
diff -r 4d6e6b53c6e7 -r 499adb108641 distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Fri Jun 22 20:42:22 2012 +0000
+++ b/distrib/utils/sysinst/defs.h      Fri Jun 22 20:54:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.162 2012/04/06 23:48:53 riz Exp $   */
+/*     $NetBSD: defs.h,v 1.163 2012/06/22 20:54:39 abs Exp $   */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -171,10 +171,8 @@
 #define PI_ISBSDFS(p) ((p)->pi_fstype == FS_BSDLFS || \
                       (p)->pi_fstype == FS_BSDFFS)
 
-/* non-standard cd0 driver */
-#ifndef CD_NAME
-#define CD_NAME "cd0a"
-#endif
+/* standard cd0 device */
+#define CD_NAMES "cd0a"
 
 /* Types */
 typedef struct distinfo {
@@ -379,6 +377,7 @@
 void   toplevel(void);
 
 /* from disks.c */
+const char *get_default_cdrom(void);
 int    find_disks(const char *);
 struct menudesc;
 void   fmt_fspart(struct menudesc *, int, void *);
diff -r 4d6e6b53c6e7 -r 499adb108641 distrib/utils/sysinst/disks.c
--- a/distrib/utils/sysinst/disks.c     Fri Jun 22 20:42:22 2012 +0000
+++ b/distrib/utils/sysinst/disks.c     Fri Jun 22 20:54:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.124 2012/05/21 22:38:26 jdf Exp $ */
+/*     $NetBSD: disks.c,v 1.125 2012/06/22 20:54:39 abs Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -43,6 +43,7 @@
 #include <util.h>
 
 #include <sys/param.h>
+#include <sys/sysctl.h>
 #include <sys/swap.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
@@ -305,6 +306,45 @@
                strcpy(dd->dd_descr, dd->dd_name);
 }
 
+/* disknames - contains device names without partition letters
+ * cdrom_devices - contains devices including partition letters
+ * 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)
+{
+       static const char *cdrom_devices[] = { CD_NAMES, 0};
+       static const char mib_name[] = "hw.disknames";
+       size_t len;
+       char *disknames;
+       char *last;
+       char *name;
+       const char **arg;
+       const char *cd_dev;
+
+       /* On error just use first entry in cdrom_devices */
+       if (sysctlbyname(mib_name, NULL, &len, NULL, 0) != 0)
+               return cdrom_devices[0];
+       if ((disknames = malloc(len)) == 0) /* skip on malloc fail */
+               return cdrom_devices[0];
+
+       sysctlbyname(mib_name, disknames, &len, NULL, 0);
+        for ((name = strtok_r(disknames, " ", &last)); name;
+           (name = strtok_r(NULL, " ", &last))) {
+               for (arg = cdrom_devices ; *arg ; ++arg ) {
+                       cd_dev = *arg;
+                       if (strncmp(cd_dev, name, strlen(cd_dev) - 1) == 0) {
+                               free(disknames);
+                               return cd_dev;
+                       }
+
+               }
+       }
+       free(disknames);
+       return cdrom_devices[0];
+}
+
 static int
 get_disks(struct disk_desc *dd)
 {
@@ -773,7 +813,8 @@
        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/" CD_NAME "\t\t/cdrom\tcd9660\tro,noauto\n");
+       scripting_fprintf(f, "/dev/%s\t\t/cdrom\tcd9660\tro,noauto\n",
+           (char *)get_default_cdrom);
        make_target_dir("/kern");
        make_target_dir("/proc");
        make_target_dir("/dev/pts");
diff -r 4d6e6b53c6e7 -r 499adb108641 distrib/utils/sysinst/main.c
--- a/distrib/utils/sysinst/main.c      Fri Jun 22 20:42:22 2012 +0000
+++ b/distrib/utils/sysinst/main.c      Fri Jun 22 20:54:39 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.64 2012/04/06 23:48:53 riz Exp $    */
+/*     $NetBSD: main.c,v 1.65 2012/06/22 20:54:39 abs Exp $    */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -91,7 +91,7 @@
        {"ftp proxy", "", ftp.proxy, sizeof ftp.proxy},
        {"nfs host", "", nfs_host, sizeof nfs_host},
        {"nfs dir", "/bsd/release", nfs_dir, sizeof nfs_dir},
-       {"cd dev", CD_NAME, cdrom_dev, sizeof cdrom_dev},
+       {"cd dev", 0, cdrom_dev, sizeof cdrom_dev}, /* default filled in init */
        {"fd dev", "/dev/fd0a", fd_dev, sizeof fd_dev},
        {"local dev", "", localfs_dev, sizeof localfs_dev},
        {"local fs", "ffs", localfs_fs, sizeof localfs_fs},
@@ -129,6 +129,13 @@
        fd_type = "msdos";
 
        for (arg = fflagopts; arg->name != NULL; arg++)
+               if (arg->var == cdrom_dev) {
+                       const char **dfltptr = __UNCONST(&arg->dflt);
+                       *dfltptr = get_default_cdrom();
+                       break;
+               }
+
+       for (arg = fflagopts; arg->name != NULL; arg++)
                strlcpy(arg->var, arg->dflt, arg->size);
        pkg.xfer_type = pkgsrc.xfer_type = "http";
 }



Home | Main Index | Thread Index | Old Index