From 58c89b619bcc1655c29686354e325d321c993b0f Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sun, 15 May 2011 22:56:14 +0000 Subject: [PATCH] new functions for applying a wrapper for (u)mount SVN revision: 59422 --- legacy/eeze/ChangeLog | 4 ++++ legacy/eeze/src/lib/Eeze_Disk.h | 21 ++++++++++++++++++ legacy/eeze/src/lib/eeze_disk_mount.c | 29 +++++++++++++++++++++++++ legacy/eeze/src/lib/eeze_disk_private.h | 1 + 4 files changed, 55 insertions(+) diff --git a/legacy/eeze/ChangeLog b/legacy/eeze/ChangeLog index 135860f1fa..f4de526e07 100644 --- a/legacy/eeze/ChangeLog +++ b/legacy/eeze/ChangeLog @@ -1,4 +1,8 @@ 2011-05-15 Mike Blumenkrantz (discomfitor/zmike) ++eeze_disk_mount_wrapper_set ++eeze_disk_mount_wrapper_get +Allow use of wrapper exes for mount commands (such as sudo) +--------------------------------------- +eeze_disk_udev_get_property +eeze_disk_udev_get_sysattr +eeze_disk_udev_walk_check_sysattr diff --git a/legacy/eeze/src/lib/Eeze_Disk.h b/legacy/eeze/src/lib/Eeze_Disk.h index 631bfa2ea9..08185b4844 100644 --- a/legacy/eeze/src/lib/Eeze_Disk.h +++ b/legacy/eeze/src/lib/Eeze_Disk.h @@ -249,6 +249,27 @@ EAPI Eina_Bool eeze_disk_removable_get(Eeze_Disk *disk); */ EAPI Eina_Bool eeze_disk_mounted_get(Eeze_Disk *disk); +/** + * @brief Get the previously set mount wrapper for a disk + * @param disk The disk + * @return The wrapper, or NULL on failure + * + * This returns the wrapper previously set with eeze_disk_mount_wrapper_set + */ +EAPI const char *eeze_disk_mount_wrapper_get(Eeze_Disk *disk); + +/** + * @brief Set a wrapper to run mount commands with + * @param disk The disk to wrap mount commands for + * @param wrapper The wrapper executable + * @return EINA_TRUE on success, else EINA_FALSE + * + * Use this function to set up a wrapper for running mount/umount commands. The wrapper must + * NOT use any of the standard mount/umount error code return values, and it must return 0 on success. + * Note that this function will call stat() on @p wrapper if not NULL to test for existence. + */ +EAPI Eina_Bool eeze_disk_mount_wrapper_set(Eeze_Disk *disk, const char *wrapper); + /** * @brief Begin a mount operation on the disk * @param disk The disk diff --git a/legacy/eeze/src/lib/eeze_disk_mount.c b/legacy/eeze/src/lib/eeze_disk_mount.c index d5465d3310..d01ea38d16 100644 --- a/legacy/eeze/src/lib/eeze_disk_mount.c +++ b/legacy/eeze/src/lib/eeze_disk_mount.c @@ -168,6 +168,33 @@ eeze_disk_mountopts_get(Eeze_Disk *disk) return disk->mount_opts; } +EAPI Eina_Bool +eeze_disk_mount_wrapper_set(Eeze_Disk *disk, const char *wrapper) +{ + struct stat s; + EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE); + if (wrapper) EINA_SAFETY_ON_TRUE_RETURN_VAL(!*wrapper, EINA_FALSE); + else + { + eina_stringshare_del(disk->mount_wrapper); + return EINA_TRUE; + } + if ((!stat(wrapper, &s)) && S_ISREG(s.st_mode)) + { + eina_stringshare_replace(&disk->mount_wrapper, wrapper); + return EINA_TRUE; + } + ERR("%s does not exist!", wrapper); + return EINA_FALSE; +} + +EAPI const char * +eeze_disk_mount_wrapper_get(Eeze_Disk *disk) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(disk, NULL); + return disk->mount_wrapper; +} + EAPI Eina_Bool eeze_disk_mount(Eeze_Disk *disk) { @@ -218,6 +245,8 @@ eeze_disk_mount(Eeze_Disk *disk) } if ((!disk->mount_point) || (!disk->mount_point[0])) return EINA_FALSE; + if (disk->mount_wrapper) + eina_strbuf_append_printf(disk->mount_cmd, "%s ", disk->mount_wrapper); if (disk->mount_opts == EEZE_DISK_MOUNTOPT_DEFAULTS) eina_strbuf_append_printf(disk->mount_cmd, EEZE_MOUNT_BIN" -o "EEZE_MOUNT_DEFAULT_OPTS" UUID=%s %s", disk->cache.uuid, disk->mount_point); else if (!disk->mount_opts) diff --git a/legacy/eeze/src/lib/eeze_disk_private.h b/legacy/eeze/src/lib/eeze_disk_private.h index 0fbcafeac5..0c5b972484 100644 --- a/legacy/eeze/src/lib/eeze_disk_private.h +++ b/legacy/eeze/src/lib/eeze_disk_private.h @@ -53,6 +53,7 @@ struct _Eeze_Disk const char *devpath; const char *fstype; const char *mount_point; + const char *mount_wrapper; unsigned long mount_opts; struct -- 2.34.1