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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <hurd/xattr.h>
25 /* Right now we support only a fixed set of xattr names for Hurd features.
26 There are no RPC interfaces for free-form xattr names and values.
30 gnu.author empty if st_author==st_uid
31 uid_t giving st_author value
32 gnu.translator empty if no passive translator
33 translator and arguments: "/hurd/foo\0arg1\0arg2\0"
37 _hurd_xattr_get (io_t port, const char *name, void *value, size_t *size)
39 if (strncmp (name, "gnu.", 4))
43 if (!strcmp (name, "author"))
46 error_t err = __io_stat (port, &st);
49 if (st.st_author == st.st_uid)
53 if (*size < sizeof st.st_author)
55 memcpy (value, &st.st_author, sizeof st.st_author);
57 *size = sizeof st.st_author;
61 if (!strcmp (name, "translator"))
64 size_t bufsz = value ? *size : 0;
65 error_t err = __file_get_translator (port, &buf, &bufsz);
68 if (value != NULL && *size < bufsz)
74 if (buf != value && bufsz > 0)
77 memcpy (value, buf, bufsz);
88 _hurd_xattr_set (io_t port, const char *name, const void *value, size_t size,
91 if (strncmp (name, "gnu.", 4))
95 if (!strcmp (name, "author"))
100 case 0: /* "Clear" author by setting to st_uid. */
103 error_t err = __io_stat (port, &st);
106 if (st.st_author == st.st_uid)
109 if (flags & XATTR_REPLACE)
113 if (flags & XATTR_CREATE)
115 return __file_chauthor (port, st.st_uid);
117 case sizeof (uid_t): /* Set the author. */
120 memcpy (&id, value, sizeof id);
121 if (flags & (XATTR_CREATE|XATTR_REPLACE))
124 error_t err = __io_stat (port, &st);
127 if (st.st_author == st.st_uid)
129 if (flags & XATTR_REPLACE)
132 else if (flags & XATTR_CREATE)
134 if (st.st_author == id)
138 return __file_chauthor (port, id);
142 if (!strcmp (name, "translator"))
144 if (flags & XATTR_REPLACE)
146 /* Must make sure it's already there. */
149 error_t err = __file_get_translator (port, &buf, &bufsz);
158 return __file_set_translator (port,
159 FS_TRANS_SET | ((flags & XATTR_CREATE)
160 ? FS_TRANS_EXCL : 0), 0, 0,
162 MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND);
169 _hurd_xattr_remove (io_t port, const char *name)
171 return _hurd_xattr_set (port, name, NULL, 0, XATTR_REPLACE);
175 _hurd_xattr_list (io_t port, void *buffer, size_t *size)
179 inline void add (const char *name, size_t len)
182 if (bufp != NULL && total <= *size)
183 bufp = __mempcpy (bufp, name, len);
185 #define add(s) add (s, sizeof s)
188 error_t err = __io_stat (port, &st);
192 if (st.st_author != st.st_uid)
194 if (st.st_mode & S_IPTRANS)
195 add ("gnu.translator");
197 if (buffer != NULL && total > *size)