summaryrefslogtreecommitdiff
path: root/library/storage.cpp
Unidiff
Diffstat (limited to 'library/storage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp2
1 files changed, 0 insertions, 2 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index 1ce43bc..dc5cc22 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,218 +1,216 @@
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#if defined(QT_QWS_SL5XXX)
25#include <qpe/custom.h> 24#include <qpe/custom.h>
26#endif
27 25
28#include <qfile.h> 26#include <qfile.h>
29#include <qtimer.h> 27#include <qtimer.h>
30#include <qcopchannel_qws.h> 28#include <qcopchannel_qws.h>
31 29
32#include <stdio.h> 30#include <stdio.h>
33 31
34#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 32#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
35#include <sys/vfs.h> 33#include <sys/vfs.h>
36#include <mntent.h> 34#include <mntent.h>
37#endif 35#endif
38 36
39#include <qstringlist.h> 37#include <qstringlist.h>
40 38
41#include <sys/vfs.h> 39#include <sys/vfs.h>
42#include <mntent.h> 40#include <mntent.h>
43 41
44 42
45static bool isCF(const QString& m) 43static bool isCF(const QString& m)
46{ 44{
47 FILE* f = fopen("/var/run/stab", "r"); 45 FILE* f = fopen("/var/run/stab", "r");
48 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 46 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
49 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 47 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
50 if ( f ) { 48 if ( f ) {
51 char line[1024]; 49 char line[1024];
52 char devtype[80]; 50 char devtype[80];
53 char devname[80]; 51 char devname[80];
54 while ( fgets( line, 1024, f ) ) { 52 while ( fgets( line, 1024, f ) ) {
55 // 0 ide ide-cs 0 hda 3 0 53 // 0 ide ide-cs 0 hda 3 0
56 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 54 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
57 { 55 {
58 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 56 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
59 fclose(f); 57 fclose(f);
60 return TRUE; 58 return TRUE;
61 } 59 }
62 } 60 }
63 } 61 }
64 fclose(f); 62 fclose(f);
65 } 63 }
66 return FALSE; 64 return FALSE;
67} 65}
68 66
69/*! \class StorageInfo storage.h 67/*! \class StorageInfo storage.h
70 \brief The StorageInfo class describes the disks mounted on the file system. 68 \brief The StorageInfo class describes the disks mounted on the file system.
71 69
72 This class provides access to the mount information for the Linux 70 This class provides access to the mount information for the Linux
73 filesystem. Each mount point is represented by the FileSystem class. 71 filesystem. Each mount point is represented by the FileSystem class.
74 To ensure this class has the most up to date size information, call 72 To ensure this class has the most up to date size information, call
75 the update() method. Note that this will automatically be signaled 73 the update() method. Note that this will automatically be signaled
76 by the operating system when a disk has been mounted or unmounted. 74 by the operating system when a disk has been mounted or unmounted.
77 75
78 \ingroup qtopiaemb 76 \ingroup qtopiaemb
79*/ 77*/
80 78
81/*! Constructor that determines the current mount points of the filesystem. 79/*! Constructor that determines the current mount points of the filesystem.
82 The standard \a parent parameters is passed on to QObject. 80 The standard \a parent parameters is passed on to QObject.
83 */ 81 */
84StorageInfo::StorageInfo( QObject *parent ) 82StorageInfo::StorageInfo( QObject *parent )
85 : QObject( parent ) 83 : QObject( parent )
86{ 84{
87 mFileSystems.setAutoDelete( TRUE ); 85 mFileSystems.setAutoDelete( TRUE );
88 channel = new QCopChannel( "QPE/Card", this ); 86 channel = new QCopChannel( "QPE/Card", this );
89 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 87 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
90 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 88 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
91 update(); 89 update();
92} 90}
93 91
94/*! Returns the longest matching FileSystem that starts with the 92/*! Returns the longest matching FileSystem that starts with the
95 same prefix as \a filename as its mount point. 93 same prefix as \a filename as its mount point.
96*/ 94*/
97const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 95const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
98{ 96{
99 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 97 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
100 if ( filename.startsWith( (*i)->path() ) ) 98 if ( filename.startsWith( (*i)->path() ) )
101 return (*i); 99 return (*i);
102 } 100 }
103 return 0; 101 return 0;
104} 102}
105 103
106 104
107void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 105void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
108{ 106{
109 if ( msg == "mtabChanged()" ) 107 if ( msg == "mtabChanged()" )
110 update(); 108 update();
111} 109}
112 110
113 111
114/*! Updates the mount and free space available information for each mount 112/*! Updates the mount and free space available information for each mount
115 point. This method is automatically called when a disk is mounted or 113 point. This method is automatically called when a disk is mounted or
116 unmounted. 114 unmounted.
117*/ 115*/
118// cause of the lack of a d pointer we need 116// cause of the lack of a d pointer we need
119// to store informations in a config file :( 117// to store informations in a config file :(
120void StorageInfo::update() 118void StorageInfo::update()
121{ 119{
122 //qDebug("StorageInfo::updating"); 120 //qDebug("StorageInfo::updating");
123#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 121#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
124 struct mntent *me; 122 struct mntent *me;
125 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 123 FILE *mntfp = setmntent( "/etc/mtab", "r" );
126 124
127 QStringList curdisks; 125 QStringList curdisks;
128 QStringList curopts; 126 QStringList curopts;
129 QStringList curfs; 127 QStringList curfs;
130 bool rebuild = FALSE; 128 bool rebuild = FALSE;
131 int n=0; 129 int n=0;
132 if ( mntfp ) { 130 if ( mntfp ) {
133 while ( (me = getmntent( mntfp )) != 0 ) { 131 while ( (me = getmntent( mntfp )) != 0 ) {
134 QString fs = me->mnt_fsname; 132 QString fs = me->mnt_fsname;
135 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 133 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
136 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 134 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
137 || fs.left( 14 ) == "/dev/mmc/part1" 135 || fs.left( 14 ) == "/dev/mmc/part1"
138 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) 136 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
139 { 137 {
140 n++; 138 n++;
141 curdisks.append(fs); 139 curdisks.append(fs);
142 curopts.append( me->mnt_opts ); 140 curopts.append( me->mnt_opts );
143 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 141 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
144 curfs.append( me->mnt_dir ); 142 curfs.append( me->mnt_dir );
145 bool found = FALSE; 143 bool found = FALSE;
146 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 144 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
147 if ( (*i)->disk() == fs ) { 145 if ( (*i)->disk() == fs ) {
148 found = TRUE; 146 found = TRUE;
149 break; 147 break;
150 } 148 }
151 } 149 }
152 if ( !found ) 150 if ( !found )
153 rebuild = TRUE; 151 rebuild = TRUE;
154 } 152 }
155 } 153 }
156 endmntent( mntfp ); 154 endmntent( mntfp );
157 } 155 }
158 if ( rebuild || n != (int)mFileSystems.count() ) { 156 if ( rebuild || n != (int)mFileSystems.count() ) {
159 mFileSystems.clear(); 157 mFileSystems.clear();
160 QStringList::ConstIterator it=curdisks.begin(); 158 QStringList::ConstIterator it=curdisks.begin();
161 QStringList::ConstIterator fsit=curfs.begin(); 159 QStringList::ConstIterator fsit=curfs.begin();
162 QStringList::ConstIterator optsIt=curopts.begin(); 160 QStringList::ConstIterator optsIt=curopts.begin();
163 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { 161 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
164 QString opts = *optsIt; 162 QString opts = *optsIt;
165 163
166 QString disk = *it; 164 QString disk = *it;
167 QString humanname; 165 QString humanname;
168 bool removable = FALSE; 166 bool removable = FALSE;
169 if ( isCF(disk) ) { 167 if ( isCF(disk) ) {
170 humanname = tr("CF Card"); 168 humanname = tr("CF Card");
171 removable = TRUE; 169 removable = TRUE;
172 } else if ( disk == "/dev/hda1" ) { 170 } else if ( disk == "/dev/hda1" ) {
173 humanname = tr("Hard Disk"); 171 humanname = tr("Hard Disk");
174 } else if ( disk.left(9) == "/dev/mmcd" ) { 172 } else if ( disk.left(9) == "/dev/mmcd" ) {
175 humanname = tr("SD Card"); 173 humanname = tr("SD Card");
176 removable = TRUE; 174 removable = TRUE;
177 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { 175 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) {
178 humanname = tr("MMC Card"); 176 humanname = tr("MMC Card");
179 removable = TRUE; 177 removable = TRUE;
180 } else if ( disk.left(7) == "/dev/hd" ) 178 } else if ( disk.left(7) == "/dev/hd" )
181 humanname = tr("Hard Disk") + " " + disk; 179 humanname = tr("Hard Disk") + " " + disk;
182 else if ( disk.left(7) == "/dev/sd" ) 180 else if ( disk.left(7) == "/dev/sd" )
183 humanname = tr("SCSI Hard Disk") + " " + disk; 181 humanname = tr("SCSI Hard Disk") + " " + disk;
184 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 182 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
185 humanname = tr("Internal Memory"); 183 humanname = tr("Internal Memory");
186 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 184 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
187 humanname = tr("Internal Storage"); 185 humanname = tr("Internal Storage");
188 else if ( disk.left(14) == "/dev/mtdblock/" ) 186 else if ( disk.left(14) == "/dev/mtdblock/" )
189 humanname = tr("Internal Storage") + " " + disk; 187 humanname = tr("Internal Storage") + " " + disk;
190 else if ( disk.left(13) == "/dev/mtdblock" ) 188 else if ( disk.left(13) == "/dev/mtdblock" )
191 humanname = tr("Internal Storage") + " " + disk; 189 humanname = tr("Internal Storage") + " " + disk;
192 else if ( disk.left(9) == "/dev/root" ) 190 else if ( disk.left(9) == "/dev/root" )
193 humanname = tr("Internal Storage") + " " + disk; 191 humanname = tr("Internal Storage") + " " + disk;
194 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 192 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
195 humanname = tr("Internal Memory"); 193 humanname = tr("Internal Memory");
196 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 194 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
197 mFileSystems.append( fs ); 195 mFileSystems.append( fs );
198 } 196 }
199 emit disksChanged(); 197 emit disksChanged();
200 } else { 198 } else {
201 // just update them 199 // just update them
202 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 200 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
203 i.current()->update(); 201 i.current()->update();
204 } 202 }
205#endif 203#endif
206} 204}
207 205
208bool deviceTab( const char *device) { 206bool deviceTab( const char *device) {
209 QString name = device; 207 QString name = device;
210 bool hasDevice=false; 208 bool hasDevice=false;
211 struct mntent *me; 209 struct mntent *me;
212 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 210 FILE *mntfp = setmntent( "/etc/mtab", "r" );
213 if ( mntfp ) { 211 if ( mntfp ) {
214 while ( (me = getmntent( mntfp )) != 0 ) { 212 while ( (me = getmntent( mntfp )) != 0 ) {
215 QString deviceName = me->mnt_fsname; 213 QString deviceName = me->mnt_fsname;
216// qDebug(deviceName); 214// qDebug(deviceName);
217 if( deviceName.left(name.length()) == name) { 215 if( deviceName.left(name.length()) == name) {
218 hasDevice = true; 216 hasDevice = true;