#
# I have a file open using fopen and am reaing using fread.
# Does this mean that the OS (linux) already buffers this
# file? What is the buffer size? Can I change it?
There are two kinds of bufferring going on: your program's stdio
buffers in your program's address space, and the system's buffers
hidden inside the kernel's address space. You can adjust the
stdio buffers with setbuf and setvbuf. You need system dependent
calls to control the kernel's buffers. For example fflush flushes
your program's stdio buffers to the kernel, but the kernel might
not flush its buffers all the way to disk immediately.
I think most stdio implementations discard their buffer contents
after an fseek. On a VM system like linux, the kernel buffers are
page frames managed by the virtual memory page replacement
algorithm.
If you need to do a lot of random jumping around in a file,
you might consider a system dependent memory mapping instead
of stdio.