1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) Wipro Technologies Ltd, 2003.  All Rights Reserved.
4 *
5 * Check that ustat() succeeds given correct parameters.
6 */
7
8#include "config.h"
9#include "tst_test.h"
10
11#if defined(HAVE_SYS_USTAT_H) || defined(HAVE_LINUX_TYPES_H)
12#include <unistd.h>
13#include <errno.h>
14#include <sys/types.h>
15#include <sys/stat.h>
16
17#include "lapi/syscalls.h"
18#include "lapi/ustat.h"
19
20static dev_t dev_num;
21
22void run(void)
23{
24	struct ustat ubuf;
25
26	TEST(tst_syscall(__NR_ustat, (unsigned int)dev_num, &ubuf));
27
28	if (TST_RET == -1)
29		tst_res(TFAIL | TTERRNO, "ustat(2) failed");
30	else
31		tst_res(TPASS, "ustat(2) passed");
32}
33
34static void setup(void)
35{
36	struct stat buf;
37
38	/* Find a valid device number */
39	SAFE_STAT("/", &buf);
40
41	dev_num = buf.st_dev;
42}
43
44static struct tst_test test = {
45	.test_all = run,
46	.setup = setup,
47	.tags = (const struct tst_tag[]) {
48		{"known-fail", "ustat() is known to fail with EINVAL on Btrfs, see "
49			"https://lore.kernel.org/linux-btrfs/e7e867b8-b57a-7eb2-2432-1627bd3a88fb@toxicpanda.com/"
50		},
51		{}
52	}
53};
54#else
55TST_TEST_TCONF("testing ustat requires <sys/ustat.h> or <linux/types.h>");
56#endif
57