[PATCH v2 034/113] fs: set current working dir directly when mounting root

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Mar 4 10:59:19 PST 2024


The default current working directory is the root directory, but this
can't be initialized statically, because the root directory is only
mounted at runtime. Therefore, the get_pwd accessor initializes the
current working directory on first access.

Instead we could just initialize them when we mount the root directory
and simplify the code a tiny bit.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/fs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index c034f2cb9a0d..bf527f1b2d9b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1651,11 +1651,6 @@ static inline void get_root(struct path *root)
 
 static inline void get_pwd(struct path *pwd)
 {
-	if (!cwd_dentry) {
-		cwd_dentry = d_root;
-		cwd_mnt = mnt_root;
-	}
-
 	pwd->dentry = cwd_dentry;
 	pwd->mnt = cwd_mnt;
 
@@ -3211,6 +3206,9 @@ int mount(const char *device, const char *fsname, const char *pathname,
 		fsdev->vfsmount.mountpoint = d_root;
 		fsdev->vfsmount.parent = &fsdev->vfsmount;
 		fsdev->path = xstrdup("/");
+
+		cwd_dentry = d_root;
+		cwd_mnt = mnt_root;
 	}
 
 	fsdev->vfsmount.mnt_root = fsdev->sb.s_root;
-- 
2.39.2




More information about the barebox mailing list