diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_disk.c | 15 | ||||
-rw-r--r-- | plugins/tests/.cvsignore | 1 | ||||
-rw-r--r-- | plugins/tests/test_disk.c | 115 | ||||
-rw-r--r-- | plugins/utils_disk.c | 54 | ||||
-rw-r--r-- | plugins/utils_disk.h | 19 |
5 files changed, 150 insertions, 54 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index f0a679d..8e9c1fc 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -74,21 +74,6 @@ static int show_local_fs = 0; | |||
74 | SunOs4.1.3, for one. It is *not* necessary on Linux. */ | 74 | SunOs4.1.3, for one. It is *not* necessary on Linux. */ |
75 | /* static int require_sync = 0; */ | 75 | /* static int require_sync = 0; */ |
76 | 76 | ||
77 | /* A filesystem type to display. */ | ||
78 | struct parameter_list | ||
79 | { | ||
80 | char *name; | ||
81 | int found; | ||
82 | int found_len; | ||
83 | uintmax_t w_df; | ||
84 | uintmax_t c_df; | ||
85 | double w_dfp; | ||
86 | double c_dfp; | ||
87 | double w_idfp; | ||
88 | double c_idfp; | ||
89 | struct parameter_list *name_next; | ||
90 | }; | ||
91 | |||
92 | /* Linked list of filesystem types to display. | 77 | /* Linked list of filesystem types to display. |
93 | If `fs_select_list' is NULL, list all types. | 78 | If `fs_select_list' is NULL, list all types. |
94 | This table is generated dynamically from command-line options, | 79 | This table is generated dynamically from command-line options, |
diff --git a/plugins/tests/.cvsignore b/plugins/tests/.cvsignore index 94b5122..6dc692f 100644 --- a/plugins/tests/.cvsignore +++ b/plugins/tests/.cvsignore | |||
@@ -1,4 +1,5 @@ | |||
1 | Makefile | 1 | Makefile |
2 | Makefile.in | 2 | Makefile.in |
3 | test_utils | 3 | test_utils |
4 | test_disk | ||
4 | .deps | 5 | .deps |
diff --git a/plugins/tests/test_disk.c b/plugins/tests/test_disk.c index 19cc3ac..8940236 100644 --- a/plugins/tests/test_disk.c +++ b/plugins/tests/test_disk.c | |||
@@ -27,16 +27,24 @@ main (int argc, char **argv) | |||
27 | { | 27 | { |
28 | struct name_list *exclude_filesystem=NULL; | 28 | struct name_list *exclude_filesystem=NULL; |
29 | struct name_list *exclude_fstype=NULL; | 29 | struct name_list *exclude_fstype=NULL; |
30 | struct name_list *dummy_mountlist = NULL; | ||
31 | struct name_list *temp_name; | ||
32 | struct parameter_list *paths = NULL; | ||
33 | struct parameter_list *p; | ||
30 | 34 | ||
31 | plan_tests(8); | 35 | struct mount_entry *dummy_mount_list; |
36 | struct mount_entry *me; | ||
37 | struct mount_entry **mtail = &dummy_mount_list; | ||
32 | 38 | ||
33 | ok( np_find_name(exclude_filesystem, "/var") == FALSE, "/var not in list"); | 39 | plan_tests(17); |
34 | np_add_name(&exclude_filesystem, "/var"); | 40 | |
35 | ok( np_find_name(exclude_filesystem, "/var") == TRUE, "is in list now"); | 41 | ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); |
42 | np_add_name(&exclude_filesystem, "/var/log"); | ||
43 | ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now"); | ||
36 | ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list"); | 44 | ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list"); |
37 | np_add_name(&exclude_filesystem, "/home"); | 45 | np_add_name(&exclude_filesystem, "/home"); |
38 | ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now"); | 46 | ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now"); |
39 | ok( np_find_name(exclude_filesystem, "/var") == TRUE, "/var still in list"); | 47 | ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list"); |
40 | 48 | ||
41 | ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list"); | 49 | ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list"); |
42 | np_add_name(&exclude_fstype, "iso9660"); | 50 | np_add_name(&exclude_fstype, "iso9660"); |
@@ -44,42 +52,73 @@ main (int argc, char **argv) | |||
44 | 52 | ||
45 | ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables"); | 53 | ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables"); |
46 | 54 | ||
47 | |||
48 | |||
49 | |||
50 | /* | 55 | /* |
51 | range = parse_range_string("6"); | 56 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { |
52 | ok( range != NULL, "'6' is valid range"); | 57 | printf("Name: %s\n", temp_name->name); |
53 | ok( range->start == 0, "Start correct"); | 58 | } |
54 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
55 | ok( range->end == 6, "End correct"); | ||
56 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
57 | free(range); | ||
58 | |||
59 | range = parse_range_string("-7:23"); | ||
60 | ok( range != NULL, "'-7:23' is valid range"); | ||
61 | ok( range->start == -7, "Start correct"); | ||
62 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
63 | ok( range->end == 23, "End correct"); | ||
64 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
65 | free(range); | ||
66 | |||
67 | range = parse_range_string(":5.75"); | ||
68 | ok( range != NULL, "':5.75' is valid range"); | ||
69 | ok( range->start == 0, "Start correct"); | ||
70 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | ||
71 | ok( range->end == 5.75, "End correct"); | ||
72 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
73 | free(range); | ||
74 | |||
75 | range = parse_range_string("~:-95.99"); | ||
76 | ok( range != NULL, "~:-95.99' is valid range"); | ||
77 | ok( range->start_infinity == TRUE, "Using negative infinity"); | ||
78 | ok( range->end == -95.99, "End correct (with rounding errors)"); | ||
79 | ok( range->end_infinity == FALSE, "Not using infinity"); | ||
80 | free(range); | ||
81 | */ | 59 | */ |
82 | 60 | ||
61 | me = (struct mount_entry *) malloc(sizeof *me); | ||
62 | me->me_devname = strdup("/dev/c0t0d0s0"); | ||
63 | me->me_mountdir = strdup("/"); | ||
64 | *mtail = me; | ||
65 | mtail = &me->me_next; | ||
66 | |||
67 | me = (struct mount_entry *) malloc(sizeof *me); | ||
68 | me->me_devname = strdup("/dev/c1t0d1s0"); | ||
69 | me->me_mountdir = strdup("/var"); | ||
70 | *mtail = me; | ||
71 | mtail = &me->me_next; | ||
72 | |||
73 | me = (struct mount_entry *) malloc(sizeof *me); | ||
74 | me->me_devname = strdup("/dev/c2t0d0s0"); | ||
75 | me->me_mountdir = strdup("/home"); | ||
76 | *mtail = me; | ||
77 | mtail = &me->me_next; | ||
78 | |||
79 | |||
80 | np_add_parameter(&paths, "/home/groups"); | ||
81 | np_add_parameter(&paths, "/var"); | ||
82 | np_add_parameter(&paths, "/tmp"); | ||
83 | np_add_parameter(&paths, "/home/tonvoon"); | ||
84 | np_add_parameter(&paths, "/dev/c2t0d0s0"); | ||
85 | |||
86 | np_set_best_match(paths, dummy_mount_list, FALSE); | ||
87 | for (p = paths; p; p = p->name_next) { | ||
88 | struct mount_entry *temp_me; | ||
89 | temp_me = p->best_match; | ||
90 | if (! strcmp(p->name, "/home/groups")) { | ||
91 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); | ||
92 | } else if (! strcmp(p->name, "/var")) { | ||
93 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); | ||
94 | } else if (! strcmp(p->name, "/tmp")) { | ||
95 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); | ||
96 | } else if (! strcmp(p->name, "/home/tonvoon")) { | ||
97 | ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); | ||
98 | } else if (! strcmp(p->name, "/dev/c2t0d0s0")) { | ||
99 | ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | paths = NULL; /* Bad boy - should free, but this is a test suite */ | ||
104 | np_add_parameter(&paths, "/home/groups"); | ||
105 | np_add_parameter(&paths, "/var"); | ||
106 | np_add_parameter(&paths, "/tmp"); | ||
107 | np_add_parameter(&paths, "/home/tonvoon"); | ||
108 | |||
109 | np_set_best_match(paths, dummy_mount_list, TRUE); | ||
110 | for (p = paths; p; p = p->name_next) { | ||
111 | if (! strcmp(p->name, "/home/groups")) { | ||
112 | ok( p->found == 0, "/home/groups correctly not found"); | ||
113 | } else if (! strcmp(p->name, "/var")) { | ||
114 | ok( p->found == 1, "/var found"); | ||
115 | } else if (! strcmp(p->name, "/tmp")) { | ||
116 | ok( p->found == 0, "/tmp correctly not found"); | ||
117 | } else if (! strcmp(p->name, "/home/tonvoon")) { | ||
118 | ok( p->found == 0, "/home/tonvoon not found"); | ||
119 | } | ||
120 | } | ||
121 | |||
83 | return exit_status(); | 122 | return exit_status(); |
84 | } | 123 | } |
85 | 124 | ||
diff --git a/plugins/utils_disk.c b/plugins/utils_disk.c index 6380df3..0a71d79 100644 --- a/plugins/utils_disk.c +++ b/plugins/utils_disk.c | |||
@@ -43,6 +43,60 @@ np_add_name (struct name_list **list, const char *name) | |||
43 | *list = new_entry; | 43 | *list = new_entry; |
44 | } | 44 | } |
45 | 45 | ||
46 | void | ||
47 | np_add_parameter(struct parameter_list **list, const char *name) | ||
48 | { | ||
49 | struct parameter_list *new_path; | ||
50 | new_path = (struct parameter_list *) malloc (sizeof *new_path); | ||
51 | new_path->name = (char *) name; | ||
52 | new_path->found = 0; | ||
53 | new_path->found_len = 0; | ||
54 | new_path->w_df = 0; | ||
55 | new_path->c_df = 0; | ||
56 | new_path->w_dfp = -1.0; | ||
57 | new_path->c_dfp = -1.0; | ||
58 | new_path->w_idfp = -1.0; | ||
59 | new_path->c_idfp = -1.0; | ||
60 | new_path->name_next = *list; | ||
61 | *list = new_path; | ||
62 | } | ||
63 | |||
64 | void | ||
65 | np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact) | ||
66 | { | ||
67 | struct parameter_list *d; | ||
68 | for (d = desired; d; d= d->name_next) { | ||
69 | struct mount_entry *me; | ||
70 | size_t name_len = strlen(d->name); | ||
71 | size_t best_match_len = 0; | ||
72 | struct mount_entry *best_match = NULL; | ||
73 | |||
74 | for (me = mount_list; me; me = me->me_next) { | ||
75 | size_t len = strlen (me->me_mountdir); | ||
76 | if ((exact == FALSE && (best_match_len <= len && len <= name_len && | ||
77 | (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) | ||
78 | || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) | ||
79 | { | ||
80 | best_match = me; | ||
81 | best_match_len = len; | ||
82 | } else { | ||
83 | len = strlen (me->me_devname); | ||
84 | if ((exact == FALSE && (best_match_len <= len && len <= name_len && | ||
85 | (len == 1 || strncmp (me->me_devname, d->name, len) == 0))) | ||
86 | || (exact == TRUE && strcmp(me->me_devname, d->name)==0)) | ||
87 | { | ||
88 | best_match = me; | ||
89 | best_match_len = len; | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | if (best_match) { | ||
94 | d->best_match = best_match; | ||
95 | d->found = TRUE; | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
46 | /* Returns TRUE if name is in list */ | 100 | /* Returns TRUE if name is in list */ |
47 | int | 101 | int |
48 | np_find_name (struct name_list *list, const char *name) | 102 | np_find_name (struct name_list *list, const char *name) |
diff --git a/plugins/utils_disk.h b/plugins/utils_disk.h index f173c91..c1919fe 100644 --- a/plugins/utils_disk.h +++ b/plugins/utils_disk.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* Header file for utils_disk */ | 1 | /* Header file for utils_disk */ |
2 | 2 | ||
3 | #include "mountlist.h" | ||
3 | 4 | ||
4 | struct name_list | 5 | struct name_list |
5 | { | 6 | { |
@@ -7,6 +8,22 @@ struct name_list | |||
7 | struct name_list *next; | 8 | struct name_list *next; |
8 | }; | 9 | }; |
9 | 10 | ||
11 | struct parameter_list | ||
12 | { | ||
13 | char *name; | ||
14 | int found; | ||
15 | int found_len; | ||
16 | uintmax_t w_df; | ||
17 | uintmax_t c_df; | ||
18 | double w_dfp; | ||
19 | double c_dfp; | ||
20 | double w_idfp; | ||
21 | double c_idfp; | ||
22 | struct mount_entry *best_match; | ||
23 | struct parameter_list *name_next; | ||
24 | }; | ||
25 | |||
10 | void np_add_name (struct name_list **list, const char *name); | 26 | void np_add_name (struct name_list **list, const char *name); |
11 | int np_find_name (struct name_list *list, const char *name); | 27 | int np_find_name (struct name_list *list, const char *name); |
12 | 28 | void np_add_parameter(struct parameter_list **list, const char *name); | |
29 | int search_parameter_list (struct parameter_list *list, const char *name); | ||