2

Is there a file type or method for using files in which certain files look and behave like symbolically linked files, but contain extra meta information for changing the data when they are read?

For example:
If I have a file called hello-world.txt, and I build a symbolically linked file pointing to it,

ln -s /path/to/hello-world.txt /path/to/symlink

I can not change the contents of the symlink without changing hello-world.txt, as well as changing all of the other files that point to hello-world.txt. I realize that symbolically/hard linked files are suppose to remain the same(because they are the same file in a sense), but it would be great, if I could write a file that references a particular file, and then also provides change details that get applied every time the file is read.

I tried to create my own file type using plain text that looked like this:

/path/to/file/being/referenced
change statement
change statement
...

I would then give these files their own file extension and mime type, and create an intermediate program to redirect to the referenced file, and basically try to mimic the behavior of a symbolic link. The problem is, the file doesn't "really" reference another file, and so actually reading the file(by using the cat command, or having a c++ processor pull in the file, etc), will not get the same information back that a symbolically linked file would. I'm not sure if I can provide a hook for this kind of thing, and have a program output the correct text for whatever is reading it. Maybe something with piped files? I don't know.

What would be the best way to achieve this kind of behavior on the file system?

Perhaps an analogy that best describes the kind of dynamic capabilities I want files to have, is how php files work on the web. The same file can be referenced using additional parameters, and that changes the contents of a file read by the user.

2
  • You could maybe combine a symlink with some auditd like functionality. Do the change details need to be stored in the "symbolic link" file, or could they be stored elsewhere? Feb 3, 2014 at 15:00
  • @FaheemMitha they could be stored elsewhere. I'm open for any solution that is easy to maintain and provides an easy workflow. looking into "auditd" Feb 3, 2014 at 15:15

2 Answers 2

3

You might be able to build this with FUSE, or one of the overlay systems like UnionFS. I don't think it can be done without either a filesystem driver or making every program that accesses it use LD_PRELOAD hacks to modify the behaviour of read().

There are several likely implementation problems:

  • in order to apply the changes, you have to read both files and store the intermediate somehow; http://en.wikipedia.org/wiki/Rope_%28data_structure%29 may help, but what if the base file and the changes file are both several Gb in size? Also, this will stall the program that opens the file while you apply the changes.

  • what happens if the underlying file changes in such a way that the change statements no longer apply?

  • in fact, what happens if the underlying file changes at all?

  • what happens if you try to write to the patched file?

1

You might be able to do something like this using patch. The "symlink" would then basically be a shellscript that reads the original and applies the patches. But I've not heard of anything ready-made that does what you want; if anyone else comes up with it I'd be very interested. Otherwise it'd be an interesting programming exercise.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .