author | alwin <alwin> | 2005-03-07 14:32:58 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-07 14:32:58 (UTC) |
commit | 9ac0dc3c7b4e56f38c3cefce2e5699078aa3a357 (patch) (unidiff) | |
tree | 9b8e96c6971ca8750a274f2542eed1272f4ec683 | |
parent | c26df8eafe66bded4a4af4f95830fd2187bfa2ca (diff) | |
download | opie-9ac0dc3c7b4e56f38c3cefce2e5699078aa3a357.zip opie-9ac0dc3c7b4e56f38c3cefce2e5699078aa3a357.tar.gz opie-9ac0dc3c7b4e56f38c3cefce2e5699078aa3a357.tar.bz2 |
yes - scsi storage may be removeable devices!
-rw-r--r-- | library/storage.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/library/storage.cpp b/library/storage.cpp index 9549ff3..e657573 100644 --- a/library/storage.cpp +++ b/library/storage.cpp | |||
@@ -79,259 +79,260 @@ static bool isCF(const QString& m) | |||
79 | \brief The StorageInfo class describes the disks mounted on the file system. | 79 | \brief The StorageInfo class describes the disks mounted on the file system. |
80 | 80 | ||
81 | This class provides access to the mount information for the Linux | 81 | This class provides access to the mount information for the Linux |
82 | filesystem. Each mount point is represented by the FileSystem class. | 82 | filesystem. Each mount point is represented by the FileSystem class. |
83 | To ensure this class has the most up to date size information, call | 83 | To ensure this class has the most up to date size information, call |
84 | the update() method. Note that this will automatically be signaled | 84 | the update() method. Note that this will automatically be signaled |
85 | by the operating system when a disk has been mounted or unmounted. | 85 | by the operating system when a disk has been mounted or unmounted. |
86 | 86 | ||
87 | \ingroup qtopiaemb | 87 | \ingroup qtopiaemb |
88 | */ | 88 | */ |
89 | 89 | ||
90 | /*! Constructor that determines the current mount points of the filesystem. | 90 | /*! Constructor that determines the current mount points of the filesystem. |
91 | The standard \a parent parameters is passed on to QObject. | 91 | The standard \a parent parameters is passed on to QObject. |
92 | */ | 92 | */ |
93 | StorageInfo::StorageInfo( QObject *parent ) | 93 | StorageInfo::StorageInfo( QObject *parent ) |
94 | : QObject( parent ) | 94 | : QObject( parent ) |
95 | { | 95 | { |
96 | mFileSystems.setAutoDelete( TRUE ); | 96 | mFileSystems.setAutoDelete( TRUE ); |
97 | channel = new QCopChannel( "QPE/Card", this ); | 97 | channel = new QCopChannel( "QPE/Card", this ); |
98 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 98 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
99 | this, SLOT(cardMessage(const QCString&,const QByteArray&)) ); | 99 | this, SLOT(cardMessage(const QCString&,const QByteArray&)) ); |
100 | update(); | 100 | update(); |
101 | } | 101 | } |
102 | 102 | ||
103 | /*! Returns the longest matching FileSystem that starts with the | 103 | /*! Returns the longest matching FileSystem that starts with the |
104 | same prefix as \a filename as its mount point. | 104 | same prefix as \a filename as its mount point. |
105 | */ | 105 | */ |
106 | const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) | 106 | const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) |
107 | { | 107 | { |
108 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) | 108 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) |
109 | { | 109 | { |
110 | if ( filename.startsWith( (*i)->path() ) ) | 110 | if ( filename.startsWith( (*i)->path() ) ) |
111 | return (*i); | 111 | return (*i); |
112 | } | 112 | } |
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) | 117 | void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) |
118 | { | 118 | { |
119 | if ( msg == "mtabChanged()" ) | 119 | if ( msg == "mtabChanged()" ) |
120 | update(); | 120 | update(); |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | /*! Updates the mount and free space available information for each mount | 124 | /*! Updates the mount and free space available information for each mount |
125 | point. This method is automatically called when a disk is mounted or | 125 | point. This method is automatically called when a disk is mounted or |
126 | unmounted. | 126 | unmounted. |
127 | */ | 127 | */ |
128 | // cause of the lack of a d pointer we need | 128 | // cause of the lack of a d pointer we need |
129 | // to store informations in a config file :( | 129 | // to store informations in a config file :( |
130 | void StorageInfo::update() | 130 | void StorageInfo::update() |
131 | { | 131 | { |
132 | //qDebug("StorageInfo::updating"); | 132 | //qDebug("StorageInfo::updating"); |
133 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 133 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
134 | struct mntent *me; | 134 | struct mntent *me; |
135 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 135 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
136 | 136 | ||
137 | QStringList curdisks; | 137 | QStringList curdisks; |
138 | QStringList curopts; | 138 | QStringList curopts; |
139 | QStringList curfs; | 139 | QStringList curfs; |
140 | bool rebuild = FALSE; | 140 | bool rebuild = FALSE; |
141 | int n=0; | 141 | int n=0; |
142 | if ( mntfp ) | 142 | if ( mntfp ) |
143 | { | 143 | { |
144 | while ( (me = getmntent( mntfp )) != 0 ) | 144 | while ( (me = getmntent( mntfp )) != 0 ) |
145 | { | 145 | { |
146 | QString fs = me->mnt_fsname; | 146 | QString fs = me->mnt_fsname; |
147 | if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" | 147 | if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" |
148 | || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" | 148 | || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" |
149 | || fs.left( 14 ) == "/dev/mmc/part1" | 149 | || fs.left( 14 ) == "/dev/mmc/part1" |
150 | || fs.left(5)=="tmpfs" || fs.left(11)=="/dev/mmcblk" | 150 | || fs.left(5)=="tmpfs" || fs.left(11)=="/dev/mmcblk" |
151 | || fs.left(9)=="/dev/root" ) | 151 | || fs.left(9)=="/dev/root" ) |
152 | { | 152 | { |
153 | n++; | 153 | n++; |
154 | curdisks.append(fs); | 154 | curdisks.append(fs); |
155 | curopts.append( me->mnt_opts ); | 155 | curopts.append( me->mnt_opts ); |
156 | //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); | 156 | //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); |
157 | curfs.append( me->mnt_dir ); | 157 | curfs.append( me->mnt_dir ); |
158 | bool found = FALSE; | 158 | bool found = FALSE; |
159 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) | 159 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) |
160 | { | 160 | { |
161 | if ( (*i)->disk() == fs ) | 161 | if ( (*i)->disk() == fs ) |
162 | { | 162 | { |
163 | found = TRUE; | 163 | found = TRUE; |
164 | break; | 164 | break; |
165 | } | 165 | } |
166 | } | 166 | } |
167 | if ( !found ) | 167 | if ( !found ) |
168 | rebuild = TRUE; | 168 | rebuild = TRUE; |
169 | } | 169 | } |
170 | } | 170 | } |
171 | endmntent( mntfp ); | 171 | endmntent( mntfp ); |
172 | } | 172 | } |
173 | if ( rebuild || n != (int)mFileSystems.count() ) | 173 | if ( rebuild || n != (int)mFileSystems.count() ) |
174 | { | 174 | { |
175 | mFileSystems.clear(); | 175 | mFileSystems.clear(); |
176 | QStringList::ConstIterator it=curdisks.begin(); | 176 | QStringList::ConstIterator it=curdisks.begin(); |
177 | QStringList::ConstIterator fsit=curfs.begin(); | 177 | QStringList::ConstIterator fsit=curfs.begin(); |
178 | QStringList::ConstIterator optsIt=curopts.begin(); | 178 | QStringList::ConstIterator optsIt=curopts.begin(); |
179 | for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) | 179 | for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) |
180 | { | 180 | { |
181 | QString opts = *optsIt; | 181 | QString opts = *optsIt; |
182 | 182 | ||
183 | QString disk = *it; | 183 | QString disk = *it; |
184 | QString humanname; | 184 | QString humanname; |
185 | bool removable = FALSE; | 185 | bool removable = FALSE; |
186 | if ( isCF(disk) ) | 186 | if ( isCF(disk) ) |
187 | { | 187 | { |
188 | humanname = tr("CF Card"); | 188 | humanname = tr("CF Card"); |
189 | removable = TRUE; | 189 | removable = TRUE; |
190 | } | 190 | } |
191 | else if ( disk == "/dev/hda1" ) | 191 | else if ( disk == "/dev/hda1" ) |
192 | { | 192 | { |
193 | humanname = tr("Hard Disk"); | 193 | humanname = tr("Hard Disk"); |
194 | } | 194 | } |
195 | else if ( disk.left(9) == "/dev/mmcd" ) | 195 | else if ( disk.left(9) == "/dev/mmcd" ) |
196 | { | 196 | { |
197 | humanname = tr("SD Card"); | 197 | humanname = tr("SD Card"); |
198 | removable = TRUE; | 198 | removable = TRUE; |
199 | } | 199 | } |
200 | else if ( disk.left( 14 ) == "/dev/mmc/part1" || disk.left(11) == "/dev/mmcblk" ) | 200 | else if ( disk.left( 14 ) == "/dev/mmc/part1" || disk.left(11) == "/dev/mmcblk" ) |
201 | { | 201 | { |
202 | humanname = tr("MMC Card"); | 202 | humanname = tr("MMC Card"); |
203 | removable = TRUE; | 203 | removable = TRUE; |
204 | } | 204 | } |
205 | else if ( disk.left(7) == "/dev/hd" ) | 205 | else if ( disk.left(7) == "/dev/hd" ) |
206 | humanname = tr("Hard Disk") + " " + disk; | 206 | humanname = tr("Hard Disk") + " " + disk; |
207 | else if ( disk.left(7) == "/dev/sd" ) | 207 | else if ( disk.left(7) == "/dev/sd" ) { |
208 | humanname = tr("SCSI Hard Disk") + " " + disk; | 208 | humanname = tr("SCSI Hard Disk") + " " + disk; |
209 | else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs | 209 | removable = TRUE; |
210 | } else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs | ||
210 | humanname = tr("Internal Memory"); | 211 | humanname = tr("Internal Memory"); |
211 | else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) | 212 | else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) |
212 | humanname = tr("Internal Storage"); | 213 | humanname = tr("Internal Storage"); |
213 | else if ( disk.left(14) == "/dev/mtdblock/" ) | 214 | else if ( disk.left(14) == "/dev/mtdblock/" ) |
214 | humanname = tr("Internal Storage") + " " + disk; | 215 | humanname = tr("Internal Storage") + " " + disk; |
215 | else if ( disk.left(13) == "/dev/mtdblock" ) | 216 | else if ( disk.left(13) == "/dev/mtdblock" ) |
216 | humanname = tr("Internal Storage") + " " + disk; | 217 | humanname = tr("Internal Storage") + " " + disk; |
217 | else if ( disk.left(9) == "/dev/root" ) | 218 | else if ( disk.left(9) == "/dev/root" ) |
218 | humanname = tr("Internal Storage") + " " + disk; | 219 | humanname = tr("Internal Storage") + " " + disk; |
219 | else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs | 220 | else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs |
220 | humanname = tr("Internal Memory"); | 221 | humanname = tr("Internal Memory"); |
221 | FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); | 222 | FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); |
222 | mFileSystems.append( fs ); | 223 | mFileSystems.append( fs ); |
223 | } | 224 | } |
224 | emit disksChanged(); | 225 | emit disksChanged(); |
225 | } | 226 | } |
226 | else | 227 | else |
227 | { | 228 | { |
228 | // just update them | 229 | // just update them |
229 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) | 230 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) |
230 | i.current()->update(); | 231 | i.current()->update(); |
231 | } | 232 | } |
232 | #endif | 233 | #endif |
233 | } | 234 | } |
234 | 235 | ||
235 | bool deviceTab( const char *device) | 236 | bool deviceTab( const char *device) |
236 | { | 237 | { |
237 | QString name = device; | 238 | QString name = device; |
238 | bool hasDevice=false; | 239 | bool hasDevice=false; |
239 | 240 | ||
240 | #ifdef Q_OS_MACX | 241 | #ifdef Q_OS_MACX |
241 | // Darwin (MacOS X) | 242 | // Darwin (MacOS X) |
242 | struct statfs** mntbufp; | 243 | struct statfs** mntbufp; |
243 | int count = 0; | 244 | int count = 0; |
244 | if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 ) | 245 | if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 ) |
245 | { | 246 | { |
246 | qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) ); | 247 | qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) ); |
247 | hasDevice = false; | 248 | hasDevice = false; |
248 | } | 249 | } |
249 | for( int i = 0; i < count; i++ ) | 250 | for( int i = 0; i < count; i++ ) |
250 | { | 251 | { |
251 | QString deviceName = mntbufp[i]->f_mntfromname; | 252 | QString deviceName = mntbufp[i]->f_mntfromname; |
252 | qDebug(deviceName); | 253 | qDebug(deviceName); |
253 | if( deviceName.left( name.length() ) == name ) | 254 | if( deviceName.left( name.length() ) == name ) |
254 | hasDevice = true; | 255 | hasDevice = true; |
255 | } | 256 | } |
256 | #else | 257 | #else |
257 | // Linux | 258 | // Linux |
258 | struct mntent *me; | 259 | struct mntent *me; |
259 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 260 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
260 | if ( mntfp ) | 261 | if ( mntfp ) |
261 | { | 262 | { |
262 | while ( (me = getmntent( mntfp )) != 0 ) | 263 | while ( (me = getmntent( mntfp )) != 0 ) |
263 | { | 264 | { |
264 | QString deviceName = me->mnt_fsname; | 265 | QString deviceName = me->mnt_fsname; |
265 | // qDebug(deviceName); | 266 | // qDebug(deviceName); |
266 | if( deviceName.left(name.length()) == name) | 267 | if( deviceName.left(name.length()) == name) |
267 | { | 268 | { |
268 | hasDevice = true; | 269 | hasDevice = true; |
269 | } | 270 | } |
270 | } | 271 | } |
271 | } | 272 | } |
272 | endmntent( mntfp ); | 273 | endmntent( mntfp ); |
273 | #endif /* Q_OS_MACX */ | 274 | #endif /* Q_OS_MACX */ |
274 | 275 | ||
275 | 276 | ||
276 | return hasDevice; | 277 | return hasDevice; |
277 | } | 278 | } |
278 | 279 | ||
279 | /*! | 280 | /*! |
280 | * @fn static bool StorageInfo::hasCf() | 281 | * @fn static bool StorageInfo::hasCf() |
281 | * @brief returns whether device has Cf mounted | 282 | * @brief returns whether device has Cf mounted |
282 | * | 283 | * |
283 | */ | 284 | */ |
284 | bool StorageInfo::hasCf() | 285 | bool StorageInfo::hasCf() |
285 | { | 286 | { |
286 | return deviceTab("/dev/hd"); | 287 | return deviceTab("/dev/hd"); |
287 | } | 288 | } |
288 | 289 | ||
289 | /*! | 290 | /*! |
290 | * @fn static bool StorageInfo::hasSd() | 291 | * @fn static bool StorageInfo::hasSd() |
291 | * @brief returns whether device has SD mounted | 292 | * @brief returns whether device has SD mounted |
292 | * | 293 | * |
293 | */ | 294 | */ |
294 | bool StorageInfo::hasSd() | 295 | bool StorageInfo::hasSd() |
295 | { | 296 | { |
296 | return deviceTab("/dev/mmcd"); | 297 | return deviceTab("/dev/mmcd"); |
297 | } | 298 | } |
298 | 299 | ||
299 | /*! | 300 | /*! |
300 | * @fn static bool StorageInfo::hasMmc() | 301 | * @fn static bool StorageInfo::hasMmc() |
301 | * @brief returns whether device has mmc mounted | 302 | * @brief returns whether device has mmc mounted |
302 | * | 303 | * |
303 | */ | 304 | */ |
304 | bool StorageInfo::hasMmc() | 305 | bool StorageInfo::hasMmc() |
305 | { | 306 | { |
306 | bool hasMmc=false; | 307 | bool hasMmc=false; |
307 | if( deviceTab("/dev/mmc/part")) | 308 | if( deviceTab("/dev/mmc/part")) |
308 | hasMmc=true; | 309 | hasMmc=true; |
309 | if( deviceTab("/dev/mmcd")) | 310 | if( deviceTab("/dev/mmcd")) |
310 | hasMmc=true; | 311 | hasMmc=true; |
311 | return hasMmc; | 312 | return hasMmc; |
312 | } | 313 | } |
313 | 314 | ||
314 | /*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const | 315 | /*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const |
315 | Returns a list of all available mounted file systems. | 316 | Returns a list of all available mounted file systems. |
316 | 317 | ||
317 | \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) | 318 | \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) |
318 | */ | 319 | */ |
319 | 320 | ||
320 | /*! \fn void StorageInfo::disksChanged() | 321 | /*! \fn void StorageInfo::disksChanged() |
321 | Gets emitted when a disk has been mounted or unmounted, such as when | 322 | Gets emitted when a disk has been mounted or unmounted, such as when |
322 | a CF c | 323 | a CF c |
323 | */ | 324 | */ |
324 | //--------------------------------------------------------------------------- | 325 | //--------------------------------------------------------------------------- |
325 | 326 | ||
326 | FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) | 327 | FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) |
327 | : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) | 328 | : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) |
328 | { | 329 | { |
329 | update(); | 330 | update(); |
330 | } | 331 | } |
331 | 332 | ||
332 | void FileSystem::update() | 333 | void FileSystem::update() |
333 | { | 334 | { |
334 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 335 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
335 | struct statfs fs; | 336 | struct statfs fs; |
336 | if ( !statfs( fspath.latin1(), &fs ) ) | 337 | if ( !statfs( fspath.latin1(), &fs ) ) |
337 | { | 338 | { |