sys文件系统下的接口函数
来源:互联网 发布:孟克鞋搭配 知乎 编辑:程序博客网 时间:2024/05/21 22:49
有很多的文章组合而成:
说到sys接口文件,就不得不说“ DEVICE_ATTR”
在介绍 DEVICE_ATTR之前,先介绍两个函数:
1 ssccanf()函数:
char buf[512] ;
sscanf("123456 ", "%s", buf);//此处buf是数组名,它的意思是将123456以%s的形式存入buf中!
printf("%s\n", buf);
结果为:123456
2 sprintf()函数:
//把整数123 打印成一个字符串保存在s 中。
sprintf(s, "%d", 123); //产生"123"
下面开始正式介绍DEVICE_ATTR:
1 先看两个结构体:
struct attribute {
const char *name;
mode_t mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key *key;
struct lock_class_key skey;
#endif
};
const char *name;
mode_t mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key *key;
struct lock_class_key skey;
#endif
};
/* interface for exporting device attributes */
struct device_attribute {
struct attribute attr;
ssize_t (*show)(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count);
};
struct device_attribute {
struct attribute attr;
ssize_t (*show)(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count);
};
_show表示的是读方法,_stroe表示的是写方法。
DEVICE_ATTR 宏声明有四个参数,分别是名称、权限位、读函数、写函数。其中读函数和写函数是读写功能函数的函数名。
2 在linux内核中分4种attr:
1 BUS_ATTR。
2 DRIVER_ATTR
3 CLASS_ATTR
4 DEVICE_ATTR。
对设备的使用 DEVICE_ATTR ,对总线使用 BUS_ATTR ,对驱动使用 DRIVER_ATTR ,对类别 (class) 使用 CLASS_ATTR, 这四个高级的宏来自于<include/linux/device.h>
3 ATTR的几种属性:
- sys文件系统下的接口函数
- efi的sys文件系统接口
- /sys 文件系统下的目录结构
- cpu topology sys文件系统接口
- 应用程序访问内核的新接口/sys文件系统
- linux驱动层到应用层的重要接口sys文件系统---/sys目录详解
- Android下的两个文件系统:proc和sys(一)
- Android下的两个文件系统:proc和sys(二)
- Android下的两个文件系统:proc和sys(三)
- sys文件系统
- sys文件系统
- Python的sys.argv函数
- Python3的sys模块函数
- sys文件系统总结,,
- 什么是sys文件系统
- proc sys文件系统对比
- proc sys文件系统对比
- Sys文件系统分析
- wireshark插件开发——前期工作
- Android软键盘的一些控制
- 函数传递数组
- Netbeans 逆向工程生成JPA项目---流程图
- Jquery Easyui DataGrid加载本地Json串
- sys文件系统下的接口函数
- Tomcat Too many open files
- java MessageFormat
- MSYS环境下编译VLC
- render yuv on ios
- 【2013.1.25】 为什么C#不支持宏命令
- shell 不转义
- 最近项目中用hibernate分页查询的底层方法
- Widget组件及设计介绍