Pokusam som sa napisat jenoduchy "device". Bohuzial mi kompilacia nepresla. Vie mi niekto skusenejsi poradit, kde robim chybu?
Vdaka,
~jay
=====================
/* running kernel-2.6.11-1.14_FC3 */
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "hello"
#define NOTH_LEN 9
char hello_msg[] = "Hello world!";
static int major;
static int hello_open(struct inode *inode, struct file *file)
{
return 0;
}
static int hello_release(struct inode *inode, struct file *file)
{
return 0;
}
static ssize_t hello_read(struct inode *inode, char *user_buf, size_t len, loff_t offset)
{
int bytes = 0;
bytes = copy_to_user(user_buf, hello_msg, len);
if (bytes < 0) {
return -EFAULT;
}
return bytes;
}
static struct file_operations fops = {
read: hello_read,
open: hello_open,
release: hello_release,
};
int __init loading(void)
{
major = register_chrdev(major, DEVICE_NAME, &fops);
if (major < 0) {
return major;
}
return 0;
}
void __exit unloading(void)
{
unregister_chrdev(major, DEVICE_NAME);
}
module_init(loading);
module_exit(unloading);
MODULE_LICENSE("GPL");
=====================
# gcc -c hello.c
hello.c:17: warning: "struct file" declared inside parameter list
hello.c:17: warning: its scope is only this definition or declaration, which is probably not what you want
hello.c:17: warning: "struct inode" declared inside parameter list
hello.c:22: warning: "struct file" declared inside parameter list
hello.c:22: warning: "struct inode" declared inside parameter list
hello.c:27: warning: "struct inode" declared inside parameter list
hello.c:39: error: variable `fops' has initializer but incomplete type
hello.c:40: error: unknown field `read' specified in initializer
hello.c:40: warning: excess elements in struct initializer
hello.c:40: warning: (near initialization for `fops')
hello.c:41: error: unknown field `open' specified in initializer
hello.c:41: warning: excess elements in struct initializer
hello.c:41: warning: (near initialization for `fops')
hello.c:42: error: unknown field `release' specified in initializer
hello.c:42: warning: excess elements in struct initializer
hello.c:42: warning: (near initialization for `fops')
hello.c:39: error: storage size of `fops' isn't known