From 0038afdd5eec253957b9ca72071463aeed1421b8 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 1 Dec 2022 16:56:30 +0100 Subject: [PATCH] fsSize() added rw (win, linux, mac OS, BSD) --- CHANGELOG.md | 1 + README.md | 3 +++ docs/filesystem.html | 15 +++++++++++++-- docs/history.html | 5 +++++ docs/index.html | 4 ++-- lib/filesystem.js | 37 +++++++++++++++++++++++++++++++------ lib/index.d.ts | 1 + 7 files changed, 56 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3451c..b9cba81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | +| 5.16.0 | 2022-12-01 | `fsSize()` added rw (win, linux, mac OS, BSD) | | 5.15.1 | 2022-11-29 | fix typescript typings | | 5.15.0 | 2022-11-29 | `blockDevices()` added device (win, linux, mac OS) | | 5.14.4 | 2022-11-21 | `osInfo()` improved uefi parsing (FreeBSD) | diff --git a/README.md b/README.md index 8dbbbca..87e9063 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ si.cpu() (last 7 major and minor version releases) +- Version 5.16.0: `fsSize()` added rw property +- Version 5.15.0: `blockDevices()` added device - Version 5.14.0: `blockDevices()` added raid group member (linux) - Version 5.13.0: `networkConnections()` added process name (mac OS) - Version 5.12.0: `cpu()` added performance and efficiency cores @@ -489,6 +491,7 @@ Full function reference with examples can be found at [https://systeminformation | | [0].available | X | X | X | X | | used in bytes | | | [0].use | X | X | X | X | | used in % | | | [0].mount | X | X | X | X | | mount point | +| | [0].rw | X | X | X | X | | read and write (false if read only) | | si.fsOpenFiles(cb) | {...} | X | X | X | | | count max/allocated file descriptors | | | max | X | X | X | | | max file descriptors | | | allocated | X | X | X | | | current open files count | diff --git a/docs/filesystem.html b/docs/filesystem.html index 2b1d3ef..e3c19a3 100644 --- a/docs/filesystem.html +++ b/docs/filesystem.html @@ -742,6 +742,16 @@ setInterval(function() { mount point + + + [0].rw + X + X + X + X + + Read/Write (false if read only) + @@ -757,7 +767,8 @@ si.fsSize().then(data => console.log(data)); used: 59142635520, available: 913434726400, use: 6.08, - mount: '/' + mount: '/', + rw: true }, { ... @@ -1000,4 +1011,4 @@ setInterval(function() { - \ No newline at end of file + diff --git a/docs/history.html b/docs/history.html index 9ea0fe6..e4e35b7 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.16.0 + 2022-12-01 + fsSize() added rw attribute (win, linux, mac OS, BSD) + 5.15.1 2022-11-29 diff --git a/docs/index.html b/docs/index.html index 868d86d..964ed7c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.15.1
+
New Version: 5.16.0
@@ -206,7 +206,7 @@
-
15,211
+
15,381
Lines of code
diff --git a/lib/filesystem.js b/lib/filesystem.js index d46f790..624cd3d 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -39,6 +39,7 @@ let _disk_io = {}; function fsSize(callback) { let macOsDisks = []; + let osMounts = []; function getmacOsFsType(fs) { if (!fs.startsWith('/')) { return 'NFS'; } @@ -86,6 +87,7 @@ function fsSize(callback) { const used = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[3] : line[2])) * 1024; const available = parseInt(((_linux || _freebsd || _openbsd || _netbsd) ? line[4] : line[3])) * 1024; const use = parseFloat((100.0 * (used / (used + available))).toFixed(2)); + let rw = _darwin && osMounts && Object.keys(osMounts).length > 0 ? osMounts[fs] || false : null; line.splice(0, (_linux || _freebsd || _openbsd || _netbsd) ? 6 : 5); const mount = line.join(' '); if (!data.find(el => (el.fs === fs && el.type === fsType))) { @@ -96,7 +98,8 @@ function fsSize(callback) { used, available, use, - mount + mount, + rw }); } } @@ -110,18 +113,37 @@ function fsSize(callback) { let data = []; if (_linux || _freebsd || _openbsd || _netbsd || _darwin) { let cmd = ''; + macOsDisks = []; + osMounts = {}; if (_darwin) { cmd = 'df -kP'; try { macOsDisks = execSync('diskutil list').toString().split('\n').filter(line => { return !line.startsWith('/') && line.indexOf(':') > 0; }); + execSync('mount').toString().split('\n').filter(line => { + return line.startsWith('/'); + }).forEach((line) => { + osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1; + }); } catch (e) { - macOsDisks = []; + util.noop(); } } - if (_linux) { cmd = 'df -lkPTx squashfs'; } - if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; } + if (_linux) { + cmd = 'df -lkPTx squashfs'; + execSync('cat /proc/mounts').toString().split('\n').filter(line => { + return line.startsWith('/'); + }).forEach((line) => { + osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('rw') >= 0; + }); + } + if (_freebsd || _openbsd || _netbsd) { + cmd = 'df -lkPT'; + execSync('mount').toString().split('\n').forEach((line) => { + osMounts[line.split(' ')[0]] = line.toLowerCase().indexOf('read-only') === -1; + }); + } exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) { let lines = filterLines(stdout); data = parseDf(lines); @@ -151,7 +173,7 @@ function fsSize(callback) { if (_windows) { try { // util.wmic('logicaldisk get Caption,FileSystem,FreeSpace,Size').then((stdout) => { - util.powerShell('Get-CimInstance Win32_logicaldisk | select Caption,FileSystem,FreeSpace,Size | fl').then((stdout, error) => { + util.powerShell('Get-CimInstance Win32_logicaldisk | select Access,Caption,FileSystem,FreeSpace,Size | fl').then((stdout, error) => { if (!error) { let devices = stdout.toString().split(/\n\s*\n/); devices.forEach(function (device) { @@ -159,6 +181,8 @@ function fsSize(callback) { const size = util.toInt(util.getValue(lines, 'size', ':')); const free = util.toInt(util.getValue(lines, 'freespace', ':')); const caption = util.getValue(lines, 'caption', ':'); + const rwValue = util.getValue(lines, 'access', ':'); + const rw = rwValue ? (util.toInt(rwValue) !== 1) : null; if (size) { data.push({ fs: caption, @@ -167,7 +191,8 @@ function fsSize(callback) { used: size - free, available: free, use: parseFloat(((100.0 * (size - free)) / size).toFixed(2)), - mount: caption + mount: caption, + rw }); } }); diff --git a/lib/index.d.ts b/lib/index.d.ts index 7c0d1dc..643c05b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -434,6 +434,7 @@ export namespace Systeminformation { available: number; use: number; mount: string; + rw: boolean | null; } interface FsOpenFilesData {