| 1 |
/** |
| 2 |
* collectd - src/utils/mount/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 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 |
| 18 |
* |
| 19 |
* Author: |
| 20 |
* Niki W. Waibel <[email protected]> |
| 21 |
**/ |
| 22 |
|
| 23 |
/* See below for instructions how to use the public functions. */ |
| 24 |
|
| 25 |
#ifndef COLLECTD_UTILS_MOUNT_H |
| 26 |
#define COLLECTD_UTILS_MOUNT_H 1 |
| 27 |
|
| 28 |
#include <stdio.h> |
| 29 |
#if HAVE_FS_INFO_H |
| 30 |
#include <fs_info.h> |
| 31 |
#endif |
| 32 |
#if HAVE_FSHELP_H |
| 33 |
#include <fshelp.h> |
| 34 |
#endif |
| 35 |
#if HAVE_PATHS_H |
| 36 |
#include <paths.h> |
| 37 |
#endif |
| 38 |
#if HAVE_MNTENT_H |
| 39 |
#include <mntent.h> |
| 40 |
#endif |
| 41 |
#if HAVE_MNTTAB_H |
| 42 |
#include <mnttab.h> |
| 43 |
#endif |
| 44 |
#if HAVE_SYS_FSTYP_H |
| 45 |
#include <sys/fstyp.h> |
| 46 |
#endif |
| 47 |
#if HAVE_SYS_FS_TYPES_H |
| 48 |
#include <sys/fs_types.h> |
| 49 |
#endif |
| 50 |
#if HAVE_SYS_MNTENT_H |
| 51 |
#include <sys/mntent.h> |
| 52 |
#endif |
| 53 |
#if HAVE_SYS_MNTTAB_H |
| 54 |
#include <sys/mnttab.h> |
| 55 |
#endif |
| 56 |
#if HAVE_SYS_MOUNT_H |
| 57 |
#include <sys/mount.h> |
| 58 |
#endif |
| 59 |
#if HAVE_SYS_STATFS_H |
| 60 |
#include <sys/statfs.h> |
| 61 |
#endif |
| 62 |
#if HAVE_SYS_VFS_H |
| 63 |
#include <sys/vfs.h> |
| 64 |
#endif |
| 65 |
#if HAVE_SYS_VFSTAB_H |
| 66 |
#include <sys/vfstab.h> |
| 67 |
#endif |
| 68 |
|
| 69 |
/* Collectd Utils Mount Type */ |
| 70 |
#define CUMT_UNKNOWN (0) |
| 71 |
#define CUMT_EXT2 (1) |
| 72 |
#define CUMT_EXT3 (2) |
| 73 |
#define CUMT_XFS (3) |
| 74 |
#define CUMT_UFS (4) |
| 75 |
#define CUMT_VXFS (5) |
| 76 |
#define CUMT_ZFS (6) |
| 77 |
|
| 78 |
typedef struct _cu_mount_t cu_mount_t; |
| 79 |
struct _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" */ |
| 85 |
cu_mount_t *next; |
| 86 |
}; |
| 87 |
|
| 88 |
cu_mount_t *cu_mount_getlist(cu_mount_t **list); |
| 89 |
/* |
| 90 |
DESCRIPTION |
| 91 |
The cu_mount_getlist() function creates a list |
| 92 |
of all mountpoints. |
| 93 |
|
| 94 |
If *list is NULL, a new list is created and *list is |
| 95 |
set to point to the first entry. |
| 96 |
|
| 97 |
If *list is not NULL, the list of mountpoints is appended |
| 98 |
and *list is not changed. |
| 99 |
|
| 100 |
RETURN VALUE |
| 101 |
The cu_mount_getlist() function returns a pointer to |
| 102 |
the last entry of the list, or NULL if an error has |
| 103 |
occured. |
| 104 |
|
| 105 |
NOTES |
| 106 |
In case of an error, *list is not modified. |
| 107 |
*/ |
| 108 |
|
| 109 |
void cu_mount_freelist(cu_mount_t *list); |
| 110 |
/* |
| 111 |
DESCRIPTION |
| 112 |
The cu_mount_freelist() function free()s all memory |
| 113 |
allocated by *list and *list itself as well. |
| 114 |
*/ |
| 115 |
|
| 116 |
char *cu_mount_checkoption(char *line, const char *keyword, int full); |
| 117 |
/* |
| 118 |
DESCRIPTION |
| 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 ','. |
| 125 |
|
| 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. |
| 128 |
|
| 129 |
RETURN VALUE |
| 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. |
| 133 |
|
| 134 |
NOTES |
| 135 |
Do *not* try to free() the pointer which is returned! It is |
| 136 |
just part of the string line. |
| 137 |
|
| 138 |
full should be set to 0 when matching options like: rw, quota, |
| 139 |
noatime. Set full to 1 when matching options like: loop=, |
| 140 |
gid=, commit=. |
| 141 |
|
| 142 |
EXAMPLES |
| 143 |
If line is "rw,usrquota,grpquota", keyword is "quota", NULL |
| 144 |
will be returned (independend of full). |
| 145 |
|
| 146 |
If line is "rw,usrquota,grpquota", keyword is "usrquota", |
| 147 |
a pointer to "usrquota,grpquota" is returned (independend |
| 148 |
of full). |
| 149 |
|
| 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()... |
| 154 |
*/ |
| 155 |
|
| 156 |
char *cu_mount_getoptionvalue(char *line, const char *keyword); |
| 157 |
/* |
| 158 |
DESCRIPTION |
| 159 |
The cu_mount_getoptionvalue() function can be used to grab |
| 160 |
a VALUE out of a mount option (line) like: |
| 161 |
loop=VALUE |
| 162 |
whereas "loop=" is the keyword. |
| 163 |
|
| 164 |
RETURN VALUE |
| 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. |
| 168 |
|
| 169 |
If the option keyword is not found, cu_mount_getoptionvalue() |
| 170 |
returns NULL; |
| 171 |
|
| 172 |
NOTES |
| 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 |
| 176 |
after use!!! |
| 177 |
*/ |
| 178 |
|
| 179 |
int cu_mount_type(const char *type); |
| 180 |
/* |
| 181 |
DESCRIPTION |
| 182 |
|
| 183 |
RETURN VALUE |
| 184 |
*/ |
| 185 |
|
| 186 |
#endif /* !COLLECTD_UTILS_MOUNT_H */ |