From 0df63e44c3e315ec0fe427ae62558231864108bd Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 28 Apr 2006 15:13:41 +0200 Subject: [ALSA] Add O_APPEND flag support to PCM Added O_APPEND flag support to PCM to enable shared substreams among multiple processes. This mechanism is used by dmix and dsnoop plugins. Signed-off-by: Takashi Iwai --- sound/core/pcm.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'sound/core/pcm.c') diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 4f5204175d37..8136be2e6066 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -829,6 +829,26 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, return -EINVAL; } + if (file->f_flags & O_APPEND) { + if (prefer_subdevice < 0) { + if (pstr->substream_count > 1) + return -EINVAL; /* must be unique */ + substream = pstr->substream; + } else { + for (substream = pstr->substream; substream; + substream = substream->next) + if (substream->number == prefer_subdevice) + break; + } + if (! substream) + return -ENODEV; + if (! SUBSTREAM_BUSY(substream)) + return -EBADFD; + substream->ref_count++; + *rsubstream = substream; + return 0; + } + if (prefer_subdevice >= 0) { for (substream = pstr->substream; substream; substream = substream->next) if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice) @@ -873,7 +893,8 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, substream->runtime = runtime; substream->private_data = pcm->private_data; - substream->ffile = file; + substream->ref_count = 1; + substream->f_flags = file->f_flags; pstr->substream_opened++; *rsubstream = substream; return 0; @@ -882,7 +903,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, void snd_pcm_detach_substream(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; - substream->file = NULL; + runtime = substream->runtime; snd_assert(runtime != NULL, return); if (runtime->private_free != NULL) -- cgit v1.2.3