-rw-r--r-- | library/storage.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/library/storage.cpp b/library/storage.cpp index 4e07ec6..1ce43bc 100644 --- a/library/storage.cpp +++ b/library/storage.cpp | |||
@@ -45,73 +45,97 @@ | |||
45 | static bool isCF(const QString& m) | 45 | static bool isCF(const QString& m) |
46 | { | 46 | { |
47 | FILE* f = fopen("/var/run/stab", "r"); | 47 | FILE* f = fopen("/var/run/stab", "r"); |
48 | if (!f) f = fopen("/var/state/pcmcia/stab", "r"); | 48 | if (!f) f = fopen("/var/state/pcmcia/stab", "r"); |
49 | if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); | 49 | if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); |
50 | if ( f ) { | 50 | if ( f ) { |
51 | char line[1024]; | 51 | char line[1024]; |
52 | char devtype[80]; | 52 | char devtype[80]; |
53 | char devname[80]; | 53 | char devname[80]; |
54 | while ( fgets( line, 1024, f ) ) { | 54 | while ( fgets( line, 1024, f ) ) { |
55 | // 0 ide ide-cs 0 hda 3 0 | 55 | // 0 ide ide-cs 0 hda 3 0 |
56 | if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) | 56 | if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) |
57 | { | 57 | { |
58 | if ( QString(devtype) == "ide" && m.find(devname)>0 ) { | 58 | if ( QString(devtype) == "ide" && m.find(devname)>0 ) { |
59 | fclose(f); | 59 | fclose(f); |
60 | return TRUE; | 60 | return TRUE; |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | fclose(f); | 64 | fclose(f); |
65 | } | 65 | } |
66 | return FALSE; | 66 | return FALSE; |
67 | } | 67 | } |
68 | 68 | ||
69 | /*! \class StorageInfo storage.h | ||
70 | \brief The StorageInfo class describes the disks mounted on the file system. | ||
71 | |||
72 | This class provides access to the mount information for the Linux | ||
73 | filesystem. Each mount point is represented by the FileSystem class. | ||
74 | To ensure this class has the most up to date size information, call | ||
75 | the update() method. Note that this will automatically be signaled | ||
76 | by the operating system when a disk has been mounted or unmounted. | ||
77 | |||
78 | \ingroup qtopiaemb | ||
79 | */ | ||
80 | |||
81 | /*! Constructor that determines the current mount points of the filesystem. | ||
82 | The standard \a parent parameters is passed on to QObject. | ||
83 | */ | ||
69 | StorageInfo::StorageInfo( QObject *parent ) | 84 | StorageInfo::StorageInfo( QObject *parent ) |
70 | : QObject( parent ) | 85 | : QObject( parent ) |
71 | { | 86 | { |
72 | mFileSystems.setAutoDelete( TRUE ); | 87 | mFileSystems.setAutoDelete( TRUE ); |
73 | channel = new QCopChannel( "QPE/Card", this ); | 88 | channel = new QCopChannel( "QPE/Card", this ); |
74 | connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), | 89 | connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), |
75 | this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); | 90 | this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); |
76 | update(); | 91 | update(); |
77 | } | 92 | } |
78 | 93 | ||
94 | /*! Returns the longest matching FileSystem that starts with the | ||
95 | same prefix as \a filename as its mount point. | ||
96 | */ | ||
79 | const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) | 97 | const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) |
80 | { | 98 | { |
81 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { | 99 | for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { |
82 | if ( filename.startsWith( (*i)->path() ) ) | 100 | if ( filename.startsWith( (*i)->path() ) ) |
83 | return (*i); | 101 | return (*i); |
84 | } | 102 | } |
85 | return 0; | 103 | return 0; |
86 | } | 104 | } |
87 | 105 | ||
88 | 106 | ||
89 | void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) | 107 | void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) |
90 | { | 108 | { |
91 | if ( msg == "mtabChanged()" ) | 109 | if ( msg == "mtabChanged()" ) |
92 | update(); | 110 | update(); |
93 | } | 111 | } |
112 | |||
113 | |||
114 | /*! Updates the mount and free space available information for each mount | ||
115 | point. This method is automatically called when a disk is mounted or | ||
116 | unmounted. | ||
117 | */ | ||
94 | // cause of the lack of a d pointer we need | 118 | // cause of the lack of a d pointer we need |
95 | // to store informations in a config file :( | 119 | // to store informations in a config file :( |
96 | void StorageInfo::update() | 120 | void StorageInfo::update() |
97 | { | 121 | { |
98 | //qDebug("StorageInfo::updating"); | 122 | //qDebug("StorageInfo::updating"); |
99 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 123 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
100 | struct mntent *me; | 124 | struct mntent *me; |
101 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 125 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
102 | 126 | ||
103 | QStringList curdisks; | 127 | QStringList curdisks; |
104 | QStringList curopts; | 128 | QStringList curopts; |
105 | QStringList curfs; | 129 | QStringList curfs; |
106 | bool rebuild = FALSE; | 130 | bool rebuild = FALSE; |
107 | int n=0; | 131 | int n=0; |
108 | if ( mntfp ) { | 132 | if ( mntfp ) { |
109 | while ( (me = getmntent( mntfp )) != 0 ) { | 133 | while ( (me = getmntent( mntfp )) != 0 ) { |
110 | QString fs = me->mnt_fsname; | 134 | QString fs = me->mnt_fsname; |
111 | if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" | 135 | if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" |
112 | || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" | 136 | || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" |
113 | || fs.left( 14 ) == "/dev/mmc/part1" | 137 | || fs.left( 14 ) == "/dev/mmc/part1" |
114 | || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) | 138 | || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) |
115 | { | 139 | { |
116 | n++; | 140 | n++; |
117 | curdisks.append(fs); | 141 | curdisks.append(fs); |
@@ -213,49 +237,110 @@ bool StorageInfo::hasCf() | |||
213 | * @fn static bool StorageInfo::hasSd() | 237 | * @fn static bool StorageInfo::hasSd() |
214 | * @brief returns whether device has SD mounted | 238 | * @brief returns whether device has SD mounted |
215 | * | 239 | * |
216 | */ | 240 | */ |
217 | bool StorageInfo::hasSd() | 241 | bool StorageInfo::hasSd() |
218 | { | 242 | { |
219 | return deviceTab("/dev/mmcd"); | 243 | return deviceTab("/dev/mmcd"); |
220 | } | 244 | } |
221 | 245 | ||
222 | /*! | 246 | /*! |
223 | * @fn static bool StorageInfo::hasMmc() | 247 | * @fn static bool StorageInfo::hasMmc() |
224 | * @brief reutrns whether device has mmc mounted | 248 | * @brief reutrns whether device has mmc mounted |
225 | * | 249 | * |
226 | */ | 250 | */ |
227 | bool StorageInfo::hasMmc() | 251 | bool StorageInfo::hasMmc() |
228 | { | 252 | { |
229 | bool hasMmc=false; | 253 | bool hasMmc=false; |
230 | if( deviceTab("/dev/mmc/part")) | 254 | if( deviceTab("/dev/mmc/part")) |
231 | hasMmc=true; | 255 | hasMmc=true; |
232 | if( deviceTab("/dev/mmcd")) | 256 | if( deviceTab("/dev/mmcd")) |
233 | hasMmc=true; | 257 | hasMmc=true; |
234 | return hasMmc; | 258 | return hasMmc; |
235 | } | 259 | } |
236 | 260 | ||
261 | /*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const | ||
262 | Returns a list of all available mounted file systems. | ||
263 | |||
264 | \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) | ||
265 | */ | ||
237 | 266 | ||
267 | /*! \fn void StorageInfo::disksChanged() | ||
268 | Gets emitted when a disk has been mounted or unmounted, such as when | ||
269 | a CF c | ||
270 | */ | ||
238 | //--------------------------------------------------------------------------- | 271 | //--------------------------------------------------------------------------- |
239 | 272 | ||
240 | FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) | 273 | FileSystem::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 ) | 274 | : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) |
242 | { | 275 | { |
243 | update(); | 276 | update(); |
244 | } | 277 | } |
245 | 278 | ||
246 | void FileSystem::update() | 279 | void FileSystem::update() |
247 | { | 280 | { |
248 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 281 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
249 | struct statfs fs; | 282 | struct statfs fs; |
250 | if ( !statfs( fspath.latin1(), &fs ) ) { | 283 | if ( !statfs( fspath.latin1(), &fs ) ) { |
251 | blkSize = fs.f_bsize; | 284 | blkSize = fs.f_bsize; |
252 | totalBlks = fs.f_blocks; | 285 | totalBlks = fs.f_blocks; |
253 | availBlks = fs.f_bavail; | 286 | availBlks = fs.f_bavail; |
254 | } else { | 287 | } else { |
255 | blkSize = 0; | 288 | blkSize = 0; |
256 | totalBlks = 0; | 289 | totalBlks = 0; |
257 | availBlks = 0; | 290 | availBlks = 0; |
258 | } | 291 | } |
259 | #endif | 292 | #endif |
260 | } | 293 | } |
261 | 294 | ||
295 | /*! \class FileSystem storage.h | ||
296 | \brief The FileSystem class describes a single mount point. | ||
297 | |||
298 | This class simply returns information about a mount point, including | ||
299 | file system name, mount point, human readable name, size information | ||
300 | and mount options information. | ||
301 | \ingroup qtopiaemb | ||
302 | |||
303 | \sa StorageInfo | ||
304 | */ | ||
305 | |||
306 | /*! \fn const QString &FileSystem::disk() const | ||
307 | Returns the file system name, such as /dev/hda3 | ||
308 | */ | ||
309 | |||
310 | /*! \fn const QString &FileSystem::path() const | ||
311 | Returns the mount path, such as /home | ||
312 | */ | ||
313 | |||
314 | /*! \fn const QString &FileSystem::name() const | ||
315 | Returns the translated, human readable name for the mount directory. | ||
316 | */ | ||
317 | |||
318 | /*! \fn const QString &FileSystem::options() const | ||
319 | Returns the mount options | ||
320 | */ | ||
321 | |||
322 | /*! \fn long FileSystem::blockSize() const | ||
323 | Returns the size of each block on the file system. | ||
324 | */ | ||
325 | |||
326 | /*! \fn long FileSystem::totalBlocks() const | ||
327 | Returns the total number of blocks on the file system | ||
328 | */ | ||
329 | |||
330 | /*! \fn long FileSystem::availBlocks() const | ||
331 | Returns the number of available blocks on the file system | ||
332 | */ | ||
333 | |||
334 | /*! \fn bool FileSystem::isRemovable() const | ||
335 | Returns flag whether the file system can be removed, such as a CF card | ||
336 | would be removable, but the internal memory wouldn't | ||
337 | */ | ||
338 | |||
339 | /*! \fn bool FileSystem::isWritable() const | ||
340 | Returns flag whether the file system is mounted as writable or read-only. | ||
341 | Returns FALSE if read-only, TRUE if read and write. | ||
342 | */ | ||
343 | |||
344 | /*! \fn QStringList StorageInfo::fileSystemNames() const | ||
345 | Returns a list of filesystem names. | ||
346 | */ | ||