Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4275901rwb; Sun, 7 Aug 2022 20:06:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR7PD6Df7m3wmyavtJHts4qzyLfUtF0t1Hb4u02HCqtUmssimYeRHFX0gnAlg437fD7lflo1 X-Received: by 2002:aa7:cac7:0:b0:43a:c5ba:24a6 with SMTP id l7-20020aa7cac7000000b0043ac5ba24a6mr15989994edt.84.1659927980183; Sun, 07 Aug 2022 20:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659927980; cv=none; d=google.com; s=arc-20160816; b=WEyBce97HRo3mQ8VEXsbTKUz4LGgq/QHSIs8XcEiYTJ7yTXbXr3h82isDZUQc8QHkt pyxyk5qd7xKXitBSalIrnB4Y6F14EcsJRNzmKDG98VgIt/K4Q2K1qXCrnq9mULl1K9ZO z2LDwnMrcqtQQh0xEZJ6U3yNWg3McpL0uQgvyv3slcY7s986EsrwjUY58wVaHkggfYN0 YBTPKu+lSbqee1N8Yw/NZk7mH902Ai3xKyC8TfcMDiYtQx1OXVDM1JkEY/YfR+9jUt1q kwwMOhqxSS8/o7fcfTcZy7yE+ESeWVAQG9IPS5jgXvD0n8L/ufm/Gkk+Bl5jCOtqFUcf W5TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PdlpiFKX35KK8r3Bv1PVQ9ch5aGjfo6klq0s7Ja/ZcU=; b=Z0xPOLgLaaSaP/cUZbNthgKWKkWX0V6Tqlfy6XCF5mtBfvBMBao5K+SLgMBVPWkCjC 6zPE+wBSCFkekn7Qs+78O3eoigQh5SlVzKR7lGwsKZjsJrUUg7BszOrZpH6voH7xYBp4 KTjNg9+U811hZ0Sm93Zu8UHLui8tOPhIMJvhc+lX9UfcmKb+XaQmtUUCj0y6dtmx7gPE 066riBc7/Ab7lg248VMqCJpBBztWkuwDPqHTpeGIWwIWSqKSn2tT+mxLSeqVHKjAnpiC aBRzQO10i014OTYMJ0zg2NG0RYs5bM/RGh8IZ1nK7DyxEm9LjHDmmQTXfNuE45AK1RUX tWjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=oavNtuqi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a170906580b00b007309383490esi8157468ejq.122.2022.08.07.20.05.54; Sun, 07 Aug 2022 20:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=oavNtuqi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243992AbiHHCmW (ORCPT + 99 others); Sun, 7 Aug 2022 22:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241934AbiHHClj (ORCPT ); Sun, 7 Aug 2022 22:41:39 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E615B25D5 for ; Sun, 7 Aug 2022 19:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=PdlpiFKX35KK8r3Bv1PVQ9ch5aGjfo6klq0s7Ja/ZcU=; b=oavNtuqiUYqRRZhJ0sIwHV2ERi QtwceMggiiUt4buzv5kNGHnxwn78DqQLJ9+zdX3PyUGRwKMMT3uQ9a14miL94tKa8TDlz5IMHHpnv CvymKXqKOcfi9tdYZHtcsaGyJI6dp4ahgWSNVtOq/ZRG9gGAoE2ZRR8FT7RCCGOgebyhM/p4wXPb2 XmyW8qkOjaWxz7nlCbLBKTuX3JFkcZ4vAxSnUH1pJNZyk7fZ0Z/AN0QDUbHiQuGRn6OdSEPOPQw9y ulUb13Y3kdgROubNzvA3OSf21ei2nqJVFl86XRx1ceCMc7VAWy/SD8vBX7aqpwkDSduDQwxzJPT1D OBUNPUaw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKshy-00DVSp-Vf; Mon, 08 Aug 2022 02:41:35 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org, pmladek@suse.com, Kent Overstreet Cc: Alexander Viro Subject: [PATCH v5 29/32] d_path: prt_path() Date: Mon, 8 Aug 2022 03:41:25 +0100 Message-Id: <20220808024128.3219082-30-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808024128.3219082-1-willy@infradead.org> References: <20220808024128.3219082-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet This implements a new printbuf version of d_path()/mangle_path(), which will replace the seq_buf version. Part of what we're trying to do with printbufs is standardizing a calling convention so they don't have to live in lib/vsprintf.c, and can instead with the code for the types they're printing - so this patch adds prt_path() to d_path.c, another patch will switch vsprintf.c to use it. Signed-off-by: Kent Overstreet Cc: Alexander Viro --- fs/d_path.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/dcache.h | 1 + 2 files changed, 36 insertions(+) diff --git a/fs/d_path.c b/fs/d_path.c index e4e0ebad1f15..1bd9e85f2f65 100644 --- a/fs/d_path.c +++ b/fs/d_path.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "mount.h" @@ -294,6 +295,40 @@ char *d_path(const struct path *path, char *buf, int buflen) } EXPORT_SYMBOL(d_path); +/** + * prt_path - format a path for output + * @out: printbuf to output to + * @path: path to write into the sequence buffer. + * @esc: set of characters to escape in the output + * + * Write a path name into the sequence buffer. + * + * Returns 0 on success, or error code from d_path + */ +int prt_path(struct printbuf *out, const struct path *path, const char *esc) +{ + char *p, *buf; + size_t size; +again: + buf = out->buf + out->pos; + size = printbuf_remaining_size(out); + + p = d_path(path, buf, size); + if (IS_ERR(p)) { + printbuf_make_room(out, max_t(size_t, 64, size * 2)); + if (printbuf_remaining_size(out) > size) + goto again; + + return PTR_ERR(p); + } + + p = mangle_path(buf, p, esc); + if (p) + out->pos += p - buf; + return 0; +} +EXPORT_SYMBOL(prt_path); + /* * Helper function for dentry_operations.d_dname() members */ diff --git a/include/linux/dcache.h b/include/linux/dcache.h index c73e5e327e76..bdd5940aa75a 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -293,6 +293,7 @@ extern char *d_absolute_path(const struct path *, char *, int); extern char *d_path(const struct path *, char *, int); extern char *dentry_path_raw(const struct dentry *, char *, int); extern char *dentry_path(const struct dentry *, char *, int); +extern int prt_path(struct printbuf *, const struct path *, const char *); /* Allocation counts.. */ -- 2.35.1