utils_disk.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #include "common.h"
  33. #include "utils_disk.h"
  34. void
  35. np_add_name (struct name_list **list, const char *name)
  36. {
  37. struct name_list *new_entry;
  38. new_entry = (struct name_list *) malloc (sizeof *new_entry);
  39. new_entry->name = (char *) name;
  40. new_entry->next = *list;
  41. *list = new_entry;
  42. }
  43. void
  44. np_add_parameter(struct parameter_list **list, const char *name)
  45. {
  46. struct parameter_list *new_path;
  47. new_path = (struct parameter_list *) malloc (sizeof *new_path);
  48. new_path->name = (char *) name;
  49. new_path->found = 0;
  50. new_path->found_len = 0;
  51. new_path->w_df = 0;
  52. new_path->c_df = 0;
  53. new_path->w_dfp = -1.0;
  54. new_path->c_dfp = -1.0;
  55. new_path->w_idfp = -1.0;
  56. new_path->c_idfp = -1.0;
  57. new_path->name_next = *list;
  58. *list = new_path;
  59. }
  60. void
  61. np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
  62. {
  63. struct parameter_list *d;
  64. for (d = desired; d; d= d->name_next) {
  65. struct mount_entry *me;
  66. size_t name_len = strlen(d->name);
  67. size_t best_match_len = 0;
  68. struct mount_entry *best_match = NULL;
  69. for (me = mount_list; me; me = me->me_next) {
  70. size_t len = strlen (me->me_mountdir);
  71. if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
  72. (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
  73. || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
  74. {
  75. best_match = me;
  76. best_match_len = len;
  77. } else {
  78. len = strlen (me->me_devname);
  79. if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
  80. (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
  81. || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
  82. {
  83. best_match = me;
  84. best_match_len = len;
  85. }
  86. }
  87. }
  88. if (best_match) {
  89. d->best_match = best_match;
  90. d->found = TRUE;
  91. }
  92. }
  93. }
  94. /* Returns TRUE if name is in list */
  95. int
  96. np_find_name (struct name_list *list, const char *name)
  97. {
  98. const struct name_list *n;
  99. if (list == NULL || name == NULL) {
  100. return FALSE;
  101. }
  102. for (n = list; n; n = n->next) {
  103. if (!strcmp(name, n->name)) {
  104. return TRUE;
  105. }
  106. }
  107. return FALSE;
  108. }