summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-15 11:41:54 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-08-05 20:07:13 +0200
commit1869d1b312e27cd34bb837b61ff674532afbc842 (patch)
tree9d33a8942bf2819f245b0748b6c2e4ab5b497935 /src
parent39efe737746d6da8e4819f41b6e4069c4b09d359 (diff)
libcamera: v4l2_device: Add method to lookup device path
Add a method to lookup a V4L2 devices path in sysfs. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/v4l2_device.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 56ea1ddd..65830d41 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -9,12 +9,15 @@
#include <fcntl.h>
#include <iomanip>
+#include <limits.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <unistd.h>
#include "libcamera/internal/log.h"
+#include "libcamera/internal/sysfs.h"
#include "libcamera/internal/utils.h"
#include "libcamera/internal/v4l2_controls.h"
@@ -351,6 +354,34 @@ int V4L2Device::setControls(ControlList *ctrls)
}
/**
+ * \brief Retrieve the device path in sysfs
+ *
+ * This function returns the sysfs path to the physical device backing the V4L2
+ * device. The path is guaranteed to be an absolute path, without any symbolic
+ * link.
+ *
+ * It includes the sysfs mount point prefix
+ *
+ * \return The device path in sysfs
+ */
+std::string V4L2Device::devicePath() const
+{
+ std::string devicePath = sysfs::charDevPath(deviceNode_) + "/device";
+
+ char *realPath = realpath(devicePath.c_str(), nullptr);
+ if (!realPath) {
+ LOG(V4L2, Fatal)
+ << "Can not resolve device path for " << devicePath;
+ return {};
+ }
+
+ std::string path{ realPath };
+ free(realPath);
+
+ return path;
+}
+
+/**
* \brief Perform an IOCTL system call on the device node
* \param[in] request The IOCTL request code
* \param[in] argp A pointer to the IOCTL argument