1 /* Support for *xattr interfaces on GNU/Hurd.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <hurd/xattr.h>
24 /* Right now we support only a fixed set of xattr names for Hurd features.
25 There are no RPC interfaces for free-form xattr names and values.
29 gnu.author empty if st_author==st_uid
30 uid_t giving st_author value
31 gnu.translator empty if no passive translator
32 translator and arguments: "/hurd/foo\0arg1\0arg2\0"
36 _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
38 if (strncmp (name, "gnu.", 4))
42 if (!strcmp (name, "author"))
45 error_t err = __io_stat (port, &st);
48 if (st.st_author == st.st_uid)
52 if (*size < sizeof st.st_author)
54 memcpy (value, &st.st_author, sizeof st.st_author);
56 *size = sizeof st.st_author;
60 if (!strcmp (name, "translator"))
63 size_t bufsz = value ? *size : 0;
64 error_t err = __file_get_translator (port, &buf, &bufsz);
67 if (value != NULL && *size < bufsz)
73 if (buf != value && bufsz > 0)
76 memcpy (value, buf, bufsz);
87 _hurd_xattr_set (io_t port, const char *name, const void *value, size_t size,
90 if (strncmp (name, "gnu.", 4))
94 if (!strcmp (name, "author"))
99 case 0: /* "Clear" author by setting to st_uid. */
102 error_t err = __io_stat (port, &st);
105 if (st.st_author == st.st_uid)
108 if (flags & XATTR_REPLACE)
112 if (flags & XATTR_CREATE)
114 return __file_chauthor (port, st.st_uid);
116 case sizeof (uid_t): /* Set the author. */
119 memcpy (&id, value, sizeof id);
120 if (flags & (XATTR_CREATE|XATTR_REPLACE))
123 error_t err = __io_stat (port, &st);
126 if (st.st_author == st.st_uid)
128 if (flags & XATTR_REPLACE)
131 else if (flags & XATTR_CREATE)
133 if (st.st_author == id)
137 return __file_chauthor (port, id);
141 if (!strcmp (name, "translator"))
143 if (flags & XATTR_REPLACE)
145 /* Must make sure it's already there. */
148 error_t err = __file_get_translator (port, &buf, &bufsz);
157 return __file_set_translator (port,
158 FS_TRANS_SET | ((flags & XATTR_CREATE)
159 ? FS_TRANS_EXCL : 0), 0, 0,
161 MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND);
168 _hurd_xattr_remove (io_t port, const char *name)
170 return _hurd_xattr_set (port, name, NULL, 0, XATTR_REPLACE);
174 _hurd_xattr_list (io_t port, void *buffer, size_t *size)
178 inline void add (const char *name, size_t len)
181 if (bufp != NULL && total <= *size)
182 bufp = __mempcpy (bufp, name, len);
184 #define add(s) add (s, sizeof s)
187 error_t err = __io_stat (port, &st);
191 if (st.st_author != st.st_uid)
193 if (st.st_mode & S_IPTRANS)
194 add ("gnu.translator");
196 if (buffer != NULL && total > *size)