Hacker News new | ask | show | jobs
by magicalhippo 2115 days ago
I've set the Samba shares on my NAS to be case-sensitive, as making them case-insensitive slows down directory access by orders of magnitude.

I've been running this for years accessing them both from Linux desktops and Windows desktops, and only once have I had an issue that required me to manually rename something on the NAS.

This makes sense as most applications don't care about the filename, and will just use what you supply, or generate one and use that string all over.

1 comments

Yep, that's true. It's the cache misses that kill performance. If the client asks for file "Foo", and the (l)stat fails to find it, then we have to scan the whole directory looking for any case-differing versions of "foo" "FOO" "fOo" etc.

Very costly, but the only way to give case-insensitivity.

> Very costly, but the only way to give case-insensitivity.

That is very costly — but it's certainly not the only way to provide case-insensitivity, nor is it the recommended way, and I'd be surprised if any implementation of case-insensitivity actually did what you say.

Normally one would lowercase (or uppercase) both strings, and then do the comparison.

The complexity here usually comes when case-folding various tricky locales.

You are incorrect. It is the only way for a user-space application to provide Windows-style case insensitivity.

Windows slient sends a name "foo" over SMB2+. Samba does a stat("foo", &st) call, gets ENOENT.

Now, does that name really not exist ? Or is it there in the requested directory under any of the names "FOO"/"FOo"/"Foo"/"fOo"/"fOO"/"FoO" etc. ?

The only way for an application to tell is to do:

opendir() fname = readdir().... check strlower(client_provided_name, fname); closedir().

If the file really doesn't exist you have ended up scanning the whole directory.

Because Linux doesn't provide directory leasing you have to do this for every missed lookup (another process might have created it in the meantime).

There is no POSIX API for "does this file exist under another cased name" ? If there were Samba would use it.

Ah, my bad: In the post I was replying to, I thought you were saying that all of the permutation were enumerated and tested for — which we can all agree is terrible.

I now understand you mean that the directory is in fact scanned (and filenames compared in a case insensitive manner) once a miss occurs. Which is what I was hinting at.

Apologies, I misunderstood your post — and my reply could have been clearer also.