From a9a17f5fe51498b182d4a11ac48207b8c7ffe8ec Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Tue, 14 Feb 2023 22:55:10 +0900 Subject: [PATCH] Cygwin: dsp: Fix SNDCTL_DSP_GET[IO]SPACE before read()/write(). Even with the commit 3a4c740f59c0, SNDCTL_DSP_GET[IO]SPACE ioctl() does not return the fragment set by SNDCTL_DSP_SETFRAGMENT if it is issued before read()/write(). This patch fixes the issue. Fixes: 3a4c740f59c0 ("Cygwin: dsp: Implement SNDCTL_DSP_SETFRAGMENT ioctl().") Signed-off-by: Takashi Yano --- winsup/cygwin/fhandler/dsp.cc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/fhandler/dsp.cc b/winsup/cygwin/fhandler/dsp.cc index dd1aac8e2..16db6bb29 100644 --- a/winsup/cygwin/fhandler/dsp.cc +++ b/winsup/cygwin/fhandler/dsp.cc @@ -1369,11 +1369,17 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf) return -1; } audio_buf_info *p = (audio_buf_info *) buf; - if (audio_out_) { - audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_); - } else { - Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_); - } + if (audio_out_) + audio_out_->buf_info (p, audiofreq_, audiobits_, audiochannels_); + else if (fragment_has_been_set) + { + p->bytes = fragsize_ * fragstotal_; + p->fragsize = fragsize_; + p->fragstotal = fragstotal_; + p->fragments = fragstotal_; + } + else + Audio_out::default_buf_info(p, audiofreq_, audiobits_, audiochannels_); debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d", buf, p->fragments, p->fragsize, p->bytes); return 0; @@ -1387,11 +1393,17 @@ fhandler_dev_dsp::_ioctl (unsigned int cmd, void *buf) return -1; } audio_buf_info *p = (audio_buf_info *) buf; - if (audio_in_) { - audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_); - } else { - Audio_in::default_buf_info(p, audiofreq_, audiobits_, audiochannels_); - } + if (audio_in_) + audio_in_->buf_info (p, audiofreq_, audiobits_, audiochannels_); + else if (fragment_has_been_set) + { + p->bytes = 0; + p->fragsize = fragsize_; + p->fragstotal = fragstotal_; + p->fragments = 0; + } + else + Audio_in::default_buf_info(p, audiofreq_, audiobits_, audiochannels_); debug_printf ("buf=%p frags=%d fragsize=%d bytes=%d", buf, p->fragments, p->fragsize, p->bytes); return 0;