Deleted Added
sdiff udiff text old ( 170289 ) new ( 170815 )
full compact
1/*-
2 * Copyright (c) 2001 Cameron Grant <cg@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <dev/sound/pcm/sound.h>
28#include <dev/sound/pcm/vchan.h>
29#ifdef USING_MUTEX
30#include <sys/sx.h>
31#endif
32
33SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/sndstat.c 170289 2007-06-04 18:25:08Z dwmalone $");
34
35#define SS_TYPE_MODULE 0
36#define SS_TYPE_FIRST 1
37#define SS_TYPE_PCM 1
38#define SS_TYPE_MIDI 2
39#define SS_TYPE_SEQUENCER 3
40#define SS_TYPE_LAST 3
41
42static d_open_t sndstat_open;
43static d_close_t sndstat_close;
44static d_read_t sndstat_read;
45
46static struct cdevsw sndstat_cdevsw = {
47 .d_version = D_VERSION,
48 .d_flags = D_NEEDGIANT,
49 .d_open = sndstat_open,
50 .d_close = sndstat_close,
51 .d_read = sndstat_read,
52 .d_name = "sndstat",
53};
54
55struct sndstat_entry {
56 SLIST_ENTRY(sndstat_entry) link;

--- 75 unchanged lines hidden (view full) ---

132 return error;
133}
134SYSCTL_PROC(_hw_snd, OID_AUTO, verbose, CTLTYPE_INT | CTLFLAG_RW,
135 0, sizeof(int), sysctl_hw_sndverbose, "I", "verbosity level");
136
137static int
138sndstat_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
139{
140 int error;
141
142 if (sndstat_dev == NULL || i_dev != sndstat_dev)
143 return EBADF;
144
145 mtx_lock(&sndstat_lock);
146 if (SNDSTAT_PID(i_dev) != 0) {
147 mtx_unlock(&sndstat_lock);
148 return EBUSY;
149 }
150 SNDSTAT_PID_SET(i_dev, td->td_proc->p_pid);
151 mtx_unlock(&sndstat_lock);
152 if (sbuf_new(&sndstat_sbuf, NULL, 4096, SBUF_AUTOEXTEND) == NULL) {
153 error = ENXIO;
154 goto out;
155 }
156 sndstat_bufptr = 0;
157 error = (sndstat_prepare(&sndstat_sbuf) > 0) ? 0 : ENOMEM;
158out:
159 if (error) {
160 mtx_lock(&sndstat_lock);
161 SNDSTAT_FLUSH();
162 SNDSTAT_PID_SET(i_dev, 0);
163 mtx_unlock(&sndstat_lock);
164 }
165 return (error);
166}
167
168static int
169sndstat_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
170{
171 if (sndstat_dev == NULL || i_dev != sndstat_dev)
172 return EBADF;
173

--- 22 unchanged lines hidden (view full) ---

196 mtx_lock(&sndstat_lock);
197 if (SNDSTAT_PID(i_dev) != buf->uio_td->td_proc->p_pid ||
198 sndstat_bufptr == -1) {
199 mtx_unlock(&sndstat_lock);
200 return EBADF;
201 }
202 mtx_unlock(&sndstat_lock);
203
204 l = min(buf->uio_resid, sbuf_len(&sndstat_sbuf) - sndstat_bufptr);
205 err = (l > 0)? uiomove(sbuf_data(&sndstat_sbuf) + sndstat_bufptr, l, buf) : 0;
206 sndstat_bufptr += l;
207
208 return err;
209}
210
211/************************************************************************/

--- 131 unchanged lines hidden (view full) ---

343}
344
345/************************************************************************/
346
347static int
348sndstat_prepare(struct sbuf *s)
349{
350 struct sndstat_entry *ent;
351 int i, j;
352
353 sbuf_printf(s, "FreeBSD Audio Driver (newpcm: %ubit)\n",
354 (unsigned int)sizeof(intpcm_t) << 3);
355 if (SLIST_EMPTY(&sndstat_devlist)) {
356 sbuf_printf(s, "No devices installed.\n");
357 sbuf_finish(s);
358 return sbuf_len(s);
359 }
360
361 sbuf_printf(s, "Installed devices:\n");
362
363 for (i = 0; i <= sndstat_maxunit; i++) {
364 for (j = SS_TYPE_FIRST; j <= SS_TYPE_LAST; j++) {
365 ent = sndstat_find(j, i);
366 if (!ent)
367 continue;
368 sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
369 sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
370 sbuf_printf(s, " %s", ent->str);
371 if (ent->handler)
372 ent->handler(s, ent->dev, snd_verbose);
373 else
374 sbuf_printf(s, " [no handler]");
375 sbuf_printf(s, "\n");
376 }
377 }
378
379 if (snd_verbose >= 3 && sndstat_files > 0) {
380 sbuf_printf(s, "\nFile Versions:\n");
381
382 SLIST_FOREACH(ent, &sndstat_devlist, link) {
383 if (ent->dev == NULL && ent->str != NULL)

--- 59 unchanged lines hidden ---