Linux内核使用misc_register函数注册一个混杂设备,使用misc_deregister移除一个混杂设备。注册成功后,linux内核为自动为该设备创建设备节点,在/dev/下会产生相应的节点。

 HAL层

fd = open("/devshf",READONY); //这样open的路径跟kernel中路径一样,就会走到kernel对应的系统调用中了

 

kernel端code:

struct file_operations shf_fops = {

  .owner = THIS_MODULE,

  .open= shf_open,

  .release = shf_release,

  .unlocked_ioctl = shf_unlocked_ioctrl,

}

struct miscdevice shf_device = {

    .minor = MISC_DYNAMIC_MINOR,

    .name = "shf",

    .fops = &shf_fops,

};

misc_regiseter(&shf_device);  //会在/dev下创建shf节点,即/dev/shf

 顺序misc_register(miscdevice)->声明一个misc device,且其中包含fops->声明一个fops,且里面包含open,read,write,unlocked_ioctl的实现

posted on 2018-03-30 20:25  snowdrop  阅读(4258)  评论(0编辑  收藏  举报