Module Name:    src
Committed By:   nat
Date:           Tue Mar 21 07:04:30 UTC 2017

Modified Files:
        src/share/man/man4: audio.4
        src/sys/dev: audio.c
        src/sys/sys: audioio.h
        src/usr.bin/audio/ctl: ctl.c

Log Message:
Renane ioctl AUDIO_SETPROC to AUDIO_SETCHAN.

Add an ioctl to return channel number (AUDIO_GETCHAN). This can be used
on audio/sound/audioctl devices.

Return EIO in read/write/ioctl/poll/stat if fp has been closed or is
invalid.

Update audio.4, audioio.h and audioctl(1) to reflect these changes.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/share/man/man4/audio.4
cvs rdiff -u -r1.316 -r1.317 src/sys/dev/audio.c
cvs rdiff -u -r1.36 -r1.37 src/sys/sys/audioio.h
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/audio/ctl/ctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.75 src/share/man/man4/audio.4:1.76
--- src/share/man/man4/audio.4:1.75	Sun Feb 12 14:44:20 2017
+++ src/share/man/man4/audio.4	Tue Mar 21 07:04:29 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.75 2017/02/12 14:44:20 wiz Exp $
+.\"	$NetBSD: audio.4,v 1.76 2017/03/21 07:04:29 nat Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -245,7 +245,9 @@ The following
 commands are supported on the sample devices:
 .Pp
 .Bl -tag -width indent
-.It Dv AUDIO_SETPROC (int)
+.It Dv AUDIO_GETCHAN (int)
+This command will return the audio channel in use.
+.It Dv AUDIO_SETCHAN (int)
 This command will select the audio channel for subsequent ioctl calls.
 .It Dv AUDIO_FLUSH
 This command stops all playback and recording, clears all queued

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.316 src/sys/dev/audio.c:1.317
--- src/sys/dev/audio.c:1.316	Mon Mar 20 22:42:39 2017
+++ src/sys/dev/audio.c	Tue Mar 21 07:04:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.316 2017/03/20 22:42:39 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.317 2017/03/21 07:04:29 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.316 2017/03/20 22:42:39 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.317 2017/03/21 07:04:29 nat Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -1525,6 +1525,8 @@ audio_waitio(struct audio_softc *sc, kco
 
 	found = false;
 	SIMPLEQ_FOREACH(vchan, &sc->sc_audiochan, entries) {
+		if (vchan == SIMPLEQ_FIRST(&sc->sc_audiochan))
+			continue;
 		if (vchan->vc == vc) {
 			found = true;
 			break;
@@ -1660,6 +1662,9 @@ audioread(struct file *fp, off_t *offp, 
 	int error;
 	dev_t dev;
 
+	if (fp->f_audioctx == NULL)
+		return EIO;
+
 	dev = fp->f_audioctx->dev;
 
 	if ((error = audio_enter(dev, RW_READER, &sc)) != 0)
@@ -1693,6 +1698,9 @@ audiowrite(struct file *fp, off_t *offp,
 	int error;
 	dev_t dev;
 
+	if (fp->f_audioctx == NULL)
+		return EIO;
+
 	dev = fp->f_audioctx->dev;
 
 	if ((error = audio_enter(dev, RW_READER, &sc)) != 0)
@@ -1727,6 +1735,9 @@ audioioctl(struct file *fp, u_long cmd, 
 	krw_t rw;
 	dev_t dev;
 
+	if (fp->f_audioctx == NULL)
+		return EIO;
+
 	chan = fp->f_audioctx;
 	dev = chan->dev;
 
@@ -1773,6 +1784,9 @@ audioioctl(struct file *fp, u_long cmd, 
 static int
 audiostat(struct file *fp, struct stat *st)
 {
+	if (fp->f_audioctx == NULL)
+		return EIO;
+
 	memset(st, 0, sizeof(*st));
 
 	st->st_dev = fp->f_audioctx->dev;
@@ -1792,6 +1806,9 @@ audiopoll(struct file *fp, int events)
 	int revents;
 	dev_t dev;
 
+	if (fp->f_audioctx == NULL)
+		return EIO;
+
 	dev = fp->f_audioctx->dev;
 
 	/* Don't bother with device level lock here. */
@@ -2947,6 +2964,8 @@ audio_ioctl(dev_t dev, struct audio_soft
 	KASSERT(mutex_owned(sc->sc_lock));
 
 	SIMPLEQ_FOREACH(pchan, &sc->sc_audiochan, entries) {
+		if (pchan == SIMPLEQ_FIRST(&sc->sc_audiochan))
+			continue;
 		if (pchan->chan == chan->deschan)
 			break;
 	}
@@ -2962,7 +2981,11 @@ audio_ioctl(dev_t dev, struct audio_soft
 		return ENXIO;
 	error = 0;
 	switch (cmd) {
-	case AUDIO_SETPROC:
+	case AUDIO_GETCHAN:
+		if ((int *)addr != NULL)
+			*(int*)addr = chan->chan;
+		break;
+	case AUDIO_SETCHAN:
 		if ((int *)addr != NULL && *(int*)addr > 0)
 			chan->deschan = *(int*)addr;
 		break;

Index: src/sys/sys/audioio.h
diff -u src/sys/sys/audioio.h:1.36 src/sys/sys/audioio.h:1.37
--- src/sys/sys/audioio.h:1.36	Fri Feb 10 19:31:42 2017
+++ src/sys/sys/audioio.h	Tue Mar 21 07:04:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audioio.h,v 1.36 2017/02/10 19:31:42 nat Exp $	*/
+/*	$NetBSD: audioio.h,v 1.37 2017/03/21 07:04:29 nat Exp $	*/
 
 /*
  * Copyright (c) 1991-1993 Regents of the University of California.
@@ -191,7 +191,8 @@ typedef struct audio_encoding {
 #define  AUDIO_PROP_PLAYBACK	0x10
 #define  AUDIO_PROP_CAPTURE	0x20
 #define AUDIO_GETBUFINFO	_IOR('A', 35, struct audio_info)
-#define AUDIO_SETPROC	_IOW('A', 36, int)
+#define AUDIO_SETCHAN	_IOW('A', 36, int)
+#define AUDIO_GETCHAN	_IOR('A', 37, int)
 
 /*
  * Mixer device

Index: src/usr.bin/audio/ctl/ctl.c
diff -u src/usr.bin/audio/ctl/ctl.c:1.42 src/usr.bin/audio/ctl/ctl.c:1.43
--- src/usr.bin/audio/ctl/ctl.c:1.42	Fri Feb 10 19:31:42 2017
+++ src/usr.bin/audio/ctl/ctl.c	Tue Mar 21 07:04:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ctl.c,v 1.42 2017/02/10 19:31:42 nat Exp $	*/
+/*	$NetBSD: ctl.c,v 1.43 2017/03/21 07:04:29 nat Exp $	*/
 
 /*
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: ctl.c,v 1.42 2017/02/10 19:31:42 nat Exp $");
+__RCSID("$NetBSD: ctl.c,v 1.43 2017/03/21 07:04:29 nat Exp $");
 #endif
 
 
@@ -291,8 +291,8 @@ getinfo(int fd)
 {
 	int pos, i;
 
-	if (channel >= 0 && ioctl(fd, AUDIO_SETPROC, &channel) < 0)
-		err(1, "AUDIO_SETPROC");
+	if (channel >= 0 && ioctl(fd, AUDIO_SETCHAN, &channel) < 0)
+		err(1, "AUDIO_SETCHAN");
 
 	if (ioctl(fd, AUDIO_GETDEV, &adev) < 0)
 		err(1, "AUDIO_GETDEV");
@@ -440,8 +440,8 @@ audioctl_write(int fd, int argc, char *a
 {
 	struct field *p;
 
-	if (channel >= 0 && ioctl(fd, AUDIO_SETPROC, &channel) < 0)
-		err(1, "AUDIO_SETPROC");
+	if (channel >= 0 && ioctl(fd, AUDIO_SETCHAN, &channel) < 0)
+		err(1, "AUDIO_SETCHAN");
 
 	AUDIO_INITINFO(&info);
 	while (argc--) {

Reply via email to