Re: [PATCH] add -l option to gvfs-mount + crash report

nf2 <[email protected]>
Newsgroups gmane.comp.gnome.vfs.general
Message-ID <[email protected]>
David Zeuthen wrote:
> Hi,
>
> Using CamelCase names such as gFileRoot, mountName and so on is probably
> not the best idea. Suggest to follow the coding standards.
>
> It would also be useful to display the drives and volumes much like the
> side bar in Nautilus current does (see the Nautilus source code for
> details), e.g. sorta like this
>
>  Drive0
>   Volume0
>    Mount0
>   Volume1
>    Mount1
>   Volume2
>  Drive1
>
>  Volume_without_drive10
>  Volume_without_drive11
>   Mount11
>
>  Mount_without_volume20
>  Mount_without_volume21
>   
Here is a patch which also lists drives and volumes. Additionally it 
tries to fix the crash in gmounttracker.c, caused by an empty DBus reply 
when gvfsd is not running.

Cheers,
Norbert

_______________________________________________
gnome-vfs-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list
gvfs-mount-l-2.patch (text/x-patch, 5.4 KB)
Index: common/gmounttracker.c
===================================================================
--- common/gmounttracker.c	(revision 1085)
+++ common/gmounttracker.c	(working copy)
@@ -386,18 +386,25 @@
   dbus_pending_call_unref (pending);
 
   b = dbus_message_iter_init (reply, &iter);
-  dbus_message_iter_recurse (&iter, &array_iter);
-
-  do
+  if (b && dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY)
     {
-      info = g_mount_info_from_dbus (&array_iter);
-      if (info)
-	{
-	  g_mount_tracker_add_mount (tracker, info);
-	  g_mount_info_unref (info);
-	}
+      dbus_message_iter_recurse (&iter, &array_iter);
+    
+      do
+        {
+          info = g_mount_info_from_dbus (&array_iter);
+          if (info)
+    	{
+    	  g_mount_tracker_add_mount (tracker, info);
+    	  g_mount_info_unref (info);
+    	}
+        }
+      while (dbus_message_iter_next (&array_iter));
     }
-  while (dbus_message_iter_next (&array_iter));
+  else
+    {
+      /* list_mounts_reply problem - gvfsd not running? */
+    }
   
   dbus_message_unref (reply);
 }
Index: programs/gvfs-mount.c
===================================================================
--- programs/gvfs-mount.c	(revision 1085)
+++ programs/gvfs-mount.c	(working copy)
@@ -35,11 +35,13 @@
 
 static gboolean mount_mountable = FALSE;
 static gboolean mount_unmount = FALSE;
+static gboolean mount_list = FALSE;
 
 static GOptionEntry entries[] = 
 {
 	{ "mountable", 'm', 0, G_OPTION_ARG_NONE, &mount_mountable, "Mount as mountable", NULL },
-        { "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, "Unmount", NULL},
+  { "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, "Unmount", NULL},
+  { "list", 'l', 0, G_OPTION_ARG_NONE, &mount_list, "List", NULL},
 	{ NULL }
 };
 
@@ -212,6 +214,129 @@
   outstanding_mounts++;
 }
 
+// =============== list mounts ==================
+
+static GMainLoop *main_loop;
+
+const char indentstr[] = "                               ";
+
+#define get_indent_str(x) indentstr + (sizeof(indentstr)-x-1)
+
+static gboolean iterate_gmain_timeout_function(gpointer data)
+{
+  g_main_loop_quit (main_loop);
+  return FALSE;
+}
+
+static void iterate_gmain()
+{
+  g_timeout_add(500, iterate_gmain_timeout_function, NULL);  
+  
+  main_loop = g_main_loop_new (NULL, FALSE);
+  g_main_loop_run (main_loop);
+  g_main_loop_unref(main_loop);
+}
+
+static void list_mounts(GVolumeMonitor* volume_monitor, int indent, GDrive * forDrive, GVolume * forVolume)
+{
+  GList* mount_list = g_volume_monitor_get_mounts(volume_monitor);
+  
+  GList* mount_list_el = mount_list;
+  int c=0;
+  for(;mount_list_el != NULL; mount_list_el = g_list_next(mount_list_el), c++)
+    {
+      GMount * mount = (GMount *) mount_list_el->data;
+
+      if (forDrive && g_mount_get_drive(mount)!=forDrive)
+          continue;
+      if (forVolume && g_mount_get_volume(mount)!=forVolume)
+          continue;
+      if (!forDrive && !forVolume && (g_mount_get_volume(mount) || g_mount_get_drive(mount)))
+          continue;
+      
+      char * mount_uuid = g_mount_get_uuid(mount);
+      char * mount_name = g_mount_get_name(mount);
+      GFile * file_root = g_mount_get_root(mount);
+      
+      char * points_to_uri = g_file_get_uri(file_root);
+      
+      printf("%sMount(%d) : %s -> %s\n", get_indent_str(indent), c, mount_name, points_to_uri);
+      
+      g_object_unref(file_root);
+      g_free(mount_uuid);
+      g_free(mount_name);
+      g_free(points_to_uri);
+    }
+}
+
+
+static void list_volumes(GVolumeMonitor* volume_monitor, int indent, GDrive * forDrive)
+{
+  
+  GList* volume_list = g_volume_monitor_get_volumes(volume_monitor);
+  GList* volume_list_el = volume_list;
+  
+  int c=0;
+  for(;volume_list_el!=NULL;volume_list_el = g_list_next(volume_list_el), c++)
+    {
+      GVolume * volume = (GVolume *) volume_list_el->data;
+
+      if (forDrive && g_volume_get_drive(volume)!=forDrive)
+          continue;
+      if (!forDrive && g_volume_get_drive(volume))
+          continue;
+      
+      char * volume_name = g_volume_get_name(volume);
+      
+      printf("%sVolume(%d) : %s\n", get_indent_str(indent), c, volume_name);
+      g_free(volume_name);
+      
+      list_mounts(volume_monitor, indent+2, NULL, volume);      
+      
+    }  
+}
+
+
+static void list_drives(GVolumeMonitor* volume_monitor, int indent)
+{
+  GList* drive_list = g_volume_monitor_get_connected_drives(volume_monitor);
+  
+  GList* drive_list_el = drive_list;
+  
+  int c=0;
+  while(drive_list_el)
+    {
+      GDrive * drive = (GDrive *) drive_list_el->data;
+
+      char * drive_name = g_drive_get_name(drive);
+      
+      printf("%sDrive(%d) : %s\n", get_indent_str(indent), c, drive_name);
+      g_free(drive_name);
+
+      list_mounts(volume_monitor, indent+2, drive, NULL);
+      list_volumes(volume_monitor, indent+2, drive);
+      
+      drive_list_el = g_list_next(drive_list_el);
+      c++;
+    }
+}
+
+
+
+static void list_monitor_items()
+{
+  GVolumeMonitor* volume_monitor = g_volume_monitor_get();
+  
+  // populate gvfs network mounts
+  iterate_gmain();
+
+  list_drives(volume_monitor, 0);
+  list_volumes(volume_monitor, 0, NULL);
+  list_mounts(volume_monitor, 0, NULL, NULL);
+  
+}
+
+
 int
 main (int argc, char *argv[])
 {
@@ -229,6 +354,9 @@
   g_option_context_parse (context, &argc, &argv, &error);
   g_option_context_free (context);
   
+  if (mount_list)
+    list_monitor_items();
+  else
   if (argc > 1)
     {
       int i;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.