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.
This commit is contained in:
parent
8df70e6b71
commit
3b44a3d7f6
|
@ -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"
|
||||
|
|
|
@ -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 @@ extern struct mbr_bootsel *mbs;
|
|||
#ifdef CD_NAMES
|
||||
#undef CD_NAMES
|
||||
#endif
|
||||
#define CD_NAMES "cd0a","mcd0a"
|
||||
#define CD_NAMES "cd*","mcd*"
|
||||
|
||||
/*
|
||||
* prototypes for MD code.
|
||||
|
|
|
@ -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*"
|
||||
|
|
|
@ -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 @@ enum {
|
|||
(p)->pi_fstype == FS_BSDFFS)
|
||||
|
||||
/* standard cd0 device */
|
||||
#define CD_NAMES "cd0a"
|
||||
#define CD_NAMES "cd*"
|
||||
|
||||
/* Types */
|
||||
|
||||
|
@ -473,7 +473,7 @@ int md_update(void);
|
|||
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 *);
|
||||
|
|
|
@ -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 @@ done:
|
|||
* 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 @@ is_ffs_wedge(const char *dev)
|
|||
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 @@ get_disks(struct disk_desc *dd, bool with_non_partitionable)
|
|||
}
|
||||
|
||||
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 @@ find_disks(const char *doingwhat)
|
|||
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 @@ done_with_disks:
|
|||
#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");
|
||||
|
|
|
@ -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 @@ init(void)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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 @@ get_iso9660_volname(int dev, int sess, char *volname)
|
|||
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) {
|
||||
close(dev);
|
||||
continue;
|
||||
}
|
||||
error = ioctl(dev, DIOCGDINFO, &label);
|
||||
close(dev);
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
if (++count >= MAX_CD_INFOS)
|
||||
break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue