[{"id":11685,"web_url":"https://patchwork.libcamera.org/comment/11685/","msgid":"<20200729072824.i4bz6up4yuimyggu@uno.localdomain>","date":"2020-07-29T07:28:24","subject":"Re: [libcamera-devel] [PATCH v3 1/5] libcamera: v4l2_device: Add\n\tmethod to lookup device path","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Wed, Jul 29, 2020 at 01:42:21AM +0200, Niklas Söderlund wrote:\n> Add a method to lookup a V4L2 devices path in sysfs.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  include/libcamera/internal/v4l2_device.h |  1 +\n>  src/libcamera/v4l2_device.cpp            | 24 ++++++++++++++++++++++++\n>  2 files changed, 25 insertions(+)\n>\n> diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\n> index bf643f2ec966bb33..3b605aab343b3b94 100644\n> --- a/include/libcamera/internal/v4l2_device.h\n> +++ b/include/libcamera/internal/v4l2_device.h\n> @@ -30,6 +30,7 @@ public:\n>  \tint setControls(ControlList *ctrls);\n>\n>  \tconst std::string &deviceNode() const { return deviceNode_; }\n> +\tstd::string devicePath() const;\n>\n>  protected:\n>  \tV4L2Device(const std::string &deviceNode);\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 56ea1ddda2c1425f..c186f246dbfaff66 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -9,6 +9,7 @@\n>\n>  #include <fcntl.h>\n>  #include <iomanip>\n> +#include <limits.h>\n>  #include <string.h>\n>  #include <sys/ioctl.h>\n>  #include <sys/syscall.h>\n> @@ -350,6 +351,29 @@ int V4L2Device::setControls(ControlList *ctrls)\n>  \treturn ret;\n>  }\n>\n> +/**\n> + * \\brief Retrieve the device path\n\n\"the device path in sysfs\" or \"under /sys\" not sure which one is the\nmost correct one. But I think it's worth pointing it out as when I\nread \"the device path\" I thought about the device node path in /dev/\n\n> + *\n> + * The device path describes the device backing the V4L2 device.\n\nsame\n\n> + *\n> + * \\todo When switching to C++17 use std::filesystem:: in the implementation.\n> + * \\todo Query udev for this information as the path created for vdev here\n> + * migh not be correct.\n> + *\n> + * \\return The device path\n\nsame here\n\n> + */\n> +std::string V4L2Device::devicePath() const\n> +{\n> +\tstd::string vdev = basename(deviceNode_.c_str());\n> +\tstd::string sysfs = \"/sys/class/video4linux/\" + vdev + \"/device\";\n> +\n> +\tchar path[PATH_MAX];\n> +\tif (!realpath(sysfs.c_str(), path))\n> +\t\tLOG(V4L2, Fatal) << \"Can not resolve path for \" << deviceNode_;\n> +\n> +\treturn path;\n> +}\n> +\n\nI think Laurent had a comment suggesting to have this go through the\ndevice enumerator sub-classes. I can't tell why both him and you say\nthat \"the path here might not be correct\", so I'll just re-state his\ncomment here.\n\nFrom my side\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n>  /**\n>   * \\brief Perform an IOCTL system call on the device node\n>   * \\param[in] request The IOCTL request code\n> --\n> 2.27.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 58E0BBD878\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Jul 2020 07:24:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F393A613C6;\n\tWed, 29 Jul 2020 09:24:45 +0200 (CEST)","from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 328BC605B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jul 2020 09:24:45 +0200 (CEST)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 74D441BF212;\n\tWed, 29 Jul 2020 07:24:44 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","Date":"Wed, 29 Jul 2020 09:28:24 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20200729072824.i4bz6up4yuimyggu@uno.localdomain>","References":"<20200728233744.3503740-1-niklas.soderlund@ragnatech.se>\n\t<20200728234225.3505868-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200728234225.3505868-1-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v3 1/5] libcamera: v4l2_device: Add\n\tmethod to lookup device path","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]