1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
4 *
5 * Test whether ustat(2) system call returns appropriate error number for
6 * invalid dev_t parameter and for bad address paramater.
7 */
8
9 #include <unistd.h>
10 #include <errno.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13
14 #include "lapi/syscalls.h"
15 #include "lapi/ustat.h"
16 #include "tst_test.h"
17
18 static dev_t invalid_dev = -1;
19 static dev_t root_dev;
20 struct ustat ubuf;
21
22 static struct test_case_t {
23 char *err_desc;
24 int exp_errno;
25 char *exp_errval;
26 dev_t *dev;
27 struct ustat *buf;
28 } tc[] = {
29 {"Invalid parameter", EINVAL, "EINVAL", &invalid_dev, &ubuf},
30 #ifndef UCLINUX
31 {"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1}
32 #endif
33 };
34
35 int TST_TOTAL = ARRAY_SIZE(tc);
36
run(unsigned int test)37 void run(unsigned int test)
38 {
39 TEST(tst_syscall(__NR_ustat, *tc[test].dev, tc[test].buf));
40
41 if ((TST_RET == -1) && (TST_ERR == tc[test].exp_errno))
42 tst_res(TPASS | TTERRNO, "ustat(2) expected failure");
43 else
44 tst_res(TFAIL | TTERRNO,
45 "ustat(2) failed to produce expected error; %d, errno"
46 ": %s", tc[test].exp_errno, tc[test].exp_errval);
47 }
48
setup(void)49 static void setup(void)
50 {
51 struct stat buf;
52
53 /* Find a valid device number */
54 SAFE_STAT("/", &buf);
55
56 root_dev = buf.st_dev;
57 }
58
59 static struct tst_test test = {
60 .test = run,
61 .setup = setup,
62 .tcnt = ARRAY_SIZE(tc),
63 };
64