mirror of
https://github.com/clearlinux/clr-boot-manager.git
synced 2026-10-03 23:38:21 +00:00
lib: Add stub around devnode_to_devpath
This allows us to mock the return location for a /dev/ node per the stat calls, enabling the full blkid / check loop to run. Signed-off-by: Ikey Doherty <michael.i.doherty@intel.com>
This commit is contained in:
committed by
William Douglas
parent
de37b1d3ff
commit
26b1c00a8e
+3
-18
@@ -24,20 +24,9 @@
|
||||
#include "blkid_stub.h"
|
||||
#include "log.h"
|
||||
#include "probe.h"
|
||||
#include "system_stub.h"
|
||||
#include "util.h"
|
||||
|
||||
/**
|
||||
* Factory function to convert a dev_t to the full device path
|
||||
*/
|
||||
static char *cbm_devnode_to_devpath(dev_t dev)
|
||||
{
|
||||
autofree(char) *c = NULL;
|
||||
if (asprintf(&c, "/dev/block/%u:%u", major(dev), minor(dev)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return realpath(c, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a sysfs dev file to the target device path
|
||||
*/
|
||||
@@ -65,7 +54,7 @@ static char *cbm_dev_file_to_devpath(const char *devfile)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cbm_devnode_to_devpath(makedev(dev_major, dev_minor));
|
||||
return cbm_system_devnode_to_devpath(makedev(dev_major, dev_minor));
|
||||
}
|
||||
|
||||
static char *cbm_get_luks_uuid(const char *part)
|
||||
@@ -150,13 +139,9 @@ CbmDeviceProbe *cbm_probe_path(const char *path)
|
||||
LOG_ERROR("Path does not exist: %s", path);
|
||||
return NULL;
|
||||
}
|
||||
if (major(st.st_dev) == 0) {
|
||||
LOG_ERROR("Invalid block device: %s", path);
|
||||
return NULL;
|
||||
}
|
||||
probe.dev = st.st_dev;
|
||||
|
||||
devnode = cbm_devnode_to_devpath(probe.dev);
|
||||
devnode = cbm_system_devnode_to_devpath(probe.dev);
|
||||
if (!devnode) {
|
||||
DECLARE_OOM();
|
||||
return NULL;
|
||||
|
||||
+33
-6
@@ -16,16 +16,37 @@
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "files.h"
|
||||
#include "log.h"
|
||||
|
||||
/**
|
||||
* Factory function to convert a dev_t to the full device path
|
||||
* This is the default internal function
|
||||
*/
|
||||
static char *cbm_devnode_to_devpath(dev_t dev)
|
||||
{
|
||||
if (major(dev) == 0) {
|
||||
LOG_ERROR("Invalid block device: %u:%u", major(dev), minor(dev));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
autofree(char) *c = NULL;
|
||||
if (asprintf(&c, "/dev/block/%u:%u", major(dev), minor(dev)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return realpath(c, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default vtable for system call passthrough
|
||||
*/
|
||||
static CbmSystemOps default_system_ops = {.mount = mount,
|
||||
.umount = umount,
|
||||
.system = system,
|
||||
.is_mounted = cbm_is_mounted,
|
||||
.get_mountpoint_for_device =
|
||||
cbm_get_mountpoint_for_device };
|
||||
static CbmSystemOps default_system_ops = {
|
||||
.mount = mount,
|
||||
.umount = umount,
|
||||
.system = system,
|
||||
.is_mounted = cbm_is_mounted,
|
||||
.get_mountpoint_for_device = cbm_get_mountpoint_for_device,
|
||||
.devnode_to_devpath = cbm_devnode_to_devpath,
|
||||
};
|
||||
|
||||
/**
|
||||
* Pointer to the currently active vtable
|
||||
@@ -50,6 +71,7 @@ void cbm_system_set_vtable(CbmSystemOps *ops)
|
||||
assert(system_ops->is_mounted != NULL);
|
||||
assert(system_ops->get_mountpoint_for_device != NULL);
|
||||
assert(system_ops->system != NULL);
|
||||
assert(system_ops->devnode_to_devpath != NULL);
|
||||
}
|
||||
|
||||
int cbm_system_mount(const char *source, const char *target, const char *filesystemtype,
|
||||
@@ -78,6 +100,11 @@ char *cbm_system_get_mountpoint_for_device(const char *device)
|
||||
return system_ops->get_mountpoint_for_device(device);
|
||||
}
|
||||
|
||||
char *cbm_system_devnode_to_devpath(dev_t d)
|
||||
{
|
||||
return system_ops->devnode_to_devpath(d);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
* Defines the vtable used for all systen operations within clr-boot-manager.
|
||||
@@ -32,6 +33,9 @@ typedef struct CbmSystemOps {
|
||||
|
||||
/* exec family */
|
||||
int (*system)(const char *command);
|
||||
|
||||
/* dev utility */
|
||||
char *(*devnode_to_devpath)(dev_t t);
|
||||
} CbmSystemOps;
|
||||
|
||||
/**
|
||||
@@ -74,6 +78,11 @@ int cbm_system_umount(const char *target);
|
||||
*/
|
||||
int cbm_system_system(const char *command);
|
||||
|
||||
/**
|
||||
* Resolve the path for a given dev_t
|
||||
*/
|
||||
char *cbm_system_devnode_to_devpath(dev_t d);
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
|
||||
+11
-1
@@ -41,6 +41,15 @@ static inline char *test_get_mountpoint_for_device(__cbm_unused__ const char *de
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline char *test_devnode_to_devpath(__cbm_unused__ dev_t d)
|
||||
{
|
||||
char *a = NULL;
|
||||
if (asprintf(&a, "%s/dev/testRoot", TOP_BUILD_DIR "/tests/update_playground") < 0) {
|
||||
abort();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default vtable for testing. Copy into a local struct and override specific
|
||||
* fields.
|
||||
@@ -49,7 +58,8 @@ CbmSystemOps SystemTestOps = {.mount = test_mount,
|
||||
.umount = test_umount,
|
||||
.system = test_system,
|
||||
.is_mounted = test_is_mounted,
|
||||
.get_mountpoint_for_device = test_get_mountpoint_for_device };
|
||||
.get_mountpoint_for_device = test_get_mountpoint_for_device,
|
||||
.devnode_to_devpath = test_devnode_to_devpath };
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
|
||||
Reference in New Issue
Block a user