|
Packit Service |
407539 |
/* mountlist.c -- return a list of mounted filesystems
|
|
Packit Service |
407539 |
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
407539 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
407539 |
the Free Software Foundation; either version 2, or (at your option)
|
|
Packit Service |
407539 |
any later version.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
407539 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
407539 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
407539 |
GNU General Public License for more details.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
407539 |
along with this program; if not, write to the Free Software Foundation,
|
|
Packit Service |
407539 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <config.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <glib.h>
|
|
Packit Service |
407539 |
#include <stdio.h>
|
|
Packit Service |
407539 |
#include <stdlib.h>
|
|
Packit Service |
407539 |
#include <sys/types.h>
|
|
Packit Service |
407539 |
#include <sys/param.h>
|
|
Packit Service |
407539 |
#include <sys/mount.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <string.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <glibtop.h>
|
|
Packit Service |
407539 |
#include <glibtop/mountlist.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* A mount table entry. */
|
|
Packit Service |
407539 |
struct mount_entry
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
char *me_devname; /* Device node pathname, including "/dev/". */
|
|
Packit Service |
407539 |
char *me_mountdir; /* Mount point directory pathname. */
|
|
Packit Service |
407539 |
char *me_type; /* "nfs", "4.2", etc. */
|
|
Packit Service |
407539 |
dev_t me_dev; /* Device number of me_mountdir. */
|
|
Packit Service |
407539 |
struct mount_entry *me_next;
|
|
Packit Service |
407539 |
};
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
static struct mount_entry *read_filesystem_list (void);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Return a list of the currently mounted filesystems, or NULL on error.
|
|
Packit Service |
407539 |
Add each entry to the tail of the list so that they stay in order.
|
|
Packit Service |
407539 |
*/
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
static struct mount_entry *
|
|
Packit Service |
407539 |
read_filesystem_list (void)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
struct mount_entry *mount_list;
|
|
Packit Service |
407539 |
struct mount_entry *me;
|
|
Packit Service |
407539 |
struct mount_entry *mtail;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Start the list off with a dummy entry. */
|
|
Packit Service |
407539 |
me = g_new (struct mount_entry, 1);
|
|
Packit Service |
407539 |
me->me_next = NULL;
|
|
Packit Service |
407539 |
mount_list = mtail = me;
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
struct statfs *fsp;
|
|
Packit Service |
407539 |
int entries;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
|
Packit Service |
407539 |
if (entries < 0)
|
|
Packit Service |
407539 |
return NULL;
|
|
Packit Service |
407539 |
while (entries-- > 0)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
me = (struct mount_entry *) g_malloc (sizeof (struct mount_entry));
|
|
Packit Service |
407539 |
me->me_devname = g_strdup (fsp->f_mntfromname);
|
|
Packit Service |
407539 |
me->me_mountdir = g_strdup (fsp->f_mntonname);
|
|
Packit Service |
407539 |
me->me_type = g_strdup (fsp->f_fstypename);
|
|
Packit Service |
407539 |
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
|
Packit Service |
407539 |
me->me_next = NULL;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Add to the linked list. */
|
|
Packit Service |
407539 |
mtail->me_next = me;
|
|
Packit Service |
407539 |
mtail = me;
|
|
Packit Service |
407539 |
fsp++;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Free the dummy head. */
|
|
Packit Service |
407539 |
me = mount_list;
|
|
Packit Service |
407539 |
mount_list = mount_list->me_next;
|
|
Packit Service |
407539 |
g_free (me);
|
|
Packit Service |
407539 |
return mount_list;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
static gboolean ignore_mount_entry(const struct mount_entry *me)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
/* keep sorted */
|
|
Packit Service |
407539 |
static const char ignored[][17] = {
|
|
Packit Service |
407539 |
"autofs",
|
|
Packit Service |
407539 |
"devfs",
|
|
Packit Service |
407539 |
"fusectl",
|
|
Packit Service |
407539 |
"linprocfs",
|
|
Packit Service |
407539 |
"linsysfs",
|
|
Packit Service |
407539 |
"mfs",
|
|
Packit Service |
407539 |
"none",
|
|
Packit Service |
407539 |
"nfs",
|
|
Packit Service |
407539 |
"nullfs",
|
|
Packit Service |
407539 |
"nwfs",
|
|
Packit Service |
407539 |
"portalfs",
|
|
Packit Service |
407539 |
"proc",
|
|
Packit Service |
407539 |
"procfs",
|
|
Packit Service |
407539 |
"smbfs",
|
|
Packit Service |
407539 |
"tmpfs",
|
|
Packit Service |
407539 |
"unionfs",
|
|
Packit Service |
407539 |
"unknown"
|
|
Packit Service |
407539 |
};
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
typedef int (*Comparator)(const void*, const void*);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
return bsearch(me->me_type,
|
|
Packit Service |
407539 |
ignored, G_N_ELEMENTS(ignored), sizeof ignored[0],
|
|
Packit Service |
407539 |
(Comparator) strcmp) != NULL;
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_mountentry *
|
|
Packit Service |
407539 |
glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
struct mount_entry *entries, *cur, *next;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
GArray *mount_array = g_array_new(FALSE, FALSE,
|
|
Packit Service |
407539 |
sizeof(glibtop_mountentry));
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_init_r (&server, 0, 0);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
memset (buf, 0, sizeof (glibtop_mountlist));
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Read filesystem list. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
if((entries = read_filesystem_list ()) == NULL)
|
|
Packit Service |
407539 |
return NULL;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
for (cur = &entries[0]; cur != NULL; cur = next) {
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
if(all_fs || !ignore_mount_entry(cur)) {
|
|
Packit Service |
407539 |
/* add a new glibtop_mountentry */
|
|
Packit Service |
407539 |
glibtop_mountentry e;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
g_strlcpy(e.devname, cur->me_devname, sizeof e.devname);
|
|
Packit Service |
407539 |
g_strlcpy(e.mountdir, cur->me_mountdir, sizeof e.mountdir);
|
|
Packit Service |
407539 |
g_strlcpy(e.type, cur->me_type, sizeof e.type);
|
|
Packit Service |
407539 |
e.dev = cur->me_dev;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
g_array_append_val(mount_array, e);
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* free current mount_entry and move to the next */
|
|
Packit Service |
407539 |
next = cur->me_next;
|
|
Packit Service |
407539 |
g_free(cur->me_devname);
|
|
Packit Service |
407539 |
g_free(cur->me_mountdir);
|
|
Packit Service |
407539 |
g_free(cur->me_type);
|
|
Packit Service |
407539 |
g_free(cur);
|
|
Packit Service |
407539 |
}
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
buf->size = sizeof (glibtop_mountentry);
|
|
Packit Service |
407539 |
buf->number = mount_array->len;
|
|
Packit Service |
407539 |
buf->total = buf->number * buf->size;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
buf->flags = (1 << GLIBTOP_MOUNTLIST_SIZE)
|
|
Packit Service |
407539 |
| (1 << GLIBTOP_MOUNTLIST_NUMBER)
|
|
Packit Service |
407539 |
| (1 << GLIBTOP_MOUNTLIST_TOTAL);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
return (glibtop_mountentry*) g_array_free(mount_array, FALSE);
|
|
Packit Service |
407539 |
}
|