Welcome, Unregistered.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Reply
Old 24-Oct-2008, 15:57   #1
Simon F
Tea maker
 
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
Default "synthetic file" in *nix

Just wondering if there are any *nix gurus here who could help with a tricky little problem (or perhaps point me at the right location).

I'd like to create (for want of a better term) a "synthesised" file, a bit like a named pipe/FIFO, except that when a program opens that file for reading, the system actually runs a program that generates the content 'on the fly'. (In a way it is also analogous to an executable script where the first line of the script tells how to interpret the remainder.)

An example of what I'd like to achieve would be, say, decompressing a gzipped file transparently so that the reading program doesn't even know that the real source is compressed. Simply opening the file would automatically launch the decompression tool. (Unfortunately, reading from stdin and using a pipe seems to be out of the question).

Has anyone seen this sort of thing before?

TIA
Simon
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson

"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay
Simon F is offline   Reply With Quote
Old 24-Oct-2008, 16:41   #2
Kalin
Member
 
Join Date: Jul 2004
Location: Sofia, BG
Posts: 160
Send a message via ICQ to Kalin
Default

FUSE might help.
Kalin is offline   Reply With Quote
Old 24-Oct-2008, 17:45   #3
Simon F
Tea maker
 
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
Default

Thanks. I'll take a look
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson

"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay
Simon F is offline   Reply With Quote
Old 13-Dec-2008, 19:22   #4
SPM
Member
 
Join Date: Dec 2005
Posts: 639
Default

Quote:
Originally Posted by Simon F View Post
I'd like to create (for want of a better term) a "synthesised" file, a bit like a named pipe/FIFO, except that when a program opens that file for reading, the system actually runs a program that generates the content 'on the fly'.
Unix/Linux device drivers work in exactly this way - they appear as files on the system, and can be opened as character or block devices. What you may be looking for is how to write a Unix/Linux device driver.

As for reading compressed files transparently, lots of applications already do that. You may want to take a look at the source code of these applications.
SPM is offline   Reply With Quote
Old 14-Dec-2008, 07:25   #5
Simon F
Tea maker
 
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
Default

Quote:
Originally Posted by SPM View Post
Unix/Linux device drivers work in exactly this way - they appear as files on the system, and can be opened as character or block devices. What you may be looking for is how to write a Unix/Linux device driver.
As I am not the admin on these systems, it has to be something that is in user space.
Quote:
As for reading compressed files transparently, lots of applications already do that. You may want to take a look at the source code of these applications.
Are you referring to, say, using zlib to transparently open either gzipped or standard files? I've used this in my own applications, but as I don't have either access to the source for the other tools or time to do the modifications, that option is out. <shrug>
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson

"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay
Simon F is offline   Reply With Quote
Old 14-Dec-2008, 13:14   #6
SPM
Member
 
Join Date: Dec 2005
Posts: 639
Default

Quote:
Originally Posted by Simon F View Post
As I am not the admin on these systems, it has to be something that is in user space.

Are you referring to, say, using zlib to transparently open either gzipped or standard files? I've used this in my own applications, but as I don't have either access to the source for the other tools or time to do the modifications, that option is out. <shrug>
Pretty well every Linux file manager will browse through compressed archives transparently and open files contained in them - for example on Fedora 9, nautilus (the native Gnome file manager), Thunar, and PC Man file managers, and even command line file managers like Midnight Commander (mc) allow this. These are open source user space programs, the source code is freely available, and it should be fairly straightforward to look at the source code for the libraries used and the techniques used to do the transparent access as an example and use it if your own code. mc for example is a fairly compact file browser and so there should be less code to look through. You should perhaps install Fedora Linux on a PC and check if the functionality is what you want. It may be just a question of adding a hook to an existing open source application to allow programmatical access.

I am not familiar with zlib, but it should surely be fairly straightforward to get a listing of the content of a compressed file and feed that back to your program for display to allow the user to select files of a subdirectory in the compressed file and so on. Since mc, Thunar etc. and other programs routinely do this, if you don't know how to do this, all you need to do is to look at the mc, Thunar code for an example of how to do it. Most GNU Linux utility programs and libraries have already been ported to Unix or vice versa or are trivial to port to Unix.

As for faking file systems from user space without root access, it is obviously a serious security violation if anyone can do this - it opens the door to Windows 98 style security (or lack of it) and rampant cracker/virus/trojan vulnerability, so Unix/Linux systems sensibly don't permit this. On a properly administered Unix system, users can normally only mount file systems which are declared as user mountable in the /etc/fstab file, and all device files are only accessible to root. FUSE allows user space file systems, but you still need to compile the options into the kernel, which again for obvious security reasons requires root access. FUSE used in a properly administered Unix/Linux system would normally be used in a way that would not compromise the system security - eg. the user space filesystem programs would run under a non-root psuedo-user who no ordinary user can log in as - a kind of a second level administrator if you will.
SPM is offline   Reply With Quote
Old 30-Dec-2008, 00:04   #7
Saem
Senior Member
 
Join Date: Feb 2002
Posts: 1,532
Send a message via ICQ to Saem Send a message via AIM to Saem Send a message via MSN to Saem
Default

Hi Simon,

Just wondering if you found a solution to your problem?
__________________
Regards.
Saem is offline   Reply With Quote
Old 30-Dec-2008, 11:19   #8
Simon F
Tea maker
 
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
Default

Quote:
Originally Posted by Saem View Post
Hi Simon,

Just wondering if you found a solution to your problem?
The sys admins just added N more terrabytes of storage!
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson

"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay
Simon F is offline   Reply With Quote
Old 31-Dec-2008, 06:16   #9
Saem
Senior Member
 
Join Date: Feb 2002
Posts: 1,532
Send a message via ICQ to Saem Send a message via AIM to Saem Send a message via MSN to Saem
Default

LoL, I guess that works too. I suppose considering the price of hardware it was probably not that much more expensive, if at all, than your time on the problem.

Thinking about it, without admin access, I don't imagine you'd want that to be possible, as you could easily hijack things that way.
__________________
Regards.
Saem is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 16:01.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.