[{"id":21471,"web_url":"https://patchwork.libcamera.org/comment/21471/","msgid":"<20211130220839.beonsws2fren622i@uno.localdomain>","date":"2021-11-30T22:08:39","subject":"Re: [libcamera-devel] [PATCH v4.1 03/22] libcamera: base:\n\tfile_descriptor: Move inode() function to frame_buffer.cpp","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Tue, Nov 30, 2021 at 12:27:16PM +0200, Laurent Pinchart wrote:\n> The inode() function has always been a bit of an outcast in the\n> FileDescriptor class, as it's not related to the core feature provided\n> by FileDescriptor, a shared ownership wrapper around file descriptors.\n> As it's only used in the FrameBuffer implementation, move it to\n> frame_buffer.cpp as a static function.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>\n\nThanks\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\n> ---\n> Changes since v4:\n>\n> - Drop leftover #include and forward declaration\n>\n> Changes since v3:\n>\n> - Move the inode function to frame_buffer.cpp\n> ---\n>  include/libcamera/base/file_descriptor.h |  3 ---\n>  src/libcamera/base/file_descriptor.cpp   | 25 ---------------------\n>  src/libcamera/framebuffer.cpp            | 28 ++++++++++++++++++++++--\n>  3 files changed, 26 insertions(+), 30 deletions(-)\n>\n> diff --git a/include/libcamera/base/file_descriptor.h b/include/libcamera/base/file_descriptor.h\n> index 8d764f8b4a26..5d1594e80801 100644\n> --- a/include/libcamera/base/file_descriptor.h\n> +++ b/include/libcamera/base/file_descriptor.h\n> @@ -8,7 +8,6 @@\n>  #pragma once\n>\n>  #include <memory>\n> -#include <sys/types.h>\n>\n>  namespace libcamera {\n>\n> @@ -28,8 +27,6 @@ public:\n>  \tint fd() const { return fd_ ? fd_->fd() : -1; }\n>  \tFileDescriptor dup() const;\n>\n> -\tino_t inode() const;\n> -\n>  private:\n>  \tclass Descriptor\n>  \t{\n> diff --git a/src/libcamera/base/file_descriptor.cpp b/src/libcamera/base/file_descriptor.cpp\n> index f5f87c56eee8..98d4b4bfd24f 100644\n> --- a/src/libcamera/base/file_descriptor.cpp\n> +++ b/src/libcamera/base/file_descriptor.cpp\n> @@ -8,7 +8,6 @@\n>  #include <libcamera/base/file_descriptor.h>\n>\n>  #include <string.h>\n> -#include <sys/stat.h>\n>  #include <sys/types.h>\n>  #include <unistd.h>\n>  #include <utility>\n> @@ -223,30 +222,6 @@ FileDescriptor FileDescriptor::dup() const\n>  \treturn FileDescriptor(fd());\n>  }\n>\n> -/**\n> - * \\brief Retrieve the file descriptor inode\n> - *\n> - * \\todo Should this move to the File class ?\n> - *\n> - * \\return The file descriptor inode on success, or 0 on error\n> - */\n> -ino_t FileDescriptor::inode() const\n> -{\n> -\tif (!isValid())\n> -\t\treturn 0;\n> -\n> -\tstruct stat st;\n> -\tint ret = fstat(fd_->fd(), &st);\n> -\tif (ret < 0) {\n> -\t\tret = -errno;\n> -\t\tLOG(FileDescriptor, Fatal)\n> -\t\t\t<< \"Failed to fstat() fd: \" << strerror(-ret);\n> -\t\treturn 0;\n> -\t}\n> -\n> -\treturn st.st_ino;\n> -}\n> -\n>  FileDescriptor::Descriptor::Descriptor(int fd, bool duplicate)\n>  {\n>  \tif (!duplicate) {\n> diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp\n> index 337ea1155a38..fcb475c21df4 100644\n> --- a/src/libcamera/framebuffer.cpp\n> +++ b/src/libcamera/framebuffer.cpp\n> @@ -8,6 +8,9 @@\n>  #include <libcamera/framebuffer.h>\n>  #include \"libcamera/internal/framebuffer.h\"\n>\n> +#include <sys/stat.h>\n> +\n> +#include <libcamera/base/file_descriptor.h>\n>  #include <libcamera/base/log.h>\n>\n>  /**\n> @@ -207,6 +210,27 @@ FrameBuffer::Private::Private()\n>   * \\brief The plane length in bytes\n>   */\n>\n> +namespace {\n> +\n> +ino_t fileDescriptorInode(const FileDescriptor &fd)\n> +{\n> +\tif (!fd.isValid())\n> +\t\treturn 0;\n> +\n> +\tstruct stat st;\n> +\tint ret = fstat(fd.fd(), &st);\n> +\tif (ret < 0) {\n> +\t\tret = -errno;\n> +\t\tLOG(Buffer, Fatal)\n> +\t\t\t<< \"Failed to fstat() fd: \" << strerror(-ret);\n> +\t\treturn 0;\n> +\t}\n> +\n> +\treturn st.st_ino;\n> +}\n> +\n> +} /* namespace */\n> +\n>  /**\n>   * \\brief Construct a FrameBuffer with an array of planes\n>   * \\param[in] planes The frame memory planes\n> @@ -236,8 +260,8 @@ FrameBuffer::FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie)\n>  \t\t */\n>  \t\tif (plane.fd.fd() != planes_[0].fd.fd()) {\n>  \t\t\tif (!inode)\n> -\t\t\t\tinode = planes_[0].fd.inode();\n> -\t\t\tif (plane.fd.inode() != inode) {\n> +\t\t\t\tinode = fileDescriptorInode(planes_[0].fd);\n> +\t\t\tif (fileDescriptorInode(plane.fd) != inode) {\n>  \t\t\t\tisContiguous = false;\n>  \t\t\t\tbreak;\n>  \t\t\t}\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","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 B3116BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 22:07:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EAFF160720;\n\tTue, 30 Nov 2021 23:07:49 +0100 (CET)","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 32D7D605C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 23:07:48 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 18D481BF209;\n\tTue, 30 Nov 2021 22:07:46 +0000 (UTC)"],"Date":"Tue, 30 Nov 2021 23:08:39 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20211130220839.beonsws2fren622i@uno.localdomain>","References":"<20211130033820.18235-4-laurent.pinchart@ideasonboard.com>\n\t<20211130102716.1674-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211130102716.1674-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v4.1 03/22] libcamera: base:\n\tfile_descriptor: Move inode() function to frame_buffer.cpp","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","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]