aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-04-25 04:37:32 +0000
committersotech117 <michael_foiani@brown.edu>2024-04-25 04:37:32 +0000
commit47320018d6da07ccda409a04490d6132eb94861c (patch)
tree8c9048ed9f96e7c92f5ae212be2cbf23d4143c03
parent88db52baebd10ab1c2643f214ab9d44edcdb0851 (diff)
cleanup edge cases
-rw-r--r--kernel/fs/namev.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/kernel/fs/namev.c b/kernel/fs/namev.c
index 5146165..dd44450 100644
--- a/kernel/fs/namev.c
+++ b/kernel/fs/namev.c
@@ -232,11 +232,23 @@ long namev_dir(vnode_t *base, const char *path, vnode_t **res_vnode,
vref(dir);
// Tokenize the path
- char *token = NULL;
+ const char *token = NULL;
size_t len = 0;
+
while ((token = namev_tokenize(&path, &len)) && len > 0)
{
- if (path == NULL || *path == '\0' || (*path == '/' && *(path + 1) == '\0'))
+ if (path == NULL || *path == '\0')
+ {
+ break;
+ }
+
+ // Check if the whole path is a sequence of '/' then a null
+ int index = 0;
+ while (path[index] == '/')
+ {
+ index++;
+ }
+ if (path[index] == '\0')
{
break;
}
@@ -259,16 +271,9 @@ long namev_dir(vnode_t *base, const char *path, vnode_t **res_vnode,
return err;
}
- *res_vnode = dir;
- *name = token;
- *namelen = len;
-
// Reduce refcount and move to the next token
- if (next)
- {
- vput(&dir);
- dir = next;
- }
+ vput(&dir);
+ dir = next;
}
// Check if it's a directory
@@ -278,11 +283,10 @@ long namev_dir(vnode_t *base, const char *path, vnode_t **res_vnode,
return -ENOTDIR;
}
- // Assign the basename
+ // Assign the ret vars
*res_vnode = dir;
*name = token;
*namelen = len;
-
return 0;
}
/*