• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kfloppy

zip.cpp

Go to the documentation of this file.
00001 /*
00002     
00003     This file is part of the KFloppy program, part of the KDE project
00004   
00005     Copyright (C) 2002 by Adriaan de Groot
00006   
00007   
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012   
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017   
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021   
00022 */
00023 
00024 #include <sys/types.h>
00025 #include <signal.h>
00026 
00027 #include <stdlib.h>
00028 #include <ctype.h>
00029 
00030 #include "debug.h"
00031 #include "zip.moc"
00032 
00033 #include <QCheckBox>
00034 #include <QTimer>
00035 #include <QGridLayout>
00036 
00037 #include <klocale.h>
00038 #include <k3process.h>
00039 #include <kconfig.h>
00040 
00041 ZipFormat::ZipFormat(QWidget *w,const char *n) :
00042     DiskFormat(w,n),
00043     zeroWholeDisk(0L),
00044     p(0L),
00045     formatStep(0),
00046     statusTimer(0L)
00047 {
00048     DEBUGSETUP;
00049 
00050     QGridLayout *grid = new QGridLayout(this);
00051     grid->setSpacing(10);
00052 
00053     zeroWholeDisk = new QCheckBox(i18n("Zero entire disk"),this);
00054     zeroWholeDisk->setWhatsThis(
00055         i18n("Try to write zeroes to the entire disk "
00056             "before adding a filesystem, in order "
00057             "to check the disk's integrity."));
00058     grid->addWidget(zeroWholeDisk,0,0);
00059     enableSoftUpdates = new QCheckBox(i18n("Enable softupdates"),this);
00060     grid->addWidget(enableSoftUpdates,1,0);
00061 
00062     // Remember the stretch at the bottom to clear
00063     // up layour problems when this widget is smaller
00064     // than others in the stack.
00065     //
00066     grid->addItem( new QSpacerItem( 0,10), 2, 0 );
00067     grid->setRowStretch(2,100);
00068 
00069     endInit();
00070 }
00071 
00072 const char fslabel[] = I18N_NOOP("UFS Zip100");
00073 
00074 FilesystemList ZipFormat::FSLabels() const
00075 {
00076     FilesystemList l;
00077     // THis isn't a basic format anywhere, I don't think.
00078     l.append(new FilesystemData(i18n(fslabel),0xefc87329,(DiskFormat *)this));
00079     return l;
00080 }
00081 
00082 /* static */ bool ZipFormat::runtimeCheck()
00083 {
00084     DEBUGSETUP;
00085     dd = findExecutable("dd");
00086     newfs = findExecutable("newfs");
00087     return !newfs.isEmpty() && !dd.isEmpty();
00088 }
00089 
00090 /* static */ QString ZipFormat::dd;
00091 /* static */ QString ZipFormat::newfs;
00092 
00093 /* virtual slot */ void ZipFormat::setEnabled(bool b)
00094 {
00095     zeroWholeDisk->setEnabled(b);
00096     enableSoftUpdates->setEnabled(b);
00097 }
00098 
00099 /* virtual */  void ZipFormat::readSettings(KConfig *c)
00100 {
00101     c->setGroup(fslabel);
00102     zeroWholeDisk->setChecked(
00103         c->readBoolEntry("ZeroDisk",false));
00104     enableSoftUpdates->setChecked(
00105         c->readBoolEntry("SoftUpdates",false));
00106 }
00107 
00108 /* virtual */  void ZipFormat::writeSettings(KConfig *c)
00109 {
00110     c->setGroup(fslabel);
00111     c->writeEntry("ZeroDisk",zeroWholeDisk->isChecked());
00112     c->writeEntry("SoftUpdates",enableSoftUpdates->isChecked());
00113 }
00114 
00115 void ZipFormat::quit()
00116 {
00117     DEBUGSETUP;
00118     delete p;
00119     delete statusTimer;
00120 
00121     p=0L;
00122     statusTimer=0L;
00123 }
00124 
00125 /* virtual slot */ void ZipFormat::format(FilesystemData *f)
00126 {
00127     DEBUGSETUP;
00128 
00129     if (f->magic()!=0xefc87329)
00130     {
00131         complainAboutFormat(f);
00132         return;
00133     }
00134 
00135     formatStep=0;
00136 
00137     if (p) delete p;
00138     p = new K3Process();
00139 
00140     if (statusTimer) delete statusTimer;
00141     statusTimer = new QTimer(this);
00142 
00143     connect(p,SIGNAL(processExited(K3Process *)),
00144         this,SLOT(transition()));
00145     connect(p,SIGNAL(receivedStdout(K3Process *,char *,int)),
00146         this,SLOT(processResult(K3Process *,char *,int)));
00147     connect(p,SIGNAL(receivedStderr(K3Process *,char *,int)),
00148         this,SLOT(processResult(K3Process *,char *,int)));
00149     connect(statusTimer,SIGNAL(timeout()),
00150         this,SLOT(statusRequest()));
00151 
00152     transition();
00153 }
00154 
00155 void ZipFormat::transition()
00156 {
00157     DEBUGSETUP;
00158 
00159     switch(formatStep)
00160     {
00161     case 0 :
00162         // We're using a larger block size to speed up writing.
00163         // So instead of 196608 blocks of 512b, use 12288 blocks
00164         // of 8k instead.
00165         //
00166         // For newfs we need to set the real number of blocks.
00167         //
00168         if (zeroWholeDisk->isChecked())
00169         {
00170             // Zeroing whole disk takes about 2 min.
00171             // No point in making a dizzy display of it.
00172             statusTimer->start(10000);
00173             QTimer::singleShot(1000,this,
00174                 SLOT(statusRequest()));
00175             totalBlocks=12288; // 196608 * 512b = 12288 * 8192b ;
00176         }
00177         else
00178         {
00179             // Takes about 5 seconds.
00180             statusTimer->start(1000);
00181             totalBlocks=100;
00182         }
00183 
00184         *p << dd
00185             << "if=/dev/zero"
00186             << "of=/dev/afd0c"
00187             << "bs=8192" ;
00188         *p << QString("count=%1").arg(totalBlocks);
00189         if (!p->start(K3Process::NotifyOnExit,K3Process::AllOutput))
00190         {
00191             emit statusMessage(i18n("Cannot start dd to zero disk."));
00192             emit formatDone(-1);
00193             delete statusTimer;
00194             delete p;
00195             statusTimer=0L;
00196             p=0L;
00197             return;
00198         }
00199 
00200         formatStep=1;
00201         emit statusMessage(i18n("Zeroing disk..."));
00202         break;
00203     case 1 :
00204         statusTimer->stop();
00205         // The dd for zeroing the disk has finished.
00206         if (p->exitStatus())
00207         {
00208             emit statusMessage(i18n("Zeroing disk failed."));
00209             emit formatDone(-1);
00210             return;
00211         }
00212 
00213         totalBlocks=196608; // Now use the real number of 512b blocks
00214 
00215         p->clearArguments();
00216         *p << newfs << "-T" << "zip100" ;
00217         if (enableSoftUpdates->isChecked())
00218         {
00219             *p << "-U" ;
00220         }
00221         *p << "/dev/afd0c" ;
00222         if (!p->start(K3Process::NotifyOnExit,K3Process::AllOutput))
00223         {
00224             emit statusMessage(i18n("Cannot start newfs."));
00225             emit formatDone(-1);
00226         };
00227         formatStep=2;
00228         emit statusMessage(i18n("Making filesystem..."));
00229         break;
00230     case 2 :
00231         if (p->exitStatus())
00232         {
00233             emit statusMessage(i18n("newfs failed."));
00234             emit formatDone(-1);
00235         }
00236         else
00237         {
00238             emit statusMessage(i18n("Disk formatted successfully."));
00239             emit formatDone(0);
00240         }
00241         break;
00242     }
00243 }
00244 
00245 void ZipFormat::processResult(K3Process *, char *b, int l)
00246 {
00247     DEBUGSETUP;
00248 
00249 #ifdef DEBUG
00250     QString o = QString::fromLatin1(b,l);
00251     DEBUGS(QString("  %1").arg(o).latin1());
00252 #endif
00253 
00254     switch(formatStep)
00255     {
00256     case 1 : // These are messages from dd
00257         if (strchr(b,'+'))
00258         {
00259             int currentblock=atoi(b);
00260             emit setProgress(currentblock*100/totalBlocks);
00261             if (totalBlocks>10000)
00262             {
00263                 emit statusMessage(i18n("Zeroing block %1 of %2...",
00264                      currentblock,
00265                      totalBlocks));
00266             }
00267         }
00268         break;
00269     case 2 : // These are messages from newfs
00270         if ((b[0]==' ') && isdigit(b[1]))
00271         {
00272             int currentblock=atoi(b+1);
00273             emit setProgress(currentblock*100/totalBlocks);
00274         }
00275         else
00276         {
00277             // This is the initial display message from
00278             // newfs. It writes a first block to sector 32.
00279             //
00280             //
00281             emit setProgress(1);
00282 
00283             // QString myBuf = QString::fromLatin1(b, l);
00284             // DEBUGS(myBuf.latin1());
00285         }
00286         break;
00287     }
00288 }
00289 
00290 void ZipFormat::statusRequest()
00291 {
00292     if (formatStep!=1) // Not in dd mode?
00293         return;
00294     if (!p) // How can that happen?
00295         return;
00296 
00297 #ifdef ANY_BSD
00298     p->kill(SIGINFO);
00299 #endif
00300 }
00301 
00302 

kfloppy

Skip menu "kfloppy"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal