Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Oct 2019 18:41:25 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353447 - head/sys/fs/devfs
Message-ID:  <201910111841.x9BIfPRD052450@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Oct 11 18:41:24 2019
New Revision: 353447
URL: https://svnweb.freebsd.org/changeset/base/353447

Log:
  devfs_vptocnp(): correct the component name when node is not at top.
  
  Node' cdp.si_name is the full path as provided by make_dev(9), it
  should not be returned by VOP_VPTOCNP() when only the last component
  is requested.  Use the dirent entry instead.
  
  With this note, handling of VDIR and VCHR nodes only differs in
  handling of root vnode, which simplifies and unifies the logic.
  
  Reported by:	Li, Zhichao1 <Zhichao_Li1@Dell.com>
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

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

Modified: head/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- head/sys/fs/devfs/devfs_vnops.c	Fri Oct 11 18:37:02 2019	(r353446)
+++ head/sys/fs/devfs/devfs_vnops.c	Fri Oct 11 18:41:24 2019	(r353447)
@@ -284,38 +284,27 @@ devfs_vptocnp(struct vop_vptocnp_args *ap)
 	if (error != 0)
 		return (error);
 
-	i = *buflen;
+	if (vp->v_type != VCHR && vp->v_type != VDIR) {
+		error = ENOENT;
+		goto finished;
+	}
+
 	dd = vp->v_data;
+	if (vp->v_type == VDIR && dd == dmp->dm_rootdir) {
+		*dvp = vp;
+		vref(*dvp);
+		goto finished;
+	}
 
-	if (vp->v_type == VCHR) {
-		i -= strlen(dd->de_cdp->cdp_c.si_name);
-		if (i < 0) {
-			error = ENOMEM;
-			goto finished;
-		}
-		bcopy(dd->de_cdp->cdp_c.si_name, buf + i,
-		    strlen(dd->de_cdp->cdp_c.si_name));
-		de = dd->de_dir;
-	} else if (vp->v_type == VDIR) {
-		if (dd == dmp->dm_rootdir) {
-			*dvp = vp;
-			vref(*dvp);
-			goto finished;
-		}
-		i -= dd->de_dirent->d_namlen;
-		if (i < 0) {
-			error = ENOMEM;
-			goto finished;
-		}
-		bcopy(dd->de_dirent->d_name, buf + i,
-		    dd->de_dirent->d_namlen);
-		de = dd;
-	} else {
-		error = ENOENT;
+	i = *buflen;
+	i -= dd->de_dirent->d_namlen;
+	if (i < 0) {
+		error = ENOMEM;
 		goto finished;
 	}
+	bcopy(dd->de_dirent->d_name, buf + i, dd->de_dirent->d_namlen);
 	*buflen = i;
-	de = devfs_parent_dirent(de);
+	de = devfs_parent_dirent(dd);
 	if (de == NULL) {
 		error = ENOENT;
 		goto finished;



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