sxyazi/yazi · error

Cannot get the IO matching services

Error message

Cannot get the IO matching services

What it means

In `all_names` (yazi-fs macOS mounts), `IOServiceGetMatchingServices(0, IOServiceMatching(c"IOService"), &mut iterator)` must return 0 (KERN_SUCCESS). Any nonzero kern_return_t means IOKit could not produce the service iterator, so BSD name discovery aborts. This is the first step of enumerating disks via the IOKit registry.

Source

Thrown at yazi-fs/src/mounts/macos.rs:138

				label: dict.os_string("DAVolumeName").ok(),
				capacity: dict.integer("DAMediaSize").unwrap_or_default() as u64,
				external: dict.bool("DADeviceInternal").ok().map(|b| !b),
				removable: dict.bool("DAMediaRemovable").ok(),
				..partition
			});
		}

		Ok(disks)
	}

	fn all_names() -> Result<Vec<CString>> {
		let mut iterator: mach_port_t = 0;
		let result = unsafe {
			IOServiceGetMatchingServices(0, IOServiceMatching(c"IOService".as_ptr()), &mut iterator)
		};

		if result != 0 {
			bail!("Cannot get the IO matching services");
		}
		defer! { unsafe { IOObjectRelease(iterator); } };

		let mut names = vec![];
		loop {
			let service = unsafe { IOIteratorNext(iterator) };
			if service == 0 {
				break;
			}
			defer! { unsafe { IOObjectRelease(service); } };
			if let Some(name) = Self::bsd_name(service).ok().filter(|s| s.as_bytes().starts_with(b"disk"))
			{
				names.push(name);
			}
		}

		names.sort_unstable_by(|a, b| natsort(a.as_bytes(), b.as_bytes(), false));
		Ok(names)

View on GitHub (pinned to 5f901b886b)

Solutions

  1. Run in an environment with full IOKit access (normal macOS user session, no sandbox denying IOKit).
  2. Check that the process isn't running under a sandbox profile blocking IOKit lookups.
  3. Handle the error by skipping disk-name discovery and using a fallback partition listing.
  4. Retry once; transient IOKit failures can occur before system services are fully up.

Example fix

// before
if result != 0 {
    bail!("Cannot get the IO matching services");
}
// after: log and degrade
if result != 0 {
    tracing::warn!("IOServiceGetMatchingServices failed: {result}");
    return Ok(Vec::new());
}
Defensive patterns

Strategy: fallback

Try / catch

match all_names() {
    Ok(names) => names,
    Err(e) if e.to_string().contains("IO matching services") => Vec::new(),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `all_names()` on macOS when `IOServiceGetMatchingServices` returns a nonzero kern_return_t — IOKit service matching failed, typically because the IOKit master port / IOMasterPort is unavailable or the process lacks access to IOKit.

Common situations: Running inside macOS sandboxes or containers without IOKit access; non-standard environments (iOS-adjacent runtimes, hardened runtimes without entitlements); rare IOKit initialization failures at early boot or in restricted CI VMs.

Related errors


AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02). Data as JSON: /api/errors/7df3b6aa9235480f. Report an issue: GitHub.