VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
author: Christoph Hellwig <hch@lst.de> 2020-07-22 11:25:21 +0200 committer: Christoph Hellwig <hch@lst.de> 2020-07-31 08:17:52 +0200 commit: db63f1e315384590b979f8f74abd1b5363b69894 parent: 20cce026c3e0972017b9cb4a7cccfb8cacf187d5
Commit Summary:
init: add an init_chdir helper
Diffstat:
1 file changed, 15 insertions, 0 deletions
diff --git a/fs/init.c b/fs/init.c
index eabd9ed2b510..64d4e12eba93 100644
--- a/fs/init.c
+++ b/fs/init.c
@@ -7,6 +7,7 @@
 #include <linux/mount.h>
 #include <linux/namei.h>
 #include <linux/fs.h>
+#include <linux/fs_struct.h>
 #include <linux/init_syscalls.h>
 #include "internal.h"
 
@@ -38,6 +39,21 @@ int __init init_umount(const char *name, int flags)
 	return path_umount(&path, flags);
 }
 
+int __init init_chdir(const char *filename)
+{
+	struct path path;
+	int error;
+
+	error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
+	if (error)
+		return error;
+	error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
+	if (!error)
+		set_fs_pwd(current->fs, &path);
+	path_put(&path);
+	return error;
+}
+
 int __init init_unlink(const char *pathname)
 {
 	return do_unlinkat(AT_FDCWD, getname_kernel(pathname));