From nobody Sun Feb 8 22:35:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641913798; cv=none; d=zohomail.com; s=zohoarc; b=LX4YzARCBmXGR3zWBLU/Z+NLWuTCVzDL259ZnjDmlNqTE3ueitvRsryLSMj5G7sLkaP2810pP6bo5aHKvcEk1BYLER17yYGKx5l6RIcKtWdylxhHID9U4vi3IGGUy48MTv2ZGkmBOHReUBUEFGifa6O7T4SBDt1pwTWEBoe2PVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641913798; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C9AyKNzGKENy2BPxgLKGB+hFKK51Mm2oD341mOYK6aA=; b=QqVkWPnttAuW4ttdu0pmIHdDOdql+eiUXMhioDfNzmYW3hY7ujqqIPXH8Wpls0i+ooWeFku/omKcvCwdI22/sn0kpTjqMZsT3CPng1ei4KuO8lqvn84XrrJYnfZo1G4OeOVNrUSDAN6aw03AsMDmyEMPK07umUG4OTy9Pr/FLVM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641913798406439.88799004783505; Tue, 11 Jan 2022 07:09:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255844.438662 (Exim 4.92) (envelope-from ) id 1n7ImO-0007YN-P9; Tue, 11 Jan 2022 15:09:44 +0000 Received: by outflank-mailman (output) from mailman id 255844.438662; Tue, 11 Jan 2022 15:09:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7ImO-0007Xi-I7; Tue, 11 Jan 2022 15:09:44 +0000 Received: by outflank-mailman (input) for mailman id 255844; Tue, 11 Jan 2022 15:09:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ibg-0002Oa-ED for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 14:58:40 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ec3e09a2-72ee-11ec-9ce5-af14b9085ebd; Tue, 11 Jan 2022 15:58:23 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DAF8921639; Tue, 11 Jan 2022 14:58:22 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B2F4A13DDD; Tue, 11 Jan 2022 14:58:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SEeCKg6b3WH9eQAAMHmgww (envelope-from ); Tue, 11 Jan 2022 14:58:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ec3e09a2-72ee-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913102; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C9AyKNzGKENy2BPxgLKGB+hFKK51Mm2oD341mOYK6aA=; b=R0GKkNi+dhG4W5lbRM9+2Frk+rVnQIdIdPOS8v8+F5cg1HTIkgQ6Y2/3UjnpFCRPAvzP5m B9FDuzQpDzsnvybo9xP0Yqg7Jru3vd1W3D73Ff6vapQ7YP1JmJxUeMmNHTjZs94re/0DP5 8Q+Wk/oJuwX3UQnpVGwHfiG/VouWXf8= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 15/18] mini-os: introduce get_file_from_fd() Date: Tue, 11 Jan 2022 15:58:14 +0100 Message-Id: <20220111145817.22170-16-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111145817.22170-1-jgross@suse.com> References: <20220111145817.22170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641913800717100001 Content-Type: text/plain; charset="utf-8" Exporting the files[] array especially for components outside the mini-os source tree is limiting the ability to change any file handling in mini-os. Introduce a new function get_file_from_fd() to return the struct file pointer (or NULL) for a given file descriptor. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- include/lib.h | 1 + lib/sys.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/lib.h b/include/lib.h index 91364ba..7a0546b 100644 --- a/include/lib.h +++ b/include/lib.h @@ -198,6 +198,7 @@ struct file { =20 extern struct file files[]; =20 +struct file *get_file_from_fd(int fd); int alloc_fd(enum fd_type type); void close_all_files(void); extern struct thread *main_thread; diff --git a/lib/sys.c b/lib/sys.c index 6f2b026..0e6fe5d 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -98,6 +98,14 @@ struct file files[NOFILE] =3D { { .type =3D FTYPE_CONSOLE }, /* stderr */ }; =20 +struct file *get_file_from_fd(int fd) +{ + if ( fd < 0 || fd >=3D NOFILE ) + return NULL; + + return (files[fd].type =3D=3D FTYPE_NONE) ? NULL : files + fd; +} + DECLARE_WAIT_QUEUE_HEAD(event_queue); =20 int alloc_fd(enum fd_type type) --=20 2.26.2