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.

1 Answers1

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.

meuh
  • 51,383