From 74caff0d5988b721c08b9a8e35bce79a3d167dd6 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sun, 3 Apr 2022 16:13:45 +0100 Subject: [PATCH] uvol: fixes and adapt to in-tree ucode Don't use features which are not yet present in the version of ucode currently shipped with OpenWrt (such as `fs.access()` or assuming raw mode by default). Fix syntax error in main executable. Signed-off-by: Daniel Golle --- utils/uvol/Makefile | 2 +- utils/uvol/files/blockdev_common.uc | 3 +++ utils/uvol/files/lvm.uc | 7 +++++-- utils/uvol/files/uvol | 10 +++------- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/utils/uvol/Makefile b/utils/uvol/Makefile index 410788df33..378faf1a1f 100644 --- a/utils/uvol/Makefile +++ b/utils/uvol/Makefile @@ -32,7 +32,7 @@ define Package/uvol endef define Package/uvol/description - 'uvol' is tool to automate storage volume handling on embedded + 'uvol' is a tool to automate storage volume handling on embedded devices in a generic way. Depending on what is available, 'uvol' will use either UBI or LVM2 as storage backends and transparently offer identical operations on diff --git a/utils/uvol/files/blockdev_common.uc b/utils/uvol/files/blockdev_common.uc index 8edf65bfe3..ac601e78c4 100644 --- a/utils/uvol/files/blockdev_common.uc +++ b/utils/uvol/files/blockdev_common.uc @@ -108,6 +108,9 @@ let get_bootdev = function(void) { // adapted from /lib/upgrade/common.sh let get_partition = function(dev, num) { + if (!dev) + return null; + for (let bd in get_blockdevs()) { let r = get_uevent_major_minor(sprintf("/sys/class/block/%s/uevent", bd)); if (r.major == dev.major && r.minor == dev.minor + num) { diff --git a/utils/uvol/files/lvm.uc b/utils/uvol/files/lvm.uc index d05701dc4a..36fb37c5fb 100644 --- a/utils/uvol/files/lvm.uc +++ b/utils/uvol/files/lvm.uc @@ -50,6 +50,9 @@ function pvs() { } include("/usr/lib/uvol/blockdev_common.uc"); let rootdev = blockdev_common.get_partition(blockdev_common.get_bootdev(), 0); + if (!rootdev) + return null; + let tmp = lvm("pvs", "-o", "vg_name", "-S", sprintf("\"pv_name=~^/dev/%s.*\$\"", rootdev)); if (tmp.report.pv) return tmp.report.pv[0].vg_name; @@ -112,8 +115,8 @@ function getdev(lv) { function lvm_init(ctx) { cursor = ctx.cursor; fs = ctx.fs; - if (!fs.access(lvm_exec, "x")) - return false; +// if (!fs.access(lvm_exec, "x")) +// return false; vg_name = pvs(); if (!vg_name) diff --git a/utils/uvol/files/uvol b/utils/uvol/files/uvol index 692606895f..6a5a82c138 100644 --- a/utils/uvol/files/uvol +++ b/utils/uvol/files/uvol @@ -1,4 +1,4 @@ -#!/usr/bin/ucode +#!/usr/bin/ucode -R // SPDX-License-Identifier: GPL-2.0-or-later // uvol - storage volume manager for OpenWrt // (c) 2022 Daniel Golle @@ -25,11 +25,7 @@ commands: 1 - volume is not ready for use 2 - volume doesn'y exist write volname size write to volume from stdin, size in bytes -" - -function help() { - printf("%s", help_output); -); +"; let fs = require("fs"); let uci = require("uci"); @@ -71,7 +67,7 @@ if (!backend) { let cmd = shift(ARGV); if (!cmd || cmd == "-h" || cmd == "help") { - help(); + printf("%s", help_output); return cmd?0:22; }