Skip to content

Read FreeBSD USB devices from devinfo -v instead of lshal - #3826

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:freebsd-usb-devinfo
Oct 17, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:freebsd-usb-devinfo

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

getUsbDevices() on FreeBSD parsed lshal. That tool went away with HAL and isn't present on current FreeBSD, so the method returned nothing. Neither cfarm430 (16.0-CURRENT) nor the Arm Morello board (cfarm240) has lshal, and the report's USB section was empty on both.

Change

devinfo -v prints the same device tree, and needs no privileges:

xhci0 <XHCI (generic) USB 3.0 controller> pnpinfo vendor=0x104c device=0x8241 ... at slot=0 ...
  usbus0
    uhub0 <(0x104c) XHCI root HUB, class 9/0, rev 3.00/1.00, addr 1>
      urndis0 <BeagleBoard.org TIAM335xBeagleBoneBlack, class 0/0, ...> pnpinfo vendor=0x1d6b product=0x0104 ... sernum="1234BBBK5678" ... at ... ugen=ugen0.2
      cdce0 <BeagleBoard.org TIAM335xBeagleBoneBlack, ...> pnpinfo ... at ... ugen=ugen0.2
      umodem0 <BeagleBoard.org TIAM335xBeagleBoneBlack, ...> pnpinfo ... at ... ugen=ugen0.2
  • Tree shape: the tree is built from the indentation. A usbus node's parent becomes the controller, and the root hub and devices hang beneath it. That's the same shape the lshal code produced.
  • Fields: a device's name is its description, without the , class ... suffix. Its IDs come from vendor= and product=, or device= for a PCI controller, and its serial number from sernum=.
  • One entry per device: a device is listed once per interface driver, and each listing carries the same ugen= location field. That field identifies the device, so it appears once, and it serves as the unique device ID.
  • Non-USB drivers: drivers beneath a USB device that have no ugen name of their own, such as a tablet's HID bus and hms mouse driver, aren't USB devices and are left out.

Verification

On cfarm430 (FreeBSD 16.0-CURRENT VM), both backends:

 Intel 82801I (ICH9) USB 2.0 controller
 |-- Intel EHCI root HUB
     |-- QEMU QEMU USB Tablet [s/n: 28754-0000:00:1d.7-1]

That device is shown along with seven other controllers and their root hubs. Before this change, the list was empty.

The Morello board has no JDK, so its real devinfo -v output is the test fixture: one BeagleBone Black with vendor 1d6b, product 0104, serial 1234BBBK5678 and ID ugen0.2, though three interface drivers list it. Other fixtures cover controllers with only root hubs, the tablet's child drivers, and PCI functions without a driver, which devinfo names unknown.

Limits

  • No vendor name: devinfo gives one description combining manufacturer and product, so the vendor-name field is now empty. lshal used to supply it separately.
  • Driverless devices: a USB device with no driver attached doesn't appear in devinfo. Only usbconfig lists those, and it needs root.
  • Sound cards: FreeBsdSoundCard also reads lshal, and is left for a separate change, because no machine available to me has a FreeBSD sound device to test against.

Summary by CodeRabbit

  • New Features
    • FreeBSD USB device enumeration now works with current system information and no elevated privileges.
    • Devices are listed once, including their vendor ID, product ID, and serial number.
  • Bug Fixes
    • Improved FreeBSD USB device hierarchy reporting, including controllers and devices with multiple interface drivers.

getUsbDevices() on FreeBSD parsed lshal, which went with HAL and is
absent from current FreeBSD, so it returned nothing. devinfo -v prints
the same device tree without privileges.

The tree comes from the indentation. A usbus node's parent is the
controller, whose children become the root hub and what hangs from it,
the shape the lshal code built. A device's name is its description less
the ", class ..." suffix, its IDs come from vendor= and product= (or
device= for a PCI controller), and its serial from sernum=. A USB
device is listed once per interface driver, each with the same ugen=
location field, which identifies the device. Drivers beneath a device
that have no ugen name of their own, such as a HID bus, are not USB
devices and are left out.

Verified on cfarm430 (FreeBSD 16.0-CURRENT) in both backends: eight
controllers with their root hubs and QEMU's tablet with its serial. The
Arm Morello board (cfarm240) has no JDK; its devinfo output, a
BeagleBone Black behind XHCI listed under three interface drivers, is
the test fixture.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9634f26-c91b-44d0-b363-2f89b4ebaccc
📥 Commits

Reviewing files that changed from the base of the PR and between ef2b95b and 0d9420e.

📒 Files selected for processing: 3
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDeviceTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 9
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📚 Code guidelines: 2
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered
📓 Path-based instructions: 2
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDeviceTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java
Applicability reference: AGENTS.md: # AGENTS.md Instructions for AI coding agents working in the OSHI repository.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md
🔇 Additional comments: 6
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java: 3

7-18: LGTM!

Also applies to: 27-40

63-63: LGTM!

Also applies to: 67-153

154-172: LGTM!

CHANGELOG.md: 1

33-33: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDeviceTest.java: 2

21-48: LGTM!

52-70: LGTM!

Also applies to: 74-84, 87-106, 111-112

📝 Walkthrough

FreeBSD USB enumeration now reads devinfo -v output instead of lshal. The parser builds controller and device trees from indentation and extracts device identifiers. Tests use FreeBSD 15.0 and 16.0 output samples.

Changes: FreeBSD USB enumeration

Layer / File(s) Summary
Read and parse devinfo output
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDevice.java, CHANGELOG.md
Enumeration runs devinfo -v. The parser builds device trees from indentation, combines entries that share a ugen, and extracts descriptions, vendor and product IDs, and serial numbers. It omits usbus nodes and uses their children to build controller trees. The changelog records the source change and reported identifiers.
Validate devinfo parsing
oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdUsbDeviceTest.java
Tests cover controller and root-hub parsing, repeated interface drivers, and HID descendants without their own ugen.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: taz03

Merge Risk: ⚪ Minimal · up to 0d942

FreeBSD USB enumeration now reads devinfo -v instead of the removed lshal. No concrete merge-blocking risk was identified, and the change restores device listing on current FreeBSD.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: replacing lshal with devinfo -v for FreeBSD USB device enumeration.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads the bus-tree lines,
Where BeagleBone and root hub shine.
Three drivers merge to one device,
IDs fall neatly into place.
No lshal trail is left to roam,
devinfo guides the gadgets home.

Comment @coderabbitai help to get the list of available commands.

@dbwiddis
dbwiddis merged commit d7805fa into oshi:master Oct 17, 2026
17 of 18 checks passed
@dbwiddis
dbwiddis deleted the freebsd-usb-devinfo branch October 17, 2026 23:55
dbwiddis added a commit to dbwiddis/oshi that referenced this pull request Oct 18, 2026
DragonFly's hardware layer extends FreeBSD's and so reads USB devices
with FreeBsdUsbDevice, which oshi#3826 moved to devinfo -v. FreeBSD's devinfo
prints a <description> on each line; DragonFly's prints none:

  uhci0 pnpinfo vendor=0x8086 device=0x7020 ... at slot=1 function=2
    usbus0
      uhub0

so every DragonFly USB device had a blank name, failing UsbDeviceTest
in the DragonFly job of Unix CI on master. Where there is no
description, name the device by its driver instance (uhci0, uhub0),
which devinfo always prints.

The fixture is DragonFly 6.4.2's devinfo -v from CI. Unix CI dispatched
on the fork for this branch passes on all six VMs, DragonFly included.
dbwiddis added a commit that referenced this pull request Oct 18, 2026
…3830)

DragonFly's hardware layer extends FreeBSD's and so reads USB devices
with FreeBsdUsbDevice, which #3826 moved to devinfo -v. FreeBSD's devinfo
prints a <description> on each line; DragonFly's prints none:

  uhci0 pnpinfo vendor=0x8086 device=0x7020 ... at slot=1 function=2
    usbus0
      uhub0

so every DragonFly USB device had a blank name, failing UsbDeviceTest
in the DragonFly job of Unix CI on master. Where there is no
description, name the device by its driver instance (uhci0, uhub0),
which devinfo always prints.

The fixture is DragonFly 6.4.2's devinfo -v from CI. Unix CI dispatched
on the fork for this branch passes on all six VMs, DragonFly included.
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