From e6bd9fd7dabb198638fef56c8c03b983286918c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= <josef.soentgen@genode-labs.com>
Date: Thu, 30 Sep 2021 18:15:21 +0200
Subject: [PATCH] libc: implement SNDCTL_DSP_GETFMTS ioctl

This I/O control is used to query the audio format, e.g. AFMT_S16_LE
in our case.

Fixes #4276.
---
 repos/libports/src/lib/libc/vfs_plugin.cc | 26 +++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/repos/libports/src/lib/libc/vfs_plugin.cc b/repos/libports/src/lib/libc/vfs_plugin.cc
index 3301c8100f..c93b6d2920 100644
--- a/repos/libports/src/lib/libc/vfs_plugin.cc
+++ b/repos/libports/src/lib/libc/vfs_plugin.cc
@@ -1308,6 +1308,31 @@ Libc::Vfs_plugin::_ioctl_sndctl(File_descriptor *fd, unsigned long request, char
 
 		handled = true;
 
+	} else if (request == SNDCTL_DSP_GETFMTS) {
+
+		if (!argp) return { true, EINVAL };
+
+		monitor().monitor([&] {
+			_with_info(*fd, [&] (Xml_node info) {
+				if (info.type() != "oss") {
+					return;
+				}
+
+				unsigned int const format =
+					info.attribute_value("format", 0U);
+				if (format == 0U) {
+					result = EINVAL;
+					return;
+				}
+
+				*(int *)argp = format;
+
+				handled = true;
+			});
+
+			return Fn::COMPLETE;
+		});
+
 	} else if (request == SNDCTL_DSP_GETISPACE) {
 
 		if (!argp) return { true, EINVAL };
@@ -1638,6 +1663,7 @@ int Libc::Vfs_plugin::ioctl(File_descriptor *fd, unsigned long request, char *ar
 	case SNDCTL_DSP_CHANNELS:
 	case SNDCTL_DSP_CURRENT_OPTR:
 	case SNDCTL_DSP_GETERROR:
+	case SNDCTL_DSP_GETFMTS:
 	case SNDCTL_DSP_GETISPACE:
 	case SNDCTL_DSP_GETOPTR:
 	case SNDCTL_DSP_GETOSPACE: