Changeset 128 in MondoRescue for branches/2.05/mondo/mondo/common


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/common
Files:
49 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);
Note: See TracChangeset for help on using the changeset viewer.