Copied src/utils_mount.[ch] from quota-branch to trunk
[collectd.git] / src / utils_mount.h
1 /**
2  * collectd - src/utils_mount.h
3  * Copyright (C) 2005  Niki W. Waibel
4  *
5  * This program is free software; you can redistribute it and/
6  * or modify it under the terms of the GNU General Public Li-
7  * cence as published by the Free Software Foundation; either
8  * version 2 of the Licence, or any later version.
9  *
10  * This program is distributed in the hope that it will be use-
11  * ful, but WITHOUT ANY WARRANTY; without even the implied war-
12  * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public Licence for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * Licence along with this program; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
18  * USA.
19  *
20  * Author:
21  *   Niki W. Waibel <niki.waibel@gmx.net>
22 **/
23
24 /* See below for instructions how to use the public functions. */
25
26 #if !COLLECTD_UTILS_MOUNT_H
27 #define COLLECTD_UTILS_MOUNT_H 1
28
29 #include "common.h"
30
31 #if HAVE_FS_INFO_H
32 # include <fs_info.h>
33 #endif
34 #if HAVE_FSHELP_H
35 # include <fshelp.h>
36 #endif
37 #if HAVE_PATHS_H
38 # include <paths.h>
39 #endif
40 #if HAVE_MNTENT_H
41 # include <mntent.h>
42 #endif
43 #if HAVE_MNTTAB_H
44 # include <mnttab.h>
45 #endif
46 #if HAVE_SYS_FSTYP_H
47 # include <sys/fstyp.h>
48 #endif
49 #if HAVE_SYS_FS_TYPES_H
50 # include <sys/fs_types.h>
51 #endif
52 #if HAVE_SYS_MNTENT_H
53 # include <sys/mntent.h>
54 #endif
55 #if HAVE_SYS_MNTTAB_H
56 # include <sys/mnttab.h>
57 #endif
58 #if HAVE_SYS_MOUNT_H
59 # include <sys/mount.h>
60 #endif
61 #if HAVE_SYS_STATFS_H
62 # include <sys/statfs.h>
63 #endif
64 #if HAVE_SYS_VFS_H
65 # include <sys/vfs.h>
66 #endif
67 #if HAVE_SYS_VFSTAB_H
68 # include <sys/vfstab.h>
69 #endif
70
71 /* Collectd Utils Mount Type */
72 #define CUMT_UNKNOWN (0)
73 #define CUMT_EXT2    (1)
74 #define CUMT_EXT3    (2)
75 #define CUMT_XFS     (3)
76 #define CUMT_UFS     (4)
77 #define CUMT_VXFS    (5)
78 #define CUMT_ZFS     (6)
79
80 typedef struct _cu_mount_t cu_mount_t;
81 struct _cu_mount_t {
82         char *dir;         /* "/sys" or "/" */
83         char *spec_device; /* "LABEL=/" or "none" or "proc" or "/dev/hda1" */
84         char *device;      /* "none" or "proc" or "/dev/hda1" */
85         char *type;        /* "sysfs" or "ext3" */
86         char *options;     /* "rw,noatime,commit=600,quota,grpquota" */
87         cu_mount_t *next;
88 };
89
90 cu_mount_t *cu_mount_getlist(cu_mount_t **list);
91 /*
92   DESCRIPTION
93         The cu_mount_getlist() function creates a list
94         of all mountpoints.
95
96         If *list is NULL, a new list is created and *list is
97         set to point to the first entry.
98
99         If *list is not NULL, the list of mountpoints is appended
100         and *list is not changed.
101
102   RETURN VALUE
103         The cu_mount_getlist() function returns a pointer to
104         the last entry of the list, or NULL if an error has
105         occured.
106
107   NOTES
108         In case of an error, *list is not modified.
109 */
110
111 void cu_mount_freelist(cu_mount_t *list);
112 /*
113   DESCRIPTION
114         The cu_mount_freelist() function free()s all memory
115         allocated by *list and *list itself as well.
116 */
117
118 char *cu_mount_checkoption(char *line, char *keyword, int full);
119 /*
120   DESCRIPTION
121         The cu_mount_checkoption() function is a replacement of
122         char *hasmntopt(const struct mntent *mnt, const char *opt).
123         In fact hasmntopt() just looks for the first occurence of the
124         characters at opt in mnt->mnt_opts. cu_mount_checkoption()
125         checks for the *option* keyword in line, starting at the
126         first character of line or after a ','.
127
128         If full is not 0 then also the end of keyword has to match
129         either the end of line or a ',' after keyword.
130
131   RETURN VALUE
132         The cu_mount_checkoption() function returns a pointer into
133         string line if a match of keyword is found. If no match is
134         found cu_mount_checkoption() returns NULL.
135
136   NOTES
137         Do *not* try to free() the pointer which is returned! It is
138         just part of the string line.
139
140         full should be set to 0 when matching options like: rw, quota,
141         noatime. Set full to 1 when matching options like: loop=,
142         gid=, commit=.
143
144   EXAMPLES
145         If line is "rw,usrquota,grpquota", keyword is "quota", NULL
146         will be returned (independend of full).
147
148         If line is "rw,usrquota,grpquota", keyword is "usrquota",
149         a pointer to "usrquota,grpquota" is returned (independend
150         of full).
151
152         If line is "rw,loop=/dev/loop1,quota", keyword is "loop="
153         and full is 0, then a pointer to "loop=/dev/loop1,quota"
154         is returned. If full is not 0 then NULL is returned. But
155         maybe you might want to try cu_mount_getoptionvalue()...
156 */
157
158 char *cu_mount_getoptionvalue(char *line, char *keyword);
159 /*
160   DESCRIPTION
161         The cu_mount_getoptionvalue() function can be used to grab
162         a VALUE out of a mount option (line) like:
163                 loop=VALUE
164         whereas "loop=" is the keyword.
165
166   RETURN VALUE
167         If the cu_mount_getoptionvalue() function can find the option
168         keyword in line, then memory is allocated for the value of
169         that option and a pointer to that value is returned.
170
171         If the option keyword is not found, cu_mount_getoptionvalue()
172         returns NULL;
173
174   NOTES
175         Internally it calls cu_mount_checkoption(), then it
176         allocates memory for VALUE and returns a pointer to that
177         string. So *do not forget* to free() the memory returned
178         after use!!!
179 */
180
181 int cu_mount_type(const char *type);
182 /*
183   DESCRIPTION
184
185   RETURN VALUE
186 */
187
188
189 #endif /* !COLLECTD_UTILS_MOUNT_H */
190