Re: Problems with read() on /proc/devices with x86_64 system

From: Jan Engelhardt
Date: Fri Feb 24 2006 - 02:40:30 EST


>> If your code ever worked, it's probably because of some
>> fortuitous buffering in the 'C' runtime library.
>
>Not my code .. I just did a minimal hack to get it to build with klibc
>(klibc do not support fscanf(), so used fread() and sscanf() ..).
>
Ah, you can't do fread(ptr, 4096, 1, fp), because it would probably never
return 1 if the file was smaller than 4096. Bad luck with stdio, I'd say.
Back to read(2).

>> Most
>> of the 'read' code in drivers that have a /proc interface
>> is not designed for 1-character-at-a-time I/O. It's expected
>> that it will be accessed like `cat` or `more` or other
>> such tools access it, -- one read with 4096-byte buffer --
>>
>> read(3, "MemTotal: 773860 kB\nMemFre"..., 4096) = 670
>> write(1, "MemTotal: 773860 kB\nMemFre"..., 670) = 670

Jan Engelhardt
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/