I am trying to compile the code in the 2nd paragraph as a device driver, and I get the following errors. Any ideas why I get this error and how to fix it please?
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,
};
...
This is a sample code for a loadable module. I have already loaded a smaller version of it. This one is supposed to have more functionality. It comes with another file, which is supposed to run from the user space. Any hints on where I can put that code within the project is greatly appreciated.
I found another link about this issue. The problem and the solution are described here I made the modifications they suggested in the above file, but now I get a different error about the updated lines as follows:
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
So I changed the following procedure as follow:
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;
}
@ nsilent - I was up for a very long time and was not thinking clearly. I see now, it only makes sense to change the print type to be the same as the variable you are printing. Thanks for catching the misspelling also.