Search code examples
pipesambanfsfile-handlingfile-processing

Howto create a directory under Linux which behaves like a pipe


We want to create a relative simple document storage but there are some requirements. My idea was, that a file is scanned and handled by a separate tool/daemon when it arrives at storage immediately.

The (pseudo) DMS should provide access via NFS and Samba. As I've seen so far, pipes would be fine for passing the incoming file to some hooks. But I wondered if there's a way to create a directory as a pipe. I've seen only named pipes yet.

The process which should take any incoming file in this directory is a PHP script which should does something like MIME type guessing, CRC32 check (against value in DB)...Has anyone a hint how to do this?

EDIT: I hope it's a bit clearer with the following explanation - I'm looking for a way to provide an "endpoint" via Samba and NFS where files can be placed that are handled by virus scanning and meta process immediately (and stored finally).


Solution

  • You can use FUSE to implement an intermediate Linux file system that sits on top of your real file system (the backend file system) and that performs any validation you need on the data before finally writing it to the backend. Then, you serve that file system via NFS/Samba.

    Another possibility is to use the inotify API to be notified of the changes on some file system tree and perform the required operations. The problem with this approach is that the processing will be asynchronous, so malware files will be published for a short time until they are scanned and deleted.

    update: ClamFS does exactly that!