Changeset 128 in MondoRescue


Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (18 years ago)
Author:
bcornec
Message:

indent on all the C code

Location:
branches/2.05/mondo/mondo
Files:
69 edited

Legend:

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

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/X-specific.c

    r30 r128  
    2626
    2727
    28 char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN], g_blurb_str_1[MAX_STR_LEN] =
    29   "", g_blurb_str_2[MAX_STR_LEN] = "", g_blurb_str_3[MAX_STR_LEN] = "";
     28char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN],
     29    g_blurb_str_1[MAX_STR_LEN] = "", g_blurb_str_2[MAX_STR_LEN] =
     30    "", g_blurb_str_3[MAX_STR_LEN] = "";
    3031
    3132
     
    3536int g_mysterious_dot_counter;
    3637
    37 int g_currentY = 3;     /* purpose */
     38int g_currentY = 3;             /* purpose */
    3839int g_current_media_number;
    3940
    4041long g_maximum_progress = 999;  /* purpose */
    4142long g_current_progress = -999; /* purpose */
    42 long g_start_time = 0;      /* purpose */
     43long g_start_time = 0;          /* purpose */
    4344bool g_text_mode = TRUE;
    4445
    4546
    4647extern pid_t g_mastermind_pid;
    47 
    48 
    49 
    50 
  • branches/2.05/mondo/mondo/common/X-specific.h

    r30 r128  
    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 */
  • branches/2.05/mondo/mondo/common/crcttt.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/lib-common-externs.h

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

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-archive.c

    r126 r128  
    199199
    200200#ifdef __FreeBSD__
    201     #define DEFAULT_1722MB_DISK "/dev/fd0.1722"
    202     #define BACKUP_1722MB_DISK "/dev/fd0.1722"
     201#define DEFAULT_1722MB_DISK "/dev/fd0.1722"
     202#define BACKUP_1722MB_DISK "/dev/fd0.1722"
    203203#else
    204     #define DEFAULT_1722MB_DISK "/dev/fd0u1722"
    205     #define BACKUP_1722MB_DISK "/dev/fd0H1722"
     204#define DEFAULT_1722MB_DISK "/dev/fd0u1722"
     205#define BACKUP_1722MB_DISK "/dev/fd0H1722"
    206206#ifndef _SEMUN_H
    207     #define _SEMUN_H
     207#define _SEMUN_H
    208208
    209209    /**
    210210     * The semaphore union, provided only in case the user's system doesn't.
    211211     */
    212     union semun {
    213       int val;
    214       struct semid_ds *buf;
    215       unsigned short int *array;
    216       struct seminfo *__buf;
    217     };
     212union semun {
     213    int val;
     214    struct semid_ds *buf;
     215    unsigned short int *array;
     216    struct seminfo *__buf;
     217};
    218218#endif
    219 #endif /* __FreeBSD__ */
     219#endif                          /* __FreeBSD__ */
    220220
    221221/*@unused@*/
     
    228228extern bool g_exiting;
    229229extern long g_current_progress;
    230 extern FILE*g_tape_stream;
     230extern FILE *g_tape_stream;
    231231extern long long g_tape_posK;
    232232extern char *g_mondo_home;
     
    242242 * The current backup media type in use.
    243243 */
    244 t_bkptype g_backup_media_type=none;
     244t_bkptype g_backup_media_type = none;
    245245
    246246/**
     
    274274 * @return 1 for success, 0 for failure.
    275275 */
    276 static int set_semvalue(void) // initializes semaphore
     276static int set_semvalue(void)   // initializes semaphore
    277277{
    278   union semun sem_union;
    279   sem_union.val = 1;
    280   if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) { return(0); }
    281   return(1);
     278    union semun sem_union;
     279    sem_union.val = 1;
     280    if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
     281        return (0);
     282    }
     283    return (1);
    282284}
    283285
     
    287289 * @see set_semvalue
    288290 */
    289 static void del_semvalue(void) // deletes semaphore
     291static void del_semvalue(void)  // deletes semaphore
    290292{
    291   union semun sem_union;
    292 
    293   if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1)
    294     { log_msg (3, "Failed to delete semaphore"); }
     293    union semun sem_union;
     294
     295    if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
     296        log_msg(3, "Failed to delete semaphore");
     297    }
    295298}
    296299
     
    300303 * @see semaphore_v
    301304 */
    302 static int semaphore_p(void) // changes status to 'P' (waiting)
     305static int semaphore_p(void)    // changes status to 'P' (waiting)
    303306{
    304   struct sembuf sem_b;
    305 
    306   sem_b.sem_num = 0;
    307   sem_b.sem_op = -1; // P()
    308   sem_b.sem_flg = SEM_UNDO;
    309   if (semop(g_sem_id, &sem_b, 1) == -1)
    310     { log_msg(3, "semaphore_p failed"); return(0); }
    311   return(1);
     307    struct sembuf sem_b;
     308
     309    sem_b.sem_num = 0;
     310    sem_b.sem_op = -1;          // P()
     311    sem_b.sem_flg = SEM_UNDO;
     312    if (semop(g_sem_id, &sem_b, 1) == -1) {
     313        log_msg(3, "semaphore_p failed");
     314        return (0);
     315    }
     316    return (1);
    312317}
    313318
     
    316321 * @return 1 for success, 0 for failure.
    317322 */
    318 static int semaphore_v(void) // changes status to 'V' (free)
     323static int semaphore_v(void)    // changes status to 'V' (free)
    319324{
    320   struct sembuf sem_b;
    321 
    322   sem_b.sem_num = 0;
    323   sem_b.sem_op = 1; // V()
    324   sem_b.sem_flg = SEM_UNDO;
    325   if (semop(g_sem_id, &sem_b, 1) == -1)
    326     { log_msg(3, "semaphore_v failed"); return(0); }
    327   return(1);
     325    struct sembuf sem_b;
     326
     327    sem_b.sem_num = 0;
     328    sem_b.sem_op = 1;           // V()
     329    sem_b.sem_flg = SEM_UNDO;
     330    if (semop(g_sem_id, &sem_b, 1) == -1) {
     331        log_msg(3, "semaphore_v failed");
     332        return (0);
     333    }
     334    return (1);
    328335}
    329336
     
    344351
    345352int
    346 archive_this_fileset_with_star (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    347           int setno)
     353archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, char *filelist,
     354                               char *fname, int setno)
    348355{
    349   int retval = 0;
    350   unsigned int res = 0;
    351   int tries = 0;
    352   char *command;
    353   char *zipparams;
    354   char *tmp;
    355   char *p;
    356  
    357   malloc_string(command);
    358   malloc_string(zipparams);
    359   malloc_string(tmp);
    360 
    361   if (!does_file_exist (filelist))
    362     {
    363       sprintf (tmp, "(archive_this_fileset) - filelist %s does not exist", filelist);
    364       log_to_screen (tmp);
    365       return (1);
    366     }
    367 
    368   sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    369   if (system(tmp))
    370     {
    371       fatal_error("Unable to write tarball to scratchdir");
    372     }
    373  
    374   sprintf(command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s", filelist, fname);
    375   if (bkpinfo->use_lzo) { fatal_error("Can't use lzop"); }
    376   if (bkpinfo->compression_level > 0)
    377     {
    378       strcat(command, " -bz");
    379     }
    380   sprintf(command+strlen(command), " 2>> %s", MONDO_LOGFILE);
    381   log_msg(4, "command = '%s'", command);
    382    
    383   for(res=99,tries=0; tries<3 && res!=0; tries++)
    384     {
    385       log_msg(5, "command='%s'", command);
    386       res = system (command);
    387       strcpy(tmp, last_line_of_file(MONDO_LOGFILE));
    388       log_msg(1, "res=%d; tmp='%s'", res, tmp);
    389       if (bkpinfo->use_star && (res==254 || res==65024) && strstr(tmp, "star: Processed all possible files") && tries>0)
    390     {
    391       log_msg(1, "Star returned nonfatal error");
    392       res=0;
    393     }
    394       if (res)
    395         {
    396           log_OS_error (command);
    397       p = strstr(command, "-acl ");
    398       if (p)
    399         {
    400           p[0]=p[1]=p[2]=p[3]=' ';
    401               log_msg(1,"new command = '%s'", command);
    402         }
    403       else
    404         {
    405               log_msg (3, "Attempt #%d failed. Pausing 3 seconds and retrying...", tries+1);
    406           sleep(3);
    407         }
    408         }
    409     }
    410   retval += res;
    411   if (retval) { log_msg (3, "Failed to write set %d", setno); }
    412   else if (tries>1) { log_msg( 3,"Succeeded in writing set %d, on try #%d", setno, tries); }
    413 
    414   paranoid_free(command);
    415   paranoid_free(zipparams);
    416   paranoid_free(tmp);
    417   return (retval);
     356    int retval = 0;
     357    unsigned int res = 0;
     358    int tries = 0;
     359    char *command;
     360    char *zipparams;
     361    char *tmp;
     362    char *p;
     363
     364    malloc_string(command);
     365    malloc_string(zipparams);
     366    malloc_string(tmp);
     367
     368    if (!does_file_exist(filelist)) {
     369        sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
     370                filelist);
     371        log_to_screen(tmp);
     372        return (1);
     373    }
     374
     375    sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     376    if (system(tmp)) {
     377        fatal_error("Unable to write tarball to scratchdir");
     378    }
     379
     380    sprintf(command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
     381            filelist, fname);
     382    if (bkpinfo->use_lzo) {
     383        fatal_error("Can't use lzop");
     384    }
     385    if (bkpinfo->compression_level > 0) {
     386        strcat(command, " -bz");
     387    }
     388    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
     389    log_msg(4, "command = '%s'", command);
     390
     391    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     392        log_msg(5, "command='%s'", command);
     393        res = system(command);
     394        strcpy(tmp, last_line_of_file(MONDO_LOGFILE));
     395        log_msg(1, "res=%d; tmp='%s'", res, tmp);
     396        if (bkpinfo->use_star && (res == 254 || res == 65024)
     397            && strstr(tmp, "star: Processed all possible files")
     398            && tries > 0) {
     399            log_msg(1, "Star returned nonfatal error");
     400            res = 0;
     401        }
     402        if (res) {
     403            log_OS_error(command);
     404            p = strstr(command, "-acl ");
     405            if (p) {
     406                p[0] = p[1] = p[2] = p[3] = ' ';
     407                log_msg(1, "new command = '%s'", command);
     408            } else {
     409                log_msg(3,
     410                        "Attempt #%d failed. Pausing 3 seconds and retrying...",
     411                        tries + 1);
     412                sleep(3);
     413            }
     414        }
     415    }
     416    retval += res;
     417    if (retval) {
     418        log_msg(3, "Failed to write set %d", setno);
     419    } else if (tries > 1) {
     420        log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
     421                tries);
     422    }
     423
     424    paranoid_free(command);
     425    paranoid_free(zipparams);
     426    paranoid_free(tmp);
     427    return (retval);
    418428}
    419429
     
    436446 */
    437447int
    438 archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,
    439           int setno)
     448archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
     449                     char *fname, int setno)
    440450{
    441451
    442         /*@ int ****************************************************************/
    443   int retval = 0;
    444   int res = 0;
    445   int i = 0;
    446   int tries = 0;
    447   static int free_ramdisk_space = 9999;
    448 
    449     /*@ buffers *************************************************************/
    450   char *command;
    451   char *zipparams;
    452   char *tmp;
    453 
    454   assert(bkpinfo!=NULL);
    455   assert_string_is_neither_NULL_nor_zerolength(filelist);
    456   assert_string_is_neither_NULL_nor_zerolength(fname);
    457  
    458   if (bkpinfo->compression_level > 0 && bkpinfo->use_star)
    459     {
    460       return(archive_this_fileset_with_star(bkpinfo, filelist, fname, setno));
    461     }
    462  
    463   malloc_string(command);
    464   malloc_string(zipparams);
    465   malloc_string(tmp);
    466  
    467   if (!does_file_exist (filelist))
    468     {
    469       sprintf (tmp, "(archive_this_fileset) - filelist %s does not exist", filelist);
    470       log_to_screen (tmp);
    471       return (1);
    472     }
    473   sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    474   if (system(tmp))
    475     {
    476       fatal_error("Unable to write tarball to scratchdir");
    477     }
    478 
    479  
    480   if (bkpinfo->compression_level > 0)
    481     {
    482       sprintf (tmp, "%s/do-not-compress-these", g_mondo_home);
    483       //       -b %ld, TAPE_BLOCK_SIZE
    484       sprintf (zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, bkpinfo->compression_level);
    485       if (does_file_exist(tmp))
    486     { strcat (zipparams, " -E "); strcat (zipparams, tmp); }
    487       else
    488     { log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); }
    489     }
    490   else
    491     {
    492       zipparams[0] = '\0';
    493     }
     452    /*@ int *************************************************************** */
     453    int retval = 0;
     454    int res = 0;
     455    int i = 0;
     456    int tries = 0;
     457    static int free_ramdisk_space = 9999;
     458
     459    /*@ buffers ************************************************************ */
     460    char *command;
     461    char *zipparams;
     462    char *tmp;
     463
     464    assert(bkpinfo != NULL);
     465    assert_string_is_neither_NULL_nor_zerolength(filelist);
     466    assert_string_is_neither_NULL_nor_zerolength(fname);
     467
     468    if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
     469        return (archive_this_fileset_with_star
     470                (bkpinfo, filelist, fname, setno));
     471    }
     472
     473    malloc_string(command);
     474    malloc_string(zipparams);
     475    malloc_string(tmp);
     476
     477    if (!does_file_exist(filelist)) {
     478        sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
     479                filelist);
     480        log_to_screen(tmp);
     481        return (1);
     482    }
     483    sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     484    if (system(tmp)) {
     485        fatal_error("Unable to write tarball to scratchdir");
     486    }
     487
     488
     489    if (bkpinfo->compression_level > 0) {
     490        sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     491        //       -b %ld, TAPE_BLOCK_SIZE
     492        sprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
     493                bkpinfo->compression_level);
     494        if (does_file_exist(tmp)) {
     495            strcat(zipparams, " -E ");
     496            strcat(zipparams, tmp);
     497        } else {
     498            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
     499        }
     500    } else {
     501        zipparams[0] = '\0';
     502    }
    494503
    495504//  make_hole_for_file(fname);
    496505
    497   if (!does_file_exist(bkpinfo->tmpdir)) { log_OS_error("tmpdir not found"); fatal_error("tmpdir not found"); }
    498   if (!does_file_exist(bkpinfo->scratchdir)) { log_OS_error("scratchdir not found"); fatal_error("scratchdir not found"); }
    499   sprintf (command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, fname,
    500        bkpinfo->zip_suffix);
    501   paranoid_system (command);
    502 
    503   sprintf (command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
    504 
    505   sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    506   if (system(tmp))
    507     {
    508       fatal_error("Unable to write tarball to scratchdir");
    509     }
    510 
    511   for(res=99,tries=0; tries<3 && res!=0; tries++)
    512     {
    513       log_msg(5, "command='%s'", command);
    514       res = system (command);
    515       if (res)
    516         {
    517           log_OS_error (command);
    518           log_msg (3, "Attempt #%d failed. Pausing 3 seconds and retrying...", tries+1);
    519           sleep(3);
    520         }
    521     }
    522   retval += res;
    523   if (retval) { log_msg (3, "Failed to write set %d", setno); }
    524   else if (tries>1) { log_msg( 3,"Succeeded in writing set %d, on try #%d", setno, tries); }
    525 
    526   if (g_tmpfs_mountpt[0] != '\0') {
    527       i = atoi( call_program_and_get_last_line_of_output ("df -m | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
    528       if (i>0)
    529       {
    530           if (free_ramdisk_space > i)
    531           {
    532               free_ramdisk_space = i;
    533               log_msg (2, "min(free_ramdisk_space) is now %d", free_ramdisk_space);
    534               if (free_ramdisk_space < 10)
    535               {
    536                   fatal_error ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
    537               }
    538           }
    539       }
    540   }
    541   paranoid_free(command);
    542   paranoid_free(zipparams);
    543   paranoid_free(tmp);
    544   return (retval);
     506    if (!does_file_exist(bkpinfo->tmpdir)) {
     507        log_OS_error("tmpdir not found");
     508        fatal_error("tmpdir not found");
     509    }
     510    if (!does_file_exist(bkpinfo->scratchdir)) {
     511        log_OS_error("scratchdir not found");
     512        fatal_error("scratchdir not found");
     513    }
     514    sprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
     515            fname, bkpinfo->zip_suffix);
     516    paranoid_system(command);
     517
     518    sprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
     519            TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
     520
     521    sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     522    if (system(tmp)) {
     523        fatal_error("Unable to write tarball to scratchdir");
     524    }
     525
     526    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     527        log_msg(5, "command='%s'", command);
     528        res = system(command);
     529        if (res) {
     530            log_OS_error(command);
     531            log_msg(3,
     532                    "Attempt #%d failed. Pausing 3 seconds and retrying...",
     533                    tries + 1);
     534            sleep(3);
     535        }
     536    }
     537    retval += res;
     538    if (retval) {
     539        log_msg(3, "Failed to write set %d", setno);
     540    } else if (tries > 1) {
     541        log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
     542                tries);
     543    }
     544
     545    if (g_tmpfs_mountpt[0] != '\0') {
     546        i = atoi(call_program_and_get_last_line_of_output
     547                 ("df -m | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
     548        if (i > 0) {
     549            if (free_ramdisk_space > i) {
     550                free_ramdisk_space = i;
     551                log_msg(2, "min(free_ramdisk_space) is now %d",
     552                        free_ramdisk_space);
     553                if (free_ramdisk_space < 10) {
     554                    fatal_error
     555                        ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
     556                }
     557            }
     558        }
     559    }
     560    paranoid_free(command);
     561    paranoid_free(zipparams);
     562    paranoid_free(tmp);
     563    return (retval);
    545564}
    546565
     
    564583int backup_data(struct s_bkpinfo *bkpinfo)
    565584{
    566 int retval=0, res=0;
    567 char *tmp;
    568 
    569   assert(bkpinfo!=NULL);
    570   set_g_cdrom_and_g_dvd_to_bkpinfo_value(bkpinfo);
    571    malloc_string(tmp);
    572       if (bkpinfo->backup_media_type == dvd)
    573         {
     585    int retval = 0, res = 0;
     586    char *tmp;
     587
     588    assert(bkpinfo != NULL);
     589    set_g_cdrom_and_g_dvd_to_bkpinfo_value(bkpinfo);
     590    malloc_string(tmp);
     591    if (bkpinfo->backup_media_type == dvd) {
    574592#ifdef DVDRWFORMAT
    575       if (!find_home_of_exe("dvd+rw-format")) { fatal_error("Cannot find dvd+rw-format. Please install it or fix your PATH."); }
     593        if (!find_home_of_exe("dvd+rw-format")) {
     594            fatal_error
     595                ("Cannot find dvd+rw-format. Please install it or fix your PATH.");
     596        }
    576597#endif
    577       if (!find_home_of_exe("growisofs")) { fatal_error("Cannot find growisofs. Please install it or fix your PATH."); }
    578     }
    579 
    580       if ((res=prepare_filelist (bkpinfo))) /* generate scratchdir/filelist.full */
    581         { fatal_error ("Failed to generate filelist catalog"); }
    582       if (call_filelist_chopper (bkpinfo)) { fatal_error("Failed to run filelist chopper"); }
     598        if (!find_home_of_exe("growisofs")) {
     599            fatal_error
     600                ("Cannot find growisofs. Please install it or fix your PATH.");
     601        }
     602    }
     603
     604    if ((res = prepare_filelist(bkpinfo))) {    /* generate scratchdir/filelist.full */
     605        fatal_error("Failed to generate filelist catalog");
     606    }
     607    if (call_filelist_chopper(bkpinfo)) {
     608        fatal_error("Failed to run filelist chopper");
     609    }
    583610
    584611/*
     
    587614        { fatal_error("Failed to count filelist.full"); }
    588615*/
    589       sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
    590       if (run_program_and_log_output(tmp, 2))
    591         { fatal_error("Failed to gzip filelist.full"); }
    592       sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
    593       if (run_program_and_log_output(tmp, 2))
    594         { fatal_error("Failed to copy to tmpdir"); }
    595 
    596       copy_mondo_and_mindi_stuff_to_scratchdir (bkpinfo); // payload, too, if it exists
     616    sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
     617    if (run_program_and_log_output(tmp, 2)) {
     618        fatal_error("Failed to gzip filelist.full");
     619    }
     620    sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
     621            bkpinfo->tmpdir);
     622    if (run_program_and_log_output(tmp, 2)) {
     623        fatal_error("Failed to copy to tmpdir");
     624    }
     625
     626    copy_mondo_and_mindi_stuff_to_scratchdir(bkpinfo);  // payload, too, if it exists
    597627#if __FreeBSD__ == 5
    598       strcpy (bkpinfo->kernel_path, "/boot/kernel/kernel");
     628    strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");
    599629#elif __FreeBSD__ == 4
    600       strcpy (bkpinfo->kernel_path, "/kernel");
     630    strcpy(bkpinfo->kernel_path, "/kernel");
    601631#elif linux
    602       if (figure_out_kernel_path_interactively_if_necessary(bkpinfo->kernel_path))
    603         { fatal_error ("Kernel not found. Please specify manually with the '-k' switch."); }
     632    if (figure_out_kernel_path_interactively_if_necessary
     633        (bkpinfo->kernel_path)) {
     634        fatal_error
     635            ("Kernel not found. Please specify manually with the '-k' switch.");
     636    }
    604637#else
    605638#error "I don't know about this system!"
    606639#endif
    607       if ((res = call_mindi_to_supply_boot_disks (bkpinfo)))
    608     { fatal_error ("Failed to generate boot+data disks"); }
    609       retval += do_that_initial_phase (bkpinfo); // prepare
    610       sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
    611       run_program_and_log_output(tmp, 1);
    612       retval += make_those_afios_phase (bkpinfo); // backup regular files
    613       retval += make_those_slices_phase (bkpinfo); // backup BIG files
    614       retval += do_that_final_phase (bkpinfo); // clean up
    615       log_msg (1, "Creation of archives... complete.");
    616       if (bkpinfo->verify_data) { sleep(2); }
    617       paranoid_free(tmp);
    618       return(retval);
     640    if ((res = call_mindi_to_supply_boot_disks(bkpinfo))) {
     641        fatal_error("Failed to generate boot+data disks");
     642    }
     643    retval += do_that_initial_phase(bkpinfo);   // prepare
     644    sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
     645    run_program_and_log_output(tmp, 1);
     646    retval += make_those_afios_phase(bkpinfo);  // backup regular files
     647    retval += make_those_slices_phase(bkpinfo); // backup BIG files
     648    retval += do_that_final_phase(bkpinfo); // clean up
     649    log_msg(1, "Creation of archives... complete.");
     650    if (bkpinfo->verify_data) {
     651        sleep(2);
     652    }
     653    paranoid_free(tmp);
     654    return (retval);
    619655}
    620656
     
    648684 * @ingroup MLarchiveGroup
    649685 */
    650 int
    651 call_mindi_to_supply_boot_disks (struct s_bkpinfo *bkpinfo)
     686int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo)
    652687{
    653     /*@ buffer *************************************************************/
    654   char *tmp;
    655         char *scratchdir;
     688    /*@ buffer ************************************************************ */
     689    char *tmp;
     690    char *scratchdir;
    656691    char *command;
    657692    char *use_lzo_sz;
    658         char *use_comp_sz;
     693    char *use_comp_sz;
    659694    char *use_star_sz;
    660695    char *bootldr_str;
     
    665700    char *tape_size_sz;
    666701    char *devs_to_exclude;
    667         char *use_lilo_sz;
    668         char *value;
     702    char *use_lilo_sz;
     703    char *value;
    669704    char *bootdev;
    670705
    671706
    672707
    673     /*@ char ***************************************************************/
     708    /*@ char ************************************************************** */
    674709    char ch = '\0';
    675    
    676     /*@ long     ***********************************************************/
    677   long lines_in_filelist = 0;
    678 
    679     /*@ int     **************************************************************/
    680   int res   = 0;
    681   long estimated_total_noof_slices = 0;
    682 
    683   assert(bkpinfo!=NULL);
    684   command = malloc(1200);
    685 malloc_string ( tmp );
    686 malloc_string ( scratchdir );
    687 malloc_string ( use_lzo_sz );
    688 malloc_string ( use_star_sz );
    689 malloc_string ( use_comp_sz );
    690 malloc_string ( bootldr_str );
    691 malloc_string ( tape_device );
    692 malloc_string ( last_filelist_number );
    693 malloc_string ( broken_bios_sz );
    694 malloc_string ( cd_recovery_sz );
    695 malloc_string ( tape_size_sz );
    696 malloc_string ( devs_to_exclude );
    697 malloc_string ( use_lilo_sz ); /* BCO: shared between LILO/ELILO */
    698 malloc_string ( value );
    699 malloc_string ( bootdev );
    700 
    701   strcpy( scratchdir, bkpinfo->scratchdir);
    702   sprintf (tmp,
    703        "echo '%s' | tr -s ' ' '\n' | grep -x '/dev/.*' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
    704        bkpinfo->exclude_paths);
    705   strcpy (devs_to_exclude, call_program_and_get_last_line_of_output (tmp));
    706   sprintf (tmp, "devs_to_exclude = '%s'", devs_to_exclude);
    707   log_msg (2, tmp);
    708   mvaddstr_and_log_it (g_currentY, 0,
    709                "Calling MINDI to create boot+data disks");
    710   sprintf (tmp, "%s/filelist.full", bkpinfo->tmpdir);
    711   if (!does_file_exist(tmp))
    712     {
    713       sprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
    714       if (!does_file_exist(tmp))
    715         { fatal_error("Cannot find filelist.full, so I cannot count its lines"); }
    716     }
    717   lines_in_filelist = count_lines_in_file (tmp);
    718   sprintf (tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
    719   strcpy (last_filelist_number, last_line_of_file (tmp));
    720   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    721     {
    722       sprintf (tape_size_sz, "%ld", bkpinfo->media_size[1]);
    723       strcpy (tape_device, bkpinfo->media_device);
    724     }
    725   else
    726     {
    727       tape_size_sz[0] = '\0';
    728       tape_device[0] = '\0';
    729     }
    730   if (bkpinfo->use_lzo)
    731     {
    732       strcpy (use_lzo_sz, "yes");
    733     }
    734   else
    735     {
    736       strcpy (use_lzo_sz, "no");
    737     }
    738   if (bkpinfo->use_star)
    739     { strcpy( use_star_sz, "yes"); }
    740   else
    741     { strcpy( use_star_sz, "no"); }
    742    
    743   if (bkpinfo->compression_level>0)
    744     {
    745       strcpy (use_comp_sz, "yes");
    746     }
    747   else
    748     {
    749       strcpy (use_comp_sz, "no");
    750     }
    751 
    752   strcpy (broken_bios_sz, "yes");   /* assume so */
    753   if (g_cd_recovery)
    754     {
    755       strcpy (cd_recovery_sz, "yes");
    756     }
    757   else
    758     {
    759       strcpy (cd_recovery_sz, "no");
    760     }
    761   if (bkpinfo->make_cd_use_lilo)
    762     {
    763       strcpy (use_lilo_sz, "yes");
    764     }
    765   else
    766     {
    767       strcpy (use_lilo_sz, "no");
    768     }
    769 
    770   if (!bkpinfo->nonbootable_backup && (bkpinfo->boot_loader == '\0' || bkpinfo->boot_device[0] == '\0'))
    771     {
     710
     711    /*@ long     ********************************************************** */
     712    long lines_in_filelist = 0;
     713
     714    /*@ int     ************************************************************* */
     715    int res = 0;
     716    long estimated_total_noof_slices = 0;
     717
     718    assert(bkpinfo != NULL);
     719    command = malloc(1200);
     720    malloc_string(tmp);
     721    malloc_string(scratchdir);
     722    malloc_string(use_lzo_sz);
     723    malloc_string(use_star_sz);
     724    malloc_string(use_comp_sz);
     725    malloc_string(bootldr_str);
     726    malloc_string(tape_device);
     727    malloc_string(last_filelist_number);
     728    malloc_string(broken_bios_sz);
     729    malloc_string(cd_recovery_sz);
     730    malloc_string(tape_size_sz);
     731    malloc_string(devs_to_exclude);
     732    malloc_string(use_lilo_sz); /* BCO: shared between LILO/ELILO */
     733    malloc_string(value);
     734    malloc_string(bootdev);
     735
     736    strcpy(scratchdir, bkpinfo->scratchdir);
     737    sprintf(tmp,
     738            "echo '%s' | tr -s ' ' '\n' | grep -x '/dev/.*' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
     739            bkpinfo->exclude_paths);
     740    strcpy(devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
     741    sprintf(tmp, "devs_to_exclude = '%s'", devs_to_exclude);
     742    log_msg(2, tmp);
     743    mvaddstr_and_log_it(g_currentY, 0,
     744                        "Calling MINDI to create boot+data disks");
     745    sprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir);
     746    if (!does_file_exist(tmp)) {
     747        sprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
     748        if (!does_file_exist(tmp)) {
     749            fatal_error
     750                ("Cannot find filelist.full, so I cannot count its lines");
     751        }
     752    }
     753    lines_in_filelist = count_lines_in_file(tmp);
     754    sprintf(tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
     755    strcpy(last_filelist_number, last_line_of_file(tmp));
     756    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     757        sprintf(tape_size_sz, "%ld", bkpinfo->media_size[1]);
     758        strcpy(tape_device, bkpinfo->media_device);
     759    } else {
     760        tape_size_sz[0] = '\0';
     761        tape_device[0] = '\0';
     762    }
     763    if (bkpinfo->use_lzo) {
     764        strcpy(use_lzo_sz, "yes");
     765    } else {
     766        strcpy(use_lzo_sz, "no");
     767    }
     768    if (bkpinfo->use_star) {
     769        strcpy(use_star_sz, "yes");
     770    } else {
     771        strcpy(use_star_sz, "no");
     772    }
     773
     774    if (bkpinfo->compression_level > 0) {
     775        strcpy(use_comp_sz, "yes");
     776    } else {
     777        strcpy(use_comp_sz, "no");
     778    }
     779
     780    strcpy(broken_bios_sz, "yes");  /* assume so */
     781    if (g_cd_recovery) {
     782        strcpy(cd_recovery_sz, "yes");
     783    } else {
     784        strcpy(cd_recovery_sz, "no");
     785    }
     786    if (bkpinfo->make_cd_use_lilo) {
     787        strcpy(use_lilo_sz, "yes");
     788    } else {
     789        strcpy(use_lilo_sz, "no");
     790    }
     791
     792    if (!bkpinfo->nonbootable_backup
     793        && (bkpinfo->boot_loader == '\0'
     794            || bkpinfo->boot_device[0] == '\0')) {
    772795
    773796#ifdef __FreeBSD__
    774     strcpy (bootdev, call_program_and_get_last_line_of_output
    775         ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    776     if (!bootdev[0])
    777       {
    778         strcpy (bootdev, call_program_and_get_last_line_of_output
    779         ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    780       }
     797        strcpy(bootdev, call_program_and_get_last_line_of_output
     798               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     799        if (!bootdev[0]) {
     800            strcpy(bootdev, call_program_and_get_last_line_of_output
     801                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     802        }
    781803#else
    782     strcpy (bootdev, call_program_and_get_last_line_of_output
    783             ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    784     if (strstr(bootdev, "/dev/cciss/")) {
    785          strcpy (bootdev, call_program_and_get_last_line_of_output
    786             ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    787          }
    788     if (!bootdev[0])
    789       {
    790         strcpy (bootdev, call_program_and_get_last_line_of_output
    791             ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    792        if (strstr(bootdev, "/dev/cciss/")) {
    793             strcpy (bootdev, call_program_and_get_last_line_of_output
    794                ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    795             }
    796       }
     804        strcpy(bootdev, call_program_and_get_last_line_of_output
     805               ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     806        if (strstr(bootdev, "/dev/cciss/")) {
     807            strcpy(bootdev, call_program_and_get_last_line_of_output
     808                   ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     809        }
     810        if (!bootdev[0]) {
     811            strcpy(bootdev, call_program_and_get_last_line_of_output
     812                   ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     813            if (strstr(bootdev, "/dev/cciss/")) {
     814                strcpy(bootdev, call_program_and_get_last_line_of_output
     815                       ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
     816            }
     817        }
    797818#endif
    798     if (bootdev[0])
    799         ch = which_boot_loader (bootdev);
    800     else
    801         ch = 'U';
    802       if (bkpinfo->boot_loader != '\0')
    803         {
    804           sprintf (tmp, "User specified boot loader. It is '%c'.",
    805                bkpinfo->boot_loader);
    806           log_msg (2, tmp);
    807         }
    808       else
    809         {
    810           bkpinfo->boot_loader = ch;
    811         }
    812       if (bkpinfo->boot_device[0] != '\0')
    813         {
    814           sprintf (tmp, "User specified boot device. It is '%s'.",
    815                bkpinfo->boot_device);
    816           log_msg (2, tmp);
    817         }
    818       else
    819         {
    820           strcpy (bkpinfo->boot_device, bootdev);
    821         }
    822     }
    823 
    824   if (
     819        if (bootdev[0])
     820            ch = which_boot_loader(bootdev);
     821        else
     822            ch = 'U';
     823        if (bkpinfo->boot_loader != '\0') {
     824            sprintf(tmp, "User specified boot loader. It is '%c'.",
     825                    bkpinfo->boot_loader);
     826            log_msg(2, tmp);
     827        } else {
     828            bkpinfo->boot_loader = ch;
     829        }
     830        if (bkpinfo->boot_device[0] != '\0') {
     831            sprintf(tmp, "User specified boot device. It is '%s'.",
     832                    bkpinfo->boot_device);
     833            log_msg(2, tmp);
     834        } else {
     835            strcpy(bkpinfo->boot_device, bootdev);
     836        }
     837    }
     838
     839    if (
    825840#ifdef __FreeBSD__
    826       bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
     841           bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
    827842#endif
    828843#ifdef __IA64__
    829       bkpinfo->boot_loader != 'E' &&
     844           bkpinfo->boot_loader != 'E' &&
    830845#endif
    831       bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G' && bkpinfo->boot_loader != 'R' && !bkpinfo->nonbootable_backup)
    832     {
    833       fatal_error
    834     ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
    835     }
    836   if (bkpinfo->boot_loader == 'L')
    837     {
    838       strcpy (bootldr_str, "LILO");
    839       if (!does_file_exist("/etc/lilo.conf"))
    840         { fatal_error("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?"); }
    841     }
    842   else if (bkpinfo->boot_loader == 'G')
    843     {
    844       strcpy (bootldr_str, "GRUB");
    845       if (!does_file_exist("/etc/grub.conf") && does_file_exist("/boot/grub/grub.conf"))
    846     {
    847       run_program_and_log_output("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
    848     }
    849       /* Detect Debian's grub config file */
    850       else if (!does_file_exist("/etc/grub.conf") && does_file_exist("/boot/grub/menu.lst"))
    851         {
    852           run_program_and_log_output("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
    853         }
    854       if (!does_file_exist("/etc/grub.conf"))
    855     { fatal_error("The de facto standard location for your boot loader's config file is /etc/grub.conf but I cannot find it there. What is wrong with your Linux distribution? Try 'ln -s /boot/grub/menu.lst /etc/grub.conf'..."); }
    856     }
    857   else if (bkpinfo->boot_loader == 'E')
    858     {
    859       strcpy (bootldr_str, "ELILO");
    860       /* BCO: fix it for SuSE, Debian, Mandrake, ... */
    861       if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/redhat/elilo.conf"))
    862     {
    863       run_program_and_log_output("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf", 5);
    864     }
    865       if (!does_file_exist("/etc/elilo.conf"))
    866     { fatal_error("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'"); }
    867     }
    868   else if (bkpinfo->boot_loader == 'R')
    869     {
    870       strcpy (bootldr_str, "RAW");
    871     }
     846           bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G'
     847           && bkpinfo->boot_loader != 'R'
     848           && !bkpinfo->nonbootable_backup) {
     849        fatal_error
     850            ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
     851    }
     852    if (bkpinfo->boot_loader == 'L') {
     853        strcpy(bootldr_str, "LILO");
     854        if (!does_file_exist("/etc/lilo.conf")) {
     855            fatal_error
     856                ("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
     857        }
     858    } else if (bkpinfo->boot_loader == 'G') {
     859        strcpy(bootldr_str, "GRUB");
     860        if (!does_file_exist("/etc/grub.conf")
     861            && does_file_exist("/boot/grub/grub.conf")) {
     862            run_program_and_log_output
     863                ("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
     864        }
     865        /* Detect Debian's grub config file */
     866        else if (!does_file_exist("/etc/grub.conf")
     867                 && does_file_exist("/boot/grub/menu.lst")) {
     868            run_program_and_log_output
     869                ("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
     870        }
     871        if (!does_file_exist("/etc/grub.conf")) {
     872            fatal_error
     873                ("The de facto standard location for your boot loader's config file is /etc/grub.conf but I cannot find it there. What is wrong with your Linux distribution? Try 'ln -s /boot/grub/menu.lst /etc/grub.conf'...");
     874        }
     875    } else if (bkpinfo->boot_loader == 'E') {
     876        strcpy(bootldr_str, "ELILO");
     877        /* BCO: fix it for SuSE, Debian, Mandrake, ... */
     878        if (!does_file_exist("/etc/elilo.conf")
     879            && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
     880            run_program_and_log_output
     881                ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf",
     882                 5);
     883        }
     884        if (!does_file_exist("/etc/elilo.conf")) {
     885            fatal_error
     886                ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
     887        }
     888    } else if (bkpinfo->boot_loader == 'R') {
     889        strcpy(bootldr_str, "RAW");
     890    }
    872891#ifdef __FreeBSD__
    873   else if (bkpinfo->boot_loader == 'D')
    874       {
    875       strcpy (bootldr_str, "DD");
    876       }
    877 
    878   else if (bkpinfo->boot_loader == 'B')
    879       {
    880       strcpy (bootldr_str, "BOOT0");
    881       }
     892    else if (bkpinfo->boot_loader == 'D') {
     893        strcpy(bootldr_str, "DD");
     894    }
     895
     896    else if (bkpinfo->boot_loader == 'B') {
     897        strcpy(bootldr_str, "BOOT0");
     898    }
    882899#endif
    883   else
    884     {
    885       strcpy (bootldr_str, "unknown");
    886     }
    887   sprintf (tmp, "Your boot loader is %s and it boots from %s", bootldr_str,
    888        bkpinfo->boot_device);
    889   log_to_screen (tmp);
    890   sprintf (tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
    891   if (write_one_liner_data_file (tmp, bkpinfo->boot_device)) { log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__); }
    892   switch(bkpinfo->backup_media_type)
    893     {
    894       case cdr: strcpy(value, "cdr"); break;
    895       case cdrw: strcpy(value, "cdrw"); break;
    896       case cdstream: strcpy(value, "cdstream"); break;
    897       case tape: strcpy(value, "tape"); break;
    898       case udev: strcpy(value, "udev"); break;
    899       case iso: strcpy(value, "iso"); break;
    900       case nfs: strcpy(value, "nfs"); break;
    901       case dvd: strcpy(value, "dvd"); break;
    902       default: fatal_error("Unknown backup_media_type");
    903     }
    904   sprintf (tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
    905   if (write_one_liner_data_file (tmp, value)) { res++; log_msg(1, "%ld: Unable to write one-liner backup-media-type", __LINE__); }
    906   log_to_screen(bkpinfo->tmpdir);
    907   sprintf (tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
    908   if (write_one_liner_data_file (tmp, bootldr_str)) { res++; log_msg(1, "%ld: Unable to write one-liner bootloader.name", __LINE__); }
    909   sprintf (tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
    910   if (bkpinfo->differential)
    911     {
    912       res+=write_one_liner_data_file (tmp, "1");
    913     }
    914   else
    915     {
    916       res+=write_one_liner_data_file (tmp, "0");
    917     }
    918 
    919   estimated_total_noof_slices =
    920     size_of_all_biggiefiles_K (bkpinfo) / bkpinfo->optimal_set_size + 1;
     900    else {
     901        strcpy(bootldr_str, "unknown");
     902    }
     903    sprintf(tmp, "Your boot loader is %s and it boots from %s",
     904            bootldr_str, bkpinfo->boot_device);
     905    log_to_screen(tmp);
     906    sprintf(tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
     907    if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
     908        log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
     909    }
     910    switch (bkpinfo->backup_media_type) {
     911    case cdr:
     912        strcpy(value, "cdr");
     913        break;
     914    case cdrw:
     915        strcpy(value, "cdrw");
     916        break;
     917    case cdstream:
     918        strcpy(value, "cdstream");
     919        break;
     920    case tape:
     921        strcpy(value, "tape");
     922        break;
     923    case udev:
     924        strcpy(value, "udev");
     925        break;
     926    case iso:
     927        strcpy(value, "iso");
     928        break;
     929    case nfs:
     930        strcpy(value, "nfs");
     931        break;
     932    case dvd:
     933        strcpy(value, "dvd");
     934        break;
     935    default:
     936        fatal_error("Unknown backup_media_type");
     937    }
     938    sprintf(tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
     939    if (write_one_liner_data_file(tmp, value)) {
     940        res++;
     941        log_msg(1, "%ld: Unable to write one-liner backup-media-type",
     942                __LINE__);
     943    }
     944    log_to_screen(bkpinfo->tmpdir);
     945    sprintf(tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
     946    if (write_one_liner_data_file(tmp, bootldr_str)) {
     947        res++;
     948        log_msg(1, "%ld: Unable to write one-liner bootloader.name",
     949                __LINE__);
     950    }
     951    sprintf(tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
     952    if (bkpinfo->differential) {
     953        res += write_one_liner_data_file(tmp, "1");
     954    } else {
     955        res += write_one_liner_data_file(tmp, "0");
     956    }
     957
     958    estimated_total_noof_slices =
     959        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
    921960/* add nfs stuff here? */
    922   sprintf (command, "mkdir -p %s/images", bkpinfo->scratchdir);
    923   if (system (command)) { res++; log_OS_error("Unable to make images directory"); }
    924   sprintf (command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
    925   if (system (command)) { res++; log_OS_error("Unable to make mnt floppy directory"); }
    926   sprintf (tmp, "BTW, I'm telling Mindi your kernel is '%s'",
    927        bkpinfo->kernel_path);
    928 
    929   log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
    930 
    931   sprintf (command,
     961    sprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
     962    if (system(command)) {
     963        res++;
     964        log_OS_error("Unable to make images directory");
     965    }
     966    sprintf(command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
     967    if (system(command)) {
     968        res++;
     969        log_OS_error("Unable to make mnt floppy directory");
     970    }
     971    sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
     972            bkpinfo->kernel_path);
     973
     974    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
     975
     976    sprintf(command,
    932977/*     "mindi --custom 2=%s 3=%s/images 4=\"%s\" 5=\"%s\" \
    9339786=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
    93497911=\"%s\" 12=%s 13=%ld 14=\"%s\" 15=\"%s\" 16=\"%s\" 17=\"%s\" 18=%ld 19=%d",*/
    935        
    936        
    937     "mindi --custom %s %s/images '%s' '%s' \
     980            "mindi --custom %s %s/images '%s' '%s' \
    938981'%s' %ld '%s' '%s' '%s' \
    939 '%s' %s %ld '%s' '%s' '%s' '%s' %ld %d",
    940 
    941        bkpinfo->tmpdir,         // parameter #2
    942        bkpinfo->scratchdir,     // parameter #3
    943        bkpinfo->kernel_path,    // parameter #4
    944        tape_device,         // parameter #5
    945        tape_size_sz,        // parameter #6
    946        lines_in_filelist,       // parameter #7 (INT)
    947        use_lzo_sz,          // parameter #8
    948        cd_recovery_sz,      // parameter #9
    949        bkpinfo->image_devs,     // parameter #10
    950        broken_bios_sz,      // parameter #11
    951        last_filelist_number,    // parameter #12 (STRING)
    952        estimated_total_noof_slices, // parameter #13 (INT)
    953        devs_to_exclude,         // parameter #14
    954        use_comp_sz,         // parameter #15
    955        use_lilo_sz,         // parameter #16
    956        use_star_sz,         // parameter #17
    957        bkpinfo->internal_tape_block_size, // parameter #18 (LONG)
    958        bkpinfo->differential);  // parameter #19 (INT)
    959      
     982'%s' %s %ld '%s' '%s' '%s' '%s' %ld %d", bkpinfo->tmpdir,   // parameter #2
     983            bkpinfo->scratchdir,    // parameter #3
     984            bkpinfo->kernel_path,   // parameter #4
     985            tape_device,        // parameter #5
     986            tape_size_sz,       // parameter #6
     987            lines_in_filelist,  // parameter #7 (INT)
     988            use_lzo_sz,         // parameter #8
     989            cd_recovery_sz,     // parameter #9
     990            bkpinfo->image_devs,    // parameter #10
     991            broken_bios_sz,     // parameter #11
     992            last_filelist_number,   // parameter #12 (STRING)
     993            estimated_total_noof_slices,    // parameter #13 (INT)
     994            devs_to_exclude,    // parameter #14
     995            use_comp_sz,        // parameter #15
     996            use_lilo_sz,        // parameter #16
     997            use_star_sz,        // parameter #17
     998            bkpinfo->internal_tape_block_size,  // parameter #18 (LONG)
     999            bkpinfo->differential); // parameter #19 (INT)
     1000
    9601001// Watch it! This next line adds a parameter...
    961   if (bkpinfo->nonbootable_backup) { strcat(command, " NONBOOTABLE"); }
    962   log_msg (2, command);
     1002    if (bkpinfo->nonbootable_backup) {
     1003        strcat(command, " NONBOOTABLE");
     1004    }
     1005    log_msg(2, command);
    9631006
    9641007//  popup_and_OK("Pausing");
    965  
    966   res = run_program_and_log_to_screen (command, "Generating boot+data disks");
    967   if (bkpinfo->nonbootable_backup) { res=0; } // hack
    968   if (!res)
    969     {
    970       log_to_screen ("Boot+data disks were created OK");
    971       sprintf (command, "mkdir -p /root/images/mindi/");
    972       log_msg (2, command);
    973       run_program_and_log_output (command, FALSE);
    974       sprintf (command, "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
    975            bkpinfo->scratchdir);
    976       log_msg (2, command);
    977       run_program_and_log_output (command, FALSE);
    978       if (bkpinfo->nonbootable_backup)
    979         {
    980           sprintf(command, "cp -f %s/all.tar.gz %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir);
    981           if (system(command)) { fatal_error("Unable to create temporary duff tarball"); }
    982         }
    983       sprintf(command, "cp -f %s/mindi-*oot*.img %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir);
    984       sprintf (tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
    985       if (system (tmp)) { fatal_error ("Cannot find all.tar.gz in tmpdir"); }
    986       if (res) { mvaddstr_and_log_it (g_currentY++, 74, "Errors."); }
    987       else {  mvaddstr_and_log_it (g_currentY++, 74, "Done."); }
    988     }
    989   else
    990     {
    991       log_to_screen ("Mindi failed to create your boot+data disks.");
    992       sprintf (command, "grep 'Fatal error' %s", "/var/log/mindi.log");
    993       strcpy (tmp, call_program_and_get_last_line_of_output (command));
    994       if (strlen (tmp) > 1)
    995         {
    996           log_to_screen (tmp);
    997         }
    998     }
    999   paranoid_free(tmp); paranoid_free(use_lzo_sz); paranoid_free(scratchdir);
    1000   paranoid_free(use_comp_sz); paranoid_free(bootldr_str); paranoid_free(tape_device);
    1001   paranoid_free(last_filelist_number); paranoid_free(broken_bios_sz); paranoid_free(cd_recovery_sz);
    1002   paranoid_free(tape_size_sz); paranoid_free(devs_to_exclude); paranoid_free(use_lilo_sz); paranoid_free(value);
    1003   paranoid_free(bootdev); paranoid_free(command); paranoid_free(use_star_sz);
    1004   return (res);
     1008
     1009    res =
     1010        run_program_and_log_to_screen(command,
     1011                                      "Generating boot+data disks");
     1012    if (bkpinfo->nonbootable_backup) {
     1013        res = 0;
     1014    }                           // hack
     1015    if (!res) {
     1016        log_to_screen("Boot+data disks were created OK");
     1017        sprintf(command, "mkdir -p /root/images/mindi/");
     1018        log_msg(2, command);
     1019        run_program_and_log_output(command, FALSE);
     1020        sprintf(command,
     1021                "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
     1022                bkpinfo->scratchdir);
     1023        log_msg(2, command);
     1024        run_program_and_log_output(command, FALSE);
     1025        if (bkpinfo->nonbootable_backup) {
     1026            sprintf(command, "cp -f %s/all.tar.gz %s/images",
     1027                    bkpinfo->tmpdir, bkpinfo->scratchdir);
     1028            if (system(command)) {
     1029                fatal_error("Unable to create temporary duff tarball");
     1030            }
     1031        }
     1032        sprintf(command, "cp -f %s/mindi-*oot*.img %s/images",
     1033                bkpinfo->tmpdir, bkpinfo->scratchdir);
     1034        sprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
     1035                bkpinfo->tmpdir);
     1036        if (system(tmp)) {
     1037            fatal_error("Cannot find all.tar.gz in tmpdir");
     1038        }
     1039        if (res) {
     1040            mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     1041        } else {
     1042            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1043        }
     1044    } else {
     1045        log_to_screen("Mindi failed to create your boot+data disks.");
     1046        sprintf(command, "grep 'Fatal error' %s", "/var/log/mindi.log");
     1047        strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1048        if (strlen(tmp) > 1) {
     1049            log_to_screen(tmp);
     1050        }
     1051    }
     1052    paranoid_free(tmp);
     1053    paranoid_free(use_lzo_sz);
     1054    paranoid_free(scratchdir);
     1055    paranoid_free(use_comp_sz);
     1056    paranoid_free(bootldr_str);
     1057    paranoid_free(tape_device);
     1058    paranoid_free(last_filelist_number);
     1059    paranoid_free(broken_bios_sz);
     1060    paranoid_free(cd_recovery_sz);
     1061    paranoid_free(tape_size_sz);
     1062    paranoid_free(devs_to_exclude);
     1063    paranoid_free(use_lilo_sz);
     1064    paranoid_free(value);
     1065    paranoid_free(bootdev);
     1066    paranoid_free(command);
     1067    paranoid_free(use_star_sz);
     1068    return (res);
    10051069}
    10061070
     
    10431107 * @ingroup LLarchiveGroup
    10441108 */
    1045 void *create_afio_files_in_background(void*inbuf)
     1109void *create_afio_files_in_background(void *inbuf)
    10461110{
    1047   long int archiving_set_no;
    1048   char *archiving_filelist_fname;
    1049   char * archiving_afioball_fname;
    1050   char *curr_xattr_list_fname;
    1051   char *curr_acl_list_fname;
    1052    
    1053   struct s_bkpinfo*bkpinfo;
    1054   char *tmp;
    1055   int res=0, retval=0;
    1056   int *p_archival_threads_running;
    1057   int *p_last_set_archived;
    1058   int *p_next_set_to_archive;
    1059   char *p_list_of_fileset_flags;
    1060   int this_thread_no = g_current_thread_no++;
    1061 
    1062   malloc_string(curr_xattr_list_fname);
    1063   malloc_string(curr_acl_list_fname);
    1064   malloc_string(archiving_filelist_fname);
    1065   malloc_string(archiving_afioball_fname);
    1066   malloc_string(tmp);
    1067   p_last_set_archived = (int*)inbuf;
    1068   p_archival_threads_running = (int*)(inbuf+4);
    1069   p_next_set_to_archive = (int*)(inbuf+8);
    1070   p_list_of_fileset_flags = (char*)(inbuf+12);
    1071   bkpinfo = (struct s_bkpinfo*)(inbuf+BKPINFO_LOC_OFFSET);
    1072 
    1073   sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
    1074   for (archiving_set_no = 0; does_file_exist (archiving_filelist_fname);
    1075        sprintf (archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1076         archiving_set_no))
    1077     {
    1078       if (g_exiting)
    1079     { fatal_error("Execution run aborted (pthread)"); }
    1080       if (archiving_set_no >= MAX_NOOF_SETS_HERE)
    1081     { fatal_error("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please."); }
    1082       if (!semaphore_p()) { log_msg(3, "P sem failed (pid=%d)", (int)getpid()); fatal_error("Cannot get semaphore P"); }
    1083       if (archiving_set_no < *p_next_set_to_archive)
    1084     {
    1085       archiving_set_no= *p_next_set_to_archive;
    1086     }
    1087       *p_next_set_to_archive = *p_next_set_to_archive + 1;
    1088       if (!semaphore_v()) { fatal_error("Cannot get semaphore V"); }
    1089 
    1090       /* backup this set of files */
    1091       sprintf (archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,bkpinfo->tmpdir,
    1092                archiving_set_no, bkpinfo->zip_suffix);
    1093       sprintf (archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,bkpinfo->tmpdir,
    1094            archiving_set_no);
    1095       if (!does_file_exist(archiving_filelist_fname))
    1096     {
    1097       log_msg (3, "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1098       break;
    1099     }
    1100 
    1101       sprintf (tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no-ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
    1102       if (does_file_exist(tmp))
    1103     {
    1104       log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, getpid(), this_thread_no);
    1105       while (does_file_exist(tmp))
    1106         {
    1107           sleep(1);
    1108         }
    1109       log_msg(4, "[%d] - continuing", getpid());
    1110     }
    1111    
    1112       log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1113       sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    1114       sprintf (curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    1115       get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
    1116       get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
    1117      
    1118       log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1119       res = archive_this_fileset (bkpinfo, archiving_filelist_fname,
    1120                   archiving_afioball_fname,
    1121                   archiving_set_no);
    1122       retval += res;
    1123 
    1124       if (res)
    1125     {
    1126       sprintf (tmp,
    1127            "Errors occurred while archiving set %ld. Please review logs.",
    1128            archiving_set_no);
    1129       log_to_screen (tmp);
    1130     }
    1131       if (!semaphore_p()) { fatal_error("Cannot get semaphore P"); }
    1132 
    1133       set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
    1134 
    1135       if (*p_last_set_archived < archiving_set_no)
    1136     { *p_last_set_archived = archiving_set_no; } // finished archiving this one
    1137 
    1138       if (!semaphore_v()) { fatal_error("Cannot get semaphore V"); }
    1139       log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    1140       archiving_set_no ++;
    1141     }
    1142   if (!semaphore_p()) { fatal_error("Cannot get semaphore P"); }
    1143   (*p_archival_threads_running) --;
    1144   if (!semaphore_v()) { fatal_error("Cannot get semaphore V"); }
    1145   log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), this_thread_no);
    1146   paranoid_free(archiving_filelist_fname);
    1147   paranoid_free(archiving_afioball_fname);
    1148   paranoid_free(curr_xattr_list_fname);
    1149   paranoid_free(curr_acl_list_fname);
    1150   paranoid_free(tmp);
    1151   pthread_exit(NULL);
     1111    long int archiving_set_no;
     1112    char *archiving_filelist_fname;
     1113    char *archiving_afioball_fname;
     1114    char *curr_xattr_list_fname;
     1115    char *curr_acl_list_fname;
     1116
     1117    struct s_bkpinfo *bkpinfo;
     1118    char *tmp;
     1119    int res = 0, retval = 0;
     1120    int *p_archival_threads_running;
     1121    int *p_last_set_archived;
     1122    int *p_next_set_to_archive;
     1123    char *p_list_of_fileset_flags;
     1124    int this_thread_no = g_current_thread_no++;
     1125
     1126    malloc_string(curr_xattr_list_fname);
     1127    malloc_string(curr_acl_list_fname);
     1128    malloc_string(archiving_filelist_fname);
     1129    malloc_string(archiving_afioball_fname);
     1130    malloc_string(tmp);
     1131    p_last_set_archived = (int *) inbuf;
     1132    p_archival_threads_running = (int *) (inbuf + 4);
     1133    p_next_set_to_archive = (int *) (inbuf + 8);
     1134    p_list_of_fileset_flags = (char *) (inbuf + 12);
     1135    bkpinfo = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET);
     1136
     1137    sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1138            bkpinfo->tmpdir, 0L);
     1139    for (archiving_set_no = 0; does_file_exist(archiving_filelist_fname);
     1140         sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1141                 bkpinfo->tmpdir, archiving_set_no)) {
     1142        if (g_exiting) {
     1143            fatal_error("Execution run aborted (pthread)");
     1144        }
     1145        if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
     1146            fatal_error
     1147                ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
     1148        }
     1149        if (!semaphore_p()) {
     1150            log_msg(3, "P sem failed (pid=%d)", (int) getpid());
     1151            fatal_error("Cannot get semaphore P");
     1152        }
     1153        if (archiving_set_no < *p_next_set_to_archive) {
     1154            archiving_set_no = *p_next_set_to_archive;
     1155        }
     1156        *p_next_set_to_archive = *p_next_set_to_archive + 1;
     1157        if (!semaphore_v()) {
     1158            fatal_error("Cannot get semaphore V");
     1159        }
     1160
     1161        /* backup this set of files */
     1162        sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     1163                bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
     1164        sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1165                bkpinfo->tmpdir, archiving_set_no);
     1166        if (!does_file_exist(archiving_filelist_fname)) {
     1167            log_msg(3,
     1168                    "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
     1169                    FORTY_SPACES, getpid(), this_thread_no,
     1170                    archiving_set_no);
     1171            break;
     1172        }
     1173
     1174        sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
     1175                archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
     1176        if (does_file_exist(tmp)) {
     1177            log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES,
     1178                    getpid(), this_thread_no);
     1179            while (does_file_exist(tmp)) {
     1180                sleep(1);
     1181            }
     1182            log_msg(4, "[%d] - continuing", getpid());
     1183        }
     1184
     1185        log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(),
     1186                this_thread_no, archiving_set_no);
     1187        sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     1188                bkpinfo->tmpdir, archiving_set_no);
     1189        sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     1190                bkpinfo->tmpdir, archiving_set_no);
     1191        get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
     1192        get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
     1193
     1194        log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(),
     1195                this_thread_no, archiving_set_no);
     1196        res =
     1197            archive_this_fileset(bkpinfo, archiving_filelist_fname,
     1198                                 archiving_afioball_fname,
     1199                                 archiving_set_no);
     1200        retval += res;
     1201
     1202        if (res) {
     1203            sprintf(tmp,
     1204                    "Errors occurred while archiving set %ld. Please review logs.",
     1205                    archiving_set_no);
     1206            log_to_screen(tmp);
     1207        }
     1208        if (!semaphore_p()) {
     1209            fatal_error("Cannot get semaphore P");
     1210        }
     1211
     1212        set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
     1213
     1214        if (*p_last_set_archived < archiving_set_no) {
     1215            *p_last_set_archived = archiving_set_no;
     1216        }                       // finished archiving this one
     1217
     1218        if (!semaphore_v()) {
     1219            fatal_error("Cannot get semaphore V");
     1220        }
     1221        log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(),
     1222                this_thread_no, archiving_set_no);
     1223        archiving_set_no++;
     1224    }
     1225    if (!semaphore_p()) {
     1226        fatal_error("Cannot get semaphore P");
     1227    }
     1228    (*p_archival_threads_running)--;
     1229    if (!semaphore_v()) {
     1230        fatal_error("Cannot get semaphore V");
     1231    }
     1232    log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(),
     1233            this_thread_no);
     1234    paranoid_free(archiving_filelist_fname);
     1235    paranoid_free(archiving_afioball_fname);
     1236    paranoid_free(curr_xattr_list_fname);
     1237    paranoid_free(curr_acl_list_fname);
     1238    paranoid_free(tmp);
     1239    pthread_exit(NULL);
    11521240}
    11531241
     
    11651253 * @ingroup MLarchiveGroup
    11661254 */
    1167 int
    1168 do_that_final_phase (struct s_bkpinfo *bkpinfo)
     1255int do_that_final_phase(struct s_bkpinfo *bkpinfo)
    11691256{
    11701257
    1171     /*@ int ***************************************/
    1172   int res = 0;
    1173   int retval = 0;
    1174 
    1175     /*@ buffers ***********************************/
    1176 
    1177   assert(bkpinfo!=NULL);
    1178   mvaddstr_and_log_it (g_currentY, 0, "Writing any remaining data to media         ");
    1179 
    1180   log_msg (1, "Closing tape/CD ... ");
    1181   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1182     /* write tape/cdstream */
    1183     {
    1184       closeout_tape(bkpinfo);
    1185     }
    1186   else
    1187     /* write final ISO */
    1188     {
    1189       res = write_final_iso_if_necessary (bkpinfo);
    1190       retval += res;
    1191       if (res)
     1258    /*@ int ************************************** */
     1259    int res = 0;
     1260    int retval = 0;
     1261
     1262    /*@ buffers ********************************** */
     1263
     1264    assert(bkpinfo != NULL);
     1265    mvaddstr_and_log_it(g_currentY, 0,
     1266                        "Writing any remaining data to media         ");
     1267
     1268    log_msg(1, "Closing tape/CD ... ");
     1269    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     1270        /* write tape/cdstream */
    11921271    {
    1193       log_msg (1, "write_final_iso_if_necessary returned an error");
    1194     }
    1195     }
    1196   log_msg (2, "Fork is exiting ... ");
    1197 
    1198   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1199 
    1200   /* final stuff */
    1201   if (retval)
    1202     {
    1203       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    1204     }
    1205   else
    1206     {
    1207       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1208     }
    1209 
    1210   return (retval);
     1272        closeout_tape(bkpinfo);
     1273    } else
     1274        /* write final ISO */
     1275    {
     1276        res = write_final_iso_if_necessary(bkpinfo);
     1277        retval += res;
     1278        if (res) {
     1279            log_msg(1, "write_final_iso_if_necessary returned an error");
     1280        }
     1281    }
     1282    log_msg(2, "Fork is exiting ... ");
     1283
     1284    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1285
     1286    /* final stuff */
     1287    if (retval) {
     1288        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     1289    } else {
     1290        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1291    }
     1292
     1293    return (retval);
    12111294}
    12121295
     
    12311314 * @ingroup MLarchiveGroup
    12321315 */
    1233 int
    1234 do_that_initial_phase (struct s_bkpinfo *bkpinfo)
     1316int do_that_initial_phase(struct s_bkpinfo *bkpinfo)
    12351317{
    1236     /*@ int ****************************************/
    1237   int retval = 0;
    1238 
    1239     /*@ buffers ************************************/
    1240   char*command, *tmpfile, *data_disks_file;
    1241    
    1242   assert(bkpinfo!=NULL);
    1243   malloc_string(command);
    1244   malloc_string(tmpfile);
    1245   malloc_string(data_disks_file);
    1246   sprintf (data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
    1247 
    1248   snprintf (g_serial_string, MAX_STR_LEN-1,
    1249         call_program_and_get_last_line_of_output("dd \
     1318    /*@ int *************************************** */
     1319    int retval = 0;
     1320
     1321    /*@ buffers *********************************** */
     1322    char *command, *tmpfile, *data_disks_file;
     1323
     1324    assert(bkpinfo != NULL);
     1325    malloc_string(command);
     1326    malloc_string(tmpfile);
     1327    malloc_string(data_disks_file);
     1328    sprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
     1329
     1330    snprintf(g_serial_string, MAX_STR_LEN - 1,
     1331            call_program_and_get_last_line_of_output("dd \
    12501332if=/dev/urandom bs=16 count=1 2> /dev/null | \
    12511333hexdump | tr -s ' ' '0' | head -n1"));
    1252   strip_spaces(g_serial_string);
    1253   strcat(g_serial_string, "...word.");
    1254   log_msg(2, "g_serial_string = '%s'", g_serial_string);
    1255   assert(strlen(g_serial_string) < MAX_STR_LEN);
    1256 
    1257   sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
    1258   if (write_one_liner_data_file (tmpfile, g_serial_string)) { log_msg(1, "%ld: Failed to write serial string", __LINE__); }
    1259 
    1260   mvaddstr_and_log_it (g_currentY, 0, "Preparing to archive your data");
    1261   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1262     {
    1263       if (bkpinfo->backup_media_type == cdstream)
    1264         {
    1265           openout_cdstream (bkpinfo->media_device, bkpinfo->cdrw_speed);
    1266         }
    1267       else
    1268         {
    1269           openout_tape (bkpinfo->media_device, bkpinfo->internal_tape_block_size);  /* sets g_tape_stream */
    1270         }
    1271       if (!g_tape_stream)
    1272     {
    1273       fatal_error ("Cannot open backup (streaming) device");
    1274     }
    1275       log_msg (1, "Backup (stream) opened OK");
    1276       write_data_disks_to_stream (data_disks_file);
    1277     }
    1278   else
    1279     {
    1280       log_msg (1, "Backing up to CD's");
    1281     }
    1282 
    1283   sprintf (command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
    1284                         bkpinfo->nfs_remote_dir, bkpinfo->prefix);
    1285   paranoid_system (command);
    1286   wipe_archives (bkpinfo->scratchdir);
    1287   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1288   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1289     {
    1290       write_header_block_to_stream (0, "start-of-tape", BLK_START_OF_TAPE);
    1291       write_header_block_to_stream (0, "start-of-backup", BLK_START_OF_BACKUP);
    1292     }
    1293   paranoid_free(command);
    1294   paranoid_free(tmpfile);
    1295   paranoid_free(data_disks_file);
    1296   return (retval);
     1334    strip_spaces(g_serial_string);
     1335    strcat(g_serial_string, "...word.");
     1336    log_msg(2, "g_serial_string = '%s'", g_serial_string);
     1337    assert(strlen(g_serial_string) < MAX_STR_LEN);
     1338
     1339    sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
     1340    if (write_one_liner_data_file(tmpfile, g_serial_string)) {
     1341        log_msg(1, "%ld: Failed to write serial string", __LINE__);
     1342    }
     1343
     1344    mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
     1345    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1346        if (bkpinfo->backup_media_type == cdstream) {
     1347            openout_cdstream(bkpinfo->media_device, bkpinfo->cdrw_speed);
     1348        } else {
     1349            openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
     1350        }
     1351        if (!g_tape_stream) {
     1352            fatal_error("Cannot open backup (streaming) device");
     1353        }
     1354        log_msg(1, "Backup (stream) opened OK");
     1355        write_data_disks_to_stream(data_disks_file);
     1356    } else {
     1357        log_msg(1, "Backing up to CD's");
     1358    }
     1359
     1360    sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
     1361            bkpinfo->nfs_remote_dir, bkpinfo->prefix);
     1362    paranoid_system(command);
     1363    wipe_archives(bkpinfo->scratchdir);
     1364    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1365    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1366        write_header_block_to_stream(0, "start-of-tape",
     1367                                     BLK_START_OF_TAPE);
     1368        write_header_block_to_stream(0, "start-of-backup",
     1369                                     BLK_START_OF_BACKUP);
     1370    }
     1371    paranoid_free(command);
     1372    paranoid_free(tmpfile);
     1373    paranoid_free(data_disks_file);
     1374    return (retval);
    12971375}
    12981376
     
    13081386 * @return The exit code of fdformat/superformat.
    13091387 */
    1310 int
    1311 format_disk_SUB (char *cmd, char *title)
     1388int format_disk_SUB(char *cmd, char *title)
    13121389{
    13131390
    1314     /*@ int ****************************************************************/
    1315   int res = 0;
     1391    /*@ int *************************************************************** */
     1392    int res = 0;
    13161393    int percentage = 0;
    13171394    int maxtracks = 0;
     
    13191396    int last_trkno = 0;
    13201397
    1321     /*@ buffers ************************************************************/
    1322   char *command;
    1323   char *tempfile;
    1324 
    1325     /*@ pointers ***********************************************************/
    1326   FILE *pin;
    1327 
    1328   assert_string_is_neither_NULL_nor_zerolength(cmd);
    1329   assert_string_is_neither_NULL_nor_zerolength(title);
    1330 
    1331   malloc_string(command);
    1332   malloc_string(tempfile);
     1398    /*@ buffers *********************************************************** */
     1399    char *command;
     1400    char *tempfile;
     1401
     1402    /*@ pointers ********************************************************** */
     1403    FILE *pin;
     1404
     1405    assert_string_is_neither_NULL_nor_zerolength(cmd);
     1406    assert_string_is_neither_NULL_nor_zerolength(title);
     1407
     1408    malloc_string(command);
     1409    malloc_string(tempfile);
    13331410#ifdef __FreeBSD__
    13341411/* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
     
    13381415   not done yet.
    13391416*/
    1340     return (run_program_and_log_to_screen (cmd, title));
     1417    return (run_program_and_log_to_screen(cmd, title));
    13411418#endif
    13421419
    13431420/* if Debian then do bog-standard superformat; don't be pretty */
    1344   if (strstr (cmd, "superformat"))
    1345     {
    1346       return (run_program_and_log_to_screen (cmd, title));
    1347     }
     1421    if (strstr(cmd, "superformat")) {
     1422        return (run_program_and_log_to_screen(cmd, title));
     1423    }
    13481424/* if not Debian then go ahead & use fdformat */
    1349   strcpy (tempfile,
    1350       call_program_and_get_last_line_of_output
    1351       ("mktemp -q /tmp/mondo.XXXXXXXX"));
    1352   sprintf (command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    1353        tempfile);
    1354   log_msg (3, command);
    1355   open_evalcall_form (title);
    1356   if (!(pin = popen (command, "r")))
    1357     {
    1358       log_OS_error ("fmt err");
    1359       return (1);
    1360     }
    1361   if (strstr (command, "1722"))
    1362     {
    1363       maxtracks = 82;
    1364     }
    1365   else
    1366     {
    1367       maxtracks = 80;
    1368     }
    1369   for (sleep (1); does_file_exist (tempfile); sleep (1))
    1370     {
    1371       trackno = get_trackno_from_logfile (tempfile);
    1372       if (trackno < 0 || trackno > 80)
    1373     {
    1374       log_msg (1, "Weird track#");
    1375       continue;
    1376     }
    1377       percentage = trackno * 100 / maxtracks;
    1378       if (trackno <= 5 && last_trkno > 40)
    1379     {
    1380       close_evalcall_form ();
    1381       strcpy (title, "Verifying format");
    1382       open_evalcall_form (title);
    1383     }
    1384       last_trkno = trackno;
    1385       update_evalcall_form (percentage);
    1386     }
    1387   close_evalcall_form ();
    1388   if (pclose (pin)) { res++; log_OS_error("Unable to pclose"); }
    1389   unlink (tempfile);
    1390   paranoid_free(command);
    1391   paranoid_free(tempfile);
    1392   return (res);
     1425    strcpy(tempfile,
     1426           call_program_and_get_last_line_of_output
     1427           ("mktemp -q /tmp/mondo.XXXXXXXX"));
     1428    sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
     1429            tempfile);
     1430    log_msg(3, command);
     1431    open_evalcall_form(title);
     1432    if (!(pin = popen(command, "r"))) {
     1433        log_OS_error("fmt err");
     1434        return (1);
     1435    }
     1436    if (strstr(command, "1722")) {
     1437        maxtracks = 82;
     1438    } else {
     1439        maxtracks = 80;
     1440    }
     1441    for (sleep(1); does_file_exist(tempfile); sleep(1)) {
     1442        trackno = get_trackno_from_logfile(tempfile);
     1443        if (trackno < 0 || trackno > 80) {
     1444            log_msg(1, "Weird track#");
     1445            continue;
     1446        }
     1447        percentage = trackno * 100 / maxtracks;
     1448        if (trackno <= 5 && last_trkno > 40) {
     1449            close_evalcall_form();
     1450            strcpy(title, "Verifying format");
     1451            open_evalcall_form(title);
     1452        }
     1453        last_trkno = trackno;
     1454        update_evalcall_form(percentage);
     1455    }
     1456    close_evalcall_form();
     1457    if (pclose(pin)) {
     1458        res++;
     1459        log_OS_error("Unable to pclose");
     1460    }
     1461    unlink(tempfile);
     1462    paranoid_free(command);
     1463    paranoid_free(tempfile);
     1464    return (res);
    13931465}
    13941466
     
    14041476 * @ingroup deviceGroup
    14051477 */
    1406 int
    1407 format_disk (char *device)
     1478int format_disk(char *device)
    14081479{
    1409    
    1410     /*@ int ***************************************************************/
    1411   int res = 0;
    1412 
    1413     /*@ buffer ************************************************************/
    1414   char *command;
    1415   char *title;
    1416  
    1417 
    1418   assert_string_is_neither_NULL_nor_zerolength(device);
    1419   malloc_string(title);
    1420   command = malloc(1000);
    1421   if (!system ("which superformat > /dev/null 2> /dev/null"))
    1422     {
    1423       sprintf (command, "superformat %s", device);
    1424     }
    1425   else
    1426     {
     1480
     1481    /*@ int ************************************************************** */
     1482    int res = 0;
     1483
     1484    /*@ buffer *********************************************************** */
     1485    char *command;
     1486    char *title;
     1487
     1488
     1489    assert_string_is_neither_NULL_nor_zerolength(device);
     1490    malloc_string(title);
     1491    command = malloc(1000);
     1492    if (!system("which superformat > /dev/null 2> /dev/null")) {
     1493        sprintf(command, "superformat %s", device);
     1494    } else {
    14271495#ifdef __FreeBSD__
    1428       sprintf (command, "fdformat -y %s", device);
     1496        sprintf(command, "fdformat -y %s", device);
    14291497#else
    1430       sprintf (command, "fdformat %s", device);
     1498        sprintf(command, "fdformat %s", device);
    14311499#endif
    1432     }
    1433   sprintf (title, "Formatting disk %s", device);
    1434   while ((res = format_disk_SUB (command, title)))
    1435     {
    1436       if (!ask_me_yes_or_no ("Failed to format disk. Retry?"))
    1437     {
    1438       return (res);
    1439     }
    1440     }
    1441   paranoid_free(title);
    1442   paranoid_free(command);
    1443   return (res);
     1500    }
     1501    sprintf(title, "Formatting disk %s", device);
     1502    while ((res = format_disk_SUB(command, title))) {
     1503        if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
     1504            return (res);
     1505        }
     1506    }
     1507    paranoid_free(title);
     1508    paranoid_free(command);
     1509    return (res);
    14441510}
    14451511
     
    14521518 * @ingroup utilityGroup
    14531519 */
    1454 bool get_bit_N_of_array(char*array, int N)
     1520bool get_bit_N_of_array(char *array, int N)
    14551521{
    1456   int element_number;
    1457   int bit_number;
    1458   int mask;
    1459  
    1460   element_number = N / 8;
    1461   bit_number = N % 8;
    1462   mask = 1 << bit_number;
    1463   if (array[element_number] & mask)
    1464     { return(TRUE); }
    1465   else
    1466     { return(FALSE); }
     1522    int element_number;
     1523    int bit_number;
     1524    int mask;
     1525
     1526    element_number = N / 8;
     1527    bit_number = N % 8;
     1528    mask = 1 << bit_number;
     1529    if (array[element_number] & mask) {
     1530        return (TRUE);
     1531    } else {
     1532        return (FALSE);
     1533    }
    14671534}
    14681535
     
    14971564 * @return The number of errors encountered (0 for success)
    14981565 */
    1499 int
    1500 make_afioballs_and_images (struct s_bkpinfo *bkpinfo)
     1566int make_afioballs_and_images(struct s_bkpinfo *bkpinfo)
    15011567{
    15021568
    1503     /*@ int ***************************************************/
    1504   int retval = 0;
    1505   long int storing_set_no = 0;
    1506   int res = 0;
    1507   bool done_storing=FALSE;
    1508   char *result_str;
    1509   char *transfer_block;
    1510   void*vp;
    1511   void**pvp;
    1512 
    1513     /*@ buffers ***********************************************/
    1514   char *storing_filelist_fname;
    1515   char *storing_afioball_fname;
    1516   char *tmp;
    1517   char *media_usage_comment;
    1518   pthread_t archival_thread[ARCH_THREADS];
    1519   char *p_list_of_fileset_flags;
    1520   int *p_archival_threads_running;
    1521   int *p_last_set_archived;
    1522   int *p_next_set_to_archive;
    1523   int noof_threads;
    1524   int i;
    1525   char *curr_xattr_list_fname;
    1526   char *curr_acl_list_fname;
    1527   int misc_counter_that_is_not_important=0; 
    1528  
    1529   log_msg(8, "here");
    1530   assert(bkpinfo!=NULL);
    1531   tmp = malloc(MAX_STR_LEN*2);
    1532   malloc_string(result_str);
    1533   malloc_string(curr_xattr_list_fname);
    1534   malloc_string(curr_acl_list_fname);
    1535   malloc_string(storing_filelist_fname);
    1536   malloc_string(media_usage_comment);
    1537   malloc_string(storing_afioball_fname);
    1538   transfer_block = malloc(sizeof(struct s_bkpinfo)+BKPINFO_LOC_OFFSET+64);
    1539   memset((void*)transfer_block, 0, sizeof(struct s_bkpinfo)+BKPINFO_LOC_OFFSET+64);
    1540   p_last_set_archived = (int*)transfer_block;
    1541   p_archival_threads_running = (int*)(transfer_block+4);
    1542   p_next_set_to_archive = (int*)(transfer_block+8);
    1543   p_list_of_fileset_flags = (char*)(transfer_block+12);
    1544   memcpy((void*)(transfer_block+BKPINFO_LOC_OFFSET), (void*)bkpinfo, sizeof(struct s_bkpinfo));
    1545   pvp=&vp;
    1546   vp=(void*)result_str;
    1547   *p_archival_threads_running = 0;
    1548   *p_last_set_archived = -1;
    1549   *p_next_set_to_archive = 0;
    1550   sprintf (tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    1551   log_to_screen ("Archiving regular files");
    1552   log_msg (5, "Go, Shorty. It's your birthday.");
    1553   open_progress_form ("Backing up filesystem",
    1554               "I am backing up your live filesystem now.",
    1555               "Please wait. This may take a couple of hours.",
    1556               "Working...", get_last_filelist_number (bkpinfo) + 1);
    1557 
    1558   log_msg (5, "We're gonna party like it's your birthday.");
    1559 
    1560   srand((unsigned int)getpid());
    1561   g_sem_key = 1234+random()%30000;
    1562   if ((g_sem_id = semget((key_t)g_sem_key, 1, IPC_CREAT|S_IREAD|S_IWRITE))==-1)
    1563     { fatal_error("MABAI - unable to semget"); }
    1564   if (!set_semvalue())
    1565     { fatal_error("Unable to init semaphore"); } // initialize semaphore
    1566   for(noof_threads=0; noof_threads<ARCH_THREADS; noof_threads++)
    1567     {
    1568       log_msg(8, "Creating thread #%d", noof_threads);
    1569       (*p_archival_threads_running) ++;
    1570       if ((res = pthread_create(&archival_thread[noof_threads], NULL, create_afio_files_in_background, (void*)transfer_block)))
    1571     { fatal_error("Unable to create an archival thread"); }
    1572     }
    1573 
    1574   log_msg(8, "About to enter while() loop");
    1575   while(!done_storing)
    1576     {
    1577       if (g_exiting) { fatal_error("Execution run aborted (main loop)"); }
    1578       if (*p_archival_threads_running == 0 && *p_last_set_archived == storing_set_no-1)
    1579     {
    1580       log_msg(2, "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)", *p_last_set_archived, storing_set_no);
    1581       done_storing = TRUE;
    1582     }
    1583       else if (!get_bit_N_of_array(p_list_of_fileset_flags, storing_set_no))
    1584     {
    1585       misc_counter_that_is_not_important = (misc_counter_that_is_not_important+1) % 5;
    1586       if (!misc_counter_that_is_not_important)
    1587         { update_progress_form (media_usage_comment); }
    1588       sleep(1);
    1589     }
    1590       else
    1591     // store set N
    1592     {
    1593       sprintf (storing_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1594            storing_set_no);
    1595       sprintf (storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1596            storing_set_no, bkpinfo->zip_suffix);
    1597           sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    1598           sprintf (curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    1599 
    1600       log_msg (2, "Storing set %d", storing_set_no);
    1601       while(!does_file_exist(storing_filelist_fname) || !does_file_exist(storing_afioball_fname))
    1602         {
    1603           log_msg (2, "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.", storing_filelist_fname, storing_afioball_fname);
    1604           sleep(5);
    1605         }
    1606       strcpy (media_usage_comment, percent_media_full_comment (bkpinfo));
    1607       /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    1608       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1609         {
    1610               register_in_tape_catalog(fileset, storing_set_no, -1, storing_afioball_fname);
    1611           maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname);
    1612           iamhere("Writing EXAT files");
    1613               res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname, curr_acl_list_fname);
     1569    /*@ int ************************************************** */
     1570    int retval = 0;
     1571    long int storing_set_no = 0;
     1572    int res = 0;
     1573    bool done_storing = FALSE;
     1574    char *result_str;
     1575    char *transfer_block;
     1576    void *vp;
     1577    void **pvp;
     1578
     1579    /*@ buffers ********************************************** */
     1580    char *storing_filelist_fname;
     1581    char *storing_afioball_fname;
     1582    char *tmp;
     1583    char *media_usage_comment;
     1584    pthread_t archival_thread[ARCH_THREADS];
     1585    char *p_list_of_fileset_flags;
     1586    int *p_archival_threads_running;
     1587    int *p_last_set_archived;
     1588    int *p_next_set_to_archive;
     1589    int noof_threads;
     1590    int i;
     1591    char *curr_xattr_list_fname;
     1592    char *curr_acl_list_fname;
     1593    int misc_counter_that_is_not_important = 0;
     1594
     1595    log_msg(8, "here");
     1596    assert(bkpinfo != NULL);
     1597    tmp = malloc(MAX_STR_LEN * 2);
     1598    malloc_string(result_str);
     1599    malloc_string(curr_xattr_list_fname);
     1600    malloc_string(curr_acl_list_fname);
     1601    malloc_string(storing_filelist_fname);
     1602    malloc_string(media_usage_comment);
     1603    malloc_string(storing_afioball_fname);
     1604    transfer_block =
     1605        malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1606    memset((void *) transfer_block, 0,
     1607           sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1608    p_last_set_archived = (int *) transfer_block;
     1609    p_archival_threads_running = (int *) (transfer_block + 4);
     1610    p_next_set_to_archive = (int *) (transfer_block + 8);
     1611    p_list_of_fileset_flags = (char *) (transfer_block + 12);
     1612    memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
     1613           (void *) bkpinfo, sizeof(struct s_bkpinfo));
     1614    pvp = &vp;
     1615    vp = (void *) result_str;
     1616    *p_archival_threads_running = 0;
     1617    *p_last_set_archived = -1;
     1618    *p_next_set_to_archive = 0;
     1619    sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
     1620    log_to_screen("Archiving regular files");
     1621    log_msg(5, "Go, Shorty. It's your birthday.");
     1622    open_progress_form("Backing up filesystem",
     1623                       "I am backing up your live filesystem now.",
     1624                       "Please wait. This may take a couple of hours.",
     1625                       "Working...",
     1626                       get_last_filelist_number(bkpinfo) + 1);
     1627
     1628    log_msg(5, "We're gonna party like it's your birthday.");
     1629
     1630    srand((unsigned int) getpid());
     1631    g_sem_key = 1234 + random() % 30000;
     1632    if ((g_sem_id =
     1633         semget((key_t) g_sem_key, 1,
     1634                IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
     1635        fatal_error("MABAI - unable to semget");
     1636    }
     1637    if (!set_semvalue()) {
     1638        fatal_error("Unable to init semaphore");
     1639    }                           // initialize semaphore
     1640    for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
     1641        log_msg(8, "Creating thread #%d", noof_threads);
     1642        (*p_archival_threads_running)++;
     1643        if ((res =
     1644             pthread_create(&archival_thread[noof_threads], NULL,
     1645                            create_afio_files_in_background,
     1646                            (void *) transfer_block))) {
     1647            fatal_error("Unable to create an archival thread");
     1648        }
     1649    }
     1650
     1651    log_msg(8, "About to enter while() loop");
     1652    while (!done_storing) {
     1653        if (g_exiting) {
     1654            fatal_error("Execution run aborted (main loop)");
     1655        }
     1656        if (*p_archival_threads_running == 0
     1657            && *p_last_set_archived == storing_set_no - 1) {
     1658            log_msg(2,
     1659                    "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)",
     1660                    *p_last_set_archived, storing_set_no);
     1661            done_storing = TRUE;
     1662        } else
     1663            if (!get_bit_N_of_array
     1664                (p_list_of_fileset_flags, storing_set_no)) {
     1665            misc_counter_that_is_not_important =
     1666                (misc_counter_that_is_not_important + 1) % 5;
     1667            if (!misc_counter_that_is_not_important) {
     1668                update_progress_form(media_usage_comment);
     1669            }
     1670            sleep(1);
     1671        } else
     1672            // store set N
     1673        {
     1674            sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
     1675                    bkpinfo->tmpdir, storing_set_no);
     1676            sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     1677                    bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
     1678            sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     1679                    bkpinfo->tmpdir, storing_set_no);
     1680            sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     1681                    bkpinfo->tmpdir, storing_set_no);
     1682
     1683            log_msg(2, "Storing set %d", storing_set_no);
     1684            while (!does_file_exist(storing_filelist_fname)
     1685                   || !does_file_exist(storing_afioball_fname)) {
     1686                log_msg(2,
     1687                        "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
     1688                        storing_filelist_fname, storing_afioball_fname);
     1689                sleep(5);
     1690            }
     1691            strcpy(media_usage_comment,
     1692                   percent_media_full_comment(bkpinfo));
     1693            /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     1694            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1695                register_in_tape_catalog(fileset, storing_set_no, -1,
     1696                                         storing_afioball_fname);
     1697                maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     1698                                                       storing_afioball_fname);
     1699                iamhere("Writing EXAT files");
     1700                res +=
     1701                    write_EXAT_files_to_tape(bkpinfo,
     1702                                             curr_xattr_list_fname,
     1703                                             curr_acl_list_fname);
    16141704// archives themselves
    1615           res += move_files_to_stream (bkpinfo, storing_afioball_fname, NULL);
    1616         }
    1617       else
    1618         {
    1619           res = move_files_to_cd (bkpinfo, storing_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, storing_afioball_fname, NULL);
    1620         }
    1621       retval += res;
    1622       g_current_progress++;
    1623       update_progress_form (media_usage_comment);
    1624       if (res)
    1625         {
    1626           sprintf (tmp, "Failed to add archive %ld's files to CD dir\n",
    1627                storing_set_no);
    1628           log_to_screen (tmp);
    1629           fatal_error
    1630         ("Is your hard disk full? If not, please send the author the logfile.");
    1631         }
    1632       storing_set_no++;
    1633       //      sleep(2);
    1634     }
    1635     }
    1636   close_progress_form ();
    1637 
    1638   sprintf (tmp, "Your regular files have been archived ");
    1639   log_msg(2, "Joining background threads to foreground thread");
    1640   for(i=0; i<noof_threads; i++)
    1641     {
    1642       pthread_join(archival_thread[i], pvp);
    1643       log_msg(3, "Thread %d of %d: closed OK", i+1, noof_threads);
    1644     }
    1645   del_semvalue();
    1646   log_msg (2, "Done.");
    1647   if (retval)
    1648     {
    1649       strcat (tmp, "(with errors).");
    1650     }
    1651   else
    1652     {
    1653       strcat (tmp, "successfully.");
    1654     }
    1655   log_to_screen (tmp);
    1656   paranoid_free(transfer_block);
    1657   paranoid_free(result_str);
    1658   paranoid_free(storing_filelist_fname);
    1659   paranoid_free(media_usage_comment);
    1660   paranoid_free(storing_afioball_fname);
    1661   paranoid_free(curr_xattr_list_fname);
    1662   paranoid_free(curr_acl_list_fname);
    1663   return (retval);
     1705                res +=
     1706                    move_files_to_stream(bkpinfo, storing_afioball_fname,
     1707                                         NULL);
     1708            } else {
     1709                res =
     1710                    move_files_to_cd(bkpinfo, storing_filelist_fname,
     1711                                     curr_xattr_list_fname,
     1712                                     curr_acl_list_fname,
     1713                                     storing_afioball_fname, NULL);
     1714            }
     1715            retval += res;
     1716            g_current_progress++;
     1717            update_progress_form(media_usage_comment);
     1718            if (res) {
     1719                sprintf(tmp,
     1720                        "Failed to add archive %ld's files to CD dir\n",
     1721                        storing_set_no);
     1722                log_to_screen(tmp);
     1723                fatal_error
     1724                    ("Is your hard disk full? If not, please send the author the logfile.");
     1725            }
     1726            storing_set_no++;
     1727            //      sleep(2);
     1728        }
     1729    }
     1730    close_progress_form();
     1731
     1732    sprintf(tmp, "Your regular files have been archived ");
     1733    log_msg(2, "Joining background threads to foreground thread");
     1734    for (i = 0; i < noof_threads; i++) {
     1735        pthread_join(archival_thread[i], pvp);
     1736        log_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
     1737    }
     1738    del_semvalue();
     1739    log_msg(2, "Done.");
     1740    if (retval) {
     1741        strcat(tmp, "(with errors).");
     1742    } else {
     1743        strcat(tmp, "successfully.");
     1744    }
     1745    log_to_screen(tmp);
     1746    paranoid_free(transfer_block);
     1747    paranoid_free(result_str);
     1748    paranoid_free(storing_filelist_fname);
     1749    paranoid_free(media_usage_comment);
     1750    paranoid_free(storing_afioball_fname);
     1751    paranoid_free(curr_xattr_list_fname);
     1752    paranoid_free(curr_acl_list_fname);
     1753    return (retval);
    16641754}
    16651755
    16661756
    1667 void pause_for_N_seconds(int how_long, char*msg)
     1757void pause_for_N_seconds(int how_long, char *msg)
    16681758{
    1669   int i;
    1670   open_evalcall_form(msg);
    1671   for(i=0; i<how_long; i++)
    1672     {
    1673       update_evalcall_form((int) ( (100.0/(float)(how_long)*i) ) );
    1674       sleep(1);
    1675     }
    1676   close_evalcall_form();
     1759    int i;
     1760    open_evalcall_form(msg);
     1761    for (i = 0; i < how_long; i++) {
     1762        update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
     1763        sleep(1);
     1764    }
     1765    close_evalcall_form();
    16771766}
    16781767
     
    16971786 * @return The number of errors encountered (0 for success)
    16981787 */
    1699 int
    1700 make_iso_fs (struct s_bkpinfo *bkpinfo, char *destfile)
     1788int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
    17011789{
    1702     /*@ int ***********************************************/
    1703   int retval = 0;
    1704   int res;
    1705 
    1706     /*@ buffers *******************************************/
    1707   char *tmp;
    1708   char *old_pwd;
    1709   char *result_sz;
    1710   char *message_to_screen;
    1711   char *sz_blank_disk;
    1712   char *fnam;
    1713   char *tmp2;
    1714   char *tmp3;
    1715   bool cd_is_mountable;
    1716 
    1717   malloc_string(old_pwd);
    1718   malloc_string(result_sz);
    1719   malloc_string(message_to_screen);
    1720   malloc_string(sz_blank_disk);
    1721   malloc_string(fnam);
    1722   tmp = malloc(1200);
    1723   tmp2 =malloc(1200);
    1724   tmp3 =malloc(1200);
    1725   assert(bkpinfo!=NULL);
    1726   assert_string_is_neither_NULL_nor_zerolength(destfile);
    1727 
    1728   sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
    1729   sprintf(tmp2,"%s/isolinux.bin", bkpinfo->tmpdir);
    1730   if (does_file_exist(tmp))
    1731     {
    1732       sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
    1733       paranoid_system(tmp3);
    1734     }
    1735   if (!does_file_exist(tmp) && does_file_exist(tmp2))
    1736     {
    1737       sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
    1738       paranoid_system(tmp3);
    1739     }
    1740   /*
    1741   if (!does_file_exist(tmp))
    1742     {
    1743       log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
    1744       strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
    1745       if (strlen(fnam)>0 && does_file_exist(fnam))
    1746         {
    1747           sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
    1748           res = run_program_and_log_output(tmp, FALSE);
    1749         }
    1750       else
    1751         {
    1752       res = 1;
    1753     }
    1754       if (res)
    1755     {
    1756       log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
    1757     }
    1758     }
    1759   */
    1760   free(tmp2);
    1761   free(tmp3);
    1762   tmp2 = NULL;
    1763   tmp3 = NULL;
    1764   if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray)
    1765     {
    1766       popup_and_OK("Please insert new media and press Enter.");
    1767     }
    1768 
    1769   log_msg (2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
    1770        bkpinfo->scratchdir, destfile);
    1771   (void) getcwd (old_pwd, MAX_STR_LEN - 1);
    1772   sprintf (tmp, "chmod 744 %s", bkpinfo->scratchdir);
    1773   run_program_and_log_output(tmp, FALSE);
    1774   chdir (bkpinfo->scratchdir);
    1775 
    1776   if (bkpinfo->call_before_iso[0] != '\0')
    1777     {
    1778       sprintf (message_to_screen, "Running pre-ISO call for CD#%d",
    1779            g_current_media_number);
    1780       res =
    1781     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_before_iso, destfile,
    1782            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1783       if (res)
    1784     {
    1785       strcat (message_to_screen, "...failed");
    1786     }
    1787       else
    1788     {
    1789       strcat (message_to_screen, "...OK");
    1790     }
    1791       log_to_screen (message_to_screen);
    1792       retval += res;
    1793     }
    1794 
    1795   if (bkpinfo->call_make_iso[0] != '\0')
    1796     {
    1797       log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
    1798       sprintf (tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    1799       sprintf (message_to_screen, "Making an ISO (%s #%d)",
    1800                media_descriptor_string(bkpinfo->backup_media_type),
    1801            g_current_media_number);
    1802 
    1803       pause_and_ask_for_cdr (2, &cd_is_mountable);  /* if g_current_media_number >= 2 then pause & ask */
    1804       if (retval)
    1805          {
    1806        log_to_screen("Serious error(s) occurred already. I shan't try to write to media.");
    1807          }
    1808       else
    1809          {
    1810        res =
    1811         eval_call_to_make_ISO (bkpinfo, bkpinfo->call_make_iso, bkpinfo->scratchdir,
    1812            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1813           if (res)
    1814             {
    1815               log_to_screen ("%s...failed to write", message_to_screen);
    1816            }
    1817           else
    1818             {
    1819               log_to_screen ("%s...OK", message_to_screen);
    1820           if (!run_program_and_log_output("tail -n10 /var/log/mondo-archive.log | fgrep ':-('", 1))
    1821             {
    1822           log_to_screen("Despite nonfatal errors, growisofs confirms the write was successful.");
    1823         }
    1824             }
    1825           retval += res;
     1790    /*@ int ********************************************** */
     1791    int retval = 0;
     1792    int res;
     1793
     1794    /*@ buffers ****************************************** */
     1795    char *tmp;
     1796    char *old_pwd;
     1797    char *result_sz;
     1798    char *message_to_screen;
     1799    char *sz_blank_disk;
     1800    char *fnam;
     1801    char *tmp2;
     1802    char *tmp3;
     1803    bool cd_is_mountable;
     1804
     1805    malloc_string(old_pwd);
     1806    malloc_string(result_sz);
     1807    malloc_string(message_to_screen);
     1808    malloc_string(sz_blank_disk);
     1809    malloc_string(fnam);
     1810    tmp = malloc(1200);
     1811    tmp2 = malloc(1200);
     1812    tmp3 = malloc(1200);
     1813    assert(bkpinfo != NULL);
     1814    assert_string_is_neither_NULL_nor_zerolength(destfile);
     1815
     1816    sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
     1817    sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
     1818    if (does_file_exist(tmp)) {
     1819        sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
     1820        paranoid_system(tmp3);
     1821    }
     1822    if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
     1823        sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
     1824        paranoid_system(tmp3);
     1825    }
     1826    /*
     1827       if (!does_file_exist(tmp))
     1828       {
     1829       log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
     1830       strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
     1831       if (strlen(fnam)>0 && does_file_exist(fnam))
     1832       {
     1833       sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
     1834       res = run_program_and_log_output(tmp, FALSE);
     1835       }
     1836       else
     1837       {
     1838       res = 1;
     1839       }
     1840       if (res)
     1841       {
     1842       log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
     1843       }
     1844       }
     1845     */
     1846    free(tmp2);
     1847    free(tmp3);
     1848    tmp2 = NULL;
     1849    tmp3 = NULL;
     1850    if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
     1851        popup_and_OK("Please insert new media and press Enter.");
     1852    }
     1853
     1854    log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
     1855            bkpinfo->scratchdir, destfile);
     1856    (void) getcwd(old_pwd, MAX_STR_LEN - 1);
     1857    sprintf(tmp, "chmod 744 %s", bkpinfo->scratchdir);
     1858    run_program_and_log_output(tmp, FALSE);
     1859    chdir(bkpinfo->scratchdir);
     1860
     1861    if (bkpinfo->call_before_iso[0] != '\0') {
     1862        sprintf(message_to_screen, "Running pre-ISO call for CD#%d",
     1863                g_current_media_number);
     1864        res =
     1865            eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
     1866                                  destfile, g_current_media_number,
     1867                                  MONDO_LOGFILE, message_to_screen);
     1868        if (res) {
     1869            strcat(message_to_screen, "...failed");
     1870        } else {
     1871            strcat(message_to_screen, "...OK");
     1872        }
     1873        log_to_screen(message_to_screen);
     1874        retval += res;
     1875    }
     1876
     1877    if (bkpinfo->call_make_iso[0] != '\0') {
     1878        log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
     1879        sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     1880        sprintf(message_to_screen, "Making an ISO (%s #%d)",
     1881                media_descriptor_string(bkpinfo->backup_media_type),
     1882                g_current_media_number);
     1883
     1884        pause_and_ask_for_cdr(2, &cd_is_mountable); /* if g_current_media_number >= 2 then pause & ask */
     1885        if (retval) {
     1886            log_to_screen
     1887                ("Serious error(s) occurred already. I shan't try to write to media.");
     1888        } else {
     1889            res =
     1890                eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1891                                      bkpinfo->scratchdir,
     1892                                      g_current_media_number,
     1893                                      MONDO_LOGFILE, message_to_screen);
     1894            if (res) {
     1895                log_to_screen("%s...failed to write", message_to_screen);
     1896            } else {
     1897                log_to_screen("%s...OK", message_to_screen);
     1898                if (!run_program_and_log_output
     1899                    ("tail -n10 /var/log/mondo-archive.log | fgrep ':-('",
     1900                     1)) {
     1901                    log_to_screen
     1902                        ("Despite nonfatal errors, growisofs confirms the write was successful.");
     1903                }
     1904            }
     1905            retval += res;
    18261906#ifdef DVDRWFORMAT
    1827           sprintf(tmp, "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", MONDO_LOGFILE);
    1828       if (g_backup_media_type == dvd && (res || !run_program_and_log_output(tmp, 1)))
    1829             {
    1830           log_to_screen("Failed to write to disk. I shall blank it and then try again.");
    1831           sleep(5);
    1832           system("sync");
    1833               pause_for_N_seconds(5, "Letting DVD drive settle");
     1907            sprintf(tmp,
     1908                    "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
     1909                    MONDO_LOGFILE);
     1910            if (g_backup_media_type == dvd
     1911                && (res || !run_program_and_log_output(tmp, 1))) {
     1912                log_to_screen
     1913                    ("Failed to write to disk. I shall blank it and then try again.");
     1914                sleep(5);
     1915                system("sync");
     1916                pause_for_N_seconds(5, "Letting DVD drive settle");
    18341917
    18351918// dvd+rw-format --- OPTION 2
    1836           if (!bkpinfo->please_dont_eject)
    1837         {
    1838           log_to_screen("Ejecting media to clear drive status.");
    1839           eject_device(bkpinfo->media_device);
    1840           inject_device(bkpinfo->media_device);
    1841         }
    1842               pause_for_N_seconds(5, "Letting DVD drive settle");
    1843           sprintf(sz_blank_disk, "dvd+rw-format %s", bkpinfo->media_device);
    1844           log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
    1845               res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    1846           if (res)
    1847             {
    1848           log_to_screen("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
    1849                   pause_for_N_seconds(5, "Letting DVD drive settle... and trying again.");
    1850                   res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    1851                   if (res) { log_to_screen("Format failed a second time."); }
    1852         }
    1853           else { log_to_screen("Format succeeded. Sleeping for 5 seconds to take a breath..."); }
    1854               pause_for_N_seconds(5, "Letting DVD drive settle");
    1855           if (!bkpinfo->please_dont_eject)
    1856         {
    1857           log_to_screen("Ejecting media to clear drive status.");
    1858           eject_device(bkpinfo->media_device);
    1859           inject_device(bkpinfo->media_device);
    1860         }
    1861               pause_for_N_seconds(5, "Letting DVD drive settle");
    1862           res = eval_call_to_make_ISO (bkpinfo, bkpinfo->call_make_iso, bkpinfo->scratchdir,
    1863            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1864           retval += res;
    1865           if (!bkpinfo->please_dont_eject)
    1866         {
    1867           log_to_screen("Ejecting media.");
    1868           eject_device(bkpinfo->media_device);
    1869         }
    1870           if (res)
    1871             { log_to_screen("Dagnabbit. It still failed."); }
    1872           else
    1873             { log_to_screen("OK, this time I successfully backed up to DVD."); }
    1874         }
     1919                if (!bkpinfo->please_dont_eject) {
     1920                    log_to_screen("Ejecting media to clear drive status.");
     1921                    eject_device(bkpinfo->media_device);
     1922                    inject_device(bkpinfo->media_device);
     1923                }
     1924                pause_for_N_seconds(5, "Letting DVD drive settle");
     1925                sprintf(sz_blank_disk, "dvd+rw-format %s",
     1926                        bkpinfo->media_device);
     1927                log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
     1928                res =
     1929                    run_external_binary_with_percentage_indicator_NEW
     1930                    ("Blanking DVD disk", sz_blank_disk);
     1931                if (res) {
     1932                    log_to_screen
     1933                        ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
     1934                    pause_for_N_seconds(5,
     1935                                        "Letting DVD drive settle... and trying again.");
     1936                    res =
     1937                        run_external_binary_with_percentage_indicator_NEW
     1938                        ("Blanking DVD disk", sz_blank_disk);
     1939                    if (res) {
     1940                        log_to_screen("Format failed a second time.");
     1941                    }
     1942                } else {
     1943                    log_to_screen
     1944                        ("Format succeeded. Sleeping for 5 seconds to take a breath...");
     1945                }
     1946                pause_for_N_seconds(5, "Letting DVD drive settle");
     1947                if (!bkpinfo->please_dont_eject) {
     1948                    log_to_screen("Ejecting media to clear drive status.");
     1949                    eject_device(bkpinfo->media_device);
     1950                    inject_device(bkpinfo->media_device);
     1951                }
     1952                pause_for_N_seconds(5, "Letting DVD drive settle");
     1953                res =
     1954                    eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
     1955                                          bkpinfo->scratchdir,
     1956                                          g_current_media_number,
     1957                                          MONDO_LOGFILE,
     1958                                          message_to_screen);
     1959                retval += res;
     1960                if (!bkpinfo->please_dont_eject) {
     1961                    log_to_screen("Ejecting media.");
     1962                    eject_device(bkpinfo->media_device);
     1963                }
     1964                if (res) {
     1965                    log_to_screen("Dagnabbit. It still failed.");
     1966                } else {
     1967                    log_to_screen
     1968                        ("OK, this time I successfully backed up to DVD.");
     1969                }
     1970            }
    18751971#endif
    1876       if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject)
    1877         { eject_device(bkpinfo->media_device); }
    1878      }
    1879     }
    1880   else
    1881     {
    1882       sprintf (message_to_screen, "Running mkisofs to make %s #%d",
    1883            media_descriptor_string(bkpinfo->backup_media_type),
    1884            g_current_media_number);
    1885       log_msg (1, message_to_screen);
    1886       sprintf (result_sz, "Call to mkisofs to make ISO (%s #%d) ",
    1887             media_descriptor_string(bkpinfo->backup_media_type),
    1888             g_current_media_number);
    1889       if (bkpinfo->nonbootable_backup)
    1890         {
    1891           log_msg (1, "Making nonbootable backup");
     1972            if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
     1973                eject_device(bkpinfo->media_device);
     1974            }
     1975        }
     1976    } else {
     1977        sprintf(message_to_screen, "Running mkisofs to make %s #%d",
     1978                media_descriptor_string(bkpinfo->backup_media_type),
     1979                g_current_media_number);
     1980        log_msg(1, message_to_screen);
     1981        sprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ",
     1982                media_descriptor_string(bkpinfo->backup_media_type),
     1983                g_current_media_number);
     1984        if (bkpinfo->nonbootable_backup) {
     1985            log_msg(1, "Making nonbootable backup");
    18921986// FIXME --- change mkisofs string to MONDO_MKISOFS_NONBOOTABLE and add ' .' at end
    1893           res =
    1894         eval_call_to_make_ISO (bkpinfo,
    1895            "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1896            destfile, g_current_media_number, MONDO_LOGFILE,
    1897            message_to_screen);
    1898         }
    1899       else
    1900         {
    1901           log_msg (1, "Making bootable backup");
     1987            res =
     1988                eval_call_to_make_ISO(bkpinfo,
     1989                                      "mkisofs -o _ISO_ -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     1990                                      destfile, g_current_media_number,
     1991                                      MONDO_LOGFILE, message_to_screen);
     1992        } else {
     1993            log_msg(1, "Making bootable backup");
    19021994
    19031995#ifdef __FreeBSD__
    1904           bkpinfo->make_cd_use_lilo = TRUE;
     1996            bkpinfo->make_cd_use_lilo = TRUE;
    19051997#endif
    19061998
    19071999
    1908           log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo);
    1909           if (bkpinfo->make_cd_use_lilo)
    1910             {
    1911               log_msg(1, "make_cd_use_lilo = TRUE");
     2000            log_msg(1, "make_cd_use_lilo is actually %d",
     2001                    bkpinfo->make_cd_use_lilo);
     2002            if (bkpinfo->make_cd_use_lilo) {
     2003                log_msg(1, "make_cd_use_lilo = TRUE");
    19122004// FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
    19132005// and add ' .' at end
    19142006#ifdef __IA64__
    1915               log_msg(1, "IA64 --> elilo");
    1916               res =
    1917                 eval_call_to_make_ISO (bkpinfo,
    1918                     //-b images/mindi-boot.2880.img
    1919             "mkisofs -no-emul-boot -b images/mindi-bootroot."IA64_BOOT_SIZE".img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1920                     destfile, g_current_media_number, MONDO_LOGFILE,
    1921                     message_to_screen);
     2007                log_msg(1, "IA64 --> elilo");
     2008                res = eval_call_to_make_ISO(bkpinfo,
     2009                                            //-b images/mindi-boot.2880.img
     2010                                            "mkisofs -no-emul-boot -b images/mindi-bootroot."
     2011                                            IA64_BOOT_SIZE
     2012                                            ".img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2013                                            destfile,
     2014                                            g_current_media_number,
     2015                                            MONDO_LOGFILE,
     2016                                            message_to_screen);
    19222017#else
    19232018// FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
    19242019// and add ' .' at end
    1925           log_msg(1, "Non-ia64 --> lilo");
    1926               res =
    1927                 eval_call_to_make_ISO (bkpinfo,
    1928                     "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1929                     destfile, g_current_media_number, MONDO_LOGFILE,
    1930                     message_to_screen);
     2020                log_msg(1, "Non-ia64 --> lilo");
     2021                res =
     2022                    eval_call_to_make_ISO(bkpinfo,
     2023                                          "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2024                                          destfile, g_current_media_number,
     2025                                          MONDO_LOGFILE,
     2026                                          message_to_screen);
    19312027#endif
    1932             }
    1933           else
    1934             {
    1935               log_msg(1, "make_cd_use_lilo = FALSE");
    1936           log_msg(1, "Isolinux");
    1937               res =
    1938             eval_call_to_make_ISO (bkpinfo,
    1939                    "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
    1940            destfile, g_current_media_number, MONDO_LOGFILE,
    1941            message_to_screen);
    1942             }
    1943         }
    1944       if (res)
    1945     {
    1946       strcat (result_sz, "...failed");
    1947     }
    1948       else
    1949     {
    1950       strcat (result_sz, "...OK");
    1951     }
    1952       log_to_screen (result_sz);
    1953       retval += res;
    1954     }
    1955 
    1956   if (bkpinfo->backup_media_type == cdr || bkpinfo->backup_media_type == cdrw)
    1957     {
    1958       if (is_this_device_mounted(bkpinfo->media_device))
    1959         {
    1960           log_msg (2, "Warning - %s mounted. I'm unmounting it before I burn to it.", bkpinfo->media_device);
    1961           sprintf(tmp, "umount %s", bkpinfo->media_device);
    1962           run_program_and_log_output(tmp, FALSE);
    1963         }
    1964     }
    1965 
    1966   if (bkpinfo->call_burn_iso[0] != '\0')
    1967     {
    1968       log_msg (2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
    1969       sprintf (message_to_screen, "Burning %s #%d",
    1970             media_descriptor_string(bkpinfo->backup_media_type),
    1971            g_current_media_number);
    1972       pause_and_ask_for_cdr (2, &cd_is_mountable);
    1973       res =
    1974     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_burn_iso, destfile,
    1975            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1976       if (res)
    1977     {
    1978       strcat (message_to_screen, "...failed");
    1979     }
    1980       else
    1981     {
    1982       strcat (message_to_screen, "...OK");
    1983     }
    1984       log_to_screen (message_to_screen);
    1985       retval += res;
    1986     }
    1987 
    1988   if (bkpinfo->call_after_iso[0] != '\0')
    1989     {
    1990       sprintf (message_to_screen, "Running post-ISO call (%s #%d)",
    1991             media_descriptor_string(bkpinfo->backup_media_type),
    1992            g_current_media_number);
    1993       res =
    1994     eval_call_to_make_ISO (bkpinfo, bkpinfo->call_after_iso, destfile,
    1995            g_current_media_number, MONDO_LOGFILE, message_to_screen);
    1996       if (res)
    1997     {
    1998       strcat (message_to_screen, "...failed");
    1999     }
    2000       else
    2001     {
    2002       strcat (message_to_screen, "...OK");
    2003     }
    2004       log_to_screen (message_to_screen);
    2005       retval += res;
    2006     }
    2007 
    2008   chdir (old_pwd);
    2009   if (retval)
    2010     {
    2011       log_msg (1, "WARNING - make_iso_fs returned an error");
    2012     }
    2013   paranoid_free(old_pwd);
    2014   paranoid_free(result_sz);
    2015   paranoid_free(message_to_screen);
    2016   paranoid_free(sz_blank_disk);
    2017   paranoid_free(fnam);
    2018   paranoid_free(tmp);
    2019   return (retval);
     2028            } else {
     2029                log_msg(1, "make_cd_use_lilo = FALSE");
     2030                log_msg(1, "Isolinux");
     2031                res =
     2032                    eval_call_to_make_ISO(bkpinfo,
     2033                                          "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
     2034                                          destfile, g_current_media_number,
     2035                                          MONDO_LOGFILE,
     2036                                          message_to_screen);
     2037            }
     2038        }
     2039        if (res) {
     2040            strcat(result_sz, "...failed");
     2041        } else {
     2042            strcat(result_sz, "...OK");
     2043        }
     2044        log_to_screen(result_sz);
     2045        retval += res;
     2046    }
     2047
     2048    if (bkpinfo->backup_media_type == cdr
     2049        || bkpinfo->backup_media_type == cdrw) {
     2050        if (is_this_device_mounted(bkpinfo->media_device)) {
     2051            log_msg(2,
     2052                    "Warning - %s mounted. I'm unmounting it before I burn to it.",
     2053                    bkpinfo->media_device);
     2054            sprintf(tmp, "umount %s", bkpinfo->media_device);
     2055            run_program_and_log_output(tmp, FALSE);
     2056        }
     2057    }
     2058
     2059    if (bkpinfo->call_burn_iso[0] != '\0') {
     2060        log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
     2061        sprintf(message_to_screen, "Burning %s #%d",
     2062                media_descriptor_string(bkpinfo->backup_media_type),
     2063                g_current_media_number);
     2064        pause_and_ask_for_cdr(2, &cd_is_mountable);
     2065        res =
     2066            eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
     2067                                  destfile, g_current_media_number,
     2068                                  MONDO_LOGFILE, message_to_screen);
     2069        if (res) {
     2070            strcat(message_to_screen, "...failed");
     2071        } else {
     2072            strcat(message_to_screen, "...OK");
     2073        }
     2074        log_to_screen(message_to_screen);
     2075        retval += res;
     2076    }
     2077
     2078    if (bkpinfo->call_after_iso[0] != '\0') {
     2079        sprintf(message_to_screen, "Running post-ISO call (%s #%d)",
     2080                media_descriptor_string(bkpinfo->backup_media_type),
     2081                g_current_media_number);
     2082        res =
     2083            eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
     2084                                  destfile, g_current_media_number,
     2085                                  MONDO_LOGFILE, message_to_screen);
     2086        if (res) {
     2087            strcat(message_to_screen, "...failed");
     2088        } else {
     2089            strcat(message_to_screen, "...OK");
     2090        }
     2091        log_to_screen(message_to_screen);
     2092        retval += res;
     2093    }
     2094
     2095    chdir(old_pwd);
     2096    if (retval) {
     2097        log_msg(1, "WARNING - make_iso_fs returned an error");
     2098    }
     2099    paranoid_free(old_pwd);
     2100    paranoid_free(result_sz);
     2101    paranoid_free(message_to_screen);
     2102    paranoid_free(sz_blank_disk);
     2103    paranoid_free(fnam);
     2104    paranoid_free(tmp);
     2105    return (retval);
    20202106}
    20212107
     
    20302116bool is_dev_an_NTFS_dev(char *bigfile_fname)
    20312117{
    2032   char *tmp;
    2033   char *command;
    2034   malloc_string(tmp);
    2035   malloc_string(command);
    2036   sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1", bigfile_fname);
    2037   log_msg(1, "command = '%s'", command);
    2038   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2039   log_msg(1, "--> tmp = '%s'", tmp);
    2040   if (strstr(tmp, "NTFS"))
    2041     { iamhere("TRUE"); return(TRUE); }
    2042   else
    2043     { iamhere("FALSE"); return(FALSE); }
     2118    char *tmp;
     2119    char *command;
     2120    malloc_string(tmp);
     2121    malloc_string(command);
     2122    sprintf(command,
     2123            "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
     2124            bigfile_fname);
     2125    log_msg(1, "command = '%s'", command);
     2126    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2127    log_msg(1, "--> tmp = '%s'", tmp);
     2128    if (strstr(tmp, "NTFS")) {
     2129        iamhere("TRUE");
     2130        return (TRUE);
     2131    } else {
     2132        iamhere("FALSE");
     2133        return (FALSE);
     2134    }
    20442135}
    20452136
     
    20602151 */
    20612152int
    2062 make_slices_and_images (struct s_bkpinfo *bkpinfo, char *biggielist_fname)
     2153make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
    20632154{
    20642155
    2065     /*@ pointers ********************************************/
    2066   FILE *fin;
    2067   char *p;
    2068 
    2069     /*@ buffers *********************************************/
    2070   char *tmp;
    2071   char *bigfile_fname;
    2072   char *sz_devfile;
    2073   char *partimagehack_fifo = NULL;
    2074     /*@ long ************************************************/
    2075   long biggie_file_number = 0;
    2076   long noof_biggie_files = 0;
    2077   long estimated_total_noof_slices = 0;
    2078 
    2079     /*@ int *************************************************/
    2080   int retval = 0;
    2081   int res = 0;
    2082   pid_t pid;
    2083   FILE*ftmp=NULL;
    2084   bool delete_when_done; 
    2085   bool use_partimagehack;
    2086     /*@ long long *******************************************/
    2087   long long biggie_fsize;
    2088 
    2089   assert(bkpinfo!=NULL);
    2090   assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
    2091 
    2092   malloc_string(tmp);
    2093   malloc_string(bigfile_fname);
    2094   malloc_string(sz_devfile);
    2095   estimated_total_noof_slices =
    2096     size_of_all_biggiefiles_K (bkpinfo) / bkpinfo->optimal_set_size + 1;
    2097 
    2098   log_msg (1, "size of all biggiefiles = %ld",
    2099        size_of_all_biggiefiles_K (bkpinfo));
    2100   log_msg (1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
    2101        size_of_all_biggiefiles_K (bkpinfo), bkpinfo->optimal_set_size,
    2102        estimated_total_noof_slices);
    2103 
    2104   if (length_of_file (biggielist_fname) < 6)
    2105     {
    2106       log_msg (1, "No biggiefiles; fair enough...");
    2107       return (0);
    2108     }
    2109   sprintf (tmp, "I am now backing up all large files.");
    2110   log_to_screen (tmp);
    2111   noof_biggie_files = count_lines_in_file (biggielist_fname);
    2112   open_progress_form ("Backing up big files", tmp,
    2113               "Please wait. This may take some time.", "",
    2114               estimated_total_noof_slices);
    2115   if (!(fin = fopen (biggielist_fname, "r"))) { log_OS_error("Unable to openin biggielist"); return(1); }
    2116   for (fgets (bigfile_fname, MAX_STR_LEN, fin); !feof (fin);
    2117        fgets (bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++)
    2118     {
    2119       use_partimagehack = FALSE;
    2120       if (bigfile_fname[strlen (bigfile_fname) - 1] < 32)
    2121     {
    2122       bigfile_fname[strlen (bigfile_fname) - 1] = '\0';
    2123     }
    2124       biggie_fsize = length_of_file (bigfile_fname);
    2125       delete_when_done = FALSE;
    2126      
    2127       if (!does_file_exist (bigfile_fname))
    2128     {
    2129           ftmp = fopen(bigfile_fname, "w");
    2130       paranoid_fclose(ftmp);
    2131       sprintf (tmp, "bigfile %s was deleted - creating a dummy", bigfile_fname);
    2132       delete_when_done = TRUE;
    2133     }
    2134       else
    2135         {
     2156    /*@ pointers ******************************************* */
     2157    FILE *fin;
     2158    char *p;
     2159
     2160    /*@ buffers ******************************************** */
     2161    char *tmp;
     2162    char *bigfile_fname;
     2163    char *sz_devfile;
     2164    char *partimagehack_fifo = NULL;
     2165    /*@ long *********************************************** */
     2166    long biggie_file_number = 0;
     2167    long noof_biggie_files = 0;
     2168    long estimated_total_noof_slices = 0;
     2169
     2170    /*@ int ************************************************ */
     2171    int retval = 0;
     2172    int res = 0;
     2173    pid_t pid;
     2174    FILE *ftmp = NULL;
     2175    bool delete_when_done;
     2176    bool use_partimagehack;
     2177    /*@ long long ****************************************** */
     2178    long long biggie_fsize;
     2179
     2180    assert(bkpinfo != NULL);
     2181    assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
     2182
     2183    malloc_string(tmp);
     2184    malloc_string(bigfile_fname);
     2185    malloc_string(sz_devfile);
     2186    estimated_total_noof_slices =
     2187        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
     2188
     2189    log_msg(1, "size of all biggiefiles = %ld",
     2190            size_of_all_biggiefiles_K(bkpinfo));
     2191    log_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
     2192            size_of_all_biggiefiles_K(bkpinfo), bkpinfo->optimal_set_size,
     2193            estimated_total_noof_slices);
     2194
     2195    if (length_of_file(biggielist_fname) < 6) {
     2196        log_msg(1, "No biggiefiles; fair enough...");
     2197        return (0);
     2198    }
     2199    sprintf(tmp, "I am now backing up all large files.");
     2200    log_to_screen(tmp);
     2201    noof_biggie_files = count_lines_in_file(biggielist_fname);
     2202    open_progress_form("Backing up big files", tmp,
     2203                       "Please wait. This may take some time.", "",
     2204                       estimated_total_noof_slices);
     2205    if (!(fin = fopen(biggielist_fname, "r"))) {
     2206        log_OS_error("Unable to openin biggielist");
     2207        return (1);
     2208    }
     2209    for (fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin);
     2210         fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
     2211        use_partimagehack = FALSE;
     2212        if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
     2213            bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
     2214        }
     2215        biggie_fsize = length_of_file(bigfile_fname);
     2216        delete_when_done = FALSE;
     2217
     2218        if (!does_file_exist(bigfile_fname)) {
     2219            ftmp = fopen(bigfile_fname, "w");
     2220            paranoid_fclose(ftmp);
     2221            sprintf(tmp, "bigfile %s was deleted - creating a dummy",
     2222                    bigfile_fname);
     2223            delete_when_done = TRUE;
     2224        } else {
    21362225// Call partimagehack if it's a /dev entry (i.e. a partition to be imaged)
    2137           log_msg (2, "bigfile_fname = %s", bigfile_fname);
    2138       use_partimagehack = FALSE;
    2139       if (!strncmp ( bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname))
    2140             {
    2141           use_partimagehack = TRUE;
    2142           log_msg (2, "Calling partimagehack in background because %s is an NTFS partition", bigfile_fname);
    2143               sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    2144           mkfifo(sz_devfile, 0x770);
    2145           partimagehack_fifo = sz_devfile;
    2146               switch(pid=fork())
    2147                 {
    2148                   case -1: fatal_error("Fork failure");
    2149               case 0:
    2150             log_msg (2, "CHILD - fip - calling feed_into_partimage(%s, %s)", bigfile_fname, sz_devfile);
    2151             res=feed_into_partimage(bigfile_fname, sz_devfile);
    2152             exit(res);
    2153             break;
    2154                   default:
    2155             log_msg (2, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    2156                 }
    2157         }
     2226            log_msg(2, "bigfile_fname = %s", bigfile_fname);
     2227            use_partimagehack = FALSE;
     2228            if (!strncmp(bigfile_fname, "/dev/", 5)
     2229                && is_dev_an_NTFS_dev(bigfile_fname)) {
     2230                use_partimagehack = TRUE;
     2231                log_msg(2,
     2232                        "Calling partimagehack in background because %s is an NTFS partition",
     2233                        bigfile_fname);
     2234                sprintf(sz_devfile, "/tmp/%d.%d.000",
     2235                        (int) (random() % 32768),
     2236                        (int) (random() % 32768));
     2237                mkfifo(sz_devfile, 0x770);
     2238                partimagehack_fifo = sz_devfile;
     2239                switch (pid = fork()) {
     2240                case -1:
     2241                    fatal_error("Fork failure");
     2242                case 0:
     2243                    log_msg(2,
     2244                            "CHILD - fip - calling feed_into_partimage(%s, %s)",
     2245                            bigfile_fname, sz_devfile);
     2246                    res = feed_into_partimage(bigfile_fname, sz_devfile);
     2247                    exit(res);
     2248                    break;
     2249                default:
     2250                    log_msg(2,
     2251                            "feed_into_partimage() called in background --- pid=%ld",
     2252                            (long int) (pid));
     2253                }
     2254            }
    21582255// Otherwise, use good old 'dd' and 'bzip2'
    2159           else
    2160         {
    2161           sz_devfile[0] = '\0';
    2162           partimagehack_fifo = NULL;
    2163         }
     2256            else {
     2257                sz_devfile[0] = '\0';
     2258                partimagehack_fifo = NULL;
     2259            }
    21642260
    21652261// Whether partition or biggiefile, just do your thang :-)
    2166       sprintf (tmp, "Bigfile #%ld is '%s' (%ld KB)", biggie_file_number+1,
    2167            bigfile_fname, (long) biggie_fsize >> 10);
    2168           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2169         {
    2170           write_header_block_to_stream (biggie_fsize, bigfile_fname,
    2171                       use_partimagehack?BLK_START_A_PIHBIGGIE:BLK_START_A_NORMBIGGIE);
    2172         }
    2173       res =
    2174         slice_up_file_etc (bkpinfo, bigfile_fname, partimagehack_fifo,
    2175             biggie_file_number, noof_biggie_files, use_partimagehack);
    2176           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2177         {
    2178           write_header_block_to_stream (0,
    2179                       calc_checksum_of_file
    2180                       (bigfile_fname), BLK_STOP_A_BIGGIE);
    2181         }
    2182       retval += res;
    2183       p = strrchr (bigfile_fname, '/');
    2184       if (p)
    2185         {
    2186           p++;
    2187         }
    2188       else
    2189         {
    2190           p = bigfile_fname;
    2191         }
    2192       sprintf (tmp, "Archiving %s ... ", bigfile_fname);
    2193       if (res)
    2194         {
    2195           strcat (tmp, "Failed!");
    2196         }
    2197       else
    2198         {
    2199           strcat (tmp, "OK");
    2200         }
    2201       if (delete_when_done)
    2202         { unlink(bigfile_fname); delete_when_done=FALSE; }
    2203     }
     2262            sprintf(tmp, "Bigfile #%ld is '%s' (%ld KB)",
     2263                    biggie_file_number + 1, bigfile_fname,
     2264                    (long) biggie_fsize >> 10);
     2265            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2266                write_header_block_to_stream(biggie_fsize, bigfile_fname,
     2267                                             use_partimagehack ?
     2268                                             BLK_START_A_PIHBIGGIE :
     2269                                             BLK_START_A_NORMBIGGIE);
     2270            }
     2271            res =
     2272                slice_up_file_etc(bkpinfo, bigfile_fname,
     2273                                  partimagehack_fifo, biggie_file_number,
     2274                                  noof_biggie_files, use_partimagehack);
     2275            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2276                write_header_block_to_stream(0,
     2277                                             calc_checksum_of_file
     2278                                             (bigfile_fname),
     2279                                             BLK_STOP_A_BIGGIE);
     2280            }
     2281            retval += res;
     2282            p = strrchr(bigfile_fname, '/');
     2283            if (p) {
     2284                p++;
     2285            } else {
     2286                p = bigfile_fname;
     2287            }
     2288            sprintf(tmp, "Archiving %s ... ", bigfile_fname);
     2289            if (res) {
     2290                strcat(tmp, "Failed!");
     2291            } else {
     2292                strcat(tmp, "OK");
     2293            }
     2294            if (delete_when_done) {
     2295                unlink(bigfile_fname);
     2296                delete_when_done = FALSE;
     2297            }
     2298        }
    22042299#ifndef _XWIN
    2205       if (!g_text_mode) { newtDrawRootText (0, g_noof_rows - 2, tmp); newtRefresh (); }
     2300        if (!g_text_mode) {
     2301            newtDrawRootText(0, g_noof_rows - 2, tmp);
     2302            newtRefresh();
     2303        }
    22062304#endif
    2207     }
    2208   log_msg (1, "Finished backing up bigfiles");
    2209   log_msg (1, "estimated slices = %ld; actual slices = %ld",
    2210        estimated_total_noof_slices, g_current_progress);
    2211   close_progress_form ();
    2212   paranoid_fclose(fin);
    2213   paranoid_free(tmp);
    2214   paranoid_free(bigfile_fname);
    2215   paranoid_free(sz_devfile);
    2216   return (retval);
     2305    }
     2306    log_msg(1, "Finished backing up bigfiles");
     2307    log_msg(1, "estimated slices = %ld; actual slices = %ld",
     2308            estimated_total_noof_slices, g_current_progress);
     2309    close_progress_form();
     2310    paranoid_fclose(fin);
     2311    paranoid_free(tmp);
     2312    paranoid_free(bigfile_fname);
     2313    paranoid_free(sz_devfile);
     2314    return (retval);
    22172315}
    22182316
     
    22242322 * @see make_afioballs_and_images
    22252323 */
    2226 int
    2227 make_afioballs_and_images_OLD (struct s_bkpinfo *bkpinfo)
     2324int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
    22282325{
    22292326
    2230     /*@ int ***************************************************/
    2231   int retval = 0;
    2232   long int curr_set_no = 0;
    2233   int res = 0;
    2234  
    2235     /*@ buffers ***********************************************/
    2236   char *curr_filelist_fname;
    2237   char *curr_afioball_fname;
    2238   char *curr_xattr_list_fname;
    2239   char *curr_acl_list_fname;
    2240   char *tmp;
    2241   char *media_usage_comment;
    2242  
    2243   malloc_string(curr_afioball_fname);
    2244   malloc_string(media_usage_comment);
    2245   malloc_string(curr_filelist_fname);
    2246   malloc_string(curr_xattr_list_fname);
    2247   malloc_string(curr_acl_list_fname);
    2248  
    2249   tmp = malloc(MAX_STR_LEN*2);
    2250  
    2251   sprintf (tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    2252 
    2253   log_to_screen ("Archiving regular files");
    2254 
    2255   open_progress_form ("Backing up filesystem",
    2256               "I am backing up your live filesystem now.",
    2257               "Please wait. This may take a couple of hours.",
    2258               "Working...", get_last_filelist_number (bkpinfo) + 1);
    2259 
    2260   sprintf (curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
    2261 
    2262   for (curr_set_no = 0; does_file_exist (curr_filelist_fname);
    2263        sprintf (curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
    2264         ++curr_set_no))
    2265     {
    2266       /* backup this set of files */
    2267       sprintf (curr_filelist_fname,  FILELIST_FNAME_RAW_SZ,  bkpinfo->tmpdir, curr_set_no);
    2268       sprintf (curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,bkpinfo->tmpdir,
    2269                curr_set_no, bkpinfo->zip_suffix);
    2270      
    2271       log_msg (1, "EXAT'g set %ld", curr_set_no);
    2272       sprintf (curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, curr_set_no);
    2273       sprintf (curr_acl_list_fname,   ACL_LIST_FNAME_RAW_SZ,   bkpinfo->tmpdir, curr_set_no);
    2274       get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
    2275       get_acl_list(curr_filelist_fname, curr_acl_list_fname);
    2276      
    2277       log_msg (1, "Archiving set %ld", curr_set_no);
    2278       res =
    2279     archive_this_fileset (bkpinfo, curr_filelist_fname, curr_afioball_fname, curr_set_no);
    2280       retval += res;
    2281       if (res)
    2282     {
    2283       sprintf (tmp,
    2284            "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
    2285            curr_set_no);
    2286       log_to_screen (tmp);
    2287     }
    2288 
    2289       strcpy (media_usage_comment, percent_media_full_comment (bkpinfo));
    2290 
    2291       /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    2292       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2293         {
    2294               register_in_tape_catalog(fileset, curr_set_no, -1, curr_afioball_fname);
    2295               maintain_collection_of_recent_archives(bkpinfo->tmpdir, curr_afioball_fname);
    2296           iamhere("Writing EXAT files");
    2297               res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname, curr_acl_list_fname);
     2327    /*@ int ************************************************** */
     2328    int retval = 0;
     2329    long int curr_set_no = 0;
     2330    int res = 0;
     2331
     2332    /*@ buffers ********************************************** */
     2333    char *curr_filelist_fname;
     2334    char *curr_afioball_fname;
     2335    char *curr_xattr_list_fname;
     2336    char *curr_acl_list_fname;
     2337    char *tmp;
     2338    char *media_usage_comment;
     2339
     2340    malloc_string(curr_afioball_fname);
     2341    malloc_string(media_usage_comment);
     2342    malloc_string(curr_filelist_fname);
     2343    malloc_string(curr_xattr_list_fname);
     2344    malloc_string(curr_acl_list_fname);
     2345
     2346    tmp = malloc(MAX_STR_LEN * 2);
     2347
     2348    sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
     2349
     2350    log_to_screen("Archiving regular files");
     2351
     2352    open_progress_form("Backing up filesystem",
     2353                       "I am backing up your live filesystem now.",
     2354                       "Please wait. This may take a couple of hours.",
     2355                       "Working...",
     2356                       get_last_filelist_number(bkpinfo) + 1);
     2357
     2358    sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
     2359            0L);
     2360
     2361    for (curr_set_no = 0; does_file_exist(curr_filelist_fname);
     2362         sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
     2363                 bkpinfo->tmpdir, ++curr_set_no)) {
     2364        /* backup this set of files */
     2365        sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
     2366                bkpinfo->tmpdir, curr_set_no);
     2367        sprintf(curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
     2368                bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
     2369
     2370        log_msg(1, "EXAT'g set %ld", curr_set_no);
     2371        sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     2372                bkpinfo->tmpdir, curr_set_no);
     2373        sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     2374                bkpinfo->tmpdir, curr_set_no);
     2375        get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
     2376        get_acl_list(curr_filelist_fname, curr_acl_list_fname);
     2377
     2378        log_msg(1, "Archiving set %ld", curr_set_no);
     2379        res =
     2380            archive_this_fileset(bkpinfo, curr_filelist_fname,
     2381                                 curr_afioball_fname, curr_set_no);
     2382        retval += res;
     2383        if (res) {
     2384            sprintf(tmp,
     2385                    "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
     2386                    curr_set_no);
     2387            log_to_screen(tmp);
     2388        }
     2389
     2390        strcpy(media_usage_comment, percent_media_full_comment(bkpinfo));
     2391
     2392        /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     2393        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2394            register_in_tape_catalog(fileset, curr_set_no, -1,
     2395                                     curr_afioball_fname);
     2396            maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     2397                                                   curr_afioball_fname);
     2398            iamhere("Writing EXAT files");
     2399            res +=
     2400                write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
     2401                                         curr_acl_list_fname);
    22982402// archives themselves
    2299               res = move_files_to_stream (bkpinfo, curr_afioball_fname, NULL);
    2300         }
    2301       else
    2302         {
    2303           res = move_files_to_cd (bkpinfo, curr_filelist_fname, curr_xattr_list_fname, curr_acl_list_fname, curr_afioball_fname, NULL);
    2304         }
    2305       retval += res;
    2306       g_current_progress++;
    2307       update_progress_form (media_usage_comment);
    2308 
    2309       if (res)
    2310     {
    2311       sprintf (tmp, "Failed to add archive %ld's files to CD dir\n",
    2312            curr_set_no);
    2313       log_to_screen (tmp);
    2314       fatal_error
    2315         ("Is your hard disk is full? If not, please send the author the logfile.");
    2316     }
    2317     }
    2318   close_progress_form ();
    2319   sprintf (tmp, "Your regular files have been archived ");
    2320   if (retval)
    2321     {
    2322       strcat (tmp, "(with errors).");
    2323     }
    2324   else
    2325     {
    2326       strcat (tmp, "successfully.");
    2327     }
    2328   log_to_screen (tmp);
    2329   paranoid_free(tmp);
    2330   paranoid_free(curr_filelist_fname);
    2331   paranoid_free(curr_afioball_fname);
    2332   paranoid_free(media_usage_comment);
    2333   paranoid_free(curr_xattr_list_fname);
    2334   paranoid_free(curr_acl_list_fname);
    2335   return (retval);
     2403            res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
     2404        } else {
     2405            res =
     2406                move_files_to_cd(bkpinfo, curr_filelist_fname,
     2407                                 curr_xattr_list_fname,
     2408                                 curr_acl_list_fname, curr_afioball_fname,
     2409                                 NULL);
     2410        }
     2411        retval += res;
     2412        g_current_progress++;
     2413        update_progress_form(media_usage_comment);
     2414
     2415        if (res) {
     2416            sprintf(tmp, "Failed to add archive %ld's files to CD dir\n",
     2417                    curr_set_no);
     2418            log_to_screen(tmp);
     2419            fatal_error
     2420                ("Is your hard disk is full? If not, please send the author the logfile.");
     2421        }
     2422    }
     2423    close_progress_form();
     2424    sprintf(tmp, "Your regular files have been archived ");
     2425    if (retval) {
     2426        strcat(tmp, "(with errors).");
     2427    } else {
     2428        strcat(tmp, "successfully.");
     2429    }
     2430    log_to_screen(tmp);
     2431    paranoid_free(tmp);
     2432    paranoid_free(curr_filelist_fname);
     2433    paranoid_free(curr_afioball_fname);
     2434    paranoid_free(media_usage_comment);
     2435    paranoid_free(curr_xattr_list_fname);
     2436    paranoid_free(curr_acl_list_fname);
     2437    return (retval);
    23362438}
    23372439
    2338 /* @} - end of LLarchiveGroup */ 
    2339  
    2340  
     2440/* @} - end of LLarchiveGroup */
     2441
     2442
    23412443/**
    23422444 * Wrapper around @c make_afioballs_and_images().
     
    23472449 * @ingroup MLarchiveGroup
    23482450 */
    2349 int
    2350 make_those_afios_phase (struct s_bkpinfo *bkpinfo)
     2451int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
    23512452{
    2352     /*@ int ********************************************/
    2353   int res = 0;
    2354   int retval = 0;
    2355 
    2356   assert(bkpinfo!=NULL);
    2357 
    2358   mvaddstr_and_log_it (g_currentY, 0, "Archiving regular files to media          ");
    2359 
    2360   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2361     {
    2362       write_header_block_to_stream (0, "start-of-afioballs",
    2363                   BLK_START_AFIOBALLS);
     2453    /*@ int ******************************************* */
     2454    int res = 0;
     2455    int retval = 0;
     2456
     2457    assert(bkpinfo != NULL);
     2458
     2459    mvaddstr_and_log_it(g_currentY, 0,
     2460                        "Archiving regular files to media          ");
     2461
     2462    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2463        write_header_block_to_stream(0, "start-of-afioballs",
     2464                                    BLK_START_AFIOBALLS);
    23642465#if __FreeBSD__ == 5
    2365       log_msg (1, "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
    2366       res = make_afioballs_and_images_OLD (bkpinfo);
     2466        log_msg(1,
     2467                "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
     2468        res = make_afioballs_and_images_OLD(bkpinfo);
    23672469#else
    2368       res = make_afioballs_and_images_OLD (bkpinfo);
     2470        res = make_afioballs_and_images_OLD(bkpinfo);
    23692471#endif
    2370       write_header_block_to_stream (0, "stop-afioballs", BLK_STOP_AFIOBALLS);
    2371     }
    2372   else
    2373     {
    2374       res = make_afioballs_and_images (bkpinfo);
    2375     }
    2376 
    2377   retval += res;
    2378   if (res)
    2379     {
    2380       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    2381       log_msg (1, "make_afioballs_and_images returned an error");
    2382     }
    2383   else
    2384     {
    2385       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2386     }
    2387   return (retval);
     2472        write_header_block_to_stream(0, "stop-afioballs",
     2473                                     BLK_STOP_AFIOBALLS);
     2474    } else {
     2475        res = make_afioballs_and_images(bkpinfo);
     2476    }
     2477
     2478    retval += res;
     2479    if (res) {
     2480        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2481        log_msg(1, "make_afioballs_and_images returned an error");
     2482    } else {
     2483        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2484    }
     2485    return (retval);
    23882486}
    23892487
     
    23972495 * @ingroup MLarchiveGroup
    23982496 */
    2399 int
    2400 make_those_slices_phase (struct s_bkpinfo *bkpinfo)
     2497int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
    24012498{
    24022499
    2403     /*@ int ******************************************************/
    2404   int res = 0;
    2405   int retval = 0;
    2406 
    2407     /*@ buffers ***************************************************/
    2408   char *biggielist;
    2409   char *command;
    2410   char *blah;
    2411   char *xattr_fname;
    2412   char *acl_fname;
    2413  
    2414   assert(bkpinfo!=NULL);
    2415   /* slice big files */
    2416   malloc_string(blah);
    2417   malloc_string(biggielist);
    2418   malloc_string(xattr_fname);
    2419   malloc_string(acl_fname);
    2420   command = malloc(1200);
    2421   mvaddstr_and_log_it (g_currentY, 0, "Archiving large files to media           ");
    2422   sprintf (biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
    2423   sprintf (xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2424   sprintf (acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2425  
    2426   sprintf (command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
    2427   paranoid_system(command);
    2428   sprintf (blah, "biggielist = %s", biggielist);
    2429   log_msg (2, blah);
    2430  
    2431   if (!does_file_exist (biggielist))
    2432     {
    2433       log_msg (1, "BTW, the biggielist does not exist");
    2434     }
    2435 
    2436   get_fattr_list(biggielist, xattr_fname);
    2437   get_acl_list(biggielist, acl_fname);
    2438   sprintf (command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
    2439   paranoid_system(command);
    2440   sprintf (command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
    2441   paranoid_system(command);
    2442 
    2443   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2444     {
    2445       res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
    2446       sprintf (blah, "%ld", count_lines_in_file (biggielist));
    2447       write_header_block_to_stream (0, blah, BLK_START_BIGGIEFILES);
    2448     }
    2449   res = make_slices_and_images (bkpinfo, biggielist);
    2450   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2451     {
    2452       write_header_block_to_stream (0, "end-of-biggiefiles",
    2453                   BLK_STOP_BIGGIEFILES);
    2454     }
    2455   retval += res;
    2456   if (res)
    2457     {
    2458       log_msg (1, "make_slices_and_images returned an error");
    2459       mvaddstr_and_log_it (g_currentY++, 74, "Errors.");
    2460     }
    2461   else
    2462     {
    2463       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2464     }
    2465   paranoid_free(blah);
    2466   paranoid_free(biggielist);
    2467   paranoid_free(command);
    2468   paranoid_free(xattr_fname);
    2469   paranoid_free(acl_fname);
    2470   return (retval);
     2500    /*@ int ***************************************************** */
     2501    int res = 0;
     2502    int retval = 0;
     2503
     2504    /*@ buffers ************************************************** */
     2505    char *biggielist;
     2506    char *command;
     2507    char *blah;
     2508    char *xattr_fname;
     2509    char *acl_fname;
     2510
     2511    assert(bkpinfo != NULL);
     2512    /* slice big files */
     2513    malloc_string(blah);
     2514    malloc_string(biggielist);
     2515    malloc_string(xattr_fname);
     2516    malloc_string(acl_fname);
     2517    command = malloc(1200);
     2518    mvaddstr_and_log_it(g_currentY, 0,
     2519                        "Archiving large files to media           ");
     2520    sprintf(biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
     2521    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2522    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2523
     2524    sprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
     2525            biggielist);
     2526    paranoid_system(command);
     2527    sprintf(blah, "biggielist = %s", biggielist);
     2528    log_msg(2, blah);
     2529
     2530    if (!does_file_exist(biggielist)) {
     2531        log_msg(1, "BTW, the biggielist does not exist");
     2532    }
     2533
     2534    get_fattr_list(biggielist, xattr_fname);
     2535    get_acl_list(biggielist, acl_fname);
     2536    sprintf(command, "cp %s %s/archives/", xattr_fname,
     2537            bkpinfo->scratchdir);
     2538    paranoid_system(command);
     2539    sprintf(command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
     2540    paranoid_system(command);
     2541
     2542    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2543        res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
     2544        sprintf(blah, "%ld", count_lines_in_file(biggielist));
     2545        write_header_block_to_stream(0, blah, BLK_START_BIGGIEFILES);
     2546    }
     2547    res = make_slices_and_images(bkpinfo, biggielist);
     2548    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2549        write_header_block_to_stream(0, "end-of-biggiefiles",
     2550                                     BLK_STOP_BIGGIEFILES);
     2551    }
     2552    retval += res;
     2553    if (res) {
     2554        log_msg(1, "make_slices_and_images returned an error");
     2555        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2556    } else {
     2557        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2558    }
     2559    paranoid_free(blah);
     2560    paranoid_free(biggielist);
     2561    paranoid_free(command);
     2562    paranoid_free(xattr_fname);
     2563    paranoid_free(acl_fname);
     2564    return (retval);
    24712565}
    24722566
     
    24822576 * transfer files over the network) or leave it as is.
    24832577 */
    2484 int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) = _move_files_to_cd;
     2578int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
     2579    _move_files_to_cd;
    24852580
    24862581/**
     
    25022597 * @return The number of errors encountered (0 for success)
    25032598 */
    2504 int
    2505 _move_files_to_cd (struct s_bkpinfo *bkpinfo,
    2506          char *files_to_add, ...)
     2599int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    25072600{
    25082601
    2509     /*@ int *************************************************************/
    2510   int retval = 0;
     2602    /*@ int ************************************************************ */
     2603    int retval = 0;
    25112604    int res = 0;
    25122605
    2513     /*@ buffers *********************************************************/
    2514   char *tmp,
    2515        *curr_file, *cf;
    2516 
    2517     /*@ long *************************************************************/
    2518   va_list ap;
    2519   long long would_occupy;
    2520 
    2521   assert(bkpinfo!=NULL);
    2522   malloc_string(curr_file);
    2523   tmp = malloc(1200);
    2524   would_occupy = space_occupied_by_cd (bkpinfo->scratchdir);
    2525   va_start(ap, files_to_add); // initialize the variable arguments
    2526   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2527     {
    2528       if (!cf) {continue;}
    2529       strcpy(curr_file, cf);
    2530       if (!does_file_exist (curr_file))
    2531     {
    2532       log_msg (1, "Warning - you're trying to add a non-existent file - '%s' to the CD", curr_file);
    2533     }
    2534       else
    2535         {
    2536       log_msg (8, "Trying to add file %s to CD", curr_file);
    2537           would_occupy += length_of_file (curr_file) / 1024;
    2538         }
    2539     }
    2540   va_end(ap);
    2541 
    2542   if (bkpinfo->media_size[g_current_media_number]<=0) { fatal_error( "move_files_to_cd() - unknown media size"); }
    2543   if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number])
    2544     {
    2545       res = write_iso_and_go_on (bkpinfo, FALSE);   /* FALSE because this is not the last CD we'll write */
    2546       retval += res;
    2547       if (res)
    2548     {
    2549       log_msg (1, "WARNING - write_iso_and_go_on returned an error");
    2550     }
    2551     }
    2552 
    2553   va_start(ap, files_to_add); // initialize the variable arguments
    2554   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2555     {
    2556       if (!cf) {continue;}
    2557       strcpy(curr_file, cf);
    2558 
    2559       sprintf (tmp, "mv -f %s %s/archives/", curr_file,
    2560            bkpinfo->scratchdir);
    2561       res = run_program_and_log_output (tmp, 5);
    2562       retval += res;
    2563       if (res)
    2564     {
    2565       log_msg (1, "(move_files_to_cd) '%s' failed", tmp);
    2566     }
    2567       else
    2568         {
    2569       log_msg (8, "Moved %s to CD OK", tmp);
    2570     }
    2571       //      unlink (curr_file);
    2572     }
    2573   va_end(ap);
    2574 
    2575   if (retval)
    2576     {
    2577       log_msg (1, "Warning - errors occurred while I was adding files to CD dir");
    2578     }
    2579   paranoid_free(tmp);
    2580   paranoid_free(curr_file);
    2581   return (retval);
     2606    /*@ buffers ******************************************************** */
     2607    char *tmp, *curr_file, *cf;
     2608
     2609    /*@ long ************************************************************ */
     2610    va_list ap;
     2611    long long would_occupy;
     2612
     2613    assert(bkpinfo != NULL);
     2614    malloc_string(curr_file);
     2615    tmp = malloc(1200);
     2616    would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
     2617    va_start(ap, files_to_add); // initialize the variable arguments
     2618    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2619        if (!cf) {
     2620            continue;
     2621        }
     2622        strcpy(curr_file, cf);
     2623        if (!does_file_exist(curr_file)) {
     2624            log_msg(1,
     2625                    "Warning - you're trying to add a non-existent file - '%s' to the CD",
     2626                    curr_file);
     2627        } else {
     2628            log_msg(8, "Trying to add file %s to CD", curr_file);
     2629            would_occupy += length_of_file(curr_file) / 1024;
     2630        }
     2631    }
     2632    va_end(ap);
     2633
     2634    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     2635        fatal_error("move_files_to_cd() - unknown media size");
     2636    }
     2637    if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
     2638        res = write_iso_and_go_on(bkpinfo, FALSE);  /* FALSE because this is not the last CD we'll write */
     2639        retval += res;
     2640        if (res) {
     2641            log_msg(1, "WARNING - write_iso_and_go_on returned an error");
     2642        }
     2643    }
     2644
     2645    va_start(ap, files_to_add); // initialize the variable arguments
     2646    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2647        if (!cf) {
     2648            continue;
     2649        }
     2650        strcpy(curr_file, cf);
     2651
     2652        sprintf(tmp, "mv -f %s %s/archives/", curr_file,
     2653                bkpinfo->scratchdir);
     2654        res = run_program_and_log_output(tmp, 5);
     2655        retval += res;
     2656        if (res) {
     2657            log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
     2658        } else {
     2659            log_msg(8, "Moved %s to CD OK", tmp);
     2660        }
     2661        //      unlink (curr_file);
     2662    }
     2663    va_end(ap);
     2664
     2665    if (retval) {
     2666        log_msg(1,
     2667                "Warning - errors occurred while I was adding files to CD dir");
     2668    }
     2669    paranoid_free(tmp);
     2670    paranoid_free(curr_file);
     2671    return (retval);
    25822672}
    25832673
     
    26032693 * @ingroup MLarchiveGroup
    26042694 */
    2605 int
    2606 offer_to_write_floppies (struct s_bkpinfo *bkpinfo, char *imagesdir)
     2695int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
    26072696{
    2608     /*@ buffer *************************************************************/
    2609   char *tmp;
     2697    /*@ buffer ************************************************************ */
     2698    char *tmp;
    26102699    char *comment;
    26112700    char *bootdisk_dev;
     
    26142703    char *rootdisk_file;
    26152704
    2616     /*@ int ****************************************************************/
    2617   int i = 0;
     2705    /*@ int *************************************************************** */
     2706    int i = 0;
    26182707    int res = 0;
    26192708
    2620     /*@ bool ***************************************************************/
    2621   bool format_first;
    2622   bool root_disk_exists=FALSE;
    2623 
    2624   malloc_string(tmp);
    2625   malloc_string(comment);
    2626   malloc_string(bootdisk_dev);
    2627   malloc_string(datadisk_dev);
    2628   malloc_string(rootdisk_file);
    2629   malloc_string(bootdisk_file);
    2630   assert(bkpinfo!=NULL);
    2631   assert_string_is_neither_NULL_nor_zerolength(imagesdir);
    2632 
    2633 
    2634   if (!ask_me_yes_or_no
    2635       ("Write boot and data disk images to 3.5\" floppy disks?"))
    2636     {
    2637       return (0);
    2638     }
    2639   if (does_device_exist (DEFAULT_1722MB_DISK))
    2640     {
     2709    /*@ bool ************************************************************** */
     2710    bool format_first;
     2711    bool root_disk_exists = FALSE;
     2712
     2713    malloc_string(tmp);
     2714    malloc_string(comment);
     2715    malloc_string(bootdisk_dev);
     2716    malloc_string(datadisk_dev);
     2717    malloc_string(rootdisk_file);
     2718    malloc_string(bootdisk_file);
     2719    assert(bkpinfo != NULL);
     2720    assert_string_is_neither_NULL_nor_zerolength(imagesdir);
     2721
     2722
     2723    if (!ask_me_yes_or_no
     2724        ("Write boot and data disk images to 3.5\" floppy disks?")) {
     2725        return (0);
     2726    }
     2727    if (does_device_exist(DEFAULT_1722MB_DISK)) {
    26412728#ifdef __FreeBSD__
    2642  // tell the system that this is a 1.72m floppy
    2643       system ("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
     2729        // tell the system that this is a 1.72m floppy
     2730        system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
    26442731#endif
    2645       strcpy (bootdisk_dev, DEFAULT_1722MB_DISK);
    2646     }
    2647   else if (does_device_exist (BACKUP_1722MB_DISK))
    2648     {
    2649       sprintf (bootdisk_dev, "/dev/fd0H1722");
    2650     }
    2651   else
    2652     {
    2653       log_msg( 1, "Warning - can't find a 1.72MB floppy device *sigh*" );
    2654       strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
     2732        strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
     2733    } else if (does_device_exist(BACKUP_1722MB_DISK)) {
     2734        sprintf(bootdisk_dev, "/dev/fd0H1722");
     2735    } else {
     2736        log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
     2737        strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
    26552738//      return (1);
    2656     }
    2657   strcpy (datadisk_dev, "/dev/fd0");
    2658   if (!does_device_exist (datadisk_dev))
    2659     {
    2660       log_msg( 1, "Warning - can't find a 1.44MB floppy device *sigh*" );
    2661       strcpy(datadisk_dev, "/dev/fd0");
     2739    }
     2740    strcpy(datadisk_dev, "/dev/fd0");
     2741    if (!does_device_exist(datadisk_dev)) {
     2742        log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
     2743        strcpy(datadisk_dev, "/dev/fd0");
    26622744//      return (1);
    2663     }
    2664   format_first =
    2665     ask_me_yes_or_no
    2666     ("Do you want me to format the disks before I write to them?");
     2745    }
     2746    format_first =
     2747        ask_me_yes_or_no
     2748        ("Do you want me to format the disks before I write to them?");
    26672749
    26682750/* boot disk */
    2669   if (ask_me_OK_or_cancel ("About to write boot disk"))
    2670     {
    2671       log_to_screen ("Writing boot floppy");
     2751    if (ask_me_OK_or_cancel("About to write boot disk")) {
     2752        log_to_screen("Writing boot floppy");
    26722753#ifdef __FreeBSD__
    2673       sprintf (tmp, "%s/mindi-kern.1722.img", imagesdir);
    2674       if (format_first) { format_disk (bootdisk_dev); }
    2675       res += write_image_to_floppy (bootdisk_dev, tmp);
    2676       if (ask_me_OK_or_cancel ("About to write 1.44MB mfsroot disk"))
    2677         {
    2678           log_to_screen ("Writing mfsroot floppy");
    2679           if (format_first) { format_disk (datadisk_dev); }
    2680           sprintf (tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
    2681           write_image_to_floppy (datadisk_dev, tmp);
    2682         }
     2754        sprintf(tmp, "%s/mindi-kern.1722.img", imagesdir);
     2755        if (format_first) {
     2756            format_disk(bootdisk_dev);
     2757        }
     2758        res += write_image_to_floppy(bootdisk_dev, tmp);
     2759        if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
     2760            log_to_screen("Writing mfsroot floppy");
     2761            if (format_first) {
     2762                format_disk(datadisk_dev);
     2763            }
     2764            sprintf(tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
     2765            write_image_to_floppy(datadisk_dev, tmp);
     2766        }
    26832767#else
    2684       sprintf (bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
    2685       if (does_file_exist(bootdisk_file))
    2686         {
    2687           if (format_first) { format_disk (bootdisk_dev); }
    2688       res += write_image_to_floppy (bootdisk_dev, bootdisk_file);
    2689         }
    2690       else
    2691         {
    2692       sprintf (bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
    2693       sprintf (rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
    2694       root_disk_exists = TRUE;
    2695       if (!does_file_exist(rootdisk_file) || !does_file_exist(bootdisk_file))
    2696         {
    2697           popup_and_OK("Cannot write boot/root floppies. Files not found.");
    2698           log_to_screen("Failed to find boot/root floppy images. Oh dear.");
    2699           return(1);
    2700         }
    2701       if (format_first) { format_disk (datadisk_dev); }
    2702         /*
    2703           sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
    2704           res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
    2705         */
    2706       res += write_image_to_floppy (datadisk_dev, bootdisk_file);
    2707       if (ask_me_OK_or_cancel ("About to write root disk"))
    2708         {
    2709           log_to_screen ("Writing root floppy");
    2710           if (format_first) { format_disk (datadisk_dev); }
    2711           sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
    2712           log_msg(1, "tmp = '%s'", tmp);
    2713           res += run_external_binary_with_percentage_indicator_NEW("Writing root floppy", tmp);
     2768        sprintf(bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
     2769        if (does_file_exist(bootdisk_file)) {
     2770            if (format_first) {
     2771                format_disk(bootdisk_dev);
     2772            }
     2773            res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
     2774        } else {
     2775            sprintf(bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
     2776            sprintf(rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
     2777            root_disk_exists = TRUE;
     2778            if (!does_file_exist(rootdisk_file)
     2779                || !does_file_exist(bootdisk_file)) {
     2780                popup_and_OK
     2781                    ("Cannot write boot/root floppies. Files not found.");
     2782                log_to_screen
     2783                    ("Failed to find boot/root floppy images. Oh dear.");
     2784                return (1);
     2785            }
     2786            if (format_first) {
     2787                format_disk(datadisk_dev);
     2788            }
     2789            /*
     2790               sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
     2791               res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
     2792             */
     2793            res += write_image_to_floppy(datadisk_dev, bootdisk_file);
     2794            if (ask_me_OK_or_cancel("About to write root disk")) {
     2795                log_to_screen("Writing root floppy");
     2796                if (format_first) {
     2797                    format_disk(datadisk_dev);
     2798                }
     2799                sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
     2800                log_msg(1, "tmp = '%s'", tmp);
     2801                res +=
     2802                    run_external_binary_with_percentage_indicator_NEW
     2803                    ("Writing root floppy", tmp);
    27142804//              res += write_image_to_floppy (datadisk_dev, rootdisk_file);
    2715         }
    2716         }
     2805            }
     2806        }
    27172807#endif
    2718     }
    2719   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    2720     {
    2721       log_to_screen
    2722     ("FYI, the data disks are stored on tape/CD for your convenience.");
    2723       return (0);
    2724     }
    2725   for (i = 1; i < 99; i++)
    2726     {
    2727       sprintf (tmp, "%s/mindi-data-%d.img", imagesdir, i);
    2728       log_msg (3, tmp);
    2729       if (!does_file_exist (tmp))
    2730     {
    2731       log_msg (3, "...not found");
    2732       break;
    2733     }
    2734       sprintf (comment, "About to write data disk #%d", i);
    2735       if (ask_me_OK_or_cancel (comment))
    2736     {
    2737       sprintf (comment, "Writing data disk #%3d", i);
    2738       log_to_screen (comment);
    2739       if (format_first)
    2740         {
    2741           res += format_disk (datadisk_dev);
    2742         }
    2743       res += write_image_to_floppy (datadisk_dev, tmp);
    2744     }
    2745     }
    2746   paranoid_free(tmp);
    2747   paranoid_free(comment);
    2748   paranoid_free(bootdisk_dev);
    2749   paranoid_free(datadisk_dev);
    2750   return (res);
     2808    }
     2809    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2810        log_to_screen
     2811            ("FYI, the data disks are stored on tape/CD for your convenience.");
     2812        return (0);
     2813    }
     2814    for (i = 1; i < 99; i++) {
     2815        sprintf(tmp, "%s/mindi-data-%d.img", imagesdir, i);
     2816        log_msg(3, tmp);
     2817        if (!does_file_exist(tmp)) {
     2818            log_msg(3, "...not found");
     2819            break;
     2820        }
     2821        sprintf(comment, "About to write data disk #%d", i);
     2822        if (ask_me_OK_or_cancel(comment)) {
     2823            sprintf(comment, "Writing data disk #%3d", i);
     2824            log_to_screen(comment);
     2825            if (format_first) {
     2826                res += format_disk(datadisk_dev);
     2827            }
     2828            res += write_image_to_floppy(datadisk_dev, tmp);
     2829        }
     2830    }
     2831    paranoid_free(tmp);
     2832    paranoid_free(comment);
     2833    paranoid_free(bootdisk_dev);
     2834    paranoid_free(datadisk_dev);
     2835    return (res);
    27512836}
    27522837
     
    27682853 */
    27692854
    2770 int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo)
     2855int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo
     2856                                                   *bkpinfo)
    27712857{
    2772 int res=0;
    2773 
    2774   assert(bkpinfo!=NULL);
    2775 
    2776       mvaddstr_and_log_it (g_currentY, 0,
    2777                "Writing boot+data floppy images to disk");
    2778 
    2779       if (!bkpinfo->nonbootable_backup) {
     2858    int res = 0;
     2859
     2860    assert(bkpinfo != NULL);
     2861
     2862    mvaddstr_and_log_it(g_currentY, 0,
     2863                        "Writing boot+data floppy images to disk");
     2864
     2865    if (!bkpinfo->nonbootable_backup) {
    27802866#ifdef __FreeBSD__
    2781       if (!does_file_exist ("/root/images/mindi/mindi-kern.1722.img"))
     2867        if (!does_file_exist("/root/images/mindi/mindi-kern.1722.img"))
    27822868#else
    2783       if (!does_file_exist ("/root/images/mindi/mindi-bootroot.1722.img") &&
    2784           !does_file_exist ("/root/images/mindi/mindi-boot.1440.img"))
     2869        if (!does_file_exist("/root/images/mindi/mindi-bootroot.1722.img")
     2870            && !does_file_exist("/root/images/mindi/mindi-boot.1440.img"))
    27852871#endif
    2786       {
    2787           mvaddstr_and_log_it (g_currentY++, 74, "No Imgs");
    2788           if (does_file_exist ("/root/images/mindi/mondorescue.iso"))
    2789           {
    2790               popup_and_OK
    2791               ("Boot+data floppy creation failed. However, FYI, you may burn /root/images/mindi/mondorescue.iso to a CD and boot from that instead if you wish.");
    2792               res++;
    2793           }
    2794       }
    2795       else
    2796       {
    2797           offer_to_write_floppies (bkpinfo, "/root/images/mindi");
    2798           mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    2799       }
    2800       } else {
    2801       popup_and_OK ("Since you opted for a nonbootable backup, no boot floppies were created.");
    2802       }
    2803      
    2804   return(res);
     2872        {
     2873            mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
     2874            if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
     2875                popup_and_OK
     2876                    ("Boot+data floppy creation failed. However, FYI, you may burn /root/images/mindi/mondorescue.iso to a CD and boot from that instead if you wish.");
     2877                res++;
     2878            }
     2879        } else {
     2880            offer_to_write_floppies(bkpinfo, "/root/images/mindi");
     2881            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2882        }
     2883    } else {
     2884        popup_and_OK
     2885            ("Since you opted for a nonbootable backup, no boot floppies were created.");
     2886    }
     2887
     2888    return (res);
    28052889}
    28062890
     
    28172901 * transfer files over the network) or leave it as is.
    28182902 */
    2819 int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) = _move_files_to_stream;
     2903int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
     2904    _move_files_to_stream;
    28202905
    28212906/**
     
    28332918 */
    28342919int
    2835 _move_files_to_stream (struct s_bkpinfo *bkpinfo,
    2836          char *files_to_add, ...)
     2920_move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    28372921{
    28382922
    2839     /*@ int *************************************************************/
    2840   int retval = 0;
     2923    /*@ int ************************************************************ */
     2924    int retval = 0;
    28412925    int res = 0;
    2842     /*@ buffers *********************************************************/
    2843 
    2844     /*@ char ************************************************************/
     2926    /*@ buffers ******************************************************** */
     2927
     2928    /*@ char *********************************************************** */
    28452929    char start_chr;
    28462930    char stop_chr;
    2847         char *curr_file, *cf;
    2848     /*@ long long *******************************************************/
    2849   long long length_of_incoming_file = 0;
    2850   t_archtype type;
    2851   va_list ap;
    2852 
    2853   assert(bkpinfo!=NULL);
    2854   malloc_string(curr_file);
    2855   va_start(ap, files_to_add);
    2856   for(cf = files_to_add; cf!=NULL; cf=va_arg(ap, char*))
    2857     {
    2858       if (!cf) {continue;}
    2859       strcpy(curr_file, cf);
    2860       if (!does_file_exist (curr_file))
    2861         {
    2862           log_msg (1,
    2863            "Warning - you're trying to add a non-existent file - '%s' to the tape",
    2864            curr_file);
    2865         }
     2931    char *curr_file, *cf;
     2932    /*@ long long ****************************************************** */
     2933    long long length_of_incoming_file = 0;
     2934    t_archtype type;
     2935    va_list ap;
     2936
     2937    assert(bkpinfo != NULL);
     2938    malloc_string(curr_file);
     2939    va_start(ap, files_to_add);
     2940    for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
     2941        if (!cf) {
     2942            continue;
     2943        }
     2944        strcpy(curr_file, cf);
     2945        if (!does_file_exist(curr_file)) {
     2946            log_msg(1,
     2947                    "Warning - you're trying to add a non-existent file - '%s' to the tape",
     2948                    curr_file);
     2949        }
    28662950/* create header chars */
    2867       start_chr = BLK_START_AN_AFIO_OR_SLICE;
    2868       stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
     2951        start_chr = BLK_START_AN_AFIO_OR_SLICE;
     2952        stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
    28692953/* ask for new tape if necessary */
    2870       length_of_incoming_file = length_of_file (curr_file);
    2871       write_header_block_to_stream (length_of_incoming_file, curr_file,
    2872                   start_chr);
    2873       if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star."))
    2874     { type = fileset; }
    2875       else if (strstr(curr_file, "slice"))
    2876     { type = biggieslice; }
    2877       else
    2878     { type = other; }
    2879       res = write_file_to_stream_from_file (bkpinfo, curr_file);
    2880       retval += res;
    2881       unlink (curr_file);
     2954        length_of_incoming_file = length_of_file(curr_file);
     2955        write_header_block_to_stream(length_of_incoming_file, curr_file,
     2956                                     start_chr);
     2957        if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
     2958            type = fileset;
     2959        } else if (strstr(curr_file, "slice")) {
     2960            type = biggieslice;
     2961        } else {
     2962            type = other;
     2963        }
     2964        res = write_file_to_stream_from_file(bkpinfo, curr_file);
     2965        retval += res;
     2966        unlink(curr_file);
    28822967/* write closing header */
    2883       write_header_block_to_stream (0, "finished-writing-file", stop_chr);
    2884     }
    2885   va_end(ap);
    2886 
    2887   if (retval)
    2888     {
    2889       log_msg (1, "Warning - errors occurred while I was adding file to tape");
    2890     }
    2891   paranoid_free(curr_file);
    2892   return (retval);
     2968        write_header_block_to_stream(0, "finished-writing-file", stop_chr);
     2969    }
     2970    va_end(ap);
     2971
     2972    if (retval) {
     2973        log_msg(1,
     2974                "Warning - errors occurred while I was adding file to tape");
     2975    }
     2976    paranoid_free(curr_file);
     2977    return (retval);
    28932978}
    28942979
     
    29082993 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
    29092994 */
    2910 int interrogate_disk_currently_in_cdrw_drive(char*cdrw_dev, bool keep_looping)
     2995int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
     2996                                             bool keep_looping)
    29112997{
    2912   char *tmp;
    2913   int res=0;
    2914   char *bkp;
    2915   char *cdrecord;
    2916 
    2917   malloc_string(tmp);
    2918   malloc_string(bkp);
    2919   malloc_string(cdrecord);
    2920   strcpy(bkp, cdrw_dev);
    2921   if (find_cdrw_device(cdrw_dev))
    2922     {
    2923       strcpy(cdrw_dev, bkp);
    2924     }
    2925   else
    2926     {
    2927       if (!system("which cdrecord > /dev/null 2> /dev/null"))
    2928         { sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev); }
    2929       else if (!system("which dvdrecord > /dev/null 2> /dev/null"))
    2930         { sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev); }
    2931       else
    2932         { cdrecord[0] = '\0'; log_msg(2, "Oh well. I guess I'll just pray then."); }
    2933       if (cdrecord[0])
    2934         {
    2935          if (!keep_looping)
    2936            {
    2937              retract_CD_tray_and_defeat_autorun();
    2938              res = run_program_and_log_output(cdrecord, 5);
    2939            }
    2940          else
    2941            {
    2942              while((res=run_program_and_log_output(cdrecord, 5)))
    2943                {
    2944                  retract_CD_tray_and_defeat_autorun();
    2945                  if (ask_me_yes_or_no("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
    2946                    { log_msg(1, "Well, he insisted..."); break; }
    2947                }
    2948             }
    2949         }
    2950     }
     2998    char *tmp;
     2999    int res = 0;
     3000    char *bkp;
     3001    char *cdrecord;
     3002
     3003    malloc_string(tmp);
     3004    malloc_string(bkp);
     3005    malloc_string(cdrecord);
     3006    strcpy(bkp, cdrw_dev);
     3007    if (find_cdrw_device(cdrw_dev)) {
     3008        strcpy(cdrw_dev, bkp);
     3009    } else {
     3010        if (!system("which cdrecord > /dev/null 2> /dev/null")) {
     3011            sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     3012        } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
     3013            sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     3014        } else {
     3015            cdrecord[0] = '\0';
     3016            log_msg(2, "Oh well. I guess I'll just pray then.");
     3017        }
     3018        if (cdrecord[0]) {
     3019            if (!keep_looping) {
     3020                retract_CD_tray_and_defeat_autorun();
     3021                res = run_program_and_log_output(cdrecord, 5);
     3022            } else {
     3023                while ((res = run_program_and_log_output(cdrecord, 5))) {
     3024                    retract_CD_tray_and_defeat_autorun();
     3025                    if (ask_me_yes_or_no
     3026                        ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
     3027                    {
     3028                        log_msg(1, "Well, he insisted...");
     3029                        break;
     3030                    }
     3031                }
     3032            }
     3033        }
     3034    }
    29513035//  retract_CD_tray_and_defeat_autorun();
    2952   paranoid_free(tmp);
    2953   paranoid_free(cdrecord);
    2954   paranoid_free(bkp);
    2955   return(res);
     3036    paranoid_free(tmp);
     3037    paranoid_free(cdrecord);
     3038    paranoid_free(bkp);
     3039    return (res);
    29563040}
    29573041
     
    29703054 */
    29713055void
    2972 pause_and_ask_for_cdr (int ask_for_one_if_more_than_this, bool*pmountable)
     3056pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
    29733057{
    29743058
    2975     /*@ buffers **********************************************/
    2976   char *tmp;
    2977   char *szmsg;
    2978   char *cdrom_dev;
    2979   char *cdrw_dev;
    2980   char *our_serial_str;
    2981   bool ok_go_ahead_burn_it;
    2982   int cd_number = -1;
    2983   int attempt_to_mount_returned_this=999;
    2984   char *mtpt;
    2985   char *szcdno;
    2986   char *szserfname;
    2987   char *szunmount;
    2988 
    2989   malloc_string(tmp);
    2990   malloc_string(szmsg);
    2991   malloc_string(cdrom_dev);
    2992   malloc_string(cdrw_dev);
    2993   malloc_string(mtpt);
    2994   malloc_string(szcdno);
    2995   malloc_string(szserfname);
    2996   malloc_string(our_serial_str);
    2997   malloc_string(szunmount);
    2998 
    2999   sprintf(szmsg, "I am about to burn %s #%d", media_descriptor_string(g_backup_media_type), g_current_media_number);
    3000   log_to_screen(szmsg);
    3001   if (g_current_media_number < ask_for_one_if_more_than_this)
    3002     { return; }
    3003  log_to_screen("Scanning CD-ROM drive...");
    3004   sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int)random(), (long int)random());
    3005   make_hole_for_dir(mtpt);
    3006 
    3007 gotos_make_me_puke:
    3008   ok_go_ahead_burn_it = TRUE;
    3009   if (!find_cdrom_device(cdrom_dev, FALSE))
    3010     {
     3059    /*@ buffers ********************************************* */
     3060    char *tmp;
     3061    char *szmsg;
     3062    char *cdrom_dev;
     3063    char *cdrw_dev;
     3064    char *our_serial_str;
     3065    bool ok_go_ahead_burn_it;
     3066    int cd_number = -1;
     3067    int attempt_to_mount_returned_this = 999;
     3068    char *mtpt;
     3069    char *szcdno;
     3070    char *szserfname;
     3071    char *szunmount;
     3072
     3073    malloc_string(tmp);
     3074    malloc_string(szmsg);
     3075    malloc_string(cdrom_dev);
     3076    malloc_string(cdrw_dev);
     3077    malloc_string(mtpt);
     3078    malloc_string(szcdno);
     3079    malloc_string(szserfname);
     3080    malloc_string(our_serial_str);
     3081    malloc_string(szunmount);
     3082
     3083    sprintf(szmsg, "I am about to burn %s #%d",
     3084            media_descriptor_string(g_backup_media_type),
     3085            g_current_media_number);
     3086    log_to_screen(szmsg);
     3087    if (g_current_media_number < ask_for_one_if_more_than_this) {
     3088        return;
     3089    }
     3090    log_to_screen("Scanning CD-ROM drive...");
     3091    sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
     3092            (long int) random());
     3093    make_hole_for_dir(mtpt);
     3094
     3095  gotos_make_me_puke:
     3096    ok_go_ahead_burn_it = TRUE;
     3097    if (!find_cdrom_device(cdrom_dev, FALSE)) {
    30113098/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
    30123099      log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
    30133100      retract_CD_tray_and_defeat_autorun();
    30143101*/
    3015       sprintf(tmp, "umount %s", cdrom_dev);
    3016       run_program_and_log_output(tmp, 1);
    3017       sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
    3018       sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
    3019       sprintf(szunmount, "umount %s", mtpt);
    3020       cd_number = -1;
    3021       our_serial_str[0] = '\0';
    3022       sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
    3023       if ((attempt_to_mount_returned_this=run_program_and_log_output(tmp, 1)))
    3024         {
    3025       log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
    3026       log_to_screen("If there's a CD/DVD in the drive, it's blank.");
    3027      /*
    3028       if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    3029         {
    3030               ok_go_ahead_burn_it = FALSE;
    3031               log_to_screen("There isn't a writable CD/DVD in the drive.");
    3032         }
    3033       else
    3034         {
    3035           log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
    3036         }
    3037      */
    3038         }
    3039       else if (!does_file_exist(szcdno) || !does_file_exist(szserfname))
    3040         {
    3041       log_to_screen("%s has data on it but it's probably not a Mondo CD.", media_descriptor_string(g_backup_media_type));
    3042         }
    3043       else
    3044     {
    3045       log_to_screen("%s found in drive. It's a Mondo disk.", media_descriptor_string(g_backup_media_type));
    3046           cd_number = atoi(last_line_of_file(szcdno));
    3047           sprintf(tmp, "cat %s 2> /dev/null", szserfname);
    3048           strcpy(our_serial_str, call_program_and_get_last_line_of_output(tmp));
    3049       // FIXME - should be able to use last_line_of_file(), surely?
    3050         }
    3051       run_program_and_log_output(szunmount, 1);
    3052       log_msg(2, "paafcd: cd_number = %d", cd_number);
    3053       log_msg(2, "our serial str = %s; g_serial_string = %s", our_serial_str, g_serial_string);
    3054       if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string))
    3055         {
    3056       log_msg(2, "This %s is part of this backup set!", media_descriptor_string(g_backup_media_type));
    3057           ok_go_ahead_burn_it = FALSE;
    3058           if (cd_number == g_current_media_number-1)
    3059             { log_to_screen("I think you've left the previous %s in the drive.", media_descriptor_string(g_backup_media_type)); }
    3060           else
    3061             { log_to_screen("Please remove this %s. It is part of the backup set you're making now.", media_descriptor_string(g_backup_media_type)); }
    3062         }
    3063       else
    3064         {
    3065       log_to_screen("...but not part of _our_ backup set.");
    3066     }
    3067     }
    3068   else
    3069     {
    3070       log_msg(2, "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?", media_descriptor_string(g_backup_media_type));
    3071       if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    3072         {
    3073           ok_go_ahead_burn_it = FALSE;
    3074           log_to_screen("There isn't a writable %s in the drive.", media_descriptor_string(g_backup_media_type));
    3075         }
    3076     }
     3102        sprintf(tmp, "umount %s", cdrom_dev);
     3103        run_program_and_log_output(tmp, 1);
     3104        sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
     3105        sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
     3106        sprintf(szunmount, "umount %s", mtpt);
     3107        cd_number = -1;
     3108        our_serial_str[0] = '\0';
     3109        sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
     3110        if ((attempt_to_mount_returned_this =
     3111             run_program_and_log_output(tmp, 1))) {
     3112            log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
     3113            log_to_screen("If there's a CD/DVD in the drive, it's blank.");
     3114            /*
     3115               if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
     3116               {
     3117               ok_go_ahead_burn_it = FALSE;
     3118               log_to_screen("There isn't a writable CD/DVD in the drive.");
     3119               }
     3120               else
     3121               {
     3122               log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
     3123               }
     3124             */
     3125        } else if (!does_file_exist(szcdno)
     3126                   || !does_file_exist(szserfname)) {
     3127            log_to_screen
     3128                ("%s has data on it but it's probably not a Mondo CD.",
     3129                 media_descriptor_string(g_backup_media_type));
     3130        } else {
     3131            log_to_screen("%s found in drive. It's a Mondo disk.",
     3132                          media_descriptor_string(g_backup_media_type));
     3133            cd_number = atoi(last_line_of_file(szcdno));
     3134            sprintf(tmp, "cat %s 2> /dev/null", szserfname);
     3135            strcpy(our_serial_str,
     3136                   call_program_and_get_last_line_of_output(tmp));
     3137            // FIXME - should be able to use last_line_of_file(), surely?
     3138        }
     3139        run_program_and_log_output(szunmount, 1);
     3140        log_msg(2, "paafcd: cd_number = %d", cd_number);
     3141        log_msg(2, "our serial str = %s; g_serial_string = %s",
     3142                our_serial_str, g_serial_string);
     3143        if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
     3144            log_msg(2, "This %s is part of this backup set!",
     3145                    media_descriptor_string(g_backup_media_type));
     3146            ok_go_ahead_burn_it = FALSE;
     3147            if (cd_number == g_current_media_number - 1) {
     3148                log_to_screen
     3149                    ("I think you've left the previous %s in the drive.",
     3150                     media_descriptor_string(g_backup_media_type));
     3151            } else {
     3152                log_to_screen
     3153                    ("Please remove this %s. It is part of the backup set you're making now.",
     3154                     media_descriptor_string(g_backup_media_type));
     3155            }
     3156        } else {
     3157            log_to_screen("...but not part of _our_ backup set.");
     3158        }
     3159    } else {
     3160        log_msg(2,
     3161                "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
     3162                media_descriptor_string(g_backup_media_type));
     3163        if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
     3164            ok_go_ahead_burn_it = FALSE;
     3165            log_to_screen("There isn't a writable %s in the drive.",
     3166                          media_descriptor_string(g_backup_media_type));
     3167        }
     3168    }
    30773169
    30783170/*
     
    30843176*/
    30853177
    3086   if (!ok_go_ahead_burn_it)
    3087     {
    3088       eject_device(cdrom_dev);
    3089       sprintf (tmp,
    3090            "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
    3091             media_descriptor_string(g_backup_media_type),
    3092            g_current_media_number,
    3093            media_descriptor_string(g_backup_media_type));
    3094       popup_and_OK (tmp);
    3095       goto gotos_make_me_puke;
    3096     }
    3097   else
    3098     {
    3099       log_msg(2, "paafcd: OK, going ahead and burning it.");
    3100     }
    3101 
    3102   log_msg (2,"paafcd: OK, I assume I have a blank/reusable %s in the drive...", media_descriptor_string(g_backup_media_type));
    3103 
    3104   //  if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
    3105 
    3106   log_to_screen ("Proceeding w/ %s in drive.", media_descriptor_string(g_backup_media_type));
    3107   paranoid_free(tmp);
    3108   paranoid_free(szmsg);
    3109   paranoid_free(cdrom_dev);
    3110   paranoid_free(cdrw_dev);
    3111   paranoid_free(mtpt);
    3112   paranoid_free(szcdno);
    3113   paranoid_free(szserfname);
    3114   paranoid_free(our_serial_str);
    3115   paranoid_free(szunmount);
    3116   if (pmountable)
    3117     {
    3118       if (attempt_to_mount_returned_this)
    3119         { *pmountable = FALSE; }
    3120       else
    3121         { *pmountable = TRUE; }
    3122     }
     3178    if (!ok_go_ahead_burn_it) {
     3179        eject_device(cdrom_dev);
     3180        sprintf(tmp,
     3181                "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
     3182                media_descriptor_string(g_backup_media_type),
     3183                g_current_media_number,
     3184                media_descriptor_string(g_backup_media_type));
     3185        popup_and_OK(tmp);
     3186        goto gotos_make_me_puke;
     3187    } else {
     3188        log_msg(2, "paafcd: OK, going ahead and burning it.");
     3189    }
     3190
     3191    log_msg(2,
     3192            "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
     3193            media_descriptor_string(g_backup_media_type));
     3194
     3195    //  if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
     3196
     3197    log_to_screen("Proceeding w/ %s in drive.",
     3198                  media_descriptor_string(g_backup_media_type));
     3199    paranoid_free(tmp);
     3200    paranoid_free(szmsg);
     3201    paranoid_free(cdrom_dev);
     3202    paranoid_free(cdrw_dev);
     3203    paranoid_free(mtpt);
     3204    paranoid_free(szcdno);
     3205    paranoid_free(szserfname);
     3206    paranoid_free(our_serial_str);
     3207    paranoid_free(szunmount);
     3208    if (pmountable) {
     3209        if (attempt_to_mount_returned_this) {
     3210            *pmountable = FALSE;
     3211        } else {
     3212            *pmountable = TRUE;
     3213        }
     3214    }
    31233215
    31243216}
     
    31383230 * @see get_bit_N_of_array
    31393231 */
    3140 void set_bit_N_of_array(char*array, int N, bool true_or_false)
     3232void set_bit_N_of_array(char *array, int N, bool true_or_false)
    31413233{
    3142   int bit_number;
    3143   int mask, orig_val, to_add;
    3144   int element_number;
    3145 
    3146   assert(array!=NULL);
    3147 
    3148   element_number = N / 8;
    3149   bit_number = N % 8;
    3150   to_add = (1 << bit_number);
    3151   mask = 255 - to_add;
    3152   orig_val = array[element_number] & mask;
    3153   //  log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
    3154   if (true_or_false) { array[element_number] = orig_val | to_add; }
     3234    int bit_number;
     3235    int mask, orig_val, to_add;
     3236    int element_number;
     3237
     3238    assert(array != NULL);
     3239
     3240    element_number = N / 8;
     3241    bit_number = N % 8;
     3242    to_add = (1 << bit_number);
     3243    mask = 255 - to_add;
     3244    orig_val = array[element_number] & mask;
     3245    //  log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
     3246    if (true_or_false) {
     3247        array[element_number] = orig_val | to_add;
     3248    }
    31553249}
    31563250
     
    31843278 */
    31853279int
    3186 slice_up_file_etc (struct s_bkpinfo *bkpinfo, char *biggie_filename, char *partimagehack_fifo,
    3187            long biggie_file_number, long noof_biggie_files, bool use_partimagehack)
     3280slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
     3281                  char *partimagehack_fifo, long biggie_file_number,
     3282                  long noof_biggie_files, bool use_partimagehack)
    31883283{
    31893284
    3190     /*@ buffers ***************************************************/
    3191   char *tmp, *checksum_line, *command;
    3192   char *tempblock;
    3193   char *curr_slice_fname_uncompressed;
    3194   char *curr_slice_fname_compressed;
    3195   char *file_to_archive;
    3196   char *file_to_openin;
    3197     /*@ pointers ***************************************************/
    3198   char *pB;
    3199   FILE *fin, *fout;
    3200 
    3201     /*@ bool *******************************************************/
    3202   bool finished = FALSE;
    3203 
    3204     /*@ long *******************************************************/
    3205   size_t blksize = 0;
    3206   long slice_num = 0;
    3207   long i;
    3208   long optimal_set_size;
    3209   bool should_I_compress_slices;
    3210   char *suffix; // for compressed slices
    3211 
    3212     /*@ long long ***************************************************/
    3213   long long totalread = 0;
    3214   long long totallength = 0;
    3215   long long length;
    3216 
    3217   /*@ int *********************************************************/
    3218   int retval = 0;
    3219   int res = 0;
    3220 
    3221     /*@ structures ***************************************************/
    3222   struct s_filename_and_lstat_info biggiestruct;
     3285    /*@ buffers ************************************************** */
     3286    char *tmp, *checksum_line, *command;
     3287    char *tempblock;
     3288    char *curr_slice_fname_uncompressed;
     3289    char *curr_slice_fname_compressed;
     3290    char *file_to_archive;
     3291    char *file_to_openin;
     3292    /*@ pointers ************************************************** */
     3293    char *pB;
     3294    FILE *fin, *fout;
     3295
     3296    /*@ bool ****************************************************** */
     3297    bool finished = FALSE;
     3298
     3299    /*@ long ****************************************************** */
     3300    size_t blksize = 0;
     3301    long slice_num = 0;
     3302    long i;
     3303    long optimal_set_size;
     3304    bool should_I_compress_slices;
     3305    char *suffix;               // for compressed slices
     3306
     3307    /*@ long long ************************************************** */
     3308    long long totalread = 0;
     3309    long long totallength = 0;
     3310    long long length;
     3311
     3312    /*@ int ******************************************************** */
     3313    int retval = 0;
     3314    int res = 0;
     3315
     3316    /*@ structures ************************************************** */
     3317    struct s_filename_and_lstat_info biggiestruct;
    32233318//  struct stat statbuf;
    32243319
    3225   assert(bkpinfo!=NULL);
    3226   assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    3227   malloc_string(tmp);
    3228   malloc_string(checksum_line);
    3229   malloc_string(curr_slice_fname_uncompressed);
    3230   malloc_string(curr_slice_fname_compressed);
    3231   malloc_string(file_to_archive);
    3232   malloc_string(suffix);
    3233   command = malloc(MAX_STR_LEN*8);
    3234 
    3235   biggiestruct.for_backward_compatibility = '\n';
    3236   biggiestruct.use_partimagehack = use_partimagehack;
    3237   if (!(tempblock = (char*)malloc(256*1024))) { fatal_error("malloc error 256*1024"); }
    3238   optimal_set_size = bkpinfo->optimal_set_size;
    3239   if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0)
    3240     {
    3241       suffix[0] = '\0';
    3242       //      log_it("%s is indeed compressed :-)", filename);
    3243       should_I_compress_slices = FALSE;
    3244     }
    3245   else
    3246     {
    3247       strcpy(suffix, bkpinfo->zip_suffix);
    3248       should_I_compress_slices = TRUE;
    3249     }
    3250 
    3251   if (optimal_set_size < 999)
    3252     {
    3253       fatal_error ("bkpinfo->optimal_set_size is insanely small");
    3254     }
    3255   if (partimagehack_fifo)
    3256     {
    3257       file_to_openin = partimagehack_fifo;
    3258       strcpy (checksum_line, "IGNORE");
    3259       log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
    3260     }
    3261   else
    3262     {
    3263       file_to_openin = biggie_filename;
    3264       sprintf (command, "md5sum '%s'", biggie_filename);
    3265       if (!(fin = popen (command, "r"))) { log_OS_error("Unable to popen-in command"); return(1); }
    3266       (void) fgets (checksum_line, MAX_STR_LEN, fin);
    3267       pclose (fin);
    3268     }
    3269   lstat (biggie_filename, &biggiestruct.properties);
    3270   strcpy (biggiestruct.filename, biggie_filename);
    3271   pB = strchr(checksum_line, ' ');
    3272   if (!pB) { pB = strchr(checksum_line, '\t'); }
    3273   if (pB) { *pB='\0'; }
    3274   strcpy (biggiestruct.checksum, checksum_line);
    3275 
    3276   strcpy (tmp, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""));
    3277   fout = fopen (tmp, "w");
    3278   (void) fwrite((void*)&biggiestruct, 1, sizeof(biggiestruct), fout);
    3279   paranoid_fclose (fout);
    3280   totallength = length_of_file (biggie_filename);
    3281   length      = totallength / optimal_set_size / 1024;
    3282   log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin);
    3283   if (!(fin = fopen(file_to_openin, "r")))
    3284     {
    3285       log_OS_error("Unable to openin biggie_filename");
    3286       sprintf (tmp, "Cannot archive bigfile '%s': not found", biggie_filename);
    3287       log_to_screen (tmp);
    3288       paranoid_free(tempblock);
    3289       paranoid_free(tmp);
    3290       paranoid_free(checksum_line);
    3291       paranoid_free(command);
    3292       return (1);
    3293     }
    3294   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3295     { res = move_files_to_stream (bkpinfo, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL); }
    3296   else
    3297     { res = move_files_to_cd (bkpinfo, slice_fname (biggie_file_number, 0, bkpinfo->tmpdir, ""), NULL); }
    3298   i = bkpinfo->optimal_set_size / 256;
    3299   for (slice_num = 1; !finished; slice_num++)
    3300     {
    3301       strcpy (curr_slice_fname_uncompressed,
    3302           slice_fname (biggie_file_number, slice_num, bkpinfo->tmpdir,
    3303                ""));
    3304       strcpy (curr_slice_fname_compressed,
    3305           slice_fname (biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
    3306 
    3307       strcpy (tmp, percent_media_full_comment (bkpinfo));
    3308       update_progress_form (tmp);
    3309       if (!(fout = fopen (curr_slice_fname_uncompressed, "w"))) { log_OS_error(curr_slice_fname_uncompressed); return(1); }
    3310       if ( (i == bkpinfo->optimal_set_size / 256) && (totalread < 1.1 * totallength) )
    3311     {
    3312       for (i = 0; i < bkpinfo->optimal_set_size / 256; i++)
    3313         {
    3314           blksize = fread (tempblock, 1, 256 * 1024, fin);
    3315           if (blksize > 0)
     3320    assert(bkpinfo != NULL);
     3321    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
     3322    malloc_string(tmp);
     3323    malloc_string(checksum_line);
     3324    malloc_string(curr_slice_fname_uncompressed);
     3325    malloc_string(curr_slice_fname_compressed);
     3326    malloc_string(file_to_archive);
     3327    malloc_string(suffix);
     3328    command = malloc(MAX_STR_LEN * 8);
     3329
     3330    biggiestruct.for_backward_compatibility = '\n';
     3331    biggiestruct.use_partimagehack = use_partimagehack;
     3332    if (!(tempblock = (char *) malloc(256 * 1024))) {
     3333        fatal_error("malloc error 256*1024");
     3334    }
     3335    optimal_set_size = bkpinfo->optimal_set_size;
     3336    if (is_this_file_compressed(biggie_filename)
     3337        || bkpinfo->compression_level == 0) {
     3338        suffix[0] = '\0';
     3339        //      log_it("%s is indeed compressed :-)", filename);
     3340        should_I_compress_slices = FALSE;
     3341    } else {
     3342        strcpy(suffix, bkpinfo->zip_suffix);
     3343        should_I_compress_slices = TRUE;
     3344    }
     3345
     3346    if (optimal_set_size < 999) {
     3347        fatal_error("bkpinfo->optimal_set_size is insanely small");
     3348    }
     3349    if (partimagehack_fifo) {
     3350        file_to_openin = partimagehack_fifo;
     3351        strcpy(checksum_line, "IGNORE");
     3352        log_msg(2,
     3353                "Not calculating checksum for %s: it would take too long",
     3354                biggie_filename);
     3355    } else {
     3356        file_to_openin = biggie_filename;
     3357        sprintf(command, "md5sum '%s'", biggie_filename);
     3358        if (!(fin = popen(command, "r"))) {
     3359            log_OS_error("Unable to popen-in command");
     3360            return (1);
     3361        }
     3362        (void) fgets(checksum_line, MAX_STR_LEN, fin);
     3363        pclose(fin);
     3364    }
     3365    lstat(biggie_filename, &biggiestruct.properties);
     3366    strcpy(biggiestruct.filename, biggie_filename);
     3367    pB = strchr(checksum_line, ' ');
     3368    if (!pB) {
     3369        pB = strchr(checksum_line, '\t');
     3370    }
     3371    if (pB) {
     3372        *pB = '\0';
     3373    }
     3374    strcpy(biggiestruct.checksum, checksum_line);
     3375
     3376    strcpy(tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     3377    fout = fopen(tmp, "w");
     3378    (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
     3379    paranoid_fclose(fout);
     3380    totallength = length_of_file(biggie_filename);
     3381    length = totallength / optimal_set_size / 1024;
     3382    log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
     3383            file_to_openin);
     3384    if (!(fin = fopen(file_to_openin, "r"))) {
     3385        log_OS_error("Unable to openin biggie_filename");
     3386        sprintf(tmp, "Cannot archive bigfile '%s': not found",
     3387                biggie_filename);
     3388        log_to_screen(tmp);
     3389        paranoid_free(tempblock);
     3390        paranoid_free(tmp);
     3391        paranoid_free(checksum_line);
     3392        paranoid_free(command);
     3393        return (1);
     3394    }
     3395    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3396        res =
     3397            move_files_to_stream(bkpinfo,
     3398                                 slice_fname(biggie_file_number, 0,
     3399                                             bkpinfo->tmpdir, ""), NULL);
     3400    } else {
     3401        res =
     3402            move_files_to_cd(bkpinfo,
     3403                             slice_fname(biggie_file_number, 0,
     3404                                         bkpinfo->tmpdir, ""), NULL);
     3405    }
     3406    i = bkpinfo->optimal_set_size / 256;
     3407    for (slice_num = 1; !finished; slice_num++) {
     3408        strcpy(curr_slice_fname_uncompressed,
     3409               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
     3410                           ""));
     3411        strcpy(curr_slice_fname_compressed,
     3412               slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
     3413                           suffix));
     3414
     3415        strcpy(tmp, percent_media_full_comment(bkpinfo));
     3416        update_progress_form(tmp);
     3417        if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
     3418            log_OS_error(curr_slice_fname_uncompressed);
     3419            return (1);
     3420        }
     3421        if ((i == bkpinfo->optimal_set_size / 256)
     3422            && (totalread < 1.1 * totallength)) {
     3423            for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
     3424                blksize = fread(tempblock, 1, 256 * 1024, fin);
     3425                if (blksize > 0) {
     3426                    totalread = totalread + blksize;
     3427                    (void) fwrite(tempblock, 1, blksize, fout);
     3428                } else {
     3429                    break;
     3430                }
     3431            }
     3432        } else {
     3433            i = 0;
     3434        }
     3435        paranoid_fclose(fout);
     3436        if (i > 0)              // length_of_file (curr_slice_fname_uncompressed)
    33163437        {
    3317           totalread = totalread + blksize;
    3318           (void) fwrite (tempblock, 1, blksize, fout);
    3319         }
    3320           else
    3321         {
    3322           break;
    3323         }
    3324         }
    3325     }
    3326       else
    3327     {
    3328       i = 0;
    3329     }
    3330       paranoid_fclose (fout);
    3331       if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
    3332     {
    3333       if (!does_file_exist (curr_slice_fname_uncompressed))
    3334         {
    3335           log_msg (2,
    3336                "Warning - '%s' doesn't exist. How can I compress slice?",
    3337                curr_slice_fname_uncompressed);
    3338         }
    3339           if (should_I_compress_slices && bkpinfo->compression_level>0)
    3340             {
    3341           sprintf (command, "%s -%d %s", bkpinfo->zip_exe,
    3342            bkpinfo->compression_level, curr_slice_fname_uncompressed);
    3343               log_msg (2, command);
    3344           if ((res = system (command))) { log_OS_error(command); }
    3345           //          did_I_compress_slice = TRUE;
    3346             }
    3347           else
    3348             {
    3349               sprintf (command, "mv %s %s 2>> %s", curr_slice_fname_uncompressed, curr_slice_fname_compressed, MONDO_LOGFILE);
    3350               res=0; // don't do it :)
    3351           //          did_I_compress_slice = FALSE;
    3352             }
    3353       retval += res;
    3354       if (res)
    3355         {
    3356           log_msg (2, "Failed to compress the slice");
    3357         }
    3358       if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed))
    3359         {
    3360           unlink (curr_slice_fname_uncompressed);
    3361         }
    3362       if (res)
    3363         {
    3364           sprintf (tmp, "Problem with slice # %ld", slice_num);
    3365         }
    3366       else
    3367         {
    3368           sprintf (tmp,
    3369                "%s - Bigfile #%ld, slice #%ld compressed OK          ",
    3370                biggie_filename, biggie_file_number + 1, slice_num);
    3371         }
     3438            if (!does_file_exist(curr_slice_fname_uncompressed)) {
     3439                log_msg(2,
     3440                        "Warning - '%s' doesn't exist. How can I compress slice?",
     3441                        curr_slice_fname_uncompressed);
     3442            }
     3443            if (should_I_compress_slices && bkpinfo->compression_level > 0) {
     3444                sprintf(command, "%s -%d %s", bkpinfo->zip_exe,
     3445                        bkpinfo->compression_level,
     3446                        curr_slice_fname_uncompressed);
     3447                log_msg(2, command);
     3448                if ((res = system(command))) {
     3449                    log_OS_error(command);
     3450                }
     3451                //          did_I_compress_slice = TRUE;
     3452            } else {
     3453                sprintf(command, "mv %s %s 2>> %s",
     3454                        curr_slice_fname_uncompressed,
     3455                        curr_slice_fname_compressed, MONDO_LOGFILE);
     3456                res = 0;        // don't do it :)
     3457                //          did_I_compress_slice = FALSE;
     3458            }
     3459            retval += res;
     3460            if (res) {
     3461                log_msg(2, "Failed to compress the slice");
     3462            }
     3463            if (bkpinfo->use_lzo
     3464                && strcmp(curr_slice_fname_compressed,
     3465                          curr_slice_fname_uncompressed)) {
     3466                unlink(curr_slice_fname_uncompressed);
     3467            }
     3468            if (res) {
     3469                sprintf(tmp, "Problem with slice # %ld", slice_num);
     3470            } else {
     3471                sprintf(tmp,
     3472                        "%s - Bigfile #%ld, slice #%ld compressed OK          ",
     3473                        biggie_filename, biggie_file_number + 1,
     3474                        slice_num);
     3475            }
    33723476#ifndef _XWIN
    3373       if (!g_text_mode)
    3374         {
    3375           newtDrawRootText (0, g_noof_rows - 2, tmp);
    3376           newtRefresh ();
    3377         }
    3378       else
    3379         {
    3380           log_msg (2, tmp);
    3381         }
     3477            if (!g_text_mode) {
     3478                newtDrawRootText(0, g_noof_rows - 2, tmp);
     3479                newtRefresh();
     3480            } else {
     3481                log_msg(2, tmp);
     3482            }
    33823483#else
    3383         log_msg(2, tmp);
     3484            log_msg(2, tmp);
    33843485#endif
    3385         strcpy(file_to_archive, curr_slice_fname_compressed);
    3386       g_current_progress++;
    3387     }
    3388       else /* if i==0 then ... */
    3389     {
    3390       finished = TRUE;
    3391       strcpy (file_to_archive, curr_slice_fname_uncompressed);
    3392           if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3393         {
    3394           break;
    3395         }
    3396     }
    3397 
    3398       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    3399         {
    3400           register_in_tape_catalog(biggieslice, biggie_file_number, slice_num, file_to_archive);
    3401           maintain_collection_of_recent_archives(bkpinfo->tmpdir, file_to_archive);
    3402       res = move_files_to_stream (bkpinfo, file_to_archive, NULL);
    3403     }
    3404       else
    3405         {
    3406       res = move_files_to_cd (bkpinfo, file_to_archive, NULL);
    3407     }
    3408       retval += res;
    3409       if (res)
    3410     {
    3411       sprintf (tmp,
    3412            "Failed to add slice %ld of bigfile %ld to scratchdir",
    3413            slice_num, biggie_file_number+1);
    3414       log_to_screen (tmp);
    3415       fatal_error
    3416         ("Hard disk full. You should have bought a bigger one.");
    3417     }
    3418     }
    3419   paranoid_fclose (fin);
    3420   sprintf (tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
    3421   if (retval)
    3422     {
    3423       strcat (tmp, "...FAILED");
    3424     }
    3425   else
    3426     {
    3427       strcat (tmp, "...OK!");
    3428     }
    3429   log_msg (1, tmp);
    3430   paranoid_free(tempblock);
    3431   paranoid_free(tmp);
    3432   paranoid_free(checksum_line);
    3433   paranoid_free(command);
    3434   paranoid_free(curr_slice_fname_uncompressed);
    3435   paranoid_free(curr_slice_fname_compressed);
    3436   paranoid_free(file_to_archive);
    3437   paranoid_free(suffix);
    3438   return (retval);
     3486            strcpy(file_to_archive, curr_slice_fname_compressed);
     3487            g_current_progress++;
     3488        } else {                /* if i==0 then ... */
     3489
     3490            finished = TRUE;
     3491            strcpy(file_to_archive, curr_slice_fname_uncompressed);
     3492            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3493                break;
     3494            }
     3495        }
     3496
     3497        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3498            register_in_tape_catalog(biggieslice, biggie_file_number,
     3499                                     slice_num, file_to_archive);
     3500            maintain_collection_of_recent_archives(bkpinfo->tmpdir,
     3501                                                   file_to_archive);
     3502            res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
     3503        } else {
     3504            res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
     3505        }
     3506        retval += res;
     3507        if (res) {
     3508            sprintf(tmp,
     3509                    "Failed to add slice %ld of bigfile %ld to scratchdir",
     3510                    slice_num, biggie_file_number + 1);
     3511            log_to_screen(tmp);
     3512            fatal_error
     3513                ("Hard disk full. You should have bought a bigger one.");
     3514        }
     3515    }
     3516    paranoid_fclose(fin);
     3517    sprintf(tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
     3518    if (retval) {
     3519        strcat(tmp, "...FAILED");
     3520    } else {
     3521        strcat(tmp, "...OK!");
     3522    }
     3523    log_msg(1, tmp);
     3524    paranoid_free(tempblock);
     3525    paranoid_free(tmp);
     3526    paranoid_free(checksum_line);
     3527    paranoid_free(command);
     3528    paranoid_free(curr_slice_fname_uncompressed);
     3529    paranoid_free(curr_slice_fname_compressed);
     3530    paranoid_free(file_to_archive);
     3531    paranoid_free(suffix);
     3532    return (retval);
    34393533}
    34403534
     
    34563550 * @ingroup utilityGroup
    34573551 */
    3458 void
    3459 wipe_archives (char *d)
     3552void wipe_archives(char *d)
    34603553{
    3461     /*@ buffers **********************************************/
    3462   char *tmp;
    3463   char *dir;
    3464 
    3465   malloc_string(tmp);
    3466   malloc_string(dir);
    3467   assert_string_is_neither_NULL_nor_zerolength(d);
    3468 
    3469   sprintf (dir, "%s/archives", d);
    3470   sprintf (tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
    3471   run_program_and_log_output(tmp, FALSE);
    3472   sprintf (tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
    3473   run_program_and_log_output(tmp, FALSE);
    3474   sprintf (tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
    3475   run_program_and_log_output(tmp, FALSE);
    3476   sprintf (tmp, "rm -f %s/cklist*", dir);
    3477   run_program_and_log_output(tmp, FALSE);
    3478   sprintf (tmp, "rm -f %s/zero", dir);
    3479   run_program_and_log_output(tmp, FALSE);
    3480   log_msg(1, "Wiped %s's archives", dir);
    3481   sprintf (tmp, "ls -l %s", dir);
    3482   run_program_and_log_output (tmp, FALSE);
    3483   paranoid_free(tmp);
    3484   paranoid_free(dir);
     3554    /*@ buffers ********************************************* */
     3555    char *tmp;
     3556    char *dir;
     3557
     3558    malloc_string(tmp);
     3559    malloc_string(dir);
     3560    assert_string_is_neither_NULL_nor_zerolength(d);
     3561
     3562    sprintf(dir, "%s/archives", d);
     3563    sprintf(tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
     3564    run_program_and_log_output(tmp, FALSE);
     3565    sprintf(tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
     3566    run_program_and_log_output(tmp, FALSE);
     3567    sprintf(tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
     3568    run_program_and_log_output(tmp, FALSE);
     3569    sprintf(tmp, "rm -f %s/cklist*", dir);
     3570    run_program_and_log_output(tmp, FALSE);
     3571    sprintf(tmp, "rm -f %s/zero", dir);
     3572    run_program_and_log_output(tmp, FALSE);
     3573    log_msg(1, "Wiped %s's archives", dir);
     3574    sprintf(tmp, "ls -l %s", dir);
     3575    run_program_and_log_output(tmp, FALSE);
     3576    paranoid_free(tmp);
     3577    paranoid_free(dir);
    34853578}
    34863579
     
    35013594 * however, this occurs rarely.
    35023595 */
    3503 int
    3504 write_final_iso_if_necessary (struct s_bkpinfo *bkpinfo)
     3596int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
    35053597{
    3506     /*@ int ******************************************************/
    3507   int res;
    3508 
    3509     /*@ buffers ***************************************************/
    3510   char *tmp;
    3511 
    3512   malloc_string(tmp);
    3513   assert(bkpinfo!=NULL);
     3598    /*@ int ***************************************************** */
     3599    int res;
     3600
     3601    /*@ buffers ************************************************** */
     3602    char *tmp;
     3603
     3604    malloc_string(tmp);
     3605    assert(bkpinfo != NULL);
    35143606
    35153607// I should really check if there are any slices or tarballs to be copied to CD-R(W)'s; the odds are approx. 1 in a million that there are no files here, so I'll just go ahead & make one more CD anyway
    35163608
    3517   sprintf(tmp, "Writing the final ISO");
    3518   log_msg(2, tmp);
    3519   center_string (tmp, 80);
     3609    sprintf(tmp, "Writing the final ISO");
     3610    log_msg(2, tmp);
     3611    center_string(tmp, 80);
    35203612#ifndef _XWIN
    3521   if (!g_text_mode)
    3522     {
    3523       newtPushHelpLine (tmp);
    3524     }
     3613    if (!g_text_mode) {
     3614        newtPushHelpLine(tmp);
     3615    }
    35253616#endif
    3526   res = write_iso_and_go_on (bkpinfo, TRUE);
     3617    res = write_iso_and_go_on(bkpinfo, TRUE);
    35273618#ifndef _XWIN
    3528   if (!g_text_mode)
    3529     {
    3530       newtPopHelpLine ();
    3531     }
     3619    if (!g_text_mode) {
     3620        newtPopHelpLine();
     3621    }
    35323622#endif
    3533   log_msg (2, "Returning from writing final ISO (res=%d)", res);
    3534   paranoid_free(tmp);
    3535   return (res);
     3623    log_msg(2, "Returning from writing final ISO (res=%d)", res);
     3624    paranoid_free(tmp);
     3625    return (res);
    35363626}
    35373627
     
    35543644 * @see make_iso_fs
    35553645 */
    3556 int
    3557 write_iso_and_go_on (struct s_bkpinfo *bkpinfo, bool last_cd)
     3646int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
    35583647{
    3559     /*@ pointers *****************************************************/
    3560   FILE *fout;
    3561 
    3562     /*@ buffers ******************************************************/
    3563   char *tmp;
    3564   char *cdno_fname;
    3565   char *lastcd_fname;
    3566   char *isofile;
    3567 
    3568     /*@ bool *********************************************************/
    3569   bool that_one_was_ok;
    3570   bool using_nfs;
    3571   bool orig_vfy_flag_val;
    3572 
    3573     /*@ int ************************************************************/
    3574   int res = 0;
    3575 
    3576   malloc_string(tmp);
    3577   malloc_string(cdno_fname);
    3578   malloc_string(lastcd_fname);
    3579   malloc_string(isofile);
    3580  
    3581   assert(bkpinfo!=NULL);
    3582   orig_vfy_flag_val = bkpinfo->verify_data;
    3583   if (bkpinfo->media_size[g_current_media_number]<=0) { fatal_error( "write_iso_and_go_on() - unknown media size"); }
    3584 
    3585   if (strlen (bkpinfo->nfs_mount) > 1)
    3586     {
    3587       using_nfs = TRUE;
    3588     }
    3589   else
    3590     {
    3591       using_nfs = FALSE;
    3592     }
    3593   log_msg (1, "OK, time to make %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    3594 
    3595   /* label the ISO with its number */
    3596 
    3597   sprintf (cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
    3598   fout = fopen (cdno_fname, "w");
    3599   fprintf (fout, "%d", g_current_media_number);
    3600   paranoid_fclose (fout);
    3601 
    3602   sprintf (tmp, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir);
    3603   if (run_program_and_log_output(tmp, FALSE))
    3604     { log_msg(2, "Warning - unable to copy autorun to scratchdir"); }
    3605 
    3606   /* last CD or not? Label accordingly */
    3607   sprintf (lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    3608   if (last_cd)
    3609     {
    3610       unlink (lastcd_fname);
    3611       log_msg (2, "OK, you're telling me this is the last CD. Fair enough.");
    3612     }
    3613   else
    3614     {
    3615       fout = fopen (lastcd_fname, "w");
    3616       fprintf (fout,
    3617            "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
    3618       paranoid_fclose (fout);
    3619     }
    3620   if (space_occupied_by_cd (bkpinfo->scratchdir) / 1024 > bkpinfo->media_size[g_current_media_number])
    3621     {
    3622       sprintf (tmp,
    3623            "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
    3624            (long) space_occupied_by_cd (bkpinfo->scratchdir),
    3625            (long) bkpinfo->media_size[g_current_media_number]);
    3626       log_to_screen (tmp);
    3627     }
    3628   sprintf (isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
    3629            bkpinfo->prefix, g_current_media_number);
    3630   for (that_one_was_ok = FALSE; !that_one_was_ok;)
    3631     {
    3632       res = make_iso_fs (bkpinfo, isofile);
    3633       if (g_current_media_number==1 && !res && ( bkpinfo->backup_media_type == cdr || bkpinfo->backup_media_type == cdrw) )
    3634         {
    3635           if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
    3636             { log_msg(3, "*Sigh* Mike, I hate your computer."); bkpinfo->manual_cd_tray = TRUE; } // if it can't be found then force pausing
    3637           else
    3638             { log_msg(3, "Great. Found Mike's CD-ROM drive."); }
    3639         }
    3640       if (bkpinfo->verify_data && !res)
    3641     {
    3642       log_to_screen
    3643         ("Please reboot from the 1st %s in Compare Mode, as a precaution.", media_descriptor_string(g_backup_media_type));
    3644       chdir ("/");
    3645       iamhere("Before calling verify_cd_image()");
    3646       res += verify_cd_image (bkpinfo);
    3647       iamhere("After calling verify_cd_image()");
    3648     }
    3649       if (!res)
    3650     {
    3651       that_one_was_ok = TRUE;
    3652     }
    3653       else
    3654     {
    3655       sprintf (tmp, "Failed to burn %s #%d. Retry?",
    3656             media_descriptor_string(bkpinfo->backup_media_type),
    3657            g_current_media_number);
    3658       res = ask_me_yes_or_no (tmp);
    3659       if (!res)
    3660         {
    3661           if (ask_me_yes_or_no ("Abort the backup?"))
    3662         {
    3663           fatal_error ("FAILED TO BACKUP");
    3664         }
    3665           else
    3666         {
    3667           break;
    3668         }
    3669         }
    3670       else
    3671         {
    3672           log_msg (2, "Retrying, at user's request...");
    3673           res = 0;
    3674         }
    3675     }
    3676     }
     3648    /*@ pointers **************************************************** */
     3649    FILE *fout;
     3650
     3651    /*@ buffers ***************************************************** */
     3652    char *tmp;
     3653    char *cdno_fname;
     3654    char *lastcd_fname;
     3655    char *isofile;
     3656
     3657    /*@ bool ******************************************************** */
     3658    bool that_one_was_ok;
     3659    bool using_nfs;
     3660    bool orig_vfy_flag_val;
     3661
     3662    /*@ int *********************************************************** */
     3663    int res = 0;
     3664
     3665    malloc_string(tmp);
     3666    malloc_string(cdno_fname);
     3667    malloc_string(lastcd_fname);
     3668    malloc_string(isofile);
     3669
     3670    assert(bkpinfo != NULL);
     3671    orig_vfy_flag_val = bkpinfo->verify_data;
     3672    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     3673        fatal_error("write_iso_and_go_on() - unknown media size");
     3674    }
     3675
     3676    if (strlen(bkpinfo->nfs_mount) > 1) {
     3677        using_nfs = TRUE;
     3678    } else {
     3679        using_nfs = FALSE;
     3680    }
     3681    log_msg(1, "OK, time to make %s #%d",
     3682            media_descriptor_string(bkpinfo->backup_media_type),
     3683            g_current_media_number);
     3684
     3685    /* label the ISO with its number */
     3686
     3687    sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
     3688    fout = fopen(cdno_fname, "w");
     3689    fprintf(fout, "%d", g_current_media_number);
     3690    paranoid_fclose(fout);
     3691
     3692    sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home,
     3693            bkpinfo->scratchdir);
     3694    if (run_program_and_log_output(tmp, FALSE)) {
     3695        log_msg(2, "Warning - unable to copy autorun to scratchdir");
     3696    }
     3697
     3698    /* last CD or not? Label accordingly */
     3699    sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     3700    if (last_cd) {
     3701        unlink(lastcd_fname);
     3702        log_msg(2,
     3703                "OK, you're telling me this is the last CD. Fair enough.");
     3704    } else {
     3705        fout = fopen(lastcd_fname, "w");
     3706        fprintf(fout,
     3707                "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
     3708        paranoid_fclose(fout);
     3709    }
     3710    if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
     3711        bkpinfo->media_size[g_current_media_number]) {
     3712        sprintf(tmp,
     3713                "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
     3714                (long) space_occupied_by_cd(bkpinfo->scratchdir),
     3715                (long) bkpinfo->media_size[g_current_media_number]);
     3716        log_to_screen(tmp);
     3717    }
     3718    sprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
     3719            bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     3720            g_current_media_number);
     3721    for (that_one_was_ok = FALSE; !that_one_was_ok;) {
     3722        res = make_iso_fs(bkpinfo, isofile);
     3723        if (g_current_media_number == 1 && !res
     3724            && (bkpinfo->backup_media_type == cdr
     3725                || bkpinfo->backup_media_type == cdrw)) {
     3726            if (find_cdrom_device(tmp, FALSE))  // make sure find_cdrom_device() finds, records CD-R's loc
     3727            {
     3728                log_msg(3, "*Sigh* Mike, I hate your computer.");
     3729                bkpinfo->manual_cd_tray = TRUE;
     3730            }                   // if it can't be found then force pausing
     3731            else {
     3732                log_msg(3, "Great. Found Mike's CD-ROM drive.");
     3733            }
     3734        }
     3735        if (bkpinfo->verify_data && !res) {
     3736            log_to_screen
     3737                ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
     3738                 media_descriptor_string(g_backup_media_type));
     3739            chdir("/");
     3740            iamhere("Before calling verify_cd_image()");
     3741            res += verify_cd_image(bkpinfo);
     3742            iamhere("After calling verify_cd_image()");
     3743        }
     3744        if (!res) {
     3745            that_one_was_ok = TRUE;
     3746        } else {
     3747            sprintf(tmp, "Failed to burn %s #%d. Retry?",
     3748                    media_descriptor_string(bkpinfo->backup_media_type),
     3749                    g_current_media_number);
     3750            res = ask_me_yes_or_no(tmp);
     3751            if (!res) {
     3752                if (ask_me_yes_or_no("Abort the backup?")) {
     3753                    fatal_error("FAILED TO BACKUP");
     3754                } else {
     3755                    break;
     3756                }
     3757            } else {
     3758                log_msg(2, "Retrying, at user's request...");
     3759                res = 0;
     3760            }
     3761        }
     3762    }
    36773763/*
    36783764  if (using_nfs)
     
    36833769    }
    36843770*/
    3685   g_current_media_number++;
    3686   if (g_current_media_number > MAX_NOOF_MEDIA) { fatal_error("Too many CD-R(W)'s. Use tape or net."); }
    3687   wipe_archives (bkpinfo->scratchdir);
    3688   sprintf (tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
    3689        bkpinfo->scratchdir, bkpinfo->scratchdir);
    3690   if (system (tmp))
    3691     {
    3692       log_msg
    3693     (2, "Error occurred when I tried to delete the redundant IMGs and GZs");
    3694     }
    3695 
    3696   if (last_cd)
    3697     {
    3698       log_msg (2, "This was your last CD.");
    3699     }
    3700   else
    3701     {
    3702       log_msg (2, "Continuing to backup your data...");
    3703     }
    3704 
    3705   bkpinfo->verify_data = orig_vfy_flag_val;
    3706   paranoid_free(tmp);
    3707   paranoid_free(cdno_fname);
    3708   paranoid_free(lastcd_fname);
    3709   paranoid_free(isofile);
    3710   return (0);
     3771    g_current_media_number++;
     3772    if (g_current_media_number > MAX_NOOF_MEDIA) {
     3773        fatal_error("Too many CD-R(W)'s. Use tape or net.");
     3774    }
     3775    wipe_archives(bkpinfo->scratchdir);
     3776    sprintf(tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
     3777            bkpinfo->scratchdir, bkpinfo->scratchdir);
     3778    if (system(tmp)) {
     3779        log_msg
     3780            (2,
     3781             "Error occurred when I tried to delete the redundant IMGs and GZs");
     3782    }
     3783
     3784    if (last_cd) {
     3785        log_msg(2, "This was your last CD.");
     3786    } else {
     3787        log_msg(2, "Continuing to backup your data...");
     3788    }
     3789
     3790    bkpinfo->verify_data = orig_vfy_flag_val;
     3791    paranoid_free(tmp);
     3792    paranoid_free(cdno_fname);
     3793    paranoid_free(lastcd_fname);
     3794    paranoid_free(isofile);
     3795    return (0);
    37113796}
    37123797
     
    37293814int verify_data(struct s_bkpinfo *bkpinfo)
    37303815{
    3731     int res=0, retval=0, cdno=0;
    3732     char *tmp;
    3733     long diffs=0;
    3734 
    3735   malloc_string(tmp);
    3736   assert(bkpinfo!=NULL); 
    3737       if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
     3816    int res = 0, retval = 0, cdno = 0;
     3817    char *tmp;
     3818    long diffs = 0;
     3819
     3820    malloc_string(tmp);
     3821    assert(bkpinfo != NULL);
     3822    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3823        chdir("/");
     3824        mvaddstr_and_log_it(g_currentY, 0,
     3825                            "Verifying archives against live filesystem");
     3826        if (bkpinfo->backup_media_type == cdstream) {
     3827            strcpy(bkpinfo->media_device, "/dev/cdrom");
     3828        }
     3829        verify_tape_backups(bkpinfo);
     3830        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     3831    } else if (bkpinfo->backup_data)
     3832        //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
    37383833    {
    3739       chdir ("/");
    3740       mvaddstr_and_log_it (g_currentY, 0,
    3741                    "Verifying archives against live filesystem");
    3742       if (bkpinfo->backup_media_type == cdstream)
    3743         {
    3744           strcpy (bkpinfo->media_device, "/dev/cdrom");
    3745         }
    3746       verify_tape_backups (bkpinfo);
    3747       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    3748     }
    3749       else if (bkpinfo->backup_data)
    3750     //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
    3751         {
    3752           log_msg (2, "Not verifying again. Per-CD/ISO verification already carried out.");
    3753           paranoid_system("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
    3754         }
    3755       else
    3756     {
    3757           g_current_media_number = cdno;
    3758       if (bkpinfo->backup_media_type != iso)
    3759         {
    3760           find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom
    3761         }
    3762       chdir ("/");
    3763       for (cdno = 1;
    3764            cdno < 99 && bkpinfo->verify_data;
    3765            cdno++)
    3766         {
    3767           if (cdno != g_current_media_number)
    3768             {
    3769           log_msg (2, "Warning - had to change g_current_media_number from %d to %d", g_current_media_number, cdno);
    3770           g_current_media_number = cdno;
    3771         }       
    3772           if (bkpinfo->backup_media_type != iso)
    3773         {
    3774           insist_on_this_cd_number (bkpinfo, cdno);
    3775         }
    3776           res = verify_cd_image (bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
    3777           retval += res;
    3778           if (res)
    3779         {
    3780           sprintf (tmp,
    3781                "Warnings/errors were reported while checking %s #%d",
    3782                media_descriptor_string(bkpinfo->backup_media_type),
    3783                g_current_media_number);
    3784           log_to_screen (tmp);
    3785 
    3786         }
    3787         }
     3834        log_msg(2,
     3835                "Not verifying again. Per-CD/ISO verification already carried out.");
     3836        paranoid_system
     3837            ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
     3838    } else {
     3839        g_current_media_number = cdno;
     3840        if (bkpinfo->backup_media_type != iso) {
     3841            find_cdrom_device(bkpinfo->media_device, FALSE);    // replace 0,0,0 with /dev/cdrom
     3842        }
     3843        chdir("/");
     3844        for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
     3845            if (cdno != g_current_media_number) {
     3846                log_msg(2,
     3847                        "Warning - had to change g_current_media_number from %d to %d",
     3848                        g_current_media_number, cdno);
     3849                g_current_media_number = cdno;
     3850            }
     3851            if (bkpinfo->backup_media_type != iso) {
     3852                insist_on_this_cd_number(bkpinfo, cdno);
     3853            }
     3854            res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
     3855            retval += res;
     3856            if (res) {
     3857                sprintf(tmp,
     3858                        "Warnings/errors were reported while checking %s #%d",
     3859                        media_descriptor_string(bkpinfo->
     3860                                                backup_media_type),
     3861                        g_current_media_number);
     3862                log_to_screen(tmp);
     3863
     3864            }
     3865        }
    37883866/*
    37893867      sprintf (tmp,
     
    37923870      system (tmp);
    37933871*/
    3794           sprintf (tmp,
    3795        "sed -n -e 's/afio: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
    3796        MONDO_LOGFILE);
    3797       system (tmp);
    3798          
    3799       sprintf (tmp,
    3800        "sed -n -e 's/star: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
    3801        MONDO_LOGFILE);
    3802       system (tmp);
    3803           run_program_and_log_output("umount "MNT_CDROM, FALSE);
    3804 //    if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
     3872        sprintf(tmp,
     3873                "sed -n -e 's/afio: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
     3874                MONDO_LOGFILE);
     3875        system(tmp);
     3876
     3877        sprintf(tmp,
     3878                "sed -n -e 's/star: //p' %s | grep -vx '/dev/.*' >> /tmp/changed.files",
     3879                MONDO_LOGFILE);
     3880        system(tmp);
     3881        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3882//    if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
    38053883//{
    3806           eject_device(bkpinfo->media_device);
     3884        eject_device(bkpinfo->media_device);
    38073885//}
    38083886    }
    3809       diffs = count_lines_in_file ("/tmp/changed.files");
    3810 
    3811       if (diffs > 0)
    3812     {
    3813           if (retval==0) { retval=(int)(-diffs); }
    3814     }
    3815   paranoid_free(tmp);
    3816  return(retval);
     3887    diffs = count_lines_in_file("/tmp/changed.files");
     3888
     3889    if (diffs > 0) {
     3890        if (retval == 0) {
     3891            retval = (int) (-diffs);
     3892        }
     3893    }
     3894    paranoid_free(tmp);
     3895    return (retval);
    38173896}
    38183897
     
    38323911 * @see write_image_to_floppy
    38333912 */
    3834 int
    3835 write_image_to_floppy_SUB (char *device, char *datafile)
     3913int write_image_to_floppy_SUB(char *device, char *datafile)
    38363914{
    3837     /*@ int ****************************************************************/
    3838   int res = 0;
     3915    /*@ int *************************************************************** */
     3916    int res = 0;
    38393917    int percentage = 0;
    38403918    int blockno = 0;
    3841     int maxblocks =0;
    3842 
    3843     /*@ buffers*************************************************************/
    3844   char *tmp;
     3919    int maxblocks = 0;
     3920
     3921    /*@ buffers************************************************************ */
     3922    char *tmp;
    38453923    char blk[1024];
    38463924    char *title;
    38473925
    3848     /*@ pointers ***********************************************************/
     3926    /*@ pointers ********************************************************** */
    38493927    char *p;
    3850   FILE *fout, *fin;
    3851 
    3852 
    3853   malloc_string(tmp);
    3854   malloc_string(title);
    3855   /* pretty stuff */
    3856   if (!(p = strrchr (datafile, '/')))
    3857     {
    3858       p = datafile;
    3859     }
    3860   else
    3861     {
    3862       p++;
    3863     }
    3864   sprintf (title, "Writing %s to floppy", p);
    3865   open_evalcall_form (title);
    3866   /* functional stuff */
    3867   for (p = device + strlen (device); p != device && isdigit (*(p - 1)); p--);
    3868   maxblocks = atoi (p);
    3869   if (!maxblocks) { maxblocks = 1440; }
    3870   sprintf (tmp, "maxblocks = %d; p=%s", maxblocks, p);
    3871   log_msg (2, tmp);
    3872   /* copy data from image to floppy */
    3873   if (!(fin = fopen (datafile, "r")))
    3874     {
    3875       log_OS_error ("Cannot open img");
    3876       return (1);
    3877     }
    3878   if (!(fout = fopen (device, "w")))
    3879     {
    3880       log_OS_error ("Cannot open fdd");
    3881       return (1);
    3882     }
    3883   for (blockno = 0; blockno < maxblocks; blockno++)
    3884     {
    3885       percentage = blockno * 100 / maxblocks;
    3886       if (fread (blk, 1, 1024, fin) != 1024)
    3887     {
    3888       if (feof(fin))
    3889         {
    3890           log_msg(1, "img read err - img ended prematurely - non-fatal error");
    3891           sleep(3);
    3892           return(res);
    3893         }
    3894       res++;
    3895       log_to_screen ("img read err");
    3896     }
    3897       if (fwrite (blk, 1, 1024, fout) != 1024)
    3898     {
    3899       res++;
    3900       log_to_screen ("fdd write err");
    3901     }
    3902       if (((blockno + 1) % 128) == 0)
    3903     {
    3904       paranoid_system ("sync"); /* fflush doesn't work; dunno why */
    3905       update_evalcall_form (percentage);
    3906     }
    3907     }
    3908   paranoid_fclose (fin);
    3909   paranoid_fclose(fout);
    3910   paranoid_free(tmp);
    3911   paranoid_free(title);
    3912   close_evalcall_form ();
    3913   return (res);
     3928    FILE *fout, *fin;
     3929
     3930
     3931    malloc_string(tmp);
     3932    malloc_string(title);
     3933    /* pretty stuff */
     3934    if (!(p = strrchr(datafile, '/'))) {
     3935        p = datafile;
     3936    } else {
     3937        p++;
     3938    }
     3939    sprintf(title, "Writing %s to floppy", p);
     3940    open_evalcall_form(title);
     3941    /* functional stuff */
     3942    for (p = device + strlen(device); p != device && isdigit(*(p - 1));
     3943         p--);
     3944    maxblocks = atoi(p);
     3945    if (!maxblocks) {
     3946        maxblocks = 1440;
     3947    }
     3948    sprintf(tmp, "maxblocks = %d; p=%s", maxblocks, p);
     3949    log_msg(2, tmp);
     3950    /* copy data from image to floppy */
     3951    if (!(fin = fopen(datafile, "r"))) {
     3952        log_OS_error("Cannot open img");
     3953        return (1);
     3954    }
     3955    if (!(fout = fopen(device, "w"))) {
     3956        log_OS_error("Cannot open fdd");
     3957        return (1);
     3958    }
     3959    for (blockno = 0; blockno < maxblocks; blockno++) {
     3960        percentage = blockno * 100 / maxblocks;
     3961        if (fread(blk, 1, 1024, fin) != 1024) {
     3962            if (feof(fin)) {
     3963                log_msg(1,
     3964                        "img read err - img ended prematurely - non-fatal error");
     3965                sleep(3);
     3966                return (res);
     3967            }
     3968            res++;
     3969            log_to_screen("img read err");
     3970        }
     3971        if (fwrite(blk, 1, 1024, fout) != 1024) {
     3972            res++;
     3973            log_to_screen("fdd write err");
     3974        }
     3975        if (((blockno + 1) % 128) == 0) {
     3976            paranoid_system("sync");    /* fflush doesn't work; dunno why */
     3977            update_evalcall_form(percentage);
     3978        }
     3979    }
     3980    paranoid_fclose(fin);
     3981    paranoid_fclose(fout);
     3982    paranoid_free(tmp);
     3983    paranoid_free(title);
     3984    close_evalcall_form();
     3985    return (res);
    39143986}
    39153987
     
    39284000 * @see write_image_to_floppy_SUB
    39294001 */
    3930 int
    3931 write_image_to_floppy (char *device, char *datafile)
     4002int write_image_to_floppy(char *device, char *datafile)
    39324003{
    3933     /*@ int ***************************************************************/
    3934   int res   = 0;
    3935 
    3936   assert_string_is_neither_NULL_nor_zerolength(device);
    3937   assert_string_is_neither_NULL_nor_zerolength(datafile);
    3938 
    3939   while ((res = write_image_to_floppy_SUB (device, datafile)))
    3940     {
    3941       if (!ask_me_yes_or_no ("Failed to write image to floppy. Retry?"))
    3942     {
    3943       return (res);
    3944     }
    3945     }
    3946   return (res);
     4004    /*@ int ************************************************************** */
     4005    int res = 0;
     4006
     4007    assert_string_is_neither_NULL_nor_zerolength(device);
     4008    assert_string_is_neither_NULL_nor_zerolength(datafile);
     4009
     4010    while ((res = write_image_to_floppy_SUB(device, datafile))) {
     4011        if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
     4012            return (res);
     4013        }
     4014    }
     4015    return (res);
    39474016}
    39484017
    39494018/* @} - end of utilityGroup */
    3950 
  • branches/2.05/mondo/mondo/common/libmondo-archive.h

    r30 r128  
    11/* libmondo-archive.h
    2  * $Id: libmondo-archive.h,v 1.3 2004/06/17 08:49:06 hugo Exp $
     2 * $Id$
    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);
  • branches/2.05/mondo/mondo/common/libmondo-devices-EXT.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-devices.c

    r126 r128  
    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
     
    262262extern char *g_selfmounted_isodir;
    263263
    264 static char g_cdrw_drive_is_here[MAX_STR_LEN/4]="";
    265 static char g_cdrom_drive_is_here[MAX_STR_LEN/4]="";
    266 static char g_dvd_drive_is_here[MAX_STR_LEN/4]="";
     264static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = "";
     265static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = "";
     266static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = "";
    267267
    268268
     
    271271 * @ingroup globalGroup
    272272 */
    273 bool g_restoring_live_from_cd=FALSE;
    274 
    275 extern t_bkptype g_backup_media_type; // set by main()
     273bool g_restoring_live_from_cd = FALSE;
     274
     275extern t_bkptype g_backup_media_type;   // set by main()
    276276
    277277
     
    280280void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo)
    281281{
    282   strcpy(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case
    283   strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
     282    strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
     283    strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
    284284}
    285285
     
    293293{
    294294//  log_it("rctada: Retracting all CD trays", __LINE__);
    295   if (strlen(g_cdrom_drive_is_here)>0)
    296     { inject_device(g_cdrom_drive_is_here); }
    297   if (strlen(g_dvd_drive_is_here)>0)
    298     { inject_device(g_dvd_drive_is_here); }
    299   if (strlen(g_cdrw_drive_is_here)>0)
    300     { inject_device(g_cdrw_drive_is_here); }
     295    if (strlen(g_cdrom_drive_is_here) > 0) {
     296        inject_device(g_cdrom_drive_is_here);
     297    }
     298    if (strlen(g_dvd_drive_is_here) > 0) {
     299        inject_device(g_dvd_drive_is_here);
     300    }
     301    if (strlen(g_cdrw_drive_is_here) > 0) {
     302        inject_device(g_cdrw_drive_is_here);
     303    }
    301304//  log_it("rctada: killing autorun");
    302305//  run_program_and_log_output("killall autorun", TRUE);
    303   if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5))
    304     {
    305       log_it("autorun detected; sleeping for 2 seconds");
    306       sleep(2);
    307     }
    308   log_it("rctada: Unmounting all CD drives", __LINE__);
    309   run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
     306    if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) {
     307        log_it("autorun detected; sleeping for 2 seconds");
     308        sleep(2);
     309    }
     310    log_it("rctada: Unmounting all CD drives", __LINE__);
     311    run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
    310312}
    311313
     
    317319 * @ingroup utilityGroup
    318320 */
    319 bool
    320 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, "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);
     321bool am_I_in_disaster_recovery_mode(void)
     322{
     323    char *tmp, *comment;
     324    bool is_this_a_ramdisk = FALSE;
     325
     326    malloc_string(tmp);
     327    malloc_string(comment);
     328    strcpy(tmp, where_is_root_mounted());
     329    sprintf(comment, "root is mounted at %s\n", tmp);
     330    log_msg(0, comment);
     331    log_msg(0,
     332            "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().",
     333            tmp);
    331334
    332335#ifdef __FreeBSD__
    333   if (strstr(tmp, "/dev/md"))
    334     {
    335       is_this_a_ramdisk = TRUE;
    336     }
     336    if (strstr(tmp, "/dev/md")) {
     337        is_this_a_ramdisk = TRUE;
     338    }
    337339#else
    338   if (!strncmp(tmp, "/dev/ram", 8) || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/") && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
    339     || !strcmp(tmp, "/dev/root"))
    340     { is_this_a_ramdisk = TRUE; }
    341   else
    342     { is_this_a_ramdisk = FALSE; }
    343 #endif
    344 
    345   if (is_this_a_ramdisk)
    346     {
    347       if (!does_file_exist("/THIS-IS-A-RAMDISK") && !does_file_exist("/tmp/mountlist.txt.sample"))
    348         {
    349           log_to_screen("Using /dev/root is stupid of you but I'll forgive you.");
    350           is_this_a_ramdisk = FALSE;
    351         }
    352     }
    353   if (does_file_exist("/THIS-IS-A-RAMDISK"))
    354     {
    355       is_this_a_ramdisk = TRUE;
    356     }
    357   paranoid_free(tmp);
    358   paranoid_free(comment);
    359   log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
    360   return(is_this_a_ramdisk);
     340    if (!strncmp(tmp, "/dev/ram", 8)
     341        || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/")
     342            && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
     343        || !strcmp(tmp, "/dev/root")) {
     344        is_this_a_ramdisk = TRUE;
     345    } else {
     346        is_this_a_ramdisk = FALSE;
     347    }
     348#endif
     349
     350    if (is_this_a_ramdisk) {
     351        if (!does_file_exist("/THIS-IS-A-RAMDISK")
     352            && !does_file_exist("/tmp/mountlist.txt.sample")) {
     353            log_to_screen
     354                ("Using /dev/root is stupid of you but I'll forgive you.");
     355            is_this_a_ramdisk = FALSE;
     356        }
     357    }
     358    if (does_file_exist("/THIS-IS-A-RAMDISK")) {
     359        is_this_a_ramdisk = TRUE;
     360    }
     361    paranoid_free(tmp);
     362    paranoid_free(comment);
     363    log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
     364    return (is_this_a_ramdisk);
    361365}
    362366
     
    373377static char *bkptype_to_string(t_bkptype bt)
    374378{
    375   static char output[MAX_STR_LEN/4];
    376   switch(bt)
    377     {
    378     case none: strcpy(output, "none");
     379    static char output[MAX_STR_LEN / 4];
     380    switch (bt) {
     381    case none:
     382        strcpy(output, "none");
    379383        break;
    380     case iso:  strcpy(output, "iso");
     384    case iso:
     385        strcpy(output, "iso");
    381386        break;
    382     case cdr:  strcpy(output, "cdr");
     387    case cdr:
     388        strcpy(output, "cdr");
    383389        break;
    384     case cdrw: strcpy(output, "cdrw");
     390    case cdrw:
     391        strcpy(output, "cdrw");
    385392        break;
    386     case cdstream: strcpy(output, "cdstream");
     393    case cdstream:
     394        strcpy(output, "cdstream");
    387395        break;
    388     case nfs:  strcpy(output, "nfs");
     396    case nfs:
     397        strcpy(output, "nfs");
    389398        break;
    390     case tape: strcpy(output, "tape");
     399    case tape:
     400        strcpy(output, "tape");
    391401        break;
    392     case udev: strcpy(output, "udev");
     402    case udev:
     403        strcpy(output, "udev");
    393404        break;
    394     default: strcpy(output, "default");
    395     }
    396   return(output);
     405    default:
     406        strcpy(output, "default");
     407    }
     408    return (output);
    397409}
    398410
     
    408420 * @return the return value of the @c eject command. (0=success, nonzero=failure)
    409421 */
    410 int eject_device(char*dev)
    411 {
    412   char *command;
    413   int res1=0, res2=0;
    414 
    415   malloc_string(command);
    416 
    417   if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) && g_backup_media_type!=udev)
    418     {
    419       sprintf(command, "mt -f %s offline", dev);
    420       res1 = run_program_and_log_output(command, 1);
    421     }
    422   else
    423     {
    424       res1 = 0;
    425     }
     422int eject_device(char *dev)
     423{
     424    char *command;
     425    int res1 = 0, res2 = 0;
     426
     427    malloc_string(command);
     428
     429    if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
     430        && g_backup_media_type != udev) {
     431        sprintf(command, "mt -f %s offline", dev);
     432        res1 = run_program_and_log_output(command, 1);
     433    } else {
     434        res1 = 0;
     435    }
    426436
    427437#ifdef __FreeBSD__
    428   if (strstr (dev, "acd")) {
    429       sprintf (command, "cdcontrol -f %s eject", dev);
    430   } else {
    431       sprintf (command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev);
    432   }
     438    if (strstr(dev, "acd")) {
     439        sprintf(command, "cdcontrol -f %s eject", dev);
     440    } else {
     441        sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`",
     442                dev);
     443    }
    433444#else
    434   sprintf(command, "eject %s", dev);
    435 #endif
    436 
    437   log_msg(3, "Ejecting %s", dev);
    438   res2 = run_program_and_log_output(command, 1);
    439   paranoid_free(command);
    440   if (res1 && res2) { return(1); }
    441   else { return(0); }
     445    sprintf(command, "eject %s", dev);
     446#endif
     447
     448    log_msg(3, "Ejecting %s", dev);
     449    res2 = run_program_and_log_output(command, 1);
     450    paranoid_free(command);
     451    if (res1 && res2) {
     452        return (1);
     453    } else {
     454        return (0);
     455    }
    442456}
    443457
     
    447461 * @return 0 for success, nonzero for failure.
    448462 */
    449 int inject_device(char*dev)
    450 {
    451   char *command;
    452   int i;
    453 
    454   malloc_string(command);
     463int inject_device(char *dev)
     464{
     465    char *command;
     466    int i;
     467
     468    malloc_string(command);
    455469
    456470
    457471#ifdef __FreeBSD__
    458   if (strstr (dev, "acd")) {
    459       sprintf (command, "cdcontrol -f %s close", dev);
    460   } else {
    461       sprintf (command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev);
    462   }
     472    if (strstr(dev, "acd")) {
     473        sprintf(command, "cdcontrol -f %s close", dev);
     474    } else {
     475        sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`",
     476                dev);
     477    }
    463478#else
    464   sprintf(command, "eject -t %s", dev);
    465 #endif
    466   i = run_program_and_log_output(command, FALSE);
    467   paranoid_free(command);
    468   return(i);
     479    sprintf(command, "eject -t %s", dev);
     480#endif
     481    i = run_program_and_log_output(command, FALSE);
     482    paranoid_free(command);
     483    return (i);
    469484}
    470485
     
    475490 * @return TRUE if it exists, FALSE if it doesn't.
    476491 */
    477 bool
    478 does_device_exist (char *device)
    479 {
    480 
    481     /*@ buffers ************************************************************/
    482   char *tmp;
    483   bool ret;
    484 
    485   malloc_string(tmp);
    486   assert_string_is_neither_NULL_nor_zerolength(device);
    487 
    488   sprintf (tmp, "ls %s > /dev/null 2> /dev/null", device);
    489  
    490   if (system (tmp))
    491     {
    492       ret = FALSE;
    493     }
    494   else
    495     {
    496       ret = TRUE;
    497     }
    498   paranoid_free(tmp);
    499   return(ret);
     492bool does_device_exist(char *device)
     493{
     494
     495    /*@ buffers *********************************************************** */
     496    char *tmp;
     497    bool ret;
     498
     499    malloc_string(tmp);
     500    assert_string_is_neither_NULL_nor_zerolength(device);
     501
     502    sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
     503
     504    if (system(tmp)) {
     505        ret = FALSE;
     506    } else {
     507        ret = TRUE;
     508    }
     509    paranoid_free(tmp);
     510    return (ret);
    500511}
    501512
     
    505516 * @return TRUE (there's a Linux/FreeBSD partition) or FALSE (Microsoft has taken over yet another innocent PC).
    506517 */
    507 bool
    508 does_nonMS_partition_exist (void)
     518bool does_nonMS_partition_exist(void)
    509519{
    510520#if __FreeBSD__
    511     return !system ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
     521    return
     522        !system
     523        ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
    512524#else
    513     return !system ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | egrep -qv '(MS|DOS|FAT|NTFS)'");
     525    return
     526        !system
     527        ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | egrep -qv '(MS|DOS|FAT|NTFS)'");
    514528#endif
    515529}
     
    521535 * @return 0 if it exists, nonzero otherwise.
    522536 */
    523 int
    524 does_partition_exist (const char *drive, int partno)
    525 {
    526     /*@ buffers *****************************************************/
    527   char *program;
    528   char *incoming;
    529   char *searchstr;
    530   char *tmp;
    531 
    532     /*@ ints ********************************************************/
    533   int res = 0;
    534 
    535     /*@ pointers ****************************************************/
    536   FILE *fin;
    537 
    538 
    539     /*@ end vars ****************************************************/
    540   assert_string_is_neither_NULL_nor_zerolength(drive);
    541   assert(partno>=0 && partno<999);
    542 
    543   malloc_string(program);
    544   malloc_string(incoming);
    545   malloc_string(searchstr);
    546   malloc_string(tmp);
     537int does_partition_exist(const char *drive, int partno)
     538{
     539    /*@ buffers **************************************************** */
     540    char *program;
     541    char *incoming;
     542    char *searchstr;
     543    char *tmp;
     544
     545    /*@ ints ******************************************************* */
     546    int res = 0;
     547
     548    /*@ pointers *************************************************** */
     549    FILE *fin;
     550
     551
     552    /*@ end vars *************************************************** */
     553    assert_string_is_neither_NULL_nor_zerolength(drive);
     554    assert(partno >= 0 && partno < 999);
     555
     556    malloc_string(program);
     557    malloc_string(incoming);
     558    malloc_string(searchstr);
     559    malloc_string(tmp);
    547560
    548561#ifdef __FreeBSD__
    549   // We assume here that this is running from mondorestore. (It is.)
    550   sprintf (program, "ls %s >/dev/null 2>&1", drive, build_partition_name (tmp, drive, partno));
    551   return system (program);
     562    // We assume here that this is running from mondorestore. (It is.)
     563    sprintf(program, "ls %s >/dev/null 2>&1", drive,
     564            build_partition_name(tmp, drive, partno));
     565    return system(program);
    552566#else
    553   tmp[0] = '\0';
    554 #endif
    555 
    556   sprintf (program, "parted2fdisk -l %s 2> /dev/null", drive);
    557   fin = popen (program, "r");
    558   if (!fin)
    559     {
    560       log_it("program=%s", program);
    561       log_OS_error("Cannot popen-in program");
    562       return (0);
    563     }
    564   (void) build_partition_name (searchstr, drive, partno);
    565   strcat(searchstr, " ");
    566   for (res = 0; !res && fgets (incoming, MAX_STR_LEN - 1, fin); )
    567     {
    568       if (strstr (incoming, searchstr))
    569     {
    570       res = 1;
    571     }
    572     }
    573   if (pclose (fin)) { log_OS_error("Cannot pclose fin"); }
    574   paranoid_free(program);
    575   paranoid_free(incoming);
    576   paranoid_free(searchstr);
    577   paranoid_free(tmp);
    578   return (res);
     567    tmp[0] = '\0';
     568#endif
     569
     570    sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
     571    fin = popen(program, "r");
     572    if (!fin) {
     573        log_it("program=%s", program);
     574        log_OS_error("Cannot popen-in program");
     575        return (0);
     576    }
     577    (void) build_partition_name(searchstr, drive, partno);
     578    strcat(searchstr, " ");
     579    for (res = 0; !res && fgets(incoming, MAX_STR_LEN - 1, fin);) {
     580        if (strstr(incoming, searchstr)) {
     581            res = 1;
     582        }
     583    }
     584    if (pclose(fin)) {
     585        log_OS_error("Cannot pclose fin");
     586    }
     587    paranoid_free(program);
     588    paranoid_free(incoming);
     589    paranoid_free(searchstr);
     590    paranoid_free(tmp);
     591    return (res);
    579592}
    580593
     
    589602 * @return TRUE if it exists, FALSE if it doesn't.
    590603 */
    591 bool
    592 does_string_exist_in_boot_block (char *dev, char *str)
    593 {
    594     /*@ buffers *****************************************************/
    595   char *command;
    596 
    597     /*@ end vars ****************************************************/
    598   int i;
    599 
    600   assert_string_is_neither_NULL_nor_zerolength(dev);
    601   assert_string_is_neither_NULL_nor_zerolength(str);
    602 
    603   malloc_string(command);
    604   sprintf (command,
    605        "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    606        dev, str);
    607   i = system(command);
    608   paranoid_free(command);
    609   if (i)
    610     {
    611       return (FALSE);
    612     }
    613   else
    614     {
    615       return (TRUE);
    616     }
     604bool does_string_exist_in_boot_block(char *dev, char *str)
     605{
     606    /*@ buffers **************************************************** */
     607    char *command;
     608
     609    /*@ end vars *************************************************** */
     610    int i;
     611
     612    assert_string_is_neither_NULL_nor_zerolength(dev);
     613    assert_string_is_neither_NULL_nor_zerolength(str);
     614
     615    malloc_string(command);
     616    sprintf(command,
     617            "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
     618            dev, str);
     619    i = system(command);
     620    paranoid_free(command);
     621    if (i) {
     622        return (FALSE);
     623    } else {
     624        return (TRUE);
     625    }
    617626}
    618627
     
    624633 * @param n The number of 512-byte sectors to search.
    625634 */
    626 bool
    627 does_string_exist_in_first_N_blocks (char *dev, char *str, int n)
    628 {
    629       /*@ buffers *****************************************************/
    630   char *command;
    631       /*@ end vars ****************************************************/
    632   int i;
    633 
    634   malloc_string(command);
    635   sprintf (command,
    636          "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    637          dev, n, str);
    638   i = system(command);
    639   paranoid_free(command);
    640   if (i)
    641     {
    642       return (FALSE);
    643     }
    644   else
    645     {
    646       return (TRUE);
    647     }
     635bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n)
     636{
     637    /*@ buffers **************************************************** */
     638    char *command;
     639    /*@ end vars *************************************************** */
     640    int i;
     641
     642    malloc_string(command);
     643    sprintf(command,
     644            "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
     645            dev, n, str);
     646    i = system(command);
     647    paranoid_free(command);
     648    if (i) {
     649        return (FALSE);
     650    } else {
     651        return (TRUE);
     652    }
    648653}
    649654
     
    658663 * @see mount_CDROM_here
    659664 */
    660 int
    661 find_and_mount_actual_cd (struct s_bkpinfo *bkpinfo, char *mountpoint)
    662 {
    663     /*@ buffers ******************************************************/
    664 
    665     /*@ int's  *******************************************************/
    666   int res;
    667   char *dev;
    668 
    669     /*@ end vars *****************************************************/
    670 
    671   malloc_string(dev);
    672   assert(bkpinfo!=NULL);
    673   assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    674 
    675   if (g_backup_media_type == dvd)
    676     {
    677       strcpy(dev, g_dvd_drive_is_here);
    678       if (!dev[0])
    679         { find_dvd_device(dev,FALSE); }
    680     }
    681   else
    682     {
    683       strcpy(dev, g_cdrom_drive_is_here);
    684       if (!dev[0])
    685         { find_cdrom_device(dev,FALSE); }
    686     }
    687 
    688   if (bkpinfo->backup_media_type != iso)
    689     { retract_CD_tray_and_defeat_autorun(); }
    690 
    691   if (!dev[0] || (res=mount_CDROM_here (dev, mountpoint)))
    692     {
    693       if (!popup_and_get_string
     665int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint)
     666{
     667    /*@ buffers ***************************************************** */
     668
     669    /*@ int's  ****************************************************** */
     670    int res;
     671    char *dev;
     672
     673    /*@ end vars **************************************************** */
     674
     675    malloc_string(dev);
     676    assert(bkpinfo != NULL);
     677    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     678
     679    if (g_backup_media_type == dvd) {
     680        strcpy(dev, g_dvd_drive_is_here);
     681        if (!dev[0]) {
     682            find_dvd_device(dev, FALSE);
     683        }
     684    } else {
     685        strcpy(dev, g_cdrom_drive_is_here);
     686        if (!dev[0]) {
     687            find_cdrom_device(dev, FALSE);
     688        }
     689    }
     690
     691    if (bkpinfo->backup_media_type != iso) {
     692        retract_CD_tray_and_defeat_autorun();
     693    }
     694
     695    if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
     696        if (!popup_and_get_string
    694697            ("CD-ROM device", "Please enter your CD-ROM's /dev device",
    695             dev, MAX_STR_LEN/4))
    696     { res = 1; }
    697       else
    698     { res=mount_CDROM_here (dev, mountpoint); }
    699     }
    700   if (res) { log_msg(1, "mount failed"); }
    701   else { log_msg(1, "mount succeeded with %s", dev); }
    702   paranoid_free(dev);
    703   return (res);
     698             dev, MAX_STR_LEN / 4)) {
     699            res = 1;
     700        } else {
     701            res = mount_CDROM_here(dev, mountpoint);
     702        }
     703    }
     704    if (res) {
     705        log_msg(1, "mount failed");
     706    } else {
     707        log_msg(1, "mount succeeded with %s", dev);
     708    }
     709    paranoid_free(dev);
     710    return (res);
    704711}
    705712
     
    720727 * @return 0 for success, nonzero for failure.
    721728 */
    722 int
    723 find_cdrw_device (char *cdrw_device)
    724 {
    725     /*@ buffers *************************/
    726   char *comment;
    727   char *tmp;
    728   char *cdr_exe;
    729   char *command;
    730 
    731   malloc_string(comment);
    732   malloc_string(tmp);
    733   malloc_string(cdr_exe);
    734   malloc_string(command);
    735   if (g_cdrw_drive_is_here[0])
    736     {
    737       strcpy(cdrw_device, g_cdrw_drive_is_here);
    738       log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    739   paranoid_free(comment);
    740   paranoid_free(tmp);
    741   paranoid_free(cdr_exe);
    742   paranoid_free(command);
    743       return(0);
    744     }
    745   if (g_backup_media_type == dvd)
    746     {
    747       log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    748   paranoid_free(comment);
    749   paranoid_free(tmp);
    750   paranoid_free(cdr_exe);
    751   paranoid_free(command);
    752       return(1);
    753     }
    754   run_program_and_log_output("insmod ide-scsi", -1);
    755   if (find_home_of_exe("cdrecord"))
    756     { strcpy(cdr_exe, "cdrecord"); }
    757   else
    758     { strcpy(cdr_exe, "dvdrecord"); }
    759   tmp[0]='\0';
    760   if (find_home_of_exe(cdr_exe))
    761     {
    762       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);
    763       strcpy (tmp, call_program_and_get_last_line_of_output(command));
    764     }
    765   if (strlen (tmp) < 2)
    766     {
    767   paranoid_free(comment);
    768   paranoid_free(tmp);
    769   paranoid_free(cdr_exe);
    770   paranoid_free(command);
    771       return 1;
    772     }
    773   else
    774     {
    775       strcpy (cdrw_device, tmp);
    776       sprintf (comment, "Found CDRW device - %s", cdrw_device);
    777       log_it (comment);
    778       strcpy (g_cdrw_drive_is_here, cdrw_device);
    779       paranoid_free(comment);
    780       paranoid_free(tmp);
    781       paranoid_free(cdr_exe);
    782       paranoid_free(command);
    783       return (0);
    784     }
     729int find_cdrw_device(char *cdrw_device)
     730{
     731    /*@ buffers ************************ */
     732    char *comment;
     733    char *tmp;
     734    char *cdr_exe;
     735    char *command;
     736
     737    malloc_string(comment);
     738    malloc_string(tmp);
     739    malloc_string(cdr_exe);
     740    malloc_string(command);
     741    if (g_cdrw_drive_is_here[0]) {
     742        strcpy(cdrw_device, g_cdrw_drive_is_here);
     743        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
     744        paranoid_free(comment);
     745        paranoid_free(tmp);
     746        paranoid_free(cdr_exe);
     747        paranoid_free(command);
     748        return (0);
     749    }
     750    if (g_backup_media_type == dvd) {
     751        log_msg(1,
     752                "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
     753        paranoid_free(comment);
     754        paranoid_free(tmp);
     755        paranoid_free(cdr_exe);
     756        paranoid_free(command);
     757        return (1);
     758    }
     759    run_program_and_log_output("insmod ide-scsi", -1);
     760    if (find_home_of_exe("cdrecord")) {
     761        strcpy(cdr_exe, "cdrecord");
     762    } else {
     763        strcpy(cdr_exe, "dvdrecord");
     764    }
     765    tmp[0] = '\0';
     766    if (find_home_of_exe(cdr_exe)) {
     767        sprintf(command,
     768                "%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",
     769                cdr_exe);
     770        strcpy(tmp, call_program_and_get_last_line_of_output(command));
     771    }
     772    if (strlen(tmp) < 2) {
     773        paranoid_free(comment);
     774        paranoid_free(tmp);
     775        paranoid_free(cdr_exe);
     776        paranoid_free(command);
     777        return 1;
     778    } else {
     779        strcpy(cdrw_device, tmp);
     780        sprintf(comment, "Found CDRW device - %s", cdrw_device);
     781        log_it(comment);
     782        strcpy(g_cdrw_drive_is_here, cdrw_device);
     783        paranoid_free(comment);
     784        paranoid_free(tmp);
     785        paranoid_free(cdr_exe);
     786        paranoid_free(command);
     787        return (0);
     788    }
    785789}
    786790
     
    797801 * @return 0 for success, nonzero for failure.
    798802 */
    799 int
    800 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     {
    840       strcpy(output, g_cdrom_drive_is_here);
    841       log_msg(3, "Been there, done that. Returning %s", output);
    842       retval=0;
    843       goto end_of_find_cdrom_device;
    844     }
    845   if (the_last_place_i_found_it[0]!='\0' && !try_to_mount)
    846     {
    847         strcpy(output, the_last_place_i_found_it);
    848         log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", 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   tmp[0]='\0';
    861   if (!find_home_of_exe(cdr_exe))
    862     {
    863       strcpy(output, "/dev/cdrom");
    864       log_msg(4, "Can't find cdrecord; assuming %s", output);
    865       if (!does_device_exist(output))
    866         {
    867           log_msg(4, "That didn't work. Sorry.");
    868           retval=1;
    869           goto end_of_find_cdrom_device;
    870         }
    871       else
    872         {
    873           retval=0;
    874           goto end_of_find_cdrom_device;
    875         }
    876     }
    877 
    878   sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
    879   fin = popen (command, "r");
    880   if (!fin) { log_msg(4, "command=%s", command); log_OS_error("Cannot popen command"); return (1); }
    881   for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin);
    882        fgets (tmp, MAX_STR_LEN, fin))
    883     {
    884       p = strchr (tmp, '\'');
    885       if (p)
    886     {
    887       q = strchr (++p, '\'');
    888       if (q)
    889         {
    890           for (r = q; *(r - 1) == ' '; r--);
    891           *r = '\0';
    892           strcpy (phrase_one, p);
    893           p = strchr (++q, '\'');
    894           if (p)
    895         {
    896           q = strchr (++p, '\'');
    897           if (q)
    898             {
    899               while (*(q - 1) == ' ')
    900             {
    901               q--;
    902             }
    903               *q = '\0';
    904               strcpy (phrase_two, p);
    905             }
    906         }
    907         }
    908     }
    909     }
    910   paranoid_pclose(fin);
     803int find_cdrom_device(char *output, bool try_to_mount)
     804{
     805    /*@ pointers **************************************************** */
     806    FILE *fin;
     807    char *p;
     808    char *q;
     809    char *r;
     810    int retval = 0;
     811
     812    /*@ bool's ****************************************************** */
     813    bool found_it = FALSE;
     814
     815    /*@ buffers ***************************************************** */
     816    char *tmp;
     817    char *cdr_exe;
     818    char *phrase_one;
     819    char *phrase_two;
     820    char *command;
     821    char *dvd_last_resort;
     822    char *mountpoint;
     823    static char the_last_place_i_found_it[MAX_STR_LEN] = "";
     824
     825    /*@ intialize *************************************************** */
     826    malloc_string(tmp);
     827    malloc_string(cdr_exe);
     828    malloc_string(phrase_one);
     829    malloc_string(phrase_two);
     830    malloc_string(command);
     831    malloc_string(dvd_last_resort);
     832    malloc_string(mountpoint);
     833
     834    output[0] = '\0';
     835    phrase_one[0] = '\0';
     836    phrase_two[0] = '\0';
     837    dvd_last_resort[0] = '\0';
     838
     839    /*@ end vars **************************************************** */
     840
     841    if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) {
     842        strcpy(output, g_cdrom_drive_is_here);
     843        log_msg(3, "Been there, done that. Returning %s", output);
     844        retval = 0;
     845        goto end_of_find_cdrom_device;
     846    }
     847    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
     848        strcpy(output, the_last_place_i_found_it);
     849        log_msg(3,
     850                "find_cdrom_device() --- returning last found location - '%s'",
     851                output);
     852        retval = 0;
     853        goto end_of_find_cdrom_device;
     854    }
     855
     856    sprintf(mountpoint, "/tmp/cd.%d", (int) (random() % 32767));
     857    make_hole_for_dir(mountpoint);
     858
     859    if (find_home_of_exe("cdrecord")) {
     860        strcpy(cdr_exe, "cdrecord");
     861    } else {
     862        strcpy(cdr_exe, "dvdrecord");
     863    }
     864    tmp[0] = '\0';
     865    if (!find_home_of_exe(cdr_exe)) {
     866        strcpy(output, "/dev/cdrom");
     867        log_msg(4, "Can't find cdrecord; assuming %s", output);
     868        if (!does_device_exist(output)) {
     869            log_msg(4, "That didn't work. Sorry.");
     870            retval = 1;
     871            goto end_of_find_cdrom_device;
     872        } else {
     873            retval = 0;
     874            goto end_of_find_cdrom_device;
     875        }
     876    }
     877
     878    sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
     879    fin = popen(command, "r");
     880    if (!fin) {
     881        log_msg(4, "command=%s", command);
     882        log_OS_error("Cannot popen command");
     883        return (1);
     884    }
     885    for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     886         fgets(tmp, MAX_STR_LEN, fin)) {
     887        p = strchr(tmp, '\'');
     888        if (p) {
     889            q = strchr(++p, '\'');
     890            if (q) {
     891                for (r = q; *(r - 1) == ' '; r--);
     892                *r = '\0';
     893                strcpy(phrase_one, p);
     894                p = strchr(++q, '\'');
     895                if (p) {
     896                    q = strchr(++p, '\'');
     897                    if (q) {
     898                        while (*(q - 1) == ' ') {
     899                            q--;
     900                        }
     901                        *q = '\0';
     902                        strcpy(phrase_two, p);
     903                    }
     904                }
     905            }
     906        }
     907    }
     908    paranoid_pclose(fin);
    911909
    912910#ifndef __FreeBSD__
    913   if (strlen(phrase_two)==0)
    914     { log_msg(4, "Not running phase two. String is empty."); }
    915   else
    916     {
    917       sprintf (command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
    918       fin = popen (command, "r");
    919       if (!fin)
    920         {
    921           log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
    922         }
    923       else
    924         {
    925           for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin); fgets (tmp, MAX_STR_LEN, fin))
    926         {
    927               log_msg(5, "--> '%s'", tmp);
    928               if (tmp[0] != ' ' && tmp[1] != ' ')
    929             {
    930               p = strchr (tmp, ':');
    931               if (p)
    932             {
    933               *p = '\0';
    934               if (strstr(tmp, "DVD"))
    935                 {
    936                   sprintf(dvd_last_resort, "/dev/%s", tmp);
    937                   log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp);
    938                 }
    939               else
    940                 {
    941                   sprintf (output, "/dev/%s", tmp);
    942                   found_it = TRUE;
    943                 }
    944             }
    945                 }
    946             }
    947           paranoid_pclose(fin);
    948         }
    949     }
     911    if (strlen(phrase_two) == 0) {
     912        log_msg(4, "Not running phase two. String is empty.");
     913    } else {
     914        sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
     915        fin = popen(command, "r");
     916        if (!fin) {
     917            log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
     918        } else {
     919            for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     920                 fgets(tmp, MAX_STR_LEN, fin)) {
     921                log_msg(5, "--> '%s'", tmp);
     922                if (tmp[0] != ' ' && tmp[1] != ' ') {
     923                    p = strchr(tmp, ':');
     924                    if (p) {
     925                        *p = '\0';
     926                        if (strstr(tmp, "DVD")) {
     927                            sprintf(dvd_last_resort, "/dev/%s", tmp);
     928                            log_msg(4,
     929                                    "Ignoring '%s' because it's a DVD drive",
     930                                    tmp);
     931                        } else {
     932                            sprintf(output, "/dev/%s", tmp);
     933                            found_it = TRUE;
     934                        }
     935                    }
     936                }
     937            }
     938            paranoid_pclose(fin);
     939        }
     940    }
    950941
    951942#endif
    952943#ifdef __FreeBSD__
    953   if (!found_it)
    954       { log_msg(4, "OK, approach 2"); if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom")))
    955         { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom1")))
    956           { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/dvd")))
    957             { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/acd0")))
    958               { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cd01")))
    959                 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/acd1")))
    960                   { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cd1")))
    961               { retval=1; goto end_of_find_cdrom_device; }
    962           } } } } } } }
     944    if (!found_it) {
     945        log_msg(4, "OK, approach 2");
     946        if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
     947            if (!
     948                (found_it =
     949                 set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) {
     950                if (!
     951                    (found_it =
     952                     set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) {
     953                    if (!
     954                        (found_it =
     955                         set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) {
     956                        if (!
     957                            (found_it =
     958                             set_dev_to_this_if_rx_OK(output,
     959                                                      "/dev/cd01"))) {
     960                            if (!
     961                                (found_it =
     962                                 set_dev_to_this_if_rx_OK(output,
     963                                                          "/dev/acd1"))) {
     964                                if (!
     965                                    (found_it =
     966                                     set_dev_to_this_if_rx_OK(output,
     967                                                              "/dev/cd1")))
     968                                {
     969                                    retval = 1;
     970                                    goto end_of_find_cdrom_device;
     971                                }
     972                            }
     973                        }
     974                    }
     975                }
     976            }
     977        }
     978    }
    963979#else
    964   if (!found_it && strlen(dvd_last_resort)>0)
    965     {
    966       log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort);
    967       strcpy(output, dvd_last_resort);
    968       found_it = TRUE;
    969     }
    970   if (found_it)
    971     {
    972       sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output,'/')+1);
    973       if (system(tmp) == 0)
    974     {
    975       log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
    976       found_it = FALSE;
    977       output[0] = '\0';
    978     }
    979     }
    980 
    981   if (found_it)
    982     {
    983       log_msg(4, "(find_cdrom_device) --> '%s'", output);
    984       if (!does_device_exist(output)) { found_it=FALSE; log_msg(4, "OK, I was wrong, I haven't found it... yet."); }
    985     }
    986 
    987   if (!found_it)
    988       { log_msg(4, "OK, approach 2"); if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0")))
    989         { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0" )))
    990           { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom")))
    991             { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom0")))
    992               { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom1")))
    993         { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr1")))
    994                   { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/dvd")))
    995             { if (!(found_it = set_dev_to_this_if_rx_OK(output, g_cdrw_drive_is_here)))
    996               { retval=1; goto end_of_find_cdrom_device; }
    997             } } } } } } } }
    998 #endif
    999 
    1000   if (found_it && try_to_mount)
    1001     {
    1002       if (mount_CDROM_here (output, mountpoint))
    1003         {
    1004           log_msg(4, "[Cardigans] I've changed my mind");
    1005           found_it = FALSE;
    1006         }
    1007       else
    1008         {
    1009           sprintf(tmp, "%s/archives", mountpoint);
    1010           if (!does_file_exist(tmp))
    1011             {
    1012               log_msg(4, "[Cardigans] I'll take it back");
    1013               found_it = FALSE;
    1014             }
    1015           else
    1016             {
    1017               sprintf(command, "umount %s", output);
    1018               paranoid_system(command);
    1019               log_msg(4, "I'm confident the Mondo CD is in %s", output);
    1020         }
    1021         }
    1022     }
    1023   unlink(mountpoint);
    1024 
    1025   if (found_it)
    1026     {
    1027       if (!does_file_exist(output)) { log_msg(3, "I still haven't found it."); return(1); }
    1028       log_msg(3, "(find_cdrom_device) --> '%s'", output);
    1029       strcpy(the_last_place_i_found_it, output);
    1030       strcpy(g_cdrom_drive_is_here, output);
    1031       retval=0;
    1032       goto end_of_find_cdrom_device;
    1033     }
    1034 
    1035   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);
    1036   log_msg(1, "command=%s", command);
    1037   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1038   if (tmp[0])
    1039     {
    1040       strcpy(output, tmp);
    1041       log_msg(4, "Finally found it at %s", output);
    1042       retval=0;
    1043       goto end_of_find_cdrom_device;
    1044     }
    1045   else
    1046     {
    1047       log_msg(4, "Still couldn't find it.");
    1048       retval=1;
    1049       goto end_of_find_cdrom_device;
    1050     }
    1051 end_of_find_cdrom_device:
    1052   paranoid_free(tmp);
    1053   paranoid_free(cdr_exe);
    1054   paranoid_free(phrase_one);
    1055   paranoid_free(phrase_two);
    1056   paranoid_free(command);
    1057   paranoid_free(dvd_last_resort);
    1058   paranoid_free(mountpoint);
    1059   return(retval);
    1060 }
    1061 
    1062 
    1063 
    1064 
    1065 
    1066 int find_dvd_device(char*output, bool try_to_mount)
    1067 {
    1068   char *command;
    1069   char *tmp;
    1070   int retval=0, devno=-1;
    1071 
    1072   malloc_string(command);
    1073   malloc_string(tmp);
    1074 
    1075     if (g_dvd_drive_is_here[0])
    1076     {
    1077       strcpy(output, g_dvd_drive_is_here);
    1078       log_msg(3, "Been there, done that. Returning %s", output);
    1079       return(0);
    1080     }
    1081 
    1082   sprintf(tmp, call_program_and_get_last_line_of_output
    1083             (
    1084 "dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1"
    1085             )
     980    if (!found_it && strlen(dvd_last_resort) > 0) {
     981        log_msg(4, "Well, I'll use the DVD - %s - as a last resort",
     982                dvd_last_resort);
     983        strcpy(output, dvd_last_resort);
     984        found_it = TRUE;
     985    }
     986    if (found_it) {
     987        sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",
     988                strrchr(output, '/') + 1);
     989        if (system(tmp) == 0) {
     990            log_msg(4,
     991                    "%s is not right. It's being SCSI-emulated. Continuing.",
     992                    output);
     993            found_it = FALSE;
     994            output[0] = '\0';
     995        }
     996    }
     997
     998    if (found_it) {
     999        log_msg(4, "(find_cdrom_device) --> '%s'", output);
     1000        if (!does_device_exist(output)) {
     1001            found_it = FALSE;
     1002            log_msg(4, "OK, I was wrong, I haven't found it... yet.");
     1003        }
     1004    }
     1005
     1006    if (!found_it) {
     1007        log_msg(4, "OK, approach 2");
     1008        if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) {
     1009            if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0"))) {
     1010                if (!
     1011                    (found_it =
     1012                     set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
     1013                    if (!
     1014                        (found_it =
     1015                         set_dev_to_this_if_rx_OK(output,
     1016                                                  "/dev/cdrom0"))) {
     1017                        if (!
     1018                            (found_it =
     1019                             set_dev_to_this_if_rx_OK(output,
     1020                                                      "/dev/cdrom1"))) {
     1021                            if (!
     1022                                (found_it =
     1023                                 set_dev_to_this_if_rx_OK(output,
     1024                                                          "/dev/sr1"))) {
     1025                                if (!
     1026                                    (found_it =
     1027                                     set_dev_to_this_if_rx_OK(output,
     1028                                                              "/dev/dvd")))
     1029                                {
     1030                                    if (!
     1031                                        (found_it =
     1032                                         set_dev_to_this_if_rx_OK(output,
     1033                                                                  g_cdrw_drive_is_here)))
     1034                                    {
     1035                                        retval = 1;
     1036                                        goto end_of_find_cdrom_device;
     1037                                    }
     1038                                }
     1039                            }
     1040                        }
     1041                    }
     1042                }
     1043            }
     1044        }
     1045    }
     1046#endif
     1047
     1048    if (found_it && try_to_mount) {
     1049        if (mount_CDROM_here(output, mountpoint)) {
     1050            log_msg(4, "[Cardigans] I've changed my mind");
     1051            found_it = FALSE;
     1052        } else {
     1053            sprintf(tmp, "%s/archives", mountpoint);
     1054            if (!does_file_exist(tmp)) {
     1055                log_msg(4, "[Cardigans] I'll take it back");
     1056                found_it = FALSE;
     1057            } else {
     1058                sprintf(command, "umount %s", output);
     1059                paranoid_system(command);
     1060                log_msg(4, "I'm confident the Mondo CD is in %s", output);
     1061            }
     1062        }
     1063    }
     1064    unlink(mountpoint);
     1065
     1066    if (found_it) {
     1067        if (!does_file_exist(output)) {
     1068            log_msg(3, "I still haven't found it.");
     1069            return (1);
     1070        }
     1071        log_msg(3, "(find_cdrom_device) --> '%s'", output);
     1072        strcpy(the_last_place_i_found_it, output);
     1073        strcpy(g_cdrom_drive_is_here, output);
     1074        retval = 0;
     1075        goto end_of_find_cdrom_device;
     1076    }
     1077
     1078    sprintf(command,
     1079            "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2",
     1080            cdr_exe, g_cdrw_drive_is_here);
     1081    log_msg(1, "command=%s", command);
     1082    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1083    if (tmp[0]) {
     1084        strcpy(output, tmp);
     1085        log_msg(4, "Finally found it at %s", output);
     1086        retval = 0;
     1087        goto end_of_find_cdrom_device;
     1088    } else {
     1089        log_msg(4, "Still couldn't find it.");
     1090        retval = 1;
     1091        goto end_of_find_cdrom_device;
     1092    }
     1093  end_of_find_cdrom_device:
     1094    paranoid_free(tmp);
     1095    paranoid_free(cdr_exe);
     1096    paranoid_free(phrase_one);
     1097    paranoid_free(phrase_two);
     1098    paranoid_free(command);
     1099    paranoid_free(dvd_last_resort);
     1100    paranoid_free(mountpoint);
     1101    return (retval);
     1102}
     1103
     1104
     1105
     1106
     1107
     1108int find_dvd_device(char *output, bool try_to_mount)
     1109{
     1110    char *command;
     1111    char *tmp;
     1112    int retval = 0, devno = -1;
     1113
     1114    malloc_string(command);
     1115    malloc_string(tmp);
     1116
     1117    if (g_dvd_drive_is_here[0]) {
     1118        strcpy(output, g_dvd_drive_is_here);
     1119        log_msg(3, "Been there, done that. Returning %s", output);
     1120        return (0);
     1121    }
     1122
     1123    sprintf(tmp, call_program_and_get_last_line_of_output
     1124            ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
    10861125        );
    1087   log_msg(5, "tmp = '%s'", tmp);
    1088   if (!tmp[0]) sprintf (tmp, call_program_and_get_last_line_of_output
    1089                  (
    1090 "cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1"
    1091                              )
    1092                        );
    1093   if (tmp[0])
    1094     {
    1095       devno=atoi(tmp) - 1;
    1096     }
    1097   if (devno>=0)
    1098     {
    1099       retval=0;
    1100       sprintf(output, "/dev/scd%d", devno);
    1101       strcpy(g_dvd_drive_is_here, output);
    1102       log_msg(2, "I think DVD is at %s", output);
    1103     }
    1104   else
    1105     {
    1106       log_msg(2,"I cannot find DVD");
    1107       retval=1;
    1108     }
    1109 
    1110   if (try_to_mount)
    1111     {
    1112       log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
    1113     }
    1114   return(retval);
     1126    log_msg(5, "tmp = '%s'", tmp);
     1127    if (!tmp[0])
     1128        sprintf(tmp, call_program_and_get_last_line_of_output
     1129                ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
     1130            );
     1131    if (tmp[0]) {
     1132        devno = atoi(tmp) - 1;
     1133    }
     1134    if (devno >= 0) {
     1135        retval = 0;
     1136        sprintf(output, "/dev/scd%d", devno);
     1137        strcpy(g_dvd_drive_is_here, output);
     1138        log_msg(2, "I think DVD is at %s", output);
     1139    } else {
     1140        log_msg(2, "I cannot find DVD");
     1141        retval = 1;
     1142    }
     1143
     1144    if (try_to_mount) {
     1145        log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
     1146    }
     1147    return (retval);
    11151148}
    11161149
     
    11271160 * @return size in megabytes.
    11281161 */
    1129 long
    1130 get_phys_size_of_drive (char *drive)
    1131 {
    1132     int fd;
     1162long get_phys_size_of_drive(char *drive)
     1163{
     1164    int fd;
    11331165#if linux
    1134     unsigned long long s=0;
    1135     int fileid, cylinders=0, cylindersleft=0;
    1136     int cylindersize=0;
     1166    unsigned long long s = 0;
     1167    int fileid, cylinders = 0, cylindersleft = 0;
     1168    int cylindersize = 0;
    11371169    int gotgeo = 0;
    11381170
    1139    
    1140   struct hd_geometry hdgeo;
     1171
     1172    struct hd_geometry hdgeo;
    11411173#elif __FreeBSD__
    1142     off_t s;
    1143 #endif
    1144 
    1145     long outvalA=-1;
    1146     long outvalB=-1;
    1147     long outvalC=-1;
    1148 
    1149     if ((fd = open (drive, O_RDONLY)) != -1) {
    1150     if (ioctl (fd,
     1174    off_t s;
     1175#endif
     1176
     1177    long outvalA = -1;
     1178    long outvalB = -1;
     1179    long outvalC = -1;
     1180
     1181    if ((fd = open(drive, O_RDONLY)) != -1) {
     1182        if (ioctl(fd,
    11511183#if linux
    1152     #ifdef BLKGETSIZE64
    1153             BLKGETSIZE64,
    1154     #else
    1155             BLKGETSIZE,
    1156    #endif
     1184#ifdef BLKGETSIZE64
     1185                  BLKGETSIZE64,
     1186#else
     1187                  BLKGETSIZE,
     1188#endif
    11571189#elif __FreeBSD__
    1158            DIOCGMEDIASIZE,
    1159 #endif
    1160            &s) != -1) {
    1161         close (fd);
    1162                     // s>>11 works for older disks but not for newer ones
    1163         outvalB =
     1190                  DIOCGMEDIASIZE,
     1191#endif
     1192                  &s) != -1) {
     1193            close(fd);
     1194            // s>>11 works for older disks but not for newer ones
     1195            outvalB =
    11641196#if linux
    1165     #ifdef BLKGETSIZE64 
    1166           s >> 20
    1167     #else
    1168               s >> 11
    1169     #endif
     1197#ifdef BLKGETSIZE64
     1198                s >> 20
    11701199#else
    1171               s >> 20
    1172 #endif
    1173 ;
    1174     }
    1175     }
    1176 
    1177     if (outvalB<=0)
    1178       { log_msg (1, "Error getting size of %s: %s", drive, strerror (errno)); }
     1200                s >> 11
     1201#endif
     1202#else
     1203                s >> 20
     1204#endif
     1205                ;
     1206        }
     1207    }
     1208
     1209    if (outvalB <= 0) {
     1210        log_msg(1, "Error getting size of %s: %s", drive, strerror(errno));
     1211    }
    11791212#if linux
    1180     fileid = open (drive, O_RDONLY);
     1213    fileid = open(drive, O_RDONLY);
    11811214    if (fileid) {
    1182         if (ioctl (fileid, HDIO_GETGEO, &hdgeo) != -1) {
     1215        if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
    11831216            if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
    11841217                cylindersleft = cylinders = hdgeo.cylinders;
    11851218                cylindersize = hdgeo.heads * hdgeo.sectors / 2;
    11861219                outvalA = cylindersize * cylinders / 1024;
    1187                 log_msg (2, "Got Harddisk geometry, C:%d, H:%d, S:%d", hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
     1220                log_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
     1221                        hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
    11881222                gotgeo = 1;
    11891223            } else {
    1190                 log_msg (1, "Harddisk geometry wrong");
     1224                log_msg(1, "Harddisk geometry wrong");
    11911225            }
    11921226        } else {
    1193             log_msg (1, "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode", strerror(errno));
     1227            log_msg(1,
     1228                    "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode",
     1229                    strerror(errno));
    11941230        }
    11951231        close(fileid);
    11961232    } else {
    1197         log_msg (1, "Failed to open %s for reading: %s", drive, strerror(errno));
     1233        log_msg(1, "Failed to open %s for reading: %s", drive,
     1234                strerror(errno));
    11981235    }
    11991236    if (!gotgeo) {
    1200         log_msg (1, "Failed to get harddisk geometry, using old mode");
     1237        log_msg(1, "Failed to get harddisk geometry, using old mode");
    12011238    }
    12021239/* 
     
    12161253// NEWER DISKS will give sane value for outvalB (close to outvalA, in other words) :)
    12171254
    1218   outvalC = (outvalA > outvalB) ? outvalA : outvalB;
    1219  
     1255    outvalC = (outvalA > outvalB) ? outvalA : outvalB;
     1256
    12201257//  log_msg (5, "drive = %s, error = %s", drive, strerror (errno));
    12211258//  fatal_error ("GPSOD: Unable to get size of drive");
    1222   log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB, outvalC);
    1223  
    1224   return(outvalC);
    1225 }
    1226    
     1259    log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB,
     1260            outvalC);
     1261
     1262    return (outvalC);
     1263}
     1264
    12271265/* The old version */
    1228 #if 0
    1229 long
    1230 get_phys_size_of_drive (char *drive)
    1231 {
    1232     /*@ pointers *****************************************************/
     1266#if 0
     1267long get_phys_size_of_drive(char *drive)
     1268{
     1269    /*@ pointers **************************************************** */
    12331270#if linux
    1234   FILE *fin;
    1235   char *p;
    1236   char *q;
    1237   char *r;
    1238     /*@ buffers ******************************************************/
    1239   char *tmp;
    1240   char *command;
    1241 
    1242     /*@ long *********************************************************/
    1243   long outL;
    1244   long tempLa;
    1245   long tempLb;
    1246   long tempLc;
    1247 
    1248 #endif
    1249 
    1250   struct hd_geometry hdgeo;
    1251   int fd;
     1271    FILE *fin;
     1272    char *p;
     1273    char *q;
     1274    char *r;
     1275    /*@ buffers ***************************************************** */
     1276    char *tmp;
     1277    char *command;
     1278
     1279    /*@ long ******************************************************** */
     1280    long outL;
     1281    long tempLa;
     1282    long tempLb;
     1283    long tempLc;
     1284
     1285#endif
     1286
     1287    struct hd_geometry hdgeo;
     1288    int fd;
    12521289
    12531290#ifdef __FreeBSD__
    1254   off_t o;
    1255 
    1256   if ((fd = open (drive, O_RDONLY)) != -1) {
    1257       if (ioctl (fd, DIOCGMEDIASIZE, &o) != -1) {
    1258       close (fd);
    1259       return (long) (o / (off_t) (1024 * 1024));
    1260       }
    1261       close (fd);
    1262   }
    1263   log_msg (4, "drive = %s, error = %s", drive, strerror (errno));
    1264   fatal_error ("GPSOD: Unable to get size of drive");
     1291    off_t o;
     1292
     1293    if ((fd = open(drive, O_RDONLY)) != -1) {
     1294        if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) {
     1295            close(fd);
     1296            return (long) (o / (off_t) (1024 * 1024));
     1297        }
     1298        close(fd);
     1299    }
     1300    log_msg(4, "drive = %s, error = %s", drive, strerror(errno));
     1301    fatal_error("GPSOD: Unable to get size of drive");
    12651302#else
    12661303
    1267   malloc_string(tmp);
    1268   malloc_string(command);
    1269 
    1270   if ((fd = open (drive, O_RDONLY)) != -1) {
    1271       if (ioctl (fd, HDIO_GETGEO, &hdgeo) != -1)  {
    1272       close (fd);
    1273       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));
    1274       if ( hdgeo.cylinders && hdgeo.heads && hdgeo.sectors ) {
    1275           return ((long) (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));
    1276       }
    1277       }
    1278       close (fd);
    1279   }
    1280 
    1281   assert_string_is_neither_NULL_nor_zerolength(drive);
    1282 
    1283   sprintf (command,
    1284        "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",
    1285        drive);
    1286   strcpy (tmp, call_program_and_get_last_line_of_output (command));
    1287   if (tmp[0])
    1288     {
    1289       p = tmp;
    1290       q = strchr (p, ' ');
    1291       if (q)
    1292     {
    1293       *(q++) = '\0';
    1294       r = strchr (q, ' ');
    1295       if (r)
    1296         {
    1297           *(r++) = '\0';
    1298           tempLa = atol (p);
    1299           tempLb = atol (q);
    1300           tempLc = atol (r);
    1301           outL = tempLa * tempLb / 1024 * tempLc / 1024;
    1302           if (outL > 100)
    1303         {
    1304       paranoid_free(tmp);
    1305       paranoid_free(command);
    1306           return (outL);
    1307         }
    1308         }
    1309     }
    1310     }
    1311 
    1312   /* try to grep for 'Drive xxxx: yyy MB' */
    1313   sprintf(command, "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3", drive);
    1314   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1315   if (atol(tmp) > 0)
    1316     {
    1317       paranoid_free(tmp);
    1318       paranoid_free(command);
    1319       return (atol(tmp));
    1320     }
    1321 
    1322   /* else, do it the old-fashioned way */
    1323   p = strrchr (drive, (int) '/');
    1324   if (p)
    1325     {
    1326       strcpy (tmp, p + 1);
    1327     }
    1328   else
    1329     {
    1330       paranoid_free(tmp);
    1331       paranoid_free(command);
    1332       return (-1);
    1333     }
    1334   sprintf (command, "dmesg | grep %s 2> /dev/null", tmp);
    1335   if (!(fin = popen (command, "r")))
    1336     { log_OS_error("Cannot popen dmesg command"); }
    1337   else
    1338     {
    1339       fgets (tmp, MAX_STR_LEN - 1, fin);
    1340       while (!feof (fin) && !strstr (tmp, "GB") && !strstr (tmp, "MB"))
    1341         {
    1342           fgets (tmp, MAX_STR_LEN - 1, fin);
    1343         }
    1344       if (pclose (fin)) { log_OS_error("Cannot pclose dmesg fin"); }
    1345     }
    1346   if (!(p = strstr (tmp, "GB")) && !(p = strstr (tmp, "MB")))
    1347     {
    1348       log_msg (3, "Cannot find %s's size: dmesg isn't helping either.",
    1349            drive);
    1350       paranoid_free(tmp);
    1351       paranoid_free(command);
    1352       return (-1);
    1353     }
    1354   for (; !isdigit (*(p - 1)); p--);
    1355   *p = '\0';
    1356   for (p--; isdigit (*(p - 1)); p--);
    1357   outL = atol (p);
    1358   if (outL <= 0)
    1359     {
    1360       paranoid_free(tmp);
    1361       paranoid_free(command);
    1362       return (-1);
    1363     }
    1364   if (strstr (tmp, "GB"))
    1365     {
    1366       outL = outL * 1024;
    1367     }
    1368       paranoid_free(tmp);
    1369       paranoid_free(command);
    1370   return (outL * 19 / 20);
    1371 #endif
    1372 }
    1373 #endif /* 0 */
     1304    malloc_string(tmp);
     1305    malloc_string(command);
     1306
     1307    if ((fd = open(drive, O_RDONLY)) != -1) {
     1308        if (ioctl(fd, HDIO_GETGEO, &hdgeo) != -1) {
     1309            close(fd);
     1310            log_msg(2,
     1311                    "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB",
     1312                    drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors,
     1313                    (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 /
     1314                     1024));
     1315            if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
     1316                return ((long)
     1317                        (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors /
     1318                         2 / 1024));
     1319            }
     1320        }
     1321        close(fd);
     1322    }
     1323
     1324    assert_string_is_neither_NULL_nor_zerolength(drive);
     1325
     1326    sprintf(command,
     1327            "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",
     1328            drive);
     1329    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1330    if (tmp[0]) {
     1331        p = tmp;
     1332        q = strchr(p, ' ');
     1333        if (q) {
     1334            *(q++) = '\0';
     1335            r = strchr(q, ' ');
     1336            if (r) {
     1337                *(r++) = '\0';
     1338                tempLa = atol(p);
     1339                tempLb = atol(q);
     1340                tempLc = atol(r);
     1341                outL = tempLa * tempLb / 1024 * tempLc / 1024;
     1342                if (outL > 100) {
     1343                    paranoid_free(tmp);
     1344                    paranoid_free(command);
     1345                    return (outL);
     1346                }
     1347            }
     1348        }
     1349    }
     1350
     1351    /* try to grep for 'Drive xxxx: yyy MB' */
     1352    sprintf(command,
     1353            "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3",
     1354            drive);
     1355    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1356    if (atol(tmp) > 0) {
     1357        paranoid_free(tmp);
     1358        paranoid_free(command);
     1359        return (atol(tmp));
     1360    }
     1361
     1362    /* else, do it the old-fashioned way */
     1363    p = strrchr(drive, (int) '/');
     1364    if (p) {
     1365        strcpy(tmp, p + 1);
     1366    } else {
     1367        paranoid_free(tmp);
     1368        paranoid_free(command);
     1369        return (-1);
     1370    }
     1371    sprintf(command, "dmesg | grep %s 2> /dev/null", tmp);
     1372    if (!(fin = popen(command, "r"))) {
     1373        log_OS_error("Cannot popen dmesg command");
     1374    } else {
     1375        fgets(tmp, MAX_STR_LEN - 1, fin);
     1376        while (!feof(fin) && !strstr(tmp, "GB") && !strstr(tmp, "MB")) {
     1377            fgets(tmp, MAX_STR_LEN - 1, fin);
     1378        }
     1379        if (pclose(fin)) {
     1380            log_OS_error("Cannot pclose dmesg fin");
     1381        }
     1382    }
     1383    if (!(p = strstr(tmp, "GB")) && !(p = strstr(tmp, "MB"))) {
     1384        log_msg(3, "Cannot find %s's size: dmesg isn't helping either.",
     1385                drive);
     1386        paranoid_free(tmp);
     1387        paranoid_free(command);
     1388        return (-1);
     1389    }
     1390    for (; !isdigit(*(p - 1)); p--);
     1391    *p = '\0';
     1392    for (p--; isdigit(*(p - 1)); p--);
     1393    outL = atol(p);
     1394    if (outL <= 0) {
     1395        paranoid_free(tmp);
     1396        paranoid_free(command);
     1397        return (-1);
     1398    }
     1399    if (strstr(tmp, "GB")) {
     1400        outL = outL * 1024;
     1401    }
     1402    paranoid_free(tmp);
     1403    paranoid_free(command);
     1404    return (outL * 19 / 20);
     1405#endif
     1406}
     1407#endif                          /* 0 */
    13741408
    13751409
     
    13831417 * @return TRUE if the format is supported, FALSE if not.
    13841418 */
    1385 bool
    1386 is_this_a_valid_disk_format (char *format)
    1387 {
    1388   char *good_formats;
     1419bool is_this_a_valid_disk_format(char *format)
     1420{
     1421    char *good_formats;
    13891422    char *command;
    13901423    char *format_sz;
    13911424
    1392   FILE *pin;
    1393   int retval;
    1394   malloc_string(good_formats);
    1395   malloc_string(command);
    1396   malloc_string(format_sz);
    1397 
    1398   assert_string_is_neither_NULL_nor_zerolength(format);
    1399 
    1400   sprintf (format_sz, "%s ", format);
     1425    FILE *pin;
     1426    int retval;
     1427    malloc_string(good_formats);
     1428    malloc_string(command);
     1429    malloc_string(format_sz);
     1430
     1431    assert_string_is_neither_NULL_nor_zerolength(format);
     1432
     1433    sprintf(format_sz, "%s ", format);
    14011434
    14021435#ifdef __FreeBSD__
    1403   sprintf (command,
    1404            "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
     1436    sprintf(command,
     1437            "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
    14051438#else
    1406   sprintf (command,
    1407        "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
    1408 #endif
    1409 
    1410   pin = popen (command, "r");
    1411   if (!pin)
    1412     {
    1413       log_OS_error ("Unable to read good formats");
    1414       retval=0;
    1415     }
    1416   else
    1417     {
    1418       strcpy (good_formats, " ");
    1419       (void) fgets (good_formats + 1, MAX_STR_LEN, pin);
    1420       if (pclose (pin))
    1421         { log_OS_error("Cannot pclose good formats"); }
    1422       strip_spaces (good_formats);
    1423       strcat (good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
    1424       if (strstr (good_formats, format_sz))
    1425         {
    1426       retval=1;
    1427         }
    1428       else
    1429         {
    1430       retval=0;
    1431         }
    1432     }
    1433   paranoid_free(good_formats);
    1434   paranoid_free(command);
    1435   paranoid_free(format_sz);
    1436   return (retval);
     1439    sprintf(command,
     1440            "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
     1441#endif
     1442
     1443    pin = popen(command, "r");
     1444    if (!pin) {
     1445        log_OS_error("Unable to read good formats");
     1446        retval = 0;
     1447    } else {
     1448        strcpy(good_formats, " ");
     1449        (void) fgets(good_formats + 1, MAX_STR_LEN, pin);
     1450        if (pclose(pin)) {
     1451            log_OS_error("Cannot pclose good formats");
     1452        }
     1453        strip_spaces(good_formats);
     1454        strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
     1455        if (strstr(good_formats, format_sz)) {
     1456            retval = 1;
     1457        } else {
     1458            retval = 0;
     1459        }
     1460    }
     1461    paranoid_free(good_formats);
     1462    paranoid_free(command);
     1463    paranoid_free(format_sz);
     1464    return (retval);
    14371465}
    14381466
     
    14451473 * @return TRUE if it's mounted, FALSE if not.
    14461474 */
    1447 bool is_this_device_mounted (char *device_raw)
    1448 {
    1449 
    1450     /*@ pointers *****************************************************/
    1451   FILE *fin;
    1452 
    1453     /*@ buffers ******************************************************/
    1454   char *incoming;
    1455   char *device_with_tab;
    1456   char *device_with_space;
    1457   char *tmp;
    1458   int retval=0;
    1459  
     1475bool is_this_device_mounted(char *device_raw)
     1476{
     1477
     1478    /*@ pointers **************************************************** */
     1479    FILE *fin;
     1480
     1481    /*@ buffers ***************************************************** */
     1482    char *incoming;
     1483    char *device_with_tab;
     1484    char *device_with_space;
     1485    char *tmp;
     1486    int retval = 0;
     1487
    14601488#ifdef __FreeBSD__
    1461   #define SWAPLIST_COMMAND "swapinfo"
     1489#define SWAPLIST_COMMAND "swapinfo"
    14621490#else
    1463   #define SWAPLIST_COMMAND "cat /proc/swaps"
    1464 #endif
    1465 
    1466     /*@ end vars *****************************************************/
    1467 
    1468   malloc_string(incoming);
    1469   malloc_string(device_with_tab);
    1470   malloc_string(device_with_space);
    1471   malloc_string(tmp);
    1472   assert(device_raw!=NULL);
     1491#define SWAPLIST_COMMAND "cat /proc/swaps"
     1492#endif
     1493
     1494    /*@ end vars **************************************************** */
     1495
     1496    malloc_string(incoming);
     1497    malloc_string(device_with_tab);
     1498    malloc_string(device_with_space);
     1499    malloc_string(tmp);
     1500    assert(device_raw != NULL);
    14731501//  assert_string_is_neither_NULL_nor_zerolength(device_raw);
    1474   if (device_raw[0] != '/' && !strstr(device_raw, ":/"))
    1475     {
    1476       log_msg(1, "%s needs to have a '/' prefixed - I'll do it", device_raw);
    1477       sprintf(tmp, "/%s", device_raw);
    1478     }
    1479   else
    1480     {
    1481       strcpy(tmp, device_raw);
    1482     }
    1483   log_msg(1, "Is %s mounted?", tmp);
    1484   if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc"))
    1485     {
    1486       log_msg(1, "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
    1487       return(0);
    1488     }
    1489   sprintf (device_with_tab, "%s\t", tmp);
    1490   sprintf (device_with_space, "%s ", tmp);
    1491 
    1492   if (!(fin = popen ("mount", "r"))) { log_OS_error("Cannot popen 'mount'"); return(FALSE); }
    1493   for (fgets (incoming, MAX_STR_LEN - 1, fin); !feof (fin);
    1494        fgets (incoming, MAX_STR_LEN - 1, fin))
    1495     {
    1496       if ( strstr (incoming, device_with_space) //> incoming
    1497       || strstr (incoming, device_with_tab) ) // > incoming)
    1498     {
    1499       paranoid_pclose (fin);
    1500       retval=1;
    1501       goto end_of_func;
    1502     }
    1503     }
    1504   paranoid_pclose(fin);
    1505   sprintf (tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null",
    1506        SWAPLIST_COMMAND, device_with_space);
    1507   log_msg(4, "tmp (command) = '%s'", tmp);
    1508   if (!system (tmp))
    1509     {
    1510       retval=1;
    1511       goto end_of_func;
    1512     }
    1513 end_of_func:
    1514   paranoid_free(incoming);
    1515   paranoid_free(device_with_tab);
    1516   paranoid_free(device_with_space);
    1517   paranoid_free(tmp);
    1518   return (retval);
     1502    if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
     1503        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
     1504                device_raw);
     1505        sprintf(tmp, "/%s", device_raw);
     1506    } else {
     1507        strcpy(tmp, device_raw);
     1508    }
     1509    log_msg(1, "Is %s mounted?", tmp);
     1510    if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) {
     1511        log_msg(1,
     1512                "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
     1513        return (0);
     1514    }
     1515    sprintf(device_with_tab, "%s\t", tmp);
     1516    sprintf(device_with_space, "%s ", tmp);
     1517
     1518    if (!(fin = popen("mount", "r"))) {
     1519        log_OS_error("Cannot popen 'mount'");
     1520        return (FALSE);
     1521    }
     1522    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     1523         fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1524        if (strstr(incoming, device_with_space) //> incoming
     1525            || strstr(incoming, device_with_tab))   // > incoming)
     1526        {
     1527            paranoid_pclose(fin);
     1528            retval = 1;
     1529            goto end_of_func;
     1530        }
     1531    }
     1532    paranoid_pclose(fin);
     1533    sprintf(tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null",
     1534            SWAPLIST_COMMAND, device_with_space);
     1535    log_msg(4, "tmp (command) = '%s'", tmp);
     1536    if (!system(tmp)) {
     1537        retval = 1;
     1538        goto end_of_func;
     1539    }
     1540  end_of_func:
     1541    paranoid_free(incoming);
     1542    paranoid_free(device_with_tab);
     1543    paranoid_free(device_with_space);
     1544    paranoid_free(tmp);
     1545    return (retval);
    15191546}
    15201547
     
    15261553 * @return /dev entry for the device, or NULL if it couldn't be allocated.
    15271554 */
    1528 char *
    1529 make_vn (char *fname)
    1530 {
    1531     char *device   = (char*) malloc (MAX_STR_LEN);
    1532     char *mddevice = (char*) malloc (32);
    1533     char command[MAX_STR_LEN];
    1534     int vndev = 2;
    1535     if (atoi (call_program_and_get_last_line_of_output ("/sbin/sysctl -n kern.osreldate")) <
    1536         500000) {
    1537         do {
    1538             sprintf (mddevice, "vn%ic", vndev++);
    1539             sprintf (command, "vnconfig %s %s", mddevice, fname);
    1540             if (vndev > 10) {
    1541                 return NULL;
    1542             }
    1543         }
    1544        while (system (command));
    1545     } else {
    1546         sprintf (command, "mdconfig -a -t vnode -f %s", fname);
    1547         mddevice = call_program_and_get_last_line_of_output (command);
    1548         if (!strstr (mddevice, "md")) {
    1549             return NULL;
    1550         }
    1551     }
    1552     sprintf (device, "/dev/%s", mddevice);
    1553     return device;
     1555char *make_vn(char *fname)
     1556{
     1557    char *device = (char *) malloc(MAX_STR_LEN);
     1558    char *mddevice = (char *) malloc(32);
     1559    char command[MAX_STR_LEN];
     1560    int vndev = 2;
     1561    if (atoi
     1562        (call_program_and_get_last_line_of_output
     1563         ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1564        do {
     1565            sprintf(mddevice, "vn%ic", vndev++);
     1566            sprintf(command, "vnconfig %s %s", mddevice, fname);
     1567            if (vndev > 10) {
     1568                return NULL;
     1569            }
     1570        }
     1571        while (system(command));
     1572    } else {
     1573        sprintf(command, "mdconfig -a -t vnode -f %s", fname);
     1574        mddevice = call_program_and_get_last_line_of_output(command);
     1575        if (!strstr(mddevice, "md")) {
     1576            return NULL;
     1577        }
     1578    }
     1579    sprintf(device, "/dev/%s", mddevice);
     1580    return device;
    15541581}
    15551582
     
    15641591 * @return 0 for success, nonzero for failure.
    15651592 */
    1566 int
    1567 kick_vn (char *dname)
    1568 {
    1569     char command[MAX_STR_LEN];
    1570 
    1571     if (strncmp (dname, "/dev/", 5) == 0) {
    1572         dname += 5;
    1573     }
    1574 
    1575     if (atoi (call_program_and_get_last_line_of_output ("/sbin/sysctl -n kern.osreldate")) <
    1576         500000) {
    1577         sprintf (command, "vnconfig -d %s", dname);
    1578         return system (command);
    1579     } else {
    1580         sprintf (command, "mdconfig -d -u %s", dname);
    1581         return system (command);
    1582     }
    1583     /*NOTREACHED*/
    1584     return 255;
     1593int kick_vn(char *dname)
     1594{
     1595    char command[MAX_STR_LEN];
     1596
     1597    if (strncmp(dname, "/dev/", 5) == 0) {
     1598        dname += 5;
     1599    }
     1600
     1601    if (atoi
     1602        (call_program_and_get_last_line_of_output
     1603         ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1604        sprintf(command, "vnconfig -d %s", dname);
     1605        return system(command);
     1606    } else {
     1607        sprintf(command, "mdconfig -d -u %s", dname);
     1608        return system(command);
     1609    }
     1610     /*NOTREACHED*/ return 255;
    15851611}
    15861612#endif
     
    15931619 * @return 0 for success, nonzero for failure.
    15941620 */
    1595 int
    1596 mount_CDROM_here (char *device, char *mountpoint)
    1597 {
    1598     /*@ buffer *******************************************************/
    1599   char *command;
    1600   char *dev;
    1601   char *options;
    1602   int retval;
    1603 
    1604   malloc_string(command);
    1605   malloc_string(dev);
    1606   malloc_string(options);
    1607   assert_string_is_neither_NULL_nor_zerolength(device);
    1608   assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    1609 
    1610   make_hole_for_dir(mountpoint);
    1611   strcpy(options, "ro");
    1612   if (isdigit(device[0]))
    1613     { find_cdrom_device(device, FALSE); }
    1614   else
    1615     { strcpy(dev, device); }
    1616   if (g_ISO_restore_mode)
    1617     {
     1621int mount_CDROM_here(char *device, char *mountpoint)
     1622{
     1623    /*@ buffer ****************************************************** */
     1624    char *command;
     1625    char *dev;
     1626    char *options;
     1627    int retval;
     1628
     1629    malloc_string(command);
     1630    malloc_string(dev);
     1631    malloc_string(options);
     1632    assert_string_is_neither_NULL_nor_zerolength(device);
     1633    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     1634
     1635    make_hole_for_dir(mountpoint);
     1636    strcpy(options, "ro");
     1637    if (isdigit(device[0])) {
     1638        find_cdrom_device(device, FALSE);
     1639    } else {
     1640        strcpy(dev, device);
     1641    }
     1642    if (g_ISO_restore_mode) {
    16181643
    16191644#ifdef __FreeBSD__
    1620       strcpy (dev, make_vn (device));
    1621       if (!dev) {
    1622           sprintf (command, "Unable to mount ISO (make_vn(%s) failed)", device);
    1623           fatal_error (command);
    1624         }
    1625       strcpy (device, dev);
     1645        strcpy(dev, make_vn(device));
     1646        if (!dev) {
     1647            sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",
     1648                    device);
     1649            fatal_error(command);
     1650        }
     1651        strcpy(device, dev);
    16261652#else
    1627       strcat(options,",loop");
    1628 #endif
    1629 
    1630     }
    1631   log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
    1632     /*@ end vars ****************************************************/
     1653        strcat(options, ",loop");
     1654#endif
     1655
     1656    }
     1657    log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
     1658            mountpoint);
     1659    /*@ end vars *************************************************** */
    16331660
    16341661#ifdef __FreeBSD__
    1635   sprintf (command, "mount_cd9660 -r %s %s 2>> %s",
    1636            device, mountpoint, MONDO_LOGFILE);
     1662    sprintf(command, "mount_cd9660 -r %s %s 2>> %s",
     1663            device, mountpoint, MONDO_LOGFILE);
    16371664
    16381665#else
    1639   sprintf (command, "mount %s -o %s -t iso9660 %s 2>> %s",
    1640            device, options, mountpoint, MONDO_LOGFILE);
    1641 #endif
    1642 
    1643   log_msg (4, command);
    1644   if (strncmp(device, "/dev/", 5) == 0)
    1645     {
    1646       retract_CD_tray_and_defeat_autorun();
    1647     }
    1648   retval = system (command);
    1649   log_msg(1, "system(%s) returned %d", command, retval);
    1650 
    1651   paranoid_free(command);
    1652   paranoid_free(dev);
    1653   paranoid_free(options);
    1654   return(retval);
     1666    sprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s",
     1667            device, options, mountpoint, MONDO_LOGFILE);
     1668#endif
     1669
     1670    log_msg(4, command);
     1671    if (strncmp(device, "/dev/", 5) == 0) {
     1672        retract_CD_tray_and_defeat_autorun();
     1673    }
     1674    retval = system(command);
     1675    log_msg(1, "system(%s) returned %d", command, retval);
     1676
     1677    paranoid_free(command);
     1678    paranoid_free(dev);
     1679    paranoid_free(options);
     1680    return (retval);
    16551681}
    16561682
     
    16721698 */
    16731699void
    1674 insist_on_this_cd_number (struct s_bkpinfo* bkpinfo, int cd_number_i_want)
    1675 {
    1676 
    1677     /*@ int **************************************************************/
    1678   int res = 0;
    1679 
    1680 
    1681     /*@ buffers **********************************************************/
    1682   char *tmp;
    1683   char *request;
    1684 
    1685   assert(bkpinfo!=NULL);
    1686   assert(cd_number_i_want > 0);
     1700insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, int cd_number_i_want)
     1701{
     1702
     1703    /*@ int ************************************************************* */
     1704    int res = 0;
     1705
     1706
     1707    /*@ buffers ********************************************************* */
     1708    char *tmp;
     1709    char *request;
     1710
     1711    assert(bkpinfo != NULL);
     1712    assert(cd_number_i_want > 0);
    16871713
    16881714//  log_msg(3, "Insisting on CD number %d", cd_number_i_want);
    16891715
    1690   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1691     {
    1692       log_msg(3, "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
    1693       return;
    1694     }
    1695   malloc_string(tmp);
    1696   malloc_string(request);
    1697   sprintf(tmp, "mkdir -p "MNT_CDROM);
    1698   run_program_and_log_output(tmp, 5);
    1699   if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs)
    1700     {
    1701       log_msg(3, "Remounting CD");
    1702       g_ISO_restore_mode = TRUE;
     1716    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1717        log_msg(3,
     1718                "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
     1719        return;
     1720    }
     1721    malloc_string(tmp);
     1722    malloc_string(request);
     1723    sprintf(tmp, "mkdir -p " MNT_CDROM);
     1724    run_program_and_log_output(tmp, 5);
     1725    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
     1726        || bkpinfo->backup_media_type == nfs) {
     1727        log_msg(3, "Remounting CD");
     1728        g_ISO_restore_mode = TRUE;
    17031729// FIXME --- I'm tempted to do something about this...
    17041730// Why unmount and remount again and again?
    1705       if (is_this_device_mounted(MNT_CDROM)) { run_program_and_log_output("umount "MNT_CDROM, 5); }
    1706       system("mkdir -p /tmp/isodir &> /dev/null");
    1707       sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
    1708       if (!does_file_exist(tmp))
    1709         {
    1710       sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso", bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
    1711       if (does_file_exist(tmp))
    1712         {
    1713           log_msg(1, "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir", bkpinfo->isodir);
    1714           strcpy(bkpinfo->isodir, "/tmp/isodir");
    1715         }
    1716         }
    1717       log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
    1718       if (mount_CDROM_here(tmp, MNT_CDROM)) { fatal_error("Mommy!"); }
    1719 //    g_current_media_number = cd_number_i_want;
    1720 //    return;
    1721     }
    1722   if ((res=what_number_cd_is_this (bkpinfo)) != cd_number_i_want)
    1723     {
    1724       log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
    1725       sprintf (tmp, "Insisting on %s #%d", media_descriptor_string(bkpinfo->backup_media_type), cd_number_i_want);
    1726       sprintf (request, "Please insert %s #%d and press Enter.",
    1727                media_descriptor_string(bkpinfo->backup_media_type),
    1728            cd_number_i_want);
    1729       log_msg (3, tmp);
    1730       while (what_number_cd_is_this (bkpinfo) != cd_number_i_want)
    1731     {
    1732       paranoid_system ("sync");
    1733       if (is_this_device_mounted (MNT_CDROM))
    1734         {
    1735           res = run_program_and_log_output ("umount "MNT_CDROM, FALSE);
    1736         }
    1737       else
    1738         {
    1739           res = 0;
    1740         }
    1741       if (res)
    1742         {
    1743           log_to_screen ("WARNING - failed to unmount CD-ROM drive");
    1744         }
    1745           if (!bkpinfo->please_dont_eject)
    1746             { res = eject_device(bkpinfo->media_device); }
    1747           else
    1748             { res = 0; }
    1749       if (res)
    1750         {
    1751               log_to_screen ("WARNING - failed to eject CD-ROM disk");
    1752         }
    1753           popup_and_OK (request);
    1754           if (!bkpinfo->please_dont_eject)
    1755             {
    1756               inject_device(bkpinfo->media_device);
    1757             }
    1758       paranoid_system ("sync");
    1759     }
    1760       log_msg (1, "Thankyou. Proceeding...");
    1761       g_current_media_number = cd_number_i_want;
    1762     }
    1763   paranoid_free(tmp);
    1764   paranoid_free(request);
     1731        if (is_this_device_mounted(MNT_CDROM)) {
     1732            run_program_and_log_output("umount " MNT_CDROM, 5);
     1733        }
     1734        system("mkdir -p /tmp/isodir &> /dev/null");
     1735        sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,
     1736                bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     1737                cd_number_i_want);
     1738        if (!does_file_exist(tmp)) {
     1739            sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso",
     1740                    bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     1741                    cd_number_i_want);
     1742            if (does_file_exist(tmp)) {
     1743                log_msg(1,
     1744                        "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir",
     1745                        bkpinfo->isodir);
     1746                strcpy(bkpinfo->isodir, "/tmp/isodir");
     1747            }
     1748        }
     1749        log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
     1750        if (mount_CDROM_here(tmp, MNT_CDROM)) {
     1751            fatal_error("Mommy!");
     1752        }
     1753//    g_current_media_number = cd_number_i_want;
     1754//    return;
     1755    }
     1756    if ((res = what_number_cd_is_this(bkpinfo)) != cd_number_i_want) {
     1757        log_msg(3, "Currently, we hold %d but we want %d", res,
     1758                cd_number_i_want);
     1759        sprintf(tmp, "Insisting on %s #%d",
     1760                media_descriptor_string(bkpinfo->backup_media_type),
     1761                cd_number_i_want);
     1762        sprintf(request, "Please insert %s #%d and press Enter.",
     1763                media_descriptor_string(bkpinfo->backup_media_type),
     1764                cd_number_i_want);
     1765        log_msg(3, tmp);
     1766        while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) {
     1767            paranoid_system("sync");
     1768            if (is_this_device_mounted(MNT_CDROM)) {
     1769                res =
     1770                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1771            } else {
     1772                res = 0;
     1773            }
     1774            if (res) {
     1775                log_to_screen("WARNING - failed to unmount CD-ROM drive");
     1776            }
     1777            if (!bkpinfo->please_dont_eject) {
     1778                res = eject_device(bkpinfo->media_device);
     1779            } else {
     1780                res = 0;
     1781            }
     1782            if (res) {
     1783                log_to_screen("WARNING - failed to eject CD-ROM disk");
     1784            }
     1785            popup_and_OK(request);
     1786            if (!bkpinfo->please_dont_eject) {
     1787                inject_device(bkpinfo->media_device);
     1788            }
     1789            paranoid_system("sync");
     1790        }
     1791        log_msg(1, "Thankyou. Proceeding...");
     1792        g_current_media_number = cd_number_i_want;
     1793    }
     1794    paranoid_free(tmp);
     1795    paranoid_free(request);
    17651796}
    17661797
     
    17811812 * @ingroup archiveGroup
    17821813 */
    1783 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *bkpinfo, bool archiving_to_media)
     1814int interactively_obtain_media_parameters_from_user(struct s_bkpinfo
     1815                                                    *bkpinfo,
     1816                                                    bool
     1817                                                    archiving_to_media)
    17841818// archiving_to_media is TRUE if I'm being called by mondoarchive
    17851819// archiving_to_media is FALSE if I'm being called by mondorestore
    17861820{
    1787   char *tmp;
    1788   char *sz_size;
    1789   char *command;
    1790   char *comment;
    1791   char *prompt;
    1792   int i;
    1793   FILE*fin;
    1794 
    1795   malloc_string(tmp);
    1796   malloc_string(sz_size);
    1797   malloc_string(command);
    1798   malloc_string(comment);
    1799   malloc_string(prompt);
    1800   assert(bkpinfo!=NULL);
    1801   sz_size[0] = '\0';
    1802   bkpinfo->nonbootable_backup = FALSE;
     1821    char *tmp;
     1822    char *sz_size;
     1823    char *command;
     1824    char *comment;
     1825    char *prompt;
     1826    int i;
     1827    FILE *fin;
     1828
     1829    malloc_string(tmp);
     1830    malloc_string(sz_size);
     1831    malloc_string(command);
     1832    malloc_string(comment);
     1833    malloc_string(prompt);
     1834    assert(bkpinfo != NULL);
     1835    sz_size[0] = '\0';
     1836    bkpinfo->nonbootable_backup = FALSE;
    18031837
    18041838// Tape, CD, NFS, ...?
    1805   srandom(getpid());
    1806   bkpinfo->backup_media_type = (g_restoring_live_from_cd) ? cdr : which_backup_media_type(bkpinfo->restore_data);
    1807   if (bkpinfo->backup_media_type == none)
    1808     { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1809   if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data)
    1810     { popup_and_OK("Please remove CD/floppy from drive(s)"); }
    1811   log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    1812   if (archiving_to_media)
    1813     {
    1814       sensibly_set_tmpdir_and_scratchdir(bkpinfo);
    1815     }
    1816   bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
    1817   bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1:5;
    1818   bkpinfo->use_lzo =  (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
     1839    srandom(getpid());
     1840    bkpinfo->backup_media_type =
     1841        (g_restoring_live_from_cd) ? cdr :
     1842        which_backup_media_type(bkpinfo->restore_data);
     1843    if (bkpinfo->backup_media_type == none) {
     1844        log_to_screen("User has chosen not to backup the PC");
     1845        finish(1);
     1846    }
     1847    if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {
     1848        popup_and_OK("Please remove CD/floppy from drive(s)");
     1849    }
     1850    log_msg(3, "media type = %s",
     1851            bkptype_to_string(bkpinfo->backup_media_type));
     1852    if (archiving_to_media) {
     1853        sensibly_set_tmpdir_and_scratchdir(bkpinfo);
     1854    }
     1855    bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
     1856    bkpinfo->compression_level =
     1857        (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
     1858    bkpinfo->use_lzo =
     1859        (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
    18191860
    18201861/*
     
    18311872*/
    18321873
    1833   mvaddstr_and_log_it(2, 0, " ");
     1874    mvaddstr_and_log_it(2, 0, " ");
    18341875
    18351876// Find device's /dev (or SCSI) entry
    1836   switch(bkpinfo->backup_media_type)
    1837     {
    1838       case cdr:
    1839       case cdrw:
    1840       case dvd:
    1841     if (archiving_to_media)
    1842           {
    1843             if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?"))
    1844               { bkpinfo->manual_cd_tray = TRUE; }
    1845             if ((bkpinfo->compression_level = which_compression_level()) == -1)
    1846               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1847         sprintf(comment, "What speed is your %s (re)writer?", media_descriptor_string(bkpinfo->backup_media_type));
    1848         if (bkpinfo->backup_media_type==dvd)
    1849           {
    1850         find_dvd_device(bkpinfo->media_device, FALSE);
    1851             strcpy(tmp, "1");
    1852         sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    1853         log_msg(1, "Setting to DVD defaults");
    1854           }
    1855         else
    1856           {
    1857                 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    1858             strcpy(tmp, "4");
    1859         strcpy(sz_size, "650");
    1860         log_msg(1, "Setting to CD defaults");
    1861           }
    1862         if (bkpinfo->backup_media_type != dvd)
    1863           {
    1864             if (!popup_and_get_string("Speed", comment, tmp, 4))
    1865               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1866           }
    1867             bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :)
    1868         sprintf(comment, "How much data (in Megabytes) will each %s store?", media_descriptor_string(bkpinfo->backup_media_type));
    1869         if (!popup_and_get_string("Size", comment, sz_size, 5))
    1870           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1871         for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = atoi(sz_size); }
    1872         if (bkpinfo->media_size[0] <=0)
    1873               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1874           }
    1875       case cdstream:
    1876     if (bkpinfo->disaster_recovery)
    1877       {
    1878             strcpy(bkpinfo->media_device, "/dev/cdrom");
    1879         log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
    1880       }
    1881     else if (bkpinfo->restore_data
    1882         || bkpinfo->backup_media_type == dvd)
    1883       {
    1884             if (!bkpinfo->media_device[0])
    1885               { strcpy(bkpinfo->media_device, "/dev/cdrom"); } // just for the heck of it :)
    1886         log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
    1887         if (bkpinfo->backup_media_type == dvd || find_cdrom_device (bkpinfo->media_device, FALSE))
    1888           {
    1889         log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
    1890             sprintf(comment, "Please specify your %s drive's /dev entry", media_descriptor_string(bkpinfo->backup_media_type));
    1891             if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN/4))
    1892               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1893           }
    1894         log_msg(2, "%s device found at %s", media_descriptor_string(bkpinfo->backup_media_type), bkpinfo->media_device);
    1895       }
    1896     else
    1897       {
    1898         if (find_cdrw_device(bkpinfo->media_device)) { bkpinfo->media_device[0]='\0'; }
    1899         if (bkpinfo->media_device[0])
    1900           {
    1901             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);
    1902             if (!ask_me_yes_or_no(tmp)) { bkpinfo->media_device[0]='\0'; }
    1903           }
    1904            if (!bkpinfo->media_device[0])
    1905           {
    1906         if (g_kernel_version < 2.6)
    1907           {
    1908             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);
    1909           }
    1910         else
    1911           {
    1912             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);
    1913           }
    1914         if (!i)
    1915               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1916           }
    1917       }
    1918     if (bkpinfo->backup_media_type == cdstream)
    1919       {
    1920         for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650; }
    1921       }
    1922     break;
    1923       case udev:
    1924     if (!ask_me_yes_or_no("This option is for advanced users only. Are you sure?"))
    1925       { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1926       case tape:
    1927 
    1928     if (find_tape_device_and_size(bkpinfo->media_device, sz_size))
    1929       {
    1930         log_msg(3, "Ok, using vanilla scsi tape.");
    1931         strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
    1932         if ((fin=fopen(bkpinfo->media_device, "r")))
    1933           { paranoid_fclose(fin); }
    1934         else
    1935           { strcpy(bkpinfo->media_device, "/dev/osst0"); }
    1936       }
    1937     if (bkpinfo->media_device[0])
    1938       {
    1939         if ((fin=fopen(bkpinfo->media_device, "r")))
    1940           { paranoid_fclose(fin); }
    1941         else
    1942           {
    1943         if (does_file_exist("/tmp/mondo-restore.cfg"))
    1944           {
    1945             read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device);
    1946           }
    1947           }
    1948         sprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
    1949       }
    1950     if (bkpinfo->media_device[0])
    1951       {
    1952         sprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
    1953         if (!ask_me_yes_or_no(tmp)) { bkpinfo->media_device[0]='\0'; }
    1954       }
    1955         if (!bkpinfo->media_device[0])
    1956       {
    1957         if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device, MAX_STR_LEN/4))
    1958           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1959       }
    1960     sprintf(tmp, "ls -l %s", bkpinfo->media_device);
    1961     if (run_program_and_log_output(tmp, FALSE))
    1962           { log_to_screen("User has not specified a valid /dev entry"); finish(1); }
    1963     log_msg(4, "sz_size = %s", sz_size);
    1964         sz_size[0] = '\0';
     1877    switch (bkpinfo->backup_media_type) {
     1878    case cdr:
     1879    case cdrw:
     1880    case dvd:
     1881        if (archiving_to_media) {
     1882            if (ask_me_yes_or_no
     1883                ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?"))
     1884            {
     1885                bkpinfo->manual_cd_tray = TRUE;
     1886            }
     1887            if ((bkpinfo->compression_level =
     1888                 which_compression_level()) == -1) {
     1889                log_to_screen("User has chosen not to backup the PC");
     1890                finish(1);
     1891            }
     1892            sprintf(comment, "What speed is your %s (re)writer?",
     1893                    media_descriptor_string(bkpinfo->backup_media_type));
     1894            if (bkpinfo->backup_media_type == dvd) {
     1895                find_dvd_device(bkpinfo->media_device, FALSE);
     1896                strcpy(tmp, "1");
     1897                sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4582 MB
     1898                log_msg(1, "Setting to DVD defaults");
     1899            } else {
     1900                strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
     1901                strcpy(tmp, "4");
     1902                strcpy(sz_size, "650");
     1903                log_msg(1, "Setting to CD defaults");
     1904            }
     1905            if (bkpinfo->backup_media_type != dvd) {
     1906                if (!popup_and_get_string("Speed", comment, tmp, 4)) {
     1907                    log_to_screen("User has chosen not to backup the PC");
     1908                    finish(1);
     1909                }
     1910            }
     1911            bkpinfo->cdrw_speed = atoi(tmp);    // if DVD then this shouldn't ever be used anyway :)
     1912            sprintf(comment,
     1913                    "How much data (in Megabytes) will each %s store?",
     1914                    media_descriptor_string(bkpinfo->backup_media_type));
     1915            if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     1916                log_to_screen("User has chosen not to backup the PC");
     1917                finish(1);
     1918            }
     1919            for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     1920                bkpinfo->media_size[i] = atoi(sz_size);
     1921            }
     1922            if (bkpinfo->media_size[0] <= 0) {
     1923                log_to_screen("User has chosen not to backup the PC");
     1924                finish(1);
     1925            }
     1926        }
     1927    case cdstream:
     1928        if (bkpinfo->disaster_recovery) {
     1929            strcpy(bkpinfo->media_device, "/dev/cdrom");
     1930            log_msg(2, "CD-ROM device assumed to be at %s",
     1931                    bkpinfo->media_device);
     1932        } else if (bkpinfo->restore_data
     1933                   || bkpinfo->backup_media_type == dvd) {
     1934            if (!bkpinfo->media_device[0]) {
     1935                strcpy(bkpinfo->media_device, "/dev/cdrom");
     1936            }                   // just for the heck of it :)
     1937            log_msg(1, "bkpinfo->media_device = %s",
     1938                    bkpinfo->media_device);
     1939            if (bkpinfo->backup_media_type == dvd
     1940                || find_cdrom_device(bkpinfo->media_device, FALSE)) {
     1941                log_msg(1, "bkpinfo->media_device = %s",
     1942                        bkpinfo->media_device);
     1943                sprintf(comment,
     1944                        "Please specify your %s drive's /dev entry",
     1945                        media_descriptor_string(bkpinfo->
     1946                                                backup_media_type));
     1947                if (!popup_and_get_string
     1948                    ("Device?", comment, bkpinfo->media_device,
     1949                     MAX_STR_LEN / 4)) {
     1950                    log_to_screen("User has chosen not to backup the PC");
     1951                    finish(1);
     1952                }
     1953            }
     1954            log_msg(2, "%s device found at %s",
     1955                    media_descriptor_string(bkpinfo->backup_media_type),
     1956                    bkpinfo->media_device);
     1957        } else {
     1958            if (find_cdrw_device(bkpinfo->media_device)) {
     1959                bkpinfo->media_device[0] = '\0';
     1960            }
     1961            if (bkpinfo->media_device[0]) {
     1962                sprintf(tmp,
     1963                        "I think I've found your %s burner at SCSI node %s; am I right on the money?",
     1964                        media_descriptor_string(bkpinfo->
     1965                                                backup_media_type),
     1966                        bkpinfo->media_device);
     1967                if (!ask_me_yes_or_no(tmp)) {
     1968                    bkpinfo->media_device[0] = '\0';
     1969                }
     1970            }
     1971            if (!bkpinfo->media_device[0]) {
     1972                if (g_kernel_version < 2.6) {
     1973                    i = popup_and_get_string("Device node?",
     1974                                             "What is the SCSI node of your CD (re)writer, please?",
     1975                                             bkpinfo->media_device,
     1976                                             MAX_STR_LEN / 4);
     1977                } else {
     1978                    i = popup_and_get_string("/dev entry?",
     1979                                             "What is the /dev entry of your CD (re)writer, please?",
     1980                                             bkpinfo->media_device,
     1981                                             MAX_STR_LEN / 4);
     1982                }
     1983                if (!i) {
     1984                    log_to_screen("User has chosen not to backup the PC");
     1985                    finish(1);
     1986                }
     1987            }
     1988        }
     1989        if (bkpinfo->backup_media_type == cdstream) {
     1990            for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     1991                bkpinfo->media_size[i] = 650;
     1992            }
     1993        }
     1994        break;
     1995    case udev:
     1996        if (!ask_me_yes_or_no
     1997            ("This option is for advanced users only. Are you sure?")) {
     1998            log_to_screen("User has chosen not to backup the PC");
     1999            finish(1);
     2000        }
     2001    case tape:
     2002
     2003        if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) {
     2004            log_msg(3, "Ok, using vanilla scsi tape.");
     2005            strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
     2006            if ((fin = fopen(bkpinfo->media_device, "r"))) {
     2007                paranoid_fclose(fin);
     2008            } else {
     2009                strcpy(bkpinfo->media_device, "/dev/osst0");
     2010            }
     2011        }
     2012        if (bkpinfo->media_device[0]) {
     2013            if ((fin = fopen(bkpinfo->media_device, "r"))) {
     2014                paranoid_fclose(fin);
     2015            } else {
     2016                if (does_file_exist("/tmp/mondo-restore.cfg")) {
     2017                    read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
     2018                                 bkpinfo->media_device);
     2019                }
     2020            }
     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        }
     2025        if (bkpinfo->media_device[0]) {
     2026            sprintf(tmp,
     2027                    "I think I've found your tape streamer at %s; am I right on the money?",
     2028                    bkpinfo->media_device);
     2029            if (!ask_me_yes_or_no(tmp)) {
     2030                bkpinfo->media_device[0] = '\0';
     2031            }
     2032        }
     2033        if (!bkpinfo->media_device[0]) {
     2034            if (!popup_and_get_string
     2035                ("Device name?",
     2036                 "What is the /dev entry of your tape streamer?",
     2037                 bkpinfo->media_device, MAX_STR_LEN / 4)) {
     2038                log_to_screen("User has chosen not to backup the PC");
     2039                finish(1);
     2040            }
     2041        }
     2042        sprintf(tmp, "ls -l %s", bkpinfo->media_device);
     2043        if (run_program_and_log_output(tmp, FALSE)) {
     2044            log_to_screen("User has not specified a valid /dev entry");
     2045            finish(1);
     2046        }
     2047        log_msg(4, "sz_size = %s", sz_size);
     2048        sz_size[0] = '\0';
    19652049/*
    19662050    if ((size_sz[0]=='\0' || atol(size_sz)==0) && archiving_to_media)
     
    19702054      }
    19712055*/
    1972     if (sz_size[0]=='\0')
    1973       { bkpinfo->media_size[0] = 0; }
    1974         else
    1975       { bkpinfo->media_size[0] = friendly_sizestr_to_sizelong (sz_size)/2 - 50; }
    1976     log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
    1977         if (bkpinfo->media_size[0] <= 0) { bkpinfo->media_size[0] = 0; }
    1978     for(i=1; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = bkpinfo->media_size[0]; }
    1979         if (archiving_to_media)
    1980           {
    1981             if ((bkpinfo->compression_level = which_compression_level()) == -1)
    1982               { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    1983           }
    1984         break;
    1985 
    1986 
    1987 
    1988       case nfs:
    1989     if (!bkpinfo->nfs_mount[0]) { strcpy(bkpinfo->nfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1")); }
     2056        if (sz_size[0] == '\0') {
     2057            bkpinfo->media_size[0] = 0;
     2058        } else {
     2059            bkpinfo->media_size[0] =
     2060                friendly_sizestr_to_sizelong(sz_size) / 2 - 50;
     2061        }
     2062        log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
     2063        if (bkpinfo->media_size[0] <= 0) {
     2064            bkpinfo->media_size[0] = 0;
     2065        }
     2066        for (i = 1; i <= MAX_NOOF_MEDIA; i++) {
     2067            bkpinfo->media_size[i] = bkpinfo->media_size[0];
     2068        }
     2069        if (archiving_to_media) {
     2070            if ((bkpinfo->compression_level =
     2071                 which_compression_level()) == -1) {
     2072                log_to_screen("User has chosen not to backup the PC");
     2073                finish(1);
     2074            }
     2075        }
     2076        break;
     2077
     2078
     2079
     2080    case nfs:
     2081        if (!bkpinfo->nfs_mount[0]) {
     2082            strcpy(bkpinfo->nfs_mount,
     2083                   call_program_and_get_last_line_of_output
     2084                   ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     2085        }
    19902086#ifdef __FreeBSD__
    1991         if (TRUE)
     2087        if (TRUE)
    19922088#else
    1993     if (!bkpinfo->disaster_recovery )
    1994 #endif
    1995       {
    1996         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))
    1997           {
    1998         log_to_screen("User has chosen not to backup the PC");
    1999         finish(1);
    2000           }
    2001             if (!bkpinfo->restore_data)
    2002               {
    2003                 if ((bkpinfo->compression_level = which_compression_level()) == -1)
    2004                   {
    2005                     log_to_screen("User has chosen not to backup the PC");
    2006                     finish(1);
    2007                   }
    2008               }
    2009             // check whether already mounted - we better remove
    2010             // surrounding spaces and trailing '/' for this
    2011             strip_spaces (bkpinfo->nfs_mount);
    2012             if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
    2013                bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
    2014             sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3",bkpinfo->nfs_mount);
    2015             strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command));
    2016       }
    2017     if (bkpinfo->disaster_recovery)
    2018           {
    2019         system("umount /tmp/isodir 2> /dev/null");
    2020         if (!popup_and_get_string("NFS share", "Which remote NFS share should I mount?", bkpinfo->nfs_mount, MAX_STR_LEN))
    2021           {
    2022                 log_to_screen("User has chosen not to backup the PC");
    2023                 finish(1);
    2024           }
    2025           }
    2026         if (!is_this_device_mounted(bkpinfo->nfs_mount))
    2027           {
    2028                   sprintf(bkpinfo->isodir, "/tmp/isodir.mondo.%d", (int)(random()%32768));
    2029                   sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    2030                   run_program_and_log_output(command, 5);
    2031                   sprintf(tmp, "mount %s -t nfs %s", bkpinfo->nfs_mount, bkpinfo->isodir);
    2032                   run_program_and_log_output(tmp, 5);
    2033                   malloc_string(g_selfmounted_isodir);
    2034                   strcpy(g_selfmounted_isodir, bkpinfo->isodir);
    2035           }
    2036     if (!is_this_device_mounted(bkpinfo->nfs_mount))
    2037       {
    2038         popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
    2039         finish(1);
    2040       }
    2041         strcpy(tmp, bkpinfo->nfs_remote_dir);
    2042         if (!popup_and_get_string("Directory", "Which directory within that mountpoint?", tmp, MAX_STR_LEN))
    2043           {
    2044             log_to_screen("User has chosen not to backup the PC");
    2045              finish(1);
    2046           }
    2047         strcpy(bkpinfo->nfs_remote_dir, tmp);
    2048         // check whether writable - we better remove surrounding spaces for this
    2049         strip_spaces (bkpinfo->nfs_remote_dir);
    2050         sprintf (command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
    2051                                   bkpinfo->nfs_remote_dir);
    2052         while (run_program_and_log_output (command, FALSE)) {
    2053             strcpy(tmp, bkpinfo->nfs_remote_dir);
    2054             sprintf (prompt,
    2055                      "Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup.",
    2056                      bkpinfo->nfs_remote_dir, bkpinfo->isodir);
    2057             if(!popup_and_get_string ("Directory", prompt, tmp, MAX_STR_LEN)) {
    2058                 log_to_screen("User has chosen not to backup the PC");
    2059                 finish(1);
    2060             }
    2061             strcpy(bkpinfo->nfs_remote_dir, tmp);
    2062             // check whether writable - we better remove surrounding space s for this
    2063             strip_spaces (bkpinfo->nfs_remote_dir);
    2064             sprintf (command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
    2065                                     bkpinfo->nfs_remote_dir);
    2066         }
    2067 
    2068     for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650; }
    2069         log_msg(3, "Just set nfs_remote_dir to %s", bkpinfo->nfs_remote_dir);
    2070     log_msg(3, "isodir is still %s", bkpinfo->isodir);
    2071     break;
    2072 
    2073       case iso:
    2074         if (!bkpinfo->disaster_recovery)
    2075           {
    2076              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))
    2077           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2078              if (archiving_to_media) {
    2079                  if ((bkpinfo->compression_level = which_compression_level()) == -1)
    2080                      { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2081                  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 or DVD's you plan to backup to.", sz_size, 16))
    2082                      { log_to_screen ("User has chosen not to backup the PC"); finish(1); }
    2083                  for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = atoi (sz_size); }
    2084              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))
    2085           { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2086              } else {
    2087                  for (i=0;i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650;}
    2088              }
    2089           }
    2090     break;
    2091       default:
    2092     fatal_error("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
    2093     }
    2094 
    2095   if (archiving_to_media)
    2096     {
     2089        if (!bkpinfo->disaster_recovery)
     2090#endif
     2091        {
     2092            if (!popup_and_get_string
     2093                ("NFS dir.",
     2094                 "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.)",
     2095                 bkpinfo->nfs_mount, MAX_STR_LEN / 4)) {
     2096                log_to_screen("User has chosen not to backup the PC");
     2097                finish(1);
     2098            }
     2099            if (!bkpinfo->restore_data) {
     2100                if ((bkpinfo->compression_level =
     2101                     which_compression_level()) == -1) {
     2102                    log_to_screen("User has chosen not to backup the PC");
     2103                    finish(1);
     2104                }
     2105            }
     2106            // check whether already mounted - we better remove
     2107            // surrounding spaces and trailing '/' for this
     2108            strip_spaces(bkpinfo->nfs_mount);
     2109            if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
     2110                bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
     2111            sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3",
     2112                    bkpinfo->nfs_mount);
     2113            strcpy(bkpinfo->isodir,
     2114                   call_program_and_get_last_line_of_output(command));
     2115        }
     2116        if (bkpinfo->disaster_recovery) {
     2117            system("umount /tmp/isodir 2> /dev/null");
     2118            if (!popup_and_get_string
     2119                ("NFS share", "Which remote NFS share should I mount?",
     2120                 bkpinfo->nfs_mount, MAX_STR_LEN)) {
     2121                log_to_screen("User has chosen not to backup the PC");
     2122                finish(1);
     2123            }
     2124        }
     2125        if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
     2126            sprintf(bkpinfo->isodir, "/tmp/isodir.mondo.%d",
     2127                    (int) (random() % 32768));
     2128            sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     2129            run_program_and_log_output(command, 5);
     2130            sprintf(tmp, "mount %s -t nfs %s", bkpinfo->nfs_mount,
     2131                    bkpinfo->isodir);
     2132            run_program_and_log_output(tmp, 5);
     2133            malloc_string(g_selfmounted_isodir);
     2134            strcpy(g_selfmounted_isodir, bkpinfo->isodir);
     2135        }
     2136        if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
     2137            popup_and_OK
     2138                ("Please mount that partition before you try to backup to or restore from it.");
     2139            finish(1);
     2140        }
     2141        strcpy(tmp, bkpinfo->nfs_remote_dir);
     2142        if (!popup_and_get_string
     2143            ("Directory", "Which directory within that mountpoint?", tmp,
     2144             MAX_STR_LEN)) {
     2145            log_to_screen("User has chosen not to backup the PC");
     2146            finish(1);
     2147        }
     2148        strcpy(bkpinfo->nfs_remote_dir, tmp);
     2149        // check whether writable - we better remove surrounding spaces for this
     2150        strip_spaces(bkpinfo->nfs_remote_dir);
     2151        sprintf(command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
     2152                bkpinfo->nfs_remote_dir);
     2153        while (run_program_and_log_output(command, FALSE)) {
     2154            strcpy(tmp, bkpinfo->nfs_remote_dir);
     2155            sprintf(prompt,
     2156                    "Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup.",
     2157                    bkpinfo->nfs_remote_dir, bkpinfo->isodir);
     2158            if (!popup_and_get_string
     2159                ("Directory", prompt, tmp, MAX_STR_LEN)) {
     2160                log_to_screen("User has chosen not to backup the PC");
     2161                finish(1);
     2162            }
     2163            strcpy(bkpinfo->nfs_remote_dir, tmp);
     2164            // check whether writable - we better remove surrounding space s for this
     2165            strip_spaces(bkpinfo->nfs_remote_dir);
     2166            sprintf(command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
     2167                    bkpinfo->nfs_remote_dir);
     2168        }
     2169
     2170        for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     2171            bkpinfo->media_size[i] = 650;
     2172        }
     2173        log_msg(3, "Just set nfs_remote_dir to %s",
     2174                bkpinfo->nfs_remote_dir);
     2175        log_msg(3, "isodir is still %s", bkpinfo->isodir);
     2176        break;
     2177
     2178    case iso:
     2179        if (!bkpinfo->disaster_recovery) {
     2180            if (!popup_and_get_string
     2181                ("Storage dir.",
     2182                 "Please enter the full path that contains your ISO images.  Example: /mnt/raid0_0",
     2183                 bkpinfo->isodir, MAX_STR_LEN / 4)) {
     2184                log_to_screen("User has chosen not to backup the PC");
     2185                finish(1);
     2186            }
     2187            if (archiving_to_media) {
     2188                if ((bkpinfo->compression_level =
     2189                     which_compression_level()) == -1) {
     2190                    log_to_screen("User has chosen not to backup the PC");
     2191                    finish(1);
     2192                }
     2193                if (!popup_and_get_string
     2194                    ("ISO size.",
     2195                     "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 or DVD's you plan to backup to.",
     2196                     sz_size, 16)) {
     2197                    log_to_screen("User has chosen not to backup the PC");
     2198                    finish(1);
     2199                }
     2200                for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     2201                    bkpinfo->media_size[i] = atoi(sz_size);
     2202                }
     2203                if (!popup_and_get_string
     2204                    ("Prefix.",
     2205                     "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files",
     2206                     bkpinfo->prefix, MAX_STR_LEN / 4)) {
     2207                    log_to_screen("User has chosen not to backup the PC");
     2208                    finish(1);
     2209                }
     2210            } else {
     2211                for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     2212                    bkpinfo->media_size[i] = 650;
     2213                }
     2214            }
     2215        }
     2216        break;
     2217    default:
     2218        fatal_error
     2219            ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
     2220    }
     2221
     2222    if (archiving_to_media) {
    20972223
    20982224#ifdef __FreeBSD__
    2099     strcpy (bkpinfo->boot_device, call_program_and_get_last_line_of_output
    2100         ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     2225        strcpy(bkpinfo->boot_device,
     2226               call_program_and_get_last_line_of_output
     2227               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    21012228#else
    2102     strcpy (bkpinfo->boot_device, call_program_and_get_last_line_of_output
    2103             ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    2104 #endif
    2105       i = which_boot_loader(bkpinfo->boot_device);
    2106       if (i=='U') // unknown
    2107         {
     2229        strcpy(bkpinfo->boot_device,
     2230               call_program_and_get_last_line_of_output
     2231               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     2232#endif
     2233        i = which_boot_loader(bkpinfo->boot_device);
     2234        if (i == 'U')           // unknown
     2235        {
    21082236
    21092237#ifdef __FreeBSD__
    2110           if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device, MAX_STR_LEN/4))
    2111             { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2112           i = which_boot_loader (bkpinfo->boot_device);
     2238            if (!popup_and_get_string
     2239                ("Boot device",
     2240                 "What is your boot device? (e.g. /dev/ad0)",
     2241                 bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     2242                log_to_screen("User has chosen not to backup the PC");
     2243                finish(1);
     2244            }
     2245            i = which_boot_loader(bkpinfo->boot_device);
    21132246#else
    2114           if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", bkpinfo->boot_device, MAX_STR_LEN/4))
    2115             { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2116           if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { i='L'; }
    2117           else if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { i='E'; }
    2118           else if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { i='G'; }
    2119           else { i = 'U'; }
    2120 #endif
    2121           if (i == 'U')
    2122             {
    2123           if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
     2247            if (!popup_and_get_string
     2248                ("Boot device",
     2249                 "What is your boot device? (e.g. /dev/hda)",
     2250                 bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     2251                log_to_screen("User has chosen not to backup the PC");
     2252                finish(1);
     2253            }
     2254            if (does_string_exist_in_boot_block
     2255                (bkpinfo->boot_device, "LILO")) {
     2256                i = 'L';
     2257            } else
     2258                if (does_string_exist_in_boot_block
     2259                    (bkpinfo->boot_device, "ELILO")) {
     2260                i = 'E';
     2261            } else
     2262                if (does_string_exist_in_boot_block
     2263                    (bkpinfo->boot_device, "GRUB")) {
     2264                i = 'G';
     2265            } else {
     2266                i = 'U';
     2267            }
     2268#endif
     2269            if (i == 'U') {
     2270                if (ask_me_yes_or_no
     2271                    ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
     2272                {
     2273                    i = 'R';    // raw
     2274                } else {
     2275                    log_to_screen
     2276                        ("I cannot find your boot loader. Please run mondoarchive with parameters.");
     2277                    finish(1);
     2278                }
     2279            }
     2280        }
     2281        bkpinfo->boot_loader = i;
     2282        strcpy(bkpinfo->include_paths, "/");
     2283        if (!popup_and_get_string
     2284            ("Backup paths",
     2285             "Please enter paths which you want me to backup. The default is '/' (i.e. everything).",
     2286             bkpinfo->include_paths, MAX_STR_LEN)) {
     2287            log_to_screen("User has chosen not to backup the PC");
     2288            finish(1);
     2289        }
     2290        strcpy(tmp, list_of_NFS_mounts_only());
     2291        if (strlen(tmp) > 2) {
     2292            if (bkpinfo->exclude_paths[0]) {
     2293                strcat(bkpinfo->exclude_paths, " ");
     2294            }
     2295            strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
     2296        }
     2297// NTFS
     2298        strcpy(tmp,
     2299               call_program_and_get_last_line_of_output
     2300               ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     2301        if (strlen(tmp) > 2) {
     2302            if (!popup_and_get_string
     2303                ("NTFS partitions",
     2304                 "Please enter/confirm the NTFS partitions you wish to backup as well.",
     2305                 tmp, MAX_STR_LEN / 4)) {
     2306                log_to_screen("User has chosen not to backup the PC");
     2307                finish(1);
     2308            }
     2309            strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4);
     2310        }
     2311
     2312
     2313        if (!popup_and_get_string
     2314            ("Exclude paths",
     2315             "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.",
     2316             bkpinfo->exclude_paths, MAX_STR_LEN)) {
     2317            log_to_screen("User has chosen not to backup the PC");
     2318            finish(1);
     2319        }
     2320        bkpinfo->make_cd_use_lilo = FALSE;
     2321        bkpinfo->backup_data = TRUE;
     2322        bkpinfo->verify_data =
     2323            ask_me_yes_or_no
     2324            ("Will you want to verify your backups after Mondo has created them?");
     2325
     2326#ifndef __FreeBSD__
     2327        if (!ask_me_yes_or_no
     2328            ("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."))
     2329#endif
    21242330        {
    2125           i = 'R'; // raw
    2126         }
    2127           else
    2128         {
    2129           log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); finish(1);
    2130         }
    2131         }
    2132     }
    2133       bkpinfo->boot_loader = i;
    2134       strcpy(bkpinfo->include_paths, "/");
    2135       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))
    2136         { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2137       strcpy(tmp, list_of_NFS_mounts_only());
    2138       if (strlen(tmp)>2)
    2139         {
    2140           if (bkpinfo->exclude_paths[0]) { strcat(bkpinfo->exclude_paths, " "); }
    2141           strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
    2142     }
    2143 
    2144 // NTFS
    2145       strcpy(tmp, call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
    2146       if (strlen(tmp) > 2)
    2147         {
    2148       if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp, MAX_STR_LEN/4))
    2149             { log_to_screen ("User has chosen not to backup the PC"); finish(1); }
    2150           strncpy (bkpinfo->image_devs, tmp, MAX_STR_LEN/4);
    2151     }
    2152 
    2153 
    2154       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))
    2155         { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2156       bkpinfo->make_cd_use_lilo = FALSE;
    2157       bkpinfo->backup_data = TRUE;
    2158       bkpinfo->verify_data = ask_me_yes_or_no("Will you want to verify your backups after Mondo has created them?");
    2159 
    2160 #ifndef __FreeBSD__
    2161       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."))
    2162 #endif
    2163         { strcpy(bkpinfo->kernel_path, "FAILSAFE"); }
    2164 
    2165       if (!ask_me_yes_or_no("Are you sure you want to proceed? Hit 'no' to abort."))
    2166         { log_to_screen("User has chosen not to backup the PC"); finish(1); }
    2167     }
    2168   else
    2169     {
    2170       bkpinfo->restore_data = TRUE; // probably...
    2171     }
    2172 
    2173   if (bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs)
    2174     {
    2175       g_ISO_restore_mode = TRUE;
    2176     }
    2177 
     2331            strcpy(bkpinfo->kernel_path, "FAILSAFE");
     2332        }
     2333
     2334        if (!ask_me_yes_or_no
     2335            ("Are you sure you want to proceed? Hit 'no' to abort.")) {
     2336            log_to_screen("User has chosen not to backup the PC");
     2337            finish(1);
     2338        }
     2339    } else {
     2340        bkpinfo->restore_data = TRUE;   // probably...
     2341    }
     2342
     2343    if (bkpinfo->backup_media_type == iso
     2344        || bkpinfo->backup_media_type == nfs) {
     2345        g_ISO_restore_mode = TRUE;
     2346    }
    21782347#ifdef __FreeSD__
    21792348// skip
    21802349#else
    2181   if (bkpinfo->backup_media_type == nfs)
    2182     {
    2183       sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3", bkpinfo->nfs_mount);
     2350    if (bkpinfo->backup_media_type == nfs) {
     2351        sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3",
     2352                bkpinfo->nfs_mount);
    21842353//      strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp));
    2185       log_msg(3, "I think the NFS mount is mounted at %s", bkpinfo->isodir);
    2186     }
    2187   log_it("isodir = %s", bkpinfo->isodir);
    2188   log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
    2189 #endif
    2190 
    2191   log_it("media device = %s", bkpinfo->media_device);
    2192   log_it("media size = %ld", bkpinfo->media_size[1]);
    2193   log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    2194   log_it("compression = %ld", bkpinfo->compression_level);
    2195   log_it("include_paths = '%s'", bkpinfo->include_paths);
    2196   log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);
    2197   log_it("scratchdir = '%s'", bkpinfo->scratchdir);
    2198   log_it("tmpdir = '%s'", bkpinfo->tmpdir);
    2199   log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
    2200   if (bkpinfo->media_size[0] < 0)
    2201     {
    2202       if (archiving_to_media)
    2203         {
    2204           fatal_error("Media size is less than zero.");
    2205         }
    2206       else
    2207         {
    2208       log_msg(2, "Warning - media size is less than zero.");
    2209       bkpinfo->media_size[0] = 0;
    2210     }
    2211     }
    2212   paranoid_free(tmp);
    2213   paranoid_free(sz_size);
    2214   paranoid_free(command);
    2215   paranoid_free(comment);
    2216   paranoid_free(prompt);
    2217   return(0);
     2354        log_msg(3, "I think the NFS mount is mounted at %s",
     2355                bkpinfo->isodir);
     2356    }
     2357    log_it("isodir = %s", bkpinfo->isodir);
     2358    log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
     2359#endif
     2360
     2361    log_it("media device = %s", bkpinfo->media_device);
     2362    log_it("media size = %ld", bkpinfo->media_size[1]);
     2363    log_it("media type = %s",
     2364           bkptype_to_string(bkpinfo->backup_media_type));
     2365    log_it("compression = %ld", bkpinfo->compression_level);
     2366    log_it("include_paths = '%s'", bkpinfo->include_paths);
     2367    log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);
     2368    log_it("scratchdir = '%s'", bkpinfo->scratchdir);
     2369    log_it("tmpdir = '%s'", bkpinfo->tmpdir);
     2370    log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device,
     2371           bkpinfo->boot_loader);
     2372    if (bkpinfo->media_size[0] < 0) {
     2373        if (archiving_to_media) {
     2374            fatal_error("Media size is less than zero.");
     2375        } else {
     2376            log_msg(2, "Warning - media size is less than zero.");
     2377            bkpinfo->media_size[0] = 0;
     2378        }
     2379    }
     2380    paranoid_free(tmp);
     2381    paranoid_free(sz_size);
     2382    paranoid_free(command);
     2383    paranoid_free(comment);
     2384    paranoid_free(prompt);
     2385    return (0);
    22182386}
    22192387
     
    22322400char *list_of_NFS_devices_and_mounts(void)
    22332401{
    2234   char *exclude_these_devices;
    2235   char *exclude_these_directories;
    2236   static char result_sz[512];
    2237 
    2238   malloc_string(exclude_these_devices);
    2239   malloc_string(exclude_these_directories);
    2240   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;}'"));
    2241   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;}'"));
    2242   sprintf(result_sz, "%s %s", exclude_these_directories, exclude_these_devices);
    2243   paranoid_free(exclude_these_devices);
    2244   paranoid_free(exclude_these_directories);
    2245   return(result_sz);
     2402    char *exclude_these_devices;
     2403    char *exclude_these_directories;
     2404    static char result_sz[512];
     2405
     2406    malloc_string(exclude_these_devices);
     2407    malloc_string(exclude_these_directories);
     2408    strcpy(exclude_these_directories,
     2409           call_program_and_get_last_line_of_output
     2410           ("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2411    strcpy(exclude_these_devices,
     2412           call_program_and_get_last_line_of_output
     2413           ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2414    sprintf(result_sz, "%s %s", exclude_these_directories,
     2415            exclude_these_devices);
     2416    paranoid_free(exclude_these_devices);
     2417    paranoid_free(exclude_these_directories);
     2418    return (result_sz);
    22462419}
    22472420
     
    22572430char *list_of_NFS_mounts_only(void)
    22582431{
    2259   char *exclude_these_devices;
    2260   char *exclude_these_directories;
    2261   static char result_sz[512];
    2262 
    2263   malloc_string(exclude_these_devices);
    2264   malloc_string(exclude_these_directories);
    2265   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;}'"));
    2266   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;}'"));
    2267   sprintf(result_sz, "%s", exclude_these_directories);
    2268   paranoid_free(exclude_these_devices);
    2269   paranoid_free(exclude_these_directories);
    2270   return(result_sz);
     2432    char *exclude_these_devices;
     2433    char *exclude_these_directories;
     2434    static char result_sz[512];
     2435
     2436    malloc_string(exclude_these_devices);
     2437    malloc_string(exclude_these_directories);
     2438    strcpy(exclude_these_directories,
     2439           call_program_and_get_last_line_of_output
     2440           ("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2441    strcpy(exclude_these_devices,
     2442           call_program_and_get_last_line_of_output
     2443           ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2444    sprintf(result_sz, "%s", exclude_these_directories);
     2445    paranoid_free(exclude_these_devices);
     2446    paranoid_free(exclude_these_directories);
     2447    return (result_sz);
    22712448}
    22722449
     
    22842461 * @ingroup deviceGroup
    22852462 */
    2286 void make_fifo(char*store_name_here, char*stub)
    2287 {
    2288   char *tmp;
    2289 
    2290   malloc_string(tmp);
    2291   assert_string_is_neither_NULL_nor_zerolength(stub);
    2292 
    2293   sprintf(store_name_here, "%s%d%d", stub, (int)(random()%32768), (int)(random()%32768));
    2294   make_hole_for_file(store_name_here);
    2295   mkfifo(store_name_here, S_IRWXU|S_IRWXG);
    2296   sprintf(tmp, "chmod 770 %s", store_name_here);
    2297   paranoid_system(tmp);
    2298   paranoid_free(tmp);
     2463void make_fifo(char *store_name_here, char *stub)
     2464{
     2465    char *tmp;
     2466
     2467    malloc_string(tmp);
     2468    assert_string_is_neither_NULL_nor_zerolength(stub);
     2469
     2470    sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
     2471            (int) (random() % 32768));
     2472    make_hole_for_file(store_name_here);
     2473    mkfifo(store_name_here, S_IRWXU | S_IRWXG);
     2474    sprintf(tmp, "chmod 770 %s", store_name_here);
     2475    paranoid_system(tmp);
     2476    paranoid_free(tmp);
    22992477}
    23002478
     
    23122490void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
    23132491{
    2314   char *tmp, *command, *sz;
    2315 
    2316   malloc_string(tmp);
    2317   malloc_string(command);
    2318   malloc_string(sz);
    2319   assert(bkpinfo!=NULL);
     2492    char *tmp, *command, *sz;
     2493
     2494    malloc_string(tmp);
     2495    malloc_string(command);
     2496    malloc_string(sz);
     2497    assert(bkpinfo != NULL);
    23202498
    23212499#ifdef __FreeBSD__
    2322       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;}'"));
     2500    strcpy(tmp,
     2501           call_program_and_get_last_line_of_output
     2502           ("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;}'"));
    23232503#else
    2324       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;}'"));
    2325 #endif
    2326 
    2327       if (tmp[0]!='/') { strcpy(sz, tmp); strcpy(tmp, "/"); strcat(tmp, sz); }
    2328       if (!tmp[0]) {
    2329       fatal_error ("I couldn't figure out the tempdir!");
    2330       }
    2331       sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, (int)(random()%32768));
    2332       log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    2333 
    2334       sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, (int)(random()%32768));
    2335       log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    2336 
    2337       sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    2338      
    2339       sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
    2340       paranoid_system(command);
    2341   paranoid_free(tmp);
    2342   paranoid_free(command);
    2343   paranoid_free(sz);
     2504    strcpy(tmp,
     2505           call_program_and_get_last_line_of_output
     2506           ("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;}'"));
     2507#endif
     2508
     2509    if (tmp[0] != '/') {
     2510        strcpy(sz, tmp);
     2511        strcpy(tmp, "/");
     2512        strcat(tmp, sz);
     2513    }
     2514    if (!tmp[0]) {
     2515        fatal_error("I couldn't figure out the tempdir!");
     2516    }
     2517    sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,
     2518            (int) (random() % 32768));
     2519    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
     2520
     2521    sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp,
     2522            (int) (random() % 32768));
     2523    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
     2524
     2525    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     2526            bkpinfo->scratchdir);
     2527
     2528    sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2529    paranoid_system(command);
     2530    paranoid_free(tmp);
     2531    paranoid_free(command);
     2532    paranoid_free(sz);
    23442533}
    23452534
     
    23602549 * @return TRUE if @p dev exists, FALSE if it doesn't.
    23612550 */
    2362 bool set_dev_to_this_if_rx_OK(char *output, char*dev)
    2363 {
    2364   char *command;
    2365 
    2366   malloc_string(command);
    2367   if (!dev || dev[0]=='\0') { output[0]='\0'; return(FALSE); }
     2551bool set_dev_to_this_if_rx_OK(char *output, char *dev)
     2552{
     2553    char *command;
     2554
     2555    malloc_string(command);
     2556    if (!dev || dev[0] == '\0') {
     2557        output[0] = '\0';
     2558        return (FALSE);
     2559    }
    23682560//  assert_string_is_neither_NULL_nor_zerolength(dev);
    2369   log_msg(10, "Injecting %s", dev);
    2370   inject_device(dev);
    2371   if (!does_file_exist(dev)) { log_msg(10, "%s doesn't exist. Returning FALSE.", dev); return(FALSE); }
    2372   sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
    2373   if (!run_program_and_log_output(command, FALSE) && !run_program_and_log_output(command, FALSE))
    2374     { strcpy(output, dev); log_msg(4, "Found it - %s", dev); return(TRUE); }
    2375   else
    2376     { output[0]='\0'; log_msg(4, "It's not %s",dev); return(FALSE); }
     2561    log_msg(10, "Injecting %s", dev);
     2562    inject_device(dev);
     2563    if (!does_file_exist(dev)) {
     2564        log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
     2565        return (FALSE);
     2566    }
     2567    sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
     2568            512L, dev);
     2569    if (!run_program_and_log_output(command, FALSE)
     2570        && !run_program_and_log_output(command, FALSE)) {
     2571        strcpy(output, dev);
     2572        log_msg(4, "Found it - %s", dev);
     2573        return (TRUE);
     2574    } else {
     2575        output[0] = '\0';
     2576        log_msg(4, "It's not %s", dev);
     2577        return (FALSE);
     2578    }
    23772579}
    23782580
     
    23902592int what_number_cd_is_this(struct s_bkpinfo *bkpinfo)
    23912593{
    2392   int cd_number=-1;
    2393   char *mountdev;
    2394   char *tmp;
    2395 
    2396   malloc_string(mountdev);
    2397   malloc_string(tmp);
    2398   assert(bkpinfo!=NULL);
     2594    int cd_number = -1;
     2595    char *mountdev;
     2596    char *tmp;
     2597
     2598    malloc_string(mountdev);
     2599    malloc_string(tmp);
     2600    assert(bkpinfo != NULL);
    23992601//  log_it("Asking what_number_cd_is_this");
    2400   if (g_ISO_restore_mode)
    2401     {
    2402       sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
     2602    if (g_ISO_restore_mode) {
     2603        sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    24032604//      log_it("tmp = %s", tmp);
    24042605
    2405       strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
    2406       strcat(mountdev, "/archives/THIS-CD-NUMBER");
     2606        strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
     2607        strcat(mountdev, "/archives/THIS-CD-NUMBER");
    24072608//      log_it("mountdev = %s", mountdev);
    2408       cd_number = atoi(last_line_of_file(mountdev));
     2609        cd_number = atoi(last_line_of_file(mountdev));
    24092610//      log_it("cd_number = %d", cd_number);
    2410 paranoid_free(mountdev);
    2411 paranoid_free(tmp);
    2412       return(cd_number);
    2413     }
    2414 
    2415   strcpy(mountdev, bkpinfo->media_device);
    2416   if (!mountdev[0])
    2417     {
    2418       log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
    2419       find_cdrom_device(bkpinfo->media_device, FALSE);
    2420     }
    2421   if (! is_this_device_mounted(MNT_CDROM))
    2422     { mount_CDROM_here(mountdev, MNT_CDROM); }
    2423   cd_number = atoi(last_line_of_file(MNT_CDROM"/archives/THIS-CD-NUMBER"));
     2611        paranoid_free(mountdev);
     2612        paranoid_free(tmp);
     2613        return (cd_number);
     2614    }
     2615
     2616    strcpy(mountdev, bkpinfo->media_device);
     2617    if (!mountdev[0]) {
     2618        log_it
     2619            ("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
     2620        find_cdrom_device(bkpinfo->media_device, FALSE);
     2621    }
     2622    if (!is_this_device_mounted(MNT_CDROM)) {
     2623        mount_CDROM_here(mountdev, MNT_CDROM);
     2624    }
     2625    cd_number =
     2626        atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    24242627//  log_it("cd_number..later.. = %d", cd_number);
    2425 paranoid_free(mountdev);
    2426 paranoid_free(tmp);
    2427   return(cd_number);
     2628    paranoid_free(mountdev);
     2629    paranoid_free(tmp);
     2630    return (cd_number);
    24282631}
    24292632
     
    24412644 * The mountpoint (where it's mounted) will obviously be '/'.
    24422645 */
    2443 char *
    2444 where_is_root_mounted ()
    2445 {
    2446     /*@ buffers *****************/
    2447   static char tmp[MAX_STR_LEN];
     2646char *where_is_root_mounted()
     2647{
     2648    /*@ buffers **************** */
     2649    static char tmp[MAX_STR_LEN];
    24482650
    24492651
    24502652#ifdef __FreeBSD__
    2451   strcpy (tmp, call_program_and_get_last_line_of_output
    2452           ("mount | grep \" on / \" | cut -d' ' -f1"));
     2653    strcpy(tmp, call_program_and_get_last_line_of_output
     2654           ("mount | grep \" on / \" | cut -d' ' -f1"));
    24532655#else
    2454   strcpy (tmp, call_program_and_get_last_line_of_output
    2455       ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
    2456   if (strstr(tmp, "/dev/cciss/")) {
    2457       strcpy (tmp, call_program_and_get_last_line_of_output
    2458               ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
    2459   }
    2460   if (strstr(tmp, "/dev/md"))
    2461     {
    2462       strcpy(tmp,
    2463          call_program_and_get_last_line_of_output
    2464          ("mount | grep \" on / \" | cut -d' ' -f1"));
    2465     }
    2466 #endif
    2467 
    2468   return (tmp);
     2656    strcpy(tmp, call_program_and_get_last_line_of_output
     2657           ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
     2658    if (strstr(tmp, "/dev/cciss/")) {
     2659        strcpy(tmp, call_program_and_get_last_line_of_output
     2660               ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
     2661    }
     2662    if (strstr(tmp, "/dev/md")) {
     2663        strcpy(tmp,
     2664               call_program_and_get_last_line_of_output
     2665               ("mount | grep \" on / \" | cut -d' ' -f1"));
     2666    }
     2667#endif
     2668
     2669    return (tmp);
    24692670}
    24702671
     
    24772678 */
    24782679#ifdef __FreeBSD__
    2479 char which_boot_loader (char *which_device)
    2480 {
    2481   int count_lilos = 0;
    2482   int count_grubs = 0;
    2483   int count_boot0s = 0;
    2484   int count_dangerouslydedicated = 0;
    2485 
    2486   log_it ("looking at drive %s's MBR", which_device);
    2487   if (does_string_exist_in_boot_block (which_device, "GRUB"))
    2488       { count_grubs++; }
    2489   if (does_string_exist_in_boot_block (which_device, "LILO"))
    2490       { count_lilos++; }
    2491   if (does_string_exist_in_boot_block (which_device, "Drive"))
    2492       { count_boot0s++; }
    2493   if (does_string_exist_in_first_N_blocks (which_device, "FreeBSD/i386", 17))
    2494       { count_dangerouslydedicated++; }
    2495   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);
    2496 
    2497   if (count_grubs && !count_lilos)
    2498     { return ('G'); }
    2499   else if (count_lilos && !count_grubs)
    2500     { return ('L'); }
    2501  else if (count_grubs == 1 && count_lilos == 1)
    2502     {
    2503       log_it ("I'll bet you used to use LILO but switched to GRUB...");
    2504       return ('G');
    2505     }
    2506   else if (count_boot0s == 1)
    2507       { return ('B'); }
    2508   else if (count_dangerouslydedicated)
    2509       { return ('D'); }
    2510   else
    2511     {
    2512       log_it ("Unknown boot loader");
    2513       return ('U');
    2514     }
     2680char which_boot_loader(char *which_device)
     2681{
     2682    int count_lilos = 0;
     2683    int count_grubs = 0;
     2684    int count_boot0s = 0;
     2685    int count_dangerouslydedicated = 0;
     2686
     2687    log_it("looking at drive %s's MBR", which_device);
     2688    if (does_string_exist_in_boot_block(which_device, "GRUB")) {
     2689        count_grubs++;
     2690    }
     2691    if (does_string_exist_in_boot_block(which_device, "LILO")) {
     2692        count_lilos++;
     2693    }
     2694    if (does_string_exist_in_boot_block(which_device, "Drive")) {
     2695        count_boot0s++;
     2696    }
     2697    if (does_string_exist_in_first_N_blocks
     2698        (which_device, "FreeBSD/i386", 17)) {
     2699        count_dangerouslydedicated++;
     2700    }
     2701    log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n",
     2702           count_grubs, count_lilos, count_elilos, count_boot0s,
     2703           count_dangerouslydedicated);
     2704
     2705    if (count_grubs && !count_lilos) {
     2706        return ('G');
     2707    } else if (count_lilos && !count_grubs) {
     2708        return ('L');
     2709    } else if (count_grubs == 1 && count_lilos == 1) {
     2710        log_it("I'll bet you used to use LILO but switched to GRUB...");
     2711        return ('G');
     2712    } else if (count_boot0s == 1) {
     2713        return ('B');
     2714    } else if (count_dangerouslydedicated) {
     2715        return ('D');
     2716    } else {
     2717        log_it("Unknown boot loader");
     2718        return ('U');
     2719    }
    25152720}
    25162721
    25172722#else
    25182723
    2519 char which_boot_loader (char *which_device)
    2520 {
    2521     /*@ buffer ******************************************************/
    2522   char *list_drives_cmd;
    2523   char *current_drive;
    2524 
    2525     /*@ pointers ****************************************************/
    2526   FILE *pdrives;
    2527 
    2528     /*@ int *********************************************************/
    2529   int count_lilos = 0;
    2530   int count_grubs = 0;
    2531 
    2532     /*@ end vars ****************************************************/
    2533 
    2534   malloc_string(list_drives_cmd);
    2535   malloc_string(current_drive);
     2724char which_boot_loader(char *which_device)
     2725{
     2726    /*@ buffer ***************************************************** */
     2727    char *list_drives_cmd;
     2728    char *current_drive;
     2729
     2730    /*@ pointers *************************************************** */
     2731    FILE *pdrives;
     2732
     2733    /*@ int ******************************************************** */
     2734    int count_lilos = 0;
     2735    int count_grubs = 0;
     2736
     2737    /*@ end vars *************************************************** */
     2738
     2739    malloc_string(list_drives_cmd);
     2740    malloc_string(current_drive);
    25362741
    25372742#ifdef __IA64__
    2538   /* No choice for it */
    2539   return ('E');
    2540 #endif
    2541   assert(which_device!=NULL);
    2542   //  sprintf (list_drives_cmd,
    2543   //       "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2");
    2544 
    2545   sprintf (list_drives_cmd,
    2546   // "parted2fdisk
    2547        "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
    2548   log_it("list_drives_cmd = %s", list_drives_cmd);
    2549 
    2550   if (!(pdrives = popen (list_drives_cmd, "r")))
    2551     {
    2552       log_OS_error ("Unable to open list of drives");
    2553       paranoid_free(list_drives_cmd);
    2554       paranoid_free(current_drive);
    2555       return ('\0');
    2556     }
    2557   for (fgets (current_drive, MAX_STR_LEN, pdrives); !feof (pdrives);
    2558        fgets (current_drive, MAX_STR_LEN, pdrives))
    2559     {
    2560       strip_spaces (current_drive);
    2561       log_it ("looking at drive %s's MBR", current_drive);
    2562       if (does_string_exist_in_boot_block (current_drive, "GRUB"))
    2563     {
    2564       count_grubs++;
    2565       strcpy (which_device, current_drive);
    2566       break;
    2567     }
    2568       if (does_string_exist_in_boot_block (current_drive, "LILO"))
    2569     {
    2570       count_lilos++;
    2571       strcpy (which_device, current_drive);
    2572       break;
    2573     }
    2574     }
    2575   if (pclose (pdrives)) { log_OS_error("Cannot pclose pdrives"); }
    2576   log_it ("%d grubs and %d lilos\n", count_grubs, count_lilos);
    2577   paranoid_free(list_drives_cmd);
    2578   paranoid_free(current_drive);
    2579   if (count_grubs && !count_lilos)
    2580     {
    2581       return ('G');
    2582     }
    2583   else if (count_lilos && !count_grubs)
    2584     {
    2585       return ('L');
    2586     }
    2587   else if (count_grubs == 1 && count_lilos == 1)
    2588     {
    2589       log_it ("I'll bet you used to use LILO but switched to GRUB...");
    2590       return ('G');
    2591     }
    2592   else
    2593     {
    2594       log_it ("Unknown boot loader");
    2595       return ('U');
    2596     }
     2743    /* No choice for it */
     2744    return ('E');
     2745#endif
     2746    assert(which_device != NULL);
     2747    //  sprintf (list_drives_cmd,
     2748    //       "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2");
     2749
     2750    sprintf(list_drives_cmd,
     2751            // "parted2fdisk
     2752            "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s",
     2753            where_is_root_mounted());
     2754    log_it("list_drives_cmd = %s", list_drives_cmd);
     2755
     2756    if (!(pdrives = popen(list_drives_cmd, "r"))) {
     2757        log_OS_error("Unable to open list of drives");
     2758        paranoid_free(list_drives_cmd);
     2759        paranoid_free(current_drive);
     2760        return ('\0');
     2761    }
     2762    for (fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
     2763         fgets(current_drive, MAX_STR_LEN, pdrives)) {
     2764        strip_spaces(current_drive);
     2765        log_it("looking at drive %s's MBR", current_drive);
     2766        if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
     2767            count_grubs++;
     2768            strcpy(which_device, current_drive);
     2769            break;
     2770        }
     2771        if (does_string_exist_in_boot_block(current_drive, "LILO")) {
     2772            count_lilos++;
     2773            strcpy(which_device, current_drive);
     2774            break;
     2775        }
     2776    }
     2777    if (pclose(pdrives)) {
     2778        log_OS_error("Cannot pclose pdrives");
     2779    }
     2780    log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
     2781    paranoid_free(list_drives_cmd);
     2782    paranoid_free(current_drive);
     2783    if (count_grubs && !count_lilos) {
     2784        return ('G');
     2785    } else if (count_lilos && !count_grubs) {
     2786        return ('L');
     2787    } else if (count_grubs == 1 && count_lilos == 1) {
     2788        log_it("I'll bet you used to use LILO but switched to GRUB...");
     2789        return ('G');
     2790    } else {
     2791        log_it("Unknown boot loader");
     2792        return ('U');
     2793    }
    25972794}
    25982795#endif
     
    26062803 * @return 0 for success, 1 for failure.
    26072804 */
    2608 int
    2609 zero_out_a_device (char *device)
    2610 {
    2611   FILE *fout;
    2612   int i;
    2613 
    2614   assert_string_is_neither_NULL_nor_zerolength(device);
    2615 
    2616   log_it ("Zeroing drive %s", device);
    2617   if (!(fout=fopen (device, "w")))
    2618     {
    2619       log_OS_error ("Unable to open/write to device");
    2620       return (1);
    2621     }
    2622   for (i = 0; i < 16384; i++)
    2623     {
    2624       fputc ('\0', fout);
    2625     }
    2626   paranoid_fclose(fout);
    2627   log_it ("Device successfully zeroed.");
    2628   return (0);
     2805int zero_out_a_device(char *device)
     2806{
     2807    FILE *fout;
     2808    int i;
     2809
     2810    assert_string_is_neither_NULL_nor_zerolength(device);
     2811
     2812    log_it("Zeroing drive %s", device);
     2813    if (!(fout = fopen(device, "w"))) {
     2814        log_OS_error("Unable to open/write to device");
     2815        return (1);
     2816    }
     2817    for (i = 0; i < 16384; i++) {
     2818        fputc('\0', fout);
     2819    }
     2820    paranoid_fclose(fout);
     2821    log_it("Device successfully zeroed.");
     2822    return (0);
    26292823}
    26302824
     
    26362830 * @bug Won't work with file v4.0; needs to be written in C.
    26372831 */
    2638 char *resolve_softlinks_to_get_to_actual_device_file(char*incoming)
    2639 {
    2640   static char output[MAX_STR_LEN];
    2641   char *command;
    2642   char *curr_fname;
    2643   char *scratch;
    2644   char *tmp;
    2645   char *p;
    2646    
    2647   struct stat statbuf; 
    2648   command = malloc(1000);
    2649   malloc_string(tmp);
    2650   malloc_string(scratch);
    2651   malloc_string(curr_fname);
    2652   if (!does_file_exist(incoming))
    2653     {
    2654       log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found");
    2655       strcpy(output, incoming);
    2656     }
    2657   else
    2658     {
    2659       strcpy(curr_fname, incoming);
    2660       lstat(curr_fname, &statbuf);
    2661       while(S_ISLNK(statbuf.st_mode))
    2662         {
    2663       log_msg(1, "curr_fname = %s", curr_fname);
    2664       sprintf(command, "file %s", curr_fname);
    2665       strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2666       for(p=tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--);
    2667       p++;
    2668       strcpy(scratch, p);
    2669       for(p=scratch; *p != '\0' && *p != '\''; p++);
    2670       *p = '\0';
    2671       log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
    2672       if (scratch[0] == '/')
    2673         {
    2674           strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink
    2675         }
    2676       else
    2677         { // copy over the basename cos it's a relative softlink
    2678           p = curr_fname + strlen(curr_fname);
    2679           while(p!=curr_fname && *p != '/') { p--;}
    2680           if (*p == '/') { p++; }
    2681           strcpy(p, scratch);
    2682         }
    2683           lstat(curr_fname, &statbuf);
    2684     }
    2685       strcpy(output, curr_fname);
    2686       log_it("resolved %s to %s", incoming, output);
    2687     }
    2688   paranoid_free(command);
    2689   paranoid_free(curr_fname);
    2690   paranoid_free(tmp);
    2691   return(output);
     2832char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
     2833{
     2834    static char output[MAX_STR_LEN];
     2835    char *command;
     2836    char *curr_fname;
     2837    char *scratch;
     2838    char *tmp;
     2839    char *p;
     2840
     2841    struct stat statbuf;
     2842    command = malloc(1000);
     2843    malloc_string(tmp);
     2844    malloc_string(scratch);
     2845    malloc_string(curr_fname);
     2846    if (!does_file_exist(incoming)) {
     2847        log_it
     2848            ("resolve_softlinks_to_get_to_actual_device_file --- device not found");
     2849        strcpy(output, incoming);
     2850    } else {
     2851        strcpy(curr_fname, incoming);
     2852        lstat(curr_fname, &statbuf);
     2853        while (S_ISLNK(statbuf.st_mode)) {
     2854            log_msg(1, "curr_fname = %s", curr_fname);
     2855            sprintf(command, "file %s", curr_fname);
     2856            strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2857            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
     2858                 p--);
     2859            p++;
     2860            strcpy(scratch, p);
     2861            for (p = scratch; *p != '\0' && *p != '\''; p++);
     2862            *p = '\0';
     2863            log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp,
     2864                    scratch);
     2865            if (scratch[0] == '/') {
     2866                strcpy(curr_fname, scratch);    // copy whole thing because it's an absolute softlink
     2867            } else {            // copy over the basename cos it's a relative softlink
     2868                p = curr_fname + strlen(curr_fname);
     2869                while (p != curr_fname && *p != '/') {
     2870                    p--;
     2871                }
     2872                if (*p == '/') {
     2873                    p++;
     2874                }
     2875                strcpy(p, scratch);
     2876            }
     2877            lstat(curr_fname, &statbuf);
     2878        }
     2879        strcpy(output, curr_fname);
     2880        log_it("resolved %s to %s", incoming, output);
     2881    }
     2882    paranoid_free(command);
     2883    paranoid_free(curr_fname);
     2884    paranoid_free(tmp);
     2885    return (output);
    26922886}
    26932887
     
    27002894char *which_partition_format(const char *drive)
    27012895{
    2702   static char output[4];
    2703   char *tmp;
    2704   char *command;
    2705   char *fdisk;
    2706   struct stat buf;
    2707    
    2708   malloc_string(tmp);
    2709   malloc_string(command);
    2710   malloc_string(fdisk);
    2711   log_msg(0, "Looking for partition table format type");
     2896    static char output[4];
     2897    char *tmp;
     2898    char *command;
     2899    char *fdisk;
     2900    struct stat buf;
     2901
     2902    malloc_string(tmp);
     2903    malloc_string(command);
     2904    malloc_string(fdisk);
     2905    log_msg(0, "Looking for partition table format type");
    27122906// BERLIOS: Do that temporarily: we need to put back parted2fdisk everywhere
    27132907#ifdef __IA64__
    2714   sprintf(fdisk, "/usr/local/bin/fdisk");
    2715   if (stat(fdisk, &buf) != 0) {
    2716 #endif
    2717       sprintf(fdisk, "/sbin/fdisk");
     2908    sprintf(fdisk, "/usr/local/bin/fdisk");
     2909    if (stat(fdisk, &buf) != 0) {
     2910#endif
     2911        sprintf(fdisk, "/sbin/fdisk");
    27182912#ifdef __IA64__
    2719   }
    2720 #endif
    2721   log_msg(1, "Using %s",fdisk);
    2722   sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
    2723   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    2724   if (strstr(tmp,"GPT") == NULL) {
    2725       strcpy(output,"MBR");
    2726   } else {
    2727       strcpy(output,"GPT");
    2728   }
    2729   log_msg(0, "Found %s partition table format type",output);
    2730   paranoid_free(command);
    2731   paranoid_free(tmp);
    2732   paranoid_free(fdisk);
    2733   return(output);
     2913    }
     2914#endif
     2915    log_msg(1, "Using %s", fdisk);
     2916    sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
     2917    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     2918    if (strstr(tmp, "GPT") == NULL) {
     2919        strcpy(output, "MBR");
     2920    } else {
     2921        strcpy(output, "GPT");
     2922    }
     2923    log_msg(0, "Found %s partition table format type", output);
     2924    paranoid_free(command);
     2925    paranoid_free(tmp);
     2926    paranoid_free(fdisk);
     2927    return (output);
    27342928}
    27352929
    27362930/* @} - end of deviceGroup */
    2737 
  • branches/2.05/mondo/mondo/common/libmondo-devices.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-fifo-EXT.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-fifo.c

    r30 r128  
    11/* libmondo-fifo.c
    2    $Id: libmondo-fifo.c,v 1.7 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33
    44
     
    9292#include <stdio.h>
    9393#include <signal.h>
    94 #include <fcntl.h>     
     94#include <fcntl.h>
    9595#include <stdio.h>
    96  
     96
    9797#include <errno.h>
    9898#include <sys/types.h>
     
    115115 * The SIGPIPE handler sets this to TRUE.
    116116 */
    117 bool g_sigpipe=FALSE;
     117bool g_sigpipe = FALSE;
    118118
    119119/**
    120120 * PID of the "main" process.
    121121 */
    122 pid_t g_mastermind_pid=0;
     122pid_t g_mastermind_pid = 0;
    123123
    124124
     
    132132 * Size of the buffer used with @c buffer.
    133133 */
    134 int g_tape_buffer_size_MB=0;
     134int g_tape_buffer_size_MB = 0;
    135135
    136136/* @} - end of globalGroup */
     
    148148 * @return A file pointer to/from the @c buffer process.
    149149 */
    150 FILE*open_device_via_buffer(char*device, char direction, long internal_tape_block_size)
     150FILE *open_device_via_buffer(char *device, char direction,
     151                             long internal_tape_block_size)
    151152{
    152   char sz_dir[32];
    153   char keych;
    154   char *tmp;
    155   char *command;
    156   FILE*fres;
    157   int bufsize; // in megabytes
    158   int res;
    159   int wise_upper_limit;
    160   int wise_lower_limit;
    161 
    162   malloc_string(tmp);
    163   malloc_string(command);
    164   assert_string_is_neither_NULL_nor_zerolength(device);
    165   assert(direction=='w'||direction=='r');
    166   sprintf(sz_dir, "%c", direction);
    167   wise_upper_limit = (am_I_in_disaster_recovery_mode() ? 8 : 32);
    168   wise_lower_limit = 1; // wise_upper_limit/2 + 1;
    169   paranoid_system("sync");
    170   for(bufsize=wise_upper_limit,res=-1; res!=0 && bufsize>=wise_lower_limit; bufsize--)
    171     {
    172       sprintf(tmp, "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c", internal_tape_block_size, bufsize, 'm');
    173       res = run_program_and_log_output(tmp, 2);
    174     }
    175   if (!res)
    176     {
    177       bufsize++;
    178       sprintf(tmp, "Negotiated max buffer of %d MB ", bufsize);
    179       log_to_screen(tmp);
    180     }
    181   else
    182     {
    183       bufsize=0;
    184       res=0;
    185       log_to_screen("Cannot negotiate a buffer of ANY size. Using dd instead.");
    186     }
    187   if (direction=='r')
    188     { keych = 'i'; }
    189   else
    190     { keych = 'o'; }
    191   if (bufsize)
    192     { sprintf(g_sz_call_to_buffer, "buffer -m %d%c -p%d -B -s%ld -%c %s 2>> %s", bufsize, 'm', (direction=='r')?20:75, internal_tape_block_size, keych, device, MONDO_LOGFILE); }
    193   else
    194     { sprintf(g_sz_call_to_buffer, "dd bs=%ld %cf=%s", internal_tape_block_size, keych, device); }
    195   log_msg (2, "Calling buffer --- command = '%s'", g_sz_call_to_buffer);
    196   fres = popen(g_sz_call_to_buffer, sz_dir);
    197   if (fres)
    198     { log_msg (2, "Successfully opened ('%c') tape device %s", direction, device); }
    199   else
    200     { log_msg (2, "Failed to open ('%c') tape device %s", direction, device); }
    201   sleep(2);
    202   sprintf(tmp, "ps wwax | grep \"%s\"", g_sz_call_to_buffer);
    203   if (run_program_and_log_output(tmp, 2))
    204     { log_msg(2, "Warning - I think I failed to open tape, actually."); }
    205   g_tape_buffer_size_MB = bufsize;
    206   strcmp(tmp, g_sz_call_to_buffer);
    207   tmp[30] = '\0';
    208   sprintf(command, "ps wwax | grep buffer | grep -v grep");
    209   if (run_program_and_log_output(command, 1))
    210     {
    211       fres = NULL;
    212       log_to_screen("Failed to open tape streamer. Buffer error.");
    213     }
    214   else
    215     {
    216       log_to_screen("Buffer successfully started.");
    217     }
    218 
    219   paranoid_free(command);
    220   paranoid_free(tmp);
    221   return(fres);
     153    char sz_dir[32];
     154    char keych;
     155    char *tmp;
     156    char *command;
     157    FILE *fres;
     158    int bufsize;                // in megabytes
     159    int res;
     160    int wise_upper_limit;
     161    int wise_lower_limit;
     162
     163    malloc_string(tmp);
     164    malloc_string(command);
     165    assert_string_is_neither_NULL_nor_zerolength(device);
     166    assert(direction == 'w' || direction == 'r');
     167    sprintf(sz_dir, "%c", direction);
     168    wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32);
     169    wise_lower_limit = 1;       // wise_upper_limit/2 + 1;
     170    paranoid_system("sync");
     171    for (bufsize = wise_upper_limit, res = -1;
     172         res != 0 && bufsize >= wise_lower_limit; bufsize--) {
     173        sprintf(tmp,
     174                "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c",
     175                internal_tape_block_size, bufsize, 'm');
     176        res = run_program_and_log_output(tmp, 2);
     177    }
     178    if (!res) {
     179        bufsize++;
     180        sprintf(tmp, "Negotiated max buffer of %d MB ", bufsize);
     181        log_to_screen(tmp);
     182    } else {
     183        bufsize = 0;
     184        res = 0;
     185        log_to_screen
     186            ("Cannot negotiate a buffer of ANY size. Using dd instead.");
     187    }
     188    if (direction == 'r') {
     189        keych = 'i';
     190    } else {
     191        keych = 'o';
     192    }
     193    if (bufsize) {
     194        sprintf(g_sz_call_to_buffer,
     195                "buffer -m %d%c -p%d -B -s%ld -%c %s 2>> %s", bufsize, 'm',
     196                (direction == 'r') ? 20 : 75, internal_tape_block_size,
     197                keych, device, MONDO_LOGFILE);
     198    } else {
     199        sprintf(g_sz_call_to_buffer, "dd bs=%ld %cf=%s",
     200                internal_tape_block_size, keych, device);
     201    }
     202    log_msg(2, "Calling buffer --- command = '%s'", g_sz_call_to_buffer);
     203    fres = popen(g_sz_call_to_buffer, sz_dir);
     204    if (fres) {
     205        log_msg(2, "Successfully opened ('%c') tape device %s", direction,
     206                device);
     207    } else {
     208        log_msg(2, "Failed to open ('%c') tape device %s", direction,
     209                device);
     210    }
     211    sleep(2);
     212    sprintf(tmp, "ps wwax | grep \"%s\"", g_sz_call_to_buffer);
     213    if (run_program_and_log_output(tmp, 2)) {
     214        log_msg(2, "Warning - I think I failed to open tape, actually.");
     215    }
     216    g_tape_buffer_size_MB = bufsize;
     217    strcmp(tmp, g_sz_call_to_buffer);
     218    tmp[30] = '\0';
     219    sprintf(command, "ps wwax | grep buffer | grep -v grep");
     220    if (run_program_and_log_output(command, 1)) {
     221        fres = NULL;
     222        log_to_screen("Failed to open tape streamer. Buffer error.");
     223    } else {
     224        log_to_screen("Buffer successfully started.");
     225    }
     226
     227    paranoid_free(command);
     228    paranoid_free(tmp);
     229    return (fres);
    222230}
    223231
     
    228236void kill_buffer()
    229237{
    230   char *tmp;
    231   char *command;
    232 
    233   malloc_string(tmp);
    234   malloc_string(command);
    235   paranoid_system("sync");
    236   sprintf(command, "ps wwax | fgrep \"%s\" | fgrep -v grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'", g_sz_call_to_buffer);
    237   log_msg (2, "kill_buffer() --- command = %s", command);
    238   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    239   sprintf(command, "kill %s", tmp);
    240   log_msg (2, "kill_buffer() --- command = %s", command);
    241   if (strlen(tmp)>0) { run_program_and_log_output(command, TRUE); }
    242   paranoid_free(tmp);
    243   paranoid_free(command);
     238    char *tmp;
     239    char *command;
     240
     241    malloc_string(tmp);
     242    malloc_string(command);
     243    paranoid_system("sync");
     244    sprintf(command,
     245            "ps wwax | fgrep \"%s\" | fgrep -v grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'",
     246            g_sz_call_to_buffer);
     247    log_msg(2, "kill_buffer() --- command = %s", command);
     248    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     249    sprintf(command, "kill %s", tmp);
     250    log_msg(2, "kill_buffer() --- command = %s", command);
     251    if (strlen(tmp) > 0) {
     252        run_program_and_log_output(command, TRUE);
     253    }
     254    paranoid_free(tmp);
     255    paranoid_free(command);
    244256}
    245257
     
    254266void sigpipe_occurred(int sig)
    255267{
    256   g_sigpipe = TRUE;
     268    g_sigpipe = TRUE;
    257269}
    258270
    259271/* @} - end of fifoGroup */
    260272
    261 int 
    262 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
    263                   char *ramdisk_fname,
    264                   char *output_cfg_file,
    265                   char *output_mountlist_file);
     273int
     274extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
     275                                 char *ramdisk_fname,
     276                                 char *output_cfg_file,
     277                                char *output_mountlist_file);
  • branches/2.05/mondo/mondo/common/libmondo-fifo.h

    r30 r128  
    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();
  • branches/2.05/mondo/mondo/common/libmondo-filelist-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-filelist.c

    r30 r128  
    11/* libmondo-filelist.c
    2    $Id: libmondo-filelist.c,v 1.6 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33
    44- for subroutines which manipulate the filelist
     
    135135
    136136
    137 extern ssize_t getline(char **lineptr, size_t *n, FILE *stream);
    138 
    139 
    140 int mondo_makefilelist(char*logfile, char*tmpdir, char*scratchdir,
    141     char*include_paths, char*excp, int differential, char *userdef_filelist);
     137extern ssize_t getline(char **lineptr, size_t * n, FILE * stream);
     138
     139
     140int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
     141                       char *include_paths, char *excp, int differential,
     142                       char *userdef_filelist);
    142143
    143144
    144145/*@unused@*/
    145 //static char cvsid[] = "$Id: libmondo-filelist.c,v 1.6 2004/06/10 15:29:12 hugo Exp $";
     146//static char cvsid[] = "$Id$";
    146147
    147148/**
     
    156157 * @ingroup globalGroup
    157158 */
    158 long g_noof_sets=0;
     159long g_noof_sets = 0;
    159160
    160161extern bool g_text_mode;
     
    180181 * @see chop_filelist
    181182 */
    182 int
    183 call_filelist_chopper (struct s_bkpinfo *bkpinfo)
    184 {
    185     /*@ buffers ************************/
    186   char *dev;
    187   char *filelist;
    188   char *tempfile;
    189   char *cksumlist;
    190   char *tmp;
    191   long noof_sets;
    192 
    193     /*@ pointers ***********************/
    194   char *ptr;
    195   FILE *fout;
    196 
    197     /*@ int ****************************/
    198   int i, retval=0;
    199 
    200   malloc_string(dev);
    201   malloc_string(filelist);
    202   malloc_string(tempfile);
    203   malloc_string(cksumlist);
    204   malloc_string(tmp);
    205   mvaddstr_and_log_it (g_currentY, 0, "Dividing filelist into sets");
    206 
    207   log_to_screen ("Dividing filelist into sets. Please wait.");
    208   i=0;
     183int call_filelist_chopper(struct s_bkpinfo *bkpinfo)
     184{
     185    /*@ buffers *********************** */
     186    char *dev;
     187    char *filelist;
     188    char *tempfile;
     189    char *cksumlist;
     190    char *tmp;
     191    long noof_sets;
     192
     193    /*@ pointers ********************** */
     194    char *ptr;
     195    FILE *fout;
     196
     197    /*@ int *************************** */
     198    int i, retval = 0;
     199
     200    malloc_string(dev);
     201    malloc_string(filelist);
     202    malloc_string(tempfile);
     203    malloc_string(cksumlist);
     204    malloc_string(tmp);
     205    mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets");
     206
     207    log_to_screen("Dividing filelist into sets. Please wait.");
     208    i = 0;
    209209/*
    210210  if (find_home_of_exe("getfattr"))
     
    215215    { i=0; log_to_screen ("This will take more time. Please be patient."); }
    216216*/
    217   sprintf (filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
    218   sprintf (cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
    219   if (!does_file_exist(filelist)) { log_it("filelist %s not found", filelist); fatal_error("call_filelist_chopper() -- filelist not found!"); }
    220 
    221   noof_sets = chop_filelist (filelist, bkpinfo->tmpdir, bkpinfo->optimal_set_size);
    222   estimate_noof_media_required (bkpinfo, noof_sets); // for cosmetic purposes
    223 
    224   sprintf (tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
    225   if (!(fout = fopen (tempfile, "a")))
    226     {
    227       log_OS_error("Cannot append to biggielist");
    228       retval++;
    229       goto end_of_func;
    230     }
    231   log_it (bkpinfo->image_devs);
    232 
    233   ptr = bkpinfo->image_devs;
    234 
    235   while (ptr && *ptr)
    236     {
    237       strcpy (dev, ptr);
    238       log_it ("Examining imagedev %s", dev);
    239       for (i = 0; i < (int) strlen (dev) && dev[i] != ' '; i++);
    240       dev[i] = '\0';
    241       if (!strlen (dev))
    242     {
    243       continue;
    244     }
    245       fprintf (fout, "%s\n", dev);
    246       log_it ("Adding '%s' to biggielist", dev);
    247       if ((ptr = strchr (ptr, ' ')))
    248     {
    249       ptr++;
    250     }
    251     }
    252   paranoid_fclose(fout);
    253   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    254 
    255 end_of_func:
    256   paranoid_free(filelist);
    257   paranoid_free(tempfile);
    258   paranoid_free(cksumlist);
    259   paranoid_free(dev);
    260   paranoid_free(tmp);
    261   return(retval);
    262 }
    263 
    264 
    265 
    266 int sort_file(char*orig_fname)
    267 {
    268   char *tmp_fname;
    269   char *command;
    270   int retval=0;
    271 
    272   log_msg(1, "Sorting file %s", orig_fname);
    273   malloc_string(tmp_fname);
    274   malloc_string(command);
    275   sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int)(random()%32768), (int)(random()%32768), (int)(random()%32768));
    276  
    277   if (!does_file_exist(orig_fname))
    278     { return(0); } // no sense in trying to sort an empty file
    279 
    280   sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
    281   retval = system(command);
    282   if (retval)
    283     {
    284       log_msg(2, "Failed to sort %s - oh dear", orig_fname);
    285     }
    286   else
    287     {
    288       log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now", orig_fname, tmp_fname, orig_fname);
    289       sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
    290       retval += run_program_and_log_output(command, 2);
    291       if (retval)
    292         {
    293       log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, orig_fname);
    294     }
    295       else
    296         {
    297       log_msg(2, "%s was sorted OK.", orig_fname);
    298     }
    299     }
    300   paranoid_free(tmp_fname);
    301   paranoid_free(command);
    302   log_msg(1, "Finished sorting file %s", orig_fname);
    303   return(retval);
     217    sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
     218    sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
     219    if (!does_file_exist(filelist)) {
     220        log_it("filelist %s not found", filelist);
     221        fatal_error("call_filelist_chopper() -- filelist not found!");
     222    }
     223
     224    noof_sets =
     225        chop_filelist(filelist, bkpinfo->tmpdir,
     226                      bkpinfo->optimal_set_size);
     227    estimate_noof_media_required(bkpinfo, noof_sets);   // for cosmetic purposes
     228
     229    sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
     230    if (!(fout = fopen(tempfile, "a"))) {
     231        log_OS_error("Cannot append to biggielist");
     232        retval++;
     233        goto end_of_func;
     234    }
     235    log_it(bkpinfo->image_devs);
     236
     237    ptr = bkpinfo->image_devs;
     238
     239    while (ptr && *ptr) {
     240        strcpy(dev, ptr);
     241        log_it("Examining imagedev %s", dev);
     242        for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
     243        dev[i] = '\0';
     244        if (!strlen(dev)) {
     245            continue;
     246        }
     247        fprintf(fout, "%s\n", dev);
     248        log_it("Adding '%s' to biggielist", dev);
     249        if ((ptr = strchr(ptr, ' '))) {
     250            ptr++;
     251        }
     252    }
     253    paranoid_fclose(fout);
     254    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     255
     256  end_of_func:
     257    paranoid_free(filelist);
     258    paranoid_free(tempfile);
     259    paranoid_free(cksumlist);
     260    paranoid_free(dev);
     261    paranoid_free(tmp);
     262    return (retval);
     263}
     264
     265
     266
     267int sort_file(char *orig_fname)
     268{
     269    char *tmp_fname;
     270    char *command;
     271    int retval = 0;
     272
     273    log_msg(1, "Sorting file %s", orig_fname);
     274    malloc_string(tmp_fname);
     275    malloc_string(command);
     276    sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768),
     277            (int) (random() % 32768), (int) (random() % 32768));
     278
     279    if (!does_file_exist(orig_fname)) {
     280        return (0);
     281    }                           // no sense in trying to sort an empty file
     282
     283    sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,
     284            MONDO_LOGFILE);
     285    retval = system(command);
     286    if (retval) {
     287        log_msg(2, "Failed to sort %s - oh dear", orig_fname);
     288    } else {
     289        log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now",
     290                orig_fname, tmp_fname, orig_fname);
     291        sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
     292        retval += run_program_and_log_output(command, 2);
     293        if (retval) {
     294            log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname,
     295                    orig_fname);
     296        } else {
     297            log_msg(2, "%s was sorted OK.", orig_fname);
     298        }
     299    }
     300    paranoid_free(tmp_fname);
     301    paranoid_free(command);
     302    log_msg(1, "Finished sorting file %s", orig_fname);
     303    return (retval);
    304304}
    305305
     
    318318 * @return number of errors encountered (0 for success).
    319319 */
    320 int
    321 chop_filelist (char *filelist, char *outdir, long maxsetsizeK)
     320int chop_filelist(char *filelist, char *outdir, long maxsetsizeK)
    322321{
    323322/*@ long ****************************************/
    324   long lino = 0;
    325   long max_sane_size_for_a_file;
    326   long curr_set_size;
    327   long noof_lines;
    328   long siz;
    329 
    330     /*@ int *****************************************/
    331   int i;
    332   long curr_set_no;
    333 
    334     /*@ buffers **************************************/
    335   char *outfname;
    336   char *biggie_fname;
    337   char *incoming;
    338   char *tmp;
    339   char *acl_fname;
    340   char *xattr_fname;
    341 
    342     /*@ pointers ************************************/
    343   FILE *fin;
    344   FILE *fout;
    345   FILE *fbig;
    346 
    347     /*@ structures **********************************/
    348   struct stat buf;
    349   int err = 0;
    350 
    351   malloc_string(outfname);
    352   malloc_string(biggie_fname);
    353   incoming = malloc(MAX_STR_LEN*2);
    354   malloc_string(tmp);
    355   malloc_string(acl_fname);
    356   malloc_string(xattr_fname);
    357  
    358   assert_string_is_neither_NULL_nor_zerolength(filelist);
    359   assert_string_is_neither_NULL_nor_zerolength(outdir);
    360   assert( maxsetsizeK > 0);
    361 
    362   max_sane_size_for_a_file = 32L*1024L;
     323    long lino = 0;
     324    long max_sane_size_for_a_file;
     325    long curr_set_size;
     326    long noof_lines;
     327    long siz;
     328
     329    /*@ int **************************************** */
     330    int i;
     331    long curr_set_no;
     332
     333    /*@ buffers ************************************* */
     334    char *outfname;
     335    char *biggie_fname;
     336    char *incoming;
     337    char *tmp;
     338    char *acl_fname;
     339    char *xattr_fname;
     340
     341    /*@ pointers *********************************** */
     342    FILE *fin;
     343    FILE *fout;
     344    FILE *fbig;
     345
     346    /*@ structures ********************************* */
     347    struct stat buf;
     348    int err = 0;
     349
     350    malloc_string(outfname);
     351    malloc_string(biggie_fname);
     352    incoming = malloc(MAX_STR_LEN * 2);
     353    malloc_string(tmp);
     354    malloc_string(acl_fname);
     355    malloc_string(xattr_fname);
     356
     357    assert_string_is_neither_NULL_nor_zerolength(filelist);
     358    assert_string_is_neither_NULL_nor_zerolength(outdir);
     359    assert(maxsetsizeK > 0);
     360
     361    max_sane_size_for_a_file = 32L * 1024L;
    363362// max_sane_size_for_a_file = maxsetsizeK*2;
    364363//  if (max_sane_size_for_a_file > 32*1024)
    365364//    { max_sane_size_for_a_file = 32*1024; }
    366  
    367   log_it("filelist=%s;", filelist);
    368   open_evalcall_form ("Dividing filelist into sets");
    369   noof_lines = count_lines_in_file (filelist);
    370   if (!(fin = fopen (filelist, "r"))) { log_OS_error("Cannot openin filelist"); return(0); }
    371   curr_set_no = 0;
    372   curr_set_size = 0;
    373   sprintf (outfname, "%s/filelist.%ld", outdir, curr_set_no);
    374   sprintf (biggie_fname, "%s/biggielist.txt", outdir);
    375   log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
    376   if (!(fbig = fopen (biggie_fname, "w"))) { log_OS_error("Cannot openout biggie_fname"); err++; goto end_of_func; }
    377   if (!(fout = fopen (outfname, "w"))) { log_OS_error("Cannot openout outfname"); err++; goto end_of_func; }
    378   (void) fgets (incoming, MAX_STR_LEN*2-1, fin);
    379   while (!feof (fin))
    380     {
    381       lino++;
    382       i = strlen (incoming) - 1;
    383       if (i < 0)
    384     {
    385       i = 0;
    386     }
    387       if (i > MAX_STR_LEN-1)
    388         {
    389       incoming[MAX_STR_LEN-30] = '\0';
    390       log_msg(1, "Warning - truncating file %s's name", incoming);
    391       err++;
    392     }
    393       if (incoming[i] < 32)
    394     {
    395       incoming[i] = '\0';
    396     }
    397       if (!strncmp (incoming, "/dev/", 5))
    398     {
    399       siz = 1;
    400     }
    401       else if (lstat (incoming, &buf) != 0)
    402     {
    403       siz = 0;
    404     }
    405       else
    406     {
    407       siz = (long) (buf.st_size >> 10);
    408     }
    409       if (siz > max_sane_size_for_a_file)
     365
     366    log_it("filelist=%s;", filelist);
     367    open_evalcall_form("Dividing filelist into sets");
     368    noof_lines = count_lines_in_file(filelist);
     369    if (!(fin = fopen(filelist, "r"))) {
     370        log_OS_error("Cannot openin filelist");
     371        return (0);
     372    }
     373    curr_set_no = 0;
     374    curr_set_size = 0;
     375    sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     376    sprintf(biggie_fname, "%s/biggielist.txt", outdir);
     377    log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
     378    if (!(fbig = fopen(biggie_fname, "w"))) {
     379        log_OS_error("Cannot openout biggie_fname");
     380        err++;
     381        goto end_of_func;
     382    }
     383    if (!(fout = fopen(outfname, "w"))) {
     384        log_OS_error("Cannot openout outfname");
     385        err++;
     386        goto end_of_func;
     387    }
     388    (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     389    while (!feof(fin)) {
     390        lino++;
     391        i = strlen(incoming) - 1;
     392        if (i < 0) {
     393            i = 0;
     394        }
     395        if (i > MAX_STR_LEN - 1) {
     396            incoming[MAX_STR_LEN - 30] = '\0';
     397            log_msg(1, "Warning - truncating file %s's name", incoming);
     398            err++;
     399        }
     400        if (incoming[i] < 32) {
     401            incoming[i] = '\0';
     402        }
     403        if (!strncmp(incoming, "/dev/", 5)) {
     404            siz = 1;
     405        } else if (lstat(incoming, &buf) != 0) {
     406            siz = 0;
     407        } else {
     408            siz = (long) (buf.st_size >> 10);
     409        }
     410        if (siz > max_sane_size_for_a_file)
    410411// && strcmp(incoming+strlen(incoming)-4, ".bz2") && strcmp(incoming+strlen(incoming)-4, ".tbz"))
    411     {
    412       fprintf (fbig, "%s\n", incoming);
    413     }
    414       else
    415     {
    416       curr_set_size += siz;
    417       fprintf (fout, "%s\n", incoming);
    418       if (curr_set_size > maxsetsizeK)
    419         {
    420           paranoid_fclose(fout);
    421           sort_file(outfname);
    422           curr_set_no++;
    423           curr_set_size = 0;
    424           sprintf (outfname, "%s/filelist.%ld", outdir, curr_set_no);
    425           if (!(fout = fopen (outfname, "w"))) { log_OS_error("Unable to openout outfname"); err++; goto end_of_func; }
    426           sprintf (tmp, "Fileset #%ld chopped ", curr_set_no - 1);
    427           update_evalcall_form ((int) (lino * 100 / noof_lines));
    428           /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
    429         }
    430     }
    431       (void) fgets (incoming, MAX_STR_LEN*2-1, fin);
    432     }
    433   paranoid_fclose (fin);
    434   paranoid_fclose (fout);
    435   paranoid_fclose (fbig);
    436 
    437   if (length_of_file(outfname) <= 2)
    438     {
    439       unlink(outfname);
    440       g_noof_sets --;
    441     }
    442   g_noof_sets = curr_set_no;
    443   sort_file(outfname);
    444   sort_file(biggie_fname);
    445   sprintf (outfname, "%s/LAST-FILELIST-NUMBER", outdir);
    446   sprintf (tmp, "%ld", curr_set_no);
    447   if (write_one_liner_data_file (outfname, tmp))
    448       { log_OS_error("Unable to echo write one-liner to LAST-FILELIST-NUMBER"); err = 1;}
    449   if (curr_set_no == 0)
    450     {
    451       sprintf (tmp, "Only one fileset. Fine.");
    452     }
    453   else
    454     {
    455       sprintf (tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    456     }
    457   log_msg(1, tmp);
    458   close_evalcall_form ();
    459   /* This is to work around an obscure bug in Newt; open a form, close it,
    460      carry on... I don't know why it works but it works. If you don't do this
    461      then update_progress_form() won't show the "time taken / time remaining"
    462      line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
     412        {
     413            fprintf(fbig, "%s\n", incoming);
     414        } else {
     415            curr_set_size += siz;
     416            fprintf(fout, "%s\n", incoming);
     417            if (curr_set_size > maxsetsizeK) {
     418                paranoid_fclose(fout);
     419                sort_file(outfname);
     420                curr_set_no++;
     421                curr_set_size = 0;
     422                sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     423                if (!(fout = fopen(outfname, "w"))) {
     424                    log_OS_error("Unable to openout outfname");
     425                    err++;
     426                    goto end_of_func;
     427                }
     428                sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);
     429                update_evalcall_form((int) (lino * 100 / noof_lines));
     430                /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
     431            }
     432        }
     433        (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     434    }
     435    paranoid_fclose(fin);
     436    paranoid_fclose(fout);
     437    paranoid_fclose(fbig);
     438
     439    if (length_of_file(outfname) <= 2) {
     440        unlink(outfname);
     441        g_noof_sets--;
     442    }
     443    g_noof_sets = curr_set_no;
     444    sort_file(outfname);
     445    sort_file(biggie_fname);
     446    sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir);
     447    sprintf(tmp, "%ld", curr_set_no);
     448    if (write_one_liner_data_file(outfname, tmp)) {
     449        log_OS_error
     450            ("Unable to echo write one-liner to LAST-FILELIST-NUMBER");
     451        err = 1;
     452    }
     453    if (curr_set_no == 0) {
     454        sprintf(tmp, "Only one fileset. Fine.");
     455    } else {
     456        sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
     457    }
     458    log_msg(1, tmp);
     459    close_evalcall_form();
     460    /* This is to work around an obscure bug in Newt; open a form, close it,
     461       carry on... I don't know why it works but it works. If you don't do this
     462       then update_progress_form() won't show the "time taken / time remaining"
     463       line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
    463464#ifndef _XWIN
    464   if (!g_text_mode)
    465     {
    466       open_progress_form ("", "", "", "", 100);
    467       newtPopHelpLine ();
    468       newtFormDestroy (g_progressForm);
    469       newtPopWindow ();
    470     }
     465    if (!g_text_mode) {
     466        open_progress_form("", "", "", "", 100);
     467        newtPopHelpLine();
     468        newtFormDestroy(g_progressForm);
     469        newtPopWindow();
     470    }
    471471#endif
    472 end_of_func:
    473   paranoid_free(outfname);
    474   paranoid_free(biggie_fname);
    475   paranoid_free(incoming);
    476   paranoid_free(tmp);
    477   paranoid_free(acl_fname);
    478   paranoid_free(xattr_fname);
    479   return (err ? 0 : curr_set_no + 1);
     472  end_of_func:
     473    paranoid_free(outfname);
     474    paranoid_free(biggie_fname);
     475    paranoid_free(incoming);
     476    paranoid_free(tmp);
     477    paranoid_free(acl_fname);
     478    paranoid_free(xattr_fname);
     479    return (err ? 0 : curr_set_no + 1);
    480480}
    481481
     
    489489 * @param filelist The filelist to free.
    490490 */
    491 void
    492 free_filelist (struct s_node *filelist)
    493 {
    494     /*@ int's ********************************************************/
    495   static int depth = 0;
    496   int percentage;
    497 
    498     /*@ long's *******************************************************/
    499   static long i = 0;
    500 
    501     /*@ end vars *****************************************************/
    502 
    503   assert(filelist!=NULL);
    504   if (depth == 0)
    505     {
    506       open_evalcall_form ("Freeing memory");
    507       log_to_screen ("Freeing memory formerly occupied by filelist");
    508     }
    509   depth++;
    510 
    511   if (filelist->ch == '\0')
    512     {
    513       if (!(i++ % 1111))
    514     {
    515       percentage = (int) (i * 100 / g_original_noof_lines_in_filelist);
    516       update_evalcall_form (percentage);
    517 
    518     }
    519     }
    520 
    521   if (filelist->right)
    522     {
    523       free_filelist (filelist->right);
    524       filelist->right = NULL;
    525     }
    526   if (filelist->down)
    527     {
     491void free_filelist(struct s_node *filelist)
     492{
     493    /*@ int's ******************************************************* */
     494    static int depth = 0;
     495    int percentage;
     496
     497    /*@ long's ****************************************************** */
     498    static long i = 0;
     499
     500    /*@ end vars **************************************************** */
     501
     502    assert(filelist != NULL);
     503    if (depth == 0) {
     504        open_evalcall_form("Freeing memory");
     505        log_to_screen("Freeing memory formerly occupied by filelist");
     506    }
     507    depth++;
     508
     509    if (filelist->ch == '\0') {
     510        if (!(i++ % 1111)) {
     511            percentage =
     512                (int) (i * 100 / g_original_noof_lines_in_filelist);
     513            update_evalcall_form(percentage);
     514
     515        }
     516    }
     517
     518    if (filelist->right) {
     519        free_filelist(filelist->right);
     520        filelist->right = NULL;
     521    }
     522    if (filelist->down) {
    528523/*      if (!(i++ %39999)) { update_evalcall_form(0); } */
    529       free_filelist (filelist->down);
    530       filelist->down = NULL;
    531     }
    532   filelist->ch = '\0';
    533   paranoid_free (filelist);
    534   depth--;
    535   if (depth == 0)
    536     {
    537       close_evalcall_form ();
    538       log_it ("Finished freeing memory");
    539     }
    540 }
    541 
    542 
    543 int call_exe_and_pipe_output_to_fd(char*syscall, FILE*pout)
    544 {
    545   FILE *pattr;
    546   char *tmp;
    547       pattr = popen(syscall, "r");
    548       if (!pattr)
    549         {
    550       log_msg(1, "Failed to open fattr() %s", syscall);
    551       return(1);
    552         }
    553       if (feof(pattr))
    554         {
    555       log_msg(1, "Failed to call fattr() %s", syscall);
    556       paranoid_pclose(pattr);
    557       return(2); 
    558     }
    559       malloc_string(tmp);
    560       for (fgets (tmp, MAX_STR_LEN, pattr); !feof (pattr);
    561        fgets (tmp, MAX_STR_LEN, pattr))
    562         {
    563       fputs(tmp, pout);
    564     }
    565       paranoid_pclose(pattr);
    566       paranoid_free(tmp);
    567       return(0);
    568 }
    569 
    570 
    571 
    572 int gen_aux_list(char*filelist, char*syscall_sprintf, char*auxlist_fname)
    573 {
    574   FILE*fin;
    575   FILE*pout;
    576   char*pout_command;
    577   char*syscall;
    578   char*file_to_analyze;
    579   int i;
    580  
    581   if (!(fin=fopen(filelist, "r")))
    582     {
    583       log_msg(1, "Cannot openin filelist %s", filelist);
    584       return(1);
    585     }
    586   malloc_string(pout_command);
    587   sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
    588   if (!(pout=popen(pout_command, "w")))
    589     {
    590       log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
    591       fclose(fin);
    592       paranoid_free(pout_command);
    593       return(4);
    594     }
    595   malloc_string(syscall);
    596   malloc_string(file_to_analyze);
    597   for (fgets (file_to_analyze, MAX_STR_LEN, fin); !feof (fin);
    598        fgets (file_to_analyze, MAX_STR_LEN, fin))
    599     {
    600       i = strlen(file_to_analyze);
    601       if (i>0 && file_to_analyze[i-1]<32) { file_to_analyze[i-1]='\0'; }
    602       log_msg(8, "Analyzing %s", file_to_analyze);
    603       sprintf(syscall, syscall_sprintf, file_to_analyze);
    604       strcat(syscall, " 2>> /dev/null"); // " MONDO_LOGFILE);
    605       call_exe_and_pipe_output_to_fd(syscall, pout);
    606     }
    607   paranoid_fclose(fin);
    608   paranoid_pclose(pout);
    609   paranoid_free(file_to_analyze);
    610   paranoid_free(syscall);
    611   paranoid_free(pout_command);
    612   return(0);
    613 }
    614 
    615 
    616 int get_acl_list(char*filelist, char*facl_fname)
    617 {
    618   char*command;
    619   int retval=0;
    620  
    621   malloc_string(command);
    622   sprintf(command, "touch %s", facl_fname);
    623   run_program_and_log_output(command, 8);
    624   if (find_home_of_exe("getfacl"))
    625     {
     524        free_filelist(filelist->down);
     525        filelist->down = NULL;
     526    }
     527    filelist->ch = '\0';
     528    paranoid_free(filelist);
     529    depth--;
     530    if (depth == 0) {
     531        close_evalcall_form();
     532        log_it("Finished freeing memory");
     533    }
     534}
     535
     536
     537int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
     538{
     539    FILE *pattr;
     540    char *tmp;
     541    pattr = popen(syscall, "r");
     542    if (!pattr) {
     543        log_msg(1, "Failed to open fattr() %s", syscall);
     544        return (1);
     545    }
     546    if (feof(pattr)) {
     547        log_msg(1, "Failed to call fattr() %s", syscall);
     548        paranoid_pclose(pattr);
     549        return (2);
     550    }
     551    malloc_string(tmp);
     552    for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr);
     553         fgets(tmp, MAX_STR_LEN, pattr)) {
     554        fputs(tmp, pout);
     555    }
     556    paranoid_pclose(pattr);
     557    paranoid_free(tmp);
     558    return (0);
     559}
     560
     561
     562
     563int gen_aux_list(char *filelist, char *syscall_sprintf,
     564                 char *auxlist_fname)
     565{
     566    FILE *fin;
     567    FILE *pout;
     568    char *pout_command;
     569    char *syscall;
     570    char *file_to_analyze;
     571    int i;
     572
     573    if (!(fin = fopen(filelist, "r"))) {
     574        log_msg(1, "Cannot openin filelist %s", filelist);
     575        return (1);
     576    }
     577    malloc_string(pout_command);
     578    sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
     579    if (!(pout = popen(pout_command, "w"))) {
     580        log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
     581        fclose(fin);
     582        paranoid_free(pout_command);
     583        return (4);
     584    }
     585    malloc_string(syscall);
     586    malloc_string(file_to_analyze);
     587    for (fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);
     588         fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     589        i = strlen(file_to_analyze);
     590        if (i > 0 && file_to_analyze[i - 1] < 32) {
     591            file_to_analyze[i - 1] = '\0';
     592        }
     593        log_msg(8, "Analyzing %s", file_to_analyze);
     594        sprintf(syscall, syscall_sprintf, file_to_analyze);
     595        strcat(syscall, " 2>> /dev/null");  // " MONDO_LOGFILE);
     596        call_exe_and_pipe_output_to_fd(syscall, pout);
     597    }
     598    paranoid_fclose(fin);
     599    paranoid_pclose(pout);
     600    paranoid_free(file_to_analyze);
     601    paranoid_free(syscall);
     602    paranoid_free(pout_command);
     603    return (0);
     604}
     605
     606
     607int get_acl_list(char *filelist, char *facl_fname)
     608{
     609    char *command;
     610    int retval = 0;
     611
     612    malloc_string(command);
     613    sprintf(command, "touch %s", facl_fname);
     614    run_program_and_log_output(command, 8);
     615    if (find_home_of_exe("getfacl")) {
    626616//      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    627       sprintf(command, "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s", filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
    628       iamhere(command);
    629       retval = system(command);
    630     }
    631   paranoid_free(command);
    632   return(retval);
    633 }
    634 
    635 
    636 int get_fattr_list(char*filelist, char*fattr_fname)
    637 {
    638   char *command;
    639   int retval=0;
    640  
    641   malloc_string(command);
    642   sprintf(command, "touch %s", fattr_fname);
    643   run_program_and_log_output(command, 8);
    644   if (find_home_of_exe("getfattr"))
    645     {
     617        sprintf(command,
     618                "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s",
     619                filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
     620        iamhere(command);
     621        retval = system(command);
     622    }
     623    paranoid_free(command);
     624    return (retval);
     625}
     626
     627
     628int get_fattr_list(char *filelist, char *fattr_fname)
     629{
     630    char *command;
     631    int retval = 0;
     632
     633    malloc_string(command);
     634    sprintf(command, "touch %s", fattr_fname);
     635    run_program_and_log_output(command, 8);
     636    if (find_home_of_exe("getfattr")) {
    646637//      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    647       retval = gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"", fattr_fname);
    648     }
    649   paranoid_free(command);
    650   return(retval);
     638        retval =
     639            gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"",
     640                         fattr_fname);
     641    }
     642    paranoid_free(command);
     643    return (retval);
    651644}
    652645
     
    674667
    675668
    676 int set_EXAT_list(char*orig_msklist, char*original_exat_fname, char*executable)
    677 {
    678   const int my_depth=8;
    679   char*command, *syscall_pin, *syscall_pout, *incoming;
    680   char*current_subset_file, *current_master_file, *masklist;
    681   int retval=0;
    682   int i;
    683   char*p,*q;
    684   FILE*pin, *pout, *faclin;
    685 
    686   malloc_string(command);
    687   log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable); 
    688   if (!orig_msklist || !orig_msklist[0] || !does_file_exist(orig_msklist))
    689     {
    690       log_msg(1, "No masklist provided. I shall therefore set ALL attributes.");
    691       sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s", original_exat_fname, executable, MONDO_LOGFILE);
    692       log_msg(1, "command = %s", command);
    693       retval = system(command);
    694       paranoid_free(command);
    695       log_msg(1, "Returning w/ retval=%d", retval);
    696       return(retval);
    697     }
    698   if (length_of_file(original_exat_fname) <= 0)
    699     {
    700       log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname);
    701       paranoid_free(command);
    702       return(0);
    703     }
    704   malloc_string(incoming);
    705   malloc_string(masklist);
    706   malloc_string(current_subset_file);
    707   malloc_string(current_master_file);
    708   malloc_string(syscall_pin);
    709   malloc_string(syscall_pout);
    710   sprintf(masklist, "/tmp/%d.%d.mask", (int)(random()%32768), (int)(random()%32768));
    711   sprintf(command, "cp -f %s %s", orig_msklist, masklist);
    712   run_program_and_log_output(command, 1);
    713   sort_file(masklist);
    714   current_subset_file[0] = current_master_file[0] = '\0';
    715   sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname);
    716   sprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
    717 
    718   log_msg(1, "syscall_pin = %s", syscall_pin);
    719   log_msg(1, "syscall_pout = %s", syscall_pout);
    720   pout = popen(syscall_pout, "w");
    721   if (!pout)
    722     { iamhere("Unable to openout to syscall_pout"); return(1); }
    723   pin = popen(syscall_pin, "r");
    724   if (!pin)
    725     { pclose(pout); iamhere("Unable to openin from syscall"); return(1); }
    726   faclin = fopen(masklist, "r");
    727   if (!faclin)
    728     { pclose(pin); pclose(pout); iamhere("Unable to openin masklist"); return(1); }
    729 
     669int set_EXAT_list(char *orig_msklist, char *original_exat_fname,
     670                  char *executable)
     671{
     672    const int my_depth = 8;
     673    char *command, *syscall_pin, *syscall_pout, *incoming;
     674    char *current_subset_file, *current_master_file, *masklist;
     675    int retval = 0;
     676    int i;
     677    char *p, *q;
     678    FILE *pin, *pout, *faclin;
     679
     680    malloc_string(command);
     681    log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
     682            original_exat_fname, executable);
     683    if (!orig_msklist || !orig_msklist[0]
     684        || !does_file_exist(orig_msklist)) {
     685        log_msg(1,
     686                "No masklist provided. I shall therefore set ALL attributes.");
     687        sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s",
     688                original_exat_fname, executable, MONDO_LOGFILE);
     689        log_msg(1, "command = %s", command);
     690        retval = system(command);
     691        paranoid_free(command);
     692        log_msg(1, "Returning w/ retval=%d", retval);
     693        return (retval);
     694    }
     695    if (length_of_file(original_exat_fname) <= 0) {
     696        log_msg(1,
     697                "original_exat_fname %s is empty or missing, so no need to set EXAT list",
     698                original_exat_fname);
     699        paranoid_free(command);
     700        return (0);
     701    }
     702    malloc_string(incoming);
     703    malloc_string(masklist);
     704    malloc_string(current_subset_file);
     705    malloc_string(current_master_file);
     706    malloc_string(syscall_pin);
     707    malloc_string(syscall_pout);
     708    sprintf(masklist, "/tmp/%d.%d.mask", (int) (random() % 32768),
     709            (int) (random() % 32768));
     710    sprintf(command, "cp -f %s %s", orig_msklist, masklist);
     711    run_program_and_log_output(command, 1);
     712    sort_file(masklist);
     713    current_subset_file[0] = current_master_file[0] = '\0';
     714    sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname);
     715    sprintf(syscall_pout, "%s --restore - 2>> %s", executable,
     716            MONDO_LOGFILE);
     717
     718    log_msg(1, "syscall_pin = %s", syscall_pin);
     719    log_msg(1, "syscall_pout = %s", syscall_pout);
     720    pout = popen(syscall_pout, "w");
     721    if (!pout) {
     722        iamhere("Unable to openout to syscall_pout");
     723        return (1);
     724    }
     725    pin = popen(syscall_pin, "r");
     726    if (!pin) {
     727        pclose(pout);
     728        iamhere("Unable to openin from syscall");
     729        return (1);
     730    }
     731    faclin = fopen(masklist, "r");
     732    if (!faclin) {
     733        pclose(pin);
     734        pclose(pout);
     735        iamhere("Unable to openin masklist");
     736        return (1);
     737    }
    730738//  printf("Hi there. Starting the loop\n");
    731  
    732   fgets(current_subset_file, MAX_STR_LEN, faclin);
    733   fgets(incoming, MAX_STR_LEN, pin);
    734   while(!feof(pin) && !feof(faclin))
    735     {
     739
     740    fgets(current_subset_file, MAX_STR_LEN, faclin);
     741    fgets(incoming, MAX_STR_LEN, pin);
     742    while (!feof(pin) && !feof(faclin)) {
    736743//      printf("incoming = %s", incoming);
    737      
    738       strcpy(current_master_file, incoming+8);
    739      
    740       p = current_subset_file;
    741       if (*p=='/') {p++;}
    742       i = strlen(p);
    743       if (i>0 && p[i-1]<32) { p[i-1] = '\0'; }
    744 
    745            
    746       q = current_master_file;
    747       if (*q=='/') {q++;}
    748       i = strlen(q);
    749       if (i>0 && q[i-1]<32) { q[i-1] = '\0'; }
    750 
    751       i = strcmp(p,q);
    752       log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
    753      
     744
     745        strcpy(current_master_file, incoming + 8);
     746
     747        p = current_subset_file;
     748        if (*p == '/') {
     749            p++;
     750        }
     751        i = strlen(p);
     752        if (i > 0 && p[i - 1] < 32) {
     753            p[i - 1] = '\0';
     754        }
     755
     756
     757        q = current_master_file;
     758        if (*q == '/') {
     759            q++;
     760        }
     761        i = strlen(q);
     762        if (i > 0 && q[i - 1] < 32) {
     763            q[i - 1] = '\0';
     764        }
     765
     766        i = strcmp(p, q);
     767        log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
     768
    754769//      printf("%s v %s --> %d\n", p, q, i);
    755      
    756       if (i<0)
    757         { // read another subset file in.
    758       log_msg(my_depth, "Reading next subset line in\n\n");
    759       fgets(current_subset_file, MAX_STR_LEN, faclin);
    760       continue;
    761     }
    762 
    763       if (!i) { fputs(incoming, pout); }
    764       fgets(incoming, MAX_STR_LEN, pin);
    765       if (!i) { log_msg(my_depth, "Copying master %s", q); }
    766      
     770
     771        if (i < 0) {            // read another subset file in.
     772            log_msg(my_depth, "Reading next subset line in\n\n");
     773            fgets(current_subset_file, MAX_STR_LEN, faclin);
     774            continue;
     775        }
     776
     777        if (!i) {
     778            fputs(incoming, pout);
     779        }
     780        fgets(incoming, MAX_STR_LEN, pin);
     781        if (!i) {
     782            log_msg(my_depth, "Copying master %s", q);
     783        }
    767784//      if (!i) { printf("Match --- %s\n", q); }
    768      
    769       while (!feof(pin) && strncmp(incoming, "# file: ", 8))
    770         {
    771           if (!i) {
    772      
    773 //    printf("%s", incoming);
    774      
    775       fputs(incoming, pout); }
    776           fgets(incoming, MAX_STR_LEN, pin);
    777         }
    778       if (!i) { fgets(current_subset_file, MAX_STR_LEN, faclin); }
    779     }
    780   while(!feof(pin)) { fgets (incoming, MAX_STR_LEN, pin); }
    781   fclose(faclin);
    782   pclose(pin);
    783   pclose(pout); 
    784  
     785
     786        while (!feof(pin) && strncmp(incoming, "# file: ", 8)) {
     787            if (!i) {
     788
     789//    printf("%s", incoming);
     790
     791                fputs(incoming, pout);
     792            }
     793            fgets(incoming, MAX_STR_LEN, pin);
     794        }
     795        if (!i) {
     796            fgets(current_subset_file, MAX_STR_LEN, faclin);
     797        }
     798    }
     799    while (!feof(pin)) {
     800        fgets(incoming, MAX_STR_LEN, pin);
     801    }
     802    fclose(faclin);
     803    pclose(pin);
     804    pclose(pout);
     805
    785806//  printf("OK, loop is done\n");
    786807
    787   unlink(masklist); 
    788   paranoid_free(current_subset_file);
    789   paranoid_free(current_master_file);
    790   paranoid_free(syscall_pout);
    791   paranoid_free(syscall_pin);
    792   paranoid_free(masklist);
    793   paranoid_free(incoming);
    794   paranoid_free(command);
    795   return(retval);
    796 } 
    797 
    798 
    799 int set_fattr_list(char*masklist, char*fattr_fname)
    800 {
    801   return(set_EXAT_list(masklist, fattr_fname, "setfattr"));
    802 }
    803 
    804 
    805 
    806 int set_acl_list(char*masklist, char*acl_fname)
    807 {
    808   return(set_EXAT_list(masklist, acl_fname, "setfacl"));
     808    unlink(masklist);
     809    paranoid_free(current_subset_file);
     810    paranoid_free(current_master_file);
     811    paranoid_free(syscall_pout);
     812    paranoid_free(syscall_pin);
     813    paranoid_free(masklist);
     814    paranoid_free(incoming);
     815    paranoid_free(command);
     816    return (retval);
     817}
     818
     819
     820int set_fattr_list(char *masklist, char *fattr_fname)
     821{
     822    return (set_EXAT_list(masklist, fattr_fname, "setfattr"));
     823}
     824
     825
     826
     827int set_acl_list(char *masklist, char *acl_fname)
     828{
     829    return (set_EXAT_list(masklist, acl_fname, "setfacl"));
    809830}
    810831
     
    833854 * @note This function should only be called at restore-time.
    834855 */
    835 int
    836 get_last_filelist_number (struct s_bkpinfo *bkpinfo)
    837 {
    838     /*@ buffers ******************************************************/
    839   char val_sz[MAX_STR_LEN];
    840   char cfg_fname[MAX_STR_LEN];
     856int get_last_filelist_number(struct s_bkpinfo *bkpinfo)
     857{
     858    /*@ buffers ***************************************************** */
     859    char val_sz[MAX_STR_LEN];
     860    char cfg_fname[MAX_STR_LEN];
    841861/*  char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */
    842862
    843     /*@ long *********************************************************/
    844   int val_i;
    845 
    846     /*@ end vars *****************************************************/
    847 
    848   assert(bkpinfo!=NULL);
    849 
    850   sprintf (cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
    851   read_cfg_var (cfg_fname, "last-filelist-number", val_sz);
    852   val_i = atoi (val_sz);
    853   if (val_i <= 0)
    854     {
    855       val_i = 500;
    856     }
    857   return (val_i);
     863    /*@ long ******************************************************** */
     864    int val_i;
     865
     866    /*@ end vars **************************************************** */
     867
     868    assert(bkpinfo != NULL);
     869
     870    sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
     871    read_cfg_var(cfg_fname, "last-filelist-number", val_sz);
     872    val_i = atoi(val_sz);
     873    if (val_i <= 0) {
     874        val_i = 500;
     875    }
     876    return (val_i);
    858877}
    859878
     
    866885 * @bug I don't understand this function. Would someone care to explain it?
    867886 */
    868 int
    869 add_string_at_node (struct s_node *startnode, char *string_to_add)
    870 {
    871 
    872 
    873     /*@ int *********************************************************/
    874   int noof_chars;
    875   int i;
    876   int res;
    877 
    878     /*@ sturctures **************************************************/
    879   struct s_node *node, *newnode;
    880 
    881     /*@ char  *******************************************************/
    882   char char_to_add;
    883 
    884     /*@ bools *******************************************************/
    885 
    886   const bool sosodef = FALSE;
    887 
    888   static int depth=0;
    889   static char original_string[MAX_STR_LEN];
    890 
    891   assert(startnode!=NULL);
    892   assert(string_to_add!=NULL);
    893 
    894   if (!depth) { strcpy(original_string, string_to_add); }
    895 
    896   noof_chars = strlen (string_to_add) + 1;  /* we include the '\0' */
     887int add_string_at_node(struct s_node *startnode, char *string_to_add)
     888{
     889
     890
     891    /*@ int ******************************************************** */
     892    int noof_chars;
     893    int i;
     894    int res;
     895
     896    /*@ sturctures ************************************************* */
     897    struct s_node *node, *newnode;
     898
     899    /*@ char  ****************************************************** */
     900    char char_to_add;
     901
     902    /*@ bools ****************************************************** */
     903
     904    const bool sosodef = FALSE;
     905
     906    static int depth = 0;
     907    static char original_string[MAX_STR_LEN];
     908
     909    assert(startnode != NULL);
     910    assert(string_to_add != NULL);
     911
     912    if (!depth) {
     913        strcpy(original_string, string_to_add);
     914    }
     915
     916    noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    897917
    898918/* walk across tree if necessary */
    899   node = startnode;
    900   char_to_add = string_to_add[0];
    901   if (node->right != NULL && node->ch < char_to_add)
    902     {
    903       log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth, char_to_add, node->ch, (node->right)->ch);
    904       return (add_string_at_node (node->right, string_to_add));
    905     }
     919    node = startnode;
     920    char_to_add = string_to_add[0];
     921    if (node->right != NULL && node->ch < char_to_add) {
     922        log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
     923                char_to_add, node->ch, (node->right)->ch);
     924        return (add_string_at_node(node->right, string_to_add));
     925    }
    906926
    907927/* walk down tree if appropriate */
    908   if (node->down != NULL && node->ch == char_to_add)
    909     {
    910       log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
    911       depth++;
    912       res = add_string_at_node (node->down, string_to_add + 1);
    913       depth--;
    914       return (res);
    915     }
    916 
    917   if (char_to_add == '\0' && node->ch =='\0')
    918     {
    919       log_msg(6, "%s already in tree", original_string);
    920       return(1);
    921     }
     928    if (node->down != NULL && node->ch == char_to_add) {
     929        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     930        depth++;
     931        res = add_string_at_node(node->down, string_to_add + 1);
     932        depth--;
     933        return (res);
     934    }
     935
     936    if (char_to_add == '\0' && node->ch == '\0') {
     937        log_msg(6, "%s already in tree", original_string);
     938        return (1);
     939    }
    922940
    923941/* add here */
    924   if (!(newnode = (struct s_node*)malloc (sizeof (struct s_node))))
    925             {
    926               log_to_screen ("failed to malloc");
    927               depth--;
    928               return (1);
    929             }
    930   if (char_to_add < node->ch) // add to the left of node
    931     {
    932       log_msg(7, "depth=%d char=%c --- adding (left)", depth, char_to_add);
    933       memcpy((void*)newnode, (void*)node, sizeof(struct s_node));
    934       node->right = newnode;
    935     }
    936   else if (char_to_add > node->ch) // add to the right of node
    937     {
    938       log_msg(7, "depth=%d char=%c --- adding (right)", depth, char_to_add);
    939       newnode->right = node->right; // newnode is to the RIGHT of node
    940       node->right = newnode;
    941       node = newnode;
    942     }
    943   // from now on, we're working on 'node'
    944   node->down = NULL;
    945   node->ch = char_to_add;
    946   node->expanded = node->selected = FALSE;
    947   if (char_to_add == '\0')
    948     {
    949       log_msg (6, "Added %s OK", original_string);
    950       return (0);
    951     }
    952 
     942    if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
     943        log_to_screen("failed to malloc");
     944        depth--;
     945        return (1);
     946    }
     947    if (char_to_add < node->ch) // add to the left of node
     948    {
     949        log_msg(7, "depth=%d char=%c --- adding (left)", depth,
     950                char_to_add);
     951        memcpy((void *) newnode, (void *) node, sizeof(struct s_node));
     952        node->right = newnode;
     953    } else if (char_to_add > node->ch)  // add to the right of node
     954    {
     955        log_msg(7, "depth=%d char=%c --- adding (right)", depth,
     956                char_to_add);
     957        newnode->right = node->right;   // newnode is to the RIGHT of node
     958        node->right = newnode;
     959        node = newnode;
     960    }
     961    // from now on, we're working on 'node'
     962    node->down = NULL;
     963    node->ch = char_to_add;
     964    node->expanded = node->selected = FALSE;
     965    if (char_to_add == '\0') {
     966        log_msg(6, "Added %s OK", original_string);
     967        return (0);
     968    }
    953969// add the rest
    954   log_msg(6, "Adding remaining chars ('%s')", string_to_add+1);
    955   for (i = 1; i < noof_chars; i++)
    956     {
    957       if (!(node->down = (struct s_node*)malloc (sizeof (struct s_node))))
    958     {
    959       log_to_screen ("%s - failed to malloc", string_to_add);
    960       return (1);
    961     }
    962       node = node->down;
    963       char_to_add = string_to_add[i];
    964       log_msg(6, "Adding '%c'", char_to_add);
    965       node->ch = char_to_add;
    966       node->right = node->down = NULL;
    967       node->expanded = node->selected = FALSE;
    968       if (!node->ch) { node->selected = sosodef; }
    969     }
    970   log_msg (6, "Finally - added %s OK", original_string);
    971   return (0);
     970    log_msg(6, "Adding remaining chars ('%s')", string_to_add + 1);
     971    for (i = 1; i < noof_chars; i++) {
     972        if (!
     973            (node->down =
     974             (struct s_node *) malloc(sizeof(struct s_node)))) {
     975            log_to_screen("%s - failed to malloc", string_to_add);
     976            return (1);
     977        }
     978        node = node->down;
     979        char_to_add = string_to_add[i];
     980        log_msg(6, "Adding '%c'", char_to_add);
     981        node->ch = char_to_add;
     982        node->right = node->down = NULL;
     983        node->expanded = node->selected = FALSE;
     984        if (!node->ch) {
     985            node->selected = sosodef;
     986        }
     987    }
     988    log_msg(6, "Finally - added %s OK", original_string);
     989    return (0);
    972990}
    973991
     
    981999 * @return A filelist tree structure.
    9821000 */
    983 struct s_node *
    984 load_filelist (char *filelist_fname)
    985 {
    986 
    987     /*@ structures **************************************************/
    988   struct s_node *filelist;
    989 
    990     /*@ pointers ****************************************************/
    991   FILE *pin;
    992 
    993     /*@ buffers *****************************************************/
    994   char command_to_open_fname[MAX_STR_LEN];
    995   char fname[MAX_STR_LEN];
    996   char tmp[MAX_STR_LEN];
    997   int pos_in_fname;
    998     /*@ int *********************************************************/
    999   int percentage;
    1000 
    1001     /*@ long ********************************************************/
    1002   long lines_in_filelist;
    1003   long lino = 0;
    1004     /*@ end vars ****************************************************/
    1005 
    1006   assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
    1007 
    1008   if (!does_file_exist(filelist_fname))
    1009     { fatal_error("filelist does not exist -- cannot load it"); }
    1010   log_to_screen ("Loading filelist");
    1011   sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
    1012   sprintf(tmp, "zcat %s | wc -l", filelist_fname);
    1013   log_msg(6, "tmp = %s", tmp);
    1014   lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp));
    1015   if (lines_in_filelist < 3) { log_to_screen("Warning - surprisingly short filelist."); }
    1016   g_original_noof_lines_in_filelist = lines_in_filelist;
    1017   if (!(filelist = (struct s_node*)malloc (sizeof (struct s_node))))
    1018     {
    1019       return (NULL);
    1020     }
    1021   filelist->ch = '/';
    1022   filelist->right = NULL;
    1023   filelist->down = malloc(sizeof(struct s_node));
    1024   filelist->expanded = filelist->selected = FALSE;
    1025   (filelist->down)->ch = '\0';
    1026   (filelist->down)->right = (filelist->down)->down = FALSE;
    1027   (filelist->down)->expanded = (filelist->down)->selected = FALSE;
    1028   if (!(pin = popen (command_to_open_fname, "r")))
    1029     {
    1030       log_OS_error("Unable to openin filelist_fname");
    1031       return (NULL);
    1032     }
    1033   open_evalcall_form ("Loading filelist from disk");
    1034   for (fgets (fname, MAX_STR_LEN, pin); !feof (pin);
    1035        fgets (fname, MAX_STR_LEN, pin))
    1036     {
    1037       if ((fname[strlen(fname)-1]==13 || fname[strlen(fname)-1]==10) && strlen(fname)>0)
    1038         { fname[strlen(fname)-1] = '\0'; }
     1001struct s_node *load_filelist(char *filelist_fname)
     1002{
     1003
     1004    /*@ structures ************************************************* */
     1005    struct s_node *filelist;
     1006
     1007    /*@ pointers *************************************************** */
     1008    FILE *pin;
     1009
     1010    /*@ buffers **************************************************** */
     1011    char command_to_open_fname[MAX_STR_LEN];
     1012    char fname[MAX_STR_LEN];
     1013    char tmp[MAX_STR_LEN];
     1014    int pos_in_fname;
     1015    /*@ int ******************************************************** */
     1016    int percentage;
     1017
     1018    /*@ long ******************************************************* */
     1019    long lines_in_filelist;
     1020    long lino = 0;
     1021    /*@ end vars *************************************************** */
     1022
     1023    assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
     1024
     1025    if (!does_file_exist(filelist_fname)) {
     1026        fatal_error("filelist does not exist -- cannot load it");
     1027    }
     1028    log_to_screen("Loading filelist");
     1029    sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
     1030    sprintf(tmp, "zcat %s | wc -l", filelist_fname);
     1031    log_msg(6, "tmp = %s", tmp);
     1032    lines_in_filelist =
     1033        atol(call_program_and_get_last_line_of_output(tmp));
     1034    if (lines_in_filelist < 3) {
     1035        log_to_screen("Warning - surprisingly short filelist.");
     1036    }
     1037    g_original_noof_lines_in_filelist = lines_in_filelist;
     1038    if (!(filelist = (struct s_node *) malloc(sizeof(struct s_node)))) {
     1039        return (NULL);
     1040    }
     1041    filelist->ch = '/';
     1042    filelist->right = NULL;
     1043    filelist->down = malloc(sizeof(struct s_node));
     1044    filelist->expanded = filelist->selected = FALSE;
     1045    (filelist->down)->ch = '\0';
     1046    (filelist->down)->right = (filelist->down)->down = FALSE;
     1047    (filelist->down)->expanded = (filelist->down)->selected = FALSE;
     1048    if (!(pin = popen(command_to_open_fname, "r"))) {
     1049        log_OS_error("Unable to openin filelist_fname");
     1050        return (NULL);
     1051    }
     1052    open_evalcall_form("Loading filelist from disk");
     1053    for (fgets(fname, MAX_STR_LEN, pin); !feof(pin);
     1054         fgets(fname, MAX_STR_LEN, pin)) {
     1055        if ((fname[strlen(fname) - 1] == 13
     1056             || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) {
     1057            fname[strlen(fname) - 1] = '\0';
     1058        }
    10391059//      strip_spaces (fname);
    1040       if (!strlen (fname))
    1041     {
    1042       continue;
    1043     }
    1044       for(pos_in_fname=0; fname[pos_in_fname]!='\0'; pos_in_fname++)
    1045         {
    1046       if (fname[pos_in_fname]!='/') { continue; }
    1047       strcpy(tmp, fname);
    1048       tmp[pos_in_fname] = '\0';
    1049       if (strlen(tmp))
    1050         { add_string_at_node (filelist, tmp); }
    1051     }
    1052       add_string_at_node (filelist, fname);
    1053       if (!(++lino % 1111))
    1054     {
    1055       percentage = (int) (lino * 100 / lines_in_filelist);
    1056       update_evalcall_form (percentage);
    1057     }
    1058     }
    1059   paranoid_pclose(pin);
    1060   close_evalcall_form ();
    1061   log_it ("Finished loading filelist");
    1062   return (filelist);
     1060        if (!strlen(fname)) {
     1061            continue;
     1062        }
     1063        for (pos_in_fname = 0; fname[pos_in_fname] != '\0'; pos_in_fname++) {
     1064            if (fname[pos_in_fname] != '/') {
     1065                continue;
     1066            }
     1067            strcpy(tmp, fname);
     1068            tmp[pos_in_fname] = '\0';
     1069            if (strlen(tmp)) {
     1070                add_string_at_node(filelist, tmp);
     1071            }
     1072        }
     1073        add_string_at_node(filelist, fname);
     1074        if (!(++lino % 1111)) {
     1075            percentage = (int) (lino * 100 / lines_in_filelist);
     1076            update_evalcall_form(percentage);
     1077        }
     1078    }
     1079    paranoid_pclose(pin);
     1080    close_evalcall_form();
     1081    log_it("Finished loading filelist");
     1082    return (filelist);
    10631083}
    10641084
     
    10681088 * @param node The toplevel node to use.
    10691089 */
    1070 void
    1071 show_filelist (struct s_node *node)
    1072 {
    1073   static int depth=0;
    1074   static char current_string[200];
    1075 
    1076   if (depth==0)
    1077     { log_msg(0, "----------------show filelist--------------"); }
    1078   current_string[depth] = node->ch;
    1079 
    1080   log_msg(3, "depth=%d", depth);
    1081   if (node->down)
    1082     {
    1083       log_msg(3, "moving down");
    1084       depth++;
    1085       show_filelist(node->down);
    1086       depth--;
    1087     }
    1088 
    1089   if (!node->ch)
    1090     {
    1091       log_msg(0, "%s\n", current_string);
    1092     }
    1093 
    1094   if (node->right)
    1095     {
    1096       log_msg(3, "moving right");
    1097       show_filelist(node->right);
    1098     }
    1099   if (depth==0)
    1100     { log_msg(0, "----------------show filelist--------------"); }
    1101   return;
     1090void show_filelist(struct s_node *node)
     1091{
     1092    static int depth = 0;
     1093    static char current_string[200];
     1094
     1095    if (depth == 0) {
     1096        log_msg(0, "----------------show filelist--------------");
     1097    }
     1098    current_string[depth] = node->ch;
     1099
     1100    log_msg(3, "depth=%d", depth);
     1101    if (node->down) {
     1102        log_msg(3, "moving down");
     1103        depth++;
     1104        show_filelist(node->down);
     1105        depth--;
     1106    }
     1107
     1108    if (!node->ch) {
     1109        log_msg(0, "%s\n", current_string);
     1110    }
     1111
     1112    if (node->right) {
     1113        log_msg(3, "moving right");
     1114        show_filelist(node->right);
     1115    }
     1116    if (depth == 0) {
     1117        log_msg(0, "----------------show filelist--------------");
     1118    }
     1119    return;
    11021120}
    11031121
     
    11101128 * @param filelist The filelist tree structure.
    11111129 */
    1112 void
    1113 reload_filelist (struct s_node *filelist)
    1114 {
    1115   assert(filelist!=NULL);
    1116   toggle_node_selection (filelist, FALSE);
    1117   toggle_path_expandability (filelist, "/", FALSE);
    1118   toggle_all_root_dirs_on (filelist);
     1130void reload_filelist(struct s_node *filelist)
     1131{
     1132    assert(filelist != NULL);
     1133    toggle_node_selection(filelist, FALSE);
     1134    toggle_path_expandability(filelist, "/", FALSE);
     1135    toggle_all_root_dirs_on(filelist);
    11191136}
    11201137
     
    11261143 * @param outfname Where to save it.
    11271144 */
    1128 void
    1129 save_filelist (struct s_node *filelist, char *outfname)
    1130 {
    1131     /*@ int **********************************************************/
    1132   static int percentage;
    1133   static int depth = 0;
    1134 
    1135     /*@ buffers ******************************************************/
    1136   static char str[MAX_STR_LEN];
    1137 
    1138     /*@ structures ***************************************************/
    1139   struct s_node *node;
    1140 
    1141     /*@ pointers *****************************************************/
    1142   static FILE *fout = NULL;
    1143 
    1144     /*@ long *********************************************************/
    1145   static long lines_in_filelist = 0;
    1146   static long lino = 0;
    1147 
    1148     /*@ end vars ****************************************************/
    1149 
    1150   assert(filelist!=NULL);
    1151   assert(outfname!=NULL); // will be zerolength if save_filelist() is called by itself
    1152   if (depth == 0)
    1153     {
    1154       log_to_screen ("Saving filelist");
    1155       if (!(fout = fopen (outfname, "w"))) { fatal_error("Cannot openout/save filelist"); }
    1156       lines_in_filelist = g_original_noof_lines_in_filelist;    /* set by load_filelist() */
    1157       open_evalcall_form ("Saving selection to disk");
    1158     }
    1159   for (node = filelist; node != NULL; node = node->right)
    1160     {
    1161       str[depth] = node->ch;
    1162       log_msg(5, "depth=%d ch=%c", depth, node->ch);
    1163       if (!node->ch)
    1164     {
    1165 //    if (node->selected)
    1166 //      {
    1167           fprintf (fout, "%s\n", str);
    1168 //      }
    1169       if (!(++lino % 1111))
    1170         {
    1171           percentage = (int) (lino * 100 / lines_in_filelist);
    1172           update_evalcall_form (percentage);
    1173         }
    1174     }
    1175       if (node->down)
    1176     {
    1177       depth++;
    1178       save_filelist (node->down, "");
    1179       depth--;
    1180     }
    1181     }
    1182   if (depth == 0)
    1183     {
    1184       paranoid_fclose (fout);
    1185       close_evalcall_form ();
    1186       log_it ("Finished saving filelist");
    1187     }
     1145void save_filelist(struct s_node *filelist, char *outfname)
     1146{
     1147    /*@ int ********************************************************* */
     1148    static int percentage;
     1149    static int depth = 0;
     1150
     1151    /*@ buffers ***************************************************** */
     1152    static char str[MAX_STR_LEN];
     1153
     1154    /*@ structures ************************************************** */
     1155    struct s_node *node;
     1156
     1157    /*@ pointers **************************************************** */
     1158    static FILE *fout = NULL;
     1159
     1160    /*@ long ******************************************************** */
     1161    static long lines_in_filelist = 0;
     1162    static long lino = 0;
     1163
     1164    /*@ end vars *************************************************** */
     1165
     1166    assert(filelist != NULL);
     1167    assert(outfname != NULL);   // will be zerolength if save_filelist() is called by itself
     1168    if (depth == 0) {
     1169        log_to_screen("Saving filelist");
     1170        if (!(fout = fopen(outfname, "w"))) {
     1171            fatal_error("Cannot openout/save filelist");
     1172        }
     1173        lines_in_filelist = g_original_noof_lines_in_filelist;  /* set by load_filelist() */
     1174        open_evalcall_form("Saving selection to disk");
     1175    }
     1176    for (node = filelist; node != NULL; node = node->right) {
     1177        str[depth] = node->ch;
     1178        log_msg(5, "depth=%d ch=%c", depth, node->ch);
     1179        if (!node->ch) {
     1180//    if (node->selected)
     1181//      {
     1182            fprintf(fout, "%s\n", str);
     1183//      }
     1184            if (!(++lino % 1111)) {
     1185                percentage = (int) (lino * 100 / lines_in_filelist);
     1186                update_evalcall_form(percentage);
     1187            }
     1188        }
     1189        if (node->down) {
     1190            depth++;
     1191            save_filelist(node->down, "");
     1192            depth--;
     1193        }
     1194    }
     1195    if (depth == 0) {
     1196        paranoid_fclose(fout);
     1197        close_evalcall_form();
     1198        log_it("Finished saving filelist");
     1199    }
    11881200}
    11891201
     
    11951207 * @bug I don't understand this function. Would someone care to explain it?
    11961208 */
    1197 void
    1198 toggle_all_root_dirs_on (struct s_node *filelist)
    1199 {
    1200     /*@ structures ***************************************************/
    1201   struct s_node *node;
    1202 
    1203     /*@ int **********************************************************/
    1204   static int depth = 0;
    1205   static int root_dirs_expanded;
    1206 
    1207     /*@ buffers ******************************************************/
    1208   static char filename[MAX_STR_LEN];
    1209 
    1210     /*@ end vars ****************************************************/
    1211 
    1212   assert(filelist!=NULL);
    1213   if (depth == 0)
    1214     {
    1215       log_it ("Toggling all root dirs ON");
    1216       root_dirs_expanded = 0;
    1217     }
    1218   for (node = filelist; node != NULL; node = node->right)
    1219     {
    1220       filename[depth] = node->ch;
    1221       if (node->ch == '\0' && strlen (filename) > 1
    1222       && (!strchr (filename + 1, '/')))
    1223     {
    1224       node->selected = FALSE;
    1225       node->expanded = TRUE;
    1226 //    log_it (filename);
    1227       root_dirs_expanded++;
    1228     }
    1229       if (node->down)
    1230     {
    1231       depth++;
    1232       toggle_all_root_dirs_on (node->down);
    1233       depth--;
    1234     }
    1235     }
    1236   if (depth == 0)
    1237     {
    1238       log_it ("Finished toggling all root dirs ON");
    1239     }
     1209void toggle_all_root_dirs_on(struct s_node *filelist)
     1210{
     1211    /*@ structures ************************************************** */
     1212    struct s_node *node;
     1213
     1214    /*@ int ********************************************************* */
     1215    static int depth = 0;
     1216    static int root_dirs_expanded;
     1217
     1218    /*@ buffers ***************************************************** */
     1219    static char filename[MAX_STR_LEN];
     1220
     1221    /*@ end vars *************************************************** */
     1222
     1223    assert(filelist != NULL);
     1224    if (depth == 0) {
     1225        log_it("Toggling all root dirs ON");
     1226        root_dirs_expanded = 0;
     1227    }
     1228    for (node = filelist; node != NULL; node = node->right) {
     1229        filename[depth] = node->ch;
     1230        if (node->ch == '\0' && strlen(filename) > 1
     1231            && (!strchr(filename + 1, '/'))) {
     1232            node->selected = FALSE;
     1233            node->expanded = TRUE;
     1234//    log_it (filename);
     1235            root_dirs_expanded++;
     1236        }
     1237        if (node->down) {
     1238            depth++;
     1239            toggle_all_root_dirs_on(node->down);
     1240            depth--;
     1241        }
     1242    }
     1243    if (depth == 0) {
     1244        log_it("Finished toggling all root dirs ON");
     1245    }
    12401246}
    12411247
     
    12491255 */
    12501256void
    1251 toggle_path_expandability (struct s_node *filelist, char *pathname,
    1252                bool on_or_off)
    1253 {
    1254 
    1255     /*@ int *********************************************************/
    1256   static int depth = 0;
    1257   static int total_expanded;
    1258   static int root_depth;
    1259   int j;
    1260     /*@ structures **************************************************/
    1261   struct s_node *node;
    1262 
    1263     /*@ buffers *****************************************************/
    1264   static char current_filename[MAX_STR_LEN];
     1257toggle_path_expandability(struct s_node *filelist, char *pathname,
     1258                          bool on_or_off)
     1259{
     1260
     1261    /*@ int ******************************************************** */
     1262    static int depth = 0;
     1263    static int total_expanded;
     1264    static int root_depth;
     1265    int j;
     1266    /*@ structures ************************************************* */
     1267    struct s_node *node;
     1268
     1269    /*@ buffers **************************************************** */
     1270    static char current_filename[MAX_STR_LEN];
    12651271
    12661272/*  char tmp[MAX_STR_LEN+2]; */
    12671273
    1268     /*@ end vars ****************************************************/
    1269 
    1270   assert(filelist!=NULL);
    1271   assert_string_is_neither_NULL_nor_zerolength(pathname);
    1272   if (depth == 0)
    1273     {
    1274       total_expanded = 0;
     1274    /*@ end vars *************************************************** */
     1275
     1276    assert(filelist != NULL);
     1277    assert_string_is_neither_NULL_nor_zerolength(pathname);
     1278    if (depth == 0) {
     1279        total_expanded = 0;
    12751280//      log_it ("Toggling path's expandability");
    1276       for (root_depth = (int) strlen (pathname);
    1277        root_depth > 0 && pathname[root_depth - 1] != '/'; root_depth--);
    1278       if (root_depth < 2)
    1279     {
    1280       root_depth = (int) strlen (pathname);
    1281     }
    1282     }
    1283   for (node = filelist; node != NULL; node = node->right)
    1284     {
    1285       current_filename[depth] = node->ch;
    1286       if (node->down)
    1287     {
    1288       depth++;
    1289       toggle_path_expandability (node->down, pathname, on_or_off);
    1290       depth--;
    1291     }
    1292       if (node->ch == '\0')
    1293     {
    1294       if (!strncmp (pathname, current_filename, strlen (pathname)))
    1295         {
    1296           for (j = root_depth;
    1297            current_filename[j] != '/' && current_filename[j] != '\0';
    1298            j++);
    1299           if (current_filename[j] != '\0')
    1300         {
    1301           for (j++;
    1302                current_filename[j] != '/'
    1303                && current_filename[j] != '\0'; j++);
    1304         }
    1305           if (current_filename[j] == '\0')
    1306         {
    1307           node->expanded =
    1308             (!strcmp (pathname, current_filename) ? TRUE : on_or_off);
    1309         }
    1310         }
    1311     }
    1312       if (node->expanded)
    1313     {
    1314       if (total_expanded < ARBITRARY_MAXIMUM - 32
    1315           || !strrchr (current_filename + strlen (pathname), '/'))
    1316         {
    1317           total_expanded++;
    1318         }
    1319       else
    1320         {
    1321           node->expanded = FALSE;
    1322         }
    1323     }
    1324     }
    1325   if (depth == 0)
    1326     {
     1281        for (root_depth = (int) strlen(pathname);
     1282             root_depth > 0 && pathname[root_depth - 1] != '/';
     1283             root_depth--);
     1284        if (root_depth < 2) {
     1285            root_depth = (int) strlen(pathname);
     1286        }
     1287    }
     1288    for (node = filelist; node != NULL; node = node->right) {
     1289        current_filename[depth] = node->ch;
     1290        if (node->down) {
     1291            depth++;
     1292            toggle_path_expandability(node->down, pathname, on_or_off);
     1293            depth--;
     1294        }
     1295        if (node->ch == '\0') {
     1296            if (!strncmp(pathname, current_filename, strlen(pathname))) {
     1297                for (j = root_depth;
     1298                     current_filename[j] != '/'
     1299                     && current_filename[j] != '\0'; j++);
     1300                if (current_filename[j] != '\0') {
     1301                    for (j++;
     1302                         current_filename[j] != '/'
     1303                         && current_filename[j] != '\0'; j++);
     1304                }
     1305                if (current_filename[j] == '\0') {
     1306                    node->expanded =
     1307                        (!strcmp(pathname, current_filename) ? TRUE :
     1308                         on_or_off);
     1309                }
     1310            }
     1311        }
     1312        if (node->expanded) {
     1313            if (total_expanded < ARBITRARY_MAXIMUM - 32
     1314                || !strrchr(current_filename + strlen(pathname), '/')) {
     1315                total_expanded++;
     1316            } else {
     1317                node->expanded = FALSE;
     1318            }
     1319        }
     1320    }
     1321    if (depth == 0) {
    13271322//      log_it ("Finished toggling expandability");
    1328     }
     1323    }
    13291324}
    13301325
     
    13371332 */
    13381333void
    1339 toggle_path_selection (struct s_node *filelist, char *pathname,
    1340                bool on_or_off)
    1341 {
    1342     /*@ int **********************************************************/
    1343   static int depth = 0;
    1344   int j;
    1345 
    1346     /*@ structures ***************************************************/
    1347   struct s_node *node;
    1348 
    1349     /*@ buffers ******************************************************/
    1350   static char current_filename[MAX_STR_LEN];
    1351   char tmp[MAX_STR_LEN + 2];
    1352 
    1353     /*@ end vars ****************************************************/
    1354   assert(filelist!=NULL);
    1355   assert_string_is_neither_NULL_nor_zerolength(pathname);
    1356   if (depth == 0)
    1357     {
    1358       log_it ("Toggling path's selection");
    1359     }
    1360   for (node = filelist; node != NULL; node = node->right)
    1361     {
    1362       current_filename[depth] = node->ch;
    1363       if (node->down)
    1364     {
    1365       depth++;
    1366       toggle_path_selection (node->down, pathname, on_or_off);
    1367       depth--;
    1368     }
    1369       if (node->ch == '\0')
    1370     {
    1371       if (!strncmp (pathname, current_filename, strlen (pathname)))
    1372         {
    1373           for (j = 0;
    1374            pathname[j] != '\0' && pathname[j] == current_filename[j];
    1375            j++);
    1376           if (current_filename[j] == '/' || current_filename[j] == '\0')
    1377         {
    1378           node->selected = on_or_off;
    1379           sprintf (tmp, "%s is now %s\n", current_filename,
    1380                (on_or_off ? "ON" : "OFF"));
    1381         }
    1382         }
    1383     }
    1384     }
    1385   if (depth == 0)
    1386     {
    1387       log_it ("Finished toggling selection");
    1388     }
     1334toggle_path_selection(struct s_node *filelist, char *pathname,
     1335                      bool on_or_off)
     1336{
     1337    /*@ int ********************************************************* */
     1338    static int depth = 0;
     1339    int j;
     1340
     1341    /*@ structures ************************************************** */
     1342    struct s_node *node;
     1343
     1344    /*@ buffers ***************************************************** */
     1345    static char current_filename[MAX_STR_LEN];
     1346    char tmp[MAX_STR_LEN + 2];
     1347
     1348    /*@ end vars *************************************************** */
     1349    assert(filelist != NULL);
     1350    assert_string_is_neither_NULL_nor_zerolength(pathname);
     1351    if (depth == 0) {
     1352        log_it("Toggling path's selection");
     1353    }
     1354    for (node = filelist; node != NULL; node = node->right) {
     1355        current_filename[depth] = node->ch;
     1356        if (node->down) {
     1357            depth++;
     1358            toggle_path_selection(node->down, pathname, on_or_off);
     1359            depth--;
     1360        }
     1361        if (node->ch == '\0') {
     1362            if (!strncmp(pathname, current_filename, strlen(pathname))) {
     1363                for (j = 0;
     1364                     pathname[j] != '\0'
     1365                     && pathname[j] == current_filename[j]; j++);
     1366                if (current_filename[j] == '/'
     1367                    || current_filename[j] == '\0') {
     1368                    node->selected = on_or_off;
     1369                    sprintf(tmp, "%s is now %s\n", current_filename,
     1370                            (on_or_off ? "ON" : "OFF"));
     1371                }
     1372            }
     1373        }
     1374    }
     1375    if (depth == 0) {
     1376        log_it("Finished toggling selection");
     1377    }
    13891378}
    13901379
     
    13961385 * @bug I don't understand this function. Would someone care to explain it?
    13971386 */
    1398 void
    1399 toggle_node_selection (struct s_node *filelist, bool on_or_off)
    1400 {
    1401     /*@ structure ***************************************************/
    1402   struct s_node *node;
    1403 
    1404     /*@ end vars ****************************************************/
    1405   assert(filelist!=NULL);
    1406   for (node = filelist; node != NULL; node = node->right)
    1407     {
    1408       if (node->ch == '/')
    1409     {
    1410       continue;
    1411     }           /* don't go deep */
    1412       if (node->ch == '\0')
    1413     {
    1414       node->selected = on_or_off;
    1415     }
    1416       if (node->down)
    1417     {
    1418       toggle_node_selection (node->down, on_or_off);
    1419     }
    1420     }
     1387void toggle_node_selection(struct s_node *filelist, bool on_or_off)
     1388{
     1389    /*@ structure ************************************************** */
     1390    struct s_node *node;
     1391
     1392    /*@ end vars *************************************************** */
     1393    assert(filelist != NULL);
     1394    for (node = filelist; node != NULL; node = node->right) {
     1395        if (node->ch == '/') {
     1396            continue;
     1397        }                       /* don't go deep */
     1398        if (node->ch == '\0') {
     1399            node->selected = on_or_off;
     1400        }
     1401        if (node->down) {
     1402            toggle_node_selection(node->down, on_or_off);
     1403        }
     1404    }
    14211405}
    14221406
     
    14301414 * The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().
    14311415 */
    1432 char *g_skeleton_filelist=NULL;
     1416char *g_skeleton_filelist = NULL;
    14331417
    14341418/**
    14351419 * Number of entries in the skeleton filelist.
    14361420 */
    1437 long g_skeleton_entries=0;
     1421long g_skeleton_entries = 0;
    14381422
    14391423/**
     
    14491433 * @see mondo_makefilelist
    14501434 */
    1451 int
    1452 prepare_filelist (struct s_bkpinfo *bkpinfo)
    1453 {
    1454 
    1455     /*@ int *****************************************************/
    1456   int res = 0;
     1435int prepare_filelist(struct s_bkpinfo *bkpinfo)
     1436{
     1437
     1438    /*@ int **************************************************** */
     1439    int res = 0;
    14571440// patch by Herman Kuster
    14581441// end patch
    1459   int *p_res = &res;
    1460 
    1461     /*@ buffers *************************************************/
     1442    int *p_res = &res;
     1443
     1444    /*@ buffers ************************************************ */
    14621445//  char command[MAX_STR_LEN*2];
    14631446
    1464     /*@ i don't have any idea ***********************************/
    1465 
    1466   assert(bkpinfo!=NULL);
    1467   log_it ("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
    1468        bkpinfo->scratchdir);
    1469   if (bkpinfo->make_filelist)
    1470     {
    1471       mvaddstr_and_log_it (g_currentY, 0,
    1472                "Making catalog of files to be backed up");
    1473     }
    1474   else
    1475     {
    1476       mvaddstr_and_log_it (g_currentY, 0,
    1477                "Using supplied catalog of files to be backed up");
    1478     }
    1479 
    1480   if (bkpinfo->make_filelist)
    1481     {
    1482       res = mondo_makefilelist(
    1483        MONDO_LOGFILE, bkpinfo->tmpdir, bkpinfo->scratchdir,
    1484        bkpinfo->include_paths,
    1485        bkpinfo->exclude_paths,
    1486        bkpinfo->differential,
    1487        NULL);
    1488     }
    1489   else
    1490     {
    1491       res = mondo_makefilelist(
    1492        MONDO_LOGFILE, bkpinfo->tmpdir, bkpinfo->scratchdir,
    1493        NULL,
    1494        bkpinfo->exclude_paths,
    1495        bkpinfo->differential,
    1496        bkpinfo->include_paths);
    1497     }
    1498 
    1499   if (res)
    1500     {
    1501       log_OS_error("Call to mondo-makefilelist failed");
    1502       *p_res ++;
    1503       mvaddstr_and_log_it (g_currentY++, 74, "Failed.");
    1504     }
    1505   else
    1506     {
    1507       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1508     }
    1509   return (res);
     1447    /*@ i don't have any idea ********************************** */
     1448
     1449    assert(bkpinfo != NULL);
     1450    log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
     1451           bkpinfo->scratchdir);
     1452    if (bkpinfo->make_filelist) {
     1453        mvaddstr_and_log_it(g_currentY, 0,
     1454                            "Making catalog of files to be backed up");
     1455    } else {
     1456        mvaddstr_and_log_it(g_currentY, 0,
     1457                            "Using supplied catalog of files to be backed up");
     1458    }
     1459
     1460    if (bkpinfo->make_filelist) {
     1461        res =
     1462            mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
     1463                               bkpinfo->scratchdir, bkpinfo->include_paths,
     1464                               bkpinfo->exclude_paths,
     1465                               bkpinfo->differential, NULL);
     1466    } else {
     1467        res =
     1468            mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
     1469                               bkpinfo->scratchdir, NULL,
     1470                               bkpinfo->exclude_paths,
     1471                               bkpinfo->differential,
     1472                               bkpinfo->include_paths);
     1473    }
     1474
     1475    if (res) {
     1476        log_OS_error("Call to mondo-makefilelist failed");
     1477        *p_res++;
     1478        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1479    } else {
     1480        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1481    }
     1482    return (res);
    15101483}
    15111484
     
    15201493 * @bug Return value should be @c void.
    15211494 */
    1522 int open_and_list_dir(char*dir, char*sth, FILE*fout, time_t time_of_last_full_backup)
    1523 {
    1524   DIR             *dip;
    1525   struct dirent   *dit;
    1526   struct stat statbuf;
    1527   char new[MAX_STR_LEN];
    1528   char *tmp;
    1529   char *sth_B;
    1530   static int percentage=0;
    1531   char *ith_B;
    1532   char *skip_these;
    1533   char *new_with_spaces;
    1534   static char *name_of_evalcall_form;
    1535   int i;
    1536   static int depth=0;
    1537   char *p;
    1538   static int counter=0;
    1539   static int uberctr=0;
    1540   static char *find_skeleton_marker;
    1541   static long skeleton_lino=0;
    1542   static time_t last_time=0;
    1543   time_t this_time;
    1544  
    1545   malloc_string(tmp);
    1546   malloc_string(sth_B);
    1547   malloc_string(ith_B);
    1548   malloc_string(new_with_spaces);
    1549   p = strrchr(dir, '/');
    1550   if (p)
    1551     {
    1552       if (!strcmp(p, "/.") || !strcmp(p, "/.."))
    1553         {
    1554           return(0);
    1555         }
    1556     }
    1557 
    1558   if (!depth)
    1559     {
    1560       malloc_string(name_of_evalcall_form);
    1561       malloc_string(find_skeleton_marker);
     1495int open_and_list_dir(char *dir, char *sth, FILE * fout,
     1496                      time_t time_of_last_full_backup)
     1497{
     1498    DIR *dip;
     1499    struct dirent *dit;
     1500    struct stat statbuf;
     1501    char new[MAX_STR_LEN];
     1502    char *tmp;
     1503    char *sth_B;
     1504    static int percentage = 0;
     1505    char *ith_B;
     1506    char *skip_these;
     1507    char *new_with_spaces;
     1508    static char *name_of_evalcall_form;
     1509    int i;
     1510    static int depth = 0;
     1511    char *p;
     1512    static int counter = 0;
     1513    static int uberctr = 0;
     1514    static char *find_skeleton_marker;
     1515    static long skeleton_lino = 0;
     1516    static time_t last_time = 0;
     1517    time_t this_time;
     1518
     1519    malloc_string(tmp);
     1520    malloc_string(sth_B);
     1521    malloc_string(ith_B);
     1522    malloc_string(new_with_spaces);
     1523    p = strrchr(dir, '/');
     1524    if (p) {
     1525        if (!strcmp(p, "/.") || !strcmp(p, "/..")) {
     1526            return (0);
     1527        }
     1528    }
     1529
     1530    if (!depth) {
     1531        malloc_string(name_of_evalcall_form);
     1532        malloc_string(find_skeleton_marker);
    15621533#if linux
    1563       // 2.6 has /sys as a proc-type thing -- must be excluded
    1564       sprintf(tmp, "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
     1534        // 2.6 has /sys as a proc-type thing -- must be excluded
     1535        sprintf(tmp,
     1536                "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null",
     1537                dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
    15651538#else
    1566       // On BSD, for example, /sys is the kernel sources -- don't exclude
    1567       sprintf(tmp, "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
     1539        // On BSD, for example, /sys is the kernel sources -- don't exclude
     1540        sprintf(tmp,
     1541                "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null",
     1542                dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
    15681543#endif
    1569       system(tmp);
    1570       sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    1571       g_skeleton_entries = 1 + atol(call_program_and_get_last_line_of_output(tmp));
    1572       sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
    1573       open_evalcall_form (name_of_evalcall_form);
    1574       find_skeleton_marker[0] = '\0';
    1575       skeleton_lino=1;
    1576       log_msg(5, "entries = %ld", g_skeleton_entries);
    1577       percentage=0;
    1578     }
    1579   else if (depth<=MAX_SKEL_DEPTH) // update evalcall form if appropriate
    1580         {
    1581       sprintf(find_skeleton_marker, "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist);
    1582 //    log_msg(0, "fsm = %s", find_skeleton_marker);
    1583       if (!system(find_skeleton_marker))
    1584         {
    1585           percentage = (int)(skeleton_lino*100/g_skeleton_entries);
    1586           skeleton_lino++;
    1587 //        log_msg(5, "Found %s", dir);
    1588 //        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
    1589           sprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist);
    1590 //        log_msg(6, "fsm = %s", find_skeleton_marker);
    1591           run_program_and_log_output(find_skeleton_marker, 8);
    1592           time(&this_time);
    1593           if (this_time != last_time)
    1594             {
    1595             last_time = this_time;
     1544        system(tmp);
     1545        sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
     1546        g_skeleton_entries =
     1547            1 + atol(call_program_and_get_last_line_of_output(tmp));
     1548        sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
     1549        open_evalcall_form(name_of_evalcall_form);
     1550        find_skeleton_marker[0] = '\0';
     1551        skeleton_lino = 1;
     1552        log_msg(5, "entries = %ld", g_skeleton_entries);
     1553        percentage = 0;
     1554    } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate
     1555    {
     1556        sprintf(find_skeleton_marker,
     1557                "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir,
     1558                g_skeleton_filelist, g_skeleton_filelist);
     1559//    log_msg(0, "fsm = %s", find_skeleton_marker);
     1560        if (!system(find_skeleton_marker)) {
     1561            percentage = (int) (skeleton_lino * 100 / g_skeleton_entries);
     1562            skeleton_lino++;
     1563//        log_msg(5, "Found %s", dir);
     1564//        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
     1565            sprintf(find_skeleton_marker, "mv -f %s.new %s",
     1566                    g_skeleton_filelist, g_skeleton_filelist);
     1567//        log_msg(6, "fsm = %s", find_skeleton_marker);
     1568            run_program_and_log_output(find_skeleton_marker, 8);
     1569            time(&this_time);
     1570            if (this_time != last_time) {
     1571                last_time = this_time;
    15961572#ifndef _XWIN
    1597                   if (!g_text_mode)
    1598                 {
    1599               sprintf(tmp, "Reading %-68s", dir);
    1600                   newtDrawRootText (0, g_noof_rows - 3, tmp);
    1601             }
     1573                if (!g_text_mode) {
     1574                    sprintf(tmp, "Reading %-68s", dir);
     1575                    newtDrawRootText(0, g_noof_rows - 3, tmp);
     1576                }
    16021577#endif
    1603           update_evalcall_form(percentage);
    1604         }
    1605         }
    1606         }
    1607 
    1608   depth++;
     1578                update_evalcall_form(percentage);
     1579            }
     1580        }
     1581    }
     1582
     1583    depth++;
    16091584
    16101585//  log_msg(0, "Cataloguing %s", dir);
    1611   if (sth[0]==' ') { skip_these = sth; }
    1612   else
    1613     {
    1614       skip_these = sth_B;
    1615       sprintf(skip_these, " %s ", sth);
    1616     }
    1617   sprintf(new_with_spaces, " %s ", dir);
    1618   if ((dip = opendir(dir)) == NULL)
    1619     {
    1620       log_OS_error("opendir");
    1621     }
    1622   else if (strstr(skip_these, new_with_spaces))
    1623     {
    1624       fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
    1625     }
    1626   else
    1627     {
    1628       fprintf(fout, "%s\n", dir);
    1629       while ((dit = readdir(dip)) != NULL)
    1630        {
    1631     i++;
    1632         strcpy(new, dir);
    1633         if (strcmp(dir, "/")) { strcat(new, "/"); }
    1634         strcat(new, dit->d_name);
    1635     new_with_spaces[0] = ' ';
    1636           strcpy(new_with_spaces+1, new);
    1637           strcat(new_with_spaces, " ");
    1638     if (strstr(skip_these, new_with_spaces))
    1639       {
    1640         fprintf(fout, "%s\n", new);
    1641       }
    1642     else
    1643       {
    1644         if (!lstat(new, &statbuf))
    1645           {
    1646         if (!S_ISLNK(statbuf.st_mode) && S_ISDIR(statbuf.st_mode)) {
    1647           open_and_list_dir(new, skip_these, fout, time_of_last_full_backup);
    1648         }
    1649         else {
    1650           if (time_of_last_full_backup==0 || time_of_last_full_backup<statbuf.st_ctime)
    1651             {
    1652               fprintf(fout, "%s\n", new);
    1653               if ((counter++)>128)
    1654                 {
    1655                   counter=0;
    1656               uberctr++;
    1657                   sprintf(tmp, " %c ", special_dot_char(uberctr));
     1586    if (sth[0] == ' ') {
     1587        skip_these = sth;
     1588    } else {
     1589        skip_these = sth_B;
     1590        sprintf(skip_these, " %s ", sth);
     1591    }
     1592    sprintf(new_with_spaces, " %s ", dir);
     1593    if ((dip = opendir(dir)) == NULL) {
     1594        log_OS_error("opendir");
     1595    } else if (strstr(skip_these, new_with_spaces)) {
     1596        fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
     1597    } else {
     1598        fprintf(fout, "%s\n", dir);
     1599        while ((dit = readdir(dip)) != NULL) {
     1600            i++;
     1601            strcpy(new, dir);
     1602            if (strcmp(dir, "/")) {
     1603                strcat(new, "/");
     1604            }
     1605            strcat(new, dit->d_name);
     1606            new_with_spaces[0] = ' ';
     1607            strcpy(new_with_spaces + 1, new);
     1608            strcat(new_with_spaces, " ");
     1609            if (strstr(skip_these, new_with_spaces)) {
     1610                fprintf(fout, "%s\n", new);
     1611            } else {
     1612                if (!lstat(new, &statbuf)) {
     1613                    if (!S_ISLNK(statbuf.st_mode)
     1614                        && S_ISDIR(statbuf.st_mode)) {
     1615                        open_and_list_dir(new, skip_these, fout,
     1616                                          time_of_last_full_backup);
     1617                    } else {
     1618                        if (time_of_last_full_backup == 0
     1619                            || time_of_last_full_backup <
     1620                            statbuf.st_ctime) {
     1621                            fprintf(fout, "%s\n", new);
     1622                            if ((counter++) > 128) {
     1623                                counter = 0;
     1624                                uberctr++;
     1625                                sprintf(tmp, " %c ",
     1626                                        special_dot_char(uberctr));
    16581627#ifndef _XWIN
    1659               if (!g_text_mode) {
    1660                   newtDrawRootText (77, g_noof_rows - 3, tmp);
    1661                   newtRefresh();
    1662               }
     1628                                if (!g_text_mode) {
     1629                                    newtDrawRootText(77, g_noof_rows - 3,
     1630                                                     tmp);
     1631                                    newtRefresh();
     1632                                }
    16631633#endif
    1664                         }
    1665             }
    1666         }
    1667           }
    1668       }
    1669        }
    1670     }
    1671   if (dip)
    1672     {
    1673       if (closedir(dip) == -1)
    1674         {
    1675       log_OS_error("closedir");
    1676         }
    1677     }
    1678   depth--;
    1679   if (!depth)
    1680     {
    1681       close_evalcall_form ();
    1682       paranoid_free (name_of_evalcall_form);
    1683       paranoid_free(find_skeleton_marker);
    1684       unlink(g_skeleton_filelist);
    1685       log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
    1686     }
    1687   paranoid_free(tmp);
    1688   paranoid_free(sth_B);
    1689   paranoid_free(ith_B);
    1690   paranoid_free(new_with_spaces);
    1691   return(0);
     1634                            }
     1635                        }
     1636                    }
     1637                }
     1638            }
     1639        }
     1640    }
     1641    if (dip) {
     1642        if (closedir(dip) == -1) {
     1643            log_OS_error("closedir");
     1644        }
     1645    }
     1646    depth--;
     1647    if (!depth) {
     1648        close_evalcall_form();
     1649        paranoid_free(name_of_evalcall_form);
     1650        paranoid_free(find_skeleton_marker);
     1651        unlink(g_skeleton_filelist);
     1652        log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
     1653    }
     1654    paranoid_free(tmp);
     1655    paranoid_free(sth_B);
     1656    paranoid_free(ith_B);
     1657    paranoid_free(new_with_spaces);
     1658    return (0);
    16921659}
    16931660
     
    17021669 * @note The returned string points to static data that will be overwritten with each call.
    17031670 */
    1704 char *next_entry(char*incoming)
    1705 {
    1706   static char sz_res[MAX_STR_LEN];
    1707   char *p;
    1708   bool in_quotes=FALSE;
    1709 
    1710   strcpy(sz_res, incoming);
    1711   p = sz_res;
    1712   while((*p!=' ' || in_quotes) && *p!='\0')
    1713     {
    1714       if (*p=='\"') { in_quotes = !in_quotes; }
    1715       p++;
    1716     }
    1717   *p = '\0';
    1718   return(sz_res);
     1671char *next_entry(char *incoming)
     1672{
     1673    static char sz_res[MAX_STR_LEN];
     1674    char *p;
     1675    bool in_quotes = FALSE;
     1676
     1677    strcpy(sz_res, incoming);
     1678    p = sz_res;
     1679    while ((*p != ' ' || in_quotes) && *p != '\0') {
     1680        if (*p == '\"') {
     1681            in_quotes = !in_quotes;
     1682        }
     1683        p++;
     1684    }
     1685    *p = '\0';
     1686    return (sz_res);
    17191687}
    17201688
     
    17341702 * @bug Return value is meaningless.
    17351703 */
    1736 int mondo_makefilelist(char*logfile, char*tmpdir, char*scratchdir,
    1737     char*include_paths, char*excp, int differential, char *userdef_filelist)
     1704int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
     1705                       char *include_paths, char *excp, int differential,
     1706                       char *userdef_filelist)
    17381707{
    17391708    char sz_datefile_wildcard[] = "/var/cache/mondo-archive/difflevel.%d";
     
    17421711    char *sz_filelist, *exclude_paths, *tmp;
    17431712    int i;
    1744     FILE*fout;
     1713    FILE *fout;
    17451714    char *command;
    1746         time_t time_of_last_full_backup=0;
     1715    time_t time_of_last_full_backup = 0;
    17471716    struct stat statbuf;
    17481717
    1749   malloc_string(command);
    1750   malloc_string(tmp);
    1751   malloc_string(sz_filelist);
    1752   malloc_string(g_skeleton_filelist);
    1753   if (!(exclude_paths = malloc(1000))) { fatal_error("Cannot malloc exclude_paths"); }
    1754   log_msg(3, "Trying to write test string to exclude_paths");
    1755   strcpy(exclude_paths, "/blah /froo");
    1756   log_msg(3, "...Success!");
    1757   sprintf(sz_datefile, sz_datefile_wildcard, 0);
    1758   if (!include_paths && !userdef_filelist)
    1759     { fatal_error("Please supply either include_paths or userdef_filelist"); }
    1760 
     1718    malloc_string(command);
     1719    malloc_string(tmp);
     1720    malloc_string(sz_filelist);
     1721    malloc_string(g_skeleton_filelist);
     1722    if (!(exclude_paths = malloc(1000))) {
     1723        fatal_error("Cannot malloc exclude_paths");
     1724    }
     1725    log_msg(3, "Trying to write test string to exclude_paths");
     1726    strcpy(exclude_paths, "/blah /froo");
     1727    log_msg(3, "...Success!");
     1728    sprintf(sz_datefile, sz_datefile_wildcard, 0);
     1729    if (!include_paths && !userdef_filelist) {
     1730        fatal_error
     1731            ("Please supply either include_paths or userdef_filelist");
     1732    }
    17611733// make hole for filelist
    1762   sprintf(command, "mkdir -p %s/archives", scratchdir);
    1763   paranoid_system(command);
    1764   sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    1765   make_hole_for_file(sz_filelist);
    1766 
    1767   if (differential==0)
    1768     {
    1769   // restore last good datefile if it exists
    1770       sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
    1771       run_program_and_log_output(command, 3);
    1772   // backup last known good datefile just in case :)
    1773       if (does_file_exist(sz_datefile))
    1774         {
    1775           sprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
    1776           paranoid_system(command);
    1777         }
    1778       make_hole_for_file(sz_datefile);
    1779       write_one_liner_data_file(sz_datefile, call_program_and_get_last_line_of_output("date +%s"));
    1780     }
    1781   else if (lstat(sz_datefile, &statbuf))
    1782     {
    1783       log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
    1784       differential = 0;
    1785       time_of_last_full_backup = 0;
    1786     }
    1787   else
    1788     {
    1789       time_of_last_full_backup = statbuf.st_mtime;
    1790       log_msg(2, "Differential backup. Yay.");
    1791     }
     1734    sprintf(command, "mkdir -p %s/archives", scratchdir);
     1735    paranoid_system(command);
     1736    sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1737    make_hole_for_file(sz_filelist);
     1738
     1739    if (differential == 0) {
     1740        // restore last good datefile if it exists
     1741        sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
     1742        run_program_and_log_output(command, 3);
     1743        // backup last known good datefile just in case :)
     1744        if (does_file_exist(sz_datefile)) {
     1745            sprintf(command, "mv -f %s %s.aborted", sz_datefile,
     1746                    sz_datefile);
     1747            paranoid_system(command);
     1748        }
     1749        make_hole_for_file(sz_datefile);
     1750        write_one_liner_data_file(sz_datefile,
     1751                                  call_program_and_get_last_line_of_output
     1752                                  ("date +%s"));
     1753    } else if (lstat(sz_datefile, &statbuf)) {
     1754        log_msg(2,
     1755                "Warning - unable to find date of previous backup. Full backup instead.");
     1756        differential = 0;
     1757        time_of_last_full_backup = 0;
     1758    } else {
     1759        time_of_last_full_backup = statbuf.st_mtime;
     1760        log_msg(2, "Differential backup. Yay.");
     1761    }
    17921762
    17931763// use user-specified filelist (if specified)
    1794   if (userdef_filelist)
    1795     {
    1796       log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
    1797       sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    1798       if (run_program_and_log_output(command, 3))
    1799         { fatal_error("Failed to copy user-specified filelist"); }
    1800     }
    1801   else
    1802     {
    1803       log_msg(2, "include_paths = '%s'", include_paths);
    1804       log_msg(1, "Calculating filelist");
    1805       sprintf(exclude_paths, " %s %s %s %s %s %s . .. \
    1806 "MNT_CDROM" "MNT_FLOPPY" /media/cdrom /media/cdrecorder \
    1807 /proc /sys /tmp /root/images/mondo /root/images/mindi ",
    1808         excp,
    1809         call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"),
    1810         call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"),
    1811         call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"),
    1812         (tmpdir[0]=='/' && tmpdir[1]=='/')?(tmpdir+1):tmpdir,
    1813         (scratchdir[0]=='/' && scratchdir[1]=='/')?(scratchdir+1):scratchdir
    1814                         );
    1815 
    1816     log_msg(2, "Excluding paths = '%s'", exclude_paths);
    1817     log_msg(2, "Generating skeleton filelist so that we can track our progress");
    1818     sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
    1819     make_hole_for_file(g_skeleton_filelist);
    1820     log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
    1821     log_msg(2, "Opening out filelist to %s", sz_filelist);
    1822     if (!(fout = fopen(sz_filelist, "w"))) { fatal_error("Cannot openout to sz_filelist"); }
    1823     i = 0;
    1824     if (strlen(include_paths)==0)
    1825         {
    1826           log_msg(1, "Including only '/' in %s", sz_filelist);
    1827         open_and_list_dir("/", exclude_paths, fout, time_of_last_full_backup);
    1828         }
    1829     else
    1830         {
    1831         p = include_paths;
    1832         while(*p)
    1833             {
    1834             q = next_entry(p);
    1835             log_msg(1, "Including %s in filelist %s", q, sz_filelist);
    1836             open_and_list_dir(q, exclude_paths, fout, time_of_last_full_backup);
    1837             p += strlen(q);
    1838             while(*p==' ') { p++; }
     1764    if (userdef_filelist) {
     1765        log_msg(1,
     1766                "Using the user-specified filelist - %s - instead of calculating one",
     1767                userdef_filelist);
     1768        sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
     1769        if (run_program_and_log_output(command, 3)) {
     1770            fatal_error("Failed to copy user-specified filelist");
     1771        }
     1772    } else {
     1773        log_msg(2, "include_paths = '%s'", include_paths);
     1774        log_msg(1, "Calculating filelist");
     1775        sprintf(exclude_paths, " %s %s %s %s %s %s . .. \
     1776" MNT_CDROM " " MNT_FLOPPY " /media/cdrom /media/cdrecorder \
     1777/proc /sys /tmp /root/images/mondo /root/images/mindi ", excp, call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"), call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"), call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"), (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1778
     1779        log_msg(2, "Excluding paths = '%s'", exclude_paths);
     1780        log_msg(2,
     1781                "Generating skeleton filelist so that we can track our progress");
     1782        sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
     1783        make_hole_for_file(g_skeleton_filelist);
     1784        log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
     1785        log_msg(2, "Opening out filelist to %s", sz_filelist);
     1786        if (!(fout = fopen(sz_filelist, "w"))) {
     1787            fatal_error("Cannot openout to sz_filelist");
     1788        }
     1789        i = 0;
     1790        if (strlen(include_paths) == 0) {
     1791            log_msg(1, "Including only '/' in %s", sz_filelist);
     1792            open_and_list_dir("/", exclude_paths, fout,
     1793                              time_of_last_full_backup);
     1794        } else {
     1795            p = include_paths;
     1796            while (*p) {
     1797                q = next_entry(p);
     1798                log_msg(1, "Including %s in filelist %s", q, sz_filelist);
     1799                open_and_list_dir(q, exclude_paths, fout,
     1800                                  time_of_last_full_backup);
     1801                p += strlen(q);
     1802                while (*p == ' ') {
     1803                    p++;
     1804                }
    18391805            }
    18401806        }
    1841     paranoid_fclose(fout);
    1842     }
    1843   log_msg(2, "Copying new filelist to scratchdir");
    1844   sprintf(command, "mkdir -p %s/archives", scratchdir);
    1845   paranoid_system(command);
    1846   sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
    1847   paranoid_system(command);
    1848   sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
    1849   paranoid_system(command);
    1850   log_msg(2, "Freeing variables");
    1851   paranoid_free(sz_filelist);
    1852   paranoid_free(command);
    1853   paranoid_free(exclude_paths);
    1854   paranoid_free(tmp);
    1855   paranoid_free(g_skeleton_filelist);
    1856   log_msg(2, "Exiting");
    1857   return(0);
     1807        paranoid_fclose(fout);
     1808    }
     1809    log_msg(2, "Copying new filelist to scratchdir");
     1810    sprintf(command, "mkdir -p %s/archives", scratchdir);
     1811    paranoid_system(command);
     1812    sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
     1813    paranoid_system(command);
     1814    sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
     1815    paranoid_system(command);
     1816    log_msg(2, "Freeing variables");
     1817    paranoid_free(sz_filelist);
     1818    paranoid_free(command);
     1819    paranoid_free(exclude_paths);
     1820    paranoid_free(tmp);
     1821    paranoid_free(g_skeleton_filelist);
     1822    log_msg(2, "Exiting");
     1823    return (0);
    18581824}
    18591825
     
    18681834 * it was not found.
    18691835 */
    1870 struct s_node *find_string_at_node (struct s_node *startnode, char *string_to_find)
    1871 {
    1872     /*@ int *********************************************************/
    1873   int noof_chars;
    1874   static int depth=0;
    1875   static char original_string[MAX_STR_LEN];
    1876 
    1877     /*@ sturctures **************************************************/
    1878   struct s_node *node;
    1879 
    1880     /*@ char  *******************************************************/
    1881   char char_to_find;
    1882 
    1883     /*@ bools *******************************************************/
    1884 
    1885   if (!depth) { strcpy(original_string, string_to_find); }
    1886 
    1887   assert(startnode!=NULL);
    1888   assert(string_to_find!=NULL);
    1889 
    1890   noof_chars = strlen (string_to_find) + 1; /* we include the '\0' */
    1891 
    1892   log_msg(7, "starting --- str=%s", string_to_find);
     1836struct s_node *find_string_at_node(struct s_node *startnode,
     1837                                   char *string_to_find)
     1838{
     1839    /*@ int ******************************************************** */
     1840    int noof_chars;
     1841    static int depth = 0;
     1842    static char original_string[MAX_STR_LEN];
     1843
     1844    /*@ sturctures ************************************************* */
     1845    struct s_node *node;
     1846
     1847    /*@ char  ****************************************************** */
     1848    char char_to_find;
     1849
     1850    /*@ bools ****************************************************** */
     1851
     1852    if (!depth) {
     1853        strcpy(original_string, string_to_find);
     1854    }
     1855
     1856    assert(startnode != NULL);
     1857    assert(string_to_find != NULL);
     1858
     1859    noof_chars = strlen(string_to_find) + 1;    /* we include the '\0' */
     1860
     1861    log_msg(7, "starting --- str=%s", string_to_find);
    18931862
    18941863/* walk across tree if necessary */
    1895   node = startnode;
    1896   char_to_find = string_to_find[0];
    1897   if (node->right != NULL && node->ch < char_to_find)
    1898     {
    1899       log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth, char_to_find, node->ch, (node->right)->ch);
    1900       return (find_string_at_node (node->right, string_to_find));
    1901     }
     1864    node = startnode;
     1865    char_to_find = string_to_find[0];
     1866    if (node->right != NULL && node->ch < char_to_find) {
     1867        log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
     1868                char_to_find, node->ch, (node->right)->ch);
     1869        return (find_string_at_node(node->right, string_to_find));
     1870    }
    19021871
    19031872/* walk down tree if appropriate */
    1904   if (node->down != NULL && node->ch == char_to_find)
    1905     {
    1906       log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
    1907       depth++;
    1908       node = find_string_at_node (node->down, string_to_find + 1);
    1909       depth--;
    1910       return (node);
    1911     }
    1912 
    1913   if (char_to_find == '\0' && node->ch =='\0')
    1914     {
    1915       log_msg(7, "%s is in tree", original_string);
    1916       return(node);
    1917     }
    1918   else
    1919     {
    1920       log_msg(7, "%s is NOT in tree", original_string);
    1921       return(NULL);
    1922     }
     1873    if (node->down != NULL && node->ch == char_to_find) {
     1874        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
     1875        depth++;
     1876        node = find_string_at_node(node->down, string_to_find + 1);
     1877        depth--;
     1878        return (node);
     1879    }
     1880
     1881    if (char_to_find == '\0' && node->ch == '\0') {
     1882        log_msg(7, "%s is in tree", original_string);
     1883        return (node);
     1884    } else {
     1885        log_msg(7, "%s is NOT in tree", original_string);
     1886        return (NULL);
     1887    }
    19231888}
    19241889
     
    19331898 * @return The number of matches found.
    19341899 */
    1935 long save_filelist_entries_in_common(
    1936             char*needles_list_fname,
    1937             struct s_node *filelist,
    1938             char*matches_list_fname, bool use_star)
    1939 {
    1940   int retval=0;
    1941   struct s_node *found_node;
    1942   FILE*fin;
    1943   FILE*fout;
    1944   char *fname;
    1945   char *tmp;
    1946   size_t len = 0; // Scrub's patch doesn't work without that
     1900long save_filelist_entries_in_common(char *needles_list_fname,
     1901                                     struct s_node *filelist,
     1902                                     char *matches_list_fname,
     1903                                    bool use_star)
     1904{
     1905    int retval = 0;
     1906    struct s_node *found_node;
     1907    FILE *fin;
     1908    FILE *fout;
     1909    char *fname;
     1910    char *tmp;
     1911    size_t len = 0;             // Scrub's patch doesn't work without that
    19471912
    19481913//  log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
    1949   malloc_string(fname);
    1950   malloc_string(tmp);
    1951   log_msg(5, "starting");
    1952   log_msg(5, "needles_list_fname = %s", needles_list_fname);
    1953   log_msg(5, "matches_list_fname = %s", matches_list_fname);
    1954   if (!(fin = fopen(needles_list_fname, "r"))) { fatal_error("Cannot openin needles_list_fname"); }
    1955   if (!(fout= fopen(matches_list_fname, "w"))) { fatal_error("Cannot openout matches_list_fname"); }
    1956   while(!feof(fin))
    1957     {
     1914    malloc_string(fname);
     1915    malloc_string(tmp);
     1916    log_msg(5, "starting");
     1917    log_msg(5, "needles_list_fname = %s", needles_list_fname);
     1918    log_msg(5, "matches_list_fname = %s", matches_list_fname);
     1919    if (!(fin = fopen(needles_list_fname, "r"))) {
     1920        fatal_error("Cannot openin needles_list_fname");
     1921    }
     1922    if (!(fout = fopen(matches_list_fname, "w"))) {
     1923        fatal_error("Cannot openout matches_list_fname");
     1924    }
     1925    while (!feof(fin)) {
    19581926//      fscanf(fin, "%s\n", fname);
    1959       len = MAX_STR_LEN-1;
    1960       getline(& fname, & len, fin); // patch by Scrub
    1961       if (!use_star)
    1962         {
    1963       if (fname[0]=='/')
    1964         { strcpy(tmp, fname); }
    1965       else
    1966         {
    1967           tmp[0]='/';
    1968           strcpy(tmp+1, fname);
    1969         }
    1970       strcpy(fname, tmp);
    1971         }
    1972       while (strlen(fname)>0 && fname[strlen(fname)-1]<32) { fname[strlen(fname)-1] = '\0'; }
     1927        len = MAX_STR_LEN - 1;
     1928        getline(&fname, &len, fin); // patch by Scrub
     1929        if (!use_star) {
     1930            if (fname[0] == '/') {
     1931                strcpy(tmp, fname);
     1932            } else {
     1933                tmp[0] = '/';
     1934                strcpy(tmp + 1, fname);
     1935            }
     1936            strcpy(fname, tmp);
     1937        }
     1938        while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
     1939            fname[strlen(fname) - 1] = '\0';
     1940        }
    19731941
    19741942/*
     
    19771945      sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);
    19781946      system(temporary_string);
    1979 */     
    1980      
    1981       log_msg(5, "Looking for '%s'", fname);
    1982       found_node = find_string_at_node(filelist, fname);
    1983       if (found_node)
    1984         {
    1985       if (found_node->selected)
    1986         {
     1947*/
     1948
     1949        log_msg(5, "Looking for '%s'", fname);
     1950        found_node = find_string_at_node(filelist, fname);
     1951        if (found_node) {
     1952            if (found_node->selected) {
    19871953//              if (use_star)
    1988               if (fname[0]=='/')
    1989             {
    1990           strcpy(tmp, fname+1);
    1991           strcpy(fname, tmp);
    1992         }
    1993           log_msg(5, "Found '%s'", fname);
    1994           turn_wildcard_chars_into_literal_chars(tmp, fname);
    1995           fprintf(fout, "%s\n", tmp);
    1996           retval++;
    1997         }
    1998     }
    1999     }
    2000   paranoid_fclose(fout);
    2001   paranoid_fclose(fin);
    2002   paranoid_free(fname);
    2003   paranoid_free(tmp);
    2004   return(retval);
     1954                if (fname[0] == '/') {
     1955                    strcpy(tmp, fname + 1);
     1956                    strcpy(fname, tmp);
     1957                }
     1958                log_msg(5, "Found '%s'", fname);
     1959                turn_wildcard_chars_into_literal_chars(tmp, fname);
     1960                fprintf(fout, "%s\n", tmp);
     1961                retval++;
     1962            }
     1963        }
     1964    }
     1965    paranoid_fclose(fout);
     1966    paranoid_fclose(fin);
     1967    paranoid_free(fname);
     1968    paranoid_free(tmp);
     1969    return (retval);
    20051970}
    20061971
     
    20181983 * @return 0 for success, nonzero for failure.
    20191984 */
    2020 int add_list_of_files_to_filelist(struct s_node *filelist, char*list_of_files_fname, bool flag_em)
    2021 {
    2022   FILE*fin;
    2023   char*tmp;
    2024   struct s_node *nod;
    2025 
    2026   malloc_string(tmp);
    2027   log_msg(3, "Adding %s to filelist", list_of_files_fname);
    2028   if (!(fin=fopen(list_of_files_fname,"r"))) { iamhere(list_of_files_fname); return(1); }
    2029   for (fgets (tmp, MAX_STR_LEN, fin); !feof(fin);
    2030        fgets (tmp, MAX_STR_LEN, fin))
    2031     {
    2032       if (!tmp[0]) { continue; }
    2033       if ((tmp[strlen(tmp)-1]==13 || tmp[strlen(tmp)-1]==10) && strlen(tmp)>0)
    2034         { tmp[strlen(tmp)-1] = '\0'; }
    2035       log_msg(2, "tmp = '%s'", tmp);
    2036       if (!tmp[0]) { continue; }
    2037       if ((nod = find_string_at_node (filelist, tmp)))
    2038         {
    2039       log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
    2040         }
    2041       else
    2042         {
    2043       add_string_at_node (filelist, tmp);
    2044           nod = find_string_at_node (filelist, tmp);
    2045         }
    2046 
    2047       if (nod && flag_em)
    2048         {
    2049       toggle_path_selection(filelist, tmp, TRUE);
    2050       log_msg (5, "Flagged '%s'", tmp);
    2051     }
    2052     }
    2053   paranoid_fclose(fin);
    2054   paranoid_free(tmp);
    2055   return(0);
     1985int add_list_of_files_to_filelist(struct s_node *filelist,
     1986                                  char *list_of_files_fname, bool flag_em)
     1987{
     1988    FILE *fin;
     1989    char *tmp;
     1990    struct s_node *nod;
     1991
     1992    malloc_string(tmp);
     1993    log_msg(3, "Adding %s to filelist", list_of_files_fname);
     1994    if (!(fin = fopen(list_of_files_fname, "r"))) {
     1995        iamhere(list_of_files_fname);
     1996        return (1);
     1997    }
     1998    for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     1999         fgets(tmp, MAX_STR_LEN, fin)) {
     2000        if (!tmp[0]) {
     2001            continue;
     2002        }
     2003        if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
     2004            && strlen(tmp) > 0) {
     2005            tmp[strlen(tmp) - 1] = '\0';
     2006        }
     2007        log_msg(2, "tmp = '%s'", tmp);
     2008        if (!tmp[0]) {
     2009            continue;
     2010        }
     2011        if ((nod = find_string_at_node(filelist, tmp))) {
     2012            log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
     2013        } else {
     2014            add_string_at_node(filelist, tmp);
     2015            nod = find_string_at_node(filelist, tmp);
     2016        }
     2017
     2018        if (nod && flag_em) {
     2019            toggle_path_selection(filelist, tmp, TRUE);
     2020            log_msg(5, "Flagged '%s'", tmp);
     2021        }
     2022    }
     2023    paranoid_fclose(fin);
     2024    paranoid_free(tmp);
     2025    return (0);
    20562026}
    20572027
  • branches/2.05/mondo/mondo/common/libmondo-filelist.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-files-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-files.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-fork-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-fork.c

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-fork.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-gui-EXT.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-gui.c

    r30 r128  
    11/* libmondo-gui.c
    2  * $Id: libmondo-gui.c,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    1010
    1111#ifdef _XWIN
    12     #include "X-specific.c"
     12#include "X-specific.c"
    1313#else
    14     #include "newt-specific.c"
     14#include "newt-specific.c"
    1515#endif
    16 
    17 
    18 
    19 
    20 
    21 
  • branches/2.05/mondo/mondo/common/libmondo-gui.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-mountlist-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-mountlist.c

    r30 r128  
    11/* libmondo-mountlist.c                            subroutines for handling mountlist
    2    $Id: libmondo-mountlist.c,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33
    44
     
    6161
    6262/*@unused@*/
    63 //static char cvsid[] = "$Id: libmondo-mountlist.c,v 1.2 2004/06/10 15:29:12 hugo Exp $";
     63//static char cvsid[] = "$Id$";
    6464
    6565/**
     
    8585 * @see evaluate_mountlist
    8686 */
    87 int evaluate_drive_within_mountlist (struct mountlist_itself *mountlist,
    88                  char *drive, char *flaws_str)
     87int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist,
     88                                    char *drive, char *flaws_str)
    8989#ifdef __FreeBSD__
    9090{
    9191// FreeBSD-specific version of evaluate_drive_within_mountlist()
    92     /*@ int **************************************************************/
    93   int prev_part_no = 0;
     92    /*@ int ************************************************************* */
     93    int prev_part_no = 0;
    9494    int curr_part_no = 0;
    9595    int pos = 0, npos = 0;
     
    102102    int foundsome = FALSE;
    103103
    104     /*@ buffers *********************************************************/
    105   char tmp[MAX_STR_LEN];
     104    /*@ buffers ******************************************************** */
     105    char tmp[MAX_STR_LEN];
    106106    char device[MAX_STR_LEN];
    107107    char mountpoint[MAX_STR_LEN];
    108108
    109     /*@ long ************************************************************/
    110   long physical_drive_size = 0;
     109    /*@ long *********************************************************** */
     110    long physical_drive_size = 0;
    111111    long amount_allocated = 0;
    112112
    113     /*@ pointers ********************************************************/
     113    /*@ pointers ******************************************************* */
    114114    char *part_table_fmt;
    115115
    116     /*@ initialize ******************************************************/
    117   flaws_str[0] = '\0';
    118   prev_part_no = 0;
    119   tmp[0] = '\0';
    120 
    121 
    122   physical_drive_size = get_phys_size_of_drive (drive);
    123 
    124   if (physical_drive_size < 0)
    125     {
    126       sprintf (tmp, " %s does not exist.", drive);
    127       strcat (flaws_str, tmp);
    128     }
    129   else
    130     {
    131       sprintf (tmp, "%s is %ld MB", drive, physical_drive_size);
    132     }
    133   log_it (tmp);
    134  
    135 
    136   /* check DD */
    137   for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    138       sprintf (device, "%s%c", drive, cur_sp_no);
    139       if (find_device_in_mountlist (mountlist, device) >= 0)
    140       foundsome = TRUE;
    141   }
    142   if (foundsome) {
    143       for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {   
    144       sprintf (device, "%s%c", drive, cur_sp_no);
    145       pos = find_device_in_mountlist (mountlist, device);
    146       if (pos < 0)
    147           {
    148           continue;
    149           }
    150       strcpy (mountpoint, mountlist->el[pos].mountpoint);
    151       /* is it too big? */
    152       if (curr_part_no > 'h')
    153           {
    154           sprintf (tmp, " Can only have up to 'h' in disklabel.");
    155           log_it (tmp);
    156           strcat (flaws_str, tmp);
    157           res++;
    158           }
    159       /* does partition /dev/adXsYZ exist more than once in the mountlist? */
    160       for (i = 0, mountpoint_copies = 0, device_copies = 0;
    161            i < mountlist->entries; i++)
    162           {
    163           if (!strcmp (device, mountlist->el[i].device))
    164               {
    165               device_copies++;
    166               }
    167           }
    168       if (device_copies > 1)
    169           {
    170           sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    171           if (!strstr (flaws_str, tmp))
    172               {
    173               log_it (tmp);
    174               strcat (flaws_str, tmp);
    175               res++;
    176               }
    177           }
    178       /* silly partition size? */
    179       if (mountlist->el[pos].size < 8192
    180           && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    181           {
    182           sprintf (tmp, " %s is tiny!", device);
    183           log_it (tmp);
    184           strcat (flaws_str, tmp);
    185           res++;
    186           }
    187       /* mountpoint should begin with / unless it is swap, lvm or raid */
    188       if (strcmp (mountlist->el[pos].mountpoint, "swap")
    189           && strcmp (mountlist->el[pos].mountpoint, "lvm")
    190           && strcmp (mountlist->el[pos].mountpoint, "raid")
    191           && strcmp (mountlist->el[pos].mountpoint, "image")
    192           && strcmp (mountlist->el[pos].mountpoint, "none")
    193           && mountlist->el[pos].mountpoint[0] != '/')
    194           {
    195           sprintf (tmp, " %s has a weird mountpoint.", device);
    196           log_it (tmp);
    197           strcat (flaws_str, tmp);
    198           res++;
    199           }
    200       /* is format sensible? */
    201       if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    202           {
    203           sprintf (tmp, " %s has unsupported format.", device);
    204           log_it (tmp);
    205           strcat (flaws_str, tmp);
    206           res++;
    207           }
    208       amount_allocated += mountlist->el[pos].size / 1024;
    209       prev_sp_no = cur_sp_no;
    210       }
    211   }
    212 
    213   npos = pos = 0;
    214   for (curr_part_no = 1; curr_part_no < 99; curr_part_no++)
    215     {
    216       sprintf (device, "%ss%d", drive, curr_part_no);
    217       pos = find_device_in_mountlist (mountlist, device);
    218       npos = 0;
    219       for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
    220       sprintf (device, "%ss%i%c", device, curr_part_no, cur_sp_no);
    221       if (find_device_in_mountlist (mountlist, device) >= 0) npos++;
    222       }
    223       if (((pos >= 0) || npos) && foundsome) {
    224       sprintf (flaws_str + strlen (flaws_str), " %s has both DD and PC-style partitions.", drive);
    225       return ++res; // fatal error
    226       }
    227      
    228       sprintf (device, "%ss%d", drive, curr_part_no);
    229       strcpy (mountpoint, mountlist->el[pos].mountpoint);
    230       if (pos > 0 && !npos) {
    231       /* gap in the partition list? */
    232       if (curr_part_no - prev_part_no > 1)
    233           {
    234           if (prev_part_no == 0)
    235               {
    236               sprintf (tmp, " Gap prior to %s.", device);
    237               log_it (tmp);
    238               strcat (flaws_str, tmp);
    239               res++;
    240               }
    241           else if (curr_part_no > 5
    242                || (curr_part_no <= 4 && prev_part_no > 0))
    243               {
    244               sprintf (tmp, " Gap between %ss%d and %d.", drive, prev_part_no,
    245                    curr_part_no);
    246               log_it (tmp);
    247               strcat (flaws_str, tmp);
    248               res++;
    249               }
    250           }
    251       /* GPT allows more than 4 primary partitions */
    252       part_table_fmt = which_partition_format(drive);
    253       /* no spare primary partitions to help accommodate the logical(s)? */
    254       if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt,"MBR") == 0))
    255           {
    256           sprintf (tmp, " Partition %ss4 is occupied.", drive);
    257           log_it (tmp);
    258           strcat (flaws_str, tmp);
    259           res++;
    260           }
    261       /* does partition /dev/adXsY exist more than once in the mountlist? */
    262       for (i = 0, mountpoint_copies = 0, device_copies = 0;
    263            i < mountlist->entries; i++)
    264           {
    265           if (!strcmp (device, mountlist->el[i].device))
    266               {
    267               device_copies++;
    268               }
    269           }
    270       if (device_copies > 1)
    271           {
    272           sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    273           if (!strstr (flaws_str, tmp))
    274               {
    275               log_it (tmp);
    276               strcat (flaws_str, tmp);
    277               res++;
    278               }
    279           }
    280       /* silly partition size? */
    281       if (mountlist->el[pos].size < 8192
    282           && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    283           {
    284           sprintf (tmp, " %s is tiny!", device);
    285           log_it (tmp);
    286           strcat (flaws_str, tmp);
    287           res++;
    288           }
    289       /* mountpoint should begin with / unless it is swap, lvm or raid */
    290       if (strcmp (mountlist->el[pos].mountpoint, "swap")
    291           && strcmp (mountlist->el[pos].mountpoint, "lvm")
    292           && strcmp (mountlist->el[pos].mountpoint, "raid")
    293           && strcmp (mountlist->el[pos].mountpoint, "image")
    294           && strcmp (mountlist->el[pos].mountpoint, "none")
    295           && mountlist->el[pos].mountpoint[0] != '/')
    296           {
    297           sprintf (tmp, " %s has a weird mountpoint.", device);
    298           log_it (tmp);
    299           strcat (flaws_str, tmp);
    300           res++;
    301           }
    302       /* is format sensible? */
    303       if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    304           {
    305           sprintf (tmp, " %s has unsupported format.", device);
    306           log_it (tmp);
    307           strcat (flaws_str, tmp);
    308           res++;
    309           }
    310       } else {
    311       /* Check subpartitions */
    312       for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {   
    313           sprintf (device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
    314           pos = find_device_in_mountlist (mountlist, device);
    315           if (pos < 0)
    316           {
    317           continue;
    318           }
    319           strcpy (mountpoint, mountlist->el[pos].mountpoint);
    320           /* is it too big? */
    321           if (curr_part_no > 'h')
    322           {
    323               sprintf (tmp, " Can only have up to 'h' in disklabel.");
    324               log_it (tmp);
    325               strcat (flaws_str, tmp);
    326               res++;
    327           }
    328           /* does partition /dev/adXsYZ exist more than once in the mountlist? */
    329           for (i = 0, mountpoint_copies = 0, device_copies = 0;
    330            i < mountlist->entries; i++)
    331           {
    332               if (!strcmp (device, mountlist->el[i].device))
    333               {
    334                   device_copies++;
    335               }
    336           }
    337           if (device_copies > 1)
    338           {
    339               sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    340               if (!strstr (flaws_str, tmp))
    341               {
    342                   log_it (tmp);
    343                   strcat (flaws_str, tmp);
    344                   res++;
    345               }
    346           }
    347           /* silly partition size? */
    348           if (mountlist->el[pos].size < 8192
    349           && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    350           {
    351               sprintf (tmp, " %s is tiny!", device);
    352               log_it (tmp);
    353               strcat (flaws_str, tmp);
    354               res++;
    355           }
    356           /* mountpoint should begin with / unless it is swap, lvm or raid */
    357           if (strcmp (mountlist->el[pos].mountpoint, "swap")
    358           && strcmp (mountlist->el[pos].mountpoint, "lvm")
    359           && strcmp (mountlist->el[pos].mountpoint, "raid")
    360           && strcmp (mountlist->el[pos].mountpoint, "image")
    361           && strcmp (mountlist->el[pos].mountpoint, "none")
    362           && mountlist->el[pos].mountpoint[0] != '/')
    363           {
    364               sprintf (tmp, " %s has a weird mountpoint.", device);
    365               log_it (tmp);
    366               strcat (flaws_str, tmp);
    367               res++;
    368           }
    369           /* is format sensible? */
    370           if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    371           {
    372               sprintf (tmp, " %s has unsupported format.", device);
    373               log_it (tmp);
    374               strcat (flaws_str, tmp);
    375               res++;
    376           }
    377           amount_allocated += mountlist->el[pos].size / 1024;
    378           prev_sp_no = cur_sp_no;
    379       }
    380       }
    381      
    382       /* OK, continue with main loop */
    383       amount_allocated += mountlist->el[pos].size / 1024;
    384       prev_part_no = curr_part_no;
    385     }
    386 
    387   /* Over-allocated the disk? Unallocated space on disk? */
    388   if (amount_allocated > physical_drive_size)  // Used to be +1, but what if you're 1 MB too high?
    389     {
    390       sprintf (tmp, " %ld MB over-allocated on %s.",
    391            amount_allocated - physical_drive_size, drive);
    392       log_it (tmp);
    393       strcat (flaws_str, tmp);
    394       res++;
    395     }
    396   else if (amount_allocated < physical_drive_size - 1)
    397     {               /* NOT AN ERROR, JUST A WARNING :-) */
    398       sprintf (tmp, " %ld MB unallocated on %s.",
    399            physical_drive_size - amount_allocated, drive);
    400       log_it (tmp), strcat (flaws_str, tmp);
    401     }
    402   if (res)
    403     {
    404       return (FALSE);
    405     }
    406   else
    407     {
    408       return (TRUE);
    409     }
     116    /*@ initialize ***************************************************** */
     117    flaws_str[0] = '\0';
     118    prev_part_no = 0;
     119    tmp[0] = '\0';
     120
     121
     122    physical_drive_size = get_phys_size_of_drive(drive);
     123
     124    if (physical_drive_size < 0) {
     125        sprintf(tmp, " %s does not exist.", drive);
     126        strcat(flaws_str, tmp);
     127    } else {
     128        sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     129    }
     130    log_it(tmp);
     131
     132
     133    /* check DD */
     134    for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
     135        sprintf(device, "%s%c", drive, cur_sp_no);
     136        if (find_device_in_mountlist(mountlist, device) >= 0)
     137            foundsome = TRUE;
     138    }
     139    if (foundsome) {
     140        for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
     141            sprintf(device, "%s%c", drive, cur_sp_no);
     142            pos = find_device_in_mountlist(mountlist, device);
     143            if (pos < 0) {
     144                continue;
     145            }
     146            strcpy(mountpoint, mountlist->el[pos].mountpoint);
     147            /* is it too big? */
     148            if (curr_part_no > 'h') {
     149                sprintf(tmp, " Can only have up to 'h' in disklabel.");
     150                log_it(tmp);
     151                strcat(flaws_str, tmp);
     152                res++;
     153            }
     154            /* does partition /dev/adXsYZ exist more than once in the mountlist? */
     155            for (i = 0, mountpoint_copies = 0, device_copies = 0;
     156                 i < mountlist->entries; i++) {
     157                if (!strcmp(device, mountlist->el[i].device)) {
     158                    device_copies++;
     159                }
     160            }
     161            if (device_copies > 1) {
     162                sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     163                        device);
     164                if (!strstr(flaws_str, tmp)) {
     165                    log_it(tmp);
     166                    strcat(flaws_str, tmp);
     167                    res++;
     168                }
     169            }
     170            /* silly partition size? */
     171            if (mountlist->el[pos].size < 8192
     172                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     173                sprintf(tmp, " %s is tiny!", device);
     174                log_it(tmp);
     175                strcat(flaws_str, tmp);
     176                res++;
     177            }
     178            /* mountpoint should begin with / unless it is swap, lvm or raid */
     179            if (strcmp(mountlist->el[pos].mountpoint, "swap")
     180                && strcmp(mountlist->el[pos].mountpoint, "lvm")
     181                && strcmp(mountlist->el[pos].mountpoint, "raid")
     182                && strcmp(mountlist->el[pos].mountpoint, "image")
     183                && strcmp(mountlist->el[pos].mountpoint, "none")
     184                && mountlist->el[pos].mountpoint[0] != '/') {
     185                sprintf(tmp, " %s has a weird mountpoint.", device);
     186                log_it(tmp);
     187                strcat(flaws_str, tmp);
     188                res++;
     189            }
     190            /* is format sensible? */
     191            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
     192                sprintf(tmp, " %s has unsupported format.", device);
     193                log_it(tmp);
     194                strcat(flaws_str, tmp);
     195                res++;
     196            }
     197            amount_allocated += mountlist->el[pos].size / 1024;
     198            prev_sp_no = cur_sp_no;
     199        }
     200    }
     201
     202    npos = pos = 0;
     203    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
     204        sprintf(device, "%ss%d", drive, curr_part_no);
     205        pos = find_device_in_mountlist(mountlist, device);
     206        npos = 0;
     207        for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
     208            sprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no);
     209            if (find_device_in_mountlist(mountlist, device) >= 0)
     210                npos++;
     211        }
     212        if (((pos >= 0) || npos) && foundsome) {
     213            sprintf(flaws_str + strlen(flaws_str),
     214                    " %s has both DD and PC-style partitions.", drive);
     215            return ++res;       // fatal error
     216        }
     217
     218        sprintf(device, "%ss%d", drive, curr_part_no);
     219        strcpy(mountpoint, mountlist->el[pos].mountpoint);
     220        if (pos > 0 && !npos) {
     221            /* gap in the partition list? */
     222            if (curr_part_no - prev_part_no > 1) {
     223                if (prev_part_no == 0) {
     224                    sprintf(tmp, " Gap prior to %s.", device);
     225                    log_it(tmp);
     226                    strcat(flaws_str, tmp);
     227                    res++;
     228                } else if (curr_part_no > 5
     229                           || (curr_part_no <= 4 && prev_part_no > 0)) {
     230                    sprintf(tmp, " Gap between %ss%d and %d.", drive,
     231                            prev_part_no, curr_part_no);
     232                    log_it(tmp);
     233                    strcat(flaws_str, tmp);
     234                    res++;
     235                }
     236            }
     237            /* GPT allows more than 4 primary partitions */
     238            part_table_fmt = which_partition_format(drive);
     239            /* no spare primary partitions to help accommodate the logical(s)? */
     240            if ((curr_part_no >= 5 && prev_part_no == 4)
     241                && (strcmp(part_table_fmt, "MBR") == 0)) {
     242                sprintf(tmp, " Partition %ss4 is occupied.", drive);
     243                log_it(tmp);
     244                strcat(flaws_str, tmp);
     245                res++;
     246            }
     247            /* does partition /dev/adXsY exist more than once in the mountlist? */
     248            for (i = 0, mountpoint_copies = 0, device_copies = 0;
     249                 i < mountlist->entries; i++) {
     250                if (!strcmp(device, mountlist->el[i].device)) {
     251                    device_copies++;
     252                }
     253            }
     254            if (device_copies > 1) {
     255                sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     256                        device);
     257                if (!strstr(flaws_str, tmp)) {
     258                    log_it(tmp);
     259                    strcat(flaws_str, tmp);
     260                    res++;
     261                }
     262            }
     263            /* silly partition size? */
     264            if (mountlist->el[pos].size < 8192
     265                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     266                sprintf(tmp, " %s is tiny!", device);
     267                log_it(tmp);
     268                strcat(flaws_str, tmp);
     269                res++;
     270            }
     271            /* mountpoint should begin with / unless it is swap, lvm or raid */
     272            if (strcmp(mountlist->el[pos].mountpoint, "swap")
     273                && strcmp(mountlist->el[pos].mountpoint, "lvm")
     274                && strcmp(mountlist->el[pos].mountpoint, "raid")
     275                && strcmp(mountlist->el[pos].mountpoint, "image")
     276                && strcmp(mountlist->el[pos].mountpoint, "none")
     277                && mountlist->el[pos].mountpoint[0] != '/') {
     278                sprintf(tmp, " %s has a weird mountpoint.", device);
     279                log_it(tmp);
     280                strcat(flaws_str, tmp);
     281                res++;
     282            }
     283            /* is format sensible? */
     284            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
     285                sprintf(tmp, " %s has unsupported format.", device);
     286                log_it(tmp);
     287                strcat(flaws_str, tmp);
     288                res++;
     289            }
     290        } else {
     291            /* Check subpartitions */
     292            for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
     293                sprintf(device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
     294                pos = find_device_in_mountlist(mountlist, device);
     295                if (pos < 0) {
     296                    continue;
     297                }
     298                strcpy(mountpoint, mountlist->el[pos].mountpoint);
     299                /* is it too big? */
     300                if (curr_part_no > 'h') {
     301                    sprintf(tmp, " Can only have up to 'h' in disklabel.");
     302                    log_it(tmp);
     303                    strcat(flaws_str, tmp);
     304                    res++;
     305                }
     306                /* does partition /dev/adXsYZ exist more than once in the mountlist? */
     307                for (i = 0, mountpoint_copies = 0, device_copies = 0;
     308                     i < mountlist->entries; i++) {
     309                    if (!strcmp(device, mountlist->el[i].device)) {
     310                        device_copies++;
     311                    }
     312                }
     313                if (device_copies > 1) {
     314                    sprintf(tmp, " %s %s's.",
     315                            number_to_text(device_copies), device);
     316                    if (!strstr(flaws_str, tmp)) {
     317                        log_it(tmp);
     318                        strcat(flaws_str, tmp);
     319                        res++;
     320                    }
     321                }
     322                /* silly partition size? */
     323                if (mountlist->el[pos].size < 8192
     324                    && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     325                    sprintf(tmp, " %s is tiny!", device);
     326                    log_it(tmp);
     327                    strcat(flaws_str, tmp);
     328                    res++;
     329                }
     330                /* mountpoint should begin with / unless it is swap, lvm or raid */
     331                if (strcmp(mountlist->el[pos].mountpoint, "swap")
     332                    && strcmp(mountlist->el[pos].mountpoint, "lvm")
     333                    && strcmp(mountlist->el[pos].mountpoint, "raid")
     334                    && strcmp(mountlist->el[pos].mountpoint, "image")
     335                    && strcmp(mountlist->el[pos].mountpoint, "none")
     336                    && mountlist->el[pos].mountpoint[0] != '/') {
     337                    sprintf(tmp, " %s has a weird mountpoint.", device);
     338                    log_it(tmp);
     339                    strcat(flaws_str, tmp);
     340                    res++;
     341                }
     342                /* is format sensible? */
     343                if (!is_this_a_valid_disk_format
     344                    (mountlist->el[pos].format)) {
     345                    sprintf(tmp, " %s has unsupported format.", device);
     346                    log_it(tmp);
     347                    strcat(flaws_str, tmp);
     348                    res++;
     349                }
     350                amount_allocated += mountlist->el[pos].size / 1024;
     351                prev_sp_no = cur_sp_no;
     352            }
     353        }
     354
     355        /* OK, continue with main loop */
     356        amount_allocated += mountlist->el[pos].size / 1024;
     357        prev_part_no = curr_part_no;
     358    }
     359
     360    /* Over-allocated the disk? Unallocated space on disk? */
     361    if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
     362    {
     363        sprintf(tmp, " %ld MB over-allocated on %s.",
     364                amount_allocated - physical_drive_size, drive);
     365        log_it(tmp);
     366        strcat(flaws_str, tmp);
     367        res++;
     368    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     369        sprintf(tmp, " %ld MB unallocated on %s.",
     370                physical_drive_size - amount_allocated, drive);
     371        log_it(tmp), strcat(flaws_str, tmp);
     372    }
     373    if (res) {
     374        return (FALSE);
     375    } else {
     376        return (TRUE);
     377    }
    410378}
    411379
     
    414382{
    415383
    416     /*@ int **************************************************************/
    417   int prev_part_no = 0;
     384    /*@ int ************************************************************* */
     385    int prev_part_no = 0;
    418386    int curr_part_no = 0;
    419387    int pos = 0;
     
    423391    int i = 0;
    424392
    425     /*@ buffers *********************************************************/
    426   char *tmp;
     393    /*@ buffers ******************************************************** */
     394    char *tmp;
    427395    char *device;
    428396    char *mountpoint;
    429397
    430     /*@ long ************************************************************/
    431   long physical_drive_size = 0;
     398    /*@ long *********************************************************** */
     399    long physical_drive_size = 0;
    432400    long amount_allocated = 0;
    433401
    434     /*@ pointers ********************************************************/
     402    /*@ pointers ******************************************************* */
    435403    char *part_table_fmt;
    436404
    437     /*@ initialize ******************************************************/
    438   assert_string_is_neither_NULL_nor_zerolength(drive);
    439   assert(mountlist!=NULL);
    440   assert(flaws_str!=NULL);
    441 
    442   malloc_string(tmp);
    443   malloc_string(device);
    444   malloc_string(mountpoint);
    445   flaws_str[0] = '\0';
    446   prev_part_no = 0;
    447   tmp[0] = '\0';
    448 
    449 
    450   physical_drive_size = get_phys_size_of_drive (drive);
    451 
    452   if (physical_drive_size < 0)
    453     {
    454       sprintf (tmp, " %s does not exist.", drive);
    455       strcat (flaws_str, tmp);
    456       res++;
    457       log_msg(1, tmp);
    458       goto endoffunc;
    459     }
    460   else
    461     {
    462       sprintf (tmp, "%s is %ld MB", drive, physical_drive_size);
    463       log_it (tmp);
    464     }
    465 
    466   for (curr_part_no = 1; curr_part_no < 99; curr_part_no++)
    467     {
    468       sprintf (device, "%s%d", drive, curr_part_no);
    469       pos = find_device_in_mountlist (mountlist, device);
    470       if (pos < 0)
    471     {
    472       continue;
    473     }
    474       if (physical_drive_size < 0)
    475         {
    476           sprintf(tmp, " %s refers to non-existent hardware.", device);
    477           strcat (flaws_str, tmp);
    478           res++;
    479           continue;
    480         }
    481       strcpy (mountpoint, mountlist->el[pos].mountpoint);
    482       /* gap in the partition list? */
    483       if (curr_part_no - prev_part_no > 1)
    484     {
    485       if (prev_part_no == 0)
    486         {
    487           sprintf (tmp, " Gap prior to %s.", device);
    488           log_it (tmp);
    489           strcat (flaws_str, tmp);
    490           res++;
    491         }
    492       else if (curr_part_no > 5
    493            || (curr_part_no <= 4 && prev_part_no > 0))
    494         {
    495           sprintf (tmp, " Gap between %s%d and %d.", drive, prev_part_no,
    496                curr_part_no);
    497           log_it (tmp);
    498           strcat (flaws_str, tmp);
    499           res++;
    500         }
    501     }
    502       /* GPT allows more than 4 primary partitions */
    503       part_table_fmt = which_partition_format(drive);
    504       /* no spare primary partitions to help accommodate the logical(s)? */
    505       if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt,"MBR") == 0))
    506     {
    507       sprintf (tmp, " Partition %s4 is occupied.", drive);
    508       log_it (tmp);
    509       strcat (flaws_str, tmp);
    510       res++;
    511     }
    512       /* does partition /dev/hdNX exist more than once in the mountlist? */
    513       for (i = 0, mountpoint_copies = 0, device_copies = 0;
    514        i < mountlist->entries; i++)
    515     {
    516       if (!strcmp (device, mountlist->el[i].device))
    517         {
    518           device_copies++;
    519         }
    520     }
    521       if (device_copies > 1)
    522     {
    523       sprintf (tmp, " %s %s's.", number_to_text (device_copies), device);
    524       if (!strstr (flaws_str, tmp))
    525         {
    526           log_it (tmp);
    527           strcat (flaws_str, tmp);
    528           res++;
    529         }
    530     }
    531       /* silly partition size? */
    532       if (mountlist->el[pos].size < 8192
    533       && strcmp (mountlist->el[pos].mountpoint, "lvm"))
    534     {
    535       sprintf (tmp, " %s is tiny!", device);
    536       log_it (tmp);
    537       strcat (flaws_str, tmp);
    538       res++;
    539     }
    540       /* mountpoint should begin with / unless it is swap, lvm or raid */
    541       if (strcmp (mountlist->el[pos].mountpoint, "swap")
    542       && strcmp (mountlist->el[pos].mountpoint, "lvm")
    543       && strcmp (mountlist->el[pos].mountpoint, "raid")
    544       && strcmp (mountlist->el[pos].mountpoint, "image")
    545       && mountlist->el[pos].mountpoint[0] != '/')
    546     {
    547       sprintf (tmp, " %s has a weird mountpoint.", device);
    548       log_it (tmp);
    549       strcat (flaws_str, tmp);
    550       res++;
    551     }
    552       /* is format sensible? */
    553       if (!is_this_a_valid_disk_format (mountlist->el[pos].format))
    554     {
    555       sprintf (tmp, " %s has unsupported format.", device);
    556       log_it (tmp);
    557       strcat (flaws_str, tmp);
    558       res++;
    559     }
    560       /* OK, continue with main loop */
    561       amount_allocated += mountlist->el[pos].size / 1024;
    562       prev_part_no = curr_part_no;
    563     }
    564 
    565   /* Over-allocated the disk? Unallocated space on disk? */
    566   if (amount_allocated > physical_drive_size + 1)
    567     {
    568       sprintf (tmp, " %ld MB over-allocated on %s.",
    569            amount_allocated - physical_drive_size, drive);
    570       log_it (tmp);
    571       strcat (flaws_str, tmp);
    572       res++;
    573     }
    574   else if (amount_allocated < physical_drive_size - 1)
    575     {               /* NOT AN ERROR, JUST A WARNING :-) */
    576       sprintf (tmp, " %ld MB unallocated on %s.",
    577            physical_drive_size - amount_allocated, drive);
    578       log_it (tmp), strcat (flaws_str, tmp);
    579     }
    580 
    581 endoffunc:
    582   paranoid_free(tmp);
    583   paranoid_free(device);
    584   paranoid_free(mountpoint);
    585  
    586   if (res)
    587     {
    588       return (FALSE);
    589     }
    590   else
    591     {
    592       return (TRUE);
    593     }
     405    /*@ initialize ***************************************************** */
     406    assert_string_is_neither_NULL_nor_zerolength(drive);
     407    assert(mountlist != NULL);
     408    assert(flaws_str != NULL);
     409
     410    malloc_string(tmp);
     411    malloc_string(device);
     412    malloc_string(mountpoint);
     413    flaws_str[0] = '\0';
     414    prev_part_no = 0;
     415    tmp[0] = '\0';
     416
     417
     418    physical_drive_size = get_phys_size_of_drive(drive);
     419
     420    if (physical_drive_size < 0) {
     421        sprintf(tmp, " %s does not exist.", drive);
     422        strcat(flaws_str, tmp);
     423        res++;
     424        log_msg(1, tmp);
     425        goto endoffunc;
     426    } else {
     427        sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     428        log_it(tmp);
     429    }
     430
     431    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
     432        sprintf(device, "%s%d", drive, curr_part_no);
     433        pos = find_device_in_mountlist(mountlist, device);
     434        if (pos < 0) {
     435            continue;
     436        }
     437        if (physical_drive_size < 0) {
     438            sprintf(tmp, " %s refers to non-existent hardware.", device);
     439            strcat(flaws_str, tmp);
     440            res++;
     441            continue;
     442        }
     443        strcpy(mountpoint, mountlist->el[pos].mountpoint);
     444        /* gap in the partition list? */
     445        if (curr_part_no - prev_part_no > 1) {
     446            if (prev_part_no == 0) {
     447                sprintf(tmp, " Gap prior to %s.", device);
     448                log_it(tmp);
     449                strcat(flaws_str, tmp);
     450                res++;
     451            } else if (curr_part_no > 5
     452                       || (curr_part_no <= 4 && prev_part_no > 0)) {
     453                sprintf(tmp, " Gap between %s%d and %d.", drive,
     454                        prev_part_no, curr_part_no);
     455                log_it(tmp);
     456                strcat(flaws_str, tmp);
     457                res++;
     458            }
     459        }
     460        /* GPT allows more than 4 primary partitions */
     461        part_table_fmt = which_partition_format(drive);
     462        /* no spare primary partitions to help accommodate the logical(s)? */
     463        if ((curr_part_no >= 5 && prev_part_no == 4)
     464            && (strcmp(part_table_fmt, "MBR") == 0)) {
     465            sprintf(tmp, " Partition %s4 is occupied.", drive);
     466            log_it(tmp);
     467            strcat(flaws_str, tmp);
     468            res++;
     469        }
     470        /* does partition /dev/hdNX exist more than once in the mountlist? */
     471        for (i = 0, mountpoint_copies = 0, device_copies = 0;
     472             i < mountlist->entries; i++) {
     473            if (!strcmp(device, mountlist->el[i].device)) {
     474                device_copies++;
     475            }
     476        }
     477        if (device_copies > 1) {
     478            sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     479                    device);
     480            if (!strstr(flaws_str, tmp)) {
     481                log_it(tmp);
     482                strcat(flaws_str, tmp);
     483                res++;
     484            }
     485        }
     486        /* silly partition size? */
     487        if (mountlist->el[pos].size < 8192
     488            && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
     489            sprintf(tmp, " %s is tiny!", device);
     490            log_it(tmp);
     491            strcat(flaws_str, tmp);
     492            res++;
     493        }
     494        /* mountpoint should begin with / unless it is swap, lvm or raid */
     495        if (strcmp(mountlist->el[pos].mountpoint, "swap")
     496            && strcmp(mountlist->el[pos].mountpoint, "lvm")
     497            && strcmp(mountlist->el[pos].mountpoint, "raid")
     498            && strcmp(mountlist->el[pos].mountpoint, "image")
     499            && mountlist->el[pos].mountpoint[0] != '/') {
     500            sprintf(tmp, " %s has a weird mountpoint.", device);
     501            log_it(tmp);
     502            strcat(flaws_str, tmp);
     503            res++;
     504        }
     505        /* is format sensible? */
     506        if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
     507            sprintf(tmp, " %s has unsupported format.", device);
     508            log_it(tmp);
     509            strcat(flaws_str, tmp);
     510            res++;
     511        }
     512        /* OK, continue with main loop */
     513        amount_allocated += mountlist->el[pos].size / 1024;
     514        prev_part_no = curr_part_no;
     515    }
     516
     517    /* Over-allocated the disk? Unallocated space on disk? */
     518    if (amount_allocated > physical_drive_size + 1) {
     519        sprintf(tmp, " %ld MB over-allocated on %s.",
     520                amount_allocated - physical_drive_size, drive);
     521        log_it(tmp);
     522        strcat(flaws_str, tmp);
     523        res++;
     524    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     525        sprintf(tmp, " %ld MB unallocated on %s.",
     526                physical_drive_size - amount_allocated, drive);
     527        log_it(tmp), strcat(flaws_str, tmp);
     528    }
     529
     530  endoffunc:
     531    paranoid_free(tmp);
     532    paranoid_free(device);
     533    paranoid_free(mountpoint);
     534
     535    if (res) {
     536        return (FALSE);
     537    } else {
     538        return (TRUE);
     539    }
    594540}
    595541#endif
     
    608554 */
    609555int
    610 evaluate_mountlist (struct mountlist_itself *mountlist, char *flaws_str_A,
    611             char *flaws_str_B, char *flaws_str_C)
    612 {
    613 
    614     /*@ buffer ************************************************************/
    615     struct list_of_disks *drivelist;
     556evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A,
     557                   char *flaws_str_B, char *flaws_str_C)
     558{
     559
     560    /*@ buffer *********************************************************** */
     561    struct list_of_disks *drivelist;
    616562    char *tmp;
    617563    char *flaws_str;
    618564
    619     /*@ int ***************************************************************/
     565    /*@ int ************************************************************** */
    620566    int i = 0;
    621567    int res = 0;
    622568
    623     /*@ initialize ********************************************************/
    624 
    625   drivelist = malloc(sizeof(struct list_of_disks));
    626   malloc_string(tmp);
    627   malloc_string(flaws_str);
    628   assert(mountlist!=NULL);
    629   assert(flaws_str_A!=NULL);
    630   assert(flaws_str_B!=NULL);
    631   assert(flaws_str_C!=NULL);
    632   flaws_str[0] = '\0';
    633 
    634   make_list_of_drives_in_mountlist (mountlist, drivelist);
    635 
    636   log_it ("Evaluating mountlist...");
    637 
    638  for (i = 0; i < drivelist->entries; i++)
    639     {
    640       if (strstr (drivelist->el[i].device, DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE))
    641     {
    642       sprintf (tmp, " Not evaluating %s (I don't know how yet)",
    643            drivelist->el[i].device);
    644       log_it (tmp);
    645       tmp[0] = '\0';
    646     }
    647       else
    648     {
    649       if (!evaluate_drive_within_mountlist
    650           (mountlist, drivelist->el[i].device, tmp))
    651         {
    652           res++;
    653         }
    654     }
    655       strcat (flaws_str, tmp);
    656     }
    657   res += look_for_duplicate_mountpoints (mountlist, flaws_str);
     569    /*@ initialize ******************************************************* */
     570
     571    drivelist = malloc(sizeof(struct list_of_disks));
     572    malloc_string(tmp);
     573    malloc_string(flaws_str);
     574    assert(mountlist != NULL);
     575    assert(flaws_str_A != NULL);
     576    assert(flaws_str_B != NULL);
     577    assert(flaws_str_C != NULL);
     578    flaws_str[0] = '\0';
     579
     580    make_list_of_drives_in_mountlist(mountlist, drivelist);
     581
     582    log_it("Evaluating mountlist...");
     583
     584    for (i = 0; i < drivelist->entries; i++) {
     585        if (strstr
     586            (drivelist->el[i].device,
     587             DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
     588            sprintf(tmp, " Not evaluating %s (I don't know how yet)",
     589                    drivelist->el[i].device);
     590            log_it(tmp);
     591            tmp[0] = '\0';
     592        } else {
     593            if (!evaluate_drive_within_mountlist
     594                (mountlist, drivelist->el[i].device, tmp)) {
     595                res++;
     596            }
     597        }
     598        strcat(flaws_str, tmp);
     599    }
     600    res += look_for_duplicate_mountpoints(mountlist, flaws_str);
    658601/*  res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see
    659602 which formarts are actually _supported_ by the kernel */
    660   /* log_it(flaws_str); */
    661   return (spread_flaws_across_three_lines
    662       (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
     603    /* log_it(flaws_str); */
     604    return (spread_flaws_across_three_lines
     605            (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
    663606}
    664607
     
    672615 */
    673616int
    674 find_device_in_mountlist (struct mountlist_itself *mountlist, char *device)
    675 {
    676 
    677     /*@ int ***************************************************************/
    678   int i = 0;
    679   char*tmp;
    680   char*flaws_str;
    681  
    682   malloc_string(tmp);
    683   malloc_string(flaws_str);
    684  
    685   assert(mountlist!=NULL);
    686   assert_string_is_neither_NULL_nor_zerolength(device);
    687   for (i = 0;
    688        i < mountlist->entries
    689        && strcmp (mountlist->el[i].device, device) != 0; i++);
    690  
    691   paranoid_free(tmp);
    692   paranoid_free(flaws_str);
    693 
    694   if (i == mountlist->entries)
    695     {
    696       return (-1);
    697     }
    698   else
    699     {
    700       return (i);
    701     }
     617find_device_in_mountlist(struct mountlist_itself *mountlist, char *device)
     618{
     619
     620    /*@ int ************************************************************** */
     621    int i = 0;
     622    char *tmp;
     623    char *flaws_str;
     624
     625    malloc_string(tmp);
     626    malloc_string(flaws_str);
     627
     628    assert(mountlist != NULL);
     629    assert_string_is_neither_NULL_nor_zerolength(device);
     630    for (i = 0;
     631         i < mountlist->entries
     632         && strcmp(mountlist->el[i].device, device) != 0; i++);
     633
     634    paranoid_free(tmp);
     635    paranoid_free(flaws_str);
     636
     637    if (i == mountlist->entries) {
     638        return (-1);
     639    } else {
     640        return (i);
     641    }
    702642}
    703643
     
    713653 */
    714654int
    715 look_for_duplicate_mountpoints (struct mountlist_itself *mountlist,
    716                 char *flaws_str)
    717 {
    718 
    719     /*@ int **************************************************************/
    720   int res = 0;
     655look_for_duplicate_mountpoints(struct mountlist_itself *mountlist,
     656                               char *flaws_str)
     657{
     658
     659    /*@ int ************************************************************* */
     660    int res = 0;
    721661    int currline = 0;
    722662    int i = 0;
     
    724664    int last_copy = 0;
    725665
    726     /*@ buffetr **********************************************************/
    727   char *curr_mountpoint;
     666    /*@ buffetr ********************************************************* */
     667    char *curr_mountpoint;
    728668    char *tmp;
    729669
    730   malloc_string(curr_mountpoint);
    731   malloc_string(tmp);
    732   assert(mountlist!=NULL);
    733   assert(flaws_str!=NULL);
    734   for (currline = 0; currline < mountlist->entries; currline++)
    735     {
    736       strcpy (curr_mountpoint, mountlist->el[currline].mountpoint);
    737       for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; i++)
    738     {
    739       if (!strcmp (mountlist->el[i].mountpoint, curr_mountpoint)
    740           && strcmp (mountlist->el[i].mountpoint, "lvm")
    741           && strcmp (mountlist->el[i].mountpoint, "swap"))
    742         {
    743           last_copy = i;
    744           copies++;
    745         }
    746     }
    747       if (copies > 1 && last_copy == currline
    748       && strcmp (curr_mountpoint, "raid"))
    749     {
    750       sprintf (tmp, " %s %s's.", number_to_text (copies),
    751            curr_mountpoint);
    752       strcat (flaws_str, tmp);
    753       log_it (tmp);
    754       res++;
    755     }
    756     }
    757   paranoid_free(curr_mountpoint);
    758   paranoid_free(tmp);
    759   return (res);
     670    malloc_string(curr_mountpoint);
     671    malloc_string(tmp);
     672    assert(mountlist != NULL);
     673    assert(flaws_str != NULL);
     674    for (currline = 0; currline < mountlist->entries; currline++) {
     675        strcpy(curr_mountpoint, mountlist->el[currline].mountpoint);
     676        for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries;
     677             i++) {
     678            if (!strcmp(mountlist->el[i].mountpoint, curr_mountpoint)
     679                && strcmp(mountlist->el[i].mountpoint, "lvm")
     680                && strcmp(mountlist->el[i].mountpoint, "swap")) {
     681                last_copy = i;
     682                copies++;
     683            }
     684        }
     685        if (copies > 1 && last_copy == currline
     686            && strcmp(curr_mountpoint, "raid")) {
     687            sprintf(tmp, " %s %s's.", number_to_text(copies),
     688                    curr_mountpoint);
     689            strcat(flaws_str, tmp);
     690            log_it(tmp);
     691            res++;
     692        }
     693    }
     694    paranoid_free(curr_mountpoint);
     695    paranoid_free(tmp);
     696    return (res);
    760697}
    761698
     
    768705 */
    769706int
    770 look_for_weird_formats (struct mountlist_itself *mountlist, char *flaws_str)
    771 {
    772 
    773     /*@ int **************************************************************/
    774   int i = 0;
     707look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)
     708{
     709
     710    /*@ int ************************************************************* */
     711    int i = 0;
    775712    int res = 0;
    776713
    777     /*@ buffers **********************************************************/
    778   char *tmp;
     714    /*@ buffers ********************************************************* */
     715    char *tmp;
    779716    char *format_sz;
    780717
    781   malloc_string(tmp);
    782   malloc_string(format_sz);
    783  
    784   assert(mountlist!=NULL);
    785   assert(flaws_str!=NULL);
    786 
    787   for (i = 0; i < mountlist->entries; i++)
    788     {
    789       sprintf (format_sz, " %s ", mountlist->el[i].format);
    790       if (!strstr
    791       (SANE_FORMATS, format_sz)
    792         && strcmp (mountlist->el[i].mountpoint, "image") != 0)
    793     {
    794       sprintf (tmp, " %s has unknown format.", mountlist->el[i].device);
    795       log_it (tmp);
    796       strcat (flaws_str, tmp);
    797       res++;
    798     }
    799       else
    800     if ((!strcmp (mountlist->el[i].format, "swap")
    801          && strcmp (mountlist->el[i].mountpoint, "swap") && strcmp (mountlist->el[i].mountpoint, "none"))
    802         || (strcmp (mountlist->el[i].format, "swap")
    803         && !strcmp (mountlist->el[i].mountpoint, "swap") && !strcmp (mountlist->el[i].mountpoint, "none")))
    804     {
    805       sprintf (tmp, " %s is half-swap.", mountlist->el[i].device);
    806       log_it (tmp);
    807       strcat (flaws_str, tmp);
    808       res++;
    809     }
    810     }
    811   paranoid_free(tmp);
    812   paranoid_free(format_sz);
    813   return (res);
     718    malloc_string(tmp);
     719    malloc_string(format_sz);
     720
     721    assert(mountlist != NULL);
     722    assert(flaws_str != NULL);
     723
     724    for (i = 0; i < mountlist->entries; i++) {
     725        sprintf(format_sz, " %s ", mountlist->el[i].format);
     726        if (!strstr(SANE_FORMATS, format_sz)
     727            && strcmp(mountlist->el[i].mountpoint, "image") != 0) {
     728            sprintf(tmp, " %s has unknown format.",
     729                    mountlist->el[i].device);
     730            log_it(tmp);
     731            strcat(flaws_str, tmp);
     732            res++;
     733        } else if ((!strcmp(mountlist->el[i].format, "swap")
     734                    && strcmp(mountlist->el[i].mountpoint, "swap")
     735                    && strcmp(mountlist->el[i].mountpoint, "none"))
     736                   || (strcmp(mountlist->el[i].format, "swap")
     737                       && !strcmp(mountlist->el[i].mountpoint, "swap")
     738                       && !strcmp(mountlist->el[i].mountpoint, "none"))) {
     739            sprintf(tmp, " %s is half-swap.", mountlist->el[i].device);
     740            log_it(tmp);
     741            strcat(flaws_str, tmp);
     742            res++;
     743        }
     744    }
     745    paranoid_free(tmp);
     746    paranoid_free(format_sz);
     747    return (res);
    814748}
    815749
     
    823757 */
    824758int
    825 make_list_of_drives_in_mountlist (struct mountlist_itself *mountlist,
    826              struct list_of_disks *drivelist)
    827 {
    828 
    829         /*@ int **************************************************************/
    830   int lino;
    831   int noof_drives;
    832   int j;
    833 
    834         /*@ buffers **********************************************************/
    835   char *drive;
    836   char *tmp;
    837 
    838   long long size;
    839 
    840   malloc_string(drive);
    841   malloc_string(tmp);
    842   assert(mountlist!=NULL);
    843   assert(drivelist!=NULL);
    844   log_it ("Making list of drives");
    845   for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++)
    846     {
    847      
    848       strcpy (drive, mountlist->el[lino].device);
    849       if (!strncmp (drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)))
    850     {
    851       sprintf (tmp,
    852            "Not putting %s in list of drives: it's a virtual drive",
    853            drive);
    854       log_msg (8, tmp);
    855       continue;
    856     }
    857 
    858       size=mountlist->el[lino].size;
    859       if ( size == 0 )
    860         {
    861           sprintf (tmp,
    862                    "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
    863                    drive);
    864           log_msg (8, tmp);
    865           continue;
    866         }
     759make_list_of_drives_in_mountlist(struct mountlist_itself *mountlist,
     760                                 struct list_of_disks *drivelist)
     761{
     762
     763    /*@ int ************************************************************* */
     764    int lino;
     765    int noof_drives;
     766    int j;
     767
     768    /*@ buffers ********************************************************* */
     769    char *drive;
     770    char *tmp;
     771
     772    long long size;
     773
     774    malloc_string(drive);
     775    malloc_string(tmp);
     776    assert(mountlist != NULL);
     777    assert(drivelist != NULL);
     778    log_it("Making list of drives");
     779    for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {
     780
     781        strcpy(drive, mountlist->el[lino].device);
     782        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     783            sprintf(tmp,
     784                    "Not putting %s in list of drives: it's a virtual drive",
     785                    drive);
     786            log_msg(8, tmp);
     787            continue;
     788        }
     789
     790        size = mountlist->el[lino].size;
     791        if (size == 0) {
     792            sprintf(tmp,
     793                    "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
     794                    drive);
     795            log_msg(8, tmp);
     796            continue;
     797        }
    867798
    868799/*
     
    877808*/
    878809
    879       sprintf (tmp,
    880            "Putting %s with size %lli in list of drives",
    881            drive, size);
    882       log_msg (8, tmp);
    883 
    884       (void) truncate_to_drive_name (drive);
    885       for (j = 0; j < noof_drives && strcmp (drivelist->el[j].device, drive) != 0; j++)
    886     continue;
    887       if (j == noof_drives)
    888     {
    889       strcpy (drivelist->el[noof_drives++].device, drive);
    890     }
    891     }
    892   drivelist->entries = noof_drives;
    893   log_msg (8, "Made list of drives");
    894   paranoid_free(drive);
    895   paranoid_free(tmp);
    896 
    897   return (noof_drives);
     810        sprintf(tmp,
     811                "Putting %s with size %lli in list of drives",
     812                drive, size);
     813        log_msg(8, tmp);
     814
     815        (void) truncate_to_drive_name(drive);
     816        for (j = 0;
     817             j < noof_drives
     818             && strcmp(drivelist->el[j].device, drive) != 0; j++)
     819            continue;
     820        if (j == noof_drives) {
     821            strcpy(drivelist->el[noof_drives++].device, drive);
     822        }
     823    }
     824    drivelist->entries = noof_drives;
     825    log_msg(8, "Made list of drives");
     826    paranoid_free(drive);
     827    paranoid_free(tmp);
     828
     829    return (noof_drives);
    898830}
    899831
     
    910842 * @param raidlist The raidlist to examine.
    911843 */
    912 void
    913 make_list_of_unallocated_raid_partitions (struct mountlist_itself
    914                       *output_list,
    915                       struct mountlist_itself *mountlist,
    916                       struct raidlist_itself *raidlist)
    917 {
    918 
    919     /*@ int **************************************************************/
    920   int items = 0;
     844void make_list_of_unallocated_raid_partitions(struct mountlist_itself
     845                                              *output_list,
     846                                              struct mountlist_itself
     847                                              *mountlist,
     848                                              struct raidlist_itself
     849                                              *raidlist)
     850{
     851
     852    /*@ int ************************************************************* */
     853    int items = 0;
    921854    int i = 0;
    922855    int used_by = 0;
    923856
    924     /*@ buffers **********************************************************/
    925   char *tmp;
    926 
    927   malloc_string(tmp);
    928   assert(output_list!=NULL);
    929   assert(mountlist!=NULL);
    930   assert(raidlist!=NULL);
    931   log_it ("MLOURP -- starting");
    932   items = 0;
    933 
    934 
    935   for (i = 0; i < mountlist->entries; i++)
    936     {
    937       if (strstr (mountlist->el[i].mountpoint, "raid"))
    938     {
    939       used_by =
    940         which_raid_device_is_using_this_partition (raidlist,
    941                                mountlist->el[i].
    942                                device);
    943       if (used_by < 0)
    944         {
    945           memcpy ((void *) &output_list->el[items++],
    946               (void *) &mountlist->el[i],
    947               sizeof (struct mountlist_line));
    948           sprintf (tmp,
    949                "%s is available; user may choose to add it to raid device",
    950                output_list->el[items - 1].device);
    951           log_it (tmp);
    952         }
    953     }
    954     }
    955   output_list->entries = items;
    956   log_it ("MLUORP -- ending");
    957   paranoid_free(tmp);
     857    /*@ buffers ********************************************************* */
     858    char *tmp;
     859
     860    malloc_string(tmp);
     861    assert(output_list != NULL);
     862    assert(mountlist != NULL);
     863    assert(raidlist != NULL);
     864    log_it("MLOURP -- starting");
     865    items = 0;
     866
     867
     868    for (i = 0; i < mountlist->entries; i++) {
     869        if (strstr(mountlist->el[i].mountpoint, "raid")) {
     870            used_by =
     871                which_raid_device_is_using_this_partition(raidlist,
     872                                                          mountlist->el[i].
     873                                                          device);
     874            if (used_by < 0) {
     875                memcpy((void *) &output_list->el[items++],
     876                       (void *) &mountlist->el[i],
     877                       sizeof(struct mountlist_line));
     878                sprintf(tmp,
     879                        "%s is available; user may choose to add it to raid device",
     880                        output_list->el[items - 1].device);
     881                log_it(tmp);
     882            }
     883        }
     884    }
     885    output_list->entries = items;
     886    log_it("MLUORP -- ending");
     887    paranoid_free(tmp);
    958888}
    959889
     
    969899 */
    970900long long
    971 size_of_specific_device_in_mountlist (struct mountlist_itself *mountlist, char *device)
    972 {
    973     /*@ int ***************************************************************/
    974   int i = 0;
    975 
    976 
    977   assert(mountlist!=NULL);
    978   assert_string_is_neither_NULL_nor_zerolength(device);
    979 
    980   for (i = 0;
    981        i < mountlist->entries && strcmp (mountlist->el[i].device, device);
    982        i++);
    983   if (i == mountlist->entries)
    984     {
    985       return (-1);
    986     }
    987   else
    988     {
    989       return (mountlist->el[i].size);
    990     }
     901size_of_specific_device_in_mountlist(struct mountlist_itself *mountlist,
     902                                     char *device)
     903{
     904    /*@ int ************************************************************** */
     905    int i = 0;
     906
     907
     908    assert(mountlist != NULL);
     909    assert_string_is_neither_NULL_nor_zerolength(device);
     910
     911    for (i = 0;
     912         i < mountlist->entries && strcmp(mountlist->el[i].device, device);
     913         i++);
     914    if (i == mountlist->entries) {
     915        return (-1);
     916    } else {
     917        return (mountlist->el[i].size);
     918    }
    991919}
    992920
     
    1004932 * @return 0 for success, 1 for failure.
    1005933 */
    1006 int
    1007 load_mountlist( struct mountlist_itself *mountlist, char *fname)
    1008 {
    1009   FILE *fin;
    1010   /* malloc ***/
    1011   char *incoming;
    1012   char *siz;
    1013   char *tmp;
    1014   char*p;
    1015 
    1016   int items;
    1017   int j;
    1018 
    1019   assert(mountlist!=NULL);
    1020   assert_string_is_neither_NULL_nor_zerolength(fname);
    1021   malloc_string(incoming);
    1022   malloc_string(siz);
    1023   malloc_string(tmp);
    1024   if ( !( fin = fopen( fname, "r" ) ) )
    1025     {
    1026       log_it( "Unable to open mountlist - '%s'", fname );
    1027       log_to_screen( "Cannot open mountlist" );
    1028       paranoid_free(incoming);
    1029       paranoid_free(siz);
    1030       paranoid_free(tmp);
    1031       return( 1 );
    1032     }
    1033   items = 0;
    1034   (void) fgets( incoming, MAX_STR_LEN - 1, fin );
    1035   log_it( "Loading mountlist..." );
    1036   while( !feof( fin ) )
    1037     {
     934int load_mountlist(struct mountlist_itself *mountlist, char *fname)
     935{
     936    FILE *fin;
     937    /* malloc ** */
     938    char *incoming;
     939    char *siz;
     940    char *tmp;
     941    char *p;
     942
     943    int items;
     944    int j;
     945
     946    assert(mountlist != NULL);
     947    assert_string_is_neither_NULL_nor_zerolength(fname);
     948    malloc_string(incoming);
     949    malloc_string(siz);
     950    malloc_string(tmp);
     951    if (!(fin = fopen(fname, "r"))) {
     952        log_it("Unable to open mountlist - '%s'", fname);
     953        log_to_screen("Cannot open mountlist");
     954        paranoid_free(incoming);
     955        paranoid_free(siz);
     956        paranoid_free(tmp);
     957        return (1);
     958    }
     959    items = 0;
     960    (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     961    log_it("Loading mountlist...");
     962    while (!feof(fin)) {
    1038963#if linux
    1039       sscanf( incoming,
    1040           "%s %s %s %s %s",
    1041           mountlist->el[items].device,
    1042           mountlist->el[items].mountpoint,
    1043           mountlist->el[items].format,
    1044           siz,
    1045           mountlist->el[items].label);
     964        sscanf(incoming,
     965               "%s %s %s %s %s",
     966               mountlist->el[items].device,
     967               mountlist->el[items].mountpoint,
     968               mountlist->el[items].format,
     969               siz, mountlist->el[items].label);
    1046970#elif __FreeBSD__
    1047       sscanf (incoming,
    1048           "%s %s %s %s",
    1049           mountlist->el[items].device,
    1050           mountlist->el[items].mountpoint,
    1051           mountlist->el[items].format,
    1052           siz);
    1053       strcpy (mountlist->el[items].label, "");
     971        sscanf(incoming,
     972               "%s %s %s %s",
     973               mountlist->el[items].device,
     974               mountlist->el[items].mountpoint,
     975               mountlist->el[items].format, siz);
     976        strcpy(mountlist->el[items].label, "");
    1054977#endif
    1055978
    1056       if (
    1057         !strcmp(mountlist->el[items].device,"/proc") ||
    1058         !strcmp(mountlist->el[items].device, "proc") ||
    1059         !strcmp(mountlist->el[items].device,"/sys") ||
    1060         !strcmp(mountlist->el[items].device, "sys") ||
    1061         !strcmp(mountlist->el[items].device,"/devpts") ||
    1062     !strcmp(mountlist->el[items].device, "devpts")
    1063       )
    1064         {
    1065       log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device);
    1066           (void) fgets( incoming, MAX_STR_LEN - 1,fin );
    1067       continue;
    1068     }
    1069       mountlist->el[items].size = atoll( siz );
    1070       if ( mountlist->el[items].device[0] != '\0' && mountlist->el[items].device[0] != '#' )
    1071     {
    1072       if ( items >= ARBITRARY_MAXIMUM )
    1073         {
    1074           log_to_screen( "Too many lines in mountlist.. ABORTING" );
    1075           finish( 1 );
    1076         }
    1077       for( j=0; j < items && strcmp( mountlist->el[j].device, mountlist->el[items].device ); j++);
    1078       if (j < items)
    1079         {
    1080           strcat( mountlist->el[items].device, "_dup" );
    1081           sprintf( tmp, "Duplicate entry in mountlist - renaming to %s",mountlist->el[items].device );
    1082           log_it( tmp );
    1083         }
    1084     strcpy(tmp, mountlist->el[items].device);
    1085     if (strstr(tmp, "/dev/md/"))
    1086       {
    1087         log_it("format_device() --- Contracting %s", tmp);
    1088         p = strrchr(tmp, '/');
    1089         if (p) { *p = *(p+1); *(p+1) = *(p+2); *(p+2) = *(p+3); }
    1090         log_it("It was %s; it is now %s", mountlist->el[items].device, tmp);
    1091         strcpy(mountlist->el[items].device, tmp);
    1092       }
    1093 
    1094       sprintf( tmp,
    1095            "%s %s %s %lld %s",
    1096            mountlist->el[items].device,
    1097            mountlist->el[items].mountpoint,
    1098            mountlist->el[items].format,
    1099            mountlist->el[items].size,
    1100            mountlist->el[items].label);
    1101 
    1102       log_it( tmp );
    1103       items++;
    1104     }
    1105       (void) fgets( incoming, MAX_STR_LEN - 1,fin );
    1106     }
    1107   paranoid_fclose( fin );
    1108   mountlist->entries = items;
    1109 
    1110   log_it( "Mountlist loaded successfully." );
    1111   sprintf( tmp, "%d entries in mountlist", items );
    1112   log_it( tmp );
    1113   paranoid_free(incoming);
    1114   paranoid_free(siz);
    1115   paranoid_free(tmp);
    1116   return( 0 );
     979        if (!strcmp(mountlist->el[items].device, "/proc") ||
     980            !strcmp(mountlist->el[items].device, "proc") ||
     981            !strcmp(mountlist->el[items].device, "/sys") ||
     982            !strcmp(mountlist->el[items].device, "sys") ||
     983            !strcmp(mountlist->el[items].device, "/devpts") ||
     984            !strcmp(mountlist->el[items].device, "devpts")
     985            ) {
     986            log_msg(1,
     987                    "Ignoring %s in mountlist - not loading that line :) ",
     988                    mountlist->el[items].device);
     989            (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     990            continue;
     991        }
     992        mountlist->el[items].size = atoll(siz);
     993        if (mountlist->el[items].device[0] != '\0'
     994            && mountlist->el[items].device[0] != '#') {
     995            if (items >= ARBITRARY_MAXIMUM) {
     996                log_to_screen("Too many lines in mountlist.. ABORTING");
     997                finish(1);
     998            }
     999            for (j = 0;
     1000                 j < items
     1001                 && strcmp(mountlist->el[j].device,
     1002                           mountlist->el[items].device); j++);
     1003            if (j < items) {
     1004                strcat(mountlist->el[items].device, "_dup");
     1005                sprintf(tmp,
     1006                        "Duplicate entry in mountlist - renaming to %s",
     1007                        mountlist->el[items].device);
     1008                log_it(tmp);
     1009            }
     1010            strcpy(tmp, mountlist->el[items].device);
     1011            if (strstr(tmp, "/dev/md/")) {
     1012                log_it("format_device() --- Contracting %s", tmp);
     1013                p = strrchr(tmp, '/');
     1014                if (p) {
     1015                    *p = *(p + 1);
     1016                    *(p + 1) = *(p + 2);
     1017                    *(p + 2) = *(p + 3);
     1018                }
     1019                log_it("It was %s; it is now %s",
     1020                       mountlist->el[items].device, tmp);
     1021                strcpy(mountlist->el[items].device, tmp);
     1022            }
     1023
     1024            sprintf(tmp,
     1025                    "%s %s %s %lld %s",
     1026                    mountlist->el[items].device,
     1027                    mountlist->el[items].mountpoint,
     1028                    mountlist->el[items].format,
     1029                    mountlist->el[items].size, mountlist->el[items].label);
     1030
     1031            log_it(tmp);
     1032            items++;
     1033        }
     1034        (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     1035    }
     1036    paranoid_fclose(fin);
     1037    mountlist->entries = items;
     1038
     1039    log_it("Mountlist loaded successfully.");
     1040    sprintf(tmp, "%d entries in mountlist", items);
     1041    log_it(tmp);
     1042    paranoid_free(incoming);
     1043    paranoid_free(siz);
     1044    paranoid_free(tmp);
     1045    return (0);
    11171046}
    11181047
     
    11261055 * @see load_mountlist
    11271056 */
    1128 int
    1129 save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname)
    1130 {
    1131   FILE *fout;
    1132   int i;
    1133 
    1134   assert(mountlist!=NULL);
    1135   assert_string_is_neither_NULL_nor_zerolength(fname);
    1136 
    1137   log_it("save_mountlist_to_disk() --- saving to %s", fname);
    1138   if (!(fout=fopen(fname,"w")))
    1139     {
    1140       log_OS_error("WMTD - Cannot openout mountlist");
    1141       return(1);
    1142     }
    1143   for( i = 0; i < mountlist->entries; i++)
    1144     {
    1145       fprintf(fout,
    1146           "%-15s %-15s %-15s %-15lld %-15s\n",mountlist->el[i].device,
    1147           mountlist->el[i].mountpoint,
    1148           mountlist->el[i].format,
    1149           mountlist->el[i].size,
    1150           mountlist->el[i].label);
    1151     }
    1152   paranoid_fclose(fout);
    1153   return(0);
     1057int save_mountlist_to_disk(struct mountlist_itself *mountlist, char *fname)
     1058{
     1059    FILE *fout;
     1060    int i;
     1061
     1062    assert(mountlist != NULL);
     1063    assert_string_is_neither_NULL_nor_zerolength(fname);
     1064
     1065    log_it("save_mountlist_to_disk() --- saving to %s", fname);
     1066    if (!(fout = fopen(fname, "w"))) {
     1067        log_OS_error("WMTD - Cannot openout mountlist");
     1068        return (1);
     1069    }
     1070    for (i = 0; i < mountlist->entries; i++) {
     1071        fprintf(fout,
     1072                "%-15s %-15s %-15s %-15lld %-15s\n",
     1073                mountlist->el[i].device, mountlist->el[i].mountpoint,
     1074                mountlist->el[i].format, mountlist->el[i].size,
     1075                mountlist->el[i].label);
     1076    }
     1077    paranoid_fclose(fout);
     1078    return (0);
    11541079}
    11551080
     
    11611086 * @param mountlist The mountlist to sort.
    11621087 */
    1163 void
    1164 sort_mountlist_by_device( struct mountlist_itself *mountlist)
    1165 {
    1166   int diff;
    1167   int lino = -999;
    1168 
    1169   assert(mountlist!=NULL);
    1170 
    1171   while (lino < mountlist->entries)
    1172     {
    1173       for(lino = 1; lino < mountlist->entries; lino++)
    1174     {
    1175       diff = strcmp_inc_numbers(mountlist->el[lino-1].device,mountlist->el[lino].device);
    1176       if (diff > 0)
    1177         {
    1178           swap_mountlist_entries( mountlist, lino - 1, lino);
    1179           break;
    1180         }
    1181     }
    1182     }
     1088void sort_mountlist_by_device(struct mountlist_itself *mountlist)
     1089{
     1090    int diff;
     1091    int lino = -999;
     1092
     1093    assert(mountlist != NULL);
     1094
     1095    while (lino < mountlist->entries) {
     1096        for (lino = 1; lino < mountlist->entries; lino++) {
     1097            diff =
     1098                strcmp_inc_numbers(mountlist->el[lino - 1].device,
     1099                                   mountlist->el[lino].device);
     1100            if (diff > 0) {
     1101                swap_mountlist_entries(mountlist, lino - 1, lino);
     1102                break;
     1103            }
     1104        }
     1105    }
    11831106}
    11841107
     
    11891112 * @param reverse If TRUE, then do a reverse sort.
    11901113 */
    1191 void 
    1192 sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, bool reverse)
    1193 {
    1194   int diff;
    1195   int lino = -999;
    1196 
    1197   assert(mountlist!=NULL);
    1198 
    1199   while(lino < mountlist->entries)
    1200     {
    1201       for(lino = 1; lino < mountlist->entries; lino++)
    1202     {
    1203       diff = strcmp( mountlist->el[lino-1].mountpoint,mountlist->el[lino].mountpoint);
    1204       if ((diff >0 && !reverse) || ((diff <0 && reverse)))
    1205         {
    1206           swap_mountlist_entries(mountlist, lino - 1, lino);
    1207           break;
    1208         }
    1209     }
    1210     }
     1114void
     1115sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist,
     1116                             bool reverse)
     1117{
     1118    int diff;
     1119    int lino = -999;
     1120
     1121    assert(mountlist != NULL);
     1122
     1123    while (lino < mountlist->entries) {
     1124        for (lino = 1; lino < mountlist->entries; lino++) {
     1125            diff =
     1126                strcmp(mountlist->el[lino - 1].mountpoint,
     1127                       mountlist->el[lino].mountpoint);
     1128            if ((diff > 0 && !reverse) || ((diff < 0 && reverse))) {
     1129                swap_mountlist_entries(mountlist, lino - 1, lino);
     1130                break;
     1131            }
     1132        }
     1133    }
    12111134}
    12121135
     
    12181141 * @param b The index number of the second entry.
    12191142 */
    1220 void 
     1143void
    12211144swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b)
    12221145{
    1223   /*@ mallocs ****/
    1224   char device[64];
    1225   char mountpoint[256];
    1226   char format[64];
    1227 
    1228   long long size;
    1229 
    1230   assert(mountlist!=NULL);
    1231   assert(a>=0);
    1232   assert(b>=0);
    1233 
    1234   strcpy(device,                    mountlist->el[a].device);
    1235   strcpy(mountpoint,                mountlist->el[a].mountpoint);
    1236   strcpy(format,                    mountlist->el[a].format);
    1237 
    1238   size=                              mountlist->el[a].size;
    1239 
    1240   strcpy(mountlist->el[a].device,    mountlist->el[b].device);
    1241   strcpy(mountlist->el[a].mountpoint,mountlist->el[b].mountpoint);
    1242   strcpy(mountlist->el[a].format,    mountlist->el[b].format);
    1243 
    1244   mountlist->el[a].size=            mountlist->el[b].size;
    1245 
    1246   strcpy(mountlist->el[b].device,    device);
    1247   strcpy(mountlist->el[b].mountpoint,mountpoint);
    1248   strcpy(mountlist->el[b].format,    format);
    1249 
    1250   mountlist->el[b].size=            size;
     1146    /*@ mallocs *** */
     1147    char device[64];
     1148    char mountpoint[256];
     1149    char format[64];
     1150
     1151    long long size;
     1152
     1153    assert(mountlist != NULL);
     1154    assert(a >= 0);
     1155    assert(b >= 0);
     1156
     1157    strcpy(device, mountlist->el[a].device);
     1158    strcpy(mountpoint, mountlist->el[a].mountpoint);
     1159    strcpy(format, mountlist->el[a].format);
     1160
     1161    size = mountlist->el[a].size;
     1162
     1163    strcpy(mountlist->el[a].device, mountlist->el[b].device);
     1164    strcpy(mountlist->el[a].mountpoint, mountlist->el[b].mountpoint);
     1165    strcpy(mountlist->el[a].format, mountlist->el[b].format);
     1166
     1167    mountlist->el[a].size = mountlist->el[b].size;
     1168
     1169    strcpy(mountlist->el[b].device, device);
     1170    strcpy(mountlist->el[b].mountpoint, mountpoint);
     1171    strcpy(mountlist->el[b].format, format);
     1172
     1173    mountlist->el[b].size = size;
    12511174}
    12521175
  • branches/2.05/mondo/mondo/common/libmondo-mountlist.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-raid-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-raid.c

    r30 r128  
    11/* libmondo-raid.c                                                subroutines for handling RAID
    2    $Id: libmondo-raid.c,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33.
    44
     
    5151#ifdef __FreeBSD__
    5252/* Nonstandard library functions: */
    53 extern void errx (int exitval, const char *fmt, ...);
    54 extern char *strsep (char **stringp, const char *delim);
     53extern void errx(int exitval, const char *fmt, ...);
     54extern char *strsep(char **stringp, const char *delim);
    5555#endif
    5656
    5757/*@unused@*/
    58 //static char cvsid[] = "$Id: libmondo-raid.c,v 1.2 2004/06/10 15:29:12 hugo Exp $";
     58//static char cvsid[] = "$Id$";
    5959
    6060
     
    6969 * @return TRUE if it's supported, FALSE if not.
    7070 */
    71 bool
    72 is_this_raid_personality_registered (int raidno)
     71bool is_this_raid_personality_registered(int raidno)
    7372{
    7473#ifdef __FreeBSD__
    75   return ((raidno == -1) || (raidno == 0) || (raidno == 1) || (raidno == 5)) ? TRUE : FALSE;
     74    return ((raidno == -1) || (raidno == 0) || (raidno == 1)
     75            || (raidno == 5)) ? TRUE : FALSE;
    7676#else
    77     /*@ buffer ***********************************************************/
    78   char *command;
    79   int res;
    80  
    81   command = malloc(MAX_STR_LEN*2);
    82   strcpy (command, "cat /proc/mdstat | grep \"");
    83   if (raidno == -1)
    84     {
    85       strcat (command, "linear");
    86     }
    87   else
    88     {
    89       sprintf (command + strlen (command), "raid%d", raidno);
    90     }
    91   strcat (command, "\" > /dev/null 2> /dev/null");
    92   log_it ("Is raid %d registered? Command = '%s'", raidno, command);
    93   res = system (command);
    94   paranoid_free(command);
    95   if (res)
    96     {
    97       return (FALSE);
    98     }
    99   else
    100     {
    101       return (TRUE);
    102     }
     77    /*@ buffer ********************************************************** */
     78    char *command;
     79    int res;
     80
     81    command = malloc(MAX_STR_LEN * 2);
     82    strcpy(command, "cat /proc/mdstat | grep \"");
     83    if (raidno == -1) {
     84        strcat(command, "linear");
     85    } else {
     86        sprintf(command + strlen(command), "raid%d", raidno);
     87    }
     88    strcat(command, "\" > /dev/null 2> /dev/null");
     89    log_it("Is raid %d registered? Command = '%s'", raidno, command);
     90    res = system(command);
     91    paranoid_free(command);
     92    if (res) {
     93        return (FALSE);
     94    } else {
     95        return (TRUE);
     96    }
    10397#endif
    10498}
     
    116110 */
    117111int
    118 where_in_drivelist_is_drive (struct list_of_disks *disklist, char *device)
    119 {
    120 
    121     /*@ int **************************************************************/
    122   int i = 0;
    123 
    124   assert(disklist!=NULL);
    125   assert_string_is_neither_NULL_nor_zerolength(device);
    126 
    127   for (i = 0; i < disklist->entries; i++)
    128     {
    129       if (!strcmp (disklist->el[i].device, device))
    130     {
    131       break;
    132     }
    133     }
    134   if (i == disklist->entries)
    135     {
    136       return (-1);
    137     }
    138   else
    139     {
    140       return (i);
    141     }
     112where_in_drivelist_is_drive(struct list_of_disks *disklist, char *device)
     113{
     114
     115    /*@ int ************************************************************* */
     116    int i = 0;
     117
     118    assert(disklist != NULL);
     119    assert_string_is_neither_NULL_nor_zerolength(device);
     120
     121    for (i = 0; i < disklist->entries; i++) {
     122        if (!strcmp(disklist->el[i].device, device)) {
     123            break;
     124        }
     125    }
     126    if (i == disklist->entries) {
     127        return (-1);
     128    } else {
     129        return (i);
     130    }
    142131}
    143132
     
    156145 */
    157146int
    158 which_raid_device_is_using_this_partition (struct raidlist_itself *raidlist,
    159                        char *device)
     147which_raid_device_is_using_this_partition(struct raidlist_itself *raidlist,
     148                                          char *device)
    160149{
    161150#ifdef __FreeBSD__
    162151// FreeBSD-specific version of which_raid_device_is_using_this_partition()
    163     /*@ int **********************************************************/
    164   int i = 0;
    165 
    166   for (i = 0; i < raidlist->entries; i++)
    167     {
    168     bool thisone = FALSE;
    169     int j, k, l;
    170    
    171     for (j = 0; j < raidlist->el[i].plexes; ++j) {
    172         for (k = 0; k < raidlist->el[i].plex[j].subdisks; ++k) {
    173         for (l = 0; l < raidlist->disks.entries; ++l) {
    174             if (!strcmp (raidlist->disks.el[l].device,
    175                  device) &&
    176             !strcmp (raidlist->el[i].plex[j].sd[k].which_device,
    177                  raidlist->disks.el[l].name))
    178             thisone = TRUE;
    179         }
    180         }
    181     }
    182    
    183     if (thisone)
    184     {
    185       break;
    186     }
    187     }
    188   if (i == raidlist->entries)
    189     {
    190       return (-1);
    191     }
    192   else
    193     {
    194       return (i);
    195     }
     152    /*@ int ********************************************************* */
     153    int i = 0;
     154
     155    for (i = 0; i < raidlist->entries; i++) {
     156        bool thisone = FALSE;
     157        int j, k, l;
     158
     159        for (j = 0; j < raidlist->el[i].plexes; ++j) {
     160            for (k = 0; k < raidlist->el[i].plex[j].subdisks; ++k) {
     161                for (l = 0; l < raidlist->disks.entries; ++l) {
     162                    if (!strcmp(raidlist->disks.el[l].device,
     163                                device) &&
     164                        !strcmp(raidlist->el[i].plex[j].sd[k].which_device,
     165                                raidlist->disks.el[l].name))
     166                        thisone = TRUE;
     167                }
     168            }
     169        }
     170
     171        if (thisone) {
     172            break;
     173        }
     174    }
     175    if (i == raidlist->entries) {
     176        return (-1);
     177    } else {
     178        return (i);
     179    }
    196180}
    197181
     
    200184// and one other function which FreeBSD doesn't use
    201185
    202   int current_raiddev = 0;
    203 
    204   assert_string_is_neither_NULL_nor_zerolength(device);
    205   assert(raidlist!=NULL);
    206 
    207   for (current_raiddev = 0; current_raiddev < raidlist->entries;
    208        current_raiddev++)
    209     {
    210       if (where_in_drivelist_is_drive
    211       (&raidlist->el[current_raiddev].data_disks, device) >= 0
    212       || where_in_drivelist_is_drive (&raidlist->el[current_raiddev].
    213                       spare_disks, device) >= 0
    214       || where_in_drivelist_is_drive (&raidlist->el[current_raiddev].
    215                       parity_disks, device) >= 0
    216       || where_in_drivelist_is_drive (&raidlist->el[current_raiddev].
    217                       failed_disks, device) >= 0)
    218     {
    219       break;
    220     }
    221     }
    222   if (current_raiddev == raidlist->entries)
    223     {
    224       return (-1);
    225     }
    226   else
    227     {
    228       return (current_raiddev);
    229     }
     186    int current_raiddev = 0;
     187
     188    assert_string_is_neither_NULL_nor_zerolength(device);
     189    assert(raidlist != NULL);
     190
     191    for (current_raiddev = 0; current_raiddev < raidlist->entries;
     192         current_raiddev++) {
     193        if (where_in_drivelist_is_drive
     194            (&raidlist->el[current_raiddev].data_disks, device) >= 0
     195            || where_in_drivelist_is_drive(&raidlist->el[current_raiddev].
     196                                           spare_disks, device) >= 0
     197            || where_in_drivelist_is_drive(&raidlist->el[current_raiddev].
     198                                           parity_disks, device) >= 0
     199            || where_in_drivelist_is_drive(&raidlist->el[current_raiddev].
     200                                           failed_disks, device) >= 0) {
     201            break;
     202        }
     203    }
     204    if (current_raiddev == raidlist->entries) {
     205        return (-1);
     206    } else {
     207        return (current_raiddev);
     208    }
    230209}
    231210
     
    238217 */
    239218void
    240 write_variableINT_to_raid_var_line (struct raid_device_record *raidrec,
    241                     int lino, char *label, int value)
    242 {
    243     /*@ buffers ******************************************************/
    244   char *sz_value;
    245 
    246   malloc_string(sz_value);
    247   assert(raidrec!=NULL);
    248   assert(label!=NULL);
    249 
    250   sprintf (sz_value, "%d", value);
    251   strcpy (raidrec->additional_vars.el[lino].label, label);
    252   strcpy (raidrec->additional_vars.el[lino].value, sz_value);
    253   paranoid_free(sz_value);
     219write_variableINT_to_raid_var_line(struct raid_device_record *raidrec,
     220                                   int lino, char *label, int value)
     221{
     222    /*@ buffers ***************************************************** */
     223    char *sz_value;
     224
     225    malloc_string(sz_value);
     226    assert(raidrec != NULL);
     227    assert(label != NULL);
     228
     229    sprintf(sz_value, "%d", value);
     230    strcpy(raidrec->additional_vars.el[lino].label, label);
     231    strcpy(raidrec->additional_vars.el[lino].value, sz_value);
     232    paranoid_free(sz_value);
    254233}
    255234#endif
     
    268247 * @param device_to_add The device to add to @p p.
    269248 */
    270 void add_disk_to_raid_device(struct vinum_plex *p, char*device_to_add)
    271 {
    272     strcpy (p->sd[p->subdisks].which_device, device_to_add);
    273     ++p->subdisks;
     249void add_disk_to_raid_device(struct vinum_plex *p, char *device_to_add)
     250{
     251    strcpy(p->sd[p->subdisks].which_device, device_to_add);
     252    ++p->subdisks;
    274253
    275254}
     
    281260 * @param index The index number of the disklist entry we're creating.
    282261 */
    283 void add_disk_to_raid_device(struct list_of_disks *disklist, char*device_to_add, int index)
    284 {
    285   int items;
    286 
    287   assert(disklist!=NULL);
    288   assert_string_is_neither_NULL_nor_zerolength(device_to_add);
    289   items = disklist->entries;
    290   strcpy( disklist->el[items].device, device_to_add );
    291   disklist->el[items].index = index;
    292   items++;
    293   disklist->entries = items;
     262void add_disk_to_raid_device(struct list_of_disks *disklist,
     263                             char *device_to_add, int index)
     264{
     265    int items;
     266
     267    assert(disklist != NULL);
     268    assert_string_is_neither_NULL_nor_zerolength(device_to_add);
     269    items = disklist->entries;
     270    strcpy(disklist->el[items].device, device_to_add);
     271    disklist->el[items].index = index;
     272    items++;
     273    disklist->entries = items;
    294274}
    295275#endif
     
    301281 * @param fout The FILE pointer to save them to.
    302282 */
    303 void
    304 save_additional_vars_to_file(struct additional_raid_variables *vars, FILE *fout)
    305 {
    306   int i;
    307 
    308   assert(vars!=NULL);
    309   assert(fout!=NULL);
    310 
    311   for(i = 0; i < vars->entries; i++ )
    312     {
    313       fprintf(fout,"    %-21s %s\n",vars->el[i].label, vars->el[i].value);
    314     }
     283void
     284save_additional_vars_to_file(struct additional_raid_variables *vars,
     285                             FILE * fout)
     286{
     287    int i;
     288
     289    assert(vars != NULL);
     290    assert(fout != NULL);
     291
     292    for (i = 0; i < vars->entries; i++) {
     293        fprintf(fout, "    %-21s %s\n", vars->el[i].label,
     294                vars->el[i].value);
     295    }
    315296}
    316297
     
    323304 * @bug Return value is redundant.
    324305 */
    325 int
    326 save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char *fname)
    327 {
    328   FILE *fout;
    329   int current_raid_device;
     306int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char *fname)
     307{
     308    FILE *fout;
     309    int current_raid_device;
    330310#ifdef __FreeBSD__
    331   int i;
     311    int i;
    332312#else
    333313// Linux
    334314#endif
    335315
    336   assert(raidlist!=NULL);
    337   assert_string_is_neither_NULL_nor_zerolength(fname);
    338 
    339   if (raidlist->entries <= 0)
    340     {
    341       unlink(fname);
    342       log_it("Deleting raidtab (no RAID devs anyway)");
    343       return(0);
    344     }
    345   if (!(fout=fopen(fname,"w")))
    346     {
    347       log_OS_error("Failed to save raidlist");return(1);
    348     }
    349     fprintf (fout, "# Generated by Mondo Rescue\n");
     316    assert(raidlist != NULL);
     317    assert_string_is_neither_NULL_nor_zerolength(fname);
     318
     319    if (raidlist->entries <= 0) {
     320        unlink(fname);
     321        log_it("Deleting raidtab (no RAID devs anyway)");
     322        return (0);
     323    }
     324    if (!(fout = fopen(fname, "w"))) {
     325        log_OS_error("Failed to save raidlist");
     326        return (1);
     327    }
     328    fprintf(fout, "# Generated by Mondo Rescue\n");
    350329
    351330#ifdef __FreeBSD__
    352     for (i = 0; i < raidlist->disks.entries; ++i) {
    353     fprintf (fout, "drive %s device %s\n", raidlist->disks.el[i].name, raidlist->disks.el[i].device);
    354     }
    355     for (i = 0; i < (raidlist->spares.entries); ++i) {
    356     fprintf (fout, "drive %s device %s hotspare\n", raidlist->spares.el[i].name, raidlist->spares.el[i].device);
    357     }
     331    for (i = 0; i < raidlist->disks.entries; ++i) {
     332        fprintf(fout, "drive %s device %s\n", raidlist->disks.el[i].name,
     333                raidlist->disks.el[i].device);
     334    }
     335    for (i = 0; i < (raidlist->spares.entries); ++i) {
     336        fprintf(fout, "drive %s device %s hotspare\n",
     337                raidlist->spares.el[i].name,
     338                raidlist->spares.el[i].device);
     339    }
    358340#endif
    359341
    360   for(current_raid_device = 0; current_raid_device < raidlist->entries; current_raid_device++ )
    361     {
    362       save_raidrec_to_file(&raidlist->el[current_raid_device],fout);
    363     }
    364   paranoid_fclose(fout);
    365   return(0);
     342    for (current_raid_device = 0; current_raid_device < raidlist->entries;
     343         current_raid_device++) {
     344        save_raidrec_to_file(&raidlist->el[current_raid_device], fout);
     345    }
     346    paranoid_fclose(fout);
     347    return (0);
    366348}
    367349
     
    372354 * @param fout The stream to save it to.
    373355 */
    374 void
    375 save_raidrec_to_file( struct
     356void save_raidrec_to_file(struct
    376357#ifdef __FreeBSD__
    377 vinum_volume
     358                          vinum_volume
    378359#else
    379 raid_device_record
     360                          raid_device_record
    380361#endif
    381 *raidrec, FILE *fout )
     362                          * raidrec, FILE * fout)
    382363{
    383364#ifdef __FreeBSD__
    384     int i, j;
    385 
    386     fprintf (fout, "\nvolume %s\n", raidrec->volname);
    387     for (i = 0; i < raidrec->plexes; ++i) {
    388     char org[24];
    389     switch (raidrec->plex[i].raidlevel) {
    390     case -1: strcpy (org, "concat"); break;
    391     case 0:  strcpy (org, "striped"); break;
    392     case 5:  strcpy (org, "raid5"); break;
    393     }
    394     fprintf (fout, "  plex org %s", org);
    395     if (raidrec->plex[i].raidlevel != -1) {
    396         fprintf (fout, " %ik", raidrec->plex[i].stripesize);
    397     }
    398     fprintf (fout, "\n");
    399    
    400     for (j = 0; j < raidrec->plex[i].subdisks; ++j) {
    401         fprintf (fout, "    sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device);
    402     }
    403     }
     365    int i, j;
     366
     367    fprintf(fout, "\nvolume %s\n", raidrec->volname);
     368    for (i = 0; i < raidrec->plexes; ++i) {
     369        char org[24];
     370        switch (raidrec->plex[i].raidlevel) {
     371        case -1:
     372            strcpy(org, "concat");
     373            break;
     374        case 0:
     375            strcpy(org, "striped");
     376            break;
     377        case 5:
     378            strcpy(org, "raid5");
     379            break;
     380        }
     381        fprintf(fout, "  plex org %s", org);
     382        if (raidrec->plex[i].raidlevel != -1) {
     383            fprintf(fout, " %ik", raidrec->plex[i].stripesize);
     384        }
     385        fprintf(fout, "\n");
     386
     387        for (j = 0; j < raidrec->plex[i].subdisks; ++j) {
     388            fprintf(fout, "    sd drive %s size 0\n",
     389                    raidrec->plex[i].sd[j].which_device);
     390        }
     391    }
    404392#else
    405   assert(raidrec!=NULL);
    406   assert(fout!=NULL);
    407 
    408   fprintf(fout,"raiddev %s\n",raidrec->raid_device);
    409   if (raidrec->raid_level == -1 )
    410     {
    411       fprintf(fout,"    raid-level            linear\n");
    412     }
    413   else
    414     {
    415       fprintf(fout,"    raid-level            %d\n",raidrec->raid_level);
    416     }
    417   fprintf(fout,"    chunk-size            %d\n",raidrec->chunk_size);
    418   fprintf(fout,"    nr-raid-disks         %d\n",raidrec->data_disks.entries);
    419   fprintf(fout,"    nr-spare-disks        %d\n",raidrec->spare_disks.entries);
    420   if (raidrec->parity_disks.entries > 0)
    421     {
    422       fprintf(fout,"    nr-parity-disks       %d\n",raidrec->parity_disks.entries);
    423     }
    424 
    425   fprintf(fout,"    persistent-superblock %d\n",raidrec->persistent_superblock);
    426   save_additional_vars_to_file(&raidrec->additional_vars,fout);
    427   fprintf(fout,"\n");
    428   save_disklist_to_file("raid-disk", &raidrec->data_disks, fout);
    429   save_disklist_to_file("spare-disk", &raidrec->spare_disks, fout);
    430   save_disklist_to_file("parity-disk", &raidrec->parity_disks, fout);
    431   save_disklist_to_file("failed-disk", &raidrec->failed_disks, fout);
    432   fprintf(fout,"\n");
     393    assert(raidrec != NULL);
     394    assert(fout != NULL);
     395
     396    fprintf(fout, "raiddev %s\n", raidrec->raid_device);
     397    if (raidrec->raid_level == -1) {
     398        fprintf(fout, "    raid-level            linear\n");
     399    } else {
     400        fprintf(fout, "    raid-level            %d\n",
     401                raidrec->raid_level);
     402    }
     403    fprintf(fout, "    chunk-size            %d\n", raidrec->chunk_size);
     404    fprintf(fout, "    nr-raid-disks         %d\n",
     405            raidrec->data_disks.entries);
     406    fprintf(fout, "    nr-spare-disks        %d\n",
     407            raidrec->spare_disks.entries);
     408    if (raidrec->parity_disks.entries > 0) {
     409        fprintf(fout, "    nr-parity-disks       %d\n",
     410                raidrec->parity_disks.entries);
     411    }
     412
     413    fprintf(fout, "    persistent-superblock %d\n",
     414            raidrec->persistent_superblock);
     415    save_additional_vars_to_file(&raidrec->additional_vars, fout);
     416    fprintf(fout, "\n");
     417    save_disklist_to_file("raid-disk", &raidrec->data_disks, fout);
     418    save_disklist_to_file("spare-disk", &raidrec->spare_disks, fout);
     419    save_disklist_to_file("parity-disk", &raidrec->parity_disks, fout);
     420    save_disklist_to_file("failed-disk", &raidrec->failed_disks, fout);
     421    fprintf(fout, "\n");
    433422#endif
    434423}
     
    441430 * @return 0 if the line was read and stored successfully, 1 if we're at end of file.
    442431 */
    443 int
    444 get_next_raidtab_line( FILE *fin, char *label, char *value )
    445 {
    446   char *incoming;
    447   char *p;
    448 
    449   malloc_string(incoming);
    450   assert(fin!=NULL);
    451   assert(label!=NULL);
    452   assert(value!=NULL);
    453 
    454   label[0] = value[0]= '\0';
    455   if ( feof(fin) )
    456     {
    457       paranoid_free(incoming);
    458       return( 1 );
    459     }
    460   for( fgets(incoming, MAX_STR_LEN - 1, fin ); !feof( fin ); fgets(incoming, MAX_STR_LEN - 1, fin ) )
    461     {
    462       strip_spaces( incoming );
    463       p = strchr( incoming,' ' );
    464       if ( strlen( incoming ) < 3 || incoming[0] == '#' || !p)
    465     {
    466       continue;
    467     }
    468       *(p++) = '\0';
    469       while(*p==' ') { p++; }
    470       strcpy( label, incoming );
    471       strcpy( value, p );
    472       paranoid_free(incoming);
    473       return( 0 );
    474     }
    475   return( 1 );
     432int get_next_raidtab_line(FILE * fin, char *label, char *value)
     433{
     434    char *incoming;
     435    char *p;
     436
     437    malloc_string(incoming);
     438    assert(fin != NULL);
     439    assert(label != NULL);
     440    assert(value != NULL);
     441
     442    label[0] = value[0] = '\0';
     443    if (feof(fin)) {
     444        paranoid_free(incoming);
     445        return (1);
     446    }
     447    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     448         fgets(incoming, MAX_STR_LEN - 1, fin)) {
     449        strip_spaces(incoming);
     450        p = strchr(incoming, ' ');
     451        if (strlen(incoming) < 3 || incoming[0] == '#' || !p) {
     452            continue;
     453        }
     454        *(p++) = '\0';
     455        while (*p == ' ') {
     456            p++;
     457        }
     458        strcpy(label, incoming);
     459        strcpy(value, p);
     460        paranoid_free(incoming);
     461        return (0);
     462    }
     463    return (1);
    476464}
    477465
     
    485473 */
    486474#ifdef __FreeBSD__
    487 int load_raidtab_into_raidlist( struct raidlist_itself *raidlist, char *fname)
    488 {
    489   FILE*fin;
    490   char *tmp;
    491   int items;
    492  
    493   malloc_string(tmp);
    494   raidlist->spares.entries = 0;
    495   raidlist->disks.entries  = 0;
    496   if (length_of_file(fname)<5)
    497     {
    498       log_it("Raidtab is very small or non-existent. Ignoring it.");
    499       raidlist->entries=0;
    500       paranoid_free(tmp);
    501       return(0);
    502     }
    503   if (!(fin=fopen(fname,"r")))
    504     {
    505       log_it("Cannot open raidtab");
    506       paranoid_free(tmp);
    507       return(1);
    508     }
    509   items=0;
    510   log_it("Loading raidtab...");
    511   while(!feof(fin))
    512     {
    513     int argc;
    514     char **argv = get_next_vinum_conf_line (fin, &argc);
    515     if (!argv) break;
    516     if (!strcmp (argv[0], "drive")) {
    517         char *drivename, *devname;
    518         if (argc < 4) continue;
    519         drivename   = argv[1];
    520         devname     = get_option_val (argc, argv, "device");
    521         if (!devname) continue;
    522 
    523         if (get_option_state (argc, argv, "hotspare")) {
    524         strcpy (raidlist->spares.el [raidlist->spares.entries].name, drivename);
    525         strcpy (raidlist->spares.el [raidlist->spares.entries].device, devname);
    526         raidlist->spares.el [raidlist->spares.entries].index  = raidlist->disks.entries;
    527         raidlist->spares.entries++;
    528         } else {
    529         strcpy (raidlist->disks.el [raidlist->disks.entries].name, drivename);
    530         strcpy (raidlist->disks.el [raidlist->disks.entries].device, devname);
    531         raidlist->disks.el [raidlist->disks.entries].index   = raidlist->disks.entries;
    532         raidlist->disks.entries++;
    533         }
    534     }
    535     else if (!strcmp (argv[0], "volume")) {
    536         char *volname;
    537         if (argc < 2) continue;
    538         volname = argv[1];
    539         strcpy (raidlist->el [raidlist->entries].volname, volname);
    540         raidlist->el [raidlist->entries].plexes = 0;
    541         raidlist->entries++;
    542     }
    543     else if (!strcmp (argv[0], "plex")) {
    544         int raidlevel, stripesize;
    545         char *org   = 0;
    546         char ** tmp = 0;
    547         if (argc < 3) continue;
    548         org = get_option_val (argc, argv, "org");
    549         if (!org) continue;
    550         if (strcmp (org, "concat")) {
    551         tmp = get_option_vals (argc, argv, "org", 2);
    552         if (tmp && tmp[1]) {
    553             stripesize = (int) (size_spec (tmp[1]) / 1024);
    554         }
    555         else stripesize = 279;
    556         }
    557         else stripesize = 0;
    558 
    559         if (!strcmp (org, "concat")) {
    560         raidlevel = -1;
    561         }
    562         else if (!strcmp (org, "striped")) {
    563         raidlevel = 0;
    564         }
    565         else if (!strcmp (org, "raid5")) {
    566         raidlevel = 5;
    567         }
    568         else continue;
    569 
    570         raidlist->el[raidlist->entries - 1].plex
    571         [raidlist->el [raidlist->entries - 1].plexes].raidlevel = raidlevel;
    572         raidlist->el[raidlist->entries - 1].plex
    573         [raidlist->el [raidlist->entries - 1].plexes].stripesize = stripesize;
    574         raidlist->el[raidlist->entries - 1].plex
    575         [raidlist->el [raidlist->entries - 1].plexes].subdisks = 0;
    576         raidlist->el[raidlist->entries - 1].plexes++;
    577     }
    578     else if ((!strcmp (argv[0], "sd")) || (!strcmp (argv[0], "subdisk"))) {
    579         char *drive = 0;
    580         if (argc < 3) continue;
    581         drive = get_option_val (argc, argv, "drive");
    582         if (!drive) continue;
    583        
    584         strcpy (raidlist->el [raidlist->entries - 1].plex
    585             [raidlist->el [raidlist->entries - 1].plexes - 1].sd
    586             [raidlist->el [raidlist->entries - 1].plex
    587              [raidlist->el [raidlist->entries - 1].plexes - 1].subdisks].which_device, drive);
    588         raidlist->el [raidlist->entries - 1].plex
    589         [raidlist->el [raidlist->entries - 1].plexes - 1].subdisks++;
    590     }
    591     }
    592   fclose(fin);
    593   log_it("Raidtab loaded successfully.");
    594   sprintf(tmp,"%d RAID devices in raidtab", raidlist->entries);
    595   log_it(tmp);
    596   paranoid_free(tmp);
    597   return(0);
     475int load_raidtab_into_raidlist(struct raidlist_itself *raidlist,
     476                               char *fname)
     477{
     478    FILE *fin;
     479    char *tmp;
     480    int items;
     481
     482    malloc_string(tmp);
     483    raidlist->spares.entries = 0;
     484    raidlist->disks.entries = 0;
     485    if (length_of_file(fname) < 5) {
     486        log_it("Raidtab is very small or non-existent. Ignoring it.");
     487        raidlist->entries = 0;
     488        paranoid_free(tmp);
     489        return (0);
     490    }
     491    if (!(fin = fopen(fname, "r"))) {
     492        log_it("Cannot open raidtab");
     493        paranoid_free(tmp);
     494        return (1);
     495    }
     496    items = 0;
     497    log_it("Loading raidtab...");
     498    while (!feof(fin)) {
     499        int argc;
     500        char **argv = get_next_vinum_conf_line(fin, &argc);
     501        if (!argv)
     502            break;
     503        if (!strcmp(argv[0], "drive")) {
     504            char *drivename, *devname;
     505            if (argc < 4)
     506                continue;
     507            drivename = argv[1];
     508            devname = get_option_val(argc, argv, "device");
     509            if (!devname)
     510                continue;
     511
     512            if (get_option_state(argc, argv, "hotspare")) {
     513                strcpy(raidlist->spares.el[raidlist->spares.entries].name,
     514                       drivename);
     515                strcpy(raidlist->spares.el[raidlist->spares.entries].
     516                       device, devname);
     517                raidlist->spares.el[raidlist->spares.entries].index =
     518                    raidlist->disks.entries;
     519                raidlist->spares.entries++;
     520            } else {
     521                strcpy(raidlist->disks.el[raidlist->disks.entries].name,
     522                       drivename);
     523                strcpy(raidlist->disks.el[raidlist->disks.entries].device,
     524                       devname);
     525                raidlist->disks.el[raidlist->disks.entries].index =
     526                    raidlist->disks.entries;
     527                raidlist->disks.entries++;
     528            }
     529        } else if (!strcmp(argv[0], "volume")) {
     530            char *volname;
     531            if (argc < 2)
     532                continue;
     533            volname = argv[1];
     534            strcpy(raidlist->el[raidlist->entries].volname, volname);
     535            raidlist->el[raidlist->entries].plexes = 0;
     536            raidlist->entries++;
     537        } else if (!strcmp(argv[0], "plex")) {
     538            int raidlevel, stripesize;
     539            char *org = 0;
     540            char **tmp = 0;
     541            if (argc < 3)
     542                continue;
     543            org = get_option_val(argc, argv, "org");
     544            if (!org)
     545                continue;
     546            if (strcmp(org, "concat")) {
     547                tmp = get_option_vals(argc, argv, "org", 2);
     548                if (tmp && tmp[1]) {
     549                    stripesize = (int) (size_spec(tmp[1]) / 1024);
     550                } else
     551                    stripesize = 279;
     552            } else
     553                stripesize = 0;
     554
     555            if (!strcmp(org, "concat")) {
     556                raidlevel = -1;
     557            } else if (!strcmp(org, "striped")) {
     558                raidlevel = 0;
     559            } else if (!strcmp(org, "raid5")) {
     560                raidlevel = 5;
     561            } else
     562                continue;
     563
     564            raidlist->el[raidlist->entries - 1].plex
     565                [raidlist->el[raidlist->entries - 1].plexes].raidlevel =
     566                raidlevel;
     567            raidlist->el[raidlist->entries -
     568                         1].plex[raidlist->el[raidlist->entries -
     569                                              1].plexes].stripesize =
     570                stripesize;
     571            raidlist->el[raidlist->entries -
     572                         1].plex[raidlist->el[raidlist->entries -
     573                                              1].plexes].subdisks = 0;
     574            raidlist->el[raidlist->entries - 1].plexes++;
     575        } else if ((!strcmp(argv[0], "sd"))
     576                   || (!strcmp(argv[0], "subdisk"))) {
     577            char *drive = 0;
     578            if (argc < 3)
     579                continue;
     580            drive = get_option_val(argc, argv, "drive");
     581            if (!drive)
     582                continue;
     583
     584            strcpy(raidlist->el[raidlist->entries - 1].plex
     585                   [raidlist->el[raidlist->entries - 1].plexes - 1].sd
     586                   [raidlist->el[raidlist->entries - 1].plex
     587                    [raidlist->el[raidlist->entries - 1].plexes -
     588                     1].subdisks].which_device, drive);
     589            raidlist->el[raidlist->entries -
     590                         1].plex[raidlist->el[raidlist->entries -
     591                                              1].plexes - 1].subdisks++;
     592        }
     593    }
     594    fclose(fin);
     595    log_it("Raidtab loaded successfully.");
     596    sprintf(tmp, "%d RAID devices in raidtab", raidlist->entries);
     597    log_it(tmp);
     598    paranoid_free(tmp);
     599    return (0);
    598600}
    599601
     
    601603#else
    602604
    603 int load_raidtab_into_raidlist( struct raidlist_itself *raidlist, char *fname)
    604 
    605 {
    606   FILE *fin;
    607   char *tmp;
    608   char *label;
    609   char *value;
    610   int items;
    611   int v;
    612 
    613   malloc_string(tmp);
    614   malloc_string(label);
    615   malloc_string(value);
    616   assert(raidlist!=NULL);
    617   assert_string_is_neither_NULL_nor_zerolength(fname);
    618 
    619   if ( length_of_file( fname ) < 5 )
    620     {
    621       log_it( "Raidtab is very small or non-existent. Ignoring it." );
    622       raidlist->entries = 0;
    623       paranoid_free(tmp);
    624       paranoid_free(label);
    625       paranoid_free(value);
    626       return( 0 );
    627     }
    628   if ( !( fin = fopen( fname, "r" ) ) )
    629     {
    630       log_it( "Cannot open raidtab" );
    631       paranoid_free(tmp);
    632       paranoid_free(label);
    633       paranoid_free(value);
    634       return( 1 );
    635     }
    636   items = 0;
    637   log_it( "Loading raidtab..." );
    638   get_next_raidtab_line( fin, label, value );
    639   while( !feof( fin ) )
    640     {
    641       log_msg(1, "Looking for raid record #%d", items);
    642       initialize_raidrec( &raidlist->el[items] );
    643       v = 0;
    644       /* find the 'raiddev' entry, indicating the start of the block of info */
    645       while( !feof( fin ) && strcmp( label, "raiddev") )
    646     {
    647       strcpy( raidlist->el[items].additional_vars.el[v].label, label );
    648       strcpy( raidlist->el[items].additional_vars.el[v].value, value );
    649       v++;
    650       get_next_raidtab_line( fin, label, value );
    651       log_it( tmp );
    652     }
    653       raidlist->el[items].additional_vars.entries = v;
    654       if ( feof( fin ) )
    655     {
    656       log_msg(1, "No more records.");
    657       continue;
    658     }
    659       log_msg(2, "Record #%d (%s) found", items, value);
    660       strcpy( raidlist->el[items].raid_device, value );
    661       for( get_next_raidtab_line( fin, label, value);
    662        !feof( fin ) && strcmp( label, "raiddev" );
    663        get_next_raidtab_line( fin, label, value ) )
    664     {
    665       process_raidtab_line( fin, &raidlist->el[items], label, value );
    666     }
    667       items++;
    668     }
    669   paranoid_fclose( fin );
    670   raidlist->entries = items;
    671   log_msg(1,  "Raidtab loaded successfully." );
    672   log_msg(1, "%d RAID devices in raidtab", items );
    673   paranoid_free(tmp);
    674   paranoid_free(label);
    675   paranoid_free(value);
    676   return( 0 );
     605int load_raidtab_into_raidlist(struct raidlist_itself *raidlist,
     606                               char *fname)
     607{
     608    FILE *fin;
     609    char *tmp;
     610    char *label;
     611    char *value;
     612    int items;
     613    int v;
     614
     615    malloc_string(tmp);
     616    malloc_string(label);
     617    malloc_string(value);
     618    assert(raidlist != NULL);
     619    assert_string_is_neither_NULL_nor_zerolength(fname);
     620
     621    if (length_of_file(fname) < 5) {
     622        log_it("Raidtab is very small or non-existent. Ignoring it.");
     623        raidlist->entries = 0;
     624        paranoid_free(tmp);
     625        paranoid_free(label);
     626        paranoid_free(value);
     627        return (0);
     628    }
     629    if (!(fin = fopen(fname, "r"))) {
     630        log_it("Cannot open raidtab");
     631        paranoid_free(tmp);
     632        paranoid_free(label);
     633        paranoid_free(value);
     634        return (1);
     635    }
     636    items = 0;
     637    log_it("Loading raidtab...");
     638    get_next_raidtab_line(fin, label, value);
     639    while (!feof(fin)) {
     640        log_msg(1, "Looking for raid record #%d", items);
     641        initialize_raidrec(&raidlist->el[items]);
     642        v = 0;
     643        /* find the 'raiddev' entry, indicating the start of the block of info */
     644        while (!feof(fin) && strcmp(label, "raiddev")) {
     645            strcpy(raidlist->el[items].additional_vars.el[v].label, label);
     646            strcpy(raidlist->el[items].additional_vars.el[v].value, value);
     647            v++;
     648            get_next_raidtab_line(fin, label, value);
     649            log_it(tmp);
     650        }
     651        raidlist->el[items].additional_vars.entries = v;
     652        if (feof(fin)) {
     653            log_msg(1, "No more records.");
     654            continue;
     655        }
     656        log_msg(2, "Record #%d (%s) found", items, value);
     657        strcpy(raidlist->el[items].raid_device, value);
     658        for (get_next_raidtab_line(fin, label, value);
     659             !feof(fin) && strcmp(label, "raiddev");
     660             get_next_raidtab_line(fin, label, value)) {
     661            process_raidtab_line(fin, &raidlist->el[items], label, value);
     662        }
     663        items++;
     664    }
     665    paranoid_fclose(fin);
     666    raidlist->entries = items;
     667    log_msg(1, "Raidtab loaded successfully.");
     668    log_msg(1, "%d RAID devices in raidtab", items);
     669    paranoid_free(tmp);
     670    paranoid_free(label);
     671    paranoid_free(value);
     672    return (0);
    677673}
    678674#endif
     
    694690 */
    695691void
    696 process_raidtab_line( FILE *fin,
    697               struct raid_device_record *raidrec,
    698               char *label,
    699               char *value)
    700 {
    701 
    702   /*@ add mallocs **/
    703   char *tmp;
    704   char *labelB;
    705   char *valueB;
    706 
    707   struct list_of_disks *disklist;
    708   int index;
    709   int  v;
    710 
    711   malloc_string(tmp);
    712   malloc_string(labelB);
    713   malloc_string(valueB);
    714   assert(fin!=NULL);
    715   assert(raidrec!=NULL);
    716   assert_string_is_neither_NULL_nor_zerolength(label);
    717   assert(value!=NULL);
    718 
    719   if (!strcmp( label, "raid-level" ) )
    720     {
    721       if (!strcmp( value, "linear" ) )
    722     { raidrec->raid_level = -1;
    723     }
    724       else
    725     {
    726       raidrec->raid_level = atoi(value);
    727     }
    728     }
    729   else if (!strcmp(label,"nr-raid-disks") )
    730     { /* ignore it */
    731     }
    732   else if (!strcmp(label,"nr-spare-disks"))
    733     { /* ignore it */
    734     }
    735   else if (!strcmp(label,"nr-parity-disks"))
    736     { /* ignore it */
    737     }
    738   else if (!strcmp(label,"nr-failed-disks"))
    739     { /* ignore it */
    740     }
    741   else if (!strcmp(label,"persistent-superblock"))
    742     {
    743       raidrec->persistent_superblock = atoi(value);
    744     }
    745   else if (!strcmp(label,"chunk-size"))
    746     {
    747       raidrec->chunk_size = atoi(value);
    748     }
    749   else if (!strcmp(label,"device"))
    750     {
    751       get_next_raidtab_line(fin,labelB,valueB);
    752       if (!strcmp(labelB,"raid-disk"))
    753     {
    754       disklist=&raidrec->data_disks;
    755     }
    756       else if (!strcmp(labelB,"spare-disk"))
    757     {
    758       disklist=&raidrec->spare_disks;
    759     }
    760       else if (!strcmp(labelB,"parity-disk"))
    761     {
    762       disklist=&raidrec->parity_disks;
    763     }
    764       else if (!strcmp(labelB,"failed-disk"))
    765     {
    766       disklist=&raidrec->failed_disks;
    767     }
    768       else
    769     {
    770       disklist=NULL;
    771     }
    772       if (!disklist)
    773     {
    774       sprintf( tmp,
    775            "Ignoring '%s %s' pair of disk %s",labelB,valueB,label);
    776       log_it(tmp);
    777     }
    778       else
    779     {
    780       index = atoi(valueB);
    781       add_disk_to_raid_device(disklist,value,index);
    782     }
    783     }
    784   else
    785     {
    786       v = raidrec->additional_vars.entries;
    787       strcpy(raidrec->additional_vars.el[v].label, label);
    788       strcpy(raidrec->additional_vars.el[v].value, value);
    789       raidrec->additional_vars.entries = ++v;
    790     }
    791   paranoid_free(tmp);
    792   paranoid_free(labelB);
    793   paranoid_free(valueB);
     692process_raidtab_line(FILE * fin,
     693                     struct raid_device_record *raidrec,
     694                     char *label, char *value)
     695{
     696
     697    /*@ add mallocs * */
     698    char *tmp;
     699    char *labelB;
     700    char *valueB;
     701
     702    struct list_of_disks *disklist;
     703    int index;
     704    int v;
     705
     706    malloc_string(tmp);
     707    malloc_string(labelB);
     708    malloc_string(valueB);
     709    assert(fin != NULL);
     710    assert(raidrec != NULL);
     711    assert_string_is_neither_NULL_nor_zerolength(label);
     712    assert(value != NULL);
     713
     714    if (!strcmp(label, "raid-level")) {
     715        if (!strcmp(value, "linear")) {
     716            raidrec->raid_level = -1;
     717        } else {
     718            raidrec->raid_level = atoi(value);
     719        }
     720    } else if (!strcmp(label, "nr-raid-disks")) {   /* ignore it */
     721    } else if (!strcmp(label, "nr-spare-disks")) {  /* ignore it */
     722    } else if (!strcmp(label, "nr-parity-disks")) { /* ignore it */
     723    } else if (!strcmp(label, "nr-failed-disks")) { /* ignore it */
     724    } else if (!strcmp(label, "persistent-superblock")) {
     725        raidrec->persistent_superblock = atoi(value);
     726    } else if (!strcmp(label, "chunk-size")) {
     727        raidrec->chunk_size = atoi(value);
     728    } else if (!strcmp(label, "device")) {
     729        get_next_raidtab_line(fin, labelB, valueB);
     730        if (!strcmp(labelB, "raid-disk")) {
     731            disklist = &raidrec->data_disks;
     732        } else if (!strcmp(labelB, "spare-disk")) {
     733            disklist = &raidrec->spare_disks;
     734        } else if (!strcmp(labelB, "parity-disk")) {
     735            disklist = &raidrec->parity_disks;
     736        } else if (!strcmp(labelB, "failed-disk")) {
     737            disklist = &raidrec->failed_disks;
     738        } else {
     739            disklist = NULL;
     740        }
     741        if (!disklist) {
     742            sprintf(tmp,
     743                    "Ignoring '%s %s' pair of disk %s", labelB, valueB,
     744                    label);
     745            log_it(tmp);
     746        } else {
     747            index = atoi(valueB);
     748            add_disk_to_raid_device(disklist, value, index);
     749        }
     750    } else {
     751        v = raidrec->additional_vars.entries;
     752        strcpy(raidrec->additional_vars.el[v].label, label);
     753        strcpy(raidrec->additional_vars.el[v].value, value);
     754        raidrec->additional_vars.entries = ++v;
     755    }
     756    paranoid_free(tmp);
     757    paranoid_free(labelB);
     758    paranoid_free(valueB);
    794759}
    795760#endif
     
    802767 * @param fout The stream to write to.
    803768 */
    804 void
    805 save_disklist_to_file(char *listname,
    806               struct list_of_disks *disklist,
    807               FILE *fout)
    808 {
    809   int i;
    810 
    811   assert_string_is_neither_NULL_nor_zerolength(listname);
    812   assert(disklist!=NULL);
    813   assert(fout!=NULL);
    814 
    815   for(i = 0; i < disklist->entries; i++)
    816     {
    817       fprintf(fout,"    device                %s\n",disklist->el[i].device);
    818       fprintf(fout,"    %-21s %d\n",listname,disklist->el[i].index);
    819     }
     769void
     770save_disklist_to_file(char *listname,
     771                      struct list_of_disks *disklist, FILE * fout)
     772{
     773    int i;
     774
     775    assert_string_is_neither_NULL_nor_zerolength(listname);
     776    assert(disklist != NULL);
     777    assert(fout != NULL);
     778
     779    for (i = 0; i < disklist->entries; i++) {
     780        fprintf(fout, "    device                %s\n",
     781                disklist->el[i].device);
     782        fprintf(fout, "    %-21s %d\n", listname, disklist->el[i].index);
     783    }
    820784}
    821785
     
    831795 * @param stripesize The stripe size (chunk size) of the new plex.
    832796 */
    833 void add_plex_to_volume(struct vinum_volume *v, int raidlevel, int stripesize)
    834 {
    835     v->plex[v->plexes].raidlevel = raidlevel;
    836     v->plex[v->plexes].stripesize = stripesize;
    837     v->plex[v->plexes].subdisks = 0;
    838     ++v->plexes;
     797void add_plex_to_volume(struct vinum_volume *v, int raidlevel,
     798                        int stripesize)
     799{
     800    v->plex[v->plexes].raidlevel = raidlevel;
     801    v->plex[v->plexes].stripesize = stripesize;
     802    v->plex[v->plexes].subdisks = 0;
     803    ++v->plexes;
    839804}
    840805
     
    842807 * For internal use only.
    843808 */
    844 char ** get_next_vinum_conf_line (FILE *f, int *argc)
    845 {
    846     int cnt = 0;
    847     static char *argv[64];
    848     char **ap;
    849     char *line = (char *) malloc (MAX_STR_LEN);
    850     if (!line) errx (1, "unable to allocate %i bytes of memory for `char *line' at %s:%i",
    851              MAX_STR_LEN, __FILE__, __LINE__);
    852     (void) fgets (line, MAX_STR_LEN, f);
    853     if (feof (f)) {
    854     log_it ("[GNVCL] Uh... I reached the EOF.");
     809char **get_next_vinum_conf_line(FILE * f, int *argc)
     810{
     811    int cnt = 0;
     812    static char *argv[64];
     813    char **ap;
     814    char *line = (char *) malloc(MAX_STR_LEN);
     815    if (!line)
     816        errx(1,
     817             "unable to allocate %i bytes of memory for `char *line' at %s:%i",
     818             MAX_STR_LEN, __FILE__, __LINE__);
     819    (void) fgets(line, MAX_STR_LEN, f);
     820    if (feof(f)) {
     821        log_it("[GNVCL] Uh... I reached the EOF.");
     822        return 0;
     823    }
     824
     825    for (ap = argv; (*ap = strsep(&line, " \t")) != NULL;)
     826        if (**ap != '\0') {
     827            if (++ap >= &argv[64])
     828                break;
     829            cnt++;
     830        }
     831
     832    if (strchr(argv[cnt - 1], '\n')) {
     833        *(strchr(argv[cnt - 1], '\n')) = '\0';
     834    }
     835
     836    if (argc)
     837        *argc = cnt;
     838    return argv;
     839}
     840
     841/**
     842 * For internal use only.
     843 */
     844char *get_option_val(int argc, char **argv, char *option)
     845{
     846    int i;
     847    for (i = 0; i < (argc - 1); ++i) {
     848        if (!strcmp(argv[i], option)) {
     849            return argv[i + 1];
     850        }
     851    }
    855852    return 0;
    856     }
    857    
    858     for (ap = argv; (*ap = strsep (&line, " \t")) != NULL;)
    859     if (**ap != '\0') {
    860         if (++ap >= &argv[64])
    861         break;
    862         cnt++;
    863     }
    864 
    865     if (strchr (argv[cnt-1], '\n')) {
    866     *(strchr (argv[cnt-1], '\n')) = '\0';
    867     }
    868 
    869     if (argc) *argc = cnt;
    870     return argv;
    871853}
    872854
     
    874856 * For internal use only.
    875857 */
    876 char * get_option_val (int argc, char ** argv, char * option)
    877 {
    878     int i;
    879     for (i = 0; i < (argc - 1); ++i) {
    880     if (!strcmp (argv[i], option)) {
    881         return argv[i + 1];
    882     }
    883     }
    884     return 0;
     858char **get_option_vals(int argc, char **argv, char *option, int nval)
     859{
     860    int i, j;
     861    static char **ret;
     862    ret = (char **) malloc(nval * sizeof(char *));
     863    for (i = 0; i < (argc - nval); ++i) {
     864        if (!strcmp(argv[i], option)) {
     865            for (j = 0; j < nval; ++j) {
     866                ret[j] = (char *) malloc(strlen(argv[i + j + 1]) + 1);
     867                strcpy(ret[j], argv[i + j + 1]);
     868            }
     869            return ret;
     870        }
     871    }
     872    return 0;
    885873}
    886874
     
    888876 * For internal use only.
    889877 */
    890 char ** get_option_vals (int argc, char ** argv, char * option, int nval)
    891 {
    892     int i, j;
    893     static char **ret;
    894     ret = (char **) malloc (nval * sizeof (char *));
    895     for (i = 0; i < (argc - nval); ++i) {
    896     if (!strcmp (argv[i], option)) {
    897         for (j = 0; j < nval; ++j) {
    898         ret[j] = (char *) malloc (strlen (argv[i + j + 1]) + 1);
    899         strcpy (ret[j], argv[i + j + 1]);
    900         }
    901         return ret;
    902     }
    903     }
    904     return 0;
    905 }
    906 
    907 /**
    908  * For internal use only.
    909  */
    910 bool get_option_state (int argc, char ** argv, char * option)
    911 {
    912     int i;
    913     for (i = 0; i < argc; ++i)
    914     if (!strcmp (argv[i], option))
    915         return TRUE;
    916 
    917     return FALSE;
     878bool get_option_state(int argc, char **argv, char *option)
     879{
     880    int i;
     881    for (i = 0; i < argc; ++i)
     882        if (!strcmp(argv[i], option))
     883            return TRUE;
     884
     885    return FALSE;
    918886}
    919887
     
    923891long long size_spec(char *spec)
    924892{
    925     u_int64_t size;
    926     char *s;
    927     int sign = 1;                       /* -1 if negative */
    928 
    929     size = 0;
    930     if (spec != NULL) {                     /* we have a parameter */
    931     s = spec;
    932     if (*s == '-') {                    /* negative, */
    933         sign = -1;
    934         s++;                        /* skip */
    935     }
    936     if ((*s >= '0') && (*s <= '9')) {           /* it's numeric */
    937         while ((*s >= '0') && (*s <= '9'))          /* it's numeric */
    938         size = size * 10 + *s++ - '0';          /* convert it */
    939         switch (*s) {
    940         case '\0':
    941         return size * sign;
    942 
    943         case 'B':
    944         case 'b':
    945         case 'S':
    946         case 's':
    947         return size * sign * 512;
    948 
    949         case 'K':
    950         case 'k':
    951         return size * sign * 1024;
    952 
    953         case 'M':
    954         case 'm':
    955         return size * sign * 1024 * 1024;
    956 
    957         case 'G':
    958         case 'g':
    959         return size * sign * 1024 * 1024 * 1024;
    960 
    961         case 'T':
    962         case 't':
    963         log_it ("Ok, I'm scared... Someone did a TERABYTE+ size-spec");
    964         return size * sign * 1024 * 1024 * 1024 * 1024;
    965        
    966         case 'P':
    967         case 'p':
    968         log_it ("If I was scared last time, I'm freaked out now. Someone actually has a PETABYTE?!?!?!?!");
    969         return size * sign * 1024 * 1024 * 1024 * 1024 * 1024;
    970 
    971         case 'E':
    972         case 'e':
    973         log_it ("Okay, I'm REALLY freaked out. Who could devote a whole EXABYTE to their data?!?!");
    974         return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
    975 
    976         case 'Z':
    977         case 'z':
    978         log_it ("WHAT!?!? A ZETABYTE!?!? You've GOT to be kidding me!!!");
    979         return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
    980 
    981         case 'Y':
    982         case 'y':
    983         log_it ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes?!?!");
    984         popup_and_OK ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
    985         return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
    986         }
    987     }
    988     }
    989     return size * sign;
     893    u_int64_t size;
     894    char *s;
     895    int sign = 1;               /* -1 if negative */
     896
     897    size = 0;
     898    if (spec != NULL) {         /* we have a parameter */
     899        s = spec;
     900        if (*s == '-') {        /* negative, */
     901            sign = -1;
     902            s++;                /* skip */
     903        }
     904        if ((*s >= '0') && (*s <= '9')) {   /* it's numeric */
     905            while ((*s >= '0') && (*s <= '9'))  /* it's numeric */
     906                size = size * 10 + *s++ - '0';  /* convert it */
     907            switch (*s) {
     908            case '\0':
     909                return size * sign;
     910
     911            case 'B':
     912            case 'b':
     913            case 'S':
     914            case 's':
     915                return size * sign * 512;
     916
     917            case 'K':
     918            case 'k':
     919                return size * sign * 1024;
     920
     921            case 'M':
     922            case 'm':
     923                return size * sign * 1024 * 1024;
     924
     925            case 'G':
     926            case 'g':
     927                return size * sign * 1024 * 1024 * 1024;
     928
     929            case 'T':
     930            case 't':
     931                log_it
     932                    ("Ok, I'm scared... Someone did a TERABYTE+ size-spec");
     933                return size * sign * 1024 * 1024 * 1024 * 1024;
     934
     935            case 'P':
     936            case 'p':
     937                log_it
     938                    ("If I was scared last time, I'm freaked out now. Someone actually has a PETABYTE?!?!?!?!");
     939                return size * sign * 1024 * 1024 * 1024 * 1024 * 1024;
     940
     941            case 'E':
     942            case 'e':
     943                log_it
     944                    ("Okay, I'm REALLY freaked out. Who could devote a whole EXABYTE to their data?!?!");
     945                return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
     946                    1024;
     947
     948            case 'Z':
     949            case 'z':
     950                log_it
     951                    ("WHAT!?!? A ZETABYTE!?!? You've GOT to be kidding me!!!");
     952                return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
     953                    1024 * 1024;
     954
     955            case 'Y':
     956            case 'y':
     957                log_it
     958                    ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes?!?!");
     959                popup_and_OK
     960                    ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
     961                return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
     962                    1024 * 1024 * 1024;
     963            }
     964        }
     965    }
     966    return size * sign;
    990967}
    991968
     
    995972
    996973
    997 int read_mdstat(struct s_mdstat *mdstat, char*mdstat_file)
    998 {
    999     FILE*fin;
    1000     char*tmp;
    1001     char*stub;
    1002     char*incoming;
    1003     char*raid_devname;
    1004     char*p, *q, *r;
    1005     int  diskno;
    1006    
    1007     malloc_string(tmp);
    1008     malloc_string(stub);
    1009     malloc_string(incoming);
    1010     malloc_string(raid_devname);
    1011     if (!(fin = fopen(mdstat_file, "r")))
    1012       {
    1013         log_msg(1, "%s not found", mdstat_file);
    1014     return(1);
    1015       }
    1016     mdstat->entries = 0;
    1017     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin))
    1018       {
    1019         p = incoming;
    1020         if (*p != 'm' && *(p+1) == 'm') { p++; }
    1021     if (strncmp(p, "md", 2)) { continue; }
     974int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file)
     975{
     976    FILE *fin;
     977    char *tmp;
     978    char *stub;
     979    char *incoming;
     980    char *raid_devname;
     981    char *p, *q, *r;
     982    int diskno;
     983
     984    malloc_string(tmp);
     985    malloc_string(stub);
     986    malloc_string(incoming);
     987    malloc_string(raid_devname);
     988    if (!(fin = fopen(mdstat_file, "r"))) {
     989        log_msg(1, "%s not found", mdstat_file);
     990        return (1);
     991    }
     992    mdstat->entries = 0;
     993    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     994         fgets(incoming, MAX_STR_LEN - 1, fin)) {
     995        p = incoming;
     996        if (*p != 'm' && *(p + 1) == 'm') {
     997            p++;
     998        }
     999        if (strncmp(p, "md", 2)) {
     1000            continue;
     1001        }
    10221002// read first line --- mdN : active raidX ............
    1023     mdstat->el[mdstat->entries].md = atoi(p+2);
    1024     log_msg(8, "Storing /dev/md%d's info", atoi(p+2));
    1025     while(*p != ':' && *p) { p++; }
    1026     while((*p!='r' || *(p+1)!='a') && *p) { p++; }
    1027         if (!strncmp(p, "raid", 4))
    1028       {
    1029         mdstat->el[mdstat->entries].raidlevel = *(p+4) - '0';
    1030       }
    1031     p += 4;
    1032         while(*p!=' '&& *p) { p++; }
    1033     while(*p==' '&& *p) { p++; }
    1034     for(diskno=0; *p; diskno++)
    1035       {
    1036         strcpy(stub, p);
    1037 //      log_msg(1, "diskno=%d; tmp=%s", diskno, tmp);
    1038         q = strchr(stub, '[');
    1039         if (q)
    1040           {
    1041             *q = '\0';
    1042             q++;
    1043         r = strchr(q, ']');
    1044         if (r) { *r='\0'; }
    1045         mdstat->el[mdstat->entries].disks.el[diskno].index = atoi(q);
    1046           }
    1047         else
    1048           {
    1049             mdstat->el[mdstat->entries].disks.el[diskno].index = -1;
    1050         q = strchr(stub, ' ');
    1051         if (q) { *q = '\0'; }
    1052           }
    1053         sprintf(tmp, "/dev/%s", stub);
    1054         log_msg(8, "/dev/md%d : disk#%d : %s (%d)", mdstat->el[mdstat->entries].md, diskno, tmp, mdstat->el[mdstat->entries].disks.el[diskno].index);
    1055         strcpy(mdstat->el[mdstat->entries].disks.el[diskno].device, tmp);
    1056         while(*p!=' '&& *p) { p++; }
    1057             while(*p==' '&& *p) { p++; }
    1058       }
    1059     mdstat->el[mdstat->entries].disks.entries = diskno;
     1003        mdstat->el[mdstat->entries].md = atoi(p + 2);
     1004        log_msg(8, "Storing /dev/md%d's info", atoi(p + 2));
     1005        while (*p != ':' && *p) {
     1006            p++;
     1007        }
     1008        while ((*p != 'r' || *(p + 1) != 'a') && *p) {
     1009            p++;
     1010        }
     1011        if (!strncmp(p, "raid", 4)) {
     1012            mdstat->el[mdstat->entries].raidlevel = *(p + 4) - '0';
     1013        }
     1014        p += 4;
     1015        while (*p != ' ' && *p) {
     1016            p++;
     1017        }
     1018        while (*p == ' ' && *p) {
     1019            p++;
     1020        }
     1021        for (diskno = 0; *p; diskno++) {
     1022            strcpy(stub, p);
     1023//      log_msg(1, "diskno=%d; tmp=%s", diskno, tmp);
     1024            q = strchr(stub, '[');
     1025            if (q) {
     1026                *q = '\0';
     1027                q++;
     1028                r = strchr(q, ']');
     1029                if (r) {
     1030                    *r = '\0';
     1031                }
     1032                mdstat->el[mdstat->entries].disks.el[diskno].index =
     1033                    atoi(q);
     1034            } else {
     1035                mdstat->el[mdstat->entries].disks.el[diskno].index = -1;
     1036                q = strchr(stub, ' ');
     1037                if (q) {
     1038                    *q = '\0';
     1039                }
     1040            }
     1041            sprintf(tmp, "/dev/%s", stub);
     1042            log_msg(8, "/dev/md%d : disk#%d : %s (%d)",
     1043                    mdstat->el[mdstat->entries].md, diskno, tmp,
     1044                    mdstat->el[mdstat->entries].disks.el[diskno].index);
     1045            strcpy(mdstat->el[mdstat->entries].disks.el[diskno].device,
     1046                   tmp);
     1047            while (*p != ' ' && *p) {
     1048                p++;
     1049            }
     1050            while (*p == ' ' && *p) {
     1051                p++;
     1052            }
     1053        }
     1054        mdstat->el[mdstat->entries].disks.entries = diskno;
    10601055// next line --- skip it
    1061     if (!feof(fin)) { fgets(incoming, MAX_STR_LEN - 1, fin); } else {continue; }
     1056        if (!feof(fin)) {
     1057            fgets(incoming, MAX_STR_LEN - 1, fin);
     1058        } else {
     1059            continue;
     1060        }
    10621061// next line --- the 'progress' line
    1063         if (!feof(fin)) { fgets(incoming, MAX_STR_LEN - 1, fin); } else {continue; }
    1064 //  log_msg(1, "Percentage line = '%s'", incoming);
    1065     if (!(p=strchr(incoming, '\%')))
    1066       {
    1067         mdstat->el[mdstat->entries].progress = 999; // not found
    1068       }
    1069     else if (strstr(incoming, "DELAYED"))
    1070       {
    1071         mdstat->el[mdstat->entries].progress = -1; // delayed (therefore, stuck at 0%)
    1072       }
    1073     else
    1074       {
    1075         for(*p='\0'; *p!=' '; p--);
    1076         mdstat->el[mdstat->entries].progress = atoi(p);
    1077       }
    1078     log_msg(8, "progress =%d", mdstat->el[mdstat->entries].progress);
    1079     mdstat->entries ++;
    1080       }
    1081     fclose(fin);
    1082     paranoid_free(tmp);
    1083     paranoid_free(stub);
    1084     paranoid_free(incoming);
    1085     paranoid_free(raid_devname);
    1086     return(0);
    1087 }
    1088 
    1089 
    1090 
    1091 int create_raidtab_from_mdstat(char*raidtab_fname, char *mdstat_fname)
    1092 {
    1093     struct raidlist_itself *raidlist;
    1094     struct s_mdstat *mdstat;
    1095     int retval=0;
    1096     int i;
    1097    
    1098     raidlist = malloc(sizeof(struct raidlist_itself));
    1099     mdstat = malloc(sizeof(struct s_mdstat));
    1100 
    1101     if (read_mdstat(mdstat, mdstat_fname))
    1102         { log_to_screen("Sorry, cannot read %s", mdstat_fname); return(1); }
    1103 
    1104     for(i=0; i<mdstat->entries; i++)
    1105       {
    1106         sprintf(raidlist->el[i].raid_device, "/dev/md%d", mdstat->el[i].md);
    1107     raidlist->el[i].raid_level = mdstat->el[i].raidlevel;
    1108     raidlist->el[i].persistent_superblock = 1;
    1109     raidlist->el[i].chunk_size = 4;
    1110     memcpy((void*)&raidlist->el[i].data_disks, (void*)&mdstat->el[i].disks, sizeof(struct list_of_disks));
    1111     // FIXME --- the above line does not allow for spare disks
    1112     log_to_screen("FIXME - create_raidtab_from_mdstat does not allow for spare disks");
    1113       }
    1114     raidlist->entries = i;
    1115     retval += save_raidlist_to_raidtab(raidlist, raidtab_fname);
    1116     return(retval);
     1062        if (!feof(fin)) {
     1063            fgets(incoming, MAX_STR_LEN - 1, fin);
     1064        } else {
     1065            continue;
     1066        }
     1067//  log_msg(1, "Percentage line = '%s'", incoming);
     1068        if (!(p = strchr(incoming, '\%'))) {
     1069            mdstat->el[mdstat->entries].progress = 999; // not found
     1070        } else if (strstr(incoming, "DELAYED")) {
     1071            mdstat->el[mdstat->entries].progress = -1;  // delayed (therefore, stuck at 0%)
     1072        } else {
     1073            for (*p = '\0'; *p != ' '; p--);
     1074            mdstat->el[mdstat->entries].progress = atoi(p);
     1075        }
     1076        log_msg(8, "progress =%d", mdstat->el[mdstat->entries].progress);
     1077        mdstat->entries++;
     1078    }
     1079    fclose(fin);
     1080    paranoid_free(tmp);
     1081    paranoid_free(stub);
     1082    paranoid_free(incoming);
     1083    paranoid_free(raid_devname);
     1084    return (0);
     1085}
     1086
     1087
     1088
     1089int create_raidtab_from_mdstat(char *raidtab_fname, char *mdstat_fname)
     1090{
     1091    struct raidlist_itself *raidlist;
     1092    struct s_mdstat *mdstat;
     1093    int retval = 0;
     1094    int i;
     1095
     1096    raidlist = malloc(sizeof(struct raidlist_itself));
     1097    mdstat = malloc(sizeof(struct s_mdstat));
     1098
     1099    if (read_mdstat(mdstat, mdstat_fname)) {
     1100        log_to_screen("Sorry, cannot read %s", mdstat_fname);
     1101        return (1);
     1102    }
     1103
     1104    for (i = 0; i < mdstat->entries; i++) {
     1105        sprintf(raidlist->el[i].raid_device, "/dev/md%d",
     1106                mdstat->el[i].md);
     1107        raidlist->el[i].raid_level = mdstat->el[i].raidlevel;
     1108        raidlist->el[i].persistent_superblock = 1;
     1109        raidlist->el[i].chunk_size = 4;
     1110        memcpy((void *) &raidlist->el[i].data_disks,
     1111               (void *) &mdstat->el[i].disks,
     1112               sizeof(struct list_of_disks));
     1113        // FIXME --- the above line does not allow for spare disks
     1114        log_to_screen
     1115            ("FIXME - create_raidtab_from_mdstat does not allow for spare disks");
     1116    }
     1117    raidlist->entries = i;
     1118    retval += save_raidlist_to_raidtab(raidlist, raidtab_fname);
     1119    return (retval);
    11171120}
    11181121
     
    11201123
    11211124/* @} - end of raidGroup */
    1122 
  • branches/2.05/mondo/mondo/common/libmondo-raid.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-stream-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-stream.c

    r30 r128  
    11/* libmondo-stream.c
    2    $Id: libmondo-stream.c,v 1.4 2004/06/21 20:20:36 hugo Exp $
     2   $Id$
    33
    44...tools for talking to tapes, Monitas streams, etc.
     
    112112
    113113/*@unused@*/
    114 //static char cvsid[] = "$Id: libmondo-stream.c,v 1.4 2004/06/21 20:20:36 hugo Exp $";
     114//static char cvsid[] = "$Id$";
    115115extern bool g_sigpipe;
    116116extern int g_tape_buffer_size_MB;
     
    137137 * The current media number we're using. This value is 1-based.
    138138 */
    139 int g_current_media_number=-1;
     139int g_current_media_number = -1;
    140140
    141141/**
     
    146146/* @} - end of globalGroup */
    147147
    148 int write_backcatalog_to_tape (struct s_bkpinfo *bkpinfo);
     148int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
    149149
    150150
     
    163163 * @note This should be called by restore processes only.
    164164 */
    165 int
    166 closein_cdstream (struct s_bkpinfo *bkpinfo)
    167 {
    168   return (closein_tape (bkpinfo));
     165int closein_cdstream(struct s_bkpinfo *bkpinfo)
     166{
     167    return (closein_tape(bkpinfo));
    169168}
    170169
     
    179178 * @bug @p bkpinfo parameter is unused.
    180179 */
    181 int
    182 closein_tape (struct s_bkpinfo *bkpinfo)
    183 {
    184     /*@ int's ********************************************************/
    185   int retval = 0;
    186   int res = 0;
    187   int ctrl_chr = '\0';
    188 
    189     /*@ buffers ******************************************************/
    190   char fname[MAX_STR_LEN];
    191 
    192     /*@ long long's **************************************************/
    193   long long size;
    194   char *blk;
    195   int i;
    196 
    197   blk = (char*)malloc(256*1024);
    198 
    199   log_it("closein_tape() -- entering");
    200   res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    201   retval += res;
    202   if (ctrl_chr != BLK_END_OF_BACKUP)
    203     {
    204       wrong_marker (BLK_END_OF_BACKUP, ctrl_chr);
    205     }
    206   res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    207   retval += res;
    208   if (ctrl_chr != BLK_END_OF_TAPE)
    209     {
    210       wrong_marker (BLK_END_OF_TAPE, ctrl_chr);
    211     }
    212   for(i=0; i<8 && !feof(g_tape_stream); i++)
    213     {
    214         (void) fread (blk, 1, 256*1024, g_tape_stream);
    215     }
    216   sleep(1);
    217   paranoid_system("sync");
    218   sleep(1);
    219   paranoid_pclose (g_tape_stream);
    220   log_it("closein_tape() -- leaving");
     180int closein_tape(struct s_bkpinfo *bkpinfo)
     181{
     182    /*@ int's ******************************************************* */
     183    int retval = 0;
     184    int res = 0;
     185    int ctrl_chr = '\0';
     186
     187    /*@ buffers ***************************************************** */
     188    char fname[MAX_STR_LEN];
     189
     190    /*@ long long's ************************************************* */
     191    long long size;
     192    char *blk;
     193    int i;
     194
     195    blk = (char *) malloc(256 * 1024);
     196
     197    log_it("closein_tape() -- entering");
     198    res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     199    retval += res;
     200    if (ctrl_chr != BLK_END_OF_BACKUP) {
     201        wrong_marker(BLK_END_OF_BACKUP, ctrl_chr);
     202    }
     203    res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     204    retval += res;
     205    if (ctrl_chr != BLK_END_OF_TAPE) {
     206        wrong_marker(BLK_END_OF_TAPE, ctrl_chr);
     207    }
     208    for (i = 0; i < 8 && !feof(g_tape_stream); i++) {
     209        (void) fread(blk, 1, 256 * 1024, g_tape_stream);
     210    }
     211    sleep(1);
     212    paranoid_system("sync");
     213    sleep(1);
     214    paranoid_pclose(g_tape_stream);
     215    log_it("closein_tape() -- leaving");
    221216/*
    222217  for(i=0; i < g_tapecatalog->entries; i++)
     
    225220    }
    226221*/
    227   if (!bkpinfo->please_dont_eject)
    228     {  eject_device(bkpinfo->media_device); }
    229   paranoid_free(blk);
    230   paranoid_free(g_tapecatalog);
    231   return (retval);
     222    if (!bkpinfo->please_dont_eject) {
     223        eject_device(bkpinfo->media_device);
     224    }
     225    paranoid_free(blk);
     226    paranoid_free(g_tapecatalog);
     227    return (retval);
    232228}
    233229
     
    241237 * @note This should be called by backup processes only.
    242238 */
    243 int
    244 closeout_tape (struct s_bkpinfo *bkpinfo)
    245 {
    246     /*@ int's ********************************************************/
    247   int retval = 0;
     239int closeout_tape(struct s_bkpinfo *bkpinfo)
     240{
     241    /*@ int's ******************************************************* */
     242    int retval = 0;
    248243//  int res = 0;
    249244//  int ctrl_chr = '\0';
    250245
    251     /*@ buffers ******************************************************/
     246    /*@ buffers ***************************************************** */
    252247//  char fname[MAX_STR_LEN];
    253248
    254     /*@ long long's **************************************************/
     249    /*@ long long's ************************************************* */
    255250//  long long size;
    256   int i;
    257   char *blk;
    258 
    259   blk = (char*)malloc(256*1024);
    260 
    261   sleep(1);
    262   paranoid_system("sync");
    263   sleep(1);
    264   log_it("closeout_tape() -- entering");
    265     retval+=write_header_block_to_stream (0, "end-of-backup", BLK_END_OF_BACKUP);
    266     retval+=write_header_block_to_stream (0, "end-of-tape", BLK_END_OF_TAPE);   /* just in case */
     251    int i;
     252    char *blk;
     253
     254    blk = (char *) malloc(256 * 1024);
     255
     256    sleep(1);
     257    paranoid_system("sync");
     258    sleep(1);
     259    log_it("closeout_tape() -- entering");
     260    retval +=
     261        write_header_block_to_stream(0, "end-of-backup",
     262                                     BLK_END_OF_BACKUP);
     263    retval += write_header_block_to_stream(0, "end-of-tape", BLK_END_OF_TAPE);  /* just in case */
    267264/* write 1MB of crap */
    268     for (i = 0; i < 256*1024; i++)
    269       {
    270         blk[i] = (int)(random()&0xFF);
    271       }
    272     for (i = 0; i < 4*8; i++)
    273       {
    274         (void) fwrite (blk, 1, 256*1024, g_tape_stream);
    275         if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], 256*1024))
    276           {
    277             start_to_write_to_next_tape (bkpinfo);
    278           }
    279       }
     265    for (i = 0; i < 256 * 1024; i++) {
     266        blk[i] = (int) (random() & 0xFF);
     267    }
     268    for (i = 0; i < 4 * 8; i++) {
     269        (void) fwrite(blk, 1, 256 * 1024, g_tape_stream);
     270        if (should_we_write_to_next_tape
     271            (bkpinfo->media_size[g_current_media_number], 256 * 1024)) {
     272            start_to_write_to_next_tape(bkpinfo);
     273        }
     274    }
    280275/* write 1MB of zeroes */
    281276/*
     
    293288      }
    294289*/
    295   sleep(2);
    296   paranoid_pclose (g_tape_stream);
    297   log_it("closeout_tape() -- leaving");
    298   for(i=0; i<g_tapecatalog->entries; i++)
    299     {
    300       log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux, g_tapecatalog->el[i].tape_posK);
    301     }
    302   //  if (!bkpinfo->please_dont_eject)
    303   //    { eject_device(bkpinfo->media_device); }
    304   paranoid_free(blk);
    305   paranoid_free(g_tapecatalog);
    306   return (retval);
    307 }
    308 
    309 
    310 
    311 bool mt_says_tape_exists(char*dev)
    312 {
    313   char *command;
    314   int res;
    315 
    316   malloc_string(command);
    317   sprintf(command, "mt -f %s status", dev);
    318   res = run_program_and_log_output(command, 1);
    319   paranoid_free(command);
    320   if (res) { return(FALSE); } else { return(TRUE); }
     290    sleep(2);
     291    paranoid_pclose(g_tape_stream);
     292    log_it("closeout_tape() -- leaving");
     293    for (i = 0; i < g_tapecatalog->entries; i++) {
     294        log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i,
     295               (g_tapecatalog->el[i].type ==
     296                fileset) ? "fileset" : "bigslice",
     297               g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux,
     298               g_tapecatalog->el[i].tape_posK);
     299    }
     300    //  if (!bkpinfo->please_dont_eject)
     301    //    { eject_device(bkpinfo->media_device); }
     302    paranoid_free(blk);
     303    paranoid_free(g_tapecatalog);
     304    return (retval);
     305}
     306
     307
     308
     309bool mt_says_tape_exists(char *dev)
     310{
     311    char *command;
     312    int res;
     313
     314    malloc_string(command);
     315    sprintf(command, "mt -f %s status", dev);
     316    res = run_program_and_log_output(command, 1);
     317    paranoid_free(command);
     318    if (res) {
     319        return (FALSE);
     320    } else {
     321        return (TRUE);
     322    }
    321323}
    322324
     
    330332 * @return 0 if success, nonzero if failure (in which @p dev and @p siz are undefined).
    331333 */
    332 int
    333 find_tape_device_and_size (char*dev, char*siz)
    334 {
    335   char tmp[MAX_STR_LEN];
    336   char command[MAX_STR_LEN*2];
    337   char cdr_exe[MAX_STR_LEN];
     334int find_tape_device_and_size(char *dev, char *siz)
     335{
     336    char tmp[MAX_STR_LEN];
     337    char command[MAX_STR_LEN * 2];
     338    char cdr_exe[MAX_STR_LEN];
    338339//  char tape_description_[MAX_STR_LEN];
    339340//  char tape_manufacturer_cdr[MAX_STR_LEN];
    340341//  FILE*fin;
    341   int res;
    342 
    343   log_to_screen("I am looking for your tape streamer. Please wait.");
    344   dev[0] = siz[0] = '\0';
    345   if (find_home_of_exe("cdrecord"))
    346     { strcpy(cdr_exe, "cdrecord"); }
    347   else
    348     { strcpy(cdr_exe, "dvdrecord"); }
    349   sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe);
    350   strcpy (tmp, call_program_and_get_last_line_of_output(command));
    351   if (atoi(tmp)!=1)
    352     {
    353       log_it("Either too few or too many tape streamers for me to detect...");
    354       strcpy(dev, VANILLA_SCSI_TAPE);
    355       return 1;
    356     }
    357   sprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", cdr_exe);
    358   strcpy (tmp, call_program_and_get_last_line_of_output(command));
    359   if (strlen (tmp) < 2)
    360     {
    361       log_it ("Could not find tape device");
    362       return 1;
    363     }
    364   sprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", cdr_exe);
    365   strcpy (tmp, call_program_and_get_last_line_of_output(command));
    366   strcpy (dev, VANILLA_SCSI_TAPE);
    367   dev[strlen(dev)-1] = '\0';
    368   strcat(dev, tmp);     // e.g. '/dev/st0' becomes '/dev/stN'
    369   res = 0;
    370   if (!mt_says_tape_exists(dev))
    371     {
    372       strcpy(dev, ALT_TAPE);
    373       if (!mt_says_tape_exists(dev))
    374     {
    375       log_it ("Cannot openin %s", dev);
    376       strcpy(dev, "/dev/st0");
    377       if (!mt_says_tape_exists(dev))
    378         {
    379           log_it ("Cannot openin %s", dev);
    380           strcpy(dev, "/dev/osst0");
    381           if (!mt_says_tape_exists(dev))
    382         { res++; }
    383           else
    384         { res=0; }
    385         }
    386     }
    387     }
    388  
    389   log_it("At this point, dev = %s and res = %d" , dev, res);
    390 
    391   strcpy(tmp, call_program_and_get_last_line_of_output("\
     342    int res;
     343
     344    log_to_screen("I am looking for your tape streamer. Please wait.");
     345    dev[0] = siz[0] = '\0';
     346    if (find_home_of_exe("cdrecord")) {
     347        strcpy(cdr_exe, "cdrecord");
     348    } else {
     349        strcpy(cdr_exe, "dvdrecord");
     350    }
     351    sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
     352            cdr_exe);
     353    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     354    if (atoi(tmp) != 1) {
     355        log_it
     356            ("Either too few or too many tape streamers for me to detect...");
     357        strcpy(dev, VANILLA_SCSI_TAPE);
     358        return 1;
     359    }
     360    sprintf(command,
     361            "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1",
     362            cdr_exe);
     363    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     364    if (strlen(tmp) < 2) {
     365        log_it("Could not find tape device");
     366        return 1;
     367    }
     368    sprintf(command,
     369            "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1",
     370            cdr_exe);
     371    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     372    strcpy(dev, VANILLA_SCSI_TAPE);
     373    dev[strlen(dev) - 1] = '\0';
     374    strcat(dev, tmp);           // e.g. '/dev/st0' becomes '/dev/stN'
     375    res = 0;
     376    if (!mt_says_tape_exists(dev)) {
     377        strcpy(dev, ALT_TAPE);
     378        if (!mt_says_tape_exists(dev)) {
     379            log_it("Cannot openin %s", dev);
     380            strcpy(dev, "/dev/st0");
     381            if (!mt_says_tape_exists(dev)) {
     382                log_it("Cannot openin %s", dev);
     383                strcpy(dev, "/dev/osst0");
     384                if (!mt_says_tape_exists(dev)) {
     385                    res++;
     386                } else {
     387                    res = 0;
     388                }
     389            }
     390        }
     391    }
     392
     393    log_it("At this point, dev = %s and res = %d", dev, res);
     394
     395    strcpy(tmp, call_program_and_get_last_line_of_output("\
    392396cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
    393397grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
    394398awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
    395399
    396   if (mt_says_tape_exists(dev))
    397     { res = 0; }
    398   else
    399     {
    400       log_it("Turning %s", dev);
    401       strcpy(tmp, (strrchr(dev, '/')!=NULL)?strrchr(dev, '/'):dev);
    402       sprintf(dev, "/dev/os%s", tmp);
    403       log_it("...into %s", dev);
    404       if (mt_says_tape_exists(dev))
    405     { res=0; }
    406       else
    407     { res++; }
    408     }
    409 
    410   siz[0] = '\0';
    411   log_it("res=%d; dev=%s", res, dev);
    412 
    413   if (res) { return(res); }
    414 
    415   if (strlen(tmp)<2) { siz[0]='\0'; log_it("Warning - size of tape unknown"); return(0); }
    416   else { strcpy(siz, tmp); return(0); }
    417 }
    418 
    419 
    420 
    421 
    422 
    423 
    424 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)
    425 {
    426   int res=0;
    427   int retval=0;
    428  
     400    if (mt_says_tape_exists(dev)) {
     401        res = 0;
     402    } else {
     403        log_it("Turning %s", dev);
     404        strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
     405        sprintf(dev, "/dev/os%s", tmp);
     406        log_it("...into %s", dev);
     407        if (mt_says_tape_exists(dev)) {
     408            res = 0;
     409        } else {
     410            res++;
     411        }
     412    }
     413
     414    siz[0] = '\0';
     415    log_it("res=%d; dev=%s", res, dev);
     416
     417    if (res) {
     418        return (res);
     419    }
     420
     421    if (strlen(tmp) < 2) {
     422        siz[0] = '\0';
     423        log_it("Warning - size of tape unknown");
     424        return (0);
     425    } else {
     426        strcpy(siz, tmp);
     427        return (0);
     428    }
     429}
     430
     431
     432
     433
     434
     435
     436int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo,
     437                              long long *ptmp_size, char *tmp_fname,
     438                              int *pctrl_chr, char *xattr_fname,
     439                              char *acl_fname)
     440{
     441    int res = 0;
     442    int retval = 0;
     443
    429444// xattr
    430           res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    431           if(*pctrl_chr!=BLK_START_EXAT_FILE){wrong_marker(BLK_START_EXAT_FILE,*pctrl_chr);}
    432       if (!strstr(tmp_fname, "xattr")) { fatal_error("Wrong order, sunshine."); }
    433       read_file_from_stream_to_file(bkpinfo, xattr_fname, *ptmp_size);
    434       res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    435           if(*pctrl_chr!= BLK_STOP_EXAT_FILE) {wrong_marker(BLK_STOP_EXAT_FILE,*pctrl_chr);}
     445    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     446    if (*pctrl_chr != BLK_START_EXAT_FILE) {
     447        wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
     448    }
     449    if (!strstr(tmp_fname, "xattr")) {
     450        fatal_error("Wrong order, sunshine.");
     451    }
     452    read_file_from_stream_to_file(bkpinfo, xattr_fname, *ptmp_size);
     453    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     454    if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
     455        wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
     456    }
    436457// acl
    437       res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    438       if (!strstr(tmp_fname, "acl")) { fatal_error("Wrong order, sunshine."); }
    439           if(*pctrl_chr!=BLK_START_EXAT_FILE){wrong_marker(BLK_START_EXAT_FILE,*pctrl_chr);}
    440       read_file_from_stream_to_file(bkpinfo, acl_fname, *ptmp_size);
    441           res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    442           if(*pctrl_chr!= BLK_STOP_EXAT_FILE){wrong_marker(BLK_STOP_EXAT_FILE,*pctrl_chr);}
    443           res=read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    444           if(*pctrl_chr!= BLK_STOP_EXTENDED_ATTRIBUTES)
    445         { wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES,*pctrl_chr); }
     458    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     459    if (!strstr(tmp_fname, "acl")) {
     460        fatal_error("Wrong order, sunshine.");
     461    }
     462    if (*pctrl_chr != BLK_START_EXAT_FILE) {
     463        wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
     464    }
     465    read_file_from_stream_to_file(bkpinfo, acl_fname, *ptmp_size);
     466    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     467    if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
     468        wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
     469    }
     470    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     471    if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) {
     472        wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr);
     473    }
    446474// tarball itself
    447           res=read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    448       log_msg(1, "Got xattr and acl; now looking for afioball");
    449       return(retval);
    450 }
    451 
    452 
    453 int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char*xattr_fname, char*acl_fname)
    454 {
    455   int res=0;
     475    res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     476    log_msg(1, "Got xattr and acl; now looking for afioball");
     477    return (retval);
     478}
     479
     480
     481int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char *xattr_fname,
     482                             char *acl_fname)
     483{
     484    int res = 0;
    456485// EXATs
    457               write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_START_EXTENDED_ATTRIBUTES);
     486    write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
     487                                 BLK_START_EXTENDED_ATTRIBUTES);
    458488// xattr
    459               write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_START_EXAT_FILE);
    460           write_file_to_stream_from_file(bkpinfo, xattr_fname); 
    461           write_header_block_to_stream(-1, xattr_fname, BLK_STOP_EXAT_FILE);
     489    write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
     490                                 BLK_START_EXAT_FILE);
     491    write_file_to_stream_from_file(bkpinfo, xattr_fname);
     492    write_header_block_to_stream(-1, xattr_fname, BLK_STOP_EXAT_FILE);
    462493// acl
    463               write_header_block_to_stream(length_of_file(acl_fname), acl_fname, BLK_START_EXAT_FILE);
    464           write_file_to_stream_from_file(bkpinfo, acl_fname); 
    465           write_header_block_to_stream(-1, acl_fname, BLK_STOP_EXAT_FILE);
    466               write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_STOP_EXTENDED_ATTRIBUTES);
    467   return(res);
     494    write_header_block_to_stream(length_of_file(acl_fname), acl_fname,
     495                                 BLK_START_EXAT_FILE);
     496    write_file_to_stream_from_file(bkpinfo, acl_fname);
     497    write_header_block_to_stream(-1, acl_fname, BLK_STOP_EXAT_FILE);
     498    write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
     499                                 BLK_STOP_EXTENDED_ATTRIBUTES);
     500    return (res);
    468501}
    469502
     
    479512void insist_on_this_tape_number(int tapeno)
    480513{
    481   int i;
    482   char tmp[MAX_STR_LEN];
    483 
    484   log_it("Insisting on tape #%d", tapeno);
    485   if (g_current_media_number != tapeno)
    486     {
    487       //      log_it("g_current_media_number = %d", g_current_media_number);
    488       sprintf(tmp, "When the tape drive goes quiet, please insert volume %d in this series.", tapeno);
    489       popup_and_OK (tmp);
    490       open_evalcall_form ("Waiting while the tape drive settles");
    491     }
    492   else
    493     {
    494       open_evalcall_form ("Waiting while the tape drive rewinds");
    495     }
    496 
    497   for(i=0; i<=100; i+=2)
    498     {
    499       usleep(100000);
    500       update_evalcall_form (i);
    501     }
    502   close_evalcall_form();
    503   log_it("I assume user has inserted it. They _say_ they have...");
    504   g_current_media_number = tapeno;
    505 
    506   //  log_it("g_current_media_number = %d", g_current_media_number);
    507   log_it("OK, I've finished insisting. On with the revelry.");
     514    int i;
     515    char tmp[MAX_STR_LEN];
     516
     517    log_it("Insisting on tape #%d", tapeno);
     518    if (g_current_media_number != tapeno) {
     519        //      log_it("g_current_media_number = %d", g_current_media_number);
     520        sprintf(tmp,
     521                "When the tape drive goes quiet, please insert volume %d in this series.",
     522                tapeno);
     523        popup_and_OK(tmp);
     524        open_evalcall_form("Waiting while the tape drive settles");
     525    } else {
     526        open_evalcall_form("Waiting while the tape drive rewinds");
     527    }
     528
     529    for (i = 0; i <= 100; i += 2) {
     530        usleep(100000);
     531        update_evalcall_form(i);
     532    }
     533    close_evalcall_form();
     534    log_it("I assume user has inserted it. They _say_ they have...");
     535    g_current_media_number = tapeno;
     536
     537    //  log_it("g_current_media_number = %d", g_current_media_number);
     538    log_it("OK, I've finished insisting. On with the revelry.");
    508539}
    509540
     
    514545 * Debugging aid - log the offset we're at on the tape (reading or writing).
    515546 */
    516 void
    517 log_tape_pos (void)
    518 {
    519     /*@ buffers ******************************************************/
    520 
    521 
    522     /*@ end vars ****************************************************/
    523 
    524   log_it ("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK,
    525        (long) g_tape_posK >> 10);
     547void log_tape_pos(void)
     548{
     549    /*@ buffers ***************************************************** */
     550
     551
     552    /*@ end vars *************************************************** */
     553
     554    log_it("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK,
     555           (long) g_tape_posK >> 10);
    526556}
    527557
     
    542572int maintain_collection_of_recent_archives(char *td, char *latest_fname)
    543573{
    544   long long final_alleged_writeK, final_projected_certain_writeK, final_actually_certain_writeK=0, cposK, bufsize_K;
    545   int last, curr, i;
    546   t_archtype type=other;
    547   char command[MAX_STR_LEN];
    548   char tmpdir[MAX_STR_LEN];
    549   char old_fname[MAX_STR_LEN];
    550   char *p;
    551   char suffix[16];
    552 
    553   bufsize_K = (long long)(1024LL * (1+g_tape_buffer_size_MB) );
    554   sprintf(tmpdir, "%s/tmpfs/backcatalog", td);
    555   if ((p=strrchr(latest_fname, '.'))) { strcpy(suffix, ++p); } else { suffix[0] = '\0'; }
    556   if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) { type = fileset; }
    557   else if (strstr(latest_fname, "slice")) { type = biggieslice; }
    558   else
    559     {
    560       log_it("fname = %s", latest_fname);
    561       fatal_error("Unknown type. Internal error in maintain_collection_of_recent_archives()");
    562     }
    563   mkdir(tmpdir, 0x700);
    564   sprintf(command, "cp -f %s %s", latest_fname, tmpdir);
    565   if (run_program_and_log_output(command, 6)) { log_it("Warning - failed to copy %s to backcatalog at %s", latest_fname, tmpdir); }
    566   last = g_tapecatalog->entries-1;
    567   if ( last<=0 )
    568     {
    569       iamhere("Too early to start deleting from collection.");
    570       return( 0 );
    571     }
    572   final_alleged_writeK = g_tapecatalog->el[last].tape_posK;
    573   final_projected_certain_writeK = final_alleged_writeK - bufsize_K;
    574   for( curr=last; curr>=0; curr--)
    575     {
    576       cposK = g_tapecatalog->el[curr].tape_posK;
    577       if (cposK < final_projected_certain_writeK)
    578         {
    579       final_actually_certain_writeK = cposK;
    580       break;
    581     }
    582     }
    583   if ( curr<0 )
    584     {
    585       iamhere( "Not far enough into tape to start deleting old archives from collection." );
    586       return( 0 );
    587     }
     574    long long final_alleged_writeK, final_projected_certain_writeK,
     575        final_actually_certain_writeK = 0, cposK, bufsize_K;
     576    int last, curr, i;
     577    t_archtype type = other;
     578    char command[MAX_STR_LEN];
     579    char tmpdir[MAX_STR_LEN];
     580    char old_fname[MAX_STR_LEN];
     581    char *p;
     582    char suffix[16];
     583
     584    bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB));
     585    sprintf(tmpdir, "%s/tmpfs/backcatalog", td);
     586    if ((p = strrchr(latest_fname, '.'))) {
     587        strcpy(suffix, ++p);
     588    } else {
     589        suffix[0] = '\0';
     590    }
     591    if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) {
     592        type = fileset;
     593    } else if (strstr(latest_fname, "slice")) {
     594        type = biggieslice;
     595    } else {
     596        log_it("fname = %s", latest_fname);
     597        fatal_error
     598            ("Unknown type. Internal error in maintain_collection_of_recent_archives()");
     599    }
     600    mkdir(tmpdir, 0x700);
     601    sprintf(command, "cp -f %s %s", latest_fname, tmpdir);
     602    if (run_program_and_log_output(command, 6)) {
     603        log_it("Warning - failed to copy %s to backcatalog at %s",
     604               latest_fname, tmpdir);
     605    }
     606    last = g_tapecatalog->entries - 1;
     607    if (last <= 0) {
     608        iamhere("Too early to start deleting from collection.");
     609        return (0);
     610    }
     611    final_alleged_writeK = g_tapecatalog->el[last].tape_posK;
     612    final_projected_certain_writeK = final_alleged_writeK - bufsize_K;
     613    for (curr = last; curr >= 0; curr--) {
     614        cposK = g_tapecatalog->el[curr].tape_posK;
     615        if (cposK < final_projected_certain_writeK) {
     616            final_actually_certain_writeK = cposK;
     617            break;
     618        }
     619    }
     620    if (curr < 0) {
     621        iamhere
     622            ("Not far enough into tape to start deleting old archives from collection.");
     623        return (0);
     624    }
    588625//  log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K);
    589626
    590   for(i=curr-1; i>=0 && curr-i<10; i--)
    591     {
    592       sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
    593       unlink(old_fname);
    594     }
    595   return(0);
     627    for (i = curr - 1; i >= 0 && curr - i < 10; i--) {
     628        sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
     629        unlink(old_fname);
     630    }
     631    return (0);
    596632}
    597633
     
    605641 * @note Equivalent to openin_tape() for now, but don't count on this behavior.
    606642 */
    607 int
    608 openin_cdstream (struct s_bkpinfo *bkpinfo)
    609 {
    610   return (openin_tape (bkpinfo));
     643int openin_cdstream(struct s_bkpinfo *bkpinfo)
     644{
     645    return (openin_tape(bkpinfo));
    611646}
    612647
     
    619654
    620655
    621 int set_tape_block_size_with_mt(char*tapedev, long internal_tape_block_size)
    622 {
    623   char *tmp;
    624   int res;
    625 
    626   if (strncmp(tapedev, "/dev/", 5))
    627     {
    628       log_msg(1, "Not using 'mt setblk'. This isn't an actual /dev entry.");
    629       return(0);
    630     }
    631   malloc_string( tmp );
    632   sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
    633   res = run_program_and_log_output(tmp, 3);
    634   paranoid_free( tmp );
    635   return(res);
     656int set_tape_block_size_with_mt(char *tapedev,
     657                                long internal_tape_block_size)
     658{
     659    char *tmp;
     660    int res;
     661
     662    if (strncmp(tapedev, "/dev/", 5)) {
     663        log_msg(1,
     664                "Not using 'mt setblk'. This isn't an actual /dev entry.");
     665        return (0);
     666    }
     667    malloc_string(tmp);
     668    sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
     669    res = run_program_and_log_output(tmp, 3);
     670    paranoid_free(tmp);
     671    return (res);
    636672}
    637673
     
    646682 * @note This will also work with a cdstream for now, but don't count on this behavior.
    647683 */
    648 int
    649 openin_tape (struct s_bkpinfo *bkpinfo)
    650 {
    651     /*@ buffer ******************************************************/
    652   char fname[MAX_STR_LEN];
    653   char *datablock;
    654   char tmp[MAX_STR_LEN];
    655   char old_cwd[MAX_STR_LEN];
    656   char outfname[MAX_STR_LEN];
    657     /*@ int ********************************************************/
    658   int i;
    659   int j;
    660   int res;
    661   long length, templong;
    662   size_t k;
    663   int retval = 0;
    664   int ctrl_chr;
    665 
    666     /*@ long long **************************************************/
    667   long long size;
    668 
    669     /*@ pointers ***************************************************/
    670   FILE *fout;
    671 
    672     /*@ end vars ****************************************************/
    673 
    674   assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
    675   if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { fatal_error("Cannot alloc mem for tape catalog"); }
    676   g_tapecatalog->entries = 0;
    677   g_tape_posK = 0;
    678   if (g_tape_stream) { log_it("FYI - I won't 'openin' the tape. It's already open."); return(0); }
    679   insist_on_this_tape_number(1);
    680   sprintf (outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
    681   make_hole_for_file (outfname);
    682 
    683   set_tape_block_size_with_mt(bkpinfo->media_device, bkpinfo->internal_tape_block_size);
     684int openin_tape(struct s_bkpinfo *bkpinfo)
     685{
     686    /*@ buffer ***************************************************** */
     687    char fname[MAX_STR_LEN];
     688    char *datablock;
     689    char tmp[MAX_STR_LEN];
     690    char old_cwd[MAX_STR_LEN];
     691    char outfname[MAX_STR_LEN];
     692    /*@ int ******************************************************* */
     693    int i;
     694    int j;
     695    int res;
     696    long length, templong;
     697    size_t k;
     698    int retval = 0;
     699    int ctrl_chr;
     700
     701    /*@ long long ************************************************* */
     702    long long size;
     703
     704    /*@ pointers ************************************************** */
     705    FILE *fout;
     706
     707    /*@ end vars *************************************************** */
     708
     709    assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
     710    if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
     711        fatal_error("Cannot alloc mem for tape catalog");
     712    }
     713    g_tapecatalog->entries = 0;
     714    g_tape_posK = 0;
     715    if (g_tape_stream) {
     716        log_it("FYI - I won't 'openin' the tape. It's already open.");
     717        return (0);
     718    }
     719    insist_on_this_tape_number(1);
     720    sprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
     721    make_hole_for_file(outfname);
     722
     723    set_tape_block_size_with_mt(bkpinfo->media_device,
     724                                bkpinfo->internal_tape_block_size);
    684725
    685726//  start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);
    686   log_it ("Opening IN tape");
    687   if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { log_OS_error(g_tape_fifo); log_to_screen ("Cannot openin stream device"); return(1); }
    688   log_to_screen ("Reading stream");
    689   log_it ("stream device = '%s'", bkpinfo->media_device);
     727    log_it("Opening IN tape");
     728    if (!
     729        (g_tape_stream =
     730         open_device_via_buffer(bkpinfo->media_device, 'r',
     731                                bkpinfo->internal_tape_block_size))) {
     732        log_OS_error(g_tape_fifo);
     733        log_to_screen("Cannot openin stream device");
     734        return (1);
     735    }
     736    log_to_screen("Reading stream");
     737    log_it("stream device = '%s'", bkpinfo->media_device);
    690738/* skip data disks */
    691   open_evalcall_form ("Skipping data disks on stream");
    692   log_to_screen ("Skipping data disks on stream");
    693   if (!(fout = fopen (outfname, "w")))
    694     {
    695       log_OS_error(outfname);
    696       log_to_screen ("Cannot openout datadisk all.tar.gz file");
    697       return(-1);
    698     }
    699   if (!(datablock = (char*)malloc(256*1024))) { log_to_screen("Unable to malloc 256*1024"); exit(1); }
    700   for (i = 0; i < 32; i++)
    701     {
    702       for (j = 0; j < 4; j++)
    703     {
    704           for(length=0, k=0; length<256*1024; length+=k)
    705             {
    706           k=fread(datablock+length, 1, 256*1024 - length, g_tape_stream);
    707             }
    708           (void) fwrite (datablock, 1, (size_t) length, fout);
    709       g_tape_posK += length/1024;
    710     }
    711       if (i>8) // otherwise, 'buffer' distorts calculations
    712         {
    713           templong = ((i-8) * 4 + j) * 100 / (128-8*4);
    714           update_evalcall_form ((int)(templong));
    715         }
    716     }
    717   paranoid_fclose (fout);
    718   paranoid_free(datablock);
     739    open_evalcall_form("Skipping data disks on stream");
     740    log_to_screen("Skipping data disks on stream");
     741    if (!(fout = fopen(outfname, "w"))) {
     742        log_OS_error(outfname);
     743        log_to_screen("Cannot openout datadisk all.tar.gz file");
     744        return (-1);
     745    }
     746    if (!(datablock = (char *) malloc(256 * 1024))) {
     747        log_to_screen("Unable to malloc 256*1024");
     748        exit(1);
     749    }
     750    for (i = 0; i < 32; i++) {
     751        for (j = 0; j < 4; j++) {
     752            for (length = 0, k = 0; length < 256 * 1024; length += k) {
     753                k = fread(datablock + length, 1, 256 * 1024 - length,
     754                          g_tape_stream);
     755            }
     756            (void) fwrite(datablock, 1, (size_t) length, fout);
     757            g_tape_posK += length / 1024;
     758        }
     759        if (i > 8)              // otherwise, 'buffer' distorts calculations
     760        {
     761            templong = ((i - 8) * 4 + j) * 100 / (128 - 8 * 4);
     762            update_evalcall_form((int) (templong));
     763        }
     764    }
     765    paranoid_fclose(fout);
     766    paranoid_free(datablock);
    719767/* find initial blocks */
    720   res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    721   retval += res;
    722   if (ctrl_chr != BLK_START_OF_TAPE)
    723     {
    724       wrong_marker (BLK_START_OF_TAPE, ctrl_chr);
    725     }
    726   res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    727   retval += res;
    728   if (ctrl_chr != BLK_START_OF_BACKUP)
    729     {
    730       wrong_marker (BLK_START_OF_BACKUP, ctrl_chr);
    731     }
    732   close_evalcall_form ();
    733   log_it ("Saved all.tar.gz to '%s'", outfname);
    734   (void) getcwd (old_cwd, MAX_STR_LEN);
    735   chdir (bkpinfo->tmpdir);
    736   sprintf (tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null", outfname);
    737   paranoid_system(tmp);
    738   paranoid_system ("cp -f tmp/mondo-restore.cfg . 2> /dev/null");
    739   chdir (old_cwd);
    740   unlink (outfname);
    741   return (retval);
     768    res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     769    retval += res;
     770    if (ctrl_chr != BLK_START_OF_TAPE) {
     771        wrong_marker(BLK_START_OF_TAPE, ctrl_chr);
     772    }
     773    res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     774    retval += res;
     775    if (ctrl_chr != BLK_START_OF_BACKUP) {
     776        wrong_marker(BLK_START_OF_BACKUP, ctrl_chr);
     777    }
     778    close_evalcall_form();
     779    log_it("Saved all.tar.gz to '%s'", outfname);
     780    (void) getcwd(old_cwd, MAX_STR_LEN);
     781    chdir(bkpinfo->tmpdir);
     782    sprintf(tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null",
     783            outfname);
     784    paranoid_system(tmp);
     785    paranoid_system("cp -f tmp/mondo-restore.cfg . 2> /dev/null");
     786    chdir(old_cwd);
     787    unlink(outfname);
     788    return (retval);
    742789}
    743790
     
    750797 * @note This should be called only from backup processes.
    751798 */
    752 int
    753 openout_cdstream (char *cddev, int speed)
    754 {
    755     /*@ buffers ******************************************************/
    756   char command[MAX_STR_LEN*2];
    757 
    758     /*@ end vars ****************************************************/
     799int openout_cdstream(char *cddev, int speed)
     800{
     801    /*@ buffers ***************************************************** */
     802    char command[MAX_STR_LEN * 2];
     803
     804    /*@ end vars *************************************************** */
    759805
    760806/*  add 'dummy' if testing */
    761   sprintf (command,
    762        "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    763        cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
     807    sprintf(command,
     808            "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
     809            cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
    764810/*  initialise the catalog */
    765   g_current_media_number = 1;
    766   if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { fatal_error("Cannot alloc mem for tape catalog"); }
    767   g_tapecatalog->entries = 0;
     811    g_current_media_number = 1;
     812    if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
     813        fatal_error("Cannot alloc mem for tape catalog");
     814    }
     815    g_tapecatalog->entries = 0;
    768816/* log stuff */
    769   log_it ("Opening OUT cdstream with the command");
    770   log_it (command);
     817    log_it("Opening OUT cdstream with the command");
     818    log_it(command);
    771819/*  log_it("Let's see what happens, shall we?"); */
    772   g_tape_stream = popen (command, "w");
    773   if (g_tape_stream)
    774     {
    775       return (0);
    776     }
    777   else
    778     {
    779       log_to_screen ("Failed to openout to cdstream (fifo)");
    780       return (1);
    781     }
     820    g_tape_stream = popen(command, "w");
     821    if (g_tape_stream) {
     822        return (0);
     823    } else {
     824        log_to_screen("Failed to openout to cdstream (fifo)");
     825        return (1);
     826    }
    782827}
    783828
     
    789834 * EXISTING DATA on the tape!
    790835 */
    791 int
    792 openout_tape (char *tapedev, long internal_tape_block_size)
     836int openout_tape(char *tapedev, long internal_tape_block_size)
    793837{
    794838//  char sz_call_to_buffer[MAX_STR_LEN];
    795  
    796   g_current_media_number = 1;
    797   if (g_tape_stream) { log_it("FYI - I won't 'openout' the tape. It's already open."); return(0); }
    798   if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { fatal_error("Cannot alloc mem for tape catalog"); }
    799   g_tapecatalog->entries = 0;
    800   g_tape_posK = 0;
    801 
    802   set_tape_block_size_with_mt(tapedev, internal_tape_block_size);
    803   log_it ("Opening OUT tape");
    804   if (!(g_tape_stream = open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) { log_OS_error(g_tape_fifo); log_to_screen ("Cannot openin stream device"); return(1); }
    805   return(0);
     839
     840    g_current_media_number = 1;
     841    if (g_tape_stream) {
     842        log_it("FYI - I won't 'openout' the tape. It's already open.");
     843        return (0);
     844    }
     845    if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
     846        fatal_error("Cannot alloc mem for tape catalog");
     847    }
     848    g_tapecatalog->entries = 0;
     849    g_tape_posK = 0;
     850
     851    set_tape_block_size_with_mt(tapedev, internal_tape_block_size);
     852    log_it("Opening OUT tape");
     853    if (!
     854        (g_tape_stream =
     855         open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) {
     856        log_OS_error(g_tape_fifo);
     857        log_to_screen("Cannot openin stream device");
     858        return (1);
     859    }
     860    return (0);
    806861}
    807862
     
    817872 */
    818873int
    819 read_file_from_stream_to_file (struct s_bkpinfo *bkpinfo, char *outfile,
    820                  long long size)
    821 {
    822 
    823     /*@ int *********************************************************/
    824   int res;
    825 
    826     /*@ end vars ****************************************************/
    827 
    828   res = read_file_from_stream_FULL (bkpinfo, outfile, NULL, size);
    829 
    830   return (res);
     874read_file_from_stream_to_file(struct s_bkpinfo *bkpinfo, char *outfile,
     875                              long long size)
     876{
     877
     878    /*@ int ******************************************************** */
     879    int res;
     880
     881    /*@ end vars *************************************************** */
     882
     883    res = read_file_from_stream_FULL(bkpinfo, outfile, NULL, size);
     884
     885    return (res);
    831886}
    832887
     
    842897 */
    843898int
    844 read_file_from_stream_to_stream (struct s_bkpinfo *bkpinfo, FILE * fout,
    845                    long long size)
    846 {
    847 
    848     /*@ int *********************************************************/
    849   int res;
    850 
    851     /*@ end vars ****************************************************/
    852 
    853   res = read_file_from_stream_FULL (bkpinfo, NULL, fout, size);
     899read_file_from_stream_to_stream(struct s_bkpinfo *bkpinfo, FILE * fout,
     900                                long long size)
     901{
     902
     903    /*@ int ******************************************************** */
     904    int res;
     905
     906    /*@ end vars *************************************************** */
     907
     908    res = read_file_from_stream_FULL(bkpinfo, NULL, fout, size);
    854909/*  fflush(g_tape_stream);
    855910  fflush(fout);*/
    856   return (res);
     911    return (res);
    857912}
    858913
     
    872927 */
    873928int
    874 read_file_from_stream_FULL (struct s_bkpinfo *bkpinfo, char *outfname,
    875               FILE * foutstream, long long orig_size)
    876 {
    877     /*@ buffers ******************************************************/
    878   char *tmp;
    879   char *datablock;
    880   char *temp_fname;
    881   char *temp_cksum;
    882   char *actual_cksum;
     929read_file_from_stream_FULL(struct s_bkpinfo *bkpinfo, char *outfname,
     930                           FILE * foutstream, long long orig_size)
     931{
     932    /*@ buffers ***************************************************** */
     933    char *tmp;
     934    char *datablock;
     935    char *temp_fname;
     936    char *temp_cksum;
     937    char *actual_cksum;
    883938//  char *pA, *pB;
    884939
    885     /*@ int **********************************************************/
    886   int retval = 0;
     940    /*@ int ********************************************************* */
     941    int retval = 0;
    887942#ifdef EXTRA_TAPE_CHECKSUMS
    888   int i, ch;
     943    int i, ch;
    889944#endif
    890   int noof_blocks;
    891   int ctrl_chr;
    892   int res;
    893     /*@ pointers *****************************************************/
    894   FILE *fout;
    895 
    896     /*@ long    ******************************************************/
    897   long bytes_to_write = 0 /*,i */ ;
     945    int noof_blocks;
     946    int ctrl_chr;
     947    int res;
     948    /*@ pointers **************************************************** */
     949    FILE *fout;
     950
     951    /*@ long    ***************************************************** */
     952    long bytes_to_write = 0 /*,i */ ;
    898953//  long bytes_successfully_read_in_this_time = 0;
    899954
    900     /*@ long long ****************************************************/
    901   long long temp_size, size;
    902   long bytes_read, bytes_to_read;
    903   long long total_read_from_tape_for_this_file = 0;
    904   long long where_I_was_before_tape_change = 0;
    905     /*@ unsigned int *************************************************/
    906   /*  unsigned int ch; */
    907   unsigned int crc16;
    908   unsigned int crctt;
    909 
    910   bool had_to_resync=FALSE;
    911 
    912     /*@ init  ********************************************************/
    913   malloc_string(tmp);
    914   malloc_string(temp_fname);
    915   malloc_string(temp_cksum);
    916   malloc_string(actual_cksum);
    917   datablock = malloc(TAPE_BLOCK_SIZE);
    918   crc16 = 0;
    919   crctt = 0;
    920   size = orig_size;
    921 
    922     /*@ end vars ****************************************************/
    923 
    924   res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    925   if (orig_size != temp_size && orig_size != -1)
    926     {
    927       sprintf (tmp,
    928            "output file's size should be %ld K but is apparently %ld K",
    929            (long) size >> 10, (long) temp_size >> 10);
    930       log_to_screen (tmp);
    931     }
    932   if (ctrl_chr != BLK_START_FILE)
    933     {
    934       wrong_marker (BLK_START_FILE, ctrl_chr);
    935       return(1);
    936     }
    937   sprintf (tmp, "Reading file from tape; writing to '%s'; %ld KB", outfname,
    938        (long) size >> 10);
    939 
    940   if (foutstream) { fout = foutstream; }
    941   else { fout = fopen (outfname, "w"); }
    942   if (!fout)
    943     {
    944       log_OS_error (outfname);
    945       log_to_screen ("Cannot openout file");
    946       return(1);
    947     }
    948   total_read_from_tape_for_this_file = 0;
    949   for (noof_blocks = 0; size > 0; noof_blocks++, size-=bytes_to_write, total_read_from_tape_for_this_file+=bytes_read)
    950     {
    951       bytes_to_write = (size < TAPE_BLOCK_SIZE) ? (long)size : TAPE_BLOCK_SIZE;
    952       bytes_to_read = TAPE_BLOCK_SIZE;
    953       bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
    954       while(bytes_read < bytes_to_read)
    955         { // next tape!
    956 //    crctt=crc16=0;
    957           where_I_was_before_tape_change = size;
    958           log_msg(4, "where_I_was_... = %lld", where_I_was_before_tape_change);
    959       start_to_read_from_next_tape(bkpinfo);
    960       log_msg(4, "Started reading from next tape.");
    961       skip_incoming_files_until_we_find_this_one(temp_fname);
    962       log_msg(4, "Skipped irrelevant files OK.");
    963           for(size = orig_size; size > where_I_was_before_tape_change; size-=bytes_to_write)
    964         {
    965           bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
    966         }
    967       log_msg(4, "'size' is now %lld (should be %lld)", size, where_I_was_before_tape_change);
    968           log_to_screen("Successfully re-sync'd tape");
    969       had_to_resync = TRUE;
    970           bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
    971     }
    972 
    973       (void) fwrite (datablock, 1, (size_t) bytes_to_write, fout); // for blocking reasons, bytes_successfully_read_in isn't necessarily the same as bytes_to_write
     955    /*@ long long *************************************************** */
     956    long long temp_size, size;
     957    long bytes_read, bytes_to_read;
     958    long long total_read_from_tape_for_this_file = 0;
     959    long long where_I_was_before_tape_change = 0;
     960    /*@ unsigned int ************************************************ */
     961    /*  unsigned int ch; */
     962    unsigned int crc16;
     963    unsigned int crctt;
     964
     965    bool had_to_resync = FALSE;
     966
     967    /*@ init  ******************************************************* */
     968    malloc_string(tmp);
     969    malloc_string(temp_fname);
     970    malloc_string(temp_cksum);
     971    malloc_string(actual_cksum);
     972    datablock = malloc(TAPE_BLOCK_SIZE);
     973    crc16 = 0;
     974    crctt = 0;
     975    size = orig_size;
     976
     977    /*@ end vars *************************************************** */
     978
     979    res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr);
     980    if (orig_size != temp_size && orig_size != -1) {
     981        sprintf(tmp,
     982                "output file's size should be %ld K but is apparently %ld K",
     983                (long) size >> 10, (long) temp_size >> 10);
     984        log_to_screen(tmp);
     985    }
     986    if (ctrl_chr != BLK_START_FILE) {
     987        wrong_marker(BLK_START_FILE, ctrl_chr);
     988        return (1);
     989    }
     990    sprintf(tmp, "Reading file from tape; writing to '%s'; %ld KB",
     991            outfname, (long) size >> 10);
     992
     993    if (foutstream) {
     994        fout = foutstream;
     995    } else {
     996        fout = fopen(outfname, "w");
     997    }
     998    if (!fout) {
     999        log_OS_error(outfname);
     1000        log_to_screen("Cannot openout file");
     1001        return (1);
     1002    }
     1003    total_read_from_tape_for_this_file = 0;
     1004    for (noof_blocks = 0; size > 0;
     1005         noof_blocks++, size -=
     1006         bytes_to_write, total_read_from_tape_for_this_file +=
     1007         bytes_read) {
     1008        bytes_to_write =
     1009            (size < TAPE_BLOCK_SIZE) ? (long) size : TAPE_BLOCK_SIZE;
     1010        bytes_to_read = TAPE_BLOCK_SIZE;
     1011        bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
     1012        while (bytes_read < bytes_to_read) {    // next tape!
     1013//    crctt=crc16=0;
     1014            where_I_was_before_tape_change = size;
     1015            log_msg(4, "where_I_was_... = %lld",
     1016                    where_I_was_before_tape_change);
     1017            start_to_read_from_next_tape(bkpinfo);
     1018            log_msg(4, "Started reading from next tape.");
     1019            skip_incoming_files_until_we_find_this_one(temp_fname);
     1020            log_msg(4, "Skipped irrelevant files OK.");
     1021            for (size = orig_size; size > where_I_was_before_tape_change;
     1022                 size -= bytes_to_write) {
     1023                bytes_read =
     1024                    fread(datablock, 1, bytes_to_read, g_tape_stream);
     1025            }
     1026            log_msg(4, "'size' is now %lld (should be %lld)", size,
     1027                    where_I_was_before_tape_change);
     1028            log_to_screen("Successfully re-sync'd tape");
     1029            had_to_resync = TRUE;
     1030            bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
     1031        }
     1032
     1033        (void) fwrite(datablock, 1, (size_t) bytes_to_write, fout); // for blocking reasons, bytes_successfully_read_in isn't necessarily the same as bytes_to_write
    9741034
    9751035#ifdef EXTRA_TAPE_CHECKSUMS
    976          for(i=0;i<(int)bytes_to_write;i++)
    977          {
    978          ch=datablock[i];
    979          crc16=updcrcr(crc16,(unsigned)ch);
    980          crctt=updcrc(crctt,(unsigned)ch);
    981          }
     1036        for (i = 0; i < (int) bytes_to_write; i++) {
     1037            ch = datablock[i];
     1038            crc16 = updcrcr(crc16, (unsigned) ch);
     1039            crctt = updcrc(crctt, (unsigned) ch);
     1040        }
    9821041#endif
    983     }
    984   log_msg(6, "Total read from tape for this file = %lld", total_read_from_tape_for_this_file);
    985   log_msg(6, ".......................... Should be %lld", orig_size);
    986   g_tape_posK += total_read_from_tape_for_this_file/1024;
    987   sprintf (actual_cksum, "%04x%04x", crc16, crctt);
    988   if (foutstream)
    989     {               /*log_it("Finished writing to foutstream"); */
    990     }
    991   else
    992     {
    993       paranoid_fclose (fout);
    994     }
    995   res = read_header_block_from_stream (&temp_size, temp_cksum, &ctrl_chr);
    996   if (ctrl_chr != BLK_STOP_FILE)
    997     {
    998       wrong_marker (BLK_STOP_FILE, ctrl_chr);
     1042    }
     1043    log_msg(6, "Total read from tape for this file = %lld",
     1044            total_read_from_tape_for_this_file);
     1045    log_msg(6, ".......................... Should be %lld", orig_size);
     1046    g_tape_posK += total_read_from_tape_for_this_file / 1024;
     1047    sprintf(actual_cksum, "%04x%04x", crc16, crctt);
     1048    if (foutstream) {           /*log_it("Finished writing to foutstream"); */
     1049    } else {
     1050        paranoid_fclose(fout);
     1051    }
     1052    res = read_header_block_from_stream(&temp_size, temp_cksum, &ctrl_chr);
     1053    if (ctrl_chr != BLK_STOP_FILE) {
     1054        wrong_marker(BLK_STOP_FILE, ctrl_chr);
    9991055//      fatal_error("Bad marker"); // return(1);
    1000     }
    1001   if (strcmp (temp_cksum, actual_cksum))
    1002     {
    1003       sprintf (tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
    1004            temp_cksum);
    1005       log_to_screen (tmp);
    1006       sprintf (tmp, "%s (%ld K) is corrupt on tape", temp_fname,
    1007            (long) orig_size >> 10);
    1008       log_to_screen (tmp);
    1009       retval++;
    1010     }
    1011   else
    1012     {
    1013       sprintf (tmp, "%s is GOOD on tape", temp_fname);
    1014       /*      log_it(tmp); */
    1015     }
    1016   paranoid_free(datablock);
    1017   paranoid_free(tmp);
    1018   paranoid_free(temp_fname);
    1019   paranoid_free(temp_cksum);
    1020   paranoid_free(actual_cksum);
    1021   return (retval);
     1056    }
     1057    if (strcmp(temp_cksum, actual_cksum)) {
     1058        sprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
     1059                temp_cksum);
     1060        log_to_screen(tmp);
     1061        sprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname,
     1062                (long) orig_size >> 10);
     1063        log_to_screen(tmp);
     1064        retval++;
     1065    } else {
     1066        sprintf(tmp, "%s is GOOD on tape", temp_fname);
     1067        /*      log_it(tmp); */
     1068    }
     1069    paranoid_free(datablock);
     1070    paranoid_free(tmp);
     1071    paranoid_free(temp_fname);
     1072    paranoid_free(temp_cksum);
     1073    paranoid_free(actual_cksum);
     1074    return (retval);
    10221075}
    10231076
     
    10351088 */
    10361089int
    1037 read_header_block_from_stream (long long *plen, char *filename,
    1038                  int *pcontrol_char)
    1039 {
    1040 
    1041     /*@ buffers ******************************************************/
    1042   char *tempblock;
    1043 
    1044     /*@ int **********************************************************/
    1045   int i, retval;
    1046 
    1047     /*@ end vars ****************************************************/
    1048 
    1049   tempblock = (char*)malloc((size_t) TAPE_BLOCK_SIZE);
    1050 
    1051   for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++)
    1052     {
    1053       tempblock[i] = 0;
    1054     }
    1055   while(!(*pcontrol_char = tempblock[7000]))
    1056     {
    1057       g_tape_posK += fread (tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
    1058     }
     1090read_header_block_from_stream(long long *plen, char *filename,
     1091                              int *pcontrol_char)
     1092{
     1093
     1094    /*@ buffers ***************************************************** */
     1095    char *tempblock;
     1096
     1097    /*@ int ********************************************************* */
     1098    int i, retval;
     1099
     1100    /*@ end vars *************************************************** */
     1101
     1102    tempblock = (char *) malloc((size_t) TAPE_BLOCK_SIZE);
     1103
     1104    for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) {
     1105        tempblock[i] = 0;
     1106    }
     1107    while (!(*pcontrol_char = tempblock[7000])) {
     1108        g_tape_posK +=
     1109            fread(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
     1110                  g_tape_stream) / 1024;
     1111    }
    10591112/*  memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */
    10601113/*  for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */
    1061   memcpy ((char *) plen, tempblock + 7001, sizeof (long long));
    1062   if (strcmp (tempblock + 6000 + *pcontrol_char, "Mondolicious, baby"))
    1063     {
    1064       log_it ("Bad header block at %ld K", (long) g_tape_posK);
    1065     }
    1066   strcpy (filename, tempblock + 1000);
     1114    memcpy((char *) plen, tempblock + 7001, sizeof(long long));
     1115    if (strcmp(tempblock + 6000 + *pcontrol_char, "Mondolicious, baby")) {
     1116        log_it("Bad header block at %ld K", (long) g_tape_posK);
     1117    }
     1118    strcpy(filename, tempblock + 1000);
    10671119/*  strcpy(cksum,tempblock+5555);*/
    10681120/*  log_it( "%s  (reading) fname=%s, filesize=%ld K",
     
    10701122       (long) ((*plen) >> 10));
    10711123*/
    1072   if (*pcontrol_char == BLK_ABORTED_BACKUP)
    1073     {
    1074       log_to_screen ("I can't verify an aborted backup.");
    1075       retval=1;
    1076     }
    1077   else
    1078     { retval=0; }
    1079   for(i=1000; i<1020; i++) { if (tempblock[i]<32 || tempblock[i]>126) { tempblock[i]=' '; } }
    1080   tempblock[i] = '\0';
    1081   log_msg(6, "%s (fname=%s, size=%ld K)", marker_to_string (*pcontrol_char),
    1082        tempblock+1000, (long) (*plen) >> 10);
    1083   paranoid_free(tempblock);
    1084   return (retval);
     1124    if (*pcontrol_char == BLK_ABORTED_BACKUP) {
     1125        log_to_screen("I can't verify an aborted backup.");
     1126        retval = 1;
     1127    } else {
     1128        retval = 0;
     1129    }
     1130    for (i = 1000; i < 1020; i++) {
     1131        if (tempblock[i] < 32 || tempblock[i] > 126) {
     1132            tempblock[i] = ' ';
     1133        }
     1134    }
     1135    tempblock[i] = '\0';
     1136    log_msg(6, "%s (fname=%s, size=%ld K)",
     1137            marker_to_string(*pcontrol_char), tempblock + 1000,
     1138            (long) (*plen) >> 10);
     1139    paranoid_free(tempblock);
     1140    return (retval);
    10851141}
    10861142
     
    10981154 * @return The index of the record we just added.
    10991155 */
    1100 int register_in_tape_catalog(t_archtype type, int number, long aux, char*fn)
    1101 {
    1102   int last;
    1103   char fname[MAX_TAPECAT_FNAME_LEN];
    1104   char *p;
    1105 
    1106   p = strrchr(fn, '/');
    1107   if (p) { p++; } else { p = fn; }
    1108   strncpy(fname, p, MAX_TAPECAT_FNAME_LEN);
    1109   fname[MAX_TAPECAT_FNAME_LEN] = '\0';
    1110   last = g_tapecatalog->entries;
    1111   if (last >= MAX_TAPECATALOG_ENTRIES)
    1112     {
    1113       log_it("Warning - can't log #%d in tape catalog - too many entries already", number);
    1114       return(-1);
    1115     }
    1116   g_tapecatalog->el[last].type = type;
    1117   g_tapecatalog->el[last].number = number;
    1118   g_tapecatalog->el[last].aux = aux;
    1119   g_tapecatalog->el[last].tape_posK = g_tape_posK;
    1120   strcpy(g_tapecatalog->el[last].fname, fname);
    1121   g_tapecatalog->entries ++;
    1122   return(last); // returns the index of the record we've jsut added
     1156int register_in_tape_catalog(t_archtype type, int number, long aux,
     1157                             char *fn)
     1158{
     1159    int last;
     1160    char fname[MAX_TAPECAT_FNAME_LEN];
     1161    char *p;
     1162
     1163    p = strrchr(fn, '/');
     1164    if (p) {
     1165        p++;
     1166    } else {
     1167        p = fn;
     1168    }
     1169    strncpy(fname, p, MAX_TAPECAT_FNAME_LEN);
     1170    fname[MAX_TAPECAT_FNAME_LEN] = '\0';
     1171    last = g_tapecatalog->entries;
     1172    if (last >= MAX_TAPECATALOG_ENTRIES) {
     1173        log_it
     1174            ("Warning - can't log #%d in tape catalog - too many entries already",
     1175             number);
     1176        return (-1);
     1177    }
     1178    g_tapecatalog->el[last].type = type;
     1179    g_tapecatalog->el[last].number = number;
     1180    g_tapecatalog->el[last].aux = aux;
     1181    g_tapecatalog->el[last].tape_posK = g_tape_posK;
     1182    strcpy(g_tapecatalog->el[last].fname, fname);
     1183    g_tapecatalog->entries++;
     1184    return (last);              // returns the index of the record we've jsut added
    11231185}
    11241186
     
    11351197 */
    11361198bool
    1137 should_we_write_to_next_tape (long mediasize,
    1138                   long long length_of_incoming_file)
    1139 {
    1140     /*@ bool's ******************************************************/
    1141   bool we_need_a_new_tape = FALSE;
    1142 
    1143     /*@ end vars ****************************************************/
    1144 
    1145   if (mediasize==0) { return(FALSE); }
    1146   if (mediasize>0 && (g_tape_posK >> 10 >= mediasize))
    1147     {
    1148       log_it("mediasize = %ld", mediasize);
    1149       we_need_a_new_tape = TRUE;
    1150       log_to_screen ("Should have started a new tape/CD already");
    1151     }
    1152   if ((g_tape_posK + length_of_incoming_file / 1024) >> 10 >= mediasize-(SLICE_SIZE*4/1024))
    1153     {
    1154       log_it("g_tape_posK = %ld\nmediasize = %ld\n", g_tape_posK, mediasize);
    1155       we_need_a_new_tape = TRUE;
    1156     }
    1157   return (we_need_a_new_tape);
     1199should_we_write_to_next_tape(long mediasize,
     1200                             long long length_of_incoming_file)
     1201{
     1202    /*@ bool's ***************************************************** */
     1203    bool we_need_a_new_tape = FALSE;
     1204
     1205    /*@ end vars *************************************************** */
     1206
     1207    if (mediasize == 0) {
     1208        return (FALSE);
     1209    }
     1210    if (mediasize > 0 && (g_tape_posK >> 10 >= mediasize)) {
     1211        log_it("mediasize = %ld", mediasize);
     1212        we_need_a_new_tape = TRUE;
     1213        log_to_screen("Should have started a new tape/CD already");
     1214    }
     1215    if ((g_tape_posK + length_of_incoming_file / 1024) >> 10 >=
     1216        mediasize - (SLICE_SIZE * 4 / 1024)) {
     1217        log_it("g_tape_posK = %ld\nmediasize = %ld\n", g_tape_posK,
     1218               mediasize);
     1219        we_need_a_new_tape = TRUE;
     1220    }
     1221    return (we_need_a_new_tape);
    11581222}
    11591223
     
    11661230 * @return 0 for success, nonzero for failure.
    11671231 */
    1168 int skip_incoming_files_until_we_find_this_one(char*the_file_I_was_reading)
    1169 {
    1170   char*pA;
    1171   char*pB;
    1172   int res;
    1173   int ctrl_chr;
    1174   char *temp_fname;
    1175   char *datablock;
    1176   long long temp_size, size;
    1177   long bytes_to_write;
    1178 
    1179   datablock = malloc(TAPE_BLOCK_SIZE);
    1180   malloc_string(temp_fname);
    1181   pB = strrchr(the_file_I_was_reading, '/'); if (pB) { pB++; } else { pB = the_file_I_was_reading; }
    1182   log_msg(1, "skip_incoming_..(%s)", pB);
    1183   log_msg(2, "Looking for initial START_AN_AFIO_OR_SLICE");
    1184   ctrl_chr=-1;
    1185   while(ctrl_chr != BLK_START_AN_AFIO_OR_SLICE)
    1186     {
    1187       res=read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    1188       if (ctrl_chr == BLK_START_AN_AFIO_OR_SLICE)
    1189     { break; }
    1190       log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr);
    1191       wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    1192       log_msg(3, "Still trying to re-sync w/ tape");
    1193     }
    1194   while(ctrl_chr != BLK_START_FILE)
    1195     {
    1196       res=read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    1197       if (ctrl_chr == BLK_START_FILE)
    1198     { break; }
    1199       log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr);
    1200       wrong_marker(BLK_START_FILE, ctrl_chr);
    1201       log_msg(3, "Still trying to re-sync w/ tape");
    1202     }
    1203   pA = strrchr(temp_fname, '/'); if (pA) { pA++; } else { pA = temp_fname; }
    1204   pB = strrchr(the_file_I_was_reading, '/'); if (pB) { pB++; } else { pB = the_file_I_was_reading; }
    1205   while (strcmp(pA, pB))
    1206     {
    1207       log_msg(6, "Skipping %s (it's not %s)", temp_fname, the_file_I_was_reading);
    1208       for(size=temp_size; size>0; size-=bytes_to_write)
    1209         {
    1210           bytes_to_write = (size < TAPE_BLOCK_SIZE) ? (long)size : TAPE_BLOCK_SIZE;
    1211           // FIXME - needs error-checking and -catching
    1212       fread(datablock,1,(size_t) TAPE_BLOCK_SIZE, g_tape_stream);
    1213     }
    1214       res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    1215       if (ctrl_chr != BLK_STOP_FILE) { wrong_marker (BLK_STOP_FILE, ctrl_chr); }
    1216       res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    1217       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); }
    1218       res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    1219       if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); }
    1220       res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr);
    1221       if (ctrl_chr != BLK_START_FILE) { wrong_marker(BLK_START_FILE, ctrl_chr); }
    1222       pA = strrchr(temp_fname, '/'); if (pA) { pA++; } else { pA = temp_fname; }
    1223       pB = strrchr(the_file_I_was_reading, '/'); if (pB) { pB++; } else { pB = the_file_I_was_reading; }
    1224     }
    1225   log_msg(2, "Reading %s (it matches %s)", temp_fname, the_file_I_was_reading);
    1226   paranoid_free(temp_fname);
    1227   paranoid_free(datablock);
    1228   return(0);
     1232int skip_incoming_files_until_we_find_this_one(char
     1233                                               *the_file_I_was_reading)
     1234{
     1235    char *pA;
     1236    char *pB;
     1237    int res;
     1238    int ctrl_chr;
     1239    char *temp_fname;
     1240    char *datablock;
     1241    long long temp_size, size;
     1242    long bytes_to_write;
     1243
     1244    datablock = malloc(TAPE_BLOCK_SIZE);
     1245    malloc_string(temp_fname);
     1246    pB = strrchr(the_file_I_was_reading, '/');
     1247    if (pB) {
     1248        pB++;
     1249    } else {
     1250        pB = the_file_I_was_reading;
     1251    }
     1252    log_msg(1, "skip_incoming_..(%s)", pB);
     1253    log_msg(2, "Looking for initial START_AN_AFIO_OR_SLICE");
     1254    ctrl_chr = -1;
     1255    while (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     1256        res =
     1257            read_header_block_from_stream(&temp_size, temp_fname,
     1258                                          &ctrl_chr);
     1259        if (ctrl_chr == BLK_START_AN_AFIO_OR_SLICE) {
     1260            break;
     1261        }
     1262        log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr);
     1263        wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     1264        log_msg(3, "Still trying to re-sync w/ tape");
     1265    }
     1266    while (ctrl_chr != BLK_START_FILE) {
     1267        res =
     1268            read_header_block_from_stream(&temp_size, temp_fname,
     1269                                          &ctrl_chr);
     1270        if (ctrl_chr == BLK_START_FILE) {
     1271            break;
     1272        }
     1273        log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr);
     1274        wrong_marker(BLK_START_FILE, ctrl_chr);
     1275        log_msg(3, "Still trying to re-sync w/ tape");
     1276    }
     1277    pA = strrchr(temp_fname, '/');
     1278    if (pA) {
     1279        pA++;
     1280    } else {
     1281        pA = temp_fname;
     1282    }
     1283    pB = strrchr(the_file_I_was_reading, '/');
     1284    if (pB) {
     1285        pB++;
     1286    } else {
     1287        pB = the_file_I_was_reading;
     1288    }
     1289    while (strcmp(pA, pB)) {
     1290        log_msg(6, "Skipping %s (it's not %s)", temp_fname,
     1291                the_file_I_was_reading);
     1292        for (size = temp_size; size > 0; size -= bytes_to_write) {
     1293            bytes_to_write =
     1294                (size < TAPE_BLOCK_SIZE) ? (long) size : TAPE_BLOCK_SIZE;
     1295            // FIXME - needs error-checking and -catching
     1296            fread(datablock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream);
     1297        }
     1298        res =
     1299            read_header_block_from_stream(&temp_size, temp_fname,
     1300                                          &ctrl_chr);
     1301        if (ctrl_chr != BLK_STOP_FILE) {
     1302            wrong_marker(BLK_STOP_FILE, ctrl_chr);
     1303        }
     1304        res =
     1305            read_header_block_from_stream(&temp_size, temp_fname,
     1306                                          &ctrl_chr);
     1307        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     1308            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     1309        }
     1310        res =
     1311            read_header_block_from_stream(&temp_size, temp_fname,
     1312                                          &ctrl_chr);
     1313        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     1314            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     1315        }
     1316        res =
     1317            read_header_block_from_stream(&temp_size, temp_fname,
     1318                                          &ctrl_chr);
     1319        if (ctrl_chr != BLK_START_FILE) {
     1320            wrong_marker(BLK_START_FILE, ctrl_chr);
     1321        }
     1322        pA = strrchr(temp_fname, '/');
     1323        if (pA) {
     1324            pA++;
     1325        } else {
     1326            pA = temp_fname;
     1327        }
     1328        pB = strrchr(the_file_I_was_reading, '/');
     1329        if (pB) {
     1330            pB++;
     1331        } else {
     1332            pB = the_file_I_was_reading;
     1333        }
     1334    }
     1335    log_msg(2, "Reading %s (it matches %s)", temp_fname,
     1336            the_file_I_was_reading);
     1337    paranoid_free(temp_fname);
     1338    paranoid_free(datablock);
     1339    return (0);
    12291340}
    12301341
     
    12351346 * @return 0 for success, nonzero for failure.
    12361347 */
    1237 int
    1238 start_to_read_from_next_tape (struct s_bkpinfo *bkpinfo)
    1239 {
    1240     /*@ int **********************************************************/
    1241   int res = 0;
    1242   char *sz_msg;
    1243   int ctrlchr;
    1244   long long temp_size;
    1245   malloc_string(sz_msg);
    1246     /*@ end vars ****************************************************/
    1247 
    1248   paranoid_pclose(g_tape_stream);
    1249   system("sync");system("sync");system("sync");
    1250   log_it ("Next tape requested.");
    1251   insist_on_this_tape_number(g_current_media_number+1); // will increment it, too
    1252   log_it ("Opening IN the next tape");
    1253   if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { log_OS_error(g_tape_fifo); log_to_screen ("Cannot openin stream device"); return(1); }
    1254   g_tape_posK = 0;
    1255   g_sigpipe = FALSE;
    1256   res+=read_header_block_from_stream (&temp_size, sz_msg, &ctrlchr);    /* just in case */
    1257   if (ctrlchr != BLK_START_OF_TAPE) { wrong_marker (BLK_START_OF_TAPE, ctrlchr); }
    1258   res+=read_header_block_from_stream (&temp_size, sz_msg, &ctrlchr);    /* just in case */
    1259   if (ctrlchr != BLK_START_OF_BACKUP) { wrong_marker (BLK_START_OF_BACKUP, ctrlchr); }
    1260   else { log_msg(3, "Next tape opened OK. Whoopee!"); }
    1261   paranoid_free(sz_msg);
    1262   return (res);
     1348int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo)
     1349{
     1350    /*@ int ********************************************************* */
     1351    int res = 0;
     1352    char *sz_msg;
     1353    int ctrlchr;
     1354    long long temp_size;
     1355    malloc_string(sz_msg);
     1356    /*@ end vars *************************************************** */
     1357
     1358    paranoid_pclose(g_tape_stream);
     1359    system("sync");
     1360    system("sync");
     1361    system("sync");
     1362    log_it("Next tape requested.");
     1363    insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too
     1364    log_it("Opening IN the next tape");
     1365    if (!
     1366        (g_tape_stream =
     1367         open_device_via_buffer(bkpinfo->media_device, 'r',
     1368                                bkpinfo->internal_tape_block_size))) {
     1369        log_OS_error(g_tape_fifo);
     1370        log_to_screen("Cannot openin stream device");
     1371        return (1);
     1372    }
     1373    g_tape_posK = 0;
     1374    g_sigpipe = FALSE;
     1375    res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */
     1376    if (ctrlchr != BLK_START_OF_TAPE) {
     1377        wrong_marker(BLK_START_OF_TAPE, ctrlchr);
     1378    }
     1379    res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */
     1380    if (ctrlchr != BLK_START_OF_BACKUP) {
     1381        wrong_marker(BLK_START_OF_BACKUP, ctrlchr);
     1382    } else {
     1383        log_msg(3, "Next tape opened OK. Whoopee!");
     1384    }
     1385    paranoid_free(sz_msg);
     1386    return (res);
    12631387}
    12641388
     
    12701394 * @return 0 for success, nonzero for failure.
    12711395 */
    1272 int
    1273 start_to_write_to_next_tape (struct s_bkpinfo *bkpinfo)
    1274 {
    1275   int res=0;
    1276   char command[MAX_STR_LEN*2];
    1277   paranoid_pclose(g_tape_stream);
    1278   system("sync");system("sync");system("sync");
    1279   log_it ("New tape requested.");
    1280   insist_on_this_tape_number(g_current_media_number+1); // will increment g_current_media, too
    1281   if (g_current_media_number > MAX_NOOF_MEDIA) { res++; log_to_screen("Too many tapes. Man, you need to use nfs!"); }
    1282   if (bkpinfo->backup_media_type == cdstream)
    1283     {
    1284       sprintf (command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, MONDO_LOGFILE);
    1285       log_it ("Opening OUT to next CD with the command");
    1286       log_it (command);
    1287       log_it ("Let's see what happens, shall we?");
    1288       g_tape_stream = popen (command, "w");
    1289       if (!g_tape_stream)
    1290     {
    1291       log_to_screen ("Failed to openout to cdstream (fifo)");
    1292       return (1);
    1293     }
    1294     }
    1295   else
    1296     {
    1297       log_it ("Opening OUT to next tape");
    1298       if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size)))
    1299     {
    1300       log_OS_error(g_tape_fifo);
    1301       log_to_screen ("Cannot openin stream device");
    1302       return(1);
    1303     }
    1304     }
    1305   g_tape_posK = 0;
    1306   g_sigpipe = FALSE;
    1307   res+=write_header_block_to_stream (0, "start-of-tape", BLK_START_OF_TAPE);    /* just in case */
    1308   res+=write_header_block_to_stream (0, "start-of-backup", BLK_START_OF_BACKUP);    /* just in case */
    1309   return (res);
     1396int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo)
     1397{
     1398    int res = 0;
     1399    char command[MAX_STR_LEN * 2];
     1400    paranoid_pclose(g_tape_stream);
     1401    system("sync");
     1402    system("sync");
     1403    system("sync");
     1404    log_it("New tape requested.");
     1405    insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
     1406    if (g_current_media_number > MAX_NOOF_MEDIA) {
     1407        res++;
     1408        log_to_screen("Too many tapes. Man, you need to use nfs!");
     1409    }
     1410    if (bkpinfo->backup_media_type == cdstream) {
     1411        sprintf(command,
     1412                "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
     1413                bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
     1414                MONDO_LOGFILE);
     1415        log_it("Opening OUT to next CD with the command");
     1416        log_it(command);
     1417        log_it("Let's see what happens, shall we?");
     1418        g_tape_stream = popen(command, "w");
     1419        if (!g_tape_stream) {
     1420            log_to_screen("Failed to openout to cdstream (fifo)");
     1421            return (1);
     1422        }
     1423    } else {
     1424        log_it("Opening OUT to next tape");
     1425        if (!
     1426            (g_tape_stream =
     1427             open_device_via_buffer(bkpinfo->media_device, 'w',
     1428                                    bkpinfo->internal_tape_block_size))) {
     1429            log_OS_error(g_tape_fifo);
     1430            log_to_screen("Cannot openin stream device");
     1431            return (1);
     1432        }
     1433    }
     1434    g_tape_posK = 0;
     1435    g_sigpipe = FALSE;
     1436    res += write_header_block_to_stream(0, "start-of-tape", BLK_START_OF_TAPE); /* just in case */
     1437    res += write_header_block_to_stream(0, "start-of-backup", BLK_START_OF_BACKUP); /* just in case */
     1438    return (res);
    13101439}
    13111440
     
    13251454 * @return 0 for success, nonzero for failure.
    13261455 */
    1327 int write_backcatalog_to_tape (struct s_bkpinfo *bkpinfo)
    1328 {
    1329   int i, last, res=0;
    1330   char *fname;
    1331 
    1332   log_msg(2, "I am now writing back catalog to tape");
    1333   malloc_string(fname);
    1334   last = g_tapecatalog->entries-1;
    1335   for(i=0; i<=last; i++)
    1336     {
    1337       sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, g_tapecatalog->el[i].fname);
    1338       if (!does_file_exist(fname))
    1339         { log_msg(6, "Can't write %s - it doesn't exist.", fname); }
    1340       else
    1341         {
    1342           write_header_block_to_stream (length_of_file(fname), "start-backcatalog-afio-or-slice", BLK_START_AN_AFIO_OR_SLICE);
    1343           log_msg(2, "Writing %s", fname);
    1344           if (write_file_to_stream_from_file(bkpinfo, fname))
    1345         { res++; log_msg(2, "%s failed", fname); }
    1346       if (i!=last)
    1347         { write_header_block_to_stream (0, "stop-backcatalog-afio-or-slice", BLK_STOP_AN_AFIO_OR_SLICE); }
    1348         }
    1349     }
    1350   paranoid_free(fname);
    1351   log_msg(2, "Finished writing back catalog to tape");
    1352   return(res);
     1456int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo)
     1457{
     1458    int i, last, res = 0;
     1459    char *fname;
     1460
     1461    log_msg(2, "I am now writing back catalog to tape");
     1462    malloc_string(fname);
     1463    last = g_tapecatalog->entries - 1;
     1464    for (i = 0; i <= last; i++) {
     1465        sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
     1466                g_tapecatalog->el[i].fname);
     1467        if (!does_file_exist(fname)) {
     1468            log_msg(6, "Can't write %s - it doesn't exist.", fname);
     1469        } else {
     1470            write_header_block_to_stream(length_of_file(fname),
     1471                                         "start-backcatalog-afio-or-slice",
     1472                                         BLK_START_AN_AFIO_OR_SLICE);
     1473            log_msg(2, "Writing %s", fname);
     1474            if (write_file_to_stream_from_file(bkpinfo, fname)) {
     1475                res++;
     1476                log_msg(2, "%s failed", fname);
     1477            }
     1478            if (i != last) {
     1479                write_header_block_to_stream(0,
     1480                                             "stop-backcatalog-afio-or-slice",
     1481                                             BLK_STOP_AN_AFIO_OR_SLICE);
     1482            }
     1483        }
     1484    }
     1485    paranoid_free(fname);
     1486    log_msg(2, "Finished writing back catalog to tape");
     1487    return (res);
    13531488}
    13541489
     
    13601495 * @return 0 for success, nonzero for failure.
    13611496 */
    1362 int
    1363 write_data_disks_to_stream (char *fname)
    1364 {
    1365     /*@ pointers ****************************************************/
    1366   FILE *fin;
    1367   char tmp[MAX_STR_LEN];
    1368 
    1369     /*@ long ********************************************************/
    1370   long m = -1;
    1371   long templong;
    1372 
    1373     /*@ int *********************************************************/
    1374   int i,j;
    1375 
    1376     /*@ buffers *****************************************************/
    1377   char tempblock[256 * 1024];
    1378 
    1379     /*@ end vars ****************************************************/
    1380 
    1381   open_evalcall_form ("Writing data disks to tape");
    1382   log_to_screen ("Writing data disks to tape");
    1383   log_it ("Data disks = %s", fname);
    1384   if (!does_file_exist (fname))
    1385     {
    1386       sprintf (tmp, "Cannot find %s", fname);
    1387       log_to_screen (tmp);
    1388       return(1);
    1389     }
    1390   if (!(fin = fopen (fname, "r")))
    1391     {
    1392       log_OS_error (fname);
    1393       fatal_error ("Cannot openin the data disk");
    1394     }
    1395   for (i = 0; i < 32; i++)  /* 32MB */
    1396     {
    1397       for (j = 0; j < 4; j++)   /* 256K x 4 = 1MB (1024K) */
    1398     {
    1399       if (!feof (fin))
    1400         {
    1401           m = (long) fread (tempblock, 1, 256 * 1024, fin);
    1402         }
    1403       else
    1404         {
    1405           m = 0;
    1406         }
    1407       for (; m < 256 * 1024; m++)
    1408         {
    1409           tempblock[m] = '\0';
    1410         }
    1411       g_tape_posK +=
    1412         fwrite (tempblock, 1, 256 * 1024, g_tape_stream) / 1024;
    1413     }
    1414       if (i>g_tape_buffer_size_MB) // otherwise, 'buffer' distorts calculations
    1415         {
    1416           templong = ((i-8) * 4 + j) * 100 / (128-8*4);
    1417           update_evalcall_form ((int)(templong));
    1418         }
    1419     }
    1420   paranoid_fclose (fin);
    1421   close_evalcall_form ();
    1422   return (0);
     1497int write_data_disks_to_stream(char *fname)
     1498{
     1499    /*@ pointers *************************************************** */
     1500    FILE *fin;
     1501    char tmp[MAX_STR_LEN];
     1502
     1503    /*@ long ******************************************************* */
     1504    long m = -1;
     1505    long templong;
     1506
     1507    /*@ int ******************************************************** */
     1508    int i, j;
     1509
     1510    /*@ buffers **************************************************** */
     1511    char tempblock[256 * 1024];
     1512
     1513    /*@ end vars *************************************************** */
     1514
     1515    open_evalcall_form("Writing data disks to tape");
     1516    log_to_screen("Writing data disks to tape");
     1517    log_it("Data disks = %s", fname);
     1518    if (!does_file_exist(fname)) {
     1519        sprintf(tmp, "Cannot find %s", fname);
     1520        log_to_screen(tmp);
     1521        return (1);
     1522    }
     1523    if (!(fin = fopen(fname, "r"))) {
     1524        log_OS_error(fname);
     1525        fatal_error("Cannot openin the data disk");
     1526    }
     1527    for (i = 0; i < 32; i++) {  /* 32MB */
     1528        for (j = 0; j < 4; j++) {   /* 256K x 4 = 1MB (1024K) */
     1529            if (!feof(fin)) {
     1530                m = (long) fread(tempblock, 1, 256 * 1024, fin);
     1531            } else {
     1532                m = 0;
     1533            }
     1534            for (; m < 256 * 1024; m++) {
     1535                tempblock[m] = '\0';
     1536            }
     1537            g_tape_posK +=
     1538                fwrite(tempblock, 1, 256 * 1024, g_tape_stream) / 1024;
     1539        }
     1540        if (i > g_tape_buffer_size_MB)  // otherwise, 'buffer' distorts calculations
     1541        {
     1542            templong = ((i - 8) * 4 + j) * 100 / (128 - 8 * 4);
     1543            update_evalcall_form((int) (templong));
     1544        }
     1545    }
     1546    paranoid_fclose(fin);
     1547    close_evalcall_form();
     1548    return (0);
    14231549}
    14241550
     
    14321558 * @return 0 for success, nonzero for failure.
    14331559 */
    1434 int
    1435 write_file_to_stream_from_file (struct s_bkpinfo *bkpinfo, char *infile)
    1436 {
    1437     /*@ buffers *****************************************************/
    1438   char tmp[MAX_STR_LEN];
    1439   char datablock[TAPE_BLOCK_SIZE];
    1440   char checksum[MAX_STR_LEN];
    1441   char *infile_basename;
    1442 
    1443     /*@ int *********************************************************/
    1444   int retval = 0;
    1445   int noof_blocks;
    1446 
    1447   /*  unsigned int ch; */
    1448   unsigned int crc16;
    1449   unsigned int crctt;
    1450 
    1451     /*@ pointers ****************************************************/
    1452   FILE *fin;
    1453   char *p;
    1454 
    1455     /*@ long ********************************************************/
    1456   long bytes_to_read = 0;
    1457   long i;
    1458 
    1459     /*@ long long ***************************************************/
    1460   long long filesize;
     1560int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo, char *infile)
     1561{
     1562    /*@ buffers **************************************************** */
     1563    char tmp[MAX_STR_LEN];
     1564    char datablock[TAPE_BLOCK_SIZE];
     1565    char checksum[MAX_STR_LEN];
     1566    char *infile_basename;
     1567
     1568    /*@ int ******************************************************** */
     1569    int retval = 0;
     1570    int noof_blocks;
     1571
     1572    /*  unsigned int ch; */
     1573    unsigned int crc16;
     1574    unsigned int crctt;
     1575
     1576    /*@ pointers *************************************************** */
     1577    FILE *fin;
     1578    char *p;
     1579
     1580    /*@ long ******************************************************* */
     1581    long bytes_to_read = 0;
     1582    long i;
     1583
     1584    /*@ long long ************************************************** */
     1585    long long filesize;
    14611586
    14621587#ifdef EXTRA_TAPE_CHECKSUMS
    1463   int ch;
     1588    int ch;
    14641589#endif
    14651590
    1466     /*@ initialize *************************************************/
    1467   crc16 = 0;
    1468   crctt = 0;
    1469 
    1470 
    1471 
    1472     /*@ end vars ****************************************************/
    1473 
    1474   infile_basename = strrchr(infile, '/');
    1475   if (infile_basename) { infile_basename++; } else { infile_basename=infile; }
    1476   filesize = length_of_file (infile);
    1477   if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], filesize))
    1478     {
    1479       start_to_write_to_next_tape (bkpinfo);
    1480       write_backcatalog_to_tape (bkpinfo);
    1481     }
    1482   p = strrchr (infile, '/');
    1483   if (!p)
    1484     {
    1485       p = infile;
    1486     }
    1487   else
    1488     {
    1489       p++;
    1490     }
    1491   sprintf (tmp, "Writing file '%s' to tape (%ld KB)", p,
    1492        (long) filesize >> 10);
    1493   log_it (tmp);
    1494   write_header_block_to_stream (filesize, infile_basename, BLK_START_FILE);
     1591    /*@ initialize ************************************************ */
     1592    crc16 = 0;
     1593    crctt = 0;
     1594
     1595
     1596
     1597    /*@ end vars *************************************************** */
     1598
     1599    infile_basename = strrchr(infile, '/');
     1600    if (infile_basename) {
     1601        infile_basename++;
     1602    } else {
     1603        infile_basename = infile;
     1604    }
     1605    filesize = length_of_file(infile);
     1606    if (should_we_write_to_next_tape
     1607        (bkpinfo->media_size[g_current_media_number], filesize)) {
     1608        start_to_write_to_next_tape(bkpinfo);
     1609        write_backcatalog_to_tape(bkpinfo);
     1610    }
     1611    p = strrchr(infile, '/');
     1612    if (!p) {
     1613        p = infile;
     1614    } else {
     1615        p++;
     1616    }
     1617    sprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,
     1618            (long) filesize >> 10);
     1619    log_it(tmp);
     1620    write_header_block_to_stream(filesize, infile_basename,
     1621                                 BLK_START_FILE);
    14951622//go_here_to_restart_saving_of_file:
    1496   if (!(fin = fopen (infile, "r"))) { log_OS_error(infile); return(1); }
    1497   for (noof_blocks = 0; filesize > 0;
    1498        noof_blocks++, filesize -= bytes_to_read)
    1499     {
    1500       if (filesize < TAPE_BLOCK_SIZE)
    1501     {
    1502       bytes_to_read = (long) filesize;
    1503       for (i = 0; i < TAPE_BLOCK_SIZE; i++)
    1504         {
    1505           datablock[i] = '\0';
    1506         }
    1507     }
    1508       else
    1509     {
    1510       bytes_to_read = TAPE_BLOCK_SIZE;
    1511     }
    1512       (void) fread (datablock, 1, (size_t) bytes_to_read, fin);
    1513       g_tape_posK += fwrite (datablock, 1, /*bytes_to_read */ (size_t) TAPE_BLOCK_SIZE,
    1514                  g_tape_stream) / 1024;
    1515       if (g_sigpipe)
    1516         {
    1517       iamhere("Sigpipe occurred recently. I'll start a new tape.");
    1518       fclose(fin);
    1519       g_sigpipe = FALSE;
    1520           start_to_write_to_next_tape (bkpinfo);
    1521           write_backcatalog_to_tape (bkpinfo); // kinda-sorta recursive :)
    1522       return(0);
    1523         }
     1623    if (!(fin = fopen(infile, "r"))) {
     1624        log_OS_error(infile);
     1625        return (1);
     1626    }
     1627    for (noof_blocks = 0; filesize > 0;
     1628         noof_blocks++, filesize -= bytes_to_read) {
     1629        if (filesize < TAPE_BLOCK_SIZE) {
     1630            bytes_to_read = (long) filesize;
     1631            for (i = 0; i < TAPE_BLOCK_SIZE; i++) {
     1632                datablock[i] = '\0';
     1633            }
     1634        } else {
     1635            bytes_to_read = TAPE_BLOCK_SIZE;
     1636        }
     1637        (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;
     1642        if (g_sigpipe) {
     1643            iamhere("Sigpipe occurred recently. I'll start a new tape.");
     1644            fclose(fin);
     1645            g_sigpipe = FALSE;
     1646            start_to_write_to_next_tape(bkpinfo);
     1647            write_backcatalog_to_tape(bkpinfo); // kinda-sorta recursive :)
     1648            return (0);
     1649        }
    15241650#ifdef EXTRA_TAPE_CHECKSUMS
    1525          for(i=0;i<bytes_to_read;i++)
    1526          {
    1527          ch=datablock[i];
    1528          crc16=updcrcr(crc16,(unsigned)ch);
    1529          crctt=updcrc(crctt,(unsigned)ch);
    1530          }
     1651        for (i = 0; i < bytes_to_read; i++) {
     1652            ch = datablock[i];
     1653            crc16 = updcrcr(crc16, (unsigned) ch);
     1654            crctt = updcrc(crctt, (unsigned) ch);
     1655        }
    15311656#endif
    1532     }
    1533   paranoid_fclose (fin);
    1534   sprintf (checksum, "%04x%04x", crc16, crctt);
    1535   write_header_block_to_stream (g_current_media_number, checksum,
    1536                   BLK_STOP_FILE);
     1657    }
     1658    paranoid_fclose(fin);
     1659    sprintf(checksum, "%04x%04x", crc16, crctt);
     1660    write_header_block_to_stream(g_current_media_number, checksum,
     1661                                BLK_STOP_FILE);
    15371662//  log_it("File '%s' written to tape.", infile);
    1538   return (retval);
     1663    return (retval);
    15391664}
    15401665
     
    15551680 */
    15561681int
    1557 write_header_block_to_stream (long long length_of_incoming_file, char *filename,
    1558                 int control_char)
    1559 {
    1560     /*@ buffers *****************************************************/
    1561   char tempblock[TAPE_BLOCK_SIZE];
    1562   char tmp[MAX_STR_LEN];
    1563   char *p;
    1564 
    1565     /*@ int *********************************************************/
    1566   int i;
    1567 
    1568     /*@ long long ***************************************************/
    1569   long long olen;
    1570 
    1571     /*@ end vars ****************************************************/
    1572 
    1573 
    1574   olen = length_of_incoming_file;
    1575   p = strrchr (filename, '/');  /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */
    1576   if (!p)
    1577     {
    1578       p = filename;
    1579     }
    1580   else
    1581     {
    1582       p++;
    1583     }
    1584   if (!g_tape_stream)
    1585     {
    1586       log_to_screen
    1587     ("You're not backing up to tape. Why write a tape header?");
    1588       return(1);
    1589     }
    1590   for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++)
    1591     {
    1592       tempblock[i] = 0;
    1593     }
    1594   sprintf (tempblock + 6000 + control_char, "Mondolicious, baby");
    1595   tempblock[7000] = control_char;
     1682write_header_block_to_stream(long long length_of_incoming_file,
     1683                             char *filename, int control_char)
     1684{
     1685    /*@ buffers **************************************************** */
     1686    char tempblock[TAPE_BLOCK_SIZE];
     1687    char tmp[MAX_STR_LEN];
     1688    char *p;
     1689
     1690    /*@ int ******************************************************** */
     1691    int i;
     1692
     1693    /*@ long long ************************************************** */
     1694    long long olen;
     1695
     1696    /*@ end vars *************************************************** */
     1697
     1698
     1699    olen = length_of_incoming_file;
     1700    p = strrchr(filename, '/'); /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */
     1701    if (!p) {
     1702        p = filename;
     1703    } else {
     1704        p++;
     1705    }
     1706    if (!g_tape_stream) {
     1707        log_to_screen
     1708            ("You're not backing up to tape. Why write a tape header?");
     1709        return (1);
     1710    }
     1711    for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) {
     1712        tempblock[i] = 0;
     1713    }
     1714    sprintf(tempblock + 6000 + control_char, "Mondolicious, baby");
     1715    tempblock[7000] = control_char;
    15961716/*  for(i=0;i<8;i++) {tempblock[7001+i]=olen&0xff; olen>>=8;} */
    1597   memcpy (tempblock + 7001, (char *) &olen, sizeof (long long));
     1717    memcpy(tempblock + 7001, (char *) &olen, sizeof(long long));
    15981718/*  if (length_of_incoming_file) {memcpy(tempblock+7001,(char*)&length_of_incoming_file,sizeof(long long));} */
    1599   strcpy (tempblock + 1000, filename);
     1719    strcpy(tempblock + 1000, filename);
    16001720/*  strcpy(tempblock+5555,cksum); */
    1601   g_tape_posK += fwrite (tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
    1602   sprintf (tmp, "%s (fname=%s, size=%ld K)", marker_to_string (control_char),
    1603        p, (long) length_of_incoming_file >> 10);
    1604   log_msg(6, tmp);
     1721    g_tape_posK +=
     1722        fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
     1723               g_tape_stream) / 1024;
     1724    sprintf(tmp, "%s (fname=%s, size=%ld K)",
     1725            marker_to_string(control_char), p,
     1726            (long) length_of_incoming_file >> 10);
     1727    log_msg(6, tmp);
    16051728/*  log_tape_pos(); */
    1606   return (0);
     1729    return (0);
    16071730}
    16081731
     
    16211744 * @param it_is What we got.
    16221745 */
    1623 void
    1624 wrong_marker (int should_be, int it_is)
    1625 {
    1626     /*@ buffer ******************************************************/
    1627   char tmp[MAX_STR_LEN];
    1628 
    1629 
    1630     /*@ end vars ****************************************************/
    1631   sprintf (tmp, "Wrong marker! (Should be %s, ",
    1632        marker_to_string (should_be));
    1633   sprintf (tmp + strlen (tmp), "is actually %s)", marker_to_string (it_is));
    1634   log_to_screen (tmp);
     1746void wrong_marker(int should_be, int it_is)
     1747{
     1748    /*@ buffer ***************************************************** */
     1749    char tmp[MAX_STR_LEN];
     1750
     1751
     1752    /*@ end vars *************************************************** */
     1753    sprintf(tmp, "Wrong marker! (Should be %s, ",
     1754            marker_to_string(should_be));
     1755    sprintf(tmp + strlen(tmp), "is actually %s)", marker_to_string(it_is));
     1756    log_to_screen(tmp);
    16351757}
    16361758
  • branches/2.05/mondo/mondo/common/libmondo-stream.h

    r30 r128  
    11/* libmondo-stream.h
    2  * $Id: libmondo-stream.h,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
    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);
  • branches/2.05/mondo/mondo/common/libmondo-string-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-string.c

    r30 r128  
    11/* libmondo-string.c
    2    $Id: libmondo-string.c,v 1.3 2004/06/21 20:20:36 hugo Exp $
     2   $Id$
    33
    44- string manipulation
     
    7171
    7272/*@unused@*/
    73 //static char cvsid[] = "$Id: libmondo-string.c,v 1.3 2004/06/21 20:20:36 hugo Exp $";
     73//static char cvsid[] = "$Id$";
    7474
    7575extern int g_current_media_number;
     
    8989 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
    9090 */
    91 char *
    92 build_partition_name (char *partition, const char *drive, int partno)
    93 {
    94     char *p, *c;
    95 
    96   assert(partition!=NULL);
    97   assert_string_is_neither_NULL_nor_zerolength(drive);
    98   assert(partno>=0);
    99 
    100   p = strcpy(partition, drive);
    101   /* is this a devfs device path? */
    102   c = strrchr (partition, '/');
    103   if (c && strncmp (c, "/disc", 5) == 0) {
    104       /* yup it's devfs, return the "part" path */
    105       strcpy (c + 1, "part");
    106       p = c + 5;
    107   } else {
    108       p += strlen (p);
    109       if (isdigit (p[-1])) {
    110       *p++ =
     91char *build_partition_name(char *partition, const char *drive, int partno)
     92{
     93    char *p, *c;
     94
     95    assert(partition != NULL);
     96    assert_string_is_neither_NULL_nor_zerolength(drive);
     97    assert(partno >= 0);
     98
     99    p = strcpy(partition, drive);
     100    /* is this a devfs device path? */
     101    c = strrchr(partition, '/');
     102    if (c && strncmp(c, "/disc", 5) == 0) {
     103        /* yup it's devfs, return the "part" path */
     104        strcpy(c + 1, "part");
     105        p = c + 5;
     106    } else {
     107        p += strlen(p);
     108        if (isdigit(p[-1])) {
     109            *p++ =
    111110#ifdef BSD
    112          's';
     111                's';
    113112#else
    114              'p';
     113                'p';
    115114#endif
    116       }
    117     }
    118   sprintf (p, "%d", partno);
    119   return (partition);
     115        }
     116    }
     117    sprintf(p, "%d", partno);
     118    return (partition);
    120119}
    121120
     
    137136 * @param width The width of the final result.
    138137 */
    139 void center_string (char *in_out, int width)
    140 {
    141   char scratch[MAX_STR_LEN];
    142   char *p;
    143   int i;            /* purpose */
    144   int len;          /* purpose */
    145   int mid;          /* purpose */
    146   int x;            /* purpose */
    147 
    148   assert(in_out!=NULL);
    149   assert(width>2);
    150 
    151   if (strlen (in_out) == 0)
    152     {
    153       return;
    154     }
    155   for (p = in_out; *p == ' '; p++);
    156   strcpy (scratch, p);
    157   len = (int) strlen (scratch);
    158   mid = width / 2;
    159   x = mid - len / 2;
    160   for (i = 0; i < x; i++)
    161     {
    162       in_out[i] = ' ';
    163     }
    164   in_out[i] = '\0';
    165   strcat (in_out, scratch);
    166 }
    167 
    168 
    169 
    170 
    171 inline void turn_wildcard_chars_into_literal_chars(char*sout, char*sin)
     138void center_string(char *in_out, int width)
     139{
     140    char scratch[MAX_STR_LEN];
     141    char *p;
     142    int i;                      /* purpose */
     143    int len;                    /* purpose */
     144    int mid;                    /* purpose */
     145    int x;                      /* purpose */
     146
     147    assert(in_out != NULL);
     148    assert(width > 2);
     149
     150    if (strlen(in_out) == 0) {
     151        return;
     152    }
     153    for (p = in_out; *p == ' '; p++);
     154    strcpy(scratch, p);
     155    len = (int) strlen(scratch);
     156    mid = width / 2;
     157    x = mid - len / 2;
     158    for (i = 0; i < x; i++) {
     159        in_out[i] = ' ';
     160    }
     161    in_out[i] = '\0';
     162    strcat(in_out, scratch);
     163}
     164
     165
     166
     167
     168inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)
    172169{
    173170    char *p, *q;
    174    
    175     for(p=sin, q=sout; *p!='\0'; *(q++) = *(p++) )
    176       {
    177         if (strchr("[]*?", *p)) { *(q++) = '\\'; }
    178       }
    179     *q = *p; // for the final '\0'
     171
     172    for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) {
     173        if (strchr("[]*?", *p)) {
     174            *(q++) = '\\';
     175        }
     176    }
     177    *q = *p;                    // for the final '\0'
    180178}
    181179
     
    188186 * @note The returned string points to static storage that will be overwritten with each call.
    189187 */
    190 char* commarize(char*input)
    191 {
    192   char pos_w_commas[MAX_STR_LEN];
    193   static char output[MAX_STR_LEN];
    194   char tmp[MAX_STR_LEN];
    195   int j;
    196 
    197   assert(input!=NULL);
    198 
    199   strcpy(tmp, input);
    200   if (strlen(tmp) > 6)
    201     {
    202       strcpy(pos_w_commas, tmp);
    203       j = (int) strlen(pos_w_commas);
    204       tmp[j-6] = ',';
    205       strcpy(tmp+j-5, pos_w_commas+j-6);
     188char *commarize(char *input)
     189{
     190    char pos_w_commas[MAX_STR_LEN];
     191    static char output[MAX_STR_LEN];
     192    char tmp[MAX_STR_LEN];
     193    int j;
     194
     195    assert(input != NULL);
     196
     197    strcpy(tmp, input);
     198    if (strlen(tmp) > 6) {
     199        strcpy(pos_w_commas, tmp);
     200        j = (int) strlen(pos_w_commas);
     201        tmp[j - 6] = ',';
     202        strcpy(tmp + j - 5, pos_w_commas + j - 6);
    206203//      tmp[j-2] = ',';
    207204//      strcpy(tmp+j-1, pos_w_commas+j-3);
    208       strcpy(pos_w_commas, tmp);
    209     }
    210   if (strlen(tmp) > 3)
    211     {
    212       j = (int) strlen(tmp);
    213       strcpy(pos_w_commas, tmp);
    214       pos_w_commas[j-3] = ',';
    215       strcpy(pos_w_commas+j-2, tmp+j-3);
    216     }
    217   else
    218     {
    219       strcpy(pos_w_commas, tmp);
    220     }
    221   strcpy(output, pos_w_commas);
    222   return(output);
     205        strcpy(pos_w_commas, tmp);
     206    }
     207    if (strlen(tmp) > 3) {
     208        j = (int) strlen(tmp);
     209        strcpy(pos_w_commas, tmp);
     210        pos_w_commas[j - 3] = ',';
     211        strcpy(pos_w_commas + j - 2, tmp + j - 3);
     212    } else {
     213        strcpy(pos_w_commas, tmp);
     214    }
     215    strcpy(output, pos_w_commas);
     216    return (output);
    223217}
    224218
     
    241235 * @note The returned string points to static storage and will be overwritten with each call.
    242236 */
    243 char *
    244 disklist_entry_to_string (struct list_of_disks *disklist, int lino)
    245 {
    246 
    247     /*@ buffers ***********************************************************/
    248   static char output[MAX_STR_LEN];
    249 
    250   assert(disklist!=NULL);
    251 
    252   sprintf (output, "%-24s %8d", disklist->el[lino].device,
    253        disklist->el[lino].index);
    254   return (output);
     237char *disklist_entry_to_string(struct list_of_disks *disklist, int lino)
     238{
     239
     240    /*@ buffers ********************************************************** */
     241    static char output[MAX_STR_LEN];
     242
     243    assert(disklist != NULL);
     244
     245    sprintf(output, "%-24s %8d", disklist->el[lino].device,
     246            disklist->el[lino].index);
     247    return (output);
    255248}
    256249
     
    266259 * @return The size in megabytes.
    267260 */
    268 long
    269 friendly_sizestr_to_sizelong (char *incoming)
    270 {
    271   long outval;
    272   int i;
    273   char *tmp;
    274   char ch;
    275 
    276   assert_string_is_neither_NULL_nor_zerolength(incoming);
    277 
    278   malloc_string(tmp);
    279   if (!incoming[0]) { free(tmp); return(0); }
    280   if (strchr(incoming, '.'))
    281     { fatal_error("Please use integers only. No decimal points."); }
    282   strcpy (tmp, incoming);
    283   i = (int) strlen(tmp);
    284   if (tmp[i-1]=='B' || tmp[i-1]=='b') { tmp[i-1]='\0'; }
    285   for (i = 0; i < (int) strlen (tmp) && isdigit (tmp[i]); i++);
    286   ch = tmp[i];
    287   tmp[i] = '\0';
    288   outval = atol (tmp);
    289   if (ch == 'g' || ch == 'G')
    290     {
    291       outval = outval * 1024;
    292     }
    293   else if (ch == 'k' || ch == 'K')
    294     {
    295       outval = outval / 1024;
    296     }
    297   else if (ch == 't' || ch == 'T') // terabyte
    298     {
    299     outval *= 1048576;
    300     }
    301   else if (ch == 'Y' || ch == 'y') // yottabyte - the biggest measure in the info file
    302     {
    303     log_it ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
    304     popup_and_OK ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
    305     fatal_error ("Integer overflow.");
    306     }
    307   else if (ch != 'm' && ch != 'M')
    308     {
    309       sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch);
    310       fatal_error(tmp);
    311     }
    312   paranoid_free(tmp);
    313   return (outval);
     261long friendly_sizestr_to_sizelong(char *incoming)
     262{
     263    long outval;
     264    int i;
     265    char *tmp;
     266    char ch;
     267
     268    assert_string_is_neither_NULL_nor_zerolength(incoming);
     269
     270    malloc_string(tmp);
     271    if (!incoming[0]) {
     272        free(tmp);
     273        return (0);
     274    }
     275    if (strchr(incoming, '.')) {
     276        fatal_error("Please use integers only. No decimal points.");
     277    }
     278    strcpy(tmp, incoming);
     279    i = (int) strlen(tmp);
     280    if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
     281        tmp[i - 1] = '\0';
     282    }
     283    for (i = 0; i < (int) strlen(tmp) && isdigit(tmp[i]); i++);
     284    ch = tmp[i];
     285    tmp[i] = '\0';
     286    outval = atol(tmp);
     287    if (ch == 'g' || ch == 'G') {
     288        outval = outval * 1024;
     289    } else if (ch == 'k' || ch == 'K') {
     290        outval = outval / 1024;
     291    } else if (ch == 't' || ch == 'T')  // terabyte
     292    {
     293        outval *= 1048576;
     294    } else if (ch == 'Y' || ch == 'y')  // yottabyte - the biggest measure in the info file
     295    {
     296        log_it
     297            ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
     298        popup_and_OK
     299            ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
     300        fatal_error("Integer overflow.");
     301    } else if (ch != 'm' && ch != 'M') {
     302        sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')",
     303                incoming, ch);
     304        fatal_error(tmp);
     305    }
     306    paranoid_free(tmp);
     307    return (outval);
    314308}
    315309
     
    324318 * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?
    325319 */
    326 char *
    327 leftpad_string (char *incoming, int width)
    328 {
    329     /*@ buffers ******************************************************/
    330   static char output[MAX_STR_LEN];
    331 
    332     /*@ ints *********************************************************/
    333   int i;
    334 
    335     /*@ end vars *****************************************************/
    336   assert(incoming!=NULL);
    337   assert(width>2);
    338 
    339   strcpy (output, incoming);
    340   for (i = (int) strlen (output); i < width; i++)
    341     {
    342       output[i] = ' ';
    343     }
    344   output[i] = '\0';
    345   return (output);
     320char *leftpad_string(char *incoming, int width)
     321{
     322    /*@ buffers ***************************************************** */
     323    static char output[MAX_STR_LEN];
     324
     325    /*@ ints ******************************************************** */
     326    int i;
     327
     328    /*@ end vars **************************************************** */
     329    assert(incoming != NULL);
     330    assert(width > 2);
     331
     332    strcpy(output, incoming);
     333    for (i = (int) strlen(output); i < width; i++) {
     334        output[i] = ' ';
     335    }
     336    output[i] = '\0';
     337    return (output);
    346338}
    347339
     
    355347 * @note The returned string points to static storage that will be overwritten with each call.
    356348 */
    357 char *
    358 marker_to_string (int marker)
    359 {
    360     /*@ buffer *******************************************************/
    361   static char outstr[MAX_STR_LEN];
    362 
    363 
    364     /*@ end vars ****************************************************/
    365 
    366   switch (marker)
    367     {
    368     case BLK_START_OF_BACKUP:
    369       strcpy (outstr, "BLK_START_OF_BACKUP");
    370       break;
    371     case BLK_START_OF_TAPE:
    372       strcpy (outstr, "BLK_START_OF_TAPE");
    373       break;
    374     case BLK_START_AN_AFIO_OR_SLICE:
    375       strcpy (outstr, "BLK_START_AN_AFIO_OR_SLICE");
    376       break;
    377     case BLK_STOP_AN_AFIO_OR_SLICE:
    378       strcpy (outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
    379       break;
    380     case BLK_START_AFIOBALLS:
    381       strcpy (outstr, "BLK_START_AFIOBALLS");
    382       break;
    383     case BLK_STOP_AFIOBALLS:
    384       strcpy (outstr, "BLK_STOP_AFIOBALLS");
    385       break;
    386     case BLK_STOP_BIGGIEFILES:
    387       strcpy (outstr, "BLK_STOP_BIGGIEFILES");
    388       break;
    389     case BLK_START_A_NORMBIGGIE:
    390       strcpy (outstr, "BLK_START_A_NORMBIGGIE");
    391       break;
    392     case BLK_START_A_PIHBIGGIE:
    393       strcpy (outstr, "BLK_START_A_PIHBIGGIE");
    394       break;
    395     case BLK_START_EXTENDED_ATTRIBUTES:
    396       strcpy (outstr, "BLK_START_EXTENDED_ATTRIBUTES");
    397       break;
    398     case BLK_STOP_EXTENDED_ATTRIBUTES:
    399       strcpy (outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
    400       break;
    401     case BLK_START_EXAT_FILE:
    402       strcpy (outstr, "BLK_START_EXAT_FILE");
    403       break;
    404     case BLK_STOP_EXAT_FILE:
    405       strcpy (outstr, "BLK_STOP_EXAT_FILE");
    406       break;
    407     case BLK_START_BIGGIEFILES:
    408       strcpy (outstr, "BLK_START_BIGGIEFILES");
    409       break;
    410     case BLK_STOP_A_BIGGIE:
    411       strcpy (outstr, "BLK_STOP_A_BIGGIE");
    412       break;
    413     case BLK_END_OF_TAPE:
    414       strcpy (outstr, "BLK_END_OF_TAPE");
    415       break;
    416     case BLK_END_OF_BACKUP:
    417       strcpy (outstr, "BLK_END_OF_BACKUP");
    418       break;
    419     case BLK_ABORTED_BACKUP:
    420       strcpy (outstr, "BLK_ABORTED_BACKUP");
    421       break;
    422     case BLK_START_FILE:
    423       strcpy (outstr, "BLK_START_FILE");
    424       break;
    425     case BLK_STOP_FILE:
    426       strcpy (outstr, "BLK_STOP_FILE");
    427       break;
    428     default:
    429       sprintf (outstr, "BLK_UNKNOWN (%d)", marker);
    430       break;
    431     }
    432   return (outstr);
     349char *marker_to_string(int marker)
     350{
     351    /*@ buffer ****************************************************** */
     352    static char outstr[MAX_STR_LEN];
     353
     354
     355    /*@ end vars *************************************************** */
     356
     357    switch (marker) {
     358    case BLK_START_OF_BACKUP:
     359        strcpy(outstr, "BLK_START_OF_BACKUP");
     360        break;
     361    case BLK_START_OF_TAPE:
     362        strcpy(outstr, "BLK_START_OF_TAPE");
     363        break;
     364    case BLK_START_AN_AFIO_OR_SLICE:
     365        strcpy(outstr, "BLK_START_AN_AFIO_OR_SLICE");
     366        break;
     367    case BLK_STOP_AN_AFIO_OR_SLICE:
     368        strcpy(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
     369        break;
     370    case BLK_START_AFIOBALLS:
     371        strcpy(outstr, "BLK_START_AFIOBALLS");
     372        break;
     373    case BLK_STOP_AFIOBALLS:
     374        strcpy(outstr, "BLK_STOP_AFIOBALLS");
     375        break;
     376    case BLK_STOP_BIGGIEFILES:
     377        strcpy(outstr, "BLK_STOP_BIGGIEFILES");
     378        break;
     379    case BLK_START_A_NORMBIGGIE:
     380        strcpy(outstr, "BLK_START_A_NORMBIGGIE");
     381        break;
     382    case BLK_START_A_PIHBIGGIE:
     383        strcpy(outstr, "BLK_START_A_PIHBIGGIE");
     384        break;
     385    case BLK_START_EXTENDED_ATTRIBUTES:
     386        strcpy(outstr, "BLK_START_EXTENDED_ATTRIBUTES");
     387        break;
     388    case BLK_STOP_EXTENDED_ATTRIBUTES:
     389        strcpy(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
     390        break;
     391    case BLK_START_EXAT_FILE:
     392        strcpy(outstr, "BLK_START_EXAT_FILE");
     393        break;
     394    case BLK_STOP_EXAT_FILE:
     395        strcpy(outstr, "BLK_STOP_EXAT_FILE");
     396        break;
     397    case BLK_START_BIGGIEFILES:
     398        strcpy(outstr, "BLK_START_BIGGIEFILES");
     399        break;
     400    case BLK_STOP_A_BIGGIE:
     401        strcpy(outstr, "BLK_STOP_A_BIGGIE");
     402        break;
     403    case BLK_END_OF_TAPE:
     404        strcpy(outstr, "BLK_END_OF_TAPE");
     405        break;
     406    case BLK_END_OF_BACKUP:
     407        strcpy(outstr, "BLK_END_OF_BACKUP");
     408        break;
     409    case BLK_ABORTED_BACKUP:
     410        strcpy(outstr, "BLK_ABORTED_BACKUP");
     411        break;
     412    case BLK_START_FILE:
     413        strcpy(outstr, "BLK_START_FILE");
     414        break;
     415    case BLK_STOP_FILE:
     416        strcpy(outstr, "BLK_STOP_FILE");
     417        break;
     418    default:
     419        sprintf(outstr, "BLK_UNKNOWN (%d)", marker);
     420        break;
     421    }
     422    return (outstr);
    433423}
    434424
     
    447437 * @note The returned string points to static storage and will be overwritten with each call.
    448438 */
    449 char *
    450 mountlist_entry_to_string (struct mountlist_itself *mountlist, int lino)
    451 {
    452 
    453     /*@ buffer ************************************************************/
    454   static char output[MAX_STR_LEN];
    455 
    456   assert(mountlist!=NULL);
    457 
    458   sprintf (output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
    459        mountlist->el[lino].mountpoint, mountlist->el[lino].format,
    460        mountlist->el[lino].size / 1024);
    461   return (output);
     439char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
     440                                int lino)
     441{
     442
     443    /*@ buffer *********************************************************** */
     444    static char output[MAX_STR_LEN];
     445
     446    assert(mountlist != NULL);
     447
     448    sprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
     449            mountlist->el[lino].mountpoint, mountlist->el[lino].format,
     450            mountlist->el[lino].size / 1024);
     451    return (output);
    462452}
    463453
     
    475465 * @note The returned string points to static storage and will be overwritten with each call.
    476466 */
    477 char *
    478 number_of_disks_as_string (int noof_disks, char *label)
    479 {
    480 
    481     /*@ buffers **********************************************************/
    482   static char output[MAX_STR_LEN];
    483 
    484     /*@ char     *********************************************************/
    485   char p;
    486 
    487   assert(label!=NULL);
    488 
    489   if (noof_disks > 1)
    490     {
    491       p = 's';
    492     }
    493   else
    494     {
    495       p = ' ';
    496     }
    497   sprintf (output, "%d %s disk%c", noof_disks, label, p);
    498   while (strlen (output) < 14)
    499     {
    500       strcat (output, " ");
    501     }
    502   return (output);
     467char *number_of_disks_as_string(int noof_disks, char *label)
     468{
     469
     470    /*@ buffers ********************************************************* */
     471    static char output[MAX_STR_LEN];
     472
     473    /*@ char     ******************************************************** */
     474    char p;
     475
     476    assert(label != NULL);
     477
     478    if (noof_disks > 1) {
     479        p = 's';
     480    } else {
     481        p = ' ';
     482    }
     483    sprintf(output, "%d %s disk%c", noof_disks, label, p);
     484    while (strlen(output) < 14) {
     485        strcat(output, " ");
     486    }
     487    return (output);
    503488}
    504489
     
    512497 * @note The returned value points to static strorage that will be overwritten with each call.
    513498 */
    514 char *
    515 number_to_text (int i)
    516 {
    517 
    518     /*@ buffers ******************************************************/
    519   static char output[MAX_STR_LEN];
    520 
    521 
    522     /*@ end vars ****************************************************/
    523 
    524   switch (i)
    525     {
    526     case 0:
    527       strcpy (output, "zero");
    528       break;
    529     case 1:
    530       strcpy (output, "one");
    531       break;
    532     case 2:
    533       strcpy (output, "two");
    534       break;
    535     case 3:
    536       strcpy (output, "three");
    537       break;
    538     case 4:
    539       strcpy (output, "four");
    540       break;
    541     case 5:
    542       strcpy (output, "five");
    543       break;
    544     case 6:
    545       strcpy (output, "six");
    546       break;
    547     case 7:
    548       strcpy (output, "seven");
    549       break;
    550     case 8:
    551       strcpy (output, "eight");
    552       break;
    553     case 9:
    554       strcpy (output, "nine");
    555     case 10:
    556       strcpy (output, "ten");
    557     default:
    558       sprintf (output, "%d", i);
    559     }
    560   return (output);
     499char *number_to_text(int i)
     500{
     501
     502    /*@ buffers ***************************************************** */
     503    static char output[MAX_STR_LEN];
     504
     505
     506    /*@ end vars *************************************************** */
     507
     508    switch (i) {
     509    case 0:
     510        strcpy(output, "zero");
     511        break;
     512    case 1:
     513        strcpy(output, "one");
     514        break;
     515    case 2:
     516        strcpy(output, "two");
     517        break;
     518    case 3:
     519        strcpy(output, "three");
     520        break;
     521    case 4:
     522        strcpy(output, "four");
     523        break;
     524    case 5:
     525        strcpy(output, "five");
     526        break;
     527    case 6:
     528        strcpy(output, "six");
     529        break;
     530    case 7:
     531        strcpy(output, "seven");
     532        break;
     533    case 8:
     534        strcpy(output, "eight");
     535        break;
     536    case 9:
     537        strcpy(output, "nine");
     538    case 10:
     539        strcpy(output, "ten");
     540    default:
     541        sprintf(output, "%d", i);
     542    }
     543    return (output);
    561544}
    562545
     
    571554 * @param value The value to replace @p token.
    572555 */
    573 void
    574 resolve_naff_tokens (char *output, char *ip, char *value, char *token)
    575 {
    576     /*@ buffers ****/
    577   char *input;
    578 
    579     /*@ pointers **/
    580   char *p;
    581 
    582   input = malloc(2000);
    583   assert_string_is_neither_NULL_nor_zerolength(ip);
    584   assert_string_is_neither_NULL_nor_zerolength(token);
    585   assert(value!=NULL);
    586 
    587   strcpy (output, ip);      /* just in case the token doesn't appear in string at all */
    588   for (strcpy (input, ip); strstr (input, token); strcpy (input, output))
    589     {
    590       strcpy (output, input);
    591       p = strstr (output, token);
    592       *p = '\0';
    593       strcat (output, value);
    594       p = strstr (input, token) + strlen (token);
    595       strcat (output, p);
    596     }
    597   paranoid_free(input);
     556void resolve_naff_tokens(char *output, char *ip, char *value, char *token)
     557{
     558    /*@ buffers *** */
     559    char *input;
     560
     561    /*@ pointers * */
     562    char *p;
     563
     564    input = malloc(2000);
     565    assert_string_is_neither_NULL_nor_zerolength(ip);
     566    assert_string_is_neither_NULL_nor_zerolength(token);
     567    assert(value != NULL);
     568
     569    strcpy(output, ip);         /* just in case the token doesn't appear in string at all */
     570    for (strcpy(input, ip); strstr(input, token); strcpy(input, output)) {
     571        strcpy(output, input);
     572        p = strstr(output, token);
     573        *p = '\0';
     574        strcat(output, value);
     575        p = strstr(input, token) + strlen(token);
     576        strcat(output, p);
     577    }
     578    paranoid_free(input);
    598579}
    599580
     
    617598 * @note The returned value points to static storage and will be overwritten with each call.
    618599 */
    619 char *
    620 slice_fname (long bigfileno, long sliceno, char *path, char *s)
    621 {
    622 
    623     /*@ buffers *****************************************************/
    624   static char output[MAX_STR_LEN];
    625   static char suffix[MAX_STR_LEN];
    626 
    627     /*@ end vars ****************************************************/
    628 
    629   assert_string_is_neither_NULL_nor_zerolength(path);
    630   if (s[0] != '\0')
    631     {
    632       sprintf (suffix, ".%s", s);
    633     }
    634   else
    635     {
    636       suffix[0] = '\0';
    637     }
    638   sprintf (output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
    639        suffix);
    640   return (output);
     600char *slice_fname(long bigfileno, long sliceno, char *path, char *s)
     601{
     602
     603    /*@ buffers **************************************************** */
     604    static char output[MAX_STR_LEN];
     605    static char suffix[MAX_STR_LEN];
     606
     607    /*@ end vars *************************************************** */
     608
     609    assert_string_is_neither_NULL_nor_zerolength(path);
     610    if (s[0] != '\0') {
     611        sprintf(suffix, ".%s", s);
     612    } else {
     613        suffix[0] = '\0';
     614    }
     615    sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
     616            suffix);
     617    return (output);
    641618}
    642619
     
    650627 * @return The character for this iteration.
    651628 */
    652 int
    653 special_dot_char (int i)
    654 {
    655   switch (i % 4)
    656     {
    657     case 0:
    658       return ('/');
    659     case 1:
    660       return ('-');
    661     case 2:
    662       return ('\\');
    663     case 3:
    664       return ('|');
    665     default:
    666       return ('.');
    667     }
    668   return ('.');
     629int special_dot_char(int i)
     630{
     631    switch (i % 4) {
     632    case 0:
     633        return ('/');
     634    case 1:
     635        return ('-');
     636    case 2:
     637        return ('\\');
     638    case 3:
     639        return ('|');
     640    default:
     641        return ('.');
     642    }
     643    return ('.');
    669644}
    670645
     
    682657 */
    683658bool
    684 spread_flaws_across_three_lines (char *flaws_str, char *flaws_str_A,
    685                  char *flaws_str_B, char *flaws_str_C,
    686                  int res)
    687 {
    688 
    689     /*@ int **************************************************************/
    690   int i = 0;
    691 
    692     /*@ initialize *******************************************************/
    693   assert(flaws_str_A!=NULL);
    694   assert(flaws_str_B!=NULL);
    695   assert(flaws_str_C!=NULL);
    696   assert(flaws_str!=NULL);
    697 
    698   flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0';
    699 
    700 
    701   if (!res && !strlen (flaws_str))
    702     {
    703       return (TRUE);
    704     }
    705   if (strlen (flaws_str) > 0)
    706     {
    707       sprintf (flaws_str_A, "%s", flaws_str + 1);
    708     }
    709   if (strlen (flaws_str_A) >= 74)
    710     {
    711       for (i = 74; flaws_str_A[i] != ' '; i--);
    712       strcpy (flaws_str_B, flaws_str_A + i + 1);
    713       flaws_str_A[i] = '\0';
    714     }
    715   if (strlen (flaws_str_B) >= 74)
    716     {
    717       for (i = 74; flaws_str_B[i] != ' '; i--);
    718       strcpy (flaws_str_C, flaws_str_B + i + 1);
    719       flaws_str_B[i] = '\0';
    720     }
    721   if (res)
    722     {
    723       return (FALSE);
    724     }
    725   else
    726     {
    727       return (TRUE);
    728     }
     659spread_flaws_across_three_lines(char *flaws_str, char *flaws_str_A,
     660                                char *flaws_str_B, char *flaws_str_C,
     661                                int res)
     662{
     663
     664    /*@ int ************************************************************* */
     665    int i = 0;
     666
     667    /*@ initialize ****************************************************** */
     668    assert(flaws_str_A != NULL);
     669    assert(flaws_str_B != NULL);
     670    assert(flaws_str_C != NULL);
     671    assert(flaws_str != NULL);
     672
     673    flaws_str_A[0] = flaws_str_B[0] = flaws_str_C[0] = '\0';
     674
     675
     676    if (!res && !strlen(flaws_str)) {
     677        return (TRUE);
     678    }
     679    if (strlen(flaws_str) > 0) {
     680        sprintf(flaws_str_A, "%s", flaws_str + 1);
     681    }
     682    if (strlen(flaws_str_A) >= 74) {
     683        for (i = 74; flaws_str_A[i] != ' '; i--);
     684        strcpy(flaws_str_B, flaws_str_A + i + 1);
     685        flaws_str_A[i] = '\0';
     686    }
     687    if (strlen(flaws_str_B) >= 74) {
     688        for (i = 74; flaws_str_B[i] != ' '; i--);
     689        strcpy(flaws_str_C, flaws_str_B + i + 1);
     690        flaws_str_B[i] = '\0';
     691    }
     692    if (res) {
     693        return (FALSE);
     694    } else {
     695        return (TRUE);
     696    }
    729697}
    730698
     
    740708 * there are any in the middle those will be sorted ASCIIbetically.
    741709 */
    742 int
    743 strcmp_inc_numbers (char *stringA, char *stringB)
    744 {
    745     /*@ int **********************************************************/
    746   int i;
    747   int start_of_numbers_in_A;
    748   int start_of_numbers_in_B;
    749   int res;
    750 
    751     /*@ long ********************************************************/
    752   long numA;
    753   long numB;
    754 
    755     /*@ end vars ****************************************************/
    756   assert(stringA!=NULL);
    757   assert(stringB!=NULL);
    758 
    759   if (strlen (stringA) == strlen (stringB))
    760     {
    761       return (strcmp (stringA, stringB));
    762     }
    763   for (i = (int) strlen (stringA); i > 0 && isdigit (stringA[i - 1]); i--);
    764   if (i == (int) strlen (stringA))
    765     {
    766       return (strcmp (stringA, stringB));
    767     }
    768   start_of_numbers_in_A = i;
    769   for (i = (int) strlen (stringB); i > 0 && isdigit (stringB[i - 1]); i--);
    770   if (i == (int) strlen (stringB))
    771     {
    772       return (strcmp (stringA, stringB));
    773     }
    774   start_of_numbers_in_B = i;
    775   if (start_of_numbers_in_A != start_of_numbers_in_B)
    776     {
    777       return (strcmp (stringA, stringB));
    778     }
    779   res = strncmp (stringA, stringB, (size_t) i);
    780   if (res)
    781     {
    782       return (res);
    783     }
    784   numA = atol (stringA + start_of_numbers_in_A);
    785   numB = atol (stringB + start_of_numbers_in_B);
    786   /*
    787      sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);
    788      log_to_screen(tmp);
    789    */
    790   return ((int) (numA - numB));
     710int strcmp_inc_numbers(char *stringA, char *stringB)
     711{
     712    /*@ int ********************************************************* */
     713    int i;
     714    int start_of_numbers_in_A;
     715    int start_of_numbers_in_B;
     716    int res;
     717
     718    /*@ long ******************************************************* */
     719    long numA;
     720    long numB;
     721
     722    /*@ end vars *************************************************** */
     723    assert(stringA != NULL);
     724    assert(stringB != NULL);
     725
     726    if (strlen(stringA) == strlen(stringB)) {
     727        return (strcmp(stringA, stringB));
     728    }
     729    for (i = (int) strlen(stringA); i > 0 && isdigit(stringA[i - 1]); i--);
     730    if (i == (int) strlen(stringA)) {
     731        return (strcmp(stringA, stringB));
     732    }
     733    start_of_numbers_in_A = i;
     734    for (i = (int) strlen(stringB); i > 0 && isdigit(stringB[i - 1]); i--);
     735    if (i == (int) strlen(stringB)) {
     736        return (strcmp(stringA, stringB));
     737    }
     738    start_of_numbers_in_B = i;
     739    if (start_of_numbers_in_A != start_of_numbers_in_B) {
     740        return (strcmp(stringA, stringB));
     741    }
     742    res = strncmp(stringA, stringB, (size_t) i);
     743    if (res) {
     744        return (res);
     745    }
     746    numA = atol(stringA + start_of_numbers_in_A);
     747    numB = atol(stringB + start_of_numbers_in_B);
     748    /*
     749       sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);
     750       log_to_screen(tmp);
     751     */
     752    return ((int) (numA - numB));
    791753}
    792754
     
    801763 * @note The returned string points to static storage that will be overwritten with each call.
    802764 */
    803 char *
    804 strip_afio_output_line (char *input)
    805 {
    806     /*@ buffer *******************************************************/
    807   static char output[MAX_STR_LEN];
    808 
    809     /*@ pointers *****************************************************/
    810   char *p;
    811   char *q;
    812     /*@ end vars ****************************************************/
    813 
    814   assert(input!=NULL);
    815   strcpy (output, input);
    816   p = strchr (input, '\"');
    817   if (p)
    818     {
    819       q = strchr (++p, '\"');
    820       if (q)
    821     {
    822       strcpy (output, p);
    823       *(strchr (output, '\"')) = '\0';
    824     }
    825     }
    826   return (output);
     765char *strip_afio_output_line(char *input)
     766{
     767    /*@ buffer ****************************************************** */
     768    static char output[MAX_STR_LEN];
     769
     770    /*@ pointers **************************************************** */
     771    char *p;
     772    char *q;
     773    /*@ end vars *************************************************** */
     774
     775    assert(input != NULL);
     776    strcpy(output, input);
     777    p = strchr(input, '\"');
     778    if (p) {
     779        q = strchr(++p, '\"');
     780        if (q) {
     781            strcpy(output, p);
     782            *(strchr(output, '\"')) = '\0';
     783        }
     784    }
     785    return (output);
    827786}
    828787
     
    834793 * @param in_out The string to strip spaces/control characters from (modified).
    835794 */
    836 void
    837 strip_spaces (char *in_out)
    838 {
    839     /*@ buffers ******************************************************/
    840   char *tmp;
    841 
    842     /*@ pointers *****************************************************/
    843   char *p;
    844 
    845     /*@ int *********************************************************/
    846   int i;
    847   int original_incoming_length;
    848 
    849     /*@ end vars ****************************************************/
    850 
    851   assert(in_out!=NULL);
    852   malloc_string(tmp);
    853   original_incoming_length = (int) strlen(in_out);
    854   for (i = 0; in_out[i] <= ' ' && i < (int) strlen (in_out); i++);
    855   strcpy (tmp, in_out + i);
    856   for (i = (int) strlen (tmp); i>0 && tmp[i - 1] <= 32; i--);
    857   tmp[i] = '\0';
    858   for (i = 0; i < original_incoming_length && MAX_STR_LEN; i++)
    859     {
    860       in_out[i] = ' ';
    861     }
    862   in_out[i] = '\0';
    863   i = 0;
    864   p = tmp;
    865   while (*p != '\0')
    866     {
    867       in_out[i] = *(p++);
    868       in_out[i + 1] = '\0';
    869       if (in_out[i] < 32 && i > 0)
    870     {
    871       if (in_out[i] == 8)
    872         {
    873           i--;
    874         }
    875       else if (in_out[i] == 9)
    876         {
    877           in_out[i++] = ' ';
    878         }
    879       else if (in_out[i] == '\r') // added 1st October 2003 -- FIXME
    880         {
    881               strcpy(tmp, in_out+i);
    882           strcpy(in_out,tmp);
    883           i=-1;
    884           continue;
    885         }
    886       else if (in_out[i] == '\t')
    887         {
    888           for (i++; i % 5; i++);
    889         }
    890       else if (in_out[i] >= 10 && in_out[i] <= 13)
    891         {
    892           break;
    893         }
    894       else
    895         {
    896           i--;
    897         }
    898     }
    899       else
    900     {
    901       i++;
    902     }
    903     }
    904   in_out[i] = '\0';
    905   paranoid_free(tmp);
     795void strip_spaces(char *in_out)
     796{
     797    /*@ buffers ***************************************************** */
     798    char *tmp;
     799
     800    /*@ pointers **************************************************** */
     801    char *p;
     802
     803    /*@ int ******************************************************** */
     804    int i;
     805    int original_incoming_length;
     806
     807    /*@ end vars *************************************************** */
     808
     809    assert(in_out != NULL);
     810    malloc_string(tmp);
     811    original_incoming_length = (int) strlen(in_out);
     812    for (i = 0; in_out[i] <= ' ' && i < (int) strlen(in_out); i++);
     813    strcpy(tmp, in_out + i);
     814    for (i = (int) strlen(tmp); i > 0 && tmp[i - 1] <= 32; i--);
     815    tmp[i] = '\0';
     816    for (i = 0; i < original_incoming_length && MAX_STR_LEN; i++) {
     817        in_out[i] = ' ';
     818    }
     819    in_out[i] = '\0';
     820    i = 0;
     821    p = tmp;
     822    while (*p != '\0') {
     823        in_out[i] = *(p++);
     824        in_out[i + 1] = '\0';
     825        if (in_out[i] < 32 && i > 0) {
     826            if (in_out[i] == 8) {
     827                i--;
     828            } else if (in_out[i] == 9) {
     829                in_out[i++] = ' ';
     830            } else if (in_out[i] == '\r')   // added 1st October 2003 -- FIXME
     831            {
     832                strcpy(tmp, in_out + i);
     833                strcpy(in_out, tmp);
     834                i = -1;
     835                continue;
     836            } else if (in_out[i] == '\t') {
     837                for (i++; i % 5; i++);
     838            } else if (in_out[i] >= 10 && in_out[i] <= 13) {
     839                break;
     840            } else {
     841                i--;
     842            }
     843        } else {
     844            i++;
     845        }
     846    }
     847    in_out[i] = '\0';
     848    paranoid_free(tmp);
    906849/*  for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */
    907850}
     
    914857 * @return @p incoming.
    915858 */
    916 char *
    917 trim_empty_quotes (char *incoming)
    918 {
    919     /*@ buffer *******************************************************/
    920   static char outgoing[MAX_STR_LEN];
    921 
    922     /*@ end vars ****************************************************/
    923   assert(incoming!=NULL);
    924 
    925   if (incoming[0] == '\"' && incoming[strlen (incoming) - 1] == '\"')
    926     {
    927       strcpy (outgoing, incoming + 1);
    928       outgoing[strlen (outgoing) - 1] = '\0';
    929     }
    930   else
    931     {
    932       strcpy (outgoing, incoming);
    933     }
    934   return (outgoing);
     859char *trim_empty_quotes(char *incoming)
     860{
     861    /*@ buffer ****************************************************** */
     862    static char outgoing[MAX_STR_LEN];
     863
     864    /*@ end vars *************************************************** */
     865    assert(incoming != NULL);
     866
     867    if (incoming[0] == '\"' && incoming[strlen(incoming) - 1] == '\"') {
     868        strcpy(outgoing, incoming + 1);
     869        outgoing[strlen(outgoing) - 1] = '\0';
     870    } else {
     871        strcpy(outgoing, incoming);
     872    }
     873    return (outgoing);
    935874}
    936875
     
    943882 * @return @p partition.
    944883 */
    945 char *
    946 truncate_to_drive_name (char *partition)
    947 {
    948   int i = strlen (partition) - 1;
    949   char *c;
     884char *truncate_to_drive_name(char *partition)
     885{
     886    int i = strlen(partition) - 1;
     887    char *c;
    950888
    951889#ifdef __FreeBSD__
    952890
    953   if (islower (partition[i])) // BSD subpartition
    954       i--;
    955   if (partition[i - 1] == 's') {
    956       while (isdigit (partition[i]))
    957       i--;
    958       i--;
    959   }
    960   partition[i + 1] = '\0';
     891    if (islower(partition[i]))  // BSD subpartition
     892        i--;
     893    if (partition[i - 1] == 's') {
     894        while (isdigit(partition[i]))
     895            i--;
     896        i--;
     897    }
     898    partition[i + 1] = '\0';
    961899
    962900#else
    963901
    964   assert_string_is_neither_NULL_nor_zerolength(partition);
    965   /* first see if it's a devfs style device */
    966   c = strrchr(partition, '/');
    967   if (c && strncmp(c, "/part", 5) == 0) {
    968     /* yup it's devfs, return the "disc" path */
    969     strcpy(c + 1, "disc");
    970     return partition;
    971   }
    972 
    973   for (i = strlen (partition); isdigit (partition[i - 1]); i--)
    974     continue;
    975   if (partition[i - 1] == 'p' && isdigit (partition[i - 2]))
    976     {
    977       i--;
    978     }
    979   partition[i] = '\0';
     902    assert_string_is_neither_NULL_nor_zerolength(partition);
     903    /* first see if it's a devfs style device */
     904    c = strrchr(partition, '/');
     905    if (c && strncmp(c, "/part", 5) == 0) {
     906        /* yup it's devfs, return the "disc" path */
     907        strcpy(c + 1, "disc");
     908        return partition;
     909    }
     910
     911    for (i = strlen(partition); isdigit(partition[i - 1]); i--)
     912        continue;
     913    if (partition[i - 1] == 'p' && isdigit(partition[i - 2])) {
     914        i--;
     915    }
     916    partition[i] = '\0';
    980917
    981918#endif
    982919
    983   return partition;
     920    return partition;
    984921}
    985922
     
    996933 * @note The returned value points to static storage that will be overwritten with each call.
    997934 */
    998 char *
    999 turn_raid_level_number_to_string (int raid_level)
    1000 {
    1001 
    1002     /*@ buffer ***********************************************************/
    1003   static char output[MAX_STR_LEN];
    1004 
    1005 
    1006 
    1007   if (raid_level >= 0)
    1008     {
    1009       sprintf (output, " RAID %-2d ", raid_level);
    1010     }
    1011   else
    1012     {
    1013       sprintf (output, "Linear RAID");
    1014     }
    1015   return (output);
     935char *turn_raid_level_number_to_string(int raid_level)
     936{
     937
     938    /*@ buffer ********************************************************** */
     939    static char output[MAX_STR_LEN];
     940
     941
     942
     943    if (raid_level >= 0) {
     944        sprintf(output, " RAID %-2d ", raid_level);
     945    } else {
     946        sprintf(output, "Linear RAID");
     947    }
     948    return (output);
    1016949}
    1017950
     
    1033966int severity_of_difference(char *fn, char *out_reason)
    1034967{
    1035   int sev;
    1036   char *reason;
    1037   char *filename;
    1038 
    1039   malloc_string(reason);
    1040   malloc_string(filename);
     968    int sev;
     969    char *reason;
     970    char *filename;
     971
     972    malloc_string(reason);
     973    malloc_string(filename);
    1041974// out_reason might be null on purpose, so don't bomb if it is :) OK?
    1042   assert_string_is_neither_NULL_nor_zerolength(fn);
    1043   if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING)))
    1044     { strcpy(filename, fn+strlen(MNT_RESTORING)); }
    1045   else if (fn[0]!='/')
    1046     { sprintf(filename, "/%s", fn); }
    1047   else
    1048     { strcpy(filename, fn); }
    1049 
    1050   sev = 3;
    1051   sprintf(reason, "Changed since backup. Consider running a differential backup in a day or two.");
    1052   if (!strncmp(filename, "/var/", 5)) { sev = 2; sprintf(reason, "/var's contents will change regularly, inevitably."); }
    1053   if (!strncmp(filename, "/home", 5)) { sev = 2; sprintf(reason, "It's in your /home partiton. Therefore, it is important."); }
    1054   if (!strncmp(filename, "/usr/", 5)) { sev = 3; sprintf(reason, "You may have installed/removed software during the backup."); }
    1055   if (!strncmp(filename, "/etc/", 5)) { sev = 3; sprintf(reason, "Do not edit config files while backing up your PC."); }
    1056   if (!strcmp(filename, "/etc/adjtime") || !strcmp(filename, "/etc/mtab")) { sev = 1; sprintf(reason, "This file changes all the time. It's OK."); }
    1057   if (!strncmp(filename, "/root/", 6)) { sev = 3; sprintf(reason, "Were you compiling/editing something in /root?"); }
    1058   if (!strncmp(filename, "/root/.", 7)) { sev = 2; sprintf(reason, "Temp or 'dot' files changed in /root."); }
    1059   if (!strncmp(filename, "/var/lib/", 9)) { sev = 2; sprintf(reason, "Did you add/remove software during backing?"); }
    1060   if (!strncmp(filename, "/var/lib/rpm", 12)) { sev = 3; sprintf(reason, "Did you add/remove software during backing?"); }
    1061   if (!strncmp(filename, "/var/lib/slocate", 16)) { sev = 1; sprintf(reason, "The 'update' daemon ran during backup. This does not affect the integrity of your backup."); }
    1062   if (!strncmp(filename, "/var/log/", 9) || strstr(filename,"/.xsession") || !strcmp(filename+strlen(filename)-4, ".log")) { sev = 1; sprintf(reason, "Log files change frequently as the computer runs. Fret not."); }
    1063   if (!strncmp(filename, "/var/spool", 10)) { sev = 1; sprintf(reason, "Background processes or printers were active. This does not affect the integrity of your backup."); }
    1064   if (!strncmp(filename, "/var/spool/mail", 10)) { sev = 2; sprintf(reason, "Mail was sent/received during backup."); }
    1065   if (filename[strlen(filename)-1]== '~')
    1066     { sev = 1; sprintf(reason, "Backup copy of another file which was modified recently."); }
    1067   if (strstr(filename, "cache"))
    1068     { sev = 1; sprintf(reason, "Part of a cache of data. Caches change from time to time. Don't worry."); }
    1069   if (!strncmp(filename, "/var/run/", 9) || !strncmp(filename, "/var/lock", 8) || strstr(filename, "/.DCOPserver") || strstr(filename, "/.MCOP") || strstr(filename, "/.Xauthority"))
    1070     { sev = 1; sprintf(reason, "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); }
    1071   if (out_reason) { strcpy(out_reason,reason); }
    1072   paranoid_free(filename);
    1073   paranoid_free(reason);
    1074   return(sev);
     975    assert_string_is_neither_NULL_nor_zerolength(fn);
     976    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
     977        strcpy(filename, fn + strlen(MNT_RESTORING));
     978    } else if (fn[0] != '/') {
     979        sprintf(filename, "/%s", fn);
     980    } else {
     981        strcpy(filename, fn);
     982    }
     983
     984    sev = 3;
     985    sprintf(reason,
     986            "Changed since backup. Consider running a differential backup in a day or two.");
     987    if (!strncmp(filename, "/var/", 5)) {
     988        sev = 2;
     989        sprintf(reason,
     990                "/var's contents will change regularly, inevitably.");
     991    }
     992    if (!strncmp(filename, "/home", 5)) {
     993        sev = 2;
     994        sprintf(reason,
     995                "It's in your /home partiton. Therefore, it is important.");
     996    }
     997    if (!strncmp(filename, "/usr/", 5)) {
     998        sev = 3;
     999        sprintf(reason,
     1000                "You may have installed/removed software during the backup.");
     1001    }
     1002    if (!strncmp(filename, "/etc/", 5)) {
     1003        sev = 3;
     1004        sprintf(reason,
     1005                "Do not edit config files while backing up your PC.");
     1006    }
     1007    if (!strcmp(filename, "/etc/adjtime")
     1008        || !strcmp(filename, "/etc/mtab")) {
     1009        sev = 1;
     1010        sprintf(reason, "This file changes all the time. It's OK.");
     1011    }
     1012    if (!strncmp(filename, "/root/", 6)) {
     1013        sev = 3;
     1014        sprintf(reason, "Were you compiling/editing something in /root?");
     1015    }
     1016    if (!strncmp(filename, "/root/.", 7)) {
     1017        sev = 2;
     1018        sprintf(reason, "Temp or 'dot' files changed in /root.");
     1019    }
     1020    if (!strncmp(filename, "/var/lib/", 9)) {
     1021        sev = 2;
     1022        sprintf(reason, "Did you add/remove software during backing?");
     1023    }
     1024    if (!strncmp(filename, "/var/lib/rpm", 12)) {
     1025        sev = 3;
     1026        sprintf(reason, "Did you add/remove software during backing?");
     1027    }
     1028    if (!strncmp(filename, "/var/lib/slocate", 16)) {
     1029        sev = 1;
     1030        sprintf(reason,
     1031                "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");
     1032    }
     1033    if (!strncmp(filename, "/var/log/", 9)
     1034        || strstr(filename, "/.xsession")
     1035        || !strcmp(filename + strlen(filename) - 4, ".log")) {
     1036        sev = 1;
     1037        sprintf(reason,
     1038                "Log files change frequently as the computer runs. Fret not.");
     1039    }
     1040    if (!strncmp(filename, "/var/spool", 10)) {
     1041        sev = 1;
     1042        sprintf(reason,
     1043                "Background processes or printers were active. This does not affect the integrity of your backup.");
     1044    }
     1045    if (!strncmp(filename, "/var/spool/mail", 10)) {
     1046        sev = 2;
     1047        sprintf(reason, "Mail was sent/received during backup.");
     1048    }
     1049    if (filename[strlen(filename) - 1] == '~') {
     1050        sev = 1;
     1051        sprintf(reason,
     1052                "Backup copy of another file which was modified recently.");
     1053    }
     1054    if (strstr(filename, "cache")) {
     1055        sev = 1;
     1056        sprintf(reason,
     1057                "Part of a cache of data. Caches change from time to time. Don't worry.");
     1058    }
     1059    if (!strncmp(filename, "/var/run/", 9)
     1060        || !strncmp(filename, "/var/lock", 8)
     1061        || strstr(filename, "/.DCOPserver") || strstr(filename, "/.MCOP")
     1062        || strstr(filename, "/.Xauthority")) {
     1063        sev = 1;
     1064        sprintf(reason,
     1065                "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
     1066    }
     1067    if (out_reason) {
     1068        strcpy(out_reason, reason);
     1069    }
     1070    paranoid_free(filename);
     1071    paranoid_free(reason);
     1072    return (sev);
    10751073}
    10761074
     
    10841082 * @return The return value of strcmp().
    10851083 */
    1086 int compare_two_filelist_entries(void*va,void*vb)
    1087 {
    1088   static int res;
    1089   struct s_filelist_entry *fa, *fb;
    1090 
    1091   assert(va!=NULL);
    1092   assert(vb!=NULL);
    1093   fa = (struct s_filelist_entry*)va;
    1094   fb = (struct s_filelist_entry*)vb;
    1095   res = strcmp(fa->filename, fb->filename);
    1096   return(res);
     1084int compare_two_filelist_entries(void *va, void *vb)
     1085{
     1086    static int res;
     1087    struct s_filelist_entry *fa, *fb;
     1088
     1089    assert(va != NULL);
     1090    assert(vb != NULL);
     1091    fa = (struct s_filelist_entry *) va;
     1092    fb = (struct s_filelist_entry *) vb;
     1093    res = strcmp(fa->filename, fb->filename);
     1094    return (res);
    10971095}
    10981096
     
    11131111 * @note The returned string points to static storage that will be overwritten with each call.
    11141112 */
    1115 char *
    1116 percent_media_full_comment (struct s_bkpinfo *bkpinfo)
    1117 {
    1118     /*@ int ************************************************/
    1119   int percentage;
    1120   int j;
    1121 
    1122     /*@ buffers ********************************************/
    1123   static char outstr[MAX_STR_LEN];
    1124   char *pos_w_commas, *tmp;
    1125 
    1126   assert(bkpinfo!=NULL);
    1127   malloc_string(pos_w_commas);
    1128   malloc_string(tmp);
    1129   sprintf(tmp, "%lld", g_tape_posK);
    1130   strcpy(pos_w_commas, commarize(tmp));
    1131 
    1132 
    1133 
    1134   if (bkpinfo->media_size[g_current_media_number]<=0)
     1113char *percent_media_full_comment(struct s_bkpinfo *bkpinfo)
     1114{
     1115    /*@ int *********************************************** */
     1116    int percentage;
     1117    int j;
     1118
     1119    /*@ buffers ******************************************* */
     1120    static char outstr[MAX_STR_LEN];
     1121    char *pos_w_commas, *tmp;
     1122
     1123    assert(bkpinfo != NULL);
     1124    malloc_string(pos_w_commas);
     1125    malloc_string(tmp);
     1126    sprintf(tmp, "%lld", g_tape_posK);
     1127    strcpy(pos_w_commas, commarize(tmp));
     1128
     1129
     1130
     1131    if (bkpinfo->media_size[g_current_media_number] <= 0)
    11351132//    { fatal_error( "percentage_media_full_comment() - unknown media size"); }
    1136     {
    1137       sprintf( outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
    1138       return( outstr );
    1139     }
     1133    {
     1134        sprintf(outstr, "Volume %d: %s kilobytes archived so far",
     1135                g_current_media_number, pos_w_commas);
     1136        return (outstr);
     1137    }
    11401138
    11411139/* update screen */
    1142   if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
    1143     {
    1144       percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size[g_current_media_number]);
    1145       if (percentage > 100)
    1146     {
    1147       percentage = 100;
    1148     }
    1149       sprintf (outstr, "Volume %d: [", g_current_media_number);
    1150     }
    1151   else
    1152     {
    1153       percentage =
    1154     (int) (space_occupied_by_cd (bkpinfo->scratchdir) * 100 / 1024 /
    1155            bkpinfo->media_size[g_current_media_number]);
    1156       sprintf (outstr, "%s %d: [", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    1157     }
    1158   for (j = 0; j < percentage; j += 5)
    1159     {
    1160       strcat (outstr, "*");
    1161     }
    1162   for (; j < 100; j += 5)
    1163     {
    1164       strcat (outstr, ".");
    1165     }
    1166   j = (int) strlen (outstr);
    1167   sprintf (outstr + j, "] %d%% used", percentage);
    1168   paranoid_free(pos_w_commas);
    1169   paranoid_free(tmp);
    1170   return (outstr);
     1140    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1141        percentage =
     1142            (int) (g_tape_posK / 10 /
     1143                   bkpinfo->media_size[g_current_media_number]);
     1144        if (percentage > 100) {
     1145            percentage = 100;
     1146        }
     1147        sprintf(outstr, "Volume %d: [", g_current_media_number);
     1148    } else {
     1149        percentage =
     1150            (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 /
     1151                   bkpinfo->media_size[g_current_media_number]);
     1152        sprintf(outstr, "%s %d: [",
     1153                media_descriptor_string(bkpinfo->backup_media_type),
     1154                g_current_media_number);
     1155    }
     1156    for (j = 0; j < percentage; j += 5) {
     1157        strcat(outstr, "*");
     1158    }
     1159    for (; j < 100; j += 5) {
     1160        strcat(outstr, ".");
     1161    }
     1162    j = (int) strlen(outstr);
     1163    sprintf(outstr + j, "] %d%% used", percentage);
     1164    paranoid_free(pos_w_commas);
     1165    paranoid_free(tmp);
     1166    return (outstr);
    11711167}
    11721168
     
    11791175char *media_descriptor_string(t_bkptype type_of_bkp)
    11801176{
    1181   static char *type_of_backup=NULL;
    1182  
    1183   if (!type_of_backup)
    1184     { malloc_string(type_of_backup); }
    1185    
    1186   switch(type_of_bkp)
    1187     {
     1177    static char *type_of_backup = NULL;
     1178
     1179    if (!type_of_backup) {
     1180        malloc_string(type_of_backup);
     1181    }
     1182
     1183    switch (type_of_bkp) {
    11881184    case dvd:
    11891185        strcpy(type_of_backup, "DVD");
     
    12131209        strcpy(type_of_backup, "ISO");
    12141210    }
    1215   return(type_of_backup);
     1211    return (type_of_backup);
    12161212}
    12171213
  • branches/2.05/mondo/mondo/common/libmondo-string.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-tools-EXT.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-tools.c

    r126 r128  
    199199 * @{
    200200 */
    201 bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
    202     g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
    203 bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
     201bool g_remount_cdrom_at_end,    ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
     202 g_remount_floppy_at_end;       ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
     203bool g_cd_recovery;             ///< TRUE if we're making an "autonuke" backup.
    204204double g_kernel_version;
    205205
     
    207207 * The place where /boot is mounted.
    208208 */
    209 char *g_boot_mountpt=NULL;
     209char *g_boot_mountpt = NULL;
    210210
    211211/**
    212212 * The location of Mondo's home directory.
    213213 */
    214 char *g_mondo_home=NULL;
     214char *g_mondo_home = NULL;
    215215
    216216/**
    217217 * The serial string (used to differentiate between backups) of the current backup.
    218218 */
    219 char *g_serial_string=NULL;
     219char *g_serial_string = NULL;
    220220
    221221/**
    222222 * The location where tmpfs is mounted, or "" if it's not mounted.
    223223 */
    224 char *g_tmpfs_mountpt=NULL;
    225 char *g_magicdev_command=NULL;
     224char *g_tmpfs_mountpt = NULL;
     225char *g_magicdev_command = NULL;
    226226
    227227/**
    228228 * The default maximum level to log messages at or below.
    229229 */
    230 int g_loglevel=DEFAULT_DEBUG_LEVEL;
     230int g_loglevel = DEFAULT_DEBUG_LEVEL;
    231231
    232232/* @} - end of globalGroup */
     
    255255 * @param exp The expression that failed (as a string).
    256256 */
    257 void _mondo_assert_fail (const char *file,
    258              const char *function,
    259              int         line,
    260              const char *exp)
    261 {
    262     static int ignoring_assertions = 0;
    263     bool is_valid = TRUE;
    264 
    265     log_it ("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line, function);
    266     if (ignoring_assertions) {
    267     log_it ("Well, the user doesn't care...");
    268     return;
    269     }
    270 
     257void _mondo_assert_fail(const char *file,
     258                        const char *function, int line, const char *exp)
     259{
     260    static int ignoring_assertions = 0;
     261    bool is_valid = TRUE;
     262
     263    log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
     264           function);
     265    if (ignoring_assertions) {
     266        log_it("Well, the user doesn't care...");
     267        return;
     268    }
    271269#ifndef _XWIN
    272     if (!g_text_mode)
    273     newtSuspend();
    274 #endif
    275     printf ("ASSERTION FAILED: `%s'\n", exp);
    276     printf ("\tat %s:%d in %s\n\n", file, line, function);
    277     printf ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
    278     do {
    279     is_valid = TRUE;
    280     switch (toupper (getchar())) {
    281     case 'A': // ignore (A)ll
    282         ignoring_assertions = 1;
    283         break;
    284     case 'B': // a(B)ort
    285         signal (SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
    286         raise (SIGABRT);
    287         break;          /* "can't get here" */
    288     case 'D': // (D)ebug, aka asm("int 3")
     270    if (!g_text_mode)
     271        newtSuspend();
     272#endif
     273    printf("ASSERTION FAILED: `%s'\n", exp);
     274    printf("\tat %s:%d in %s\n\n", file, line, function);
     275    printf("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
     276    do {
     277        is_valid = TRUE;
     278        switch (toupper(getchar())) {
     279        case 'A':               // ignore (A)ll
     280            ignoring_assertions = 1;
     281            break;
     282        case 'B':               // a(B)ort
     283            signal(SIGABRT, SIG_DFL);   /* prevent SIGABRT handler from running */
     284            raise(SIGABRT);
     285            break;              /* "can't get here" */
     286        case 'D':               // (D)ebug, aka asm("int 3")
    289287#ifdef __IA32__
    290         __asm__ __volatile__ ("int $3"); // break to debugger
    291 #endif
    292         break;
    293     case 'E': // (E)xit
    294         fatal_error ("Failed assertion -- see above for details");
    295         break;          /* "can't get here" */
    296     case 'I': // (I)gnore
    297         break;
    298     /* These next two work as follows:
    299        the `default' catches the user's invalid choice and says so;
    300        the '\n' catches the newline on the end and prints the prompt again.
    301     */
    302     case '\n':
    303         printf ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
    304         break;
    305     default:
    306         is_valid = FALSE;
    307         printf ("Invalid choice.\n");
    308         break;
    309     }
    310     } while (!is_valid);
    311 
    312     if (ignoring_assertions) {
    313     log_it ("Ignoring ALL assertions from now on.");
    314     } else {
    315     log_it ("Ignoring assertion: %s", exp);
    316     }
    317 
    318     getchar(); // skip \n
     288            __asm__ __volatile__("int $3"); // break to debugger
     289#endif
     290            break;
     291        case 'E':               // (E)xit
     292            fatal_error("Failed assertion -- see above for details");
     293            break;              /* "can't get here" */
     294        case 'I':               // (I)gnore
     295            break;
     296            /* These next two work as follows:
     297               the `default' catches the user's invalid choice and says so;
     298               the '\n' catches the newline on the end and prints the prompt again.
     299             */
     300        case '\n':
     301            printf
     302                ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
     303            break;
     304        default:
     305            is_valid = FALSE;
     306            printf("Invalid choice.\n");
     307            break;
     308        }
     309    } while (!is_valid);
     310
     311    if (ignoring_assertions) {
     312        log_it("Ignoring ALL assertions from now on.");
     313    } else {
     314        log_it("Ignoring assertion: %s", exp);
     315    }
     316
     317    getchar();                  // skip \n
    319318
    320319#ifndef _XWIN
    321     if (!g_text_mode)
    322     newtResume();
     320    if (!g_text_mode)
     321        newtResume();
    323322#endif
    324323}
     
    330329void clean_up_KDE_desktop_if_necessary(void)
    331330{
    332   char *tmp;
    333 
    334   malloc_string(tmp);
    335   strcpy(tmp, "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
     331    char *tmp;
     332
     333    malloc_string(tmp);
     334    strcpy(tmp,
     335           "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
    336336file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
    337337cat $file.old | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
    338338else { print $0;};}' > $file ; fi ; done");
    339   run_program_and_log_output(tmp, 5);
    340   paranoid_free(tmp);
     339    run_program_and_log_output(tmp, 5);
     340    paranoid_free(tmp);
    341341}
    342342
     
    351351int find_and_store_mondoarchives_home(char *home_sz)
    352352{
    353   assert(home_sz!=NULL);
    354   strcpy (home_sz,
    355       call_program_and_get_last_line_of_output
    356       ("find /usr/lib/ /usr/local/ /usr/share/ /usr/local/share/ /opt/ /ramdisk/usr/share/ -type d -maxdepth 2 -name include -prune -o -type d -maxdepth 2 -path '*/mondo/restore-scripts' -printf '%h\n' 2> /dev/null"));
    357 
    358   if (home_sz[0] == '\0')
    359     {
    360       strcpy (home_sz,
    361           call_program_and_get_last_line_of_output
    362           ("find /usr -type d -path '*/mondo/restore-scripts' -follow -maxdepth 3 -printf '%h\n' 2> /dev/null"));
    363     }
    364   if (home_sz[0] == '\0')
    365     {
    366       return(1);
    367     }
    368   else
    369     {
    370       return(0);
    371     }
     353    assert(home_sz != NULL);
     354    strcpy(home_sz,
     355           call_program_and_get_last_line_of_output
     356           ("find /usr/lib/ /usr/local/ /usr/share/ /usr/local/share/ /opt/ /ramdisk/usr/share/ -type d -maxdepth 2 -name include -prune -o -type d -maxdepth 2 -path '*/mondo/restore-scripts' -printf '%h\n' 2> /dev/null"));
     357
     358    if (home_sz[0] == '\0') {
     359        strcpy(home_sz,
     360               call_program_and_get_last_line_of_output
     361               ("find /usr -type d -path '*/mondo/restore-scripts' -follow -maxdepth 3 -printf '%h\n' 2> /dev/null"));
     362    }
     363    if (home_sz[0] == '\0') {
     364        return (1);
     365    } else {
     366        return (0);
     367    }
    372368}
    373369
     
    376372{
    377373#ifdef __IA32__
    378     return("i386");
     374    return ("i386");
    379375#endif
    380376#ifdef __IA64__
    381     return("ia64");
    382 #endif
    383     return("unknown");
     377    return ("ia64");
     378#endif
     379    return ("unknown");
    384380}
    385381
     
    388384double get_kernel_version()
    389385{
    390   char *p, tmp[200];
    391   double d;
     386    char *p, tmp[200];
     387    double d;
    392388#ifdef __FreeBSD__
    393   // JOSH - FIXME :)
    394   d = 5.2; // :-)
     389    // JOSH - FIXME :)
     390    d = 5.2;                    // :-)
    395391#else
    396   strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
    397   p = strchr(tmp, '.');
    398   if (p)
    399     {
    400       p = strchr(++p, '.');
    401       if (p)
    402         {
    403       while(*p) { *p=*(p+1); p++; }
    404         }
    405     }
     392    strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
     393    p = strchr(tmp, '.');
     394    if (p) {
     395        p = strchr(++p, '.');
     396        if (p) {
     397            while (*p) {
     398                *p = *(p + 1);
     399                p++;
     400            }
     401        }
     402    }
    406403//  log_msg(1, "tmp = '%s'", tmp);
    407   d = atof(tmp);
    408 #endif
    409   log_msg(1, "g_kernel_version = %f", d);
    410   return(d);
     404    d = atof(tmp);
     405#endif
     406    log_msg(1, "g_kernel_version = %f", d);
     407    return (d);
    411408}
    412409
     
    419416 * @return number of seconds since the epoch.
    420417 */
    421 long
    422 get_time ()
    423 {
    424   return (long) time ((void *) 0);
     418long get_time()
     419{
     420    return (long) time((void *) 0);
    425421}
    426422
     
    439435 */
    440436#ifdef __FreeBSD__
    441 void initialize_raidrec (struct vinum_volume *raidrec)
    442 {
    443   int i, j;
    444   raidrec->volname[0] = '\0';
    445   raidrec->plexes = 0;
    446   for (i = 0; i < 9; ++i) {
    447     raidrec->plex[i].raidlevel = -1;
    448     raidrec->plex[i].stripesize = 0;
    449     raidrec->plex[i].subdisks = 0;
    450     for (j = 0; j < 9; ++j) {
    451        strcpy (raidrec->plex[i].sd[j].which_device, "");
    452     }
    453   }
     437void initialize_raidrec(struct vinum_volume *raidrec)
     438{
     439    int i, j;
     440    raidrec->volname[0] = '\0';
     441    raidrec->plexes = 0;
     442    for (i = 0; i < 9; ++i) {
     443        raidrec->plex[i].raidlevel = -1;
     444        raidrec->plex[i].stripesize = 0;
     445        raidrec->plex[i].subdisks = 0;
     446        for (j = 0; j < 9; ++j) {
     447            strcpy(raidrec->plex[i].sd[j].which_device, "");
     448        }
     449    }
    454450}
    455451#else
    456 void initialize_raidrec (struct raid_device_record *raidrec)
    457 {
    458   assert(raidrec!=NULL);
    459   raidrec->raid_device[0] = '\0';
    460   raidrec->raid_level = 0;
    461   raidrec->chunk_size = 4;
    462   raidrec->persistent_superblock = 1;
    463   raidrec->data_disks.entries = 0;
    464   raidrec->spare_disks.entries = 0;
    465   raidrec->parity_disks.entries = 0;
    466   raidrec->failed_disks.entries = 0;
    467   raidrec->additional_vars.entries = 0;
     452void initialize_raidrec(struct raid_device_record *raidrec)
     453{
     454    assert(raidrec != NULL);
     455    raidrec->raid_device[0] = '\0';
     456    raidrec->raid_level = 0;
     457    raidrec->chunk_size = 4;
     458    raidrec->persistent_superblock = 1;
     459    raidrec->data_disks.entries = 0;
     460    raidrec->spare_disks.entries = 0;
     461    raidrec->parity_disks.entries = 0;
     462    raidrec->failed_disks.entries = 0;
     463    raidrec->additional_vars.entries = 0;
    468464}
    469465#endif
     
    480476{
    481477#ifdef __FreeBSD__
    482   system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
    483   system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
     478    system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
     479    system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
    484480#else
    485   system("modprobe dos &> /dev/null");
    486   system("modprobe fat &> /dev/null");
    487   system("modprobe vfat &> /dev/null");
    488   //  system("modprobe osst &> /dev/null");
     481    system("modprobe dos &> /dev/null");
     482    system("modprobe fat &> /dev/null");
     483    system("modprobe vfat &> /dev/null");
     484    //  system("modprobe osst &> /dev/null");
    489485#endif
    490486}
     
    495491 * @bug This function seems orphaned. Please remove.
    496492 */
    497 void
    498 log_trace (char *o)
    499 {
    500     /*@ pointers *****************************************************/
    501   FILE *fout;
    502 
    503     /*@ buffers ******************************************************/
    504   char output[MAX_STR_LEN];
    505 
    506     /*@ int    *******************************************************/
    507   int i;
    508 
    509     /*@ end vars ****************************************************/
    510 
    511   if (o[0] == '\0')
    512     {
    513       return;
    514     }
    515   strcpy (output, o);
    516   i = (int) strlen (output);
    517   if (i <= 0)
    518     {
    519       return;
    520     }
    521   if (output[i - 1] < 32)
    522     {
    523       output[i - 1] = '\0';
    524     }
    525   if (g_text_mode /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ )
    526     {
    527       printf ("%s\n", output);
    528     }
    529 
    530   fout = fopen (MONDO_TRACEFILE, "a");
    531   if (fout)
    532     {
    533       fprintf (fout, "%s\n", output);
    534       paranoid_fclose (fout);
    535     }
    536   else
    537     {
    538       log_OS_error( "Cannot write to tracefile" );
    539     }
     493void log_trace(char *o)
     494{
     495    /*@ pointers **************************************************** */
     496    FILE *fout;
     497
     498    /*@ buffers ***************************************************** */
     499    char output[MAX_STR_LEN];
     500
     501    /*@ int    ****************************************************** */
     502    int i;
     503
     504    /*@ end vars *************************************************** */
     505
     506    if (o[0] == '\0') {
     507        return;
     508    }
     509    strcpy(output, o);
     510    i = (int) strlen(output);
     511    if (i <= 0) {
     512        return;
     513    }
     514    if (output[i - 1] < 32) {
     515        output[i - 1] = '\0';
     516    }
     517    if (g_text_mode
     518        /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
     519        printf("%s\n", output);
     520    }
     521
     522    fout = fopen(MONDO_TRACEFILE, "a");
     523    if (fout) {
     524        fprintf(fout, "%s\n", output);
     525        paranoid_fclose(fout);
     526    } else {
     527        log_OS_error("Cannot write to tracefile");
     528    }
    540529}
    541530
     
    575564 * do not exist.
    576565 */
    577 int post_param_configuration (struct s_bkpinfo *bkpinfo)
    578 {
    579   char *extra_cdrom_params;
    580   char *mondo_mkisofs_sz;
    581   char *command;
    582   char *mtpt;
    583   char *hostname, *ip_address;
    584   int retval=0;
    585   long avm = 0;
    586   char *colon;
    587   char *cdr_exe;
    588   char *tmp;
    589   int rdsiz_MB;
    590       char *iso_dev;
    591       char *iso_mnt;
    592       char *iso_tmp;
    593       char *iso_path;
    594 
    595   assert(bkpinfo!=NULL);
    596   malloc_string(extra_cdrom_params);
    597   malloc_string(mondo_mkisofs_sz);
    598   malloc_string(command);
    599   malloc_string(mtpt);
    600   malloc_string(hostname);
    601   malloc_string(ip_address);
    602   malloc_string(cdr_exe);
    603   malloc_string(tmp);
    604       malloc_string(iso_dev);
    605       malloc_string(iso_mnt);
    606       malloc_string(iso_tmp);
    607       malloc_string(iso_path);
    608   bkpinfo->optimal_set_size = (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)?4:8) * 1024;
    609 
    610   log_msg(1, "Foo");
    611   if (bkpinfo->backup_media_type == tape)
    612     {
    613       log_msg(1, "Bar");
    614       sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    615       log_msg(1, "tmp = '%s'", tmp);
    616       if (run_program_and_log_output(tmp, 3))
    617         {
    618           fatal_error("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
    619     }
    620     }   
    621   make_hole_for_dir(bkpinfo->scratchdir);
    622   make_hole_for_dir(bkpinfo->tmpdir);
    623   if (bkpinfo->backup_media_type == iso)
    624       make_hole_for_dir(bkpinfo->isodir);
    625 
    626   run_program_and_log_output ("uname -a", 5);
    627   run_program_and_log_output ("cat /etc/*issue*", 5);
    628   sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
    629   sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
    630   paranoid_system(command);
    631   rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
     566int post_param_configuration(struct s_bkpinfo *bkpinfo)
     567{
     568    char *extra_cdrom_params;
     569    char *mondo_mkisofs_sz;
     570    char *command;
     571    char *mtpt;
     572    char *hostname, *ip_address;
     573    int retval = 0;
     574    long avm = 0;
     575    char *colon;
     576    char *cdr_exe;
     577    char *tmp;
     578    int rdsiz_MB;
     579    char *iso_dev;
     580    char *iso_mnt;
     581    char *iso_tmp;
     582    char *iso_path;
     583
     584    assert(bkpinfo != NULL);
     585    malloc_string(extra_cdrom_params);
     586    malloc_string(mondo_mkisofs_sz);
     587    malloc_string(command);
     588    malloc_string(mtpt);
     589    malloc_string(hostname);
     590    malloc_string(ip_address);
     591    malloc_string(cdr_exe);
     592    malloc_string(tmp);
     593    malloc_string(iso_dev);
     594    malloc_string(iso_mnt);
     595    malloc_string(iso_tmp);
     596    malloc_string(iso_path);
     597    bkpinfo->optimal_set_size =
     598        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 4 : 8) *
     599        1024;
     600
     601    log_msg(1, "Foo");
     602    if (bkpinfo->backup_media_type == tape) {
     603        log_msg(1, "Bar");
     604        sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
     605        log_msg(1, "tmp = '%s'", tmp);
     606        if (run_program_and_log_output(tmp, 3)) {
     607            fatal_error
     608                ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
     609        }
     610    }
     611    make_hole_for_dir(bkpinfo->scratchdir);
     612    make_hole_for_dir(bkpinfo->tmpdir);
     613    if (bkpinfo->backup_media_type == iso)
     614        make_hole_for_dir(bkpinfo->isodir);
     615
     616    run_program_and_log_output("uname -a", 5);
     617    run_program_and_log_output("cat /etc/*issue*", 5);
     618    sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
     619    sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
     620    paranoid_system(command);
     621    rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
    632622#ifdef __FreeBSD__
    633   strcpy(tmp, call_program_and_get_last_line_of_output("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
    634   avm += atol (tmp);
    635   strcpy(tmp, call_program_and_get_last_line_of_output("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
    636   avm += atol (tmp);
    637   sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm', g_tmpfs_mountpt);
     623    strcpy(tmp,
     624           call_program_and_get_last_line_of_output
     625           ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
     626    avm += atol(tmp);
     627    strcpy(tmp,
     628           call_program_and_get_last_line_of_output
     629           ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
     630    avm += atol(tmp);
     631    sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
     632            g_tmpfs_mountpt);
    638633#else
    639   strcpy(tmp, call_program_and_get_last_line_of_output("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
    640   avm += atol (tmp);
    641   sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c", g_tmpfs_mountpt, rdsiz_MB, 'm');
    642   run_program_and_log_output ("cat /proc/cpuinfo", 5);
    643   run_program_and_log_output ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc", 5);
    644 #endif
    645   if (avm/1024 > rdsiz_MB*3)
    646     {
    647       if (run_program_and_log_output(command, 5))
     634    strcpy(tmp,
     635           call_program_and_get_last_line_of_output
     636           ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
     637    avm += atol(tmp);
     638    sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
     639            g_tmpfs_mountpt, rdsiz_MB, 'm');
     640    run_program_and_log_output("cat /proc/cpuinfo", 5);
     641    run_program_and_log_output
     642        ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
     643         5);
     644#endif
     645    if (avm / 1024 > rdsiz_MB * 3) {
     646        if (run_program_and_log_output(command, 5)) {
     647            g_tmpfs_mountpt[0] = '\0';
     648            log_it("Failed to mount tmpfs");
     649        } else {
     650            log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
     651        }
     652    } else {
     653        g_tmpfs_mountpt[0] = '\0';
     654        log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
     655    }
     656
     657    if (bkpinfo->use_lzo) {
     658        strcpy(bkpinfo->zip_exe, "lzop");
     659        strcpy(bkpinfo->zip_suffix, "lzo");
     660    } else if (bkpinfo->compression_level != 0) {
     661        strcpy(bkpinfo->zip_exe, "bzip2");
     662        strcpy(bkpinfo->zip_suffix, "bz2");
     663    } else {
     664        bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     665    }
     666
     667// DVD
     668
     669    if (bkpinfo->backup_media_type == dvd) {
     670        extra_cdrom_params[0] = '\0';
     671        mondo_mkisofs_sz[0] = '\0';
     672        if (find_home_of_exe("growisofs")) {
     673            strcpy(cdr_exe, "growisofs");
     674        }                       // unlikely to be used
     675        else {
     676            fatal_error("Please install growisofs.");
     677        }
     678        if (bkpinfo->nonbootable_backup) {
     679            strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     680        } else if
     681#ifdef __FreeBSD__
     682            (TRUE)
     683#else
     684            (bkpinfo->make_cd_use_lilo)
     685#endif
     686#ifdef __IA64__
    648687    {
    649       g_tmpfs_mountpt[0] = '\0';
    650       log_it("Failed to mount tmpfs");
    651     }
    652       else
     688        strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     689    }
     690#else
    653691    {
    654       log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
    655     }
    656     }
    657   else
    658     {
    659       g_tmpfs_mountpt[0] = '\0';
    660       log_it ("It doesn't seem you have enough swap to use tmpfs. Fine.");
    661     }
    662 
    663   if (bkpinfo->use_lzo)
    664     {
    665       strcpy (bkpinfo->zip_exe, "lzop");
    666       strcpy (bkpinfo->zip_suffix, "lzo");
    667     }
    668   else if (bkpinfo->compression_level!=0)
    669     {
    670       strcpy (bkpinfo->zip_exe, "bzip2");
    671       strcpy (bkpinfo->zip_suffix, "bz2");
    672     }
    673   else
    674     {
    675       bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    676     }
    677 
    678 // DVD
    679 
    680   if (bkpinfo->backup_media_type == dvd)
    681       {
    682       extra_cdrom_params[0] = '\0';
    683       mondo_mkisofs_sz[0] = '\0';
    684       if (find_home_of_exe("growisofs"))
    685     { strcpy(cdr_exe, "growisofs"); } // unlikely to be used
    686       else
    687         { fatal_error("Please install growisofs."); }
    688       if (bkpinfo->nonbootable_backup)
    689         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT); }
    690       else if
     692        strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     693    }
     694#endif
     695        else
     696        {
     697            strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     698        }
     699        if (bkpinfo->manual_cd_tray) {
     700            fatal_error("Manual CD tray + DVD not supported yet.");
     701            // -m isn't supported by growisofs, BTW...
     702        } else {
     703            sprintf(bkpinfo->call_make_iso,
     704                    "%s %s -Z %s . 2>> _ERR_",
     705                    mondo_mkisofs_sz,
     706                    extra_cdrom_params, bkpinfo->media_device);
     707        }
     708        log_msg(2, "call_make_iso (DVD res) is ... %s",
     709                bkpinfo->call_make_iso);
     710    }                           // end of DVD code
     711
     712// CD-R or CD-RW
     713    if (bkpinfo->backup_media_type == cdrw
     714        || bkpinfo->backup_media_type == cdr) {
     715        extra_cdrom_params[0] = '\0';
     716        if (!bkpinfo->manual_cd_tray) {
     717            strcat(extra_cdrom_params, "-waiti ");
     718        }
     719        if (bkpinfo->backup_media_type == cdrw) {
     720            strcat(extra_cdrom_params, "blank=fast ");
     721        }
     722        if (find_home_of_exe("cdrecord")) {
     723            strcpy(cdr_exe, "cdrecord");
     724        } else if (find_home_of_exe("dvdrecord")) {
     725            strcpy(cdr_exe, "dvdrecord");
     726        } else {
     727            fatal_error("Please install either cdrecord or dvdrecord.");
     728        }
     729        if (bkpinfo->nonbootable_backup) {
     730            strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     731        } else if
    691732#ifdef __FreeBSD__
    692         (TRUE)
     733            (TRUE)
    693734#else
    694         (bkpinfo->make_cd_use_lilo)
     735            (bkpinfo->make_cd_use_lilo)
    695736#endif
    696737#ifdef __IA64__
    697         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO); }
     738    {
     739        strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     740    }
    698741#else
    699         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO); }
    700 #endif
    701       else
    702         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); }
    703       if (bkpinfo->manual_cd_tray)
    704742    {
    705       fatal_error("Manual CD tray + DVD not supported yet.");
    706       // -m isn't supported by growisofs, BTW...
    707     }
    708       else
    709     {
    710       sprintf (bkpinfo->call_make_iso,
    711            "%s %s -Z %s . 2>> _ERR_",
    712            mondo_mkisofs_sz,
    713            extra_cdrom_params,
    714            bkpinfo->media_device);
    715         }
    716       log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
    717     } // end of DVD code
    718 
    719 // CD-R or CD-RW
    720   if (bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr)
    721     {
    722       extra_cdrom_params[0] = '\0';
    723       if (!bkpinfo->manual_cd_tray)
    724     {
    725       strcat (extra_cdrom_params, "-waiti ");
    726     }
    727       if (bkpinfo->backup_media_type == cdrw)
    728     {
    729       strcat (extra_cdrom_params, "blank=fast ");
    730     }
    731       if (find_home_of_exe("cdrecord"))
    732     { strcpy(cdr_exe, "cdrecord"); }
    733       else if (find_home_of_exe("dvdrecord"))
    734     { strcpy(cdr_exe, "dvdrecord"); }
    735       else
    736         { fatal_error("Please install either cdrecord or dvdrecord."); }
    737       if (bkpinfo->nonbootable_backup)
    738         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT); }
    739       else if
    740 #ifdef __FreeBSD__
    741         (TRUE)
    742 #else
    743         (bkpinfo->make_cd_use_lilo)
    744 #endif
    745 #ifdef __IA64__
    746         { strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO); }
    747 #else
    748         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO); }
    749 #endif
    750       else
    751         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX); }
    752       if (bkpinfo->manual_cd_tray)
    753     {
    754       sprintf (bkpinfo->call_before_iso,
    755            "%s -o %s/temporary.iso . 2>> _ERR_", mondo_mkisofs_sz, bkpinfo->tmpdir);
    756       sprintf (bkpinfo->call_make_iso,
    757            "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
    758            cdr_exe,
    759            (bkpinfo->please_dont_eject)?" ":"-eject",
    760            extra_cdrom_params, bkpinfo->media_device,
    761            bkpinfo->cdrw_speed, bkpinfo->tmpdir);
    762     }
    763       else
    764     {
    765       sprintf (bkpinfo->call_make_iso,
    766            "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
    767            mondo_mkisofs_sz, cdr_exe,
    768            (bkpinfo->please_dont_eject)?" ":"-eject",
    769            extra_cdrom_params, bkpinfo->media_device,
    770            bkpinfo->cdrw_speed);
    771         }
    772     } // end of CD code
    773 
    774   /*
    775   if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
    776     {
    777       sprintf (tmp,
    778            "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
    779            bkpinfo->media_device, bkpinfo->internal_tape_block_size);
    780       if (system(tmp))
    781     {
    782       retval++;
    783       fprintf (stderr,
    784            "Cannot write to tape device. Is the tape set read-only?\n");
    785     }
    786     } // end of tape code
    787   */
    788 
    789 
    790   if (bkpinfo->backup_media_type == iso)
    791     {
     743        strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     744    }
     745#endif
     746        else
     747        {
     748            strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     749        }
     750        if (bkpinfo->manual_cd_tray) {
     751            sprintf(bkpinfo->call_before_iso,
     752                    "%s -o %s/temporary.iso . 2>> _ERR_", mondo_mkisofs_sz,
     753                    bkpinfo->tmpdir);
     754            sprintf(bkpinfo->call_make_iso,
     755                    "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
     756                    cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
     757                    extra_cdrom_params, bkpinfo->media_device,
     758                    bkpinfo->cdrw_speed, bkpinfo->tmpdir);
     759        } else {
     760            sprintf(bkpinfo->call_make_iso,
     761                    "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
     762                    mondo_mkisofs_sz, cdr_exe,
     763                    (bkpinfo->please_dont_eject) ? " " : "-eject",
     764                    extra_cdrom_params, bkpinfo->media_device,
     765                    bkpinfo->cdrw_speed);
     766        }
     767    }                           // end of CD code
     768
     769    /*
     770       if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
     771       {
     772       sprintf (tmp,
     773       "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
     774       bkpinfo->media_device, bkpinfo->internal_tape_block_size);
     775       if (system(tmp))
     776       {
     777       retval++;
     778       fprintf (stderr,
     779       "Cannot write to tape device. Is the tape set read-only?\n");
     780       }
     781       } // end of tape code
     782     */
     783
     784
     785    if (bkpinfo->backup_media_type == iso) {
    792786
    793787/* Patch by Conor Daly <conor.daly@met.ie>
     
    798792 */
    799793
    800       log_it("isodir = %s", bkpinfo->isodir);
    801       sprintf(command, "df %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    802       log_it("command = %s", command);
    803       log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    804       sprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
    805       sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    806       write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    807 
    808       sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);
    809       log_it("command = %s", command);
    810       log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    811       sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    812       sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    813       write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    814 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
    815       sprintf(iso_tmp, "%s", bkpinfo->isodir);
    816       if (strlen(iso_tmp) < strlen(iso_mnt))
    817         {
    818       iso_path[0] = '\0';
    819     }
    820       else
    821         {
    822           sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
    823     }
    824       sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
    825       write_one_liner_data_file(tmp, iso_path);
    826 log_it("isodir: %s", iso_path);
     794        log_it("isodir = %s", bkpinfo->isodir);
     795        sprintf(command, "df %s | tail -n1 | cut -d' ' -f1",
     796                bkpinfo->isodir);
     797        log_it("command = %s", command);
     798        log_it("res of it = %s",
     799               call_program_and_get_last_line_of_output(command));
     800        sprintf(iso_dev, "%s",
     801                call_program_and_get_last_line_of_output(command));
     802        sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
     803        write_one_liner_data_file(tmp,
     804                                  call_program_and_get_last_line_of_output
     805                                  (command));
     806
     807        sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     808                iso_dev);
     809        log_it("command = %s", command);
     810        log_it("res of it = %s",
     811               call_program_and_get_last_line_of_output(command));
     812        sprintf(iso_mnt, "%s",
     813                call_program_and_get_last_line_of_output(command));
     814        sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
     815        write_one_liner_data_file(tmp,
     816                                  call_program_and_get_last_line_of_output
     817                                  (command));
     818        log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
     819        sprintf(iso_tmp, "%s", bkpinfo->isodir);
     820        if (strlen(iso_tmp) < strlen(iso_mnt)) {
     821            iso_path[0] = '\0';
     822        } else {
     823            sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
     824        }
     825        sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     826        write_one_liner_data_file(tmp, iso_path);
     827        log_it("isodir: %s", iso_path);
    827828
    828829/* End patch */
    829     } // end of iso code
    830 
    831   if (bkpinfo->backup_media_type == nfs) {
    832       strcpy (hostname, bkpinfo->nfs_mount);
    833       colon = strchr (hostname, ':');
    834       if (!colon) {
    835       log_it ("nfs mount doesn't have a colon in it");
    836       retval++;
    837       } else {
    838       struct hostent *hent;
    839 
    840       *colon = '\0';
    841       hent = gethostbyname (hostname);
    842       if (!hent) {
    843           log_it ("Can't resolve NFS mount (%s): %s", hostname, hstrerror (h_errno));
    844           retval++;
    845       } else {
    846           strcpy (ip_address, inet_ntoa
    847               ((struct in_addr)*((struct in_addr *)hent->h_addr)));
    848           strcat (ip_address, strchr (bkpinfo->nfs_mount, ':'));
    849           strcpy (bkpinfo->nfs_mount, ip_address);
    850       }
    851       }
    852       store_nfs_config (bkpinfo);
    853   }
    854 
    855   log_it("Finished processing incoming params");
    856   if (retval)
    857     {
    858       fprintf (stderr, "Type 'man mondoarchive' for help.\n");
    859     }
    860   sprintf (tmp, "%s", MONDO_TMPISOS);   /* added #define 22 apr 2002 */
    861   if (does_file_exist (tmp))
    862     {
    863       unlink (tmp);
    864     }
    865   if (strlen (bkpinfo->tmpdir) < 2 || strlen (bkpinfo->scratchdir) < 2)
    866     {
    867       log_it ("tmpdir or scratchdir are blank/missing");
    868       retval++;
    869     }
    870   if (bkpinfo->include_paths[0] == '\0')
    871     {
    872     //      fatal_error ("Why no backup path?");
    873     strcpy (bkpinfo->include_paths, "/");
    874     }
    875   chmod(bkpinfo->scratchdir, 0700);
    876   chmod(bkpinfo->tmpdir, 0700);
    877   g_backup_media_type = bkpinfo->backup_media_type;
    878   paranoid_free(mtpt);
    879   paranoid_free(extra_cdrom_params);
    880   paranoid_free(mondo_mkisofs_sz);
    881   paranoid_free(command);
    882   paranoid_free(hostname);
    883   paranoid_free(ip_address);
    884   paranoid_free(cdr_exe);
    885   paranoid_free(tmp);
    886   paranoid_free(iso_dev);
    887   paranoid_free(iso_mnt);
    888   paranoid_free(iso_tmp);
    889   paranoid_free(iso_path);
    890   return(retval);
     830    }                           // end of iso code
     831
     832    if (bkpinfo->backup_media_type == nfs) {
     833        strcpy(hostname, bkpinfo->nfs_mount);
     834        colon = strchr(hostname, ':');
     835        if (!colon) {
     836            log_it("nfs mount doesn't have a colon in it");
     837            retval++;
     838        } else {
     839            struct hostent *hent;
     840
     841            *colon = '\0';
     842            hent = gethostbyname(hostname);
     843            if (!hent) {
     844                log_it("Can't resolve NFS mount (%s): %s", hostname,
     845                       hstrerror(h_errno));
     846                retval++;
     847            } else {
     848                strcpy(ip_address, inet_ntoa
     849                       ((struct in_addr)
     850                        *((struct in_addr *) hent->h_addr)));
     851                strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
     852                strcpy(bkpinfo->nfs_mount, ip_address);
     853            }
     854        }
     855        store_nfs_config(bkpinfo);
     856    }
     857
     858    log_it("Finished processing incoming params");
     859    if (retval) {
     860        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
     861    }
     862    sprintf(tmp, "%s", MONDO_TMPISOS);  /* added #define 22 apr 2002 */
     863    if (does_file_exist(tmp)) {
     864        unlink(tmp);
     865    }
     866    if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
     867        log_it("tmpdir or scratchdir are blank/missing");
     868        retval++;
     869    }
     870    if (bkpinfo->include_paths[0] == '\0') {
     871        //      fatal_error ("Why no backup path?");
     872        strcpy(bkpinfo->include_paths, "/");
     873    }
     874    chmod(bkpinfo->scratchdir, 0700);
     875    chmod(bkpinfo->tmpdir, 0700);
     876    g_backup_media_type = bkpinfo->backup_media_type;
     877    paranoid_free(mtpt);
     878    paranoid_free(extra_cdrom_params);
     879    paranoid_free(mondo_mkisofs_sz);
     880    paranoid_free(command);
     881    paranoid_free(hostname);
     882    paranoid_free(ip_address);
     883    paranoid_free(cdr_exe);
     884    paranoid_free(tmp);
     885    paranoid_free(iso_dev);
     886    paranoid_free(iso_mnt);
     887    paranoid_free(iso_tmp);
     888    paranoid_free(iso_path);
     889    return (retval);
    891890}
    892891
     
    902901int pre_param_configuration(struct s_bkpinfo *bkpinfo)
    903902{
    904   int res=0;
    905 
    906   make_hole_for_dir(MNT_CDROM);
    907   assert(bkpinfo!=NULL);
    908   srandom ((unsigned long)(time (NULL)));
    909   insmod_crucial_modules();
    910   reset_bkpinfo (bkpinfo); // also sets defaults ('/'=backup path, 3=compression level)
    911   if (bkpinfo->disaster_recovery) {
    912     if (!does_nonMS_partition_exist()) {
    913       fatal_error ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
    914     }
    915   }
    916 
    917   unlink (MONDO_TRACEFILE);
    918   run_program_and_log_output( "rm -Rf /tmp/changed.files*", FALSE);
    919   if (find_and_store_mondoarchives_home(g_mondo_home))
    920     {
    921       fprintf (stderr,
    922            "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
    923       res++;
    924       return(res);
    925     }
    926   res += some_basic_system_sanity_checks ();
    927   if (res)
    928     {
    929       log_it ("Your distribution did not pass Mondo's sanity test.");
    930     }
    931   g_current_media_number = 1;
    932   bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
    933   return(res);
     903    int res = 0;
     904
     905    make_hole_for_dir(MNT_CDROM);
     906    assert(bkpinfo != NULL);
     907    srandom((unsigned long) (time(NULL)));
     908    insmod_crucial_modules();
     909    reset_bkpinfo(bkpinfo);     // also sets defaults ('/'=backup path, 3=compression level)
     910    if (bkpinfo->disaster_recovery) {
     911        if (!does_nonMS_partition_exist()) {
     912            fatal_error
     913                ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
     914        }
     915    }
     916
     917    unlink(MONDO_TRACEFILE);
     918    run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
     919    if (find_and_store_mondoarchives_home(g_mondo_home)) {
     920        fprintf(stderr,
     921                "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
     922        res++;
     923        return (res);
     924    }
     925    res += some_basic_system_sanity_checks();
     926    if (res) {
     927        log_it("Your distribution did not pass Mondo's sanity test.");
     928    }
     929    g_current_media_number = 1;
     930    bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
     931    return (res);
    934932}
    935933
     
    941939 * @param bkpinfo The @c bkpinfo to reset.
    942940 */
    943 void
    944 reset_bkpinfo (struct s_bkpinfo *bkpinfo)
    945 {
    946   int i;
    947 
    948   log_msg(1, "Hi");
    949   assert(bkpinfo!=NULL);
    950   memset((void*)bkpinfo, 0, sizeof(struct s_bkpinfo));
    951   bkpinfo->manual_cd_tray = FALSE;
    952   bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    953   bkpinfo->media_device[0] = '\0';
    954   for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = -1; }
    955   bkpinfo->boot_loader = '\0';
    956   bkpinfo->boot_device[0] = '\0';
    957   bkpinfo->zip_exe[0] = '\0';
    958   bkpinfo->zip_suffix[0] = '\0';
    959   bkpinfo->restore_path[0] = '\0';
    960   bkpinfo->use_lzo = FALSE;
    961   bkpinfo->do_not_compress_these[0] = '\0';
    962   bkpinfo->verify_data = FALSE;
    963   bkpinfo->backup_data = FALSE;
    964   bkpinfo->restore_data = FALSE;
    965   bkpinfo->disaster_recovery = (am_I_in_disaster_recovery_mode()?TRUE:FALSE);
    966   if (bkpinfo->disaster_recovery)
    967     { strcpy(bkpinfo->isodir, "/"); }
    968   else
    969     { strcpy (bkpinfo->isodir, "/root/images/mondo"); }
    970   strcpy (bkpinfo->prefix, "mondorescue");
    971 
    972   bkpinfo->scratchdir[0] = '\0';
    973   bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
    974   sprintf( bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) ( random() %32768 ) ); // for mondorestore
    975   bkpinfo->optimal_set_size = 0;
    976   bkpinfo->backup_media_type = none;
    977   strcpy (bkpinfo->include_paths, "/");
    978   bkpinfo->exclude_paths[0] = '\0';
    979   bkpinfo->call_before_iso[0] = '\0';
    980   bkpinfo->call_make_iso[0] = '\0';
    981   bkpinfo->call_burn_iso[0] = '\0';
    982   bkpinfo->call_after_iso[0] = '\0';
    983   bkpinfo->image_devs[0] = '\0';
    984   bkpinfo->postnuke_tarball[0] = '\0';
    985   bkpinfo->kernel_path[0] = '\0';
    986   bkpinfo->nfs_mount[0] = '\0';
    987   bkpinfo->nfs_remote_dir[0] = '\0';
    988   bkpinfo->wipe_media_first = FALSE;
    989   bkpinfo->differential = FALSE;
    990   bkpinfo->cdrw_speed = 0;
     941void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
     942{
     943    int i;
     944
     945    log_msg(1, "Hi");
     946    assert(bkpinfo != NULL);
     947    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     948    bkpinfo->manual_cd_tray = FALSE;
     949    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     950    bkpinfo->media_device[0] = '\0';
     951    for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     952        bkpinfo->media_size[i] = -1;
     953    }
     954    bkpinfo->boot_loader = '\0';
     955    bkpinfo->boot_device[0] = '\0';
     956    bkpinfo->zip_exe[0] = '\0';
     957    bkpinfo->zip_suffix[0] = '\0';
     958    bkpinfo->restore_path[0] = '\0';
     959    bkpinfo->use_lzo = FALSE;
     960    bkpinfo->do_not_compress_these[0] = '\0';
     961    bkpinfo->verify_data = FALSE;
     962    bkpinfo->backup_data = FALSE;
     963    bkpinfo->restore_data = FALSE;
     964    bkpinfo->disaster_recovery =
     965        (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
     966    if (bkpinfo->disaster_recovery) {
     967        strcpy(bkpinfo->isodir, "/");
     968    } else {
     969        strcpy(bkpinfo->isodir, "/root/images/mondo");
     970    }
     971    strcpy(bkpinfo->prefix, "mondorescue");
     972
     973    bkpinfo->scratchdir[0] = '\0';
     974    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
     975    sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768));  // for mondorestore
     976    bkpinfo->optimal_set_size = 0;
     977    bkpinfo->backup_media_type = none;
     978    strcpy(bkpinfo->include_paths, "/");
     979    bkpinfo->exclude_paths[0] = '\0';
     980    bkpinfo->call_before_iso[0] = '\0';
     981    bkpinfo->call_make_iso[0] = '\0';
     982    bkpinfo->call_burn_iso[0] = '\0';
     983    bkpinfo->call_after_iso[0] = '\0';
     984    bkpinfo->image_devs[0] = '\0';
     985    bkpinfo->postnuke_tarball[0] = '\0';
     986    bkpinfo->kernel_path[0] = '\0';
     987    bkpinfo->nfs_mount[0] = '\0';
     988    bkpinfo->nfs_remote_dir[0] = '\0';
     989    bkpinfo->wipe_media_first = FALSE;
     990    bkpinfo->differential = FALSE;
     991    bkpinfo->cdrw_speed = 0;
    991992// patch by Herman Kuster 
    992   bkpinfo->differential = 0;
     993    bkpinfo->differential = 0;
    993994// patch end
    994   bkpinfo->compression_level = 3;
     995    bkpinfo->compression_level = 3;
    995996}
    996997
     
    10031004 * @return The free space on @p partition, in MB.
    10041005 */
    1005 long free_space_on_given_partition(char*partition)
    1006 {
    1007   char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
    1008   long res;
    1009 
    1010   assert_string_is_neither_NULL_nor_zerolength(partition);
    1011 
    1012   sprintf(command, "df -m %s &> /dev/null", partition);
    1013   if (system(command))
    1014     { return(-1); } // partition does not exist
    1015   sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
    1016   strcpy(out_sz, call_program_and_get_last_line_of_output(command));
    1017   if (strlen(out_sz)==0)
    1018     { return(-1); } // error within df, probably
    1019   res = atol(out_sz);
    1020   return(res);
     1006long free_space_on_given_partition(char *partition)
     1007{
     1008    char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
     1009    long res;
     1010
     1011    assert_string_is_neither_NULL_nor_zerolength(partition);
     1012
     1013    sprintf(command, "df -m %s &> /dev/null", partition);
     1014    if (system(command)) {
     1015        return (-1);
     1016    }                           // partition does not exist
     1017    sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     1018            partition);
     1019    strcpy(out_sz, call_program_and_get_last_line_of_output(command));
     1020    if (strlen(out_sz) == 0) {
     1021        return (-1);
     1022    }                           // error within df, probably
     1023    res = atol(out_sz);
     1024    return (res);
    10211025}
    10221026
     
    10351039 * @return number of problems with the user's setup (0 for success)
    10361040 */
    1037 int
    1038 some_basic_system_sanity_checks ()
    1039 {
    1040 
    1041     /*@ buffers *************/
    1042   char tmp[MAX_STR_LEN];
    1043   //  char command[MAX_STR_LEN];
    1044 
    1045     /*@ int's ****************/
    1046   int retval = 0;
    1047   long Lres;
    1048 
    1049 
    1050   mvaddstr_and_log_it (g_currentY, 0,
    1051                "Checking sanity of your Linux distribution");
     1041int some_basic_system_sanity_checks()
     1042{
     1043
     1044    /*@ buffers ************ */
     1045    char tmp[MAX_STR_LEN];
     1046    //  char command[MAX_STR_LEN];
     1047
     1048    /*@ int's *************** */
     1049    int retval = 0;
     1050    long Lres;
     1051
     1052
     1053    mvaddstr_and_log_it(g_currentY, 0,
     1054                        "Checking sanity of your Linux distribution");
    10521055#ifndef __FreeBSD__
    1053   if (system("which mkfs.vfat &> /dev/null") && !system("which mkfs.msdos &> /dev/null"))
    1054     {
    1055       log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
    1056       run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    1057     }
    1058   strcpy (tmp,
    1059       call_program_and_get_last_line_of_output
    1060       ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    1061   if (atol (tmp) < 35000)
    1062     {
    1063       retval++;
    1064       log_to_screen ("You must have at least 32MB of RAM to use Mondo.");
    1065     }
    1066   if (atol (tmp) < 66000)
    1067     {
    1068       log_to_screen
    1069     ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    1070     }
    1071 #endif
    1072 
    1073   if ((Lres = free_space_on_given_partition("/root"))==-1)
    1074     { Lres = free_space_on_given_partition("/"); }
    1075   log_it("Free space on given partition = %ld MB", Lres);
    1076 
    1077   if (Lres < 50)
    1078     {
    1079       run_program_and_log_output("rm -Rf /root/images/mindi; mkdir -p /home/root/images/mindi; mkdir -p /root/images; ln -sf /home/root/images/mindi /root/images/mindi", 3);
    1080       //      fatal_error("Your / (or /root) partition has <50MB free. Please adjust your partition table to something saner.");
    1081     }
    1082 
    1083   if (system ("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null"))
    1084     {
    1085       retval++;
    1086       log_to_screen
    1087     ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
    1088       fatal_error
    1089         ("Please use \"su -\", not \"su\" to become root. OK? ...and please don't e-mail the mailing list or me about this. Just read the message. :)");
    1090     }
     1056    if (system("which mkfs.vfat &> /dev/null")
     1057        && !system("which mkfs.msdos &> /dev/null")) {
     1058        log_it
     1059            ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
     1060        run_program_and_log_output
     1061            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
     1062    }
     1063    strcpy(tmp,
     1064           call_program_and_get_last_line_of_output
     1065           ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     1066    if (atol(tmp) < 35000) {
     1067        retval++;
     1068        log_to_screen("You must have at least 32MB of RAM to use Mondo.");
     1069    }
     1070    if (atol(tmp) < 66000) {
     1071        log_to_screen
     1072            ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
     1073    }
     1074#endif
     1075
     1076    if ((Lres = free_space_on_given_partition("/root")) == -1) {
     1077        Lres = free_space_on_given_partition("/");
     1078    }
     1079    log_it("Free space on given partition = %ld MB", Lres);
     1080
     1081    if (Lres < 50) {
     1082        run_program_and_log_output
     1083            ("rm -Rf /root/images/mindi; mkdir -p /home/root/images/mindi; mkdir -p /root/images; ln -sf /home/root/images/mindi /root/images/mindi",
     1084             3);
     1085        //      fatal_error("Your / (or /root) partition has <50MB free. Please adjust your partition table to something saner.");
     1086    }
     1087
     1088    if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
     1089        retval++;
     1090        log_to_screen
     1091            ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
     1092        fatal_error
     1093            ("Please use \"su -\", not \"su\" to become root. OK? ...and please don't e-mail the mailing list or me about this. Just read the message. :)");
     1094    }
    10911095#ifndef __FreeBSD__
    1092   if (run_program_and_log_output ("cat /proc/devices | grep ramdisk", FALSE))
    1093     {
    1094       if (!ask_me_yes_or_no("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?"))
    1095         {
    1096       //          retval++;
    1097           log_to_screen
    1098             ("It looks as if your kernel lacks ramdisk and initrd support.");
    1099       log_to_screen
    1100         ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
    1101         }
    1102     }
    1103 #endif
    1104   retval += whine_if_not_found (MKE2FS_OR_NEWFS);
    1105   retval += whine_if_not_found ("mkisofs");
    1106   if (system("which dvdrecord > /dev/null 2> /dev/null"))
    1107     { retval += whine_if_not_found ("cdrecord"); }
    1108   retval += whine_if_not_found ("bzip2");
    1109   retval += whine_if_not_found ("awk");
    1110   retval += whine_if_not_found ("md5sum");
    1111   retval += whine_if_not_found ("strings");
    1112   retval += whine_if_not_found ("mindi");
    1113   retval += whine_if_not_found ("buffer");
    1114 
    1115   // abort if Windows partition but no ms-sys and parted
    1116   if (!run_program_and_log_output("mount | grep -w vfat | grep -v /dev/fd | grep -v nexdisk", 0) ||
    1117       !run_program_and_log_output("mount | grep -w dos | grep -v /dev/fd | grep -v nexdisk", 0))
    1118     {
    1119       log_to_screen("I think you have a Windows 9x partition.");
    1120       retval += whine_if_not_found ("parted");
     1096    if (run_program_and_log_output
     1097        ("cat /proc/devices | grep ramdisk", FALSE)) {
     1098        if (!ask_me_yes_or_no
     1099            ("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?"))
     1100        {
     1101            //          retval++;
     1102            log_to_screen
     1103                ("It looks as if your kernel lacks ramdisk and initrd support.");
     1104            log_to_screen
     1105                ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
     1106        }
     1107    }
     1108#endif
     1109    retval += whine_if_not_found(MKE2FS_OR_NEWFS);
     1110    retval += whine_if_not_found("mkisofs");
     1111    if (system("which dvdrecord > /dev/null 2> /dev/null")) {
     1112        retval += whine_if_not_found("cdrecord");
     1113    }
     1114    retval += whine_if_not_found("bzip2");
     1115    retval += whine_if_not_found("awk");
     1116    retval += whine_if_not_found("md5sum");
     1117    retval += whine_if_not_found("strings");
     1118    retval += whine_if_not_found("mindi");
     1119    retval += whine_if_not_found("buffer");
     1120
     1121    // abort if Windows partition but no ms-sys and parted
     1122    if (!run_program_and_log_output
     1123        ("mount | grep -w vfat | grep -v /dev/fd | grep -v nexdisk", 0)
     1124        ||
     1125        !run_program_and_log_output
     1126        ("mount | grep -w dos | grep -v /dev/fd | grep -v nexdisk", 0)) {
     1127        log_to_screen("I think you have a Windows 9x partition.");
     1128        retval += whine_if_not_found("parted");
    11211129#ifndef __IA64__
    1122       /* IA64 always has one vfat partition for EFI even without Windows */
    1123       // retval +=
    1124       if (!find_home_of_exe("ms-sys"))
    1125         {
    1126       log_to_screen("Please install ms-sys just in case.");
    1127     }
    1128 #endif
    1129     }
    1130 
    1131   if (!find_home_of_exe("cmp"))
    1132     {
    1133       if (!find_home_of_exe("true"))
    1134         { whine_if_not_found ("cmp"); }
    1135       else
    1136         {
    1137           log_to_screen("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
    1138           if (run_program_and_log_output("cp -f `which true` /usr/bin/cmp", 0))
    1139             { fatal_error("Failed to create dummy 'cmp' file."); }
    1140         }
    1141     }
    1142   run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1143   strcpy (tmp,
    1144       call_program_and_get_last_line_of_output
    1145       ("mount | grep -E \"cdr(om|w)\""));
    1146   if (strcmp ("", tmp))
    1147     {
    1148     if (strstr (tmp, "autofs")) {
    1149         log_to_screen ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
    1150         log_to_screen ("if a CD actually is inserted. If a CD is inserted, please");
    1151         log_to_screen ("eject it. Thank you.");
    1152         log_it ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
    1153     } else if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
    1154         retval++;
    1155         fatal_error ("Your CD-ROM drive is mounted. Please unmount it.");
    1156     }
    1157     }
     1130        /* IA64 always has one vfat partition for EFI even without Windows */
     1131        // retval +=
     1132        if (!find_home_of_exe("ms-sys")) {
     1133            log_to_screen("Please install ms-sys just in case.");
     1134        }
     1135#endif
     1136    }
     1137
     1138    if (!find_home_of_exe("cmp")) {
     1139        if (!find_home_of_exe("true")) {
     1140            whine_if_not_found("cmp");
     1141        } else {
     1142            log_to_screen
     1143                ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
     1144            if (run_program_and_log_output
     1145                ("cp -f `which true` /usr/bin/cmp", 0)) {
     1146                fatal_error("Failed to create dummy 'cmp' file.");
     1147            }
     1148        }
     1149    }
     1150    run_program_and_log_output
     1151        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
     1152    strcpy(tmp,
     1153           call_program_and_get_last_line_of_output
     1154           ("mount | grep -E \"cdr(om|w)\""));
     1155    if (strcmp("", tmp)) {
     1156        if (strstr(tmp, "autofs")) {
     1157            log_to_screen
     1158                ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
     1159            log_to_screen
     1160                ("if a CD actually is inserted. If a CD is inserted, please");
     1161            log_to_screen("eject it. Thank you.");
     1162            log_it
     1163                ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
     1164        } else
     1165            if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
     1166            retval++;
     1167            fatal_error
     1168                ("Your CD-ROM drive is mounted. Please unmount it.");
     1169        }
     1170    }
    11581171#ifndef __FreeBSD__
    1159   if (!does_file_exist ("/etc/modules.conf"))
    1160     {
    1161       if (does_file_exist("/etc/conf.modules"))
    1162         {
    1163           log_it("Linking /etc/modules.conf to /etc/conf.modules");
    1164           run_program_and_log_output("ln -sf /etc/conf.modules /etc/modules.conf", 5);
    1165         }
    1166       else if (does_file_exist("/etc/modprobe.d"))
    1167     {
    1168       log_it("Directory /etc/modprobe.d found. mindi will use its contents.");
    1169     }
    1170       else if (does_file_exist("/etc/modprobe.conf"))
    1171         {
    1172           log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
    1173           run_program_and_log_output("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
    1174     }
    1175       else
    1176         {
    1177           retval++;
    1178           log_to_screen ("Please find out what happened to /etc/modules.conf");
    1179         }
    1180     }
    1181 #endif
    1182 
    1183   run_program_and_log_output("cat /etc/fstab", 5);
     1172    if (!does_file_exist("/etc/modules.conf")) {
     1173        if (does_file_exist("/etc/conf.modules")) {
     1174            log_it("Linking /etc/modules.conf to /etc/conf.modules");
     1175            run_program_and_log_output
     1176                ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
     1177        } else if (does_file_exist("/etc/modprobe.d")) {
     1178            log_it
     1179                ("Directory /etc/modprobe.d found. mindi will use its contents.");
     1180        } else if (does_file_exist("/etc/modprobe.conf")) {
     1181            log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
     1182            run_program_and_log_output
     1183                ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
     1184        } else {
     1185            retval++;
     1186            log_to_screen
     1187                ("Please find out what happened to /etc/modules.conf");
     1188        }
     1189    }
     1190#endif
     1191
     1192    run_program_and_log_output("cat /etc/fstab", 5);
    11841193#ifdef __FreeBSD__
    1185   run_program_and_log_output("vinum printconfig", 5);
     1194    run_program_and_log_output("vinum printconfig", 5);
    11861195#else
    1187   run_program_and_log_output("cat /etc/raidtab", 5);
    1188 #endif
    1189 
    1190   if (run_program_and_log_output("mindi -V", 1))
    1191     {
    1192       log_to_screen("Could not ascertain mindi's version number.");
    1193       log_to_screen("You have not installed Mondo and/or Mindi properly.");
    1194       log_to_screen("Please uninstall and reinstall them both.");
    1195       fatal_error("Please reinstall Mondo and Mindi.");
    1196     }
    1197   if (run_program_and_log_output("mindi --makemountlist /tmp/mountlist.txt.test", 5))
    1198     {
    1199       log_to_screen("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
    1200       log_to_screen("Please run that command by hand and examine /var/log/mindi.log");
    1201       log_to_screen("for more information. Perhaps your /etc/fstab file is insane.");
    1202       log_to_screen("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
    1203       retval++;
    1204     }
    1205 
    1206   if (!run_program_and_log_output("fdisk -l | grep -i raid", 1) && !does_file_exist("/etc/raidtab"))
    1207     {
    1208       log_to_screen("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
    1209       create_raidtab_from_mdstat("/etc/raidtab", "/proc/mdstat");
    1210     }
    1211  
    1212   if (retval)
    1213     {
    1214       mvaddstr_and_log_it (g_currentY++, 74, "Failed.");
    1215     }
    1216   else
    1217     {
    1218       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1219     }
    1220   return (retval);
     1196    run_program_and_log_output("cat /etc/raidtab", 5);
     1197#endif
     1198
     1199    if (run_program_and_log_output("mindi -V", 1)) {
     1200        log_to_screen("Could not ascertain mindi's version number.");
     1201        log_to_screen
     1202            ("You have not installed Mondo and/or Mindi properly.");
     1203        log_to_screen("Please uninstall and reinstall them both.");
     1204        fatal_error("Please reinstall Mondo and Mindi.");
     1205    }
     1206    if (run_program_and_log_output
     1207        ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) {
     1208        log_to_screen
     1209            ("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
     1210        log_to_screen
     1211            ("Please run that command by hand and examine /var/log/mindi.log");
     1212        log_to_screen
     1213            ("for more information. Perhaps your /etc/fstab file is insane.");
     1214        log_to_screen
     1215            ("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
     1216        retval++;
     1217    }
     1218
     1219    if (!run_program_and_log_output("fdisk -l | grep -i raid", 1)
     1220        && !does_file_exist("/etc/raidtab")) {
     1221        log_to_screen
     1222            ("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
     1223        create_raidtab_from_mdstat("/etc/raidtab", "/proc/mdstat");
     1224    }
     1225
     1226    if (retval) {
     1227        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1228    } else {
     1229        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1230    }
     1231    return (retval);
    12211232}
    12221233
     
    12281239 * @return 0 for success, 1 for failure.
    12291240 */
    1230 int
    1231 read_cfg_var (char *config_file, char *label, char *value)
    1232 {
    1233     /*@ buffer *******************************************************/
    1234   char command[MAX_STR_LEN*2];
    1235   char tmp[MAX_STR_LEN];
    1236 
    1237     /*@ end vars ****************************************************/
    1238 
    1239   assert_string_is_neither_NULL_nor_zerolength(config_file);
    1240   assert_string_is_neither_NULL_nor_zerolength(label);
    1241   if (!does_file_exist (config_file))
    1242     {
    1243       sprintf (tmp, "(read_cfg_var) Cannot find %s config file", config_file);
    1244       log_to_screen (tmp);
    1245       value[0] = '\0';
    1246       return (1);
    1247     }
    1248   else if (strstr(value, "/dev/") && strstr(value, "t0") && !strcmp(label, "media-dev"))
    1249     {
    1250       log_msg (2, "FYI, I shan't read new value for %s - already got %s", label, value);
    1251       return(0);
    1252     }
    1253   else
    1254     {
    1255       sprintf (command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
    1256            config_file, label);
    1257       strcpy (value, call_program_and_get_last_line_of_output (command));
    1258       if (strlen (value) == 0)
    1259     {
    1260       return (1);
    1261     }
    1262       else
    1263     {
    1264       return (0);
    1265     }
    1266     }
     1241int read_cfg_var(char *config_file, char *label, char *value)
     1242{
     1243    /*@ buffer ****************************************************** */
     1244    char command[MAX_STR_LEN * 2];
     1245    char tmp[MAX_STR_LEN];
     1246
     1247    /*@ end vars *************************************************** */
     1248
     1249    assert_string_is_neither_NULL_nor_zerolength(config_file);
     1250    assert_string_is_neither_NULL_nor_zerolength(label);
     1251    if (!does_file_exist(config_file)) {
     1252        sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
     1253                config_file);
     1254        log_to_screen(tmp);
     1255        value[0] = '\0';
     1256        return (1);
     1257    } else if (strstr(value, "/dev/") && strstr(value, "t0")
     1258               && !strcmp(label, "media-dev")) {
     1259        log_msg(2, "FYI, I shan't read new value for %s - already got %s",
     1260                label, value);
     1261        return (0);
     1262    } else {
     1263        sprintf(command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
     1264                config_file, label);
     1265        strcpy(value, call_program_and_get_last_line_of_output(command));
     1266        if (strlen(value) == 0) {
     1267            return (1);
     1268        } else {
     1269            return (0);
     1270        }
     1271    }
    12671272}
    12681273
     
    12741279void remount_supermounts_if_necessary()
    12751280{
    1276   if (g_remount_cdrom_at_end)
    1277     {
    1278       run_program_and_log_output ("mount "MNT_CDROM, FALSE);
    1279     }
    1280   if (g_remount_floppy_at_end)
    1281     {
    1282       run_program_and_log_output ("mount "MNT_FLOPPY, FALSE);
    1283     }
     1281    if (g_remount_cdrom_at_end) {
     1282        run_program_and_log_output("mount " MNT_CDROM, FALSE);
     1283    }
     1284    if (g_remount_floppy_at_end) {
     1285        run_program_and_log_output("mount " MNT_FLOPPY, FALSE);
     1286    }
    12841287}
    12851288
     
    12891292void unmount_supermounts_if_necessary()
    12901293{
    1291   if (run_program_and_log_output ("mount | grep cdrom | grep super", FALSE) == 0)
    1292     {
    1293       g_remount_cdrom_at_end = TRUE;
    1294       run_program_and_log_output ("umount "MNT_CDROM, FALSE);
    1295     }
    1296   if (run_program_and_log_output ("mount | grep floppy | grep super", FALSE) == 0)
    1297     {
    1298       g_remount_floppy_at_end = TRUE;
    1299       run_program_and_log_output ("umount "MNT_FLOPPY, FALSE);
    1300     }
     1294    if (run_program_and_log_output
     1295        ("mount | grep cdrom | grep super", FALSE) == 0) {
     1296        g_remount_cdrom_at_end = TRUE;
     1297        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1298    }
     1299    if (run_program_and_log_output
     1300        ("mount | grep floppy | grep super", FALSE) == 0) {
     1301        g_remount_floppy_at_end = TRUE;
     1302        run_program_and_log_output("umount " MNT_FLOPPY, FALSE);
     1303    }
    13011304}
    13021305
     
    13041307 * Whether we had to stop autofs (if so, restart it at end).
    13051308 */
    1306 bool g_autofs_stopped=FALSE;
     1309bool g_autofs_stopped = FALSE;
    13071310
    13081311/**
     
    13261329void stop_autofs_if_necessary()
    13271330{
    1328   char tmp[MAX_STR_LEN];
    1329  
    1330   g_autofs_exe[0] = '\0';
    1331   if (does_file_exist(XANDROS_AUTOFS_FNAME))
    1332     { strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME); } 
    1333   else if (does_file_exist(STOCK_AUTOFS_FNAME))
    1334     { strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME); }
    1335    
    1336   if (!g_autofs_exe[0]) { log_msg(3, "No autofs detected."); } 
    1337   else
    1338     {
    1339       log_msg(3, "%s --- autofs detected", g_autofs_exe);
     1331    char tmp[MAX_STR_LEN];
     1332
     1333    g_autofs_exe[0] = '\0';
     1334    if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
     1335        strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
     1336    } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
     1337        strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
     1338    }
     1339
     1340    if (!g_autofs_exe[0]) {
     1341        log_msg(3, "No autofs detected.");
     1342    } else {
     1343        log_msg(3, "%s --- autofs detected", g_autofs_exe);
    13401344// FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1341       sprintf(tmp, "%s stop", g_autofs_exe);
    1342       if (run_program_and_log_output(tmp, 2))
    1343         { log_it("Failed to stop autofs - I assume it wasn't running"); }
    1344       else
    1345         { g_autofs_stopped = TRUE; log_it("Stopped autofs OK"); }
    1346     }
     1345        sprintf(tmp, "%s stop", g_autofs_exe);
     1346        if (run_program_and_log_output(tmp, 2)) {
     1347            log_it("Failed to stop autofs - I assume it wasn't running");
     1348        } else {
     1349            g_autofs_stopped = TRUE;
     1350            log_it("Stopped autofs OK");
     1351        }
     1352    }
    13471353}
    13481354
     
    13521358void restart_autofs_if_necessary()
    13531359{
    1354   char tmp[MAX_STR_LEN];
    1355  
    1356   if (!g_autofs_stopped || !g_autofs_exe[0]) { log_msg(3, "No autofs detected."); return; } 
    1357   sprintf(tmp, "%s start", g_autofs_exe);
    1358   if (run_program_and_log_output(tmp, 2))
    1359     { log_it("Failed to start autofs"); }
    1360   else
    1361     { g_autofs_stopped = FALSE; log_it("Started autofs OK"); }
     1360    char tmp[MAX_STR_LEN];
     1361
     1362    if (!g_autofs_stopped || !g_autofs_exe[0]) {
     1363        log_msg(3, "No autofs detected.");
     1364        return;
     1365    }
     1366    sprintf(tmp, "%s start", g_autofs_exe);
     1367    if (run_program_and_log_output(tmp, 2)) {
     1368        log_it("Failed to start autofs");
     1369    } else {
     1370        g_autofs_stopped = FALSE;
     1371        log_it("Started autofs OK");
     1372    }
    13621373}
    13631374
     
    13681379void mount_boot_if_necessary()
    13691380{
    1370   char tmp[MAX_STR_LEN];
    1371   char command[MAX_STR_LEN];
    1372 
    1373   log_msg(1, "Started sub");
    1374   log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
    1375   g_boot_mountpt[0] = '\0';
    1376   log_msg(4, "Done. Great. Seeting command to something");
    1377   strcpy(command, "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    1378   log_msg(4, "Cool. Command = '%s'", command);
    1379   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1380   log_msg(4, "tmp = '%s'", tmp);
    1381   if (tmp[0])
    1382     {
    1383       log_it("/boot is at %s according to /etc/fstab", tmp);
    1384       if (strstr(tmp, "LABEL="))
    1385         {
    1386       if (!run_program_and_log_output("mount /boot", 5))
    1387         {
    1388           strcpy(g_boot_mountpt, "/boot");
    1389           log_msg(1, "Mounted /boot");
    1390         }
    1391       else
    1392         {
    1393           log_it("...ignored cos it's a label :-)");
    1394         }
    1395     }
    1396       else
    1397         {
    1398           sprintf(command, "mount | grep -w \"%s\"", tmp);
    1399           log_msg(3, "command = %s", command);
    1400           if (run_program_and_log_output(command, 5))
    1401             {
    1402           strcpy(g_boot_mountpt, tmp);
    1403               sprintf(tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
    1404           log_it(tmp);
    1405           sprintf(tmp, "mount %s", g_boot_mountpt);
    1406           if (run_program_and_log_output(tmp, 5))
    1407         {
    1408           g_boot_mountpt[0] = '\0';
    1409           log_msg(1, "Plan B");
    1410           if (!run_program_and_log_output("mount /boot", 5))
    1411             {
    1412               strcpy(g_boot_mountpt, "/boot");
    1413               log_msg(1, "Plan B worked");
    1414             }
    1415           else
    1416             {
    1417               log_msg(1, "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
    1418             }
    1419         }
    1420             }
    1421         }
    1422     }
    1423   log_msg(1, "Ended sub");
     1381    char tmp[MAX_STR_LEN];
     1382    char command[MAX_STR_LEN];
     1383
     1384    log_msg(1, "Started sub");
     1385    log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
     1386    g_boot_mountpt[0] = '\0';
     1387    log_msg(4, "Done. Great. Seeting command to something");
     1388    strcpy(command,
     1389           "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1390    log_msg(4, "Cool. Command = '%s'", command);
     1391    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1392    log_msg(4, "tmp = '%s'", tmp);
     1393    if (tmp[0]) {
     1394        log_it("/boot is at %s according to /etc/fstab", tmp);
     1395        if (strstr(tmp, "LABEL=")) {
     1396            if (!run_program_and_log_output("mount /boot", 5)) {
     1397                strcpy(g_boot_mountpt, "/boot");
     1398                log_msg(1, "Mounted /boot");
     1399            } else {
     1400                log_it("...ignored cos it's a label :-)");
     1401            }
     1402        } else {
     1403            sprintf(command, "mount | grep -w \"%s\"", tmp);
     1404            log_msg(3, "command = %s", command);
     1405            if (run_program_and_log_output(command, 5)) {
     1406                strcpy(g_boot_mountpt, tmp);
     1407                sprintf(tmp,
     1408                        "%s (your /boot partition) is not mounted. I'll mount it before backing up",
     1409                        g_boot_mountpt);
     1410                log_it(tmp);
     1411                sprintf(tmp, "mount %s", g_boot_mountpt);
     1412                if (run_program_and_log_output(tmp, 5)) {
     1413                    g_boot_mountpt[0] = '\0';
     1414                    log_msg(1, "Plan B");
     1415                    if (!run_program_and_log_output("mount /boot", 5)) {
     1416                        strcpy(g_boot_mountpt, "/boot");
     1417                        log_msg(1, "Plan B worked");
     1418                    } else {
     1419                        log_msg(1,
     1420                                "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
     1421                    }
     1422                }
     1423            }
     1424        }
     1425    }
     1426    log_msg(1, "Ended sub");
    14241427}
    14251428
     
    14301433void unmount_boot_if_necessary()
    14311434{
    1432   char tmp[MAX_STR_LEN];
    1433 
    1434   log_msg(3, "starting");
    1435   if (g_boot_mountpt[0])
    1436     {
    1437       sprintf(tmp, "umount %s", g_boot_mountpt);
    1438       if (run_program_and_log_output(tmp, 5))
    1439     { log_it("WARNING - unable to unmount /boot"); }
    1440     }
    1441    log_msg(3, "leaving");
     1435    char tmp[MAX_STR_LEN];
     1436
     1437    log_msg(3, "starting");
     1438    if (g_boot_mountpt[0]) {
     1439        sprintf(tmp, "umount %s", g_boot_mountpt);
     1440        if (run_program_and_log_output(tmp, 5)) {
     1441            log_it("WARNING - unable to unmount /boot");
     1442        }
     1443    }
     1444    log_msg(3, "leaving");
    14421445}
    14431446
     
    14521455 * @return 0 for success, 1 for failure.
    14531456 */
    1454 int
    1455 write_cfg_var (char *config_file, char *label, char *value)
    1456 {
    1457     /*@ buffers ******************************************************/
    1458   char command[MAX_STR_LEN*2];
    1459   char tempfile[MAX_STR_LEN];
    1460   char tmp[MAX_STR_LEN];
    1461 
    1462 
    1463     /*@ end vars ****************************************************/
    1464   assert_string_is_neither_NULL_nor_zerolength(config_file);
    1465   assert_string_is_neither_NULL_nor_zerolength(label);
    1466   assert(value!=NULL);
    1467   if (!does_file_exist (config_file))
    1468     {
    1469       sprintf (tmp, "(write_cfg_file) Cannot find %s config file",
    1470            config_file);
    1471       log_to_screen (tmp);
    1472       return(1);
    1473     }
    1474   strcpy (tempfile,
    1475       call_program_and_get_last_line_of_output
    1476       ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
    1477   if (does_file_exist (config_file))
    1478     {
    1479       sprintf (command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
    1480            label, tempfile);
    1481       paranoid_system (command);
    1482     }
    1483   sprintf (command, "echo \"%s %s\" >> %s", label, value, tempfile);
    1484   paranoid_system (command);
    1485   sprintf (command, "mv -f %s %s", tempfile, config_file);
    1486   paranoid_system (command);
    1487   unlink (tempfile);
    1488   return (0);
     1457int write_cfg_var(char *config_file, char *label, char *value)
     1458{
     1459    /*@ buffers ***************************************************** */
     1460    char command[MAX_STR_LEN * 2];
     1461    char tempfile[MAX_STR_LEN];
     1462    char tmp[MAX_STR_LEN];
     1463
     1464
     1465    /*@ end vars *************************************************** */
     1466    assert_string_is_neither_NULL_nor_zerolength(config_file);
     1467    assert_string_is_neither_NULL_nor_zerolength(label);
     1468    assert(value != NULL);
     1469    if (!does_file_exist(config_file)) {
     1470        sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
     1471                config_file);
     1472        log_to_screen(tmp);
     1473        return (1);
     1474    }
     1475    strcpy(tempfile,
     1476           call_program_and_get_last_line_of_output
     1477           ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
     1478    if (does_file_exist(config_file)) {
     1479        sprintf(command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
     1480                label, tempfile);
     1481        paranoid_system(command);
     1482    }
     1483    sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
     1484    paranoid_system(command);
     1485    sprintf(command, "mv -f %s %s", tempfile, config_file);
     1486    paranoid_system(command);
     1487    unlink(tempfile);
     1488    return (0);
    14891489}
    14901490
     
    14951495 */
    14961496void standard_log_debug_msg(int debug_level, const char *szFile,
    1497                 const char *szFunction, int nLine, const char *fmt, ...)
    1498 {
    1499   va_list args;
    1500   int i;
    1501   static int depth=0; 
    1502   char *tmp;
    1503   FILE*fout;
    1504 
    1505   if (depth>5) { depth--; return; }
    1506   depth++;
    1507 
    1508   malloc_string(tmp);
    1509 
    1510   if (debug_level <= g_loglevel)
    1511     {
    1512       va_start(args, fmt);
    1513       if (!(fout = fopen (MONDO_LOGFILE, "a")))
    1514     { return; } // fatal_error("Failed to openout to logfile - sheesh..."); }
    1515 
    1516       // add tabs to distinguish log levels
    1517       if (debug_level > 0)
    1518     {
    1519       for (i = 1; i < debug_level; i++)
    1520         fprintf(fout, "\t");
    1521       if (getpid() == g_main_pid)
    1522         fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine);
    1523       else if (getpid() == g_buffer_pid && g_buffer_pid>0)
    1524         fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction, nLine);
    1525       else
    1526         fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine);
    1527     }
    1528       vfprintf(fout, fmt, args);
    1529 
    1530     // do not slow down the progran if standard debug level
    1531     // must be enabled: if no flush, the log won't be up-to-date if there
    1532     // is a segfault
    1533     //if (g_dwDebugLevel != 1)
    1534 
    1535       va_end(args);
    1536       fprintf(fout, "\n");
    1537       paranoid_fclose(fout);
    1538     }
    1539   depth--;
    1540   paranoid_free(tmp);
     1497                            const char *szFunction, int nLine,
     1498                            const char *fmt, ...)
     1499{
     1500    va_list args;
     1501    int i;
     1502    static int depth = 0;
     1503    char *tmp;
     1504    FILE *fout;
     1505
     1506    if (depth > 5) {
     1507        depth--;
     1508        return;
     1509    }
     1510    depth++;
     1511
     1512    malloc_string(tmp);
     1513
     1514    if (debug_level <= g_loglevel) {
     1515        va_start(args, fmt);
     1516        if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
     1517            return;
     1518        }                       // fatal_error("Failed to openout to logfile - sheesh..."); }
     1519
     1520        // add tabs to distinguish log levels
     1521        if (debug_level > 0) {
     1522            for (i = 1; i < debug_level; i++)
     1523                fprintf(fout, "\t");
     1524            if (getpid() == g_main_pid)
     1525                fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction,
     1526                        nLine);
     1527            else if (getpid() == g_buffer_pid && g_buffer_pid > 0)
     1528                fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction,
     1529                        nLine);
     1530            else
     1531                fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile,
     1532                        szFunction, nLine);
     1533        }
     1534        vfprintf(fout, fmt, args);
     1535
     1536        // do not slow down the progran if standard debug level
     1537        // must be enabled: if no flush, the log won't be up-to-date if there
     1538        // is a segfault
     1539        //if (g_dwDebugLevel != 1)
     1540
     1541        va_end(args);
     1542        fprintf(fout, "\n");
     1543        paranoid_fclose(fout);
     1544    }
     1545    depth--;
     1546    paranoid_free(tmp);
    15411547}
    15421548
     
    15441550 * Function pointer to the @c log_debug_msg function to use. Points to standard_log_debug_msg() by default.
    15451551 */
    1546 void (*log_debug_msg) (int, const char *, const char *, int, const char *, ...) = standard_log_debug_msg;
     1552void (*log_debug_msg) (int, const char *, const char *, int, const char *,
     1553                       ...) = standard_log_debug_msg;
    15471554
    15481555
     
    15591566void do_libmondo_global_strings_thing(int mal)
    15601567{
    1561   if (mal)
    1562     {
    1563       iamhere("Malloc'ing globals");
    1564       malloc_string(g_boot_mountpt);
    1565       malloc_string(g_mondo_home);
    1566       malloc_string(g_tmpfs_mountpt);
    1567       malloc_string(g_erase_tmpdir_and_scratchdir);
    1568       malloc_string(g_serial_string);
    1569       malloc_string(g_magicdev_command);
    1570     }
    1571   else
    1572     {
    1573       iamhere("Freeing globals");
    1574       paranoid_free(g_boot_mountpt);
    1575       paranoid_free(g_mondo_home);
    1576       paranoid_free(g_tmpfs_mountpt);
    1577       paranoid_free(g_erase_tmpdir_and_scratchdir);
    1578       paranoid_free(g_serial_string);
    1579       paranoid_free(g_magicdev_command);
    1580     }
    1581 
    1582   /*
    1583   char**list_of_arrays[] = {
    1584     &g_boot_mountpt,
    1585     &g_mondo_home,
    1586     &g_tmpfs_mountpt,
    1587     &g_erase_tmpdir_and_scratchdir,
    1588     &g_serial_string,
    1589     &g_magicdev_command,
    1590     NULL};
    1591 
    1592   char**ppcurr;
    1593   int i;
    1594  
    1595   for(i=0;list_of_arrays[i];i++)
    1596     {
    1597       log_msg(5, "Allocating %d", i);
    1598       ppcurr = list_of_arrays[i];
    1599       if (mal)
    1600         { *ppcurr = malloc(MAX_STR_LEN); }
    1601       else
    1602         {
    1603       if (*ppcurr)
    1604         {
    1605           free(*ppcurr);
    1606         }
    1607     }
    1608     }
    1609   log_msg(5, "Returning");
    1610   */
     1568    if (mal) {
     1569        iamhere("Malloc'ing globals");
     1570        malloc_string(g_boot_mountpt);
     1571        malloc_string(g_mondo_home);
     1572        malloc_string(g_tmpfs_mountpt);
     1573        malloc_string(g_erase_tmpdir_and_scratchdir);
     1574        malloc_string(g_serial_string);
     1575        malloc_string(g_magicdev_command);
     1576    } else {
     1577        iamhere("Freeing globals");
     1578        paranoid_free(g_boot_mountpt);
     1579        paranoid_free(g_mondo_home);
     1580        paranoid_free(g_tmpfs_mountpt);
     1581        paranoid_free(g_erase_tmpdir_and_scratchdir);
     1582        paranoid_free(g_serial_string);
     1583        paranoid_free(g_magicdev_command);
     1584    }
     1585
     1586    /*
     1587       char**list_of_arrays[] = {
     1588       &g_boot_mountpt,
     1589       &g_mondo_home,
     1590       &g_tmpfs_mountpt,
     1591       &g_erase_tmpdir_and_scratchdir,
     1592       &g_serial_string,
     1593       &g_magicdev_command,
     1594       NULL};
     1595
     1596       char**ppcurr;
     1597       int i;
     1598
     1599       for(i=0;list_of_arrays[i];i++)
     1600       {
     1601       log_msg(5, "Allocating %d", i);
     1602       ppcurr = list_of_arrays[i];
     1603       if (mal)
     1604       { *ppcurr = malloc(MAX_STR_LEN); }
     1605       else
     1606       {
     1607       if (*ppcurr)
     1608       {
     1609       free(*ppcurr);
     1610       }
     1611       }
     1612       }
     1613       log_msg(5, "Returning");
     1614     */
    16111615}
    16121616
     
    16171621void malloc_libmondo_global_strings(void)
    16181622{
    1619   do_libmondo_global_strings_thing(1);
     1623    do_libmondo_global_strings_thing(1);
    16201624}
    16211625
     
    16261630void free_libmondo_global_strings(void)
    16271631{
    1628   do_libmondo_global_strings_thing(0);
     1632    do_libmondo_global_strings_thing(0);
    16291633}
    16301634
     
    16371641void stop_magicdev_if_necessary()
    16381642{
    1639   strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
    1640   if (g_magicdev_command[0])
    1641     {
    1642       log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
    1643       paranoid_system("killall magicdev");
    1644     }
     1643    strcpy(g_magicdev_command,
     1644           call_program_and_get_last_line_of_output
     1645           ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
     1646    if (g_magicdev_command[0]) {
     1647        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
     1648        paranoid_system("killall magicdev");
     1649    }
    16451650}
    16461651
     
    16511656void restart_magicdev_if_necessary()
    16521657{
    1653   char *tmp;
    1654  
    1655   malloc_string(tmp);
    1656   if (g_magicdev_command && g_magicdev_command[0])
    1657     {
    1658       sprintf(tmp, "%s &", g_magicdev_command);
    1659       paranoid_system(tmp);
    1660     }
    1661   paranoid_free(tmp);
     1658    char *tmp;
     1659
     1660    malloc_string(tmp);
     1661    if (g_magicdev_command && g_magicdev_command[0]) {
     1662        sprintf(tmp, "%s &", g_magicdev_command);
     1663        paranoid_system(tmp);
     1664    }
     1665    paranoid_free(tmp);
    16621666}
    16631667
  • branches/2.05/mondo/mondo/common/libmondo-tools.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/libmondo-verify-EXT.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/common/libmondo-verify.c

    r117 r128  
    115115//static char cvsid[] = "$Id$";
    116116
    117 char *vfy_tball_fname (struct s_bkpinfo *, char *, int);
     117char *vfy_tball_fname(struct s_bkpinfo *, char *, int);
    118118
    119119
     
    136136 */
    137137long
    138 generate_list_of_changed_files (char *changedfiles_fname,
    139                 char *ignorefiles_fname, char *stderr_fname)
     138generate_list_of_changed_files(char *changedfiles_fname,
     139                               char *ignorefiles_fname, char *stderr_fname)
    140140{
    141     /*@ buffer ***********************************************************/
    142   char *command;
     141    /*@ buffer ********************************************************** */
     142    char *command;
    143143    char *afio_found_changes;
    144144
    145     /*@ int **************************************************************/
    146   int res = 0;
    147 
    148     /*@ long *************************************************************/
    149   long afio_diffs = 0;
    150 
    151   command = malloc(2000);
    152   afio_found_changes = malloc(500);
    153   assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname);
    154   assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname);
    155   assert_string_is_neither_NULL_nor_zerolength(stderr_fname);
    156 
    157   sprintf (afio_found_changes, "%s.afio", ignorefiles_fname);
    158   paranoid_system ("sync");
    159  
     145    /*@ int ************************************************************* */
     146    int res = 0;
     147
     148    /*@ long ************************************************************ */
     149    long afio_diffs = 0;
     150
     151    command = malloc(2000);
     152    afio_found_changes = malloc(500);
     153    assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname);
     154    assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname);
     155    assert_string_is_neither_NULL_nor_zerolength(stderr_fname);
     156
     157    sprintf(afio_found_changes, "%s.afio", ignorefiles_fname);
     158    paranoid_system("sync");
     159
    160160/*  sprintf (command,
    161161       "cat %s | grep \"afio: \" | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort | uniq | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s",
    162162       stderr_fname, afio_found_changes);
    163163*/
    164  
    165   log_msg(1, "Now scanning log file for 'afio: ' stuff");
    166   sprintf (command,
    167        "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s",
    168        stderr_fname, afio_found_changes);
    169   log_msg (2, command);
    170   res = system (command);
    171   if (res)
    172     {
    173       log_msg (2, "Warning - failed to think");
    174     }
    175 
    176   log_msg(1, "Now scanning log file for 'star: ' stuff");
    177   sprintf (command,
    178        "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s",
    179        stderr_fname, afio_found_changes);
    180   log_msg (2, command);
    181   res = system (command);
    182   if (res)
    183     {
    184       log_msg (2, "Warning - failed to think");
    185     }
     164
     165    log_msg(1, "Now scanning log file for 'afio: ' stuff");
     166    sprintf(command,
     167            "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s",
     168            stderr_fname, afio_found_changes);
     169    log_msg(2, command);
     170    res = system(command);
     171    if (res) {
     172        log_msg(2, "Warning - failed to think");
     173    }
     174
     175    log_msg(1, "Now scanning log file for 'star: ' stuff");
     176    sprintf(command,
     177            "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s",
     178            stderr_fname, afio_found_changes);
     179    log_msg(2, command);
     180    res = system(command);
     181    if (res) {
     182        log_msg(2, "Warning - failed to think");
     183    }
    186184//  exclude_nonexistent_files (afio_found_changes);
    187   afio_diffs = count_lines_in_file (afio_found_changes);
    188   sprintf (command,
    189        "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
    190        ignorefiles_fname, afio_found_changes, afio_found_changes,
    191        changedfiles_fname);
    192   log_msg (2, command);
    193   paranoid_system (command);
    194   paranoid_free(command);
    195   paranoid_free(afio_found_changes);
    196   return (afio_diffs);
     185    afio_diffs = count_lines_in_file(afio_found_changes);
     186    sprintf(command,
     187            "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
     188            ignorefiles_fname, afio_found_changes, afio_found_changes,
     189            changedfiles_fname);
     190    log_msg(2, command);
     191    paranoid_system(command);
     192    paranoid_free(command);
     193    paranoid_free(afio_found_changes);
     194    return (afio_diffs);
    197195}
    198196
     
    209207 * @return The number of sets containing differences (0 for success).
    210208 */
    211 int
    212 verify_afioballs_on_CD (struct s_bkpinfo *bkpinfo, char *mountpoint)
     209int verify_afioballs_on_CD(struct s_bkpinfo *bkpinfo, char *mountpoint)
    213210{
    214211
    215     /*@ buffers **********************************************************/
    216   char *tmp;
    217 
    218     /*@ int **************************************************************/
    219   int set_number = 0;
     212    /*@ buffers ********************************************************* */
     213    char *tmp;
     214
     215    /*@ int ************************************************************* */
     216    int set_number = 0;
    220217    int retval = 0;
    221218    int total_sets = 0;
    222219    int percentage = 0;
    223220
    224   assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    225   assert(bkpinfo!=NULL);
    226   malloc_string(tmp);
    227  
    228   for (set_number = 0;
    229        set_number < 9999
    230        &&
    231        !does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, set_number));
    232        set_number++);
    233   if (!does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, set_number)))
    234     {
    235       return (0);
    236     }
    237    
    238   if (g_last_afioball_number != set_number - 1)
    239     {
    240       if (set_number==0)
    241         {
    242       log_msg(1, "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more");
    243     }
    244       else
    245         {
    246           retval++;
    247           sprintf (tmp, "Warning - missing set(s) between %d and %d\n",
    248                g_last_afioball_number, set_number - 1);
    249           log_to_screen (tmp);
    250         }
    251     }
    252   sprintf (tmp, "Verifying %s #%d's tarballs", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    253   open_evalcall_form (tmp);
    254  
    255   for (total_sets = set_number;
    256        does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, total_sets));
    257        total_sets++) { log_msg(1, "total_sets = %d", total_sets); }
    258   for (; does_file_exist (vfy_tball_fname (bkpinfo, mountpoint, set_number));
    259        set_number++)
    260     {
    261       percentage =
    262     (set_number - g_last_afioball_number) * 100 / (total_sets -
    263                                g_last_afioball_number);
    264       update_evalcall_form (percentage);
    265       log_msg(1, "set = %d", set_number);
    266       retval +=
    267     verify_an_afioball_from_CD (bkpinfo,
    268                     vfy_tball_fname (bkpinfo, mountpoint,
    269                              set_number));
    270     }
    271   g_last_afioball_number = set_number - 1;
    272   close_evalcall_form ();
    273   paranoid_free(tmp);
    274   return (retval);
     221    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     222    assert(bkpinfo != NULL);
     223    malloc_string(tmp);
     224
     225    for (set_number = 0;
     226         set_number < 9999
     227         &&
     228         !does_file_exist(vfy_tball_fname
     229                          (bkpinfo, mountpoint, set_number));
     230         set_number++);
     231    if (!does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number))) {
     232        return (0);
     233    }
     234
     235    if (g_last_afioball_number != set_number - 1) {
     236        if (set_number == 0) {
     237            log_msg(1,
     238                    "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more");
     239        } else {
     240            retval++;
     241            sprintf(tmp, "Warning - missing set(s) between %d and %d\n",
     242                    g_last_afioball_number, set_number - 1);
     243            log_to_screen(tmp);
     244        }
     245    }
     246    sprintf(tmp, "Verifying %s #%d's tarballs",
     247            media_descriptor_string(bkpinfo->backup_media_type),
     248            g_current_media_number);
     249    open_evalcall_form(tmp);
     250
     251    for (total_sets = set_number;
     252         does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, total_sets));
     253         total_sets++) {
     254        log_msg(1, "total_sets = %d", total_sets);
     255    }
     256    for (;
     257         does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number));
     258         set_number++) {
     259        percentage =
     260            (set_number - g_last_afioball_number) * 100 / (total_sets -
     261                                                           g_last_afioball_number);
     262        update_evalcall_form(percentage);
     263        log_msg(1, "set = %d", set_number);
     264        retval +=
     265            verify_an_afioball_from_CD(bkpinfo,
     266                                       vfy_tball_fname(bkpinfo, mountpoint,
     267                                                       set_number));
     268    }
     269    g_last_afioball_number = set_number - 1;
     270    close_evalcall_form();
     271    paranoid_free(tmp);
     272    return (retval);
    275273}
    276274
     
    286284 * @return The number of differences (0 for perfect biggiefiles).
    287285 */
    288 int
    289 verify_all_slices_on_CD (struct s_bkpinfo *bkpinfo, char *mtpt)
     286int verify_all_slices_on_CD(struct s_bkpinfo *bkpinfo, char *mtpt)
    290287{
    291288
    292     /*@ buffer ***********************************************************/
    293   char *tmp;
    294   char *mountpoint;
     289    /*@ buffer ********************************************************** */
     290    char *tmp;
     291    char *mountpoint;
    295292//  char ca, cb;
    296   char *command;
    297   char *sz_exe;
    298   static char *bufblkA=NULL;
    299   static char *bufblkB=NULL;
    300   const long maxbufsize=65536L;
    301   long currsizA=0;
    302   long currsizB=0;
    303   long j;
    304 
    305     /*@ long *************************************************************/
    306   long bigfile_num = 0;
    307   long slice_num = -1;
    308   int res;
    309 
    310   static FILE*forig=NULL;
    311   static struct s_filename_and_lstat_info biggiestruct;
    312   static long last_bigfile_num = -1;
    313   static long last_slice_num = -1;
    314   FILE*pin;
    315   FILE*fin;
    316   int retval=0;
     293    char *command;
     294    char *sz_exe;
     295    static char *bufblkA = NULL;
     296    static char *bufblkB = NULL;
     297    const long maxbufsize = 65536L;
     298    long currsizA = 0;
     299    long currsizB = 0;
     300    long j;
     301
     302    /*@ long ************************************************************ */
     303    long bigfile_num = 0;
     304    long slice_num = -1;
     305    int res;
     306
     307    static FILE *forig = NULL;
     308    static struct s_filename_and_lstat_info biggiestruct;
     309    static long last_bigfile_num = -1;
     310    static long last_slice_num = -1;
     311    FILE *pin;
     312    FILE *fin;
     313    int retval = 0;
    317314//  long long outlen;
    318315
    319   malloc_string(tmp);
    320   malloc_string(mountpoint);
    321   malloc_string(command);
    322   malloc_string(sz_exe);
    323   if (!bufblkA) { if (!(bufblkA = malloc(maxbufsize))) { fatal_error("Cannot malloc bufblkA"); } }
    324   if (!bufblkB) { if (!(bufblkB = malloc(maxbufsize))) { fatal_error("Cannot malloc bufblkB"); } }
    325 
    326   assert(bkpinfo!=NULL);
    327   assert_string_is_neither_NULL_nor_zerolength(mtpt);
    328 
    329   if (bkpinfo->compression_level>0)
    330     {
    331       if (bkpinfo->use_lzo)
    332         { strcpy(sz_exe, "lzop"); }
    333       else
    334         { strcpy(sz_exe, "bzip2"); }
    335     }
    336   else
    337     { sz_exe[0] = '\0'; }
    338 
    339   iamhere("before vsbf");
    340   sprintf (tmp, "Verifying %s#%d's big files", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    341   open_evalcall_form (tmp);
    342   iamhere("after vsbf");
    343   sprintf (mountpoint, "%s/archives", mtpt);
    344   if (last_bigfile_num == -1)
    345     {
    346       bigfile_num = 0;
    347       slice_num = 0;
    348     }
    349   else if (slice_num == 0)
    350     {
    351       bigfile_num = last_bigfile_num + 1;
    352       slice_num = 0;
    353     }
    354   else
    355     {
    356       bigfile_num = last_bigfile_num;
    357       slice_num = last_slice_num + 1;
    358     }
    359   while (does_file_exist
    360     (slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix))
    361     ||
    362     does_file_exist
    363     (slice_fname(bigfile_num, slice_num, mountpoint, "")))
    364     {
     316    malloc_string(tmp);
     317    malloc_string(mountpoint);
     318    malloc_string(command);
     319    malloc_string(sz_exe);
     320    if (!bufblkA) {
     321        if (!(bufblkA = malloc(maxbufsize))) {
     322            fatal_error("Cannot malloc bufblkA");
     323        }
     324    }
     325    if (!bufblkB) {
     326        if (!(bufblkB = malloc(maxbufsize))) {
     327            fatal_error("Cannot malloc bufblkB");
     328        }
     329    }
     330
     331    assert(bkpinfo != NULL);
     332    assert_string_is_neither_NULL_nor_zerolength(mtpt);
     333
     334    if (bkpinfo->compression_level > 0) {
     335        if (bkpinfo->use_lzo) {
     336            strcpy(sz_exe, "lzop");
     337        } else {
     338            strcpy(sz_exe, "bzip2");
     339        }
     340    } else {
     341        sz_exe[0] = '\0';
     342    }
     343
     344    iamhere("before vsbf");
     345    sprintf(tmp, "Verifying %s#%d's big files",
     346            media_descriptor_string(bkpinfo->backup_media_type),
     347            g_current_media_number);
     348    open_evalcall_form(tmp);
     349    iamhere("after vsbf");
     350    sprintf(mountpoint, "%s/archives", mtpt);
     351    if (last_bigfile_num == -1) {
     352        bigfile_num = 0;
     353        slice_num = 0;
     354    } else if (slice_num == 0) {
     355        bigfile_num = last_bigfile_num + 1;
     356        slice_num = 0;
     357    } else {
     358        bigfile_num = last_bigfile_num;
     359        slice_num = last_slice_num + 1;
     360    }
     361    while (does_file_exist
     362           (slice_fname
     363            (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix))
     364           ||
     365           does_file_exist(slice_fname
     366                           (bigfile_num, slice_num, mountpoint, ""))) {
    365367// handle slices until end of CD
    366       if (slice_num == 0)
    367     {
    368       log_msg (2, "ISO=%d  bigfile=%ld --START--", g_current_media_number, bigfile_num);
    369       if ( !(fin = fopen( slice_fname( bigfile_num, slice_num, mountpoint, ""), "r" ) ) )
    370             { log_msg(2, "Cannot open bigfile's info file"); }
    371       else
    372         {
    373           if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct))
    374             { log_msg(2, "Unable to get biggiestruct"); }
    375           paranoid_fclose(fin);
    376         }
    377       sprintf( tmp, "%s/%s", bkpinfo->restore_path, biggiestruct.filename );
    378       log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
    379       if (!(forig = fopen(tmp, "r"))) { log_msg(2, "Failed to open bigfile. Darn."); retval++; }
    380       slice_num++;
    381     }
    382       else if (does_file_exist
    383         (slice_fname (bigfile_num, slice_num, mountpoint, "")))
    384     {
    385       log_msg (2, "ISO=%d  bigfile=%ld ---END---",
    386            g_current_media_number, bigfile_num);
    387       bigfile_num++;
    388       paranoid_fclose(forig);
    389       slice_num = 0;
    390     }
    391       else
    392     {
    393       log_msg (2, "ISO=%d  bigfile=%ld  slice=%ld  \r",
    394            g_current_media_number, bigfile_num, slice_num);
    395       if (bkpinfo->compression_level > 0)
    396         { sprintf(command, "cat %s | %s -dc 2>> %s", slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), sz_exe, MONDO_LOGFILE); }
    397       else
    398         { sprintf(command, "cat %s", slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)); }
    399       if ((pin = popen(command,"r")))
    400         {
    401           res=0;
    402           while(!feof(pin))
    403             {
    404           currsizA = fread(bufblkA, 1, maxbufsize, pin);
    405           if (currsizA<=0) { break; }
    406           currsizB = fread(bufblkB, 1, currsizA, forig);
    407           if (currsizA != currsizB) { res++; }
    408           else
    409             {
    410               for(j=0; j<currsizA && bufblkA[j]==bufblkB[j]; j++);
    411               if (j<currsizA) { res++;}
    412             }
    413         }
    414           paranoid_pclose(pin);
    415           if (res && !strncmp(biggiestruct.filename," /dev/", 5))
    416             {
    417           log_msg(3, "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via partimagehack, not dd.", biggiestruct.filename);
    418           log_msg(3, "If you really want verification for %s, please contact the devteam and offer an incentive.", biggiestruct.filename);
    419           res=0;
    420         }
    421           if (res)
    422             {
    423           log_msg(0, "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c", biggiestruct.filename);
    424           retval++;
    425         }
    426         }
    427       slice_num++;
    428     }
    429     }
    430   last_bigfile_num = bigfile_num;
    431   last_slice_num = slice_num - 1;
    432   if (last_slice_num < 0)
    433     {
    434       last_bigfile_num--;
    435     }
    436   close_evalcall_form ();
    437   if (bufblkA) { paranoid_free(bufblkA); }
    438   if (bufblkB) { paranoid_free(bufblkB); }
    439   paranoid_free(tmp);
    440   paranoid_free(command);
    441   paranoid_free(sz_exe);
    442   paranoid_free(mountpoint);
    443   return (0);
     368        if (slice_num == 0) {
     369            log_msg(2, "ISO=%d  bigfile=%ld --START--",
     370                    g_current_media_number, bigfile_num);
     371            if (!
     372                (fin =
     373                 fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""),
     374                       "r"))) {
     375                log_msg(2, "Cannot open bigfile's info file");
     376            } else {
     377                if (fread
     378                    ((void *) &biggiestruct, 1, sizeof(biggiestruct),
     379                     fin) < sizeof(biggiestruct)) {
     380                    log_msg(2, "Unable to get biggiestruct");
     381                }
     382                paranoid_fclose(fin);
     383            }
     384            sprintf(tmp, "%s/%s", bkpinfo->restore_path,
     385                    biggiestruct.filename);
     386            log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
     387            if (!(forig = fopen(tmp, "r"))) {
     388                log_msg(2, "Failed to open bigfile. Darn.");
     389                retval++;
     390            }
     391            slice_num++;
     392        } else if (does_file_exist
     393                   (slice_fname(bigfile_num, slice_num, mountpoint, ""))) {
     394            log_msg(2, "ISO=%d  bigfile=%ld ---END---",
     395                    g_current_media_number, bigfile_num);
     396            bigfile_num++;
     397            paranoid_fclose(forig);
     398            slice_num = 0;
     399        } else {
     400            log_msg(2, "ISO=%d  bigfile=%ld  slice=%ld  \r",
     401                    g_current_media_number, bigfile_num, slice_num);
     402            if (bkpinfo->compression_level > 0) {
     403                sprintf(command, "cat %s | %s -dc 2>> %s",
     404                        slice_fname(bigfile_num, slice_num, mountpoint,
     405                                    bkpinfo->zip_suffix), sz_exe,
     406                        MONDO_LOGFILE);
     407            } else {
     408                sprintf(command, "cat %s",
     409                        slice_fname(bigfile_num, slice_num, mountpoint,
     410                                    bkpinfo->zip_suffix));
     411            }
     412            if ((pin = popen(command, "r"))) {
     413                res = 0;
     414                while (!feof(pin)) {
     415                    currsizA = fread(bufblkA, 1, maxbufsize, pin);
     416                    if (currsizA <= 0) {
     417                        break;
     418                    }
     419                    currsizB = fread(bufblkB, 1, currsizA, forig);
     420                    if (currsizA != currsizB) {
     421                        res++;
     422                    } else {
     423                        for (j = 0;
     424                             j < currsizA && bufblkA[j] == bufblkB[j];
     425                             j++);
     426                        if (j < currsizA) {
     427                            res++;
     428                        }
     429                    }
     430                }
     431                paranoid_pclose(pin);
     432                if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) {
     433                    log_msg(3,
     434                            "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via partimagehack, not dd.",
     435                            biggiestruct.filename);
     436                    log_msg(3,
     437                            "If you really want verification for %s, please contact the devteam and offer an incentive.",
     438                            biggiestruct.filename);
     439                    res = 0;
     440                }
     441                if (res) {
     442                    log_msg(0,
     443                            "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c",
     444                            biggiestruct.filename);
     445                    retval++;
     446                }
     447            }
     448            slice_num++;
     449        }
     450    }
     451    last_bigfile_num = bigfile_num;
     452    last_slice_num = slice_num - 1;
     453    if (last_slice_num < 0) {
     454        last_bigfile_num--;
     455    }
     456    close_evalcall_form();
     457    if (bufblkA) {
     458        paranoid_free(bufblkA);
     459    }
     460    if (bufblkB) {
     461        paranoid_free(bufblkB);
     462    }
     463    paranoid_free(tmp);
     464    paranoid_free(command);
     465    paranoid_free(sz_exe);
     466    paranoid_free(mountpoint);
     467    return (0);
    444468}
    445469
     
    460484 * @return 0, always.
    461485 */
    462 int
    463 verify_a_tarball (struct s_bkpinfo *bkpinfo, char *tarball_fname)
     486int verify_a_tarball(struct s_bkpinfo *bkpinfo, char *tarball_fname)
    464487{
    465     /*@ buffers **********************************************************/
    466   char *command;
     488    /*@ buffers ********************************************************* */
     489    char *command;
    467490    char *outlog;
    468491    char *tmp;
    469     //  char *p;
    470 
    471     /*@ pointers ********************************************************/
    472   FILE *pin;
    473 
    474     /*@ long ************************************************************/
    475   long diffs = 0;
    476   /*  getcwd(old_pwd,MAX_STR_LEN-1); */
    477 
    478 
    479   command = malloc(2000);
    480   malloc_string(outlog);
    481   malloc_string(tmp);
    482   assert(bkpinfo!=NULL);
    483   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    484 
    485   log_it("Verifying fileset '%s'", tarball_fname);
    486   /*  chdir("/"); */
    487   sprintf (outlog, "%s/afio.log", bkpinfo->tmpdir);
     492    //  char *p;
     493
     494    /*@ pointers ******************************************************* */
     495    FILE *pin;
     496
     497    /*@ long *********************************************************** */
     498    long diffs = 0;
     499    /*  getcwd(old_pwd,MAX_STR_LEN-1); */
     500
     501
     502    command = malloc(2000);
     503    malloc_string(outlog);
     504    malloc_string(tmp);
     505    assert(bkpinfo != NULL);
     506    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     507
     508    log_it("Verifying fileset '%s'", tarball_fname);
     509    /*  chdir("/"); */
     510    sprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);
    488511/* if programmer forgot to say which compression thingy to use then find out */
    489   if (strstr (tarball_fname, ".lzo") && strcmp (bkpinfo->zip_suffix, "lzo"))
    490     {
    491       log_msg (2, "OK, I'm going to start using lzop.");
    492       strcpy (bkpinfo->zip_exe, "lzop");
    493       strcpy (bkpinfo->zip_suffix, "lzo");
    494       bkpinfo->use_lzo = TRUE;
    495     }
    496   if (strstr (tarball_fname, ".bz2") && strcmp (bkpinfo->zip_suffix, "bz2"))
    497     {
    498       log_msg (2, "OK, I'm going to start using bzip2.");
    499       strcpy (bkpinfo->zip_exe, "bzip2");
    500       strcpy (bkpinfo->zip_suffix, "bz2");
    501       bkpinfo->use_lzo = FALSE;
    502     }
    503   unlink(outlog);
    504   if (strstr(tarball_fname, ".star"))
    505     {
    506       bkpinfo->use_star = TRUE;
    507       if (strstr(tarball_fname, ".bz2"))
    508       sprintf (command, "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
    509            tarball_fname,
    510            (strstr(tarball_fname, ".bz2"))?"-bz":" ",
    511            outlog, outlog);
    512     }
    513   else
    514     {
    515       bkpinfo->use_star = FALSE;
    516       sprintf (command, "afio -r -P %s -Z %s >> %s 2>> %s",
    517        bkpinfo->zip_exe, tarball_fname, outlog, outlog);
    518     }
    519   log_msg(6, "command=%s", command);
    520   paranoid_system (command);
    521   if (length_of_file(outlog) < 10)
    522     {
    523       sprintf (command, "cat %s >> %s", outlog, MONDO_LOGFILE);
    524     }
    525   else
    526     {
    527       sprintf (command, "cat %s | cut -d':' -f%d | sort | uniq", outlog,
    528        (bkpinfo->use_star)?1:2);
    529       pin = popen (command, "r");
    530       if (pin)
    531         {
    532           for (fgets (tmp, MAX_STR_LEN, pin); !feof (pin);
    533            fgets (tmp, MAX_STR_LEN, pin))
    534         {
    535           if (bkpinfo->use_star)
    536             {
    537               if (!strstr(tmp, "diffopts="))
    538             {
    539               while( strlen(tmp)>0 && tmp[strlen(tmp)-1] < 32)
    540                 { tmp[strlen(tmp)-1] = '\0'; }
    541               if (strchr(tmp, '/') )
    542                 {
    543                   if (!diffs) { log_msg (0, "'%s' - differences found", tarball_fname); }
    544                           log_msg (0,"star: /%s", strip_afio_output_line (tmp));
    545                           diffs++;
     512    if (strstr(tarball_fname, ".lzo")
     513        && strcmp(bkpinfo->zip_suffix, "lzo")) {
     514        log_msg(2, "OK, I'm going to start using lzop.");
     515        strcpy(bkpinfo->zip_exe, "lzop");
     516        strcpy(bkpinfo->zip_suffix, "lzo");
     517        bkpinfo->use_lzo = TRUE;
     518    }
     519    if (strstr(tarball_fname, ".bz2")
     520        && strcmp(bkpinfo->zip_suffix, "bz2")) {
     521        log_msg(2, "OK, I'm going to start using bzip2.");
     522        strcpy(bkpinfo->zip_exe, "bzip2");
     523        strcpy(bkpinfo->zip_suffix, "bz2");
     524        bkpinfo->use_lzo = FALSE;
     525    }
     526    unlink(outlog);
     527    if (strstr(tarball_fname, ".star")) {
     528        bkpinfo->use_star = TRUE;
     529        if (strstr(tarball_fname, ".bz2"))
     530            sprintf(command,
     531                    "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
     532                    tarball_fname,
     533                    (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
     534                    outlog);
     535    } else {
     536        bkpinfo->use_star = FALSE;
     537        sprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s",
     538                bkpinfo->zip_exe, tarball_fname, outlog, outlog);
     539    }
     540    log_msg(6, "command=%s", command);
     541    paranoid_system(command);
     542    if (length_of_file(outlog) < 10) {
     543        sprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);
     544    } else {
     545        sprintf(command, "cat %s | cut -d':' -f%d | sort | uniq", outlog,
     546                (bkpinfo->use_star) ? 1 : 2);
     547        pin = popen(command, "r");
     548        if (pin) {
     549            for (fgets(tmp, MAX_STR_LEN, pin); !feof(pin);
     550                 fgets(tmp, MAX_STR_LEN, pin)) {
     551                if (bkpinfo->use_star) {
     552                    if (!strstr(tmp, "diffopts=")) {
     553                        while (strlen(tmp) > 0
     554                               && tmp[strlen(tmp) - 1] < 32) {
     555                            tmp[strlen(tmp) - 1] = '\0';
     556                        }
     557                        if (strchr(tmp, '/')) {
     558                            if (!diffs) {
     559                                log_msg(0, "'%s' - differences found",
     560                                        tarball_fname);
     561                            }
     562                            log_msg(0, "star: /%s",
     563                                    strip_afio_output_line(tmp));
     564                            diffs++;
     565                        }
     566                    }
     567                } else {
     568                    if (!diffs) {
     569                        log_msg(0, "'%s' - differences found",
     570                                tarball_fname);
     571                    }
     572                    log_msg(0, "afio: /%s", strip_afio_output_line(tmp));
     573                    diffs++;
     574                }
    546575            }
    547             }
    548             }
    549           else
    550             {
    551               if (!diffs) { log_msg (0, "'%s' - differences found", tarball_fname); }
    552                   log_msg (0,"afio: /%s", strip_afio_output_line (tmp));
    553                   diffs++;
    554             }
    555         }
    556           paranoid_pclose (pin);
    557         }
    558       else
    559         {
    560           log_OS_error(command);
    561          }
    562     }
    563   /*  chdir(old_pwd); */
    564   //  sprintf (tmp, "cat %s | uniq -u >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
    565   //  paranoid_system (tmp);
    566   //  unlink ("/tmp/mondo-verify.err");
    567   paranoid_free(command);
    568   paranoid_free(outlog);
    569   paranoid_free(tmp);
    570   return (0);
     576            paranoid_pclose(pin);
     577        } else {
     578            log_OS_error(command);
     579        }
     580    }
     581    /*  chdir(old_pwd); */
     582    //  sprintf (tmp, "cat %s | uniq -u >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
     583    //  paranoid_system (tmp);
     584    //  unlink ("/tmp/mondo-verify.err");
     585    paranoid_free(command);
     586    paranoid_free(outlog);
     587    paranoid_free(tmp);
     588    return (0);
    571589}
    572590
     
    586604 */
    587605int
    588 verify_an_afioball_from_CD (struct s_bkpinfo *bkpinfo, char *tarball_fname)
     606verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname)
    589607{
    590608
    591     /*@ int **************************************************************/
    592   int res = 0;
    593 
    594   assert(bkpinfo!=NULL);
    595   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    596 
    597   log_msg (1, "Verifying %s", tarball_fname);
    598   if (!does_file_exist (tarball_fname))
    599     {
    600       fatal_error ("Cannot verify nonexistent afioball");
    601     }
    602   res = verify_a_tarball (bkpinfo, tarball_fname);
    603   return (res);
     609    /*@ int ************************************************************* */
     610    int res = 0;
     611
     612    assert(bkpinfo != NULL);
     613    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     614
     615    log_msg(1, "Verifying %s", tarball_fname);
     616    if (!does_file_exist(tarball_fname)) {
     617        fatal_error("Cannot verify nonexistent afioball");
     618    }
     619    res = verify_a_tarball(bkpinfo, tarball_fname);
     620    return (res);
    604621}
    605622
     
    615632 */
    616633int
    617 verify_an_afioball_from_stream (struct s_bkpinfo *bkpinfo, char *orig_fname,
    618                   long long size)
     634verify_an_afioball_from_stream(struct s_bkpinfo *bkpinfo, char *orig_fname,
     635                               long long size)
    619636{
    620637
    621     /*@ int ***************************************************************/
    622   int retval = 0;
     638    /*@ int ************************************************************** */
     639    int retval = 0;
    623640    int res = 0;
    624641
    625     /*@ buffers ***********************************************************/
    626   char *tmp;
     642    /*@ buffers ********************************************************** */
     643    char *tmp;
    627644    char *tarball_fname;
    628645
    629     /*@ pointers **********************************************************/
    630     char  *p;
    631 
    632   malloc_string(tmp);
    633   malloc_string(tarball_fname);
    634   assert(bkpinfo!=NULL);
    635   assert_string_is_neither_NULL_nor_zerolength(orig_fname);
    636 
    637   p = strrchr (orig_fname, '/');
    638   if (!p)
    639     {
    640       p = orig_fname;
    641     }
    642   else
    643     {
    644       p++;
    645     }
    646   sprintf (tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
    647   paranoid_system (tmp);
    648   sprintf (tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
    649   sprintf (tmp, "Temporarily copying file from tape to '%s'", tarball_fname);
     646    /*@ pointers ********************************************************* */
     647    char *p;
     648
     649    malloc_string(tmp);
     650    malloc_string(tarball_fname);
     651    assert(bkpinfo != NULL);
     652    assert_string_is_neither_NULL_nor_zerolength(orig_fname);
     653
     654    p = strrchr(orig_fname, '/');
     655    if (!p) {
     656        p = orig_fname;
     657    } else {
     658        p++;
     659    }
     660    sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     661    paranoid_system(tmp);
     662    sprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
     663    sprintf(tmp, "Temporarily copying file from tape to '%s'",
     664            tarball_fname);
    650665/*  log_it(tmp); */
    651   read_file_from_stream_to_file (bkpinfo, tarball_fname, size);
    652   res = verify_a_tarball (bkpinfo, tarball_fname);
    653   if (res)
    654     {
    655       sprintf (tmp, "Afioball '%s' no longer matches your live filesystem",
    656            p);
    657       log_msg (0, tmp);
    658       retval++;
    659     }
    660   unlink (tarball_fname);
    661   paranoid_free(tmp);
    662   paranoid_free(tarball_fname);
    663   return (retval);
     666    read_file_from_stream_to_file(bkpinfo, tarball_fname, size);
     667    res = verify_a_tarball(bkpinfo, tarball_fname);
     668    if (res) {
     669        sprintf(tmp,
     670                "Afioball '%s' no longer matches your live filesystem", p);
     671        log_msg(0, tmp);
     672        retval++;
     673    }
     674    unlink(tarball_fname);
     675    paranoid_free(tmp);
     676    paranoid_free(tarball_fname);
     677    return (retval);
    664678}
    665679
     
    673687 */
    674688int
    675 verify_a_biggiefile_from_stream (struct s_bkpinfo *bkpinfo, char *biggie_fname,
    676                   long long size)
     689verify_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
     690                                char *biggie_fname, long long size)
    677691{
    678692
    679     /*@ int **************************************************************/
    680   int retval = 0;
     693    /*@ int ************************************************************* */
     694    int retval = 0;
    681695    int res = 0;
    682696    int current_slice_number = 0;
    683697    int ctrl_chr = '\0';
    684698
    685   /*@ char *************************************************************/
     699    /*@ char ************************************************************ */
    686700    char *test_file;
    687701    char *biggie_cksum;
     
    689703    char *tmp;
    690704    char *slice_fnam;
    691    
    692     /*@ pointers *********************************************************/
     705
     706    /*@ pointers ******************************************************** */
    693707    char *p;
    694708
    695     /*@ long long ********************************************************/
    696   long long slice_siz;
    697 
    698   malloc_string(test_file);
    699   malloc_string(biggie_cksum);
    700   malloc_string(orig_cksum);
    701   malloc_string(tmp);
    702   malloc_string(slice_fnam);
    703   assert(bkpinfo!=NULL);
    704   assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
    705 
    706   p = strrchr (biggie_fname, '/');
    707   if (!p)
    708     {
    709       p = biggie_fname;
    710     }
    711   else
    712     {
    713       p++;
    714     }
    715   sprintf (test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
    716   sprintf (tmp,
    717        "Temporarily copying biggiefile %s's slices from tape to '%s'", p,
    718        test_file);
     709    /*@ long long ******************************************************* */
     710    long long slice_siz;
     711
     712    malloc_string(test_file);
     713    malloc_string(biggie_cksum);
     714    malloc_string(orig_cksum);
     715    malloc_string(tmp);
     716    malloc_string(slice_fnam);
     717    assert(bkpinfo != NULL);
     718    assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
     719
     720    p = strrchr(biggie_fname, '/');
     721    if (!p) {
     722        p = biggie_fname;
     723    } else {
     724        p++;
     725    }
     726    sprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
     727    sprintf(tmp,
     728            "Temporarily copying biggiefile %s's slices from tape to '%s'",
     729            p, test_file);
    719730/*  log_it(tmp); */
    720   for (res = read_header_block_from_stream (&slice_siz, slice_fnam, &ctrl_chr);
    721        ctrl_chr != BLK_STOP_A_BIGGIE;
    722        res = read_header_block_from_stream (&slice_siz, slice_fnam, &ctrl_chr))
    723     {
    724       if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE)
    725     {
    726       wrong_marker (BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    727     }
    728       res = read_file_from_stream_to_file (bkpinfo, test_file, slice_siz);
    729       unlink (test_file);
    730       res = read_header_block_from_stream (&slice_siz, slice_fnam, &ctrl_chr);
    731       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE)
    732     {
    733       log_msg (2, "test_file = %s", test_file);
    734       wrong_marker (BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
    735     }
    736       current_slice_number++;
    737       retval += res;
    738     }
    739   strcpy (biggie_cksum, slice_fnam);
    740   if (biggie_cksum[0] != '\0')
    741     {
    742       strcpy (orig_cksum, calc_checksum_of_file (biggie_fname));
    743       if (strcmp (biggie_cksum, orig_cksum))
    744     {
    745       sprintf (tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
    746            orig_cksum);
    747       log_msg (2, tmp);
    748       sprintf (tmp, "%s has changed on live filesystem", biggie_fname);
    749       log_to_screen (tmp);
    750       sprintf(tmp, "echo \"%s\" >> /tmp/biggies.changed", biggie_fname);
    751       system(tmp);
    752     }
    753     }
    754   paranoid_free(test_file);
    755   paranoid_free(biggie_cksum);
    756   paranoid_free(orig_cksum);
    757   paranoid_free(tmp);
    758   paranoid_free(slice_fnam);
    759   return (retval);
     731    for (res =
     732         read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
     733         ctrl_chr != BLK_STOP_A_BIGGIE;
     734         res =
     735         read_header_block_from_stream(&slice_siz, slice_fnam,
     736                                       &ctrl_chr)) {
     737        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     738            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     739        }
     740        res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
     741        unlink(test_file);
     742        res =
     743            read_header_block_from_stream(&slice_siz, slice_fnam,
     744                                          &ctrl_chr);
     745        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     746            log_msg(2, "test_file = %s", test_file);
     747            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     748        }
     749        current_slice_number++;
     750        retval += res;
     751    }
     752    strcpy(biggie_cksum, slice_fnam);
     753    if (biggie_cksum[0] != '\0') {
     754        strcpy(orig_cksum, calc_checksum_of_file(biggie_fname));
     755        if (strcmp(biggie_cksum, orig_cksum)) {
     756            sprintf(tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
     757                    orig_cksum);
     758            log_msg(2, tmp);
     759            sprintf(tmp, "%s has changed on live filesystem",
     760                    biggie_fname);
     761            log_to_screen(tmp);
     762            sprintf(tmp, "echo \"%s\" >> /tmp/biggies.changed",
     763                    biggie_fname);
     764            system(tmp);
     765        }
     766    }
     767    paranoid_free(test_file);
     768    paranoid_free(biggie_cksum);
     769    paranoid_free(orig_cksum);
     770    paranoid_free(tmp);
     771    paranoid_free(slice_fnam);
     772    return (retval);
    760773}
    761774
     
    769782 * @return 0 for success (even if there are differences); nonzero for a tape error.
    770783 */
    771 int
    772 verify_afioballs_from_stream (struct s_bkpinfo *bkpinfo)
     784int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo)
    773785{
    774     /*@ int ***********************************************************/
    775   int retval = 0;
     786    /*@ int ********************************************************** */
     787    int retval = 0;
    776788    int res = 0;
    777789    long current_afioball_number = 0;
     
    779791    int total_afioballs = 0;
    780792
    781     /*@ buffers ******************************************************/
    782   char *tmp;
     793    /*@ buffers ***************************************************** */
     794    char *tmp;
    783795    char *fname;
    784   char *curr_xattr_list_fname;
    785   char *curr_acl_list_fname;
    786 
    787     /*@ long long ****************************************************/
    788   long long size = 0;
    789 
    790   assert(bkpinfo!=NULL);
    791   malloc_string(tmp);
    792   malloc_string(fname);
    793   malloc_string(curr_xattr_list_fname);
    794   malloc_string(curr_acl_list_fname);
    795 
    796   sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 
    797   sprintf(curr_acl_list_fname,     ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 
    798   log_to_screen ("Verifying regular archives on tape");
    799   total_afioballs = get_last_filelist_number (bkpinfo) + 1;
    800   open_progress_form ("Verifying filesystem",
    801               "I am verifying archives against your live filesystem now.",
    802               "Please wait. This may take a couple of hours.", "",
    803               total_afioballs);
    804   res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    805   if (ctrl_chr != BLK_START_AFIOBALLS)
    806     {
    807       iamhere("YOU SHOULD NOT GET HERE");
    808       iamhere("Grabbing the EXAT files");
    809       if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    810         {
    811       res = read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, curr_xattr_list_fname, curr_acl_list_fname);
    812     }
    813     }
    814   if (ctrl_chr != BLK_START_AFIOBALLS)
    815     { wrong_marker (BLK_START_AFIOBALLS, ctrl_chr); }
    816  
    817   for (res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    818        ctrl_chr != BLK_STOP_AFIOBALLS;
    819        res = read_header_block_from_stream (&size, fname, &ctrl_chr))
    820     {
    821       sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, current_afioball_number);
    822       sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, current_afioball_number);
    823       if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    824         {
    825       iamhere("Reading EXAT files from tape");
    826       res = read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, curr_xattr_list_fname, curr_acl_list_fname);
    827         }
    828       if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE)
    829     {
    830       wrong_marker (BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    831     }
    832       sprintf (tmp, "Verifying fileset #%ld", current_afioball_number);
    833       /*log_it(tmp); */
    834       update_progress_form (tmp);
    835       res = verify_an_afioball_from_stream (bkpinfo, fname, size);
    836       if (res)
    837     {
    838       sprintf (tmp, "Afioball %ld differs from live filesystem",
    839            current_afioball_number);
    840       log_to_screen (tmp);
    841     }
    842       retval += res;
    843       current_afioball_number++;
    844       g_current_progress++;
    845       res = read_header_block_from_stream (&size, fname, &ctrl_chr);
    846       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE)
    847     {
    848       wrong_marker (BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
    849     }
    850     }
    851   log_msg (1, "All done with afioballs");
    852   close_progress_form ();
    853   paranoid_free(tmp);
    854   paranoid_free(fname);
    855   paranoid_free(curr_xattr_list_fname);
    856   paranoid_free(curr_acl_list_fname);
    857   return (retval);
     796    char *curr_xattr_list_fname;
     797    char *curr_acl_list_fname;
     798
     799    /*@ long long *************************************************** */
     800    long long size = 0;
     801
     802    assert(bkpinfo != NULL);
     803    malloc_string(tmp);
     804    malloc_string(fname);
     805    malloc_string(curr_xattr_list_fname);
     806    malloc_string(curr_acl_list_fname);
     807
     808    sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
     809            bkpinfo->tmpdir);
     810    sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
     811            bkpinfo->tmpdir);
     812    log_to_screen("Verifying regular archives on tape");
     813    total_afioballs = get_last_filelist_number(bkpinfo) + 1;
     814    open_progress_form("Verifying filesystem",
     815                       "I am verifying archives against your live filesystem now.",
     816                       "Please wait. This may take a couple of hours.", "",
     817                       total_afioballs);
     818    res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     819    if (ctrl_chr != BLK_START_AFIOBALLS) {
     820        iamhere("YOU SHOULD NOT GET HERE");
     821        iamhere("Grabbing the EXAT files");
     822        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     823            res =
     824                read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
     825                                          curr_xattr_list_fname,
     826                                          curr_acl_list_fname);
     827        }
     828    }
     829    if (ctrl_chr != BLK_START_AFIOBALLS) {
     830        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
     831    }
     832
     833    for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     834         ctrl_chr != BLK_STOP_AFIOBALLS;
     835         res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
     836        sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
     837                bkpinfo->tmpdir, current_afioball_number);
     838        sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
     839                bkpinfo->tmpdir, current_afioball_number);
     840        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     841            iamhere("Reading EXAT files from tape");
     842            res =
     843                read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
     844                                          curr_xattr_list_fname,
     845                                          curr_acl_list_fname);
     846        }
     847        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     848            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     849        }
     850        sprintf(tmp, "Verifying fileset #%ld", current_afioball_number);
     851        /*log_it(tmp); */
     852        update_progress_form(tmp);
     853        res = verify_an_afioball_from_stream(bkpinfo, fname, size);
     854        if (res) {
     855            sprintf(tmp, "Afioball %ld differs from live filesystem",
     856                    current_afioball_number);
     857            log_to_screen(tmp);
     858        }
     859        retval += res;
     860        current_afioball_number++;
     861        g_current_progress++;
     862        res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     863        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     864            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     865        }
     866    }
     867    log_msg(1, "All done with afioballs");
     868    close_progress_form();
     869    paranoid_free(tmp);
     870    paranoid_free(fname);
     871    paranoid_free(curr_xattr_list_fname);
     872    paranoid_free(curr_acl_list_fname);
     873    return (retval);
    858874}
    859875
     
    866882 * @return 0 for success (even if there are differences); nonzero for a tape error.
    867883 */
    868 int
    869 verify_biggiefiles_from_stream (struct s_bkpinfo *bkpinfo)
     884int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo)
    870885{
    871886
    872     /*@ int *************************************************************/
    873   int retval = 0;
     887    /*@ int ************************************************************ */
     888    int retval = 0;
    874889    int res = 0;
    875890    int ctrl_chr = 0;
    876891
    877     /*@ long ************************************************************/
    878   long noof_biggiefiles = 0;
     892    /*@ long *********************************************************** */
     893    long noof_biggiefiles = 0;
    879894    long current_biggiefile_number = 0;
    880895
    881     /*@ buffers *********************************************************/
    882   char *tmp;
     896    /*@ buffers ******************************************************** */
     897    char *tmp;
    883898    char *orig_fname, *logical_fname;
    884899    char *comment;
    885900    char *curr_xattr_list_fname;
    886901    char *curr_acl_list_fname;
    887     /*@ pointers ********************************************************/
     902    /*@ pointers ******************************************************* */
    888903    char *p;
    889904
    890     /*@ long long size **************************************************/
    891   long long size = 0;
    892 
    893   assert(bkpinfo!=NULL);
    894   malloc_string(tmp);
    895   malloc_string(orig_fname);
    896   malloc_string(logical_fname);
    897   malloc_string(comment);
    898   malloc_string(curr_xattr_list_fname);
    899   malloc_string(curr_acl_list_fname);
    900 
    901   sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 
    902   sprintf(curr_acl_list_fname,     ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 
    903   sprintf (comment, "Verifying all bigfiles.");
    904   log_to_screen (comment);
    905   sprintf (tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
     905    /*@ long long size ************************************************* */
     906    long long size = 0;
     907
     908    assert(bkpinfo != NULL);
     909    malloc_string(tmp);
     910    malloc_string(orig_fname);
     911    malloc_string(logical_fname);
     912    malloc_string(comment);
     913    malloc_string(curr_xattr_list_fname);
     914    malloc_string(curr_acl_list_fname);
     915
     916    sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
     917            bkpinfo->tmpdir);
     918    sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
     919            bkpinfo->tmpdir);
     920    sprintf(comment, "Verifying all bigfiles.");
     921    log_to_screen(comment);
     922    sprintf(tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
    906923//  noof_biggiefiles = count_lines_in_file (tmp); // pointless
    907   res = read_header_block_from_stream (&size, orig_fname, &ctrl_chr);
    908   if (ctrl_chr != BLK_START_BIGGIEFILES)
    909     {
    910       if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    911         {
    912           iamhere("Grabbing the EXAT biggiefiles");
    913       res = read_EXAT_files_from_tape(bkpinfo, &size, orig_fname, &ctrl_chr, curr_xattr_list_fname, curr_acl_list_fname);
    914     }
    915     }
    916   if (ctrl_chr != BLK_START_BIGGIEFILES)
    917     {
    918       wrong_marker (BLK_START_BIGGIEFILES, ctrl_chr);
    919     }
    920   noof_biggiefiles = (long)size;
    921   log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);
    922   open_progress_form ("Verifying big files", comment,
    923               "Please wait. This may take some time.", "",
    924               noof_biggiefiles);
    925   for (res = read_header_block_from_stream (&size, orig_fname, &ctrl_chr);
    926        ctrl_chr != BLK_STOP_BIGGIEFILES;
    927        res = read_header_block_from_stream (&size, orig_fname, &ctrl_chr))
    928     {
    929       if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE)
     924    res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
     925    if (ctrl_chr != BLK_START_BIGGIEFILES) {
     926        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     927            iamhere("Grabbing the EXAT biggiefiles");
     928            res =
     929                read_EXAT_files_from_tape(bkpinfo, &size, orig_fname,
     930                                          &ctrl_chr, curr_xattr_list_fname,
     931                                          curr_acl_list_fname);
     932        }
     933    }
     934    if (ctrl_chr != BLK_START_BIGGIEFILES) {
     935        wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr);
     936    }
     937    noof_biggiefiles = (long) size;
     938    log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);
     939    open_progress_form("Verifying big files", comment,
     940                       "Please wait. This may take some time.", "",
     941                       noof_biggiefiles);
     942    for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
     943         ctrl_chr != BLK_STOP_BIGGIEFILES;
     944         res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr))
    930945    {
    931       wrong_marker (BLK_START_A_NORMBIGGIE, ctrl_chr);
    932     }
    933       p = strrchr (orig_fname, '/');
    934       if (!p)
    935     {
    936       p = orig_fname;
    937     }
    938       else
    939     {
    940       p++;
    941     }
    942       sprintf (comment, "Verifying bigfile #%ld (%ld K)",
    943            current_biggiefile_number, (long) size >> 10);
    944       update_progress_form (comment);
    945       sprintf( logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
    946       res = verify_a_biggiefile_from_stream (bkpinfo, logical_fname, size);
    947       retval += res;
    948       current_biggiefile_number++;
    949       g_current_progress++;
    950     }
    951   close_progress_form ();
    952   paranoid_free(orig_fname);
    953   paranoid_free(logical_fname);
    954   paranoid_free(curr_xattr_list_fname);
    955   paranoid_free(curr_acl_list_fname);
    956   paranoid_free(comment);
    957   paranoid_free(tmp);
    958   return (retval);
     946        if (ctrl_chr != BLK_START_A_NORMBIGGIE
     947            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
     948            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
     949        }
     950        p = strrchr(orig_fname, '/');
     951        if (!p) {
     952            p = orig_fname;
     953        } else {
     954            p++;
     955        }
     956        sprintf(comment, "Verifying bigfile #%ld (%ld K)",
     957                current_biggiefile_number, (long) size >> 10);
     958        update_progress_form(comment);
     959        sprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
     960        res =
     961            verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
     962        retval += res;
     963        current_biggiefile_number++;
     964        g_current_progress++;
     965    }
     966    close_progress_form();
     967    paranoid_free(orig_fname);
     968    paranoid_free(logical_fname);
     969    paranoid_free(curr_xattr_list_fname);
     970    paranoid_free(curr_acl_list_fname);
     971    paranoid_free(comment);
     972    paranoid_free(tmp);
     973    return (retval);
    959974}
    960975
     
    976991 * @ingroup verifyGroup
    977992 */
    978 int
    979 verify_cd_image (struct s_bkpinfo *bkpinfo)
     993int verify_cd_image(struct s_bkpinfo *bkpinfo)
    980994{
    981995
    982     /*@ int *************************************************************/
    983   int retval = 0;
    984 
    985     /*@ buffers *********************************************************/
    986   char *mountpoint;
     996    /*@ int ************************************************************ */
     997    int retval = 0;
     998
     999    /*@ buffers ******************************************************** */
     1000    char *mountpoint;
    9871001    char *command;
    9881002    char *tmp;
    9891003    char *fname;
    9901004#ifdef __FreeBSD__
    991         char mdd[32];
     1005    char mdd[32];
    9921006    char *mddevice = mdd;
    993         int ret = 0; int vndev = 2;
     1007    int ret = 0;
     1008    int vndev = 2;
    9941009#else
    9951010//skip
    9961011#endif
    9971012
    998   command = malloc(2000);
    999   malloc_string(mountpoint);
    1000   malloc_string(tmp);
    1001   malloc_string(fname);
    1002  
    1003   assert(bkpinfo!=NULL);
    1004 
    1005   sprintf (mountpoint, "%s/cdrom", bkpinfo->tmpdir);
    1006   sprintf (fname, "%s/%s/%s-%d.iso", bkpinfo->nfs_remote_dir, bkpinfo->isodir,
    1007           bkpinfo->prefix, g_current_media_number);
    1008 
    1009   mkdir (mountpoint, 1777);
    1010   sync ();
    1011   if (!does_file_exist (fname))
    1012     {
    1013       sprintf (tmp,
    1014            "%s not found; assuming you backed up to CD; verifying CD...",
    1015            fname);
    1016       log_msg (2, tmp);
    1017       if (bkpinfo->manual_cd_tray)
    1018     {
    1019       popup_and_OK ("Please push CD tray closed.");
    1020     }
    1021       if (find_and_mount_actual_cd (bkpinfo, mountpoint))
    1022     {
    1023       log_to_screen ("failed to mount actual CD");
    1024       return (1);
    1025     }
    1026     }
    1027   else
    1028     {
    1029       sprintf (tmp, "%s found; verifying ISO...", fname);
     1013    command = malloc(2000);
     1014    malloc_string(mountpoint);
     1015    malloc_string(tmp);
     1016    malloc_string(fname);
     1017
     1018    assert(bkpinfo != NULL);
     1019
     1020    sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir);
     1021    sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->nfs_remote_dir,
     1022            bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
     1023
     1024    mkdir(mountpoint, 1777);
     1025    sync();
     1026    if (!does_file_exist(fname)) {
     1027        sprintf(tmp,
     1028                "%s not found; assuming you backed up to CD; verifying CD...",
     1029                fname);
     1030        log_msg(2, tmp);
     1031        if (bkpinfo->manual_cd_tray) {
     1032            popup_and_OK("Please push CD tray closed.");
     1033        }
     1034        if (find_and_mount_actual_cd(bkpinfo, mountpoint)) {
     1035            log_to_screen("failed to mount actual CD");
     1036            return (1);
     1037        }
     1038    } else {
     1039        sprintf(tmp, "%s found; verifying ISO...", fname);
    10301040#ifdef __FreeBSD__
    1031       ret = 0;
    1032       vndev = 2;
    1033       mddevice = make_vn (fname);
    1034       if (ret)
    1035         {
    1036           sprintf (tmp, "make_vn of %s failed; unable to verify ISO\n", fname);
    1037           log_to_screen (tmp);
    1038           return (1);
    1039         }
    1040       sprintf (command, "mount_cd9660 %s %s", mddevice, mountpoint);
     1041        ret = 0;
     1042        vndev = 2;
     1043        mddevice = make_vn(fname);
     1044        if (ret) {
     1045            sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n",
     1046                    fname);
     1047            log_to_screen(tmp);
     1048            return (1);
     1049        }
     1050        sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);
    10411051#else
    1042       sprintf (command, "mount -o loop,ro -t iso9660 %s %s", fname,
    1043            mountpoint);
     1052        sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname,
     1053                mountpoint);
    10441054#endif
    1045       if (run_program_and_log_output(command, FALSE))
    1046     {
    1047       sprintf (tmp, "%s failed; unable to mount ISO image\n", command);
    1048       log_to_screen (tmp);
    1049       return (1);
    1050     }
    1051     }
    1052   log_msg (2, "OK, I've mounted the ISO/CD\n");
    1053   sprintf (tmp, "%s/archives/NOT-THE-LAST", mountpoint);
    1054   if (!does_file_exist (tmp))
    1055     {
    1056       log_msg
    1057     (2, "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
    1058       bkpinfo->verify_data = FALSE;
     1055        if (run_program_and_log_output(command, FALSE)) {
     1056            sprintf(tmp, "%s failed; unable to mount ISO image\n",
     1057                    command);
     1058            log_to_screen(tmp);
     1059            return (1);
     1060        }
     1061    }
     1062    log_msg(2, "OK, I've mounted the ISO/CD\n");
     1063    sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);
     1064    if (!does_file_exist(tmp)) {
     1065        log_msg
     1066            (2,
     1067            "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
     1068        bkpinfo->verify_data = FALSE;
    10591069/*
    10601070   (a) It's an easy way to tell the calling subroutine that we've finished &
     
    10621072   from running after the per-CD verifier has run too.
    10631073*/
    1064     }
    1065   verify_afioballs_on_CD (bkpinfo, mountpoint);
    1066   iamhere("before verify_all_slices");
    1067   verify_all_slices_on_CD (bkpinfo, mountpoint);
     1074    }
     1075    verify_afioballs_on_CD(bkpinfo, mountpoint);
     1076    iamhere("before verify_all_slices");
     1077    verify_all_slices_on_CD(bkpinfo, mountpoint);
    10681078
    10691079#ifdef __FreeBSD__
    1070   ret=0;
    1071   sprintf (command, "umount %s", mountpoint);
    1072   ret += system (command);
    1073   ret += kick_vn (mddevice);
    1074   if (ret)
     1080    ret = 0;
     1081    sprintf(command, "umount %s", mountpoint);
     1082    ret += system(command);
     1083    ret += kick_vn(mddevice);
     1084    if (ret)
    10751085#else
    1076   sprintf (command, "umount %s", mountpoint);
    1077   if (system (command))
     1086    sprintf(command, "umount %s", mountpoint);
     1087    if (system(command))
    10781088#endif
    1079     {
    1080       sprintf (tmp, "%s failed; unable to unmount ISO image\n", command);
    1081       log_to_screen (tmp);
    1082       retval++;
    1083     }
    1084   else
    1085     {
    1086       log_msg (2, "OK, I've unmounted the ISO file\n");
    1087     }
    1088   if (!does_file_exist (fname))
    1089     {
    1090       sprintf(command, "umount %s", bkpinfo->media_device);
    1091       run_program_and_log_output(command, 2);
    1092       if (!bkpinfo->please_dont_eject && eject_device(bkpinfo->media_device))
    10931089    {
    1094       log_msg (2, "Failed to eject CD-ROM drive");
    1095     }
    1096     }
    1097   paranoid_free(command);
    1098   paranoid_free(mountpoint);
    1099   paranoid_free(tmp);
    1100   paranoid_free(fname);
    1101   return (retval);
     1090        sprintf(tmp, "%s failed; unable to unmount ISO image\n", command);
     1091        log_to_screen(tmp);
     1092        retval++;
     1093    } else {
     1094        log_msg(2, "OK, I've unmounted the ISO file\n");
     1095    }
     1096    if (!does_file_exist(fname)) {
     1097        sprintf(command, "umount %s", bkpinfo->media_device);
     1098        run_program_and_log_output(command, 2);
     1099        if (!bkpinfo->please_dont_eject
     1100            && eject_device(bkpinfo->media_device)) {
     1101            log_msg(2, "Failed to eject CD-ROM drive");
     1102        }
     1103    }
     1104    paranoid_free(command);
     1105    paranoid_free(mountpoint);
     1106    paranoid_free(tmp);
     1107    paranoid_free(fname);
     1108    return (retval);
    11021109}
    11031110
     
    11091116 * @ingroup verifyGroup
    11101117 */
    1111 int
    1112 verify_tape_backups (struct s_bkpinfo *bkpinfo)
     1118int verify_tape_backups(struct s_bkpinfo *bkpinfo)
    11131119{
    11141120
    1115     /*@ int *************************************************************/
    1116   int retval = 0;
    1117 
    1118     /*@ buffers *********************************************************/
    1119   char tmp[MAX_STR_LEN];
    1120   char changed_files_fname[MAX_STR_LEN];
    1121 
    1122     /*@ long ************************************************************/
    1123   long diffs = 0;
    1124 
    1125   assert(bkpinfo!=NULL);
    1126 
    1127   log_msg (3, "verify_tape_backups --- starting");
    1128   log_to_screen ("Verifying backups");
    1129   openin_tape (bkpinfo);
     1121    /*@ int ************************************************************ */
     1122    int retval = 0;
     1123
     1124    /*@ buffers ******************************************************** */
     1125    char tmp[MAX_STR_LEN];
     1126    char changed_files_fname[MAX_STR_LEN];
     1127
     1128    /*@ long *********************************************************** */
     1129    long diffs = 0;
     1130
     1131    assert(bkpinfo != NULL);
     1132
     1133    log_msg(3, "verify_tape_backups --- starting");
     1134    log_to_screen("Verifying backups");
     1135    openin_tape(bkpinfo);
    11301136/* verify archives themselves */
    1131   retval += verify_afioballs_from_stream (bkpinfo);
    1132   retval += verify_biggiefiles_from_stream (bkpinfo);
     1137    retval += verify_afioballs_from_stream(bkpinfo);
     1138    retval += verify_biggiefiles_from_stream(bkpinfo);
    11331139/* find the final blocks */
    1134   paranoid_system ("sync");
    1135   sleep (2);
    1136   closein_tape (bkpinfo);
     1140    paranoid_system("sync");
     1141    sleep(2);
     1142    closein_tape(bkpinfo);
    11371143/* close tape; exit */
    11381144//  fclose(g_tape_stream); <-- not needed; is handled by closein_tape()
    1139   paranoid_system("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
    1140   sprintf (changed_files_fname, "/tmp/changed.files.%d", (int)(random()%32767));
    1141   sprintf (tmp,
    1142        "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",
    1143        MONDO_LOGFILE, (bkpinfo->use_star)?"star":"afio", changed_files_fname);
    1144   log_msg (2, "Running command to derive list of changed files");
    1145   log_msg (2, tmp);
    1146   if (system (tmp))
    1147     {
    1148       if (does_file_exist(changed_files_fname) && length_of_file(changed_files_fname)>2)
    1149         { log_to_screen("Warning - unable to check logfile to derive list of changed files"); }
    1150       else
    1151         { log_to_screen("No differences found. Therefore, no 'changed.files' text file."); }
    1152     }
    1153   sprintf(tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname);
    1154   paranoid_system(tmp);
    1155 
    1156   diffs = count_lines_in_file (changed_files_fname);
    1157   if (diffs > 0)
    1158     {
    1159       sprintf (tmp, "cp -f %s %s", changed_files_fname, "/tmp/changed.files");
    1160       run_program_and_log_output(tmp, FALSE);
    1161       sprintf (tmp,
    1162            "%ld files differed from live filesystem; type less %s or less %s to see",
    1163            diffs, changed_files_fname, "/tmp/changed.files");
    1164       log_msg (0, tmp);
    1165       log_to_screen ("See /tmp/changed.files for a list of nonmatching files.");
    1166       log_to_screen ("The files probably changed on filesystem, not on backup media.");
    1167       //      retval++;
    1168     }
    1169   return (retval);
     1145    paranoid_system
     1146        ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
     1147    sprintf(changed_files_fname, "/tmp/changed.files.%d",
     1148            (int) (random() % 32767));
     1149    sprintf(tmp,
     1150            "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",
     1151            MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio",
     1152            changed_files_fname);
     1153    log_msg(2, "Running command to derive list of changed files");
     1154    log_msg(2, tmp);
     1155    if (system(tmp)) {
     1156        if (does_file_exist(changed_files_fname)
     1157            && length_of_file(changed_files_fname) > 2) {
     1158            log_to_screen
     1159                ("Warning - unable to check logfile to derive list of changed files");
     1160        } else {
     1161            log_to_screen
     1162                ("No differences found. Therefore, no 'changed.files' text file.");
     1163        }
     1164    }
     1165    sprintf(tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname);
     1166    paranoid_system(tmp);
     1167
     1168    diffs = count_lines_in_file(changed_files_fname);
     1169    if (diffs > 0) {
     1170        sprintf(tmp, "cp -f %s %s", changed_files_fname,
     1171                "/tmp/changed.files");
     1172        run_program_and_log_output(tmp, FALSE);
     1173        sprintf(tmp,
     1174                "%ld files differed from live filesystem; type less %s or less %s to see",
     1175                diffs, changed_files_fname, "/tmp/changed.files");
     1176        log_msg(0, tmp);
     1177        log_to_screen
     1178            ("See /tmp/changed.files for a list of nonmatching files.");
     1179        log_to_screen
     1180            ("The files probably changed on filesystem, not on backup media.");
     1181        //      retval++;
     1182    }
     1183    return (retval);
    11701184}
    11711185
     
    11811195 * @ingroup stringGroup
    11821196 */
    1183 char *
    1184 vfy_tball_fname (struct s_bkpinfo *bkpinfo, char *mountpoint, int setno)
     1197char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint,
     1198                      int setno)
    11851199{
    1186     /*@ buffers ********************************************************/
    1187   static char output[MAX_STR_LEN];
    1188 
    1189   assert(bkpinfo!=NULL);
    1190   assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    1191   sprintf (output, "%s/archives/%d.star.%s", mountpoint, setno,
    1192        bkpinfo->zip_suffix);
    1193   if (!does_file_exist(output))
    1194     {
    1195       sprintf (output, "%s/archives/%d.afio.%s", mountpoint, setno,
    1196        bkpinfo->zip_suffix);
    1197     }
    1198   return (output);
     1200    /*@ buffers ******************************************************* */
     1201    static char output[MAX_STR_LEN];
     1202
     1203    assert(bkpinfo != NULL);
     1204    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     1205    sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno,
     1206            bkpinfo->zip_suffix);
     1207    if (!does_file_exist(output)) {
     1208        sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno,
     1209                bkpinfo->zip_suffix);
     1210    }
     1211    return (output);
    11991212}
  • branches/2.05/mondo/mondo/common/libmondo-verify.h

    r30 r128  
    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 *);
  • branches/2.05/mondo/mondo/common/libmondo.h

    r30 r128  
    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 
  • branches/2.05/mondo/mondo/common/mondostructures.h

    r30 r128  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: mondostructures.h,v 1.3 2004/06/17 08:49:06 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    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 
  • branches/2.05/mondo/mondo/common/my-stuff.h

    r126 r128  
    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 -speed=1 -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 -speed=1 -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
    529 #endif /* _MY_STUFF_H_ */
     530#endif                          /* _MY_STUFF_H_ */
  • branches/2.05/mondo/mondo/common/newt-specific-EXT.h

    r30 r128  
    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;
  • branches/2.05/mondo/mondo/common/newt-specific.c

    r126 r128  
    124124//static char cvsid[] = "$Id$";
    125125
    126 extern pid_t g_mastermind_pid;
    127 extern char *g_tmpfs_mountpt;
    128 extern char *g_boot_mountpt;
    129 extern char *g_mondo_home;
    130 
    131 extern char g_version[];
    132 
    133 extern void set_signals(int);
     126    extern pid_t g_mastermind_pid;
     127    extern char *g_tmpfs_mountpt;
     128    extern char *g_boot_mountpt;
     129    extern char *g_mondo_home;
     130
     131    extern char g_version[];
     132
     133    extern void set_signals(int);
    134134
    135135/**
     
    140140 * Whether we are currently in a nested call of fatal_error().
    141141 */
    142 bool g_exiting=FALSE;
     142    bool g_exiting = FALSE;
    143143
    144144/**
    145145 * Padding below the Newt components, to overcome bugs in Newt.
    146146 */
    147 char g_haharrrrr[500];
    148 
    149 
    150 newtComponent g_timeline=NULL, ///< The line of the progress form that shows the time elapsed/remaining
    151     g_percentline=NULL, ///< The line of the progress form that shows the percent completed/remaining
    152     g_scale=NULL, ///< The progress bar component in the progress form
    153     g_progressForm=NULL, ///< The progress form component itself
    154     g_blurb1=NULL, ///< The component for line 1 of the blurb in the progress form
    155     g_blurb2=NULL, ///< The component for line 2 of the blurb in the progress form
    156     g_blurb3=NULL, ///< The component for line 3 (updated continuously) of the blurb in the progress form
    157     g_label=NULL; ///< ????? @bug ?????
     147    char g_haharrrrr[500];
     148
     149
     150    newtComponent g_timeline = NULL,    ///< The line of the progress form that shows the time elapsed/remaining
     151        g_percentline = NULL,   ///< The line of the progress form that shows the percent completed/remaining
     152        g_scale = NULL,         ///< The progress bar component in the progress form
     153        g_progressForm = NULL,  ///< The progress form component itself
     154        g_blurb1 = NULL,        ///< The component for line 1 of the blurb in the progress form
     155        g_blurb2 = NULL,        ///< The component for line 2 of the blurb in the progress form
     156        g_blurb3 = NULL,        ///< The component for line 3 (updated continuously) of the blurb in the progress form
     157        g_label = NULL;         ///< ????? @bug ?????
    158158
    159159/**
    160160 * Padding above the Newt components, to overcome bugs in Newt.
    161161 */
    162 char g_jim_lad_yarr[500];
    163 char **err_log_lines = NULL, ///< The list of log lines to show on the screen.
    164     g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 1 of the blurb in the progress form
    165     g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 2 of the blurb in the progress form
    166     g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = ""; ///< The string for line 3 (updated continuously) of the blurb in the progress form
    167 newtComponent g_isoform_main = NULL, ///< The evalcall form component itself
    168     g_isoform_header=NULL, ///< The component for the evalcall form title
    169     g_isoform_scale=NULL, ///< The progress bar component in the evalcall form
    170     g_isoform_timeline=NULL, ///< The line of the evalcall form that shows the time elapsed/remaining
    171     g_isoform_pcline=NULL; ///< The line of the evalcall form that shows the percent completed/remaining
    172 long g_isoform_starttime; ///< The time (in seconds since the epoch) that the evalcall form was opened.
    173 int g_isoform_old_progress = -1; ///< The most recent progress update of the evalcall form (percent).
    174 char g_isoform_header_str[MAX_STR_LEN]="                                                                                                               "; ///< The string for the evalcall form title.
    175 int g_mysterious_dot_counter; ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3
    176 int g_noof_log_lines = 6; ///< The number of lines to show in the log at the bottom of the screen.
    177 int g_noof_rows = 25; ///< The number of rows on the screen.
    178 
    179 int g_currentY = 3; ///< The row to write background progress messages to. Incremented each time a message is written.
    180 extern int g_current_media_number;
    181 pid_t g_main_pid = 0; ///< The PID of the main Mondo process.
    182 long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form.
    183 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
    184 long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened.
    185 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
    186 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo.
    187     g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.
    188 bool g_called_by_xmondo=FALSE; ///< @bug Unneeded w/current XMondo.
    189 char *g_erase_tmpdir_and_scratchdir; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.
    190 char *g_selfmounted_isodir; ///< Holds the NFS mountpoint if mounted via mondoarchive.
     162    char g_jim_lad_yarr[500];
     163    char **err_log_lines = NULL,    ///< The list of log lines to show on the screen.
     164        g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "",   ///< The string for line 1 of the blurb in the progress form
     165        g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "",   ///< The string for line 2 of the blurb in the progress form
     166        g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = "";   ///< The string for line 3 (updated continuously) of the blurb in the progress form
     167    newtComponent g_isoform_main = NULL,    ///< The evalcall form component itself
     168        g_isoform_header = NULL,    ///< The component for the evalcall form title
     169        g_isoform_scale = NULL, ///< The progress bar component in the evalcall form
     170        g_isoform_timeline = NULL,  ///< The line of the evalcall form that shows the time elapsed/remaining
     171        g_isoform_pcline = NULL;    ///< The line of the evalcall form that shows the percent completed/remaining
     172    long g_isoform_starttime;   ///< The time (in seconds since the epoch) that the evalcall form was opened.
     173    int g_isoform_old_progress = -1;    ///< The most recent progress update of the evalcall form (percent).
     174    char g_isoform_header_str[MAX_STR_LEN] = "                                                                                                               "; ///< The string for the evalcall form title.
     175    int g_mysterious_dot_counter;   ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3
     176    int g_noof_log_lines = 6;   ///< The number of lines to show in the log at the bottom of the screen.
     177    int g_noof_rows = 25;       ///< The number of rows on the screen.
     178
     179    int g_currentY = 3;         ///< The row to write background progress messages to. Incremented each time a message is written.
     180    extern int g_current_media_number;
     181    pid_t g_main_pid = 0;       ///< The PID of the main Mondo process.
     182    long g_maximum_progress = 999;  ///< The maximum amount of progress (100%) for the currently opened progress form.
     183    long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
     184    long g_start_time = 0;      ///< The time (in seconds since the epoch) that the progress form was opened.
     185    bool g_text_mode = TRUE;    ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
     186    char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN],  ///< ... @bug Unneeded w/current XMondo.
     187     g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.
     188    bool g_called_by_xmondo = FALSE;    ///< @bug Unneeded w/current XMondo.
     189    char *g_erase_tmpdir_and_scratchdir;    ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.
     190    char *g_selfmounted_isodir; ///< Holds the NFS mountpoint if mounted via mondoarchive.
    191191
    192192/* @} - end of globalGroup */
     
    194194//int g_fd_in=-1, g_fd_out=-1;
    195195
    196 void popup_and_OK(char*);
     196    void popup_and_OK(char *);
    197197
    198198
     
    206206 * @return TRUE for yes; FALSE for no.
    207207 */
    208 bool
    209 ask_me_yes_or_no (char *prompt)
    210 {
    211 
    212     /*@ buffers ***********************************************************/
    213   char *tmp;
    214   int i;
    215 
    216   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    217   assert_string_is_neither_NULL_nor_zerolength(prompt);
    218 
    219   if (g_text_mode)
    220     {
    221       while(1)
    222         {
    223           system("sync");
    224           printf ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", prompt);
    225       (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    226       if (tmp[strlen (tmp) - 1] == '\n')
    227           tmp[strlen (tmp) - 1] = '\0';
    228 
    229           i = (int) strlen(tmp);
    230           if (i>0 && tmp[i-1]<32) { tmp[i-1]='\0'; }
    231           if (strstr ("yesYES", tmp))
    232             {
    233           paranoid_free(tmp);
    234               return (TRUE);
    235             }
    236           else if (strstr ("NOno", tmp))
    237             {
    238           paranoid_free(tmp);
    239               return (FALSE);
    240         }
    241           else
    242             {
    243               system("sync");
    244               printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
    245             }
    246         }
    247     }
    248   else
    249     {
    250       paranoid_free(tmp);
    251       return (popup_with_buttons (prompt, "Yes", "No"));
    252     }
    253 }
     208     bool ask_me_yes_or_no(char *prompt) {
     209
     210        /*@ buffers ********************************************************** */
     211        char *tmp;
     212        int i;
     213
     214         tmp = malloc(MAX_NEWT_COMMENT_LEN);
     215         assert_string_is_neither_NULL_nor_zerolength(prompt);
     216
     217        if (g_text_mode) {
     218            while (1) {
     219                system("sync");
     220                printf
     221                    ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ",
     222                     prompt);
     223                (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     224                if (tmp[strlen(tmp) - 1] == '\n')
     225                    tmp[strlen(tmp) - 1] = '\0';
     226
     227                i = (int) strlen(tmp);
     228                if (i > 0 && tmp[i - 1] < 32) {
     229                    tmp[i - 1] = '\0';
     230                }
     231                if (strstr("yesYES", tmp)) {
     232                    paranoid_free(tmp);
     233                    return (TRUE);
     234                } else if (strstr("NOno", tmp)) {
     235                    paranoid_free(tmp);
     236                    return (FALSE);
     237                } else {
     238                    system("sync");
     239                    printf
     240                        ("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
     241                }
     242            }
     243        } else {
     244            paranoid_free(tmp);
     245            return (popup_with_buttons(prompt, "Yes", "No"));
     246        }
     247    }
    254248
    255249
     
    260254 * @return TRUE for OK, FALSE for Cancel.
    261255 */
    262 bool
    263 ask_me_OK_or_cancel (char *prompt)
    264 {
    265 
    266     /*@ buffer ************************************************************/
    267   char *tmp;
    268   int i;
    269 
    270   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    271   assert_string_is_neither_NULL_nor_zerolength(prompt);
    272   if (g_text_mode)
    273     {
    274       system("sync");
    275       printf ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", prompt);
    276       (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    277       if (tmp[strlen (tmp) - 1] == '\n')
    278       tmp[strlen (tmp) - 1] = '\0';
    279 
    280       i = (int) strlen(tmp);
    281       if (i>0 && tmp[i-1]<32) { tmp[i-1]='\0'; }
    282       if (strstr ("okOKOkYESyes", tmp))
    283     {
    284           paranoid_free(tmp);
    285       return (TRUE);
    286     }
    287       else
    288     {
    289           paranoid_free(tmp);
    290       return (FALSE);
    291     }
    292     }
    293   else
    294     {
    295       paranoid_free(tmp);
    296       return (popup_with_buttons (prompt, " Okay ", "Cancel"));
    297     }
    298 }
     256    bool ask_me_OK_or_cancel(char *prompt) {
     257
     258        /*@ buffer *********************************************************** */
     259        char *tmp;
     260        int i;
     261
     262        tmp = malloc(MAX_NEWT_COMMENT_LEN);
     263        assert_string_is_neither_NULL_nor_zerolength(prompt);
     264        if (g_text_mode) {
     265            system("sync");
     266            printf
     267                ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ",
     268                 prompt);
     269            (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     270            if (tmp[strlen(tmp) - 1] == '\n')
     271                tmp[strlen(tmp) - 1] = '\0';
     272
     273            i = (int) strlen(tmp);
     274            if (i > 0 && tmp[i - 1] < 32) {
     275                tmp[i - 1] = '\0';
     276            }
     277            if (strstr("okOKOkYESyes", tmp)) {
     278                paranoid_free(tmp);
     279                return (TRUE);
     280            } else {
     281                paranoid_free(tmp);
     282                return (FALSE);
     283            }
     284        } else {
     285            paranoid_free(tmp);
     286            return (popup_with_buttons(prompt, " Okay ", "Cancel"));
     287        }
     288    }
    299289
    300290
     
    303293 * Close the currently opened evalcall form.
    304294 */
    305 void
    306 close_evalcall_form (void)
    307 {
    308   if (g_text_mode) {return;}
    309   if (g_isoform_main == NULL) {return; }
    310   update_evalcall_form (100);
    311   usleep (500000);
    312   if (g_text_mode)
    313     {
    314       log_msg (2, "Closing evalcall form");
    315       return;
    316     }
    317   newtPopHelpLine ();
    318   newtFormDestroy (g_isoform_main);
    319   newtPopWindow ();
    320   g_isoform_main = NULL;
    321   g_isoform_old_progress = -1;
    322 }
     295    void
     296     close_evalcall_form(void) {
     297        if (g_text_mode) {
     298            return;
     299        }
     300        if (g_isoform_main == NULL) {
     301            return;
     302        }
     303        update_evalcall_form(100);
     304        usleep(500000);
     305        if (g_text_mode) {
     306            log_msg(2, "Closing evalcall form");
     307            return;
     308        }
     309        newtPopHelpLine();
     310        newtFormDestroy(g_isoform_main);
     311        newtPopWindow();
     312        g_isoform_main = NULL;
     313        g_isoform_old_progress = -1;
     314    }
    323315
    324316
     
    326318 * Close the currently opened progress form.
    327319 */
    328 void
    329 close_progress_form ()
    330 {
    331   if (g_text_mode) {return;}
    332   if (g_current_progress == -999)
    333     {
    334       log_msg (2, "Trying to close the progress form when it ain't open!");
    335       return;
    336     }
    337   g_current_progress = g_maximum_progress;
    338   update_progress_form ("Complete");
    339   sleep (1);
    340   if (g_text_mode)
    341     {
    342       log_msg (2, "Closing progress form");
    343       return;
    344     }
    345   newtPopHelpLine ();
    346   newtFormDestroy (g_progressForm);
    347   newtPopWindow ();
    348   g_progressForm = NULL;
    349   g_current_progress = -999;
    350 }
     320    void
     321     close_progress_form() {
     322        if (g_text_mode) {
     323            return;
     324        }
     325        if (g_current_progress == -999) {
     326            log_msg(2,
     327                    "Trying to close the progress form when it ain't open!");
     328            return;
     329        }
     330        g_current_progress = g_maximum_progress;
     331        update_progress_form("Complete");
     332        sleep(1);
     333        if (g_text_mode) {
     334            log_msg(2, "Closing progress form");
     335            return;
     336        }
     337        newtPopHelpLine();
     338        newtFormDestroy(g_progressForm);
     339        newtPopWindow();
     340        g_progressForm = NULL;
     341        g_current_progress = -999;
     342    }
    351343
    352344
     
    358350 * @note This function never returns.
    359351 */
    360 void
    361 fatal_error (char *error_string)
    362 {
    363     /*@ buffers ******************************************************/
    364   char fatalstr[MAX_NEWT_COMMENT_LEN] = "-------FATAL ERROR---------";
    365   char *tmp;
    366   char *command;
    367   static bool already_exiting=FALSE;
    368   int i;
    369 
    370     /*@ end vars *****************************************************/
    371 
    372   malloc_string(command);
    373   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    374   set_signals(FALSE); // link to external func
    375   g_exiting = TRUE;
    376   log_msg(1, "Fatal error received - '%s'", error_string);
    377   printf("Fatal error... %s\n", error_string);
    378   if (getpid() == g_mastermind_pid)
    379     {
    380       log_msg(2, "mastermind %d is exiting", (int)getpid());
    381       kill(g_main_pid, SIGTERM);
    382       paranoid_free(tmp);
    383       finish(1);
    384     }
    385 
    386   if (getpid() != g_main_pid)
    387     {
    388       if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid)
    389     {
    390       log_msg(2, "non-m/m %d is exiting", (int)getpid());
    391       kill(g_main_pid, SIGTERM);
    392       paranoid_free(tmp);
    393       finish(1);
    394     }
    395     }
    396 
    397   log_msg (3, "OK, I think I'm the main PID.");
    398   if (already_exiting)
    399     {
    400       log_msg(3, "...I'm already exiting. Give me time, Julian!");
    401       paranoid_free(tmp);
    402       finish(1);
    403     }
    404 
    405   already_exiting = TRUE;
    406   log_msg(2, "I'm going to do some cleaning up now.");
    407   paranoid_system("killall mindi 2> /dev/null");
    408   kill_anything_like_this("/mondo/do-not");
    409   kill_anything_like_this("tmp.mondo");
    410   kill_anything_like_this("partimagehack");
    411   sync();
    412   sprintf(tmp, "umount %s", g_tmpfs_mountpt);
    413   chdir("/");
    414   for(i=0; i<10 && run_program_and_log_output(tmp, 5); i++)
    415     {
    416       log_msg(2, "Waiting for child processes to terminate");
    417       sleep(1);
    418       run_program_and_log_output(tmp, 5);
    419     }
    420 
    421   if (g_erase_tmpdir_and_scratchdir[0])
    422     { run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); }
    423 
    424   if (g_selfmounted_isodir) {
    425     sprintf(command, "umount %s", g_selfmounted_isodir);
    426     run_program_and_log_output(command, 5);
    427     sprintf(command, "rmdir %s", g_selfmounted_isodir);
    428     run_program_and_log_output(command, 5);
    429     }
    430 
    431   if (!g_text_mode)
    432     {
    433       log_msg (0, fatalstr);
    434       log_msg (0, error_string);
    435       //      popup_and_OK (error_string);
    436       newtFinished ();
    437     }
    438 
    439   printf ("---FATALERROR--- %s\n", error_string);
    440   system("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null");
    441   if (!strstr(g_version, "cvs") && !strstr(g_version, "svn"))
    442     {
    443       printf("Please try the snapshot (the version with 'cvs' and the date in its filename)");
    444       printf("to see if that fixes the problem. Please don't bother the mailing list with");
    445       printf("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes");
    446       printf("which might help you. Go to http://www.mondorescue.org/download/download.html");
    447       printf("For more information.\n");
    448       log_msg(0, "Please DON'T contact the mailing list. Try the SNAPSHOTS.");
    449     }
    450   else
    451     {
    452       printf("If you require technical support, please contact the mailing list.\n");
    453       printf("See http://www.mondorescue.org for details.\n");
    454       printf("The list's members can help you, if you attach that file to your e-mail.\n");
    455     }
    456   printf("Log file: %s\n", MONDO_LOGFILE);
    457   //  printf("VERSION=%s\n", g_version);
    458   if (does_file_exist("/tmp/MA.log.gz"))
    459     {
    460       printf("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n");
    461     }
    462   printf ("Mondo has aborted.\n");
    463   register_pid(0, "mondo"); // finish() does this too, FYI
    464   if (!g_main_pid) { log_msg(3, "FYI - g_main_pid is blank"); }
    465   paranoid_free(tmp);
    466   paranoid_free(command);
    467   finish (254);
    468 }
     352    void
     353     fatal_error(char *error_string) {
     354        /*@ buffers ***************************************************** */
     355        char fatalstr[MAX_NEWT_COMMENT_LEN] =
     356            "-------FATAL ERROR---------";
     357        char *tmp;
     358        char *command;
     359        static bool already_exiting = FALSE;
     360        int i;
     361
     362        /*@ end vars **************************************************** */
     363
     364        malloc_string(command);
     365        tmp = malloc(MAX_NEWT_COMMENT_LEN);
     366        set_signals(FALSE);     // link to external func
     367        g_exiting = TRUE;
     368        log_msg(1, "Fatal error received - '%s'", error_string);
     369        printf("Fatal error... %s\n", error_string);
     370        if (getpid() == g_mastermind_pid) {
     371            log_msg(2, "mastermind %d is exiting", (int) getpid());
     372            kill(g_main_pid, SIGTERM);
     373            paranoid_free(tmp);
     374            finish(1);
     375        }
     376
     377        if (getpid() != g_main_pid) {
     378            if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) {
     379                log_msg(2, "non-m/m %d is exiting", (int) getpid());
     380                kill(g_main_pid, SIGTERM);
     381                paranoid_free(tmp);
     382                finish(1);
     383            }
     384        }
     385
     386        log_msg(3, "OK, I think I'm the main PID.");
     387        if (already_exiting) {
     388            log_msg(3, "...I'm already exiting. Give me time, Julian!");
     389            paranoid_free(tmp);
     390            finish(1);
     391        }
     392
     393        already_exiting = TRUE;
     394        log_msg(2, "I'm going to do some cleaning up now.");
     395        paranoid_system("killall mindi 2> /dev/null");
     396        kill_anything_like_this("/mondo/do-not");
     397        kill_anything_like_this("tmp.mondo");
     398        kill_anything_like_this("partimagehack");
     399        sync();
     400        sprintf(tmp, "umount %s", g_tmpfs_mountpt);
     401        chdir("/");
     402        for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
     403            log_msg(2, "Waiting for child processes to terminate");
     404            sleep(1);
     405            run_program_and_log_output(tmp, 5);
     406        }
     407
     408        if (g_erase_tmpdir_and_scratchdir[0]) {
     409            run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5);
     410        }
     411
     412        if (g_selfmounted_isodir) {
     413            sprintf(command, "umount %s", g_selfmounted_isodir);
     414            run_program_and_log_output(command, 5);
     415            sprintf(command, "rmdir %s", g_selfmounted_isodir);
     416            run_program_and_log_output(command, 5);
     417        }
     418
     419        if (!g_text_mode) {
     420            log_msg(0, fatalstr);
     421            log_msg(0, error_string);
     422            //      popup_and_OK (error_string);
     423            newtFinished();
     424        }
     425
     426        printf("---FATALERROR--- %s\n", error_string);
     427        system
     428            ("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null");
     429        if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) {
     430            printf
     431                ("Please try the snapshot (the version with 'cvs' and the date in its filename)");
     432            printf
     433                ("to see if that fixes the problem. Please don't bother the mailing list with");
     434            printf
     435                ("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes");
     436            printf
     437                ("which might help you. Go to http://www.mondorescue.org/download/download.html");
     438            printf("For more information.\n");
     439            log_msg(0,
     440                    "Please DON'T contact the mailing list. Try the SNAPSHOTS.");
     441        } else {
     442            printf
     443                ("If you require technical support, please contact the mailing list.\n");
     444            printf("See http://www.mondorescue.org for details.\n");
     445            printf
     446                ("The list's members can help you, if you attach that file to your e-mail.\n");
     447        }
     448        printf("Log file: %s\n", MONDO_LOGFILE);
     449        //  printf("VERSION=%s\n", g_version);
     450        if (does_file_exist("/tmp/MA.log.gz")) {
     451            printf
     452                ("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n");
     453        }
     454        printf("Mondo has aborted.\n");
     455        register_pid(0, "mondo");   // finish() does this too, FYI
     456        if (!g_main_pid) {
     457            log_msg(3, "FYI - g_main_pid is blank");
     458        }
     459        paranoid_free(tmp);
     460        paranoid_free(command);
     461        finish(254);
     462    }
    469463
    470464
     
    476470 * @note This function never returns.
    477471 */
    478 void
    479 finish (int signal)
    480 {
     472    void
     473     finish(int signal) {
    481474        char *command;
    482475        malloc_string(command);
    483476
    484   /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
    485 
    486   /* newtPopHelpLine(); */
    487 
    488   register_pid(0, "mondo");
    489   chdir("/");
    490   run_program_and_log_output("umount "MNT_CDROM, FALSE);
    491   run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*", FALSE);
    492   if (g_erase_tmpdir_and_scratchdir)
    493     {
    494       run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1);
    495     }
    496   if (g_selfmounted_isodir) {
    497     sprintf(command, "umount %s", g_selfmounted_isodir);
    498     run_program_and_log_output(command, 1);
    499     sprintf(command, "rmdir %s", g_selfmounted_isodir);
    500     run_program_and_log_output(command, 1);
    501     }
    502    
     477        /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
     478
     479        /* newtPopHelpLine(); */
     480
     481        register_pid(0, "mondo");
     482        chdir("/");
     483        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     484        run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*",
     485                                   FALSE);
     486        if (g_erase_tmpdir_and_scratchdir) {
     487            run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1);
     488        }
     489        if (g_selfmounted_isodir) {
     490            sprintf(command, "umount %s", g_selfmounted_isodir);
     491            run_program_and_log_output(command, 1);
     492            sprintf(command, "rmdir %s", g_selfmounted_isodir);
     493            run_program_and_log_output(command, 1);
     494        }
    503495//  iamhere("foo");
    504   /* system("clear"); */
     496        /* system("clear"); */
    505497//  iamhere("About to call newtFinished");
    506   if (!g_text_mode)
    507     {
    508       if (does_file_exist("/THIS-IS-A-RAMDISK"))
    509         {
    510       log_msg(1, "Calling newtFinished()");
    511       newtFinished();
    512     }
    513       else
    514         {
    515       log_msg(1, "Calling newtSuspend()");
    516           newtSuspend();
    517     }
    518     }
     498        if (!g_text_mode) {
     499            if (does_file_exist("/THIS-IS-A-RAMDISK")) {
     500                log_msg(1, "Calling newtFinished()");
     501                newtFinished();
     502            } else {
     503                log_msg(1, "Calling newtSuspend()");
     504                newtSuspend();
     505            }
     506        }
    519507//  system("clear");
    520508//  iamhere("Finished calling newtFinished");
    521   printf( "Execution run ended; result=%d\n", signal);
    522   printf( "Type 'less %s' to see the output log\n", MONDO_LOGFILE);
    523   free_libmondo_global_strings();
    524   exit (signal);
    525 }
     509        printf("Execution run ended; result=%d\n", signal);
     510        printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);
     511        free_libmondo_global_strings();
     512        exit(signal);
     513    }
    526514
    527515
     
    535523 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
    536524 */
    537 void
    538 log_file_end_to_screen (char *filename, char *grep_for_me)
    539 {
    540 
    541     /*@ buffers ***********************************************************/
    542   char *command;
    543     char *tmp;
    544 
    545     /*@ pointers **********************************************************/
    546   FILE *fin;
    547 
    548     /*@ int ***************************************************************/
    549   int i = 0;
    550 
    551   malloc_string(command);
    552   malloc_string(tmp);
    553   assert_string_is_neither_NULL_nor_zerolength(filename);
    554   assert(grep_for_me!=NULL);
    555 
    556   if (!does_file_exist (filename))
    557     {
    558       paranoid_free(command);
    559       paranoid_free(tmp);
    560       return;
    561     }
    562   if (grep_for_me[0] != '\0')
    563     {
    564       sprintf (command, "grep '%s' %s | tail -n%d",           
    565                     grep_for_me, filename,
    566                     g_noof_log_lines);
    567     }
    568   else
    569     {
    570       sprintf (command, "cat %s | tail -n%d %s", g_noof_log_lines, filename);
    571     }
    572   fin = popen (command, "r");
    573   if (!fin)
    574     {
    575       log_OS_error(command);
    576     }
    577   else
    578     {
    579       for (i = 0; i < g_noof_log_lines; i++)
    580     {
    581       for (err_log_lines[i][0] = '\0';
    582            strlen (err_log_lines[i]) < 2 && !feof (fin);)
    583         {
    584           (void) fgets (err_log_lines[i], MAX_NEWT_COMMENT_LEN, fin);
    585           strip_spaces (err_log_lines[i]);
    586           if (!strncmp (err_log_lines[i], "root:", 5))
    587         {
    588           strcpy (tmp, err_log_lines[i] + 6);
    589           strcpy (err_log_lines[i], tmp);
    590         }
    591           if (feof (fin))
    592         {
    593           break;
    594         }
    595         }
    596     }
    597       paranoid_pclose (fin);
    598     }
    599   refresh_log_screen ();
    600   paranoid_free(command);
    601   paranoid_free(tmp);
    602 }
     525    void
     526     log_file_end_to_screen(char *filename, char *grep_for_me) {
     527
     528        /*@ buffers ********************************************************** */
     529        char *command;
     530        char *tmp;
     531
     532        /*@ pointers ********************************************************* */
     533        FILE *fin;
     534
     535        /*@ int ************************************************************** */
     536        int i = 0;
     537
     538        malloc_string(command);
     539        malloc_string(tmp);
     540        assert_string_is_neither_NULL_nor_zerolength(filename);
     541        assert(grep_for_me != NULL);
     542
     543        if (!does_file_exist(filename)) {
     544            paranoid_free(command);
     545            paranoid_free(tmp);
     546            return;
     547        }
     548        if (grep_for_me[0] != '\0') {
     549            sprintf(command, "grep '%s' %s | tail -n%d",
     550                    grep_for_me, filename, g_noof_log_lines);
     551        } else {
     552            sprintf(command, "cat %s | tail -n%d %s", g_noof_log_lines,
     553                    filename);
     554        }
     555        fin = popen(command, "r");
     556        if (!fin) {
     557            log_OS_error(command);
     558        } else {
     559            for (i = 0; i < g_noof_log_lines; i++) {
     560                for (err_log_lines[i][0] = '\0';
     561                     strlen(err_log_lines[i]) < 2 && !feof(fin);) {
     562                    (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN,
     563                                 fin);
     564                    strip_spaces(err_log_lines[i]);
     565                    if (!strncmp(err_log_lines[i], "root:", 5)) {
     566                        strcpy(tmp, err_log_lines[i] + 6);
     567                        strcpy(err_log_lines[i], tmp);
     568                    }
     569                    if (feof(fin)) {
     570                        break;
     571                    }
     572                }
     573            }
     574            paranoid_pclose(fin);
     575        }
     576        refresh_log_screen();
     577        paranoid_free(command);
     578        paranoid_free(tmp);
     579    }
    603580
    604581
     
    608585 * @note The message is also written to the logfile.
    609586 */
    610 void
    611 log_to_screen (const char *fmt, ...)
    612 {
    613 
    614     /*@ int ***************************************************************/
    615   int i = 0;
    616     int j = 0;
    617   va_list args;
    618 
    619     /*@ buffers ***********************************************************/
    620   char *output;
    621 
    622   malloc_string(output);
    623 
    624   va_start(args, fmt);
    625   vsprintf(output, fmt, args);
    626   log_msg(0, output);
    627   output[80] = '\0';
    628   va_end(args);
    629   i = (int) strlen (output);
    630   if (i>0 && output[i - 1] < 32)
    631     {
    632       output[i - 1] = '\0';
    633     }
    634 
    635   if (err_log_lines) {
    636     for (i = 1; i < g_noof_log_lines; i++)
    637       {
    638     strcpy (err_log_lines[i - 1],
    639         "                                                                                ");
    640     strcpy (err_log_lines[i - 1], err_log_lines[i]);
    641       }
    642   }
    643   while (strlen(output)>0 && output[strlen (output) - 1] < 32)
    644     {
    645       output[strlen (output) - 1] = '\0';
    646     }
    647   for (j = 0; j < (int) strlen (output); j++)
    648     {
    649       if (output[j] < 32)
    650     {
    651       output[j] = ' ';
    652     }
    653     }
    654   if (err_log_lines)
    655     strcpy (err_log_lines[g_noof_log_lines - 1], output);
    656   if (g_text_mode)
    657     {
    658       printf("%s\n", output);
    659     }
    660   else
    661     {
    662       refresh_log_screen ();
    663     }
    664   paranoid_free(output);
    665 }
     587    void
     588     log_to_screen(const char *fmt, ...) {
     589
     590        /*@ int ************************************************************** */
     591        int i = 0;
     592        int j = 0;
     593        va_list args;
     594
     595        /*@ buffers ********************************************************** */
     596        char *output;
     597
     598        malloc_string(output);
     599
     600        va_start(args, fmt);
     601        vsprintf(output, fmt, args);
     602        log_msg(0, output);
     603        output[80] = '\0';
     604        va_end(args);
     605        i = (int) strlen(output);
     606        if (i > 0 && output[i - 1] < 32) {
     607            output[i - 1] = '\0';
     608        }
     609
     610        if (err_log_lines) {
     611            for (i = 1; i < g_noof_log_lines; i++) {
     612                strcpy(err_log_lines[i - 1],
     613                       "                                                                                ");
     614                strcpy(err_log_lines[i - 1], err_log_lines[i]);
     615            }
     616        }
     617        while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
     618            output[strlen(output) - 1] = '\0';
     619        }
     620        for (j = 0; j < (int) strlen(output); j++) {
     621            if (output[j] < 32) {
     622                output[j] = ' ';
     623            }
     624        }
     625        if (err_log_lines)
     626            strcpy(err_log_lines[g_noof_log_lines - 1], output);
     627        if (g_text_mode) {
     628            printf("%s\n", output);
     629        } else {
     630            refresh_log_screen();
     631        }
     632        paranoid_free(output);
     633    }
    666634
    667635
     
    674642 * @param output The string to write.
    675643 */
    676 void
    677 mvaddstr_and_log_it (int y, int x, char *output)
    678 {
    679   assert_string_is_neither_NULL_nor_zerolength(output);
    680   log_msg (0, output);
    681   if (g_text_mode)
    682     {
    683       printf ("%s\n", output);
    684     }
    685   else
    686     {
    687       newtDrawRootText (x, y, output);
    688       newtRefresh ();
    689     }
    690 }
     644    void
     645     mvaddstr_and_log_it(int y, int x, char *output) {
     646        assert_string_is_neither_NULL_nor_zerolength(output);
     647        log_msg(0, output);
     648        if (g_text_mode) {
     649            printf("%s\n", output);
     650        } else {
     651            newtDrawRootText(x, y, output);
     652            newtRefresh();
     653        }
     654    }
    691655
    692656
     
    697661 * @param ttl The title to use for the evalcall form.
    698662 */
    699 void
    700 open_evalcall_form (char *ttl)
    701 {
    702 
    703     /*@ buffers **********************************************************/
    704   char *title;
    705   char *tmp;
    706 
    707     /*@ initialize *******************************************************/
    708   g_isoform_old_progress = -1;
    709   g_mysterious_dot_counter = 0;
    710   malloc_string(title);
    711   malloc_string(tmp);
    712 
    713   assert(ttl!=NULL);
    714   strcpy (title, ttl);
    715   strcpy (g_isoform_header_str, title);
     663    void
     664     open_evalcall_form(char *ttl) {
     665
     666        /*@ buffers ********************************************************* */
     667        char *title;
     668        char *tmp;
     669
     670        /*@ initialize ****************************************************** */
     671        g_isoform_old_progress = -1;
     672        g_mysterious_dot_counter = 0;
     673        malloc_string(title);
     674        malloc_string(tmp);
     675
     676        assert(ttl != NULL);
     677        strcpy(title, ttl);
     678        strcpy(g_isoform_header_str, title);
    716679//  center_string (title, 80);
    717   if (g_text_mode)
    718     {
    719       log_msg (0, title);
    720     }
    721   else
    722     {
    723       strcpy(tmp, title);
    724       center_string(tmp, 80);
    725       newtPushHelpLine (tmp);
    726     }
    727   center_string (g_isoform_header_str, 36);
    728   g_isoform_starttime = get_time ();
    729   if (g_text_mode)
    730     {
    731       log_msg (0, g_isoform_header_str);
    732     }
    733   else
    734     {
    735       g_isoform_header = newtLabel (1, 1, g_isoform_header_str);
    736       g_isoform_scale = newtScale (3, 3, 34, 100);
    737       //      newtOpenWindow (20, 6, 40, 7, title);      // "Please Wait");
    738       newtCenteredWindow (40, 7, title);
    739       g_isoform_main = newtForm (NULL, NULL, 0);
    740       g_isoform_timeline = newtLabel (1, 5, "This is the timeline");
    741       g_isoform_pcline = newtLabel (1, 6, "This is the pcline");
    742       newtFormAddComponents (g_isoform_main, g_isoform_timeline,
    743                  g_isoform_pcline, g_isoform_header,
    744                  g_isoform_scale, NULL);
    745       newtRefresh ();
    746     }
    747   update_evalcall_form (0);
    748   paranoid_free(tmp);
    749   paranoid_free(title);
    750 }
     680        if (g_text_mode) {
     681            log_msg(0, title);
     682        } else {
     683            strcpy(tmp, title);
     684            center_string(tmp, 80);
     685            newtPushHelpLine(tmp);
     686        }
     687        center_string(g_isoform_header_str, 36);
     688        g_isoform_starttime = get_time();
     689        if (g_text_mode) {
     690            log_msg(0, g_isoform_header_str);
     691        } else {
     692            g_isoform_header = newtLabel(1, 1, g_isoform_header_str);
     693            g_isoform_scale = newtScale(3, 3, 34, 100);
     694            //      newtOpenWindow (20, 6, 40, 7, title);      // "Please Wait");
     695            newtCenteredWindow(40, 7, title);
     696            g_isoform_main = newtForm(NULL, NULL, 0);
     697            g_isoform_timeline = newtLabel(1, 5, "This is the timeline");
     698            g_isoform_pcline = newtLabel(1, 6, "This is the pcline");
     699            newtFormAddComponents(g_isoform_main, g_isoform_timeline,
     700                                  g_isoform_pcline, g_isoform_header,
     701                                  g_isoform_scale, NULL);
     702            newtRefresh();
     703        }
     704        update_evalcall_form(0);
     705        paranoid_free(tmp);
     706        paranoid_free(title);
     707    }
    751708
    752709
     
    761718 * @param max_val The maximum amount of progress (number of filesets, etc.)
    762719 */
    763 void
    764 open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val)
    765 {
    766 
    767     /*@ buffers **********************************************************/
    768   char *b1c;
    769     char *blurb1;
    770     char *blurb2;
    771     char *blurb3;
    772 
    773     /*@ initialize *******************************************************/
    774   g_mysterious_dot_counter = 0;
    775 
    776   malloc_string(b1c);
    777   malloc_string(blurb1);
    778   malloc_string(blurb2);
    779   malloc_string(blurb3);
    780  
    781   assert(title!=NULL);
    782   assert(b1!=NULL);
    783   assert(b2!=NULL);
    784   assert(b3!=NULL);
    785 
    786   strcpy (blurb1, b1);
    787   strcpy (blurb2, b2);
    788   strcpy (blurb3, b3);
    789   strcpy (b1c, b1);
    790   center_string (b1c, 80);
    791   if (max_val <= 0)
    792     {
    793       max_val = 1;
    794     }
    795 
    796   g_start_time = get_time ();
    797   g_maximum_progress = max_val;
    798   g_current_progress = 0;
    799   strcpy (g_blurb_str_1, blurb1);
    800   strcpy (g_blurb_str_2, blurb3);
    801   strcpy (g_blurb_str_3, blurb2);
    802   if (g_text_mode)
    803     {
    804       log_msg (0, blurb1);
    805       log_msg (0, blurb2);
    806       log_msg (0, blurb3);
    807     }
    808   else
    809     {
    810       g_blurb1 = newtLabel (2, 1, blurb1);
    811       g_blurb2 = newtLabel (2, 2, blurb3);
    812       g_blurb3 = newtLabel (2, 4, blurb2);
    813       //      newtOpenWindow (10, 4, 60, 11, title);
    814       newtCenteredWindow (60, 11, title);
    815       g_scale = newtScale (3, 6, 54, g_maximum_progress);
    816       g_progressForm = newtForm (NULL, NULL, 0);
    817       g_percentline = newtLabel (10, 9, "This is the percentline");
    818       g_timeline = newtLabel (10, 8, "This is the timeline");
    819       newtFormAddComponents (g_progressForm, g_percentline, g_timeline,
    820                  g_scale, g_blurb1, g_blurb3, g_blurb2, NULL);
    821       newtPushHelpLine (b1c);
    822       newtRefresh ();
    823     }
    824   update_progress_form_full (blurb1, blurb2, blurb3);
    825   paranoid_free(b1c);
    826   paranoid_free(blurb1);
    827   paranoid_free(blurb2);
    828   paranoid_free(blurb3);
    829 }
     720    void
     721     open_progress_form(char *title, char *b1, char *b2, char *b3,
     722                        long max_val) {
     723
     724        /*@ buffers ********************************************************* */
     725        char *b1c;
     726        char *blurb1;
     727        char *blurb2;
     728        char *blurb3;
     729
     730        /*@ initialize ****************************************************** */
     731        g_mysterious_dot_counter = 0;
     732
     733        malloc_string(b1c);
     734        malloc_string(blurb1);
     735        malloc_string(blurb2);
     736        malloc_string(blurb3);
     737
     738        assert(title != NULL);
     739        assert(b1 != NULL);
     740        assert(b2 != NULL);
     741        assert(b3 != NULL);
     742
     743        strcpy(blurb1, b1);
     744        strcpy(blurb2, b2);
     745        strcpy(blurb3, b3);
     746        strcpy(b1c, b1);
     747        center_string(b1c, 80);
     748        if (max_val <= 0) {
     749            max_val = 1;
     750        }
     751
     752        g_start_time = get_time();
     753        g_maximum_progress = max_val;
     754        g_current_progress = 0;
     755        strcpy(g_blurb_str_1, blurb1);
     756        strcpy(g_blurb_str_2, blurb3);
     757        strcpy(g_blurb_str_3, blurb2);
     758        if (g_text_mode) {
     759            log_msg(0, blurb1);
     760            log_msg(0, blurb2);
     761            log_msg(0, blurb3);
     762        } else {
     763            g_blurb1 = newtLabel(2, 1, blurb1);
     764            g_blurb2 = newtLabel(2, 2, blurb3);
     765            g_blurb3 = newtLabel(2, 4, blurb2);
     766            //      newtOpenWindow (10, 4, 60, 11, title);
     767            newtCenteredWindow(60, 11, title);
     768            g_scale = newtScale(3, 6, 54, g_maximum_progress);
     769            g_progressForm = newtForm(NULL, NULL, 0);
     770            g_percentline = newtLabel(10, 9, "This is the percentline");
     771            g_timeline = newtLabel(10, 8, "This is the timeline");
     772            newtFormAddComponents(g_progressForm, g_percentline,
     773                                  g_timeline, g_scale, g_blurb1, g_blurb3,
     774                                  g_blurb2, NULL);
     775            newtPushHelpLine(b1c);
     776            newtRefresh();
     777        }
     778        update_progress_form_full(blurb1, blurb2, blurb3);
     779        paranoid_free(b1c);
     780        paranoid_free(blurb1);
     781        paranoid_free(blurb2);
     782        paranoid_free(blurb3);
     783    }
    830784
    831785/**
     
    833787 * @param prompt The message.
    834788 */
    835 void
    836 popup_and_OK (char *prompt)
    837 {
    838     char ch;
    839 
    840   assert_string_is_neither_NULL_nor_zerolength(prompt);
    841 
    842   log_msg (0, prompt);
    843   if (g_text_mode)
    844     {
    845       printf
    846     ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ", prompt);
    847       while (((ch = getchar()) != '\n') && (ch != EOF))
    848       ;
    849     }
    850   else
    851     {
    852     (void) popup_with_buttons (prompt, " OK ", "");
    853     }
    854 }
     789    void
     790     popup_and_OK(char *prompt) {
     791        char ch;
     792
     793        assert_string_is_neither_NULL_nor_zerolength(prompt);
     794
     795        log_msg(0, prompt);
     796        if (g_text_mode) {
     797            printf
     798                ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ",
     799                 prompt);
     800            while (((ch = getchar()) != '\n') && (ch != EOF));
     801        } else {
     802            (void) popup_with_buttons(prompt, " OK ", "");
     803        }
     804    }
    855805
    856806/**
     
    862812 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
    863813 */
    864 bool
    865 popup_and_get_string (char *title, char *b, char *output, int maxsize)
    866 {
    867 
    868     /*@ newt *************************************************************/
    869   newtComponent myForm;
    870     newtComponent b_1;
    871     newtComponent b_2;
    872     newtComponent b_res;
    873     newtComponent text;
    874     newtComponent type_here;
    875 
    876     /*@ pointers **********************************************************/
    877   char *entry_value;
    878 
    879     /*@ buffers ***********************************************************/
    880     char *blurb;
    881     char *original_contents;
    882 
    883   blurb = malloc(MAX_NEWT_COMMENT_LEN);
    884   original_contents = malloc(MAX_NEWT_COMMENT_LEN);
    885   assert_string_is_neither_NULL_nor_zerolength(title);
    886   assert(b!=NULL);
    887   assert(output!=NULL);
    888 
    889   if (g_text_mode)
    890     {
    891       printf ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ", title, b);
    892       (void) fgets(output, maxsize, stdin);
    893       if (output[strlen (output) - 1] == '\n')
    894       output[strlen (output) - 1] = '\0';
    895       paranoid_free(blurb);
    896       paranoid_free(original_contents);
    897       return (TRUE);
    898     }
    899   strcpy (blurb, b);
    900   text = newtTextboxReflowed (2, 1, blurb, 48, 5, 5, 0);
    901   strcpy (original_contents, output);
    902   output[0] = '\0';
    903   type_here =
    904     newtEntry (2, newtTextboxGetNumLines (text) + 2, original_contents, 50,
     814    bool popup_and_get_string(char *title, char *b, char *output,
     815                              int maxsize) {
     816
     817        /*@ newt ************************************************************ */
     818        newtComponent myForm;
     819        newtComponent b_1;
     820        newtComponent b_2;
     821        newtComponent b_res;
     822        newtComponent text;
     823        newtComponent type_here;
     824
     825        /*@ pointers ********************************************************* */
     826        char *entry_value;
     827
     828        /*@ buffers ********************************************************** */
     829        char *blurb;
     830        char *original_contents;
     831
     832        blurb = malloc(MAX_NEWT_COMMENT_LEN);
     833        original_contents = malloc(MAX_NEWT_COMMENT_LEN);
     834        assert_string_is_neither_NULL_nor_zerolength(title);
     835        assert(b != NULL);
     836        assert(output != NULL);
     837
     838        if (g_text_mode) {
     839            printf
     840                ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
     841                 title, b);
     842            (void) fgets(output, maxsize, stdin);
     843            if (output[strlen(output) - 1] == '\n')
     844                output[strlen(output) - 1] = '\0';
     845            paranoid_free(blurb);
     846            paranoid_free(original_contents);
     847            return (TRUE);
     848        }
     849        strcpy(blurb, b);
     850        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
     851        strcpy(original_contents, output);
     852        output[0] = '\0';
     853        type_here =
     854            newtEntry(2, newtTextboxGetNumLines(text) + 2,
     855                      original_contents, 50,
    905856#ifdef __cplusplus
    906            0, NEWT_FLAG_RETURNEXIT
     857                      0, NEWT_FLAG_RETURNEXIT
    907858#else
    908            (void*)&entry_value, NEWT_FLAG_RETURNEXIT
     859                      (void *) &entry_value, NEWT_FLAG_RETURNEXIT
    909860#endif
    910            );
    911   b_1 = newtButton (6, newtTextboxGetNumLines (text) + 4, "  OK  ");
    912   b_2 = newtButton (18, newtTextboxGetNumLines (text) + 4, "Cancel");
    913   //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
    914   newtCenteredWindow (54, newtTextboxGetNumLines (text) + 9, title);
    915   myForm = newtForm (NULL, NULL, 0);
    916   newtFormAddComponents (myForm, text, type_here, b_1, b_2, NULL);
    917   center_string (blurb, 80);
    918   newtPushHelpLine (blurb);
    919   b_res = newtRunForm (myForm);
    920   strcpy (output, entry_value);
    921   newtPopHelpLine ();
    922   newtFormDestroy (myForm);
    923   newtPopWindow ();
    924   if (b_res == b_2)
    925     {
    926       strcpy (output, original_contents);
    927       paranoid_free(blurb);
    928       paranoid_free(original_contents);
    929       return (FALSE);
    930     }
    931   else
    932     {
    933       paranoid_free(blurb);
    934       paranoid_free(original_contents);
    935       return (TRUE);
    936     }
    937 }
     861            );
     862        b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, "  OK  ");
     863        b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
     864        //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
     865        newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
     866        myForm = newtForm(NULL, NULL, 0);
     867        newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
     868        center_string(blurb, 80);
     869        newtPushHelpLine(blurb);
     870        b_res = newtRunForm(myForm);
     871        strcpy(output, entry_value);
     872        newtPopHelpLine();
     873        newtFormDestroy(myForm);
     874        newtPopWindow();
     875        if (b_res == b_2) {
     876            strcpy(output, original_contents);
     877            paranoid_free(blurb);
     878            paranoid_free(original_contents);
     879            return (FALSE);
     880        } else {
     881            paranoid_free(blurb);
     882            paranoid_free(original_contents);
     883            return (TRUE);
     884        }
     885    }
    938886
    939887
     
    945893 * @return TRUE if @p button1 was pushed, FALSE otherwise.
    946894 */
    947 bool
    948 popup_with_buttons (char *p, char *button1, char *button2)
    949 {
    950 
    951     /*@ buffers ************************************************************/
    952   char *prompt, *tmp;
    953 
    954     /*@ newt ***************************************************************/
    955   newtComponent myForm;
    956     newtComponent b_1;
    957     newtComponent b_2;
    958     newtComponent b_res;
    959     newtComponent text;
    960  
    961   prompt = malloc(MAX_NEWT_COMMENT_LEN);
    962   tmp = malloc(MAX_NEWT_COMMENT_LEN);
    963   assert_string_is_neither_NULL_nor_zerolength(p);
    964   assert(button1!=NULL);
    965   assert(button2!=NULL);
    966   if (g_text_mode)
    967     {
    968       if (strlen(button2)==0)
    969         { printf("%s (%s) --> ", p, button1); }
    970       else
    971         { printf("%s (%s or %s) --> ", p, button1, button2); }
    972       for(tmp[0]='\0'; strcmp(tmp, button1) && (strlen(button2)==0 || strcmp(tmp, button2)); )
    973         {
    974           printf("--> ");
    975           (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    976         }
    977       if (!strcmp(tmp, button1)) { paranoid_free(tmp); paranoid_free(prompt); return(TRUE); }
    978       else { paranoid_free(tmp); paranoid_free(prompt); return(FALSE); }
    979     }
    980 
    981   strcpy (prompt, p);
    982   text = newtTextboxReflowed (1, 1, prompt, 40, 5, 5, 0);
    983   b_1 =
    984     newtButton (20 -
    985         ((button2[0] !=
    986           '\0') ? strlen (button1) + 2 : strlen (button1) / 2),
    987         newtTextboxGetNumLines (text) + 3, button1);
    988   if (button2[0] != '\0')
    989     {
    990       b_2 = newtButton (24, newtTextboxGetNumLines (text) + 3, button2);
    991     }
    992   else
    993     {
    994       b_2 = NULL;
    995     }
    996   //  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
    997   newtCenteredWindow (46, newtTextboxGetNumLines (text) + 7, "Alert");
    998   myForm = newtForm (NULL, NULL, 0);
    999   newtFormAddComponents (myForm, text, b_1, b_2, NULL);
    1000   center_string (prompt, 80);
    1001   newtPushHelpLine (prompt);
    1002   b_res = newtRunForm (myForm);
    1003   newtPopHelpLine ();
    1004   newtFormDestroy (myForm);
    1005   newtPopWindow ();
    1006   if (b_res == b_1)
    1007     {
    1008 paranoid_free(tmp); paranoid_free(prompt);       return (TRUE);
    1009     }
    1010   else
    1011     {
    1012 paranoid_free(tmp); paranoid_free(prompt);       return (FALSE);
    1013     }
    1014 }
     895    bool popup_with_buttons(char *p, char *button1, char *button2) {
     896
     897        /*@ buffers *********************************************************** */
     898        char *prompt, *tmp;
     899
     900        /*@ newt ************************************************************** */
     901        newtComponent myForm;
     902        newtComponent b_1;
     903        newtComponent b_2;
     904        newtComponent b_res;
     905        newtComponent text;
     906
     907        prompt = malloc(MAX_NEWT_COMMENT_LEN);
     908        tmp = malloc(MAX_NEWT_COMMENT_LEN);
     909        assert_string_is_neither_NULL_nor_zerolength(p);
     910        assert(button1 != NULL);
     911        assert(button2 != NULL);
     912        if (g_text_mode) {
     913            if (strlen(button2) == 0) {
     914                printf("%s (%s) --> ", p, button1);
     915            } else {
     916                printf("%s (%s or %s) --> ", p, button1, button2);
     917            }
     918            for (tmp[0] = '\0';
     919                 strcmp(tmp, button1) && (strlen(button2) == 0
     920                                          || strcmp(tmp, button2));) {
     921                printf("--> ");
     922                (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     923            }
     924            if (!strcmp(tmp, button1)) {
     925                paranoid_free(tmp);
     926                paranoid_free(prompt);
     927                return (TRUE);
     928            } else {
     929                paranoid_free(tmp);
     930                paranoid_free(prompt);
     931                return (FALSE);
     932            }
     933        }
     934
     935        strcpy(prompt, p);
     936        text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
     937        b_1 =
     938            newtButton(20 -
     939                       ((button2[0] !=
     940                         '\0') ? strlen(button1) +
     941                        2 : strlen(button1) / 2),
     942                       newtTextboxGetNumLines(text) + 3, button1);
     943        if (button2[0] != '\0') {
     944            b_2 =
     945                newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
     946        } else {
     947            b_2 = NULL;
     948        }
     949        //  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
     950        newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert");
     951        myForm = newtForm(NULL, NULL, 0);
     952        newtFormAddComponents(myForm, text, b_1, b_2, NULL);
     953        center_string(prompt, 80);
     954        newtPushHelpLine(prompt);
     955        b_res = newtRunForm(myForm);
     956        newtPopHelpLine();
     957        newtFormDestroy(myForm);
     958        newtPopWindow();
     959        if (b_res == b_1) {
     960            paranoid_free(tmp);
     961            paranoid_free(prompt);
     962            return (TRUE);
     963        } else {
     964            paranoid_free(tmp);
     965            paranoid_free(prompt);
     966            return (FALSE);
     967        }
     968    }
    1015969
    1016970
     
    1021975 * on the screen.
    1022976 */
    1023 void
    1024 refresh_log_screen ()
    1025 {
    1026 
    1027     /*@ int ************************************************************/
    1028   int i = 0;
    1029 
    1030 
    1031   if (g_text_mode || !err_log_lines)
    1032     {
    1033       return;
    1034     }
    1035   for (i = g_noof_log_lines - 1; i >= 0; i--)
    1036     {
    1037       newtDrawRootText (0, i + g_noof_rows - 1 - g_noof_log_lines,
    1038 "                                                                                ");
    1039     }
    1040   newtRefresh ();
    1041   for (i = g_noof_log_lines - 1; i >= 0; i--)
    1042     {
    1043       err_log_lines[i][79] = '\0';
    1044       newtDrawRootText (0, i + g_noof_rows - 1 - g_noof_log_lines, err_log_lines[i]);
    1045     }
    1046   newtRefresh ();
    1047 }
     977    void
     978     refresh_log_screen() {
     979
     980        /*@ int *********************************************************** */
     981        int i = 0;
     982
     983
     984        if (g_text_mode || !err_log_lines) {
     985            return;
     986        }
     987        for (i = g_noof_log_lines - 1; i >= 0; i--) {
     988            newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
     989                             "                                                                                ");
     990        }
     991        newtRefresh();
     992        for (i = g_noof_log_lines - 1; i >= 0; i--) {
     993            err_log_lines[i][79] = '\0';
     994            newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
     995                             err_log_lines[i]);
     996        }
     997        newtRefresh();
     998    }
    1048999
    10491000
     
    10521003 * only allocate some memory.
    10531004 */
    1054 void
    1055 setup_newt_stuff ()
    1056 {
    1057 
    1058     /*@ int ************************************************************/
    1059   int i = 0;
    1060   int cols;
    1061 
    1062   if (!g_text_mode)
    1063     {
    1064       newtInit();
    1065       newtCls();
    1066       newtPushHelpLine
    1067     ("Welcome to Mondo Rescue, by Hugo Rabson and the Internet. All rights reversed.");
    1068       /*  newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
    1069       newtDrawRootText (18, 0, WELCOME_STRING);
    1070       newtRefresh();
    1071       newtGetScreenSize (&cols, &g_noof_rows);
    1072       g_noof_log_lines = (g_noof_rows / 5) + 1;
    1073     }
    1074 
    1075   err_log_lines = (char **) malloc (sizeof (char *) * g_noof_log_lines);
    1076   if (!err_log_lines) {
    1077     fatal_error ("Out of memory");
    1078   }
    1079 
    1080   for (i = 0; i < g_noof_log_lines; i++) {
    1081     err_log_lines[i] = (char *) malloc (MAX_NEWT_COMMENT_LEN);
    1082     if (!err_log_lines[i]) {
    1083       fatal_error ("Out of memory");
    1084     }
    1085   }
    1086 
    1087   for (i = 0; i < g_noof_log_lines; i++)
    1088     {
    1089       err_log_lines[i][0] = '\0';
    1090     }
    1091 }
     1005    void
     1006     setup_newt_stuff() {
     1007
     1008        /*@ int *********************************************************** */
     1009        int i = 0;
     1010        int cols;
     1011
     1012        if (!g_text_mode) {
     1013            newtInit();
     1014            newtCls();
     1015            newtPushHelpLine
     1016                ("Welcome to Mondo Rescue, by Hugo Rabson and the Internet. All rights reversed.");
     1017            /*  newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
     1018            newtDrawRootText(18, 0, WELCOME_STRING);
     1019            newtRefresh();
     1020            newtGetScreenSize(&cols, &g_noof_rows);
     1021            g_noof_log_lines = (g_noof_rows / 5) + 1;
     1022        }
     1023
     1024        err_log_lines =
     1025            (char **) malloc(sizeof(char *) * g_noof_log_lines);
     1026        if (!err_log_lines) {
     1027            fatal_error("Out of memory");
     1028        }
     1029
     1030        for (i = 0; i < g_noof_log_lines; i++) {
     1031            err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN);
     1032            if (!err_log_lines[i]) {
     1033                fatal_error("Out of memory");
     1034            }
     1035        }
     1036
     1037        for (i = 0; i < g_noof_log_lines; i++) {
     1038            err_log_lines[i][0] = '\0';
     1039        }
     1040    }
    10921041
    10931042
     
    10971046 * @param denom The denomenator of the ratio.
    10981047 */
    1099 void
    1100 update_evalcall_form_ratio (int num, int denom)
    1101 {
    1102 
    1103     /*@ long *************************************************************/
    1104   long current_time = 0;
    1105     long time_taken = 0;
    1106     long time_total_est = 0;
    1107     long time_remaining = 0;
    1108 
    1109     /*@ buffers ***********************************************************/
    1110   char *timeline_str;
    1111     char *pcline_str;
    1112     char *taskprogress;
    1113 
    1114     /*@ int ***************************************************************/
    1115   int percentage = 0;
    1116     int i = 0;
    1117     int j = 0;
    1118 
    1119   malloc_string(timeline_str);
    1120   malloc_string(pcline_str);
    1121   malloc_string(taskprogress);
    1122   timeline_str[0] = '\0';
     1048    void
     1049     update_evalcall_form_ratio(int num, int denom) {
     1050
     1051        /*@ long ************************************************************ */
     1052        long current_time = 0;
     1053        long time_taken = 0;
     1054        long time_total_est = 0;
     1055        long time_remaining = 0;
     1056
     1057        /*@ buffers ********************************************************** */
     1058        char *timeline_str;
     1059        char *pcline_str;
     1060        char *taskprogress;
     1061
     1062        /*@ int ************************************************************** */
     1063        int percentage = 0;
     1064        int i = 0;
     1065        int j = 0;
     1066
     1067        malloc_string(timeline_str);
     1068        malloc_string(pcline_str);
     1069        malloc_string(taskprogress);
     1070        timeline_str[0] = '\0';
    11231071//  log_it("update_eval_call_form called");
    1124   if (num * 100 < denom)
    1125     {
    1126       percentage = 1;
    1127     }
    1128   else
    1129     {
    1130       percentage = (num * 100 + denom / 2) / denom ;
    1131     }
    1132    
    1133   current_time = get_time ();
    1134   time_taken = current_time - g_isoform_starttime;
    1135   if (num)
    1136     {
    1137       time_total_est = time_taken * denom / num;
    1138       time_remaining = time_total_est - time_taken;
    1139     }
    1140   else
    1141     {
    1142       time_remaining = 0;
    1143     }
    1144   if (!g_text_mode)
    1145     {
    1146       newtLabelSetText (g_isoform_header, g_isoform_header_str);
    1147     }
    1148   g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1149   if ((percentage < 3 && g_isoform_old_progress < 3)
    1150       || percentage > g_isoform_old_progress)
    1151     {
    1152       g_isoform_old_progress = percentage;
    1153       sprintf (timeline_str,
    1154            "%2ld:%02ld taken            %2ld:%02ld remaining",
    1155            time_taken / 60, time_taken % 60, time_remaining / 60,
    1156            time_remaining % 60);
    1157       if (percentage < 3)
    1158     {
    1159       sprintf (pcline_str, " Working");
    1160       for (j = 0; j < g_mysterious_dot_counter; j++)
    1161         {
    1162           strcat (pcline_str, ".");
    1163         }
    1164       for (; j < 27; j++)
    1165         {
    1166           strcat (pcline_str, " ");
    1167         }
    1168       sprintf (pcline_str + strlen (pcline_str), " %c",
    1169            special_dot_char (g_mysterious_dot_counter));
    1170     }
    1171       else
    1172     {
    1173       sprintf (pcline_str, " %3d%% done              %3d%% to go",
    1174            percentage, 100 - percentage);
    1175     }
    1176       if (g_text_mode)
    1177     {
    1178       sprintf (taskprogress, "TASK:  [");
    1179       for (i = 0; i < percentage; i += 5)
    1180         {
    1181           strcat (taskprogress, "*");
    1182         }
    1183       for (; i < 100; i += 5)
    1184         {
    1185           strcat (taskprogress, ".");
    1186         }
    1187       if (percentage >= 3)
    1188         {
    1189           sprintf (taskprogress + strlen (taskprogress),
    1190                "] %3d%% done; %2ld:%02ld to go", percentage,
    1191                time_remaining / 60, time_remaining % 60);
    1192               printf ("---evalcall---1--- %s\r\n", g_isoform_header_str);
    1193           printf ("---evalcall---2--- %s\r\n", taskprogress);
    1194               printf ("---evalcall---E---\r\n");
    1195         }
    1196     }
    1197       else
    1198     {
    1199       newtScaleSet (g_isoform_scale, (unsigned long long) percentage);
    1200       newtLabelSetText (g_isoform_pcline, pcline_str);
    1201       if (percentage >= 3)
    1202         {
    1203           newtLabelSetText (g_isoform_timeline, timeline_str);
    1204         }
    1205     }
    1206     }
    1207   if (!g_text_mode)
    1208     {
     1072        if (num * 100 < denom) {
     1073            percentage = 1;
     1074        } else {
     1075            percentage = (num * 100 + denom / 2) / denom;
     1076        }
     1077
     1078        current_time = get_time();
     1079        time_taken = current_time - g_isoform_starttime;
     1080        if (num) {
     1081            time_total_est = time_taken * denom / num;
     1082            time_remaining = time_total_est - time_taken;
     1083        } else {
     1084            time_remaining = 0;
     1085        }
     1086        if (!g_text_mode) {
     1087            newtLabelSetText(g_isoform_header, g_isoform_header_str);
     1088        }
     1089        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
     1090        if ((percentage < 3 && g_isoform_old_progress < 3)
     1091            || percentage > g_isoform_old_progress) {
     1092            g_isoform_old_progress = percentage;
     1093            sprintf(timeline_str,
     1094                    "%2ld:%02ld taken            %2ld:%02ld remaining",
     1095                    time_taken / 60, time_taken % 60, time_remaining / 60,
     1096                    time_remaining % 60);
     1097            if (percentage < 3) {
     1098                sprintf(pcline_str, " Working");
     1099                for (j = 0; j < g_mysterious_dot_counter; j++) {
     1100                    strcat(pcline_str, ".");
     1101                }
     1102                for (; j < 27; j++) {
     1103                    strcat(pcline_str, " ");
     1104                }
     1105                sprintf(pcline_str + strlen(pcline_str), " %c",
     1106                        special_dot_char(g_mysterious_dot_counter));
     1107            } else {
     1108                sprintf(pcline_str, " %3d%% done              %3d%% to go",
     1109                        percentage, 100 - percentage);
     1110            }
     1111            if (g_text_mode) {
     1112                sprintf(taskprogress, "TASK:  [");
     1113                for (i = 0; i < percentage; i += 5) {
     1114                    strcat(taskprogress, "*");
     1115                }
     1116                for (; i < 100; i += 5) {
     1117                    strcat(taskprogress, ".");
     1118                }
     1119                if (percentage >= 3) {
     1120                    sprintf(taskprogress + strlen(taskprogress),
     1121                            "] %3d%% done; %2ld:%02ld to go", percentage,
     1122                            time_remaining / 60, time_remaining % 60);
     1123                    printf("---evalcall---1--- %s\r\n",
     1124                           g_isoform_header_str);
     1125                    printf("---evalcall---2--- %s\r\n", taskprogress);
     1126                    printf("---evalcall---E---\r\n");
     1127                }
     1128            } else {
     1129                newtScaleSet(g_isoform_scale,
     1130                             (unsigned long long) percentage);
     1131                newtLabelSetText(g_isoform_pcline, pcline_str);
     1132                if (percentage >= 3) {
     1133                    newtLabelSetText(g_isoform_timeline, timeline_str);
     1134                }
     1135            }
     1136        }
     1137        if (!g_text_mode) {
    12091138//      log_it("refreshing");
    1210       newtRefresh ();
    1211     }
    1212   paranoid_free(timeline_str);
    1213   paranoid_free(pcline_str);
    1214   paranoid_free(taskprogress);
    1215 }
     1139            newtRefresh();
     1140        }
     1141        paranoid_free(timeline_str);
     1142        paranoid_free(pcline_str);
     1143        paranoid_free(taskprogress);
     1144    }
    12161145
    12171146
     
    12211150 * @param curr The current amount of progress (percentage) in the evalcall form.
    12221151 */
    1223 void
    1224 update_evalcall_form (int curr)
    1225 {
    1226   update_evalcall_form_ratio (curr, 100);
    1227 }
     1152    void
     1153     update_evalcall_form(int curr) {
     1154        update_evalcall_form_ratio(curr, 100);
     1155    }
    12281156
    12291157
     
    12341162 * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same.
    12351163 */
    1236 void
    1237 update_progress_form (char *blurb3)
    1238 {
    1239   /*  log_it("update_progress_form --- called"); */
    1240   if (g_current_progress == -999)
    1241     {
    1242       /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */
    1243       return;
    1244     }
    1245   strcpy (g_blurb_str_2, blurb3);
    1246   update_progress_form_full (g_blurb_str_1, g_blurb_str_2, g_blurb_str_3);
    1247 }
     1164    void
     1165     update_progress_form(char *blurb3) {
     1166        /*  log_it("update_progress_form --- called"); */
     1167        if (g_current_progress == -999) {
     1168            /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */
     1169            return;
     1170        }
     1171        strcpy(g_blurb_str_2, blurb3);
     1172        update_progress_form_full(g_blurb_str_1, g_blurb_str_2,
     1173                                  g_blurb_str_3);
     1174    }
    12481175
    12491176
     
    12541181 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same.
    12551182 */
    1256 void
    1257 update_progress_form_full (char *blurb1, char *blurb2, char *blurb3)
    1258 {
    1259     /*@ long ******************************************************/
    1260   long current_time = 0;
    1261     long time_taken = 0;
    1262     long time_remaining = 0;
    1263     long time_total_est = 0;
    1264 
    1265     /*@ int ********************************************************/
    1266   int percentage = 0;
    1267     int i = 0;
    1268 
    1269     /*@ buffers ****************************************************/
    1270   char *percentline_str;
    1271     char *timeline_str;
    1272     char *taskprogress;
    1273     char *tmp;
     1183    void
     1184     update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) {
     1185        /*@ long ***************************************************** */
     1186        long current_time = 0;
     1187        long time_taken = 0;
     1188        long time_remaining = 0;
     1189        long time_total_est = 0;
     1190
     1191        /*@ int ******************************************************* */
     1192        int percentage = 0;
     1193        int i = 0;
     1194
     1195        /*@ buffers *************************************************** */
     1196        char *percentline_str;
     1197        char *timeline_str;
     1198        char *taskprogress;
     1199        char *tmp;
    12741200
    12751201//  log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3);
    1276   percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1277   timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1278   taskprogress = malloc(MAX_NEWT_COMMENT_LEN);
    1279   malloc_string(tmp);
    1280   if (!g_text_mode)
    1281     {
    1282       assert(blurb1!=NULL);
    1283       assert(blurb2!=NULL);
    1284       assert(blurb3!=NULL);
    1285       assert(g_timeline!=NULL);
    1286     }
    1287 
    1288   percentline_str[0] = '\0';
    1289 
    1290   current_time = get_time ();
    1291   time_taken = current_time - g_start_time;
    1292   if (g_maximum_progress == 0)
    1293     {
    1294       percentage = 0;
    1295     }
    1296   else
    1297     {
    1298       if (g_current_progress > g_maximum_progress)
    1299     {
    1300       sprintf (tmp,
    1301            "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
    1302            blurb1, blurb2, blurb3, g_current_progress,
    1303            g_maximum_progress);
    1304       log_msg (0, tmp);
    1305       g_current_progress = g_maximum_progress;
    1306     }
    1307       percentage = (int) ((g_current_progress * 100L) / g_maximum_progress);
    1308     }
    1309   if (percentage < 1)
    1310     {
    1311       percentage = 1;
    1312     }
    1313   if (percentage > 100)
    1314     {
    1315       percentage = 100;
    1316     }
    1317   if (g_current_progress)
    1318     {
    1319       time_total_est = time_taken * (long) g_maximum_progress / (long) (g_current_progress);
    1320       time_remaining = time_total_est - time_taken;
    1321     }
    1322   else
    1323     {
    1324       time_remaining = 0;
    1325     }
    1326   g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1327   sprintf (timeline_str,
    1328        "%2ld:%02ld taken               %2ld:%02ld remaining  ",
    1329        time_taken / 60, time_taken % 60, time_remaining / 60,
    1330        time_remaining % 60);
    1331   sprintf (percentline_str, " %3d%% done                 %3d%% to go",
    1332        percentage, 100 - percentage);
    1333 
    1334   if (g_text_mode)
    1335     {
    1336       printf("---progress-form---1--- %s\r\n", blurb1);
    1337       printf("---progress-form---2--- %s\r\n", blurb2);
    1338       printf("---progress-form---3--- %s\r\n", blurb3);
    1339       printf("---progress-form---E---\n");
    1340       sprintf (taskprogress, "TASK:  [");
    1341       for (i = 0; i < percentage; i += 5)
    1342     {
    1343       strcat (taskprogress, "*");
    1344     }
    1345       for (; i < 100; i += 5)
    1346     {
    1347       strcat (taskprogress, ".");
    1348     }
    1349       if (percentage>100) { log_msg(2, "percentage = %d", percentage); }
    1350       sprintf (taskprogress + strlen (taskprogress),
    1351            "] %3d%c", percentage, '%');
    1352       sprintf (taskprogress + strlen (taskprogress),
    1353         " done; %2ld:%02ld to go",
    1354         time_remaining / 60, time_remaining % 60);
    1355       printf("---progress-form---4--- %s\r\n", taskprogress);
    1356     }
    1357   else
    1358     {
    1359       center_string (blurb1, 54);
    1360       center_string (blurb2, 54);
    1361       center_string (blurb3, 54);
    1362       newtLabelSetText (g_blurb1, blurb1);
    1363       newtLabelSetText (g_blurb2, blurb3);
    1364       newtLabelSetText (g_blurb3, blurb2);
    1365           newtScaleSet (g_scale, (unsigned long long) g_current_progress);
    1366       if (percentage >= 2)
    1367     {
    1368       newtLabelSetText (g_timeline, timeline_str);
    1369     }
    1370       newtLabelSetText (g_percentline, percentline_str);
    1371       newtRefresh ();
    1372     }
    1373   paranoid_free(percentline_str);
    1374   paranoid_free(timeline_str);
    1375   paranoid_free(taskprogress);
    1376   paranoid_free(tmp);
    1377 }
     1202        percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
     1203        timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
     1204        taskprogress = malloc(MAX_NEWT_COMMENT_LEN);
     1205        malloc_string(tmp);
     1206        if (!g_text_mode) {
     1207            assert(blurb1 != NULL);
     1208            assert(blurb2 != NULL);
     1209            assert(blurb3 != NULL);
     1210            assert(g_timeline != NULL);
     1211        }
     1212
     1213        percentline_str[0] = '\0';
     1214
     1215        current_time = get_time();
     1216        time_taken = current_time - g_start_time;
     1217        if (g_maximum_progress == 0) {
     1218            percentage = 0;
     1219        } else {
     1220            if (g_current_progress > g_maximum_progress) {
     1221                sprintf(tmp,
     1222                        "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
     1223                        blurb1, blurb2, blurb3, g_current_progress,
     1224                        g_maximum_progress);
     1225                log_msg(0, tmp);
     1226                g_current_progress = g_maximum_progress;
     1227            }
     1228            percentage =
     1229                (int) ((g_current_progress * 100L) / g_maximum_progress);
     1230        }
     1231        if (percentage < 1) {
     1232            percentage = 1;
     1233        }
     1234        if (percentage > 100) {
     1235            percentage = 100;
     1236        }
     1237        if (g_current_progress) {
     1238            time_total_est =
     1239                time_taken * (long) g_maximum_progress /
     1240                (long) (g_current_progress);
     1241            time_remaining = time_total_est - time_taken;
     1242        } else {
     1243            time_remaining = 0;
     1244        }
     1245        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
     1246        sprintf(timeline_str,
     1247                "%2ld:%02ld taken               %2ld:%02ld remaining  ",
     1248                time_taken / 60, time_taken % 60, time_remaining / 60,
     1249                time_remaining % 60);
     1250        sprintf(percentline_str, " %3d%% done                 %3d%% to go",
     1251                percentage, 100 - percentage);
     1252
     1253        if (g_text_mode) {
     1254            printf("---progress-form---1--- %s\r\n", blurb1);
     1255            printf("---progress-form---2--- %s\r\n", blurb2);
     1256            printf("---progress-form---3--- %s\r\n", blurb3);
     1257            printf("---progress-form---E---\n");
     1258            sprintf(taskprogress, "TASK:  [");
     1259            for (i = 0; i < percentage; i += 5) {
     1260                strcat(taskprogress, "*");
     1261            }
     1262            for (; i < 100; i += 5) {
     1263                strcat(taskprogress, ".");
     1264            }
     1265            if (percentage > 100) {
     1266                log_msg(2, "percentage = %d", percentage);
     1267            }
     1268            sprintf(taskprogress + strlen(taskprogress),
     1269                    "] %3d%c", percentage, '%');
     1270            sprintf(taskprogress + strlen(taskprogress),
     1271                    " done; %2ld:%02ld to go",
     1272                    time_remaining / 60, time_remaining % 60);
     1273            printf("---progress-form---4--- %s\r\n", taskprogress);
     1274        } else {
     1275            center_string(blurb1, 54);
     1276            center_string(blurb2, 54);
     1277            center_string(blurb3, 54);
     1278            newtLabelSetText(g_blurb1, blurb1);
     1279            newtLabelSetText(g_blurb2, blurb3);
     1280            newtLabelSetText(g_blurb3, blurb2);
     1281            newtScaleSet(g_scale, (unsigned long long) g_current_progress);
     1282            if (percentage >= 2) {
     1283                newtLabelSetText(g_timeline, timeline_str);
     1284            }
     1285            newtLabelSetText(g_percentline, percentline_str);
     1286            newtRefresh();
     1287        }
     1288        paranoid_free(percentline_str);
     1289        paranoid_free(timeline_str);
     1290        paranoid_free(taskprogress);
     1291        paranoid_free(tmp);
     1292    }
    13781293
    13791294
     
    13981313 * @return The backup type chosen, or @c none if the user chose "Exit to shell".
    13991314 */
    1400 t_bkptype
    1401 which_backup_media_type (bool restoring)
    1402 {
    1403 
    1404     /*@ char *************************************************************/
    1405       t_bkptype output;
    1406 
    1407 
    1408     /*@ newt *************************************************************/
    1409   char *title_sz;
    1410   char *minimsg_sz;
    1411   static t_bkptype possible_bkptypes[] = { none,cdr,cdrw,dvd,tape,cdstream,udev,nfs,iso };
    1412   static char *possible_responses[] = {"none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "nfs", "iso", NULL };
    1413   char *outstr;
    1414   t_bkptype backup_type;
    1415   int i;
    1416 
    1417   newtComponent b1;
    1418     newtComponent b2;
    1419     newtComponent b3;
    1420     newtComponent b4;
    1421     newtComponent b5;
    1422     newtComponent b6;
    1423     newtComponent b7;
    1424     newtComponent b8;
    1425     newtComponent b_res;
    1426     newtComponent myForm;
    1427 
    1428   title_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1429   minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1430   outstr = malloc(MAX_NEWT_COMMENT_LEN);
    1431   if (g_text_mode)
    1432     {
    1433       for(backup_type = none; backup_type == none; )
    1434         {
    1435           printf("Backup type (");
    1436           for(i=0; possible_responses[i]; i++)
    1437             {
    1438               printf("%c%s", (i==0)?'\0':' ', possible_responses[i]);
    1439             }
    1440           printf(")\n--> ");
    1441           (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
    1442           strip_spaces(outstr);
    1443           for(i=0; possible_responses[i]; i++)
    1444             {
    1445               if (!strcmp(possible_responses[i], outstr))
    1446                 { backup_type = possible_bkptypes[i]; }
    1447             }
    1448         }
    1449   paranoid_free(title_sz);
    1450   paranoid_free(minimsg_sz);
    1451   paranoid_free(outstr);
    1452       return(backup_type);
    1453     }
    1454   newtDrawRootText (18, 0, WELCOME_STRING);
    1455   if (restoring)
    1456     {
    1457       strcpy(title_sz, "Please choose the backup media from which you want to read data.");
    1458       strcpy(minimsg_sz, "Read from:");
    1459     }
    1460   else
    1461     {
    1462       strcpy(title_sz, "Please choose the backup media to which you want to archive data.");
    1463       strcpy(minimsg_sz, "Backup to:");
    1464     }
    1465   newtPushHelpLine (title_sz);
    1466   //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
    1467   newtCenteredWindow (34, 17, minimsg_sz);
    1468   b1 = newtButton ( 1, 1, "CD-R disks ");
    1469   b2 = newtButton (17, 1, "CD-RW disks");
    1470   b3 = newtButton ( 1, 9, "Tape drive ");
    1471   b4 = newtButton (17, 5, "CD streamer");
    1472   b5 = newtButton ( 1, 5, " DVD disks ");
    1473   b6 = newtButton (17, 9, " NFS mount ");
    1474   b7 = newtButton ( 1,13, " Hard disk ");
    1475   b8 = newtButton (17,13, "    Exit   ");
    1476   myForm = newtForm (NULL, NULL, 0);
    1477   newtFormAddComponents (myForm, b1, b5, b3, b7, b2, b4, b6, b8, NULL);
    1478   b_res = newtRunForm (myForm);
    1479   newtFormDestroy (myForm);
    1480   newtPopWindow ();
    1481   if (b_res == b1)      { output = cdr; }
    1482   else if (b_res == b2) { output = cdrw; }
    1483   else if (b_res == b3) { output = tape; }
    1484   else if (b_res == b4) { output = cdstream; }
    1485   else if (b_res == b5) { output = dvd; }
    1486   else if (b_res == b6) { output = nfs; }
    1487   else if (b_res == b7) { output = iso; }
    1488   else { output = none; }
    1489   newtPopHelpLine ();
    1490   paranoid_free(title_sz);
    1491   paranoid_free(minimsg_sz);
    1492   paranoid_free(outstr);
    1493   return (output);
    1494 }
     1315    t_bkptype which_backup_media_type(bool restoring) {
     1316
     1317        /*@ char ************************************************************ */
     1318        t_bkptype output;
     1319
     1320
     1321        /*@ newt ************************************************************ */
     1322        char *title_sz;
     1323        char *minimsg_sz;
     1324        static t_bkptype possible_bkptypes[] =
     1325            { none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso };
     1326        static char *possible_responses[] =
     1327            { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
     1328"nfs", "iso", NULL };
     1329        char *outstr;
     1330        t_bkptype backup_type;
     1331        int i;
     1332
     1333        newtComponent b1;
     1334        newtComponent b2;
     1335        newtComponent b3;
     1336        newtComponent b4;
     1337        newtComponent b5;
     1338        newtComponent b6;
     1339        newtComponent b7;
     1340        newtComponent b8;
     1341        newtComponent b_res;
     1342        newtComponent myForm;
     1343
     1344        title_sz = malloc(MAX_NEWT_COMMENT_LEN);
     1345        minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
     1346        outstr = malloc(MAX_NEWT_COMMENT_LEN);
     1347        if (g_text_mode) {
     1348            for (backup_type = none; backup_type == none;) {
     1349                printf("Backup type (");
     1350                for (i = 0; possible_responses[i]; i++) {
     1351                    printf("%c%s", (i == 0) ? '\0' : ' ',
     1352                           possible_responses[i]);
     1353                }
     1354                printf(")\n--> ");
     1355                (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
     1356                strip_spaces(outstr);
     1357                for (i = 0; possible_responses[i]; i++) {
     1358                    if (!strcmp(possible_responses[i], outstr)) {
     1359                        backup_type = possible_bkptypes[i];
     1360                    }
     1361                }
     1362            }
     1363            paranoid_free(title_sz);
     1364            paranoid_free(minimsg_sz);
     1365            paranoid_free(outstr);
     1366            return (backup_type);
     1367        }
     1368        newtDrawRootText(18, 0, WELCOME_STRING);
     1369        if (restoring) {
     1370            strcpy(title_sz,
     1371                   "Please choose the backup media from which you want to read data.");
     1372            strcpy(minimsg_sz, "Read from:");
     1373        } else {
     1374            strcpy(title_sz,
     1375                   "Please choose the backup media to which you want to archive data.");
     1376            strcpy(minimsg_sz, "Backup to:");
     1377        }
     1378        newtPushHelpLine(title_sz);
     1379        //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
     1380        newtCenteredWindow(34, 17, minimsg_sz);
     1381        b1 = newtButton(1, 1, "CD-R disks ");
     1382        b2 = newtButton(17, 1, "CD-RW disks");
     1383        b3 = newtButton(1, 9, "Tape drive ");
     1384        b4 = newtButton(17, 5, "CD streamer");
     1385        b5 = newtButton(1, 5, " DVD disks ");
     1386        b6 = newtButton(17, 9, " NFS mount ");
     1387        b7 = newtButton(1, 13, " Hard disk ");
     1388        b8 = newtButton(17, 13, "    Exit   ");
     1389        myForm = newtForm(NULL, NULL, 0);
     1390        newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8,
     1391                              NULL);
     1392        b_res = newtRunForm(myForm);
     1393        newtFormDestroy(myForm);
     1394        newtPopWindow();
     1395        if (b_res == b1) {
     1396            output = cdr;
     1397        } else if (b_res == b2) {
     1398            output = cdrw;
     1399        } else if (b_res == b3) {
     1400            output = tape;
     1401        } else if (b_res == b4) {
     1402            output = cdstream;
     1403        } else if (b_res == b5) {
     1404            output = dvd;
     1405        } else if (b_res == b6) {
     1406            output = nfs;
     1407        } else if (b_res == b7) {
     1408            output = iso;
     1409        } else {
     1410            output = none;
     1411        }
     1412        newtPopHelpLine();
     1413        paranoid_free(title_sz);
     1414        paranoid_free(minimsg_sz);
     1415        paranoid_free(outstr);
     1416        return (output);
     1417    }
    14951418
    14961419
     
    15021425 * @return The compression level (0-9) chosen, or -1 for "Exit".
    15031426 */
    1504 int
    1505 which_compression_level ()
    1506 {
    1507 
    1508     /*@ char *************************************************************/
    1509   int output = none;
    1510 
    1511 
    1512     /*@ newt *************************************************************/
    1513 
    1514   newtComponent b1;
    1515     newtComponent b2;
    1516     newtComponent b3;
    1517     newtComponent b4;
    1518     newtComponent b5;
    1519     newtComponent b_res;
    1520     newtComponent myForm;
    1521 
    1522   newtDrawRootText (18, 0, WELCOME_STRING);
    1523   newtPushHelpLine
    1524     ("   Please specify the level of compression that you want.");
    1525   //  newtOpenWindow (23, 3, 34, 13, "How much compression?");
    1526   newtCenteredWindow (34, 13, "How much compression?");
    1527   b1 = newtButton ( 4, 1, "Maximum");
    1528   b2 = newtButton (18, 1, "Average");
    1529   b3 = newtButton ( 4, 5, "Minumum");
    1530   b4 = newtButton (18, 5, " None  ");
    1531   b5 = newtButton ( 4, 9, "         Exit        ");
    1532   myForm = newtForm (NULL, NULL, 0);
    1533   newtFormAddComponents (myForm, b1, b3, b2, b4, b5, NULL);
    1534   b_res = newtRunForm (myForm);
    1535   newtFormDestroy (myForm);
    1536   newtPopWindow ();
    1537   if (b_res == b1)      { output = 9; }
    1538   else if (b_res == b2) { output = 4; }
    1539   else if (b_res == b3) { output = 1; }
    1540   else if (b_res == b4) { output = 0; }
    1541   else if (b_res == b5) { output = -1; }
    1542   newtPopHelpLine ();
    1543   return (output);
    1544 }
     1427    int
     1428     which_compression_level() {
     1429
     1430        /*@ char ************************************************************ */
     1431        int output = none;
     1432
     1433
     1434        /*@ newt ************************************************************ */
     1435
     1436        newtComponent b1;
     1437        newtComponent b2;
     1438        newtComponent b3;
     1439        newtComponent b4;
     1440        newtComponent b5;
     1441        newtComponent b_res;
     1442        newtComponent myForm;
     1443
     1444        newtDrawRootText(18, 0, WELCOME_STRING);
     1445        newtPushHelpLine
     1446            ("   Please specify the level of compression that you want.");
     1447        //  newtOpenWindow (23, 3, 34, 13, "How much compression?");
     1448        newtCenteredWindow(34, 13, "How much compression?");
     1449        b1 = newtButton(4, 1, "Maximum");
     1450        b2 = newtButton(18, 1, "Average");
     1451        b3 = newtButton(4, 5, "Minumum");
     1452        b4 = newtButton(18, 5, " None  ");
     1453        b5 = newtButton(4, 9, "         Exit        ");
     1454        myForm = newtForm(NULL, NULL, 0);
     1455        newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL);
     1456        b_res = newtRunForm(myForm);
     1457        newtFormDestroy(myForm);
     1458        newtPopWindow();
     1459        if (b_res == b1) {
     1460            output = 9;
     1461        } else if (b_res == b2) {
     1462            output = 4;
     1463        } else if (b_res == b3) {
     1464            output = 1;
     1465        } else if (b_res == b4) {
     1466            output = 0;
     1467        } else if (b_res == b5) {
     1468            output = -1;
     1469        }
     1470        newtPopHelpLine();
     1471        return (output);
     1472    }
    15451473
    15461474
     
    15541482 * @param source_file The file containing a list of filenames to load into @p filelist.
    15551483 */
    1556 int load_filelist_into_array(struct s_filelist *filelist, char *source_file)
    1557 {
    1558   int i;
    1559   bool done;
    1560   char *tmp;
    1561   FILE*fin;
    1562   struct s_filelist_entry dummy_fle;
    1563 
    1564   malloc_string(tmp);
    1565   assert(filelist!=NULL);
    1566   assert_string_is_neither_NULL_nor_zerolength(source_file);
    1567 
    1568   iamhere("entering");
    1569   if (!(fin=fopen(source_file, "r"))) { log_OS_error(source_file); log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); paranoid_free(tmp); return(1); }
    1570   log_msg(2, "Loading %s", source_file);
    1571   for(filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; filelist->entries++)
    1572     {
    1573 god_i_hate_gotos:
    1574       if (feof(fin)) { break; }
    1575       (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
    1576       i = (int) strlen(tmp);
    1577       if (i<2) { goto god_i_hate_gotos; }
    1578       if (tmp[i-1]<32) { tmp[--i]='\0'; }
    1579       if (i<2) { goto god_i_hate_gotos; }
    1580       if (!does_file_exist(tmp)) { goto god_i_hate_gotos; }
    1581       filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL);
    1582       strcpy(filelist->el[filelist->entries].filename, tmp);
    1583       if (feof(fin)) { break; }
    1584     }
    1585   paranoid_fclose(fin);
    1586   if (filelist->entries >= ARBITRARY_MAXIMUM)
    1587     {
    1588       log_to_screen ("Arbitrary limits suck, man!");
    1589       paranoid_free(tmp);
    1590       return(1);
    1591     }
    1592   for(done=FALSE;!done;)
    1593     {
    1594       done = TRUE;
    1595       for(i=0; i<filelist->entries-1; i++)
    1596         {
     1484    int load_filelist_into_array(struct s_filelist *filelist,
     1485                                 char *source_file) {
     1486        int i;
     1487        bool done;
     1488        char *tmp;
     1489        FILE *fin;
     1490        struct s_filelist_entry dummy_fle;
     1491
     1492        malloc_string(tmp);
     1493        assert(filelist != NULL);
     1494        assert_string_is_neither_NULL_nor_zerolength(source_file);
     1495
     1496        iamhere("entering");
     1497        if (!(fin = fopen(source_file, "r"))) {
     1498            log_OS_error(source_file);
     1499            log_msg(2, "Can't open %s; therefore, cannot popup list",
     1500                    source_file);
     1501            paranoid_free(tmp);
     1502            return (1);
     1503        }
     1504        log_msg(2, "Loading %s", source_file);
     1505        for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM;
     1506             filelist->entries++) {
     1507          god_i_hate_gotos:
     1508            if (feof(fin)) {
     1509                break;
     1510            }
     1511            (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
     1512            i = (int) strlen(tmp);
     1513            if (i < 2) {
     1514                goto god_i_hate_gotos;
     1515            }
     1516            if (tmp[i - 1] < 32) {
     1517                tmp[--i] = '\0';
     1518            }
     1519            if (i < 2) {
     1520                goto god_i_hate_gotos;
     1521            }
     1522            if (!does_file_exist(tmp)) {
     1523                goto god_i_hate_gotos;
     1524            }
     1525            filelist->el[filelist->entries].severity =
     1526                severity_of_difference(tmp, NULL);
     1527            strcpy(filelist->el[filelist->entries].filename, tmp);
     1528            if (feof(fin)) {
     1529                break;
     1530            }
     1531        }
     1532        paranoid_fclose(fin);
     1533        if (filelist->entries >= ARBITRARY_MAXIMUM) {
     1534            log_to_screen("Arbitrary limits suck, man!");
     1535            paranoid_free(tmp);
     1536            return (1);
     1537        }
     1538        for (done = FALSE; !done;) {
     1539            done = TRUE;
     1540            for (i = 0; i < filelist->entries - 1; i++) {
    15971541//          if (strcmp(filelist->el[i].filename, filelist->el[i+1].filename) > 0)
    1598           if (filelist->el[i].severity < filelist->el[i+1].severity || (filelist->el[i].severity==filelist->el[i+1].severity && strcmp(filelist->el[i].filename, filelist->el[i+1].filename)>0))
    1599             {
    1600               memcpy((void*)&dummy_fle, (void*)&(filelist->el[i]), sizeof(struct s_filelist_entry));
    1601               memcpy((void*)&(filelist->el[i]), (void*)&(filelist->el[i+1]), sizeof(struct s_filelist_entry));
    1602                memcpy((void*)&(filelist->el[i+1]), (void*)&dummy_fle, sizeof(struct s_filelist_entry));
    1603               log_msg(2, "Swapping %s and %s", filelist->el[i].filename, filelist->el[i+1].filename);
    1604               done = FALSE;
    1605             }
    1606         }
    1607     }
    1608   paranoid_free(tmp);
    1609   iamhere("leaving");
    1610   return(0);
    1611 }
     1542                if (filelist->el[i].severity < filelist->el[i + 1].severity
     1543                    || (filelist->el[i].severity ==
     1544                        filelist->el[i + 1].severity
     1545                        && strcmp(filelist->el[i].filename,
     1546                                  filelist->el[i + 1].filename) > 0)) {
     1547                    memcpy((void *) &dummy_fle,
     1548                           (void *) &(filelist->el[i]),
     1549                           sizeof(struct s_filelist_entry));
     1550                    memcpy((void *) &(filelist->el[i]),
     1551                           (void *) &(filelist->el[i + 1]),
     1552                           sizeof(struct s_filelist_entry));
     1553                    memcpy((void *) &(filelist->el[i + 1]),
     1554                           (void *) &dummy_fle,
     1555                           sizeof(struct s_filelist_entry));
     1556                    log_msg(2, "Swapping %s and %s",
     1557                            filelist->el[i].filename,
     1558                            filelist->el[i + 1].filename);
     1559                    done = FALSE;
     1560                }
     1561            }
     1562        }
     1563        paranoid_free(tmp);
     1564        iamhere("leaving");
     1565        return (0);
     1566    }
    16121567
    16131568
     
    16191574 * @note The returned value points to static storage that will be overwritten with each call.
    16201575 */
    1621 char*filelist_entry_to_string(struct s_filelist_entry *flentry)
    1622 {
    1623   static char comment[100];
    1624   char *tmp;
    1625 
    1626   iamhere("entering"); 
    1627   malloc_string(tmp);
    1628   assert(flentry!=NULL);
    1629   if (flentry->severity==0) { strcpy(tmp, "0   "); }
    1630   else if (flentry->severity==1) { strcpy(tmp, "low "); }
    1631   else if (flentry->severity==2) { strcpy(tmp, "med "); }
    1632   else { strcpy(tmp, "high"); }
    1633   strcat(tmp, "  ");
    1634   strncat(tmp, flentry->filename, 100);
    1635   tmp[98] = '\0';
    1636   strcpy(comment, tmp);
    1637   paranoid_free(tmp);
    1638   iamhere("leaving");
    1639   return(comment);
    1640 }
     1576    char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
     1577        static char comment[100];
     1578        char *tmp;
     1579
     1580        iamhere("entering");
     1581        malloc_string(tmp);
     1582        assert(flentry != NULL);
     1583        if (flentry->severity == 0) {
     1584            strcpy(tmp, "0   ");
     1585        } else if (flentry->severity == 1) {
     1586            strcpy(tmp, "low ");
     1587        } else if (flentry->severity == 2) {
     1588            strcpy(tmp, "med ");
     1589        } else {
     1590            strcpy(tmp, "high");
     1591        }
     1592        strcat(tmp, "  ");
     1593        strncat(tmp, flentry->filename, 100);
     1594        tmp[98] = '\0';
     1595        strcpy(comment, tmp);
     1596        paranoid_free(tmp);
     1597        iamhere("leaving");
     1598        return (comment);
     1599    }
    16411600
    16421601
     
    16491608 * @param source_file The file containing a list of changed files.
    16501609 */
    1651 void popup_changelist_from_file(char*source_file)
    1652 {
    1653   char *reason;
    1654   newtComponent myForm;
    1655     newtComponent bClose;
    1656     newtComponent bSelect;
    1657     newtComponent b_res;
    1658     newtComponent fileListbox;
    1659     newtComponent headerMsg;
    1660 
    1661     /*@ ???? *************************************************************/
    1662   void *curr_choice;
    1663   void *keylist[ARBITRARY_MAXIMUM];
    1664 
    1665     /*@ int **************************************************************/
    1666   int i = 0;
    1667     int currline = 0;
    1668     int finished = FALSE;
    1669   long lng = 0;
    1670 
    1671     /*@ buffers **********************************************************/
    1672     char *tmp;
    1673     char *differ_sz;
    1674 
    1675   struct s_filelist *filelist;
    1676   malloc_string(reason);
    1677   tmp = malloc(5000);
    1678   malloc_string(differ_sz);
    1679   assert_string_is_neither_NULL_nor_zerolength(source_file);
    1680   if (g_text_mode)
    1681     {
    1682       log_msg(2, "Text mode. Therefore, no popup list.");
    1683       goto free_to_go;
    1684     }
    1685   log_msg (2, "Examining file %s", source_file);
    1686 
    1687   lng = count_lines_in_file(source_file);
    1688   if (lng < 1)
    1689     {
    1690       log_msg (2, "No lines in file. Therefore, no popup list."); paranoid_free(reason);
    1691       goto free_to_go;
    1692      }
    1693   else if (lng >= ARBITRARY_MAXIMUM)
    1694      {
    1695        log_msg(2, "Too many files differ for me to list.");
    1696        goto free_to_go;
    1697      }
    1698 
    1699   filelist = (struct s_filelist*)malloc(sizeof(struct s_filelist));
    1700   fileListbox =
    1701     newtListbox (2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1702   newtListboxClear (fileListbox);
    1703 
    1704   if (load_filelist_into_array(filelist, source_file)) { log_msg (2, "Can't open %s; therefore, cannot popup list", source_file); paranoid_free(reason); return; }
    1705   log_msg(2, "%d files loaded into filelist array", filelist->entries);
    1706   for(i=0; i<filelist->entries; i++)
    1707     {
    1708       keylist[i] = (void *) i;
    1709       newtListboxAppendEntry (fileListbox, filelist_entry_to_string(&(filelist->el[i])), keylist[i]);
    1710     }
    1711   sprintf(differ_sz, "  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i);
    1712   newtPushHelpLine(differ_sz);
    1713   bClose = newtCompactButton (10, 15, " Close  ");
    1714   bSelect = newtCompactButton (30, 15, " Select ");
    1715   sprintf (tmp, "%-10s               %-20s", "Priority", "Filename");
    1716   headerMsg = newtLabel (2, 1, tmp);
    1717   newtOpenWindow (5, 4, 70, 16, "Non-matching files");
    1718   myForm = newtForm (NULL, NULL, 0);
    1719   newtFormAddComponents (myForm, headerMsg, fileListbox, bClose, bSelect, NULL);
    1720   while (!finished)
    1721     {
    1722       b_res = newtRunForm (myForm);
    1723       if (b_res == bClose)
    1724     {
    1725           finished = TRUE;
    1726         }
    1727       else
    1728         {
    1729           curr_choice = newtListboxGetCurrent (fileListbox);
    1730       for (i = 0; i < filelist->entries && keylist[i] != curr_choice;
    1731            i++);
    1732       if (i == filelist->entries && filelist->entries > 0)
    1733         {
    1734           log_to_screen ("I don't know what that button does!");
    1735         }
    1736       else
    1737         {
    1738           currline = i;
    1739           if (filelist->entries > 0)
    1740             {
    1741             severity_of_difference(filelist->el[currline].filename, reason);
    1742             sprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason);
    1743             popup_and_OK(tmp);
    1744             }
    1745         }
    1746     }
    1747     }
    1748   newtFormDestroy (myForm);
    1749   newtPopWindow ();
    1750   newtPopHelpLine ();
    1751 free_to_go:
    1752   paranoid_free(reason);
    1753   paranoid_free(tmp);
    1754   paranoid_free(differ_sz);
    1755   return;
    1756 }
     1610    void popup_changelist_from_file(char *source_file) {
     1611        char *reason;
     1612        newtComponent myForm;
     1613        newtComponent bClose;
     1614        newtComponent bSelect;
     1615        newtComponent b_res;
     1616        newtComponent fileListbox;
     1617        newtComponent headerMsg;
     1618
     1619        /*@ ???? ************************************************************ */
     1620        void *curr_choice;
     1621        void *keylist[ARBITRARY_MAXIMUM];
     1622
     1623        /*@ int ************************************************************* */
     1624        int i = 0;
     1625        int currline = 0;
     1626        int finished = FALSE;
     1627        long lng = 0;
     1628
     1629        /*@ buffers ********************************************************* */
     1630        char *tmp;
     1631        char *differ_sz;
     1632
     1633        struct s_filelist *filelist;
     1634        malloc_string(reason);
     1635        tmp = malloc(5000);
     1636        malloc_string(differ_sz);
     1637        assert_string_is_neither_NULL_nor_zerolength(source_file);
     1638        if (g_text_mode) {
     1639            log_msg(2, "Text mode. Therefore, no popup list.");
     1640            goto free_to_go;
     1641        }
     1642        log_msg(2, "Examining file %s", source_file);
     1643
     1644        lng = count_lines_in_file(source_file);
     1645        if (lng < 1) {
     1646            log_msg(2, "No lines in file. Therefore, no popup list.");
     1647            paranoid_free(reason);
     1648            goto free_to_go;
     1649        } else if (lng >= ARBITRARY_MAXIMUM) {
     1650            log_msg(2, "Too many files differ for me to list.");
     1651            goto free_to_go;
     1652        }
     1653
     1654        filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
     1655        fileListbox =
     1656            newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1657        newtListboxClear(fileListbox);
     1658
     1659        if (load_filelist_into_array(filelist, source_file)) {
     1660            log_msg(2, "Can't open %s; therefore, cannot popup list",
     1661                    source_file);
     1662            paranoid_free(reason);
     1663            return;
     1664        }
     1665        log_msg(2, "%d files loaded into filelist array",
     1666                filelist->entries);
     1667        for (i = 0; i < filelist->entries; i++) {
     1668            keylist[i] = (void *) i;
     1669            newtListboxAppendEntry(fileListbox,
     1670                                   filelist_entry_to_string(&
     1671                                                            (filelist->
     1672                                                             el[i])),
     1673                                   keylist[i]);
     1674        }
     1675        sprintf(differ_sz,
     1676                "  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.",
     1677                i);
     1678        newtPushHelpLine(differ_sz);
     1679        bClose = newtCompactButton(10, 15, " Close  ");
     1680        bSelect = newtCompactButton(30, 15, " Select ");
     1681        sprintf(tmp, "%-10s               %-20s", "Priority", "Filename");
     1682        headerMsg = newtLabel(2, 1, tmp);
     1683        newtOpenWindow(5, 4, 70, 16, "Non-matching files");
     1684        myForm = newtForm(NULL, NULL, 0);
     1685        newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
     1686                              bSelect, NULL);
     1687        while (!finished) {
     1688            b_res = newtRunForm(myForm);
     1689            if (b_res == bClose) {
     1690                finished = TRUE;
     1691            } else {
     1692                curr_choice = newtListboxGetCurrent(fileListbox);
     1693                for (i = 0;
     1694                     i < filelist->entries && keylist[i] != curr_choice;
     1695                     i++);
     1696                if (i == filelist->entries && filelist->entries > 0) {
     1697                    log_to_screen("I don't know what that button does!");
     1698                } else {
     1699                    currline = i;
     1700                    if (filelist->entries > 0) {
     1701                        severity_of_difference(filelist->el[currline].
     1702                                               filename, reason);
     1703                        sprintf(tmp, "%s --- %s",
     1704                                filelist->el[currline].filename, reason);
     1705                        popup_and_OK(tmp);
     1706                    }
     1707                }
     1708            }
     1709        }
     1710        newtFormDestroy(myForm);
     1711        newtPopWindow();
     1712        newtPopHelpLine();
     1713      free_to_go:
     1714        paranoid_free(reason);
     1715        paranoid_free(tmp);
     1716        paranoid_free(differ_sz);
     1717        return;
     1718    }
    17571719
    17581720/* @} - end of guiGroup */
     
    17601722
    17611723#if __cplusplus
    1762 } /* extern "C" */
     1724}                               /* extern "C" */
    17631725#endif
    17641726
    17651727
    1766 void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage);
    1767 
     1728void wait_until_software_raids_are_prepped(char *mdstat_file,
     1729                                           int wait_for_percentage);
  • branches/2.05/mondo/mondo/common/newt-specific.h

    r30 r128  
    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);
  • branches/2.05/mondo/mondo/mondoarchive/main.c

    r30 r128  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: main.c,v 1.14 2004/06/21 20:20:36 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    127127
    128128// for CVS
    129 //static char cvsid[] = "$Id: main.c,v 1.14 2004/06/21 20:20:36 hugo Exp $";
     129//static char cvsid[] = "$Id$";
    130130
    131131/************************* external variables *************************/
    132132extern void set_signals(int);
    133133extern int g_current_media_number;
    134 extern void register_pid(pid_t, char*);
     134extern void register_pid(pid_t, char *);
    135135extern int g_currentY;
    136136extern bool g_text_mode;
     
    141141extern char *g_erase_tmpdir_and_scratchdir;
    142142extern char *g_cdrw_drive_is_here;
    143 static char *g_cdrom_drive_is_here=NULL;
    144 static char *g_dvd_drive_is_here=NULL;
     143static char *g_cdrom_drive_is_here = NULL;
     144static char *g_dvd_drive_is_here = NULL;
    145145extern double g_kernel_version;
    146146
     
    160160void welcome_to_mondoarchive()
    161161{
    162   log_msg (0, "Mondo Archive v%s --- http://www.mondorescue.org", VERSION);
    163   log_msg (0, "running on %s architecture",get_architecture());
    164   log_msg (0,"-----------------------------------------------------------");
    165   log_msg (0, "NB: Mondo logs almost everything, so don't panic if you see");
    166   log_msg (0, "some error messages.  Please read them carefully before you");
    167   log_msg (0, "decide to break out in a cold sweat.    Despite (or perhaps");
    168   log_msg (0, "because of) the wealth of messages. some users are inclined");
    169   log_msg (0, "to stop reading this log. If Mondo stopped for some reason,");
    170   log_msg (0, "chances are it's detailed here.  More than likely there's a");
    171   log_msg (0, "message at the very end of this log that will tell you what");
    172   log_msg (0, "is wrong. Please read it!                          -Devteam");
    173   log_msg (0,"-----------------------------------------------------------");
    174 
    175   log_msg (0, "Zero...");
    176   log_msg (1, "One...");
    177   log_msg (2, "Two...");
    178   log_msg (3, "Three...");
    179   log_msg (4, "Four...");
    180   log_msg (5, "Five...");
    181   log_msg (6, "Six...");
    182   log_msg (7, "Seven...");
    183   log_msg (8, "Eight...");
    184   printf ("See %s for details of backup run.\n", MONDO_LOGFILE);
     162    log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
     163            VERSION);
     164    log_msg(0, "running on %s architecture", get_architecture());
     165    log_msg(0,
     166            "-----------------------------------------------------------");
     167    log_msg(0,
     168            "NB: Mondo logs almost everything, so don't panic if you see");
     169    log_msg(0,
     170            "some error messages.  Please read them carefully before you");
     171    log_msg(0,
     172            "decide to break out in a cold sweat.    Despite (or perhaps");
     173    log_msg(0,
     174            "because of) the wealth of messages. some users are inclined");
     175    log_msg(0,
     176            "to stop reading this log. If Mondo stopped for some reason,");
     177    log_msg(0,
     178            "chances are it's detailed here.  More than likely there's a");
     179    log_msg(0,
     180            "message at the very end of this log that will tell you what");
     181    log_msg(0,
     182            "is wrong. Please read it!                          -Devteam");
     183    log_msg(0,
     184            "-----------------------------------------------------------");
     185
     186    log_msg(0, "Zero...");
     187    log_msg(1, "One...");
     188    log_msg(2, "Two...");
     189    log_msg(3, "Three...");
     190    log_msg(4, "Four...");
     191    log_msg(5, "Five...");
     192    log_msg(6, "Six...");
     193    log_msg(7, "Seven...");
     194    log_msg(8, "Eight...");
     195    printf("See %s for details of backup run.\n", MONDO_LOGFILE);
    185196}
    186197
     
    194205void distro_specific_kludges_at_start_of_mondoarchive()
    195206{
    196   log_msg (2, "Unmounting old ramdisks if necessary");
    197   stop_magicdev_if_necessary(); // for RH+Gnome users
    198   run_program_and_log_output("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
    199   unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
    200   //  stop_autofs_if_necessary(); // for Xandros users
    201   mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions
    202   clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way
     207    log_msg(2, "Unmounting old ramdisks if necessary");
     208    stop_magicdev_if_necessary();   // for RH+Gnome users
     209    run_program_and_log_output
     210        ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
     211    unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
     212    //  stop_autofs_if_necessary(); // for Xandros users
     213    mount_boot_if_necessary();  // for Gentoo users with non-mounted /boot partitions
     214    clean_up_KDE_desktop_if_necessary();    // delete various misc ~/.* files that get in the way
    203215}
    204216
     
    211223{
    212224//  char tmp[500];
    213   log_msg( 2, "Restarting magicdev if necessary");
    214   sync();
    215   restart_magicdev_if_necessary(); // for RH+Gnome users
    216 
    217   log_msg( 2, "Restarting autofs if necessary");
    218   sync();
    219   //  restart_autofs_if_necessary(); // for Xandros users
    220 
    221   log_msg( 2, "Restarting supermounts if necessary");
    222   sync();
    223   remount_supermounts_if_necessary(); // for Mandrake users
    224 
    225   log_msg( 2, "Unmounting /boot if necessary");
    226   sync();
    227   unmount_boot_if_necessary(); // for Gentoo users
     225    log_msg(2, "Restarting magicdev if necessary");
     226    sync();
     227    restart_magicdev_if_necessary();    // for RH+Gnome users
     228
     229    log_msg(2, "Restarting autofs if necessary");
     230    sync();
     231    //  restart_autofs_if_necessary(); // for Xandros users
     232
     233    log_msg(2, "Restarting supermounts if necessary");
     234    sync();
     235    remount_supermounts_if_necessary(); // for Mandrake users
     236
     237    log_msg(2, "Unmounting /boot if necessary");
     238    sync();
     239    unmount_boot_if_necessary();    // for Gentoo users
    228240
    229241//  log_msg( 2, "Cleaning up KDE desktop");
     
    240252 * What did you think it did, anyway? :-)
    241253 */
    242 int
    243 main (int argc, char *argv[])
     254int main(int argc, char *argv[])
    244255{
    245   struct s_bkpinfo *bkpinfo;
    246   char *tmp;
    247   int res, retval;
    248   char *say_at_end;
     256    struct s_bkpinfo *bkpinfo;
     257    char *tmp;
     258    int res, retval;
     259    char *say_at_end;
    249260
    250261/* Make sure I'm root; abort if not */
    251   if (getuid () != 0)
    252     {
    253       fprintf (stderr, "Please run as root.\r\n");
    254       exit (127);
    255     }
     262    if (getuid() != 0) {
     263        fprintf(stderr, "Please run as root.\r\n");
     264        exit(127);
     265    }
    256266
    257267/* If -V, -v or --version then echo version no. and quit */
    258   if (argc==2 && (!strcmp(argv[argc-1], "-v") || !strcmp(argv[argc-1], "-V") || !strcmp(argv[argc-1], "--version")))
    259     { printf("mondoarchive v%s\nSee man page for help\n", VERSION); exit(0); }
     268    if (argc == 2
     269        && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
     270            || !strcmp(argv[argc - 1], "--version"))) {
     271        printf("mondoarchive v%s\nSee man page for help\n", VERSION);
     272        exit(0);
     273    }
    260274
    261275/* Initialize variables */
    262276
    263   malloc_libmondo_global_strings();
    264   malloc_string(tmp);
    265   malloc_string(say_at_end);
    266 
    267   res = 0;
    268   retval = 0;
    269   diffs = 0;
    270   say_at_end[0] = '\0';
    271   unlink("/var/log/partimagehack-debug.log");
    272   printf ("Initializing...\n");
    273   if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) { fatal_error("Cannot malloc bkpinfo"); }
     277    malloc_libmondo_global_strings();
     278    malloc_string(tmp);
     279    malloc_string(say_at_end);
     280
     281    res = 0;
     282    retval = 0;
     283    diffs = 0;
     284    say_at_end[0] = '\0';
     285    unlink("/var/log/partimagehack-debug.log");
     286    printf("Initializing...\n");
     287    if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) {
     288        fatal_error("Cannot malloc bkpinfo");
     289    }
    274290
    275291
    276292/* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
    277   strncpy(tmp, getenv("PATH"), MAX_STR_LEN-1);
    278   tmp[MAX_STR_LEN-1] = '\0';
    279   if (strlen(tmp)>=MAX_STR_LEN-33)
    280     { fatal_error("Your PATH environmental variable is too long. Please shorten it."); }
    281   strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
    282   setenv("PATH", tmp, 1);
     293    strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
     294    tmp[MAX_STR_LEN - 1] = '\0';
     295    if (strlen(tmp) >= MAX_STR_LEN - 33) {
     296        fatal_error
     297            ("Your PATH environmental variable is too long. Please shorten it.");
     298    }
     299    strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
     300    setenv("PATH", tmp, 1);
    283301
    284302/* Add the ARCH environment variable for ia64 purposes */
    285   strncpy(tmp, get_architecture(), MAX_STR_LEN-1);
    286   tmp[MAX_STR_LEN-1] = '\0';
    287   setenv("ARCH", tmp, 1);
    288 
    289   unlink(MONDO_LOGFILE);
     303    strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
     304    tmp[MAX_STR_LEN - 1] = '\0';
     305    setenv("ARCH", tmp, 1);
     306
     307    unlink(MONDO_LOGFILE);
    290308
    291309/* Configure the bkpinfo structure, global file paths, etc. */
    292   g_main_pid = getpid();
    293   log_msg(9, "This");
    294 
    295   register_pid(g_main_pid, "mondo");
    296   set_signals(TRUE); // catch SIGTERM, etc.
    297   nice(10);
    298   run_program_and_log_output("dmesg -n1", TRUE);
    299 
    300   log_msg(9, "Next");
    301   welcome_to_mondoarchive();
    302   distro_specific_kludges_at_start_of_mondoarchive();
    303   sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    304   g_kernel_version = get_kernel_version();
    305 
    306   if (argc==4 && !strcmp(argv[1], "getfattr"))
    307     {
    308       g_loglevel = 10;
    309       g_text_mode = TRUE;
    310       setup_newt_stuff();
    311       if (!strstr(argv[2], "filelist"))
    312         {
    313       printf("Sorry - filelist goes first\n");
    314       finish(1);
    315     }
    316       else
    317         {
    318           finish(get_fattr_list(argv[2], argv[3]));
    319     }
    320       finish(0);
    321     }
    322   if (argc==4 && !strcmp(argv[1], "setfattr"))
    323     {
    324       g_loglevel = 10;
     310    g_main_pid = getpid();
     311    log_msg(9, "This");
     312
     313    register_pid(g_main_pid, "mondo");
     314    set_signals(TRUE);          // catch SIGTERM, etc.
     315    nice(10);
     316    run_program_and_log_output("dmesg -n1", TRUE);
     317
     318    log_msg(9, "Next");
     319    welcome_to_mondoarchive();
     320    distro_specific_kludges_at_start_of_mondoarchive();
     321    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     322            bkpinfo->scratchdir);
     323    g_kernel_version = get_kernel_version();
     324
     325    if (argc == 4 && !strcmp(argv[1], "getfattr")) {
     326        g_loglevel = 10;
     327        g_text_mode = TRUE;
     328        setup_newt_stuff();
     329        if (!strstr(argv[2], "filelist")) {
     330            printf("Sorry - filelist goes first\n");
     331            finish(1);
     332        } else {
     333            finish(get_fattr_list(argv[2], argv[3]));
     334        }
     335        finish(0);
     336    }
     337    if (argc == 4 && !strcmp(argv[1], "setfattr")) {
     338        g_loglevel = 10;
    325339//      chdir("/tmp");
    326       g_text_mode = TRUE;
    327       setup_newt_stuff();
    328       finish(set_fattr_list(argv[2], argv[3]));
    329     }
    330    
    331   if (argc==3 && !strcmp(argv[1], "wildcards"))
    332     {
    333       g_loglevel = 10;
    334       g_text_mode = TRUE;
    335       setup_newt_stuff();
    336       turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
    337       printf("in=%s; out=%s\n", argv[2], tmp);
    338       finish(1);
    339     }
    340    
    341   if (argc==4 && !strcmp(argv[1], "getfacl"))
    342     {
    343       g_loglevel = 10;
    344       g_text_mode = TRUE;
    345       setup_newt_stuff();
    346       if (!strstr(argv[2], "filelist"))
    347         {
    348       printf("Sorry - filelist goes first\n");
    349       finish(1);
    350     }
    351       else
    352         {
    353           finish(get_acl_list(argv[2], argv[3]));
    354     }
    355       finish(0);
    356     }
    357   if (argc==4 && !strcmp(argv[1], "setfacl"))
    358     {
    359       g_loglevel = 10;
     340        g_text_mode = TRUE;
     341        setup_newt_stuff();
     342        finish(set_fattr_list(argv[2], argv[3]));
     343    }
     344
     345    if (argc == 3 && !strcmp(argv[1], "wildcards")) {
     346        g_loglevel = 10;
     347        g_text_mode = TRUE;
     348        setup_newt_stuff();
     349        turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
     350        printf("in=%s; out=%s\n", argv[2], tmp);
     351        finish(1);
     352    }
     353
     354    if (argc == 4 && !strcmp(argv[1], "getfacl")) {
     355        g_loglevel = 10;
     356        g_text_mode = TRUE;
     357        setup_newt_stuff();
     358        if (!strstr(argv[2], "filelist")) {
     359            printf("Sorry - filelist goes first\n");
     360            finish(1);
     361        } else {
     362            finish(get_acl_list(argv[2], argv[3]));
     363        }
     364        finish(0);
     365    }
     366    if (argc == 4 && !strcmp(argv[1], "setfacl")) {
     367        g_loglevel = 10;
    360368//      chdir("/tmp");
    361       g_text_mode = TRUE;
    362       setup_newt_stuff();
    363           finish(set_acl_list(argv[2], argv[3]));
    364     }
    365    
    366   if (argc>2 && !strcmp(argv[1], "find-cd"))
    367     {
    368       g_loglevel = 10;
    369       g_text_mode = TRUE;
    370       setup_newt_stuff();
    371       if (find_cdrw_device(tmp))
    372         { printf("Failed to find CDR-RW drive\n"); }
    373       else
    374         { printf("CD-RW is at %s\n", tmp); }
    375       tmp[0] = '\0';
    376       if (find_cdrom_device(tmp, atoi(argv[2])))
    377         { printf("Failed to find CD-ROM drive\n"); }
    378       else
    379         { printf("CD-ROM is at %s\n", tmp); }
    380       finish(0);
    381     }
    382 
    383   if (argc>2 && !strcmp(argv[1], "find-dvd"))
    384     {
    385       g_loglevel = 10;
    386       g_text_mode = TRUE;
    387       setup_newt_stuff();
    388       if (find_dvd_device(tmp, atoi(argv[2])))
    389         { printf("Failed to find DVD drive\n"); }
    390       else
    391         { printf("DVD is at %s\n", tmp); }
    392       finish(0);
    393     }
    394 
    395   if (argc>2 && !strcmp(argv[1], "disksize"))
    396     {
    397       printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
    398       finish(0);
    399     }
    400   if (argc>2 && !strcmp(argv[1], "test-dev"))
    401     {
    402       if (is_dev_an_NTFS_dev(argv[2]))
    403         { printf("%s is indeed an NTFS dev\n", argv[2]); }
    404       else
    405         { printf("%s is _not_ an NTFS dev\n", argv[2]); }
    406       finish(0);
    407     }
    408 
    409   if (pre_param_configuration(bkpinfo)) { fatal_error("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); }
    410    
     369        g_text_mode = TRUE;
     370        setup_newt_stuff();
     371        finish(set_acl_list(argv[2], argv[3]));
     372    }
     373
     374    if (argc > 2 && !strcmp(argv[1], "find-cd")) {
     375        g_loglevel = 10;
     376        g_text_mode = TRUE;
     377        setup_newt_stuff();
     378        if (find_cdrw_device(tmp)) {
     379            printf("Failed to find CDR-RW drive\n");
     380        } else {
     381            printf("CD-RW is at %s\n", tmp);
     382        }
     383        tmp[0] = '\0';
     384        if (find_cdrom_device(tmp, atoi(argv[2]))) {
     385            printf("Failed to find CD-ROM drive\n");
     386        } else {
     387            printf("CD-ROM is at %s\n", tmp);
     388        }
     389        finish(0);
     390    }
     391
     392    if (argc > 2 && !strcmp(argv[1], "find-dvd")) {
     393        g_loglevel = 10;
     394        g_text_mode = TRUE;
     395        setup_newt_stuff();
     396        if (find_dvd_device(tmp, atoi(argv[2]))) {
     397            printf("Failed to find DVD drive\n");
     398        } else {
     399            printf("DVD is at %s\n", tmp);
     400        }
     401        finish(0);
     402    }
     403
     404    if (argc > 2 && !strcmp(argv[1], "disksize")) {
     405        printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2]));
     406        finish(0);
     407    }
     408    if (argc > 2 && !strcmp(argv[1], "test-dev")) {
     409        if (is_dev_an_NTFS_dev(argv[2])) {
     410            printf("%s is indeed an NTFS dev\n", argv[2]);
     411        } else {
     412            printf("%s is _not_ an NTFS dev\n", argv[2]);
     413        }
     414        finish(0);
     415    }
     416
     417    if (pre_param_configuration(bkpinfo)) {
     418        fatal_error
     419            ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting...");
     420    }
     421
    411422/* Process command line, if there is one. If not, ask user for info. */
    412   if (argc==1)
    413     {
    414       g_text_mode = FALSE;
    415       setup_newt_stuff ();
    416       res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */
    417       if (res) { fatal_error("Syntax error. Please review the parameters you have supplied and try again."); }
    418     }
    419   else
    420     {
    421       res = handle_incoming_parameters (argc, argv, bkpinfo);
    422       if (res) {
    423         printf("Errors were detected in the command line you supplied.\n");
    424     printf("Please review the log file - " MONDO_LOGFILE "\n");
    425         log_msg(1, "Mondoarchive will now exit.");
    426     finish(1);
    427     }
    428       setup_newt_stuff ();
    429     } 
     423    if (argc == 1) {
     424        g_text_mode = FALSE;
     425        setup_newt_stuff();
     426        res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE);   /* yes, archiving */
     427        if (res) {
     428            fatal_error
     429                ("Syntax error. Please review the parameters you have supplied and try again.");
     430        }
     431    } else {
     432        res = handle_incoming_parameters(argc, argv, bkpinfo);
     433        if (res) {
     434            printf
     435                ("Errors were detected in the command line you supplied.\n");
     436            printf("Please review the log file - " MONDO_LOGFILE "\n");
     437            log_msg(1, "Mondoarchive will now exit.");
     438            finish(1);
     439        }
     440        setup_newt_stuff();
     441    }
    430442
    431443/* Finish configuring global structures */
    432   if (post_param_configuration (bkpinfo)) { fatal_error("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting..."); }
    433 
    434   log_to_screen("BusyBox's sources are available from http://www.busybox.net");
    435   sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    436 
    437   /* If we're meant to backup then backup */
    438   if (bkpinfo->backup_data)
    439     {
     444    if (post_param_configuration(bkpinfo)) {
     445        fatal_error
     446            ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting...");
     447    }
     448
     449    log_to_screen
     450        ("BusyBox's sources are available from http://www.busybox.net");
     451    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     452            bkpinfo->scratchdir);
     453
     454    /* If we're meant to backup then backup */
     455    if (bkpinfo->backup_data) {
    440456/*
    441457      log_to_screen("INFERNAL PORPOISES");
     
    444460      finish(0);
    445461*/
    446       res = backup_data(bkpinfo);
    447       retval += res;
    448       if (res)
    449     { strcat (say_at_end, "Data archived. Please check the logs, just as a precaution. "); }
    450       else
    451     { strcat (say_at_end, "Data archived OK. "); }
    452     }
     462        res = backup_data(bkpinfo);
     463        retval += res;
     464        if (res) {
     465            strcat(say_at_end,
     466                   "Data archived. Please check the logs, just as a precaution. ");
     467        } else {
     468            strcat(say_at_end, "Data archived OK. ");
     469        }
     470    }
    453471
    454472/* If we're meant to verify then verify */
    455   if (bkpinfo->verify_data)
    456     {
    457       res = verify_data(bkpinfo);
    458       if (res<0)
    459         {
    460           sprintf(tmp, "%d difference%c found.", -res, (-res != 1) ? 's' : ' ');
    461       strcat(say_at_end, tmp);
    462           log_to_screen(tmp);
    463           res=0;
    464         }
    465       retval += res;
    466     }
     473    if (bkpinfo->verify_data) {
     474        res = verify_data(bkpinfo);
     475        if (res < 0) {
     476            sprintf(tmp, "%d difference%c found.", -res,
     477                    (-res != 1) ? 's' : ' ');
     478            strcat(say_at_end, tmp);
     479            log_to_screen(tmp);
     480            res = 0;
     481        }
     482        retval += res;
     483    }
    467484
    468485/* Offer to write floppy disk images to physical disks */
    469   if (bkpinfo->backup_data && !g_skip_floppies)
    470     {
    471       res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
    472       retval += res;
     486    if (bkpinfo->backup_data && !g_skip_floppies) {
     487        res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
     488        retval += res;
    473489//      res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo);
    474490//      retval += res;
    475     }
     491    }
    476492
    477493/* Report result of entire operation (success? errors?) */
    478   if (!retval)
    479     {
    480       mvaddstr_and_log_it (g_currentY++, 0,
    481                "Backup and/or verify ran to completion. Everything appears to be fine.");
    482     }
    483   else
    484     {
    485       mvaddstr_and_log_it (g_currentY++, 0,
    486              "Backup and/or verify ran to completion. However, errors did occur.");
    487     }
    488 
    489   if (does_file_exist ("/root/images/mindi/mondorescue.iso"))
    490     {
    491       log_to_screen ("/root/images/mindi/mondorescue.iso, a boot/utility CD, is available if you want it.");
    492     }
    493 
    494 
    495   if (length_of_file ("/tmp/changed.files") > 2)
    496     {
    497       if (g_text_mode) { log_to_screen("Type 'less /tmp/changed.files' to see which files don't match the archives"); }
    498       else
    499         {
    500           log_msg (1, "Type 'less /tmp/changed.files' to see which files don't match the archives");
    501           log_msg (2, "Calling popup_changelist_from_file()");
    502           popup_changelist_from_file("/tmp/changed.files");
    503           log_msg (2, "Returned from popup_changelist_from_file()");
    504         }
    505     }
    506   else
    507     {
    508       unlink ("/tmp/changed.files");
    509     }
    510   log_to_screen (say_at_end);
    511   sprintf (tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    512   run_program_and_log_output (tmp, TRUE);
    513   run_program_and_log_output (g_erase_tmpdir_and_scratchdir, TRUE);
    514 
    515   run_program_and_log_output("mount", 2);
    516 
    517   if (bkpinfo->please_dont_eject)
    518     {
    519       log_msg(5, "Not ejecting at end. Fair enough.");
    520     }
    521   else
    522     {
    523       log_msg(5, "Ejecting at end.");
    524       if (!find_cdrom_device(tmp, FALSE) || !find_dvd_device(tmp, FALSE))
    525     {
    526       log_msg(1, "Ejecting %s", tmp);
    527       eject_device(tmp);
    528     }
    529     }
    530 
    531   system("rm -f /var/cache/mondo-archive/last-backup.aborted");
    532   system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
    533   if (!retval) { printf("Mondoarchive ran OK.\n"); }
    534   else { printf("Errors occurred during backup. Please check logfile.\n"); }
    535   distro_specific_kludges_at_end_of_mondoarchive();
    536   register_pid(0,"mondo");
    537   set_signals(FALSE);
    538   chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
    539   system(g_erase_tmpdir_and_scratchdir);
    540   free_libmondo_global_strings();
    541   paranoid_free(say_at_end);
    542   paranoid_free(tmp);
    543   paranoid_free(bkpinfo);
    544 
    545   unlink("/tmp/filelist.full");
    546   unlink("/tmp/filelist.full.gz");
    547  
    548   if (!g_cdrom_drive_is_here) { log_msg(10, "FYI, g_cdrom_drive_is_here was never used"); }
    549   if (!g_dvd_drive_is_here) { log_msg(10, "FYI, g_dvd_drive_is_here was never used"); }
    550 
    551   if (!g_text_mode)
    552     {
    553       popup_and_OK
    554     ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
    555       log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
    556       finish(retval);
    557     }
    558   else
    559     {
    560       printf ("See %s for details of backup run.\n", MONDO_LOGFILE);
    561       exit(retval);
    562     }
    563 
    564   return EXIT_SUCCESS;
     494    if (!retval) {
     495        mvaddstr_and_log_it(g_currentY++, 0,
     496                            "Backup and/or verify ran to completion. Everything appears to be fine.");
     497    } else {
     498        mvaddstr_and_log_it(g_currentY++, 0,
     499                            "Backup and/or verify ran to completion. However, errors did occur.");
     500    }
     501
     502    if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
     503        log_to_screen
     504            ("/root/images/mindi/mondorescue.iso, a boot/utility CD, is available if you want it.");
     505    }
     506
     507
     508    if (length_of_file("/tmp/changed.files") > 2) {
     509        if (g_text_mode) {
     510            log_to_screen
     511                ("Type 'less /tmp/changed.files' to see which files don't match the archives");
     512        } else {
     513            log_msg(1,
     514                    "Type 'less /tmp/changed.files' to see which files don't match the archives");
     515            log_msg(2, "Calling popup_changelist_from_file()");
     516            popup_changelist_from_file("/tmp/changed.files");
     517            log_msg(2, "Returned from popup_changelist_from_file()");
     518        }
     519    } else {
     520        unlink("/tmp/changed.files");
     521    }
     522    log_to_screen(say_at_end);
     523    sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
     524    run_program_and_log_output(tmp, TRUE);
     525    run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
     526
     527    run_program_and_log_output("mount", 2);
     528
     529    if (bkpinfo->please_dont_eject) {
     530        log_msg(5, "Not ejecting at end. Fair enough.");
     531    } else {
     532        log_msg(5, "Ejecting at end.");
     533        if (!find_cdrom_device(tmp, FALSE) || !find_dvd_device(tmp, FALSE)) {
     534            log_msg(1, "Ejecting %s", tmp);
     535            eject_device(tmp);
     536        }
     537    }
     538
     539    system("rm -f /var/cache/mondo-archive/last-backup.aborted");
     540    system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
     541    if (!retval) {
     542        printf("Mondoarchive ran OK.\n");
     543    } else {
     544        printf("Errors occurred during backup. Please check logfile.\n");
     545    }
     546    distro_specific_kludges_at_end_of_mondoarchive();
     547    register_pid(0, "mondo");
     548    set_signals(FALSE);
     549    chdir("/tmp");              // just in case there's something wrong with g_erase_tmpdir_and_scratchdir
     550    system(g_erase_tmpdir_and_scratchdir);
     551    free_libmondo_global_strings();
     552    paranoid_free(say_at_end);
     553    paranoid_free(tmp);
     554    paranoid_free(bkpinfo);
     555
     556    unlink("/tmp/filelist.full");
     557    unlink("/tmp/filelist.full.gz");
     558
     559    if (!g_cdrom_drive_is_here) {
     560        log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
     561    }
     562    if (!g_dvd_drive_is_here) {
     563        log_msg(10, "FYI, g_dvd_drive_is_here was never used");
     564    }
     565
     566    if (!g_text_mode) {
     567        popup_and_OK
     568            ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
     569        log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
     570        finish(retval);
     571    } else {
     572        printf("See %s for details of backup run.\n", MONDO_LOGFILE);
     573        exit(retval);
     574    }
     575
     576    return EXIT_SUCCESS;
    565577}
    566 
    567 
  • branches/2.05/mondo/mondo/mondoarchive/mondo-cli-EXT.h

    r30 r128  
    11/* mondo-cli-EXT.h */
    22
    3 extern int handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo);
     3extern int handle_incoming_parameters(int argc, char *argv[],
     4                                      struct s_bkpinfo *bkpinfo);
    45extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value);
    5 extern int process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN],
    6           bool flag_set[128]);
    7 extern int retrieve_switches_from_command_line (int argc, char *argv[],
    8                      char flag_val[128][MAX_STR_LEN],
    9                      bool flag_set[128]);
    10 extern void help_screen ();
     6extern int process_switches(struct s_bkpinfo *bkpinfo,
     7                            char flag_val[128][MAX_STR_LEN],
     8                            bool flag_set[128]);
     9extern int retrieve_switches_from_command_line(int argc, char *argv[],
     10                                               char
     11                                               flag_val[128][MAX_STR_LEN],
     12                                               bool flag_set[128]);
     13extern void help_screen();
    1114extern void terminate_daemon(int sig);
    1215extern void set_signals(int on);
    1316extern void termination_in_progress(int sig);
    14 
  • branches/2.05/mondo/mondo/mondoarchive/mondo-cli.h

    r30 r128  
    11/* mondo-cli.h
    2  * $Id: mondo-cli.h,v 1.2 2004/06/10 15:29:13 hugo Exp $
     2 * $Id$
    33 */
    44
    5 int handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo);
     5int handle_incoming_parameters(int argc, char *argv[],
     6                               struct s_bkpinfo *bkpinfo);
    67int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value);
    7 int process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN],
    8           bool flag_set[128]);
    9 int retrieve_switches_from_command_line (int argc, char *argv[],
    10                      char flag_val[128][MAX_STR_LEN],
    11                      bool flag_set[128]);
    12 void help_screen ();
     8int process_switches(struct s_bkpinfo *bkpinfo,
     9                     char flag_val[128][MAX_STR_LEN], bool flag_set[128]);
     10int retrieve_switches_from_command_line(int argc, char *argv[],
     11                                        char flag_val[128][MAX_STR_LEN],
     12                                        bool flag_set[128]);
     13void help_screen();
    1314void terminate_daemon(int sig);
    1415void set_signals(int on);
    1516void termination_in_progress(int sig);
    16 
    17 
  • branches/2.05/mondo/mondo/mondorestore/mondo-prep.c

    r126 r128  
    188188extern bool g_text_mode;
    189189
    190 extern void pause_for_N_seconds(int, char*);
    191 
    192 
    193 FILE *g_fprep=NULL;
    194 
    195 
    196 
    197 int g_partition_table_locked_up=0;
     190extern void pause_for_N_seconds(int, char *);
     191
     192
     193FILE *g_fprep = NULL;
     194
     195
     196
     197int g_partition_table_locked_up = 0;
    198198
    199199
     
    208208void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist)
    209209{
    210     char *command;
    211     char *tmp;
    212     int lino;
    213     int i;
    214     FILE*fout;
    215     char *buf;
    216     const int blocksize=512;       
    217         struct list_of_disks *drivelist=NULL;
     210    char *command;
     211    char *tmp;
     212    int lino;
     213    int i;
     214    FILE *fout;
     215    char *buf;
     216    const int blocksize = 512;
     217    struct list_of_disks *drivelist = NULL;
    218218// If LVMs are present and a zero-and-reboot wasn't recently undertaken
    219219// then zero & insist on reboot.
    220     malloc_string(command);
    221     malloc_string(tmp);
    222     buf = malloc(blocksize);
    223         if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :)
    224       {
    225         drivelist = malloc(sizeof(struct list_of_disks));
    226         make_list_of_drives_in_mountlist(mountlist, drivelist);
    227         for (lino = 0; lino < drivelist->entries; lino++)
    228           {
    229             sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", drivelist->el[lino].device, MONDO_WAS_HERE);
    230             if (!run_program_and_log_output(command, 1))
    231           {
    232             log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", lino, drivelist->el[lino].device);
    233             break;
    234           }
    235               }
    236        
    237         if (lino==drivelist->entries)
    238           {
     220    malloc_string(command);
     221    malloc_string(tmp);
     222    buf = malloc(blocksize);
     223    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
     224    {
     225        drivelist = malloc(sizeof(struct list_of_disks));
     226        make_list_of_drives_in_mountlist(mountlist, drivelist);
     227        for (lino = 0; lino < drivelist->entries; lino++) {
     228            sprintf(command,
     229                    "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
     230                    drivelist->el[lino].device, MONDO_WAS_HERE);
     231            if (!run_program_and_log_output(command, 1)) {
     232                log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)",
     233                        lino, drivelist->el[lino].device);
     234                break;
     235            }
     236        }
     237
     238        if (lino == drivelist->entries) {
    239239// zero & reboot
    240             log_to_screen("I am sorry for the inconvenience but I must ask you to reboot.");
    241         log_to_screen("I need to reset the Master Boot Record; in order to be");
    242         log_to_screen("sure the kernel notices, I must reboot after doing it.");
    243         log_to_screen("Please hit 'Enter' to reboot.");
    244             for (lino = 0; lino < drivelist->entries; lino++)
    245               {
    246             for(i=0;i<blocksize; i++)
    247               { buf[i] = 0; }
    248             sprintf(buf, "%s\n", MONDO_WAS_HERE);
    249             fout = fopen(drivelist->el[lino].device, "w+");
    250             if (!fout)
    251               {
    252                 log_msg(1, "Unable to open+wipe %s", drivelist->el[lino].device);
    253               }
    254             else
    255               {
    256                 if (1!=fwrite(buf, blocksize, 1, fout))
    257               {
    258                 log_msg(1, "Failed to wipe %s", drivelist->el[lino].device);
    259               }
    260             else
    261               {
    262                 log_msg(1, "Successfully wiped %s", drivelist->el[lino].device);
    263               }
    264                 fclose(fout);
    265                   }
    266           }
    267                 system("sync"); system("sync"); system("sync");
    268         popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
    269                 system("reboot");
    270           }
    271           }
    272      
     240            log_to_screen
     241                ("I am sorry for the inconvenience but I must ask you to reboot.");
     242            log_to_screen
     243                ("I need to reset the Master Boot Record; in order to be");
     244            log_to_screen
     245                ("sure the kernel notices, I must reboot after doing it.");
     246            log_to_screen("Please hit 'Enter' to reboot.");
     247            for (lino = 0; lino < drivelist->entries; lino++) {
     248                for (i = 0; i < blocksize; i++) {
     249                    buf[i] = 0;
     250                }
     251                sprintf(buf, "%s\n", MONDO_WAS_HERE);
     252                fout = fopen(drivelist->el[lino].device, "w+");
     253                if (!fout) {
     254                    log_msg(1, "Unable to open+wipe %s",
     255                            drivelist->el[lino].device);
     256                } else {
     257                    if (1 != fwrite(buf, blocksize, 1, fout)) {
     258                        log_msg(1, "Failed to wipe %s",
     259                                drivelist->el[lino].device);
     260                    } else {
     261                        log_msg(1, "Successfully wiped %s",
     262                                drivelist->el[lino].device);
     263                    }
     264                    fclose(fout);
     265                }
     266            }
     267            system("sync");
     268            system("sync");
     269            system("sync");
     270            popup_and_OK
     271                ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
     272            system("reboot");
     273        }
     274    }
    273275// Still here? Cool!
    274   paranoid_free(command);
    275   paranoid_free(tmp);
    276   log_msg(1, "Cool. I didn't have to wipe anything.");
     276    paranoid_free(command);
     277    paranoid_free(tmp);
     278    log_msg(1, "Cool. I didn't have to wipe anything.");
    277279}
    278280
     
    282284
    283285
    284 int fput_string_one_char_at_a_time(FILE*fout, char*str)
     286int fput_string_one_char_at_a_time(FILE * fout, char *str)
    285287{
    286   int i, j;
    287   FILE*fq;
    288 
    289   if (ferror(fout))
    290     {
    291     return(-1);
    292     }
    293   log_msg(5, "Writing string '%s', one char at a time", str);
    294   j = strlen(str);
    295   for(i=0; i<j; i++)
    296     {
    297       log_msg(6, "Writing %d ('%c')", str[i], str[i]);
    298       if ((fq = fopen(FDISK_LOG, "a+"))) { fputc(str[i], fq);fclose(fq); }
    299       fputc(str[i], fout);
    300       fflush(fout);
    301       usleep(1000L*100L);
    302       if (str[i]<32) { usleep(1000L*10L); }
    303     }
    304   log_msg(5, "Returning");
    305    
    306    return(i);
     288    int i, j;
     289    FILE *fq;
     290
     291    if (ferror(fout)) {
     292        return (-1);
     293    }
     294    log_msg(5, "Writing string '%s', one char at a time", str);
     295    j = strlen(str);
     296    for (i = 0; i < j; i++) {
     297        log_msg(6, "Writing %d ('%c')", str[i], str[i]);
     298        if ((fq = fopen(FDISK_LOG, "a+"))) {
     299            fputc(str[i], fq);
     300            fclose(fq);
     301        }
     302        fputc(str[i], fout);
     303        fflush(fout);
     304        usleep(1000L * 100L);
     305        if (str[i] < 32) {
     306            usleep(1000L * 10L);
     307        }
     308    }
     309    log_msg(5, "Returning");
     310
     311    return (i);
    307312}
    308313
     
    325330 * @return The number of errors encountered (0 for success).
    326331 */
    327  
    328 
    329 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, bool vacuum_pack)
     332
     333
     334int do_my_funky_lvm_stuff(bool just_erase_existing_volumes,
     335                          bool vacuum_pack)
    330336{
    331337    /**  buffers **********************************************/
     
    340346    char *vgchange_sz;
    341347    char *vgremove_sz;
    342 //  char *do_this_last;
     348//  char *do_this_last;
    343349
    344350    /** char **************************************************/
     
    353359    long extents;
    354360    fpos_t orig_pos;
    355    
     361
    356362    /** pointers **********************************************/
    357363    FILE *fin;
     
    377383    malloc_string(vgchange_sz);
    378384    malloc_string(vgremove_sz);
    379 //  malloc_string(do_this_last); // postpone lvcreate call if necessary
     385//  malloc_string(do_this_last); // postpone lvcreate call if necessary
    380386    command = malloc(512);
    381387
    382 //  do_this_last[0] = '\0';
    383 iamhere("STARTING");
     388//  do_this_last[0] = '\0';
     389    iamhere("STARTING");
    384390    log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes...");
    385     if (find_home_of_exe("lvm")) // found it :) cool
    386       {
    387         strcpy(lvscan_sz,   "lvm lvscan");
    388         strcpy(lvremove_sz, "lvm lvremove");
    389         strcpy(vgscan_sz,   "lvm vgscan");
    390         strcpy(pvscan_sz,   "lvm pvscan");
    391         strcpy(vgcreate_sz, "lvm vgcreate");
    392         strcpy(vgchange_sz, "lvm vgchange");
    393         strcpy(vgremove_sz, "lvm vgremove");
    394       }
    395     else
    396       {
    397         strcpy(lvscan_sz,   "lvscan");
    398         strcpy(lvremove_sz, "lvremove");
    399         strcpy(vgscan_sz,   "vgscan");
    400         strcpy(pvscan_sz,   "pvscan");
    401         strcpy(vgcreate_sz, "vgcreate");
    402         strcpy(vgchange_sz, "vgchange");
    403         strcpy(vgremove_sz, "vgremove");
    404       }
    405     sprintf(command, "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " MONDO_LOGFILE "; %s -f $i; done",
    406                     lvscan_sz, lvremove_sz);
     391    if (find_home_of_exe("lvm"))    // found it :) cool
     392    {
     393        strcpy(lvscan_sz, "lvm lvscan");
     394        strcpy(lvremove_sz, "lvm lvremove");
     395        strcpy(vgscan_sz, "lvm vgscan");
     396        strcpy(pvscan_sz, "lvm pvscan");
     397        strcpy(vgcreate_sz, "lvm vgcreate");
     398        strcpy(vgchange_sz, "lvm vgchange");
     399        strcpy(vgremove_sz, "lvm vgremove");
     400    } else {
     401        strcpy(lvscan_sz, "lvscan");
     402        strcpy(lvremove_sz, "lvremove");
     403        strcpy(vgscan_sz, "vgscan");
     404        strcpy(pvscan_sz, "pvscan");
     405        strcpy(vgcreate_sz, "vgcreate");
     406        strcpy(vgchange_sz, "vgchange");
     407        strcpy(vgremove_sz, "vgremove");
     408    }
     409    sprintf(command,
     410            "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> "
     411            MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz);
    407412    run_program_and_log_output(command, 5);
    408413    sleep(1);
    409     sprintf(command, "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, vgremove_sz, vgremove_sz);
     414    sprintf(command,
     415            "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> "
     416            MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz,
     417            vgremove_sz, vgremove_sz);
    410418    run_program_and_log_output(command, 5);
    411419    if (just_erase_existing_volumes) {
    412420        paranoid_fclose(fin);
    413421        log_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs.");
    414         retval=0;
     422        retval = 0;
    415423        goto end_of_i_want_my_lvm;
    416424    }
     
    423431            continue;
    424432        }
    425         if (res && strstr(command, "create") && vacuum_pack)
    426           {
    427             sleep(2);
    428             system("sync"); system("sync"); system("sync");
    429           }
    430         if ((p=strstr(incoming, "vgcreate")))
    431           {
     433        if (res && strstr(command, "create") && vacuum_pack) {
     434            sleep(2);
     435            system("sync");
     436            system("sync");
     437            system("sync");
     438        }
     439        if ((p = strstr(incoming, "vgcreate"))) {
    432440// include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    433             for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {
    434             if (tmp[0] == '#') {
    435                 fsetpos(fin, &orig_pos);
    436                 break;
    437             } else {
    438                 fgetpos(fin, &orig_pos);
    439                 strcat(incoming, tmp);
    440             }
    441             }
    442             for(q=incoming; *q!='\0'; q++)
    443               {
    444                 if (*q<32) { *q=' '; }
    445               }
    446             strcpy(tmp, p+strlen("vgcreate")+1);
    447             for(q=tmp; *q>32; q++);
    448             *q = '\0';
    449                log_msg(1, "Deleting old entries at /dev/%s", tmp);
    450 //             sprintf(command, "%s -f %s", vgremove_sz, tmp);
    451 //             run_program_and_log_output(command, 1);
    452                sprintf(command, "rm -Rf /dev/%s", tmp);
    453                run_program_and_log_output(command, 1);
    454             run_program_and_log_output(vgscan_sz, 1);
    455             run_program_and_log_output(pvscan_sz, 1);
    456             log_msg(3, "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", incoming);
    457           }
     441            for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {
     442                if (tmp[0] == '#') {
     443                    fsetpos(fin, &orig_pos);
     444                    break;
     445                } else {
     446                    fgetpos(fin, &orig_pos);
     447                    strcat(incoming, tmp);
     448                }
     449            }
     450            for (q = incoming; *q != '\0'; q++) {
     451                if (*q < 32) {
     452                    *q = ' ';
     453                }
     454            }
     455            strcpy(tmp, p + strlen("vgcreate") + 1);
     456            for (q = tmp; *q > 32; q++);
     457            *q = '\0';
     458            log_msg(1, "Deleting old entries at /dev/%s", tmp);
     459//             sprintf(command, "%s -f %s", vgremove_sz, tmp);
     460//             run_program_and_log_output(command, 1);
     461            sprintf(command, "rm -Rf /dev/%s", tmp);
     462            run_program_and_log_output(command, 1);
     463            run_program_and_log_output(vgscan_sz, 1);
     464            run_program_and_log_output(pvscan_sz, 1);
     465            log_msg(3,
     466                    "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'",
     467                    incoming);
     468        }
    458469        for (p = incoming + 1; *p == ' '; p++);
    459470        strcpy(command, p);
     
    462473        *p = '\0';
    463474        res = run_program_and_log_output(command, 5);
    464         if (res>0 && (p=strstr(command, "lvm ")))
    465           {
    466             *p = *(p+1) = *(p+2) = ' ';
    467             res = run_program_and_log_output(command, 5);
    468           }
     475        if (res > 0 && (p = strstr(command, "lvm "))) {
     476            *p = *(p + 1) = *(p + 2) = ' ';
     477            res = run_program_and_log_output(command, 5);
     478        }
    469479        log_msg(0, "%s --> %d", command, res);
    470                 if (res>0) {res=1;}
    471         if (res && strstr(command, "lvcreate") && vacuum_pack)
    472           {
    473             res=0;
    474             if (strstr(command, "lvm lvcreate"))
    475             lvmversion = 2;
    476             log_it("%s... so I'll get creative.", tmp);
    477             if (lvmversion == 2)
    478               {
    479                 strcpy(tmp, call_program_and_get_last_line_of_output
    480                     ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1"));
    481               }
    482             else
    483               {
    484                 strcpy(tmp, call_program_and_get_last_line_of_output
    485                     ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1"));
    486               }
    487             for(p=tmp; *p!='\0' && !isdigit(*p); p++);
    488             extents = atol(p);
    489             log_msg(5, "p='%s' --> extents=%ld", p, extents);
    490             p = strstr(command, "-L");
    491             if (!p)
    492               {
    493                 log_msg(0, "Fiddlesticks. '%s' returned %d", command, res);
    494               }
    495             else
    496               {
    497             if (lvmversion == 2)
    498               {
    499                 *p++ = '-'; *p++ = 'l'; *p++ = ' ';
    500                 for(q=p; *q!=' '; q++) { *q = ' '; }
    501                 sprintf(p, "%ld", extents);
    502                 i = strlen(p);
    503                 *(p+i) = ' ';
    504               }
    505             else
    506               {
    507                 p++; p++; p++;
    508                 for(q=p; *q!=' '; q++) { *(q-1) = ' '; }
    509                 sprintf(p, "%ld%c", extents, 'm');
    510                 i = strlen(p);
    511                 *(p+i) = ' ';
    512               }
    513                 log_msg(5, "Retrying with '%s'", command);
    514                 res = run_program_and_log_output(command, 5);
    515             if (res>0) { res=1; }
    516             if (g_fprep) { fprintf(g_fprep, "%s\n", command); }
    517                 log_msg(0, "%s --> %d", command, res);
    518             if (!res)
    519               {
    520                 log_msg(5, "YAY! This time, it succeeded.");
    521               }
    522               }
    523           }
    524         if (strstr(command, "vgcreate"))
    525           {
    526             log_msg(0, "In case you're interested...");
    527             run_program_and_log_output(vgscan_sz, 1);
    528             run_program_and_log_output(pvscan_sz, 1);
    529           }
    530                 if (res!=0 && !strstr(command, "insmod")) {
    531             retval ++;
     480        if (res > 0) {
     481            res = 1;
     482        }
     483        if (res && strstr(command, "lvcreate") && vacuum_pack) {
     484            res = 0;
     485            if (strstr(command, "lvm lvcreate"))
     486                lvmversion = 2;
     487            log_it("%s... so I'll get creative.", tmp);
     488            if (lvmversion == 2) {
     489                strcpy(tmp, call_program_and_get_last_line_of_output
     490                       ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1"));
     491            } else {
     492                strcpy(tmp, call_program_and_get_last_line_of_output
     493                       ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1"));
     494            }
     495            for (p = tmp; *p != '\0' && !isdigit(*p); p++);
     496            extents = atol(p);
     497            log_msg(5, "p='%s' --> extents=%ld", p, extents);
     498            p = strstr(command, "-L");
     499            if (!p) {
     500                log_msg(0, "Fiddlesticks. '%s' returned %d", command, res);
     501            } else {
     502                if (lvmversion == 2) {
     503                    *p++ = '-';
     504                    *p++ = 'l';
     505                    *p++ = ' ';
     506                    for (q = p; *q != ' '; q++) {
     507                        *q = ' ';
     508                    }
     509                    sprintf(p, "%ld", extents);
     510                    i = strlen(p);
     511                    *(p + i) = ' ';
     512                } else {
     513                    p++;
     514                    p++;
     515                    p++;
     516                    for (q = p; *q != ' '; q++) {
     517                        *(q - 1) = ' ';
     518                    }
     519                    sprintf(p, "%ld%c", extents, 'm');
     520                    i = strlen(p);
     521                    *(p + i) = ' ';
     522                }
     523                log_msg(5, "Retrying with '%s'", command);
     524                res = run_program_and_log_output(command, 5);
     525                if (res > 0) {
     526                    res = 1;
     527                }
     528                if (g_fprep) {
     529                    fprintf(g_fprep, "%s\n", command);
     530                }
     531                log_msg(0, "%s --> %d", command, res);
     532                if (!res) {
     533                    log_msg(5, "YAY! This time, it succeeded.");
     534                }
     535            }
     536        }
     537        if (strstr(command, "vgcreate")) {
     538            log_msg(0, "In case you're interested...");
     539            run_program_and_log_output(vgscan_sz, 1);
     540            run_program_and_log_output(pvscan_sz, 1);
     541        }
     542        if (res != 0 && !strstr(command, "insmod")) {
     543            retval++;
    532544        }
    533545        sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command);
     
    537549    paranoid_fclose(fin);
    538550    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
    539 end_of_i_want_my_lvm:
     551  end_of_i_want_my_lvm:
    540552    paranoid_free(tmp);
    541553    paranoid_free(incoming);
     
    548560    paranoid_free(vgchange_sz);
    549561    paranoid_free(vgremove_sz);
    550 //  paranoid_free(do_this_last);
    551     system("sync"); system("sync"); system("sync");
     562//  paranoid_free(do_this_last);
     563    system("sync");
     564    system("sync");
     565    system("sync");
    552566    sleep(1);
    553 iamhere("ENDING");
    554     if (retval>2)
    555       {
    556         log_msg(1, "%d errors. I'm reporting this.", retval);
    557         return(retval);
    558       }
    559     else
    560       {
    561         log_msg(1, "Not many errors. Returning 0.");
    562         return(0);
    563       }
     567    iamhere("ENDING");
     568    if (retval > 2) {
     569        log_msg(1, "%d errors. I'm reporting this.", retval);
     570        return (retval);
     571    } else {
     572        log_msg(1, "Not many errors. Returning 0.");
     573        return (0);
     574    }
    564575}
    565576
     
    574585 * @return 0 for success, nonzero for failure.
    575586 */
    576     int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself
    577                             *new_mountlist, struct mountlist_itself
    578                             *old_mountlist)
     587int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself
     588                                                    *new_mountlist, struct mountlist_itself
     589                                                    *old_mountlist)
    579590{
    580591    /** pointers *********************************************************/
     
    603614
    604615#ifdef __FreeBSD__
    605     log_to_screen ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
    606     return(1);
     616    log_to_screen
     617        ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
     618    return (1);
    607619#endif
    608620
     
    611623        {
    612624            if (!does_file_exist("/etc/raidtab")) {
    613                 log_to_screen("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries");
     625                log_to_screen
     626                    ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries");
    614627                finish(1);
    615628            }
     
    619632            }
    620633            for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
    621                  && !strstr(incoming, old_mountlist->el[lino].device); fgets(incoming, MAX_STR_LEN - 1, fin));
     634                 && !strstr(incoming, old_mountlist->el[lino].device);
     635                 fgets(incoming, MAX_STR_LEN - 1, fin));
    622636            if (!feof(fin)) {
    623                 sprintf(tmp, "Investigating %s", old_mountlist->el[lino].device);
     637                sprintf(tmp, "Investigating %s",
     638                        old_mountlist->el[lino].device);
    624639                log_it(tmp);
    625640                for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
    626                      && !strstr(incoming, "raiddev"); fgets(incoming, MAX_STR_LEN - 1, fin)) {
     641                     && !strstr(incoming, "raiddev");
     642                     fgets(incoming, MAX_STR_LEN - 1, fin)) {
    627643                    if (strstr(incoming, OSSWAP("device", "drive"))
    628                         && !strchr(incoming, '#')) {
    629                         for (p = incoming + strlen(incoming); *(p - 1) <= 32; p--);
     644                        && !strchr(incoming, '#')) {
     645                        for (p = incoming + strlen(incoming);
     646                             *(p - 1) <= 32; p--);
    630647                        *p = '\0';
    631648                        for (p--; p > incoming && *(p - 1) > 32; p--);
    632649                        sprintf(tmp, "Extrapolating %s", p);
    633650                        log_it(tmp);
    634                         for (j = 0; j < new_mountlist->entries && strcmp(new_mountlist->el[j].device, p);
    635                              j++);
     651                        for (j = 0;
     652                             j < new_mountlist->entries
     653                             && strcmp(new_mountlist->el[j].device, p);
     654                             j++);
    636655                        if (j >= new_mountlist->entries) {
    637                             strcpy(new_mountlist->el[new_mountlist->entries].device, p);
    638                             strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, "raid");
    639                             strcpy(new_mountlist->el[new_mountlist->entries].format, "raid");
    640                             new_mountlist->el[new_mountlist->entries].size =
    641                                 old_mountlist->el[lino].size;
     656                            strcpy(new_mountlist->
     657                                   el[new_mountlist->entries].device, p);
     658                            strcpy(new_mountlist->
     659                                   el[new_mountlist->entries].mountpoint,
     660                                   "raid");
     661                            strcpy(new_mountlist->
     662                                   el[new_mountlist->entries].format,
     663                                   "raid");
     664                            new_mountlist->el[new_mountlist->entries].
     665                                size = old_mountlist->el[lino].size;
    642666                            new_mountlist->entries++;
    643667                        } else {
    644                             sprintf(tmp, "Not adding %s to mountlist: it's already there", p);
     668                            sprintf(tmp,
     669                                    "Not adding %s to mountlist: it's already there",
     670                                    p);
    645671                            log_it(tmp);
    646672                        }
     
    650676            paranoid_fclose(fin);
    651677        } else {
    652             strcpy(new_mountlist->el[new_mountlist->entries].device, old_mountlist->el[lino].device);
    653             strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, old_mountlist->el[lino].mountpoint);
    654             strcpy(new_mountlist->el[new_mountlist->entries].format, old_mountlist->el[lino].format);
    655             new_mountlist->el[new_mountlist->entries].size = old_mountlist->el[lino].size;
     678            strcpy(new_mountlist->el[new_mountlist->entries].device,
     679                   old_mountlist->el[lino].device);
     680            strcpy(new_mountlist->el[new_mountlist->entries].mountpoint,
     681                   old_mountlist->el[lino].mountpoint);
     682            strcpy(new_mountlist->el[new_mountlist->entries].format,
     683                   old_mountlist->el[lino].format);
     684            new_mountlist->el[new_mountlist->entries].size =
     685                old_mountlist->el[lino].size;
    656686            new_mountlist->entries++;
    657687        }
     
    697727        sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);
    698728        log_it(tmp);
    699         paranoid_free(program); paranoid_free(tmp);
     729        paranoid_free(program);
     730        paranoid_free(tmp);
    700731        return (0);
    701732    }
     
    703734    if (strcmp(format, "swap") == 0) {
    704735        log_it("Not formatting %s - it's swap", device);
    705         paranoid_free(program); paranoid_free(tmp);
     736        paranoid_free(program);
     737        paranoid_free(tmp);
    706738        return (0);
    707739    }
     
    709741    if (strlen(format) <= 2) {
    710742        sprintf(tmp,
    711             "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
    712             device, format);
     743                "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
     744                device, format);
    713745        log_it(tmp);
    714         paranoid_free(program); paranoid_free(tmp);
     746        paranoid_free(program);
     747        paranoid_free(tmp);
    715748        return (0);
    716749    }
     
    718751        sprintf(tmp, "%s is mounted - cannot format it       ", device);
    719752        log_to_screen(tmp);
    720         paranoid_free(program); paranoid_free(tmp);
     753        paranoid_free(program);
     754        paranoid_free(tmp);
    721755        return (1);
    722756    }
     
    726760        if (!vinum_started_yet) {
    727761            if (!does_file_exist("/tmp/raidconf.txt")) {
    728                 log_to_screen("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.");
     762                log_to_screen
     763                    ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.");
    729764            } else {
    730765                int res;
    731                 res = run_program_and_log_output("vinum create /tmp/raidconf.txt", TRUE);
     766                res =
     767                    run_program_and_log_output
     768                    ("vinum create /tmp/raidconf.txt", TRUE);
    732769                if (res) {
    733770                    log_to_screen
    734                         ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.");
     771                        ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.");
    735772                    finish(1);
    736773                }
     
    742779            FILE *fin;
    743780            char line[MAX_STR_LEN];
    744             sprintf(tmp, "Initializing Vinum device %s (this may take a *long* time)", device);
     781            sprintf(tmp,
     782                    "Initializing Vinum device %s (this may take a *long* time)",
     783                    device);
    745784            log_to_screen(tmp);
    746785            /* format raid partition */
    747786            //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
    748787            sprintf(program,
    749                 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
    750                 basename(device));
     788                    "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
     789                    basename(device));
    751790            system(program);
    752             if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     791            if (g_fprep) {
     792                fprintf(g_fprep, "%s\n", program);
     793            }
    753794            fin = fopen("/tmp/plexes", "r");
    754795            while (fgets(line, MAX_STR_LEN - 1, fin)) {
     
    762803                while (1) {
    763804                    sprintf(tmp,
    764                         "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    765                         line);
     805                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
     806                            line);
    766807                    FILE *pin = popen(tmp, "r");
    767808                    char status[MAX_STR_LEN / 4];
     
    788829        log_to_screen("Stopping %s", device);
    789830        stop_raid_device(device);
    790         system("sync"); sleep(1);
    791         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     831        system("sync");
     832        sleep(1);
     833        if (g_fprep) {
     834            fprintf(g_fprep, "%s\n", program);
     835        }
    792836
    793837        log_msg(1, "Making %s", device);
     
    795839        res = run_program_and_log_output(program, 1);
    796840        log_msg(1, "%s returned %d", program, res);
    797         system("sync"); sleep(3);
     841        system("sync");
     842        sleep(3);
    798843        start_raid_device(device);
    799         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    800         system("sync"); sleep(2);
    801        
    802 //      log_to_screen("Starting %s", device);
    803 //      sprintf(program, "raidstart %s", device);
    804 //      res = run_program_and_log_output(program, 1);
    805 //      log_msg(1, "%s returned %d", program, res);
    806 //      system("sync"); sleep(1);
    807         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    808 
    809 #endif
    810         system("sync"); sleep(1);
     844        if (g_fprep) {
     845            fprintf(g_fprep, "%s\n", program);
     846        }
     847        system("sync");
     848        sleep(2);
     849
     850//      log_to_screen("Starting %s", device);
     851//      sprintf(program, "raidstart %s", device);
     852//      res = run_program_and_log_output(program, 1);
     853//      log_msg(1, "%s returned %d", program, res);
     854//      system("sync"); sleep(1);
     855        if (g_fprep) {
     856            fprintf(g_fprep, "%s\n", program);
     857        }
     858#endif
     859        system("sync");
     860        sleep(1);
    811861        newtResume();
    812862    }
     
    814864//#endif
    815865
    816     if (!strcmp(format, "lvm"))
    817       {
    818         log_msg(1, "Don't format %s - it's part of an lvm volume", device);
    819         paranoid_free(program); paranoid_free(tmp);
    820         return(0);
    821       }
     866    if (!strcmp(format, "lvm")) {
     867        log_msg(1, "Don't format %s - it's part of an lvm volume", device);
     868        paranoid_free(program);
     869        paranoid_free(tmp);
     870        return (0);
     871    }
    822872    res = which_format_command_do_i_need(format, program);
    823873    sprintf(tmp, "%s %s", program, device);
     
    830880    res = run_program_and_log_output(program, FALSE);
    831881    if (res && strstr(program, "kludge")) {
    832         sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", format, device);
     882        sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",
     883                format, device);
    833884#ifdef __FreeBSD__
    834885        sprintf(program, "newfs_msdos -F 32 %s", device);
     
    843894#endif
    844895        res = run_program_and_log_output(program, FALSE);
    845         if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
     896        if (g_fprep) {
     897            fprintf(g_fprep, "%s\n", program);
     898        }
    846899    }
    847900    retval += res;
     
    853906
    854907    log_to_screen(tmp);
    855     paranoid_free(program); paranoid_free(tmp);
    856     system("sync"); sleep(1);
     908    paranoid_free(program);
     909    paranoid_free(tmp);
     910    system("sync");
     911    sleep(1);
    857912    return (retval);
    858913}
     
    868923 * @return The number of errors encountered (0 for success).
    869924 */
    870 int format_everything(struct mountlist_itself *mountlist, bool interactively)
     925int format_everything(struct mountlist_itself *mountlist,
     926                      bool interactively)
    871927{
    872928    /** int **************************************************************/
     
    874930    int lino;
    875931    int res;
    876 //  int i;
    877 //  struct list_of_disks *drivelist;
     932//  int i;
     933//  struct list_of_disks *drivelist;
    878934
    879935    /** long *************************************************************/
     
    890946    /** end **************************************************************/
    891947
    892     assert(mountlist!=NULL);
     948    assert(mountlist != NULL);
    893949    malloc_string(tmp);
    894     sprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false");
     950    sprintf(tmp, "format_everything (mountlist, interactively = %s",
     951            (interactively) ? "true" : "false");
    895952    log_it(tmp);
    896953    mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
    897     open_progress_form("Formatting partitions", "I am now formatting your hard disk partitions.",
    898                "This may take up to five minutes.", "", mountlist->entries + 1);
    899 
    900     progress_step = (mountlist->entries > 0) ? g_maximum_progress / mountlist->entries : 1;
     954    open_progress_form("Formatting partitions",
     955                       "I am now formatting your hard disk partitions.",
     956                       "This may take up to five minutes.", "",
     957                       mountlist->entries + 1);
     958
     959    progress_step =
     960        (mountlist->entries >
     961         0) ? g_maximum_progress / mountlist->entries : 1;
    901962// start soft-raids now (because LVM might depend on them)
    902963// ...and for simplicity's sake, let's format them at the same time :)
    903964    log_msg(1, "Stopping all RAID devices");
    904965    stop_all_raid_devices(mountlist);
    905     system("sync"); system("sync"); system("sync");
     966    system("sync");
     967    system("sync");
     968    system("sync");
    906969    sleep(2);
    907     log_msg(1, "Prepare soft-RAIDs"); // prep and format too
     970    log_msg(1, "Prepare soft-RAIDs");   // prep and format too
    908971    for (lino = 0; lino < mountlist->entries; lino++) {
    909972        me = &mountlist->el[lino];  // the current mountlist entry
     
    912975            if (interactively) {
    913976                // ask user if we should format the current device
    914                 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint);
     977                sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     978                        me->mountpoint);
    915979                do_it = ask_me_yes_or_no(tmp);
    916980            } else {
     
    918982            }
    919983            if (do_it) {
    920             // NB: format_device() also stops/starts RAID device if necessary
     984                // NB: format_device() also stops/starts RAID device if necessary
    921985                retval += format_device(me->device, me->format);
    922986            }
     
    924988        }
    925989    }
    926     system("sync"); system("sync"); system("sync");
     990    system("sync");
     991    system("sync");
     992    system("sync");
    927993    sleep(2);
    928994// This last step is probably necessary
    929 //  log_to_screen("Re-starting software RAIDs...");
    930 //  start_all_raid_devices(mountlist);
    931 //  system("sync"); system("sync"); system("sync");
    932 //  sleep(5);
     995//  log_to_screen("Re-starting software RAIDs...");
     996//  start_all_raid_devices(mountlist);
     997//  system("sync"); system("sync"); system("sync");
     998//  sleep(5);
    933999// do LVMs now
    9341000    log_msg(1, "Creating LVMs");
     
    9361002        wait_until_software_raids_are_prepped("/proc/mdstat", 10);
    9371003        log_to_screen("Configuring LVM");
    938                 if (!g_text_mode) { newtSuspend(); }
     1004        if (!g_text_mode) {
     1005            newtSuspend();
     1006        }
    9391007/*
    9401008        for(i=0; i<3; i++)
     
    9491017            log_msg(1, "Vacuum-packing...");
    9501018*/
    951             res = do_my_funky_lvm_stuff(FALSE, TRUE);
     1019        res = do_my_funky_lvm_stuff(FALSE, TRUE);
    9521020/*
    9531021        }
    9541022*/
    955                 if (!g_text_mode) { newtResume(); }
    956         if (!res) { log_to_screen("LVM initialized OK"); }
    957         else { log_to_screen("Failed to initialize LVM"); }
     1023        if (!g_text_mode) {
     1024            newtResume();
     1025        }
     1026        if (!res) {
     1027            log_to_screen("LVM initialized OK");
     1028        } else {
     1029            log_to_screen("Failed to initialize LVM");
     1030        }
    9581031        // retval += res;
    9591032        if (res) {
    960             retval ++;
    961         }
    962         sleep(3);
    963     }
    964 
     1033            retval++;
     1034        }
     1035        sleep(3);
     1036    }
    9651037// do regulars at last
    966     sleep(2); // woo!
    967         log_msg(1, "Formatting regulars");
     1038    sleep(2);                   // woo!
     1039    log_msg(1, "Formatting regulars");
    9681040    for (lino = 0; lino < mountlist->entries; lino++) {
    9691041        me = &mountlist->el[lino];  // the current mountlist entry
     
    9721044            log_it(tmp);
    9731045        } else if (!strcmp(me->format, "raid")) {
    974             sprintf(tmp, "Not formatting %s - it's a raid-let", me->device);
     1046            sprintf(tmp, "Not formatting %s - it's a raid-let",
     1047                    me->device);
    9751048            log_it(tmp);
    9761049            continue;
     
    9801053            continue;
    9811054        } else if (!strncmp(me->device, "/dev/md", 7)) {
    982             sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", me->device);
     1055            sprintf(tmp, "Already formatted %s - it's a soft-RAID dev",
     1056                    me->device);
    9831057            log_it(tmp);
    9841058            continue;
    9851059        } else if (!does_file_exist(me->device)
    986                     && strncmp(me->device, "/dev/hd", 7)
    987                     && strncmp(me->device, "/dev/sd", 7)) {
    988             sprintf(tmp, "Not formatting %s yet - doesn't exist - probably an LVM", me->device);
     1060                   && strncmp(me->device, "/dev/hd", 7)
     1061                   && strncmp(me->device, "/dev/sd", 7)) {
     1062            sprintf(tmp,
     1063                    "Not formatting %s yet - doesn't exist - probably an LVM",
     1064                    me->device);
    9891065            log_it(tmp);
    9901066            continue;
     
    9921068            if (interactively) {
    9931069                // ask user if we should format the current device
    994                 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint);
     1070                sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     1071                        me->mountpoint);
    9951072                do_it = ask_me_yes_or_no(tmp);
    9961073            } else {
     
    10161093    if (retval) {
    10171094        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1018         log_to_screen("Errors occurred during the formatting of your hard drives.");
     1095        log_to_screen
     1096            ("Errors occurred during the formatting of your hard drives.");
    10191097    } else {
    10201098        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    10211099    }
    10221100
    1023     sprintf(tmp, "format_everything () - %s", (retval) ? "failed!" : "finished successfully");
     1101    sprintf(tmp, "format_everything () - %s",
     1102            (retval) ? "failed!" : "finished successfully");
    10241103    log_it(tmp);
    10251104
    1026     if (g_partition_table_locked_up > 0)
    1027       {
    1028         if (retval > 0 && !interactively)
    1029               {
     1105    if (g_partition_table_locked_up > 0) {
     1106        if (retval > 0 && !interactively) {
    10301107//123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    1031                 log_to_screen(
    1032   "Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up);
    1033                 log_to_screen(
    1034   "failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
    1035                 log_to_screen(
    1036   "to refresh its copy of the partition table causes the kernel to lock the ");
    1037                 log_to_screen(
    1038   "partition table. I believe this has just happened.");
    1039                 if (ask_me_yes_or_no("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
    1040                   {
    1041             system("sync");
    1042             system("sync");
    1043             system("sync");
    1044             system("reboot");
    1045           }
    1046           }
    1047         else
    1048           {
    1049             log_to_screen(
    1050 "Partition table locked up %d time%c. However, disk formatting succeeded.", g_partition_table_locked_up, (g_partition_table_locked_up==1)?'.':'s');
    1051           }
    1052       }
    1053         newtSuspend();
     1108            log_to_screen
     1109                ("Partition table locked up %d times. At least one 'mkfs' (format) command",
     1110                 g_partition_table_locked_up);
     1111            log_to_screen
     1112                ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
     1113            log_to_screen
     1114                ("to refresh its copy of the partition table causes the kernel to lock the ");
     1115            log_to_screen
     1116                ("partition table. I believe this has just happened.");
     1117            if (ask_me_yes_or_no
     1118                ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
     1119            {
     1120                system("sync");
     1121                system("sync");
     1122                system("sync");
     1123                system("reboot");
     1124            }
     1125        } else {
     1126            log_to_screen
     1127                ("Partition table locked up %d time%c. However, disk formatting succeeded.",
     1128                 g_partition_table_locked_up,
     1129                 (g_partition_table_locked_up == 1) ? '.' : 's');
     1130        }
     1131    }
     1132    newtSuspend();
    10541133    system("clear");
    10551134    newtResume();
     
    10671146 * @return The number of errors encountered (0 for success).
    10681147 */
    1069 int make_dummy_partitions(FILE*pout_to_fdisk, char *drivename, int devno_we_must_allow_for)
     1148int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename,
     1149                          int devno_we_must_allow_for)
    10701150{
    10711151    /** int **************************************************************/
     
    10871167        log_it(tmp);
    10881168        g_maximum_progress++;
    1089         res = partition_device(pout_to_fdisk,drivename, 1, 0, "ext2", 32000);
     1169        res =
     1170            partition_device(pout_to_fdisk, drivename, 1, 0, "ext2",
     1171                             32000);
    10901172        retval += res;
    10911173        previous_devno = 1;
     
    10961178    }
    10971179    for (; current_devno < devno_we_must_allow_for; current_devno++) {
    1098         sprintf(tmp, "Creating dummy partition %s%d", drivename, current_devno);
     1180        sprintf(tmp, "Creating dummy partition %s%d", drivename,
     1181                current_devno);
    10991182        log_it(tmp);
    11001183        g_maximum_progress++;
    1101         res = partition_device(pout_to_fdisk,drivename, current_devno, previous_devno, OSSWAP("ext2", "ufs"), 32000);
     1184        res =
     1185            partition_device(pout_to_fdisk, drivename, current_devno,
     1186                             previous_devno, OSSWAP("ext2", "ufs"), 32000);
    11021187        retval += res;
    11031188        previous_devno = current_devno;
     
    11471232    else
    11481233        fprintf(f, "type: %u\n", lp->d_type);
    1149     fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename);
    1150     fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname);
     1234    fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename),
     1235            lp->d_typename);
     1236    fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname),
     1237            lp->d_packname);
    11511238    fprintf(f, "flags:");
    11521239    if (lp->d_flags & D_REMOVABLE)
     
    11671254    fprintf(f, "trackskew: %u\n", lp->d_trackskew);
    11681255    fprintf(f, "cylinderskew: %u\n", lp->d_cylskew);
    1169     fprintf(f, "headswitch: %lu\t\t# milliseconds\n", (u_long) lp->d_headswitch);
    1170     fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", (u_long) lp->d_trkseek);
     1256    fprintf(f, "headswitch: %lu\t\t# milliseconds\n",
     1257            (u_long) lp->d_headswitch);
     1258    fprintf(f, "track-to-track seek: %ld\t# milliseconds\n",
     1259            (u_long) lp->d_trkseek);
    11711260    fprintf(f, "drivedata: ");
    11721261    for (i = NDDATA - 1; i >= 0; i--)
     
    11781267        fprintf(f, "%lu ", (u_long) lp->d_drivedata[j]);
    11791268    fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions);
    1180     fprintf(f, "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
     1269    fprintf(f,
     1270            "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
    11811271    pp = lp->d_partitions;
    11821272    for (i = 0; i < lp->d_npartitions; i++, pp++) {
    11831273        if (pp->p_size) {
    1184             fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size, (u_long) pp->p_offset);
     1274            fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
     1275                    (u_long) pp->p_offset);
    11851276            if (pp->p_fstype < FSMAXTYPES)
    11861277                fprintf(f, "%8.8s", fstypenames[pp->p_fstype]);
     
    11901281
    11911282            case FS_UNUSED: /* XXX */
    1192                 fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag), "");
     1283                fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
     1284                        (u_long) (pp->p_fsize * pp->p_frag), "");
    11931285                break;
    11941286
    11951287            case FS_BSDFFS:
    1196                 fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),
    1197                     pp->p_cpg);
     1288                fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize,
     1289                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    11981290                break;
    11991291
    12001292            case FS_BSDLFS:
    1201                 fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),
    1202                     pp->p_cpg);
     1293                fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize,
     1294                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    12031295                break;
    12041296
     
    12071299                break;
    12081300            }
    1209             fprintf(f, "\t# (Cyl. %4lu", (u_long) (pp->p_offset / lp->d_secpercyl));
     1301            fprintf(f, "\t# (Cyl. %4lu",
     1302                    (u_long) (pp->p_offset / lp->d_secpercyl));
    12101303            if (pp->p_offset % lp->d_secpercyl)
    12111304                putc('*', f);
    12121305            else
    12131306                putc(' ', f);
    1214             fprintf(f, "- %lu", (u_long) ((pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1));
     1307            fprintf(f, "- %lu",
     1308                    (u_long) ((pp->p_offset + pp->p_size +
     1309                               lp->d_secpercyl - 1) / lp->d_secpercyl -
     1310                              1));
    12151311            if (pp->p_size % lp->d_secpercyl)
    12161312                putc('*', f);
     
    12381334    /* New world order */
    12391335    if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0)
    1240         || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) {
     1336        || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) {
    12411337        close(f);
    12421338        return (NULL);
     
    12821378    return (&loclab);
    12831379}
     1380
    12841381/* End stolen from /usr/src/sbin/disklabel/disklabel.c. */
    12851382
     
    13011398 * @return The number of errors encountered (0 for success).
    13021399 */
    1303 int label_drive_or_slice(struct mountlist_itself *mountlist, char *drivename, struct disklabel *ret)
     1400int label_drive_or_slice(struct mountlist_itself *mountlist,
     1401                         char *drivename, struct disklabel *ret)
    13041402{
    13051403    char subdev_str[MAX_STR_LEN];
     
    13251423            lp->d_partitions[c - 'a'].p_cpg = 0;
    13261424            if (!strcmp(mountlist->el[idx].format, "ufs")
    1327                 || !strcmp(mountlist->el[idx].format, "ffs")
    1328                 || !strcmp(mountlist->el[idx].format, "4.2BSD")) {
     1425                || !strcmp(mountlist->el[idx].format, "ffs")
     1426                || !strcmp(mountlist->el[idx].format, "4.2BSD")) {
    13291427                lp->d_partitions[c - 'a'].p_fstype = FS_BSDFFS;
    13301428                lp->d_partitions[c - 'a'].p_fsize = 2048;
     
    13321430                lp->d_partitions[c - 'a'].p_cpg = 64;
    13331431            } else if (!strcasecmp(mountlist->el[idx].format, "raid")
    1334                    || !strcasecmp(mountlist->el[idx].format, "vinum")) {
     1432                       || !strcasecmp(mountlist->el[idx].format, "vinum")) {
    13351433                lp->d_partitions[c - 'a'].p_fstype = FS_VINUM;
    13361434            } else if (!strcmp(mountlist->el[idx].format, "swap")) {
     
    13531451        for (lastone = i - 1; lastone >= 0; lastone--) {
    13541452            if ((lp->d_partitions[lastone].p_size)
    1355                 && (lastone != RAW_PART))
     1453                && (lastone != RAW_PART))
    13561454                break;
    13571455        }
    1358         lp->d_partitions[i].p_offset = lp->d_partitions[lastone].p_offset + lp->d_partitions[lastone].p_size;
    1359     }
    1360     if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > lp->d_secperunit) {
    1361         lp->d_partitions[lo].p_size = lp->d_secperunit - lp->d_partitions[lo].p_offset;
     1456        lp->d_partitions[i].p_offset =
     1457            lp->d_partitions[lastone].p_offset +
     1458            lp->d_partitions[lastone].p_size;
     1459    }
     1460    if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size >
     1461        lp->d_secperunit) {
     1462        lp->d_partitions[lo].p_size =
     1463            lp->d_secperunit - lp->d_partitions[lo].p_offset;
    13621464    }
    13631465
     
    13671469    sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));
    13681470    retval += run_program_and_log_output(command, TRUE);
    1369     sprintf(command, "disklabel -R %s /tmp/disklabel", canonical_name(drivename));
     1471    sprintf(command, "disklabel -R %s /tmp/disklabel",
     1472            canonical_name(drivename));
    13701473    retval += run_program_and_log_output(command, TRUE);
    13711474    if (ret)
     
    13901493    int retval = 0;
    13911494    int i;
    1392     FILE*pout_to_fdisk=NULL;
    1393    
     1495    FILE *pout_to_fdisk = NULL;
     1496
    13941497#ifdef __FreeBSD__
    13951498    bool fbsd_part = FALSE;
     
    14131516    malloc_string(format);
    14141517    malloc_string(tmp);
    1415    
     1518
    14161519    sprintf(tmp, "Partitioning drive %s", drivename);
    14171520    log_it(tmp);
    14181521
    1419 #if __FreeBSD__ 
    1420         log_it("(Not opening fdisk now; that's the Linux guy's job)");
     1522#if __FreeBSD__
     1523    log_it("(Not opening fdisk now; that's the Linux guy's job)");
    14211524    pout_to_fdisk = NULL;
    14221525#else
    14231526    make_hole_for_file(FDISK_LOG);
    14241527#ifdef __IA64__
    1425     sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
     1528    sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
     1529            FDISK_LOG);
    14261530#else
    14271531    sprintf(tmp, "fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
    14281532#endif
    14291533    pout_to_fdisk = popen(tmp, "w");
    1430     if (!pout_to_fdisk) { 
    1431         log_to_screen("Cannot call fdisk to configure %s", drivename); 
     1534    if (!pout_to_fdisk) {
     1535        log_to_screen("Cannot call fdisk to configure %s", drivename);
    14321536        paranoid_free(device_str);
    14331537        paranoid_free(format);
    14341538        paranoid_free(tmp);
    1435         return(1);
     1539        return (1);
    14361540    }
    14371541#endif
     
    14511555                for (c = 'a'; c <= 'z'; c++) {
    14521556                    sprintf(subdev_str, "%s%c", drivename, c);
    1453                     if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
     1557                    if (find_device_in_mountlist(mountlist, subdev_str) >
     1558                        0) {
    14541559                        fbsd_part = TRUE;
    14551560                    }
     
    14571562                if (fbsd_part) {
    14581563                    int r = label_drive_or_slice(mountlist,
    1459                                     drivename,
    1460                                     0);
     1564                                                drivename,
     1565                                                0);
    14611566                    char command[MAX_STR_LEN];
    1462                     sprintf(command, "disklabel -B %s", basename(drivename));
     1567                    sprintf(command, "disklabel -B %s",
     1568                            basename(drivename));
    14631569                    if (system(command)) {
    1464                         log_to_screen("Warning! Unable to make the drive bootable.");
     1570                        log_to_screen
     1571                            ("Warning! Unable to make the drive bootable.");
    14651572                    }
    14661573                    paranoid_free(device_str);
     
    15071614#if __FreeBSD__
    15081615            // FreeBSD doesn't let you write to blk devices in <512byte chunks.
    1509 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1510 //          if (run_program_and_log_output(tmp, TRUE)) {
     1616//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1617//          if (run_program_and_log_output(tmp, TRUE)) {
    15111618            file = open(drivename, O_WRONLY);
    15121619            if (!file) {
    1513                 sprintf(tmp, "Warning - unable to open %s for wiping it's partition table", drivename);
     1620                sprintf(tmp,
     1621                        "Warning - unable to open %s for wiping it's partition table",
     1622                        drivename);
    15141623                log_to_screen(tmp);
    15151624            }
    15161625
    1517             for (i=0; i<512; i++) {
    1518                 if ( !write(file, "\0", 1) ) {
    1519                     sprintf(tmp, "Warning - unable to write to %s", drivename);
     1626            for (i = 0; i < 512; i++) {
     1627                if (!write(file, "\0", 1)) {
     1628                    sprintf(tmp, "Warning - unable to write to %s",
     1629                            drivename);
    15201630                    log_to_screen(tmp);
    15211631                }
     
    15241634#else
    15251635            iamhere("New, kernel-friendly partition remover");
    1526             for(i=20;i>0;i--)
    1527               {
    1528                 fprintf(pout_to_fdisk, "d\n%d\n", i);
    1529                 fflush(pout_to_fdisk);
    1530               }
    1531 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1532 //          run_program_and_log_output(tmp, 1);
    1533 #endif 
     1636            for (i = 20; i > 0; i--) {
     1637                fprintf(pout_to_fdisk, "d\n%d\n", i);
     1638                fflush(pout_to_fdisk);
     1639            }
     1640//          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
     1641//          run_program_and_log_output(tmp, 1);
     1642#endif
    15341643            if (current_devno > 1) {
    1535                 previous_devno = make_dummy_partitions(pout_to_fdisk,drivename, current_devno);
     1644                previous_devno =
     1645                    make_dummy_partitions(pout_to_fdisk, drivename,
     1646                                          current_devno);
    15361647            }
    15371648        }
     
    15401651#endif
    15411652
    1542         strcpy(format, mountlist->el[lino].format);
    1543         partsize = mountlist->el[lino].size;
     1653            strcpy(format, mountlist->el[lino].format);
     1654            partsize = mountlist->el[lino].size;
    15441655
    15451656#ifdef __FreeBSD__
     
    15491660#ifndef __IA64__
    15501661        if (current_devno == 5 && previous_devno == 4) {
    1551             log_to_screen("You must leave at least one partition spare as the Extended partition.");
     1662            log_to_screen
     1663                ("You must leave at least one partition spare as the Extended partition.");
    15521664            paranoid_free(device_str);
    15531665            paranoid_free(format);
     
    15571669#endif
    15581670
    1559         retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize);
     1671        retval +=
     1672            partition_device(pout_to_fdisk, drivename, current_devno,
     1673                             previous_devno, format, partsize);
    15601674
    15611675#ifdef __FreeBSD__
     
    15641678            retval += label_drive_or_slice(mountlist, device_str, 0);
    15651679            if (system(tmp)) {
    1566                 log_to_screen("Warning! Unable to make the slice bootable.");
     1680                log_to_screen
     1681                    ("Warning! Unable to make the slice bootable.");
    15671682            }
    15681683        }
     
    15721687    }
    15731688
    1574     if (pout_to_fdisk)
    1575     {
     1689    if (pout_to_fdisk) {
    15761690// mark relevant partition as bootable
    1577         sprintf(tmp, "a\n%s\n", call_program_and_get_last_line_of_output("make-me-bootable /tmp/mountlist.txt dummy"));
     1691        sprintf(tmp, "a\n%s\n",
     1692                call_program_and_get_last_line_of_output
     1693                ("make-me-bootable /tmp/mountlist.txt dummy"));
    15781694        fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    15791695// close fdisk
    15801696        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    15811697        system("sync");
    1582         paranoid_pclose(pout_to_fdisk);
    1583         log_msg(0, "------------------- fdisk.log looks like this ------------------");
     1698        paranoid_pclose(pout_to_fdisk);
     1699        log_msg(0,
     1700                "------------------- fdisk.log looks like this ------------------");
    15841701        sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    15851702        system(tmp);
    1586         log_msg(0, "------------------- end of fdisk.log... word! ------------------");
     1703        log_msg(0,
     1704                "------------------- end of fdisk.log... word! ------------------");
    15871705        sprintf(tmp, "tail -n6 %s | fgrep \"16: \"", FDISK_LOG);
    1588         if (!run_program_and_log_output(tmp, 5))
    1589           {
    1590             g_partition_table_locked_up++;
    1591             log_to_screen("A flaw in the Linux kernel has locked the partition table.");
    1592           }
     1706        if (!run_program_and_log_output(tmp, 5)) {
     1707            g_partition_table_locked_up++;
     1708            log_to_screen
     1709                ("A flaw in the Linux kernel has locked the partition table.");
     1710        }
    15931711    }
    15941712    paranoid_free(device_str);
     
    16071725 * @return 0 for success, nonzero for failure.
    16081726 */
    1609 int partition_device(FILE*pout_to_fdisk, const char *drive, int partno, int prev_partno, const char *format, long long partsize)
     1727int partition_device(FILE * pout_to_fdisk, const char *drive, int partno,
     1728                     int prev_partno, const char *format,
     1729                     long long partsize)
    16101730{
    16111731    /** int **************************************************************/
     
    16321752    malloc_string(logfile);
    16331753    malloc_string(output);
    1634    
     1754
    16351755    assert_string_is_neither_NULL_nor_zerolength(drive);
    16361756    assert(format != NULL);
    16371757
    1638     log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", drive, partno, prev_partno, format, partsize);
     1758    log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting",
     1759           drive, partno, prev_partno, format, partsize);
    16391760
    16401761    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     
    16521773        sprintf(tmp, "Partitioning device %s (max size)", partition_name);
    16531774    } else {
    1654         sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, (long long) partsize / 1024);
     1775        sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name,
     1776                (long long) partsize / 1024);
    16551777    }
    16561778    update_progress_form(tmp);
     
    16581780
    16591781    if (is_this_device_mounted(partition_name)) {
    1660         sprintf(tmp, "%s is mounted, and should not be partitioned", partition_name);
     1782        sprintf(tmp, "%s is mounted, and should not be partitioned",
     1783                partition_name);
    16611784        log_to_screen(tmp);
    16621785        paranoid_free(program);
     
    16791802    p = (char *) strrchr(partition_name, '/');
    16801803    sprintf(logfile, "/tmp/fdisk.log.%s", ++p);
    1681     sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     1804    sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
     1805            MONDO_LOGFILE);
    16821806
    16831807    /* BERLIOS: shoould not be called each time */
     
    16891813    } else {
    16901814        /* MBR needs an extended partition if more than 4 partitions */
    1691         if (strcmp(part_table_fmt,"MBR") == 0) {
     1815        if (strcmp(part_table_fmt, "MBR") == 0) {
    16921816            if (partno == 5) {
    16931817                if (prev_partno >= 4) {
    1694                     log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
     1818                    log_to_screen
     1819                        ("You need to leave at least one partition free, for 'extended/logical'");
    16951820                    paranoid_free(program);
    16961821                    paranoid_free(partition_name);
     
    17001825                    return (1);
    17011826                } else {
    1702                     sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1);
     1827                    sprintf(output + strlen(output), "n\ne\n%d\n\n\n",
     1828                            prev_partno + 1);
    17031829                }
    17041830            }
     
    17111837    strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
    17121838    if (partsize > 0) {
    1713                 if (!strcmp(format, "7")) { log_msg(1, "Adding 512K, just in case"); partsize+=512; }
     1839        if (!strcmp(format, "7")) {
     1840            log_msg(1, "Adding 512K, just in case");
     1841            partsize += 512;
     1842        }
    17141843        sprintf(output + strlen(output), "+%lldK", (long long) (partsize));
    17151844    }
     
    17281857
    17291858
    1730     if (pout_to_fdisk)
    1731     {
     1859    if (pout_to_fdisk) {
    17321860        log_msg(1, "Doing the new all-in-one fdisk thing");
    17331861        log_msg(1, "output = '%s'", output);
     
    17351863        fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n");
    17361864        strcpy(tmp, last_line_of_file(FDISK_LOG));
    1737         if (strstr(tmp, " (m "))
    1738         {
     1865        if (strstr(tmp, " (m ")) {
    17391866            log_msg(1, "Successfully created %s%d", drive, partno);
    1740         }
    1741         else
    1742         {
     1867        } else {
    17431868            log_msg(1, "last line = %s", tmp);
    1744             log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, partno);
    1745         }
    1746         if (!retval)
    1747         {
    1748             log_msg(1, "Trying to set %s%d's partition type now", drive, partno);
    1749             retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
    1750             if (retval)
    1751             {
     1869            log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive,
     1870                    partno);
     1871        }
     1872        if (!retval) {
     1873            log_msg(1, "Trying to set %s%d's partition type now", drive,
     1874                    partno);
     1875            retval =
     1876                set_partition_type(pout_to_fdisk, drive, partno, format,
     1877                                   partsize);
     1878            if (retval) {
    17521879                log_msg(1, "Failed. Trying again...");
    1753                     retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
    1754             }
    1755           }
    1756         if (retval) { log_msg(1, "...but failed to set type"); }
    1757     }
    1758     else
    1759     {
     1880                retval =
     1881                    set_partition_type(pout_to_fdisk, drive, partno,
     1882                                       format, partsize);
     1883            }
     1884        }
     1885        if (retval) {
     1886            log_msg(1, "...but failed to set type");
     1887        }
     1888    } else {
    17601889        strcat(output, "w\n\n");
    1761             if (g_fprep) { fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); }
     1890        if (g_fprep) {
     1891            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     1892        }
    17621893        /* write to disk; close fdisk's stream */
    17631894        if (!(fout = popen(program, "w"))) {
     
    17701901            log_it("Vaccum-packing");
    17711902            g_current_progress--;
    1772             res = partition_device(pout_to_fdisk, drive, partno, prev_partno, format, -1);
     1903            res =
     1904                partition_device(pout_to_fdisk, drive, partno, prev_partno,
     1905                                 format, -1);
    17731906            if (res) {
    17741907                sprintf(tmp, "Failed to vacuum-pack %s", partition_name);
     
    17801913        }
    17811914        if (does_partition_exist(drive, partno)) {
    1782             retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize);
     1915            retval =
     1916                set_partition_type(pout_to_fdisk, drive, partno, format,
     1917                                   partsize);
    17831918            if (retval) {
    1784                 sprintf(tmp, "Partitioned %s but failed to set its type", partition_name);
     1919                sprintf(tmp, "Partitioned %s but failed to set its type",
     1920                        partition_name);
    17851921                log_it(tmp);
    17861922            } else {
    17871923                if (partsize > 0) {
    1788                     sprintf(tmp, "Partition %s created+configured OK", partition_name);
     1924                    sprintf(tmp, "Partition %s created+configured OK",
     1925                            partition_name);
    17891926                    log_to_screen(tmp);
    17901927                } else {
     
    17921929                }
    17931930            }
    1794             } else {
     1931        } else {
    17951932            sprintf(tmp, "Failed to partition %s", partition_name);
    17961933            if (partsize > 0) {
     
    18441981        /*      mountlist=&new_mtlist; */
    18451982        /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
    1846         log_msg(0,"Mountlist, including the partitions incorporated in RAID devices:-");
     1983        log_msg(0,
     1984                "Mountlist, including the partitions incorporated in RAID devices:-");
    18471985        for (i = 0; i < mountlist->entries; i++) {
    18481986            log_it(mountlist->el[i].device);
     
    18511989    }
    18521990    log_msg(0, "Stopping all LVMs, just in case");
    1853         if (!g_text_mode) { newtSuspend(); }
    1854     do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions
    1855         if (!g_text_mode) { newtResume(); }
     1991    if (!g_text_mode) {
     1992        newtSuspend();
     1993    }
     1994    do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions
     1995    if (!g_text_mode) {
     1996        newtResume();
     1997    }
    18561998    log_msg(0, "Stopping all software RAID devices, just in case");
    18571999    stop_all_raid_devices(mountlist);
    18582000    log_msg(0, "Done.");
    1859    
     2001
    18602002/* 
    18612003    if (does_file_exist("/tmp/i-want-my-lvm"))
     
    18652007*/
    18662008
    1867     open_progress_form("Partitioning devices", "I am now going to partition all your drives.",
    1868                "This should not take more than five minutes.", "", mountlist->entries);
     2009    open_progress_form("Partitioning devices",
     2010                       "I am now going to partition all your drives.",
     2011                       "This should not take more than five minutes.", "",
     2012                       mountlist->entries);
    18692013
    18702014    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    18782022    if (retval) {
    18792023        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1880         log_to_screen("Errors occurred during the partitioning of your hard drives.");
     2024        log_to_screen
     2025            ("Errors occurred during the partitioning of your hard drives.");
    18812026    } else {
    18822027        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    19042049 * @return 0 for success, nonzero for failure.
    19052050 */
    1906 int set_partition_type(FILE *pout_to_fdisk, const char *drive, int partno, const char *format, long long partsize)
     2051int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno,
     2052                       const char *format, long long partsize)
    19072053{
    19082054    /** buffers *********************************************************/
    1909   char *partition;
    1910   char *command;
    1911   char *output;
    1912   char *tmp;
    1913   char *partcode;
    1914   char *logfile;
     2055    char *partition;
     2056    char *command;
     2057    char *output;
     2058    char *tmp;
     2059    char *partcode;
     2060    char *logfile;
    19152061
    19162062    /** pointers *********************************************************/
     
    19262072    assert(format != NULL);
    19272073
    1928   malloc_string(partition);
    1929   malloc_string(command);
    1930   malloc_string(output);
    1931   malloc_string(tmp);
    1932   malloc_string(partcode);
    1933   malloc_string(logfile);
     2074    malloc_string(partition);
     2075    malloc_string(command);
     2076    malloc_string(output);
     2077    malloc_string(tmp);
     2078    malloc_string(partcode);
     2079    malloc_string(logfile);
    19342080
    19352081    build_partition_name(partition, drive, partno);
     
    19442090            strcpy(partcode, "b");
    19452091        }
    1946     } else if (strcmp(format, "ext2") == 0 || strcmp(format, "reiserfs") == 0 || strcmp(format, "ext3") == 0
    1947            || strcmp(format, "xfs") == 0 || strcmp(format, "jfs") == 0) {
     2092    } else if (strcmp(format, "ext2") == 0
     2093               || strcmp(format, "reiserfs") == 0
     2094               || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0
     2095               || strcmp(format, "jfs") == 0) {
    19482096        strcpy(partcode, "83");
    19492097    } else if (strcmp(format, "minix") == 0) {
     
    19522100        strcpy(partcode, "fd");
    19532101    } else if ((strcmp(format, "ufs") == 0)
    1954            || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
     2102               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
    19552103        strcpy(partcode, "a5");
    19562104    } else if (strcmp(format, "lvm") == 0) {
     
    19622110    } else {
    19632111        /* probably an image */
    1964         sprintf(tmp, "Unknown format ('%s') - using supplied string anyway", format);
     2112        sprintf(tmp,
     2113                "Unknown format ('%s') - using supplied string anyway",
     2114                format);
    19652115        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    19662116#ifdef __FreeBSD__
    1967         strcpy(partcode, format); // was a5
     2117        strcpy(partcode, format);   // was a5
    19682118#else
    1969         strcpy(partcode, format); // was 83
    1970 #endif
    1971     }
    1972     sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, partcode);
     2119        strcpy(partcode, format);   // was 83
     2120#endif
     2121    }
     2122    sprintf(tmp, "Setting %s's type to %s (%s)", partition, format,
     2123            partcode);
    19732124    log_msg(1, tmp);
    19742125    if (partcode[0] != '\0' && strcmp(partcode, "83")) {    /* no need to set type if 83: 83 is default */
    1975        
    1976         if (pout_to_fdisk)
    1977         {
     2126
     2127        if (pout_to_fdisk) {
    19782128            res = 0;
    19792129            fput_string_one_char_at_a_time(pout_to_fdisk, "t\n");
    1980             if (partno > 1 || strstr(last_line_of_file(FDISK_LOG), " (1-4)"))
    1981             {
     2130            if (partno > 1
     2131                || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) {
    19822132                log_msg(5, "Specifying partno (%d) - yay", partno);
    19832133                sprintf(tmp, "%d\n", partno);
    19842134                fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1985                 log_msg(5, "A - last line = '%s'", last_line_of_file(FDISK_LOG));
    1986             }
    1987            
     2135                log_msg(5, "A - last line = '%s'",
     2136                        last_line_of_file(FDISK_LOG));
     2137            }
     2138
    19882139            sprintf(tmp, "%s\n", partcode);
    19892140            fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1990             log_msg(5, "B - last line = '%s'", last_line_of_file(FDISK_LOG));
     2141            log_msg(5, "B - last line = '%s'",
     2142                    last_line_of_file(FDISK_LOG));
    19912143            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    1992             log_msg(5, "C - last line = '%s'", last_line_of_file(FDISK_LOG));
    1993            
     2144            log_msg(5, "C - last line = '%s'",
     2145                    last_line_of_file(FDISK_LOG));
     2146
    19942147            strcpy(tmp, last_line_of_file(FDISK_LOG));
    1995             if (!strstr(tmp, " (m "))
    1996               {
    1997                 log_msg(1, "last line = '%s'; part type set failed", tmp);
    1998                 res++;
    1999                 fput_string_one_char_at_a_time(pout_to_fdisk,"\n");
    2000               }
    2001             fput_string_one_char_at_a_time(pout_to_fdisk,"p\n");
    2002         }
    2003         else
    2004         {
     2148            if (!strstr(tmp, " (m ")) {
     2149                log_msg(1, "last line = '%s'; part type set failed", tmp);
     2150                res++;
     2151                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
     2152            }
     2153            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
     2154        } else {
    20052155            sprintf(output, "t\n%d\n%s\n", partno, partcode);
    20062156            strcat(output, "w\n");
    2007             sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     2157            sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
     2158                    MONDO_LOGFILE, MONDO_LOGFILE);
    20082159            log_msg(5, "output = '%s'", output);
    20092160            log_msg(5, "partno=%d; partcode=%s", partno, partcode);
     
    20192170            }
    20202171        }
    2021     if (res)
    2022       {
    2023         log_OS_error(command);
    2024       }
    2025     }
    2026 
    2027   paranoid_free(partition);
    2028   paranoid_free(command);
    2029   paranoid_free(output);
    2030   paranoid_free(tmp);
    2031   paranoid_free(partcode);
    2032   paranoid_free(logfile);
    2033 
    2034   return (res);
     2172        if (res) {
     2173            log_OS_error(command);
     2174        }
     2175    }
     2176
     2177    paranoid_free(partition);
     2178    paranoid_free(command);
     2179    paranoid_free(output);
     2180    paranoid_free(tmp);
     2181    paranoid_free(partcode);
     2182    paranoid_free(logfile);
     2183
     2184    return (res);
    20352185}
    20362186
     
    20492199    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    20502200    malloc_string(program);
    2051    
     2201
    20522202#ifdef __FreeBSD__
    20532203    if (is_this_device_mounted(raid_device)) {
     
    20622212    log_msg(1, "program = %s", program);
    20632213    res = run_program_and_log_output(program, 1);
    2064     if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    2065     if (res) { log_msg(1, "Warning - failed to start RAID device %s", raid_device); }
     2214    if (g_fprep) {
     2215        fprintf(g_fprep, "%s\n", program);
     2216    }
     2217    if (res) {
     2218        log_msg(1, "Warning - failed to start RAID device %s",
     2219                raid_device);
     2220    }
    20662221    retval += res;
    20672222    sleep(1);
     
    20892244    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    20902245    malloc_string(program);
    2091    
     2246
    20922247#ifdef __FreeBSD__
    20932248    if (is_this_device_mounted(raid_device)) {
     
    21022257    log_msg(1, "program = %s", program);
    21032258    res = run_program_and_log_output(program, 1);
    2104     if (g_fprep) { fprintf(g_fprep, "%s\n", program); }
    2105     if (res) { log_msg(1, "Warning - failed to stop RAID device %s", raid_device); }
     2259    if (g_fprep) {
     2260        fprintf(g_fprep, "%s\n", program);
     2261    }
     2262    if (res) {
     2263        log_msg(1, "Warning - failed to stop RAID device %s", raid_device);
     2264    }
    21062265    retval += res;
    21072266    return (retval);
     
    21122271{
    21132272    int i;
    2114     int retval=0;
     2273    int retval = 0;
    21152274    int res;
    2116    
    2117     for(i=0; i<mountlist->entries; i++)
    2118       {
    2119         if (!strncmp(mountlist->el[i].device, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)))
    2120           {
    2121             log_msg(1, "Starting %s", mountlist->el[i].device);
    2122         res = start_raid_device(mountlist->el[i].device);
    2123         retval += res;
    2124           }
    2125       }
    2126     if (retval) { log_msg(1, "Started all s/w raid devices OK"); }
    2127     else { log_msg(1, "Failed to start some/all s/w raid devices"); }
    2128     return(retval);
     2275
     2276    for (i = 0; i < mountlist->entries; i++) {
     2277        if (!strncmp
     2278            (mountlist->el[i].device, RAID_DEVICE_STUB,
     2279             strlen(RAID_DEVICE_STUB))) {
     2280            log_msg(1, "Starting %s", mountlist->el[i].device);
     2281            res = start_raid_device(mountlist->el[i].device);
     2282            retval += res;
     2283        }
     2284    }
     2285    if (retval) {
     2286        log_msg(1, "Started all s/w raid devices OK");
     2287    } else {
     2288        log_msg(1, "Failed to start some/all s/w raid devices");
     2289    }
     2290    return (retval);
    21292291}
    21302292
     
    21632325    for (i = 0; i < 3; i++) {
    21642326#ifdef __FreeBSD__
    2165         fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r");
     2327        fin =
     2328            popen
     2329            ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2",
     2330             "r");
    21662331        if (!fin) {
    21672332            paranoid_free(dev);
     
    21692334            return (1);
    21702335        }
    2171         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2336        for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2337             fgets(incoming, MAX_STR_LEN - 1, fin)) {
    21722338            retval += stop_raid_device(incoming);
    21732339        }
     
    21802346            return (1);
    21812347        }
    2182         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
    2183             for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++);
     2348        for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2349             fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2350            for (p = incoming;
     2351                 *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
     2352                                || !isdigit(*(p + 2))); p++);
    21842353            if (*p != '\0') {
    21852354                sprintf(dev, "/dev/%s", p);
     
    21922361    }
    21932362    paranoid_fclose(fin);
    2194     if (retval) { log_msg(1, "Warning - unable to stop some RAID devices"); }
     2363    if (retval) {
     2364        log_msg(1, "Warning - unable to stop some RAID devices");
     2365    }
    21952366    paranoid_free(dev);
    21962367    paranoid_free(incoming);
    2197     system("sync"); system("sync"); system("sync");
     2368    system("sync");
     2369    system("sync");
     2370    system("sync");
    21982371    sleep(1);
    21992372    return (retval);
     
    22502423        sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
    22512424#endif
    2252         sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program);
     2425        sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format,
     2426                program);
    22532427        log_it(tmp);
    22542428        res = 0;
     
    22672441 */
    22682442long calc_orig_size_of_drive_from_mountlist(struct mountlist_itself
    2269                         *mountlist, char *drive_name)
     2443                                            *mountlist, char *drive_name)
    22702444{
    22712445    /** long ************************************************************/
     
    22842458    assert_string_is_neither_NULL_nor_zerolength(drive_name);
    22852459
    2286     for (original_size_of_drive = 0, partno = 0; partno < mountlist->entries; partno++) {
    2287         if (strncmp(mountlist->el[partno].device, drive_name, strlen(drive_name)) == 0) {
     2460    for (original_size_of_drive = 0, partno = 0;
     2461         partno < mountlist->entries; partno++) {
     2462        if (strncmp
     2463            (mountlist->el[partno].device, drive_name,
     2464             strlen(drive_name)) == 0) {
    22882465            original_size_of_drive += mountlist->el[partno].size;
    22892466        } else {
     
    23102487 */
    23112488void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself
    2312                              *mountlist, char *drive_name)
     2489                                                     *mountlist,
     2490                                                     char *drive_name)
    23132491{
    23142492    /**buffers **********************************************************/
     
    23172495    /** int *************************************************************/
    23182496    int partno, lastpart;
    2319                /** remove driveno, noof_drives stan benoit apr 2002**/
     2497               /** remove driveno, noof_drives stan benoit apr 2002**/
    23202498
    23212499    /** float ***********************************************************/
    23222500    float factor;
    23232501    float new_size;
    2324 //  float newcylinderno;
     2502//  float newcylinderno;
    23252503
    23262504    /** long *************************************************************/
     
    23282506    long current_size_of_drive = 0;
    23292507    long original_size_of_drive = 0;
    2330     long final_size;    /* all in Megabytes */
     2508    long final_size;            /* all in Megabytes */
    23312509    struct mountlist_reference *drivemntlist;
    23322510
     
    23402518
    23412519    if (strlen(drive_name) >= strlen(RAID_DEVICE_STUB)) {
    2342         if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) == 0) {
     2520        if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))
     2521            == 0) {
    23432522            paranoid_free(tmp);
    23442523            return;
     
    23522531
    23532532    current_size_of_drive = get_phys_size_of_drive(drive_name);
    2354    
     2533
    23552534    if (current_size_of_drive <= 0) {
    23562535        log_it("Not resizing to match %s - can't find drive", drive_name);
     
    23582537        return;
    23592538    }
    2360     sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, current_size_of_drive);
     2539    sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name,
     2540            current_size_of_drive);
    23612541    log_to_screen(tmp);
    23622542
    2363     drivemntlist = malloc(sizeof (struct mountlist_reference));
    2364     drivemntlist->el = malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
     2543    drivemntlist = malloc(sizeof(struct mountlist_reference));
     2544    drivemntlist->el =
     2545        malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES);
    23652546
    23662547    if (!drivemntlist) {
     
    23752556
    23762557    if (original_size_of_drive <= 0) {
    2377         sprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name);
     2558        sprintf(tmp, "Cannot resize %s's entries. Drive not found.",
     2559                drive_name);
    23782560        log_to_screen(tmp);
    23792561        paranoid_free(tmp);
    23802562        return;
    23812563    }
    2382     factor = (float) (current_size_of_drive) / (float) (original_size_of_drive);
    2383     sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", drive_name, original_size_of_drive, current_size_of_drive,
    2384         factor);
     2564    factor =
     2565        (float) (current_size_of_drive) / (float) (original_size_of_drive);
     2566    sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
     2567            drive_name, original_size_of_drive, current_size_of_drive,
     2568            factor);
    23852569    log_to_screen(tmp);
    23862570
    2387     lastpart = drivemntlist->entries-1;
     2571    lastpart = drivemntlist->entries - 1;
    23882572    for (partno = 0; partno < drivemntlist->entries; partno++) {
    23892573        /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */
    2390         if ( !atoi(drivemntlist->el[partno]->format) ) {
     2574        if (!atoi(drivemntlist->el[partno]->format)) {
    23912575            new_size = (float) (drivemntlist->el[partno]->size) * factor;
    23922576        } else {
    23932577            new_size = drivemntlist->el[partno]->size;
    23942578        }
    2395        
     2579
    23962580        if (!strcmp(drivemntlist->el[partno]->mountpoint, "image")) {
    23972581            log_msg(1, "Skipping %s (%s) because it's an image",
    2398                             drivemntlist->el[partno]->device,
    2399                             drivemntlist->el[partno]->mountpoint);
    2400             newsizL = (long) new_size; // It looks wrong but it's not
     2582                    drivemntlist->el[partno]->device,
     2583                    drivemntlist->el[partno]->mountpoint);
     2584            newsizL = (long) new_size;  // It looks wrong but it's not
    24012585        } else {
    24022586            newsizL = (long) new_size;
    24032587        }
    2404         sprintf(tmp, "Changing %s from %lld KB to %ld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size,newsizL);
     2588        sprintf(tmp, "Changing %s from %lld KB to %ld KB",
     2589                drivemntlist->el[partno]->device,
     2590                drivemntlist->el[partno]->size, newsizL);
    24052591        log_to_screen(tmp);
    24062592        drivemntlist->el[partno]->size = newsizL;
     
    24202606 */
    24212607void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself
    2422                             *mountlist)
     2608                                                        *mountlist)
    24232609{
    24242610    /** buffers *********************************************************/
     
    24342620
    24352621    if (g_mountlist_fname[0] == '\0') {
    2436         log_it ("resize_mountlist_prop...() - warning - mountlist fname is blank");
    2437         log_it ("That does NOT affect the functioning of this subroutine.");
    2438         log_it ("--- Hugo, 2002/11/20");
     2622        log_it
     2623            ("resize_mountlist_prop...() - warning - mountlist fname is blank");
     2624        log_it("That does NOT affect the functioning of this subroutine.");
     2625        log_it("--- Hugo, 2002/11/20");
    24392626    }
    24402627    iamhere("Resizing mountlist");
     
    24422629    iamhere("Back from MLoDiM");
    24432630    for (driveno = 0; driveno < drivelist->entries; driveno++) {
    2444         resize_drive_proportionately_to_suit_new_drives(mountlist, drivelist->el[driveno].device);
     2631        resize_drive_proportionately_to_suit_new_drives(mountlist,
     2632                                                        drivelist->
     2633                                                        el[driveno].
     2634                                                        device);
    24452635    }
    24462636    log_to_screen("Mountlist adjusted to suit current hard drive(s)");
     
    24562646 * @author Ralph Grewe
    24572647 */
    2458 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist) {
     2648void create_mountlist_for_drive(struct mountlist_itself *mountlist,
     2649                                char *drive_name,
     2650                                struct mountlist_reference *drivemntlist)
     2651{
    24592652    int partno;
    24602653    char *tmp_drive_name, *c;
     
    24642657    assert(drivemntlist != NULL);
    24652658
    2466     log_msg (1, "Creating list of partitions for drive %s",drive_name);
    2467 
    2468     tmp_drive_name = strdup (drive_name);
    2469     if (!tmp_drive_name) fatal_error ("Out of memory");
    2470    
     2659    log_msg(1, "Creating list of partitions for drive %s", drive_name);
     2660
     2661    tmp_drive_name = strdup(drive_name);
     2662    if (!tmp_drive_name)
     2663        fatal_error("Out of memory");
     2664
    24712665    /* devfs devices? */
    2472     c = strrchr (tmp_drive_name, '/');
    2473     if (c && strncmp (c, "/disc", 5) == 0) {
    2474         /* yup its devfs, change the "disc" to "part" so the existing code works */
    2475         strcpy (c + 1, "part");
    2476     }
    2477     drivemntlist->entries=0;
     2666    c = strrchr(tmp_drive_name, '/');
     2667    if (c && strncmp(c, "/disc", 5) == 0) {
     2668        /* yup its devfs, change the "disc" to "part" so the existing code works */
     2669        strcpy(c + 1, "part");
     2670    }
     2671    drivemntlist->entries = 0;
    24782672    for (partno = 0; partno < mountlist->entries; partno++) {
    2479         if (strncmp (mountlist->el[partno].device, tmp_drive_name, strlen(tmp_drive_name)) == 0) {
    2480             drivemntlist->el[drivemntlist->entries] = &mountlist->el[partno];
     2673        if (strncmp
     2674            (mountlist->el[partno].device, tmp_drive_name,
     2675             strlen(tmp_drive_name)) == 0) {
     2676            drivemntlist->el[drivemntlist->entries] =
     2677                &mountlist->el[partno];
    24812678            drivemntlist->entries++;
    24822679        }
    24832680    }
    24842681    if (tmp_drive_name)
    2485         free (tmp_drive_name);
     2682        free(tmp_drive_name);
    24862683}
    24872684
  • branches/2.05/mondo/mondo/mondorestore/mondo-restore-EXT.h

    r30 r128  
    66
    77extern bool g_sigpipe_caught;
    8 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
     8extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
    99extern bool g_I_have_just_nuked;
    1010extern char *g_tmpfs_mountpt;
     
    1313
    1414extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS;
    15 extern char  *g_biggielist_txt;
    16 extern char  *g_filelist_full;
    17 extern char  *g_biggielist_pot;
    18 extern char  *g_filelist_potential;
    19 extern char  *g_filelist_imagedevs;
    20 extern char  *g_filelist_restthese;
    21 extern char  *g_biggielist_restthese;
    22 extern char  *g_imagedevs_restthese;
    23 extern char  *g_mondo_cfg_file;
    24 extern char  *g_mountlist_fname;
    25 extern char  *g_mondo_home;
     15extern char *g_biggielist_txt;
     16extern char *g_filelist_full;
     17extern char *g_biggielist_pot;
     18extern char *g_filelist_potential;
     19extern char *g_filelist_imagedevs;
     20extern char *g_filelist_restthese;
     21extern char *g_biggielist_restthese;
     22extern char *g_imagedevs_restthese;
     23extern char *g_mondo_cfg_file;
     24extern char *g_mountlist_fname;
     25extern char *g_mondo_home;
    2626
    2727
    28 extern void ask_about_these_imagedevs(char*,char*);
    29 extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*);
    30 extern void sort_mountlist_by_device(struct mountlist_itself*);
    31 extern void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*);
    32 extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    33 extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    34 extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
     28extern void ask_about_these_imagedevs(char *, char *);
     29extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *,
     30                         struct raidlist_itself *);
     31extern void sort_mountlist_by_device(struct mountlist_itself *);
     32extern void find_pathname_of_executable_preferably_in_RESTORING(char *,
     33                                                                char *,
     34                                                                char *);
     35extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *,
     36                            struct raidlist_itself *);
     37extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *,
     38                     struct raidlist_itself *);
     39extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *,
     40                        struct raidlist_itself *);
    3541extern int iso_mode(struct s_bkpinfo *bkpinfo,
    36      struct mountlist_itself *mountlist,
    37      struct raidlist_itself *raidlist,
    38      bool nuke_me_please);
    39 extern int load_mountlist(struct mountlist_itself*,char*);
    40 extern int load_raidtab_into_raidlist(struct raidlist_itself*,char*);
    41 extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    42 extern int save_raidlist_to_raidtab(struct raidlist_itself*,char*);
    43 extern void process_raidtab_line(FILE*, struct raid_device_record *, char*, char*);
    44 extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*);
    45 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*);
    46 extern int restore_a_tarball_from_CD(char *, int, struct s_node*);
    47 extern int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, int, struct s_node*, long long);
    48 extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*);
    49 extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*);
    50 extern int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*);
    51 extern int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*);
    52 extern int restore_everything(struct s_bkpinfo*, struct s_node*);
    53 extern int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*);
    54 extern int restore_to_live_filesystem(struct s_bkpinfo*);
    55 extern void swap_mountlist_entries(struct mountlist_itself*,int,int);
    56 extern void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool);
    57 extern void sort_mountlist_by_device(struct mountlist_itself*);
     42                    struct mountlist_itself *mountlist,
     43                    struct raidlist_itself *raidlist, bool nuke_me_please);
     44extern int load_mountlist(struct mountlist_itself *, char *);
     45extern int load_raidtab_into_raidlist(struct raidlist_itself *, char *);
     46extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *,
     47                        struct raidlist_itself *);
     48extern int save_raidlist_to_raidtab(struct raidlist_itself *, char *);
     49extern void process_raidtab_line(FILE *, struct raid_device_record *,
     50                                 char *, char *);
     51extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long,
     52                                        struct s_node *);
     53extern int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *,
     54                                            long, char *, long long,
     55                                            struct s_node *);
     56extern int restore_a_tarball_from_CD(char *, int, struct s_node *);
     57extern int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, int,
     58                                         struct s_node *, long long);
     59extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo *,
     60                                           struct s_node *);
     61extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo *,
     62                                               struct s_node *);
     63extern int restore_all_tarballs_from_CD(struct s_bkpinfo *,
     64                                        struct s_node *);
     65extern int restore_all_tarballs_from_stream(struct s_bkpinfo *,
     66                                            struct s_node *);
     67extern int restore_everything(struct s_bkpinfo *, struct s_node *);
     68extern int restore_live_from_monitas_server(struct s_bkpinfo *, char *,
     69                                            char *, char *);
     70extern int restore_to_live_filesystem(struct s_bkpinfo *);
     71extern void swap_mountlist_entries(struct mountlist_itself *, int, int);
     72extern void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool);
     73extern void sort_mountlist_by_device(struct mountlist_itself *);
    5874extern void success_message(void);
    5975extern void twenty_seconds_til_yikes(void);
    60 extern int run_raw_mbr(bool offer_to_hack_scripts, char*bd);
    61 extern int save_mountlist_to_disk(struct mountlist_itself*, char*);
    62 extern void save_raidrec_to_file(struct raid_device_record *raidrec, FILE*fout);
    63 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char*fname);
    64 extern int what_number_cd_is_this(struct s_bkpinfo*);
     76extern int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
     77extern int save_mountlist_to_disk(struct mountlist_itself *, char *);
     78extern void save_raidrec_to_file(struct raid_device_record *raidrec,
     79                                 FILE * fout);
     80extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist,
     81                                    char *fname);
     82extern int what_number_cd_is_this(struct s_bkpinfo *);
    6583
    6684#ifdef __FreeBSD__
  • branches/2.05/mondo/mondo/mondorestore/mondo-restore.c

    r30 r128  
    55    copyright            : (C) 2000 by Hugo Rabson
    66    email                : Hugo Rabson <hugorabson@msn.com>
    7     cvsid                : $Id: mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp $
     7    cvsid                : $Id$
    88***************************************************************************/
    99
     
    407407
    408408
    409 //static char cvsid[] = "$Id: mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp $";
     409//static char cvsid[] = "$Id$";
    410410
    411411/**************************************************************************
    412412 * Globals                                                                *
    413413 **************************************************************************/
    414 extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
    415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
    416                                                 // up global bkpinfo struct
     414extern char *g_tmpfs_mountpt;   // declared in libmondo-tools.c
     415extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
     416                                                // up global bkpinfo struct
    417417extern bool g_text_mode;
    418418extern FILE *g_fprep;
     
    433433 * Set by the signal handler; cleared after it's handled.
    434434 */
    435 bool    g_sigpipe_caught=FALSE;
     435bool g_sigpipe_caught = FALSE;
    436436
    437437/**
     
    439439 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
    440440 */
    441 bool    g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
     441bool g_ISO_restore_mode = FALSE;    /* are we in Iso Mode? */
    442442
    443443/**
    444444 * If TRUE, then we have had a successful "nuke" restore.
    445445 */
    446 bool    g_I_have_just_nuked = FALSE;
     446bool g_I_have_just_nuked = FALSE;
    447447
    448448/**
    449449 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
    450450 */
    451 char    *g_isodir_device;
     451char *g_isodir_device;
    452452
    453453/**
    454454 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
    455455 */
    456 char    *g_isodir_format;
     456char *g_isodir_format;
    457457
    458458/**
    459459 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
    460460 */
    461 char    *g_biggielist_txt;
     461char *g_biggielist_txt;
    462462
    463463/**
     
    465465 * the current archive set.
    466466 */
    467 char    *g_filelist_full;
     467char *g_filelist_full;
    468468
    469469/**
     
    471471 * as images, not as individual files.
    472472 */
    473 char  *g_filelist_imagedevs;
     473char *g_filelist_imagedevs;
    474474
    475475/**
     
    477477 * @see g_filelist_imagedevs
    478478 */
    479 char  *g_imagedevs_restthese;
     479char *g_imagedevs_restthese;
    480480
    481481/**
     
    483483 * information for this backup.
    484484 */
    485 char  *g_mondo_cfg_file;
     485char *g_mondo_cfg_file;
    486486
    487487/**
     
    489489 * user's partitions and hard drives.
    490490 */
    491 char  *g_mountlist_fname;
     491char *g_mountlist_fname;
    492492
    493493/**
     
    495495 * to avoid link errors.
    496496 */
    497 char  *g_mondo_home;
     497char *g_mondo_home;
    498498
    499499/* @} - end of "Restore-Time Globals" in globalGroup */
     
    501501
    502502
    503 extern int copy_from_src_to_dest(FILE*f_orig, FILE*f_archived, char direction);
     503extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
     504                                 char direction);
    504505
    505506
     
    525526 * @ingroup restoreGuiGroup
    526527 */
    527 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
     528int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
     529                                struct mountlist_itself *mountlist,
     530                                struct raidlist_itself *raidlist)
    528531{
    529   int retval=0, res=0;
    530 
    531   log_msg(2, "let_user_edit_the_mountlist() --- starting");
    532 
    533   assert(bkpinfo!=NULL);
    534   assert(mountlist!=NULL);
    535   assert(raidlist!=NULL);
    536       if ( !bkpinfo->disaster_recovery )
    537         {
    538           strcpy( g_mountlist_fname, "/tmp/mountlist.txt" );
    539           log_msg(2,  "I guess you're testing edit_mountlist()" );
    540         }
    541       if (!does_file_exist(g_mountlist_fname))
    542         {
    543           log_to_screen(g_mountlist_fname);
    544           log_to_screen("does not exist");
    545           return(1);
    546         }
    547      
    548       retval = load_mountlist( mountlist, g_mountlist_fname );
    549       load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    550       if ( retval ) { log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); }
    551       res = edit_mountlist( g_mountlist_fname, mountlist, raidlist );
    552       if ( res )
    553     {
    554       return( 1 );
    555     }
    556 
    557       save_mountlist_to_disk( mountlist, g_mountlist_fname );
    558       save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME );
    559      
    560       log_to_screen("I have finished editing the mountlist for you.");
    561      
    562       return( retval );
    563     }
     532    int retval = 0, res = 0;
     533
     534    log_msg(2, "let_user_edit_the_mountlist() --- starting");
     535
     536    assert(bkpinfo != NULL);
     537    assert(mountlist != NULL);
     538    assert(raidlist != NULL);
     539    if (!bkpinfo->disaster_recovery) {
     540        strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     541        log_msg(2, "I guess you're testing edit_mountlist()");
     542    }
     543    if (!does_file_exist(g_mountlist_fname)) {
     544        log_to_screen(g_mountlist_fname);
     545        log_to_screen("does not exist");
     546        return (1);
     547    }
     548
     549    retval = load_mountlist(mountlist, g_mountlist_fname);
     550    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     551    if (retval) {
     552        log_to_screen
     553            ("Warning - load_raidtab_into_raidlist returned an error");
     554    }
     555    res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
     556    if (res) {
     557        return (1);
     558    }
     559
     560    save_mountlist_to_disk(mountlist, g_mountlist_fname);
     561    save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
     562
     563    log_to_screen("I have finished editing the mountlist for you.");
     564
     565    return (retval);
     566}
    564567
    565568
     
    573576 * @ingroup restoreUtilityGroup
    574577 */
    575 bool
    576 partition_table_contains_Compaq_diagnostic_partition(struct mountlist_itself *mountlist)
     578bool
     579partition_table_contains_Compaq_diagnostic_partition(struct
     580                                                     mountlist_itself *
     581                                                     mountlist)
    577582{
    578   int i;
    579 
    580   assert(mountlist!=NULL);
    581 
    582   for( i = 0; i < mountlist->entries; i++ )
    583     {
    584       if ( strstr( mountlist->el[i].format, "ompaq" ) )
    585     {
    586       log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
    587           i,
    588           mountlist->el[i].device,
    589           mountlist->el[i].format );
    590      
    591       return( TRUE );
    592     }
    593     }
    594   return( FALSE );
     583    int i;
     584
     585    assert(mountlist != NULL);
     586
     587    for (i = 0; i < mountlist->entries; i++) {
     588        if (strstr(mountlist->el[i].format, "ompaq")) {
     589            log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
     590                    i, mountlist->el[i].device, mountlist->el[i].format);
     591
     592            return (TRUE);
     593        }
     594    }
     595    return (FALSE);
    595596}
     597
    596598/**************************************************************************
    597599 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION                *
     
    604606 * @ingroup restoreUtilityGroup
    605607 */
    606 void
    607 offer_to_abort_because_Compaq_Proliants_suck(void)
     608void offer_to_abort_because_Compaq_Proliants_suck(void)
    608609{
    609   popup_and_OK( COMPAQ_PROLIANTS_SUCK );
    610   if ( ask_me_yes_or_no("Would you like to reboot and use your Compaq CD to prep your hard drive?") )
    611     {
    612       fatal_error( "Aborting. Please reboot and prep your hard drive with your Compaq CD." );
    613     }
     610    popup_and_OK(COMPAQ_PROLIANTS_SUCK);
     611    if (ask_me_yes_or_no
     612        ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
     613    {
     614        fatal_error
     615            ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
     616    }
    614617}
     618
    615619/**************************************************************************
    616620 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK                        *
     
    627631 * @ingroup restoreGroup
    628632 */
    629 int 
    630 catchall_mode( struct s_bkpinfo *bkpinfo,
    631            struct mountlist_itself *mountlist,
    632            struct raidlist_itself*raidlist)
     633int
     634catchall_mode(struct s_bkpinfo *bkpinfo,
     635              struct mountlist_itself *mountlist,
     636              struct raidlist_itself *raidlist)
    633637{
    634   char c, *tmp;
    635   int retval = 0;
    636 
    637   iamhere("inside catchall");
    638   assert(bkpinfo!=NULL);
    639   assert(mountlist!=NULL);
    640   assert(raidlist!=NULL);
    641   malloc_string(tmp);
    642   iamhere("pre wrm");
    643   c = which_restore_mode();
    644   iamhere("post wrm");
    645   if ( c == 'I' || c == 'N' || c == 'C')
    646     {
    647       interactively_obtain_media_parameters_from_user( bkpinfo, FALSE);
    648     }
    649   else
    650     {
    651       popup_and_OK( "No restoring or comparing will take place today." );
    652       if ( is_this_device_mounted( "/mnt/cdrom" ) )
    653     {
    654       run_program_and_log_output( "umount /mnt/cdrom", FALSE);
    655     }
    656       if ( g_ISO_restore_mode )
    657     {
    658           sprintf(tmp, "umount %s", bkpinfo->isodir);
    659       run_program_and_log_output( tmp, FALSE);
    660     }
    661       paranoid_MR_finish( 0 );
    662     }
    663 
    664   iamhere("post int");
    665 
    666   if (bkpinfo->backup_media_type == iso)
    667     {
    668       if (iso_fiddly_bits(bkpinfo, (c=='N')?TRUE:FALSE))
    669         { log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error"); return(1); }
    670       else
    671         { log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); }
    672     }
    673 
    674   if (c == 'I' )
    675     {
    676       log_msg(2, "IM selected" );
    677       retval += interactive_mode( bkpinfo,mountlist,raidlist );
    678     }
    679   else if
    680     ( c == 'N' )
    681     {
    682       log_msg(2, "NM selected");
    683       retval += nuke_mode( bkpinfo, mountlist, raidlist ); }
    684   else if
    685     ( c == 'C' )
    686     {
    687       log_msg(2, "CM selected" );
    688       retval += compare_mode( bkpinfo, mountlist, raidlist);
    689     }
    690   paranoid_free(tmp);
    691   return( retval );
     638    char c, *tmp;
     639    int retval = 0;
     640
     641    iamhere("inside catchall");
     642    assert(bkpinfo != NULL);
     643    assert(mountlist != NULL);
     644    assert(raidlist != NULL);
     645    malloc_string(tmp);
     646    iamhere("pre wrm");
     647    c = which_restore_mode();
     648    iamhere("post wrm");
     649    if (c == 'I' || c == 'N' || c == 'C') {
     650        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     651    } else {
     652        popup_and_OK("No restoring or comparing will take place today.");
     653        if (is_this_device_mounted("/mnt/cdrom")) {
     654            run_program_and_log_output("umount /mnt/cdrom", FALSE);
     655        }
     656        if (g_ISO_restore_mode) {
     657            sprintf(tmp, "umount %s", bkpinfo->isodir);
     658            run_program_and_log_output(tmp, FALSE);
     659        }
     660        paranoid_MR_finish(0);
     661    }
     662
     663    iamhere("post int");
     664
     665    if (bkpinfo->backup_media_type == iso) {
     666        if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
     667            log_msg(2,
     668                    "catchall_mode --- iso_fiddly_bits returned w/ error");
     669            return (1);
     670        } else {
     671            log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
     672        }
     673    }
     674
     675    if (c == 'I') {
     676        log_msg(2, "IM selected");
     677        retval += interactive_mode(bkpinfo, mountlist, raidlist);
     678    } else if (c == 'N') {
     679        log_msg(2, "NM selected");
     680        retval += nuke_mode(bkpinfo, mountlist, raidlist);
     681    } else if (c == 'C') {
     682        log_msg(2, "CM selected");
     683        retval += compare_mode(bkpinfo, mountlist, raidlist);
     684    }
     685    paranoid_free(tmp);
     686    return (retval);
    692687}
     688
    693689/**************************************************************************
    694690 *END_CATCHALL_MODE                                                      *
     
    709705 */
    710706void
    711 find_pathname_of_executable_preferably_in_RESTORING( char *out_path, char *fname, char*restg )
     707find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
     708                                                    char *fname,
     709                                                    char *restg)
    712710{
    713   assert(out_path!=NULL);
    714   assert_string_is_neither_NULL_nor_zerolength(fname);
    715 
    716   sprintf( out_path, "%s/sbin/%s", restg, fname );
    717   if ( does_file_exist(out_path) )
    718     {
    719       sprintf( out_path, "%s/usr/sbin/%s", restg, fname );
    720       if ( does_file_exist( out_path ) )
    721         {
    722           sprintf( out_path, "%s/bin/%s", restg, fname );
    723           if ( does_file_exist( out_path ) )
    724             {
    725               sprintf( out_path, "%s/usr/bin/%s", restg, fname );
    726               if ( does_file_exist( out_path ) )
    727                 {
    728                   strcpy( out_path, fname );
    729                 }
    730             }
    731         }
    732     }
     711    assert(out_path != NULL);
     712    assert_string_is_neither_NULL_nor_zerolength(fname);
     713
     714    sprintf(out_path, "%s/sbin/%s", restg, fname);
     715    if (does_file_exist(out_path)) {
     716        sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
     717        if (does_file_exist(out_path)) {
     718            sprintf(out_path, "%s/bin/%s", restg, fname);
     719            if (does_file_exist(out_path)) {
     720                sprintf(out_path, "%s/usr/bin/%s", restg, fname);
     721                if (does_file_exist(out_path)) {
     722                    strcpy(out_path, fname);
     723                }
     724            }
     725        }
     726    }
    733727}
    734728
     
    753747 * @return 0 for success, or the number of errors encountered.
    754748 */
    755 int 
    756 interactive_mode( struct s_bkpinfo *bkpinfo,
    757           struct mountlist_itself *mountlist,
    758           struct raidlist_itself *raidlist)
     749int
     750interactive_mode(struct s_bkpinfo *bkpinfo,
     751                 struct mountlist_itself *mountlist,
     752                struct raidlist_itself *raidlist)
    759753{
    760   int retval = 0;
    761   int res;
    762   int ptn_errs = 0;
    763   int fmt_errs = 0;
    764 
    765   bool done;
    766   bool restore_all;
     754    int retval = 0;
     755    int res;
     756    int ptn_errs = 0;
     757    int fmt_errs = 0;
     758
     759    bool done;
     760    bool restore_all;
    767761
    768762  /** needs malloc **********/
    769   char *tmp;
    770   char *fstab_fname;
    771   char *old_restpath;
    772  
    773   struct s_node *filelist;
    774 
    775   /* try to partition and format */
    776 
    777   log_msg(2,"interactive_mode --- starting (great, assertions OK)");
    778 
    779   malloc_string(tmp);
    780   malloc_string(fstab_fname);
    781   malloc_string(old_restpath);
    782   assert(bkpinfo!=NULL);
    783   assert(mountlist!=NULL);
    784   assert(raidlist!=NULL);
    785 
    786   log_msg(2,"interactive_mode --- assertions OK");
    787 
    788   if (g_text_mode)
    789     {
    790       if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?"))
    791         { fatal_error("Wise move."); }
    792     }
    793 
    794   iamhere("About to load config file");
    795   get_cfg_file_from_archive_or_bust(bkpinfo);
    796   read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo );
    797   iamhere("Done loading config file; resizing ML");
     763    char *tmp;
     764    char *fstab_fname;
     765    char *old_restpath;
     766
     767    struct s_node *filelist;
     768
     769    /* try to partition and format */
     770
     771    log_msg(2, "interactive_mode --- starting (great, assertions OK)");
     772
     773    malloc_string(tmp);
     774    malloc_string(fstab_fname);
     775    malloc_string(old_restpath);
     776    assert(bkpinfo != NULL);
     777    assert(mountlist != NULL);
     778    assert(raidlist != NULL);
     779
     780    log_msg(2, "interactive_mode --- assertions OK");
     781
     782    if (g_text_mode) {
     783        if (!ask_me_yes_or_no
     784            ("Interactive Mode + textonly = experimental! Proceed anyway?"))
     785        {
     786            fatal_error("Wise move.");
     787        }
     788    }
     789
     790    iamhere("About to load config file");
     791    get_cfg_file_from_archive_or_bust(bkpinfo);
     792    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     793    iamhere("Done loading config file; resizing ML");
    798794#ifdef __FreeBSD__
    799   if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
     795    if (strstr
     796        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
     797         "noresize"))
    800798#else
    801   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
     799    if (strstr
     800        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     801         "noresize"))
    802802#endif
    803     { log_msg(1,"Not resizing mountlist."); }
    804   else
    805     { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }
    806   for( done = FALSE; !done; )
    807     {
    808       iamhere("About to edit mountlist");
    809       if (g_text_mode)
    810         {
    811           save_mountlist_to_disk (mountlist, g_mountlist_fname);
    812       sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
    813           res = system(tmp);
    814           load_mountlist (mountlist, g_mountlist_fname);
    815         }
    816       else
    817         {
    818           res = edit_mountlist( g_mountlist_fname, mountlist, raidlist );
    819         }
    820       iamhere("Finished editing mountlist");
    821       if ( res )
    822     {
    823       paranoid_MR_finish( 1 );
    824     }
    825       log_msg(2, "Proceeding..." );
    826       save_mountlist_to_disk( mountlist, g_mountlist_fname );
    827       save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME );
    828       mvaddstr_and_log_it( 1, 30, "Restoring Interactively" );
    829       if ( bkpinfo->differential )
    830         {
    831           log_to_screen( "Because this is a differential backup, disk" );
    832       log_to_screen(" partitioning and formatting will not take place." );
    833           done=TRUE;
    834         }
    835       else
    836         {
    837           if ( ask_me_yes_or_no( "Do you want to erase and partition your hard drives?" ) )
    838             {
    839           if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) )
    840         { offer_to_abort_because_Compaq_Proliants_suck(); done=TRUE; }
    841           else
    842         {
    843           twenty_seconds_til_yikes();
    844           g_fprep = fopen("/tmp/prep.sh", "w");
    845           ptn_errs = partition_everything( mountlist );
    846           if (ptn_errs)
    847             {
    848               log_to_screen("Warning. Errors occurred during disk partitioning.");
    849             }
    850          
    851           fmt_errs = format_everything( mountlist, FALSE );
    852           if (!fmt_errs)
    853             {
    854               log_to_screen("Errors during disk partitioning were handled OK.");
    855               log_to_screen("Partitions were formatted OK despite those errors.");
    856               ptn_errs = 0;
    857             }
    858           if ( !ptn_errs && !fmt_errs)
    859             {
    860               done = TRUE;
    861             }
    862         }
    863               paranoid_fclose(g_fprep);
    864         }
    865           else
    866             {
    867               mvaddstr_and_log_it( g_currentY++, 0, "User opted not to partition the devices" );
    868               if ( ask_me_yes_or_no( "Do you want to format your hard drives?" ) )
    869                 {
    870                   fmt_errs = format_everything( mountlist, TRUE );
    871                   if (!fmt_errs)
    872             {
    873               done = TRUE;
    874             }
    875             }
    876               else
    877                 {
    878                   ptn_errs = fmt_errs = 0;
    879                   done = TRUE;
    880                 }
    881             }
    882           if (fmt_errs)
    883             {
    884               mvaddstr_and_log_it( g_currentY++,
    885                    0,
    886                    "Errors occurred. Please repartition and format drives manually.");
    887               done = FALSE;
    888             }
    889           if ( ptn_errs & !fmt_errs )
    890             {
    891               mvaddstr_and_log_it( g_currentY++,
    892                    0,
    893                    "Errors occurred during partitioning. Formatting, however, went OK.");
    894               done = TRUE;
    895             }
    896           if ( !done )
    897             {
    898               if ( !ask_me_yes_or_no( "Re-edit the mountlist?" ) )
    899         {
    900           retval++;
    901           goto end_of_func;
    902         }
    903             }
    904         }
    905     }
    906 
    907   /* mount */
    908   if ( mount_all_devices( mountlist, TRUE ) )
    909     {
    910       unmount_all_devices( mountlist );
    911       retval++;
    912       goto end_of_func;
    913     }
    914   /* restore */
    915   if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore all of your data?" ) ) )
    916     {
    917       log_msg(1, "Restoring all data");
    918       retval += restore_everything( bkpinfo, NULL );
    919     }
    920   else if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore _some_ of your data?") ) )
    921     {
    922       strcpy( old_restpath, bkpinfo->restore_path );
    923       for( done = FALSE; !done; )
    924         {
    925       unlink("/tmp/filelist.full");
    926           filelist = process_filelist_and_biggielist( bkpinfo );
    927       /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
    928          the former is a list of regular files; the latter, biggiefiles and imagedevs.
    929       */       
    930       if ( filelist )
    931             {
    932 gotos_suck:
    933               strcpy( tmp, old_restpath );
     803    {
     804        log_msg(1, "Not resizing mountlist.");
     805    } else {
     806        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
     807    }
     808    for (done = FALSE; !done;) {
     809        iamhere("About to edit mountlist");
     810        if (g_text_mode) {
     811            save_mountlist_to_disk(mountlist, g_mountlist_fname);
     812            sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
     813            res = system(tmp);
     814            load_mountlist(mountlist, g_mountlist_fname);
     815        } else {
     816            res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
     817        }
     818        iamhere("Finished editing mountlist");
     819        if (res) {
     820            paranoid_MR_finish(1);
     821        }
     822        log_msg(2, "Proceeding...");
     823        save_mountlist_to_disk(mountlist, g_mountlist_fname);
     824        save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
     825        mvaddstr_and_log_it(1, 30, "Restoring Interactively");
     826        if (bkpinfo->differential) {
     827            log_to_screen("Because this is a differential backup, disk");
     828            log_to_screen
     829                (" partitioning and formatting will not take place.");
     830            done = TRUE;
     831        } else {
     832            if (ask_me_yes_or_no
     833                ("Do you want to erase and partition your hard drives?")) {
     834                if (partition_table_contains_Compaq_diagnostic_partition
     835                    (mountlist)) {
     836                    offer_to_abort_because_Compaq_Proliants_suck();
     837                    done = TRUE;
     838                } else {
     839                    twenty_seconds_til_yikes();
     840                    g_fprep = fopen("/tmp/prep.sh", "w");
     841                    ptn_errs = partition_everything(mountlist);
     842                    if (ptn_errs) {
     843                        log_to_screen
     844                            ("Warning. Errors occurred during disk partitioning.");
     845                    }
     846
     847                    fmt_errs = format_everything(mountlist, FALSE);
     848                    if (!fmt_errs) {
     849                        log_to_screen
     850                            ("Errors during disk partitioning were handled OK.");
     851                        log_to_screen
     852                            ("Partitions were formatted OK despite those errors.");
     853                        ptn_errs = 0;
     854                    }
     855                    if (!ptn_errs && !fmt_errs) {
     856                        done = TRUE;
     857                    }
     858                }
     859                paranoid_fclose(g_fprep);
     860            } else {
     861                mvaddstr_and_log_it(g_currentY++, 0,
     862                                    "User opted not to partition the devices");
     863                if (ask_me_yes_or_no
     864                    ("Do you want to format your hard drives?")) {
     865                    fmt_errs = format_everything(mountlist, TRUE);
     866                    if (!fmt_errs) {
     867                        done = TRUE;
     868                    }
     869                } else {
     870                    ptn_errs = fmt_errs = 0;
     871                    done = TRUE;
     872                }
     873            }
     874            if (fmt_errs) {
     875                mvaddstr_and_log_it(g_currentY++,
     876                                    0,
     877                                    "Errors occurred. Please repartition and format drives manually.");
     878                done = FALSE;
     879            }
     880            if (ptn_errs & !fmt_errs) {
     881                mvaddstr_and_log_it(g_currentY++,
     882                                    0,
     883                                    "Errors occurred during partitioning. Formatting, however, went OK.");
     884                done = TRUE;
     885            }
     886            if (!done) {
     887                if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
     888                    retval++;
     889                    goto end_of_func;
     890                }
     891            }
     892        }
     893    }
     894
     895    /* mount */
     896    if (mount_all_devices(mountlist, TRUE)) {
     897        unmount_all_devices(mountlist);
     898        retval++;
     899        goto end_of_func;
     900    }
     901    /* restore */
     902    if ((restore_all =
     903         ask_me_yes_or_no("Do you want me to restore all of your data?")))
     904    {
     905        log_msg(1, "Restoring all data");
     906        retval += restore_everything(bkpinfo, NULL);
     907    } else
     908        if ((restore_all =
     909             ask_me_yes_or_no
     910             ("Do you want me to restore _some_ of your data?"))) {
     911        strcpy(old_restpath, bkpinfo->restore_path);
     912        for (done = FALSE; !done;) {
     913            unlink("/tmp/filelist.full");
     914            filelist = process_filelist_and_biggielist(bkpinfo);
     915            /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
     916               the former is a list of regular files; the latter, biggiefiles and imagedevs.
     917             */
     918            if (filelist) {
     919              gotos_suck:
     920                strcpy(tmp, old_restpath);
    934921// (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
    935               if ( popup_and_get_string( "Restore path", "Restore files to where?", tmp, MAX_STR_LEN/4 ) )
    936                 {
    937           if ( !strcmp( tmp, "/" ) )
    938             {
    939               if ( !ask_me_yes_or_no( "Are you sure?" ) )
    940             {
    941               goto gotos_suck;
    942             }
    943               tmp[0] = '\0'; // so we restore to [blank]/file/name :)
    944             }
    945                   strcpy( bkpinfo->restore_path, tmp );
    946           log_msg(1, "Restoring subset");
    947                   retval += restore_everything( bkpinfo, filelist );
    948                   free_filelist( filelist );
    949                 }
    950               else
    951                 {
    952                   strcpy( bkpinfo->restore_path, old_restpath );
    953                   free_filelist( filelist );
    954                 }
    955               if ( !ask_me_yes_or_no( "Restore another subset of your backup?" ) )
    956         {
    957           done = TRUE;
    958         }
    959             }
    960           else
    961             {
    962               done = TRUE;
    963             }
    964     }
    965       strcpy( old_restpath, bkpinfo->restore_path );
    966     }
    967   else
    968     {
    969       mvaddstr_and_log_it( g_currentY++,
    970                0,
    971                "User opted not to restore any data.                                  ");
    972     }
    973   if ( retval )
    974     {
    975       mvaddstr_and_log_it( g_currentY++,
    976                0,
    977                "Errors occurred during the restore phase.            ");
    978     }
    979  
    980   if (ask_me_yes_or_no( "Initialize the boot loader?" ) )
    981     {
    982       run_boot_loader( TRUE );
    983     }
    984   else
    985     {
    986       mvaddstr_and_log_it( g_currentY++,
    987                0,
    988                "User opted not to initialize the boot loader.");
    989     }
     922                if (popup_and_get_string
     923                    ("Restore path", "Restore files to where?", tmp,
     924                     MAX_STR_LEN / 4)) {
     925                    if (!strcmp(tmp, "/")) {
     926                        if (!ask_me_yes_or_no("Are you sure?")) {
     927                            goto gotos_suck;
     928                        }
     929                        tmp[0] = '\0';  // so we restore to [blank]/file/name :)
     930                    }
     931                    strcpy(bkpinfo->restore_path, tmp);
     932                    log_msg(1, "Restoring subset");
     933                    retval += restore_everything(bkpinfo, filelist);
     934                    free_filelist(filelist);
     935                } else {
     936                    strcpy(bkpinfo->restore_path, old_restpath);
     937                    free_filelist(filelist);
     938                }
     939                if (!ask_me_yes_or_no
     940                    ("Restore another subset of your backup?")) {
     941                    done = TRUE;
     942                }
     943            } else {
     944                done = TRUE;
     945            }
     946        }
     947        strcpy(old_restpath, bkpinfo->restore_path);
     948    } else {
     949        mvaddstr_and_log_it(g_currentY++,
     950                            0,
     951                            "User opted not to restore any data.                                  ");
     952    }
     953    if (retval) {
     954        mvaddstr_and_log_it(g_currentY++,
     955                            0,
     956                            "Errors occurred during the restore phase.            ");
     957    }
     958
     959    if (ask_me_yes_or_no("Initialize the boot loader?")) {
     960        run_boot_loader(TRUE);
     961    } else {
     962        mvaddstr_and_log_it(g_currentY++,
     963                            0,
     964                            "User opted not to initialize the boot loader.");
     965    }
    990966
    991967//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
    992   protect_against_braindead_sysadmins();
    993   //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
    994   retval += unmount_all_devices( mountlist );
    995   /*  if (restore_some || restore_all || */
    996   if ( ask_me_yes_or_no( "Label your ext2 and ext3 partitions if necessary?" ) )
    997     {
    998       mvaddstr_and_log_it( g_currentY,
    999                0,
    1000                "Using e2label to label your ext2,3 partitions" );
    1001       if ( does_file_exist( "/tmp/fstab.new" ) )
    1002         {
    1003       strcpy( fstab_fname, "/tmp/fstab.new");
    1004     }
    1005       else
    1006         {
    1007       strcpy( fstab_fname, "/tmp/fstab");
    1008     }
    1009       sprintf( tmp,
    1010            "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname,
    1011            fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
    1012       res=system( tmp );
    1013       if ( res )
    1014     {
    1015       log_to_screen("label-partitions-as-necessary returned an error");
    1016       mvaddstr_and_log_it( g_currentY++, 74, "Failed.");
    1017     }
    1018       else
    1019     {
    1020       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    1021     }
    1022       retval += res;
    1023     }
    1024 
    1025   iamhere("About to leave interactive_mode()");
    1026   if ( retval )
    1027     {
    1028       mvaddstr_and_log_it(g_currentY++,
    1029               0,
    1030               "Warning - errors occurred during the restore phase.");
    1031     }
    1032 end_of_func:
    1033   paranoid_free(tmp);
    1034   paranoid_free(fstab_fname);
    1035   paranoid_free(old_restpath);
    1036   iamhere("Leaving interactive_mode()");
    1037   return( retval );
     968    protect_against_braindead_sysadmins();
     969    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
     970    retval += unmount_all_devices(mountlist);
     971    /*  if (restore_some || restore_all || */
     972    if (ask_me_yes_or_no
     973        ("Label your ext2 and ext3 partitions if necessary?")) {
     974        mvaddstr_and_log_it(g_currentY, 0,
     975                            "Using e2label to label your ext2,3 partitions");
     976        if (does_file_exist("/tmp/fstab.new")) {
     977            strcpy(fstab_fname, "/tmp/fstab.new");
     978        } else {
     979            strcpy(fstab_fname, "/tmp/fstab");
     980        }
     981        sprintf(tmp,
     982                "label-partitions-as-necessary %s < %s >> %s 2>> %s",
     983                g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
     984                MONDO_LOGFILE);
     985        res = system(tmp);
     986        if (res) {
     987            log_to_screen
     988                ("label-partitions-as-necessary returned an error");
     989            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     990        } else {
     991            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     992        }
     993        retval += res;
     994    }
     995
     996    iamhere("About to leave interactive_mode()");
     997    if (retval) {
     998        mvaddstr_and_log_it(g_currentY++,
     999                            0,
     1000                            "Warning - errors occurred during the restore phase.");
     1001    }
     1002  end_of_func:
     1003    paranoid_free(tmp);
     1004    paranoid_free(fstab_fname);
     1005    paranoid_free(old_restpath);
     1006    iamhere("Leaving interactive_mode()");
     1007    return (retval);
    10381008}
     1009
    10391010/**************************************************************************
    10401011 *END_INTERACTIVE_MODE                                                    *
     
    10521023 * @return 0 for success, or the number of errors encountered.
    10531024 */
    1054 int
    1055 iso_mode(struct s_bkpinfo *bkpinfo,
    1056      struct mountlist_itself *mountlist,
    1057      struct raidlist_itself *raidlist,
    1058      bool nuke_me_please)
     1025int
     1026iso_mode(struct s_bkpinfo *bkpinfo,
     1027         struct mountlist_itself *mountlist,
     1028         struct raidlist_itself *raidlist, bool nuke_me_please)
    10591029{
    1060   char c;
    1061   int retval=0;
    1062 
    1063   assert(bkpinfo!=NULL);
    1064   assert(mountlist!=NULL);
    1065   assert(raidlist!=NULL);
    1066   if (iso_fiddly_bits(bkpinfo, nuke_me_please))
    1067     { log_msg(1,"iso_mode --- returning w/ error"); return(1); }
    1068   else
    1069     {
    1070       c=which_restore_mode();
    1071       if (c=='I' || c=='N' || c=='C')
    1072     { interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); }
    1073       if (c=='I') { retval+=interactive_mode(bkpinfo,mountlist,raidlist); }
    1074       else if (c=='N') { retval+=nuke_mode(bkpinfo,mountlist,raidlist); }
    1075       else if (c=='C') { retval+=compare_mode(bkpinfo,mountlist,raidlist); }
    1076       else
    1077     { log_to_screen("OK, I shan't restore/compare any files."); }
    1078     }
    1079   if (is_this_device_mounted(MNT_CDROM)) { paranoid_system("umount "MNT_CDROM); }
     1030    char c;
     1031    int retval = 0;
     1032
     1033    assert(bkpinfo != NULL);
     1034    assert(mountlist != NULL);
     1035    assert(raidlist != NULL);
     1036    if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
     1037        log_msg(1, "iso_mode --- returning w/ error");
     1038        return (1);
     1039    } else {
     1040        c = which_restore_mode();
     1041        if (c == 'I' || c == 'N' || c == 'C') {
     1042            interactively_obtain_media_parameters_from_user(bkpinfo,
     1043                                                            FALSE);
     1044        }
     1045        if (c == 'I') {
     1046            retval += interactive_mode(bkpinfo, mountlist, raidlist);
     1047        } else if (c == 'N') {
     1048            retval += nuke_mode(bkpinfo, mountlist, raidlist);
     1049        } else if (c == 'C') {
     1050            retval += compare_mode(bkpinfo, mountlist, raidlist);
     1051        } else {
     1052            log_to_screen("OK, I shan't restore/compare any files.");
     1053        }
     1054    }
     1055    if (is_this_device_mounted(MNT_CDROM)) {
     1056        paranoid_system("umount " MNT_CDROM);
     1057    }
    10801058//  if (! already_mounted)
    10811059//    {
    1082       if (system("umount /tmp/isodir 2> /dev/null")) { log_to_screen("WARNING - unable to unmount device where the ISO files are stored."); }
     1060    if (system("umount /tmp/isodir 2> /dev/null")) {
     1061        log_to_screen
     1062            ("WARNING - unable to unmount device where the ISO files are stored.");
     1063    }
    10831064//    }
    1084   return( retval );
     1065    return (retval);
    10851066}
     1067
    10861068/**************************************************************************
    10871069 *END_ISO_MODE                                                            *
     
    11031085 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
    11041086 */
    1105 int 
    1106 nuke_mode( struct s_bkpinfo *bkpinfo,
    1107        struct mountlist_itself *mountlist,
    1108        struct raidlist_itself *raidlist )
     1087int
     1088nuke_mode(struct s_bkpinfo *bkpinfo,
     1089          struct mountlist_itself *mountlist,
     1090          struct raidlist_itself *raidlist)
    11091091{
    1110   int retval = 0;
    1111   int res = 0;
    1112   bool boot_loader_installed = FALSE;
     1092    int retval = 0;
     1093    int res = 0;
     1094    bool boot_loader_installed = FALSE;
    11131095  /** malloc **/
    1114   char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], tmpC[MAX_STR_LEN];
    1115 
    1116   assert(bkpinfo!=NULL);
    1117   assert(mountlist!=NULL);
    1118   assert(raidlist!=NULL);
    1119 
    1120   log_msg(2, "nuke_mode --- starting");
    1121 
    1122   get_cfg_file_from_archive_or_bust(bkpinfo);
    1123   load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
     1096    char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
     1097        tmpC[MAX_STR_LEN];
     1098
     1099    assert(bkpinfo != NULL);
     1100    assert(mountlist != NULL);
     1101    assert(raidlist != NULL);
     1102
     1103    log_msg(2, "nuke_mode --- starting");
     1104
     1105    get_cfg_file_from_archive_or_bust(bkpinfo);
     1106    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
    11241107#ifdef __FreeBSD__
    1125   if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
     1108    if (strstr
     1109        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
     1110         "noresize"))
    11261111#else
    1127   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
     1112    if (strstr
     1113        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     1114         "noresize"))
    11281115#endif
    1129     { log_msg(2, "Not resizing mountlist."); }
    1130   else
    1131     { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }
    1132   if (!evaluate_mountlist( mountlist, tmpA, tmpB, tmpC ))
    1133     {
    1134       sprintf(tmp, "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", tmpA, tmpB, tmpC);
    1135       if (ask_me_yes_or_no(tmp) )
    11361116    {
    1137       retval = interactive_mode( bkpinfo, mountlist, raidlist );
    1138       finish(retval);
    1139     }
    1140       else
     1117        log_msg(2, "Not resizing mountlist.");
     1118    } else {
     1119        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
     1120    }
     1121    if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
     1122        sprintf(tmp,
     1123                "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
     1124                tmpA, tmpB, tmpC);
     1125        if (ask_me_yes_or_no(tmp)) {
     1126            retval = interactive_mode(bkpinfo, mountlist, raidlist);
     1127            finish(retval);
     1128        } else {
     1129            fatal_error("Nuke Mode aborted. ");
     1130        }
     1131    }
     1132    save_mountlist_to_disk(mountlist, g_mountlist_fname);
     1133    mvaddstr_and_log_it(1, 30, "Restoring Automatically");
     1134    if (bkpinfo->differential) {
     1135        log_to_screen("Because this is a differential backup, disk");
     1136        log_to_screen("partitioning and formatting will not take place.");
     1137        res = 0;
     1138    } else {
     1139        if (partition_table_contains_Compaq_diagnostic_partition
     1140            (mountlist)) {
     1141            offer_to_abort_because_Compaq_Proliants_suck();
     1142        } else {
     1143            twenty_seconds_til_yikes();
     1144            g_fprep = fopen("/tmp/prep.sh", "w");
     1145#ifdef __FreeBSD__
     1146            if (strstr
     1147                (call_program_and_get_last_line_of_output
     1148                 ("cat /tmp/cmdline"), "nopart"))
     1149#else
     1150            if (strstr
     1151                (call_program_and_get_last_line_of_output
     1152                 ("cat /proc/cmdline"), "nopart"))
     1153#endif
     1154            {
     1155                log_msg(2,
     1156                        "Not partitioning drives due to 'nopart' option.");
     1157                res = 0;
     1158            } else {
     1159                res = partition_everything(mountlist);
     1160                if (res) {
     1161                    log_to_screen
     1162                        ("Warning. Errors occurred during partitioning.");
     1163                    res = 0;
     1164                }
     1165            }
     1166            retval += res;
     1167            if (!res) {
     1168                log_to_screen("Preparing to format your disk(s)");
     1169                sleep(1);
     1170                system("sync");
     1171                log_to_screen("Please wait. This may take a few minutes.");
     1172                res += format_everything(mountlist, FALSE);
     1173            }
     1174            paranoid_fclose(g_fprep);
     1175        }
     1176    }
     1177    retval += res;
     1178    if (res) {
     1179        mvaddstr_and_log_it(g_currentY++,
     1180                            0,
     1181                            "Failed to partition and/or format your hard drives.");
     1182
     1183        if (ask_me_yes_or_no("Try in interactive mode instead?")) {
     1184            retval = interactive_mode(bkpinfo, mountlist, raidlist);
     1185            goto after_the_nuke;
     1186        } else
     1187            if (!ask_me_yes_or_no
     1188                ("Would you like to try to proceed anyway?")) {
     1189            return (retval);
     1190        }
     1191    }
     1192    retval = mount_all_devices(mountlist, TRUE);
     1193    if (retval) {
     1194        unmount_all_devices(mountlist);
     1195        log_to_screen
     1196            ("Unable to mount all partitions. Sorry, I cannot proceed.");
     1197        return (retval);
     1198    }
     1199    iamhere("Restoring everything");
     1200    retval += restore_everything(bkpinfo, NULL);
     1201    if (!run_boot_loader(FALSE)) {
     1202        log_msg(1,
     1203                "Great! Boot loader was installed. No need for msg at end.");
     1204        boot_loader_installed = TRUE;
     1205    }
     1206    protect_against_braindead_sysadmins();
     1207//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
     1208    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
     1209    retval += unmount_all_devices(mountlist);
     1210    mvaddstr_and_log_it(g_currentY,
     1211                        0,
     1212                        "Using e2label to label your ext2,3 partitions");
     1213
     1214    sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
     1215            g_mountlist_fname);
     1216    res = run_program_and_log_output(tmp, TRUE);
     1217    if (res) {
     1218        log_to_screen("label-partitions-as-necessary returned an error");
     1219        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1220    } else {
     1221        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1222    }
     1223    retval += res;
     1224
     1225  after_the_nuke:
     1226    if (retval) {
     1227        log_to_screen("Errors occurred during the nuke phase.");
     1228    } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE"))    // Bruno's thing
    11411229    {
    1142       fatal_error( "Nuke Mode aborted. ");
    1143     }
    1144     }
    1145   save_mountlist_to_disk( mountlist, g_mountlist_fname );
    1146   mvaddstr_and_log_it( 1, 30, "Restoring Automatically" );
    1147   if ( bkpinfo->differential )
    1148     {
    1149       log_to_screen( "Because this is a differential backup, disk" );
    1150       log_to_screen( "partitioning and formatting will not take place." );
    1151       res = 0;
    1152     }
    1153   else
    1154     {     
    1155       if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) )
    1156     {
    1157       offer_to_abort_because_Compaq_Proliants_suck();
    1158     }
    1159       else
    1160     {
    1161       twenty_seconds_til_yikes();
    1162       g_fprep = fopen("/tmp/prep.sh", "w");
    1163 #ifdef __FreeBSD__
    1164       if (strstr (call_program_and_get_last_line_of_output ("cat /tmp/cmdline"), "nopart"))
     1230        log_to_screen
     1231            ("PC was restored successfully. Thank you for using Mondo Rescue.");
     1232        log_to_screen
     1233            ("Please visit http://www.mondorescue.org and thank the dev team.");
     1234    } else {
     1235#ifdef FREELOADER
     1236        success_message();
    11651237#else
    1166       if (strstr (call_program_and_get_last_line_of_output ("cat /proc/cmdline"), "nopart"))
     1238        log_to_screen("PC was restored successfully!");
    11671239#endif
    1168           {
    1169           log_msg (2, "Not partitioning drives due to 'nopart' option.");
    1170           res = 0;
    1171           }
    1172       else
    1173           {
    1174           res = partition_everything( mountlist );
    1175           if (res)
    1176             {
    1177               log_to_screen("Warning. Errors occurred during partitioning.");
    1178               res = 0;
    1179             }
    1180           }
    1181       retval += res;
    1182       if ( !res )
    1183         {
    1184           log_to_screen("Preparing to format your disk(s)");
    1185           sleep(1);
    1186           system("sync");
    1187           log_to_screen("Please wait. This may take a few minutes.");
    1188           res += format_everything( mountlist, FALSE );
    1189         }
    1190       paranoid_fclose(g_fprep);
    1191     }
    1192     }
    1193   retval += res;
    1194   if ( res )
    1195     {
    1196       mvaddstr_and_log_it( g_currentY++,
    1197                0,
    1198                "Failed to partition and/or format your hard drives.");
    1199      
    1200       if ( ask_me_yes_or_no( "Try in interactive mode instead?" ) )
    1201     {
    1202       retval = interactive_mode( bkpinfo, mountlist, raidlist );
    1203       goto after_the_nuke;
    1204     }
    1205       else if ( !ask_me_yes_or_no( "Would you like to try to proceed anyway?" ) )
    1206         {
    1207           return( retval );
    1208     }
    1209     }
    1210   retval = mount_all_devices( mountlist, TRUE );
    1211   if ( retval )
    1212     {
    1213       unmount_all_devices( mountlist );
    1214       log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed.");
    1215       return( retval );
    1216     }
    1217   iamhere("Restoring everything");
    1218   retval += restore_everything( bkpinfo, NULL );
    1219   if (!run_boot_loader( FALSE ))
    1220     {
    1221       log_msg(1, "Great! Boot loader was installed. No need for msg at end.");
    1222       boot_loader_installed = TRUE;
    1223     }
    1224   protect_against_braindead_sysadmins();
    1225 //  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
    1226   //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
    1227   retval += unmount_all_devices( mountlist );
    1228   mvaddstr_and_log_it( g_currentY,
    1229                0,
    1230                "Using e2label to label your ext2,3 partitions");
    1231 
    1232   sprintf( tmp, "label-partitions-as-necessary %s < /tmp/fstab", g_mountlist_fname );
    1233   res = run_program_and_log_output( tmp, TRUE );
    1234   if ( res )
    1235     {
    1236       log_to_screen( "label-partitions-as-necessary returned an error" );
    1237       mvaddstr_and_log_it( g_currentY++, 74, "Failed." );
    1238     }
    1239   else
    1240     {
    1241       mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    1242     }
    1243   retval += res;
    1244 
    1245 after_the_nuke:
    1246   if (retval)
    1247     {
    1248       log_to_screen("Errors occurred during the nuke phase.");
    1249     }
    1250   else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing
    1251     {
    1252       log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue.");
    1253       log_to_screen("Please visit http://www.mondorescue.org and thank the dev team.");
    1254     }
    1255   else
    1256     {
    1257 #ifdef FREELOADER
    1258       success_message();
    1259 #else
    1260       log_to_screen("PC was restored successfully!");
    1261 #endif
    1262     }
    1263   g_I_have_just_nuked = TRUE;
     1240    }
     1241    g_I_have_just_nuked = TRUE;
    12641242/*
    12651243  if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
     
    12691247    }
    12701248*/
    1271   return( retval );
     1249    return (retval);
    12721250}
    12731251
     
    12841262 * @return 0 for success, or the number of errors encountered.
    12851263 */
    1286 int
    1287 restore_to_live_filesystem( struct s_bkpinfo *bkpinfo )
     1264int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
    12881265{
    1289   int retval = 0;
     1266    int retval = 0;
    12901267
    12911268  /** malloc **/
    1292   char *old_restpath;
    1293 
    1294   struct mountlist_itself *mountlist;
     1269    char *old_restpath;
     1270
     1271    struct mountlist_itself *mountlist;
    12951272//  static
    1296   struct raidlist_itself *raidlist;
    1297   struct s_node *filelist;
    1298 
    1299   log_msg(1, "restore_to_live_filesystem() - starting");
    1300   assert(bkpinfo!=NULL);
    1301   malloc_string(old_restpath);
    1302   mountlist = malloc(sizeof(struct mountlist_itself));
    1303   raidlist = malloc(sizeof(struct raidlist_itself));
    1304   if (!mountlist || !raidlist) { fatal_error("Cannot malloc() mountlist and/or raidlist"); }
    1305 
    1306   strcpy(bkpinfo->restore_path, "/");
    1307   if ( !g_restoring_live_from_cd)
    1308     {
    1309       popup_and_OK("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
    1310       sleep( 1 );
    1311     }
    1312   interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    1313   log_msg(2,  "bkpinfo->media_device = %s", bkpinfo->media_device );
    1314   if ( !bkpinfo->media_device[0] )
    1315     {
    1316       log_msg(2, "Warning - failed to find media dev");
    1317     }
    1318 
    1319 
    1320   log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
    1321 
    1322   open_evalcall_form("Thinking...");
    1323 
    1324   get_cfg_file_from_archive_or_bust ( bkpinfo );
    1325   read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    1326   load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
    1327  
    1328   close_evalcall_form();
    1329   retval = load_mountlist(mountlist, g_mountlist_fname );
    1330   load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME );
    1331   filelist = process_filelist_and_biggielist( bkpinfo );
    1332   if ( filelist )
    1333     {
    1334       save_filelist(filelist, "/tmp/selected-files.txt");
    1335       strcpy( old_restpath, bkpinfo->restore_path );
    1336       if ( popup_and_get_string( "Restore path",
    1337                  "Restore files to where? )",
    1338                  bkpinfo->restore_path, MAX_STR_LEN/4 ) )
    1339         {
    1340       iamhere("Restoring everything");
    1341           retval += restore_everything( bkpinfo, filelist );
    1342           free_filelist( filelist );
    1343           strcpy(bkpinfo->restore_path, old_restpath);
    1344         }
    1345       else
    1346         {
    1347           free_filelist(filelist);
    1348         }
    1349       strcpy(bkpinfo->restore_path, old_restpath);
    1350     }
    1351   if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) )
    1352     {
    1353       log_msg(2, "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
    1354     }
    1355   run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    1356   if (!bkpinfo->please_dont_eject) { eject_device( bkpinfo->media_device ); }
    1357   paranoid_free(old_restpath);
    1358   free(mountlist);
    1359   free(raidlist);
    1360   return( retval );
     1273    struct raidlist_itself *raidlist;
     1274    struct s_node *filelist;
     1275
     1276    log_msg(1, "restore_to_live_filesystem() - starting");
     1277    assert(bkpinfo != NULL);
     1278    malloc_string(old_restpath);
     1279    mountlist = malloc(sizeof(struct mountlist_itself));
     1280    raidlist = malloc(sizeof(struct raidlist_itself));
     1281    if (!mountlist || !raidlist) {
     1282        fatal_error("Cannot malloc() mountlist and/or raidlist");
     1283    }
     1284
     1285    strcpy(bkpinfo->restore_path, "/");
     1286    if (!g_restoring_live_from_cd) {
     1287        popup_and_OK
     1288            ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
     1289        sleep(1);
     1290    }
     1291    interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     1292    log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
     1293    if (!bkpinfo->media_device[0]) {
     1294        log_msg(2, "Warning - failed to find media dev");
     1295    }
     1296
     1297
     1298    log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
     1299
     1300    open_evalcall_form("Thinking...");
     1301
     1302    get_cfg_file_from_archive_or_bust(bkpinfo);
     1303    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     1304    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo
     1305
     1306    close_evalcall_form();
     1307    retval = load_mountlist(mountlist, g_mountlist_fname);
     1308    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     1309    filelist = process_filelist_and_biggielist(bkpinfo);
     1310    if (filelist) {
     1311        save_filelist(filelist, "/tmp/selected-files.txt");
     1312        strcpy(old_restpath, bkpinfo->restore_path);
     1313        if (popup_and_get_string("Restore path",
     1314                                 "Restore files to where? )",
     1315                                 bkpinfo->restore_path, MAX_STR_LEN / 4)) {
     1316            iamhere("Restoring everything");
     1317            retval += restore_everything(bkpinfo, filelist);
     1318            free_filelist(filelist);
     1319            strcpy(bkpinfo->restore_path, old_restpath);
     1320        } else {
     1321            free_filelist(filelist);
     1322        }
     1323        strcpy(bkpinfo->restore_path, old_restpath);
     1324    }
     1325    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1326        log_msg(2,
     1327                "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
     1328    }
     1329    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1330    if (!bkpinfo->please_dont_eject) {
     1331        eject_device(bkpinfo->media_device);
     1332    }
     1333    paranoid_free(old_restpath);
     1334    free(mountlist);
     1335    free(raidlist);
     1336    return (retval);
    13611337}
    13621338
     
    13861362int
    13871363restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
    1388                  long bigfileno,
    1389                  struct s_node*filelist, char*pathname_of_last_file_restored)
     1364                             long bigfileno,
     1365                             struct s_node *filelist,
     1366                             char *pathname_of_last_file_restored)
    13901367{
    1391   FILE *fin;
    1392   FILE *fout;
    1393   FILE *fbzip2;
    1394  
     1368    FILE *fin;
     1369    FILE *fout;
     1370    FILE *fbzip2;
     1371
    13951372  /** malloc ***/
    1396   char *checksum, *outfile_fname, *tmp, *bzip2_command, *partimagehack_command, *suffix, *sz_devfile;
    1397   char *bigblk;
    1398   char *p;
    1399   int retval = 0;
    1400   int finished = FALSE;
    1401   long sliceno;
    1402   long siz;
    1403   char partimagehack_fifo[MAX_STR_LEN];
    1404   char *file_to_openout = NULL;
    1405   struct s_filename_and_lstat_info biggiestruct;
    1406   struct utimbuf the_utime_buf, *ubuf;
    1407   bool use_partimage_hack=FALSE;
    1408   pid_t pid;
    1409   int res=0;
    1410   int old_loglevel;
    1411   char sz_msg[MAX_STR_LEN];
    1412   struct s_node *node;
    1413 
    1414   old_loglevel = g_loglevel;
    1415   ubuf = &the_utime_buf;
    1416   assert(bkpinfo!=NULL);
    1417 
    1418   malloc_string(checksum);
    1419   malloc_string(outfile_fname);
    1420   malloc_string(tmp);
    1421   malloc_string(bzip2_command);
    1422   malloc_string(partimagehack_command);
    1423   malloc_string(suffix);
    1424   malloc_string(sz_devfile);
    1425 
    1426   pathname_of_last_file_restored[0] = '\0';
    1427   if( !(bigblk = malloc( TAPE_BLOCK_SIZE ) ) )
    1428     {
    1429       fatal_error("Cannot malloc bigblk");
    1430     }
    1431 
    1432   if ( !(fin = fopen( slice_fname( bigfileno, 0, ARCHIVES_PATH, ""), "r" ) ) )
    1433     {
    1434       log_to_screen( "Cannot even open bigfile's info file" );
    1435       return( 1 );
    1436     }
    1437 
    1438   memset((void*)&biggiestruct, 0, sizeof(biggiestruct));
    1439   if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct))
    1440     {
    1441       log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", bigfileno+1);
    1442     }
    1443   paranoid_fclose(fin);
    1444 
    1445   strcpy(checksum, biggiestruct.checksum);
    1446 
    1447   if ( !checksum[0])
    1448     {
    1449       sprintf(tmp,"Warning - bigfile %ld does not have a checksum",bigfileno+1);
    1450       log_msg(3, tmp);
    1451       p = checksum;
    1452     }
    1453 
    1454   if (!strncmp ( biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
    1455     { strcpy( outfile_fname, biggiestruct.filename); }
    1456   else
    1457     { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename ); }
    1458 
    1459   /* skip file if we have a selective restore subset & it doesn't match */
    1460   if (filelist != NULL)
    1461     {
    1462       node = find_string_at_node(filelist, biggiestruct.filename);
    1463       if (!node)
    1464         {
    1465           log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
    1466           pathname_of_last_file_restored[0] = '\0';
    1467       return (0);
    1468         }
    1469       else if (!(node->selected))
    1470         {
    1471       log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
    1472           pathname_of_last_file_restored[0] = '\0';
    1473           return( 0 );
    1474         }
    1475     }
    1476   /* otherwise, continue */
    1477  
    1478   log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    1479   if (biggiestruct.use_partimagehack)
    1480     {
    1481       if (strncmp ( biggiestruct.filename, "/dev/", 5))
    1482         {
    1483       log_msg(1, "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
    1484       log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    1485       biggiestruct.use_partimagehack = FALSE;
    1486     }
    1487     }
    1488 
    1489   if (biggiestruct.use_partimagehack) // if it's an NTFS device
     1373    char *checksum, *outfile_fname, *tmp, *bzip2_command,
     1374        *partimagehack_command, *suffix, *sz_devfile;
     1375    char *bigblk;
     1376    char *p;
     1377    int retval = 0;
     1378    int finished = FALSE;
     1379    long sliceno;
     1380    long siz;
     1381    char partimagehack_fifo[MAX_STR_LEN];
     1382    char *file_to_openout = NULL;
     1383    struct s_filename_and_lstat_info biggiestruct;
     1384    struct utimbuf the_utime_buf, *ubuf;
     1385    bool use_partimage_hack = FALSE;
     1386    pid_t pid;
     1387    int res = 0;
     1388    int old_loglevel;
     1389    char sz_msg[MAX_STR_LEN];
     1390    struct s_node *node;
     1391
     1392    old_loglevel = g_loglevel;
     1393    ubuf = &the_utime_buf;
     1394    assert(bkpinfo != NULL);
     1395
     1396    malloc_string(checksum);
     1397    malloc_string(outfile_fname);
     1398    malloc_string(tmp);
     1399    malloc_string(bzip2_command);
     1400    malloc_string(partimagehack_command);
     1401    malloc_string(suffix);
     1402    malloc_string(sz_devfile);
     1403
     1404    pathname_of_last_file_restored[0] = '\0';
     1405    if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
     1406        fatal_error("Cannot malloc bigblk");
     1407    }
     1408
     1409    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
     1410        log_to_screen("Cannot even open bigfile's info file");
     1411        return (1);
     1412    }
     1413
     1414    memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
     1415    if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
     1416        sizeof(biggiestruct)) {
     1417        log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
     1418                bigfileno + 1);
     1419    }
     1420    paranoid_fclose(fin);
     1421
     1422    strcpy(checksum, biggiestruct.checksum);
     1423
     1424    if (!checksum[0]) {
     1425        sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
     1426                bigfileno + 1);
     1427        log_msg(3, tmp);
     1428        p = checksum;
     1429    }
     1430
     1431    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
     1432    {
     1433        strcpy(outfile_fname, biggiestruct.filename);
     1434    } else {
     1435        sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
     1436                biggiestruct.filename);
     1437    }
     1438
     1439    /* skip file if we have a selective restore subset & it doesn't match */
     1440    if (filelist != NULL) {
     1441        node = find_string_at_node(filelist, biggiestruct.filename);
     1442        if (!node) {
     1443            log_msg(0, "Skipping %s (name isn't in filelist)",
     1444                    biggiestruct.filename);
     1445            pathname_of_last_file_restored[0] = '\0';
     1446            return (0);
     1447        } else if (!(node->selected)) {
     1448            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
     1449                    biggiestruct.filename);
     1450            pathname_of_last_file_restored[0] = '\0';
     1451            return (0);
     1452        }
     1453    }
     1454    /* otherwise, continue */
     1455
     1456    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
     1457    if (biggiestruct.use_partimagehack) {
     1458        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
     1459            log_msg(1,
     1460                    "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
     1461            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
     1462            biggiestruct.use_partimagehack = FALSE;
     1463        }
     1464    }
     1465
     1466    if (biggiestruct.use_partimagehack) // if it's an NTFS device
    14901467//  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    1491     {
    1492       g_loglevel = 4;
    1493       use_partimage_hack = TRUE;
    1494       log_msg(2, "Calling partimagehack in background because %s is an NTFS /dev entry", outfile_fname);
    1495       sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    1496       mkfifo(sz_devfile, 0x770);
    1497       strcpy(partimagehack_fifo, sz_devfile);
    1498       file_to_openout = partimagehack_fifo;
    1499       switch(pid=fork())
    1500                 {
    1501                   case -1: fatal_error("Fork failure");
    1502               case 0:
    1503             log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", biggiestruct.filename, partimagehack_fifo);
    1504             res=feed_outfrom_partimage(biggiestruct.filename, partimagehack_fifo);
    1505 //          log_msg(3, "CHILD - fip - exiting");
    1506             exit(res);
    1507             break;
    1508                   default:
    1509             log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    1510                 }
    1511     }
    1512   else
    1513     {
    1514       use_partimage_hack = FALSE;
    1515       partimagehack_fifo[0] = '\0';
    1516       file_to_openout = outfile_fname;
    1517       if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way
    1518        { make_hole_for_file( outfile_fname ); }
    1519     }
    1520 
    1521   sprintf( tmp, "Reassembling big file %ld (%s)", bigfileno+1, outfile_fname );
    1522   log_msg(2, tmp );
    1523 
    1524   /*
    1525     last slice is zero-length and uncompressed; when we find it, we stop.
    1526     We DON'T wait until there are no more slices; if we did that,
    1527     We might stop at end of CD, not at last slice (which is 0-len and uncompd)
    1528   */
    1529 
    1530   strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN-1);
    1531   pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';
    1532 
    1533   log_msg(3, "file_to_openout = %s", file_to_openout);
    1534   if ( !(fout = fopen( file_to_openout, "w" ) ) )
    1535     {
    1536       log_to_screen( "Cannot openout outfile_fname - hard disk full?");
    1537       return(1);
    1538     }
    1539   log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
    1540 
    1541   for( sliceno = 1, finished = FALSE; !finished; )
    1542     {
    1543       if ( !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"lzo")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"bz2")))
    15441468    {
    1545       log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
    1546       g_current_media_number++;
    1547       sprintf( tmp, "Asking for %s #%d so that I may read slice #%ld\n",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number,sliceno);
    1548       log_msg(2,  tmp );
    1549       sprintf( tmp, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number );
    1550       log_to_screen( tmp );
    1551       insist_on_this_cd_number( bkpinfo, g_current_media_number );
    1552       log_to_screen( "Continuing to restore.");
    1553     }
    1554       else
    1555     {
    1556       strcpy(tmp, slice_fname(bigfileno,sliceno,ARCHIVES_PATH,""));
    1557       if (does_file_exist(tmp) && length_of_file(tmp) == 0)
    1558         {
    1559           log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno );
    1560           finished = TRUE;
    1561               continue;
    1562         }
    1563       else
    1564         {
    1565           if ( does_file_exist(slice_fname(bigfileno, sliceno,ARCHIVES_PATH, "lzo" ) ) )
     1469        g_loglevel = 4;
     1470        use_partimage_hack = TRUE;
     1471        log_msg(2,
     1472                "Calling partimagehack in background because %s is an NTFS /dev entry",
     1473                outfile_fname);
     1474        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
     1475                (int) (random() % 32768));
     1476        mkfifo(sz_devfile, 0x770);
     1477        strcpy(partimagehack_fifo, sz_devfile);
     1478        file_to_openout = partimagehack_fifo;
     1479        switch (pid = fork()) {
     1480        case -1:
     1481            fatal_error("Fork failure");
     1482        case 0:
     1483            log_msg(3,
     1484                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
     1485                    biggiestruct.filename, partimagehack_fifo);
     1486            res =
     1487                feed_outfrom_partimage(biggiestruct.filename,
     1488                                       partimagehack_fifo);
     1489//          log_msg(3, "CHILD - fip - exiting");
     1490            exit(res);
     1491            break;
     1492        default:
     1493            log_msg(3,
     1494                    "feed_into_partimage() called in background --- pid=%ld",
     1495                    (long int) (pid));
     1496        }
     1497    } else {
     1498        use_partimage_hack = FALSE;
     1499        partimagehack_fifo[0] = '\0';
     1500        file_to_openout = outfile_fname;
     1501        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
    15661502        {
    1567           strcpy( bzip2_command, "lzop" );
    1568           strcpy( suffix, "lzo");
    1569         }
    1570           else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "bz2" ) ) )
    1571         {
    1572           strcpy( bzip2_command, "bzip2" );
    1573           strcpy( suffix, "bz2");
    1574         }
    1575           else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "" ) ) )
    1576         {
    1577           strcpy( bzip2_command, "" );
    1578           strcpy( suffix, "");
    1579         }
    1580           else
    1581         {
    1582           log_to_screen( "OK, that's pretty fsck0red...");
    1583           return( 1 );
    1584         }
    1585         }
    1586           if ( bzip2_command[0] != '\0' )
    1587             {
    1588           sprintf( bzip2_command + strlen( bzip2_command ),
    1589                " -dc %s 2>> %s",
    1590                slice_fname( bigfileno, sliceno, ARCHIVES_PATH, suffix),
    1591                MONDO_LOGFILE);
    1592         }
    1593           else
    1594             {
    1595           sprintf( bzip2_command, "cat %s 2>> %s",
    1596                slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix ),
    1597                MONDO_LOGFILE );
    1598         }
    1599       sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number, bigfileno + 1, sliceno );
    1600           log_msg(2, tmp );
    1601 
    1602           if (!g_text_mode)
    1603             {
    1604               newtDrawRootText( 0, g_noof_rows - 2, tmp );
    1605               newtRefresh();
    1606               strip_spaces( tmp );
    1607               update_progress_form( tmp );
    1608             }
    1609       if ( !(fbzip2 = popen( bzip2_command, "r" ) ) )
    1610         {
    1611           fatal_error( "Can't run popen command");
    1612         }
    1613       while( !feof( fbzip2 ) )
    1614         {
    1615           siz = fread( bigblk, 1, TAPE_BLOCK_SIZE, fbzip2 );
    1616           if (siz > 0)
    1617         {
    1618                   sprintf(sz_msg, "Read %ld from fbzip2", siz);
    1619           siz = fwrite( bigblk, 1, siz, fout);
    1620                   sprintf(sz_msg + strlen(sz_msg), "; written %ld to fout", siz);
    1621 //        log_msg(2. sz_msg);
    1622         }
    1623         }
    1624       paranoid_pclose(fbzip2);
    1625 
    1626 
    1627           sliceno++;
    1628           g_current_progress++;
    1629         }
    1630     }
     1503            make_hole_for_file(outfile_fname);
     1504        }
     1505    }
     1506
     1507    sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
     1508            outfile_fname);
     1509    log_msg(2, tmp);
     1510
     1511    /*
     1512       last slice is zero-length and uncompressed; when we find it, we stop.
     1513       We DON'T wait until there are no more slices; if we did that,
     1514       We might stop at end of CD, not at last slice (which is 0-len and uncompd)
     1515     */
     1516
     1517    strncpy(pathname_of_last_file_restored, biggiestruct.filename,
     1518            MAX_STR_LEN - 1);
     1519    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
     1520
     1521    log_msg(3, "file_to_openout = %s", file_to_openout);
     1522    if (!(fout = fopen(file_to_openout, "w"))) {
     1523        log_to_screen("Cannot openout outfile_fname - hard disk full?");
     1524        return (1);
     1525    }
     1526    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
     1527
     1528    for (sliceno = 1, finished = FALSE; !finished;) {
     1529        if (!does_file_exist
     1530            (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
     1531            &&
     1532            !does_file_exist(slice_fname
     1533                             (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
     1534            &&
     1535            !does_file_exist(slice_fname
     1536                             (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1537            log_msg(3,
     1538                    "Cannot find a data slice or terminator slice on CD %d",
     1539                    g_current_media_number);
     1540            g_current_media_number++;
     1541            sprintf(tmp,
     1542                    "Asking for %s #%d so that I may read slice #%ld\n",
     1543                    media_descriptor_string(bkpinfo->backup_media_type),
     1544                    g_current_media_number, sliceno);
     1545            log_msg(2, tmp);
     1546            sprintf(tmp, "Restoring from %s #%d",
     1547                    media_descriptor_string(bkpinfo->backup_media_type),
     1548                    g_current_media_number);
     1549            log_to_screen(tmp);
     1550            insist_on_this_cd_number(bkpinfo, g_current_media_number);
     1551            log_to_screen("Continuing to restore.");
     1552        } else {
     1553            strcpy(tmp,
     1554                   slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
     1555            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
     1556                log_msg(2,
     1557                        "End of bigfile # %ld (slice %ld is the terminator)",
     1558                        bigfileno + 1, sliceno);
     1559                finished = TRUE;
     1560                continue;
     1561            } else {
     1562                if (does_file_exist
     1563                    (slice_fname
     1564                     (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
     1565                    strcpy(bzip2_command, "lzop");
     1566                    strcpy(suffix, "lzo");
     1567                } else
     1568                    if (does_file_exist
     1569                        (slice_fname
     1570                         (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1571                    strcpy(bzip2_command, "bzip2");
     1572                    strcpy(suffix, "bz2");
     1573                } else
     1574                    if (does_file_exist
     1575                        (slice_fname
     1576                         (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
     1577                    strcpy(bzip2_command, "");
     1578                    strcpy(suffix, "");
     1579                } else {
     1580                    log_to_screen("OK, that's pretty fsck0red...");
     1581                    return (1);
     1582                }
     1583            }
     1584            if (bzip2_command[0] != '\0') {
     1585                sprintf(bzip2_command + strlen(bzip2_command),
     1586                        " -dc %s 2>> %s",
     1587                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
     1588                                    suffix), MONDO_LOGFILE);
     1589            } else {
     1590                sprintf(bzip2_command, "cat %s 2>> %s",
     1591                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
     1592                                    suffix), MONDO_LOGFILE);
     1593            }
     1594            sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ",
     1595                    media_descriptor_string(bkpinfo->backup_media_type),
     1596                    g_current_media_number, bigfileno + 1, sliceno);
     1597            log_msg(2, tmp);
     1598
     1599            if (!g_text_mode) {
     1600                newtDrawRootText(0, g_noof_rows - 2, tmp);
     1601                newtRefresh();
     1602                strip_spaces(tmp);
     1603                update_progress_form(tmp);
     1604            }
     1605            if (!(fbzip2 = popen(bzip2_command, "r"))) {
     1606                fatal_error("Can't run popen command");
     1607            }
     1608            while (!feof(fbzip2)) {
     1609                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
     1610                if (siz > 0) {
     1611                    sprintf(sz_msg, "Read %ld from fbzip2", siz);
     1612                    siz = fwrite(bigblk, 1, siz, fout);
     1613                    sprintf(sz_msg + strlen(sz_msg),
     1614                            "; written %ld to fout", siz);
     1615//        log_msg(2. sz_msg);
     1616                }
     1617            }
     1618            paranoid_pclose(fbzip2);
     1619
     1620
     1621            sliceno++;
     1622            g_current_progress++;
     1623        }
     1624    }
    16311625/*
    16321626  memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
     
    16361630  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    16371631*/
    1638   paranoid_fclose( fout );
    1639   g_loglevel = old_loglevel;
    1640 
    1641   if (use_partimage_hack)
    1642     {
    1643       log_msg(3, "Waiting for partimage to finish");
    1644       sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
    1645       while(system(tmp) == 0)
    1646         { sleep(1); }
    1647       log_it("OK, partimage has really finished");
    1648     }
    1649 
    1650   if (strcmp(outfile_fname, "/dev/null"))
    1651     {
    1652       chown( outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid );
    1653       chmod( outfile_fname, biggiestruct.properties.st_mode );
    1654       ubuf->actime = biggiestruct.properties.st_atime;
    1655       ubuf->modtime= biggiestruct.properties.st_mtime;
    1656       utime( outfile_fname, ubuf );
    1657     }
    1658   paranoid_free( bigblk );
    1659   paranoid_free(checksum);
    1660   paranoid_free(outfile_fname);
    1661   paranoid_free(tmp);
    1662   paranoid_free(bzip2_command);
    1663   paranoid_free(partimagehack_command);
    1664   paranoid_free(suffix);
    1665   paranoid_free(sz_devfile);
    1666 
    1667   return( retval );
     1632    paranoid_fclose(fout);
     1633    g_loglevel = old_loglevel;
     1634
     1635    if (use_partimage_hack) {
     1636        log_msg(3, "Waiting for partimage to finish");
     1637        sprintf(tmp,
     1638                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
     1639        while (system(tmp) == 0) {
     1640            sleep(1);
     1641        }
     1642        log_it("OK, partimage has really finished");
     1643    }
     1644
     1645    if (strcmp(outfile_fname, "/dev/null")) {
     1646        chown(outfile_fname, biggiestruct.properties.st_uid,
     1647              biggiestruct.properties.st_gid);
     1648        chmod(outfile_fname, biggiestruct.properties.st_mode);
     1649        ubuf->actime = biggiestruct.properties.st_atime;
     1650        ubuf->modtime = biggiestruct.properties.st_mtime;
     1651        utime(outfile_fname, ubuf);
     1652    }
     1653    paranoid_free(bigblk);
     1654    paranoid_free(checksum);
     1655    paranoid_free(outfile_fname);
     1656    paranoid_free(tmp);
     1657    paranoid_free(bzip2_command);
     1658    paranoid_free(partimagehack_command);
     1659    paranoid_free(suffix);
     1660    paranoid_free(sz_devfile);
     1661
     1662    return (retval);
    16681663}
    16691664
     
    16881683 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
    16891684 */
    1690 int
    1691 restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
    1692                  char *orig_bf_fname,
    1693                  long biggiefile_number,
    1694                  char *orig_checksum, //UNUSED
    1695                  long long biggiefile_size, //UNUSED
    1696                  struct s_node *filelist, int use_partimagehack,
    1697                  char*pathname_of_last_file_restored)
     1685int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum,   //UNUSED
     1686                                     long long biggiefile_size, //UNUSED
     1687                                     struct s_node *filelist,
     1688                                     int use_partimagehack,
     1689                                     char *pathname_of_last_file_restored)
    16981690{
    1699   FILE *pout;
    1700   FILE *fin;
     1691    FILE *pout;
     1692    FILE *fin;
    17011693
    17021694  /** mallocs ********/
    1703   char *tmp;
    1704   char *command;
    1705   char *outfile_fname;
    1706   char *partimagehack_command;
    1707   char *sz_devfile;
    1708   char *partimagehack_fifo;
    1709   char *file_to_openout = NULL;
    1710 
    1711   struct s_node *node;
    1712 
    1713   int old_loglevel;
    1714   long current_slice_number = 0;
    1715   int retval = 0;
    1716   int res = 0;
    1717   int ctrl_chr = '\0';
    1718   long long slice_siz;
    1719   bool dummy_restore = FALSE;
    1720   bool use_partimage_hack=FALSE;
    1721   pid_t pid;
    1722   struct s_filename_and_lstat_info biggiestruct;
    1723   struct utimbuf the_utime_buf, *ubuf;
    1724   ubuf = &the_utime_buf;
    1725 
    1726   malloc_string(tmp);
    1727   malloc_string(partimagehack_fifo);
    1728   malloc_string(outfile_fname);
    1729   malloc_string(command);
    1730   malloc_string(sz_devfile);
    1731   malloc_string(partimagehack_command);
    1732   old_loglevel = g_loglevel;
    1733   assert(bkpinfo!=NULL);
    1734   assert(orig_bf_fname!=NULL);
    1735   assert(orig_checksum!=NULL);
    1736 
    1737   pathname_of_last_file_restored[0] = '\0';
    1738   if (use_partimagehack == BLK_START_A_PIHBIGGIE)
    1739     {
    1740       use_partimagehack = 1;
    1741       log_msg(1, "%s --- pih=YES", orig_bf_fname);
    1742     }
    1743   else if (use_partimagehack == BLK_START_A_NORMBIGGIE)
    1744     {
    1745       use_partimagehack = 0;
    1746       log_msg(1, "%s --- pih=NO", orig_bf_fname);
    1747     }
    1748   else
    1749     {
    1750       use_partimagehack = 0;
    1751       log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
    1752     }
    1753  
    1754   strncpy(pathname_of_last_file_restored, orig_bf_fname, MAX_STR_LEN-1);
    1755   pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';
    1756  
    1757   /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
    1758 
    1759   if (filelist != NULL)
    1760     {
    1761       node = find_string_at_node(filelist, orig_bf_fname);
    1762       if (!node)
    1763         {
    1764           dummy_restore = TRUE;
    1765           log_msg(1, "Skipping big file %ld (%s) - not in biggielist subset", biggiefile_number+1, orig_bf_fname);
    1766           pathname_of_last_file_restored[0] = '\0';
    1767         }
    1768       else if (!(node->selected))
    1769         {
    1770           dummy_restore = TRUE;
    1771       log_msg(1, "Skipping %s (name isn't in biggielist subset)", orig_bf_fname);
    1772           pathname_of_last_file_restored[0] = '\0';
    1773         }
    1774     }
    1775 
    1776   if (use_partimagehack)
    1777     {
    1778       if (strncmp ( orig_bf_fname, "/dev/", 5))
    1779         {
    1780       log_msg(1, "I was in error when I set use_partimagehack to TRUE.");
    1781       log_msg(1, "%s isn't even in /dev", orig_bf_fname);
    1782       use_partimagehack = FALSE;
    1783     }
    1784     }
    1785 
    1786   if (use_partimagehack)
    1787     {
    1788       g_loglevel = 4;
    1789       strcpy(outfile_fname, orig_bf_fname);
    1790       use_partimage_hack = TRUE;
    1791       log_msg(2, "Calling partimagehack in background because %s is a /dev entry", outfile_fname);
    1792       sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));
    1793       mkfifo(sz_devfile, 0x770);
    1794       strcpy(partimagehack_fifo, sz_devfile);
    1795       file_to_openout = partimagehack_fifo;
    1796       switch(pid=fork())
    1797                 {
    1798                   case -1: fatal_error("Fork failure");
    1799               case 0:
    1800             log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", outfile_fname, partimagehack_fifo);
    1801             res=feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
    1802 //          log_msg(3, "CHILD - fip - exiting");
    1803             exit(res);
    1804             break;
    1805                   default:
    1806             log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));
    1807                 }
    1808     }
    1809   else
    1810     {
    1811       if (!strncmp ( orig_bf_fname, "/dev/", 5)) // non-NTFS partition
    1812         { strcpy(outfile_fname, orig_bf_fname); }
    1813       else // biggiefile
    1814         { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname ); }
    1815       use_partimage_hack = FALSE;
    1816       partimagehack_fifo[0] = '\0';
    1817       file_to_openout = outfile_fname;
    1818       if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way
    1819        { make_hole_for_file( outfile_fname ); }
    1820       sprintf(tmp, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname );
    1821       log_msg(2, tmp );
    1822     }
    1823  
    1824   if (dummy_restore)
    1825     { sprintf( outfile_fname, "/dev/null" ); }
    1826    
    1827   if ( !bkpinfo->zip_exe[0] )
    1828     {
    1829       sprintf(command, "cat > \"%s\"", file_to_openout);
    1830     }
    1831   else
    1832     {
    1833       sprintf(command,"%s -dc > \"%s\" 2>> %s",bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
    1834     }
    1835   sprintf(tmp,"Pipe command = '%s'",command);
    1836   log_msg(3, tmp);
    1837 
    1838   /* restore biggiefile, one slice at a time */
    1839   if ( !( pout = popen(command, "w" ) ) )
    1840     {
    1841       fatal_error( "Cannot pipe out" );
    1842     }
    1843   for( res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr); ctrl_chr!=BLK_STOP_A_BIGGIE; res=read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr ) )
    1844     {
    1845       if ( ctrl_chr != BLK_START_AN_AFIO_OR_SLICE )
    1846     {
    1847       wrong_marker( BLK_START_AN_AFIO_OR_SLICE,ctrl_chr );
    1848     }
    1849       sprintf( tmp,"Working on file #%ld, slice #%ld    ",
    1850            biggiefile_number + 1,
    1851            current_slice_number);
    1852       log_msg(2, tmp);
    1853       if (!g_text_mode)
    1854         {
    1855           newtDrawRootText( 0, g_noof_rows - 2, tmp);
    1856           newtRefresh();
    1857         }
    1858       strip_spaces( tmp );
    1859       update_progress_form( tmp );
    1860       if ( current_slice_number == 0 )
    1861         {
    1862           res = read_file_from_stream_to_file( bkpinfo,"/tmp/biggie-blah.txt",slice_siz);
    1863           if (!(fin = fopen("/tmp/biggie-blah.txt", "r")))
    1864             { log_OS_error("blah blah"); }
    1865           else
    1866             {
    1867               if ( fread( (void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct))
    1868                 {
    1869                   log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", biggiefile_number + 1);
    1870                 }
    1871               paranoid_fclose(fin);
    1872             }
    1873     }
    1874       else
    1875         {
    1876           res = read_file_from_stream_to_stream( bkpinfo, pout, slice_siz );
    1877         }
    1878       retval += res;
    1879       res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr );
    1880       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE)
    1881     {
    1882       wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
    1883     }
    1884       current_slice_number++;
    1885       g_current_progress++;
    1886     }
    1887   paranoid_pclose(pout);
    1888  
    1889   log_msg(1, "pathname_of_last_file_restored is now %s", pathname_of_last_file_restored);
    1890 
    1891   if (use_partimage_hack)
    1892     {
    1893       log_msg(3, "Waiting for partimage to finish");
    1894       sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
    1895       while(system(tmp) == 0)
    1896         { sleep(1); }
    1897       log_msg(3, "OK, partimage has really finished");
    1898     }
    1899 
    1900   log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
    1901   log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
    1902   if (strcmp(outfile_fname, "/dev/null"))
    1903     {
    1904       chmod(outfile_fname, biggiestruct.properties.st_mode);
    1905       chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid);
    1906       ubuf->actime = biggiestruct.properties.st_atime;
    1907       ubuf->modtime= biggiestruct.properties.st_mtime;
    1908       utime( outfile_fname, ubuf );
    1909     }
    1910 
    1911   paranoid_free(tmp);
    1912   paranoid_free(outfile_fname);
    1913   paranoid_free(command);
    1914   paranoid_free(partimagehack_command);
    1915   paranoid_free(sz_devfile);
    1916   paranoid_free(partimagehack_fifo);
    1917   g_loglevel = old_loglevel;
    1918   return(retval);
     1695    char *tmp;
     1696    char *command;
     1697    char *outfile_fname;
     1698    char *partimagehack_command;
     1699    char *sz_devfile;
     1700    char *partimagehack_fifo;
     1701    char *file_to_openout = NULL;
     1702
     1703    struct s_node *node;
     1704
     1705    int old_loglevel;
     1706    long current_slice_number = 0;
     1707    int retval = 0;
     1708    int res = 0;
     1709    int ctrl_chr = '\0';
     1710    long long slice_siz;
     1711    bool dummy_restore = FALSE;
     1712    bool use_partimage_hack = FALSE;
     1713    pid_t pid;
     1714    struct s_filename_and_lstat_info biggiestruct;
     1715    struct utimbuf the_utime_buf, *ubuf;
     1716    ubuf = &the_utime_buf;
     1717
     1718    malloc_string(tmp);
     1719    malloc_string(partimagehack_fifo);
     1720    malloc_string(outfile_fname);
     1721    malloc_string(command);
     1722    malloc_string(sz_devfile);
     1723    malloc_string(partimagehack_command);
     1724    old_loglevel = g_loglevel;
     1725    assert(bkpinfo != NULL);
     1726    assert(orig_bf_fname != NULL);
     1727    assert(orig_checksum != NULL);
     1728
     1729    pathname_of_last_file_restored[0] = '\0';
     1730    if (use_partimagehack == BLK_START_A_PIHBIGGIE) {
     1731        use_partimagehack = 1;
     1732        log_msg(1, "%s --- pih=YES", orig_bf_fname);
     1733    } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) {
     1734        use_partimagehack = 0;
     1735        log_msg(1, "%s --- pih=NO", orig_bf_fname);
     1736    } else {
     1737        use_partimagehack = 0;
     1738        log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
     1739    }
     1740
     1741    strncpy(pathname_of_last_file_restored, orig_bf_fname,
     1742            MAX_STR_LEN - 1);
     1743    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
     1744
     1745    /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
     1746
     1747    if (filelist != NULL) {
     1748        node = find_string_at_node(filelist, orig_bf_fname);
     1749        if (!node) {
     1750            dummy_restore = TRUE;
     1751            log_msg(1,
     1752                    "Skipping big file %ld (%s) - not in biggielist subset",
     1753                    biggiefile_number + 1, orig_bf_fname);
     1754            pathname_of_last_file_restored[0] = '\0';
     1755        } else if (!(node->selected)) {
     1756            dummy_restore = TRUE;
     1757            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
     1758                    orig_bf_fname);
     1759            pathname_of_last_file_restored[0] = '\0';
     1760        }
     1761    }
     1762
     1763    if (use_partimagehack) {
     1764        if (strncmp(orig_bf_fname, "/dev/", 5)) {
     1765            log_msg(1,
     1766                    "I was in error when I set use_partimagehack to TRUE.");
     1767            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
     1768            use_partimagehack = FALSE;
     1769        }
     1770    }
     1771
     1772    if (use_partimagehack) {
     1773        g_loglevel = 4;
     1774        strcpy(outfile_fname, orig_bf_fname);
     1775        use_partimage_hack = TRUE;
     1776        log_msg(2,
     1777                "Calling partimagehack in background because %s is a /dev entry",
     1778                outfile_fname);
     1779        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
     1780                (int) (random() % 32768));
     1781        mkfifo(sz_devfile, 0x770);
     1782        strcpy(partimagehack_fifo, sz_devfile);
     1783        file_to_openout = partimagehack_fifo;
     1784        switch (pid = fork()) {
     1785        case -1:
     1786            fatal_error("Fork failure");
     1787        case 0:
     1788            log_msg(3,
     1789                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
     1790                    outfile_fname, partimagehack_fifo);
     1791            res =
     1792                feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
     1793//          log_msg(3, "CHILD - fip - exiting");
     1794            exit(res);
     1795            break;
     1796        default:
     1797            log_msg(3,
     1798                    "feed_into_partimage() called in background --- pid=%ld",
     1799                    (long int) (pid));
     1800        }
     1801    } else {
     1802        if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
     1803        {
     1804            strcpy(outfile_fname, orig_bf_fname);
     1805        } else                  // biggiefile
     1806        {
     1807            sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
     1808                    orig_bf_fname);
     1809        }
     1810        use_partimage_hack = FALSE;
     1811        partimagehack_fifo[0] = '\0';
     1812        file_to_openout = outfile_fname;
     1813        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     1814        {
     1815            make_hole_for_file(outfile_fname);
     1816        }
     1817        sprintf(tmp, "Reassembling big file %ld (%s)",
     1818                biggiefile_number + 1, orig_bf_fname);
     1819        log_msg(2, tmp);
     1820    }
     1821
     1822    if (dummy_restore) {
     1823        sprintf(outfile_fname, "/dev/null");
     1824    }
     1825
     1826    if (!bkpinfo->zip_exe[0]) {
     1827        sprintf(command, "cat > \"%s\"", file_to_openout);
     1828    } else {
     1829        sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
     1830                file_to_openout, MONDO_LOGFILE);
     1831    }
     1832    sprintf(tmp, "Pipe command = '%s'", command);
     1833    log_msg(3, tmp);
     1834
     1835    /* restore biggiefile, one slice at a time */
     1836    if (!(pout = popen(command, "w"))) {
     1837        fatal_error("Cannot pipe out");
     1838    }
     1839    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
     1840         ctrl_chr != BLK_STOP_A_BIGGIE;
     1841         res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
     1842        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     1843            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     1844        }
     1845        sprintf(tmp, "Working on file #%ld, slice #%ld    ",
     1846                biggiefile_number + 1, current_slice_number);
     1847        log_msg(2, tmp);
     1848        if (!g_text_mode) {
     1849            newtDrawRootText(0, g_noof_rows - 2, tmp);
     1850            newtRefresh();
     1851        }
     1852        strip_spaces(tmp);
     1853        update_progress_form(tmp);
     1854        if (current_slice_number == 0) {
     1855            res =
     1856                read_file_from_stream_to_file(bkpinfo,
     1857                                              "/tmp/biggie-blah.txt",
     1858                                              slice_siz);
     1859            if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
     1860                log_OS_error("blah blah");
     1861            } else {
     1862                if (fread
     1863                    ((void *) &biggiestruct, 1, sizeof(biggiestruct),
     1864                     fin) < sizeof(biggiestruct)) {
     1865                    log_msg(2,
     1866                            "Warning - unable to get biggiestruct of bigfile #%d",
     1867                            biggiefile_number + 1);
     1868                }
     1869                paranoid_fclose(fin);
     1870            }
     1871        } else {
     1872            res =
     1873                read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
     1874        }
     1875        retval += res;
     1876        res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
     1877        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     1878            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     1879        }
     1880        current_slice_number++;
     1881        g_current_progress++;
     1882    }
     1883    paranoid_pclose(pout);
     1884
     1885    log_msg(1, "pathname_of_last_file_restored is now %s",
     1886            pathname_of_last_file_restored);
     1887
     1888    if (use_partimage_hack) {
     1889        log_msg(3, "Waiting for partimage to finish");
     1890        sprintf(tmp,
     1891                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
     1892        while (system(tmp) == 0) {
     1893            sleep(1);
     1894        }
     1895        log_msg(3, "OK, partimage has really finished");
     1896    }
     1897
     1898    log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
     1899    log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
     1900    if (strcmp(outfile_fname, "/dev/null")) {
     1901        chmod(outfile_fname, biggiestruct.properties.st_mode);
     1902        chown(outfile_fname, biggiestruct.properties.st_uid,
     1903              biggiestruct.properties.st_gid);
     1904        ubuf->actime = biggiestruct.properties.st_atime;
     1905        ubuf->modtime = biggiestruct.properties.st_mtime;
     1906        utime(outfile_fname, ubuf);
     1907    }
     1908
     1909    paranoid_free(tmp);
     1910    paranoid_free(outfile_fname);
     1911    paranoid_free(command);
     1912    paranoid_free(partimagehack_command);
     1913    paranoid_free(sz_devfile);
     1914    paranoid_free(partimagehack_fifo);
     1915    g_loglevel = old_loglevel;
     1916    return (retval);
    19191917}
    19201918
     
    19381936int
    19391937restore_a_tarball_from_CD(char *tarball_fname,
    1940               long current_tarball_number,
    1941               struct s_node*filelist)
     1938                          long current_tarball_number,
     1939                          struct s_node *filelist)
    19421940{
    1943   int retval = 0;
    1944   int res;
    1945   char *p;
     1941    int retval = 0;
     1942    int res;
     1943    char *p;
    19461944
    19471945  /** malloc **/
    1948   char *command;
    1949   char *tmp;
    1950   char *filelist_name;
    1951   char *filelist_subset_fname;
    1952   char *executable;
    1953   char *temp_log;
    1954   char screen_message[100];
    1955   long matches=0;
    1956   bool use_star;
    1957   char *xattr_fname;
    1958   char *acl_fname;
     1946    char *command;
     1947    char *tmp;
     1948    char *filelist_name;
     1949    char *filelist_subset_fname;
     1950    char *executable;
     1951    char *temp_log;
     1952    char screen_message[100];
     1953    long matches = 0;
     1954    bool use_star;
     1955    char *xattr_fname;
     1956    char *acl_fname;
    19591957//  char files_to_restore_this_time_fname[MAX_STR_LEN];
    19601958
    1961   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1962   malloc_string(command);
    1963   malloc_string(tmp);
    1964   malloc_string(filelist_name);
    1965   malloc_string(filelist_subset_fname);
    1966   malloc_string(executable);
    1967   malloc_string(temp_log);
    1968   malloc_string(xattr_fname);
    1969   malloc_string(acl_fname);
    1970  
    1971   log_msg(5, "Entering");
    1972   filelist_subset_fname[0] = '\0';
    1973   use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;
     1959    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     1960    malloc_string(command);
     1961    malloc_string(tmp);
     1962    malloc_string(filelist_name);
     1963    malloc_string(filelist_subset_fname);
     1964    malloc_string(executable);
     1965    malloc_string(temp_log);
     1966    malloc_string(xattr_fname);
     1967    malloc_string(acl_fname);
     1968
     1969    log_msg(5, "Entering");
     1970    filelist_subset_fname[0] = '\0';
     1971    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    19741972//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    1975   sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
    1976   run_program_and_log_output(command, 9);
    1977   sprintf(temp_log, "/tmp/%d.%d", (int)(random()%32768), (int)(random()%32768));
    1978  
    1979   sprintf(filelist_name, MNT_CDROM"/archives/filelist.%ld",current_tarball_number);
    1980   if ( length_of_file( filelist_name ) <= 2 )
    1981     {
    1982       log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
    1983       log_msg(2, "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)");
    1984       log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
    1985       retval=0;
    1986       goto leave_sub;
    1987     }
    1988   if ( count_lines_in_file(filelist_name) <= 0 || length_of_file( tarball_fname ) <= 0 )
    1989     {
    1990       log_msg(3, "length_of_file(%s) = %ld", tarball_fname, length_of_file(tarball_fname));
    1991       sprintf(tmp,"Unable to restore fileset #%ld (CD I/O error)",current_tarball_number);
    1992       log_to_screen(tmp);
    1993       retval=1;
    1994       goto leave_sub;
    1995     }
    1996 
    1997   if (filelist)
    1998     {
    1999       sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
    2000       if ((matches=save_filelist_entries_in_common
    2001                 (filelist_name, filelist, filelist_subset_fname, use_star))
    2002                 <= 0)
    2003     {
    2004       sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    2005       log_msg(1, tmp);
    2006     }
    2007       else
    2008         {
    2009       log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
    2010     }
    2011       sprintf(screen_message, "Tarball #%ld --- %ld matches", current_tarball_number, matches);
    2012       log_to_screen(screen_message);
    2013     }
    2014   else
    2015     {
    2016       filelist_subset_fname[0] = '\0';
    2017     }
    2018 
    2019   if (filelist == NULL || matches>0)
    2020     {
    2021       sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);
    2022       sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);
    2023       if ( strstr( tarball_fname, ".bz2" ) )
    2024         {
    2025           strcpy(executable,"bzip2");
    2026         }
    2027       else if ( strstr( tarball_fname, ".lzo") )
    2028         {
    2029           strcpy( executable,"lzop");
    2030         }
    2031       else
    2032         {
    2033           executable[0] = '\0';
    2034         }
    2035       if (executable[0])
    2036         {
    2037           sprintf( tmp, "which %s > /dev/null 2> /dev/null", executable );
    2038           if ( run_program_and_log_output( tmp, FALSE ) )
    2039             {
    2040              log_to_screen("(compare_a_tarball) Compression program not found - oh no!");
    2041              paranoid_MR_finish(1);
    2042             }
    2043           strcpy(tmp, executable);
    2044           sprintf(executable, "-P %s -Z", tmp);
    2045         }
     1973    sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
     1974    run_program_and_log_output(command, 9);
     1975    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
     1976            (int) (random() % 32768));
     1977
     1978    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
     1979            current_tarball_number);
     1980    if (length_of_file(filelist_name) <= 2) {
     1981        log_msg(2, "There are _zero_ files in filelist '%s'",
     1982                filelist_name);
     1983        log_msg(2,
     1984                "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)");
     1985        log_msg(2,
     1986                "but it's non-critical. It's cosmetic. Don't worry about it.");
     1987        retval = 0;
     1988        goto leave_sub;
     1989    }
     1990    if (count_lines_in_file(filelist_name) <= 0
     1991        || length_of_file(tarball_fname) <= 0) {
     1992        log_msg(3, "length_of_file(%s) = %ld", tarball_fname,
     1993                length_of_file(tarball_fname));
     1994        sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
     1995                current_tarball_number);
     1996        log_to_screen(tmp);
     1997        retval = 1;
     1998        goto leave_sub;
     1999    }
     2000
     2001    if (filelist) {
     2002        sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
     2003                current_tarball_number);
     2004        if ((matches =
     2005             save_filelist_entries_in_common(filelist_name, filelist,
     2006                                             filelist_subset_fname,
     2007                                             use_star))
     2008            <= 0) {
     2009            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
     2010            log_msg(1, tmp);
     2011        } else {
     2012            log_msg(3, "Saved fileset %ld's subset to %s",
     2013                    current_tarball_number, filelist_subset_fname);
     2014        }
     2015        sprintf(screen_message, "Tarball #%ld --- %ld matches",
     2016                current_tarball_number, matches);
     2017        log_to_screen(screen_message);
     2018    } else {
     2019        filelist_subset_fname[0] = '\0';
     2020    }
     2021
     2022    if (filelist == NULL || matches > 0) {
     2023        sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
     2024                MNT_CDROM "/archives", current_tarball_number);
     2025        sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
     2026                current_tarball_number);
     2027        if (strstr(tarball_fname, ".bz2")) {
     2028            strcpy(executable, "bzip2");
     2029        } else if (strstr(tarball_fname, ".lzo")) {
     2030            strcpy(executable, "lzop");
     2031        } else {
     2032            executable[0] = '\0';
     2033        }
     2034        if (executable[0]) {
     2035            sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
     2036            if (run_program_and_log_output(tmp, FALSE)) {
     2037                log_to_screen
     2038                    ("(compare_a_tarball) Compression program not found - oh no!");
     2039                paranoid_MR_finish(1);
     2040            }
     2041            strcpy(tmp, executable);
     2042            sprintf(executable, "-P %s -Z", tmp);
     2043        }
    20462044#ifdef __FreeBSD__
    20472045#define BUFSIZE 512
     
    20512049
    20522050//      if (strstr(tarball_fname, ".star."))
    2053       if (use_star)
    2054         {
    2055       sprintf( command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname);
    2056       if (strstr (tarball_fname, ".bz2"))
    2057         { strcat( command, " -bz"); }
    2058     }
    2059       else
    2060         {
    2061       if ( filelist_subset_fname[0] != '\0' )
    2062             {
    2063               sprintf( command,
    2064            "afio -i -M 8m -b %ld -c %ld %s -w %s %s",
    2065            TAPE_BLOCK_SIZE,
    2066            BUFSIZE,
    2067            executable,
    2068            filelist_subset_fname,
    2069 //             files_to_restore_this_time_fname,
    2070            tarball_fname);
    2071         }
    2072           else
    2073             {
    2074               sprintf( command,
    2075            "afio -i -b %ld -c %ld -M 8m %s %s",
    2076            TAPE_BLOCK_SIZE,
    2077            BUFSIZE,
    2078            executable,
    2079            tarball_fname);
    2080             }
    2081     }
     2051        if (use_star) {
     2052            sprintf(command,
     2053                    "star -x -force-remove -U " STAR_ACL_SZ
     2054                    " errctl= file=%s", tarball_fname);
     2055            if (strstr(tarball_fname, ".bz2")) {
     2056                strcat(command, " -bz");
     2057            }
     2058        } else {
     2059            if (filelist_subset_fname[0] != '\0') {
     2060                sprintf(command,
     2061                        "afio -i -M 8m -b %ld -c %ld %s -w %s %s",
     2062                        TAPE_BLOCK_SIZE,
     2063                        BUFSIZE, executable, filelist_subset_fname,
     2064//             files_to_restore_this_time_fname,
     2065                        tarball_fname);
     2066            } else {
     2067                sprintf(command,
     2068                        "afio -i -b %ld -c %ld -M 8m %s %s",
     2069                        TAPE_BLOCK_SIZE,
     2070                        BUFSIZE, executable, tarball_fname);
     2071            }
     2072        }
    20822073#undef BUFSIZE
    2083       sprintf(command+strlen(command), " 2>> %s >> %s", temp_log, temp_log);
    2084       log_msg(1,"command = '%s'", command);
    2085       unlink(temp_log);
    2086       res = system(command);
    2087       if (res)
    2088         {
    2089       p = strstr(command, "-acl ");
    2090       if (p)
    2091         {
    2092           p[0]=p[1]=p[2]=p[3]=' ';
    2093               log_msg(1,"new command = '%s'", command);
    2094               res = system(command);
    2095         }
    2096         }
    2097       if (res && length_of_file(temp_log)<5) { res=0; }
    2098      
    2099       log_msg(1, "Setting fattr list %s", xattr_fname);
    2100       if (length_of_file(xattr_fname)>0)
    2101         {
    2102           res=set_fattr_list(filelist_subset_fname, xattr_fname);
    2103           if (res) { log_to_screen("Errors occurred while setting extended attributes"); }
    2104           else { log_msg(1, "I set xattr OK"); }
    2105           retval += res;
    2106         }
    2107       if (length_of_file(acl_fname)>0)
    2108         {
    2109           log_msg(1, "Setting acl list %s", acl_fname);
    2110           res=set_acl_list(filelist_subset_fname, acl_fname);
    2111           if (res) { log_to_screen("Errors occurred while setting access control lists"); }
    2112           else { log_msg(1, "I set ACL OK"); }
    2113           retval += res;
    2114         }
    2115       if ( retval )
    2116         {
    2117           sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
    2118           system(command);
    2119           log_msg(2, "Errors occurred while processing fileset #%d",current_tarball_number);
    2120         }
    2121       else
    2122         {
    2123           log_msg(2, "Fileset #%d processed OK", current_tarball_number);
    2124         }
    2125     }
    2126   if (does_file_exist("/PAUSE"))
    2127     { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); }
    2128   unlink(filelist_subset_fname);
    2129   unlink(xattr_fname);
    2130   unlink(acl_fname);
    2131   unlink(temp_log);
    2132  
    2133 leave_sub:
    2134   paranoid_free(command); paranoid_free(tmp);
    2135   paranoid_free(filelist_name); paranoid_free(filelist_subset_fname);
    2136   paranoid_free(executable); paranoid_free(temp_log);
    2137   paranoid_free(xattr_fname); paranoid_free(acl_fname);
    2138   log_msg(5, "Leaving");
    2139   return(retval);
     2074        sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
     2075                temp_log);
     2076        log_msg(1, "command = '%s'", command);
     2077        unlink(temp_log);
     2078        res = system(command);
     2079        if (res) {
     2080            p = strstr(command, "-acl ");
     2081            if (p) {
     2082                p[0] = p[1] = p[2] = p[3] = ' ';
     2083                log_msg(1, "new command = '%s'", command);
     2084                res = system(command);
     2085            }
     2086        }
     2087        if (res && length_of_file(temp_log) < 5) {
     2088            res = 0;
     2089        }
     2090
     2091        log_msg(1, "Setting fattr list %s", xattr_fname);
     2092        if (length_of_file(xattr_fname) > 0) {
     2093            res = set_fattr_list(filelist_subset_fname, xattr_fname);
     2094            if (res) {
     2095                log_to_screen
     2096                    ("Errors occurred while setting extended attributes");
     2097            } else {
     2098                log_msg(1, "I set xattr OK");
     2099            }
     2100            retval += res;
     2101        }
     2102        if (length_of_file(acl_fname) > 0) {
     2103            log_msg(1, "Setting acl list %s", acl_fname);
     2104            res = set_acl_list(filelist_subset_fname, acl_fname);
     2105            if (res) {
     2106                log_to_screen
     2107                    ("Errors occurred while setting access control lists");
     2108            } else {
     2109                log_msg(1, "I set ACL OK");
     2110            }
     2111            retval += res;
     2112        }
     2113        if (retval) {
     2114            sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
     2115            system(command);
     2116            log_msg(2, "Errors occurred while processing fileset #%d",
     2117                    current_tarball_number);
     2118        } else {
     2119            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
     2120        }
     2121    }
     2122    if (does_file_exist("/PAUSE")) {
     2123        popup_and_OK
     2124            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2125    }
     2126    unlink(filelist_subset_fname);
     2127    unlink(xattr_fname);
     2128    unlink(acl_fname);
     2129    unlink(temp_log);
     2130
     2131  leave_sub:
     2132    paranoid_free(command);
     2133    paranoid_free(tmp);
     2134    paranoid_free(filelist_name);
     2135    paranoid_free(filelist_subset_fname);
     2136    paranoid_free(executable);
     2137    paranoid_free(temp_log);
     2138    paranoid_free(xattr_fname);
     2139    paranoid_free(acl_fname);
     2140    log_msg(5, "Leaving");
     2141    return (retval);
    21402142}
    21412143
     
    21622164int
    21632165restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
    2164                   char *tarball_fname,
    2165                   long current_tarball_number,
    2166                   struct s_node*filelist,
    2167                   long long size, char*xattr_fname, char*acl_fname)
     2166                              char *tarball_fname,
     2167                              long current_tarball_number,
     2168                              struct s_node *filelist,
     2169                              long long size, char *xattr_fname,
     2170                              char *acl_fname)
    21682171{
    2169   int retval = 0;
    2170   int res = 0;
     2172    int retval = 0;
     2173    int res = 0;
    21712174
    21722175  /** malloc add ***/
    2173   char *tmp;
    2174   char *command;
    2175   char *afio_fname;
    2176   char *filelist_fname;
    2177   char *filelist_subset_fname;
    2178   char *executable;
    2179   long matches=0;
    2180   bool restore_this_fileset = FALSE;
    2181   bool use_star;
    2182  
    2183   assert(bkpinfo!=NULL);
    2184   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    2185   malloc_string(filelist_subset_fname);
    2186   malloc_string(filelist_fname);
    2187   malloc_string(afio_fname);
    2188   malloc_string(executable);
    2189   malloc_string(command);
    2190   malloc_string(tmp);
    2191   filelist_subset_fname[0] = '\0';
    2192   /* to do it with a file... */
    2193   use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;
    2194   sprintf( tmp,
    2195        "Restoring from fileset #%ld (%ld KB) on %s #%d",current_tarball_number,
    2196        (long) size>>10,
    2197        media_descriptor_string(bkpinfo->backup_media_type),
    2198        g_current_media_number );
    2199   log_msg(2, tmp );
    2200   run_program_and_log_output( "mkdir -p " MNT_RESTORING "/tmp", FALSE );
     2176    char *tmp;
     2177    char *command;
     2178    char *afio_fname;
     2179    char *filelist_fname;
     2180    char *filelist_subset_fname;
     2181    char *executable;
     2182    long matches = 0;
     2183    bool restore_this_fileset = FALSE;
     2184    bool use_star;
     2185
     2186    assert(bkpinfo != NULL);
     2187    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     2188    malloc_string(filelist_subset_fname);
     2189    malloc_string(filelist_fname);
     2190    malloc_string(afio_fname);
     2191    malloc_string(executable);
     2192    malloc_string(command);
     2193    malloc_string(tmp);
     2194    filelist_subset_fname[0] = '\0';
     2195    /* to do it with a file... */
     2196    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
     2197    sprintf(tmp,
     2198            "Restoring from fileset #%ld (%ld KB) on %s #%d",
     2199            current_tarball_number, (long) size >> 10,
     2200            media_descriptor_string(bkpinfo->backup_media_type),
     2201            g_current_media_number);
     2202    log_msg(2, tmp);
     2203    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
    22012204
    22022205  /****************************************************************************
     
    22052208   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
    22062209   ****************************************************************************/
    2207   filelist_fname[0] = filelist_subset_fname[0] = '\0';
    2208   sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
    2209   sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
    2210   sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
     2210    filelist_fname[0] = filelist_subset_fname[0] = '\0';
     2211    sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
     2212            current_tarball_number);
     2213    sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
     2214            current_tarball_number);
     2215    sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
     2216            bkpinfo->tmpdir, current_tarball_number);
    22112217//  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
    2212   res = read_file_from_stream_to_file( bkpinfo, afio_fname,size );
    2213   if (strstr(tarball_fname, ".star")) { bkpinfo->use_star = TRUE; }
    2214   if (res) { log_msg(1, "Warning - error reading afioball from tape"); }
    2215   if (bkpinfo->compression_level == 0)
    2216     {
    2217       executable[0] = '\0';
    2218     }
    2219   else
    2220     {
    2221       if (bkpinfo->use_star)
    2222         { strcpy(executable, " -bz"); }
    2223       else
    2224         { sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); }
    2225     }
    2226 
    2227   if (!filelist) // if unconditional restore then restore entire fileset
    2228     {
    2229       restore_this_fileset = TRUE;
    2230     }
    2231   else          // If restoring selectively then get TOC from tarball
    2232     {
    2233       if (strstr(tarball_fname, ".star."))
    2234         {
    2235       use_star = TRUE;
    2236       sprintf( command, "star -t file=%s %s", afio_fname, executable);
    2237     }
    2238       else
    2239         {
    2240       use_star = FALSE;
    2241           sprintf( command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
    2242                         executable, afio_fname);
    2243     }
    2244       sprintf(command+strlen(command), " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
    2245       log_msg(1, "command = %s", command);
    2246       if (system(command)) { log_msg(4, "Warning - error occurred while retrieving TOC"); }
    2247       if ((matches=save_filelist_entries_in_common(filelist_fname, filelist, filelist_subset_fname, use_star))
    2248                      <= 0
    2249                     || length_of_file(filelist_subset_fname)<2)
    2250         {
    2251       if (length_of_file(filelist_subset_fname)<2)
    2252         { log_msg(1, "No matches found in fileset %ld", current_tarball_number); }
    2253       sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
    2254       log_msg(2, tmp);
    2255           restore_this_fileset = FALSE;
    2256         }
    2257       else
    2258         {
    2259       log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", matches, current_tarball_number, filelist_subset_fname);
    2260       restore_this_fileset = TRUE;
    2261     }
    2262     }
     2218    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
     2219    if (strstr(tarball_fname, ".star")) {
     2220        bkpinfo->use_star = TRUE;
     2221    }
     2222    if (res) {
     2223        log_msg(1, "Warning - error reading afioball from tape");
     2224    }
     2225    if (bkpinfo->compression_level == 0) {
     2226        executable[0] = '\0';
     2227    } else {
     2228        if (bkpinfo->use_star) {
     2229            strcpy(executable, " -bz");
     2230        } else {
     2231            sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
     2232        }
     2233    }
     2234
     2235    if (!filelist)              // if unconditional restore then restore entire fileset
     2236    {
     2237        restore_this_fileset = TRUE;
     2238    } else                      // If restoring selectively then get TOC from tarball
     2239    {
     2240        if (strstr(tarball_fname, ".star.")) {
     2241            use_star = TRUE;
     2242            sprintf(command, "star -t file=%s %s", afio_fname, executable);
     2243        } else {
     2244            use_star = FALSE;
     2245            sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
     2246                    executable, afio_fname);
     2247        }
     2248        sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
     2249                MONDO_LOGFILE);
     2250        log_msg(1, "command = %s", command);
     2251        if (system(command)) {
     2252            log_msg(4, "Warning - error occurred while retrieving TOC");
     2253        }
     2254        if ((matches =
     2255             save_filelist_entries_in_common(filelist_fname, filelist,
     2256                                             filelist_subset_fname,
     2257                                             use_star))
     2258            <= 0 || length_of_file(filelist_subset_fname) < 2) {
     2259            if (length_of_file(filelist_subset_fname) < 2) {
     2260                log_msg(1, "No matches found in fileset %ld",
     2261                        current_tarball_number);
     2262            }
     2263            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
     2264            log_msg(2, tmp);
     2265            restore_this_fileset = FALSE;
     2266        } else {
     2267            log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
     2268                    matches, current_tarball_number,
     2269                    filelist_subset_fname);
     2270            restore_this_fileset = TRUE;
     2271        }
     2272    }
    22632273
    22642274// Concoct the call to star/afio to restore files
    2265   if (strstr(tarball_fname, ".star.")) // star
    2266     {
    2267       sprintf( command, "star -x file=%s %s", afio_fname, executable);
    2268       if (filelist)
    2269         { sprintf(command+strlen(command), " list=%s", filelist_subset_fname); }
    2270     }
    2271   else                                 // afio
    2272     {
    2273       sprintf( command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
    2274       if (filelist)
    2275         { sprintf(command+strlen(command), " -w %s", filelist_subset_fname); }
    2276       sprintf(command+strlen(command), " %s", afio_fname);
    2277     }
    2278   sprintf( command+strlen(command), " 2>> %s", MONDO_LOGFILE);
     2275    if (strstr(tarball_fname, ".star."))    // star
     2276    {
     2277        sprintf(command, "star -x file=%s %s", afio_fname, executable);
     2278        if (filelist) {
     2279            sprintf(command + strlen(command), " list=%s",
     2280                    filelist_subset_fname);
     2281        }
     2282    } else                      // afio
     2283    {
     2284        sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
     2285                executable);
     2286        if (filelist) {
     2287            sprintf(command + strlen(command), " -w %s",
     2288                    filelist_subset_fname);
     2289        }
     2290        sprintf(command + strlen(command), " %s", afio_fname);
     2291    }
     2292    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
    22792293
    22802294// Call if IF there are files to restore (selectively/unconditionally)
    2281   if (restore_this_fileset)
    2282     {
    2283       log_msg(1, "Calling command='%s'", command);
    2284       paranoid_system(command);
    2285 
    2286       iamhere("Restoring xattr, acl stuff");
    2287       res=set_fattr_list(filelist_subset_fname, xattr_fname);
    2288       if (res) { log_msg(1, "Errors occurred while setting xattr"); }
    2289       else { log_msg(1, "I set xattr OK"); }
    2290       retval += res;
    2291      
    2292       res=set_acl_list(filelist_subset_fname, acl_fname);
    2293       if (res) { log_msg(1, "Errors occurred while setting ACL"); }
    2294       else { log_msg(1, "I set ACL OK"); }
    2295       retval += res;
    2296      
    2297     }
    2298   else
    2299     {
    2300       log_msg(1, "NOT CALLING '%s'", command);
    2301     }
    2302    
    2303   if (does_file_exist("/PAUSE") && current_tarball_number >= 50)
    2304     {
    2305       log_to_screen("Paused after set %ld", current_tarball_number);
    2306       popup_and_OK("Pausing. Press ENTER to continue.");
    2307     }
    2308    
    2309   unlink(filelist_subset_fname);
    2310   unlink(filelist_fname);
    2311   unlink(afio_fname);
    2312 
    2313   paranoid_free(filelist_subset_fname);
    2314   paranoid_free(filelist_fname);
    2315   paranoid_free(afio_fname);
    2316   paranoid_free(command);
    2317   paranoid_free(tmp);
    2318   return(retval);
     2295    if (restore_this_fileset) {
     2296        log_msg(1, "Calling command='%s'", command);
     2297        paranoid_system(command);
     2298
     2299        iamhere("Restoring xattr, acl stuff");
     2300        res = set_fattr_list(filelist_subset_fname, xattr_fname);
     2301        if (res) {
     2302            log_msg(1, "Errors occurred while setting xattr");
     2303        } else {
     2304            log_msg(1, "I set xattr OK");
     2305        }
     2306        retval += res;
     2307
     2308        res = set_acl_list(filelist_subset_fname, acl_fname);
     2309        if (res) {
     2310            log_msg(1, "Errors occurred while setting ACL");
     2311        } else {
     2312            log_msg(1, "I set ACL OK");
     2313        }
     2314        retval += res;
     2315
     2316    } else {
     2317        log_msg(1, "NOT CALLING '%s'", command);
     2318    }
     2319
     2320    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
     2321        log_to_screen("Paused after set %ld", current_tarball_number);
     2322        popup_and_OK("Pausing. Press ENTER to continue.");
     2323    }
     2324
     2325    unlink(filelist_subset_fname);
     2326    unlink(filelist_fname);
     2327    unlink(afio_fname);
     2328
     2329    paranoid_free(filelist_subset_fname);
     2330    paranoid_free(filelist_fname);
     2331    paranoid_free(afio_fname);
     2332    paranoid_free(command);
     2333    paranoid_free(tmp);
     2334    return (retval);
    23192335}
     2336
    23202337/**************************************************************************
    23212338 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
     
    23352352 */
    23362353int
    2337 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist)
     2354restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
     2355                                struct s_node *filelist)
    23382356{
    2339   int retval = 0;
    2340   int res;
    2341   long noof_biggiefiles, bigfileno = 0, total_slices;
     2357    int retval = 0;
     2358    int res;
     2359    long noof_biggiefiles, bigfileno = 0, total_slices;
    23422360  /** malloc **/
    2343   char *tmp;
    2344   bool just_changed_cds = FALSE, finished;
    2345   char *xattr_fname;
    2346   char *acl_fname;
    2347   char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
    2348   char *pathname_of_last_biggie_restored;
    2349   FILE *fbw = NULL;
    2350    
    2351   malloc_string(xattr_fname);
    2352   malloc_string(acl_fname);
    2353   malloc_string(tmp);
    2354   malloc_string(biggies_whose_EXATs_we_should_set);
    2355   malloc_string(pathname_of_last_biggie_restored);
    2356   assert(bkpinfo!=NULL);
    2357 
    2358   sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    2359   if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w")))
    2360    { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); }
    2361  
    2362   read_cfg_var( g_mondo_cfg_file, "total-slices", tmp);
    2363   total_slices = atol( tmp );
    2364   sprintf(tmp,"Reassembling large files      ");
    2365   mvaddstr_and_log_it( g_currentY, 0, tmp );
    2366   if (length_of_file(BIGGIELIST) < 6)
    2367     {
    2368       log_msg(1, "OK, no biggielist; not restoring biggiefiles");
    2369       return(0);
    2370     }
    2371   noof_biggiefiles = count_lines_in_file(BIGGIELIST);
    2372   if ( noof_biggiefiles <= 0 )
    2373     {
    2374       log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
    2375       return(0);
    2376     }
    2377   sprintf( tmp,"OK, there are %ld biggiefiles in the archives",noof_biggiefiles);
    2378   log_msg(2, tmp );
    2379  
    2380   open_progress_form( "Reassembling large files",
    2381               "I am now reassembling all the large files." ,
    2382               "Please wait. This may take some time.",
    2383               "",
    2384               total_slices);
    2385   for( bigfileno = 0, finished = FALSE; !finished;)
    2386     {
    2387       log_msg( 2, "Thinking about restoring bigfile %ld", bigfileno + 1 );
    2388       if ( !does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) )
    2389     {
    2390       log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
    2391           log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno+1, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2392           log_msg(3, "Slicename would have been %s", slice_fname(bigfileno+1,0,ARCHIVES_PATH,""));
    2393       // I'm not positive 'just_changed_cds' is even necessary...
    2394       if (just_changed_cds)
    2395             {
    2396               just_changed_cds = FALSE;
    2397               log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
    2398             }
    2399       else if (does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST"))
    2400         {
    2401               insist_on_this_cd_number(bkpinfo, ++g_current_media_number);
    2402           sprintf(tmp,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2403           log_to_screen(tmp);
    2404               just_changed_cds = TRUE;
    2405         }
    2406           else
    2407         {
    2408           log_msg(2, "There was no bigfile #%ld. That's OK." ,bigfileno+1);
    2409           log_msg(2, "I'm going to stop restoring bigfiles now.");
    2410           finished = TRUE;
    2411         }
    2412     }
    2413       else
    2414     {
    2415           just_changed_cds = FALSE;
    2416       sprintf(tmp,"Restoring big file %ld",bigfileno + 1);
    2417       update_progress_form(tmp);
    2418       res = restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, pathname_of_last_biggie_restored);
    2419       iamhere(pathname_of_last_biggie_restored);
    2420       if (fbw && pathname_of_last_biggie_restored[0])
    2421         { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); }
    2422       retval += res;
    2423       bigfileno++;
    2424 
    2425     }
    2426     }
    2427 
    2428   if (fbw)
    2429     {
    2430       fclose(fbw);
    2431       sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    2432       sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    2433       if (length_of_file(acl_fname)  >0 && find_home_of_exe("setfacl"))
    2434         {
    2435       set_acl_list  (biggies_whose_EXATs_we_should_set, acl_fname);
    2436     }
    2437       if (length_of_file(xattr_fname)>0 && find_home_of_exe("setfattr"))
    2438         {
    2439       set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    2440     }
    2441     }
    2442   if (does_file_exist("/PAUSE"))
    2443     { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); }
    2444   close_progress_form();
    2445   if (retval)
    2446     {
    2447       mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
    2448     }
    2449   else
    2450     {
    2451       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2452     }
    2453   paranoid_free(xattr_fname);
    2454   paranoid_free(acl_fname);
    2455   paranoid_free(tmp);
    2456   paranoid_free(biggies_whose_EXATs_we_should_set);
    2457   paranoid_free(pathname_of_last_biggie_restored);
    2458   return( retval );
     2361    char *tmp;
     2362    bool just_changed_cds = FALSE, finished;
     2363    char *xattr_fname;
     2364    char *acl_fname;
     2365    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     2366    char *pathname_of_last_biggie_restored;
     2367    FILE *fbw = NULL;
     2368
     2369    malloc_string(xattr_fname);
     2370    malloc_string(acl_fname);
     2371    malloc_string(tmp);
     2372    malloc_string(biggies_whose_EXATs_we_should_set);
     2373    malloc_string(pathname_of_last_biggie_restored);
     2374    assert(bkpinfo != NULL);
     2375
     2376    sprintf(biggies_whose_EXATs_we_should_set,
     2377            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     2378    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
     2379        log_msg(1, "Warning - cannot openout %s",
     2380                biggies_whose_EXATs_we_should_set);
     2381    }
     2382
     2383    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
     2384    total_slices = atol(tmp);
     2385    sprintf(tmp, "Reassembling large files      ");
     2386    mvaddstr_and_log_it(g_currentY, 0, tmp);
     2387    if (length_of_file(BIGGIELIST) < 6) {
     2388        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
     2389        return (0);
     2390    }
     2391    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
     2392    if (noof_biggiefiles <= 0) {
     2393        log_msg(2,
     2394                "OK, no biggiefiles in biggielist; not restoring biggiefiles");
     2395        return (0);
     2396    }
     2397    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
     2398            noof_biggiefiles);
     2399    log_msg(2, tmp);
     2400
     2401    open_progress_form("Reassembling large files",
     2402                       "I am now reassembling all the large files.",
     2403                       "Please wait. This may take some time.",
     2404                       "", total_slices);
     2405    for (bigfileno = 0, finished = FALSE; !finished;) {
     2406        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
     2407        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
     2408            log_msg(3,
     2409                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
     2410            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
     2411                    bigfileno + 1,
     2412                    media_descriptor_string(bkpinfo->backup_media_type),
     2413                    g_current_media_number);
     2414            log_msg(3, "Slicename would have been %s",
     2415                    slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
     2416            // I'm not positive 'just_changed_cds' is even necessary...
     2417            if (just_changed_cds) {
     2418                just_changed_cds = FALSE;
     2419                log_msg(3,
     2420                        "I'll continue to scan this CD for bigfiles to be restored.");
     2421            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
     2422                insist_on_this_cd_number(bkpinfo,
     2423                                         ++g_current_media_number);
     2424                sprintf(tmp, "Restoring from %s #%d",
     2425                        media_descriptor_string(bkpinfo->
     2426                                                backup_media_type),
     2427                        g_current_media_number);
     2428                log_to_screen(tmp);
     2429                just_changed_cds = TRUE;
     2430            } else {
     2431                log_msg(2, "There was no bigfile #%ld. That's OK.",
     2432                        bigfileno + 1);
     2433                log_msg(2, "I'm going to stop restoring bigfiles now.");
     2434                finished = TRUE;
     2435            }
     2436        } else {
     2437            just_changed_cds = FALSE;
     2438            sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
     2439            update_progress_form(tmp);
     2440            res =
     2441                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
     2442                                             pathname_of_last_biggie_restored);
     2443            iamhere(pathname_of_last_biggie_restored);
     2444            if (fbw && pathname_of_last_biggie_restored[0]) {
     2445                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
     2446            }
     2447            retval += res;
     2448            bigfileno++;
     2449
     2450        }
     2451    }
     2452
     2453    if (fbw) {
     2454        fclose(fbw);
     2455        sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2456        sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2457        if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) {
     2458            set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
     2459        }
     2460        if (length_of_file(xattr_fname) > 0
     2461            && find_home_of_exe("setfattr")) {
     2462            set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
     2463        }
     2464    }
     2465    if (does_file_exist("/PAUSE")) {
     2466        popup_and_OK
     2467            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2468    }
     2469    close_progress_form();
     2470    if (retval) {
     2471        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2472    } else {
     2473        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2474    }
     2475    paranoid_free(xattr_fname);
     2476    paranoid_free(acl_fname);
     2477    paranoid_free(tmp);
     2478    paranoid_free(biggies_whose_EXATs_we_should_set);
     2479    paranoid_free(pathname_of_last_biggie_restored);
     2480    return (retval);
    24592481}
     2482
    24602483/**************************************************************************
    24612484 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
     
    24752498 */
    24762499int
    2477 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist)
     2500restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
     2501                             struct s_node *filelist)
    24782502{
    2479   int retval = 0;
    2480   int res;
    2481   int attempts;
    2482   long current_tarball_number = 0;
    2483   long max_val;
     2503    int retval = 0;
     2504    int res;
     2505    int attempts;
     2506    long current_tarball_number = 0;
     2507    long max_val;
    24842508  /**malloc ***/
    2485   char *tmp;
    2486   char *tarball_fname;
    2487   char *progress_str;
    2488   char *comment;
    2489 
    2490   malloc_string(tmp);
    2491   malloc_string(tarball_fname);
    2492   malloc_string(progress_str);
    2493   malloc_string(comment);
    2494  
    2495   assert(bkpinfo!=NULL);
    2496 
    2497   mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    2498   log_msg(2, "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
    2499   if ( g_current_media_number != 1)
    2500     {
    2501       log_msg(3, "OK, that's jacked up.");
    2502       g_current_media_number = 1;
    2503     }
    2504   insist_on_this_cd_number( bkpinfo, g_current_media_number);
    2505   read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    2506   max_val = atol(tmp) + 1;
    2507   sprintf(progress_str,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2508   log_to_screen(progress_str);
    2509   open_progress_form("Restoring from archives",
    2510              "Restoring data from the archives." ,
    2511              "Please wait. This may take some time.",
    2512              progress_str,max_val);
    2513   for(;;)
    2514     {
    2515       insist_on_this_cd_number(bkpinfo, g_current_media_number);
    2516       update_progress_form(progress_str);
    2517       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.bz2",current_tarball_number);
    2518       if (!does_file_exist(tarball_fname))
    2519     {
    2520       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.lzo",current_tarball_number);
    2521     }
    2522       if (!does_file_exist(tarball_fname))
    2523     {
    2524       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.",current_tarball_number);
    2525     }
    2526       if (!does_file_exist(tarball_fname))
    2527     {
    2528       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.bz2", current_tarball_number);
    2529     }
    2530       if (!does_file_exist(tarball_fname))
    2531     {
    2532       sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.", current_tarball_number);
    2533     }
    2534       if (!does_file_exist(tarball_fname))
    2535     {
    2536       if (current_tarball_number == 0)
    2537         {
    2538           log_to_screen("No tarballs. Strange. Maybe you only backed up freakin' big files?");
    2539           return(0);
    2540         }
    2541       if (!does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST") || system("find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null") == 0 )
    2542         {
    2543           break;
    2544         }
    2545       g_current_media_number++;
    2546       sprintf(progress_str,"Restoring from %s #%d",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
    2547       log_to_screen(progress_str);
    2548     }
    2549       else
    2550         {
    2551           sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",
    2552                 current_tarball_number,
    2553                 media_descriptor_string(bkpinfo->backup_media_type),
    2554                 g_current_media_number);
    2555 //    log_msg(3, "progress_str = %s", progress_str);
    2556           for(res = 999, attempts = 0; attempts < 3 && res != 0; attempts++)
    2557             {
    2558           res = restore_a_tarball_from_CD(tarball_fname,current_tarball_number, filelist);
    2559         }
    2560           sprintf(tmp,"%s #%d, fileset #%ld - restore ",
    2561         media_descriptor_string(bkpinfo->backup_media_type),
    2562           g_current_media_number,
    2563           current_tarball_number);
    2564           if (res)
    2565         {
    2566           strcat(tmp,"reported errors");
    2567         }
    2568       else if (attempts > 1)
    2569         {
    2570           strcat(tmp,"succeeded");
    2571         }
    2572       else
    2573         {
    2574           strcat(tmp,"succeeded");
    2575         }
    2576           if (attempts > 1)
    2577         {
    2578           sprintf( tmp + strlen(tmp)," (%d attempts) - review logs",attempts);
    2579         }
    2580           strcpy(comment, tmp);
    2581           if (attempts > 1)
    2582         {
    2583           log_to_screen(comment);
    2584         }
    2585          
    2586           retval += res;
    2587           current_tarball_number++;
    2588           g_current_progress++;
    2589         }
    2590     }
    2591   close_progress_form();
    2592   if (retval)
    2593     {
    2594       mvaddstr_and_log_it(g_currentY++,74,"Errors.");
    2595     }
    2596   else
    2597     {
    2598       mvaddstr_and_log_it(g_currentY++,74,"Done.");
    2599     }
    2600   paranoid_free(tmp);
    2601   paranoid_free(tarball_fname);
    2602   paranoid_free(progress_str);
    2603   paranoid_free(comment);
    2604  
    2605   return(retval);
     2509    char *tmp;
     2510    char *tarball_fname;
     2511    char *progress_str;
     2512    char *comment;
     2513
     2514    malloc_string(tmp);
     2515    malloc_string(tarball_fname);
     2516    malloc_string(progress_str);
     2517    malloc_string(comment);
     2518
     2519    assert(bkpinfo != NULL);
     2520
     2521    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
     2522    log_msg(2,
     2523            "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
     2524    if (g_current_media_number != 1) {
     2525        log_msg(3, "OK, that's jacked up.");
     2526        g_current_media_number = 1;
     2527    }
     2528    insist_on_this_cd_number(bkpinfo, g_current_media_number);
     2529    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     2530    max_val = atol(tmp) + 1;
     2531    sprintf(progress_str, "Restoring from %s #%d",
     2532            media_descriptor_string(bkpinfo->backup_media_type),
     2533            g_current_media_number);
     2534    log_to_screen(progress_str);
     2535    open_progress_form("Restoring from archives",
     2536                       "Restoring data from the archives.",
     2537                       "Please wait. This may take some time.",
     2538                       progress_str, max_val);
     2539    for (;;) {
     2540        insist_on_this_cd_number(bkpinfo, g_current_media_number);
     2541        update_progress_form(progress_str);
     2542        sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
     2543                current_tarball_number);
     2544        if (!does_file_exist(tarball_fname)) {
     2545            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
     2546                    current_tarball_number);
     2547        }
     2548        if (!does_file_exist(tarball_fname)) {
     2549            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
     2550                    current_tarball_number);
     2551        }
     2552        if (!does_file_exist(tarball_fname)) {
     2553            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
     2554                    current_tarball_number);
     2555        }
     2556        if (!does_file_exist(tarball_fname)) {
     2557            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
     2558                    current_tarball_number);
     2559        }
     2560        if (!does_file_exist(tarball_fname)) {
     2561            if (current_tarball_number == 0) {
     2562                log_to_screen
     2563                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
     2564                return (0);
     2565            }
     2566            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
     2567                || system("find " MNT_CDROM
     2568                          "/archives/slice* > /dev/null 2> /dev/null") ==
     2569                0) {
     2570                break;
     2571            }
     2572            g_current_media_number++;
     2573            sprintf(progress_str, "Restoring from %s #%d",
     2574                    media_descriptor_string(bkpinfo->backup_media_type),
     2575                    g_current_media_number);
     2576            log_to_screen(progress_str);
     2577        } else {
     2578            sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
     2579                    current_tarball_number,
     2580                    media_descriptor_string(bkpinfo->backup_media_type),
     2581                    g_current_media_number);
     2582//    log_msg(3, "progress_str = %s", progress_str);
     2583            for (res = 999, attempts = 0; attempts < 3 && res != 0;
     2584                 attempts++) {
     2585                res =
     2586                    restore_a_tarball_from_CD(tarball_fname,
     2587                                              current_tarball_number,
     2588                                              filelist);
     2589            }
     2590            sprintf(tmp, "%s #%d, fileset #%ld - restore ",
     2591                    media_descriptor_string(bkpinfo->backup_media_type),
     2592                    g_current_media_number, current_tarball_number);
     2593            if (res) {
     2594                strcat(tmp, "reported errors");
     2595            } else if (attempts > 1) {
     2596                strcat(tmp, "succeeded");
     2597            } else {
     2598                strcat(tmp, "succeeded");
     2599            }
     2600            if (attempts > 1) {
     2601                sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
     2602                        attempts);
     2603            }
     2604            strcpy(comment, tmp);
     2605            if (attempts > 1) {
     2606                log_to_screen(comment);
     2607            }
     2608
     2609            retval += res;
     2610            current_tarball_number++;
     2611            g_current_progress++;
     2612        }
     2613    }
     2614    close_progress_form();
     2615    if (retval) {
     2616        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2617    } else {
     2618        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2619    }
     2620    paranoid_free(tmp);
     2621    paranoid_free(tarball_fname);
     2622    paranoid_free(progress_str);
     2623    paranoid_free(comment);
     2624
     2625    return (retval);
    26062626}
    26072627
     
    26202640 */
    26212641int
    2622 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, struct s_node*filelist)
     2642restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
     2643                                    struct s_node *filelist)
    26232644{
    2624   long noof_biggiefiles;
    2625   long current_bigfile_number = 0;
    2626   long total_slices;
    2627 
    2628   int retval = 0;
    2629   int res = 0;
    2630   int ctrl_chr;
     2645    long noof_biggiefiles;
     2646    long current_bigfile_number = 0;
     2647    long total_slices;
     2648
     2649    int retval = 0;
     2650    int res = 0;
     2651    int ctrl_chr;
    26312652
    26322653  /** malloc add ****/
    2633   char *tmp;
    2634   char *biggie_fname;
    2635   char *biggie_cksum;
    2636   char *xattr_fname;
    2637   char *acl_fname;
    2638   char *p;
    2639   char *pathname_of_last_biggie_restored; 
    2640   char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes
    2641   long long biggie_size;
    2642   FILE *fbw = NULL;
    2643 
    2644   malloc_string(tmp);
    2645   malloc_string(biggie_fname);
    2646   malloc_string(biggie_cksum);
    2647   malloc_string(xattr_fname);
    2648   malloc_string(acl_fname);
    2649   malloc_string(biggies_whose_EXATs_we_should_set);
    2650   malloc_string(pathname_of_last_biggie_restored);
    2651   assert(bkpinfo!=NULL);
    2652 
    2653   read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
    2654 
    2655   total_slices = atol(tmp);
    2656   sprintf(tmp, "Reassembling large files      ");
    2657   sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2658   sprintf(acl_fname,   ACL_BIGGLST_FNAME_RAW_SZ,   bkpinfo->tmpdir);
    2659   mvaddstr_and_log_it( g_currentY, 0, tmp );
    2660   sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    2661   if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w")))
    2662    { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); }
    2663  
     2654    char *tmp;
     2655    char *biggie_fname;
     2656    char *biggie_cksum;
     2657    char *xattr_fname;
     2658    char *acl_fname;
     2659    char *p;
     2660    char *pathname_of_last_biggie_restored;
     2661    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
     2662    long long biggie_size;
     2663    FILE *fbw = NULL;
     2664
     2665    malloc_string(tmp);
     2666    malloc_string(biggie_fname);
     2667    malloc_string(biggie_cksum);
     2668    malloc_string(xattr_fname);
     2669    malloc_string(acl_fname);
     2670    malloc_string(biggies_whose_EXATs_we_should_set);
     2671    malloc_string(pathname_of_last_biggie_restored);
     2672    assert(bkpinfo != NULL);
     2673
     2674    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
     2675
     2676    total_slices = atol(tmp);
     2677    sprintf(tmp, "Reassembling large files      ");
     2678    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2679    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2680    mvaddstr_and_log_it(g_currentY, 0, tmp);
     2681    sprintf(biggies_whose_EXATs_we_should_set,
     2682            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
     2683    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
     2684        log_msg(1, "Warning - cannot openout %s",
     2685                biggies_whose_EXATs_we_should_set);
     2686    }
    26642687// get xattr and acl files if they're there
    2665   res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr);
    2666   if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    2667     {
    2668       res = read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
    2669     }
    2670 
    2671   noof_biggiefiles = atol( biggie_fname );
    2672   sprintf( tmp, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles );
    2673   log_msg(2, tmp );
    2674   open_progress_form( "Reassembling large files",
    2675               "I am now reassembling all the large files." ,
    2676               "Please wait. This may take some time.",
    2677               "",
    2678               total_slices);
    2679 
    2680   for( res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); ctrl_chr!=BLK_STOP_BIGGIEFILES; res=read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr))
    2681     {
    2682       if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE)
    2683     {
    2684       wrong_marker(BLK_START_A_NORMBIGGIE,ctrl_chr);
    2685     }
    2686       p = strrchr(biggie_fname,'/');
    2687       if (!p)
    2688     {
    2689       p = biggie_fname;
    2690     }
    2691       else
    2692     {
    2693       p++;
    2694     }
    2695       sprintf(tmp,"Restoring big file %ld (%lld K)",current_bigfile_number+1, biggie_size/1024);
    2696       update_progress_form(tmp);
    2697       res = restore_a_biggiefile_from_stream(bkpinfo,biggie_fname,
    2698                          current_bigfile_number,
    2699                          biggie_cksum,
    2700                          biggie_size,
    2701                          filelist, ctrl_chr,
    2702                          pathname_of_last_biggie_restored);
    2703       log_msg(1, "I believe I have restored %s", pathname_of_last_biggie_restored);
    2704       if (fbw && pathname_of_last_biggie_restored[0])
    2705         { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); }
    2706       retval += res;
    2707       current_bigfile_number++;
    2708 
    2709     }
    2710   if (current_bigfile_number != noof_biggiefiles && noof_biggiefiles != 0 )
    2711     {
    2712       sprintf( tmp,
    2713            "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",current_bigfile_number,
    2714            noof_biggiefiles);
    2715     }
    2716   else
    2717     {
    2718       sprintf( tmp,"%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
    2719            noof_biggiefiles,
    2720            current_bigfile_number);
    2721     }
    2722   log_msg(1, tmp);
    2723 
    2724   if (fbw)
    2725     {
    2726       fclose(fbw);
    2727       if (length_of_file(biggies_whose_EXATs_we_should_set) >2)
    2728         {
    2729       iamhere("Setting biggie-EXATs");
    2730           if (length_of_file(acl_fname)  >0)
    2731             {
    2732           log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
    2733           set_acl_list  (biggies_whose_EXATs_we_should_set, acl_fname);
    2734         }
    2735           if (length_of_file(xattr_fname)>0)
    2736             {
    2737           log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
    2738           set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    2739         }
    2740     }
    2741       else
    2742         {
    2743       iamhere("No biggiefiles selected. So, no biggie-EXATs to set.");
    2744     }
    2745     }
    2746   if (does_file_exist("/PAUSE"))
    2747     { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); }
    2748 
    2749   close_progress_form();
    2750   if (retval)
    2751     {
    2752       mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
    2753     }
    2754   else
    2755     {
    2756       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2757     }
    2758   paranoid_free(biggies_whose_EXATs_we_should_set);
    2759   paranoid_free(pathname_of_last_biggie_restored);
    2760   paranoid_free(biggie_fname);
    2761   paranoid_free(biggie_cksum);
    2762   paranoid_free(xattr_fname);
    2763   paranoid_free(acl_fname);
    2764   paranoid_free(tmp);
    2765   return(retval);
     2688    res =
     2689        read_header_block_from_stream(&biggie_size, biggie_fname,
     2690                                      &ctrl_chr);
     2691    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     2692        res =
     2693            read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
     2694                                      &ctrl_chr, xattr_fname, acl_fname);
     2695    }
     2696
     2697    noof_biggiefiles = atol(biggie_fname);
     2698    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
     2699            noof_biggiefiles);
     2700    log_msg(2, tmp);
     2701    open_progress_form("Reassembling large files",
     2702                       "I am now reassembling all the large files.",
     2703                       "Please wait. This may take some time.",
     2704                       "", total_slices);
     2705
     2706    for (res =
     2707         read_header_block_from_stream(&biggie_size, biggie_fname,
     2708                                       &ctrl_chr);
     2709         ctrl_chr != BLK_STOP_BIGGIEFILES;
     2710         res =
     2711         read_header_block_from_stream(&biggie_size, biggie_fname,
     2712                                       &ctrl_chr)) {
     2713        if (ctrl_chr != BLK_START_A_NORMBIGGIE
     2714            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
     2715            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
     2716        }
     2717        p = strrchr(biggie_fname, '/');
     2718        if (!p) {
     2719            p = biggie_fname;
     2720        } else {
     2721            p++;
     2722        }
     2723        sprintf(tmp, "Restoring big file %ld (%lld K)",
     2724                current_bigfile_number + 1, biggie_size / 1024);
     2725        update_progress_form(tmp);
     2726        res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
     2727                                               current_bigfile_number,
     2728                                               biggie_cksum,
     2729                                               biggie_size,
     2730                                               filelist, ctrl_chr,
     2731                                               pathname_of_last_biggie_restored);
     2732        log_msg(1, "I believe I have restored %s",
     2733                pathname_of_last_biggie_restored);
     2734        if (fbw && pathname_of_last_biggie_restored[0]) {
     2735            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
     2736        }
     2737        retval += res;
     2738        current_bigfile_number++;
     2739
     2740    }
     2741    if (current_bigfile_number != noof_biggiefiles
     2742        && noof_biggiefiles != 0) {
     2743        sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
     2744                current_bigfile_number, noof_biggiefiles);
     2745    } else {
     2746        sprintf(tmp,
     2747                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
     2748                noof_biggiefiles, current_bigfile_number);
     2749    }
     2750    log_msg(1, tmp);
     2751
     2752    if (fbw) {
     2753        fclose(fbw);
     2754        if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
     2755            iamhere("Setting biggie-EXATs");
     2756            if (length_of_file(acl_fname) > 0) {
     2757                log_msg(1, "set_acl_list(%s,%s)",
     2758                        biggies_whose_EXATs_we_should_set, acl_fname);
     2759                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
     2760            }
     2761            if (length_of_file(xattr_fname) > 0) {
     2762                log_msg(1, "set_fattr_List(%s,%s)",
     2763                        biggies_whose_EXATs_we_should_set, xattr_fname);
     2764                set_fattr_list(biggies_whose_EXATs_we_should_set,
     2765                               xattr_fname);
     2766            }
     2767        } else {
     2768            iamhere
     2769                ("No biggiefiles selected. So, no biggie-EXATs to set.");
     2770        }
     2771    }
     2772    if (does_file_exist("/PAUSE")) {
     2773        popup_and_OK
     2774            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
     2775    }
     2776
     2777    close_progress_form();
     2778    if (retval) {
     2779        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2780    } else {
     2781        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2782    }
     2783    paranoid_free(biggies_whose_EXATs_we_should_set);
     2784    paranoid_free(pathname_of_last_biggie_restored);
     2785    paranoid_free(biggie_fname);
     2786    paranoid_free(biggie_cksum);
     2787    paranoid_free(xattr_fname);
     2788    paranoid_free(acl_fname);
     2789    paranoid_free(tmp);
     2790    return (retval);
    27662791}
     2792
    27672793/**************************************************************************
    27682794 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
     
    27852811 */
    27862812int
    2787 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
     2813restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
     2814                                 struct s_node *filelist)
    27882815{
    2789   int retval = 0;
    2790   int res;
    2791   long current_afioball_number = 0;
    2792   int ctrl_chr;
    2793   long max_val /*, total_noof_files */;
     2816    int retval = 0;
     2817    int res;
     2818    long current_afioball_number = 0;
     2819    int ctrl_chr;
     2820    long max_val /*, total_noof_files */ ;
    27942821
    27952822  /** malloc **/
    2796   char *tmp;
    2797   char *progress_str;
    2798   char *tmp_fname;
    2799   char *xattr_fname;
    2800   char *acl_fname;
    2801 
    2802   long long tmp_size;
    2803 
    2804   malloc_string(tmp);
    2805   malloc_string(progress_str);
    2806   malloc_string(tmp_fname);
    2807   assert(bkpinfo!=NULL);
    2808   malloc_string(xattr_fname);
    2809   malloc_string(acl_fname);
    2810   mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
    2811   read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    2812   max_val = atol(tmp) + 1;
    2813 
    2814   chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
    2815 
    2816   run_program_and_log_output("pwd", 5);
    2817 
    2818   sprintf(progress_str,"Restoring from media #%d",g_current_media_number);
    2819   log_to_screen(progress_str);
    2820   open_progress_form("Restoring from archives",
    2821              "Restoring data from the archives." ,
    2822              "Please wait. This may take some time.",
    2823              progress_str,max_val);
    2824 
    2825   log_msg(3, "hey");
    2826 
    2827   res = read_header_block_from_stream( &tmp_size, tmp_fname, &ctrl_chr);
    2828   if (res)
    2829     {
    2830       log_msg(2, "Warning - error reading afioball from tape");
    2831     }
    2832   retval += res;
    2833   if ( ctrl_chr != BLK_START_AFIOBALLS)
    2834     {
    2835       wrong_marker(BLK_START_AFIOBALLS,ctrl_chr);
    2836     }
    2837   log_msg(2, "ho");
    2838   res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    2839   while(ctrl_chr!=BLK_STOP_AFIOBALLS)
    2840     {
    2841       update_progress_form(progress_str);
    2842       sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    2843       sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
    2844       unlink(xattr_fname);
    2845       unlink(acl_fname);
    2846       if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES)
    2847         {
    2848       iamhere("Reading EXAT files from tape");
    2849       res = read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
    2850         }
    2851       if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE)
    2852         { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); }
    2853       sprintf(tmp,
    2854           "Restoring from fileset #%ld (name=%s, size=%ld K)",
    2855           current_afioball_number,
    2856           tmp_fname,
    2857           (long) tmp_size>>10);
    2858       res = restore_a_tarball_from_stream(bkpinfo,tmp_fname,current_afioball_number,filelist,tmp_size, xattr_fname, acl_fname);
    2859       retval += res;
    2860       if ( res )
    2861         {
    2862       sprintf(tmp,"Fileset %ld - errors occurred",current_afioball_number);
    2863       log_to_screen(tmp);
    2864     }
    2865       res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    2866       if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE)
    2867     {
    2868       wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE,ctrl_chr);
    2869     }
    2870 
    2871       current_afioball_number++;
    2872       g_current_progress++;
    2873       sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",current_afioball_number, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);     
    2874       res=read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
    2875       unlink(xattr_fname);
    2876       unlink(acl_fname);
    2877     } // next
    2878   log_msg(1, "All done with afioballs");
    2879   close_progress_form();
    2880   if (retval)
    2881     {
    2882       mvaddstr_and_log_it(g_currentY++,74,"Errors."); }
    2883   else
    2884     {
    2885       mvaddstr_and_log_it(g_currentY++,74,"Done."); }
    2886   paranoid_free(tmp);
    2887   paranoid_free(progress_str);
    2888   paranoid_free(tmp_fname);
    2889   paranoid_free(xattr_fname);
    2890   paranoid_free(acl_fname);
    2891   return(retval);
     2823    char *tmp;
     2824    char *progress_str;
     2825    char *tmp_fname;
     2826    char *xattr_fname;
     2827    char *acl_fname;
     2828
     2829    long long tmp_size;
     2830
     2831    malloc_string(tmp);
     2832    malloc_string(progress_str);
     2833    malloc_string(tmp_fname);
     2834    assert(bkpinfo != NULL);
     2835    malloc_string(xattr_fname);
     2836    malloc_string(acl_fname);
     2837    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
     2838    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     2839    max_val = atol(tmp) + 1;
     2840
     2841    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
     2842
     2843    run_program_and_log_output("pwd", 5);
     2844
     2845    sprintf(progress_str, "Restoring from media #%d",
     2846            g_current_media_number);
     2847    log_to_screen(progress_str);
     2848    open_progress_form("Restoring from archives",
     2849                       "Restoring data from the archives.",
     2850                       "Please wait. This may take some time.",
     2851                       progress_str, max_val);
     2852
     2853    log_msg(3, "hey");
     2854
     2855    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2856    if (res) {
     2857        log_msg(2, "Warning - error reading afioball from tape");
     2858    }
     2859    retval += res;
     2860    if (ctrl_chr != BLK_START_AFIOBALLS) {
     2861        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
     2862    }
     2863    log_msg(2, "ho");
     2864    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2865    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
     2866        update_progress_form(progress_str);
     2867        sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
     2868                current_afioball_number);
     2869        sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
     2870                current_afioball_number);
     2871        unlink(xattr_fname);
     2872        unlink(acl_fname);
     2873        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
     2874            iamhere("Reading EXAT files from tape");
     2875            res =
     2876                read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
     2877                                          &ctrl_chr, xattr_fname,
     2878                                          acl_fname);
     2879        }
     2880        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     2881            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     2882        }
     2883        sprintf(tmp,
     2884                "Restoring from fileset #%ld (name=%s, size=%ld K)",
     2885                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
     2886        res =
     2887            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
     2888                                          current_afioball_number,
     2889                                          filelist, tmp_size, xattr_fname,
     2890                                          acl_fname);
     2891        retval += res;
     2892        if (res) {
     2893            sprintf(tmp, "Fileset %ld - errors occurred",
     2894                    current_afioball_number);
     2895            log_to_screen(tmp);
     2896        }
     2897        res =
     2898            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2899        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     2900            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
     2901        }
     2902
     2903        current_afioball_number++;
     2904        g_current_progress++;
     2905        sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
     2906                current_afioball_number,
     2907                media_descriptor_string(bkpinfo->backup_media_type),
     2908                g_current_media_number);
     2909        res =
     2910            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
     2911        unlink(xattr_fname);
     2912        unlink(acl_fname);
     2913    }                           // next
     2914    log_msg(1, "All done with afioballs");
     2915    close_progress_form();
     2916    if (retval) {
     2917        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     2918    } else {
     2919        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2920    }
     2921    paranoid_free(tmp);
     2922    paranoid_free(progress_str);
     2923    paranoid_free(tmp_fname);
     2924    paranoid_free(xattr_fname);
     2925    paranoid_free(acl_fname);
     2926    return (retval);
    28922927}
     2928
    28932929/**************************************************************************
    28942930 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM                                   *
     
    29062942 * @ingroup restoreGroup
    29072943 */
    2908 int
    2909 restore_everything(struct s_bkpinfo*bkpinfo,
    2910            struct s_node *filelist)
     2944int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
    29112945{
    2912   int resA;
    2913   int resB;
     2946    int resA;
     2947    int resB;
    29142948
    29152949  /** mallco ***/
    2916   char *cwd;
    2917   char *newpath;
    2918   char *tmp;
    2919   assert(bkpinfo!=NULL);
    2920 
    2921   malloc_string(cwd);
    2922   malloc_string(newpath);
    2923   malloc_string(tmp);
    2924   log_msg(2, "restore_everything() --- starting");
    2925   g_current_media_number = 1;
    2926   getcwd(cwd, MAX_STR_LEN - 1);
    2927   sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
    2928   run_program_and_log_output(tmp, FALSE);
    2929   log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
    2930   chdir(bkpinfo->restore_path);
    2931   getcwd(newpath,MAX_STR_LEN-1);
    2932   log_msg(1, "path is now %s", newpath);
    2933   log_msg(1, "restoring everything");
    2934   if (!find_home_of_exe("petris") && !g_text_mode)
    2935     {
    2936       newtDrawRootText(0, g_noof_rows-2, "Press ALT-<left cursor> twice to play Petris :-) ");
    2937       newtRefresh();
    2938     }
    2939   mvaddstr_and_log_it (g_currentY, 0, "Preparing to read your archives");
    2940   if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) )
    2941     {
    2942       mount_cdrom( bkpinfo );
    2943       mvaddstr_and_log_it ( g_currentY++, 0, "Restoring OS and data from streaming media");
    2944       if (bkpinfo->backup_media_type == cdstream)
    2945         {
    2946       openin_cdstream( bkpinfo );
    2947     }
    2948       else
    2949         {
    2950       assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
    2951       openin_tape(bkpinfo);
    2952     }
    2953       resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
    2954       resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
    2955       if (bkpinfo->backup_media_type == cdstream)
    2956         {
    2957       closein_cdstream(bkpinfo);
    2958     }
    2959       else
    2960         {
    2961       closein_tape(bkpinfo);
    2962     }
    2963     }
    2964   else
    2965     {
    2966       mvaddstr_and_log_it (g_currentY++, 0, "Restoring OS and data from CD       ");
    2967       mount_cdrom(bkpinfo);
    2968       resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
    2969       resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
    2970     }
    2971   chdir(cwd);
    2972   if ( resA + resB )
    2973     {
    2974       log_to_screen("Errors occurred while data was being restored.");
    2975     }
    2976   if ( length_of_file("/etc/raidtab") > 0 )
    2977     {
    2978       log_msg(2, "Copying local raidtab to restored filesystem");
    2979       run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING "/etc/raidtab", FALSE);
    2980     }
    2981   kill_petris();
    2982   log_msg(2, "restore_everything() --- leaving");
    2983   paranoid_free(cwd);
    2984   paranoid_free(newpath);
    2985   paranoid_free(tmp);
    2986   return(resA+resB);
     2950    char *cwd;
     2951    char *newpath;
     2952    char *tmp;
     2953    assert(bkpinfo != NULL);
     2954
     2955    malloc_string(cwd);
     2956    malloc_string(newpath);
     2957    malloc_string(tmp);
     2958    log_msg(2, "restore_everything() --- starting");
     2959    g_current_media_number = 1;
     2960    getcwd(cwd, MAX_STR_LEN - 1);
     2961    sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
     2962    run_program_and_log_output(tmp, FALSE);
     2963    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
     2964    chdir(bkpinfo->restore_path);
     2965    getcwd(newpath, MAX_STR_LEN - 1);
     2966    log_msg(1, "path is now %s", newpath);
     2967    log_msg(1, "restoring everything");
     2968    if (!find_home_of_exe("petris") && !g_text_mode) {
     2969        newtDrawRootText(0, g_noof_rows - 2,
     2970                         "Press ALT-<left cursor> twice to play Petris :-) ");
     2971        newtRefresh();
     2972    }
     2973    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
     2974    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2975        mount_cdrom(bkpinfo);
     2976        mvaddstr_and_log_it(g_currentY++, 0,
     2977                            "Restoring OS and data from streaming media");
     2978        if (bkpinfo->backup_media_type == cdstream) {
     2979            openin_cdstream(bkpinfo);
     2980        } else {
     2981            assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
     2982                                                         media_device);
     2983            openin_tape(bkpinfo);
     2984        }
     2985        resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
     2986        resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
     2987        if (bkpinfo->backup_media_type == cdstream) {
     2988            closein_cdstream(bkpinfo);
     2989        } else {
     2990            closein_tape(bkpinfo);
     2991        }
     2992    } else {
     2993        mvaddstr_and_log_it(g_currentY++, 0,
     2994                            "Restoring OS and data from CD       ");
     2995        mount_cdrom(bkpinfo);
     2996        resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
     2997        resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
     2998    }
     2999    chdir(cwd);
     3000    if (resA + resB) {
     3001        log_to_screen("Errors occurred while data was being restored.");
     3002    }
     3003    if (length_of_file("/etc/raidtab") > 0) {
     3004        log_msg(2, "Copying local raidtab to restored filesystem");
     3005        run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
     3006                                   "/etc/raidtab", FALSE);
     3007    }
     3008    kill_petris();
     3009    log_msg(2, "restore_everything() --- leaving");
     3010    paranoid_free(cwd);
     3011    paranoid_free(newpath);
     3012    paranoid_free(tmp);
     3013    return (resA + resB);
    29873014}
    29883015
     
    29973024 */
    29983025int
    2999 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 
    3000                 char *monitas_device,
    3001                  char *restore_this_directory,
    3002                 char *restore_here)
    3003     /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
     3026restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
     3027                                char *monitas_device,
     3028                                 char *restore_this_directory,
     3029                                char *restore_here)
     3030    /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
    30043031{
    3005   FILE *fout;
    3006   int retval = 0;
    3007   int i;
    3008   int j;
    3009   struct mountlist_itself the_mountlist;
    3010   static struct raidlist_itself the_raidlist;
     3032    FILE *fout;
     3033    int retval = 0;
     3034    int i;
     3035    int j;
     3036    struct mountlist_itself the_mountlist;
     3037    static struct raidlist_itself the_raidlist;
    30113038  /** malloc **/
    3012   char tmp[ MAX_STR_LEN + 1 ];
    3013   char command[ MAX_STR_LEN + 1 ];
    3014   char datablock[ 256 * 1024 ];
    3015   char datadisks_fname[ MAX_STR_LEN + 1 ];
    3016   long k;
    3017   long length;
    3018   long long llt;
    3019   struct s_node *filelist = NULL;
    3020   assert(bkpinfo!=NULL);
    3021   assert_string_is_neither_NULL_nor_zerolength(monitas_device);
    3022   assert(restore_this_directory != NULL);
    3023   assert(restore_here != NULL);
    3024 
    3025   sprintf(tmp, "restore_here = '%s'", restore_here);
    3026 
    3027   log_msg(2, tmp);
    3028  
    3029   log_msg(2, "restore_live_from_monitas_server() - starting");
    3030   unlink("/tmp/mountlist.txt"); unlink("/tmp/filelist.full");
    3031   unlink("/tmp/biggielist.txt");
    3032   if ( restore_here[0] == '\0' )
    3033     {
    3034       strcpy(bkpinfo->restore_path, MNT_RESTORING);
    3035     }
    3036   else
    3037     {
    3038       strcpy(bkpinfo->restore_path, restore_here);
    3039     }
    3040   log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
    3041   sprintf(tmp, "FYI - data will be restored to %s", bkpinfo->restore_path);
    3042   log_msg(3, tmp);
    3043   log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
    3044   sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", (int)(random()%32768));
    3045   chdir(bkpinfo->tmpdir);
    3046 
    3047   sprintf(command, "cat %s", monitas_device);
    3048   g_tape_stream=popen(command, "r"); // for compatibility with openin_tape()
    3049   if (!(fout = fopen(datadisks_fname, "w"))) { log_OS_error(datadisks_fname); return(1); }
    3050   for (i = 0; i < 32; i++)
    3051     {
    3052       for (j = 0; j < 4; j++)
    3053         {
    3054           for( length = k = 0; length < 256 * 1024; length += k)
    3055             {
    3056               k = fread( datablock + length, 1, 256 * 1024 - length, g_tape_stream);
    3057             }
    3058           fwrite (datablock, 1, length, fout);
    3059           g_tape_posK += length;
    3060         }
    3061     }
    3062   paranoid_fclose(fout);
    3063   sprintf( command,
    3064        "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
    3065        datadisks_fname);
    3066   run_program_and_log_output(command, 4);
    3067   read_header_block_from_stream (&llt, tmp, &i);
    3068   read_header_block_from_stream (&llt, tmp, &i);
    3069 
    3070   unlink(datadisks_fname);
    3071   read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    3072   retval = load_mountlist( &the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
    3073  
    3074 
    3075   load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME );
    3076   iamhere("FIXME");
    3077   fatal_error("This will fail");
    3078   sprintf( command,
    3079        "cat %s | grep -x \"%s.*\" > %s",
    3080        g_filelist_full,
    3081        restore_this_directory,
    3082        g_filelist_full);
    3083   if (system(command))
    3084     {
    3085       retval++;
    3086       log_to_screen("Error(s) occurred while processing filelist and wildcard");
    3087     }
    3088   iamhere("FIXME");
    3089   fatal_error("This will fail");
    3090   sprintf(command,
    3091       "cat %s | grep -x \"%s.*\" > %s",
    3092       g_biggielist_txt,
    3093       restore_this_directory,
    3094       g_biggielist_txt);
    3095   if (system(command))
    3096     {
    3097       log_msg(1, "Error(s) occurred while processing biggielist and wildcard");
    3098     }
    3099   sprintf(command, "touch %s", g_biggielist_txt);
    3100   run_program_and_log_output(command, FALSE);
     3039    char tmp[MAX_STR_LEN + 1];
     3040    char command[MAX_STR_LEN + 1];
     3041    char datablock[256 * 1024];
     3042    char datadisks_fname[MAX_STR_LEN + 1];
     3043    long k;
     3044    long length;
     3045    long long llt;
     3046    struct s_node *filelist = NULL;
     3047    assert(bkpinfo != NULL);
     3048    assert_string_is_neither_NULL_nor_zerolength(monitas_device);
     3049    assert(restore_this_directory != NULL);
     3050    assert(restore_here != NULL);
     3051
     3052    sprintf(tmp, "restore_here = '%s'", restore_here);
     3053
     3054    log_msg(2, tmp);
     3055
     3056    log_msg(2, "restore_live_from_monitas_server() - starting");
     3057    unlink("/tmp/mountlist.txt");
     3058    unlink("/tmp/filelist.full");
     3059    unlink("/tmp/biggielist.txt");
     3060    if (restore_here[0] == '\0') {
     3061        strcpy(bkpinfo->restore_path, MNT_RESTORING);
     3062    } else {
     3063        strcpy(bkpinfo->restore_path, restore_here);
     3064    }
     3065    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
     3066    sprintf(tmp, "FYI - data will be restored to %s",
     3067            bkpinfo->restore_path);
     3068    log_msg(3, tmp);
     3069    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
     3070    sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
     3071            (int) (random() % 32768));
     3072    chdir(bkpinfo->tmpdir);
     3073
     3074    sprintf(command, "cat %s", monitas_device);
     3075    g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
     3076    if (!(fout = fopen(datadisks_fname, "w"))) {
     3077        log_OS_error(datadisks_fname);
     3078        return (1);
     3079    }
     3080    for (i = 0; i < 32; i++) {
     3081        for (j = 0; j < 4; j++) {
     3082            for (length = k = 0; length < 256 * 1024; length += k) {
     3083                k = fread(datablock + length, 1, 256 * 1024 - length,
     3084                          g_tape_stream);
     3085            }
     3086            fwrite(datablock, 1, length, fout);
     3087            g_tape_posK += length;
     3088        }
     3089    }
     3090    paranoid_fclose(fout);
     3091    sprintf(command,
     3092            "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
     3093            datadisks_fname);
     3094    run_program_and_log_output(command, 4);
     3095    read_header_block_from_stream(&llt, tmp, &i);
     3096    read_header_block_from_stream(&llt, tmp, &i);
     3097
     3098    unlink(datadisks_fname);
     3099    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     3100    retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
     3101
     3102
     3103    load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
     3104    iamhere("FIXME");
     3105    fatal_error("This will fail");
     3106    sprintf(command,
     3107            "cat %s | grep -x \"%s.*\" > %s",
     3108            g_filelist_full, restore_this_directory, g_filelist_full);
     3109    if (system(command)) {
     3110        retval++;
     3111        log_to_screen
     3112            ("Error(s) occurred while processing filelist and wildcard");
     3113    }
     3114    iamhere("FIXME");
     3115    fatal_error("This will fail");
     3116    sprintf(command,
     3117            "cat %s | grep -x \"%s.*\" > %s",
     3118            g_biggielist_txt, restore_this_directory, g_biggielist_txt);
     3119    if (system(command)) {
     3120        log_msg(1,
     3121                "Error(s) occurred while processing biggielist and wildcard");
     3122    }
     3123    sprintf(command, "touch %s", g_biggielist_txt);
     3124    run_program_and_log_output(command, FALSE);
    31013125//  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
    3102   retval += restore_everything(bkpinfo, filelist);
    3103   free_filelist(filelist);
    3104   log_msg(2, "--------End of restore_live_from_monitas_server--------");
    3105   return(retval);
     3126    retval += restore_everything(bkpinfo, filelist);
     3127    free_filelist(filelist);
     3128    log_msg(2, "--------End of restore_live_from_monitas_server--------");
     3129    return (retval);
    31063130}
     3131
    31073132/**************************************************************************
    31083133 *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
     
    31123137
    31133138
    3114 extern void wait_until_software_raids_are_prepped(char*, int);
     3139extern void wait_until_software_raids_are_prepped(char *, int);
    31153140
    31163141
     
    31233148void welcome_to_mondorestore()
    31243149{
    3125   log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION);
    3126   log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please " );
    3127   log_msg(0, "don't break out in a cold sweat just because you see a few  " );
    3128   log_msg(0, "error messages in the log. Read them; analyze them; see if  " );
    3129   log_msg(0, "they are significant; above all, verify your backups! Please" );
    3130   log_msg(0, "attach a compressed copy of this log to any e-mail you send " );
    3131   log_msg(0, "to the Mondo mailing list when you are seeking technical    " );
    3132   log_msg(0, "support. Without it, we can't help you.               - Hugo" );
    3133   log_msg(0, "------------------------------------------------------------" );
    3134   log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages," );
    3135   log_msg(0, "some users are inclined to stop reading this log.  If Mondo " );
    3136   log_msg(0, "stopped for some reason, chances are it's detailed here.    " );
    3137   log_msg(0, "More than likely there's a message at the very end of this  " );
    3138   log_msg(0, "log that will tell you what is wrong.  Please read it!      " );
    3139   log_msg(0, "------------------------------------------------------------");
     3150    log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION);
     3151    log_msg(0,
     3152            "DON'T PANIC! Mondorestore logs almost everything, so please ");
     3153    log_msg(0,
     3154            "don't break out in a cold sweat just because you see a few  ");
     3155    log_msg(0,
     3156            "error messages in the log. Read them; analyze them; see if  ");
     3157    log_msg(0,
     3158            "they are significant; above all, verify your backups! Please");
     3159    log_msg(0,
     3160            "attach a compressed copy of this log to any e-mail you send ");
     3161    log_msg(0,
     3162            "to the Mondo mailing list when you are seeking technical    ");
     3163    log_msg(0,
     3164            "support. Without it, we can't help you.               - Hugo");
     3165    log_msg(0,
     3166            "------------------------------------------------------------");
     3167    log_msg(0,
     3168            "BTW, despite (or perhaps because of) the wealth of messages,");
     3169    log_msg(0,
     3170            "some users are inclined to stop reading this log.  If Mondo ");
     3171    log_msg(0,
     3172            "stopped for some reason, chances are it's detailed here.    ");
     3173    log_msg(0,
     3174            "More than likely there's a message at the very end of this  ");
     3175    log_msg(0,
     3176            "log that will tell you what is wrong.  Please read it!      ");
     3177    log_msg(0,
     3178            "------------------------------------------------------------");
    31403179}
    31413180
     
    31463185 * What did you think it did, anyway? :-)
    31473186 */
    3148 int
    3149 main(int argc, char*argv[])
     3187int main(int argc, char *argv[])
    31503188{
    3151       FILE*fin;
    3152       FILE*fout;
    3153   int retval = 0;
    3154   int res;
     3189    FILE *fin;
     3190    FILE *fout;
     3191    int retval = 0;
     3192    int res;
    31553193//  int c;
    3156   char *tmp;
     3194    char *tmp;
    31573195
    31583196#ifndef VERSION
     
    31603198#endif
    31613199
    3162   struct mountlist_itself    *mountlist;
    3163   struct raidlist_itself      *raidlist;
    3164   struct s_bkpinfo            *bkpinfo;
    3165   struct s_node *filelist;
    3166   char *a, *b;
     3200    struct mountlist_itself *mountlist;
     3201    struct raidlist_itself *raidlist;
     3202    struct s_bkpinfo *bkpinfo;
     3203    struct s_node *filelist;
     3204    char *a, *b;
    31673205
    31683206  /**************************************************************************
     
    31713209   *                                                                        *
    31723210   **************************************************************************/
    3173   if (getuid () != 0)
    3174     {
    3175       fprintf (stderr, "Please run as root.\r\n");
    3176       exit (127);
    3177     }
    3178 
    3179   g_loglevel = DEFAULT_MR_LOGLEVEL;
    3180   malloc_string(tmp);
    3181  
     3211    if (getuid() != 0) {
     3212        fprintf(stderr, "Please run as root.\r\n");
     3213        exit(127);
     3214    }
     3215
     3216    g_loglevel = DEFAULT_MR_LOGLEVEL;
     3217    malloc_string(tmp);
     3218
    31823219/* Configure global variables */
    31833220#ifdef __FreeBSD__
    3184   if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "textonly"))
     3221    if (strstr
     3222        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
     3223         "textonly"))
    31853224#else
    3186   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "textonly"))
     3225    if (strstr
     3226        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     3227         "textonly"))
    31873228#endif
    3188     { g_text_mode = TRUE; log_msg(1, "TEXTONLY MODE"); }
    3189   else
    3190     { g_text_mode = FALSE; }               // newt :-)
    3191   if ( ! ( bkpinfo = g_bkpinfo_DONTUSETHIS = malloc( sizeof(struct s_bkpinfo))))
    3192     { fatal_error( "Cannot malloc bkpinfo" ); }
    3193   if ( ! ( mountlist = malloc (sizeof(struct mountlist_itself))))
    3194     { fatal_error ("Cannot malloc mountlist" ); }
    3195   if ( ! ( raidlist = malloc (sizeof(struct raidlist_itself))))
    3196     { fatal_error ("Cannot malloc raidlist" ); }
    3197 
    3198   malloc_libmondo_global_strings();
    3199 
    3200   strcpy( g_mondo_home, call_program_and_get_last_line_of_output("which mondorestore") );
    3201   sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
    3202   make_hole_for_dir(g_tmpfs_mountpt);
    3203   g_current_media_number = 1;        // precaution
    3204 
    3205   run_program_and_log_output ("mkdir -p " MNT_CDROM, FALSE);
    3206   run_program_and_log_output ("mkdir -p /mnt/floppy", FALSE);
    3207 
    3208   malloc_string(tmp);
    3209   malloc_string(a);
    3210   malloc_string(b);
    3211   setup_MR_global_filenames( bkpinfo ); // malloc() and set globals, using bkpinfo->tmpdir etc.
    3212   reset_bkpinfo( bkpinfo );
    3213   bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
    3214   bkpinfo->restore_data = TRUE;      // Well, yeah :-)
    3215   if (am_I_in_disaster_recovery_mode())
    3216     { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros
    3217   g_main_pid = getpid();
    3218   srandom( (int)(time(NULL)) );
    3219   register_pid( getpid(), "mondo" );
    3220   set_signals(TRUE);
    3221   g_kernel_version = get_kernel_version();
    3222 
    3223   log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
    3224   if (strlen(g_mountlist_fname) < 3)
    3225     { fatal_error("Serious error in malloc()'ing. Could be a bug in your glibc."); }
    3226   mkdir(MNT_CDROM, 0x770);
    3227  
     3229    {
     3230        g_text_mode = TRUE;
     3231        log_msg(1, "TEXTONLY MODE");
     3232    } else {
     3233        g_text_mode = FALSE;
     3234    }                           // newt :-)
     3235    if (!
     3236        (bkpinfo = g_bkpinfo_DONTUSETHIS =
     3237         malloc(sizeof(struct s_bkpinfo)))) {
     3238        fatal_error("Cannot malloc bkpinfo");
     3239    }
     3240    if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
     3241        fatal_error("Cannot malloc mountlist");
     3242    }
     3243    if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
     3244        fatal_error("Cannot malloc raidlist");
     3245    }
     3246
     3247    malloc_libmondo_global_strings();
     3248
     3249    strcpy(g_mondo_home,
     3250           call_program_and_get_last_line_of_output("which mondorestore"));
     3251    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
     3252    make_hole_for_dir(g_tmpfs_mountpt);
     3253    g_current_media_number = 1; // precaution
     3254
     3255    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
     3256    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
     3257
     3258    malloc_string(tmp);
     3259    malloc_string(a);
     3260    malloc_string(b);
     3261    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
     3262    reset_bkpinfo(bkpinfo);
     3263    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     3264    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
     3265    if (am_I_in_disaster_recovery_mode()) {
     3266        run_program_and_log_output("mount / -o remount,rw", 2);
     3267    }                           // for b0rken distros
     3268    g_main_pid = getpid();
     3269    srandom((int) (time(NULL)));
     3270    register_pid(getpid(), "mondo");
     3271    set_signals(TRUE);
     3272    g_kernel_version = get_kernel_version();
     3273
     3274    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
     3275    if (strlen(g_mountlist_fname) < 3) {
     3276        fatal_error
     3277            ("Serious error in malloc()'ing. Could be a bug in your glibc.");
     3278    }
     3279    mkdir(MNT_CDROM, 0x770);
     3280
    32283281/* Backup original mountlist.txt */
    3229   sprintf (tmp, "%s.orig", g_mountlist_fname);
    3230   if (!does_file_exist(g_mountlist_fname))
    3231     {
    3232       log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname);
    3233     }
    3234   else if ( !does_file_exist(tmp) )
    3235     {
    3236        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname);
    3237        run_program_and_log_output(tmp, FALSE);
    3238     }
     3282    sprintf(tmp, "%s.orig", g_mountlist_fname);
     3283    if (!does_file_exist(g_mountlist_fname)) {
     3284        log_msg(2,
     3285                "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
     3286                __LINE__, g_mountlist_fname);
     3287    } else if (!does_file_exist(tmp)) {
     3288        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
     3289                g_mountlist_fname);
     3290        run_program_and_log_output(tmp, FALSE);
     3291    }
    32393292
    32403293/* Init directories */
    3241   make_hole_for_dir(bkpinfo->tmpdir);
    3242   sprintf( tmp, "mkdir -p %s", bkpinfo->tmpdir );
    3243   run_program_and_log_output( tmp, FALSE );
    3244   make_hole_for_dir( "/var/log");
    3245   make_hole_for_dir( "/tmp/tmpfs"); /* just in case... */
    3246   run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    3247   run_program_and_log_output( "ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", FALSE );
    3248 
    3249   run_program_and_log_output( "rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
     3294    make_hole_for_dir(bkpinfo->tmpdir);
     3295    sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
     3296    run_program_and_log_output(tmp, FALSE);
     3297    make_hole_for_dir("/var/log");
     3298    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
     3299    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3300    run_program_and_log_output
     3301        ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log",
     3302         FALSE);
     3303
     3304    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
    32503305
    32513306/* Init GUI */
    3252   malloc_libmondo_global_strings();
    3253   setup_newt_stuff();                       /* call newtInit and setup screen log */
    3254   welcome_to_mondorestore();
    3255   if ( bkpinfo->disaster_recovery )
    3256     { log_msg(1, "I am in disaster recovery mode" ); }
    3257   else
    3258     { log_msg(1, "I am in normal, live mode" ); }
    3259 
    3260   iamhere("what time is it");
     3307    malloc_libmondo_global_strings();
     3308    setup_newt_stuff();         /* call newtInit and setup screen log */
     3309    welcome_to_mondorestore();
     3310    if (bkpinfo->disaster_recovery) {
     3311        log_msg(1, "I am in disaster recovery mode");
     3312    } else {
     3313        log_msg(1, "I am in normal, live mode");
     3314    }
     3315
     3316    iamhere("what time is it");
    32613317
    32623318/* Process command-line parameters */
    3263   if (argc == 2 && strcmp( argv[1], "--edit-mountlist" ) == 0 )
    3264     {
     3319    if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
    32653320#ifdef __FreeBSD__
    3266     system ("mv -f /tmp/raidconf.txt /etc/raidtab");
    3267     if (!does_file_exist ("/etc/raidtab"))
    3268         system ("vinum printconfig > /etc/raidtab");
     3321        system("mv -f /tmp/raidconf.txt /etc/raidtab");
     3322        if (!does_file_exist("/etc/raidtab"))
     3323            system("vinum printconfig > /etc/raidtab");
    32693324#endif
    3270       load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3271       if (!does_file_exist(g_mountlist_fname)) { strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); }
    3272       res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
     3325        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3326        if (!does_file_exist(g_mountlist_fname)) {
     3327            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3328        }
     3329        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
    32733330#ifdef __FreeBSD__
    3274       system ("mv -f /etc/raidtab /tmp/raidconf.txt");
     3331        system("mv -f /etc/raidtab /tmp/raidconf.txt");
    32753332#endif
    3276       paranoid_MR_finish(res);
    3277     }
    3278 
    3279   g_loglevel = DEFAULT_MR_LOGLEVEL;
    3280   if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0)
    3281     {
    3282       fout = fopen("/tmp/out.txt", "w");
    3283       fput_string_one_char_at_a_time(stderr, argv[2]);
    3284       finish(0);
    3285     }     
    3286 
    3287   if (argc == 3 && strcmp( argv[1], "--gendf" ) == 0 )
    3288     {
    3289       make_grub_install_scriptlet(argv[2]);
    3290       finish(0);
    3291     }
    3292 
    3293   if (argc >= 2 && strcmp(argv[1], "--pih" ) == 0 )
    3294     {
    3295       if (system("mount | grep cdrom 2> /dev/null > /dev/null"))
    3296         { system("mount "MNT_CDROM); }
    3297       bkpinfo->compression_level = 1;
    3298       g_current_media_number = 2;
    3299       strcpy(bkpinfo->restore_path, "/tmp/TESTING");
    3300       bkpinfo->backup_media_type = dvd;
    3301         open_progress_form( "Reassembling /dev/hda1",
    3302               "Shark is a bit of a silly person." ,
    3303               "Please wait. This may take some time.",
    3304               "",
    3305               1999);
    3306      system("rm -Rf /tmp/*pih*");
    3307 
    3308       restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
    3309     }
    3310 
    3311   if (argc == 5 && strcmp( argv[1], "--common") == 0 )
    3312     {
    3313       g_loglevel = 6;
    3314       filelist = load_filelist(argv[2]);
    3315       if (!filelist) { fatal_error("Failed to load filelist"); }
    3316       toggle_node_selection (filelist, FALSE);
    3317       toggle_all_root_dirs_on (filelist);
    3318       toggle_path_selection (filelist, "/usr/share", TRUE);
     3333        paranoid_MR_finish(res);
     3334    }
     3335
     3336    g_loglevel = DEFAULT_MR_LOGLEVEL;
     3337    if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
     3338        fout = fopen("/tmp/out.txt", "w");
     3339        fput_string_one_char_at_a_time(stderr, argv[2]);
     3340        finish(0);
     3341    }
     3342
     3343    if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
     3344        make_grub_install_scriptlet(argv[2]);
     3345        finish(0);
     3346    }
     3347
     3348    if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
     3349        if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
     3350            system("mount " MNT_CDROM);
     3351        }
     3352        bkpinfo->compression_level = 1;
     3353        g_current_media_number = 2;
     3354        strcpy(bkpinfo->restore_path, "/tmp/TESTING");
     3355        bkpinfo->backup_media_type = dvd;
     3356        open_progress_form("Reassembling /dev/hda1",
     3357                           "Shark is a bit of a silly person.",
     3358                           "Please wait. This may take some time.",
     3359                           "", 1999);
     3360        system("rm -Rf /tmp/*pih*");
     3361
     3362        restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
     3363    }
     3364
     3365    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
     3366        g_loglevel = 6;
     3367        filelist = load_filelist(argv[2]);
     3368        if (!filelist) {
     3369            fatal_error("Failed to load filelist");
     3370        }
     3371        toggle_node_selection(filelist, FALSE);
     3372        toggle_all_root_dirs_on(filelist);
     3373        toggle_path_selection(filelist, "/usr/share", TRUE);
    33193374//      show_filelist(filelist);
    3320       save_filelist(filelist, "/tmp/out.txt");
     3375        save_filelist(filelist, "/tmp/out.txt");
    33213376//      finish(0);
    33223377//      toggle_path_selection (filelist, "/root/stuff", TRUE);
    3323       strcpy(a, argv[3]);
    3324       strcpy(b, argv[4]);
    3325 
    3326       res = save_filelist_entries_in_common(
    3327                 a, filelist, b, FALSE);
    3328       free_filelist(filelist);
    3329       printf("res = %d", res);
    3330       finish(0);
    3331     }
    3332 
    3333   if (argc == 3 && strcmp( argv[1], "--popuplist" ) == 0 )
    3334     {
    3335       popup_changelist_from_file( argv[2] );
    3336       paranoid_MR_finish(0);
    3337     }
    3338 
    3339    if (argc == 5 && strcmp( argv[1], "--copy" ) == 0 )
    3340     {
    3341           log_msg(1, "SCORE");
    3342       g_loglevel = 10;
    3343           if (strstr(argv[2], "save"))
    3344         {
    3345           log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
    3346           fin = fopen(argv[3], "r");
    3347           fout = fopen(argv[4], "w");
    3348           copy_from_src_to_dest(fin, fout, 'w');
    3349           fclose(fin);
    3350           fin = fopen(argv[3], "r");
    3351           copy_from_src_to_dest(fin, fout, 'w');
    3352           fclose(fout);
    3353           fclose(fin);
    3354         }
    3355       else if (strstr(argv[2], "restore"))
    3356         {
    3357           fout = fopen(argv[3], "w");
    3358           fin = fopen(argv[4], "r");
    3359           copy_from_src_to_dest(fout, fin, 'r');
    3360           fclose(fin);
    3361           fin = fopen(argv[4], "r");
    3362           copy_from_src_to_dest(fout, fin, 'r');
    3363           fclose(fout);
    3364           fclose(fin);
    3365         }
    3366       else
    3367         { fatal_error("Unknown additional param"); }
    3368       finish(0);
    3369     }
    3370 
    3371   if (argc == 3 && strcmp(argv[1], "--mdstat") == 0)
    3372     {
    3373       wait_until_software_raids_are_prepped(argv[2], 100);
    3374       finish(0);
    3375     }
    3376  
    3377   if (argc == 4 && strcmp(argv[1], "--mdconv") == 0)
    3378     {
    3379       finish(create_raidtab_from_mdstat(argv[2], argv[3]));
    3380     }
    3381 
    3382 
    3383   if ( argc == 2 && strcmp( argv[1],"--live-grub" ) == 0 )
    3384     {
    3385               retval = run_grub( FALSE, "/dev/hda" );
    3386           if ( retval )
    3387             {
    3388               log_to_screen("Failed to write Master Boot Record");
    3389             }
    3390       paranoid_MR_finish(0);
    3391    }
    3392   if (argc == 3 && strcmp( argv[1], "--paa" ) == 0 )
    3393     {
    3394       g_current_media_number = atoi(argv[2]);
    3395       pause_and_ask_for_cdr(5, NULL);
    3396       paranoid_MR_finish(0);
    3397     }
    3398   else if ( !bkpinfo->disaster_recovery )
    3399     { // live!
    3400       if (argc!=1)
    3401         {
    3402       popup_and_OK("Live mode doesn't support command-line parameters yet.");
    3403       paranoid_MR_finish(1);
    3404 //    return(1);
    3405     }
    3406       log_msg (1, "I am in normal, live mode.");
    3407       log_msg (2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
    3408       mount_boot_if_necessary();  /* for Gentoo users */
    3409       log_msg (2, "Still here.");
    3410       if ( argc>1 && strcmp( argv[argc-1], "--live-from-cd" ) == 0 )
    3411         { g_restoring_live_from_cd = TRUE; }
    3412       if ( argc == 5 && strcmp(argv[1], "--monitas-live" ) == 0 )
    3413         {
    3414       retval =
    3415         restore_live_from_monitas_server( bkpinfo,
    3416                           argv[2],
    3417                           argv[3],
    3418                           argv[4] );
    3419     }
    3420       else
    3421         {
    3422       log_msg(2, "Calling restore_to_live_filesystem()");
    3423       retval = restore_to_live_filesystem( bkpinfo );
    3424     }
    3425       log_msg(2, "Still here. Yay.");
    3426       if (strlen(bkpinfo->tmpdir) > 0)
    3427         {
    3428           sprintf( tmp, "rm -Rf %s/*", bkpinfo->tmpdir );
    3429           run_program_and_log_output ( tmp, FALSE );
    3430         }
    3431       unmount_boot_if_necessary(); /* for Gentoo users */
    3432       paranoid_MR_finish( retval );
    3433     }
    3434   else
    3435     {
     3378        strcpy(a, argv[3]);
     3379        strcpy(b, argv[4]);
     3380
     3381        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
     3382        free_filelist(filelist);
     3383        printf("res = %d", res);
     3384        finish(0);
     3385    }
     3386
     3387    if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
     3388        popup_changelist_from_file(argv[2]);
     3389        paranoid_MR_finish(0);
     3390    }
     3391
     3392    if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
     3393        log_msg(1, "SCORE");
     3394        g_loglevel = 10;
     3395        if (strstr(argv[2], "save")) {
     3396            log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
     3397            fin = fopen(argv[3], "r");
     3398            fout = fopen(argv[4], "w");
     3399            copy_from_src_to_dest(fin, fout, 'w');
     3400            fclose(fin);
     3401            fin = fopen(argv[3], "r");
     3402            copy_from_src_to_dest(fin, fout, 'w');
     3403            fclose(fout);
     3404            fclose(fin);
     3405        } else if (strstr(argv[2], "restore")) {
     3406            fout = fopen(argv[3], "w");
     3407            fin = fopen(argv[4], "r");
     3408            copy_from_src_to_dest(fout, fin, 'r');
     3409            fclose(fin);
     3410            fin = fopen(argv[4], "r");
     3411            copy_from_src_to_dest(fout, fin, 'r');
     3412            fclose(fout);
     3413            fclose(fin);
     3414        } else {
     3415            fatal_error("Unknown additional param");
     3416        }
     3417        finish(0);
     3418    }
     3419
     3420    if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
     3421        wait_until_software_raids_are_prepped(argv[2], 100);
     3422        finish(0);
     3423    }
     3424
     3425    if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) {
     3426        finish(create_raidtab_from_mdstat(argv[2], argv[3]));
     3427    }
     3428
     3429
     3430    if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
     3431        retval = run_grub(FALSE, "/dev/hda");
     3432        if (retval) {
     3433            log_to_screen("Failed to write Master Boot Record");
     3434        }
     3435        paranoid_MR_finish(0);
     3436    }
     3437    if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
     3438        g_current_media_number = atoi(argv[2]);
     3439        pause_and_ask_for_cdr(5, NULL);
     3440        paranoid_MR_finish(0);
     3441    } else if (!bkpinfo->disaster_recovery) {   // live!
     3442        if (argc != 1) {
     3443            popup_and_OK
     3444                ("Live mode doesn't support command-line parameters yet.");
     3445            paranoid_MR_finish(1);
     3446//    return(1);
     3447        }
     3448        log_msg(1, "I am in normal, live mode.");
     3449        log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
     3450        mount_boot_if_necessary();  /* for Gentoo users */
     3451        log_msg(2, "Still here.");
     3452        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
     3453            g_restoring_live_from_cd = TRUE;
     3454        }
     3455        if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
     3456            retval =
     3457                restore_live_from_monitas_server(bkpinfo,
     3458                                                 argv[2],
     3459                                                 argv[3], argv[4]);
     3460        } else {
     3461            log_msg(2, "Calling restore_to_live_filesystem()");
     3462            retval = restore_to_live_filesystem(bkpinfo);
     3463        }
     3464        log_msg(2, "Still here. Yay.");
     3465        if (strlen(bkpinfo->tmpdir) > 0) {
     3466            sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
     3467            run_program_and_log_output(tmp, FALSE);
     3468        }
     3469        unmount_boot_if_necessary();    /* for Gentoo users */
     3470        paranoid_MR_finish(retval);
     3471    } else {
    34363472/* Disaster recovery mode (must be) */
    3437       log_msg(1, "I must be in disaster recovery mode.");
    3438       log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname );
    3439       if (argc == 3 && strcmp(argv[1], "--monitas-memorex" ) == 0 )
    3440         {
    3441           log_to_screen( "Uh, that hasn't been implemented yet." );
    3442           paranoid_MR_finish( 1 );
    3443         }
    3444 
    3445       iamhere("About to call load_mountlist and load_raidtab");
    3446       strcpy( bkpinfo->restore_path, MNT_RESTORING );
    3447       read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo );
    3448       retval = load_mountlist( mountlist, g_mountlist_fname );
    3449       retval += load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3450       iamhere("Returned from calling load_mountlist and load_raidtab successfully");
    3451 
    3452       if (argc>1 && (strcmp( argv[1], "--compare" ) == 0 || strcmp( argv[1], "--nuke" ) == 0 ))
    3453         {
    3454           if (bkpinfo->backup_media_type == nfs && !is_this_device_mounted(bkpinfo->nfs_mount))
    3455             {
    3456           log_msg(1, "Mounting nfs dir");
    3457               sprintf(bkpinfo->isodir, "/tmp/isodir");
    3458           run_program_and_log_output("mkdir -p /tmp/isodir", 5);
    3459           sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount);
    3460           run_program_and_log_output(tmp, 1);
    3461            }
    3462         }
    3463 
    3464      
    3465       if ( retval )
    3466         {
    3467           log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" );
    3468         }
    3469    
    3470 
    3471       log_msg(1, "Send in the clowns.");
    3472 
    3473       if (argc == 2 && strcmp(argv[1], "--partition-only") == 0)
    3474         {
    3475       log_msg(0, "Partitioning only.");
    3476           load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3477           strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    3478       load_mountlist( mountlist, g_mountlist_fname );
    3479           res = partition_everything(mountlist);
    3480           finish(res);
    3481         }
    3482 
    3483       if (argc == 2 && strcmp(argv[1], "--format-only") == 0)
    3484         {
    3485       log_msg(0, "Formatting only.");
    3486           load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3487           strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    3488       load_mountlist( mountlist, g_mountlist_fname );
    3489           res = format_everything(mountlist, FALSE);
    3490           finish(res);
    3491         }
    3492 
    3493       if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0)
    3494         {
    3495       log_msg(0, "Stopping LVM and RAID");
    3496           load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME );
    3497           strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
    3498       load_mountlist( mountlist, g_mountlist_fname );
    3499           res = do_my_funky_lvm_stuff(TRUE, FALSE);
    3500       res += stop_all_raid_devices(mountlist);
    3501           finish(res);
    3502         }
    3503 
    3504       if (argc == 2 && strcmp( argv[1], "--nuke" ) == 0 )
    3505         {
    3506       iamhere("nuking");
    3507           retval += nuke_mode( bkpinfo, mountlist, raidlist);
    3508         }
    3509       else if (argc == 2 && strcmp( argv[1], "--interactive" ) == 0 )
    3510         {
    3511       iamhere("catchall");
    3512           retval += catchall_mode( bkpinfo, mountlist,raidlist );
    3513         }
    3514       else if (argc == 2 && strcmp( argv[1], "--compare" ) == 0 )
    3515         {
    3516       iamhere("compare");
    3517           retval += compare_mode( bkpinfo, mountlist, raidlist );
    3518         }
    3519       else if (argc == 2 && strcmp( argv[1], "--iso" ) == 0 )
    3520         {
    3521       iamhere("iso");
    3522       retval = iso_mode( bkpinfo, mountlist, raidlist, FALSE );
    3523         }
    3524       else if ( argc == 2 && strcmp( argv[1],"--mbr" ) == 0 )
    3525         {
    3526       iamhere("mbr");
    3527           retval = mount_all_devices( mountlist, TRUE );
    3528           if ( !retval )
    3529             {
    3530               retval += run_boot_loader( FALSE );
    3531               retval += unmount_all_devices( mountlist );
    3532             }
    3533           if ( retval )
    3534             {
    3535               log_to_screen("Failed to write Master Boot Record");
    3536             }
    3537         }
    3538       else if ( argc == 2 && strcmp( argv[1],"--isonuke") ==0 )
    3539         {
    3540       iamhere("isonuke");
    3541           retval = iso_mode( bkpinfo,
    3542              mountlist,
    3543              raidlist,
    3544              TRUE );
    3545         }
    3546       else if ( argc != 1 )
    3547         {
    3548           log_to_screen( "Invalid paremeters" );
    3549           paranoid_MR_finish( 1 );
    3550         }
    3551       else
    3552         {
    3553       iamhere("catchall (no mode specified in command-line call");
    3554           retval += catchall_mode( bkpinfo, mountlist, raidlist);
    3555         }
    3556     }
    3557 
    3558   /* clean up at the end */
    3559   if (retval)
    3560     {
    3561       if (does_file_exist("/tmp/changed.files"))
    3562     {
    3563           log_to_screen( "See /tmp/changed.files for list of files that have changed." );
    3564     }
    3565       mvaddstr_and_log_it ( g_currentY++,
    3566             0,
    3567             "Run complete. Errors were reported. Please review the logfile." );
    3568     }
    3569   else
    3570     {
    3571       if (IS_THIS_A_STREAMING_BACKUP ( bkpinfo->backup_media_type ) )
    3572         {
    3573       mvaddstr_and_log_it( g_currentY++,
    3574                    0,
    3575                    "Run complete. Please remove floppy/CD/media and reboot." );
    3576     }
    3577       else
    3578     {
    3579       run_program_and_log_output ( "sync", FALSE );
    3580       if ( is_this_device_mounted( MNT_CDROM ) )
    3581         {
    3582           res = run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    3583         }
    3584       else
    3585         {
    3586           res = 0;
    3587         }
    3588      
    3589           if ( !bkpinfo->please_dont_eject)
    3590             {
    3591               res = eject_device("/dev/cdrom");
     3473        log_msg(1, "I must be in disaster recovery mode.");
     3474        log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
     3475        if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
     3476            log_to_screen("Uh, that hasn't been implemented yet.");
     3477            paranoid_MR_finish(1);
     3478        }
     3479
     3480        iamhere("About to call load_mountlist and load_raidtab");
     3481        strcpy(bkpinfo->restore_path, MNT_RESTORING);
     3482        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     3483        retval = load_mountlist(mountlist, g_mountlist_fname);
     3484        retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3485        iamhere
     3486            ("Returned from calling load_mountlist and load_raidtab successfully");
     3487
     3488        if (argc > 1
     3489            && (strcmp(argv[1], "--compare") == 0
     3490                || strcmp(argv[1], "--nuke") == 0)) {
     3491            if (bkpinfo->backup_media_type == nfs
     3492                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
     3493                log_msg(1, "Mounting nfs dir");
     3494                sprintf(bkpinfo->isodir, "/tmp/isodir");
     3495                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
     3496                sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
     3497                        bkpinfo->nfs_mount);
     3498                run_program_and_log_output(tmp, 1);
     3499            }
     3500        }
     3501
     3502
     3503        if (retval) {
     3504            log_to_screen
     3505                ("Warning - load_raidtab_into_raidlist returned an error");
     3506        }
     3507
     3508
     3509        log_msg(1, "Send in the clowns.");
     3510
     3511        if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
     3512            log_msg(0, "Partitioning only.");
     3513            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3514            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3515            load_mountlist(mountlist, g_mountlist_fname);
     3516            res = partition_everything(mountlist);
     3517            finish(res);
     3518        }
     3519
     3520        if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
     3521            log_msg(0, "Formatting only.");
     3522            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3523            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3524            load_mountlist(mountlist, g_mountlist_fname);
     3525            res = format_everything(mountlist, FALSE);
     3526            finish(res);
     3527        }
     3528
     3529        if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
     3530            log_msg(0, "Stopping LVM and RAID");
     3531            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     3532            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     3533            load_mountlist(mountlist, g_mountlist_fname);
     3534            res = do_my_funky_lvm_stuff(TRUE, FALSE);
     3535            res += stop_all_raid_devices(mountlist);
     3536            finish(res);
     3537        }
     3538
     3539        if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
     3540            iamhere("nuking");
     3541            retval += nuke_mode(bkpinfo, mountlist, raidlist);
     3542        } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
     3543            iamhere("catchall");
     3544            retval += catchall_mode(bkpinfo, mountlist, raidlist);
     3545        } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
     3546            iamhere("compare");
     3547            retval += compare_mode(bkpinfo, mountlist, raidlist);
     3548        } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
     3549            iamhere("iso");
     3550            retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
     3551        } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
     3552            iamhere("mbr");
     3553            retval = mount_all_devices(mountlist, TRUE);
     3554            if (!retval) {
     3555                retval += run_boot_loader(FALSE);
     3556                retval += unmount_all_devices(mountlist);
     3557            }
     3558            if (retval) {
     3559                log_to_screen("Failed to write Master Boot Record");
     3560            }
     3561        } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
     3562            iamhere("isonuke");
     3563            retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
     3564        } else if (argc != 1) {
     3565            log_to_screen("Invalid paremeters");
     3566            paranoid_MR_finish(1);
     3567        } else {
     3568            iamhere("catchall (no mode specified in command-line call");
     3569            retval += catchall_mode(bkpinfo, mountlist, raidlist);
     3570        }
     3571    }
     3572
     3573    /* clean up at the end */
     3574    if (retval) {
     3575        if (does_file_exist("/tmp/changed.files")) {
     3576            log_to_screen
     3577                ("See /tmp/changed.files for list of files that have changed.");
     3578        }
     3579        mvaddstr_and_log_it(g_currentY++,
     3580                            0,
     3581                            "Run complete. Errors were reported. Please review the logfile.");
     3582    } else {
     3583        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     3584            mvaddstr_and_log_it(g_currentY++,
     3585                                0,
     3586                                "Run complete. Please remove floppy/CD/media and reboot.");
     3587        } else {
     3588            run_program_and_log_output("sync", FALSE);
     3589            if (is_this_device_mounted(MNT_CDROM)) {
     3590                res =
     3591                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     3592            } else {
     3593                res = 0;
     3594            }
     3595
     3596            if (!bkpinfo->please_dont_eject) {
     3597                res = eject_device("/dev/cdrom");
    35923598/*
    35933599              if (res)
     
    35963602        }
    35973603*/
    3598             }
    3599       mvaddstr_and_log_it( g_currentY++,
    3600                    0,
    3601                    "Run complete. Please remove media and reboot." );
    3602     }
    3603     }
     3604            }
     3605            mvaddstr_and_log_it(g_currentY++,
     3606                                0,
     3607                                "Run complete. Please remove media and reboot.");
     3608        }
     3609    }
    36043610
    36053611// g_I_have_just_nuked is set true by nuke_mode() just before it returns
    3606   if ( g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY"))
    3607     {
    3608       if (!system("which post-nuke > /dev/null 2> /dev/null"))
    3609         {
    3610           log_msg(1, "post-nuke found; running...");
    3611           if (mount_all_devices(mountlist, TRUE))
    3612             {
    3613               log_to_screen("Unable to re-mount partitions for post-nuke stuff");
    3614             }
    3615           else
    3616             {
    3617               log_msg(1, "Re-mounted partitions for post-nuke stuff");
    3618               sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
    3619               if (!g_text_mode) { newtSuspend(); }
    3620               log_msg(2, "Calling '%s'", tmp);
    3621               if ((res=system(tmp))) { log_OS_error(tmp); }
    3622               if (!g_text_mode) { newtResume(); }
     3612    if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
     3613        if (!system("which post-nuke > /dev/null 2> /dev/null")) {
     3614            log_msg(1, "post-nuke found; running...");
     3615            if (mount_all_devices(mountlist, TRUE)) {
     3616                log_to_screen
     3617                    ("Unable to re-mount partitions for post-nuke stuff");
     3618            } else {
     3619                log_msg(1, "Re-mounted partitions for post-nuke stuff");
     3620                sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
     3621                        retval);
     3622                if (!g_text_mode) {
     3623                    newtSuspend();
     3624                }
     3625                log_msg(2, "Calling '%s'", tmp);
     3626                if ((res = system(tmp))) {
     3627                    log_OS_error(tmp);
     3628                }
     3629                if (!g_text_mode) {
     3630                    newtResume();
     3631                }
    36233632//              newtCls();
    3624               log_msg(1, "post-nuke returned w/ res=%d", res);
    3625             }
    3626           unmount_all_devices(mountlist);
    3627           log_msg(1, "I've finished post-nuking.");
    3628         }
    3629     }
     3633                log_msg(1, "post-nuke returned w/ res=%d", res);
     3634            }
     3635            unmount_all_devices(mountlist);
     3636            log_msg(1, "I've finished post-nuking.");
     3637        }
     3638    }
    36303639/* 
    36313640  log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
     
    36333642  wait_until_software_raids_are_prepped("/proc/mdstat", 100);
    36343643  log_to_screen("Thank you.");
    3635 */
    3636   unlink( "/tmp/mondo-run-prog.tmp" );
    3637   set_signals( FALSE );
    3638   sprintf( tmp, "rm -Rf %s", bkpinfo->tmpdir );
    3639   run_program_and_log_output ( tmp, FALSE );
    3640   log_to_screen( "Restore log copied to /tmp/mondo-restore.log on your hard disk" );
    3641   sprintf( tmp, "Mondo-restore is exiting (retval=%d)                                      ",retval);
    3642   log_to_screen( tmp );
    3643   sprintf(tmp, "umount %s", bkpinfo->isodir);
    3644   run_program_and_log_output(tmp, 5);
    3645   paranoid_free(mountlist);
    3646   paranoid_free(raidlist);
    3647   if (am_I_in_disaster_recovery_mode())
    3648     { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros
    3649   paranoid_MR_finish( retval ); // frees global stuff plus bkpinfo
    3650   free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3651   paranoid_free(a);
    3652   paranoid_free(b);
    3653   paranoid_free(tmp);
    3654  
    3655   unlink("/tmp/filelist.full");
    3656   unlink("/tmp/filelist.full.gz");
    3657 
    3658   exit( retval );
     3644*/
     3645    unlink("/tmp/mondo-run-prog.tmp");
     3646    set_signals(FALSE);
     3647    sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
     3648    run_program_and_log_output(tmp, FALSE);
     3649    log_to_screen
     3650        ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
     3651    sprintf(tmp,
     3652            "Mondo-restore is exiting (retval=%d)                                      ",
     3653            retval);
     3654    log_to_screen(tmp);
     3655    sprintf(tmp, "umount %s", bkpinfo->isodir);
     3656    run_program_and_log_output(tmp, 5);
     3657    paranoid_free(mountlist);
     3658    paranoid_free(raidlist);
     3659    if (am_I_in_disaster_recovery_mode()) {
     3660        run_program_and_log_output("mount / -o remount,rw", 2);
     3661    }                           // for b0rken distros
     3662    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
     3663    free_libmondo_global_strings(); // it's fine to have this here :) really :)
     3664    paranoid_free(a);
     3665    paranoid_free(b);
     3666    paranoid_free(tmp);
     3667
     3668    unlink("/tmp/filelist.full");
     3669    unlink("/tmp/filelist.full.gz");
     3670
     3671    exit(retval);
    36593672}
    36603673
     
    36703683 *END_MONDO-RESTORE.C                                                     *
    36713684 **************************************************************************/
    3672 
  • branches/2.05/mondo/mondo/mondorestore/mondo-restore.h

    r30 r128  
    11/* mondo-restore.h
    2  * $Id: mondo-restore.h,v 1.3 2004/06/21 20:20:37 hugo Exp $
     2 * $Id$
    33 */
    44
     
    77 **************************************************************************/
    88
    9 void ask_about_these_imagedevs(char*,char*);
    10 int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*);
    11 void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*);
    12 int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    13 int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    14 int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    15 int iso_mode(struct s_bkpinfo *bkpinfo,
    16      struct mountlist_itself *mountlist,
    17      struct raidlist_itself *raidlist,
    18      bool nuke_me_please);
    19 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *);
    20 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*, char*);
    21 int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*, int, char*);
    22 int restore_a_tarball_from_CD(char *, long, struct s_node*);
    23 int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, long, struct s_node*, long long, char*, char*);
    24 int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*);
    25 int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*);
    26 int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*);
    27 int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*);
    28 int restore_everything(struct s_bkpinfo*,struct s_node*);
    29 int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*);
    30 int restore_to_live_filesystem(struct s_bkpinfo*);
    31 void swap_mountlist_entries(struct mountlist_itself*,int,int);
    32 void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool);
    33 void sort_mountlist_by_device(struct mountlist_itself*);
    34 int what_number_cd_is_this(struct s_bkpinfo*);
     9void ask_about_these_imagedevs(char *, char *);
     10int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *,
     11                  struct raidlist_itself *);
     12void find_pathname_of_executable_preferably_in_RESTORING(char *, char *,
     13                                                         char *);
     14int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *,
     15                     struct raidlist_itself *);
     16int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *,
     17              struct raidlist_itself *);
     18int compare_mode(struct s_bkpinfo *, struct mountlist_itself *,
     19                 struct raidlist_itself *);
     20int iso_mode(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist,
     21             struct raidlist_itself *raidlist, bool nuke_me_please);
     22int restore_mode(struct s_bkpinfo *, struct mountlist_itself *,
     23                 struct raidlist_itself *);
     24int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node *,
     25                                 char *);
     26int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long,
     27                                     char *, long long, struct s_node *,
     28                                     int, char *);
     29int restore_a_tarball_from_CD(char *, long, struct s_node *);
     30int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, long,
     31                                  struct s_node *, long long, char *,
     32                                  char *);
     33int restore_all_biggiefiles_from_CD(struct s_bkpinfo *, struct s_node *);
     34int restore_all_biggiefiles_from_stream(struct s_bkpinfo *,
     35                                        struct s_node *);
     36int restore_all_tarballs_from_CD(struct s_bkpinfo *, struct s_node *);
     37int restore_all_tarballs_from_stream(struct s_bkpinfo *, struct s_node *);
     38int restore_everything(struct s_bkpinfo *, struct s_node *);
     39int restore_live_from_monitas_server(struct s_bkpinfo *, char *, char *,
     40                                     char *);
     41int restore_to_live_filesystem(struct s_bkpinfo *);
     42void swap_mountlist_entries(struct mountlist_itself *, int, int);
     43void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool);
     44void sort_mountlist_by_device(struct mountlist_itself *);
     45int what_number_cd_is_this(struct s_bkpinfo *);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-compare-EXT.h

    r30 r128  
    22
    33
    4 extern int compare_to_CD(struct s_bkpinfo*);
    5 extern int compare_to_cdstream(struct s_bkpinfo*);
    6 extern int compare_to_tape(struct s_bkpinfo*);
    7 extern int compare_mode( struct s_bkpinfo *bkpinfo ,
    8           struct mountlist_itself *mountlist,
    9           struct raidlist_itself *raidlist);
     4extern int compare_to_CD(struct s_bkpinfo *);
     5extern int compare_to_cdstream(struct s_bkpinfo *);
     6extern int compare_to_tape(struct s_bkpinfo *);
     7extern int compare_mode(struct s_bkpinfo *bkpinfo,
     8                        struct mountlist_itself *mountlist,
     9                        struct raidlist_itself *raidlist);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-compare.c

    r30 r128  
    55    copyright            : (C) 2000 by Hugo Rabson
    66    email                : Hugo Rabson <hugorabson@msn.com>
    7     cvsid                : $Id: mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp $
     7    cvsid                : $Id$
    88***************************************************************************/
    99
     
    6565#include "mondo-rstr-tools-EXT.h"
    6666
    67 //static char cvsid[] = "$Id: mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp $";
    68 
    69 void popup_changelist_from_file(char*);
     67//static char cvsid[] = "$Id$";
     68
     69void popup_changelist_from_file(char *);
    7070
    7171
     
    8080 * @note This function uses an MD5 checksum.
    8181 */
    82 int
    83 compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno)
     82int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno)
    8483{
    8584
    86   FILE *fin;
    87   FILE *fout;
     85    FILE *fin;
     86    FILE *fout;
    8887
    8988  /** needs malloc *******/
    90   char *checksum_ptr;
    91   char *original_cksum_ptr;
    92   char *bigfile_fname_ptr;
    93   char *tmp_ptr;
    94   char *command_ptr;
    95 
    96   char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
    97  
    98   char *p;
    99   int i;
    100   int retval = 0;
    101 
    102   struct s_filename_and_lstat_info biggiestruct;
    103  
    104   malloc_string(checksum);
    105   malloc_string(original_cksum);
    106   malloc_string(bigfile_fname);
    107   malloc_string(tmp);
    108   malloc_string(command);
    109   malloc_string(checksum_ptr);
    110   malloc_string(original_cksum_ptr);
    111   malloc_string(bigfile_fname_ptr);
    112   malloc_string(command_ptr);
    113   malloc_string(tmp_ptr);
    114  
     89    char *checksum_ptr;
     90    char *original_cksum_ptr;
     91    char *bigfile_fname_ptr;
     92    char *tmp_ptr;
     93    char *command_ptr;
     94
     95    char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
     96
     97    char *p;
     98    int i;
     99    int retval = 0;
     100
     101    struct s_filename_and_lstat_info biggiestruct;
     102
     103    malloc_string(checksum);
     104    malloc_string(original_cksum);
     105    malloc_string(bigfile_fname);
     106    malloc_string(tmp);
     107    malloc_string(command);
     108    malloc_string(checksum_ptr);
     109    malloc_string(original_cksum_ptr);
     110    malloc_string(bigfile_fname_ptr);
     111    malloc_string(command_ptr);
     112    malloc_string(tmp_ptr);
     113
    115114  /*********************************************************************
    116115   * allocate memory clear test                sab 16 feb 2003         *
    117116   *********************************************************************/
    118   assert(bkpinfo!=NULL);
    119   memset( checksum_ptr, '\0', sizeof(checksum));
    120   memset ( original_cksum_ptr, '\0', sizeof(original_cksum));
    121   memset (bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    122   memset (tmp_ptr, '\0', sizeof(tmp));
    123   memset ( command_ptr, '\0', sizeof( command ) );
     117    assert(bkpinfo != NULL);
     118    memset(checksum_ptr, '\0', sizeof(checksum));
     119    memset(original_cksum_ptr, '\0', sizeof(original_cksum));
     120    memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
     121    memset(tmp_ptr, '\0', sizeof(tmp));
     122    memset(command_ptr, '\0', sizeof(command));
    124123  /** end **/
    125124
    126   if ( !does_file_exist( slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) )
    127     {
    128       if ( does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) )
    129     {
    130           insist_on_this_cd_number(bkpinfo, ( ++g_current_media_number ) );
    131         }
    132       else
    133     {
    134       sprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob." );
    135       log_msg(2,  tmp_ptr );
    136       return( 0 );
    137         }
    138     }
    139   if ( !( fin = fopen(slice_fname( bigfileno, 0, ARCHIVES_PATH, "" ), "r" ) ) )
    140     {
    141       sprintf( tmp_ptr,
    142            "Cannot open bigfile %ld (%s)'s info file",
    143            bigfileno + 1, bigfile_fname_ptr);
    144       log_to_screen( tmp_ptr );
    145       return( 1 );
    146     }
    147   fread( ( void* )&biggiestruct, 1, sizeof( biggiestruct ), fin);
    148   paranoid_fclose( fin );
    149  
    150   strcpy( checksum_ptr, biggiestruct.checksum );
    151   strcpy( bigfile_fname_ptr, biggiestruct.filename );
    152  
    153   log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename );
    154   log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum );
    155  
    156   sprintf( tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    157  
    158   if (!g_text_mode)
    159     {
    160       newtDrawRootText( 0, 22, tmp_ptr);
    161       newtRefresh();
    162     }
    163   if ( !checksum[0] ) {
    164     log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr );
    165   }
    166   if ( !strncmp( bigfile_fname_ptr, "/dev/", 5 ) )
    167     {
    168       strcpy( original_cksum_ptr, "IGNORE" );
    169     }
    170   else
    171     {
    172       sprintf( command_ptr,
    173            "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
    174            MNT_RESTORING, bigfile_fname_ptr);
    175     }
    176   log_msg(2, command_ptr );
    177   paranoid_system( "cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null" );
    178   if ( system( command_ptr ) )
    179     {
    180       log_OS_error( "Warning - command failed" );
    181       original_cksum[0] = '\0';
    182       return( 1 );
    183     }
    184   else
    185     {
    186       if ( !(fin = fopen( "/tmp/md5sum.txt", "r" ) ) )
    187     {
    188       log_msg(2,  "Unable to open /tmp/md5sum.txt; can't get live checksum" );
    189       original_cksum[0] = '\0';
    190       return( 1 );
    191     }
    192       else
    193     {
    194       fgets( original_cksum_ptr, MAX_STR_LEN - 1, fin );
    195       paranoid_fclose( fin );
    196       for(i = strlen( original_cksum_ptr ); i > 0 && original_cksum[i-1] < 32; i-- );
    197       original_cksum[i] = '\0';
    198       p = ( char* ) strchr( original_cksum_ptr, ' ' );
    199       if ( p )
    200         {
    201           *p = '\0';
    202         }
    203     }
    204     }
    205   sprintf( tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);
    206   if ( !strcmp(checksum_ptr, original_cksum_ptr ) != 0 )
    207     {
    208       strcat( tmp_ptr," ... OK");
    209     }
    210   else
    211     {
    212       strcat( tmp_ptr, "... changed" );
    213       retval++;
    214     }
    215   log_msg(1, tmp_ptr );
    216   if ( retval )
    217     {
    218       if ( !( fout = fopen("/tmp/changed.txt", "a") ) )
    219     {
    220       fatal_error( "Cannot openout changed.txt");
    221     }
    222       fprintf( fout, "%s\n", bigfile_fname_ptr );
    223       paranoid_fclose( fout );
    224     }
    225 
    226   paranoid_free (original_cksum_ptr);
    227   paranoid_free (original_cksum);
    228   paranoid_free (bigfile_fname_ptr);
    229   paranoid_free (bigfile_fname);
    230   paranoid_free (checksum_ptr);
    231   paranoid_free (checksum);
    232   paranoid_free (command_ptr);
    233   paranoid_free (command);
    234   paranoid_free (tmp_ptr);
    235   paranoid_free (tmp);
    236 
    237   return( retval );
     125    if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
     126        if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
     127            insist_on_this_cd_number(bkpinfo, (++g_current_media_number));
     128        } else {
     129            sprintf(tmp_ptr,
     130                    "No CD's left. No biggiefiles left. No prob, Bob.");
     131            log_msg(2, tmp_ptr);
     132            return (0);
     133        }
     134    }
     135    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
     136        sprintf(tmp_ptr,
     137                "Cannot open bigfile %ld (%s)'s info file",
     138                bigfileno + 1, bigfile_fname_ptr);
     139        log_to_screen(tmp_ptr);
     140        return (1);
     141    }
     142    fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
     143    paranoid_fclose(fin);
     144
     145    strcpy(checksum_ptr, biggiestruct.checksum);
     146    strcpy(bigfile_fname_ptr, biggiestruct.filename);
     147
     148    log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
     149    log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
     150
     151    sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
     152
     153    if (!g_text_mode) {
     154        newtDrawRootText(0, 22, tmp_ptr);
     155        newtRefresh();
     156    }
     157    if (!checksum[0]) {
     158        log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
     159    }
     160    if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
     161        strcpy(original_cksum_ptr, "IGNORE");
     162    } else {
     163        sprintf(command_ptr,
     164                "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
     165                MNT_RESTORING, bigfile_fname_ptr);
     166    }
     167    log_msg(2, command_ptr);
     168    paranoid_system
     169        ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null");
     170    if (system(command_ptr)) {
     171        log_OS_error("Warning - command failed");
     172        original_cksum[0] = '\0';
     173        return (1);
     174    } else {
     175        if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
     176            log_msg(2,
     177                    "Unable to open /tmp/md5sum.txt; can't get live checksum");
     178            original_cksum[0] = '\0';
     179            return (1);
     180        } else {
     181            fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);
     182            paranoid_fclose(fin);
     183            for (i = strlen(original_cksum_ptr);
     184                 i > 0 && original_cksum[i - 1] < 32; i--);
     185            original_cksum[i] = '\0';
     186            p = (char *) strchr(original_cksum_ptr, ' ');
     187            if (p) {
     188                *p = '\0';
     189            }
     190        }
     191    }
     192    sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
     193            bigfile_fname_ptr);
     194    if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
     195        strcat(tmp_ptr, " ... OK");
     196    } else {
     197        strcat(tmp_ptr, "... changed");
     198        retval++;
     199    }
     200    log_msg(1, tmp_ptr);
     201    if (retval) {
     202        if (!(fout = fopen("/tmp/changed.txt", "a"))) {
     203            fatal_error("Cannot openout changed.txt");
     204        }
     205        fprintf(fout, "%s\n", bigfile_fname_ptr);
     206        paranoid_fclose(fout);
     207    }
     208
     209    paranoid_free(original_cksum_ptr);
     210    paranoid_free(original_cksum);
     211    paranoid_free(bigfile_fname_ptr);
     212    paranoid_free(bigfile_fname);
     213    paranoid_free(checksum_ptr);
     214    paranoid_free(checksum);
     215    paranoid_free(command_ptr);
     216    paranoid_free(command);
     217    paranoid_free(tmp_ptr);
     218    paranoid_free(tmp);
     219
     220    return (retval);
    238221}
    239222
     
    248231 * @return 0 for success, nonzero for failure.
    249232 */
    250 int
    251 compare_all_biggiefiles(struct s_bkpinfo*bkpinfo)
     233int compare_all_biggiefiles(struct s_bkpinfo *bkpinfo)
    252234{
    253   int retval = 0;
    254   int res;
    255   long noof_biggiefiles,bigfileno = 0;
    256   char tmp[MAX_STR_LEN];
    257 
    258   assert(bkpinfo!=NULL);
    259   log_msg(1, "Comparing biggiefiles" );
    260  
    261   if ( length_of_file(BIGGIELIST) < 6 )
    262     {
    263       log_msg(1, "OK, really teeny-tiny biggielist; not comparing biggiefiles" );
    264       return( 0 );
    265     }
    266   noof_biggiefiles = count_lines_in_file(BIGGIELIST);
    267   if (noof_biggiefiles <= 0 )
    268     {
    269       log_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
    270       return( 0 );
    271     }
    272   mvaddstr_and_log_it( g_currentY, 0, "Comparing large files                                                  ");
    273   open_progress_form("Comparing large files", "I am now comparing the large files" , "against the filesystem. Please wait.",
    274              "",
    275              noof_biggiefiles );
    276   for( bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++ )
    277     {
    278       sprintf( tmp, "Comparing big file #%ld", bigfileno + 1 );
    279       log_msg(1, tmp );
    280       update_progress_form( tmp );
    281       res = compare_a_biggiefile( bkpinfo, bigfileno );
    282       retval += res;
    283       g_current_progress++;
    284     }
    285   close_progress_form();
    286   return( 0 );
    287   if ( retval )
    288     {
    289       mvaddstr_and_log_it( g_currentY++, 74, "Errors." );
    290     }
    291   else
    292     {
    293       mvaddstr_and_log_it( g_currentY++,74, "Done." );
    294     }
    295   return( retval );
     235    int retval = 0;
     236    int res;
     237    long noof_biggiefiles, bigfileno = 0;
     238    char tmp[MAX_STR_LEN];
     239
     240    assert(bkpinfo != NULL);
     241    log_msg(1, "Comparing biggiefiles");
     242
     243    if (length_of_file(BIGGIELIST) < 6) {
     244        log_msg(1,
     245                "OK, really teeny-tiny biggielist; not comparing biggiefiles");
     246        return (0);
     247    }
     248    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
     249    if (noof_biggiefiles <= 0) {
     250        log_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
     251        return (0);
     252    }
     253    mvaddstr_and_log_it(g_currentY, 0,
     254                        "Comparing large files                                                  ");
     255    open_progress_form("Comparing large files",
     256                       "I am now comparing the large files",
     257                       "against the filesystem. Please wait.", "",
     258                       noof_biggiefiles);
     259    for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
     260        sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
     261        log_msg(1, tmp);
     262        update_progress_form(tmp);
     263        res = compare_a_biggiefile(bkpinfo, bigfileno);
     264        retval += res;
     265        g_current_progress++;
     266    }
     267    close_progress_form();
     268    return (0);
     269    if (retval) {
     270        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     271    } else {
     272        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     273    }
     274    return (retval);
    296275}
     276
    297277/**************************************************************************
    298278 *END_COMPARE_ALL_BIGGIEFILES                                             *
     
    308288 * @return 0 for success, nonzero for failure.
    309289 */
    310 int
    311 compare_a_tarball( char *tarball_fname, int current_tarball_number )
     290int compare_a_tarball(char *tarball_fname, int current_tarball_number)
    312291{
    313   int retval = 0;
    314   int res;
    315   long noof_lines;
    316   long archiver_errors;
    317   bool use_star;
    318  
     292    int retval = 0;
     293    int res;
     294    long noof_lines;
     295    long archiver_errors;
     296    bool use_star;
     297
    319298  /***  needs malloc *********/
    320   char *command, *tmp, *filelist_name, *logfile, *archiver_exe, *compressor_exe;
    321 
    322   malloc_string(command);
    323   malloc_string(tmp);
    324   malloc_string(filelist_name);
    325   malloc_string(logfile);
    326   malloc_string(archiver_exe);
    327   malloc_string(compressor_exe);
    328  
    329   use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;
    330   assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    331   sprintf( logfile, "/tmp/afio.log.%d", current_tarball_number );
    332   sprintf( filelist_name, MNT_CDROM"/archives/filelist.%d", current_tarball_number );
    333 
    334   noof_lines = count_lines_in_file( filelist_name );
    335 
    336   if ( strstr( tarball_fname, ".bz2") )
    337     {
    338       strcpy( compressor_exe, "bzip2");
    339     }
    340   else if ( strstr (tarball_fname, ".lzo") )
    341     {
    342       strcpy( compressor_exe, "lzop" );
    343     }
    344   else
    345     {
    346       compressor_exe[0] = '\0';
    347     }
    348  
    349   if (use_star)
    350     { strcpy(archiver_exe, "star"); }
    351   else
    352     { strcpy(archiver_exe, "afio"); }
    353  
    354   if (compressor_exe[0])
    355     {
    356       strcpy(tmp, compressor_exe);
    357       if (!find_home_of_exe(tmp))
    358         { fatal_error("(compare_a_tarball) Compression program missing"); }
    359       if (use_star) // star
    360         {
    361       if (!strcmp(compressor_exe, "bzip2"))
    362         { strcat(archiver_exe, " -bz"); }
    363       else { fatal_error("(compare_a_tarball) Please use only bzip2 with star"); }
    364     }
    365       else      // afio
    366         {
    367       sprintf(compressor_exe, "-P %s -Z", tmp);
    368     }
    369     }
     299    char *command, *tmp, *filelist_name, *logfile, *archiver_exe,
     300        *compressor_exe;
     301
     302    malloc_string(command);
     303    malloc_string(tmp);
     304    malloc_string(filelist_name);
     305    malloc_string(logfile);
     306    malloc_string(archiver_exe);
     307    malloc_string(compressor_exe);
     308
     309    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
     310    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     311    sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
     312    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d",
     313            current_tarball_number);
     314
     315    noof_lines = count_lines_in_file(filelist_name);
     316
     317    if (strstr(tarball_fname, ".bz2")) {
     318        strcpy(compressor_exe, "bzip2");
     319    } else if (strstr(tarball_fname, ".lzo")) {
     320        strcpy(compressor_exe, "lzop");
     321    } else {
     322        compressor_exe[0] = '\0';
     323    }
     324
     325    if (use_star) {
     326        strcpy(archiver_exe, "star");
     327    } else {
     328        strcpy(archiver_exe, "afio");
     329    }
     330
     331    if (compressor_exe[0]) {
     332        strcpy(tmp, compressor_exe);
     333        if (!find_home_of_exe(tmp)) {
     334            fatal_error("(compare_a_tarball) Compression program missing");
     335        }
     336        if (use_star)           // star
     337        {
     338            if (!strcmp(compressor_exe, "bzip2")) {
     339                strcat(archiver_exe, " -bz");
     340            } else {
     341                fatal_error
     342                    ("(compare_a_tarball) Please use only bzip2 with star");
     343            }
     344        } else                  // afio
     345        {
     346            sprintf(compressor_exe, "-P %s -Z", tmp);
     347        }
     348    }
    370349// star -diff H=star -bz file=....
    371350
     
    375354#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
    376355#endif
    377   if (use_star) // doesn't use compressor_exe
    378     {
    379       sprintf( command,
    380           "%s -diff H=star file=%s >> %s 2>> %s",
    381       archiver_exe, tarball_fname, logfile, logfile);
    382     }
    383   else
    384     {
    385       sprintf( command,
    386        "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
    387        archiver_exe,
    388        TAPE_BLOCK_SIZE,
    389        BUFSIZE,
    390        compressor_exe, tarball_fname,
    391        logfile,
    392        logfile);
    393     }
     356    if (use_star)               // doesn't use compressor_exe
     357    {
     358        sprintf(command,
     359                "%s -diff H=star file=%s >> %s 2>> %s",
     360                archiver_exe, tarball_fname, logfile, logfile);
     361    } else {
     362        sprintf(command,
     363                "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
     364                archiver_exe,
     365                TAPE_BLOCK_SIZE,
     366                BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
     367    }
    394368#undef BUFSIZE
    395369
    396   res = system( command );
    397   retval += res;
    398   if ( res )
    399     {
    400       log_OS_error( command );
    401       sprintf( tmp, "Warning - afio returned error = %d", res );
    402     }
    403   if (length_of_file(logfile)>5)
    404     {
    405       sprintf(command,
    406       "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt",
    407       logfile);
    408       system(command);
    409       archiver_errors = count_lines_in_file( logfile );
    410     }
    411   else
    412     {
    413       archiver_errors = 0;
    414     }
    415   sprintf(tmp, "%ld difference%c in fileset #%d          ",
    416       archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number);
    417   if (archiver_errors)
    418     {
    419       sprintf(tmp,
    420           "Differences found while processing fileset #%d       ",
    421           current_tarball_number);
    422       log_msg(1, tmp );
    423     }
    424   unlink( logfile );
    425   paranoid_free(command);
    426   paranoid_free(tmp);
    427   paranoid_free(filelist_name);
    428   paranoid_free(logfile);
    429   malloc_string(archiver_exe);
    430   malloc_string(compressor_exe);
    431   return( retval );
     370    res = system(command);
     371    retval += res;
     372    if (res) {
     373        log_OS_error(command);
     374        sprintf(tmp, "Warning - afio returned error = %d", res);
     375    }
     376    if (length_of_file(logfile) > 5) {
     377        sprintf(command,
     378                "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt",
     379                logfile);
     380        system(command);
     381        archiver_errors = count_lines_in_file(logfile);
     382    } else {
     383        archiver_errors = 0;
     384    }
     385    sprintf(tmp, "%ld difference%c in fileset #%d          ",
     386            archiver_errors, (archiver_errors != 1) ? 's' : ' ',
     387            current_tarball_number);
     388    if (archiver_errors) {
     389        sprintf(tmp,
     390                "Differences found while processing fileset #%d       ",
     391                current_tarball_number);
     392        log_msg(1, tmp);
     393    }
     394    unlink(logfile);
     395    paranoid_free(command);
     396    paranoid_free(tmp);
     397    paranoid_free(filelist_name);
     398    paranoid_free(logfile);
     399    malloc_string(archiver_exe);
     400    malloc_string(compressor_exe);
     401    return (retval);
    432402}
     403
    433404/**************************************************************************
    434405 *END_COMPARE_A_TARBALL                                                   *
     
    441412 * @return 0 for success, nonzero for failure.
    442413 */
    443 int
    444 compare_all_tarballs( struct s_bkpinfo *bkpinfo )
     414int compare_all_tarballs(struct s_bkpinfo *bkpinfo)
    445415{
    446   int retval = 0;
    447   int res;
    448   int current_tarball_number = 0;
     416    int retval = 0;
     417    int res;
     418    int current_tarball_number = 0;
    449419
    450420  /**  needs malloc **********/
    451  
    452   char *tarball_fname, *progress_str, *tmp;
    453   long max_val;
    454  
    455   malloc_string(tarball_fname);
    456   malloc_string(progress_str);
    457   malloc_string(tmp);
    458  
    459   assert(bkpinfo!=NULL);
    460   mvaddstr_and_log_it( g_currentY,0, "Comparing archives" );
    461   read_cfg_var( g_mondo_cfg_file, "last-filelist-number", tmp );
    462  
    463   max_val = atol( tmp );
    464   sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number );
    465 
    466   open_progress_form("Comparing files",
    467              "Comparing tarballs against filesystem.",
    468              "Please wait. This may take some time.",
    469              progress_str,
    470              max_val);
    471 
    472   log_to_screen( progress_str );
    473  
    474   for( ;; )
    475     {
    476       insist_on_this_cd_number( bkpinfo, g_current_media_number );
    477       update_progress_form( progress_str );
    478       sprintf( tarball_fname,
    479            MNT_CDROM"/archives/%d.afio.bz2",
    480            current_tarball_number);
    481      
    482       if ( !does_file_exist( tarball_fname ) )
    483     {
    484       sprintf( tarball_fname, MNT_CDROM"/archives/%d.afio.lzo", current_tarball_number );
    485     }
    486       if (!does_file_exist ( tarball_fname ) )
    487     {
    488       sprintf(tarball_fname, MNT_CDROM"/archives/%d.afio.",
    489           current_tarball_number);
    490     }
    491       if (!does_file_exist ( tarball_fname ) )
    492     {
    493       sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.bz2",
    494           current_tarball_number);
    495     }
    496       if (!does_file_exist ( tarball_fname ) )
    497     {
    498       sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.",
    499           current_tarball_number);
    500     }
    501       if ( !does_file_exist( tarball_fname ) )
    502     {
    503       if ( !does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) ||
    504            system( "find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null" )
    505            == 0 )
    506         {
    507           log_msg(2, "OK, I think I'm done with tarballs..." );
    508           break;
    509         }
    510       log_msg(2, "OK, I think it's time for another CD..." );
    511       g_current_media_number++;
    512       sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number );
    513       log_to_screen( progress_str );
    514     }
    515       else
    516     {
    517       res =
    518         compare_a_tarball( tarball_fname, current_tarball_number );
    519      
    520       g_current_progress++;
    521       current_tarball_number++;
    522     }
    523     }
    524   close_progress_form();
    525   if ( retval )
    526     {
    527       mvaddstr_and_log_it( g_currentY++,74, "Errors." );
    528     }
    529   else
    530     {
    531       mvaddstr_and_log_it( g_currentY++,
    532                74,
    533                "Done.");
    534     }
    535   paranoid_free(tarball_fname);
    536   paranoid_free(progress_str);
    537   paranoid_free(tmp);
    538   return(retval);
     421
     422    char *tarball_fname, *progress_str, *tmp;
     423    long max_val;
     424
     425    malloc_string(tarball_fname);
     426    malloc_string(progress_str);
     427    malloc_string(tmp);
     428
     429    assert(bkpinfo != NULL);
     430    mvaddstr_and_log_it(g_currentY, 0, "Comparing archives");
     431    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
     432
     433    max_val = atol(tmp);
     434    sprintf(progress_str, "Comparing with %s #%d ",
     435            media_descriptor_string(bkpinfo->backup_media_type),
     436            g_current_media_number);
     437
     438    open_progress_form("Comparing files",
     439                       "Comparing tarballs against filesystem.",
     440                       "Please wait. This may take some time.",
     441                       progress_str, max_val);
     442
     443    log_to_screen(progress_str);
     444
     445    for (;;) {
     446        insist_on_this_cd_number(bkpinfo, g_current_media_number);
     447        update_progress_form(progress_str);
     448        sprintf(tarball_fname,
     449                MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
     450
     451        if (!does_file_exist(tarball_fname)) {
     452            sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
     453                    current_tarball_number);
     454        }
     455        if (!does_file_exist(tarball_fname)) {
     456            sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",
     457                    current_tarball_number);
     458        }
     459        if (!does_file_exist(tarball_fname)) {
     460            sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
     461                    current_tarball_number);
     462        }
     463        if (!does_file_exist(tarball_fname)) {
     464            sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",
     465                    current_tarball_number);
     466        }
     467        if (!does_file_exist(tarball_fname)) {
     468            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") ||
     469                system("find " MNT_CDROM
     470                       "/archives/slice* > /dev/null 2> /dev/null")
     471                == 0) {
     472                log_msg(2, "OK, I think I'm done with tarballs...");
     473                break;
     474            }
     475            log_msg(2, "OK, I think it's time for another CD...");
     476            g_current_media_number++;
     477            sprintf(progress_str, "Comparing with %s #%d ",
     478                    media_descriptor_string(bkpinfo->backup_media_type),
     479                    g_current_media_number);
     480            log_to_screen(progress_str);
     481        } else {
     482            res = compare_a_tarball(tarball_fname, current_tarball_number);
     483
     484            g_current_progress++;
     485            current_tarball_number++;
     486        }
     487    }
     488    close_progress_form();
     489    if (retval) {
     490        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
     491    } else {
     492        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     493    }
     494    paranoid_free(tarball_fname);
     495    paranoid_free(progress_str);
     496    paranoid_free(tmp);
     497    return (retval);
    539498}
     499
    540500/**************************************************************************
    541501 *END_COMPARE_ALL_TARBALLS                                                *
     
    554514 * @return 0 for success, nonzero for failure.
    555515 */
    556 int
    557 compare_to_CD( struct s_bkpinfo *bkpinfo )
     516int compare_to_CD(struct s_bkpinfo *bkpinfo)
    558517{
    559518  /** needs malloc *********/
    560   char *tmp, *cwd, *new, *command;
    561   int resA = 0;
    562   int resB = 0;
    563   long noof_changed_files;
    564  
    565   malloc_string(tmp);
    566   malloc_string(cwd);
    567   malloc_string(new);
    568   malloc_string(command);
    569  
    570   assert(bkpinfo!=NULL);
    571 
    572   getcwd( cwd, MAX_STR_LEN - 1 );
    573   chdir( bkpinfo->restore_path );
    574   getcwd( new, MAX_STR_LEN - 1 );
    575   sprintf( tmp, "new path is %s", new );
    576   insist_on_this_cd_number( bkpinfo, g_current_media_number );
    577   unlink( "/tmp/changed.txt" );
    578  
    579   resA = compare_all_tarballs( bkpinfo );
    580   resB = compare_all_biggiefiles( bkpinfo );
    581   chdir( cwd );
    582   noof_changed_files = count_lines_in_file( "/tmp/changed.txt" );
    583   if ( noof_changed_files )
    584     {
    585       sprintf( tmp, "%ld files do not match the backup            ",
    586            noof_changed_files );
    587       //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
    588       log_to_screen (tmp);
    589       sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE );
    590       paranoid_system( command );
    591     }
    592   else
    593     {
    594       sprintf( tmp, "All files match the backup                     ");
    595       mvaddstr_and_log_it( g_currentY++, 0, tmp );
    596       log_to_screen( tmp );
    597     }
    598  
    599   paranoid_free(tmp);
    600   paranoid_free(cwd);
    601   paranoid_free(new);
    602   paranoid_free(command);
    603 
    604   return( resA + resB );
     519    char *tmp, *cwd, *new, *command;
     520    int resA = 0;
     521    int resB = 0;
     522    long noof_changed_files;
     523
     524    malloc_string(tmp);
     525    malloc_string(cwd);
     526    malloc_string(new);
     527    malloc_string(command);
     528
     529    assert(bkpinfo != NULL);
     530
     531    getcwd(cwd, MAX_STR_LEN - 1);
     532    chdir(bkpinfo->restore_path);
     533    getcwd(new, MAX_STR_LEN - 1);
     534    sprintf(tmp, "new path is %s", new);
     535    insist_on_this_cd_number(bkpinfo, g_current_media_number);
     536    unlink("/tmp/changed.txt");
     537
     538    resA = compare_all_tarballs(bkpinfo);
     539    resB = compare_all_biggiefiles(bkpinfo);
     540    chdir(cwd);
     541    noof_changed_files = count_lines_in_file("/tmp/changed.txt");
     542    if (noof_changed_files) {
     543        sprintf(tmp, "%ld files do not match the backup            ",
     544                noof_changed_files);
     545        //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
     546        log_to_screen(tmp);
     547        sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
     548        paranoid_system(command);
     549    } else {
     550        sprintf(tmp, "All files match the backup                     ");
     551        mvaddstr_and_log_it(g_currentY++, 0, tmp);
     552        log_to_screen(tmp);
     553    }
     554
     555    paranoid_free(tmp);
     556    paranoid_free(cwd);
     557    paranoid_free(new);
     558    paranoid_free(command);
     559
     560    return (resA + resB);
    605561}
    606562
     
    622578 */
    623579int
    624 compare_mode( struct s_bkpinfo *bkpinfo ,
    625           struct mountlist_itself *mountlist,
    626           struct raidlist_itself *raidlist)
     580compare_mode(struct s_bkpinfo *bkpinfo,
     581             struct mountlist_itself *mountlist,
     582            struct raidlist_itself *raidlist)
    627583{
    628   int retval = 0;
    629   long q;
    630   char *tmp;
    631  
    632   malloc_string(tmp);
     584    int retval = 0;
     585    long q;
     586    char *tmp;
     587
     588    malloc_string(tmp);
    633589
    634590  /**************************************************************************
     
    636592   * restore them from start of tape, if available                          *
    637593   **************************************************************************/
    638   assert(bkpinfo!=NULL);
    639   assert(mountlist!=NULL);
    640   assert(raidlist!=NULL);
    641 
    642   while (get_cfg_file_from_archive( bkpinfo ))
    643     {
    644       if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?"))
    645         { fatal_error("Unable to find config file/archives. Aborting."); }
    646       interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    647     }
    648 
    649   read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo );
    650   g_current_media_number = 1;
    651   mvaddstr_and_log_it( 1, 30, "Comparing Automatically" );
    652   iamhere("Pre-MAD");
    653   retval = mount_all_devices( mountlist, FALSE );
    654   iamhere("Post-MAD");
    655   if ( retval )
    656     {
    657       unmount_all_devices( mountlist );
    658       return( retval );
    659     }
    660   if ( bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev)
    661     {
    662       retval += compare_to_tape( bkpinfo );
    663     }
    664   else if ( bkpinfo->backup_media_type == cdstream )
    665     {
    666       retval += compare_to_cdstream( bkpinfo );
    667     }
    668   else
    669     {
    670       retval += compare_to_CD( bkpinfo );
    671     }
    672   if ( retval )
    673     {
    674       mvaddstr_and_log_it( g_currentY++,
    675                0,
    676                "Warning - differences found during the compare phase");
    677     }
    678 
    679   retval += unmount_all_devices( mountlist );
    680 
    681   if ( count_lines_in_file("/tmp/changed.txt") > 0 )
    682     {
    683       mvaddstr_and_log_it( g_currentY++, 0,
    684                "Differences found while files were being compared." );
    685       streamline_changes_file( "/tmp/changed.files", "/tmp/changed.txt" );
    686       if (count_lines_in_file( "/tmp/changed.files" ) <= 0 )
    687         {
    688       mvaddstr_and_log_it( g_currentY++,0,
    689                    "...but they were logfiles and temporary files. Your archives are fine.");
    690       log_to_screen( "The differences were logfiles and temporary files. Your archives are fine.");
    691     }
    692       else
    693         {
    694       q = count_lines_in_file("/tmp/changed.files");
    695       sprintf( tmp, "%ld significant difference%s found.", q, (q!=1) ? "s" : "");
    696       mvaddstr_and_log_it( g_currentY++, 0, tmp);
    697       log_to_screen (tmp);
    698 
    699       strcpy( tmp, "Type 'less /tmp/changed.files' for a list of non-matching files" );
    700       mvaddstr_and_log_it( g_currentY++, 0, tmp );
    701       log_to_screen( tmp );
    702 
    703           log_msg(2, "calling popup_changelist_from_file()");
    704           popup_changelist_from_file("/tmp/changed.files");
    705           log_msg(2, "Returning from popup_changelist_from_file()");
    706     }
    707     }
    708   else
    709     {
    710       log_to_screen( "No significant differences were found. Your backup is perfect." );
    711     }
    712   kill_petris();
    713   paranoid_free(tmp);
    714   return( retval );
     594    assert(bkpinfo != NULL);
     595    assert(mountlist != NULL);
     596    assert(raidlist != NULL);
     597
     598    while (get_cfg_file_from_archive(bkpinfo)) {
     599        if (!ask_me_yes_or_no
     600            ("Failed to find config file/archives. Choose another source?"))
     601        {
     602            fatal_error("Unable to find config file/archives. Aborting.");
     603        }
     604        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     605    }
     606
     607    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
     608    g_current_media_number = 1;
     609    mvaddstr_and_log_it(1, 30, "Comparing Automatically");
     610    iamhere("Pre-MAD");
     611    retval = mount_all_devices(mountlist, FALSE);
     612    iamhere("Post-MAD");
     613    if (retval) {
     614        unmount_all_devices(mountlist);
     615        return (retval);
     616    }
     617    if (bkpinfo->backup_media_type == tape
     618        || bkpinfo->backup_media_type == udev) {
     619        retval += compare_to_tape(bkpinfo);
     620    } else if (bkpinfo->backup_media_type == cdstream) {
     621        retval += compare_to_cdstream(bkpinfo);
     622    } else {
     623        retval += compare_to_CD(bkpinfo);
     624    }
     625    if (retval) {
     626        mvaddstr_and_log_it(g_currentY++,
     627                            0,
     628                            "Warning - differences found during the compare phase");
     629    }
     630
     631    retval += unmount_all_devices(mountlist);
     632
     633    if (count_lines_in_file("/tmp/changed.txt") > 0) {
     634        mvaddstr_and_log_it(g_currentY++, 0,
     635                            "Differences found while files were being compared.");
     636        streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt");
     637        if (count_lines_in_file("/tmp/changed.files") <= 0) {
     638            mvaddstr_and_log_it(g_currentY++, 0,
     639                                "...but they were logfiles and temporary files. Your archives are fine.");
     640            log_to_screen
     641                ("The differences were logfiles and temporary files. Your archives are fine.");
     642        } else {
     643            q = count_lines_in_file("/tmp/changed.files");
     644            sprintf(tmp, "%ld significant difference%s found.", q,
     645                    (q != 1) ? "s" : "");
     646            mvaddstr_and_log_it(g_currentY++, 0, tmp);
     647            log_to_screen(tmp);
     648
     649            strcpy(tmp,
     650                   "Type 'less /tmp/changed.files' for a list of non-matching files");
     651            mvaddstr_and_log_it(g_currentY++, 0, tmp);
     652            log_to_screen(tmp);
     653
     654            log_msg(2, "calling popup_changelist_from_file()");
     655            popup_changelist_from_file("/tmp/changed.files");
     656            log_msg(2, "Returning from popup_changelist_from_file()");
     657        }
     658    } else {
     659        log_to_screen
     660            ("No significant differences were found. Your backup is perfect.");
     661    }
     662    kill_petris();
     663    paranoid_free(tmp);
     664    return (retval);
    715665}
    716666
     
    727677 * @return 0 for success, nonzero for failure.
    728678 */
    729 int
    730 compare_to_cdstream(struct s_bkpinfo *bkpinfo)
     679int compare_to_cdstream(struct s_bkpinfo *bkpinfo)
    731680{
    732   int res;
     681    int res;
    733682
    734683  /** needs malloc **/
    735   char *dir, *command;
    736  
    737   assert(bkpinfo!=NULL);
    738   malloc_string(dir);
    739   malloc_string(command);
    740   getcwd( dir, MAX_STR_LEN );
    741   chdir( bkpinfo->restore_path );
    742 
    743   sprintf( command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path );
    744   run_program_and_log_output( command, FALSE );
    745   mvaddstr_and_log_it(g_currentY,
    746               0,
    747               "Verifying archives against filesystem" );
    748 
    749   if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE"))
    750     { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); }
    751   else
    752     { find_cdrom_device( bkpinfo->media_device, FALSE ); }
    753   res = verify_tape_backups( bkpinfo );
    754   chdir( dir );
    755   if ( length_of_file ( "/tmp/changed.txt" ) > 2 && length_of_file ( "/tmp/changed.files" ) > 2 )
    756     {
    757       log_msg(0, "Type 'less /tmp/changed.files' to see which files don't match the archives" );
    758       log_msg(2, "Calling popup_changelist_from_file()" );
    759       popup_changelist_from_file( "/tmp/changed.files" );
    760       log_msg(2, "Returned from popup_changelist_from_file()" );
    761     }
    762 
    763   mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    764   paranoid_free(dir);
    765   paranoid_free(command);
    766   return( res );
     684    char *dir, *command;
     685
     686    assert(bkpinfo != NULL);
     687    malloc_string(dir);
     688    malloc_string(command);
     689    getcwd(dir, MAX_STR_LEN);
     690    chdir(bkpinfo->restore_path);
     691
     692    sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     693            bkpinfo->restore_path);
     694    run_program_and_log_output(command, FALSE);
     695    mvaddstr_and_log_it(g_currentY,
     696                        0, "Verifying archives against filesystem");
     697
     698    if (bkpinfo->disaster_recovery
     699        && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     700        strcpy(bkpinfo->media_device,
     701               last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     702    } else {
     703        find_cdrom_device(bkpinfo->media_device, FALSE);
     704    }
     705    res = verify_tape_backups(bkpinfo);
     706    chdir(dir);
     707    if (length_of_file("/tmp/changed.txt") > 2
     708        && length_of_file("/tmp/changed.files") > 2) {
     709        log_msg(0,
     710                "Type 'less /tmp/changed.files' to see which files don't match the archives");
     711        log_msg(2, "Calling popup_changelist_from_file()");
     712        popup_changelist_from_file("/tmp/changed.files");
     713        log_msg(2, "Returned from popup_changelist_from_file()");
     714    }
     715
     716    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     717    paranoid_free(dir);
     718    paranoid_free(command);
     719    return (res);
    767720}
     721
    768722/**************************************************************************
    769723 *END_COMPARE_CD_STREAM                                                   *
     
    782736 * returns: int                                                           *
    783737 **************************************************************************/
    784 int
    785 compare_to_tape( struct s_bkpinfo *bkpinfo )
     738int compare_to_tape(struct s_bkpinfo *bkpinfo)
    786739{
    787   int res;
    788   char *dir, *command;
    789    
    790   assert(bkpinfo!=NULL);
    791   malloc_string(dir);
    792   malloc_string(command);
    793 
    794   getcwd( dir, MAX_STR_LEN );
    795   chdir( bkpinfo->restore_path );
    796   sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path);
    797   run_program_and_log_output( command, FALSE );
    798   mvaddstr_and_log_it( g_currentY,
    799                0,
    800                "Verifying archives against filesystem");
    801   res = verify_tape_backups( bkpinfo );
    802   chdir( dir );
    803   if ( res )
    804     {
    805       mvaddstr_and_log_it( g_currentY++, 74, "Failed." );
    806     }
    807   else
    808     {
    809       mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    810     }
    811   paranoid_free(dir);
    812   paranoid_free(command);
    813   return( res );
     740    int res;
     741    char *dir, *command;
     742
     743    assert(bkpinfo != NULL);
     744    malloc_string(dir);
     745    malloc_string(command);
     746
     747    getcwd(dir, MAX_STR_LEN);
     748    chdir(bkpinfo->restore_path);
     749    sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     750            bkpinfo->restore_path);
     751    run_program_and_log_output(command, FALSE);
     752    mvaddstr_and_log_it(g_currentY,
     753                        0, "Verifying archives against filesystem");
     754    res = verify_tape_backups(bkpinfo);
     755    chdir(dir);
     756    if (res) {
     757        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     758    } else {
     759        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     760    }
     761    paranoid_free(dir);
     762    paranoid_free(command);
     763    return (res);
    814764}
    815765
     
    819769
    820770/* @} - end compareGroup */
    821 
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-compare.h

    r30 r128  
    11/* mondo-rstr-compare.h
    2  * $Id: mondo-rstr-compare.h,v 1.1 2004/06/10 15:29:13 hugo Exp $
     2 * $Id$
    33 */
    44
    55
    6 int compare_to_CD(struct s_bkpinfo*);
    7 int compare_to_cdstream(struct s_bkpinfo*);
    8 int compare_to_tape(struct s_bkpinfo*);
     6int compare_to_CD(struct s_bkpinfo *);
     7int compare_to_cdstream(struct s_bkpinfo *);
     8int compare_to_tape(struct s_bkpinfo *);
    99
    10 int 
    11 compare_mode( struct s_bkpinfo *bkpinfo ,
    12           struct mountlist_itself *mountlist,
    13           struct raidlist_itself *raidlist);
     10int
     11compare_mode(struct s_bkpinfo *bkpinfo,
     12             struct mountlist_itself *mountlist,
     13            struct raidlist_itself *raidlist);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-newt.c

    r30 r128  
    88edited by : by Stan Benoit 4/2002
    99email     : troff@nakedsoul.org
    10 cvsid     : $Id: mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp $
     10cvsid     : $Id$
    1111***************************************************************************/
    1212
     
    9292#include "mondo-rstr-newt.h"
    9393
    94 //static char cvsid[] = "$Id: mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp $";
     94//static char cvsid[] = "$Id$";
    9595
    9696extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
     
    127127 */
    128128void
    129 add_disklist_entry (struct list_of_disks *disklist, char *raid_device,
    130             struct mountlist_itself *unallocated_raid_partitions)
     129add_disklist_entry(struct list_of_disks *disklist, char *raid_device,
     130                   struct mountlist_itself *unallocated_raid_partitions)
    131131{
    132132    /** buffers ***********************************************************/
    133   char tmp[MAX_STR_LEN];
     133    char tmp[MAX_STR_LEN];
    134134
    135135    /** newt **************************************************************/
    136   newtComponent myForm;
     136    newtComponent myForm;
    137137    newtComponent bOK;
    138138    newtComponent bCancel;
     
    140140    newtComponent partitionsListbox;
    141141    newtComponent headerMsg;
    142    
     142
    143143  /** prototypes *********************************************************/
    144   void *keylist[ARBITRARY_MAXIMUM];
    145   void *curr_choice;
     144    void *keylist[ARBITRARY_MAXIMUM];
     145    void *curr_choice;
    146146
    147147    /** int ****************************************************************/
    148   int i = 0;
     148    int i = 0;
    149149    int index = 0;
    150150    int currline = 0;
    151151    int items = 0;
    152152
    153   assert(disklist!=NULL);
    154   assert_string_is_neither_NULL_nor_zerolength(raid_device);
    155   assert(unallocated_raid_partitions!=NULL);
    156 
    157   newtPushHelpLine
    158     ("   Add one of the following unallocated RAID partitions to this RAID device.");
    159   sprintf (tmp, "%-26s %s", "Device", "Size");
    160   headerMsg = newtLabel (1, 1, tmp);
    161   partitionsListbox =
    162     newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    163   redraw_unallocpartnslist (unallocated_raid_partitions, keylist,
    164                 partitionsListbox);
    165   i = 7;
    166   bOK = newtCompactButton (i, 9, "  OK  ");
    167   bCancel = newtCompactButton (i += 9, 9, "Cancel");
    168   newtOpenWindow (22, 6, 36, 10, "Unallocated RAID partitions");
    169   myForm = newtForm (NULL, NULL, 0);
    170   newtFormAddComponents (myForm, headerMsg, partitionsListbox, bOK, bCancel,
    171              NULL);
    172   b_res = newtRunForm (myForm);
    173   if (b_res != bCancel)
    174     {
    175       curr_choice = newtListboxGetCurrent (partitionsListbox);
    176       for (currline = 0;
    177        currline < unallocated_raid_partitions->entries
    178        && keylist[currline] != curr_choice; currline++);
    179       if (currline == unallocated_raid_partitions->entries
    180       && unallocated_raid_partitions->entries > 0)
    181     {
    182       log_it ("I don't know what this button does");
    183     }
    184       else
    185     {
    186       index = find_next_free_index_in_disklist (disklist);
    187    
    188       items = disklist->entries;
    189       strcpy (disklist->el[items].device,
    190           unallocated_raid_partitions->el[currline].device);
    191       disklist->el[items].index = index;
    192       disklist->entries = ++items;
    193    
    194     }
    195     }
    196   newtFormDestroy (myForm);
    197   newtPopWindow ();
    198   newtPopHelpLine ();
     153    assert(disklist != NULL);
     154    assert_string_is_neither_NULL_nor_zerolength(raid_device);
     155    assert(unallocated_raid_partitions != NULL);
     156
     157    newtPushHelpLine
     158        ("   Add one of the following unallocated RAID partitions to this RAID device.");
     159    sprintf(tmp, "%-26s %s", "Device", "Size");
     160    headerMsg = newtLabel(1, 1, tmp);
     161    partitionsListbox =
     162        newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     163    redraw_unallocpartnslist(unallocated_raid_partitions, keylist,
     164                             partitionsListbox);
     165    i = 7;
     166    bOK = newtCompactButton(i, 9, "  OK  ");
     167    bCancel = newtCompactButton(i += 9, 9, "Cancel");
     168    newtOpenWindow(22, 6, 36, 10, "Unallocated RAID partitions");
     169    myForm = newtForm(NULL, NULL, 0);
     170    newtFormAddComponents(myForm, headerMsg, partitionsListbox, bOK,
     171                          bCancel, NULL);
     172    b_res = newtRunForm(myForm);
     173    if (b_res != bCancel) {
     174        curr_choice = newtListboxGetCurrent(partitionsListbox);
     175        for (currline = 0;
     176             currline < unallocated_raid_partitions->entries
     177             && keylist[currline] != curr_choice; currline++);
     178        if (currline == unallocated_raid_partitions->entries
     179            && unallocated_raid_partitions->entries > 0) {
     180            log_it("I don't know what this button does");
     181        } else {
     182            index = find_next_free_index_in_disklist(disklist);
     183
     184            items = disklist->entries;
     185            strcpy(disklist->el[items].device,
     186                   unallocated_raid_partitions->el[currline].device);
     187            disklist->el[items].index = index;
     188            disklist->entries = ++items;
     189
     190        }
     191    }
     192    newtFormDestroy(myForm);
     193    newtPopWindow();
     194    newtPopHelpLine();
    199195}
    200196
     
    212208 */
    213209void
    214 add_mountlist_entry (struct mountlist_itself *mountlist,
    215              struct raidlist_itself *raidlist, newtComponent listbox,
    216             int currline, void *keylist[])
     210add_mountlist_entry(struct mountlist_itself *mountlist,
     211                    struct raidlist_itself *raidlist,
     212                    newtComponent listbox, int currline, void *keylist[])
    217213{
    218214
    219215    /** int **************************************************************/
    220   int i = 0;
     216    int i = 0;
    221217    int num_to_add = 0;
    222218
    223219    /** newt *************************************************************/
    224   newtComponent myForm;
     220    newtComponent myForm;
    225221    newtComponent bOK;
    226222    newtComponent bCancel;
     
    236232
    237233    /** buffers **********************************************************/
    238   char drive_to_add[MAX_STR_LEN];
     234    char drive_to_add[MAX_STR_LEN];
    239235    char mountpoint_str[MAX_STR_LEN];
    240236    char size_str[MAX_STR_LEN];
    241   char device_str[MAX_STR_LEN];
     237    char device_str[MAX_STR_LEN];
    242238    char format_str[MAX_STR_LEN];
    243239
     
    248244    char *format_here;
    249245
    250   assert(mountlist!=NULL);
    251   assert(raidlist!=NULL);
    252   assert(listbox!=NULL);
    253   assert(keylist!=NULL);
    254 
    255     strcpy (device_str, "/dev/");
    256     strcpy (mountpoint_str, "/");
     246    assert(mountlist != NULL);
     247    assert(raidlist != NULL);
     248    assert(listbox != NULL);
     249    assert(keylist != NULL);
     250
     251    strcpy(device_str, "/dev/");
     252    strcpy(mountpoint_str, "/");
    257253#ifdef __FreeBSD__
    258     strcpy (format_str, "ufs");
     254    strcpy(format_str, "ufs");
    259255#else
    260   strcpy (format_str, "ext2");
     256    strcpy(format_str, "ext2");
    261257#endif
    262   size_str[0] = '\0';
    263   /* sprintf(size_str,""); */
    264   newtOpenWindow (20, 5, 48, 10, "Add entry");
    265   label0 = newtLabel (2, 1, "Device:    ");
    266   label1 = newtLabel (2, 2, "Mountpoint:");
    267   label2 = newtLabel (2, 3, "Size (MB): ");
    268   label3 = newtLabel (2, 4, "Format:    ");
    269   deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0);
    270   mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0);
    271   formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0);
    272   sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0);
    273   bOK = newtButton (5, 6, "  OK  ");
    274   bCancel = newtButton (17, 6, "Cancel");
    275   newtPushHelpLine
    276     ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'");
    277   myForm = newtForm (NULL, NULL, 0);
    278   newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp,
    279              formatComp, label0, label1, label2, label3, bOK,
    280              bCancel, NULL);
    281   for (b_res = NULL; b_res != bOK && b_res != bCancel;)
    282     {
    283       b_res = newtRunForm (myForm);
    284       strcpy (device_str, device_here);
    285       strcpy (mountpoint_str, mountpoint_here);
    286       strcpy (format_str, format_here);
    287       strcpy (size_str, size_here);
     258    size_str[0] = '\0';
     259    /* sprintf(size_str,""); */
     260    newtOpenWindow(20, 5, 48, 10, "Add entry");
     261    label0 = newtLabel(2, 1, "Device:    ");
     262    label1 = newtLabel(2, 2, "Mountpoint:");
     263    label2 = newtLabel(2, 3, "Size (MB): ");
     264    label3 = newtLabel(2, 4, "Format:    ");
     265    deviceComp =
     266        newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     267    mountpointComp =
     268        newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     269    formatComp =
     270        newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     271    sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
     272    bOK = newtButton(5, 6, "  OK  ");
     273    bCancel = newtButton(17, 6, "Cancel");
     274    newtPushHelpLine
     275        ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'");
     276    myForm = newtForm(NULL, NULL, 0);
     277    newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
     278                          formatComp, label0, label1, label2, label3, bOK,
     279                          bCancel, NULL);
     280    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
     281        b_res = newtRunForm(myForm);
     282        strcpy(device_str, device_here);
     283        strcpy(mountpoint_str, mountpoint_here);
     284        strcpy(format_str, format_here);
     285        strcpy(size_str, size_here);
    288286//      log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    289       strip_spaces (device_str);
    290       strip_spaces (mountpoint_str);
    291       strip_spaces (format_str);
    292       strip_spaces (size_str);
     287        strip_spaces(device_str);
     288        strip_spaces(mountpoint_str);
     289        strip_spaces(format_str);
     290        strip_spaces(size_str);
    293291//      log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    294       if (b_res == bOK)
    295     {
    296       if (device_str[strlen (device_str) - 1] == '/')
    297         {
    298           popup_and_OK ("You left the device nearly blank!");
    299           b_res = NULL;
    300         }
    301       if (size_of_specific_device_in_mountlist (mountlist, device_str) >= 0)
    302         {
    303           popup_and_OK ("Can't add this - you've got one already!");
    304           b_res = NULL;
    305         }
    306     }
    307     }
    308   newtFormDestroy (myForm);
    309   newtPopHelpLine ();
    310   newtPopWindow ();
    311   if (b_res == bCancel)
    312     {
    313       return;
    314     }
    315   strcpy (drive_to_add, device_str);
    316   for (i = strlen (drive_to_add); isdigit (drive_to_add[i - 1]); i--);
    317   num_to_add = atoi (drive_to_add + i);
    318   drive_to_add[i] = '\0';
    319   currline = mountlist->entries;
    320   strcpy (mountlist->el[currline].device, device_str);
    321   strcpy (mountlist->el[currline].mountpoint, mountpoint_str);
    322   strcpy (mountlist->el[currline].format, format_str);
    323   mountlist->el[currline].size = atol (size_str) * 1024;
    324   mountlist->entries++;
    325   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB))
    326     {
    327       initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str);
    328     }
    329   redraw_mountlist (mountlist, keylist, listbox);
     292        if (b_res == bOK) {
     293            if (device_str[strlen(device_str) - 1] == '/') {
     294                popup_and_OK("You left the device nearly blank!");
     295                b_res = NULL;
     296            }
     297            if (size_of_specific_device_in_mountlist(mountlist, device_str)
     298                >= 0) {
     299                popup_and_OK("Can't add this - you've got one already!");
     300                b_res = NULL;
     301            }
     302        }
     303    }
     304    newtFormDestroy(myForm);
     305    newtPopHelpLine();
     306    newtPopWindow();
     307    if (b_res == bCancel) {
     308        return;
     309    }
     310    strcpy(drive_to_add, device_str);
     311    for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--);
     312    num_to_add = atoi(drive_to_add + i);
     313    drive_to_add[i] = '\0';
     314    currline = mountlist->entries;
     315    strcpy(mountlist->el[currline].device, device_str);
     316    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     317    strcpy(mountlist->el[currline].format, format_str);
     318    mountlist->el[currline].size = atol(size_str) * 1024;
     319    mountlist->entries++;
     320    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     321        initiate_new_raidlist_entry(raidlist, mountlist, currline,
     322                                    device_str);
     323    }
     324    redraw_mountlist(mountlist, keylist, listbox);
    330325}
    331326
     
    337332 * @ingroup restoreGuiVarslist
    338333 */
    339 void
    340 add_varslist_entry (struct raid_device_record *raidrec)
     334void add_varslist_entry(struct raid_device_record *raidrec)
    341335{
    342336
    343337    /** buffers ***********************************************************/
    344   char sz_out[MAX_STR_LEN];
     338    char sz_out[MAX_STR_LEN];
    345339
    346340    /** int ****************************************************************/
    347   int items = 0;
     341    int items = 0;
    348342    int i = 0;
    349343
    350   assert(raidrec!=NULL);
    351 
    352   sz_out[0] = '\0';
    353   if (popup_and_get_string
    354       ("Add variable", "Enter the name of the variable to add", sz_out, MAX_STR_LEN))
    355     {
    356       strip_spaces (sz_out);
    357       items = raidrec->additional_vars.entries;
    358       for (i = 0;
    359        i < items && strcmp (raidrec->additional_vars.el[i].label, sz_out);
    360        i++);
    361       if (i < items)
    362     {
    363       popup_and_OK
    364         ("No need to add that variable. It is already listed here.");
    365     }
    366       else
    367     {
    368       strcpy (raidrec->additional_vars.el[items].label, sz_out);
    369       edit_varslist_entry (raidrec, items);
    370       raidrec->additional_vars.entries = ++items;
    371     }
    372     }
     344    assert(raidrec != NULL);
     345
     346    sz_out[0] = '\0';
     347    if (popup_and_get_string
     348        ("Add variable", "Enter the name of the variable to add", sz_out,
     349         MAX_STR_LEN)) {
     350        strip_spaces(sz_out);
     351        items = raidrec->additional_vars.entries;
     352        for (i = 0;
     353             i < items
     354             && strcmp(raidrec->additional_vars.el[i].label, sz_out); i++);
     355        if (i < items) {
     356            popup_and_OK
     357                ("No need to add that variable. It is already listed here.");
     358        } else {
     359            strcpy(raidrec->additional_vars.el[items].label, sz_out);
     360            edit_varslist_entry(raidrec, items);
     361            raidrec->additional_vars.entries = ++items;
     362        }
     363    }
    373364}
    374365#endif
     
    383374 */
    384375long
    385 calculate_raid_device_size (struct mountlist_itself *mountlist,
    386                 struct raidlist_itself *raidlist,
    387                 char *raid_device)
     376calculate_raid_device_size(struct mountlist_itself *mountlist,
     377                           struct raidlist_itself *raidlist,
     378                           char *raid_device)
    388379{
    389380#ifdef __FreeBSD__
    390     /** FreeBSD-specific version of calculate_raid_device_size() **/
     381    /** FreeBSD-specific version of calculate_raid_device_size() **/
    391382
    392383    /** structures ********************************************************/
    393   struct vinum_volume *raidrec;
     384    struct vinum_volume *raidrec;
    394385
    395386    /** int ***************************************************************/
    396   int i = 0, j = 0;
     387    int i = 0, j = 0;
    397388    int noof_partitions = 0;
    398389
    399390    /** long **************************************************************/
    400   long total_size = 0;
    401   long plex_size = 0;
    402   long smallest_partition = 999999999;
    403   long smallest_plex      = 999999999;
     391    long total_size = 0;
     392    long plex_size = 0;
     393    long smallest_partition = 999999999;
     394    long smallest_plex = 999999999;
    404395    long sp = 0;
    405396
    406397    /** buffers ***********************************************************/
    407   char tmp[MAX_STR_LEN];
    408 
    409 
    410 
    411 
    412   for (i = 0;
    413        i < raidlist->entries
    414        && strcmp (raidlist->el[i].volname, basename (raid_device)); i++);
    415   if (i == raidlist->entries)
    416     {
    417       sprintf (tmp,
    418            "Cannot calc size of raid device %s - cannot find it in raidlist",
    419            raid_device);
    420       log_it (tmp);
    421       return (0); // Isn't this more sensible than 999999999? If the raid dev !exists,
    422                   // then it has no size, right?
    423     }
    424   raidrec = &raidlist->el[i];
    425   total_size = 0;
    426   if (raidrec->plexes == 0) return 0;
    427   for (j = 0; j < raidrec->plexes; j++) {
    428       plex_size = 0;
    429       int k = 0, l = 0;
    430       for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
    431       char devname[64];
    432       strcpy (devname, raidrec->plex[j].sd[k].which_device);
    433       for (l = 0; l < raidlist->disks.entries; ++l) {
    434           if (!strcmp (devname, raidlist->disks.el[l].name)) {
    435           switch (raidrec->plex[j].raidlevel) {
    436           case -1:
    437               plex_size +=
    438               size_of_specific_device_in_mountlist (mountlist,
    439                                 raidlist->disks.el[l].device);
    440               break;
    441           case 0:
    442           case 5:
    443               if (size_of_specific_device_in_mountlist (mountlist,
    444                                    raidlist->disks.el[l].device) < smallest_partition) {
    445               smallest_partition = size_of_specific_device_in_mountlist (mountlist,
    446                                             raidlist->disks.el[l].device);
    447               }
    448               break;
    449           }
    450           }
    451       }
    452       }
    453      
    454       if (!is_this_raid_personality_registered (raidrec->plex[j].raidlevel)) {
    455       log_it ("%s has a really weird RAID level - couldn't calc size :(", raid_device);
    456       return (999999999);
    457       }
    458       if (raidrec->plex[j].raidlevel != -1) {
    459       plex_size = smallest_partition * (raidrec->plex[j].subdisks -
    460                         (raidrec->plex[j].raidlevel == 5 ? 1 : 0));
    461       }
    462       if (plex_size < smallest_plex)
    463       smallest_plex = plex_size;
    464 
    465       smallest_partition = 999999999;
    466   }
    467 
    468   sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device,
    469        (long) smallest_plex);
    470   log_it (tmp);
    471   return (smallest_plex);
     398    char tmp[MAX_STR_LEN];
     399
     400
     401
     402
     403    for (i = 0;
     404         i < raidlist->entries
     405         && strcmp(raidlist->el[i].volname, basename(raid_device)); i++);
     406    if (i == raidlist->entries) {
     407        sprintf(tmp,
     408                "Cannot calc size of raid device %s - cannot find it in raidlist",
     409                raid_device);
     410        log_it(tmp);
     411        return (0);             // Isn't this more sensible than 999999999? If the raid dev !exists,
     412        // then it has no size, right?
     413    }
     414    raidrec = &raidlist->el[i];
     415    total_size = 0;
     416    if (raidrec->plexes == 0)
     417        return 0;
     418    for (j = 0; j < raidrec->plexes; j++) {
     419        plex_size = 0;
     420        int k = 0, l = 0;
     421        for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
     422            char devname[64];
     423            strcpy(devname, raidrec->plex[j].sd[k].which_device);
     424            for (l = 0; l < raidlist->disks.entries; ++l) {
     425                if (!strcmp(devname, raidlist->disks.el[l].name)) {
     426                    switch (raidrec->plex[j].raidlevel) {
     427                    case -1:
     428                        plex_size +=
     429                            size_of_specific_device_in_mountlist(mountlist,
     430                                                                 raidlist->
     431                                                                 disks.
     432                                                                 el[l].
     433                                                                 device);
     434                        break;
     435                    case 0:
     436                    case 5:
     437                        if (size_of_specific_device_in_mountlist(mountlist,
     438                                                                 raidlist->
     439                                                                 disks.
     440                                                                 el[l].
     441                                                                 device) <
     442                            smallest_partition) {
     443                            smallest_partition =
     444                                size_of_specific_device_in_mountlist
     445                                (mountlist, raidlist->disks.el[l].device);
     446                        }
     447                        break;
     448                    }
     449                }
     450            }
     451        }
     452
     453        if (!is_this_raid_personality_registered
     454            (raidrec->plex[j].raidlevel)) {
     455            log_it
     456                ("%s has a really weird RAID level - couldn't calc size :(",
     457                 raid_device);
     458            return (999999999);
     459        }
     460        if (raidrec->plex[j].raidlevel != -1) {
     461            plex_size = smallest_partition * (raidrec->plex[j].subdisks -
     462                                              (raidrec->plex[j].
     463                                               raidlevel == 5 ? 1 : 0));
     464        }
     465        if (plex_size < smallest_plex)
     466            smallest_plex = plex_size;
     467
     468        smallest_partition = 999999999;
     469    }
     470
     471    sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
     472            (long) smallest_plex);
     473    log_it(tmp);
     474    return (smallest_plex);
    472475#else
    473     /** Linux-specific version of calculate_raid_device_size() **/
     476    /** Linux-specific version of calculate_raid_device_size() **/
    474477
    475478    /** structures ********************************************************/
    476   struct raid_device_record *raidrec;
     479    struct raid_device_record *raidrec;
    477480
    478481    /** int ***************************************************************/
    479   int i = 0;
     482    int i = 0;
    480483    int noof_partitions = 0;
    481484
    482485    /** long **************************************************************/
    483   long total_size = 0;
     486    long total_size = 0;
    484487    long smallest_partition = 999999999;
    485488    long sp = 0;
    486489
    487490    /** buffers ***********************************************************/
    488   char tmp[MAX_STR_LEN];
    489 
    490   assert(mountlist!=NULL);
    491   assert(raidlist!=NULL);
    492   assert_string_is_neither_NULL_nor_zerolength(raid_device);
    493 
    494   for (i = 0;
    495        i < raidlist->entries
    496        && strcmp (raidlist->el[i].raid_device, raid_device); i++);
    497   if (i == raidlist->entries)
    498     {
    499       sprintf (tmp,
    500            "Cannot calc size of raid device %s - cannot find it in raidlist",
    501            raid_device);
    502       log_it (tmp);
    503       return (999999999);
    504     }
    505   raidrec = &raidlist->el[i];
    506   noof_partitions = raidrec->data_disks.entries;
    507   if (raidrec->raid_level == -1 || raidrec->raid_level == 0)
    508     {
    509       for (total_size = 0, i = 0; i < noof_partitions; i++)
    510     {
    511       total_size +=
    512         size_of_specific_device_in_mountlist (mountlist,
    513                      raidrec->data_disks.el[i].device);
    514     }
    515     }
    516   else
    517     {
    518       for (i = 0; i < noof_partitions; i++)
    519     {
    520       sp =
    521         size_of_specific_device_in_mountlist (mountlist,
    522                      raidrec->data_disks.el[i].device);
    523       if (smallest_partition > sp)
    524         {
    525           smallest_partition = sp;
    526         }
    527     }
    528       total_size = smallest_partition * (noof_partitions - 1);
    529     }
    530   sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device,
    531        (long) total_size);
    532   log_it (tmp);
    533   return (total_size);
     491    char tmp[MAX_STR_LEN];
     492
     493    assert(mountlist != NULL);
     494    assert(raidlist != NULL);
     495    assert_string_is_neither_NULL_nor_zerolength(raid_device);
     496
     497    for (i = 0;
     498         i < raidlist->entries
     499         && strcmp(raidlist->el[i].raid_device, raid_device); i++);
     500    if (i == raidlist->entries) {
     501        sprintf(tmp,
     502                "Cannot calc size of raid device %s - cannot find it in raidlist",
     503                raid_device);
     504        log_it(tmp);
     505        return (999999999);
     506    }
     507    raidrec = &raidlist->el[i];
     508    noof_partitions = raidrec->data_disks.entries;
     509    if (raidrec->raid_level == -1 || raidrec->raid_level == 0) {
     510        for (total_size = 0, i = 0; i < noof_partitions; i++) {
     511            total_size +=
     512                size_of_specific_device_in_mountlist(mountlist,
     513                                                     raidrec->data_disks.
     514                                                     el[i].device);
     515        }
     516    } else {
     517        for (i = 0; i < noof_partitions; i++) {
     518            sp = size_of_specific_device_in_mountlist(mountlist,
     519                                                      raidrec->data_disks.
     520                                                      el[i].device);
     521            if (smallest_partition > sp) {
     522                smallest_partition = sp;
     523            }
     524        }
     525        total_size = smallest_partition * (noof_partitions - 1);
     526    }
     527    sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
     528            (long) total_size);
     529    log_it(tmp);
     530    return (total_size);
    534531#endif
    535532}
     
    543540 */
    544541void
    545 choose_raid_level (struct OSSWAP (raid_device_record, vinum_plex) *raidrec)
     542choose_raid_level(struct OSSWAP (raid_device_record, vinum_plex) * raidrec)
    546543{
    547544
    548545#ifdef __FreeBSD__
    549    
     546
    550547    /** int ***************************************************************/
    551   int res = 0;
     548    int res = 0;
    552549    int out = 0;
    553550
    554551    /** buffers ***********************************************************/
    555   char tmp[MAX_STR_LEN];
    556   char prompt[MAX_STR_LEN];
    557   char sz[MAX_STR_LEN];
    558 
    559   sprintf (prompt, "Please enter the RAID level you want. (concat, striped, raid5)");
    560   if (raidrec->raidlevel == -1)
    561     {
    562       strcpy (tmp, "concat");
    563     }
    564   else if (raidrec->raidlevel == 0)
    565     {
    566       strcpy (tmp, "striped");
    567     } else {
    568     sprintf (tmp, "raid%i", raidrec->raidlevel);
    569     }
    570   for (out = 999; out == 999;)
    571     {
    572       res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10);
    573       if (!res)
    574     {
    575       return;
    576     }
    577       strip_spaces (tmp);
    578       if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']')
    579     {
    580       strcpy (sz, tmp);
    581       strncpy (tmp, sz + 1, strlen (sz) - 2);
    582       tmp[strlen (sz) - 2] = '\0';
    583     }
    584       if (!strcmp (tmp, "concat"))
    585     {
    586       out = -1;
    587     }
    588       else if (!strcmp (tmp, "striped"))
    589     {
    590         out = 0;
    591     }
    592       else if (!strcmp (tmp, "raid5"))
    593     {
    594       out = 5;
    595     }
    596       log_it (tmp);
    597       if (is_this_raid_personality_registered (out))
    598     {
    599       log_it
    600         ("Groovy. You've picked a RAID personality which is registered.");
    601     }
    602       else
    603     {
    604       if (ask_me_yes_or_no
    605           ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
    606         {
    607           out = 999;
    608         }
    609     }
    610     }
    611   raidrec->raidlevel = out;
     552    char tmp[MAX_STR_LEN];
     553    char prompt[MAX_STR_LEN];
     554    char sz[MAX_STR_LEN];
     555
     556    sprintf(prompt,
     557            "Please enter the RAID level you want. (concat, striped, raid5)");
     558    if (raidrec->raidlevel == -1) {
     559        strcpy(tmp, "concat");
     560    } else if (raidrec->raidlevel == 0) {
     561        strcpy(tmp, "striped");
     562    } else {
     563        sprintf(tmp, "raid%i", raidrec->raidlevel);
     564    }
     565    for (out = 999; out == 999;) {
     566        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
     567        if (!res) {
     568            return;
     569        }
     570        strip_spaces(tmp);
     571        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
     572            strcpy(sz, tmp);
     573            strncpy(tmp, sz + 1, strlen(sz) - 2);
     574            tmp[strlen(sz) - 2] = '\0';
     575        }
     576        if (!strcmp(tmp, "concat")) {
     577            out = -1;
     578        } else if (!strcmp(tmp, "striped")) {
     579            out = 0;
     580        } else if (!strcmp(tmp, "raid5")) {
     581            out = 5;
     582        }
     583        log_it(tmp);
     584        if (is_this_raid_personality_registered(out)) {
     585            log_it
     586                ("Groovy. You've picked a RAID personality which is registered.");
     587        } else {
     588            if (ask_me_yes_or_no
     589                ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
     590            {
     591                out = 999;
     592            }
     593        }
     594    }
     595    raidrec->raidlevel = out;
    612596#else
    613597    /** buffers ***********************************************************/
    614   char tmp[MAX_STR_LEN];
     598    char tmp[MAX_STR_LEN];
    615599    char personalities[MAX_STR_LEN];
    616600    char prompt[MAX_STR_LEN];
    617601    char sz[MAX_STR_LEN];
    618     int out=0, res=0;
    619 
    620 
    621   assert(raidrec!=NULL);
    622   system
    623     ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null");
    624   strcpy (personalities, last_line_of_file ("/tmp/raid-personalities.txt"));
    625   sprintf (prompt, "Please enter the RAID level you want. %s", personalities);
    626   if (raidrec->raid_level == -1)
    627     {
    628       strcpy (tmp, "linear");
    629     }
    630   else
    631     {
    632       sprintf (tmp, "%d", raidrec->raid_level);
    633     }
    634   for (out = 999;
    635        out != -1 && out != 0 && out != 1 && out != 4 && out != 5
    636        && out != 10;)
    637     {
    638       res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10);
    639       if (!res)
    640     {
    641       return;
    642     }
    643       strip_spaces (tmp);
    644       if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']')
    645     {
    646       strcpy (sz, tmp);
    647       strncpy (tmp, sz + 1, strlen (sz) - 2);
    648       tmp[strlen (sz) - 2] = '\0';
    649     }
    650       if (!strcmp (tmp, "linear"))
    651     {
    652       out = -1;
    653     }
    654       else if (!strncmp (tmp, "raid", 4))
    655     {
    656       out = atoi (tmp + 4);
    657     }
    658       else
    659     {
    660       out = atoi (tmp);
    661     }
    662       log_it (tmp);
    663       if (is_this_raid_personality_registered (out))
    664     {
    665       log_it
    666         ("Groovy. You've picked a RAID personality which is registered.");
    667     }
    668       else
    669     {
    670       if (ask_me_yes_or_no
    671           ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
    672         {
    673           out = 999;
    674         }
    675     }
    676     }
    677   raidrec->raid_level = out;
     602    int out = 0, res = 0;
     603
     604
     605    assert(raidrec != NULL);
     606    system
     607        ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null");
     608    strcpy(personalities,
     609           last_line_of_file("/tmp/raid-personalities.txt"));
     610    sprintf(prompt, "Please enter the RAID level you want. %s",
     611            personalities);
     612    if (raidrec->raid_level == -1) {
     613        strcpy(tmp, "linear");
     614    } else {
     615        sprintf(tmp, "%d", raidrec->raid_level);
     616    }
     617    for (out = 999;
     618         out != -1 && out != 0 && out != 1 && out != 4 && out != 5
     619         && out != 10;) {
     620        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
     621        if (!res) {
     622            return;
     623        }
     624        strip_spaces(tmp);
     625        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
     626            strcpy(sz, tmp);
     627            strncpy(tmp, sz + 1, strlen(sz) - 2);
     628            tmp[strlen(sz) - 2] = '\0';
     629        }
     630        if (!strcmp(tmp, "linear")) {
     631            out = -1;
     632        } else if (!strncmp(tmp, "raid", 4)) {
     633            out = atoi(tmp + 4);
     634        } else {
     635            out = atoi(tmp);
     636        }
     637        log_it(tmp);
     638        if (is_this_raid_personality_registered(out)) {
     639            log_it
     640                ("Groovy. You've picked a RAID personality which is registered.");
     641        } else {
     642            if (ask_me_yes_or_no
     643                ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))
     644            {
     645                out = 999;
     646            }
     647        }
     648    }
     649    raidrec->raid_level = out;
    678650#endif
    679651}
     
    690662 */
    691663void
    692 del_partns_listed_in_disklist (struct mountlist_itself *mountlist,
    693                    struct raidlist_itself *raidlist,
    694                    struct list_of_disks *disklist)
     664del_partns_listed_in_disklist(struct mountlist_itself *mountlist,
     665                              struct raidlist_itself *raidlist,
     666                              struct list_of_disks *disklist)
    695667{
    696668
    697669    /** int ***************************************************************/
    698   int i = 0;
     670    int i = 0;
    699671    int pos = 0;
    700672
    701673    /** buffers ***********************************************************/
    702   char tmp[MAX_STR_LEN];
    703 
    704   assert(mountlist!=NULL);
    705   assert(raidlist!=NULL);
    706   assert(disklist!=NULL);
    707 
    708   for (i = 0; i < disklist->entries; i++)
    709     {
    710       for (pos = 0;
    711        pos < mountlist->entries
    712        && strcmp (mountlist->el[pos].device, disklist->el[i].device);
    713        pos++);
    714       if (pos < mountlist->entries)
    715     {
    716       sprintf (tmp,
    717            "Deleting partition %s cos it was part of a now-defunct RAID",
    718            mountlist->el[pos].device);
    719       log_it (tmp);
    720       memcpy ((void *) &mountlist->el[pos],
    721           (void *) &mountlist->el[mountlist->entries - 1],
    722           sizeof (struct mountlist_line));
    723       mountlist->entries--;
    724     }
    725     }
     674    char tmp[MAX_STR_LEN];
     675
     676    assert(mountlist != NULL);
     677    assert(raidlist != NULL);
     678    assert(disklist != NULL);
     679
     680    for (i = 0; i < disklist->entries; i++) {
     681        for (pos = 0;
     682             pos < mountlist->entries
     683             && strcmp(mountlist->el[pos].device, disklist->el[i].device);
     684             pos++);
     685        if (pos < mountlist->entries) {
     686            sprintf(tmp,
     687                    "Deleting partition %s cos it was part of a now-defunct RAID",
     688                    mountlist->el[pos].device);
     689            log_it(tmp);
     690            memcpy((void *) &mountlist->el[pos],
     691                   (void *) &mountlist->el[mountlist->entries - 1],
     692                   sizeof(struct mountlist_line));
     693            mountlist->entries--;
     694        }
     695    }
    726696}
    727697
     
    737707 */
    738708void
    739 delete_disklist_entry (struct list_of_disks *disklist, char *raid_device,
    740                int currline)
     709delete_disklist_entry(struct list_of_disks *disklist, char *raid_device,
     710                      int currline)
    741711{
    742712
    743713    /** int ***************************************************************/
    744   int pos = 0;
     714    int pos = 0;
    745715
    746716    /** buffers ***********************************************************/
    747   char tmp[MAX_STR_LEN];
    748 
    749   assert(disklist!=NULL);
    750   assert_string_is_neither_NULL_nor_zerolength(raid_device);
    751 
    752   sprintf (tmp, "Delete %s from RAID device %s - are you sure?",
    753        disklist->el[currline].device, raid_device);
    754   if (!ask_me_yes_or_no (tmp))
    755     {
    756       return;
    757     }
    758   for (pos = currline; pos < disklist->entries - 1; pos++)
    759     {
    760       /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
    761       strcpy (disklist->el[pos].device, disklist->el[pos + 1].device);
    762     }
    763   disklist->entries--;
     717    char tmp[MAX_STR_LEN];
     718
     719    assert(disklist != NULL);
     720    assert_string_is_neither_NULL_nor_zerolength(raid_device);
     721
     722    sprintf(tmp, "Delete %s from RAID device %s - are you sure?",
     723            disklist->el[currline].device, raid_device);
     724    if (!ask_me_yes_or_no(tmp)) {
     725        return;
     726    }
     727    for (pos = currline; pos < disklist->entries - 1; pos++) {
     728        /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
     729        strcpy(disklist->el[pos].device, disklist->el[pos + 1].device);
     730    }
     731    disklist->entries--;
    764732}
    765733
     
    776744 */
    777745void
    778 delete_mountlist_entry (struct mountlist_itself *mountlist,
    779             struct raidlist_itself *raidlist,
    780             newtComponent listbox, int currline, void *keylist[])
     746delete_mountlist_entry(struct mountlist_itself *mountlist,
     747                       struct raidlist_itself *raidlist,
     748                       newtComponent listbox, int currline,
     749                       void *keylist[])
    781750{
    782751
    783752    /** int ***************************************************************/
    784   int pos = 0;
     753    int pos = 0;
    785754
    786755    /** buffers ***********************************************************/
    787   char tmp[MAX_STR_LEN];
     756    char tmp[MAX_STR_LEN];
    788757    char device[MAX_STR_LEN];
    789758
    790759
    791   assert(mountlist!=NULL);
    792   assert(raidlist!=NULL);
    793   assert(listbox!=NULL);
    794   assert(keylist!=NULL);
    795 
    796   pos =
    797     which_raid_device_is_using_this_partition (raidlist,
    798                            mountlist->el[currline].
    799                            device);
    800   if (pos >= 0)
    801     {
    802       sprintf (tmp, "Cannot delete %s: it is in use by RAID device %s",
    803            mountlist->el[currline].device, raidlist->el[pos].OSSWAP (raid_device, volname));
    804       popup_and_OK (tmp);
    805       return;
    806     }
    807   sprintf (tmp, "Delete %s - are you sure?", mountlist->el[currline].device);
    808   if (!ask_me_yes_or_no (tmp))
    809     {
    810       return;
    811     }
    812   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB))
    813     {
    814       strcpy (device, mountlist->el[currline].device);
    815       delete_raidlist_entry (mountlist, raidlist, device);
    816       for (currline = 0;
    817        currline < mountlist->entries
    818        && strcmp (mountlist->el[currline].device, device); currline++);
    819       if (currline == mountlist->entries)
    820     {
    821       log_it ("Dev is gone. I can't delete it. Ho-hum");
    822       return;
    823     }
    824     }
    825   memcpy ((void *) &mountlist->el[currline],
    826       (void *) &mountlist->el[mountlist->entries - 1],
    827       sizeof (struct mountlist_line));
    828   mountlist->entries--;
    829   redraw_mountlist (mountlist, keylist, listbox);
     760    assert(mountlist != NULL);
     761    assert(raidlist != NULL);
     762    assert(listbox != NULL);
     763    assert(keylist != NULL);
     764
     765    pos =
     766        which_raid_device_is_using_this_partition(raidlist,
     767                                                  mountlist->el[currline].
     768                                                  device);
     769    if (pos >= 0) {
     770        sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s",
     771                mountlist->el[currline].device,
     772                raidlist->el[pos].OSSWAP(raid_device, volname));
     773        popup_and_OK(tmp);
     774        return;
     775    }
     776    sprintf(tmp, "Delete %s - are you sure?",
     777            mountlist->el[currline].device);
     778    if (!ask_me_yes_or_no(tmp)) {
     779        return;
     780    }
     781    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     782        strcpy(device, mountlist->el[currline].device);
     783        delete_raidlist_entry(mountlist, raidlist, device);
     784        for (currline = 0;
     785             currline < mountlist->entries
     786             && strcmp(mountlist->el[currline].device, device);
     787             currline++);
     788        if (currline == mountlist->entries) {
     789            log_it("Dev is gone. I can't delete it. Ho-hum");
     790            return;
     791        }
     792    }
     793    memcpy((void *) &mountlist->el[currline],
     794           (void *) &mountlist->el[mountlist->entries - 1],
     795           sizeof(struct mountlist_line));
     796    mountlist->entries--;
     797    redraw_mountlist(mountlist, keylist, listbox);
    830798}
    831799
     
    839807 */
    840808void
    841 delete_raidlist_entry (struct mountlist_itself *mountlist,
    842                struct raidlist_itself *raidlist, char *device)
    843 {
    844    
     809delete_raidlist_entry(struct mountlist_itself *mountlist,
     810                      struct raidlist_itself *raidlist, char *device)
     811{
     812
    845813    /** int ***************************************************************/
    846   int i = 0;
    847     int items =0;
     814    int i = 0;
     815    int items = 0;
    848816
    849817    /** bool **************************************************************/
    850   bool delete_partitions_too;
     818    bool delete_partitions_too;
    851819
    852820    /** buffers ***********************************************************/
    853   char tmp[MAX_STR_LEN];
    854 
    855   assert(mountlist!=NULL);
    856   assert(raidlist!=NULL);
    857   assert_string_is_neither_NULL_nor_zerolength(device);
    858 
    859   i = find_raid_device_in_raidlist (raidlist, device);
    860   if (i < 0)
    861     {
    862       return;
    863     }
    864   sprintf (tmp, "Do you want me to delete %s's partitions, too?", device);
    865   delete_partitions_too = ask_me_yes_or_no (tmp);
    866   if (delete_partitions_too)
    867     {
     821    char tmp[MAX_STR_LEN];
     822
     823    assert(mountlist != NULL);
     824    assert(raidlist != NULL);
     825    assert_string_is_neither_NULL_nor_zerolength(device);
     826
     827    i = find_raid_device_in_raidlist(raidlist, device);
     828    if (i < 0) {
     829        return;
     830    }
     831    sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
     832    delete_partitions_too = ask_me_yes_or_no(tmp);
     833    if (delete_partitions_too) {
    868834#ifdef __FreeBSD__
    869       // static so it's zeroed
    870       static struct list_of_disks d;
    871       int x, y, z;
    872      
    873       for (x = 0; x < raidlist->el[i].plexes; ++x) {
    874           for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) {
    875           for (z = 0; z < raidlist->disks.entries; ++z) {
    876               if (!strcmp (raidlist->el[i].plex[x].sd[y].which_device,
    877                    raidlist->disks.el[z].name)) {
    878               strcpy (d.el [d.entries  ].name, raidlist->disks.el[z].name);
    879               strcpy (d.el [d.entries++].device, raidlist->disks.el[z].device);
    880               }
    881           }
    882           }
    883       }
    884      
    885       del_partns_listed_in_disklist (mountlist, raidlist, &d);
     835        // static so it's zeroed
     836        static struct list_of_disks d;
     837        int x, y, z;
     838
     839        for (x = 0; x < raidlist->el[i].plexes; ++x) {
     840            for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) {
     841                for (z = 0; z < raidlist->disks.entries; ++z) {
     842                    if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device,
     843                                raidlist->disks.el[z].name)) {
     844                        strcpy(d.el[d.entries].name,
     845                               raidlist->disks.el[z].name);
     846                        strcpy(d.el[d.entries++].device,
     847                               raidlist->disks.el[z].device);
     848                    }
     849                }
     850            }
     851        }
     852
     853        del_partns_listed_in_disklist(mountlist, raidlist, &d);
    886854#else
    887       del_partns_listed_in_disklist (mountlist, raidlist,
    888                      &raidlist->el[i].data_disks);
    889       del_partns_listed_in_disklist (mountlist, raidlist,
    890                      &raidlist->el[i].spare_disks);
    891       del_partns_listed_in_disklist (mountlist, raidlist,
    892                      &raidlist->el[i].parity_disks);
    893       del_partns_listed_in_disklist (mountlist, raidlist,
    894                      &raidlist->el[i].failed_disks);
     855        del_partns_listed_in_disklist(mountlist, raidlist,
     856                                      &raidlist->el[i].data_disks);
     857        del_partns_listed_in_disklist(mountlist, raidlist,
     858                                      &raidlist->el[i].spare_disks);
     859        del_partns_listed_in_disklist(mountlist, raidlist,
     860                                      &raidlist->el[i].parity_disks);
     861        del_partns_listed_in_disklist(mountlist, raidlist,
     862                                      &raidlist->el[i].failed_disks);
    895863#endif
    896     }
    897   items = raidlist->entries;
    898   if (items == 1)
    899     {
    900       items = 0;
    901     }
    902   else
    903     {
    904       log_it (tmp);
    905       memcpy ((void *) &raidlist->el[i], (void *) &raidlist->el[items - 1],
    906           sizeof (struct OSSWAP(raid_device_record, vinum_volume)));
    907       items--;
    908     }
    909   raidlist->entries = items;
     864    }
     865    items = raidlist->entries;
     866    if (items == 1) {
     867        items = 0;
     868    } else {
     869        log_it(tmp);
     870        memcpy((void *) &raidlist->el[i],
     871               (void *) &raidlist->el[items - 1],
     872               sizeof(struct OSSWAP (raid_device_record, vinum_volume)));
     873        items--;
     874    }
     875    raidlist->entries = items;
    910876}
    911877
     
    918884 * @ingroup restoreGuiVarslist
    919885 */
    920 void
    921 delete_varslist_entry (struct raid_device_record *raidrec, int lino)
     886void delete_varslist_entry(struct raid_device_record *raidrec, int lino)
    922887{
    923888
    924889    /** buffers ************************************************************/
    925   char tmp[MAX_STR_LEN];
     890    char tmp[MAX_STR_LEN];
    926891
    927892    /** structures *********************************************************/
    928   struct additional_raid_variables *av;
    929 
    930   assert(raidrec!=NULL);
    931 
    932   av = &raidrec->additional_vars;
    933   sprintf (tmp, "Delete %s - are you sure?", av->el[lino].label);
    934   if (ask_me_yes_or_no (tmp))
    935     {
    936       if (!strcmp (av->el[lino].label, "persistent-superblock")
    937       || !strcmp (av->el[lino].label, "chunk-size"))
    938     {
    939       sprintf (tmp, "%s must not be deleted. It would be bad.",
    940            av->el[lino].label);
    941       popup_and_OK (tmp);
    942     }
    943       else
    944     {
    945       memcpy ((void *) &av->el[lino], (void *) &av->el[av->entries--],
    946           sizeof (struct raid_var_line));
    947     }
    948     }
     893    struct additional_raid_variables *av;
     894
     895    assert(raidrec != NULL);
     896
     897    av = &raidrec->additional_vars;
     898    sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
     899    if (ask_me_yes_or_no(tmp)) {
     900        if (!strcmp(av->el[lino].label, "persistent-superblock")
     901            || !strcmp(av->el[lino].label, "chunk-size")) {
     902            sprintf(tmp, "%s must not be deleted. It would be bad.",
     903                    av->el[lino].label);
     904            popup_and_OK(tmp);
     905        } else {
     906            memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--],
     907                   sizeof(struct raid_var_line));
     908        }
     909    }
    949910}
    950911#endif
     
    960921 */
    961922int
    962 redraw_filelist (struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM],
    963          newtComponent listbox)
     923redraw_filelist(struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM],
     924                newtComponent listbox)
    964925{
    965926
    966927    /** int ***************************************************************/
    967   static int lines_in_flist_window = 0;
    968   static int depth = 0;
    969   int i = 0;
     928    static int lines_in_flist_window = 0;
     929    static int depth = 0;
     930    int i = 0;
    970931
    971932    /** structures *******************************************************/
    972   struct s_node *node;
     933    struct s_node *node;
    973934
    974935    /** buffers **********************************************************/
    975   static char current_filename[MAX_STR_LEN];
    976   char tmp[MAX_STR_LEN + 2];
     936    static char current_filename[MAX_STR_LEN];
     937    char tmp[MAX_STR_LEN + 2];
    977938
    978939    /** bool *************************************************************/
    979940    /*  void*dummyptr; */
    980   bool dummybool;
    981   static bool warned_already;
    982 
    983   assert(filelist!=NULL);
    984   assert(keylist!=NULL);
    985   assert(listbox!=NULL);
    986 
    987 
    988   if (depth == 0)
    989     {
    990       lines_in_flist_window = 0;
    991       warned_already = FALSE;
    992       for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    993     {
    994       g_strings_of_flist_window[i][0] = '\0';
    995       g_is_path_selected[i] = FALSE;
    996     }
    997     }
    998   for (node = filelist; node != NULL; node = node->right)
    999     {
    1000       current_filename[depth] = node->ch;
    1001       if (node->down)
    1002     {
    1003       depth++;
    1004       i = redraw_filelist (node->down, keylist, listbox);
    1005       depth--;
    1006     }
    1007       if (node->ch == '\0' && node->expanded)
    1008     {
    1009       if (lines_in_flist_window == ARBITRARY_MAXIMUM)
    1010         {
    1011           if (!warned_already)
    1012         {
    1013           warned_already = TRUE;
    1014           sprintf (tmp,
    1015                "Too many lines. Displaying first %d entries only. Close a directory to see more.",
    1016                ARBITRARY_MAXIMUM);
    1017           popup_and_OK (tmp);
    1018         }
    1019         }
    1020       else
    1021         {
    1022           strcpy (g_strings_of_flist_window[lines_in_flist_window],
    1023               current_filename);
    1024           g_is_path_selected[lines_in_flist_window] = node->selected;
    1025           lines_in_flist_window++;
    1026         }
    1027     }
    1028     }
    1029   if (depth == 0)
    1030     {
    1031       if (lines_in_flist_window > ARBITRARY_MAXIMUM)
    1032     {
    1033       lines_in_flist_window = ARBITRARY_MAXIMUM;
    1034     }
     941    bool dummybool;
     942    static bool warned_already;
     943
     944    assert(filelist != NULL);
     945    assert(keylist != NULL);
     946    assert(listbox != NULL);
     947
     948
     949    if (depth == 0) {
     950        lines_in_flist_window = 0;
     951        warned_already = FALSE;
     952        for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     953            g_strings_of_flist_window[i][0] = '\0';
     954            g_is_path_selected[i] = FALSE;
     955        }
     956    }
     957    for (node = filelist; node != NULL; node = node->right) {
     958        current_filename[depth] = node->ch;
     959        if (node->down) {
     960            depth++;
     961            i = redraw_filelist(node->down, keylist, listbox);
     962            depth--;
     963        }
     964        if (node->ch == '\0' && node->expanded) {
     965            if (lines_in_flist_window == ARBITRARY_MAXIMUM) {
     966                if (!warned_already) {
     967                    warned_already = TRUE;
     968                    sprintf(tmp,
     969                            "Too many lines. Displaying first %d entries only. Close a directory to see more.",
     970                            ARBITRARY_MAXIMUM);
     971                    popup_and_OK(tmp);
     972                }
     973            } else {
     974                strcpy(g_strings_of_flist_window[lines_in_flist_window],
     975                       current_filename);
     976                g_is_path_selected[lines_in_flist_window] = node->selected;
     977                lines_in_flist_window++;
     978            }
     979        }
     980    }
     981    if (depth == 0) {
     982        if (lines_in_flist_window > ARBITRARY_MAXIMUM) {
     983            lines_in_flist_window = ARBITRARY_MAXIMUM;
     984        }
    1035985/* do an elementary sort */
    1036       for (i = 1; i < lines_in_flist_window; i++)
    1037     {
    1038       if (strcmp
    1039           (g_strings_of_flist_window[i],
    1040            g_strings_of_flist_window[i - 1]) < 0)
    1041         {
    1042           strcpy (tmp, g_strings_of_flist_window[i]);
    1043           strcpy (g_strings_of_flist_window[i],
    1044               g_strings_of_flist_window[i - 1]);
    1045           strcpy (g_strings_of_flist_window[i - 1], tmp);
    1046           dummybool = g_is_path_selected[i];
    1047           g_is_path_selected[i] = g_is_path_selected[i - 1];
    1048           g_is_path_selected[i - 1] = dummybool;
    1049           i = 0;
    1050         }
    1051     }
     986        for (i = 1; i < lines_in_flist_window; i++) {
     987            if (strcmp
     988                (g_strings_of_flist_window[i],
     989                 g_strings_of_flist_window[i - 1]) < 0) {
     990                strcpy(tmp, g_strings_of_flist_window[i]);
     991                strcpy(g_strings_of_flist_window[i],
     992                       g_strings_of_flist_window[i - 1]);
     993                strcpy(g_strings_of_flist_window[i - 1], tmp);
     994                dummybool = g_is_path_selected[i];
     995                g_is_path_selected[i] = g_is_path_selected[i - 1];
     996                g_is_path_selected[i - 1] = dummybool;
     997                i = 0;
     998            }
     999        }
    10521000/* write list to screen */
    1053       newtListboxClear (listbox);
    1054       for (i = 0; i < lines_in_flist_window; i++)
    1055     {
    1056       sprintf (tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '),
    1057            (g_is_path_expanded[i] ? '+' : '-'),
    1058            strip_path(g_strings_of_flist_window[i]));
    1059       tmp[70] = '\0';
    1060       keylist[i] = (void *) i;
    1061       newtListboxAppendEntry (listbox, tmp, keylist[i]);
    1062     }
    1063       return (lines_in_flist_window);
    1064     }
    1065   else
    1066     {
    1067       return (0);
    1068     }
     1001        newtListboxClear(listbox);
     1002        for (i = 0; i < lines_in_flist_window; i++) {
     1003            sprintf(tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '),
     1004                    (g_is_path_expanded[i] ? '+' : '-'),
     1005                    strip_path(g_strings_of_flist_window[i]));
     1006            tmp[70] = '\0';
     1007            keylist[i] = (void *) i;
     1008            newtListboxAppendEntry(listbox, tmp, keylist[i]);
     1009        }
     1010        return (lines_in_flist_window);
     1011    } else {
     1012        return (0);
     1013    }
    10691014}
    10701015
     
    10771022 * @ingroup restoreUtilityGroup
    10781023 */
    1079 char *strip_path(char *tmp) 
     1024char *strip_path(char *tmp)
    10801025{
    10811026
     
    10831028    int slashloc = 0, lastslashloc = 0;
    10841029
    1085     while(tmp[i] != '\0')
    1086     { /* Count the slashes in tmp
    1087          1 slash per dir */
    1088       if( tmp[i] == '/')
    1089       {
    1090         slashcount++;
    1091         lastslashloc = slashloc;
    1092         slashloc = i;
    1093         if(tmp[i + 1] == '\0')
    1094         { /* if this slash is last char, back off */
    1095           slashcount--;
    1096           slashloc = lastslashloc;
    1097         }
    1098       }
    1099       i++;
    1100     }
    1101     if(slashcount > 0) slashcount--; /* Keep one slash 'cos Hugh does... */
    1102 
    1103     for(i=0; i<slashcount; i++)
    1104     { /* Replace each dir with a space char */
    1105       tmpnopath[i] = ' ';
     1030    while (tmp[i] != '\0') {    /* Count the slashes in tmp
     1031                                   1 slash per dir */
     1032        if (tmp[i] == '/') {
     1033            slashcount++;
     1034            lastslashloc = slashloc;
     1035            slashloc = i;
     1036            if (tmp[i + 1] == '\0') {   /* if this slash is last char, back off */
     1037                slashcount--;
     1038                slashloc = lastslashloc;
     1039            }
     1040        }
     1041        i++;
     1042    }
     1043    if (slashcount > 0)
     1044        slashcount--;           /* Keep one slash 'cos Hugh does... */
     1045
     1046    for (i = 0; i < slashcount; i++) {  /* Replace each dir with a space char */
     1047        tmpnopath[i] = ' ';
    11061048    }
    11071049
    11081050    i = slashloc;
    11091051    j = slashcount;
    1110     while(tmp[i] != '\0')
    1111     { /* Now add what's left of tmp */
    1112       if( (tmpprevpath[j] == ' ' || tmpprevpath[j] == '^')
    1113           && tmp[i] == '/'
    1114           && tmpnopath[j - 1] != '^'
    1115           && j != 0)
    1116       { /* Add a pointer upwards if this is not in the same dir as line above */
    1117           tmpnopath[j - 1] = '^';
    1118       } else {
    1119         tmpnopath[j++] = tmp[i++];
    1120       }
     1052    while (tmp[i] != '\0') {    /* Now add what's left of tmp */
     1053        if ((tmpprevpath[j] == ' ' || tmpprevpath[j] == '^')
     1054            && tmp[i] == '/' && tmpnopath[j - 1] != '^' && j != 0) {    /* Add a pointer upwards if this is not in the same dir as line above */
     1055            tmpnopath[j - 1] = '^';
     1056        } else {
     1057            tmpnopath[j++] = tmp[i++];
     1058        }
    11211059    }
    11221060    tmpnopath[j] = '\0';
    11231061
    1124     strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */
    1125    
    1126     return(tmpnopath);
     1062    strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */
     1063
     1064    return (tmpnopath);
    11271065}
    11281066
     
    11331071 * @return 0 if the user pressed OK, 1 if they pressed Cancel.
    11341072 */
    1135 int
    1136 edit_filelist (struct s_node *filelist)
     1073int edit_filelist(struct s_node *filelist)
    11371074{
    11381075
    11391076    /** newt **************************************************************/
    1140   newtComponent myForm;
    1141     newtComponent bLess=NULL;
    1142     newtComponent bMore=NULL;
    1143     newtComponent bToggle=NULL;
    1144     newtComponent bOK=NULL;
    1145     newtComponent bCancel=NULL;
    1146     newtComponent b_res=NULL;
    1147     newtComponent filelistListbox=NULL;
    1148     newtComponent bRegex=NULL;
     1077    newtComponent myForm;
     1078    newtComponent bLess = NULL;
     1079    newtComponent bMore = NULL;
     1080    newtComponent bToggle = NULL;
     1081    newtComponent bOK = NULL;
     1082    newtComponent bCancel = NULL;
     1083    newtComponent b_res = NULL;
     1084    newtComponent filelistListbox = NULL;
     1085    newtComponent bRegex = NULL;
    11491086
    11501087    /** int ***************************************************************/
     
    11551092
    11561093    /** ???? **************************************************************/
    1157   void *curr_choice;
    1158   void *keylist[ARBITRARY_MAXIMUM];
     1094    void *curr_choice;
     1095    void *keylist[ARBITRARY_MAXIMUM];
    11591096
    11601097    /** buffers ***********************************************************/
    1161   char tmp[MAX_STR_LEN];
     1098    char tmp[MAX_STR_LEN];
    11621099
    11631100    /** bool **************************************************************/
    1164   bool dummybool;
     1101    bool dummybool;
    11651102
    11661103/*  struct s_node *node; */
    11671104
    1168   assert(filelist!=NULL);
    1169 
    1170   log_to_screen ("Editing filelist");
    1171   newtPushHelpLine
    1172     ("   Please edit the filelist to your satisfaction, then click OK or Cancel.");
    1173   j = 4;
    1174   bLess = newtCompactButton (j, 17, " Less ");
    1175   bMore = newtCompactButton (j += 12, 17, " More ");
    1176   bToggle = newtCompactButton (j += 12, 17, "Toggle");
    1177   bRegex = newtCompactButton (j += 12, 17, "RegEx");
    1178   bCancel = newtCompactButton (j += 12, 17, "Cancel");
    1179   bOK = newtCompactButton (j += 12, 17, "  OK  ");
    1180   filelistListbox =
    1181     newtListbox (2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1182   toggle_all_root_dirs_on (filelist);
    1183   lines_in_flist_window =
    1184     redraw_filelist (filelist, keylist, filelistListbox);
    1185   newtOpenWindow (1, 3, 77, 18, "Editing filelist");
    1186   myForm = newtForm (NULL, NULL, 0);
    1187   newtFormAddComponents (myForm, filelistListbox, bLess, bMore, bToggle,
    1188              bRegex, bCancel, bOK, NULL);
    1189   while (!finished)
    1190     {
    1191       b_res = newtRunForm (myForm);
    1192       if (b_res == bOK)
    1193     {
    1194       finished =
    1195         ask_me_yes_or_no ("Are you happy with your file selection?");
    1196     }
    1197       else if (b_res == bCancel)
    1198     {
    1199       finished = TRUE;
    1200     }
    1201       else if (b_res == bRegex)
    1202     {
    1203       popup_and_OK ("I haven't implemented this yet...");
    1204     }
    1205       else
    1206     {
    1207       curr_choice = newtListboxGetCurrent (filelistListbox);
    1208       for (indexno = 0;
    1209            indexno < lines_in_flist_window
    1210            && keylist[indexno] != curr_choice; indexno++);
    1211       if (indexno == lines_in_flist_window)
    1212         {
    1213           log_it
    1214         ("I don't know what this button does; assuming I am to toggle 1st entry");
    1215           indexno = 0;
    1216         }
    1217       sprintf (tmp, "You selected '%s'",
    1218            g_strings_of_flist_window[indexno]);
    1219       log_it (tmp);
    1220       if (b_res == bMore)
    1221         {
    1222           g_is_path_expanded[indexno] = TRUE;
    1223           toggle_path_expandability (filelist,
    1224                      g_strings_of_flist_window[indexno],
    1225                      TRUE);
    1226           lines_in_flist_window =
    1227         redraw_filelist (filelist, keylist, filelistListbox);
    1228           newtListboxSetCurrentByKey (filelistListbox, curr_choice);
    1229         }
    1230       else if (b_res == bLess)
    1231         {
    1232           g_is_path_expanded[indexno] = FALSE;
    1233           toggle_path_expandability (filelist,
    1234                      g_strings_of_flist_window[indexno],
    1235                      FALSE);
    1236           lines_in_flist_window =
    1237         redraw_filelist (filelist, keylist, filelistListbox);
    1238           newtListboxSetCurrentByKey (filelistListbox, curr_choice);
    1239         }
    1240       else
    1241         {
    1242           if (!strcmp (g_strings_of_flist_window[indexno], "/"))
    1243         {
    1244           dummybool = !g_is_path_selected[indexno];
    1245           for (j = 1; j < lines_in_flist_window; j++)
    1246             {
    1247               toggle_path_selection (filelist,
    1248                          g_strings_of_flist_window[j],
    1249                          dummybool);
    1250             }
    1251         }
    1252           else
    1253         {
    1254           toggle_path_selection (filelist,
    1255                      g_strings_of_flist_window[indexno],
    1256                      !g_is_path_selected[indexno]);
    1257           lines_in_flist_window =
    1258             redraw_filelist (filelist, keylist, filelistListbox);
    1259         }
    1260           newtListboxSetCurrentByKey (filelistListbox, curr_choice);
    1261         }
    1262       for (indexno = 0;
    1263            indexno < lines_in_flist_window
    1264            && keylist[indexno] != curr_choice; indexno++);
    1265       if (indexno == lines_in_flist_window)
    1266         {
    1267           log_it
    1268         ("Layout of table has changed. Y pointer is reverting to zero.");
    1269           indexno = 0;
    1270         }
    1271     }
    1272     }
    1273   newtFormDestroy (myForm);
    1274   newtPopWindow ();
    1275   newtPopHelpLine ();
    1276   if (b_res == bOK)
    1277     {
    1278       return (0);
    1279     }
    1280   else
    1281     {
     1105    assert(filelist != NULL);
     1106
     1107    log_to_screen("Editing filelist");
     1108    newtPushHelpLine
     1109        ("   Please edit the filelist to your satisfaction, then click OK or Cancel.");
     1110    j = 4;
     1111    bLess = newtCompactButton(j, 17, " Less ");
     1112    bMore = newtCompactButton(j += 12, 17, " More ");
     1113    bToggle = newtCompactButton(j += 12, 17, "Toggle");
     1114    bRegex = newtCompactButton(j += 12, 17, "RegEx");
     1115    bCancel = newtCompactButton(j += 12, 17, "Cancel");
     1116    bOK = newtCompactButton(j += 12, 17, "  OK  ");
     1117    filelistListbox =
     1118        newtListbox(2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1119    toggle_all_root_dirs_on(filelist);
     1120    lines_in_flist_window =
     1121        redraw_filelist(filelist, keylist, filelistListbox);
     1122    newtOpenWindow(1, 3, 77, 18, "Editing filelist");
     1123    myForm = newtForm(NULL, NULL, 0);
     1124    newtFormAddComponents(myForm, filelistListbox, bLess, bMore, bToggle,
     1125                          bRegex, bCancel, bOK, NULL);
     1126    while (!finished) {
     1127        b_res = newtRunForm(myForm);
     1128        if (b_res == bOK) {
     1129            finished =
     1130                ask_me_yes_or_no
     1131                ("Are you happy with your file selection?");
     1132        } else if (b_res == bCancel) {
     1133            finished = TRUE;
     1134        } else if (b_res == bRegex) {
     1135            popup_and_OK("I haven't implemented this yet...");
     1136        } else {
     1137            curr_choice = newtListboxGetCurrent(filelistListbox);
     1138            for (indexno = 0;
     1139                 indexno < lines_in_flist_window
     1140                 && keylist[indexno] != curr_choice; indexno++);
     1141            if (indexno == lines_in_flist_window) {
     1142                log_it
     1143                    ("I don't know what this button does; assuming I am to toggle 1st entry");
     1144                indexno = 0;
     1145            }
     1146            sprintf(tmp, "You selected '%s'",
     1147                    g_strings_of_flist_window[indexno]);
     1148            log_it(tmp);
     1149            if (b_res == bMore) {
     1150                g_is_path_expanded[indexno] = TRUE;
     1151                toggle_path_expandability(filelist,
     1152                                          g_strings_of_flist_window
     1153                                          [indexno], TRUE);
     1154                lines_in_flist_window =
     1155                    redraw_filelist(filelist, keylist, filelistListbox);
     1156                newtListboxSetCurrentByKey(filelistListbox, curr_choice);
     1157            } else if (b_res == bLess) {
     1158                g_is_path_expanded[indexno] = FALSE;
     1159                toggle_path_expandability(filelist,
     1160                                          g_strings_of_flist_window
     1161                                          [indexno], FALSE);
     1162                lines_in_flist_window =
     1163                    redraw_filelist(filelist, keylist, filelistListbox);
     1164                newtListboxSetCurrentByKey(filelistListbox, curr_choice);
     1165            } else {
     1166                if (!strcmp(g_strings_of_flist_window[indexno], "/")) {
     1167                    dummybool = !g_is_path_selected[indexno];
     1168                    for (j = 1; j < lines_in_flist_window; j++) {
     1169                        toggle_path_selection(filelist,
     1170                                              g_strings_of_flist_window[j],
     1171                                              dummybool);
     1172                    }
     1173                } else {
     1174                    toggle_path_selection(filelist,
     1175                                          g_strings_of_flist_window
     1176                                          [indexno],
     1177                                          !g_is_path_selected[indexno]);
     1178                    lines_in_flist_window =
     1179                        redraw_filelist(filelist, keylist,
     1180                                        filelistListbox);
     1181                }
     1182                newtListboxSetCurrentByKey(filelistListbox, curr_choice);
     1183            }
     1184            for (indexno = 0;
     1185                 indexno < lines_in_flist_window
     1186                 && keylist[indexno] != curr_choice; indexno++);
     1187            if (indexno == lines_in_flist_window) {
     1188                log_it
     1189                    ("Layout of table has changed. Y pointer is reverting to zero.");
     1190                indexno = 0;
     1191            }
     1192        }
     1193    }
     1194    newtFormDestroy(myForm);
     1195    newtPopWindow();
     1196    newtPopHelpLine();
     1197    if (b_res == bOK) {
     1198        return (0);
     1199    } else {
    12821200/*    popup_and_OK("You pushed 'cancel'. I shall now abort."); */
    1283       return (1);
    1284     }
     1201        return (1);
     1202    }
    12851203}
    12861204
     
    12961214 */
    12971215void
    1298 edit_mountlist_entry (struct mountlist_itself *mountlist,
    1299               struct raidlist_itself *raidlist, newtComponent listbox,
    1300               int currline, void *keylist[])
     1216edit_mountlist_entry(struct mountlist_itself *mountlist,
     1217                     struct raidlist_itself *raidlist,
     1218                     newtComponent listbox, int currline, void *keylist[])
    13011219{
    13021220
    13031221    /** structures ********************************************************/
    1304   static struct raidlist_itself bkp_raidlist;
     1222    static struct raidlist_itself bkp_raidlist;
    13051223
    13061224    /** newt **************************************************************/
    1307   newtComponent myForm;
     1225    newtComponent myForm;
    13081226    newtComponent bOK;
    13091227    newtComponent bCancel;
     
    13241242    char size_str[MAX_STR_LEN];
    13251243    char format_str[MAX_STR_LEN];
    1326   char tmp[MAX_STR_LEN];
    1327   char device_used_to_be[MAX_STR_LEN];
     1244    char tmp[MAX_STR_LEN];
     1245    char device_used_to_be[MAX_STR_LEN];
    13281246    char mountpt_used_to_be[MAX_STR_LEN];
    13291247
     
    13351253
    13361254    /** int ***************************************************************/
    1337   int j = 0;
    1338 
    1339   assert(mountlist!=NULL);
    1340   assert(raidlist!=NULL);
    1341   assert(listbox!=NULL);
    1342   assert(keylist!=NULL);
    1343 
    1344   memcpy ((void *) &bkp_raidlist, (void *) raidlist,
    1345       sizeof (struct raidlist_itself));
    1346   strcpy (device_str, mountlist->el[currline].device);
    1347   strcpy (device_used_to_be, mountlist->el[currline].device);
    1348   strcpy (mountpoint_str, mountlist->el[currline].mountpoint);
    1349   strcpy (mountpt_used_to_be, mountlist->el[currline].mountpoint);
    1350   strcpy (format_str, mountlist->el[currline].format);
    1351   sprintf (size_str, "%lld", mountlist->el[currline].size / 1024);
    1352   newtOpenWindow (20, 5, 48, 10, "Edit entry");
    1353   label0 = newtLabel (2, 1, "Device:");
    1354   label1 = newtLabel (2, 2, "Mountpoint:");
    1355   label2 = newtLabel (2, 3, "Size (MB): ");
    1356   label3 = newtLabel (2, 4, "Format:    ");
    1357   deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0);
    1358   mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0);
    1359   formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0);
    1360   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1361       || !strcmp (mountlist->el[currline].mountpoint, "image"))
    1362     {
    1363       sizeComp = newtLabel (14, 3, size_str);
    1364     }
    1365   else
    1366     {
    1367       sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0);
    1368     }
    1369   bOK = newtButton (2, 6, "  OK  ");
    1370   bCancel = newtButton (14, 6, "Cancel");
    1371   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB))
    1372     {
    1373       b_raid = newtButton (26, 6, "RAID..");
    1374     }
    1375   newtPushHelpLine
    1376     ("       Edit this partition's mountpoint, size and format; then click 'OK'.");
    1377   myForm = newtForm (NULL, NULL, 0);
    1378   newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp,
    1379              formatComp, label0, label1, label2, label3, bOK,
    1380              bCancel, b_raid, NULL);
    1381   for (b_res = NULL; b_res != bOK && b_res != bCancel;)
    1382     {
    1383       b_res = newtRunForm (myForm);
    1384       strcpy (device_str, device_here);
    1385       strip_spaces (device_str);
    1386       strcpy (mountpoint_str, mountpoint_here);
    1387       strip_spaces (mountpoint_str);
    1388       strcpy (format_str, format_here);
    1389       strip_spaces (format_str);
    1390       if (b_res == bOK && strstr (device_str, RAID_DEVICE_STUB)
    1391       && strstr (device_used_to_be, RAID_DEVICE_STUB)
    1392       && strcmp (device_str, device_used_to_be))
    1393     {
    1394       popup_and_OK ("You can't change /dev/mdX to /dev/mdY.");
    1395       b_res = NULL;
    1396       continue;
    1397     }
    1398       else if (b_res == bOK && !strcmp (mountpoint_str, "image")
    1399            && strcmp (mountpt_used_to_be, "image"))
    1400     {
    1401       popup_and_OK ("You can't change a regular device to an image.");
    1402       b_res = NULL;
    1403       continue;
    1404     }
    1405       if (!strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1406       && strcmp (mountlist->el[currline].mountpoint, "image"))
    1407     {
    1408       strcpy (size_str, size_here);
    1409       strip_spaces (size_str);
    1410     }
    1411       else
    1412     {
    1413       sprintf (size_str, "%ld",
    1414            calculate_raid_device_size (mountlist, raidlist,
    1415                            mountlist->el[currline].
    1416                            device) / 1024);
    1417       newtLabelSetText (sizeComp, size_str);
    1418     }
    1419       /* do not let user click RAID button if user has changed device_str */
    1420       if (b_res == b_raid)
    1421     {
    1422       if (strcmp (device_str, mountlist->el[currline].device))
    1423         {
    1424           /*
    1425              can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly
    1426              when you try to map the changes over to the raidtab list, trust me
    1427            */
    1428           popup_and_OK
    1429         ("You cannot edit the RAID settings until you have OK'd your change to the device node.");
    1430         }
    1431       else
    1432         {
    1433           j =
    1434         find_raid_device_in_raidlist (raidlist,
    1435                           mountlist->el[currline].device);
    1436           if (j < 0)
    1437         {
    1438           sprintf (tmp,
    1439                "/etc/raidtab does not have an entry for %s; please delete it and add it again",
    1440                mountlist->el[currline].device);
    1441           popup_and_OK (tmp);
    1442         }
    1443           else
    1444         {
    1445           log_it ("edit_raidlist_entry - calling");
    1446           edit_raidlist_entry (mountlist, raidlist, &raidlist->el[j],
    1447                        currline);
    1448         }
    1449         }
    1450     }
    1451     }
    1452   newtFormDestroy (myForm);
    1453   newtPopHelpLine ();
    1454   newtPopWindow ();
    1455   if (b_res == bCancel)
    1456     {
    1457       memcpy ((void *) raidlist, (void *) &bkp_raidlist,
    1458           sizeof (struct raidlist_itself));
    1459       return;
    1460     }
    1461   strcpy (mountlist->el[currline].device, device_str);
    1462   strcpy (mountlist->el[currline].mountpoint, mountpoint_str);
    1463   strcpy (mountlist->el[currline].format, format_str);
    1464   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1465       || !strcmp (mountlist->el[currline].mountpoint, "image"))
    1466     {
    1467       mountlist->el[currline].size =
    1468     calculate_raid_device_size (mountlist, raidlist,
    1469                     mountlist->el[currline].device);
    1470     }
    1471   else
    1472     {
    1473       mountlist->el[currline].size = atol (size_str) * 1024;
    1474     }
    1475   newtListboxSetEntry (listbox, (int) keylist[currline],
    1476                mountlist_entry_to_string (mountlist, currline));
    1477   /* if new /dev/md RAID device then do funky stuff */
    1478   if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)
    1479       && !strstr (device_used_to_be, RAID_DEVICE_STUB))
    1480     {
    1481       initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str);
    1482     }
    1483   /* if moving from RAID to non-RAID then do funky stuff */
    1484   else if (strstr (device_used_to_be, RAID_DEVICE_STUB)
    1485        && !strstr (device_str, RAID_DEVICE_STUB))
    1486     {
    1487       delete_raidlist_entry (mountlist, raidlist, device_str);
    1488     }
    1489   /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */
    1490   else if (!strstr (device_used_to_be, RAID_DEVICE_STUB)
    1491        && !strstr (device_str, RAID_DEVICE_STUB))
    1492     {
    1493       rejig_partition_name_in_raidlist_if_necessary (raidlist,
    1494                              device_used_to_be,
    1495                              device_str);
    1496     }
     1255    int j = 0;
     1256
     1257    assert(mountlist != NULL);
     1258    assert(raidlist != NULL);
     1259    assert(listbox != NULL);
     1260    assert(keylist != NULL);
     1261
     1262    memcpy((void *) &bkp_raidlist, (void *) raidlist,
     1263           sizeof(struct raidlist_itself));
     1264    strcpy(device_str, mountlist->el[currline].device);
     1265    strcpy(device_used_to_be, mountlist->el[currline].device);
     1266    strcpy(mountpoint_str, mountlist->el[currline].mountpoint);
     1267    strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);
     1268    strcpy(format_str, mountlist->el[currline].format);
     1269    sprintf(size_str, "%lld", mountlist->el[currline].size / 1024);
     1270    newtOpenWindow(20, 5, 48, 10, "Edit entry");
     1271    label0 = newtLabel(2, 1, "Device:");
     1272    label1 = newtLabel(2, 2, "Mountpoint:");
     1273    label2 = newtLabel(2, 3, "Size (MB): ");
     1274    label3 = newtLabel(2, 4, "Format:    ");
     1275    deviceComp =
     1276        newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     1277    mountpointComp =
     1278        newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     1279    formatComp =
     1280        newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     1281    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1282        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     1283        sizeComp = newtLabel(14, 3, size_str);
     1284    } else {
     1285        sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
     1286    }
     1287    bOK = newtButton(2, 6, "  OK  ");
     1288    bCancel = newtButton(14, 6, "Cancel");
     1289    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     1290        b_raid = newtButton(26, 6, "RAID..");
     1291    }
     1292    newtPushHelpLine
     1293        ("       Edit this partition's mountpoint, size and format; then click 'OK'.");
     1294    myForm = newtForm(NULL, NULL, 0);
     1295    newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
     1296                          formatComp, label0, label1, label2, label3, bOK,
     1297                          bCancel, b_raid, NULL);
     1298    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
     1299        b_res = newtRunForm(myForm);
     1300        strcpy(device_str, device_here);
     1301        strip_spaces(device_str);
     1302        strcpy(mountpoint_str, mountpoint_here);
     1303        strip_spaces(mountpoint_str);
     1304        strcpy(format_str, format_here);
     1305        strip_spaces(format_str);
     1306        if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
     1307            && strstr(device_used_to_be, RAID_DEVICE_STUB)
     1308            && strcmp(device_str, device_used_to_be)) {
     1309            popup_and_OK("You can't change /dev/mdX to /dev/mdY.");
     1310            b_res = NULL;
     1311            continue;
     1312        } else if (b_res == bOK && !strcmp(mountpoint_str, "image")
     1313                   && strcmp(mountpt_used_to_be, "image")) {
     1314            popup_and_OK("You can't change a regular device to an image.");
     1315            b_res = NULL;
     1316            continue;
     1317        }
     1318        if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1319            && strcmp(mountlist->el[currline].mountpoint, "image")) {
     1320            strcpy(size_str, size_here);
     1321            strip_spaces(size_str);
     1322        } else {
     1323            sprintf(size_str, "%ld",
     1324                    calculate_raid_device_size(mountlist, raidlist,
     1325                                               mountlist->el[currline].
     1326                                               device) / 1024);
     1327            newtLabelSetText(sizeComp, size_str);
     1328        }
     1329        /* do not let user click RAID button if user has changed device_str */
     1330        if (b_res == b_raid) {
     1331            if (strcmp(device_str, mountlist->el[currline].device)) {
     1332                /*
     1333                   can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly
     1334                   when you try to map the changes over to the raidtab list, trust me
     1335                 */
     1336                popup_and_OK
     1337                    ("You cannot edit the RAID settings until you have OK'd your change to the device node.");
     1338            } else {
     1339                j = find_raid_device_in_raidlist(raidlist,
     1340                                                 mountlist->el[currline].
     1341                                                 device);
     1342                if (j < 0) {
     1343                    sprintf(tmp,
     1344                            "/etc/raidtab does not have an entry for %s; please delete it and add it again",
     1345                            mountlist->el[currline].device);
     1346                    popup_and_OK(tmp);
     1347                } else {
     1348                    log_it("edit_raidlist_entry - calling");
     1349                    edit_raidlist_entry(mountlist, raidlist,
     1350                                        &raidlist->el[j], currline);
     1351                }
     1352            }
     1353        }
     1354    }
     1355    newtFormDestroy(myForm);
     1356    newtPopHelpLine();
     1357    newtPopWindow();
     1358    if (b_res == bCancel) {
     1359        memcpy((void *) raidlist, (void *) &bkp_raidlist,
     1360               sizeof(struct raidlist_itself));
     1361        return;
     1362    }
     1363    strcpy(mountlist->el[currline].device, device_str);
     1364    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     1365    strcpy(mountlist->el[currline].format, format_str);
     1366    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1367        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     1368        mountlist->el[currline].size =
     1369            calculate_raid_device_size(mountlist, raidlist,
     1370                                       mountlist->el[currline].device);
     1371    } else {
     1372        mountlist->el[currline].size = atol(size_str) * 1024;
     1373    }
     1374    newtListboxSetEntry(listbox, (int) keylist[currline],
     1375                        mountlist_entry_to_string(mountlist, currline));
     1376    /* if new /dev/md RAID device then do funky stuff */
     1377    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     1378        && !strstr(device_used_to_be, RAID_DEVICE_STUB)) {
     1379        initiate_new_raidlist_entry(raidlist, mountlist, currline,
     1380                                    device_str);
     1381    }
     1382    /* if moving from RAID to non-RAID then do funky stuff */
     1383    else if (strstr(device_used_to_be, RAID_DEVICE_STUB)
     1384             && !strstr(device_str, RAID_DEVICE_STUB)) {
     1385        delete_raidlist_entry(mountlist, raidlist, device_str);
     1386    }
     1387    /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */
     1388    else if (!strstr(device_used_to_be, RAID_DEVICE_STUB)
     1389             && !strstr(device_str, RAID_DEVICE_STUB)) {
     1390        rejig_partition_name_in_raidlist_if_necessary(raidlist,
     1391                                                      device_used_to_be,
     1392                                                      device_str);
     1393    }
    14971394/* else, moving a RAID to another RAID; bad idea, or so I thought */
    1498 #ifndef __FreeBSD__ /* It works fine under FBSD. */
    1499   else if (strcmp (device_used_to_be, device_str))
    1500     {
    1501       popup_and_OK
    1502     ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
    1503     }
     1395#ifndef __FreeBSD__             /* It works fine under FBSD. */
     1396    else if (strcmp(device_used_to_be, device_str)) {
     1397        popup_and_OK
     1398            ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
     1399    }
    15041400#endif
    1505   redraw_mountlist (mountlist, keylist, listbox);
     1401    redraw_mountlist(mountlist, keylist, listbox);
    15061402}
    15071403
     
    15171413 */
    15181414void
    1519 add_raid_subdisk (struct raidlist_itself *raidlist, struct vinum_plex *raidrec, char *temp)
    1520 {
    1521     int i;
    1522     bool found = FALSE;
    1523    
    1524     for (i = 0; i < raidlist->disks.entries; ++i) {
    1525     if (!strcmp (raidlist->disks.el[i].device, temp)) {
    1526         strcpy (raidrec->sd [raidrec->subdisks].which_device,
    1527             raidlist->disks.el[i].name);
    1528         found = TRUE;
    1529     }
    1530     }
    1531     if (!found) {
    1532     sprintf (raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries);
    1533     sprintf (raidrec->sd [raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries);
    1534     strcpy (raidlist->disks.el[raidlist->disks.entries++].device, temp);
    1535     }
    1536     raidrec->subdisks++;
     1415add_raid_subdisk(struct raidlist_itself *raidlist,
     1416                 struct vinum_plex *raidrec, char *temp)
     1417{
     1418    int i;
     1419    bool found = FALSE;
     1420
     1421    for (i = 0; i < raidlist->disks.entries; ++i) {
     1422        if (!strcmp(raidlist->disks.el[i].device, temp)) {
     1423            strcpy(raidrec->sd[raidrec->subdisks].which_device,
     1424                   raidlist->disks.el[i].name);
     1425            found = TRUE;
     1426        }
     1427    }
     1428    if (!found) {
     1429        sprintf(raidlist->disks.el[raidlist->disks.entries].name,
     1430                "drive%i", raidlist->disks.entries);
     1431        sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i",
     1432                raidlist->disks.entries);
     1433        strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp);
     1434    }
     1435    raidrec->subdisks++;
    15371436}
    15381437
     
    15471446 * @ingroup restoreUtilityGroup
    15481447 */
    1549 char *
    1550 find_dev_entry_for_raid_device_name (struct raidlist_itself *raidlist, char *vinum_name)
    1551 {
    1552     int i;
    1553     for (i = 0; i < raidlist->disks.entries; ++i) {
    1554     if (!strcmp (raidlist->disks.el[i].name, vinum_name)) {
    1555         return raidlist->disks.el[i].device;
    1556     }
    1557     }
    1558     return NULL;
     1448char *find_dev_entry_for_raid_device_name(struct raidlist_itself *raidlist,
     1449                                          char *vinum_name)
     1450{
     1451    int i;
     1452    for (i = 0; i < raidlist->disks.entries; ++i) {
     1453        if (!strcmp(raidlist->disks.el[i].name, vinum_name)) {
     1454            return raidlist->disks.el[i].device;
     1455        }
     1456    }
     1457    return NULL;
    15591458}
    15601459
    15611460void
    1562 edit_raidlist_plex (struct mountlist_itself *mountlist,
    1563             struct raidlist_itself *raidlist,
    1564             struct vinum_plex *raidrec, int currline, int currline2);
     1461edit_raidlist_plex(struct mountlist_itself *mountlist,
     1462                   struct raidlist_itself *raidlist,
     1463                   struct vinum_plex *raidrec, int currline,
     1464                   int currline2);
    15651465
    15661466#endif
     
    15761476 */
    15771477void
    1578 edit_raidlist_entry (struct mountlist_itself *mountlist,
    1579              struct raidlist_itself *raidlist,
    1580              struct OSSWAP (raid_device_record, vinum_volume) *raidrec, int currline)
     1478edit_raidlist_entry(struct mountlist_itself *mountlist,
     1479                    struct raidlist_itself *raidlist,
     1480                    struct OSSWAP (raid_device_record,
     1481                                   vinum_volume) * raidrec, int currline)
    15811482{
    15821483
    15831484#ifdef __FreeBSD__
    15841485    /** structures ********************************************************/
    1585   struct vinum_volume bkp_raidrec;
     1486    struct vinum_volume bkp_raidrec;
    15861487
    15871488
    15881489    /** buffers ***********************************************************/
    1589   char title_of_editraidForm_window[MAX_STR_LEN];
     1490    char title_of_editraidForm_window[MAX_STR_LEN];
    15901491
    15911492    /** newt **************************************************************/
    1592   newtComponent editraidForm;
    1593   newtComponent bOK;
    1594   newtComponent bCancel;
    1595   newtComponent bEdit;
    1596   newtComponent bAdd;
    1597   newtComponent bDelete;
    1598   newtComponent b_res;
    1599   newtComponent plexesListbox;
    1600   newtComponent plexesHeader;
    1601 
    1602   void *keylist[10];
    1603   void *curr_choice;
    1604 
    1605   int currline2 = 0;
    1606 
    1607   log_it ("Started edit_raidlist_entry");
    1608   memcpy ((void *) &bkp_raidrec, (void *) raidrec,
    1609       sizeof (struct vinum_volume));
    1610   sprintf (title_of_editraidForm_window, "Plexes on %s", raidrec->volname);
    1611   newtPushHelpLine ("   Please select a plex to edit");
    1612   newtOpenWindow (13, 5, 54, 15, title_of_editraidForm_window);
    1613   for (;;)
    1614     {
    1615     int i;
    1616     char headerstr[MAX_STR_LEN];
    1617     snprintf (headerstr, MAX_STR_LEN, "%-14s %-8s  %11s  %8s",
    1618           "Plex", "Level", "Stripe Size", "Subdisks");
    1619 
    1620     bOK = newtCompactButton (2, 13, "  OK  ");
    1621     bCancel = newtCompactButton (12, 13, "Cancel");
    1622     bAdd  = newtCompactButton (22, 13, " Add ");
    1623     bEdit = newtCompactButton (32, 13, " Edit ");
    1624     bDelete = newtCompactButton (42, 13, "Delete");
    1625 
    1626     plexesListbox = newtListbox (2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1627     plexesHeader  = newtLabel (2, 2, headerstr);
    1628     editraidForm = newtForm (NULL, NULL, 0);
    1629 
    1630     newtListboxClear (plexesListbox);
    1631     for (i = 0; i < 10; ++i) {
    1632         keylist[i] = (void *) i;
    1633         if (i < raidrec->plexes) {
    1634         char pname[64], entry[MAX_STR_LEN], raidlevel[64], chunksize[64];
    1635         switch (raidrec->plex[i].raidlevel) {
    1636         case -1:
    1637             strcpy (raidlevel, "concat");
    1638             break;
    1639         case 0:
    1640             strcpy (raidlevel, "striped");
    1641             break;
    1642         case 5:
    1643             strcpy (raidlevel, "raid5");
    1644             break;
    1645         default:
    1646             sprintf (raidlevel, "raid%i", raidrec->plex[i].raidlevel);
    1647             break;
    1648         }
    1649 
    1650         if (raidrec->plex[i].raidlevel == -1) {
    1651             strcpy (chunksize, "N/A");
    1652         } else {
    1653             sprintf (chunksize, "%dk", raidrec->plex[i].stripesize);
    1654         }
    1655         snprintf (pname, 64, "%s.p%i", raidrec->volname, i);
    1656         snprintf (entry, MAX_STR_LEN, "%-14s %-8s  %11s  %8d", pname, raidlevel, chunksize,
    1657               raidrec->plex[i].subdisks);
    1658         newtListboxAppendEntry (plexesListbox, entry, keylist[i]);
    1659         }
    1660     }
    1661 
    1662     newtFormAddComponents (editraidForm, bOK, bCancel, bAdd, bEdit,
    1663                    bDelete, plexesListbox, plexesHeader, NULL);
    1664 
    1665     b_res = newtRunForm (editraidForm);
    1666       if (b_res == bOK || b_res == bCancel)
    1667     {
    1668       break;
    1669     }
    1670 
    1671       curr_choice = newtListboxGetCurrent (plexesListbox);
    1672       for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) {
    1673       if (currline2 > 9) break;
    1674       if (keylist[currline2] == curr_choice) break;
    1675       }
    1676 
    1677       if (b_res == bDelete) {
    1678       char msg[MAX_STR_LEN];
    1679       sprintf (msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2);
    1680       if (ask_me_yes_or_no (msg)) {
    1681           log_it ("Deleting RAID plex");
    1682           memcpy ((void *) &raidrec->plex[currline2],
    1683               (void *) &raidrec->plex[raidrec->plexes - 1],
    1684               sizeof (struct vinum_plex));
    1685           raidrec->plexes--;
    1686       }
    1687       continue;
    1688       }
    1689       if (b_res == bAdd) {
    1690       raidrec->plex[raidrec->plexes].raidlevel = 0;
    1691       raidrec->plex[raidrec->plexes].stripesize = 279;
    1692       raidrec->plex[raidrec->plexes].subdisks = 0;
    1693       currline2 = raidrec->plexes++;
    1694       }
    1695       edit_raidlist_plex (mountlist, raidlist, &raidrec->plex[currline2], currline, currline2);
    1696       newtFormDestroy (editraidForm);
    1697     }
    1698   if (b_res == bCancel)
    1699     {
    1700       memcpy ((void *) raidrec, (void *) &bkp_raidrec,
    1701           sizeof (struct vinum_volume));
    1702     }
    1703   newtPopHelpLine ();
    1704   newtPopWindow ();
    1705   mountlist->el[currline].size =
    1706     calculate_raid_device_size (mountlist, raidlist, raidrec->volname);
     1493    newtComponent editraidForm;
     1494    newtComponent bOK;
     1495    newtComponent bCancel;
     1496    newtComponent bEdit;
     1497    newtComponent bAdd;
     1498    newtComponent bDelete;
     1499    newtComponent b_res;
     1500    newtComponent plexesListbox;
     1501    newtComponent plexesHeader;
     1502
     1503    void *keylist[10];
     1504    void *curr_choice;
     1505
     1506    int currline2 = 0;
     1507
     1508    log_it("Started edit_raidlist_entry");
     1509    memcpy((void *) &bkp_raidrec, (void *) raidrec,
     1510           sizeof(struct vinum_volume));
     1511    sprintf(title_of_editraidForm_window, "Plexes on %s",
     1512            raidrec->volname);
     1513    newtPushHelpLine("   Please select a plex to edit");
     1514    newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window);
     1515    for (;;) {
     1516        int i;
     1517        char headerstr[MAX_STR_LEN];
     1518        snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s  %11s  %8s",
     1519                 "Plex", "Level", "Stripe Size", "Subdisks");
     1520
     1521        bOK = newtCompactButton(2, 13, "  OK  ");
     1522        bCancel = newtCompactButton(12, 13, "Cancel");
     1523        bAdd = newtCompactButton(22, 13, " Add ");
     1524        bEdit = newtCompactButton(32, 13, " Edit ");
     1525        bDelete = newtCompactButton(42, 13, "Delete");
     1526
     1527        plexesListbox =
     1528            newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1529        plexesHeader = newtLabel(2, 2, headerstr);
     1530        editraidForm = newtForm(NULL, NULL, 0);
     1531
     1532        newtListboxClear(plexesListbox);
     1533        for (i = 0; i < 10; ++i) {
     1534            keylist[i] = (void *) i;
     1535            if (i < raidrec->plexes) {
     1536                char pname[64], entry[MAX_STR_LEN], raidlevel[64],
     1537                    chunksize[64];
     1538                switch (raidrec->plex[i].raidlevel) {
     1539                case -1:
     1540                    strcpy(raidlevel, "concat");
     1541                    break;
     1542                case 0:
     1543                    strcpy(raidlevel, "striped");
     1544                    break;
     1545                case 5:
     1546                    strcpy(raidlevel, "raid5");
     1547                    break;
     1548                default:
     1549                    sprintf(raidlevel, "raid%i",
     1550                            raidrec->plex[i].raidlevel);
     1551                    break;
     1552                }
     1553
     1554                if (raidrec->plex[i].raidlevel == -1) {
     1555                    strcpy(chunksize, "N/A");
     1556                } else {
     1557                    sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
     1558                }
     1559                snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
     1560                snprintf(entry, MAX_STR_LEN, "%-14s %-8s  %11s  %8d",
     1561                         pname, raidlevel, chunksize,
     1562                         raidrec->plex[i].subdisks);
     1563                newtListboxAppendEntry(plexesListbox, entry, keylist[i]);
     1564            }
     1565        }
     1566
     1567        newtFormAddComponents(editraidForm, bOK, bCancel, bAdd, bEdit,
     1568                              bDelete, plexesListbox, plexesHeader, NULL);
     1569
     1570        b_res = newtRunForm(editraidForm);
     1571        if (b_res == bOK || b_res == bCancel) {
     1572            break;
     1573        }
     1574
     1575        curr_choice = newtListboxGetCurrent(plexesListbox);
     1576        for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) {
     1577            if (currline2 > 9)
     1578                break;
     1579            if (keylist[currline2] == curr_choice)
     1580                break;
     1581        }
     1582
     1583        if (b_res == bDelete) {
     1584            char msg[MAX_STR_LEN];
     1585            sprintf(msg, "Are you sure you want to delete %s.p%i?",
     1586                    raidrec->volname, currline2);
     1587            if (ask_me_yes_or_no(msg)) {
     1588                log_it("Deleting RAID plex");
     1589                memcpy((void *) &raidrec->plex[currline2],
     1590                       (void *) &raidrec->plex[raidrec->plexes - 1],
     1591                       sizeof(struct vinum_plex));
     1592                raidrec->plexes--;
     1593            }
     1594            continue;
     1595        }
     1596        if (b_res == bAdd) {
     1597            raidrec->plex[raidrec->plexes].raidlevel = 0;
     1598            raidrec->plex[raidrec->plexes].stripesize = 279;
     1599            raidrec->plex[raidrec->plexes].subdisks = 0;
     1600            currline2 = raidrec->plexes++;
     1601        }
     1602        edit_raidlist_plex(mountlist, raidlist, &raidrec->plex[currline2],
     1603                           currline, currline2);
     1604        newtFormDestroy(editraidForm);
     1605    }
     1606    if (b_res == bCancel) {
     1607        memcpy((void *) raidrec, (void *) &bkp_raidrec,
     1608               sizeof(struct vinum_volume));
     1609    }
     1610    newtPopHelpLine();
     1611    newtPopWindow();
     1612    mountlist->el[currline].size =
     1613        calculate_raid_device_size(mountlist, raidlist, raidrec->volname);
    17071614#else
    17081615    /** structures ********************************************************/
    1709   struct raid_device_record *bkp_raidrec;
     1616    struct raid_device_record *bkp_raidrec;
    17101617
    17111618
    17121619    /** buffers ***********************************************************/
    1713     char *title_of_editraidForm_window;
     1620    char *title_of_editraidForm_window;
    17141621    char *sz_raid_level;
    17151622    char *sz_data_disks;
     
    17191626
    17201627    /** newt **************************************************************/
    1721   newtComponent editraidForm;
     1628    newtComponent editraidForm;
    17221629    newtComponent bOK;
    17231630    newtComponent bCancel;
     
    17301637    newtComponent b_res;
    17311638
    1732   assert(mountlist!=NULL);
    1733   assert(raidlist!=NULL);
    1734   assert(raidrec!=NULL);
    1735 
    1736   malloc_string(title_of_editraidForm_window);
    1737   malloc_string(sz_raid_level);
    1738   malloc_string(sz_data_disks);
    1739   malloc_string(sz_spare_disks);
    1740   malloc_string(sz_parity_disks);
    1741   malloc_string(sz_failed_disks);
    1742   if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record))))
    1743     { fatal_error("Cannot malloc space for raidrec"); }
    1744 
    1745   log_it ("Started edit_raidlist_entry");
    1746 
    1747   memcpy ((void *) bkp_raidrec, (void *) raidrec,
    1748       sizeof (struct raid_device_record));
    1749   sprintf (title_of_editraidForm_window, "%s", raidrec->raid_device);
    1750   log_msg(2, "Opening newt window");
    1751   newtOpenWindow (20, 5, 40, 14, title_of_editraidForm_window);
    1752   for (;;)
    1753     {
    1754       log_msg(2, "Main loop");
    1755       sprintf (title_of_editraidForm_window, "Edit %s", raidrec->raid_device);
    1756       strcpy (sz_raid_level,
    1757           turn_raid_level_number_to_string (raidrec->raid_level));
    1758       strcpy (sz_data_disks,
    1759           number_of_disks_as_string (raidrec->data_disks.entries,
    1760                      "data"));
    1761       strcpy (sz_spare_disks,
    1762           number_of_disks_as_string (raidrec->spare_disks.entries,
    1763                      "spare"));
    1764       strcpy (sz_parity_disks,
    1765           number_of_disks_as_string (raidrec->parity_disks.entries,
    1766                      "parity"));
    1767       strcpy (sz_failed_disks,
    1768           number_of_disks_as_string (raidrec->failed_disks.entries,
    1769                      "failed"));
    1770       bSelectData = newtButton (1, 1, sz_data_disks);
    1771       bSelectSpare = newtButton (20, 1, sz_spare_disks);
    1772       bSelectParity = newtButton (1, 5, sz_parity_disks);
    1773       bSelectFailed = newtButton (20, 5, sz_failed_disks);
    1774       bChangeRaid = newtButton (1, 9, sz_raid_level);
    1775       bOK = newtButton (16 + (raidrec->raid_level == -1), 9, "  OK  ");
    1776       bCancel = newtButton (28, 9, "Cancel");
    1777       bAdditional =
    1778     newtCompactButton (1, 13, "Additional settings and information");
    1779       newtPushHelpLine
    1780     ("  Edit the RAID device's settings to your heart's content, then hit OK/Cancel.");
    1781       editraidForm = newtForm (NULL, NULL, 0);
    1782       newtFormAddComponents (editraidForm, bSelectData, bSelectParity,
    1783                  bChangeRaid, bSelectSpare, bSelectFailed, bOK,
    1784                  bCancel, bAdditional);
    1785       b_res = newtRunForm (editraidForm);
    1786       if (b_res == bChangeRaid)
    1787     {
    1788       choose_raid_level (raidrec);
    1789     }
    1790       else if (b_res == bSelectData)
    1791     {
    1792       select_raid_disks (mountlist, raidlist, raidrec, "data",
    1793                  &raidrec->data_disks);
    1794     }
    1795       else if (b_res == bSelectSpare)
    1796     {
    1797       select_raid_disks (mountlist, raidlist, raidrec, "spare",
    1798                  &raidrec->spare_disks);
    1799     }
    1800       else if (b_res == bSelectParity)
    1801     {
    1802       select_raid_disks (mountlist, raidlist, raidrec, "parity",
    1803                  &raidrec->parity_disks);
    1804     }
    1805       else if (b_res == bSelectFailed)
    1806     {
    1807       select_raid_disks (mountlist, raidlist, raidrec, "failed",
    1808                  &raidrec->failed_disks);
    1809     }
    1810       else if (b_res == bAdditional)
    1811     {
    1812       edit_raidrec_additional_vars (raidrec);
    1813     }
    1814       newtFormDestroy (editraidForm);
    1815       if (b_res == bOK || b_res == bCancel)
    1816     {
    1817       break;
    1818     }
    1819     }
    1820   if (b_res == bCancel)
    1821     {
    1822       memcpy ((void *) raidrec, (void *) bkp_raidrec,
    1823           sizeof (struct raid_device_record));
    1824     }
    1825   newtPopHelpLine ();
    1826   newtPopWindow ();
    1827   mountlist->el[currline].size =
    1828     calculate_raid_device_size (mountlist, raidlist, raidrec->raid_device);
    1829   paranoid_free(title_of_editraidForm_window);
    1830   paranoid_free(sz_raid_level);
    1831   paranoid_free(sz_data_disks);
    1832   paranoid_free(sz_spare_disks);
    1833   paranoid_free(sz_parity_disks);
    1834   paranoid_free(sz_failed_disks);
    1835   paranoid_free(bkp_raidrec);
     1639    assert(mountlist != NULL);
     1640    assert(raidlist != NULL);
     1641    assert(raidrec != NULL);
     1642
     1643    malloc_string(title_of_editraidForm_window);
     1644    malloc_string(sz_raid_level);
     1645    malloc_string(sz_data_disks);
     1646    malloc_string(sz_spare_disks);
     1647    malloc_string(sz_parity_disks);
     1648    malloc_string(sz_failed_disks);
     1649    if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
     1650        fatal_error("Cannot malloc space for raidrec");
     1651    }
     1652
     1653    log_it("Started edit_raidlist_entry");
     1654
     1655    memcpy((void *) bkp_raidrec, (void *) raidrec,
     1656           sizeof(struct raid_device_record));
     1657    sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
     1658    log_msg(2, "Opening newt window");
     1659    newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window);
     1660    for (;;) {
     1661        log_msg(2, "Main loop");
     1662        sprintf(title_of_editraidForm_window, "Edit %s",
     1663                raidrec->raid_device);
     1664        strcpy(sz_raid_level,
     1665               turn_raid_level_number_to_string(raidrec->raid_level));
     1666        strcpy(sz_data_disks,
     1667               number_of_disks_as_string(raidrec->data_disks.entries,
     1668                                         "data"));
     1669        strcpy(sz_spare_disks,
     1670               number_of_disks_as_string(raidrec->spare_disks.entries,
     1671                                         "spare"));
     1672        strcpy(sz_parity_disks,
     1673               number_of_disks_as_string(raidrec->parity_disks.entries,
     1674                                         "parity"));
     1675        strcpy(sz_failed_disks,
     1676               number_of_disks_as_string(raidrec->failed_disks.entries,
     1677                                         "failed"));
     1678        bSelectData = newtButton(1, 1, sz_data_disks);
     1679        bSelectSpare = newtButton(20, 1, sz_spare_disks);
     1680        bSelectParity = newtButton(1, 5, sz_parity_disks);
     1681        bSelectFailed = newtButton(20, 5, sz_failed_disks);
     1682        bChangeRaid = newtButton(1, 9, sz_raid_level);
     1683        bOK = newtButton(16 + (raidrec->raid_level == -1), 9, "  OK  ");
     1684        bCancel = newtButton(28, 9, "Cancel");
     1685        bAdditional =
     1686            newtCompactButton(1, 13,
     1687                              "Additional settings and information");
     1688        newtPushHelpLine
     1689            ("  Edit the RAID device's settings to your heart's content, then hit OK/Cancel.");
     1690        editraidForm = newtForm(NULL, NULL, 0);
     1691        newtFormAddComponents(editraidForm, bSelectData, bSelectParity,
     1692                              bChangeRaid, bSelectSpare, bSelectFailed,
     1693                              bOK, bCancel, bAdditional);
     1694        b_res = newtRunForm(editraidForm);
     1695        if (b_res == bChangeRaid) {
     1696            choose_raid_level(raidrec);
     1697        } else if (b_res == bSelectData) {
     1698            select_raid_disks(mountlist, raidlist, raidrec, "data",
     1699                              &raidrec->data_disks);
     1700        } else if (b_res == bSelectSpare) {
     1701            select_raid_disks(mountlist, raidlist, raidrec, "spare",
     1702                              &raidrec->spare_disks);
     1703        } else if (b_res == bSelectParity) {
     1704            select_raid_disks(mountlist, raidlist, raidrec, "parity",
     1705                              &raidrec->parity_disks);
     1706        } else if (b_res == bSelectFailed) {
     1707            select_raid_disks(mountlist, raidlist, raidrec, "failed",
     1708                              &raidrec->failed_disks);
     1709        } else if (b_res == bAdditional) {
     1710            edit_raidrec_additional_vars(raidrec);
     1711        }
     1712        newtFormDestroy(editraidForm);
     1713        if (b_res == bOK || b_res == bCancel) {
     1714            break;
     1715        }
     1716    }
     1717    if (b_res == bCancel) {
     1718        memcpy((void *) raidrec, (void *) bkp_raidrec,
     1719               sizeof(struct raid_device_record));
     1720    }
     1721    newtPopHelpLine();
     1722    newtPopWindow();
     1723    mountlist->el[currline].size =
     1724        calculate_raid_device_size(mountlist, raidlist,
     1725                                   raidrec->raid_device);
     1726    paranoid_free(title_of_editraidForm_window);
     1727    paranoid_free(sz_raid_level);
     1728    paranoid_free(sz_data_disks);
     1729    paranoid_free(sz_spare_disks);
     1730    paranoid_free(sz_parity_disks);
     1731    paranoid_free(sz_failed_disks);
     1732    paranoid_free(bkp_raidrec);
    18361733#endif
    18371734}
     
    18501747 */
    18511748void
    1852 edit_raidlist_plex (struct mountlist_itself *mountlist,
    1853             struct raidlist_itself *raidlist,
    1854             struct vinum_plex *raidrec, int currline, int currline2)
     1749edit_raidlist_plex(struct mountlist_itself *mountlist,
     1750                   struct raidlist_itself *raidlist,
     1751                   struct vinum_plex *raidrec, int currline, int currline2)
    18551752{
    18561753
    18571754    /** structures ********************************************************/
    1858   struct vinum_plex bkp_raidrec;
     1755    struct vinum_plex bkp_raidrec;
    18591756
    18601757
    18611758    /** buffers ***********************************************************/
    1862   char title_of_editraidForm_window[MAX_STR_LEN];
     1759    char title_of_editraidForm_window[MAX_STR_LEN];
    18631760
    18641761    /** newt **************************************************************/
    1865   newtComponent editraidForm;
    1866   newtComponent bOK;
    1867   newtComponent bCancel;
    1868   newtComponent bEdit;
    1869   newtComponent bAdd;
    1870   newtComponent bDelete;
    1871   newtComponent b_res;
    1872   newtComponent unallocListbox, allocListbox;
    1873   newtComponent bLevel, sLevel;
    1874   newtComponent bStripeSize, sStripeSize;
    1875   newtComponent bAlloc, bUnalloc;
    1876 
    1877   void *keylist[ARBITRARY_MAXIMUM];
    1878   void *curr_choice_a, *curr_choice_u;
    1879   int currline_a, currline_u;
    1880 
    1881   struct mountlist_itself *unallocparts;
    1882  
    1883   unallocparts = malloc (sizeof (struct mountlist_itself));
    1884 
    1885   log_it ("Started edit_raidlist_entry");
    1886   memcpy ((void *) &bkp_raidrec, (void *) raidrec,
    1887       sizeof (struct vinum_plex));
    1888   sprintf (title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2);
    1889   newtPushHelpLine ("   Please select a subdisk to edit, or edit this plex's parameters");
    1890   newtOpenWindow (13, 3, 54, 18, title_of_editraidForm_window);
    1891  for (;;)
    1892     {
    1893     int i;
    1894     char headerstr[MAX_STR_LEN];
    1895     char tmp[64];
    1896     snprintf (headerstr, MAX_STR_LEN, "%-24s %s",
    1897           "Subdisk", "Device");
    1898    
    1899    
    1900     switch (raidrec->raidlevel) {
    1901     case -1:
    1902         strcpy (tmp, "concat");
    1903         break;
    1904     case 0:
    1905         strcpy (tmp, "striped");
    1906         break;
    1907     case 5:
    1908         strcpy (tmp, "raid5");
    1909         break;
    1910     default:
    1911         sprintf (tmp, "unknown (%i)", raidrec->raidlevel);
    1912         break;
    1913     }
    1914     bLevel = newtCompactButton (2, 2, " RAID level ");
    1915     sLevel = newtLabel (19, 2, tmp);
    1916 
    1917     if (raidrec->raidlevel >= 0) {
    1918         sprintf (tmp, "%ik", raidrec->stripesize);
    1919         bStripeSize = newtCompactButton (2, 4, " Stripe size ");
    1920     } else {
    1921         strcpy (tmp, "N/A");
    1922         bStripeSize = newtLabel (2, 4, "Stripe size:");     
    1923     }
    1924     sStripeSize = newtLabel (19, 4, tmp);
    1925    
    1926     bOK = newtCompactButton (2, 16, "  OK  ");
    1927     bCancel = newtCompactButton (12, 16, "Cancel");
    1928     bAdd  = newtCompactButton (22, 16, " Add ");
    1929     bEdit = newtCompactButton (32, 16, " Edit ");
    1930     bDelete = newtCompactButton (42, 16, "Delete");
    1931    
    1932    
    1933     //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1934     //  plexesHeader  = newtLabel (2, 6, headerstr);
    1935     unallocListbox  = newtListbox (2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1936     allocListbox   = newtListbox (33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1937     bAlloc   = newtButton (23, 7, " -> ");
    1938     bUnalloc = newtButton (23, 11, " <- ");
    1939    
    1940     editraidForm = newtForm (NULL, NULL, 0);
    1941 
    1942     newtListboxClear (allocListbox);
    1943     newtListboxClear (unallocListbox);
    1944     bzero (unallocparts, sizeof (struct mountlist_itself));
    1945     make_list_of_unallocated_raid_partitions (unallocparts, mountlist, raidlist);
    1946     for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
    1947         char entry[MAX_STR_LEN];
    1948         keylist[i] = (void *) i;
    1949         if (i < raidrec->subdisks) {
    1950         snprintf (entry, MAX_STR_LEN, "%-17s", find_dev_entry_for_raid_device_name (raidlist, raidrec->sd[i].which_device));
    1951         newtListboxAppendEntry (allocListbox, entry, keylist[i]);
    1952         }
    1953         if (i < unallocparts->entries) {
    1954         snprintf (entry, MAX_STR_LEN, "%-17s", unallocparts->el[i].device);
    1955         newtListboxAppendEntry (unallocListbox, entry, keylist[i]);
    1956         }
    1957     }
    1958    
     1762    newtComponent editraidForm;
     1763    newtComponent bOK;
     1764    newtComponent bCancel;
     1765    newtComponent bEdit;
     1766    newtComponent bAdd;
     1767    newtComponent bDelete;
     1768    newtComponent b_res;
     1769    newtComponent unallocListbox, allocListbox;
     1770    newtComponent bLevel, sLevel;
     1771    newtComponent bStripeSize, sStripeSize;
     1772    newtComponent bAlloc, bUnalloc;
     1773
     1774    void *keylist[ARBITRARY_MAXIMUM];
     1775    void *curr_choice_a, *curr_choice_u;
     1776    int currline_a, currline_u;
     1777
     1778    struct mountlist_itself *unallocparts;
     1779
     1780    unallocparts = malloc(sizeof(struct mountlist_itself));
     1781
     1782    log_it("Started edit_raidlist_entry");
     1783    memcpy((void *) &bkp_raidrec, (void *) raidrec,
     1784           sizeof(struct vinum_plex));
     1785    sprintf(title_of_editraidForm_window, "%s.p%i",
     1786            raidlist->el[currline].volname, currline2);
     1787    newtPushHelpLine
     1788        ("   Please select a subdisk to edit, or edit this plex's parameters");
     1789    newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window);
     1790    for (;;) {
     1791        int i;
     1792        char headerstr[MAX_STR_LEN];
     1793        char tmp[64];
     1794        snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");
     1795
     1796
     1797        switch (raidrec->raidlevel) {
     1798        case -1:
     1799            strcpy(tmp, "concat");
     1800            break;
     1801        case 0:
     1802            strcpy(tmp, "striped");
     1803            break;
     1804        case 5:
     1805            strcpy(tmp, "raid5");
     1806            break;
     1807        default:
     1808            sprintf(tmp, "unknown (%i)", raidrec->raidlevel);
     1809            break;
     1810        }
     1811        bLevel = newtCompactButton(2, 2, " RAID level ");
     1812        sLevel = newtLabel(19, 2, tmp);
     1813
     1814        if (raidrec->raidlevel >= 0) {
     1815            sprintf(tmp, "%ik", raidrec->stripesize);
     1816            bStripeSize = newtCompactButton(2, 4, " Stripe size ");
     1817        } else {
     1818            strcpy(tmp, "N/A");
     1819            bStripeSize = newtLabel(2, 4, "Stripe size:");
     1820        }
     1821        sStripeSize = newtLabel(19, 4, tmp);
     1822
     1823        bOK = newtCompactButton(2, 16, "  OK  ");
     1824        bCancel = newtCompactButton(12, 16, "Cancel");
     1825        bAdd = newtCompactButton(22, 16, " Add ");
     1826        bEdit = newtCompactButton(32, 16, " Edit ");
     1827        bDelete = newtCompactButton(42, 16, "Delete");
     1828
     1829
     1830        //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1831        //  plexesHeader  = newtLabel (2, 6, headerstr);
     1832        unallocListbox =
     1833            newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1834        allocListbox =
     1835            newtListbox(33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     1836        bAlloc = newtButton(23, 7, " -> ");
     1837        bUnalloc = newtButton(23, 11, " <- ");
     1838
     1839        editraidForm = newtForm(NULL, NULL, 0);
     1840
     1841        newtListboxClear(allocListbox);
     1842        newtListboxClear(unallocListbox);
     1843        bzero(unallocparts, sizeof(struct mountlist_itself));
     1844        make_list_of_unallocated_raid_partitions(unallocparts, mountlist,
     1845                                                 raidlist);
     1846        for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
     1847            char entry[MAX_STR_LEN];
     1848            keylist[i] = (void *) i;
     1849            if (i < raidrec->subdisks) {
     1850                snprintf(entry, MAX_STR_LEN, "%-17s",
     1851                         find_dev_entry_for_raid_device_name(raidlist,
     1852                                                             raidrec->
     1853                                                             sd[i].
     1854                                                             which_device));
     1855                newtListboxAppendEntry(allocListbox, entry, keylist[i]);
     1856            }
     1857            if (i < unallocparts->entries) {
     1858                snprintf(entry, MAX_STR_LEN, "%-17s",
     1859                         unallocparts->el[i].device);
     1860                newtListboxAppendEntry(unallocListbox, entry, keylist[i]);
     1861            }
     1862        }
     1863
    19591864#define COMP(x)  newtFormAddComponent (editraidForm, x)
    19601865#define UCOMP(x) if (unallocparts->entries > 0) COMP(x)
    19611866#define ACOMP(x) if (raidrec->subdisks > 0) COMP(x)
    1962     editraidForm = newtForm (NULL, NULL, 0);
    1963     UCOMP (unallocListbox);
    1964     UCOMP (bAlloc);
    1965     ACOMP (allocListbox);
    1966     ACOMP (bUnalloc);
    1967     COMP (bOK);
    1968     COMP (bCancel);
    1969     COMP (bLevel);
    1970     COMP (sLevel);
    1971     if (raidrec->raidlevel != -1) {
    1972         COMP (bStripeSize);
    1973         COMP (sStripeSize);
    1974     }
     1867        editraidForm = newtForm(NULL, NULL, 0);
     1868        UCOMP(unallocListbox);
     1869        UCOMP(bAlloc);
     1870        ACOMP(allocListbox);
     1871        ACOMP(bUnalloc);
     1872        COMP(bOK);
     1873        COMP(bCancel);
     1874        COMP(bLevel);
     1875        COMP(sLevel);
     1876        if (raidrec->raidlevel != -1) {
     1877            COMP(bStripeSize);
     1878            COMP(sStripeSize);
     1879        }
    19751880#undef COMP
    19761881#undef UCOMP
    19771882#undef ACOMP
    19781883
     1884        newtRefresh();
     1885        b_res = newtRunForm(editraidForm);
     1886        if (b_res == bOK || b_res == bCancel) {
     1887            break;
     1888        }
     1889
     1890        curr_choice_a = (raidrec->subdisks > 0) ?
     1891            newtListboxGetCurrent(allocListbox) : (void *) 1234;
     1892        curr_choice_u = (unallocparts->entries > 0) ?
     1893            newtListboxGetCurrent(unallocListbox) : (void *) 1234;
     1894        for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) {
     1895            if (currline_a > ARBITRARY_MAXIMUM)
     1896                break;
     1897            if (keylist[currline_a] == curr_choice_a)
     1898                break;
     1899        }
     1900        for (currline_u = 0; currline_u < unallocparts->entries;
     1901             ++currline_u) {
     1902            if (currline_u > ARBITRARY_MAXIMUM)
     1903                break;
     1904            if (keylist[currline_u] == curr_choice_u)
     1905                break;
     1906        }
     1907        if (b_res == bLevel) {
     1908            choose_raid_level(raidrec);
     1909        } else if (b_res == bStripeSize) {
     1910            char tmp[64];
     1911            sprintf(tmp, "%i", raidrec->stripesize);
     1912            if (popup_and_get_string
     1913                ("Stripe size",
     1914                 "Please enter the stripe size in kilobytes.", tmp, 20)) {
     1915                raidrec->stripesize = atoi(tmp);
     1916            }
     1917        } else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
     1918            if (currline_u <= unallocparts->entries)
     1919                add_raid_subdisk(raidlist, raidrec,
     1920                                 unallocparts->el[currline_u].device);
     1921        } else if ((b_res == bUnalloc) || (b_res == allocListbox)) {
     1922            if (currline_a <= raidrec->subdisks) {
     1923                memcpy((void *) &raidrec->sd[currline_a],
     1924                       (void *) &raidrec->sd[raidrec->subdisks - 1],
     1925                       sizeof(struct vinum_subdisk));
     1926                raidrec->subdisks--;
     1927            }
     1928        }
     1929#if 0
     1930    } else {
     1931        edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],
     1932                          currline3);
     1933    }
     1934#endif
     1935    newtFormDestroy(editraidForm);
    19791936    newtRefresh();
    1980     b_res = newtRunForm (editraidForm);
    1981       if (b_res == bOK || b_res == bCancel)
    1982     {
    1983       break;
    1984     }
    1985 
    1986       curr_choice_a = (raidrec->subdisks > 0)     ?
    1987       newtListboxGetCurrent (allocListbox)    : (void *)1234;
    1988       curr_choice_u = (unallocparts->entries > 0) ?
    1989       newtListboxGetCurrent (unallocListbox)  : (void *)1234;
    1990       for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) {
    1991       if (currline_a > ARBITRARY_MAXIMUM) break;
    1992       if (keylist[currline_a] == curr_choice_a) break;
    1993       }
    1994       for (currline_u = 0; currline_u < unallocparts->entries; ++currline_u) {
    1995       if (currline_u > ARBITRARY_MAXIMUM) break;
    1996       if (keylist[currline_u] == curr_choice_u) break;
    1997       }
    1998       if (b_res == bLevel) {
    1999       choose_raid_level (raidrec);
    2000       }
    2001       else if (b_res == bStripeSize) {
    2002       char tmp[64];
    2003       sprintf (tmp, "%i", raidrec->stripesize);
    2004       if (popup_and_get_string ("Stripe size", "Please enter the stripe size in kilobytes.",
    2005                     tmp, 20)) {
    2006           raidrec->stripesize = atoi (tmp);
    2007       }
    2008       }
    2009       else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
    2010       if (currline_u <= unallocparts->entries)
    2011           add_raid_subdisk (raidlist, raidrec, unallocparts->el[currline_u].device);
    2012       }
    2013       else if ((b_res == bUnalloc) || (b_res == allocListbox)) {
    2014       if (currline_a <= raidrec->subdisks) {
    2015           memcpy ((void *) &raidrec->sd[currline_a],
    2016               (void *) &raidrec->sd[raidrec->subdisks - 1],
    2017               sizeof (struct vinum_subdisk));
    2018           raidrec->subdisks--;
    2019       }
    2020       }
    2021 #if 0     
    2022       } else {
    2023       edit_raid_subdisk (raidlist, raidrec, &raidrec->sd[currline3], currline3);
    2024       }
    2025 #endif
    2026       newtFormDestroy (editraidForm);
    2027       newtRefresh();
    2028     }
    2029   if (b_res == bCancel)
    2030     {
    2031     memcpy ((void *) raidrec, (void *) &bkp_raidrec,
    2032         sizeof (struct vinum_plex));
    2033     }
    2034   newtPopWindow();
    2035   newtPopHelpLine ();
     1937}
     1938
     1939if (b_res == bCancel) {
     1940    memcpy((void *) raidrec, (void *) &bkp_raidrec,
     1941           sizeof(struct vinum_plex));
     1942}
     1943newtPopWindow();
     1944newtPopHelpLine();
    20361945}
    20371946#else
     
    20421951 * @ingroup restoreGuiVarslist
    20431952 */
    2044 void
    2045 edit_varslist_entry (struct raid_device_record *raidrec, int lino)
     1953void edit_varslist_entry(struct raid_device_record *raidrec, int lino)
    20461954{
    20471955
    20481956    /** buffers ***********************************************************/
    2049   char header[MAX_STR_LEN];
     1957    char header[MAX_STR_LEN];
    20501958    char comment[MAX_STR_LEN];
    20511959    char sz_out[MAX_STR_LEN];
    20521960
    2053   assert(raidrec!=0);
    2054   assert(lino>=0);
    2055 
    2056   strcpy (sz_out, raidrec->additional_vars.el[lino].value);
    2057   sprintf (header, "Edit %s", raidrec->additional_vars.el[lino].label);
    2058   sprintf (comment, "Please set %s's value (currently '%s')",
    2059        raidrec->additional_vars.el[lino].label, sz_out);
    2060   if (popup_and_get_string (header, comment, sz_out, MAX_STR_LEN))
    2061     {
    2062       strip_spaces (sz_out);
    2063       strcpy (raidrec->additional_vars.el[lino].value, sz_out);
    2064     }
     1961    assert(raidrec != 0);
     1962    assert(lino >= 0);
     1963
     1964    strcpy(sz_out, raidrec->additional_vars.el[lino].value);
     1965    sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label);
     1966    sprintf(comment, "Please set %s's value (currently '%s')",
     1967            raidrec->additional_vars.el[lino].label, sz_out);
     1968    if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) {
     1969        strip_spaces(sz_out);
     1970        strcpy(raidrec->additional_vars.el[lino].value, sz_out);
     1971    }
    20651972}
    20661973
     
    20771984 */
    20781985int
    2079 edit_mountlist_in_newt (char*mountlist_fname, struct mountlist_itself *mountlist,
    2080         struct raidlist_itself *raidlist)
     1986edit_mountlist_in_newt(char *mountlist_fname,
     1987                       struct mountlist_itself *mountlist,
     1988                       struct raidlist_itself *raidlist)
    20811989{
    20821990
    20831991    /** newt **************************************************************/
    2084   newtComponent myForm;
     1992    newtComponent myForm;
    20851993    newtComponent bAdd;
    20861994    newtComponent bEdit;
     
    20972005
    20982006    /** ???? *************************************************************/
    2099   void *curr_choice;
    2100   void *keylist[ARBITRARY_MAXIMUM];
     2007    void *curr_choice;
     2008    void *keylist[ARBITRARY_MAXIMUM];
    21012009
    21022010    /** int **************************************************************/
    2103   int i = 0;
     2011    int i = 0;
    21042012    int currline = 0;
    21052013    int finished = FALSE;
     
    21112019    char flaws_str_C[MAX_STR_LEN];
    21122020
    2113   assert(mountlist!=NULL);
    2114   assert(raidlist!=NULL);
    2115 
    2116   strcpy (flaws_str_A, "xxxxxxxxx");
    2117   strcpy (flaws_str_B, "xxxxxxxxx");
    2118   strcpy (flaws_str_C, "xxxxxxxxx");
    2119   if (mountlist->entries > ARBITRARY_MAXIMUM)
    2120     {
    2121       log_to_screen ("Arbitrary limits suck, man!");
    2122       finish (1);
    2123     }
    2124   newtPushHelpLine
    2125     ("   Please edit the mountlist to your satisfaction, then click OK or Cancel.");
    2126   i = 4;
    2127   bAdd = newtCompactButton (i, 17, " Add ");
    2128   bEdit = newtCompactButton (i += 11, 17, " Edit ");
    2129   bDelete = newtCompactButton (i += 12, 17, "Delete");
    2130   bReload = newtCompactButton (i += 12, 17, "Reload");
    2131   bCancel = newtCompactButton (i += 12, 17, "Cancel");
    2132   bOK = newtCompactButton (i += 12, 17, "  OK  ");
    2133   sprintf (tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format",
    2134        "Size (MB)");
    2135   headerMsg = newtLabel (2, 1, tmp);
    2136   flawsLabelA = newtLabel (2, 13, flaws_str_A);
    2137   flawsLabelB = newtLabel (2, 14, flaws_str_B);
    2138   flawsLabelC = newtLabel (2, 15, flaws_str_C);
    2139   partitionsListbox =
    2140     newtListbox (2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    2141   redraw_mountlist (mountlist, keylist, partitionsListbox);
    2142   newtOpenWindow (1, 3, 77, 18, "Editing mountlist");
    2143   myForm = newtForm (NULL, NULL, 0);
    2144   newtFormAddComponents (myForm, headerMsg, partitionsListbox, flawsLabelA,
    2145              flawsLabelB, flawsLabelC, bAdd, bEdit, bDelete,
    2146              bReload, bCancel, bOK, NULL);
    2147   while (!finished)
    2148     {
    2149       evaluate_mountlist (mountlist, flaws_str_A, flaws_str_B, flaws_str_C);
    2150       newtLabelSetText (flawsLabelA, flaws_str_A);
    2151       newtLabelSetText (flawsLabelB, flaws_str_B);
    2152       newtLabelSetText (flawsLabelC, flaws_str_C);
    2153       b_res = newtRunForm (myForm);
    2154       if (b_res == bOK)
    2155     {
    2156       if (!evaluate_mountlist
    2157           (mountlist, flaws_str_A, flaws_str_B, flaws_str_C))
    2158         {
    2159           finished =
    2160         ask_me_yes_or_no
    2161         ("Your mountlist might not work. Continue anyway?");
    2162         }
    2163       else
    2164         {
    2165           finished =
    2166         ask_me_yes_or_no
    2167         ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)");
    2168         }
    2169     }
    2170       else if (b_res == bCancel)
    2171     {
    2172       finished = TRUE;
    2173     }
    2174       else if (b_res == bReload)
    2175     {
    2176       if (ask_me_yes_or_no ("Reload original mountlist?"))
    2177         {
     2021    assert(mountlist != NULL);
     2022    assert(raidlist != NULL);
     2023
     2024    strcpy(flaws_str_A, "xxxxxxxxx");
     2025    strcpy(flaws_str_B, "xxxxxxxxx");
     2026    strcpy(flaws_str_C, "xxxxxxxxx");
     2027    if (mountlist->entries > ARBITRARY_MAXIMUM) {
     2028        log_to_screen("Arbitrary limits suck, man!");
     2029        finish(1);
     2030    }
     2031    newtPushHelpLine
     2032        ("   Please edit the mountlist to your satisfaction, then click OK or Cancel.");
     2033    i = 4;
     2034    bAdd = newtCompactButton(i, 17, " Add ");
     2035    bEdit = newtCompactButton(i += 11, 17, " Edit ");
     2036    bDelete = newtCompactButton(i += 12, 17, "Delete");
     2037    bReload = newtCompactButton(i += 12, 17, "Reload");
     2038    bCancel = newtCompactButton(i += 12, 17, "Cancel");
     2039    bOK = newtCompactButton(i += 12, 17, "  OK  ");
     2040    sprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format",
     2041            "Size (MB)");
     2042    headerMsg = newtLabel(2, 1, tmp);
     2043    flawsLabelA = newtLabel(2, 13, flaws_str_A);
     2044    flawsLabelB = newtLabel(2, 14, flaws_str_B);
     2045    flawsLabelC = newtLabel(2, 15, flaws_str_C);
     2046    partitionsListbox =
     2047        newtListbox(2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     2048    redraw_mountlist(mountlist, keylist, partitionsListbox);
     2049    newtOpenWindow(1, 3, 77, 18, "Editing mountlist");
     2050    myForm = newtForm(NULL, NULL, 0);
     2051    newtFormAddComponents(myForm, headerMsg, partitionsListbox,
     2052                          flawsLabelA, flawsLabelB, flawsLabelC, bAdd,
     2053                          bEdit, bDelete, bReload, bCancel, bOK, NULL);
     2054    while (!finished) {
     2055        evaluate_mountlist(mountlist, flaws_str_A, flaws_str_B,
     2056                           flaws_str_C);
     2057        newtLabelSetText(flawsLabelA, flaws_str_A);
     2058        newtLabelSetText(flawsLabelB, flaws_str_B);
     2059        newtLabelSetText(flawsLabelC, flaws_str_C);
     2060        b_res = newtRunForm(myForm);
     2061        if (b_res == bOK) {
     2062            if (!evaluate_mountlist
     2063                (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) {
     2064                finished =
     2065                    ask_me_yes_or_no
     2066                    ("Your mountlist might not work. Continue anyway?");
     2067            } else {
     2068                finished =
     2069                    ask_me_yes_or_no
     2070                    ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)");
     2071            }
     2072        } else if (b_res == bCancel) {
     2073            finished = TRUE;
     2074        } else if (b_res == bReload) {
     2075            if (ask_me_yes_or_no("Reload original mountlist?")) {
    21782076/*
    21792077This would be really dumb. RAIDTAB_FNAME is #define'd.   --- Hugo, 2003/04/24
     
    21842082        }
    21852083*/
    2186           load_mountlist (mountlist, mountlist_fname);
    2187           load_raidtab_into_raidlist (raidlist, RAIDTAB_FNAME);
    2188           redraw_mountlist (mountlist, keylist, partitionsListbox);
    2189         }
    2190     }
    2191       else
    2192     {
    2193       curr_choice = newtListboxGetCurrent (partitionsListbox);
    2194       for (i = 0; i < mountlist->entries && keylist[i] != curr_choice;
    2195            i++);
    2196       if (i == mountlist->entries && mountlist->entries > 0)
    2197         {
    2198           log_to_screen ("I don't know what that button does!");
    2199         }
    2200       else
    2201         {
    2202           currline = i;
    2203           if (b_res == bAdd)
    2204         {
    2205           add_mountlist_entry (mountlist, raidlist, partitionsListbox,
    2206                        currline, keylist);
    2207         }
    2208           else if (b_res == bDelete)
    2209         {
    2210           delete_mountlist_entry (mountlist, raidlist,
    2211                       partitionsListbox, currline,
    2212                       keylist);
    2213         }
    2214           else
    2215         {
    2216           if (mountlist->entries > 0)
    2217             {
    2218               edit_mountlist_entry (mountlist, raidlist,
    2219                         partitionsListbox, currline,
    2220                         keylist);
    2221             }
    2222           else
    2223             {
    2224               popup_and_OK
    2225             ("Please add an entry. Then press ENTER to edit it.");
    2226             }
    2227         }
    2228         }
    2229     }
    2230     }
    2231   newtFormDestroy (myForm);
    2232   newtPopWindow ();
    2233   newtPopHelpLine ();
    2234   if (b_res == bOK)
    2235     {
    2236       log_it("You pushed 'OK'. I shall now continue.");
    2237       return (0);
    2238     }
    2239   else
    2240     {
    2241       /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */
    2242       return (1);
    2243     }
     2084                load_mountlist(mountlist, mountlist_fname);
     2085                load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     2086                redraw_mountlist(mountlist, keylist, partitionsListbox);
     2087            }
     2088        } else {
     2089            curr_choice = newtListboxGetCurrent(partitionsListbox);
     2090            for (i = 0;
     2091                 i < mountlist->entries && keylist[i] != curr_choice; i++);
     2092            if (i == mountlist->entries && mountlist->entries > 0) {
     2093                log_to_screen("I don't know what that button does!");
     2094            } else {
     2095                currline = i;
     2096                if (b_res == bAdd) {
     2097                    add_mountlist_entry(mountlist, raidlist,
     2098                                        partitionsListbox, currline,
     2099                                        keylist);
     2100                } else if (b_res == bDelete) {
     2101                    delete_mountlist_entry(mountlist, raidlist,
     2102                                           partitionsListbox, currline,
     2103                                           keylist);
     2104                } else {
     2105                    if (mountlist->entries > 0) {
     2106                        edit_mountlist_entry(mountlist, raidlist,
     2107                                             partitionsListbox, currline,
     2108                                             keylist);
     2109                    } else {
     2110                        popup_and_OK
     2111                            ("Please add an entry. Then press ENTER to edit it.");
     2112                    }
     2113                }
     2114            }
     2115        }
     2116    }
     2117    newtFormDestroy(myForm);
     2118    newtPopWindow();
     2119    newtPopHelpLine();
     2120    if (b_res == bOK) {
     2121        log_it("You pushed 'OK'. I shall now continue.");
     2122        return (0);
     2123    } else {
     2124        /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */
     2125        return (1);
     2126    }
    22442127}
    22452128
     
    22532136 */
    22542137int
    2255 edit_mountlist (char *mountlist_fname, struct mountlist_itself *mountlist,
    2256         struct raidlist_itself *raidlist)
    2257 {
    2258   int res=0;
     2138edit_mountlist(char *mountlist_fname, struct mountlist_itself *mountlist,
     2139               struct raidlist_itself *raidlist)
     2140{
     2141    int res = 0;
    22592142//  char tmp[MAX_STR_LEN];
    22602143
    2261   iamhere("entering eml");
    2262 
    2263   if (g_text_mode)
    2264     {
    2265       fatal_error("Don't call edit_mountlist() in text mode");
    2266     }
    2267   else
    2268     {
    2269       log_it("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()");
    2270       res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist);
    2271     }
    2272   iamhere("leaving eml");
    2273   return(res);
     2144    iamhere("entering eml");
     2145
     2146    if (g_text_mode) {
     2147        fatal_error("Don't call edit_mountlist() in text mode");
     2148    } else {
     2149        log_it
     2150            ("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()");
     2151        res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist);
     2152    }
     2153    iamhere("leaving eml");
     2154    return (res);
    22742155}
    22752156
     
    22832164 * @ingroup restoreGuiVarslist
    22842165 */
    2285 void
    2286 edit_raidrec_additional_vars (struct raid_device_record *raidrec)
     2166void edit_raidrec_additional_vars(struct raid_device_record *raidrec)
    22872167{
    22882168
    22892169    /** structure *********************************************************/
    2290   struct raid_device_record bkp_raidrec;
     2170    struct raid_device_record bkp_raidrec;
    22912171
    22922172    /** newt **************************************************************/
    2293   newtComponent myForm;
     2173    newtComponent myForm;
    22942174    newtComponent bAdd;
    22952175    newtComponent bEdit;
     
    23022182
    23032183    /** ?? ***************************************************************/
    2304   void *keylist[ARBITRARY_MAXIMUM], *curr_choice;
     2184    void *keylist[ARBITRARY_MAXIMUM], *curr_choice;
    23052185
    23062186    /** buffers **********************************************************/
    2307   char title_of_window[MAX_STR_LEN];
     2187    char title_of_window[MAX_STR_LEN];
    23082188
    23092189    /** int **************************************************************/
    2310   int i = 0;
     2190    int i = 0;
    23112191    int currline = 0;
    23122192
    23132193
    2314   assert(raidrec!=NULL);
    2315 
    2316   memcpy ((void *) &bkp_raidrec, (void *) raidrec,
    2317       sizeof (struct raid_device_record));
    2318   sprintf (title_of_window, "Additional variables");
    2319   newtPushHelpLine
    2320     ("  Edit the additional fields to your heart's content, then click OK or Cancel.");
    2321   headerMsg = newtLabel (1, 1, "Label                            Value");
    2322   varsListbox =
    2323     newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    2324   i = 1;
    2325   bAdd = newtCompactButton (i, 9, " Add ");
    2326   bEdit = newtCompactButton (i += 8, 9, " Edit ");
    2327   bDelete = newtCompactButton (i += 9, 9, "Delete");
    2328   bOK = newtCompactButton (i += 9, 9, "  OK  ");
    2329   bCancel = newtCompactButton (i += 9, 9, "Cancel");
    2330   newtOpenWindow (17, 7, 46, 10, title_of_window);
    2331   myForm = newtForm (NULL, NULL, 0);
    2332   newtFormAddComponents (myForm, headerMsg, varsListbox, bAdd, bEdit, bDelete,
    2333              bOK, bCancel, NULL);
    2334   insert_essential_additionalvars (raidrec);
    2335   redraw_varslist (&raidrec->additional_vars, keylist, varsListbox);
    2336   for (b_res = NULL; b_res != bOK && b_res != bCancel;)
    2337     {
    2338       b_res = newtRunForm (myForm);
    2339       curr_choice = newtListboxGetCurrent (varsListbox);
    2340       for (currline = 0;
    2341        currline < raidrec->additional_vars.entries
    2342        && keylist[currline] != curr_choice; currline++);
    2343       if (currline == raidrec->additional_vars.entries
    2344       && raidrec->additional_vars.entries > 0)
    2345     {
    2346       log_it ("Warning - I don't know what this button does");
    2347     }
    2348       if (b_res == bOK)
    2349     {           /* do nothing */
    2350     }
    2351       else if (b_res == bCancel)
    2352     {           /* do nothing */
    2353     }
    2354       else if (b_res == bAdd)
    2355     {
    2356       add_varslist_entry (raidrec);
    2357     }
    2358       else if (b_res == bDelete)
    2359     {
    2360       delete_varslist_entry (raidrec, currline);
    2361     }
    2362       else
    2363     {
    2364       edit_varslist_entry (raidrec, currline);
    2365     }
    2366       redraw_varslist (&raidrec->additional_vars, keylist, varsListbox);
    2367     }
    2368   remove_essential_additionalvars (raidrec);
    2369   newtFormDestroy (myForm);
    2370   newtPopWindow ();
    2371   newtPopHelpLine ();
    2372   if (b_res == bCancel)
    2373     {
    2374       memcpy ((void *) raidrec, (void *) &bkp_raidrec,
    2375           sizeof (struct raid_device_record));
    2376     }
    2377   return;
     2194    assert(raidrec != NULL);
     2195
     2196    memcpy((void *) &bkp_raidrec, (void *) raidrec,
     2197           sizeof(struct raid_device_record));
     2198    sprintf(title_of_window, "Additional variables");
     2199    newtPushHelpLine
     2200        ("  Edit the additional fields to your heart's content, then click OK or Cancel.");
     2201    headerMsg = newtLabel(1, 1, "Label                            Value");
     2202    varsListbox =
     2203        newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     2204    i = 1;
     2205    bAdd = newtCompactButton(i, 9, " Add ");
     2206    bEdit = newtCompactButton(i += 8, 9, " Edit ");
     2207    bDelete = newtCompactButton(i += 9, 9, "Delete");
     2208    bOK = newtCompactButton(i += 9, 9, "  OK  ");
     2209    bCancel = newtCompactButton(i += 9, 9, "Cancel");
     2210    newtOpenWindow(17, 7, 46, 10, title_of_window);
     2211    myForm = newtForm(NULL, NULL, 0);
     2212    newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit,
     2213                          bDelete, bOK, bCancel, NULL);
     2214    insert_essential_additionalvars(raidrec);
     2215    redraw_varslist(&raidrec->additional_vars, keylist, varsListbox);
     2216    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
     2217        b_res = newtRunForm(myForm);
     2218        curr_choice = newtListboxGetCurrent(varsListbox);
     2219        for (currline = 0;
     2220             currline < raidrec->additional_vars.entries
     2221             && keylist[currline] != curr_choice; currline++);
     2222        if (currline == raidrec->additional_vars.entries
     2223            && raidrec->additional_vars.entries > 0) {
     2224            log_it("Warning - I don't know what this button does");
     2225        }
     2226        if (b_res == bOK) {     /* do nothing */
     2227        } else if (b_res == bCancel) {  /* do nothing */
     2228        } else if (b_res == bAdd) {
     2229            add_varslist_entry(raidrec);
     2230        } else if (b_res == bDelete) {
     2231            delete_varslist_entry(raidrec, currline);
     2232        } else {
     2233            edit_varslist_entry(raidrec, currline);
     2234        }
     2235        redraw_varslist(&raidrec->additional_vars, keylist, varsListbox);
     2236    }
     2237    remove_essential_additionalvars(raidrec);
     2238    newtFormDestroy(myForm);
     2239    newtPopWindow();
     2240    newtPopHelpLine();
     2241    if (b_res == bCancel) {
     2242        memcpy((void *) raidrec, (void *) &bkp_raidrec,
     2243               sizeof(struct raid_device_record));
     2244    }
     2245    return;
    23782246}
    23792247#endif
     
    23862254 * @ingroup restoreGuiDisklist
    23872255 */
    2388 int
    2389 find_next_free_index_in_disklist (struct list_of_disks *disklist)
     2256int find_next_free_index_in_disklist(struct list_of_disks *disklist)
    23902257{
    23912258
    23922259    /** int ***************************************************************/
    2393   int index = -1;
     2260    int index = -1;
    23942261    int pos = 0;
    2395    
     2262
    23962263  /** bool **************************************************************/
    2397   bool done;
    2398 
    2399   assert(disklist!=NULL);
    2400 
    2401   for (done = FALSE; !done;)
    2402     {
    2403       for (pos = 0;
    2404        pos < disklist->entries && disklist->el[pos].index <= index;
    2405        pos++);
    2406       if (pos >= disklist->entries)
    2407     {
    2408       done = TRUE;
    2409     }
    2410       else
    2411     {
    2412       index = disklist->el[pos].index;
    2413     }
    2414     }
    2415   return (index + 1);
     2264    bool done;
     2265
     2266    assert(disklist != NULL);
     2267
     2268    for (done = FALSE; !done;) {
     2269        for (pos = 0;
     2270             pos < disklist->entries && disklist->el[pos].index <= index;
     2271             pos++);
     2272        if (pos >= disklist->entries) {
     2273            done = TRUE;
     2274        } else {
     2275            index = disklist->el[pos].index;
     2276        }
     2277    }
     2278    return (index + 1);
    24162279}
    24172280
     
    24262289 */
    24272290int
    2428 find_raid_device_in_raidlist (struct raidlist_itself *raidlist, char *device)
     2291find_raid_device_in_raidlist(struct raidlist_itself *raidlist,
     2292                             char *device)
    24292293{
    24302294
    24312295    /** int ***************************************************************/
    2432   int i = 0;
     2296    int i = 0;
    24332297#ifdef __FreeBSD__
    2434   char vdev [64];
     2298    char vdev[64];
    24352299#else
    24362300// Linux
    24372301#endif
    2438  
    2439   assert(raidlist!=NULL);
    2440   assert_string_is_neither_NULL_nor_zerolength(device);
     2302
     2303    assert(raidlist != NULL);
     2304    assert_string_is_neither_NULL_nor_zerolength(device);
    24412305
    24422306#ifdef __FreeBSD__
    2443   for (i = 0; i < raidlist->entries; i++) {
    2444       sprintf (vdev, "/dev/vinum/%s", raidlist->el[i].volname);
    2445       if (!strcmp (device, vdev)) break;
    2446   }
     2307    for (i = 0; i < raidlist->entries; i++) {
     2308        sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
     2309        if (!strcmp(device, vdev))
     2310            break;
     2311    }
    24472312#else
    24482313
    2449   for (i = 0;
    2450        strcmp (raidlist->el[i].raid_device, device) && i < raidlist->entries;
    2451       i++);
     2314    for (i = 0;
     2315         strcmp(raidlist->el[i].raid_device, device)
     2316         && i < raidlist->entries; i++);
    24522317#endif
    2453   if (i == raidlist->entries)
    2454     {
    2455       return (-1);
    2456     }
    2457   else
    2458     {
    2459       return (i);
    2460     }
     2318    if (i == raidlist->entries) {
     2319        return (-1);
     2320    } else {
     2321        return (i);
     2322    }
    24612323}
    24622324
     
    24712333 */
    24722334bool
    2473 get_isodir_info (char *isodir_device, char *isodir_format, char *isodir_path, bool nuke_me_please)
     2335get_isodir_info(char *isodir_device, char *isodir_format,
     2336                char *isodir_path, bool nuke_me_please)
    24742337{
    24752338
    24762339    /** initialize ********************************************************/
    24772340
    2478   assert(isodir_device!=NULL);
    2479   assert(isodir_format!=NULL);
    2480   assert(isodir_path!=NULL);
    2481 
    2482   log_it("%d - AAA - isodir_path = %s", isodir_path);
    2483   isodir_format[0] = '\0';
    2484   if (isodir_device[0]=='\0') { strcpy (isodir_device, "/dev/"); }
    2485   if (isodir_path[0]=='\0') { strcpy (isodir_path, "/"); }
    2486   if (does_file_exist ("/tmp/NFS-SERVER-PATH"))
    2487     {
    2488       strcpy (isodir_device, last_line_of_file ("/tmp/NFS-SERVER-MOUNT"));
    2489       strcpy (isodir_format, "nfs");
    2490       strcpy (isodir_path, last_line_of_file ("/tmp/NFS-SERVER-PATH"));
    2491     }
    2492   if (nuke_me_please) { return(TRUE); }
    2493 
    2494   if (popup_and_get_string
    2495       ("ISO Mode - device", "On what device do the ISO files live?",
    2496        isodir_device, MAX_STR_LEN/4))
    2497     {
    2498       if (popup_and_get_string
    2499       ("ISO Mode - format",
    2500        "What is the disk format of the device? (Hit ENTER if you don't know.)",
    2501        isodir_format, 16))
    2502     {
    2503       if (popup_and_get_string
    2504           ("ISO Mode - path",
    2505            "At what path on this device can the ISO files be found?",
    2506            isodir_path, MAX_STR_LEN/4))
    2507         {
    2508           strip_spaces (isodir_device);
    2509           strip_spaces (isodir_format);
    2510           strip_spaces (isodir_path);
    2511   log_it("%d - BBB - isodir_path = %s", isodir_path);
    2512           return (TRUE);
    2513         }
    2514     }
    2515     }
    2516   return (FALSE);
     2341    assert(isodir_device != NULL);
     2342    assert(isodir_format != NULL);
     2343    assert(isodir_path != NULL);
     2344
     2345    log_it("%d - AAA - isodir_path = %s", isodir_path);
     2346    isodir_format[0] = '\0';
     2347    if (isodir_device[0] == '\0') {
     2348        strcpy(isodir_device, "/dev/");
     2349    }
     2350    if (isodir_path[0] == '\0') {
     2351        strcpy(isodir_path, "/");
     2352    }
     2353    if (does_file_exist("/tmp/NFS-SERVER-PATH")) {
     2354        strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT"));
     2355        strcpy(isodir_format, "nfs");
     2356        strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH"));
     2357    }
     2358    if (nuke_me_please) {
     2359        return (TRUE);
     2360    }
     2361
     2362    if (popup_and_get_string
     2363        ("ISO Mode - device", "On what device do the ISO files live?",
     2364         isodir_device, MAX_STR_LEN / 4)) {
     2365        if (popup_and_get_string
     2366            ("ISO Mode - format",
     2367             "What is the disk format of the device? (Hit ENTER if you don't know.)",
     2368             isodir_format, 16)) {
     2369            if (popup_and_get_string
     2370                ("ISO Mode - path",
     2371                 "At what path on this device can the ISO files be found?",
     2372                 isodir_path, MAX_STR_LEN / 4)) {
     2373                strip_spaces(isodir_device);
     2374                strip_spaces(isodir_format);
     2375                strip_spaces(isodir_path);
     2376                log_it("%d - BBB - isodir_path = %s", isodir_path);
     2377                return (TRUE);
     2378            }
     2379        }
     2380    }
     2381    return (FALSE);
    25172382}
    25182383
     
    25272392 */
    25282393void
    2529 initiate_new_raidlist_entry (struct raidlist_itself *raidlist,
    2530                  struct mountlist_itself *mountlist, int currline,
    2531                 char *device)
     2394initiate_new_raidlist_entry(struct raidlist_itself *raidlist,
     2395                            struct mountlist_itself *mountlist,
     2396                            int currline, char *device)
    25322397{
    25332398
    25342399    /** structure *********************************************************/
    2535   struct OSSWAP (raid_device_record, vinum_volume) *raidrec;
     2400    struct OSSWAP (raid_device_record, vinum_volume) * raidrec;
    25362401
    25372402    /** int ***************************************************************/
    2538   int pos_in_raidlist = 0;
    2539 
    2540   assert(raidlist!=NULL);
    2541   assert(mountlist!=NULL);
    2542   assert_string_is_neither_NULL_nor_zerolength(device);
    2543 
    2544   pos_in_raidlist =
    2545     find_raid_device_in_raidlist (raidlist, mountlist->el[currline].device);
    2546   if (pos_in_raidlist >= 0)
    2547     {
    2548       fatal_error ("Sorry, that RAID device already exists. Weird.");
    2549     }
    2550   pos_in_raidlist = raidlist->entries++;
    2551   raidrec = &raidlist->el[pos_in_raidlist];
    2552   initialize_raidrec (raidrec);
    2553   strcpy (raidrec->OSSWAP (raid_device, volname), OSSWAP (device, basename (device)));
     2403    int pos_in_raidlist = 0;
     2404
     2405    assert(raidlist != NULL);
     2406    assert(mountlist != NULL);
     2407    assert_string_is_neither_NULL_nor_zerolength(device);
     2408
     2409    pos_in_raidlist =
     2410        find_raid_device_in_raidlist(raidlist,
     2411                                     mountlist->el[currline].device);
     2412    if (pos_in_raidlist >= 0) {
     2413        fatal_error("Sorry, that RAID device already exists. Weird.");
     2414    }
     2415    pos_in_raidlist = raidlist->entries++;
     2416    raidrec = &raidlist->el[pos_in_raidlist];
     2417    initialize_raidrec(raidrec);
     2418    strcpy(raidrec->OSSWAP(raid_device, volname),
     2419           OSSWAP(device, basename(device)));
    25542420#ifndef __FreeBSD__
    2555   choose_raid_level (raidrec);
    2556   select_raid_disks (mountlist, raidlist, raidrec, "data",
    2557              &raidrec->data_disks);
     2421    choose_raid_level(raidrec);
     2422    select_raid_disks(mountlist, raidlist, raidrec, "data",
     2423                      &raidrec->data_disks);
    25582424#endif
    2559   edit_raidlist_entry (mountlist, raidlist, raidrec, currline);
     2425    edit_raidlist_entry(mountlist, raidlist, raidrec, currline);
    25602426}
    25612427
     
    25672433 * @ingroup restoreGuiVarslist
    25682434 */
    2569 void
    2570 insert_essential_additionalvars (struct raid_device_record *raidrec)
     2435void insert_essential_additionalvars(struct raid_device_record *raidrec)
    25712436{
    25722437
    25732438    /** int **************************************************************/
    2574   int items = 0;
    2575 
    2576   assert(raidrec!=NULL);
    2577 
    2578   items = raidrec->additional_vars.entries;
    2579   write_variableINT_to_raid_var_line (raidrec, items++,
    2580                       "persistent-superblock",
    2581                       raidrec->persistent_superblock);
    2582   write_variableINT_to_raid_var_line (raidrec, items++, "chunk-size",
    2583                       raidrec->chunk_size);
    2584   raidrec->additional_vars.entries = items;
     2439    int items = 0;
     2440
     2441    assert(raidrec != NULL);
     2442
     2443    items = raidrec->additional_vars.entries;
     2444    write_variableINT_to_raid_var_line(raidrec, items++,
     2445                                       "persistent-superblock",
     2446                                       raidrec->persistent_superblock);
     2447    write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size",
     2448                                       raidrec->chunk_size);
     2449    raidrec->additional_vars.entries = items;
    25852450}
    25862451
     
    25902455 * Dummy function that proves that we can get to the point where Mondo is run.
    25912456 */
    2592 void
    2593 nuke_mode_dummy ()
     2457void nuke_mode_dummy()
    25942458{
    25952459
    25962460    /** newt *************************************************************/
    2597   newtComponent myForm;
     2461    newtComponent myForm;
    25982462    newtComponent b1;
    25992463    newtComponent b2;
     
    26022466
    26032467
    2604   newtPushHelpLine
    2605     ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!");
    2606   newtOpenWindow (24, 3, 32, 13, "Nuking");
    2607   b1 = newtButton (7, 1, "Slowly");
    2608   b2 = newtButton (7, 5, "Medium");
    2609   b3 = newtButton (7, 9, "Quickly");
    2610   myForm = newtForm (NULL, NULL, 0);
    2611   newtFormAddComponents (myForm, b1, b2, b3, NULL);
    2612   b_res = newtRunForm (myForm);
    2613   newtFormDestroy (myForm);
    2614   newtPopWindow ();
    2615   newtPopHelpLine ();
     2468    newtPushHelpLine
     2469        ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!");
     2470    newtOpenWindow(24, 3, 32, 13, "Nuking");
     2471    b1 = newtButton(7, 1, "Slowly");
     2472    b2 = newtButton(7, 5, "Medium");
     2473    b3 = newtButton(7, 9, "Quickly");
     2474    myForm = newtForm(NULL, NULL, 0);
     2475    newtFormAddComponents(myForm, b1, b2, b3, NULL);
     2476    b_res = newtRunForm(myForm);
     2477    newtFormDestroy(myForm);
     2478    newtPopWindow();
     2479    newtPopHelpLine();
    26162480}
    26172481
     
    26262490 */
    26272491void
    2628 redraw_disklist (struct list_of_disks *disklist,
    2629          void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
     2492redraw_disklist(struct list_of_disks *disklist,
     2493                void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
    26302494{
    26312495
    26322496    /** int *************************************************************/
    2633   int i = 0;
    2634 
    2635   assert(disklist!=NULL);
    2636   assert(keylist!=NULL);
    2637   assert(listbox!=NULL);
    2638 
    2639   newtListboxClear (listbox);
    2640 
    2641   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2642     {
    2643       keylist[i] = (void *) i;
    2644     }
    2645   for (i = 0; i < disklist->entries; i++)
    2646     {
    2647       newtListboxAppendEntry (listbox, disklist_entry_to_string (disklist, i),
    2648                   keylist[i]);
    2649     }
     2497    int i = 0;
     2498
     2499    assert(disklist != NULL);
     2500    assert(keylist != NULL);
     2501    assert(listbox != NULL);
     2502
     2503    newtListboxClear(listbox);
     2504
     2505    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2506        keylist[i] = (void *) i;
     2507    }
     2508    for (i = 0; i < disklist->entries; i++) {
     2509        newtListboxAppendEntry(listbox,
     2510                               disklist_entry_to_string(disklist, i),
     2511                               keylist[i]);
     2512    }
    26502513}
    26512514
     
    26592522 */
    26602523void
    2661 redraw_mountlist (struct mountlist_itself *mountlist,
    2662           void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
    2663 {
    2664    
     2524redraw_mountlist(struct mountlist_itself *mountlist,
     2525                void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox)
     2526{
     2527
    26652528    /** int **************************************************************/
    2666   int i = 0;
    2667 
    2668   assert(mountlist!=NULL);
    2669   assert(keylist!=NULL);
    2670   assert(listbox!=NULL);
    2671 
    2672   newtListboxClear (listbox);
     2529    int i = 0;
     2530
     2531    assert(mountlist != NULL);
     2532    assert(keylist != NULL);
     2533    assert(listbox != NULL);
     2534
     2535    newtListboxClear(listbox);
    26732536//  sort_mountlist_by_device (mountlist);
    2674   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2675     {
    2676       keylist[i] = (void *) i;
    2677     }
    2678   for (i = 0; i < mountlist->entries; i++)
    2679     {
    2680       newtListboxAppendEntry (listbox,
    2681                   mountlist_entry_to_string (mountlist, i),
    2682                   keylist[i]);
    2683     }
     2537    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2538        keylist[i] = (void *) i;
     2539    }
     2540    for (i = 0; i < mountlist->entries; i++) {
     2541        newtListboxAppendEntry(listbox,
     2542                               mountlist_entry_to_string(mountlist, i),
     2543                               keylist[i]);
     2544    }
    26842545}
    26852546
     
    26942555 * @ingroup restoreGuiDisklist
    26952556 */
    2696 void
    2697 redraw_unallocpartnslist (struct mountlist_itself
    2698               *unallocated_raid_partitions,
    2699               void *keylist[ARBITRARY_MAXIMUM],
    2700               newtComponent listbox)
     2557void redraw_unallocpartnslist(struct mountlist_itself
     2558                              *unallocated_raid_partitions,
     2559                              void *keylist[ARBITRARY_MAXIMUM],
     2560                              newtComponent listbox)
    27012561{
    27022562
    27032563    /** int **************************************************************/
    2704   int i = 0;
     2564    int i = 0;
    27052565
    27062566    /** buffers **********************************************************/
    2707   char tmp[MAX_STR_LEN];
    2708 
    2709   assert(unallocated_raid_partitions!=NULL);
    2710   assert(keylist!=NULL);
    2711   assert(listbox!=NULL);
    2712 
    2713   newtListboxClear (listbox);
    2714   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2715     {
    2716       keylist[i] = (void *) i;
    2717     }
    2718   for (i = 0; i < unallocated_raid_partitions->entries; i++)
    2719     {
    2720       sprintf (tmp, "%-22s %8lld", unallocated_raid_partitions->el[i].device,
    2721            unallocated_raid_partitions->el[i].size / 1024);
    2722       newtListboxAppendEntry (listbox, tmp, keylist[i]);
    2723     }
     2567    char tmp[MAX_STR_LEN];
     2568
     2569    assert(unallocated_raid_partitions != NULL);
     2570    assert(keylist != NULL);
     2571    assert(listbox != NULL);
     2572
     2573    newtListboxClear(listbox);
     2574    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2575        keylist[i] = (void *) i;
     2576    }
     2577    for (i = 0; i < unallocated_raid_partitions->entries; i++) {
     2578        sprintf(tmp, "%-22s %8lld",
     2579                unallocated_raid_partitions->el[i].device,
     2580                unallocated_raid_partitions->el[i].size / 1024);
     2581        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2582    }
    27242583}
    27252584
     
    27332592 */
    27342593void
    2735 redraw_varslist (struct additional_raid_variables *additional_vars,
    2736          void *keylist[], newtComponent listbox)
     2594redraw_varslist(struct additional_raid_variables *additional_vars,
     2595                void *keylist[], newtComponent listbox)
    27372596{
    27382597    /** int *************************************************************/
    2739   int i = 0;
     2598    int i = 0;
    27402599
    27412600    /** buffers *********************************************************/
    2742   char tmp[MAX_STR_LEN];
    2743 
    2744   assert(additional_vars!=NULL);
    2745   assert(keylist!=NULL);
    2746   assert(listbox!=NULL);
    2747 
    2748   newtListboxClear (listbox);
    2749 
    2750   for (i = 0; i < ARBITRARY_MAXIMUM; i++)
    2751     {
    2752       keylist[i] = (void *) i;
    2753     }
    2754   for (i = 0; i < additional_vars->entries; i++)
    2755     {
    2756       sprintf (tmp, "%-32s %-8s", additional_vars->el[i].label,
    2757            additional_vars->el[i].value);
    2758       newtListboxAppendEntry (listbox, tmp, keylist[i]);
    2759     }
     2601    char tmp[MAX_STR_LEN];
     2602
     2603    assert(additional_vars != NULL);
     2604    assert(keylist != NULL);
     2605    assert(listbox != NULL);
     2606
     2607    newtListboxClear(listbox);
     2608
     2609    for (i = 0; i < ARBITRARY_MAXIMUM; i++) {
     2610        keylist[i] = (void *) i;
     2611    }
     2612    for (i = 0; i < additional_vars->entries; i++) {
     2613        sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label,
     2614                additional_vars->el[i].value);
     2615        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2616    }
    27602617}
    27612618
     
    27692626 */
    27702627int
    2771 read_variableINT_and_remove_from_raidvars (struct OSSWAP (raid_device_record, vinum_volume) *raidrec,
    2772                        char *label)
     2628read_variableINT_and_remove_from_raidvars(struct
     2629                                          OSSWAP (raid_device_record,
     2630                                                  vinum_volume) * raidrec,
     2631                                          char *label)
    27732632{
    27742633    /** int ***************************************************************/
    2775   int i = 0;
     2634    int i = 0;
    27762635    int res = 0;
    27772636
    27782637
    2779   assert(raidrec!=NULL);
    2780   assert(label!=NULL);
    2781 
    2782   for (i = 0;
    2783        i < raidrec->additional_vars.entries
    2784        && strcmp (raidrec->additional_vars.el[i].label, label); i++);
    2785   if (i == raidrec->additional_vars.entries)
    2786     {
    2787       res = -1;
    2788     }
    2789   else
    2790     {
    2791       res = atoi (raidrec->additional_vars.el[i].value);
    2792       for (i++; i < raidrec->additional_vars.entries; i++)
    2793     {
    2794       memcpy ((void *) &raidrec->additional_vars.el[i - 1],
    2795           (void *) &raidrec->additional_vars.el[i],
    2796           sizeof (struct raid_var_line));
    2797     }
    2798       raidrec->additional_vars.entries--;
    2799     }
    2800   return (res);
     2638    assert(raidrec != NULL);
     2639    assert(label != NULL);
     2640
     2641    for (i = 0;
     2642         i < raidrec->additional_vars.entries
     2643         && strcmp(raidrec->additional_vars.el[i].label, label); i++);
     2644    if (i == raidrec->additional_vars.entries) {
     2645        res = -1;
     2646    } else {
     2647        res = atoi(raidrec->additional_vars.el[i].value);
     2648        for (i++; i < raidrec->additional_vars.entries; i++) {
     2649            memcpy((void *) &raidrec->additional_vars.el[i - 1],
     2650                   (void *) &raidrec->additional_vars.el[i],
     2651                   sizeof(struct raid_var_line));
     2652        }
     2653        raidrec->additional_vars.entries--;
     2654    }
     2655    return (res);
    28012656}
    28022657#endif
     
    28092664 * @ingroup restoreGuiMountlist
    28102665 */
    2811 void
    2812 rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself
    2813                            *raidlist, char *old_dev,
    2814                            char *new_dev)
     2666void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself
     2667                                                   *raidlist,
     2668                                                  char *old_dev,
     2669                                                   char *new_dev)
    28152670{
    28162671    /** buffers ********************************************************/
    2817   char tmp[MAX_STR_LEN];
     2672    char tmp[MAX_STR_LEN];
    28182673
    28192674    /** int ************************************************************/
    2820   int pos = 0;
     2675    int pos = 0;
    28212676    int j = 0;
    28222677
    2823   assert(raidlist!=NULL);
    2824   assert_string_is_neither_NULL_nor_zerolength(old_dev);
    2825   assert_string_is_neither_NULL_nor_zerolength(new_dev);
    2826 
    2827   pos = which_raid_device_is_using_this_partition (raidlist, old_dev);
    2828   if (pos < 0)
    2829     {
    2830       sprintf (tmp, "No need to rejig %s in raidlist: it's not listed.",
    2831            old_dev);
    2832       log_it (tmp);
    2833     }
    2834   else
    2835     {
    2836       if ((j =
    2837        where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].data_disks, disks),
    2838                     old_dev)) >= 0)
    2839     {
    2840       strcpy (raidlist->OSSWAP (el[pos].data_disks, disks).el[j].device, new_dev);
    2841     }
    2842       else
    2843     if ((j =
    2844          where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].spare_disks, spares),
    2845                       old_dev)) >= 0)
    2846     {
    2847       strcpy (raidlist->OSSWAP (el[pos].spare_disks, spares).el[j].device, new_dev);
    2848     }
     2678    assert(raidlist != NULL);
     2679    assert_string_is_neither_NULL_nor_zerolength(old_dev);
     2680    assert_string_is_neither_NULL_nor_zerolength(new_dev);
     2681
     2682    pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
     2683    if (pos < 0) {
     2684        sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",
     2685                old_dev);
     2686        log_it(tmp);
     2687    } else {
     2688        if ((j =
     2689             where_in_drivelist_is_drive(&raidlist->
     2690                                         OSSWAP(el[pos].data_disks, disks),
     2691                                         old_dev)) >= 0) {
     2692            strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].
     2693                   device, new_dev);
     2694        } else
     2695            if ((j =
     2696                 where_in_drivelist_is_drive(&raidlist->
     2697                                             OSSWAP(el[pos].spare_disks,
     2698                                                    spares),
     2699                                             old_dev)) >= 0) {
     2700            strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].
     2701                   device, new_dev);
     2702        }
    28492703#ifndef __FreeBSD__
    2850       else
    2851     if ((j =
    2852          where_in_drivelist_is_drive (&raidlist->el[pos].parity_disks,
    2853                       old_dev)) >= 0)
    2854     {
    2855       strcpy (raidlist->el[pos].parity_disks.el[j].device, new_dev);
    2856     }
    2857       else
    2858     if ((j =
    2859          where_in_drivelist_is_drive (&raidlist->el[pos].failed_disks,
    2860                       old_dev)) >= 0)
    2861     {
    2862       strcpy (raidlist->el[pos].failed_disks.el[j].device, new_dev);
    2863     }
     2704        else if ((j =
     2705                  where_in_drivelist_is_drive(&raidlist->el[pos].
     2706                                              parity_disks,
     2707                                              old_dev)) >= 0) {
     2708            strcpy(raidlist->el[pos].parity_disks.el[j].device, new_dev);
     2709        } else
     2710            if ((j =
     2711                 where_in_drivelist_is_drive(&raidlist->el[pos].
     2712                                             failed_disks,
     2713                                             old_dev)) >= 0) {
     2714            strcpy(raidlist->el[pos].failed_disks.el[j].device, new_dev);
     2715        }
    28642716#endif
    2865       else
    2866     {
    2867       sprintf (tmp,
    2868            "%s is supposed to be listed in this raid dev but it's not...",
    2869            old_dev);
    2870       log_it (tmp);
    2871     }
    2872     }
     2717        else {
     2718            sprintf(tmp,
     2719                    "%s is supposed to be listed in this raid dev but it's not...",
     2720                    old_dev);
     2721            log_it(tmp);
     2722        }
     2723    }
    28732724}
    28742725
     
    28812732 * @ingroup restoreUtilityVarslist
    28822733 */
    2883 void
    2884 remove_essential_additionalvars (struct raid_device_record *raidrec)
     2734void remove_essential_additionalvars(struct raid_device_record *raidrec)
    28852735{
    28862736
    28872737    /** int **************************************************************/
    2888   int res = 0;
    2889 
    2890   assert(raidrec!=NULL);
    2891 
    2892 res =
    2893     read_variableINT_and_remove_from_raidvars (raidrec,
    2894                            "persistent-superblock");
    2895   if (res > 0)
    2896     {
    2897       raidrec->persistent_superblock = res;
    2898     }
    2899   res = read_variableINT_and_remove_from_raidvars (raidrec, "chunk-size");
    2900   if (res > 0)
    2901     {
    2902       raidrec->chunk_size = res;
    2903     }
    2904   res = read_variableINT_and_remove_from_raidvars (raidrec, "block-size");
     2738    int res = 0;
     2739
     2740    assert(raidrec != NULL);
     2741
     2742    res =
     2743        read_variableINT_and_remove_from_raidvars(raidrec,
     2744                                                  "persistent-superblock");
     2745    if (res > 0) {
     2746        raidrec->persistent_superblock = res;
     2747    }
     2748    res = read_variableINT_and_remove_from_raidvars(raidrec, "chunk-size");
     2749    if (res > 0) {
     2750        raidrec->chunk_size = res;
     2751    }
     2752    res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size");
    29052753}
    29062754
     
    29152763 */
    29162764void
    2917 select_raid_disks (struct mountlist_itself *mountlist_dontedit,
    2918            struct raidlist_itself *raidlist,
    2919            struct raid_device_record *raidrec,
    2920            char *description_of_list, struct list_of_disks *disklist)
    2921 {
    2922   void *curr_choice;
     2765select_raid_disks(struct mountlist_itself *mountlist_dontedit,
     2766                  struct raidlist_itself *raidlist,
     2767                  struct raid_device_record *raidrec,
     2768                  char *description_of_list,
     2769                  struct list_of_disks *disklist)
     2770{
     2771    void *curr_choice;
    29232772
    29242773    /** ??? ***************************************************************/
    29252774
    29262775    /** structures ********************************************************/
    2927   struct raidlist_itself *bkp_raidlist;
    2928   struct raid_device_record *bkp_raidrec;
    2929   struct list_of_disks *bkp_disklist;
    2930   struct mountlist_itself *unallocated_raid_partitions;
     2776    struct raidlist_itself *bkp_raidlist;
     2777    struct raid_device_record *bkp_raidrec;
     2778    struct list_of_disks *bkp_disklist;
     2779    struct mountlist_itself *unallocated_raid_partitions;
    29312780
    29322781    /** newt **************************************************************/
    2933   newtComponent myForm=NULL;
    2934   newtComponent bAdd=NULL;
    2935     newtComponent bDelete=NULL;
    2936     newtComponent bOK=NULL;
    2937     newtComponent bCancel=NULL;
    2938     newtComponent b_res=NULL;
    2939     newtComponent partitionsListbox=NULL;
    2940     newtComponent headerMsg=NULL;
     2782    newtComponent myForm = NULL;
     2783    newtComponent bAdd = NULL;
     2784    newtComponent bDelete = NULL;
     2785    newtComponent bOK = NULL;
     2786    newtComponent bCancel = NULL;
     2787    newtComponent b_res = NULL;
     2788    newtComponent partitionsListbox = NULL;
     2789    newtComponent headerMsg = NULL;
    29412790
    29422791    /** buffers **********************************************************/
    2943   void *keylist[ARBITRARY_MAXIMUM];
    2944   char *tmp;
    2945   char *help_text;
    2946   char *title_of_window;
    2947   char *sz_res;
    2948   char *header_text;
     2792    void *keylist[ARBITRARY_MAXIMUM];
     2793    char *tmp;
     2794    char *help_text;
     2795    char *title_of_window;
     2796    char *sz_res;
     2797    char *header_text;
    29492798
    29502799  /** int **************************************************************/
    2951   int i = 0;
    2952   int currline = 0;
    2953 
    2954   assert(mountlist_dontedit!=NULL);
    2955   assert(raidlist!=NULL);
    2956   assert(raidrec!=NULL);
    2957   assert(description_of_list!=NULL);
    2958   assert(disklist!=NULL);
    2959 
    2960   iamhere("malloc'ing");
    2961   malloc_string(tmp);
    2962   malloc_string(help_text);
    2963   malloc_string(title_of_window);
    2964   malloc_string(sz_res);
    2965   malloc_string(header_text);
    2966   if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record))))
    2967     { fatal_error("Cannot malloc space for raidrec"); }
    2968   if (!(bkp_disklist = malloc(sizeof(struct list_of_disks))))
    2969     { fatal_error("Cannot malloc space for disklist"); }
    2970   if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself))))
    2971     { fatal_error("Cannot malloc space for raidlist"); }
    2972   if (!(unallocated_raid_partitions = malloc(sizeof(struct mountlist_itself))))
    2973     { fatal_error("Cannot malloc space for unallocated_raid_partitions"); }
    2974 
    2975   memcpy ((void *) bkp_raidlist, (void *) raidlist,
    2976       sizeof (struct raidlist_itself));
    2977   memcpy ((void *) bkp_raidrec, (void *) raidrec,
    2978       sizeof (struct raid_device_record));
    2979   memcpy ((void *) bkp_disklist, (void *) disklist,
    2980       sizeof (struct list_of_disks));
    2981 
    2982   iamhere("Post-malloc");
    2983   strcpy (help_text,
    2984       "   Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
    2985   sprintf (header_text, "%-24s    %s", "Device", "Index");
    2986   sprintf (title_of_window, "%s contains...", raidrec->raid_device);
    2987   newtPushHelpLine (help_text);
    2988   for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;)
    2989     {
    2990       headerMsg = newtLabel (1, 1, header_text);
    2991       partitionsListbox =
    2992     newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    2993       redraw_disklist (disklist, keylist, partitionsListbox);
    2994       i = 1;
    2995       bAdd = newtCompactButton (i, 9, " Add ");
    2996       bDelete = newtCompactButton (i += 8, 9, "Delete");
    2997       bOK = newtCompactButton (i += 9, 9, "  OK  ");
    2998       bCancel = newtCompactButton (i += 9, 9, "Cancel");
    2999       newtOpenWindow (21, 7, 38, 10, title_of_window);
    3000       myForm = newtForm (NULL, NULL, 0);
    3001       if (disklist->entries == 0)
    3002     {
    3003       newtFormAddComponents (myForm, headerMsg, bAdd, bDelete, bOK,
    3004                  bCancel, NULL);
    3005     }
    3006       else
    3007     {
    3008       newtFormAddComponents (myForm, headerMsg, partitionsListbox, bAdd,
    3009                  bDelete, bOK, bCancel, NULL);
    3010     }
    3011       b_res = newtRunForm (myForm);
    3012       if (b_res == bOK || b_res == bCancel)
    3013     {           /* do nothing */
     2800    int i = 0;
     2801    int currline = 0;
     2802
     2803    assert(mountlist_dontedit != NULL);
     2804    assert(raidlist != NULL);
     2805    assert(raidrec != NULL);
     2806    assert(description_of_list != NULL);
     2807    assert(disklist != NULL);
     2808
     2809    iamhere("malloc'ing");
     2810    malloc_string(tmp);
     2811    malloc_string(help_text);
     2812    malloc_string(title_of_window);
     2813    malloc_string(sz_res);
     2814    malloc_string(header_text);
     2815    if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
     2816        fatal_error("Cannot malloc space for raidrec");
     2817    }
     2818    if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) {
     2819        fatal_error("Cannot malloc space for disklist");
     2820    }
     2821    if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) {
     2822        fatal_error("Cannot malloc space for raidlist");
     2823    }
     2824    if (!
     2825        (unallocated_raid_partitions =
     2826         malloc(sizeof(struct mountlist_itself)))) {
     2827        fatal_error("Cannot malloc space for unallocated_raid_partitions");
     2828    }
     2829
     2830    memcpy((void *) bkp_raidlist, (void *) raidlist,
     2831           sizeof(struct raidlist_itself));
     2832    memcpy((void *) bkp_raidrec, (void *) raidrec,
     2833           sizeof(struct raid_device_record));
     2834    memcpy((void *) bkp_disklist, (void *) disklist,
     2835           sizeof(struct list_of_disks));
     2836
     2837    iamhere("Post-malloc");
     2838    strcpy(help_text,
     2839           "   Edit this RAID device's list of partitions. Choose OK or Cancel when done.");
     2840    sprintf(header_text, "%-24s    %s", "Device", "Index");
     2841    sprintf(title_of_window, "%s contains...", raidrec->raid_device);
     2842    newtPushHelpLine(help_text);
     2843    for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) {
     2844        headerMsg = newtLabel(1, 1, header_text);
     2845        partitionsListbox =
     2846            newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     2847        redraw_disklist(disklist, keylist, partitionsListbox);
     2848        i = 1;
     2849        bAdd = newtCompactButton(i, 9, " Add ");
     2850        bDelete = newtCompactButton(i += 8, 9, "Delete");
     2851        bOK = newtCompactButton(i += 9, 9, "  OK  ");
     2852        bCancel = newtCompactButton(i += 9, 9, "Cancel");
     2853        newtOpenWindow(21, 7, 38, 10, title_of_window);
     2854        myForm = newtForm(NULL, NULL, 0);
     2855        if (disklist->entries == 0) {
     2856            newtFormAddComponents(myForm, headerMsg, bAdd, bDelete, bOK,
     2857                                  bCancel, NULL);
     2858        } else {
     2859            newtFormAddComponents(myForm, headerMsg, partitionsListbox,
     2860                                  bAdd, bDelete, bOK, bCancel, NULL);
     2861        }
     2862        b_res = newtRunForm(myForm);
     2863        if (b_res == bOK || b_res == bCancel) { /* do nothing */
    30142864// That's OK. At the end of this subroutine (after this do/while loop),
    30152865// we'll throw away the changes if Cancel was pushed.
    3016     }
    3017       else
    3018     {
    3019       curr_choice = newtListboxGetCurrent (partitionsListbox);
    3020       for (i = 0; i < disklist->entries && keylist[i] != curr_choice;
    3021            i++);
    3022       if (i == disklist->entries && disklist->entries > 0)
    3023         {
    3024           log_to_screen ("I don't know what that button does!");
    3025         }
    3026       else
    3027         {
    3028           currline = i;
    3029           if (b_res == bAdd)
    3030         {
    3031           log_it ("Making list of unallocated RAID slices");
    3032           make_list_of_unallocated_raid_partitions
    3033             (unallocated_raid_partitions, mountlist_dontedit,
    3034              raidlist);
    3035           if (unallocated_raid_partitions->entries <= 0)
    3036             {
    3037               popup_and_OK
    3038             ("There are no unallocated partitions marked for RAID.");
    3039             }
    3040           else
    3041             {
    3042               log_it
    3043             ("Done. The user may add one or more of the above to RAID device");
    3044               add_disklist_entry (disklist, raidrec->raid_device,
    3045                       unallocated_raid_partitions);
    3046               log_it ("I have finished adding a disklist entry.");
    3047               redraw_disklist (disklist, keylist, partitionsListbox);
    3048             }
    3049         }
    3050           else if (b_res == bDelete)
    3051         {
    3052           delete_disklist_entry (disklist, raidrec->raid_device,
    3053                      currline);
    3054           redraw_disklist (disklist, keylist, partitionsListbox);
    3055         }
    3056           else
    3057         {
    3058           sprintf (tmp, "%s's index is %d. What should it be?",
    3059                raidrec->raid_device,
    3060                disklist->el[currline].index);
    3061           sprintf (sz_res, "%d", disklist->el[currline].index);
    3062           if (popup_and_get_string ("Set index", tmp, sz_res, 10))
    3063             {
    3064               disklist->el[currline].index = atoi (sz_res);
    3065             }
    3066           redraw_disklist (disklist, keylist, partitionsListbox);
    3067         }
    3068         }
    3069     }
    3070       newtFormDestroy (myForm);
    3071       newtPopWindow ();
    3072     }
    3073   newtPopHelpLine ();
    3074   if (b_res == bCancel)
    3075     {
    3076       memcpy ((void *) raidlist, (void *) bkp_raidlist,
    3077           sizeof (struct raidlist_itself));
    3078       memcpy ((void *) raidrec, (void *) bkp_raidrec,
    3079           sizeof (struct raid_device_record));
    3080       memcpy ((void *) disklist, (void *) bkp_disklist,
    3081           sizeof (struct list_of_disks));
    3082     }
    3083   paranoid_free(tmp);
    3084   paranoid_free(help_text);
    3085   paranoid_free(title_of_window);
    3086   paranoid_free(sz_res);
    3087   paranoid_free(header_text);
    3088   paranoid_free(bkp_raidrec);
    3089   paranoid_free(bkp_disklist);
    3090   paranoid_free(bkp_raidlist);
    3091   paranoid_free(unallocated_raid_partitions);
     2866        } else {
     2867            curr_choice = newtListboxGetCurrent(partitionsListbox);
     2868            for (i = 0; i < disklist->entries && keylist[i] != curr_choice;
     2869                 i++);
     2870            if (i == disklist->entries && disklist->entries > 0) {
     2871                log_to_screen("I don't know what that button does!");
     2872            } else {
     2873                currline = i;
     2874                if (b_res == bAdd) {
     2875                    log_it("Making list of unallocated RAID slices");
     2876                    make_list_of_unallocated_raid_partitions
     2877                        (unallocated_raid_partitions, mountlist_dontedit,
     2878                         raidlist);
     2879                    if (unallocated_raid_partitions->entries <= 0) {
     2880                        popup_and_OK
     2881                            ("There are no unallocated partitions marked for RAID.");
     2882                    } else {
     2883                        log_it
     2884                            ("Done. The user may add one or more of the above to RAID device");
     2885                        add_disklist_entry(disklist, raidrec->raid_device,
     2886                                           unallocated_raid_partitions);
     2887                        log_it("I have finished adding a disklist entry.");
     2888                        redraw_disklist(disklist, keylist,
     2889                                        partitionsListbox);
     2890                    }
     2891                } else if (b_res == bDelete) {
     2892                    delete_disklist_entry(disklist, raidrec->raid_device,
     2893                                          currline);
     2894                    redraw_disklist(disklist, keylist, partitionsListbox);
     2895                } else {
     2896                    sprintf(tmp, "%s's index is %d. What should it be?",
     2897                            raidrec->raid_device,
     2898                            disklist->el[currline].index);
     2899                    sprintf(sz_res, "%d", disklist->el[currline].index);
     2900                    if (popup_and_get_string("Set index", tmp, sz_res, 10)) {
     2901                        disklist->el[currline].index = atoi(sz_res);
     2902                    }
     2903                    redraw_disklist(disklist, keylist, partitionsListbox);
     2904                }
     2905            }
     2906        }
     2907        newtFormDestroy(myForm);
     2908        newtPopWindow();
     2909    }
     2910    newtPopHelpLine();
     2911    if (b_res == bCancel) {
     2912        memcpy((void *) raidlist, (void *) bkp_raidlist,
     2913               sizeof(struct raidlist_itself));
     2914        memcpy((void *) raidrec, (void *) bkp_raidrec,
     2915               sizeof(struct raid_device_record));
     2916        memcpy((void *) disklist, (void *) bkp_disklist,
     2917               sizeof(struct list_of_disks));
     2918    }
     2919    paranoid_free(tmp);
     2920    paranoid_free(help_text);
     2921    paranoid_free(title_of_window);
     2922    paranoid_free(sz_res);
     2923    paranoid_free(header_text);
     2924    paranoid_free(bkp_raidrec);
     2925    paranoid_free(bkp_disklist);
     2926    paranoid_free(bkp_raidlist);
     2927    paranoid_free(unallocated_raid_partitions);
    30922928}
    30932929#endif
     
    31002936 * or 'E' (or any other letter) for exit.
    31012937 */
    3102 char
    3103 which_restore_mode ()
    3104 {
    3105  
     2938char which_restore_mode()
     2939{
     2940
    31062941  /** char *************************************************************/
    3107   char output = '\0';
    3108   char tmp[MAX_STR_LEN];
    3109  
     2942    char output = '\0';
     2943    char tmp[MAX_STR_LEN];
     2944
    31102945  /** newt *************************************************************/
    31112946
    3112   newtComponent b1;
    3113   newtComponent b2;
    3114   newtComponent b3;
    3115   newtComponent b4;
    3116   newtComponent b_res;
    3117   newtComponent myForm;
    3118  
    3119   if (g_text_mode)
    3120     {
    3121       for(output='z'; !strchr("AICE", output); output=tmp[0])
    3122     {
    3123       printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
    3124       fgets(tmp, MAX_STR_LEN-1, stdin);
    3125     }
    3126       return(output);
    3127     }
    3128 
    3129   newtPushHelpLine
    3130     ("   Do you want to 'nuke' your system, restore interactively, or just compare?");
    3131   newtOpenWindow (24, 3, 32, 17, "How should I restore?");
    3132   b1 = newtButton (7, 1, "Automatically");
    3133   b2 = newtButton (7, 5, "Interactively");
    3134   b3 = newtButton (7, 9, "Compare only!");
    3135   b4 = newtButton (7, 13, "Exit to shell");
    3136   myForm = newtForm (NULL, NULL, 0);
    3137   newtFormAddComponents (myForm, b1, b2, b3, b4, NULL);
    3138   b_res = newtRunForm (myForm);
    3139   newtFormDestroy (myForm);
    3140   newtPopWindow ();
    3141   if (b_res == b1)
    3142     {
    3143       output = 'N';
    3144     }
    3145   if (b_res == b2)
    3146     {
    3147       output = 'I';
    3148     }
    3149   if (b_res == b3)
    3150     {
    3151       output = 'C';
    3152     }
    3153   if (b_res == b4)
    3154     {
    3155       output = 'E';
    3156     }
    3157   newtPopHelpLine ();
    3158   return (output);
    3159 }
    3160 
     2947    newtComponent b1;
     2948    newtComponent b2;
     2949    newtComponent b3;
     2950    newtComponent b4;
     2951    newtComponent b_res;
     2952    newtComponent myForm;
     2953
     2954    if (g_text_mode) {
     2955        for (output = 'z'; !strchr("AICE", output); output = tmp[0]) {
     2956            printf
     2957                ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
     2958            fgets(tmp, MAX_STR_LEN - 1, stdin);
     2959        }
     2960        return (output);
     2961    }
     2962
     2963    newtPushHelpLine
     2964        ("   Do you want to 'nuke' your system, restore interactively, or just compare?");
     2965    newtOpenWindow(24, 3, 32, 17, "How should I restore?");
     2966    b1 = newtButton(7, 1, "Automatically");
     2967    b2 = newtButton(7, 5, "Interactively");
     2968    b3 = newtButton(7, 9, "Compare only!");
     2969    b4 = newtButton(7, 13, "Exit to shell");
     2970    myForm = newtForm(NULL, NULL, 0);
     2971    newtFormAddComponents(myForm, b1, b2, b3, b4, NULL);
     2972    b_res = newtRunForm(myForm);
     2973    newtFormDestroy(myForm);
     2974    newtPopWindow();
     2975    if (b_res == b1) {
     2976        output = 'N';
     2977    }
     2978    if (b_res == b2) {
     2979        output = 'I';
     2980    }
     2981    if (b_res == b3) {
     2982        output = 'C';
     2983    }
     2984    if (b_res == b4) {
     2985        output = 'E';
     2986    }
     2987    newtPopHelpLine();
     2988    return (output);
     2989}
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-newt.h

    r30 r128  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: mondo-rstr-newt.h,v 1.3 2004/06/10 15:29:13 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    3737/* external subroutines and global vars */
    3838
    39 extern long get_time (void);
    40 extern char *last_line_of_file (char *);
    41 extern void center_string (char *, int);
    42 extern bool does_file_exist (char *);
    43 extern void finish (int);
    44 extern long get_phys_size_of_drive (char *);
    45 extern bool is_this_device_mounted (char *);
    46 extern void strip_spaces (char *);
    47 extern void initialize_raidrec (struct raid_device_record *);
    48 extern int make_list_of_drives (struct mountlist_itself *,
    49                 char[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
    50 char *number_to_text (int);
    51 extern void reload_filelist (struct s_node *);
    52 extern void toggle_all_root_dirs_on (struct s_node *);
    53 extern void toggle_path_expandability (struct s_node *, char *, bool);
    54 extern void toggle_path_selection (struct s_node *, char *, bool);
    55 extern void toggle_node_selection (struct s_node *, bool);
    56 extern struct s_node *find_node_in_filelist (struct s_node *, char *filename);
    57 extern int what_number_cd_is_this (struct s_bkpinfo*);
     39extern long get_time(void);
     40extern char *last_line_of_file(char *);
     41extern void center_string(char *, int);
     42extern bool does_file_exist(char *);
     43extern void finish(int);
     44extern long get_phys_size_of_drive(char *);
     45extern bool is_this_device_mounted(char *);
     46extern void strip_spaces(char *);
     47extern void initialize_raidrec(struct raid_device_record *);
     48extern int make_list_of_drives(struct mountlist_itself *,
     49                               char[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
     50char *number_to_text(int);
     51extern void reload_filelist(struct s_node *);
     52extern void toggle_all_root_dirs_on(struct s_node *);
     53extern void toggle_path_expandability(struct s_node *, char *, bool);
     54extern void toggle_path_selection(struct s_node *, char *, bool);
     55extern void toggle_node_selection(struct s_node *, bool);
     56extern struct s_node *find_node_in_filelist(struct s_node *,
     57                                            char *filename);
     58extern int what_number_cd_is_this(struct s_bkpinfo *);
    5859//extern void fatal_error (char *);
    59 extern void sort_mountlist_by_device (struct mountlist_itself *);
    60 extern int load_mountlist (struct mountlist_itself *a, char *b);
     60extern void sort_mountlist_by_device(struct mountlist_itself *);
     61extern int load_mountlist(struct mountlist_itself *a, char *b);
    6162extern bool g_text_mode;
    6263
    6364
    6465/* hacks */
    65 extern int load_raidtab_into_raidlist (struct raidlist_itself *a, char *b);
     66extern int load_raidtab_into_raidlist(struct raidlist_itself *a, char *b);
    6667
    6768
    6869
    6970extern long g_start_time, g_minimum_progress, g_maximum_progress,
    70   g_current_progress, g_currentY;
     71    g_current_progress, g_currentY;
    7172extern bool g_ISO_restore_mode;
    7273
     
    9293/* my subroutines */
    9394
    94 void add_disklist_entry (struct list_of_disks *, char *,
    95              struct mountlist_itself *);
    96 void add_mountlist_entry (struct mountlist_itself *, struct raidlist_itself *,
    97               newtComponent, int, void *keylist[]);
    98 void add_varslist_entry (struct raid_device_record *);
    99 bool ask_me_yes_or_no (char *);
    100 bool ask_me_OK_or_cancel (char *);
    101 long calculate_raid_device_size (struct mountlist_itself *,
    102                  struct raidlist_itself *, char *);
    103 void choose_raid_level (struct
     95void add_disklist_entry(struct list_of_disks *, char *,
     96                        struct mountlist_itself *);
     97void add_mountlist_entry(struct mountlist_itself *,
     98                         struct raidlist_itself *, newtComponent, int,
     99                         void *keylist[]);
     100void add_varslist_entry(struct raid_device_record *);
     101bool ask_me_yes_or_no(char *);
     102bool ask_me_OK_or_cancel(char *);
     103long calculate_raid_device_size(struct mountlist_itself *,
     104                                struct raidlist_itself *, char *);
     105void choose_raid_level(struct
    104106#ifdef __FreeBSD__
    105 vinum_plex
     107                       vinum_plex
    106108#else
    107 raid_device_record
     109                       raid_device_record
    108110#endif
    109 *);
    110 void close_evalcall_form (void);
    111 void close_progress_form (void);
    112 void del_partns_listed_in_disklist (struct mountlist_itself *,
    113                     struct raidlist_itself *,
    114                     struct list_of_disks *);
    115 void delete_disklist_entry (struct list_of_disks *, char *, int);
    116 void delete_mountlist_entry (struct mountlist_itself *,
    117                  struct raidlist_itself *, newtComponent, int,
    118                  void *keylist[]);
    119 void delete_raidlist_entry (struct mountlist_itself *,
    120                 struct raidlist_itself *, char *);
    121 void delete_varslist_entry (struct raid_device_record *, int);
    122 char *disklist_entry_to_string (struct list_of_disks *, int);
    123 int edit_filelist (struct s_node *);
    124 void edit_mountlist_entry (struct mountlist_itself *,
    125                struct raidlist_itself *, newtComponent, int,
    126                void *keylist[]);
    127 void edit_raidlist_entry (struct mountlist_itself *, struct raidlist_itself *,
    128               struct raid_device_record *, int);
    129 void edit_varslist_entry (struct raid_device_record *, int);
    130 int edit_mountlist_in_newt (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *);
    131 int edit_mountlist (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *);
    132 void edit_raidrec_additional_vars (struct raid_device_record *);
    133 int evaluate_drive_within_mountlist (struct mountlist_itself *, char *,
    134                      char *);
    135 int evaluate_mountlist (struct mountlist_itself *, char *, char *, char *);
    136 int find_device_in_mountlist (struct mountlist_itself *, char *);
    137 int find_next_free_index_in_disklist (struct list_of_disks *);
    138 int find_raid_device_in_raidlist (struct raidlist_itself *, char *);
    139 bool get_isodir_info (char *, char *, char *, bool);
    140 void initiate_new_raidlist_entry (struct raidlist_itself *,
    141                   struct mountlist_itself *, int, char *);
    142 void insert_essential_additionalvars (struct raid_device_record *);
    143 bool is_this_raid_personality_registered (int);
    144 void log_file_end_to_screen (char *, char *);
    145 void log_to_screen (const char *fmt, ...);
    146 int look_for_duplicate_mountpoints (struct mountlist_itself *, char *);
    147 int look_for_weird_formats (struct mountlist_itself *, char *);
    148 void make_list_of_unallocated_raid_partitions (struct mountlist_itself *,
    149                            struct mountlist_itself *,
    150                            struct raidlist_itself *);
    151 char *mountlist_entry_to_string (struct mountlist_itself *, int);
    152 void mvaddstr_and_log_it (int, int, char *);
    153 void nuke_mode_dummy ();
    154 char *number_of_disks_as_string (int, char *);
    155 void open_evalcall_form (char *);
    156 void open_progress_form (char *, char *, char *, char *, long);
    157 void popup_and_OK (char *);
    158 bool popup_and_get_string (char *, char *, char *, int);
    159 bool popup_with_buttons (char *, char *, char *);
    160 void redraw_disklist (struct list_of_disks *, void *keylist[], newtComponent);
    161 void redraw_mountlist (struct mountlist_itself *, void *keylist[],
    162                newtComponent);
    163 void redraw_unallocpartnslist (struct mountlist_itself *, void *keylist[],
    164                    newtComponent);
    165 void redraw_varslist (struct additional_raid_variables *, void *keylist[],
    166               newtComponent);
    167 int read_variableINT_and_remove_from_raidvars (struct raid_device_record *,
    168                            char *);
    169 void refresh_log_screen (void);
    170 void rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself *,
    171                             char *, char *);
    172 void remove_essential_additionalvars (struct raid_device_record *);
    173 void select_raid_disks (struct mountlist_itself *, struct raidlist_itself *,
    174             struct raid_device_record *, char *,
    175             struct list_of_disks *);
    176 void setup_newt_stuff (void);
    177 long size_of_specific_device (struct mountlist_itself *, char *);
    178 bool spread_flaws_across_three_lines (char *, char *, char *, char *, int);
    179 char *turn_raid_level_number_to_string (int);
    180 void update_evalcall_form (int);
    181 void update_progress_form (char *);
    182 void update_progress_form_full (char *, char *, char *);
    183 char which_restore_mode (void);
    184 void write_variableINT_to_raid_var_line (struct raid_device_record *, int,
    185                      char *, int);
    186 int where_in_drivelist_is_drive (struct list_of_disks *, char *);
     111                       *);
     112void close_evalcall_form(void);
     113void close_progress_form(void);
     114void del_partns_listed_in_disklist(struct mountlist_itself *,
     115                                   struct raidlist_itself *,
     116                                   struct list_of_disks *);
     117void delete_disklist_entry(struct list_of_disks *, char *, int);
     118void delete_mountlist_entry(struct mountlist_itself *,
     119                            struct raidlist_itself *, newtComponent, int,
     120                            void *keylist[]);
     121void delete_raidlist_entry(struct mountlist_itself *,
     122                           struct raidlist_itself *, char *);
     123void delete_varslist_entry(struct raid_device_record *, int);
     124char *disklist_entry_to_string(struct list_of_disks *, int);
     125int edit_filelist(struct s_node *);
     126void edit_mountlist_entry(struct mountlist_itself *,
     127                          struct raidlist_itself *, newtComponent, int,
     128                          void *keylist[]);
     129void edit_raidlist_entry(struct mountlist_itself *,
     130                         struct raidlist_itself *,
     131                         struct raid_device_record *, int);
     132void edit_varslist_entry(struct raid_device_record *, int);
     133int edit_mountlist_in_newt(char *mountlist_fname,
     134                           struct mountlist_itself *,
     135                           struct raidlist_itself *);
     136int edit_mountlist(char *mountlist_fname, struct mountlist_itself *,
     137                   struct raidlist_itself *);
     138void edit_raidrec_additional_vars(struct raid_device_record *);
     139int evaluate_drive_within_mountlist(struct mountlist_itself *, char *,
     140                                    char *);
     141int evaluate_mountlist(struct mountlist_itself *, char *, char *, char *);
     142int find_device_in_mountlist(struct mountlist_itself *, char *);
     143int find_next_free_index_in_disklist(struct list_of_disks *);
     144int find_raid_device_in_raidlist(struct raidlist_itself *, char *);
     145bool get_isodir_info(char *, char *, char *, bool);
     146void initiate_new_raidlist_entry(struct raidlist_itself *,
     147                                 struct mountlist_itself *, int, char *);
     148void insert_essential_additionalvars(struct raid_device_record *);
     149bool is_this_raid_personality_registered(int);
     150void log_file_end_to_screen(char *, char *);
     151void log_to_screen(const char *fmt, ...);
     152int look_for_duplicate_mountpoints(struct mountlist_itself *, char *);
     153int look_for_weird_formats(struct mountlist_itself *, char *);
     154void make_list_of_unallocated_raid_partitions(struct mountlist_itself *,
     155                                              struct mountlist_itself *,
     156                                              struct raidlist_itself *);
     157char *mountlist_entry_to_string(struct mountlist_itself *, int);
     158void mvaddstr_and_log_it(int, int, char *);
     159void nuke_mode_dummy();
     160char *number_of_disks_as_string(int, char *);
     161void open_evalcall_form(char *);
     162void open_progress_form(char *, char *, char *, char *, long);
     163void popup_and_OK(char *);
     164bool popup_and_get_string(char *, char *, char *, int);
     165bool popup_with_buttons(char *, char *, char *);
     166void redraw_disklist(struct list_of_disks *, void *keylist[],
     167                     newtComponent);
     168void redraw_mountlist(struct mountlist_itself *, void *keylist[],
     169                      newtComponent);
     170void redraw_unallocpartnslist(struct mountlist_itself *, void *keylist[],
     171                              newtComponent);
     172void redraw_varslist(struct additional_raid_variables *, void *keylist[],
     173                     newtComponent);
     174int read_variableINT_and_remove_from_raidvars(struct raid_device_record *,
     175                                              char *);
     176void refresh_log_screen(void);
     177void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself
     178                                                   *, char *, char *);
     179void remove_essential_additionalvars(struct raid_device_record *);
     180void select_raid_disks(struct mountlist_itself *, struct raidlist_itself *,
     181                       struct raid_device_record *, char *,
     182                       struct list_of_disks *);
     183void setup_newt_stuff(void);
     184long size_of_specific_device(struct mountlist_itself *, char *);
     185bool spread_flaws_across_three_lines(char *, char *, char *, char *, int);
     186char *turn_raid_level_number_to_string(int);
     187void update_evalcall_form(int);
     188void update_progress_form(char *);
     189void update_progress_form_full(char *, char *, char *);
     190char which_restore_mode(void);
     191void write_variableINT_to_raid_var_line(struct raid_device_record *, int,
     192                                        char *, int);
     193int where_in_drivelist_is_drive(struct list_of_disks *, char *);
    187194char *strip_path(char *);
    188195
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools-EXT.h

    r30 r128  
    44
    55extern void free_MR_global_filenames();
    6 extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo*);
    7 extern bool is_file_in_list(char*, char*, char*); /* needle, haystack, preamble */
     6extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);
     7extern bool is_file_in_list(char *, char *, char *);    /* needle, haystack, preamble */
    88extern int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please);
    99extern void kill_petris(void);
    10 extern int modify_rclocal_one_time( char *path );
     10extern int modify_rclocal_one_time(char *path);
    1111extern int mount_cdrom(struct s_bkpinfo *bkpinfo);
    12 extern int mount_device(char*,char*,char*,bool);
    13 extern int mount_all_devices(struct mountlist_itself*, bool);
     12extern int mount_device(char *, char *, char *, bool);
     13extern int mount_all_devices(struct mountlist_itself *, bool);
    1414extern void protect_against_braindead_sysadmins(void);
    15 extern int read_cfg_file_into_bkpinfo( char* cfg_file, struct s_bkpinfo *bkpinfo);
     15extern int read_cfg_file_into_bkpinfo(char *cfg_file,
     16                                      struct s_bkpinfo *bkpinfo);
    1617struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *);
    17 extern int backup_crucial_file(char *path_root, char*filename);
     18extern int backup_crucial_file(char *path_root, char *filename);
    1819extern int run_boot_loader(bool);
    19 extern int run_grub(bool, char*);
     20extern int run_grub(bool, char *);
    2021extern int run_lilo(bool);
    2122extern int run_elilo(bool);
     
    2324extern char *find_my_editor(void);
    2425
    25 extern void streamline_changes_file(char*,char*);
    26 extern void  set_signals( int on );
     26extern void streamline_changes_file(char *, char *);
     27extern void set_signals(int on);
    2728extern void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo);
    2829//extern void setup_signals(int);
    2930extern void terminate_daemon(int);
    3031extern void termination_in_progress(int);
    31 extern int unmount_all_devices(struct mountlist_itself*);
     32extern int unmount_all_devices(struct mountlist_itself *);
    3233extern int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo);
    33 extern int 
    34 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
    35                   char *ramdisk_fname,
    36                   char *output_cfg_file,
    37                   char *output_mountlist_file);
     34extern int
     35extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
     36                                 char *ramdisk_fname,
     37                                 char *output_cfg_file,
     38                                char *output_mountlist_file);
    3839
    39 extern void ask_about_these_imagedevs( char *infname, char *outfname );
     40extern void ask_about_these_imagedevs(char *infname, char *outfname);
    4041
    41 extern void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage);
     42extern void wait_until_software_raids_are_prepped(char *mdstat_file,
     43                                                  int wait_for_percentage);
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools.c

    r30 r128  
    134134
    135135extern bool g_sigpipe_caught;
    136 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
     136extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
    137137extern bool g_I_have_just_nuked;
    138138extern char *g_tmpfs_mountpt;
     
    140140extern char *g_isodir_format;
    141141extern long g_current_progress, g_maximum_progress;
    142 extern char *g_biggielist_txt;// where 'biggielist.txt' is stored, on ramdisk / tempdir;
    143                           // biggielist.txt is the list of big files stored on the
    144                           // backup media set in question
    145 extern char    *g_filelist_full; // filelist.full.gz is the list of all regular files
    146                           // (excluding big files) stored on the backup media set
    147 extern char    *g_biggielist_pot;// list of big files which _could_ be restored, if the
    148                           // user chooses them
    149 extern char  *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
    150                             // were archived as images, not just /dev entries
    151                             // ... e.g. NTFS, BeOS partitions
    152 extern char  *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
    153                               // restore only these
    154 extern char  *g_mondo_cfg_file;      // where m*ndo-restore.cfg (the config file) is stored
    155 extern char  *g_mountlist_fname;     // where mountlist.txt (the mountlist file) is stored
    156 extern char    *g_mondo_home;        // homedir of Mondo; usually /usr/local/share/mondo
     142extern char *g_biggielist_txt;  // where 'biggielist.txt' is stored, on ramdisk / tempdir;
     143                          // biggielist.txt is the list of big files stored on the
     144                          // backup media set in question
     145extern char *g_filelist_full;   // filelist.full.gz is the list of all regular files
     146                          // (excluding big files) stored on the backup media set
     147extern char *g_biggielist_pot;  // list of big files which _could_ be restored, if the
     148                          // user chooses them
     149extern char *g_filelist_imagedevs;  // list of devices (e.g. /dev/hda1, /dev/sda5) which
     150                            // were archived as images, not just /dev entries
     151                            // ... e.g. NTFS, BeOS partitions
     152extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
     153                              // restore only these
     154extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
     155extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
     156extern char *g_mondo_home;      // homedir of Mondo; usually /usr/local/share/mondo
    157157extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS;
    158158
     
    170170void free_MR_global_filenames()
    171171{
    172   paranoid_free ( g_biggielist_txt );
    173   paranoid_free ( g_filelist_full );
    174   paranoid_free ( g_filelist_imagedevs );
     172    paranoid_free(g_biggielist_txt);
     173    paranoid_free(g_filelist_full);
     174    paranoid_free(g_filelist_imagedevs);
    175175//  paranoid_free (g_imagedevs_pot );
    176   paranoid_free ( g_imagedevs_restthese );
    177   paranoid_free ( g_mondo_cfg_file );
    178   paranoid_free ( g_mountlist_fname );
    179   paranoid_free ( g_mondo_home );
    180   paranoid_free ( g_tmpfs_mountpt );
    181   paranoid_free ( g_isodir_device );
    182   paranoid_free ( g_isodir_format );
     176    paranoid_free(g_imagedevs_restthese);
     177    paranoid_free(g_mondo_cfg_file);
     178    paranoid_free(g_mountlist_fname);
     179    paranoid_free(g_mondo_home);
     180    paranoid_free(g_tmpfs_mountpt);
     181    paranoid_free(g_isodir_device);
     182    paranoid_free(g_isodir_format);
    183183
    184184}
     
    193193 * @ingroup restoreUtilityGroup
    194194 */
    195 void
    196 ask_about_these_imagedevs( char *infname, char *outfname )
    197 {
    198   FILE *fin;
    199   FILE *fout;
     195void ask_about_these_imagedevs(char *infname, char *outfname)
     196{
     197    FILE *fin;
     198    FILE *fout;
    200199  /************************************************************************
    201200   * allocate memory regions. test and set  -sab 16 feb 2003              *
    202201   ************************************************************************/
    203   char *incoming_ptr;
    204   char *question_ptr;
    205 
    206   char incoming[ MAX_STR_LEN ];
    207   char question[ MAX_STR_LEN ];
    208 
    209   assert_string_is_neither_NULL_nor_zerolength(infname);
    210   assert_string_is_neither_NULL_nor_zerolength(outfname);
    211 
    212   incoming_ptr = malloc(sizeof(incoming));
    213   if ( incoming_ptr == NULL )
    214     {
    215       fprintf(stderr, "Out of Memory\n");
    216       exit (EXIT_FAILURE);
    217     }
    218 
    219   question_ptr = malloc(sizeof(question));
    220   if ( question_ptr == NULL)
    221     {
    222       fprintf(stderr, "Out of Memory\n");
    223       exit (EXIT_FAILURE);
    224     }
    225 
    226   memset (incoming_ptr, '\0', sizeof(incoming));
    227   memset (question_ptr, '\0', sizeof(question));
    228 
    229  
    230 
    231   if (!( fin = fopen( infname,"r") ) ) 
    232     {
    233       fatal_error( "Cannot openin infname" );
    234     }
    235   if ( !( fout = fopen( outfname, "w" ) ) )
    236     {
    237       fatal_error( "Cannot openin outfname");
    238     }
    239   for( fgets( incoming_ptr, MAX_STR_LEN, fin);
    240        !feof( fin );
    241        fgets( incoming_ptr, MAX_STR_LEN, fin ) )
    242     {
    243       strip_spaces( incoming_ptr );
    244 
    245       if ( incoming[0] == '\0')
    246     {
    247       continue;
    248     }
    249 
    250       sprintf( question_ptr,
    251            "Should I restore the image of %s ?",
    252            incoming_ptr );
    253 
    254       if ( ask_me_yes_or_no( question_ptr ) )
    255         {
    256           fprintf( fout, "%s\n", incoming_ptr );
    257         }
    258     }
    259  
     202    char *incoming_ptr;
     203    char *question_ptr;
     204
     205    char incoming[MAX_STR_LEN];
     206    char question[MAX_STR_LEN];
     207
     208    assert_string_is_neither_NULL_nor_zerolength(infname);
     209    assert_string_is_neither_NULL_nor_zerolength(outfname);
     210
     211    incoming_ptr = malloc(sizeof(incoming));
     212    if (incoming_ptr == NULL) {
     213        fprintf(stderr, "Out of Memory\n");
     214        exit(EXIT_FAILURE);
     215    }
     216
     217    question_ptr = malloc(sizeof(question));
     218    if (question_ptr == NULL) {
     219        fprintf(stderr, "Out of Memory\n");
     220        exit(EXIT_FAILURE);
     221    }
     222
     223    memset(incoming_ptr, '\0', sizeof(incoming));
     224    memset(question_ptr, '\0', sizeof(question));
     225
     226
     227
     228    if (!(fin = fopen(infname, "r"))) {
     229        fatal_error("Cannot openin infname");
     230    }
     231    if (!(fout = fopen(outfname, "w"))) {
     232        fatal_error("Cannot openin outfname");
     233    }
     234    for (fgets(incoming_ptr, MAX_STR_LEN, fin);
     235         !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
     236        strip_spaces(incoming_ptr);
     237
     238        if (incoming[0] == '\0') {
     239            continue;
     240        }
     241
     242        sprintf(question_ptr,
     243                "Should I restore the image of %s ?", incoming_ptr);
     244
     245        if (ask_me_yes_or_no(question_ptr)) {
     246            fprintf(fout, "%s\n", incoming_ptr);
     247        }
     248    }
     249
    260250  /*** free memory ***********/
    261   paranoid_free(incoming_ptr);
    262   incoming_ptr = NULL;
    263   paranoid_free(question_ptr);
    264   question_ptr = NULL;
    265  
    266 
    267   paranoid_fclose( fout );
    268   paranoid_fclose( fin );
     251    paranoid_free(incoming_ptr);
     252    incoming_ptr = NULL;
     253    paranoid_free(question_ptr);
     254    question_ptr = NULL;
     255
     256
     257    paranoid_fclose(fout);
     258    paranoid_fclose(fin);
    269259}
    270260
     
    289279 * @ingroup restoreUtilityGroup
    290280 */
    291 int
    292 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
    293                   char *ramdisk_fname,
    294                   char *output_cfg_file,
    295                   char *output_mountlist_file)
    296 {
    297   char *mountpt;
    298   char *command;
    299   char *orig_fname;
    300   int retval=0;
    301  
    302   assert(bkpinfo!=NULL);
    303   malloc_string(mountpt);
    304   malloc_string(command);
    305   malloc_string(orig_fname);
    306   assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
    307   assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
    308   assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
    309   sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir );
    310   sprintf( command, "mkdir -p %s", mountpt );
    311   run_program_and_log_output ( command, FALSE );
    312   sprintf( command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
    313        ramdisk_fname,
    314        bkpinfo->tmpdir );
    315 
    316   run_program_and_log_output( command, FALSE );
    317   sprintf( command, "umount %s", mountpt );
    318 
    319   run_program_and_log_output( command, FALSE );
    320 
    321   sprintf( command, "mount -o loop %s/mindi.rd -t ext2 %s",
    322        bkpinfo->tmpdir,
    323        mountpt );
    324 
    325   run_program_and_log_output( command, FALSE );
    326 
    327   sprintf( command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    328 
    329   run_program_and_log_output( command, FALSE );
    330 
    331   sprintf( command,
    332            "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
    333        mountpt, g_mondo_cfg_file,
    334        output_cfg_file );
    335   run_program_and_log_output(command, FALSE);
    336 
    337   sprintf( orig_fname, "%s/%s", mountpt, g_mountlist_fname );
    338   if (does_file_exist( orig_fname ))
    339     {
    340       sprintf( command,
    341        "cp -f %s %s",
    342        orig_fname, output_mountlist_file );
    343       run_program_and_log_output( command, FALSE );
    344     }
    345   sprintf( command, "umount %s", mountpt );
    346   run_program_and_log_output( command, FALSE );
    347   if ( !does_file_exist(output_cfg_file) || (!does_file_exist(output_mountlist_file) && does_file_exist(orig_fname)) )
    348     {
    349       log_msg(2, "Failed to extract %s and/or %s from ramdisk",
    350           output_cfg_file,
    351           output_mountlist_file );
    352       retval=1;
    353     }
    354   else
    355     {
    356       retval=0;
    357     }
    358   paranoid_free(mountpt);
    359   paranoid_free(command);
    360   paranoid_free(orig_fname);
    361   return(retval);
     281int
     282extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
     283                                 char *ramdisk_fname,
     284                                 char *output_cfg_file,
     285                                 char *output_mountlist_file)
     286{
     287    char *mountpt;
     288    char *command;
     289    char *orig_fname;
     290    int retval = 0;
     291
     292    assert(bkpinfo != NULL);
     293    malloc_string(mountpt);
     294    malloc_string(command);
     295    malloc_string(orig_fname);
     296    assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
     297    assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
     298    assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
     299    sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
     300    sprintf(command, "mkdir -p %s", mountpt);
     301    run_program_and_log_output(command, FALSE);
     302    sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
     303            ramdisk_fname, bkpinfo->tmpdir);
     304
     305    run_program_and_log_output(command, FALSE);
     306    sprintf(command, "umount %s", mountpt);
     307
     308    run_program_and_log_output(command, FALSE);
     309
     310    sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
     311            bkpinfo->tmpdir, mountpt);
     312
     313    run_program_and_log_output(command, FALSE);
     314
     315    sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
     316
     317    run_program_and_log_output(command, FALSE);
     318
     319    sprintf(command, "cp -f %s/%s %s",  // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
     320            mountpt, g_mondo_cfg_file, output_cfg_file);
     321    run_program_and_log_output(command, FALSE);
     322
     323    sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
     324    if (does_file_exist(orig_fname)) {
     325        sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
     326        run_program_and_log_output(command, FALSE);
     327    }
     328    sprintf(command, "umount %s", mountpt);
     329    run_program_and_log_output(command, FALSE);
     330    if (!does_file_exist(output_cfg_file)
     331        || (!does_file_exist(output_mountlist_file)
     332            && does_file_exist(orig_fname))) {
     333        log_msg(2, "Failed to extract %s and/or %s from ramdisk",
     334                output_cfg_file, output_mountlist_file);
     335        retval = 1;
     336    } else {
     337        retval = 0;
     338    }
     339    paranoid_free(mountpt);
     340    paranoid_free(command);
     341    paranoid_free(orig_fname);
     342    return (retval);
    362343
    363344}
     
    372353void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo)
    373354{
    374   while(get_cfg_file_from_archive(bkpinfo))
    375     {
    376       if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?"))
    377     { fatal_error("Could not find config file/archives. Aborting."); }
    378       interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    379     }
     355    while (get_cfg_file_from_archive(bkpinfo)) {
     356        if (!ask_me_yes_or_no
     357            ("Failed to find config file/archives. Choose another source?"))
     358        {
     359            fatal_error("Could not find config file/archives. Aborting.");
     360        }
     361        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     362    }
    380363}
    381364
     
    388371 * @return TRUE if it's in the list, FALSE if it's not.
    389372 */
    390 bool
    391 is_file_in_list(char *f, char *list_fname, char *preamble)
     373bool is_file_in_list(char *f, char *list_fname, char *preamble)
    392374{
    393375
    394376  /** needs malloc **/
    395   char *command;
    396   char *file;
    397   char *tmp;
    398   int res;
    399 
    400   malloc_string(command);
    401   malloc_string(file);
    402   malloc_string(tmp);
    403   assert_string_is_neither_NULL_nor_zerolength(f);
    404   assert_string_is_neither_NULL_nor_zerolength(list_fname);
    405   assert(preamble!=NULL);
    406 
    407   if ( strncmp( preamble, f, strlen(preamble ) ) == 0 )
    408     {
    409       strcpy( file, f + strlen(preamble) );
    410     }
    411   else
    412     {
    413       strcpy( file, f );
    414     }
    415   if ( file[0] == '/' && file[1] == '/')
    416     {
    417       strcpy( tmp, file );
    418       strcpy( file,tmp + 1 );
    419     }
    420   sprintf( tmp,"Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
    421   log_msg(2, tmp );
    422   sprintf( command, "cat %s | grep -x \"%s\"",  list_fname, file );
    423   res = run_program_and_log_output( command, FALSE);
    424   paranoid_free(command);
    425   paranoid_free(file);
    426   paranoid_free(tmp);
    427   if (res)
    428     {
    429       return(FALSE);
    430     }
    431   else
    432     {
    433       return(TRUE);
    434     }
    435 }
     377    char *command;
     378    char *file;
     379    char *tmp;
     380    int res;
     381
     382    malloc_string(command);
     383    malloc_string(file);
     384    malloc_string(tmp);
     385    assert_string_is_neither_NULL_nor_zerolength(f);
     386    assert_string_is_neither_NULL_nor_zerolength(list_fname);
     387    assert(preamble != NULL);
     388
     389    if (strncmp(preamble, f, strlen(preamble)) == 0) {
     390        strcpy(file, f + strlen(preamble));
     391    } else {
     392        strcpy(file, f);
     393    }
     394    if (file[0] == '/' && file[1] == '/') {
     395        strcpy(tmp, file);
     396        strcpy(file, tmp + 1);
     397    }
     398    sprintf(tmp,
     399            "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
     400            f, file);
     401    log_msg(2, tmp);
     402    sprintf(command, "cat %s | grep -x \"%s\"", list_fname, file);
     403    res = run_program_and_log_output(command, FALSE);
     404    paranoid_free(command);
     405    paranoid_free(file);
     406    paranoid_free(tmp);
     407    if (res) {
     408        return (FALSE);
     409    } else {
     410        return (TRUE);
     411    }
     412}
     413
    436414/**************************************************************************
    437415 *END_IS_FILE_IN_LIST                                                     *
     
    451429int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please)
    452430{
    453   char *mount_isodir_command, *tmp,
    454     *command;
    455   int retval=0, i;
    456   bool already_mounted=FALSE;
    457 
    458   assert(bkpinfo!=NULL);
    459   malloc_string(mount_isodir_command);
    460   malloc_string(tmp);
    461   malloc_string(command);
    462   g_ISO_restore_mode=TRUE;
    463   read_cfg_var( g_mondo_cfg_file, "iso-dev", g_isodir_device);
    464   if (bkpinfo->disaster_recovery)
    465     {
     431    char *mount_isodir_command, *tmp, *command;
     432    int retval = 0, i;
     433    bool already_mounted = FALSE;
     434
     435    assert(bkpinfo != NULL);
     436    malloc_string(mount_isodir_command);
     437    malloc_string(tmp);
     438    malloc_string(command);
     439    g_ISO_restore_mode = TRUE;
     440    read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     441    if (bkpinfo->disaster_recovery) {
    466442/* Patch Conor Daly 26-june-2004
    467443 * Don't let this clobber an existing bkpinfo->isodir */
    468       if (!bkpinfo->isodir[0]) {
    469         strcpy(bkpinfo->isodir, "/tmp/isodir");
    470       }
     444        if (!bkpinfo->isodir[0]) {
     445            strcpy(bkpinfo->isodir, "/tmp/isodir");
     446        }
    471447/* End patch */
    472       sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    473       run_program_and_log_output(command, 5);
    474       log_msg(2,"Setting isodir to %s", bkpinfo->isodir);
    475     }
    476 
    477   if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {return(1);}
    478   paranoid_system("umount "MNT_CDROM" 2> /dev/null"); /* just in case */
    479 
    480   if (is_this_device_mounted(g_isodir_device))
    481     {
    482       log_to_screen("WARNING - isodir is already mounted");
    483       already_mounted=TRUE;
    484     }
    485   else
    486     {
    487       sprintf(mount_isodir_command,"mount %s", g_isodir_device);
    488       if (strlen(g_isodir_format)>1)
    489         { sprintf(mount_isodir_command+strlen(mount_isodir_command)," -t %s", g_isodir_format); }
    490       strcat(mount_isodir_command," -o ro ");
    491       strcat(mount_isodir_command, bkpinfo->isodir);
    492       run_program_and_log_output("df -m", FALSE);
    493       sprintf(tmp, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command);
    494       log_msg(1,tmp);
    495       if (run_program_and_log_output(mount_isodir_command, FALSE))
    496         { popup_and_OK("Cannot mount the device where the ISO files are stored."); return(1); }
    497       log_to_screen("I have mounted the device where the ISO files are stored.");
    498     }
    499   if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { mount_cdrom(bkpinfo); }
    500   i=what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */
    501   sprintf(tmp,"%s #%d has been mounted via loopback mount", media_descriptor_string(bkpinfo->backup_media_type), i);
    502   log_msg(1,tmp);
    503   if (i<0)
    504     { popup_and_OK("Cannot find ISO images in the directory you specified."); retval=1; }
    505   log_msg(2,"%ld: bkpinfo->isodir is now %s", __LINE__, bkpinfo->isodir);
    506   paranoid_free(mount_isodir_command);
    507   paranoid_free(tmp);
    508   paranoid_free(command);
    509   return(retval);
     448        sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     449        run_program_and_log_output(command, 5);
     450        log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
     451    }
     452
     453    if (!get_isodir_info
     454        (g_isodir_device, g_isodir_format, bkpinfo->isodir,
     455         nuke_me_please)) {
     456        return (1);
     457    }
     458    paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
     459
     460    if (is_this_device_mounted(g_isodir_device)) {
     461        log_to_screen("WARNING - isodir is already mounted");
     462        already_mounted = TRUE;
     463    } else {
     464        sprintf(mount_isodir_command, "mount %s", g_isodir_device);
     465        if (strlen(g_isodir_format) > 1) {
     466            sprintf(mount_isodir_command + strlen(mount_isodir_command),
     467                    " -t %s", g_isodir_format);
     468        }
     469        strcat(mount_isodir_command, " -o ro ");
     470        strcat(mount_isodir_command, bkpinfo->isodir);
     471        run_program_and_log_output("df -m", FALSE);
     472        sprintf(tmp,
     473                "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
     474                mount_isodir_command);
     475        log_msg(1, tmp);
     476        if (run_program_and_log_output(mount_isodir_command, FALSE)) {
     477            popup_and_OK
     478                ("Cannot mount the device where the ISO files are stored.");
     479            return (1);
     480        }
     481        log_to_screen
     482            ("I have mounted the device where the ISO files are stored.");
     483    }
     484    if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     485        mount_cdrom(bkpinfo);
     486    }
     487    i = what_number_cd_is_this(bkpinfo);    /* has the side-effect of calling mount_cdrom() */
     488    sprintf(tmp, "%s #%d has been mounted via loopback mount",
     489            media_descriptor_string(bkpinfo->backup_media_type), i);
     490    log_msg(1, tmp);
     491    if (i < 0) {
     492        popup_and_OK
     493            ("Cannot find ISO images in the directory you specified.");
     494        retval = 1;
     495    }
     496    log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
     497            bkpinfo->isodir);
     498    paranoid_free(mount_isodir_command);
     499    paranoid_free(tmp);
     500    paranoid_free(command);
     501    return (retval);
    510502}
    511503
     
    516508 * Kill all Petris processes.
    517509 */
    518 void
    519 kill_petris(void)
    520 {
    521   char *command;
    522   malloc_string(command);
    523   sprintf( command, "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
    524   paranoid_system( command );
    525   paranoid_free(command);
    526 }
     510void kill_petris(void)
     511{
     512    char *command;
     513    malloc_string(command);
     514    sprintf(command,
     515            "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
     516    paranoid_system(command);
     517    paranoid_free(command);
     518}
     519
    527520/**************************************************************************
    528521 *END_KILL_PETRIS                                                         *
     
    537530 * @return 0 for success, nonzero for failure.
    538531 */
    539 int
    540 modify_rclocal_one_time( char *path )
     532int modify_rclocal_one_time(char *path)
    541533{
    542534  /** malloc **/
    543   char *rclocal_fname;
    544   char *newfile_fname;
    545   char *tmp;
    546 
    547   malloc_string(rclocal_fname);
    548   malloc_string(newfile_fname);
    549   malloc_string(tmp);
    550   assert_string_is_neither_NULL_nor_zerolength(path);
    551 
    552   sprintf( rclocal_fname, "%s/rc.local", path );
     535    char *rclocal_fname;
     536    char *newfile_fname;
     537    char *tmp;
     538
     539    malloc_string(rclocal_fname);
     540    malloc_string(newfile_fname);
     541    malloc_string(tmp);
     542    assert_string_is_neither_NULL_nor_zerolength(path);
     543
     544    sprintf(rclocal_fname, "%s/rc.local", path);
    553545
    554546//  sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);
    555547//  run_program_and_log_output( tmp, FALSE );
    556   return( 0 ); /* remove this line to open the floodgates... */
    557 
    558   if (! does_file_exist( rclocal_fname ) )
    559     {
    560       sprintf( rclocal_fname, "%s/rc.d/rc.local", path );
    561     }
    562   if (! does_file_exist( rclocal_fname ) )
    563     {
    564 paranoid_free(rclocal_fname);
    565 paranoid_free(newfile_fname);
    566 paranoid_free(tmp);
    567       return( 1 );
    568     }
    569   sprintf( newfile_fname, "%s/rc.local.mondorescue", path );
    570   sprintf( tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",rclocal_fname );
    571   if (system( tmp ) )
    572     {
    573       sprintf( tmp,"echo \"[ -e %s ] && %s\n\" >> %s",
    574            newfile_fname,
    575            newfile_fname,
    576            rclocal_fname);
    577 
    578       paranoid_system( tmp );
    579     }
    580   sprintf( tmp, "echo -en \"#!/bin/sh\
     548    return (0);                 /* remove this line to open the floodgates... */
     549
     550    if (!does_file_exist(rclocal_fname)) {
     551        sprintf(rclocal_fname, "%s/rc.d/rc.local", path);
     552    }
     553    if (!does_file_exist(rclocal_fname)) {
     554        paranoid_free(rclocal_fname);
     555        paranoid_free(newfile_fname);
     556        paranoid_free(tmp);
     557        return (1);
     558    }
     559    sprintf(newfile_fname, "%s/rc.local.mondorescue", path);
     560    sprintf(tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",
     561            rclocal_fname);
     562    if (system(tmp)) {
     563        sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",
     564                newfile_fname, newfile_fname, rclocal_fname);
     565
     566        paranoid_system(tmp);
     567    }
     568    sprintf(tmp, "echo -en \"#!/bin/sh\
    581569\\n\
    582570\\n\
     
    587575service xfs start\\n\
    588576yes | rm -f %s\\n\
    589 \" > %s",rclocal_fname,rclocal_fname,newfile_fname,newfile_fname);
    590   sprintf( tmp, "chmod +x \"%s\"", newfile_fname );
    591   run_program_and_log_output( tmp, FALSE );
    592 paranoid_free(rclocal_fname);
    593 paranoid_free(newfile_fname);
    594 paranoid_free(tmp);
    595   return( 0 );
    596 }
     577\" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);
     578    sprintf(tmp, "chmod +x \"%s\"", newfile_fname);
     579    run_program_and_log_output(tmp, FALSE);
     580    paranoid_free(rclocal_fname);
     581    paranoid_free(newfile_fname);
     582    paranoid_free(tmp);
     583    return (0);
     584}
     585
    597586/**************************************************************************
    598587 *END_ MODIFY_RCLOCAL_ONE_TIME                                            *
     
    609598 * @return The number of errors encountered (0 for success).
    610599 */
    611 int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable)
    612 {
    613   int retval=0,lino,res;
    614   char *tmp, *these_failed, *format;
    615   struct mountlist_itself *mountlist;
    616 
    617   malloc_string(tmp);
    618   malloc_string(format);
    619   malloc_string(these_failed);
    620   assert(p_external_copy_of_mountlist!=NULL);
    621   mountlist = malloc(sizeof(struct mountlist_itself));
    622   memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
    623   sort_mountlist_by_mountpoint(mountlist, 0);
     600int mount_all_devices(struct mountlist_itself
     601                      *p_external_copy_of_mountlist, bool writeable)
     602{
     603    int retval = 0, lino, res;
     604    char *tmp, *these_failed, *format;
     605    struct mountlist_itself *mountlist;
     606
     607    malloc_string(tmp);
     608    malloc_string(format);
     609    malloc_string(these_failed);
     610    assert(p_external_copy_of_mountlist != NULL);
     611    mountlist = malloc(sizeof(struct mountlist_itself));
     612    memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
     613           sizeof(struct mountlist_itself));
     614    sort_mountlist_by_mountpoint(mountlist, 0);
    624615
    625616  /** menset **/
    626   these_failed[0] = '\0';
    627 
    628   mvaddstr_and_log_it( g_currentY, 0, "Mounting devices         ");
    629   open_progress_form("Mounting devices",
    630              "I am now mounting all the drives.",
    631              "This should not take long.",
    632              "",
    633              mountlist->entries);
    634  
    635   for( lino = 0; lino < mountlist->entries; lino++ )
    636     {
    637       if ( !strcmp( mountlist->el[lino].device, "/proc" ) )
    638         {
    639       log_msg(1, "Again with the /proc - why is this in your mountlist?");
    640     }
    641       else if ( is_this_device_mounted( mountlist->el[lino].device ) )
    642     {
    643       sprintf( tmp, "%s is already mounted",mountlist->el[lino].device );
    644       log_to_screen( tmp );
    645     }
    646       else if ( strcmp( mountlist->el[lino].mountpoint, "none" ) && strcmp( mountlist->el[lino].mountpoint, "lvm" ) && strcmp( mountlist->el[lino].mountpoint,"raid" ) && strcmp(mountlist->el[lino].mountpoint, "image" ) )
    647     {
    648       sprintf( tmp, "Mounting %s",mountlist->el[lino].device );
    649       update_progress_form( tmp );
    650       strcpy(format, mountlist->el[lino].format);
    651       if (!strcmp(format, "ext3")) { strcpy(format, "ext2"); }
    652       res = mount_device( mountlist->el[lino].device,
    653                   mountlist->el[lino].mountpoint,
    654                   format,
    655                   writeable );
    656       retval += res;
    657           if ( res )
    658         {
    659           strcat( these_failed,mountlist->el[lino].device );
    660           strcat( these_failed, " " );
    661         }
    662     }
    663       g_current_progress++;
    664     }
    665   close_progress_form();
    666   run_program_and_log_output( "df -m", TRUE );
    667   if ( retval )
    668     {
    669       if (g_partition_table_locked_up > 0)
    670         {
    671           log_to_screen(
    672 "fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
    673       log_to_screen(
    674 "lock up the partition table. You might have to reboot and use Interactive Mode to");
    675       log_to_screen(
    676 "format and restore *without* partitioning first. Sorry for the inconvenience.");
    677         }
    678       sprintf( tmp, "Could not mount devices %s- shall I abort?", these_failed );
    679       if ( !ask_me_yes_or_no( tmp ) )
    680     {
    681       retval = 0;
    682       log_to_screen( "Continuing, although some devices failed to be mounted" );
    683       mvaddstr_and_log_it( g_currentY++, 74, "Done." );
    684     }
    685       else
    686     {
    687       mvaddstr_and_log_it( g_currentY++, 74, "Failed." );
    688       log_to_screen( "Unable to mount some or all of your partitions." );
    689     }
    690     }
    691   else
    692     {
    693       log_to_screen("All partitions were mounted OK.");
    694       mvaddstr_and_log_it(g_currentY++,74,"Done.");
    695     }
    696   run_program_and_log_output("df -m", 3);
    697   paranoid_free(mountlist);
    698   paranoid_free(tmp);
    699   paranoid_free(format);
    700   paranoid_free(these_failed);
    701   return(retval);
    702 }
     617    these_failed[0] = '\0';
     618
     619    mvaddstr_and_log_it(g_currentY, 0, "Mounting devices         ");
     620    open_progress_form("Mounting devices",
     621                       "I am now mounting all the drives.",
     622                       "This should not take long.",
     623                       "", mountlist->entries);
     624
     625    for (lino = 0; lino < mountlist->entries; lino++) {
     626        if (!strcmp(mountlist->el[lino].device, "/proc")) {
     627            log_msg(1,
     628                    "Again with the /proc - why is this in your mountlist?");
     629        } else if (is_this_device_mounted(mountlist->el[lino].device)) {
     630            sprintf(tmp, "%s is already mounted",
     631                    mountlist->el[lino].device);
     632            log_to_screen(tmp);
     633        } else if (strcmp(mountlist->el[lino].mountpoint, "none")
     634                   && strcmp(mountlist->el[lino].mountpoint, "lvm")
     635                   && strcmp(mountlist->el[lino].mountpoint, "raid")
     636                   && strcmp(mountlist->el[lino].mountpoint, "image")) {
     637            sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
     638            update_progress_form(tmp);
     639            strcpy(format, mountlist->el[lino].format);
     640            if (!strcmp(format, "ext3")) {
     641                strcpy(format, "ext2");
     642            }
     643            res = mount_device(mountlist->el[lino].device,
     644                               mountlist->el[lino].mountpoint,
     645                               format, writeable);
     646            retval += res;
     647            if (res) {
     648                strcat(these_failed, mountlist->el[lino].device);
     649                strcat(these_failed, " ");
     650            }
     651        }
     652        g_current_progress++;
     653    }
     654    close_progress_form();
     655    run_program_and_log_output("df -m", TRUE);
     656    if (retval) {
     657        if (g_partition_table_locked_up > 0) {
     658            log_to_screen
     659                ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
     660            log_to_screen
     661                ("lock up the partition table. You might have to reboot and use Interactive Mode to");
     662            log_to_screen
     663                ("format and restore *without* partitioning first. Sorry for the inconvenience.");
     664        }
     665        sprintf(tmp, "Could not mount devices %s- shall I abort?",
     666                these_failed);
     667        if (!ask_me_yes_or_no(tmp)) {
     668            retval = 0;
     669            log_to_screen
     670                ("Continuing, although some devices failed to be mounted");
     671            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     672        } else {
     673            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     674            log_to_screen
     675                ("Unable to mount some or all of your partitions.");
     676        }
     677    } else {
     678        log_to_screen("All partitions were mounted OK.");
     679        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     680    }
     681    run_program_and_log_output("df -m", 3);
     682    paranoid_free(mountlist);
     683    paranoid_free(tmp);
     684    paranoid_free(format);
     685    paranoid_free(these_failed);
     686    return (retval);
     687}
     688
    703689 /**************************************************************************
    704690  *END_MOUNT_ALL_DEVICES                                                   *
     
    717703int mount_cdrom(struct s_bkpinfo *bkpinfo)
    718704{
    719   char *mount_cmd;
    720   int i,res;
     705    char *mount_cmd;
     706    int i, res;
    721707#ifdef __FreeBSD__
    722   char mdd[32];
    723   char *mddev = mdd;
     708    char mdd[32];
     709    char *mddev = mdd;
    724710#endif
    725711
    726   malloc_string(mount_cmd);
    727   assert(bkpinfo!=NULL);
    728  
    729   if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev)
    730     {
    731       log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
    732       paranoid_free(mount_cmd);
    733       return 0;
    734     }
    735 
    736   if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE))
    737     {
    738       log_msg(2,"mount_cdrom() - CD already mounted. Fair enough.");
    739       paranoid_free(mount_cmd);
    740       return(0);
    741     }
    742 
    743   if (bkpinfo->backup_media_type == nfs)
    744     {
    745       log_msg(2,"Mounting for NFS thingy");
    746       log_msg(2, "isodir = %s", bkpinfo->isodir);
    747       if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
    748       && am_I_in_disaster_recovery_mode())
    749         {
    750       strcpy(bkpinfo->isodir, "/tmp/isodir");
    751           log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    752     }
    753 
     712    malloc_string(mount_cmd);
     713    assert(bkpinfo != NULL);
     714
     715    if (bkpinfo->backup_media_type == tape
     716        || bkpinfo->backup_media_type == udev) {
     717        log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
     718        paranoid_free(mount_cmd);
     719        return 0;
     720    }
     721
     722    if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) {
     723        log_msg(2, "mount_cdrom() - CD already mounted. Fair enough.");
     724        paranoid_free(mount_cmd);
     725        return (0);
     726    }
     727
     728    if (bkpinfo->backup_media_type == nfs) {
     729        log_msg(2, "Mounting for NFS thingy");
     730        log_msg(2, "isodir = %s", bkpinfo->isodir);
     731        if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
     732            && am_I_in_disaster_recovery_mode()) {
     733            strcpy(bkpinfo->isodir, "/tmp/isodir");
     734            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
     735        }
    754736#ifdef __FreeBSD__
    755       sprintf (mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number);
    756       mddev = make_vn (mount_cmd);
    757       sprintf (mount_cmd, "mount_cd9660 -r %s "MNT_CDROM, mddev);
     737        sprintf(mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir,
     738                bkpinfo->nfs_remote_dir, g_current_media_number);
     739        mddev = make_vn(mount_cmd);
     740        sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
    758741#else
    759       sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number, MNT_CDROM);
     742        sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s",
     743                bkpinfo->isodir, bkpinfo->nfs_remote_dir,
     744                g_current_media_number, MNT_CDROM);
    760745#endif
    761746
    762     }
    763   else
    764 
    765   if (bkpinfo->backup_media_type == iso)
    766     {
     747    } else
     748     if (bkpinfo->backup_media_type == iso) {
    767749#ifdef __FreeBSD__
    768       sprintf (mount_cmd, "%s/%d.iso", bkpinfo->isodir, g_current_media_number);
    769       mddev = make_vn (mount_cmd);
    770       sprintf (mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     750        sprintf(mount_cmd, "%s/%d.iso", bkpinfo->isodir,
     751                g_current_media_number);
     752        mddev = make_vn(mount_cmd);
     753        sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
    771754#else
    772       sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, g_current_media_number, MNT_CDROM);
     755        sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s",
     756                bkpinfo->isodir, g_current_media_number, MNT_CDROM);
    773757#endif
    774     }
    775   else if (strstr(bkpinfo->media_device, "/dev/"))
    776 
     758    } else if (strstr(bkpinfo->media_device, "/dev/"))
    777759#ifdef __FreeBSD__
    778     { sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); }
     760    {
     761        sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     762                MNT_CDROM);
     763    }
    779764#else
    780     { sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); }
     765    {
     766        sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     767                bkpinfo->media_device, MNT_CDROM);
     768    }
    781769#endif
    782770
    783   else
    784     {
    785       if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE"))
    786         { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); }
    787       else
    788         { find_cdrom_device( bkpinfo->media_device, TRUE ); }
     771    else {
     772        if (bkpinfo->disaster_recovery
     773            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     774            strcpy(bkpinfo->media_device,
     775                   last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     776        } else {
     777            find_cdrom_device(bkpinfo->media_device, TRUE);
     778        }
    789779
    790780#ifdef __FreeBSD__
    791       sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
     781        sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     782                MNT_CDROM);
    792783#else
    793       sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
     784        sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     785                bkpinfo->media_device, MNT_CDROM);
    794786#endif
    795787
    796     }
    797   log_msg(2,"(mount_cdrom) --- command = %s", mount_cmd);
    798   for(i=0;i<2;i++)
    799     {
    800       res=run_program_and_log_output(mount_cmd, FALSE);
    801       if (!res)
    802     {
    803       break;
    804     }
    805       else
    806     {
    807       log_msg(2,"Failed to mount CD-ROM drive.");
    808       sleep(5);
    809       run_program_and_log_output( "sync", FALSE );
    810     }
    811     }
    812   if (res) { log_msg(2,"Failed, despite %d attempts", i); }
    813   else { log_msg(2,"Mounted CD-ROM drive OK"); }
    814   paranoid_free(mount_cmd);
    815   return(res);
     788    }
     789    log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd);
     790    for (i = 0; i < 2; i++) {
     791        res = run_program_and_log_output(mount_cmd, FALSE);
     792        if (!res) {
     793            break;
     794        } else {
     795            log_msg(2, "Failed to mount CD-ROM drive.");
     796            sleep(5);
     797            run_program_and_log_output("sync", FALSE);
     798        }
     799    }
     800    if (res) {
     801        log_msg(2, "Failed, despite %d attempts", i);
     802    } else {
     803        log_msg(2, "Mounted CD-ROM drive OK");
     804    }
     805    paranoid_free(mount_cmd);
     806    return (res);
    816807}
    817808
     
    833824 * @return 0 for success, nonzero for failure.
    834825 */
    835 int
    836 mount_device( char *device, char *mpt, char *format, bool writeable)
    837 {
    838   int res = 0;
     826int mount_device(char *device, char *mpt, char *format, bool writeable)
     827{
     828    int res = 0;
    839829
    840830  /** malloc **/
    841   char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
    842 
    843   assert_string_is_neither_NULL_nor_zerolength(device);
    844   assert_string_is_neither_NULL_nor_zerolength(mpt);
    845   assert(format!=NULL);
    846   malloc_string(tmp);
    847   malloc_string(command);
    848   malloc_string(mountdir);
    849   malloc_string(mountpoint);
    850   malloc_string(additional_parameters);
    851 
    852       if (!strcmp (mpt, "/1"))
    853       {
    854           strcpy (mountpoint, "/");
    855           log_msg (3,"Mommm! SME is being a dildo!");
    856       }
    857       else
    858       {
    859           strcpy (mountpoint, mpt);
    860       }
    861 
    862   if ( !strcmp(mountpoint,"lvm" ) )
    863     {
    864       return( 0 );
    865     }
    866   if ( !strcmp(mountpoint,"image" ) )
    867     {
    868       return( 0 );
    869     }
    870   sprintf( tmp, "Mounting device %s   ", device );
    871   log_msg( 1, tmp );
    872   if ( writeable )
    873     {
    874       strcpy( additional_parameters, "-o rw");
    875     }
    876   else
    877     {
    878       strcpy( additional_parameters, "-o ro");
    879     }
    880   if (find_home_of_exe("setfattr"))
    881     {
    882       strcat( additional_parameters, ",user_xattr");
    883     }
    884   if (find_home_of_exe("setfacl"))
    885     {
    886       strcat( additional_parameters, ",acl");
    887     }
    888    
    889   if ( !strcmp( mountpoint,"swap" ) )
    890     {
    891       sprintf( command, "swapon %s", device );
    892     }
    893   else
    894     {
    895       if ( !strcmp( mountpoint,"/" ) )
    896         {
    897       strcpy( mountdir, MNT_RESTORING);
    898     }
    899       else
    900         {
    901       sprintf( mountdir, "%s%s", MNT_RESTORING, mountpoint);
    902     }
    903       sprintf( command, "mkdir -p %s", mountdir );
    904       run_program_and_log_output( command, FALSE );
    905       sprintf( command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE );
    906       log_msg(2, "command='%s'", command);
    907     }
    908   res = run_program_and_log_output( command, TRUE );
    909   if ( res && (strstr(command, "xattr") || strstr(command, "acl")))
    910     {
    911       log_msg(1, "Re-trying without the fancy extra parameters");
    912       sprintf( command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE );
    913       res = run_program_and_log_output( command, TRUE );
    914     }
    915   if ( res )
    916     {
    917       log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir );
    918       log_msg(1, "command was '%s'", command);
    919       if ( !strcmp( mountpoint, "swap" ) )
    920         {
    921       log_to_screen( tmp );
    922     }
    923       else
    924     {
    925       log_msg(2, "Retrying w/o the '-t' switch" );
    926       sprintf( command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE);
    927       log_msg(2, "2nd command = '%s'", command);
    928       res = run_program_and_log_output( command, TRUE );
    929       if (res == 0 )
    930         {
    931           log_msg(1, "That's OK. I called mount w/o a filesystem type and it worked fine in the end." );
    932         }
    933       else
    934         {
    935           log_to_screen( tmp );
    936         }
    937         }
    938     }
    939   if (res && !strcmp( mountpoint, "swap" ))
    940     {
    941      log_msg(2, "That's ok. It's just a swap partition.");
    942      log_msg(2, "Non-fatal error. Returning 0.");
    943      res=0;
    944     }
    945 
    946   paranoid_free(tmp);
    947   paranoid_free(command);
    948   paranoid_free(mountdir);
    949   paranoid_free(mountpoint);
    950   paranoid_free(additional_parameters);
    951 
    952   return( res );
    953 }
     831    char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
     832
     833    assert_string_is_neither_NULL_nor_zerolength(device);
     834    assert_string_is_neither_NULL_nor_zerolength(mpt);
     835    assert(format != NULL);
     836    malloc_string(tmp);
     837    malloc_string(command);
     838    malloc_string(mountdir);
     839    malloc_string(mountpoint);
     840    malloc_string(additional_parameters);
     841
     842    if (!strcmp(mpt, "/1")) {
     843        strcpy(mountpoint, "/");
     844        log_msg(3, "Mommm! SME is being a dildo!");
     845    } else {
     846        strcpy(mountpoint, mpt);
     847    }
     848
     849    if (!strcmp(mountpoint, "lvm")) {
     850        return (0);
     851    }
     852    if (!strcmp(mountpoint, "image")) {
     853        return (0);
     854    }
     855    sprintf(tmp, "Mounting device %s   ", device);
     856    log_msg(1, tmp);
     857    if (writeable) {
     858        strcpy(additional_parameters, "-o rw");
     859    } else {
     860        strcpy(additional_parameters, "-o ro");
     861    }
     862    if (find_home_of_exe("setfattr")) {
     863        strcat(additional_parameters, ",user_xattr");
     864    }
     865    if (find_home_of_exe("setfacl")) {
     866        strcat(additional_parameters, ",acl");
     867    }
     868
     869    if (!strcmp(mountpoint, "swap")) {
     870        sprintf(command, "swapon %s", device);
     871    } else {
     872        if (!strcmp(mountpoint, "/")) {
     873            strcpy(mountdir, MNT_RESTORING);
     874        } else {
     875            sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
     876        }
     877        sprintf(command, "mkdir -p %s", mountdir);
     878        run_program_and_log_output(command, FALSE);
     879        sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
     880                additional_parameters, mountdir, MONDO_LOGFILE);
     881        log_msg(2, "command='%s'", command);
     882    }
     883    res = run_program_and_log_output(command, TRUE);
     884    if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
     885        log_msg(1, "Re-trying without the fancy extra parameters");
     886        sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
     887                mountdir, MONDO_LOGFILE);
     888        res = run_program_and_log_output(command, TRUE);
     889    }
     890    if (res) {
     891        log_msg(1, "Unable to mount device %s (type %s) at %s", device,
     892                format, mountdir);
     893        log_msg(1, "command was '%s'", command);
     894        if (!strcmp(mountpoint, "swap")) {
     895            log_to_screen(tmp);
     896        } else {
     897            log_msg(2, "Retrying w/o the '-t' switch");
     898            sprintf(command, "mount %s %s 2>> %s", device, mountdir,
     899                    MONDO_LOGFILE);
     900            log_msg(2, "2nd command = '%s'", command);
     901            res = run_program_and_log_output(command, TRUE);
     902            if (res == 0) {
     903                log_msg(1,
     904                        "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
     905            } else {
     906                log_to_screen(tmp);
     907            }
     908        }
     909    }
     910    if (res && !strcmp(mountpoint, "swap")) {
     911        log_msg(2, "That's ok. It's just a swap partition.");
     912        log_msg(2, "Non-fatal error. Returning 0.");
     913        res = 0;
     914    }
     915
     916    paranoid_free(tmp);
     917    paranoid_free(command);
     918    paranoid_free(mountdir);
     919    paranoid_free(mountpoint);
     920    paranoid_free(additional_parameters);
     921
     922    return (res);
     923}
     924
    954925/**************************************************************************
    955926 *END_MOUNT_DEVICE                                                        *
     
    962933 * up correctly on the first boot.
    963934 */
    964 void
    965 protect_against_braindead_sysadmins()
    966 {
    967   run_program_and_log_output( "touch " MNT_RESTORING "/var/log/pacct", FALSE );
    968   run_program_and_log_output( "touch " MNT_RESTORING "/var/account/pacct", FALSE );
    969   if (run_program_and_log_output( "ls " MNT_RESTORING" /tmp", FALSE ) )
    970      {
    971       run_program_and_log_output( "chmod 1777 " MNT_RESTORING "/tmp", FALSE );
    972     }
    973   run_program_and_log_output( "mkdir -p " MNT_RESTORING "/var/run/console", FALSE );
    974   run_program_and_log_output( "chmod 777 " MNT_RESTORING "/dev/null", FALSE );
    975   run_program_and_log_output( "cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done", TRUE);
    976   run_program_and_log_output( "rm -f " MNT_RESTORING "/var/run/*.pid", TRUE);
    977   run_program_and_log_output( "rm -f " MNT_RESTORING "/var/lock/subsys/*", TRUE);
    978 }
     935void protect_against_braindead_sysadmins()
     936{
     937    run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
     938                               FALSE);
     939    run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
     940                               FALSE);
     941    if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
     942        run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
     943                                   FALSE);
     944    }
     945    run_program_and_log_output("mkdir -p " MNT_RESTORING
     946                               "/var/run/console", FALSE);
     947    run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
     948                               FALSE);
     949    run_program_and_log_output("cd " MNT_RESTORING
     950                               "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done",
     951                               TRUE);
     952    run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
     953                               TRUE);
     954    run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
     955                               TRUE);
     956}
     957
    979958/**************************************************************************
    980959 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS                                 *
     
    991970 * @return 0 for success, nonzero for failure.
    992971 */
    993 int
    994 read_cfg_file_into_bkpinfo( char* cfgf, struct s_bkpinfo *bkpinfo)
     972int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
    995973{
    996974  /** add mallocs **/
    997   char *value;
    998   char *tmp;
    999       char *command;
    1000       char *iso_mnt;
    1001       char *iso_path;
    1002       char *old_isodir;
    1003       char cfg_file[100];
    1004   t_bkptype media_specified_by_user;
    1005 
    1006   malloc_string(command);
    1007   malloc_string(iso_mnt);
    1008   malloc_string(iso_path);
    1009   malloc_string(old_isodir);
    1010   malloc_string(value);
    1011   malloc_string(tmp);
     975    char *value;
     976    char *tmp;
     977    char *command;
     978    char *iso_mnt;
     979    char *iso_path;
     980    char *old_isodir;
     981    char cfg_file[100];
     982    t_bkptype media_specified_by_user;
     983
     984    malloc_string(command);
     985    malloc_string(iso_mnt);
     986    malloc_string(iso_path);
     987    malloc_string(old_isodir);
     988    malloc_string(value);
     989    malloc_string(tmp);
    1012990//  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
    1013   assert(bkpinfo!=NULL);
    1014 
    1015   if (!cfgf)
    1016     { strcpy(cfg_file, g_mondo_cfg_file); }
    1017   else
    1018     { strcpy(cfg_file, cfgf); }
    1019 
    1020   media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
    1021 
    1022   if (0 == read_cfg_var(cfg_file, "backup-media-type", value))
    1023     {
    1024       if ( !strcmp(value, "cdstream" ) )
    1025     {
    1026       bkpinfo->backup_media_type = cdstream;
    1027     }
    1028       else if (!strcmp(value, "cdr"))
    1029     {
    1030       bkpinfo->backup_media_type = cdr;
    1031     }
    1032       else if (!strcmp(value, "cdrw"))
    1033     {
    1034       bkpinfo->backup_media_type = cdrw;
    1035     }
    1036       else if (!strcmp(value, "dvd"))
    1037     {
    1038       bkpinfo->backup_media_type = dvd;
    1039     }
    1040       else if (!strcmp(value, "iso"))
    1041     {
     991    assert(bkpinfo != NULL);
     992
     993    if (!cfgf) {
     994        strcpy(cfg_file, g_mondo_cfg_file);
     995    } else {
     996        strcpy(cfg_file, cfgf);
     997    }
     998
     999    media_specified_by_user = bkpinfo->backup_media_type;   // or 'none', if not specified
     1000
     1001    if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
     1002        if (!strcmp(value, "cdstream")) {
     1003            bkpinfo->backup_media_type = cdstream;
     1004        } else if (!strcmp(value, "cdr")) {
     1005            bkpinfo->backup_media_type = cdr;
     1006        } else if (!strcmp(value, "cdrw")) {
     1007            bkpinfo->backup_media_type = cdrw;
     1008        } else if (!strcmp(value, "dvd")) {
     1009            bkpinfo->backup_media_type = dvd;
     1010        } else if (!strcmp(value, "iso")) {
    10421011/*
    10431012      if (am_I_in_disaster_recovery_mode()
     
    10471016
    10481017// Patch by Conor Daly - 2004/07/12
    1049           bkpinfo->backup_media_type = iso;
    1050           if (am_I_in_disaster_recovery_mode())
    1051         {
    1052  /* Check to see if CD is already mounted before mounting it... */
    1053               if (!is_this_device_mounted("/dev/cdrom"))
    1054             {
    1055                   log_msg(2, "NB: CDROM device not mounted, mounting...");
    1056                   run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
    1057                 }
    1058               if( does_file_exist(MNT_CDROM"/archives/filelist.0"))
     1018            bkpinfo->backup_media_type = iso;
     1019            if (am_I_in_disaster_recovery_mode()) {
     1020                /* Check to see if CD is already mounted before mounting it... */
     1021                if (!is_this_device_mounted("/dev/cdrom")) {
     1022                    log_msg(2,
     1023                            "NB: CDROM device not mounted, mounting...");
     1024                    run_program_and_log_output("mount /dev/cdrom "
     1025                                               MNT_CDROM, 1);
     1026                }
     1027                if (does_file_exist(MNT_CDROM "/archives/filelist.0"))
    10591028// End patch
    1060             {
    1061                   bkpinfo->backup_media_type = cdr;
    1062               run_program_and_log_output("umount "MNT_CDROM, 1);
    1063               log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
    1064                 }
    1065           else
    1066             {
    1067               bkpinfo->backup_media_type = iso;
    1068             }
    1069         }
    1070     }
    1071       else if (!strcmp(value, "nfs"))
    1072     {
    1073       bkpinfo->backup_media_type = nfs;
    1074     }
    1075       else if (!strcmp(value, "tape"))
    1076     {
    1077       bkpinfo->backup_media_type = tape;
    1078     }
    1079       else if (!strcmp(value, "udev"))
    1080     {
    1081       bkpinfo->backup_media_type = udev;
    1082     }
    1083       else
    1084     {
    1085       fatal_error("UNKNOWN bkp-media-type");
    1086     }
    1087     }
    1088   else
    1089     {
    1090       fatal_error("backup-media-type not specified!");
    1091     }
    1092   if (bkpinfo->disaster_recovery)
    1093     {
    1094       if (bkpinfo->backup_media_type == cdstream)
    1095         {
    1096           sprintf(bkpinfo->media_device, "/dev/cdrom");
     1029                {
     1030                    bkpinfo->backup_media_type = cdr;
     1031                    run_program_and_log_output("umount " MNT_CDROM, 1);
     1032                    log_it
     1033                        ("Re-jigging configuration AGAIN. CD-R, not ISO.");
     1034                } else {
     1035                    bkpinfo->backup_media_type = iso;
     1036                }
     1037            }
     1038        } else if (!strcmp(value, "nfs")) {
     1039            bkpinfo->backup_media_type = nfs;
     1040        } else if (!strcmp(value, "tape")) {
     1041            bkpinfo->backup_media_type = tape;
     1042        } else if (!strcmp(value, "udev")) {
     1043            bkpinfo->backup_media_type = udev;
     1044        } else {
     1045            fatal_error("UNKNOWN bkp-media-type");
     1046        }
     1047    } else {
     1048        fatal_error("backup-media-type not specified!");
     1049    }
     1050    if (bkpinfo->disaster_recovery) {
     1051        if (bkpinfo->backup_media_type == cdstream) {
     1052            sprintf(bkpinfo->media_device, "/dev/cdrom");
    10971053//          bkpinfo->media_size[0] = -1;
    1098           bkpinfo->media_size[0] = 1999*1024;
    1099           bkpinfo->media_size[1] = 650; /* good guess */
    1100         }
    1101       else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev)
    1102         {
    1103           if (read_cfg_var(cfg_file, "media-dev", value)) { fatal_error("Cannot get tape device name from cfg file"); }
    1104           strcpy(bkpinfo->media_device, value);
    1105           read_cfg_var(cfg_file, "media-size", value);
    1106           bkpinfo->media_size[1] = atol(value);
    1107           sprintf(tmp,"Backup medium is TAPE --- dev=%s",bkpinfo->media_device);
    1108           log_msg(2, tmp);
    1109         }
    1110        else
    1111          {
    1112            strcpy(bkpinfo->media_device,"/dev/cdrom"); /* we don't really need this var */
    1113            bkpinfo->media_size[0]= 1999*1024; /* 650, probably, but we don't need this var anyway */
    1114            bkpinfo->media_size[1]=1999*1024; /* 650, probably, but we don't need this var anyway */
    1115            log_msg(2, "Backup medium is CD-R[W]");
    1116          }
    1117       }
    1118   else
    1119     {
    1120       log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
    1121     }
    1122  
    1123   read_cfg_var(cfg_file, "use-star", value);
    1124   if (strstr(value,"yes"))
    1125     {
    1126       bkpinfo->use_star = TRUE;
    1127       log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
    1128     }
    1129 
    1130   if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value))
    1131     {
    1132       bkpinfo->internal_tape_block_size = atol(value);
    1133       log_msg(1, "Internal tape block size has been custom-set to %ld", bkpinfo->internal_tape_block_size);
    1134     }
    1135   else
    1136     {
    1137       bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    1138       log_msg(1, "Internal tape block size = default (%ld)", DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
    1139     }
    1140 
    1141   read_cfg_var(cfg_file, "use-lzo", value);
    1142   if (strstr(value,"yes"))
    1143     {
    1144       bkpinfo->use_lzo = TRUE;
    1145       strcpy(bkpinfo->zip_exe, "lzop");
    1146       strcpy(bkpinfo->zip_suffix, "lzo");
    1147     }
    1148   else
    1149     {
    1150       read_cfg_var(cfg_file, "use-comp", value);
    1151       if (strstr(value,"yes"))
    1152     {
    1153       bkpinfo->use_lzo = FALSE;
    1154       strcpy(bkpinfo->zip_exe, "bzip2");
    1155       strcpy(bkpinfo->zip_suffix, "bz2");
    1156     }
    1157       else
    1158     {
    1159       bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    1160     }
    1161     }
    1162 
    1163   value[0] = '\0';
    1164   read_cfg_var( cfg_file, "differential", value);
    1165   if (!strcmp(value, "yes") || !strcmp(value, "1"))
    1166     {
    1167       bkpinfo->differential = TRUE;
    1168     }
    1169   log_msg(2, "differential var = '%s'", value);
    1170   if (bkpinfo->differential)
    1171     {
    1172       log_msg(2, "THIS IS A DIFFERENTIAL BACKUP" );
    1173     }
    1174   else
    1175     {
    1176       log_msg(2, "This is a regular (full) backup");
    1177     }
    1178 
    1179   read_cfg_var( g_mondo_cfg_file, "please-dont-eject", tmp);
    1180   if (tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject"))
    1181     { bkpinfo->please_dont_eject = TRUE; log_msg(2, "Ok, I shan't eject when restoring! Groovy."); }
    1182 
    1183   if (bkpinfo->backup_media_type == nfs)
    1184     {
    1185       if (!cfgf)
    1186         {
    1187           log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
    1188           log_msg(2, "nfs_remote_dir remains %s", bkpinfo->nfs_remote_dir);
    1189       log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
    1190     }
    1191       else
    1192         {
    1193           read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", bkpinfo->nfs_mount);
    1194           read_cfg_var(g_mondo_cfg_file, "nfs-server-path", bkpinfo->nfs_remote_dir);
    1195           log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
    1196           log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
    1197     }
    1198     }
    1199   else if (bkpinfo->backup_media_type == iso)
    1200     {
    1201  /* Patch by Conor Daly 23-june-2004
    1202   * to correctly mount iso-dev and set a sensible
    1203   * isodir in disaster recovery mode
    1204   */
    1205       strcpy (old_isodir, bkpinfo->isodir);
    1206       read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
    1207       read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
    1208       sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1209       if (!bkpinfo->isodir[0]) {
    1210       strcpy (bkpinfo->isodir, old_isodir);
    1211       }
    1212       if (!bkpinfo->disaster_recovery)
    1213         {
    1214         if (strcmp(old_isodir, bkpinfo->isodir)) {
    1215           log_it("user nominated isodir differs from archive, keeping user's choice: %s %s\n", old_isodir, bkpinfo->isodir);
    1216         strcpy (bkpinfo->isodir, old_isodir);
    1217         }
    1218         }
    1219       read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    1220       log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
    1221       if (bkpinfo->disaster_recovery) {
    1222       if (is_this_device_mounted(g_isodir_device))
    1223           { log_msg(2, "NB: isodir is already mounted");
    1224         /* Find out where it's mounted */
    1225          sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", g_isodir_device);
    1226         log_it("command = %s", command);
    1227         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    1228         sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    1229           }
    1230       else
    1231           {
    1232           sprintf(iso_mnt, "/tmp/isodir");
    1233           sprintf(tmp, "mkdir -p %s", iso_mnt);
    1234           run_program_and_log_output(tmp, 5);
    1235           sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
    1236           if (run_program_and_log_output(tmp, 3))
    1237               {
    1238                 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
    1239             bkpinfo->backup_media_type = cdr;
    1240             strcpy(bkpinfo->media_device,"/dev/cdrom"); /* superfluous */
    1241             bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
    1242             if ( mount_cdrom( bkpinfo ) )
    1243               {
    1244                     fatal_error( "Unable to mount isodir. Failed to mount CD-ROM as well.");
    1245               }
    1246             else
    1247               {
    1248                 log_msg(1, "You backed up to disk, then burned some CDs. Naughty monkey!" );
    1249               }
    1250               }
    1251           }
    1252       /* bkpinfo->isodir should now be the true path to 1.iso etc... */
    1253       if (bkpinfo->backup_media_type == iso)
    1254         {
    1255               sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1256         }
    1257       }
    1258     }
    1259 
    1260   if (media_specified_by_user != none)
    1261     {
    1262       if (g_restoring_live_from_cd)
    1263         {
    1264           if (bkpinfo->backup_media_type != media_specified_by_user)
    1265             {
    1266               log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
    1267               interactively_obtain_media_parameters_from_user( bkpinfo, FALSE);
    1268               media_specified_by_user = bkpinfo->backup_media_type;
    1269               get_cfg_file_from_archive(bkpinfo);
     1054            bkpinfo->media_size[0] = 1999 * 1024;
     1055            bkpinfo->media_size[1] = 650;   /* good guess */
     1056        } else if (bkpinfo->backup_media_type == tape
     1057                   || bkpinfo->backup_media_type == udev) {
     1058            if (read_cfg_var(cfg_file, "media-dev", value)) {
     1059                fatal_error("Cannot get tape device name from cfg file");
     1060            }
     1061            strcpy(bkpinfo->media_device, value);
     1062            read_cfg_var(cfg_file, "media-size", value);
     1063            bkpinfo->media_size[1] = atol(value);
     1064            sprintf(tmp, "Backup medium is TAPE --- dev=%s",
     1065                    bkpinfo->media_device);
     1066            log_msg(2, tmp);
     1067        } else {
     1068            strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
     1069            bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     1070            bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     1071            log_msg(2, "Backup medium is CD-R[W]");
     1072        }
     1073    } else {
     1074        log_msg(2,
     1075                "Not in Disaster Recovery Mode. No need to derive device name from config file.");
     1076    }
     1077
     1078    read_cfg_var(cfg_file, "use-star", value);
     1079    if (strstr(value, "yes")) {
     1080        bkpinfo->use_star = TRUE;
     1081        log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
     1082    }
     1083
     1084    if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
     1085        bkpinfo->internal_tape_block_size = atol(value);
     1086        log_msg(1, "Internal tape block size has been custom-set to %ld",
     1087                bkpinfo->internal_tape_block_size);
     1088    } else {
     1089        bkpinfo->internal_tape_block_size =
     1090            DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     1091        log_msg(1, "Internal tape block size = default (%ld)",
     1092                DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
     1093    }
     1094
     1095    read_cfg_var(cfg_file, "use-lzo", value);
     1096    if (strstr(value, "yes")) {
     1097        bkpinfo->use_lzo = TRUE;
     1098        strcpy(bkpinfo->zip_exe, "lzop");
     1099        strcpy(bkpinfo->zip_suffix, "lzo");
     1100    } else {
     1101        read_cfg_var(cfg_file, "use-comp", value);
     1102        if (strstr(value, "yes")) {
     1103            bkpinfo->use_lzo = FALSE;
     1104            strcpy(bkpinfo->zip_exe, "bzip2");
     1105            strcpy(bkpinfo->zip_suffix, "bz2");
     1106        } else {
     1107            bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     1108        }
     1109    }
     1110
     1111    value[0] = '\0';
     1112    read_cfg_var(cfg_file, "differential", value);
     1113    if (!strcmp(value, "yes") || !strcmp(value, "1")) {
     1114        bkpinfo->differential = TRUE;
     1115    }
     1116    log_msg(2, "differential var = '%s'", value);
     1117    if (bkpinfo->differential) {
     1118        log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
     1119    } else {
     1120        log_msg(2, "This is a regular (full) backup");
     1121    }
     1122
     1123    read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
     1124    if (tmp[0]
     1125        ||
     1126        strstr(call_program_and_get_last_line_of_output
     1127               ("cat /proc/cmdline"), "donteject")) {
     1128        bkpinfo->please_dont_eject = TRUE;
     1129        log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
     1130    }
     1131
     1132    if (bkpinfo->backup_media_type == nfs) {
     1133        if (!cfgf) {
     1134            log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
     1135            log_msg(2, "nfs_remote_dir remains %s",
     1136                    bkpinfo->nfs_remote_dir);
     1137            log_msg(2,
     1138                    "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
     1139        } else {
     1140            read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
     1141                         bkpinfo->nfs_mount);
     1142            read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
     1143                         bkpinfo->nfs_remote_dir);
     1144            log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
     1145            log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
     1146        }
     1147    } else if (bkpinfo->backup_media_type == iso) {
     1148        /* Patch by Conor Daly 23-june-2004
     1149         * to correctly mount iso-dev and set a sensible
     1150         * isodir in disaster recovery mode
     1151         */
     1152        strcpy(old_isodir, bkpinfo->isodir);
     1153        read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
     1154        read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
     1155        sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1156        if (!bkpinfo->isodir[0]) {
     1157            strcpy(bkpinfo->isodir, old_isodir);
     1158        }
     1159        if (!bkpinfo->disaster_recovery) {
     1160            if (strcmp(old_isodir, bkpinfo->isodir)) {
     1161                log_it
     1162                    ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
     1163                     old_isodir, bkpinfo->isodir);
     1164                strcpy(bkpinfo->isodir, old_isodir);
     1165            }
     1166        }
     1167        read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     1168        log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
     1169                g_isodir_device);
     1170        if (bkpinfo->disaster_recovery) {
     1171            if (is_this_device_mounted(g_isodir_device)) {
     1172                log_msg(2, "NB: isodir is already mounted");
     1173                /* Find out where it's mounted */
     1174                sprintf(command,
     1175                        "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     1176                        g_isodir_device);
     1177                log_it("command = %s", command);
     1178                log_it("res of it = %s",
     1179                       call_program_and_get_last_line_of_output(command));
     1180                sprintf(iso_mnt, "%s",
     1181                        call_program_and_get_last_line_of_output(command));
     1182            } else {
     1183                sprintf(iso_mnt, "/tmp/isodir");
     1184                sprintf(tmp, "mkdir -p %s", iso_mnt);
     1185                run_program_and_log_output(tmp, 5);
     1186                sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
     1187                if (run_program_and_log_output(tmp, 3)) {
     1188                    log_msg(1,
     1189                            "Unable to mount isodir. Perhaps this is really a CD backup?");
     1190                    bkpinfo->backup_media_type = cdr;
     1191                    strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
     1192                    bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
     1193                    if (mount_cdrom(bkpinfo)) {
     1194                        fatal_error
     1195                            ("Unable to mount isodir. Failed to mount CD-ROM as well.");
     1196                    } else {
     1197                        log_msg(1,
     1198                                "You backed up to disk, then burned some CDs. Naughty monkey!");
     1199                    }
     1200                }
     1201            }
     1202            /* bkpinfo->isodir should now be the true path to 1.iso etc... */
     1203            if (bkpinfo->backup_media_type == iso) {
     1204                sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1205            }
     1206        }
     1207    }
     1208
     1209    if (media_specified_by_user != none) {
     1210        if (g_restoring_live_from_cd) {
     1211            if (bkpinfo->backup_media_type != media_specified_by_user) {
     1212                log_msg(2,
     1213                        "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
     1214                interactively_obtain_media_parameters_from_user(bkpinfo,
     1215                                                                FALSE);
     1216                media_specified_by_user = bkpinfo->backup_media_type;
     1217                get_cfg_file_from_archive(bkpinfo);
    12701218/*
    12711219              if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
    12721220                { g_restoring_live_from_cd = FALSE; }
    12731221*/
    1274             }
    1275         }
    1276       bkpinfo->backup_media_type = media_specified_by_user;
    1277    }
    1278   g_backup_media_type = bkpinfo->backup_media_type;
    1279   paranoid_free(value);
    1280   paranoid_free(tmp);
    1281   paranoid_free(command);
    1282   paranoid_free(iso_mnt);
    1283   paranoid_free(iso_path);
    1284   paranoid_free(old_isodir);
    1285   return( 0 );
    1286 
    1287 }
     1222            }
     1223        }
     1224        bkpinfo->backup_media_type = media_specified_by_user;
     1225    }
     1226    g_backup_media_type = bkpinfo->backup_media_type;
     1227    paranoid_free(value);
     1228    paranoid_free(tmp);
     1229    paranoid_free(command);
     1230    paranoid_free(iso_mnt);
     1231    paranoid_free(iso_path);
     1232    paranoid_free(old_isodir);
     1233    return (0);
     1234
     1235}
     1236
    12881237/**************************************************************************
    12891238 *END_READ_CFG_FILE_INTO_BKPINFO                                          *
     
    12911240
    12921241
    1293  
     1242
    12941243
    12951244/**
     
    13041253 */
    13051254struct
    1306 s_node *process_filelist_and_biggielist( struct s_bkpinfo *bkpinfo )
    1307 {
    1308   struct s_node *filelist;
     1255s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo)
     1256{
     1257    struct s_node *filelist;
    13091258
    13101259  /** add mallocs**/
    1311   char *command;
    1312   char *tmp;
    1313   int res=0;
    1314   pid_t pid;
    1315 
    1316   assert(bkpinfo!=NULL);
    1317   malloc_string(command);
    1318   malloc_string(tmp);
    1319 
    1320   if ( does_file_exist( g_filelist_full ) && does_file_exist( g_biggielist_txt ) )
    1321     {
    1322       log_msg(1, "%s exists", g_filelist_full);
    1323       log_msg(1, "%s exists", g_biggielist_txt);
    1324       log_msg(2, "Filelist and biggielist already recovered from media. Yay!" );
    1325     }
    1326   else
    1327     {
    1328       getcwd( tmp, MAX_STR_LEN );
    1329       chdir( bkpinfo->tmpdir );
    1330       log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
    1331       log_to_screen( "Extracting filelist and biggielist from media..." );
    1332       unlink("/tmp/filelist.full");
    1333       unlink("/" FILELIST_FULL_STUB);
    1334       unlink("/tmp/i-want-my-lvm");
    1335       if ( IS_THIS_A_STREAMING_BACKUP( bkpinfo->backup_media_type ) )
    1336         {
    1337       sprintf( command,
    1338            "tar -zxf %s %s %s %s %s %s",
    1339            bkpinfo->media_device,
    1340            MOUNTLIST_FNAME_STUB,
    1341            BIGGIELIST_TXT_STUB,
    1342            FILELIST_FULL_STUB,
    1343            "tmp/i-want-my-lvm",
    1344            MONDO_CFG_FILE_STUB);
    1345           log_msg(1, "tarcommand = %s", command);
    1346           run_program_and_log_output( command, 1 );
    1347         }
    1348       else
    1349         {
    1350           log_msg(2,"Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
    1351       insist_on_this_cd_number( bkpinfo, 1 );
    1352           log_msg(2, "Back from iotcn");
    1353       run_program_and_log_output("mount", 1);
    1354           sprintf( command,
    1355            "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
    1356            MNT_CDROM,
    1357            MOUNTLIST_FNAME_STUB,
    1358            BIGGIELIST_TXT_STUB,
    1359            FILELIST_FULL_STUB,
    1360            "tmp/i-want-my-lvm",
    1361            MONDO_CFG_FILE_STUB);
    1362 
    1363           log_msg(1, "tarcommand = %s", command);
    1364       run_program_and_log_output(command, 1);
    1365 //    popup_and_OK("Press ENTER to continue");
    1366           if ( !does_file_exist( BIGGIELIST_TXT_STUB ) )
    1367             {
    1368           fatal_error( "all.tar.gz did not include tmp/biggielist.txt");
    1369         }
    1370           if ( !does_file_exist( FILELIST_FULL_STUB ) )
    1371             {
    1372           fatal_error( "all.tar.gz did not include tmp/filelist.full.gz");
    1373         }
    1374         }
    1375       sprintf( command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file );
    1376       run_program_and_log_output( command, FALSE );
    1377 
    1378       sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
    1379       log_msg(1, "command = %s", command);
    1380       paranoid_system(command);
    1381       sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
    1382       log_msg(1, "command = %s", command);
    1383       paranoid_system(command);
    1384     }
    1385 
    1386   if (am_I_in_disaster_recovery_mode() && ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
    1387     {
     1260    char *command;
     1261    char *tmp;
     1262    int res = 0;
     1263    pid_t pid;
     1264
     1265    assert(bkpinfo != NULL);
     1266    malloc_string(command);
     1267    malloc_string(tmp);
     1268
     1269    if (does_file_exist(g_filelist_full)
     1270        && does_file_exist(g_biggielist_txt)) {
     1271        log_msg(1, "%s exists", g_filelist_full);
     1272        log_msg(1, "%s exists", g_biggielist_txt);
     1273        log_msg(2,
     1274                "Filelist and biggielist already recovered from media. Yay!");
     1275    } else {
     1276        getcwd(tmp, MAX_STR_LEN);
     1277        chdir(bkpinfo->tmpdir);
     1278        log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
     1279        log_to_screen("Extracting filelist and biggielist from media...");
     1280        unlink("/tmp/filelist.full");
     1281        unlink("/" FILELIST_FULL_STUB);
     1282        unlink("/tmp/i-want-my-lvm");
     1283        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1284            sprintf(command,
     1285                    "tar -zxf %s %s %s %s %s %s",
     1286                    bkpinfo->media_device,
     1287                    MOUNTLIST_FNAME_STUB,
     1288                    BIGGIELIST_TXT_STUB,
     1289                    FILELIST_FULL_STUB,
     1290                    "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
     1291            log_msg(1, "tarcommand = %s", command);
     1292            run_program_and_log_output(command, 1);
     1293        } else {
     1294            log_msg(2,
     1295                    "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
     1296                    bkpinfo->isodir);
     1297            insist_on_this_cd_number(bkpinfo, 1);
     1298            log_msg(2, "Back from iotcn");
     1299            run_program_and_log_output("mount", 1);
     1300            sprintf(command,
     1301                    "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
     1302                    MNT_CDROM,
     1303                    MOUNTLIST_FNAME_STUB,
     1304                    BIGGIELIST_TXT_STUB,
     1305                    FILELIST_FULL_STUB,
     1306                    "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
     1307
     1308            log_msg(1, "tarcommand = %s", command);
     1309            run_program_and_log_output(command, 1);
     1310//    popup_and_OK("Press ENTER to continue");
     1311            if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
     1312                fatal_error
     1313                    ("all.tar.gz did not include tmp/biggielist.txt");
     1314            }
     1315            if (!does_file_exist(FILELIST_FULL_STUB)) {
     1316                fatal_error
     1317                    ("all.tar.gz did not include tmp/filelist.full.gz");
     1318            }
     1319        }
     1320        sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
     1321                g_mondo_cfg_file);
     1322        run_program_and_log_output(command, FALSE);
     1323
     1324        sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
     1325                BIGGIELIST_TXT_STUB, g_biggielist_txt);
     1326        log_msg(1, "command = %s", command);
     1327        paranoid_system(command);
     1328        sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
     1329                FILELIST_FULL_STUB, g_filelist_full);
     1330        log_msg(1, "command = %s", command);
     1331        paranoid_system(command);
     1332    }
     1333
     1334    if (am_I_in_disaster_recovery_mode()
     1335        &&
     1336        ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
     1337    {
    13881338//      sprintf(command, "cp -f tmp/mountlist.txt /tmp");
    1389       sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
    1390       paranoid_system(command);
    1391     }
    1392 
    1393   chdir( tmp );
    1394 
    1395   if (!does_file_exist( g_biggielist_txt) )
    1396     {
    1397       log_msg(1, "Warning - %s not found", g_biggielist_txt);
    1398     }
    1399   if (!does_file_exist(g_filelist_full) )
    1400     {
    1401       log_msg(1, "Warning - %s does not exist", g_filelist_full);
    1402     }
    1403 
     1339        sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
     1340                bkpinfo->tmpdir);
     1341        paranoid_system(command);
     1342    }
     1343
     1344    chdir(tmp);
     1345
     1346    if (!does_file_exist(g_biggielist_txt)) {
     1347        log_msg(1, "Warning - %s not found", g_biggielist_txt);
     1348    }
     1349    if (!does_file_exist(g_filelist_full)) {
     1350        log_msg(1, "Warning - %s does not exist", g_filelist_full);
     1351    }
    14041352//  popup_and_OK("Wonderful.");
    14051353
    1406   log_msg(2, "Forking" );
    1407   pid = fork();
    1408   switch( pid )
    1409     {
    1410     case -1:
    1411       fatal_error("Forking error");
    1412       break;
    1413 
    1414     case 0:
    1415       log_to_screen("Pre-processing filelist");
    1416       if (!does_file_exist(g_biggielist_txt))
    1417     {
    1418       sprintf(command,"> %s",g_biggielist_txt);
    1419       paranoid_system(command);
    1420     }
    1421       sprintf(command,"cat %s | grep  -x \"/dev/.*\" > %s", g_biggielist_txt, g_filelist_imagedevs);
    1422       paranoid_system(command);
    1423       exit( 0 );
    1424       break;
    1425 
    1426     default:
    1427       open_evalcall_form("Pre-processing filelist");
    1428       while( !waitpid( pid, (int*)0, WNOHANG ) )
    1429     {
    1430       usleep( 100000 );
    1431       update_evalcall_form( 0 );
    1432     }
    1433     }
    1434   close_evalcall_form();
    1435 
    1436   log_msg(3, "loading filelist");
    1437   filelist = load_filelist( g_filelist_full );
    1438   log_msg(3, "deleting original filelist");
    1439   unlink(g_filelist_full);
    1440   if (g_text_mode)
    1441     {
    1442       printf("Restore which directory? --> ");
    1443       fgets(tmp, sizeof(tmp), stdin);
    1444       toggle_path_selection (filelist, tmp, TRUE);
    1445       if (strlen(tmp)==0) { res=1; } else { res=0; }
    1446     }
    1447   else
    1448     {
    1449       res = edit_filelist( filelist );
    1450     }
    1451   if (res)
    1452     {
    1453       log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
    1454       free_filelist( filelist );
    1455       return( NULL );
    1456     }
    1457   ask_about_these_imagedevs( g_filelist_imagedevs, g_imagedevs_restthese );
    1458   close_evalcall_form();
    1459 
    1460   // NB: It's not necessary to add g_biggielist_txt to the filelist.full
    1461   // file. The filelist.full file already contains the filename of EVERY
    1462   // file backed up - regular and biggie files.
    1463 
    1464   // However, we do want to make sure the imagedevs selected by the user
    1465   // are flagged for restoring.
    1466   if ( length_of_file( g_imagedevs_restthese ) > 2 )
    1467     { add_list_of_files_to_filelist(filelist, g_imagedevs_restthese, TRUE); }
    1468 
    1469   paranoid_free(command);
    1470   paranoid_free(tmp);
    1471   return( filelist );
    1472 }
     1354    log_msg(2, "Forking");
     1355    pid = fork();
     1356    switch (pid) {
     1357    case -1:
     1358        fatal_error("Forking error");
     1359        break;
     1360
     1361    case 0:
     1362        log_to_screen("Pre-processing filelist");
     1363        if (!does_file_exist(g_biggielist_txt)) {
     1364            sprintf(command, "> %s", g_biggielist_txt);
     1365            paranoid_system(command);
     1366        }
     1367        sprintf(command, "cat %s | grep  -x \"/dev/.*\" > %s",
     1368                g_biggielist_txt, g_filelist_imagedevs);
     1369        paranoid_system(command);
     1370        exit(0);
     1371        break;
     1372
     1373    default:
     1374        open_evalcall_form("Pre-processing filelist");
     1375        while (!waitpid(pid, (int *) 0, WNOHANG)) {
     1376            usleep(100000);
     1377            update_evalcall_form(0);
     1378        }
     1379    }
     1380    close_evalcall_form();
     1381
     1382    log_msg(3, "loading filelist");
     1383    filelist = load_filelist(g_filelist_full);
     1384    log_msg(3, "deleting original filelist");
     1385    unlink(g_filelist_full);
     1386    if (g_text_mode) {
     1387        printf("Restore which directory? --> ");
     1388        fgets(tmp, sizeof(tmp), stdin);
     1389        toggle_path_selection(filelist, tmp, TRUE);
     1390        if (strlen(tmp) == 0) {
     1391            res = 1;
     1392        } else {
     1393            res = 0;
     1394        }
     1395    } else {
     1396        res = edit_filelist(filelist);
     1397    }
     1398    if (res) {
     1399        log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
     1400        free_filelist(filelist);
     1401        return (NULL);
     1402    }
     1403    ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
     1404    close_evalcall_form();
     1405
     1406    // NB: It's not necessary to add g_biggielist_txt to the filelist.full
     1407    // file. The filelist.full file already contains the filename of EVERY
     1408    // file backed up - regular and biggie files.
     1409
     1410    // However, we do want to make sure the imagedevs selected by the user
     1411    // are flagged for restoring.
     1412    if (length_of_file(g_imagedevs_restthese) > 2) {
     1413        add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
     1414                                      TRUE);
     1415    }
     1416
     1417    paranoid_free(command);
     1418    paranoid_free(tmp);
     1419    return (filelist);
     1420}
     1421
    14731422/**************************************************************************
    14741423 *END_ PROCESS_FILELIST_AND_BIGGIELIST                                    *
     
    14851434 * @return 0 for success, nonzero for failure.
    14861435 */
    1487 int backup_crucial_file(char *path_root, char*filename)
    1488 {
    1489   char *tmp;
    1490   char *command;
    1491   int res;
    1492  
    1493   malloc_string(tmp);
    1494   malloc_string(command);
    1495   assert(path_root!=NULL);
    1496   assert_string_is_neither_NULL_nor_zerolength(filename);
    1497 
    1498   sprintf(tmp, "%s/%s", path_root, filename);
    1499   sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
    1500  
    1501   res = run_program_and_log_output(command, 5);
    1502   paranoid_free(tmp);
    1503   paranoid_free(command);
    1504   return(res);
     1436int backup_crucial_file(char *path_root, char *filename)
     1437{
     1438    char *tmp;
     1439    char *command;
     1440    int res;
     1441
     1442    malloc_string(tmp);
     1443    malloc_string(command);
     1444    assert(path_root != NULL);
     1445    assert_string_is_neither_NULL_nor_zerolength(filename);
     1446
     1447    sprintf(tmp, "%s/%s", path_root, filename);
     1448    sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
     1449
     1450    res = run_program_and_log_output(command, 5);
     1451    paranoid_free(tmp);
     1452    paranoid_free(command);
     1453    return (res);
    15051454}
    15061455
     
    15121461 * @return 0 for success, nonzero for failure.
    15131462 */
    1514 int
    1515 run_boot_loader(bool offer_to_hack_scripts)
    1516 {
    1517   int res;
    1518   int retval = 0;
     1463int run_boot_loader(bool offer_to_hack_scripts)
     1464{
     1465    int res;
     1466    int retval = 0;
    15191467
    15201468  /** malloc *******/
    1521   char *device;
    1522   char *tmp;
    1523   char *name;
    1524 
    1525   malloc_string(device);
    1526   malloc_string(tmp);
    1527   malloc_string(name);
    1528   backup_crucial_file( MNT_RESTORING, "/etc/fstab");
    1529   backup_crucial_file( MNT_RESTORING, "/etc/grub.conf");
    1530   backup_crucial_file( MNT_RESTORING, "/etc/lilo.conf");
    1531   backup_crucial_file( MNT_RESTORING, "/etc/elilo.conf");
    1532   read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
    1533   read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
    1534   sprintf(tmp,"run_boot_loader: device='%s', name='%s'",device,name);
    1535   log_msg(2, tmp);
    1536   system("sync");
    1537   if (!strcmp(name,"LILO"))
    1538     {
    1539       res = run_lilo(offer_to_hack_scripts);
    1540     }
    1541   else if (!strcmp(name,"ELILO"))
    1542     {
    1543       res = run_elilo(offer_to_hack_scripts);
    1544     }
    1545   else if (!strcmp(name,"GRUB"))
    1546     {
     1469    char *device;
     1470    char *tmp;
     1471    char *name;
     1472
     1473    malloc_string(device);
     1474    malloc_string(tmp);
     1475    malloc_string(name);
     1476    backup_crucial_file(MNT_RESTORING, "/etc/fstab");
     1477    backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
     1478    backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
     1479    backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
     1480    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
     1481    read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
     1482    sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
     1483    log_msg(2, tmp);
     1484    system("sync");
     1485    if (!strcmp(name, "LILO")) {
     1486        res = run_lilo(offer_to_hack_scripts);
     1487    } else if (!strcmp(name, "ELILO")) {
     1488        res = run_elilo(offer_to_hack_scripts);
     1489    } else if (!strcmp(name, "GRUB")) {
    15471490//      if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?")))
    15481491//        {
    1549       res = run_grub(offer_to_hack_scripts, device);
    1550 //    unlink(DO_MBR_PLEASE);
    1551 //  }
     1492        res = run_grub(offer_to_hack_scripts, device);
     1493//    unlink(DO_MBR_PLEASE);
     1494//  }
    15521495//      else
    15531496//        {
    1554 //    log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
    1555 //    res = 1;
    1556 //  }
    1557     }
    1558   else if (!strcmp(name,"RAW"))
    1559     {
    1560       res = run_raw_mbr(offer_to_hack_scripts, device);
    1561     }
     1497//    log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
     1498//    res = 1;
     1499//  }
     1500    } else if (!strcmp(name, "RAW")) {
     1501        res = run_raw_mbr(offer_to_hack_scripts, device);
     1502    }
    15621503#ifdef __FreeBSD__
    1563   else if (!strcmp(name,"BOOT0"))
    1564       {
    1565       sprintf (tmp, "boot0cfg -B %s", device);
    1566       res = run_program_and_log_output (tmp, FALSE);
    1567       } else {
    1568       sprintf (tmp, "ls /dev | grep -xq %ss[1-4].*", device);
    1569       if (!system (tmp)) {
    1570           sprintf (tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
    1571           res = run_program_and_log_output (tmp, 3);
    1572       } else {
    1573           log_msg (1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
    1574       }
    1575       }
     1504    else if (!strcmp(name, "BOOT0")) {
     1505        sprintf(tmp, "boot0cfg -B %s", device);
     1506        res = run_program_and_log_output(tmp, FALSE);
     1507    } else {
     1508        sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device);
     1509        if (!system(tmp)) {
     1510            sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
     1511            res = run_program_and_log_output(tmp, 3);
     1512        } else {
     1513            log_msg(1,
     1514                    "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
     1515        }
     1516    }
    15761517#else
    1577   else
    1578     {
    1579       log_to_screen("Unable to determine type of boot loader. Defaulting to LILO.");
    1580       res=run_lilo(offer_to_hack_scripts);
    1581     }
     1518    else {
     1519        log_to_screen
     1520            ("Unable to determine type of boot loader. Defaulting to LILO.");
     1521        res = run_lilo(offer_to_hack_scripts);
     1522    }
    15821523#endif
    1583   retval += res;
    1584   if (res)
    1585     {
    1586       log_to_screen("Your boot loader returned an error");
    1587     }
    1588   else
    1589     {
    1590       log_to_screen("Your boot loader ran OK");
    1591     }
    1592   paranoid_free(device);
    1593   paranoid_free(tmp);
    1594   paranoid_free(name);
    1595   return(retval);
    1596 }
     1524    retval += res;
     1525    if (res) {
     1526        log_to_screen("Your boot loader returned an error");
     1527    } else {
     1528        log_to_screen("Your boot loader ran OK");
     1529    }
     1530    paranoid_free(device);
     1531    paranoid_free(tmp);
     1532    paranoid_free(name);
     1533    return (retval);
     1534}
     1535
    15971536/**************************************************************************
    15981537 *END_ RUN_BOOT_LOADER                                                    *
     
    16081547char *find_my_editor(void)
    16091548{
    1610   static char output[MAX_STR_LEN];
    1611   if (find_home_of_exe("pico"))
    1612     { strcpy(output, "pico"); }
    1613   else if (find_home_of_exe("nano"))
    1614     { strcpy(output, "nano"); }
    1615   else if (find_home_of_exe ("e3em"))
    1616       {
    1617       strcpy (output, "e3em");
    1618       }
    1619   else if (find_home_of_exe ("e3vi"))
    1620       {
    1621       strcpy (output, "e3vi");
    1622       }
    1623   else
    1624     { strcpy(output, "vi"); }
    1625   if (!find_home_of_exe(output))
    1626     { log_msg(2, " (find_my_editor) --- warning - %s not found", output); }
    1627   return(output);
     1549    static char output[MAX_STR_LEN];
     1550    if (find_home_of_exe("pico")) {
     1551        strcpy(output, "pico");
     1552    } else if (find_home_of_exe("nano")) {
     1553        strcpy(output, "nano");
     1554    } else if (find_home_of_exe("e3em")) {
     1555        strcpy(output, "e3em");
     1556    } else if (find_home_of_exe("e3vi")) {
     1557        strcpy(output, "e3vi");
     1558    } else {
     1559        strcpy(output, "vi");
     1560    }
     1561    if (!find_home_of_exe(output)) {
     1562        log_msg(2, " (find_my_editor) --- warning - %s not found", output);
     1563    }
     1564    return (output);
    16281565}
    16291566
     
    16351572 * @return 0 for success, nonzero for failure.
    16361573 */
    1637 int
    1638 run_grub(bool offer_to_run_stabgrub, char*bd)
     1574int run_grub(bool offer_to_run_stabgrub, char *bd)
    16391575{
    16401576  /** malloc **/
    1641   char *command;
    1642   char *boot_device;
    1643   char *rootdev;
    1644   char *rootdrive;
    1645   char *conffile;
    1646   char *tmp;
    1647   char *editor;
    1648 
    1649   int res;
    1650   int done;
    1651 
    1652   malloc_string(command);
    1653   malloc_string(boot_device);
    1654   malloc_string(tmp);
    1655   malloc_string(editor);
    1656   malloc_string(rootdev);
    1657   malloc_string(rootdrive);
    1658   malloc_string(conffile);
    1659   assert_string_is_neither_NULL_nor_zerolength(bd);
    1660   strcpy( editor, "vi" ); // find_my_editor() );
    1661   strcpy( boot_device, bd);
    1662  
    1663   if (!run_program_and_log_output("which grub-MR", FALSE))
    1664     {
    1665       log_msg(1, "Yay! grub-MR found...");
    1666       sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
    1667       log_msg(1, "command = %s", command);
    1668     }
    1669   else
    1670     {
    1671       sprintf(command, "chroot " MNT_RESTORING " grub-install %s",boot_device);
    1672       log_msg(1, "WARNING - grub-MR not found; using grub-install");
    1673     }
    1674   if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist?"))
    1675     /* interactive mode */
    1676     {
    1677       mvaddstr_and_log_it(g_currentY,
    1678               0,
    1679               "Modifying fstab and grub.conf, and running GRUB...                             ");
    1680       for(done = FALSE; !done; )
     1577    char *command;
     1578    char *boot_device;
     1579    char *rootdev;
     1580    char *rootdrive;
     1581    char *conffile;
     1582    char *tmp;
     1583    char *editor;
     1584
     1585    int res;
     1586    int done;
     1587
     1588    malloc_string(command);
     1589    malloc_string(boot_device);
     1590    malloc_string(tmp);
     1591    malloc_string(editor);
     1592    malloc_string(rootdev);
     1593    malloc_string(rootdrive);
     1594    malloc_string(conffile);
     1595    assert_string_is_neither_NULL_nor_zerolength(bd);
     1596    strcpy(editor, "vi");       // find_my_editor() );
     1597    strcpy(boot_device, bd);
     1598
     1599    if (!run_program_and_log_output("which grub-MR", FALSE)) {
     1600        log_msg(1, "Yay! grub-MR found...");
     1601        sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
     1602        log_msg(1, "command = %s", command);
     1603    } else {
     1604        sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
     1605                boot_device);
     1606        log_msg(1, "WARNING - grub-MR not found; using grub-install");
     1607    }
     1608    if (offer_to_run_stabgrub
     1609        && ask_me_yes_or_no("Did you change the mountlist?"))
     1610        /* interactive mode */
    16811611    {
    1682       popup_and_get_string("Boot device",
    1683                    "Please confirm/enter the boot device. If in doubt, try /dev/hda",
    1684                    boot_device, MAX_STR_LEN/4);
    1685       sprintf(command, "stabgrub-me %s", boot_device);
    1686       res = run_program_and_log_output(command, 1);
    1687       if (res)
    1688         {
    1689           popup_and_OK("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
    1690           newtSuspend();
    1691           system("chroot " MNT_RESTORING);
    1692           newtResume();
    1693           popup_and_OK("Thank you.");
    1694         }
    1695       else
    1696         {
    1697           done = TRUE;
    1698         }
    1699       popup_and_OK("You will now edit fstab and grub.conf");
    1700       if (!g_text_mode) { newtSuspend(); }
    1701       sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1702       paranoid_system(tmp);
    1703       sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
    1704       paranoid_system(tmp);
    1705       if (!g_text_mode) { newtResume(); }
    1706     }
    1707     }
    1708   else
    1709 
    1710     /* nuke mode */
    1711     {
    1712       mvaddstr_and_log_it(g_currentY,
    1713               0,
    1714               "Running GRUB...                                                 ");
    1715       iamhere(command);
    1716       res = run_program_and_log_output(command, 1);
    1717       if (res)
     1612        mvaddstr_and_log_it(g_currentY,
     1613                            0,
     1614                            "Modifying fstab and grub.conf, and running GRUB...                             ");
     1615        for (done = FALSE; !done;) {
     1616            popup_and_get_string("Boot device",
     1617                                 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
     1618                                 boot_device, MAX_STR_LEN / 4);
     1619            sprintf(command, "stabgrub-me %s", boot_device);
     1620            res = run_program_and_log_output(command, 1);
     1621            if (res) {
     1622                popup_and_OK
     1623                    ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
     1624                newtSuspend();
     1625                system("chroot " MNT_RESTORING);
     1626                newtResume();
     1627                popup_and_OK("Thank you.");
     1628            } else {
     1629                done = TRUE;
     1630            }
     1631            popup_and_OK("You will now edit fstab and grub.conf");
     1632            if (!g_text_mode) {
     1633                newtSuspend();
     1634            }
     1635            sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1636            paranoid_system(tmp);
     1637            sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
     1638            paranoid_system(tmp);
     1639            if (!g_text_mode) {
     1640                newtResume();
     1641            }
     1642        }
     1643    } else
     1644        /* nuke mode */
    17181645    {
    1719       popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
    1720       newtSuspend();
    1721       system("chroot " MNT_RESTORING);
    1722       newtResume();
    1723       popup_and_OK("Thank you.");
    1724     }
    1725     }
    1726   if (res)
    1727     {
    1728       mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1729       log_to_screen("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.");
    1730       log_msg(1,"Type:-");
    1731       log_msg(1,"    mount-me");
    1732       log_msg(1,"    chroot " MNT_RESTORING);
    1733       log_msg(1,"    mount /boot");
    1734       log_msg(1,"    grub-install '(hd0)'");
    1735       log_msg(1,"    exit");
    1736       log_msg(1,"    unmount-me");
    1737       log_msg(1,"If you're really stuck, please e-mail the mailing list.");
    1738     }
    1739   else
    1740     {
    1741       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    1742     }
    1743   paranoid_free(rootdev);
    1744   paranoid_free(rootdrive);
    1745   paranoid_free(conffile);
    1746   paranoid_free(command);
    1747   paranoid_free(boot_device);
    1748   paranoid_free(tmp);
    1749   paranoid_free(editor);
    1750 
    1751   return( res );
    1752 }
     1646        mvaddstr_and_log_it(g_currentY,
     1647                            0,
     1648                            "Running GRUB...                                                 ");
     1649        iamhere(command);
     1650        res = run_program_and_log_output(command, 1);
     1651        if (res) {
     1652            popup_and_OK
     1653                ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
     1654            newtSuspend();
     1655            system("chroot " MNT_RESTORING);
     1656            newtResume();
     1657            popup_and_OK("Thank you.");
     1658        }
     1659    }
     1660    if (res) {
     1661        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1662        log_to_screen
     1663            ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.");
     1664        log_msg(1, "Type:-");
     1665        log_msg(1, "    mount-me");
     1666        log_msg(1, "    chroot " MNT_RESTORING);
     1667        log_msg(1, "    mount /boot");
     1668        log_msg(1, "    grub-install '(hd0)'");
     1669        log_msg(1, "    exit");
     1670        log_msg(1, "    unmount-me");
     1671        log_msg(1,
     1672                "If you're really stuck, please e-mail the mailing list.");
     1673    } else {
     1674        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1675    }
     1676    paranoid_free(rootdev);
     1677    paranoid_free(rootdrive);
     1678    paranoid_free(conffile);
     1679    paranoid_free(command);
     1680    paranoid_free(boot_device);
     1681    paranoid_free(tmp);
     1682    paranoid_free(editor);
     1683
     1684    return (res);
     1685}
     1686
    17531687/**************************************************************************
    17541688 *END_RUN_GRUB                                                            *
     
    17611695 * @return 0 for success, nonzero for failure.
    17621696 */
    1763 int
    1764 run_elilo(bool offer_to_run_stabelilo)
     1697int run_elilo(bool offer_to_run_stabelilo)
    17651698{
    17661699  /** malloc **/
    1767   char *command;
    1768   char *tmp;
    1769   char *editor;
    1770 
    1771   int res;
    1772   int done;
    1773 
    1774   malloc_string(command);
    1775   malloc_string(tmp);
    1776   malloc_string(editor);
    1777   strcpy(editor, find_my_editor());
    1778   if (offer_to_run_stabelilo && ask_me_yes_or_no("Did you change the mountlist?"))
    1779 
    1780     /* interactive mode */
    1781     {
    1782       mvaddstr_and_log_it(g_currentY,
    1783               0,
    1784               "Modifying fstab and elilo.conf...                             ");
    1785       sprintf(command,"stabelilo-me");
    1786       res = run_program_and_log_output(command, 3);
    1787       if (res)
    1788         {
    1789           popup_and_OK("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
    1790           for(done = FALSE; !done;)
    1791             {
    1792               if (!g_text_mode) { newtSuspend(); }
    1793           sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1794           paranoid_system(tmp);
    1795           sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor);
    1796           paranoid_system(tmp);
    1797               if (!g_text_mode) { newtResume(); }
     1700    char *command;
     1701    char *tmp;
     1702    char *editor;
     1703
     1704    int res;
     1705    int done;
     1706
     1707    malloc_string(command);
     1708    malloc_string(tmp);
     1709    malloc_string(editor);
     1710    strcpy(editor, find_my_editor());
     1711    if (offer_to_run_stabelilo
     1712        && ask_me_yes_or_no("Did you change the mountlist?"))
     1713
     1714        /* interactive mode */
     1715    {
     1716        mvaddstr_and_log_it(g_currentY,
     1717                            0,
     1718                            "Modifying fstab and elilo.conf...                             ");
     1719        sprintf(command, "stabelilo-me");
     1720        res = run_program_and_log_output(command, 3);
     1721        if (res) {
     1722            popup_and_OK
     1723                ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
     1724            for (done = FALSE; !done;) {
     1725                if (!g_text_mode) {
     1726                    newtSuspend();
     1727                }
     1728                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1729                paranoid_system(tmp);
     1730                sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
     1731                        editor);
     1732                paranoid_system(tmp);
     1733                if (!g_text_mode) {
     1734                    newtResume();
     1735                }
    17981736//              newtCls();
    1799               if (ask_me_yes_or_no("Edit them again?"))
    1800         {
    1801           continue;
    1802         }
    1803           done = TRUE;
    1804             }
    1805     }
    1806       else
     1737                if (ask_me_yes_or_no("Edit them again?")) {
     1738                    continue;
     1739                }
     1740                done = TRUE;
     1741            }
     1742        } else {
     1743            log_to_screen("elilo.conf and fstab were modified OK");
     1744        }
     1745    } else
     1746        /* nuke mode */
    18071747    {
    1808       log_to_screen("elilo.conf and fstab were modified OK");
    1809     }
    1810     }
    1811   else
    1812 
    1813     /* nuke mode */
    1814     {
    1815     res = TRUE;
    1816     }
    1817   paranoid_free(command);
    1818   paranoid_free(tmp);
    1819   paranoid_free(editor);
    1820   return(res);
    1821 }
     1748        res = TRUE;
     1749    }
     1750    paranoid_free(command);
     1751    paranoid_free(tmp);
     1752    paranoid_free(editor);
     1753    return (res);
     1754}
     1755
    18221756/**************************************************************************
    18231757 *END_RUN_ELILO                                                            *
     
    18301764 * @return 0 for success, nonzero for failure.
    18311765 */
    1832 int
    1833 run_lilo(bool offer_to_run_stablilo)
     1766int run_lilo(bool offer_to_run_stablilo)
    18341767{
    18351768  /** malloc **/
    1836   char *command;
    1837   char *tmp;
    1838   char *editor;
    1839 
    1840   int res;
    1841   int done;
    1842   bool run_lilo_M = FALSE;
    1843   malloc_string(command);
    1844   malloc_string(tmp);
    1845   malloc_string(editor);
    1846 
    1847   if (!run_program_and_log_output("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1))
    1848         { run_lilo_M = TRUE; }
    1849 
    1850   strcpy(editor, find_my_editor());
    1851   if (offer_to_run_stablilo && ask_me_yes_or_no("Did you change the mountlist?"))
    1852 
    1853     /* interactive mode */
    1854     {
    1855       mvaddstr_and_log_it(g_currentY,
    1856               0,
    1857               "Modifying fstab and lilo.conf, and running LILO...                             ");
    1858       sprintf(command,"stablilo-me");
    1859       res = run_program_and_log_output(command, 3);
    1860       if (res)
    1861         {
    1862           popup_and_OK("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
    1863           for(done = FALSE; !done;)
    1864             {
    1865               if (!g_text_mode) { newtSuspend(); }
    1866           sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1867           paranoid_system(tmp);
    1868           sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
    1869           paranoid_system(tmp);
    1870               if (!g_text_mode) { newtResume(); }
     1769    char *command;
     1770    char *tmp;
     1771    char *editor;
     1772
     1773    int res;
     1774    int done;
     1775    bool run_lilo_M = FALSE;
     1776    malloc_string(command);
     1777    malloc_string(tmp);
     1778    malloc_string(editor);
     1779
     1780    if (!run_program_and_log_output
     1781        ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
     1782        run_lilo_M = TRUE;
     1783    }
     1784
     1785    strcpy(editor, find_my_editor());
     1786    if (offer_to_run_stablilo
     1787        && ask_me_yes_or_no("Did you change the mountlist?"))
     1788
     1789        /* interactive mode */
     1790    {
     1791        mvaddstr_and_log_it(g_currentY,
     1792                            0,
     1793                            "Modifying fstab and lilo.conf, and running LILO...                             ");
     1794        sprintf(command, "stablilo-me");
     1795        res = run_program_and_log_output(command, 3);
     1796        if (res) {
     1797            popup_and_OK
     1798                ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
     1799            for (done = FALSE; !done;) {
     1800                if (!g_text_mode) {
     1801                    newtSuspend();
     1802                }
     1803                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1804                paranoid_system(tmp);
     1805                sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
     1806                paranoid_system(tmp);
     1807                if (!g_text_mode) {
     1808                    newtResume();
     1809                }
    18711810//              newtCls();
    1872               if (ask_me_yes_or_no("Edit them again?"))
    1873         {
    1874           continue;
    1875         }
    1876               res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
    1877               if (res)
    1878         {
    1879           res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
    1880         }
    1881               if (res)
    1882                 {
    1883                   done = ask_me_yes_or_no("LILO failed. Re-edit system files?");
    1884                 }
    1885               else
    1886             {
    1887               done = TRUE;
    1888             }
    1889             }
    1890     }
    1891       else
     1811                if (ask_me_yes_or_no("Edit them again?")) {
     1812                    continue;
     1813                }
     1814                res =
     1815                    run_program_and_log_output("chroot " MNT_RESTORING
     1816                                               " lilo -L", 3);
     1817                if (res) {
     1818                    res =
     1819                        run_program_and_log_output("chroot " MNT_RESTORING
     1820                                                   " lilo", 3);
     1821                }
     1822                if (res) {
     1823                    done =
     1824                        ask_me_yes_or_no
     1825                        ("LILO failed. Re-edit system files?");
     1826                } else {
     1827                    done = TRUE;
     1828                }
     1829            }
     1830        } else {
     1831            log_to_screen("lilo.conf and fstab were modified OK");
     1832        }
     1833    } else
     1834        /* nuke mode */
    18921835    {
    1893       log_to_screen("lilo.conf and fstab were modified OK");
    1894     }
    1895     }
    1896   else
    1897 
    1898     /* nuke mode */
    1899     {
    1900       mvaddstr_and_log_it(g_currentY,
    1901               0,
    1902               "Running LILO...                                                 ");
    1903       res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
    1904       if (res)
    1905     {
    1906       res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
    1907     }
    1908       if (res)
    1909         {
    1910           mvaddstr_and_log_it(g_currentY++,74,"Failed.");
    1911           log_to_screen("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
    1912         }
    1913       else
    1914     { 
    1915           mvaddstr_and_log_it(g_currentY++,74,"Done.");
    1916         }
    1917     }
    1918   if (run_lilo_M)
    1919     {
    1920       run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/hda", 3);
    1921       run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/sda", 3);
    1922     }
    1923   paranoid_free(command);
    1924   paranoid_free(tmp);
    1925   paranoid_free(editor);
    1926   return(res);
    1927 }
     1836        mvaddstr_and_log_it(g_currentY,
     1837                            0,
     1838                            "Running LILO...                                                 ");
     1839        res =
     1840            run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
     1841                                       3);
     1842        if (res) {
     1843            res =
     1844                run_program_and_log_output("chroot " MNT_RESTORING " lilo",
     1845                                           3);
     1846        }
     1847        if (res) {
     1848            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1849            log_to_screen
     1850                ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
     1851        } else {
     1852            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1853        }
     1854    }
     1855    if (run_lilo_M) {
     1856        run_program_and_log_output("chroot " MNT_RESTORING
     1857                                   " lilo -M /dev/hda", 3);
     1858        run_program_and_log_output("chroot " MNT_RESTORING
     1859                                   " lilo -M /dev/sda", 3);
     1860    }
     1861    paranoid_free(command);
     1862    paranoid_free(tmp);
     1863    paranoid_free(editor);
     1864    return (res);
     1865}
     1866
    19281867/**************************************************************************
    19291868 *END_RUN_LILO                                                            *
     
    19371876 * @return 0 for success, nonzero for failure.
    19381877 */
    1939 int
    1940 run_raw_mbr(bool offer_to_hack_scripts, char *bd)
     1878int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
    19411879{
    19421880  /** malloc **/
    1943   char *command;
    1944   char *boot_device;
    1945   char *tmp;
    1946   char *editor;
    1947   int res;
    1948   int done;
    1949 
    1950   malloc_string(command);
    1951   malloc_string(boot_device);
    1952   malloc_string(tmp);
    1953   malloc_string(editor);
    1954   assert_string_is_neither_NULL_nor_zerolength(bd);
    1955 
    1956   strcpy( editor, find_my_editor() );
    1957   strcpy( boot_device, bd );
    1958   sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
    1959   log_msg(2, "run_raw_mbr() --- command='%s'", command);
    1960 
    1961   if (offer_to_hack_scripts && ask_me_yes_or_no("Did you change the mountlist?"))
    1962     /* interactive mode */
    1963     {
    1964       mvaddstr_and_log_it(g_currentY,0,"Modifying fstab and restoring MBR...                           ");
    1965       for(done=FALSE; !done; )
     1881    char *command;
     1882    char *boot_device;
     1883    char *tmp;
     1884    char *editor;
     1885    int res;
     1886    int done;
     1887
     1888    malloc_string(command);
     1889    malloc_string(boot_device);
     1890    malloc_string(tmp);
     1891    malloc_string(editor);
     1892    assert_string_is_neither_NULL_nor_zerolength(bd);
     1893
     1894    strcpy(editor, find_my_editor());
     1895    strcpy(boot_device, bd);
     1896    sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
     1897    log_msg(2, "run_raw_mbr() --- command='%s'", command);
     1898
     1899    if (offer_to_hack_scripts
     1900        && ask_me_yes_or_no("Did you change the mountlist?"))
     1901        /* interactive mode */
    19661902    {
    1967       if (!run_program_and_log_output("which vi", FALSE))
    1968         {
    1969           popup_and_OK("You will now edit fstab");
    1970           if (!g_text_mode) { newtSuspend(); }
    1971           sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    1972           paranoid_system(tmp);
    1973           if (!g_text_mode) { newtResume(); }
     1903        mvaddstr_and_log_it(g_currentY, 0,
     1904                            "Modifying fstab and restoring MBR...                           ");
     1905        for (done = FALSE; !done;) {
     1906            if (!run_program_and_log_output("which vi", FALSE)) {
     1907                popup_and_OK("You will now edit fstab");
     1908                if (!g_text_mode) {
     1909                    newtSuspend();
     1910                }
     1911                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1912                paranoid_system(tmp);
     1913                if (!g_text_mode) {
     1914                    newtResume();
     1915                }
    19741916//              newtCls();
    1975         }
    1976       popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda",boot_device, MAX_STR_LEN/4);
    1977       sprintf(command, "stabraw-me %s", boot_device);
    1978       res = run_program_and_log_output(command, 3);
    1979       if (res)
    1980         {
    1981           done = ask_me_yes_or_no("Modifications failed. Re-try?");
    1982         }
    1983       else
    1984         {
    1985           done = TRUE;
    1986         }
    1987     }
    1988     }
    1989   else
    1990    
    1991     /* nuke mode */
    1992     {
    1993       mvaddstr_and_log_it(g_currentY,0,"Restoring MBR...                                               ");
    1994       res = run_program_and_log_output(command, 3);
    1995     }
    1996   if (res)
    1997     {
    1998       mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    1999       log_to_screen("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.");
    2000     }
    2001   else
    2002     {
    2003       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2004     }
    2005   paranoid_free(command);
    2006   paranoid_free(boot_device);
    2007   paranoid_free(tmp);
    2008   paranoid_free(editor);
    2009   return(res);
    2010 }
     1917            }
     1918            popup_and_get_string("Boot device",
     1919                                 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
     1920                                 boot_device, MAX_STR_LEN / 4);
     1921            sprintf(command, "stabraw-me %s", boot_device);
     1922            res = run_program_and_log_output(command, 3);
     1923            if (res) {
     1924                done = ask_me_yes_or_no("Modifications failed. Re-try?");
     1925            } else {
     1926                done = TRUE;
     1927            }
     1928        }
     1929    } else
     1930        /* nuke mode */
     1931    {
     1932        mvaddstr_and_log_it(g_currentY, 0,
     1933                            "Restoring MBR...                                               ");
     1934        res = run_program_and_log_output(command, 3);
     1935    }
     1936    if (res) {
     1937        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1938        log_to_screen
     1939            ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.");
     1940    } else {
     1941        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1942    }
     1943    paranoid_free(command);
     1944    paranoid_free(boot_device);
     1945    paranoid_free(tmp);
     1946    paranoid_free(editor);
     1947    return (res);
     1948}
     1949
    20111950/**************************************************************************
    20121951 *END_RUN_RAW_MBR                                                         *
     
    20151954
    20161955
    2017  
    2018  
     1956
     1957
    20191958/**
    20201959 * Turn signal trapping on or off.
     
    20221961 * print a message and exit immediately.
    20231962 */
    2024 void
    2025 set_signals( int on )
    2026 {
    2027   int signals[]= { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGSTOP, 0 };
    2028   int i;
    2029   for ( i = 0; signals[i]; i++)
    2030     {
    2031       if (on)
    2032         {
    2033       signal( signals[i], terminate_daemon);
    2034     }
    2035       else
    2036         {
    2037       signal(signals[i], termination_in_progress);
    2038     }
    2039     }
     1963void set_signals(int on)
     1964{
     1965    int signals[] =
     1966        { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT,
     1967SIGSTOP, 0 };
     1968    int i;
     1969    for (i = 0; signals[i]; i++) {
     1970        if (on) {
     1971            signal(signals[i], terminate_daemon);
     1972        } else {
     1973            signal(signals[i], termination_in_progress);
     1974        }
     1975    }
    20401976}
    20411977
     
    20511987 * - @c bkpinfo->disaster_recovery
    20521988 */
    2053 void
    2054 setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
    2055 {
    2056   char *temppath;
    2057 
    2058   assert(bkpinfo!=NULL);
    2059 
    2060   malloc_string ( g_biggielist_txt );
    2061   malloc_string ( g_filelist_full );
    2062   malloc_string ( g_filelist_imagedevs );
    2063   malloc_string ( g_imagedevs_restthese );
    2064   malloc_string ( g_mondo_cfg_file );
    2065   malloc_string ( g_mountlist_fname );
    2066   malloc_string ( g_mondo_home );
    2067   malloc_string ( g_tmpfs_mountpt );
    2068   malloc_string ( g_isodir_device );
    2069   malloc_string ( g_isodir_format );
    2070 
    2071   temppath = bkpinfo->tmpdir;
    2072 
    2073   sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
    2074   sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
    2075   sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
     1989void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
     1990{
     1991    char *temppath;
     1992
     1993    assert(bkpinfo != NULL);
     1994
     1995    malloc_string(g_biggielist_txt);
     1996    malloc_string(g_filelist_full);
     1997    malloc_string(g_filelist_imagedevs);
     1998    malloc_string(g_imagedevs_restthese);
     1999    malloc_string(g_mondo_cfg_file);
     2000    malloc_string(g_mountlist_fname);
     2001    malloc_string(g_mondo_home);
     2002    malloc_string(g_tmpfs_mountpt);
     2003    malloc_string(g_isodir_device);
     2004    malloc_string(g_isodir_format);
     2005
     2006    temppath = bkpinfo->tmpdir;
     2007
     2008    sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
     2009    sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
     2010    sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
    20762011//  sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
    2077   sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", temppath);
    2078   if (bkpinfo->disaster_recovery)
    2079     {
    2080       sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
    2081       sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
    2082     }
    2083   else
    2084     {
    2085       sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
    2086       sprintf(g_mountlist_fname, "%s/%s", temppath, MOUNTLIST_FNAME_STUB);
    2087     }
    2088 }
     2012    sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
     2013            temppath);
     2014    if (bkpinfo->disaster_recovery) {
     2015        sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
     2016        sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
     2017    } else {
     2018        sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
     2019        sprintf(g_mountlist_fname, "%s/%s", temppath,
     2020                MOUNTLIST_FNAME_STUB);
     2021    }
     2022}
     2023
    20892024/**************************************************************************
    20902025 *END_SET_GLOBAL_FILENAME                                                 *
     
    20982033 * @param input_file The input file, a list of changed files created by a compare.
    20992034 */
    2100 void
    2101 streamline_changes_file(char *output_file, char *input_file)
    2102 {
    2103   FILE *fin;
    2104   FILE *fout;
     2035void streamline_changes_file(char *output_file, char *input_file)
     2036{
     2037    FILE *fin;
     2038    FILE *fout;
    21052039  /** malloc **/
    2106       char *incoming;
    2107 
    2108   assert_string_is_neither_NULL_nor_zerolength(output_file);
    2109   assert_string_is_neither_NULL_nor_zerolength(input_file);
    2110   malloc_string(incoming);
    2111  
    2112       if (!(fin=fopen(input_file,"r")))
    2113       {
    2114       log_OS_error(input_file);
    2115       return;
    2116       }
    2117       if (!(fout=fopen(output_file,"w")))
    2118       {
    2119       fatal_error("cannot open output_file");
    2120       }
    2121       for(fgets(incoming,MAX_STR_LEN-1,fin); !feof(fin); fgets(incoming,MAX_STR_LEN-1,fin))
    2122       {
    2123       if(strncmp(incoming,"etc/adjtime",11) \
    2124       && strncmp(incoming,"etc/mtab",8) \
    2125       && strncmp(incoming,"tmp/",4) \
    2126       && strncmp(incoming,"boot/map",8) \
    2127       && !strstr(incoming,"incheckentry") \
    2128       && strncmp(incoming,"etc/mail/statistics",19) \
    2129       && strncmp(incoming,"var/",4))
    2130       fprintf(fout,"%s",incoming); /* don't need \n here, for some reason.. */
    2131       }
    2132   paranoid_fclose(fout);
    2133   paranoid_fclose(fin);
    2134   paranoid_free(incoming);
    2135 }
     2040    char *incoming;
     2041
     2042    assert_string_is_neither_NULL_nor_zerolength(output_file);
     2043    assert_string_is_neither_NULL_nor_zerolength(input_file);
     2044    malloc_string(incoming);
     2045
     2046    if (!(fin = fopen(input_file, "r"))) {
     2047        log_OS_error(input_file);
     2048        return;
     2049    }
     2050    if (!(fout = fopen(output_file, "w"))) {
     2051        fatal_error("cannot open output_file");
     2052    }
     2053    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
     2054         fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2055        if (strncmp(incoming, "etc/adjtime", 11)
     2056            && strncmp(incoming, "etc/mtab", 8)
     2057            && strncmp(incoming, "tmp/", 4)
     2058            && strncmp(incoming, "boot/map", 8)
     2059            && !strstr(incoming, "incheckentry")
     2060            && strncmp(incoming, "etc/mail/statistics", 19)
     2061            && strncmp(incoming, "var/", 4))
     2062            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
     2063    }
     2064    paranoid_fclose(fout);
     2065    paranoid_fclose(fin);
     2066    paranoid_free(incoming);
     2067}
     2068
    21362069/**************************************************************************
    21372070 *END_STREAMLINE_CHANGES_FILE                                             *
     
    21462079 * Prompt the user to support the Mondo project.
    21472080 */
    2148 void
    2149 success_message(void)
    2150 {
    2151   int i;
    2152   /* malloc and ptr */
    2153   char *tmp;
    2154 
    2155   malloc_string(tmp);
    2156   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) {
    2157       if (ask_me_yes_or_no("Have you contributed to the Mondo project financially or in some other way, yet?")) {
    2158           log_to_screen("Thank you for supporting Mondo. It goes from strength to strength,");
    2159           log_to_screen("thanks to the support of users like you.");
    2160           }
    2161       else {
    2162           if (ask_me_yes_or_no("Are you or your company willing to consider contributing to Mondo in some way?")) {
    2163               popup_and_OK("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'.");
    2164               }
    2165           else {
    2166               log_to_screen("Free Software, like freedom itself, must be supported or it will be lost.");
    2167               log_msg(1, "To your credit, you were honest: you said no, you wouldn't be contributing");
    2168               log_msg(1, "to this project, ever. However, that makes you a freeloader. I bet you're");
    2169               log_msg(1, "the sort of person who likes to sneak into movie theatres...");
    2170               popup_and_OK("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'.");
    2171               }
    2172            }
    2173   }
    2174 
     2081void success_message(void)
     2082{
     2083    int i;
     2084    /* malloc and ptr */
     2085    char *tmp;
     2086
     2087    malloc_string(tmp);
     2088    if (strstr
     2089        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     2090         "restore") == NULL) {
     2091        if (ask_me_yes_or_no
     2092            ("Have you contributed to the Mondo project financially or in some other way, yet?"))
     2093        {
     2094            log_to_screen
     2095                ("Thank you for supporting Mondo. It goes from strength to strength,");
     2096            log_to_screen("thanks to the support of users like you.");
     2097        } else {
     2098            if (ask_me_yes_or_no
     2099                ("Are you or your company willing to consider contributing to Mondo in some way?"))
     2100            {
     2101                popup_and_OK
     2102                    ("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'.");
     2103            } else {
     2104                log_to_screen
     2105                    ("Free Software, like freedom itself, must be supported or it will be lost.");
     2106                log_msg(1,
     2107                        "To your credit, you were honest: you said no, you wouldn't be contributing");
     2108                log_msg(1,
     2109                        "to this project, ever. However, that makes you a freeloader. I bet you're");
     2110                log_msg(1,
     2111                        "the sort of person who likes to sneak into movie theatres...");
     2112                popup_and_OK
     2113                    ("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'.");
     2114            }
     2115        }
     2116    }
    21752117#ifdef FREELOADER
    2176   i = (int)(random())%32;
     2118    i = (int) (random()) % 32;
    21772119#else
    2178   i=1;
     2120    i = 1;
    21792121#endif
    21802122
    2181   if (i!=25)
    2182     {
    2183       strcpy(tmp,"Mondo has restored your system. Please remove the backup media and reboot.");
    2184     }
    2185   else
    2186     {
    2187       strcpy(tmp,"M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007.");
    2188     }
    2189   if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) {
    2190       popup_and_OK(tmp);
    2191       }
    2192   log_to_screen(tmp);
    2193   paranoid_free(tmp);
    2194 }
     2123    if (i != 25) {
     2124        strcpy(tmp,
     2125               "Mondo has restored your system. Please remove the backup media and reboot.");
     2126    } else {
     2127        strcpy(tmp,
     2128               "M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007.");
     2129    }
     2130    if (strstr
     2131        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
     2132         "restore") == NULL) {
     2133        popup_and_OK(tmp);
     2134    }
     2135    log_to_screen(tmp);
     2136    paranoid_free(tmp);
     2137}
     2138
    21952139/**************************************************************************
    21962140 *END_SUCCESS_MESSAGE                                                     *
     
    22032147 * @param sig The signal we're exiting due to.
    22042148 */
    2205 void
    2206 terminate_daemon(int sig)
    2207 {
    2208   log_to_screen("Mondorestore is terminating in response to a signal from the OS");
    2209   paranoid_MR_finish(254);
    2210 }
     2149void terminate_daemon(int sig)
     2150{
     2151    log_to_screen
     2152        ("Mondorestore is terminating in response to a signal from the OS");
     2153    paranoid_MR_finish(254);
     2154}
     2155
    22112156/**************************************************************************
    22122157 *END_TERMINATE_DAEMON                                                    *
     
    22172162 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
    22182163 */
    2219 void
    2220 twenty_seconds_til_yikes()
    2221 {
    2222   int i;
    2223   /* MALLOC **/
    2224   char *tmp;
    2225 
    2226   malloc_string(tmp);
    2227   if (does_file_exist("/tmp/NOPAUSE")) { return; }
    2228   open_progress_form("CAUTION",
    2229              "Be advised: I am about to ERASE your hard disk(s)!",
    2230              "You may press Ctrl+Alt+Del to abort safely.",
    2231              "",
    2232             20);
    2233   for(i = 0; i < 20; i++)
    2234     {
    2235       g_current_progress = i;
    2236       sprintf(tmp,"You have %d seconds left to abort.", 20 - i );
    2237       update_progress_form( tmp );
    2238       sleep( 1 );
    2239     }
    2240   close_progress_form();
    2241   paranoid_free(tmp);
    2242 }
     2164void twenty_seconds_til_yikes()
     2165{
     2166    int i;
     2167    /* MALLOC * */
     2168    char *tmp;
     2169
     2170    malloc_string(tmp);
     2171    if (does_file_exist("/tmp/NOPAUSE")) {
     2172        return;
     2173    }
     2174    open_progress_form("CAUTION",
     2175                       "Be advised: I am about to ERASE your hard disk(s)!",
     2176                       "You may press Ctrl+Alt+Del to abort safely.",
     2177                       "", 20);
     2178    for (i = 0; i < 20; i++) {
     2179        g_current_progress = i;
     2180        sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
     2181        update_progress_form(tmp);
     2182        sleep(1);
     2183    }
     2184    close_progress_form();
     2185    paranoid_free(tmp);
     2186}
     2187
    22432188/**************************************************************************
    22442189 *END_TWENTY_SECONDS_TIL_YIKES                                            *
     
    22532198 * @param sig The signal we're exiting due to.
    22542199 */
    2255 void
    2256 termination_in_progress(int sig)
    2257 {
    2258   log_msg(1, "Termination in progress");
    2259   usleep(1000);
    2260   pthread_exit(0);
    2261 }
     2200void termination_in_progress(int sig)
     2201{
     2202    log_msg(1, "Termination in progress");
     2203    usleep(1000);
     2204    pthread_exit(0);
     2205}
     2206
    22622207/**************************************************************************
    22632208 *END_TERMINATION_IN_PROGRESS                                             *
     
    22712216 * @return 0 for success, nonzero for failure.
    22722217 */
    2273 int unmount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist)
    2274 {
    2275   struct mountlist_itself *mountlist;
    2276   int retval=0,lino,res=0,i;
    2277   char *command;
    2278   char *tmp;
    2279 
    2280   malloc_string(command);
    2281   malloc_string(tmp);
    2282   assert(p_external_copy_of_mountlist!=NULL);
    2283 
    2284   mountlist = malloc(sizeof(struct mountlist_itself));
    2285   memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
    2286   sort_mountlist_by_mountpoint(mountlist, 0);
    2287 
    2288   run_program_and_log_output("df -m", 3);
    2289   mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices      ");
    2290   open_progress_form("Unmounting devices",
    2291              "Unmounting all devices that were mounted," ,
    2292              "in preparation for the post-restoration reboot.",
    2293              "",
    2294              mountlist->entries);
    2295   chdir( "/" );
    2296   for(i = 0; i < 10 && run_program_and_log_output("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++)
    2297     {
    2298       sleep( 1 );
    2299       log_msg(2, "Waiting for buffer() to finish");
    2300     }
    2301 
    2302   paranoid_system("sync");
    2303 
    2304   if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE ) )
    2305     {
    2306       log_msg(1, "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)");
    2307     }
    2308   if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE ) )
    2309     {
    2310       log_msg(1, "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)");
    2311     }
    2312   if (does_file_exist("/tmp/DUMBASS-GENTOO"))
    2313     {
    2314       run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5);
    2315     }
    2316   for( lino = mountlist->entries-1; lino >= 0; lino-- )
    2317     {
    2318       if (!strcmp(mountlist->el[lino].mountpoint,"lvm"))
    2319         {
    2320       continue;
    2321     }
    2322       sprintf(tmp,"Unmounting device %s  ",mountlist->el[lino].device);
    2323      
    2324       update_progress_form(tmp);
    2325       if (is_this_device_mounted(mountlist->el[lino].device))
    2326         {
    2327           if (!strcmp(mountlist->el[lino].mountpoint,"swap"))
    2328             {
    2329           sprintf(command,"swapoff %s",mountlist->el[lino].device);
    2330         } else {
    2331         if (!strcmp (mountlist->el[lino].mountpoint, "/1"))
    2332             {
    2333             sprintf (command, "umount %s/", MNT_RESTORING);
    2334             log_msg (3, "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
    2335             }
    2336         else
    2337             {
    2338             sprintf(command,"umount " MNT_RESTORING "%s",mountlist->el[lino].mountpoint);
    2339             }
    2340         }
    2341           log_msg(10, "The 'umount' command is '%s'", command);
    2342           res = run_program_and_log_output(command, 3);
    2343         }
    2344       else
    2345         {
    2346           strcat(tmp,"...not mounted anyway :-) OK");
    2347           res = 0;
    2348         }
    2349       g_current_progress++;
    2350       if (res)
    2351     {
    2352       strcat(tmp,"...Failed");
    2353       retval++;
    2354       log_to_screen(tmp);
    2355     }
    2356       else
    2357     {
    2358       log_msg(2, tmp);
    2359     }
    2360     }
    2361   close_progress_form();
    2362   if (retval)
    2363     {
    2364       mvaddstr_and_log_it(g_currentY++, 74, "Failed." );
    2365     }
    2366   else       
    2367     {
    2368       mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    2369     }
    2370   if (retval)
    2371     {
    2372       log_to_screen("Unable to unmount some of your partitions.");
    2373     }
    2374   else
    2375     {
    2376       log_to_screen("All partitions were unmounted OK.");
    2377     }
    2378   free(mountlist);
    2379   paranoid_free(command);
    2380   paranoid_free(tmp);
    2381   return(retval);
    2382 }
     2218int unmount_all_devices(struct mountlist_itself
     2219                        *p_external_copy_of_mountlist)
     2220{
     2221    struct mountlist_itself *mountlist;
     2222    int retval = 0, lino, res = 0, i;
     2223    char *command;
     2224    char *tmp;
     2225
     2226    malloc_string(command);
     2227    malloc_string(tmp);
     2228    assert(p_external_copy_of_mountlist != NULL);
     2229
     2230    mountlist = malloc(sizeof(struct mountlist_itself));
     2231    memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
     2232           sizeof(struct mountlist_itself));
     2233    sort_mountlist_by_mountpoint(mountlist, 0);
     2234
     2235    run_program_and_log_output("df -m", 3);
     2236    mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices      ");
     2237    open_progress_form("Unmounting devices",
     2238                       "Unmounting all devices that were mounted,",
     2239                       "in preparation for the post-restoration reboot.",
     2240                       "", mountlist->entries);
     2241    chdir("/");
     2242    for (i = 0;
     2243         i < 10
     2244         &&
     2245         run_program_and_log_output
     2246         ("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
     2247         i++) {
     2248        sleep(1);
     2249        log_msg(2, "Waiting for buffer() to finish");
     2250    }
     2251
     2252    paranoid_system("sync");
     2253
     2254    if (run_program_and_log_output
     2255        ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE)) {
     2256        log_msg(1,
     2257                "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)");
     2258    }
     2259    if (run_program_and_log_output
     2260        ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE)) {
     2261        log_msg(1,
     2262                "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)");
     2263    }
     2264    if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
     2265        run_program_and_log_output("mkdir -p " MNT_RESTORING
     2266                                   "/mnt/.boot.d", 5);
     2267    }
     2268    for (lino = mountlist->entries - 1; lino >= 0; lino--) {
     2269        if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
     2270            continue;
     2271        }
     2272        sprintf(tmp, "Unmounting device %s  ", mountlist->el[lino].device);
     2273
     2274        update_progress_form(tmp);
     2275        if (is_this_device_mounted(mountlist->el[lino].device)) {
     2276            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
     2277                sprintf(command, "swapoff %s", mountlist->el[lino].device);
     2278            } else {
     2279                if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
     2280                    sprintf(command, "umount %s/", MNT_RESTORING);
     2281                    log_msg(3,
     2282                            "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
     2283                } else {
     2284                    sprintf(command, "umount " MNT_RESTORING "%s",
     2285                            mountlist->el[lino].mountpoint);
     2286                }
     2287            }
     2288            log_msg(10, "The 'umount' command is '%s'", command);
     2289            res = run_program_and_log_output(command, 3);
     2290        } else {
     2291            strcat(tmp, "...not mounted anyway :-) OK");
     2292            res = 0;
     2293        }
     2294        g_current_progress++;
     2295        if (res) {
     2296            strcat(tmp, "...Failed");
     2297            retval++;
     2298            log_to_screen(tmp);
     2299        } else {
     2300            log_msg(2, tmp);
     2301        }
     2302    }
     2303    close_progress_form();
     2304    if (retval) {
     2305        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     2306    } else {
     2307        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     2308    }
     2309    if (retval) {
     2310        log_to_screen("Unable to unmount some of your partitions.");
     2311    } else {
     2312        log_to_screen("All partitions were unmounted OK.");
     2313    }
     2314    free(mountlist);
     2315    paranoid_free(command);
     2316    paranoid_free(tmp);
     2317    return (retval);
     2318}
     2319
    23832320/**************************************************************************
    23842321 *END_UNMOUNT_ALL_DEVICES                                                 *
     
    23932330 * @return 0 for success, nonzero for failure.
    23942331 */
    2395 int extract_cfg_file_and_mountlist_from_tape_dev(char*dev)
    2396 {
    2397   char *command;
    2398   int res=0;
    2399   // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
    2400   long tape_block_size=32768;
    2401 
    2402   malloc_string(command);
    2403 
    2404   // tar -zxvf-
    2405        sprintf( command,
    2406         "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
    2407            dev,
    2408            tape_block_size,
    2409            1024L*1024*32/tape_block_size,
    2410                    MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
    2411            BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB,
    2412            "tmp/i-want-my-lvm" );
    2413        log_msg (2, "command = '%s'", command);
    2414            res = run_program_and_log_output( command, -1 );
    2415        if (res!=0 && does_file_exist(MONDO_CFG_FILE_STUB)) { res=0; }
    2416   paranoid_free(command);
    2417   return(res);
    2418 }
    2419 
    2420  
    2421  
     2332int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
     2333{
     2334    char *command;
     2335    int res = 0;
     2336    // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
     2337    long tape_block_size = 32768;
     2338
     2339    malloc_string(command);
     2340
     2341    // tar -zxvf-
     2342    sprintf(command,
     2343            "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
     2344            dev,
     2345            tape_block_size,
     2346            1024L * 1024 * 32 / tape_block_size,
     2347            MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
     2348            BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");
     2349    log_msg(2, "command = '%s'", command);
     2350    res = run_program_and_log_output(command, -1);
     2351    if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
     2352        res = 0;
     2353    }
     2354    paranoid_free(command);
     2355    return (res);
     2356}
     2357
     2358
     2359
    24222360/**
    24232361 * Get the configuration file from the floppy, tape, or CD.
     
    24282366 * @return 0 for success, nonzero for failure.
    24292367 */
    2430 int
    2431 get_cfg_file_from_archive( struct s_bkpinfo *bkpinfo )
    2432 {
    2433    int retval = 0;
    2434    
     2368int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo)
     2369{
     2370    int retval = 0;
     2371
    24352372   /** malloc *****/
    2436    char *device;
    2437    char *command;
    2438    char *cfg_file;
    2439    char *mounted_cfgf_path;
    2440    char *tmp;
    2441    char *mountpt;
    2442    char *ramdisk_fname;
    2443    char *mountlist_file;
    2444    int res;
    2445    
    2446    bool try_plan_B;
    2447 
    2448    assert(bkpinfo!=NULL);
    2449    malloc_string(cfg_file);
    2450    malloc_string(mounted_cfgf_path);
    2451    malloc_string(mountpt);
    2452    malloc_string(ramdisk_fname);
    2453    malloc_string(mountlist_file);
    2454    malloc_string(device);
    2455    malloc_string(command);
    2456    malloc_string(tmp);
    2457    log_msg(2, "gcffa --- starting" );
    2458    log_to_screen("I'm thinking...");
    2459    sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir );
    2460    device[0] = '\0';
    2461    chdir( bkpinfo->tmpdir );
    2462    strcpy( cfg_file, MONDO_CFG_FILE_STUB);
    2463    unlink( cfg_file ); // cfg_file[] is missing the '/' at the start, FYI, by intent
    2464    unlink( FILELIST_FULL_STUB );
    2465    unlink( BIGGIELIST_TXT_STUB );
    2466    unlink( "tmp/i-want-my-lvm");
    2467    sprintf( command, "mkdir -p %s", mountpt );
    2468    run_program_and_log_output( command, FALSE );
    2469    
     2373    char *device;
     2374    char *command;
     2375    char *cfg_file;
     2376    char *mounted_cfgf_path;
     2377    char *tmp;
     2378    char *mountpt;
     2379    char *ramdisk_fname;
     2380    char *mountlist_file;
     2381    int res;
     2382
     2383    bool try_plan_B;
     2384
     2385    assert(bkpinfo != NULL);
     2386    malloc_string(cfg_file);
     2387    malloc_string(mounted_cfgf_path);
     2388    malloc_string(mountpt);
     2389    malloc_string(ramdisk_fname);
     2390    malloc_string(mountlist_file);
     2391    malloc_string(device);
     2392    malloc_string(command);
     2393    malloc_string(tmp);
     2394    log_msg(2, "gcffa --- starting");
     2395    log_to_screen("I'm thinking...");
     2396    sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
     2397    device[0] = '\0';
     2398    chdir(bkpinfo->tmpdir);
     2399    strcpy(cfg_file, MONDO_CFG_FILE_STUB);
     2400    unlink(cfg_file);           // cfg_file[] is missing the '/' at the start, FYI, by intent
     2401    unlink(FILELIST_FULL_STUB);
     2402    unlink(BIGGIELIST_TXT_STUB);
     2403    unlink("tmp/i-want-my-lvm");
     2404    sprintf(command, "mkdir -p %s", mountpt);
     2405    run_program_and_log_output(command, FALSE);
     2406
    24702407//   unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
    2471  
    2472    sprintf( cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
    2473    sprintf( mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
    2474    //   make_hole_for_file( cfg_file );
    2475    //   make_hole_for_file( mountlist_file);
    2476    log_msg (2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file );
    2477  
    2478    /* Floppy? */
    2479    sprintf( tmp, "mkdir -p %s", mountpt );
    2480    run_program_and_log_output( tmp, FALSE );
    2481    sprintf( tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    2482    run_program_and_log_output( tmp, FALSE);
    2483 
    2484    sprintf( command, "mount /dev/fd0u1722 %s", mountpt );
    2485    sprintf( tmp, "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", command);
    2486    log_msg(1, "tmp = '%s'", tmp);
    2487    system(tmp);
    2488    res = run_program_and_log_output( command, FALSE );
    2489    if (res) {
    2490     sprintf( command, "mount /dev/fd0H1440 %s", mountpt );
    2491     res = run_program_and_log_output( command, FALSE );
    2492    }
    2493    if (res) {
    2494     try_plan_B=TRUE;
    2495    } else {
    2496         try_plan_B=TRUE;
    2497         log_msg(2, "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
     2408
     2409    sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
     2410    sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
     2411            MOUNTLIST_FNAME_STUB);
     2412    //   make_hole_for_file( cfg_file );
     2413    //   make_hole_for_file( mountlist_file);
     2414    log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
     2415
     2416    /* Floppy? */
     2417    sprintf(tmp, "mkdir -p %s", mountpt);
     2418    run_program_and_log_output(tmp, FALSE);
     2419    sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
     2420    run_program_and_log_output(tmp, FALSE);
     2421
     2422    sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
     2423    sprintf(tmp,
     2424            "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
     2425            command);
     2426    log_msg(1, "tmp = '%s'", tmp);
     2427    system(tmp);
     2428    res = run_program_and_log_output(command, FALSE);
     2429    if (res) {
     2430        sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
     2431        res = run_program_and_log_output(command, FALSE);
     2432    }
     2433    if (res) {
     2434        try_plan_B = TRUE;
     2435    } else {
     2436        try_plan_B = TRUE;
     2437        log_msg(2,
     2438                "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
    24982439// NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
    2499     log_msg(2, "Processing floppy (plan A?)" );
    2500     sprintf( ramdisk_fname, "%s/mindi.rdz", mountpt );
    2501     if ( !does_file_exist( ramdisk_fname ) )
    2502       {
    2503         sprintf( ramdisk_fname, "%s/initrd.img", mountpt );
    2504       }
    2505     if ( !does_file_exist( ramdisk_fname ) )
    2506       {
    2507         log_msg(2, "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?" );
    2508       }
    2509     if ( extract_config_file_from_ramdisk( bkpinfo, ramdisk_fname, cfg_file, mountlist_file ) )
    2510       {
    2511         log_msg(2, "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled." );
    2512       }
    2513     sprintf( command, "umount %s", mountpt );
    2514         run_program_and_log_output(command, 5);
    2515     unlink(ramdisk_fname);
    2516        }
    2517    if ( !does_file_exist( cfg_file ) )
    2518      {
    2519 log_msg(2, "gcffa --- we don't have cfg file yet." );
    2520        if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) )
    2521          {
    2522       try_plan_B = TRUE;
    2523     }
    2524         else
    2525           {
    2526            log_msg(2, "gcffa --- calling mount_cdrom now :)" );
    2527            if ( !mount_cdrom( bkpinfo ) )
    2528              {
    2529 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B" );
    2530           try_plan_B = FALSE;
    2531         }
    2532             else
    2533              {
    2534           try_plan_B = TRUE;
    2535         }
    2536       if ( what_number_cd_is_this(bkpinfo) > 1 )
    2537               {
    2538                insist_on_this_cd_number( bkpinfo, ( g_current_media_number = 1 ) );
    2539               }
    2540           }
    2541        if ( try_plan_B )
    2542           {
    2543            log_msg(2, "gcffa --- OK, switching to Plan B" );
    2544            chdir( bkpinfo->tmpdir );
    2545            run_program_and_log_output ( "mkdir -p tmp", FALSE );
    2546 
    2547        if (strlen(bkpinfo->media_device) ==0 )
    2548          {
    2549            strcpy(bkpinfo->media_device, "/dev/st0");
    2550            log_msg(2,"media_device is blank; assuming %s");
    2551          }
    2552            strcpy(tmp, bkpinfo->media_device);
    2553            if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2554          {
    2555            strcpy(bkpinfo->media_device, "/dev/st0");
    2556                if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2557              {
    2558                strcpy(bkpinfo->media_device, "/dev/osst0");
    2559                    if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2560              {
    2561                strcpy(bkpinfo->media_device, "/dev/ht0");
    2562                        if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device))
    2563                          {
    2564                log_msg(3, "I tried lots of devices but none worked.");
    2565                strcpy(bkpinfo->media_device, tmp);
    2566                          }
    2567                      }
    2568              }
    2569              }
    2570 
    2571            if ( !does_file_exist( "tmp/mondo-restore.cfg") )
    2572              {
    2573           log_to_screen ( "Cannot find config info on tape/CD/floppy");
    2574               return(1);
    2575         }
    2576           }
    2577       else
    2578         {
    2579 log_msg(2, "gcffa --- looking at mounted CD for mindi-boot.2880.img" );
    2580           sprintf( command, "mount "MNT_CDROM"/images/mindi-boot.2880.img -o loop %s", mountpt );
    2581           sprintf( mounted_cfgf_path, "%s/%s", mountpt, cfg_file );
    2582           if (!does_file_exist(mounted_cfgf_path))
    2583             {
    2584               log_msg(2,"gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz" );
    2585               sprintf( command,
    2586                "tar -zxvf "MNT_CDROM"/images/all.tar.gz %s %s %s %s %s",
    2587                 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"
    2588                ); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
    2589               run_program_and_log_output( command, TRUE );
    2590               if ( !does_file_exist( MONDO_CFG_FILE_STUB ) )
    2591                 {
    2592           fatal_error( "Please reinsert the disk/CD and try again." );
    2593         }
    2594             }
    2595         }
    2596     }
    2597   if ( does_file_exist( MONDO_CFG_FILE_STUB) )
    2598     {
    2599       log_msg(1, "gcffa --- great! We've got the config file" );
    2600       sprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB);
    2601       sprintf( command, "cp -f %s %s", tmp, cfg_file);
    2602       iamhere(command);
    2603       if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 ))
    2604         { log_msg(1,"... but an error occurred when I tried to move it to %s", cfg_file); }
    2605       else
    2606         { log_msg(1,"... and I moved it successfully to %s", cfg_file); }
    2607       sprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file);
    2608       iamhere(command);
    2609       if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 ))
    2610         { log_msg(1,"Failed to get mountlist"); }
    2611       else
    2612         {
    2613       log_msg(1,"Got mountlist too");
    2614       sprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
    2615       if (run_program_and_log_output(command, 1))
    2616         { log_msg(1, "Failed to copy mountlist to /tmp"); }
    2617       else
    2618         {
    2619           log_msg(1, "Copied mountlist to /tmp as well OK");
    2620           sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
    2621           run_program_and_log_output(command, 1);
     2440        log_msg(2, "Processing floppy (plan A?)");
     2441        sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
     2442        if (!does_file_exist(ramdisk_fname)) {
     2443            sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
     2444        }
     2445        if (!does_file_exist(ramdisk_fname)) {
     2446            log_msg(2,
     2447                    "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?");
     2448        }
     2449        if (extract_config_file_from_ramdisk
     2450            (bkpinfo, ramdisk_fname, cfg_file, mountlist_file)) {
     2451            log_msg(2,
     2452                    "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
     2453        }
     2454        sprintf(command, "umount %s", mountpt);
     2455        run_program_and_log_output(command, 5);
     2456        unlink(ramdisk_fname);
     2457    }
     2458    if (!does_file_exist(cfg_file)) {
     2459        log_msg(2, "gcffa --- we don't have cfg file yet.");
     2460        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     2461            try_plan_B = TRUE;
     2462        } else {
     2463            log_msg(2, "gcffa --- calling mount_cdrom now :)");
     2464            if (!mount_cdrom(bkpinfo)) {
     2465                log_msg(2,
     2466                        "gcffa --- managed to mount CD; so, no need for Plan B");
     2467                try_plan_B = FALSE;
     2468            } else {
     2469                try_plan_B = TRUE;
     2470            }
     2471            if (what_number_cd_is_this(bkpinfo) > 1) {
     2472                insist_on_this_cd_number(bkpinfo,
     2473                                         (g_current_media_number = 1));
     2474            }
     2475        }
     2476        if (try_plan_B) {
     2477            log_msg(2, "gcffa --- OK, switching to Plan B");
     2478            chdir(bkpinfo->tmpdir);
     2479            run_program_and_log_output("mkdir -p tmp", FALSE);
     2480
     2481            if (strlen(bkpinfo->media_device) == 0) {
     2482                strcpy(bkpinfo->media_device, "/dev/st0");
     2483                log_msg(2, "media_device is blank; assuming %s");
     2484            }
     2485            strcpy(tmp, bkpinfo->media_device);
     2486            if (extract_cfg_file_and_mountlist_from_tape_dev
     2487                (bkpinfo->media_device)) {
     2488                strcpy(bkpinfo->media_device, "/dev/st0");
     2489                if (extract_cfg_file_and_mountlist_from_tape_dev
     2490                    (bkpinfo->media_device)) {
     2491                    strcpy(bkpinfo->media_device, "/dev/osst0");
     2492                    if (extract_cfg_file_and_mountlist_from_tape_dev
     2493                        (bkpinfo->media_device)) {
     2494                        strcpy(bkpinfo->media_device, "/dev/ht0");
     2495                        if (extract_cfg_file_and_mountlist_from_tape_dev
     2496                            (bkpinfo->media_device)) {
     2497                            log_msg(3,
     2498                                    "I tried lots of devices but none worked.");
     2499                            strcpy(bkpinfo->media_device, tmp);
     2500                        }
     2501                    }
     2502                }
     2503            }
     2504
     2505            if (!does_file_exist("tmp/mondo-restore.cfg")) {
     2506                log_to_screen("Cannot find config info on tape/CD/floppy");
     2507                return (1);
     2508            }
     2509        } else {
     2510            log_msg(2,
     2511                    "gcffa --- looking at mounted CD for mindi-boot.2880.img");
     2512            sprintf(command,
     2513                    "mount " MNT_CDROM
     2514                    "/images/mindi-boot.2880.img -o loop %s", mountpt);
     2515            sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
     2516            if (!does_file_exist(mounted_cfgf_path)) {
     2517                log_msg(2,
     2518                        "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz");
     2519                sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");  // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
     2520                run_program_and_log_output(command, TRUE);
     2521                if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
     2522                    fatal_error
     2523                        ("Please reinsert the disk/CD and try again.");
     2524                }
     2525            }
     2526        }
     2527    }
     2528    if (does_file_exist(MONDO_CFG_FILE_STUB)) {
     2529        log_msg(1, "gcffa --- great! We've got the config file");
     2530        sprintf(tmp, "%s/%s",
     2531                call_program_and_get_last_line_of_output("pwd"),
     2532                MONDO_CFG_FILE_STUB);
     2533        sprintf(command, "cp -f %s %s", tmp, cfg_file);
     2534        iamhere(command);
     2535        if (strcmp(tmp, cfg_file)
     2536            && run_program_and_log_output(command, 1)) {
     2537            log_msg(1,
     2538                    "... but an error occurred when I tried to move it to %s",
     2539                    cfg_file);
     2540        } else {
     2541            log_msg(1, "... and I moved it successfully to %s", cfg_file);
     2542        }
     2543        sprintf(command, "cp -f %s/%s %s",
     2544                call_program_and_get_last_line_of_output("pwd"),
     2545                MOUNTLIST_FNAME_STUB, mountlist_file);
     2546        iamhere(command);
     2547        if (strcmp(tmp, cfg_file)
     2548            && run_program_and_log_output(command, 1)) {
     2549            log_msg(1, "Failed to get mountlist");
     2550        } else {
     2551            log_msg(1, "Got mountlist too");
     2552            sprintf(command, "cp -f %s %s", mountlist_file,
     2553                    g_mountlist_fname);
     2554            if (run_program_and_log_output(command, 1)) {
     2555                log_msg(1, "Failed to copy mountlist to /tmp");
     2556            } else {
     2557                log_msg(1, "Copied mountlist to /tmp as well OK");
     2558                sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
     2559                run_program_and_log_output(command, 1);
    26222560/*        sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
    26232561          if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
     
    26392577        }
    26402578*/
    2641         }
    2642         }
    2643     }
    2644   run_program_and_log_output( "umount "MNT_CDROM, FALSE );
    2645   if ( !does_file_exist( cfg_file ) )
    2646     {
    2647       iamhere(cfg_file);
    2648       log_msg(1, "%s not found", cfg_file);
    2649       log_to_screen("Oh dear. Unable to recover configuration file from boot disk");
    2650       return(1);
    2651     }
    2652 
    2653   log_to_screen( "Recovered mondo-restore.cfg" );
    2654   if (!does_file_exist( MOUNTLIST_FNAME_STUB ))
    2655     { log_to_screen( "...but not mountlist.txt - a pity, really..."); }
     2579            }
     2580        }
     2581    }
     2582    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     2583    if (!does_file_exist(cfg_file)) {
     2584        iamhere(cfg_file);
     2585        log_msg(1, "%s not found", cfg_file);
     2586        log_to_screen
     2587            ("Oh dear. Unable to recover configuration file from boot disk");
     2588        return (1);
     2589    }
     2590
     2591    log_to_screen("Recovered mondo-restore.cfg");
     2592    if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
     2593        log_to_screen("...but not mountlist.txt - a pity, really...");
     2594    }
    26562595/* start SAH */
    2657   else
    2658     {
    2659       sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    2660       run_program_and_log_output(command,FALSE);
    2661     }
     2596    else {
     2597        sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
     2598                bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
     2599        run_program_and_log_output(command, FALSE);
     2600    }
    26622601/*--commented out by SAH
    26632602  sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
     
    26682607/* end SAH */
    26692608
    2670   sprintf( command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB );
    2671   run_program_and_log_output( command, FALSE );
    2672   sprintf( command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB );
    2673   run_program_and_log_output( command, FALSE );
    2674   sprintf( command, "cp -f etc/raidtab /etc/");
    2675   run_program_and_log_output( command, FALSE );
    2676   sprintf( command, "cp -f tmp/i-want-my-lvm /tmp/");
    2677   run_program_and_log_output( command, FALSE );
    2678   g_backup_media_type = bkpinfo->backup_media_type;
    2679   paranoid_free(device);
    2680   paranoid_free(command);
    2681   paranoid_free(tmp);
    2682   paranoid_free(cfg_file);
    2683   paranoid_free(mounted_cfgf_path);
    2684   paranoid_free(mountpt);
    2685   paranoid_free(ramdisk_fname);
    2686   paranoid_free(mountlist_file);
    2687   return( retval );
     2609    sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
     2610    run_program_and_log_output(command, FALSE);
     2611    sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
     2612    run_program_and_log_output(command, FALSE);
     2613    sprintf(command, "cp -f etc/raidtab /etc/");
     2614    run_program_and_log_output(command, FALSE);
     2615    sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
     2616    run_program_and_log_output(command, FALSE);
     2617    g_backup_media_type = bkpinfo->backup_media_type;
     2618    paranoid_free(device);
     2619    paranoid_free(command);
     2620    paranoid_free(tmp);
     2621    paranoid_free(cfg_file);
     2622    paranoid_free(mounted_cfgf_path);
     2623    paranoid_free(mountpt);
     2624    paranoid_free(ramdisk_fname);
     2625    paranoid_free(mountlist_file);
     2626    return (retval);
    26882627}
    26892628
     
    27062645 ***************************************************************************/
    27072646
    2708  
    2709  
    2710 void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage)
    2711 {
    2712   struct s_mdstat *mdstat;
    2713   int unfinished_mdstat_devices=9999, i;
    2714   char *screen_message;
    2715  
    2716   malloc_string(screen_message);
    2717   mdstat = malloc(sizeof(struct s_mdstat));
    2718 
    2719   assert(wait_for_percentage <= 100);
    2720   iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
    2721   while(unfinished_mdstat_devices > 0)
    2722     {
    2723       if (read_mdstat(mdstat, mdstat_file))
    2724         { log_to_screen("Sorry, cannot read %s", mdstat_file); return; }
    2725       for(unfinished_mdstat_devices=i=0; i<mdstat->entries; i++)
    2726         {
    2727           if (mdstat->el[i].progress < wait_for_percentage)
    2728             {
    2729           unfinished_mdstat_devices++;
    2730           sprintf(screen_message, "Sync'ing /dev/md%d", mdstat->el[i].md);
    2731           open_evalcall_form(screen_message);
    2732           if (mdstat->el[i].progress == -1) // delayed while another partition inits
    2733             {
    2734           continue;
    2735         }
    2736           while(mdstat->el[i].progress < wait_for_percentage)
    2737             {
    2738           update_evalcall_form(mdstat->el[i].progress);
    2739           sleep(2);
    2740           if (read_mdstat(mdstat, mdstat_file)) {break;}
    2741         }
    2742           close_evalcall_form();
    2743         }
    2744         }
    2745     }
    2746   paranoid_free(screen_message);
    2747   paranoid_free(mdstat);
    2748 }
    2749 
    2750 
     2647
     2648
     2649void wait_until_software_raids_are_prepped(char *mdstat_file,
     2650                                           int wait_for_percentage)
     2651{
     2652    struct s_mdstat *mdstat;
     2653    int unfinished_mdstat_devices = 9999, i;
     2654    char *screen_message;
     2655
     2656    malloc_string(screen_message);
     2657    mdstat = malloc(sizeof(struct s_mdstat));
     2658
     2659    assert(wait_for_percentage <= 100);
     2660    iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");
     2661    while (unfinished_mdstat_devices > 0) {
     2662        if (read_mdstat(mdstat, mdstat_file)) {
     2663            log_to_screen("Sorry, cannot read %s", mdstat_file);
     2664            return;
     2665        }
     2666        for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) {
     2667            if (mdstat->el[i].progress < wait_for_percentage) {
     2668                unfinished_mdstat_devices++;
     2669                sprintf(screen_message, "Sync'ing /dev/md%d",
     2670                        mdstat->el[i].md);
     2671                open_evalcall_form(screen_message);
     2672                if (mdstat->el[i].progress == -1)   // delayed while another partition inits
     2673                {
     2674                    continue;
     2675                }
     2676                while (mdstat->el[i].progress < wait_for_percentage) {
     2677                    update_evalcall_form(mdstat->el[i].progress);
     2678                    sleep(2);
     2679                    if (read_mdstat(mdstat, mdstat_file)) {
     2680                        break;
     2681                    }
     2682                }
     2683                close_evalcall_form();
     2684            }
     2685        }
     2686    }
     2687    paranoid_free(screen_message);
     2688    paranoid_free(mdstat);
     2689}
  • branches/2.05/mondo/mondo/mondorestore/mondo-rstr-tools.h

    r30 r128  
    44
    55void free_global_filenames();
    6 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo*);
    7 bool is_file_in_list(char*, char*, char*); /* needle, haystack, preamble */
     6void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);
     7bool is_file_in_list(char *, char *, char *);   /* needle, haystack, preamble */
    88int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please);
    99void kill_petris(void);
    10 int modify_rclocal_one_time( char *path );
     10int modify_rclocal_one_time(char *path);
    1111int mount_cdrom(struct s_bkpinfo *bkpinfo);
    12 int mount_device(char*,char*,char*,bool);
    13 int mount_all_devices(struct mountlist_itself*, bool);
     12int mount_device(char *, char *, char *, bool);
     13int mount_all_devices(struct mountlist_itself *, bool);
    1414void protect_against_braindead_sysadmins(void);
    15 int read_cfg_file_into_bkpinfo( char* cfg_file, struct s_bkpinfo *bkpinfo);
     15int read_cfg_file_into_bkpinfo(char *cfg_file, struct s_bkpinfo *bkpinfo);
    1616struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *);
    17 int backup_crucial_file(char *path_root, char*filename);
     17int backup_crucial_file(char *path_root, char *filename);
    1818
    1919int run_boot_loader(bool);
    20 int run_grub(bool, char*);
     20int run_grub(bool, char *);
    2121int run_lilo(bool);
    2222int run_elilo(bool);
    2323int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
    2424char *find_my_editor(void);
    25 void streamline_changes_file(char*,char*);
    26 void  set_signals( int on );
     25void streamline_changes_file(char *, char *);
     26void set_signals(int on);
    2727void setup_global_filenames(struct s_bkpinfo *bkpinfo);
    2828//void setup_signals(int);
    2929void success_message(void);
    3030void twenty_seconds_til_yikes(void);
    31 int run_raw_mbr(bool offer_to_hack_scripts, char*bd);
     31int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
    3232void terminate_daemon(int);
    3333void termination_in_progress(int);
    34 int unmount_all_devices(struct mountlist_itself*);
     34int unmount_all_devices(struct mountlist_itself *);
    3535int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo);
    36 void ask_about_these_imagedevs( char *infname, char *outfname );
    37 
     36void ask_about_these_imagedevs(char *infname, char *outfname);
  • branches/2.05/mondo/mondo/mondorestore/mondoprep.h

    r30 r128  
    55    copyright            : (C) 2002 by Stan Benoit
    66    email                : troff@nakedsoul.org
    7     cvsid                : $Id: mondoprep.h,v 1.4 2004/06/16 10:38:29 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    2323extern int g_currentY, g_current_cd_number;
    2424extern char *g_tape_device;
    25 extern void finish (int);
    26 extern void setup_newt_stuff (void);
    27 extern char which_restore_mode (void);
    28 extern bool ask_me_yes_or_no (char *);
    29 extern long get_phys_size_of_drive (char *);
     25extern void finish(int);
     26extern void setup_newt_stuff(void);
     27extern char which_restore_mode(void);
     28extern bool ask_me_yes_or_no(char *);
     29extern long get_phys_size_of_drive(char *);
    3030//extern void log_to_screen (char *);
    31 extern void update_progress_form (char *);
    32 extern void open_progress_form (char *, char *, char *, char *, long);
    33 extern void close_progress_form (void);
    34 extern void popup_and_OK (char *);
    35 extern bool popup_and_get_string (char *, char *, char *, int);
    36 extern long get_time (void);
    37 extern bool is_this_device_mounted (char *);
    38 extern int does_partition_exist (const char *device, int partno);
    39 extern int strcmp_inc_numbers (char *, char *);
    40 extern long count_lines_in_file (char *);
    41 extern long long length_of_file (char *);
    42 extern long noof_lines_that_match_wildcard (char *, char *);
     31extern void update_progress_form(char *);
     32extern void open_progress_form(char *, char *, char *, char *, long);
     33extern void close_progress_form(void);
     34extern void popup_and_OK(char *);
     35extern bool popup_and_get_string(char *, char *, char *, int);
     36extern long get_time(void);
     37extern bool is_this_device_mounted(char *);
     38extern int does_partition_exist(const char *device, int partno);
     39extern int strcmp_inc_numbers(char *, char *);
     40extern long count_lines_in_file(char *);
     41extern long long length_of_file(char *);
     42extern long noof_lines_that_match_wildcard(char *, char *);
    4343//extern char *slice_fname (long, long, bool, char *);
    44 extern char *last_line_of_file (char *);
    45 extern void log_file_end_to_screen (char *, char *);
    46 extern int zero_out_a_device (char *);
    47 extern void mvaddstr_and_log_it (int, int, char *);
    48 extern bool does_file_exist (char *);
     44extern char *last_line_of_file(char *);
     45extern void log_file_end_to_screen(char *, char *);
     46extern int zero_out_a_device(char *);
     47extern void mvaddstr_and_log_it(int, int, char *);
     48extern bool does_file_exist(char *);
    4949
    5050
    5151/** locals **********************************************************/
    52 int extrapolate_mountlist_to_include_raid_partitions (struct mountlist_itself
    53                               *,
    54                               struct mountlist_itself
    55                               *);
    56 bool mountlist_contains_raid_devices (struct mountlist_itself *);
    57 int start_raid_device (char *);
    58 int stop_raid_device (char *);
    59 int start_all_raid_devices (struct mountlist_itself *);
    60 int stop_all_raid_devices (struct mountlist_itself *);
    61 int format_everything (struct mountlist_itself *, bool);
    62 int partition_device (FILE*,const char *, int, int, const char *, long long);
    63 int partition_device_with_parted (FILE*,const char *, int, int, const char *, long long);
    64 int partition_device_with_fdisk (FILE*,const char *, int, int, const char *, long long);
    65 int format_device (char *, char *);
    66 int partition_drive (struct mountlist_itself *, char *);
    67 int partition_everything (struct mountlist_itself *);
    68 int do_my_funky_lvm_stuff (bool, bool);
    69 int which_format_command_do_i_need (char *, char *);
    70 int make_dummy_partitions (FILE*, char *, int);
    71 int make_list_of_drives (struct mountlist_itself *,
    72              char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
    73 int set_partition_type (FILE*,const char *, int, const char *, long long);
    74 void resize_drive_proportionately_to_suit_new_drives (struct mountlist_itself
    75                               *mountlist,
    76                               char *drive_name);
    77 void resize_mountlist_proportionately_to_suit_new_drives (struct
    78                               mountlist_itself
    79                               *mountlist);
     52int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself
     53                                                     *, struct mountlist_itself
     54                                                     *);
     55bool mountlist_contains_raid_devices(struct mountlist_itself *);
     56int start_raid_device(char *);
     57int stop_raid_device(char *);
     58int start_all_raid_devices(struct mountlist_itself *);
     59int stop_all_raid_devices(struct mountlist_itself *);
     60int format_everything(struct mountlist_itself *, bool);
     61int partition_device(FILE *, const char *, int, int, const char *,
     62                     long long);
     63int partition_device_with_parted(FILE *, const char *, int, int,
     64                                 const char *, long long);
     65int partition_device_with_fdisk(FILE *, const char *, int, int,
     66                                const char *, long long);
     67int format_device(char *, char *);
     68int partition_drive(struct mountlist_itself *, char *);
     69int partition_everything(struct mountlist_itself *);
     70int do_my_funky_lvm_stuff(bool, bool);
     71int which_format_command_do_i_need(char *, char *);
     72int make_dummy_partitions(FILE *, char *, int);
     73int make_list_of_drives(struct mountlist_itself *,
     74                        char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]);
     75int set_partition_type(FILE *, const char *, int, const char *, long long);
     76void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself
     77                                                     *mountlist,
     78                                                     char *drive_name);
     79void resize_mountlist_proportionately_to_suit_new_drives(struct
     80                                                         mountlist_itself
     81                                                         *mountlist);
    8082
    8183
    82 char *
    83 truncate_to_drive_name (char *partition);
    84 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist);
    85 
     84char *truncate_to_drive_name(char *partition);
     85void create_mountlist_for_drive(struct mountlist_itself *mountlist,
     86                                char *drive_name,
     87                                struct mountlist_reference *drivemntlist);
  • branches/2.05/mondo/mondo/mondorestore/mr-externs.h

    r30 r128  
    11/*
    2  * $Id: mr-externs.h,v 1.3 2004/06/10 15:29:13 hugo Exp $
     2 * $Id$
    33 *
    44 * mondo-restore.c's externs
     
    66 */
    77
    8 #define SIZE 730000 * 1024                        /*  Size for ISO's stops -1 */
     8#define SIZE 730000 * 1024      /*  Size for ISO's stops -1 */
    99#define BIGGIELIST MNT_CDROM"/archives/biggielist.txt"
    1010#define ARCHIVES_PATH MNT_CDROM"/archives"
     
    1414#endif
    1515
    16 extern bool ask_me_yes_or_no(char*);
    17 extern char* calc_checksum_of_file(char*);
    18 extern int closein_tape(struct s_bkpinfo*);
     16extern bool ask_me_yes_or_no(char *);
     17extern char *calc_checksum_of_file(char *);
     18extern int closein_tape(struct s_bkpinfo *);
    1919extern void close_evalcall_form(void);
    20 extern char *call_program_and_get_last_line_of_output(char*);
     20extern char *call_program_and_get_last_line_of_output(char *);
    2121extern void close_progress_form(void);
    22 extern long count_lines_in_file(char*);
    23 extern bool does_file_exist(char*);
    24 extern int does_partition_exist(const char*device, int partno);
     22extern long count_lines_in_file(char *);
     23extern bool does_file_exist(char *);
     24extern int does_partition_exist(const char *device, int partno);
    2525extern int do_my_funky_lvm_stuff(bool, bool);
    2626extern int edit_filelist(struct s_node *);
    27 extern int edit_mountlist(char* mountlist_fname, struct mountlist_itself*, struct raidlist_itself*);
    28 extern int format_everything(struct mountlist_itself*, bool);
    29 extern int format_device(char*,char*);
     27extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *,
     28                          struct raidlist_itself *);
     29extern int format_everything(struct mountlist_itself *, bool);
     30extern int format_device(char *, char *);
    3031extern void finish(int);
    31 extern void free_filelist(struct s_node*);
     32extern void free_filelist(struct s_node *);
    3233extern long get_time(void);
    33 extern bool get_isodir_info(char*,char*,char*,bool);
    34 extern void fatal_error(char*);
    35 extern void initialize_raid_record(struct raid_device_record*);
    36 extern bool is_this_device_mounted(char*);
    37 extern long long length_of_file(char*);
    38 extern char *last_line_of_file(char*);
    39 extern struct s_node *load_filelist(char*);
     34extern bool get_isodir_info(char *, char *, char *, bool);
     35extern void fatal_error(char *);
     36extern void initialize_raid_record(struct raid_device_record *);
     37extern bool is_this_device_mounted(char *);
     38extern long long length_of_file(char *);
     39extern char *last_line_of_file(char *);
     40extern struct s_node *load_filelist(char *);
    4041extern void log_tape_pos(void);
    41 extern void initialize_raidrec(struct raid_device_record*);
    42 extern void log_file_end_to_screen(char*,char*);
    43 extern void log_to_screen (const char *fmt, ...);
     42extern void initialize_raidrec(struct raid_device_record *);
     43extern void log_file_end_to_screen(char *, char *);
     44extern void log_to_screen(const char *fmt, ...);
    4445extern void mvaddstr_and_log_it(int, int, char *);
    45 extern int make_dummy_partitions(char*,int);
    46 extern int make_hole_for_file(char*);
    47 extern int make_list_of_drives(struct mountlist_itself*, struct list_of_disks*);
    48 extern bool mountlist_contains_raid_devices(struct mountlist_itself*);
    49 extern void open_evalcall_form(char*);
    50 extern void open_progress_form(char*,char*,char*,char*,long);
     46extern int make_dummy_partitions(char *, int);
     47extern int make_hole_for_file(char *);
     48extern int make_list_of_drives(struct mountlist_itself *,
     49                               struct list_of_disks *);
     50extern bool mountlist_contains_raid_devices(struct mountlist_itself *);
     51extern void open_evalcall_form(char *);
     52extern void open_progress_form(char *, char *, char *, char *, long);
    5153extern int openin_cdstream(struct s_bkpinfo *);
    5254extern int openin_tape(struct s_bkpinfo *);
    53 extern int partition_device(char*,int,int,char*,long);
    54 extern int partition_device_with_fdisk(char*,int,int,char*,long);
    55 extern int partition_device_with_parted(char*,int,int,char*,long);
    56 extern int partition_drive(struct mountlist_itself*, char*);
    57 extern int partition_everything(struct mountlist_itself*);
    58 extern void popup_and_OK(char*);
    59 extern bool popup_and_get_string(char*,char*,char*, int);
     55extern int partition_device(char *, int, int, char *, long);
     56extern int partition_device_with_fdisk(char *, int, int, char *, long);
     57extern int partition_device_with_parted(char *, int, int, char *, long);
     58extern int partition_drive(struct mountlist_itself *, char *);
     59extern int partition_everything(struct mountlist_itself *);
     60extern void popup_and_OK(char *);
     61extern bool popup_and_get_string(char *, char *, char *, int);
    6062extern void setup_newt_stuff(void);
    61 extern void reset_bkpinfo(struct s_bkpinfo*);
    62 extern int read_cfg_var(char*, char*, char*);
    63 extern int read_file_from_stream_to_file(struct s_bkpinfo*, char*, long long);
    64 extern int read_file_from_stream_to_stream(struct s_bkpinfo*, FILE*, long long);
    65 extern int read_file_from_stream_FULL(struct s_bkpinfo*, char*, FILE*, long long);
    66 extern int read_header_block_from_stream(long long *, char*, int *);
    67 extern void save_filelist(struct s_node*, char*);
    68 extern void strip_spaces(char*);
    69 extern int strcmp_inc_numbers(char*,char*);
    70 extern char *slice_fname(long,long,char*,char*);
    71 extern int stop_raid_device(char*);
    72 extern int stop_all_raid_devices(struct mountlist_itself*);
     63extern void reset_bkpinfo(struct s_bkpinfo *);
     64extern int read_cfg_var(char *, char *, char *);
     65extern int read_file_from_stream_to_file(struct s_bkpinfo *, char *,
     66                                         long long);
     67extern int read_file_from_stream_to_stream(struct s_bkpinfo *, FILE *,
     68                                           long long);
     69extern int read_file_from_stream_FULL(struct s_bkpinfo *, char *, FILE *,
     70                                      long long);
     71extern int read_header_block_from_stream(long long *, char *, int *);
     72extern void save_filelist(struct s_node *, char *);
     73extern void strip_spaces(char *);
     74extern int strcmp_inc_numbers(char *, char *);
     75extern char *slice_fname(long, long, char *, char *);
     76extern int stop_raid_device(char *);
     77extern int stop_all_raid_devices(struct mountlist_itself *);
    7378extern void update_evalcall_form(int);
    74 extern void update_progress_form(char*);
    75 extern int verify_tape_backups(struct s_bkpinfo*);
     79extern void update_progress_form(char *);
     80extern int verify_tape_backups(struct s_bkpinfo *);
    7681extern char which_restore_mode(void);
    77 extern int which_format_command_do_i_need(char*,char*);
    78 extern int write_cfg_var(char*,char*,char*);
    79 extern void wrong_marker(int,int);
    80 extern void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist, char*drive_name);
    81 extern void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist);
    82 extern int get_cfg_file_from_archive(struct s_bkpinfo*);
     82extern int which_format_command_do_i_need(char *, char *);
     83extern int write_cfg_var(char *, char *, char *);
     84extern void wrong_marker(int, int);
     85extern void resize_drive_proportionately_to_suit_new_drives(struct
     86                                                            mountlist_itself
     87                                                            *mountlist,
     88                                                            char
     89                                                            *drive_name);
     90extern void resize_mountlist_proportionately_to_suit_new_drives(struct
     91                                                                mountlist_itself
     92                                                                *mountlist);
     93extern int get_cfg_file_from_archive(struct s_bkpinfo *);
    8394
    8495
     
    8798 * Externals   yummmy!!!                                                  *
    8899 **************************************************************************/
    89 extern long   g_maximum_progress;
    90 extern long   g_current_progress;
    91 extern long   g_start_time;
    92 extern int    g_currentY;
    93 extern int    g_current_media_number;  /* set to 1 in mondo-tools.c (tape)*/
     100extern long g_maximum_progress;
     101extern long g_current_progress;
     102extern long g_start_time;
     103extern int g_currentY;
     104extern int g_current_media_number;  /* set to 1 in mondo-tools.c (tape) */
    94105extern long long g_tape_posK;
    95106extern FILE *g_tape_stream;
     
    97108extern bool g_text_mode;
    98109extern bool g_restoring_live_from_cd;
    99 extern int fput_string_one_char_at_a_time(FILE*, char*);
     110extern int fput_string_one_char_at_a_time(FILE *, char *);
    100111
    101112
     
    104115
    105116extern int
    106 evaluate_mountlist (struct mountlist_itself *mountlist, char *flaws_str_A,
    107             char *flaws_str_B, char *flaws_str_C);
     117evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A,
     118                   char *flaws_str_B, char *flaws_str_C);
    108119
    109120
  • branches/2.05/mondo/mondo/xmondo/xmondo.h

    r30 r128  
    55    copyright            : (C) 2003 by Joshua Oreman
    66    email                : oremanj@get-linux.org
    7     cvsid                : $Id: xmondo.h,v 1.1 2004/06/10 16:13:06 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    2020#define XMONDO_H
    2121
    22 #undef scroll // newt weirdness
     22#undef scroll                   // newt weirdness
    2323
    2424#ifdef HAVE_CONFIG_H
     
    4141#include "mondostructures.h"
    4242#undef bool
    43 }
    44 
    45 class QVButtonGroup;
     43} class QVButtonGroup;
    4644class QLabel;
    4745class QLineEdit;
     
    5553
    5654/** XMondo is the base class of the project */
    57 class XMondo : public KMainWindow
    58 {
    59   Q_OBJECT
    60 public:
    61     /** construtor */
    62     XMondo(QWidget* parent=0, const char *name=0);
    63     /** destructor */
    64     virtual ~XMondo();
     55class XMondo:public KMainWindow {
     56  Q_OBJECT public:
     57    /** construtor */
     58    XMondo(QWidget * parent = 0, const char *name = 0);
     59    /** destructor */
     60     virtual ~ XMondo();
    6561
    66     void fillBkpinfo (struct s_bkpinfo *);
    67  
    68 public slots:
    69     void slotVerboseChange (bool v);
    70     void slotMode (int x);
    71     void slotMediaType (int x);
    72     void slotCompareMediaType (int x);
    73     void slotRestoreMediaType (int x);
    74     void slotStartBackup();
    75     void slotStartCompare();
    76     void slotAddInclude();
    77     void slotAddExclude();
    78     void slotDelInclude();
    79     void slotDelExclude();
    80     void slotTabChange (QWidget *);
    81     void slotPrevRestore();
    82     void slotNextRestore();
    83    
    84 private:
    85     void initBackupTab (QWidget *&);
    86     void initOptionsTab (QWidget *&);
    87     void initAdvancedTab (QWidget *&);
    88     void initCompareTab (QWidget *&);
    89     void initRestoreTab (QWidget *&);
    90    
    91     QVButtonGroup *buttons;
    92     QWidgetStack *stack, *restoreStack;
    93     QTabWidget *backup;
    94     QWidget *compare, *restore, *tabHardware, *tabOptions, *tabAdvanced, *restoreInfo, *restoreFiles;
    95     QPushButton *bStartBackup, *bStartCompare;
    96     QPushButton *rPrev, *rNext;
    97     QButtonGroup *bgMediaType, *bgCompression, *bgCompareMediaType, *bgCompareCompression, *bgBootLoader, *mainButtons,
    98              *bgRestoreMediaType;
    99     QLabel *lDOption, *compareLDOption, *nfsRemoteDir, *compareNFSRemoteDir, *restoreLDOption, *restoreNFSRemoteDir;
    100     QLineEdit *editDOption, *editMediaSize, *compareEditDOption, *compareEditMediaSize, *restoreEditDOption,
    101           *restoreEditMediaSize, *editBootDevice, *editKernel, *editNFSRemoteDir, *compareEditNFSRemoteDir,
    102           *restoreEditNFSRemoteDir, *restoreFilter;
    103     QListView *listImageDevs, *listInclude, *listExclude, *listExcludeDevs;
    104     QCheckBox *checkDifferential, *checkBackupNFS, *checkCompare,
    105           *checkMakeBootFloppies, *checkUseLilo;
    106     QLineEdit *pendingInclude, *pendingExclude;
    107     XMondoBackup *bkup;
    108     XMondoRestore *rstr;
     62    void fillBkpinfo(struct s_bkpinfo *);
     63
     64    public slots:void slotVerboseChange(bool v);
     65    void slotMode(int x);
     66    void slotMediaType(int x);
     67    void slotCompareMediaType(int x);
     68    void slotRestoreMediaType(int x);
     69    void slotStartBackup();
     70    void slotStartCompare();
     71    void slotAddInclude();
     72    void slotAddExclude();
     73    void slotDelInclude();
     74    void slotDelExclude();
     75    void slotTabChange(QWidget *);
     76    void slotPrevRestore();
     77    void slotNextRestore();
     78
     79  private:
     80    void initBackupTab(QWidget * &);
     81    void initOptionsTab(QWidget * &);
     82    void initAdvancedTab(QWidget * &);
     83    void initCompareTab(QWidget * &);
     84    void initRestoreTab(QWidget * &);
     85
     86    QVButtonGroup *buttons;
     87    QWidgetStack *stack, *restoreStack;
     88    QTabWidget *backup;
     89    QWidget *compare, *restore, *tabHardware, *tabOptions, *tabAdvanced,
     90        *restoreInfo, *restoreFiles;
     91    QPushButton *bStartBackup, *bStartCompare;
     92    QPushButton *rPrev, *rNext;
     93    QButtonGroup *bgMediaType, *bgCompression, *bgCompareMediaType,
     94        *bgCompareCompression, *bgBootLoader, *mainButtons,
     95        *bgRestoreMediaType;
     96    QLabel *lDOption, *compareLDOption, *nfsRemoteDir,
     97        *compareNFSRemoteDir, *restoreLDOption, *restoreNFSRemoteDir;
     98    QLineEdit *editDOption, *editMediaSize, *compareEditDOption,
     99        *compareEditMediaSize, *restoreEditDOption, *restoreEditMediaSize,
     100        *editBootDevice, *editKernel, *editNFSRemoteDir,
     101        *compareEditNFSRemoteDir, *restoreEditNFSRemoteDir, *restoreFilter;
     102    QListView *listImageDevs, *listInclude, *listExclude, *listExcludeDevs;
     103    QCheckBox *checkDifferential, *checkBackupNFS, *checkCompare,
     104        *checkMakeBootFloppies, *checkUseLilo;
     105    QLineEdit *pendingInclude, *pendingExclude;
     106    XMondoBackup *bkup;
     107    XMondoRestore *rstr;
    109108};
    110109
  • branches/2.05/mondo/mondo/xmondo/xmondobackup.h

    r30 r128  
    55    copyright            : (C) 2003 by Joshua Oreman
    66    email                : oremanj@get-linux.org
    7     cvsid                : $Id: xmondobackup.h,v 1.1 2004/06/10 16:13:06 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    2828
    2929class BackupThread;
    30 class XMondoBackup : public QObject {
    31    Q_OBJECT
    32 public:
     30class XMondoBackup:public QObject {
     31  Q_OBJECT public:
    3332    XMondoBackup();
    3433    ~XMondoBackup();
    35     int run (struct s_bkpinfo *bkpinfo);
    36     int compare (struct s_bkpinfo *bkpinfo);
     34    int run(struct s_bkpinfo *bkpinfo);
     35    int compare(struct s_bkpinfo *bkpinfo);
    3736
    38 public slots:
    39     void abortBackup();
     37    public slots:void abortBackup();
    4038
    41 private:
    42     BackupThread *th;
     39  private:
     40     BackupThread * th;
    4341};
    4442
  • branches/2.05/mondo/mondo/xmondo/xmondorestore.h

    r30 r128  
    55    copyright            : (C) 2003 by Joshua Oreman
    66    email                : oremanj@get-linux.org
    7     cvsid                : $Id: xmondorestore.h,v 1.1 2004/06/10 16:13:06 hugo Exp $
     7    cvsid                : $Id$
    88 ***************************************************************************/
    99
     
    3232 * @author Joshua Oreman
    3333 */
    34 class XMondoRestore : public QObject
    35 {
    36     Q_OBJECT
     34class XMondoRestore:public QObject {
     35    Q_OBJECT friend void *XMondoRestore_preparer_thread(void *arg);
    3736
    38     friend void *XMondoRestore_preparer_thread (void *arg);
    39    
    40 public:
    41     XMondoRestore (QWidget *parent, QButtonGroup *mediaType, QLineEdit *device, QLineEdit *nfsRemoteDir, QLineEdit *filelistFilter);
    42     virtual ~XMondoRestore();
     37  public:
     38     XMondoRestore(QWidget * parent, QButtonGroup * mediaType,
     39                   QLineEdit * device, QLineEdit * nfsRemoteDir,
     40                   QLineEdit * filelistFilter);
     41     virtual ~ XMondoRestore();
    4342
    44     virtual void go();
    45     bool good() {
    46     return ok;
    47     }
    48     bool isSetupDone() {
    49     return doneSetup;
    50     }
     43    virtual void go();
     44    bool good() {
     45        return ok;
     46    } bool isSetupDone() {
     47        return doneSetup;
     48    }
    5149
    52 public slots:
    53     void slotAbortRestore();
     50    public slots:void slotAbortRestore();
    5451
    55 protected:
    56     bool ok;
    57     bool doneSetup;
    58    
    59     QButtonGroup *rMediaType;
    60     QLineEdit *rDevice, *rNFSRemoteDir, *rFilter;
     52  protected:
     53    bool ok;
     54    bool doneSetup;
    6155
    62     QWidget *files;
    63     QLabel *fStatusMsg;
    64     QListView *fList;
    65     QLabel *fRestoreDirLabel;
    66     QLineEdit *fRestoreDir;
     56    QButtonGroup *rMediaType;
     57    QLineEdit *rDevice, *rNFSRemoteDir, *rFilter;
    6758
    68     QString tempdir, filelistLocation, cfgLocation, cdMountpoint;
     59    QWidget *files;
     60    QLabel *fStatusMsg;
     61    QListView *fList;
     62    QLabel *fRestoreDirLabel;
     63    QLineEdit *fRestoreDir;
    6964
    70     pthread_t preparer_thread;
    71    
    72     s_bkpinfo *bkpinfo;
    73    
    74     RestoreThread *th;
     65    QString tempdir, filelistLocation, cfgLocation, cdMountpoint;
     66
     67    pthread_t preparer_thread;
     68
     69    s_bkpinfo *bkpinfo;
     70
     71    RestoreThread *th;
    7572};
    7673
    7774#endif
    78 
Note: See TracChangeset for help on using the changeset viewer.