aboutsummaryrefslogtreecommitdiff
path: root/testcases/kernel/syscalls/statvfs/statvfs02.c
blob: 8aaa47318eef711dfe4d92e76106a50071c2fb07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: GPL-2.0

/*
 * Copyright (c) 2014 Fujitsu Ltd.
 * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
 */

/*\
 * [Description]
 *
 * Verify that statvfs() fails with:
 * - EFAULT when path points to an invalid address.
 * - ELOOP when too many symbolic links were encountered in translating path.
 * - ENAMETOOLONG when path is too long.
 * - ENOENT when the file referred to by path does not exist.
 * - ENOTDIR a component of the path prefix of path is not a directory.
 */

#include <sys/statvfs.h>

#include "tst_test.h"

#define TEST_SYMLINK	"statvfs_symlink"
#define TEST_FILE	"statvfs_file"

static struct statvfs buf;
static char nametoolong[PATH_MAX+2];

static struct tcase {
	char *path;
	struct statvfs *buf;
	int exp_errno;
} tcases[] = {
	{(char *)-1, &buf, EFAULT},
	{TEST_SYMLINK, &buf, ELOOP},
	{nametoolong, &buf, ENAMETOOLONG},
	{"filenoexist", &buf, ENOENT},
	{"statvfs_file/test", &buf, ENOTDIR},
};

static void setup(void)
{
	unsigned int i;

	SAFE_SYMLINK(TEST_SYMLINK, "symlink_2");
	SAFE_SYMLINK("symlink_2", TEST_SYMLINK);

	memset(nametoolong, 'a', PATH_MAX+1);
	SAFE_TOUCH(TEST_FILE, 0644, NULL);

	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
		if (tcases[i].path == (char *)-1)
			tcases[i].path = tst_get_bad_addr(NULL);
	}
}

static void run(unsigned int i)
{
	struct tcase *tc = &tcases[i];

	TST_EXP_FAIL(statvfs(tc->path, tc->buf), tc->exp_errno);
}

static struct tst_test test = {
	.setup = setup,
	.test = run,
	.tcnt = ARRAY_SIZE(tcases),
	.needs_tmpdir = 1
};