diskLayout() support for older versions of lsblk
This commit is contained in:
parent
24e8145a43
commit
0fd3c20474
@ -244,7 +244,8 @@ function parseBlk(lines) {
|
|||||||
'model': disk.model,
|
'model': disk.model,
|
||||||
'serial': disk.serial,
|
'serial': disk.serial,
|
||||||
'removable': disk.rm === '1',
|
'removable': disk.rm === '1',
|
||||||
'protocol': disk.tran
|
'protocol': disk.tran,
|
||||||
|
'group': disk.group,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -269,6 +270,7 @@ function blkStdoutToObject(stdout) {
|
|||||||
.replace(/LABEL=/g, ',"label":')
|
.replace(/LABEL=/g, ',"label":')
|
||||||
.replace(/MODEL=/g, ',"model":')
|
.replace(/MODEL=/g, ',"model":')
|
||||||
.replace(/OWNER=/g, ',"owner":')
|
.replace(/OWNER=/g, ',"owner":')
|
||||||
|
.replace(/GROUP=/g, ',"group":')
|
||||||
.replace(/\n/g, '}\n');
|
.replace(/\n/g, '}\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,45 +717,54 @@ function diskLayout(callback) {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
try {
|
try {
|
||||||
const out = stdout.toString().trim();
|
const out = stdout.toString().trim();
|
||||||
const outJSON = JSON.parse(out);
|
let devices = [];
|
||||||
if (outJSON && outJSON.hasOwnProperty('blockdevices')) {
|
try {
|
||||||
let devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; });
|
const outJSON = JSON.parse(out);
|
||||||
devices.forEach((device) => {
|
if (outJSON && outJSON.hasOwnProperty('blockdevices')) {
|
||||||
let mediumType = '';
|
devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; });
|
||||||
const BSDName = '/dev/' + device.name;
|
}
|
||||||
const logical = device.name;
|
} catch (e) {
|
||||||
try {
|
// fallback to older version of lsblk
|
||||||
mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational').toString().split('\n')[0];
|
const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP; unset LC_ALL').toString();
|
||||||
} catch (e) {
|
let lines = blkStdoutToObject(out2).split('\n');
|
||||||
util.noop();
|
const data = parseBlk(lines);
|
||||||
}
|
devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null && item.model !== ''; });
|
||||||
let interfaceType = device.tran ? device.tran.toUpperCase().trim() : '';
|
|
||||||
if (interfaceType === 'NVME') {
|
|
||||||
mediumType = '2';
|
|
||||||
interfaceType = 'PCIe';
|
|
||||||
}
|
|
||||||
result.push({
|
|
||||||
device: BSDName,
|
|
||||||
type: (mediumType === '0' ? 'SSD' : (mediumType === '1' ? 'HD' : (mediumType === '2' ? 'NVMe' : (device.model && device.model.indexOf('SSD') > -1 ? 'SSD' : (device.model && device.model.indexOf('NVM') > -1 ? 'NVMe' : 'HD'))))),
|
|
||||||
name: device.model || '',
|
|
||||||
vendor: getVendorFromModel(device.model) || (device.vendor ? device.vendor.trim() : ''),
|
|
||||||
size: device.size || 0,
|
|
||||||
bytesPerSector: -1,
|
|
||||||
totalCylinders: -1,
|
|
||||||
totalHeads: -1,
|
|
||||||
totalSectors: -1,
|
|
||||||
totalTracks: -1,
|
|
||||||
tracksPerCylinder: -1,
|
|
||||||
sectorsPerTrack: -1,
|
|
||||||
firmwareRevision: device.rev ? device.rev.trim() : '',
|
|
||||||
serialNum: device.serial ? device.serial.trim() : '',
|
|
||||||
interfaceType: interfaceType,
|
|
||||||
smartStatus: 'unknown',
|
|
||||||
BSDName: BSDName
|
|
||||||
});
|
|
||||||
cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
devices.forEach((device) => {
|
||||||
|
let mediumType = '';
|
||||||
|
const BSDName = '/dev/' + device.name;
|
||||||
|
const logical = device.name;
|
||||||
|
try {
|
||||||
|
mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational').toString().split('\n')[0];
|
||||||
|
} catch (e) {
|
||||||
|
util.noop();
|
||||||
|
}
|
||||||
|
let interfaceType = device.tran ? device.tran.toUpperCase().trim() : '';
|
||||||
|
if (interfaceType === 'NVME') {
|
||||||
|
mediumType = '2';
|
||||||
|
interfaceType = 'PCIe';
|
||||||
|
}
|
||||||
|
result.push({
|
||||||
|
device: BSDName,
|
||||||
|
type: (mediumType === '0' ? 'SSD' : (mediumType === '1' ? 'HD' : (mediumType === '2' ? 'NVMe' : (device.model && device.model.indexOf('SSD') > -1 ? 'SSD' : (device.model && device.model.indexOf('NVM') > -1 ? 'NVMe' : 'HD'))))),
|
||||||
|
name: device.model || '',
|
||||||
|
vendor: getVendorFromModel(device.model) || (device.vendor ? device.vendor.trim() : ''),
|
||||||
|
size: device.size || 0,
|
||||||
|
bytesPerSector: -1,
|
||||||
|
totalCylinders: -1,
|
||||||
|
totalHeads: -1,
|
||||||
|
totalSectors: -1,
|
||||||
|
totalTracks: -1,
|
||||||
|
tracksPerCylinder: -1,
|
||||||
|
sectorsPerTrack: -1,
|
||||||
|
firmwareRevision: device.rev ? device.rev.trim() : '',
|
||||||
|
serialNum: device.serial ? device.serial.trim() : '',
|
||||||
|
interfaceType: interfaceType,
|
||||||
|
smartStatus: 'unknown',
|
||||||
|
BSDName: BSDName
|
||||||
|
});
|
||||||
|
cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;';
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
@ -811,7 +822,6 @@ function diskLayout(callback) {
|
|||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_darwin) {
|
if (_darwin) {
|
||||||
exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) {
|
exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user