summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.d/utils_disk.h
blob: 6831d1fda1d777e8f8973346643672d5a4fd9900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
/* Header file for utils_disk */

#include "../../config.h"
#include "../../gl/mountlist.h"
#include "../../lib/utils_base.h"
#include "../../lib/output.h"
#include "regex.h"
#include <stdint.h>

typedef unsigned long long byte_unit;

typedef enum {
	Humanized,
	Bytes,
	KibiBytes,
	MebiBytes,
	GibiBytes,
	TebiBytes,
	PebiBytes,
	ExbiBytes,
	KiloBytes,
	MegaBytes,
	GigaBytes,
	TeraBytes,
	PetaBytes,
	ExaBytes,
} byte_unit_enum;

typedef struct name_list string_list;
struct name_list {
	char *name;
	string_list *next;
};

struct regex_list {
	regex_t regex;
	struct regex_list *next;
};

typedef struct parameter_list parameter_list_elem;
struct parameter_list {
	char *name;
	char *group;

	mp_thresholds freespace_units;
	mp_thresholds freespace_percent;
	mp_thresholds freeinodes_percent;

	struct mount_entry *best_match;

	uintmax_t inodes_free_to_root;
	uintmax_t inodes_free;
	uintmax_t inodes_used;
	uintmax_t inodes_total;

	uint64_t used_bytes;
	uint64_t free_bytes;
	uint64_t total_bytes;

	parameter_list_elem *next;
	parameter_list_elem *prev;
};

typedef struct {
	size_t length;
	parameter_list_elem *first;
} filesystem_list;

filesystem_list filesystem_list_init();

typedef struct {
	char *name;
	char *filesystem_type;
	bool is_group;

	mp_thresholds freespace_bytes_thresholds;
	mp_thresholds freespace_percent_thresholds;
	mp_thresholds freeinodes_percent_thresholds;

	uintmax_t inodes_free_to_root;
	uintmax_t inodes_free;
	uintmax_t inodes_used;
	uintmax_t inodes_total;

	uintmax_t used_bytes;
	uintmax_t free_bytes;
	uintmax_t total_bytes;
} measurement_unit;

typedef struct measurement_unit_list measurement_unit_list;
struct measurement_unit_list {
	measurement_unit unit;
	measurement_unit_list *next;
};

typedef struct {
	// Output options
	bool erronly;
	bool display_mntp;
	/* show only local filesystems.  */
	bool show_local_fs;
	/* show only local filesystems but call stat() on remote ones. */
	bool stat_remote_fs;
	bool display_inodes_perfdata;

	bool exact_match;
	bool freespace_ignore_reserved;

	bool ignore_missing;
	bool path_ignored;

	/* Linked list of filesystem types to omit.
	   If the list is empty, don't exclude any types.  */
	struct regex_list *fs_exclude_list;
	/* Linked list of filesystem types to check.
	   If the list is empty, include all types.  */
	struct regex_list *fs_include_list;
	struct name_list *device_path_exclude_list;
	filesystem_list path_select_list;
	/* Linked list of mounted filesystems. */
	struct mount_entry *mount_list;
	struct name_list *seen;

	byte_unit_enum display_unit;
	// byte_unit unit;

	bool output_format_is_set;
	mp_output_format output_format;
} check_disk_config;

void np_add_name(struct name_list **list, const char *name);
bool np_find_name(struct name_list *list, const char *name);
bool np_seen_name(struct name_list *list, const char *name);
int np_add_regex(struct regex_list **list, const char *regex, int cflags);
bool np_find_regmatch(struct regex_list *list, const char *name);

parameter_list_elem parameter_list_init(const char *);

parameter_list_elem *mp_int_fs_list_append(filesystem_list *list, const char *name);
parameter_list_elem *mp_int_fs_list_find(filesystem_list list, const char *name);
parameter_list_elem *mp_int_fs_list_del(filesystem_list *list, parameter_list_elem *item);
parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current);
void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, bool exact);

measurement_unit measurement_unit_init();
measurement_unit_list *add_measurement_list(measurement_unit_list *list, measurement_unit elem);
measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, parameter_list_elem filesystem);
measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, bool display_mntp);

int search_parameter_list(parameter_list_elem *list, const char *name);
bool np_regex_match_mount_entry(struct mount_entry *, regex_t *);

char *get_unit_string(byte_unit_enum);
check_disk_config check_disk_config_init();

char *humanize_byte_value(unsigned long long value, bool use_si_units);