summaryrefslogtreecommitdiff
path: root/library/storage.cpp
Unidiff
Diffstat (limited to 'library/storage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index f4c1c02..12f9df9 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -107,155 +107,155 @@ void StorageInfo::update()
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" || fs.left(9)=="/dev/root" ) 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" ) 168 else if ( disk.left(9) == "/dev/root" )
169 humanname = tr("Internal Storage") + " " + disk; 169 humanname = tr("Internal Storage") + " " + disk;
170 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 170 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
171 humanname = tr("Internal Memory"); 171 humanname = tr("Internal Memory");
172 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 172 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
173 mFileSystems.append( fs ); 173 mFileSystems.append( fs );
174 } 174 }
175 emit disksChanged(); 175 emit disksChanged();
176 } else { 176 } else {
177 // just update them 177 // just update them
178 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 178 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
179 i.current()->update(); 179 i.current()->update();
180 } 180 }
181#endif 181#endif
182} 182}
183 183
184bool deviceTab( const char *device) { 184bool deviceTab( const char *device) {
185 QString name = device; 185 QString name = device;
186 bool hasDevice=false; 186 bool hasDevice=false;
187 struct mntent *me; 187 struct mntent *me;
188 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 188 FILE *mntfp = setmntent( "/etc/mtab", "r" );
189 if ( mntfp ) { 189 if ( mntfp ) {
190 while ( (me = getmntent( mntfp )) != 0 ) { 190 while ( (me = getmntent( mntfp )) != 0 ) {
191 QString deviceName = me->mnt_fsname; 191 QString deviceName = me->mnt_fsname;
192// qDebug(deviceName); 192// qDebug(deviceName);
193 if( deviceName.left(name.length()) == name) { 193 if( deviceName.left(name.length()) == name) {
194 hasDevice = true; 194 hasDevice = true;
195 } 195 }
196 } 196 }
197 } 197 }
198 endmntent( mntfp ); 198 endmntent( mntfp );
199 return hasDevice; 199 return hasDevice;
200} 200}
201 201
202/*! 202/*!
203 * @fn hasCf() 203 * @fn static bool StorageInfo::hasCf()
204 * @brief returns whether device has Cf mounted 204 * @brief returns whether device has Cf mounted
205 * 205 *
206 */ 206 */
207bool StorageInfo::hasCf() 207bool StorageInfo::hasCf()
208{ 208{
209 return deviceTab("/dev/hd"); 209 return deviceTab("/dev/hd");
210} 210}
211 211
212/*! 212/*!
213 * @fn hasSd() 213 * @fn static bool StorageInfo::hasSd()
214 * @brief returns whether device has SD mounted 214 * @brief returns whether device has SD mounted
215 * 215 *
216 */ 216 */
217bool StorageInfo::hasSd() 217bool StorageInfo::hasSd()
218{ 218{
219 return deviceTab("/dev/mmcd"); 219 return deviceTab("/dev/mmcd");
220} 220}
221 221
222/*! 222/*!
223 * @fn hasMmc() 223 * @fn static bool StorageInfo::hasMmc()
224 * @brief reutrns whether device has mmc mounted 224 * @brief reutrns whether device has mmc mounted
225 * 225 *
226 */ 226 */
227bool StorageInfo::hasMmc() 227bool StorageInfo::hasMmc()
228{ 228{
229 bool hasMmc=false; 229 bool hasMmc=false;
230 if( deviceTab("/dev/mmc/part")) 230 if( deviceTab("/dev/mmc/part"))
231 hasMmc=true; 231 hasMmc=true;
232 if( deviceTab("/dev/mmcd")) 232 if( deviceTab("/dev/mmcd"))
233 hasMmc=true; 233 hasMmc=true;
234 return hasMmc; 234 return hasMmc;
235} 235}
236 236
237 237
238//--------------------------------------------------------------------------- 238//---------------------------------------------------------------------------
239 239
240FileSystem::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 )
241 : 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 )
242{ 242{
243 update(); 243 update();
244} 244}
245 245
246void FileSystem::update() 246void FileSystem::update()
247{ 247{
248#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 248#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
249 struct statfs fs; 249 struct statfs fs;
250 if ( !statfs( fspath.latin1(), &fs ) ) { 250 if ( !statfs( fspath.latin1(), &fs ) ) {
251 blkSize = fs.f_bsize; 251 blkSize = fs.f_bsize;
252 totalBlks = fs.f_blocks; 252 totalBlks = fs.f_blocks;
253 availBlks = fs.f_bavail; 253 availBlks = fs.f_bavail;
254 } else { 254 } else {
255 blkSize = 0; 255 blkSize = 0;
256 totalBlks = 0; 256 totalBlks = 0;
257 availBlks = 0; 257 availBlks = 0;
258 } 258 }
259#endif 259#endif
260} 260}
261 261