tags:

views:

88

answers:

2

I am implementing a filesystem using Python Fuse. A directory contains only symlinks and as such I return S_IFLNK | 0777 on the getattr method.

Now, when I do an ls on the directory, I notice that Linux calls readlink method 6 times in a row for each entry in the directory.

Is it a bug on my side or a normal behavior?

A: 

It's not have to be a bug. It's may just simplify code of ls to call method many times rather than once and distribute result to different ls procedures. ls isn't bottleneck in any case, so developers don't have to write optimized code.

Tomasz Wysocki
interesting conjecture: I was hoping for a tangible response.
jldupont
You should probably dive into code of `ls` for that.
Tomasz Wysocki
+2  A: 

Well, it's definitely not ls calling readlink more than once. Unless you're calling it with unusual flags?

$ls
entropy  share
$ls -l
total 0
lrwxrwxrwx 1 entropy users 14 Aug  8 14:26 entropy -> /home/entropy/
lrwxrwxrwx 1 entropy users 11 Aug  8 14:18 share -> /usr/share/
$ltrace ls 2>&1 | grep readlink
$ltrace ls -l 2>&1 | grep readlink
readlink(0xbfdbb6c0, 0x9549b90, 15, 0, 0xb75ceec8) = 14
readlink(0xbfdbb6c0, 0x954a148, 12, 0xbfdbb992, 0) = 11
$

From the looks of things here ls with no flag never calls readlink, and will call it only once per link if the long flag is given. I don't know much about fuse, much less python fuse. So unfortunately, I can't answer your original question beyond saying that this looks very much like buggy behavior on your side but I could be wrong.

entropy
Great tip re:ltrace. Thanks a lot!
jldupont
Ah yes, ltrace, strace and a bit of grep make a pretty useful combination for debugging :)
entropy