Skip to content

Conversation

@christoph-zededa
Copy link
Contributor

This PR adds USB devices to the list of devices.

The code basically iterates over /sys/bus/usb/devices, follows the symlinks and reads uevent, interface and product.

For the snapshot, the symlinks in /sys/bus/usb/devices are added as well as the aforementioned files.

@christoph-zededa christoph-zededa force-pushed the usb branch 3 times, most recently from 215b125 to 03aa3e7 Compare September 1, 2025 12:09
@christoph-zededa
Copy link
Contributor Author

Fixed the build errors for Mac OS X and the linting errors about missing error-return-checks.

@christoph-zededa christoph-zededa force-pushed the usb branch 2 times, most recently from 11861e0 to 67402b7 Compare September 1, 2025 16:59
@jaypipes
Copy link
Owner

jaypipes commented Sep 2, 2025

@christoph-zededa thanks so much for this submission! I'll try to do a full review later today or tomorrow :)

Copy link
Collaborator

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many thanks for the submission. I think that a usb package will benefit the project.
I'm very wary to add more deps, we should rather head to remove them all.
This is especially true if we can get similar (or identical?) results using golang code and peeking around in /sys.
Other than that, the code looks reasonnable, but I think we can use a bit more tests.

At glance, API additions (user-facing APIs) looks good but I'll leave the final word to @jaypipes

}
if err := showAccelerator(cmd, args); err != nil {
return err
fmt.Println("------------------------------")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: we should avoid fixed size separators; either avoid them for now or automatically align to the longest line, this approach will likely require extra code and/or a 3rd party helper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove it after debugging. Now it is gone.

info.Baseboard.String(),
info.Product.String(),
info.PCI.String(),
info.USB.String(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated: this scales pretty poorly and is too hard to extend, I'll file a PR to send an improvement ASAP

}

type Paths struct {
ChrootSys string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be "SysRoot"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it to SysRoot

Comment on lines 41 to 45
fileSpecs := ExpectedCloneStaticContent()
fileSpecs = append(fileSpecs, ExpectedCloneNetContent()...)
fileSpecs = append(fileSpecs, ExpectedCloneUSBContent()...)
fileSpecs = append(fileSpecs, ExpectedClonePCIContent()...)
fileSpecs = append(fileSpecs, ExpectedCloneGPUContent()...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, this code probably deserves some cleanup, I'll take care in a different PR

Comment on lines +19 to +21
/*
#cgo pkg-config: libusb-1.0
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this provide critical functionalities we can't replace with our code, I think we should avoid this especially becase it requires C code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea behind this is to use libusb on Mac OS X and use sysfs directly on Linux.
Perhaps it is better that I remove the OS X implementation now and later create another PR so this can be discussed there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this is an important clarification which changes the perspective a bit. I would prefer this approach you outline in your last comment, but please don't do any change just yet, let's wait for @jaypipes 's review.

import (
"runtime"

"github.com/pkg/errors"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the native errors in new code

jaypipes and others added 5 commits October 13, 2025 16:23
Updates the third-party dependencies in order for importing projects
that have stricter dependency compliance restrictions.

For `github.com/jaypipes/pcidb`, uplifts it to the latest 1.1.0 release,
which removed the archived `github.com/mitchellh/go-homedir` dependency.

For `howett.net/plist`, there hasn't been a tagged release of that repo
since December, 2023, so I manually `go get` the latest commit from
January 2025 for that repository. `howett.net/plist` is used for MacOS
support.

For `github.com/StackExchange/wmi`, I changed this to
`github.com/yusufpapurcu/wmi` which is the officially-supported fork of
the `github.com/StackExchange/wmi` repo.

Closes Issue jaypipes#323
Related Issue jaypipes/pcidb#36
Related google/dranet#194

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
Adds a fix for a missing $HOME envvar on Linux.

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
instead of checking every return manually, use a for-loop

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
basically this code iterates over entries in `/sys/bus/usb/devices/`
and reads out information from the `uevent` file and some other
files

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
not all operating systems expose usb information via sysfs;
on the platforms still gousb can be used although it links
to native libusb, misses some values and is a lot slower

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
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.

3 participants