7

Is there a way that I can have something which appears as a file, but when being read some code executes which fills the content of the file "on the fly"?

Like FIFO/ named pipe, but without the need to start the writing process by hand.

Or like CGI on webservers, but on the local file system.

EDIT:
To guard myself against "why I want this"-doubts:
I want this to be able to have an audiofile whose content is generated on access, and then delivered to the audio player. And it should not be streaming, since when accessed by the audio player the length of the audio should be known.

5
  • A named pipe is the way to go. If you don't want to start the writing process by hand, turn it into a daemon and start it at boot. Apr 2, 2016 at 10:40
  • 2
    Do you mean something like /dev/random or /dev/zero?
    – ohno
    Apr 2, 2016 at 10:45
  • @Henrik: I want to start it on demand. Apr 2, 2016 at 13:50
  • @ohno: but I want to be able to specify an arpitrary command/ script to generate the content. Apr 2, 2016 at 13:51
  • 1
    Yes, unix.stackexchange.com/questions/66990/… answers this question for me (scriptfs, or maybe fuseflt can also do the job). Apr 3, 2016 at 6:01

1 Answer 1

12

If you are willing to do some coding, the fanotify system call allows you write a program that will intercept reads on any file beneath some mount point, and substitute or manipulate the data before returning it. See man fanotify for example C code.

Alternatively, you can mount a fuse filesystem, see man fuse, which allows you to implement a filesystem by a userspace program. For example, curlftpfs (see its man page) converts file accesses into curl ftp calls.

2
  • Is the FA in fanotify for "File Access?"
    – Aaron Hall
    Apr 2, 2016 at 12:33
  • The FA might be for "file activities", as this phrase is used in the man page, though it is not explicitly defined.
    – meuh
    Apr 2, 2016 at 12:39

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