]> git.saurik.com Git - apt.git/commitdiff
apt-pkg/contrib/cdromutl.{cc,h}: add FindMountPointForDevice helper; apt-pkg/cdrom...
authorMichael Vogt <michael.vogt@ubuntu.com>
Fri, 4 Mar 2011 21:24:09 +0000 (22:24 +0100)
committerMichael Vogt <michael.vogt@ubuntu.com>
Fri, 4 Mar 2011 21:24:09 +0000 (22:24 +0100)
apt-pkg/cdrom.cc
apt-pkg/contrib/cdromutl.cc
apt-pkg/contrib/cdromutl.h

index 3dc7e99244c9da4d280001477b8da447490bf101..86fe45fbe11c57b95f9eaa6b7f4e81503c7b02d2 100644 (file)
@@ -882,6 +882,8 @@ pkgUdevCdromDevices::Scan()                                             /*{{{*/
    udev_ctx = udev_new();
    enumerate = udev_enumerate_new (udev_ctx);
    udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1");
    udev_ctx = udev_new();
    enumerate = udev_enumerate_new (udev_ctx);
    udev_enumerate_add_match_property(enumerate, "ID_CDROM", "1");
+   //FIXME: just use removalble here to include usb etc
+   //udev_enumerate_add_match_sysattr(enumerate, "removable", "1");
 
    udev_enumerate_scan_devices (enumerate);
    devices = udev_enumerate_get_list_entry (enumerate);
 
    udev_enumerate_scan_devices (enumerate);
    devices = udev_enumerate_get_list_entry (enumerate);
@@ -894,6 +896,11 @@ pkgUdevCdromDevices::Scan()                                             /*{{{*/
         continue;
       const char* devnode = udev_device_get_devnode(udevice);
       const char* mountpath = udev_device_get_property_value(udevice, "FSTAB_DIR");
         continue;
       const char* devnode = udev_device_get_devnode(udevice);
       const char* mountpath = udev_device_get_property_value(udevice, "FSTAB_DIR");
+      if (mountpath == NULL)
+         mountpath = FindMountPointForDevice(devnode);
+
+      if (_config->FindB("Debug::Acquire::cdrom", false))
+         cerr << "found " << devnode << " mounted on " << mountpath << endl;
 
       // fill in the struct
       cdrom.DeviceName = string(devnode);
 
       // fill in the struct
       cdrom.DeviceName = string(devnode);
index 68b98040722e3b611a03e16d30a227ea015fad40..cf1c0c29bf02edaa476988f680f029701892df00 100644 (file)
@@ -15,6 +15,7 @@
 #include <apt-pkg/md5.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
 
 #include <apti18n.h>
     
 
 #include <apti18n.h>
     
@@ -234,3 +235,33 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
    return true;   
 }
                                                                        /*}}}*/
    return true;   
 }
                                                                        /*}}}*/
+
+// FindMountPointForDevice - Find mountpoint for the given device      /*{{{*/
+char* FindMountPointForDevice(const char *devnode)
+{
+   char buf[255];
+   char *out[10];
+   int i=0;
+
+   // this is the order that mount uses as well
+   const char *mount[] = { "/etc/mtab", 
+                           "/proc/mount", 
+                           NULL };
+
+   for (i=0; mount[i] != NULL; i++) {
+      if (FileExists(mount[i])) {
+         FILE *f=fopen(mount[i], "r");
+         while ( fgets(buf, sizeof(buf), f) != NULL) {
+            if (strncmp(buf, devnode, strlen(devnode)) == 0) {
+               if(TokSplitString(' ', buf, out, 10))
+                  return strdup(out[1]);
+            }
+         }
+         fclose(f);
+      }
+   }
+   
+   return NULL;
+}
+
+
index 9d14249c53b71fbcfa9d0051dfe60ab308c1ba03..4f0f903477dbd32a8c0240271dfd64fdfba482bd 100644 (file)
@@ -19,5 +19,6 @@ bool MountCdrom(string Path, string DeviceName="");
 bool UnmountCdrom(string Path);
 bool IdentCdrom(string CD,string &Res,unsigned int Version = 2);
 bool IsMounted(string &Path);
 bool UnmountCdrom(string Path);
 bool IdentCdrom(string CD,string &Res,unsigned int Version = 2);
 bool IsMounted(string &Path);
+char *FindMountPointForDevice(const char *device);
 
 #endif
 
 #endif