fileio: introduce read_full_virtual_file() for reading virtual files in sysfs, procfs
authorFranck Bui <fbui@suse.com>
Tue, 22 Oct 2019 14:09:21 +0000 (16:09 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Oct 2019 13:24:49 +0000 (15:24 +0200)
commit21b40f16622f171a9969dc334d74fb5eb2f575c2
treeea2e335a4330b93c25a35075ebe82edaf72a3242
parentf5d28be33fac86e8d33b5b151f02918ac1e3d6b7
fileio: introduce read_full_virtual_file() for reading virtual files in sysfs, procfs

Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work
with two sorts of virtual files.

One sort uses "seq_file", and the results of the first read are buffered for
the second read. The other sort uses "raw" reads which always go direct to the
device.

In the later case, the content of the virtual file must be retrieved with a
single read otherwise subsequent read might get the new value instead of
finding EOF immediately. That's the reason why the usage of fread(3) is
prohibited in this case as it always performs a second call to read(2) looking
for EOF which is subject to the race described previously.

Fixes: #13585.
src/basic/fileio.c
src/basic/fileio.h
src/libsystemd/sd-device/sd-device.c