Doubt on show() function of sysfs attribute

Mohana Datta Yelugoti ymdatta.work at gmail.com
Tue Jan 26 12:37:24 EST 2021


Hello everyone,

I am going through Documentation/filesystems/sysfs.rst.

It says that sysfs allocates a buffer of size PAGE_SIZE and
passes it to the show/store functions of the attribute. On
read(), the show() method should fill the entire buffer[0].

The document also says that sysfs_emit() and sysfs_emit_at()
are the preferred function calls in show() function when
formatting the value to be returned to the user space [1].

I checked the sysfs_emit() function definition.

sysfs_emit() -> vscnprintf() -> vsnprintf() is the function
series. (-> = calls)

In the vsnprintf() function, i found that only in the case of
(start + size > end) the buffer is completely filled, in the other
case, that's not the case [2].

Isn't this contradictory to what the sysfs.rst says? (that entire
buffer should be filled)

Can you please help me understand what i am missing here?

Thank you for your time.

Cheers,
ymdatta.


[0]:
https://elixir.bootlin.com/linux/latest/source/Documentation/filesystems/sysfs.rst#L214

[1]:
https://elixir.bootlin.com/linux/latest/source/Documentation/filesystems/sysfs.rst#L246

[2]: https://elixir.bootlin.com/linux/latest/source/lib/vsprintf.c#L2689



More information about the Kernelnewbies mailing list