Author: Davide Libenzi
Description: File Links Copy On Write (FL-COW) Home Page
Keywords: hard,link,file,copy,write,unix

FL-COW Home Page

The library born to solve a problem I had when working with the Linux Kernel archives that I use to replicate using hard links. Replicating archives with hard links is both fast and space saving, and it helped me a lot in speeding up my operations when working on the kernel source. A recent Arch's mailing list thread that suggested that use of hard links to create archive cached revisions pushed me to write the FL-COW library. What is the problem with hard links when, for example, I'm working with kernel sources? The problem is that I do a:
$ cp -al linux-2.6-test6 linux-2.6-test6.vm-fix
This command replicate at light speed the vanilla (Linus) archive into an archive I can start hacking on. The problem is that I have to manually remember to break hard links on files I start working on, otherwise even the original copy get modified. This might break because I forgot doing so and it might also break because other tools might eventually touch file they were not supposed to touch. If it happens that I forget to decouple a file hard link, the next command:
$ diff -Nru linux-2.6-test6 linux-2.6-test6.vm-fix
will skip all changes done on the file I forgot, because my changes has been applied to the original file also. The library works by intercepting all file open operations happening inside a configured path list, and by decoupling the hard link with a COW if a write operation is requested. The library is installed using the environment variable LD_PRELOAD and in this way it is able to hook glibc open(2) functions and it is able to perform the COW when necessary. The environment variable FLCOW_PATH control which paths should be subject to COWing. The logic that the library follow to know if a file should be COWed is the following:

1. Is the file being opened with O_RDWR or O_WRONLY modes?
2. Is the file inside one of the paths listed inside the FLCOW_PATH environment variable?
3. Is the file being opened a regular file?
4. Is the (struct stat)->st_nlink variable greater than one?

If all those answers are yes, the file is COWed by leaving the calling application with a non hard linked version of the file. To setup the library you must start with building it doing a (for example):
$ ./configure --prefix=/usr
$ make
$ make check
$ su
# make install
If all those steps complete correctly you will have your library installed in /usr/lib/libflcow.so that is ready for use. I use to set the LD_PRELOAD inside my .bashrc file so that I am sure that no tool will screw up my hard-linked archives. This is the relevant section of my .bashrc file:
export LD_PRELOAD=/usr/lib/libflcow.so:$LD_PRELOAD
export FLCOW_PATH=/usr/src/:/home/davide/arch-archives/
The library source code is available here:
FL-COW 0.10
Back Home