Skip to content
Snippets Groups Projects
Commit 3bd235e9 authored by Raphael S. Carvalho's avatar Raphael S. Carvalho Committed by Pekka Enberg
Browse files

vfs: Add hierarchy support to directory entries


It will be useful to take better and safer VFS decisions in the future.
For example, avoiding code that uses the absolute path to determine something.

Signed-off-by: default avatarRaphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent e30bed5c
No related branches found
No related tags found
No related merge requests found
...@@ -137,7 +137,7 @@ int vfs_findroot(char *path, struct mount **mp, char **root); ...@@ -137,7 +137,7 @@ int vfs_findroot(char *path, struct mount **mp, char **root);
int fs_noop(void); int fs_noop(void);
struct dentry *dentry_alloc(struct vnode *vp, const char *path); struct dentry *dentry_alloc(struct dentry *parent_dp, struct vnode *vp, const char *path);
void dref(struct dentry *dp); void dref(struct dentry *dp);
void drele(struct dentry *dp); void drele(struct dentry *dp);
......
...@@ -59,7 +59,7 @@ dentry_hash(struct mount *mp, const char *path) ...@@ -59,7 +59,7 @@ dentry_hash(struct mount *mp, const char *path)
struct dentry * struct dentry *
dentry_alloc(struct vnode *vp, const char *path) dentry_alloc(struct dentry *parent_dp, struct vnode *vp, const char *path)
{ {
struct mount *mp = vp->v_mount; struct mount *mp = vp->v_mount;
struct dentry *dp = calloc(sizeof(*dp), 1); struct dentry *dp = calloc(sizeof(*dp), 1);
...@@ -73,6 +73,12 @@ dentry_alloc(struct vnode *vp, const char *path) ...@@ -73,6 +73,12 @@ dentry_alloc(struct vnode *vp, const char *path)
dp->d_vnode = vp; dp->d_vnode = vp;
dp->d_mount = mp; dp->d_mount = mp;
dp->d_path = strdup(path); dp->d_path = strdup(path);
if (parent_dp) {
dref(parent_dp);
}
dp->d_parent = parent_dp;
vn_add_name(vp, dp); vn_add_name(vp, dp);
mutex_lock(&dentry_hash_lock); mutex_lock(&dentry_hash_lock);
...@@ -126,6 +132,10 @@ drele(struct dentry *dp) ...@@ -126,6 +132,10 @@ drele(struct dentry *dp)
mutex_unlock(&dentry_hash_lock); mutex_unlock(&dentry_hash_lock);
if (dp->d_parent) {
drele(dp->d_parent);
}
vrele(dp->d_vnode); vrele(dp->d_vnode);
free(dp->d_path); free(dp->d_path);
...@@ -211,7 +221,7 @@ namei(char *path, struct dentry **dpp) ...@@ -211,7 +221,7 @@ namei(char *path, struct dentry **dpp)
return error; return error;
} }
dp = dentry_alloc(vp, node); dp = dentry_alloc(ddp, vp, node);
vput(vp); vput(vp);
if (!dp) { if (!dp) {
......
...@@ -173,7 +173,7 @@ sys_mount(char *dev, char *dir, char *fsname, int flags, void *data) ...@@ -173,7 +173,7 @@ sys_mount(char *dev, char *dir, char *fsname, int flags, void *data)
vp->v_flags = VROOT; vp->v_flags = VROOT;
vp->v_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR; vp->v_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
mp->m_root = dentry_alloc(vp, "/"); mp->m_root = dentry_alloc(NULL, vp, "/");
if (!mp->m_root) { if (!mp->m_root) {
vput(vp); vput(vp);
goto err3; goto err3;
...@@ -318,6 +318,11 @@ sys_pivot_root(const char *new_root, const char *put_old) ...@@ -318,6 +318,11 @@ sys_pivot_root(const char *new_root, const char *put_old)
} }
newmp->m_covered = NULL; newmp->m_covered = NULL;
if (newmp->m_root->d_parent) {
drele(newmp->m_root->d_parent);
}
newmp->m_root->d_parent = NULL;
free(oldmp); free(oldmp);
strlcpy(newmp->m_path, "/", sizeof(newmp->m_path)); strlcpy(newmp->m_path, "/", sizeof(newmp->m_path));
......
...@@ -777,7 +777,7 @@ sys_link(char *oldpath, char *newpath) ...@@ -777,7 +777,7 @@ sys_link(char *oldpath, char *newpath)
goto out1; goto out1;
/* Map newpath into dentry hash with the same vnode as oldpath */ /* Map newpath into dentry hash with the same vnode as oldpath */
if (!(newdp = dentry_alloc(vp, newpath))) { if (!(newdp = dentry_alloc(newdirdp, vp, newpath))) {
error = ENOMEM; error = ENOMEM;
goto out1; goto out1;
} }
......
...@@ -19,6 +19,7 @@ struct dentry { ...@@ -19,6 +19,7 @@ struct dentry {
char *d_path; /* pointer to path in fs */ char *d_path; /* pointer to path in fs */
struct vnode *d_vnode; struct vnode *d_vnode;
struct mount *d_mount; struct mount *d_mount;
struct dentry *d_parent; /* pointer to parent */
LIST_ENTRY(dentry) d_names_link; /* link fo vnode::d_names */ LIST_ENTRY(dentry) d_names_link; /* link fo vnode::d_names */
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment