zoukankan      html  css  js  c++  java
  • Linux 内核类设备

    一个类的真正目的是作为一个是该类成员的设备的容器. 一个成员由 struct class_device 来表示:

    struct class_device { struct kobject kobj; struct class *class; struct device *dev; void *class_data;

    char class_id[BUS_ID_SIZE];

    };

    class_id 成员持有设备名子, 如同它在 sysfs 中的一样. class 指针应当指向持有这个 设备的类, 并且 dev 应当指向关联的设备结构. 设置 dev 是可选的; 如果它是非 NULL, 它用来创建一个符号连接从类入口到对应的在 /sys/devices 下的入口, 使得易于在用户 空间找到设备入口. 类可以使用 class_data 来持有一个私有指针.

    通常的注册函数已经被提供:

    int class_device_register(struct class_device *cd); void class_device_unregister(struct class_device *cd);

    类设备接口也允许重命名一个已经注册的入口:

    int class_device_rename(struct class_device *cd, char *new_name); 类设备入口有属性:

    struct class_device_attribute { struct attribute attr;

    ssize_t (*show)(struct class_device *cls, char *buf); ssize_t (*store)(struct class_device *cls, const char *buf, size_t count);

    };

    CLASS_DEVICE_ATTR(name, mode, show, store);

    int class_device_create_file(struct class_device *cls, const struct class_device_attribute

    *attr);

    void class_device_remove_file(struct class_device *cls, const struct class_device_attribute *attr);

    一个缺省的属性集合, 在类的 class_dev_attrs 成员, 被创建当类设备被注册时; class_device_create_file 可用来创建额外的属性. 属性还可以被加入到由 class_simple 接口创建的类设备.

  • 相关阅读:
    有哪些命令行的软件堪称神器?
    [置顶] 《技术大牛养成指南》
    Java 8 集合不完全一览
    [置顶] tcpflow 抓包
    被遗忘的 Logrotate
    [置顶] Every Programmer Should Know These Latency Numbers
    安装 Ubuntu 14.04 之后要做的一些事
    windows.h系统函数
    《葡萄源》
    在 Visual Studio 中创建一个简单的 C# 控制台应用程序
  • 原文地址:https://www.cnblogs.com/fanweisheng/p/11148041.html
Copyright © 2011-2022 走看看