2.4下内核linux字符驱动模板

linux 字符驱动模板 2.4以下的内核适用。

#include

#include

#include

#include

#include

#include

#include

#define MAJOR_NUM 125

#define DEVICE_NAME "emptychr"

static ssize_t test_read(struct file *file,char *buf,size_t count,loff_t *f_pos)

{

return count;

}

static ssize_t test_write(struct file *file, const char *buf, size_t count, loff_t *f_pos)

{

return count;

}

static int test_open(struct inode *inode,struct file *file )

{

MOD_INC_USE_COUNT;

return 0;

}

static int test_release(struct inode *inode,struct file *file )

{

MOD_DEC_USE_COUNT;

return 0;

}

static int test_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)

{

return 0;

}

struct file_operations test_fops = {

read:test_read,

write:test_write,

open: test_open,

release:test_release,

ioctl:test_ioctl

};

int test_init(void)

{

int result;

result = register_chrdev(MAJOR_NUM, DEVICE_NAME, &test_fops);

if (result < 0) {

printk(KERN_INFO "test: can't get major number\n");

return result;

}

printk("init module\n");

return 0;

}

void test_exit(void)

{

unregister_chrdev(MAJOR_NUM,DEVICE_NAME);

printk("cleanup_module\n");

}

module_init(test_init);

module_exit(test_exit);

MODULE_LICENSE("GPL");

MODULE_AUTHOR("huangxb");

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzwjjj.html