1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Verify that fstatfs() syscall executes successfully for all
11 * available filesystems.
12 */
13
14
15 #include <stdio.h>
16 #include "tst_test.h"
17
18 #define MNT_POINT "mntpoint"
19 #define TEMP_FILE MNT_POINT"/test_file"
20
21 static int file_fd;
22 static int pipe_fd;
23
24 static struct tcase {
25 int *fd;
26 const char *msg;
27 } tcases[] = {
28 {&file_fd, "fstatfs() on a file"},
29 {&pipe_fd, "fstatfs() on a pipe"},
30 };
31
run(unsigned int i)32 static void run(unsigned int i)
33 {
34 struct tcase *tc = &tcases[i];
35 struct statfs buf;
36
37 TST_EXP_PASS(fstatfs(*tc->fd, &buf), "%s", tc->msg);
38 }
39
setup(void)40 static void setup(void)
41 {
42 int pipe[2];
43
44 file_fd = SAFE_OPEN(TEMP_FILE, O_RDWR | O_CREAT, 0700);
45 SAFE_PIPE(pipe);
46 pipe_fd = pipe[0];
47 SAFE_CLOSE(pipe[1]);
48 }
49
cleanup(void)50 static void cleanup(void)
51 {
52 if (file_fd > 0)
53 SAFE_CLOSE(file_fd);
54 if (pipe_fd > 0)
55 SAFE_CLOSE(pipe_fd);
56 }
57
58 static struct tst_test test = {
59 .setup = setup,
60 .cleanup = cleanup,
61 .tcnt = ARRAY_SIZE(tcases),
62 .test = run,
63 .mount_device = 1,
64 .mntpoint = MNT_POINT,
65 .all_filesystems = 1,
66 .needs_root = 1
67 };
68