#include linux/module.h
#include linux/init.h
#include linux/device.h
struct device deviceSY = {
.init_name = "deviceSY",
};
static struct class *char_dev_class;
static int devicesReg_init(void)
{
int ret;
dev_t devno = MKDEV(260,0);
deviceSY.devt = devno; //1.creat "260:0" file in /sys/dev/char/260:0
//2.creat "deviceSY" file in /dev/deviceSY
ret = device_register(&deviceSY);//creat "deviceSY" file in /sys/devices/deviceSY
if (ret)
printk(KERN_NOTICE "Unable to register deviceSY\n");
char_dev_class = class_create(THIS_MODULE,"deviceSY_class");//creat "deviceSY_class" file in /sys/class/deviceSY_class
if (IS_ERR(char_dev_class))
{
printk("Err: failed in creating class.\n");
return 0;
}
return ret;
}
static void devicesReg_exit(void)
{
device_unregister(&deviceSY);
}
MODULE_AUTHOR("SYSMDSY");
MODULE_LICENSE("GPL");
module_init(devicesReg_init);
module_exit(devicesReg_exit);
阅读(1757) | 评论(0) | 转发(0) |