Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Fix multiple non compliances in our Linux-like extattr API, ...
details: https://anonhg.NetBSD.org/src/rev/172554ef599d
branches: trunk
changeset: 766558:172554ef599d
user: manu <manu%NetBSD.org@localhost>
date: Mon Jun 27 16:39:43 2011 +0000
description:
Fix multiple non compliances in our Linux-like extattr API, and make it
public so that it can be used.
diffstat:
distrib/sets/lists/comp/mi | 3 +-
lib/libc/sys/Makefile.inc | 5 +-
sys/kern/vfs_xattr.c | 201 +++++++++++++++++++++++++++++++++++++-------
sys/sys/Makefile | 4 +-
4 files changed, 176 insertions(+), 37 deletions(-)
diffs (truncated from 502 to 300 lines):
diff -r 2dd88aa55f43 -r 172554ef599d distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Mon Jun 27 16:34:47 2011 +0000
+++ b/distrib/sets/lists/comp/mi Mon Jun 27 16:39:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1633 2011/06/27 11:52:22 uch Exp $
+# $NetBSD: mi,v 1.1634 2011/06/27 16:39:43 manu Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2228,6 +2228,7 @@
./usr/include/sys/wapbl.h comp-c-include
./usr/include/sys/wapbl_replay.h comp-c-include
./usr/include/sys/wdog.h comp-c-include
+./usr/include/sys/xattr.h comp-c-include
./usr/include/sysexits.h comp-c-include
./usr/include/syslog.h comp-c-include
./usr/include/tar.h comp-c-include
diff -r 2dd88aa55f43 -r 172554ef599d lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Mon Jun 27 16:34:47 2011 +0000
+++ b/lib/libc/sys/Makefile.inc Mon Jun 27 16:39:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.206 2011/06/26 16:42:41 christos Exp $
+# $NetBSD: Makefile.inc,v 1.207 2011/06/27 16:39:44 manu Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 10/24/94
# sys sources
@@ -84,6 +84,9 @@
extattr_get_link.S extattr_list_fd.S extattr_list_file.S \
extattr_list_link.S extattr_set_fd.S extattr_set_file.S \
extattr_set_link.S \
+ setxattr.S getxattr.S listxattr.S removexattr.S \
+ lsetxattr.S lgetxattr.S llistxattr.S lremovexattr.S \
+ fsetxattr.S fgetxattr.S flistxattr.S fremovexattr.S \
fchdir.S fchflags.S fchmod.S fchown.S fchroot.S \
__fhopen40.S __fhstat50.S __fhstatvfs140.S fktrace.S \
flock.S fpathconf.S __fstat50.S fstatvfs1.S __futimes50.S \
diff -r 2dd88aa55f43 -r 172554ef599d sys/kern/vfs_xattr.c
--- a/sys/kern/vfs_xattr.c Mon Jun 27 16:34:47 2011 +0000
+++ b/sys/kern/vfs_xattr.c Mon Jun 27 16:39:43 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_xattr.c,v 1.23 2010/11/19 06:44:45 dholland Exp $ */
+/* $NetBSD: vfs_xattr.c,v 1.24 2011/06/27 16:39:43 manu Exp $ */
/*-
* Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.23 2010/11/19 06:44:45 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.24 2011/06/27 16:39:43 manu Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -212,7 +212,8 @@
*/
static int
extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
- const void *data, size_t nbytes, struct lwp *l, register_t *retval)
+ const void *data, size_t nbytes, struct lwp *l, register_t *retval,
+ int flag)
{
struct uio auio;
struct iovec aiov;
@@ -221,6 +222,29 @@
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ if (flag) {
+ size_t attrlen;
+
+ error = VOP_GETEXTATTR(vp, attrnamespace, attrname, NULL,
+ &attrlen, l->l_cred);
+
+ switch (error) {
+ case ENOATTR:
+ if (flag & XATTR_REPLACE)
+ goto done;
+ break;
+ case 0:
+ if (flag & XATTR_CREATE) {
+ error = EEXIST;
+ goto done;
+ }
+ break;
+ default:
+ goto done;
+ break;
+ }
+ }
+
aiov.iov_base = __UNCONST(data); /* XXXUNCONST kills const */
aiov.iov_len = nbytes;
auio.uio_iov = &aiov;
@@ -405,7 +429,7 @@
vp = (struct vnode *) fp->f_data;
error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
- SCARG(uap, data), SCARG(uap, nbytes), l, retval);
+ SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
fd_putfile(SCARG(uap, fd));
return (error);
@@ -436,7 +460,7 @@
return (error);
error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
- SCARG(uap, data), SCARG(uap, nbytes), l, retval);
+ SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
vrele(vp);
return (error);
@@ -467,7 +491,7 @@
return (error);
error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
- SCARG(uap, data), SCARG(uap, nbytes), l, retval);
+ SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
vrele(vp);
return (error);
@@ -729,6 +753,23 @@
* Linux-compatible <sys/xattr.h> API for file system extended attributes
*****************************************************************************/
+#define MATCH_NS(ns, key) (strncmp(ns, key, sizeof(ns) - 1) == 0)
+static int
+xattr_native(const char *key) {
+ if (MATCH_NS("system.", key))
+ return EXTATTR_NAMESPACE_SYSTEM;
+ else if (MATCH_NS("user.", key))
+ return EXTATTR_NAMESPACE_USER;
+ else if (MATCH_NS("security.", key))
+ return EXTATTR_NAMESPACE_SYSTEM;
+ else if (MATCH_NS("trusted.", key))
+ return EXTATTR_NAMESPACE_SYSTEM;
+ else
+ return EXTATTR_NAMESPACE_USER;
+
+}
+#undef MATCH_NS
+
int
sys_setxattr(struct lwp *l, const struct sys_setxattr_args *uap, register_t *retval)
{
@@ -741,24 +782,30 @@
} */
struct vnode *vp;
char attrname[XATTR_NAME_MAX];
+ int namespace;
+ register_t attrlen;
int error;
error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
NULL);
if (error)
- return (error);
+ goto out;
error = namei_simple_user(SCARG(uap, path),
NSM_FOLLOW_NOEMULROOT, &vp);
if (error)
- return (error);
+ goto out_rele;
- /* XXX flags */
+ namespace = xattr_native(attrname);
- error = extattr_set_vp(vp, EXTATTR_NAMESPACE_USER,
- attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
+ error = extattr_set_vp(vp, namespace,
+ attrname, SCARG(uap, value), SCARG(uap, size), l,
+ &attrlen, SCARG(uap, flags));
+out_rele:
vrele(vp);
+out:
+ *retval = (error == 0) ? 0 : -1;
return (error);
}
@@ -774,24 +821,30 @@
} */
struct vnode *vp;
char attrname[XATTR_NAME_MAX];
+ int namespace;
+ register_t attrlen;
int error;
error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
NULL);
if (error)
- return (error);
+ goto out;
error = namei_simple_user(SCARG(uap, path),
NSM_NOFOLLOW_NOEMULROOT, &vp);
if (error)
- return (error);
+ goto out_rele;
- /* XXX flags */
+ namespace = xattr_native(attrname);
- error = extattr_set_vp(vp, EXTATTR_NAMESPACE_USER,
- attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
+ error = extattr_set_vp(vp, namespace,
+ attrname, SCARG(uap, value), SCARG(uap, size), l,
+ &attrlen, SCARG(uap, flags));
+out_rele:
vrele(vp);
+out:
+ *retval = (error == 0) ? 0 : -1;
return (error);
}
@@ -808,24 +861,29 @@
struct file *fp;
struct vnode *vp;
char attrname[XATTR_NAME_MAX];
+ int namespace;
+ register_t attrlen;
int error;
error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
NULL);
if (error)
- return (error);
+ goto out;
error = fd_getvnode(SCARG(uap, fd), &fp);
if (error)
- return (error);
+ goto out;
vp = (struct vnode *) fp->f_data;
- /* XXX flags */
+ namespace = xattr_native(attrname);
- error = extattr_set_vp(vp, EXTATTR_NAMESPACE_USER,
- attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
+ error = extattr_set_vp(vp, namespace,
+ attrname, SCARG(uap, value), SCARG(uap, size), l,
+ &attrlen, SCARG(uap, flags));
fd_putfile(SCARG(uap, fd));
+out:
+ *retval = (error == 0) ? 0 : -1;
return (error);
}
@@ -840,6 +898,7 @@
} */
struct vnode *vp;
char attrname[XATTR_NAME_MAX];
+ int namespace;
int error;
error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
@@ -852,7 +911,9 @@
if (error)
return (error);
- error = extattr_get_vp(vp, EXTATTR_NAMESPACE_USER,
+ namespace = xattr_native(attrname);
+
+ error = extattr_get_vp(vp, namespace,
attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
vrele(vp);
@@ -870,6 +931,7 @@
} */
struct vnode *vp;
char attrname[XATTR_NAME_MAX];
+ int namespace;
int error;
error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
@@ -882,7 +944,9 @@
if (error)
return (error);
- error = extattr_get_vp(vp, EXTATTR_NAMESPACE_USER,
+ namespace = xattr_native(attrname);
+
+ error = extattr_get_vp(vp, namespace,
attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
vrele(vp);
@@ -901,6 +965,7 @@
struct file *fp;
struct vnode *vp;
char attrname[XATTR_NAME_MAX];
+ int namespace;
int error;
error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
@@ -913,7 +978,9 @@
return (error);
Home |
Main Index |
Thread Index |
Old Index