Re: [Nautilus-list] nautilus-1.0.4-automount patch



le mer 03-10-2001 à 18:17, Darin Adler a écrit :
> There are a few problems with this patch that must be fixed before it can be
> committed. I'd like to see another patch with problems fixed before anything
> goes into the Nautilus source code.
> 
> There is no comment explaining why an automounted volume should not be
> ejected by Nautilus. I don't understand the overall theory, and how
> "automounted" interacts with "removable" and other volume attributes.

This patch has been created because users using automounter for cdrom
were getting unwanted eject command when automount daemon was unmounting
cdrom .. The automount patch is only needed for cdrom drives (since
eject is only called on them).

> The code does not consistently use the space between the function name and
> the opening parenthesis that's needed for Nautilus coding style, nor are
> there spaces after parameters everywhere there should be.
Fixed

 
> There is at least one obvious coding mistake:
> 
> > +            g_list_append(autofs_list,g_strdup(ent->mnt_mountp));
> 
> This has to be assigned into autofs_list.

This was in solaris part of code that I can't test.. Sorry :(

> The volume_is_automounted function builds a list of the items, but that's a
> waste of time since all we do is go through the same list a second time
> checking the paths. I'd like to see structure that's more like the latest
> version of volume_is_removable.

At first, I though it was a good idea to keep this automount list
somewhere but then there is desynchronization problem between this list
and reality.. Fixed
 
> The check to see if a volume is matches one of the mount paths uses strstr,
> which means any substring match. I'm not sure that's correct. It seems to me
> that there might be a false positive if part of another mount path happens
> to match the volume name.
Yes, strstr is not specific enough.. I've replaced it with strncmp 

So, here is second version of patch (against 1.0.6)..
-- 
Frédéric Crozat
MandrakeSoft
--- nautilus-1.0.6/libnautilus-private/nautilus-volume-monitor.c.autofs	Wed Oct 10 02:16:39 2001
+++ nautilus-1.0.6/libnautilus-private/nautilus-volume-monitor.c	Mon Nov 12 16:54:22 2001
@@ -623,6 +623,55 @@
 
 #endif /* !SOLARIS_MNT */
 
+static gboolean 
+volume_is_automounted (const NautilusVolume *volume)
+{
+	FILE *file;
+	MountTableEntry *ent;
+	gboolean automounted = FALSE;
+	
+
+#ifdef HAVE_SYS_MNTTAB_H
+ 	MountTableEntry ent_storage;
+
+	file = setmntent (MOUNT_TABLE_PATH, "r");
+ 	if (file == NULL) {
+ 		return FALSE;
+ 	}
+ 
+ 	 /* Search for our device in the fstab */
+ 	ent = &ent_storage;
+	while (!getmntent (file, ent)) {
+		if ((strstr (ent->mnt_fstype, "autofs") != NULL) && (strncmp (ent->mnt_mountp, volume->mount_path, strlen (ent->mnt_mountp)) == 0)) {
+			automounted = TRUE;
+			break;
+		}
+ 	}
+	fclose (file);
+
+#elif defined (HAVE_MNTENT_H)
+	file = setmntent (_PATH_MOUNTED, "r");
+	if (file == NULL) {
+		return FALSE;
+	}
+		
+	/* Search for our device in the fstab */
+	while ((ent = getmntent (file)) != NULL) {
+		if ((strstr (ent->mnt_type, "autofs") != NULL) && (strncmp (ent->mnt_dir, volume->mount_path, strlen (ent->mnt_dir)) == 0)) {
+			automounted = TRUE;
+			break;
+		}
+	}
+	
+	endmntent (file);
+#else
+	automounted = FALSE;
+#endif
+	
+	
+	return automounted;
+}
+
 char *
 nautilus_volume_get_name (const NautilusVolume *volume)
 {
@@ -833,7 +882,10 @@
 
 	switch (volume->device_type) {
 	case NAUTILUS_DEVICE_CDROM_DRIVE:
-		pthread_create (&eject_thread, NULL, eject_device, g_strdup (volume->device_path));
+		/* Don't eject automounted device since this action is done by autmount daemon, not user */
+		if (!volume_is_automounted (volume)) {
+			pthread_create (&eject_thread, NULL, eject_device, g_strdup (volume->device_path));
+		}
 		break;
 	default:
 	}


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