plugmate-storage-free-space-check-10.ino

TrustKernel PlugMate : Secure Miniature USB-C Computer running PlugOS · File : plugmate-storage-free-space-check-10.ino · Language : python · Use case : Vérifier l'espace de stockage disponible sur la partition eMMC chiffrée du PlugMate.

Host-side Python script that queries the PlugMate via ADB to monitor free space on the encrypted eMMC storage.

Requires Python 3 and ADB installed on the host machine. The PlugMate must be connected and unlocked. The script uses Android's standard df command to read the /data partition. This helps prevent write errors due to saturated encrypted eMMC.

plugmate-storage-free-space-check-10.ino

import os
import subprocess
import sys

def check_storage():
    try:
        # Utilise df pour vérifier l'espace sur /data (partition principale utilisateur sur Android)
        # -h : format humain, /data : chemin standard sur Android/PlugOS
        result = subprocess.run(
            ['adb', 'shell', 'df', '-h', '/data'],
            capture_output=True,
            text=True,
            check=True
        )
        lines = result.stdout.splitlines()
        if len(lines) < 2:
            print("Erreur : Impossible de lire la sortie de df.")
            return

        header = lines[0].split()
        data_row = lines[1].split()
        
        # Extraire l'utilisation (ex: 45%)
        use_idx = header.index('Use%') if 'Use%' in header else 4
        use_percent = data_row[use_idx]
        
        print(f"PlugMate Storage Status:")
        print(f"Partition : /data (eMMC chiffré)")
        print(f"Utilisation : {use_percent}")
        print(f"Détails : {data_row}")
        
        # Alerte si plus de 90%
        val = int(use_percent.strip('%'))
        if val > 90:
            print("ALERTE : Espace disque critique (<10% restant).")
            sys.exit(1)
            
    except subprocess.CalledProcessError as e:
        print(f"Erreur ADB : {e.stderr}")
        sys.exit(1)
    except Exception as e:
        print(f"Erreur inattendue : {e}")
        sys.exit(1)

if __name__ == "__main__":
    check_storage()

← Back to the board