From bc3fa141faa10d927d568bb1f958d736c5f6edcd Mon Sep 17 00:00:00 2001 From: jh Date: Wed, 9 Jun 2010 15:29:12 +0000 Subject: [PATCH] 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 --- sys/fs/devfs/devfs.h | 1 + sys/fs/devfs/devfs_devs.c | 20 ++++++++++++++++++++ sys/fs/devfs/devfs_vnops.c | 20 +++++++++++--------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/sys/fs/devfs/devfs.h b/sys/fs/devfs/devfs.h index 524bec830173..a50a7b066d29 100644 --- a/sys/fs/devfs/devfs.h +++ b/sys/fs/devfs/devfs.h @@ -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); diff --git a/sys/fs/devfs/devfs_devs.c b/sys/fs/devfs/devfs_devs.c index 4bd672867cca..b14a41fdc5b9 100644 --- a/sys/fs/devfs/devfs_devs.c +++ b/sys/fs/devfs/devfs_devs.c @@ -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) { diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 88937a62b2e4..c277355e16e3 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -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);