vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / media-add-ons / opensound / OpenSoundDeviceMixer.cpp
blob39cc8390aa8e93cfd01b6d668fdf0d016d3efa53
1 /*
2 * OpenSound media addon for BeOS and Haiku
4 * Copyright (c) 2007, François Revol (revol@free.fr)
5 * Distributed under the terms of the MIT License.
6 */
8 #include "OpenSoundDeviceMixer.h"
9 #include "debug.h"
10 #include "driver_io.h"
11 #include <MediaDefs.h>
12 #include <Debug.h>
13 #include <errno.h>
14 #include <string.h>
16 OpenSoundDeviceMixer::~OpenSoundDeviceMixer()
18 CALLED();
19 if (fFD != 0) {
20 close(fFD);
24 OpenSoundDeviceMixer::OpenSoundDeviceMixer(oss_mixerinfo *info)
26 CALLED();
27 fInitCheckStatus = B_NO_INIT;
28 memcpy(&fMixerInfo, info, sizeof(oss_mixerinfo));
29 fFD = open(info->devnode, O_RDWR);
30 if (fFD < 0) {
31 fInitCheckStatus = errno;
32 return;
34 fInitCheckStatus = B_OK;
38 status_t OpenSoundDeviceMixer::InitCheck(void) const
40 CALLED();
41 return fInitCheckStatus;
44 int OpenSoundDeviceMixer::CountExtInfos()
46 int n;
47 CALLED();
49 // faster way!
50 return Info()->nrext;
52 // -1 doesn't work here (!?)
53 n = Info()->dev;
54 if (ioctl(fFD, SNDCTL_MIX_NREXT, &n, sizeof(int)) < 0) {
55 PRINT(("OpenSoundDeviceMixer::CountExtInfos: SNDCTL_MIX_NREXT: %s\n", strerror(errno)));
56 return 0;
59 return n;
64 status_t OpenSoundDeviceMixer::GetExtInfo(int index, oss_mixext *info)
66 CALLED();
68 if (!info)
69 return EINVAL;
71 // XXX: we should probably cache them as they might change on the fly
73 info->dev = Info()->dev; // this mixer
74 info->ctrl = index;
75 if (ioctl(fFD, SNDCTL_MIX_EXTINFO, info, sizeof(*info)) < 0) {
76 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_EXTINFO(%d): %s\n", __FUNCTION__, index, strerror(errno)));
77 return errno;
80 return B_OK;
84 status_t OpenSoundDeviceMixer::GetMixerValue(oss_mixer_value *value)
86 CALLED();
88 if (!value)
89 return EINVAL;
91 value->dev = Info()->dev; // this mixer
92 // should be set before calling
93 //value->ctrl = index;
94 //value->timestamp =
95 if (ioctl(fFD, SNDCTL_MIX_READ, value, sizeof(*value)) < 0) {
96 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_READ(%d): %s\n", __FUNCTION__, value->ctrl, strerror(errno)));
97 return errno;
100 return B_OK;
104 status_t OpenSoundDeviceMixer::SetMixerValue(oss_mixer_value *value)
106 CALLED();
108 if (!value)
109 return EINVAL;
111 value->dev = Info()->dev; // this mixer
112 // should be set before calling
113 //value->ctrl = index;
114 //value->timestamp =
115 if (ioctl(fFD, SNDCTL_MIX_WRITE, value, sizeof(*value)) < 0) {
116 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_WRITE(%d): %s\n", __FUNCTION__, value->ctrl, strerror(errno)));
117 return errno;
120 return B_OK;
124 status_t OpenSoundDeviceMixer::GetEnumInfo(int index, oss_mixer_enuminfo *info)
126 CALLED();
128 if (!info)
129 return EINVAL;
131 info->dev = Info()->dev; // this mixer
132 info->ctrl = index;
133 if (ioctl(fFD, SNDCTL_MIX_ENUMINFO, info, sizeof(*info)) < 0) {
134 PRINT(("OpenSoundDeviceMixer::%s: SNDCTL_MIX_ENUMINFO(%d): %s\n", __FUNCTION__, index, strerror(errno)));
135 return errno;
138 return B_OK;
142 //update_counter