不確定是否有人在這裏有任何想法,我以前沒有看到過。我正在編寫一個存根來測試我的內核模塊,當我在用戶空間中檢查命令的值時,我得到了一個與我在內核空間中查看時不同的值。存根的Linux ioctl命令在用戶空間和內核空間之間變化
部分:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "ain.h"
#include "ain_ioctl.h"
#define AI_DEVICE "/dev/ain"
void main()
{
int fd, error, ioctl_par = 0;
char* dev;
long ret;
dev = AI_DEVICE;
printf("Starting driver test\n");
fd = open(dev, O_RDWR);
if (fd < 0) {
/* Failed to open -> Print error-message and exit */
printf("%s failed to open, error: %s\n", dev, strerror(errno));
}
printf("Doing the IOCTL now... cmd: %d\n", AIN_IOC_GET_AN0_CONF);
fflush(stdout);
ret = ioctl(fd, AIN_IOC_GET_AN0_CONF, &ioctl_par);
的ain_ioctl.h文件:
內核中的ioctl例程:
int ain_ioctl (struct inode * inodep, struct file * filp, unsigned int cmd, unsigned long arg)
{
printk("In the ain_ioctl function, cmd: %d. type: %d, dir: %d, nr: %d, size: %d\n",
cmd, _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
printk("Testing against command: %d. type: %d, dir: %d, nr: %d, size: %d\n",
AIN_IOC_GET_AN0_CONF, _IOC_TYPE(AIN_IOC_GET_AN0_CONF), _IOC_DIR(AIN_IOC_GET_AN0_CONF),
_IOC_NR(AIN_IOC_GET_AN0_CONF), _IOC_SIZE(AIN_IOC_GET_AN0_CONF));
現在我本來期望相同的輸出在用戶空間打印和內核一樣。在第一組內核中打印到第二組。然而,這不是我所看到的...
輸出:
[email protected]:~> ./a.out
Starting driver test
Doing the IOCTL now... cmd: -2147195602
[email protected]:~> dmesg | tail
[75253.205136] In the ain_ioctl function, cmd: -1078168112. type: 117, dir: 2, nr: 208, size: 16316
[75253.205140] Testing against cmd: -2147195602. type: 101, dir: 2, nr: 46, size: 4
任何人有,爲什麼我的命令行事不同的任何想法,當我通過ioctl命令將其傳遞給內核VS時,我只是通過對它們進行硬編碼來檢查這些值(正如我在打印中所做的那樣)?
當我建立我看到的唯一的警告似乎無關的ioctl調用:
makedepend: warning: ignoring option -Wall
makedepend: warning: ignoring option -Wall
makedepend: warning: ain.c (reading /usr/src/linux/include/linux/compiler-gcc.h), line 94: incomplete include == "#include gcc_header(__GNUC__)"
makedepend: warning: ain.c (reading /usr/src/linux/include/linux/string.h, line 13): cannot find include file "stdarg.h"
感謝。
我不知道ioctl的警告。關於構建選項,我會在原始問題中包含這些選項。 十六進制值爲: 0x8004652e = -2147195602 0xbf9c28e0 = -1078168112 – Mike 2012-08-16 12:56:31