1 // SPDX-License-Identifier: GPL-2.0-only
2
3 /*
4 * Copyright (c) 2014 Fujitsu Ltd.
5 * Author: Zeng Linggang <[email protected]>
6 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
7 */
8
9 /*\
10 * [Description]
11 *
12 * Verify that statvfs() fails with:
13 *
14 * - EFAULT when path points to an invalid address.
15 * - ELOOP when too many symbolic links were encountered in translating path.
16 * - ENAMETOOLONG when path is too long.
17 * - ENOENT when the file referred to by path does not exist.
18 * - ENOTDIR a component of the path prefix of path is not a directory.
19 */
20
21 #include <sys/statvfs.h>
22
23 #include "tst_test.h"
24
25 #define TEST_SYMLINK "statvfs_symlink"
26 #define TEST_FILE "statvfs_file"
27
28 static struct statvfs buf;
29 static char nametoolong[PATH_MAX+2];
30
31 static struct tcase {
32 char *path;
33 struct statvfs *buf;
34 int exp_errno;
35 } tcases[] = {
36 {(char *)-1, &buf, EFAULT},
37 {TEST_SYMLINK, &buf, ELOOP},
38 {nametoolong, &buf, ENAMETOOLONG},
39 {"filenoexist", &buf, ENOENT},
40 {"statvfs_file/test", &buf, ENOTDIR},
41 };
42
setup(void)43 static void setup(void)
44 {
45 unsigned int i;
46
47 SAFE_SYMLINK(TEST_SYMLINK, "symlink_2");
48 SAFE_SYMLINK("symlink_2", TEST_SYMLINK);
49
50 memset(nametoolong, 'a', PATH_MAX+1);
51 SAFE_TOUCH(TEST_FILE, 0644, NULL);
52
53 for (i = 0; i < ARRAY_SIZE(tcases); i++) {
54 if (tcases[i].path == (char *)-1)
55 tcases[i].path = tst_get_bad_addr(NULL);
56 }
57 }
58
run(unsigned int i)59 static void run(unsigned int i)
60 {
61 struct tcase *tc = &tcases[i];
62
63 TST_EXP_FAIL(statvfs(tc->path, tc->buf), tc->exp_errno);
64 }
65
66 static struct tst_test test = {
67 .setup = setup,
68 .test = run,
69 .tcnt = ARRAY_SIZE(tcases),
70 .needs_tmpdir = 1
71 };
72