#include "binary_storage.h"
#include "utils.h"
-#include "const.h"
+#include "fuse_xattrs_config.h"
-#include <attr/xattr.h>
+#include <sys/xattr.h>
+
+#ifndef ENOATTR
+ #define ENOATTR ENODATA
+#endif
struct on_memory_attr {
u_int16_t name_size;
void __free_on_memory_attr(struct on_memory_attr *attr)
{
- free(attr->name);
- free(attr->value);
+ if(attr->name != NULL)
+ free(attr->name);
+
+ if(attr->value != NULL)
+ free(attr->value);
+
free(attr);
}
{
debug_print("offset=%zu\n", *offset);
struct on_memory_attr *attr = malloc(sizeof(struct on_memory_attr));
+ attr->name = NULL;
+ attr->value = NULL;
////////////////////////////////
// Read name size
#ifdef DEBUG
char *sanitized_value = sanitize_value(value, value_size);
- debug_print("name=%s sanitized_value=%s value_size=%zu\n", name, sanitized_value, value_size);
+ debug_print("name='%s' name_size=%hu sanitized_value='%s' value_size=%zu\n", name, name_size, sanitized_value, value_size);
free(sanitized_value);
#endif
if (fwrite(&value_size, sizeof(size_t), 1, file) != 1) {
return -1;
}
- if (fwrite(value, value_size, 1, file) != 1) {
- return -1;
+ // write value content only if we have something to write.
+ if (value_size > 0) {
+ if (fwrite(value, value_size, 1, file) != 1) {
+ return -1;
+ }
}
return 0;
* @param value - attribute value. size < XATTR_SIZE_MAX
* @param size
* @param flags - XATTR_CREATE and/or XATTR_REPLACE
- * @return On success, zero is returned. On failure, -errno is returnted.
+ * @return On success, zero is returned. On failure, -errno is returned.
*/
int binary_storage_write_key(const char *path, const char *name, const char *value, size_t size, int flags)
{
if (buffer == NULL && buffer_size == -ENOENT && flags & XATTR_REPLACE) {
error_print("No xattr. (flag XATTR_REPLACE)");
- return -ENODATA;
+ return -ENOATTR;
}
if (buffer == NULL && buffer_size != -ENOENT) {
if (size == 0 && res > XATTR_LIST_MAX) {
// FIXME: we should return the size or an error ?
- return -E2BIG;
+ return -ENOSPC;
}
return (int)res;
fclose(file);
free(buffer);
return res;
-}
\ No newline at end of file
+}