I'd like to run a Linux process in a fake-write environment where all file writes (with the write(2) system call) are redirected to an in-memory cache, and subsequent reads (of the same region only) will be served from the cache. The cache can be discarded after the process finishes.
The files the process will be modifying are huge (several terabytes), but the total amount of written data is small (a few megabytes). So overlayfs is not an option, because I don't have several terabytes of free space.
Please note that I don't care about fake device nodes or fake permissions, thus fakeroot(1) doesn't help me.
This should be possible to implement with LD_PRELOAD, ptrace(2), fuse(8) or dm snapshot. Is there an existing tool which will do it for me, like this:
$ fakewrites ./myprog myfile.dat
myfile.dat
is a file (then we need an extra loop device). Feel free to copy your finding to an answer.