From ef38181605be2f7131bed9865d965300339389b5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 4 Mar 2011 22:24:09 +0100 Subject: apt-pkg/contrib/cdromutl.{cc,h}: add FindMountPointForDevice helper; apt-pkg/cdrom.cc: deal with missing FSTAB_DIR --- apt-pkg/contrib/cdromutl.cc | 31 +++++++++++++++++++++++++++++++ apt-pkg/contrib/cdromutl.h | 1 + 2 files changed, 32 insertions(+) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index 68b980407..cf1c0c29b 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -234,3 +235,33 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) 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; +} + + diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h index 9d14249c5..4f0f90347 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); +char *FindMountPointForDevice(const char *device); #endif -- cgit v1.2.3 From 4703608e2ab7549e542410465304078b1ccfa793 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 9 Mar 2011 12:16:12 +0100 Subject: cherry pick (2) from lp:~mvo/apt/mvo --- apt-pkg/contrib/cdromutl.cc | 6 +++--- apt-pkg/contrib/cdromutl.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib') diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index cf1c0c29b..83c324f54 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -237,7 +237,7 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) /*}}}*/ // FindMountPointForDevice - Find mountpoint for the given device /*{{{*/ -char* FindMountPointForDevice(const char *devnode) +string FindMountPointForDevice(const char *devnode) { char buf[255]; char *out[10]; @@ -254,14 +254,14 @@ char* FindMountPointForDevice(const char *devnode) while ( fgets(buf, sizeof(buf), f) != NULL) { if (strncmp(buf, devnode, strlen(devnode)) == 0) { if(TokSplitString(' ', buf, out, 10)) - return strdup(out[1]); + return string(out[1]); } } fclose(f); } } - return NULL; + return string(); } diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h index 4f0f90347..38ed2996e 100644 --- a/apt-pkg/contrib/cdromutl.h +++ b/apt-pkg/contrib/cdromutl.h @@ -19,6 +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); -char *FindMountPointForDevice(const char *device); +string FindMountPointForDevice(const char *device); #endif -- cgit v1.2.3