From patchwork Sun Nov 28 23:57:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14818 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 03C78C324F for ; Sun, 28 Nov 2021 23:58:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4EDE060596; Mon, 29 Nov 2021 00:58:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hTso7Poh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B312060591 for ; Mon, 29 Nov 2021 00:58:22 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 33965730; Mon, 29 Nov 2021 00:58:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1638143902; bh=vouL4op4AAtLX9vNiPG1Fp1rivj6Kz38JJ/WSGtPvWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTso7PohVggGe+nGoOZoLQwUiWOSCPVZdFDNvLqwcKccDwVEne9Z1j7c6EOA1Erli uFcCrQnSnY3YYGcgZWGmSgipIJh+lHtWCyQyZ96fzP8S1eSTFQ8vCaXjU7NimB3YLr eNOVK4tlUnkUkDBw/MUhOp0fkfEKf3MmYnKPtDG4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Nov 2021 01:57:38 +0200 Message-Id: <20211128235752.10836-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211128235752.10836-1-laurent.pinchart@ideasonboard.com> References: <20211128235752.10836-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 03/17] libcamera: base: file_descriptor: Move inode() function to File class 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" The inode() function has always been a bit of an outcast in the FileDescriptor class, as it's not related to the core feature provided by FileDescriptor, a shared ownership wrapper around file descriptors. Move it to the File class instead. It may not be a perfect fit there either, but File is a private class, so the inode() function is at least not part of the public API anymore. Signed-off-by: Laurent Pinchart --- include/libcamera/base/file.h | 3 +++ include/libcamera/base/file_descriptor.h | 3 --- src/libcamera/base/file.cpp | 23 ++++++++++++++++++++++ src/libcamera/base/file_descriptor.cpp | 25 ------------------------ src/libcamera/framebuffer.cpp | 5 +++-- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/include/libcamera/base/file.h b/include/libcamera/base/file.h index 55e8edd934d4..996751a7ab72 100644 --- a/include/libcamera/base/file.h +++ b/include/libcamera/base/file.h @@ -20,6 +20,8 @@ namespace libcamera { +class FileDescriptor; + class File { public: @@ -66,6 +68,7 @@ public: bool unmap(uint8_t *addr); static bool exists(const std::string &name); + static ino_t inode(const FileDescriptor &fd); private: LIBCAMERA_DISABLE_COPY(File) diff --git a/include/libcamera/base/file_descriptor.h b/include/libcamera/base/file_descriptor.h index 8d764f8b4a26..5d1594e80801 100644 --- a/include/libcamera/base/file_descriptor.h +++ b/include/libcamera/base/file_descriptor.h @@ -8,7 +8,6 @@ #pragma once #include -#include namespace libcamera { @@ -28,8 +27,6 @@ public: int fd() const { return fd_ ? fd_->fd() : -1; } FileDescriptor dup() const; - ino_t inode() const; - private: class Descriptor { diff --git a/src/libcamera/base/file.cpp b/src/libcamera/base/file.cpp index ae4be1f95fa6..7043f9461cf7 100644 --- a/src/libcamera/base/file.cpp +++ b/src/libcamera/base/file.cpp @@ -14,6 +14,7 @@ #include #include +#include #include /** @@ -472,4 +473,26 @@ bool File::exists(const std::string &name) return !S_ISDIR(st.st_mode); } +/** + * \brief Retrieve the inode of a FileDescriptor + * + * \return The file descriptor inode on success, or 0 on error + */ +ino_t File::inode(const FileDescriptor &fd) +{ + if (!fd.isValid()) + return 0; + + struct stat st; + int ret = fstat(fd.fd(), &st); + if (ret < 0) { + ret = -errno; + LOG(File, Fatal) + << "Failed to fstat() fd: " << strerror(-ret); + return 0; + } + + return st.st_ino; +} + } /* namespace libcamera */ diff --git a/src/libcamera/base/file_descriptor.cpp b/src/libcamera/base/file_descriptor.cpp index f5f87c56eee8..98d4b4bfd24f 100644 --- a/src/libcamera/base/file_descriptor.cpp +++ b/src/libcamera/base/file_descriptor.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -223,30 +222,6 @@ FileDescriptor FileDescriptor::dup() const return FileDescriptor(fd()); } -/** - * \brief Retrieve the file descriptor inode - * - * \todo Should this move to the File class ? - * - * \return The file descriptor inode on success, or 0 on error - */ -ino_t FileDescriptor::inode() const -{ - if (!isValid()) - return 0; - - struct stat st; - int ret = fstat(fd_->fd(), &st); - if (ret < 0) { - ret = -errno; - LOG(FileDescriptor, Fatal) - << "Failed to fstat() fd: " << strerror(-ret); - return 0; - } - - return st.st_ino; -} - FileDescriptor::Descriptor::Descriptor(int fd, bool duplicate) { if (!duplicate) { diff --git a/src/libcamera/framebuffer.cpp b/src/libcamera/framebuffer.cpp index 337ea1155a38..f5bcf107d7aa 100644 --- a/src/libcamera/framebuffer.cpp +++ b/src/libcamera/framebuffer.cpp @@ -8,6 +8,7 @@ #include #include "libcamera/internal/framebuffer.h" +#include #include /** @@ -236,8 +237,8 @@ FrameBuffer::FrameBuffer(const std::vector &planes, unsigned int cookie) */ if (plane.fd.fd() != planes_[0].fd.fd()) { if (!inode) - inode = planes_[0].fd.inode(); - if (plane.fd.inode() != inode) { + inode = File::inode(planes_[0].fd); + if (File::inode(plane.fd) != inode) { isContiguous = false; break; }