From b120ad2c4515e1dcc5214f125274a85fefd367bd Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 11 Feb 2021 19:11:09 +0100 Subject: [PATCH] diskLayout() added USB drives (mac OS) --- CHANGELOG.md | 1 + docs/history.html | 5 + docs/index.html | 4 +- lib/filesystem.js | 309 ++++++++++++++++++++++++---------------------- 4 files changed, 169 insertions(+), 150 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ec74de..fc531ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 5.2.3 | 2020-02-11 | `diskLayout()` added USB drives (mac OS) | | 5.2.2 | 2020-02-11 | code cleanup, updated docs | | 5.2.1 | 2020-02-10 | `system()` fixed issue virtual detect (linux) | | 5.2.0 | 2020-02-10 | `wifiInterfces()` and `wifiConnections()` added | diff --git a/docs/history.html b/docs/history.html index eb3a317..31ea1e0 100644 --- a/docs/history.html +++ b/docs/history.html @@ -56,6 +56,11 @@ + + 5.2.3 + 2020-02-11 + diskLayout() added USB drives (mac OS) + 5.2.2 2020-02-11 diff --git a/docs/index.html b/docs/index.html index d291284..83bc91f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.2.2
+
New Version: 5.2.3
@@ -201,7 +201,7 @@
-
13,682
+
13,752
Lines of code
diff --git a/lib/filesystem.js b/lib/filesystem.js index 99a7321..b19d535 100755 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -929,157 +929,178 @@ function diskLayout(callback) { else if (dataType === 'NVMe') { linesNVMe.push(line); } else if (dataType === 'USB') { linesUSB.push(line); } }); - // Serial ATA Drives - let devices = linesSATA.join('\n').split(' Physical Interconnect: '); - devices.shift(); - devices.forEach(function (device) { - device = 'InterfaceType: ' + device; - let lines = device.split('\n'); - const mediumType = util.getValue(lines, 'Medium Type', ':', true).trim(); - const sizeStr = util.getValue(lines, 'capacity', ':', true).trim(); - const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim(); - if (sizeStr) { - let sizeValue = 0; - if (sizeStr.indexOf('(') >= 0) { - sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '')); + try { + // Serial ATA Drives + let devices = linesSATA.join('\n').split(' Physical Interconnect: '); + devices.shift(); + devices.forEach(function (device) { + device = 'InterfaceType: ' + device; + let lines = device.split('\n'); + const mediumType = util.getValue(lines, 'Medium Type', ':', true).trim(); + const sizeStr = util.getValue(lines, 'capacity', ':', true).trim(); + const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim(); + if (sizeStr) { + let sizeValue = 0; + if (sizeStr.indexOf('(') >= 0) { + sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '')); + } + if (!sizeValue) { + sizeValue = parseInt(sizeStr); + } + if (sizeValue) { + const smartStatusString = util.getValue(lines, 'S.M.A.R.T. status', ':', true).trim().toLowerCase(); + result.push({ + device: BSDName, + type: mediumType.startsWith('Solid') ? 'SSD' : 'HD', + name: util.getValue(lines, 'Model', ':', true).trim(), + vendor: getVendorFromModel(util.getValue(lines, 'Model', ':', true).trim()) || util.getValue(lines, 'Manufacturer', ':', true), + size: sizeValue, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(), + serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(), + interfaceType: util.getValue(lines, 'InterfaceType', ':', true).trim(), + smartStatus: smartStatusString === 'verified' ? 'OK' : smartStatusString || 'unknown', + temperature: null, + BSDName: BSDName + }); + cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;'; + } } - if (!sizeValue) { - sizeValue = parseInt(sizeStr); - } - if (sizeValue) { - const smartStatusString = util.getValue(lines, 'S.M.A.R.T. status', ':', true).trim().toLowerCase(); - result.push({ - device: BSDName, - type: mediumType.startsWith('Solid') ? 'SSD' : 'HD', - name: util.getValue(lines, 'Model', ':', true).trim(), - vendor: getVendorFromModel(util.getValue(lines, 'Model', ':', true).trim()) || util.getValue(lines, 'Manufacturer', ':', true), - size: sizeValue, - bytesPerSector: null, - totalCylinders: null, - totalHeads: null, - totalSectors: null, - totalTracks: null, - tracksPerCylinder: null, - sectorsPerTrack: null, - firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(), - serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(), - interfaceType: util.getValue(lines, 'InterfaceType', ':', true).trim(), - smartStatus: smartStatusString === 'verified' ? 'OK' : smartStatusString || 'unknown', - temperature: null, - BSDName: BSDName - }); - cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;'; - } - } - }); + }); + } catch (e) { + util.noop(); + } + // NVME Drives - devices = linesNVMe.join('\n').split('\n\n Capacity:'); - devices.shift(); - devices.forEach(function (device) { - device = '!Capacity: ' + device; - let lines = device.split('\n'); - const linkWidth = util.getValue(lines, 'link width', ':', true).trim(); - const sizeStr = util.getValue(lines, '!capacity', ':', true).trim(); - const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim(); - if (sizeStr) { - let sizeValue = 0; - if (sizeStr.indexOf('(') >= 0) { - sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '')); + try { + let devices = linesNVMe.join('\n').split('\n\n Capacity:'); + devices.shift(); + devices.forEach(function (device) { + device = '!Capacity: ' + device; + let lines = device.split('\n'); + const linkWidth = util.getValue(lines, 'link width', ':', true).trim(); + const sizeStr = util.getValue(lines, '!capacity', ':', true).trim(); + const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim(); + if (sizeStr) { + let sizeValue = 0; + if (sizeStr.indexOf('(') >= 0) { + sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '')); + } + if (!sizeValue) { + sizeValue = parseInt(sizeStr); + } + if (sizeValue) { + const smartStatusString = util.getValue(lines, 'S.M.A.R.T. status', ':', true).trim().toLowerCase(); + result.push({ + device: BSDName, + type: 'NVMe', + name: util.getValue(lines, 'Model', ':', true).trim(), + vendor: getVendorFromModel(util.getValue(lines, 'Model', ':', true).trim()), + size: sizeValue, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(), + serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(), + interfaceType: ('PCIe ' + linkWidth).trim(), + smartStatus: smartStatusString === 'verified' ? 'OK' : smartStatusString || 'unknown', + temperature: null, + BSDName: BSDName + }); + cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;'; + } } - if (!sizeValue) { - sizeValue = parseInt(sizeStr); - } - if (sizeValue) { - const smartStatusString = util.getValue(lines, 'S.M.A.R.T. status', ':', true).trim().toLowerCase(); - result.push({ - device: BSDName, - type: 'NVMe', - name: util.getValue(lines, 'Model', ':', true).trim(), - vendor: getVendorFromModel(util.getValue(lines, 'Model', ':', true).trim()), - size: sizeValue, - bytesPerSector: null, - totalCylinders: null, - totalHeads: null, - totalSectors: null, - totalTracks: null, - tracksPerCylinder: null, - sectorsPerTrack: null, - firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(), - serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(), - interfaceType: ('PCIe ' + linkWidth).trim(), - smartStatus: smartStatusString === 'verified' ? 'OK' : smartStatusString || 'unknown', - temperature: null, - BSDName: BSDName - }); - cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;'; - } - } - }); + }); + } catch (e) { + util.noop(); + } // USB Drives - devices = linesUSB.join('\n').replaceAll('Media:\n ', 'Model:').split('\n\n Product ID:'); - devices.shift(); - devices.forEach(function (device) { - let lines = device.split('\n'); - const sizeStr = util.getValue(lines, 'Capacity', ':', true).trim(); - const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim(); - if (sizeStr) { - let sizeValue = 0; - if (sizeStr.indexOf('(') >= 0) { - sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '')); + try { + let devices = linesUSB.join('\n').replaceAll('Media:\n ', 'Model:').split('\n\n Product ID:'); + devices.shift(); + devices.forEach(function (device) { + let lines = device.split('\n'); + const sizeStr = util.getValue(lines, 'Capacity', ':', true).trim(); + const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim(); + if (sizeStr) { + let sizeValue = 0; + if (sizeStr.indexOf('(') >= 0) { + sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '')); + } + if (!sizeValue) { + sizeValue = parseInt(sizeStr); + } + if (sizeValue) { + const smartStatusString = util.getValue(lines, 'S.M.A.R.T. status', ':', true).trim().toLowerCase(); + result.push({ + device: BSDName, + type: 'USB', + name: util.getValue(lines, 'Model', ':', true).trim().replaceAll(':', ''), + vendor: getVendorFromModel(util.getValue(lines, 'Model', ':', true).trim()), + size: sizeValue, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(), + serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(), + interfaceType: 'USB', + smartStatus: smartStatusString === 'verified' ? 'OK' : smartStatusString || 'unknown', + temperature: null, + BSDName: BSDName + }); + cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;'; + } } - if (!sizeValue) { - sizeValue = parseInt(sizeStr); - } - if (sizeValue) { - const smartStatusString = util.getValue(lines, 'S.M.A.R.T. status', ':', true).trim().toLowerCase(); - result.push({ - device: BSDName, - type: 'USB', - name: util.getValue(lines, 'Model', ':', true).trim().replaceAll(':', ''), - vendor: getVendorFromModel(util.getValue(lines, 'Model', ':', true).trim()), - size: sizeValue, - bytesPerSector: null, - totalCylinders: null, - totalHeads: null, - totalSectors: null, - totalTracks: null, - tracksPerCylinder: null, - sectorsPerTrack: null, - firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(), - serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(), - interfaceType: 'USB', - smartStatus: smartStatusString === 'verified' ? 'OK' : smartStatusString || 'unknown', - temperature: null, - BSDName: BSDName - }); - cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;'; - } - } - }); - } - if (cmd) { - cmd = cmd + 'printf "\n"'; - exec(cmd, function (error, stdout) { - let lines = stdout.toString().split('\n'); - lines.forEach(line => { - if (line) { - let parts = line.split('|'); - if (parts.length === 2) { - let BSDName = parts[0]; - parts[1] = parts[1].trim(); - let parts2 = parts[1].split(':'); - if (parts2.length === 2) { - parts2[1] = parts2[1].trim(); - let status = parts2[1].toLowerCase(); - for (let i = 0; i < result.length; i++) { - if (result[i].BSDName === BSDName) { - result[i].smartStatus = (status === 'not supported' ? 'not supported' : (status === 'verified' ? 'Ok' : (status === 'failing' ? 'Predicted Failure' : 'unknown'))); + }); + } catch (e) { + util.noop(); + } + if (cmd) { + cmd = cmd + 'printf "\n"'; + exec(cmd, function (error, stdout) { + let lines = stdout.toString().split('\n'); + lines.forEach(line => { + if (line) { + let parts = line.split('|'); + if (parts.length === 2) { + let BSDName = parts[0]; + parts[1] = parts[1].trim(); + let parts2 = parts[1].split(':'); + if (parts2.length === 2) { + parts2[1] = parts2[1].trim(); + let status = parts2[1].toLowerCase(); + for (let i = 0; i < result.length; i++) { + if (result[i].BSDName === BSDName) { + result[i].smartStatus = (status === 'not supported' ? 'not supported' : (status === 'verified' ? 'Ok' : (status === 'failing' ? 'Predicted Failure' : 'unknown'))); + } } } } } + }); + for (let i = 0; i < result.length; i++) { + delete result[i].BSDName; } + if (callback) { + callback(result); + } + resolve(result); }); + } else { for (let i = 0; i < result.length; i++) { delete result[i].BSDName; } @@ -1087,15 +1108,7 @@ function diskLayout(callback) { callback(result); } resolve(result); - }); - } else { - for (let i = 0; i < result.length; i++) { - delete result[i].BSDName; } - if (callback) { - callback(result); - } - resolve(result); } }); }