Commit 4edddbf0 authored by James's avatar James

- linux disk model via "df /data/path" & "lsblk /dev/path --output MODEL"

 - minor optimizations for powershell script (untested)
parent 937e4a58
......@@ -38,14 +38,11 @@ v0.3
v0.4e
- updated eclipselink to 2.6 allows auto schema update
- improved gui initialization
- windows hard disk model via powershell query
- windows disk model via powershell query
- linux disk model via "df /data/path" & "lsblk /dev/path --output MODEL"
desired features
- hard drive specs, ie. model
on linux: "hdparm -I /dev/sda"
https://www.cyberciti.biz/faq/linux-getting-scsi-ide-harddisk-information/
http://unix.stackexchange.com/questions/5085/how-to-see-disk-details-like-manufacturer-in-linux
- osx disk model
- hard disk capacity and drive letter (windows)
- auto clear disk cache linux
- auto clear disk cache windows
......@@ -13,15 +13,15 @@ Get-WmiObject Win32_DiskDrive | % {
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | % {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.DeviceID
DiskSize = $disk.Size
#Disk = $disk.DeviceID
#DiskSize = $disk.Size
DiskModel = $disk.Model
Partition = $partition.Name
RawSize = $partition.Size
#Partition = $partition.Name
#RawSize = $partition.Size
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
Size = $_.Size
FreeSpace = $_.FreeSpace
#VolumeName = $_.VolumeName
#Size = $_.Size
#FreeSpace = $_.FreeSpace
}
}
}
......
This diff is collapsed.
......@@ -3,6 +3,6 @@ build.xml.script.CRC32=86c27f78
build.xml.stylesheet.CRC32=28e38971@1.56.1.46
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=606a4144
nbproject/build-impl.xml.script.CRC32=02f0fa7d
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48
nbproject/build-impl.xml.data.CRC32=9b231352
nbproject/build-impl.xml.script.CRC32=799f92a1
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
......@@ -72,7 +72,7 @@ main.class=jdiskmark.App
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=JDK_1.8
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>jDiskMark</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>jDiskMark</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
......@@ -126,6 +126,7 @@ public class Util {
/**
* Get OS specific disk info based on the drive the path is mapped to.
*
* @param dataDir the data directory being used in the run.
* @return Disk info if available.
*/
......@@ -134,13 +135,16 @@ public class Util {
if (System.getProperty("os.name").contains("Linux")) {
// get disk info for linux
return "implementation pending";
String devicePath = Util.getDeviceFromPath(dataDirPath);
String deviceModel = Util.getDeviceModel(devicePath);
String deviceSize = Util.getDeviceSize(devicePath);
return deviceModel + " " + deviceSize;
} else if (System.getProperty("os.name").contains("Windows")) {
// get disk info for windows
String driveLetter = dataDirPath.getRoot().toFile().toString().split(":")[0];
return Util.getModelFromLetter(driveLetter);
}
return "unknown";
return "Pending OS support";
}
/**
......@@ -151,34 +155,114 @@ public class Util {
* @return Disk Drive Model description or empty string if not found.
*/
public static String getModelFromLetter(String driveLetter) {
try {
Process p = Runtime.getRuntime().exec("powershell -ExecutionPolicy ByPass -File disk-model.ps1");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
try {
Process p = Runtime.getRuntime().exec("powershell -ExecutionPolicy ByPass -File disk-model.ps1");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
String curDriveLetter = null;
String curDiskModel = null;
while (line != null) {
System.out.println(line);
if (line.trim().isEmpty()) {
if (curDriveLetter != null && curDiskModel != null &&
curDriveLetter.equalsIgnoreCase(driveLetter)) {
return curDiskModel;
}
}
if (line.contains("DriveLetter : ")) {
curDriveLetter = line.split(" : ")[1].substring(0, 1);
System.out.println("current letter=" + curDriveLetter);
String curDriveLetter = null;
String curDiskModel = null;
while (line != null) {
System.out.println(line);
if (line.trim().isEmpty()) {
if (curDriveLetter != null && curDiskModel != null &&
curDriveLetter.equalsIgnoreCase(driveLetter)) {
return curDiskModel;
}
if (line.contains("DiskModel : ")) {
curDiskModel = line.split(" : ")[1];
System.out.println("current model="+curDiskModel);
}
if (line.contains("DriveLetter : ")) {
curDriveLetter = line.split(" : ")[1].substring(0, 1);
System.out.println("current letter=" + curDriveLetter);
}
if (line.contains("DiskModel : ")) {
curDiskModel = line.split(" : ")[1];
System.out.println("current model="+curDiskModel);
}
line = reader.readLine();
}
}
catch(IOException | InterruptedException e) {}
return null;
}
/**
* On Linux OS get the device path when given a file path.
* eg. filePath = /home/james/Desktop/jDiskMarkData
* devicePath = /dev/sda
*
* @param path the file path
* @return the device path
*/
static public String getDeviceFromPath(Path path) {
try {
Process p = Runtime.getRuntime().exec("df "+path.toString());
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
String curDevice;
while (line != null) {
//System.out.println(line);
if (line.contains("/dev/")) {
curDevice = line.split(" ")[0];
// strip the partition digit if it is numeric
if (curDevice.substring(curDevice.length()-1).matches("[0-9]{1}")) {
curDevice = curDevice.substring(0,curDevice.length()-1);
}
line = reader.readLine();
return curDevice;
}
line = reader.readLine();
}
} catch(IOException | InterruptedException e) {}
return null;
}
/**
* On Linux OS use the lsblk command to get the disk model number for a
* specific Device ie. /dev/sda
*
* @param devicePath path of the device
* @return the disk model number
*/
static public String getDeviceModel(String devicePath) {
try {
Process p = Runtime.getRuntime().exec("lsblk "+devicePath+" --output MODEL");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
//System.out.println(line);
if (!line.equals("MODEL") && !line.trim().isEmpty()) {
return line;
}
line = reader.readLine();
}
} catch(IOException | InterruptedException e) {}
return null;
}
/**
* On Linux OS use the lsblk command to get the disk size for a
* specific Device ie. /dev/sda
*
* @param devicePath path of the device
* @return the size of the device
*/
static public String getDeviceSize(String devicePath) {
try {
Process p = Runtime.getRuntime().exec("lsblk "+devicePath+" --output SIZE");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
//System.out.println(line);
if (!line.contains("SIZE") && !line.trim().isEmpty()) {
return line;
}
line = reader.readLine();
}
catch(IOException | InterruptedException e) {}
return "";
} catch(IOException | InterruptedException e) {}
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment