track all disk objects, fix typo in eeze optmap from earlier, catch and create extern...
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 16 May 2011 09:52:16 +0000 (09:52 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 16 May 2011 09:52:16 +0000 (09:52 +0000)
SVN revision: 59439

legacy/eeze/src/lib/eeze_disk.c
legacy/eeze/src/lib/eeze_disk_libmount.c
legacy/eeze/src/lib/eeze_disk_libmount_old.c
legacy/eeze/src/lib/eeze_disk_mount.c
legacy/eeze/src/lib/eeze_disk_private.h

index 91010affa569fe9676518ea7a8d2c8d715195d67..6a5726f8ce26a6a887d5913f7e58bdc695580be6 100644 (file)
@@ -9,6 +9,8 @@
 #include "eeze_udev_private.h"
 #include "eeze_disk_private.h"
 
+Eina_List *_eeze_disks = NULL;
+
 static Eeze_Disk_Type
 _eeze_disk_type_find(Eeze_Disk *disk)
 {
@@ -110,6 +112,8 @@ eeze_disk_new(const char *path)
    disk->mount_cmd_changed = EINA_TRUE;
    disk->unmount_cmd_changed = EINA_TRUE;
 
+   _eeze_disks = eina_list_append(_eeze_disks, disk);
+
    return disk;
 }
 
@@ -165,6 +169,8 @@ eeze_disk_new_from_mount(const char *mount_point)
    else
      disk->devpath = devpath;
    disk->mount_point = eina_stringshare_add(mount_point);
+   
+   _eeze_disks = eina_list_append(_eeze_disks, disk);
 
    return disk;
 error:
@@ -186,12 +192,12 @@ eeze_disk_free(Eeze_Disk *disk)
 {
    EINA_SAFETY_ON_NULL_RETURN(disk);
 
-
    udev_device_unref(disk->device);
    if (disk->mount_cmd)
      eina_strbuf_free(disk->mount_cmd);
    if (disk->unmount_cmd)
      eina_strbuf_free(disk->unmount_cmd);
+   _eeze_disks = eina_list_remove(_eeze_disks, disk);
    free(disk);
 }
 
index ade0c388c8d50d9f75a14d94edde0c47112654d0..d37bf2281ad428c27aa873a41b3048a0c556b902 100644 (file)
@@ -27,7 +27,7 @@ static struct libmnt_optmap eeze_optmap[] =
    { "noexec", EEZE_DISK_MOUNTOPT_NOEXEC, 0 },
    { "nosuid", EEZE_DISK_MOUNTOPT_NOSUID, 0 },
    { "remount", EEZE_DISK_MOUNTOPT_REMOUNT, 0 },
-   { "uid[=]", EEZE_DISK_MOUNTOPT_LOOP, 0 },
+   { "uid[=]", EEZE_DISK_MOUNTOPT_UID, 0 },
    { NULL, 0, 0 }
 };
 typedef struct libmnt_table libmnt_table;
@@ -41,6 +41,7 @@ static Eina_Bool _fstab_scan_active = EINA_FALSE;
 static libmnt_table *_eeze_mount_mtab = NULL;
 static libmnt_table *_eeze_mount_fstab = NULL;
 static libmnt_lock *_eeze_mtab_lock = NULL;
+extern Eina_List *_eeze_disks;
 
 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);
@@ -123,6 +124,43 @@ _eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_Fi
         ERR("Could not parse %s! keeping old tab...", path);
         goto error;
      }
+   if (data)
+     {
+        Eina_List *l;
+        Eeze_Disk *disk;
+
+        /* catch externally initiated mounts on existing disks by comparing known mount state to current state */
+        EINA_LIST_FOREACH(_eeze_disks, l, disk)
+          {
+             Eina_Bool mounted;
+
+             mounted = disk->mounted;
+
+             if ((eeze_disk_libmount_mounted_get(disk) != mounted) && (!disk->mount_status))
+               {
+                  if (!mounted)
+                    {
+                        Eeze_Event_Disk_Mount *e;
+                        e = malloc(sizeof(Eeze_Event_Disk_Mount));
+                        if (e)
+                          {
+                             e->disk = disk;
+                             ecore_event_add(EEZE_EVENT_DISK_MOUNT, e, NULL, NULL);
+                          }
+                    }
+                  else
+                    {
+                       Eeze_Event_Disk_Unmount *e;
+                       e = malloc(sizeof(Eeze_Event_Disk_Unmount));
+                       if (e)
+                         {
+                            e->disk = disk;
+                            ecore_event_add(EEZE_EVENT_DISK_UNMOUNT, e, NULL, NULL);
+                         }
+                    }
+               }
+          }
+     }
 
    mnt_free_table(bak);
    return;
@@ -197,9 +235,13 @@ eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
 
    mnt = mnt_table_find_srcpath(_eeze_mount_mtab, eeze_disk_devpath_get(disk), MNT_ITER_BACKWARD);
    if (!mnt)
-     return EINA_FALSE;
+     {
+        disk->mounted = EINA_FALSE;
+        return EINA_FALSE;
+     }
 
    eina_stringshare_replace(&disk->mount_point, mnt_fs_get_target(mnt));
+   disk->mounted = EINA_TRUE;
    return EINA_TRUE;
 }
 
index c1aa4f4b6df3db9f3f988d8c8684ee63afb2f43a..b551033a65dee9b2679a6875856ea8460d25ff5d 100644 (file)
@@ -26,6 +26,7 @@ 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;
+extern Eina_List *_eeze_disks;
 
 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);
@@ -108,6 +109,44 @@ _eeze_mount_tab_watcher(void *data, Ecore_File_Monitor *mon __UNUSED__, Ecore_Fi
         goto error;
      }
 
+   if (data)
+     {
+        Eina_List *l;
+        Eeze_Disk *disk;
+
+        /* catch externally initiated mounts on existing disks by comparing known mount state to current state */
+        EINA_LIST_FOREACH(_eeze_disks, l, disk)
+          {
+             Eina_Bool mounted;
+
+             mounted = disk->mounted;
+
+             if ((eeze_disk_libmount_mounted_get(disk) != mounted) && (!disk->mount_status))
+               {
+                  if (!mounted)
+                    {
+                        Eeze_Event_Disk_Mount *e;
+                        e = malloc(sizeof(Eeze_Event_Disk_Mount));
+                        if (e)
+                          {
+                             e->disk = disk;
+                             ecore_event_add(EEZE_EVENT_DISK_MOUNT, e, NULL, NULL);
+                          }
+                    }
+                  else
+                    {
+                       Eeze_Event_Disk_Unmount *e;
+                       e = malloc(sizeof(Eeze_Event_Disk_Unmount));
+                       if (e)
+                         {
+                            e->disk = disk;
+                            ecore_event_add(EEZE_EVENT_DISK_UNMOUNT, e, NULL, NULL);
+                         }
+                    }
+               }
+          }
+     }
+
    mnt_free_tab(bak);
    return;
 
@@ -159,9 +198,13 @@ eeze_disk_libmount_mounted_get(Eeze_Disk *disk)
 
    mnt = mnt_tab_find_srcpath(_eeze_mount_mtab, eeze_disk_devpath_get(disk), MNT_ITER_BACKWARD);
    if (!mnt)
-     return EINA_FALSE;
+     {
+        disk->mounted = EINA_FALSE;
+        return EINA_FALSE;
+     }
 
    disk->mount_point = eina_stringshare_add(mnt_fs_get_target(mnt));
+   disk->mounted = EINA_TRUE;
    return EINA_TRUE;
 }
 
index af059ae031899cc02e868bd160511f3329daae11..d26ab465a031af72500839ac9d349878b0acd414 100644 (file)
@@ -68,7 +68,6 @@ _eeze_disk_mount_result_handler(void *data __UNUSED__, int type __UNUSED__, Ecor
    eeze_events = eina_list_remove_list(eeze_events, l);
    if (disk->mount_status == EEZE_DISK_MOUNTING)
      {
-        disk->mount_status = EEZE_DISK_NULL;
         disk->mounter = NULL;
         if (!ev->exit_code)
           { 
@@ -99,7 +98,6 @@ _eeze_disk_mount_result_handler(void *data __UNUSED__, int type __UNUSED__, Ecor
           e = malloc(sizeof(Eeze_Event_Disk_Unmount));
           EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
           e->disk = disk;
-          disk->mount_status = EEZE_DISK_NULL;
           disk->mounter = NULL;
           ecore_event_add(EEZE_EVENT_DISK_UNMOUNT, e, NULL, NULL);
           break;
index 1959348a7bd597c164fd5cca14274bc6bf283cab..3146a088a64332cd02e4cbabaf2c4350d49db5cf 100644 (file)
@@ -47,6 +47,7 @@ struct _Eeze_Disk
    Eina_Strbuf *unmount_cmd;
    Eina_Bool mount_cmd_changed : 1;
    Eina_Bool unmount_cmd_changed : 1;
+   Eina_Bool mounted : 1;
    Ecore_Exe *mounter;
 
    const char *syspath;