From patchwork Thu Sep 2 04:22:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13598 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 96FE9C3241 for ; Thu, 2 Sep 2021 04:23:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D4AC069178; Thu, 2 Sep 2021 06:23:25 +0200 (CEST) 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="slGFA+kL"; 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 EE9B369165 for ; Thu, 2 Sep 2021 06:23:23 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 836A01516; Thu, 2 Sep 2021 06:23:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630556603; bh=xlimUmJ5zsZKLiB/zii3QqC3WblIuvqwIrzvJQEqS8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slGFA+kLNpOyfVRNgFC15eS1fQQcsqnxkOyUjKFduw2I/y5JXK5VkCCjcHz3hzfXk B/lhxUtW6/ApSYrVUUQCeiocRFwxmqYpmV5DoDoiIOXDix9hucoM2sGiglVSUmGEyV 6s0LZ3ABLFCc1J4qCVZvBzwM+hQoZrOnSJ7N9R8I= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Sep 2021 07:22:53 +0300 Message-Id: <20210902042303.2254-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> References: <20210902042303.2254-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v1 02/12] libcamera: file_descriptor: Add a function to retrieve the inode 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 is useful to check if two file descriptors refer to the same file. Add a function to retrieve it. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/file_descriptor.h | 3 +++ src/libcamera/file_descriptor.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/libcamera/file_descriptor.h b/include/libcamera/file_descriptor.h index d514aac7697b..988f9b7a3d25 100644 --- a/include/libcamera/file_descriptor.h +++ b/include/libcamera/file_descriptor.h @@ -8,6 +8,7 @@ #define __LIBCAMERA_FILE_DESCRIPTOR_H__ #include +#include namespace libcamera { @@ -27,6 +28,8 @@ public: int fd() const { return fd_ ? fd_->fd() : -1; } FileDescriptor dup() const; + ino_t inode() const; + private: class Descriptor { diff --git a/src/libcamera/file_descriptor.cpp b/src/libcamera/file_descriptor.cpp index 9f9ebc81f738..d55e2b100b6d 100644 --- a/src/libcamera/file_descriptor.cpp +++ b/src/libcamera/file_descriptor.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include @@ -221,6 +223,26 @@ 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 (!fd_ || fd_->fd() == -1) + return 0; + + struct stat st; + int ret = fstat(fd_->fd(), &st); + if (ret < 0) + return 0; + + return st.st_ino; +} + FileDescriptor::Descriptor::Descriptor(int fd, bool duplicate) { if (!duplicate) {