X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/58d9e6e0f9bf93724637c8a5687fe22058fc75a1..032bd56ff86166fd4b6a8f69bd9d5d1bc57b886e:/apt-pkg/contrib/cdromutl.cc diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 68b980407..187f6bd59 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -10,24 +10,28 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include #include #include #include +#include -#include - #include -#include #include #include #include #include #include #include + +#include /*}}}*/ +using std::string; + // IsMounted - Returns true if the mount point is mounted /*{{{*/ // --------------------------------------------------------------------- /* This is a simple algorithm that should always work, we stat the mount point @@ -205,8 +209,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 +241,37 @@ 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); + // unescape the \0XXX chars in the path + string mount_point = out[1]; + return DeEscapeString(mount_point); + } + } + } + fclose(f); + } + } + + return string(); +} + /*}}}*/