Date: Fri, 11 Oct 2019 09:21:49 +0000 From: <Zhichao1.Li@dell.com> To: <kostikbel@gmail.com> Cc: <freebsd-fs@freebsd.org>, <freebsd-drivers@freebsd.org>, <Shunchao.Hu@dell.com> Subject: RE: a issue about getting a devfs node's fullpath Message-ID: <512acd5891c94cb49bba6df379202bc6@KULX13MDC103.APAC.DELL.COM> In-Reply-To: <20191011082838.GR44691@kib.kiev.ua> References: <c6d34bd0b4114bee956b0af6d680a67f@KULX13MDC103.APAC.DELL.COM> <20191010153932.GO44691@kib.kiev.ua> <54b7173c96df43689de04f848ca86de6@KULX13MDC103.APAC.DELL.COM> <20191011082838.GR44691@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
sorry my bad, your pitch works exactly, thank you so much -----Original Message----- From: Konstantin Belousov <kostikbel@gmail.com>=20 Sent: Friday, October 11, 2019 4:29 PM To: Li, Zhichao1 <Zhichao_Li1@Dell.com> Cc: freebsd-fs@freebsd.org; freebsd-drivers@freebsd.org; Hu, Shunchao <Shun= chao_Hu@Dell.com> Subject: Re: a issue about getting a devfs node's fullpath [EXTERNAL EMAIL]=20 On Fri, Oct 11, 2019 at 02:23:14AM +0000, Zhichao1.Li@dell.com wrote: > Hello > Thank you for your time > Unfortunately it does not work, how about this way? It does not work in which way ? I tried it and it worked as expected. Your patch is wrong, VOP_VPTOCNP() must return parent vnode, if any. >=20 > --- a/src/sys/fs/devfs/devfs_vnops.c > +++ b/src/sys/fs/devfs/devfs_vnops.c > @@ -293,7 +293,14 @@ devfs_vptocnp(struct vop_vptocnp_args *ap) > } > bcopy(dd->de_cdp->cdp_c.si_name, buf + i, > strlen(dd->de_cdp->cdp_c.si_name)); > - de =3D dd->de_dir; > + /* > + * when dealing with VCHR > + * the element 'si_name' already > + * holds the full path string > + * except rootdir, so just go > + * to the rootdir > + */ > + de =3D dmp->dm_rootdir; > } else if (vp->v_type =3D=3D VDIR) { > if (dd =3D=3D dmp->dm_rootdir) { > *dvp =3D vp; > @@ -307,13 +314,17 @@ devfs_vptocnp(struct vop_vptocnp_args *ap) > } > bcopy(dd->de_dirent->d_name, buf + i, > dd->de_dirent->d_namlen); > - de =3D dd; > + /* > + * when dealing with VDIR > + * get its parent > + */ > + de =3D devfs_parent_dirent(dd); > } else { > error =3D ENOENT; > goto finished; > } > *buflen =3D i; > - de =3D devfs_parent_dirent(de); > + /*no need to get another parent*/ > if (de =3D=3D NULL) { > error =3D ENOENT; > goto finished; >=20 > another thing is this func is called by many modules, I want to ensure mo= difying the func this way will not impact other modules and not bring some = bugs, would you be so kind to help me out? >=20 > thank you >=20 > -----Original Message----- > From: Konstantin Belousov <kib@freebsd.org> > Sent: Thursday, October 10, 2019 11:40 PM > To: Li, Zhichao1 <Zhichao_Li1@Dell.com> > Cc: freebsd-fs@freebsd.org; freebsd-drivers@freebsd.org; Hu, Shunchao=20 > <Shunchao_Hu@Dell.com> > Subject: Re: a issue about getting a devfs node's fullpath >=20 >=20 > [EXTERNAL EMAIL] >=20 > On Thu, Oct 10, 2019 at 05:49:55AM +0000, Zhichao1.Li@dell.com wrote: > > Dear freebsd developers > > I know you're swamped, so I'll be brief. > > I am trying to get a node's full under /dev by calling the function 'vn= _fullpath', when dealing with things like '/dev/null' or '/dev/usb/1.0.1', = it works well. > > However when dealing a node under more than 2 sub directories (e.g. /de= v/bus/usb/001/002) which I made by calling 'make_dev_s' , it goes a little= bit different, I got a string "/dev/bus/usb/bus/usb/001/002" > > And I found the function 'devfs_vptocnp' gets the string wrongly=20 > > when dealing multi slashes path string, I have remark the code as follo= wed and put some comments would you please take a look, and tell me what th= e purpose this func pass the string that way? >=20 > Try this. Not tested. >=20 > diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c=20 > index 3b80c68e309..f20b466d88b 100644 > --- a/sys/fs/devfs/devfs_vnops.c > +++ b/sys/fs/devfs/devfs_vnops.c > @@ -284,38 +284,27 @@ devfs_vptocnp(struct vop_vptocnp_args *ap) > if (error !=3D 0) > return (error); > =20 > - i =3D *buflen; > + if (vp->v_type !=3D VCHR && vp->v_type !=3D VDIR) { > + error =3D ENOENT; > + goto finished; > + } > + > dd =3D vp->v_data; > + if (vp->v_type =3D=3D VDIR && dd =3D=3D dmp->dm_rootdir) { > + *dvp =3D vp; > + vref(*dvp); > + goto finished; > + } > =20 > - if (vp->v_type =3D=3D VCHR) { > - i -=3D strlen(dd->de_cdp->cdp_c.si_name); > - if (i < 0) { > - error =3D ENOMEM; > - goto finished; > - } > - bcopy(dd->de_cdp->cdp_c.si_name, buf + i, > - strlen(dd->de_cdp->cdp_c.si_name)); > - de =3D dd->de_dir; > - } else if (vp->v_type =3D=3D VDIR) { > - if (dd =3D=3D dmp->dm_rootdir) { > - *dvp =3D vp; > - vref(*dvp); > - goto finished; > - } > - i -=3D dd->de_dirent->d_namlen; > - if (i < 0) { > - error =3D ENOMEM; > - goto finished; > - } > - bcopy(dd->de_dirent->d_name, buf + i, > - dd->de_dirent->d_namlen); > - de =3D dd; > - } else { > - error =3D ENOENT; > + i =3D *buflen; > + i -=3D dd->de_dirent->d_namlen; > + if (i < 0) { > + error =3D ENOMEM; > goto finished; > } > + bcopy(dd->de_dirent->d_name, buf + i, dd->de_dirent->d_namlen); > *buflen =3D i; > - de =3D devfs_parent_dirent(de); > + de =3D devfs_parent_dirent(dd); > if (de =3D=3D NULL) { > error =3D ENOENT; > goto finished;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?512acd5891c94cb49bba6df379202bc6>