Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jdm-core/src/main/java/jdiskmark/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public static String getDriveModel(File dataDir) {

// handle whole-disk filesystem (no partition table) — pkname is empty
if (deviceNames.isEmpty()) {
return UtilOs.getVendorModelLinux(partition);
String vendorModel = UtilOs.getVendorModelLinux(partition);
return vendorModel != null ? vendorModel : ERROR_DRIVE_INFO;
}

// handle single physical drive
Expand Down
29 changes: 21 additions & 8 deletions jdm-core/src/main/java/jdiskmark/UtilOs.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public static String getDriveModelWindows(String driveLetter) {
* Get the storage bus interface for a Windows drive letter using
* PowerShell's Get-Partition / Get-Disk pipeline.
*
* <p>Returns the BusType string from {@code Get-Disk}, e.g.
* <p>Returns the BusType string from {@code Get-Disk}, e.g.

* {@code NVMe}, {@code SATA}, {@code USB}, {@code RAID}, {@code SAS}.
*
* @param driveLetter single drive letter (e.g. "C")
Expand Down Expand Up @@ -414,21 +415,27 @@ static public String getPartitionFromFilePathLinux(Path path) {
ProcessBuilder pb = new ProcessBuilder("df", "-k", path.toString());
Map<String, String> env = pb.environment();
env.put("LC_ALL", "C"); // set language to english
pb.redirectErrorStream(true);
Process process = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
String curPartition;
String curPartition = null;
while ((line = reader.readLine()) != null) {
if (App.verbose) {
System.out.println("curLine=" + line);
}
if (line.contains("/dev/")) {
curPartition = line.split(" ")[0];
return curPartition;
break;
}
}
} catch (IOException e) {
int exitCode = process.waitFor();
if (exitCode == 0 && curPartition != null) {
return curPartition;
}
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
LOGGER.log(Level.SEVERE, null, e);
}
return null;
Expand All @@ -449,7 +456,6 @@ static public List<String> getDeviceNamesFromPartitionLinux(String partition) {
ProcessBuilder pb = new ProcessBuilder("lsblk", "-no", "pkname", partition);
Map<String, String> env = pb.environment();
env.put("LC_ALL", "C"); // set language to english
pb.redirectErrorStream(true);
Process process = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
// detect multiple lines and if so indicate it is an LVM
Expand All @@ -459,10 +465,17 @@ static public List<String> getDeviceNamesFromPartitionLinux(String partition) {
System.err.println("devName=" + line);
}
if (!line.trim().isEmpty()) {
deviceNames.add(line);
deviceNames.add(line.trim());
}
}
} catch (IOException e) {
int exitCode = process.waitFor();
if (exitCode != 0) {
deviceNames.clear();
}
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
LOGGER.log(Level.SEVERE, null, e);
}
return deviceNames;
Expand Down
Loading