1 // setattr.c by kanda.motohiro@gmail.com
2 // xfs extended attribute corruption bug reproducer
10 #include <sys/xattr.h>
13 #define die() do { perror(""); \
14 fprintf(stderr, "error=%d at line %d\n", errno, __LINE__); \
17 #define fail(...) do { \
18 fprintf(stderr, __VA_ARGS__); exit (1); \
21 int main(int argc, char *argv[])
26 char *name = "user.world";
29 size_t size = sizeof(value);
32 fail("Usage: %s <file>\n", argv[0]);
35 fd = open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
39 * The value should be 3/4 the size of a fs block to ensure that we
40 * get to extents format.
42 ret = fstat(fd, &sbuf);
44 size = sbuf.st_blksize * 3 / 4;
46 fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
49 fail("Failed to allocate memory\n");
51 /* First, create a small xattr. */
52 memset(value, '0', 1);
53 ret = fsetxattr(fd, name, value, 1, XATTR_CREATE);
57 fd = open(path, O_RDWR);
60 /* Then, replace it with bigger one, forcing short form to leaf conversion. */
61 memset(value, '1', size);
62 ret = fsetxattr(fd, name, value, size, XATTR_REPLACE);