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);
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);
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
#include <apti18n.h>
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;
+}
+
+
bool UnmountCdrom(string Path);
bool IdentCdrom(string CD,string &Res,unsigned int Version = 2);
bool IsMounted(string &Path);
+char *FindMountPointForDevice(const char *device);
#endif