1 // setattr.c by kanda.motohiro@gmail.com
2 // xfs extended attribute corruption bug reproducer
10 #include <sys/xattr.h>
12 #include <sys/param.h>
13 #include <linux/limits.h>
15 #define die() do { perror(""); \
16 fprintf(stderr, "error at line %d\n", __LINE__); \
19 #define fail(...) do { \
20 fprintf(stderr, __VA_ARGS__); exit (1); \
23 int main(int argc, char *argv[])
28 char *name = "user.world";
31 size_t size = sizeof(value);
34 fail("Usage: %s <file>\n", argv[0]);
37 fd = open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
41 * The value should be 3/4 the size of a fs block to ensure that we
42 * get to extents format.
44 ret = fstat(fd, &sbuf);
46 size = sbuf.st_blksize * 3 / 4;
48 fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
49 size = MIN(size, XATTR_SIZE_MAX);
52 fail("Failed to allocate memory\n");
54 /* First, create a small xattr. */
55 memset(value, '0', 1);
56 ret = fsetxattr(fd, name, value, 1, XATTR_CREATE);
60 fd = open(path, O_RDWR);
63 /* Then, replace it with bigger one, forcing short form to leaf conversion. */
64 memset(value, '1', size);
65 ret = fsetxattr(fd, name, value, size, XATTR_REPLACE);