2007-04-05 16:48:42 +05:30
|
|
|
/*
|
|
|
|
mountinfo.c
|
|
|
|
Obtains information about mounted filesystems.
|
|
|
|
*/
|
|
|
|
|
2008-01-14 10:35:22 +05:30
|
|
|
/*
|
2008-03-26 23:23:37 +05:30
|
|
|
* Copyright 2007-2008 Roy Marples <roy@marples.name>
|
2007-11-14 20:52:04 +05:30
|
|
|
* All rights reserved
|
|
|
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2007-07-31 22:10:32 +05:30
|
|
|
#include <sys/types.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <sys/param.h>
|
2008-01-10 04:52:04 +05:30
|
|
|
|
|
|
|
#if defined(__DragonFly__) || defined(__FreeBSD__)
|
|
|
|
# include <sys/ucred.h>
|
|
|
|
# include <sys/mount.h>
|
2008-01-14 10:35:22 +05:30
|
|
|
# define F_FLAGS f_flags
|
2008-01-10 04:52:04 +05:30
|
|
|
#elif defined(BSD)
|
|
|
|
# include <sys/statvfs.h>
|
|
|
|
# define statfs statvfs
|
|
|
|
# define F_FLAGS f_flag
|
2007-10-09 21:03:05 +05:30
|
|
|
#elif defined (__linux__)
|
|
|
|
#include <mntent.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
2007-04-12 15:38:42 +05:30
|
|
|
#include <getopt.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <limits.h>
|
2008-03-16 22:30:56 +05:30
|
|
|
#include <regex.h>
|
2007-04-05 16:48:42 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-07-31 21:35:56 +05:30
|
|
|
#include "builtins.h"
|
2008-01-06 19:17:39 +05:30
|
|
|
#include "einfo.h"
|
2007-04-05 16:48:42 +05:30
|
|
|
#include "rc.h"
|
2008-01-06 19:17:39 +05:30
|
|
|
#include "rc-misc.h"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2008-02-12 01:44:09 +05:30
|
|
|
extern const char *applet;
|
2007-12-18 23:31:05 +05:30
|
|
|
|
2007-09-18 14:50:30 +05:30
|
|
|
typedef enum {
|
|
|
|
mount_from,
|
|
|
|
mount_to,
|
|
|
|
mount_fstype,
|
|
|
|
mount_options
|
|
|
|
} mount_type;
|
|
|
|
|
2007-10-09 21:03:05 +05:30
|
|
|
typedef enum {
|
|
|
|
net_ignore,
|
|
|
|
net_yes,
|
|
|
|
net_no
|
|
|
|
} net_opts;
|
|
|
|
|
2007-09-18 14:50:30 +05:30
|
|
|
struct args {
|
|
|
|
regex_t *node_regex;
|
|
|
|
regex_t *skip_node_regex;
|
|
|
|
regex_t *fstype_regex;
|
|
|
|
regex_t *skip_fstype_regex;
|
|
|
|
regex_t *options_regex;
|
|
|
|
regex_t *skip_options_regex;
|
2008-03-16 22:30:56 +05:30
|
|
|
RC_STRINGLIST *mounts;
|
2007-09-18 14:50:30 +05:30
|
|
|
mount_type mount_type;
|
2007-10-09 21:03:05 +05:30
|
|
|
net_opts netdev;
|
2007-09-18 14:50:30 +05:30
|
|
|
};
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
static int process_mount(RC_STRINGLIST *list, struct args *args,
|
|
|
|
char *from, char *to, char *fstype, char *options,
|
|
|
|
int netdev)
|
2007-09-18 14:50:30 +05:30
|
|
|
{
|
|
|
|
char *p;
|
2008-03-16 22:30:56 +05:30
|
|
|
RC_STRING *s;
|
2007-09-18 14:50:30 +05:30
|
|
|
|
|
|
|
errno = ENOENT;
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
/* Skip the really silly rootfs */
|
2008-03-16 22:30:56 +05:30
|
|
|
if (strcmp(fstype, "rootfs") == 0)
|
|
|
|
return -1;
|
2007-09-18 14:50:30 +05:30
|
|
|
#endif
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
if (args->netdev == net_yes &&
|
|
|
|
(netdev != -1 || TAILQ_FIRST(args->mounts)))
|
|
|
|
{
|
2007-10-09 21:03:05 +05:30
|
|
|
if (netdev != 0)
|
2008-03-16 22:30:56 +05:30
|
|
|
return 1;
|
|
|
|
} else if (args->netdev == net_no &&
|
|
|
|
(netdev != -1 || TAILQ_FIRST(args->mounts)))
|
|
|
|
{
|
2007-10-09 21:03:05 +05:30
|
|
|
if (netdev != 1)
|
2008-03-16 22:30:56 +05:30
|
|
|
return 1;
|
2007-10-09 21:03:05 +05:30
|
|
|
} else {
|
|
|
|
if (args->node_regex &&
|
2008-03-16 22:30:56 +05:30
|
|
|
regexec(args->node_regex, from, 0, NULL, 0) != 0)
|
|
|
|
return 1;
|
2007-10-09 21:03:05 +05:30
|
|
|
if (args->skip_node_regex &&
|
2008-03-16 22:30:56 +05:30
|
|
|
regexec(args->skip_node_regex, from, 0, NULL, 0) == 0)
|
|
|
|
return 1;
|
2007-10-09 21:03:05 +05:30
|
|
|
|
|
|
|
if (args->fstype_regex &&
|
2008-03-16 22:30:56 +05:30
|
|
|
regexec(args->fstype_regex, fstype, 0, NULL, 0) != 0)
|
|
|
|
return -1;
|
2007-10-09 21:03:05 +05:30
|
|
|
if (args->skip_fstype_regex &&
|
2008-03-16 22:30:56 +05:30
|
|
|
regexec(args->skip_fstype_regex, fstype, 0, NULL, 0) == 0)
|
|
|
|
return -1;
|
2007-09-18 14:50:30 +05:30
|
|
|
|
2007-10-09 21:03:05 +05:30
|
|
|
if (args->options_regex &&
|
2008-03-16 22:30:56 +05:30
|
|
|
regexec(args->options_regex, options, 0, NULL, 0) != 0)
|
|
|
|
return -1;
|
2007-10-09 21:03:05 +05:30
|
|
|
if (args->skip_options_regex &&
|
2008-03-16 22:30:56 +05:30
|
|
|
regexec(args->skip_options_regex, options, 0, NULL, 0) == 0)
|
|
|
|
return -1;
|
2007-10-09 21:03:05 +05:30
|
|
|
}
|
2007-09-18 14:50:30 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
if (TAILQ_FIRST(args->mounts)) {
|
|
|
|
TAILQ_FOREACH(s, args->mounts, entries)
|
|
|
|
if (strcmp(s->value, to) == 0)
|
2007-09-18 14:50:30 +05:30
|
|
|
break;
|
2008-03-16 22:30:56 +05:30
|
|
|
if (! s)
|
|
|
|
return -1;
|
2007-09-18 14:50:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
switch (args->mount_type) {
|
2008-03-16 22:30:56 +05:30
|
|
|
case mount_from:
|
|
|
|
p = from;
|
|
|
|
break;
|
|
|
|
case mount_to:
|
|
|
|
p = to;
|
|
|
|
break;
|
|
|
|
case mount_fstype:
|
|
|
|
p = fstype;
|
|
|
|
break;
|
|
|
|
case mount_options:
|
|
|
|
p = options;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
p = NULL;
|
|
|
|
errno = EINVAL;
|
|
|
|
break;
|
2007-09-18 14:50:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
errno = 0;
|
2008-03-16 22:30:56 +05:30
|
|
|
rc_stringlist_add(list, p);
|
|
|
|
return 0;
|
2007-09-18 14:50:30 +05:30
|
|
|
}
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
return -1;
|
2007-09-18 14:50:30 +05:30
|
|
|
}
|
2007-04-12 15:38:42 +05:30
|
|
|
|
2008-01-14 10:35:22 +05:30
|
|
|
#ifdef BSD
|
2007-09-18 14:50:30 +05:30
|
|
|
|
|
|
|
/* Translate the mounted options to english
|
|
|
|
* This is taken directly from FreeBSD mount.c */
|
|
|
|
static struct opt {
|
|
|
|
int o_opt;
|
|
|
|
const char *o_name;
|
|
|
|
} optnames[] = {
|
|
|
|
{ MNT_ASYNC, "asynchronous" },
|
|
|
|
{ MNT_EXPORTED, "NFS exported" },
|
|
|
|
{ MNT_LOCAL, "local" },
|
|
|
|
{ MNT_NOATIME, "noatime" },
|
|
|
|
{ MNT_NOEXEC, "noexec" },
|
|
|
|
{ MNT_NOSUID, "nosuid" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#ifdef MNT_NOSYMFOLLOW
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_NOSYMFOLLOW, "nosymfollow" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#endif
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_QUOTA, "with quotas" },
|
|
|
|
{ MNT_RDONLY, "read-only" },
|
|
|
|
{ MNT_SYNCHRONOUS, "synchronous" },
|
|
|
|
{ MNT_UNION, "union" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#ifdef MNT_NOCLUSTERR
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_NOCLUSTERR, "noclusterr" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#endif
|
|
|
|
#ifdef MNT_NOCLUSTERW
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_NOCLUSTERW, "noclusterw" },
|
2008-01-14 10:35:22 +05:30
|
|
|
#endif
|
2008-01-10 04:52:04 +05:30
|
|
|
#ifdef MNT_SUIDDIR
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_SUIDDIR, "suiddir" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#endif
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_SOFTDEP, "soft-updates" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#ifdef MNT_MULTILABEL
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_MULTILABEL, "multilabel" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#endif
|
|
|
|
#ifdef MNT_ACLS
|
2007-09-18 14:50:30 +05:30
|
|
|
{ MNT_ACLS, "acls" },
|
2008-01-10 04:52:04 +05:30
|
|
|
#endif
|
2007-09-18 14:50:30 +05:30
|
|
|
#ifdef MNT_GJOURNAL
|
|
|
|
{ MNT_GJOURNAL, "gjournal" },
|
|
|
|
#endif
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
static RC_STRINGLIST *find_mounts(struct args *args)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
struct statfs *mnts;
|
|
|
|
int nmnts;
|
|
|
|
int i;
|
2008-03-16 22:30:56 +05:30
|
|
|
RC_STRINGLIST *list;
|
2007-09-18 14:50:30 +05:30
|
|
|
char *options = NULL;
|
2008-01-22 16:37:39 +05:30
|
|
|
uint64_t flags;
|
2007-09-18 14:50:30 +05:30
|
|
|
struct opt *o;
|
2008-03-16 22:30:56 +05:30
|
|
|
int netdev;
|
|
|
|
char *tmp;
|
|
|
|
size_t l;
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
if ((nmnts = getmntinfo(&mnts, MNT_NOWAIT)) == 0)
|
|
|
|
eerrorx("getmntinfo: %s", strerror (errno));
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
list = rc_stringlist_new();
|
2007-04-11 18:14:47 +05:30
|
|
|
for (i = 0; i < nmnts; i++) {
|
2008-03-16 22:30:56 +05:30
|
|
|
netdev = 0;
|
2008-01-10 04:52:04 +05:30
|
|
|
flags = mnts[i].F_FLAGS & MNT_VISFLAGMASK;
|
2007-09-18 14:50:30 +05:30
|
|
|
for (o = optnames; flags && o->o_opt; o++) {
|
|
|
|
if (flags & o->o_opt) {
|
2007-10-09 21:03:05 +05:30
|
|
|
if (o->o_opt == MNT_LOCAL)
|
|
|
|
netdev = 1;
|
2007-09-18 14:50:30 +05:30
|
|
|
if (! options)
|
2008-03-16 22:30:56 +05:30
|
|
|
options = xstrdup(o->o_name);
|
2007-09-18 14:50:30 +05:30
|
|
|
else {
|
2008-03-16 22:30:56 +05:30
|
|
|
l = strlen(options) + strlen(o->o_name) + 2;
|
|
|
|
tmp = xmalloc(sizeof (char) * l);
|
|
|
|
snprintf(tmp, l, "%s,%s", options, o->o_name);
|
|
|
|
free(options);
|
2007-09-18 14:50:30 +05:30
|
|
|
options = tmp;
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-09-18 14:50:30 +05:30
|
|
|
}
|
|
|
|
flags &= ~o->o_opt;
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
process_mount(list, args,
|
|
|
|
mnts[i].f_mntfromname,
|
|
|
|
mnts[i].f_mntonname,
|
|
|
|
mnts[i].f_fstypename,
|
|
|
|
options,
|
|
|
|
netdev);
|
2007-09-18 14:50:30 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
free(options);
|
2007-09-18 14:50:30 +05:30
|
|
|
options = NULL;
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
return list;
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined (__linux__)
|
2008-03-16 22:30:56 +05:30
|
|
|
static struct mntent *getmntfile(const char *file)
|
2007-10-09 21:03:05 +05:30
|
|
|
{
|
|
|
|
struct mntent *ent = NULL;
|
|
|
|
FILE *fp;
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
fp = setmntent("/etc/fstab", "r");
|
|
|
|
while ((ent = getmntent(fp)))
|
|
|
|
if (strcmp(file, ent->mnt_dir) == 0)
|
2007-10-09 21:03:05 +05:30
|
|
|
break;
|
2008-03-16 22:30:56 +05:30
|
|
|
endmntent(fp);
|
2008-01-11 21:21:40 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
return ent;
|
2007-10-09 21:03:05 +05:30
|
|
|
}
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
static RC_STRINGLIST *find_mounts(struct args *args)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-04-11 18:14:47 +05:30
|
|
|
FILE *fp;
|
2007-10-12 05:31:33 +05:30
|
|
|
char *buffer;
|
2007-04-11 18:14:47 +05:30
|
|
|
char *p;
|
|
|
|
char *from;
|
|
|
|
char *to;
|
2007-07-16 22:37:15 +05:30
|
|
|
char *fst;
|
2007-09-18 14:50:30 +05:30
|
|
|
char *opts;
|
2007-10-09 21:03:05 +05:30
|
|
|
struct mntent *ent;
|
|
|
|
int netdev;
|
2008-03-16 22:30:56 +05:30
|
|
|
RC_STRINGLIST *list;
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
if ((fp = fopen("/proc/mounts", "r")) == NULL)
|
|
|
|
eerrorx("getmntinfo: %s", strerror(errno));
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
list = rc_stringlist_new();
|
|
|
|
|
|
|
|
buffer = xmalloc(sizeof(char) * PATH_MAX * 3);
|
|
|
|
while (fgets(buffer, PATH_MAX * 3, fp)) {
|
2007-10-09 21:03:05 +05:30
|
|
|
netdev = -1;
|
2007-04-11 18:14:47 +05:30
|
|
|
p = buffer;
|
2008-03-16 22:30:56 +05:30
|
|
|
from = strsep(&p, " ");
|
|
|
|
to = strsep(&p, " ");
|
|
|
|
fst = strsep(&p, " ");
|
|
|
|
opts = strsep(&p, " ");
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
if ((ent = getmntfile(to))) {
|
|
|
|
if (strstr(ent->mnt_opts, "_netdev"))
|
2007-10-09 21:03:05 +05:30
|
|
|
netdev = 0;
|
|
|
|
}
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
process_mount(list, args, from, to, fst, opts, netdev);
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2008-03-16 22:30:56 +05:30
|
|
|
free(buffer);
|
|
|
|
fclose(fp);
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
return list;
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
# error "Operating system not supported!"
|
|
|
|
#endif
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
static regex_t *get_regex(const char *string)
|
2007-07-11 22:57:46 +05:30
|
|
|
{
|
2008-03-16 22:30:56 +05:30
|
|
|
regex_t *reg = xmalloc(sizeof (*reg));
|
2007-07-11 22:57:46 +05:30
|
|
|
int result;
|
|
|
|
char buffer[256];
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
if ((result = regcomp(reg, string, REG_EXTENDED | REG_NOSUB)) != 0)
|
2007-07-11 22:57:46 +05:30
|
|
|
{
|
2008-03-16 22:30:56 +05:30
|
|
|
regerror(result, reg, buffer, sizeof(buffer));
|
|
|
|
eerrorx("%s: invalid regex `%s'", applet, buffer);
|
2007-07-11 22:57:46 +05:30
|
|
|
}
|
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
return reg;
|
2007-07-11 22:57:46 +05:30
|
|
|
}
|
|
|
|
|
2007-06-28 21:14:14 +05:30
|
|
|
#include "_usage.h"
|
2007-09-21 17:22:37 +05:30
|
|
|
#define extraopts "[mount1] [mount2] ..."
|
2007-09-26 04:47:25 +05:30
|
|
|
#define getoptstring "f:F:n:N:o:O:p:P:ist" getoptstring_COMMON
|
2008-02-02 01:24:46 +05:30
|
|
|
static const struct option longopts[] = {
|
2007-07-11 22:57:46 +05:30
|
|
|
{ "fstype-regex", 1, NULL, 'f'},
|
|
|
|
{ "skip-fstype-regex", 1, NULL, 'F'},
|
|
|
|
{ "node-regex", 1, NULL, 'n'},
|
|
|
|
{ "skip-node-regex", 1, NULL, 'N'},
|
2007-09-18 14:50:30 +05:30
|
|
|
{ "options-regex", 1, NULL, 'o'},
|
|
|
|
{ "skip-options-regex", 1, NULL, 'O'},
|
2007-07-11 22:57:46 +05:30
|
|
|
{ "point-regex", 1, NULL, 'p'},
|
|
|
|
{ "skip-point-regex", 1, NULL, 'P'},
|
2007-09-18 14:50:30 +05:30
|
|
|
{ "options", 0, NULL, 'i'},
|
2007-07-16 22:37:15 +05:30
|
|
|
{ "fstype", 0, NULL, 's'},
|
2007-09-18 14:50:30 +05:30
|
|
|
{ "node", 0, NULL, 't'},
|
2008-03-16 22:30:56 +05:30
|
|
|
{ "netdev", 0, NULL, 'e'},
|
2007-10-09 21:03:05 +05:30
|
|
|
{ "nonetdev", 0, NULL, 'E'},
|
2007-06-28 21:14:14 +05:30
|
|
|
longopts_COMMON
|
2007-04-13 20:39:37 +05:30
|
|
|
};
|
2007-09-25 21:51:38 +05:30
|
|
|
static const char * const longopts_help[] = {
|
2007-10-09 23:11:53 +05:30
|
|
|
"fstype regex to find",
|
|
|
|
"fstype regex to skip",
|
|
|
|
"node regex to find",
|
|
|
|
"node regex to skip",
|
|
|
|
"options regex to find",
|
|
|
|
"options regex to skip",
|
|
|
|
"point regex to find",
|
|
|
|
"point regex to skip",
|
|
|
|
"print options",
|
|
|
|
"print fstype",
|
|
|
|
"print node",
|
|
|
|
"is it a network device",
|
|
|
|
"is it not a network device",
|
2007-09-25 21:51:38 +05:30
|
|
|
longopts_help_COMMON
|
|
|
|
};
|
2007-04-17 18:14:32 +05:30
|
|
|
#include "_usage.c"
|
2007-04-13 20:39:37 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
int mountinfo(int argc, char **argv)
|
2007-04-05 16:48:42 +05:30
|
|
|
{
|
2007-09-18 14:50:30 +05:30
|
|
|
struct args args;
|
2007-07-11 22:57:46 +05:30
|
|
|
regex_t *point_regex = NULL;
|
|
|
|
regex_t *skip_point_regex = NULL;
|
2008-03-16 22:30:56 +05:30
|
|
|
RC_STRINGLIST *nodes;
|
|
|
|
RC_STRING *s;
|
2007-05-14 17:54:18 +05:30
|
|
|
int opt;
|
2007-07-11 22:57:46 +05:30
|
|
|
int result;
|
2007-11-23 17:34:11 +05:30
|
|
|
bool quiet;
|
2007-07-11 22:57:46 +05:30
|
|
|
|
2007-12-15 04:31:28 +05:30
|
|
|
/* Ensure that we are only quiet when explicitly told to be */
|
2008-03-16 22:30:56 +05:30
|
|
|
unsetenv("EINFO_QUIET");
|
2007-12-15 04:31:28 +05:30
|
|
|
|
2007-07-11 22:57:46 +05:30
|
|
|
#define DO_REG(_var) \
|
2008-03-16 22:30:56 +05:30
|
|
|
if (_var) free(_var); \
|
|
|
|
_var = get_regex(optarg);
|
2007-09-24 14:37:00 +05:30
|
|
|
#define REG_FREE(_var) \
|
2008-03-16 22:30:56 +05:30
|
|
|
if (_var) { regfree(_var); free(_var); }
|
2007-04-12 15:38:42 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
memset (&args, 0, sizeof(args));
|
2007-09-18 14:50:30 +05:30
|
|
|
args.mount_type = mount_to;
|
2007-10-09 21:03:05 +05:30
|
|
|
args.netdev = net_ignore;
|
2008-03-16 22:30:56 +05:30
|
|
|
args.mounts = rc_stringlist_new();
|
2007-09-18 14:50:30 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
while ((opt = getopt_long(argc, argv, getoptstring,
|
|
|
|
longopts, (int *) 0)) != -1)
|
2007-07-11 22:57:46 +05:30
|
|
|
{
|
2007-05-14 17:54:18 +05:30
|
|
|
switch (opt) {
|
2008-03-16 22:30:56 +05:30
|
|
|
case 'e':
|
|
|
|
args.netdev = net_yes;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
args.netdev = net_no;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
DO_REG(args.fstype_regex);
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
DO_REG(args.skip_fstype_regex);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
DO_REG(args.node_regex);
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
DO_REG(args.skip_node_regex);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
DO_REG(args.options_regex);
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
DO_REG(args.skip_options_regex);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
DO_REG(point_regex);
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
DO_REG(skip_point_regex);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
args.mount_type = mount_options;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
args.mount_type = mount_fstype;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
args.mount_type = mount_from;
|
|
|
|
break;
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
case_RC_COMMON_GETOPT
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2007-07-11 22:57:46 +05:30
|
|
|
}
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2007-04-12 15:38:42 +05:30
|
|
|
while (optind < argc) {
|
|
|
|
if (argv[optind][0] != '/')
|
2008-03-16 22:30:56 +05:30
|
|
|
eerrorx("%s: `%s' is not a mount point", argv[0], argv[optind]);
|
|
|
|
rc_stringlist_add(args.mounts, argv[optind++]);
|
2007-04-11 18:14:47 +05:30
|
|
|
}
|
2008-03-16 22:30:56 +05:30
|
|
|
nodes = find_mounts(&args);
|
|
|
|
rc_stringlist_free(args.mounts);
|
2007-07-11 22:57:46 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
REG_FREE(args.fstype_regex);
|
|
|
|
REG_FREE(args.skip_fstype_regex);
|
|
|
|
REG_FREE(args.node_regex);
|
|
|
|
REG_FREE(args.skip_node_regex);
|
|
|
|
REG_FREE(args.options_regex);
|
|
|
|
REG_FREE(args.skip_options_regex);
|
2007-04-11 18:14:47 +05:30
|
|
|
|
|
|
|
result = EXIT_FAILURE;
|
2008-03-16 22:30:56 +05:30
|
|
|
quiet = rc_yesno(getenv("EINFO_QUIET"));
|
2008-03-24 01:21:41 +05:30
|
|
|
|
|
|
|
/* We should report the mounts in reverse order to ease unmounting */
|
2008-03-16 22:30:56 +05:30
|
|
|
TAILQ_FOREACH_REVERSE(s, nodes, rc_stringlist, entries) {
|
|
|
|
if (point_regex &&
|
|
|
|
regexec(point_regex, s->value, 0, NULL, 0) != 0)
|
2007-07-11 22:57:46 +05:30
|
|
|
continue;
|
2008-03-16 22:30:56 +05:30
|
|
|
if (skip_point_regex &&
|
|
|
|
regexec(skip_point_regex, s->value, 0, NULL, 0) == 0)
|
2007-04-11 18:14:47 +05:30
|
|
|
continue;
|
2007-11-23 17:34:11 +05:30
|
|
|
if (! quiet)
|
2008-03-16 22:30:56 +05:30
|
|
|
printf("%s\n", s->value);
|
2007-04-11 18:14:47 +05:30
|
|
|
result = EXIT_SUCCESS;
|
|
|
|
}
|
2008-03-16 22:30:56 +05:30
|
|
|
rc_stringlist_free(nodes);
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-03-16 22:30:56 +05:30
|
|
|
REG_FREE(point_regex);
|
|
|
|
REG_FREE(skip_point_regex);
|
2007-04-11 18:14:47 +05:30
|
|
|
|
2008-09-18 18:39:51 +05:30
|
|
|
return result;
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|