Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Nov 2014 17:01:24 -0330
From:      Jonathan Anderson <jonathan@FreeBSD.org>
To:        Benjamin Kaduk <bjk@freebsd.org>
Cc:        arch@freebsd.org, fs@freebsd.org, freebsd-arch@freebsd.org
Subject:   Re: Removal of kern_xxx() no-at variants.
Message-ID:  <5463C39C.2010204@FreeBSD.org>
In-Reply-To: <alpine.GSO.1.10.1411121449340.27826@multics.mit.edu>
References:  <20141112132451.GM17068@kib.kiev.ua> <201411121014.04482.jhb@freebsd.org> <alpine.GSO.1.10.1411121449340.27826@multics.mit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
A thought:

If we're only going to have one of {kern_open,kern_openat}, might it 
make sense to keep the shorter name rather than the longer one? 
kern_openat as a name seems meaningful to me only if we're trying to 
disambiguate it from an also-existent-but-different-meaning kern_open.


Jon

> Benjamin Kaduk <mailto:bjk@freebsd.org>
> 12 November 2014 at 16:21
>
> Please do bump __FreeBSD_version along with the change.
>
> -Ben
> _______________________________________________
> freebsd-arch@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-arch
> To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
> John Baldwin <mailto:jhb@freebsd.org>
> 12 November 2014 at 11:44
>
> The idea sounds fine to me. Note that I only did a glance over the diff
> rather than a thorough review.
>
> Konstantin Belousov <mailto:kostikbel@gmail.com>
> 12 November 2014 at 9:54
> We have 'fat' KPI for kern_open() and other vfs syscall helpers, after
> the at-version of the syscalls was added somewhere at 8-CURRENT.
> For instance, we provide
> kern_open() and kern_openat().
> But more, we provide
> kern_stat()
> kern_lstat()
> kern_statat()
> kern_statat_vhook()
> first three being a trivial wrapper around kern_statat_vhook().
> More, existence of two or (sometimes) three layers around basic
> syscall helper causes issues like r271655 making the argument
> validation split.
>
> Kepping the compat layer was reasonable in 8-CURRENT time when the
> at variants were experimental and patch to add the syscalls was
> already large and error-prone. Now, I think we should shave the
> extra call indirections, it costs nothing at callers and sometimes
> even improves the code.
>
> diff --git a/sys/cddl/compat/opensolaris/sys/vnode.h
> b/sys/cddl/compat/opensolaris/sys/vnode.h
> index 4e5b1c9..22256cf 100644
> --- a/sys/cddl/compat/opensolaris/sys/vnode.h
> +++ b/sys/cddl/compat/opensolaris/sys/vnode.h
> @@ -282,7 +282,7 @@ vn_rename(char *from, char *to, enum uio_seg seg)
>
> ASSERT(seg == UIO_SYSSPACE);
>
> - return (kern_rename(curthread, from, to, seg));
> + return (kern_renameat(curthread, AT_FDCWD, from, AT_FDCWD, to, seg));
> }
>
> static __inline int
> @@ -292,7 +292,7 @@ vn_remove(char *fnamep, enum uio_seg seg, enum rm
> dirflag)
> ASSERT(seg == UIO_SYSSPACE);
> ASSERT(dirflag == RMFILE);
>
> - return (kern_unlink(curthread, fnamep, seg));
> + return (kern_unlinkat(curthread, AT_FDCWD, fnamep, seg, 0));
> }
>
> #endif /* _KERNEL */
> diff --git a/sys/compat/freebsd32/freebsd32_misc.c
> b/sys/compat/freebsd32/freebsd32_misc.c
> index 5ea062e..9323138 100644
> --- a/sys/compat/freebsd32/freebsd32_misc.c
> +++ b/sys/compat/freebsd32/freebsd32_misc.c
> @@ -1235,7 +1235,8 @@ freebsd32_utimes(struct thread *td, struct
> freebsd32_utimes_args *uap)
> sp = s;
> } else
> sp = NULL;
> - return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
> + return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + sp, UIO_SYSSPACE));
> }
>
> int
> @@ -1723,7 +1724,8 @@ freebsd32_stat(struct thread *td, struct
> freebsd32_stat_args *uap)
> struct stat32 sb32;
> int error;
>
> - error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
> + &sb, NULL);
> if (error)
> return (error);
> copy_stat(&sb, &sb32);
> @@ -1739,7 +1741,8 @@ ofreebsd32_stat(struct thread *td, struct
> ofreebsd32_stat_args *uap)
> struct ostat32 sb32;
> int error;
>
> - error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
> + &sb, NULL);
> if (error)
> return (error);
> copy_ostat(&sb, &sb32);
> @@ -1787,7 +1790,8 @@ freebsd32_fstatat(struct thread *td, struct
> freebsd32_fstatat_args *uap)
> struct stat32 ub32;
> int error;
>
> - error = kern_statat(td, uap->flag, uap->fd, uap->path,
> UIO_USERSPACE, &ub);
> + error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
> + &ub, NULL);
> if (error)
> return (error);
> copy_stat(&ub, &ub32);
> @@ -1802,7 +1806,8 @@ freebsd32_lstat(struct thread *td, struct
> freebsd32_lstat_args *uap)
> struct stat32 sb32;
> int error;
>
> - error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
> + UIO_USERSPACE, &sb, NULL);
> if (error)
> return (error);
> copy_stat(&sb, &sb32);
> @@ -1818,7 +1823,8 @@ ofreebsd32_lstat(struct thread *td, struct
> ofreebsd32_lstat_args *uap)
> struct ostat32 sb32;
> int error;
>
> - error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
> + UIO_USERSPACE, &sb, NULL);
> if (error)
> return (error);
> copy_ostat(&sb, &sb32);
> diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
> index e56e61f..88303b9 100644
> --- a/sys/compat/linux/linux_file.c
> +++ b/sys/compat/linux/linux_file.c
> @@ -82,8 +82,8 @@ linux_creat(struct thread *td, struct
> linux_creat_args *args)
> if (ldebug(creat))
> printf(ARGS(creat, "%s, %d"), path, args->mode);
> #endif
> - error = kern_open(td, path, UIO_SYSSPACE, O_WRONLY | O_CREAT | O_TRUNC,
> - args->mode);
> + error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + O_WRONLY | O_CREAT | O_TRUNC, args->mode);
> LFREEPATH(path);
> return (error);
> }
> @@ -572,7 +572,8 @@ linux_access(struct thread *td, struct
> linux_access_args *args)
> if (ldebug(access))
> printf(ARGS(access, "%s, %d"), path, args->amode);
> #endif
> - error = kern_access(td, path, UIO_SYSSPACE, args->amode);
> + error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
> + args->amode);
> LFREEPATH(path);
>
> return (error);
> @@ -619,12 +620,15 @@ linux_unlink(struct thread *td, struct
> linux_unlink_args *args)
> printf(ARGS(unlink, "%s"), path);
> #endif
>
> - error = kern_unlink(td, path, UIO_SYSSPACE);
> - if (error == EPERM)
> + error = kern_unlinkat(td, AT_FDCWD, path, UIO_SYSSPACE, 0);
> + if (error == EPERM) {
> /* Introduce POSIX noncompliant behaviour of Linux */
> - if (kern_stat(td, path, UIO_SYSSPACE, &st) == 0)
> + if (kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st,
> + NULL) == 0) {
> if (S_ISDIR(st.st_mode))
> error = EISDIR;
> + }
> + }
> LFREEPATH(path);
> return (error);
> }
> @@ -654,7 +658,7 @@ linux_unlinkat(struct thread *td, struct
> linux_unlinkat_args *args)
> if (error == EPERM && !(args->flag & LINUX_AT_REMOVEDIR)) {
> /* Introduce POSIX noncompliant behaviour of Linux */
> if (kern_statat(td, AT_SYMLINK_NOFOLLOW, dfd, path,
> - UIO_SYSSPACE, &st) == 0 && S_ISDIR(st.st_mode))
> + UIO_SYSSPACE, &st, NULL) == 0 && S_ISDIR(st.st_mode))
> error = EISDIR;
> }
> LFREEPATH(path);
> @@ -689,7 +693,8 @@ linux_chmod(struct thread *td, struct
> linux_chmod_args *args)
> if (ldebug(chmod))
> printf(ARGS(chmod, "%s, %d"), path, args->mode);
> #endif
> - error = kern_chmod(td, path, UIO_SYSSPACE, args->mode);
> + error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + args->mode, 0);
> LFREEPATH(path);
> return (error);
> }
> @@ -725,7 +730,7 @@ linux_mkdir(struct thread *td, struct
> linux_mkdir_args *args)
> if (ldebug(mkdir))
> printf(ARGS(mkdir, "%s, %d"), path, args->mode);
> #endif
> - error = kern_mkdir(td, path, UIO_SYSSPACE, args->mode);
> + error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode);
> LFREEPATH(path);
> return (error);
> }
> @@ -760,7 +765,7 @@ linux_rmdir(struct thread *td, struct
> linux_rmdir_args *args)
> if (ldebug(rmdir))
> printf(ARGS(rmdir, "%s"), path);
> #endif
> - error = kern_rmdir(td, path, UIO_SYSSPACE);
> + error = kern_rmdirat(td, AT_FDCWD, path, UIO_SYSSPACE);
> LFREEPATH(path);
> return (error);
> }
> @@ -783,7 +788,7 @@ linux_rename(struct thread *td, struct
> linux_rename_args *args)
> if (ldebug(rename))
> printf(ARGS(rename, "%s, %s"), from, to);
> #endif
> - error = kern_rename(td, from, to, UIO_SYSSPACE);
> + error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
> LFREEPATH(from);
> LFREEPATH(to);
> return (error);
> @@ -833,7 +838,7 @@ linux_symlink(struct thread *td, struct
> linux_symlink_args *args)
> if (ldebug(symlink))
> printf(ARGS(symlink, "%s, %s"), path, to);
> #endif
> - error = kern_symlink(td, path, to, UIO_SYSSPACE);
> + error = kern_symlinkat(td, path, AT_FDCWD, to, UIO_SYSSPACE);
> LFREEPATH(path);
> LFREEPATH(to);
> return (error);
> @@ -878,8 +883,8 @@ linux_readlink(struct thread *td, struct
> linux_readlink_args *args)
> printf(ARGS(readlink, "%s, %p, %d"), name, (void *)args->buf,
> args->count);
> #endif
> - error = kern_readlink(td, name, UIO_SYSSPACE, args->buf, UIO_USERSPACE,
> - args->count);
> + error = kern_readlinkat(td, AT_FDCWD, name, UIO_SYSSPACE,
> + args->buf, UIO_USERSPACE, args->count);
> LFREEPATH(name);
> return (error);
> }
> @@ -972,7 +977,8 @@ linux_link(struct thread *td, struct
> linux_link_args *args)
> if (ldebug(link))
> printf(ARGS(link, "%s, %s"), path, to);
> #endif
> - error = kern_link(td, path, to, UIO_SYSSPACE);
> + error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
> + FOLLOW);
> LFREEPATH(path);
> LFREEPATH(to);
> return (error);
> @@ -1487,7 +1493,8 @@ linux_chown(struct thread *td, struct
> linux_chown_args *args)
> if (ldebug(chown))
> printf(ARGS(chown, "%s, %d, %d"), path, args->uid, args->gid);
> #endif
> - error = kern_chown(td, path, UIO_SYSSPACE, args->uid, args->gid);
> + error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
> + args->gid, 0);
> LFREEPATH(path);
> return (error);
> }
> @@ -1529,7 +1536,8 @@ linux_lchown(struct thread *td, struct
> linux_lchown_args *args)
> if (ldebug(lchown))
> printf(ARGS(lchown, "%s, %d, %d"), path, args->uid, args->gid);
> #endif
> - error = kern_lchown(td, path, UIO_SYSSPACE, args->uid, args->gid);
> + error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
> + args->gid, AT_SYMLINK_NOFOLLOW);
> LFREEPATH(path);
> return (error);
> }
> diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
> index ff5e8a2..4433e18 100644
> --- a/sys/compat/linux/linux_misc.c
> +++ b/sys/compat/linux/linux_misc.c
> @@ -777,7 +777,8 @@ linux_utime(struct thread *td, struct
> linux_utime_args *args)
> } else
> tvp = NULL;
>
> - error = kern_utimes(td, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
> + error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE, tvp,
> + UIO_SYSSPACE);
> LFREEPATH(fname);
> return (error);
> }
> @@ -809,7 +810,8 @@ linux_utimes(struct thread *td, struct
> linux_utimes_args *args)
> tvp = tv;
> }
>
> - error = kern_utimes(td, fname, UIO_SYSSPACE, tvp, UIO_SYSSPACE);
> + error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE,
> + tvp, UIO_SYSSPACE);
> LFREEPATH(fname);
> return (error);
> }
> @@ -914,13 +916,14 @@ linux_mknod(struct thread *td, struct
> linux_mknod_args *args)
> switch (args->mode & S_IFMT) {
> case S_IFIFO:
> case S_IFSOCK:
> - error = kern_mkfifo(td, path, UIO_SYSSPACE, args->mode);
> + error = kern_mkfifoat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + args->mode);
> break;
>
> case S_IFCHR:
> case S_IFBLK:
> - error = kern_mknod(td, path, UIO_SYSSPACE, args->mode,
> - args->dev);
> + error = kern_mknodat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + args->mode, args->dev);
> break;
>
> case S_IFDIR:
> @@ -931,7 +934,7 @@ linux_mknod(struct thread *td, struct
> linux_mknod_args *args)
> args->mode |= S_IFREG;
> /* FALLTHROUGH */
> case S_IFREG:
> - error = kern_open(td, path, UIO_SYSSPACE,
> + error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
> O_WRONLY | O_CREAT | O_TRUNC, args->mode);
> if (error == 0)
> kern_close(td, td->td_retval[0]);
> diff --git a/sys/compat/linux/linux_socket.c
> b/sys/compat/linux/linux_socket.c
> index 43b255d..61b786f 100644
> --- a/sys/compat/linux/linux_socket.c
> +++ b/sys/compat/linux/linux_socket.c
> @@ -731,7 +731,7 @@ linux_bind(struct thread *td, struct
> linux_bind_args *args)
> if (error)
> return (error);
>
> - error = kern_bind(td, args->s, sa);
> + error = kern_bindat(td, AT_FDCWD, args->s, sa);
> free(sa, M_SONAME);
> if (error == EADDRNOTAVAIL && args->namelen != sizeof(struct sockaddr_in))
> return (EINVAL);
> @@ -759,7 +759,7 @@ linux_connect(struct thread *td, struct
> linux_connect_args *args)
> if (error)
> return (error);
>
> - error = kern_connect(td, args->s, sa);
> + error = kern_connectat(td, AT_FDCWD, args->s, sa);
> free(sa, M_SONAME);
> if (error != EISCONN)
> return (error);
> diff --git a/sys/compat/linux/linux_stats.c
> b/sys/compat/linux/linux_stats.c
> index 2e05c85..b6dd86d 100644
> --- a/sys/compat/linux/linux_stats.c
> +++ b/sys/compat/linux/linux_stats.c
> @@ -77,7 +77,7 @@ linux_kern_statat(struct thread *td, int flag, int
> fd, char *path,
> enum uio_seg pathseg, struct stat *sbp)
> {
>
> - return (kern_statat_vnhook(td, flag, fd, path, pathseg, sbp,
> + return (kern_statat(td, flag, fd, path, pathseg, sbp,
> translate_vnhook_major_minor));
> }
>
> diff --git a/sys/compat/linux/linux_uid16.c
> b/sys/compat/linux/linux_uid16.c
> index c5bf2dd..61f3030 100644
> --- a/sys/compat/linux/linux_uid16.c
> +++ b/sys/compat/linux/linux_uid16.c
> @@ -121,8 +121,8 @@ linux_chown16(struct thread *td, struct
> linux_chown16_args *args)
> args->gid);
> LIN_SDT_PROBE1(uid16, linux_chown16, conv_path, path);
>
> - error = kern_chown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
> - CAST_NOCHG(args->gid));
> + error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0);
> LFREEPATH(path);
>
> LIN_SDT_PROBE1(uid16, linux_chown16, return, error);
> @@ -146,8 +146,8 @@ linux_lchown16(struct thread *td, struct
> linux_lchown16_args *args)
> args->gid);
> LIN_SDT_PROBE1(uid16, linux_lchown16, conv_path, path);
>
> - error = kern_lchown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
> - CAST_NOCHG(args->gid));
> + error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW);
> LFREEPATH(path);
>
> LIN_SDT_PROBE1(uid16, linux_lchown16, return, error);
> diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c
> index c604675..edcfcc107 100644
> --- a/sys/compat/svr4/svr4_fcntl.c
> +++ b/sys/compat/svr4/svr4_fcntl.c
> @@ -390,7 +390,8 @@ svr4_sys_open(td, uap)
> CHECKALTEXIST(td, uap->path, &newpath);
>
> bsd_flags = svr4_to_bsd_flags(uap->flags);
> - error = kern_open(td, newpath, UIO_SYSSPACE, bsd_flags, uap->mode);
> + error = kern_openat(td, AT_FDCWD, newpath, UIO_SYSSPACE, bsd_flags,
> + uap->mode);
> free(newpath, M_TEMP);
>
> if (error) {
> @@ -450,8 +451,8 @@ svr4_sys_creat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &newpath);
>
> - error = kern_open(td, newpath, UIO_SYSSPACE, O_WRONLY | O_CREAT |
> - O_TRUNC, uap->mode);
> + error = kern_openat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
> + O_WRONLY | O_CREAT | O_TRUNC, uap->mode);
> free(newpath, M_TEMP);
> return (error);
> }
> @@ -494,7 +495,8 @@ svr4_sys_access(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &newpath);
> - error = kern_access(td, newpath, UIO_SYSSPACE, uap->amode);
> + error = kern_accessat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
> + 0, uap->amode);
> free(newpath, M_TEMP);
> return (error);
> }
> diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c
> index 0db5453..9e9b020 100644
> --- a/sys/compat/svr4/svr4_misc.c
> +++ b/sys/compat/svr4/svr4_misc.c
> @@ -653,10 +653,13 @@ svr4_mknod(td, retval, path, mode, dev)
>
> CHECKALTEXIST(td, path, &newpath);
>
> - if (S_ISFIFO(mode))
> - error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
> - else
> - error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
> + if (S_ISFIFO(mode)) {
> + error = kern_mkfifoat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
> + mode);
> + } else {
> + error = kern_mknodat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
> + mode, dev);
> + }
> free(newpath, M_TEMP);
> return (error);
> }
> diff --git a/sys/compat/svr4/svr4_stat.c b/sys/compat/svr4/svr4_stat.c
> index b686642..6ed9873 100644
> --- a/sys/compat/svr4/svr4_stat.c
> +++ b/sys/compat/svr4/svr4_stat.c
> @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
> #include <sys/proc.h>
> #include <sys/stat.h>
> #include <sys/filedesc.h>
> +#include <sys/fcntl.h>
> #include <sys/jail.h>
> #include <sys/kernel.h>
> #include <sys/malloc.h>
> @@ -170,7 +171,7 @@ svr4_sys_stat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_stat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -195,7 +196,8 @@ svr4_sys_lstat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_lstat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
> + UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -238,7 +240,7 @@ svr4_sys_xstat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_stat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -265,7 +267,8 @@ svr4_sys_lxstat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_lstat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
> + UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -309,7 +312,7 @@ svr4_sys_stat64(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_stat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -335,7 +338,8 @@ svr4_sys_lstat64(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_lstat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
> + UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -582,7 +586,8 @@ svr4_sys_utime(td, uap)
> tp = NULL;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_utimes(td, path, UIO_SYSSPACE, tp, UIO_SYSSPACE);
> + error = kern_utimesat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + tp, UIO_SYSSPACE);
> free(path, M_TEMP);
> return (error);
> }
> @@ -597,7 +602,8 @@ svr4_sys_utimes(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_utimes(td, path, UIO_SYSSPACE, uap->tptr, UIO_USERSPACE);
> + error = kern_utimesat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + uap->tptr, UIO_USERSPACE);
> free(path, M_TEMP);
> return (error);
> }
> diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c
> index 91c393f..d287d5d 100644
> --- a/sys/compat/svr4/svr4_stream.c
> +++ b/sys/compat/svr4/svr4_stream.c
> @@ -282,7 +282,8 @@ clean_pipe(td, path)
> struct stat st;
> int error;
>
> - error = kern_lstat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
> + UIO_SYSSPACE, &st, NULL);
>
> /*
> * Make sure we are dealing with a mode 0 named pipe.
> @@ -293,7 +294,7 @@ clean_pipe(td, path)
> if ((st.st_mode & ALLPERMS) != 0)
> return (0);
>
> - error = kern_unlink(td, path, UIO_SYSSPACE);
> + error = kern_unlinkat(td, AT_FDCWD, path, UIO_SYSSPACE, 0);
> if (error)
> DPRINTF(("clean_pipe: unlink failed %d\n", error));
> return (error);
> @@ -812,7 +813,7 @@ ti_bind(fp, fd, ioc, td)
>
> DPRINTF(("TI_BIND: fileno %d\n", fd));
>
> - if ((error = kern_bind(td, fd, skp)) != 0) {
> + if ((error = kern_bindat(td, AT_FDCWD, fd, skp)) != 0) {
> DPRINTF(("TI_BIND: bind failed %d\n", error));
> return error;
> }
> @@ -1586,7 +1587,7 @@ svr4_do_putmsg(td, uap, fp)
> case SVR4_TI_CONNECT_REQUEST: /* connect */
> {
>
> - return (kern_connect(td, uap->fd, sa));
> + return (kern_connectat(td, AT_FDCWD, uap->fd, sa));
> }
>
> case SVR4_TI_SENDTO_REQUEST: /* sendto */
> diff --git a/sys/dev/streams/streams.c b/sys/dev/streams/streams.c
> index 42265a4..6a9219e 100644
> --- a/sys/dev/streams/streams.c
> +++ b/sys/dev/streams/streams.c
> @@ -302,7 +302,8 @@ svr4_ptm_alloc(td)
> ptyname[8] = ttyletters[l];
> ptyname[9] = ttynumbers[n];
>
> - error = kern_open(td, ptyname, UIO_SYSSPACE, O_RDWR, 0);
> + error = kern_openat(td, AT_FDCWD, ptyname, UIO_SYSSPACE,
> + O_RDWR, 0);
> switch (error) {
> case ENOENT:
> case ENXIO:
> diff --git a/sys/i386/ibcs2/ibcs2_fcntl.c b/sys/i386/ibcs2/ibcs2_fcntl.c
> index d2489df..5d06d4d 100644
> --- a/sys/i386/ibcs2/ibcs2_fcntl.c
> +++ b/sys/i386/ibcs2/ibcs2_fcntl.c
> @@ -189,7 +189,7 @@ ibcs2_open(td, uap)
> CHECKALTCREAT(td, uap->path, &path);
> else
> CHECKALTEXIST(td, uap->path, &path);
> - ret = kern_open(td, path, UIO_SYSSPACE, flags, uap->mode);
> + ret = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE, flags, uap->mode);
>
> #ifdef SPX_HACK
> if (ret == ENXIO) {
> @@ -230,8 +230,8 @@ ibcs2_creat(td, uap)
> int error;
>
> CHECKALTCREAT(td, uap->path, &path);
> - error = kern_open(td, path, UIO_SYSSPACE, O_WRONLY | O_CREAT | O_TRUNC,
> - uap->mode);
> + error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + O_WRONLY | O_CREAT | O_TRUNC, uap->mode);
> free(path, M_TEMP);
> return (error);
> }
> @@ -245,7 +245,7 @@ ibcs2_access(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_access(td, path, UIO_SYSSPACE, uap->amode);
> + error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0, uap->amode);
> free(path, M_TEMP);
> return (error);
> }
> diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c
> index 42bc4b7..d81cfee 100644
> --- a/sys/i386/ibcs2/ibcs2_misc.c
> +++ b/sys/i386/ibcs2/ibcs2_misc.c
> @@ -646,10 +646,13 @@ ibcs2_mknod(td, uap)
> int error;
>
> CHECKALTCREAT(td, uap->path, &path);
> - if (S_ISFIFO(uap->mode))
> - error = kern_mkfifo(td, path, UIO_SYSSPACE, uap->mode);
> - else
> - error = kern_mknod(td, path, UIO_SYSSPACE, uap->mode, uap->dev);
> + if (S_ISFIFO(uap->mode)) {
> + error = kern_mkfifoat(td, AT_FDCWD, path,
> + UIO_SYSSPACE, uap->mode);
> + } else {
> + error = kern_mknodat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + uap->mode, uap->dev);
> + }
> free(path, M_TEMP);
> return (error);
> }
> @@ -938,7 +941,8 @@ ibcs2_utime(td, uap)
> tp = NULL;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_utimes(td, path, UIO_SYSSPACE, tp, UIO_SYSSPACE);
> + error = kern_utimesat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + tp, UIO_SYSSPACE);
> free(path, M_TEMP);
> return (error);
> }
> @@ -1119,7 +1123,7 @@ ibcs2_unlink(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_unlink(td, path, UIO_SYSSPACE);
> + error = kern_unlinkat(td, AT_FDCWD, path, UIO_SYSSPACE, 0);
> free(path, M_TEMP);
> return (error);
> }
> @@ -1147,7 +1151,7 @@ ibcs2_chmod(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_chmod(td, path, UIO_SYSSPACE, uap->mode);
> + error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->mode, 0);
> free(path, M_TEMP);
> return (error);
> }
> @@ -1161,7 +1165,8 @@ ibcs2_chown(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_chown(td, path, UIO_SYSSPACE, uap->uid, uap->gid);
> + error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->uid,
> + uap->gid, 0);
> free(path, M_TEMP);
> return (error);
> }
> @@ -1175,7 +1180,7 @@ ibcs2_rmdir(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_rmdir(td, path, UIO_SYSSPACE);
> + error = kern_rmdirat(td, AT_FDCWD, path, UIO_SYSSPACE);
> free(path, M_TEMP);
> return (error);
> }
> @@ -1189,7 +1194,7 @@ ibcs2_mkdir(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_mkdir(td, path, UIO_SYSSPACE, uap->mode);
> + error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->mode);
> free(path, M_TEMP);
> return (error);
> }
> @@ -1213,7 +1218,7 @@ ibcs2_symlink(td, uap)
> free(path, M_TEMP);
> return (error);
> }
> - error = kern_symlink(td, path, link, UIO_SYSSPACE);
> + error = kern_symlinkat(td, path, AT_FDCWD, link, UIO_SYSSPACE);
> free(path, M_TEMP);
> free(link, M_TEMP);
> return (error);
> @@ -1238,7 +1243,7 @@ ibcs2_rename(td, uap)
> free(from, M_TEMP);
> return (error);
> }
> - error = kern_rename(td, from, to, UIO_SYSSPACE);
> + error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
> free(from, M_TEMP);
> free(to, M_TEMP);
> return (error);
> @@ -1253,8 +1258,8 @@ ibcs2_readlink(td, uap)
> int error;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_readlink(td, path, UIO_SYSSPACE, uap->buf, UIO_USERSPACE,
> - uap->count);
> + error = kern_readlinkat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + uap->buf, UIO_USERSPACE, uap->count);
> free(path, M_TEMP);
> return (error);
> }
> diff --git a/sys/i386/ibcs2/ibcs2_other.c b/sys/i386/ibcs2/ibcs2_other.c
> index f688661..b49e605 100644
> --- a/sys/i386/ibcs2/ibcs2_other.c
> +++ b/sys/i386/ibcs2/ibcs2_other.c
> @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
>
> #include <sys/param.h>
> #include <sys/systm.h>
> +#include <sys/fcntl.h>
> #include <sys/lock.h>
> #include <sys/mutex.h>
> #include <sys/syscallsubr.h>
> @@ -107,7 +108,7 @@ spx_open(struct thread *td)
> sun.sun_len = sizeof(struct sockaddr_un) - sizeof(sun.sun_path) +
> strlen(sun.sun_path) + 1;
>
> - error = kern_connect(td, fd, (struct sockaddr *)&sun);
> + error = kern_connectat(td, AT_FDCWD, fd, (struct sockaddr *)&sun);
> if (error) {
> kern_close(td, fd);
> return error;
> diff --git a/sys/i386/ibcs2/ibcs2_stat.c b/sys/i386/ibcs2/ibcs2_stat.c
> index c1097a3..55d14af 100644
> --- a/sys/i386/ibcs2/ibcs2_stat.c
> +++ b/sys/i386/ibcs2/ibcs2_stat.c
> @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
> #include <sys/param.h>
> #include <sys/systm.h>
> #include <sys/namei.h>
> +#include <sys/fcntl.h>
> #include <sys/file.h>
> #include <sys/stat.h>
> #include <sys/filedesc.h>
> @@ -145,7 +146,7 @@ ibcs2_stat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_stat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> @@ -166,7 +167,8 @@ ibcs2_lstat(td, uap)
>
> CHECKALTEXIST(td, uap->path, &path);
>
> - error = kern_lstat(td, path, UIO_SYSSPACE, &st);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path,
> + UIO_SYSSPACE, &st, NULL);
> free(path, M_TEMP);
> if (error)
> return (error);
> diff --git a/sys/i386/ibcs2/ibcs2_xenix.c b/sys/i386/ibcs2/ibcs2_xenix.c
> index c5416fb..829f6ab 100644
> --- a/sys/i386/ibcs2/ibcs2_xenix.c
> +++ b/sys/i386/ibcs2/ibcs2_xenix.c
> @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
>
> #include <sys/param.h>
> #include <sys/systm.h>
> +#include <sys/fcntl.h>
> #include <sys/namei.h>
> #include <sys/sysproto.h>
> #include <sys/clock.h>
> @@ -209,7 +210,8 @@ xenix_eaccess(struct thread *td, struct
> xenix_eaccess_args *uap)
> bsd_flags |= X_OK;
>
> CHECKALTEXIST(td, uap->path, &path);
> - error = kern_eaccess(td, path, UIO_SYSSPACE, bsd_flags);
> + error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE,
> + AT_EACCESS, bsd_flags);
> free(path, M_TEMP);
> return (error);
> }
> diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
> index 32c837c..7f88a6c 100644
> --- a/sys/kern/kern_descrip.c
> +++ b/sys/kern/kern_descrip.c
> @@ -2215,8 +2215,8 @@ fdcheckstd(struct thread *td)
> if (devnull != -1) {
> error = do_dup(td, DUP_FIXED, devnull, i);
> } else {
> - error = kern_open(td, "/dev/null", UIO_SYSSPACE,
> - O_RDWR, 0);
> + error = kern_openat(td, AT_FDCWD, "/dev/null",
> + UIO_SYSSPACE, O_RDWR, 0);
> if (error == 0) {
> devnull = td->td_retval[0];
> KASSERT(devnull == i, ("we didn't get our fd"));
> diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c
> index 6d423ba..24a4436 100644
> --- a/sys/kern/uipc_syscalls.c
> +++ b/sys/kern/uipc_syscalls.c
> @@ -283,13 +283,13 @@ sys_bind(td, uap)
>
> error = getsockaddr(&sa, uap->name, uap->namelen);
> if (error == 0) {
> - error = kern_bind(td, uap->s, sa);
> + error = kern_bindat(td, AT_FDCWD, uap->s, sa);
> free(sa, M_SONAME);
> }
> return (error);
> }
>
> -static int
> +int
> kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa)
> {
> struct socket *so;
> @@ -323,13 +323,6 @@ kern_bindat(struct thread *td, int dirfd, int fd,
> struct sockaddr *sa)
> return (error);
> }
>
> -int
> -kern_bind(struct thread *td, int fd, struct sockaddr *sa)
> -{
> -
> - return (kern_bindat(td, AT_FDCWD, fd, sa));
> -}
> -
> /* ARGSUSED */
> int
> sys_bindat(td, uap)
> @@ -636,13 +629,13 @@ sys_connect(td, uap)
>
> error = getsockaddr(&sa, uap->name, uap->namelen);
> if (error == 0) {
> - error = kern_connect(td, uap->s, sa);
> + error = kern_connectat(td, AT_FDCWD, uap->s, sa);
> free(sa, M_SONAME);
> }
> return (error);
> }
>
> -static int
> +int
> kern_connectat(struct thread *td, int dirfd, int fd, struct sockaddr *sa)
> {
> struct socket *so;
> @@ -705,13 +698,6 @@ done1:
> return (error);
> }
>
> -int
> -kern_connect(struct thread *td, int fd, struct sockaddr *sa)
> -{
> -
> - return (kern_connectat(td, AT_FDCWD, fd, sa));
> -}
> -
> /* ARGSUSED */
> int
> sys_connectat(td, uap)
> diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c
> index 2816e1b..a050099 100644
> --- a/sys/kern/vfs_mountroot.c
> +++ b/sys/kern/vfs_mountroot.c
> @@ -238,7 +238,7 @@ vfs_mountroot_devfs(struct thread *td, struct
> mount **mpp)
> *mpp = mp;
> set_rootvnode();
>
> - error = kern_symlink(td, "/", "dev", UIO_SYSSPACE);
> + error = kern_symlinkat(td, "/", AT_FDCWD, "dev", UIO_SYSSPACE);
> if (error)
> printf("kern_symlink /dev -> / returns %d\n", error);
>
> @@ -350,7 +350,8 @@ vfs_mountroot_shuffle(struct thread *td, struct
> mount *mpdevfs)
> if (mporoot == mpdevfs) {
> vfs_unbusy(mpdevfs);
> /* Unlink the no longer needed /dev/dev -> / symlink */
> - error = kern_unlink(td, "/dev/dev", UIO_SYSSPACE);
> + error = kern_unlinkat(td, AT_FDCWD, "/dev/dev",
> + UIO_SYSSPACE, 0);
> if (error && bootverbose)
> printf("mountroot: unable to unlink /dev/dev "
> "(error %d)\n", error);
> @@ -524,12 +525,13 @@ parse_dir_md(char **conf)
> free(tok, M_TEMP);
>
> /* Get file status. */
> - error = kern_stat(td, path, UIO_SYSSPACE, &sb);
> + error = kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &sb, NULL);
> if (error)
> goto out;
>
> /* Open /dev/mdctl so that we can attach/detach. */
> - error = kern_open(td, "/dev/" MDCTL_NAME, UIO_SYSSPACE, O_RDWR, 0);
> + error = kern_openat(td, AT_FDCWD, "/dev/" MDCTL_NAME, UIO_SYSSPACE,
> + O_RDWR, 0);
> if (error)
> goto out;
>
> diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
> index 04c1c7b..f6a8ae0 100644
> --- a/sys/kern/vfs_syscalls.c
> +++ b/sys/kern/vfs_syscalls.c
> @@ -1017,7 +1017,8 @@ sys_open(td, uap)
> } */ *uap;
> {
>
> - return (kern_open(td, uap->path, UIO_USERSPACE, uap->flags, uap->mode));
> + return (kern_openat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->flags, uap->mode));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -1037,14 +1038,6 @@ sys_openat(struct thread *td, struct
> openat_args *uap)
> }
>
> int
> -kern_open(struct thread *td, char *path, enum uio_seg pathseg, int flags,
> - int mode)
> -{
> -
> - return (kern_openat(td, AT_FDCWD, path, pathseg, flags, mode));
> -}
> -
> -int
> kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> int flags, int mode)
> {
> @@ -1202,7 +1195,7 @@ ocreat(td, uap)
> } */ *uap;
> {
>
> - return (kern_open(td, uap->path, UIO_USERSPACE,
> + return (kern_openat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> O_WRONLY | O_CREAT | O_TRUNC, uap->mode));
> }
> #endif /* COMPAT_43 */
> @@ -1227,7 +1220,8 @@ sys_mknod(td, uap)
> } */ *uap;
> {
>
> - return (kern_mknod(td, uap->path, UIO_USERSPACE, uap->mode, uap->dev));
> + return (kern_mknodat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->mode, uap->dev));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -1247,14 +1241,6 @@ sys_mknodat(struct thread *td, struct
> mknodat_args *uap)
> }
>
> int
> -kern_mknod(struct thread *td, char *path, enum uio_seg pathseg, int mode,
> - int dev)
> -{
> -
> - return (kern_mknodat(td, AT_FDCWD, path, pathseg, mode, dev));
> -}
> -
> -int
> kern_mknodat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> int mode, int dev)
> {
> @@ -1373,7 +1359,8 @@ sys_mkfifo(td, uap)
> } */ *uap;
> {
>
> - return (kern_mkfifo(td, uap->path, UIO_USERSPACE, uap->mode));
> + return (kern_mkfifoat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->mode));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -1392,13 +1379,6 @@ sys_mkfifoat(struct thread *td, struct
> mkfifoat_args *uap)
> }
>
> int
> -kern_mkfifo(struct thread *td, char *path, enum uio_seg pathseg, int
> mode)
> -{
> -
> - return (kern_mkfifoat(td, AT_FDCWD, path, pathseg, mode));
> -}
> -
> -int
> kern_mkfifoat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> int mode)
> {
> @@ -1470,7 +1450,8 @@ sys_link(td, uap)
> } */ *uap;
> {
>
> - return (kern_link(td, uap->path, uap->link, UIO_USERSPACE));
> + return (kern_linkat(td, AT_FDCWD, AT_FDCWD, uap->path, uap->link,
> + UIO_USERSPACE, FOLLOW));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -1535,13 +1516,6 @@ can_hardlink(struct vnode *vp, struct ucred *cred)
> }
>
> int
> -kern_link(struct thread *td, char *path, char *link, enum uio_seg segflg)
> -{
> -
> - return (kern_linkat(td, AT_FDCWD, AT_FDCWD, path,link, segflg, FOLLOW));
> -}
> -
> -int
> kern_linkat(struct thread *td, int fd1, int fd2, char *path1, char *path2,
> enum uio_seg segflg, int follow)
> {
> @@ -1643,7 +1617,8 @@ sys_symlink(td, uap)
> } */ *uap;
> {
>
> - return (kern_symlink(td, uap->path, uap->link, UIO_USERSPACE));
> + return (kern_symlinkat(td, uap->path, AT_FDCWD, uap->link,
> + UIO_USERSPACE));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -1662,13 +1637,6 @@ sys_symlinkat(struct thread *td, struct
> symlinkat_args *uap)
> }
>
> int
> -kern_symlink(struct thread *td, char *path, char *link, enum uio_seg
> segflg)
> -{
> -
> - return (kern_symlinkat(td, path, AT_FDCWD, link, segflg));
> -}
> -
> -int
> kern_symlinkat(struct thread *td, char *path1, int fd, char *path2,
> enum uio_seg segflg)
> {
> @@ -1796,7 +1764,7 @@ sys_unlink(td, uap)
> } */ *uap;
> {
>
> - return (kern_unlink(td, uap->path, UIO_USERSPACE));
> + return (kern_unlinkat(td, AT_FDCWD, uap->path, UIO_USERSPACE, 0));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -1823,13 +1791,6 @@ sys_unlinkat(struct thread *td, struct
> unlinkat_args *uap)
> }
>
> int
> -kern_unlink(struct thread *td, char *path, enum uio_seg pathseg)
> -{
> -
> - return (kern_unlinkat(td, AT_FDCWD, path, pathseg, 0));
> -}
> -
> -int
> kern_unlinkat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> ino_t oldinum)
> {
> @@ -2032,7 +1993,8 @@ sys_access(td, uap)
> } */ *uap;
> {
>
> - return (kern_access(td, uap->path, UIO_USERSPACE, uap->amode));
> + return (kern_accessat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + 0, uap->amode));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -2047,20 +2009,11 @@ int
> sys_faccessat(struct thread *td, struct faccessat_args *uap)
> {
>
> - if (uap->flag & ~AT_EACCESS)
> - return (EINVAL);
> return (kern_accessat(td, uap->fd, uap->path, UIO_USERSPACE, uap->flag,
> uap->amode));
> }
>
> int
> -kern_access(struct thread *td, char *path, enum uio_seg pathseg, int
> amode)
> -{
> -
> - return (kern_accessat(td, AT_FDCWD, path, pathseg, 0, amode));
> -}
> -
> -int
> kern_accessat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> int flag, int amode)
> {
> @@ -2070,6 +2023,8 @@ kern_accessat(struct thread *td, int fd, char
> *path, enum uio_seg pathseg,
> cap_rights_t rights;
> int error;
>
> + if (flag & ~AT_EACCESS)
> + return (EINVAL);
> if (amode != F_OK && (amode & ~(R_OK | W_OK | X_OK)) != 0)
> return (EINVAL);
>
> @@ -2124,14 +2079,8 @@ sys_eaccess(td, uap)
> } */ *uap;
> {
>
> - return (kern_eaccess(td, uap->path, UIO_USERSPACE, uap->amode));
> -}
> -
> -int
> -kern_eaccess(struct thread *td, char *path, enum uio_seg pathseg, int
> amode)
> -{
> -
> - return (kern_accessat(td, AT_FDCWD, path, pathseg, AT_EACCESS, amode));
> + return (kern_accessat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + AT_EACCESS, uap->amode));
> }
>
> #if defined(COMPAT_43)
> @@ -2156,7 +2105,8 @@ ostat(td, uap)
> struct ostat osb;
> int error;
>
> - error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
> + &sb, NULL);
> if (error != 0)
> return (error);
> cvtstat(&sb, &osb);
> @@ -2184,7 +2134,8 @@ olstat(td, uap)
> struct ostat osb;
> int error;
>
> - error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
> + UIO_USERSPACE, &sb, NULL);
> if (error != 0)
> return (error);
> cvtstat(&sb, &osb);
> @@ -2241,7 +2192,8 @@ sys_stat(td, uap)
> struct stat sb;
> int error;
>
> - error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
> + &sb, NULL);
> if (error == 0)
> error = copyout(&sb, uap->ub, sizeof (sb));
> return (error);
> @@ -2262,29 +2214,14 @@ sys_fstatat(struct thread *td, struct
> fstatat_args *uap)
> int error;
>
> error = kern_statat(td, uap->flag, uap->fd, uap->path,
> - UIO_USERSPACE, &sb);
> + UIO_USERSPACE, &sb, NULL);
> if (error == 0)
> error = copyout(&sb, uap->buf, sizeof (sb));
> return (error);
> }
>
> int
> -kern_stat(struct thread *td, char *path, enum uio_seg pathseg, struct
> stat *sbp)
> -{
> -
> - return (kern_statat(td, 0, AT_FDCWD, path, pathseg, sbp));
> -}
> -
> -int
> kern_statat(struct thread *td, int flag, int fd, char *path,
> - enum uio_seg pathseg, struct stat *sbp)
> -{
> -
> - return (kern_statat_vnhook(td, flag, fd, path, pathseg, sbp, NULL));
> -}
> -
> -int
> -kern_statat_vnhook(struct thread *td, int flag, int fd, char *path,
> enum uio_seg pathseg, struct stat *sbp,
> void (*hook)(struct vnode *vp, struct stat *sbp))
> {
> @@ -2342,20 +2279,13 @@ sys_lstat(td, uap)
> struct stat sb;
> int error;
>
> - error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
> + UIO_USERSPACE, &sb, NULL);
> if (error == 0)
> error = copyout(&sb, uap->ub, sizeof (sb));
> return (error);
> }
>
> -int
> -kern_lstat(struct thread *td, char *path, enum uio_seg pathseg,
> struct stat *sbp)
> -{
> -
> - return (kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, path, pathseg,
> - sbp));
> -}
> -
> /*
> * Implementation of the NetBSD [l]stat() functions.
> */
> @@ -2402,7 +2332,8 @@ sys_nstat(td, uap)
> struct nstat nsb;
> int error;
>
> - error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
> + &sb, NULL);
> if (error != 0)
> return (error);
> cvtnstat(&sb, &nsb);
> @@ -2430,7 +2361,8 @@ sys_nlstat(td, uap)
> struct nstat nsb;
> int error;
>
> - error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
> + error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
> + UIO_USERSPACE, &sb, NULL);
> if (error != 0)
> return (error);
> cvtnstat(&sb, &nsb);
> @@ -2519,8 +2451,8 @@ sys_readlink(td, uap)
> } */ *uap;
> {
>
> - return (kern_readlink(td, uap->path, UIO_USERSPACE, uap->buf,
> - UIO_USERSPACE, uap->count));
> + return (kern_readlinkat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->buf, UIO_USERSPACE, uap->count));
> }
> #ifndef _SYS_SYSPROTO_H_
> struct readlinkat_args {
> @@ -2539,15 +2471,6 @@ sys_readlinkat(struct thread *td, struct
> readlinkat_args *uap)
> }
>
> int
> -kern_readlink(struct thread *td, char *path, enum uio_seg pathseg,
> char *buf,
> - enum uio_seg bufseg, size_t count)
> -{
> -
> - return (kern_readlinkat(td, AT_FDCWD, path, pathseg, buf, bufseg,
> - count));
> -}
> -
> -int
> kern_readlinkat(struct thread *td, int fd, char *path, enum uio_seg
> pathseg,
> char *buf, enum uio_seg bufseg, size_t count)
> {
> @@ -2655,7 +2578,8 @@ sys_chflags(td, uap)
> } */ *uap;
> {
>
> - return (kern_chflags(td, uap->path, UIO_USERSPACE, uap->flags));
> + return (kern_chflagsat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->flags, 0));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -2680,14 +2604,6 @@ sys_chflagsat(struct thread *td, struct
> chflagsat_args *uap)
> return (kern_chflagsat(td, fd, path, UIO_USERSPACE, flags, atflag));
> }
>
> -static int
> -kern_chflags(struct thread *td, const char *path, enum uio_seg pathseg,
> - u_long flags)
> -{
> -
> - return (kern_chflagsat(td, AT_FDCWD, path, pathseg, flags, 0));
> -}
> -
> /*
> * Same as chflags() but doesn't follow symlinks.
> */
> @@ -2808,7 +2724,8 @@ sys_chmod(td, uap)
> } */ *uap;
> {
>
> - return (kern_chmod(td, uap->path, UIO_USERSPACE, uap->mode));
> + return (kern_fchmodat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->mode, 0));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -2833,13 +2750,6 @@ sys_fchmodat(struct thread *td, struct
> fchmodat_args *uap)
> return (kern_fchmodat(td, fd, path, UIO_USERSPACE, mode, flag));
> }
>
> -int
> -kern_chmod(struct thread *td, char *path, enum uio_seg pathseg, int mode)
> -{
> -
> - return (kern_fchmodat(td, AT_FDCWD, path, pathseg, mode, 0));
> -}
> -
> /*
> * Change mode of a file given path name (don't follow links.)
> */
> @@ -2961,7 +2871,8 @@ sys_chown(td, uap)
> } */ *uap;
> {
>
> - return (kern_chown(td, uap->path, UIO_USERSPACE, uap->uid, uap->gid));
> + return (kern_fchownat(td, 0, uap->path, UIO_USERSPACE, uap->uid,
> + uap->gid, 0));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -2987,14 +2898,6 @@ sys_fchownat(struct thread *td, struct
> fchownat_args *uap)
> }
>
> int
> -kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid,
> - int gid)
> -{
> -
> - return (kern_fchownat(td, AT_FDCWD, path, pathseg, uid, gid, 0));
> -}
> -
> -int
> kern_fchownat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> int uid, int gid, int flag)
> {
> @@ -3035,16 +2938,8 @@ sys_lchown(td, uap)
> } */ *uap;
> {
>
> - return (kern_lchown(td, uap->path, UIO_USERSPACE, uap->uid, uap->gid));
> -}
> -
> -int
> -kern_lchown(struct thread *td, char *path, enum uio_seg pathseg, int uid,
> - int gid)
> -{
> -
> - return (kern_fchownat(td, AT_FDCWD, path, pathseg, uid, gid,
> - AT_SYMLINK_NOFOLLOW));
> + return (kern_fchownat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->uid, uap->gid, AT_SYMLINK_NOFOLLOW));
> }
>
> /*
> @@ -3174,8 +3069,8 @@ sys_utimes(td, uap)
> } */ *uap;
> {
>
> - return (kern_utimes(td, uap->path, UIO_USERSPACE, uap->tptr,
> - UIO_USERSPACE));
> + return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->tptr, UIO_USERSPACE));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -3194,14 +3089,6 @@ sys_futimesat(struct thread *td, struct
> futimesat_args *uap)
> }
>
> int
> -kern_utimes(struct thread *td, char *path, enum uio_seg pathseg,
> - struct timeval *tptr, enum uio_seg tptrseg)
> -{
> -
> - return (kern_utimesat(td, AT_FDCWD, path, pathseg, tptr, tptrseg));
> -}
> -
> -int
> kern_utimesat(struct thread *td, int fd, char *path, enum uio_seg pathseg,
> struct timeval *tptr, enum uio_seg tptrseg)
> {
> @@ -3500,7 +3387,8 @@ sys_rename(td, uap)
> } */ *uap;
> {
>
> - return (kern_rename(td, uap->from, uap->to, UIO_USERSPACE));
> + return (kern_renameat(td, AT_FDCWD, uap->from, AT_FDCWD,
> + uap->to, UIO_USERSPACE));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -3520,13 +3408,6 @@ sys_renameat(struct thread *td, struct
> renameat_args *uap)
> }
>
> int
> -kern_rename(struct thread *td, char *from, char *to, enum uio_seg
> pathseg)
> -{
> -
> - return (kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, pathseg));
> -}
> -
> -int
> kern_renameat(struct thread *td, int oldfd, char *old, int newfd, char
> *new,
> enum uio_seg pathseg)
> {
> @@ -3675,7 +3556,8 @@ sys_mkdir(td, uap)
> } */ *uap;
> {
>
> - return (kern_mkdir(td, uap->path, UIO_USERSPACE, uap->mode));
> + return (kern_mkdirat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
> + uap->mode));
> }
>
> #ifndef _SYS_SYSPROTO_H_
> @@ -3693,13 +3575,6 @@ sys_mkdirat(struct thread *td, struct
> mkdirat_args *uap)
> }
>
> int
> -kern_mkdir(struct thread *td, char *path, enum uio_seg segflg, int mode)
> -{
> -
> - return (kern_mkdirat(td, AT_FDCWD, path, segflg, mode));
> -}
> -
> -int
> kern_mkdirat(struct thread *td, int fd, char *path, enum uio_seg segflg,
> int mode)
> {
> @@ -3777,14 +3652,7 @@ sys_rmdir(td, uap)
> } */ *uap;
> {
>
> - return (kern_rmdir(td, uap->path, UIO_USERSPACE));
> -}
> -
> -int
> -kern_rmdir(struct thread *td, char *path, enum uio_seg pathseg)
> -{
> -
> - return (kern_rmdirat(td, AT_FDCWD, path, pathseg));
> + return (kern_rmdirat(td, AT_FDCWD, uap->path, UIO_USERSPACE));
> }
>
> int
> diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
> index 7098c43..266c619 100644
> --- a/sys/sys/syscallsubr.h
> +++ b/sys/sys/syscallsubr.h
> @@ -62,22 +62,16 @@ int kern_accept(struct thread *td, int s, struct
> sockaddr **name,
> socklen_t *namelen, struct file **fp);
> int kern_accept4(struct thread *td, int s, struct sockaddr **name,
> socklen_t *namelen, int flags, struct file **fp);
> -int kern_access(struct thread *td, char *path, enum uio_seg pathseg,
> - int flags);
> int kern_accessat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, int flags, int mode);
> int kern_adjtime(struct thread *td, struct timeval *delta,
> struct timeval *olddelta);
> int kern_alternate_path(struct thread *td, const char *prefix, const
> char *path,
> enum uio_seg pathseg, char **pathbuf, int create, int dirfd);
> -int kern_bind(struct thread *td, int fd, struct sockaddr *sa);
> +int kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr
> *sa);
> int kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds,
> size_t ncmds);
> int kern_chdir(struct thread *td, char *path, enum uio_seg pathseg);
> -int kern_chmod(struct thread *td, char *path, enum uio_seg pathseg,
> - int mode);
> -int kern_chown(struct thread *td, char *path, enum uio_seg pathseg,
> int uid,
> - int gid);
> int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which,
> clockid_t *clk_id);
> int kern_clock_getres(struct thread *td, clockid_t clock_id,
> @@ -87,9 +81,8 @@ int kern_clock_gettime(struct thread *td, clockid_t
> clock_id,
> int kern_clock_settime(struct thread *td, clockid_t clock_id,
> struct timespec *ats);
> int kern_close(struct thread *td, int fd);
> -int kern_connect(struct thread *td, int fd, struct sockaddr *sa);
> -int kern_eaccess(struct thread *td, char *path, enum uio_seg pathseg,
> - int flags);
> +int kern_connectat(struct thread *td, int dirfd, int fd,
> + struct sockaddr *sa);
> int kern_execve(struct thread *td, struct image_args *args,
> struct mac *mac_p);
> int kern_fchmodat(struct thread *td, int fd, char *path,
> @@ -127,26 +120,14 @@ int kern_kevent(struct thread *td, int fd, int
> nchanges, int nevents,
> int kern_kldload(struct thread *td, const char *file, int *fileid);
> int kern_kldstat(struct thread *td, int fileid, struct kld_file_stat
> *stat);
> int kern_kldunload(struct thread *td, int fileid, int flags);
> -int kern_lchown(struct thread *td, char *path, enum uio_seg pathseg,
> - int uid, int gid);
> -int kern_link(struct thread *td, char *path, char *link,
> - enum uio_seg segflg);
> int kern_linkat(struct thread *td, int fd1, int fd2, char *path1,
> char *path2, enum uio_seg segflg, int follow);
> -int kern_lstat(struct thread *td, char *path, enum uio_seg pathseg,
> - struct stat *sbp);
> int kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg,
> struct timeval *tptr, enum uio_seg tptrseg);
> -int kern_mkdir(struct thread *td, char *path, enum uio_seg segflg,
> - int mode);
> int kern_mkdirat(struct thread *td, int fd, char *path,
> enum uio_seg segflg, int mode);
> -int kern_mkfifo(struct thread *td, char *path, enum uio_seg pathseg,
> - int mode);
> int kern_mkfifoat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, int mode);
> -int kern_mknod(struct thread *td, char *path, enum uio_seg pathseg,
> - int mode, int dev);
> int kern_mknodat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, int mode, int dev);
> int kern_msgctl(struct thread *, int, int, struct msqid_ds *);
> @@ -156,8 +137,6 @@ int kern_nanosleep(struct thread *td, struct
> timespec *rqt,
> struct timespec *rmt);
> int kern_ogetdirentries(struct thread *td, struct ogetdirentries_args
> *uap,
> long *ploff);
> -int kern_open(struct thread *td, char *path, enum uio_seg pathseg,
> - int flags, int mode);
> int kern_openat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, int flags, int mode);
> int kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg,
> @@ -176,18 +155,13 @@ int kern_pselect(struct thread *td, int nd,
> fd_set *in, fd_set *ou,
> int kern_ptrace(struct thread *td, int req, pid_t pid, void *addr,
> int data);
> int kern_pwritev(struct thread *td, int fd, struct uio *auio, off_t
> offset);
> -int kern_readlink(struct thread *td, char *path, enum uio_seg pathseg,
> - char *buf, enum uio_seg bufseg, size_t count);
> int kern_readlinkat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, char *buf, enum uio_seg bufseg, size_t count);
> int kern_readv(struct thread *td, int fd, struct uio *auio);
> int kern_recvit(struct thread *td, int s, struct msghdr *mp,
> enum uio_seg fromseg, struct mbuf **controlp);
> -int kern_rename(struct thread *td, char *from, char *to,
> - enum uio_seg pathseg);
> int kern_renameat(struct thread *td, int oldfd, char *old, int newfd,
> char *new, enum uio_seg pathseg);
> -int kern_rmdir(struct thread *td, char *path, enum uio_seg pathseg);
> int kern_rmdirat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg);
> int kern_sched_rr_get_interval(struct thread *td, pid_t pid,
> @@ -220,17 +194,11 @@ int kern_sigprocmask(struct thread *td, int how,
> int kern_sigsuspend(struct thread *td, sigset_t mask);
> int kern_sigtimedwait(struct thread *td, sigset_t waitset,
> struct ksiginfo *ksi, struct timespec *timeout);
> -int kern_stat(struct thread *td, char *path, enum uio_seg pathseg,
> - struct stat *sbp);
> int kern_statat(struct thread *td, int flag, int fd, char *path,
> - enum uio_seg pathseg, struct stat *sbp);
> -int kern_statat_vnhook(struct thread *td, int flag, int fd, char *path,
> enum uio_seg pathseg, struct stat *sbp,
> void (*hook)(struct vnode *vp, struct stat *sbp));
> int kern_statfs(struct thread *td, char *path, enum uio_seg pathseg,
> struct statfs *buf);
> -int kern_symlink(struct thread *td, char *path, char *link,
> - enum uio_seg segflg);
> int kern_symlinkat(struct thread *td, char *path1, int fd, char *path2,
> enum uio_seg segflg);
> int kern_ktimer_create(struct thread *td, clockid_t clock_id,
> @@ -245,11 +213,8 @@ int kern_thr_new(struct thread *td, struct
> thr_param *param);
> int kern_thr_suspend(struct thread *td, struct timespec *tsp);
> int kern_truncate(struct thread *td, char *path, enum uio_seg pathseg,
> off_t length);
> -int kern_unlink(struct thread *td, char *path, enum uio_seg pathseg);
> int kern_unlinkat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, ino_t oldinum);
> -int kern_utimes(struct thread *td, char *path, enum uio_seg pathseg,
> - struct timeval *tptr, enum uio_seg tptrseg);
> int kern_utimesat(struct thread *td, int fd, char *path,
> enum uio_seg pathseg, struct timeval *tptr, enum uio_seg tptrseg);
> int kern_wait(struct thread *td, pid_t pid, int *status, int options,
> _______________________________________________
> freebsd-arch@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-arch
> To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"

-- Jonathan Anderson
jonathan@FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5463C39C.2010204>