From 389ca018d1b3681d3a11e6a12fdbcd34b4904c33 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 12 Feb 2024 23:51:54 -0500 Subject: [PATCH] vfs: fix bug in `vfs_open` with leading `/` char --- fs/vfs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/vfs.c b/fs/vfs.c index e28c6fd..459ef51 100644 --- a/fs/vfs.c +++ b/fs/vfs.c @@ -70,6 +70,18 @@ struct file *vfs_open(const char *pathname, int *err) } memset(file, 0, sizeof(struct file)); + int len = strlen(pathname); + int inc = 0; + for (int i = 0; i < len; i++) { + if (pathname[i] == '/') + inc++; + else + break; + } + + if (inc < len) + pathname += inc; + /* start at root */ struct fs *fs = rootfs; struct vnode *cur_vnode = fs->root;