Ticket #2952: exo-0.3.101-hal_fixes-1.patch
File exo-0.3.101-hal_fixes-1.patch, 17.4 KB (added by , 15 years ago) |
---|
-
exo-mount/exo-mount-hal.c
Submitted By: William Immendorf (will.immendorf@gmail.com) Date: 2009-09-19 Initial Package Version: 0.3.101 Upstream Status: unknown Origin: Both http://bugzilla.xfce.org/show_bug.cgi?id=2891 (first bug) and http://bugzilla.xfce.org/show_bug.cgi?id=2968. (second bug) Descirption: This kills the two HAL birds (or bugs) with one stone (or patch). This fixes two issues: 1. You can't speficy the mount options for hal, as they are hardcoded in exo-mount. This is troubling, espicaly if you live in a non-English speaking contry (in which you had to spefiy the iocharset option to hal), or if you are STILL using LFS 6.3 (which uses Linux 2.6.22.*), and have that slow-vfat issue that can be solved (other than GETTING A NEW VERSION!) by adding the usefree option. 2. HAL bombards you with cryptic messages every time you press the eject button on a CD/DVD drive. My patch fixes both, and it helps kill all the HAL releated bugs on the mouse. (my term for XFCE, who's mascot is a mouse.) diff -Naur exo-0.3.101-old/exo-mount/exo-mount-hal.c exo-0.3.101/exo-mount/exo-mount-hal.c
old new 40 40 41 41 #include <exo-mount/exo-mount-hal.h> 42 42 43 43 #define CONFIG_FILE_GLOBAL DATADIR "/xfce4/mount.rules" 44 44 45 45 static gboolean exo_mount_hal_init (GError **error); 46 46 static void exo_mount_hal_propagate_error (GError **error, … … 64 64 LibHalVolumeUsage fsusage; 65 65 }; 66 66 67 typedef struct _ExoVolumeOptions 68 { 69 char** mount_options; 70 char* fstype_override; 71 } ExoVolumeOptions; 67 72 68 73 69 74 static LibHalContext *hal_context = NULL; 70 75 static DBusConnection *dbus_connection = NULL; 71 76 72 77 static gboolean exo_volume_hal_get_options( const char* fs, ExoVolumeOptions* ret ); 73 78 74 79 static gboolean 75 80 exo_mount_hal_init (GError **error) … … 145 150 } 146 151 147 152 153 static gboolean 154 string_in_list(gchar * const *haystack, const gchar *needle) 155 { 156 gint n; 157 158 if (!haystack) 159 return FALSE; 160 161 for (n=0; haystack[n]; ++n) { 162 if (!strcmp (haystack[n], needle)) 163 return TRUE; 164 } 165 return FALSE; 166 } 167 168 169 static gboolean 170 device_has_interface(const gchar *udi, const gchar *iface, 171 DBusError *derror) 172 { 173 gboolean result; 174 gchar **interfaces; 175 176 /* determine the info.interfaces property of the device */ 177 interfaces = libhal_device_get_property_strlist (hal_context, udi, 178 "info.interfaces", derror); 179 180 /* check for the interface we need */ 181 result = string_in_list(interfaces, iface); 182 libhal_free_string_array(interfaces); 183 184 return result; 185 } 186 187 188 148 189 149 190 /** 150 191 * exo_mount_hal_device_from_udi: … … 158 199 * or %NULL in case of an error. 159 200 **/ 160 201 ExoMountHalDevice* 161 exo_mount_hal_device_from_udi (const gchar * udi,202 exo_mount_hal_device_from_udi (const gchar *in_udi, 162 203 GError **error) 163 204 { 164 205 ExoMountHalDevice *device = NULL; 165 206 DBusError derror; 166 gchar **interfaces;167 gchar **volume_udis;168 gchar *volume_udi = NULL;169 207 gint n_volume_udis; 170 g int n;208 gchar *udi; 171 209 172 g_return_val_if_fail ( udi != NULL, NULL);210 g_return_val_if_fail (in_udi != NULL, NULL); 173 211 g_return_val_if_fail (error == NULL || *error == NULL, NULL); 174 212 175 213 /* make sure the HAL support is initialized */ … … 179 217 /* initialize D-Bus error */ 180 218 dbus_error_init (&derror); 181 219 182 again: 183 /* determine the info.interfaces property of the device */ 184 interfaces = libhal_device_get_property_strlist (hal_context, udi, "info.interfaces", &derror); 185 if (G_UNLIKELY (interfaces == NULL)) 220 udi = g_strdup (in_udi); 221 /* at this point, we own udi */ 222 223 /* maybe we have a mountable device here */ 224 while(G_UNLIKELY (!device_has_interface (udi, 225 "org.freedesktop.Hal.Device.Volume", &derror))) 186 226 { 187 /* reset D-Bus error */ 188 dbus_error_free (&derror); 227 gchar **volume_udis; 189 228 190 /* release any previous volume UDI */ 191 g_free (volume_udi); 192 volume_udi = NULL; 229 /* maybe there was a D-Bus error? gotta check */ 230 if (G_UNLIKELY (dbus_error_is_set (&derror))) 231 { 232 exo_mount_hal_propagate_error (error, &derror); 233 g_free (udi); 234 return NULL; 235 } 236 237 /* maybe we have a volume whose parent is identified by the udi */ 238 volume_udis = libhal_manager_find_device_string_match (hal_context, 239 "info.parent", udi, &n_volume_udis, &derror); 193 240 194 /* ok, but maybe we have a volume whose parent is identified by the udi */195 volume_udis = libhal_manager_find_device_string_match (hal_context, "info.parent", udi, &n_volume_udis, &derror);196 241 if (G_UNLIKELY (volume_udis == NULL)) 197 242 { 198 err0: exo_mount_hal_propagate_error (error, &derror); 199 goto out; 243 exo_mount_hal_propagate_error (error, &derror); 244 g_free (udi); 245 return NULL; 200 246 } 201 247 else if (G_UNLIKELY (n_volume_udis < 1)) 202 248 { 203 /* no match, we cannot handle that device */204 249 libhal_free_string_array (volume_udis); 205 goto err1; 250 dbus_error_free (&derror); 251 /* definitely not a device that we're able to 252 * mount, eject or unmount */ 253 g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, 254 _("Given device \"%s\" is not a volume or drive"), udi); 255 g_free (udi); 256 return NULL; 206 257 } 207 258 259 g_free (udi); 260 208 261 /* use the first volume UDI... */ 209 volume_udi = g_strdup (volume_udis[0]);262 udi = g_strdup (volume_udis[0]); 210 263 libhal_free_string_array (volume_udis); 211 212 264 /* ..and try again using that UDI */ 213 udi = (const gchar *) volume_udi;214 goto again;215 265 } 216 266 217 /* verify that we have a mountable device here */ 218 for (n = 0; interfaces[n] != NULL; ++n) 219 if (strcmp (interfaces[n], "org.freedesktop.Hal.Device.Volume") == 0) 220 break; 221 if (G_UNLIKELY (interfaces[n] == NULL)) 222 { 223 /* definitely not a device that we're able to mount, eject or unmount */ 224 err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%s\" is not a volume or drive"), udi); 225 goto out; 226 } 267 /* at this point, udi contains the UDI of something 268 * that implements Hal.Device.Volume. 269 * udi is the only resource that we hold here. */ 227 270 228 271 /* setup the device struct */ 229 272 device = g_new0 (ExoMountHalDevice, 1); 230 device->udi = g_strdup (udi);273 device->udi = udi; 231 274 232 275 /* check if we have a volume here */ 233 276 device->volume = libhal_volume_from_udi (hal_context, udi); … … 269 312 if (G_UNLIKELY (device->file == NULL || device->name == NULL)) 270 313 { 271 314 exo_mount_hal_device_free (device); 272 device = NULL;273 goto err0;315 exo_mount_hal_propagate_error(error, &derror); 316 return NULL; 274 317 } 275 318 276 319 /* check if we failed */ … … 282 325 device = NULL; 283 326 } 284 327 285 out: 286 /* cleanup */ 287 libhal_free_string_array (interfaces); 288 g_free (volume_udi); 289 328 dbus_error_free (&derror); 290 329 return device; 291 330 } 292 331 … … 313 352 gchar **interfaces; 314 353 gchar **udis; 315 354 gint n_udis; 316 gint n , m;355 gint n; 317 356 318 357 g_return_val_if_fail (g_path_is_absolute (file), NULL); 319 358 g_return_val_if_fail (error == NULL || *error == NULL, NULL); … … 347 386 continue; 348 387 349 388 /* check if we have a mountable device here */ 350 for (m = 0; interfaces[m] != NULL; ++m) 351 if (strcmp (interfaces[m], "org.freedesktop.Hal.Device.Volume") == 0) 352 break; 353 354 /* check if it's a usable device */ 355 if (interfaces[m] != NULL) 389 if (string_in_list (interfaces, "org.freedesktop.Hal.Device.Volume")) 356 390 { 357 391 libhal_free_string_array (interfaces); 358 392 break; … … 647 681 gchar *fstype; 648 682 gchar *s; 649 683 gint m, n = 0; 684 ExoVolumeOptions opts; 650 685 651 686 g_return_val_if_fail (device != NULL, FALSE); 652 687 g_return_val_if_fail (error == NULL || *error == NULL, FALSE); 653 688 654 /* determine the required mount options */ 655 options = g_new0 (gchar *, 20); 656 657 /* check if we know any valid mount options */ 658 if (G_LIKELY (device->fsoptions != NULL)) 689 /* get mount options set by pcmanfm first */ 690 if( exo_volume_hal_get_options( device->fstype, &opts ) ) 659 691 { 660 /* process all valid mount options */ 661 for (m = 0; device->fsoptions[m] != NULL; ++m) 662 { 663 /* this is currently mostly Linux specific noise */ 664 if (strcmp (device->fsoptions[m], "uid=") == 0 665 && (strcmp (device->fstype, "vfat") == 0 666 || strcmp (device->fstype, "iso9660") == 0 667 || strcmp (device->fstype, "udf") == 0 668 || device->volume == NULL)) 669 { 670 options[n++] = g_strdup_printf ("uid=%u", (guint) getuid ()); 671 } 672 else if (strcmp (device->fsoptions[m], "shortname=") == 0 673 && strcmp (device->fstype, "vfat") == 0) 692 char** popts = opts.mount_options; 693 n = g_strv_length( popts ); 694 if( n > 0) 695 { 696 int i; 697 /* We have to allocate a new larger array bacause we might need to 698 * append new options to the array later */ 699 options = g_new0 (gchar *, n + 4); 700 for( i = 0; i < n; ++i ) 674 701 { 675 options[n++] = g_strdup_printf ("shortname=winnt"); 702 options[i] = popts[i]; 703 popts[i] = NULL; 704 /* steal the string */ 676 705 } 677 else if (strcmp (device->fsoptions[m], "sync") == 0 678 && device->volume == NULL) 679 { 680 /* non-pollable drive... */ 681 options[n++] = g_strdup ("sync"); 682 } 683 else if (strcmp (device->fsoptions[m], "longnames") == 0 684 && strcmp (device->fstype, "vfat") == 0) 706 /* the strings in the array are already stolen, so strfreev is not needed. */ 707 } 708 g_free( opts.mount_options ); 709 710 fstype = opts.fstype_override; 711 } 712 713 if( G_UNLIKELY( ! options ) ) 714 { 715 /* determine the required mount options */ 716 options = g_new0 (gchar *, 20); 717 718 /* check if we know any valid mount options */ 719 if (G_LIKELY (device->fsoptions != NULL)) 720 { 721 /* process all valid mount options */ 722 for (m = 0; device->fsoptions[m] != NULL; ++m) 685 723 { 686 /* however this one is FreeBSD specific */ 687 options[n++] = g_strdup ("longnames"); 724 /* this is currently mostly Linux specific noise */ 725 if (strcmp (device->fsoptions[m], "uid=") == 0 726 && (strcmp (device->fstype, "vfat") == 0 727 || strcmp (device->fstype, "iso9660") == 0 728 || strcmp (device->fstype, "udf") == 0 729 || device->volume == NULL)) 730 { 731 options[n++] = g_strdup_printf ("uid=%u", (guint) getuid ()); 732 } 733 else if (strcmp (device->fsoptions[m], "shortname=") == 0 734 && strcmp (device->fstype, "vfat") == 0) 735 { 736 options[n++] = g_strdup_printf ("shortname=winnt"); 737 } 738 else if (strcmp (device->fsoptions[m], "sync") == 0 739 && device->volume == NULL) 740 { 741 /* non-pollable drive... */ 742 options[n++] = g_strdup ("sync"); 743 } 744 else if (strcmp (device->fsoptions[m], "longnames") == 0 745 && strcmp (device->fstype, "vfat") == 0) 746 { 747 /* however this one is FreeBSD specific */ 748 options[n++] = g_strdup ("longnames"); 749 } 750 else if (strcmp (device->fsoptions[m], "locale=") == 0 751 && strcmp (device->fstype, "ntfs-3g") == 0) 752 { 753 options[n++] = g_strdup_printf ("locale=%s", setlocale (LC_ALL, "")); 754 } 688 755 } 689 756 } 690 757 } 691 692 758 /* try to determine a usable mount point */ 693 759 if (G_LIKELY (device->volume != NULL)) 694 760 { … … 703 769 704 770 /* make sure that the mount point is usable (i.e. does not contain G_DIR_SEPARATOR's) */ 705 771 mount_point = (mount_point != NULL && *mount_point != '\0') 706 ? exo_str_replace (mount_point, G_DIR_SEPARATOR_S, "_") 772 ? exo_str_replace (mount_point, G_DIR_SEPARATOR_S, "_") 707 773 : g_strdup (""); 708 774 709 775 /* let HAL guess the fstype */ … … 835 901 if (dbus_error_is_set (&derror)) 836 902 { 837 903 /* try to translate the error appropriately */ 838 if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied") == 0) 904 if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied") == 0) 839 905 { 840 906 /* TRANSLATORS: User tried to mount a volume, but is not privileged to do so. */ 841 907 g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("You are not privileged to mount the volume \"%s\""), device->name); … … 1015 1081 if (G_UNLIKELY (dbus_error_is_set (&derror))) 1016 1082 { 1017 1083 /* try to translate the error appropriately */ 1018 if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied") == 0) 1084 if (strcmp (derror.name, "org.freedesktop.Hal.Device.Volume.PermissionDenied") == 0) 1019 1085 { 1020 1086 /* TRANSLATORS: User tried to unmount a volume, but is not privileged to do so. */ 1021 1087 g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("You are not privileged to unmount the volume \"%s\""), device->name); … … 1055 1121 return TRUE; 1056 1122 } 1057 1123 1124 /** 1125 * exo_volume_hal_get_options: 1126 * @fs : files system name. 1127 * @ret : an #ExoVolumeOptions. 1128 * 1129 * return mount options for specified file sytem or 1130 * override file system name. If options not found return %NULL 1131 * 1132 * code taked from PCManFM project. 1133 * 1134 * Return value: %TRUE if options is found or %FALSE if not. 1135 **/ 1136 gboolean 1137 exo_volume_hal_get_options (const char* fs, 1138 ExoVolumeOptions* ret) 1139 { 1140 GKeyFile* f; 1141 const gchar* user_opts = g_strconcat(g_getenv("HOME"), "/.config/xfce4/mount.rules", NULL); 1142 gboolean is_options_read = FALSE; 1143 if( fs == NULL || ! *fs) 1144 return FALSE; 1145 g_return_val_if_fail( ret != NULL, FALSE ); 1146 1147 f = g_key_file_new(); 1148 if( g_key_file_load_from_file( f, user_opts, 0, NULL )) 1149 { 1150 printf("User's mount options is readed\n"); 1151 is_options_read = TRUE; 1152 } 1153 else if( g_key_file_load_from_file( f, CONFIG_FILE_GLOBAL, 0, NULL) ) 1154 { 1155 printf("Global mount options is readed\n"); 1156 is_options_read = TRUE; 1157 } 1158 1159 if(is_options_read == TRUE) 1160 { 1161 gsize n = 0; 1162 int i; 1163 ret->mount_options = g_key_file_get_string_list( f, fs, "mount_options", &n, NULL ); 1164 ret->fstype_override = g_key_file_get_string(f, fs, "fstype_override", NULL ); 1165 1166 for( i = 0; i < n; ++i ) 1167 { 1168 /* replace "uid=" with "uid=<actual uid>" */ 1169 #ifndef __FreeBSD__ 1170 if (strcmp (ret->mount_options[i], "uid=") == 0) { 1171 g_free (ret->mount_options[i]); 1172 ret->mount_options[i] = g_strdup_printf ("uid=%u", getuid ()); 1173 } 1174 #else 1175 if (strcmp (ret->mount_options[i], "-u=") == 0) { 1176 g_free (ret->mount_options[i]); 1177 ret->mount_options[i] = g_strdup_printf ("-u=%u", getuid ()); 1178 } 1179 #endif 1180 /* for ntfs-3g */ 1181 if (strcmp (ret->mount_options[i], "locale=") == 0) { 1182 g_free (ret->mount_options[i]); 1183 ret->mount_options[i] = g_strdup_printf ("locale=%s", setlocale (LC_ALL, "")); 1184 } 1185 } 1186 } 1187 else 1188 { 1189 ret->mount_options = NULL; 1190 ret->fstype_override = NULL; 1191 } 1192 g_key_file_free(f); 1193 return (ret->mount_options || ret->fstype_override); 1194 } -
exo-mount/Makefile.am
diff -Naur exo-0.3.101-old/exo-mount/Makefile.am exo-0.3.101/exo-mount/Makefile.am
old new 6 6 -DG_LOG_DOMAIN=\"exo-mount\" \ 7 7 -DLIBEXECDIR=\"$(libexecdir)\" \ 8 8 -DLIBEXO_VERSION_API=\"$(LIBEXO_VERSION_API)\" \ 9 -DPACKAGE_LOCALE_DIR=\"$(localedir)\" 9 -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ 10 -DDATADIR=\"$(datadir)\" 10 11 11 12 bin_PROGRAMS = \ 12 13 exo-mount -
exo-mount/Makefile.in
diff -Naur exo-0.3.101-old/exo-mount/Makefile.in exo-0.3.101/exo-mount/Makefile.in
old new 299 299 -DG_LOG_DOMAIN=\"exo-mount\" \ 300 300 -DLIBEXECDIR=\"$(libexecdir)\" \ 301 301 -DLIBEXO_VERSION_API=\"$(LIBEXO_VERSION_API)\" \ 302 -DPACKAGE_LOCALE_DIR=\"$(localedir)\" 302 -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ 303 -DDATADIR=\"$(datadir)\" 303 304 304 305 exo_mount_SOURCES = exo-mount-fstab.c exo-mount-fstab.h \ 305 306 exo-mount-utils.c exo-mount-utils.h main.c $(am__append_1) … … 386 387 echo " rm -f $$p $$f"; \ 387 388 rm -f $$p $$f ; \ 388 389 done 389 exo-mount$(EXEEXT): $(exo_mount_OBJECTS) $(exo_mount_DEPENDENCIES) 390 exo-mount$(EXEEXT): $(exo_mount_OBJECTS) $(exo_mount_DEPENDENCIES) 390 391 @rm -f exo-mount$(EXEEXT) 391 392 $(exo_mount_LINK) $(exo_mount_OBJECTS) $(exo_mount_LDADD) $(LIBS) 392 393