I am developing a Linux device driver where I have to pass a string of characters to it using sysfs interface. Can the sysfs attributes accept the data in a string form (something like echo "somedata" > sysfs_interface )?
I have implemented it above, and it seems to be working fine, but I would like to make certain that this is valid (acceptable in the kernel community).
Can the sysfs attributes accepts the data in a string form ...
Yes.
Actually that is what sysfs accepts when you use echo. When you use echo 0 the output is two bytes, 0x30 (the ASCII code for digit zero) and 0x0A (a newline).
For example the GPIO LED interface uses keywords to report and select the trigger.
# cat /sys/class/leds/d8/trigger
none nand-disk mmc0 timer [heartbeat] gpio
(The bracketed keyword indicates the current selection, the heartbeat timer.)
# 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)
You don't even need to use the quote marks.
See the above example of setting the LED trigger to none.
ADDENDUM
these are the custom interfaces ...
No, this is in mainline .
... but what about the one provided by the subsystem?
The authoritative answer is from Linux Documentation/filesystems/sysfs.txt:
Attributes should be ASCII text files, preferably with only one value
per file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With