// SPDX-License-Identifier: LGPL-2.0-only // SPDX-FileCopyrightText: 2023 Oleksij Rempel #include #include #include #include #include "isobusfs_cmn.h" #include #include #include #include int isobusfs_cmn_dh_validate_dir_path(const char *path, bool writable) { struct stat path_stat; int mode = R_OK; int ret; mode |= writable ? W_OK : 0; ret = access(path, mode); if (ret == -1) { ret = -errno; pr_err("failed to access path %s, for read %s. %s", path, writable ? "and write" : "", strerror(ret)); return ret; } ret = stat(path, &path_stat); if (ret == -1) { ret = -errno; pr_err("failed to get stat information on path %s. %s", path, strerror(ret)); return ret; } if (!S_ISDIR(path_stat.st_mode)) { pr_err("path %s is not a directory", path); return -ENOTDIR; } return 0; }