tags:

views:

104

answers:

3

I want to implement a file system using FUSE. When the contents of the directory is requested, only the types of files in that directory will be reported as subdirectories. For example, if there are ugur.PDF, guler.JPG and devatate.PNG files in the directory, the files themselves will not be reported, but types (PDF, JPG and PNG) will be reported instead. I tried to implement this file system. My problem is i can not imagine that how can i report without changing ls-l command? how does ls-l command work? (I have a readdir function and it loads file_type and file_name to buffer. I tried to change but i couldn't achive)

A: 

Don't use ls. Whatever programming language you are using will have its own API's for walking directories. E.g., in Python, you might do this:

exts = set(ext for base,ext in (os.path.splitext(p) for p in os.listdir(path)) if ext)
Marcelo Cantos
I'm not sure you understood the question.
Nicolás
+1  A: 

If I understand correctly, you want to make a FUSE filesystem that converts this:

root
+-- foo.png
+-- bar.png
+-- quux.jpg
+-- asd.jpg
\-- photo.jpg

Into:

root
+-- png/
|   +-- foo.png
|   \-- bar.png
\-- jpg/
    +-- quux.jpg
    +-- asd.jpg
    \-- photo.jpg

Why would you need to change ls for that?

Nicolás
how can i implement?Can you give me an advise?
Iguramu
+1  A: 

How does ls -l work? That seems to be the crux of the issue. It calls fstat(2). That system call fills the stat structure. When you implement a fuse provider, you are providing the data that ends up in the stat structure. If you want to change the directory structure, you return the necessary fabricated information for the various items.

bmargulies