ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) { struct inode *inode = d_inode(dentry); struct f2fs_xattr_entry *entry; void *base_addr; int error = 0; size_t rest = buffer_size; down_read(&F2FS_I(inode)->i_xattr_sem); error = read_all_xattrs(inode, NULL, &base_addr); up_read(&F2FS_I(inode)->i_xattr_sem); if (error) return error; list_for_each_xattr(entry, base_addr) { const struct xattr_handler *handler = f2fs_xattr_handler(entry->e_name_index); const char *prefix; size_t prefix_len; size_t size; if (!handler || (handler->list && !handler->list(dentry))) continue; prefix = handler->prefix ?: handler->name; prefix_len = strlen(prefix); size = prefix_len + entry->e_name_len + 1; if (buffer) { if (size > rest) { error = -ERANGE; goto cleanup; } memcpy(buffer, prefix, prefix_len); buffer += prefix_len; memcpy(buffer, entry->e_name, entry->e_name_len); buffer += entry->e_name_len; *buffer++ = 0; } rest -= size; } error = buffer_size - rest; cleanup: kzfree(base_addr); return error; }
ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) { struct inode *inode = dentry->d_inode; struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_inode_info *fi = F2FS_I(inode); struct f2fs_xattr_entry *entry; struct page *page; void *base_addr; int error = 0; size_t rest = buffer_size; if (!fi->i_xattr_nid) return 0; page = get_node_page(sbi, fi->i_xattr_nid); base_addr = page_address(page); list_for_each_xattr(entry, base_addr) { const struct xattr_handler *handler = f2fs_xattr_handler(entry->e_name_index); size_t size; if (!handler) continue; size = handler->list(dentry, buffer, rest, entry->e_name, entry->e_name_len, handler->flags); if (buffer && size > rest) { error = -ERANGE; goto cleanup; } if (buffer) buffer += size; rest -= size; } error = buffer_size - rest; cleanup: f2fs_put_page(page, 1); return error; }
ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) { struct inode *inode = d_inode(dentry); struct f2fs_xattr_entry *entry; void *base_addr; int error = 0; size_t rest = buffer_size; base_addr = read_all_xattrs(inode, NULL); if (!base_addr) return -ENOMEM; list_for_each_xattr(entry, base_addr) { const struct xattr_handler *handler = f2fs_xattr_handler(entry->e_name_index); size_t size; if (!handler) continue; size = handler->list(dentry, buffer, rest, entry->e_name, entry->e_name_len, handler->flags); if (buffer && size > rest) { error = -ERANGE; goto cleanup; } if (buffer) buffer += size; rest -= size; } error = buffer_size - rest; cleanup: kzfree(base_addr); return error; }