2 * Extended attribute support for rsync.
4 * Copyright (C) 2004 Red Hat, Inc.
5 * Copyright (C) 2003-2008 Wayne Davison
6 * Written by Jay Fenlason.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, visit the http://fsf.org website.
23 #include "sysxattrs.h"
27 #if defined HAVE_LINUX_XATTRS
29 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
31 return lgetxattr(path, name, value, size);
34 ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
36 return fgetxattr(filedes, name, value, size);
39 int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size)
41 return lsetxattr(path, name, value, size, 0);
44 int sys_lremovexattr(const char *path, const char *name)
46 return lremovexattr(path, name);
49 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
51 return llistxattr(path, list, size);
56 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
58 return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
61 ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
63 return fgetxattr(filedes, name, value, size, 0, 0);
66 int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size)
68 return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
71 int sys_lremovexattr(const char *path, const char *name)
73 return removexattr(path, name, XATTR_NOFOLLOW);
76 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
78 return listxattr(path, list, size, XATTR_NOFOLLOW);
81 #elif HAVE_FREEBSD_XATTRS
83 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
85 return extattr_get_link(path, EXTATTR_NAMESPACE_USER, name, value, size);
88 ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
90 return extattr_get_fd(filedes, EXTATTR_NAMESPACE_USER, name, value, size);
93 int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size)
95 return extattr_set_link(path, EXTATTR_NAMESPACE_USER, name, value, size);
98 int sys_lremovexattr(const char *path, const char *name)
100 return extattr_delete_link(path, EXTATTR_NAMESPACE_USER, name);
103 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
105 unsigned char keylen;
106 ssize_t off, len = extattr_list_link(path, EXTATTR_NAMESPACE_USER, list, size);
108 if (len <= 0 || (size_t)len > size)
111 /* FreeBSD puts a single-byte length before each string, with no '\0'
112 * terminator. We need to change this into a series of null-terminted
113 * strings. Since the size is the same, we can simply transform the
114 * output in place. */
115 for (off = 0; off < len; off += keylen + 1) {
116 keylen = ((unsigned char*)list)[off];
117 if (off + keylen >= len) {
118 /* Should be impossible, but kernel bugs happen! */
122 memmove(list+off, list+off+1, keylen);
123 list[off+keylen] = '\0';
131 #error You need to create xattr compatibility functions.
135 #endif /* SUPPORT_XATTRS */