The maximum size for extended attribute values is 65536 (XATTR_SIZE_MAX).
Since there are filesystems that can set blksize to really big values
(CephFS for example has a default of 4M), it's easy to have this test
failing with fsetxattr returning -E2BIG.
Cc: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Luis Henriques <lhenriques@suse.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
#include <sys/types.h>
#include <sys/xattr.h>
#include <sys/stat.h>
+#include <sys/param.h>
+#include <linux/limits.h>
#define die() do { perror(""); \
fprintf(stderr, "error at line %d\n", __LINE__); \
size = sbuf.st_blksize * 3 / 4;
if (!size)
fail("Invalid st_blksize(%ld)\n", sbuf.st_blksize);
+ size = MIN(size, XATTR_SIZE_MAX);
value = malloc(size);
if (!value)
fail("Failed to allocate memory\n");