Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there anyway in linux (I don't care which distribution or flavor) to have a dynamic file system with read/write hooks? For example I would like to mount a dynamic file system at /dynamic and whenever I try to read/write to a non-existing location a bash script or program is run. like if I did tail /dynamic/folder1/file1.log a bash script would run before the read operation and the path would be available as an argument. Is there any projects out there that do something like this?

share|improve this question
add comment

2 Answers

You're looking for FUSE.

With FUSE it is possible to implement a fully functional filesystem in a userspace program. Features include:

  • Simple library API
  • Simple installation (no need to patch or recompile the kernel)
  • Secure implementation
  • Userspace - kernel interface is very efficient
  • Usable by non privileged users
  • Runs on Linux kernels 2.4.X, 2.6.X and 3.X
  • Has proven very stable over time

Although to be fair, I haven't seen a FUSE module for raw programs/scripts so you'll still need to do some coding.

share|improve this answer
    
There's a Python binding for FUSE, but even there, it is indeed more than a 5-minute job to do anything useful. –  Gilles Feb 12 '13 at 22:25
add comment

You might also want to have a look at inotify. It provides an API that listens for file system changes. You could for example use IN_CREATE to get notified each time a new file gets created in a specific directory (there are inotify APIs for almost any programming or scripting language, so feel free to pick the one you're most comfortable with).

However I think it's not possible to get informed of read attempts to inexisting files (with an option to create it before the other program can read it) but depending on your use-case you might get around that issue. If inotify is not the right choice for you, I'd use FUSE as Ignacio suggested. But that might add a lot of additional work to implement what you desire.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.