-rw-r--r-- | library/storage.cpp | 42 |
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 | |||
@@ -26,25 +26,36 @@ | |||
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 | ||
43 | static bool isCF(const QString& m) | 52 | static 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]; |
@@ -58,12 +69,13 @@ static bool isCF(const QString& m) | |||
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 | ||
@@ -201,26 +213,46 @@ void StorageInfo::update() | |||
201 | i.current()->update(); | 213 | i.current()->update(); |
202 | } | 214 | } |
203 | #endif | 215 | #endif |
204 | } | 216 | } |
205 | 217 | ||
206 | bool deviceTab( const char *device) { | 218 | bool 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 |