summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-03-26 02:06:21 (UTC)
committer llornkcor <llornkcor>2003-03-26 02:06:21 (UTC)
commita76176911328349414203edda3785ac8925c0648 (patch) (side-by-side diff)
tree30e345d6c458b3dc2f0fd06fe900d4b7203e902f
parentf50d60ad220bbaf76e6cbcb07caf5bed037311d5 (diff)
downloadopie-a76176911328349414203edda3785ac8925c0648.zip
opie-a76176911328349414203edda3785ac8925c0648.tar.gz
opie-a76176911328349414203edda3785ac8925c0648.tar.bz2
add static isCf, isSd, and isMmc
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--library/storage.cpp61
-rw-r--r--library/storage.h4
2 files changed, 63 insertions, 2 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index a7c466d..912b22d 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,21 +1,22 @@
/**********************************************************************
** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
+** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
@@ -24,32 +25,36 @@
#include <qpe/custom.h>
#endif
#include <qfile.h>
#include <qtimer.h>
#include <qcopchannel_qws.h>
#include <stdio.h>
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
#include <sys/vfs.h>
#include <mntent.h>
#endif
#include <qstringlist.h>
+#include <sys/vfs.h>
+#include <mntent.h>
+
+
static bool isCF(const QString& m)
{
FILE* f = fopen("/var/run/stab", "r");
if (!f) f = fopen("/var/state/pcmcia/stab", "r");
if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
if ( f ) {
char line[1024];
char devtype[80];
char devname[80];
while ( fgets( line, 1024, f ) ) {
// 0 ide ide-cs 0 hda 3 0
if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
{
if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
fclose(f);
return TRUE;
@@ -161,32 +166,86 @@ void StorageInfo::update()
else if ( disk.left(13) == "/dev/mtdblock" )
humanname = tr("Internal Storage") + " " + disk;
else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
humanname = tr("Internal Memory");
FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
mFileSystems.append( fs );
}
emit disksChanged();
} else {
// just update them
for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
i.current()->update();
}
#endif
}
+bool deviceTab( const char *device) {
+ QString name = device;
+ bool hasDevice=false;
+ struct mntent *me;
+ FILE *mntfp = setmntent( "/etc/mtab", "r" );
+ if ( mntfp ) {
+ while ( (me = getmntent( mntfp )) != 0 ) {
+ QString deviceName = me->mnt_fsname;
+// qDebug(deviceName);
+ if( deviceName.left(name.length()) == name) {
+ hasDevice = true;
+ }
+ }
+ }
+ endmntent( mntfp );
+ return hasDevice;
+}
+
+/*!
+ * @fn hasCf()
+ * @brief returns whether device has Cf mounted
+ *
+ */
+bool StorageInfo::hasCf()
+{
+ return deviceTab("/dev/hd");
+}
+
+/*!
+ * @fn hasSd()
+ * @brief returns whether device has SD mounted
+ *
+ */
+bool StorageInfo::hasSd()
+{
+ return deviceTab("/dev/mmcd");
+}
+
+/*!
+ * @fn hasMmc()
+ * @brief reutrns whether device has mmc mounted
+ *
+ */
+bool StorageInfo::hasMmc()
+{
+ bool hasMmc=false;
+ if( deviceTab("/dev/mmc/part"))
+ hasMmc=true;
+ if( deviceTab("/dev/mmcd"))
+ hasMmc=true;
+ return hasMmc;
+}
+
+
//---------------------------------------------------------------------------
FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
: fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
{
update();
}
void FileSystem::update()
{
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
struct statfs fs;
if ( !statfs( fspath.latin1(), &fs ) ) {
blkSize = fs.f_bsize;
totalBlks = fs.f_blocks;
availBlks = fs.f_bavail;
diff --git a/library/storage.h b/library/storage.h
index 66a9f9d..0a0698f 100644
--- a/library/storage.h
+++ b/library/storage.h
@@ -21,33 +21,35 @@
#define __storage_h__
#include <qobject.h>
#include <qlist.h>
class FileSystem;
class QCopChannel;
class StorageInfo : public QObject
{
Q_OBJECT
public:
StorageInfo( QObject *parent=0 );
const QList<FileSystem> &fileSystems() const { return mFileSystems; }
const FileSystem *fileSystemOf( const QString &filename );
-
+ static bool hasCf();
+ static bool hasSd();
+ static bool hasMmc();
signals:
void disksChanged();
public slots:
void update();
private slots:
void cardMessage( const QCString& msg, const QByteArray& data );
private:
QList<FileSystem> mFileSystems;
QCopChannel *channel;
};
class FileSystem
{
public: