sysfs属性是否可以在Linux设备驱动程序中使用非数字值?

Rau*_*ulp 5 device-driver linux-device-driver linux-kernel sysfs

我正在开发一个Linux设备驱动程序,我必须使用sysfs接口将一串字符传递给它.sysfs属性是否可以接受字符串形式的数据(类似echo "somedata" > sysfs_interface)?

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

saw*_*ust 7

sysfs属性是否可以接受字符串形式的数据...

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

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

# cat /sys/class/leds/d8/trigger
none nand-disk mmc0 timer [heartbeat] gpio
Run Code Online (Sandbox Code Playgroud)

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

# echo none > /sys/class/leds/d8/trigger
# cat /sys/class/leds/d8/trigger
[none] nand-disk mmc0 timer heartbeat gpio
Run Code Online (Sandbox Code Playgroud)

...(类似的东西echo "somedata" > sysfs_interface)

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


附录

这些是自定义界面......

不,这是主线.

......但子系统提供的那个怎么样?

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

Attributes should be ASCII text files, preferably with only one value
per file.
Run Code Online (Sandbox Code Playgroud)