-rw-r--r-- | noncore/tools/formatter/formatter.cpp | 131 | ||||
-rw-r--r-- | noncore/tools/formatter/formatter.h | 4 |
2 files changed, 108 insertions, 27 deletions
diff --git a/noncore/tools/formatter/formatter.cpp b/noncore/tools/formatter/formatter.cpp index 0dd42c8..983459c 100644 --- a/noncore/tools/formatter/formatter.cpp +++ b/noncore/tools/formatter/formatter.cpp | |||
@@ -300,4 +300,4 @@ void FormatterApp::doFormat() { | |||
300 | // outDlg->close(); | 300 | // outDlg->close(); |
301 | // if(outDlg) | 301 | // if(outDlg) |
302 | // delete outDlg; | 302 | // delete outDlg; |
303 | } | 303 | } |
@@ -326,10 +326,8 @@ void FormatterApp::fillCombos() { | |||
326 | } | 326 | } |
327 | deviceComboBox->insertItem(disk); | 327 | // deviceComboBox->insertItem(disk); |
328 | } | 328 | } |
329 | parsetab(); | 329 | parsetab("/etc/mtab"); |
330 | // parsetab("/etc/fstab"); | ||
330 | fileSystemsCombo->insertStringList( fsList,-1); | 331 | fileSystemsCombo->insertStringList( fsList,-1); |
331 | // for(int i = 0; i < fileSystemsCombo->count(); i++) { | 332 | deviceComboBox->insertStringList( deviceList,-1); |
332 | // if( fsType == fileSystemsCombo->text(i)) | ||
333 | // fileSystemsCombo->setCurrentItem(i); | ||
334 | // } | ||
335 | storageComboSelected(0); | 333 | storageComboSelected(0); |
@@ -409,3 +407,3 @@ void FormatterApp::editFstab() { | |||
409 | 407 | ||
410 | void FormatterApp::parsetab() { | 408 | void FormatterApp::parsetab(const QString &fileName) { |
411 | 409 | ||
@@ -414,3 +412,4 @@ void FormatterApp::parsetab() { | |||
414 | struct mntent *me; | 412 | struct mntent *me; |
415 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 413 | // if(fileName == "/etc/mtab") { |
414 | FILE *mntfp = setmntent( fileName.latin1(), "r" ); | ||
416 | if ( mntfp ) { | 415 | if ( mntfp ) { |
@@ -422,4 +421,7 @@ void FormatterApp::parsetab() { | |||
422 | & filesystemType.find("proc",0,TRUE) == -1 | 421 | & filesystemType.find("proc",0,TRUE) == -1 |
423 | & filesystemType.find("cramfs",0,TRUE) == -1) | 422 | & filesystemType.find("cramfs",0,TRUE) == -1 |
423 | & filesystemType.find("auto",0,TRUE) == -1) | ||
424 | fsList << filesystemType; | 424 | fsList << filesystemType; |
425 | deviceList << deviceName; | ||
426 | qDebug(deviceName+"::"+filesystemType); | ||
425 | fileSystemTypeList << deviceName+"::"+filesystemType; | 427 | fileSystemTypeList << deviceName+"::"+filesystemType; |
@@ -429,3 +431,3 @@ void FormatterApp::parsetab() { | |||
429 | endmntent( mntfp ); | 431 | endmntent( mntfp ); |
430 | 432 | // } else if(fileName == "/etc/fstab") { | |
431 | // QFile f("/etc/fstab"); | 433 | // QFile f("/etc/fstab"); |
@@ -435,12 +437,19 @@ void FormatterApp::parsetab() { | |||
435 | // while (! t.eof()) { | 437 | // while (! t.eof()) { |
436 | // s=t.readLine(); | 438 | // s=t.readLine(); |
437 | // s=s.simplifyWhiteSpace(); | 439 | // s=s.simplifyWhiteSpace(); |
438 | // if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { | 440 | // if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { |
439 | // s=s.remove(0,s.find(BLANK)+1 ); // devicename | 441 | // // = me->mnt_fsname; |
440 | // s=s.remove(0,s.find(BLANK)+1 ); // mountpoint | 442 | // QString filesystemType = me->mnt_type; |
441 | // s=s.remove(0,s.find(BLANK)+1 ); // fs | 443 | // QString deviceName = s.left(0,s.find(BLANK) ); |
442 | // } | 444 | // s=s.remove(0,s.find(BLANK)+1 ); // devicename |
445 | |||
446 | // s=s.remove(0,s.find(BLANK)+1 ); // mountpoint | ||
447 | // QStringt mountPoint= s.left(0,s.find(BLANK) ); | ||
448 | // s=s.remove(0,s.find(BLANK)+1 ); // fs | ||
449 | // QString filesystemType= s.left(0,s.find(BLANK) ); | ||
450 | // } | ||
443 | // } | 451 | // } |
444 | // } | 452 | // } |
445 | // f.close(); | 453 | // f.close(); |
454 | // } | ||
446 | } | 455 | } |
@@ -449,3 +458,3 @@ QString FormatterApp::getFileSystemType(const QString ¤tText) { | |||
449 | 458 | ||
450 | parsetab(); //why did TT forget filesystem type? | 459 | parsetab("/etc/mtab"); //why did TT forget filesystem type? |
451 | 460 | ||
@@ -463,3 +472,14 @@ bool FormatterApp::doFsck() { | |||
463 | 472 | ||
464 | QString selectedDevice = deviceComboBox->currentText(); | 473 | Output *outDlg; |
474 | QString selectedDevice; | ||
475 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) // lets test on something cheap | ||
476 | selectedDevice = deviceComboBox->currentText(); | ||
477 | #else | ||
478 | // currentText = diskDevice = "/dev/fd0"; | ||
479 | QString umountS = "umount -v /floppy 2>&1"; | ||
480 | QString remountS = "mount -v /floppy 2>&1"; | ||
481 | selectedDevice ="/dev/fd0"; | ||
482 | |||
483 | #endif | ||
484 | |||
465 | QString fsType = getFileSystemType((const QString &)selectedDevice); | 485 | QString fsType = getFileSystemType((const QString &)selectedDevice); |
@@ -469,6 +489,66 @@ bool FormatterApp::doFsck() { | |||
469 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; | 489 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; |
470 | cmd += selectedDevice; | 490 | cmd += selectedDevice + " 2>&1"; |
471 | 491 | ||
492 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | ||
493 | outDlg->showMaximized(); | ||
494 | outDlg->show(); | ||
495 | qApp->processEvents(); | ||
496 | FILE *fp; | ||
497 | char line[130]; | ||
498 | outDlg->OutputEdit->append( tr("Trying to umount.")); | ||
499 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
472 | 500 | ||
473 | return FALSE; | 501 | sleep(1); |
502 | // qDebug("Command is "+umountS); | ||
503 | fp = popen( (const char *) umountS, "r"); | ||
504 | // qDebug("%d", fp); | ||
505 | if ( !fp ) { | ||
506 | qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); | ||
507 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); | ||
508 | pclose(fp); | ||
509 | return false; | ||
510 | } else { | ||
511 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); | ||
512 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
513 | while ( fgets( line, sizeof line, fp)) { | ||
514 | if( ((QString)line).find("busy",0,TRUE) != -1) { | ||
515 | qDebug("Could not find '" + umountS); | ||
516 | QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); | ||
517 | pclose(fp); | ||
518 | return false; | ||
519 | } else { | ||
520 | QString lineStr = line; | ||
521 | lineStr=lineStr.left(lineStr.length()-1); | ||
522 | outDlg->OutputEdit->append(lineStr); | ||
523 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
524 | } | ||
525 | } | ||
526 | } | ||
527 | pclose(fp); | ||
528 | ///////////////////////////////////// | ||
529 | fp = popen( (const char *) cmd, "r"); | ||
530 | while ( fgets( line, sizeof line, fp)) { | ||
531 | if( ((QString)line).find("No such device",0,TRUE) != -1) { | ||
532 | qDebug("No such device '" + umountS); | ||
533 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); | ||
534 | pclose(fp); | ||
535 | // outDlg->OutputEdit->append("No such device"); | ||
536 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
537 | return false; | ||
538 | } else { | ||
539 | QString lineStr = line; | ||
540 | lineStr=lineStr.left(lineStr.length()-1); | ||
541 | outDlg->OutputEdit->append(lineStr); | ||
542 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
543 | } | ||
544 | } | ||
545 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | ||
546 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
547 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); | ||
548 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
549 | pclose(fp); | ||
550 | |||
551 | ///////////////////////////////////////// | ||
552 | |||
553 | return true; | ||
474 | } | 554 | } |
@@ -476,2 +556,3 @@ bool FormatterApp::doFsck() { | |||
476 | bool FormatterApp::doFsckCheck() { | 556 | bool FormatterApp::doFsckCheck() { |
557 | |||
477 | return FALSE; | 558 | return FALSE; |
diff --git a/noncore/tools/formatter/formatter.h b/noncore/tools/formatter/formatter.h index 871054d..960a68a 100644 --- a/noncore/tools/formatter/formatter.h +++ b/noncore/tools/formatter/formatter.h | |||
@@ -41,3 +41,3 @@ public: | |||
41 | QLineEdit* mountPointLineEdit; | 41 | QLineEdit* mountPointLineEdit; |
42 | QStringList fileSystemTypeList, fsList; | 42 | QStringList fileSystemTypeList, fsList, deviceList; |
43 | protected: | 43 | protected: |
@@ -47,3 +47,3 @@ protected: | |||
47 | void fillCombos(); | 47 | void fillCombos(); |
48 | void parsetab(); | 48 | void parsetab(const QString &); |
49 | bool doFdisk(); | 49 | bool doFdisk(); |