Code

Merge remote-tracking branch 'github/pr/387'
[collectd.git] / src / utils_mount.h
1 /**
2  * collectd - src/utils_mount.h
3  * Copyright (C) 2005,2006  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 **/
24 /* See below for instructions how to use the public functions. */
26 #ifndef COLLECTD_UTILS_MOUNT_H
27 #define COLLECTD_UTILS_MOUNT_H 1
29 #include <stdio.h>
30 #if HAVE_FS_INFO_H
31 # include <fs_info.h>
32 #endif
33 #if HAVE_FSHELP_H
34 # include <fshelp.h>
35 #endif
36 #if HAVE_PATHS_H
37 # include <paths.h>
38 #endif
39 #if HAVE_MNTENT_H
40 # include <mntent.h>
41 #endif
42 #if HAVE_MNTTAB_H
43 # include <mnttab.h>
44 #endif
45 #if HAVE_SYS_FSTYP_H
46 # include <sys/fstyp.h>
47 #endif
48 #if HAVE_SYS_FS_TYPES_H
49 # include <sys/fs_types.h>
50 #endif
51 #if HAVE_SYS_MNTENT_H
52 # include <sys/mntent.h>
53 #endif
54 #if HAVE_SYS_MNTTAB_H
55 # include <sys/mnttab.h>
56 #endif
57 #if HAVE_SYS_MOUNT_H
58 # include <sys/mount.h>
59 #endif
60 #if HAVE_SYS_STATFS_H
61 # include <sys/statfs.h>
62 #endif
63 #if HAVE_SYS_VFS_H
64 # include <sys/vfs.h>
65 #endif
66 #if HAVE_SYS_VFSTAB_H
67 # include <sys/vfstab.h>
68 #endif
70 /* Collectd Utils Mount Type */
71 #define CUMT_UNKNOWN (0)
72 #define CUMT_EXT2    (1)
73 #define CUMT_EXT3    (2)
74 #define CUMT_XFS     (3)
75 #define CUMT_UFS     (4)
76 #define CUMT_VXFS    (5)
77 #define CUMT_ZFS     (6)
79 typedef struct _cu_mount_t cu_mount_t;
80 struct _cu_mount_t {
81         char *dir;         /* "/sys" or "/" */
82         char *spec_device; /* "LABEL=/" or "none" or "proc" or "/dev/hda1" */
83         char *device;      /* "none" or "proc" or "/dev/hda1" */
84         char *type;        /* "sysfs" or "ext3" */
85         char *options;     /* "rw,noatime,commit=600,quota,grpquota" */
86         cu_mount_t *next;
87 };
89 cu_mount_t *cu_mount_getlist(cu_mount_t **list);
90 /*
91   DESCRIPTION
92         The cu_mount_getlist() function creates a list
93         of all mountpoints.
95         If *list is NULL, a new list is created and *list is
96         set to point to the first entry.
98         If *list is not NULL, the list of mountpoints is appended
99         and *list is not changed.
101   RETURN VALUE
102         The cu_mount_getlist() function returns a pointer to
103         the last entry of the list, or NULL if an error has
104         occured.
106   NOTES
107         In case of an error, *list is not modified.
108 */
110 void cu_mount_freelist(cu_mount_t *list);
111 /*
112   DESCRIPTION
113         The cu_mount_freelist() function free()s all memory
114         allocated by *list and *list itself as well.
115 */
117 char *cu_mount_checkoption(char *line, char *keyword, int full);
118 /*
119   DESCRIPTION
120         The cu_mount_checkoption() function is a replacement of
121         char *hasmntopt(const struct mntent *mnt, const char *opt).
122         In fact hasmntopt() just looks for the first occurence of the
123         characters at opt in mnt->mnt_opts. cu_mount_checkoption()
124         checks for the *option* keyword in line, starting at the
125         first character of line or after a ','.
127         If full is not 0 then also the end of keyword has to match
128         either the end of line or a ',' after keyword.
130   RETURN VALUE
131         The cu_mount_checkoption() function returns a pointer into
132         string line if a match of keyword is found. If no match is
133         found cu_mount_checkoption() returns NULL.
135   NOTES
136         Do *not* try to free() the pointer which is returned! It is
137         just part of the string line.
139         full should be set to 0 when matching options like: rw, quota,
140         noatime. Set full to 1 when matching options like: loop=,
141         gid=, commit=.
143   EXAMPLES
144         If line is "rw,usrquota,grpquota", keyword is "quota", NULL
145         will be returned (independend of full).
147         If line is "rw,usrquota,grpquota", keyword is "usrquota",
148         a pointer to "usrquota,grpquota" is returned (independend
149         of full).
151         If line is "rw,loop=/dev/loop1,quota", keyword is "loop="
152         and full is 0, then a pointer to "loop=/dev/loop1,quota"
153         is returned. If full is not 0 then NULL is returned. But
154         maybe you might want to try cu_mount_getoptionvalue()...
155 */
157 char *cu_mount_getoptionvalue(char *line, char *keyword);
158 /*
159   DESCRIPTION
160         The cu_mount_getoptionvalue() function can be used to grab
161         a VALUE out of a mount option (line) like:
162                 loop=VALUE
163         whereas "loop=" is the keyword.
165   RETURN VALUE
166         If the cu_mount_getoptionvalue() function can find the option
167         keyword in line, then memory is allocated for the value of
168         that option and a pointer to that value is returned.
170         If the option keyword is not found, cu_mount_getoptionvalue()
171         returns NULL;
173   NOTES
174         Internally it calls cu_mount_checkoption(), then it
175         allocates memory for VALUE and returns a pointer to that
176         string. So *do not forget* to free() the memory returned
177         after use!!!
178 */
180 int cu_mount_type(const char *type);
181 /*
182   DESCRIPTION
184   RETURN VALUE
185 */
188 #endif /* !COLLECTD_UTILS_MOUNT_H */