News for hackers. Stuff that matters.
Re:A brief history of APFS (Apple File System) in honour of ... by flohofwoe on Tuesday March 28, 2023 @03:04AM (#35336936)
The solution is simply what Linux does: treat filenames as bags of bytes instead of strings (but this would also include case-sensitivity). At least then the behaviour is completely straightforward and transparent down in the file system layer.

UNICODE details like normalization can be handled up in the application layer.

Re:A brief history of APFS (Apple File System) in honour of ... by eviks on Tuesday March 28, 2023 @03:37AM (#35337138)
It's straightforward, transparent, and wrong, because filenames are not a bag of bytes, they are labels by and for humans, so no good API should ignore this simple fact
Re:A brief history of APFS (Apple File System) in honour of ... by Wicher on Tuesday March 28, 2023 @04:57PM (#35347730)
Nothing stops you from encoding your human-labels as bytestrings. Most fellow humans do exactly that. "Gosh I wish the relation between this file's human-label and its filesystem-identity were something other than bijective", said no Linux user ever.

A filename is an identity and if identities are ambiguous, you run into trouble, examples in this thread abound.

Putting it another way, do you work with relational databases? Primary keys? Those are identities. I don't even want to think about a world in which I can't roundtrip data through a database and have things NOT come out the way I put them in. "Human labels" or not ;-)

Of course it's fine to search for things case-insensitively or otherwise normalized. And so we have "find -iname" and "locate -i" etc. etc. That's totally reasonable.

Re:A brief history of APFS (Apple File System) in honour of ... by eviks on Wednesday March 29, 2023 @01:12AM (#35352920)
> Nothing stops you from encoding your human-labels as bytestrings

The fact that inhuman labels can sneak in stops me

> said no Linux user ever

You just weren't listening

> you run into trouble, examples in this thread abound

Bag of bytes approach is not trouble free

> Primary keys?

Do those accept any bytes in a bag?

> can't roundtrip data through a database and have things NOT come out the way I put them in

So you just want normalisation-preserving filesystem?

But I see that you care so little about human users that you think they should learn to avoid Á outside of letters to grandma...

Re:A brief history of APFS (Apple File System) in honour of ... by Wicher on Wednesday March 29, 2023 @10:43AM (#35358008)
> The fact that inhuman labels can sneak in stops me

Stops you from what? I'm not sure what you mean there. No one mentioned inhuman. Someone, not me, instantiated a "labels for humans" concept and I roll with that, for the sake of conversation.

>> Primary keys? > Do those accept any bytes in a bag?

Well, a "bag" (unordered) would not be the right term, but we understand what the original author meant (a bytestring), so: Yes, in fact they do. For instance, PostgreSQL:

create table bla (joyfulkey bytea PRIMARY KEY)

We don't want identifiers mangled. Should you be so unfortunate to have to use bytestrings as primary keys, then they'll come out the way you put them in. Because they're unambiguous identifiers. Not prose.

> So you just want normalisation-preserving filesystem?

I want an identity-preserving filesystem. And I have it!

> But I see that you care so little about human users that you think they should learn to avoid Á outside of letters to grandma...

I care a lot about human users. I give them nice file pickers so that they can easily choose to open files named ÁÁÁ.docx. Or search for those, using a system where both query and index is normalized (as is the common approach). And the other kind of users, also human, who find they care about the identity of files since they're writing that search engine and have to pass them in an argument vector to get the PDF viewer to open the file that the user found, will be most happy if they don't need to worry about the file system second-guessing them on identities.

PS There's a lot of you-this you-that ad-hominem things in your comments. That's not really the best way to hold a discussion.

Re:A brief history of APFS (Apple File System) in honour of ... by kalleboo on Tuesday March 28, 2023 @07:38PM (#35349693)
Personally I loved how Classic MacOS stored all it's file references as an "alias" data type which used the equivalent of inode, going as far as encoding file server connection details for auto-reconnect and a fallback path of inodes and names to traverse in case the file was removed and replaced.

But that worked in an OS that had no command line - UNIX users are allergic to binary configuration formats and demand to be able to type path names.

Re:A brief history of APFS (Apple File System) in honour of ... by Someone on Tuesday March 28, 2023 @04:16AM (#35337373)
“Bags of bytes” has its own problems. If the idea of ‘character encoding’ is alien to the file system, the application layer cannot reliably show file names to users, other than as sequence of byte values. It cannot even assume 0x41 is an ‘A’, for example.

Historically, you configured your OS to match (what you thought was) the encoding used on your disk, but that starts to break when you have network disks or when users exchange floppies.

In practice, I think about every Unix/Linux file system at least assumes ASCII encoding for the printable ASCII range. How else does, for example, your shell find “ls” on your disk when you type those characters?

So, not even in Unix/Linux is a file name “a bag of bytes”

I think file systems should enforce an encoding, and provide a way for users of the file system to find out what it is.

Apple’s HFS, for example, stored explicit ‘code page’ ID so that the Finder knew, for example, to use the Apple Cyrillic encoding to interpret the bytes describing file names on disk for that disk.

The modern way is to just say file names are valid Unicode strings, with UTF-8 being the popular choice. Unfortunately that introduces the normalization problem.

Re:A brief history of APFS (Apple File System) in honour of ... by gpderetta on Tuesday March 28, 2023 @05:50AM (#35338114)
> the application layer cannot reliably show file names to users, other than as sequence of byte values.

As you say, it can just show the sequence of bytes (plus some visual hints that they are escaped). It is not like nonsensical filenames with seem composed of random numbers are uncommon (e.g. look into your .git dir)

> How else does, for example, your shell find “ls” on your disk when you type those characters?

This is purely a presentation layer issue. The filesystem assumes nothing.

Re:A brief history of APFS (Apple File System) in honour of ... by klausa on Tuesday March 28, 2023 @06:34AM (#35338493)
The git files aren't supposed to be seen by a human being.

What you're suggesting would mean that a Korean user saving a file on their desktop and naming it in Korean would in turn see the filename turn into garbage, which, I hope we can all agree, is not a reasonable suggestion.

Re:A brief history of APFS (Apple File System) in honour of ... by gpderetta on Tuesday March 28, 2023 @06:41AM (#35338563)
Of course if the file-name is correctly decodeable in the user preferred encoding (hopefully UTF-8) it should be shown as such. But giving up on supposedly malformed filenames shouldn't be an option for robust software.
Re:A brief history of APFS (Apple File System) in honour of ... by CorrectHorseBat on Tuesday March 28, 2023 @06:52AM (#35338655)
Why though? What do you lose by forcing utf-8 at the filesystem level?
Re:A brief history of APFS (Apple File System) in honour of ... by gpderetta on Tuesday March 28, 2023 @07:17AM (#35338844)
Compatibility with a few decades of data and with other systems.
Re:A brief history of APFS (Apple File System) in honour of ... by eviks on Tuesday March 28, 2023 @12:15PM (#35343432)
But the future is longer than a few decades, so why extend the mistake further?
Re:A brief history of APFS (Apple File System) in honour of ... by sacnoradhq on Tuesday March 28, 2023 @08:22PM (#35350183)
Because change costs way more to than you think: maybe billions of dollars and impacting billions of users.

Creating 2 different systems carries risks: it has a learning curve, a support cost, and breaks everything that came before.

Perhaps, in a utopian green field, we redo a systems language, a portable systems API, and a common operating system with a compatibility layer to the old way on top.

Re:A brief history of APFS (Apple File System) in honour of ... by eviks on Wednesday March 29, 2023 @12:18AM (#35352472)
Change has already partially happened since there is no one single filesystem with one behavior.

Not changing impacts many more users (all the future billions) and costs even more: the learning/support/etc. is all there, and it's harder to learn about a buggy system since you have more papercuts

Also, it doesn't break everything, we're not living in a dystopia

Re:A brief history of APFS (Apple File System) in honour of ... by actionfromafar on Wednesday March 29, 2023 @04:59AM (#35354430)
This is all true. We should also fix global warming, it's the same kind of problem. Massive investments now or even more massive losses tomorrow.
Re:A brief history of APFS (Apple File System) in honour of ... by gpderetta on Wednesday March 29, 2023 @04:43AM (#35354316)
1) Not everybody, or even a majority, agrees that the current state is a mistake

2) Change what to what? There are multiple filesystems systems (and OSs) with different and sometimes incompatible filename encodings. Who picks the winner?

3) There is irony on dropping backward compat and requiring UTF-8, an econding whose claim to fame is backward compatibility with ASCII based systems (and not coincidentally was designed by UNIX Elder Ones)

Re:A brief history of APFS (Apple File System) in honour of ... by eviks on Wednesday March 29, 2023 @11:58AM (#35359091)
I was responding to your specific argument ignoring the bigger future for the smaller past, not sure how the broader questions about what others think etc is relevant

1) so? That will be true for anything

2) sequence of bytes to human encoding. Who picked the loser??? This would similarly be some unidentifiable group of people. You can start by picking the winner for yourself, even at a conceptual level

3) no irony, sequence of bytes is not ASCII

Re:A brief history of APFS (Apple File System) in honour of ... by sacnoradhq on Tuesday March 28, 2023 @08:16PM (#35350124)
Are you running EBCDIC or a localization other than UTF-8 anywhere?

The filesystem shouldn't arbitrate localization issues. It's the wrong place to do it in terms of performance, area-of-responsibility, and portability.

NUL-terminated UTF-8 in memory and size+data on disk is the best encoding.

Normalization is a multifaceted problem that needs to be handled at or before where the filename argument hits the standard library. Sometimes, normalization is NOT desirable and it is preferrable to normalize for comparison only to other strings and to faithfully store whatever was provided verbatim.

Side-effects and doing 737 MAX MCAS underneath users is the road to ruin.

Re:A brief history of APFS (Apple File System) in honour of ... by j16sdiz on Tuesday March 28, 2023 @05:45AM (#35338063)
... and this cause lots of problem in python2 to python3 migration.

Command line argument is treated as (unicode) string, and file name are (sometimes) treated as bag of byte .....

Re:A brief history of APFS (Apple File System) in honour of ... by ClumsyPilot on Tuesday March 28, 2023 @07:31AM (#35338997)
Do you speak other languages?

Czech language has Á, Č, Ď, Ě, É, Í, Ň, Ó, Ř, Š, Ť, Ů, Ú, Ý

Á can be represented in Unicode by its spesific codepoint, or can be made up of two - Letter A and the squiggly bit.

So when a user tries to fOpen a file called ÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁÁ

Should by application make 2^32 requests to the file systen to open a file for every possible combination of bytes this steing could be represented as?

Re:A brief history of APFS (Apple File System) in honour of ... by FeepingCreature on Tuesday March 28, 2023 @08:36AM (#35339884)
To be fair, what a sufficiently clever application could do would be to try and naively open the file, note a mismatch, then do a directory walk comparing normalized filenames.

Still not great.

Re:A brief history of APFS (Apple File System) in honour of ... by flohofwoe on Tuesday March 28, 2023 @09:37AM (#35340836)
Ideally, un-normalized paths wouldn't even make it down to the filesystem layer. I'm just saying that it shouldn't be the filesystem's job to care about text encoding details, but the layers above it (e.g. the filesystem would work in a simple "garbage in - garbage out" mode).
Re:A brief history of APFS (Apple File System) in honour of ... by flohofwoe on Tuesday March 28, 2023 @09:31AM (#35340761)
I speak German which has its share of pointy letters :)

I'm aware of the normalization problem, but that should be handled in the API layers above the filesystem. In which layer exactly is up for discussion though (but IMHO there should always be a fallback to access files via their "raw bytes path identifiers", if for nothing else than debugging).

Re:A brief history of APFS (Apple File System) in honour of ... by sacnoradhq on Wednesday March 29, 2023 @12:22AM (#35352510)
Yes. Separate concerns and group logic where the knowledge and configuration to handle it for the use exist closer to the application, not scatter it throughout the system stack that shouldn't need to know anything above it.

The main ways of finding files are by enumeration and filtering on that enumeration. Normalization should selectively occur during filtering rather than permanently destroying the original bytes of the name of the file. Without a binary-precise filename call to open() (fopen() is a library call, not a syscall), then case-folding and Unicode normalization shouldn't second-guess the request or help the program. Case-insensitive filesystems are industry nonstandard and a dumb choice Apple continues to use.

Re:A brief history of APFS (Apple File System) in honour of ... by Wicher on Tuesday March 28, 2023 @05:14PM (#35347966)
At this point the user will discover that easy to type unambiguously encoded filenames have value, and may opt to save the Á's for when they actually are writing a letter to grandma.

"But that's subjecting the user to limitations of the system!" you might object, and while you'd be right we should also ponder whether a filesystem is a word processor or a system for locating data using filenames as identifiers, and consequently, what sound handling of identifiers is.

And let's be realistic. Most users will choose the file to open from a file picker dialog. fopen() is not their interface, their interface is a file picker.

The intersection of people for whom fopen() is their interface (no file pickers) but for whom learning lessons on the value of using unambiguous identifiers is somehow out of reach, would be exceedingly small.

Re:A brief history of APFS (Apple File System) in honour of ... by hibbelig on Wednesday March 29, 2023 @10:02AM (#35357427)
> At this point the user will discover that easy to type unambiguously encoded filenames have value, and may opt to save the Á's for when they actually are writing a letter to grandma.

The unambiguously encoded filenames wouldn't be in the natural language of the user, so you're asking the user to learn another language. Users shouldn't have to learn another language to use the computer.

Re:A brief history of APFS (Apple File System) in honour of ... by Wicher on Wednesday March 29, 2023 @11:12AM (#35358424)
I'm not 100% sure on this, but in many/most/all scripts, wouldn't there be a subset of characters in unicode for which you don't need to worry about unicode ambiguities with respect to combining characters?

For prose of course it wouldn't be acceptable if you can't use your full language, but this is a filesystem, and we're talking identifiers, not prose. We accept that for a wide range of everyday things — I don't think many people are getting worked up about web forms not accepting their phone numbers when entered in Latin numerals.

Using bytestring labels sans normalization is just the rational choice, and actually quite accommodating. People _can_ use their natural language. If you can encode your prose in bytes, then there you go, that'll be your filename ;-) and if you can't remember what diacritic-combining strategy you used when you created the file, and can't manage to fopen() it anymore by typing out the filename, use a file picker or search. And then, perhaps, go "that was a hassle, I'll avoid those fu͝n͜n͏y͝ sq̧u͜igg̶l̢įȩş for my next filename, computer are stupid" - not the end of the world, not the worst outcome.

Re:A brief history of APFS (Apple File System) in honour of ... by hibbelig on Wednesday March 29, 2023 @02:21PM (#35361147)
I'm not 100% certain, either. Hasn't someone else here written that all of the Korean characters can be expressed in two ways?

Then there is Vietnamese which has a lot of accents and other diacritics. Not sure how much you can do without them.

Perhaps a language like Chinese doesn't have so many ambiguities, as in there is only one way to encode a given character in Unicode?

Re:A brief history of APFS (Apple File System) in honour of ... by sacnoradhq on Tuesday March 28, 2023 @08:02PM (#35349958)
This is the answer. Normalization cannot and should not be guessed at by the filesystem. It's the wrong place to do it. If normalization is generally (but not universally) desirable, then the standard library (libc, etc.) should provide options to make it more convenient with sane defaults. Second-guessing users and developers with assumptions outside of its domain is a recipe for failure and endless workarounds.