Add the support for the AT_FDCWD and fd-relative name lookups to the
namei(9). Based on the submission by rdivacky, sponsored by Google Summer of Code 2007 Reviewed by: rwatson, rdivacky Tested by: pho
This commit is contained in:
parent
e314f69fff
commit
57b4252e45
@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/blist.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/exec.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/jail.h>
|
||||
#include <sys/kernel.h>
|
||||
|
@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_compat.h"
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/linker_set.h>
|
||||
|
@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/imgact.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sysent.h>
|
||||
#include <sys/imgact.h>
|
||||
#include <sys/imgact_elf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
|
@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <sys/systm.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/iconv.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kdb.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/syscallsubr.h>
|
||||
|
@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/exec.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/imgact.h>
|
||||
#include <sys/imgact_aout.h>
|
||||
#include <sys/imgact_elf.h>
|
||||
|
@ -22,6 +22,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/priv.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/taskqueue.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/jail.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
|
@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
|
@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/mount.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/limits.h>
|
||||
|
@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/namei.h>
|
||||
@ -192,10 +193,29 @@ namei(struct nameidata *ndp)
|
||||
ndp->ni_rootdir = fdp->fd_rdir;
|
||||
ndp->ni_topdir = fdp->fd_jdir;
|
||||
|
||||
dp = fdp->fd_cdir;
|
||||
if (cnp->cn_pnbuf[0] != '/' && ndp->ni_dirfd != AT_FDCWD) {
|
||||
error = fgetvp(td, ndp->ni_dirfd, &dp);
|
||||
FILEDESC_SUNLOCK(fdp);
|
||||
if (error == 0 && dp->v_type != VDIR) {
|
||||
vfslocked = VFS_LOCK_GIANT(dp->v_mount);
|
||||
vrele(dp);
|
||||
VFS_UNLOCK_GIANT(vfslocked);
|
||||
error = ENOTDIR;
|
||||
}
|
||||
if (error) {
|
||||
uma_zfree(namei_zone, cnp->cn_pnbuf);
|
||||
#ifdef DIAGNOSTIC
|
||||
cnp->cn_pnbuf = NULL;
|
||||
cnp->cn_nameptr = NULL;
|
||||
#endif
|
||||
return (error);
|
||||
}
|
||||
} else {
|
||||
dp = fdp->fd_cdir;
|
||||
VREF(dp);
|
||||
FILEDESC_SUNLOCK(fdp);
|
||||
}
|
||||
vfslocked = VFS_LOCK_GIANT(dp->v_mount);
|
||||
VREF(dp);
|
||||
FILEDESC_SUNLOCK(fdp);
|
||||
for (;;) {
|
||||
/*
|
||||
* Check if root directory should replace current directory.
|
||||
|
@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/clock.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/jail.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/libkern.h>
|
||||
|
@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include "opt_mac.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
|
@ -69,6 +69,7 @@ struct nameidata {
|
||||
struct vnode *ni_startdir; /* starting directory */
|
||||
struct vnode *ni_rootdir; /* logical root directory */
|
||||
struct vnode *ni_topdir; /* logical top directory */
|
||||
int ni_dirfd; /* starting directory for *at functions */
|
||||
/*
|
||||
* Results: returned from/manipulated by lookup
|
||||
*/
|
||||
@ -148,19 +149,22 @@ struct nameidata {
|
||||
/*
|
||||
* Initialization of a nameidata structure.
|
||||
*/
|
||||
static void NDINIT(struct nameidata *, u_long, u_long, enum uio_seg,
|
||||
const char *, struct thread *);
|
||||
#define NDINIT(ndp, op, flags, segflg, namep, td) \
|
||||
NDINIT_AT(ndp, op, flags, segflg, namep, AT_FDCWD, td)
|
||||
|
||||
static __inline void
|
||||
NDINIT(struct nameidata *ndp,
|
||||
NDINIT_AT(struct nameidata *ndp,
|
||||
u_long op, u_long flags,
|
||||
enum uio_seg segflg,
|
||||
const char *namep,
|
||||
int dirfd,
|
||||
struct thread *td)
|
||||
{
|
||||
ndp->ni_cnd.cn_nameiop = op;
|
||||
ndp->ni_cnd.cn_flags = flags;
|
||||
ndp->ni_segflg = segflg;
|
||||
ndp->ni_dirp = namep;
|
||||
ndp->ni_dirfd = dirfd;
|
||||
ndp->ni_cnd.cn_thread = td;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/sched.h>
|
||||
|
Loading…
Reference in New Issue
Block a user