aboutsummaryrefslogtreecommitdiff
path: root/lib/tst_fs_setup.c
blob: 6b93483dea7ba4f3375353b931494d0c9202da2b (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
// SPDX-License-Identifier: GPL-2.0-or-later

#include <dirent.h>
#include <errno.h>
#include <sys/mount.h>

#define TST_NO_DEFAULT_MAIN
#include "tst_test.h"
#include "tst_fs.h"

#define TST_FS_SETUP_OVERLAYFS_MSG "overlayfs is not configured in this kernel"
#define TST_FS_SETUP_OVERLAYFS_CONFIG "lowerdir="OVL_LOWER",upperdir="OVL_UPPER",workdir="OVL_WORK

void create_overlay_dirs(void)
{
	DIR *dir = opendir(OVL_LOWER);
	if (dir == NULL) {
		SAFE_MKDIR(OVL_LOWER, 0755);
		SAFE_MKDIR(OVL_UPPER, 0755);
		SAFE_MKDIR(OVL_WORK, 0755);
		SAFE_MKDIR(OVL_MNT, 0755);
		return;
	}
	closedir(dir);
}

int mount_overlay(const char *file, const int lineno, int skip)
{
	int ret;

	create_overlay_dirs();
	ret = mount("overlay", OVL_MNT, "overlay", 0,
				TST_FS_SETUP_OVERLAYFS_CONFIG);
	if (ret == 0)
		return 0;

	if (errno == ENODEV) {
		if (skip) {
			tst_brk_(file, lineno, TCONF,
				TST_FS_SETUP_OVERLAYFS_MSG);
		} else {
			tst_res_(file, lineno, TINFO,
				TST_FS_SETUP_OVERLAYFS_MSG);
		}
	} else {
		tst_brk_(file, lineno, TBROK | TERRNO,
			"overlayfs mount failed");
	}
	return ret;
}