Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

FIFO directory?

by lindex (Friar)
on Jun 18, 2001 at 15:09 UTC ( [id://89261]=perlquestion: print w/replies, xml ) Need Help??

lindex has asked for the wisdom of the Perl Monks concerning the following question:

Pardon the *nix-centric and lack of code nature of this question... Does anyone know if its possible to create a "fifo directory" that would beable to handle request from say an opendir call? What I would like todo is have a perl script that waited for a read on a special file and when it got that read it would output data as though the file where a directory. For example if I wanted to provide dynamic information to a directory listing program such as "ls".


Brought to you by that crazy but lovable guy... lindex

Replies are listed 'Best First'.
(tye)Re: FIFO directory?
by tye (Sage) on Jun 18, 2001 at 18:31 UTC

    Sure, just rewrite nfsd in Perl. See RFC 1813 for more info.

            - tye (but my friends call me "Tye")
Re: FIFO directory?
by jeroenes (Priest) on Jun 18, 2001 at 15:26 UTC
    Comments:
    1. This is really off-topic
    2. I don't see how your question relates to a First In First Out queue.
    3. You actually want to hack the filesystem. Luckily for you, there is a beautiful filesystem with source code handy, ext2fs. Brought to you by the Linux Corporation. Just ask about it at cmonks.org
    4. I'm sure you can get similar functionality with some perl script, but than you have to drop the demand that the output is visible through any filesystem access. If you won't mind that, please describe your problem in more detial.
    Jeroen
    "We are not alone"(FZ)

    Update: Maybe it is possible, but you don't tell us what kind of data you want to provide. For example, it's simple to replace 'ls' by a perlscript that gathers some data about a file, and displays that besides the filesystem data.

      In addition to ext2fs, there's the Perl Filesystem. I don't purport to understand it myself, but there it is.

      -- Frag.

      I think maybe your missing what I'am trying to get at. This is more of an "Is it possible" question than anything else. A Virtual Filesystem is one way of explaining it. I just would like to provide directory data dynamicly with perl.
      But then agian it may not be possible with out going through the rigors of writing a kernel module which is way out side the scope of the question, if this where so then the answer would be a simple "No, you can't do that in perl".


      Brought to you by that crazy but lovable guy... lindex
Re: FIFO directory?
by knobunc (Pilgrim) on Jun 18, 2001 at 18:46 UTC

    The reason this is a FIFO is that you can have 'named pipes' in UNIX where the file is connected directly to a process that can read or write to it. Some people use this to make their finger information cycle dynamically each time they are fingered, or to do a 'back finger' to work out who fingered them. However, there are more modern finger daemons that can run scripts directly so that particular application is less common.

    The reason that a directory like fifo would be useful is to allow access to a program through a file system like interface. This would allow some funky stuff to occur. So you could map a DB directly to some filesystem layout so that reads and writes would access the DB (I think Oracle has something like this). Or you could have a filesystem that automatically version controlled files that were stored in it (e.g. Clearcase). Or you could present a dynamic view of processes running & use the OS permissions structures to controll access (e.g. the proc filesystem). Or make a directory that was mapped to a different site using FTP or HTTP. Or to store the files encrypted on disk and automatically show the desrypted version once the program has been run with the appropriate arguments.

    Unfortunately there is no easy way to do this. There are some things you can do under Linux to allow a program to act as a filesystem (userfs) but that is pretty hard core. And you would probably have to write a layer in C that would map the lower level stuff up into Perl.

    Tye's idea of using nfs to do this is pretty cunning and is used by some encryption filesystems. NFS basically takes a filesytem request and shoves it over the network to a program (typically nfsd) running on some remote host. The standard nfsd maps this to a local file system operation. You might be able to find an nfsd that allows you to hook into it and override the operations. Then if you run it on the same host, you can mount some arbitrary directory against your hacked nfsd and present whatever virtual view of the world that you want.

    Good luck.

    -ben

      you said ...
      The reason that a directory like fifo would be useful is to allow access to a program through a file system like interface. This would allow some funky stuff to occur. So you could map a DB directly to some filesystem layout so that reads and writes would access the DB ...
      You hit the nail on the head with that one, that's exactly what I am aiming at only you phrased in much more elequently than I. I am going to keep working on this, I will keep pm.org updated.
      Maybe at some point or another we will have a setup of Tie:: modules to provide access to a user maped filesystem :)

      Brought to you by that crazy but lovable guy... lindex
Re: FIFO directory?
by Gloom (Monk) on Jun 18, 2001 at 15:23 UTC
    Hum ... I think that you wanna make something like "proc" virtual filesystem isn't it ? So the only way to do this under linux ( i think ) is a module ( kernel module, not perl module :) thus is not a perl question. Maybe take a look to proc source in the linux kernel.
    _______________________
    Hope this helps
Re: FIFO directory?
by mugwumpjism (Hermit) on Jun 18, 2001 at 18:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://89261]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found