cmemoryfile-iotransparencylibrary-interposition

memory-mapped files in C


I was playing around with memory-mapped files in C and was wondering if there is a way to replace the FILE * from fopen with a memory mapped file transparently.

Example:

FILE * fp = g_fopen(...);

//Program does things to this fp.

fclose();

But instead, is it possible to have FILE *fp = my_fopen(...)

Where my own function would open a file on disk mmap it, maybe change contents and then pass back the FILE * without the program seeing anything different except the new my_fopen() and my_fclose().

Is this possible to do without having to rewrite the way the operations are done in the program?


Solution

  • The magic words are "library interposition". Here's a good tutorial: http://developers.sun.com/solaris/articles/lib_interposers.html


    When Oracle purchased sun a lot of articles seem to have disappeared and/or aren't accessible through Oracle's website.

    Here's some links that, for the time being, are functional: