Skip to content

ALI-2601: Format a removable drive from the sidebar - #65

Merged
michaelaguiar merged 5 commits into
mainfrom
aliasbot/ali-2601-format-drive
Dec 4, 2026
Merged

michaelaguiar merged 5 commits into
mainfrom
aliasbot/ali-2601-format-drive

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

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_refusal in disks.rs. It's refused if any block on the drive:

    • is marked HintSystem;
    • has swap in use;
    • has /, /boot, /efi, /home, /usr, /var (and similar) mounted;
    • is part of RAID or LVM.

    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.CanFormat for each format.

  • The dialog:

    • Name: checked as you type. exFAT allows up to 15 characters. FAT32 allows up to 11 ASCII characters, with no reserved ones, in capitals. ext4 allows up to 16 bytes. No format allows /.
    • Formats: exFAT (the default), FAT32 or ext4. A missing tool reads "Unavailable: needs the exfatprogs package" (or dosfstools, or e2fsprogs).
    • The warning names what will be lost, for example: Everything on "General USB Flash Disk, 125 GB" will be erased: the "ARCH_202601" partition, with 1.3 GB of files, and the 263 MB "ARCHISO_EFI" partition. This can't be undone.
  • No typed confirmation, as Mike decided:

    • focus starts on Cancel;
    • Enter only ever presses Cancel;
    • Erase and Format needs a click, or Tab and then Space;
    • it uses the danger colour, and its label and the warning say what it does.

    The polkit password prompt is the second step.

  • The format runs as a job:

    1. the window lets go of the drive's folders;
    2. its partitions are unmounted and locked;
    3. Block.Format("gpt");
    4. CreatePartitionAndFormat from 1 MiB to the end. The partition type is basic data for exFAT and FAT32, and Linux data for ext4 with take-ownership;
    5. the new partition is mounted.

    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, and format-option-row (44 px). design/build --check passes. Lowest WCAG ratios:

Pair Ratio
Danger label on an unfocused button 4.54:1 (aliasos)
Focused Erase and Format 5.77:1 light, 6.86:1 dark
Radio outline 3.62:1
Focus ring 4.67:1

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=/nonexistent is unchanged.

Checks

  • Mike tried a dev build on his Arch stick, up to Cancel.
  • Unit tests: which drives can be formatted (a fixture with /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 /boot mounted at the last moment.
  • Clippy: 0 warnings.
  • e2e: 120 checks pass, covering Format offered and refused, starting on Cancel, Enter never erasing, the name errors, each format's udisks2 calls, polkit refusal, a missing tool, and dark theme. The screen-reader check covers the alert, the entry and the radio buttons. Two drive-menu checks were updated for its 4th item.
    • Mutations, each of which made the check fail: Enter confirming, Format offered on any drive, no name check, and CanFormat ignored.

Hardened in review (four rounds, recorded in the comments)

  • Re-checked after unmounting: the drive's identity, whole disk and refusal rules are checked again after the release, and a stick swapped meanwhile is left alone. The polkit wait inside Block.Format can't be closed from our side.
  • Running-system sticks are refused:
    • mounts under /run/archiso, /run/initramfs, /run/live, /cdrom or /lib/live/mount;
    • a loop device's backing file on the stick;
    • the boot device from /proc/cmdline (root=, archisodevice=, archisolabel=, archisosearchuuid=, live:, UUID, LABEL, PARTUUID and by-* forms);
    • any other device built on a block (dm such as Ventoy, loop, md, bcache, nbd), except the stick's own LUKS cleartext;
    • unreadable sysfs fails closed.
  • Honest outcomes: only the D-Bus errors NotAuthorized* and DeviceBusy count as untouched and re-mount. Anything else says it may have been erased and mounts nothing. Erased with no partition, and partitioned but unformatted, are told apart.
  • Names match the real tools, measured on scratch images: exFAT 11 UTF-16 code units, FAT32 11 bytes from a fixed set (with "NO NAME" refused), and ext4 16 bytes. name_limits_are_what_mkfs_takes runs the real tools.
  • FAT32 is real FAT32 through mkfs-args -F 32 on udisks2 2.10 or newer. Below 512 MiB of partition, it's shown as unavailable on older udisks2.
  • During a format: the drive shows busy and Unmount, Eject and Format are disabled. A drop guard clears busy if the thread dies.
  • main (ALI-2632: Hide the host's drives and network shares from the test sandboxes #62, ALI-2599: Suggest folders while a path is typed, with Tab to complete #64) is merged in. CI passes.

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.
@michaelaguiar

Copy link
Copy Markdown
Member Author

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:

  • P2: no re-check between the release (unmounting can take seconds) and Block.Format, so a stick swapped meanwhile at the same block path could be formatted. A fresh snapshot after the release will repeat every check. The polkit wait inside Block.Format can't be closed from our side, and that will be documented.
  • P2: a booted live or installer stick is offered, because its mounts (/run/archiso, /run/initramfs, /run/live, /cdrom) aren't system paths. Refuse a drive with live-media mounts, one backing a loop device, or one holding the boot device from /proc/cmdline.
  • P3:
    • re-mount after a cancelled or failed format, with an honest message;
    • the spinner and disabled Eject during a format (the busy check uses the block, not the drive);
    • accurate FAT32 label wording, plus all-space and edge-space names;
    • real FAT32, through mkfs-args if udisks2 supports it, or else honest wording;
    • the warning not double-counting MBR extended containers.
  • Declined (P3): /var/ as a system prefix refuses a stick at /var/mnt. It fails safe and is rare.

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.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 1 fixes are in a0a485d. 7 fixed, 1 declined.

  • P2, re-check after the release: a fresh snapshot is taken after unmounting, repeating the same-drive, whole-disk and refusal checks before Block.Format. If anything changed, it aborts and mounts again. The doc says the polkit wait inside Block.Format can't be closed, and that two identical serial-less sticks can pass same_drive for each other. Stand-in test: /boot appearing mid-unmount, and a same-make card swapped in. It fails without the second snapshot.
  • P2, live and installer sticks: refused ("the running system started from it") when a block is mounted under /run/archiso, /run/initramfs, /run/live, /cdrom or /lib/live/mount; when it holds a loop device's backing file; or when it matches the boot device in /proc/cmdline (root=, archisodevice=, archisolabel= as UUID, LABEL, PARTUUID, PARTLABEL, a by-* path or a device). Unit and stand-in tests for each. The e2e LIVEDATA stick gets no Format item.
  • P3, cancel or early failure: everything that was mounted is mounted again, and the message says honestly whether it was left unmounted. An unlocked encrypted volume can't be reopened without its passphrase.
  • P3, busy: drive_busy() checks the block and the drive, so the spinner shows and Unmount, Eject and Format are disabled during a format. e2e.
  • P3, FAT32 names: the rule lists exactly what's allowed. Every format refuses a leading or trailing space, which covers all-space names. The rule line wraps at a fixed height.
  • P3, real FAT32: udisks2 here is 2.12.0, read from its Version property. On 2.10 or newer, mkfs-args = ["-F","32"] is passed. Older versions leave it to mkfs.fat (FAT32 from 512 MiB), and FAT32 is shown as unavailable below that. Stand-in tests.
  • P3: MBR extended containers are left out of the warning, and their logical partitions are listed.
  • Declined: the /var/ prefix. It fails safe, and the code comment says so.

Unit tests: 929. Clippy: 0 warnings. design/build --check passes. e2e passes. The only real-bus calls were the read-only Version and CanFormat.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 2. The code-review skill ran, and its findings were checked; one of them, CanFormat deserialization, was wrong and is dismissed. Nothing was run on any bus or device. Being fixed:

  • P2: every Block.Format error was reported as "Nothing was erased", with a re-mount. Only Cancelled, NotAuthorized and Busy mean nothing was wiped. Timeouts, I/O errors and a gone device will say it may have been erased, and won't re-mount.
  • P2: a booted Ventoy stick isn't detected: the live system runs from a dm device over the unmounted partition, and udisks gives that dm device no drive. Fix: refuse when any block's /sys holders include a dm or loop device other than the stick's own LUKS cleartext, or an md member.
  • P3:
    • archisosearchuuid=;
    • re-mount after a swap only for blocks still on the same drive;
    • cmdline quoting, by-id and by-path, live:CDLABEL=, and \\x20;
    • honest wording for a loop-file refusal;
    • "erased and partitioned, but not formatted";
    • the FAT32 threshold uses the partition size;
    • refuse "NO NAME" as a FAT32 label.

Confirmed fine:

  • the second snapshot and its checks, with Block.Format on the re-checked whole disk;
  • mkfs-args is documented for Block.Format and CreatePartitionAndFormat, unknown options are ignored, and the 2.10 gate and version parsing are safe;
  • busy and disabled menu items;
  • FAT32 labels are stricter than mkfs.fat 4.2.

- 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.
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 2 fixes are in 53334ef. All 9 fixed, none declined.

  • P2, failed erases: FormatFailed.left is one of Untouched, MaybeErased, Erased or Unformatted. Only Cancelled, NotAuthorized and Busy from Block.Format count as not erased and re-mount. Anything else says "stopped partway, and it may have been erased" and mounts nothing. Stand-in test covering I/O failure, a timeout (hang) and busy. It fails with the old mapping.
  • P2, built-on devices: /sys/dev/block holders are read for each block. An md* holder is refused as RAID or LVM. A dm-* or loop* holder is refused, except the LUKS cleartext udisks2 reports for that block. A unit test uses a fake sysfs, and a stand-in Ventoy-style stick gets no Format item.
  • P3:
    • archisosearchuuid=, and archisosearchfilename= when it's a /dev path;
    • undo re-mounts only blocks still on the same drive;
    • kernel-style cmdline quoting, live:CDLABEL/LABEL/UUID, \\x20, and by-* links resolved read-only;
    • its own wording for a loop-file refusal;
    • "erased and partitioned, but couldn't be formatted" versus "has no partition";
    • the FAT32 threshold by partition size (drive minus 2 MiB), with a stand-in test at 513 and 514 MiB;
    • "NO NAME" refused for FAT32.

Unit tests: 933. Clippy: 0 warnings. design/build --check passes. e2e passes. Nothing destructive touched the real bus or a device; the real reads are /proc/cmdline, sysfs holders, and canonicalize on /dev/disk/by-* links.

@michaelaguiar

Copy link
Copy Markdown
Member Author

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:

  • P2: exFAT labels are limited to 11 characters: 11 pass, and 12 fail with "input string is too long". The dialog allowed 15, so a name like "Holiday photos" would erase the drive and then fail in mkfs. The ext4 and FAT32 limits will also be checked against the real tools, on image files.
  • P2: disk_error maps any "is busy" message to Busy, which Block.Format treats as untouched, with a re-mount. Only the D-Bus error names NotAuthorized* and DeviceBusy will count as untouched; anything matched by message text counts as possibly erased.
  • P3: fail closed when sysfs can't be read or a block has no DeviceNumber. A lossy UTF-8 read of /proc/cmdline, cached once. by-* values must stay under /dev with no ...
  • Nits:
    • a disabled Erase looks disabled when focused;
    • a drop guard clears busy if the format thread dies;
    • the progress step off by one;
    • the lookup result kept behind another dialog;
    • bcache and nbd holders refused.

Confirmed fine:

  • every other error maps to MaybeErased, and the wording arms are in the right order;
  • DeviceNumber decoding, whole-disk coverage, and the exact LUKS exception;
  • cmdline parsing can't panic;
  • undo's same-drive check;
  • the test seams are harmless in release.

- 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).
@michaelaguiar

Copy link
Copy Markdown
Member Author

Round 3 fixes are in da19952. All fixed, none declined.

  • P2, name limits, measured on scratch images (exfatprogs 1.4.5, dosfstools 4.2, e2fsprogs):

    Format Accepts Rejects or changes
    exFAT 11 UTF-16 code units 12 fail
    FAT32 11 bytes, plus the listed symbols 12, . + * ? , ; : / \\ | = < > [ ] " and é fail; "NO NAME" becomes no label
    ext4 16 bytes longer names are silently cut short

    The app now allows exFAT 11 code units (emoji count as 2) and refuses an ext4 name the tool would cut. name_limits_are_what_mkfs_takes runs the real tools on scratch images at the app's limit and one past it, and fails if the exFAT check is loosened to 12.

  • P2, busy by error name: format() decides from the D-Bus error name only. NotAuthorized* and DeviceBusy are untouched and re-mounted. Everything else, including a Failed whose message says "is busy", is MaybeErased with no re-mount. Stand-in test, which fails with the old matching.

  • P3, fail closed on /sys: a block with device number 0, or whose holders can't be read, refuses the drive ("can't tell what's built on it"). The stand-in now keeps its own /sys, the e2e adds a VENTOY stick with a dm holder, and bench builds read GANNET_SYSFS.

  • P3, cmdline: read once, lossy UTF-8, and cached. by-* values with .. are ignored, and canonicalized results must be under /dev.

  • Nits:

    • a disabled Erase keeps its muted look when focused;
    • FormatDoneGuard clears busy if the thread dies;
    • the progress reaches 4 of 4;
    • a lookup result opens once another dialog closes;
    • bcache, nbd and any other non-cleartext holder refuse.

Unit tests: 934. Clippy: 0 warnings. design/build --check passes. e2e passes. Every mkfs ran on scratch image files only.

@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 4 (by hand, a narrow check of da19952): no findings.

  • refused_before_starting reads the D-Bus error name, never the message, and a dismissed polkit prompt is still Cancelled and untouched.
  • The exFAT UTF-16 count matches mkfs.exfat, and the FAT32 and ext4 checks run on the exact string sent.
  • The mkfs test runs only on scratch images, inside the sandbox.
  • Every block on this machine has a sysfs holders folder, including whole disks without partitions, so failing closed refuses no normal drive.
  • GANNET_SYSFS is bench-only.

#62 and #64 have since merged, so main is being merged in.

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.
@michaelaguiar
michaelaguiar marked this pull request as ready for review December 4, 2026 05:55
@michaelaguiar
michaelaguiar merged commit 658abda into main Dec 4, 2026
3 checks passed
@michaelaguiar
michaelaguiar deleted the aliasbot/ali-2601-format-drive branch December 4, 2026 05:56
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