Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add Linux-compatible {, fl}{get, set, list}xattr() system c...



details:   https://anonhg.NetBSD.org/src/rev/0f61efe0f106
branches:  trunk
changeset: 582905:0f61efe0f106
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Jul 10 22:04:20 2005 +0000

description:
Add Linux-compatible {,fl}{get,set,list}xattr() system call interface
to the VFS extended attribute subsystem.

diffstat:

 sys/kern/syscalls.master |   29 +++-
 sys/kern/vfs_xattr.c     |  406 ++++++++++++++++++++++++++++++++++++++++++++++-
 sys/sys/extattr.h        |   11 +-
 sys/sys/xattr.h          |   88 ++++++++++
 4 files changed, 527 insertions(+), 7 deletions(-)

diffs (truncated from 605 to 300 lines):

diff -r f4d613e42ee3 -r 0f61efe0f106 sys/kern/syscalls.master
--- a/sys/kern/syscalls.master  Sun Jul 10 19:07:39 2005 +0000
+++ b/sys/kern/syscalls.master  Sun Jul 10 22:04:20 2005 +0000
@@ -1,4 +1,4 @@
-       $NetBSD: syscalls.master,v 1.146 2005/05/29 21:07:49 christos Exp $
+       $NetBSD: syscalls.master,v 1.147 2005/07/10 22:04:20 thorpej Exp $
 
 ;      @(#)syscalls.master     8.2 (Berkeley) 1/13/94
 
@@ -751,3 +751,30 @@
                            const sigset_t *mask); }
 374    STD             { int sys_pollts(struct pollfd *fds, u_int nfds, \
                            const struct timespec *ts, const sigset_t *mask); }
+375    STD             { int sys_setxattr(const char *path, \
+                           const char *name, void *value, size_t size, \
+                           int flags); }
+376    STD             { int sys_lsetxattr(const char *path, \
+                           const char *name, void *value, size_t size, \
+                           int flags); }
+377    STD             { int sys_fsetxattr(int fd, \
+                           const char *name, void *value, size_t size, \
+                           int flags); }
+378    STD             { int sys_getxattr(const char *path, \
+                           const char *name, void *value, size_t size); }
+379    STD             { int sys_lgetxattr(const char *path, \
+                           const char *name, void *value, size_t size); }
+380    STD             { int sys_fgetxattr(int fd, \
+                           const char *name, void *value, size_t size); }
+381    STD             { int sys_listxattr(const char *path, \
+                           char *list, size_t size); }
+382    STD             { int sys_llistxattr(const char *path, \
+                           char *list, size_t size); }
+383    STD             { int sys_flistxattr(int fd, \
+                           char *list, size_t size); }
+384    STD             { int sys_removexattr(const char *path, \
+                           const char *name); }
+385    STD             { int sys_lremovexattr(const char *path, \
+                           const char *name); }
+386    STD             { int sys_fremovexattr(int fd, \
+                           const char *name); }
diff -r f4d613e42ee3 -r 0f61efe0f106 sys/kern/vfs_xattr.c
--- a/sys/kern/vfs_xattr.c      Sun Jul 10 19:07:39 2005 +0000
+++ b/sys/kern/vfs_xattr.c      Sun Jul 10 22:04:20 2005 +0000
@@ -1,4 +1,40 @@
-/*     $NetBSD: vfs_xattr.c,v 1.1 2005/07/09 01:05:24 thorpej Exp $    */
+/*     $NetBSD: vfs_xattr.c,v 1.2 2005/07/10 22:04:20 thorpej Exp $    */
+
+/*-
+ * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 /*
  * Copyright (c) 1989, 1993
@@ -39,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.1 2005/07/09 01:05:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.2 2005/07/10 22:04:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -52,12 +88,14 @@
 #include <sys/proc.h>
 #include <sys/uio.h>
 #include <sys/extattr.h>
+#include <sys/xattr.h>
 #include <sys/sysctl.h>
 #include <sys/sa.h>
 #include <sys/syscallargs.h>
 
 /*
- * Push extended attribute configuration information into the VFS.
+ * Push extended attribute configuration information into the file
+ * system.
  *
  * NOTE: Not all file systems that support extended attributes will
  * require the use of this system call.
@@ -680,3 +718,365 @@
        vrele(nd.ni_vp);
        return (error);
 }
+
+/*****************************************************************************
+ * Linux-compatible <sys/xattr.h> API for file system extended attributes
+ *****************************************************************************/
+
+int
+sys_setxattr(struct lwp *l, void *v, register_t *retval)
+{
+       struct sys_setxattr_args /* {
+               syscallarg(const char *) path;
+               syscallarg(const char *) name;
+               syscallarg(void *) value;
+               syscallarg(size_t) size;
+               syscallarg(int) flags;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct nameidata nd;
+       char attrname[XATTR_NAME_MAX];
+       int error;
+
+       error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
+           NULL);
+       if (error)
+               return (error);
+
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
+       error = namei(&nd);
+       if (error)
+               return (error);
+
+       /* XXX flags */
+
+       error = extattr_set_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
+           attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
+
+       vrele(nd.ni_vp);
+       return (error);
+}
+
+int
+sys_lsetxattr(struct lwp *l, void *v, register_t *retval)
+{
+       struct sys_lsetxattr_args /* {
+               syscallarg(const char *) path;
+               syscallarg(const char *) name;
+               syscallarg(void *) value;
+               syscallarg(size_t) size;
+               syscallarg(int) flags;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct nameidata nd;
+       char attrname[XATTR_NAME_MAX];
+       int error;
+
+       error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
+           NULL);
+       if (error)
+               return (error);
+
+       NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
+       error = namei(&nd);
+       if (error)
+               return (error);
+
+       /* XXX flags */
+
+       error = extattr_set_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
+           attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
+
+       vrele(nd.ni_vp);
+       return (error);
+}
+
+int
+sys_fsetxattr(struct lwp *l, void *v, register_t *retval)
+{
+       struct sys_fsetxattr_args /* {
+               syscallarg(int) fd;
+               syscallarg(const char *) name;
+               syscallarg(void *) value;
+               syscallarg(size_t) size;
+               syscallarg(int) flags;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct file *fp;
+       struct vnode *vp;
+       char attrname[XATTR_NAME_MAX];
+       int error;
+
+       error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
+           NULL);
+       if (error)
+               return (error);
+
+       error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
+       if (error)
+               return (error);
+       vp = (struct vnode *) fp->f_data;
+
+       /* XXX flags */
+
+       error = extattr_set_vp(vp, EXTATTR_NAMESPACE_USER,
+           attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
+
+       FILE_UNUSE(fp, p);
+       return (error);
+}
+
+int
+sys_getxattr(struct lwp *l, void *v, register_t *retval)
+{
+       struct sys_getxattr_args /* {
+               syscallarg(const char *) path;
+               syscallarg(const char *) name;
+               syscallarg(void *) value;
+               syscallarg(size_t) size;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct nameidata nd;
+       char attrname[XATTR_NAME_MAX];
+       int error;
+
+       error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
+           NULL);
+       if (error)
+               return (error);
+
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
+       error = namei(&nd);
+       if (error)
+               return (error);
+
+       error = extattr_get_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
+           attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
+
+       vrele(nd.ni_vp);
+       return (error);
+}
+
+int
+sys_lgetxattr(struct lwp *l, void *v, register_t *retval)
+{
+       struct sys_lgetxattr_args /* {
+               syscallarg(const char *) path;
+               syscallarg(const char *) name;
+               syscallarg(void *) value;
+               syscallarg(size_t) size;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct nameidata nd;
+       char attrname[XATTR_NAME_MAX];
+       int error;
+
+       error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
+           NULL);
+       if (error)
+               return (error);
+
+       NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
+       error = namei(&nd);
+       if (error)
+               return (error);
+
+       error = extattr_get_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
+           attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
+
+       vrele(nd.ni_vp);
+       return (error);
+}
+
+int
+sys_fgetxattr(struct lwp *l, void *v, register_t *retval)
+{
+       struct sys_fgetxattr_args /* {
+               syscallarg(int) fd;
+               syscallarg(const char *) name;
+               syscallarg(void *) value;
+               syscallarg(size_t) size;
+       } */ *uap = v;
+       struct proc *p = l->l_proc;
+       struct file *fp;
+       struct vnode *vp;
+       char attrname[XATTR_NAME_MAX];
+       int error;
+
+       error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),



Home | Main Index | Thread Index | Old Index