summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp
index 054d261..eae356e 100644
--- a/libopie2/opiecore/linux/opcmciasystem.cpp
+++ b/libopie2/opiecore/linux/opcmciasystem.cpp
@@ -1,193 +1,196 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; version 2 of the License. 10 - .   .-<_>     .<> Foundation; version 2 of the License.
11     ._= =}       : 11     ._= =}       :
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "opcmciasystem.h" 30#include "opcmciasystem.h"
31using namespace Opie::Core; 31using namespace Opie::Core;
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35 35
36/* QT */ 36/* QT */
37#include <qfile.h> 37#include <qfile.h>
38#include <qtextstream.h> 38#include <qtextstream.h>
39 39
40/* STD */ 40/* STD */
41#include <errno.h> 41#include <errno.h>
42#include <fcntl.h> 42#include <fcntl.h>
43#include <string.h> 43#include <string.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/types.h> 46#include <sys/types.h>
47#include <sys/stat.h> 47#include <sys/stat.h>
48#include <unistd.h> 48#include <unistd.h>
49 49
50#define PROC_DEVICES "/proc/devices" 50#define PROC_DEVICES "/proc/devices"
51 51
52// #define OPCMCIA_DEBUG 1 52// #define OPCMCIA_DEBUG 1
53 53
54/*====================================================================================== 54/*======================================================================================
55 * OPcmciaSystem 55 * OPcmciaSystem
56 *======================================================================================*/ 56 *======================================================================================*/
57 57
58OPcmciaSystem* OPcmciaSystem::_instance = 0; 58OPcmciaSystem* OPcmciaSystem::_instance = 0;
59 59
60OPcmciaSystem::OPcmciaSystem() 60OPcmciaSystem::OPcmciaSystem()
61 :_major( 0 ) 61 :_major( 0 )
62{ 62{
63 qDebug( "OPcmciaSystem::OPcmciaSystem()" ); 63 qDebug( "OPcmciaSystem::OPcmciaSystem()" );
64 64
65 // get major node number out of /proc/devices 65 // get major node number out of /proc/devices
66 QFile procfile( PROC_DEVICES ); 66 QFile procfile( PROC_DEVICES );
67 if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) 67 if ( procfile.exists() && procfile.open( IO_ReadOnly ) )
68 { 68 {
69 QTextStream devstream( &procfile ); 69 QTextStream devstream( &procfile );
70 devstream.readLine(); // skip header 70 devstream.readLine(); // skip header
71 while ( !devstream.atEnd() && !_major ) 71 while ( !devstream.atEnd() && !_major )
72 { 72 {
73 int nodenumber; 73 int nodenumber;
74 QString driver; 74 QString driver;
75 devstream >> nodenumber >> driver; 75 devstream >> nodenumber >> driver;
76 if ( driver == "pcmcia" ) 76 if ( driver == "pcmcia" )
77 { 77 {
78 qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); 78 qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber );
79 _major = nodenumber; 79 _major = nodenumber;
80 break; 80 break;
81 } 81 }
82 } 82 }
83 } 83 }
84 else 84 else
85 { 85 {
86 qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." ); 86 qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." );
87 } 87 }
88 88
89 synchronize(); 89 synchronize();
90} 90}
91 91
92void OPcmciaSystem::synchronize() 92void OPcmciaSystem::synchronize()
93{ 93{
94 qDebug( "OPcmciaSystem::synchronize()" ); 94 qDebug( "OPcmciaSystem::synchronize()" );
95 _interfaces.clear(); 95 _interfaces.clear();
96 96
97 //FIXME: Use cardmgr subsystem ioctls 97 //NOTE: We _could_ use ioctl's here as well, however we want to know if
98 // the card is recognized by the cardmgr (hence has a valid binding)
99 // If it is not recognized yet, userland may want to provide a configuration dialog
100 //TODO: Revise for pcmciautils
98 101
99 QString fileName; 102 QString fileName;
100 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } 103 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
101 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } 104 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; }
102 else { fileName = "/var/lib/pcmcia/stab"; } 105 else { fileName = "/var/lib/pcmcia/stab"; }
103 QFile cardinfofile( fileName ); 106 QFile cardinfofile( fileName );
104 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) 107 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) )
105 { 108 {
106 qWarning( "pcmcia info file not found or unaccessible" ); 109 qWarning( "pcmcia info file not found or unaccessible" );
107 return; 110 return;
108 } 111 }
109 QTextStream cardinfo( &cardinfofile ); 112 QTextStream cardinfo( &cardinfofile );
110 while ( !cardinfo.atEnd() ) 113 while ( !cardinfo.atEnd() )
111 { 114 {
112 QString strSocket; 115 QString strSocket;
113 int numSocket; 116 int numSocket;
114 char colon; 117 char colon;
115 QString cardName; 118 QString cardName;
116 cardinfo >> strSocket >> numSocket >> colon; 119 cardinfo >> strSocket >> numSocket >> colon;
117 cardName = cardinfo.readLine().stripWhiteSpace(); 120 cardName = cardinfo.readLine().stripWhiteSpace();
118 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); 121 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName );
119 if ( strSocket == "Socket" && colon == ':' ) 122 if ( strSocket == "Socket" && colon == ':' )
120 { 123 {
121 _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); 124 _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) );
122 } 125 }
123 else 126 else
124 { 127 {
125 continue; 128 continue;
126 } 129 }
127 } 130 }
128} 131}
129 132
130 133
131int OPcmciaSystem::count() const 134int OPcmciaSystem::count() const
132{ 135{
133 return _interfaces.count(); 136 return _interfaces.count();
134} 137}
135 138
136 139
137int OPcmciaSystem::cardCount() const 140int OPcmciaSystem::cardCount() const
138{ 141{
139 int nonEmpty = 0; 142 int nonEmpty = 0;
140 OPcmciaSystem::CardIterator it = iterator(); 143 OPcmciaSystem::CardIterator it = iterator();
141 while ( it.current() ) 144 while ( it.current() )
142 { 145 {
143 if ( !it.current()->isEmpty() ) nonEmpty++; 146 if ( !it.current()->isEmpty() ) nonEmpty++;
144 ++it; 147 ++it;
145 } 148 }
146 return nonEmpty; 149 return nonEmpty;
147} 150}
148 151
149 152
150OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) 153OPcmciaSocket* OPcmciaSystem::socket( unsigned int number )
151{ 154{
152 return _interfaces.at( number ); 155 return _interfaces.at( number );
153} 156}
154 157
155 158
156OPcmciaSystem* OPcmciaSystem::instance() 159OPcmciaSystem* OPcmciaSystem::instance()
157{ 160{
158 if ( !_instance ) _instance = new OPcmciaSystem(); 161 if ( !_instance ) _instance = new OPcmciaSystem();
159 return _instance; 162 return _instance;
160} 163}
161 164
162 165
163OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const 166OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const
164{ 167{
165 return OPcmciaSystem::CardIterator( _interfaces ); 168 return OPcmciaSystem::CardIterator( _interfaces );
166} 169}
167 170
168 171
169/*====================================================================================== 172/*======================================================================================
170 * OPcmciaSocket 173 * OPcmciaSocket
171 *======================================================================================*/ 174 *======================================================================================*/
172 175
173OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) 176OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name )
174 :QObject( parent, name ), _major( major ), _socket( socket ) 177 :QObject( parent, name ), _major( major ), _socket( socket )
175{ 178{
176 qDebug( "OPcmciaSocket::OPcmciaSocket()" ); 179 qDebug( "OPcmciaSocket::OPcmciaSocket()" );
177 init(); 180 init();
178} 181}
179 182
180 183
181OPcmciaSocket::~OPcmciaSocket() 184OPcmciaSocket::~OPcmciaSocket()
182{ 185{
183 qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); 186 qDebug( "OPcmciaSocket::~OPcmciaSocket()" );
184 cleanup(); 187 cleanup();
185} 188}
186 189
187 190
188/* internal */ void OPcmciaSocket::init() 191/* internal */ void OPcmciaSocket::init()
189{ 192{
190 // open control socket and gather file descriptor 193 // open control socket and gather file descriptor
191 if ( _major ) 194 if ( _major )
192 { 195 {
193 dev_t dev = makedev( _major, _socket ); 196 dev_t dev = makedev( _major, _socket );