From e7974ec2eae0f0142112028d8b7bd0af0c0c5ebb Mon Sep 17 00:00:00 2001 From: Daniel Walter Date: Wed, 31 Aug 2016 10:05:36 +0200 Subject: Add support for sysfs mocking In order to use test files, allow sysfs root to be set during compile time Signed-off-by: Daniel Walter --- lib/libmtd.c | 2 +- lib/libmtd_int.h | 4 ++++ ubi-utils/libubi.c | 4 ++-- ubi-utils/libubi_int.h | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index 8c0157e..8bc532f 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -561,7 +561,7 @@ libmtd_t libmtd_open(void) lib->offs64_ioctls = OFFS64_IOCTLS_UNKNOWN; - lib->sysfs_mtd = mkpath("/sys", SYSFS_MTD); + lib->sysfs_mtd = mkpath(SYSFS_ROOT, SYSFS_MTD); if (!lib->sysfs_mtd) goto out_error; diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h index 8ff33ad..db2f1cf 100644 --- a/lib/libmtd_int.h +++ b/lib/libmtd_int.h @@ -30,6 +30,10 @@ extern "C" { #define PROGRAM_NAME "libmtd" +#ifndef SYSFS_ROOT +#define SYSFS_ROOT "/sys" +#endif + #define SYSFS_MTD "class/mtd" #define MTD_NAME_PATT "mtd%d" #define MTD_DEV "dev" diff --git a/ubi-utils/libubi.c b/ubi-utils/libubi.c index 97c0434..758d351 100644 --- a/ubi-utils/libubi.c +++ b/ubi-utils/libubi.c @@ -524,7 +524,7 @@ libubi_t libubi_open(void) if (!lib) return NULL; - lib->sysfs_ctrl = mkpath("/sys", SYSFS_CTRL); + lib->sysfs_ctrl = mkpath(SYSFS_ROOT, SYSFS_CTRL); if (!lib->sysfs_ctrl) goto out_error; @@ -532,7 +532,7 @@ libubi_t libubi_open(void) if (!lib->ctrl_dev) goto out_error; - lib->sysfs_ubi = mkpath("/sys", SYSFS_UBI); + lib->sysfs_ubi = mkpath(SYSFS_ROOT, SYSFS_UBI); if (!lib->sysfs_ubi) goto out_error; diff --git a/ubi-utils/libubi_int.h b/ubi-utils/libubi_int.h index c3aa37a..86ce18a 100644 --- a/ubi-utils/libubi_int.h +++ b/ubi-utils/libubi_int.h @@ -36,6 +36,9 @@ extern "C" { * directories to '/sys/class/ubi/'. For now libubi assumes old layout. */ +#ifndef SYSFS_ROOT +#define SYSFS_ROOT "/sys" +#endif #define SYSFS_UBI "class/ubi" #define SYSFS_CTRL "class/misc/ubi_ctrl/" -- cgit v1.2.3