author | ar <ar> | 2004-01-07 20:22:49 (UTC) |
---|---|---|
committer | ar <ar> | 2004-01-07 20:22:49 (UTC) |
commit | dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8 (patch) (unidiff) | |
tree | 92c625add3c9d24e65c1550bc5449420a85342ce | |
parent | 24a62e8789083f446138aebfa11409b73886aa88 (diff) | |
download | opie-dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8.zip opie-dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8.tar.gz opie-dd56d03c7a07ad1cf4f715ba22cbbf6b3d8392e8.tar.bz2 |
new functions getCfPath, getSdPath, getMmcPath returns mountpoints
-rw-r--r-- | library/storage.cpp | 139 | ||||
-rw-r--r-- | library/storage.h | 4 |
2 files changed, 118 insertions, 25 deletions
diff --git a/library/storage.cpp b/library/storage.cpp index f8b75d0..657fb71 100644 --- a/library/storage.cpp +++ b/library/storage.cpp | |||
@@ -56,15 +56,18 @@ static bool isCF(const QString& m) | |||
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 ) ) |
65 | { | ||
64 | // 0 ide ide-cs 0 hda 3 0 | 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 ) |
70 | { | ||
68 | fclose(f); | 71 | fclose(f); |
69 | return TRUE; | 72 | return TRUE; |
70 | } | 73 | } |
@@ -106,7 +109,8 @@ StorageInfo::StorageInfo( QObject *parent ) | |||
106 | */ | 109 | */ |
107 | const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) | 110 | const 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) |
113 | { | ||
110 | if ( filename.startsWith( (*i)->path() ) ) | 114 | if ( filename.startsWith( (*i)->path() ) ) |
111 | return (*i); | 115 | return (*i); |
112 | } | 116 | } |
@@ -139,8 +143,10 @@ void StorageInfo::update() | |||
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 | { |
148 | while ( (me = getmntent( mntfp )) != 0 ) | ||
149 | { | ||
144 | QString fs = me->mnt_fsname; | 150 | QString fs = me->mnt_fsname; |
145 | if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" | 151 | if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" |
146 | || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" | 152 | || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" |
@@ -153,8 +159,10 @@ void StorageInfo::update() | |||
153 | //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); | 159 | //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); |
154 | curfs.append( me->mnt_dir ); | 160 | curfs.append( me->mnt_dir ); |
155 | bool found = FALSE; | 161 | bool found = FALSE; |
156 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { | 162 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) |
157 | if ( (*i)->disk() == fs ) { | 163 | { |
164 | if ( (*i)->disk() == fs ) | ||
165 | { | ||
158 | found = TRUE; | 166 | found = TRUE; |
159 | break; | 167 | break; |
160 | } | 168 | } |
@@ -165,29 +173,39 @@ void StorageInfo::update() | |||
165 | } | 173 | } |
166 | endmntent( mntfp ); | 174 | endmntent( mntfp ); |
167 | } | 175 | } |
168 | if ( rebuild || n != (int)mFileSystems.count() ) { | 176 | if ( rebuild || n != (int)mFileSystems.count() ) |
177 | { | ||
169 | mFileSystems.clear(); | 178 | mFileSystems.clear(); |
170 | QStringList::ConstIterator it=curdisks.begin(); | 179 | QStringList::ConstIterator it=curdisks.begin(); |
171 | QStringList::ConstIterator fsit=curfs.begin(); | 180 | QStringList::ConstIterator fsit=curfs.begin(); |
172 | QStringList::ConstIterator optsIt=curopts.begin(); | 181 | QStringList::ConstIterator optsIt=curopts.begin(); |
173 | for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { | 182 | for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) |
183 | { | ||
174 | QString opts = *optsIt; | 184 | QString opts = *optsIt; |
175 | 185 | ||
176 | QString disk = *it; | 186 | QString disk = *it; |
177 | QString humanname; | 187 | QString humanname; |
178 | bool removable = FALSE; | 188 | bool removable = FALSE; |
179 | if ( isCF(disk) ) { | 189 | if ( isCF(disk) ) |
190 | { | ||
180 | humanname = tr("CF Card"); | 191 | humanname = tr("CF Card"); |
181 | removable = TRUE; | 192 | removable = TRUE; |
182 | } else if ( disk == "/dev/hda1" ) { | 193 | } |
194 | else if ( disk == "/dev/hda1" ) | ||
195 | { | ||
183 | humanname = tr("Hard Disk"); | 196 | humanname = tr("Hard Disk"); |
184 | } else if ( disk.left(9) == "/dev/mmcd" ) { | 197 | } |
198 | else if ( disk.left(9) == "/dev/mmcd" ) | ||
199 | { | ||
185 | humanname = tr("SD Card"); | 200 | humanname = tr("SD Card"); |
186 | removable = TRUE; | 201 | removable = TRUE; |
187 | } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { | 202 | } |
203 | else if ( disk.left( 14 ) == "/dev/mmc/part1" ) | ||
204 | { | ||
188 | humanname = tr("MMC Card"); | 205 | humanname = tr("MMC Card"); |
189 | removable = TRUE; | 206 | removable = TRUE; |
190 | } else if ( disk.left(7) == "/dev/hd" ) | 207 | } |
208 | else if ( disk.left(7) == "/dev/hd" ) | ||
191 | humanname = tr("Hard Disk") + " " + disk; | 209 | humanname = tr("Hard Disk") + " " + disk; |
192 | else if ( disk.left(7) == "/dev/sd" ) | 210 | else if ( disk.left(7) == "/dev/sd" ) |
193 | humanname = tr("SCSI Hard Disk") + " " + disk; | 211 | humanname = tr("SCSI Hard Disk") + " " + disk; |
@@ -207,7 +225,9 @@ void StorageInfo::update() | |||
207 | mFileSystems.append( fs ); | 225 | mFileSystems.append( fs ); |
208 | } | 226 | } |
209 | emit disksChanged(); | 227 | emit disksChanged(); |
210 | } else { | 228 | } |
229 | else | ||
230 | { | ||
211 | // just update them | 231 | // just update them |
212 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) | 232 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) |
213 | i.current()->update(); | 233 | i.current()->update(); |
@@ -215,7 +235,8 @@ void StorageInfo::update() | |||
215 | #endif | 235 | #endif |
216 | } | 236 | } |
217 | 237 | ||
218 | bool deviceTab( const char *device) { | 238 | bool deviceTab( const char *device) |
239 | { | ||
219 | QString name = device; | 240 | QString name = device; |
220 | bool hasDevice=false; | 241 | bool hasDevice=false; |
221 | 242 | ||
@@ -223,11 +244,13 @@ bool deviceTab( const char *device) { | |||
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 ) |
248 | { | ||
227 | qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) ); | 249 | qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) ); |
228 | hasDevice = false; | 250 | hasDevice = false; |
229 | } | 251 | } |
230 | for( int i = 0; i < count; i++ ){ | 252 | for( int i = 0; i < count; i++ ) |
253 | { | ||
231 | QString deviceName = mntbufp[i]->f_mntfromname; | 254 | QString deviceName = mntbufp[i]->f_mntfromname; |
232 | qDebug(deviceName); | 255 | qDebug(deviceName); |
233 | if( deviceName.left( name.length() ) == name ) | 256 | if( deviceName.left( name.length() ) == name ) |
@@ -237,11 +260,14 @@ bool deviceTab( const char *device) { | |||
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 | { |
265 | while ( (me = getmntent( mntfp )) != 0 ) | ||
266 | { | ||
242 | QString deviceName = me->mnt_fsname; | 267 | QString deviceName = me->mnt_fsname; |
243 | // qDebug(deviceName); | 268 | // qDebug(deviceName); |
244 | if( deviceName.left(name.length()) == name) { | 269 | if( deviceName.left(name.length()) == name) |
270 | { | ||
245 | hasDevice = true; | 271 | hasDevice = true; |
246 | } | 272 | } |
247 | } | 273 | } |
@@ -275,7 +301,7 @@ bool StorageInfo::hasSd() | |||
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 | */ |
281 | bool StorageInfo::hasMmc() | 307 | bool StorageInfo::hasMmc() |
@@ -288,6 +314,66 @@ bool StorageInfo::hasMmc() | |||
288 | return hasMmc; | 314 | return hasMmc; |
289 | } | 315 | } |
290 | 316 | ||
317 | /*! | ||
318 | * @fn QString StorageInfo::getCfPath() | ||
319 | * @brief returns the Mount-Path of Cf Card | ||
320 | * | ||
321 | */ | ||
322 | QString 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 | */ | ||
342 | QString 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 | */ | ||
362 | QString 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; | ||
375 | } | ||
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 | ||
@@ -310,11 +396,14 @@ void 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 ) ) |
400 | { | ||
314 | blkSize = fs.f_bsize; | 401 | blkSize = fs.f_bsize; |
315 | totalBlks = fs.f_blocks; | 402 | totalBlks = fs.f_blocks; |
316 | availBlks = fs.f_bavail; | 403 | availBlks = fs.f_bavail; |
317 | } else { | 404 | } |
405 | else | ||
406 | { | ||
318 | blkSize = 0; | 407 | blkSize = 0; |
319 | totalBlks = 0; | 408 | totalBlks = 0; |
320 | availBlks = 0; | 409 | availBlks = 0; |
diff --git a/library/storage.h b/library/storage.h index 0a0698f..35a1109 100644 --- a/library/storage.h +++ b/library/storage.h | |||
@@ -37,6 +37,10 @@ public: | |||
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(); | ||
40 | signals: | 44 | signals: |
41 | void disksChanged(); | 45 | void disksChanged(); |
42 | 46 | ||