xref: /haiku/src/build/libroot/fs_attr_bsdxattr.h (revision b1c06fc64af1d3e520b339ab817cf3e820446dc2)
1*b1c06fc6SIngo Weinhold /*
2*b1c06fc6SIngo Weinhold  * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3*b1c06fc6SIngo Weinhold  * Distributed under the terms of the MIT License.
4*b1c06fc6SIngo Weinhold  */
5*b1c06fc6SIngo Weinhold #ifndef FS_ATTR_BSDXATTR_H
6*b1c06fc6SIngo Weinhold #define FS_ATTR_BSDXATTR_H
7*b1c06fc6SIngo Weinhold 
8*b1c06fc6SIngo Weinhold /*!	Included by fs_attr_untyped.cpp. Interfaces with BSD xattr support.
9*b1c06fc6SIngo Weinhold */
10*b1c06fc6SIngo Weinhold 
11*b1c06fc6SIngo Weinhold 
12*b1c06fc6SIngo Weinhold #include <sys/xattr.h>
13*b1c06fc6SIngo Weinhold 
14*b1c06fc6SIngo Weinhold 
15*b1c06fc6SIngo Weinhold // the namespace all attributes live in
16*b1c06fc6SIngo Weinhold static const char* kAttributeNamespace = "user.haiku.";
17*b1c06fc6SIngo Weinhold static const int kAttributeNamespaceLen = 11;
18*b1c06fc6SIngo Weinhold 
19*b1c06fc6SIngo Weinhold 
20*b1c06fc6SIngo Weinhold static ssize_t
list_attributes(int fd,const char * path,char * buffer,size_t bufferSize)21*b1c06fc6SIngo Weinhold list_attributes(int fd, const char* path, char* buffer, size_t bufferSize)
22*b1c06fc6SIngo Weinhold {
23*b1c06fc6SIngo Weinhold 	if (fd >= 0)
24*b1c06fc6SIngo Weinhold 		return flistxattr(fd, buffer, bufferSize, 0);
25*b1c06fc6SIngo Weinhold 	return listxattr(path, buffer, bufferSize, XATTR_NOFOLLOW);
26*b1c06fc6SIngo Weinhold }
27*b1c06fc6SIngo Weinhold 
28*b1c06fc6SIngo Weinhold 
29*b1c06fc6SIngo Weinhold static ssize_t
get_attribute(int fd,const char * path,const char * attribute,void * buffer,size_t bufferSize)30*b1c06fc6SIngo Weinhold get_attribute(int fd, const char* path, const char* attribute, void* buffer,
31*b1c06fc6SIngo Weinhold 	size_t bufferSize)
32*b1c06fc6SIngo Weinhold {
33*b1c06fc6SIngo Weinhold 	if (fd >= 0)
34*b1c06fc6SIngo Weinhold 		return fgetxattr(fd, attribute, buffer, bufferSize, 0, 0);
35*b1c06fc6SIngo Weinhold 	return getxattr(path, attribute, buffer, bufferSize, 0, XATTR_NOFOLLOW);
36*b1c06fc6SIngo Weinhold }
37*b1c06fc6SIngo Weinhold 
38*b1c06fc6SIngo Weinhold 
39*b1c06fc6SIngo Weinhold static int
set_attribute(int fd,const char * path,const char * attribute,const void * buffer,size_t bufferSize)40*b1c06fc6SIngo Weinhold set_attribute(int fd, const char* path, const char* attribute,
41*b1c06fc6SIngo Weinhold 	const void* buffer, size_t bufferSize)
42*b1c06fc6SIngo Weinhold {
43*b1c06fc6SIngo Weinhold 	if (fd >= 0)
44*b1c06fc6SIngo Weinhold 		return fsetxattr(fd, attribute, buffer, bufferSize, 0, 0);
45*b1c06fc6SIngo Weinhold 	return setxattr(path, attribute, buffer, bufferSize, 0, XATTR_NOFOLLOW);
46*b1c06fc6SIngo Weinhold }
47*b1c06fc6SIngo Weinhold 
48*b1c06fc6SIngo Weinhold 
49*b1c06fc6SIngo Weinhold static int
remove_attribute(int fd,const char * path,const char * attribute)50*b1c06fc6SIngo Weinhold remove_attribute(int fd, const char* path, const char* attribute)
51*b1c06fc6SIngo Weinhold {
52*b1c06fc6SIngo Weinhold 	if (fd >= 0)
53*b1c06fc6SIngo Weinhold 		return fremovexattr(fd, attribute, 0);
54*b1c06fc6SIngo Weinhold 	return removexattr(path, attribute, XATTR_NOFOLLOW);
55*b1c06fc6SIngo Weinhold }
56*b1c06fc6SIngo Weinhold 
57*b1c06fc6SIngo Weinhold 
58*b1c06fc6SIngo Weinhold #endif	// FS_ATTR_BSDXATTR_H
59