Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Adapt other cd-device query functions to ne...
details: https://anonhg.NetBSD.org/src/rev/427f6670c7a4
branches: trunk
changeset: 836840:427f6670c7a4
user: martin <martin%NetBSD.org@localhost>
date: Thu Nov 08 20:29:37 2018 +0000
description:
Adapt other cd-device query functions to new world order, fix
default cd device (assume 'a' partition).
diffstat:
usr.sbin/sysinst/defs.h | 5 +-
usr.sbin/sysinst/disks.c | 12 ++-
usr.sbin/sysinst/util.c | 164 ++++++++++++++++++++++++----------------------
3 files changed, 96 insertions(+), 85 deletions(-)
diffs (252 lines):
diff -r 86304a424120 -r 427f6670c7a4 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h Thu Nov 08 18:37:42 2018 +0000
+++ b/usr.sbin/sysinst/defs.h Thu Nov 08 20:29:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.21 2018/11/07 21:20:23 martin Exp $ */
+/* $NetBSD: defs.h,v 1.22 2018/11/08 20:29:37 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -475,6 +475,9 @@
/* from disks.c */
bool get_default_cdrom(char *, size_t);
int find_disks(const char *);
+bool enumerate_disks(void *state,bool (*func)(void *state, const char *dev));
+bool is_cdrom_device(const char *dev);
+
struct menudesc;
void fmt_fspart(struct menudesc *, int, void *);
void disp_cur_fspart(int, int);
diff -r 86304a424120 -r 427f6670c7a4 usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c Thu Nov 08 18:37:42 2018 +0000
+++ b/usr.sbin/sysinst/disks.c Thu Nov 08 20:29:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disks.c,v 1.21 2018/11/08 11:56:56 martin Exp $ */
+/* $NetBSD: disks.c,v 1.22 2018/11/08 20:29:37 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -110,8 +110,6 @@
static void fixsb(const char *, const char *, char);
static bool is_gpt(const char *);
static int incoregpt(pm_devs_t *, partinfo *);
-static bool enumerate_disks(void *state,
- bool (*func)(void *state, const char *dev));
static bool tmpfs_on_var_shm(void);
@@ -371,7 +369,11 @@
{
struct default_cdrom_data *data = state;
+ if (!is_cdrom_device(dev))
+ return true;
+
strlcpy(data->device, dev, data->max_len);
+ strlcat(data->device, "a", data->max_len); /* default to partition a */
data->found = true;
return false; /* one is enough, stop iteration */
@@ -510,7 +512,7 @@
/*
* Does this device match an entry in our default CDROM device list?
*/
-static bool
+bool
is_cdrom_device(const char *dev)
{
static const char *cdrom_devices[] = { CD_NAMES, 0 };
@@ -528,7 +530,7 @@
* Stop iteration when the callback returns false.
* Return true when iteration actually happend, false on error.
*/
-static bool
+bool
enumerate_disks(void *state, bool (*func)(void *state, const char *dev))
{
static const int mib[] = { CTL_HW, HW_DISKNAMES };
diff -r 86304a424120 -r 427f6670c7a4 usr.sbin/sysinst/util.c
--- a/usr.sbin/sysinst/util.c Thu Nov 08 18:37:42 2018 +0000
+++ b/usr.sbin/sysinst/util.c Thu Nov 08 20:29:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.14 2018/11/07 21:20:23 martin Exp $ */
+/* $NetBSD: util.c,v 1.15 2018/11/08 20:29:37 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -413,91 +413,97 @@
}
/*
+ * Local state while iterating CDs and collecting volumes
+ */
+struct get_available_cds_state {
+ struct cd_info *info;
+ size_t count;
+};
+
+/*
+ * Callback function: if this is a CD, enumerate all volumes on it
+ */
+static bool
+get_available_cds_helper(void *arg, const char *device)
+{
+ struct get_available_cds_state *state = arg;
+ char dname[16], volname[80];
+ struct disklabel label;
+ int part, dev, error, sess, ready;
+
+ if (!is_cdrom_device(device))
+ return true;
+
+ sprintf(dname, "/dev/r%s%c", device, 'a'+RAW_PART);
+ dev = open(dname, O_RDONLY, 0);
+ if (dev == -1)
+ return true;
+
+ ready = 0;
+ error = ioctl(dev, DIOCTUR, &ready);
+ if (error != 0 || ready == 0) {
+ close(dev);
+ return true;
+ }
+ error = ioctl(dev, DIOCGDINFO, &label);
+ close(dev);
+ if (error != 0)
+ return true;
+
+ 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/r%s%c", device, '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(state->info->device_name,
+ "%s%c", device, 'a'+part);
+ sprintf(state->info->menu, "%s (%s)",
+ state->info->device_name, volname);
+ } else {
+ /*
+ * All install CDs use partition
+ * a for the sets.
+ */
+ if (part > 0)
+ continue;
+ sprintf(state->info->device_name,
+ "%s%c", device, 'a'+part);
+ strcpy(state->info->menu, state->info->device_name);
+ }
+ state->info++;
+ if (++state->count >= MAX_CD_INFOS)
+ return false;
+ }
+
+ return true;
+}
+
+/*
* Get a list of all available CD media (not drives!), return
* the number of entries collected.
*/
static int
get_available_cds(void)
{
- 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;
+ struct get_available_cds_state data;
- 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;
+ data.info = cds;
+ data.count = 0;
+
+ enumerate_disks(&data, get_available_cds_helper);
+
+ return data.count;
}
static int
Home |
Main Index |
Thread Index |
Old Index