summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-06-01 14:44:27 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-06-09 15:13:56 -0400
commit9cb7d31b94633e65d31bd22fc33a48fb767ca0ee (patch)
tree2d07fffcc281054cfb86467a0e1fe4c44615949d
parent4251c717029ca9a0803c0b3e0eeb8853f46530ac (diff)
d_path: prt_path()
This implements a new printbuf version of d_path()/mangle_path(), which will replace the seq_buf version. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/d_path.c35
-rw-r--r--include/linux/dcache.h1
2 files changed, 36 insertions, 0 deletions
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 <linux/fs_struct.h>
#include <linux/fs.h>
#include <linux/slab.h>
+#include <linux/printbuf.h>
#include <linux/prefetch.h>
#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 62ddf677e777..6c661059a55b 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -294,6 +294,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.. */