当前位置: 技术问答>linux和unix
驱动程序编译问题
来源: 互联网 发布时间:2015-05-28
本文导语: 代码如下: #define MODULE #define __KERNEL__ #include #include MODULE_LICENSE("GPL"); int hello_open(struct inode *inode, struct file *filp) { printk("Hello, this is open file devicen"); return 0; } ssize_t hello_write(struct file *filp, const char *bu...
代码如下:
#define MODULE
#define __KERNEL__
#include
#include
MODULE_LICENSE("GPL");
int hello_open(struct inode *inode, struct file *filp)
{
printk("Hello, this is open file devicen");
return 0;
}
ssize_t hello_write(struct file *filp, const char *buf, size_t count,
loff_t *f_pos)
{
printk("Hello, this is write file devicen");
return 0;
}
ssize_t hello_read(struct file *filp, char *buf, size_t count,
loff_t *f_pos)
{
printk("Hello, this is read file devicen");
return 0;
}
int hello_release(struct inode *inode, struct file *filp)
{
printk("Hello, this is release file devicen");
// MOD_DEC_USE_COUNT;
return 0;
}
unsigned int hello_major = 253;
struct file_operations hello_fops={
llseek: scull_llseek,
read: scull_read,
write: scull_write,
ioctl: scull_ioctl,
open: scull_open,
release: scull_release,
}
int init_module(void)
{
printk("Hello, Worldn");
int result, i;
SET_MODULE_OWNER(&hello_fops);
result = register_chrdev(hello_major, "my_hello", &hello_fops);
if (result
#define MODULE
#define __KERNEL__
#include
#include
MODULE_LICENSE("GPL");
int hello_open(struct inode *inode, struct file *filp)
{
printk("Hello, this is open file devicen");
return 0;
}
ssize_t hello_write(struct file *filp, const char *buf, size_t count,
loff_t *f_pos)
{
printk("Hello, this is write file devicen");
return 0;
}
ssize_t hello_read(struct file *filp, char *buf, size_t count,
loff_t *f_pos)
{
printk("Hello, this is read file devicen");
return 0;
}
int hello_release(struct inode *inode, struct file *filp)
{
printk("Hello, this is release file devicen");
// MOD_DEC_USE_COUNT;
return 0;
}
unsigned int hello_major = 253;
struct file_operations hello_fops={
llseek: scull_llseek,
read: scull_read,
write: scull_write,
ioctl: scull_ioctl,
open: scull_open,
release: scull_release,
}
int init_module(void)
{
printk("Hello, Worldn");
int result, i;
SET_MODULE_OWNER(&hello_fops);
result = register_chrdev(hello_major, "my_hello", &hello_fops);
if (result