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