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 #ifndef COLLECTD_UTILS_MOUNT_H
27 #define COLLECTD_UTILS_MOUNT_H 1
46 # include <sys/fstyp.h>
48 #if HAVE_SYS_FS_TYPES_H
49 # include <sys/fs_types.h>
52 # include <sys/mntent.h>
55 # include <sys/mnttab.h>
58 # include <sys/mount.h>
61 # include <sys/statfs.h>
67 # include <sys/vfstab.h>
70 /* Collectd Utils Mount Type */
71 #define CUMT_UNKNOWN (0)
79 typedef struct _cu_mount_t 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" */
89 cu_mount_t *cu_mount_getlist(cu_mount_t **list);
92 The cu_mount_getlist() function creates a list
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.
102 The cu_mount_getlist() function returns a pointer to
103 the last entry of the list, or NULL if an error has
107 In case of an error, *list is not modified.
110 void cu_mount_freelist(cu_mount_t *list);
113 The cu_mount_freelist() function free()s all memory
114 allocated by *list and *list itself as well.
117 char *cu_mount_checkoption(char *line, char *keyword, int full);
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 occurrence 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.
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.
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=,
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
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()...
157 char *cu_mount_getoptionvalue(char *line, char *keyword);
160 The cu_mount_getoptionvalue() function can be used to grab
161 a VALUE out of a mount option (line) like:
163 whereas "loop=" is the keyword.
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()
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
180 int cu_mount_type(const char *type);
188 #endif /* !COLLECTD_UTILS_MOUNT_H */