Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Make cp -p and mv preverve extended attributes, and complain...
details: https://anonhg.NetBSD.org/src/rev/0c4cea04a0a1
branches: trunk
changeset: 767914:0c4cea04a0a1
user: manu <manu%NetBSD.org@localhost>
date: Wed Aug 03 04:11:15 2011 +0000
description:
Make cp -p and mv preverve extended attributes, and complain if they cannot.
Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
accessible to the caller are copied, and the others are silently ignored.
diffstat:
bin/cp/cp.c | 11 +-
bin/cp/utils.c | 8 +-
bin/mv/mv.c | 9 +-
distrib/sets/lists/comp/mi | 20 ++-
lib/libc/gen/Makefile.inc | 10 +-
lib/libc/gen/extattr.3 | 52 ++++++-
lib/libc/gen/extattr.c | 298 +++++++++++++++++++++++++++++++++++++++-
lib/libc/sys/extattr_get_file.2 | 12 +-
sys/sys/extattr.h | 11 +-
9 files changed, 415 insertions(+), 16 deletions(-)
diffs (truncated from 711 to 300 lines):
diff -r 7ec7bd1fb283 -r 0c4cea04a0a1 bin/cp/cp.c
--- a/bin/cp/cp.c Wed Aug 03 02:57:23 2011 +0000
+++ b/bin/cp/cp.c Wed Aug 03 04:11:15 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cp.c,v 1.55 2011/02/06 12:37:49 darcy Exp $ */
+/* $NetBSD: cp.c,v 1.56 2011/08/03 04:11:15 manu Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
#else
-__RCSID("$NetBSD: cp.c,v 1.55 2011/02/06 12:37:49 darcy Exp $");
+__RCSID("$NetBSD: cp.c,v 1.56 2011/08/03 04:11:15 manu Exp $");
#endif
#endif /* not lint */
@@ -197,6 +197,13 @@
myumask = umask(0);
(void)umask(myumask);
+ /*
+ * Warn that system extended attributes will not be preserved
+ * if not root
+ */
+ if ((myuid != 0) && pflag)
+ warnx("system extended attribute will not be preserved");
+
/* Save the target base in "to". */
target = argv[--argc];
if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
diff -r 7ec7bd1fb283 -r 0c4cea04a0a1 bin/cp/utils.c
--- a/bin/cp/utils.c Wed Aug 03 02:57:23 2011 +0000
+++ b/bin/cp/utils.c Wed Aug 03 04:11:15 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: utils.c,v 1.39 2011/02/06 12:37:49 darcy Exp $ */
+/* $NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
#else
-__RCSID("$NetBSD: utils.c,v 1.39 2011/02/06 12:37:49 darcy Exp $");
+__RCSID("$NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $");
#endif
#endif /* not lint */
@@ -42,6 +42,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/extattr.h>
#include <err.h>
#include <errno.h>
@@ -227,6 +228,9 @@
}
}
+ if (pflag && (fcpxattr(from_fd, to_fd) != 0))
+ warn("%s: error copying extended attributes", to.p_path);
+
(void)close(from_fd);
if (rval == 1) {
diff -r 7ec7bd1fb283 -r 0c4cea04a0a1 bin/mv/mv.c
--- a/bin/mv/mv.c Wed Aug 03 02:57:23 2011 +0000
+++ b/bin/mv/mv.c Wed Aug 03 04:11:15 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mv.c,v 1.41 2008/07/20 00:52:40 lukem Exp $ */
+/* $NetBSD: mv.c,v 1.42 2011/08/03 04:11:15 manu Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: mv.c,v 1.41 2008/07/20 00:52:40 lukem Exp $");
+__RCSID("$NetBSD: mv.c,v 1.42 2011/08/03 04:11:15 manu Exp $");
#endif
#endif /* not lint */
@@ -50,6 +50,7 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/stat.h>
+#include <sys/extattr.h>
#include <err.h>
#include <errno.h>
@@ -290,6 +291,10 @@
(void)close(to_fd);
return (1);
}
+
+ if (fcpxattr(from_fd, to_fd) == -1)
+ warn("%s: error copying extended attributes", to);
+
(void)close(from_fd);
#ifdef BSD4_4
TIMESPEC_TO_TIMEVAL(&tval[0], &sbp->st_atimespec);
diff -r 7ec7bd1fb283 -r 0c4cea04a0a1 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Wed Aug 03 02:57:23 2011 +0000
+++ b/distrib/sets/lists/comp/mi Wed Aug 03 04:11:15 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1651 2011/07/31 03:48:49 dholland Exp $
+# $NetBSD: mi,v 1.1652 2011/08/03 04:11:15 manu Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -5973,6 +5973,7 @@
./usr/share/man/cat3/cpuset_set.0 comp-c-catman .cat
./usr/share/man/cat3/cpuset_size.0 comp-c-catman .cat
./usr/share/man/cat3/cpuset_zero.0 comp-c-catman .cat
+./usr/share/man/cat3/cpxattr.0 comp-c-catman .cat
./usr/share/man/cat3/creal.0 comp-c-catman complex,.cat
./usr/share/man/cat3/crealf.0 comp-c-catman complex,.cat
./usr/share/man/cat3/creall.0 comp-c-catman complex,.cat
@@ -6330,6 +6331,9 @@
./usr/share/man/cat3/expm1.0 comp-c-catman .cat
./usr/share/man/cat3/expm1f.0 comp-c-catman .cat
./usr/share/man/cat3/extattr.0 comp-c-catman .cat
+./usr/share/man/cat3/extattr_copy_fd.0 comp-c-catman .cat
+./usr/share/man/cat3/extattr_copy_file.0 comp-c-catman .cat
+./usr/share/man/cat3/extattr_copy_link.0 comp-c-catman .cat
./usr/share/man/cat3/extattr_namespace_to_string.0 comp-c-catman .cat
./usr/share/man/cat3/extattr_string_to_namespace.0 comp-c-catman .cat
./usr/share/man/cat3/fabs.0 comp-c-catman .cat
@@ -6338,6 +6342,7 @@
./usr/share/man/cat3/fast_divide32_prepare.0 comp-c-catman .cat
./usr/share/man/cat3/fast_remainder32.0 comp-c-catman .cat
./usr/share/man/cat3/fclose.0 comp-c-catman .cat
+./usr/share/man/cat3/fcpxattr.0 comp-c-catman .cat
./usr/share/man/cat3/fdim.0 comp-c-catman .cat
./usr/share/man/cat3/fdimf.0 comp-c-catman .cat
./usr/share/man/cat3/fdiml.0 comp-c-catman .cat
@@ -7507,6 +7512,7 @@
./usr/share/man/cat3/lber-sockbuf.0 comp-ldap-catman ldap,.cat
./usr/share/man/cat3/lber-types.0 comp-ldap-catman ldap,.cat
./usr/share/man/cat3/lcong48.0 comp-c-catman .cat
+./usr/share/man/cat3/lcpxattr.0 comp-c-catman .cat
./usr/share/man/cat3/ld_errno.0 comp-ldap-catman ldap,.cat
./usr/share/man/cat3/ldap.0 comp-ldap-catman ldap,.cat
./usr/share/man/cat3/ldap_abandon.0 comp-ldap-catman ldap,.cat
@@ -12081,6 +12087,7 @@
./usr/share/man/html3/cpuset_set.html comp-c-htmlman html
./usr/share/man/html3/cpuset_size.html comp-c-htmlman html
./usr/share/man/html3/cpuset_zero.html comp-c-htmlman html
+./usr/share/man/html3/cpxattr.html comp-c-htmlman html
./usr/share/man/html3/creal.html comp-c-htmlman complex,html
./usr/share/man/html3/crealf.html comp-c-htmlman complex,html
./usr/share/man/html3/creall.html comp-c-htmlman complex,html
@@ -12436,6 +12443,9 @@
./usr/share/man/html3/expm1.html comp-c-htmlman html
./usr/share/man/html3/expm1f.html comp-c-htmlman html
./usr/share/man/html3/extattr.html comp-c-htmlman html
+./usr/share/man/html3/extattr_copy_fd.html comp-c-htmlman html
+./usr/share/man/html3/extattr_copy_file.html comp-c-htmlman html
+./usr/share/man/html3/extattr_copy_link.html comp-c-htmlman html
./usr/share/man/html3/extattr_namespace_to_string.html comp-c-htmlman html
./usr/share/man/html3/extattr_string_to_namespace.html comp-c-htmlman html
./usr/share/man/html3/fabs.html comp-c-htmlman html
@@ -12444,6 +12454,7 @@
./usr/share/man/html3/fast_divide32_prepare.html comp-c-htmlman html
./usr/share/man/html3/fast_remainder32.html comp-c-htmlman html
./usr/share/man/html3/fclose.html comp-c-htmlman html
+./usr/share/man/html3/fcpxattr.html comp-c-htmlman html
./usr/share/man/html3/fdim.html comp-c-htmlman html
./usr/share/man/html3/fdimf.html comp-c-htmlman html
./usr/share/man/html3/fdiml.html comp-c-htmlman html
@@ -13590,6 +13601,7 @@
./usr/share/man/html3/lber-sockbuf.html comp-ldap-htmlman ldap,html
./usr/share/man/html3/lber-types.html comp-ldap-htmlman ldap,html
./usr/share/man/html3/lcong48.html comp-c-htmlman html
+./usr/share/man/html3/lcpxattr.html comp-c-htmlman html
./usr/share/man/html3/ld_errno.html comp-ldap-htmlman ldap,html
./usr/share/man/html3/ldap.html comp-ldap-htmlman ldap,html
./usr/share/man/html3/ldap_abandon.html comp-ldap-htmlman ldap,html
@@ -18096,6 +18108,7 @@
./usr/share/man/man3/cpuset_set.3 comp-c-man .man
./usr/share/man/man3/cpuset_size.3 comp-c-man .man
./usr/share/man/man3/cpuset_zero.3 comp-c-man .man
+./usr/share/man/man3/cpxattr.3 comp-c-man .man
./usr/share/man/man3/creal.3 comp-c-man complex,.man
./usr/share/man/man3/crealf.3 comp-c-man complex,.man
./usr/share/man/man3/creall.3 comp-c-man complex,.man
@@ -18453,6 +18466,9 @@
./usr/share/man/man3/expm1.3 comp-c-man .man
./usr/share/man/man3/expm1f.3 comp-c-man .man
./usr/share/man/man3/extattr.3 comp-c-man .man
+./usr/share/man/man3/extattr_copy_fd.3 comp-c-man .man
+./usr/share/man/man3/extattr_copy_file.3 comp-c-man .man
+./usr/share/man/man3/extattr_copy_link.3 comp-c-man .man
./usr/share/man/man3/extattr_namespace_to_string.3 comp-c-man .man
./usr/share/man/man3/extattr_string_to_namespace.3 comp-c-man .man
./usr/share/man/man3/fabs.3 comp-c-man .man
@@ -18461,6 +18477,7 @@
./usr/share/man/man3/fast_divide32_prepare.3 comp-c-man .man
./usr/share/man/man3/fast_remainder32.3 comp-c-man .man
./usr/share/man/man3/fclose.3 comp-c-man .man
+./usr/share/man/man3/fcpxattr.3 comp-c-man .man
./usr/share/man/man3/fdim.3 comp-c-man .man
./usr/share/man/man3/fdimf.3 comp-c-man .man
./usr/share/man/man3/fdiml.3 comp-c-man .man
@@ -19630,6 +19647,7 @@
./usr/share/man/man3/lber-sockbuf.3 comp-ldap-man ldap,.man
./usr/share/man/man3/lber-types.3 comp-ldap-man ldap,.man
./usr/share/man/man3/lcong48.3 comp-c-man .man
+./usr/share/man/man3/lcpxattr.3 comp-c-man .man
./usr/share/man/man3/ld_errno.3 comp-ldap-man ldap,.man
./usr/share/man/man3/ldap.3 comp-ldap-man ldap,.man
./usr/share/man/man3/ldap_abandon.3 comp-ldap-man ldap,.man
diff -r 7ec7bd1fb283 -r 0c4cea04a0a1 lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Wed Aug 03 02:57:23 2011 +0000
+++ b/lib/libc/gen/Makefile.inc Wed Aug 03 04:11:15 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.178 2011/03/26 19:51:42 christos Exp $
+# $NetBSD: Makefile.inc,v 1.179 2011/08/03 04:11:16 manu Exp $
# from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95
# gen sources
@@ -93,7 +93,13 @@
MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \
exec.3 execvp.3 exec.3 exect.3
MLINKS+=extattr.3 extattr_namespace_to_string.3 \
- extattr.3 extattr_string_to_namespace.3
+ extattr.3 extattr_string_to_namespace.3 \
+ extattr.3 extattr_copy_file.3 \
+ extattr.3 extattr_copy_fd.3 \
+ extattr.3 extattr_copy_link.3 \
+ extattr.3 cpxattr.3 \
+ extattr.3 fcpxattr.3 \
+ extattr.3 lcpxattr.3
MLINKS+=fpgetmask.3 fpgetround.3 fpgetmask.3 fpgetsticky.3 \
fpgetmask.3 fpsetmask.3 fpgetmask.3 fpsetround.3 \
fpgetmask.3 fpsetsticky.3 fpgetmask.3 fpgetprec.3 \
diff -r 7ec7bd1fb283 -r 0c4cea04a0a1 lib/libc/gen/extattr.3
--- a/lib/libc/gen/extattr.3 Wed Aug 03 02:57:23 2011 +0000
+++ b/lib/libc/gen/extattr.3 Wed Aug 03 04:11:15 2011 +0000
@@ -1,6 +1,7 @@
-.\" $NetBSD: extattr.3,v 1.3 2005/01/02 18:25:09 wiz Exp $
+.\" $NetBSD: extattr.3,v 1.4 2011/08/03 04:11:17 manu Exp $
.\"
.\" Copyright (c) 2001 Dima Dorfman <dd%FreeBSD.org@localhost>
+.\" Copyright (c) 2011 Emmanuel Dreyfus <manu%NetBSD.org@localhost>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -33,6 +34,13 @@
.Nm extattr_namespace_to_string ,
.Nm extattr_string_to_namespace
.Nd convert an extended attribute namespace identifier to a string and vice versa
+.Nm extattr_copy_file ,
+.Nm extattr_copy_fd ,
+.Nm extattr_copy_link ,
+.Nm cpxattr ,
+.Nm fcpxattr ,
+.Nm lcpxattr
+.Nd copy extended attributes from a file to another one
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -41,6 +49,18 @@
.Fn extattr_namespace_to_string "int attrnamespace" "char **string"
.Ft int
.Fn extattr_string_to_namespace "const char *string" "int *attrnamespace"
+.Ft int
+.Fn extattr_copy_file "const char *from" "const char *to" "int namespace"
+.Ft int
+.Fn extattr_copy_fd "int from_fd" "int to_fd" "int namespace"
+.Ft int
+.Fn extattr_copy_link "const char *from" "const char *to" "int namespace"
+.Ft int
+.Fn cpxattr "const char *from" "const char *to"
+.Ft int
+.Fn fcpxattr "int from_fd" "int to_fd"
+.Ft int
+.Fn lcpxattr "const char *from" "const char *to"
.Sh DESCRIPTION
The
.Fn extattr_namespace_to_string
@@ -74,6 +94,31 @@
an interactive program might ask for a name and use
.Fn extattr_string_to_namespace
to get the desired identifier.
+.Pp
+.Fn extattr_copy_file
+copies extended attributes of namespace
+.Ar namespace
+from a file to another one.
+.Fn extattr_copy_fd
+does the same using open file descriptors, and
+.Fn extattr_copy_link
+does the same as
+.Fn extattr_copy_file
+but operates on symbolic links themselves instead of their targets.
Home |
Main Index |
Thread Index |
Old Index