Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a sysfs attribute take a non numeric value in Linux Device Driver? [closed]

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).

like image 882
Raulp Avatar asked Sep 05 '16 06:09

Raulp


1 Answers

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.
like image 195
sawdust Avatar answered Sep 30 '22 02:09

sawdust