File eject-2.1.0-subfs.diff of Package eject

--- eject.c
+++ eject.c
@@ -686,6 +686,7 @@
 /*
  * See if device has been mounted by looking in mount table.  If so, set
  * device name and mount point name, and return 1, otherwise return 0.
+ * Do not unmount subfs or submount devices
  */
 static int MountedDevice(const char *name, char **mountName, char **deviceName)
 {
@@ -693,6 +694,8 @@
 	char line[1024];
 	char s1[1024];
 	char s2[1024];
+	char fstype[1024];
+	char options[1024];
 	int rc;
 
 	int maj;
@@ -708,16 +711,39 @@
 	}
 
 	while (fgets(line, sizeof(line), fp) != 0) {
-		rc = sscanf(line, "%1023s %1023s", s1, s2);
-		if (rc >= 2) {
+		int supermount = 0;
+		rc = sscanf(line, "%1023s %1023s %1023s %1023s", s1, s2, fstype, options);
+		if (rc >= 4) {
 			int mtabmaj, mtabmin;
+			if (!p_option && 
+                             (  (strcmp(fstype, "subfs") == 0)  
+			     || (strcmp(fstype, "supermount") == 0) ) ) {
+				char *q, *p = strstr(options, "dev=");
+				int len;
+				
+				if (p) {
+				        q = strchr(p+4, ',');
+				        if (q) {
+				                len = q-p-4 < 1024 ? q-p-4 : 1023;
+				                strncpy(s1, p+4, len);
+				                s1[len] = 0;
+				        } else {
+				                strncpy(s1, p+4, 1023);
+				                s1[1023] = 0;
+				        }
+				}
+				supermount = 1;
+			}
+			
+			if (strcmp(s1, "none") == 0)
+			        continue;
 			GetMajorMinor(s1, &mtabmaj, &mtabmin);
 			if (((strcmp(s1, name) == 0) || (strcmp(s2, name) == 0)) ||
 				((maj != -1) && (maj == mtabmaj) && (min == mtabmin))) {
 				FCLOSE(fp);
 				*deviceName = strdup(s1);
 				*mountName = strdup(s2);
-				return 1;
+				return supermount ? -1 : 1;
 			}
 		}
 	}
@@ -739,6 +765,8 @@
 	char line[1024];
 	char s1[1024];
 	char s2[1024];
+	char fstype[1024];
+	char options[1024];
 	int rc;
 
 	fp = fopen("/etc/fstab", "r");
@@ -756,8 +784,29 @@
 	}
 
 	while (fgets(line, sizeof(line), fp) != 0) {
-		rc = sscanf(line, "%1023s %1023s", s1, s2);
-		if (rc >= 2 && s1[0] != '#' && strcmp(s2, name) == 0) {
+		rc = sscanf(line, "%1023s %1023s %1023s %1023s", s1, s2, fstype, options);
+		if (rc >= 4 && s1[0] != '#' && strcmp(s2, name) == 0) {
+			if (!p_option && 
+                             ( (strcmp(fstype, "subfs")==0) 
+			       || (strcmp(fstype, "supermount")==0) ) ) {
+				char *q, *p = strstr(options, "dev=");
+				int len;
+				
+				if (p) {
+				        q = strchr(p+4, ',');
+				        if (q) {
+				                len = q-p-4 < 1024 ? q-p-4 : 1023;
+				                strncpy(s1, p+4, len);
+				                s1[len] = 0;
+				        } else {
+				                strncpy(s1, p+4, 1023);
+				                s1[1023] = 0;
+				        }
+				}
+			}
+			if (strcmp(s1, "none") == 0)
+			        continue;
+
 			FCLOSE(fp);
 			*deviceName = strdup(s1);
 			*mountName = strdup(s2);
@@ -779,6 +828,8 @@
 	FILE *fp;
 	char s1[1024];
 	char s2[1024];
+	char fstype[1024];
+	char options[1024];
 	char line[1024];
 	int status;
 
@@ -795,10 +846,32 @@
 	}
 
 	while (fgets(line, sizeof(line), fp) != 0) {
-		status = sscanf(line, "%1023s %1023s", s1, s2);
-		if (status >= 2) {
+		int supermount = 0;
+		status = sscanf(line, "%1023s %1023s %1023s %1023s", s1, s2, fstype, options);
+		if (status >= 4) {
+			if (!p_option && 
+		             ( (strcmp(fstype, "subfs")==0) 
+			       || (strcmp(fstype, "supermount")==0) ) ) {
+			        char *q, *p = strstr(options, "dev=");
+			        int len;
+			
+			        if (p) {
+			                q = strchr(p+4, ',');
+			                if (q) {
+			                        len = q-p-4 < 1024 ? q-p-4 : 1023;
+			                        strncpy(s1, p+4, len);
+			                        s1[len] = 0;
+			                } else {
+			                        strncpy(s1, p+4, 1023);
+			                        s1[1023] = 0;
+			                }
+			        }
+			        supermount = 1;
+			}
+			if (strcmp(s1, "none") == 0)
+			        continue;
 			status = regexec(&preg, s1, 0, 0, 0);
-			if (status == 0) {
+			if (status == 0 && !supermount) {
 				if (v_option)
 					printf(_("%s: unmounting `%s'\n"), programName, s1);
 				Unmount(s1);
@@ -1042,7 +1115,7 @@
 	if (!c_option) HandleXOption(deviceName);
 
 	/* unmount device if mounted */
-	if ((m_option != 1) && mounted) {
+	if ((m_option != 1) && (mounted > 0)) {
 		if (v_option)
 			printf(_("%s: unmounting `%s'\n"), programName, deviceName);
 		Unmount(deviceName);
openSUSE Build Service is sponsored by