On ���, 2002-01-26 at 14:44, Borsenkow Andrej wrote:
> {pts/1}% sudo urpmi afio
> eject: unable to find or open device for: `none'
> 
> We use "none" for device in supermount that (unfortunately) eject does
> not like.
> 

It is funny but urpmi can't deal with supermounted medias exactly for
the same reason. It is just that nobody on cooker is using removable
media to install it :-)

The patch to urpm.pm and eject.c tries to correct it. Changes are

urpm.pm

- take device name out of dev= option; ignore lines where device ==
'none'

May be it is possible to completely remove device names from urpm.pm. We
do not use them any more anywhere; and with the attached patch eject
correctly handles eject /mnt/point for supermount. But it was the
simplest thing without going through all code. Sorry for my bad Perl.

eject.c

- get device name from dev=
- ignore everything with device == 'none'
- use stat not read to test path existence. Read fails if no media (and
it is quite valid to just open tray).

I felt kinda silly duplicating code but that is the way eject.c is
written currently :-)

Using these patches it should be possible to use

eject [-t] /mnt/point 

for any type of mount points without need to search for device first.

-andrej

--- urpm.pm.org Wed Jan 23 20:09:15 2002
+++ urpm.pm     Sat Jan 26 21:26:42 2002
@@ -1027,15 +1027,33 @@
     #- read /etc/fstab and check for existing mount point.
     open F, "/etc/fstab";
     while (<F>) {
-       my ($device, $mntpoint) = /^\s*(\S+)\s+(\/\S+)/ or next;
+       my ($device, $mntpoint, $fstype, $options) = 
+/^\s*(\S+)\s+(\/\S+)\s+(\S+)\s+(\S+)/ or next;
        $mntpoint =~ s,/+,/,g; $mntpoint =~ s,/$,,;
-       $fstab{$mntpoint} = $mode eq 'device' ? ($device eq $mntpoint ? 
m|dev=(/[^,\s]*)| && $1 : $device) : 0;
+       $fstab{$mntpoint} =  0;
+       if ($mode eq 'device') {
+           if ($fstype eq 'supermount') {
+               $options =~ /^.*dev=([^,]+),*$/ and $fstab{$mntpoint} = $1;
+           } elsif ($device eq 'none') {
+               next;
+           } else {
+               $fstab{$mntpoint} = $device;
+           }
+       }
     }
     open F, "/etc/mtab";
     while (<F>) {
-       my ($device, $mntpoint) = /^\s*(\S+)\s+(\/\S+)/ or next;
+       my ($device, $mntpoint, $fstype, $options) = 
+/^\s*(\S+)\s+(\/\S+)\s+(\S+)\s+(\S+)/ or next;
        $mntpoint =~ s,/+,/,g; $mntpoint =~ s,/$,,;
-       $fstab{$mntpoint} = $mode eq 'device' ? $device : 1;
+       $fstab{$mntpoint} = 1;
+       if ($mode eq 'device') {
+           if ($fstype eq 'supermount') {
+               $options =~ /^.*dev=([^,]+),*$/ and $fstab{$mntpoint} = $1;
+           } elsif ($device eq 'none') {
+               next;
+           } else {
+               $fstab{$mntpoint} = $device;
+           }
+       }
     }
     close F;
 
--- eject.c.org Tue Jul  3 00:17:41 2001
+++ eject.c     Sat Jan 26 20:33:22 2002
@@ -273,13 +273,11 @@
 /* Return 1 if file/device exists, 0 otherwise. */
 static int FileExists(const char *name)
 {
-       int fd;
+       struct stat buf;
 
-       fd = open(name, O_RDONLY|O_NONBLOCK);
-       if (fd == -1) {
+       if (stat(name, &buf) == -1) {
                return 0;
        } else {
-               close(fd);
                return 1;
        }
 }
@@ -595,6 +593,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.
+ * If device is supermounted, return -1
  */
 static int MountedDevice(const char *name, char **mountName, char **deviceName)
 {
@@ -602,6 +601,8 @@
        char line[1024];
        char s1[1024];
        char s2[1024];
+       char fstype[1024];
+       char options[1024];
        int rc;
 
        int maj;
@@ -617,16 +618,37 @@
        }
 
        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, "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;
                        }
                }
        }
@@ -648,6 +670,8 @@
        char line[1024];
        char s1[1024];
        char s2[1024];
+       char fstype[1024];
+       char options[1024];
        int rc;
 
        fp = fopen("/etc/fstab", "r");
@@ -657,8 +681,26 @@
        }
 
        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, "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);
@@ -680,6 +722,8 @@
        FILE *fp;
        char s1[1024];
        char s2[1024];
+       char fstype[1024];
+       char options[1024];
        char line[1024];
        int status;
 
@@ -693,10 +737,30 @@
        }
 
        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, "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);
@@ -923,7 +987,7 @@
        if (!c_option) HandleXOption(deviceName);
 
        /* unmount device if mounted */
-       if (mounted) {
+       if (mounted > 0) {
                if (v_option)
                        printf(_("%s: unmounting `%s'\n"), programName, deviceName);
                Unmount(deviceName);

Reply via email to