From patchwork Mon Aug 3 21:17:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9156 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5BC47BD87A for ; Mon, 3 Aug 2020 21:18:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 10E6A61AC7; Mon, 3 Aug 2020 23:18:04 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E8BA60398 for ; Mon, 3 Aug 2020 23:18:00 +0200 (CEST) X-Halon-ID: 9cd2dc61-d5ce-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 9cd2dc61-d5ce-11ea-86ee-0050569116f7; Mon, 03 Aug 2020 23:16:36 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 3 Aug 2020 23:17:26 +0200 Message-Id: <20200803211733.1037019-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803211733.1037019-1-niklas.soderlund@ragnatech.se> References: <20200803211733.1037019-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/9] libcamera: device_enumerator_udev: Add specialization for sysfs path X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As udev may rename the V4L2 devices in /dev add a specialization that asks udev for the sysfs path instead of using the default method that makes the assumption that V4L2 devices are never renamed. Suggested-by: Laurent Pinchart Signed-off-by: Niklas Söderlund --- .../internal/device_enumerator_udev.h | 2 ++ src/libcamera/device_enumerator_udev.cpp | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/libcamera/internal/device_enumerator_udev.h b/include/libcamera/internal/device_enumerator_udev.h index 6f45be0c1c423d02..595b16acb89d98bb 100644 --- a/include/libcamera/internal/device_enumerator_udev.h +++ b/include/libcamera/internal/device_enumerator_udev.h @@ -35,6 +35,8 @@ public: int init(); int enumerate(); + std::string lookupSysfsPath(const std::string &deviceNode); + private: using DependencyMap = std::map>; diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index 96689daa5dd113dc..2e43b84f62e0333d 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -193,6 +194,29 @@ done: return 0; } +std::string DeviceEnumeratorUdev::lookupSysfsPath(const std::string &deviceNode) +{ + struct stat st; + int ret = stat(deviceNode.c_str(), &st); + if (ret < 0) { + LOG(DeviceEnumerator, Error) + << "Unable to stat '" << deviceNode << "'"; + return {}; + } + + struct udev_device *dev = udev_device_new_from_devnum(udev_, 'c', + st.st_rdev); + if (!dev) { + LOG(DeviceEnumerator, Error) + << "Unable to make device from devnum " << st.st_rdev; + return {}; + } + + std::string path{ udev_device_get_syspath(dev) }; + udev_device_unref(dev); + return path; +} + int DeviceEnumeratorUdev::populateMediaDevice(MediaDevice *media, DependencyMap *deps) { std::set children;