-
Notifications
You must be signed in to change notification settings - Fork 5k
searching for major and minor to map between /sys to /dev devices #14271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
searching for major and minor to map between /sys to /dev devices #14271
Conversation
0182e69 to
a8e7516
Compare
a8e7516 to
061fbe7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements functionality to map between /sys and /dev device paths by utilizing major and minor device numbers, addressing scenarios where video device indices may differ between the two directories (e.g., in unprivileged containers).
Key changes:
- Adds major/minor number extraction and device mapping functionality
- Refactors device enumeration into smaller, focused functions
- Updates existing functions to use the new mapping system
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/linux/backend-v4l2.h | Adds new function declarations and data structures for device mapping |
| src/linux/backend-v4l2.cpp | Implements major/minor extraction, device mapping logic, and refactors enumeration functions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/linux/backend-v4l2.cpp
Outdated
| // dev file is in paths: | ||
| // - /sys/class/video4linux/videoX/dev for video files | ||
| // - /sys/class/d4xx-class/d4xx-dfu-30-XXXa for mipi dfu files | ||
|
|
||
| // dev file contains major_number:minor_number | ||
| // while major_number is always 81 for video4linux devices and is 506 for d4xx-class devices |
Copilot
AI
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states that major numbers are 'always 81' and 'always 506' for specific device types. This is too absolute and may not be true across all systems or kernel versions. Consider using 'typically' or 'commonly' instead of 'always'.
| // dev file is in paths: | |
| // - /sys/class/video4linux/videoX/dev for video files | |
| // - /sys/class/d4xx-class/d4xx-dfu-30-XXXa for mipi dfu files | |
| // dev file contains major_number:minor_number | |
| // while major_number is always 81 for video4linux devices and is 506 for d4xx-class devices | |
| // while major_number is typically 81 for video4linux devices and typically 506 for d4xx-class devices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/linux/backend-v4l2.cpp
Outdated
| { | ||
| std::vector<std::pair<std::string, std::string>> v4l_to_dev_video_paths; | ||
| // building vector of /dev/videoX files with path, major, minor | ||
| std::vector<path_and_identifier> dev_videos = collect_dev_video_path_and_identifier(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this returned a vector of all /dev device nodes and their major/minor numbers, the following would still work, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/linux/backend-v4l2.cpp
Outdated
| // going over video paths like /sys/class/video4linux/videoX | ||
| // find their mapping in /dev/videoY | ||
| // above videoX and videoY are often the same, but not always - for example when working in unprivileged container | ||
| // above videoX and videoY are often the same, but not alway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: alway -> always
src/linux/backend-v4l2.cpp
Outdated
| // for example when working in unprivileged container, the name in /dev even not be with the name "video" | ||
| // (depends how the mapping of the video devices has been done for the container building) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say:
// for example when working with unprivileged containers, the name in /dev may not contain the string "video"
// (depends on how the devices have been mapped (bind-mounted) into the container)
Nir-Az
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Tracked by: RSDSO-20543