Re: [PATCH v2 11/17] bsd-user: Add bsd-ioctl.c infrastructure and termios conversion

2026-04-29 Thread Pierrick Bouvier
On 4/29/2026 7:45 AM, Warner Losh wrote:
> Add initial bsd-ioctl.c file with termios conversion functions,
> structure type definitions, and ioctl table infrastructure.
> Includes target_to_host_termios and host_to_target_termios for
> terminal I/O control conversion, along with the ioctl dispatch
> table framework.
> 
> Style complains about STRUCT and STRUCT_SPECIAL defines:
>   ● checkpatch.pl: 197: ERROR: Macros with complex values should be enclosed 
> in parenthesis
>   ● checkpatch.pl: 198: ERROR: Macros with complex values should be enclosed 
> in parenthesis
> but that's fine. We are doing weird things with macros, and it's fine.
> We can't put parens or do while (0) around these since they are table
> building macros for files that are included multiple times.
> 
> Signed-off-by: Stacey D. Son 
> Signed-off-by: Warner Losh 
> Signed-off-by: Sean Bruno 
> Signed-off-by: Kyle Evans 
> ---
>  bsd-user/bsd-ioctl.c | 221 
> +++
>  1 file changed, 221 insertions(+)
> 

Reviewed-by: Pierrick Bouvier 



[PATCH v2 11/17] bsd-user: Add bsd-ioctl.c infrastructure and termios conversion

2026-04-29 Thread Warner Losh
Add initial bsd-ioctl.c file with termios conversion functions,
structure type definitions, and ioctl table infrastructure.
Includes target_to_host_termios and host_to_target_termios for
terminal I/O control conversion, along with the ioctl dispatch
table framework.

Style complains about STRUCT and STRUCT_SPECIAL defines:
  ● checkpatch.pl: 197: ERROR: Macros with complex values should be enclosed in 
parenthesis
  ● checkpatch.pl: 198: ERROR: Macros with complex values should be enclosed in 
parenthesis
but that's fine. We are doing weird things with macros, and it's fine.
We can't put parens or do while (0) around these since they are table
building macros for files that are included multiple times.

Signed-off-by: Stacey D. Son 
Signed-off-by: Warner Losh 
Signed-off-by: Sean Bruno 
Signed-off-by: Kyle Evans 
---
 bsd-user/bsd-ioctl.c | 221 +++
 1 file changed, 221 insertions(+)

diff --git a/bsd-user/bsd-ioctl.c b/bsd-user/bsd-ioctl.c
new file mode 100644
index 00..32fa9c3d33
--- /dev/null
+++ b/bsd-user/bsd-ioctl.c
@@ -0,0 +1,221 @@
+/*
+ * BSD ioctl(2) emulation
+ *
+ * Copyright (c) 2013-2015 Stacey D. Son
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "qemu.h"
+
+#include "syscall_defs.h"
+#include "bsd-ioctl.h"
+#include "os-ioctl-cryptodev.h"
+#include "os-ioctl-disk.h"
+#include "os-ioctl-filio.h"
+#include "os-ioctl-in6_var.h"
+#include "os-ioctl-sockio.h"
+#include "os-ioctl-ttycom.h"
+
+static void target_to_host_termios(void *dst, const void *src)
+{
+struct termios *host = dst;
+const struct target_termios *target = src;
+
+host->c_iflag = target_to_host_bitmask(tswap32(target->c_iflag), 
iflag_tbl);
+host->c_oflag = target_to_host_bitmask(tswap32(target->c_oflag), 
oflag_tbl);
+host->c_cflag = target_to_host_bitmask(tswap32(target->c_cflag), 
cflag_tbl);
+host->c_lflag = target_to_host_bitmask(tswap32(target->c_lflag), 
lflag_tbl);
+
+memset(host->c_cc, 0, sizeof(host->c_cc));
+host->c_cc[VEOF] = target->c_cc[TARGET_VEOF];
+host->c_cc[VEOL] = target->c_cc[TARGET_VEOL];
+#ifdef VEOL2
+host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2];
+#endif
+host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];
+#ifdef VWERASE
+host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE];
+#endif
+host->c_cc[VKILL] = target->c_cc[TARGET_VKILL];
+#ifdef VREPRINT
+host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT];
+#endif
+#ifdef VERASE2
+host->c_cc[VERASE2] = target->c_cc[TARGET_VERASE2];
+#endif
+host->c_cc[VINTR] = target->c_cc[TARGET_VINTR];
+host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT];
+host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP];
+#ifdef VDSUSP
+host->c_cc[VDSUSP] = target->c_cc[TARGET_VDSUSP];
+#endif
+host->c_cc[VSTART] = target->c_cc[TARGET_VSTART];
+host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP];
+#ifdef VLNEXT
+host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT];
+#endif
+#ifdef VDISCARD
+host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD];
+#endif
+host->c_cc[VMIN] = target->c_cc[TARGET_VMIN];
+host->c_cc[VTIME] = target->c_cc[TARGET_VTIME];
+#ifdef VSTATUS
+host->c_cc[VSTATUS] = target->c_cc[TARGET_VSTATUS];
+#endif
+
+host->c_ispeed = tswap32(target->c_ispeed);
+host->c_ospeed = tswap32(target->c_ospeed);
+}
+
+static void host_to_target_termios(void *dst, const void *src)
+{
+struct target_termios *target = dst;
+const struct termios *host = src;
+
+target->c_iflag = tswap32(host_to_target_bitmask(host->c_iflag, 
iflag_tbl));
+target->c_oflag = tswap32(host_to_target_bitmask(host->c_oflag, 
oflag_tbl));
+target->c_cflag = tswap32(host_to_target_bitmask(host->c_cflag, 
cflag_tbl));
+target->c_lflag = tswap32(host_to_target_bitmask(host->c_lflag, 
lflag_tbl));
+
+memset(target->c_cc, 0, sizeof(target->c_cc));
+target->c_cc[TARGET_VEOF] = host->c_cc[VEOF];
+target->c_cc[TARGET_VEOL] = host->c_cc[VEOL];
+#ifdef VEOL2
+target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2];
+#endif
+target->c_cc[TARGET_VERASE] = host->c_cc[VERASE];
+#ifdef VWERASE
+target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE];
+#endif
+target->c_cc[TARGET_VKILL] = host->c_cc[VKILL];
+#ifdef VREPRINT
+target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT];
+#endif
+#ifdef VERASE2
+target->c_cc[TARGET_VERASE2] = host->c_cc[VERASE2];
+#endif
+target->c_cc[TARGET_VINTR] = host->c_cc[VINTR];
+target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT];
+target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP];
+#ifdef VDSUSP
+target->c_cc[TARGET_VDSUSP] =