Direct file access
In Linux files, and block devices are treated the same. They all share a common open/close, read/write interface. When you open a file/device you can set its properties. Most often it is used for read/write/truncate purposes, but one can also use it for more interesting stuff.
Every read or write (normally) passes through the OS buffers. The i/o operations are asynchronous, meaning that the OS has the power to decide when, and in what order, to perform them. Don't worry, reordering of writes won't mess up with your data, it is done inteligently. This playing around with i/o lets the OS considerably speed up these operations. This is whta you usually want.
The problems begin when you need synchronous i/os. That is, you must know exactly when an operation ended (i.e. data was written to the device). This is usefull for databases, replications, and other applications that must guarantee write to disk before any transaction en
ds.
For this purpose you can use the O_DIRECT flag. It tells the OS not to buffer the i/o, but to directly read/write to the device. This assures you that by the time you finish the i/o operation, your data is safely stored in the device - and even a sudden powerdown of the system won't delete it. There are ups and downs to using this flag, and indeed Linus (tm) dislikes it. But the fact is this is a very useful mode.
See the following links about it, and for use instructions:
