summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2021-12-02 14:11:21 (GMT)
committerGitHub <noreply@github.com>2021-12-02 14:11:21 (GMT)
commitdf1e9e975f69c8f7965bab91684870fe509739c6 (patch)
tree526b0c77c524b2219d5a48fd78b8302f055a4a5b /plugins/check_disk.c
parent6246b8f1830e8a375bc656deafd28aab715b4fd9 (diff)
parent1a3a715702a5b6709fed2a1eb53ec644c9968057 (diff)
downloadmonitoring-plugins-df1e9e975f69c8f7965bab91684870fe509739c6.tar.gz
Merge branch 'master' into mailq-add-config-dir
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c233
1 files changed, 149 insertions, 84 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index e73a008..54befca 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_disk plugin 3* Monitoring check_disk plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2008 Monitoring Plugins Development Team 6* Copyright (c) 1999-2008 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_disk plugin 10* This file contains the check_disk plugin
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
28 28
29const char *progname = "check_disk"; 29const char *progname = "check_disk";
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
46#include <stdarg.h> 46#include <stdarg.h>
47#include "fsusage.h" 47#include "fsusage.h"
48#include "mountlist.h" 48#include "mountlist.h"
49#include "intprops.h" /* necessary for TYPE_MAXIMUM */ 49#include "intprops.h" /* necessary for TYPE_MAXIMUM */
50#if HAVE_LIMITS_H 50#if HAVE_LIMITS_H
51# include <limits.h> 51# include <limits.h>
52#endif 52#endif
@@ -141,6 +141,7 @@ int erronly = FALSE;
141int display_mntp = FALSE; 141int display_mntp = FALSE;
142int exact_match = FALSE; 142int exact_match = FALSE;
143int freespace_ignore_reserved = FALSE; 143int freespace_ignore_reserved = FALSE;
144int display_inodes_perfdata = FALSE;
144char *warn_freespace_units = NULL; 145char *warn_freespace_units = NULL;
145char *crit_freespace_units = NULL; 146char *crit_freespace_units = NULL;
146char *warn_freespace_percent = NULL; 147char *warn_freespace_percent = NULL;
@@ -167,11 +168,10 @@ main (int argc, char **argv)
167 char *output; 168 char *output;
168 char *details; 169 char *details;
169 char *perf; 170 char *perf;
171 char *perf_ilabel;
170 char *preamble; 172 char *preamble;
171 char *flag_header; 173 char *flag_header;
172 double inode_space_pct; 174 double inode_space_pct;
173 double warning_high_tide;
174 double critical_high_tide;
175 int temp_result; 175 int temp_result;
176 176
177 struct mount_entry *me; 177 struct mount_entry *me;
@@ -186,6 +186,7 @@ main (int argc, char **argv)
186 output = strdup (""); 186 output = strdup ("");
187 details = strdup (""); 187 details = strdup ("");
188 perf = strdup (""); 188 perf = strdup ("");
189 perf_ilabel = strdup ("");
189 stat_buf = malloc(sizeof *stat_buf); 190 stat_buf = malloc(sizeof *stat_buf);
190 191
191 setlocale (LC_ALL, ""); 192 setlocale (LC_ALL, "");
@@ -242,17 +243,17 @@ main (int argc, char **argv)
242 243
243#ifdef __CYGWIN__ 244#ifdef __CYGWIN__
244 if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) 245 if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
245 continue; 246 continue;
246 snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); 247 snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10);
247 if (GetDriveType(mountdir) != DRIVE_FIXED) 248 if (GetDriveType(mountdir) != DRIVE_FIXED)
248 me->me_remote = 1; 249 me->me_remote = 1;
249#endif 250#endif
250 /* Filters */ 251 /* Filters */
251 252
252 /* Remove filesystems already seen */ 253 /* Remove filesystems already seen */
253 if (np_seen_name(seen, me->me_mountdir)) { 254 if (np_seen_name(seen, me->me_mountdir)) {
254 continue; 255 continue;
255 } 256 }
256 np_add_name(&seen, me->me_mountdir); 257 np_add_name(&seen, me->me_mountdir);
257 258
258 if (path->group == NULL) { 259 if (path->group == NULL) {
@@ -285,8 +286,17 @@ main (int argc, char **argv)
285 get_stats (path, &fsp); 286 get_stats (path, &fsp);
286 287
287 if (verbose >= 3) { 288 if (verbose >= 3) {
288 printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", 289 printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
289 me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); 290 me->me_mountdir,
291 path->dused_pct,
292 path->dfree_pct,
293 path->dused_units,
294 path->dfree_units,
295 path->dtotal_units,
296 path->dused_inodes_percent,
297 path->dfree_inodes_percent,
298 fsp.fsu_blocksize,
299 mult);
290 } 300 }
291 301
292 /* Threshold comparisons */ 302 /* Threshold comparisons */
@@ -323,54 +333,79 @@ main (int argc, char **argv)
323 */ 333 */
324 334
325 /* *_high_tide must be reinitialized at each run */ 335 /* *_high_tide must be reinitialized at each run */
326 warning_high_tide = UINT_MAX; 336 uint64_t warning_high_tide = UINT64_MAX;
327 critical_high_tide = UINT_MAX;
328 337
329 if (path->freespace_units->warning != NULL) { 338 if (path->freespace_units->warning != NULL) {
330 warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; 339 warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult;
331 } 340 }
332 if (path->freespace_percent->warning != NULL) { 341 if (path->freespace_percent->warning != NULL) {
333 warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units )); 342 warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) );
334 } 343 }
344
345 uint64_t critical_high_tide = UINT64_MAX;
346
335 if (path->freespace_units->critical != NULL) { 347 if (path->freespace_units->critical != NULL) {
336 critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; 348 critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult;
337 } 349 }
338 if (path->freespace_percent->critical != NULL) { 350 if (path->freespace_percent->critical != NULL) {
339 critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); 351 critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) );
340 } 352 }
341 353
342 /* Nb: *_high_tide are unset when == UINT_MAX */ 354 /* Nb: *_high_tide are unset when == UINT64_MAX */
343 xasprintf (&perf, "%s %s", perf, 355 xasprintf (&perf, "%s %s", perf,
344 perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 356 perfdata_uint64 (
345 path->dused_units, units, 357 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
346 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, 358 path->dused_units * mult, "B",
347 (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, 359 (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
348 TRUE, 0, 360 (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
349 TRUE, path->dtotal_units)); 361 TRUE, 0,
362 TRUE, path->dtotal_units * mult));
363
364 if (display_inodes_perfdata) {
365 /* *_high_tide must be reinitialized at each run */
366 warning_high_tide = UINT64_MAX;
367 critical_high_tide = UINT64_MAX;
368
369 if (path->freeinodes_percent->warning != NULL) {
370 warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
371 }
372 if (path->freeinodes_percent->critical != NULL) {
373 critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
374 }
375
376 xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
377 /* Nb: *_high_tide are unset when == UINT64_MAX */
378 xasprintf (&perf, "%s %s", perf,
379 perfdata_uint64 (perf_ilabel,
380 path->inodes_used, "",
381 (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
382 (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
383 TRUE, 0,
384 TRUE, path->inodes_total));
385 }
350 386
351 if (disk_result==STATE_OK && erronly && !verbose) 387 if (disk_result==STATE_OK && erronly && !verbose)
352 continue; 388 continue;
353 389
354 if(disk_result && verbose >= 1) { 390 if(disk_result && verbose >= 1) {
355 xasprintf(&flag_header, " %s [", state_text (disk_result)); 391 xasprintf(&flag_header, " %s [", state_text (disk_result));
356 } else { 392 } else {
357 xasprintf(&flag_header, ""); 393 xasprintf(&flag_header, "");
358 } 394 }
359 xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", 395 xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
360 output, flag_header, 396 output, flag_header,
361 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 397 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
362 path->dfree_units, 398 path->dfree_units,
363 units, 399 units,
364 path->dfree_pct); 400 path->dfree_pct);
365 if (path->dused_inodes_percent < 0) { 401 if (path->dused_inodes_percent < 0) {
366 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); 402 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
367 } else { 403 } else {
368 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); 404 xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
369 } 405 }
370 free(flag_header); 406 free(flag_header);
371 /* TODO: Need to do a similar debug line 407 /* TODO: Need to do a similar debug line
372 xasprintf (&details, _("%s\n\ 408 xasprintf (&details, _("%s\n\%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
373%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
374 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, 409 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
375 me->me_devname, me->me_type, me->me_mountdir, 410 me->me_devname, me->me_type, me->me_mountdir,
376 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); 411 (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
@@ -455,6 +490,7 @@ process_arguments (int argc, char **argv)
455 {"ignore-eregi-partition", required_argument, 0, 'I'}, 490 {"ignore-eregi-partition", required_argument, 0, 'I'},
456 {"local", no_argument, 0, 'l'}, 491 {"local", no_argument, 0, 'l'},
457 {"stat-remote-fs", no_argument, 0, 'L'}, 492 {"stat-remote-fs", no_argument, 0, 'L'},
493 {"iperfdata", no_argument, 0, 'P'},
458 {"mountpoint", no_argument, 0, 'M'}, 494 {"mountpoint", no_argument, 0, 'M'},
459 {"errors-only", no_argument, 0, 'e'}, 495 {"errors-only", no_argument, 0, 'e'},
460 {"exact-match", no_argument, 0, 'E'}, 496 {"exact-match", no_argument, 0, 'E'},
@@ -477,7 +513,7 @@ process_arguments (int argc, char **argv)
477 strcpy (argv[c], "-t"); 513 strcpy (argv[c], "-t");
478 514
479 while (1) { 515 while (1) {
480 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); 516 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option);
481 517
482 if (c == -1 || c == EOF) 518 if (c == -1 || c == EOF)
483 break; 519 break;
@@ -530,14 +566,14 @@ process_arguments (int argc, char **argv)
530 } 566 }
531 break; 567 break;
532 568
533 case 'W': /* warning inode threshold */ 569 case 'W': /* warning inode threshold */
534 if (*optarg == '@') { 570 if (*optarg == '@') {
535 warn_freeinodes_percent = optarg; 571 warn_freeinodes_percent = optarg;
536 } else { 572 } else {
537 xasprintf(&warn_freeinodes_percent, "@%s", optarg); 573 xasprintf(&warn_freeinodes_percent, "@%s", optarg);
538 } 574 }
539 break; 575 break;
540 case 'K': /* critical inode threshold */ 576 case 'K': /* critical inode threshold */
541 if (*optarg == '@') { 577 if (*optarg == '@') {
542 crit_freeinodes_percent = optarg; 578 crit_freeinodes_percent = optarg;
543 } else { 579 } else {
@@ -547,21 +583,24 @@ process_arguments (int argc, char **argv)
547 case 'u': 583 case 'u':
548 if (units) 584 if (units)
549 free(units); 585 free(units);
550 if (! strcmp (optarg, "bytes")) { 586 if (! strcasecmp (optarg, "bytes")) {
551 mult = (uintmax_t)1; 587 mult = (uintmax_t)1;
552 units = strdup ("B"); 588 units = strdup ("B");
553 } else if (! strcmp (optarg, "kB")) { 589 } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
554 mult = (uintmax_t)1024; 590 mult = (uintmax_t)1024;
555 units = strdup ("kB"); 591 units = strdup ("kiB");
556 } else if (! strcmp (optarg, "MB")) { 592 } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
557 mult = (uintmax_t)1024 * 1024; 593 mult = (uintmax_t)1024 * 1024;
558 units = strdup ("MB"); 594 units = strdup ("MiB");
559 } else if (! strcmp (optarg, "GB")) { 595 } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
560 mult = (uintmax_t)1024 * 1024 * 1024; 596 mult = (uintmax_t)1024 * 1024 * 1024;
561 units = strdup ("GB"); 597 units = strdup ("GiB");
562 } else if (! strcmp (optarg, "TB")) { 598 } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
563 mult = (uintmax_t)1024 * 1024 * 1024 * 1024; 599 mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
564 units = strdup ("TB"); 600 units = strdup ("TiB");
601 } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
602 mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
603 units = strdup ("PiB");
565 } else { 604 } else {
566 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); 605 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
567 } 606 }
@@ -572,19 +611,23 @@ process_arguments (int argc, char **argv)
572 mult = 1024; 611 mult = 1024;
573 if (units) 612 if (units)
574 free(units); 613 free(units);
575 units = strdup ("kB"); 614 units = strdup ("kiB");
576 break; 615 break;
577 case 'm': /* display mountpoint */ 616 case 'm': /* display mountpoint */
578 mult = 1024 * 1024; 617 mult = 1024 * 1024;
579 if (units) 618 if (units)
580 free(units); 619 free(units);
581 units = strdup ("MB"); 620 units = strdup ("MiB");
582 break; 621 break;
583 case 'L': 622 case 'L':
584 stat_remote_fs = 1; 623 stat_remote_fs = 1;
624 /* fallthrough */
585 case 'l': 625 case 'l':
586 show_local_fs = 1; 626 show_local_fs = 1;
587 break; 627 break;
628 case 'P':
629 display_inodes_perfdata = 1;
630 break;
588 case 'p': /* select path */ 631 case 'p': /* select path */
589 if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || 632 if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
590 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || 633 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
@@ -781,7 +824,7 @@ process_arguments (int argc, char **argv)
781 } 824 }
782 825
783 if (units == NULL) { 826 if (units == NULL) {
784 units = strdup ("MB"); 827 units = strdup ("MiB");
785 mult = (uintmax_t)1024 * 1024; 828 mult = (uintmax_t)1024 * 1024;
786 } 829 }
787 830
@@ -904,6 +947,8 @@ print_help (void)
904 printf (" %s\n", _("Display only devices/mountpoints with errors")); 947 printf (" %s\n", _("Display only devices/mountpoints with errors"));
905 printf (" %s\n", "-f, --freespace-ignore-reserved"); 948 printf (" %s\n", "-f, --freespace-ignore-reserved");
906 printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata")); 949 printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata"));
950 printf (" %s\n", "-P, --iperfdata");
951 printf (" %s\n", _("Display inode usage in perfdata"));
907 printf (" %s\n", "-g, --group=NAME"); 952 printf (" %s\n", "-g, --group=NAME");
908 printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); 953 printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together"));
909 printf (" %s\n", "-k, --kilobytes"); 954 printf (" %s\n", "-k, --kilobytes");
@@ -993,50 +1038,59 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
993 if (p_list->group && ! (strcmp(p_list->group, p->group))) { 1038 if (p_list->group && ! (strcmp(p_list->group, p->group))) {
994 stat_path(p_list); 1039 stat_path(p_list);
995 get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); 1040 get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
996 get_path_stats(p_list, &tmpfsp); 1041 get_path_stats(p_list, &tmpfsp);
997 if (verbose >= 3) 1042 if (verbose >= 3)
998 printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", 1043 printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%lu free_units=%llu total_units=%llu mult=%llu\n",
999 p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, 1044 p_list->group,
1000 p_list->dtotal_units, mult); 1045 tmpfsp.fsu_blocks,
1001 1046 tmpfsp.fsu_blocksize,
1002 /* prevent counting the first FS of a group twice since its parameter_list entry 1047 p_list->best_match->me_mountdir,
1048 p_list->dused_units,
1049 p_list->dfree_units,
1050 p_list->dtotal_units,
1051 mult);
1052
1053 /* prevent counting the first FS of a group twice since its parameter_list entry
1003 * is used to carry the information of all file systems of the entire group */ 1054 * is used to carry the information of all file systems of the entire group */
1004 if (! first) { 1055 if (! first) {
1005 p->total += p_list->total; 1056 p->total += p_list->total;
1006 p->available += p_list->available; 1057 p->available += p_list->available;
1007 p->available_to_root += p_list->available_to_root; 1058 p->available_to_root += p_list->available_to_root;
1008 p->used += p_list->used; 1059 p->used += p_list->used;
1009 1060
1010 p->dused_units += p_list->dused_units; 1061 p->dused_units += p_list->dused_units;
1011 p->dfree_units += p_list->dfree_units; 1062 p->dfree_units += p_list->dfree_units;
1012 p->dtotal_units += p_list->dtotal_units; 1063 p->dtotal_units += p_list->dtotal_units;
1013 p->inodes_total += p_list->inodes_total; 1064 p->inodes_total += p_list->inodes_total;
1014 p->inodes_free += p_list->inodes_free; 1065 p->inodes_free += p_list->inodes_free;
1066 p->inodes_free_to_root += p_list->inodes_free_to_root;
1067 p->inodes_used += p_list->inodes_used;
1015 } 1068 }
1016 first = 0; 1069 first = 0;
1017 } 1070 }
1018 if (verbose >= 3) 1071 if (verbose >= 3)
1019 printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", 1072 printf("Group %s now has: used_units=%llu free_units=%llu total_units=%llu fsu_blocksize=%llu mult=%llu\n",
1020 p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units, 1073 p->group,
1021 p->dfree_units, p->dtotal_units, mult); 1074 p->dused_units,
1075 p->dfree_units,
1076 p->dtotal_units,
1077 tmpfsp.fsu_blocksize,
1078 mult);
1022 } 1079 }
1023 /* modify devname and mountdir for output */ 1080 /* modify devname and mountdir for output */
1024 p->best_match->me_mountdir = p->best_match->me_devname = p->group; 1081 p->best_match->me_mountdir = p->best_match->me_devname = p->group;
1025 } 1082 }
1026 /* finally calculate percentages for either plain FS or summed up group */ 1083 /* finally calculate percentages for either plain FS or summed up group */
1027 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ 1084 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
1028 p->dfree_pct = 100 - p->dused_pct; 1085 p->dfree_pct = 100 - p->dused_pct;
1029 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); 1086 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
1030 p->dfree_inodes_percent = 100 - p->dused_inodes_percent; 1087 p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
1031 1088
1032} 1089}
1033 1090
1034void 1091void
1035get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { 1092get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1036 /* 2007-12-08 - Workaround for Gnulib reporting insanely high available 1093 p->available = fsp->fsu_bavail;
1037 * space on BSD (the actual value should be negative but fsp->fsu_bavail
1038 * is unsigned) */
1039 p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail;
1040 p->available_to_root = fsp->fsu_bfree; 1094 p->available_to_root = fsp->fsu_bfree;
1041 p->used = fsp->fsu_blocks - fsp->fsu_bfree; 1095 p->used = fsp->fsu_blocks - fsp->fsu_bfree;
1042 if (freespace_ignore_reserved) { 1096 if (freespace_ignore_reserved) {
@@ -1046,11 +1100,22 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1046 /* default behaviour : take all the blocks into account */ 1100 /* default behaviour : take all the blocks into account */
1047 p->total = fsp->fsu_blocks; 1101 p->total = fsp->fsu_blocks;
1048 } 1102 }
1049 1103
1050 p->dused_units = p->used*fsp->fsu_blocksize/mult; 1104 p->dused_units = p->used*fsp->fsu_blocksize/mult;
1051 p->dfree_units = p->available*fsp->fsu_blocksize/mult; 1105 p->dfree_units = p->available*fsp->fsu_blocksize/mult;
1052 p->dtotal_units = p->total*fsp->fsu_blocksize/mult; 1106 p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
1053 p->inodes_total = fsp->fsu_files; /* Total file nodes. */ 1107 /* Free file nodes. Not sure the workaround is required, but in case...*/
1054 p->inodes_free = fsp->fsu_ffree; /* Free file nodes. */ 1108 p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail;
1109 p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */
1110 p->inodes_used = fsp->fsu_files - fsp->fsu_ffree;
1111 if (freespace_ignore_reserved) {
1112 /* option activated : we substract the root-reserved inodes from the total */
1113 /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */
1114 /* for others, fsp->fsu_ffree == fsp->fsu_favail */
1115 p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free;
1116 } else {
1117 /* default behaviour : take all the inodes into account */
1118 p->inodes_total = fsp->fsu_files;
1119 }
1055 np_add_name(&seen, p->best_match->me_mountdir); 1120 np_add_name(&seen, p->best_match->me_mountdir);
1056} 1121}