new functions for applying a wrapper for (u)mount
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Sun, 15 May 2011 22:56:14 +0000 (22:56 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Sun, 15 May 2011 22:56:14 +0000 (22:56 +0000)
SVN revision: 59422

legacy/eeze/ChangeLog
legacy/eeze/src/lib/Eeze_Disk.h
legacy/eeze/src/lib/eeze_disk_mount.c
legacy/eeze/src/lib/eeze_disk_private.h

index 135860f..f4de526 100644 (file)
@@ -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
index 631bfa2..08185b4 100644 (file)
@@ -250,6 +250,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
  * @return #EINA_TRUE if the operation was started, else #EINA_FALSE
index d5465d3..d01ea38 100644 (file)
@@ -169,6 +169,33 @@ eeze_disk_mountopts_get(Eeze_Disk *disk)
 }
 
 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)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
@@ -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)
index 0fbcafe..0c5b972 100644 (file)
@@ -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