gboolean get_compression_info_in_attr(const char *pathname, GError ** error, GHashTable ** table) { gchar *tmp; if (!table || !*table || !pathname) { SETERROR(error, "invalid parameter"); return FALSE; } tmp = _getxattr_from_chunk(pathname, -1, ATTR_DOMAIN "." ATTR_NAME_CHUNK_METADATA_COMPRESS); if (!tmp) { if (errno != ENOATTR) { GSETCODE(error, errno, "Failed to get compression attr : %s\n", strerror(errno)); return FALSE; } } else { if (*tmp) { GHashTable *ht = metadata_unpack_string(tmp, NULL); metadata_merge(*table, ht); } g_free(tmp); } return TRUE; }
static gboolean _load_from_xattr(struct attr_handle_s *attr_handle, GError ** error) { char *last_name, *buf; register ssize_t i; ssize_t s, size; EXTRA_ASSERT(attr_handle != NULL); EXTRA_ASSERT(attr_handle->attr_hash != NULL); s = longest_xattr_list; buf = g_malloc0(s); retry: size = listxattr(attr_handle->chunk_path, buf, s); if (0 > size) { if (errno != ERANGE) { SETERRCODE(error, errno, "Failed to list xattr from file [%s] : %s", attr_handle->chunk_path, strerror(errno)); g_free(buf); return FALSE; } else { s = s*2; longest_xattr_list = 1 + MAX(longest_xattr_list, s); buf = g_realloc(buf, s); memset(buf, 0, s); goto retry; } } if (!size) { g_free(buf); return TRUE; } for (last_name = buf, i = 0; i < size; i++) { if (buf[i] == '\0') { char *value = _getxattr_from_chunk(attr_handle->chunk_path, attr_handle->chunk_file_des, last_name); if (NULL != value) { g_hash_table_insert(attr_handle->attr_hash, g_strdup(last_name), value); } else if (errno == ENOATTR) { /* XATTR disappeared ! */ } else { SETERRCODE(error, errno, "Cannot get xattr %s from %s : %s", last_name, attr_handle->chunk_path, strerror(errno)); g_free(buf); return FALSE; } last_name = buf + i + 1; } } g_free(buf); return TRUE; }
gboolean get_chunk_compressed_size_in_attr(const char *pathname, GError ** error, guint32* compressed_size) { gchar* tmp = NULL; if (!(tmp = _getxattr_from_chunk(pathname, -1, ATTR_DOMAIN "." ATTR_NAME_CHUNK_COMPRESSED_SIZE))) { GSETCODE(error, errno, "compressedsize not found : %s", strerror(errno)); return FALSE; } *compressed_size = g_ascii_strtoll(tmp, NULL, 10); g_free(tmp); return TRUE; }
static gboolean _load_from_xattr(struct attr_handle_s *attr_handle, GError ** error){ char *last_name, *buf; register ssize_t i; ssize_t bufSize, bufMax; GError *local_error = NULL; if (attr_handle->attr_hash == NULL) { SETERRCODE(error, EINVAL, "Invalid parameter : attr_hash is null"); return FALSE; } bufMax = listxattr(attr_handle->chunk_path, NULL, 0); if (0 > bufMax) { SETERRCODE(error, errno, "Failed to list XAttr : %s", strerror(errno)); return FALSE; } if (0 == bufMax) { /* According to the man page, listxattr should return -1 if xattr * is not supported by the underlying fs. It looks that in reality, * it just returns a size of 0, so we'll consider this as an error. */ SETERRCODE(error, ENOTSUP, "Failed to list xattr from chunk [%s] : size of list of attr names is 0", attr_handle->chunk_path); return FALSE; } buf = g_malloc0(bufMax); bufSize = listxattr(attr_handle->chunk_path, buf, bufMax); for (last_name = buf, i = 0; i < bufSize; i++) { if (buf[i] == '\0') { char *value = NULL; if (_getxattr_from_chunk(attr_handle, &local_error, last_name, &value)) g_hash_table_insert(attr_handle->attr_hash, g_strdup(last_name), value); else { SETERRCODE(error, local_error->code, "Cannot get xattr %s from %s : %s", last_name, attr_handle->chunk_path, local_error->message); g_clear_error(&local_error); g_free(buf); return FALSE; } last_name = buf + i + 1; } } g_free(buf); return TRUE; }