0
我想編譯第二段中的代碼作爲設備驅動程序,並且出現以下錯誤。任何想法,爲什麼我得到這個錯誤,以及如何解決它?如何修復針對Android三星Note 3手機的嵌入式設備驅動程序的C代碼中的指針錯誤?
drivers/char/tbt/tbt.c:61:1: error: unknown field 'ioctl' specified in initializer
drivers/char/tbt/tbt.c:61:1: warning: initialization from incompatible pointer type [enabled by default]
#include <linux/module.h>
#include <linux/fs.h>
#define HELLO_MAJOR 234
static int debug_enable = 0;
module_param(debug_enable, int, 0);
MODULE_PARM_DESC(debug_enable, "Enable module debug mode.");
struct file_operations hello_fops;
static int hello_open(struct inode *inode, struct file *file)
{
printk("hello_open: successful\n");
return 0;
}
static int hello_release(struct inode *inode, struct file *file)
{
printk("hello_release: successful\n");
return 0;
}
static ssize_t hello_read(struct file *file, char *buf, size_t count,
loff_t *ptr)
{
printk("hello_read: returning zero bytes\n");
return 0;
}
static ssize_t hello_write(struct file *file, const char *buf,
size_t count, loff_t * ppos)
{
printk("hello_read: accepting zero bytes\n");
return 0;
}
static long hello_ioctl(struct file *filep,
unsigned int cmd, unsigned long arg)
{
printk("hello_ioctl: cmd=%ld, arg=%ld\n", cmd, arg);
return 0;
}
static int __init hello_init(void)
{
int ret;
printk("Hello Example Init - debug mode is %s\n",
debug_enable ? "enabled" : "disabled");
ret = register_chrdev(HELLO_MAJOR, "hello1", &hello_fops);
if (ret < 0) {
printk("Error registering hello device\n");
goto hello_fail1;
}
printk("Hello: registered module successfully!\n");
/* Init processing here... */
return 0;
hello_fail1:
return ret;
}
static void __exit hello_exit(void)
{
printk("Hello Example Exit\n");
}
struct file_operations hello_fops = {
owner: THIS_MODULE,
read: hello_read,
write: hello_write,
unloced_ioctl: hello_ioctl,
open: hello_open,
release: hello_release,
};
...
這是可加載模塊的示例代碼。我已經加載了它的較小版本。這個應該有更多的功能。它附帶了另一個文件,該文件應該從用戶空間運行。任何提示,我可以把該代碼放在項目中的地方,我非常感謝。
我發現了另一個關於這個問題的鏈接。的問題和解決方案描述here我做了他們在上述文件中建議的修改,但現在我得到一個不同的錯誤有關更新的線路如下:
drivers/char/tos/tos.c:34:1: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'unsigned int' [-Wformat]
error, forbidden warning: tbt.c:34
make[3]: *** [drivers/char/tbt/tbt.o] Error 1
make[2]: *** [drivers/char/tbt] Error 2
make[1]: *** [drivers/char] Error 2
make: *** [drivers] Error 2
所以我改變了下面的步驟如下:
static long hello_ioctl(struct file *filep,
unsigned long cmd, unsigned long arg)
{
printk("hello_ioctl: cmd=%ld, arg=%ld\n", cmd, arg);
return 0;
}
您應該將'%ld'改爲'%u',而不是改變函數的原型。另外我相信應該有「unloc ** k ** ed」而不是「unloced」ioctl。 – nsilent22