widelinks && performance

Alexandre Oliva oliva at dcc.unicamp.br
Wed Apr 14 11:56:11 GMT 1999

On Apr 14, 1999, Andrew Tridgell <tridge at samba.org> wrote:

> Samba currently implements this by cutting off the filename portion of
> the filename and then doing a getwd/chdir/getwd to determine if any
> part of the filename points outside the root. Because of some nasty
> cases that are possible we end up doing 3 getwd and 3 chdir calls for
> every filename reference.

Ugh!  How about the following replacement:

0) stat the root of the share

1) cut off the filename portion of the filename
2) append `/.'

3) stat it
4) If it is the root of the share, go to 8
5) If it is the same as the previous stat, fail, we've reached `/'
6) append '/..'
7) go to 3

8) If the filename is not a soft-link, succeed
9) If it is an absolute soft-link, go to 1
10) Replace the basename with the relative soft-link and go to 1
This is certainly less expensive than the current mechanism, because
getwd must open and search each directory until the root, while this
scheme just stats each directory.

> 1) use the O_NOFOLLOW open() option (on OSes where it is available,
>    such as Linux) when widelinks are disabled. If the open then fails
>    with the errno given for following links we would do the expensive
>    chdir/getwd stuff.

Or this optimized version.

Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Brasil
{oliva,Alexandre.Oliva}@dcc.unicamp.br  aoliva@{acm.org,computer.org}
*** E-mail about software projects will be forwarded to mailing lists

More information about the samba-technical mailing list