Skip to content

udf: decode 8-bit CS0 names as Latin-1 to UTF-8 - #50

Closed
reinauer wants to merge 1 commit into
mainfrom
udf/cs0-latin1-utf8
Closed

reinauer wants to merge 1 commit into
mainfrom
udf/cs0-latin1-utf8

Conversation

@reinauer

Copy link
Copy Markdown
Owner

udf: decode 8-bit CS0 names as Latin-1 to UTF-8

This commit was split out of #43. It is correct for the backend contract, but on its own it makes names on AmigaOS worse, so it is a draft.

What it does

OSTA CS0 compression ID 8 stores Latin-1 bytes. The UDF backend copies them into node names verbatim, so every other path gives UTF-8 and this one gives raw Latin-1. The commit encodes bytes ≥ 0x80 as two-byte UTF-8 and lets udf_decode_dstring() share udf_decode_cs0(). It adds a unit test, udf_cs0_8bit_name_decodes_latin1_to_utf8, which fails on main.

Size: 68000 −100 bytes, 68020 −128 bytes, ROM unchanged (no UDF).

Why not merge it alone

  • On main, the Amiga frontend copies node.name into fib_FileName and ed_Name unconverted (fill_fib and the ExAll fill in platform/amiga/handler_main.c). There is no UTF-8 to Latin-1 step anywhere in the handler, and the system charset on OS3 and OS4 is Latin-1.
  • So today, 8-bit UDF names are the one non-ASCII case that displays correctly on AmigaOS. Joliet, HFS (Mac Roman), HFS+ and 16-bit UDF names all reach AmigaDOS as UTF-8 and show as "Müller".
  • This commit moves 8-bit UDF names into the broken group as well. That is consistent, but a regression for those names.

What would fix it

Add the conversion in the Amiga frontend rather than the backends:

  1. When filling the FileInfoBlock, ExAllData and the volume name, convert UTF-8 to Latin-1. Characters outside Latin-1 become ?. Byte sequences that are not valid UTF-8, for example raw Latin-1 Rock Ridge names, pass through unchanged.
  2. Convert path components from AmigaDOS from Latin-1 to UTF-8 before lookup. Then "Müller" typed in a Shell matches a Joliet or UDF name. Today it only matches if the bytes came from a directory listing.
  3. Make collision handling in namefix see the Latin-1 form, because two distinct UTF-8 names can map to the same Latin-1 name.

With that in place, this commit becomes required: otherwise 8-bit UDF names would be raw Latin-1 bytes going into a UTF-8 decoder. It should land in the same series as the frontend change.

The cost is a conversion on every directory entry and on every path component looked up. That has to be checked against CDBench (ExAll and lock latency) before it can go in.

OSTA CS0 with compression ID 8 stores one byte per character, and
those bytes are the Unicode code points U+0000..U+00FF, i.e. Latin-1.
udf_decode_cs0() and udf_decode_dstring() copied them verbatim into
node names and the volume name, so a non-ASCII name produced invalid
UTF-8 even though odfs_node_t names are UTF-8 and the 16-bit CS0 path
already converts to UTF-8.

Encode bytes >= 0x80 as two-byte UTF-8 sequences, and let
udf_decode_dstring() reuse udf_decode_cs0() instead of carrying its
own copy of the decoder.

This is a user-visible change on AmigaOS: the Amiga frontend copies
node names into the FileInfoBlock and ExAllData unconverted, and the
system charset there is Latin-1. 8-bit UDF names, which display
correctly today, would then show as "Müller" instead of "Müller",
the same way Joliet, HFS and 16-bit CS0 names already appear. Host
tools that expect UTF-8 get valid names.
@reinauer

Copy link
Copy Markdown
Owner Author

Folded into #56: the same commit is there, after the handler learned to convert names to Latin-1, so 8-bit UDF names keep displaying correctly on AmigaOS.

@reinauer reinauer closed this Nov 24, 2026
@reinauer
reinauer deleted the udf/cs0-latin1-utf8 branch November 27, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant