Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Jul 2008 11:04:07 -0700
From:      Julian Elischer <julian@elischer.org>
To:        Uladzislau Rezki <v.rezkii@sam-solutions.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: how can i get a file name knowing its descriptor?
Message-ID:  <486D1497.3020206@elischer.org>
In-Reply-To: <200807031428.02286.v.rezkii@sam-solutions.net>
References:  <200807031428.02286.v.rezkii@sam-solutions.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Uladzislau Rezki wrote:
> Hi all,
> 
> I've been writing a small kernel module, that provides information about
> modification of the filesystem to user_land/userspace through the
> character device. I'm using FreeBSD 4.10
> 
> So, my question is: Is there any way to get file name knowing its descriptor?

well, not really, at least not the name by which it was looked up.
you MIGHT (sometimes) be able to use the directory name cache to work 
it out.. At one stage it was possible to do this for some percentage
of the files but I dont remember if it was possible in 4.x.

the idea is that you can find the name and do '..' lookups in the name 
cache.. i.e. fid if there is a name with your inode number,
then get the directory inode number from that and then look up ..
with that inode number etc.etc. but:

I dont remember if we store ".." in the name cache these days
(I remember some movement on this over the years)
and
Not all of the path to root might be there..

let me know if you work it out :-)


> 
> static int
> xxx_write (struct proc *p, struct write_args *uap)
> {
>        struct vnode *vn;
>        struct file *file;
>        int sys_error;
> 
>        /* do system call */
>        sys_error = write(p, uap);
>        if (sys_error != 0)
>                goto leave_call;
> 
>        /* get the file */
>        file = curproc->p_fd->fd_ofiles[uap->fd];
>        /* get the vnode */
>        vn = (struct vnode *) file->f_data;
> 
>        /* do we have a regular */
>        if (vn->v_type == VREG) {
>        ...
>        ...
>        ...
> }
> 
> As you can see we just know uap->fd.
> 
> Thanks.
> 
> --
> Uladzislau Rezki
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"




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