Added a new backend: mount

This is quite rought and brutal, it read the fstab file
to see the availabel mount points and the /proc/mounts
files to see if they are mounted or not.

atm only looks for fns and cifs filesystem, as all the
others should be yet managed by udisks. Works quite well
with my nfs shares.

TBD: actually mount/unmount using the mount command
This commit is contained in:
Davide Andreoli 2015-01-11 20:12:32 +01:00
parent 94f551fb12
commit e559f19cc4
5 changed files with 225 additions and 0 deletions

View File

@ -69,6 +69,17 @@ if test "x$want_eldbus" = "xno";then
have_eldbus=no
fi
# check for mount (default enabled)
#TODO here check if /etc/fstab and /proc/mounts exists
have_mount=yes
want_mount=yes
AC_ARG_ENABLE([mount],
AS_HELP_STRING([--enable-mount],[enable mount fstab/mtab support @<:@default=enabled@:>@]),
[want_mount=$enableval])
if test "x$want_mount" = "xno";then
have_mount=no
fi
# check for eeze (default disabled)
PKG_CHECK_MODULES([EEZE], [eeze >= 1.1.99],
[have_eeze="yes"], [have_eeze="no"])
@ -87,6 +98,9 @@ test "x$have_eldbus" = "xyes" && AC_DEFINE_UNQUOTED([HAVE_ELDBUS], [1], [enable
AM_CONDITIONAL([HAVE_EEZE], [test "x$have_eeze" = "xyes"])
test "x$have_eeze" = "xyes" && AC_DEFINE_UNQUOTED([HAVE_EEZE], [1], [enable eeze support])
AM_CONDITIONAL([HAVE_MOUNT], [test "x$have_mount" = "xyes"])
test "x$have_mount" = "xyes" && AC_DEFINE_UNQUOTED([HAVE_MOUNT], [1], [enable mount support])
# homedir install
datadir=$(pkg-config --variable=modules enlightenment)/${PACKAGE}
@ -123,6 +137,7 @@ echo
cat << DEVICE_EOF
Device Backends:
* build udisks (eldbus)....: $have_eldbus (default)
* build mount (fstab/mtab).: $have_mount (default)
* build eeze...............: $have_eeze (experimental)
DEVICE_EOF
echo

View File

@ -14,6 +14,8 @@ module_la_SOURCES = e_mod_main.h \
e_mod_places.c \
e_mod_udisks_eldbus.h \
e_mod_udisks_eldbus.c \
e_mod_mount.h \
e_mod_mount.c \
e_mod_eeze.h \
e_mod_eeze.c

190
src/e_mod_mount.c Normal file
View File

@ -0,0 +1,190 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_MOUNT
#include <e.h>
#include "e_mod_places.h"
#define FSTAB_FILE "/etc/fstab"
#define MTAB_FILE "/proc/mounts"
static Ecore_Timer *mtab_timer = NULL;
static Eina_List *know_mounts = NULL;
void
_places_mount_volume_add(const char *mpoint, const char *fstype)
{
Volume *vol;
// printf("PLACES: found mount: %s (%s)\n", mpoint, fstype);
vol = places_volume_add(mpoint, EINA_TRUE);
vol->valid = EINA_TRUE;
vol->mounted = EINA_FALSE;
eina_stringshare_replace(&vol->label, ecore_file_file_get(mpoint));
eina_stringshare_replace(&vol->mount_point, mpoint);
eina_stringshare_replace(&vol->fstype, fstype);
know_mounts = eina_list_append(know_mounts, vol);
}
char *
_places_mount_file_read(const char *path)
{
char buf[10000]; // :/
FILE * f;
size_t len;
f = fopen(path, "r");
if (!f)
return NULL;
len = fread(buf, sizeof(char), sizeof(buf), f);
fclose(f);
if (len < 1)
return NULL;
// printf("PLACES: readed %ld\n", len);
buf[++len] = '\0';
return strdup(buf);
}
void
_places_mount_mtab_parse(void)
{
char *contents;
char **lines;
unsigned int i, num_splits;
char mpoint[256];
Eina_List *to_search, *l, *l2;
Volume *vol;
contents = _places_mount_file_read("/proc/mounts");
if (!contents)
return;
lines = eina_str_split(contents, "\n", 0);
if (!lines)
return;
to_search = eina_list_clone(know_mounts);
for (i = 0; lines[i]; i++)
{
num_splits = sscanf(lines[i], "%*s %s %*s %*s %*d %*d", mpoint);
if (num_splits != 1)
continue;
EINA_LIST_FOREACH_SAFE(to_search, l, l2, vol)
{
if (strcmp(vol->mount_point, mpoint))
continue;
// printf("PLACES: Mounted: %s\n", mpoint);
to_search = eina_list_remove(to_search, vol);
if (vol->mounted == EINA_FALSE)
{
vol->mounted = EINA_TRUE;
places_volume_update(vol);
}
break;
}
continue;
}
EINA_LIST_FREE(to_search, vol)
{
// printf("PLACES: NOT Mounted: %s\n", vol->mount_point);
if (vol->mounted == EINA_TRUE)
{
vol->mounted = EINA_FALSE;
places_volume_update(vol);
}
}
free(lines[0]);
free(lines);
free(contents);
}
void
_places_mount_fstab_parse(void)
{
char *contents, *line;
char **lines;
unsigned int i, num_splits;
char mpoint[256];
char fstype[64];
contents = _places_mount_file_read(FSTAB_FILE);
if (!contents)
return;
lines = eina_str_split(contents, "\n", 0);
if (!lines)
return;
for (i = 0; lines[i]; i++)
{
line = lines[i];
if (!line[0] || line[0] == '\n' || line[0] == '#')
continue;
num_splits = sscanf(line, "%*s %s %s %*s %*d %*d", mpoint, fstype);
if (num_splits != 2)
continue;
if (!strcmp(fstype, "nfs") ||
!strcmp(fstype, "cifs"))
{
_places_mount_volume_add(mpoint, fstype);
}
}
free(lines[0]);
free(lines);
free(contents);
}
static Eina_Bool
_places_mount_mtab_timer_cb(void *data)
{
_places_mount_mtab_parse();
return ECORE_CALLBACK_RENEW;
}
Eina_Bool
places_mount_init(void)
{
printf("PLACES: mount: init()\n");
if (!ecore_file_exists(FSTAB_FILE) ||
!ecore_file_exists(MTAB_FILE))
{
printf("PLACES: mount: Cannot find required files\n");
return EINA_FALSE;
}
_places_mount_fstab_parse();
_places_mount_mtab_parse();
mtab_timer = ecore_timer_add(4.0, _places_mount_mtab_timer_cb, NULL);
return EINA_TRUE;
}
void
places_mount_shutdown(void)
{
printf("PLACES: mtab: shutdown()\n");
if (mtab_timer) ecore_timer_del(mtab_timer);
if (know_mounts) eina_list_free(know_mounts);
}
#endif

8
src/e_mod_mount.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef E_MOD_PLACES_MOUNT_H
#define E_MOD_PLACES_MOUNT_H
void places_mount_init(void);
void places_mount_shutdown(void);
#endif

View File

@ -11,6 +11,10 @@
#ifdef HAVE_ELDBUS
# include "e_mod_udisks_eldbus.h"
#endif
#ifdef HAVE_MOUNT
# include "e_mod_mount.h"
#endif
/* Local Function Prototypes */
static Eina_Bool _places_poller(void *data);
@ -44,6 +48,9 @@ places_init(void)
#ifdef HAVE_ELDBUS
places_udisks_eldbus_init();
#endif
#ifdef HAVE_MOUNT
places_mount_init();
#endif
snprintf(theme_file, PATH_MAX, "%s/e-module-places.edj",
places_conf->module->dir);
@ -64,6 +71,9 @@ places_shutdown(void)
#ifdef HAVE_ELDBUS
places_udisks_eldbus_shutdown();
#endif
#ifdef HAVE_MOUNT
places_mount_shutdown();
#endif
}
Evas_Object *