From 6376b2136cf4a3576ab12cd1ec4421a41912e369 Mon Sep 17 00:00:00 2001 From: pooka Date: Wed, 30 Jun 2010 15:44:54 +0000 Subject: [PATCH] Enable kernel-internal symlink creation with do_sys_symlink(). I did this a while ago already, but can't remember why i didn't commit it then. --- sys/kern/vfs_syscalls.c | 45 +++++++++++++++++++++++++---------------- sys/sys/vfs_syscalls.h | 3 ++- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index eea6d79c9127..9cfd222fb300 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.406 2010/06/24 13:03:12 hannken Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.407 2010/06/30 15:44:54 pooka Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.406 2010/06/24 13:03:12 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.407 2010/06/30 15:44:54 pooka Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -2024,29 +2024,24 @@ out: return (error); } -/* - * Make a symbolic link. - */ -/* ARGSUSED */ int -sys_symlink(struct lwp *l, const struct sys_symlink_args *uap, register_t *retval) +do_sys_symlink(const char *patharg, const char *link, enum uio_seg seg) { - /* { - syscallarg(const char *) path; - syscallarg(const char *) link; - } */ - struct proc *p = l->l_proc; + struct proc *p = curproc; struct vattr vattr; char *path; int error; struct nameidata nd; path = PNBUF_GET(); - error = copyinstr(SCARG(uap, path), path, MAXPATHLEN, NULL); - if (error) - goto out; - NDINIT(&nd, CREATE, LOCKPARENT | TRYEMULROOT, UIO_USERSPACE, - SCARG(uap, link)); + if (seg == UIO_USERSPACE) { + if ((error = copyinstr(patharg, path, MAXPATHLEN, NULL)) != 0) + goto out; + } else { + KASSERT(strlen(patharg) < MAXPATHLEN); + strcpy(path, patharg); + } + NDINIT(&nd, CREATE, LOCKPARENT | TRYEMULROOT, seg, link); if ((error = namei(&nd)) != 0) goto out; if (nd.ni_vp) { @@ -2071,6 +2066,22 @@ out: return (error); } +/* + * Make a symbolic link. + */ +/* ARGSUSED */ +int +sys_symlink(struct lwp *l, const struct sys_symlink_args *uap, register_t *retval) +{ + /* { + syscallarg(const char *) path; + syscallarg(const char *) link; + } */ + + return do_sys_symlink(SCARG(uap, path), SCARG(uap, link), + UIO_USERSPACE); +} + /* * Delete a whiteout from the filesystem. */ diff --git a/sys/sys/vfs_syscalls.h b/sys/sys/vfs_syscalls.h index 0cff328c48b8..1fcca4bc3c86 100644 --- a/sys/sys/vfs_syscalls.h +++ b/sys/sys/vfs_syscalls.h @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.h,v 1.13 2009/08/09 22:49:00 haad Exp $ */ +/* $NetBSD: vfs_syscalls.h,v 1.14 2010/06/30 15:44:55 pooka Exp $ */ /* * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -65,6 +65,7 @@ int do_sys_rename(const char *, const char *, enum uio_seg, int); int do_sys_mknod(struct lwp *, const char *, mode_t, dev_t, register_t *, enum uio_seg); int do_sys_mkdir(const char *, mode_t, enum uio_seg); +int do_sys_symlink(const char *, const char *, enum uio_seg); int chdir_lookup(const char *, int, struct vnode **, struct lwp *); void change_root(struct cwdinfo *, struct vnode *, struct lwp *);