"use strict"; const Promise = require("bluebird"); const execBinary = require("../exec-binary"); const parseIECBytes = require("../parse/bytes/iec"); const parseMountOptions = require("../parse/mount-options"); function mapMountList(mounts) { return mounts.map((mount) => { /* Some poorly-documented pseudo-filesystems were not worth investigating mount options for, yet. For those, we silently ignore missing/unknown entries. */ let missingOptionsAllowed = ["cgroup", "cgroup2", "bpf", "pstore"].includes(mount.fstype); let parsedOptions = parseMountOptions(mount.fstype, mount.options); if (missingOptionsAllowed || parsedOptions.missing.length === 0) { return { id: mount.id, sourceDevice: mount.source, mountpoint: mount.target, filesystem: mount.fstype, options: parsedOptions.parsed, label: mount.label, uuid: mount.uuid, partitionLabel: mount.partlabel, partitionUUID: mount.partuuid, deviceNumber: mount["maj:min"], totalSpace: parseIECBytes(mount.size), freeSpace: parseIECBytes(mount.avail), usedSpace: parseIECBytes(mount.used), rootPath: mount.fsroot, taskID: mount.tid, optionalFields: mount["opt-fields"], propagationFlags: mount.propagation, children: (mount.children != null) ? mapMountList(mount.children) : [] }; } else { throw new Error(`Encountered unrecognized mount options for mount '${mount.target}': ${parsedOptions.missing.join(", ")}`); } }); } let columns = [ "SOURCE", "TARGET", "FSTYPE", "OPTIONS", "LABEL", "UUID", "PARTLABEL", "PARTUUID", "MAJ:MIN", "SIZE", "AVAIL", "USED", "FSROOT", "TID", "ID", "OPT-FIELDS", "PROPAGATION", // "FREQ", // "PASSNO" ]; module.exports = function findmnt() { return Promise.try(() => { return execBinary("findmnt") .withFlags({ json: true, o: columns.join(",") }) .singleResult() .expectJsonStdout((result) => { return mapMountList(result.filesystems); }) .execute(); }).then((output) => { return output.result; }); };