Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2010 15:29:12 +0000 (UTC)
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r208951 - head/sys/fs/devfs
Message-ID:  <201006091529.o59FTCP3062583@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jh
Date: Wed Jun  9 15:29:12 2010
New Revision: 208951
URL: http://svn.freebsd.org/changeset/base/208951

Log:
  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

Modified:
  head/sys/fs/devfs/devfs.h
  head/sys/fs/devfs/devfs_devs.c
  head/sys/fs/devfs/devfs_vnops.c

Modified: head/sys/fs/devfs/devfs.h
==============================================================================
--- head/sys/fs/devfs/devfs.h	Wed Jun  9 14:54:05 2010	(r208950)
+++ head/sys/fs/devfs/devfs.h	Wed Jun  9 15:29:12 2010	(r208951)
@@ -180,6 +180,7 @@ void devfs_populate (struct devfs_mount 
 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);
 

Modified: head/sys/fs/devfs/devfs_devs.c
==============================================================================
--- head/sys/fs/devfs/devfs_devs.c	Wed Jun  9 14:54:05 2010	(r208950)
+++ head/sys/fs/devfs/devfs_devs.c	Wed Jun  9 15:29:12 2010	(r208951)
@@ -198,6 +198,26 @@ devfs_newdirent(char *name, int namelen)
 }
 
 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)
 {
 	struct devfs_dirent *dd;

Modified: head/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- head/sys/fs/devfs/devfs_vnops.c	Wed Jun  9 14:54:05 2010	(r208950)
+++ head/sys/fs/devfs/devfs_vnops.c	Wed Jun  9 15:29:12 2010	(r208951)
@@ -230,9 +230,11 @@ devfs_vptocnp(struct vop_vptocnp_args *a
 		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,
 			 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
 	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006091529.o59FTCP3062583>