forked from enlightenment/efl
support libmount 2.19, fix some bugs here and there, automatically grab fstab/mtab mount flags when using eeze_disk_mountopts_get with new libmount
SVN revision: 56947
This commit is contained in:
parent
4697916227
commit
16b61622e6
|
@ -96,7 +96,7 @@ elif test $udev_version -lt 148;then
|
|||
fi
|
||||
|
||||
eeze_mount=
|
||||
PKG_CHECK_EXISTS([mount == 2.18.0],
|
||||
PKG_CHECK_EXISTS([mount >= 2.18.0],
|
||||
[
|
||||
AC_DEFINE([HAVE_EEZE_MOUNT], [1], [Eeze is mount-capable])
|
||||
AM_CONDITIONAL([HAVE_EEZE_MOUNT], [true])
|
||||
|
@ -110,6 +110,7 @@ if test "x$eeze_mount" = "xyes";then
|
|||
AC_ARG_WITH([mount], AS_HELP_STRING([--with-mount], [specify mount bin @<:@default=detect@:>@]))
|
||||
AC_ARG_WITH([umount], AS_HELP_STRING([--with-umount], [specify umount bin @<:@default=detect@:>@]))
|
||||
PKG_CHECK_MODULES([LIBMOUNT], [mount >= 2.18.0])
|
||||
mount_v=$(pkg-config --modversion mount)
|
||||
PKG_CHECK_MODULES([ECORE_FILE], [ecore-file >= 1.0.0])
|
||||
|
||||
if test "x$with_mount" = "xdetect";then
|
||||
|
@ -122,7 +123,10 @@ if test "x$eeze_mount" = "xyes";then
|
|||
fi
|
||||
AC_DEFINE_UNQUOTED([EEZE_UNMOUNT_BIN], ["$with_umount"], [umount bin to use])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL([OLD_LIBMOUNT], [test -n $mount_v -a $(echo $mount_v | cut -d'.' -f2) -lt 19])
|
||||
if test -z "$OLD_LIBMOUNT_TRUE" ; then
|
||||
AC_DEFINE_UNQUOTED([OLD_LIBMOUNT], [1], [using first version of libmount])
|
||||
fi
|
||||
### Checks for header files
|
||||
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ EAPI Eina_Bool eeze_disk_mount(Eeze_Disk *disk);
|
|||
EAPI Eina_Bool eeze_disk_unmount(Eeze_Disk *disk);
|
||||
EAPI const char *eeze_disk_mount_point_get(Eeze_Disk *disk);
|
||||
EAPI Eina_Bool eeze_disk_mount_point_set(Eeze_Disk *disk, const char *mount_point);
|
||||
EAPI Eina_Bool eeze_disk_mountopts_set(Eeze_Disk *disk, int opts);
|
||||
EAPI int eeze_disk_mountopts_get(Eeze_Disk *disk);
|
||||
EAPI Eina_Bool eeze_disk_mountopts_set(Eeze_Disk *disk, unsigned long opts);
|
||||
EAPI unsigned long eeze_disk_mountopts_get(Eeze_Disk *disk);
|
||||
|
||||
EAPI Eina_Bool eeze_mount_tabs_watch(void);
|
||||
EAPI void eeze_mount_tabs_unwatch(void);
|
||||
|
|
|
@ -4,7 +4,12 @@ AM_CPPFLAGS = @EEZE_CFLAGS@
|
|||
|
||||
if HAVE_EEZE_MOUNT
|
||||
AM_CFLAGS = @EEZE_CFLAGS@ @LIBMOUNT_CFLAGS@ @ECORE_FILE_CFLAGS@
|
||||
MOUNT_FILES = eeze_disk.c eeze_disk_mount.c eeze_disk_libmount.c
|
||||
MOUNT_FILES = eeze_disk.c eeze_disk_mount.c
|
||||
if OLD_LIBMOUNT
|
||||
MOUNT_FILES += eeze_disk_libmount_old.c
|
||||
else
|
||||
MOUNT_FILES += eeze_disk_libmount.c
|
||||
endif
|
||||
MOUNT_INCLUDES = Eeze_Disk.h
|
||||
else
|
||||
AM_CFLAGS = @EEZE_CFLAGS@
|
||||
|
|
|
@ -157,20 +157,24 @@ eeze_disk_new_from_mount(const char *mount_point)
|
|||
|
||||
if (source[4] == '=')
|
||||
{
|
||||
source += 4;
|
||||
source += 5;
|
||||
uuid = eina_stringshare_add(source);
|
||||
dev = _eeze_disk_device_from_property(uuid, EINA_TRUE);
|
||||
}
|
||||
else if (source[5] == '=')
|
||||
{
|
||||
source += 5;
|
||||
source += 6;
|
||||
label = eina_stringshare_add(source);
|
||||
dev = _eeze_disk_device_from_property(label, EINA_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *spath;
|
||||
|
||||
devpath = eina_stringshare_add(source);
|
||||
dev = _new_device(devpath);
|
||||
spath = eeze_udev_devpath_get_syspath(devpath);
|
||||
dev = _new_device(spath);
|
||||
eina_stringshare_del(spath);
|
||||
}
|
||||
|
||||
if (!dev)
|
||||
|
@ -190,6 +194,7 @@ eeze_disk_new_from_mount(const char *mount_point)
|
|||
disk->cache.label = label;
|
||||
else
|
||||
disk->devpath = devpath;
|
||||
disk->mount_point = eina_stringshare_add(mount_point);
|
||||
|
||||
return disk;
|
||||
error:
|
||||
|
@ -217,7 +222,7 @@ eeze_disk_free(Eeze_Disk *disk)
|
|||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN(disk);
|
||||
|
||||
eina_stringshare_del(disk->syspath);
|
||||
|
||||
udev_device_unref(disk->device);
|
||||
if (disk->mount_cmd)
|
||||
eina_strbuf_free(disk->mount_cmd);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <Ecore.h>
|
||||
#include <Eeze.h>
|
||||
#include <Eeze_Disk.h>
|
||||
#include <mount/mount.h>
|
||||
#include <libmount.h>
|
||||
|
||||
#include "eeze_udev_private.h"
|
||||
#include "eeze_disk_private.h"
|
||||
|
@ -24,72 +24,86 @@
|
|||
* PRIVATE
|
||||
*
|
||||
*/
|
||||
|
||||
static struct libmnt_optmap eeze_optmap[] =
|
||||
{
|
||||
{ "loop[=]", EEZE_DISK_MOUNTOPT_LOOP, 0 },
|
||||
{ "utf8", EEZE_DISK_MOUNTOPT_UTF8, 0 },
|
||||
{ "noexec", EEZE_DISK_MOUNTOPT_NOEXEC, 0 },
|
||||
{ "nosuid", EEZE_DISK_MOUNTOPT_NOSUID, 0 },
|
||||
{ "remount", EEZE_DISK_MOUNTOPT_REMOUNT, 0 },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
typedef struct libmnt_table libmnt_table;
|
||||
typedef struct libmnt_lock libmnt_lock;
|
||||
typedef struct libmnt_fs libmnt_fs;
|
||||
static Ecore_File_Monitor *_mtab_mon = NULL;
|
||||
static Ecore_File_Monitor *_fstab_mon = NULL;
|
||||
static Eina_Bool _watching = EINA_FALSE;
|
||||
static Eina_Bool _mtab_scan_active = EINA_FALSE;
|
||||
static Eina_Bool _fstab_scan_active = EINA_FALSE;
|
||||
static mnt_tab *_eeze_mount_mtab = NULL;
|
||||
static mnt_tab *_eeze_mount_fstab = NULL;
|
||||
static mnt_lock *_eeze_mtab_lock = NULL;
|
||||
static libmnt_table *_eeze_mount_mtab = NULL;
|
||||
static libmnt_table *_eeze_mount_fstab = NULL;
|
||||
static libmnt_lock *_eeze_mtab_lock = NULL;
|
||||
|
||||
static mnt_tab *_eeze_mount_tab_parse(const char *filename);
|
||||
static libmnt_table *_eeze_mount_tab_parse(const char *filename);
|
||||
static void _eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_File_Event event __UNUSED__, const char *path);
|
||||
|
||||
static Eina_Bool
|
||||
_eeze_mount_lock_mtab(void)
|
||||
{
|
||||
DBG("Locking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
|
||||
#if 0
|
||||
#warning this code is broken with current libmount!
|
||||
// DBG("Locking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
|
||||
if (mnt_lock_file(_eeze_mtab_lock))
|
||||
{
|
||||
ERR("Couldn't lock mtab!");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
#endif
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_eeze_mount_unlock_mtab(void)
|
||||
{
|
||||
DBG("Unlocking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
|
||||
// DBG("Unlocking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
|
||||
mnt_unlock_file(_eeze_mtab_lock);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
_eeze_mount_tab_parse_errcb(libmnt_table *tab __UNUSED__, const char *filename, int line)
|
||||
{
|
||||
ERR("%s:%d: could not parse line!", filename, line); /* most worthless error reporting ever. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* I could use mnt_new_tab_from_file() but this way gives much more detailed output
|
||||
* I could use mnt_new_table_from_file() but this way gives much more detailed output
|
||||
* on failure so why not
|
||||
*/
|
||||
static mnt_tab *
|
||||
static libmnt_table *
|
||||
_eeze_mount_tab_parse(const char *filename)
|
||||
{
|
||||
mnt_tab *tab;
|
||||
libmnt_table *tab;
|
||||
|
||||
if (!(tab = mnt_new_tab(filename)))
|
||||
return NULL;
|
||||
if (!mnt_tab_parse_file(tab))
|
||||
return tab;
|
||||
|
||||
if (mnt_tab_get_nerrs(tab))
|
||||
{ /* parse error */
|
||||
char buf[1024];
|
||||
|
||||
mnt_tab_strerror(tab, buf, sizeof(buf));
|
||||
ERR("%s", buf);
|
||||
if (!(tab = mnt_new_table())) return NULL;
|
||||
if (mnt_table_set_parser_errcb(tab, _eeze_mount_tab_parse_errcb))
|
||||
{
|
||||
ERR("Alloc!");
|
||||
mnt_free_table(tab);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
/* system error */
|
||||
ERR("%s", mnt_tab_get_name(tab));
|
||||
mnt_free_tab(tab);
|
||||
|
||||
if (!mnt_table_parse_file(tab, filename))
|
||||
return tab;
|
||||
|
||||
mnt_free_table(tab);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_File_Event event __UNUSED__, const char *path)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
libmnt_table *bak;
|
||||
|
||||
if (
|
||||
((_mtab_scan_active) && (data)) || /* mtab has non-null data to avoid needing strcmp */
|
||||
|
@ -114,11 +128,11 @@ _eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_Fi
|
|||
goto error;
|
||||
}
|
||||
|
||||
mnt_free_tab(bak);
|
||||
mnt_free_table(bak);
|
||||
return;
|
||||
|
||||
error:
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
mnt_free_table(_eeze_mount_mtab);
|
||||
_eeze_mount_mtab = bak;
|
||||
}
|
||||
|
||||
|
@ -133,7 +147,7 @@ eeze_libmount_init(void)
|
|||
{
|
||||
if (_eeze_mtab_lock)
|
||||
return EINA_TRUE;
|
||||
if (!(_eeze_mtab_lock = mnt_new_lock(NULL, 0)))
|
||||
if (!(_eeze_mtab_lock = mnt_new_lock("/etc/mtab", 0)))
|
||||
return EINA_FALSE;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
@ -148,13 +162,35 @@ eeze_libmount_shutdown(void)
|
|||
mnt_free_lock(_eeze_mtab_lock);
|
||||
}
|
||||
|
||||
unsigned long
|
||||
eeze_disk_libmount_opts_get(Eeze_Disk *disk)
|
||||
{
|
||||
libmnt_fs *mnt;
|
||||
const char *opts;
|
||||
unsigned long f = 0;
|
||||
|
||||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return 0;
|
||||
|
||||
mnt = mnt_table_find_tag(_eeze_mount_mtab, "UUID", eeze_disk_uuid_get(disk), MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
mnt = mnt_table_find_tag(_eeze_mount_fstab, "UUID", eeze_disk_uuid_get(disk), MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt) return 0;
|
||||
|
||||
opts = mnt_fs_get_fs_options(mnt);
|
||||
if (!opts) return 0;
|
||||
if (!mnt_optstr_get_flags(opts, &f, eeze_optmap)) return 0;
|
||||
return f;
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function to return whether a disk is mounted
|
||||
*/
|
||||
Eina_Bool
|
||||
eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
libmnt_fs *mnt;
|
||||
|
||||
if (!disk)
|
||||
return EINA_FALSE;
|
||||
|
@ -162,11 +198,11 @@ eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
|
|||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return EINA_FALSE;
|
||||
|
||||
mnt = mnt_tab_find_srcpath(_eeze_mount_mtab, eeze_disk_devpath_get(disk), MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_srcpath(_eeze_mount_mtab, eeze_disk_devpath_get(disk), MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
return EINA_FALSE;
|
||||
|
||||
disk->mount_point = eina_stringshare_add(mnt_fs_get_target(mnt));
|
||||
eina_stringshare_replace(&disk->mount_point, mnt_fs_get_target(mnt));
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
|
@ -177,7 +213,7 @@ eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
|
|||
const char *
|
||||
eeze_disk_libmount_mp_find_source(const char *mount_point)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
libmnt_fs *mnt;
|
||||
|
||||
if (!mount_point)
|
||||
return NULL;
|
||||
|
@ -185,9 +221,9 @@ eeze_disk_libmount_mp_find_source(const char *mount_point)
|
|||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_target(_eeze_mount_mtab, mount_point, MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_target(_eeze_mount_mtab, mount_point, MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
mnt = mnt_tab_find_target(_eeze_mount_fstab, mount_point, MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_target(_eeze_mount_fstab, mount_point, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
@ -201,7 +237,7 @@ eeze_disk_libmount_mp_find_source(const char *mount_point)
|
|||
const char *
|
||||
eeze_disk_libmount_mp_lookup_by_uuid(const char *uuid)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
libmnt_fs *mnt;
|
||||
|
||||
if (!uuid)
|
||||
return NULL;
|
||||
|
@ -209,7 +245,7 @@ eeze_disk_libmount_mp_lookup_by_uuid(const char *uuid)
|
|||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_tag(_eeze_mount_fstab, "UUID", uuid, MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_tag(_eeze_mount_fstab, "UUID", uuid, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
@ -223,7 +259,7 @@ eeze_disk_libmount_mp_lookup_by_uuid(const char *uuid)
|
|||
const char *
|
||||
eeze_disk_libmount_mp_lookup_by_label(const char *label)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
libmnt_fs *mnt;
|
||||
|
||||
if (!label)
|
||||
return NULL;
|
||||
|
@ -231,7 +267,7 @@ eeze_disk_libmount_mp_lookup_by_label(const char *label)
|
|||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_tag(_eeze_mount_fstab, "LABEL", label, MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_tag(_eeze_mount_fstab, "LABEL", label, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
@ -245,7 +281,7 @@ eeze_disk_libmount_mp_lookup_by_label(const char *label)
|
|||
const char *
|
||||
eeze_disk_libmount_mp_lookup_by_devpath(const char *devpath)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
libmnt_fs *mnt;
|
||||
|
||||
if (!devpath)
|
||||
return NULL;
|
||||
|
@ -253,9 +289,9 @@ eeze_disk_libmount_mp_lookup_by_devpath(const char *devpath)
|
|||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_srcpath(_eeze_mount_mtab, devpath, MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_srcpath(_eeze_mount_mtab, devpath, MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
mnt = mnt_tab_find_srcpath(_eeze_mount_fstab, devpath, MNT_ITER_BACKWARD);
|
||||
mnt = mnt_table_find_srcpath(_eeze_mount_fstab, devpath, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
@ -282,7 +318,7 @@ eeze_disk_libmount_mp_lookup_by_devpath(const char *devpath)
|
|||
EAPI Eina_Bool
|
||||
eeze_mount_tabs_watch(void)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
libmnt_table *bak;
|
||||
|
||||
if (_watching)
|
||||
return EINA_TRUE;
|
||||
|
@ -295,12 +331,12 @@ eeze_mount_tabs_watch(void)
|
|||
if (!bak)
|
||||
goto error;
|
||||
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
mnt_free_table(_eeze_mount_mtab);
|
||||
_eeze_mount_mtab = bak;
|
||||
if (!(bak = _eeze_mount_tab_parse("/etc/fstab")))
|
||||
goto error;
|
||||
|
||||
mnt_free_tab(_eeze_mount_fstab);
|
||||
mnt_free_table(_eeze_mount_fstab);
|
||||
_eeze_mount_fstab = bak;
|
||||
|
||||
_mtab_mon = ecore_file_monitor_add("/etc/mtab", _eeze_mount_tab_watcher, (void*)1);
|
||||
|
@ -315,7 +351,7 @@ error:
|
|||
else
|
||||
{
|
||||
ERR("Could not parse /etc/fstab!");
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
mnt_free_table(_eeze_mount_mtab);
|
||||
}
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
@ -350,7 +386,7 @@ eeze_mount_tabs_unwatch(void)
|
|||
EAPI Eina_Bool
|
||||
eeze_mount_mtab_scan(void)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
libmnt_table *bak;
|
||||
|
||||
if (_watching)
|
||||
return EINA_TRUE;
|
||||
|
@ -362,7 +398,7 @@ eeze_mount_mtab_scan(void)
|
|||
if (!bak)
|
||||
goto error;
|
||||
if (_eeze_mount_mtab)
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
mnt_free_table(_eeze_mount_mtab);
|
||||
_eeze_mount_mtab = bak;
|
||||
return EINA_TRUE;
|
||||
|
||||
|
@ -385,7 +421,7 @@ error:
|
|||
EAPI Eina_Bool
|
||||
eeze_mount_fstab_scan(void)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
libmnt_table *bak;
|
||||
if (_watching)
|
||||
return EINA_TRUE;
|
||||
|
||||
|
@ -393,7 +429,7 @@ eeze_mount_fstab_scan(void)
|
|||
if (!bak)
|
||||
goto error;
|
||||
if (_eeze_mount_fstab)
|
||||
mnt_free_tab(_eeze_mount_fstab);
|
||||
mnt_free_table(_eeze_mount_fstab);
|
||||
_eeze_mount_fstab = bak;
|
||||
|
||||
return EINA_TRUE;
|
||||
|
|
|
@ -0,0 +1,405 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef USE_UNSTABLE_LIBMOUNT_API
|
||||
# define USE_UNSTABLE_LIBMOUNT_API 1
|
||||
#endif
|
||||
|
||||
#include <Ecore.h>
|
||||
#include <Eeze.h>
|
||||
#include <Eeze_Disk.h>
|
||||
#include <mount/mount.h>
|
||||
|
||||
#include "eeze_udev_private.h"
|
||||
#include "eeze_disk_private.h"
|
||||
|
||||
/**
|
||||
* @addtogroup disk Disk
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* PRIVATE
|
||||
*
|
||||
*/
|
||||
static Ecore_File_Monitor *_mtab_mon = NULL;
|
||||
static Ecore_File_Monitor *_fstab_mon = NULL;
|
||||
static Eina_Bool _watching = EINA_FALSE;
|
||||
static Eina_Bool _mtab_scan_active = EINA_FALSE;
|
||||
static Eina_Bool _fstab_scan_active = EINA_FALSE;
|
||||
static mnt_tab *_eeze_mount_mtab = NULL;
|
||||
static mnt_tab *_eeze_mount_fstab = NULL;
|
||||
static mnt_lock *_eeze_mtab_lock = NULL;
|
||||
|
||||
static mnt_tab *_eeze_mount_tab_parse(const char *filename);
|
||||
static void _eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_File_Event event __UNUSED__, const char *path);
|
||||
|
||||
static Eina_Bool
|
||||
_eeze_mount_lock_mtab(void)
|
||||
{
|
||||
DBG("Locking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
|
||||
#if 0
|
||||
#warning this code is broken with current libmount!
|
||||
if (mnt_lock_file(_eeze_mtab_lock))
|
||||
{
|
||||
ERR("Couldn't lock mtab!");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
#endif
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_eeze_mount_unlock_mtab(void)
|
||||
{
|
||||
DBG("Unlocking mlock: %s", mnt_lock_get_linkfile(_eeze_mtab_lock));
|
||||
mnt_unlock_file(_eeze_mtab_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* I could use mnt_new_tab_from_file() but this way gives much more detailed output
|
||||
* on failure so why not
|
||||
*/
|
||||
static mnt_tab *
|
||||
_eeze_mount_tab_parse(const char *filename)
|
||||
{
|
||||
mnt_tab *tab;
|
||||
|
||||
if (!(tab = mnt_new_tab(filename)))
|
||||
return NULL;
|
||||
if (!mnt_tab_parse_file(tab))
|
||||
return tab;
|
||||
|
||||
if (mnt_tab_get_nerrs(tab))
|
||||
{ /* parse error */
|
||||
char buf[1024];
|
||||
|
||||
mnt_tab_strerror(tab, buf, sizeof(buf));
|
||||
ERR("%s", buf);
|
||||
}
|
||||
else
|
||||
/* system error */
|
||||
ERR("%s", mnt_tab_get_name(tab));
|
||||
mnt_free_tab(tab);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_File_Event event __UNUSED__, const char *path)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
|
||||
if (
|
||||
((_mtab_scan_active) && (data)) || /* mtab has non-null data to avoid needing strcmp */
|
||||
((_fstab_scan_active) && (!data))
|
||||
)
|
||||
/* prevent scans from triggering a scan */
|
||||
return;
|
||||
|
||||
bak = _eeze_mount_mtab;
|
||||
if (data)
|
||||
if (!_eeze_mount_lock_mtab())
|
||||
{ /* FIXME: maybe queue job here? */
|
||||
ERR("Losing events...");
|
||||
return;
|
||||
}
|
||||
_eeze_mount_mtab = _eeze_mount_tab_parse(path);
|
||||
if (data)
|
||||
_eeze_mount_unlock_mtab();
|
||||
if (!_eeze_mount_mtab)
|
||||
{
|
||||
ERR("Could not parse %s! keeping old tab...", path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
mnt_free_tab(bak);
|
||||
return;
|
||||
|
||||
error:
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
_eeze_mount_mtab = bak;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* INVISIBLE
|
||||
*
|
||||
*/
|
||||
|
||||
Eina_Bool
|
||||
eeze_libmount_init(void)
|
||||
{
|
||||
if (_eeze_mtab_lock)
|
||||
return EINA_TRUE;
|
||||
if (!(_eeze_mtab_lock = mnt_new_lock(NULL, 0)))
|
||||
return EINA_FALSE;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
eeze_libmount_shutdown(void)
|
||||
{
|
||||
if (!_eeze_mtab_lock)
|
||||
return;
|
||||
|
||||
mnt_unlock_file(_eeze_mtab_lock);
|
||||
mnt_free_lock(_eeze_mtab_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function to return whether a disk is mounted
|
||||
*/
|
||||
Eina_Bool
|
||||
eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
|
||||
if (!disk)
|
||||
return EINA_FALSE;
|
||||
|
||||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return EINA_FALSE;
|
||||
|
||||
mnt = mnt_tab_find_srcpath(_eeze_mount_mtab, eeze_disk_devpath_get(disk), MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
return EINA_FALSE;
|
||||
|
||||
disk->mount_point = eina_stringshare_add(mnt_fs_get_target(mnt));
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* helper function to return the device that is mounted at a mount point
|
||||
*/
|
||||
const char *
|
||||
eeze_disk_libmount_mp_find_source(const char *mount_point)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
|
||||
if (!mount_point)
|
||||
return NULL;
|
||||
|
||||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_target(_eeze_mount_mtab, mount_point, MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
mnt = mnt_tab_find_target(_eeze_mount_fstab, mount_point, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
||||
return mnt_fs_get_source(mnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function to return a mount point from a uuid
|
||||
*/
|
||||
const char *
|
||||
eeze_disk_libmount_mp_lookup_by_uuid(const char *uuid)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
|
||||
if (!uuid)
|
||||
return NULL;
|
||||
|
||||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_tag(_eeze_mount_fstab, "UUID", uuid, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
||||
return mnt_fs_get_target(mnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function to return a mount point from a label
|
||||
*/
|
||||
const char *
|
||||
eeze_disk_libmount_mp_lookup_by_label(const char *label)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
|
||||
if (!label)
|
||||
return NULL;
|
||||
|
||||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_tag(_eeze_mount_fstab, "LABEL", label, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
||||
return mnt_fs_get_target(mnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* helper function to return a mount point from a /dev/ path
|
||||
*/
|
||||
const char *
|
||||
eeze_disk_libmount_mp_lookup_by_devpath(const char *devpath)
|
||||
{
|
||||
mnt_fs *mnt;
|
||||
|
||||
if (!devpath)
|
||||
return NULL;
|
||||
|
||||
if (!eeze_mount_mtab_scan() || !eeze_mount_fstab_scan())
|
||||
return NULL;
|
||||
|
||||
mnt = mnt_tab_find_srcpath(_eeze_mount_mtab, devpath, MNT_ITER_BACKWARD);
|
||||
if (!mnt)
|
||||
mnt = mnt_tab_find_srcpath(_eeze_mount_fstab, devpath, MNT_ITER_BACKWARD);
|
||||
|
||||
if (!mnt)
|
||||
return NULL;
|
||||
|
||||
return mnt_fs_get_target(mnt);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* API
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Begin watching mtab and fstab
|
||||
* @return #EINA_TRUE if watching was started, else #EINA_FALSE
|
||||
*
|
||||
* This function creates inotify watches on /etc/mtab and /etc/fstab and watches
|
||||
* them for changes. This function should be used when expecting a lot of disk
|
||||
* mounting/unmounting while you need disk data since it will automatically update
|
||||
* certain necessary data instead of waiting.
|
||||
* @see eeze_mount_mtab_scan, eeze_mount_fstab_scan
|
||||
*/
|
||||
EAPI Eina_Bool
|
||||
eeze_mount_tabs_watch(void)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
|
||||
if (_watching)
|
||||
return EINA_TRUE;
|
||||
|
||||
if (!_eeze_mount_lock_mtab())
|
||||
return EINA_FALSE;
|
||||
|
||||
bak = _eeze_mount_tab_parse("/etc/mtab");
|
||||
_eeze_mount_unlock_mtab();
|
||||
if (!bak)
|
||||
goto error;
|
||||
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
_eeze_mount_mtab = bak;
|
||||
if (!(bak = _eeze_mount_tab_parse("/etc/fstab")))
|
||||
goto error;
|
||||
|
||||
mnt_free_tab(_eeze_mount_fstab);
|
||||
_eeze_mount_fstab = bak;
|
||||
|
||||
_mtab_mon = ecore_file_monitor_add("/etc/mtab", _eeze_mount_tab_watcher, (void*)1);
|
||||
_fstab_mon = ecore_file_monitor_add("/etc/fstab", _eeze_mount_tab_watcher, NULL);
|
||||
_watching = EINA_TRUE;
|
||||
|
||||
return EINA_TRUE;
|
||||
|
||||
error:
|
||||
if (!_eeze_mount_mtab)
|
||||
ERR("Could not parse /etc/mtab!");
|
||||
else
|
||||
{
|
||||
ERR("Could not parse /etc/fstab!");
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
}
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop watching /etc/fstab and /etc/mtab
|
||||
*
|
||||
* This function stops watching fstab and mtab. Data obtained previously will be saved.
|
||||
*/
|
||||
EAPI void
|
||||
eeze_mount_tabs_unwatch(void)
|
||||
{
|
||||
if (!_watching)
|
||||
return;
|
||||
|
||||
ecore_file_monitor_del(_mtab_mon);
|
||||
ecore_file_monitor_del(_fstab_mon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Scan /etc/mtab a single time
|
||||
* @return #EINA_TRUE if mtab could be scanned, else #EINA_FALSE
|
||||
*
|
||||
* This function is used to perform a single scan on /etc/mtab. It is used to gather
|
||||
* information about mounted filesystems which can then be used with your #Eeze_Disk objects
|
||||
* where appropriate. These files will automatically be scanned any time a mount point or mount state
|
||||
* is requested unless eeze_mount_tabs_watch has been called previously, in which case data is stored for
|
||||
* use.
|
||||
* If this function is called after eeze_mount_tabs_watch, #EINA_TRUE will be returned.
|
||||
* @see eeze_mount_tabs_watch, eeze_mount_fstab_scan
|
||||
*/
|
||||
EAPI Eina_Bool
|
||||
eeze_mount_mtab_scan(void)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
|
||||
if (_watching)
|
||||
return EINA_TRUE;
|
||||
|
||||
if (!_eeze_mount_lock_mtab())
|
||||
return EINA_FALSE;
|
||||
bak = _eeze_mount_tab_parse("/etc/mtab");
|
||||
_eeze_mount_unlock_mtab();
|
||||
if (!bak)
|
||||
goto error;
|
||||
if (_eeze_mount_mtab)
|
||||
mnt_free_tab(_eeze_mount_mtab);
|
||||
_eeze_mount_mtab = bak;
|
||||
return EINA_TRUE;
|
||||
|
||||
error:
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Scan /etc/fstab a single time
|
||||
* @return #EINA_TRUE if mtab could be scanned, else #EINA_FALSE
|
||||
*
|
||||
* This function is used to perform a single scan on /etc/fstab. It is used to gather
|
||||
* information about mounted filesystems which can then be used with your #Eeze_Disk objects
|
||||
* where appropriate. These files will automatically be scanned any time a mount point or mount state
|
||||
* is requested unless eeze_mount_tabs_watch has been called previously, in which case data is stored for
|
||||
* use.
|
||||
* If this function is called after eeze_mount_tabs_watch, #EINA_TRUE will be returned.
|
||||
* @see eeze_mount_tabs_watch, eeze_mount_mtab_scan
|
||||
*/
|
||||
EAPI Eina_Bool
|
||||
eeze_mount_fstab_scan(void)
|
||||
{
|
||||
mnt_tab *bak;
|
||||
if (_watching)
|
||||
return EINA_TRUE;
|
||||
|
||||
bak = _eeze_mount_tab_parse("/etc/fstab");
|
||||
if (!bak)
|
||||
goto error;
|
||||
if (_eeze_mount_fstab)
|
||||
mnt_free_tab(_eeze_mount_fstab);
|
||||
_eeze_mount_fstab = bak;
|
||||
|
||||
return EINA_TRUE;
|
||||
|
||||
error:
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
/** @} */
|
|
@ -176,7 +176,7 @@ eeze_disk_mounted_get(Eeze_Disk *disk)
|
|||
* This function replaces the current mount opts of a disk with the ones in @p opts.
|
||||
*/
|
||||
EAPI Eina_Bool
|
||||
eeze_disk_mountopts_set(Eeze_Disk *disk, int opts)
|
||||
eeze_disk_mountopts_set(Eeze_Disk *disk, unsigned long opts)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
|
||||
if (opts != disk->mount_opts)
|
||||
|
@ -188,14 +188,18 @@ eeze_disk_mountopts_set(Eeze_Disk *disk, int opts)
|
|||
/**
|
||||
* @brief Get the flags of a disk's current mount options
|
||||
* @param disk The disk
|
||||
* @return An ORed set of #Eeze_Mount_Opts, -1 on failure
|
||||
* @return An ORed set of #Eeze_Mount_Opts, 0 on failure
|
||||
*
|
||||
* This function returns the current mount opts of a disk.
|
||||
*/
|
||||
EAPI int
|
||||
EAPI unsigned long
|
||||
eeze_disk_mountopts_get(Eeze_Disk *disk)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(disk, -1);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(disk, 0);
|
||||
#ifndef OLD_LIBMOUNT
|
||||
if (!disk->mount_opts)
|
||||
disk->mount_opts = eeze_disk_libmount_opts_get(disk);
|
||||
#endif
|
||||
return disk->mount_opts;
|
||||
}
|
||||
|
||||
|
@ -262,8 +266,10 @@ eeze_disk_mount(Eeze_Disk *disk)
|
|||
}
|
||||
|
||||
if ((!disk->mount_point) || (!disk->mount_point[0])) return EINA_FALSE;
|
||||
if ((!disk->mount_opts) || (disk->mount_opts == EEZE_DISK_MOUNTOPT_DEFAULTS))
|
||||
if (disk->mount_opts == EEZE_DISK_MOUNTOPT_DEFAULTS)
|
||||
eina_strbuf_append_printf(disk->mount_cmd, "%s -o %s UUID=%s %s", EEZE_MOUNT_BIN, EEZE_MOUNT_DEFAULT_OPTS, disk->cache.uuid, disk->mount_point);
|
||||
else if (!disk->mount_opts)
|
||||
eina_strbuf_append_printf(disk->mount_cmd, "%s UUID=%s %s", EEZE_MOUNT_BIN, disk->cache.uuid, disk->mount_point);
|
||||
else
|
||||
{
|
||||
eina_strbuf_append_printf(disk->mount_cmd, "%s -o ", EEZE_MOUNT_BIN);
|
||||
|
@ -386,7 +392,7 @@ eeze_disk_mount_point_set(Eeze_Disk *disk, const char *mount_point)
|
|||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
|
||||
|
||||
disk->mount_point = mount_point;
|
||||
eina_stringshare_replace(&disk->mount_point, mount_point);
|
||||
disk->mount_cmd_changed = EINA_TRUE;
|
||||
disk->unmount_cmd_changed = EINA_TRUE;
|
||||
return EINA_TRUE;
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#define EEZE_DISK_COLOR_DEFAULT EINA_COLOR_LIGHTBLUE
|
||||
#endif
|
||||
extern int _eeze_disk_log_dom;
|
||||
#ifdef CRI
|
||||
#undef CRI
|
||||
#endif
|
||||
|
||||
#ifdef ERR
|
||||
#undef ERR
|
||||
#endif
|
||||
|
@ -20,6 +24,7 @@ extern int _eeze_disk_log_dom;
|
|||
#undef DBG
|
||||
#endif
|
||||
|
||||
#define CRI(...) EINA_LOG_DOM_CRIT(_eeze_disk_log_dom, __VA_ARGS__)
|
||||
#define DBG(...) EINA_LOG_DOM_DBG(_eeze_disk_log_dom, __VA_ARGS__)
|
||||
#define INF(...) EINA_LOG_DOM_INFO(_eeze_disk_log_dom, __VA_ARGS__)
|
||||
#define WARN(...) EINA_LOG_DOM_WARN(_eeze_disk_log_dom, __VA_ARGS__)
|
||||
|
@ -48,7 +53,7 @@ struct _Eeze_Disk
|
|||
const char *devpath;
|
||||
const char *fstype;
|
||||
const char *mount_point;
|
||||
int mount_opts;
|
||||
unsigned long mount_opts;
|
||||
|
||||
struct
|
||||
{
|
||||
|
@ -69,7 +74,7 @@ void eeze_mount_shutdown(void);
|
|||
Eina_Bool eeze_libmount_init(void);
|
||||
void eeze_libmount_shutdown(void);
|
||||
Eina_Bool eeze_disk_libmount_mounted_get(Eeze_Disk *disk);
|
||||
|
||||
unsigned long eeze_disk_libmount_opts_get(Eeze_Disk *disk);
|
||||
const char *eeze_disk_libmount_mp_find_source(const char *mount_point);
|
||||
|
||||
const char *eeze_disk_libmount_mp_lookup_by_uuid(const char *uuid);
|
||||
|
|
Loading…
Reference in New Issue