From owner-freebsd-hackers@FreeBSD.ORG Thu Jul 3 18:03:46 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7D785106568B for ; Thu, 3 Jul 2008 18:03:46 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outZ.internet-mail-service.net (outz.internet-mail-service.net [216.240.47.249]) by mx1.freebsd.org (Postfix) with ESMTP id 6CFEF8FC16 for ; Thu, 3 Jul 2008 18:03:46 +0000 (UTC) (envelope-from julian@elischer.org) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id 2CC13290E; Thu, 3 Jul 2008 11:04:29 -0700 (PDT) Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id E2AF92D6022; Thu, 3 Jul 2008 11:03:45 -0700 (PDT) Message-ID: <486D1497.3020206@elischer.org> Date: Thu, 03 Jul 2008 11:04:07 -0700 From: Julian Elischer User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: Uladzislau Rezki References: <200807031428.02286.v.rezkii@sam-solutions.net> In-Reply-To: <200807031428.02286.v.rezkii@sam-solutions.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: how can i get a file name knowing its descriptor? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jul 2008 18:03:46 -0000 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"