From patchwork Mon Jan 30 12:52:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1733890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=wHBXEZ49; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P57Qx6rq3z23hg for ; Mon, 30 Jan 2023 23:53:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB3643858423 for ; Mon, 30 Jan 2023 12:53:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB3643858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675083221; bh=onXoadCm2muk7Few/Y08HHZs4ki93txlKdmLX+SeAQc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=wHBXEZ49nTSoMVjKzzq8RP3h08Sh30T3PYo0p4XiYfBtMwGhkbIuD9MIN9bO4R3qI cmPJ/H5AYai4WF/7hZXxhVJqG6b+AsuIRGGoJttMpJFdnsudkqsJm+vMtmHrzAbpDt WzA66P9lu3r7dh9RCHrjd+4GZ6ctrhtqf6b07Svc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 36BEC3858D1E for ; Mon, 30 Jan 2023 12:52:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36BEC3858D1E Received: by mail-lf1-x131.google.com with SMTP id d30so18802360lfv.8 for ; Mon, 30 Jan 2023 04:52:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=onXoadCm2muk7Few/Y08HHZs4ki93txlKdmLX+SeAQc=; b=LwDvSSfXDch22ANEyz63NSaKmn8rxvZe+Zi2m2fmSNSp6t0DgMJ1Ryrr34aLpyrsCl uv6rhg8LOIvQeINbxRhFSfAWngu1Rji/A5j7iMSkPOE19cRI049fYkhKFcccnc6aLvIe blfwUjg0PbI1YGdu4t2gMm0sz6FxSJY4C4cMRWBHdPgJxCfO3hpwq9n7vm9XnRz78k5F 35qkduVpoxPmI3h23gCEEdqVus5mr/RRDwxoc9FRS2FDtOcvFYs1hE+ct5xghfkj6M0K ficoz1m6MBXavleKX4E3R51jcOMpEl1EbJ2sks7VUQGHbKWW1/DIuNLIQSMIqeuNauUZ JZGw== X-Gm-Message-State: AFqh2kpIWBQmTEg+Fv4X1SkNA+INrbFgqsM1mHRJlYffPJfaIxvUYutd W2QWgwksnTqkdYzDOPBfAT8= X-Google-Smtp-Source: AMrXdXurCLGggJrys+yeocEPUSKjClBJMIzicI3G1IF4svHu4C4nI5Yc2SV8sOJsBSI+L9plXC9meQ== X-Received: by 2002:a05:6512:1086:b0:4d4:d7fb:d13 with SMTP id j6-20020a056512108600b004d4d7fb0d13mr16336497lfg.35.1675083164793; Mon, 30 Jan 2023 04:52:44 -0800 (PST) Received: from surface-pro-6.. ([194.190.106.50]) by smtp.gmail.com with ESMTPSA id m4-20020a05651202e400b004d35fea344dsm847233lfq.202.2023.01.30.04.52.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 04:52:44 -0800 (PST) To: bug-hurd@gnu.org, libc-alpha@sourceware.org, samuel.thibault@gnu.org Cc: Sergey Bugaev Subject: [PATCH v2 1/3] hurd: Consolidate file_name_lookup implementation Date: Mon, 30 Jan 2023 15:52:14 +0300 Message-Id: <20230130125216.6254-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130095907.mlvp3pbmtarkhhql@begin> References: <20230130095907.mlvp3pbmtarkhhql@begin> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Instead of __file_name_lookup_at delegating to __file_name_lookup in simple cases, make __file_name_lookup_at deal with both cases, and have __file_name_lookup simply wrap __file_name_lookup_at. Signed-off-by: Sergey Bugaev --- hurd/hurdlookup.c | 10 ++-------- hurd/lookup-at.c | 51 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/hurd/hurdlookup.c b/hurd/hurdlookup.c index 49eac443..3cfe444f 100644 --- a/hurd/hurdlookup.c +++ b/hurd/hurdlookup.c @@ -16,6 +16,7 @@ . */ #include +#include #include #include #include @@ -220,14 +221,7 @@ weak_alias (__hurd_directory_name_split, hurd_directory_name_split) file_t __file_name_lookup (const char *file_name, int flags, mode_t mode) { - error_t err; - file_t result; - - err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0, - file_name, flags, mode & ~_hurd_umask, - &result); - - return err ? (__hurd_fail (err), MACH_PORT_NULL) : result; + return __file_name_lookup_at (AT_FDCWD, 0, file_name, flags, mode); } weak_alias (__file_name_lookup, file_name_lookup) diff --git a/hurd/lookup-at.c b/hurd/lookup-at.c index 6f30a067..25dab5a1 100644 --- a/hurd/lookup-at.c +++ b/hurd/lookup-at.c @@ -36,9 +36,6 @@ __file_name_lookup_at (int fd, int at_flags, if (err) return (__hurd_fail (err), MACH_PORT_NULL); - if (fd == AT_FDCWD || file_name[0] == '/') - return __file_name_lookup (file_name, flags, mode); - if (empty != 0 && file_name[0] == '\0') { enum retry_type doretry; @@ -56,22 +53,44 @@ __file_name_lookup_at (int fd, int at_flags, return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result; } - file_t startdir; - error_t use_init_port (int which, error_t (*operate) (mach_port_t)) + if (fd == AT_FDCWD || file_name[0] == '/') { - return (which == INIT_PORT_CWDIR ? (*operate) (startdir) - : _hurd_ports_use (which, operate)); + err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0, + file_name, flags, mode & ~_hurd_umask, + &result); + if (err) + { + __hurd_fail (err); + return MACH_PORT_NULL; + } + } + else + { + file_t startdir; + /* We need to look the file up relative to the given directory (and + not our cwd). For this to work, we supply our own wrapper for + _hurd_ports_use, which replaces cwd with our startdir. */ + error_t use_init_port (int which, error_t (*operate) (mach_port_t)) + { + return (which == INIT_PORT_CWDIR ? (*operate) (startdir) + : _hurd_ports_use (which, operate)); + } + + err = HURD_DPORT_USE (fd, (startdir = port, + __hurd_file_name_lookup (&use_init_port, + &__getdport, NULL, + file_name, + flags, + mode & ~_hurd_umask, + &result))); + if (err) + { + __hurd_dfail (fd, err); + return MACH_PORT_NULL; + } } - err = HURD_DPORT_USE (fd, (startdir = port, - __hurd_file_name_lookup (&use_init_port, - &__getdport, NULL, - file_name, - flags, - mode & ~_hurd_umask, - &result))); - - return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result; + return result; } file_t