sound: Implement hw.snd.default_unit sysctl
authorFrançois Tigeot <ftigeot@wolfpond.org>
Thu, 4 Dec 2014 08:29:52 +0000 (09:29 +0100)
committerFrançois Tigeot <ftigeot@wolfpond.org>
Thu, 8 Jan 2015 10:41:02 +0000 (11:41 +0100)
etc/defaults/devfs.conf
sys/dev/sound/pcm/mixer.c
sys/dev/sound/pcm/sound.c
sys/dev/sound/pcm/sound.h

index 749e388..c2e3d17 100644 (file)
@@ -1,5 +1,5 @@
 # Default rules for devfs(5)
 # Add your own rules to /etc/devfs.conf
 
-link   dsp0    dsp
-link   mixer0  mixer
+#link  dsp0    dsp
+#link  mixer0  mixer
index da0e27e..a8501b0 100644 (file)
@@ -727,7 +727,7 @@ mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
 
        unit = device_get_unit(dev);
        devunit = snd_mkunit(unit, SND_DEV_CTL, 0);
-       pdev = make_dev(&mixer_cdevsw, PCMMINOR(devunit),
+       pdev = make_dev(&mixer_cdevsw, PCMMKMINOR(unit,0),
                 UID_ROOT, GID_WHEEL, 0666, "mixer%d", unit);
        pdev->si_drv1 = m;
        snddev->mixer_dev = pdev;
index 755f400..01b3447 100644 (file)
@@ -431,18 +431,29 @@ sysctl_hw_snd_default_unit(SYSCTL_HANDLER_ARGS)
 {
        struct snddev_info *d;
        int error, unit;
+       cdev_t old_d;
 
        unit = snd_unit;
        error = sysctl_handle_int(oidp, &unit, 0, req);
        if (error == 0 && req->newptr != NULL) {
+               if ((old_d = devfs_find_device_by_name("dsp%d", snd_unit)))
+                       destroy_dev_alias(old_d, "dsp");
+               if ((old_d = devfs_find_device_by_name("mixer%d", snd_unit)))
+                       destroy_dev_alias(old_d, "mixer");
                d = devclass_get_softc(pcm_devclass, unit);
                if (!PCM_REGISTERED(d) || CHN_EMPTY(d, channels.pcm))
                        return EINVAL;
+               error = make_dev_alias(d->dsp_clonedev, "dsp");
+               if (error)
+                       goto done;
+               error = make_dev_alias(d->mixer_dev, "mixer");
                snd_unit = unit;
                snd_unit_auto = 0;
        }
+done:
        return (error);
 }
+
 /* XXX: do we need a way to let the user change the default unit? */
 SYSCTL_PROC(_hw_snd, OID_AUTO, default_unit,
            CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
index 54a1ddd..df55812 100644 (file)
@@ -118,6 +118,8 @@ struct snd_mixer;
 /* XXX unit2minor compat */
 #define PCMMINOR(x)            snd_u2unit(x)
 
+#define PCMMKMINOR(u, c)       ((((c) & PCMMAXCHAN) << 16) | ((u) & PCMMAXUNIT))
+
 /*
  * By design, limit possible channels for each direction.
  */