Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Jul 2007 18:33:22 +0200
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        "Eren Erdemli" <erenerdemli@gmail.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: getcwd in kernel space
Message-ID:  <86sl86bwa5.fsf@dwp.des.no>
In-Reply-To: <cd4105970706300902m5f7e0432y312335b0db5138bd@mail.gmail.com> (Eren Erdemli's message of "Sat\, 30 Jun 2007 16\:02\:58 %2B0000")
References:  <cd4105970706300902m5f7e0432y312335b0db5138bd@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
"Eren Erdemli" <erenerdemli@gmail.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86sl86bwa5.fsf>