CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-github-oshi--oshi-core

JNA-based operating system and hardware information library for Java providing cross-platform access to system metrics

Pending
Overview
Eval results
Files

file-system.mddocs/

File System Access

File system information, mount points, disk usage statistics, and file store details with comprehensive storage metrics.

FileSystem Interface

Interface providing access to file system information and mounted file stores.

interface FileSystem {
    List<OSFileStore> getFileStores();
    List<OSFileStore> getFileStores(boolean localOnly);
    long getOpenFileDescriptors();
    long getMaxFileDescriptors();
}

Methods

  • getFileStores() - Gets all mounted file stores
  • getFileStores(boolean localOnly) - Gets file stores, optionally filtering to local only
  • getOpenFileDescriptors() - Gets the current number of open file descriptors
  • getMaxFileDescriptors() - Gets the maximum number of file descriptors allowed

OSFileStore Interface

Represents a mounted file system or file store with detailed storage information.

interface OSFileStore {
    String getName();
    String getVolume();
    String getLabel();
    String getLogicalVolume();
    String getMount();
    String getDescription();
    String getType();
    String getOptions();
    String getUUID();
    long getFreeSpace();
    long getUsableSpace();
    long getTotalSpace();
    long getFreeInodes();
    long getTotalInodes();
    boolean updateAttributes();
}

Properties

  • getName() - Gets the file store name
  • getVolume() - Gets the volume name
  • getLabel() - Gets the volume label
  • getLogicalVolume() - Gets the logical volume name
  • getMount() - Gets the mount point path
  • getDescription() - Gets a description of the file store
  • getType() - Gets the file system type (e.g., "NTFS", "ext4", "HFS+")
  • getOptions() - Gets mount options as a string
  • getUUID() - Gets the unique identifier for the file store

Space Information

  • getFreeSpace() - Gets free space in bytes
  • getUsableSpace() - Gets usable space in bytes (may be less than free space due to reserved space)
  • getTotalSpace() - Gets total space in bytes
  • getFreeInodes() - Gets the number of free inodes
  • getTotalInodes() - Gets the total number of inodes

Methods

  • updateAttributes() - Updates the file store information and returns true if successful

Usage Examples

List All File Systems

import oshi.SystemInfo;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

List<OSFileStore> fileStores = fileSystem.getFileStores();

System.out.println("=== File Systems ===");
for (OSFileStore store : fileStores) {
    System.out.printf("Name: %s%n", store.getName());
    System.out.printf("  Mount: %s%n", store.getMount());
    System.out.printf("  Type: %s%n", store.getType());
    System.out.printf("  Total: %s%n", formatBytes(store.getTotalSpace()));
    System.out.printf("  Free: %s%n", formatBytes(store.getFreeSpace()));
    System.out.printf("  Usable: %s%n", formatBytes(store.getUsableSpace()));
    System.out.printf("  Usage: %.1f%%%n%n", 
        (store.getTotalSpace() - store.getFreeSpace()) * 100.0 / store.getTotalSpace());
}

private static String formatBytes(long bytes) {
    if (bytes < 1024) return bytes + " B";
    if (bytes < 1024 * 1024) return String.format("%.1f KB", bytes / 1024.0);
    if (bytes < 1024 * 1024 * 1024) return String.format("%.1f MB", bytes / 1024.0 / 1024.0);
    return String.format("%.1f GB", bytes / 1024.0 / 1024.0 / 1024.0);
}

Local File Systems Only

import oshi.SystemInfo;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

// Get only local file systems (excludes network mounts)
List<OSFileStore> localStores = fileSystem.getFileStores(true);

System.out.println("=== Local File Systems ===");
for (OSFileStore store : localStores) {
    System.out.printf("%-20s %-10s %s%n",
        store.getName(),
        store.getType(),
        store.getMount()
    );
}

Disk Usage Summary

import oshi.SystemInfo;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

List<OSFileStore> fileStores = fileSystem.getFileStores();

long totalSpace = 0;
long freeSpace = 0;
long usableSpace = 0;

System.out.println("=== Disk Usage Summary ===");
System.out.printf("%-30s %10s %10s %10s %8s%n", 
    "Mount Point", "Total", "Free", "Usable", "Used %");
System.out.println("-".repeat(70));

for (OSFileStore store : fileStores) {
    totalSpace += store.getTotalSpace();
    freeSpace += store.getFreeSpace();
    usableSpace += store.getUsableSpace();
    
    double usedPercent = (store.getTotalSpace() - store.getFreeSpace()) * 100.0 / store.getTotalSpace();
    
    System.out.printf("%-30s %10s %10s %10s %7.1f%%%n",
        store.getMount(),
        formatSize(store.getTotalSpace()),
        formatSize(store.getFreeSpace()),
        formatSize(store.getUsableSpace()),
        usedPercent
    );
}

System.out.println("-".repeat(70));
System.out.printf("%-30s %10s %10s %10s %7.1f%%%n",
    "TOTAL",
    formatSize(totalSpace),
    formatSize(freeSpace),
    formatSize(usableSpace),
    (totalSpace - freeSpace) * 100.0 / totalSpace
);

private static String formatSize(long bytes) {
    if (bytes < 1024L * 1024L * 1024L) {
        return String.format("%.1f MB", bytes / 1024.0 / 1024.0);
    } else if (bytes < 1024L * 1024L * 1024L * 1024L) {
        return String.format("%.1f GB", bytes / 1024.0 / 1024.0 / 1024.0);
    } else {
        return String.format("%.1f TB", bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0);
    }
}

Detailed File Store Information

import oshi.SystemInfo;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

List<OSFileStore> fileStores = fileSystem.getFileStores();

for (OSFileStore store : fileStores) {
    System.out.println("=== File Store Details ===");
    System.out.println("Name: " + store.getName());
    System.out.println("Volume: " + store.getVolume());
    System.out.println("Label: " + store.getLabel());
    System.out.println("Logical Volume: " + store.getLogicalVolume());
    System.out.println("Mount Point: " + store.getMount());
    System.out.println("Description: " + store.getDescription());
    System.out.println("File System Type: " + store.getType());
    System.out.println("Mount Options: " + store.getOptions());
    System.out.println("UUID: " + store.getUUID());
    
    System.out.println("\n--- Space Information ---");
    System.out.println("Total Space: " + formatBytes(store.getTotalSpace()));
    System.out.println("Free Space: " + formatBytes(store.getFreeSpace()));
    System.out.println("Usable Space: " + formatBytes(store.getUsableSpace()));
    System.out.println("Used Space: " + formatBytes(store.getTotalSpace() - store.getFreeSpace()));
    
    if (store.getTotalInodes() > 0) {
        System.out.println("\n--- Inode Information ---");
        System.out.println("Total Inodes: " + store.getTotalInodes());
        System.out.println("Free Inodes: " + store.getFreeInodes());
        System.out.println("Used Inodes: " + (store.getTotalInodes() - store.getFreeInodes()));
        System.out.printf("Inode Usage: %.1f%%%n", 
            (store.getTotalInodes() - store.getFreeInodes()) * 100.0 / store.getTotalInodes());
    }
    
    System.out.println();
}

File Descriptor Information

import oshi.SystemInfo;
import oshi.software.os.FileSystem;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

long openFDs = fileSystem.getOpenFileDescriptors();
long maxFDs = fileSystem.getMaxFileDescriptors();

System.out.println("=== File Descriptor Usage ===");
System.out.println("Open File Descriptors: " + openFDs);
System.out.println("Maximum File Descriptors: " + maxFDs);

if (maxFDs > 0) {
    double usage = openFDs * 100.0 / maxFDs;
    System.out.printf("File Descriptor Usage: %.1f%%%n", usage);
    
    if (usage > 80) {
        System.out.println("WARNING: High file descriptor usage!");
    }
}

Monitor File System Changes

import oshi.SystemInfo;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

// Monitor specific file system
String targetMount = "/"; // or "C:\\" on Windows

OSFileStore targetStore = null;
for (OSFileStore store : fileSystem.getFileStores()) {
    if (store.getMount().equals(targetMount)) {
        targetStore = store;
        break;
    }
}

if (targetStore != null) {
    System.out.println("Monitoring file system: " + targetStore.getMount());
    
    long initialFree = targetStore.getFreeSpace();
    System.out.println("Initial free space: " + formatBytes(initialFree));
    
    try {
        Thread.sleep(5000); // Wait 5 seconds
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    
    // Update and check again
    if (targetStore.updateAttributes()) {
        long currentFree = targetStore.getFreeSpace();
        long change = currentFree - initialFree;
        
        System.out.println("Current free space: " + formatBytes(currentFree));
        if (change != 0) {
            System.out.printf("Change: %s (%+d bytes)%n", 
                formatBytes(Math.abs(change)), change);
        } else {
            System.out.println("No change detected");
        }
    } else {
        System.out.println("Failed to update file store attributes");
    }
}

Find File Systems by Type

import oshi.SystemInfo;
import oshi.software.os.FileSystem;
import oshi.software.os.OSFileStore;

SystemInfo si = new SystemInfo();
FileSystem fileSystem = si.getOperatingSystem().getFileSystem();

List<OSFileStore> fileStores = fileSystem.getFileStores();

// Group by file system type
Map<String, List<OSFileStore>> storesByType = fileStores.stream()
    .collect(Collectors.groupingBy(OSFileStore::getType));

System.out.println("=== File Systems by Type ===");
for (Map.Entry<String, List<OSFileStore>> entry : storesByType.entrySet()) {
    String type = entry.getKey();
    List<OSFileStore> stores = entry.getValue();
    
    System.out.printf("%s (%d mount%s):%n", 
        type, stores.size(), stores.size() == 1 ? "" : "s");
    
    for (OSFileStore store : stores) {
        System.out.printf("  %-30s %s%n", store.getMount(), formatBytes(store.getTotalSpace()));
    }
    System.out.println();
}

Install with Tessl CLI

npx tessl i tessl/maven-com-github-oshi--oshi-core

docs

file-system.md

hardware.md

index.md

network.md

operating-system.md

process-management.md

system-info.md

tile.json