forked from tytso/e2fsprogs-inline-patch-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
25-libext2fs-xattr-add-ea-count-api.patch
109 lines (100 loc) · 3.2 KB
/
25-libext2fs-xattr-add-ea-count-api.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
From: Darrick J. Wong <darrick.wong@oracle.com>
libext2fs: extend xattr api to query number of attrs
Add another API to query the number of extended attributes.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 57db793..e251435 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1168,6 +1168,7 @@ errcode_t ext2fs_xattrs_open(ext2_filsys fs, ext2_ino_t ino,
errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle);
errcode_t ext2fs_free_ext_attr(ext2_filsys fs, ext2_ino_t ino,
struct ext2_inode_large *inode);
+size_t ext2fs_xattrs_count(struct ext2_xattr_handle *handle);
/* extent.c */
extern errcode_t ext2fs_extent_header_verify(void *ptr, int size);
diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c
index bfe95f4..2fae516 100644
--- a/lib/ext2fs/ext_attr.c
+++ b/lib/ext2fs/ext_attr.c
@@ -197,7 +197,7 @@ struct ext2_xattr {
struct ext2_xattr_handle {
ext2_filsys fs;
struct ext2_xattr *attrs;
- size_t length;
+ size_t length, count;
ext2_ino_t ino;
int dirty;
};
@@ -575,7 +575,8 @@ out:
static errcode_t read_xattrs_from_buffer(struct ext2_xattr_handle *handle,
struct ext2_ext_attr_entry *entries,
unsigned int storage_size,
- void *value_start)
+ void *value_start,
+ size_t *nr_read)
{
struct ext2_xattr *x;
struct ext2_ext_attr_entry *entry;
@@ -648,6 +649,7 @@ static errcode_t read_xattrs_from_buffer(struct ext2_xattr_handle *handle,
memcpy(x->value, value_start + entry->e_value_offs,
entry->e_value_size);
x++;
+ (*nr_read)++;
entry = EXT2_EXT_ATTR_NEXT(entry);
}
@@ -697,7 +699,7 @@ errcode_t ext2fs_xattrs_read(struct ext2_xattr_handle *handle)
inode->i_extra_isize + sizeof(__u32);
err = read_xattrs_from_buffer(handle, start, storage_size,
- start);
+ start, &handle->count);
if (err)
goto out;
}
@@ -737,7 +739,7 @@ read_ea_block:
sizeof(struct ext2_ext_attr_header);
start = block_buf + sizeof(struct ext2_ext_attr_header);
err = read_xattrs_from_buffer(handle, start, storage_size,
- block_buf);
+ block_buf, &handle->count);
if (err)
goto out3;
@@ -848,6 +850,7 @@ errcode_t ext2fs_xattr_set(struct ext2_xattr_handle *handle,
memcpy(last_empty->value, value, value_len);
last_empty->value_len = value_len;
handle->dirty = 1;
+ handle->count++;
return 0;
}
@@ -868,6 +871,7 @@ errcode_t ext2fs_xattr_set(struct ext2_xattr_handle *handle,
memcpy(x->value, value, value_len);
x->value_len = value_len;
handle->dirty = 1;
+ handle->count++;
return 0;
}
@@ -886,6 +890,7 @@ errcode_t ext2fs_xattr_remove(struct ext2_xattr_handle *handle,
ext2fs_free_mem(&x->value);
x->value_len = 0;
handle->dirty = 1;
+ handle->count--;
return 0;
}
}
@@ -910,6 +915,7 @@ errcode_t ext2fs_xattrs_open(ext2_filsys fs, ext2_ino_t ino,
ext2fs_free_mem(&h);
return err;
}
+ h->count = 0;
h->ino = ino;
h->fs = fs;
*handle = h;
@@ -940,3 +946,8 @@ errcode_t ext2fs_xattrs_close(struct ext2_xattr_handle **handle)
ext2fs_free_mem(handle);
return 0;
}
+
+size_t ext2fs_xattrs_count(struct ext2_xattr_handle *handle)
+{
+ return handle->count;
+}