00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "format.h"
00024
00025 #include <unistd.h>
00026 #include <stdlib.h>
00027
00028 #include <QTimer>
00029 #include <QRegExp>
00030
00031 #include <klocale.h>
00032 #include <k3process.h>
00033 #include <kdebug.h>
00034 #include <kstandarddirs.h>
00035
00036 static QString extPath = QString();
00037
00038 QString findExecutable(const QString &e)
00039 {
00040 if (extPath.isEmpty())
00041 {
00042 QString path = getenv("PATH");
00043 if (!path.isEmpty()) path.append(":");
00044 path.append("/usr/sbin:/sbin");
00045 extPath = path;
00046 }
00047
00048 return KGlobal::dirs()->findExe(e, extPath);
00049 }
00050
00051
00052 KFAction::KFAction(QObject *parent) :
00053 QObject(parent)
00054 {
00055 DEBUGSETUP;
00056 }
00057
00058 KFAction::~KFAction()
00059 {
00060 DEBUGSETUP;
00061 quit();
00062 }
00063
00064 void KFAction::quit()
00065 {
00066 DEBUGSETUP;
00067 }
00068
00069 void KFAction::exec()
00070 {
00071 DEBUGSETUP;
00072 }
00073
00074 class KFActionQueue_p
00075 {
00076 public:
00077 QList<KFAction*> list;
00078 } ;
00079
00080 KFActionQueue::KFActionQueue(QObject *parent) :
00081 KFAction(parent),
00082 d(new KFActionQueue_p)
00083 {
00084 DEBUGSETUP;
00085 }
00086
00087 KFActionQueue::~KFActionQueue()
00088 {
00089 DEBUGSETUP;
00090 qDeleteAll(d->list);
00091 d->list.clear();
00092 delete d;
00093 }
00094
00095 void KFActionQueue::queue(KFAction *p)
00096 {
00097 DEBUGSETUP;
00098
00099 d->list.append(p);
00100 DEBUGS(p->objectName());
00101 }
00102
00103 void KFActionQueue::exec()
00104 {
00105 DEBUGSETUP;
00106
00107 actionDone(0L,true);
00108 }
00109
00110 void KFActionQueue::actionDone(KFAction *p,bool success)
00111 {
00112 DEBUGSETUP;
00113
00114 if (p)
00115 {
00116 if (d->list.first()==p)
00117 {
00118 d->list.removeFirst();
00119
00120 }
00121 else
00122 {
00123 DEBUGS( "Strange pointer received.");
00124 emit done(this,false);
00125 return;
00126 }
00127 }
00128 else
00129 {
00130 DEBUGS("Starting action queue.");
00131 }
00132
00133 if (!success)
00134 {
00135 DEBUGS("Action failed.");
00136 emit done(this,false);
00137 return;
00138 }
00139
00140 KFAction *next = d->list.first();
00141 if (!next)
00142 {
00143 emit done(this,true);
00144 }
00145 else
00146 {
00147 kDebug(KFAREA) << "Running action " << next->objectName() ;
00148 QObject::connect(next,SIGNAL(done(KFAction *,bool)),
00149 this,SLOT(actionDone(KFAction *,bool)));
00150
00151 QObject::connect(next,SIGNAL(status(const QString &,int)),
00152 this,SIGNAL(status(const QString &,int)));
00153 QTimer::singleShot(0,next,SLOT(exec()));
00154 }
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 #ifdef ANY_LINUX
00164
00165 const char *fd0H1440[] = { "/dev/fd0u1440", "/dev/floppy/0u1440", "/dev/fd0h1440", "/dev/fd0H1440", 0L } ;
00166 const char *fd0D720[] = { "/dev/fd0u720", "/dev/floppy/0u720", "/dev/fd0D720", "/dev/fd0h720", 0L };
00167 const char *fd0h1200[] = { "/dev/fd0h1200", "/dev/floppy/0h1200", 0L };
00168 const char *fd0h360[] = { "/dev/fd0u360", "/dev/floppy/0u360", "/dev/fd0h360", "/dev/fd0d360", 0L };
00169
00170 const char *fd1H1440[] = { "/dev/fd1u1440", "/dev/floppy/1u1440","/dev/fd1h1440", "/dev/fd1H1440", 0L } ;
00171 const char *fd1D720[] = { "/dev/fd1u720", "/dev/floppy/1u720", "/dev/fd1D720", "/dev/fd1h720", 0L };
00172 const char *fd1h1200[] = { "/dev/fd1h1200", "/dev/floppy/1h1200", 0L };
00173 const char *fd1h360[] = { "/dev/fd1u360", "/dev/floppy/1u360","/dev/fd1h360", "/dev/fd1d360", 0L };
00174
00175 const char *fd0auto[] = { "/dev/fd0", 0L };
00176 const char *fd1auto[] = { "/dev/fd1", 0L };
00177
00178 #endif
00179
00180
00181 #ifdef ANY_BSD
00182 const char *fd0[] = { "/dev/fd0", 0L } ;
00183 const char *fd1[] = { "/dev/fd1", 0L } ;
00184 #endif
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 fdinfo fdtable[] =
00200 {
00201 #ifdef ANY_LINUX
00202
00203 { fd0H1440, 0, 1440, 80, 0 },
00204 { fd1H1440, 1, 1440, 80, 0 },
00205 { fd0D720, 0, 720, 80, 0 },
00206 { fd1D720, 1, 720, 80, 0 },
00207 { fd0h1200, 0, 1200, 80, 0 },
00208 { fd1h1200, 1, 1200, 80, 0 },
00209 { fd0h360, 0, 360, 40, 0 },
00210 { fd1h360, 1, 360, 40, 0 },
00211 { fd0auto, 0, 0, 80, 0 },
00212 { fd1auto, 1, 0, 80, 0 },
00213 #endif
00214
00215 #ifdef ANY_BSD
00216
00217
00218
00219 { fd0, 0, 1440, 40, 0 },
00220 { fd1, 1, 1440, 40, 0 },
00221 { fd0, 0, 720, 40, 0 },
00222 { fd1, 1, 720, 40, 0 },
00223 { fd0, 0, 1200, 40, 0},
00224 { fd1, 1, 1200, 40, 0},
00225 { fd0, 0, 360, 40, 0},
00226 { fd1, 1, 360, 40, 0},
00227 #endif
00228 { 0L, 0, 0, 0, 0 }
00229 } ;
00230
00231
00232 FloppyAction::FloppyAction(QObject *p) :
00233 KFAction(p),
00234 deviceInfo(0L),
00235 theProcess(0L)
00236 {
00237 DEBUGSETUP;
00238 }
00239
00240 void FloppyAction::quit()
00241 {
00242 DEBUGSETUP;
00243 delete theProcess;
00244 theProcess=0L;
00245
00246 KFAction::quit();
00247 }
00248
00249 bool FloppyAction::configureDevice( const QString& newDeviceName )
00250 {
00251 deviceInfo = 0;
00252 deviceName = newDeviceName;
00253 return true;
00254 }
00255
00256 bool FloppyAction::configureDevice(int drive,int density)
00257 {
00258 DEBUGSETUP;
00259 const char *devicename = 0L;
00260
00261 deviceInfo=0L;
00262 deviceName = QString();
00263
00264 if ((drive<0) || (drive>1))
00265 {
00266 emit status(i18n("Unexpected drive number %1.", drive),-1);
00267 return false;
00268 }
00269
00270 fdinfo *deviceinfo = fdtable;
00271 for ( ; deviceinfo && (deviceinfo->devices) ; deviceinfo++)
00272 {
00273 if (deviceinfo->blocks != density)
00274 continue;
00275 }
00276 if (!deviceinfo)
00277 {
00278 emit status(i18n("Unexpected density number %1.", density),-1);
00279 return false;
00280 }
00281
00282 deviceinfo = fdtable;
00283 for ( ; deviceinfo && (deviceinfo->devices) ; deviceinfo++)
00284 {
00285 if (deviceinfo->blocks != density)
00286 continue;
00287 if (deviceinfo->drive == drive)
00288 break;
00289 }
00290
00291 if (!deviceinfo || !deviceinfo->devices)
00292 {
00293 emit status(i18n("Cannot find a device for drive %1 and density %2.",
00294 drive, density),-1);
00295 return false;
00296 }
00297
00298 for (const char **devices=deviceinfo->devices ;
00299 *devices ; devices++)
00300 {
00301 if (access(*devices,W_OK)>=0)
00302 {
00303 kDebug(KFAREA) << "Found device " << *devices ;
00304 devicename=*devices;
00305 break;
00306 }
00307 }
00308
00309 if (!devicename)
00310 {
00311 const QString str = i18n(
00312 "Cannot access %1\nMake sure that the device exists and that "
00313 "you have write permission to it.", deviceinfo->devices[0]);
00314 emit status(str,-1);
00315 return false;
00316 }
00317
00318 deviceName = devicename;
00319 deviceInfo = deviceinfo;
00320
00321 return true;
00322 }
00323
00324 void FloppyAction::processDone(K3Process *p)
00325 {
00326 DEBUGSETUP;
00327
00328 if (p!=theProcess)
00329 {
00330 DEBUGS(" Strange process exited.");
00331 return;
00332 }
00333
00334 if (p->normalExit())
00335 {
00336 if (p->exitStatus() == 0)
00337 {
00338 emit status(QString::null,100);
00339 emit done(this,true);
00340 }
00341 else
00342 {
00343 emit status(i18n("The program %1 terminated with an error.", theProcessName),100);
00344 emit done(this,false);
00345 }
00346 }
00347 else
00348 {
00349 emit status(i18n("The program %1 terminated abnormally.", theProcessName),100);
00350 emit done(this,false);
00351 }
00352 }
00353
00354 void FloppyAction::processStdOut(K3Process *, char *b, int l)
00355 {
00356 Q_UNUSED(b);
00357 Q_UNUSED(l);
00358 kDebug(KFAREA) << "stdout:" << QString::fromLatin1(b,l) ;
00359 }
00360
00361 void FloppyAction::processStdErr(K3Process *p, char *b, int l)
00362 {
00363 processStdOut(p,b,l);
00364 }
00365
00366 bool FloppyAction::startProcess()
00367 {
00368 DEBUGSETUP;
00369
00370 connect(theProcess,SIGNAL(processExited(K3Process *)),
00371 this,SLOT(processDone(K3Process *)));
00372 connect(theProcess,SIGNAL(receivedStdout(K3Process *,char *,int)),
00373 this,SLOT(processStdOut(K3Process *,char *,int)));
00374 connect(theProcess,SIGNAL(receivedStderr(K3Process *,char *,int)),
00375 this,SLOT(processStdErr(K3Process *,char *,int)));
00376
00377 theProcess->setEnvironment( "LC_ALL", "C" );
00378 return theProcess->start(K3Process::NotifyOnExit,
00379 K3Process::AllOutput);
00380 }
00381
00382
00383 QString FDFormat::fdformatName = QString();
00384
00385 FDFormat::FDFormat(QObject *p) :
00386 FloppyAction(p),
00387 doVerify(true)
00388 {
00389 DEBUGSETUP;
00390 theProcessName = QString::fromLatin1("fdformat");
00391 setObjectName("FDFormat");
00392 }
00393
00394 bool FDFormat::runtimeCheck()
00395 {
00396 fdformatName = findExecutable("fdformat");
00397 return (!fdformatName.isEmpty());
00398 }
00399
00400 bool FDFormat::configure(bool v)
00401 {
00402 doVerify=v;
00403 return true;
00404 }
00405
00406 void FDFormat::exec()
00407 {
00408 DEBUGSETUP;
00409
00410 if ( !deviceInfo || deviceName.isEmpty() )
00411 {
00412 emit status( i18n("Internal error: device not correctly defined."), -1 );
00413 emit done(this,false);
00414 return;
00415 }
00416
00417 if (fdformatName.isEmpty())
00418 {
00419 emit status(i18n("Cannot find fdformat."),-1);
00420 emit done(this,false);
00421 return;
00422 }
00423
00424 if (theProcess) delete theProcess;
00425 theProcess = new K3Process;
00426
00427 formatTrackCount=0;
00428
00429 *theProcess << fdformatName ;
00430
00431
00432 if (!doVerify)
00433 {
00434 *theProcess << "-n";
00435 }
00436
00437 #ifdef ANY_BSD
00438 *theProcess
00439 << "-y"
00440 << "-f"
00441 << QString::number(deviceInfo->blocks) ;
00442 #elif defined(ANY_LINUX)
00443
00444 #endif
00445
00446
00447 *theProcess << deviceName;
00448
00449 if (!startProcess())
00450 {
00451 emit status(i18n("Could not start fdformat."),-1);
00452 emit done(this,false);
00453 }
00454
00455
00456 }
00457
00458
00459
00460
00461
00462
00463
00464 void FDFormat::processStdOut(K3Process *, char *b, int l)
00465 {
00466 DEBUGSETUP;
00467 QString s;
00468
00469 #ifdef ANY_BSD
00470 if (b[0]=='F')
00471 {
00472 formatTrackCount++;
00473 emit status(QString::null,
00474 formatTrackCount * 100 / deviceInfo->tracks);
00475 }
00476 else if (b[0]=='E')
00477 {
00478 emit status(i18n("Error formatting track %1.", formatTrackCount),-1);
00479 }
00480 else
00481 {
00482 s = QString::fromLatin1(b,l);
00483 if (s.contains("ioctl(FD_FORM)"))
00484 {
00485 emit status (i18n(
00486 "Cannot access floppy or floppy drive.\n"
00487 "Please insert a floppy and make sure that you "
00488 "have selected a valid floppy drive."),-1);
00489 return;
00490 }
00491 if (s.indexOf("/dev/")>=0)
00492 {
00493 emit status(s,-1);
00494 return;
00495 }
00496 DEBUGS(s);
00497 }
00498 #elif defined(ANY_LINUX)
00499 s = QString::fromLatin1(b,l);
00500 DEBUGS(s);
00501 QRegExp regexp( "([0-9]+)" );
00502 if ( s.startsWith( "bad data at cyl" ) || s.contains( "Problem reading cylinder" ) )
00503 {
00504 if ( regexp.indexIn( s ) > -1 )
00505 {
00506 const int track = regexp.cap(1).toInt();
00507 emit status(i18n("Low-level formatting error at track %1.", track), -1);
00508 }
00509 else
00510 {
00511
00512 emit status(i18n("Low-level formatting error: %1", s), -1);
00513 }
00514 return;
00515 }
00516 else if (s.contains("ioctl(FDFMTBEG)"))
00517 {
00518 emit status (i18n(
00519 "Cannot access floppy or floppy drive.\n"
00520 "Please insert a floppy and make sure that you "
00521 "have selected a valid floppy drive."),-1);
00522 return;
00523 }
00524 else if (s.contains("busy"))
00525 {
00526 emit status(i18n("Device busy.\nPerhaps you need to unmount the floppy first."),-1);
00527 return;
00528 }
00529
00530 else if (s.contains("ioctl"))
00531 {
00532 emit status(i18n("Low-level format error: %1", s),-1);
00533 return;
00534 }
00535
00536 else if ( regexp.indexIn(s) > -1 )
00537 {
00538
00539 const int p = regexp.cap(1).toInt();
00540 if ((p>=0) && (p<deviceInfo->tracks))
00541 {
00542 emit status(QString::null,
00543 p * 100 / deviceInfo->tracks);
00544 }
00545 }
00546 #endif
00547 return;
00548 }
00549
00550
00551 QString DDZeroOut::m_ddName = QString();
00552
00553 DDZeroOut::DDZeroOut(QObject *p) :
00554 FloppyAction(p)
00555 {
00556 kDebug(KFAREA) << (__PRETTY_FUNCTION__) ;
00557 theProcessName = QString::fromLatin1("dd");
00558 setObjectName("DD");
00559 }
00560
00561 bool DDZeroOut::runtimeCheck()
00562 {
00563 m_ddName = findExecutable("dd");
00564 return (!m_ddName.isEmpty());
00565 }
00566
00567 void DDZeroOut::exec()
00568 {
00569 kDebug(KFAREA) << (__PRETTY_FUNCTION__) ;
00570
00571 if ( deviceName.isEmpty() )
00572 {
00573 emit status( i18n("Internal error: device not correctly defined."), -1 );
00574 emit done( this, false );
00575 return;
00576 }
00577
00578 if ( m_ddName.isEmpty() )
00579 {
00580 emit status( i18n("Cannot find dd."), -1 );
00581 emit done( this, false );
00582 return;
00583 }
00584
00585 delete theProcess;
00586 theProcess = new K3Process;
00587
00588 *theProcess << m_ddName ;
00589
00590 *theProcess << "if=/dev/zero" ;
00591 *theProcess << "of="+deviceName;
00592
00593 if ( !startProcess() )
00594 {
00595 emit status( i18n("Could not start dd."), -1 );
00596 emit done( this, false );
00597 }
00598
00599 }
00600
00601 void DDZeroOut::processDone(K3Process *p)
00602 {
00603 kDebug(KFAREA) << (__PRETTY_FUNCTION__) ;
00604
00605 if (p!=theProcess)
00606 {
00607 kDebug(KFAREA) << "Strange process exited." ;
00608 return;
00609 }
00610
00617 emit status(QString::null,100);
00618 emit done(this,true);
00619 }
00620
00621
00622 QString FATFilesystem::newfs_fat = QString();
00623
00624 FATFilesystem::FATFilesystem(QObject *parent) :
00625 FloppyAction(parent)
00626 {
00627 DEBUGSETUP;
00628 runtimeCheck();
00629 theProcessName=newfs_fat;
00630 setObjectName("FATFilesystem");
00631 }
00632
00633 bool FATFilesystem::runtimeCheck()
00634 {
00635 DEBUGSETUP;
00636
00637 #ifdef ANY_BSD
00638 newfs_fat = findExecutable("newfs_msdos");
00639 #elif defined(ANY_LINUX)
00640 newfs_fat = findExecutable("mkdosfs");
00641 #else
00642 return false;
00643 #endif
00644
00645 return !newfs_fat.isEmpty();
00646 }
00647
00648 bool FATFilesystem::configure(bool v,bool l,const QString &lbl)
00649 {
00650 doVerify=v;
00651 doLabel=l;
00652 if (l)
00653 label=lbl.simplified();
00654 else
00655 label.clear();
00656
00657 return true;
00658 }
00659
00660 void FATFilesystem::exec()
00661 {
00662 DEBUGSETUP;
00663
00664 if (
00665 #ifdef ANY_BSD
00666 !deviceInfo ||
00667 #endif
00668 deviceName.isEmpty())
00669 {
00670 emit status( i18n("Internal error: device not correctly defined."), -1 );
00671 emit done(this,false);
00672 return;
00673 }
00674
00675 if (newfs_fat.isEmpty())
00676 {
00677 emit status(i18n("Cannot find a program to create FAT filesystems."),-1);
00678 emit done(this,false);
00679 return;
00680 }
00681
00682 if (theProcess) delete theProcess;
00683 K3Process *p = theProcess = new K3Process;
00684
00685 *p << newfs_fat;
00686 #ifdef ANY_BSD
00687 *p << "-f" << QString::number(deviceInfo->blocks);
00688 if (doLabel)
00689 {
00690 *p << "-L" << label ;
00691 }
00692 #else
00693 #ifdef ANY_LINUX
00694 if (doLabel)
00695 {
00696 *p << "-n" << label ;
00697 }
00698 if (doVerify)
00699 {
00700 *p << "-c";
00701 }
00702 #endif
00703 #endif
00704 *p << deviceName ;
00705
00706 if (!startProcess())
00707 {
00708 emit status(i18n("Cannot start FAT format program."),-1);
00709 emit done(this,false);
00710 }
00711 }
00712
00713 void FATFilesystem::processStdOut(K3Process *, char *b, int l)
00714 {
00715 #ifdef ANY_BSD
00716
00717 #elif defined(ANY_LINUX)
00718 QString s ( QString::fromLatin1( b, l ) );
00719 kDebug(KFAREA) << s ;
00720 if (s.contains("mounted file system"))
00721 {
00722 emit status(i18n("Floppy is mounted.\nYou need to unmount the floppy first."),-1);
00723 return;
00724 }
00725 else if (s.contains("busy"))
00726 {
00727 emit status(i18n("Device busy.\nPerhaps you need to unmount the floppy first."),-1);
00728 return;
00729 }
00730 # if 0
00731 else if ( s.find( "mkdosfs" ) != -1 )
00732 {
00733 emit status( s, -1 );
00734 return;
00735 }
00736 # endif
00737 #endif
00738 }
00739
00740
00741 #ifdef ANY_BSD
00742
00743 QString UFSFilesystem::newfs = QString();
00744
00745 UFSFilesystem::UFSFilesystem(QObject *parent) :
00746 FloppyAction(parent)
00747 {
00748 DEBUGSETUP;
00749 runtimeCheck();
00750 theProcessName=newfs;
00751 setObjectName("UFSFilesystem");
00752 }
00753
00754 bool UFSFilesystem::runtimeCheck()
00755 {
00756 DEBUGSETUP;
00757
00758 newfs = findExecutable("newfs");
00759
00760 return !newfs.isEmpty();
00761 }
00762
00763 void UFSFilesystem::exec()
00764 {
00765 DEBUGSETUP;
00766
00767 if ( deviceName.isEmpty() )
00768 {
00769 emit status( i18n("Internal error: device not correctly defined."), -1 );
00770 emit done(this,false);
00771 return;
00772 }
00773
00774 if (newfs.isEmpty())
00775 {
00776 emit status(i18nc("BSD", "Cannot find a program to create UFS filesystems."),-1);
00777 emit done(this,false);
00778 return;
00779 }
00780
00781 if (theProcess) delete theProcess;
00782 K3Process *p = theProcess = new K3Process;
00783
00784 *p << newfs;
00785
00786
00787 if ( deviceInfo )
00788 *p << "-T" << QString("fd%1").arg(deviceInfo->blocks);
00789
00790 *p << deviceName;
00791
00792 if (!startProcess())
00793 {
00794 emit status(i18nc("BSD", "Cannot start UFS format program."),-1);
00795 emit done(this,false);
00796 }
00797 }
00798 #endif
00799
00800
00801 QString Ext2Filesystem::newfs = QString();
00802
00803 Ext2Filesystem::Ext2Filesystem(QObject *parent) :
00804 FloppyAction(parent)
00805 {
00806 DEBUGSETUP;
00807 runtimeCheck();
00808 theProcessName="mke2fs";
00809 setObjectName("Ext2Filesystem");
00810 }
00811
00812 bool Ext2Filesystem::runtimeCheck()
00813 {
00814 DEBUGSETUP;
00815
00816 newfs = findExecutable("mke2fs");
00817
00818 return !newfs.isEmpty();
00819 }
00820
00821 bool Ext2Filesystem::configure(bool v,bool l,const QString &lbl)
00822 {
00823 doVerify=v;
00824 doLabel=l;
00825 if (l)
00826 {
00827 label=lbl.trimmed();
00828 }
00829 else
00830 {
00831 label.clear();
00832 }
00833
00834 return true;
00835 }
00836
00837 void Ext2Filesystem::exec()
00838 {
00839 DEBUGSETUP;
00840
00841 if (
00842 #ifdef ANY_BSD
00843 !deviceInfo ||
00844 #endif
00845 deviceName.isEmpty() )
00846 {
00847 emit status( i18n("Internal error: device not correctly defined."), -1 );
00848 emit done(this,false);
00849 return;
00850 }
00851
00852 if (newfs.isEmpty())
00853 {
00854 emit status(i18n("Cannot find a program to create ext2 filesystems."),-1);
00855 emit done(this,false);
00856 return;
00857 }
00858
00859 if (theProcess) delete theProcess;
00860 K3Process *p = theProcess = new K3Process;
00861
00862 *p << newfs;
00863 *p << "-q";
00864 if (doVerify) *p << "-c" ;
00865 if (doLabel) *p << "-L" << label ;
00866
00867 *p << deviceName ;
00868
00869 if (!startProcess())
00870 {
00871 emit status(i18n("Cannot start ext2 format program."),-1);
00872 emit done(this,false);
00873 }
00874 }
00875
00876 void Ext2Filesystem::processStdOut(K3Process *, char *b, int l)
00877 {
00878 #ifdef ANY_BSD
00879
00880 #elif defined(ANY_LINUX)
00881 QString s ( QString::fromLatin1( b, l ) );
00882 kDebug(KFAREA) << s ;
00883 if (s.contains("mounted"))
00884 {
00885 emit status(i18n("Floppy is mounted.\nYou need to unmount the floppy first."),-1);
00886 return;
00887 }
00888 else if (s.contains("busy"))
00889 {
00890 emit status(i18n("Device busy.\nPerhaps you need to unmount the floppy first."),-1);
00891 return;
00892 }
00893 #endif
00894 }
00895
00896
00897
00898 #ifdef ANY_LINUX
00899 QString MinixFilesystem::newfs = QString();
00900
00901 MinixFilesystem::MinixFilesystem(QObject *parent) :
00902 FloppyAction(parent)
00903 {
00904 DEBUGSETUP;
00905 runtimeCheck();
00906 theProcessName="mkfs.minix";
00907 setObjectName("Minix2Filesystem");
00908 }
00909
00910 bool MinixFilesystem::runtimeCheck()
00911 {
00912 DEBUGSETUP;
00913
00914 newfs = findExecutable("mkfs.minix");
00915
00916 return !newfs.isEmpty();
00917 }
00918
00919 bool MinixFilesystem::configure(bool v,bool l,const QString &lbl)
00920 {
00921 doVerify=v;
00922 doLabel=l;
00923 if (l)
00924 {
00925 label=lbl.trimmed();
00926 }
00927 else
00928 {
00929 label.clear();
00930 }
00931
00932 return true;
00933 }
00934
00935 void MinixFilesystem::exec()
00936 {
00937 DEBUGSETUP;
00938
00939 if ( deviceName.isEmpty() )
00940 {
00941 emit status( i18n("Internal error: device not correctly defined."), -1 );
00942 emit done(this,false);
00943 return;
00944 }
00945
00946 if (newfs.isEmpty())
00947 {
00948 emit status(i18n("Cannot find a program to create Minix filesystems."),-1);
00949 emit done(this,false);
00950 return;
00951 }
00952
00953 if (theProcess) delete theProcess;
00954 K3Process *p = theProcess = new K3Process;
00955
00956 *p << newfs;
00957
00958
00959 if (doVerify) *p << "-c" ;
00960
00961 *p << deviceName ;
00962
00963 if (!startProcess())
00964 {
00965 emit status(i18n("Cannot start Minix format program."),-1);
00966 emit done(this,false);
00967 }
00968 }
00969
00970 void MinixFilesystem::processStdOut(K3Process *, char *b, int l)
00971 {
00972 QString s ( QString::fromLatin1( b, l ) );
00973 kDebug(KFAREA) << s ;
00974 if (s.contains("mounted"))
00975 {
00976 emit status(i18n("Floppy is mounted.\nYou need to unmount the floppy first."),-1);
00977 return;
00978 }
00979 else if (s.contains("busy"))
00980 {
00981 emit status(i18n("Device busy.\nPerhaps you need to unmount the floppy first."),-1);
00982 return;
00983 }
00984 }
00985
00986 #endif
00987
00988 #include "format.moc"