[gnome-disk-utility/udisks2-port] Use Drive.Removable and default to FAT for flash and small removable drives



commit 9a6de5ba547382b69e1f737afa28e8313add4a93
Author: David Zeuthen <davidz redhat com>
Date:   Thu Nov 3 08:45:33 2011 -0400

    Use Drive.Removable and default to FAT for flash and small removable drives
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/format-volume-dialog.ui        |    6 ++--
 src/palimpsest/gducrypttabdialog.c     |    2 +-
 src/palimpsest/gduformatvolumedialog.c |   38 +++++++++++++++++++++++++++----
 src/palimpsest/gdufstabdialog.c        |    4 +-
 src/palimpsest/gduutils.c              |   27 ----------------------
 src/palimpsest/gduutils.h              |    3 --
 6 files changed, 39 insertions(+), 41 deletions(-)
---
diff --git a/data/ui/format-volume-dialog.ui b/data/ui/format-volume-dialog.ui
index fc6adce..d150705 100644
--- a/data/ui/format-volume-dialog.ui
+++ b/data/ui/format-volume-dialog.ui
@@ -105,10 +105,10 @@
                     <property name="has_tooltip">True</property>
                     <property name="tooltip_markup" translatable="yes">The kind of filesystem to create. Choose &lt;b&gt;Custom&lt;/b&gt; to specify a custom filesystem type such as &lt;i&gt;btrfs&lt;/i&gt;, &lt;i&gt;xfs&lt;/i&gt; or &lt;i&gt;swap&lt;/i&gt;</property>
                     <items>
-                      <item translatable="yes">Compatible with all systems (FAT)</item>
+                      <item translatable="yes">Compatible with all systems and devices (FAT)</item>
                       <item translatable="yes">Compatible with most systems (NTFS)</item>
-                      <item translatable="yes">Compatible with Linux only (ext4)</item>
-                      <item translatable="yes">Encrypted, compatible with Linux (LUKS, ext4)</item>
+                      <item translatable="yes">Compatible with Linux systems (ext4)</item>
+                      <item translatable="yes">Encrypted, compatible with Linux systems (LUKS, ext4)</item>
                       <item translatable="yes">Custom</item>
                     </items>
                   </object>
diff --git a/src/palimpsest/gducrypttabdialog.c b/src/palimpsest/gducrypttabdialog.c
index f06a192..56c0a71 100644
--- a/src/palimpsest/gducrypttabdialog.c
+++ b/src/palimpsest/gducrypttabdialog.c
@@ -200,7 +200,7 @@ crypttab_dialog_present (CrypttabDialogData *data)
       name = g_strdup_printf ("luks-%s", udisks_block_get_id_uuid (data->block));
       options = "";
       /* propose noauto if the media is removable - otherwise e.g. systemd will time out at boot */
-      if (data->drive != NULL && gdu_utils_drive_treat_as_removable (data->drive, data->block))
+      if (data->drive != NULL && udisks_drive_get_removable (data->drive))
         options = "noauto";
       passphrase_contents = "";
     }
diff --git a/src/palimpsest/gduformatvolumedialog.c b/src/palimpsest/gduformatvolumedialog.c
index 46433a9..a86a74c 100644
--- a/src/palimpsest/gduformatvolumedialog.c
+++ b/src/palimpsest/gduformatvolumedialog.c
@@ -151,19 +151,47 @@ format_volume_property_changed (GObject     *object,
   format_volume_update (data);
 }
 
+static gboolean
+is_flash (UDisksDrive *drive)
+{
+  gboolean ret = FALSE;
+  guint n;
+  const gchar *const *media_compat;
+
+  media_compat = udisks_drive_get_media_compatibility (drive);
+  for (n = 0; media_compat != NULL && media_compat[n] != NULL; n++)
+    {
+      if (g_str_has_prefix (media_compat[n], "flash"))
+        {
+          ret = TRUE;
+          goto out;
+        }
+    }
+
+ out:
+  return ret;
+}
+
 static void
 format_volume_populate (FormatVolumeData *data)
 {
 
-  /* Default to NTFS for removable media... Ext4 otherwise */
-  if (data->drive != NULL && udisks_drive_get_media_removable (data->drive))
+  /* Default to FAT or NTFS for removable drives... Ext4 otherwise */
+  if (data->drive != NULL && udisks_drive_get_removable (data->drive))
     {
-      /* TODO: Default to FAT for memory cards or if the media is smaller than, say, 100GB */
-      gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 1);
+      /* default FAT for flash and disks/media smaller than 20G (assumed to be flash cards) */
+      if (is_flash (data->drive) || udisks_drive_get_size (data->drive) < 20L * 1000L*1000L*1000L)
+        {
+          gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 0); /* FAT */
+        }
+      else
+        {
+          gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 1); /* NTFS */
+        }
     }
   else
     {
-      gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 2);
+      gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 2); /* Ext4 */
     }
 
   /* Translators: this is the default name for the filesystem */
diff --git a/src/palimpsest/gdufstabdialog.c b/src/palimpsest/gdufstabdialog.c
index a3e9683..4ccf59e 100644
--- a/src/palimpsest/gdufstabdialog.c
+++ b/src/palimpsest/gdufstabdialog.c
@@ -289,7 +289,7 @@ fstab_populate_device_combo_box (GtkWidget         *device_combobox,
       /* if the device is using removable media, prefer
        * by-id / by-path to by-uuid / by-label
        */
-      if (drive != NULL && gdu_utils_drive_treat_as_removable (drive, block))
+      if (drive != NULL && udisks_drive_get_removable (drive))
         {
           if (by_id != -1)
             selected = by_id;
@@ -435,7 +435,7 @@ gdu_fstab_dialog_show (GduWindow    *window,
       type = "auto";
       opts = "defaults";
       /* propose noauto if the media is removable - otherwise e.g. systemd will time out at boot */
-      if (drive != NULL && gdu_utils_drive_treat_as_removable (drive, block))
+      if (drive != NULL && udisks_drive_get_removable (drive))
         opts = "defaults,noauto";
       freq = 0;
       passno = 0;
diff --git a/src/palimpsest/gduutils.c b/src/palimpsest/gduutils.c
index a484c4c..622371e 100644
--- a/src/palimpsest/gduutils.c
+++ b/src/palimpsest/gduutils.c
@@ -26,33 +26,6 @@
 #include "gduutils.h"
 
 gboolean
-gdu_utils_drive_treat_as_removable (UDisksDrive  *drive,
-                                    UDisksBlock  *block)
-{
-  gboolean ret = FALSE;
-  const gchar *device_file;
-
-  g_return_val_if_fail (UDISKS_IS_DRIVE (drive), FALSE);
-  g_return_val_if_fail (UDISKS_IS_BLOCK (block), FALSE);
-
-  if (udisks_drive_get_media_removable (drive))
-    {
-      ret = TRUE;
-      goto out;
-    }
-
-  device_file = udisks_block_get_device (block);
-  if (g_str_has_prefix (device_file, "/dev/mmcblk"))
-    {
-      ret = TRUE;
-      goto out;
-    }
-
- out:
-  return ret;
-}
-
-gboolean
 gdu_utils_has_configuration (UDisksBlock  *block,
                              const gchar  *type,
                              gboolean     *out_has_passphrase)
diff --git a/src/palimpsest/gduutils.h b/src/palimpsest/gduutils.h
index a61582d..f44435e 100644
--- a/src/palimpsest/gduutils.h
+++ b/src/palimpsest/gduutils.h
@@ -28,9 +28,6 @@
 
 G_BEGIN_DECLS
 
-gboolean gdu_utils_drive_treat_as_removable (UDisksDrive  *drive,
-                                             UDisksBlock  *block);
-
 gboolean gdu_utils_has_configuration (UDisksBlock  *block,
                                       const gchar  *type,
                                       gboolean     *out_has_passphrase);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]