summaryrefslogtreecommitdiffstats
path: root/plugins/utils_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/utils_disk.c')
-rw-r--r--plugins/utils_disk.c141
1 files changed, 0 insertions, 141 deletions
diff --git a/plugins/utils_disk.c b/plugins/utils_disk.c
deleted file mode 100644
index 31284d5..0000000
--- a/plugins/utils_disk.c
+++ /dev/null
@@ -1,141 +0,0 @@
1/****************************************************************************
2* Utils for check_disk
3*
4* License: GPL
5* Copyright (c) 1999-2006 nagios-plugins team
6*
7* Last Modified: $Date$
8*
9* Description:
10*
11* This file contains utilities for check_disk. These are tested by libtap
12*
13* License Information:
14*
15* This program is free software; you can redistribute it and/or modify
16* it under the terms of the GNU General Public License as published by
17* the Free Software Foundation; either version 2 of the License, or
18* (at your option) any later version.
19*
20* This program is distributed in the hope that it will be useful,
21* but WITHOUT ANY WARRANTY; without even the implied warranty of
22* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23* GNU General Public License for more details.
24*
25* You should have received a copy of the GNU General Public License
26* along with this program; if not, write to the Free Software
27* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28*
29* $Id$
30*
31*****************************************************************************/
32
33#include "common.h"
34#include "utils_disk.h"
35
36void
37np_add_name (struct name_list **list, const char *name)
38{
39 struct name_list *new_entry;
40 new_entry = (struct name_list *) malloc (sizeof *new_entry);
41 new_entry->name = (char *) name;
42 new_entry->next = *list;
43 *list = new_entry;
44}
45
46/* Initialises a new parameter at the end of list */
47struct parameter_list *
48np_add_parameter(struct parameter_list **list, const char *name)
49{
50 struct parameter_list *current = *list;
51 struct parameter_list *new_path;
52 new_path = (struct parameter_list *) malloc (sizeof *new_path);
53 new_path->name = (char *) name;
54 new_path->found = 0;
55 new_path->found_len = 0;
56 new_path->w_df = 0;
57 new_path->c_df = 0;
58 new_path->w_dfp = -1.0;
59 new_path->c_dfp = -1.0;
60 new_path->w_idfp = -1.0;
61 new_path->c_idfp = -1.0;
62 new_path->best_match = NULL;
63
64 if (current == NULL) {
65 *list = new_path;
66 } else {
67 while (current->name_next) {
68 current = current->name_next;
69 }
70 current->name_next = new_path;
71 }
72 return new_path;
73}
74
75void
76np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
77{
78 struct parameter_list *d;
79 for (d = desired; d; d= d->name_next) {
80 struct mount_entry *me;
81 size_t name_len = strlen(d->name);
82 size_t best_match_len = 0;
83 struct mount_entry *best_match = NULL;
84
85 for (me = mount_list; me; me = me->me_next) {
86 size_t len = strlen (me->me_mountdir);
87 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
88 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
89 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
90 {
91 best_match = me;
92 best_match_len = len;
93 } else {
94 len = strlen (me->me_devname);
95 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
96 (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
97 || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
98 {
99 best_match = me;
100 best_match_len = len;
101 }
102 }
103 }
104 if (best_match) {
105 d->best_match = best_match;
106 d->found = TRUE;
107 } else {
108 d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
109 }
110 }
111}
112
113/* Returns TRUE if name is in list */
114int
115np_find_name (struct name_list *list, const char *name)
116{
117 const struct name_list *n;
118
119 if (list == NULL || name == NULL) {
120 return FALSE;
121 }
122 for (n = list; n; n = n->next) {
123 if (!strcmp(name, n->name)) {
124 return TRUE;
125 }
126 }
127 return FALSE;
128}
129
130int
131np_seen_name(struct name_list *list, const char *name)
132{
133 const struct name_list *s;
134 for (s = list; s; s=s->next) {
135 if (!strcmp(s->name, name)) {
136 return TRUE;
137 }
138 }
139 return FALSE;
140}
141