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 <[email protected]>
  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;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to