Browse Source

Added raid partition and disk size display

aroz 1 year ago
parent
commit
2ddf8cc9d1
2 changed files with 41 additions and 2 deletions
  1. 38 0
      mod/disk/raid/raidutils.go
  2. 3 2
      web/SystemAO/disk/raid/index.html

+ 38 - 0
mod/disk/raid/raidutils.go

@@ -1,11 +1,13 @@
 package raid
 
 import (
+	"bytes"
 	"errors"
 	"fmt"
 	"os"
 	"os/exec"
 	"path/filepath"
+	"strconv"
 	"strings"
 
 	"imuslab.com/arozos/mod/disk/diskfs"
@@ -215,3 +217,39 @@ func (m *Manager) RAIDArrayContainsFailedDisks(devicePath string) (bool, error)
 	}
 	return strings.Contains(raidDeviceInfo.State, "degraded") || strings.Contains(raidDeviceInfo.State, "faulty"), nil
 }
+
+// GetRAIDPartitionSize returns the size of the RAID partition in bytes as an int64
+func GetRAIDPartitionSize(devicePath string) (int64, error) {
+	// Ensure devicePath is formatted correctly
+	if !strings.HasPrefix(devicePath, "/dev/") {
+		devicePath = "/dev/" + devicePath
+	}
+
+	// Execute the df command with the device path
+	cmd := exec.Command("df", "--block-size=1", devicePath)
+	var out bytes.Buffer
+	cmd.Stdout = &out
+	if err := cmd.Run(); err != nil {
+		return 0, fmt.Errorf("failed to execute df command: %v", err)
+	}
+
+	// Parse the output to find the size
+	lines := strings.Split(out.String(), "\n")
+	if len(lines) < 2 {
+		return 0, fmt.Errorf("unexpected df output: %s", out.String())
+	}
+
+	// The second line should contain the relevant information
+	fields := strings.Fields(lines[1])
+	if len(fields) < 2 {
+		return 0, fmt.Errorf("unexpected df output: %s", lines[1])
+	}
+
+	// The second field should be the size in bytes
+	size, err := strconv.ParseInt(fields[1], 10, 64)
+	if err != nil {
+		return 0, fmt.Errorf("failed to parse size: %v", err)
+	}
+
+	return size, nil
+}

+ 3 - 2
web/SystemAO/disk/raid/index.html

@@ -680,7 +680,8 @@
                             let drivePath = thisDeviceInfo.DevicePath
                             let driveName = drivePath.split("/").pop();
                             let driveIcon = "drive-working.svg";
-                            let driveSize = "Unknown";
+                            let driveSize = "Unknown"; //Overall size of the disk
+                            let partitionSize = data.ArraySize * 1024; //RAID partition size, mdadm report in KiB
                             let driveRWState = "Read Write";
                             if (thisDeviceInfo.DevicePath = ""){
                                 driveIcon = "drive-notfound.svg"
@@ -731,7 +732,7 @@
                                     </div>
                                 </h4>
                                 <div class="capinfo">
-                                    ${driveSize}<br>
+                                    <i class="chart pie icon"></i>${bytesToSize(partitionSize)} | <i class="hdd outline icon"></i> ${driveSize}<br>
                                     <span style="font-size: 0.8em;">${driveRWState}</span>
                                 </div>
                                 <div class="raidDeviceOptions">