diff --git a/lib/filesystem.js b/lib/filesystem.js index 9ce7d50..8cc47ef 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -244,7 +244,8 @@ function parseBlk(lines) { 'model': disk.model, 'serial': disk.serial, '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(/MODEL=/g, ',"model":') .replace(/OWNER=/g, ',"owner":') + .replace(/GROUP=/g, ',"group":') .replace(/\n/g, '}\n'); } @@ -715,45 +717,54 @@ function diskLayout(callback) { if (!error) { try { const out = stdout.toString().trim(); - const outJSON = JSON.parse(out); - if (outJSON && outJSON.hasOwnProperty('blockdevices')) { - let devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; }); - 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;'; - }); + let devices = []; + try { + const outJSON = JSON.parse(out); + if (outJSON && outJSON.hasOwnProperty('blockdevices')) { + devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; }); + } + } catch (e) { + // fallback to older version of lsblk + 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(); + let lines = blkStdoutToObject(out2).split('\n'); + const data = parseBlk(lines); + devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null && item.model !== ''; }); } + 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) { util.noop(); } @@ -811,7 +822,6 @@ function diskLayout(callback) { if (callback) { callback(result); } resolve(result); } - if (_darwin) { exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) { if (!error) {