summaryrefslogtreecommitdiff
authorar <ar>2004-01-07 20:22:49 (UTC)
committer ar <ar>2004-01-07 20:22:49 (UTC)
commitdd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8 (patch) (unidiff)
tree92c625add3c9d24e65c1550bc5449420a85342ce
parent24a62e8789083f446138aebfa11409b73886aa88 (diff)
downloadopie-dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8.zip
opie-dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8.tar.gz
opie-dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8.tar.bz2
new functions getCfPath, getSdPath, getMmcPath returns mountpoints
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp343
-rw-r--r--library/storage.h14
2 files changed, 225 insertions, 132 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index f8b75d0..657fb71 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,376 +1,465 @@
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 37#ifdef Q_OS_MACX
38# include <sys/param.h> 38# include <sys/param.h>
39# include <sys/ucred.h> 39# include <sys/ucred.h>
40# include <sys/mount.h> 40# include <sys/mount.h>
41# include <stdio.h> // For strerror() 41# include <stdio.h> // For strerror()
42# include <errno.h> 42# include <errno.h>
43#endif /* Q_OS_MACX */ 43#endif /* Q_OS_MACX */
44 44
45#include <qstringlist.h> 45#include <qstringlist.h>
46 46
47// Shouldn't be here ! (eilers) 47// Shouldn't be here ! (eilers)
48// #include <sys/vfs.h> 48// #include <sys/vfs.h>
49// #include <mntent.h> 49// #include <mntent.h>
50 50
51 51
52static bool isCF(const QString& m) 52static bool isCF(const QString& m)
53{ 53{
54 54
55#ifndef Q_OS_MACX 55#ifndef Q_OS_MACX
56 FILE* f = fopen("/var/run/stab", "r"); 56 FILE* f = fopen("/var/run/stab", "r");
57 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 57 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
58 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 58 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
59 if ( f ) { 59 if ( f )
60 {
60 char line[1024]; 61 char line[1024];
61 char devtype[80]; 62 char devtype[80];
62 char devname[80]; 63 char devname[80];
63 while ( fgets( line, 1024, f ) ) { 64 while ( fgets( line, 1024, f ) )
64 // 0 ide ide-cs 0 hda 3 0 65 {
66 // 0 ide ide-cs 0 hda 3 0
65 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 67 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
66 { 68 {
67 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 69 if ( QString(devtype) == "ide" && m.find(devname)>0 )
68 fclose(f); 70 {
69 return TRUE; 71 fclose(f);
70 } 72 return TRUE;
71 } 73 }
74 }
72 } 75 }
73 fclose(f); 76 fclose(f);
74 } 77 }
75#endif /* Q_OS_MACX */ 78#endif /* Q_OS_MACX */
76 return FALSE; 79 return FALSE;
77} 80}
78 81
79/*! \class StorageInfo storage.h 82/*! \class StorageInfo storage.h
80 \brief The StorageInfo class describes the disks mounted on the file system. 83 \brief The StorageInfo class describes the disks mounted on the file system.
81 84
82 This class provides access to the mount information for the Linux 85 This class provides access to the mount information for the Linux
83 filesystem. Each mount point is represented by the FileSystem class. 86 filesystem. Each mount point is represented by the FileSystem class.
84 To ensure this class has the most up to date size information, call 87 To ensure this class has the most up to date size information, call
85 the update() method. Note that this will automatically be signaled 88 the update() method. Note that this will automatically be signaled
86 by the operating system when a disk has been mounted or unmounted. 89 by the operating system when a disk has been mounted or unmounted.
87 90
88 \ingroup qtopiaemb 91 \ingroup qtopiaemb
89*/ 92*/
90 93
91/*! Constructor that determines the current mount points of the filesystem. 94/*! Constructor that determines the current mount points of the filesystem.
92 The standard \a parent parameters is passed on to QObject. 95 The standard \a parent parameters is passed on to QObject.
93 */ 96 */
94StorageInfo::StorageInfo( QObject *parent ) 97StorageInfo::StorageInfo( QObject *parent )
95 : QObject( parent ) 98 : QObject( parent )
96{ 99{
97 mFileSystems.setAutoDelete( TRUE ); 100 mFileSystems.setAutoDelete( TRUE );
98 channel = new QCopChannel( "QPE/Card", this ); 101 channel = new QCopChannel( "QPE/Card", this );
99 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 102 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
100 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 103 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
101 update(); 104 update();
102} 105}
103 106
104/*! Returns the longest matching FileSystem that starts with the 107/*! Returns the longest matching FileSystem that starts with the
105 same prefix as \a filename as its mount point. 108 same prefix as \a filename as its mount point.
106*/ 109*/
107const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 110const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
108{ 111{
109 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 112 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
110 if ( filename.startsWith( (*i)->path() ) ) 113 {
111 return (*i); 114 if ( filename.startsWith( (*i)->path() ) )
115 return (*i);
112 } 116 }
113 return 0; 117 return 0;
114} 118}
115 119
116 120
117void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 121void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
118{ 122{
119 if ( msg == "mtabChanged()" ) 123 if ( msg == "mtabChanged()" )
120 update(); 124 update();
121} 125}
122 126
123 127
124/*! Updates the mount and free space available information for each mount 128/*! Updates the mount and free space available information for each mount
125 point. This method is automatically called when a disk is mounted or 129 point. This method is automatically called when a disk is mounted or
126 unmounted. 130 unmounted.
127*/ 131*/
128// cause of the lack of a d pointer we need 132// cause of the lack of a d pointer we need
129// to store informations in a config file :( 133// to store informations in a config file :(
130void StorageInfo::update() 134void StorageInfo::update()
131{ 135{
132 //qDebug("StorageInfo::updating"); 136 //qDebug("StorageInfo::updating");
133#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 137#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
134 struct mntent *me; 138 struct mntent *me;
135 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 139 FILE *mntfp = setmntent( "/etc/mtab", "r" );
136 140
137 QStringList curdisks; 141 QStringList curdisks;
138 QStringList curopts; 142 QStringList curopts;
139 QStringList curfs; 143 QStringList curfs;
140 bool rebuild = FALSE; 144 bool rebuild = FALSE;
141 int n=0; 145 int n=0;
142 if ( mntfp ) { 146 if ( mntfp )
143 while ( (me = getmntent( mntfp )) != 0 ) { 147 {
144 QString fs = me->mnt_fsname; 148 while ( (me = getmntent( mntfp )) != 0 )
145 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 149 {
146 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 150 QString fs = me->mnt_fsname;
147 || fs.left( 14 ) == "/dev/mmc/part1" 151 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
148 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) 152 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
149 { 153 || fs.left( 14 ) == "/dev/mmc/part1"
150 n++; 154 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
151 curdisks.append(fs); 155 {
152 curopts.append( me->mnt_opts ); 156 n++;
153 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 157 curdisks.append(fs);
154 curfs.append( me->mnt_dir ); 158 curopts.append( me->mnt_opts );
155 bool found = FALSE; 159 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
156 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 160 curfs.append( me->mnt_dir );
157 if ( (*i)->disk() == fs ) { 161 bool found = FALSE;
158 found = TRUE; 162 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
159 break; 163 {
164 if ( (*i)->disk() == fs )
165 {
166 found = TRUE;
167 break;
168 }
169 }
170 if ( !found )
171 rebuild = TRUE;
172 }
160 } 173 }
174 endmntent( mntfp );
161 } 175 }
162 if ( !found ) 176 if ( rebuild || n != (int)mFileSystems.count() )
163 rebuild = TRUE; 177 {
164 } 178 mFileSystems.clear();
165 } 179 QStringList::ConstIterator it=curdisks.begin();
166 endmntent( mntfp ); 180 QStringList::ConstIterator fsit=curfs.begin();
181 QStringList::ConstIterator optsIt=curopts.begin();
182 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt)
183 {
184 QString opts = *optsIt;
185
186 QString disk = *it;
187 QString humanname;
188 bool removable = FALSE;
189 if ( isCF(disk) )
190 {
191 humanname = tr("CF Card");
192 removable = TRUE;
193 }
194 else if ( disk == "/dev/hda1" )
195 {
196 humanname = tr("Hard Disk");
197 }
198 else if ( disk.left(9) == "/dev/mmcd" )
199 {
200 humanname = tr("SD Card");
201 removable = TRUE;
202 }
203 else if ( disk.left( 14 ) == "/dev/mmc/part1" )
204 {
205 humanname = tr("MMC Card");
206 removable = TRUE;
207 }
208 else if ( disk.left(7) == "/dev/hd" )
209 humanname = tr("Hard Disk") + " " + disk;
210 else if ( disk.left(7) == "/dev/sd" )
211 humanname = tr("SCSI Hard Disk") + " " + disk;
212 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
213 humanname = tr("Internal Memory");
214 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
215 humanname = tr("Internal Storage");
216 else if ( disk.left(14) == "/dev/mtdblock/" )
217 humanname = tr("Internal Storage") + " " + disk;
218 else if ( disk.left(13) == "/dev/mtdblock" )
219 humanname = tr("Internal Storage") + " " + disk;
220 else if ( disk.left(9) == "/dev/root" )
221 humanname = tr("Internal Storage") + " " + disk;
222 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
223 humanname = tr("Internal Memory");
224 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
225 mFileSystems.append( fs );
226 }
227 emit disksChanged();
167 } 228 }
168 if ( rebuild || n != (int)mFileSystems.count() ) { 229 else
169 mFileSystems.clear(); 230 {
170 QStringList::ConstIterator it=curdisks.begin(); 231 // just update them
171 QStringList::ConstIterator fsit=curfs.begin(); 232 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
172 QStringList::ConstIterator optsIt=curopts.begin(); 233 i.current()->update();
173 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
174 QString opts = *optsIt;
175
176 QString disk = *it;
177 QString humanname;
178 bool removable = FALSE;
179 if ( isCF(disk) ) {
180 humanname = tr("CF Card");
181 removable = TRUE;
182 } else if ( disk == "/dev/hda1" ) {
183 humanname = tr("Hard Disk");
184 } else if ( disk.left(9) == "/dev/mmcd" ) {
185 humanname = tr("SD Card");
186 removable = TRUE;
187 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) {
188 humanname = tr("MMC Card");
189 removable = TRUE;
190 } else if ( disk.left(7) == "/dev/hd" )
191 humanname = tr("Hard Disk") + " " + disk;
192 else if ( disk.left(7) == "/dev/sd" )
193 humanname = tr("SCSI Hard Disk") + " " + disk;
194 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
195 humanname = tr("Internal Memory");
196 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
197 humanname = tr("Internal Storage");
198 else if ( disk.left(14) == "/dev/mtdblock/" )
199 humanname = tr("Internal Storage") + " " + disk;
200 else if ( disk.left(13) == "/dev/mtdblock" )
201 humanname = tr("Internal Storage") + " " + disk;
202 else if ( disk.left(9) == "/dev/root" )
203 humanname = tr("Internal Storage") + " " + disk;
204 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
205 humanname = tr("Internal Memory");
206 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
207 mFileSystems.append( fs );
208 }
209 emit disksChanged();
210 } else {
211 // just update them
212 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
213 i.current()->update();
214 } 234 }
215#endif 235#endif
216} 236}
217 237
218bool deviceTab( const char *device) { 238bool deviceTab( const char *device)
219 QString name = device; 239{
220 bool hasDevice=false; 240 QString name = device;
241 bool hasDevice=false;
221 242
222#ifdef Q_OS_MACX 243#ifdef Q_OS_MACX
223 // Darwin (MacOS X) 244 // Darwin (MacOS X)
224 struct statfs** mntbufp; 245 struct statfs** mntbufp;
225 int count = 0; 246 int count = 0;
226 if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 ){ 247 if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 )
227 qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) ); 248 {
228 hasDevice = false; 249 qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) );
229 } 250 hasDevice = false;
230 for( int i = 0; i < count; i++ ){ 251 }
231 QString deviceName = mntbufp[i]->f_mntfromname; 252 for( int i = 0; i < count; i++ )
232 qDebug(deviceName); 253 {
233 if( deviceName.left( name.length() ) == name ) 254 QString deviceName = mntbufp[i]->f_mntfromname;
234 hasDevice = true; 255 qDebug(deviceName);
235 } 256 if( deviceName.left( name.length() ) == name )
257 hasDevice = true;
258 }
236#else 259#else
237 // Linux 260 // Linux
238 struct mntent *me; 261 struct mntent *me;
239 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 262 FILE *mntfp = setmntent( "/etc/mtab", "r" );
240 if ( mntfp ) { 263 if ( mntfp )
241 while ( (me = getmntent( mntfp )) != 0 ) { 264 {
242 QString deviceName = me->mnt_fsname; 265 while ( (me = getmntent( mntfp )) != 0 )
243// qDebug(deviceName); 266 {
244 if( deviceName.left(name.length()) == name) { 267 QString deviceName = me->mnt_fsname;
245 hasDevice = true; 268 // qDebug(deviceName);
269 if( deviceName.left(name.length()) == name)
270 {
271 hasDevice = true;
246 } 272 }
247 } 273 }
248 } 274 }
249 endmntent( mntfp ); 275 endmntent( mntfp );
250#endif /* Q_OS_MACX */ 276#endif /* Q_OS_MACX */
251 277
252 278
253 return hasDevice; 279 return hasDevice;
254} 280}
255 281
256/*! 282/*!
257 * @fn static bool StorageInfo::hasCf() 283 * @fn static bool StorageInfo::hasCf()
258 * @brief returns whether device has Cf mounted 284 * @brief returns whether device has Cf mounted
259 * 285 *
260 */ 286 */
261bool StorageInfo::hasCf() 287bool StorageInfo::hasCf()
262{ 288{
263 return deviceTab("/dev/hd"); 289 return deviceTab("/dev/hd");
264} 290}
265 291
266/*! 292/*!
267 * @fn static bool StorageInfo::hasSd() 293 * @fn static bool StorageInfo::hasSd()
268 * @brief returns whether device has SD mounted 294 * @brief returns whether device has SD mounted
269 * 295 *
270 */ 296 */
271bool StorageInfo::hasSd() 297bool StorageInfo::hasSd()
272{ 298{
273 return deviceTab("/dev/mmcd"); 299 return deviceTab("/dev/mmcd");
274} 300}
275 301
276/*! 302/*!
277 * @fn static bool StorageInfo::hasMmc() 303 * @fn static bool StorageInfo::hasMmc()
278 * @brief reutrns whether device has mmc mounted 304 * @brief returns whether device has mmc mounted
279 * 305 *
280 */ 306 */
281bool StorageInfo::hasMmc() 307bool StorageInfo::hasMmc()
282{ 308{
283 bool hasMmc=false; 309 bool hasMmc=false;
284 if( deviceTab("/dev/mmc/part")) 310 if( deviceTab("/dev/mmc/part"))
285 hasMmc=true; 311 hasMmc=true;
286 if( deviceTab("/dev/mmcd")) 312 if( deviceTab("/dev/mmcd"))
287 hasMmc=true; 313 hasMmc=true;
288 return hasMmc; 314 return hasMmc;
315}
316
317/*!
318* @fn QString StorageInfo::getCfPath()
319* @brief returns the Mount-Path of Cf Card
320*
321*/
322QString StorageInfo::getCfPath()
323{
324 QString r = "";
325
326 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
327 {
328 if ( (*i)->disk().left( 8 ) == "/dev/hda" )
329 {
330 r = (*i)->path();
331 break;
332 }
333 }
334 return r;
335}
336
337/*!
338* @fn QString StorageInfo::getSdPath()
339* @brief returns the Mount-Path of Sd Card
340*
341*/
342QString StorageInfo::getSdPath()
343{
344 QString r = "";
345
346 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
347 {
348 if ( (*i)->disk().left( 9 ) == "/dev/mmcd" )
349 {
350 r = (*i)->path();
351 break;
352 }
353 }
354 return r;
355}
356
357/*!
358* @fn QString StorageInfo::getMmcPath()
359* @brief returns the Mount-Path of Mmc Card
360*
361*/
362QString StorageInfo::getMmcPath()
363{
364 QString r = "";
365
366 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
367 {
368 if ( (*i)->disk().left( 14 ) == "/dev/mmc/part1" )
369 {
370 r = (*i)->path();
371 break;
372 }
373 }
374 return r;
289} 375}
290 376
291/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const 377/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const
292 Returns a list of all available mounted file systems. 378 Returns a list of all available mounted file systems.
293 379
294 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) 380 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp)
295*/ 381*/
296 382
297/*! \fn void StorageInfo::disksChanged() 383/*! \fn void StorageInfo::disksChanged()
298 Gets emitted when a disk has been mounted or unmounted, such as when 384 Gets emitted when a disk has been mounted or unmounted, such as when
299 a CF c 385 a CF c
300*/ 386*/
301//--------------------------------------------------------------------------- 387//---------------------------------------------------------------------------
302 388
303FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) 389FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
304 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) 390 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
305{ 391{
306 update(); 392 update();
307} 393}
308 394
309void FileSystem::update() 395void FileSystem::update()
310{ 396{
311#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 397#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
312 struct statfs fs; 398 struct statfs fs;
313 if ( !statfs( fspath.latin1(), &fs ) ) { 399 if ( !statfs( fspath.latin1(), &fs ) )
314 blkSize = fs.f_bsize; 400 {
315 totalBlks = fs.f_blocks; 401 blkSize = fs.f_bsize;
316 availBlks = fs.f_bavail; 402 totalBlks = fs.f_blocks;
317 } else { 403 availBlks = fs.f_bavail;
318 blkSize = 0; 404 }
319 totalBlks = 0; 405 else
320 availBlks = 0; 406 {
407 blkSize = 0;
408 totalBlks = 0;
409 availBlks = 0;
321 } 410 }
322#endif 411#endif
323} 412}
324 413
325/*! \class FileSystem storage.h 414/*! \class FileSystem storage.h
326 \brief The FileSystem class describes a single mount point. 415 \brief The FileSystem class describes a single mount point.
327 416
328 This class simply returns information about a mount point, including 417 This class simply returns information about a mount point, including
329 file system name, mount point, human readable name, size information 418 file system name, mount point, human readable name, size information
330 and mount options information. 419 and mount options information.
331 \ingroup qtopiaemb 420 \ingroup qtopiaemb
332 421
333 \sa StorageInfo 422 \sa StorageInfo
334*/ 423*/
335 424
336/*! \fn const QString &FileSystem::disk() const 425/*! \fn const QString &FileSystem::disk() const
337 Returns the file system name, such as /dev/hda3 426 Returns the file system name, such as /dev/hda3
338*/ 427*/
339 428
340/*! \fn const QString &FileSystem::path() const 429/*! \fn const QString &FileSystem::path() const
341 Returns the mount path, such as /home 430 Returns the mount path, such as /home
342*/ 431*/
343 432
344/*! \fn const QString &FileSystem::name() const 433/*! \fn const QString &FileSystem::name() const
345 Returns the translated, human readable name for the mount directory. 434 Returns the translated, human readable name for the mount directory.
346*/ 435*/
347 436
348/*! \fn const QString &FileSystem::options() const 437/*! \fn const QString &FileSystem::options() const
349 Returns the mount options 438 Returns the mount options
350*/ 439*/
351 440
352/*! \fn long FileSystem::blockSize() const 441/*! \fn long FileSystem::blockSize() const
353 Returns the size of each block on the file system. 442 Returns the size of each block on the file system.
354*/ 443*/
355 444
356/*! \fn long FileSystem::totalBlocks() const 445/*! \fn long FileSystem::totalBlocks() const
357 Returns the total number of blocks on the file system 446 Returns the total number of blocks on the file system
358*/ 447*/
359 448
360/*! \fn long FileSystem::availBlocks() const 449/*! \fn long FileSystem::availBlocks() const
361 Returns the number of available blocks on the file system 450 Returns the number of available blocks on the file system
362 */ 451 */
363 452
364/*! \fn bool FileSystem::isRemovable() const 453/*! \fn bool FileSystem::isRemovable() const
365 Returns flag whether the file system can be removed, such as a CF card 454 Returns flag whether the file system can be removed, such as a CF card
366 would be removable, but the internal memory wouldn't 455 would be removable, but the internal memory wouldn't
367*/ 456*/
368 457
369/*! \fn bool FileSystem::isWritable() const 458/*! \fn bool FileSystem::isWritable() const
370 Returns flag whether the file system is mounted as writable or read-only. 459 Returns flag whether the file system is mounted as writable or read-only.
371 Returns FALSE if read-only, TRUE if read and write. 460 Returns FALSE if read-only, TRUE if read and write.
372*/ 461*/
373 462
374/*! \fn QStringList StorageInfo::fileSystemNames() const 463/*! \fn QStringList StorageInfo::fileSystemNames() const
375 Returns a list of filesystem names. 464 Returns a list of filesystem names.
376*/ 465*/
diff --git a/library/storage.h b/library/storage.h
index 0a0698f..35a1109 100644
--- a/library/storage.h
+++ b/library/storage.h
@@ -1,82 +1,86 @@
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 static bool hasCf(); 37 static bool hasCf();
38 static bool hasSd(); 38 static bool hasSd();
39 static bool hasMmc(); 39 static bool hasMmc();
40
41 QString getCfPath();
42 QString getSdPath();
43 QString getMmcPath();
40signals: 44signals:
41 void disksChanged(); 45 void disksChanged();
42 46
43public slots: 47public slots:
44 void update(); 48 void update();
45 49
46private slots: 50private slots:
47 void cardMessage( const QCString& msg, const QByteArray& data ); 51 void cardMessage( const QCString& msg, const QByteArray& data );
48private: 52private:
49 QList<FileSystem> mFileSystems; 53 QList<FileSystem> mFileSystems;
50 QCopChannel *channel; 54 QCopChannel *channel;
51}; 55};
52 56
53class FileSystem 57class FileSystem
54{ 58{
55public: 59public:
56 const QString &disk() const { return fsdisk; } 60 const QString &disk() const { return fsdisk; }
57 const QString &path() const { return fspath; } 61 const QString &path() const { return fspath; }
58 const QString &name() const { return humanname; } 62 const QString &name() const { return humanname; }
59 const QString &options() const { return opts; } 63 const QString &options() const { return opts; }
60 long blockSize() const { return blkSize; } 64 long blockSize() const { return blkSize; }
61 long totalBlocks() const { return totalBlks; } 65 long totalBlocks() const { return totalBlks; }
62 long availBlocks() const { return availBlks; } 66 long availBlocks() const { return availBlks; }
63 bool isRemovable() const { return removable; } 67 bool isRemovable() const { return removable; }
64 bool isWritable() const { return opts.contains("rw"); } 68 bool isWritable() const { return opts.contains("rw"); }
65 69
66private: 70private:
67 friend class StorageInfo; 71 friend class StorageInfo;
68 FileSystem( const QString &disk, const QString &path, const QString &humanname, bool rem, const QString &opts ); 72 FileSystem( const QString &disk, const QString &path, const QString &humanname, bool rem, const QString &opts );
69 void update(); 73 void update();
70 74
71 QString fsdisk; 75 QString fsdisk;
72 QString fspath; 76 QString fspath;
73 QString humanname; 77 QString humanname;
74 long blkSize; 78 long blkSize;
75 long totalBlks; 79 long totalBlks;
76 long availBlks; 80 long availBlks;
77 bool removable; 81 bool removable;
78 QString opts; 82 QString opts;
79}; 83};
80 84
81 85
82#endif 86#endif