45
static void usage(const char *name)
47
fprintf(stderr, "Usage: %s [-x] file\n", name);
50
43
int main(int argc, char **argv)
52
45
ssize_t len, names_len = 0;
53
int i, rc, xattr_metadata = 0;
55
char *file, *ptr = buffer;
57
if (argc < 2 || argc > 3) {
51
fprintf(stderr, "Usage: %s file\n", argv[0]);
59
52
exit(EXIT_FAILURE);
65
if (strcmp(argv[1], "-x")) {
72
* The XATTR_METADATA_NAME xattr is set. Account for it in
73
* future sanity checks.
76
names_len = 1 + strlen(XATTR_METADATA_NAME);
79
55
for (i = 0; names[i]; i++) {
80
if (setxattr(file, names[i], values[i], strlen(values[i]), 0) < 0)
56
if (setxattr(argv[1], names[i], values[i], strlen(values[i]), 0) < 0)
81
57
exit(EXIT_FAILURE);
82
58
names_len += 1 + strlen(names[i]);
86
62
* Sanity check that listxattr returns correct length
88
len = listxattr(file, NULL, 0);
89
if (len != names_len || len > sizeof(buffer))
92
memset(buffer, 0, sizeof(buffer));
94
len = listxattr(file, buffer, sizeof(buffer));
64
len = listxattr(argv[1], NULL, 0);
95
65
if (len != names_len)
96
66
exit(EXIT_FAILURE);
68
len = listxattr(argv[1], buffer, sizeof(buffer));
99
73
* Check listxattr names match what has been just set
101
for (ptr = buffer; *ptr; ptr += strlen(ptr) + 1) {
104
if (xattr_metadata && !strcmp(XATTR_METADATA_NAME, ptr))
107
for (i = 0; names[i]; i++) {
108
if (strcmp(names[i], ptr))
75
for (i = 0; names[i]; i++) {
76
if (strcmp(names[i], ptr))
116
77
exit(EXIT_FAILURE);
78
ptr += strlen(ptr) + 1;
120
82
* Check contents of xattr
122
84
for (i = 0; names[i]; i++) {
123
len = getxattr(file, names[i], buffer, sizeof(buffer));
85
len = getxattr(argv[1], names[i], buffer, sizeof(buffer));
125
87
exit(EXIT_FAILURE);
126
88
buffer[len] = '\0';
135
97
for (i = 0; names[i]; i++) {
136
rc = removexattr(file, names[i]);
98
rc = removexattr(argv[1], names[i]);
138
100
exit(EXIT_FAILURE);
139
names_len -= 1 + strlen(names[i]);
143
* ..and the only xattrs that should be left are those that were
144
* already there when the test started
104
* ..and there should be no xattrs left
146
len = listxattr(file, NULL, 0);
147
if (len != names_len)
106
len = listxattr(argv[1], NULL, 0);
148
108
exit(EXIT_FAILURE);
150
110
exit(EXIT_SUCCESS);