Synchronising cache and file

I am reading and caching some of the blocks of a large data file into program
virtual memory, for processing. My question is how do I synchronise this
cache with the file, for instance, if a block in the cache is updated or written to,
that block has to be updated in the underlying file. If this process is delayed
or only partly completed, will not the file be inconsistent. This can happen
if there is a power failure. How is this problem handled by DBMS programs ?
I am programming in C. Any answers and references to good books or readily available reading material on this subject will be gratefully appreciated.

Since UNIX already caches files, I figure I do not need to maintain a separate cache in my
program. A judicious use of flock() and fsync() should do the job. Thank you. This thread is solved and closed