1// SPDX-License-Identifier: GPL-2.0-or-later 2 3#include <dirent.h> 4#include <errno.h> 5#include <sys/mount.h> 6 7#define TST_NO_DEFAULT_MAIN 8#include "tst_test.h" 9#include "tst_fs.h" 10 11#define TST_FS_SETUP_OVERLAYFS_MSG "overlayfs is not configured in this kernel" 12#define TST_FS_SETUP_OVERLAYFS_CONFIG "lowerdir="OVL_LOWER",upperdir="OVL_UPPER",workdir="OVL_WORK 13 14void create_overlay_dirs(void) 15{ 16 DIR *dir = opendir(OVL_LOWER); 17 if (dir == NULL) { 18 SAFE_MKDIR(OVL_LOWER, 0755); 19 SAFE_MKDIR(OVL_UPPER, 0755); 20 SAFE_MKDIR(OVL_WORK, 0755); 21 SAFE_MKDIR(OVL_MNT, 0755); 22 return; 23 } 24 closedir(dir); 25} 26 27int mount_overlay(const char *file, const int lineno, int strict) 28{ 29 int ret; 30 31 create_overlay_dirs(); 32 ret = mount("overlay", OVL_MNT, "overlay", 0, 33 TST_FS_SETUP_OVERLAYFS_CONFIG); 34 if (ret == 0) 35 return 0; 36 37 if (errno == ENODEV) { 38 if (strict) { 39 tst_brk_(file, lineno, TCONF, 40 TST_FS_SETUP_OVERLAYFS_MSG); 41 } else { 42 tst_res_(file, lineno, TINFO, 43 TST_FS_SETUP_OVERLAYFS_MSG); 44 } 45 } else if (strict) { 46 tst_brk_(file, lineno, TBROK | TERRNO, 47 "overlayfs mount failed"); 48 } 49 return ret; 50} 51