summaryrefslogtreecommitdiff
path: root/library/storage.cpp
Unidiff
Diffstat (limited to 'library/storage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index dc5cc22..f8b75d0 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,111 +1,123 @@
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#include <qpe/custom.h> 24#include <qpe/custom.h>
25 25
26#include <qfile.h> 26#include <qfile.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qcopchannel_qws.h> 28#include <qcopchannel_qws.h>
29 29
30#include <stdio.h> 30#include <stdio.h>
31 31
32#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 32#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
33#include <sys/vfs.h> 33#include <sys/vfs.h>
34#include <mntent.h> 34#include <mntent.h>
35#endif 35#endif
36 36
37#ifdef Q_OS_MACX
38# include <sys/param.h>
39# include <sys/ucred.h>
40# include <sys/mount.h>
41# include <stdio.h> // For strerror()
42# include <errno.h>
43#endif /* Q_OS_MACX */
44
37#include <qstringlist.h> 45#include <qstringlist.h>
38 46
39#include <sys/vfs.h> 47// Shouldn't be here ! (eilers)
40#include <mntent.h> 48// #include <sys/vfs.h>
49// #include <mntent.h>
41 50
42 51
43static bool isCF(const QString& m) 52static bool isCF(const QString& m)
44{ 53{
54
55#ifndef Q_OS_MACX
45 FILE* f = fopen("/var/run/stab", "r"); 56 FILE* f = fopen("/var/run/stab", "r");
46 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 57 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
47 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 58 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
48 if ( f ) { 59 if ( f ) {
49 char line[1024]; 60 char line[1024];
50 char devtype[80]; 61 char devtype[80];
51 char devname[80]; 62 char devname[80];
52 while ( fgets( line, 1024, f ) ) { 63 while ( fgets( line, 1024, f ) ) {
53 // 0 ide ide-cs 0 hda 3 0 64 // 0 ide ide-cs 0 hda 3 0
54 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 65 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
55 { 66 {
56 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 67 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
57 fclose(f); 68 fclose(f);
58 return TRUE; 69 return TRUE;
59 } 70 }
60 } 71 }
61 } 72 }
62 fclose(f); 73 fclose(f);
63 } 74 }
75#endif /* Q_OS_MACX */
64 return FALSE; 76 return FALSE;
65} 77}
66 78
67/*! \class StorageInfo storage.h 79/*! \class StorageInfo storage.h
68 \brief The StorageInfo class describes the disks mounted on the file system. 80 \brief The StorageInfo class describes the disks mounted on the file system.
69 81
70 This class provides access to the mount information for the Linux 82 This class provides access to the mount information for the Linux
71 filesystem. Each mount point is represented by the FileSystem class. 83 filesystem. Each mount point is represented by the FileSystem class.
72 To ensure this class has the most up to date size information, call 84 To ensure this class has the most up to date size information, call
73 the update() method. Note that this will automatically be signaled 85 the update() method. Note that this will automatically be signaled
74 by the operating system when a disk has been mounted or unmounted. 86 by the operating system when a disk has been mounted or unmounted.
75 87
76 \ingroup qtopiaemb 88 \ingroup qtopiaemb
77*/ 89*/
78 90
79/*! Constructor that determines the current mount points of the filesystem. 91/*! Constructor that determines the current mount points of the filesystem.
80 The standard \a parent parameters is passed on to QObject. 92 The standard \a parent parameters is passed on to QObject.
81 */ 93 */
82StorageInfo::StorageInfo( QObject *parent ) 94StorageInfo::StorageInfo( QObject *parent )
83 : QObject( parent ) 95 : QObject( parent )
84{ 96{
85 mFileSystems.setAutoDelete( TRUE ); 97 mFileSystems.setAutoDelete( TRUE );
86 channel = new QCopChannel( "QPE/Card", this ); 98 channel = new QCopChannel( "QPE/Card", this );
87 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 99 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
88 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 100 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
89 update(); 101 update();
90} 102}
91 103
92/*! Returns the longest matching FileSystem that starts with the 104/*! Returns the longest matching FileSystem that starts with the
93 same prefix as \a filename as its mount point. 105 same prefix as \a filename as its mount point.
94*/ 106*/
95const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 107const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
96{ 108{
97 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 109 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
98 if ( filename.startsWith( (*i)->path() ) ) 110 if ( filename.startsWith( (*i)->path() ) )
99 return (*i); 111 return (*i);
100 } 112 }
101 return 0; 113 return 0;
102} 114}
103 115
104 116
105void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 117void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
106{ 118{
107 if ( msg == "mtabChanged()" ) 119 if ( msg == "mtabChanged()" )
108 update(); 120 update();
109} 121}
110 122
111 123
@@ -159,110 +171,130 @@ void StorageInfo::update()
159 QStringList::ConstIterator fsit=curfs.begin(); 171 QStringList::ConstIterator fsit=curfs.begin();
160 QStringList::ConstIterator optsIt=curopts.begin(); 172 QStringList::ConstIterator optsIt=curopts.begin();
161 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { 173 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
162 QString opts = *optsIt; 174 QString opts = *optsIt;
163 175
164 QString disk = *it; 176 QString disk = *it;
165 QString humanname; 177 QString humanname;
166 bool removable = FALSE; 178 bool removable = FALSE;
167 if ( isCF(disk) ) { 179 if ( isCF(disk) ) {
168 humanname = tr("CF Card"); 180 humanname = tr("CF Card");
169 removable = TRUE; 181 removable = TRUE;
170 } else if ( disk == "/dev/hda1" ) { 182 } else if ( disk == "/dev/hda1" ) {
171 humanname = tr("Hard Disk"); 183 humanname = tr("Hard Disk");
172 } else if ( disk.left(9) == "/dev/mmcd" ) { 184 } else if ( disk.left(9) == "/dev/mmcd" ) {
173 humanname = tr("SD Card"); 185 humanname = tr("SD Card");
174 removable = TRUE; 186 removable = TRUE;
175 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { 187 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) {
176 humanname = tr("MMC Card"); 188 humanname = tr("MMC Card");
177 removable = TRUE; 189 removable = TRUE;
178 } else if ( disk.left(7) == "/dev/hd" ) 190 } else if ( disk.left(7) == "/dev/hd" )
179 humanname = tr("Hard Disk") + " " + disk; 191 humanname = tr("Hard Disk") + " " + disk;
180 else if ( disk.left(7) == "/dev/sd" ) 192 else if ( disk.left(7) == "/dev/sd" )
181 humanname = tr("SCSI Hard Disk") + " " + disk; 193 humanname = tr("SCSI Hard Disk") + " " + disk;
182 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 194 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
183 humanname = tr("Internal Memory"); 195 humanname = tr("Internal Memory");
184 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 196 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
185 humanname = tr("Internal Storage"); 197 humanname = tr("Internal Storage");
186 else if ( disk.left(14) == "/dev/mtdblock/" ) 198 else if ( disk.left(14) == "/dev/mtdblock/" )
187 humanname = tr("Internal Storage") + " " + disk; 199 humanname = tr("Internal Storage") + " " + disk;
188 else if ( disk.left(13) == "/dev/mtdblock" ) 200 else if ( disk.left(13) == "/dev/mtdblock" )
189 humanname = tr("Internal Storage") + " " + disk; 201 humanname = tr("Internal Storage") + " " + disk;
190 else if ( disk.left(9) == "/dev/root" ) 202 else if ( disk.left(9) == "/dev/root" )
191 humanname = tr("Internal Storage") + " " + disk; 203 humanname = tr("Internal Storage") + " " + disk;
192 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 204 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
193 humanname = tr("Internal Memory"); 205 humanname = tr("Internal Memory");
194 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 206 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
195 mFileSystems.append( fs ); 207 mFileSystems.append( fs );
196 } 208 }
197 emit disksChanged(); 209 emit disksChanged();
198 } else { 210 } else {
199 // just update them 211 // just update them
200 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 212 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
201 i.current()->update(); 213 i.current()->update();
202 } 214 }
203#endif 215#endif
204} 216}
205 217
206bool deviceTab( const char *device) { 218bool deviceTab( const char *device) {
207 QString name = device; 219 QString name = device;
208 bool hasDevice=false; 220 bool hasDevice=false;
221
222#ifdef Q_OS_MACX
223 // Darwin (MacOS X)
224 struct statfs** mntbufp;
225 int count = 0;
226 if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 ){
227 qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) );
228 hasDevice = false;
229 }
230 for( int i = 0; i < count; i++ ){
231 QString deviceName = mntbufp[i]->f_mntfromname;
232 qDebug(deviceName);
233 if( deviceName.left( name.length() ) == name )
234 hasDevice = true;
235 }
236#else
237 // Linux
209 struct mntent *me; 238 struct mntent *me;
210 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 239 FILE *mntfp = setmntent( "/etc/mtab", "r" );
211 if ( mntfp ) { 240 if ( mntfp ) {
212 while ( (me = getmntent( mntfp )) != 0 ) { 241 while ( (me = getmntent( mntfp )) != 0 ) {
213 QString deviceName = me->mnt_fsname; 242 QString deviceName = me->mnt_fsname;
214// qDebug(deviceName); 243// qDebug(deviceName);
215 if( deviceName.left(name.length()) == name) { 244 if( deviceName.left(name.length()) == name) {
216 hasDevice = true; 245 hasDevice = true;
217 } 246 }
218 } 247 }
219 } 248 }
220 endmntent( mntfp ); 249 endmntent( mntfp );
250#endif /* Q_OS_MACX */
251
252
221 return hasDevice; 253 return hasDevice;
222} 254}
223 255
224/*! 256/*!
225 * @fn static bool StorageInfo::hasCf() 257 * @fn static bool StorageInfo::hasCf()
226 * @brief returns whether device has Cf mounted 258 * @brief returns whether device has Cf mounted
227 * 259 *
228 */ 260 */
229bool StorageInfo::hasCf() 261bool StorageInfo::hasCf()
230{ 262{
231 return deviceTab("/dev/hd"); 263 return deviceTab("/dev/hd");
232} 264}
233 265
234/*! 266/*!
235 * @fn static bool StorageInfo::hasSd() 267 * @fn static bool StorageInfo::hasSd()
236 * @brief returns whether device has SD mounted 268 * @brief returns whether device has SD mounted
237 * 269 *
238 */ 270 */
239bool StorageInfo::hasSd() 271bool StorageInfo::hasSd()
240{ 272{
241 return deviceTab("/dev/mmcd"); 273 return deviceTab("/dev/mmcd");
242} 274}
243 275
244/*! 276/*!
245 * @fn static bool StorageInfo::hasMmc() 277 * @fn static bool StorageInfo::hasMmc()
246 * @brief reutrns whether device has mmc mounted 278 * @brief reutrns whether device has mmc mounted
247 * 279 *
248 */ 280 */
249bool StorageInfo::hasMmc() 281bool StorageInfo::hasMmc()
250{ 282{
251 bool hasMmc=false; 283 bool hasMmc=false;
252 if( deviceTab("/dev/mmc/part")) 284 if( deviceTab("/dev/mmc/part"))
253 hasMmc=true; 285 hasMmc=true;
254 if( deviceTab("/dev/mmcd")) 286 if( deviceTab("/dev/mmcd"))
255 hasMmc=true; 287 hasMmc=true;
256 return hasMmc; 288 return hasMmc;
257} 289}
258 290
259/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const 291/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const
260 Returns a list of all available mounted file systems. 292 Returns a list of all available mounted file systems.
261 293
262 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) 294 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp)
263*/ 295*/
264 296
265/*! \fn void StorageInfo::disksChanged() 297/*! \fn void StorageInfo::disksChanged()
266 Gets emitted when a disk has been mounted or unmounted, such as when 298 Gets emitted when a disk has been mounted or unmounted, such as when
267 a CF c 299 a CF c
268*/ 300*/