"use strict"; const Promise = require("bluebird"); const execBinary = require("../exec-binary"); const parseIECBytes = require("../parse/bytes/iec"); const mapValue = require("../map-value"); function parseBoolean(value) { return mapValue(value, { 0: false, 1: true }); } function mapType(value) { return mapValue(value, { part: "partition", disk: "disk", loop: "loopDevice" }); } function mapDeviceList(devices) { return devices.map((device) => { return { name: device.name, type: mapType(device.type), mountpoint: device.mountpoint, deviceNumber: device["maj:min"], removable: parseBoolean(device.rm), readOnly: parseBoolean(device.ro), size: parseIECBytes(device.size), children: (device.children != null) ? mapDeviceList(device.children) : [] }; }) } module.exports = function lsblk() { return Promise.try(() => { return execBinary("lsblk") .withFlags({ json: true }) .singleResult() .expectJsonStdout((result) => { return mapDeviceList(result.blockdevices); }) .execute(); }).then((output) => { return output.result; }); };