aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2021-04-25 13:13:02 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2021-04-25 13:13:12 +0000
commit5d1d844a77622878cd05478d4ab504f70e067248 (patch)
treeb6415a469227f10f291d115b14c2e3e81df3f9f3
parentb68e6569221ecade8899eaab8e1b088947ef2f8a (diff)
downloadsrc-5d1d844a77622878cd05478d4ab504f70e067248.tar.gz
src-5d1d844a77622878cd05478d4ab504f70e067248.zip
kern_linkat: modify to accept AT_ flags instead of FOLLOW/NOFOLLOW
This makes this API match other kern_xxxat() functions. Reviewed By: kib Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D29776
-rw-r--r--sys/compat/cloudabi/cloudabi_file.c2
-rw-r--r--sys/compat/linux/linux_file.c15
-rw-r--r--sys/kern/vfs_syscalls.c12
-rw-r--r--sys/sys/syscallsubr.h2
4 files changed, 16 insertions, 15 deletions
diff --git a/sys/compat/cloudabi/cloudabi_file.c b/sys/compat/cloudabi/cloudabi_file.c
index f7d93bc85cad..83987b79aa0c 100644
--- a/sys/compat/cloudabi/cloudabi_file.c
+++ b/sys/compat/cloudabi/cloudabi_file.c
@@ -185,7 +185,7 @@ cloudabi_sys_file_link(struct thread *td,
error = kern_linkat(td, uap->fd1.fd, uap->fd2, path1, path2,
UIO_SYSSPACE, (uap->fd1.flags & CLOUDABI_LOOKUP_SYMLINK_FOLLOW) ?
- FOLLOW : NOFOLLOW);
+ AT_SYMLINK_FOLLOW : 0);
cloudabi_freestr(path1);
cloudabi_freestr(path2);
return (error);
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index 6b02c2efb88e..1febb11b0131 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1111,7 +1111,7 @@ linux_link(struct thread *td, struct linux_link_args *args)
if (!LUSECONVPATH(td)) {
return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
- UIO_USERSPACE, FOLLOW));
+ UIO_USERSPACE, AT_SYMLINK_FOLLOW));
}
LCONVPATHEXIST(td, args->path, &path);
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
@@ -1121,7 +1121,7 @@ linux_link(struct thread *td, struct linux_link_args *args)
return (error);
}
error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
- FOLLOW);
+ AT_SYMLINK_FOLLOW);
LFREEPATH(path);
LFREEPATH(to);
return (error);
@@ -1132,18 +1132,19 @@ int
linux_linkat(struct thread *td, struct linux_linkat_args *args)
{
char *path, *to;
- int error, olddfd, newdfd, follow;
+ int error, olddfd, newdfd, flag;
if (args->flag & ~LINUX_AT_SYMLINK_FOLLOW)
return (EINVAL);
+ flag = (args->flag & LINUX_AT_SYMLINK_FOLLOW) == 0 ? AT_SYMLINK_FOLLOW :
+ 0;
+
olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
- follow = (args->flag & LINUX_AT_SYMLINK_FOLLOW) == 0 ? NOFOLLOW :
- FOLLOW;
if (!LUSECONVPATH(td)) {
return (kern_linkat(td, olddfd, newdfd, args->oldname,
- args->newname, UIO_USERSPACE, follow));
+ args->newname, UIO_USERSPACE, flag));
}
LCONVPATHEXIST_AT(td, args->oldname, &path, olddfd);
/* Expand LCONVPATHCREATE so that `path' can be freed on errors */
@@ -1152,7 +1153,7 @@ linux_linkat(struct thread *td, struct linux_linkat_args *args)
LFREEPATH(path);
return (error);
}
- error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, follow);
+ error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, flag);
LFREEPATH(path);
LFREEPATH(to);
return (error);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 26a8d31e4456..32e4c8688762 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1495,7 +1495,7 @@ sys_link(struct thread *td, struct link_args *uap)
{
return (kern_linkat(td, AT_FDCWD, AT_FDCWD, uap->path, uap->link,
- UIO_USERSPACE, FOLLOW));
+ UIO_USERSPACE, AT_SYMLINK_FOLLOW));
}
#ifndef _SYS_SYSPROTO_H_
@@ -1518,8 +1518,7 @@ sys_linkat(struct thread *td, struct linkat_args *uap)
return (EINVAL);
return (kern_linkat(td, uap->fd1, uap->fd2, uap->path1, uap->path2,
- UIO_USERSPACE, at2cnpflags(flag, AT_SYMLINK_FOLLOW |
- AT_RESOLVE_BENEATH | AT_EMPTY_PATH)));
+ UIO_USERSPACE, flag));
}
int hardlink_check_uid = 0;
@@ -1563,15 +1562,16 @@ can_hardlink(struct vnode *vp, struct ucred *cred)
int
kern_linkat(struct thread *td, int fd1, int fd2, const char *path1,
- const char *path2, enum uio_seg segflag, int follow)
+ const char *path2, enum uio_seg segflag, int flag)
{
struct nameidata nd;
int error;
do {
bwillwrite();
- NDINIT_ATRIGHTS(&nd, LOOKUP, follow | AUDITVNODE1, segflag,
- path1, fd1, &cap_linkat_source_rights, td);
+ NDINIT_ATRIGHTS(&nd, LOOKUP, AUDITVNODE1 | at2cnpflags(flag,
+ AT_SYMLINK_FOLLOW | AT_RESOLVE_BENEATH | AT_EMPTY_PATH),
+ segflag, path1, fd1, &cap_linkat_source_rights, td);
if ((error = namei(&nd)) != 0)
return (error);
NDFREE(&nd, NDF_ONLY_PNBUF);
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 9e889e9d5465..471c38ab0e12 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -184,7 +184,7 @@ 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_linkat(struct thread *td, int fd1, int fd2, const char *path1,
- const char *path2, enum uio_seg segflg, int follow);
+ const char *path2, enum uio_seg segflg, int flag);
int kern_listen(struct thread *td, int s, int backlog);
int kern_lseek(struct thread *td, int fd, off_t offset, int whence);
int kern_lutimes(struct thread *td, const char *path, enum uio_seg pathseg,