zoukankan      html  css  js  c++  java
  • scull 中的设备注册

    在内部, scull 使用一个 struct scull_dev 类型的结构表示每个设备. 这个结构定义为:

    struct scull_dev {

    struct scull_qset *data;  /* Pointer to first quantum set */ int quantum;              /* the current quantum size */

    int qset;  /* the current array size */

    unsigned long size;  /* amount of data stored here */

    unsigned int access_key;  /* used by sculluid and scullpriv */ struct semaphore sem;         /* mutual exclusion semaphore  */ struct cdev cdev; /* Char device structure */

    };

    我们在遇到它们时讨论结构中的各个成员, 但是现在, 我们关注于 cdev, 我们的设备与内 核接口的 struct cdev. 这个结构必须初始化并且如上所述添加到系统中; 处理这个任务 的 scull 代码是:

    static void scull_setup_cdev(struct scull_dev *dev, int index)

    {

    int err, devno = MKDEV(scull_major, scull_minor + index);

    cdev_init(&dev->cdev, &scull_fops); dev->cdev.owner = THIS_MODULE;

    dev->cdev.ops = &scull_fops;

    err = cdev_add (&dev->cdev, devno, 1);

    /* Fail gracefully if need be */ if (err)

    printk(KERN_NOTICE "Error %d adding scull%d", err, index);

    }

    因为 cdev 结构嵌在 struct scull_dev 里面, cdev_init 必须调用来进行那个结构的初 始化.

  • 相关阅读:
    梦断代码读后感一
    二阶段之五
    二柱子阶段二
    动手动脑
    二柱子
    开学测试
    jdk的安装
    软工人8月30日学习记录
    软工人8月29日学习记录
    软工人8月28日学习记录
  • 原文地址:https://www.cnblogs.com/fanweisheng/p/11106330.html
Copyright © 2011-2022 走看看