summaryrefslogtreecommitdiff
path: root/include/linux/fs.h
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2023-12-31 03:46:00 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-10-17 16:21:17 +0300
commit12aea49495d99bebf185275e7ff33deee4d849a9 (patch)
tree000a740a7f855a8f79484e1fb697852a0eef0cd2 /include/linux/fs.h
parent3322fa8f2aa40b0b3651034cd541647a600cc6c0 (diff)
downloadlinux-12aea49495d99bebf185275e7ff33deee4d849a9.tar.xz
fs: Create a generic is_dot_dotdot() utility
commit 42c3732fa8073717dd7d924472f1c0bc5b452fdc upstream. De-duplicate the same functionality in several places by hoisting the is_dot_dotdot() utility function into linux/fs.h. Suggested-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Acked-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r--include/linux/fs.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f2206c78755a..33c496130983 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3107,6 +3107,17 @@ extern bool path_is_under(const struct path *, const struct path *);
extern char *file_path(struct file *, char *, int);
+/**
+ * is_dot_dotdot - returns true only if @name is "." or ".."
+ * @name: file name to check
+ * @len: length of file name, in bytes
+ */
+static inline bool is_dot_dotdot(const char *name, size_t len)
+{
+ return len && unlikely(name[0] == '.') &&
+ (len == 1 || (len == 2 && name[1] == '.'));
+}
+
#include <linux/err.h>
/* needed for stackable file system support */