2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef FS_ATTR_EXTATTR_H
6 #define FS_ATTR_EXTATTR_H
8 /*! Included by fs_attr_untyped.cpp. Interfaces with FreeBSD extattr support.
13 #include <sys/extattr.h>
16 // the namespace all attributes live in
17 static const char* kAttributeNamespace
= "haiku.";
18 static const int kAttributeNamespaceLen
= 6;
22 list_attributes(int fd
, const char* path
, char* buffer
, size_t bufferSize
)
26 bytesRead
= extattr_list_fd(fd
, EXTATTR_NAMESPACE_USER
, buffer
,
29 bytesRead
= extattr_list_link(path
, EXTATTR_NAMESPACE_USER
, buffer
,
36 // The listing is in a different format than expected by the caller. Here
37 // we get a sequence of (<namelen>, <unterminated name>) pairs, but expected
38 // is a sequence of null-terminated names. Let's convert it.
40 memmove(buffer
, buffer
+ 1, bytesRead
- 1);
42 while (index
< bytesRead
- 1) {
43 int len
= buffer
[index
];
48 buffer
[bytesRead
- 1] = '\0';
55 get_attribute(int fd
, const char* path
, const char* attribute
, void* buffer
,
59 return extattr_get_fd(fd
, EXTATTR_NAMESPACE_USER
, attribute
, buffer
,
62 return extattr_get_link(path
, EXTATTR_NAMESPACE_USER
, attribute
, buffer
,
68 set_attribute(int fd
, const char* path
, const char* attribute
,
69 const void* buffer
, size_t bufferSize
)
72 return extattr_set_fd(fd
, EXTATTR_NAMESPACE_USER
, attribute
, buffer
,
75 return extattr_set_link(path
, EXTATTR_NAMESPACE_USER
, attribute
, buffer
,
81 remove_attribute(int fd
, const char* path
, const char* attribute
)
84 return extattr_delete_fd(fd
, EXTATTR_NAMESPACE_USER
, attribute
);
85 return extattr_delete_link(path
, EXTATTR_NAMESPACE_USER
, attribute
);
89 #endif // FS_ATTR_EXTATTR_H