summaryrefslogtreecommitdiff
path: root/include/linux/fs.h
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-04-30 13:54:46 +0200
committerChristian Brauner <brauner@kernel.org>2024-06-27 18:31:19 +0200
commit1bc6d4452d5c91beb09e37a98a590808e1997b79 (patch)
tree27c0e8677f2708edba24be504469954806a1189e /include/linux/fs.h
parent9fb9ff7ed1656dbd2168ebfc21b8c33666a994fa (diff)
fs: new helper vfs_empty_path()
Make it possible to quickly check whether AT_EMPTY_PATH is valid. Note, after some discussion we decided to also allow NULL to be passed instead of requiring the empty string. Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r--include/linux/fs.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 942cb11dba96..5ff362277834 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3631,4 +3631,21 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,
extern int generic_fadvise(struct file *file, loff_t offset, loff_t len,
int advice);
+static inline bool vfs_empty_path(int dfd, const char __user *path)
+{
+ char c;
+
+ if (dfd < 0)
+ return false;
+
+ /* We now allow NULL to be used for empty path. */
+ if (!path)
+ return true;
+
+ if (unlikely(get_user(c, path)))
+ return false;
+
+ return !c;
+}
+
#endif /* _LINUX_FS_H */