1 // SPDX-License-Identifier: GPL-2.0
2 #define _GNU_SOURCE
3 #define __SANE_USERSPACE_TYPES__
4
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <sys/stat.h>
8 #include <sys/xattr.h>
9
10 #include "../kselftest_harness.h"
11 #include "wrappers.h"
12
TEST(kernfs_listxattr)13 TEST(kernfs_listxattr)
14 {
15 int fd;
16
17 /* Read-only file that can never have any extended attributes set. */
18 fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
19 ASSERT_GE(fd, 0);
20 ASSERT_EQ(flistxattr(fd, NULL, 0), 0);
21 EXPECT_EQ(close(fd), 0);
22 }
23
TEST(kernfs_getxattr)24 TEST(kernfs_getxattr)
25 {
26 int fd;
27 char buf[1];
28
29 /* Read-only file that can never have any extended attributes set. */
30 fd = open("/sys/kernel/warn_count", O_RDONLY | O_CLOEXEC);
31 ASSERT_GE(fd, 0);
32 ASSERT_LT(fgetxattr(fd, "user.foo", buf, sizeof(buf)), 0);
33 ASSERT_EQ(errno, ENODATA);
34 EXPECT_EQ(close(fd), 0);
35 }
36
37 TEST_HARNESS_MAIN
38
39