Module Name: src Committed By: martin Date: Thu Nov 8 20:29:38 UTC 2018
Modified Files: src/usr.sbin/sysinst: defs.h disks.c util.c Log Message: Adapt other cd-device query functions to new world order, fix default cd device (assume 'a' partition). To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/sysinst/defs.h \ src/usr.sbin/sysinst/disks.c cvs rdiff -u -r1.14 -r1.15 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/defs.h diff -u src/usr.sbin/sysinst/defs.h:1.21 src/usr.sbin/sysinst/defs.h:1.22 --- src/usr.sbin/sysinst/defs.h:1.21 Wed Nov 7 21:20:23 2018 +++ src/usr.sbin/sysinst/defs.h Thu Nov 8 20:29:37 2018 @@ -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 @@ void toplevel(void); /* 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); Index: src/usr.sbin/sysinst/disks.c diff -u src/usr.sbin/sysinst/disks.c:1.21 src/usr.sbin/sysinst/disks.c:1.22 --- src/usr.sbin/sysinst/disks.c:1.21 Thu Nov 8 11:56:56 2018 +++ src/usr.sbin/sysinst/disks.c Thu Nov 8 20:29:37 2018 @@ -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 int fsck_preen(const char *, int, 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 @@ get_default_cdrom_helper(void *state, co { 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 @@ is_ffs_wedge(const char *dev) /* * 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 @@ is_cdrom_device(const char *dev) * 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 }; Index: src/usr.sbin/sysinst/util.c diff -u src/usr.sbin/sysinst/util.c:1.14 src/usr.sbin/sysinst/util.c:1.15 --- src/usr.sbin/sysinst/util.c:1.14 Wed Nov 7 21:20:23 2018 +++ src/usr.sbin/sysinst/util.c Thu Nov 8 20:29:37 2018 @@ -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 @@ get_iso9660_volname(int dev, int sess, c } /* - * Get a list of all available CD media (not drives!), return - * the number of entries collected. + * Local state while iterating CDs and collecting volumes */ -static int -get_available_cds(void) +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) { - static const char *cdrom_devices[] = { CD_NAMES, 0 }; - char dname[16], volname[80], fmt[80], tmp[80], *star; - struct cd_info *info = cds; + struct get_available_cds_state *state = arg; + char dname[16], volname[80]; struct disklabel label; - int i, part, dev, error, sess, ready, count = 0; + int part, dev, error, sess, ready; - 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); - } + 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; - ready = 0; - error = ioctl(dev, DIOCTUR, &ready); - if (error != 0 || ready == 0) { - close(dev); - continue; - } - error = ioctl(dev, DIOCGDINFO, &label); + error = get_iso9660_volname(dev, sess, volname); 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 (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); } - if (++count >= MAX_CD_INFOS) - break; + state->info++; + if (++state->count >= MAX_CD_INFOS) + return false; } - return count; + + return true; +} + +/* + * Get a list of all available CD media (not drives!), return + * the number of entries collected. + */ +static int +get_available_cds(void) +{ + struct get_available_cds_state data; + + data.info = cds; + data.count = 0; + + enumerate_disks(&data, get_available_cds_helper); + + return data.count; } static int