diff options
author | Daniel Golle <daniel@makrotopia.org> | 2023-02-15 04:04:12 +0000 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2023-02-15 04:06:36 +0000 |
commit | 3d86716b4f83aa827e0b28ba6d27a9c71855eb96 (patch) | |
tree | e7c0b60dfb96ca85c28072eebc9c6f61d9aa54d4 /utils/uvol | |
parent | 7aa180412c8b422f7ecb9fde1e46f3cdb0e9f48b (diff) |
uvol: switch to /sys/class/ubi
Instead of /sys/devices/virtual/ubi which will no longer be available
in future kernels, switch to /sys/class/ubi.
While at it fix unrelated arithmetic syntax error by guarding the
affected expression to not run on an empty string.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'utils/uvol')
-rw-r--r-- | utils/uvol/Makefile | 2 | ||||
-rw-r--r-- | utils/uvol/files/ubi.uc | 30 | ||||
-rw-r--r-- | utils/uvol/files/uvol.defaults | 4 |
3 files changed, 21 insertions, 15 deletions
diff --git a/utils/uvol/Makefile b/utils/uvol/Makefile index 256dbfbd1..1524fc16f 100644 --- a/utils/uvol/Makefile +++ b/utils/uvol/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=uvol PKG_VERSION:=0.9 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org> PKG_LICENSE:=GPL-2.0-or-later diff --git a/utils/uvol/files/ubi.uc b/utils/uvol/files/ubi.uc index 7d0872b16..8b46112c7 100644 --- a/utils/uvol/files/ubi.uc +++ b/utils/uvol/files/ubi.uc @@ -29,7 +29,7 @@ function mkdtemp() { function ubi_get_dev(vol_name) { let wcstring = sprintf("uvol-[rw][owpd]-%s", vol_name); - for (vol_dir in fs.glob(sprintf("/sys/devices/virtual/ubi/%s/%s_*", ubidev, ubidev))) { + for (vol_dir in fs.glob(sprintf("/sys/class/ubi/%s_*", ubidev))) { let vol_ubiname = read_file(sprintf("%s/name", vol_dir)); if (wildcard(vol_ubiname, wcstring)) return fs.basename(vol_dir); @@ -38,7 +38,7 @@ function ubi_get_dev(vol_name) { } function vol_get_mode(vol_dev, mode) { - let vol_name = read_file(sprintf("/sys/devices/virtual/ubi/%s/%s/name", ubidev, vol_dev)); + let vol_name = read_file(sprintf("/sys/class/ubi/%s/name", vol_dev)); return substr(vol_name, 5, 2); } @@ -57,19 +57,23 @@ function block_hotplug(action, devname) { function ubi_init(ctx) { cursor = ctx.cursor; fs = ctx.fs; + ubidev = null; let ubiver = read_file("/sys/class/ubi/version"); if (ubiver != 1) return false; - let ubidevpath = null; - for (ubidevpath in fs.glob("/sys/devices/virtual/ubi/*")) + for (ubidevpath in fs.glob("/sys/class/ubi/*")) { + if (!fs.stat(sprintf("%s/eraseblock_size", ubidevpath))) + continue; + + ubidev = fs.basename(ubidevpath); break; + } - if (!ubidevpath) + if (!ubidev) return false; - ubidev = fs.basename(ubidevpath); ebsize = read_file(sprintf("%s/eraseblock_size", ubidevpath)); uvol_uci_add = ctx.uci_add; @@ -81,7 +85,7 @@ function ubi_init(ctx) { } function ubi_free() { - let availeb = read_file(sprintf("/sys/devices/virtual/ubi/%s/avail_eraseblocks", ubidev)); + let availeb = read_file(sprintf("/sys/class/ubi/%s/avail_eraseblocks", ubidev)); return sprintf("%d", availeb * ebsize); } @@ -90,7 +94,7 @@ function ubi_align() { } function ubi_total() { - let totaleb = read_file(sprintf("/sys/devices/virtual/ubi/%s/total_eraseblocks", ubidev)); + let totaleb = read_file(sprintf("/sys/class/ubi/%s/total_eraseblocks", ubidev)); return sprintf("%d", totaleb * ebsize); } @@ -114,7 +118,7 @@ function ubi_size(vol_name) { if (!vol_dev) return 2; - let vol_size = read_file(sprintf("/sys/devices/virtual/ubi/%s/%s/data_bytes", ubidev, vol_dev)); + let vol_size = read_file(sprintf("/sys/class/ubi/%s/data_bytes", vol_dev)); return sprintf("%d", vol_size); } @@ -255,7 +259,7 @@ function ubi_down(vol_name) { function ubi_list(search_name) { let volumes = []; - for (vol_dir in fs.glob(sprintf("/sys/devices/virtual/ubi/%s/%s_*", ubidev, ubidev))) { + for (vol_dir in fs.glob(sprintf("/sys/class/ubi/%s_*", ubidev))) { let vol = {}; let vol_ubiname = read_file(sprintf("%s/name", vol_dir)); if (!wildcard(vol_ubiname, "uvol-[rw][wod]-*")) @@ -277,7 +281,7 @@ function ubi_list(search_name) { function ubi_detect() { let tmpdev = []; - for (vol_dir in fs.glob(sprintf("/sys/devices/virtual/ubi/%s/%s_*", ubidev, ubidev))) { + for (vol_dir in fs.glob(sprintf("/sys/class/ubi/%s_*", ubidev))) { let vol_ubiname = read_file(sprintf("%s/name", vol_dir)); if (!wildcard(vol_ubiname, "uvol-r[od]-*")) @@ -297,7 +301,7 @@ function ubi_detect() { uvol_uci_init(); - for (vol_dir in fs.glob(sprintf("/sys/devices/virtual/ubi/%s/%s_*", ubidev, ubidev))) { + for (vol_dir in fs.glob(sprintf("/sys/class/ubi/%s_*", ubidev))) { let vol_ubiname = read_file(sprintf("%s/name", vol_dir)); if (!wildcard(vol_ubiname, "uvol-[rw][wod]-*")) continue; @@ -321,7 +325,7 @@ function ubi_detect() { } function ubi_boot() { - for (vol_dir in fs.glob(sprintf("/sys/devices/virtual/ubi/%s/%s_*", ubidev, ubidev))) { + for (vol_dir in fs.glob(sprintf("/sys/class/ubi/%s_*", ubidev))) { let vol_dev = fs.basename(vol_dir); let vol_ubiname = read_file(sprintf("%s/name", vol_dir)); diff --git a/utils/uvol/files/uvol.defaults b/utils/uvol/files/uvol.defaults index 43c971154..927f8c115 100644 --- a/utils/uvol/files/uvol.defaults +++ b/utils/uvol/files/uvol.defaults @@ -4,7 +4,9 @@ uvol_init() { local metasz freesz totalsz uvol detect metasz="$(uvol size .meta 2>/dev/null)" - [ "$((metasz))" -gt 0 ] && return + if [ "$metasz" ]; then + [ "$((metasz))" -gt 0 ] && return + fi totalsz="$(uvol total)" freesz="$(uvol free)" metasz="$((totalsz / 10240))" |