Repository navigation
ALI-2601: Format a removable drive from the sidebar - #65
Conversation
A drive's menu under Devices gets Format…, only for a drive that can come out (removable, USB or a card slot), never for one udisks2 marks as the system's, one holding a mounted system path (/, /boot, /home, /usr and the like) or swap, or one in a RAID or LVM set. The dialog asks for a name, checked against the format's limits (exFAT 15 characters, FAT32 11 in capitals, ext4 16 bytes), and a format: exFAT (the default), FAT32 or ext4. A format udisks2's Manager.CanFormat says can't be made is unavailable and names its package. The warning names the drive by make, model and size, and lists each partition with how much it holds. There's no typed confirmation. The keyboard starts on Cancel, Enter never presses Erase and Format (Space on it, or a click, does), and polkit asks for the password. The dialog is an alert whose description is the warning; the name's error is its description and marks it invalid; the formats are radio buttons. The format runs as a job: everything on the drive is unmounted and locked, then Block.Format "gpt" and PartitionTable.CreatePartitionAndFormat from 1 MiB filling the drive, then the new filesystem is mounted. It can be stopped until the erasing starts. The udisks2 stand-in serves Block.Format, CreatePartitionAndFormat and Manager.CanFormat, changing only its own pretend drives and writing down what it was asked. New tokens: radio, radio-dot, format-dialog-width, format-option-row.
|
Review round 1. The code-review skill ran, and its findings were checked against the code, along with a hand review of the safety areas. Nothing erases through Enter, keypad Enter, Space, AT-SPI or a double-click. The label goes to udisks2 as a D-Bus string, so there's no injection, and the stand-in can't be confused with the real bus. Being fixed:
Confirmed fine: the refusal rules for HintSystem, swap, RAID, LVM, a LUKS root (through the cleartext's mounts), whole-disk only, and the identity close of the dialog; Enter, Space and the a11y default; label passing; an unmount failure stops before the erase; Stop refused after the erase starts; the a11y roles. |
- Check the drive again after unmounting, before Block.Format: the same drive, the same whole disk and nothing of the system's on it. Abort with a clear message if it changed. Document that polkit's wait is inside Block.Format, and that identical sticks with no serial can pass as each other. - Never offer the stick a live or installer system runs from: mounted under /run/archiso, /run/initramfs, /run/live, /cdrom or /lib/live/mount, holding a loop device's backing file, or matching the boot device on the kernel's command line (root=, archisodevice=, archisolabel=). - Mount again what was mounted when a format stops or fails before the erase, and say whether nothing was erased and all of it is back, or it was left unmounted. - Show the drive as busy, and disable Unmount, Eject and Format, during a format. - Spell out FAT32's allowed characters, and refuse names that start or end with a space (or are only spaces), for every format. - Ask for FAT32 with mkfs-args -F 32 where udisks2 (2.10 or newer) passes it on. Otherwise mkfs.fat picks FAT32 from 512 MiB, and smaller drives aren't offered FAT32. - Leave MBR extended containers out of the warning; their logical partitions are listed.
|
Round 1 fixes are in a0a485d. 7 fixed, 1 declined.
Unit tests: 929. Clippy: 0 warnings. |
|
Review round 2. The code-review skill ran, and its findings were checked; one of them,
Confirmed fine:
|
- A Block.Format failure other than a refusal before it begins (polkit, or the drive busy) may have erased the drive. Say so, and don't mount anything again. - Refuse a drive with a device-mapper, loop or md device built on one of its blocks (read from /sys/dev/block/*/holders), other than the unlocked contents udisks2 reports for an encrypted partition. That covers Ventoy. - Read the boot device as the kernel splits its command line (with quotes), with archisosearchuuid=, a device in archisosearchfilename=, dracut's live: prefix, \x20 escapes, and by-id and by-path links followed. - After the drive changes mid-format, mount nothing again unless it's still the same drive with the same blocks, and say it was swapped. - A loop device's file on the stick is refused as "a file on it is in use (as a loop device)". - Tell a failed partition table write from a partition whose filesystem couldn't be made. - Compare the FAT32 512 MiB threshold with the partition's size. - Refuse "NO NAME" as a FAT32 name.
|
Round 2 fixes are in 53334ef. All 9 fixed, none declined.
Unit tests: 933. Clippy: 0 warnings. |
|
Review round 3. The code-review skill ran, and its findings were checked; the exFAT limit was confirmed by testing mkfs.exfat 1.4.5 on a scratch image file. Being fixed:
Confirmed fine:
|
- exFAT names are up to 11 UTF-16 code units, as mkfs.exfat 1.4.5 takes (12 fail). Checked on scratch image files against mkfs.exfat, mkfs.fat and mkfs.ext4, in a unit test that's skipped when a tool is missing. - Only udisks2's NotAuthorized* and DeviceBusy error names leave a failed Block.Format untouched. A Failed whose message says busy may have erased the drive. - Fail closed on /sys: a block on the drive with no device number, or whose holders can't be read, refuses it. Any holder but an unlocked partition's own contents refuses it, including bcache and nbd. - Read /proc/cmdline once, as bytes. Ignore by-* names with `..`, and follow links only to devices under /dev. - A disabled Erase and Format looks disabled with the keyboard on it. - A format thread that never runs or panics still clears the drive's busy state. The progress reaches four of four when it's done. - A format lookup that finishes while another dialog is open waits for that dialog to close. - The udisks2 stand-in keeps a /sys of its own; the e2e checks point Gannet at it with GANNET_SYSFS (bench builds only).
|
Round 3 fixes are in da19952. All fixed, none declined.
Unit tests: 934. Clippy: 0 warnings. |
|
Review round 4 (by hand, a narrow check of da19952): no findings.
|
Brings in ALI-2632 (the test sandboxes hide host mounts) and ALI-2599 (path bar folder suggestions). Conflicts in main.rs, paint.rs and e2e.py were resolved by keeping both sides. The new sidebar check uses StandIn.env, so the app reads the stand-in's own /sys.
Fixes ALI-2601.
Gannet could mount, unlock and eject drives, but not format one. A removable drive's menu now has Format…, through udisks2, as Folio has.
Behaviour
Which drives get it: removable drives, and drives on USB, SD or FireWire, as decided by
Snapshot::format_refusalin disks.rs. It's refused if any block on the drive:HintSystem;/,/boot,/efi,/home,/usr,/var(and similar) mounted;The check runs again just before the format, and the drive must still be the same one (Id, size and media time).
Opening the dialog: it reads the drive first: partition labels and sizes, how much is stored on mounted ones, and
Manager.CanFormatfor each format.The dialog:
/.No typed confirmation, as Mike decided:
The polkit password prompt is the second step.
The format runs as a job:
Block.Format("gpt");CreatePartitionAndFormatfrom 1 MiB to the end. The partition type is basic data for exFAT and FAT32, and Linux data for ext4 withtake-ownership;Stop works until the erasing starts. A no at polkit cancels quietly. When it's done, a note says "Formatted “…” as exFAT".
Screen readers: the dialog is an alert described by its warning. The name entry is described by its rule or error, and marked invalid when the name doesn't fit. The formats are radio buttons, using a new
Role::RadioButton.No new dependency and no idle cost. The README lists exfatprogs, dosfstools and e2fsprogs, and the Drives section describes Format.
Accessibility
New tokens:
radio,radio-dot,format-dialog-width, andformat-option-row(44 px).design/build --checkpasses. Lowest WCAG ratios:Buttons and the name field follow the app's dialog rule: 30 px, or 44 px with Larger targets. Format rows are always 44 px.
Safety in testing
Nothing destructive was ever called on the real system bus. Every format test goes through the udisks stand-in (
crates/core/examples/udisks-standin.rs), which now also serves Block.Format, CreatePartitionAndFormat and Manager.CanFormat, and records what it was asked.DBUS_SYSTEM_BUS_ADDRESS=unix:path=/nonexistentis unchanged.Checks
/boot,/boot/efi, swap, HintSystem, LVM and an internal disk), name limits, and formats run end to end through the stand-in: stop before the erase, a polkit no, each format's exact udisks2 calls, a swapped stick, an internal drive, and/bootmounted at the last moment.Hardened in review (four rounds, recorded in the comments)
Block.Formatcan't be closed from our side.name_limits_are_what_mkfs_takesruns the real tools.mkfs-args -F 32on udisks2 2.10 or newer. Below 512 MiB of partition, it's shown as unavailable on older udisks2.