• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "config.h"
10 #include "tst_test.h"
11 
12 #if defined(HAVE_SYS_USTAT_H) || defined(HAVE_LINUX_TYPES_H)
13 #include <unistd.h>
14 #include <errno.h>
15 #include <sys/stat.h>
16 #include <sys/types.h>
17 
18 #include "lapi/syscalls.h"
19 #include "lapi/ustat.h"
20 
21 static dev_t invalid_dev = -1;
22 static dev_t root_dev;
23 struct ustat ubuf;
24 
25 static struct test_case_t {
26 	char *err_desc;
27 	int exp_errno;
28 	char *exp_errval;
29 	dev_t *dev;
30 	struct ustat *buf;
31 } tc[] = {
32 	{"Invalid parameter", EINVAL, "EINVAL", &invalid_dev, &ubuf},
33 #ifndef UCLINUX
34 	{"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1}
35 #endif
36 };
37 
38 int TST_TOTAL = ARRAY_SIZE(tc);
39 
run(unsigned int test)40 void run(unsigned int test)
41 {
42 	TEST(tst_syscall(__NR_ustat, (unsigned int)*tc[test].dev, tc[test].buf));
43 
44 	if ((TST_RET == -1) && (TST_ERR == tc[test].exp_errno))
45 		tst_res(TPASS | TTERRNO, "ustat(2) expected failure");
46 	else
47 		tst_res(TFAIL | TTERRNO,
48 			"ustat(2) failed to produce expected error; %d, errno"
49 			": %s", tc[test].exp_errno, tc[test].exp_errval);
50 }
51 
setup(void)52 static void setup(void)
53 {
54 	struct stat buf;
55 
56 	/* Find a valid device number */
57 	SAFE_STAT("/", &buf);
58 
59 	root_dev = buf.st_dev;
60 }
61 
62 static struct tst_test test = {
63 	.test = run,
64 	.setup = setup,
65 	.tcnt = ARRAY_SIZE(tc),
66 	.tags = (const struct tst_tag[]) {
67 		{"known-fail", "ustat() is known to fail with EINVAL on Btrfs, see"
68 			"https://lore.kernel.org/linux-btrfs/e7e867b8-b57a-7eb2-2432-1627bd3a88fb@toxicpanda.com/"
69 		},
70 		{}
71 	}
72 };
73 #else
74 TST_TEST_TCONF("testing ustat requires <sys/ustat.h> or <linux/types.h>");
75 #endif
76