匿名
未登录
登录
百问网嵌入式Linux wiki
搜索
查看“How to access information in sysfs”的源代码
来自百问网嵌入式Linux wiki
名字空间
页面
讨论
更多
更多
页面选项
Read
查看源代码
历史
←
如何在sysfs中访问信息
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{DISPLAYTITLE:如何在sysfs中访问信息}} == Article purpose == This article provides some information about the sysfs pseudo filesystem usage from the user space. == Sysfs (/sys) pseudo filesystem == Sysfs provides a mean to export kernel data structures, their attributes, and the linkages between them to the user space. Please refer to [[Pseudo filesystem#sysfs (/sys) - System filesystem|sysfs part]] of [[Pseudo filesystem|pseudo filesystem]] page. == Sysfs usage == Linux kernel provides a documentation<ref>{{CodeSource | Linux kernel | Documentation/admin-guide/sysfs-rules.rst}}</ref> about the rules for sysfs usage. Some examples are also described below with two different approaches for using sysfs entries from the user space: * Linux application in C language * bash script. === Example from Linux application === The below example is a typical sequence for using sysfs entry (here a PWM component): * open a file descriptor of the sysfs entry file <syntaxhighlight lang="c" line start="10"> len=snprintf(buf, sizeof(buf), "/sys/class/pwm/pwmchip0/pwm%d/duty_cycle", pwm_channel); fd = open(buf, O_RDWR); </syntaxhighlight> *if fd is correctly opened, write/read value in the file: pay attention to the "text" format <syntaxhighlight lang="c" line start="12"> if (fd < 0) { perror("pwm/duty_cycle"); return fd; } </syntaxhighlight> :*read: store data to buffer <syntaxhighlight lang="c" line start="18"> read(fd, buf, sizeof(buf)); </syntaxhighlight> :*write: write data from buffer <syntaxhighlight lang="c" line start="20"> len = snprintf(buf, sizeof(buf), "%d", 900000); write(fd, buf, len); </syntaxhighlight> * close file descriptor <syntaxhighlight lang="c" line start="30"> close(fd); </syntaxhighlight> === Example for shell command / bash script === Operations on sysfs entries can be done by using command lines (i.e. ''echo'' for writing, ''cat'' for reading). In this way, it is possible to use a bash script to execute a configuration sequence, similarly to what a user would do by typing multiple shell commands. An example is provided in [[PWM_overview#How_to_use_PWM_with_sysfs_interface|How_to_use_PWM_with_sysfs_interface]]. == References == <references /> <noinclude> [[Category:How to trace and debug]] [[Category:OpenSTLinux filesystem]] {{PublicationRequestId | 10265 | 2019-01-16 |BrunoB}} </noinclude> [[Category:How_to ]][[Category:How_to_trace_and_debug ]] [[Category:sysfs]]
该页面使用的模板:
模板:CodeSource
(
查看源代码
)
模板:PublicationRequestId
(
查看源代码
)
返回至
如何在sysfs中访问信息
。
导航
导航
WIKI首页
官方店铺
资料下载
交流社区
所有页面
所有产品
MPU-Linux开发板
MCU-单片机开发板
Linux开发系列视频
单片机开发系列视频
所有模块配件
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志