2 * collectd - src/utils_mount.h
3 * Copyright (C) 2005,2006 Niki W. Waibel
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Niki W. Waibel <niki.waibel@gmx.net>
23 /* See below for instructions how to use the public functions. */
25 #ifndef COLLECTD_UTILS_MOUNT_H
26 #define COLLECTD_UTILS_MOUNT_H 1
45 # include <sys/fstyp.h>
47 #if HAVE_SYS_FS_TYPES_H
48 # include <sys/fs_types.h>
51 # include <sys/mntent.h>
54 # include <sys/mnttab.h>
57 # include <sys/mount.h>
60 # include <sys/statfs.h>
66 # include <sys/vfstab.h>
69 /* Collectd Utils Mount Type */
70 #define CUMT_UNKNOWN (0)
78 typedef struct _cu_mount_t cu_mount_t;
80 char *dir; /* "/sys" or "/" */
81 char *spec_device; /* "LABEL=/" or "none" or "proc" or "/dev/hda1" */
82 char *device; /* "none" or "proc" or "/dev/hda1" */
83 char *type; /* "sysfs" or "ext3" */
84 char *options; /* "rw,noatime,commit=600,quota,grpquota" */
88 cu_mount_t *cu_mount_getlist(cu_mount_t **list);
91 The cu_mount_getlist() function creates a list
94 If *list is NULL, a new list is created and *list is
95 set to point to the first entry.
97 If *list is not NULL, the list of mountpoints is appended
98 and *list is not changed.
101 The cu_mount_getlist() function returns a pointer to
102 the last entry of the list, or NULL if an error has
106 In case of an error, *list is not modified.
109 void cu_mount_freelist(cu_mount_t *list);
112 The cu_mount_freelist() function free()s all memory
113 allocated by *list and *list itself as well.
116 char *cu_mount_checkoption(char *line, const char *keyword, int full);
119 The cu_mount_checkoption() function is a replacement of
120 char *hasmntopt(const struct mntent *mnt, const char *opt).
121 In fact hasmntopt() just looks for the first occurrence of the
122 characters at opt in mnt->mnt_opts. cu_mount_checkoption()
123 checks for the *option* keyword in line, starting at the
124 first character of line or after a ','.
126 If full is not 0 then also the end of keyword has to match
127 either the end of line or a ',' after keyword.
130 The cu_mount_checkoption() function returns a pointer into
131 string line if a match of keyword is found. If no match is
132 found cu_mount_checkoption() returns NULL.
135 Do *not* try to free() the pointer which is returned! It is
136 just part of the string line.
138 full should be set to 0 when matching options like: rw, quota,
139 noatime. Set full to 1 when matching options like: loop=,
143 If line is "rw,usrquota,grpquota", keyword is "quota", NULL
144 will be returned (independend of full).
146 If line is "rw,usrquota,grpquota", keyword is "usrquota",
147 a pointer to "usrquota,grpquota" is returned (independend
150 If line is "rw,loop=/dev/loop1,quota", keyword is "loop="
151 and full is 0, then a pointer to "loop=/dev/loop1,quota"
152 is returned. If full is not 0 then NULL is returned. But
153 maybe you might want to try cu_mount_getoptionvalue()...
156 char *cu_mount_getoptionvalue(char *line, const char *keyword);
159 The cu_mount_getoptionvalue() function can be used to grab
160 a VALUE out of a mount option (line) like:
162 whereas "loop=" is the keyword.
165 If the cu_mount_getoptionvalue() function can find the option
166 keyword in line, then memory is allocated for the value of
167 that option and a pointer to that value is returned.
169 If the option keyword is not found, cu_mount_getoptionvalue()
173 Internally it calls cu_mount_checkoption(), then it
174 allocates memory for VALUE and returns a pointer to that
175 string. So *do not forget* to free() the memory returned
179 int cu_mount_type(const char *type);
187 #endif /* !COLLECTD_UTILS_MOUNT_H */