c - 如何使用 ioctl 将负整数作为有效结果返回?

标签 c linux-device-driver kernel-module ioctl

我需要将整数传递给内核模块,在那里计算 sin 并返回结果。

首先,内核有内置的 sin fixp_t fixp_sin(unsigned int degrees) 函数,它返回定点数(可以是负数)。

所以,我的问题是:如果我使用 ioctl 将整数传递给内核模块,计算 sin,我如何返回负结果?

ioctl 将负返回值检测为错误。

最佳答案

I need to pass integer to kernel module, calculate sin there and return result.

不是将整数值传递给 ioctl(),而是可以传递结构。此结构可以具有输入和输出数据字段。无需处理 ioctl() 返回值。

将结构传递给 char 驱动程序的 ioctl() 示例
https://github.com/jeyaramvrp/kernel-module-programming/tree/master/sample-char-dir

关于c - 如何使用 ioctl 将负整数作为有效结果返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35002881/

相关文章:

c - C 编程 Linux 驱动程序中的异或字符串

c - 在 Linux 内核模块中读/写文件

c - 排序数组和唯一数组

Android ndk构建无法构建32位可执行文件

c - C中语句的最大长度

linux - NETLINK_ROUTE channel 可用于将消息从内核模块发送到用户空间程序吗?

debugging - 通过KGDB进行模块调试

connect() 或accept() 的客户端服务器问题

linux-kernel - virtualbox上的内核开发

linux - 如何证明 RS 232 全调制解调器、RS 422 工作 PC 到 PC 和 LOOP BACK