From owner-freebsd-current@FreeBSD.ORG Mon Jul 2 16:33:28 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3F48A16A421 for ; Mon, 2 Jul 2007 16:33:28 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id F24D313C4AD for ; Mon, 2 Jul 2007 16:33:27 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id F057120B2; Mon, 2 Jul 2007 18:33:23 +0200 (CEST) X-Spam-Tests: AWL X-Spam-Learn: disabled X-Spam-Score: 0.0/3.0 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on tim.des.no Received: from dwp.des.no (des.no [80.203.243.180]) by smtp.des.no (Postfix) with ESMTP id 70A0720B1; Mon, 2 Jul 2007 18:33:23 +0200 (CEST) Received: by dwp.des.no (Postfix, from userid 1001) id 1458F5268; Mon, 2 Jul 2007 18:33:22 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: "Eren Erdemli" References: Date: Mon, 02 Jul 2007 18:33:22 +0200 In-Reply-To: (Eren Erdemli's message of "Sat\, 30 Jun 2007 16\:02\:58 +0000") Message-ID: <86sl86bwa5.fsf@dwp.des.no> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-current@freebsd.org Subject: Re: getcwd in kernel space X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2007 16:33:28 -0000 "Eren Erdemli" writes: > I am new to freebsd programing and I am trying to get the current > working directory of the curthread. curthread->td_proc->p_fd->fd_cdir is a pointer to the directory's vnode. > I have hook on to the sys calls and redirected the mkdir > > my_mkdir(struct thread *p, (void*) uap) > { > mkdir_args =3D ..................... > ........ > getCWD()??????????? > } > > the given path in the args is relative to the current path if not supplied > fully. So who would I get the path of file. Are you sure you need the path? There is no unique mapping from vnode to path in FreeBSD (or in any Unix derivative for that matter); multiple paths can lead to the same vnode. The kernel operates on vnodes, not paths (except for namei, which translates paths to vnodes) and the path to a vnode may change after a reference to the vnode is acquired (there is no prohibition against deleting, renaming or moving an open file or directory). Path components are cached in the namei cache, so it may sometimes be possible to reconstruct the path by which a particular vnode was most recently reached (vn_fullpath() does this), but the information may also have been displaced from the cache since the last lookup. If you just need a reference to the specified path or its parent directory, a namei lookup of the path will do all the work for you. See for instance kern_mkdir() in vfs_syscalls.c (which I assume you are already looking at, since you are writing a replacement for the mkdir(2) syscall) DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no