Can the sysfs attribute accept a numeric value in the Linux device driver?

I am developing a Linux device driver where I need to pass a character string to it using the sysfs interface. Can sysfs attributes accept data in string form (something like echo "somedata" > sysfs_interface )?

I implemented it above and it seems to be working fine, but I would like to make sure that it is valid (valid in the kernel community).

+5
source share
1 answer

Can sysfs attributes accept data in string form ...

Yes.
In fact, this is what sysfs accepts when you use echo . When you use echo 0 , the output consists of two bytes, 0x30 (ASCII code for the digit 0) and 0x0A (new line).

For example, the GPIO LED interface uses keywords to report and select a trigger.

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

(The keyword in brackets indicates the current selection, heart rate 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 do not even need to use quotation marks.
See the above example of setting the LED trigger to none .


ADD

these are user interfaces ...

No, this is in mainline.

... but what about what is provided by the subsystem?

Authoritative answer from Documentation for Linux / file systems /sysfs.txt :

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

All Articles