static inline int register_chrdev(unsigned int major, const char *name,
const struct file_operations *fops)
{
return __register_chrdev(major, 0, 256, name, fops);
}
static inline void unregister_chrdev(unsigned int major, const char *name)
{
__unregister_chrdev(major, 0, 256, name);
}
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/cdev.h>
#include <linux/init.h>
#include <linux/kdev_t.h>
static int magor = 230;
static int hello_open(struct inode *inode, struct file *file)
{
printk("hello_open \\n");
return 0;
}
static int hello_release(struct inode *inode, struct file *file)
{
printk("hello_release \\n");
return 0;
}
static struct file_operations fops = {
.open = hello_open,
.release = hello_release,
};
static int hello_init(void)
{
int ret;
printk("hello_init() \\n");
ret = register_chrdev(major, "hello_test", &fops);
if(ret < 0)
{
printk("register_chrdev() file\\n");
return ret;
}
return 0;
}
static void hello_exit(void)
{
printk("hello_exit() \\n");
unregister_chrdev(major, "hello_test");
return ;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
mknod /dev/hello_test c 230 0