diff options
-rw-r--r-- | apt-pkg/cdrom.cc | 17 | ||||
-rw-r--r-- | apt-pkg/cdrom.h | 1 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 31 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.h | 1 | ||||
-rw-r--r-- | debian/changelog | 6 |
5 files changed, 54 insertions, 2 deletions
diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 04ace10a6..1e084bfb5 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -854,6 +854,7 @@ pkgUdevCdromDevices::Dlopen() /*{{{*/ libudev_handle = h; udev_new = (udev* (*)(void)) dlsym(h, "udev_new"); udev_enumerate_add_match_property = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_property"); + udev_enumerate_add_match_sysattr = (int (*)(udev_enumerate*, const char*, const char*))dlsym(h, "udev_enumerate_add_match_sysattr"); udev_enumerate_scan_devices = (int (*)(udev_enumerate*))dlsym(h, "udev_enumerate_scan_devices"); udev_enumerate_get_list_entry = (udev_list_entry* (*)(udev_enumerate*))dlsym(h, "udev_enumerate_get_list_entry"); udev_device_new_from_syspath = (udev_device* (*)(udev*, const char*))dlsym(h, "udev_device_new_from_syspath"); @@ -881,6 +882,8 @@ pkgUdevCdromDevices::Scan() /*{{{*/ 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); @@ -892,11 +895,21 @@ pkgUdevCdromDevices::Scan() /*{{{*/ if (udevice == NULL) continue; const char* devnode = udev_device_get_devnode(udevice); - const char* mountpath = udev_device_get_property_value(udevice, "FSTAB_DIR"); + + // try fstab_dir first + string mountpath; + const char* mp = udev_device_get_property_value(udevice, "FSTAB_DIR"); + if (mp) + mountpath = string(mp); + else + 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); - if (mountpath) { + if (mountpath != "") { cdrom.MountPath = mountpath; string s = string(mountpath); cdrom.Mounted = IsMounted(s); diff --git a/apt-pkg/cdrom.h b/apt-pkg/cdrom.h index 14ca1d810..5f67a3a94 100644 --- a/apt-pkg/cdrom.h +++ b/apt-pkg/cdrom.h @@ -92,6 +92,7 @@ class pkgUdevCdromDevices /*{{{*/ struct udev_enumerate *(*udev_enumerate_new) (struct udev *udev); struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *list_entry); const char* (*udev_device_get_property_value)(struct udev_device *udev_device, const char *key); + int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value); // end libudev dlopen public: diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 68b980407..83c324f54 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -15,6 +15,7 @@ #include <apt-pkg/md5.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/configuration.h> +#include <apt-pkg/strutl.h> #include <apti18n.h> @@ -234,3 +235,33 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) return true; } /*}}}*/ + +// FindMountPointForDevice - Find mountpoint for the given device /*{{{*/ +string 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 string(out[1]); + } + } + fclose(f); + } + } + + return string(); +} + + diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h index 9d14249c5..38ed2996e 100644 --- a/apt-pkg/contrib/cdromutl.h +++ b/apt-pkg/contrib/cdromutl.h @@ -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); +string FindMountPointForDevice(const char *device); #endif diff --git a/debian/changelog b/debian/changelog index 6b88f84bf..f29452503 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +apt (0.8.11.5ubuntu3) UNRELEASED; urgency=low + + * cherry pick cdrom mount fixes from lp:~mvo/apt/mvo + + -- Michael Vogt <michael.vogt@ubuntu.com> Wed, 09 Mar 2011 12:16:32 +0100 + apt (0.8.11.5ubuntu2) natty; urgency=low [ Michael Vogt ] |