2 * Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com)
3 * Copyright (c) 2015 Kaho Ng (ngkaho1234@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup lwext4
34 * @brief Extended Attribute manipulation.
37 #include "ext4_config.h"
38 #include "ext4_types.h"
40 #include "ext4_errno.h"
41 #include "ext4_blockdev.h"
42 #include "ext4_super.h"
43 #include "ext4_debug.h"
44 #include "ext4_block_group.h"
45 #include "ext4_balloc.h"
46 #include "ext4_inode.h"
47 #include "ext4_extent.h"
54 * @brief Extended Attribute Manipulation
57 #define NAME_HASH_SHIFT 5
58 #define VALUE_HASH_SHIFT 16
60 static inline void ext4_xattr_compute_hash(struct ext4_xattr_header *header,
61 struct ext4_xattr_entry *entry)
64 char *name = EXT4_XATTR_NAME(entry);
67 for (n = 0; n < entry->e_name_len; n++) {
68 hash = (hash << NAME_HASH_SHIFT) ^
69 (hash >> (8 * sizeof(hash) - NAME_HASH_SHIFT)) ^ *name++;
72 if (entry->e_value_block == 0 && entry->e_value_size != 0) {
74 (uint32_t *)((char *)header + to_le16(entry->e_value_offs));
75 for (n = (to_le32(entry->e_value_size) + EXT4_XATTR_ROUND) >>
78 hash = (hash << VALUE_HASH_SHIFT) ^
79 (hash >> (8 * sizeof(hash) - VALUE_HASH_SHIFT)) ^
83 entry->e_hash = to_le32(hash);
86 #define BLOCK_HASH_SHIFT 16
91 * Re-compute the extended attribute hash value after an entry has changed.
93 static void ext4_xattr_rehash(struct ext4_xattr_header *header,
94 struct ext4_xattr_entry *entry)
96 struct ext4_xattr_entry *here;
99 ext4_xattr_compute_hash(header, entry);
100 here = EXT4_XATTR_ENTRY(header + 1);
101 while (!EXT4_XATTR_IS_LAST_ENTRY(here)) {
103 /* Block is not shared if an entry's hash value == 0 */
107 hash = (hash << BLOCK_HASH_SHIFT) ^
108 (hash >> (8 * sizeof(hash) - BLOCK_HASH_SHIFT)) ^
109 to_le32(here->e_hash);
110 here = EXT4_XATTR_NEXT(here);
112 header->h_hash = to_le32(hash);
115 static int ext4_xattr_item_cmp(struct ext4_xattr_item *a,
116 struct ext4_xattr_item *b)
119 result = a->name_index - b->name_index;
123 result = a->name_len - b->name_len;
127 return memcmp(a->name, b->name, a->name_len);
130 RB_GENERATE_INTERNAL(ext4_xattr_tree, ext4_xattr_item, node,
131 ext4_xattr_item_cmp, static inline)
133 static struct ext4_xattr_item *
134 ext4_xattr_item_alloc(uint8_t name_index, const char *name, size_t name_len)
136 struct ext4_xattr_item *item;
137 item = malloc(sizeof(struct ext4_xattr_item) + name_len);
141 item->name_index = name_index;
142 item->name = (char *)(item + 1);
143 item->name_len = name_len;
147 memset(&item->node, 0, sizeof(item->node));
148 memcpy(item->name, name, name_len);
153 static int ext4_xattr_item_alloc_data(struct ext4_xattr_item *item,
154 const void *orig_data, size_t data_size)
157 ext4_assert(!item->data);
158 data = malloc(data_size);
163 memcpy(data, orig_data, data_size);
166 item->data_size = data_size;
170 static void ext4_xattr_item_free_data(struct ext4_xattr_item *item)
172 ext4_assert(item->data);
178 static int ext4_xattr_item_resize_data(struct ext4_xattr_item *item,
179 size_t new_data_size)
181 if (new_data_size != item->data_size) {
183 new_data = realloc(item->data, new_data_size);
187 item->data = new_data;
188 item->data_size = new_data_size;
193 static void ext4_xattr_item_free(struct ext4_xattr_item *item)
196 ext4_xattr_item_free_data(item);
201 static void *ext4_xattr_entry_data(struct ext4_xattr_ref *xattr_ref,
202 struct ext4_xattr_entry *entry,
207 struct ext4_xattr_ibody_header *header;
208 struct ext4_xattr_entry *first_entry;
210 ext4_get16(&xattr_ref->fs->sb, inode_size);
211 header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
212 first_entry = EXT4_XATTR_IFIRST(header);
214 ret = ((char *)first_entry + to_le16(entry->e_value_offs));
215 if (ret + EXT4_XATTR_SIZE(to_le32(entry->e_value_size)) -
216 (char *)xattr_ref->inode_ref->inode > inode_size)
222 int32_t block_size = ext4_sb_get_block_size(&xattr_ref->fs->sb);
223 ret = ((char *)xattr_ref->block.data + to_le16(entry->e_value_offs));
224 if (ret + EXT4_XATTR_SIZE(to_le32(entry->e_value_size)) -
225 (char *)xattr_ref->block.data > block_size)
230 static int ext4_xattr_block_fetch(struct ext4_xattr_ref *xattr_ref)
235 struct ext4_xattr_entry *entry = NULL;
237 ext4_assert(xattr_ref->block.data);
238 entry = EXT4_XATTR_BFIRST(&xattr_ref->block);
240 size_rem = ext4_sb_get_block_size(&xattr_ref->fs->sb);
241 for (; size_rem > 0 && !EXT4_XATTR_IS_LAST_ENTRY(entry);
242 entry = EXT4_XATTR_NEXT(entry),
243 size_rem -= EXT4_XATTR_LEN(entry->e_name_len)) {
244 struct ext4_xattr_item *item;
245 char *e_name = EXT4_XATTR_NAME(entry);
247 data = ext4_xattr_entry_data(xattr_ref, entry, false);
253 item = ext4_xattr_item_alloc(entry->e_name_index, e_name,
254 (size_t)entry->e_name_len);
259 if (ext4_xattr_item_alloc_data(
260 item, data, to_le32(entry->e_value_size)) != EOK) {
261 ext4_xattr_item_free(item);
265 RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
266 xattr_ref->ea_size += EXT4_XATTR_SIZE(item->data_size) +
267 EXT4_XATTR_LEN(item->name_len);
274 static int ext4_xattr_inode_fetch(struct ext4_xattr_ref *xattr_ref)
279 struct ext4_xattr_ibody_header *header = NULL;
280 struct ext4_xattr_entry *entry = NULL;
281 uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb, inode_size);
283 header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
284 entry = EXT4_XATTR_IFIRST(header);
286 size_rem = inode_size - EXT4_GOOD_OLD_INODE_SIZE -
287 xattr_ref->inode_ref->inode->extra_isize;
288 for (; size_rem > 0 && !EXT4_XATTR_IS_LAST_ENTRY(entry);
289 entry = EXT4_XATTR_NEXT(entry),
290 size_rem -= EXT4_XATTR_LEN(entry->e_name_len)) {
291 struct ext4_xattr_item *item;
292 char *e_name = EXT4_XATTR_NAME(entry);
294 data = ext4_xattr_entry_data(xattr_ref, entry, true);
300 item = ext4_xattr_item_alloc(entry->e_name_index, e_name,
301 (size_t)entry->e_name_len);
306 if (ext4_xattr_item_alloc_data(
307 item, data, to_le32(entry->e_value_size)) != EOK) {
308 ext4_xattr_item_free(item);
312 RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
313 xattr_ref->ea_size += EXT4_XATTR_SIZE(item->data_size) +
314 EXT4_XATTR_LEN(item->name_len);
321 static size_t ext4_xattr_inode_space(struct ext4_xattr_ref *xattr_ref)
323 uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb, inode_size);
324 uint16_t size_rem = inode_size - EXT4_GOOD_OLD_INODE_SIZE -
325 xattr_ref->inode_ref->inode->extra_isize;
329 static size_t ext4_xattr_block_space(struct ext4_xattr_ref *xattr_ref)
331 return ext4_sb_get_block_size(&xattr_ref->fs->sb);
334 static int ext4_xattr_fetch(struct ext4_xattr_ref *xattr_ref)
337 uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb, inode_size);
338 if (inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
339 ret = ext4_xattr_inode_fetch(xattr_ref);
344 if (xattr_ref->block_loaded)
345 ret = ext4_xattr_block_fetch(xattr_ref);
347 xattr_ref->dirty = false;
351 static struct ext4_xattr_item *
352 ext4_xattr_lookup_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
353 const char *name, size_t name_len)
355 struct ext4_xattr_item tmp = {
356 .name_index = name_index,
357 .name = (char *)name, /*RB_FIND - won't touch this string*/
358 .name_len = name_len,
361 return RB_FIND(ext4_xattr_tree, &xattr_ref->root, &tmp);
364 static struct ext4_xattr_item *
365 ext4_xattr_insert_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
366 const char *name, size_t name_len, const void *data,
369 struct ext4_xattr_item *item;
370 item = ext4_xattr_item_alloc(name_index, name, name_len);
374 if ((xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
375 EXT4_XATTR_LEN(item->name_len)
377 ext4_xattr_inode_space(xattr_ref) -
378 sizeof(struct ext4_xattr_ibody_header))
380 (xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
381 EXT4_XATTR_LEN(item->name_len) >
382 ext4_xattr_block_space(xattr_ref) -
383 sizeof(struct ext4_xattr_header))) {
384 ext4_xattr_item_free(item);
388 if (ext4_xattr_item_alloc_data(item, data, data_size) != EOK) {
389 ext4_xattr_item_free(item);
392 RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
393 xattr_ref->ea_size +=
394 EXT4_XATTR_SIZE(item->data_size) + EXT4_XATTR_LEN(item->name_len);
395 xattr_ref->dirty = true;
399 static int ext4_xattr_remove_item(struct ext4_xattr_ref *xattr_ref,
400 uint8_t name_index, const char *name,
404 struct ext4_xattr_item *item =
405 ext4_xattr_lookup_item(xattr_ref, name_index, name, name_len);
407 if (item == xattr_ref->iter_from)
408 xattr_ref->iter_from =
409 RB_NEXT(ext4_xattr_tree, &xattr_ref->root, item);
411 RB_REMOVE(ext4_xattr_tree, &xattr_ref->root, item);
412 ext4_xattr_item_free(item);
413 xattr_ref->ea_size -= EXT4_XATTR_SIZE(item->data_size) +
414 EXT4_XATTR_LEN(item->name_len);
415 xattr_ref->dirty = true;
421 static int ext4_xattr_resize_item(struct ext4_xattr_ref *xattr_ref,
422 struct ext4_xattr_item *item,
423 size_t new_data_size)
426 if (xattr_ref->ea_size - EXT4_XATTR_SIZE(item->data_size) +
427 EXT4_XATTR_SIZE(new_data_size) >
428 ext4_xattr_inode_space(xattr_ref) +
429 ext4_xattr_block_space(xattr_ref)) {
433 ret = ext4_xattr_item_resize_data(item, new_data_size);
437 xattr_ref->ea_size -=
438 EXT4_XATTR_SIZE(item->data_size) + EXT4_XATTR_SIZE(new_data_size);
439 xattr_ref->dirty = true;
443 static void ext4_xattr_purge_items(struct ext4_xattr_ref *xattr_ref)
445 struct ext4_xattr_item *item, *save_item;
446 RB_FOREACH_SAFE(item, ext4_xattr_tree, &xattr_ref->root, save_item)
448 RB_REMOVE(ext4_xattr_tree, &xattr_ref->root, item);
449 ext4_xattr_item_free(item);
451 xattr_ref->ea_size = 0;
454 static int ext4_xattr_try_alloc_block(struct ext4_xattr_ref *xattr_ref)
458 uint64_t xattr_block = 0;
459 xattr_block = ext4_inode_get_file_acl(xattr_ref->inode_ref->inode,
462 ret = ext4_balloc_alloc_block(xattr_ref->inode_ref,
463 (uint32_t *)&xattr_block);
467 ret = ext4_block_get(xattr_ref->fs->bdev, &xattr_ref->block,
470 ext4_balloc_free_block(xattr_ref->inode_ref,
475 ext4_inode_set_file_acl(xattr_ref->inode_ref->inode,
476 &xattr_ref->fs->sb, xattr_block);
477 xattr_ref->inode_ref->dirty = true;
478 xattr_ref->block_loaded = true;
485 static void ext4_xattr_try_free_block(struct ext4_xattr_ref *xattr_ref)
487 uint64_t xattr_block;
488 xattr_block = ext4_inode_get_file_acl(xattr_ref->inode_ref->inode,
490 ext4_inode_set_file_acl(xattr_ref->inode_ref->inode, &xattr_ref->fs->sb,
492 ext4_block_set(xattr_ref->fs->bdev, &xattr_ref->block);
493 ext4_balloc_free_block(xattr_ref->inode_ref, xattr_block);
494 xattr_ref->inode_ref->dirty = true;
495 xattr_ref->block_loaded = false;
498 static void ext4_xattr_set_block_header(struct ext4_xattr_ref *xattr_ref)
500 struct ext4_xattr_header *block_header = NULL;
501 block_header = EXT4_XATTR_BHDR(&xattr_ref->block);
503 memset(block_header, 0, sizeof(struct ext4_xattr_header));
504 block_header->h_magic = EXT4_XATTR_MAGIC;
505 block_header->h_refcount = to_le32(1);
506 block_header->h_blocks = to_le32(1);
510 ext4_xattr_set_inode_entry(struct ext4_xattr_item *item,
511 struct ext4_xattr_ibody_header *ibody_header,
512 struct ext4_xattr_entry *entry, void *ibody_data_ptr)
514 entry->e_name_len = to_le32(item->name_len);
515 entry->e_name_index = item->name_index;
516 entry->e_value_offs =
517 (char *)ibody_data_ptr - (char *)EXT4_XATTR_IFIRST(ibody_header);
518 entry->e_value_block = 0;
519 entry->e_value_size = item->data_size;
522 static void ext4_xattr_set_block_entry(struct ext4_xattr_item *item,
523 struct ext4_xattr_header *block_header,
524 struct ext4_xattr_entry *block_entry,
525 void *block_data_ptr)
527 block_entry->e_name_len = to_le32(item->name_len);
528 block_entry->e_name_index = item->name_index;
529 block_entry->e_value_offs =
530 (char *)block_data_ptr - (char *)block_header;
531 block_entry->e_value_block = 0;
532 block_entry->e_value_size = item->data_size;
535 static int ext4_xattr_write_to_disk(struct ext4_xattr_ref *xattr_ref)
538 bool block_modified = false;
539 void *ibody_data = NULL;
540 void *block_data = NULL;
541 struct ext4_xattr_item *item, *save_item;
542 size_t inode_size_rem, block_size_rem;
543 struct ext4_xattr_ibody_header *ibody_header = NULL;
544 struct ext4_xattr_header *block_header = NULL;
545 struct ext4_xattr_entry *entry = NULL;
546 struct ext4_xattr_entry *block_entry = NULL;
548 inode_size_rem = ext4_xattr_inode_space(xattr_ref);
549 block_size_rem = ext4_xattr_block_space(xattr_ref);
550 if (inode_size_rem > sizeof(struct ext4_xattr_ibody_header)) {
551 ibody_header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
552 entry = EXT4_XATTR_IFIRST(ibody_header);
555 if (!xattr_ref->dirty)
557 /* If there are enough spaces in the ibody EA table.*/
558 if (inode_size_rem > sizeof(struct ext4_xattr_ibody_header)) {
559 memset(ibody_header, 0, inode_size_rem);
560 ibody_header->h_magic = EXT4_XATTR_MAGIC;
561 ibody_data = (char *)ibody_header + inode_size_rem;
562 inode_size_rem -= sizeof(struct ext4_xattr_ibody_header);
564 xattr_ref->inode_ref->dirty = true;
566 /* If we need an extra block to hold the EA entries*/
567 if (xattr_ref->ea_size > inode_size_rem) {
568 if (!xattr_ref->block_loaded) {
569 ret = ext4_xattr_try_alloc_block(xattr_ref);
573 block_header = EXT4_XATTR_BHDR(&xattr_ref->block);
574 block_entry = EXT4_XATTR_BFIRST(&xattr_ref->block);
575 ext4_xattr_set_block_header(xattr_ref);
576 block_data = (char *)block_header + block_size_rem;
577 block_size_rem -= sizeof(struct ext4_xattr_header);
579 xattr_ref->block.dirty = true;
581 /* We don't need an extra block.*/
582 if (xattr_ref->block_loaded) {
583 block_header = EXT4_XATTR_BHDR(&xattr_ref->block);
584 block_header->h_refcount =
585 to_le32(to_le32(block_header->h_refcount) - 1);
586 if (!block_header->h_refcount) {
587 ext4_xattr_try_free_block(xattr_ref);
591 EXT4_XATTR_BFIRST(&xattr_ref->block);
593 (char *)block_header + block_size_rem;
595 sizeof(struct ext4_xattr_header);
596 ext4_inode_set_file_acl(
597 xattr_ref->inode_ref->inode,
598 &xattr_ref->fs->sb, 0);
600 xattr_ref->inode_ref->dirty = true;
601 xattr_ref->block.dirty = true;
605 RB_FOREACH_SAFE(item, ext4_xattr_tree, &xattr_ref->root, save_item)
607 if (EXT4_XATTR_SIZE(item->data_size) +
608 EXT4_XATTR_LEN(item->name_len) <=
610 ibody_data = (char *)ibody_data -
611 EXT4_XATTR_SIZE(item->data_size);
612 ext4_xattr_set_inode_entry(item, ibody_header, entry,
614 memcpy(EXT4_XATTR_NAME(entry), item->name,
616 memcpy(ibody_data, item->data, item->data_size);
617 entry = EXT4_XATTR_NEXT(entry);
618 inode_size_rem -= EXT4_XATTR_SIZE(item->data_size) +
619 EXT4_XATTR_LEN(item->name_len);
621 xattr_ref->inode_ref->dirty = true;
624 if (EXT4_XATTR_SIZE(item->data_size) +
625 EXT4_XATTR_LEN(item->name_len) >
631 (char *)block_data - EXT4_XATTR_SIZE(item->data_size);
632 ext4_xattr_set_block_entry(item, block_header, block_entry,
634 memcpy(EXT4_XATTR_NAME(block_entry), item->name,
636 memcpy(block_data, item->data, item->data_size);
637 block_entry = EXT4_XATTR_NEXT(block_entry);
638 block_size_rem -= EXT4_XATTR_SIZE(item->data_size) +
639 EXT4_XATTR_LEN(item->name_len);
641 block_modified = true;
643 xattr_ref->dirty = false;
644 if (block_modified) {
645 ext4_xattr_rehash(block_header,
646 EXT4_XATTR_BFIRST(&xattr_ref->block));
647 xattr_ref->block.dirty = true;
654 void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
655 int (*iter)(struct ext4_xattr_ref *ref,
656 struct ext4_xattr_item *item))
658 struct ext4_xattr_item *item;
660 ref->iter_from = RB_MIN(ext4_xattr_tree, &ref->root);
662 RB_FOREACH_FROM(item, ext4_xattr_tree, ref->iter_from)
664 int ret = EXT4_XATTR_ITERATE_CONT;
668 if (ret != EXT4_XATTR_ITERATE_CONT) {
669 if (ret == EXT4_XATTR_ITERATE_STOP)
670 ref->iter_from = NULL;
677 void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref)
679 ref->iter_from = NULL;
682 int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
683 const char *name, size_t name_len, const void *data,
684 size_t data_size, bool replace)
687 struct ext4_xattr_item *item =
688 ext4_xattr_lookup_item(ref, name_index, name, name_len);
694 if (item->data_size != data_size)
695 ret = ext4_xattr_resize_item(ref, item, data_size);
700 memcpy(item->data, data, data_size);
706 item = ext4_xattr_insert_item(ref, name_index, name, name_len,
715 int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
716 const char *name, size_t name_len)
718 return ext4_xattr_remove_item(ref, name_index, name, name_len);
721 int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
722 const char *name, size_t name_len, void *buf, size_t buf_size,
726 size_t item_size = 0;
727 struct ext4_xattr_item *item =
728 ext4_xattr_lookup_item(ref, name_index, name, name_len);
734 item_size = item->data_size;
735 if (buf_size > item_size)
736 buf_size = item_size;
739 memcpy(buf, item->data, buf_size);
743 *data_size = item_size;
748 int ext4_fs_get_xattr_ref(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref,
749 struct ext4_xattr_ref *ref)
752 uint64_t xattr_block;
753 xattr_block = ext4_inode_get_file_acl(inode_ref->inode, &fs->sb);
756 ref->iter_from = NULL;
758 rc = ext4_block_get(fs->bdev, &ref->block, xattr_block);
762 ref->block_loaded = true;
764 ref->block_loaded = false;
766 ref->inode_ref = inode_ref;
769 rc = ext4_xattr_fetch(ref);
771 ext4_xattr_purge_items(ref);
773 ext4_block_set(fs->bdev, &inode_ref->block);
775 ref->block_loaded = false;
781 void ext4_fs_put_xattr_ref(struct ext4_xattr_ref *ref)
783 ext4_xattr_write_to_disk(ref);
784 if (ref->block_loaded) {
785 ext4_block_set(ref->fs->bdev, &ref->block);
786 ref->block_loaded = false;
788 ext4_xattr_purge_items(ref);
789 ref->inode_ref = NULL;
793 struct xattr_prefix {
798 static const struct xattr_prefix prefix_tbl[] = {
799 {"user.", EXT4_XATTR_INDEX_USER},
800 {"system.", EXT4_XATTR_INDEX_SYSTEM},
801 {"system.posix_acl_access", EXT4_XATTR_INDEX_POSIX_ACL_ACCESS},
802 {"system.posix_acl_default", EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT},
806 const char *ext4_extract_xattr_name(const char *full_name, size_t full_name_len,
807 uint8_t *name_index, size_t *name_len)
810 ext4_assert(name_index);
811 if (!full_name_len) {
818 for (i = 0; prefix_tbl[i].prefix; i++) {
819 size_t prefix_len = strlen(prefix_tbl[i].prefix);
820 if (full_name_len >= prefix_len &&
821 !memcmp(full_name, prefix_tbl[i].prefix, prefix_len)) {
822 *name_index = prefix_tbl[i].name_index;
824 *name_len = full_name_len - prefix_len;
826 return full_name + prefix_len;
835 const char *ext4_get_xattr_name_prefix(uint8_t name_index, size_t *ret_prefix_len)
839 for (i = 0; prefix_tbl[i].prefix; i++) {
840 size_t prefix_len = strlen(prefix_tbl[i].prefix);
841 if (prefix_tbl[i].name_index == name_index) {
843 *ret_prefix_len = prefix_len;
845 return prefix_tbl[i].prefix;