aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/fs.h
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2023-12-30 19:46:00 -0500
committerChuck Lever <chuck.lever@oracle.com>2024-01-23 10:58:56 -0500
commit42c3732fa8073717dd7d924472f1c0bc5b452fdc (patch)
treed62658e93e5fe91a8e0e75b7c1ab90d384c90e54 /include/linux/fs.h
parent9473c4450e9c83d890d435577a3776d925fa748c (diff)
downloadlinux-42c3732fa8073717dd7d924472f1c0bc5b452fdc.tar.gz
fs: Create a generic is_dot_dotdot() utility
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>
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 98b7a7a8c42e36..baa64344a30823 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2846,6 +2846,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 */