Changeset 59 in MondoRescue for trunk/mondo/mondo/common


Ignore:
Timestamp:
Oct 11, 2005, 1:34:31 AM (19 years ago)
Author:
bcornec
Message:

Trunk: indent on all source files

Location:
trunk/mondo/mondo/common
Files:
45 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/X-specific-EXT.h

    r30 r59  
    22
    33
    4 extern int  ask_me_yes_or_no (char *prompt);
    5 extern int  ask_me_OK_or_cancel (char *prompt);
    6 extern void close_evalcall_form (void);
    7 extern void close_progress_form ();
    8 extern void fatal_error (char *error_string);
    9 extern void finish (int signal);
    10 extern void mvaddstr_and_log_it (int y, int x, char *output);
    11 extern void open_evalcall_form (char *title);
    12 extern void open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val);
    13 extern void log_file_end_to_screen (char *filename, char *grep_for_me);
    14 extern void log_to_screen (const char *op, ...);
    15 extern void popup_and_OK (char *prompt);
    16 extern int  popup_and_get_string (char *title, char *b, char *output, int maxsize);
    17 extern int  popup_with_buttons (char *p, char *button1, char *button2);
    18 extern void refresh_log_screen ();
    19 extern void setup_newt_stuff ();
    20 extern void update_evalcall_form_ratio (int num, int denom);
    21 extern void update_evalcall_form (int curr);
    22 extern void update_progress_form (char *blurb3);
    23 extern void update_progress_form_full (char *blurb1, char *blurb2, char *blurb3);
     4extern int ask_me_yes_or_no(char *prompt);
     5extern int ask_me_OK_or_cancel(char *prompt);
     6extern void close_evalcall_form(void);
     7extern void close_progress_form();
     8extern void fatal_error(char *error_string);
     9extern void finish(int signal);
     10extern void mvaddstr_and_log_it(int y, int x, char *output);
     11extern void open_evalcall_form(char *title);
     12extern void open_progress_form(char *title, char *b1, char *b2, char *b3,
     13                               long max_val);
     14extern void log_file_end_to_screen(char *filename, char *grep_for_me);
     15extern void log_to_screen(const char *op, ...);
     16extern void popup_and_OK(char *prompt);
     17extern int popup_and_get_string(char *title, char *b, char *output,
     18                                int maxsize);
     19extern int popup_with_buttons(char *p, char *button1, char *button2);
     20extern void refresh_log_screen();
     21extern void setup_newt_stuff();
     22extern void update_evalcall_form_ratio(int num, int denom);
     23extern void update_evalcall_form(int curr);
     24extern void update_progress_form(char *blurb3);
     25extern void update_progress_form_full(char *blurb1, char *blurb2,
     26                                      char *blurb3);
    2427
    2528
     
    2730
    2831
    29 extern t_bkptype which_backup_media_type (bool);
    30 extern int which_compression_level ();
     32extern t_bkptype which_backup_media_type(bool);
     33extern int which_compression_level();
    3134
    3235
    33 extern void popup_changelist_from_file(char*source_file);
    34 
    35 
     36extern void popup_changelist_from_file(char *source_file);
  • trunk/mondo/mondo/common/X-specific.h

    r30 r59  
    77#endif
    88
    9 int  ask_me_yes_or_no (char *prompt);
    10 int  ask_me_OK_or_cancel (char *prompt);
    11 void close_evalcall_form (void);
    12 void close_progress_form ();
    13 void fatal_error (char *error_string);
    14 void fatal_error_sub (char *error_string);
    15 void finish (int signal);
    16 void mvaddstr_and_log_it (int y, int x, char *output);
    17 void log_file_end_to_screen (char *filename, char *grep_for_me);
    18 void log_to_screen (const char *op, ...);
    19 void open_evalcall_form (char *title);
    20 void open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val);
    21 void popup_and_OK (char *prompt);
    22 void popup_and_OK_sub (char *prompt);
    23 int  popup_and_get_string (char *title, char *b, char *output, int maxsize);
    24 int  popup_and_get_string_sub (char *title, char *b, char *output, int maxsize);
    25 int  popup_with_buttons (char *p, char *button1, char *button2);
    26 int  popup_with_buttons_sub (char *p, char *button1, char *button2);
    27 void refresh_log_screen ();
    28 void setup_newt_stuff ();
    29 void update_evalcall_form_ratio (int num, int denom);
    30 void update_evalcall_form (int curr);
    31 void update_progress_form (char *blurb3);
    32 void update_progress_form_full (char *blurb1, char *blurb2, char *blurb3);
    33 
    34 
    35 
    36 
    37 
    38 
    39 t_bkptype which_backup_media_type (bool);
    40 int which_compression_level ();
    41 
    42 void popup_chaneglist_from_file(char*source_file);
     9    int ask_me_yes_or_no(char *prompt);
     10    int ask_me_OK_or_cancel(char *prompt);
     11    void close_evalcall_form(void);
     12    void close_progress_form();
     13    void fatal_error(char *error_string);
     14    void fatal_error_sub(char *error_string);
     15    void finish(int signal);
     16    void mvaddstr_and_log_it(int y, int x, char *output);
     17    void log_file_end_to_screen(char *filename, char *grep_for_me);
     18    void log_to_screen(const char *op, ...);
     19    void open_evalcall_form(char *title);
     20    void open_progress_form(char *title, char *b1, char *b2, char *b3,
     21                            long max_val);
     22    void popup_and_OK(char *prompt);
     23    void popup_and_OK_sub(char *prompt);
     24    int popup_and_get_string(char *title, char *b, char *output,
     25                             int maxsize);
     26    int popup_and_get_string_sub(char *title, char *b, char *output,
     27                                 int maxsize);
     28    int popup_with_buttons(char *p, char *button1, char *button2);
     29    int popup_with_buttons_sub(char *p, char *button1, char *button2);
     30    void refresh_log_screen();
     31    void setup_newt_stuff();
     32    void update_evalcall_form_ratio(int num, int denom);
     33    void update_evalcall_form(int curr);
     34    void update_progress_form(char *blurb3);
     35    void update_progress_form_full(char *blurb1, char *blurb2,
     36                                   char *blurb3);
     37
     38
     39
     40
     41
     42
     43    t_bkptype which_backup_media_type(bool);
     44    int which_compression_level();
     45
     46    void popup_chaneglist_from_file(char *source_file);
    4347
    4448#if __cplusplus && WITH_X
    4549
    46 extern int g_result_of_last_event;
    47    
    48 } /* extern "C" */
    49 
     50    extern int g_result_of_last_event;
     51
     52}                               /* extern "C" */
    5053#include <qvaluelist.h>
    5154#include <qwidget.h>
     
    5457#include <qstring.h>
    5558#include <qmultilineedit.h>
    56 
    5759/**
    5860 * A class for XMondo to hold events queued by the backup thread until the event thread is able to handle them.
    59  */
    60 class XMEventHolder
     61 */ class XMEventHolder
    6162{
    62 public:
    63     struct Event
    64     {
    65     enum EventType { None, Show, Hide, New, SetProgress, SetTotal, SetText, InsLine, PopupWithButtons, InfoMsg, ErrorMsg, GetInfo } type;
    66     QWidget *data;
     63  public:
     64    struct Event {
     65        enum EventType { None, Show, Hide, New, SetProgress, SetTotal,
     66                SetText, InsLine, PopupWithButtons, InfoMsg, ErrorMsg,
     67                GetInfo } type;
     68        QWidget *data;
    6769// union {
    68         int iParam;
    69         QString qsParam, title, text, b1, b2;
    70         char *csParam;
    71     int len;
     70        int iParam;
     71        QString qsParam, title, text, b1, b2;
     72        char *csParam;
     73        int len;
    7274// };
    73        
    74     Event() : type (None), data (0) {}
    75     Event (EventType thetype, QWidget *thedata) {
    76         this->type = thetype;
    77         this->data = thedata;
    78     }
    79     Event (EventType thetype, QWidget *thedata, int ip) {
    80         this->type = thetype;
    81         this->data = thedata;
    82         this->iParam = ip;
    83     }
    84     Event (EventType thetype, QWidget *thedata, QString qsp) {
    85         this->type = thetype;
    86         this->data = thedata;
    87         this->qsParam = qsp;
    88     }
    89     Event (EventType thetype, QWidget *thedata, char *csp) {
    90         this->type = thetype;
    91         this->data = thedata;
    92         this->csParam = csp;
    93     }
    94     Event (EventType thetype, QWidget *thedata, char *csp, int len) {
    95         this->type = thetype;
    96         this->data = thedata;
    97         this->csParam = csp;
    98         this->len = len;
    99     }
    100     };
    101    
    102     XMEventHolder() {}
    103 
    104     /* Backup thread functions */
    105 
    106     void event (Event::EventType type, QWidget *data) {
    107     _events.push_back (Event (type, data));
    108     }
    109 
    110     /**
     75
     76         Event():type(None), data(0) {
     77        } Event(EventType thetype, QWidget * thedata) {
     78            this->type = thetype;
     79            this->data = thedata;
     80        } Event(EventType thetype, QWidget * thedata, int ip) {
     81            this->type = thetype;
     82            this->data = thedata;
     83            this->iParam = ip;
     84        }
     85        Event(EventType thetype, QWidget * thedata, QString qsp) {
     86            this->type = thetype;
     87            this->data = thedata;
     88            this->qsParam = qsp;
     89        }
     90        Event(EventType thetype, QWidget * thedata, char *csp) {
     91            this->type = thetype;
     92            this->data = thedata;
     93            this->csParam = csp;
     94        }
     95        Event(EventType thetype, QWidget * thedata, char *csp, int len) {
     96            this->type = thetype;
     97            this->data = thedata;
     98            this->csParam = csp;
     99            this->len = len;
     100        }
     101    };
     102
     103    XMEventHolder() {
     104    }
     105
     106    /* Backup thread functions */
     107
     108    void event(Event::EventType type, QWidget * data) {
     109        _events.push_back(Event(type, data));
     110    }
     111
     112    /**
    111113     * Queue a "show" event for @p data.
    112114     * This is equivalent to a delayed call of @p data->show().
    113115     * @param data The widget to show when the event is processed.
    114116     */
    115     void show (QWidget *data) {
    116     _events.push_back (Event (Event::Show, data));
    117     }
    118 
    119     /**
     117    void show(QWidget * data) {
     118        _events.push_back(Event(Event::Show, data));
     119    }
     120
     121    /**
    120122     * Queue a "hide" event for @p data.
    121123     * This is equivalent to a delayed call of @p data->hide().
    122124     * @param data The widget to hide when the event is processed.
    123125     */
    124     void hide (QWidget *data) {
    125     _events.push_back (Event (Event::Hide, data));
    126     }
    127 
    128     /**
     126    void hide(QWidget * data) {
     127        _events.push_back(Event(Event::Hide, data));
     128    }
     129
     130    /**
    129131     * Queue a "setProgress" event for @p data.
    130132     * This is equivalent to a delayed call of <tt>data-\>setProgress(progress)</tt>.
     
    132134     * @param progress The progress amount to set it to.
    133135     */
    134     void setProgress (QProgressBar *data, int progress) {
    135     _events.push_back (Event (Event::SetProgress, data, progress));
    136     }
    137 
    138     /**
     136    void setProgress(QProgressBar * data, int progress) {
     137        _events.push_back(Event(Event::SetProgress, data, progress));
     138    }
     139
     140    /**
    139141     * Queue a "setTotalSteps" event for @p data.
    140142     * This is equivalent to a delayed call of <tt>data-\>setTotalSteps(totals)</tt>.
     
    142144     * @param totals The total number of steps to set.
    143145     */
    144     void setTotalSteps (QProgressBar *data, int totals) {
    145     _events.push_back (Event (Event::SetTotal, data, totals));
    146     }
    147 
    148     /**
     146    void setTotalSteps(QProgressBar * data, int totals) {
     147        _events.push_back(Event(Event::SetTotal, data, totals));
     148    }
     149
     150    /**
    149151     * Queue a "setText" event for @p data.
    150152     * This is equivalent to a delayed call of <tt>data-\>setText(text)</tt>.
     
    152154     * @param text The text to set it to.
    153155     */
    154     void setText (QLabel *data, QString text) {
    155     _events.push_back (Event (Event::SetText, data, text));
    156     }
    157 
    158     /**
     156    void setText(QLabel * data, QString text) {
     157        _events.push_back(Event(Event::SetText, data, text));
     158    }
     159
     160    /**
    159161     * Queue an "insertLine" event for @p data.
    160162     * This is equivalent to a delayed call of <tt>data->insertLine(line)</tt>.
     
    162164     * @param line The line to add.
    163165     */
    164     void insertLine (QMultiLineEdit *data, QString line) {
    165     _events.push_back (Event (Event::InsLine, data, line));
    166     }
    167 
    168     /**
     166    void insertLine(QMultiLineEdit * data, QString line) {
     167        _events.push_back(Event(Event::InsLine, data, line));
     168    }
     169
     170    /**
    169171     * Queue an alert box with two buttons to be displayed.
    170172     * The button pushed (the return value of popup_with_buttons()) will be stored
     
    174176     * @param b2 The second button's text.
    175177     */
    176     void popupWithButtons (QString text, QString b1, QString b2) {
    177     Event e;
    178     e.type = Event::PopupWithButtons;
    179     e.text = text;
    180     e.b1    = b1;
    181     e.b2    = b2;
    182     _events.push_back (e);
    183     }
    184 
    185     /**
     178    void popupWithButtons(QString text, QString b1, QString b2) {
     179        Event e;
     180        e.type = Event::PopupWithButtons;
     181        e.text = text;
     182        e.b1 = b1;
     183        e.b2 = b2;
     184        _events.push_back(e);
     185    }
     186
     187    /**
    186188     * Queue an info box with one OK button to be displayed.
    187189     * @param text The text of the dialog box.
    188190     */
    189     void infoMsg (QString text) {
    190     Event e;
    191     e.type = Event::InfoMsg;
    192     e.text = text;
    193     _events.push_back (e);
    194     }
    195 
    196     /**
     191    void infoMsg(QString text) {
     192        Event e;
     193        e.type = Event::InfoMsg;
     194        e.text = text;
     195        _events.push_back(e);
     196    }
     197
     198    /**
    197199     * Queue a "fatal error" message.
    198200     * @param text The fatal error.
    199201     */
    200     void errorMsg (QString text) {
    201     Event e;
    202     e.type = Event::ErrorMsg;
    203     e.text = text;
    204     _events.push_back (e);
    205     }
    206 
    207     /**
     202    void errorMsg(QString text) {
     203        Event e;
     204        e.type = Event::ErrorMsg;
     205        e.text = text;
     206        _events.push_back(e);
     207    }
     208
     209    /**
    208210     * Queue a request for some information from the user.
    209211     * If you want to wait until the text is stored, you can set @p g_result_of_last_event
     
    215217     * @param len The size of the buffer allocated for @p out.
    216218     */
    217     void getInfo (QString title, QString text, char *out, int len) {
    218     Event e;
    219     e.type    = Event::GetInfo;
    220     e.title  = title;
    221     e.text    = text;
    222     e.csParam = out;
    223     e.len    = len;
    224     _events.push_back (e);
    225     }
    226    
    227     /* These are called in the GUI thread */
    228 
    229     /**
     219    void getInfo(QString title, QString text, char *out, int len) {
     220        Event e;
     221        e.type = Event::GetInfo;
     222        e.title = title;
     223        e.text = text;
     224        e.csParam = out;
     225        e.len = len;
     226        _events.push_back(e);
     227    }
     228
     229    /* These are called in the GUI thread */
     230
     231    /**
    230232     * Clear all events stored in the queue without executing them.
    231233     */
    232     void clear() {
    233     _events.erase (_events.begin(), _events.end());
    234     }
    235 
    236     /**
     234    void clear() {
     235        _events.erase(_events.begin(), _events.end());
     236    }
     237
     238    /**
    237239     * Process all events stored in the queue and then clear them.
    238240     */
    239     void send() {
    240         QProgressBar *pb;
    241         QLabel *l;
    242     QMultiLineEdit *mle;
    243     for (QValueList <Event>::iterator it = _events.begin(); it != _events.end(); ++it) {
    244         switch ((*it).type) {
    245         case Event::Show:
    246         ((*it).data)->show();
    247         break;
    248         case Event::Hide:
    249         ((*it).data)->hide();
    250         break;
    251         case Event::SetProgress:
    252         if ((pb = dynamic_cast <QProgressBar*> ((*it).data))) {
    253             pb->setProgress ((*it).iParam);
    254         }
    255         break;
    256         case Event::SetTotal:
    257         if ((pb = dynamic_cast <QProgressBar*> ((*it).data))) {
    258             pb->setTotalSteps ((*it).iParam);
    259         }
    260         break;
    261         case Event::SetText:
    262         if ((l = dynamic_cast <QLabel*> ((*it).data))) {
    263             l->setText ((*it).qsParam);
    264         }
    265         break;
    266         case Event::InsLine:
    267         if ((mle = dynamic_cast <QMultiLineEdit *> ((*it).data))) {
    268             mle->insertLine ((*it).qsParam);
    269         }
    270         break;
    271         case Event::PopupWithButtons:
    272         g_result_of_last_event = popup_with_buttons_sub (const_cast <char*> ((*it).text.ascii()), const_cast <char*> ((*it).b1.ascii()), const_cast <char*> ((*it).b2.ascii()));
    273         break;
    274         case Event::InfoMsg:
    275         popup_and_OK_sub (const_cast <char*> ((*it).text.ascii()));
    276         g_result_of_last_event = 0;
    277         break;
    278         case Event::ErrorMsg:
    279         fatal_error_sub (const_cast <char*> ((*it).text.ascii()));
    280         break;
    281         case Event::GetInfo:
    282         g_result_of_last_event = popup_and_get_string_sub (const_cast <char*> ((*it).title.ascii()), const_cast <char*> ((*it).text.ascii()), (*it).csParam, (*it).len);
    283         break;
    284         default:
    285         qDebug ("unknown event\n");
    286         }
    287     }
    288     this->clear();
    289     }
    290    
    291     /* Undocumented */
    292     QValueList <Event> events() {
    293     return _events;
    294     }
    295    
    296 protected:
    297    
    298 
    299     QValueList <Event> _events;
     241    void send() {
     242        QProgressBar *pb;
     243        QLabel *l;
     244        QMultiLineEdit *mle;
     245        for (QValueList < Event >::iterator it = _events.begin();
     246             it != _events.end(); ++it) {
     247            switch ((*it).type) {
     248            case Event::Show:
     249                ((*it).data)->show();
     250                break;
     251            case Event::Hide:
     252                ((*it).data)->hide();
     253                break;
     254            case Event::SetProgress:
     255                if ((pb = dynamic_cast < QProgressBar * >((*it).data))) {
     256                    pb->setProgress((*it).iParam);
     257                }
     258                break;
     259            case Event::SetTotal:
     260                if ((pb = dynamic_cast < QProgressBar * >((*it).data))) {
     261                    pb->setTotalSteps((*it).iParam);
     262                }
     263                break;
     264            case Event::SetText:
     265                if ((l = dynamic_cast < QLabel * >((*it).data))) {
     266                    l->setText((*it).qsParam);
     267                }
     268                break;
     269            case Event::InsLine:
     270                if ((mle = dynamic_cast < QMultiLineEdit * >((*it).data))) {
     271                    mle->insertLine((*it).qsParam);
     272                }
     273                break;
     274            case Event::PopupWithButtons:
     275                g_result_of_last_event =
     276                    popup_with_buttons_sub(const_cast <
     277                                           char *>((*it).text.ascii()),
     278                                           const_cast <
     279                                           char *>((*it).b1.ascii()),
     280                                           const_cast <
     281                                           char *>((*it).b2.ascii()));
     282                break;
     283            case Event::InfoMsg:
     284                popup_and_OK_sub(const_cast < char *>((*it).text.ascii()));
     285                g_result_of_last_event = 0;
     286                break;
     287            case Event::ErrorMsg:
     288                fatal_error_sub(const_cast < char *>((*it).text.ascii()));
     289                break;
     290            case Event::GetInfo:
     291                g_result_of_last_event =
     292                    popup_and_get_string_sub(const_cast <
     293                                             char *>((*it).title.ascii()),
     294                                             const_cast <
     295                                             char *>((*it).text.ascii()),
     296                                             (*it).csParam, (*it).len);
     297                break;
     298            default:
     299                qDebug("unknown event\n");
     300            }
     301        }
     302        this->clear();
     303    }
     304
     305    /* Undocumented */
     306    QValueList < Event > events() {
     307        return _events;
     308    }
     309
     310  protected:
     311
     312
     313    QValueList < Event > _events;
    300314};
    301  
    302 #endif /* __cplusplus */
     315
     316#endif                          /* __cplusplus */
  • trunk/mondo/mondo/common/crcttt.h

    r30 r59  
    55/** purpose        *********************************************************/
    66unsigned int crc16tab[256] = {
    7   0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
    8   0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
    9   0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
    10   0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
    11   0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
    12   0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
    13   0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
    14   0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
    15   0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
    16   0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
    17   0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
    18   0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
    19   0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
    20   0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
    21   0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
    22   0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
    23   0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
    24   0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
    25   0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
    26   0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
    27   0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
    28   0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
    29   0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
    30   0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
    31   0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
    32   0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
    33   0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
    34   0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
    35   0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
    36   0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
    37   0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
    38   0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
     7    0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
     8    0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
     9    0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
     10    0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
     11    0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
     12    0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
     13    0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
     14    0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
     15    0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
     16    0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
     17    0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
     18    0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
     19    0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
     20    0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
     21    0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
     22    0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
     23    0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
     24    0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
     25    0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
     26    0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
     27    0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
     28    0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
     29    0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
     30    0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
     31    0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
     32    0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
     33    0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
     34    0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
     35    0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
     36    0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
     37    0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
     38    0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
    3939};
    4040
    4141/** purpose **************************************************************/
    4242unsigned int crctttab[256] = {
    43   0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
    44   0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
    45   0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
    46   0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
    47   0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
    48   0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
    49   0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
    50   0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
    51   0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
    52   0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
    53   0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
    54   0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
    55   0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
    56   0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
    57   0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
    58   0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
    59   0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
    60   0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
    61   0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
    62   0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
    63   0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
    64   0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
    65   0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
    66   0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
    67   0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
    68   0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
    69   0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
    70   0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
    71   0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
    72   0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
    73   0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
    74   0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
     43    0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
     44    0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
     45    0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
     46    0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
     47    0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
     48    0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
     49    0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
     50    0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
     51    0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
     52    0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
     53    0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
     54    0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
     55    0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
     56    0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
     57    0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
     58    0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
     59    0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
     60    0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
     61    0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
     62    0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
     63    0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
     64    0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
     65    0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
     66    0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
     67    0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
     68    0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
     69    0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
     70    0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
     71    0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
     72    0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
     73    0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
     74    0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
    7575};
    76 
    77 
    78 
    79 
  • trunk/mondo/mondo/common/lib-common-externs.h

    r30 r59  
    77
    88//extern void log_it(char*);
    9 
    10 
    11 
    12 
    13 
  • trunk/mondo/mondo/common/libmondo-archive-EXT.h

    r30 r59  
    22
    33
    4 extern int archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname, int setno);
     4extern int archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
     5                                char *fname, int setno);
    56extern int backup_data(struct s_bkpinfo *bkpinfo);
    6 extern int call_mindi_to_supply_boot_disks (struct s_bkpinfo *bkpinfo);
    7 extern bool can_we_fit_these_files_on_media (struct s_bkpinfo *bkpinfo, char*files_to_add, ...);
    8 extern int do_that_initial_phase (struct s_bkpinfo *bkpinfo);
    9 extern int do_that_final_phase (struct s_bkpinfo *bkpinfo);
    10 extern int figure_out_kernel_path_interactively_if_necessary(char*kernel);
    11 extern int make_those_slices_phase (struct s_bkpinfo *bkpinfo);
    12 extern int make_those_afios_phase (struct s_bkpinfo *bkpinfo);
    13 extern int make_slices_and_images (struct s_bkpinfo *bkpinfo, char *biggielist_fname);
    14 extern int make_iso_fs (struct s_bkpinfo *bkpinfo, char *destfile);
    15 extern int make_afioballs_and_images (struct s_bkpinfo *bkpinfo);
     7extern int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo);
     8extern bool can_we_fit_these_files_on_media(struct s_bkpinfo *bkpinfo,
     9                                            char *files_to_add, ...);
     10extern int do_that_initial_phase(struct s_bkpinfo *bkpinfo);
     11extern int do_that_final_phase(struct s_bkpinfo *bkpinfo);
     12extern int figure_out_kernel_path_interactively_if_necessary(char *kernel);
     13extern int make_those_slices_phase(struct s_bkpinfo *bkpinfo);
     14extern int make_those_afios_phase(struct s_bkpinfo *bkpinfo);
     15extern int make_slices_and_images(struct s_bkpinfo *bkpinfo,
     16                                  char *biggielist_fname);
     17extern int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile);
     18extern int make_afioballs_and_images(struct s_bkpinfo *bkpinfo);
    1619extern int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...);
    17 extern int _move_files_to_cd (struct s_bkpinfo *bkpinfo, char *, ...);
     20extern int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *, ...);
    1821extern int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...);
    19 extern int _move_files_to_stream (struct s_bkpinfo *bkpinfo, char *files_to_add, ...);
    20 extern int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo);
    21 extern void pause_and_ask_for_cdr (int, bool*);
    22 extern int slice_up_file_etc (struct s_bkpinfo *bkpinfo, char *biggie_filename,
    23         char *partimagehack_fifo,
    24            long biggie_file_number, long noof_biggie_files, bool use_partimagehack);
     22extern int _move_files_to_stream(struct s_bkpinfo *bkpinfo,
     23                                 char *files_to_add, ...);
     24extern int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo
     25                                                          *bkpinfo);
     26extern void pause_and_ask_for_cdr(int, bool *);
     27extern int slice_up_file_etc(struct s_bkpinfo *bkpinfo,
     28                             char *biggie_filename,
     29                             char *partimagehack_fifo,
     30                             long biggie_file_number,
     31                             long noof_biggie_files,
     32                             bool use_partimagehack);
    2533extern int verify_data(struct s_bkpinfo *bkpinfo);
    26 extern void wipe_archives (char *d);
    27 extern int write_iso_and_go_on (struct s_bkpinfo *bkpinfo, bool last_cd);
    28 extern int write_final_iso_if_necessary (struct s_bkpinfo *bkpinfo);
    29 extern int call_growisofs (struct s_bkpinfo *bkpinfo, char *destfile);
    30 extern int make_afioballs_and_images_SINGLETHREAD (struct s_bkpinfo *bkpinfo);
    31 extern int archive_this_fileset_with_star (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    32           int setno);
    33 
     34extern void wipe_archives(char *d);
     35extern int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd);
     36extern int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo);
     37extern int call_growisofs(struct s_bkpinfo *bkpinfo, char *destfile);
     38extern int make_afioballs_and_images_SINGLETHREAD(struct s_bkpinfo
     39                                                  *bkpinfo);
     40extern int archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo,
     41                                          char *filelist, char *fname,
     42                                          int setno);
  • trunk/mondo/mondo/common/libmondo-archive.c

    r58 r59  
    20162016    }
    20172017    for (getline(&bigfile_fname, &n, fin); !feof(fin);
    2018          getline(&bigfile_fname, &n, fin),
    2019          biggie_file_number++) {
     2018         getline(&bigfile_fname, &n, fin), biggie_file_number++) {
    20202019        use_partimagehack = FALSE;
    20212020        if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
  • trunk/mondo/mondo/common/libmondo-archive.h

    r58 r59  
    33 */
    44
    5 int archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname, int setno);
     5int archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
     6                         char *fname, int setno);
    67int backup_data(struct s_bkpinfo *bkpinfo);
    7 int call_mindi_to_supply_boot_disks (struct s_bkpinfo *bkpinfo);
    8 bool can_we_fit_these_files_on_media (struct s_bkpinfo *bkpinfo, char*files_to_add, ...);
    9 int do_that_initial_phase (struct s_bkpinfo *bkpinfo);
    10 int do_that_final_phase (struct s_bkpinfo *bkpinfo);
    11 int figure_out_kernel_path_interactively_if_necessary(char*kernel);
    12 bool get_bit_N_of_array(char*array, int N);
    13 int make_those_slices_phase (struct s_bkpinfo *bkpinfo);
    14 int make_those_afios_phase (struct s_bkpinfo *bkpinfo);
    15 int make_slices_and_images (struct s_bkpinfo *bkpinfo, char *biggielist_fname);
    16 int make_iso_fs (struct s_bkpinfo *bkpinfo, char *destfile);
    17 int make_afioballs_and_images (struct s_bkpinfo *bkpinfo);
     8int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo);
     9bool can_we_fit_these_files_on_media(struct s_bkpinfo *bkpinfo,
     10                                     char *files_to_add, ...);
     11int do_that_initial_phase(struct s_bkpinfo *bkpinfo);
     12int do_that_final_phase(struct s_bkpinfo *bkpinfo);
     13int figure_out_kernel_path_interactively_if_necessary(char *kernel);
     14bool get_bit_N_of_array(char *array, int N);
     15int make_those_slices_phase(struct s_bkpinfo *bkpinfo);
     16int make_those_afios_phase(struct s_bkpinfo *bkpinfo);
     17int make_slices_and_images(struct s_bkpinfo *bkpinfo,
     18                           char *biggielist_fname);
     19int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile);
     20int make_afioballs_and_images(struct s_bkpinfo *bkpinfo);
    1821extern int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...);
    19 int _move_files_to_cd (struct s_bkpinfo *bkpinfo, char *files_to_add, ...);
     22int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...);
    2023extern int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...);
    21 int _move_files_to_stream (struct s_bkpinfo *bkpinfo, char *files_to_add, ...);
    22 int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo);
    23 void pause_and_ask_for_cdr (int, bool*);
    24 void set_bit_N_of_array(char*array, int N, bool true_or_false);
    25 int slice_up_file_etc (struct s_bkpinfo *bkpinfo, char *biggie_filename,
    26         char *partimagehack_fifo,
    27            long biggie_file_number, long noof_biggie_files, bool use_partimagehack);
     24int _move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add,
     25                          ...);
     26int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo
     27                                                   *bkpinfo);
     28void pause_and_ask_for_cdr(int, bool *);
     29void set_bit_N_of_array(char *array, int N, bool true_or_false);
     30int slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
     31                      char *partimagehack_fifo,
     32                      long biggie_file_number, long noof_biggie_files,
     33                      bool use_partimagehack);
    2834int verify_data(struct s_bkpinfo *bkpinfo);
    29 void wipe_archives (char *d);
    30 int write_image_to_floppy (char *device, char *datafile);
    31 int write_image_to_floppy_SUB (char *device, char *datafile);
    32 int write_iso_and_go_on (struct s_bkpinfo *bkpinfo, bool last_cd);
    33 int write_final_iso_if_necessary (struct s_bkpinfo *bkpinfo);
    34 int call_growisofs (struct s_bkpinfo *bkpinfo, char *destfile);
    35 int make_afioballs_and_images_SINGLETHREAD (struct s_bkpinfo *bkpinfo);
    36 int archive_this_fileset_with_star (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    37           int setno);
     35void wipe_archives(char *d);
     36int write_image_to_floppy(char *device, char *datafile);
     37int write_image_to_floppy_SUB(char *device, char *datafile);
     38int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd);
     39int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo);
     40int call_growisofs(struct s_bkpinfo *bkpinfo, char *destfile);
     41int make_afioballs_and_images_SINGLETHREAD(struct s_bkpinfo *bkpinfo);
     42int archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo,
     43                                   char *filelist, char *fname, int setno);
  • trunk/mondo/mondo/common/libmondo-devices-EXT.h

    r30 r59  
    11/*
    2  * $Id: libmondo-devices-EXT.h,v 1.4 2004/06/17 11:57:52 hugo Exp $
     2 * $Id$
    33 */
    44
    5 extern bool am_I_in_disaster_recovery_mode (void);
    6 extern bool does_device_exist (char *device);
    7 extern int does_partition_exist (const char *drive, int partno);
    8 extern bool does_string_exist_in_boot_block (char *dev, char *str);
    9 extern int find_and_mount_actual_cd (struct s_bkpinfo *bkpinfo, char *mountpoint);
    10 extern int find_cdrom_device (char *output, bool try_to_mount);
    11 extern int find_dvd_device (char *output, bool try_to_mount);
    12 extern long get_phys_size_of_drive (char *drive);
    13 extern bool is_this_a_valid_disk_format (char *format);
    14 extern bool is_this_device_mounted (char *device_raw);
    15 extern int find_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
    16 extern int mount_CDROM_here (char *device, char *mountpoint);
    17 extern long long size_of_specific_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
    18 extern char *where_is_root_mounted (void);
    19 extern char *make_vn (char *file);
    20 extern int kick_vn (char *vn);
    21 extern char which_boot_loader (char *which_device);
     5extern bool am_I_in_disaster_recovery_mode(void);
     6extern bool does_device_exist(char *device);
     7extern int does_partition_exist(const char *drive, int partno);
     8extern bool does_string_exist_in_boot_block(char *dev, char *str);
     9extern int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo,
     10                                    char *mountpoint);
     11extern int find_cdrom_device(char *output, bool try_to_mount);
     12extern int find_dvd_device(char *output, bool try_to_mount);
     13extern long get_phys_size_of_drive(char *drive);
     14extern bool is_this_a_valid_disk_format(char *format);
     15extern bool is_this_device_mounted(char *device_raw);
     16extern int find_device_in_mountlist(struct mountlist_itself *mountlist,
     17                                    char *device);
     18extern int mount_CDROM_here(char *device, char *mountpoint);
     19extern long long size_of_specific_device_in_mountlist(struct
     20                                                      mountlist_itself
     21                                                      *mountlist,
     22                                                      char *device);
     23extern char *where_is_root_mounted(void);
     24extern char *make_vn(char *file);
     25extern int kick_vn(char *vn);
     26extern char which_boot_loader(char *which_device);
    2227
    2328
    2429
    25 extern int find_cdrw_device (char *cdrw_device);
     30extern int find_cdrw_device(char *cdrw_device);
    2631
    2732
    28 extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *, bool);
     33extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo
     34                                                           *, bool);
    2935
    3036
    31 extern void make_fifo(char*store_name_here, char*stub);
     37extern void make_fifo(char *store_name_here, char *stub);
    3238
    3339
    34 extern void insist_on_this_cd_number (struct s_bkpinfo* bkpinfo, int cd_number_i_want);
     40extern void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo,
     41                                     int cd_number_i_want);
    3542
    3643
     
    3845
    3946
    40 extern int eject_device(char*);
     47extern int eject_device(char *);
    4148
    4249extern char *list_of_NFS_devices_and_mounts();
     
    4653
    4754
    48 extern bool set_dev_to_this_if_rx_OK(char*,char*);
     55extern bool set_dev_to_this_if_rx_OK(char *, char *);
    4956
    5057extern void retract_CD_tray_and_defeat_autorun(void);
    5158
    52 extern bool does_string_exist_in_first_N_blocks (char *dev, char *str, int n);
     59extern bool does_string_exist_in_first_N_blocks(char *dev, char *str,
     60                                                int n);
    5361
    54 extern int inject_device(char*dev);
     62extern int inject_device(char *dev);
    5563extern bool does_nonMS_partition_exist(void);
    56 extern char *resolve_softlinks_to_get_to_actual_device_file(char*incoming);
     64extern char *resolve_softlinks_to_get_to_actual_device_file(char
     65                                                            *incoming);
    5766
    58 extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo*bkpinfo);
     67extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo
     68                                                   *bkpinfo);
    5969
    6070extern bool is_dev_an_NTFS_dev(char *bigfile_fname);
    6171
    6272extern char *which_partition_format(const char *drive);
    63 
  • trunk/mondo/mondo/common/libmondo-devices.c

    r30 r59  
    11/* libmondo-devices.c                 Subroutines for handling devices
    2    $Id: libmondo-devices.c,v 1.26 2004/06/21 20:20:36 hugo Exp $
     2   $Id$
    33.
    44
     
    247247#elif linux
    248248#define u64 unsigned long long
    249 #include <linux/fs.h> /* for BLKGETSIZE64 */
     249#include <linux/fs.h>           /* for BLKGETSIZE64 */
    250250#include <linux/hdreg.h>
    251251#endif
    252252
    253253/*@unused@*/
    254 //static char cvsid[] = "$Id: libmondo-devices.c,v 1.26 2004/06/21 20:20:36 hugo Exp $";
     254//static char cvsid[] = "$Id$";
    255255
    256256extern int g_current_media_number;
     
    261261extern char *g_erase_tmpdir_and_scratchdir;
    262262
    263 static char g_cdrw_drive_is_here[MAX_STR_LEN/4]="";
    264 static char g_cdrom_drive_is_here[MAX_STR_LEN/4]="";
    265 static char g_dvd_drive_is_here[MAX_STR_LEN/4]="";
     263static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = "";
     264static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = "";
     265static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = "";
    266266
    267267
     
    270270 * @ingroup globalGroup
    271271 */
    272 bool g_restoring_live_from_cd=FALSE;
    273 
    274 extern t_bkptype g_backup_media_type; // set by main()
     272bool g_restoring_live_from_cd = FALSE;
     273
     274extern t_bkptype g_backup_media_type;   // set by main()
    275275
    276276
     
    279279void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo)
    280280{
    281   strcpy(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case
    282   strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
     281    strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
     282    strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
    283283}
    284284
     
    292292{
    293293//  log_it("rctada: Retracting all CD trays", __LINE__);
    294   if (strlen(g_cdrom_drive_is_here)>0)
    295     { inject_device(g_cdrom_drive_is_here); }
    296   if (strlen(g_dvd_drive_is_here)>0)
    297     { inject_device(g_dvd_drive_is_here); }
    298   if (strlen(g_cdrw_drive_is_here)>0)
    299     { inject_device(g_cdrw_drive_is_here); }
     294    if (strlen(g_cdrom_drive_is_here) > 0) {
     295        inject_device(g_cdrom_drive_is_here);
     296    }
     297    if (strlen(g_dvd_drive_is_here) > 0) {
     298        inject_device(g_dvd_drive_is_here);
     299    }
     300    if (strlen(g_cdrw_drive_is_here) > 0) {
     301        inject_device(g_cdrw_drive_is_here);
     302    }
    300303//  log_it("rctada: killing autorun");
    301304//  run_program_and_log_output("killall autorun", TRUE);
    302   if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5))
    303     {
    304       log_it("autorun detected; sleeping for 2 seconds");
    305       sleep(2);
    306     }
    307   log_it("rctada: Unmounting all CD drives", __LINE__);
    308   run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
     305    if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) {
     306        log_it("autorun detected; sleeping for 2 seconds");
     307        sleep(2);
     308    }
     309    log_it("rctada: Unmounting all CD drives", __LINE__);
     310    run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
    309311}
    310312
     
    316318 * @ingroup utilityGroup
    317319 */
    318 bool
    319 am_I_in_disaster_recovery_mode (void)
    320 {
    321   char *tmp, *comment;
    322   bool is_this_a_ramdisk = FALSE;
    323 
    324   malloc_string(tmp);
    325   malloc_string(comment);
    326   strcpy(tmp, where_is_root_mounted());
    327   sprintf(comment, "root is mounted at %s\n", tmp);
    328   log_msg(0, comment);
    329   log_msg(0, "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp);
     320bool am_I_in_disaster_recovery_mode(void)
     321{
     322    char *tmp, *comment;
     323    bool is_this_a_ramdisk = FALSE;
     324
     325    malloc_string(tmp);
     326    malloc_string(comment);
     327    strcpy(tmp, where_is_root_mounted());
     328    sprintf(comment, "root is mounted at %s\n", tmp);
     329    log_msg(0, comment);
     330    log_msg(0,
     331            "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().",
     332            tmp);
    330333
    331334#ifdef __FreeBSD__
    332   if (strstr(tmp, "/dev/md"))
    333     {
    334       is_this_a_ramdisk = TRUE;
    335     }
     335    if (strstr(tmp, "/dev/md")) {
     336        is_this_a_ramdisk = TRUE;
     337    }
    336338#else
    337   if (!strncmp(tmp, "/dev/ram", 8) || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/") && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
    338     || !strcmp(tmp, "/dev/root"))
    339     { is_this_a_ramdisk = TRUE; }
    340   else
    341     { is_this_a_ramdisk = FALSE; }
    342 #endif
    343 
    344   if (is_this_a_ramdisk)
    345     {
    346       if (!does_file_exist("/THIS-IS-A-RAMDISK") && !does_file_exist("/tmp/mountlist.txt.sample"))
    347         {
    348           log_to_screen("Using /dev/root is stupid of you but I'll forgive you.");
    349           is_this_a_ramdisk = FALSE;
    350         }
    351     }
    352   if (does_file_exist("/THIS-IS-A-RAMDISK"))
    353     {
    354       is_this_a_ramdisk = TRUE;
    355     }
    356   paranoid_free(tmp);
    357   paranoid_free(comment);
    358   log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
    359   return(is_this_a_ramdisk);
     339    if (!strncmp(tmp, "/dev/ram", 8)
     340        || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/")
     341            && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
     342        || !strcmp(tmp, "/dev/root")) {
     343        is_this_a_ramdisk = TRUE;
     344    } else {
     345        is_this_a_ramdisk = FALSE;
     346    }
     347#endif
     348
     349    if (is_this_a_ramdisk) {
     350        if (!does_file_exist("/THIS-IS-A-RAMDISK")
     351            && !does_file_exist("/tmp/mountlist.txt.sample")) {
     352            log_to_screen
     353                ("Using /dev/root is stupid of you but I'll forgive you.");
     354            is_this_a_ramdisk = FALSE;
     355        }
     356    }
     357    if (does_file_exist("/THIS-IS-A-RAMDISK")) {
     358        is_this_a_ramdisk = TRUE;
     359    }
     360    paranoid_free(tmp);
     361    paranoid_free(comment);
     362    log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
     363    return (is_this_a_ramdisk);
    360364}
    361365
     
    372376static char *bkptype_to_string(t_bkptype bt)
    373377{
    374   static char output[MAX_STR_LEN/4];
    375   switch(bt)
    376     {
    377     case none: strcpy(output, "none");
     378    static char output[MAX_STR_LEN / 4];
     379    switch (bt) {
     380    case none:
     381        strcpy(output, "none");
    378382        break;
    379     case iso:  strcpy(output, "iso");
     383    case iso:
     384        strcpy(output, "iso");
    380385        break;
    381     case cdr:  strcpy(output, "cdr");
     386    case cdr:
     387        strcpy(output, "cdr");
    382388        break;
    383     case cdrw: strcpy(output, "cdrw");
     389    case cdrw:
     390        strcpy(output, "cdrw");
    384391        break;
    385     case cdstream: strcpy(output, "cdstream");
     392    case cdstream:
     393        strcpy(output, "cdstream");
    386394        break;
    387     case nfs:  strcpy(output, "nfs");
     395    case nfs:
     396        strcpy(output, "nfs");
    388397        break;
    389     case tape: strcpy(output, "tape");
     398    case tape:
     399        strcpy(output, "tape");
    390400        break;
    391     case udev: strcpy(output, "udev");
     401    case udev:
     402        strcpy(output, "udev");
    392403        break;
    393     default: strcpy(output, "default");
    394     }
    395   return(output);
     404    default:
     405        strcpy(output, "default");
     406    }
     407    return (output);
    396408}
    397409
     
    407419 * @return the return value of the @c eject command. (0=success, nonzero=failure)
    408420 */
    409 int eject_device(char*dev)
    410 {
    411   char *command;
    412   int res1=0, res2=0;
    413 
    414   malloc_string(command);
    415 
    416   if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) && g_backup_media_type!=udev)
    417     {
    418       sprintf(command, "mt -f %s offline", dev);
    419       res1 = run_program_and_log_output(command, 1);
    420     }
    421   else
    422     {
    423       res1 = 0;
    424     }
     421int eject_device(char *dev)
     422{
     423    char *command;
     424    int res1 = 0, res2 = 0;
     425
     426    malloc_string(command);
     427
     428    if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
     429        && g_backup_media_type != udev) {
     430        sprintf(command, "mt -f %s offline", dev);
     431        res1 = run_program_and_log_output(command, 1);
     432    } else {
     433        res1 = 0;
     434    }
    425435
    426436#ifdef __FreeBSD__
    427   if (strstr (dev, "acd")) {
    428       sprintf (command, "cdcontrol -f %s eject", dev);
    429   } else {
    430       sprintf (command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev);
    431   }
     437    if (strstr(dev, "acd")) {
     438        sprintf(command, "cdcontrol -f %s eject", dev);
     439    } else {
     440        sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`",
     441                dev);
     442    }
    432443#else
    433   sprintf(command, "eject %s", dev);
    434 #endif
    435 
    436   log_msg(3, "Ejecting %s", dev);
    437   res2 = run_program_and_log_output(command, 1);
    438   paranoid_free(command);
    439   if (res1 && res2) { return(1); }
    440   else { return(0); }
     444    sprintf(command, "eject %s", dev);
     445#endif
     446
     447    log_msg(3, "Ejecting %s", dev);
     448    res2 = run_program_and_log_output(command, 1);
     449    paranoid_free(command);
     450    if (res1 && res2) {
     451        return (1);
     452    } else {
     453        return (0);
     454    }
    441455}
    442456
     
    446460 * @return 0 for success, nonzero for failure.
    447461 */
    448 int inject_device(char*dev)
    449 {
    450   char *command;
    451   int i;
    452 
    453   malloc_string(command);
     462int inject_device(char *dev)
     463{
     464    char *command;
     465    int i;
     466
     467    malloc_string(command);
    454468
    455469
    456470#ifdef __FreeBSD__
    457   if (strstr (dev, "acd")) {
    458       sprintf (command, "cdcontrol -f %s close", dev);
    459   } else {
    460       sprintf (command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev);
    461   }
     471    if (strstr(dev, "acd")) {
     472        sprintf(command, "cdcontrol -f %s close", dev);
     473    } else {
     474        sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`",
     475                dev);
     476    }
    462477#else
    463   sprintf(command, "eject -t %s", dev);
    464 #endif
    465   i = run_program_and_log_output(command, FALSE);
    466   paranoid_free(command);
    467   return(i);
     478    sprintf(command, "eject -t %s", dev);
     479#endif
     480    i = run_program_and_log_output(command, FALSE);
     481    paranoid_free(command);
     482    return (i);
    468483}
    469484
     
    474489 * @return TRUE if it exists, FALSE if it doesn't.
    475490 */
    476 bool
    477 does_device_exist (char *device)
    478 {
    479 
    480     /*@ buffers ************************************************************/
    481   char *tmp;
    482 
    483   malloc_string(tmp);
    484   assert_string_is_neither_NULL_nor_zerolength(device);
    485 
    486   sprintf (tmp, "ls %s > /dev/null 2> /dev/null", device);
    487  
    488   paranoid_free(tmp);
    489   if (system (tmp))
    490     {
    491       return (FALSE);
    492     }
    493   else
    494     {
    495       return (TRUE);
    496     }
     491bool does_device_exist(char *device)
     492{
     493
     494    /*@ buffers *********************************************************** */
     495    char *tmp;
     496
     497    malloc_string(tmp);
     498    assert_string_is_neither_NULL_nor_zerolength(device);
     499
     500    sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
     501
     502    paranoid_free(tmp);
     503    if (system(tmp)) {
     504        return (FALSE);
     505    } else {
     506        return (TRUE);
     507    }
    497508}
    498509
     
    502513 * @return TRUE (there's a Linux/FreeBSD partition) or FALSE (Microsoft has taken over yet another innocent PC).
    503514 */
    504 bool
    505 does_nonMS_partition_exist (void)
     515bool does_nonMS_partition_exist(void)
    506516{
    507517#if __FreeBSD__
    508     return !system ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
     518    return
     519        !system
     520        ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
    509521#else
    510     return !system ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | egrep -qv '(MS|DOS|FAT|NTFS)'");
     522    return
     523        !system
     524        ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | egrep -qv '(MS|DOS|FAT|NTFS)'");
    511525#endif
    512526}
     
    518532 * @return 0 if it exists, nonzero otherwise.
    519533 */
    520 int
    521 does_partition_exist (const char *drive, int partno)
    522 {
    523     /*@ buffers *****************************************************/
    524   char *program;
    525   char *incoming;
    526   char *searchstr;
    527   char *tmp;
    528 
    529     /*@ ints ********************************************************/
    530   int res = 0;
    531 
    532     /*@ pointers ****************************************************/
    533   FILE *fin;
    534 
    535 
    536     /*@ end vars ****************************************************/
    537   assert_string_is_neither_NULL_nor_zerolength(drive);
    538   assert(partno>=0 && partno<999);
    539 
    540   malloc_string(program);
    541   malloc_string(incoming);
    542   malloc_string(searchstr);
    543   malloc_string(tmp);
     534int does_partition_exist(const char *drive, int partno)
     535{
     536    /*@ buffers **************************************************** */
     537    char *program;
     538    char *incoming;
     539    char *searchstr;
     540    char *tmp;
     541
     542    /*@ ints ******************************************************* */
     543    int res = 0;
     544
     545    /*@ pointers *************************************************** */
     546    FILE *fin;
     547
     548
     549    /*@ end vars *************************************************** */
     550    assert_string_is_neither_NULL_nor_zerolength(drive);
     551    assert(partno >= 0 && partno < 999);
     552
     553    malloc_string(program);
     554    malloc_string(incoming);
     555    malloc_string(searchstr);
     556    malloc_string(tmp);
    544557
    545558#ifdef __FreeBSD__
    546   // We assume here that this is running from mondorestore. (It is.)
    547   sprintf (program, "ls %s >/dev/null 2>&1", drive, build_partition_name (tmp, drive, partno));
    548   return system (program);
     559    // We assume here that this is running from mondorestore. (It is.)
     560    sprintf(program, "ls %s >/dev/null 2>&1", drive,
     561            build_partition_name(tmp, drive, partno));
     562    return system(program);
    549563#else
    550   tmp[0] = '\0';
    551 #endif
    552 
    553   sprintf (program, "parted2fdisk -l %s 2> /dev/null", drive);
    554   fin = popen (program, "r");
    555   if (!fin)
    556     {
    557       log_it("program=%s", program);
    558       log_OS_error("Cannot popen-in program");
    559       return (0);
    560     }
    561   (void) build_partition_name (searchstr, drive, partno);
    562   strcat(searchstr, " ");
    563   for (res = 0; !res && fgets (incoming, MAX_STR_LEN - 1, fin); )
    564     {
    565       if (strstr (incoming, searchstr))
    566     {
    567       res = 1;
    568     }
    569     }
    570   if (pclose (fin)) { log_OS_error("Cannot pclose fin"); }
    571   paranoid_free(program);
    572   paranoid_free(incoming);
    573   paranoid_free(searchstr);
    574   paranoid_free(tmp);
    575   return (res);
     564    tmp[0] = '\0';
     565#endif
     566
     567    sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
     568    fin = popen(program, "r");
     569    if (!fin) {
     570        log_it("program=%s", program);
     571        log_OS_error("Cannot popen-in program");
     572        return (0);
     573    }
     574    (void) build_partition_name(searchstr, drive, partno);
     575    strcat(searchstr, " ");
     576    for (res = 0; !res && fgets(incoming, MAX_STR_LEN - 1, fin);) {
     577        if (strstr(incoming, searchstr)) {
     578            res = 1;
     579        }
     580    }
     581    if (pclose(fin)) {
     582        log_OS_error("Cannot pclose fin");
     583    }
     584    paranoid_free(program);
     585    paranoid_free(incoming);
     586    paranoid_free(searchstr);
     587    paranoid_free(tmp);
     588    return (res);
    576589}
    577590
     
    586599 * @return TRUE if it exists, FALSE if it doesn't.
    587600 */
    588 bool
    589 does_string_exist_in_boot_block (char *dev, char *str)
    590 {
    591     /*@ buffers *****************************************************/
    592   char *command;
    593 
    594     /*@ end vars ****************************************************/
    595   int i;
    596 
    597   assert_string_is_neither_NULL_nor_zerolength(dev);
    598   assert_string_is_neither_NULL_nor_zerolength(str);
    599 
    600   malloc_string(command);
    601   sprintf (command,
    602        "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    603        dev, str);
    604   i = system(command);
    605   paranoid_free(command);
    606   if (i)
    607     {
    608       return (FALSE);
    609     }
    610   else
    611     {
    612       return (TRUE);
    613     }
     601bool does_string_exist_in_boot_block(char *dev, char *str)
     602{
     603    /*@ buffers **************************************************** */
     604    char *command;
     605
     606    /*@ end vars *************************************************** */
     607    int i;
     608
     609    assert_string_is_neither_NULL_nor_zerolength(dev);
     610    assert_string_is_neither_NULL_nor_zerolength(str);
     611
     612    malloc_string(command);
     613    sprintf(command,
     614            "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
     615            dev, str);
     616    i = system(command);
     617    paranoid_free(command);
     618    if (i) {
     619        return (FALSE);
     620    } else {
     621        return (TRUE);
     622    }
    614623}
    615624
     
    621630 * @param n The number of 512-byte sectors to search.
    622631 */
    623 bool
    624 does_string_exist_in_first_N_blocks (char *dev, char *str, int n)
    625 {
    626       /*@ buffers *****************************************************/
    627   char *command;
    628       /*@ end vars ****************************************************/
    629   int i;
    630 
    631   malloc_string(command);
    632   sprintf (command,
    633          "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    634          dev, n, str);
    635   i = system(command);
    636   paranoid_free(command);
    637   if (i)
    638     {
    639       return (FALSE);
    640     }
    641   else
    642     {
    643       return (TRUE);
    644     }
     632bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n)
     633{
     634    /*@ buffers **************************************************** */
     635    char *command;
     636    /*@ end vars *************************************************** */
     637    int i;
     638
     639    malloc_string(command);
     640    sprintf(command,
     641            "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
     642            dev, n, str);
     643    i = system(command);
     644    paranoid_free(command);
     645    if (i) {
     646        return (FALSE);
     647    } else {
     648        return (TRUE);
     649    }
    645650}
    646651
     
    655660 * @see mount_CDROM_here
    656661 */
    657 int
    658 find_and_mount_actual_cd (struct s_bkpinfo *bkpinfo, char *mountpoint)
    659 {
    660     /*@ buffers ******************************************************/
    661 
    662     /*@ int's  *******************************************************/
    663   int res;
    664   char *dev;
    665 
    666     /*@ end vars *****************************************************/
    667 
    668   malloc_string(dev);
    669   assert(bkpinfo!=NULL);
    670   assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    671 
    672   if (g_backup_media_type == dvd)
    673     {
    674       strcpy(dev, g_dvd_drive_is_here);
    675       if (!dev[0])
    676         { find_dvd_device(dev,FALSE); }
    677     }
    678   else
    679     {
    680       strcpy(dev, g_cdrom_drive_is_here);
    681       if (!dev[0])
    682         { find_cdrom_device(dev,FALSE); }
    683     }
    684 
    685   if (bkpinfo->backup_media_type != iso)
    686     { retract_CD_tray_and_defeat_autorun(); }
    687 
    688   if (!dev[0] || (res=mount_CDROM_here (dev, mountpoint)))
    689     {
    690       if (!popup_and_get_string
     662int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint)
     663{
     664    /*@ buffers ***************************************************** */
     665
     666    /*@ int's  ****************************************************** */
     667    int res;
     668    char *dev;
     669
     670    /*@ end vars **************************************************** */
     671
     672    malloc_string(dev);
     673    assert(bkpinfo != NULL);
     674    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     675
     676    if (g_backup_media_type == dvd) {
     677        strcpy(dev, g_dvd_drive_is_here);
     678        if (!dev[0]) {
     679            find_dvd_device(dev, FALSE);
     680        }
     681    } else {
     682        strcpy(dev, g_cdrom_drive_is_here);
     683        if (!dev[0]) {
     684            find_cdrom_device(dev, FALSE);
     685        }
     686    }
     687
     688    if (bkpinfo->backup_media_type != iso) {
     689        retract_CD_tray_and_defeat_autorun();
     690    }
     691
     692    if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
     693        if (!popup_and_get_string
    691694            ("CD-ROM device", "Please enter your CD-ROM's /dev device",
    692             dev, MAX_STR_LEN/4))
    693     { res = 1; }
    694       else
    695     { res=mount_CDROM_here (dev, mountpoint); }
    696     }
    697   if (res) { log_msg(1, "mount failed"); }
    698   else { log_msg(1, "mount succeeded with %s", dev); }
    699   paranoid_free(dev);
    700   return (res);
     695             dev, MAX_STR_LEN / 4)) {
     696            res = 1;
     697        } else {
     698            res = mount_CDROM_here(dev, mountpoint);
     699        }
     700    }
     701    if (res) {
     702        log_msg(1, "mount failed");
     703    } else {
     704        log_msg(1, "mount succeeded with %s", dev);
     705    }
     706    paranoid_free(dev);
     707    return (res);
    701708}
    702709
     
    717724 * @return 0 for success, nonzero for failure.
    718725 */
    719 int
    720 find_cdrw_device (char *cdrw_device)
    721 {
    722     /*@ buffers *************************/
    723   char *comment;
    724   char *tmp;
    725   char *cdr_exe;
    726   char *command;
    727 
    728   malloc_string(comment);
    729   malloc_string(tmp);
    730   malloc_string(cdr_exe);
    731   malloc_string(command);
    732   if (g_cdrw_drive_is_here[0])
    733     {
    734       strcpy(cdrw_device, g_cdrw_drive_is_here);
    735       log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    736   paranoid_free(comment);
    737   paranoid_free(tmp);
    738   paranoid_free(cdr_exe);
    739   paranoid_free(command);
    740       return(0);
    741     }
    742   if (g_backup_media_type == dvd)
    743     {
    744       log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    745   paranoid_free(comment);
    746   paranoid_free(tmp);
    747   paranoid_free(cdr_exe);
    748   paranoid_free(command);
    749       return(1);
    750     }
    751   run_program_and_log_output("insmod ide-scsi", -1);
    752   if (find_home_of_exe("cdrecord"))
    753     { strcpy(cdr_exe, "cdrecord"); }
    754   else
    755     { strcpy(cdr_exe, "dvdrecord"); }
    756   tmp[0]='\0';
    757   if (find_home_of_exe(cdr_exe))
    758     {
    759       sprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", cdr_exe);
    760       strcpy (tmp, call_program_and_get_last_line_of_output(command));
    761     }
    762   if (strlen (tmp) < 2)
    763     {
    764   paranoid_free(comment);
    765   paranoid_free(tmp);
    766   paranoid_free(cdr_exe);
    767   paranoid_free(command);
    768       return 1;
    769     }
    770   else
    771     {
    772       strcpy (cdrw_device, tmp);
    773       sprintf (comment, "Found CDRW device - %s", cdrw_device);
    774       log_it (comment);
    775       strcpy (g_cdrw_drive_is_here, cdrw_device);
    776       paranoid_free(comment);
    777       paranoid_free(tmp);
    778       paranoid_free(cdr_exe);
    779       paranoid_free(command);
    780       return (0);
    781     }
     726int find_cdrw_device(char *cdrw_device)
     727{
     728    /*@ buffers ************************ */
     729    char *comment;
     730    char *tmp;
     731    char *cdr_exe;
     732    char *command;
     733
     734    malloc_string(comment);
     735    malloc_string(tmp);
     736    malloc_string(cdr_exe);
     737    malloc_string(command);
     738    if (g_cdrw_drive_is_here[0]) {
     739        strcpy(cdrw_device, g_cdrw_drive_is_here);
     740        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
     741        paranoid_free(comment);
     742        paranoid_free(tmp);
     743        paranoid_free(cdr_exe);
     744        paranoid_free(command);
     745        return (0);
     746    }
     747    if (g_backup_media_type == dvd) {
     748        log_msg(1,
     749                "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
     750        paranoid_free(comment);
     751        paranoid_free(tmp);
     752        paranoid_free(cdr_exe);
     753        paranoid_free(command);
     754        return (1);
     755    }
     756    run_program_and_log_output("insmod ide-scsi", -1);
     757    if (find_home_of_exe("cdrecord")) {
     758        strcpy(cdr_exe, "cdrecord");
     759    } else {
     760        strcpy(cdr_exe, "dvdrecord");
     761    }
     762    tmp[0] = '\0';
     763    if (find_home_of_exe(cdr_exe)) {
     764        sprintf(command,
     765                "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1",
     766                cdr_exe);
     767        strcpy(tmp, call_program_and_get_last_line_of_output(command));
     768    }
     769    if (strlen(tmp) < 2) {
     770        paranoid_free(comment);
     771        paranoid_free(tmp);
     772        paranoid_free(cdr_exe);
     773        paranoid_free(command);
     774        return 1;
     775    } else {
     776        strcpy(cdrw_device, tmp);
     777        sprintf(comment, "Found CDRW device - %s", cdrw_device);
     778        log_it(comment);
     779        strcpy(g_cdrw_drive_is_here, cdrw_device);
     780        paranoid_free(comment);
     781        paranoid_free(tmp);
     782        paranoid_free(cdr_exe);
     783        paranoid_free(command);
     784        return (0);
     785    }
    782786}
    783787
     
    794798 * @return 0 for success, nonzero for failure.
    795799 */
    796 int
    797 find_cdrom_device (char *output, bool try_to_mount)
    798 {
    799     /*@ pointers *****************************************************/
    800   FILE *fin;
    801   char *p;
    802   char *q;
    803   char *r;
    804   int retval=0;
    805 
    806     /*@ bool's *******************************************************/
    807   bool found_it = FALSE;
    808 
    809     /*@ buffers ******************************************************/
    810   char *tmp;
    811   char *cdr_exe;
    812   char *phrase_one;
    813   char *phrase_two;
    814   char *command;
    815   char *dvd_last_resort;
    816   char *mountpoint;
    817   static char the_last_place_i_found_it[MAX_STR_LEN] = "";
    818 
    819     /*@ intialize ****************************************************/
    820   malloc_string(tmp);
    821   malloc_string(cdr_exe);
    822   malloc_string(phrase_one);
    823   malloc_string(phrase_two);
    824   malloc_string(command);
    825   malloc_string(dvd_last_resort);
    826   malloc_string(mountpoint);
    827  
    828   output[0] = '\0';
    829   phrase_one[0] = '\0';
    830   phrase_two[0] = '\0';
    831   dvd_last_resort[0] = '\0';
    832 
    833     /*@ end vars *****************************************************/
    834 
    835   if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0]))
    836     {
    837       strcpy(output, g_cdrom_drive_is_here);
    838       log_msg(3, "Been there, done that. Returning %s", output);
    839       retval=0;
    840       goto end_of_find_cdrom_device;
    841     }
    842   if (the_last_place_i_found_it[0]!='\0' && !try_to_mount)
    843     {
    844         strcpy(output, the_last_place_i_found_it);
    845         log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output);
    846         retval=0;
    847     goto end_of_find_cdrom_device;
    848     }
    849 
    850   sprintf(mountpoint,"/tmp/cd.%d", (int)(random()%32767));
    851   make_hole_for_dir(mountpoint);
    852 
    853   if (find_home_of_exe("cdrecord"))
    854     { strcpy(cdr_exe, "cdrecord"); }
    855   else
    856     { strcpy(cdr_exe, "dvdrecord"); }
    857   tmp[0]='\0';
    858   if (!find_home_of_exe(cdr_exe))
    859     {
    860       strcpy(output, "/dev/cdrom");
    861       log_msg(4, "Can't find cdrecord; assuming %s", output);
    862       if (!does_device_exist(output))
    863         {
    864           log_msg(4, "That didn't work. Sorry.");
    865           retval=1;
    866           goto end_of_find_cdrom_device;
    867         }
    868       else
    869         {
    870           retval=0;
    871           goto end_of_find_cdrom_device;
    872         }
    873     }
    874 
    875   sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
    876   fin = popen (command, "r");
    877   if (!fin) { log_msg(4, "command=%s", command); log_OS_error("Cannot popen command"); return (1); }
    878   for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin);
    879        fgets (tmp, MAX_STR_LEN, fin))
    880     {
    881       p = strchr (tmp, '\'');
    882       if (p)
    883     {
    884       q = strchr (++p, '\'');
    885       if (q)
    886         {
    887           for (r = q; *(r - 1) == ' '; r--);
    888           *r = '\0';
    889           strcpy (phrase_one, p);
    890           p = strchr (++q, '\'');
    891           if (p)
    892         {
    893           q = strchr (++p, '\'');
    894           if (q)
    895             {
    896               while (*(q - 1) == ' ')
    897             {
    898               q--;
    899             }
    900               *q = '\0';
    901               strcpy (phrase_two, p);
    902             }
    903         }
    904         }
    905     }
    906     }
    907   paranoid_pclose(fin);
     800int find_cdrom_device(char *output, bool try_to_mount)
     801{
     802    /*@ pointers **************************************************** */
     803    FILE *fin;
     804    char *p;
     805    char *q;
     806    char *r;
     807    int retval = 0;
     808
     809    /*@ bool's ****************************************************** */
     810    bool found_it = FALSE;
     811
     812    /*@ buffers ***************************************************** */
     813    char *tmp;
     814    char *cdr_exe;
     815    char *phrase_one;
     816    char *phrase_two;
     817    char *command;
     818    char *dvd_last_resort;
     819    char *mountpoint;
     820    static char the_last_place_i_found_it[MAX_STR_LEN] = "";
     821
     822    /*@ intialize *************************************************** */
     823    malloc_string(tmp);
     824    malloc_string(cdr_exe);
     825    malloc_string(phrase_one);
     826    malloc_string(phrase_two);
     827    malloc_string(command);
     828    malloc_string(dvd_last_resort);
     829    malloc_string(mountpoint);
     830
     831    output[0] = '\0';
     832    phrase_one[0] = '\0';
     833    phrase_two[0] = '\0';
     834    dvd_last_resort[0] = '\0';
     835
     836    /*@ end vars **************************************************** */
     837
     838    if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) {
     839        strcpy(output, g_cdrom_drive_is_here);
     840        log_msg(3, "Been there, done that. Returning %s", output);
     841        retval = 0;
     842        goto end_of_find_cdrom_device;
     843    }
     844    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
     845        strcpy(output, the_last_place_i_found_it);
     846        log_msg(3,
     847                "find_cdrom_device() --- returning last found location - '%s'",
     848                output);
     849        retval = 0;
     850        goto end_of_find_cdrom_device;
     851    }
     852
     853    sprintf(mountpoint, "/tmp/cd.%d", (int) (random() % 32767));
     854    make_hole_for_dir(mountpoint);
     855
     856    if (find_home_of_exe("cdrecord")) {
     857        strcpy(cdr_exe, "cdrecord");
     858    } else {
     859        strcpy(cdr_exe, "dvdrecord");
     860    }
     861    tmp[0] = '\0';
     862    if (!find_home_of_exe(cdr_exe)) {
     863        strcpy(output, "/dev/cdrom");
     864        log_msg(4, "Can't find cdrecord; assuming %s", output);
     865        if (!does_device_exist(output)) {
     866            log_msg(4, "That didn't work. Sorry.");
     867            retval = 1;
     868            goto end_of_find_cdrom_device;
     869        } else {
     870            retval = 0;
     871            goto end_of_find_cdrom_device;
     872        }
     873    }
     874
     875    sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
     876    fin = popen(command, "r");
     877    if (!fin) {
     878        log_msg(4, "command=%s", command);
     879        log_OS_error("Cannot popen command");
     880        return (1);
     881    }
     882    for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     883         fgets(tmp, MAX_STR_LEN, fin)) {
     884        p = strchr(tmp, '\'');
     885        if (p) {
     886            q = strchr(++p, '\'');
     887            if (q) {
     888                for (r = q; *(r - 1) == ' '; r--);
     889                *r = '\0';
     890                strcpy(phrase_one, p);
     891                p = strchr(++q, '\'');
     892                if (p) {
     893                    q = strchr(++p, '\'');
     894                    if (q) {
     895                        while (*(q - 1) == ' ') {
     896                            q--;
     897                        }
     898                        *q = '\0';
     899                        strcpy(phrase_two, p);
     900                    }
     901                }
     902            }
     903        }
     904    }
     905    paranoid_pclose(fin);
    908906
    909907#ifndef __FreeBSD__
    910   if (strlen(phrase_two)==0)
    911     { log_msg(4, "Not running phase two. String is empty."); }
    912   else
    913     {
    914       sprintf (command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
    915       fin = popen (command, "r");
    916       if (!fin)
    917         {
    918           log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
    919         }
    920       else
    921         {
    922           for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin); fgets (tmp, MAX_STR_LEN, fin))
    923         {
    924               log_msg(5, "--> '%s'", tmp);
    925               if (tmp[0] != ' ' && tmp[1] != ' ')
    926             {
    927               p = strchr (tmp, ':');
    928               if (p)
    929             {
    930               *p = '\0';
    931               if (strstr(tmp, "DVD"))
    932                 {
    933                   sprintf(dvd_last_resort, "/dev/%s", tmp);
    934                   log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp);
    935                 }
    936               else
    937                 {
    938                   sprintf (output, "/dev/%s", tmp);
    939                   found_it = TRUE;
    940                 }
    941             }
    942                 }
    943             }
    944           paranoid_pclose(fin);
    945         }
    946     }
     908    if (strlen(phrase_two) == 0) {
     909        log_msg(4, "Not running phase two. String is empty.");
     910    } else {
     911        sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
     912        fin = popen(command, "r");
     913        if (!fin) {
     914            log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
     915        } else {
     916            for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     917                 fgets(tmp, MAX_STR_LEN, fin)) {
     918                log_msg(5, "--> '%s'", tmp);
     919                if (tmp[0] != ' ' && tmp[1] != ' ') {
     920                    p = strchr(tmp, ':');
     921                    if (p) {
     922                        *p = '\0';
     923                        if (strstr(tmp, "DVD")) {
     924                            sprintf(dvd_last_resort, "/dev/%s", tmp);
     925                            log_msg(4,
     926                                    "Ignoring '%s' because it's a DVD drive",
     927                                    tmp);
     928                        } else {
     929                            sprintf(output, "/dev/%s", tmp);
     930                            found_it = TRUE;
     931                        }
     932                    }
     933                }
     934            }
     935            paranoid_pclose(fin);
     936        }
     937    }
    947938
    948939#endif
    949940#ifdef __FreeBSD__
    950   if (!found_it)
    951       { log_msg(4, "OK, approach 2"); if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom")))
    952         { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom1")))
    953           { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/dvd")))
    954             { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/acd0")))
    955               { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cd01")))
    956                 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/acd1")))
    957                   { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cd1")))
    958               { retval=1; goto end_of_find_cdrom_device; }
    959           } } } } } } }
     941    if (!found_it) {
     942        log_msg(4, "OK, approach 2");
     943        if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
     944            if (!
     945                (found_it =
     946                 set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) {
     947                if (!
     948                    (found_it =
     949                     set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) {
     950                    if (!
     951                        (found_it =
     952                         set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) {
     953                        if (!
     954                            (found_it =
     955                             set_dev_to_this_if_rx_OK(output,
     956                                                      "/dev/cd01"))) {
     957                            if (!
     958                                (found_it =
     959                                 set_dev_to_this_if_rx_OK(output,
     960                                                          "/dev/acd1"))) {
     961                                if (!
     962                                    (found_it =
     963                                     set_dev_to_this_if_rx_OK(output,
     964                                                              "/dev/cd1")))
     965                                {
     966                                    retval = 1;
     967                                    goto end_of_find_cdrom_device;
     968                                }
     969                            }
     970                        }
     971                    }
     972                }
     973            }
     974        }
     975    }
    960976#else
    961   if (!found_it && strlen(dvd_last_resort)>0)
    962     {
    963       log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort);
    964       strcpy(output, dvd_last_resort);
    965       found_it = TRUE;
    966     }
    967   if (found_it)
    968     {
    969       sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output,'/')+1);
    970       if (system(tmp) == 0)
    971     {
    972       log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
    973       found_it = FALSE;
    974       output[0] = '\0';
    975     }
    976     }
    977 
    978   if (found_it)
    979     {
    980       log_msg(4, "(find_cdrom_device) --> '%s'", output);
    981       if (!does_device_exist(output)) { found_it=FALSE; log_msg(4, "OK, I was wrong, I haven't found it... yet."); }
    982     }
    983 
    984   if (!found_it)
    985       { log_msg(4, "OK, approach 2"); if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0")))
    986         { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0" )))
    987           { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom")))
    988             { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom0")))
    989               { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom1")))
    990         { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr1")))
    991                   { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/dvd")))
    992             { if (!(found_it = set_dev_to_this_if_rx_OK(output, g_cdrw_drive_is_here)))
    993               { retval=1; goto end_of_find_cdrom_device; }
    994             } } } } } } } }
    995 #endif
    996 
    997   if (found_it && try_to_mount)
    998     {
    999       if (mount_CDROM_here (output, mountpoint))
    1000         {
    1001           log_msg(4, "[Cardigans] I've changed my mind");
    1002           found_it = FALSE;
    1003         }
    1004       else
    1005         {
    1006           sprintf(tmp, "%s/archives", mountpoint);
    1007           if (!does_file_exist(tmp))
    1008             {
    1009               log_msg(4, "[Cardigans] I'll take it back");
    1010               found_it = FALSE;
    1011             }
    1012           else
    1013             {
    1014               sprintf(command, "umount %s", output);
    1015               paranoid_system(command);
    1016               log_msg(4, "I'm confident the Mondo CD is in %s", output);
    1017         }
    1018         }
    1019     }
    1020   unlink(mountpoint);
    1021 
    1022   if (found_it)
    1023     {
    1024       if (!does_file_exist(output)) { log_msg(3, "I still haven't found it."); return(1); }
    1025       log_msg(3, "(find_cdrom_device) --> '%s'", output);
    1026       strcpy(the_last_place_i_found_it, output);
    1027       strcpy(g_cdrom_drive_is_here, output);
    1028       retval=0;
    1029       goto end_of_find_cdrom_device;
    1030     }
    1031 
    1032   sprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here);
    1033   log_msg(1, "command=%s", command);
    1034   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1035   if (tmp[0])
    1036     {
    1037       strcpy(output, tmp);
    1038       log_msg(4, "Finally found it at %s", output);
    1039       retval=0;
    1040       goto end_of_find_cdrom_device;
    1041     }
    1042   else
    1043     {
    1044       log_msg(4, "Still couldn't find it.");
    1045       retval=1;
    1046       goto end_of_find_cdrom_device;
    1047     }
    1048 end_of_find_cdrom_device:
    1049   paranoid_free(tmp);
    1050   paranoid_free(cdr_exe);
    1051   paranoid_free(phrase_one);
    1052   paranoid_free(phrase_two);
    1053   paranoid_free(command);
    1054   paranoid_free(dvd_last_resort);
    1055   paranoid_free(mountpoint);
    1056   return(retval);
    1057 }
    1058 
    1059 
    1060 
    1061 
    1062 
    1063 int find_dvd_device(char*output, bool try_to_mount)
    1064 {
    1065   char *command;
    1066   char *tmp;
    1067   int retval=0, devno=-1;
    1068 
    1069   malloc_string(command);
    1070   malloc_string(tmp);
    1071 
    1072     if (g_dvd_drive_is_here[0])
    1073     {
    1074       strcpy(output, g_dvd_drive_is_here);
    1075       log_msg(3, "Been there, done that. Returning %s", output);
    1076       return(0);
    1077     }
    1078 
    1079   sprintf(tmp, call_program_and_get_last_line_of_output
    1080             (
    1081 "dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1"
    1082             )
     977    if (!found_it && strlen(dvd_last_resort) > 0) {
     978        log_msg(4, "Well, I'll use the DVD - %s - as a last resort",
     979                dvd_last_resort);
     980        strcpy(output, dvd_last_resort);
     981        found_it = TRUE;
     982    }
     983    if (found_it) {
     984        sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",
     985                strrchr(output, '/') + 1);
     986        if (system(tmp) == 0) {
     987            log_msg(4,
     988                    "%s is not right. It's being SCSI-emulated. Continuing.",
     989                    output);
     990            found_it = FALSE;
     991            output[0] = '\0';
     992        }
     993    }
     994
     995    if (found_it) {
     996        log_msg(4, "(find_cdrom_device) --> '%s'", output);
     997        if (!does_device_exist(output)) {
     998            found_it = FALSE;
     999            log_msg(4, "OK, I was wrong, I haven't found it... yet.");
     1000        }
     1001    }
     1002
     1003    if (!found_it) {
     1004        log_msg(4, "OK, approach 2");
     1005        if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) {
     1006            if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0"))) {
     1007                if (!
     1008                    (found_it =
     1009                     set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
     1010                    if (!
     1011                        (found_it =
     1012                         set_dev_to_this_if_rx_OK(output,
     1013                                                  "/dev/cdrom0"))) {
     1014                        if (!
     1015                            (found_it =
     1016                             set_dev_to_this_if_rx_OK(output,
     1017                                                      "/dev/cdrom1"))) {
     1018                            if (!
     1019                                (found_it =
     1020                                 set_dev_to_this_if_rx_OK(output,
     1021                                                          "/dev/sr1"))) {
     1022                                if (!
     1023                                    (found_it =
     1024                                     set_dev_to_this_if_rx_OK(output,
     1025                                                              "/dev/dvd")))
     1026                                {
     1027                                    if (!
     1028                                        (found_it =
     1029                                         set_dev_to_this_if_rx_OK(output,
     1030                                                                  g_cdrw_drive_is_here)))
     1031                                    {
     1032                                        retval = 1;
     1033                                        goto end_of_find_cdrom_device;
     1034                                    }
     1035                                }
     1036                            }
     1037                        }
     1038                    }
     1039                }
     1040            }
     1041        }
     1042    }
     1043#endif
     1044
     1045    if (found_it && try_to_mount) {
     1046        if (mount_CDROM_here(output, mountpoint)) {
     1047            log_msg(4, "[Cardigans] I've changed my mind");
     1048            found_it = FALSE;
     1049        } else {
     1050            sprintf(tmp, "%s/archives", mountpoint);
     1051            if (!does_file_exist(tmp)) {
     1052                log_msg(4, "[Cardigans] I'll take it back");
     1053                found_it = FALSE;
     1054            } else {
     1055                sprintf(command, "umount %s", output);
     1056                paranoid_system(command);
     1057                log_msg(4, "I'm confident the Mondo CD is in %s", output);
     1058            }
     1059        }
     1060    }
     1061    unlink(mountpoint);
     1062
     1063    if (found_it) {
     1064        if (!does_file_exist(output)) {
     1065            log_msg(3, "I still haven't found it.");
     1066            return (1);
     1067        }
     1068        log_msg(3, "(find_cdrom_device) --> '%s'", output);
     1069        strcpy(the_last_place_i_found_it, output);
     1070        strcpy(g_cdrom_drive_is_here, output);
     1071        retval = 0;
     1072        goto end_of_find_cdrom_device;
     1073    }
     1074
     1075    sprintf(command,
     1076            "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2",
     1077            cdr_exe, g_cdrw_drive_is_here);
     1078    log_msg(1, "command=%s", command);
     1079    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1080    if (tmp[0]) {
     1081        strcpy(output, tmp);
     1082        log_msg(4, "Finally found it at %s", output);
     1083        retval = 0;
     1084        goto end_of_find_cdrom_device;
     1085    } else {
     1086        log_msg(4, "Still couldn't find it.");
     1087        retval = 1;
     1088        goto end_of_find_cdrom_device;
     1089    }
     1090  end_of_find_cdrom_device:
     1091    paranoid_free(tmp);
     1092    paranoid_free(cdr_exe);
     1093    paranoid_free(phrase_one);
     1094    paranoid_free(phrase_two);
     1095    paranoid_free(command);
     1096    paranoid_free(dvd_last_resort);
     1097    paranoid_free(mountpoint);
     1098    return (retval);
     1099}
     1100
     1101
     1102
     1103
     1104
     1105int find_dvd_device(char *output, bool try_to_mount)
     1106{
     1107    char *command;
     1108    char *tmp;
     1109    int retval = 0, devno = -1;
     1110
     1111    malloc_string(command);
     1112    malloc_string(tmp);
     1113
     1114    if (g_dvd_drive_is_here[0]) {
     1115        strcpy(output, g_dvd_drive_is_here);
     1116        log_msg(3, "Been there, done that. Returning %s", output);
     1117        return (0);
     1118    }
     1119
     1120    sprintf(tmp, call_program_and_get_last_line_of_output
     1121            ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
    10831122        );
    1084   log_msg(5, "tmp = '%s'", tmp);
    1085   if (!tmp[0]) sprintf (tmp, call_program_and_get_last_line_of_output
    1086                  (
    1087 "cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1"
    1088                              )
    1089                        );
    1090   if (tmp[0])
    1091     {
    1092       devno=atoi(tmp) - 1;
    1093     }
    1094   if (devno>=0)
    1095     {
    1096       retval=0;
    1097       sprintf(output, "/dev/scd%d", devno);
    1098       strcpy(g_dvd_drive_is_here, output);
    1099       log_msg(2, "I think DVD is at %s", output);
    1100     }
    1101   else
    1102     {
    1103       log_msg(2,"I cannot find DVD");
    1104       retval=1;
    1105     }
    1106 
    1107   if (try_to_mount)
    1108     {
    1109       log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
    1110     }
    1111   return(retval);
     1123    log_msg(5, "tmp = '%s'", tmp);
     1124    if (!tmp[0])
     1125        sprintf(tmp, call_program_and_get_last_line_of_output
     1126                ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
     1127            );
     1128    if (tmp[0]) {
     1129        devno = atoi(tmp) - 1;
     1130    }
     1131    if (devno >= 0) {
     1132        retval = 0;
     1133        sprintf(output, "/dev/scd%d", devno);
     1134        strcpy(g_dvd_drive_is_here, output);
     1135        log_msg(2, "I think DVD is at %s", output);
     1136    } else {
     1137        log_msg(2, "I cannot find DVD");
     1138        retval = 1;
     1139    }
     1140
     1141    if (try_to_mount) {
     1142        log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
     1143    }
     1144    return (retval);
    11121145}
    11131146
     
    11241157 * @return size in megabytes.
    11251158 */
    1126 long
    1127 get_phys_size_of_drive (char *drive)
    1128 {
    1129     int fd;
     1159long get_phys_size_of_drive(char *drive)
     1160{
     1161    int fd;
    11301162#if linux
    1131     unsigned long long s=0;
    1132     int fileid, cylinders=0, cylindersleft=0;
    1133     int cylindersize=0;
     1163    unsigned long long s = 0;
     1164    int fileid, cylinders = 0, cylindersleft = 0;
     1165    int cylindersize = 0;
    11341166    int gotgeo = 0;
    11351167
    1136    
    1137   struct hd_geometry hdgeo;
     1168
     1169    struct hd_geometry hdgeo;
    11381170#elif __FreeBSD__
    1139     off_t s;
    1140 #endif
    1141 
    1142     long outvalA=-1;
    1143     long outvalB=-1;
    1144     long outvalC=-1;
    1145 
    1146     if ((fd = open (drive, O_RDONLY)) != -1) {
    1147     if (ioctl (fd,
     1171    off_t s;
     1172#endif
     1173
     1174    long outvalA = -1;
     1175    long outvalB = -1;
     1176    long outvalC = -1;
     1177
     1178    if ((fd = open(drive, O_RDONLY)) != -1) {
     1179        if (ioctl(fd,
    11481180#if linux
    1149     #ifdef BLKGETSIZE64
    1150             BLKGETSIZE64,
    1151     #else
    1152             BLKGETSIZE,
    1153    #endif
     1181#ifdef BLKGETSIZE64
     1182                  BLKGETSIZE64,
     1183#else
     1184                  BLKGETSIZE,
     1185#endif
    11541186#elif __FreeBSD__
    1155            DIOCGMEDIASIZE,
    1156 #endif
    1157            &s) != -1) {
    1158         close (fd);
    1159                     // s>>11 works for older disks but not for newer ones
    1160         outvalB =
     1187                  DIOCGMEDIASIZE,
     1188#endif
     1189                  &s) != -1) {
     1190            close(fd);
     1191            // s>>11 works for older disks but not for newer ones
     1192            outvalB =
    11611193#if linux
    1162     #ifdef BLKGETSIZE64 
    1163           s >> 20
    1164     #else
    1165               s >> 11
    1166     #endif
     1194#ifdef BLKGETSIZE64
     1195                s >> 20
    11671196#else
    1168               s >> 20
    1169 #endif
    1170 ;
    1171     }
    1172     }
    1173 
    1174     if (outvalB<=0)
    1175       { log_msg (1, "Error getting size of %s: %s", drive, strerror (errno)); }
     1197                s >> 11
     1198#endif
     1199#else
     1200                s >> 20
     1201#endif
     1202                ;
     1203        }
     1204    }
     1205
     1206    if (outvalB <= 0) {
     1207        log_msg(1, "Error getting size of %s: %s", drive, strerror(errno));
     1208    }
    11761209#if linux
    1177     fileid = open (drive, O_RDONLY);
     1210    fileid = open(drive, O_RDONLY);
    11781211    if (fileid) {
    1179         if (ioctl (fileid, HDIO_GETGEO, &hdgeo) != -1) {
     1212        if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
    11801213            if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
    11811214                cylindersleft = cylinders = hdgeo.cylinders;
    11821215                cylindersize = hdgeo.heads * hdgeo.sectors / 2;
    11831216                outvalA = cylindersize * cylinders / 1024;
    1184                 log_msg (2, "Got Harddisk geometry, C:%d, H:%d, S:%d", hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
     1217                log_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
     1218                        hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
    11851219                gotgeo = 1;
    11861220            } else {
    1187                 log_msg (1, "Harddisk geometry wrong");
     1221                log_msg(1, "Harddisk geometry wrong");
    11881222            }
    11891223        } else {
    1190             log_msg (1, "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode", strerror(errno));
     1224            log_msg(1,
     1225                    "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode",
     1226                    strerror(errno));
    11911227        }
    11921228        close(fileid);
    11931229    } else {
    1194         log_msg (1, "Failed to open %s for reading: %s", drive, strerror(errno));
     1230        log_msg(1, "Failed to open %s for reading: %s", drive,
     1231                strerror(errno));
    11951232    }
    11961233    if (!gotgeo) {
    1197         log_msg (1, "Failed to get harddisk geometry, using old mode");
     1234        log_msg(1, "Failed to get harddisk geometry, using old mode");
    11981235    }
    11991236/* 
     
    12131250// NEWER DISKS will give sane value for outvalB (close to outvalA, in other words) :)
    12141251
    1215   outvalC = (outvalA > outvalB) ? outvalA : outvalB;
    1216  
     1252    outvalC = (outvalA > outvalB) ? outvalA : outvalB;
     1253
    12171254//  log_msg (5, "drive = %s, error = %s", drive, strerror (errno));
    12181255//  fatal_error ("GPSOD: Unable to get size of drive");
    1219   log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB, outvalC);
    1220  
    1221   return(outvalC);
    1222 }
    1223    
     1256    log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB,
     1257            outvalC);
     1258
     1259    return (outvalC);
     1260}
     1261
    12241262/* The old version */
    1225 #if 0
    1226 long
    1227 get_phys_size_of_drive (char *drive)
    1228 {
    1229     /*@ pointers *****************************************************/
     1263#if 0
     1264long get_phys_size_of_drive(char *drive)
     1265{
     1266    /*@ pointers **************************************************** */
    12301267#if linux
    1231   FILE *fin;
    1232   char *p;
    1233   char *q;
    1234   char *r;
    1235     /*@ buffers ******************************************************/
    1236   char *tmp;
    1237   char *command;
    1238 
    1239     /*@ long *********************************************************/
    1240   long outL;
    1241   long tempLa;
    1242   long tempLb;
    1243   long tempLc;
    1244 
    1245 #endif
    1246 
    1247   struct hd_geometry hdgeo;
    1248   int fd;
     1268    FILE *fin;
     1269    char *p;
     1270    char *q;
     1271    char *r;
     1272    /*@ buffers ***************************************************** */
     1273    char *tmp;
     1274    char *command;
     1275
     1276    /*@ long ******************************************************** */
     1277    long outL;
     1278    long tempLa;
     1279    long tempLb;
     1280    long tempLc;
     1281
     1282#endif
     1283
     1284    struct hd_geometry hdgeo;
     1285    int fd;
    12491286
    12501287#ifdef __FreeBSD__
    1251   off_t o;
    1252 
    1253   if ((fd = open (drive, O_RDONLY)) != -1) {
    1254       if (ioctl (fd, DIOCGMEDIASIZE, &o) != -1) {
    1255       close (fd);
    1256       return (long) (o / (off_t) (1024 * 1024));
    1257       }
    1258       close (fd);
    1259   }
    1260   log_msg (4, "drive = %s, error = %s", drive, strerror (errno));
    1261   fatal_error ("GPSOD: Unable to get size of drive");
     1288    off_t o;
     1289
     1290    if ((fd = open(drive, O_RDONLY)) != -1) {
     1291        if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) {
     1292            close(fd);
     1293            return (long) (o / (off_t) (1024 * 1024));
     1294        }
     1295        close(fd);
     1296    }
     1297    log_msg(4, "drive = %s, error = %s", drive, strerror(errno));
     1298    fatal_error("GPSOD: Unable to get size of drive");
    12621299#else
    12631300
    1264   malloc_string(tmp);
    1265   malloc_string(command);
    1266 
    1267   if ((fd = open (drive, O_RDONLY)) != -1) {
    1268       if (ioctl (fd, HDIO_GETGEO, &hdgeo) != -1)  {
    1269       close (fd);
    1270       log_msg (2, "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB", drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors, (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));
    1271       if ( hdgeo.cylinders && hdgeo.heads && hdgeo.sectors ) {
    1272           return ((long) (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));
    1273       }
    1274       }
    1275       close (fd);
    1276   }
    1277 
    1278   assert_string_is_neither_NULL_nor_zerolength(drive);
    1279 
    1280   sprintf (command,
    1281        "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",
    1282        drive);
    1283   strcpy (tmp, call_program_and_get_last_line_of_output (command));
    1284   if (tmp[0])
    1285     {
    1286       p = tmp;
    1287       q = strchr (p, ' ');
    1288       if (q)
    1289     {
    1290       *(q++) = '\0';
    1291       r = strchr (q, ' ');
    1292       if (r)
    1293         {
    1294           *(r++) = '\0';
    1295           tempLa = atol (p);
    1296           tempLb = atol (q);
    1297           tempLc = atol (r);
    1298           outL = tempLa * tempLb / 1024 * tempLc / 1024;
    1299           if (outL > 100)
    1300         {
    1301       paranoid_free(tmp);
    1302       paranoid_free(command);
    1303           return (outL);
    1304         }
    1305         }
    1306     }
    1307     }
    1308 
    1309   /* try to grep for 'Drive xxxx: yyy MB' */
    1310   sprintf(command, "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3", drive);
    1311   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1312   if (atol(tmp) > 0)
    1313     {
    1314       paranoid_free(tmp);
    1315       paranoid_free(command);
    1316       return (atol(tmp));
    1317     }
    1318 
    1319   /* else, do it the old-fashioned way */
    1320   p = strrchr (drive, (int) '/');
    1321   if (p)
    1322     {
    1323       strcpy (tmp, p + 1);
    1324     }
    1325   else
    1326     {
    1327       paranoid_free(tmp);
    1328       paranoid_free(command);
    1329       return (-1);
    1330     }
    1331   sprintf (command, "dmesg | grep %s 2> /dev/null", tmp);
    1332   if (!(fin = popen (command, "r")))
    1333     { log_OS_error("Cannot popen dmesg command"); }
    1334   else
    1335     {
    1336       fgets (tmp, MAX_STR_LEN - 1, fin);
    1337       while (!feof (fin) && !strstr (tmp, "GB") && !strstr (tmp, "MB"))
    1338         {
    1339           fgets (tmp, MAX_STR_LEN - 1, fin);
    1340         }
    1341       if (pclose (fin)) { log_OS_error("Cannot pclose dmesg fin"); }
    1342     }
    1343   if (!(p = strstr (tmp, "GB")) && !(p = strstr (tmp, "MB")))
    1344     {
    1345       log_msg (3, "Cannot find %s's size: dmesg isn't helping either.",
    1346            drive);
    1347       paranoid_free(tmp);
    1348       paranoid_free(command);
    1349       return (-1);
    1350     }
    1351   for (; !isdigit (*(p - 1)); p--);
    1352   *p = '\0';
    1353   for (p--; isdigit (*(p - 1)); p--);
    1354   outL = atol (p);
    1355   if (outL <= 0)
    1356     {
    1357       paranoid_free(tmp);
    1358       paranoid_free(command);
    1359       return (-1);
    1360     }
    1361   if (strstr (tmp, "GB"))
    1362     {
    1363       outL = outL * 1024;
    1364     }
    1365       paranoid_free(tmp);
    1366       paranoid_free(command);
    1367   return (outL * 19 / 20);
    1368 #endif
    1369 }
    1370 #endif /* 0 */
     1301    malloc_string(tmp);
     1302    malloc_string(command);
     1303
     1304    if ((fd = open(drive, O_RDONLY)) != -1) {
     1305        if (ioctl(fd, HDIO_GETGEO, &hdgeo) != -1) {
     1306            close(fd);
     1307            log_msg(2,
     1308                    "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB",
     1309                    drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors,
     1310                    (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 /
     1311                     1024));
     1312            if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
     1313                return ((long)
     1314                        (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors /
     1315                         2 / 1024));
     1316            }
     1317        }
     1318        close(fd);
     1319    }
     1320
     1321    assert_string_is_neither_NULL_nor_zerolength(drive);
     1322
     1323    sprintf(command,
     1324            "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",
     1325            drive);
     1326    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1327    if (tmp[0]) {
     1328        p = tmp;
     1329        q = strchr(p, ' ');
     1330        if (q) {
     1331            *(q++) = '\0';
     1332            r = strchr(q, ' ');
     1333            if (r) {
     1334                *(r++) = '\0';
     1335                tempLa = atol(p);
     1336                tempLb = atol(q);
     1337                tempLc = atol(r);
     1338                outL = tempLa * tempLb / 1024 * tempLc / 1024;
     1339                if (outL > 100) {
     1340                    paranoid_free(tmp);
     1341                    paranoid_free(command);
     1342                    return (outL);
     1343                }
     1344            }
     1345        }
     1346    }
     1347
     1348    /* try to grep for 'Drive xxxx: yyy MB' */
     1349    sprintf(command,
     1350            "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3",
     1351            drive);
     1352    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1353    if (atol(tmp) > 0) {
     1354        paranoid_free(tmp);
     1355        paranoid_free(command);
     1356        return (atol(tmp));
     1357    }
     1358
     1359    /* else, do it the old-fashioned way */
     1360    p = strrchr(drive, (int) '/');
     1361    if (p) {
     1362        strcpy(tmp, p + 1);
     1363    } else {
     1364        paranoid_free(tmp);
     1365        paranoid_free(command);
     1366        return (-1);
     1367    }
     1368    sprintf(command, "dmesg | grep %s 2> /dev/null", tmp);
     1369    if (!(fin = popen(command, "r"))) {
     1370        log_OS_error("Cannot popen dmesg command");
     1371    } else {
     1372        fgets(tmp, MAX_STR_LEN - 1, fin);
     1373        while (!feof(fin) && !strstr(tmp, "GB") && !strstr(tmp, "MB")) {
     1374            fgets(tmp, MAX_STR_LEN - 1, fin);
     1375        }
     1376        if (pclose(fin)) {
     1377            log_OS_error("Cannot pclose dmesg fin");
     1378        }
     1379    }
     1380    if (!(p = strstr(tmp, "GB")) && !(p = strstr(tmp, "MB"))) {
     1381        log_msg(3, "Cannot find %s's size: dmesg isn't helping either.",
     1382                drive);
     1383        paranoid_free(tmp);
     1384        paranoid_free(command);
     1385        return (-1);
     1386    }
     1387    for (; !isdigit(*(p - 1)); p--);
     1388    *p = '\0';
     1389    for (p--; isdigit(*(p - 1)); p--);
     1390    outL = atol(p);
     1391    if (outL <= 0) {
     1392        paranoid_free(tmp);
     1393        paranoid_free(command);
     1394        return (-1);
     1395    }
     1396    if (strstr(tmp, "GB")) {
     1397        outL = outL * 1024;
     1398    }
     1399    paranoid_free(tmp);
     1400    paranoid_free(command);
     1401    return (outL * 19 / 20);
     1402#endif
     1403}
     1404#endif                          /* 0 */
    13711405
    13721406
     
    13801414 * @return TRUE if the format is supported, FALSE if not.
    13811415 */
    1382 bool
    1383 is_this_a_valid_disk_format (char *format)
    1384 {
    1385   char *good_formats;
     1416bool is_this_a_valid_disk_format(char *format)
     1417{
     1418    char *good_formats;
    13861419    char *command;
    13871420    char *format_sz;
    13881421
    1389   FILE *pin;
    1390   int retval;
    1391   malloc_string(good_formats);
    1392   malloc_string(command);
    1393   malloc_string(format_sz);
    1394 
    1395   assert_string_is_neither_NULL_nor_zerolength(format);
    1396 
    1397   sprintf (format_sz, "%s ", format);
     1422    FILE *pin;
     1423    int retval;
     1424    malloc_string(good_formats);
     1425    malloc_string(command);
     1426    malloc_string(format_sz);
     1427
     1428    assert_string_is_neither_NULL_nor_zerolength(format);
     1429
     1430    sprintf(format_sz, "%s ", format);
    13981431
    13991432#ifdef __FreeBSD__
    1400   sprintf (command,
    1401            "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
     1433    sprintf(command,
     1434            "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
    14021435#else
    1403   sprintf (command,
    1404        "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
    1405 #endif
    1406 
    1407   pin = popen (command, "r");
    1408   if (!pin)
    1409     {
    1410       log_OS_error ("Unable to read good formats");
    1411       retval=0;
    1412     }
    1413   else
    1414     {
    1415       strcpy (good_formats, " ");
    1416       (void) fgets (good_formats + 1, MAX_STR_LEN, pin);
    1417       if (pclose (pin))
    1418         { log_OS_error("Cannot pclose good formats"); }
    1419       strip_spaces (good_formats);
    1420       strcat (good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
    1421       if (strstr (good_formats, format_sz))
    1422         {
    1423       retval=1;
    1424         }
    1425       else
    1426         {
    1427       retval=0;
    1428         }
    1429     }
    1430   paranoid_free(good_formats);
    1431   paranoid_free(command);
    1432   paranoid_free(format_sz);
    1433   return (retval);
     1436    sprintf(command,
     1437            "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
     1438#endif
     1439
     1440    pin = popen(command, "r");
     1441    if (!pin) {
     1442        log_OS_error("Unable to read good formats");
     1443        retval = 0;
     1444    } else {
     1445        strcpy(good_formats, " ");
     1446        (void) fgets(good_formats + 1, MAX_STR_LEN, pin);
     1447        if (pclose(pin)) {
     1448            log_OS_error("Cannot pclose good formats");
     1449        }
     1450        strip_spaces(good_formats);
     1451        strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
     1452        if (strstr(good_formats, format_sz)) {
     1453            retval = 1;
     1454        } else {
     1455            retval = 0;
     1456        }
     1457    }
     1458    paranoid_free(good_formats);
     1459    paranoid_free(command);
     1460    paranoid_free(format_sz);
     1461    return (retval);
    14341462}
    14351463
     
    14421470 * @return TRUE if it's mounted, FALSE if not.
    14431471 */
    1444 bool is_this_device_mounted (char *device_raw)
    1445 {
    1446 
    1447     /*@ pointers *****************************************************/
    1448   FILE *fin;
    1449 
    1450     /*@ buffers ******************************************************/
    1451   char *incoming;
    1452   char *device_with_tab;
    1453   char *device_with_space;
    1454   char *tmp;
    1455   int retval=0;
    1456  
     1472bool is_this_device_mounted(char *device_raw)
     1473{
     1474
     1475    /*@ pointers **************************************************** */
     1476    FILE *fin;
     1477
     1478    /*@ buffers ***************************************************** */
     1479    char *incoming;
     1480    char *device_with_tab;
     1481    char *device_with_space;
     1482    char *tmp;
     1483    int retval = 0;
     1484
    14571485#ifdef __FreeBSD__
    1458   #define SWAPLIST_COMMAND "swapinfo"
     1486#define SWAPLIST_COMMAND "swapinfo"
    14591487#else
    1460   #define SWAPLIST_COMMAND "cat /proc/swaps"
    1461 #endif
    1462 
    1463     /*@ end vars *****************************************************/
    1464 
    1465   malloc_string(incoming);
    1466   malloc_string(device_with_tab);
    1467   malloc_string(device_with_space);
    1468   malloc_string(tmp);
    1469   assert(device_raw!=NULL);
     1488#define SWAPLIST_COMMAND "cat /proc/swaps"
     1489#endif
     1490
     1491    /*@ end vars **************************************************** */
     1492
     1493    malloc_string(incoming);
     1494    malloc_string(device_with_tab);
     1495    malloc_string(device_with_space);
     1496    malloc_string(tmp);
     1497    assert(device_raw != NULL);
    14701498//  assert_string_is_neither_NULL_nor_zerolength(device_raw);
    1471   if (device_raw[0] != '/' && !strstr(device_raw, ":/"))
    1472     {
    1473       log_msg(1, "%s needs to have a '/' prefixed - I'll do it", device_raw);
    1474       sprintf(tmp, "/%s", device_raw);
    1475     }
    1476   else
    1477     {
    1478       strcpy(tmp, device_raw);
    1479     }
    1480   log_msg(1, "Is %s mounted?", tmp);
    1481   if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc"))
    1482     {
    1483       log_msg(1, "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
    1484       return(0);
    1485     }
    1486   sprintf (device_with_tab, "%s\t", tmp);
    1487   sprintf (device_with_space, "%s ", tmp);
    1488 
    1489   if (!(fin = popen ("mount", "r"))) { log_OS_error("Cannot popen 'mount'"); return(FALSE); }
    1490   for (fgets (incoming, MAX_STR_LEN - 1, fin); !feof (fin);
    1491        fgets (incoming, MAX_STR_LEN - 1, fin))
    1492     {
    1493       if ( strstr (incoming, device_with_space) //> incoming
    1494       || strstr (incoming, device_with_tab) ) // > incoming)
    1495     {
    1496       paranoid_pclose (fin);
    1497       retval=1;
    1498       goto end_of_func;
    1499     }
    1500     }
    1501   paranoid_pclose(fin);
    1502   sprintf (tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null",
    1503        SWAPLIST_COMMAND, device_with_space);
    1504   log_msg(4, "tmp (command) = '%s'", tmp);
    1505   if (!system (tmp))
    1506     {
    1507       retval=1;
    1508       goto end_of_func;
    1509     }
    1510 end_of_func:
    1511   paranoid_free(incoming);
    1512   paranoid_free(device_with_tab);
    1513   paranoid_free(device_with_space);
    1514   paranoid_free(tmp);
    1515   return (retval);
     1499    if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
     1500        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
     1501                device_raw);
     1502        sprintf(tmp, "/%s", device_raw);
     1503    } else {
     1504        strcpy(tmp, device_raw);
     1505    }
     1506    log_msg(1, "Is %s mounted?", tmp);
     1507    if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) {
     1508        log_msg(1,
     1509                "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
     1510        return (0);
     1511    }
     1512    sprintf(device_with_tab, "%s\t", tmp);
     1513    sprintf(device_with_space, "%s ", tmp);
     1514
     1515    if (!(fin = popen("mount", "r"))) {
     1516        log_OS_error("Cannot popen 'mount'");
     1517        return (FALSE);
     1518    }
     1519    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     1520         fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1521        if (strstr(incoming, device_with_space) //> incoming
     1522            || strstr(incoming, device_with_tab))   // > incoming)
     1523        {
     1524            paranoid_pclose(fin);
     1525            retval = 1;
     1526            goto end_of_func;
     1527        }
     1528    }
     1529    paranoid_pclose(fin);
     1530    sprintf(tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null",
     1531            SWAPLIST_COMMAND, device_with_space);
     1532    log_msg(4, "tmp (command) = '%s'", tmp);
     1533    if (!system(tmp)) {
     1534        retval = 1;
     1535        goto end_of_func;
     1536    }
     1537  end_of_func:
     1538    paranoid_free(incoming);
     1539    paranoid_free(device_with_tab);
     1540    paranoid_free(device_with_space);
     1541    paranoid_free(tmp);
     1542    return (retval);
    15161543}
    15171544
     
    15231550 * @return /dev entry for the device, or NULL if it couldn't be allocated.
    15241551 */
    1525 char *
    1526 make_vn (char *fname)
    1527 {
    1528     char *device   = (char*) malloc (MAX_STR_LEN);
    1529     char *mddevice = (char*) malloc (32);
    1530     char command[MAX_STR_LEN];
    1531     int vndev = 2;
    1532     if (atoi (call_program_and_get_last_line_of_output ("/sbin/sysctl -n kern.osreldate")) <
    1533         500000) {
    1534         do {
    1535             sprintf (mddevice, "vn%ic", vndev++);
    1536             sprintf (command, "vnconfig %s %s", mddevice, fname);
    1537             if (vndev > 10) {
    1538                 return NULL;
    1539             }
    1540         }
    1541        while (system (command));
    1542     } else {
    1543         sprintf (command, "mdconfig -a -t vnode -f %s", fname);
    1544         mddevice = call_program_and_get_last_line_of_output (command);
    1545         if (!strstr (mddevice, "md")) {
    1546             return NULL;
    1547         }
    1548     }
    1549     sprintf (device, "/dev/%s", mddevice);
    1550     return device;
     1552char *make_vn(char *fname)
     1553{
     1554    char *device = (char *) malloc(MAX_STR_LEN);
     1555    char *mddevice = (char *) malloc(32);
     1556    char command[MAX_STR_LEN];
     1557    int vndev = 2;
     1558    if (atoi
     1559        (call_program_and_get_last_line_of_output
     1560         ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1561        do {
     1562            sprintf(mddevice, "vn%ic", vndev++);
     1563            sprintf(command, "vnconfig %s %s", mddevice, fname);
     1564            if (vndev > 10) {
     1565                return NULL;
     1566            }
     1567        }
     1568        while (system(command));
     1569    } else {
     1570        sprintf(command, "mdconfig -a -t vnode -f %s", fname);
     1571        mddevice = call_program_and_get_last_line_of_output(command);
     1572        if (!strstr(mddevice, "md")) {
     1573            return NULL;
     1574        }
     1575    }
     1576    sprintf(device, "/dev/%s", mddevice);
     1577    return device;
    15511578}
    15521579
     
    15611588 * @return 0 for success, nonzero for failure.
    15621589 */
    1563 int
    1564 kick_vn (char *dname)
    1565 {
    1566     char command[MAX_STR_LEN];
    1567 
    1568     if (strncmp (dname, "/dev/", 5) == 0) {
    1569         dname += 5;
    1570     }
    1571 
    1572     if (atoi (call_program_and_get_last_line_of_output ("/sbin/sysctl -n kern.osreldate")) <
    1573         500000) {
    1574         sprintf (command, "vnconfig -d %s", dname);
    1575         return system (command);
    1576     } else {
    1577         sprintf (command, "mdconfig -d -u %s", dname);
    1578         return system (command);
    1579     }
    1580     /*NOTREACHED*/
    1581     return 255;
     1590int kick_vn(char *dname)
     1591{
     1592    char command[MAX_STR_LEN];
     1593
     1594    if (strncmp(dname, "/dev/", 5) == 0) {
     1595        dname += 5;
     1596    }
     1597
     1598    if (atoi
     1599        (call_program_and_get_last_line_of_output
     1600         ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1601        sprintf(command, "vnconfig -d %s", dname);
     1602        return system(command);
     1603    } else {
     1604        sprintf(command, "mdconfig -d -u %s", dname);
     1605        return system(command);
     1606    }
     1607     /*NOTREACHED*/ return 255;
    15821608}
    15831609#endif
     
    15901616 * @return 0 for success, nonzero for failure.
    15911617 */
    1592 int
    1593 mount_CDROM_here (char *device, char *mountpoint)
    1594 {
    1595     /*@ buffer *******************************************************/
    1596   char *command;
    1597   char *dev;
    1598   char *options;
    1599   int retval;
    1600 
    1601   malloc_string(command);
    1602   malloc_string(dev);
    1603   malloc_string(options);
    1604   assert_string_is_neither_NULL_nor_zerolength(device);
    1605   assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    1606 
    1607   make_hole_for_dir(mountpoint);
    1608   strcpy(options, "ro");
    1609   if (isdigit(device[0]))
    1610     { find_cdrom_device(device, FALSE); }
    1611   else
    1612     { strcpy(dev, device); }
    1613   if (g_ISO_restore_mode)
    1614     {
     1618int mount_CDROM_here(char *device, char *mountpoint)
     1619{
     1620    /*@ buffer ****************************************************** */
     1621    char *command;
     1622    char *dev;
     1623    char *options;
     1624    int retval;
     1625
     1626    malloc_string(command);
     1627    malloc_string(dev);
     1628    malloc_string(options);
     1629    assert_string_is_neither_NULL_nor_zerolength(device);
     1630    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     1631
     1632    make_hole_for_dir(mountpoint);
     1633    strcpy(options, "ro");
     1634    if (isdigit(device[0])) {
     1635        find_cdrom_device(device, FALSE);
     1636    } else {
     1637        strcpy(dev, device);
     1638    }
     1639    if (g_ISO_restore_mode) {
    16151640
    16161641#ifdef __FreeBSD__
    1617       strcpy (dev, make_vn (device));
    1618       if (!dev) {
    1619           sprintf (command, "Unable to mount ISO (make_vn(%s) failed)", device);
    1620           fatal_error (command);
    1621         }
    1622       strcpy (device, dev);
     1642        strcpy(dev, make_vn(device));
     1643        if (!dev) {
     1644            sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",
     1645                    device);
     1646            fatal_error(command);
     1647        }
     1648        strcpy(device, dev);
    16231649#else
    1624       strcat(options,",loop");
    1625 #endif
    1626 
    1627     }
    1628   log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
    1629     /*@ end vars ****************************************************/
     1650        strcat(options, ",loop");
     1651#endif
     1652
     1653    }
     1654    log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
     1655            mountpoint);
     1656    /*@ end vars *************************************************** */
    16301657
    16311658#ifdef __FreeBSD__
    1632   sprintf (command, "mount_cd9660 -r %s %s 2>> %s",
    1633            device, mountpoint, MONDO_LOGFILE);
     1659    sprintf(command, "mount_cd9660 -r %s %s 2>> %s",
     1660            device, mountpoint, MONDO_LOGFILE);
    16341661
    16351662#else
    1636   sprintf (command, "mount %s -o %s -t iso9660 %s 2>> %s",
    1637            device, options, mountpoint, MONDO_LOGFILE);
    1638 #endif
    1639 
    1640   log_msg (4, command);
    1641   if (strncmp(device, "/dev/", 5) == 0)
    1642     {
    1643       retract_CD_tray_and_defeat_autorun();
    1644     }
    1645   retval = system (command);
    1646   log_msg(1, "system(%s) returned %d", command, retval);
    1647 
    1648   paranoid_free(command);
    1649   paranoid_free(dev);
    1650   paranoid_free(options);
    1651   return(retval);
     1663    sprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s",
     1664            device, options, mountpoint, MONDO_LOGFILE);
     1665#endif
     1666
     1667    log_msg(4, command);
     1668    if (strncmp(device, "/dev/", 5) == 0) {
     1669        retract_CD_tray_and_defeat_autorun();
     1670    }
     1671    retval = system(command);
     1672    log_msg(1, "system(%s) returned %d", command, retval);
     1673
     1674    paranoid_free(command);
     1675    paranoid_free(dev);
     1676    paranoid_free(options);
     1677    return (retval);
    16521678}
    16531679
     
    16691695 */
    16701696void
    1671 insist_on_this_cd_number (struct s_bkpinfo* bkpinfo, int cd_number_i_want)
    1672 {
    1673 
    1674     /*@ int **************************************************************/
    1675   int res = 0;
    1676 
    1677 
    1678     /*@ buffers **********************************************************/
    1679   char *tmp;
    1680   char *request;
    1681 
    1682   assert(bkpinfo!=NULL);
    1683   assert(cd_number_i_want > 0);
     1697insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, int cd_number_i_want)
     1698{
     1699
     1700    /*@ int ************************************************************* */
     1701    int res = 0;
     1702
     1703
     1704    /*@ buffers ********************************************************* */
     1705    char *tmp;
     1706    char *request;
     1707
     1708    assert(bkpinfo != NULL);
     1709    assert(cd_number_i_want > 0);
    16841710
    16851711//  log_msg(3, "Insisting on CD number %d", cd_number_i_want);
    16861712
    1687   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1688     {
    1689       log_msg(3, "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
    1690       return;
    1691     }
    1692   malloc_string(tmp);
    1693   malloc_string(request);
    1694   sprintf(tmp, "mkdir -p "MNT_CDROM);
    1695   run_program_and_log_output(tmp, 5);
    1696   if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs)
    1697     {
    1698       log_msg(3, "Remounting CD");
    1699       g_ISO_restore_mode = TRUE;
     1713    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1714        log_msg(3,
     1715                "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
     1716        return;
     1717    }
     1718    malloc_string(tmp);
     1719    malloc_string(request);
     1720    sprintf(tmp, "mkdir -p " MNT_CDROM);
     1721    run_program_and_log_output(tmp, 5);
     1722    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
     1723        || bkpinfo->backup_media_type == nfs) {
     1724        log_msg(3, "Remounting CD");
     1725        g_ISO_restore_mode = TRUE;
    17001726// FIXME --- I'm tempted to do something about this...
    17011727// Why unmount and remount again and again?
    1702       if (is_this_device_mounted(MNT_CDROM)) { run_program_and_log_output("umount "MNT_CDROM, 5); }
    1703       system("mkdir -p /tmp/isodir &> /dev/null");
    1704       sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
    1705       if (!does_file_exist(tmp))
    1706         {
    1707       sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso", bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
    1708       if (does_file_exist(tmp))
    1709         {
    1710           log_msg(1, "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir", bkpinfo->isodir);
    1711           strcpy(bkpinfo->isodir, "/tmp/isodir");
    1712         }
    1713         }
    1714       log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
    1715       if (mount_CDROM_here(tmp, MNT_CDROM)) { fatal_error("Mommy!"); }
    1716 //    g_current_media_number = cd_number_i_want;
    1717 //    return;
    1718     }
    1719   if ((res=what_number_cd_is_this (bkpinfo)) != cd_number_i_want)
    1720     {
    1721       log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
    1722       sprintf (tmp, "Insisting on %s #%d", media_descriptor_string(bkpinfo->backup_media_type), cd_number_i_want);
    1723       sprintf (request, "Please insert %s #%d and press Enter.",
    1724                media_descriptor_string(bkpinfo->backup_media_type),
    1725            cd_number_i_want);
    1726       log_msg (3, tmp);
    1727       while (what_number_cd_is_this (bkpinfo) != cd_number_i_want)
    1728     {
    1729       paranoid_system ("sync");
    1730       if (is_this_device_mounted (MNT_CDROM))
    1731         {
    1732           res = run_program_and_log_output ("umount "MNT_CDROM, FALSE);
    1733         }
    1734       else
    1735         {
    1736           res = 0;
    1737         }
    1738       if (res)
    1739         {
    1740           log_to_screen ("WARNING - failed to unmount CD-ROM drive");
    1741         }
    1742           if (!bkpinfo->please_dont_eject)
    1743             { res = eject_device(bkpinfo->media_device); }
    1744           else
    1745             { res = 0; }
    1746       if (res)
    1747         {
    1748               log_to_screen ("WARNING - failed to eject CD-ROM disk");
    1749         }
    1750           popup_and_OK (request);
    1751           if (!bkpinfo->please_dont_eject)
    1752             {
    1753               inject_device(bkpinfo->media_device);
    1754             }
    1755       paranoid_system ("sync");
    1756     }
    1757       log_msg (1, "Thankyou. Proceeding...");
    1758       g_current_media_number = cd_number_i_want;
    1759     }
    1760   paranoid_free(tmp);
    1761   paranoid_free(request);
     1728        if (is_this_device_mounted(MNT_CDROM)) {
     1729            run_program_and_log_output("umount " MNT_CDROM, 5);
     1730        }
     1731        system("mkdir -p /tmp/isodir &> /dev/null");
     1732        sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,
     1733                bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     1734                cd_number_i_want);
     1735        if (!does_file_exist(tmp)) {
     1736            sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso",
     1737                    bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     1738                    cd_number_i_want);
     1739            if (does_file_exist(tmp)) {
     1740                log_msg(1,
     1741                        "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir",
     1742                        bkpinfo->isodir);
     1743                strcpy(bkpinfo->isodir, "/tmp/isodir");
     1744            }
     1745        }
     1746        log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
     1747        if (mount_CDROM_here(tmp, MNT_CDROM)) {
     1748            fatal_error("Mommy!");
     1749        }
     1750//    g_current_media_number = cd_number_i_want;
     1751//    return;
     1752    }
     1753    if ((res = what_number_cd_is_this(bkpinfo)) != cd_number_i_want) {
     1754        log_msg(3, "Currently, we hold %d but we want %d", res,
     1755                cd_number_i_want);
     1756        sprintf(tmp, "Insisting on %s #%d",
     1757                media_descriptor_string(bkpinfo->backup_media_type),
     1758                cd_number_i_want);
     1759        sprintf(request, "Please insert %s #%d and press Enter.",
     1760                media_descriptor_string(bkpinfo->backup_media_type),
     1761                cd_number_i_want);
     1762        log_msg(3, tmp);
     1763        while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) {
     1764            paranoid_system("sync");
     1765            if (is_this_device_mounted(MNT_CDROM)) {
     1766                res =
     1767                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1768            } else {
     1769                res = 0;
     1770            }
     1771            if (res) {
     1772                log_to_screen("WARNING - failed to unmount CD-ROM drive");
     1773            }
     1774            if (!bkpinfo->please_dont_eject) {
     1775                res = eject_device(bkpinfo->media_device);
     1776            } else {
     1777                res = 0;
     1778            }
     1779            if (res) {
     1780                log_to_screen("WARNING - failed to eject CD-ROM disk");
     1781            }
     1782            popup_and_OK(request);
     1783            if (!bkpinfo->please_dont_eject) {
     1784                inject_device(bkpinfo->media_device);
     1785            }
     1786            paranoid_system("sync");
     1787        }
     1788        log_msg(1, "Thankyou. Proceeding...");
     1789        g_current_media_number = cd_number_i_want;
     1790    }
     1791    paranoid_free(tmp);
     1792    paranoid_free(request);
    17621793}
    17631794
     
    17781809 * @ingroup archiveGroup
    17791810 */
    1780 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *bkpinfo, bool archiving_to_media)
     1811int interactively_obtain_media_parameters_from_user(struct s_bkpinfo
     1812                                                    *bkpinfo,
     1813                                                    bool
     1814                                                    archiving_to_media)
    17811815// archiving_to_media is TRUE if I'm being called by mondoarchive
    17821816// archiving_to_media is FALSE if I'm being called by mondorestore
    17831817{
    1784   char *tmp;
    1785   char *sz_size;
    1786   char *command;
    1787   char *comment;
    1788   int i;
    1789   FILE*fin;
    1790 
    1791   malloc_string(tmp);
    1792   malloc_string(sz_size);
    1793   malloc_string(command);
    1794   malloc_string(comment);
    1795   assert(bkpinfo!=NULL);
    1796   sz_size[0] = '\0';
    1797   bkpinfo->nonbootable_backup = FALSE;
     1818    char *tmp;
     1819    char *sz_size;
     1820    char *command;
     1821    char *comment;
     1822    int i;
     1823    FILE *fin;
     1824
     1825    malloc_string(tmp);
     1826    malloc_string(sz_size);
     1827    malloc_string(command);
     1828    malloc_string(comment);
     1829    assert(bkpinfo != NULL);
     1830    sz_size[0] = '\0';
     1831    bkpinfo->nonbootable_backup = FALSE;
    17981832
    17991833// Tape, CD, NFS, ...?
    1800   srandom(getpid());
    1801   bkpinfo->backup_media_type = (g_restoring_live_from_cd) ? cdr : which_backup_media_type(bkpinfo->restore_data);
    1802   if (bkpinfo->backup_media_type == none)
    1803     { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1804   if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data)
    1805     { popup_and_OK("Please remove CD/floppy from drive(s)"); }
    1806   log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    1807   if (archiving_to_media)
    1808     {
    1809       sensibly_set_tmpdir_and_scratchdir(bkpinfo);
    1810     }
    1811   bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
    1812   bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1:5;
    1813   bkpinfo->use_lzo =  (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
     1834    srandom(getpid());
     1835    bkpinfo->backup_media_type =
     1836        (g_restoring_live_from_cd) ? cdr :
     1837        which_backup_media_type(bkpinfo->restore_data);
     1838    if (bkpinfo->backup_media_type == none) {
     1839        log_to_screen("User has chosen not to backup the PC");
     1840        finish(1);
     1841    }
     1842    if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {
     1843        popup_and_OK("Please remove CD/floppy from drive(s)");
     1844    }
     1845    log_msg(3, "media type = %s",
     1846            bkptype_to_string(bkpinfo->backup_media_type));
     1847    if (archiving_to_media) {
     1848        sensibly_set_tmpdir_and_scratchdir(bkpinfo);
     1849    }
     1850    bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
     1851    bkpinfo->compression_level =
     1852        (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
     1853    bkpinfo->use_lzo =
     1854        (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
    18141855
    18151856/*
     
    18261867*/
    18271868
    1828   mvaddstr_and_log_it(2, 0, " ");
     1869    mvaddstr_and_log_it(2, 0, " ");
    18291870
    18301871// Find device's /dev (or SCSI) entry
    1831   switch(bkpinfo->backup_media_type)
    1832     {
    1833       case cdr:
    1834       case cdrw:
    1835       case dvd:
    1836     if (archiving_to_media)
    1837           {
    1838             if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?"))
    1839               { bkpinfo->manual_cd_tray = TRUE; }
    1840             if ((bkpinfo->compression_level = which_compression_level()) == -1)
    1841               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1842         sprintf(comment, "What speed is your %s (re)writer?", media_descriptor_string(bkpinfo->backup_media_type));
    1843         if (bkpinfo->backup_media_type==dvd)
    1844           {
    1845         find_dvd_device(bkpinfo->media_device, FALSE);
    1846             strcpy(tmp, "1");
    1847         sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    1848         log_msg(1, "Setting to DVD defaults");
    1849           }
    1850         else
    1851           {
    1852                 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    1853             strcpy(tmp, "4");
    1854         strcpy(sz_size, "650");
    1855         log_msg(1, "Setting to CD defaults");
    1856           }
    1857         if (bkpinfo->backup_media_type != dvd)
    1858           {
    1859             if (!popup_and_get_string("Speed", comment, tmp, 4))
    1860               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1861           }
    1862             bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :)
    1863         sprintf(comment, "How much data (in Megabytes) will each %s store?", media_descriptor_string(bkpinfo->backup_media_type));
    1864         if (!popup_and_get_string("Size", comment, sz_size, 5))
    1865           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1866         for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = atoi(sz_size); }
    1867         if (bkpinfo->media_size[0] <=0)
    1868               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1869           }
    1870       case cdstream:
    1871     if (bkpinfo->disaster_recovery)
    1872       {
    1873             strcpy(bkpinfo->media_device, "/dev/cdrom");
    1874         log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
    1875       }
    1876     else if (bkpinfo->restore_data
    1877         || bkpinfo->backup_media_type == dvd)
    1878       {
    1879             if (!bkpinfo->media_device[0])
    1880               { strcpy(bkpinfo->media_device, "/dev/cdrom"); } // just for the heck of it :)
    1881         log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
    1882         if (bkpinfo->backup_media_type == dvd || find_cdrom_device (bkpinfo->media_device, FALSE))
    1883           {
    1884         log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
    1885             sprintf(comment, "Please specify your %s drive's /dev entry", media_descriptor_string(bkpinfo->backup_media_type));
    1886             if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN/4))
    1887               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1888           }
    1889         log_msg(2, "%s device found at %s", media_descriptor_string(bkpinfo->backup_media_type), bkpinfo->media_device);
    1890       }
    1891     else
    1892       {
    1893         if (find_cdrw_device(bkpinfo->media_device)) { bkpinfo->media_device[0]='\0'; }
    1894         if (bkpinfo->media_device[0])
    1895           {
    1896             sprintf(tmp, "I think I've found your %s burner at SCSI node %s; am I right on the money?", media_descriptor_string(bkpinfo->backup_media_type), bkpinfo->media_device);
    1897             if (!ask_me_yes_or_no(tmp)) { bkpinfo->media_device[0]='\0'; }
    1898           }
    1899            if (!bkpinfo->media_device[0])
    1900           {
    1901         if (g_kernel_version < 2.6)
    1902           {
    1903             i=popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device, MAX_STR_LEN/4);
    1904           }
    1905         else
    1906           {
    1907             i=popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device, MAX_STR_LEN/4);
    1908           }
    1909         if (!i)
    1910               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1911           }
    1912       }
    1913     if (bkpinfo->backup_media_type == cdstream)
    1914       {
    1915         for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650; }
    1916       }
    1917     break;
    1918       case udev:
    1919     if (!ask_me_yes_or_no("This option is for advanced users only. Are you sure?"))
    1920       { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1921       case tape:
    1922 
    1923     if (find_tape_device_and_size(bkpinfo->media_device, sz_size))
    1924       {
    1925         log_msg(3, "Ok, using vanilla scsi tape.");
    1926         strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
    1927         if ((fin=fopen(bkpinfo->media_device, "r")))
    1928           { paranoid_fclose(fin); }
    1929         else
    1930           { strcpy(bkpinfo->media_device, "/dev/osst0"); }
    1931       }
    1932     if (bkpinfo->media_device[0])
    1933       {
    1934         if ((fin=fopen(bkpinfo->media_device, "r")))
    1935           { paranoid_fclose(fin); }
    1936         else
    1937           {
    1938         if (does_file_exist("/tmp/mondo-restore.cfg"))
    1939           {
    1940             read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device);
    1941           }
    1942           }
    1943         sprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
    1944       }
    1945     if (bkpinfo->media_device[0])
    1946       {
    1947         sprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
    1948         if (!ask_me_yes_or_no(tmp)) { bkpinfo->media_device[0]='\0'; }
    1949       }
    1950         if (!bkpinfo->media_device[0])
    1951       {
    1952         if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device, MAX_STR_LEN/4))
    1953           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1954       }
    1955     sprintf(tmp, "ls -l %s", bkpinfo->media_device);
    1956     if (run_program_and_log_output(tmp, FALSE))
    1957           { log_to_screen("User has not specified a valid /dev entry"); finish(1); }
    1958     log_msg(4, "sz_size = %s", sz_size);
    1959         sz_size[0] = '\0';
     1872    switch (bkpinfo->backup_media_type) {
     1873    case cdr:
     1874    case cdrw:
     1875    case dvd:
     1876        if (archiving_to_media) {
     1877            if (ask_me_yes_or_no
     1878                ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?"))
     1879            {
     1880                bkpinfo->manual_cd_tray = TRUE;
     1881            }
     1882            if ((bkpinfo->compression_level =
     1883                 which_compression_level()) == -1) {
     1884                log_to_screen("User has chosen not to backup the PC");
     1885                finish(1);
     1886            }
     1887            sprintf(comment, "What speed is your %s (re)writer?",
     1888                    media_descriptor_string(bkpinfo->backup_media_type));
     1889            if (bkpinfo->backup_media_type == dvd) {
     1890                find_dvd_device(bkpinfo->media_device, FALSE);
     1891                strcpy(tmp, "1");
     1892                sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4582 MB
     1893                log_msg(1, "Setting to DVD defaults");
     1894            } else {
     1895                strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
     1896                strcpy(tmp, "4");
     1897                strcpy(sz_size, "650");
     1898                log_msg(1, "Setting to CD defaults");
     1899            }
     1900            if (bkpinfo->backup_media_type != dvd) {
     1901                if (!popup_and_get_string("Speed", comment, tmp, 4)) {
     1902                    log_to_screen("User has chosen not to backup the PC");
     1903                    finish(1);
     1904                }
     1905            }
     1906            bkpinfo->cdrw_speed = atoi(tmp);    // if DVD then this shouldn't ever be used anyway :)
     1907            sprintf(comment,
     1908                    "How much data (in Megabytes) will each %s store?",
     1909                    media_descriptor_string(bkpinfo->backup_media_type));
     1910            if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     1911                log_to_screen("User has chosen not to backup the PC");
     1912                finish(1);
     1913            }
     1914            for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     1915                bkpinfo->media_size[i] = atoi(sz_size);
     1916            }
     1917            if (bkpinfo->media_size[0] <= 0) {
     1918                log_to_screen("User has chosen not to backup the PC");
     1919                finish(1);
     1920            }
     1921        }
     1922    case cdstream:
     1923        if (bkpinfo->disaster_recovery) {
     1924            strcpy(bkpinfo->media_device, "/dev/cdrom");
     1925            log_msg(2, "CD-ROM device assumed to be at %s",
     1926                    bkpinfo->media_device);
     1927        } else if (bkpinfo->restore_data
     1928                   || bkpinfo->backup_media_type == dvd) {
     1929            if (!bkpinfo->media_device[0]) {
     1930                strcpy(bkpinfo->media_device, "/dev/cdrom");
     1931            }                   // just for the heck of it :)
     1932            log_msg(1, "bkpinfo->media_device = %s",
     1933                    bkpinfo->media_device);
     1934            if (bkpinfo->backup_media_type == dvd
     1935                || find_cdrom_device(bkpinfo->media_device, FALSE)) {
     1936                log_msg(1, "bkpinfo->media_device = %s",
     1937                        bkpinfo->media_device);
     1938                sprintf(comment,
     1939                        "Please specify your %s drive's /dev entry",
     1940                        media_descriptor_string(bkpinfo->
     1941                                                backup_media_type));
     1942                if (!popup_and_get_string
     1943                    ("Device?", comment, bkpinfo->media_device,
     1944                     MAX_STR_LEN / 4)) {
     1945                    log_to_screen("User has chosen not to backup the PC");
     1946                    finish(1);
     1947                }
     1948            }
     1949            log_msg(2, "%s device found at %s",
     1950                    media_descriptor_string(bkpinfo->backup_media_type),
     1951                    bkpinfo->media_device);
     1952        } else {
     1953            if (find_cdrw_device(bkpinfo->media_device)) {
     1954                bkpinfo->media_device[0] = '\0';
     1955            }
     1956            if (bkpinfo->media_device[0]) {
     1957                sprintf(tmp,
     1958                        "I think I've found your %s burner at SCSI node %s; am I right on the money?",
     1959                        media_descriptor_string(bkpinfo->
     1960                                                backup_media_type),
     1961                        bkpinfo->media_device);
     1962                if (!ask_me_yes_or_no(tmp)) {
     1963                    bkpinfo->media_device[0] = '\0';
     1964                }
     1965            }
     1966            if (!bkpinfo->media_device[0]) {
     1967                if (g_kernel_version < 2.6) {
     1968                    i = popup_and_get_string("Device node?",
     1969                                             "What is the SCSI node of your CD (re)writer, please?",
     1970                                             bkpinfo->media_device,
     1971                                             MAX_STR_LEN / 4);
     1972                } else {
     1973                    i = popup_and_get_string("/dev entry?",
     1974                                             "What is the /dev entry of your CD (re)writer, please?",
     1975                                             bkpinfo->media_device,
     1976                                             MAX_STR_LEN / 4);
     1977                }
     1978                if (!i) {
     1979                    log_to_screen("User has chosen not to backup the PC");
     1980                    finish(1);
     1981                }
     1982            }
     1983        }
     1984        if (bkpinfo->backup_media_type == cdstream) {
     1985            for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     1986                bkpinfo->media_size[i] = 650;
     1987            }
     1988        }
     1989        break;
     1990    case udev:
     1991        if (!ask_me_yes_or_no
     1992            ("This option is for advanced users only. Are you sure?")) {
     1993            log_to_screen("User has chosen not to backup the PC");
     1994            finish(1);
     1995        }
     1996    case tape:
     1997
     1998        if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) {
     1999            log_msg(3, "Ok, using vanilla scsi tape.");
     2000            strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
     2001            if ((fin = fopen(bkpinfo->media_device, "r"))) {
     2002                paranoid_fclose(fin);
     2003            } else {
     2004                strcpy(bkpinfo->media_device, "/dev/osst0");
     2005            }
     2006        }
     2007        if (bkpinfo->media_device[0]) {
     2008            if ((fin = fopen(bkpinfo->media_device, "r"))) {
     2009                paranoid_fclose(fin);
     2010            } else {
     2011                if (does_file_exist("/tmp/mondo-restore.cfg")) {
     2012                    read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
     2013                                 bkpinfo->media_device);
     2014                }
     2015            }
     2016            sprintf(tmp,
     2017                    "I think I've found your tape streamer at %s; am I right on the money?",
     2018                    bkpinfo->media_device);
     2019        }
     2020        if (bkpinfo->media_device[0]) {
     2021            sprintf(tmp,
     2022                    "I think I've found your tape streamer at %s; am I right on the money?",
     2023                    bkpinfo->media_device);
     2024            if (!ask_me_yes_or_no(tmp)) {
     2025                bkpinfo->media_device[0] = '\0';
     2026            }
     2027        }
     2028        if (!bkpinfo->media_device[0]) {
     2029            if (!popup_and_get_string
     2030                ("Device name?",
     2031                 "What is the /dev entry of your tape streamer?",
     2032                 bkpinfo->media_device, MAX_STR_LEN / 4)) {
     2033                log_to_screen("User has chosen not to backup the PC");
     2034                finish(1);
     2035            }
     2036        }
     2037        sprintf(tmp, "ls -l %s", bkpinfo->media_device);
     2038        if (run_program_and_log_output(tmp, FALSE)) {
     2039            log_to_screen("User has not specified a valid /dev entry");
     2040            finish(1);
     2041        }
     2042        log_msg(4, "sz_size = %s", sz_size);
     2043        sz_size[0] = '\0';
    19602044/*
    19612045    if ((size_sz[0]=='\0' || atol(size_sz)==0) && archiving_to_media)
     
    19652049      }
    19662050*/
    1967     if (sz_size[0]=='\0')
    1968       { bkpinfo->media_size[0] = 0; }
    1969         else
    1970       { bkpinfo->media_size[0] = friendly_sizestr_to_sizelong (sz_size)/2 - 50; }
    1971     log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
    1972         if (bkpinfo->media_size[0] <= 0) { bkpinfo->media_size[0] = 0; }
    1973     for(i=1; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = bkpinfo->media_size[0]; }
    1974         if (archiving_to_media)
    1975           {
    1976             if ((bkpinfo->compression_level = which_compression_level()) == -1)
    1977               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1978           }
    1979         break;
    1980 
    1981 
    1982 
    1983       case nfs:
    1984     if (!bkpinfo->nfs_mount[0]) { strcpy(bkpinfo->nfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1")); }
     2051        if (sz_size[0] == '\0') {
     2052            bkpinfo->media_size[0] = 0;
     2053        } else {
     2054            bkpinfo->media_size[0] =
     2055                friendly_sizestr_to_sizelong(sz_size) / 2 - 50;
     2056        }
     2057        log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
     2058        if (bkpinfo->media_size[0] <= 0) {
     2059            bkpinfo->media_size[0] = 0;
     2060        }
     2061        for (i = 1; i <= MAX_NOOF_MEDIA; i++) {
     2062            bkpinfo->media_size[i] = bkpinfo->media_size[0];
     2063        }
     2064        if (archiving_to_media) {
     2065            if ((bkpinfo->compression_level =
     2066                 which_compression_level()) == -1) {
     2067                log_to_screen("User has chosen not to backup the PC");
     2068                finish(1);
     2069            }
     2070        }
     2071        break;
     2072
     2073
     2074
     2075    case nfs:
     2076        if (!bkpinfo->nfs_mount[0]) {
     2077            strcpy(bkpinfo->nfs_mount,
     2078                   call_program_and_get_last_line_of_output
     2079                   ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     2080        }
    19852081#ifdef __FreeBSD__
    1986         if (TRUE)
     2082        if (TRUE)
    19872083#else
    1988     if (!bkpinfo->disaster_recovery )
    1989 #endif
    1990       {
    1991         if (!popup_and_get_string("NFS dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->nfs_mount, MAX_STR_LEN/4))
    1992           {
    1993         log_to_screen("User has chosen not to backup the PC");
    1994         finish(1);
    1995           }
    1996             if (!bkpinfo->restore_data)
    1997               {
    1998                 if ((bkpinfo->compression_level = which_compression_level()) == -1)
    1999                   {
    2000                     log_to_screen("User has chosen not to backup the PC");
    2001                     finish(1);
    2002                   }
    2003               }
    2004             sprintf(command, "mount | grep %s | cut -d' ' -f3", bkpinfo->nfs_mount);
    2005             strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command));
    2006       }
    2007     if (bkpinfo->disaster_recovery)
    2008           {
    2009         system("umount /tmp/isodir 2> /dev/null");
    2010         if (!popup_and_get_string("NFS share", "Which remote NFS share should I mount?", bkpinfo->nfs_mount, MAX_STR_LEN))
    2011           {
    2012                 log_to_screen("User has chosen not to backup the PC");
    2013                 finish(1);
    2014           }
    2015           }
    2016         if (!is_this_device_mounted(bkpinfo->nfs_mount))
    2017           {
    2018             sprintf(bkpinfo->isodir, "/tmp/isodir");
    2019         run_program_and_log_output("mkdir -p /tmp/isodir", 5);
    2020         sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount);
    2021         run_program_and_log_output(tmp, 5);
    2022           }
    2023     if (!is_this_device_mounted(bkpinfo->nfs_mount))
    2024       {
    2025         popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
    2026         finish(1);
    2027       }
    2028         strcpy(tmp, bkpinfo->nfs_remote_dir);
    2029         if (!popup_and_get_string("Directory", "Which directory within that mountpoint?", tmp, MAX_STR_LEN))
    2030           {
    2031             log_to_screen("User has chosen not to backup the PC");
    2032              finish(1);
    2033           }
    2034         strcpy(bkpinfo->nfs_remote_dir, tmp);
    2035     for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650; }
    2036         log_msg(3, "Just set nfs_remote_dir to %s", bkpinfo->nfs_remote_dir);
    2037     log_msg(3, "isodir is still %s", bkpinfo->isodir);
    2038     break;
    2039 
    2040       case iso:
    2041         if (!bkpinfo->disaster_recovery)
    2042           {
    2043              if (!popup_and_get_string("Storage dir.", "Please enter the full path that contains your ISO images.  Example: /mnt/raid0_0", bkpinfo->isodir, MAX_STR_LEN/4))
    2044           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2045              if (archiving_to_media) {
    2046                  if ((bkpinfo->compression_level = which_compression_level()) == -1)
    2047                      { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2048                  if (!popup_and_get_string ("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s you plan to backup to.", sz_size, 16))
    2049                      { log_to_screen ("User has chosen not to backup the PC"); finish(1); }
    2050                  for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = atoi (sz_size); }
    2051              if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix, MAX_STR_LEN/4))
    2052           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2053              } else {
    2054                  for (i=0;i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650;}
    2055              }
    2056           }
    2057     break;
    2058       default:
    2059     fatal_error("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
    2060     }
    2061 
    2062   if (archiving_to_media)
    2063     {
     2084        if (!bkpinfo->disaster_recovery)
     2085#endif
     2086        {
     2087            if (!popup_and_get_string
     2088                ("NFS dir.",
     2089                 "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)",
     2090                 bkpinfo->nfs_mount, MAX_STR_LEN / 4)) {
     2091                log_to_screen("User has chosen not to backup the PC");
     2092                finish(1);
     2093            }
     2094            if (!bkpinfo->restore_data) {
     2095                if ((bkpinfo->compression_level =
     2096                     which_compression_level()) == -1) {
     2097                    log_to_screen("User has chosen not to backup the PC");
     2098                    finish(1);
     2099                }
     2100            }
     2101            sprintf(command, "mount | grep %s | cut -d' ' -f3",
     2102                    bkpinfo->nfs_mount);
     2103            strcpy(bkpinfo->isodir,
     2104                   call_program_and_get_last_line_of_output(command));
     2105        }
     2106        if (bkpinfo->disaster_recovery) {
     2107            system("umount /tmp/isodir 2> /dev/null");
     2108            if (!popup_and_get_string
     2109                ("NFS share", "Which remote NFS share should I mount?",
     2110                 bkpinfo->nfs_mount, MAX_STR_LEN)) {
     2111                log_to_screen("User has chosen not to backup the PC");
     2112                finish(1);
     2113            }
     2114        }
     2115        if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
     2116            sprintf(bkpinfo->isodir, "/tmp/isodir");
     2117            run_program_and_log_output("mkdir -p /tmp/isodir", 5);
     2118            sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
     2119                    bkpinfo->nfs_mount);
     2120            run_program_and_log_output(tmp, 5);
     2121        }
     2122        if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
     2123            popup_and_OK
     2124                ("Please mount that partition before you try to backup to or restore from it.");
     2125            finish(1);
     2126        }
     2127        strcpy(tmp, bkpinfo->nfs_remote_dir);
     2128        if (!popup_and_get_string
     2129            ("Directory", "Which directory within that mountpoint?", tmp,
     2130             MAX_STR_LEN)) {
     2131            log_to_screen("User has chosen not to backup the PC");
     2132            finish(1);
     2133        }
     2134        strcpy(bkpinfo->nfs_remote_dir, tmp);
     2135        for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     2136            bkpinfo->media_size[i] = 650;
     2137        }
     2138        log_msg(3, "Just set nfs_remote_dir to %s",
     2139                bkpinfo->nfs_remote_dir);
     2140        log_msg(3, "isodir is still %s", bkpinfo->isodir);
     2141        break;
     2142
     2143    case iso:
     2144        if (!bkpinfo->disaster_recovery) {
     2145            if (!popup_and_get_string
     2146                ("Storage dir.",
     2147                 "Please enter the full path that contains your ISO images.  Example: /mnt/raid0_0",
     2148                 bkpinfo->isodir, MAX_STR_LEN / 4)) {
     2149                log_to_screen("User has chosen not to backup the PC");
     2150                finish(1);
     2151            }
     2152            if (archiving_to_media) {
     2153                if ((bkpinfo->compression_level =
     2154                     which_compression_level()) == -1) {
     2155                    log_to_screen("User has chosen not to backup the PC");
     2156                    finish(1);
     2157                }
     2158                if (!popup_and_get_string
     2159                    ("ISO size.",
     2160                     "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s you plan to backup to.",
     2161                     sz_size, 16)) {
     2162                    log_to_screen("User has chosen not to backup the PC");
     2163                    finish(1);
     2164                }
     2165                for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     2166                    bkpinfo->media_size[i] = atoi(sz_size);
     2167                }
     2168                if (!popup_and_get_string
     2169                    ("Prefix.",
     2170                     "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files",
     2171                     bkpinfo->prefix, MAX_STR_LEN / 4)) {
     2172                    log_to_screen("User has chosen not to backup the PC");
     2173                    finish(1);
     2174                }
     2175            } else {
     2176                for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     2177                    bkpinfo->media_size[i] = 650;
     2178                }
     2179            }
     2180        }
     2181        break;
     2182    default:
     2183        fatal_error
     2184            ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
     2185    }
     2186
     2187    if (archiving_to_media) {
    20642188
    20652189#ifdef __FreeBSD__
    2066     strcpy (bkpinfo->boot_device, call_program_and_get_last_line_of_output
    2067         ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     2190        strcpy(bkpinfo->boot_device,
     2191               call_program_and_get_last_line_of_output
     2192               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    20682193#else
    2069     strcpy (bkpinfo->boot_device, call_program_and_get_last_line_of_output
    2070             ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    2071 #endif
    2072       i = which_boot_loader(bkpinfo->boot_device);
    2073       if (i=='U') // unknown
    2074         {
     2194        strcpy(bkpinfo->boot_device,
     2195               call_program_and_get_last_line_of_output
     2196               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     2197#endif
     2198        i = which_boot_loader(bkpinfo->boot_device);
     2199        if (i == 'U')           // unknown
     2200        {
    20752201
    20762202#ifdef __FreeBSD__
    2077           if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device, MAX_STR_LEN/4))
    2078             { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2079           i = which_boot_loader (bkpinfo->boot_device);
     2203            if (!popup_and_get_string
     2204                ("Boot device",
     2205                 "What is your boot device? (e.g. /dev/ad0)",
     2206                 bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     2207                log_to_screen("User has chosen not to backup the PC");
     2208                finish(1);
     2209            }
     2210            i = which_boot_loader(bkpinfo->boot_device);
    20802211#else
    2081           if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", bkpinfo->boot_device, MAX_STR_LEN/4))
    2082             { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2083           if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { i='L'; }
    2084           else if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { i='E'; }
    2085           else if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { i='G'; }
    2086           else { i = 'U'; }
    2087 #endif
    2088           if (i == 'U')
    2089             {
    2090           if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
     2212            if (!popup_and_get_string
     2213                ("Boot device",
     2214                 "What is your boot device? (e.g. /dev/hda)",
     2215                 bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     2216                log_to_screen("User has chosen not to backup the PC");
     2217                finish(1);
     2218            }
     2219            if (does_string_exist_in_boot_block
     2220                (bkpinfo->boot_device, "LILO")) {
     2221                i = 'L';
     2222            } else
     2223                if (does_string_exist_in_boot_block
     2224                    (bkpinfo->boot_device, "ELILO")) {
     2225                i = 'E';
     2226            } else
     2227                if (does_string_exist_in_boot_block
     2228                    (bkpinfo->boot_device, "GRUB")) {
     2229                i = 'G';
     2230            } else {
     2231                i = 'U';
     2232            }
     2233#endif
     2234            if (i == 'U') {
     2235                if (ask_me_yes_or_no
     2236                    ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
     2237                {
     2238                    i = 'R';    // raw
     2239                } else {
     2240                    log_to_screen
     2241                        ("I cannot find your boot loader. Please run mondoarchive with parameters.");
     2242                    finish(1);
     2243                }
     2244            }
     2245        }
     2246        bkpinfo->boot_loader = i;
     2247        strcpy(bkpinfo->include_paths, "/");
     2248        if (!popup_and_get_string
     2249            ("Backup paths",
     2250             "Please enter paths which you want me to backup. The default is '/' (i.e. everything).",
     2251             bkpinfo->include_paths, MAX_STR_LEN)) {
     2252            log_to_screen("User has chosen not to backup the PC");
     2253            finish(1);
     2254        }
     2255        strcpy(tmp, list_of_NFS_mounts_only());
     2256        if (strlen(tmp) > 2) {
     2257            if (bkpinfo->exclude_paths[0]) {
     2258                strcat(bkpinfo->exclude_paths, " ");
     2259            }
     2260            strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
     2261        }
     2262// NTFS
     2263        strcpy(tmp,
     2264               call_program_and_get_last_line_of_output
     2265               ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     2266        if (strlen(tmp) > 2) {
     2267            if (!popup_and_get_string
     2268                ("NTFS partitions",
     2269                 "Please enter/confirm the NTFS partitions you wish to backup as well.",
     2270                 tmp, MAX_STR_LEN / 4)) {
     2271                log_to_screen("User has chosen not to backup the PC");
     2272                finish(1);
     2273            }
     2274            strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4);
     2275        }
     2276
     2277
     2278        if (!popup_and_get_string
     2279            ("Exclude paths",
     2280             "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.",
     2281             bkpinfo->exclude_paths, MAX_STR_LEN)) {
     2282            log_to_screen("User has chosen not to backup the PC");
     2283            finish(1);
     2284        }
     2285        bkpinfo->make_cd_use_lilo = FALSE;
     2286        bkpinfo->backup_data = TRUE;
     2287        bkpinfo->verify_data =
     2288            ask_me_yes_or_no
     2289            ("Will you want to verify your backups after Mondo has created them?");
     2290
     2291#ifndef __FreeBSD__
     2292        if (!ask_me_yes_or_no
     2293            ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))
     2294#endif
    20912295        {
    2092           i = 'R'; // raw
    2093         }
    2094           else
    2095         {
    2096           log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); finish(1);
    2097         }
    2098         }
    2099     }
    2100       bkpinfo->boot_loader = i;
    2101       strcpy(bkpinfo->include_paths, "/");
    2102       if (!popup_and_get_string("Backup paths", "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", bkpinfo->include_paths, MAX_STR_LEN))
    2103         { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2104       strcpy(tmp, list_of_NFS_mounts_only());
    2105       if (strlen(tmp)>2)
    2106         {
    2107           if (bkpinfo->exclude_paths[0]) { strcat(bkpinfo->exclude_paths, " "); }
    2108           strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
    2109     }
    2110 
    2111 // NTFS
    2112       strcpy(tmp, call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
    2113       if (strlen(tmp) > 2)
    2114         {
    2115       if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp, MAX_STR_LEN/4))
    2116             { log_to_screen ("User has chosen not to backup the PC"); finish(1); }
    2117           strncpy (bkpinfo->image_devs, tmp, MAX_STR_LEN/4);
    2118     }
    2119 
    2120 
    2121       if (!popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", bkpinfo->exclude_paths, MAX_STR_LEN))
    2122         { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2123       bkpinfo->make_cd_use_lilo = FALSE;
    2124       bkpinfo->backup_data = TRUE;
    2125       bkpinfo->verify_data = ask_me_yes_or_no("Will you want to verify your backups after Mondo has created them?");
    2126 
    2127 #ifndef __FreeBSD__
    2128       if (!ask_me_yes_or_no("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))
    2129 #endif
    2130         { strcpy(bkpinfo->kernel_path, "FAILSAFE"); }
    2131 
    2132       if (!ask_me_yes_or_no("Are you sure you want to proceed? Hit 'no' to abort."))
    2133         { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2134     }
    2135   else
    2136     {
    2137       bkpinfo->restore_data = TRUE; // probably...
    2138     }
    2139 
    2140   if (bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs)
    2141     {
    2142       g_ISO_restore_mode = TRUE;
    2143     }
    2144 
     2296            strcpy(bkpinfo->kernel_path, "FAILSAFE");
     2297        }
     2298
     2299        if (!ask_me_yes_or_no
     2300            ("Are you sure you want to proceed? Hit 'no' to abort.")) {
     2301            log_to_screen("User has chosen not to backup the PC");
     2302            finish(1);
     2303        }
     2304    } else {
     2305        bkpinfo->restore_data = TRUE;   // probably...
     2306    }
     2307
     2308    if (bkpinfo->backup_media_type == iso
     2309        || bkpinfo->backup_media_type == nfs) {
     2310        g_ISO_restore_mode = TRUE;
     2311    }
    21452312#ifdef __FreeSD__
    21462313// skip
    21472314#else
    2148   if (bkpinfo->backup_media_type == nfs)
    2149     {
    2150       sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3", bkpinfo->nfs_mount);
     2315    if (bkpinfo->backup_media_type == nfs) {
     2316        sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3",
     2317                bkpinfo->nfs_mount);
    21512318//      strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp));
    2152       log_msg(3, "I think the NFS mount is mounted at %s", bkpinfo->isodir);
    2153     }
    2154   log_it("isodir = %s", bkpinfo->isodir);
    2155   log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
    2156 #endif
    2157 
    2158   log_it("media device = %s", bkpinfo->media_device);
    2159   log_it("media size = %ld", bkpinfo->media_size[1]);
    2160   log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    2161   log_it("compression = %ld", bkpinfo->compression_level);
    2162   log_it("include_paths = '%s'", bkpinfo->include_paths);
    2163   log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);
    2164   log_it("scratchdir = '%s'", bkpinfo->scratchdir);
    2165   log_it("tmpdir = '%s'", bkpinfo->tmpdir);
    2166   log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
    2167   if (bkpinfo->media_size[0] < 0)
    2168     {
    2169       if (archiving_to_media)
    2170         {
    2171           fatal_error("Media size is less than zero.");
    2172         }
    2173       else
    2174         {
    2175       log_msg(2, "Warning - media size is less than zero.");
    2176       bkpinfo->media_size[0] = 0;
    2177     }
    2178     }
    2179   paranoid_free(tmp);
    2180   paranoid_free(sz_size);
    2181   paranoid_free(command);
    2182   paranoid_free(comment);
    2183   return(0);
     2319        log_msg(3, "I think the NFS mount is mounted at %s",
     2320                bkpinfo->isodir);
     2321    }
     2322    log_it("isodir = %s", bkpinfo->isodir);
     2323    log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
     2324#endif
     2325
     2326    log_it("media device = %s", bkpinfo->media_device);
     2327    log_it("media size = %ld", bkpinfo->media_size[1]);
     2328    log_it("media type = %s",
     2329           bkptype_to_string(bkpinfo->backup_media_type));
     2330    log_it("compression = %ld", bkpinfo->compression_level);
     2331    log_it("include_paths = '%s'", bkpinfo->include_paths);
     2332    log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);
     2333    log_it("scratchdir = '%s'", bkpinfo->scratchdir);
     2334    log_it("tmpdir = '%s'", bkpinfo->tmpdir);
     2335    log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device,
     2336           bkpinfo->boot_loader);
     2337    if (bkpinfo->media_size[0] < 0) {
     2338        if (archiving_to_media) {
     2339            fatal_error("Media size is less than zero.");
     2340        } else {
     2341            log_msg(2, "Warning - media size is less than zero.");
     2342            bkpinfo->media_size[0] = 0;
     2343        }
     2344    }
     2345    paranoid_free(tmp);
     2346    paranoid_free(sz_size);
     2347    paranoid_free(command);
     2348    paranoid_free(comment);
     2349    return (0);
    21842350}
    21852351
     
    21982364char *list_of_NFS_devices_and_mounts(void)
    21992365{
    2200   char *exclude_these_devices;
    2201   char *exclude_these_directories;
    2202   static char result_sz[512];
    2203 
    2204   malloc_string(exclude_these_devices);
    2205   malloc_string(exclude_these_directories);
    2206   strcpy(exclude_these_directories, call_program_and_get_last_line_of_output("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2207   strcpy(exclude_these_devices, call_program_and_get_last_line_of_output("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2208   sprintf(result_sz, "%s %s", exclude_these_directories, exclude_these_devices);
    2209   paranoid_free(exclude_these_devices);
    2210   paranoid_free(exclude_these_directories);
    2211   return(result_sz);
     2366    char *exclude_these_devices;
     2367    char *exclude_these_directories;
     2368    static char result_sz[512];
     2369
     2370    malloc_string(exclude_these_devices);
     2371    malloc_string(exclude_these_directories);
     2372    strcpy(exclude_these_directories,
     2373           call_program_and_get_last_line_of_output
     2374           ("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2375    strcpy(exclude_these_devices,
     2376           call_program_and_get_last_line_of_output
     2377           ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2378    sprintf(result_sz, "%s %s", exclude_these_directories,
     2379            exclude_these_devices);
     2380    paranoid_free(exclude_these_devices);
     2381    paranoid_free(exclude_these_directories);
     2382    return (result_sz);
    22122383}
    22132384
     
    22232394char *list_of_NFS_mounts_only(void)
    22242395{
    2225   char *exclude_these_devices;
    2226   char *exclude_these_directories;
    2227   static char result_sz[512];
    2228 
    2229   malloc_string(exclude_these_devices);
    2230   malloc_string(exclude_these_directories);
    2231   strcpy(exclude_these_directories, call_program_and_get_last_line_of_output("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2232   strcpy(exclude_these_devices, call_program_and_get_last_line_of_output("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2233   sprintf(result_sz, "%s", exclude_these_directories);
    2234   paranoid_free(exclude_these_devices);
    2235   paranoid_free(exclude_these_directories);
    2236   return(result_sz);
     2396    char *exclude_these_devices;
     2397    char *exclude_these_directories;
     2398    static char result_sz[512];
     2399
     2400    malloc_string(exclude_these_devices);
     2401    malloc_string(exclude_these_directories);
     2402    strcpy(exclude_these_directories,
     2403           call_program_and_get_last_line_of_output
     2404           ("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2405    strcpy(exclude_these_devices,
     2406           call_program_and_get_last_line_of_output
     2407           ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2408    sprintf(result_sz, "%s", exclude_these_directories);
     2409    paranoid_free(exclude_these_devices);
     2410    paranoid_free(exclude_these_directories);
     2411    return (result_sz);
    22372412}
    22382413
     
    22502425 * @ingroup deviceGroup
    22512426 */
    2252 void make_fifo(char*store_name_here, char*stub)
    2253 {
    2254   char *tmp;
    2255 
    2256   malloc_string(tmp);
    2257   assert_string_is_neither_NULL_nor_zerolength(stub);
    2258 
    2259   sprintf(store_name_here, "%s%d%d", stub, (int)(random()%32768), (int)(random()%32768));
    2260   make_hole_for_file(store_name_here);
    2261   mkfifo(store_name_here, S_IRWXU|S_IRWXG);
    2262   sprintf(tmp, "chmod 770 %s", store_name_here);
    2263   paranoid_system(tmp);
    2264   paranoid_free(tmp);
     2427void make_fifo(char *store_name_here, char *stub)
     2428{
     2429    char *tmp;
     2430
     2431    malloc_string(tmp);
     2432    assert_string_is_neither_NULL_nor_zerolength(stub);
     2433
     2434    sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
     2435            (int) (random() % 32768));
     2436    make_hole_for_file(store_name_here);
     2437    mkfifo(store_name_here, S_IRWXU | S_IRWXG);
     2438    sprintf(tmp, "chmod 770 %s", store_name_here);
     2439    paranoid_system(tmp);
     2440    paranoid_free(tmp);
    22652441}
    22662442
     
    22782454void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
    22792455{
    2280   char *tmp, *command, *sz;
    2281 
    2282   malloc_string(tmp);
    2283   malloc_string(command);
    2284   malloc_string(sz);
    2285   assert(bkpinfo!=NULL);
     2456    char *tmp, *command, *sz;
     2457
     2458    malloc_string(tmp);
     2459    malloc_string(command);
     2460    malloc_string(sz);
     2461    assert(bkpinfo != NULL);
    22862462
    22872463#ifdef __FreeBSD__
    2288       strcpy(tmp, call_program_and_get_last_line_of_output("df -m -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2464    strcpy(tmp,
     2465           call_program_and_get_last_line_of_output
     2466           ("df -m -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    22892467#else
    2290       strcpy(tmp, call_program_and_get_last_line_of_output("df -m -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | grep -v /dev/shm | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    2291 #endif
    2292 
    2293       if (tmp[0]!='/') { strcpy(sz, tmp); strcpy(tmp, "/"); strcat(tmp, sz); }
    2294       if (!tmp[0]) {
    2295       fatal_error ("I couldn't figure out the tempdir!");
    2296       }
    2297       sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, (int)(random()%32768));
    2298       log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    2299 
    2300       sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, (int)(random()%32768));
    2301       log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    2302 
    2303       sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    2304      
    2305       sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
    2306       paranoid_system(command);
    2307   paranoid_free(tmp);
    2308   paranoid_free(command);
    2309   paranoid_free(sz);
     2468    strcpy(tmp,
     2469           call_program_and_get_last_line_of_output
     2470           ("df -m -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | grep -v /dev/shm | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2471#endif
     2472
     2473    if (tmp[0] != '/') {
     2474        strcpy(sz, tmp);
     2475        strcpy(tmp, "/");
     2476        strcat(tmp, sz);
     2477    }
     2478    if (!tmp[0]) {
     2479        fatal_error("I couldn't figure out the tempdir!");
     2480    }
     2481    sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,
     2482            (int) (random() % 32768));
     2483    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
     2484
     2485    sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp,
     2486            (int) (random() % 32768));
     2487    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
     2488
     2489    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     2490            bkpinfo->scratchdir);
     2491
     2492    sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2493    paranoid_system(command);
     2494    paranoid_free(tmp);
     2495    paranoid_free(command);
     2496    paranoid_free(sz);
    23102497}
    23112498
     
    23262513 * @return TRUE if @p dev exists, FALSE if it doesn't.
    23272514 */
    2328 bool set_dev_to_this_if_rx_OK(char *output, char*dev)
    2329 {
    2330   char *command;
    2331 
    2332   malloc_string(command);
    2333   if (!dev || dev[0]=='\0') { output[0]='\0'; return(FALSE); }
     2515bool set_dev_to_this_if_rx_OK(char *output, char *dev)
     2516{
     2517    char *command;
     2518
     2519    malloc_string(command);
     2520    if (!dev || dev[0] == '\0') {
     2521        output[0] = '\0';
     2522        return (FALSE);
     2523    }
    23342524//  assert_string_is_neither_NULL_nor_zerolength(dev);
    2335   log_msg(10, "Injecting %s", dev);
    2336   inject_device(dev);
    2337   if (!does_file_exist(dev)) { log_msg(10, "%s doesn't exist. Returning FALSE.", dev); return(FALSE); }
    2338   sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
    2339   if (!run_program_and_log_output(command, FALSE) && !run_program_and_log_output(command, FALSE))
    2340     { strcpy(output, dev); log_msg(4, "Found it - %s", dev); return(TRUE); }
    2341   else
    2342     { output[0]='\0'; log_msg(4, "It's not %s",dev); return(FALSE); }
     2525    log_msg(10, "Injecting %s", dev);
     2526    inject_device(dev);
     2527    if (!does_file_exist(dev)) {
     2528        log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
     2529        return (FALSE);
     2530    }
     2531    sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
     2532            512L, dev);
     2533    if (!run_program_and_log_output(command, FALSE)
     2534        && !run_program_and_log_output(command, FALSE)) {
     2535        strcpy(output, dev);
     2536        log_msg(4, "Found it - %s", dev);
     2537        return (TRUE);
     2538    } else {
     2539        output[0] = '\0';
     2540        log_msg(4, "It's not %s", dev);
     2541        return (FALSE);
     2542    }
    23432543}
    23442544
     
    23562556int what_number_cd_is_this(struct s_bkpinfo *bkpinfo)
    23572557{
    2358   int cd_number=-1;
    2359   char *mountdev;
    2360   char *tmp;
    2361 
    2362   malloc_string(mountdev);
    2363   malloc_string(tmp);
    2364   assert(bkpinfo!=NULL);
     2558    int cd_number = -1;
     2559    char *mountdev;
     2560    char *tmp;
     2561
     2562    malloc_string(mountdev);
     2563    malloc_string(tmp);
     2564    assert(bkpinfo != NULL);
    23652565//  log_it("Asking what_number_cd_is_this");
    2366   if (g_ISO_restore_mode)
    2367     {
    2368       sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
     2566    if (g_ISO_restore_mode) {
     2567        sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    23692568//      log_it("tmp = %s", tmp);
    23702569
    2371       strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
    2372       strcat(mountdev, "/archives/THIS-CD-NUMBER");
     2570        strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
     2571        strcat(mountdev, "/archives/THIS-CD-NUMBER");
    23732572//      log_it("mountdev = %s", mountdev);
    2374       cd_number = atoi(last_line_of_file(mountdev));
     2573        cd_number = atoi(last_line_of_file(mountdev));
    23752574//      log_it("cd_number = %d", cd_number);
    2376 paranoid_free(mountdev);
    2377 paranoid_free(tmp);
    2378       return(cd_number);
    2379     }
    2380 
    2381   strcpy(mountdev, bkpinfo->media_device);
    2382   if (!mountdev[0])
    2383     {
    2384       log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
    2385       find_cdrom_device(bkpinfo->media_device, FALSE);
    2386     }
    2387   if (! is_this_device_mounted(MNT_CDROM))
    2388     { mount_CDROM_here(mountdev, MNT_CDROM); }
    2389   cd_number = atoi(last_line_of_file(MNT_CDROM"/archives/THIS-CD-NUMBER"));
     2575        paranoid_free(mountdev);
     2576        paranoid_free(tmp);
     2577        return (cd_number);
     2578    }
     2579
     2580    strcpy(mountdev, bkpinfo->media_device);
     2581    if (!mountdev[0]) {
     2582        log_it
     2583            ("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
     2584        find_cdrom_device(bkpinfo->media_device, FALSE);
     2585    }
     2586    if (!is_this_device_mounted(MNT_CDROM)) {
     2587        mount_CDROM_here(mountdev, MNT_CDROM);
     2588    }
     2589    cd_number =
     2590        atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    23902591//  log_it("cd_number..later.. = %d", cd_number);
    2391 paranoid_free(mountdev);
    2392 paranoid_free(tmp);
    2393   return(cd_number);
     2592    paranoid_free(mountdev);
     2593    paranoid_free(tmp);
     2594    return (cd_number);
    23942595}
    23952596
     
    24072608 * The mountpoint (where it's mounted) will obviously be '/'.
    24082609 */
    2409 char *
    2410 where_is_root_mounted ()
    2411 {
    2412     /*@ buffers *****************/
    2413   static char tmp[MAX_STR_LEN];
     2610char *where_is_root_mounted()
     2611{
     2612    /*@ buffers **************** */
     2613    static char tmp[MAX_STR_LEN];
    24142614
    24152615
    24162616#ifdef __FreeBSD__
    2417   strcpy (tmp, call_program_and_get_last_line_of_output
    2418           ("mount | grep \" on / \" | cut -d' ' -f1"));
     2617    strcpy(tmp, call_program_and_get_last_line_of_output
     2618           ("mount | grep \" on / \" | cut -d' ' -f1"));
    24192619#else
    2420   strcpy (tmp, call_program_and_get_last_line_of_output
    2421       ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
    2422   if (strstr(tmp, "/dev/cciss/")) {
    2423       strcpy (tmp, call_program_and_get_last_line_of_output
    2424               ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
    2425   }
    2426   if (strstr(tmp, "/dev/md"))
    2427     {
    2428       strcpy(tmp,
    2429          call_program_and_get_last_line_of_output
    2430          ("mount | grep \" on / \" | cut -d' ' -f1"));
    2431     }
    2432 #endif
    2433 
    2434   return (tmp);
     2620    strcpy(tmp, call_program_and_get_last_line_of_output
     2621           ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
     2622    if (strstr(tmp, "/dev/cciss/")) {
     2623        strcpy(tmp, call_program_and_get_last_line_of_output
     2624               ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
     2625    }
     2626    if (strstr(tmp, "/dev/md")) {
     2627        strcpy(tmp,
     2628               call_program_and_get_last_line_of_output
     2629               ("mount | grep \" on / \" | cut -d' ' -f1"));
     2630    }
     2631#endif
     2632
     2633    return (tmp);
    24352634}
    24362635
     
    24432642 */
    24442643#ifdef __FreeBSD__
    2445 char which_boot_loader (char *which_device)
    2446 {
    2447   int count_lilos = 0;
    2448   int count_grubs = 0;
    2449   int count_boot0s = 0;
    2450   int count_dangerouslydedicated = 0;
    2451 
    2452   log_it ("looking at drive %s's MBR", which_device);
    2453   if (does_string_exist_in_boot_block (which_device, "GRUB"))
    2454       { count_grubs++; }
    2455   if (does_string_exist_in_boot_block (which_device, "LILO"))
    2456       { count_lilos++; }
    2457   if (does_string_exist_in_boot_block (which_device, "Drive"))
    2458       { count_boot0s++; }
    2459   if (does_string_exist_in_first_N_blocks (which_device, "FreeBSD/i386", 17))
    2460       { count_dangerouslydedicated++; }
    2461   log_it ("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n", count_grubs, count_lilos, count_elilos, count_boot0s, count_dangerouslydedicated);
    2462 
    2463   if (count_grubs && !count_lilos)
    2464     { return ('G'); }
    2465   else if (count_lilos && !count_grubs)
    2466     { return ('L'); }
    2467  else if (count_grubs == 1 && count_lilos == 1)
    2468     {
    2469       log_it ("I'll bet you used to use LILO but switched to GRUB...");
    2470       return ('G');
    2471     }
    2472   else if (count_boot0s == 1)
    2473       { return ('B'); }
    2474   else if (count_dangerouslydedicated)
    2475       { return ('D'); }
    2476   else
    2477     {
    2478       log_it ("Unknown boot loader");
    2479       return ('U');
    2480     }
     2644char which_boot_loader(char *which_device)
     2645{
     2646    int count_lilos = 0;
     2647    int count_grubs = 0;
     2648    int count_boot0s = 0;
     2649    int count_dangerouslydedicated = 0;
     2650
     2651    log_it("looking at drive %s's MBR", which_device);
     2652    if (does_string_exist_in_boot_block(which_device, "GRUB")) {
     2653        count_grubs++;
     2654    }
     2655    if (does_string_exist_in_boot_block(which_device, "LILO")) {
     2656        count_lilos++;
     2657    }
     2658    if (does_string_exist_in_boot_block(which_device, "Drive")) {
     2659        count_boot0s++;
     2660    }
     2661    if (does_string_exist_in_first_N_blocks
     2662        (which_device, "FreeBSD/i386", 17)) {
     2663        count_dangerouslydedicated++;
     2664    }
     2665    log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n",
     2666           count_grubs, count_lilos, count_elilos, count_boot0s,
     2667           count_dangerouslydedicated);
     2668
     2669    if (count_grubs && !count_lilos) {
     2670        return ('G');
     2671    } else if (count_lilos && !count_grubs) {
     2672        return ('L');
     2673    } else if (count_grubs == 1 && count_lilos == 1) {
     2674        log_it("I'll bet you used to use LILO but switched to GRUB...");
     2675        return ('G');
     2676    } else if (count_boot0s == 1) {
     2677        return ('B');
     2678    } else if (count_dangerouslydedicated) {
     2679        return ('D');
     2680    } else {
     2681        log_it("Unknown boot loader");
     2682        return ('U');
     2683    }
    24812684}
    24822685
    24832686#else
    24842687
    2485 char which_boot_loader (char *which_device)
    2486 {
    2487     /*@ buffer ******************************************************/
    2488   char *list_drives_cmd;
    2489   char *current_drive;
    2490 
    2491     /*@ pointers ****************************************************/
    2492   FILE *pdrives;
    2493 
    2494     /*@ int *********************************************************/
    2495   int count_lilos = 0;
    2496   int count_grubs = 0;
    2497 
    2498     /*@ end vars ****************************************************/
    2499 
    2500   malloc_string(list_drives_cmd);
    2501   malloc_string(current_drive);
     2688char which_boot_loader(char *which_device)
     2689{
     2690    /*@ buffer ***************************************************** */
     2691    char *list_drives_cmd;
     2692    char *current_drive;
     2693
     2694    /*@ pointers *************************************************** */
     2695    FILE *pdrives;
     2696
     2697    /*@ int ******************************************************** */
     2698    int count_lilos = 0;
     2699    int count_grubs = 0;
     2700
     2701    /*@ end vars *************************************************** */
     2702
     2703    malloc_string(list_drives_cmd);
     2704    malloc_string(current_drive);
    25022705
    25032706#ifdef __IA64__
    2504   /* No choice for it */
    2505   return ('E');
    2506 #endif
    2507   assert(which_device!=NULL);
    2508   //  sprintf (list_drives_cmd,
    2509   //       "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2");
    2510 
    2511   sprintf (list_drives_cmd,
    2512   // "parted2fdisk
    2513        "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
    2514   log_it("list_drives_cmd = %s", list_drives_cmd);
    2515 
    2516   if (!(pdrives = popen (list_drives_cmd, "r")))
    2517     {
    2518       log_OS_error ("Unable to open list of drives");
    2519       paranoid_free(list_drives_cmd);
    2520       paranoid_free(current_drive);
    2521       return ('\0');
    2522     }
    2523   for (fgets (current_drive, MAX_STR_LEN, pdrives); !feof (pdrives);
    2524        fgets (current_drive, MAX_STR_LEN, pdrives))
    2525     {
    2526       strip_spaces (current_drive);
    2527       log_it ("looking at drive %s's MBR", current_drive);
    2528       if (does_string_exist_in_boot_block (current_drive, "GRUB"))
    2529     {
    2530       count_grubs++;
    2531       strcpy (which_device, current_drive);
    2532       break;
    2533     }
    2534       if (does_string_exist_in_boot_block (current_drive, "LILO"))
    2535     {
    2536       count_lilos++;
    2537       strcpy (which_device, current_drive);
    2538       break;
    2539     }
    2540     }
    2541   if (pclose (pdrives)) { log_OS_error("Cannot pclose pdrives"); }
    2542   log_it ("%d grubs and %d lilos\n", count_grubs, count_lilos);
    2543   paranoid_free(list_drives_cmd);
    2544   paranoid_free(current_drive);
    2545   if (count_grubs && !count_lilos)
    2546     {
    2547       return ('G');
    2548     }
    2549   else if (count_lilos && !count_grubs)
    2550     {
    2551       return ('L');
    2552     }
    2553   else if (count_grubs == 1 && count_lilos == 1)
    2554     {
    2555       log_it ("I'll bet you used to use LILO but switched to GRUB...");
    2556       return ('G');
    2557     }
    2558   else
    2559     {
    2560       log_it ("Unknown boot loader");
    2561       return ('U');
    2562     }
     2707    /* No choice for it */
     2708    return ('E');
     2709#endif
     2710    assert(which_device != NULL);
     2711    //  sprintf (list_drives_cmd,
     2712    //       "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2");
     2713
     2714    sprintf(list_drives_cmd,
     2715            // "parted2fdisk
     2716            "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s",
     2717            where_is_root_mounted());
     2718    log_it("list_drives_cmd = %s", list_drives_cmd);
     2719
     2720    if (!(pdrives = popen(list_drives_cmd, "r"))) {
     2721        log_OS_error("Unable to open list of drives");
     2722        paranoid_free(list_drives_cmd);
     2723        paranoid_free(current_drive);
     2724        return ('\0');
     2725    }
     2726    for (fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
     2727         fgets(current_drive, MAX_STR_LEN, pdrives)) {
     2728        strip_spaces(current_drive);
     2729        log_it("looking at drive %s's MBR", current_drive);
     2730        if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
     2731            count_grubs++;
     2732            strcpy(which_device, current_drive);
     2733            break;
     2734        }
     2735        if (does_string_exist_in_boot_block(current_drive, "LILO")) {
     2736            count_lilos++;
     2737            strcpy(which_device, current_drive);
     2738            break;
     2739        }
     2740    }
     2741    if (pclose(pdrives)) {
     2742        log_OS_error("Cannot pclose pdrives");
     2743    }
     2744    log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
     2745    paranoid_free(list_drives_cmd);
     2746    paranoid_free(current_drive);
     2747    if (count_grubs && !count_lilos) {
     2748        return ('G');
     2749    } else if (count_lilos && !count_grubs) {
     2750        return ('L');
     2751    } else if (count_grubs == 1 && count_lilos == 1) {
     2752        log_it("I'll bet you used to use LILO but switched to GRUB...");
     2753        return ('G');
     2754    } else {
     2755        log_it("Unknown boot loader");
     2756        return ('U');
     2757    }
    25632758}
    25642759#endif
     
    25722767 * @return 0 for success, 1 for failure.
    25732768 */
    2574 int
    2575 zero_out_a_device (char *device)
    2576 {
    2577   FILE *fout;
    2578   int i;
    2579 
    2580   assert_string_is_neither_NULL_nor_zerolength(device);
    2581 
    2582   log_it ("Zeroing drive %s", device);
    2583   if (!(fout=fopen (device, "w")))
    2584     {
    2585       log_OS_error ("Unable to open/write to device");
    2586       return (1);
    2587     }
    2588   for (i = 0; i < 16384; i++)
    2589     {
    2590       fputc ('\0', fout);
    2591     }
    2592   paranoid_fclose(fout);
    2593   log_it ("Device successfully zeroed.");
    2594   return (0);
     2769int zero_out_a_device(char *device)
     2770{
     2771    FILE *fout;
     2772    int i;
     2773
     2774    assert_string_is_neither_NULL_nor_zerolength(device);
     2775
     2776    log_it("Zeroing drive %s", device);
     2777    if (!(fout = fopen(device, "w"))) {
     2778        log_OS_error("Unable to open/write to device");
     2779        return (1);
     2780    }
     2781    for (i = 0; i < 16384; i++) {
     2782        fputc('\0', fout);
     2783    }
     2784    paranoid_fclose(fout);
     2785    log_it("Device successfully zeroed.");
     2786    return (0);
    25952787}
    25962788
     
    26022794 * @bug Won't work with file v4.0; needs to be written in C.
    26032795 */
    2604 char *resolve_softlinks_to_get_to_actual_device_file(char*incoming)
    2605 {
    2606   static char output[MAX_STR_LEN];
    2607   char *command;
    2608   char *curr_fname;
    2609   char *scratch;
    2610   char *tmp;
    2611   char *p;
    2612    
    2613   struct stat statbuf; 
    2614   command = malloc(1000);
    2615   malloc_string(tmp);
    2616   malloc_string(scratch);
    2617   malloc_string(curr_fname);
    2618   if (!does_file_exist(incoming))
    2619     {
    2620       log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found");
    2621       strcpy(output, incoming);
    2622     }
    2623   else
    2624     {
    2625       strcpy(curr_fname, incoming);
    2626       lstat(curr_fname, &statbuf);
    2627       while(S_ISLNK(statbuf.st_mode))
    2628         {
    2629       log_msg(1, "curr_fname = %s", curr_fname);
    2630       sprintf(command, "file %s", curr_fname);
    2631       strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2632       for(p=tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--);
    2633       p++;
    2634       strcpy(scratch, p);
    2635       for(p=scratch; *p != '\0' && *p != '\''; p++);
    2636       *p = '\0';
    2637       log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
    2638       if (scratch[0] == '/')
    2639         {
    2640           strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink
    2641         }
    2642       else
    2643         { // copy over the basename cos it's a relative softlink
    2644           p = curr_fname + strlen(curr_fname);
    2645           while(p!=curr_fname && *p != '/') { p--;}
    2646           if (*p == '/') { p++; }
    2647           strcpy(p, scratch);
    2648         }
    2649           lstat(curr_fname, &statbuf);
    2650     }
    2651       strcpy(output, curr_fname);
    2652       log_it("resolved %s to %s", incoming, output);
    2653     }
    2654   paranoid_free(command);
    2655   paranoid_free(curr_fname);
    2656   paranoid_free(tmp);
    2657   return(output);
     2796char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
     2797{
     2798    static char output[MAX_STR_LEN];
     2799    char *command;
     2800    char *curr_fname;
     2801    char *scratch;
     2802    char *tmp;
     2803    char *p;
     2804
     2805    struct stat statbuf;
     2806    command = malloc(1000);
     2807    malloc_string(tmp);
     2808    malloc_string(scratch);
     2809    malloc_string(curr_fname);
     2810    if (!does_file_exist(incoming)) {
     2811        log_it
     2812            ("resolve_softlinks_to_get_to_actual_device_file --- device not found");
     2813        strcpy(output, incoming);
     2814    } else {
     2815        strcpy(curr_fname, incoming);
     2816        lstat(curr_fname, &statbuf);
     2817        while (S_ISLNK(statbuf.st_mode)) {
     2818            log_msg(1, "curr_fname = %s", curr_fname);
     2819            sprintf(command, "file %s", curr_fname);
     2820            strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2821            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
     2822                 p--);
     2823            p++;
     2824            strcpy(scratch, p);
     2825            for (p = scratch; *p != '\0' && *p != '\''; p++);
     2826            *p = '\0';
     2827            log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp,
     2828                    scratch);
     2829            if (scratch[0] == '/') {
     2830                strcpy(curr_fname, scratch);    // copy whole thing because it's an absolute softlink
     2831            } else {            // copy over the basename cos it's a relative softlink
     2832                p = curr_fname + strlen(curr_fname);
     2833                while (p != curr_fname && *p != '/') {
     2834                    p--;
     2835                }
     2836                if (*p == '/') {
     2837                    p++;
     2838                }
     2839                strcpy(p, scratch);
     2840            }
     2841            lstat(curr_fname, &statbuf);
     2842        }
     2843        strcpy(output, curr_fname);
     2844        log_it("resolved %s to %s", incoming, output);
     2845    }
     2846    paranoid_free(command);
     2847    paranoid_free(curr_fname);
     2848    paranoid_free(tmp);
     2849    return (output);
    26582850}
    26592851
     
    26662858char *which_partition_format(const char *drive)
    26672859{
    2668   static char output[4];
    2669   char *tmp;
    2670   char *command;
    2671    
    2672   malloc_string(tmp);
    2673   malloc_string(command);
    2674   log_msg(0, "Looking for partition table format type");
    2675   sprintf(command, "fdisk -l %s | grep 'EFI GPT'", drive);
    2676   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2677   if (strstr(tmp,"GPT") == NULL) {
    2678       strcpy(output,"MBR");
    2679   } else {
    2680       strcpy(output,"GPT");
    2681   }
    2682   log_msg(0, "Found %s partition table format type",output);
    2683   paranoid_free(command);
    2684   paranoid_free(tmp);
    2685   return(output);
     2860    static char output[4];
     2861    char *tmp;
     2862    char *command;
     2863
     2864    malloc_string(tmp);
     2865    malloc_string(command);
     2866    log_msg(0, "Looking for partition table format type");
     2867    sprintf(command, "fdisk -l %s | grep 'EFI GPT'", drive);
     2868    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2869    if (strstr(tmp, "GPT") == NULL) {
     2870        strcpy(output, "MBR");
     2871    } else {
     2872        strcpy(output, "GPT");
     2873    }
     2874    log_msg(0, "Found %s partition table format type", output);
     2875    paranoid_free(command);
     2876    paranoid_free(tmp);
     2877    return (output);
    26862878}
    26872879
    26882880/* @} - end of deviceGroup */
    2689 
  • trunk/mondo/mondo/common/libmondo-devices.h

    r30 r59  
    11/*
    2  * $Id: libmondo-devices.h,v 1.4 2004/06/17 11:57:52 hugo Exp $
     2 * $Id$
    33 */
    44
    5 bool am_I_in_disaster_recovery_mode (void);
    6 bool does_device_exist (char *device);
    7 int does_partition_exist (const char *drive, int partno);
    8 bool does_string_exist_in_boot_block (char *dev, char *str);
    9 int find_and_mount_actual_cd (struct s_bkpinfo *bkpinfo, char *mountpoint);
    10 int find_cdrom_device (char *output, bool try_to_mount);
    11 int find_dvd_device (char *output, bool try_to_mount);
    12 long get_phys_size_of_drive (char *drive);
    13 bool is_this_a_valid_disk_format (char *format);
    14 int mount_CDROM_here (char *device, char *mountpoint);
    15 int find_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
    16 bool is_this_device_mounted (char *device_raw);
    17 char *where_is_root_mounted (void);
    18 char *make_vn (char *file);
    19 int kick_vn (char *vn);
    20 char which_boot_loader (char *which_device);
     5bool am_I_in_disaster_recovery_mode(void);
     6bool does_device_exist(char *device);
     7int does_partition_exist(const char *drive, int partno);
     8bool does_string_exist_in_boot_block(char *dev, char *str);
     9int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint);
     10int find_cdrom_device(char *output, bool try_to_mount);
     11int find_dvd_device(char *output, bool try_to_mount);
     12long get_phys_size_of_drive(char *drive);
     13bool is_this_a_valid_disk_format(char *format);
     14int mount_CDROM_here(char *device, char *mountpoint);
     15int find_device_in_mountlist(struct mountlist_itself *mountlist,
     16                             char *device);
     17bool is_this_device_mounted(char *device_raw);
     18char *where_is_root_mounted(void);
     19char *make_vn(char *file);
     20int kick_vn(char *vn);
     21char which_boot_loader(char *which_device);
    2122
    2223
    2324
    24 int find_cdrw_device (char *cdrw_device);
     25int find_cdrw_device(char *cdrw_device);
    2526
    26 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *, bool);
     27int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *,
     28                                                    bool);
    2729
    2830
    2931
    30 void make_fifo(char*store_name_here, char*stub);
     32void make_fifo(char *store_name_here, char *stub);
    3133
    32 void insist_on_this_cd_number (struct s_bkpinfo* bkpinfo, int cd_number_i_want);
     34void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo,
     35                              int cd_number_i_want);
    3336
    3437int what_number_cd_is_this(struct s_bkpinfo *bkpinfo);
    3538
    36 int eject_device(char*);
     39int eject_device(char *);
    3740
    3841char *list_of_NFS_devices_and_mounts();
     
    4245
    4346
    44 bool set_dev_to_this_if_rx_OK(char *output, char*dev);
     47bool set_dev_to_this_if_rx_OK(char *output, char *dev);
    4548
    4649
    4750void retract_CD_tray_and_defeat_autorun(void);
    48 bool does_string_exist_in_first_N_blocks (char *dev, char *str, int n);
     51bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n);
    4952
    50 int inject_device(char*dev);
     53int inject_device(char *dev);
    5154
    5255bool does_nonMS_partition_exist(void);
    53 char *resolve_softlinks_to_get_to_actual_device_file(char*incoming);
    54 void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo*bkpinfo);
     56char *resolve_softlinks_to_get_to_actual_device_file(char *incoming);
     57void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo);
    5558
    5659bool is_dev_an_NTFS_dev(char *bigfile_fname);
  • trunk/mondo/mondo/common/libmondo-fifo-EXT.h

    r30 r59  
    11/* libfifo-EXT.h */
    22
    3 extern FILE*open_device_via_buffer(char*dev, char direction, long internal_block_size);
     3extern FILE *open_device_via_buffer(char *dev, char direction,
     4                                    long internal_block_size);
    45extern void sigpipe_occurred(int);
    56extern void kill_buffer();
    6 
  • trunk/mondo/mondo/common/libmondo-fifo.h

    r30 r59  
    11/* libmondo-fifo.h
    2  * $Id: libmondo-fifo.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    88
    99
    10 FILE*open_device_via_buffer(char*dev, char direction, long internal_block_size);
     10FILE *open_device_via_buffer(char *dev, char direction,
     11                             long internal_block_size);
    1112void sigpipe_occurred(int);
    1213void kill_buffer();
  • trunk/mondo/mondo/common/libmondo-filelist-EXT.h

    r30 r59  
    11/* libmondo-filelist-EXT.h */
    22
    3 extern int chop_filelist (char *filelist, char *outdir, long maxsetsizeK);
    4 extern int call_filelist_chopper (struct s_bkpinfo *bkpinfo);
    5 extern void free_filelist (struct s_node *filelist);
    6 extern int get_last_filelist_number (struct s_bkpinfo *bkpinfo);
    7 extern int add_string_at_node (struct s_node *startnode, char *string_to_add);
    8 extern struct s_node *load_filelist (char *filelist_fname);
    9 extern void reload_filelist (struct s_node *filelist);
    10 extern void save_filelist (struct s_node *filelist, char *outfname);
    11 extern void toggle_all_root_dirs_on (struct s_node *filelist);
    12 extern void toggle_path_expandability (struct s_node *filelist, char *pathname, bool on_or_off);
    13 extern void toggle_path_selection (struct s_node *filelist, char *pathname, bool on_or_off);
    14 extern void toggle_node_selection (struct s_node *filelist, bool on_or_off);
    15 extern int prepare_filelist (struct s_bkpinfo *bkpinfo);
     3extern int chop_filelist(char *filelist, char *outdir, long maxsetsizeK);
     4extern int call_filelist_chopper(struct s_bkpinfo *bkpinfo);
     5extern void free_filelist(struct s_node *filelist);
     6extern int get_last_filelist_number(struct s_bkpinfo *bkpinfo);
     7extern int add_string_at_node(struct s_node *startnode,
     8                              char *string_to_add);
     9extern struct s_node *load_filelist(char *filelist_fname);
     10extern void reload_filelist(struct s_node *filelist);
     11extern void save_filelist(struct s_node *filelist, char *outfname);
     12extern void toggle_all_root_dirs_on(struct s_node *filelist);
     13extern void toggle_path_expandability(struct s_node *filelist,
     14                                      char *pathname, bool on_or_off);
     15extern void toggle_path_selection(struct s_node *filelist, char *pathname,
     16                                  bool on_or_off);
     17extern void toggle_node_selection(struct s_node *filelist, bool on_or_off);
     18extern int prepare_filelist(struct s_bkpinfo *bkpinfo);
    1619
    17 extern long save_filelist_entries_in_common(
    18             char*needles_list_fname,
    19             struct s_node *filelist,
    20             char*matches_fname, bool use_star);
    21 extern struct s_node *find_string_at_node (struct s_node *startnode, char *string_to_find);
     20extern long save_filelist_entries_in_common(char *needles_list_fname,
     21                                            struct s_node *filelist,
     22                                            char *matches_fname,
     23                                            bool use_star);
     24extern struct s_node *find_string_at_node(struct s_node *startnode,
     25                                          char *string_to_find);
    2226
    23 extern int add_list_of_files_to_filelist(struct s_node *filelist, char*list_of_files_fname, bool flag_em);
     27extern int add_list_of_files_to_filelist(struct s_node *filelist,
     28                                         char *list_of_files_fname,
     29                                         bool flag_em);
    2430
    25 extern void show_filelist (struct s_node *node);
    26 extern int get_fattr_list(char*filelist, char*fattr_fname);
    27 extern int get_acl_list(char*filelist, char*acl_fname);
    28 extern int set_fattr_list(char*masklist, char*fattr_fname);
    29 extern int set_acl_list(char*masklist, char*acl_fname);
     31extern void show_filelist(struct s_node *node);
     32extern int get_fattr_list(char *filelist, char *fattr_fname);
     33extern int get_acl_list(char *filelist, char *acl_fname);
     34extern int set_fattr_list(char *masklist, char *fattr_fname);
     35extern int set_acl_list(char *masklist, char *acl_fname);
  • trunk/mondo/mondo/common/libmondo-filelist.c

    r49 r59  
    18591859            }
    18601860        }
    1861     paranoid_free(fname);
     1861        paranoid_free(fname);
    18621862    }
    18631863    paranoid_fclose(fout);
  • trunk/mondo/mondo/common/libmondo-filelist.h

    r30 r59  
    11/* libmondo-filelist.h
    2  * $Id: libmondo-filelist.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    5 int chop_filelist (char *filelist, char *outdir, long maxsetsizeK);
    6 int call_filelist_chopper (struct s_bkpinfo *bkpinfo);
    7 void free_filelist (struct s_node *filelist);
    8 int get_last_filelist_number (struct s_bkpinfo *bkpinfo);
    9 int add_string_at_node (struct s_node *startnode, char *string_to_add);
    10 struct s_node *load_filelist (char *filelist_fname);
    11 void reload_filelist (struct s_node *filelist);
    12 void save_filelist (struct s_node *filelist, char *outfname);
    13 void toggle_all_root_dirs_on (struct s_node *filelist);
    14 void toggle_path_expandability (struct s_node *filelist, char *pathname, bool on_or_off);
    15 void toggle_path_selection (struct s_node *filelist, char *pathname, bool on_or_off);
    16 void toggle_node_selection (struct s_node *filelist, bool on_or_off);
    17 int prepare_filelist (struct s_bkpinfo *bkpinfo);
     5int chop_filelist(char *filelist, char *outdir, long maxsetsizeK);
     6int call_filelist_chopper(struct s_bkpinfo *bkpinfo);
     7void free_filelist(struct s_node *filelist);
     8int get_last_filelist_number(struct s_bkpinfo *bkpinfo);
     9int add_string_at_node(struct s_node *startnode, char *string_to_add);
     10struct s_node *load_filelist(char *filelist_fname);
     11void reload_filelist(struct s_node *filelist);
     12void save_filelist(struct s_node *filelist, char *outfname);
     13void toggle_all_root_dirs_on(struct s_node *filelist);
     14void toggle_path_expandability(struct s_node *filelist, char *pathname,
     15                               bool on_or_off);
     16void toggle_path_selection(struct s_node *filelist, char *pathname,
     17                           bool on_or_off);
     18void toggle_node_selection(struct s_node *filelist, bool on_or_off);
     19int prepare_filelist(struct s_bkpinfo *bkpinfo);
    1820
    19 long save_filelist_entries_in_common(
    20             char*needles_list_fname,
    21             struct s_node *filelist,
    22             char*matches_fname, bool use_star);
    23 struct s_node *find_string_at_node (struct s_node *startnode, char *string_to_find);
     21long save_filelist_entries_in_common(char *needles_list_fname,
     22                                     struct s_node *filelist,
     23                                     char *matches_fname, bool use_star);
     24struct s_node *find_string_at_node(struct s_node *startnode,
     25                                  char *string_to_find);
    2426
    25 int add_list_of_files_to_filelist(struct s_node *filelist, char*list_of_files_fname, bool flag_em);
    26 void show_filelist (struct s_node *node);
    27 int get_fattr_list(char*filelist, char*fattr_fname);
    28 int get_acl_list(char*filelist, char*acl_fname);
    29 int set_fattr_list(char*masklist, char*fattr_fname);
    30 int set_acl_list(char*masklist, char*acl_fname);
     27int add_list_of_files_to_filelist(struct s_node *filelist,
     28                                  char *list_of_files_fname, bool flag_em);
     29void show_filelist(struct s_node *node);
     30int get_fattr_list(char *filelist, char *fattr_fname);
     31int get_acl_list(char *filelist, char *acl_fname);
     32int set_fattr_list(char *masklist, char *fattr_fname);
     33int set_acl_list(char *masklist, char *acl_fname);
  • trunk/mondo/mondo/common/libmondo-files-EXT.h

    r30 r59  
    44#include <unistd.h>
    55
    6 extern unsigned int updcrc (unsigned int crc, unsigned int c);
    7 extern unsigned int updcrcr (unsigned int crc, unsigned int c);
    8 extern char *calc_checksum_of_file (char *filename);
    9 extern char *calc_file_ugly_minichecksum (char *curr_fname);
    10 extern long count_lines_in_file (char *filename);
    11 extern bool does_file_exist (char *filename);
    12 extern void exclude_nonexistent_files (char *inout);
    13 extern int figure_out_kernel_path_interactively_if_necessary(char*kernel);
    14 extern char *find_home_of_exe (char *fname);
    15 extern int get_trackno_from_logfile (char *logfile);
    16 extern int grab_percentage_from_last_line_of_file (char *filename);
    17 extern char *last_line_of_file (char *filename);
    18 extern long long length_of_file (char *filename);
    19 extern int make_checksum_list_file (char *filelist, char *cksumlist, char *comppath);
    20 extern int make_hole_for_file (char *outfile_fname);
    21 extern void make_list_of_files_to_ignore (char *ignorefiles_fname, char *filelist_fname,
    22                   char *cklist_fname);
    23 extern long noof_lines_that_match_wildcard (char *filelist_fname, char *wildcard);
    24 extern void register_pid(pid_t pid, char*name_str);
    25 extern long long space_occupied_by_cd (char *mountpt);
    26 extern int whine_if_not_found (char *fname);
    27 extern int write_one_liner_data_file (char *fname, char *contents);
     6extern unsigned int updcrc(unsigned int crc, unsigned int c);
     7extern unsigned int updcrcr(unsigned int crc, unsigned int c);
     8extern char *calc_checksum_of_file(char *filename);
     9extern char *calc_file_ugly_minichecksum(char *curr_fname);
     10extern long count_lines_in_file(char *filename);
     11extern bool does_file_exist(char *filename);
     12extern void exclude_nonexistent_files(char *inout);
     13extern int figure_out_kernel_path_interactively_if_necessary(char *kernel);
     14extern char *find_home_of_exe(char *fname);
     15extern int get_trackno_from_logfile(char *logfile);
     16extern int grab_percentage_from_last_line_of_file(char *filename);
     17extern char *last_line_of_file(char *filename);
     18extern long long length_of_file(char *filename);
     19extern int make_checksum_list_file(char *filelist, char *cksumlist,
     20                                   char *comppath);
     21extern int make_hole_for_file(char *outfile_fname);
     22extern void make_list_of_files_to_ignore(char *ignorefiles_fname,
     23                                         char *filelist_fname,
     24                                         char *cklist_fname);
     25extern long noof_lines_that_match_wildcard(char *filelist_fname,
     26                                           char *wildcard);
     27extern void register_pid(pid_t pid, char *name_str);
     28extern long long space_occupied_by_cd(char *mountpt);
     29extern int whine_if_not_found(char *fname);
     30extern int write_one_liner_data_file(char *fname, char *contents);
    2831
    2932
    3033
    31 extern long size_of_all_biggiefiles_K (struct s_bkpinfo *bkpinfo);
    32 extern void copy_mondo_and_mindi_stuff_to_scratchdir (struct s_bkpinfo *bkpinfo);
    33 extern void store_nfs_config (struct s_bkpinfo *bkpinfo);
     34extern long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo);
     35extern void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo
     36                                                     *bkpinfo);
     37extern void store_nfs_config(struct s_bkpinfo *bkpinfo);
    3438
    3539
    36 extern void estimate_noof_media_required (struct s_bkpinfo *bkpinfo,long);
     40extern void estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long);
    3741
    38 extern bool is_this_file_compressed (char*);
     42extern bool is_this_file_compressed(char *);
    3943
    4044
    4145
    42 extern int make_hole_for_dir (char*outdir_fname);
     46extern int make_hole_for_dir(char *outdir_fname);
    4347
    44 extern long size_of_partition_in_mountlist_K(char*tmpdir, char*dev);
     48extern long size_of_partition_in_mountlist_K(char *tmpdir, char *dev);
    4549
    46 extern int make_grub_install_scriptlet(char*outfile);
    47 extern int read_one_liner_data_file (char *fname, char *contents);
    48 extern int mode_of_file(char*fname);
    49 
    50 
     50extern int make_grub_install_scriptlet(char *outfile);
     51extern int read_one_liner_data_file(char *fname, char *contents);
     52extern int mode_of_file(char *fname);
  • trunk/mondo/mondo/common/libmondo-files.c

    r30 r59  
    11/* libmondo-files.c                                  file manipulation
    2    $Id: libmondo-files.c,v 1.5 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33.
    44
     
    9797
    9898/*@unused@*/
    99 //static char cvsid[] = "$Id: libmondo-files.c,v 1.5 2004/06/10 15:29:12 hugo Exp $";
     99//static char cvsid[] = "$Id$";
    100100
    101101extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
     
    114114 * @note The returned string points to static storage that will be overwritten with each call.
    115115 */
    116 char *
    117 calc_checksum_of_file (char *filename)
    118 {
    119     /*@ buffers ******************************************************/
    120   static char output[MAX_STR_LEN];
    121   char command[MAX_STR_LEN*2];
    122   char tmp[MAX_STR_LEN];
    123 
    124     /*@ pointers *****************************************************/
    125   char *p;
    126   FILE *fin;
    127 
    128     /*@ initialize pointers ******************************************/
    129 
    130   p = output;
    131 
    132     /*@***************************************************************/
    133 
    134   assert_string_is_neither_NULL_nor_zerolength(filename);
    135   if (does_file_exist (filename))
    136     {
    137       sprintf (command, "md5sum \"%s\"", filename);
    138       fin = popen (command, "r");
    139       if (fin)
    140     {
    141       (void) fgets (output, MAX_STR_LEN, fin);
    142       p = strchr (output, ' ');
    143       paranoid_pclose (fin);
    144     }
    145     }
    146   else
    147     {
    148       sprintf (tmp, "File '%s' not found; cannot calc checksum", filename);
    149       log_it (tmp);
    150     }
    151   if (p)
    152     {
    153       *p = '\0';
    154     }
    155   return (output);
     116char *calc_checksum_of_file(char *filename)
     117{
     118    /*@ buffers ***************************************************** */
     119    static char output[MAX_STR_LEN];
     120    char command[MAX_STR_LEN * 2];
     121    char tmp[MAX_STR_LEN];
     122
     123    /*@ pointers **************************************************** */
     124    char *p;
     125    FILE *fin;
     126
     127    /*@ initialize pointers ***************************************** */
     128
     129    p = output;
     130
     131    /*@************************************************************** */
     132
     133    assert_string_is_neither_NULL_nor_zerolength(filename);
     134    if (does_file_exist(filename)) {
     135        sprintf(command, "md5sum \"%s\"", filename);
     136        fin = popen(command, "r");
     137        if (fin) {
     138            (void) fgets(output, MAX_STR_LEN, fin);
     139            p = strchr(output, ' ');
     140            paranoid_pclose(fin);
     141        }
     142    } else {
     143        sprintf(tmp, "File '%s' not found; cannot calc checksum",
     144                filename);
     145        log_it(tmp);
     146    }
     147    if (p) {
     148        *p = '\0';
     149    }
     150    return (output);
    156151}
    157152
     
    164159 * @note The returned string points to static storage that will be overwritten with each call.
    165160 */
    166 char *
    167 calc_file_ugly_minichecksum (char *curr_fname)
    168 {
    169 
    170     /*@ buffers ******************************************************/
    171   static char curr_cksum[1000];
    172 
    173     /*@ pointers *****************************************************/
    174 
    175     /*@ structures ***************************************************/
    176   struct stat buf;
    177 
    178   /*@ initialize data ****************************************************/
    179   curr_cksum[0] = '\0';
    180 
    181     /*@***************************************************************/
    182 
    183   assert_string_is_neither_NULL_nor_zerolength(curr_fname);
    184   if (lstat (curr_fname, &buf))
    185     {
    186       return (curr_cksum); // empty
    187     }
    188 
    189   sprintf (curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size),
    190        (long) (buf.st_mtime), (long) (buf.st_ctime));
    191   return (curr_cksum);
     161char *calc_file_ugly_minichecksum(char *curr_fname)
     162{
     163
     164    /*@ buffers ***************************************************** */
     165    static char curr_cksum[1000];
     166
     167    /*@ pointers **************************************************** */
     168
     169    /*@ structures ************************************************** */
     170    struct stat buf;
     171
     172    /*@ initialize data *************************************************** */
     173    curr_cksum[0] = '\0';
     174
     175    /*@************************************************************** */
     176
     177    assert_string_is_neither_NULL_nor_zerolength(curr_fname);
     178    if (lstat(curr_fname, &buf)) {
     179        return (curr_cksum);    // empty
     180    }
     181
     182    sprintf(curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size),
     183            (long) (buf.st_mtime), (long) (buf.st_ctime));
     184    return (curr_cksum);
    192185}
    193186
     
    200193 * @bug This function uses the shell and "wc -l"; it should probably be rewritten in C.
    201194 */
    202 long
    203 count_lines_in_file (char *filename)
    204 {
    205 
    206     /*@ buffers ******************************************************/
    207   char command[MAX_STR_LEN*2];
    208   char incoming[MAX_STR_LEN];
    209   char tmp[MAX_STR_LEN];
    210 
    211     /*@ long *********************************************************/
    212   long noof_lines = -1L;
    213 
    214     /*@ pointers *****************************************************/
    215   FILE *fin;
    216 
    217   /*@ initialize [0] to null *********************************************/
    218   incoming[0] = '\0';
    219 
    220   assert_string_is_neither_NULL_nor_zerolength(filename);
    221   if (!does_file_exist (filename))
    222     {
    223       sprintf (tmp,
    224            "%s does not exist, so I cannot found the number of lines in it",
    225            filename);
    226       log_it (tmp);
    227       return (0);
    228     }
    229   sprintf (command, "cat %s | wc -l", filename);
    230   if (!does_file_exist(filename)) { return(-1); }
    231   fin = popen (command, "r");
    232   if (fin)
    233     {
    234       if (feof (fin))
    235     {
    236       noof_lines = 0;
    237     }
    238       else
    239     {
    240       (void) fgets (incoming, MAX_STR_LEN - 1, fin);
    241       while (strlen (incoming) > 0
    242          && incoming[strlen (incoming) - 1] < 32)
    243         {
    244           incoming[strlen (incoming) - 1] = '\0';
    245         }
    246       noof_lines = atol (incoming);
    247     }
    248       paranoid_pclose (fin);
    249     }
    250   return (noof_lines);
     195long count_lines_in_file(char *filename)
     196{
     197
     198    /*@ buffers ***************************************************** */
     199    char command[MAX_STR_LEN * 2];
     200    char incoming[MAX_STR_LEN];
     201    char tmp[MAX_STR_LEN];
     202
     203    /*@ long ******************************************************** */
     204    long noof_lines = -1L;
     205
     206    /*@ pointers **************************************************** */
     207    FILE *fin;
     208
     209    /*@ initialize [0] to null ******************************************** */
     210    incoming[0] = '\0';
     211
     212    assert_string_is_neither_NULL_nor_zerolength(filename);
     213    if (!does_file_exist(filename)) {
     214        sprintf(tmp,
     215                "%s does not exist, so I cannot found the number of lines in it",
     216                filename);
     217        log_it(tmp);
     218        return (0);
     219    }
     220    sprintf(command, "cat %s | wc -l", filename);
     221    if (!does_file_exist(filename)) {
     222        return (-1);
     223    }
     224    fin = popen(command, "r");
     225    if (fin) {
     226        if (feof(fin)) {
     227            noof_lines = 0;
     228        } else {
     229            (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     230            while (strlen(incoming) > 0
     231                   && incoming[strlen(incoming) - 1] < 32) {
     232                incoming[strlen(incoming) - 1] = '\0';
     233            }
     234            noof_lines = atol(incoming);
     235        }
     236        paranoid_pclose(fin);
     237    }
     238    return (noof_lines);
    251239}
    252240
     
    257245 * @return TRUE if it exists, FALSE otherwise.
    258246 */
    259 bool
    260 does_file_exist (char *filename)
    261 {
    262 
    263     /*@ structures ***************************************************/
    264   struct stat buf;
    265 
    266     /*@***************************************************************/
    267 
    268   assert(filename!=NULL);
    269   //  assert_string_is_neither_NULL_nor_zerolength(filename);
    270   if (lstat (filename, &buf))
    271     {
    272       log_msg(20, "%s does not exist", filename);
    273       return (FALSE);
    274     }
    275   else
    276     {
    277       log_msg(20, "%s exists", filename);
    278       return (TRUE);
    279     }
     247bool does_file_exist(char *filename)
     248{
     249
     250    /*@ structures ************************************************** */
     251    struct stat buf;
     252
     253    /*@************************************************************** */
     254
     255    assert(filename != NULL);
     256    //  assert_string_is_neither_NULL_nor_zerolength(filename);
     257    if (lstat(filename, &buf)) {
     258        log_msg(20, "%s does not exist", filename);
     259        return (FALSE);
     260    } else {
     261        log_msg(20, "%s exists", filename);
     262        return (TRUE);
     263    }
    280264}
    281265
     
    292276 * while the modification is in progress.
    293277 */
    294 void
    295 exclude_nonexistent_files (char *inout)
    296 {
    297   char infname[MAX_STR_LEN];
    298   char outfname[MAX_STR_LEN];
    299   char tmp[MAX_STR_LEN];
    300   char incoming[MAX_STR_LEN];
    301 
    302     /*@ int **********************************************************/
    303   int i;
    304 
    305     /*@ pointers *****************************************************/
    306   FILE *fin, *fout;
    307 
    308 
    309  /*@ end vars ************************************************************/
    310 
    311   assert_string_is_neither_NULL_nor_zerolength(inout);
    312   sprintf (infname, "%s.in", inout);
    313   sprintf (outfname, "%s", inout);
    314   sprintf (tmp, "cp -f %s %s", inout, infname);
    315   run_program_and_log_output (tmp, FALSE);
    316   if (!(fin = fopen (infname, "r"))) { log_OS_error("Unable to openin infname"); return; }
    317   if (!(fout = fopen (outfname, "w"))){log_OS_error("Unable to openout outfname"); return; }
    318   for (fgets (incoming, MAX_STR_LEN, fin); !feof (fin);
    319        fgets (incoming, MAX_STR_LEN, fin))
    320     {
    321       i = strlen (incoming) - 1;
    322       if (i >= 0 && incoming[i] < 32)
    323     {
    324       incoming[i] = '\0';
    325     }
    326       if (does_file_exist (incoming))
    327     {
    328       fprintf (fout, "%s\n", incoming);
    329     }
    330       else
    331     {
    332       sprintf (tmp, "Excluding '%s'-nonexistent\n", incoming);
    333       log_it (tmp);
    334     }
    335     }
    336   paranoid_fclose (fout);
    337   paranoid_fclose (fin);
    338   unlink (infname);
     278void exclude_nonexistent_files(char *inout)
     279{
     280    char infname[MAX_STR_LEN];
     281    char outfname[MAX_STR_LEN];
     282    char tmp[MAX_STR_LEN];
     283    char incoming[MAX_STR_LEN];
     284
     285    /*@ int ********************************************************* */
     286    int i;
     287
     288    /*@ pointers **************************************************** */
     289    FILE *fin, *fout;
     290
     291
     292    /*@ end vars *********************************************************** */
     293
     294    assert_string_is_neither_NULL_nor_zerolength(inout);
     295    sprintf(infname, "%s.in", inout);
     296    sprintf(outfname, "%s", inout);
     297    sprintf(tmp, "cp -f %s %s", inout, infname);
     298    run_program_and_log_output(tmp, FALSE);
     299    if (!(fin = fopen(infname, "r"))) {
     300        log_OS_error("Unable to openin infname");
     301        return;
     302    }
     303    if (!(fout = fopen(outfname, "w"))) {
     304        log_OS_error("Unable to openout outfname");
     305        return;
     306    }
     307    for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
     308         fgets(incoming, MAX_STR_LEN, fin)) {
     309        i = strlen(incoming) - 1;
     310        if (i >= 0 && incoming[i] < 32) {
     311            incoming[i] = '\0';
     312        }
     313        if (does_file_exist(incoming)) {
     314            fprintf(fout, "%s\n", incoming);
     315        } else {
     316            sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
     317            log_it(tmp);
     318        }
     319    }
     320    paranoid_fclose(fout);
     321    paranoid_fclose(fin);
     322    unlink(infname);
    339323}
    340324
     
    354338 * @return 0 for success, 1 for failure.
    355339 */
    356 int figure_out_kernel_path_interactively_if_necessary(char*kernel)
    357 {
    358   char tmp[MAX_STR_LEN];
    359 
    360       if (!kernel[0])
    361         { strcpy(kernel, call_program_and_get_last_line_of_output("mindi --findkernel 2> /dev/null")); }
    362       log_it("Calling Mindi with kernel path of '%s'", kernel);
    363       while(!kernel[0])
    364         {
    365           if (!ask_me_yes_or_no("Kernel not found or invalid. Choose another?"))
    366             { return(1); }
    367           if (!popup_and_get_string("Kernel path", "What is the full path and filename of your kernel, please?", kernel, MAX_STR_LEN/4))
    368             { fatal_error("Kernel not found. Please specify with the '-k' flag."); }
    369           sprintf(tmp, "User says kernel is at %s", kernel);
    370           log_it(tmp);
    371         }
    372       return(0);
     340int figure_out_kernel_path_interactively_if_necessary(char *kernel)
     341{
     342    char tmp[MAX_STR_LEN];
     343
     344    if (!kernel[0]) {
     345        strcpy(kernel,
     346               call_program_and_get_last_line_of_output
     347               ("mindi --findkernel 2> /dev/null"));
     348    }
     349    log_it("Calling Mindi with kernel path of '%s'", kernel);
     350    while (!kernel[0]) {
     351        if (!ask_me_yes_or_no
     352            ("Kernel not found or invalid. Choose another?")) {
     353            return (1);
     354        }
     355        if (!popup_and_get_string
     356            ("Kernel path",
     357             "What is the full path and filename of your kernel, please?",
     358             kernel, MAX_STR_LEN / 4)) {
     359            fatal_error
     360                ("Kernel not found. Please specify with the '-k' flag.");
     361        }
     362        sprintf(tmp, "User says kernel is at %s", kernel);
     363        log_it(tmp);
     364    }
     365    return (0);
    373366}
    374367
     
    387380 * to nothing.
    388381 */
    389 char *
    390 find_home_of_exe (char *fname)
    391 {
    392     /*@ buffers **********************/
    393   static char output[MAX_STR_LEN];
    394   char *incoming;
    395   char *command;
    396 
    397   malloc_string(incoming);
    398   malloc_string(command);
    399   incoming[0] = '\0';
    400  /*@********************************/
    401 
    402   assert_string_is_neither_NULL_nor_zerolength(fname);
    403   sprintf (command, "which %s 2> /dev/null", fname);
    404   strcpy (incoming, call_program_and_get_last_line_of_output (command));
    405   if (incoming[0] == '\0')
    406     {
    407       if (system("which file > /dev/null 2> /dev/null"))
     382char *find_home_of_exe(char *fname)
     383{
     384    /*@ buffers ********************* */
     385    static char output[MAX_STR_LEN];
     386    char *incoming;
     387    char *command;
     388
     389    malloc_string(incoming);
     390    malloc_string(command);
     391    incoming[0] = '\0';
     392    /*@******************************* */
     393
     394    assert_string_is_neither_NULL_nor_zerolength(fname);
     395    sprintf(command, "which %s 2> /dev/null", fname);
     396    strcpy(incoming, call_program_and_get_last_line_of_output(command));
     397    if (incoming[0] == '\0') {
     398        if (system("which file > /dev/null 2> /dev/null")) {
     399            paranoid_free(incoming);
     400            paranoid_free(command);
     401            output[0] = '\0';
     402            return (NULL);      // forget it :)
     403        }
     404        sprintf(command,
     405                "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
     406                incoming);
     407        strcpy(incoming,
     408               call_program_and_get_last_line_of_output(command));
     409    }
     410    if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    408411    {
    409       paranoid_free(incoming);
    410       paranoid_free(command);
    411       output[0] = '\0'; return(NULL); // forget it :)
    412     }
    413       sprintf (command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
    414       strcpy (incoming, call_program_and_get_last_line_of_output (command));
    415     }
    416   if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :)
    417     {
    418       sprintf (command, "dirname %s 2> /dev/null", incoming);
    419       strcpy (incoming, call_program_and_get_last_line_of_output (command));
    420     }
    421   strcpy (output, incoming);
    422   if (output[0] != '\0' && does_file_exist(output))
    423     { log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, incoming); }
    424   else
    425     { output[0]='\0'; log_msg(4, "find_home_of_exe() --- Could not find %s", fname); }
    426   paranoid_free(incoming);
    427   paranoid_free(command);
    428   if (!output[0]) { return(NULL); } else { return (output); }
     412        sprintf(command, "dirname %s 2> /dev/null", incoming);
     413        strcpy(incoming,
     414               call_program_and_get_last_line_of_output(command));
     415    }
     416    strcpy(output, incoming);
     417    if (output[0] != '\0' && does_file_exist(output)) {
     418        log_msg(4, "find_home_of_exe () --- Found %s at %s", fname,
     419                incoming);
     420    } else {
     421        output[0] = '\0';
     422        log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
     423    }
     424    paranoid_free(incoming);
     425    paranoid_free(command);
     426    if (!output[0]) {
     427        return (NULL);
     428    } else {
     429        return (output);
     430    }
    429431}
    430432
     
    442444 * @return The number found, or 0 if none.
    443445 */
    444 int
    445 get_trackno_from_logfile (char *logfile)
    446 {
    447 
    448     /*@ pointers **********************************************************/
    449   FILE *fin;
    450 
    451     /*@ int ***************************************************************/
    452   int trackno   = 0;
    453   size_t len    = 0;
    454 
    455     /*@ buffer *************************************************************/
    456   char datablock[32701];
    457 
    458   assert_string_is_neither_NULL_nor_zerolength(logfile);
    459   if (!(fin = fopen (logfile, "r"))) { log_OS_error("Unable to open logfile"); fatal_error("Unable to open logfile to read trackno"); }
    460   len = fread (datablock, 1, 32700, fin);
    461   paranoid_fclose (fin);
    462   if (len <= 0)
    463     {
    464       return (0);
    465     }
    466   for (; len > 0 && !isdigit (datablock[len - 1]); len--);
    467   datablock[len--] = '\0';
    468   for (; len > 0 && isdigit (datablock[len - 1]); len--);
    469   trackno = atoi (datablock + len);
    470   /*
    471      sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
    472      log_it(tmp);
    473    */
    474   return (trackno);
     446int get_trackno_from_logfile(char *logfile)
     447{
     448
     449    /*@ pointers ********************************************************* */
     450    FILE *fin;
     451
     452    /*@ int ************************************************************** */
     453    int trackno = 0;
     454    size_t len = 0;
     455
     456    /*@ buffer ************************************************************ */
     457    char datablock[32701];
     458
     459    assert_string_is_neither_NULL_nor_zerolength(logfile);
     460    if (!(fin = fopen(logfile, "r"))) {
     461        log_OS_error("Unable to open logfile");
     462        fatal_error("Unable to open logfile to read trackno");
     463    }
     464    len = fread(datablock, 1, 32700, fin);
     465    paranoid_fclose(fin);
     466    if (len <= 0) {
     467        return (0);
     468    }
     469    for (; len > 0 && !isdigit(datablock[len - 1]); len--);
     470    datablock[len--] = '\0';
     471    for (; len > 0 && isdigit(datablock[len - 1]); len--);
     472    trackno = atoi(datablock + len);
     473    /*
     474       sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
     475       log_it(tmp);
     476     */
     477    return (trackno);
    475478}
    476479
     
    487490 * @return The percentage found, or 0 for error.
    488491 */
    489 int
    490 grab_percentage_from_last_line_of_file (char *filename)
    491 {
    492 
    493     /*@ buffers ******************************************************/
    494   char tmp[MAX_STR_LEN];
    495   char lastline[MAX_STR_LEN];
    496   char command[MAX_STR_LEN];
    497     /*@ pointers *****************************************************/
    498   char *p;
    499 
    500     /*@ int's ********************************************************/
    501   int i;
    502 
    503   for(i=NOOF_ERR_LINES-1; i>=0 && !strstr(err_log_lines[i], "% Done") && !strstr(err_log_lines[i], "% done"); i--);
    504   if (i<0)
    505     {
    506       sprintf(command, "tail -n3 %s | fgrep -i \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');
    507       strcpy(lastline, call_program_and_get_last_line_of_output(command));
    508       if (!lastline[0])
    509     {
    510       return(0);
    511     }
    512     }
    513   else
    514     {
    515       strcpy(lastline, err_log_lines[i]);
    516     }
    517 
    518   p = strrchr(lastline, '%');
    519   if (p) { *p='\0'; }
     492int grab_percentage_from_last_line_of_file(char *filename)
     493{
     494
     495    /*@ buffers ***************************************************** */
     496    char tmp[MAX_STR_LEN];
     497    char lastline[MAX_STR_LEN];
     498    char command[MAX_STR_LEN];
     499    /*@ pointers **************************************************** */
     500    char *p;
     501
     502    /*@ int's ******************************************************* */
     503    int i;
     504
     505    for (i = NOOF_ERR_LINES - 1;
     506         i >= 0 && !strstr(err_log_lines[i], "% Done")
     507         && !strstr(err_log_lines[i], "% done"); i--);
     508    if (i < 0) {
     509        sprintf(command,
     510                "tail -n3 %s | fgrep -i \"%c\" | tail -n1 | awk '{print $0;}'",
     511                filename, '%');
     512        strcpy(lastline,
     513               call_program_and_get_last_line_of_output(command));
     514        if (!lastline[0]) {
     515            return (0);
     516        }
     517    } else {
     518        strcpy(lastline, err_log_lines[i]);
     519    }
     520
     521    p = strrchr(lastline, '%');
     522    if (p) {
     523        *p = '\0';
     524    }
    520525//  log_msg(2, "lastline='%s', ", p, lastline);
    521   if (!p)
    522     {
    523       return (0);
    524     }
    525   *p = '\0';
    526   for (p --; *p != ' ' && p != lastline; p--);
    527   if (p != lastline)
    528     {
    529       p++;
    530     }
    531   i = atoi (p);
    532 
    533      sprintf(tmp,"'%s' --> %d",p,i);
     526    if (!p) {
     527        return (0);
     528    }
     529    *p = '\0';
     530    for (p--; *p != ' ' && p != lastline; p--);
     531    if (p != lastline) {
     532        p++;
     533    }
     534    i = atoi(p);
     535
     536    sprintf(tmp, "'%s' --> %d", p, i);
    534537//     log_to_screen(tmp);
    535538
    536   return (i);
     539    return (i);
    537540}
    538541
     
    547550 * @note The returned string points to static storage that will be overwritten with each call.
    548551 */
    549 char *
    550 last_line_of_file (char *filename)
    551 {
    552     /*@ buffers ******************************************************/
    553   static char output[MAX_STR_LEN];
    554   static char command[MAX_STR_LEN*2];
    555   static char tmp[MAX_STR_LEN];
    556 
    557     /*@ pointers *****************************************************/
    558   FILE *fin;
    559 
    560     /*@ end vars *****************************************************/
    561 
    562   if (!does_file_exist (filename))
    563     {
    564       sprintf (tmp, "Tring to get last line of nonexistent file (%s)",
    565            filename);
    566       log_it (tmp);
    567       output[0] = '\0';
    568       return (output);
    569     }
    570   sprintf (command, "cat %s | tail -n1", filename);
    571   fin = popen (command, "r");
    572   (void) fgets (output, MAX_STR_LEN, fin);
    573   paranoid_pclose (fin);
    574   while (strlen (output) > 0 && output[strlen (output) - 1] < 32)
    575     {
    576       output[strlen (output) - 1] = '\0';
    577     }
    578   return (output);
     552char *last_line_of_file(char *filename)
     553{
     554    /*@ buffers ***************************************************** */
     555    static char output[MAX_STR_LEN];
     556    static char command[MAX_STR_LEN * 2];
     557    static char tmp[MAX_STR_LEN];
     558
     559    /*@ pointers **************************************************** */
     560    FILE *fin;
     561
     562    /*@ end vars **************************************************** */
     563
     564    if (!does_file_exist(filename)) {
     565        sprintf(tmp, "Tring to get last line of nonexistent file (%s)",
     566                filename);
     567        log_it(tmp);
     568        output[0] = '\0';
     569        return (output);
     570    }
     571    sprintf(command, "cat %s | tail -n1", filename);
     572    fin = popen(command, "r");
     573    (void) fgets(output, MAX_STR_LEN, fin);
     574    paranoid_pclose(fin);
     575    while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
     576        output[strlen(output) - 1] = '\0';
     577    }
     578    return (output);
    579579}
    580580
     
    584584 * @return The length of the file, or -1 for error.
    585585 */
    586 long long
    587 length_of_file (char *filename)
    588 {
    589     /*@ pointers ****************************************************/
    590   FILE *fin;
    591 
    592     /*@ long long **************************************************/
    593   long long length;
    594 
    595   fin = fopen (filename, "r");
    596   if (!fin)
    597     {
    598       log_it("filename=%s", filename);
    599       log_OS_error("Unable to openin filename");
    600       return (-1);
    601     }
    602   fseek (fin, 0, SEEK_END);
    603   length = ftell (fin);
    604   paranoid_fclose (fin);
    605   return (length);
     586long long length_of_file(char *filename)
     587{
     588    /*@ pointers *************************************************** */
     589    FILE *fin;
     590
     591    /*@ long long ************************************************* */
     592    long long length;
     593
     594    fin = fopen(filename, "r");
     595    if (!fin) {
     596        log_it("filename=%s", filename);
     597        log_OS_error("Unable to openin filename");
     598        return (-1);
     599    }
     600    fseek(fin, 0, SEEK_END);
     601    length = ftell(fin);
     602    paranoid_fclose(fin);
     603    return (length);
    606604}
    607605
     
    613611 */
    614612int
    615 make_checksum_list_file (char *filelist, char *cksumlist, char *comppath)
    616 {
    617     /*@ pointers *****************************************************/
    618   FILE *fin;
    619   FILE *fout;
    620 
    621     /*@ int   ********************************************************/
    622   int percentage;
    623   int i;
    624   int counter = 0;
    625 
    626     /*@ buffer *******************************************************/
    627   char stub_fname[1000];
    628   char curr_fname[1000];
    629   char curr_cksum[1000];
    630   char tmp[1000];
    631 
    632         /*@ long [long] **************************************************/
    633   long long filelist_length;
    634   long curr_pos;
    635   long start_time;
    636   long current_time;
    637   long time_taken;
    638   long time_remaining;
    639 
    640     /*@ end vars ****************************************************/
    641 
    642   start_time = get_time ();
    643   filelist_length = length_of_file (filelist);
    644   sprintf (tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
    645   log_it (tmp);
    646   fin = fopen (filelist, "r");
    647   if (fin == NULL)
    648     {
    649       log_OS_error ("Unable to fopen-in filelist");
    650       log_to_screen ("Can't open filelist");
    651       return (1);
    652     }
    653   fout = fopen (cksumlist, "w");
    654   if (fout == NULL)
    655     {
    656       log_OS_error ("Unable to openout cksumlist");
    657       paranoid_fclose (fin);
    658       log_to_screen ("Can't open checksum list");
    659       return (1);
    660     }
    661   for (fgets (stub_fname, 999, fin); !feof (fin);
    662        fgets (stub_fname, 999, fin))
    663     {
    664       if (stub_fname[(i = strlen (stub_fname) - 1)] < 32)
    665     {
    666       stub_fname[i] = '\0';
    667     }
    668       sprintf (tmp, "%s%s", comppath, stub_fname);
    669       strcpy (curr_fname, tmp + 1);
    670       strcpy (curr_cksum, calc_file_ugly_minichecksum (curr_fname));
    671       fprintf (fout, "%s\t%s\n", curr_fname, curr_cksum);
    672       if (counter++ > 12)
    673     {
    674       current_time = get_time ();
    675       counter = 0;
    676       curr_fname[37] = '\0';
    677       curr_pos = ftell (fin) / 1024;
    678       percentage = (int) (curr_pos * 100 / filelist_length);
    679       time_taken = current_time - start_time;
    680       if (percentage == 0)
    681         {
    682           /*              printf("%0d%% done      \r",percentage); */
    683         }
    684       else
    685         {
    686           time_remaining =
    687         time_taken * 100 / (long) (percentage) - time_taken;
    688           sprintf (tmp,
    689                "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
    690                percentage, (int) (time_taken / 60),
    691                (int) (time_taken % 60), (int) (time_remaining / 60),
    692                (int) (time_remaining % 60), curr_fname);
    693           log_to_screen (tmp);
    694         }
    695       sync ();
    696     }
    697     }
    698   paranoid_fclose (fout);
    699   paranoid_fclose (fin);
    700   log_it ("Done.");
    701   return (0);
     613make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)
     614{
     615    /*@ pointers **************************************************** */
     616    FILE *fin;
     617    FILE *fout;
     618
     619    /*@ int   ******************************************************* */
     620    int percentage;
     621    int i;
     622    int counter = 0;
     623
     624    /*@ buffer ****************************************************** */
     625    char stub_fname[1000];
     626    char curr_fname[1000];
     627    char curr_cksum[1000];
     628    char tmp[1000];
     629
     630    /*@ long [long] ************************************************* */
     631    long long filelist_length;
     632    long curr_pos;
     633    long start_time;
     634    long current_time;
     635    long time_taken;
     636    long time_remaining;
     637
     638    /*@ end vars *************************************************** */
     639
     640    start_time = get_time();
     641    filelist_length = length_of_file(filelist);
     642    sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
     643    log_it(tmp);
     644    fin = fopen(filelist, "r");
     645    if (fin == NULL) {
     646        log_OS_error("Unable to fopen-in filelist");
     647        log_to_screen("Can't open filelist");
     648        return (1);
     649    }
     650    fout = fopen(cksumlist, "w");
     651    if (fout == NULL) {
     652        log_OS_error("Unable to openout cksumlist");
     653        paranoid_fclose(fin);
     654        log_to_screen("Can't open checksum list");
     655        return (1);
     656    }
     657    for (fgets(stub_fname, 999, fin); !feof(fin);
     658         fgets(stub_fname, 999, fin)) {
     659        if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {
     660            stub_fname[i] = '\0';
     661        }
     662        sprintf(tmp, "%s%s", comppath, stub_fname);
     663        strcpy(curr_fname, tmp + 1);
     664        strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
     665        fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
     666        if (counter++ > 12) {
     667            current_time = get_time();
     668            counter = 0;
     669            curr_fname[37] = '\0';
     670            curr_pos = ftell(fin) / 1024;
     671            percentage = (int) (curr_pos * 100 / filelist_length);
     672            time_taken = current_time - start_time;
     673            if (percentage == 0) {
     674                /*              printf("%0d%% done      \r",percentage); */
     675            } else {
     676                time_remaining =
     677                    time_taken * 100 / (long) (percentage) - time_taken;
     678                sprintf(tmp,
     679                        "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
     680                        percentage, (int) (time_taken / 60),
     681                        (int) (time_taken % 60),
     682                        (int) (time_remaining / 60),
     683                        (int) (time_remaining % 60), curr_fname);
     684                log_to_screen(tmp);
     685            }
     686            sync();
     687        }
     688    }
     689    paranoid_fclose(fout);
     690    paranoid_fclose(fin);
     691    log_it("Done.");
     692    return (0);
    702693}
    703694
     
    708699 * @return The return value of @c mkdir.
    709700 */
    710 int make_hole_for_dir (char*outdir_fname)
    711 {
    712   char tmp[MAX_STR_LEN*2];
    713   int res=0;
    714 
    715   assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    716   sprintf(tmp, "mkdir -p %s", outdir_fname);
    717   res = system(tmp);
    718   return(res);
     701int make_hole_for_dir(char *outdir_fname)
     702{
     703    char tmp[MAX_STR_LEN * 2];
     704    int res = 0;
     705
     706    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
     707    sprintf(tmp, "mkdir -p %s", outdir_fname);
     708    res = system(tmp);
     709    return (res);
    719710}
    720711
     
    726717 * @bug Return value unnecessary.
    727718 */
    728 int
    729 make_hole_for_file (char *outfile_fname)
    730 {
    731     /*@ buffer *******************************************************/
    732   char command[MAX_STR_LEN*2];
    733 
    734     /*@ int  *********************************************************/
    735   int res = 0;
    736 
    737     /*@ end vars ****************************************************/
    738 
    739   assert_string_is_neither_NULL_nor_zerolength(outfile_fname);
    740   assert(!strstr(outfile_fname, MNT_CDROM));
    741   assert(!strstr(outfile_fname, "/dev/cdrom"));
    742   sprintf (command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    743   res += system (command);
    744   sprintf (command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    745   res += system (command);
    746       sprintf (command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    747   res += system (command);
    748   unlink (outfile_fname);
    749   return (0);
     719int make_hole_for_file(char *outfile_fname)
     720{
     721    /*@ buffer ****************************************************** */
     722    char command[MAX_STR_LEN * 2];
     723
     724    /*@ int  ******************************************************** */
     725    int res = 0;
     726
     727    /*@ end vars *************************************************** */
     728
     729    assert_string_is_neither_NULL_nor_zerolength(outfile_fname);
     730    assert(!strstr(outfile_fname, MNT_CDROM));
     731    assert(!strstr(outfile_fname, "/dev/cdrom"));
     732    sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     733    res += system(command);
     734    sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     735    res += system(command);
     736    sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     737    res += system(command);
     738    unlink(outfile_fname);
     739    return (0);
    750740}
    751741
     
    759749 * @return The number of lines matched.
    760750 */
    761 long
    762 noof_lines_that_match_wildcard (char *filelist_fname, char *wildcard)
    763 {
    764     /*@ long ********************************************************/
    765   long matches = 0;
    766 
    767     /*@ pointers ****************************************************/
    768   FILE *fin;
    769 
    770     /*@ buffers *****************************************************/
    771   char incoming[MAX_STR_LEN];
    772 
    773     /*@ end vars ****************************************************/
    774 
    775 
    776   fin = fopen (filelist_fname, "r");
    777 
    778   if (!fin)
    779     {
    780       log_OS_error("Unable to openin filelist_fname");
    781       return (0);
    782     }
    783   (void) fgets (incoming, MAX_STR_LEN - 1, fin);
    784   while (!feof (fin))
    785     {
    786       if (strstr (incoming, wildcard))
    787     {
    788       matches++;
    789     }
    790       (void) fgets (incoming, MAX_STR_LEN - 1, fin);
    791     }
    792   paranoid_fclose (fin);
    793   return (matches);
     751long noof_lines_that_match_wildcard(char *filelist_fname, char *wildcard)
     752{
     753    /*@ long ******************************************************* */
     754    long matches = 0;
     755
     756    /*@ pointers *************************************************** */
     757    FILE *fin;
     758
     759    /*@ buffers **************************************************** */
     760    char incoming[MAX_STR_LEN];
     761
     762    /*@ end vars *************************************************** */
     763
     764
     765    fin = fopen(filelist_fname, "r");
     766
     767    if (!fin) {
     768        log_OS_error("Unable to openin filelist_fname");
     769        return (0);
     770    }
     771    (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     772    while (!feof(fin)) {
     773        if (strstr(incoming, wildcard)) {
     774            matches++;
     775        }
     776        (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     777    }
     778    paranoid_fclose(fin);
     779    return (matches);
    794780}
    795781
     
    804790 * @note This function does not provide support against multiple instances, unless you check for that yourself.
    805791 */
    806 void register_pid(pid_t pid, char*name_str)
    807 {
    808   char tmp[MAX_STR_LEN+1], lockfile_fname[MAX_STR_LEN+1];
    809   int res;
    810   FILE*fin;
    811 
    812   sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);
    813   if (!pid)
    814     {
    815       log_it("Unregistering PID");
    816       if (unlink(lockfile_fname)) { log_it( "Error unregistering PID"); }
    817       return;
    818     }
    819   if (does_file_exist(lockfile_fname))
    820     {
    821       tmp[0]='\0';
    822       if ((fin=fopen(lockfile_fname,"r"))) { (void) fgets(tmp, MAX_STR_LEN, fin); paranoid_fclose(fin); }
    823       else { log_OS_error("Unable to openin lockfile_fname"); }
    824       pid = (pid_t) atol(tmp);
    825       sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int)pid);
    826       res = system(tmp);
    827       if (!res)
    828         {
    829           log_it ("I believe the daemon is already running. If it isn't, please delete %s and try again.", lockfile_fname);
    830         }
    831     }
    832   sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int)getpid(), lockfile_fname);
    833   if (system(tmp)) { fatal_error( "Cannot register PID"); }
     792void register_pid(pid_t pid, char *name_str)
     793{
     794    char tmp[MAX_STR_LEN + 1], lockfile_fname[MAX_STR_LEN + 1];
     795    int res;
     796    FILE *fin;
     797
     798    sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);
     799    if (!pid) {
     800        log_it("Unregistering PID");
     801        if (unlink(lockfile_fname)) {
     802            log_it("Error unregistering PID");
     803        }
     804        return;
     805    }
     806    if (does_file_exist(lockfile_fname)) {
     807        tmp[0] = '\0';
     808        if ((fin = fopen(lockfile_fname, "r"))) {
     809            (void) fgets(tmp, MAX_STR_LEN, fin);
     810            paranoid_fclose(fin);
     811        } else {
     812            log_OS_error("Unable to openin lockfile_fname");
     813        }
     814        pid = (pid_t) atol(tmp);
     815        sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);
     816        res = system(tmp);
     817        if (!res) {
     818            log_it
     819                ("I believe the daemon is already running. If it isn't, please delete %s and try again.",
     820                 lockfile_fname);
     821        }
     822    }
     823    sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),
     824            lockfile_fname);
     825    if (system(tmp)) {
     826        fatal_error("Cannot register PID");
     827    }
    834828}
    835829
     
    842836 * @return The size of the partition in KB.
    843837 */
    844 long size_of_partition_in_mountlist_K(char*tmpdir, char*dev)
    845 {
    846     char command[MAX_STR_LEN];
    847     char mountlist[MAX_STR_LEN];
    848     char sz_res[MAX_STR_LEN];
    849     long file_len_K;
    850            
    851     sprintf(mountlist, "%s/mountlist.txt", tmpdir);
    852     sprintf (command,
    853        "cat %s/mountlist.txt | grep \"%s \" | head -n1 | awk '{print $4;}'",
    854       tmpdir, dev);
    855     log_it (command);
    856     strcpy (sz_res, call_program_and_get_last_line_of_output (command));
    857     file_len_K = atol (sz_res);
    858     log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
    859     return(file_len_K);
     838long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
     839{
     840    char command[MAX_STR_LEN];
     841    char mountlist[MAX_STR_LEN];
     842    char sz_res[MAX_STR_LEN];
     843    long file_len_K;
     844
     845    sprintf(mountlist, "%s/mountlist.txt", tmpdir);
     846    sprintf(command,
     847            "cat %s/mountlist.txt | grep \"%s \" | head -n1 | awk '{print $4;}'",
     848            tmpdir, dev);
     849    log_it(command);
     850    strcpy(sz_res, call_program_and_get_last_line_of_output(command));
     851    file_len_K = atol(sz_res);
     852    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     853    return (file_len_K);
    860854}
    861855
     
    865859 * @return The total size of all biggiefiles in KB.
    866860 */
    867 long
    868 size_of_all_biggiefiles_K (struct s_bkpinfo *bkpinfo)
    869 {
    870     /*@ buffers ******************************************************/
    871   char *fname;
    872   char *biggielist;
    873   char *comment;
    874 
    875     /*@ long *********************************************************/
    876   long scratchL = 0;
    877   long file_len_K;
    878 
    879     /*@ pointers ****************************************************/
    880   FILE *fin=NULL;
    881 
    882     /*@ end vars ****************************************************/
    883 
    884   malloc_string(fname);
    885   malloc_string(biggielist);
    886   malloc_string(comment);
    887   log_it ("Calculating size of all biggiefiles (in total)");
    888   sprintf (biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    889   log_it("biggielist = %s", biggielist);
    890   if (!(fin = fopen (biggielist, "r")))
    891     {
    892       log_OS_error
    893     ("Cannot open biggielist. OK, so estimate is based on filesets only.");
    894     }
    895   else
    896     {
    897       log_msg(4, "Reading it...");
    898       for (fgets (fname, MAX_STR_LEN, fin); !feof (fin);
    899        fgets (fname, MAX_STR_LEN, fin))
    900     {
    901       if (fname[strlen(fname)-1]<=32) { fname[strlen(fname)-1]='\0'; }
    902       if (0 == strncmp (fname, "/dev/", 5))
    903         {
    904           file_len_K = get_phys_size_of_drive(fname)*1024L;
    905         }
    906       else
    907         {
    908           file_len_K = (long) (length_of_file (fname) / 1024);
    909         }
    910           if (file_len_K > 0)
    911         {
    912           scratchL += file_len_K;
    913           log_msg(4, "%s --> %ld K", fname, file_len_K);
    914         }
    915       sprintf (comment, "After adding %s, scratchL+%ld now equals %ld",
    916            fname, file_len_K, scratchL);
    917       log_msg(4, comment);
    918           if (feof(fin)) { break; }
    919     }
    920     }
    921   log_it ("Closing...");
    922   paranoid_fclose (fin);
    923   log_it ("Finished calculating total size of all biggiefiles");
    924   paranoid_free(fname);
    925   paranoid_free(biggielist);
    926   paranoid_free(comment);
    927   return (scratchL);
     861long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo)
     862{
     863    /*@ buffers ***************************************************** */
     864    char *fname;
     865    char *biggielist;
     866    char *comment;
     867
     868    /*@ long ******************************************************** */
     869    long scratchL = 0;
     870    long file_len_K;
     871
     872    /*@ pointers *************************************************** */
     873    FILE *fin = NULL;
     874
     875    /*@ end vars *************************************************** */
     876
     877    malloc_string(fname);
     878    malloc_string(biggielist);
     879    malloc_string(comment);
     880    log_it("Calculating size of all biggiefiles (in total)");
     881    sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     882    log_it("biggielist = %s", biggielist);
     883    if (!(fin = fopen(biggielist, "r"))) {
     884        log_OS_error
     885            ("Cannot open biggielist. OK, so estimate is based on filesets only.");
     886    } else {
     887        log_msg(4, "Reading it...");
     888        for (fgets(fname, MAX_STR_LEN, fin); !feof(fin);
     889             fgets(fname, MAX_STR_LEN, fin)) {
     890            if (fname[strlen(fname) - 1] <= 32) {
     891                fname[strlen(fname) - 1] = '\0';
     892            }
     893            if (0 == strncmp(fname, "/dev/", 5)) {
     894                file_len_K = get_phys_size_of_drive(fname) * 1024L;
     895            } else {
     896                file_len_K = (long) (length_of_file(fname) / 1024);
     897            }
     898            if (file_len_K > 0) {
     899                scratchL += file_len_K;
     900                log_msg(4, "%s --> %ld K", fname, file_len_K);
     901            }
     902            sprintf(comment,
     903                    "After adding %s, scratchL+%ld now equals %ld", fname,
     904                    file_len_K, scratchL);
     905            log_msg(4, comment);
     906            if (feof(fin)) {
     907                break;
     908            }
     909        }
     910    }
     911    log_it("Closing...");
     912    paranoid_fclose(fin);
     913    log_it("Finished calculating total size of all biggiefiles");
     914    paranoid_free(fname);
     915    paranoid_free(biggielist);
     916    paranoid_free(comment);
     917    return (scratchL);
    928918}
    929919
     
    934924 * @return The amount of space occupied in KB.
    935925 */
    936 long long
    937 space_occupied_by_cd (char *mountpt)
    938 {
    939     /*@ buffer *******************************************************/
    940   char tmp[MAX_STR_LEN];
    941   char command[MAX_STR_LEN*2];
    942   long long llres;
    943     /*@ pointers *****************************************************/
    944   char *p;
    945   FILE *fin;
    946 
    947     /*@ end vars ****************************************************/
    948 
    949   sprintf (command, "du -sk %s", mountpt);
    950   fin = popen (command, "r");
    951   (void) fgets (tmp, MAX_STR_LEN, fin);
    952   paranoid_pclose (fin);
    953   p = strchr (tmp, '\t');
    954   if (p)
    955     {
    956       *p = '\0';
    957     }
    958   for(p=tmp,llres=0; *p!='\0'; p++)
    959     {
    960       llres*=10;
    961       llres+=(int)(*p - '0');
    962     }
    963   return (llres);
     926long long space_occupied_by_cd(char *mountpt)
     927{
     928    /*@ buffer ****************************************************** */
     929    char tmp[MAX_STR_LEN];
     930    char command[MAX_STR_LEN * 2];
     931    long long llres;
     932    /*@ pointers **************************************************** */
     933    char *p;
     934    FILE *fin;
     935
     936    /*@ end vars *************************************************** */
     937
     938    sprintf(command, "du -sk %s", mountpt);
     939    fin = popen(command, "r");
     940    (void) fgets(tmp, MAX_STR_LEN, fin);
     941    paranoid_pclose(fin);
     942    p = strchr(tmp, '\t');
     943    if (p) {
     944        *p = '\0';
     945    }
     946    for (p = tmp, llres = 0; *p != '\0'; p++) {
     947        llres *= 10;
     948        llres += (int) (*p - '0');
     949    }
     950    return (llres);
    964951}
    965952
     
    972959 * @ingroup utilityGroup
    973960 */
    974 unsigned int
    975 updcrc (unsigned int crc, unsigned int c)
    976 {
    977   unsigned int tmp;
    978   tmp = (crc >> 8) ^ c;
    979   crc = (crc << 8) ^ crctttab[tmp & 255];
    980   return crc;
     961unsigned int updcrc(unsigned int crc, unsigned int c)
     962{
     963    unsigned int tmp;
     964    tmp = (crc >> 8) ^ c;
     965    crc = (crc << 8) ^ crctttab[tmp & 255];
     966    return crc;
    981967}
    982968
     
    988974 * @ingroup utilityGroup
    989975 */
    990 unsigned int
    991 updcrcr (unsigned int crc, unsigned int c)
    992 {
    993   unsigned int tmp;
    994   tmp = crc ^ c;
    995   crc = (crc >> 8) ^ crc16tab[tmp & 0xff];
    996   return crc;
     976unsigned int updcrcr(unsigned int crc, unsigned int c)
     977{
     978    unsigned int tmp;
     979    tmp = crc ^ c;
     980    crc = (crc >> 8) ^ crc16tab[tmp & 0xff];
     981    return crc;
    997982}
    998983
     
    1006991 * @return 0 if it's found, nonzero if not.
    1007992 */
    1008 int
    1009 whine_if_not_found (char *fname)
    1010 {
    1011     /*@ buffers ****/
    1012   char command[MAX_STR_LEN*2];
    1013   char errorstr[MAX_STR_LEN];
    1014 
    1015 
    1016   sprintf (command, "which %s > /dev/null 2> /dev/null", fname);
    1017   sprintf (errorstr, "Please install '%s'. I cannot find it on your system.",
    1018        fname);
    1019   if (system (command))
    1020     {
    1021       log_to_screen (errorstr);
    1022       log_to_screen
    1023     ("There may be hyperlink at http://www.mondorescue.com which");
    1024       log_to_screen ("will take you to the relevant (missing) package.");
    1025       return (1);
    1026     }
    1027   else
    1028     {
    1029       return (0);
    1030     }
     993int whine_if_not_found(char *fname)
     994{
     995    /*@ buffers *** */
     996    char command[MAX_STR_LEN * 2];
     997    char errorstr[MAX_STR_LEN];
     998
     999
     1000    sprintf(command, "which %s > /dev/null 2> /dev/null", fname);
     1001    sprintf(errorstr,
     1002            "Please install '%s'. I cannot find it on your system.",
     1003            fname);
     1004    if (system(command)) {
     1005        log_to_screen(errorstr);
     1006        log_to_screen
     1007            ("There may be hyperlink at http://www.mondorescue.com which");
     1008        log_to_screen("will take you to the relevant (missing) package.");
     1009        return (1);
     1010    } else {
     1011        return (0);
     1012    }
    10311013}
    10321014
     
    10431025 * @return 0 for success, 1 for failure.
    10441026 */
    1045 int
    1046 write_one_liner_data_file (char *fname, char *contents)
    1047 {
    1048     /*@ pointers ****************************************************/
    1049   FILE *fout;
    1050   int res=0;
    1051 
    1052     /*@ end vars ****************************************************/
    1053 
    1054   assert_string_is_neither_NULL_nor_zerolength(fname);
    1055   if (!contents) { log_it("%d: Warning - writing NULL to %s", __LINE__, fname); }
    1056   if (!(fout = fopen (fname, "w")))
    1057     {
    1058       log_it("fname=%s");
    1059       log_OS_error("Unable to openout fname");
    1060       return (1);
    1061     }
    1062   fprintf (fout, "%s\n", contents);
    1063   paranoid_fclose (fout);
    1064   return (res);
     1027int write_one_liner_data_file(char *fname, char *contents)
     1028{
     1029    /*@ pointers *************************************************** */
     1030    FILE *fout;
     1031    int res = 0;
     1032
     1033    /*@ end vars *************************************************** */
     1034
     1035    assert_string_is_neither_NULL_nor_zerolength(fname);
     1036    if (!contents) {
     1037        log_it("%d: Warning - writing NULL to %s", __LINE__, fname);
     1038    }
     1039    if (!(fout = fopen(fname, "w"))) {
     1040        log_it("fname=%s");
     1041        log_OS_error("Unable to openout fname");
     1042        return (1);
     1043    }
     1044    fprintf(fout, "%s\n", contents);
     1045    paranoid_fclose(fout);
     1046    return (res);
    10651047}
    10661048
     
    10731055 * @return 0 for success, nonzero for failure.
    10741056 */
    1075 int
    1076 read_one_liner_data_file (char *fname, char *contents)
    1077 {
    1078     /*@ pointers ****************************************************/
    1079   FILE *fin;
    1080   int res=0;
    1081   int i;
    1082 
    1083     /*@ end vars ****************************************************/
    1084 
    1085   assert_string_is_neither_NULL_nor_zerolength(fname);
    1086   if (!contents) { log_it("%d: Warning - reading NULL from %s", __LINE__, fname); }
    1087   if (!(fin = fopen (fname, "r")))
    1088     {
    1089       log_it("fname=%s", fname);
    1090       log_OS_error("Unable to openin fname");
    1091       return (1);
    1092     }
    1093   fscanf (fin, "%s\n", contents);
    1094   i = strlen(contents);
    1095   if (i>0 && contents[i-1] < 32) { contents[i-1] = '\0'; }
    1096   paranoid_fclose (fin);
    1097   return (res);
     1057int read_one_liner_data_file(char *fname, char *contents)
     1058{
     1059    /*@ pointers *************************************************** */
     1060    FILE *fin;
     1061    int res = 0;
     1062    int i;
     1063
     1064    /*@ end vars *************************************************** */
     1065
     1066    assert_string_is_neither_NULL_nor_zerolength(fname);
     1067    if (!contents) {
     1068        log_it("%d: Warning - reading NULL from %s", __LINE__, fname);
     1069    }
     1070    if (!(fin = fopen(fname, "r"))) {
     1071        log_it("fname=%s", fname);
     1072        log_OS_error("Unable to openin fname");
     1073        return (1);
     1074    }
     1075    fscanf(fin, "%s\n", contents);
     1076    i = strlen(contents);
     1077    if (i > 0 && contents[i - 1] < 32) {
     1078        contents[i - 1] = '\0';
     1079    }
     1080    paranoid_fclose(fin);
     1081    return (res);
    10981082}
    10991083
     
    11161100 * - @c bkpinfo->tmpdir
    11171101 */
    1118 void
    1119 copy_mondo_and_mindi_stuff_to_scratchdir (struct s_bkpinfo *bkpinfo)
    1120 {
    1121     /*@ Char buffers ***/
    1122   char command[MAX_STR_LEN*2];
    1123   char tmp[MAX_STR_LEN];
    1124   char old_pwd[MAX_STR_LEN];
    1125 
    1126   mvaddstr_and_log_it (g_currentY, 0,
    1127                "Copying Mondo's core files to the scratch directory");
    1128 
    1129   log_msg(4, "g_mondo_home='%s'", g_mondo_home);
    1130   if (strlen(g_mondo_home)<2)
    1131     { find_and_store_mondoarchives_home(g_mondo_home); }
    1132   sprintf (command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
    1133        bkpinfo->scratchdir);
    1134 
    1135   log_msg(4, "command = %s", command);
    1136   if (run_program_and_log_output (command, 1))
    1137     {
    1138       fatal_error ("Failed to copy Mondo's stuff to scratchdir");
    1139     }
    1140 
    1141   sprintf(tmp, "%s/payload.tgz", g_mondo_home);
    1142   if (does_file_exist(tmp))
    1143     {
    1144       log_it("Untarring payload %s to scratchdir %s", tmp, bkpinfo->scratchdir);
    1145       (void) getcwd (old_pwd, MAX_STR_LEN -1);
    1146       chdir (bkpinfo->scratchdir);
    1147       sprintf(command, "tar -zxvf %s", tmp);
    1148       if (run_program_and_log_output(command, FALSE))
    1149         { fatal_error ("Failed to untar payload"); }
    1150       chdir (old_pwd);
    1151     }
    1152 
    1153   sprintf (command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    1154        bkpinfo->scratchdir);
    1155 
    1156   if (run_program_and_log_output (command, FALSE))
    1157     {
    1158       fatal_error ("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
    1159     }
    1160 
    1161   strcpy (tmp,
    1162       call_program_and_get_last_line_of_output ("which mondorestore"));
    1163   if (!tmp[0]) { fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); }
    1164   sprintf (command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
    1165   if (run_program_and_log_output (command, FALSE))
    1166     {
    1167       fatal_error ("Failed to copy mondorestore to tmpdir");
    1168     }
    1169 
    1170   sprintf (command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    1171   paranoid_system (command);
    1172 
    1173   if (bkpinfo->postnuke_tarball[0])
    1174     {
    1175       sprintf (command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    1176       if (run_program_and_log_output (command, FALSE))
    1177         { fatal_error("Unable to copy post-nuke tarball to tmpdir"); }
    1178     }
    1179 
    1180 
    1181   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
     1102void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo *bkpinfo)
     1103{
     1104    /*@ Char buffers ** */
     1105    char command[MAX_STR_LEN * 2];
     1106    char tmp[MAX_STR_LEN];
     1107    char old_pwd[MAX_STR_LEN];
     1108
     1109    mvaddstr_and_log_it(g_currentY, 0,
     1110                        "Copying Mondo's core files to the scratch directory");
     1111
     1112    log_msg(4, "g_mondo_home='%s'", g_mondo_home);
     1113    if (strlen(g_mondo_home) < 2) {
     1114        find_and_store_mondoarchives_home(g_mondo_home);
     1115    }
     1116    sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
     1117            bkpinfo->scratchdir);
     1118
     1119    log_msg(4, "command = %s", command);
     1120    if (run_program_and_log_output(command, 1)) {
     1121        fatal_error("Failed to copy Mondo's stuff to scratchdir");
     1122    }
     1123
     1124    sprintf(tmp, "%s/payload.tgz", g_mondo_home);
     1125    if (does_file_exist(tmp)) {
     1126        log_it("Untarring payload %s to scratchdir %s", tmp,
     1127               bkpinfo->scratchdir);
     1128        (void) getcwd(old_pwd, MAX_STR_LEN - 1);
     1129        chdir(bkpinfo->scratchdir);
     1130        sprintf(command, "tar -zxvf %s", tmp);
     1131        if (run_program_and_log_output(command, FALSE)) {
     1132            fatal_error("Failed to untar payload");
     1133        }
     1134        chdir(old_pwd);
     1135    }
     1136
     1137    sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
     1138            bkpinfo->scratchdir);
     1139
     1140    if (run_program_and_log_output(command, FALSE)) {
     1141        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
     1142    }
     1143
     1144    strcpy(tmp,
     1145           call_program_and_get_last_line_of_output("which mondorestore"));
     1146    if (!tmp[0]) {
     1147        fatal_error
     1148            ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
     1149    }
     1150    sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1151    if (run_program_and_log_output(command, FALSE)) {
     1152        fatal_error("Failed to copy mondorestore to tmpdir");
     1153    }
     1154
     1155    sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1156    paranoid_system(command);
     1157
     1158    if (bkpinfo->postnuke_tarball[0]) {
     1159        sprintf(command, "cp -f %s %s/post-nuke.tgz",
     1160                bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
     1161        if (run_program_and_log_output(command, FALSE)) {
     1162            fatal_error("Unable to copy post-nuke tarball to tmpdir");
     1163        }
     1164    }
     1165
     1166
     1167    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    11821168}
    11831169
     
    11941180 * - @c tmpdir
    11951181 */
    1196 void
    1197 store_nfs_config (struct s_bkpinfo *bkpinfo)
    1198 {
    1199 
    1200     /*@ buffers *********/
    1201   char outfile[MAX_STR_LEN];
    1202   char nfs_dev[MAX_STR_LEN];
    1203   char nfs_mount[MAX_STR_LEN];
    1204   char nfs_client_ipaddr[MAX_STR_LEN];
    1205   char nfs_server_ipaddr[MAX_STR_LEN];
    1206   char tmp[MAX_STR_LEN];
    1207   char command[MAX_STR_LEN*2];
    1208 
    1209     /*@ pointers ******/
    1210   char *p;
    1211   FILE *fout;
    1212 
    1213 
    1214 
    1215   log_it ("Storing NFS configuration");
    1216   strcpy (tmp, bkpinfo->nfs_mount);
    1217   p = strchr (tmp, ':');
    1218   if (!p)
    1219     {
    1220       fatal_error
    1221     ("NFS mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
    1222     }
    1223   *(p++) = '\0';
    1224   strcpy (nfs_server_ipaddr, tmp);
    1225   strcpy (nfs_mount, p);
    1226   sprintf (command,
    1227        "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1228   strcpy (nfs_dev, call_program_and_get_last_line_of_output (command));
    1229   sprintf (command,
    1230        "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1231   strcpy (nfs_client_ipaddr,
    1232       call_program_and_get_last_line_of_output (command));
    1233   sprintf (tmp, "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s",
    1234        nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount);
    1235   if (strlen (nfs_dev) < 2)
    1236     {
    1237       fatal_error
    1238     ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified.");
    1239     }
    1240   sprintf (outfile, "%s/start-nfs", bkpinfo->tmpdir);
    1241   sprintf (tmp, "outfile = %s", outfile);
    1242   log_it (tmp);
    1243   if (!(fout = fopen (outfile, "w")))
    1244     {
    1245       fatal_error ("Cannot store NFS config");
    1246     }
    1247   fprintf (fout, "ifconfig lo 127.0.0.1  # config loopback\n");
    1248   fprintf (fout, "ifconfig %s %s; # config client\n", nfs_dev,
    1249        nfs_client_ipaddr);
    1250   fprintf (fout, "ping -c1 %s; # ping server\n", nfs_server_ipaddr);
    1251   fprintf (fout, "mount -t nfs -o nolock %s /tmp/isodir\n", bkpinfo->nfs_mount);
    1252   fprintf (fout, "exit 0\n");
    1253   paranoid_fclose (fout);
    1254   chmod (outfile, 0777);
    1255   make_hole_for_dir( "/var/cache/mondo-archive");
     1182void store_nfs_config(struct s_bkpinfo *bkpinfo)
     1183{
     1184
     1185    /*@ buffers ******** */
     1186    char outfile[MAX_STR_LEN];
     1187    char nfs_dev[MAX_STR_LEN];
     1188    char nfs_mount[MAX_STR_LEN];
     1189    char nfs_client_ipaddr[MAX_STR_LEN];
     1190    char nfs_server_ipaddr[MAX_STR_LEN];
     1191    char tmp[MAX_STR_LEN];
     1192    char command[MAX_STR_LEN * 2];
     1193
     1194    /*@ pointers ***** */
     1195    char *p;
     1196    FILE *fout;
     1197
     1198
     1199
     1200    log_it("Storing NFS configuration");
     1201    strcpy(tmp, bkpinfo->nfs_mount);
     1202    p = strchr(tmp, ':');
     1203    if (!p) {
     1204        fatal_error
     1205            ("NFS mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
     1206    }
     1207    *(p++) = '\0';
     1208    strcpy(nfs_server_ipaddr, tmp);
     1209    strcpy(nfs_mount, p);
     1210    sprintf(command,
     1211            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
     1212    strcpy(nfs_dev, call_program_and_get_last_line_of_output(command));
     1213    sprintf(command,
     1214            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
     1215    strcpy(nfs_client_ipaddr,
     1216           call_program_and_get_last_line_of_output(command));
     1217    sprintf(tmp,
     1218            "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s",
     1219            nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount);
     1220    if (strlen(nfs_dev) < 2) {
     1221        fatal_error
     1222            ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified.");
     1223    }
     1224    sprintf(outfile, "%s/start-nfs", bkpinfo->tmpdir);
     1225    sprintf(tmp, "outfile = %s", outfile);
     1226    log_it(tmp);
     1227    if (!(fout = fopen(outfile, "w"))) {
     1228        fatal_error("Cannot store NFS config");
     1229    }
     1230    fprintf(fout, "ifconfig lo 127.0.0.1  # config loopback\n");
     1231    fprintf(fout, "ifconfig %s %s; # config client\n", nfs_dev,
     1232            nfs_client_ipaddr);
     1233    fprintf(fout, "ping -c1 %s; # ping server\n", nfs_server_ipaddr);
     1234    fprintf(fout, "mount -t nfs -o nolock %s /tmp/isodir\n",
     1235            bkpinfo->nfs_mount);
     1236    fprintf(fout, "exit 0\n");
     1237    paranoid_fclose(fout);
     1238    chmod(outfile, 0777);
     1239    make_hole_for_dir("/var/cache/mondo-archive");
    12561240
    12571241//  paranoid_system ("mkdir -p /var/cache/mondo-archive 2> /dev/null");
    12581242
    1259   sprintf (tmp, "cp -f %s /var/cache/mondo-archive", outfile);
    1260   run_program_and_log_output(tmp, FALSE);
    1261 
    1262   sprintf (tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
    1263   write_one_liner_data_file (tmp, nfs_dev);
    1264 
    1265   sprintf (tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
    1266   write_one_liner_data_file (tmp, nfs_client_ipaddr);
    1267   sprintf (tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
    1268   write_one_liner_data_file (tmp, nfs_server_ipaddr);
    1269   sprintf (tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
    1270   write_one_liner_data_file (tmp, bkpinfo->nfs_mount);
    1271   sprintf (tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
    1272   write_one_liner_data_file (tmp, bkpinfo->nfs_remote_dir);
    1273   log_it ("Finished storing NFS configuration");
     1243    sprintf(tmp, "cp -f %s /var/cache/mondo-archive", outfile);
     1244    run_program_and_log_output(tmp, FALSE);
     1245
     1246    sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
     1247    write_one_liner_data_file(tmp, nfs_dev);
     1248
     1249    sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
     1250    write_one_liner_data_file(tmp, nfs_client_ipaddr);
     1251    sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
     1252    write_one_liner_data_file(tmp, nfs_server_ipaddr);
     1253    sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
     1254    write_one_liner_data_file(tmp, bkpinfo->nfs_mount);
     1255    sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
     1256    write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir);
     1257    log_it("Finished storing NFS configuration");
    12741258}
    12751259
     
    12961280 */
    12971281void
    1298 estimate_noof_media_required (struct s_bkpinfo *bkpinfo, long noof_sets)
    1299 {
    1300     /*@ buffers ****************/
    1301   char tmp[MAX_STR_LEN];
    1302 
    1303     /*@ long long **************/
    1304   long long scratchLL;
    1305 
    1306   if (bkpinfo->media_size[1]<=0 || bkpinfo->backup_media_type == nfs)
    1307     {
    1308       log_to_screen("Number of media required: UNKNOWN");
    1309       return;
    1310     }
    1311 
    1312   log_it ("Estimating number of media required...");
    1313   scratchLL = (long long)(noof_sets) * (long long)(bkpinfo->optimal_set_size)
    1314     + (long long)(size_of_all_biggiefiles_K (bkpinfo));
    1315   scratchLL = (scratchLL / 1024) / bkpinfo->media_size[1];
    1316   scratchLL++;
    1317   if (bkpinfo->use_lzo)
    1318     {
    1319       scratchLL = (scratchLL * 2) / 3;
    1320     }
    1321   else
    1322     {
    1323       scratchLL = scratchLL / 2;
    1324     }
    1325   if (!scratchLL)
    1326     {
    1327       scratchLL++;
    1328     }
    1329   if (scratchLL <= 1)
    1330     {
    1331       sprintf (tmp,
    1332            "Your backup will probably occupy a single CD/tape/ISO. Maybe two.");
    1333     }
    1334   else if (scratchLL > 4)
    1335     {
    1336       sprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)",
    1337            number_to_text ((int) (scratchLL + 1)));
    1338     }
    1339   else
    1340     {
    1341       sprintf (tmp, "Your backup will occupy approximately %s media.",
    1342            number_to_text ((int) (scratchLL + 1)));
    1343     }
    1344   if (!bkpinfo->image_devs[0] && (scratchLL<50))
    1345     {
    1346       log_to_screen (tmp);
    1347     }
     1282estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long noof_sets)
     1283{
     1284    /*@ buffers *************** */
     1285    char tmp[MAX_STR_LEN];
     1286
     1287    /*@ long long ************* */
     1288    long long scratchLL;
     1289
     1290    if (bkpinfo->media_size[1] <= 0 || bkpinfo->backup_media_type == nfs) {
     1291        log_to_screen("Number of media required: UNKNOWN");
     1292        return;
     1293    }
     1294
     1295    log_it("Estimating number of media required...");
     1296    scratchLL =
     1297        (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size)
     1298        + (long long) (size_of_all_biggiefiles_K(bkpinfo));
     1299    scratchLL = (scratchLL / 1024) / bkpinfo->media_size[1];
     1300    scratchLL++;
     1301    if (bkpinfo->use_lzo) {
     1302        scratchLL = (scratchLL * 2) / 3;
     1303    } else {
     1304        scratchLL = scratchLL / 2;
     1305    }
     1306    if (!scratchLL) {
     1307        scratchLL++;
     1308    }
     1309    if (scratchLL <= 1) {
     1310        sprintf(tmp,
     1311                "Your backup will probably occupy a single CD/tape/ISO. Maybe two.");
     1312    } else if (scratchLL > 4) {
     1313        sprintf(tmp,
     1314                "Your backup will occupy one meeeeellion media! (maybe %s)",
     1315                number_to_text((int) (scratchLL + 1)));
     1316    } else {
     1317        sprintf(tmp, "Your backup will occupy approximately %s media.",
     1318                number_to_text((int) (scratchLL + 1)));
     1319    }
     1320    if (!bkpinfo->image_devs[0] && (scratchLL < 50)) {
     1321        log_to_screen(tmp);
     1322    }
    13481323}
    13491324
     
    13561331 * @note The returned string points to static storage that will be overwritten with each call.
    13571332 */
    1358 char*sz_last_suffix(char*instr)
    1359 {
    1360   static char outstr[MAX_STR_LEN];
    1361   char *p;
    1362 
    1363   p = strrchr(instr,'.');
    1364   if (!p)
    1365     {
    1366       outstr[0]='\0';
    1367     }
    1368   else
    1369     {
    1370       strcpy(outstr, p);
    1371     }
    1372   return(outstr);
     1333char *sz_last_suffix(char *instr)
     1334{
     1335    static char outstr[MAX_STR_LEN];
     1336    char *p;
     1337
     1338    p = strrchr(instr, '.');
     1339    if (!p) {
     1340        outstr[0] = '\0';
     1341    } else {
     1342        strcpy(outstr, p);
     1343    }
     1344    return (outstr);
    13731345}
    13741346
     
    13801352 * @return TRUE if it's compressed, FALSE if not.
    13811353 */
    1382 bool is_this_file_compressed(char*filename)
    1383 {
    1384   char do_not_compress_these[MAX_STR_LEN];
    1385   char tmp[MAX_STR_LEN];
    1386   char *p;
    1387 
    1388   sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
    1389   if (!does_file_exist(tmp)) { return(FALSE); }
    1390   strcpy(do_not_compress_these, last_line_of_file(tmp));
    1391   for(p=do_not_compress_these; p!=NULL; p++)
    1392     {
    1393       strcpy(tmp, p);
    1394       if (strchr(tmp, ' ')) { *(strchr(tmp, ' ')) ='\0'; }
    1395       if (!strcmp(sz_last_suffix(filename), tmp))
    1396     { /*printf("MATCH\n");*/ return(TRUE); }
    1397       if (!(p = strchr(p, ' '))) { break; }
    1398     }
    1399   return(FALSE);
    1400 }
    1401 
    1402 
    1403 
    1404 int mode_of_file(char*fname)
    1405 {
    1406   struct stat buf;
    1407 
    1408   if (lstat(fname, &buf))
    1409     { return(-1); } // error
    1410   else
    1411     { return(buf.st_mode); }
     1354bool is_this_file_compressed(char *filename)
     1355{
     1356    char do_not_compress_these[MAX_STR_LEN];
     1357    char tmp[MAX_STR_LEN];
     1358    char *p;
     1359
     1360    sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     1361    if (!does_file_exist(tmp)) {
     1362        return (FALSE);
     1363    }
     1364    strcpy(do_not_compress_these, last_line_of_file(tmp));
     1365    for (p = do_not_compress_these; p != NULL; p++) {
     1366        strcpy(tmp, p);
     1367        if (strchr(tmp, ' ')) {
     1368            *(strchr(tmp, ' ')) = '\0';
     1369        }
     1370        if (!strcmp(sz_last_suffix(filename), tmp)) {   /*printf("MATCH\n"); */
     1371            return (TRUE);
     1372        }
     1373        if (!(p = strchr(p, ' '))) {
     1374            break;
     1375        }
     1376    }
     1377    return (FALSE);
     1378}
     1379
     1380
     1381
     1382int mode_of_file(char *fname)
     1383{
     1384    struct stat buf;
     1385
     1386    if (lstat(fname, &buf)) {
     1387        return (-1);
     1388    }                           // error
     1389    else {
     1390        return (buf.st_mode);
     1391    }
    14121392}
    14131393
     
    14201400 * @return 0 for success, 1 for failure.
    14211401 */
    1422 int make_grub_install_scriptlet(char*outfile)
    1423 {
    1424   FILE*fout;
    1425   char *tmp;
    1426   int retval=0;
    1427 
    1428   malloc_string(tmp);
    1429   if ((fout = fopen( outfile, "w")))
    1430     {
    1431       fprintf(fout, "#!/bin/sh\n\nmount /boot > /dev/null 2> /dev/null\ngrub-install $@\nres=$?\nsync;sync;sync\nexit $res\n");
    1432       paranoid_fclose(fout);
    1433       log_msg(2, "Created %s", outfile);
    1434       sprintf(tmp, "chmod +x %s", outfile);
    1435       paranoid_system(tmp);
    1436       retval=0;
    1437         }
    1438   else
    1439         {
    1440       retval=1;
    1441     }
    1442   paranoid_free(tmp);
    1443   return(retval);
     1402int make_grub_install_scriptlet(char *outfile)
     1403{
     1404    FILE *fout;
     1405    char *tmp;
     1406    int retval = 0;
     1407
     1408    malloc_string(tmp);
     1409    if ((fout = fopen(outfile, "w"))) {
     1410        fprintf(fout,
     1411                "#!/bin/sh\n\nmount /boot > /dev/null 2> /dev/null\ngrub-install $@\nres=$?\nsync;sync;sync\nexit $res\n");
     1412        paranoid_fclose(fout);
     1413        log_msg(2, "Created %s", outfile);
     1414        sprintf(tmp, "chmod +x %s", outfile);
     1415        paranoid_system(tmp);
     1416        retval = 0;
     1417    } else {
     1418        retval = 1;
     1419    }
     1420    paranoid_free(tmp);
     1421    return (retval);
    14441422}
    14451423
  • trunk/mondo/mondo/common/libmondo-files.h

    r30 r59  
    11/* libmondo-files.h
    2  * $Id: libmondo-files.h,v 1.3 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    66
    77
    8 unsigned int updcrc (unsigned int crc, unsigned int c);
    9 unsigned int updcrcr (unsigned int crc, unsigned int c);
    10 char *calc_checksum_of_file (char *filename);
    11 char *calc_file_ugly_minichecksum (char *curr_fname);
    12 char *calc_file_ugly_minichecksum (char *curr_fname);
    13 long count_lines_in_file (char *filename);
    14 bool does_file_exist (char *filename);
    15 void exclude_nonexistent_files (char *inout);
    16 int figure_out_kernel_path_interactively_if_necessary(char*kernel);
    17 char *find_home_of_exe (char *fname);
    18 int get_trackno_from_logfile (char *logfile);
    19 int grab_percentage_from_last_line_of_file (char *filename);
    20 char *last_line_of_file (char *filename);
    21 long long length_of_file (char *filename);
    22 int make_checksum_list_file (char *filelist, char *cksumlist, char *comppath);
    23 int make_hole_for_file (char *outfile_fname);
    24 void make_list_of_files_to_ignore (char *ignorefiles_fname, char *filelist_fname,
    25                   char *cklist_fname);
    26 long noof_lines_that_match_wildcard (char *filelist_fname, char *wildcard);
    27 void register_pid(pid_t pid, char*name_str);
    28 long size_of_all_biggiefiles_K (struct s_bkpinfo *bkpinfo);
    29 long long space_occupied_by_cd (char *mountpt);
    30 int whine_if_not_found (char *fname);
    31 int write_one_liner_data_file (char *fname, char *contents);
     8unsigned int updcrc(unsigned int crc, unsigned int c);
     9unsigned int updcrcr(unsigned int crc, unsigned int c);
     10char *calc_checksum_of_file(char *filename);
     11char *calc_file_ugly_minichecksum(char *curr_fname);
     12char *calc_file_ugly_minichecksum(char *curr_fname);
     13long count_lines_in_file(char *filename);
     14bool does_file_exist(char *filename);
     15void exclude_nonexistent_files(char *inout);
     16int figure_out_kernel_path_interactively_if_necessary(char *kernel);
     17char *find_home_of_exe(char *fname);
     18int get_trackno_from_logfile(char *logfile);
     19int grab_percentage_from_last_line_of_file(char *filename);
     20char *last_line_of_file(char *filename);
     21long long length_of_file(char *filename);
     22int make_checksum_list_file(char *filelist, char *cksumlist,
     23                            char *comppath);
     24int make_hole_for_file(char *outfile_fname);
     25void make_list_of_files_to_ignore(char *ignorefiles_fname,
     26                                  char *filelist_fname,
     27                                  char *cklist_fname);
     28long noof_lines_that_match_wildcard(char *filelist_fname, char *wildcard);
     29void register_pid(pid_t pid, char *name_str);
     30long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo);
     31long long space_occupied_by_cd(char *mountpt);
     32int whine_if_not_found(char *fname);
     33int write_one_liner_data_file(char *fname, char *contents);
    3234
    33 void copy_mondo_and_mindi_stuff_to_scratchdir (struct s_bkpinfo *bkpinfo);
    34 void store_nfs_config (struct s_bkpinfo *bkpinfo);
    35 void estimate_noof_media_required (struct s_bkpinfo *bkpinfo, long);
    36 bool is_this_file_compressed (char*);
     35void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo *bkpinfo);
     36void store_nfs_config(struct s_bkpinfo *bkpinfo);
     37void estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long);
     38bool is_this_file_compressed(char *);
    3739
    3840
     
    4345
    4446
    45 int make_hole_for_dir (char*outdir_fname);
    46 long size_of_partition_in_mountlist_K(char*tmpdir, char*dev);
    47 int make_grub_install_scriptlet(char*outfile);
     47int make_hole_for_dir(char *outdir_fname);
     48long size_of_partition_in_mountlist_K(char *tmpdir, char *dev);
     49int make_grub_install_scriptlet(char *outfile);
    4850
    49 int read_one_liner_data_file (char *fname, char *contents);
    50 int mode_of_file(char*fname);
     51int read_one_liner_data_file(char *fname, char *contents);
     52int mode_of_file(char *fname);
  • trunk/mondo/mondo/common/libmondo-fork-EXT.h

    r30 r59  
    11/* libmondo-fork-EXT.h */
    22
    3 extern char *call_program_and_get_last_line_of_output (char *call);
    4 extern int run_program_and_log_to_screen (char *basic_call, char *what_i_am_doing);
    5 extern int run_program_and_log_output (char *program, int);
    6 extern int eval_call_to_make_ISO (struct s_bkpinfo *bkpinfo,
    7        char *basic_call, char *isofile,
    8        int cd_no, char *logstub, char *what_i_am_doing);
    9 extern int run_external_binary_with_percentage_indicator_OLD (char *tt, char *cmd);
    10 extern int run_external_binary_with_percentage_indicator_NEW (char *tt, char *cmd);
    11 extern int copy_from_src_to_dest(FILE*,FILE*,char);
    12 extern int feed_into_partimage(char*input_device, char*output_fname);
    13 extern int feed_outfrom_partimage(char*output_device, char*input_fifo);
    14 
     3extern char *call_program_and_get_last_line_of_output(char *call);
     4extern int run_program_and_log_to_screen(char *basic_call,
     5                                         char *what_i_am_doing);
     6extern int run_program_and_log_output(char *program, int);
     7extern int eval_call_to_make_ISO(struct s_bkpinfo *bkpinfo,
     8                                 char *basic_call, char *isofile,
     9                                 int cd_no, char *logstub,
     10                                 char *what_i_am_doing);
     11extern int run_external_binary_with_percentage_indicator_OLD(char *tt,
     12                                                             char *cmd);
     13extern int run_external_binary_with_percentage_indicator_NEW(char *tt,
     14                                                             char *cmd);
     15extern int copy_from_src_to_dest(FILE *, FILE *, char);
     16extern int feed_into_partimage(char *input_device, char *output_fname);
     17extern int feed_outfrom_partimage(char *output_device, char *input_fifo);
  • trunk/mondo/mondo/common/libmondo-fork.c

    r30 r59  
    11/* libmondo-fork.c
    2    $Id: libmondo-fork.c,v 1.3 2004/06/21 20:20:36 hugo Exp $
     2   $Id$
    33
    44- subroutines for handling forking/pthreads/etc.
     
    109109
    110110/*@unused@*/
    111 //static char cvsid[] = "$Id: libmondo-fork.c,v 1.3 2004/06/21 20:20:36 hugo Exp $";
     111//static char cvsid[] = "$Id$";
    112112
    113113extern char *g_tmpfs_mountpt;
    114114extern t_bkptype g_backup_media_type;
    115115extern bool g_text_mode;
    116 pid_t g_buffer_pid=0;
     116pid_t g_buffer_pid = 0;
    117117
    118118
     
    123123 * @note The returned value points to static storage that will be overwritten with each call.
    124124 */
    125 char *
    126 call_program_and_get_last_line_of_output (char *call)
     125char *call_program_and_get_last_line_of_output(char *call)
    127126{
    128     /*@ buffers ******************************************************/
    129   static char result[512];
    130   char *tmp;
    131 
    132     /*@ pointers *****************************************************/
    133   FILE *fin;
    134 
    135     /*@ initialize data **********************************************/
    136   malloc_string(tmp);
    137   result[0] = '\0';
    138   tmp[0]    = '\0';
    139 
    140   /*@*********************************************************************/
    141 
    142   assert_string_is_neither_NULL_nor_zerolength(call);
    143   if ((fin = popen (call, "r")))
    144     {
    145       for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin);
    146        fgets (tmp, MAX_STR_LEN, fin))
    147     {
    148       if (strlen (tmp) > 1)
    149         {
    150           strcpy (result, tmp);
    151         }
    152     }
    153       paranoid_pclose (fin);
    154     }
    155   else
    156     {
    157       log_OS_error("Unable to popen call");
    158     }
    159   strip_spaces (result);
    160   return (result);
     127    /*@ buffers ***************************************************** */
     128    static char result[512];
     129    char *tmp;
     130
     131    /*@ pointers **************************************************** */
     132    FILE *fin;
     133
     134    /*@ initialize data ********************************************* */
     135    malloc_string(tmp);
     136    result[0] = '\0';
     137    tmp[0] = '\0';
     138
     139    /*@******************************************************************** */
     140
     141    assert_string_is_neither_NULL_nor_zerolength(call);
     142    if ((fin = popen(call, "r"))) {
     143        for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     144             fgets(tmp, MAX_STR_LEN, fin)) {
     145            if (strlen(tmp) > 1) {
     146                strcpy(result, tmp);
     147            }
     148        }
     149        paranoid_pclose(fin);
     150    } else {
     151        log_OS_error("Unable to popen call");
     152    }
     153    strip_spaces(result);
     154    return (result);
    161155}
    162156
     
    186180 */
    187181int
    188 eval_call_to_make_ISO (struct s_bkpinfo *bkpinfo,
    189        char *basic_call, char *isofile,
    190        int cd_no, char *logstub, char *what_i_am_doing)
     182eval_call_to_make_ISO(struct s_bkpinfo *bkpinfo,
     183                      char *basic_call, char *isofile,
     184                      int cd_no, char *logstub, char *what_i_am_doing)
    191185{
    192186
    193     /*@ int's  ****/
    194   int retval = 0;
    195 
    196 
    197     /*@ buffers      ****/
    198   char *midway_call, *ultimate_call, *tmp, *command, *incoming, *old_stderr, *cd_number_str;
    199   char *p;
     187    /*@ int's  *** */
     188    int retval = 0;
     189
     190
     191    /*@ buffers      *** */
     192    char *midway_call, *ultimate_call, *tmp, *command, *incoming,
     193        *old_stderr, *cd_number_str;
     194    char *p;
    200195
    201196/*@***********   End Variables ***************************************/
    202197
    203   log_msg(3, "Starting");
    204   assert(bkpinfo!=NULL);
    205   assert_string_is_neither_NULL_nor_zerolength(basic_call);
    206   assert_string_is_neither_NULL_nor_zerolength(isofile);
    207   assert_string_is_neither_NULL_nor_zerolength(logstub);
    208   if (!(midway_call = malloc(1200))) { fatal_error("Cannot malloc midway_call"); }
    209   if (!(ultimate_call = malloc(1200))) { fatal_error("Cannot malloc ultimate_call"); }
    210   if (!(tmp = malloc(1200))) { fatal_error("Cannot malloc tmp"); }
    211   if (!(command = malloc(1200))) { fatal_error("Cannot malloc command"); }
    212   malloc_string(incoming);
    213   malloc_string(old_stderr);
    214   malloc_string(cd_number_str);
    215 
    216   incoming[0]='\0';
    217   old_stderr[0] = '\0';
    218 
    219   sprintf (cd_number_str, "%d", cd_no);
    220   resolve_naff_tokens (midway_call, basic_call, isofile, "_ISO_");
    221   resolve_naff_tokens (tmp, midway_call, cd_number_str, "_CD#_");
    222   resolve_naff_tokens (ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
    223   log_msg (4, "basic call = '%s'", basic_call);
    224   log_msg (4, "midway_call = '%s'", midway_call);
    225   log_msg (4, "tmp = '%s'", tmp);
    226   log_msg (4, "ultimate call = '%s'", ultimate_call);
    227   sprintf( command, "%s >> %s", ultimate_call, MONDO_LOGFILE );
    228 
    229   log_to_screen("Please be patient. Do not be alarmed by on-screen inactivity.");
    230   log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", what_i_am_doing);
    231   strcpy (tmp, command);
    232   if (bkpinfo->manual_cd_tray)
    233     {
    234       p = strstr (tmp, "2>>");
    235       if (p)
    236         {
    237           sprintf (p, "   ");
    238           while(*p==' ') { p++; }
    239           for (; *p != ' '; p++)
    240         {
    241           *p = ' ';
    242         }
    243         }
    244       strcpy(command, tmp);
     198    log_msg(3, "Starting");
     199    assert(bkpinfo != NULL);
     200    assert_string_is_neither_NULL_nor_zerolength(basic_call);
     201    assert_string_is_neither_NULL_nor_zerolength(isofile);
     202    assert_string_is_neither_NULL_nor_zerolength(logstub);
     203    if (!(midway_call = malloc(1200))) {
     204        fatal_error("Cannot malloc midway_call");
     205    }
     206    if (!(ultimate_call = malloc(1200))) {
     207        fatal_error("Cannot malloc ultimate_call");
     208    }
     209    if (!(tmp = malloc(1200))) {
     210        fatal_error("Cannot malloc tmp");
     211    }
     212    if (!(command = malloc(1200))) {
     213        fatal_error("Cannot malloc command");
     214    }
     215    malloc_string(incoming);
     216    malloc_string(old_stderr);
     217    malloc_string(cd_number_str);
     218
     219    incoming[0] = '\0';
     220    old_stderr[0] = '\0';
     221
     222    sprintf(cd_number_str, "%d", cd_no);
     223    resolve_naff_tokens(midway_call, basic_call, isofile, "_ISO_");
     224    resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
     225    resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
     226    log_msg(4, "basic call = '%s'", basic_call);
     227    log_msg(4, "midway_call = '%s'", midway_call);
     228    log_msg(4, "tmp = '%s'", tmp);
     229    log_msg(4, "ultimate call = '%s'", ultimate_call);
     230    sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
     231
     232    log_to_screen
     233        ("Please be patient. Do not be alarmed by on-screen inactivity.");
     234    log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
     235            what_i_am_doing);
     236    strcpy(tmp, command);
     237    if (bkpinfo->manual_cd_tray) {
     238        p = strstr(tmp, "2>>");
     239        if (p) {
     240            sprintf(p, "   ");
     241            while (*p == ' ') {
     242                p++;
     243            }
     244            for (; *p != ' '; p++) {
     245                *p = ' ';
     246            }
     247        }
     248        strcpy(command, tmp);
    245249#ifndef _XWIN
    246       if (!g_text_mode) { newtSuspend(); }
     250        if (!g_text_mode) {
     251            newtSuspend();
     252        }
    247253#endif
    248       log_msg (1, "command = '%s'", command);
    249       retval += system (command);
    250       if (!g_text_mode) { newtResume(); }
    251       if (retval)
    252     {
    253       log_msg (2, "Basic call '%s' returned an error.", basic_call);
    254       popup_and_OK ("Press ENTER to continue.");
    255           popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created");
    256     }
    257     }
    258   /* if text mode then do the above & RETURN; if not text mode, do this... */
    259   else
    260     {
    261       log_msg (3, "command = '%s'", command);
     254        log_msg(1, "command = '%s'", command);
     255        retval += system(command);
     256        if (!g_text_mode) {
     257            newtResume();
     258        }
     259        if (retval) {
     260            log_msg(2, "Basic call '%s' returned an error.", basic_call);
     261            popup_and_OK("Press ENTER to continue.");
     262            popup_and_OK
     263                ("mkisofs and/or cdrecord returned an error. CD was not created");
     264        }
     265    }
     266    /* if text mode then do the above & RETURN; if not text mode, do this... */
     267    else {
     268        log_msg(3, "command = '%s'", command);
    262269//      yes_this_is_a_goto:
    263       retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
    264     }
    265 
    266   paranoid_free(midway_call);
    267   paranoid_free(ultimate_call);
    268   paranoid_free(tmp);
    269   paranoid_free(command);
    270   paranoid_free(incoming);
    271   paranoid_free(old_stderr);
    272   paranoid_free(cd_number_str);
     270        retval =
     271            run_external_binary_with_percentage_indicator_NEW
     272            (what_i_am_doing, command);
     273    }
     274
     275    paranoid_free(midway_call);
     276    paranoid_free(ultimate_call);
     277    paranoid_free(tmp);
     278    paranoid_free(command);
     279    paranoid_free(incoming);
     280    paranoid_free(old_stderr);
     281    paranoid_free(cd_number_str);
    273282/*
    274283  if (bkpinfo->backup_media_type == dvd && !bkpinfo->please_dont_eject_when_restoring)
     
    278287    }
    279288*/
    280   return (retval);
     289    return (retval);
    281290}
    282291
     
    290299 * @return The exit code of @p program (depends on the command, but 0 almost always indicates success).
    291300 */
    292 int
    293 run_program_and_log_output (char *program, int debug_level)
     301int run_program_and_log_output(char *program, int debug_level)
    294302{
    295     /*@ buffer *******************************************************/
    296   char callstr[MAX_STR_LEN*2];
    297   char incoming[MAX_STR_LEN*2];
    298   char tmp[MAX_STR_LEN*2];
    299   char initial_label[MAX_STR_LEN*2];
    300 
    301     /*@ int **********************************************************/
    302   int res;
    303   int i;
    304   int len;
    305   bool log_if_failure=FALSE;
    306   bool log_if_success=FALSE;
    307 
    308     /*@ pointers ****************************************************/
    309   FILE *fin;
    310   char *p;
    311 
    312     /*@ end vars ****************************************************/
    313 
    314   assert(program!=NULL);
    315   if (!program[0])
    316     {
    317       log_msg(2, "Warning - asked to run zerolength program");
    318       return(1);
    319     }
     303    /*@ buffer ****************************************************** */
     304    char callstr[MAX_STR_LEN * 2];
     305    char incoming[MAX_STR_LEN * 2];
     306    char tmp[MAX_STR_LEN * 2];
     307    char initial_label[MAX_STR_LEN * 2];
     308
     309    /*@ int ********************************************************* */
     310    int res;
     311    int i;
     312    int len;
     313    bool log_if_failure = FALSE;
     314    bool log_if_success = FALSE;
     315
     316    /*@ pointers *************************************************** */
     317    FILE *fin;
     318    char *p;
     319
     320    /*@ end vars *************************************************** */
     321
     322    assert(program != NULL);
     323    if (!program[0]) {
     324        log_msg(2, "Warning - asked to run zerolength program");
     325        return (1);
     326    }
    320327//  if (debug_level == TRUE) { debug_level=5; }
    321328
    322   //  assert_string_is_neither_NULL_nor_zerolength(program);
    323 
    324   if (debug_level <= g_loglevel) { log_if_success = TRUE; log_if_failure = TRUE; }
    325   sprintf (callstr, "%s > /tmp/mondo-run-prog-thing.tmp 2> /tmp/mondo-run-prog-thing.err",
    326        program);
    327   while ((p = strchr (callstr, '\r')))
    328     {
    329       *p = ' ';
    330     }
    331   while ((p = strchr (callstr, '\n')))
    332     {
    333       *p = ' ';
    334     }               /* single '=' is intentional */
    335 
    336 
    337   len = (int) strlen (program);
    338   for (i = 0; i < 35 - len / 2; i++)
    339     {
    340       tmp[i] = '-';
    341     }
    342   tmp[i] = '\0';
    343   strcat (tmp, " ");
    344   strcat (tmp, program);
    345   strcat (tmp, " ");
    346   for (i = 0; i < 35 - len / 2; i++)
    347     {
    348       strcat (tmp, "-");
    349     }
    350   strcpy(initial_label, tmp);
    351   res = system (callstr);
    352   if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
    353       log_msg (0, "running: %s", callstr);
    354       log_msg (0, "--------------------------------start of output-----------------------------");
    355   }
    356   if (log_if_failure && system ("cat /tmp/mondo-run-prog-thing.err >> /tmp/mondo-run-prog-thing.tmp 2> /dev/null"))
    357     {
    358       log_OS_error("Command failed");
    359     }
    360   unlink ("/tmp/mondo-run-prog-thing.err");
    361   fin = fopen ("/tmp/mondo-run-prog-thing.tmp", "r");
    362   if (fin)
    363     {
    364       for (fgets (incoming, MAX_STR_LEN, fin); !feof (fin);
    365        fgets (incoming, MAX_STR_LEN, fin))
     329    //  assert_string_is_neither_NULL_nor_zerolength(program);
     330
     331    if (debug_level <= g_loglevel) {
     332        log_if_success = TRUE;
     333        log_if_failure = TRUE;
     334    }
     335    sprintf(callstr,
     336            "%s > /tmp/mondo-run-prog-thing.tmp 2> /tmp/mondo-run-prog-thing.err",
     337            program);
     338    while ((p = strchr(callstr, '\r'))) {
     339        *p = ' ';
     340    }
     341    while ((p = strchr(callstr, '\n'))) {
     342        *p = ' ';
     343    }                           /* single '=' is intentional */
     344
     345
     346    len = (int) strlen(program);
     347    for (i = 0; i < 35 - len / 2; i++) {
     348        tmp[i] = '-';
     349    }
     350    tmp[i] = '\0';
     351    strcat(tmp, " ");
     352    strcat(tmp, program);
     353    strcat(tmp, " ");
     354    for (i = 0; i < 35 - len / 2; i++) {
     355        strcat(tmp, "-");
     356    }
     357    strcpy(initial_label, tmp);
     358    res = system(callstr);
     359    if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
     360        log_msg(0, "running: %s", callstr);
     361        log_msg(0,
     362                "--------------------------------start of output-----------------------------");
     363    }
     364    if (log_if_failure
     365        &&
     366        system
     367        ("cat /tmp/mondo-run-prog-thing.err >> /tmp/mondo-run-prog-thing.tmp 2> /dev/null"))
    366368    {
    367       /* patch by Heiko Schlittermann */
    368       p = incoming;
    369       while (p && *p)
    370         {
    371           if ((p = strchr(p, '%')))
    372         {
    373           memmove(p, p+1, strlen(p) +1);
    374           p += 2;
    375         }
    376         }
    377       /* end of patch */
    378       strip_spaces (incoming);
    379           if ((res==0 && log_if_success) || (res!=0 && log_if_failure))
    380             { log_msg (0, incoming); }
    381     }
    382       paranoid_fclose (fin);
    383     }
    384   unlink("/tmp/mondo-run-prog-thing.tmp");
    385   if ((res==0 && log_if_success) || (res!=0 && log_if_failure))
    386     {
    387       log_msg (0, "--------------------------------end of output------------------------------");
    388       if (res) { log_msg (0,"...ran with res=%d", res); }
    389       else { log_msg(0, "...ran just fine. :-)"); }
    390     }
     369        log_OS_error("Command failed");
     370    }
     371    unlink("/tmp/mondo-run-prog-thing.err");
     372    fin = fopen("/tmp/mondo-run-prog-thing.tmp", "r");
     373    if (fin) {
     374        for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
     375             fgets(incoming, MAX_STR_LEN, fin)) {
     376            /* patch by Heiko Schlittermann */
     377            p = incoming;
     378            while (p && *p) {
     379                if ((p = strchr(p, '%'))) {
     380                    memmove(p, p + 1, strlen(p) + 1);
     381                    p += 2;
     382                }
     383            }
     384            /* end of patch */
     385            strip_spaces(incoming);
     386            if ((res == 0 && log_if_success)
     387                || (res != 0 && log_if_failure)) {
     388                log_msg(0, incoming);
     389            }
     390        }
     391        paranoid_fclose(fin);
     392    }
     393    unlink("/tmp/mondo-run-prog-thing.tmp");
     394    if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
     395        log_msg(0,
     396                "--------------------------------end of output------------------------------");
     397        if (res) {
     398            log_msg(0, "...ran with res=%d", res);
     399        } else {
     400            log_msg(0, "...ran just fine. :-)");
     401        }
     402    }
    391403//  else
    392404//    { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); }
    393   return (res);
     405    return (res);
    394406}
    395407
     
    404416 * @see log_to_screen
    405417 */
    406 int
    407 run_program_and_log_to_screen (char *basic_call, char *what_i_am_doing)
     418int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing)
    408419{
    409     /*@ int *********************************************************/
    410   int retval = 0;
    411   int res = 0;
    412   int i;
    413 
    414     /*@ pointers *****************************************************/
    415   FILE *fin;
    416 
    417     /*@ buffers *****************************************************/
    418   char tmp[MAX_STR_LEN*2];
    419   char command[MAX_STR_LEN*2];
    420   char lockfile[MAX_STR_LEN];
    421 
    422     /*@ end vars ****************************************************/
    423 
    424   assert_string_is_neither_NULL_nor_zerolength(basic_call);
    425 
    426   sprintf (lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
    427   mkstemp (lockfile);
    428   sprintf (command,
    429        "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
    430        lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
    431   open_evalcall_form (what_i_am_doing);
    432   sprintf (tmp, "Executing %s", basic_call);
    433   log_msg (2, tmp);
    434   if (!(fin = popen (command, "r")))
    435     {
    436       log_OS_error("Unable to popen-in command");
    437       sprintf (tmp, "Failed utterly to call '%s'", command);
    438       log_to_screen (tmp);
    439       return (1);
    440     }
    441   if (!does_file_exist(lockfile))
    442     {
    443       log_to_screen("Waiting for external binary to start");
    444       for (i = 0; i < 60 && !does_file_exist (lockfile); sleep (1), i++)
    445         {
    446           log_msg(3, "Waiting for lockfile %s to exist", lockfile);
    447         }
    448     }
     420    /*@ int ******************************************************** */
     421    int retval = 0;
     422    int res = 0;
     423    int i;
     424
     425    /*@ pointers **************************************************** */
     426    FILE *fin;
     427
     428    /*@ buffers **************************************************** */
     429    char tmp[MAX_STR_LEN * 2];
     430    char command[MAX_STR_LEN * 2];
     431    char lockfile[MAX_STR_LEN];
     432
     433    /*@ end vars *************************************************** */
     434
     435    assert_string_is_neither_NULL_nor_zerolength(basic_call);
     436
     437    sprintf(lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
     438    mkstemp(lockfile);
     439    sprintf(command,
     440            "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
     441            lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
     442    open_evalcall_form(what_i_am_doing);
     443    sprintf(tmp, "Executing %s", basic_call);
     444    log_msg(2, tmp);
     445    if (!(fin = popen(command, "r"))) {
     446        log_OS_error("Unable to popen-in command");
     447        sprintf(tmp, "Failed utterly to call '%s'", command);
     448        log_to_screen(tmp);
     449        return (1);
     450    }
     451    if (!does_file_exist(lockfile)) {
     452        log_to_screen("Waiting for external binary to start");
     453        for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
     454            log_msg(3, "Waiting for lockfile %s to exist", lockfile);
     455        }
     456    }
    449457#ifdef _XWIN
    450   /* This only can update when newline goes into the file,
    451      but it's *much* prettier/faster on Qt. */
    452   while (does_file_exist (lockfile)) {
    453       while (!feof (fin)) {
    454       if (!fgets (tmp, 512, fin)) break;
    455       log_to_screen (tmp);
    456       }
    457       usleep (500000);
    458   }
     458    /* This only can update when newline goes into the file,
     459       but it's *much* prettier/faster on Qt. */
     460    while (does_file_exist(lockfile)) {
     461        while (!feof(fin)) {
     462            if (!fgets(tmp, 512, fin))
     463                break;
     464            log_to_screen(tmp);
     465        }
     466        usleep(500000);
     467    }
    459468#else
    460   /* This works on Newt, and it gives quicker updates. */
    461   for (; does_file_exist (lockfile); sleep (1))
    462     {
    463       log_file_end_to_screen (MONDO_LOGFILE, "");
    464       update_evalcall_form (1);
    465     }
     469    /* This works on Newt, and it gives quicker updates. */
     470    for (; does_file_exist(lockfile); sleep(1)) {
     471        log_file_end_to_screen(MONDO_LOGFILE, "");
     472        update_evalcall_form(1);
     473    }
    466474#endif
    467   paranoid_pclose (fin);
    468   retval += res;
    469   close_evalcall_form ();
    470   unlink (lockfile);
    471   return (retval);
     475    paranoid_pclose(fin);
     476    retval += res;
     477    close_evalcall_form();
     478    unlink(lockfile);
     479    return (retval);
    472480}
    473481
     
    484492 * @return NULL to pthread_join.
    485493 */
    486 void *call_partimage_in_bkgd(void*xfb)
     494void *call_partimage_in_bkgd(void *xfb)
    487495{
    488   char *transfer_block;
    489   int retval=0;
    490 
    491   g_buffer_pid = getpid();
    492   unlink("/tmp/null");
    493   log_msg(1, "starting");
    494   transfer_block = (char*)xfb;
    495   transfer_block[0] --; // should now be 1
    496   retval = system(transfer_block+2);
    497   if (retval) { log_OS_error("partimage returned an error"); }
    498   transfer_block[1] = retval;
    499   transfer_block[0] --; // should now be 0
    500   g_buffer_pid = 0;
    501   log_msg(1, "returning");
    502   pthread_exit(NULL);
     496    char *transfer_block;
     497    int retval = 0;
     498
     499    g_buffer_pid = getpid();
     500    unlink("/tmp/null");
     501    log_msg(1, "starting");
     502    transfer_block = (char *) xfb;
     503    transfer_block[0]--;        // should now be 1
     504    retval = system(transfer_block + 2);
     505    if (retval) {
     506        log_OS_error("partimage returned an error");
     507    }
     508    transfer_block[1] = retval;
     509    transfer_block[0]--;        // should now be 0
     510    g_buffer_pid = 0;
     511    log_msg(1, "returning");
     512    pthread_exit(NULL);
    503513}
    504514
     
    525535#define NO_MORE_SUBVOLS "On-second-hand,momma-bounced-on-old-man,-and-so-we-moved-to-Shaolin-Land."
    526536
    527 int copy_from_src_to_dest(FILE*f_orig, FILE*f_archived, char direction)
     537int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction)
    528538{
    529539// if dir=='w' then copy from orig to archived
    530540// if dir=='r' then copy from archived to orig
    531   char*tmp;
    532   char*buf;
    533   long int bytes_to_be_read, bytes_read_in, bytes_written_out=0, bufcap, subsliceno=0;
    534   int retval=0;
    535   FILE*fin;
    536   FILE*fout;
    537   FILE*ftmp;
    538 
    539   log_msg(5, "Opening.");
    540   malloc_string(tmp);
    541   tmp[0] = '\0';
    542   bufcap = 256L*1024L;
    543   if (!(buf = malloc(bufcap))) { fatal_error("Failed to malloc() buf"); }
    544 
    545   if (direction=='w')
    546     {
    547       fin = f_orig;
    548       fout = f_archived;
    549       sprintf(tmp, "%-64s", PIMP_START_SZ);
    550       if (fwrite(tmp, 1, 64, fout)!=64) { fatal_error("Can't write the introductory block"); }
    551       while(1)
    552         {
    553           bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
    554       if (bytes_read_in == 0) { break; }
    555           sprintf(tmp, "%-64ld", bytes_read_in);
    556           if (fwrite(tmp, 1, 64, fout)!=64) { fatal_error("Cannot write introductory block"); }
    557           log_msg(7, "subslice #%ld --- I have read %ld of %ld bytes in from f_orig", subsliceno,  bytes_read_in, bytes_to_be_read);
    558           bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    559           sprintf(tmp, "%-64ld", subsliceno);
    560           if (fwrite(tmp, 1, 64, fout)!=64) { fatal_error("Cannot write post-thingy block"); }
    561       log_msg(7, "Subslice #%d written OK", subsliceno);
    562       subsliceno++;
    563         }
    564       sprintf(tmp, "%-64ld", 0L);
    565       if (fwrite(tmp, 1, 64L, fout)!=64L) { fatal_error("Cannot write final introductory block"); }
    566     }
    567   else
    568     {
    569       fin = f_archived;
    570       fout = f_orig;
    571       if (fread(tmp, 1, 64L, fin)!=64L) { fatal_error("Cannot read the introductory block"); }
    572       log_msg(5, "tmp is %s", tmp);
    573       if (!strstr(tmp, PIMP_START_SZ)){ fatal_error("Can't find intro blk"); }
    574       if (fread(tmp, 1, 64L, fin)!=64L) { fatal_error("Cannot read introductory blk"); }
    575       bytes_to_be_read = atol(tmp);
    576       while(bytes_to_be_read > 0)
    577         {
    578       log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read);
    579           bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
    580           if (bytes_read_in != bytes_to_be_read) { fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives."); }
    581           bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    582           if (fread(tmp, 1, 64, fin)!=64) { fatal_error("Cannot read post-thingy block"); }
    583           if (atol(tmp) != subsliceno) { log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp), tmp); }
    584       log_msg(7, "Subslice #%ld read OK", subsliceno);
    585       subsliceno++;
    586           if (fread(tmp, 1, 64, fin)!=64) { fatal_error("Cannot read introductory block"); }
    587           bytes_to_be_read = atol(tmp);
    588         }
    589     }
     541    char *tmp;
     542    char *buf;
     543    long int bytes_to_be_read, bytes_read_in, bytes_written_out =
     544        0, bufcap, subsliceno = 0;
     545    int retval = 0;
     546    FILE *fin;
     547    FILE *fout;
     548    FILE *ftmp;
     549
     550    log_msg(5, "Opening.");
     551    malloc_string(tmp);
     552    tmp[0] = '\0';
     553    bufcap = 256L * 1024L;
     554    if (!(buf = malloc(bufcap))) {
     555        fatal_error("Failed to malloc() buf");
     556    }
     557
     558    if (direction == 'w') {
     559        fin = f_orig;
     560        fout = f_archived;
     561        sprintf(tmp, "%-64s", PIMP_START_SZ);
     562        if (fwrite(tmp, 1, 64, fout) != 64) {
     563            fatal_error("Can't write the introductory block");
     564        }
     565        while (1) {
     566            bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
     567            if (bytes_read_in == 0) {
     568                break;
     569            }
     570            sprintf(tmp, "%-64ld", bytes_read_in);
     571            if (fwrite(tmp, 1, 64, fout) != 64) {
     572                fatal_error("Cannot write introductory block");
     573            }
     574            log_msg(7,
     575                    "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
     576                    subsliceno, bytes_read_in, bytes_to_be_read);
     577            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
     578            sprintf(tmp, "%-64ld", subsliceno);
     579            if (fwrite(tmp, 1, 64, fout) != 64) {
     580                fatal_error("Cannot write post-thingy block");
     581            }
     582            log_msg(7, "Subslice #%d written OK", subsliceno);
     583            subsliceno++;
     584        }
     585        sprintf(tmp, "%-64ld", 0L);
     586        if (fwrite(tmp, 1, 64L, fout) != 64L) {
     587            fatal_error("Cannot write final introductory block");
     588        }
     589    } else {
     590        fin = f_archived;
     591        fout = f_orig;
     592        if (fread(tmp, 1, 64L, fin) != 64L) {
     593            fatal_error("Cannot read the introductory block");
     594        }
     595        log_msg(5, "tmp is %s", tmp);
     596        if (!strstr(tmp, PIMP_START_SZ)) {
     597            fatal_error("Can't find intro blk");
     598        }
     599        if (fread(tmp, 1, 64L, fin) != 64L) {
     600            fatal_error("Cannot read introductory blk");
     601        }
     602        bytes_to_be_read = atol(tmp);
     603        while (bytes_to_be_read > 0) {
     604            log_msg(7, "subslice#%ld, bytes=%ld", subsliceno,
     605                    bytes_to_be_read);
     606            bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
     607            if (bytes_read_in != bytes_to_be_read) {
     608                fatal_error
     609                    ("Danger, WIll Robinson. Failed to read whole subvol from archives.");
     610            }
     611            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
     612            if (fread(tmp, 1, 64, fin) != 64) {
     613                fatal_error("Cannot read post-thingy block");
     614            }
     615            if (atol(tmp) != subsliceno) {
     616                log_msg(1, "Wanted subslice %ld but got %ld ('%s')",
     617                        subsliceno, atol(tmp), tmp);
     618            }
     619            log_msg(7, "Subslice #%ld read OK", subsliceno);
     620            subsliceno++;
     621            if (fread(tmp, 1, 64, fin) != 64) {
     622                fatal_error("Cannot read introductory block");
     623            }
     624            bytes_to_be_read = atol(tmp);
     625        }
     626    }
    590627
    591628//  log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in);
    592629
    593   if (direction=='w')
    594     {
    595       sprintf(tmp, "%-64s", PIMP_END_SZ);
    596       if (fwrite(tmp, 1, 64, fout)!=64) { fatal_error("Can't write the final block"); }
    597     }
    598   else
    599     {
    600       log_msg(1, "tmpA is %s", tmp);
    601       if (!strstr(tmp, PIMP_END_SZ))
    602         {
    603           if (fread(tmp, 1, 64, fin)!=64) { fatal_error("Can't read the final block"); }
    604           log_msg(5, "tmpB is %s", tmp);
    605           if (!strstr(tmp, PIMP_END_SZ))
    606             {
    607               ftmp = fopen("/tmp/out.leftover", "w");
    608               bytes_read_in = fread(tmp, 1, 64, fin);
    609               log_msg(1, "bytes_read_in = %ld", bytes_read_in);
     630    if (direction == 'w') {
     631        sprintf(tmp, "%-64s", PIMP_END_SZ);
     632        if (fwrite(tmp, 1, 64, fout) != 64) {
     633            fatal_error("Can't write the final block");
     634        }
     635    } else {
     636        log_msg(1, "tmpA is %s", tmp);
     637        if (!strstr(tmp, PIMP_END_SZ)) {
     638            if (fread(tmp, 1, 64, fin) != 64) {
     639                fatal_error("Can't read the final block");
     640            }
     641            log_msg(5, "tmpB is %s", tmp);
     642            if (!strstr(tmp, PIMP_END_SZ)) {
     643                ftmp = fopen("/tmp/out.leftover", "w");
     644                bytes_read_in = fread(tmp, 1, 64, fin);
     645                log_msg(1, "bytes_read_in = %ld", bytes_read_in);
    610646//      if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); }
    611               fwrite(tmp, 1, bytes_read_in, ftmp);
    612               sprintf(tmp, "I am here - %ld", ftell(fin));
    613 //    log_msg(0, tmp);
    614               fread(tmp, 1, 512, fin);
    615               log_msg(0, "tmp = '%s'", tmp);
    616           fwrite(tmp, 1, 512, ftmp);
    617           fclose(ftmp);
    618               fatal_error("Missing terminating block");
    619         }
    620         }
    621     }
    622 
    623   paranoid_free(buf);
    624   paranoid_free(tmp);
    625   log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
    626   return(retval);
     647                fwrite(tmp, 1, bytes_read_in, ftmp);
     648                sprintf(tmp, "I am here - %ld", ftell(fin));
     649//    log_msg(0, tmp);
     650                fread(tmp, 1, 512, fin);
     651                log_msg(0, "tmp = '%s'", tmp);
     652                fwrite(tmp, 1, 512, ftmp);
     653                fclose(ftmp);
     654                fatal_error("Missing terminating block");
     655            }
     656        }
     657    }
     658
     659    paranoid_free(buf);
     660    paranoid_free(tmp);
     661    log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
     662    return (retval);
    627663}
    628664
     
    634670 * @return 0 for success, nonzero for failure.
    635671 */
    636 int dynamically_create_pipes_and_copy_from_them_to_output_file(char*input_device, char*output_fname)
     672int dynamically_create_pipes_and_copy_from_them_to_output_file(char
     673                                                               *input_device,
     674                                                               char
     675                                                               *output_fname)
    637676{
    638   char *curr_fifo;
    639   char *prev_fifo;
    640   char *next_fifo;
    641   char*command;
    642   char *sz_call_to_partimage;
    643   int fifo_number=0;
    644   struct stat buf;
    645   pthread_t partimage_thread;
    646   int res=0;
    647   char *tmpstub;
    648   FILE*fout;
    649   FILE*fin;
    650   char *tmp;
    651 
    652   malloc_string(tmpstub);
    653   malloc_string(curr_fifo);
    654   malloc_string(prev_fifo);
    655   malloc_string(next_fifo);
    656   malloc_string(command);
    657   malloc_string(sz_call_to_partimage);
    658   malloc_string(tmp);
    659 
    660   log_msg(1, "g_tmpfs_mountpt = %s", g_tmpfs_mountpt);
    661   if (g_tmpfs_mountpt && g_tmpfs_mountpt[0] && does_file_exist(g_tmpfs_mountpt))
    662     { strcpy(tmpstub, g_tmpfs_mountpt); }
    663   else
    664     { strcpy(tmpstub, "/tmp"); }
    665   paranoid_system("rm -f /tmp/*PARTIMAGE*");
    666   sprintf(command, "rm -Rf %s/pih-fifo-*", tmpstub);
    667   paranoid_system(command);
    668   sprintf(tmpstub+strlen(tmpstub), "/pih-fifo-%ld", (long int)random());
    669   mkfifo(tmpstub, S_IRWXU|S_IRWXG); // never used, though...
    670   sprintf(curr_fifo, "%s.%03d", tmpstub, fifo_number);
    671   sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number+1);
    672   mkfifo(curr_fifo, S_IRWXU|S_IRWXG);
    673   mkfifo(next_fifo, S_IRWXU|S_IRWXG); // make sure _next_ fifo already exists before we call partimage
    674   sz_call_to_partimage[0]=2;
    675   sz_call_to_partimage[1]=0;
    676   sprintf(sz_call_to_partimage+2, "partimagehack " PARTIMAGE_PARAMS " save %s %s > /tmp/stdout 2> /tmp/stderr", input_device, tmpstub);
    677   log_msg(5, "curr_fifo   = %s", curr_fifo);
    678   log_msg(5, "next_fifo   = %s", next_fifo);
    679   log_msg(5, "sz_call_to_partimage call is '%s'", sz_call_to_partimage+2);
    680   if (!lstat(output_fname, &buf) && S_ISREG(buf.st_mode))
    681     { log_msg(5, "Deleting %s", output_fname); unlink(output_fname); }
    682   if (!(fout = fopen(output_fname, "w"))) { fatal_error("Unable to openout to output_fname"); }
    683   res = pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd, (void*)sz_call_to_partimage);
    684   if (res) { fatal_error("Failed to create thread to call partimage"); }
    685   log_msg(1, "Running fore/back at same time");
    686   log_to_screen("Working with partimagehack...");
    687   while(sz_call_to_partimage[0]>0)
    688     {
    689       sprintf(tmp, "%s\n", NEXT_SUBVOL_PLEASE);
    690       if (fwrite(tmp, 1, 128, fout)!=128) { fatal_error("Cannot write interim block"); }
    691       log_msg(5, "fifo_number=%d", fifo_number);
    692       log_msg(4, "Cat'ting %s", curr_fifo);
    693       if (!(fin = fopen(curr_fifo, "r"))) { fatal_error("Unable to openin from fifo"); }
     677    char *curr_fifo;
     678    char *prev_fifo;
     679    char *next_fifo;
     680    char *command;
     681    char *sz_call_to_partimage;
     682    int fifo_number = 0;
     683    struct stat buf;
     684    pthread_t partimage_thread;
     685    int res = 0;
     686    char *tmpstub;
     687    FILE *fout;
     688    FILE *fin;
     689    char *tmp;
     690
     691    malloc_string(tmpstub);
     692    malloc_string(curr_fifo);
     693    malloc_string(prev_fifo);
     694    malloc_string(next_fifo);
     695    malloc_string(command);
     696    malloc_string(sz_call_to_partimage);
     697    malloc_string(tmp);
     698
     699    log_msg(1, "g_tmpfs_mountpt = %s", g_tmpfs_mountpt);
     700    if (g_tmpfs_mountpt && g_tmpfs_mountpt[0]
     701        && does_file_exist(g_tmpfs_mountpt)) {
     702        strcpy(tmpstub, g_tmpfs_mountpt);
     703    } else {
     704        strcpy(tmpstub, "/tmp");
     705    }
     706    paranoid_system("rm -f /tmp/*PARTIMAGE*");
     707    sprintf(command, "rm -Rf %s/pih-fifo-*", tmpstub);
     708    paranoid_system(command);
     709    sprintf(tmpstub + strlen(tmpstub), "/pih-fifo-%ld",
     710            (long int) random());
     711    mkfifo(tmpstub, S_IRWXU | S_IRWXG); // never used, though...
     712    sprintf(curr_fifo, "%s.%03d", tmpstub, fifo_number);
     713    sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number + 1);
     714    mkfifo(curr_fifo, S_IRWXU | S_IRWXG);
     715    mkfifo(next_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo already exists before we call partimage
     716    sz_call_to_partimage[0] = 2;
     717    sz_call_to_partimage[1] = 0;
     718    sprintf(sz_call_to_partimage + 2,
     719            "partimagehack " PARTIMAGE_PARAMS
     720            " save %s %s > /tmp/stdout 2> /tmp/stderr", input_device,
     721            tmpstub);
     722    log_msg(5, "curr_fifo   = %s", curr_fifo);
     723    log_msg(5, "next_fifo   = %s", next_fifo);
     724    log_msg(5, "sz_call_to_partimage call is '%s'",
     725            sz_call_to_partimage + 2);
     726    if (!lstat(output_fname, &buf) && S_ISREG(buf.st_mode)) {
     727        log_msg(5, "Deleting %s", output_fname);
     728        unlink(output_fname);
     729    }
     730    if (!(fout = fopen(output_fname, "w"))) {
     731        fatal_error("Unable to openout to output_fname");
     732    }
     733    res =
     734        pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd,
     735                       (void *) sz_call_to_partimage);
     736    if (res) {
     737        fatal_error("Failed to create thread to call partimage");
     738    }
     739    log_msg(1, "Running fore/back at same time");
     740    log_to_screen("Working with partimagehack...");
     741    while (sz_call_to_partimage[0] > 0) {
     742        sprintf(tmp, "%s\n", NEXT_SUBVOL_PLEASE);
     743        if (fwrite(tmp, 1, 128, fout) != 128) {
     744            fatal_error("Cannot write interim block");
     745        }
     746        log_msg(5, "fifo_number=%d", fifo_number);
     747        log_msg(4, "Cat'ting %s", curr_fifo);
     748        if (!(fin = fopen(curr_fifo, "r"))) {
     749            fatal_error("Unable to openin from fifo");
     750        }
    694751//      if (!sz_call_to_partimage[0]) { break; }
    695       log_msg(5, "Deleting %s", prev_fifo);
    696       unlink(prev_fifo); // just in case
    697       copy_from_src_to_dest(fin, fout, 'w');
    698       paranoid_fclose(fin);
    699       fifo_number ++;
    700       strcpy(prev_fifo, curr_fifo);
    701       strcpy(curr_fifo, next_fifo);
    702       log_msg(5, "Creating %s", next_fifo);
    703       sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number+1);
    704       mkfifo(next_fifo, S_IRWXU|S_IRWXG); // make sure _next_ fifo exists before we cat this one
    705       system("sync");
    706       sleep(5);
    707     }
    708   sprintf(tmp, "%s\n", NO_MORE_SUBVOLS);
    709   if (fwrite(tmp, 1, 128, fout)!=128) { fatal_error("Cannot write interim block"); }
    710   if (fwrite(tmp, 1, 128, fout)!=128) { fatal_error("Cannot write interim block"); }
    711   if (fwrite(tmp, 1, 128, fout)!=128) { fatal_error("Cannot write interim block"); }
    712   if (fwrite(tmp, 1, 128, fout)!=128) { fatal_error("Cannot write interim block"); }
    713   paranoid_fclose(fout);
    714   log_to_screen("Cleaning up after partimagehack...");
    715   log_msg(3, "Final fifo_number=%d", fifo_number);
    716   paranoid_system("sync");
    717   unlink(next_fifo);
    718   unlink(curr_fifo);
    719   unlink(prev_fifo);
    720   log_to_screen("Finished cleaning up.");
     752        log_msg(5, "Deleting %s", prev_fifo);
     753        unlink(prev_fifo);      // just in case
     754        copy_from_src_to_dest(fin, fout, 'w');
     755        paranoid_fclose(fin);
     756        fifo_number++;
     757        strcpy(prev_fifo, curr_fifo);
     758        strcpy(curr_fifo, next_fifo);
     759        log_msg(5, "Creating %s", next_fifo);
     760        sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number + 1);
     761        mkfifo(next_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo exists before we cat this one
     762        system("sync");
     763        sleep(5);
     764    }
     765    sprintf(tmp, "%s\n", NO_MORE_SUBVOLS);
     766    if (fwrite(tmp, 1, 128, fout) != 128) {
     767        fatal_error("Cannot write interim block");
     768    }
     769    if (fwrite(tmp, 1, 128, fout) != 128) {
     770        fatal_error("Cannot write interim block");
     771    }
     772    if (fwrite(tmp, 1, 128, fout) != 128) {
     773        fatal_error("Cannot write interim block");
     774    }
     775    if (fwrite(tmp, 1, 128, fout) != 128) {
     776        fatal_error("Cannot write interim block");
     777    }
     778    paranoid_fclose(fout);
     779    log_to_screen("Cleaning up after partimagehack...");
     780    log_msg(3, "Final fifo_number=%d", fifo_number);
     781    paranoid_system("sync");
     782    unlink(next_fifo);
     783    unlink(curr_fifo);
     784    unlink(prev_fifo);
     785    log_to_screen("Finished cleaning up.");
    721786
    722787//  if (!lstat(sz_wait_for_this_file, &statbuf))
    723788//    { log_msg(3, "WARNING! %s was not processed.", sz_wait_for_this_file); }
    724   log_msg(2, "Waiting for pthread_join() to join.");
    725   pthread_join(partimage_thread, NULL);
    726   res = sz_call_to_partimage[1];
    727   log_msg(2, "pthread_join() joined OK.");
    728   log_msg(1, "Partimagehack(save) returned %d", res);
    729   unlink(tmpstub);
    730   paranoid_free(curr_fifo);
    731   paranoid_free(prev_fifo);
    732   paranoid_free(next_fifo);
    733   paranoid_free(tmpstub);
    734   paranoid_free(tmp);
    735   paranoid_free(command);
    736   return(res);
     789    log_msg(2, "Waiting for pthread_join() to join.");
     790    pthread_join(partimage_thread, NULL);
     791    res = sz_call_to_partimage[1];
     792    log_msg(2, "pthread_join() joined OK.");
     793    log_msg(1, "Partimagehack(save) returned %d", res);
     794    unlink(tmpstub);
     795    paranoid_free(curr_fifo);
     796    paranoid_free(prev_fifo);
     797    paranoid_free(next_fifo);
     798    paranoid_free(tmpstub);
     799    paranoid_free(tmp);
     800    paranoid_free(command);
     801    return (res);
    737802}
    738803
     
    744809 * @return 0 for success, nonzero for failure.
    745810 */
    746 int feed_into_partimage(char*input_device, char*output_fname)
     811int feed_into_partimage(char *input_device, char *output_fname)
    747812{
    748813// BACKUP
    749   int res;
    750 
    751   if (!does_file_exist(input_device)) { fatal_error ("input device does not exist"); }
    752   if ( !find_home_of_exe("partimagehack")) { fatal_error( "partimagehack not found" ); }
    753   res = dynamically_create_pipes_and_copy_from_them_to_output_file(input_device, output_fname);
    754   return(res);
     814    int res;
     815
     816    if (!does_file_exist(input_device)) {
     817        fatal_error("input device does not exist");
     818    }
     819    if (!find_home_of_exe("partimagehack")) {
     820        fatal_error("partimagehack not found");
     821    }
     822    res =
     823        dynamically_create_pipes_and_copy_from_them_to_output_file
     824        (input_device, output_fname);
     825    return (res);
    755826}
    756827
     
    759830
    760831
    761 int
    762 run_external_binary_with_percentage_indicator_OLD (char *tt, char *cmd)
     832int run_external_binary_with_percentage_indicator_OLD(char *tt, char *cmd)
    763833{
    764834
    765     /*@ int ****************************************************************/
    766   int res = 0;
     835    /*@ int *************************************************************** */
     836    int res = 0;
    767837    int percentage = 0;
    768838    int maxpc = 0;
     
    770840    int last_pcno = 0;
    771841
    772     /*@ buffers ************************************************************/
    773   char *command;
    774   char *tempfile;
    775   char *title;
    776     /*@ pointers ***********************************************************/
    777   FILE *pin;
    778 
    779   malloc_string(title);
    780   malloc_string(command);
    781   malloc_string(tempfile);
    782   assert_string_is_neither_NULL_nor_zerolength(cmd);
    783   assert_string_is_neither_NULL_nor_zerolength(title);
    784 
    785   strcpy (title, tt);
    786   strcpy (tempfile,
    787       call_program_and_get_last_line_of_output
    788       ("mktemp -q /tmp/mondo.XXXXXXXX"));
    789   sprintf (command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    790        tempfile);
    791   log_msg (3, command);
    792   open_evalcall_form (title);
    793   if (!(pin = popen (command, "r")))
    794     {
    795       log_OS_error ("fmt err");
    796       return (1);
    797     }
    798   maxpc = 100;
     842    /*@ buffers *********************************************************** */
     843    char *command;
     844    char *tempfile;
     845    char *title;
     846    /*@ pointers ********************************************************** */
     847    FILE *pin;
     848
     849    malloc_string(title);
     850    malloc_string(command);
     851    malloc_string(tempfile);
     852    assert_string_is_neither_NULL_nor_zerolength(cmd);
     853    assert_string_is_neither_NULL_nor_zerolength(title);
     854
     855    strcpy(title, tt);
     856    strcpy(tempfile,
     857           call_program_and_get_last_line_of_output
     858           ("mktemp -q /tmp/mondo.XXXXXXXX"));
     859    sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
     860            tempfile);
     861    log_msg(3, command);
     862    open_evalcall_form(title);
     863    if (!(pin = popen(command, "r"))) {
     864        log_OS_error("fmt err");
     865        return (1);
     866    }
     867    maxpc = 100;
    799868// OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
    800   for (sleep (1); does_file_exist (tempfile); sleep (1))
    801     {
    802       pcno = grab_percentage_from_last_line_of_file (MONDO_LOGFILE);
    803       if (pcno < 0 || pcno > 100)
    804     {
    805       log_msg (5, "Weird pc#");
    806       continue;
    807     }
    808       percentage = pcno * 100 / maxpc;
    809       if (pcno <= 5 && last_pcno > 40)
    810     {
    811       close_evalcall_form ();
    812       strcpy (title, "Verifying...");
    813       open_evalcall_form (title);
    814     }
    815       last_pcno = pcno;
    816       update_evalcall_form (percentage);
    817     }
     869    for (sleep(1); does_file_exist(tempfile); sleep(1)) {
     870        pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
     871        if (pcno < 0 || pcno > 100) {
     872            log_msg(5, "Weird pc#");
     873            continue;
     874        }
     875        percentage = pcno * 100 / maxpc;
     876        if (pcno <= 5 && last_pcno > 40) {
     877            close_evalcall_form();
     878            strcpy(title, "Verifying...");
     879            open_evalcall_form(title);
     880        }
     881        last_pcno = pcno;
     882        update_evalcall_form(percentage);
     883    }
    818884// OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
    819   close_evalcall_form ();
    820   if (pclose (pin)) { res++; log_OS_error("Unable to pclose"); }
    821   unlink (tempfile);
    822   paranoid_free(command);
    823   paranoid_free(tempfile);
    824   paranoid_free(title);
    825   return (res);
     885    close_evalcall_form();
     886    if (pclose(pin)) {
     887        res++;
     888        log_OS_error("Unable to pclose");
     889    }
     890    unlink(tempfile);
     891    paranoid_free(command);
     892    paranoid_free(tempfile);
     893    paranoid_free(title);
     894    return (res);
    826895}
    827896
     
    829898
    830899
    831 void*run_prog_in_bkgd_then_exit(void*info)
     900void *run_prog_in_bkgd_then_exit(void *info)
    832901{
    833   char*sz_command;
    834   static int res=4444;
    835 
    836   res=999;
    837   sz_command = (char*)info;
    838   log_msg(4, "sz_command = '%s'", sz_command);
    839   res = system(sz_command);
    840   if (res>256 && res!=4444) { res=res / 256; }
    841   log_msg(4, "child res = %d", res);
    842   sz_command[0] = '\0';
    843   pthread_exit((void*)(&res));
     902    char *sz_command;
     903    static int res = 4444;
     904
     905    res = 999;
     906    sz_command = (char *) info;
     907    log_msg(4, "sz_command = '%s'", sz_command);
     908    res = system(sz_command);
     909    if (res > 256 && res != 4444) {
     910        res = res / 256;
     911    }
     912    log_msg(4, "child res = %d", res);
     913    sz_command[0] = '\0';
     914    pthread_exit((void *) (&res));
    844915}
    845916
     
    847918
    848919
    849 int
    850 run_external_binary_with_percentage_indicator_NEW (char*tt, char*cmd)
     920int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd)
    851921{
    852922
    853     /*@ int ****************************************************************/
    854   int res = 0;
     923    /*@ int *************************************************************** */
     924    int res = 0;
    855925    int percentage = 0;
    856926    int maxpc = 100;
    857927    int pcno = 0;
    858928    int last_pcno = 0;
    859     int counter=0;
    860 
    861     /*@ buffers ************************************************************/
    862   char *command;
    863   char *title;
    864     /*@ pointers ***********************************************************/
    865   static int chldres=0;
    866   int *pchild_result;
    867   pthread_t childthread;
    868 
    869   pchild_result = &chldres;
    870   assert_string_is_neither_NULL_nor_zerolength(cmd);
    871   assert_string_is_neither_NULL_nor_zerolength(tt);
    872   *pchild_result = 999;
    873 
    874   malloc_string(title);
    875   malloc_string(command);
    876   strcpy (title, tt);
    877   sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
    878   log_msg (3, "command = '%s'", command);
    879   if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void*)command)))
    880     { fatal_error("Unable to create an archival thread"); }
    881 
    882   log_msg(8, "Parent running");
    883   open_evalcall_form (title);
    884   for (sleep (1); command[0]!='\0'; sleep (1))
    885     {
    886       pcno = grab_percentage_from_last_line_of_file (MONDO_LOGFILE);
    887       if (pcno <= 0 || pcno > 100)
    888     {
    889       log_msg (8, "Weird pc#");
    890       continue;
    891     }
    892       percentage = pcno * 100 / maxpc;
    893       if (pcno <= 5 && last_pcno >= 40)
    894     {
    895       close_evalcall_form ();
    896       strcpy (title, "Verifying...");
    897       open_evalcall_form (title);
    898     }
    899       if (counter++ >= 5)
    900         {
    901       counter=0;
    902           log_file_end_to_screen (MONDO_LOGFILE, "");
    903     }
    904       last_pcno = pcno;
    905       update_evalcall_form (percentage);
    906     }
    907   log_file_end_to_screen (MONDO_LOGFILE, "");
    908   close_evalcall_form ();
    909   pthread_join(childthread, (void*)(&pchild_result));
    910   if (pchild_result) { res = *pchild_result; }
    911   else { res = 666; }
    912   log_msg(3, "Parent res = %d", res);
    913   paranoid_free(command);
    914   paranoid_free(title);
    915   return (res);
     929    int counter = 0;
     930
     931    /*@ buffers *********************************************************** */
     932    char *command;
     933    char *title;
     934    /*@ pointers ********************************************************** */
     935    static int chldres = 0;
     936    int *pchild_result;
     937    pthread_t childthread;
     938
     939    pchild_result = &chldres;
     940    assert_string_is_neither_NULL_nor_zerolength(cmd);
     941    assert_string_is_neither_NULL_nor_zerolength(tt);
     942    *pchild_result = 999;
     943
     944    malloc_string(title);
     945    malloc_string(command);
     946    strcpy(title, tt);
     947    sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
     948    log_msg(3, "command = '%s'", command);
     949    if ((res =
     950         pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit,
     951                        (void *) command))) {
     952        fatal_error("Unable to create an archival thread");
     953    }
     954
     955    log_msg(8, "Parent running");
     956    open_evalcall_form(title);
     957    for (sleep(1); command[0] != '\0'; sleep(1)) {
     958        pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
     959        if (pcno <= 0 || pcno > 100) {
     960            log_msg(8, "Weird pc#");
     961            continue;
     962        }
     963        percentage = pcno * 100 / maxpc;
     964        if (pcno <= 5 && last_pcno >= 40) {
     965            close_evalcall_form();
     966            strcpy(title, "Verifying...");
     967            open_evalcall_form(title);
     968        }
     969        if (counter++ >= 5) {
     970            counter = 0;
     971            log_file_end_to_screen(MONDO_LOGFILE, "");
     972        }
     973        last_pcno = pcno;
     974        update_evalcall_form(percentage);
     975    }
     976    log_file_end_to_screen(MONDO_LOGFILE, "");
     977    close_evalcall_form();
     978    pthread_join(childthread, (void *) (&pchild_result));
     979    if (pchild_result) {
     980        res = *pchild_result;
     981    } else {
     982        res = 666;
     983    }
     984    log_msg(3, "Parent res = %d", res);
     985    paranoid_free(command);
     986    paranoid_free(title);
     987    return (res);
    916988}
    917989
     
    9281000 * @bug Probably unnecessary, as the partimage is just a sparse file. We could use @c dd to restore it.
    9291001 */
    930 int feed_outfrom_partimage(char*output_device, char*input_fifo)
     1002int feed_outfrom_partimage(char *output_device, char *input_fifo)
    9311003{
    9321004// RESTORE
    933   char *tmp;
     1005    char *tmp;
    9341006//  char *command;
    935   char *stuff;
    936   char *sz_call_to_partimage;
    937   pthread_t partimage_thread;
    938   int res;
    939   char *curr_fifo;
    940   char *prev_fifo;
    941   char *oldest_fifo;
    942   char *next_fifo;
    943   char *afternxt_fifo;
    944   int fifo_number=0;
    945   char *tmpstub;
    946   FILE *fin;
    947   FILE *fout;
    948 
    949   malloc_string(curr_fifo);
    950   malloc_string(prev_fifo);
    951   malloc_string(next_fifo);
    952   malloc_string(afternxt_fifo);
    953   malloc_string(oldest_fifo);
    954   malloc_string(tmp);
    955   sz_call_to_partimage = malloc(1000);
    956   malloc_string(stuff);
    957   malloc_string(tmpstub);
    958 
    959   log_msg(1, "output_device=%s", output_device);
    960   log_msg(1, "input_fifo=%s", input_fifo);
     1007    char *stuff;
     1008    char *sz_call_to_partimage;
     1009    pthread_t partimage_thread;
     1010    int res;
     1011    char *curr_fifo;
     1012    char *prev_fifo;
     1013    char *oldest_fifo;
     1014    char *next_fifo;
     1015    char *afternxt_fifo;
     1016    int fifo_number = 0;
     1017    char *tmpstub;
     1018    FILE *fin;
     1019    FILE *fout;
     1020
     1021    malloc_string(curr_fifo);
     1022    malloc_string(prev_fifo);
     1023    malloc_string(next_fifo);
     1024    malloc_string(afternxt_fifo);
     1025    malloc_string(oldest_fifo);
     1026    malloc_string(tmp);
     1027    sz_call_to_partimage = malloc(1000);
     1028    malloc_string(stuff);
     1029    malloc_string(tmpstub);
     1030
     1031    log_msg(1, "output_device=%s", output_device);
     1032    log_msg(1, "input_fifo=%s", input_fifo);
    9611033/* I don't trust g_tmpfs_mountpt
    9621034  if (g_tmpfs_mountpt[0])
     
    9671039    {
    9681040*/
    969       strcpy(tmpstub, "/tmp");
     1041    strcpy(tmpstub, "/tmp");
    9701042//    }
    971   log_msg(1, "tmpstub was %s", tmpstub);
    972   strcpy(stuff, tmpstub);
    973   sprintf(tmpstub, "%s/pih-fifo-%ld", stuff, (long int)random());
    974   log_msg(1, "tmpstub is now %s", tmpstub);
    975   unlink("/tmp/PARTIMAGEHACK-POSITION");
    976   unlink(PAUSE_PARTIMAGE_FNAME);
    977   paranoid_system("rm -f /tmp/*PARTIMAGE*");
    978   sprintf(curr_fifo, "%s.%03d", tmpstub, fifo_number);
    979   sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number+1);
    980   sprintf(afternxt_fifo, "%s.%03d", tmpstub, fifo_number+2);
    981   mkfifo(PIH_LOG, S_IRWXU|S_IRWXG);
    982   mkfifo(curr_fifo, S_IRWXU|S_IRWXG);
    983   mkfifo(next_fifo, S_IRWXU|S_IRWXG); // make sure _next_ fifo already exists before we call partimage
    984   mkfifo(afternxt_fifo, S_IRWXU|S_IRWXG);
    985   system("cat " PIH_LOG " > /dev/null &");
    986   log_msg(3, "curr_fifo   = %s", curr_fifo);
    987   log_msg(3, "next_fifo   = %s", next_fifo);
    988   if (!does_file_exist(input_fifo)) { fatal_error ("input fifo does not exist" ); }
    989   if (!(fin = fopen(input_fifo, "r"))) { fatal_error ("Unable to openin from input_fifo"); }
    990   if ( !find_home_of_exe("partimagehack")) { fatal_error( "partimagehack not found" ); }
    991   sz_call_to_partimage[0]=2;
    992   sz_call_to_partimage[1]=0;
    993   sprintf(sz_call_to_partimage+2, "partimagehack " PARTIMAGE_PARAMS " restore %s %s > /dev/null 2>> %s", output_device, curr_fifo, MONDO_LOGFILE);
    994   log_msg(1, "output_device = %s", output_device);
    995   log_msg(1, "curr_fifo = %s", curr_fifo);
    996   log_msg(1, "sz_call_to_partimage+2 = %s", sz_call_to_partimage+2);
    997   res = pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd, (void*)sz_call_to_partimage);
    998   if (res) { fatal_error("Failed to create thread to call partimage"); }
    999   log_msg(1, "Running fore/back at same time");
    1000   log_msg(2," Trying to openin %s", input_fifo);
    1001   if (!does_file_exist(input_fifo)) { log_msg(2, "Warning - %s does not exist", input_fifo); }
    1002   while(!does_file_exist("/tmp/PARTIMAGEHACK-POSITION"))
    1003     {
    1004       log_msg(6, "Waiting for partimagehack (restore) to start");
    1005       sleep(1);
    1006     }
    1007   while(sz_call_to_partimage[0]>0)
    1008     {
    1009       if (fread(tmp, 1, 128, fin)!=128) { fatal_error("Cannot read introductory block"); }
    1010       if (strstr(tmp, NEXT_SUBVOL_PLEASE))
    1011         { log_msg(2, "Great. Next subvol coming up."); }
    1012       else if (strstr(tmp, NO_MORE_SUBVOLS))
    1013         { log_msg(2, "Great. That was the last subvol."); break; }
    1014       else
    1015         { log_msg(2, "WTF is this? '%s'", tmp); fatal_error("Unknown interim block"); }
    1016       if (feof(fin)) { log_msg(1, "Eof(fin) detected. Breaking."); break; }
    1017       log_msg(3, "Processing subvol %d", fifo_number);
    1018       log_msg(5, "fifo_number=%d", fifo_number);
    1019       if (!(fout = fopen(curr_fifo, "w"))) { fatal_error("Cannot openout to curr_fifo"); }
    1020       log_msg(6, "Deleting %s", oldest_fifo);
    1021       copy_from_src_to_dest(fout, fin, 'r');
    1022       paranoid_fclose(fout);
    1023       fifo_number ++;
    1024       unlink(oldest_fifo); // just in case
    1025       strcpy(oldest_fifo, prev_fifo);
    1026       strcpy(prev_fifo, curr_fifo);
    1027       strcpy(curr_fifo, next_fifo);
    1028       strcpy(next_fifo, afternxt_fifo);
    1029       sprintf(afternxt_fifo, "%s.%03d", tmpstub, fifo_number+2);
    1030       log_msg(6, "Creating %s", afternxt_fifo);
    1031      mkfifo(afternxt_fifo, S_IRWXU|S_IRWXG); // make sure _next_ fifo already exists before we access current fifo
    1032      fflush(fin);
     1043    log_msg(1, "tmpstub was %s", tmpstub);
     1044    strcpy(stuff, tmpstub);
     1045    sprintf(tmpstub, "%s/pih-fifo-%ld", stuff, (long int) random());
     1046    log_msg(1, "tmpstub is now %s", tmpstub);
     1047    unlink("/tmp/PARTIMAGEHACK-POSITION");
     1048    unlink(PAUSE_PARTIMAGE_FNAME);
     1049    paranoid_system("rm -f /tmp/*PARTIMAGE*");
     1050    sprintf(curr_fifo, "%s.%03d", tmpstub, fifo_number);
     1051    sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number + 1);
     1052    sprintf(afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2);
     1053    mkfifo(PIH_LOG, S_IRWXU | S_IRWXG);
     1054    mkfifo(curr_fifo, S_IRWXU | S_IRWXG);
     1055    mkfifo(next_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo already exists before we call partimage
     1056    mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG);
     1057    system("cat " PIH_LOG " > /dev/null &");
     1058    log_msg(3, "curr_fifo   = %s", curr_fifo);
     1059    log_msg(3, "next_fifo   = %s", next_fifo);
     1060    if (!does_file_exist(input_fifo)) {
     1061        fatal_error("input fifo does not exist");
     1062    }
     1063    if (!(fin = fopen(input_fifo, "r"))) {
     1064        fatal_error("Unable to openin from input_fifo");
     1065    }
     1066    if (!find_home_of_exe("partimagehack")) {
     1067        fatal_error("partimagehack not found");
     1068    }
     1069    sz_call_to_partimage[0] = 2;
     1070    sz_call_to_partimage[1] = 0;
     1071    sprintf(sz_call_to_partimage + 2,
     1072            "partimagehack " PARTIMAGE_PARAMS
     1073            " restore %s %s > /dev/null 2>> %s", output_device, curr_fifo,
     1074            MONDO_LOGFILE);
     1075    log_msg(1, "output_device = %s", output_device);
     1076    log_msg(1, "curr_fifo = %s", curr_fifo);
     1077    log_msg(1, "sz_call_to_partimage+2 = %s", sz_call_to_partimage + 2);
     1078    res =
     1079        pthread_create(&partimage_thread, NULL, call_partimage_in_bkgd,
     1080                       (void *) sz_call_to_partimage);
     1081    if (res) {
     1082        fatal_error("Failed to create thread to call partimage");
     1083    }
     1084    log_msg(1, "Running fore/back at same time");
     1085    log_msg(2, " Trying to openin %s", input_fifo);
     1086    if (!does_file_exist(input_fifo)) {
     1087        log_msg(2, "Warning - %s does not exist", input_fifo);
     1088    }
     1089    while (!does_file_exist("/tmp/PARTIMAGEHACK-POSITION")) {
     1090        log_msg(6, "Waiting for partimagehack (restore) to start");
     1091        sleep(1);
     1092    }
     1093    while (sz_call_to_partimage[0] > 0) {
     1094        if (fread(tmp, 1, 128, fin) != 128) {
     1095            fatal_error("Cannot read introductory block");
     1096        }
     1097        if (strstr(tmp, NEXT_SUBVOL_PLEASE)) {
     1098            log_msg(2, "Great. Next subvol coming up.");
     1099        } else if (strstr(tmp, NO_MORE_SUBVOLS)) {
     1100            log_msg(2, "Great. That was the last subvol.");
     1101            break;
     1102        } else {
     1103            log_msg(2, "WTF is this? '%s'", tmp);
     1104            fatal_error("Unknown interim block");
     1105        }
     1106        if (feof(fin)) {
     1107            log_msg(1, "Eof(fin) detected. Breaking.");
     1108            break;
     1109        }
     1110        log_msg(3, "Processing subvol %d", fifo_number);
     1111        log_msg(5, "fifo_number=%d", fifo_number);
     1112        if (!(fout = fopen(curr_fifo, "w"))) {
     1113            fatal_error("Cannot openout to curr_fifo");
     1114        }
     1115        log_msg(6, "Deleting %s", oldest_fifo);
     1116        copy_from_src_to_dest(fout, fin, 'r');
     1117        paranoid_fclose(fout);
     1118        fifo_number++;
     1119        unlink(oldest_fifo);    // just in case
     1120        strcpy(oldest_fifo, prev_fifo);
     1121        strcpy(prev_fifo, curr_fifo);
     1122        strcpy(curr_fifo, next_fifo);
     1123        strcpy(next_fifo, afternxt_fifo);
     1124        sprintf(afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2);
     1125        log_msg(6, "Creating %s", afternxt_fifo);
     1126        mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG);   // make sure _next_ fifo already exists before we access current fifo
     1127        fflush(fin);
    10331128//      system("sync");
    1034       usleep(1000L*100L);
    1035     }
    1036   paranoid_fclose(fin);
    1037   paranoid_system("sync");
    1038   log_msg(1, "Partimagehack has finished. Great. Fin-closing.");
    1039   log_msg(1, "Waiting for pthread_join");
    1040   pthread_join(partimage_thread, NULL);
    1041   res = sz_call_to_partimage[1];
    1042   log_msg(1, "Yay. Partimagehack (restore) returned %d", res);
    1043   unlink(prev_fifo);
    1044   unlink(curr_fifo);
    1045   unlink(next_fifo);
    1046   unlink(afternxt_fifo);
    1047   unlink(PIH_LOG);
    1048   paranoid_free(tmp);
    1049   paranoid_free(sz_call_to_partimage);
    1050   paranoid_free(stuff);
    1051   paranoid_free(prev_fifo);
    1052   paranoid_free(curr_fifo);
    1053   paranoid_free(next_fifo);
    1054   paranoid_free(afternxt_fifo);
    1055   paranoid_free(oldest_fifo);
    1056   paranoid_free(tmpstub);
    1057   return(res);
     1129        usleep(1000L * 100L);
     1130    }
     1131    paranoid_fclose(fin);
     1132    paranoid_system("sync");
     1133    log_msg(1, "Partimagehack has finished. Great. Fin-closing.");
     1134    log_msg(1, "Waiting for pthread_join");
     1135    pthread_join(partimage_thread, NULL);
     1136    res = sz_call_to_partimage[1];
     1137    log_msg(1, "Yay. Partimagehack (restore) returned %d", res);
     1138    unlink(prev_fifo);
     1139    unlink(curr_fifo);
     1140    unlink(next_fifo);
     1141    unlink(afternxt_fifo);
     1142    unlink(PIH_LOG);
     1143    paranoid_free(tmp);
     1144    paranoid_free(sz_call_to_partimage);
     1145    paranoid_free(stuff);
     1146    paranoid_free(prev_fifo);
     1147    paranoid_free(curr_fifo);
     1148    paranoid_free(next_fifo);
     1149    paranoid_free(afternxt_fifo);
     1150    paranoid_free(oldest_fifo);
     1151    paranoid_free(tmpstub);
     1152    return (res);
    10581153}
    1059 
  • trunk/mondo/mondo/common/libmondo-fork.h

    r30 r59  
    11/* libmondo-fork.h
    2  * $Id: libmondo-fork.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    55
    66
    7 char *call_program_and_get_last_line_of_output (char *call);
    8 int run_program_and_log_to_screen (char *basic_call, char *what_i_am_doing);
    9 int run_program_and_log_output (char *program, int);
    10 int eval_call_to_make_ISO (struct s_bkpinfo *bkpinfo,
    11        char *basic_call, char *isofile,
    12        int cd_no, char *logstub, char *what_i_am_doing);
     7char *call_program_and_get_last_line_of_output(char *call);
     8int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing);
     9int run_program_and_log_output(char *program, int);
     10int eval_call_to_make_ISO(struct s_bkpinfo *bkpinfo,
     11                          char *basic_call, char *isofile,
     12                          int cd_no, char *logstub, char *what_i_am_doing);
    1313
    14 int run_external_binary_with_percentage_indicator_OLD (char *tt, char *cmd);
    15 int run_external_binary_with_percentage_indicator_NEW (char *tt, char *cmd);
    16 int copy_from_src_to_dest(FILE*,FILE*,char);
    17 int feed_into_partimage(char*input_device, char*output_fname);
    18 int feed_outfrom_partimage(char*output_device, char*input_fifo);
     14int run_external_binary_with_percentage_indicator_OLD(char *tt, char *cmd);
     15int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd);
     16int copy_from_src_to_dest(FILE *, FILE *, char);
     17int feed_into_partimage(char *input_device, char *output_fname);
     18int feed_outfrom_partimage(char *output_device, char *input_fifo);
  • trunk/mondo/mondo/common/libmondo-gui-EXT.h

    r30 r59  
    22
    33#ifdef _XWIN
    4     #include "X-specific-EXT.h"
     4#include "X-specific-EXT.h"
    55#else
    6     #include "newt-specific-EXT.h"
     6#include "newt-specific-EXT.h"
    77#endif
    8 
    9 
    10 
    11 
    12 
  • trunk/mondo/mondo/common/libmondo-gui.h

    r30 r59  
    11/* libmondo-gui.h
    2  * $Id: libmondo-gui.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    55#ifdef _XWIN
    6     #include "X-specific.h"
     6#include "X-specific.h"
    77#else
    8     #include "newt-specific.h"
     8#include "newt-specific.h"
    99#endif
    10 
    11 
    12 
    13 
    14 
    15 
  • trunk/mondo/mondo/common/libmondo-mountlist-EXT.h

    r30 r59  
    11/* libmondo-mountlist-EXT.h */
    22
    3 extern int evaluate_drive_within_mountlist (struct mountlist_itself *mountlist,
    4                  char *drive, char *flaws_str);
    5 extern int evaluate_mountlist (struct mountlist_itself *mountlist, char *flaws_str_A,
    6             char *flaws_str_B, char *flaws_str_C);
    7 extern int find_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
    8 extern int look_for_duplicate_mountpoints (struct mountlist_itself *mountlist, char *flaws_str);
    9 extern int look_for_weird_formats (struct mountlist_itself *mountlist, char *flaws_str);
    10 extern int make_list_of_drives_in_mountlist(struct mountlist_itself*,struct list_of_disks*);
    11 extern long long size_of_specific_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
     3extern int evaluate_drive_within_mountlist(struct mountlist_itself
     4                                           *mountlist, char *drive,
     5                                           char *flaws_str);
     6extern int evaluate_mountlist(struct mountlist_itself *mountlist,
     7                              char *flaws_str_A, char *flaws_str_B,
     8                              char *flaws_str_C);
     9extern int find_device_in_mountlist(struct mountlist_itself *mountlist,
     10                                    char *device);
     11extern int look_for_duplicate_mountpoints(struct mountlist_itself
     12                                          *mountlist, char *flaws_str);
     13extern int look_for_weird_formats(struct mountlist_itself *mountlist,
     14                                  char *flaws_str);
     15extern int make_list_of_drives_in_mountlist(struct mountlist_itself *,
     16                                            struct list_of_disks *);
     17extern long long size_of_specific_device_in_mountlist(struct
     18                                                      mountlist_itself
     19                                                      *mountlist,
     20                                                      char *device);
    1221
    1322
    1423
    1524
    16 extern int load_mountlist( struct mountlist_itself *mountlist, char *fname);
    17 extern void sort_mountlist_by_device( struct mountlist_itself *mountlist);
    18 extern int save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname);
    19 extern void sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, bool reverse);
    20 extern void  sort_mountlist_by_device( struct mountlist_itself *mountlist);
    21 extern void swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b);
     25extern int load_mountlist(struct mountlist_itself *mountlist, char *fname);
     26extern void sort_mountlist_by_device(struct mountlist_itself *mountlist);
     27extern int save_mountlist_to_disk(struct mountlist_itself *mountlist,
     28                                  char *fname);
     29extern void sort_mountlist_by_mountpoint(struct mountlist_itself
     30                                         *mountlist, bool reverse);
     31extern void sort_mountlist_by_device(struct mountlist_itself *mountlist);
     32extern void swap_mountlist_entries(struct mountlist_itself *mountlist,
     33                                   int a, int b);
  • trunk/mondo/mondo/common/libmondo-mountlist.c

    r49 r59  
    122122            if (device_copies > 1) {
    123123                asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
    124                         device);
     124                         device);
    125125                if (!strstr(flaws_str, tmp)) {
    126126                    log_it(tmp);
     
    184184            return ++res;       // fatal error
    185185        }
    186 
    187186        // BERLIOS : useless ? asprintf(&mountpoint, mountlist->el[pos].mountpoint);
    188187        if (pos > 0 && !npos) {
     
    199198                           || (curr_part_no <= 4 && prev_part_no > 0)) {
    200199                    asprintf(&tmp, " Gap between %ss%d and %d.", drive,
    201                             prev_part_no, curr_part_no);
     200                             prev_part_no, curr_part_no);
    202201                    log_it(tmp);
    203202                    strcat(flaws_str, tmp);
     
    226225            if (device_copies > 1) {
    227226                asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
    228                         device);
     227                         device);
    229228                if (!strstr(flaws_str, tmp)) {
    230229                    log_it(tmp);
     
    268267            /* Check subpartitions */
    269268            for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    270                 asprintf(&device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
     269                asprintf(&device, "%ss%d%c", drive, curr_part_no,
     270                         cur_sp_no);
    271271                pos = find_device_in_mountlist(mountlist, device);
    272272                if (pos < 0) {
     
    276276                /* is it too big? */
    277277                if (curr_part_no > 'h') {
    278                     asprintf(&tmp, " Can only have up to 'h' in disklabel.");
     278                    asprintf(&tmp,
     279                             " Can only have up to 'h' in disklabel.");
    279280                    log_it(tmp);
    280281                    strcat(flaws_str, tmp);
     
    291292                if (device_copies > 1) {
    292293                    asprintf(&tmp, " %s %s's.",
    293                             number_to_text(device_copies), device);
     294                             number_to_text(device_copies), device);
    294295                    if (!strstr(flaws_str, tmp)) {
    295296                        log_it(tmp);
     
    345346    {
    346347        asprintf(&tmp, " %ld MB over-allocated on %s.",
    347                 amount_allocated - physical_drive_size, drive);
     348                 amount_allocated - physical_drive_size, drive);
    348349        log_it(tmp);
    349350        strcat(flaws_str, tmp);
     
    352353    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    353354        asprintf(&tmp, " %ld MB unallocated on %s.",
    354                 physical_drive_size - amount_allocated, drive);
     355                 physical_drive_size - amount_allocated, drive);
    355356        log_it(tmp);
    356         strcat(flaws_str, tmp);
     357        strcat(flaws_str, tmp);
    357358        paranoid_free(tmp);
    358359    }
     
    407408        log_msg(1, tmp);
    408409        paranoid_free(tmp);
    409         return(FALSE);
     410        return (FALSE);
    410411    } else {
    411412        asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
     
    439440                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    440441                asprintf(&tmp, " Gap between %s%d and %d.", drive,
    441                         prev_part_no, curr_part_no);
     442                         prev_part_no, curr_part_no);
    442443                log_it(tmp);
    443444                strcat(flaws_str, tmp);
     
    466467        if (device_copies > 1) {
    467468            asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
    468                     device);
     469                     device);
    469470            if (!strstr(flaws_str, tmp)) {
    470471                log_it(tmp);
     
    512513    if (amount_allocated > physical_drive_size + 1) {
    513514        asprintf(&tmp, " %ld MB over-allocated on %s.",
    514                 amount_allocated - physical_drive_size, drive);
     515                 amount_allocated - physical_drive_size, drive);
    515516        log_it(tmp);
    516517        strcat(flaws_str, tmp);
     
    519520    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    520521        asprintf(&tmp, " %ld MB unallocated on %s.",
    521                 physical_drive_size - amount_allocated, drive);
     522                 physical_drive_size - amount_allocated, drive);
    522523        log_it(tmp);
    523524        strcat(flaws_str, tmp);
     
    578579             DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
    579580            asprintf(&tmp, " Not evaluating %s (I don't know how yet)",
    580                     drivelist->el[i].device);
     581                     drivelist->el[i].device);
    581582            log_it(tmp);
    582583        } else {
     
    668669            && strcmp(curr_mountpoint, "raid")) {
    669670            asprintf(&tmp, " %s %s's.", number_to_text(copies),
    670                     curr_mountpoint);
     671                     curr_mountpoint);
    671672            strcat(flaws_str, tmp);
    672673            log_it(tmp);
     
    707708            && strcmp(mountlist->el[i].mountpoint, "image") != 0) {
    708709            asprintf(&tmp, " %s has unknown format.",
    709                     mountlist->el[i].device);
     710                     mountlist->el[i].device);
    710711            log_it(tmp);
    711712            strcat(flaws_str, tmp);
     
    760761        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    761762            asprintf(&tmp,
    762                     "Not putting %s in list of drives: it's a virtual drive",
    763                     drive);
     763                     "Not putting %s in list of drives: it's a virtual drive",
     764                     drive);
    764765            log_msg(8, tmp);
    765766            paranoid_free(tmp);
     
    770771        if (size == 0) {
    771772            asprintf(&tmp,
    772                     "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
    773                     drive);
     773                     "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
     774                     drive);
    774775            log_msg(8, tmp);
    775776            paranoid_free(tmp);
     
    789790
    790791        asprintf(&tmp,
    791                 "Putting %s with size %lli in list of drives",
    792                 drive, size);
     792                 "Putting %s with size %lli in list of drives",
     793                 drive, size);
    793794        log_msg(8, tmp);
    794795        paranoid_free(tmp);
     
    820821 */
    821822void make_list_of_unallocated_raid_partitions(struct mountlist_itself
    822                                               *output_list,
    823                                               struct mountlist_itself
    824                                               *mountlist,
    825                                               struct raidlist_itself
     823                                              *output_list, struct mountlist_itself
     824                                              *mountlist, struct raidlist_itself
    826825                                              *raidlist)
    827826{
     
    853852                       sizeof(struct mountlist_line));
    854853                asprintf(&tmp,
    855                         "%s is available; user may choose to add it to raid device",
    856                         output_list->el[items - 1].device);
     854                         "%s is available; user may choose to add it to raid device",
     855                         output_list->el[items - 1].device);
    857856                log_it(tmp);
    858857                paranoid_free(tmp);
     
    972971                strcat(mountlist->el[items].device, "_dup");
    973972                asprintf(&tmp,
    974                         "Duplicate entry in mountlist - renaming to %s",
    975                         mountlist->el[items].device);
     973                         "Duplicate entry in mountlist - renaming to %s",
     974                         mountlist->el[items].device);
    976975                log_it(tmp);
    977976                paranoid_free(tmp);
     
    993992
    994993            asprintf(&tmp,
    995                     "%s %s %s %lld %s",
    996                     mountlist->el[items].device,
    997                     mountlist->el[items].mountpoint,
    998                     mountlist->el[items].format,
    999                     mountlist->el[items].size, mountlist->el[items].label);
     994                     "%s %s %s %lld %s",
     995                     mountlist->el[items].device,
     996                     mountlist->el[items].mountpoint,
     997                     mountlist->el[items].format,
     998                     mountlist->el[items].size,
     999                     mountlist->el[items].label);
    10001000
    10011001            log_it(tmp);
  • trunk/mondo/mondo/common/libmondo-mountlist.h

    r30 r59  
    11/* libmondo-mountlist.h
    2  * $Id: libmondo-mountlist.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    55
    6 int evaluate_drive_within_mountlist (struct mountlist_itself *mountlist,
    7                  char *drive, char *flaws_str);
    8 int evaluate_mountlist (struct mountlist_itself *mountlist, char *flaws_str_A,
    9             char *flaws_str_B, char *flaws_str_C);
    10 int find_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
    11 int look_for_duplicate_mountpoints (struct mountlist_itself *mountlist, char *flaws_str);
    12 int look_for_weird_formats (struct mountlist_itself *mountlist, char *flaws_str);
    13 int make_list_of_drives_in_mountlist(struct mountlist_itself*, struct list_of_disks*);
    14 long long size_of_specific_device_in_mountlist (struct mountlist_itself *mountlist, char *device);
     6int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist,
     7                                    char *drive, char *flaws_str);
     8int evaluate_mountlist(struct mountlist_itself *mountlist,
     9                       char *flaws_str_A, char *flaws_str_B,
     10                       char *flaws_str_C);
     11int find_device_in_mountlist(struct mountlist_itself *mountlist,
     12                             char *device);
     13int look_for_duplicate_mountpoints(struct mountlist_itself *mountlist,
     14                                   char *flaws_str);
     15int look_for_weird_formats(struct mountlist_itself *mountlist,
     16                           char *flaws_str);
     17int make_list_of_drives_in_mountlist(struct mountlist_itself *,
     18                                     struct list_of_disks *);
     19long long size_of_specific_device_in_mountlist(struct mountlist_itself
     20                                               *mountlist, char *device);
    1521
    1622
    17 int load_mountlist( struct mountlist_itself *mountlist, char *fname);
    18 void sort_mountlist_by_device( struct mountlist_itself *mountlist);
    19 int save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname);
    20 void sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, bool reverse);
    21 void  sort_mountlist_by_device( struct mountlist_itself *mountlist);
    22 void swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b);
    23 
     23int load_mountlist(struct mountlist_itself *mountlist, char *fname);
     24void sort_mountlist_by_device(struct mountlist_itself *mountlist);
     25int save_mountlist_to_disk(struct mountlist_itself *mountlist,
     26                           char *fname);
     27void sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist,
     28                                  bool reverse);
     29void sort_mountlist_by_device(struct mountlist_itself *mountlist);
     30void swap_mountlist_entries(struct mountlist_itself *mountlist, int a,
     31                            int b);
  • trunk/mondo/mondo/common/libmondo-raid-EXT.h

    r30 r59  
    55#endif
    66
    7 extern bool is_this_raid_personality_registered (int raidno);
    8 extern int which_raid_device_is_using_this_partition (struct raidlist_itself *raidlist,
    9                        char *device);
    10 extern void write_variableINT_to_raid_var_line (struct raid_device_record *raidrec,
    11                     int lino, char *label, int value);
     7extern bool is_this_raid_personality_registered(int raidno);
     8extern int which_raid_device_is_using_this_partition(struct raidlist_itself
     9                                                     *raidlist,
     10                                                     char *device);
     11extern void write_variableINT_to_raid_var_line(struct raid_device_record
     12                                               *raidrec, int lino,
     13                                               char *label, int value);
    1214
    13 extern int where_in_drivelist_is_drive (struct list_of_disks *disklist, char *device);
     15extern int where_in_drivelist_is_drive(struct list_of_disks *disklist,
     16                                       char *device);
    1417
    1518
    1619
    17 extern int load_raidtab_into_raidlist(struct raidlist_itself*,char*);
    18 extern int save_raidlist_to_raidtab(struct raidlist_itself*,char*);
    19 extern void process_raidtab_line(FILE*, struct raid_device_record *, char*, char*);
    20 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char*fname);
    21 extern void save_raidrec_to_file(struct raid_device_record *raidrec, FILE*fout);
     20extern int load_raidtab_into_raidlist(struct raidlist_itself *, char *);
     21extern int save_raidlist_to_raidtab(struct raidlist_itself *, char *);
     22extern void process_raidtab_line(FILE *, struct raid_device_record *,
     23                                 char *, char *);
     24extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist,
     25                                    char *fname);
     26extern void save_raidrec_to_file(struct raid_device_record *raidrec,
     27                                 FILE * fout);
    2228
    23 extern void
    24 save_disklist_to_file(char *listname,
    25               struct list_of_disks *disklist,
    26               FILE *fout);
     29extern void
     30save_disklist_to_file(char *listname,
     31                      struct list_of_disks *disklist, FILE * fout);
    2732
    2833
    2934#ifdef __FreeBSD__
    30 extern void add_disk_to_raid_device(struct vinum_plex *p, char*device_to_add);
    31 extern void add_plex_to_volume(struct vinum_volume *v, int raidlevel, int stripesize);
    32 extern void add_disk_to_raid_device(struct vinum_plex *p, char*device_to_add);
     35extern void add_disk_to_raid_device(struct vinum_plex *p,
     36                                    char *device_to_add);
     37extern void add_plex_to_volume(struct vinum_volume *v, int raidlevel,
     38                               int stripesize);
     39extern void add_disk_to_raid_device(struct vinum_plex *p,
     40                                    char *device_to_add);
    3341extern long long size_spec(char *spec);
    34 extern bool get_option_state (int argc, char ** argv, char * option);
    35 extern char ** get_option_vals (int argc, char ** argv, char * option, int nval);
    36 extern char * get_option_val (int argc, char ** argv, char * option);
    37 extern char ** get_next_vinum_conf_line (FILE *f, int *argc);
    38 extern void add_plex_to_volume(struct vinum_volume *v, int raidlevel, int stripesize);
     42extern bool get_option_state(int argc, char **argv, char *option);
     43extern char **get_option_vals(int argc, char **argv, char *option,
     44                              int nval);
     45extern char *get_option_val(int argc, char **argv, char *option);
     46extern char **get_next_vinum_conf_line(FILE * f, int *argc);
     47extern void add_plex_to_volume(struct vinum_volume *v, int raidlevel,
     48                               int stripesize);
    3949#undef raid_device_record
    4050#else
    41 extern void add_disk_to_raid_device(struct list_of_disks *disklist, char*device_to_add, int index);
     51extern void add_disk_to_raid_device(struct list_of_disks *disklist,
     52                                    char *device_to_add, int index);
    4253#endif
    4354
    44 extern int create_raidtab_from_mdstat(char*,char*);
    45 extern int read_mdstat(struct s_mdstat *mdstat, char*mdstat_file);
     55extern int create_raidtab_from_mdstat(char *, char *);
     56extern int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file);
    4657
    47 extern int create_raidtab_from_mdstat(char*raidtab_fname, char *mdstat_fname);
     58extern int create_raidtab_from_mdstat(char *raidtab_fname,
     59                                      char *mdstat_fname);
  • trunk/mondo/mondo/common/libmondo-raid.h

    r30 r59  
    11/* libmondo-raid.h
    2  * $Id: libmondo-raid.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    77#endif
    88
    9 bool is_this_raid_personality_registered (int raidno);
    10 int which_raid_device_is_using_this_partition (struct raidlist_itself *raidlist,
    11                        char *device);
    12 void write_variableINT_to_raid_var_line (struct raid_device_record *raidrec,
    13                     int lino, char *label, int value);
    14 int where_in_drivelist_is_drive (struct list_of_disks *disklist, char *device);
     9bool is_this_raid_personality_registered(int raidno);
     10int which_raid_device_is_using_this_partition(struct raidlist_itself
     11                                              *raidlist, char *device);
     12void write_variableINT_to_raid_var_line(struct raid_device_record *raidrec,
     13                                        int lino, char *label, int value);
     14int where_in_drivelist_is_drive(struct list_of_disks *disklist,
     15                                char *device);
    1516
    16 int load_raidtab_into_raidlist(struct raidlist_itself*,char*);
    17 int save_raidlist_to_raidtab(struct raidlist_itself*,char*);
    18 void process_raidtab_line(FILE*, struct raid_device_record *, char*, char*);
    19 int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char*fname);
    20 void save_raidrec_to_file(struct raid_device_record *raidrec, FILE*fout);
    21 void
    22 save_disklist_to_file(char *listname,
    23               struct list_of_disks *disklist,
    24               FILE *fout);
     17int load_raidtab_into_raidlist(struct raidlist_itself *, char *);
     18int save_raidlist_to_raidtab(struct raidlist_itself *, char *);
     19void process_raidtab_line(FILE *, struct raid_device_record *, char *,
     20                          char *);
     21int save_raidlist_to_raidtab(struct raidlist_itself *raidlist,
     22                             char *fname);
     23void save_raidrec_to_file(struct raid_device_record *raidrec, FILE * fout);
     24void
     25save_disklist_to_file(char *listname,
     26                      struct list_of_disks *disklist, FILE * fout);
    2527#ifdef __FreeBSD__
    26 void add_disk_to_raid_device(struct vinum_plex *p, char*device_to_add);
    27 void add_plex_to_volume(struct vinum_volume *v, int raidlevel, int stripesize);
    28 void add_disk_to_raid_device(struct vinum_plex *p, char*device_to_add);
     28void add_disk_to_raid_device(struct vinum_plex *p, char *device_to_add);
     29void add_plex_to_volume(struct vinum_volume *v, int raidlevel,
     30                        int stripesize);
     31void add_disk_to_raid_device(struct vinum_plex *p, char *device_to_add);
    2932long long size_spec(char *spec);
    30 bool get_option_state (int argc, char ** argv, char * option);
    31 char ** get_option_vals (int argc, char ** argv, char * option, int nval);
    32 char * get_option_val (int argc, char ** argv, char * option);
    33 char ** get_next_vinum_conf_line (FILE *f, int *argc);
    34 void add_plex_to_volume(struct vinum_volume *v, int raidlevel, int stripesize);
     33bool get_option_state(int argc, char **argv, char *option);
     34char **get_option_vals(int argc, char **argv, char *option, int nval);
     35char *get_option_val(int argc, char **argv, char *option);
     36char **get_next_vinum_conf_line(FILE * f, int *argc);
     37void add_plex_to_volume(struct vinum_volume *v, int raidlevel,
     38                        int stripesize);
    3539#undef raid_device_record
    3640#else
    37 void add_disk_to_raid_device(struct list_of_disks *disklist, char*device_to_add, int index);
     41void add_disk_to_raid_device(struct list_of_disks *disklist,
     42                             char *device_to_add, int index);
    3843#endif
    3944
    4045
    41 int create_raidtab_from_mdstat(char*,char*);
    42 int read_mdstat(struct s_mdstat *mdstat, char*mdstat_file);
     46int create_raidtab_from_mdstat(char *, char *);
     47int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file);
    4348
    44 int create_raidtab_from_mdstat(char*raidtab_fname, char *mdstat_fname);
    45 
     49int create_raidtab_from_mdstat(char *raidtab_fname, char *mdstat_fname);
  • trunk/mondo/mondo/common/libmondo-stream-EXT.h

    r30 r59  
    33
    44
    5 extern int closein_tape (struct s_bkpinfo *bkpinfo);
    6 extern int closeout_tape (struct s_bkpinfo *bkpinfo);
    7 extern int find_tape_device_and_size (char*dev, char*siz);
    8 extern  void insist_on_this_tape_number(int tapeno);
    9 extern void log_tape_pos (void);
    10 extern int maintain_collection_of_recent_archives(char *td, char *latest_fname);
    11 extern int openin_cdstream (struct s_bkpinfo *bkpinfo);
    12 extern int openin_tape (struct s_bkpinfo *bkpinfo);
    13 extern int openout_cdstream (char *cddev, int speed);
    14 extern  int openout_tape (char *tapedev, long internal_tape_block_size);
    15 extern int read_file_from_stream_to_file (struct s_bkpinfo *bkpinfo, char *outfile,
    16                  long long size);
    17 extern int read_file_from_stream_to_stream (struct s_bkpinfo *bkpinfo, FILE * fout,
    18                    long long size);
    19 extern int read_file_from_stream_FULL (struct s_bkpinfo *bkpinfo, char *outfname,
    20               FILE * foutstream, long long orig_size);
    21 extern int read_header_block_from_stream (long long *plen, char *filename,
    22                  int *pcontrol_char);
    23 extern int register_in_tape_catalog(t_archtype type, int number, long aux, char*fn);
    24 extern bool should_we_write_to_next_tape (long mediasize,
    25                   long long length_of_incoming_file);
    26 extern int skip_incoming_files_until_we_find_this_one(char*the_file_I_was_reading);
    27 extern int start_to_read_from_next_tape (struct s_bkpinfo *bkpinfo);
    28 extern int start_to_write_to_next_tape (struct s_bkpinfo *bkpinfo);
    29 extern int write_backcatalog_to_tape (struct s_bkpinfo *bkpinfo);
    30 extern int write_data_disks_to_stream (char *fname);
    31 extern int write_file_to_stream_from_file (struct s_bkpinfo *bkpinfo, char *infile);
    32 extern int write_header_block_to_stream (long long length_of_incoming_file, char *filename,
    33                 int control_char);
    34 extern void wrong_marker (int should_be, int it_is);
    35 extern int closein_cdstream (struct s_bkpinfo *bkpinfo);
    36 extern int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo, long long *ptmp_size, char *tmp_fname, int *pctrl_chr, char*xattr_fname, char*acl_fname);
    37 extern int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char*xattr_fname, char*acl_fname);
    38 
     5extern int closein_tape(struct s_bkpinfo *bkpinfo);
     6extern int closeout_tape(struct s_bkpinfo *bkpinfo);
     7extern int find_tape_device_and_size(char *dev, char *siz);
     8extern void insist_on_this_tape_number(int tapeno);
     9extern void log_tape_pos(void);
     10extern int maintain_collection_of_recent_archives(char *td,
     11                                                  char *latest_fname);
     12extern int openin_cdstream(struct s_bkpinfo *bkpinfo);
     13extern int openin_tape(struct s_bkpinfo *bkpinfo);
     14extern int openout_cdstream(char *cddev, int speed);
     15extern int openout_tape(char *tapedev, long internal_tape_block_size);
     16extern int read_file_from_stream_to_file(struct s_bkpinfo *bkpinfo,
     17                                         char *outfile, long long size);
     18extern int read_file_from_stream_to_stream(struct s_bkpinfo *bkpinfo,
     19                                           FILE * fout, long long size);
     20extern int read_file_from_stream_FULL(struct s_bkpinfo *bkpinfo,
     21                                      char *outfname, FILE * foutstream,
     22                                      long long orig_size);
     23extern int read_header_block_from_stream(long long *plen, char *filename,
     24                                         int *pcontrol_char);
     25extern int register_in_tape_catalog(t_archtype type, int number, long aux,
     26                                    char *fn);
     27extern bool should_we_write_to_next_tape(long mediasize,
     28                                         long long
     29                                         length_of_incoming_file);
     30extern int skip_incoming_files_until_we_find_this_one(char
     31                                                      *the_file_I_was_reading);
     32extern int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo);
     33extern int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo);
     34extern int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
     35extern int write_data_disks_to_stream(char *fname);
     36extern int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo,
     37                                          char *infile);
     38extern int write_header_block_to_stream(long long length_of_incoming_file,
     39                                        char *filename, int control_char);
     40extern void wrong_marker(int should_be, int it_is);
     41extern int closein_cdstream(struct s_bkpinfo *bkpinfo);
     42extern int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo,
     43                                     long long *ptmp_size, char *tmp_fname,
     44                                     int *pctrl_chr, char *xattr_fname,
     45                                     char *acl_fname);
     46extern int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo,
     47                                    char *xattr_fname, char *acl_fname);
  • trunk/mondo/mondo/common/libmondo-stream.c

    r58 r59  
    16361636        }
    16371637        (void) fread(datablock, 1, (size_t) bytes_to_read, fin);
    1638         g_tape_posK +=
    1639             fwrite(datablock, 1, /*bytes_to_read */
    1640                    (size_t) TAPE_BLOCK_SIZE,
    1641                    g_tape_stream) / 1024;
     1638        g_tape_posK += fwrite(datablock, 1, /*bytes_to_read */
     1639                              (size_t) TAPE_BLOCK_SIZE,
     1640                              g_tape_stream) / 1024;
    16421641        if (g_sigpipe) {
    16431642            iamhere("Sigpipe occurred recently. I'll start a new tape.");
  • trunk/mondo/mondo/common/libmondo-stream.h

    r58 r59  
    55
    66
    7 int closein_tape (struct s_bkpinfo *bkpinfo);
    8 int closeout_tape (struct s_bkpinfo *bkpinfo);
    9 int find_tape_device_and_size (char*dev, char*siz);
     7int closein_tape(struct s_bkpinfo *bkpinfo);
     8int closeout_tape(struct s_bkpinfo *bkpinfo);
     9int find_tape_device_and_size(char *dev, char *siz);
    1010void insist_on_this_tape_number(int tapeno);
    11 void log_tape_pos (void);
     11void log_tape_pos(void);
    1212int maintain_collection_of_recent_archives(char *td, char *latest_fname);
    13 int openin_cdstream (struct s_bkpinfo *bkpinfo);
    14 int openin_tape (struct s_bkpinfo *bkpinfo);
    15 int openout_cdstream (char *cddev, int speed);
    16 int openout_tape (char *tapedev, long internal_tape_block_size);
    17 int read_file_from_stream_to_file (struct s_bkpinfo *bkpinfo, char *outfile,
    18                  long long size);
    19 int read_file_from_stream_to_stream (struct s_bkpinfo *bkpinfo, FILE * fout,
    20                    long long size);
    21 int read_file_from_stream_FULL (struct s_bkpinfo *bkpinfo, char *outfname,
    22               FILE * foutstream, long long orig_size);
    23 int read_header_block_from_stream (long long *plen, char *filename,
    24                  int *pcontrol_char);
    25 int register_in_tape_catalog(t_archtype type, int number, long aux, char*fn);
    26 bool should_we_write_to_next_tape (long mediasize,
    27                   long long length_of_incoming_file);
    28 int skip_incoming_files_until_we_find_this_one(char*the_file_I_was_reading);
    29 int start_to_read_from_next_tape (struct s_bkpinfo *bkpinfo);
    30 int start_to_write_to_next_tape (struct s_bkpinfo *bkpinfo);
    31 int write_backcatalog_to_tape (struct s_bkpinfo *bkpinfo);
    32 int write_data_disks_to_stream (char *fname);
    33 int write_file_to_stream_from_file (struct s_bkpinfo *bkpinfo, char *infile);
    34 int write_header_block_to_stream (long long length_of_incoming_file, char *filename,
    35                 int control_char);
    36 void wrong_marker (int should_be, int it_is);
    37 int closein_cdstream (struct s_bkpinfo *bkpinfo);
    38 int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo, long long *ptmp_size, char *tmp_fname, int *pctrl_chr, char*xattr_fname, char*acl_fname);
    39 int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char*xattr_fname, char*acl_fname);
     13int openin_cdstream(struct s_bkpinfo *bkpinfo);
     14int openin_tape(struct s_bkpinfo *bkpinfo);
     15int openout_cdstream(char *cddev, int speed);
     16int openout_tape(char *tapedev, long internal_tape_block_size);
     17int read_file_from_stream_to_file(struct s_bkpinfo *bkpinfo, char *outfile,
     18                                  long long size);
     19int read_file_from_stream_to_stream(struct s_bkpinfo *bkpinfo, FILE * fout,
     20                                    long long size);
     21int read_file_from_stream_FULL(struct s_bkpinfo *bkpinfo, char *outfname,
     22                               FILE * foutstream, long long orig_size);
     23int read_header_block_from_stream(long long *plen, char *filename,
     24                                  int *pcontrol_char);
     25int register_in_tape_catalog(t_archtype type, int number, long aux,
     26                             char *fn);
     27bool should_we_write_to_next_tape(long mediasize,
     28                                  long long length_of_incoming_file);
     29int skip_incoming_files_until_we_find_this_one(char
     30                                               *the_file_I_was_reading);
     31int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo);
     32int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo);
     33int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
     34int write_data_disks_to_stream(char *fname);
     35int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo,
     36                                   char *infile);
     37int write_header_block_to_stream(long long length_of_incoming_file,
     38                                 char *filename, int control_char);
     39void wrong_marker(int should_be, int it_is);
     40int closein_cdstream(struct s_bkpinfo *bkpinfo);
     41int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo,
     42                              long long *ptmp_size, char *tmp_fname,
     43                              int *pctrl_chr, char *xattr_fname,
     44                              char *acl_fname);
     45int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char *xattr_fname,
     46                             char *acl_fname);
  • trunk/mondo/mondo/common/libmondo-string-EXT.h

    r30 r59  
    11/*
    2  * $Id: libmondo-string-EXT.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    5 extern char *build_partition_name (char *partition, const char *drive, int partno);
    6 extern void center_string (char *in_out, int width);
    7 extern char *commarize (char*);
    8 extern char *disklist_entry_to_string (struct list_of_disks *disklist, int lino);
    9 extern long friendly_sizestr_to_sizelong (char *incoming);
    10 extern char *leftpad_string (char *incoming, int width);
    11 extern char *marker_to_string (int marker);
    12 extern char *mountlist_entry_to_string (struct mountlist_itself *mountlist, int lino);
    13 extern char *number_of_disks_as_string (int noof_disks, char *label);
    14 extern char *number_to_text (int i);
    15 extern void resolve_naff_tokens (char *output, char *ip, char *value, char *token);
    16 extern char *slice_fname (long bigfileno, long sliceno, char *path, char *s);
    17 extern int special_dot_char (int i);
    18 extern bool spread_flaws_across_three_lines (char *flaws_str, char *flaws_str_A,
    19                  char *flaws_str_B, char *flaws_str_C,
    20                  int res);
    21 extern int strcmp_inc_numbers (char *stringA, char *stringB);
    22 extern char * strip_afio_output_line (char *input);
    23 extern void strip_spaces (char *in_out);
    24 extern char *trim_empty_quotes (char *incoming);
    25 extern char *truncate_to_drive_name (char *partition);
    26 extern char *turn_raid_level_number_to_string (int raid_level);
     5extern char *build_partition_name(char *partition, const char *drive,
     6                                  int partno);
     7extern void center_string(char *in_out, int width);
     8extern char *commarize(char *);
     9extern char *disklist_entry_to_string(struct list_of_disks *disklist,
     10                                      int lino);
     11extern long friendly_sizestr_to_sizelong(char *incoming);
     12extern char *leftpad_string(char *incoming, int width);
     13extern char *marker_to_string(int marker);
     14extern char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
     15                                       int lino);
     16extern char *number_of_disks_as_string(int noof_disks, char *label);
     17extern char *number_to_text(int i);
     18extern void resolve_naff_tokens(char *output, char *ip, char *value,
     19                                char *token);
     20extern char *slice_fname(long bigfileno, long sliceno, char *path,
     21                         char *s);
     22extern int special_dot_char(int i);
     23extern bool spread_flaws_across_three_lines(char *flaws_str,
     24                                            char *flaws_str_A,
     25                                            char *flaws_str_B,
     26                                            char *flaws_str_C, int res);
     27extern int strcmp_inc_numbers(char *stringA, char *stringB);
     28extern char *strip_afio_output_line(char *input);
     29extern void strip_spaces(char *in_out);
     30extern char *trim_empty_quotes(char *incoming);
     31extern char *truncate_to_drive_name(char *partition);
     32extern char *turn_raid_level_number_to_string(int raid_level);
    2733
    2834extern void printf_silly_message(void);
    2935
    30 extern int compare_two_filelist_entries(void*va,void*vb);
     36extern int compare_two_filelist_entries(void *va, void *vb);
    3137extern int severity_of_difference(char *filename, char *out_reason);
    3238
    33 extern char *percent_media_full_comment (struct s_bkpinfo *bkpinfo);
     39extern char *percent_media_full_comment(struct s_bkpinfo *bkpinfo);
    3440
    3541
    3642extern char *media_descriptor_string(t_bkptype);
    3743
    38 extern inline void turn_wildcard_chars_into_literal_chars(char*out, char*in);
    39 
     44extern inline void turn_wildcard_chars_into_literal_chars(char *out,
     45                                                          char *in);
  • trunk/mondo/mondo/common/libmondo-string.h

    r30 r59  
    11/*
    2  * $Id: libmondo-string.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    5 char *build_partition_name (char *partition, const char *drive, int partno);
    6 void center_string (char *in_out, int width);
    7 char *commarize(char*);
    8 char *disklist_entry_to_string (struct list_of_disks *disklist, int lino);
    9 long friendly_sizestr_to_sizelong (char *incoming);
    10 char *leftpad_string (char *incoming, int width);
    11 char *marker_to_string (int marker);
    12 char *mountlist_entry_to_string (struct mountlist_itself *mountlist, int lino);
    13 char *number_of_disks_as_string (int noof_disks, char *label);
    14 char *number_to_text (int i);
    15 void resolve_naff_tokens (char *output, char *ip, char *value, char *token);
    16 char *slice_fname (long bigfileno, long sliceno, char *path, char *s);
    17 int special_dot_char (int i);
    18 bool spread_flaws_across_three_lines (char *flaws_str, char *flaws_str_A,
    19                  char *flaws_str_B, char *flaws_str_C,
    20                  int res);
    21 int strcmp_inc_numbers (char *stringA, char *stringB);
    22 char * strip_afio_output_line (char *input);
    23 void strip_spaces (char *in_out);
    24 char *trim_empty_quotes (char *incoming);
    25 char *truncate_to_drive_name (char *partition);
    26 char *turn_raid_level_number_to_string (int raid_level);
     5char *build_partition_name(char *partition, const char *drive, int partno);
     6void center_string(char *in_out, int width);
     7char *commarize(char *);
     8char *disklist_entry_to_string(struct list_of_disks *disklist, int lino);
     9long friendly_sizestr_to_sizelong(char *incoming);
     10char *leftpad_string(char *incoming, int width);
     11char *marker_to_string(int marker);
     12char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
     13                                int lino);
     14char *number_of_disks_as_string(int noof_disks, char *label);
     15char *number_to_text(int i);
     16void resolve_naff_tokens(char *output, char *ip, char *value, char *token);
     17char *slice_fname(long bigfileno, long sliceno, char *path, char *s);
     18int special_dot_char(int i);
     19bool spread_flaws_across_three_lines(char *flaws_str, char *flaws_str_A,
     20                                     char *flaws_str_B, char *flaws_str_C,
     21                                     int res);
     22int strcmp_inc_numbers(char *stringA, char *stringB);
     23char *strip_afio_output_line(char *input);
     24void strip_spaces(char *in_out);
     25char *trim_empty_quotes(char *incoming);
     26char *truncate_to_drive_name(char *partition);
     27char *turn_raid_level_number_to_string(int raid_level);
    2728void printf_silly_message(void);
    2829
    29 int compare_two_filelist_entries(void*va,void*vb);
     30int compare_two_filelist_entries(void *va, void *vb);
    3031int severity_of_difference(char *filename, char *out_reason);
    3132
    32 char *percent_media_full_comment (struct s_bkpinfo *bkpinfo);
     33char *percent_media_full_comment(struct s_bkpinfo *bkpinfo);
    3334char *media_descriptor_string(t_bkptype);
    34 inline void turn_wildcard_chars_into_literal_chars(char*out, char*in);
     35inline void turn_wildcard_chars_into_literal_chars(char *out, char *in);
  • trunk/mondo/mondo/common/libmondo-tools-EXT.h

    r30 r59  
    22
    33extern void clean_up_KDE_desktop_if_necessary(void);
    4 extern long get_time ();
     4extern long get_time();
    55extern void (*log_debug_msg) (int debug_level, const char *szFile,
    6                   const char *szFunction, int nLine, const char *fmt, ...);
    7 extern void standard_log_debug_msg (int debug_level, const char *szFile,
    8                     const char *szFunction, int nLine, const char *fmt, ...);
    9 extern int read_cfg_var (char *config_file, char *label, char *value);
    10 extern int write_cfg_var (char *config_file, char *label, char *value);
    11 extern void reset_bkpinfo (struct s_bkpinfo *bkpinfo);
     6                              const char *szFunction, int nLine,
     7                              const char *fmt, ...);
     8extern void standard_log_debug_msg(int debug_level, const char *szFile,
     9                                   const char *szFunction, int nLine,
     10                                   const char *fmt, ...);
     11extern int read_cfg_var(char *config_file, char *label, char *value);
     12extern int write_cfg_var(char *config_file, char *label, char *value);
     13extern void reset_bkpinfo(struct s_bkpinfo *bkpinfo);
    1214#ifdef __FreeBSD__
    13 extern void initialize_raidrec (struct vinum_volume *vv);
     15extern void initialize_raidrec(struct vinum_volume *vv);
    1416#else
    15 extern void initialize_raidrec (struct raid_device_record *raidrec);
     17extern void initialize_raidrec(struct raid_device_record *raidrec);
    1618#endif
    17 extern void log_trace (char *o);
    18 extern int some_basic_system_sanity_checks ();
     19extern void log_trace(char *o);
     20extern int some_basic_system_sanity_checks();
    1921
    2022
     
    2830extern void remount_supermounts_if_necessary(void);
    2931
    30 extern int post_param_configuration (struct s_bkpinfo *bkpinfo);
     32extern int post_param_configuration(struct s_bkpinfo *bkpinfo);
    3133
    3234
     
    4143
    4244extern double get_kernel_version();
    43 extern char * get_architecture();
     45extern char *get_architecture();
    4446
    45 extern bool does_nonMS_partition_exist (void);
     47extern bool does_nonMS_partition_exist(void);
    4648
    4749
     
    5052extern void stop_autofs_if_necessary(void);
    5153extern void restart_autofs_if_necessary(void);
    52 
  • trunk/mondo/mondo/common/libmondo-tools.c

    r58 r59  
    702702                retval++;
    703703            } else {
    704                 strcpy(ip_address, inet_ntoa
    705                        ((struct in_addr)
    706                         *((struct in_addr *) hent->h_addr)));
     704                strcpy(ip_address, inet_ntoa((struct in_addr)
     705                                             *((struct in_addr *) hent->
     706                                               h_addr)));
    707707                strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
    708708                strcpy(bkpinfo->nfs_mount, ip_address);
  • trunk/mondo/mondo/common/libmondo-tools.h

    r30 r59  
    11    /* libmondo-tools.h
    2  * $Id: libmondo-tools.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
    3  */
     2     * $Id$
     3    */
    44
    55void clean_up_KDE_desktop_if_necessary(void);
    66
    7 long get_time ();
     7long get_time();
    88extern void (*log_debug_msg) (int debug_level, const char *szFile,
    9                   const char *szFunction, int nLine, const char *fmt, ...);
    10 void standard_log_debug_msg (int debug_level, const char *szFile,
    11                  const char *szFunction, int nLine, const char *fmt, ...);
    12 int read_cfg_var (char *config_file, char *label, char *value);
    13 int write_cfg_var (char *config_file, char *label, char *value);
    14 void reset_bkpinfo (struct s_bkpinfo *bkpinfo);
     9                              const char *szFunction, int nLine,
     10                              const char *fmt, ...);
     11void standard_log_debug_msg(int debug_level, const char *szFile,
     12                            const char *szFunction, int nLine,
     13                            const char *fmt, ...);
     14int read_cfg_var(char *config_file, char *label, char *value);
     15int write_cfg_var(char *config_file, char *label, char *value);
     16void reset_bkpinfo(struct s_bkpinfo *bkpinfo);
    1517#ifdef __FreeBSD__
    16 void initialize_raidrec (struct vinum_volume *vv);
     18void initialize_raidrec(struct vinum_volume *vv);
    1719#else
    18 void initialize_raidrec (struct raid_device_record *raidrec);
     20void initialize_raidrec(struct raid_device_record *raidrec);
    1921#endif
    20 void log_trace (char *o);
    21 int some_basic_system_sanity_checks ();
     22void log_trace(char *o);
     23int some_basic_system_sanity_checks();
    2224
    2325
     
    2931void remount_supermounts_if_necessary(void);
    3032
    31 int post_param_configuration (struct s_bkpinfo *bkpinfo);
     33int post_param_configuration(struct s_bkpinfo *bkpinfo);
    3234
    3335
    3436int pre_param_configuration(struct s_bkpinfo *bkpinfo);
    3537
    36 long free_space_on_given_partition(char*partition);
     38long free_space_on_given_partition(char *partition);
    3739
    3840
     
    4648
    4749double get_kernel_version();
    48 char * get_architecture();
    49 bool does_nonMS_partition_exist (void);
     50char *get_architecture();
     51bool does_nonMS_partition_exist(void);
    5052void stop_magicdev_if_necessary(void);
    5153void restart_magicdev_if_necessary(void);
    5254void stop_autofs_if_necessary(void);
    5355void restart_autofs_if_necessary(void);
    54 
    55 
  • trunk/mondo/mondo/common/libmondo-verify-EXT.h

    r30 r59  
    22
    33
    4 extern int verify_cd_image (struct s_bkpinfo *);
    5 extern int verify_a_tarball (struct s_bkpinfo *, char *);
    6 extern int verify_an_afioball_from_CD (struct s_bkpinfo *, char *);
    7 extern int verify_an_afioball_from_tape (struct s_bkpinfo *, char *, long long);
    8 extern int verify_a_biggiefile_from_tape (struct s_bkpinfo *, char *, long long);
    9 int verify_afioballs_from_CD (struct s_bkpinfo *);
    10 extern int verify_afioballs_from_tape (struct s_bkpinfo *);
    11 extern int verify_biggiefiles_from_tape (struct s_bkpinfo *);
    12 extern int verify_tape_backups (struct s_bkpinfo *);
    13 extern char *vfy_tball_fname (struct s_bkpinfo *, char *, int);
    14 
    15 
     4extern int verify_cd_image(struct s_bkpinfo *);
     5extern int verify_a_tarball(struct s_bkpinfo *, char *);
     6extern int verify_an_afioball_from_CD(struct s_bkpinfo *, char *);
     7extern int verify_an_afioball_from_tape(struct s_bkpinfo *, char *,
     8                                        long long);
     9extern int verify_a_biggiefile_from_tape(struct s_bkpinfo *, char *,
     10                                         long long);
     11int verify_afioballs_from_CD(struct s_bkpinfo *);
     12extern int verify_afioballs_from_tape(struct s_bkpinfo *);
     13extern int verify_biggiefiles_from_tape(struct s_bkpinfo *);
     14extern int verify_tape_backups(struct s_bkpinfo *);
     15extern char *vfy_tball_fname(struct s_bkpinfo *, char *, int);
  • trunk/mondo/mondo/common/libmondo-verify.c

    r49 r59  
    7474    log_msg(1, "Now scanning log file for 'afio: ' stuff");
    7575    asprintf(&command,
    76             "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s",
    77             stderr_fname, afio_found_changes);
     76             "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s",
     77             stderr_fname, afio_found_changes);
    7878    log_msg(2, command);
    7979    res = system(command);
     
    8585    log_msg(1, "Now scanning log file for 'star: ' stuff");
    8686    asprintf(&command,
    87             "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s",
    88             stderr_fname, afio_found_changes);
     87             "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s",
     88             stderr_fname, afio_found_changes);
    8989    log_msg(2, command);
    9090    res = system(command);
     
    9696    afio_diffs = count_lines_in_file(afio_found_changes);
    9797    asprintf(&command,
    98             "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
    99             ignorefiles_fname, afio_found_changes, afio_found_changes,
    100             changedfiles_fname);
     98             "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
     99             ignorefiles_fname, afio_found_changes, afio_found_changes,
     100             changedfiles_fname);
    101101    log_msg(2, command);
    102102    paranoid_system(command);
     
    150150            retval++;
    151151            asprintf(&tmp, "Warning - missing set(s) between %d and %d\n",
    152                     g_last_afioball_number, set_number - 1);
     152                     g_last_afioball_number, set_number - 1);
    153153            log_to_screen(tmp);
    154154            paranoid_free(tmp);
     
    156156    }
    157157    asprintf(&tmp, "Verifying %s #%d's tarballs",
    158             media_descriptor_string(bkpinfo->backup_media_type),
    159             g_current_media_number);
     158             media_descriptor_string(bkpinfo->backup_media_type),
     159             g_current_media_number);
    160160    open_evalcall_form(tmp);
    161161    paranoid_free(tmp);
     
    177177            verify_an_afioball_from_CD(bkpinfo,
    178178                                       vfy_tball_fname(bkpinfo, mountpoint,
    179                                        set_number));
     179                                                       set_number));
    180180    }
    181181    g_last_afioball_number = set_number - 1;
     
    253253    iamhere("before vsbf");
    254254    asprintf(&tmp, "Verifying %s#%d's big files",
    255             media_descriptor_string(bkpinfo->backup_media_type),
    256             g_current_media_number);
     255             media_descriptor_string(bkpinfo->backup_media_type),
     256             g_current_media_number);
    257257    open_evalcall_form(tmp);
    258258    paranoid_free(tmp);
     
    293293            }
    294294            asprintf(&tmp, "%s/%s", bkpinfo->restore_path,
    295                     biggiestruct.filename);
     295                     biggiestruct.filename);
    296296            log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
    297297            if (!(forig = fopen(tmp, "r"))) {
     
    314314            if (bkpinfo->compression_level > 0) {
    315315                asprintf(&command, "cat %s | %s -dc 2>> %s",
    316                         slice_fname(bigfile_num, slice_num, mountpoint,
    317                                     bkpinfo->zip_suffix), sz_exe,
    318                         MONDO_LOGFILE);
     316                         slice_fname(bigfile_num, slice_num, mountpoint,
     317                                     bkpinfo->zip_suffix), sz_exe,
     318                         MONDO_LOGFILE);
    319319            } else {
    320320                asprintf(&command, "cat %s",
    321                         slice_fname(bigfile_num, slice_num, mountpoint,
    322                                     bkpinfo->zip_suffix));
     321                         slice_fname(bigfile_num, slice_num, mountpoint,
     322                                     bkpinfo->zip_suffix));
    323323            }
    324324            if ((pin = popen(command, "r"))) {
     
    437437        if (strstr(tarball_fname, ".bz2"))
    438438            asprintf(&command,
    439                     "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
    440                     tarball_fname,
    441                     (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
    442                     outlog);
     439                     "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
     440                     tarball_fname,
     441                     (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
     442                     outlog);
    443443    } else {
    444444        bkpinfo->use_star = FALSE;
    445445        asprintf(&command, "afio -r -P %s -Z %s >> %s 2>> %s",
    446                 bkpinfo->zip_exe, tarball_fname, outlog, outlog);
     446                 bkpinfo->zip_exe, tarball_fname, outlog, outlog);
    447447    }
    448448    log_msg(6, "command=%s", command);
     
    454454    } else {
    455455        asprintf(&command, "cat %s | cut -d':' -f%d | sort | uniq", outlog,
    456                 (bkpinfo->use_star) ? 1 : 2);
     456                 (bkpinfo->use_star) ? 1 : 2);
    457457        pin = popen(command, "r");
    458458        if (pin) {
     
    569569    asprintf(&tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
    570570    /* BERLIOS : useless
    571     asprintf(&tmp, "Temporarily copying file from tape to '%s'",
    572             tarball_fname);
    573     log_it(tmp);
    574     paranoid_free(tmp);
    575     */
     571       asprintf(&tmp, "Temporarily copying file from tape to '%s'",
     572       tarball_fname);
     573       log_it(tmp);
     574       paranoid_free(tmp);
     575     */
    576576    read_file_from_stream_to_file(bkpinfo, tarball_fname, size);
    577577    res = verify_a_tarball(bkpinfo, tarball_fname);
    578578    if (res) {
    579579        asprintf(&tmp,
    580                 "Afioball '%s' no longer matches your live filesystem", p);
     580                 "Afioball '%s' no longer matches your live filesystem",
     581                 p);
    581582        log_msg(0, tmp);
    582583        paranoid_free(tmp);
     
    632633    asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
    633634    /* BERLIOS: useless
    634     asprintf(&tmp,
    635             "Temporarily copying biggiefile %s's slices from tape to '%s'",
    636             p, test_file);
    637     log_it(tmp);
    638     paranoid_free(tmp);
    639     */
    640     for (res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
     635       asprintf(&tmp,
     636       "Temporarily copying biggiefile %s's slices from tape to '%s'",
     637       p, test_file);
     638       log_it(tmp);
     639       paranoid_free(tmp);
     640     */
     641    for (res =
     642         read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
    641643         ctrl_chr != BLK_STOP_A_BIGGIE;
    642          res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) {
     644         res =
     645         read_header_block_from_stream(&slice_siz, slice_fnam,
     646                                       &ctrl_chr)) {
    643647        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
    644648            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     
    646650        res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
    647651        unlink(test_file);
    648         res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
     652        res =
     653            read_header_block_from_stream(&slice_siz, slice_fnam,
     654                                          &ctrl_chr);
    649655        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
    650656            log_msg(2, "test_file = %s", test_file);
     
    663669        if (strcmp(biggie_cksum, orig_cksum)) {
    664670            asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
    665                     orig_cksum);
     671                     orig_cksum);
    666672            log_msg(2, tmp);
    667673            paranoid_free(tmp);
    668674
    669675            asprintf(&tmp, "%s has changed on live filesystem",
    670                     biggie_fname);
     676                     biggie_fname);
    671677            log_to_screen(tmp);
    672678            paranoid_free(tmp);
    673679
    674680            asprintf(&tmp, "echo \"%s\" >> /tmp/biggies.changed",
    675                     biggie_fname);
     681                     biggie_fname);
    676682            system(tmp);
    677683            paranoid_free(tmp);
     
    715721
    716722    asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
    717             bkpinfo->tmpdir);
     723             bkpinfo->tmpdir);
    718724    asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
    719             bkpinfo->tmpdir);
     725             bkpinfo->tmpdir);
    720726    log_to_screen("Verifying regular archives on tape");
    721727    total_afioballs = get_last_filelist_number(bkpinfo) + 1;
     
    745751         res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
    746752        asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    747                 bkpinfo->tmpdir, current_afioball_number);
     753                 bkpinfo->tmpdir, current_afioball_number);
    748754        asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
    749                 bkpinfo->tmpdir, current_afioball_number);
     755                 bkpinfo->tmpdir, current_afioball_number);
    750756        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    751757            iamhere("Reading EXAT files from tape");
     
    769775        if (res) {
    770776            asprintf(&tmp, "Afioball %ld differs from live filesystem",
    771                     current_afioball_number);
     777                     current_afioball_number);
    772778            log_to_screen(tmp);
    773779            paranoid_free(tmp);
     
    824830
    825831    asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
    826             bkpinfo->tmpdir);
     832             bkpinfo->tmpdir);
    827833    asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
    828             bkpinfo->tmpdir);
     834             bkpinfo->tmpdir);
    829835    asprintf(&comment, "Verifying all bigfiles.");
    830836    log_to_screen(comment);
    831837    /*
    832     asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
    833     noof_biggiefiles = count_lines_in_file (tmp); // pointless
    834     paranoid_free(tmp);
    835     */
     838       asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
     839       noof_biggiefiles = count_lines_in_file (tmp); // pointless
     840       paranoid_free(tmp);
     841     */
    836842    res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
    837843    if (ctrl_chr != BLK_START_BIGGIEFILES) {
     
    872878        }
    873879        asprintf(&comment, "Verifying bigfile #%ld (%ld K)",
    874                 current_biggiefile_number, (long) size >> 10);
     880                 current_biggiefile_number, (long) size >> 10);
    875881        update_progress_form(comment);
    876882        paranoid_free(comment);
    877883
    878         asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
    879         res = verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
     884        asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path,
     885                 orig_fname);
     886        res =
     887            verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
    880888        paranoid_free(logical_fname);
    881889        retval += res;
     
    929937    asprintf(&mountpoint, "%s/cdrom", bkpinfo->tmpdir);
    930938    asprintf(&fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix,
    931             bkpinfo->nfs_remote_dir, g_current_media_number);
     939             bkpinfo->nfs_remote_dir, g_current_media_number);
    932940
    933941    mkdir(mountpoint, 1777);
     
    935943    if (!does_file_exist(fname)) {
    936944        asprintf(&tmp,
    937                 "%s not found; assuming you backed up to CD; verifying CD...",
    938                 fname);
     945                 "%s not found; assuming you backed up to CD; verifying CD...",
     946                 fname);
    939947        log_msg(2, tmp);
    940948        paranoid_free(tmp);
     
    957965        if (ret) {
    958966            asprintf(&tmp, "make_vn of %s failed; unable to verify ISO\n",
    959                     fname);
     967                     fname);
    960968            log_to_screen(tmp);
    961969            paranoid_free(tmp);
     
    965973#else
    966974        asprintf(&command, "mount -o loop,ro -t iso9660 %s %s", fname,
    967                 mountpoint);
     975                 mountpoint);
    968976#endif
    969977        if (run_program_and_log_output(command, FALSE)) {
    970978            asprintf(&tmp, "%s failed; unable to mount ISO image\n",
    971                     command);
     979                     command);
    972980            log_to_screen(tmp);
    973981            paranoid_free(tmp);
     
    10081016#endif
    10091017    {
    1010         asprintf(&tmp, "%s failed; unable to unmount ISO image\n", command);
     1018        asprintf(&tmp, "%s failed; unable to unmount ISO image\n",
     1019                 command);
    10111020        log_to_screen(tmp);
    10121021        paranoid_free(tmp);
     
    10731082        ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
    10741083    asprintf(&changed_files_fname, "/tmp/changed.files.%d",
    1075             (int) (random() % 32767));
     1084             (int) (random() % 32767));
    10761085    asprintf(&tmp,
    1077             "cat %s | grep -x \"%s:.*\" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\"  > %s",
    1078             MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio",
    1079             changed_files_fname);
     1086             "cat %s | grep -x \"%s:.*\" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\"  > %s",
     1087             MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio",
     1088             changed_files_fname);
    10801089    log_msg(2, "Running command to derive list of changed files");
    10811090    log_msg(2, tmp);
     
    10991108    if (diffs > 0) {
    11001109        asprintf(&tmp, "cp -f %s %s", changed_files_fname,
    1101                 "/tmp/changed.files");
     1110                 "/tmp/changed.files");
    11021111        run_program_and_log_output(tmp, FALSE);
    11031112        paranoid_free(tmp);
    11041113
    11051114        asprintf(&tmp,
    1106                 "%ld files differed from live filesystem; type less %s or less %s to see",
    1107                 diffs, changed_files_fname, "/tmp/changed.files");
     1115                 "%ld files differed from live filesystem; type less %s or less %s to see",
     1116                 diffs, changed_files_fname, "/tmp/changed.files");
    11081117        log_msg(0, tmp);
    11091118        paranoid_free(tmp);
     
    11381147    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    11391148    asprintf(&output, "%s/archives/%d.star.%s", mountpoint, setno,
    1140             bkpinfo->zip_suffix);
     1149             bkpinfo->zip_suffix);
    11411150    if (!does_file_exist(output)) {
    11421151        paranoid_free(output);
    11431152        asprintf(&output, "%s/archives/%d.afio.%s", mountpoint, setno,
    1144                 bkpinfo->zip_suffix);
     1153                 bkpinfo->zip_suffix);
    11451154    }
    11461155    return (output);
  • trunk/mondo/mondo/common/libmondo-verify.h

    r30 r59  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: libmondo-verify.h,v 1.4 2004/06/10 15:29:12 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    2121
    2222 /** externals *************************************************************/
    23 int close_tape (struct s_bkpinfo *);
    24 extern void close_progress_form (void);
    25 extern long count_lines_in_file (char *);
    26 extern bool does_file_exist (char *);
    27 extern void exclude_nonexistent_files (char *);
    28 extern void fatal_error (char *);
    29 extern int find_and_mount_actual_cd (struct s_bkpinfo *, char *);
    30 extern int find_cdrom_device (char *, bool);
    31 extern void finish (int);
    32 extern int get_last_filelist_number (struct s_bkpinfo *);
    33 extern long get_time (void);
    34 extern int grab_percentage_from_last_line_of_file (char *);
    35 extern char *last_line_of_file (char *);
    36 extern long long length_of_file (char *);
    37 extern void log_file_end_to_screen (char *, char *);
    38 extern void log_tape_pos (void);
    39 extern char *marker_to_string (int);
    40 extern void open_evalcall_form (char *);
    41 extern void open_progress_form (char *, char *, char *, char *, long);
    42 extern int openin_tape (struct s_bkpinfo *);
    43 extern void popup_and_OK (char *);
    44 extern bool popup_and_get_string (char *, char *, char *, int);
    45 extern int read_file_from_tape_to_file (struct s_bkpinfo *, char *,
    46                     long long);
    47 extern int read_header_block_from_tape (long long *, char *, int *);
    48 extern void setup_newt_stuff (void);
    49 extern char *slice_fname (long, long, char *, char *);
    50 extern long long space_occupied_by_cd (char *);
    51 extern int strcmp_inc_numbers (char *, char *);
    52 extern char *strip_afio_output_line (char *);
    53 extern char *trim_empty_quotes (char *);
    54 extern void update_evalcall_form (int);
    55 extern void update_progress_form (char *);
    56 extern int write_data_disks_to_tape (char *);
    57 extern int write_header_block_to_tape (long long, char *, int);
    58 extern void wrong_marker (int, int);
     23int close_tape(struct s_bkpinfo *);
     24extern void close_progress_form(void);
     25extern long count_lines_in_file(char *);
     26extern bool does_file_exist(char *);
     27extern void exclude_nonexistent_files(char *);
     28extern void fatal_error(char *);
     29extern int find_and_mount_actual_cd(struct s_bkpinfo *, char *);
     30extern int find_cdrom_device(char *, bool);
     31extern void finish(int);
     32extern int get_last_filelist_number(struct s_bkpinfo *);
     33extern long get_time(void);
     34extern int grab_percentage_from_last_line_of_file(char *);
     35extern char *last_line_of_file(char *);
     36extern long long length_of_file(char *);
     37extern void log_file_end_to_screen(char *, char *);
     38extern void log_tape_pos(void);
     39extern char *marker_to_string(int);
     40extern void open_evalcall_form(char *);
     41extern void open_progress_form(char *, char *, char *, char *, long);
     42extern int openin_tape(struct s_bkpinfo *);
     43extern void popup_and_OK(char *);
     44extern bool popup_and_get_string(char *, char *, char *, int);
     45extern int read_file_from_tape_to_file(struct s_bkpinfo *, char *,
     46                                       long long);
     47extern int read_header_block_from_tape(long long *, char *, int *);
     48extern void setup_newt_stuff(void);
     49extern char *slice_fname(long, long, char *, char *);
     50extern long long space_occupied_by_cd(char *);
     51extern int strcmp_inc_numbers(char *, char *);
     52extern char *strip_afio_output_line(char *);
     53extern char *trim_empty_quotes(char *);
     54extern void update_evalcall_form(int);
     55extern void update_progress_form(char *);
     56extern int write_data_disks_to_tape(char *);
     57extern int write_header_block_to_tape(long long, char *, int);
     58extern void wrong_marker(int, int);
    5959
    6060
     
    6262
    6363
    64 int verify_cd_image (struct s_bkpinfo *);
    65 int verify_a_tarball (struct s_bkpinfo *, char *);
    66 int verify_an_afioball_from_CD (struct s_bkpinfo *, char *);
    67 int verify_an_afioball_from_tape (struct s_bkpinfo *, char *, long long);
    68 int verify_a_biggiefile_from_tape (struct s_bkpinfo *, char *, long long);
    69 int verify_afioballs_from_CD (struct s_bkpinfo *);
    70 int verify_afioballs_from_tape (struct s_bkpinfo *);
    71 int verify_biggiefiles_from_tape (struct s_bkpinfo *);
    72 int verify_tape_backups (struct s_bkpinfo *);
    73 char *vfy_tball_fname (struct s_bkpinfo *, char *, int);
     64int verify_cd_image(struct s_bkpinfo *);
     65int verify_a_tarball(struct s_bkpinfo *, char *);
     66int verify_an_afioball_from_CD(struct s_bkpinfo *, char *);
     67int verify_an_afioball_from_tape(struct s_bkpinfo *, char *, long long);
     68int verify_a_biggiefile_from_tape(struct s_bkpinfo *, char *, long long);
     69int verify_afioballs_from_CD(struct s_bkpinfo *);
     70int verify_afioballs_from_tape(struct s_bkpinfo *);
     71int verify_biggiefiles_from_tape(struct s_bkpinfo *);
     72int verify_tape_backups(struct s_bkpinfo *);
     73char *vfy_tball_fname(struct s_bkpinfo *, char *, int);
    7474
    7575
     
    8282extern FILE *g_tape_stream;
    8383extern long g_start_time, g_minimum_progress, g_maximum_progress,
    84   g_current_progress, g_currentY;
     84    g_current_progress, g_currentY;
    8585extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
    8686extern int g_current_media_number;
    8787
    88 extern void mvaddstr_and_log_it (int, int, char *);
     88extern void mvaddstr_and_log_it(int, int, char *);
    8989
    90 extern bool ask_me_yes_or_no (char *);
    91 extern char *calc_checksum_of_file (char *filename);
    92 extern void center_string (char *, int);
    93 extern void close_evalcall_form (void);
    94 extern int closein_tape (struct s_bkpinfo *);
    95 
    96 
     90extern bool ask_me_yes_or_no(char *);
     91extern char *calc_checksum_of_file(char *filename);
     92extern void center_string(char *, int);
     93extern void close_evalcall_form(void);
     94extern int closein_tape(struct s_bkpinfo *);
  • trunk/mondo/mondo/common/libmondo.h

    r30 r59  
    11/* libmondo.h
    2  * $Id: libmondo.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    1717#include "libmondo-verify-EXT.h"
    1818#include "libmondo-fifo-EXT.h"
    19 
  • trunk/mondo/mondo/common/mondostructures.h

    r58 r59  
    3535 * There is one mountlist_line for each device we're keeping track of in the mountlist.
    3636 */
    37 struct mountlist_line
    38 {
     37struct mountlist_line {
    3938  /**
    4039   * The name of the device (/dev entry) for this mountlist line. Guaranteed to be unique.
    4140   */
    42   char device[64];
     41    char device[64];
    4342
    4443  /**
     
    4645   * This can be "raid", for a RAID subdisk, or "lvm", for an LVM PV.
    4746   */
    48   char mountpoint[256];
     47    char mountpoint[256];
    4948
    5049  /**
     
    5251   * Also, this can be "raid", for a RAID subdisk, or "lvm", for an LVM PV.
    5352   */
    54   char format[64];
     53    char format[64];
    5554
    5655  /**
    5756   * The size in kilobytes of this device. 0 or -1 indicates LVM.
    5857   */
    59   long long size;
     58    long long size;
    6059
    6160  /**
    6261   * For ext2 and ext3, this is the filesystem label (if there is one). If not, this should be "".
    6362   */
    64   char label[256];
     63    char label[256];
    6564};
    6665
     
    7069 * system, so we can recreate them in a nuke restore.
    7170 */
    72 struct mountlist_itself
    73 {
     71struct mountlist_itself {
    7472  /**
    7573   * Number of entries in the mountlist.
    7674   */
    77   int entries;
     75    int entries;
    7876
    7977  /**
    8078   * The list of entries, all @p entries of them.
    8179   */
    82   struct mountlist_line el[MAX_TAPECATALOG_ENTRIES];
     80    struct mountlist_line el[MAX_TAPECATALOG_ENTRIES];
    8381};
    8482
     
    8886 * ensure accurate resizing.
    8987 */
    90 struct mountlist_reference
    91 {
     88struct mountlist_reference {
    9289  /**
    9390   * The number of entries in the list of mountlist references.
    9491   */
    95   int entries;
     92    int entries;
    9693
    9794  /**
    9895   * The array of mountlist_line, allocated on demand.
    9996   */
    100   struct mountlist_line **el;
     97    struct mountlist_line **el;
    10198};
    10299
     
    104101 * A line in @p additional_raid_variables.
    105102 */
    106 struct raid_var_line
    107 {
     103struct raid_var_line {
    108104  /**
    109105   * The label for this RAID variable.
    110106   */
    111   char label[64];
     107    char label[64];
    112108
    113109  /**
    114110   * The value for this RAID variable.
    115111   */
    116   char value[64];
     112    char value[64];
    117113};
    118114
     
    123119 * Each @p raid_device_record has one.
    124120 */
    125 struct additional_raid_variables
    126 {
     121struct additional_raid_variables {
    127122  /**
    128123   * The number of entries in the list.
    129124   */
    130   int entries;
     125    int entries;
    131126
    132127  /**
    133128   * The list of entries, all @p entries of them.
    134129   */
    135   struct raid_var_line el[MAXIMUM_ADDITIONAL_RAID_VARS];
     130    struct raid_var_line el[MAXIMUM_ADDITIONAL_RAID_VARS];
    136131};
    137132
     
    139134 * One disk in a @p list_of_disks.
    140135 */
    141 struct s_disk
    142 {
     136struct s_disk {
    143137#ifdef __FreeBSD__
    144     /**
     138    /**
    145139     * The name of this disk. If blank it will eventually get filled in automatically.
    146140     */
    147     char name[64];
     141    char name[64];
    148142#endif
    149143  /**
    150144   * The device this entry describes.
    151145   */
    152   char device[64];
     146    char device[64];
    153147
    154148  /**
    155149   * Index number of this entry in the whole disklist.
    156150   */
    157   int index;
     151    int index;
    158152};
    159153
     
    161155 * A list of @p s_disk. Every @p raid_device_record has four.
    162156 */
    163 struct list_of_disks
    164 {
     157struct list_of_disks {
    165158  /**
    166159   * The number of entries in the disklist.
    167160   */
    168   int entries;
     161    int entries;
    169162
    170163  /**
    171164   * The entries themselves, all @p entries of them.
    172165   */
    173   struct s_disk el[MAXIMUM_DISKS_PER_RAID_DEV];
     166    struct s_disk el[MAXIMUM_DISKS_PER_RAID_DEV];
    174167};
    175168
     
    177170 * A type of media we're backing up to.
    178171 */
    179 typedef enum { none=0,      ///< No type has been set yet.
    180            iso,     ///< Back up to ISO images.
    181            cdr,     ///< Back up to recordable CDs (do not erase them).
    182            cdrw,        ///< Back up to CD-RWs and blank them first.
    183            dvd,     ///< Back up to DVD+R[W] or DVD-R[W] disks.
    184            cdstream,    ///< Back up to recordable CDs but treat them like a tape streamer.
    185            nfs,     ///< Back up to an NFS mount on the local subnet.
    186            tape,        ///< Back up to tapes.
    187            udev     ///< Back up to another unsupported device; just send a stream of bytes.
    188              } t_bkptype;
     172typedef enum { none = 0,        ///< No type has been set yet.
     173    iso,                        ///< Back up to ISO images.
     174    cdr,                        ///< Back up to recordable CDs (do not erase them).
     175    cdrw,                       ///< Back up to CD-RWs and blank them first.
     176    dvd,                        ///< Back up to DVD+R[W] or DVD-R[W] disks.
     177    cdstream,                   ///< Back up to recordable CDs but treat them like a tape streamer.
     178    nfs,                        ///< Back up to an NFS mount on the local subnet.
     179    tape,                       ///< Back up to tapes.
     180    udev                        ///< Back up to another unsupported device; just send a stream of bytes.
     181} t_bkptype;
    189182
    190183/**
    191184 * A type of file in the catalog of recent archives.
    192185 */
    193 typedef enum { other,       ///< Some other kind of file.
    194            fileset,     ///< An afioball (fileset), optionally compressed.
    195            biggieslice  ///< A slice of a biggiefile, optionally compressed.
    196              } t_archtype;
     186typedef enum { other,           ///< Some other kind of file.
     187    fileset,                    ///< An afioball (fileset), optionally compressed.
     188    biggieslice                 ///< A slice of a biggiefile, optionally compressed.
     189} t_archtype;
    197190
    198191
    199192#ifdef __FreeBSD__
    200193
    201     struct vinum_subdisk
    202     {
    203         char which_device[64];
    204     };
    205 
    206     struct vinum_plex
    207     {
    208         int raidlevel;
    209         int stripesize;
    210         int subdisks;
    211         struct vinum_subdisk sd[MAXIMUM_RAID_DEVS];
    212     };
    213    
    214     struct vinum_volume
    215     {
    216         char volname[64];
    217         int plexes;
    218         struct vinum_plex plex[9];
    219     };
    220    
    221     struct raidlist_itself
    222     {
    223         int entries;
    224         struct list_of_disks spares;
    225         struct list_of_disks disks;
    226         struct vinum_volume el[MAXIMUM_RAID_DEVS];
    227     };
    228    
     194struct vinum_subdisk {
     195    char which_device[64];
     196};
     197
     198struct vinum_plex {
     199    int raidlevel;
     200    int stripesize;
     201    int subdisks;
     202    struct vinum_subdisk sd[MAXIMUM_RAID_DEVS];
     203};
     204
     205struct vinum_volume {
     206    char volname[64];
     207    int plexes;
     208    struct vinum_plex plex[9];
     209};
     210
     211struct raidlist_itself {
     212    int entries;
     213    struct list_of_disks spares;
     214    struct list_of_disks disks;
     215    struct vinum_volume el[MAXIMUM_RAID_DEVS];
     216};
     217
    229218#else
    230219
    231         /**
     220        /**
    232221         * A RAID device in the raidlist.
    233222         */
    234     struct raid_device_record
    235     {
     223struct raid_device_record {
    236224      /**
    237225       * The name of the RAID device (e.g. /dev/md0).
    238226       */
    239       char raid_device[64];
     227    char raid_device[64];
    240228
    241229      /**
    242230       * The RAID level (-1 to 5) we're using.
    243231       */
    244       int raid_level;
     232    int raid_level;
    245233
    246234      /**
    247235       * Whether the disk has a persistent superblock.
    248236       */
    249       int persistent_superblock;
     237    int persistent_superblock;
    250238
    251239      /**
    252240       * The chunk size of this RAID device.
    253241       */
    254       int chunk_size;
     242    int chunk_size;
    255243
    256244      /**
    257245       * A list of the disks to use for storing data.
    258246       */
    259       struct list_of_disks data_disks;
     247    struct list_of_disks data_disks;
    260248
    261249      /**
    262250       * A list of the disks to use as "hot spares" in case one dies.
    263251       */
    264       struct list_of_disks spare_disks;
     252    struct list_of_disks spare_disks;
    265253
    266254      /**
    267255       * A list of the disks to use for storing parity information.
    268256       */
    269       struct list_of_disks parity_disks;
     257    struct list_of_disks parity_disks;
    270258
    271259      /**
    272260       * A list of the disks in this RAID device that have failed\. Rare.
    273261       */
    274       struct list_of_disks failed_disks;
     262    struct list_of_disks failed_disks;
    275263
    276264      /**
    277265       * The additional RAID variables for this device.
    278266       */
    279       struct additional_raid_variables additional_vars;
    280     };
    281 
    282         /**
     267    struct additional_raid_variables additional_vars;
     268};
     269
     270        /**
    283271         * The list of RAID devices.
    284272         * This is intended to be used along with the mountlist, and it can be
    285273         * directly loaded from/saved to raidtab format.
    286274         */
    287     struct raidlist_itself
    288     {
     275struct raidlist_itself {
    289276      /**
    290277       * The number of entries in the list.
    291278       */
    292       int entries;
     279    int entries;
    293280
    294281      /**
    295282       * The RAID devices in the raidlist, all @p entries of them.
    296283       */
    297       struct raid_device_record el[MAXIMUM_RAID_DEVS];
    298     };
     284    struct raid_device_record el[MAXIMUM_RAID_DEVS];
     285};
    299286
    300287#endif
     
    316303 * extremely strange and hard-to-track errors in chop_filelist(), since optimal_set_size is 0.
    317304 */
    318 struct s_bkpinfo
    319 {
     305struct s_bkpinfo {
    320306  /**
    321307   * The device we're backing up to.
     
    324310   * If backup_media_type is anything else, this should be blank.
    325311   */
    326   char media_device[MAX_STR_LEN/4];
     312    char media_device[MAX_STR_LEN / 4];
    327313
    328314  /**
     
    333319   * @bug This should probably be only one variable, not an array.
    334320   */
    335   long media_size[MAX_NOOF_MEDIA+1];
     321    long media_size[MAX_NOOF_MEDIA + 1];
    336322
    337323  /**
     
    347333   * The function which_boot_loader() can help you set this.
    348334   */
    349   char boot_loader;
     335    char boot_loader;
    350336
    351337  /**
     
    354340   * to take truncate_to_drive_name() of where_is_root_mounted().
    355341   */
    356   char boot_device[MAX_STR_LEN/4];
     342    char boot_device[MAX_STR_LEN / 4];
    357343
    358344  /**
     
    361347   * compression_level is 0.
    362348   */
    363   char zip_exe[MAX_STR_LEN/4];
     349    char zip_exe[MAX_STR_LEN / 4];
    364350
    365351  /**
     
    367353   * bz2, gzip uses gz, etc. Do not include the dot.
    368354   */
    369   char zip_suffix[MAX_STR_LEN/4];
     355    char zip_suffix[MAX_STR_LEN / 4];
    370356
    371357  /**
     
    382368   * This is a useful feature, but use at your own risk.
    383369   */
    384   char image_devs[MAX_STR_LEN/4];
     370    char image_devs[MAX_STR_LEN / 4];
    385371
    386372  /**
    387373   * The compression level (1-9) to use. 0 disables compression.
    388374   */
    389   int compression_level;
     375    int compression_level;
    390376
    391377  /**
     
    395381   * and @p zip_suffix.
    396382   */
    397   bool use_lzo;
     383    bool use_lzo;
    398384
    399385  /**
     
    403389   * will be recompressed again.
    404390   */
    405   char do_not_compress_these[MAX_STR_LEN/2];
     391    char do_not_compress_these[MAX_STR_LEN / 2];
    406392
    407393  /**
    408394   * If TRUE, then we should verify a backup.
    409395   */
    410   bool verify_data;
     396    bool verify_data;
    411397
    412398  /**
    413399   * If TRUE, then we should back up some data.
    414400   */
    415   bool backup_data;
     401    bool backup_data;
    416402
    417403  /**
    418404   * If TRUE, then we should restore some data.
    419405   */
    420   bool restore_data;
    421 
    422  
     406    bool restore_data;
     407
     408
    423409  /**
    424410    * If TRUE, then we should backup/restore using star, not afio
    425411   */
    426    bool use_star;
    427    
     412    bool use_star;
     413
    428414
    429415  /**
    430416   * Size of internal block reads/writes
    431417   */
    432   long internal_tape_block_size;
    433    
     418    long internal_tape_block_size;
     419
    434420  /**
    435421   * If TRUE, we're making a CD that will autonuke without confirmation when booted.
    436422   */
    437   bool disaster_recovery;
     423    bool disaster_recovery;
    438424
    439425  /**
     
    442428   * If backup_media_type is anything else, this is ignored.
    443429   */
    444   char isodir[MAX_STR_LEN/4];
     430    char isodir[MAX_STR_LEN / 4];
    445431
    446432/**
     
    449435   * If backup_media_type is anything else, this is ignored.
    450436   */
    451   char prefix[MAX_STR_LEN/4];
     437    char prefix[MAX_STR_LEN / 4];
    452438
    453439  /**
     
    456442   * As such, it needs to be at least as large as the largest CD/DVD/ISO.
    457443   */
    458   char scratchdir[MAX_STR_LEN/4];
     444    char scratchdir[MAX_STR_LEN / 4];
    459445
    460446  /**
     
    464450   * of space here.
    465451   */
    466   char tmpdir[MAX_STR_LEN/4];
     452    char tmpdir[MAX_STR_LEN / 4];
    467453
    468454  /**
     
    471457   * needn't set it yourself.
    472458   */
    473   long optimal_set_size;
     459    long optimal_set_size;
    474460
    475461  /**
    476462   * The type of media we're backing up to.
    477463   */
    478   t_bkptype backup_media_type;
     464    t_bkptype backup_media_type;
    479465//  bool blank_dvd_first;
    480466
     
    484470   * If FALSE, then we use the filelist whose name is specified in @p include_paths.
    485471   */
    486   bool make_filelist;
     472    bool make_filelist;
    487473
    488474  /**
     
    491477   * If you do nothing, "/" will be used.
    492478   */
    493   char include_paths[MAX_STR_LEN];
     479    char include_paths[MAX_STR_LEN];
    494480
    495481  /**
     
    498484   * the scratchdir, and the tempdir are automatically excluded.
    499485   */
    500   char exclude_paths[MAX_STR_LEN];
     486    char exclude_paths[MAX_STR_LEN];
    501487
    502488  /**
     
    505491   * without overwriting the old ones. Ignored during a backup.
    506492   */
    507   char restore_path[MAX_STR_LEN];
     493    char restore_path[MAX_STR_LEN];
    508494
    509495  /**
    510496   * A command to call BEFORE making an ISO image.
    511497   */
    512   char call_before_iso[MAX_STR_LEN];
     498    char call_before_iso[MAX_STR_LEN];
    513499
    514500  /**
    515501   * A command to call to make an ISO image.
    516502   */
    517   char call_make_iso[MAX_STR_LEN];
     503    char call_make_iso[MAX_STR_LEN];
    518504
    519505  /**
    520506   * A command to call to burn the ISO image.
    521507   */
    522   char call_burn_iso[MAX_STR_LEN];
     508    char call_burn_iso[MAX_STR_LEN];
    523509
    524510  /**
    525511   * A command to call AFTER making an ISO image.
    526512   */
    527   char call_after_iso[MAX_STR_LEN];
     513    char call_after_iso[MAX_STR_LEN];
    528514
    529515  /**
     
    531517   * included with Mindi.
    532518   */
    533   char kernel_path[MAX_STR_LEN];
     519    char kernel_path[MAX_STR_LEN];
    534520
    535521  /**
     
    539525   * address form. (Domain names will be resolved in post_param_configuration().)
    540526   */
    541   char nfs_mount[MAX_STR_LEN];
     527    char nfs_mount[MAX_STR_LEN];
    542528
    543529  /**
     
    545531   * the backups in.
    546532   */
    547   char nfs_remote_dir[MAX_STR_LEN];
     533    char nfs_remote_dir[MAX_STR_LEN];
    548534
    549535  /**
     
    551537   * after nuking the system. If "", do not use a post-nuke tarball.
    552538   */
    553   char postnuke_tarball[MAX_STR_LEN];
     539    char postnuke_tarball[MAX_STR_LEN];
    554540
    555541  /**
     
    557543   * writing to them. This has no effect for DVDs.
    558544   */
    559   bool wipe_media_first;
     545    bool wipe_media_first;
    560546
    561547// patch by Herman Kuster 
     
    564550   * (files changed since last full backup) are supported.
    565551   */
    566   int differential;
     552    int differential;
    567553// end patch 
    568554
     
    570556   * If TRUE, then don't eject media when backing up or restoring.
    571557   */
    572   bool please_dont_eject;
     558    bool please_dont_eject;
    573559
    574560  /**
    575561   * The speed of the CD-R[W] drive.
    576562   */
    577   int cdrw_speed;
     563    int cdrw_speed;
    578564
    579565  /**
     
    582568   * it probably falls into this category.
    583569   */
    584   bool manual_cd_tray;
     570    bool manual_cd_tray;
    585571
    586572  /**
     
    588574   * or so. It is useful in testing. Use with care.
    589575   */
    590   bool nonbootable_backup;
     576    bool nonbootable_backup;
    591577
    592578  /**
    593579   * If TRUE, make the bootable CD use LILO/ELILO. If FALSE, use isolinux (the default).
    594580   */
    595   bool make_cd_use_lilo;
     581    bool make_cd_use_lilo;
    596582};
    597583
     
    603589 * @bug My understanding of this structure is horrendously incomplete. Could you please fill in the details?
    604590 */
    605 struct s_node
    606 {
     591struct s_node {
    607592  /**
    608593   * The character this node contains.
    609594   */
    610   char ch;
     595    char ch;
    611596
    612597  /**
    613598   * The node to the right of this one.
    614599   */
    615   struct s_node *right;
     600    struct s_node *right;
    616601
    617602  /**
    618603   * The node below this one.
    619604   */
    620   struct s_node *down;
     605    struct s_node *down;
    621606
    622607  /**
    623608   * If TRUE, then this node is selected (for restore, for example).
    624609   */
    625   bool selected;
     610    bool selected;
    626611
    627612  /**
    628613   * If TRUE, then we want to see the directories below this one.
    629614   */
    630   bool expanded;
     615    bool expanded;
    631616};
    632617
     
    638623 */
    639624struct s_wrapfifo {
    640         /**
     625        /**
    641626     * The device we write to or read from (a FIFO).
    642627     */
    643     char public_device[MAX_STR_LEN/4];
    644 
    645         /**
     628    char public_device[MAX_STR_LEN / 4];
     629
     630        /**
    646631     * The actual device that data from the FIFO should be buffered and written to.
    647632     */
    648     char private_device[MAX_STR_LEN/4];
    649 
    650         /**
     633    char private_device[MAX_STR_LEN / 4];
     634
     635        /**
    651636     * A buffer for holding data read from the FIFO.
    652637     */
    653     char internal_buffer_IN_fifo[MAX_STR_LEN/4];
    654 
    655         /**
     638    char internal_buffer_IN_fifo[MAX_STR_LEN / 4];
     639
     640        /**
    656641     * A buffer for holding data to be written to the FIFO.
    657642     */
    658     char internal_buffer_OUT_fifo[MAX_STR_LEN/4];
    659 
    660         /**
     643    char internal_buffer_OUT_fifo[MAX_STR_LEN / 4];
     644
     645        /**
    661646     * If TRUE, then we're writing directly to the tape streamer; if FALSE, we're writing to the FIFO.
    662647     */
     
    672657 */
    673658struct s_filename_and_lstat_info {
    674         /**
     659        /**
    675660     * The filename of the file this structure is describing.
    676661     */
    677662    char filename[MAX_STR_LEN];
    678663
    679         /**
     664        /**
    680665     * The MD5 checksum (32 hex digits) of this file.
    681666     */
    682667    char checksum[64];
    683668
    684         /**
     669        /**
    685670     * Unused; kept for backwards compatibility.
    686671     */
    687672    char for_backward_compatibility;
    688673
    689         /**
     674        /**
    690675     * The stat buffer for this file.
    691676     * Generated with a call to <tt>lstat(&(struc->properties))</tt> where @p struc
     
    701686 */
    702687struct s_filelist_entry {
    703         /**
     688        /**
    704689     * The name of the file.
    705690     */
    706691    char filename[MAX_STR_LEN];
    707         /**
     692        /**
    708693     * The severity if the file has changed between the backup and live filesystem.
    709694     * This is on a scale from 1 to 3, 3 being the most important. File patterns which cause
     
    737722     * @see severity_of_difference
    738723     */
    739         int severity;
     724    int severity;
    740725};
    741726
     
    745730 */
    746731struct s_filelist {
    747         /**
     732        /**
    748733     * The number of entries in the list.
    749734     */
    750         int entries;
    751 
    752         /**
     735    int entries;
     736
     737        /**
    753738     * The entries themselves, all @p entries of them.
    754739     */
     
    761746 */
    762747struct s_tapecat_entry {
    763         /**
     748        /**
    764749     * The type of archive it is (afioball, slice, or something else).
    765750     */
    766751    t_archtype type;
    767752
    768         /**
     753        /**
    769754     * The filelist number or biggiefile (not slice!) number.
    770755     */
    771756    int number;
    772757
    773         /**
     758        /**
    774759     * The slice number if it's a biggiefile.
    775760     */
    776761    long aux;
    777762
    778         /**
     763        /**
    779764     * The tape position at the point this entry was added.
    780765     */
    781766    long long tape_posK;
    782767
    783         /**
     768        /**
    784769     * The filename of the file cataloged here.
    785770     */
    786     char fname[MAX_TAPECAT_FNAME_LEN+1];
     771    char fname[MAX_TAPECAT_FNAME_LEN + 1];
    787772};
    788773
     
    792777 */
    793778struct s_tapecatalog {
    794         /**
     779        /**
    795780     * The number of entries in the tape catalog.
    796781     */
    797782    int entries;
    798783
    799         /**
     784        /**
    800785     * The entries themselves, all @p entries of them.
    801786     */
     
    806791
    807792struct s_mdrec {
    808     int md;     // /dev/mdN
    809     int raidlevel;  // 0, 1, 5
     793    int md;                     // /dev/mdN
     794    int raidlevel;              // 0, 1, 5
    810795    struct list_of_disks disks;
    811796    int progress;
     
    816801    struct s_mdrec el[MAXIMUM_RAID_DEVS];
    817802};
    818 
  • trunk/mondo/mondo/common/my-stuff.h

    r41 r59  
    207207#if defined(DEBUG) && !__cplusplus
    208208int count;
    209 char trace_log[255];        /*buffer for logging */
     209char trace_log[255];            /*buffer for logging */
    210210char *trace_log_ptr;
    211 #endif /* DEBUG */
     211#endif                          /* DEBUG */
    212212
    213213#define IA64_BOOT_SIZE "8192"   /* Should be coherent with mindi */
     
    240240#undef assert
    241241
    242 extern void _mondo_assert_fail (const char *file, const char *function, int line, const char *exp);
     242extern void _mondo_assert_fail(const char *file, const char *function,
     243                               int line, const char *exp);
    243244
    244245/**
     
    251252#endif
    252253
    253 #define CRC_M16 0xA001      ///< Mask for crc16.
    254 #define CRC_MTT 0x1021      ///< Mask for crc-ccitt.
    255 
    256 #define FALSE 0         ///< The ubiquitous FALSE macro.
    257 #define TRUE 1          ///< The even more ubiquitous TRUE macro.
    258 
    259 #define SCREEN_LENGTH 25            ///< The default size of the screen.
    260 #define NOOF_ERR_LINES 6            ///< The number of lines of log output to keep at the bottom of the screen.
     254#define CRC_M16 0xA001          ///< Mask for crc16.
     255#define CRC_MTT 0x1021          ///< Mask for crc-ccitt.
     256
     257#define FALSE 0                 ///< The ubiquitous FALSE macro.
     258#define TRUE 1                  ///< The even more ubiquitous TRUE macro.
     259
     260#define SCREEN_LENGTH 25        ///< The default size of the screen.
     261#define NOOF_ERR_LINES 6        ///< The number of lines of log output to keep at the bottom of the screen.
    261262#define ARBITRARY_MAXIMUM 500   ///< The maximum number of items showing at once in the mountlist or filelist editor.
    262 #define MAX_TAPECATALOG_ENTRIES 4096 ///< The maximum number of entries in the tape catalog.
    263 #define MAX_STR_LEN 380     ///< The maximum length of almost all @p char buffers in Mondo.
     263#define MAX_TAPECATALOG_ENTRIES 4096    ///< The maximum number of entries in the tape catalog.
     264#define MAX_STR_LEN 380         ///< The maximum length of almost all @p char buffers in Mondo.
    264265#define MAXIMUM_RAID_DEVS 32    ///< The maximum number of RAID devices in the raidlist.
    265 #define MAXIMUM_ADDITIONAL_RAID_VARS 32 ///< The maximum number of additional RAID variables per RAID device in the raidlist.
    266 #define MAXIMUM_DISKS_PER_RAID_DEV 32 ///< The maximum number of disks per RAID device in the raidtab.
    267 
    268 #define RAIDTAB_FNAME "/etc/raidtab" ///< The filename of the raidtab file, at least on Linux.
    269 
    270 #define BLK_START_OF_BACKUP     1 ///< Marker block: start a backup.
    271 #define BLK_START_OF_TAPE       2 ///< Marker block: start a tape.
    272 #define BLK_START_AFIOBALLS 10 ///< Marker block: start the afioball section.
    273 #define BLK_STOP_AFIOBALLS  19 ///< Marker block: stop the afioball section.
    274 #define BLK_START_AN_AFIO_OR_SLICE      20 ///< Marker block: start an afioball or a slice.
    275 #define BLK_STOP_AN_AFIO_OR_SLICE   29 ///< Marker block: stop an afioball or a slice.
    276 #define BLK_START_BIGGIEFILES   30 ///< Marker block: start the biggiefile section.
    277 #define BLK_STOP_BIGGIEFILES    39 ///< Marker block: stop the biggiefile section.
    278 #define BLK_START_A_NORMBIGGIE  40 ///< Marker block: start a normal biggiefile.
    279 #define BLK_START_A_PIHBIGGIE   41 ///< Marker block: start a partimagehack'd biggiefile
    280 #define BLK_START_EXTENDED_ATTRIBUTES 45 ///< Marker block: start xattr/acl info
    281 #define BLK_STOP_EXTENDED_ATTRIBUTES 46 ///< Marker block: stop xattr/acl info
     266#define MAXIMUM_ADDITIONAL_RAID_VARS 32 ///< The maximum number of additional RAID variables per RAID device in the raidlist.
     267#define MAXIMUM_DISKS_PER_RAID_DEV 32   ///< The maximum number of disks per RAID device in the raidtab.
     268
     269#define RAIDTAB_FNAME "/etc/raidtab"    ///< The filename of the raidtab file, at least on Linux.
     270
     271#define BLK_START_OF_BACKUP     1   ///< Marker block: start a backup.
     272#define BLK_START_OF_TAPE       2   ///< Marker block: start a tape.
     273#define BLK_START_AFIOBALLS 10  ///< Marker block: start the afioball section.
     274#define BLK_STOP_AFIOBALLS  19  ///< Marker block: stop the afioball section.
     275#define BLK_START_AN_AFIO_OR_SLICE      20  ///< Marker block: start an afioball or a slice.
     276#define BLK_STOP_AN_AFIO_OR_SLICE   29  ///< Marker block: stop an afioball or a slice.
     277#define BLK_START_BIGGIEFILES   30  ///< Marker block: start the biggiefile section.
     278#define BLK_STOP_BIGGIEFILES    39  ///< Marker block: stop the biggiefile section.
     279#define BLK_START_A_NORMBIGGIE  40  ///< Marker block: start a normal biggiefile.
     280#define BLK_START_A_PIHBIGGIE   41  ///< Marker block: start a partimagehack'd biggiefile
     281#define BLK_START_EXTENDED_ATTRIBUTES 45    ///< Marker block: start xattr/acl info
     282#define BLK_STOP_EXTENDED_ATTRIBUTES 46 ///< Marker block: stop xattr/acl info
    282283#define BLK_START_EXAT_FILE     47
    283284#define BLK_STOP_EXAT_FILE      48
    284 #define BLK_STOP_A_BIGGIE   59 ///< Marker block: stop a biggiefile.
    285 #define BLK_START_FILE          80 ///< Marker block: start a file (non-afio or slice).
    286 #define BLK_STOP_FILE           89 ///< Marker block: stop a file (non-afio or slice).
    287 #define BLK_END_OF_TAPE         100 ///< Marker block: end of tape.
    288 #define BLK_END_OF_BACKUP       101 ///< Marker block: end of backup.
    289 #define BLK_ABORTED_BACKUP      102 ///< Marker block: backup was aborted.
     285#define BLK_STOP_A_BIGGIE   59  ///< Marker block: stop a biggiefile.
     286#define BLK_START_FILE          80  ///< Marker block: start a file (non-afio or slice).
     287#define BLK_STOP_FILE           89  ///< Marker block: stop a file (non-afio or slice).
     288#define BLK_END_OF_TAPE         100 ///< Marker block: end of tape.
     289#define BLK_END_OF_BACKUP       101 ///< Marker block: end of backup.
     290#define BLK_ABORTED_BACKUP      102 ///< Marker block: backup was aborted.
    290291
    291292/// The external tape blocksize.
    292293#ifdef EXTTAPE
    293   #define TAPE_BLOCK_SIZE (long)EXTTAPE
     294#define TAPE_BLOCK_SIZE (long)EXTTAPE
    294295#else
    295   #define TAPE_BLOCK_SIZE 131072L   /* was 8192; 06/2002-->65536; 11/2002-->131072 */
    296 #endif
    297 
    298   #define DEFAULT_INTERNAL_TAPE_BLOCK_SIZE 32768 // Nov 2003?
    299 
    300 
    301 
    302 
    303 #define SLICE_SIZE 4096     ///< The size of a slice of a biggiefile.
     296#define TAPE_BLOCK_SIZE 131072L /* was 8192; 06/2002-->65536; 11/2002-->131072 */
     297#endif
     298
     299#define DEFAULT_INTERNAL_TAPE_BLOCK_SIZE 32768  // Nov 2003?
     300
     301
     302
     303
     304#define SLICE_SIZE 4096         ///< The size of a slice of a biggiefile.
    304305
    305306
     
    349350/**
    350351 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image.
    351  */ // -b images/mindi-boot.2880.img
     352     */// -b images/mindi-boot.2880.img
    352353#define MONDO_GROWISOFS_REGULAR_ELILO     "growisofs -use-the-force-luke -no-emul-boot -b images/mindi-boot.2880.img -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v"
    353354
    354355/**
    355356 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image.
    356  */ // -b images/mindi-boot.2880.img
     357     */// -b images/mindi-boot.2880.img
    357358#define MONDO_GROWISOFS_REGULAR_LILO     "growisofs -no-emul-boot -b isolinux.bin -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v"
    358359
     
    460461/** @def CP_BIN The GNU @c cp binary to use. */
    461462#ifdef __FreeBSD__
    462   #define VANILLA_SCSI_CDROM    "/dev/cd0"
    463   #define VANILLA_SCSI_TAPE "/dev/sa0"
    464   #define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE    "/dev/vinum/"
    465   #define RAID_DEVICE_STUB  DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
    466   #define SANE_FORMATS      "swap image msdosfs nfs ntfs raid lvm ffs ufs ext2fs"
    467   #define ALT_TAPE      "/dev/ast0"
    468   #define MKE2FS_OR_NEWFS   "newfs"
    469   #define CP_BIN        "gcp"
     463#define VANILLA_SCSI_CDROM  "/dev/cd0"
     464#define VANILLA_SCSI_TAPE   "/dev/sa0"
     465#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/vinum/"
     466#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
     467#define SANE_FORMATS        "swap image msdosfs nfs ntfs raid lvm ffs ufs ext2fs"
     468#define ALT_TAPE        "/dev/ast0"
     469#define MKE2FS_OR_NEWFS "newfs"
     470#define CP_BIN      "gcp"
    470471#else
    471   #define VANILLA_SCSI_CDROM    "/dev/scd0"
    472   #define VANILLA_SCSI_TAPE "/dev/st0"
    473   #define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE    "/dev/md"
    474   #define RAID_DEVICE_STUB  DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
    475   #define SANE_FORMATS      "swap image vfat ext2 ext3 xfs vfs jfs reiserfs dos minix coda nfs ntfs hpfs raid lvm"
    476   #define ALT_TAPE      "/dev/ht0"
    477   #define MKE2FS_OR_NEWFS   "mke2fs"
    478   #define CP_BIN        "cp"
     472#define VANILLA_SCSI_CDROM  "/dev/scd0"
     473#define VANILLA_SCSI_TAPE   "/dev/st0"
     474#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/md"
     475#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
     476#define SANE_FORMATS        "swap image vfat ext2 ext3 xfs vfs jfs reiserfs dos minix coda nfs ntfs hpfs raid lvm"
     477#define ALT_TAPE        "/dev/ht0"
     478#define MKE2FS_OR_NEWFS "mke2fs"
     479#define CP_BIN      "cp"
    479480#endif
    480481
     
    496497 */
    497498#define AFIOBALL_FNAME_RAW_SZ (bkpinfo->use_star)?"%s/tmpfs/%ld.star.%s":"%s/tmpfs/%ld.afio.%s"
    498 #define ARCH_THREADS 2 ///< The number of simultaneous threads running afio in the background.
    499 #define ARCH_BUFFER_NUM (ARCH_THREADS*4) // Number of permissible queued afio files
    500 #define FORTY_SPACES "                                         " ///< 40 spaces.
    501 #define PPCFG_RAMDISK_SIZE 250 ///< Size of the tmpfs, in megabytes, to attempt to mount (to speed up Mondo).
     499#define ARCH_THREADS 2          ///< The number of simultaneous threads running afio in the background.
     500#define ARCH_BUFFER_NUM (ARCH_THREADS*4)    // Number of permissible queued afio files
     501#define FORTY_SPACES "                                         "    ///< 40 spaces.
     502#define PPCFG_RAMDISK_SIZE 250  ///< Size of the tmpfs, in megabytes, to attempt to mount (to speed up Mondo).
    502503
    503504#define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE"
     
    514515#define log_msg(level, format, args...) log_debug_msg(level, __FILE__, __FUNCTION__, __LINE__, format, ## args)
    515516
    516 #define DEFAULT_DVD_DISK_SIZE 4380 ///< The default size (in MB) of a DVD disk, unless the user says otherwise.
    517 
    518 #define DEFAULT_DEBUG_LEVEL 4 ///< By default, don't log messages with a loglevel higher than this.
    519 
    520 #define SZ_PARTIMAGE_VOLSIZE "1048576" // was 4096
     517#define DEFAULT_DVD_DISK_SIZE 4380  ///< The default size (in MB) of a DVD disk, unless the user says otherwise.
     518
     519#define DEFAULT_DEBUG_LEVEL 4   ///< By default, don't log messages with a loglevel higher than this.
     520
     521#define SZ_PARTIMAGE_VOLSIZE "1048576"  // was 4096
    521522#define PARTIMAGE_PARAMS "-z0 -V" SZ_PARTIMAGE_VOLSIZE " -o -b -d -g1"
    522523
     
    524525#define MNT_FLOPPY "/mnt/floppy"
    525526
    526 #define FREELOADER // You're not a paying customer
     527#define FREELOADER              // You're not a paying customer
    527528#define DEFAULT_MR_LOGLEVEL 4
    528529
     
    530531#define _GNU_SOURCE
    531532
    532 #endif /* _MY_STUFF_H_ */
     533#endif                          /* _MY_STUFF_H_ */
  • trunk/mondo/mondo/common/newt-specific-EXT.h

    r30 r59  
    22
    33
    4 extern bool ask_me_yes_or_no (char *prompt);
    5 extern bool ask_me_OK_or_cancel (char *prompt);
    6 extern void close_evalcall_form (void);
    7 extern void close_progress_form ();
    8 extern void fatal_error (char *error_string);
    9 extern void finish (int signal);
    10 extern void mvaddstr_and_log_it (int y, int x, char *output);
    11 extern void open_evalcall_form (char *title);
    12 extern void open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val);
    13 extern void log_file_end_to_screen (char *filename, char *grep_for_me);
    14 extern void log_to_screen (const char *fmt, ...);
    15 extern void popup_and_OK (char *prompt);
    16 extern bool popup_and_get_string (char *title, char *b, char *output, int maxsize);
    17 extern bool popup_with_buttons (char *p, char *button1, char *button2);
    18 extern void refresh_log_screen ();
    19 extern void setup_newt_stuff ();
    20 extern void update_evalcall_form_ratio (int num, int denom);
    21 extern void update_evalcall_form (int curr);
    22 extern void update_progress_form (char *blurb3);
    23 extern void update_progress_form_full (char *blurb1, char *blurb2, char *blurb3);
     4extern bool ask_me_yes_or_no(char *prompt);
     5extern bool ask_me_OK_or_cancel(char *prompt);
     6extern void close_evalcall_form(void);
     7extern void close_progress_form();
     8extern void fatal_error(char *error_string);
     9extern void finish(int signal);
     10extern void mvaddstr_and_log_it(int y, int x, char *output);
     11extern void open_evalcall_form(char *title);
     12extern void open_progress_form(char *title, char *b1, char *b2, char *b3,
     13                               long max_val);
     14extern void log_file_end_to_screen(char *filename, char *grep_for_me);
     15extern void log_to_screen(const char *fmt, ...);
     16extern void popup_and_OK(char *prompt);
     17extern bool popup_and_get_string(char *title, char *b, char *output,
     18                                 int maxsize);
     19extern bool popup_with_buttons(char *p, char *button1, char *button2);
     20extern void refresh_log_screen();
     21extern void setup_newt_stuff();
     22extern void update_evalcall_form_ratio(int num, int denom);
     23extern void update_evalcall_form(int curr);
     24extern void update_progress_form(char *blurb3);
     25extern void update_progress_form_full(char *blurb1, char *blurb2,
     26                                      char *blurb3);
    2427
    2528
     
    2730
    2831
    29 extern t_bkptype which_backup_media_type (bool);
    30 extern int which_compression_level ();
     32extern t_bkptype which_backup_media_type(bool);
     33extern int which_compression_level();
    3134
    3235
    33 extern void popup_changelist_from_file(char*source_file);
     36extern void popup_changelist_from_file(char *source_file);
    3437
    3538extern pid_t g_main_pid;
  • trunk/mondo/mondo/common/newt-specific.c

    r58 r59  
    112112 * @return TRUE for yes; FALSE for no.
    113113 */
    114      bool ask_me_yes_or_no(char *prompt) {
     114    bool ask_me_yes_or_no(char *prompt) {
    115115
    116116        /*@ buffers ********************************************************** */
     
    119119        size_t n = 0;
    120120
    121         assert_string_is_neither_NULL_nor_zerolength(prompt);
     121         assert_string_is_neither_NULL_nor_zerolength(prompt);
    122122
    123123        if (g_text_mode) {
     
    221221 * Close the currently opened progress form.
    222222 */
    223 void
    224  close_progress_form() {
    225     if (g_text_mode) {
    226         return;
    227     }
    228     if (g_current_progress == -999) {
    229         log_msg(2,
    230                 "Trying to close the progress form when it ain't open!");
    231         return;
    232     }
    233     g_current_progress = g_maximum_progress;
    234     update_progress_form("Complete");
    235     sleep(1);
    236     if (g_text_mode) {
    237         log_msg(2, "Closing progress form");
    238         return;
    239     }
    240     newtPopHelpLine();
    241     newtFormDestroy(g_progressForm);
    242     newtPopWindow();
    243     g_progressForm = NULL;
    244     g_current_progress = -999;
    245 }
     223    void
     224    close_progress_form() {
     225        if (g_text_mode) {
     226            return;
     227        }
     228        if (g_current_progress == -999) {
     229            log_msg(2,
     230                    "Trying to close the progress form when it ain't open!");
     231            return;
     232        }
     233        g_current_progress = g_maximum_progress;
     234        update_progress_form("Complete");
     235        sleep(1);
     236        if (g_text_mode) {
     237            log_msg(2, "Closing progress form");
     238            return;
     239        }
     240        newtPopHelpLine();
     241        newtFormDestroy(g_progressForm);
     242        newtPopWindow();
     243        g_progressForm = NULL;
     244        g_current_progress = -999;
     245    }
    246246
    247247
     
    422422        }
    423423        if (grep_for_me[0] != '\0') {
    424             asprintf(&command, "cat %s | grep \"%s\" | tail -n%d", filename,
    425                     grep_for_me, g_noof_log_lines);
     424            asprintf(&command, "cat %s | grep \"%s\" | tail -n%d",
     425                     filename, grep_for_me, g_noof_log_lines);
    426426        } else {
    427427            asprintf(&command, "cat %s | tail -n%d", filename,
    428                     g_noof_log_lines);
     428                     g_noof_log_lines);
    429429        }
    430430        fin = popen(command, "r");
     
    12021202        static char *possible_responses[] =
    12031203            { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
    1204 "nfs", "iso", NULL };
     1204            "nfs", "iso", NULL
     1205        };
    12051206        char *outstr;
    12061207        t_bkptype backup_type;
  • trunk/mondo/mondo/common/newt-specific.h

    r30 r59  
    11/* newt-specific.h
    2  * $Id: newt-specific.h,v 1.3 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    88#endif
    99
    10 bool ask_me_yes_or_no (char *prompt);
    11 bool ask_me_OK_or_cancel (char *prompt);
    12 void close_evalcall_form (void);
    13 void close_progress_form ();
    14 void fatal_error (char *error_string);
    15 void finish (int signal);
    16 void mvaddstr_and_log_it (int y, int x, char *output);
    17 void log_file_end_to_screen (char *filename, char *grep_for_me);
    18 void log_to_screen (const char *fmt, ...);
    19 void open_evalcall_form (char *title);
    20 void open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val);
    21 void popup_and_OK (char *prompt);
    22 bool popup_and_get_string (char *title, char *b, char *output, int maxsize);
    23 bool popup_with_buttons (char *p, char *button1, char *button2);
    24 void refresh_log_screen ();
    25 void setup_newt_stuff ();
    26 void update_evalcall_form_ratio (int num, int denom);
    27 void update_evalcall_form (int curr);
    28 void update_progress_form (char *blurb3);
    29 void update_progress_form_full (char *blurb1, char *blurb2, char *blurb3);
     10bool ask_me_yes_or_no(char *prompt);
     11bool ask_me_OK_or_cancel(char *prompt);
     12void close_evalcall_form(void);
     13void close_progress_form();
     14void fatal_error(char *error_string);
     15void finish(int signal);
     16void mvaddstr_and_log_it(int y, int x, char *output);
     17void log_file_end_to_screen(char *filename, char *grep_for_me);
     18void log_to_screen(const char *fmt, ...);
     19void open_evalcall_form(char *title);
     20void open_progress_form(char *title, char *b1, char *b2, char *b3,
     21                        long max_val);
     22void popup_and_OK(char *prompt);
     23bool popup_and_get_string(char *title, char *b, char *output, int maxsize);
     24bool popup_with_buttons(char *p, char *button1, char *button2);
     25void refresh_log_screen();
     26void setup_newt_stuff();
     27void update_evalcall_form_ratio(int num, int denom);
     28void update_evalcall_form(int curr);
     29void update_progress_form(char *blurb3);
     30void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3);
    3031
    3132
     
    3435
    3536
    36 t_bkptype which_backup_media_type (bool);
    37 int which_compression_level ();
     37t_bkptype which_backup_media_type(bool);
     38int which_compression_level();
    3839
    3940
    40 void popup_changelist_from_file(char*source_file);
     41void popup_changelist_from_file(char *source_file);
Note: See TracChangeset for help on using the changeset viewer.