From b2c37ee0c4a57d716d98452278fe6a22a04ba881 Mon Sep 17 00:00:00 2001 From: bluebrother Date: Sun, 2 Sep 2007 08:49:08 +0000 Subject: [PATCH] Fix autodetection based on rockbox-info.txt which I broke when fixing X5 detection. Replace mountpoint detection to use getmntent api on linux. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14573 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/autodetection.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp index 2300a1bba..a359b91af 100644 --- a/rbutil/rbutilqt/autodetection.cpp +++ b/rbutil/rbutilqt/autodetection.cpp @@ -19,6 +19,11 @@ #include "autodetection.h" +#if defined(Q_OS_LINUX) +#include +#include +#endif + Autodetection::Autodetection(QObject* parent): QObject(parent) { @@ -45,6 +50,7 @@ bool Autodetection::detect() if(!log.value("platform").toString().isEmpty()) { m_device = log.value("platform").toString(); m_mountpoint = mountpoints.at(i); + qDebug() << "rbutil.log detected:" << m_device << m_mountpoint; return true; } } @@ -58,14 +64,16 @@ bool Autodetection::detect() if(line.startsWith("Target: ")) { line.remove("Target: "); - m_device = line; + m_device = line.trimmed(); // trim whitespaces m_mountpoint = mountpoints.at(i); + qDebug() << "rockbox-info.txt detected:" << m_device << m_mountpoint; return true; } } } } + int n; //try ipodpatcher @@ -129,25 +137,21 @@ QStringList Autodetection::getMountpoints() QString Autodetection::resolveMountPoint(QString device) { qDebug() << "Autodetection::resolveMountPoint(QString)" << device; + #if defined(Q_OS_LINUX) - FILE *fp = fopen( "/proc/mounts", "r" ); - if( !fp ) return QString(""); - char *dev, *dir; - while( fscanf( fp, "%as %as %*s %*s %*s %*s", &dev, &dir ) != EOF ) - { - if( QString(dev).startsWith(device) ) - { - QString directory = dir; - free( dev ); - free( dir ); - fclose(fp); - return directory; + FILE *mn = setmntent("/etc/mtab", "r"); + if(!mn) + return QString(""); + + struct mntent *ent; + while((ent = getmntent(mn))) { + if(QString(ent->mnt_fsname).startsWith(device)) { + endmntent(mn); + return QString(ent->mnt_dir); } - free( dev ); - free( dir ); } - fclose( fp ); - + endmntent(mn); + #endif return QString(""); -- 2.11.4.GIT