Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/jdiskmark/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public String toString() {
public static String os;
public static String arch;
public static String processorName;
public static String motherBoardName;
public static String jdk;
// elevated priviledges
public static boolean isRoot = false;
Expand Down Expand Up @@ -200,6 +201,7 @@ public static void init() {
os = System.getProperty("os.name");
arch = System.getProperty("os.arch");
processorName = Util.getProcessorName();
motherBoardName=Util.getMotherBoardName();
jdk = Util.getJvmInfo();

checkPermission();
Expand Down Expand Up @@ -674,14 +676,15 @@ static public String getDriveInfo() {
}
String driveModel = Util.getDriveModel(locationDir);
String partitionId = Util.getPartitionId(locationDir.toPath());
String interFaceType=Util.getInterfaceType(partitionId);
DiskUsageInfo usageInfo;
try {
usageInfo = Util.getDiskUsage(locationDir.toString());
} catch (IOException | InterruptedException ex) {
usageInfo = new DiskUsageInfo();
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
return driveModel + " - " + partitionId + ": " + usageInfo.getUsageTitleDisplay();
return driveModel + " - " + interFaceType + " - " + partitionId + ": " + usageInfo.getUsageTitleDisplay();
}

static public String getDriveModel() {
Expand Down
4 changes: 4 additions & 0 deletions src/jdiskmark/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public MainFrame() {
if (App.processorName != null && !App.processorName.isEmpty()) {
titleSb.append(" - ").append(App.processorName);
}

if (App.motherBoardName != null && !App.motherBoardName.isEmpty()) {
titleSb.append(" - ").append(App.motherBoardName);
}

// permission indicator
if (App.isAdmin) titleSb.append(" [Admin]");
Expand Down
198 changes: 193 additions & 5 deletions src/jdiskmark/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.filechooser.FileSystemView;

/**
Expand Down Expand Up @@ -49,7 +51,7 @@ static public boolean deleteDirectory(File path) {
* @param min Minimum value
* @param max Maximum value. Must be greater than min.
* @return Integer between min and max, inclusive.
* @see java.util.Random#nextInt(int)
* @see Random#nextInt(int)
*/
public static int randInt(int min, int max) {

Expand Down Expand Up @@ -243,16 +245,29 @@ public static DiskUsageInfo getDiskUsage(String diskPath) throws IOException, In
}

public static String getPartitionId(Path path) {
if (System.getProperty("os.name").startsWith("Windows")) {
String driveLetter = UtilOs.getDriveLetterWindows(path);
return driveLetter;
} else {

String os=System.getProperty("os.name");

if (os.startsWith("Windows")) {
return UtilOs.getDriveLetterWindows(path);
}
if (os.startsWith("Mac")) {
String partitionPath=UtilOs.getDeviceFromPathMacOs(path);
if(partitionPath.startsWith("/dev/")){
return partitionPath.substring("/dev/".length());
}
return partitionPath;
}

else if (os.startsWith("Linux")) {
String partitionPath = UtilOs.getPartitionFromFilePathLinux(path);
if (partitionPath.contains("/dev/")) {
return partitionPath.split("/dev/")[1];
}
return partitionPath;
}

return "Os Not Found";
}

public static String getJvmInfo() {
Expand All @@ -273,4 +288,177 @@ public static String getProcessorName() {
}
return "processor name unknown";
}

/**
* Get the motherboard / baseboard name of the current system.
*
* This method executes OS-specific system commands to retrieve
* motherboard identification information.
*
* Commands used:
*
* Windows:
* wmic baseboard get Product
*
* Example output:
* Product
* B450M PRO-VDH MAX
*
* Linux:
* cat /sys/devices/virtual/dmi/id/board_name
*
* Example output:
* B450M PRO-VDH MAX
*
* macOS:
* system_profiler SPHardwareDataType
*
* Example output snippet:
* Model Identifier: MacBookPro15,2
*
* Note:
* - macOS does not expose a direct motherboard name.
* - For macOS, the "Model Identifier" is returned instead.
*
* @return motherboard name as a String, or null if unavailable
*/
public static String getMotherBoardName() {

Process process = null;

try {
if (App.os.startsWith("Windows")) {
process = new ProcessBuilder("wmic", "baseboard", "get", "Product").start();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i got this

image

} else if (App.os.contains("Linux")) {
process = new ProcessBuilder("cat", "/sys/devices/virtual/dmi/id/board_name").start();
} else if (App.os.startsWith("Mac OS")) {
process = new ProcessBuilder("system_profiler", "SPHardwareDataType").start();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i got this

image

}
} catch (IOException e) {
Logger.getLogger(Util.class.getName())
.log(Level.FINE, "Unable to get Motherboard Name", e);
return null;
}

// If no command was set (unsupported OS)
if (process == null) { return null; }

try (BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {

StringBuilder builder = new StringBuilder();
String line;

while ((line = reader.readLine()) != null) {

line=line.trim();

// If OS is mac return Model Identifier as MotherBoard name is not explicitly provided
if (line.startsWith("Model Identifier:")) {

return line.split(":",2)[1].trim();
}

if (line.equalsIgnoreCase("Product")) { continue;}
builder.append(line).append(" ");
}

return builder.toString().trim();

} catch (IOException e) {
Logger.getLogger(Util.class.getName())
.log(Level.FINE, "Unable to read Motherboard Name", e);
return null;
}
}

/**
* Get the physical interface (bus / transport) type of a disk or partition.
*
* This method determines the underlying storage interface (e.g. SATA, NVMe,
* USB) by executing OS-specific system commands and parsing their output.
*
* Commands used:
*
* Windows:
* powershell -Command
* Get-Partition -DriveLetter <partitionId> | Get-Disk | Select -Expand BusType
*
* Example output:
* SATA
* NVMe
* USB
*
* Linux:
* lsblk -d -o TRAN /dev/<partitionId>
*
* Example output:
* TRAN
* sata
*
* macOS:
* diskutil info <partitionId>
*
* Example output snippet:
* Protocol: SATA
*
* Notes:
* - On Windows, the BusType field is returned.
* - On Linux, the TRAN (transport) column is used.
* - On macOS, the interface type is parsed from the "Protocol" field.
*
* @param partitionId drive letter (Windows) or device identifier (Linux/macOS)
* @return interface type as a String, or "OS not supported" if unavailable
*/
public static String getInterfaceType(String partitionId){
Process process = null;

try {
if (App.os.startsWith("Windows")) {
process = new ProcessBuilder( "powershell", "-Command", "Get-Partition -DriveLetter " + partitionId + " | Get-Disk | Select -Expand BusType").start();
} else if (App.os.contains("Linux")) {
process = new ProcessBuilder("lsblk", "-d", "-o", "TRAN", "/dev/" + partitionId).start();
} else if (App.os.startsWith("Mac OS")) {
process = new ProcessBuilder("diskutil", "info", partitionId).start();
}
} catch (IOException e) {
Logger.getLogger(Util.class.getName())
.log(Level.FINE, "Unable to get Interface Type", e);
return "OS not supported";
}

if (process == null) { return "OS not supported"; }

try (BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {

String line;

while ((line = reader.readLine()) != null) {

line = line.trim();

if (line.isEmpty()) { continue;}

if (line.equalsIgnoreCase("InterfaceType") || line.equalsIgnoreCase("TRAN")|| line.equalsIgnoreCase("NAME")) { continue;}

// In case of MacOs parse the output for interface type
if (line.startsWith("Protocol:")) {

return line.split(":",2)[1].trim();
}

return line;

}

} catch (IOException e) {
Logger.getLogger(Util.class.getName())
.log(Level.FINE, "Unable to read Interface Type", e);
return "OS not supported";
}

return "OS not supported";
}

}