1、device中建立属性文件

(1)函数调用关系:

/**************************************************************/

device_create_file

sysfs_create_file

/*************************************************************/

(2)相关的数据结构:

 struct attribute {
const char *name; // 属性文件的名字
struct module *owner; // 属性文件的所有者
mode_t mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key *key;
struct lock_class_key skey;
#endif
};
 struct device_attribute {
struct attribute attr; // 内置的attribute 结构体
ssize_t (*show)(struct device *dev, struct device_attribute *attr, // 属性文件的show方法(也就是读)
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr, // 属性文件的store方法(也就是写)
const char *buf, size_t count);
};

(3) 相关的宏定义

/**************************************************************/

#define DEVICE_ATTR(_name, _mode, _show, _store)   \

struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)

#define __ATTR(_name,_mode,_show,_store) { \

.attr = {.name = __stringify(_name), .mode = _mode }, \

.show = _show,

.store = _store,

/*************************************************************/

由此可知这个宏定义就是定义了一个 device_attribute 类型的变量并进行了初始化。

总结:我们如果需要给device添加属性文件,那么我们可以通过device_create_file函数去添加,我们需要提供相应的device属性文件描述信息,

也就是一个device_attribute 结构体变量。

2、class建立属性文件

(1)函数调用关系

/**********************************************************/

class_create_file

sysfs_create_file

/***********************************************************/

(2)相关的数据结构

 struct class_attribute {
struct attribute attr; // 内置的 attribute 结构体变量
ssize_t (*show)(struct class *class, struct class_attribute *attr, // 属性文件的show操作方法
char *buf);
ssize_t (*store)(struct class *class, struct class_attribute *attr, // 属性文件的store操作方法
const char *buf, size_t count);
};

(3)相关的宏定义

/******************************************************************************/

#define CLASS_ATTR(_name, _mode, _show, _store) \

struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)

/******************************************************************************/

3、bus建立属性文件

(1)函数调用关系

/**********************************************************/

bus_create_file

sysfs_create_file

/*********************************************************/

(2)相关的数据结构

 struct bus_attribute {
struct attribute attr;
ssize_t (*show)(struct bus_type *bus, char *buf);
ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
};

(3)相关的宏定义

#define BUS_ATTR(_name, _mode, _show, _store) \

struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)

4、一次建立多个属性文件的方法

上面说的那些函数一次只能建立一个属性文件,其实在内核中还提供了另一个可以一次建立多个属性文件的函数,所以既然是建立多个,那么我们肯定是需要提供相应的数组。

(1)一次建立多个device属性

static int device_add_attributes(struct device *dev, struct device_attribute *attrs)

(2)一次建立多个bus属性文件

static int device_add_attrs(struct bus_type *bus, struct device *dev)

/*************************************************************************************/

sysfs中属性文件的建立的更多相关文章

  1. Spring中属性文件properties的读取与使用

    实际项目中,通常将一些可配置的定制信息放到属性文件中(如数据库连接信息,邮件发送配置信息等),便于统一配置管理.例中将需配置的属性信息放在属性文件/WEB-INF/configInfo.propert ...

  2. JAVA 中加载属性文件的4种方法

    小总结 : 这个集合属性可以反序列化, 把持久化数据读出来, 输入流中放入要操作的文件! p.load加载这个输入流! p.getProperty( key) 根据这个键获得值! 补充 : web工程 ...

  3. Spring的属性文件properties使用注意

    Spring的属性文件properties使用注意 Spring 中属性文件的配置 通常我们会使用properties文件来设置一些属性,如数据库连接信息,避免进行硬编码, <bean clas ...

  4. JDBC程序优化--提取配置信息放到属性文件中

    JDBC程序优化--提取配置信息放到属性文件中 此处仅仅优化JDBC连接部分,代码如下: public class ConnectionFactory { private static String ...

  5. Spring基础—— 在 Spring Config 中使用外部属性文件

    一.在 Spring Config 文件中配置 Bean 时,有时候需要在 Bean 的配置里添加 系统部署的细节信息, 如文件路径,数据源配置信息.而这些部署细节实际上需要在配置文件外部来定义. 二 ...

  6. Spring中使用属性文件properties的两种方式

    实际项目中,通常将可配置的参数放到属性文件中,例如数据库连接信息.redis连接信息等,便于统一管理.然后通过IoC框架spring将其加载到上下文中,使得程序可以直接使用. 创建mysql.prop ...

  7. Java - 得到项目中properties属性文件中定义的属性值

    public static String getPropertiesValue(String fileName, String key) {   return ResourceBundle.getBu ...

  8. Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可。

    Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可.

  9. Spring依赖注入的方式、类型、Bean的作用域、自动注入、在Spring配置文件中引入属性文件

    1.Spring依赖注入的方式 通过set方法完成依赖注入 通过构造方法完成依赖注入 2.依赖注入的类型 基本数据类型和字符串 使用value属性 如果是指向另一个对象的引入 使用ref属性 User ...

随机推荐

  1. Codeforces Round #526 (Div. 2) Solution

    A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define ...

  2. Java IO的Reactor模式

    1.    Reactor出现的原因 Reator模式是大多数IO相关组件如Netty.Redis在使用时的IO模式,为什么需要这种模式,如何设计来解决高性能并发的呢? 最最原始的网络编程思路就是服务 ...

  3. KALI视频学习31-35

    (三十一)Kali漏洞利用之SET Social Enginnering Toolkit(SET)是一个开源.Python驱动的社会工程学渗透测试工具,提供了非常丰富的攻击向量库.是开源的社会工程学套 ...

  4. UVA 11019 Matrix Matcher(二维hash + 尺取)题解

    题意:在n*m方格中找有几个x*y矩阵. 思路:二维hash,总体思路和一维差不太多,先把每行hash,变成一维的数组,再对这个一维数组hash变成二维hash.之前还在想怎么快速把一个矩阵的hash ...

  5. reason: image not found的解决方案

    在制作framework时遇到真机运行时导致的reason: image not found允许崩溃的问题,下面是我的解决方案: 首先我们分析一下出现这种情况的原因,原因就是framework找不到镜 ...

  6. Spring boot错误处理以及定制错误页面

    如果是浏览器访问,返回错误页面 注意浏览器发送请求的请求头:  注意区别其他客户端哦比如 postman 如果是其他客户端,返回一个Json数据 原理可以参照ErrorMvcAutoConfigura ...

  7. Python学习札记(二十八) 模块1

    参考:模块 NOTE 1.模块:一个.py文件称为一个模块. 2.代码模块化的意义:a.提升程序的可维护性 b.不用重复造轮子 3.避免模块冲突,解决方法:引入了按目录来组织模块的方法,称为包(Pac ...

  8. shell脚本监控Linux系统性能指标

    2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...

  9. eclipse下maven springMVC 整合 mybatis

    参考文档:http://blog.csdn.net/zhshulin/article/details/37956105   1.搭建maven工程,具体参见我另一篇博客:http://www.cnbl ...

  10. Undertow,Tomcat和Jetty服务器配置详解与性能测试

    undertow,jetty和tomcat可以说是javaweb项目当下最火的三款服务器,tomcat是apache下的一款重量级的服务器,不用多说历史悠久,经得起实践的考验.然而:当下微服务兴起,s ...