summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/cdromutl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/cdromutl.cc')
-rw-r--r--apt-pkg/contrib/cdromutl.cc41
1 files changed, 38 insertions, 3 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc
index 68b980407..821e6d688 100644
--- a/apt-pkg/contrib/cdromutl.cc
+++ b/apt-pkg/contrib/cdromutl.cc
@@ -15,11 +15,11 @@
#include <apt-pkg/md5.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/strutl.h>
#include <apti18n.h>
#include <sys/wait.h>
-#include <sys/errno.h>
#include <sys/statvfs.h>
#include <dirent.h>
#include <fcntl.h>
@@ -205,8 +205,11 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
Hash.Add(Dir->d_name);
};
- if (chdir(StartDir.c_str()) != 0)
- return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
+ if (chdir(StartDir.c_str()) != 0) {
+ _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
+ closedir(D);
+ return false;
+ }
closedir(D);
// Some stats from the fsys
@@ -234,3 +237,35 @@ 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))
+ {
+ fclose(f);
+ return string(out[1]);
+ }
+ }
+ }
+ fclose(f);
+ }
+ }
+
+ return string();
+}
+ /*}}}*/