Why can't I eject this drive? Finder knows, and it will not say

2026-12-03来源 dev.toEnglish

This post was written as part of the Kiroween 2026 hackathon (Resurrection category), for my entry PhantomTrace.

You finish a copy, you need the drive on another machine, and you drag it to the trash. Finder answers:

The disk wasn't ejected because one or more programs may be using it.

That is the whole message. It does not say which program, or which file.

I hit this constantly. At any moment I have several terminals open, a couple of editors, a coding agent or two, a preview app, a backup tool. Somewhere in that pile, one thing has a file open on the drive, or a shell is sitting in a folder on it. Finder will not tell me which. Quitting everything is not an option, because each of those apps holds work I have not saved or a session I would have to rebuild. So a five-second job (unplug the drive, use it elsewhere) turns into a hunt.

The usual workarounds all have a cost

  • Quit apps one by one until Eject works. This loses state, and you never learn which app it was.
  • Run lsof in a terminal and read the output. It works, but the output is dense, the right flags are easy to forget, and a path with spaces or odd characters makes it harder to read.
  • Reach for kill -9. Quick, but risky. You can kill the wrong process, and an app that was mid-write can leave the drive in a bad state.
  • Pull the cable. This risks corrupting the drive.

What I wanted was the old Mac answer. In the System 7 and Mac OS 9 era there were small single-purpose utilities, such as What's Keeping Me?, that answered one question and got out of the way. The hackathon's Resurrection category asked for exactly that kind of revival, so I built one for modern macOS.

What PhantomTrace does

Right-click the stuck drive in Finder and choose the Quick Action "Why Can't I Eject?". PhantomTrace lists every process holding the volume: its name, process ID, user, whether it is a working-directory lock or an open file, and the exact file path. Diagnosis is always free. Nothing is touched until you choose.

If you want it fixed, there is a four-step pipeline, gentlest first, and you pick each step:

  1. Egress Shells. Send cd ~ to idle terminal shells. The terminal session survives. An idle shell sitting in a folder on the drive is a common blocker when you work in terminals.
  2. Graceful Request. Ask the applications to quit.
  3. Banish Locks. A targeted kill, only after you confirm, with each process named.
  4. Clean Handoff. A normal unmount, once a fresh scan finds zero locks.

It rescans before and after every step, so it never acts on a stale picture. The point is that the thing keeping the drive busy is often a shell sitting in a folder, not an app doing real work, and you can fix that without closing anything.

A few rules are fixed in code: it never signals launchd, Finder, WindowServer or similar, never touches protected volumes, and never leaves the machine. There is no network code and no telemetry.

How Kiro shaped it

This is the part I would not have predicted before starting.

  • Specs kept the safety rules from drifting. Requirements are written as "THE system SHALL" statements, and the project log cites them for each change.
  • Steering files hold the rules for safety, layering and testing. Some became lint rules, such as no print in the core library and no networking APIs.
  • Hooks block a commit that skips the project log or fails lint and tests. The real blocked-commit output is recorded in the repo.
  • Property-based tests on the safety policy found a real bug: /private/var/vm slipped past the protected-volume check because a path-normalizing call rewrote it to /var/vm. I would not have written that test case by hand.
  • Kiro drove the real app through the macOS Accessibility API to record the demo clips. Doing that, it found two UI bugs, one of which had hidden failed actions from the screen since the first build.

Try it

The code is MIT licensed, with zero runtime dependencies, at https://github.com/iolaire/PhantomTrace. It builds with the Swift command line tools. The app is ad-hoc signed, not notarized, so build it from source. Use a throwaway disk image to try it, never a real backup drive. The Scripts/demo/setup-demo.sh script makes one with a held file and an idle shell. The demo video is at https://youtu.be/P3He7COqWzA.

Not done yet: notarization, and VoiceOver and Reduce Motion testing.

原文:https://www.a8q9.cn/en/article/why-can-t-i-eject-this-drive-finder-knows-and-it-will-not-say-ef66fc.html

相关文章