Skip to content

amiga: names in the system's character set, from codesets.library - #58

Merged
reinauer merged 4 commits into
mainfrom
amiga/codesets-names
Nov 26, 2026
Merged

reinauer merged 4 commits into
mainfrom
amiga/codesets-names

Conversation

@reinauer

@reinauer reinauer commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

amiga: names in the system's character set, from codesets.library

#56 converts names to Latin-1. On a system set up for another language that is the wrong 8-bit set: a Polish name on a Polish system shows _ for every letter Latin-1 lacks. With this series the handler asks codesets.library, if it is installed, for the system's default character set and converts to that. Without the library nothing changes.

Four commits on main. The branch was rebased after #56 and #52 were merged.

What changes

  • Core: odfs_utf8_to_latin1() becomes odfs_utf8_to_8bit() and takes a map, the Unicode code point of each byte from 0xA0 to 0xFF. A mount hands the map in with ODFS_NAMES_MAPPED. A NULL map is Latin-1 as before.
  • Bytes 0x80 to 0x9F: never produced, in any character set, because the Amiga console treats them as control codes. A character that a set has there (windows-1250 has some) is shown as _.
  • Handler: on AmigaOS 3, AmigaOS 4 and AROS it reads the default character set from codesets.library once and uses its map. A set that is not ASCII in its lower half, such as the library's UTF-8 entry, is refused.
  • Memory: the library and its tables take about 295 KB. The handler tells it to leave memory again as soon as the table is copied, unless a program has it open.
  • ROM build: unchanged, Latin-1; the code is compiled out.

When the handler asks

At the first request that concerns the disc, not at startup. Two things measured on OS 3.2 rule startup out:

  • The locale is not loaded yet. The stock Startup-Sequence mounts DEVS:DOSDrivers before IPrefs, and the shipped CD0 has Activate = 1. Asked at that point, codesets.library reports ISO-8859-1 + Euro on a system whose locale is Polish.
  • The library keeps its first answer. It works out the default when it is first opened. A handler that opens it too early gives every later program the English default too, until the library is flushed from memory.

A disc that is already in the drive was mounted for Latin-1 by then, but none of its names has been handed out:

  • Volume name plain ASCII on the disc: the mount is switched to the new character set in place.
  • Volume name with other characters: the disc is mounted again, before the request is answered.
    • The backend is asked for the name as it is on the disc. In the mount's own copy a _ may be one from the disc or stand for a letter Latin-1 lacks.
    • Before the rebase the check looked at that copy and still tested for ?. On a Polish system a disc named ŁĘŻ, mounted from the DEVS:DOSDrivers position, kept the volume name ___.
  • Names stay Latin-1: nothing happens.

AmigaOS 3 and AROS: nothing added to the packet loop

On the benchmark rig, two instructions per packet cost one timer tick (about 1.4 µs) on every per-packet metric. Any other source change to handler_main_startup(), or to a function inlined into it, makes the compiler arrange the whole packet loop differently; one such variant gave the streaming-read loop an extra taken branch and cost 1.6% in sequential read. So that function is untouched:

  • mount_volume() calls into the new code. The first call turns the packet port into one that runs a software interrupt.
  • The interrupt runs for each packet until one is not ACTION_IS_FILESYSTEM. It turns the port back and marks the media change count as unknown, which sends the handler through its existing media-change path before the packet is taken.
  • unmount_volume() calls into the new code too. That call asks the library, and returns early if the disc can stay mounted.

The new code is in platform/amiga/system_charset.c, listed first among the handler's sources. The linker places handler_main.o in front of the core, so code added to it moves every routine of the core and the backends.

AmigaOS 4

Requests are calls into the vector port, made in the caller's context. The first one that concerns the disc marks the change count as unknown, signals the handler process and waits for it; the handler process then asks the library as above. FSFileSystemAttr does not count: DOS calls it from the startup script's process at boot, before the locale is loaded. Every other call during a boot of OS 4.1 FE comes from Workbench.

Not waiting on ourselves

The library comes from disk while the handler waits, and the loader process (ramlib; LDDemon on AROS) serves one request at a time. Names stay Latin-1 rather than risk the loader needing this handler:

  • A request of the loader's own is waiting.
  • Boot volume, LIBS: or DEVS: on this handler's volume, or missing, or a late or non-binding assign, which only shows where it leads when it is used.

The DOS list is locked for reading with LockDosList(), as the loader does. AttemptLockDosList() fails on OS 3.2 whenever another task has the list, even for reading, and Workbench holds it for reading around its first packet.

What remains: a program that opens a library or device by a path on the disc at the moment of that one lookup, or one that holds the DOS list for writing while it sends the handler its first request.

Testing

Test discs carry Żółć.txt, Čeština/Šárka.txt, Grüße.txt, Señor.txt and Preis 5€.txt. They are named Łódź and ŁĘŻ, which have to be mounted again, and POLTEST and MY_DISC, which can be switched in place.

Everything below was run on the final tip, after the rebase, unless it says otherwise.

  • Host: make check passes on every commit, with new tests for the map conversion, accents through a map, namefix and a mount with a map. golden-check, malformed-check and fuzz-check pass.
  • Builds: every commit builds for 68000, 68020, ROM and OS4 without warnings and passes tests/aros/check_abi.sh. The AROS i386 handler builds from the tip; CI builds the x86-64 one.
  • Regression tool (5,028 checks on the CDBench fixture): 0 failures on OS 3.2, AmigaOS 4.1 FE Update 3 and AROS i386, and CDBench completes without errors on all three.
  • AmigaOS 3.2 (WinUAE, A4000/68040, 68020 build, codesets.library 6.22):
Setup Result
No codesets.library Latin-1; List, Info and Type output byte-identical to main
English locale Preis 5€.txt gets byte 0xA4, the Euro sign of ISO-8859-1 + Euro, and opens by that name
Polish locale, CD mounted after Workbench ISO 8859-2: Żółć.txt, Čeština/Šárka.txt and the volume name are right and open by their 8859-2 names; Señor.txt becomes Se_or.txt
Polish locale, CD mounted from the DEVS:DOSDrivers position the same
Polish locale, disc named ŁĘŻ, mounted early and late volume name in ISO 8859-2 (bytes A3 CA AF), names as above
Polish locale, disc named MY_DISC, mounted early and late volume name unchanged, names as above
English locale, disc named ŁĘŻ volume name ___: ISO-8859-1 + Euro has none of the three letters
ENV:CHARSET set to ISO-8859-2 the same
LIBS: made a non-binding assign Latin-1, no hang
First access by ramlib (OpenLibrary("CD0:...")) Latin-1, no hang

Soak: 70 boots over these setups on builds from before the rebase, all with the expected listing.

  • AmigaOS 4.1 FE Update 3 (QEMU pegasos2, handler as Kickstart module, codesets.library 6.21):
    • Disc ŁĘŻ in the drive at boot: names in ISO 8859-1, the system's set; volume name ___. Files open by those names.
    • codeset_default set to ISO-8859-2, then that disc inserted: names and the volume name in ISO 8859-2, files open by those names.
    • List, DiskChange, eject, a second disc, the first one again: as on main, no traps in the serial log.
  • AROS i386 (QEMU, nightly of 2 November, codesets.library 6.22, handler mounted on the second CD drive):
    • Default: ISO-8859-1 + Euro, files open by name.
    • codeset_default set to ISO-8859-2: the discs give ISO 8859-2 names; the volume names Łódź, ŁĘŻ and MY_DISC are right.
    • Library removed: Latin-1, no hang.
  • One unexplained stall: early on, with a first version of this code on OS 3.2, one boot out of about 30 produced no output and timed out. The same case then passed five times in a row. Another session's emulator was running on the machine at the time. I could not reproduce it.
  • Not run: AROS x86-64 and m68k at run time. A LIBS: assign that has a directory on the CD was tested with an earlier version of the same check, through a debug build; in the final design that state cannot be reached from a script.

Speed

CDBench, OS 3.2, 68020 build, same rig, same session, three runs each.

seq KiB/s Discovery cold ExAll deep lock open from lock small open/read parent
main 209,020 9,927 12,932 141 159 301 52
this series, no codesets.library 209,047 9,845 12,877 140 159 303 52
this series, codesets.library installed 208,846 9,838 12,870 141 159 302 51

Same offset is 51, stride 160 and seeded 153 in every row.

  • Discovery and ExAll are 0.8% and 0.4% below main, with or without the library. That comes from the state of free memory when the benchmark runs, not from the speed of the code. Listing a directory for the first time and opening files allocate memory, and exec's allocator walks the list of free chunks.
    • The code on the listing path is not longer. The converter's loop is 10 instructions per ASCII character where main's is 12, and odfs_iso_readdir() fetches the character set once instead of twice. handler_main_startup() and the packet functions are unchanged.
    • Half of it is 8 bytes. The second commit makes the handler's main allocation 8 bytes larger. Main with 8 bytes of padding there and no other change measures 9,888 and 12,914; the second commit measures 9,889 and 12,911.
    • The other half is the lookup having run. It makes the system allocate and free memory before the benchmark starts. The tip with the lookup switched off at run time measures 9,908 and 12,944.
    • Main alone moves more than that. The unchanged main handler, on a system where ten or forty small files were written to RAM: and every other one deleted before the mount, measures 9,711 to 9,737 and 12,792 to 12,826, and an open from a lock takes 5 to 10 µs longer. Reads do not change.
  • With the library installed, sequential read is 0.08% below main; the read path is the same code.
  • The fixture is named CDBENCH_FIXTURE. A first version of the fix mounted every disc with a _ in its name again; after that second mount sequential read was 207,211 KiB/s and the lock figures 142, 162 and 306. That is why the check asks the backend.

Size

Built with the 20261103 toolchain.

Build main this series delta limit
68000 handler 85,472 86,868 +1,396 98,304
68020 handler 83,008 84,296 +1,288 98,304
ROM 32,036 32,040 +4 32,768
OS4 handler 158,776 159,544 +768 163,840

Not in this series

  • Accents for other sets: a decomposed HFS+ name merges only the accents Latin-1 has, so c + caron stays c_ on a Latin-2 system.
  • Case: matching still folds only A to Z.

odfs_utf8_to_latin1() turns names into ISO 8859-1, the character set
most Amiga systems use. A system set up for another language uses
another 8-bit set, ISO 8859-2 for Polish, and every letter of a name
that Latin-1 does not have comes out as a question mark there.

Rename the function to odfs_utf8_to_8bit() and let it take a map: the
Unicode code point of each byte from 0xA0 to 0xFF. A NULL map still
means Latin-1. Bytes 0x80 to 0x9F are never produced, as before: the
Amiga console takes them as control codes whatever the character set
says is there.

A combining accent merges as before, into the Latin-1 letter, and that
letter is then looked up in the map: it merges only into a letter the
set has.

The map code is under ODFS_FEATURE_CHARSET_EXTERNAL, which the ROM
profile has off. Nothing passes a map yet.
A mount could ask for names in UTF-8 or in Latin-1. Add a third
choice, ODFS_NAMES_MAPPED: the mount options carry a map as
odfs_utf8_to_8bit() takes it, and node names, symbolic link targets
and the volume name are converted with it.

The backends learn the character set from the cache they are handed,
which held its number. Put the number and the map into a struct,
odfs_names_t, and hand that to odfs_namefix_init() and
odfs_name_to_charset() in place of the number.

The map belongs to whoever mounts and has to stay valid until the
unmount.
Names are converted to Latin-1. That is wrong on a system set up for a
language with another 8-bit character set: a Polish name on a Polish
system shows an underscore for every letter Latin-1 does not have.

If codesets.library is installed, ask it for the system's default
character set and convert names to that. Without the library, and in
the ROM build, names stay Latin-1. The library is told to leave memory
again once the table is copied; it and its tables take some 300 KB.

The handler asks when the first packet that concerns the disc comes
in, not when it starts. Mount starts a handler from DEVS:DOSDrivers
before IPrefs has loaded the locale preferences, and codesets.library
works out its default when it is first opened and keeps it: asked that
early it answers with the English default, and gives that answer to
every program that opens it later.

This must not cost anything per packet. A test in the packet loop
shows in CDBench as one timer tick per packet, and any other change to
that function, or to one inlined into it, makes the compiler arrange
the whole loop differently. So the loop is left alone:

- mount_volume() calls odfs_amiga_system_charset(). The first call
  makes the packet port run a software interrupt.
- The interrupt runs for each packet until one is not
  ACTION_IS_FILESYSTEM, which Workbench sends first and with the DOS
  list locked. It then turns the port back into a signalling one and
  marks the change count as unknown, so that handle_media_change()
  sets out to mount the disc again before the packet is taken.
- unmount_volume() calls odfs_amiga_system_charset() as well, and
  that call asks the library.

A disc that is in the drive by then was mounted for Latin-1, but none
of its names has been handed out. If the disc is still the same and
its volume name is plain ASCII, the character set of the mount is
switched and unmount_volume() returns without doing anything. The same
if names stay Latin-1. Only a disc whose volume name has other
characters is mounted again. The backend is asked for the name as it
is on the disc: in the mount's copy an underscore may be one from the
disc or stand for a letter Latin-1 does not have.

The library is loaded from disk while the handler waits. The process
that loads it, ramlib or LDDemon on AROS, serves one request at a
time, so it must not need this handler meanwhile. Names stay Latin-1

- if a packet of the loader's own is waiting, or
- if the boot volume, LIBS: or DEVS: has a directory on this handler's
  volume, does not exist, or is a late or non-binding assign, which
  shows where it leads only when it is used.

The DOS list is locked for reading with LockDosList(), as the loader
does. AttemptLockDosList() fails whenever another task has the list,
even for reading as Workbench does around its first packet.

What is left is a program that opens a library or device by a path on
the disc at the very moment of that one lookup, or one that holds the
DOS list for writing while it sends the handler its first packet.

The code is in a file of its own, listed first among the handler's
sources: the linker places handler_main.o in front of the core, so
code added to it moves every routine of the core and the backends.

AmigaOS 4 keeps Latin-1 here. Requests reach the handler as calls
there, not as packets, and need a trigger of their own.
@reinauer
reinauer force-pushed the amiga/codesets-names branch from e90280c to cffe672 Compare November 25, 2026 23:32
@reinauer
reinauer changed the base branch from amiga/latin1-names to main November 25, 2026 23:32
On AmigaOS 4 requests reach the handler as calls into its vector port,
made in the caller's context, so there is no packet for a software
interrupt to catch. The first call that concerns the disc does what
the interrupt does elsewhere: it marks the change count as unknown and
signals a media change. Then it waits, with the filesystem semaphore
released, until the handler process has been through that pass, where
the library is asked as on AmigaOS 3.

FSFileSystemAttr does not count as such a call. DOS makes it from the
startup script's process at boot, before the locale is loaded. Every
other call during a boot of AmigaOS 4.1 FE comes from Workbench.

A handler does not shut down while a caller is waiting like this.

The checks of the assigns and of who is waiting need no code of their
own: dos/obsolete.h maps the names of the AmigaOS 3 DOS list to this
one, and the loader is a process called ramlib here too.
@reinauer
reinauer force-pushed the amiga/codesets-names branch from cffe672 to 0a4a41f Compare November 25, 2026 23:35
@reinauer
reinauer merged commit 4627a48 into main Nov 26, 2026
3 checks passed
@reinauer
reinauer deleted the amiga/codesets-names branch November 27, 2026 04:05
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