summaryrefslogtreecommitdiff
path: root/library
authorllornkcor <llornkcor>2002-05-28 16:58:47 (UTC)
committer llornkcor <llornkcor>2002-05-28 16:58:47 (UTC)
commit9ec323fe6ae0f1f737749d3d63ffaa4a04c55973 (patch) (unidiff)
treea1e65a6c72d131157728e93fbefc587f962da28d /library
parentf1f06e4cf8ec641852d1d464d8fa8c95b9d2fcb5 (diff)
downloadopie-9ec323fe6ae0f1f737749d3d63ffaa4a04c55973.zip
opie-9ec323fe6ae0f1f737749d3d63ffaa4a04c55973.tar.gz
opie-9ec323fe6ae0f1f737749d3d63ffaa4a04c55973.tar.bz2
fixed bug where not knowing /dev/ramfs
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/storage.cpp165
1 files changed, 84 insertions, 81 deletions
diff --git a/library/storage.cpp b/library/storage.cpp
index a4c96be..b4d743e 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -40,54 +40,54 @@
40static bool isCF(const QString& m) 40static bool isCF(const QString& m)
41{ 41{
42 FILE* f = fopen("/var/run/stab", "r"); 42 FILE* f = fopen("/var/run/stab", "r");
43 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 43 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
44 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 44 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
45 if ( f ) { 45 if ( f ) {
46 char line[1024]; 46 char line[1024];
47 char devtype[80]; 47 char devtype[80];
48 char devname[80]; 48 char devname[80];
49 while ( fgets( line, 1024, f ) ) { 49 while ( fgets( line, 1024, f ) ) {
50 // 0 ide ide-cs 0 hda 3 0 50 // 0 ide ide-cs 0 hda 3 0
51 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 51 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
52 { 52 {
53 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 53 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
54 fclose(f); 54 fclose(f);
55 return TRUE; 55 return TRUE;
56 } 56 }
57 } 57 }
58 } 58 }
59 fclose(f); 59 fclose(f);
60 } 60 }
61 return FALSE; 61 return FALSE;
62} 62}
63 63
64StorageInfo::StorageInfo( QObject *parent ) 64StorageInfo::StorageInfo( QObject *parent )
65 : QObject( parent ) 65 : QObject( parent )
66{ 66{
67 mFileSystems.setAutoDelete( TRUE ); 67 mFileSystems.setAutoDelete( TRUE );
68 channel = new QCopChannel( "QPE/Card", this ); 68 channel = new QCopChannel( "QPE/Card", this );
69 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 69 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
70 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 70 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
71 update(); 71 update();
72} 72}
73 73
74const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 74const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
75{ 75{
76 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 76 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
77 if ( filename.startsWith( (*i)->path() ) ) 77 if ( filename.startsWith( (*i)->path() ) )
78 return (*i); 78 return (*i);
79 } 79 }
80 return 0; 80 return 0;
81} 81}
82 82
83 83
84void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 84void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
85{ 85{
86 if ( msg == "mtabChanged()" ) 86 if ( msg == "mtabChanged()" )
87 update(); 87 update();
88} 88}
89// cause of the lack of a d pointer we need 89// cause of the lack of a d pointer we need
90// to store informations in a config file :( 90// to store informations in a config file :(
91void StorageInfo::update() 91void StorageInfo::update()
92{ 92{
93 //qDebug("StorageInfo::updating"); 93 //qDebug("StorageInfo::updating");
@@ -98,72 +98,75 @@ void StorageInfo::update()
98 QStringList curdisks; 98 QStringList curdisks;
99 QStringList curopts; 99 QStringList curopts;
100 QStringList curfs; 100 QStringList curfs;
101 bool rebuild = FALSE; 101 bool rebuild = FALSE;
102 int n=0; 102 int n=0;
103 if ( mntfp ) { 103 if ( mntfp ) {
104 while ( (me = getmntent( mntfp )) != 0 ) { 104 while ( (me = getmntent( mntfp )) != 0 ) {
105 QString fs = me->mnt_fsname; 105 QString fs = me->mnt_fsname;
106 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 106 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
107 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" ) 107 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
108 { 108 || fs.left(8)=="/dev/ram")
109 n++; 109 {
110 curdisks.append(fs); 110 n++;
111 curopts.append( me->mnt_opts ); 111 curdisks.append(fs);
112 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 112 curopts.append( me->mnt_opts );
113 curfs.append( me->mnt_dir ); 113 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
114 bool found = FALSE; 114 curfs.append( me->mnt_dir );
115 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 115 bool found = FALSE;
116 if ( (*i)->disk() == fs ) { 116 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
117 found = TRUE; 117 if ( (*i)->disk() == fs ) {
118 break; 118 found = TRUE;
119 } 119 break;
120 } 120 }
121 if ( !found ) 121 }
122 rebuild = TRUE; 122 if ( !found )
123 } 123 rebuild = TRUE;
124 } 124 }
125 endmntent( mntfp ); 125 }
126 endmntent( mntfp );
126 } 127 }
127 if ( rebuild || n != (int)mFileSystems.count() ) { 128 if ( rebuild || n != (int)mFileSystems.count() ) {
128 mFileSystems.clear(); 129 mFileSystems.clear();
129 QStringList::ConstIterator it=curdisks.begin(); 130 QStringList::ConstIterator it=curdisks.begin();
130 QStringList::ConstIterator fsit=curfs.begin(); 131 QStringList::ConstIterator fsit=curfs.begin();
131 QStringList::ConstIterator optsIt=curopts.begin(); 132 QStringList::ConstIterator optsIt=curopts.begin();
132 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { 133 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
133 QString opts = *optsIt; 134 QString opts = *optsIt;
134 135
135 QString disk = *it; 136 QString disk = *it;
136 QString humanname; 137 QString humanname;
137 bool removable = FALSE; 138 bool removable = FALSE;
138 if ( isCF(disk) ) { 139 if ( isCF(disk) ) {
139 humanname = tr("CF Card"); 140 humanname = tr("CF Card");
140 removable = TRUE; 141 removable = TRUE;
141 } else if ( disk == "/dev/hda1" ) { 142 } else if ( disk == "/dev/hda1" ) {
142 humanname = tr("Hard Disk"); 143 humanname = tr("Hard Disk");
143 } else if ( disk.left(9) == "/dev/mmcd" ) { 144 } else if ( disk.left(9) == "/dev/mmcd" ) {
144 humanname = tr("SD Card"); 145 humanname = tr("SD Card");
145 removable = TRUE; 146 removable = TRUE;
146 } else if ( disk.left(7) == "/dev/hd" ) 147 } else if ( disk.left(7) == "/dev/hd" )
147 humanname = tr("Hard Disk") + " " + humanname.mid(7); 148 humanname = tr("Hard Disk") + " " + humanname.mid(7);
148 else if ( disk.left(7) == "/dev/sd" ) 149 else if ( disk.left(7) == "/dev/sd" )
149 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7); 150 humanname = tr("SCSI Hard Disk") + " " + humanname.mid(7);
150 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 151 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
151 humanname = tr("Internal Storage"); 152 humanname = tr("Internal Storage");
152 else if ( disk.left(14) == "/dev/mtdblock/" ) 153 else if ( disk.left(14) == "/dev/mtdblock/" )
153 humanname = tr("Internal Storage") + " " + humanname.mid(14); 154 humanname = tr("Internal Storage") + " " + humanname.mid(14);
154 else if ( disk.left(13) == "/dev/mtdblock" ) 155 else if ( disk.left(13) == "/dev/mtdblock" )
155 humanname = tr("Internal Storage") + " " + humanname.mid(13); 156 humanname = tr("Internal Storage") + " " + humanname.mid(13);
156 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 157 else if ( disk.left(10) == "/dev/ramfs" )
157 mFileSystems.append( fs ); 158 humanname = tr("Internal Storage") + " " + humanname.mid(10);
158 } 159 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
159 emit disksChanged(); 160 mFileSystems.append( fs );
161 }
162 emit disksChanged();
160 } else { 163 } else {
161 // just update them 164 // just update them
162 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 165 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
163 i.current()->update(); 166 i.current()->update();
164 } 167 }
165#endif 168#endif
166} 169}
167 170
168//--------------------------------------------------------------------------- 171//---------------------------------------------------------------------------
169 172
@@ -175,17 +178,17 @@ FileSystem::FileSystem( const QString &disk, const QString &path, const QString
175 178
176void FileSystem::update() 179void FileSystem::update()
177{ 180{
178#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 181#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
179 struct statfs fs; 182 struct statfs fs;
180 if ( !statfs( fspath.latin1(), &fs ) ) { 183 if ( !statfs( fspath.latin1(), &fs ) ) {
181 blkSize = fs.f_bsize; 184 blkSize = fs.f_bsize;
182 totalBlks = fs.f_blocks; 185 totalBlks = fs.f_blocks;
183 availBlks = fs.f_bavail; 186 availBlks = fs.f_bavail;
184 } else { 187 } else {
185 blkSize = 0; 188 blkSize = 0;
186 totalBlks = 0; 189 totalBlks = 0;
187 availBlks = 0; 190 availBlks = 0;
188 } 191 }
189#endif 192#endif
190} 193}
191 194