Skip to content

Commit d9dc368

Browse files
committed
Changes to getInterfaceType getMotherBoardName and getPartitionId
Signed-off-by: Avinash Niyas <avinashNiyaz1423@gmail.com>
1 parent d5d06c8 commit d9dc368

3 files changed

Lines changed: 115 additions & 14 deletions

File tree

src/jdiskmark/App.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,17 +674,17 @@ static public String getDriveInfo() {
674674
if (locationDir == null) {
675675
return LOCATION_NOT_SELECTED_ERROR;
676676
}
677-
String interFaceType=Util.getInterfaceType();
678677
String driveModel = Util.getDriveModel(locationDir);
679678
String partitionId = Util.getPartitionId(locationDir.toPath());
679+
String interFaceType=Util.getInterfaceType(partitionId);
680680
DiskUsageInfo usageInfo;
681681
try {
682682
usageInfo = Util.getDiskUsage(locationDir.toString());
683683
} catch (IOException | InterruptedException ex) {
684684
usageInfo = new DiskUsageInfo();
685685
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
686686
}
687-
return interFaceType + " - " + driveModel + " - " + partitionId + ": " + usageInfo.getUsageTitleDisplay();
687+
return driveModel + " - " + interFaceType + " - " + partitionId + ": " + usageInfo.getUsageTitleDisplay();
688688
}
689689

690690
static public String getDriveModel() {

src/jdiskmark/MainFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public MainFrame() {
7272
}
7373

7474
if (App.motherBoardName != null && !App.motherBoardName.isEmpty()) {
75-
titleSb.append(" | ").append(App.motherBoardName);
75+
titleSb.append(" - ").append(App.motherBoardName);
7676
}
7777

7878
// permission indicator

src/jdiskmark/Util.java

Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,29 @@ public static DiskUsageInfo getDiskUsage(String diskPath) throws IOException, In
245245
}
246246

247247
public static String getPartitionId(Path path) {
248-
if (System.getProperty("os.name").startsWith("Windows")) {
249-
String driveLetter = UtilOs.getDriveLetterWindows(path);
250-
return driveLetter;
251-
} else {
248+
249+
String os=System.getProperty("os.name");
250+
251+
if (os.startsWith("Windows")) {
252+
return UtilOs.getDriveLetterWindows(path);
253+
}
254+
if (os.startsWith("Mac")) {
255+
String partitionPath=UtilOs.getDeviceFromPathMacOs(path);
256+
if(partitionPath.startsWith("/dev/")){
257+
return partitionPath.substring("/dev/".length());
258+
}
259+
return partitionPath;
260+
}
261+
262+
else if (os.startsWith("Linux")) {
252263
String partitionPath = UtilOs.getPartitionFromFilePathLinux(path);
253264
if (partitionPath.contains("/dev/")) {
254265
return partitionPath.split("/dev/")[1];
255266
}
256267
return partitionPath;
257268
}
269+
270+
return "Os Not Found";
258271
}
259272

260273
public static String getJvmInfo() {
@@ -276,6 +289,39 @@ public static String getProcessorName() {
276289
return "processor name unknown";
277290
}
278291

292+
/**
293+
* Get the motherboard / baseboard name of the current system.
294+
*
295+
* This method executes OS-specific system commands to retrieve
296+
* motherboard identification information.
297+
*
298+
* Commands used:
299+
*
300+
* Windows:
301+
* wmic baseboard get Product
302+
*
303+
* Example output:
304+
* Product
305+
* B450M PRO-VDH MAX
306+
*
307+
* Linux:
308+
* cat /sys/devices/virtual/dmi/id/board_name
309+
*
310+
* Example output:
311+
* B450M PRO-VDH MAX
312+
*
313+
* macOS:
314+
* system_profiler SPHardwareDataType
315+
*
316+
* Example output snippet:
317+
* Model Identifier: MacBookPro15,2
318+
*
319+
* Note:
320+
* - macOS does not expose a direct motherboard name.
321+
* - For macOS, the "Model Identifier" is returned instead.
322+
*
323+
* @return motherboard name as a String, or null if unavailable
324+
*/
279325
public static String getMotherBoardName() {
280326

281327
Process process = null;
@@ -304,6 +350,16 @@ public static String getMotherBoardName() {
304350
String line;
305351

306352
while ((line = reader.readLine()) != null) {
353+
354+
line=line.trim();
355+
356+
// If OS is mac return Model Identifier as MotherBoard name is not explicitly provided
357+
if (line.startsWith("Model Identifier:")) {
358+
359+
return line.split(":",2)[1].trim();
360+
}
361+
362+
if (line.equalsIgnoreCase("Product")) { continue;}
307363
builder.append(line).append(" ");
308364
}
309365

@@ -316,16 +372,54 @@ public static String getMotherBoardName() {
316372
}
317373
}
318374

319-
public static String getInterfaceType(){
375+
/**
376+
* Get the physical interface (bus / transport) type of a disk or partition.
377+
*
378+
* This method determines the underlying storage interface (e.g. SATA, NVMe,
379+
* USB) by executing OS-specific system commands and parsing their output.
380+
*
381+
* Commands used:
382+
*
383+
* Windows:
384+
* powershell -Command
385+
* Get-Partition -DriveLetter <partitionId> | Get-Disk | Select -Expand BusType
386+
*
387+
* Example output:
388+
* SATA
389+
* NVMe
390+
* USB
391+
*
392+
* Linux:
393+
* lsblk -d -o TRAN /dev/<partitionId>
394+
*
395+
* Example output:
396+
* TRAN
397+
* sata
398+
*
399+
* macOS:
400+
* diskutil info <partitionId>
401+
*
402+
* Example output snippet:
403+
* Protocol: SATA
404+
*
405+
* Notes:
406+
* - On Windows, the BusType field is returned.
407+
* - On Linux, the TRAN (transport) column is used.
408+
* - On macOS, the interface type is parsed from the "Protocol" field.
409+
*
410+
* @param partitionId drive letter (Windows) or device identifier (Linux/macOS)
411+
* @return interface type as a String, or "OS not supported" if unavailable
412+
*/
413+
public static String getInterfaceType(String partitionId){
320414
Process process = null;
321415

322416
try {
323417
if (App.os.startsWith("Windows")) {
324-
process = new ProcessBuilder("wmic", "diskdrive", "get", "InterfaceType").start();
418+
process = new ProcessBuilder( "powershell", "-Command", "Get-Partition -DriveLetter " + partitionId + " | Get-Disk | Select -Expand BusType").start();
325419
} else if (App.os.contains("Linux")) {
326-
process = new ProcessBuilder("lsblk", "-d", "-o", "tran").start();
420+
process = new ProcessBuilder("lsblk", "-d", "-o", "TRAN", "/dev/" + partitionId).start();
327421
} else if (App.os.startsWith("Mac OS")) {
328-
process = new ProcessBuilder("diskutil", "info", "disk0").start();
422+
process = new ProcessBuilder("diskutil", "info", partitionId).start();
329423
}
330424
} catch (IOException e) {
331425
Logger.getLogger(Util.class.getName())
@@ -342,13 +436,20 @@ public static String getInterfaceType(){
342436

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

345-
line=line.trim();
439+
line = line.trim();
440+
441+
if (line.isEmpty()) { continue;}
346442

347-
if(line.isEmpty()) { continue;}
443+
if (line.equalsIgnoreCase("InterfaceType") || line.equalsIgnoreCase("TRAN")|| line.equalsIgnoreCase("NAME")) { continue;}
348444

349-
if(line.equalsIgnoreCase("InterfaceType") || line.equalsIgnoreCase("TRAN")|| line.equalsIgnoreCase("NAME")) { continue;}
445+
// In case of MacOs parse the output for interface type
446+
if (line.startsWith("Protocol:")) {
447+
448+
return line.split(":",2)[1].trim();
449+
}
350450

351451
return line;
452+
352453
}
353454

354455
} catch (IOException e) {

0 commit comments

Comments
 (0)