Changeset 2050

Show
Ignore:
Timestamp:
02/20/10 23:28:51 (5 months ago)
Author:
tpgww
Message:

enable UDisks usage if available

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/filesystem/e2_devkit.c

    r1958 r2050  
    2626/* 
    2727TODO 
    28 confirm that mount-point and -options are effectively hardcoded within devkit mount opration 
     28confirm that mount-point is effectively hardcoded in daemon's mount-opration 
     29check how to work with detachable devices (udisks) 
    2930*/ 
    3031 
     
    3637#include "e2_fs.h" 
    3738 
    38 #define DEVKIT_IFACE_NAME "org.freedesktop.DeviceKit.Disks" 
    39 #define DEVKIT_PATH_ROOT "/org/freedesktop/DeviceKit/Disks/devices/" 
    40  
    41 //subset of all possible device-properties 
     39#define DEVKIT_IFACE 
     40 
     41#ifdef DEVKIT_IFACE 
     42# define DEVKIT_IFACE_NAME "org.freedesktop.DeviceKit.Disks" 
     43# define DEVKIT_BUS_PATH "/org/freedesktop/DeviceKit/Disks" 
     44//PATH_ROOT supplied to funcs will be "/org/freedesktop/DeviceKit/Disks/devices/" 
     45#endif 
     46#define UDISK_IFACE_NAME "org.freedesktop.UDisks" 
     47#define UDISK_BUS_PATH "/org/freedesktop/UDisks" 
     48//PATH_ROOT supplied to funcs will be "/org/freedesktop/UDisks/devices/" 
     49 
     50//subset of available device-properties 
    4251typedef struct _DeviceProperties 
    4352{ 
    4453        gchar   *device_file;           //e.g. /dev/sda 
    45 //      gchar  **device_file_by_id; //NULL terminated array of unique target(s) linked to corresponding device(s) 
    46                                                                 //e.g. /dev/disk/by-id/ata-ST910021AS_3MH05AVA-part1 >> /dev/sda1 
    47                                                                 //AND ALSO uid(s) linked to device(s) 
    48                                                                 //e.g. /dev/disk/by-uuid/4165-968D >> /dev/sda1 
    49 //      gchar  **device_file_by_path; //NULL terminated array of port/partition(s) linked to corresponding device(s) 
    50                                                                 //e.g. /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:1:0 >> /dev/sda2 
    51                                                                 //i.e. can get a count of mountpoints for the device_file 
     54#ifdef DEVKIT_IFACE 
    5255        gchar   *device_mount_path;     //where the device is mounted, valid only if device-is-mounted is TRUE 
    53 //      gchar   *device_presentation_name; //device name for UI use 
     56#endif 
     57        //for udisks 
     58        gchar   **device_mount_paths;//NULL terminated array of paths where the device is mounted, 
     59                                                                //valid only if device-is-mounted is TRUE 
     60 
    5461        gchar   *id_usage;      //filesystem; crypto; partitiontable; raid; other; blank=(unknown) 
    5562        gchar   *id_type;       //per id-usage: ext3, vfat etc swap blank=(unknown) 
     
    5764//      guint64 device_media_detection_time; 
    5865        gboolean device_is_removable; 
     66        gboolean device_is_detachable; //udisks only 
    5967        gboolean device_is_media_available; 
    6068        gboolean device_is_media_change_detected; 
     
    7280typedef struct _DeviceData 
    7381{ 
    74         gchar *object_path; //DEVKIT_PATH_ROOT"<native-path-cleaned-basename>" i.e. with any '-' >> '_' 
     82        gchar *object_path; //=PATH_ROOT"<native-path-cleaned-basename>" i.e. with any '-' >> '_' 
    7583        DBusGProxy *devproxy;   //not the same as the session-proxy, per-device to support async usage of the proxy 
    7684        DeviceProperties props; 
     
    7886} DeviceData; 
    7987 
    80 typedef struct _SessionDevices 
    81 { 
     88typedef struct _DevicesSession 
     89{ 
     90#ifdef DEVKIT_IFACE 
     91        gboolean udisks;                //TRUE for udisks session, FALSE for devkit-disks (saves parsing daemon_version) 
     92#endif 
     93        gchar *daemon_version; 
     94        const gchar *iface_name;//DEVKIT_IFACE_NAME or UDISK_IFACE_NAME 
    8295        DBusGConnection *bus;   //connection to system bus 
    8396        DBusGProxy *proxy;              //abstracted proxy for interface exported by a connection on bus 
    84         GHashTable *logged_devices; /* known removable devices, with 
    85                 key = (const) device object path, value = the corresponding DeviceData */ 
    86 } SessionDevices; 
    87  
    88 static SessionDevices devicesdata; 
    89  
    90 static void _e2_devkit_device_properties_clear (DeviceProperties *props); 
     97        GHashTable *logged_devices; //known removable devices, with 
     98                                                                // key = (const) device object path, 
     99                                                                // value = the corresponding DeviceData* 
     100} DevicesSession; 
     101 
     102static DevicesSession session; 
     103 
    91104static void _e2_devkit_device_changed_cb (DBusGProxy *proxy, 
    92105        const gchar *object_path, gpointer user_data); 
     
    98111 
    99112/** 
    100 @brief cleanup allocated properties data for a device 
    101 @param props the data struct to be processed 
    102 @return 
    103 */ 
    104 static void _e2_devkit_device_properties_clear (DeviceProperties *props) 
    105 { 
    106         g_free (props->device_file); 
    107 //      g_strfreev (props->device_file_by_id); 
    108 //      g_strfreev (props->device_file_by_path); 
    109         g_free (props->device_mount_path); 
    110 //      g_free (props->device_presentation_name); 
    111         g_free (props->id_usage); 
    112         g_free (props->id_type); 
    113         g_free (props->drive_media); 
     113@brief get daemon version 
     114Queries the DaemonVersion property on @a iface of @a object_path owned by the 
     115well-known name @a iface on the D-Bus system message bus. 
     116@param bus pointer to dbus connection object 
     117@param iface string like "org.freedesktop.DeviceKit.Disks" 
     118@param object_path string like "/org/freedesktop/DeviceKit/Disks" 
     119@return newly-allocated string containing version descriptor, or NULL upon error 
     120*/ 
     121static gchar *_e2_devkit_get_version (DBusGConnection *bus, 
     122        const gchar *iface, const gchar *object_path) 
     123{ 
     124        gchar *version; 
     125        DBusGProxy *prop_proxy; 
     126        GValue value1 = {0}; 
     127        GError *error; 
     128 
     129        prop_proxy = dbus_g_proxy_new_for_name (bus, 
     130                iface, 
     131                object_path, 
     132                "org.freedesktop.DBus.Properties"); 
     133        if (prop_proxy == NULL) 
     134        { 
     135//              _e2_devkit_advise (_("some warning ..."), NULL); 
     136                printd (WARN, "Unable to establish dbus connection for daemon interrogation"); 
     137                return NULL; 
     138        } 
     139        error = NULL; 
     140        if (dbus_g_proxy_call (prop_proxy, 
     141                        "Get", 
     142                        &error, 
     143                        G_TYPE_STRING, 
     144                        iface, 
     145                        G_TYPE_STRING, 
     146                        "DaemonVersion", 
     147                        G_TYPE_INVALID, 
     148                        G_TYPE_VALUE, 
     149                        &value1, 
     150                        G_TYPE_INVALID)) 
     151        { 
     152                version = g_strdup (g_value_get_string (&value1)); 
     153                g_value_unset (&value1); 
     154                printd (DEBUG,"DaemonVersion property for %s is \"%s\"", object_path, version); 
     155        } 
     156        else 
     157        { 
     158                version = NULL; 
     159                printd (DEBUG,"Failed to get DaemonVersion property for %s: %s", 
     160                        object_path, error->message); 
     161                g_error_free (error); 
     162        } 
     163 
     164        g_object_unref (G_OBJECT(prop_proxy)); 
     165        return version; 
    114166} 
    115167/** 
     
    118170The property-names conform to the ones used in gnome-disk-utility 2.28 
    119171like "DeviceIsDrive", replacing ones like "device-is-drive" 
    120 @param bus connection to system bus for this session 
    121 @param object_path DEVKIT_PATH_ROOT etc 
     172@param sessionptr pointer to connection data struct for this session 
     173@param object_path PATH_ROOT... 
    122174@param props pointer to empty (0'd) properties struct to be populated 
    123175@return TRUE if process completes successfully, FALSE upon error 
    124176*/ 
    125 static gboolean _e2_devkit_device_properties_get (DBusGConnection *bus, 
     177static gboolean _e2_devkit_device_properties_get (DevicesSession *sessionptr, 
    126178        const gchar *object_path, DeviceProperties *props) 
    127179{ 
    128180        gboolean retval; 
     181        gchar *device_iface; 
    129182        DBusGProxy *prop_proxy; 
    130183        GValue value1 = {0}; 
     
    132185        GHashTable *hash_table; 
    133186 
    134         memset (props, 0, sizeof(DeviceProperties));    //start with clear data 
    135  
    136         prop_proxy = dbus_g_proxy_new_for_name (bus, DEVKIT_IFACE_NAME, 
    137                 object_path, "org.freedesktop.DBus.Properties"); 
     187        prop_proxy = dbus_g_proxy_new_for_name (sessionptr->bus, 
     188                sessionptr->iface_name, 
     189                object_path, 
     190                "org.freedesktop.DBus.Properties"); 
    138191        if (prop_proxy == NULL) 
    139192        { 
    140 //              _e2_devkit_advise (_("message"), NULL); 
    141                 printd (WARN, "Unable to connect to devicekit daemon"); 
     193//              _e2_devkit_advise (_("some warning ..."), NULL); 
     194                printd (WARN, "Unable to establish dbus connection for properties interrogation"); 
    142195                return FALSE; 
    143196        } 
    144197 
     198        device_iface = g_strconcat (sessionptr->iface_name, ".Device", NULL); 
     199        memset (props, 0, sizeof(DeviceProperties)); 
    145200        error = NULL; 
    146201        //no point in doing async interrogations here 
    147         //since most devices are not relevant, best to do a separate, minmimal, 
    148         //check before getting full set of device properties 
     202        //since most devices are not relevant, best to do some separate, minimal, 
     203        //checks before getting full set of device properties 
    149204        if (dbus_g_proxy_call (prop_proxy, 
    150205                        "Get", 
    151206                        &error, 
    152207                        G_TYPE_STRING, 
    153                         DEVKIT_IFACE_NAME".Device", 
     208                        device_iface, 
    154209                        G_TYPE_STRING, 
    155210                        "DeviceIsDrive", 
     
    163218                else 
    164219                { 
     220                        g_value_unset (&value1); 
    165221abort: 
    166                         g_value_unset (&value1); 
     222                        g_free (device_iface); 
     223                        g_object_unref (G_OBJECT(prop_proxy)); 
    167224                        props->ignored = TRUE; 
    168                         g_object_unref (G_OBJECT(prop_proxy)); 
    169225                        return TRUE; 
    170226                } 
     
    172228        else 
    173229        { 
    174                 printd (DEBUG,"Get() failed to get properties for %s: %s", 
    175                         object_path, error->message); 
     230                printd (DEBUG,"Failed to get DeviceIsDrive property for %s: %s", 
     231                        device_iface, error->message); 
    176232                g_error_free (error); 
     233                g_free (device_iface); 
    177234                return FALSE; 
    178235        } 
     
    184241                        &error, 
    185242                        G_TYPE_STRING, 
    186                         DEVKIT_IFACE_NAME".Device", 
     243                        device_iface, 
    187244                        G_TYPE_STRING, 
    188245                        "DeviceIsRemovable", 
     
    192249                        G_TYPE_INVALID)) 
    193250        { 
    194                 if (g_value_get_boolean (&value1)) 
    195                         props->device_is_removable = TRUE; 
     251                props->device_is_removable = g_value_get_boolean (&value1); 
     252                g_value_unset (&value1); 
     253        } 
     254        else 
     255        { 
     256                printd (DEBUG,"Failed to get DeviceIsRemovable property for %s: %s", 
     257                        device_iface, error->message); 
     258                g_error_free (error); 
     259                g_free (device_iface); 
     260                return FALSE; 
     261        } 
     262 
     263#ifdef DEVKIT_IFACE 
     264        if (sessionptr->udisks) 
     265        { 
     266#endif 
     267                if (dbus_g_proxy_call (prop_proxy, 
     268                                "Get", 
     269                                &error, 
     270                                G_TYPE_STRING, 
     271                                device_iface, 
     272                                G_TYPE_STRING, 
     273                                "DriveCanDetach", 
     274                                G_TYPE_INVALID, 
     275                                G_TYPE_VALUE, 
     276                                &value1, 
     277                                G_TYPE_INVALID)) 
     278                { 
     279                        props->device_is_detachable = g_value_get_boolean (&value1); 
     280                        g_value_unset (&value1); 
     281                } 
    196282                else 
    197                         goto abort; 
    198         } 
    199  
    200         g_value_unset (&value1); 
     283                { 
     284                        printd (DEBUG,"Failed to get DriveCanDetach property for %s: %s", 
     285                                device_iface, error->message); 
     286                        g_error_free (error); 
     287                        g_free (device_iface); 
     288                        return FALSE; 
     289                } 
     290#ifdef DEVKIT_IFACE 
     291        } 
     292#endif 
     293        if (!(props->device_is_removable || props->device_is_detachable)) 
     294                goto abort; 
    201295 
    202296        //populate other properties the slow and lazy way (get all properties then filter them) 
     
    205299                        &error, 
    206300                        G_TYPE_STRING, 
    207                         DEVKIT_IFACE_NAME".Device", 
     301                        device_iface, 
    208302                        G_TYPE_INVALID, 
    209303                        dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), 
     
    216310                if (propvalue != NULL) 
    217311                        props->device_file = g_strdup (g_value_get_string (propvalue)); 
    218 //              propvalue = g_hash_table_lookup (hash_table, "DeviceFileById"); 
    219 //              if (propvalue != NULL) 
    220 //                      props->device_file_by_id = g_strdupv (g_value_get_boxed (propvalue)); 
    221 //              propvalue = g_hash_table_lookup (hash_table, "DeviceFileByPath"); 
    222 //              if (propvalue != NULL) 
    223 //                      props->device_file_by_path = g_strdupv (g_value_get_boxed (propvalue)); 
    224                 propvalue = g_hash_table_lookup (hash_table, "DeviceMountPath"); 
    225                 if (propvalue != NULL) 
    226                         props->device_mount_path = g_strdup (g_value_get_string (propvalue)); 
    227 //              propvalue = g_hash_table_lookup (hash_table, "DevicePresentationName"); 
    228 //              if (propvalue != NULL) 
    229 //                      props->device_presentation_name = g_strdup (g_value_get_string (propvalue)); 
     312#ifdef DEVKIT_IFACE 
     313                if (!sessionptr->udisks) 
     314                { 
     315                        propvalue = g_hash_table_lookup (hash_table, "DeviceMountPath"); 
     316                        if (propvalue != NULL) 
     317                                props->device_mount_path = g_strdup (g_value_get_string (propvalue)); 
     318                } 
     319                else 
     320                { 
     321#endif 
     322                        propvalue = g_hash_table_lookup (hash_table, "DeviceMountPaths"); 
     323                        if (propvalue != NULL) 
     324                                props->device_mount_paths = g_strdupv (g_value_get_boxed (propvalue)); 
     325#ifdef DEVKIT_IFACE 
     326                } 
     327#endif 
    230328                propvalue = g_hash_table_lookup (hash_table, "IdUsage"); 
    231329                if (propvalue != NULL) 
     
    274372        else 
    275373        { 
    276                 printd (DEBUG,"GetAll() failed to get properties for %s: %s", 
     374                printd (DEBUG,"Failed to get all properties for %s: %s", 
    277375                        object_path, error->message); 
    278376                g_error_free (error); 
    279377                retval = FALSE; 
    280378        } 
     379        //CHECKME props->ignored = ? 
     380        g_free (device_iface); 
    281381        g_object_unref (prop_proxy); 
    282382 
     
    284384} 
    285385/** 
     386@brief cleanup allocated properties data for a device 
     387@param props the data struct to be processed 
     388@return 
     389*/ 
     390static void _e2_devkit_device_properties_clear (DeviceProperties *props) 
     391{ 
     392        g_free (props->device_file); 
     393#ifdef DEVKIT_IFACE 
     394        g_free (props->device_mount_path); 
     395#endif 
     396        g_strfreev (props->device_mount_paths); 
     397        g_free (props->id_usage); 
     398        g_free (props->id_type); 
     399        g_free (props->drive_media); 
     400} 
     401/** 
    286402@brief cleanup device-data 
    287 @param data data for a device 
     403@param data pointer to data struct for a device 
    288404@return 
    289405*/ 
     
    296412        } 
    297413        g_free (data->object_path); 
     414        g_object_unref (G_OBJECT(data->devproxy)); 
    298415        _e2_devkit_device_properties_clear (&data->props); 
    299         g_object_unref(G_OBJECT(data->devproxy)); 
    300416 
    301417        DEALLOCATE (DeviceData, data); 
     
    309425{ 
    310426        //NOTE: ensure this cleanup conforms to the contents of data->props 
     427#ifdef DEVKIT_IFACE 
    311428        g_free (data->props.device_mount_path); 
    312429        data->props.device_mount_path = NULL; 
     430#endif 
     431        g_strfreev (data->props.device_mount_paths); 
     432        data->props.device_mount_paths = NULL; 
    313433 
    314434        g_free (data->props.id_usage); 
     
    327447@brief determine whether @a object_path represents a device we're interested in, 
    328448 and if so, set up data for it. 
    329 @param pool 
    330 @param object_path DEVKIT_PATH_ROOT etc 
     449@param sessionptr pointer to session data struct 
     450@param object_path PATH_ROOT... 
    331451@return pointer to device data, or NULL if not wanted or error 
    332452*/ 
    333 static DeviceData *_e2_devkit_device_get (SessionDevices *pool, 
     453static DeviceData *_e2_devkit_device_get (DevicesSession *sessionptr, 
    334454        const gchar *object_path) 
    335455{ 
    336456        DeviceProperties props; 
    337         if (!_e2_devkit_device_properties_get (pool->bus, object_path, &props)) 
    338         { 
    339                 printd (DEBUG, "Devkit: Cannot determine properties for device %s", object_path); 
     457        if (!_e2_devkit_device_properties_get (sessionptr, object_path, &props)) 
     458        { 
     459                printd (DEBUG, "Devices deamon cannot determine properties for device %s", object_path); 
    340460                return NULL; 
    341461        } 
     
    343463        if (props.ignored) 
    344464        { 
    345 //              printd (DEBUG, "Devkit: Not interested in device %s", object_path); 
     465//              printd (DEBUG, "Devices deamon not interested in device %s", object_path); 
    346466                return NULL; 
    347467        } 
     
    349469        { 
    350470                //this is a device of interest 
     471                gchar *device_iface; 
    351472                DeviceData *device; 
    352473                DBusGProxy *dev_proxy; //CHECKME needed ? 
     
    355476                CHECKALLOCATEDWARN (device, _e2_devkit_device_properties_clear (&props);return NULL;) 
    356477 
    357                 dev_proxy = dbus_g_proxy_new_for_name (pool->bus, 
    358                         DEVKIT_IFACE_NAME, 
     478                device_iface = g_strconcat (sessionptr->iface_name, ".Device", NULL); 
     479                dev_proxy = dbus_g_proxy_new_for_name (sessionptr->bus, 
     480                        sessionptr->iface_name, 
    359481                        object_path, 
    360                         DEVKIT_IFACE_NAME".Device"); 
     482                        device_iface); 
     483                g_free (device_iface); 
    361484 
    362485                if (dev_proxy == NULL) 
     
    384507/** 
    385508@brief log current removable devices 
    386 @param pool pointer to devkit data struct 
     509@param sessionptr pointer to devkit data struct 
    387510@return TRUE if enumeration succeeded 
    388511*/ 
    389 static gboolean _e2_devkit_detect_current_removables (SessionDevices *pool) 
     512static gboolean _e2_devkit_detect_current_removables (DevicesSession *sessionptr) 
    390513{ 
    391514        guint i; 
     
    396519        error = NULL; 
    397520        //CHECKME synchronous process ok ? 
    398         if (!dbus_g_proxy_call (pool->proxy, "EnumerateDevices", &error, G_TYPE_INVALID, 
     521        if (!dbus_g_proxy_call (sessionptr->proxy, "EnumerateDevices", &error, G_TYPE_INVALID, 
    399522                        dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), 
    400523                        &devices, G_TYPE_INVALID)) 
     
    405528        } 
    406529 
    407 //      printd (DEBUG, "Devkit: %d devices reported", devices->len); 
     530//      printd (DEBUG, "Devices daemon reported %u devices", devices->len); 
    408531        for (i = 0; i < devices->len; i++) 
    409532        { 
    410                 DeviceData *device = _e2_devkit_device_get (pool, devices->pdata[i]); 
     533                DeviceData *device = _e2_devkit_device_get (sessionptr, devices->pdata[i]); 
    411534                if (device != NULL) 
    412535                { 
    413                         printd (DEBUG, "Devkit: Logging device %s", devices->pdata[i]); 
    414                         g_hash_table_insert (pool->logged_devices, 
     536                        printd (DEBUG, "Logging removable device %s", device->props.device_file); 
     537                        g_hash_table_insert (sessionptr->logged_devices, 
    415538                                (gpointer) device->object_path, //not another copy, not truncated 
    416539                                (gpointer) device); 
    417540                } 
    418541//              else 
    419 //                      printd (DEBUG, "Devkit: Skipping device %s @ %x", devices->pdata[i], device); 
     542//                      printd (DEBUG, "Skipping device %s @ %x", device->props.device_file, device); 
    420543 
    421544                g_free (devices->pdata[i]); //CHECKME does the array-data self-destruct (glib >= 2.22) 
     
    429552@brief automount a volume 
    430553This is called from within timer callback i.e. BGL is off 
    431 @param pool 
     554@param sessionptr 
    432555@param device 
    433556 
    434557@return TRUE if the mount is performed successfully or is not needed 
    435558*/ 
    436 static gboolean _e2_devkit_mount_volume (SessionDevices *pool, DeviceData *device) 
     559static gboolean _e2_devkit_mount_volume (DevicesSession *sessionptr, DeviceData *device) 
    437560{ 
    438561        gboolean optical; 
     
    447570                ) 
    448571        { 
    449                 printd (DEBUG, "Devkit: device does not need to be mounted"); 
     572                printd (DEBUG, "Device %s does not need to be mounted", device->props.device_file); 
    450573                return TRUE; 
    451574        } 
    452575 
    453576        fstype = device->props.id_usage; 
    454         if (fstype == NULL || strcmp (fstype, "filesystem"))    //CHECKME "crypto", "raid", "other" 
    455         { 
    456                 printd (DEBUG, "Devkit: mounting this device-type is not supported"); 
     577        if (fstype == NULL || 
     578                !( strcmp (fstype, "filesystem") == 0 
     579                || strcmp (fstype, "raid") == 0 //OK ? 
     580                || strcmp (fstype, "crypto") == 0)) //OK ? //CHECKME "other" 
     581        { 
     582                printd (DEBUG, "Unmountable device %s", device->props.device_file); 
    457583                return TRUE;    //some unmountable sort of device 
    458584        } 
     
    461587        if (fstype == NULL || *fstype == '\0') 
    462588        { 
    463                 printd (DEBUG, "Devkit: device filesystem-type is not recognised"); 
     589                printd (DEBUG, "Unrecognised filesystem-type for device %s", device->props.device_file); 
    464590                return TRUE;    //not a data-medium 
    465591        } 
    466592 
    467 #if 0 
    468         //determine a suitable mountpoint ... apparently unusable if devkit does the mounting 
    469  
    470 #define FIRSTOPTIC 10 
    471         const gchar *disktypes[] = 
    472         { 
    473                 //for DeviceKit-Disks 004 
    474                 "flash", 
    475                 "flash_cf", 
    476                 "flash_ms", 
    477                 "flash_sm",             //aka "smart" 
    478  
    479                 "flash_sd", 
    480                 "flash_sdhc", 
    481                 "flash_mmc",    //aka "sd_mmc" 
    482  
    483                 "floppy", 
    484                 "floppy_zip",   //aka "zip" 
    485                 "floppy_jaz",   //aka "jaz" 
    486  
    487                 "optical_cd",   //"cd", index 10 
    488                 "optical_cd_r", //"cdrom" 
    489                 "optical_cd_rw", //"cd" writable, index 12 
    490                 "optical_dvd",  //"dvd" 
    491                 "optical_dvd_r", //"dvdrom" 
    492                 "optical_dvd_rw", //"dvd" writable 15 
    493                 "optical_dvd_ram", //writable 16 
    494                 "optical_dvd_plus_r", 
    495                 "optical_dvd_plus_rw", //writable 18 
    496                 "optical_dvd_plus_r_dl", 
    497                 "optical_dvd_plus_rw_dl", //writable 20 
    498                 "optical_bd", 
    499                 "optical_bd_r", 
    500                 "optical_bd_re", 
    501                 "optical_hddvd", //24 
    502                 "optical_hddvd_r", 
    503                 "optical_hddvd_rw", //writable 26 
    504                 "optical_mo", 
    505                 "optical_mrw", 
    506                 "optical_mrw_w", //writable 29 
    507         }; 
    508  
    509         const gchar *last; 
    510         gboolean readonly; 
    511         gint i; 
    512  
    513 /*      check for an available mountpoint 
    514         mountpoint from lsb spec: 
    515                 /media 
    516                         /floppy Floppy drive (optional) 
    517                         /cdrom  CD-ROM drive (optional) 
    518                         /cdrecorder     CD writer (optional) 
    519                         /zip    Zip drive (optional) 
    520         Where more than one device exists for mounting a certain type of media, mount 
    521         directories can be created by appending a digit to the name, starting with 
    522         '0', but the unqualified name must also exist 
    523  
    524         for device names: 
    525         Partitions or volumes will appear as device-appended numbers, like 
    526            sda1, sda2 .... 
    527         Some devices e.g. cdrom are themselves treated as a volume, and will then 
    528         have no partition number 
    529         Devices to be mounted may already exist in /dev 
    530 */ 
    531         if (optical) 
    532         {       //this volume is, or is part of, an optical disk 
    533                 gint count = sizeof (disktypes) / sizeof (const gchar *); 
    534                 if (device->props.drive_media == NULL || *device->props.drive_media == '\0') 
    535                         i = count;      //set defaults 
    536                 else 
    537                 { 
    538                         for (i = FIRSTOPTIC; i < count; i++) 
    539                         { 
    540                                 if (!strcmp (disktypes[i], device->props.drive_media)) 
    541                                 { 
    542                                         switch (i) 
    543                                         { 
    544                                                 case 12: 
    545                                                 case 15: 
    546                                                 case 16: 
    547                                                 case 18: 
    548                                                 case 20: 
    549                                                 case 26: 
    550                                                 case 29: 
    551                                                         if (i <= 12) 
    552                                                                 last = "cdrecorder"; 
    553                                                         else if (i <= 20 || i == 24 || i == 25 || i == 26) 
    554                                                                 last = "dvdrecorder"; 
    555                                                         else 
    556                                                                 last = "recorder"; 
    557                                                         readonly = FALSE; 
    558                                                         break; 
    559                                                 default: 
    560                                                         if (i <= 12) 
    561                                                                 last = "cdrom"; 
    562                                                         else if (i <= 20 || i == 24 || i == 25 || i == 26) 
    563                                                                 last = "dvdrom"; 
    564                                                         else 
    565                                                                 last = "disk"; 
    566                                                         readonly = TRUE; 
    567                                                         break; 
    568                                         } 
    569                                         break; 
    570                                 } 
    571                         } 
    572                 } 
    573                 if (i == count) 
    574                 {       //defaults 
    575                         last = "cdrom"; 
    576                         readonly = TRUE; 
    577                 } 
    578         } 
    579         else //not an optical disk 
    580         { 
    581                 if (device->props.drive_media == NULL || *device->props.drive_media == '\0') 
    582                         i = FIRSTOPTIC; //set defaults 
    583                 else 
    584                 { 
    585                         for (i = 0; i < FIRSTOPTIC; i++) 
    586                         { 
    587                                 last = disktypes[i]; 
    588                                 if (!strcmp (last, device->props.drive_media)) 
    589                                 { 
    590                                         switch (i) 
    591                                         { 
    592                                                 default: 
    593                                                         last = "disk";  //FIXME 
    594                                                         break; 
    595                                                 case 7: 
    596                                                         last = "floppy"; 
    597                                                         break; 
    598                                                 case 8: 
    599                                                         last = "zip"; 
    600                                                         break; 
    601                                                 case 9: 
    602                                                         last = "jaz"; 
    603                                                         break; 
    604                                         } 
    605                                         readonly = FALSE; 
    606                                         break; 
    607                                 } 
    608                         } 
    609                 } 
    610                 if (i == FIRSTOPTIC) 
    611                 {       //defaults 
    612                         last = "disk"; 
    613                         readonly = FALSE; 
    614                 } 
    615         } 
    616  
    617         GList *mounts_now, *member; 
    618         gchar *str, *utf, *mountpoint; 
    619  
    620         mounts_now = e2_fs_mount_get_mounts_list (); 
    621         mountpoint = g_build_filename (E2_MOUNTPLACE, last, NULL); 
    622         str = g_strdup (mountpoint); 
    623         utf = F_FILENAME_FROM_LOCALE (str);     //not strictly necessary, the default path is all ASCII 
    624         guint count = 0; 
    625 retry: 
    626         for (member = mounts_now; member != NULL; member = member->next) 
    627         { 
    628                 if (!strcmp ((gchar*)member->data, utf)) 
    629                 { 
    630                         g_free (str); 
    631                         F_FREE (utf, str); 
    632                         str = g_strdup_printf ("%s%d", mountpoint, count++); 
    633                         utf = F_FILENAME_FROM_LOCALE (str); 
    634                         goto retry; 
    635                 } 
    636         } 
    637  
    638         g_free (mountpoint); 
    639         F_FREE (utf, str); 
    640         e2_list_free_with_data (&mounts_now); 
    641         mountpoint = str; 
    642  
    643         //determine mount options from the available ones ... apparently unusable if devkit does the mounting 
    644  
    645         gboolean readonly_valid = FALSE; 
    646         gint freeindex = -1; 
    647  
    648         GPtrArray *extra_options = g_ptr_array_sized_new (6); 
    649         gboolean FIXME; //get suitable options 
    650         gchar **mountopts = NULL; 
    651         if (mountopts != NULL) 
    652         { 
    653                 gchar **thisopt; 
    654                 for (thisopt = mountopts; *thisopt != NULL; thisopt++) 
    655                 { 
    656                 //CHECKME which mount options are most suitable ? 
    657                 //e.g. ro,sync,dirsync,noatime,nodiratime,noexec,quiet,remount,exec,utf8 
    658                 //shortname=,codepage=,iocharset=,umask=,dmask=,fmask=,uid=,flush 
    659                         if (strcmp (*thisopt, "exec") == 0) 
    660                         { 
    661                                 g_ptr_array_add (extra_options, *thisopt); 
    662                         } 
    663                         else if (strncmp (*thisopt, "umask=", 6) == 0) 
    664                         { 
    665                                 g_ptr_array_add (extra_options, g_strconcat (*thisopt, "0", NULL)); 
    666                                 freeindex = extra_options->len - 1; //for leak fix 
    667                         } 
    668                         else if (strcmp (*thisopt, "sync") == 0) 
    669                         { 
    670                                 g_ptr_array_add (extra_options, *thisopt); 
    671                         } 
    672                         else if (strcmp (*thisopt, "ro") == 0) 
    673                         { 
    674                                 readonly_valid = TRUE; 
    675                                 if (readonly) 
    676                                         g_ptr_array_add (extra_options, *thisopt); 
    677                         } 
    678                         else if (readonly) 
    679                         { 
    680                                 readonly_valid = TRUE; 
    681                                         g_ptr_array_add (extra_options, "ro"); 
    682                         } 
    683  
    684                 } 
    685         } 
    686         g_ptr_array_add (extra_options, NULL);  //terminate the array 
    687 #endif //0 
    688  
    689         gboolean retval; 
    690  
    691         //do it 
    692 # if 0 //direct 
    693         gint res = run command 
    694         retval = (res == 0); 
    695 /*      if (retval) 
    696         { 
    697                 //"refresh" the filelist(s) if needed 
    698                 gchar *utf = F_FILENAME_FROM_LOCALE (mountpoint); 
    699                 if (g_str_has_prefix (curr_view->dir, utf)) 
    700                         do something 
    701                 if (g_str_has_prefix (other_view->dir, utf)) 
    702                         do something 
    703                 F_FREE (utf, mountpoint); 
    704         } 
    705 */ 
    706 # else //via devkit 
    707         gpointer cb_data = device; 
    708 #if 1 
    709         gchar *options[2]; 
    710  
    711         options[0] = NULL; 
    712 #endif 
    713  
    714         retval = 
     593        //apparently, a mountpoint can't be specified to the daemon 
     594        //so we don't bother with non-default mount-options, either 
     595        return 
    715596                (dbus_g_proxy_begin_call (device->devproxy, "FilesystemMount", 
    716                 _e2_devkit_mount_async_cb, 
    717                 cb_data, (GDestroyNotify) NULL, 
    718                 G_TYPE_STRING, fstype, 
    719 #  if 0 
    720                 G_TYPE_STRV, extra_options->pdata, 
    721 #  else 
    722                 G_TYPE_STRV, options,  //no mount options 
    723 #  endif 
    724                 G_TYPE_INVALID) != NULL); 
    725 # endif 
    726 #if 0 
    727         //cleanup 
    728         g_free (mountpoint); 
    729         //CHECKME free all options ? does the array-data self-destruct (glib >= 2.22) 
    730         if (freeindex != -1) 
    731                 g_free (g_ptr_array_index (extra_options, freeindex)); 
    732         g_ptr_array_free (extra_options, TRUE); 
    733 #endif 
    734         return retval; 
     597                        _e2_devkit_mount_async_cb, 
     598                        device, (GDestroyNotify) NULL, 
     599                        G_TYPE_STRING, fstype, 
     600                        G_TYPE_STRV, NULL,  //no mount options 
     601                        G_TYPE_INVALID) 
     602                != NULL); 
     603} 
     604 
     605/** 
     606@brief if possible, change CWD out of @mountpoint so we don't ourself block the unmount 
     607@param mountpoint a mountpoint path supplied by the daemon, converted to UTF-8 
     608 
     609@return 
     610*/ 
     611static void _e2_devkit_skipaway (const gchar *mountpoint) 
     612{ 
     613        gchar *elsewhere, *s; 
     614 
     615        if (mountpoint == NULL) 
     616                return; 
     617        elsewhere = g_strdup (mountpoint); 
     618        g_strchug (elsewhere); //just in case ... 
     619        if (*mountpoint != G_DIR_SEPARATOR) 
     620        { 
     621                g_free (elsewhere); 
     622                return; 
     623        } 
     624        if (e2_utils_pass_whitespace ((gchar *)(mountpoint + 1)) == NULL) 
     625        { 
     626                g_free (elsewhere); 
     627                return; //nothing to do 
     628        } 
     629        while ((s = strrchr (elsewhere, G_DIR_SEPARATOR)) != NULL) 
     630        { 
     631                if (s > elsewhere) //keep the root dir 
     632                        *s = '\0'; 
     633                if (!g_str_has_prefix (elsewhere, mountpoint)) 
     634                { 
     635                        e2_fs_get_valid_path (&elsewhere, TRUE E2_ERR_NONE()); 
     636                        e2_pane_change_dir (NULL, elsewhere); 
     637                        break; 
     638                } 
     639                else if (s == elsewhere) 
     640                        break; //nowhere to go 
     641        } 
     642        g_free (elsewhere); 
    735643} 
    736644 
     
    738646@brief auto-unmount a volume 
    739647This is called from within timer callback i.e. BGL is off 
    740 @param pool pointer to devkit data struct 
     648@param sessionptr pointer to devkit data struct 
    741649@param device pointer to data for the device 
    742650 
    743651@return TRUE if the unmount is performed successfully or is not needed 
    744652*/ 
    745 static gboolean _e2_devkit_unmount_volume (SessionDevices *pool, DeviceData *device) 
     653static gboolean _e2_devkit_unmount_volume (DevicesSession *sessionptr, DeviceData *device) 
    746654{ 
    747655        //CHECKME upstream check for still-need-unmount is too racy? 
     
    752660        } 
    753661 
    754         const gchar *mountpoint = device->props.device_mount_path; 
    755         if (mountpoint != NULL  //should never happen 
     662        gchar *mountpoint; 
     663#ifdef DEVKIT_IFACE 
     664        mountpoint = device->props.device_mount_path; 
     665        gboolean moved; 
     666        if (!sessionptr->udisks && mountpoint != NULL) //this is a devkit-disks session 
     667        { 
     668                mountpoint = F_FILENAME_FROM_LOCALE (mountpoint); 
     669# ifdef E2_VFSTMP 
     670                //FIXME dir when not mounted local 
     671# endif 
     672                if (g_str_has_prefix (curr_view->dir, mountpoint)) 
     673                { 
     674                        _e2_devkit_skipaway (mountpoint); 
     675                        moved = TRUE; 
     676                } 
     677                else 
     678                        moved = FALSE; 
     679                F_FREE (mountpoint, device->props.device_mount_path); 
     680        } 
     681        else 
     682                moved = FALSE; 
     683 
     684        if (sessionptr->udisks && !moved) 
     685        { 
     686#endif 
     687                gchar **allmounts; 
     688                for (allmounts = device->props.device_mount_paths; 
     689                        (mountpoint = *allmounts) != NULL; 
     690                        allmounts++) 
     691                { 
     692                        mountpoint = F_FILENAME_FROM_LOCALE (mountpoint); 
    756693#ifdef E2_VFSTMP 
    757         //FIXME dir when not mounted local 
    758 #else 
    759                 && g_str_has_prefix (curr_view->dir, mountpoint)) 
    760 #endif 
    761         {       //if possible, change CWD out of mountpoint so we don't ourself block the unmount 
    762                 gchar *elsewhere; 
    763                 const gchar *s = strrchr (mountpoint, G_DIR_SEPARATOR); //assumes no trailer on mountpoint string 
    764                 if (s > mountpoint + 1) //not doing root dir 
    765                         elsewhere = g_strndup (mountpoint, s - mountpoint); 
    766                 else //can't cd 
    767                         elsewhere = g_strdup (G_DIR_SEPARATOR_S); 
    768  
    769                 e2_fs_get_valid_path (&elsewhere, TRUE E2_ERR_NONE()); 
    770                 e2_pane_change_dir (NULL, elsewhere); 
    771                 g_free (elsewhere); 
    772         } 
    773  
     694                        //FIXME dir when not mounted local 
     695#endif 
     696                        if (g_str_has_prefix (curr_view->dir, mountpoint)) 
     697                        { 
     698                                _e2_devkit_skipaway (mountpoint); 
     699                                F_FREE (mountpoint, device->props.device_mount_path); 
     700                                break; 
     701                        } 
     702                        F_FREE (mountpoint, device->props.device_mount_path); 
     703                } 
     704#ifdef DEVKIT_IFACE 
     705        } 
     706#endif 
    774707        //do it 
    775 # if 0 //direct 
    776         gint res = run command 
     708#if 0 //direct 
     709        gint res = run unmount command 
    777710        retval = (res == 0); 
    778711        //do stuff if successful 
     
    780713                _e2_devkit_device_data_freshen (device); 
    781714        return retval; 
    782 # else //via devkit 
    783         gpointer cb_data = device; 
    784         gchar *options[2]; 
    785  
    786 #ifdef DEBUG_MESSAGES 
    787         gboolean CHECKME; 
    788 #endif 
    789         options[0] = NULL; 
    790  
     715#else //via the daemon 
     716//      gpointer cb_data = device; 
     717//      gchar *options[2]; 
     718//      options[0] = NULL; 
     719//# ifdef DEBUG_MESSAGES 
     720//      gboolean CHECKME; 
     721//# endif 
    791722        return 
    792723                (dbus_g_proxy_begin_call (device->devproxy, "FilesystemUnmount", 
    793                 _e2_devkit_unmount_async_cb, 
    794                 cb_data, (GDestroyNotify) NULL, 
    795                 G_TYPE_STRV, options, G_TYPE_INVALID) != NULL); 
    796 # endif 
     724                        _e2_devkit_unmount_async_cb, 
     725                        device, (GDestroyNotify) NULL, 
     726                        G_TYPE_STRV, /*options*/NULL, G_TYPE_INVALID) 
     727                != NULL); 
     728#endif 
    797729} 
    798730 
     
    854786                //do stuff ? 
    855787                DeviceData *device = (DeviceData *)user_data; 
    856                 printd (DEBUG, "Device %s unmounted", device->object_path); 
     788                printd (DEBUG, "Device %s unmounted", device->props.device_file); 
    857789                _e2_devkit_device_data_freshen (device); 
    858790        } 
     
    876808        device->timer_id = 0;   //ASAP indicate to any other process 
    877809                                                        //but we don't remove this source in case mount fails 
    878         printd (DEBUG, "Devkit: mount timer callback, device %s", device->props.device_file); 
     810        printd (DEBUG, "Device-mount timer callback, device %s", device->props.device_file); 
    879811 
    880812        if (!device->props.device_is_mounted 
     
    882814                ) 
    883815        { 
    884                 printd (DEBUG, "device needs to be mounted"); 
     816                printd (DEBUG, "device still not mounted"); 
    885817#ifdef DEBUG_MESSAGES 
    886                 gboolean retval = !_e2_devkit_mount_volume (&devicesdata, device); 
     818                gboolean retval = !_e2_devkit_mount_volume (&session, device); 
    887819                if (retval) 
    888820                        printd (DEBUG, "mount operation failed"); 
    889821                return retval;  //try again in case of failure 
    890822#else 
    891                 return (!_e2_devkit_mount_volume (&devicesdata, device)); 
     823                return (!_e2_devkit_mount_volume (&session, device)); 
    892824#endif 
    893825        } 
     
    898830@brief callback for a device-add event 
    899831@param proxy connection to devkit daemon 
    900 @param object_path DEVKIT_PATH_ROOT etc 
     832@param object_path PATH_ROOT... 
    901833@param user_data pointer to device monitor data struct specified when callback was connected 
    902834@return 
     
    905837        const gchar *object_path, gpointer user_data) 
    906838{ 
    907         SessionDevices *pool; 
     839        DevicesSession *sessionptr; 
    908840        DeviceData *device; 
    909841 
    910         pool = (SessionDevices *)user_data; 
    911         device = g_hash_table_lookup (pool->logged_devices, object_path); 
     842        sessionptr = (DevicesSession *)user_data; 
     843        device = g_hash_table_lookup (sessionptr->logged_devices, object_path); 
    912844 
    913845        if (G_LIKELY(device == NULL)) 
    914846        { 
    915                 device = _e2_devkit_device_get (pool, object_path); 
     847                device = _e2_devkit_device_get (sessionptr, object_path); 
    916848                if (device != NULL) 
    917849                { 
    918850                        //new device is one we want 
    919                         printd (DEBUG, "Devkit: Logging device %s @ %x", object_path, device); 
    920                         g_hash_table_insert (pool->logged_devices, 
     851                        printd (DEBUG, "Logging device %s @ %x", device->props.device_file, device); 
     852                        g_hash_table_insert (sessionptr->logged_devices, 
    921853                                (gpointer) device->object_path, //not another copy, not truncated 
    922854                                (gpointer) device); 
    923                         //CHECKME is 2-sec delay long enough ? 
     855                        //CHECKME is 5-sec delay long enough ? 
    924856                        device->timer_id = 
    925857#ifdef USE_GLIB2_14 
    926                                 g_timeout_add_seconds (2, 
     858                                g_timeout_add_seconds (5, 
    927859#else 
    928                                 g_timeout_add (2000, 
     860                                g_timeout_add (5000, 
    929861#endif 
    930862                                (GSourceFunc) _e2_devkit_check_mount, device); 
     
    941873                        device->timer_id = 0; 
    942874                } 
    943                 printd (WARN, "Devkit: add-event for previously added device %s, treat as change", 
     875                printd (WARN, "Devices daemon add-event for previously added device %s, treat as change", 
    944876                        object_path); 
    945877                _e2_devkit_device_changed_cb (proxy, object_path, user_data); 
     
    964896        } 
    965897 
    966         printd (DEBUG, "Devkit: unmount timer callback"); 
     898        printd (DEBUG, "Device unmount timer-callback"); 
    967899 
    968900        if (device->props.device_is_mounted) 
    969901        { 
    970                         printd (DEBUG, "device needs to be unmounted"); 
    971                         retval = !_e2_devkit_unmount_volume (&devicesdata, device); 
     902                printd (DEBUG, "device is still mounted"); 
     903                retval = !_e2_devkit_unmount_volume (&session, device); 
    972904#ifdef DEBUG_MESSAGES 
    973                         if (retval) 
    974                                 printd (DEBUG, "but unmount operation failed"); 
     905                if (retval) 
     906                        printd (DEBUG, "but unmount operation failed"); 
    975907#endif 
    976908        } 
     
    987919@brief callback for a device-remove event 
    988920@param proxy 
    989 @param object_path DEVKIT_PATH_ROOT etc 
     921@param object_path PATH_ROOT... 
    990922@param user_data pointer to device monitor data struct specified when callback was connected 
    991923@return 
     
    994926        const gchar *object_path, gpointer user_data) 
    995927{ 
    996         SessionDevices *pool; 
     928        DevicesSession *sessionptr; 
    997929        DeviceData *device; 
    998930 
    999         pool = (SessionDevices *)user_data; 
    1000         if (pool->logged_devices == NULL) 
     931        sessionptr = (DevicesSession *)user_data; 
     932        if (sessionptr->logged_devices == NULL) 
    1001933                return; 
    1002         device = g_hash_table_lookup (pool->logged_devices, object_path); 
     934        device = g_hash_table_lookup (sessionptr->logged_devices, object_path); 
    1003935 
    1004936        if (G_LIKELY(device != NULL)) 
     
    1024956This will be called twice when a device is added/removed. The 2nd call does nothing. 
    1025957@param proxy connection to devkit daemon 
    1026 @param object_path DEVKIT_PATH_ROOT/devicename (e.g. sr0, but with any '-' converted to '_') 
     958@param object_path PATH_ROOT/devicename (e.g. sr0, but with any '-' converted to '_') 
    1027959@param user_data pointer to session-devices data struct specified when callback was connected 
    1028960@return 
     
    1031963        const gchar *object_path, gpointer user_data) 
    1032964{ 
    1033         SessionDevices *pool; 
     965        DevicesSession *sessionptr; 
    1034966        DeviceData *device; 
    1035967 
    1036968        printd (DEBUG,"_e2_devkit_device_changed_cb: device %s", object_path); 
    1037         pool = (SessionDevices *)user_data; 
    1038         if (pool->logged_devices == NULL) 
     969        sessionptr = (DevicesSession *)user_data; 
     970        if (sessionptr->logged_devices == NULL) 
    1039971        { 
    1040972#ifdef DEBUG_MESSAGES 
     
    1044976                return; 
    1045977        } 
    1046         device = g_hash_table_lookup (pool->logged_devices, object_path); 
     978        device = g_hash_table_lookup (sessionptr->logged_devices, object_path); 
    1047979 
    1048980        if (G_LIKELY(device != NULL)) 
     
    1056988                } 
    1057989 
    1058                 if (_e2_devkit_device_properties_get (pool->bus, object_path, &new_properties)) 
     990                if (_e2_devkit_device_properties_get (sessionptr, object_path, &new_properties)) 
    1059991                { 
    1060992                        if (G_LIKELY(!new_properties.ignored)) 
     
    11121044This callback happens only at idle-time, and before any device-changed callback. 
    11131045There is no info on what properties have changed, so we must poll. 
    1114 @param object UNUSED DEVKIT_DISKS_DEVICE object 
     1046@param object UNUSED object 
    11151047@param user_data pointer to data struct for device that's changed 
    11161048@return 
     
    11551087gboolean e2_devkit_device_is_removable (const gchar *devpath) 
    11561088{ 
    1157         if (devicesdata.logged_devices != NULL) 
    1158         { 
    1159                 return (g_hash_table_find (devicesdata.logged_devices, 
     1089        if (session.logged_devices != NULL) 
     1090        { 
     1091                return (g_hash_table_find (session.logged_devices, 
    11601092                                (GHRFunc) _e2_devkit_check_device_path, 
    11611093                                (gpointer)devpath) != NULL); 
     
    11701102gboolean e2_devkit_device_is_ejectable (const gchar *devpath) 
    11711103{ 
    1172         if (devicesdata.logged_devices != NULL) 
     1104        if (session.logged_devices != NULL) 
    11731105        { 
    11741106                DeviceData *dev; 
    1175                 dev = (DeviceData *)g_hash_table_find (devicesdata.logged_devices, 
     1107                dev = (DeviceData *)g_hash_table_find (session.logged_devices, 
    11761108                                (GHRFunc) _e2_devkit_check_device_path, 
    11771109                                (gpointer)devpath); 
     
    11891121void e2_devkit_init (void) 
    11901122{ 
    1191         SessionDevices *pool; 
     1123        DevicesSession *sessionptr; 
    11921124        GError *error; 
    1193  
    1194         pool = &devicesdata; 
     1125        const gchar *iface_name, *object_path; 
     1126        gchar *version; 
     1127 
    11951128        error = NULL; 
    1196  
    1197         pool->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); 
    1198         if (pool->bus == NULL) 
    1199         { 
    1200 //              _e2_devkit_advise (_("message"), NULL); 
     1129        object_path = NULL; //warning prevention 
     1130 
     1131        session.bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); 
     1132        if (session.bus == NULL) 
     1133        { 
     1134//              _e2_devkit_advise (_("some warning ..."), NULL); 
    12011135                printd (WARN, "Unable to connect to system bus: %s", error->message); 
    12021136                g_error_free (error); 
    12031137                return; 
    12041138        } 
    1205         pool->proxy = dbus_g_proxy_new_for_name (pool->bus, 
    1206                                                                                         DEVKIT_IFACE_NAME, 
    1207                                                                                         "/org/freedesktop/DeviceKit/Disks", 
    1208                                                                                         DEVKIT_IFACE_NAME); 
    1209         //CHECKME specifically confirm daemon presence ? 
    1210         if (pool->proxy == NULL) 
    1211         { 
    1212 //              _e2_devkit_advise (_("message"), NULL); 
    1213                 printd (WARN, "Unable to connect to devicekit daemon"); 
    1214                 dbus_g_connection_unref (pool->bus); 
     1139 
     1140        //check for daemon presence 
     1141        iface_name = UDISK_IFACE_NAME; 
     1142        version = _e2_devkit_get_version (session.bus, iface_name, UDISK_BUS_PATH); 
     1143        if (version != NULL) 
     1144        { 
     1145#ifdef DEVKIT_IFACE 
     1146                session.udisks = TRUE; 
     1147#endif 
     1148                session.daemon_version = version; 
     1149                session.iface_name = iface_name; 
     1150                object_path = UDISK_BUS_PATH; 
     1151        } 
     1152        else 
     1153        { 
     1154#ifdef DEVKIT_IFACE 
     1155                iface_name = DEVKIT_IFACE_NAME; 
     1156                version = _e2_devkit_get_version (session.bus, iface_name, DEVKIT_BUS_PATH); 
     1157                if (version != NULL) 
     1158                { 
     1159                        session.daemon_version = version; 
     1160                        session.iface_name = iface_name; 
     1161                        object_path = DEVKIT_BUS_PATH; 
     1162                } 
     1163                else 
     1164                { 
     1165//                      _e2_devkit_advise (_("some warning ..."), NULL); 
     1166                        printd (WARN, "Unable to connect to any devices daemon"); 
     1167                        dbus_g_connection_unref (session.bus); 
     1168                        session.bus = NULL; 
     1169                        return; 
     1170                } 
     1171#else 
     1172//              _e2_devkit_advise (_("some warning ..."), NULL); 
     1173                printd (WARN, "Unable to connect to a udisks daemon"); 
     1174                dbus_g_connection_unref (session.bus); 
     1175                session.bus = NULL; 
    12151176                return; 
    1216         } 
    1217  
    1218         //table with key = D-Bus object path, value = the corresponding device data struct 
    1219         pool->logged_devices = g_hash_table_new_full ( 
    1220                 g_str_hash, g_str_equal, NULL, 
    1221                 (GDestroyNotify)_e2_devkit_device_data_clear); 
    1222  
    1223         if (_e2_devkit_detect_current_removables (pool)) 
     1177#endif 
     1178        } 
     1179 
     1180        session.proxy = dbus_g_proxy_new_for_name (session.bus, 
     1181                iface_name, 
     1182                object_path, 
     1183                iface_name); 
     1184        if (session.proxy == NULL) 
     1185        { 
     1186//              _e2_devkit_advise (_("some warning ..."), NULL); 
     1187                printd (WARN, "Unable to create proxy for dbus connection"); 
     1188                dbus_g_connection_unref (session.bus); 
     1189                session.bus = NULL; 
     1190                return; 
     1191        } 
     1192 
     1193        //table with: key = D-Bus object path, value = the corresponding device data struct 
     1194        session.logged_devices = g_hash_table_new_full ( 
     1195                g_str_hash, g_str_equal, 
     1196                NULL, (GDestroyNotify)_e2_devkit_device_data_clear); 
     1197 
     1198        sessionptr = &session; 
     1199        if (_e2_devkit_detect_current_removables (sessionptr)) 
    12241200        { 
    12251201                const gchar *signame; 
    12261202 
    12271203                signame = "DeviceAdded"; 
    1228                 dbus_g_proxy_add_signal (pool->proxy, signame, DBUS_TYPE_G_OBJECT_PATH, 
    1229                         G_TYPE_INVALID); 
    1230                 dbus_g_proxy_connect_signal (pool->proxy, signame, 
    1231                          G_CALLBACK (_e2_devkit_device_added_cb), pool, NULL); 
     1204                dbus_g_proxy_add_signal (session.proxy, signame, 
     1205                        DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); 
     1206                dbus_g_proxy_connect_signal (session.proxy, signame, 
     1207                         G_CALLBACK (_e2_devkit_device_added_cb), sessionptr, NULL); 
    12321208                signame = "DeviceRemoved"; 
    1233                 dbus_g_proxy_add_signal (pool->proxy, signame, DBUS_TYPE_G_OBJECT_PATH, 
    1234                         G_TYPE_INVALID); 
    1235                 dbus_g_proxy_connect_signal (pool->proxy, signame, 
    1236                          G_CALLBACK (_e2_devkit_device_removed_cb), pool, NULL); 
     1209                dbus_g_proxy_add_signal (session.proxy, signame, 
     1210                        DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); 
     1211                dbus_g_proxy_connect_signal (session.proxy, signame, 
     1212                         G_CALLBACK (_e2_devkit_device_removed_cb), sessionptr, NULL); 
    12371213                signame = "DeviceChanged"; 
    1238                 dbus_g_proxy_add_signal (pool->proxy, signame, DBUS_TYPE_G_OBJECT_PATH, 
    1239                         G_TYPE_INVALID); 
    1240                 dbus_g_proxy_connect_signal (pool->proxy, signame, 
    1241                          G_CALLBACK (_e2_devkit_device_changed_cb), pool, NULL); 
    1242         } 
    1243         else 
    1244         { 
    1245 //              _e2_devkit_advise (_("message"), NULL); 
    1246                 dbus_g_connection_unref (pool->bus); 
    1247                 g_object_unref (G_OBJECT(pool->proxy)); 
    1248                 g_hash_table_destroy (pool->logged_devices); 
    1249                 memset (pool, 0, sizeof (SessionDevices)); 
     1214                dbus_g_proxy_add_signal (session.proxy, signame, 
     1215                        DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); 
     1216                dbus_g_proxy_connect_signal (session.proxy, signame, 
     1217                         G_CALLBACK (_e2_devkit_device_changed_cb), sessionptr, NULL); 
     1218        } 
     1219        else 
     1220        { 
     1221//              _e2_devkit_advise (_("some warning ..."), NULL); 
     1222                dbus_g_connection_unref (session.bus); 
     1223                g_object_unref (G_OBJECT(session.proxy)); 
     1224                g_hash_table_destroy (session.logged_devices); 
     1225                memset (sessionptr, 0, sizeof (DevicesSession)); 
    12501226        } 
    12511227} 
     
    12561232void e2_devkit_disconnect (void) 
    12571233{ 
    1258         SessionDevices *pool; 
    1259  
    1260         pool = &devicesdata; 
    1261         if (pool->bus != NULL) 
    1262                 dbus_g_connection_unref (pool->bus); 
    1263         if (pool->proxy != NULL) 
    1264                 g_object_unref (G_OBJECT(pool->proxy)); 
    1265         if (pool->logged_devices != NULL) 
    1266                 g_hash_table_destroy (pool->logged_devices); 
     1234        if (session.daemon_version != NULL) 
     1235                g_free (session.daemon_version); 
     1236        if (session.bus != NULL) 
     1237                dbus_g_connection_unref (session.bus); 
     1238        if (session.proxy != NULL) 
     1239                g_object_unref (G_OBJECT(session.proxy)); 
     1240        if (session.logged_devices != NULL) 
     1241                g_hash_table_destroy (session.logged_devices); 
    12671242} 
    12681243#endif //def E2_DEVKIT