Add a new function devfs_parent_dirent() for resolving devfs parent

directory entry. Use the new function in devfs_fqpn(), devfs_lookupx()
and devfs_vptocnp() instead of manually resolving the parent entry.

Reviewed by:	kib
This commit is contained in:
jh 2010-06-09 15:29:12 +00:00
parent 0556dc425f
commit bc3fa141fa
3 changed files with 32 additions and 9 deletions

View File

@ -180,6 +180,7 @@ void devfs_populate (struct devfs_mount *dm);
void devfs_cleanup (struct devfs_mount *dm);
void devfs_unmount_final(struct devfs_mount *mp);
struct devfs_dirent *devfs_newdirent (char *name, int namelen);
struct devfs_dirent *devfs_parent_dirent(struct devfs_dirent *de);
struct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
struct devfs_dirent *devfs_find (struct devfs_dirent *dd, const char *name, int namelen);

View File

@ -197,6 +197,26 @@ devfs_newdirent(char *name, int namelen)
return (de);
}
struct devfs_dirent *
devfs_parent_dirent(struct devfs_dirent *de)
{
if (de->de_dirent->d_type != DT_DIR)
return (de->de_dir);
if (de->de_flags & (DE_DOT | DE_DOTDOT))
return (NULL);
de = TAILQ_FIRST(&de->de_dlist); /* "." */
if (de == NULL)
return (NULL);
de = TAILQ_NEXT(de, de_list); /* ".." */
if (de == NULL)
return (NULL);
return (de->de_dir);
}
struct devfs_dirent *
devfs_vmkdir(struct devfs_mount *dmp, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode)
{

View File

@ -230,9 +230,11 @@ devfs_vptocnp(struct vop_vptocnp_args *ap)
goto finished;
}
*buflen = i;
de = TAILQ_FIRST(&de->de_dlist); /* "." */
de = TAILQ_NEXT(de, de_list); /* ".." */
de = de->de_dir;
de = devfs_parent_dirent(de);
if (de == NULL) {
error = ENOENT;
goto finished;
}
mtx_lock(&devfs_de_interlock);
*dvp = de->de_vnode;
if (*dvp != NULL) {
@ -278,9 +280,9 @@ devfs_fqpn(char *buf, struct vnode *dvp, struct componentname *cnp)
return (NULL);
bcopy(de->de_dirent->d_name, buf + i,
de->de_dirent->d_namlen);
de = TAILQ_FIRST(&de->de_dlist); /* "." */
de = TAILQ_NEXT(de, de_list); /* ".." */
de = de->de_dir;
de = devfs_parent_dirent(de);
if (de == NULL)
return (NULL);
}
return (buf + i);
}
@ -789,10 +791,10 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock)
if (flags & ISDOTDOT) {
if ((flags & ISLASTCN) && nameiop != LOOKUP)
return (EINVAL);
de = devfs_parent_dirent(dd);
if (de == NULL)
return (ENOENT);
VOP_UNLOCK(dvp, 0);
de = TAILQ_FIRST(&dd->de_dlist); /* "." */
de = TAILQ_NEXT(de, de_list); /* ".." */
de = de->de_dir;
error = devfs_allocv(de, dvp->v_mount, vpp);
*dm_unlock = 0;
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);