|
a/src/utils/pxattr.cpp |
|
b/src/utils/pxattr.cpp |
|
... |
|
... |
25 |
|
25 |
|
26 |
/** \file pxattr.cpp
|
26 |
/** \file pxattr.cpp
|
27 |
\brief Portable External Attributes API
|
27 |
\brief Portable External Attributes API
|
28 |
*/
|
28 |
*/
|
29 |
|
29 |
|
|
|
30 |
// PXALINUX: platforms like kfreebsd which aren't linux but use the
|
|
|
31 |
// same xattr interface
|
30 |
#if defined(__gnu_linux__) || \
|
32 |
#if defined(__gnu_linux__) || \
|
31 |
(defined(__FreeBSD_kernel__)&&defined(__GLIBC__)&&!defined(__FreeBSD__)) ||\
|
33 |
(defined(__FreeBSD_kernel__)&&defined(__GLIBC__)&&!defined(__FreeBSD__)) ||\
|
32 |
defined(__CYGWIN__)
|
34 |
defined(__CYGWIN__)
|
33 |
#define PXALINUX
|
35 |
#define PXALINUX
|
34 |
#endif
|
36 |
#endif
|
35 |
|
37 |
|
36 |
// If the platform is not supported, let this file be empty instead of
|
38 |
// If the platform is not known yet, let this file be empty instead of
|
37 |
// breaking the compile, this will let the build work if the rest of
|
39 |
// breaking the compile, this will let the build work if the rest of
|
38 |
// the software is not actually calling us.
|
40 |
// the software is not actually calling us. If it does call us, this
|
|
|
41 |
// will bring attention to the necessity of a port.
|
|
|
42 |
//
|
|
|
43 |
// If the platform is known not supporting extattrs (e.g.__OpenBSD__),
|
|
|
44 |
// just let the methods return errors (like they would on a non-xattr
|
|
|
45 |
// fs on e.g. linux)
|
39 |
#if defined(__FreeBSD__) || defined(PXALINUX) || defined(__APPLE__)
|
46 |
#if defined(__FreeBSD__) || defined(PXALINUX) || defined(__APPLE__) \
|
|
|
47 |
|| defined(__OpenBSD__)
|
40 |
|
48 |
|
41 |
|
49 |
|
42 |
#ifndef TEST_PXATTR
|
50 |
#ifndef TEST_PXATTR
|
43 |
#include <sys/types.h>
|
51 |
#include <sys/types.h>
|
44 |
#include <errno.h>
|
52 |
#include <errno.h>
|
|
... |
|
... |
50 |
#include <sys/uio.h>
|
58 |
#include <sys/uio.h>
|
51 |
#elif defined(PXALINUX)
|
59 |
#elif defined(PXALINUX)
|
52 |
#include <sys/xattr.h>
|
60 |
#include <sys/xattr.h>
|
53 |
#elif defined(__APPLE__)
|
61 |
#elif defined(__APPLE__)
|
54 |
#include <sys/xattr.h>
|
62 |
#include <sys/xattr.h>
|
|
|
63 |
#elif defined(__OpenBSD__)
|
55 |
#else
|
64 |
#else
|
56 |
#error "Unknown system can't compile"
|
65 |
#error "Unknown system can't compile"
|
57 |
#endif
|
66 |
#endif
|
58 |
|
67 |
|
59 |
#include "pxattr.h"
|
68 |
#include "pxattr.h"
|
|
... |
|
... |
160 |
ret = getxattr(path.c_str(), name.c_str(), buf.buf, ret, 0, 0);
|
169 |
ret = getxattr(path.c_str(), name.c_str(), buf.buf, ret, 0, 0);
|
161 |
}
|
170 |
}
|
162 |
} else {
|
171 |
} else {
|
163 |
ret = fgetxattr(fd, name.c_str(), buf.buf, ret, 0, 0);
|
172 |
ret = fgetxattr(fd, name.c_str(), buf.buf, ret, 0, 0);
|
164 |
}
|
173 |
}
|
|
|
174 |
#else
|
|
|
175 |
errno = ENOTSUP;
|
165 |
#endif
|
176 |
#endif
|
166 |
|
177 |
|
167 |
if (ret >= 0)
|
178 |
if (ret >= 0)
|
168 |
value->assign(buf.buf, ret);
|
179 |
value->assign(buf.buf, ret);
|
169 |
return ret >= 0;
|
180 |
return ret >= 0;
|
|
... |
|
... |
255 |
}
|
266 |
}
|
256 |
} else {
|
267 |
} else {
|
257 |
ret = fsetxattr(fd, name.c_str(), value.c_str(),
|
268 |
ret = fsetxattr(fd, name.c_str(), value.c_str(),
|
258 |
value.length(), 0, opts);
|
269 |
value.length(), 0, opts);
|
259 |
}
|
270 |
}
|
|
|
271 |
#else
|
|
|
272 |
errno = ENOTSUP;
|
260 |
#endif
|
273 |
#endif
|
261 |
return ret >= 0;
|
274 |
return ret >= 0;
|
262 |
}
|
275 |
}
|
263 |
|
276 |
|
264 |
static bool
|
277 |
static bool
|
|
... |
|
... |
300 |
ret = removexattr(path.c_str(), name.c_str(), 0);
|
313 |
ret = removexattr(path.c_str(), name.c_str(), 0);
|
301 |
}
|
314 |
}
|
302 |
} else {
|
315 |
} else {
|
303 |
ret = fremovexattr(fd, name.c_str(), 0);
|
316 |
ret = fremovexattr(fd, name.c_str(), 0);
|
304 |
}
|
317 |
}
|
|
|
318 |
#else
|
|
|
319 |
errno = ENOTSUP;
|
305 |
#endif
|
320 |
#endif
|
306 |
return ret >= 0;
|
321 |
return ret >= 0;
|
307 |
}
|
322 |
}
|
308 |
|
323 |
|
309 |
static bool
|
324 |
static bool
|
|
... |
|
... |
382 |
ret = listxattr(path.c_str(), buf.buf, ret, 0);
|
397 |
ret = listxattr(path.c_str(), buf.buf, ret, 0);
|
383 |
}
|
398 |
}
|
384 |
} else {
|
399 |
} else {
|
385 |
ret = flistxattr(fd, buf.buf, ret, 0);
|
400 |
ret = flistxattr(fd, buf.buf, ret, 0);
|
386 |
}
|
401 |
}
|
|
|
402 |
#else
|
|
|
403 |
errno = ENOTSUP;
|
387 |
#endif
|
404 |
#endif
|
|
|
405 |
|
|
|
406 |
if (ret < 0)
|
|
|
407 |
return false;
|
388 |
|
408 |
|
389 |
char *bufstart = buf.buf;
|
409 |
char *bufstart = buf.buf;
|
390 |
|
410 |
|
391 |
// All systems return a 0-separated string list except FreeBSD
|
411 |
// All systems return a 0-separated string list except FreeBSD
|
392 |
// which has length, value pairs, length is a byte.
|
412 |
// which has length, value pairs, length is a byte.
|