xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/getxattr/getxattr03.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2012  Red Hat, Inc.
4  * Copyright (c) 2023 Marius Kittler <[email protected]>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * An empty buffer of size zero can be passed into getxattr(2) to
11  * return the current size of the named extended attribute.
12  */
13 
14 #include "config.h"
15 #include "tst_test.h"
16 
17 #include <sys/xattr.h>
18 #include "tst_safe_macros.h"
19 
20 #define MNTPOINT "mntpoint"
21 #define FNAME MNTPOINT"/getxattr03testfile"
22 #define XATTR_TEST_KEY "user.testkey"
23 #define XATTR_TEST_VALUE "test value"
24 #define XATTR_TEST_VALUE_SIZE (sizeof(XATTR_TEST_VALUE) - 1)
25 
run(void)26 static void run(void)
27 {
28 	TST_EXP_VAL(getxattr(FNAME, XATTR_TEST_KEY, NULL, 0),
29 				XATTR_TEST_VALUE_SIZE);
30 }
31 
setup(void)32 static void setup(void)
33 {
34 	SAFE_TOUCH(FNAME, 0644, NULL);
35 	SAFE_SETXATTR(FNAME, XATTR_TEST_KEY, XATTR_TEST_VALUE,
36 		     XATTR_TEST_VALUE_SIZE, XATTR_CREATE);
37 }
38 
39 static struct tst_test test = {
40 	.all_filesystems = 1,
41 	.needs_root = 1,
42 	.mntpoint = MNTPOINT,
43 	.mount_device = 1,
44 	.skip_filesystems = (const char *const []) {
45 			"exfat",
46 			"tmpfs",
47 			"ramfs",
48 			"nfs",
49 			"vfat",
50 			NULL
51 	},
52 	.setup = setup,
53 	.test_all = run,
54 };
55