32 #include <k3process.h>
34 #include <kstandarddirs.h>
42 QString path = QLatin1String( qgetenv(
"PATH") );
43 if (!path.isEmpty()) path.append(QLatin1String(
":" ));
44 path.append(QLatin1String(
"/usr/sbin:/sbin" ));
48 return KGlobal::dirs()->findExe(e,
extPath);
77 QList<KFAction*> list;
82 d(new KFActionQueue_p)
116 if (!d->list.isEmpty() && d->list.first()==p)
118 d->list.removeFirst();
123 DEBUGS(
"Strange pointer received.");
124 emit
done(
this,
false);
130 DEBUGS(
"Starting action queue.");
136 emit
done(
this,
false);
140 KFAction *next = d->list.isEmpty() ? 0 : d->list.first();
143 emit
done(
this,
true);
147 kDebug(
KFAREA) <<
"Running action " << next->objectName() ;
151 QObject::connect(next,SIGNAL(
status(QString,
int)),
152 this,SIGNAL(
status(QString,
int)));
153 QTimer::singleShot(0,next,SLOT(
exec()));
165 const char *
const fd0H1440[] = {
"/dev/fd0u1440",
"/dev/floppy/0u1440",
"/dev/fd0h1440",
"/dev/fd0H1440", 0L } ;
166 const char *
const fd0D720[] = {
"/dev/fd0u720",
"/dev/floppy/0u720",
"/dev/fd0D720",
"/dev/fd0h720", 0L };
167 const char *
const fd0h1200[] = {
"/dev/fd0h1200",
"/dev/floppy/0h1200", 0L };
168 const char *
const fd0h360[] = {
"/dev/fd0u360",
"/dev/floppy/0u360",
"/dev/fd0h360",
"/dev/fd0d360", 0L };
170 const char *
const fd1H1440[] = {
"/dev/fd1u1440",
"/dev/floppy/1u1440",
"/dev/fd1h1440",
"/dev/fd1H1440", 0L } ;
171 const char *
const fd1D720[] = {
"/dev/fd1u720",
"/dev/floppy/1u720",
"/dev/fd1D720",
"/dev/fd1h720", 0L };
172 const char *
const fd1h1200[] = {
"/dev/fd1h1200",
"/dev/floppy/1h1200", 0L };
173 const char *
const fd1h360[] = {
"/dev/fd1u360",
"/dev/floppy/1u360",
"/dev/fd1h360",
"/dev/fd1d360", 0L };
175 const char *
const fd0auto[] = {
"/dev/fd0", 0L };
176 const char *
const fd1auto[] = {
"/dev/fd1", 0L };
182 const char *
const fd0[] = {
"/dev/fd0", 0L } ;
183 const char *
const fd1[] = {
"/dev/fd1", 0L } ;
203 { fd0H1440, 0, 1440, 80, 0 },
204 { fd1H1440, 1, 1440, 80, 0 },
205 { fd0D720, 0, 720, 80, 0 },
206 { fd1D720, 1, 720, 80, 0 },
207 { fd0h1200, 0, 1200, 80, 0 },
208 { fd1h1200, 1, 1200, 80, 0 },
209 { fd0h360, 0, 360, 40, 0 },
210 { fd1h360, 1, 360, 40, 0 },
211 { fd0auto, 0, 0, 80, 0 },
212 { fd1auto, 1, 0, 80, 0 },
219 { fd0, 0, 1440, 40, 0 },
220 { fd1, 1, 1440, 40, 0 },
221 { fd0, 0, 720, 40, 0 },
222 { fd1, 1, 720, 40, 0 },
223 { fd0, 0, 1200, 40, 0},
224 { fd1, 1, 1200, 40, 0},
225 { fd0, 0, 360, 40, 0},
226 { fd1, 1, 360, 40, 0},
259 const char *devicename = 0L;
264 if ((drive<0) || (drive>1))
266 emit
status(i18n(
"Unexpected drive number %1.", drive),-1);
271 for ( ; deviceinfo && (deviceinfo->
devices) ; deviceinfo++)
273 if (deviceinfo->
blocks != density)
278 emit
status(i18n(
"Unexpected density number %1.", density),-1);
283 for ( ; deviceinfo && (deviceinfo->
devices) ; deviceinfo++)
285 if (deviceinfo->
blocks != density)
287 if (deviceinfo->
drive == drive)
291 if (!deviceinfo || !deviceinfo->
devices)
293 emit
status(i18n(
"Cannot find a device for drive %1 and density %2.",
298 for (
const char*
const* devices=deviceinfo->
devices ;
299 *devices ; devices++)
301 if (access(*devices,W_OK)>=0)
303 kDebug(
KFAREA) <<
"Found device " << *devices ;
311 const QString str = i18n(
312 "Cannot access %1\nMake sure that the device exists and that "
313 "you have write permission to it.",QLatin1String( deviceinfo->
devices[0] ));
330 DEBUGS(
" Strange process exited.");
336 if (p->exitStatus() == 0)
338 emit
status(QString::null,100);
339 emit
done(
this,
true);
344 emit
done(
this,
false);
350 emit
done(
this,
false);
358 kDebug(
KFAREA) <<
"stdout:" << QString::fromLatin1(b,l) ;
370 connect(
theProcess,SIGNAL(processExited(K3Process*)),
372 connect(
theProcess,SIGNAL(receivedStdout(K3Process*,
char*,
int)),
374 connect(
theProcess,SIGNAL(receivedStderr(K3Process*,
char*,
int)),
377 theProcess->setEnvironment( QLatin1String(
"LC_ALL" ), QLatin1String(
"C" ) );
378 return theProcess->start(K3Process::NotifyOnExit,
379 K3Process::AllOutput);
391 setObjectName( QLatin1String(
"FDFormat" ));
412 emit
status( i18n(
"Internal error: device not correctly defined."), -1 );
413 emit
done(
this,
false);
419 emit
status(i18n(
"Cannot find fdformat."),-1);
420 emit
done(
this,
false);
439 << QLatin1String(
"-y" )
440 << QLatin1String(
"-f" )
442 #elif defined(ANY_LINUX)
451 emit
status(i18n(
"Could not start fdformat."),-1);
452 emit
done(
this,
false);
473 emit
status(QString::null,
482 s = QString::fromLatin1(b,l);
483 if (s.contains(QLatin1String(
"ioctl(FD_FORM)" )))
486 "Cannot access floppy or floppy drive.\n"
487 "Please insert a floppy and make sure that you "
488 "have selected a valid floppy drive."),-1);
491 if (s.indexOf(QLatin1String(
"/dev/" ))>=0)
498 #elif defined(ANY_LINUX)
499 s = QString::fromLatin1(b,l);
501 QRegExp regexp( QLatin1String(
"([0-9]+)" ) );
502 if ( s.startsWith( QLatin1String(
"bad data at cyl" ) ) || s.contains( QLatin1String(
"Problem reading cylinder" ) ) )
504 if ( regexp.indexIn( s ) > -1 )
506 const int track = regexp.cap(1).toInt();
507 emit
status(i18n(
"Low-level formatting error at track %1.", track), -1);
512 emit
status(i18n(
"Low-level formatting error: %1", s), -1);
516 else if (s.contains(QLatin1String(
"ioctl(FDFMTBEG)" )))
519 "Cannot access floppy or floppy drive.\n"
520 "Please insert a floppy and make sure that you "
521 "have selected a valid floppy drive."),-1);
524 else if (s.contains(QLatin1String(
"busy" )))
526 emit
status(i18n(
"Device busy.\nPerhaps you need to unmount the floppy first."),-1);
530 else if (s.contains(QLatin1String(
"ioctl" )))
532 emit
status(i18n(
"Low-level format error: %1", s),-1);
536 else if ( regexp.indexIn(s) > -1 )
539 const int p = regexp.cap(1).toInt();
540 if ((p>=0) && (p<deviceInfo->tracks))
542 emit
status(QString::null,
556 kDebug(
KFAREA) << k_funcinfo ;
558 setObjectName( QLatin1String(
"DD" ));
569 kDebug(
KFAREA) << k_funcinfo ;
573 emit
status( i18n(
"Internal error: device not correctly defined."), -1 );
574 emit
done(
this,
false );
580 emit
status( i18n(
"Cannot find dd."), -1 );
581 emit
done(
this,
false );
590 *
theProcess << QLatin1String(
"if=/dev/zero" ) ;
595 emit
status( i18n(
"Could not start dd."), -1 );
596 emit
done(
this,
false );
603 kDebug(
KFAREA) << k_funcinfo ;
607 kDebug(
KFAREA) <<
"Strange process exited." ;
617 emit
status(QString::null,100);
618 emit
done(
this,
true);
630 setObjectName( QLatin1String(
"FATFilesystem" ));
639 #elif defined(ANY_LINUX)
653 label=lbl.simplified();
670 emit
status( i18n(
"Internal error: device not correctly defined."), -1 );
671 emit
done(
this,
false);
677 emit
status(i18n(
"Cannot find a program to create FAT filesystems."),-1);
678 emit
done(
this,
false);
690 *p << QLatin1String(
"-L" ) <<
label ;
696 *p << QLatin1String(
"-n" ) <<
label ;
700 *p << QLatin1String(
"-c" );
708 emit
status(i18n(
"Cannot start FAT format program."),-1);
709 emit
done(
this,
false);
717 #elif defined(ANY_LINUX)
718 QString s ( QString::fromLatin1( b, l ) );
720 if (s.contains(QLatin1String(
"mounted file system" )))
722 emit
status(i18n(
"Floppy is mounted.\nYou need to unmount the floppy first."),-1);
725 else if (s.contains(QLatin1String(
"busy" )))
727 emit
status(i18n(
"Device busy.\nPerhaps you need to unmount the floppy first."),-1);
731 else if ( s.find(
"mkdosfs" ) != -1 )
743 QString UFSFilesystem::newfs = QString();
745 UFSFilesystem::UFSFilesystem(
QObject *parent) :
751 setObjectName( QLatin1String(
"UFSFilesystem" ));
754 bool UFSFilesystem::runtimeCheck()
760 return !newfs.isEmpty();
763 void UFSFilesystem::exec()
767 if ( deviceName.isEmpty() )
769 emit status( i18n(
"Internal error: device not correctly defined."), -1 );
770 emit done(
this,
false);
776 emit status(i18nc(
"BSD",
"Cannot find a program to create UFS filesystems."),-1);
777 emit done(
this,
false);
782 K3Process *p = theProcess =
new K3Process;
788 *p <<
"-T" << QString(
"fd%1").arg(deviceInfo->blocks);
794 emit status(i18nc(
"BSD",
"Cannot start UFS format program."),-1);
795 emit done(
this,
false);
809 setObjectName( QLatin1String(
"Ext2Filesystem" ));
818 return !newfs.isEmpty();
845 deviceName.isEmpty() )
847 emit
status( i18n(
"Internal error: device not correctly defined."), -1 );
848 emit
done(
this,
false);
854 emit
status(i18n(
"Cannot find a program to create ext2 filesystems."),-1);
855 emit
done(
this,
false);
864 if (
doVerify) *p << QLatin1String(
"-c" ) ;
871 emit
status(i18n(
"Cannot start ext2 format program."),-1);
872 emit
done(
this,
false);
880 #elif defined(ANY_LINUX)
881 QString s ( QString::fromLatin1( b, l ) );
883 if (s.contains(QLatin1String(
"mounted" )))
885 emit
status(i18n(
"Floppy is mounted.\nYou need to unmount the floppy first."),-1);
888 else if (s.contains(QLatin1String(
"busy" )))
890 emit
status(i18n(
"Device busy.\nPerhaps you need to unmount the floppy first."),-1);
899 QString MinixFilesystem::newfs = QString();
901 MinixFilesystem::MinixFilesystem(
QObject *parent) :
907 setObjectName( QLatin1String(
"Minix2Filesystem" ));
910 bool MinixFilesystem::runtimeCheck()
916 return !newfs.isEmpty();
919 bool MinixFilesystem::configure(
bool v,
bool l,
const QString &lbl)
935 void MinixFilesystem::exec()
939 if ( deviceName.isEmpty() )
941 emit status( i18n(
"Internal error: device not correctly defined."), -1 );
942 emit done(
this,
false);
948 emit status(i18n(
"Cannot find a program to create Minix filesystems."),-1);
949 emit done(
this,
false);
954 K3Process *p = theProcess =
new K3Process;
959 if (doVerify) *p << QLatin1String(
"-c" ) ;
965 emit status(i18n(
"Cannot start Minix format program."),-1);
966 emit done(
this,
false);
970 void MinixFilesystem::processStdOut(K3Process *,
char *b,
int l)
972 QString s ( QString::fromLatin1( b, l ) );
974 if (s.contains(QLatin1String(
"mounted" )))
976 emit status(i18n(
"Floppy is mounted.\nYou need to unmount the floppy first."),-1);
979 else if (s.contains(QLatin1String(
"busy" )))
981 emit status(i18n(
"Device busy.\nPerhaps you need to unmount the floppy first."),-1);
988 #include "format.moc"
virtual void processStdOut(K3Process *, char *, int)
Provide handling of stdout.
void actionDone(KFAction *, bool)
virtual void quit()
Quit aborts the action.
virtual void processStdOut(K3Process *, char *b, int l)
Parse output.
virtual void quit()
Kills the running process, if one exists.
void queue(KFAction *)
Add a KFAction to the queue.
void done(KFAction *me, bool success)
done() should always be emitted with this as first parameter, to avoid sender() magic and the like...
const char *const * devices
KFAction(QObject *parent=0L)
virtual void processDone(K3Process *)
Provide handling of the exit of the external program.
virtual void processDone(K3Process *)
Provide handling of the exit of the external program.
bool startProcess()
Sets up connections, calls K3Process::run().
static QString m_ddName
path to executable.
bool configure(bool verify, bool label, const QString &l)
newfs_msdos(1) doesn't support an additional verify, but Linux mkdosfs(1) does.
virtual void processStdErr(K3Process *, char *, int)
Provide handling stderr.
Ext2Filesystem(QObject *parent=0L)
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
Description structure for floppy devices.
DDZeroOut(QObject *parent=0L)
void status(const QString &msg, int progress)
Emit this signal to inform the user of interesting changes; setting msg to an empty string doesn't ch...
QString deviceName
Name of the device.
bool configureDevice(int driveno, int density)
ConfigureDevice() needs to be called prior to exec() or exec() will fail; this indicates which drive ...
static bool runtimeCheck()
virtual void processStdOut(K3Process *, char *b, int l)
Parse output.
const fdinfo * deviceInfo
Configuration info (Pointer into list of "/dev/..." entries)
FloppyAction(QObject *parent=0L)
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
KFActionQueue(QObject *parent=0L)
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
Concrete action for running a single external program.
static bool runtimeCheck()
bool configure(bool verify, bool label, const QString &l)
Same args as FATFilesystem::configure.
QString theProcessName
human-readable
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
FATFilesystem(QObject *parent=0L)
Abstract base class of actions to be undertaken.
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
static bool runtimeCheck()
Concrete classes can provide a runtimeCheck function (heck, this is static, so the name is up to you)...