summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp61
-rw-r--r--library/storage.h8
2 files changed, 65 insertions, 4 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index a7c466d..912b22d 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,200 +1,259 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org> 2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
3** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
3** Copyright (C) 2000 Trolltech AS. All rights reserved. 4** Copyright (C) 2000 Trolltech AS. All rights reserved.
4** 5**
5** This file is part of Qtopia Environment. 6** This file is part of Opie Environment.
6** 7**
7** This file may be distributed and/or modified under the terms of the 8** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 9** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 10** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 11** packaging of this file.
11** 12**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 15**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 16** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 17**
17** Contact info@trolltech.com if any conditions of this licensing are 18** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 19** not clear to you.
19** 20**
20**********************************************************************/ 21**********************************************************************/
21 22
22#include <qpe/storage.h> 23#include <qpe/storage.h>
23#ifdef QT_QWS_SL5XXX 24#ifdef QT_QWS_SL5XXX
24#include <qpe/custom.h> 25#include <qpe/custom.h>
25#endif 26#endif
26 27
27#include <qfile.h> 28#include <qfile.h>
28#include <qtimer.h> 29#include <qtimer.h>
29#include <qcopchannel_qws.h> 30#include <qcopchannel_qws.h>
30 31
31#include <stdio.h> 32#include <stdio.h>
32 33
33#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 34#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
34#include <sys/vfs.h> 35#include <sys/vfs.h>
35#include <mntent.h> 36#include <mntent.h>
36#endif 37#endif
37 38
38#include <qstringlist.h> 39#include <qstringlist.h>
39 40
41#include <sys/vfs.h>
42#include <mntent.h>
43
44
40static bool isCF(const QString& m) 45static bool isCF(const QString& m)
41{ 46{
42 FILE* f = fopen("/var/run/stab", "r"); 47 FILE* f = fopen("/var/run/stab", "r");
43 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 48 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
44 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 49 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
45 if ( f ) { 50 if ( f ) {
46 char line[1024]; 51 char line[1024];
47 char devtype[80]; 52 char devtype[80];
48 char devname[80]; 53 char devname[80];
49 while ( fgets( line, 1024, f ) ) { 54 while ( fgets( line, 1024, f ) ) {
50 // 0 ide ide-cs 0 hda 3 0 55 // 0 ide ide-cs 0 hda 3 0
51 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 56 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
52 { 57 {
53 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 58 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
54 fclose(f); 59 fclose(f);
55 return TRUE; 60 return TRUE;
56 } 61 }
57 } 62 }
58 } 63 }
59 fclose(f); 64 fclose(f);
60 } 65 }
61 return FALSE; 66 return FALSE;
62} 67}
63 68
64StorageInfo::StorageInfo( QObject *parent ) 69StorageInfo::StorageInfo( QObject *parent )
65 : QObject( parent ) 70 : QObject( parent )
66{ 71{
67 mFileSystems.setAutoDelete( TRUE ); 72 mFileSystems.setAutoDelete( TRUE );
68 channel = new QCopChannel( "QPE/Card", this ); 73 channel = new QCopChannel( "QPE/Card", this );
69 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 74 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
70 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 75 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
71 update(); 76 update();
72} 77}
73 78
74const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 79const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
75{ 80{
76 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 81 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
77 if ( filename.startsWith( (*i)->path() ) ) 82 if ( filename.startsWith( (*i)->path() ) )
78 return (*i); 83 return (*i);
79 } 84 }
80 return 0; 85 return 0;
81} 86}
82 87
83 88
84void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 89void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
85{ 90{
86 if ( msg == "mtabChanged()" ) 91 if ( msg == "mtabChanged()" )
87 update(); 92 update();
88} 93}
89// cause of the lack of a d pointer we need 94// cause of the lack of a d pointer we need
90// to store informations in a config file :( 95// to store informations in a config file :(
91void StorageInfo::update() 96void StorageInfo::update()
92{ 97{
93 //qDebug("StorageInfo::updating"); 98 //qDebug("StorageInfo::updating");
94#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 99#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
95 struct mntent *me; 100 struct mntent *me;
96 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 101 FILE *mntfp = setmntent( "/etc/mtab", "r" );
97 102
98 QStringList curdisks; 103 QStringList curdisks;
99 QStringList curopts; 104 QStringList curopts;
100 QStringList curfs; 105 QStringList curfs;
101 bool rebuild = FALSE; 106 bool rebuild = FALSE;
102 int n=0; 107 int n=0;
103 if ( mntfp ) { 108 if ( mntfp ) {
104 while ( (me = getmntent( mntfp )) != 0 ) { 109 while ( (me = getmntent( mntfp )) != 0 ) {
105 QString fs = me->mnt_fsname; 110 QString fs = me->mnt_fsname;
106 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 111 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
107 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 112 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
108 || fs.left( 14 ) == "/dev/mmc/part1" 113 || fs.left( 14 ) == "/dev/mmc/part1"
109 || fs.left(5)=="tmpfs" ) 114 || fs.left(5)=="tmpfs" )
110 { 115 {
111 n++; 116 n++;
112 curdisks.append(fs); 117 curdisks.append(fs);
113 curopts.append( me->mnt_opts ); 118 curopts.append( me->mnt_opts );
114 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 119 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
115 curfs.append( me->mnt_dir ); 120 curfs.append( me->mnt_dir );
116 bool found = FALSE; 121 bool found = FALSE;
117 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 122 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
118 if ( (*i)->disk() == fs ) { 123 if ( (*i)->disk() == fs ) {
119 found = TRUE; 124 found = TRUE;
120 break; 125 break;
121 } 126 }
122 } 127 }
123 if ( !found ) 128 if ( !found )
124 rebuild = TRUE; 129 rebuild = TRUE;
125 } 130 }
126 } 131 }
127 endmntent( mntfp ); 132 endmntent( mntfp );
128 } 133 }
129 if ( rebuild || n != (int)mFileSystems.count() ) { 134 if ( rebuild || n != (int)mFileSystems.count() ) {
130 mFileSystems.clear(); 135 mFileSystems.clear();
131 QStringList::ConstIterator it=curdisks.begin(); 136 QStringList::ConstIterator it=curdisks.begin();
132 QStringList::ConstIterator fsit=curfs.begin(); 137 QStringList::ConstIterator fsit=curfs.begin();
133 QStringList::ConstIterator optsIt=curopts.begin(); 138 QStringList::ConstIterator optsIt=curopts.begin();
134 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { 139 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
135 QString opts = *optsIt; 140 QString opts = *optsIt;
136 141
137 QString disk = *it; 142 QString disk = *it;
138 QString humanname; 143 QString humanname;
139 bool removable = FALSE; 144 bool removable = FALSE;
140 if ( isCF(disk) ) { 145 if ( isCF(disk) ) {
141 humanname = tr("CF Card"); 146 humanname = tr("CF Card");
142 removable = TRUE; 147 removable = TRUE;
143 } else if ( disk == "/dev/hda1" ) { 148 } else if ( disk == "/dev/hda1" ) {
144 humanname = tr("Hard Disk"); 149 humanname = tr("Hard Disk");
145 } else if ( disk.left(9) == "/dev/mmcd" ) { 150 } else if ( disk.left(9) == "/dev/mmcd" ) {
146 humanname = tr("SD Card"); 151 humanname = tr("SD Card");
147 removable = TRUE; 152 removable = TRUE;
148 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { 153 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) {
149 humanname = tr("MMC Card"); 154 humanname = tr("MMC Card");
150 removable = TRUE; 155 removable = TRUE;
151 } else if ( disk.left(7) == "/dev/hd" ) 156 } else if ( disk.left(7) == "/dev/hd" )
152 humanname = tr("Hard Disk") + " " + disk; 157 humanname = tr("Hard Disk") + " " + disk;
153 else if ( disk.left(7) == "/dev/sd" ) 158 else if ( disk.left(7) == "/dev/sd" )
154 humanname = tr("SCSI Hard Disk") + " " + disk; 159 humanname = tr("SCSI Hard Disk") + " " + disk;
155 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 160 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
156 humanname = tr("Internal Memory"); 161 humanname = tr("Internal Memory");
157 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 162 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
158 humanname = tr("Internal Storage"); 163 humanname = tr("Internal Storage");
159 else if ( disk.left(14) == "/dev/mtdblock/" ) 164 else if ( disk.left(14) == "/dev/mtdblock/" )
160 humanname = tr("Internal Storage") + " " + disk; 165 humanname = tr("Internal Storage") + " " + disk;
161 else if ( disk.left(13) == "/dev/mtdblock" ) 166 else if ( disk.left(13) == "/dev/mtdblock" )
162 humanname = tr("Internal Storage") + " " + disk; 167 humanname = tr("Internal Storage") + " " + disk;
163 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 168 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
164 humanname = tr("Internal Memory"); 169 humanname = tr("Internal Memory");
165 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 170 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
166 mFileSystems.append( fs ); 171 mFileSystems.append( fs );
167 } 172 }
168 emit disksChanged(); 173 emit disksChanged();
169 } else { 174 } else {
170 // just update them 175 // just update them
171 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 176 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
172 i.current()->update(); 177 i.current()->update();
173 } 178 }
174#endif 179#endif
175} 180}
176 181
182bool deviceTab( const char *device) {
183 QString name = device;
184 bool hasDevice=false;
185 struct mntent *me;
186 FILE *mntfp = setmntent( "/etc/mtab", "r" );
187 if ( mntfp ) {
188 while ( (me = getmntent( mntfp )) != 0 ) {
189 QString deviceName = me->mnt_fsname;
190// qDebug(deviceName);
191 if( deviceName.left(name.length()) == name) {
192 hasDevice = true;
193 }
194 }
195 }
196 endmntent( mntfp );
197 return hasDevice;
198}
199
200/*!
201 * @fn hasCf()
202 * @brief returns whether device has Cf mounted
203 *
204 */
205bool StorageInfo::hasCf()
206{
207 return deviceTab("/dev/hd");
208}
209
210/*!
211 * @fn hasSd()
212 * @brief returns whether device has SD mounted
213 *
214 */
215bool StorageInfo::hasSd()
216{
217 return deviceTab("/dev/mmcd");
218}
219
220/*!
221 * @fn hasMmc()
222 * @brief reutrns whether device has mmc mounted
223 *
224 */
225bool StorageInfo::hasMmc()
226{
227 bool hasMmc=false;
228 if( deviceTab("/dev/mmc/part"))
229 hasMmc=true;
230 if( deviceTab("/dev/mmcd"))
231 hasMmc=true;
232 return hasMmc;
233}
234
235
177//--------------------------------------------------------------------------- 236//---------------------------------------------------------------------------
178 237
179FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) 238FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
180 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) 239 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
181{ 240{
182 update(); 241 update();
183} 242}
184 243
185void FileSystem::update() 244void FileSystem::update()
186{ 245{
187#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 246#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
188 struct statfs fs; 247 struct statfs fs;
189 if ( !statfs( fspath.latin1(), &fs ) ) { 248 if ( !statfs( fspath.latin1(), &fs ) ) {
190 blkSize = fs.f_bsize; 249 blkSize = fs.f_bsize;
191 totalBlks = fs.f_blocks; 250 totalBlks = fs.f_blocks;
192 availBlks = fs.f_bavail; 251 availBlks = fs.f_bavail;
193 } else { 252 } else {
194 blkSize = 0; 253 blkSize = 0;
195 totalBlks = 0; 254 totalBlks = 0;
196 availBlks = 0; 255 availBlks = 0;
197 } 256 }
198#endif 257#endif
199} 258}
200 259
diff --git a/library/storage.h b/library/storage.h
index 66a9f9d..0a0698f 100644
--- a/library/storage.h
+++ b/library/storage.h
@@ -1,80 +1,82 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __storage_h__ 20#ifndef __storage_h__
21#define __storage_h__ 21#define __storage_h__
22 22
23#include <qobject.h> 23#include <qobject.h>
24#include <qlist.h> 24#include <qlist.h>
25 25
26class FileSystem; 26class FileSystem;
27class QCopChannel; 27class QCopChannel;
28 28
29class StorageInfo : public QObject 29class StorageInfo : public QObject
30{ 30{
31 Q_OBJECT 31 Q_OBJECT
32public: 32public:
33 StorageInfo( QObject *parent=0 ); 33 StorageInfo( QObject *parent=0 );
34 34
35 const QList<FileSystem> &fileSystems() const { return mFileSystems; } 35 const QList<FileSystem> &fileSystems() const { return mFileSystems; }
36 const FileSystem *fileSystemOf( const QString &filename ); 36 const FileSystem *fileSystemOf( const QString &filename );
37 37 static bool hasCf();
38 static bool hasSd();
39 static bool hasMmc();
38signals: 40signals:
39 void disksChanged(); 41 void disksChanged();
40 42
41public slots: 43public slots:
42 void update(); 44 void update();
43 45
44private slots: 46private slots:
45 void cardMessage( const QCString& msg, const QByteArray& data ); 47 void cardMessage( const QCString& msg, const QByteArray& data );
46private: 48private:
47 QList<FileSystem> mFileSystems; 49 QList<FileSystem> mFileSystems;
48 QCopChannel *channel; 50 QCopChannel *channel;
49}; 51};
50 52
51class FileSystem 53class FileSystem
52{ 54{
53public: 55public:
54 const QString &disk() const { return fsdisk; } 56 const QString &disk() const { return fsdisk; }
55 const QString &path() const { return fspath; } 57 const QString &path() const { return fspath; }
56 const QString &name() const { return humanname; } 58 const QString &name() const { return humanname; }
57 const QString &options() const { return opts; } 59 const QString &options() const { return opts; }
58 long blockSize() const { return blkSize; } 60 long blockSize() const { return blkSize; }
59 long totalBlocks() const { return totalBlks; } 61 long totalBlocks() const { return totalBlks; }
60 long availBlocks() const { return availBlks; } 62 long availBlocks() const { return availBlks; }
61 bool isRemovable() const { return removable; } 63 bool isRemovable() const { return removable; }
62 bool isWritable() const { return opts.contains("rw"); } 64 bool isWritable() const { return opts.contains("rw"); }
63 65
64private: 66private:
65 friend class StorageInfo; 67 friend class StorageInfo;
66 FileSystem( const QString &disk, const QString &path, const QString &humanname, bool rem, const QString &opts ); 68 FileSystem( const QString &disk, const QString &path, const QString &humanname, bool rem, const QString &opts );
67 void update(); 69 void update();
68 70
69 QString fsdisk; 71 QString fsdisk;
70 QString fspath; 72 QString fspath;
71 QString humanname; 73 QString humanname;
72 long blkSize; 74 long blkSize;
73 long totalBlks; 75 long totalBlks;
74 long availBlks; 76 long availBlks;
75 bool removable; 77 bool removable;
76 QString opts; 78 QString opts;
77}; 79};
78 80
79 81
80#endif 82#endif