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
16 * Licence along with this program; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * Niki W. Waibel <niki.waibel@gmx.net>
24 /* See below for instructions how to use the public functions. */
26 #if !COLLECTD_UTILS_MOUNT_H
27 #define COLLECTD_UTILS_MOUNT_H 1
47 # include <sys/fstyp.h>
49 #if HAVE_SYS_FS_TYPES_H
50 # include <sys/fs_types.h>
53 # include <sys/mntent.h>
56 # include <sys/mnttab.h>
59 # include <sys/mount.h>
62 # include <sys/statfs.h>
68 # include <sys/vfstab.h>
71 /* Collectd Utils Mount Type */
72 #define CUMT_UNKNOWN (0)
80 typedef struct _cu_mount_t 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" */
90 cu_mount_t *cu_mount_getlist(cu_mount_t **list);
93 The cu_mount_getlist() function creates a list
96 If *list is NULL, a new list is created and *list is
97 set to point to the first entry.
99 If *list is not NULL, the list of mountpoints is appended
100 and *list is not changed.
103 The cu_mount_getlist() function returns a pointer to
104 the last entry of the list, or NULL if an error has
108 In case of an error, *list is not modified.
111 void cu_mount_freelist(cu_mount_t *list);
114 The cu_mount_freelist() function free()s all memory
115 allocated by *list and *list itself as well.
118 char *cu_mount_checkoption(char *line, char *keyword, int full);
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 ','.
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.
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.
137 Do *not* try to free() the pointer which is returned! It is
138 just part of the string line.
140 full should be set to 0 when matching options like: rw, quota,
141 noatime. Set full to 1 when matching options like: loop=,
145 If line is "rw,usrquota,grpquota", keyword is "quota", NULL
146 will be returned (independend of full).
148 If line is "rw,usrquota,grpquota", keyword is "usrquota",
149 a pointer to "usrquota,grpquota" is returned (independend
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()...
158 char *cu_mount_getoptionvalue(char *line, char *keyword);
161 The cu_mount_getoptionvalue() function can be used to grab
162 a VALUE out of a mount option (line) like:
164 whereas "loop=" is the keyword.
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.
171 If the option keyword is not found, cu_mount_getoptionvalue()
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
181 int cu_mount_type(const char *type);
189 #endif /* !COLLECTD_UTILS_MOUNT_H */