1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 */
5
6 /*\
7 * [Description]
8 *
9 * This test case checks whether sysfs(2) system call returns appropriate
10 * error number for invalid option and for invalid filesystem name and fs index out of bounds.
11 */
12
13 #include "tst_test.h"
14 #include "lapi/syscalls.h"
15
16 static struct test_case {
17 int option;
18 char *fsname;
19 int fsindex;
20 char *err_desc;
21 int exp_errno;
22 } tcases[] = {
23 {1, "ext0", 0, "Invalid filesystem name", EINVAL},
24 {4, NULL, 0, "Invalid option", EINVAL},
25 {1, NULL, 0, "Address is out of your address space", EFAULT},
26 {2, NULL, 1000, "fs_index is out of bounds", EINVAL}
27 };
28
verify_sysfs05(unsigned int nr)29 static void verify_sysfs05(unsigned int nr)
30 {
31 struct test_case *tc = &tcases[nr];
32 char buf[1024];
33
34 if (tc->option == 1) {
35 TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsname),
36 tc->exp_errno, "%s", tc->err_desc);
37 } else {
38 TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsindex, buf),
39 tc->exp_errno, "%s", tc->err_desc);
40 }
41 }
42
setup(void)43 static void setup(void)
44 {
45 unsigned int i;
46 char *bad_addr;
47
48 bad_addr = tst_get_bad_addr(NULL);
49
50 for (i = 0; i < ARRAY_SIZE(tcases); i++) {
51 if (tcases[i].exp_errno == EFAULT)
52 tcases[i].fsname = bad_addr;
53 }
54 }
55
56 static struct tst_test test = {
57 .setup = setup,
58 .tcnt = ARRAY_SIZE(tcases),
59 .test = verify_sysfs05,
60 };
61
62