From b72fdd90e0cac1a7f6a7211fcab651984a7dc23b Mon Sep 17 00:00:00 2001 From: Mikei386 <44135113+Mikei386@users.noreply.github.com> Date: Sun, 11 Oct 2026 17:10:22 +0200 Subject: [PATCH] r030: convert Unraid disk KiB values to bytes at source boundary --- README.md | 4 ++-- docs/STORAGE-UNITS.md | 33 ++++++++++++++++++++++++++++ mcp/helpers.php | 2 +- mcp/server.php | 2 +- package.json | 2 +- plugin/mua.plg | 12 ++++++---- plugin/plugin.json | 2 +- scripts/test-storage-units.php | 20 +++++++++++++++++ scripts/unraid-mcp-status-helper.php | 9 +++++--- src/helpers.ts | 2 +- 10 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 docs/STORAGE-UNITS.md create mode 100644 scripts/test-storage-units.php diff --git a/README.md b/README.md index ed4c838..9bd40ee 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,10 @@ Oder manuell: ```bash # .txz von Gitea laden -curl -O https://git.casaderoll.de/michael/MUA-Mikes-Unraid-Agent/raw/branch/main/dist/mua-2026.09.21.r029-x86_64-1.txz +curl -O https://git.casaderoll.de/michael/MUA-Mikes-Unraid-Agent/raw/branch/main/dist/mua-2026.10.11.r030-x86_64-1.txz # Installieren -upgradepkg --install-new mua-2026.09.21.r029-x86_64-1.txz +upgradepkg --install-new mua-2026.10.11.r030-x86_64-1.txz ``` ### 2. Service starten diff --git a/docs/STORAGE-UNITS.md b/docs/STORAGE-UNITS.md new file mode 100644 index 0000000..468202f --- /dev/null +++ b/docs/STORAGE-UNITS.md @@ -0,0 +1,33 @@ +# Storage byte units — r030 (2026-10-11) + +`unraid_storage_status` calls `runStatusHelper("storage-status")`, which executes +`scripts/unraid-mcp-status-helper.php`. `storage_status()` reads +`/var/local/emhttp/disks.ini`; `selected_disk()` formerly copied KiB values into +fields labelled bytes. + +Only `fsSize` (fallback `size`), `fsUsed`, and `fsFree` are multiplied by 1024. +Unraid's installed `webGui/nchan/device_list` and `include/DiskList.php` likewise +multiply filesystem values by 1024. `df -k /mnt/disk1` independently reproduces +all three raw filesystem values. The fallback `size * 1024` matches blockdev. +The generic numeric parser, filesize byte outputs and memory processing are +unchanged. `/proc/meminfo` already receives one KiB-to-byte conversion. + +Observed on disk1 / /dev/md1p1: + +| Source | KiB | Bytes (independent host check) | +|---|---:|---:| +| fsSize | 7811938628 | 7999425155072 | +| fsUsed | 6683446380 | 6843849093120 | +| fsFree | 1128492248 | 1155576061952 | +| size (partition) | 7814025540 | 8001562152960 | + +Filesystem figures match `df -B1 /mnt/disk1`; partition capacity matches +`blockdev --getsize64 /dev/md1p1`. They measure different layers: filesystem +capacity is 2,136,997,888 bytes smaller than partition capacity. Preserve +filesystem capacity for consistency with filesystem used/free, rather than +forcing equality with raw block-device size. Used + free = filesystem capacity; +percentage is unchanged (85.6%). Cached emhttp data may lag current df during writes. + +Validation: 10 PHP storage regression checks on Unraid, including memory; +20 existing Bun security tests; TypeScript check; package build and XML validation. +Live MCP validation is recorded after installation. No storage or media changes. diff --git a/mcp/helpers.php b/mcp/helpers.php index a7e7f4a..0f4dd69 100644 --- a/mcp/helpers.php +++ b/mcp/helpers.php @@ -10,7 +10,7 @@ error_reporting(E_ALL); ini_set('display_errors', 0); // Fehler werden als JSON-RPC-Error zurückgegeben, nicht als HTML -const MUA_VERSION = '2026.09.21.r029'; +const MUA_VERSION = '2026.10.11.r030'; const MUA_SERVER_NAME = 'mua'; /** diff --git a/mcp/server.php b/mcp/server.php index 49856f2..6b40e25 100644 --- a/mcp/server.php +++ b/mcp/server.php @@ -21,7 +21,7 @@ const MUA_PORT = 3002; const MUA_BIND = '0.0.0.0'; const MUA_SESSION_TTL = 3600; // Sekunden const MUA_SERVER_NAME = 'mua'; -const MUA_VERSION = '2026.09.21.r029'; +const MUA_VERSION = '2026.10.11.r030'; // ── Session-Management (in-memory) ─────────────────────────────────────── $sessions = []; // session_id => ['created' => time, 'initialized' => bool] diff --git a/package.json b/package.json index a216b80..ea9536f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mua", - "version": "2026.09.21.r029", + "version": "2026.10.11.r030", "description": "Mikes Unraid Agent - MCP over HTTP (Streamable HTTP) for Unraid", "type": "module", "main": "src/index.ts", diff --git a/plugin/mua.plg b/plugin/mua.plg index da472ed..96ae12f 100644 --- a/plugin/mua.plg +++ b/plugin/mua.plg @@ -2,13 +2,13 @@ - + - - + + ]> +### 2026.10.11.r030 +- Konvertiert disks.ini-Kapazität, belegt und frei gezielt von KiB in Bytes. RAM und bereits bytebasierte Quellen bleiben unverändert. +- Regressionstest und Live-Abgleich mit df -B1 und blockdev dokumentiert. + ### 2026.09.21.r029 - Liest mehrzeilige URBM- und Unraid-Benachrichtigungen ohne PHP-Parserwarnungen. - Erhält Benachrichtigungstext wörtlich, ohne INI-Variablen auszuwerten; ergänzt Regressionstests. @@ -177,7 +181,7 @@ Das .txz enthält: install/doinst.sh (läuft nach Installation) =========================================== --> - + &txzURL; &txzSHA256; diff --git a/plugin/plugin.json b/plugin/plugin.json index 7f71c2e..39062e0 100644 --- a/plugin/plugin.json +++ b/plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "mua", "author": "Michael", - "version": "2026.09.21.r029", + "version": "2026.10.11.r030", "minver": "7.0.0", "pluginDirectory": "/usr/local/emhttp/plugins/mua", "configDirectory": "/boot/config/plugins/mua", diff --git a/scripts/test-storage-units.php b/scripts/test-storage-units.php new file mode 100644 index 0000000..a25ef1b --- /dev/null +++ b/scripts/test-storage-units.php @@ -0,0 +1,20 @@ +'7811938628','fsUsed'=>'6683446380','fsFree'=>'1128492248']); +check_units('filesystem bytes vs df -B1', 7999425155072, $d['size_bytes']); +check_units('used bytes vs df -B1', 6843849093120, $d['used_bytes']); +check_units('free bytes vs df -B1', 1155576061952, $d['free_bytes']); +check_units('consistent sum', $d['size_bytes'], $d['used_bytes']+$d['free_bytes']); +check_units('percentage unchanged', 85.6, $d['used_percent']); +check_units('fallback partition size in KiB', 8001562152960, selected_disk(['size'=>'7814025540'])['size_bytes']); +check_units('filesystem capacity preferred', 2048, selected_disk(['fsSize'=>'2','size'=>'4'])['size_bytes']); +check_units('missing fields', 0, selected_disk([])['size_bytes']); +check_units('generic numeric byte values untouched', 8001562152960, number_value('8001562152960')); +if (is_readable('/proc/meminfo')) { + preg_match('/^MemTotal:\s+(\d+)\s+kB/m', file_get_contents('/proc/meminfo'), $m); + check_units('RAM converted exactly once', (int)$m[1]*1024, system_health()['memory']['total_bytes']); +} diff --git a/scripts/unraid-mcp-status-helper.php b/scripts/unraid-mcp-status-helper.php index a693c79..d6de178 100644 --- a/scripts/unraid-mcp-status-helper.php +++ b/scripts/unraid-mcp-status-helper.php @@ -91,9 +91,12 @@ function system_health(): array { } function selected_disk(array $disk): array { - $size = number_value($disk['fsSize'] ?? $disk['size'] ?? 0); - $used = number_value($disk['fsUsed'] ?? 0); - $free = number_value($disk['fsFree'] ?? 0); + // emhttp disks.ini reports fsSize/fsUsed/fsFree and fallback size in KiB. + // Convert only these source fields; number_value and RAM/file byte values stay unchanged. + // fsSize is filesystem capacity, not the raw block-device capacity. + $size = number_value($disk['fsSize'] ?? $disk['size'] ?? 0) * 1024; + $used = number_value($disk['fsUsed'] ?? 0) * 1024; + $free = number_value($disk['fsFree'] ?? 0) * 1024; return [ 'name' => $disk['name'] ?? '', 'device' => $disk['device'] ?? '', diff --git a/src/helpers.ts b/src/helpers.ts index 6f1778a..2bbc08d 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -15,7 +15,7 @@ import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } // ── Konstanten ────────────────────────────────────────────────────────── export const MUA_SERVER_NAME = "mua"; -export const MUA_VERSION = "2026.09.21.r029"; +export const MUA_VERSION = "2026.10.11.r030"; export const MUA_PROTOCOL_VERSION = "2025-03-26"; export const PHP_HELPER = "/usr/local/bin/unraid-docker-mcp-helper.php"; export const STATUS_HELPER = "/usr/local/bin/unraid-mcp-status-helper.php";