fsSize() added rw (win, linux, mac OS, BSD)

This commit is contained in:
Sebastian Hildebrandt 2022-12-01 16:56:30 +01:00
parent f716acdf55
commit 0038afdd5e
7 changed files with 56 additions and 10 deletions

View File

@ -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) |

View File

@ -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 |

View File

@ -742,6 +742,16 @@ setInterval(function() {
<td></td>
<td>mount point</td>
</tr>
<tr>
<td></td>
<td>[0].rw</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td></td>
<td>Read/Write (false if read only)</td>
</tr>
<tr class="example">
<td></td>
<td colspan="7">
@ -757,7 +767,8 @@ si.fsSize().then(data => console.log(data));</code></pre class="example">
used: 59142635520,
available: 913434726400,
use: 6.08,
mount: '/'
mount: '/',
rw: true
},
{
...
@ -1000,4 +1011,4 @@ setInterval(function() {
</script>
</body>
</html>
</html>

View File

@ -57,6 +57,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.16.0</th>
<td>2022-12-01</td>
<td><span class="code">fsSize()</span> added rw attribute (win, linux, mac OS, BSD)</td>
</tr>
<tr>
<th scope="row">5.15.1</th>
<td>2022-11-29</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png" alt="logo">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.15.1</span></div>
<div class="version">New Version: <span id="version">5.16.0</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">
@ -206,7 +206,7 @@
</div>
<div class="row number-section">
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">15,211</div>
<div class="numbers">15,381</div>
<div class="title">Lines of code</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">

View File

@ -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
});
}
});

1
lib/index.d.ts vendored
View File

@ -434,6 +434,7 @@ export namespace Systeminformation {
available: number;
use: number;
mount: string;
rw: boolean | null;
}
interface FsOpenFilesData {