加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux-kernel – sysfs属性在Linux设备驱动程序中是否可以采用非

发布时间:2020-12-14 01:07:10 所属栏目:Linux 来源:网络整理
导读:我正在开发一个 Linux设备驱动程序,我必须使用sysfs接口将一串字符传递给它. sysfs属性是否可以接受字符串形式的数据(类似echo“somedata” sysfs_interface)? 我已经实现了它,它似乎工作正常,但我想确定这是有效的(在内核社区可以接受). 解决方法 Can the
我正在开发一个 Linux设备驱动程序,我必须使用sysfs接口将一串字符传递给它. sysfs属性是否可以接受字符串形式的数据(类似echo“somedata”> sysfs_interface)?

我已经实现了它,它似乎工作正常,但我想确定这是有效的(在内核社区可以接受).

解决方法

Can the sysfs attributes accepts the data in a string form …

是.
实际上这就是sysfs在使用echo时所接受的内容.当您使用echo 0时,输出是两个字节,0x30(数字零的ASCII码)和0x0A(换行符).

例如,GPIO LED接口使用关键字来报告和选择触发器.

# cat /sys/class/leds/d8/trigger
none nand-disk mmc0 timer [heartbeat] gpio

(括号中的关键字表示当前选择,即心跳计时器.)

# echo none > /sys/class/leds/d8/trigger
# cat /sys/class/leds/d8/trigger
[none] nand-disk mmc0 timer heartbeat gpio

… (something like echo "somedata" > sysfs_interface )

您甚至不需要使用引号.
请参阅上面将LED触发器设置为无的示例.

附录

these are the custom interfaces …

不,这是主线.

… but what about the one provided by the subsystem?

权威答案来自Linux Documentation/filesystems/sysfs.txt:

Attributes should be ASCII text files,preferably with only one value
per file.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读